From 76f0f67b7c64d08692933bedab9f9a8aa91c314f Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 11 Jul 2023 19:01:41 -0700 Subject: [PATCH] channeldb: update ChanSyncMsg to populate nonce info In this commit, we update the ChanSyncMsg to populate nonce information. With this change, we can now hide nonce generation further down in the pipeline and ensure that all callers will have the expected fields populated. --- channeldb/channel.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/channeldb/channel.go b/channeldb/channel.go index 277b855dc..a933b4eed 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -1513,6 +1513,30 @@ func (c *OpenChannel) ChanSyncMsg() (*lnwire.ChannelReestablish, error) { } } + // If this is a taproot channel, then we'll need to generate our next + // verification nonce to send to the remote party. They'll use this to + // sign the next update to our commitment transaction. + var nextTaprootNonce *lnwire.Musig2Nonce + if c.ChanType.IsTaproot() { + taprootRevProducer, err := DeriveMusig2Shachain( + c.RevocationProducer, + ) + if err != nil { + return nil, err + } + + nextNonce, err := NewMusigVerificationNonce( + c.LocalChanCfg.MultiSigKey.PubKey, + nextLocalCommitHeight, taprootRevProducer, + ) + if err != nil { + return nil, fmt.Errorf("unable to gen next "+ + "nonce: %w", err) + } + + nextTaprootNonce = (*lnwire.Musig2Nonce)(&nextNonce.PubNonce) + } + return &lnwire.ChannelReestablish{ ChanID: lnwire.NewChanIDFromOutPoint( &c.FundingOutpoint, @@ -1523,6 +1547,7 @@ func (c *OpenChannel) ChanSyncMsg() (*lnwire.ChannelReestablish, error) { LocalUnrevokedCommitPoint: input.ComputeCommitmentPoint( currentCommitSecret[:], ), + LocalNonce: nextTaprootNonce, }, nil }