peer: only mark active channels as failed

Also adds similar sanity check for LinkUpdater msgs, so that we don't
process messages for inactive channels.
This commit is contained in:
Conner Fromknecht 2019-09-25 12:01:23 -07:00
parent f33a1a61e6
commit ced113452d
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

20
peer.go

@ -1042,8 +1042,8 @@ out:
} }
var ( var (
isLinkUpdate bool
targetChan lnwire.ChannelID targetChan lnwire.ChannelID
isLinkUpdate bool
) )
switch msg := nextMsg.(type) { switch msg := nextMsg.(type) {
@ -1085,16 +1085,16 @@ out:
} }
case *lnwire.Error: case *lnwire.Error:
isLinkUpdate = p.handleError(msg)
targetChan = msg.ChanID targetChan = msg.ChanID
isLinkUpdate = p.handleError(msg)
case *lnwire.ChannelReestablish: case *lnwire.ChannelReestablish:
isLinkUpdate = true isLinkUpdate = true
targetChan = msg.ChanID targetChan = msg.ChanID
case LinkUpdater: case LinkUpdater:
isLinkUpdate = true
targetChan = msg.TargetChanID() targetChan = msg.TargetChanID()
isLinkUpdate = p.isActiveChannel(targetChan)
case *lnwire.ChannelUpdate, case *lnwire.ChannelUpdate,
*lnwire.ChannelAnnouncement, *lnwire.ChannelAnnouncement,
@ -1140,6 +1140,15 @@ out:
peerLog.Tracef("readHandler for peer %v done", p) peerLog.Tracef("readHandler for peer %v done", p)
} }
// isActiveChannel returns true if the provided channel id is active, otherwise
// returns false.
func (p *peer) isActiveChannel(chanID lnwire.ChannelID) bool {
p.activeChanMtx.RLock()
_, ok := p.activeChannels[chanID]
p.activeChanMtx.RUnlock()
return ok
}
// handleError processes an error message read from the remote peer. The boolean // handleError processes an error message read from the remote peer. The boolean
// returns indicates whether the message should be delivered to a targeted peer. // returns indicates whether the message should be delivered to a targeted peer.
// //
@ -1168,11 +1177,14 @@ func (p *peer) handleError(msg *lnwire.Error) bool {
return false return false
// If not we hand the error to the channel link for this channel. // If not we hand the error to the channel link for this channel.
default: case p.isActiveChannel(msg.ChanID):
// Mark this channel as failed, so we won't try to restart it on // Mark this channel as failed, so we won't try to restart it on
// reconnect with this peer. // reconnect with this peer.
p.failedChannels[msg.ChanID] = struct{}{} p.failedChannels[msg.ChanID] = struct{}{}
return true return true
default:
return false
} }
} }