From ae724756122e4e71957f2488c007198d2bf33818 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 14 Jan 2017 18:01:18 -0800 Subject: [PATCH] lnwallet: create channel close summary when commitment broadcast detected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit modifies the closeObserver goroutine to ensure that a close summary has been inserted into the database before signalling any observers that a unilateral channel closure was detected. This fixes a slight bug where a peer would force close a channel, but we wouldn’t properly detect that and clean up the channel state if had a failed cooperative channel closure. --- lnwallet/channel.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 7ea14121..98ea4d28 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -697,6 +697,7 @@ func (lc *LightningChannel) closeObserver(channelCloseNtfn *chainntnfs.SpendEven lc.RLock() if lc.status == channelClosed || lc.status == channelDispute || lc.status == channelClosing { + lc.RUnlock() return } @@ -727,6 +728,17 @@ func (lc *LightningChannel) closeObserver(channelCloseNtfn *chainntnfs.SpendEven case broadcastStateNum == currentStateNum: walletLog.Infof("Unilateral close of ChannelPoint(%v) "+ "detected", lc.channelState.ChanID) + + // As we've deleted that the channel has been closed, + // immediately delete the state from disk, creating a close + // summary for future usage by related sub-systems. + if err := lc.DeleteState(); err != nil { + walletLog.Errorf("unable to delete channel state: %v", + err) + } + + // Notify any subscribers that we've detected a unilateral + // commitment transaction broadcast. close(lc.UnilateralCloseSignal) // If the state number broadcast is lower than the remote node's