peer: only add an active link to the channelManager if addPeer succeeds
In this commit we fix an existing bug which could cause internal state inconsistency between then switch, funding manager, and the peer. Before this commit, we would _always_ add a new channel to the channelManager. However, due to recent logic, it may be the case that this isn't the channel that will ultimately reside in the link. As a result, we would be unable to process incoming FundingLocked messages properly, as we would mutate the incorrect channel in memory. We remedy this by moving the inserting of the new channel into the activeChannels map until the end of the loadActiveChannels method, where we know that this will be the link that persists.
This commit is contained in:
parent
3db06cf7d5
commit
e1d8c37708
14
peer.go
14
peer.go
@ -324,10 +324,6 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
|
||||
|
||||
chanID := lnwire.NewChanIDFromOutPoint(chanPoint)
|
||||
|
||||
p.activeChanMtx.Lock()
|
||||
p.activeChannels[chanID] = lnChan
|
||||
p.activeChanMtx.Unlock()
|
||||
|
||||
peerLog.Infof("NodeKey(%x) loading ChannelPoint(%v)",
|
||||
p.PubKey(), chanPoint)
|
||||
|
||||
@ -415,12 +411,18 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
|
||||
}
|
||||
|
||||
// Create the link and add it to the switch.
|
||||
err = p.addLink(chanPoint, lnChan, forwardingPolicy, blockEpoch,
|
||||
chainEvents, currentHeight, true)
|
||||
err = p.addLink(
|
||||
chanPoint, lnChan, forwardingPolicy, blockEpoch,
|
||||
chainEvents, currentHeight, true,
|
||||
)
|
||||
if err != nil {
|
||||
lnChan.Stop()
|
||||
return err
|
||||
}
|
||||
|
||||
p.activeChanMtx.Lock()
|
||||
p.activeChannels[chanID] = lnChan
|
||||
p.activeChanMtx.Unlock()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user