multi: skip InitRemoteMusigNonces if we've already called it

Prior to this commit, taproot channels had a bug:

- If a disconnect happened before peer.AddNewChannel was called,
  then the subsequent reconnect would call peer.AddNewChannel and
  attempt the ChannelReestablish dance.

- peer.AddNewChannel would call NewLightningChannel with
  populated nonce ChannelOpts. This in turn would call
  InitRemoteMusigNonces which would create a new musig pair session
  and set the channel's pendingVerificationNonce to nil.

- During the reestablish dance, ProcessChanSyncMsg would be called.
  This would also call InitRemoteMusigNonces, except it would fail
  since pendingVerificationNonce was set to nil in the previous
  invocation.

To fix this, we add a new functional option to signal to the init logic
that it doesn't need to call InitRemoteMusigNonces in   in
ProcessChanSyncMsg.
This commit is contained in:
Eugene Siegel
2023-10-13 08:00:49 -07:00
committed by Olaoluwa Osuntokun
parent 32c8b82c36
commit dc42b160a0
2 changed files with 48 additions and 15 deletions

View File

@@ -3824,17 +3824,6 @@ func (p *Brontide) addActiveChannel(c *lnpeer.NewChannel) error {
chanPoint := &c.FundingOutpoint
chanID := lnwire.NewChanIDFromOutPoint(chanPoint)
// If not already active, we'll add this channel to the set of active
// channels, so we can look it up later easily according to its channel
// ID.
lnChan, err := lnwallet.NewLightningChannel(
p.cfg.Signer, c.OpenChannel,
p.cfg.SigPool, c.ChanOpts...,
)
if err != nil {
return fmt.Errorf("unable to create LightningChannel: %w", err)
}
// If we've reached this point, there are two possible scenarios. If
// the channel was in the active channels map as nil, then it was
// loaded from disk and we need to send reestablish. Else, it was not
@@ -3842,6 +3831,24 @@ func (p *Brontide) addActiveChannel(c *lnpeer.NewChannel) error {
// fresh channel.
shouldReestablish := p.isLoadedFromDisk(chanID)
chanOpts := c.ChanOpts
if shouldReestablish {
// If we have to do the reestablish dance for this channel,
// ensure that we don't try to call InitRemoteMusigNonces twice
// by calling SkipNonceInit.
chanOpts = append(chanOpts, lnwallet.WithSkipNonceInit())
}
// If not already active, we'll add this channel to the set of active
// channels, so we can look it up later easily according to its channel
// ID.
lnChan, err := lnwallet.NewLightningChannel(
p.cfg.Signer, c.OpenChannel, p.cfg.SigPool, chanOpts...,
)
if err != nil {
return fmt.Errorf("unable to create LightningChannel: %w", err)
}
// Store the channel in the activeChannels map.
p.activeChannels.Store(chanID, lnChan)