From 60627f676fc095395c870a90fe3d4be6b72a5ee0 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 16 Mar 2023 08:55:12 +0800 Subject: [PATCH] peer: stop considering pending channels as active This commit changes the method `isActiveChannel` such that the pending channels are not consider as active. --- peer/brontide.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/peer/brontide.go b/peer/brontide.go index d048e27e1..036c5168b 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -1572,7 +1572,8 @@ out: case *lnwire.ChannelReestablish: targetChan = msg.ChanID - isLinkUpdate = p.isActiveChannel(targetChan) + isLinkUpdate = p.isActiveChannel(targetChan) || + p.isPendingChannel(targetChan) // If we failed to find the link in question, and the // message received was a channel sync message, then @@ -1663,8 +1664,25 @@ func (p *Brontide) handleCustomMessage(msg *lnwire.Custom) error { // isActiveChannel returns true if the provided channel id is active, otherwise // returns false. func (p *Brontide) isActiveChannel(chanID lnwire.ChannelID) bool { - _, ok := p.activeChannels.Load(chanID) - return ok + // The channel would be nil if, + // - the channel doesn't exist, or, + // - the channel exists, but is pending. In this case, we don't + // consider this channel active. + channel, _ := p.activeChannels.Load(chanID) + + return channel != nil +} + +// isPendingChannel returns true if the provided channel ID is pending, and +// returns false if the channel is active or unknown. +func (p *Brontide) isPendingChannel(chanID lnwire.ChannelID) bool { + // Return false if the channel is unknown. + channel, ok := p.activeChannels.Load(chanID) + if !ok { + return false + } + + return channel == nil } // storeError stores an error in our peer's buffer of recent errors with the