From 911becb431b7e8f1c3c2b762b39d29851b9e2f85 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 11 Jul 2023 19:02:41 -0700 Subject: [PATCH] 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. --- lnwallet/channel.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index e6508a711..bc526f887 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -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 }