peer: check for existence of channel when handling a remote close

This commit patches a bug in the code for handling a remote cooperative
channel closer. Previous if the region node didn’t know of the channel
which was being requested to close, then a panic would occur as the
entry read from the map would be nil.

To fix this bug, we now ensure that the channel exists before we
perform any actions on it. In a later commit which overhauls the
channel opening and closing to match that of the specification, this
logic will be modified to properly send an error message in response to
the failed channel closure.
This commit is contained in:
Olaoluwa Osuntokun 2017-02-07 16:47:59 -08:00
parent 5889331422
commit 906c0451c8
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -910,8 +910,13 @@ func (p *peer) handleRemoteClose(req *lnwire.CloseRequest) {
}
p.activeChanMtx.RLock()
channel := p.activeChannels[key]
channel, ok := p.activeChannels[key]
p.activeChanMtx.RUnlock()
if !ok {
peerLog.Errorf("unable to close channel, ChannelPoint(%v) is "+
"unknown", key)
return
}
// Now that we have their signature for the closure transaction, we
// can assemble the final closure transaction, complete with our