lnwallet: move nonce generation into generateRevocation

Before this commit, we would conditionally generate nonces in
RevokeCurrentCommitment. We move this to generateRevocation as this is
called when doing channel sync, and we want to make sure we send the
correct set of nonces.
This commit is contained in:
Olaoluwa Osuntokun 2023-07-11 19:02:41 -07:00
parent 76f0f67b7c
commit 911becb431
No known key found for this signature in database
GPG Key ID: 3BBD59E99B280306

@ -5209,17 +5209,6 @@ func (lc *LightningChannel) RevokeCurrentCommitment() (*lnwire.RevokeAndAck,
&lc.channelState.FundingOutpoint,
)
// If this is a taproot channel, We've now accepted+revoked a new
// commitment, so we'll send the remote party another verification
// nonce they can use to generate new commitments.
if lc.channelState.ChanType.IsTaproot() {
localSession := lc.musigSessions.LocalSession
nextVerificationNonce := localSession.VerificationNonce()
revocationMsg.LocalNonce = (*lnwire.Musig2Nonce)(
&nextVerificationNonce.PubNonce,
)
}
return revocationMsg, newCommitment.Htlcs, finalHtlcs, nil
}
@ -7759,8 +7748,9 @@ func (lc *LightningChannel) generateRevocation(height uint64) (*lnwire.RevokeAnd
// revocation.
//
// Put simply in the window slides to the left by one.
revHeight := height + 2
nextCommitSecret, err := lc.channelState.RevocationProducer.AtIndex(
height + 2,
revHeight,
)
if err != nil {
return nil, err
@ -7771,6 +7761,21 @@ func (lc *LightningChannel) generateRevocation(height uint64) (*lnwire.RevokeAnd
&lc.channelState.FundingOutpoint,
)
// If this is a taproot channel, then we also need to generate the
// verification nonce for this target state.
if lc.channelState.ChanType.IsTaproot() {
nextVerificationNonce, err := channeldb.NewMusigVerificationNonce( //nolint:lll
lc.channelState.LocalChanCfg.MultiSigKey.PubKey,
revHeight, lc.taprootNonceProducer,
)
if err != nil {
return nil, err
}
revocationMsg.LocalNonce = (*lnwire.Musig2Nonce)(
&nextVerificationNonce.PubNonce,
)
}
return revocationMsg, nil
}