From 906c0451c8b2f45556e91c5cab18c88c5db5425c Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 7 Feb 2017 16:47:59 -0800 Subject: [PATCH] peer: check for existence of channel when handling a remote close MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- peer.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/peer.go b/peer.go index a491a2f1..ab398925 100644 --- a/peer.go +++ b/peer.go @@ -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