peer: stop considering pending channels as active

This commit changes the method `isActiveChannel` such that the pending
channels are not consider as active.
This commit is contained in:
yyforyongyu 2023-03-16 08:55:12 +08:00
parent ccb86a9d1d
commit 60627f676f
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868

View file

@ -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