From f2e077c10c6285f65e2c9e149650c6aa54a271d4 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 20 Feb 2017 19:56:55 -0800 Subject: [PATCH] lnwallet: account for de-sync'd channels within closeObserver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds an additional case of the closeObserver that will properly handle the case of a channel being closed by a de-sync’d commitment transaction from the PoV of the local node. In the case of a minor 1-state divergence, the commitment transaction broadcast by the remote node will be 1 state ahead of the commitment transaction we have locally. This should be seen as a regular unilateral close as they remote peer didn’t violate the channel contract in any way. We address this case by changing the `==` to a `>=`. --- lnwallet/channel.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index ca2b4f0a..937f2016 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -845,7 +845,7 @@ func (lc *LightningChannel) closeObserver(channelCloseNtfn *chainntnfs.SpendEven // caller/maintainer of this channel. case <-lc.quit: // As we're exiting before the spend notification has been - // triggered, we'll cancel the notificaiton intent so the + // triggered, we'll cancel the notification intent so the // ChainNotiifer can free up the resources. channelCloseNtfn.Cancel() return @@ -884,7 +884,13 @@ func (lc *LightningChannel) closeObserver(channelCloseNtfn *chainntnfs.SpendEven // state, then they've initiated a unilateral close. So we'll trigger // the unilateral close signal so subscribers can clean up the state as // necessary. - case broadcastStateNum == currentStateNum: + // + // We'll also handle the case of the remote party broadcasting their + // commitment transaction which is one height above ours. This case an + // arise when we initiate a state transition, but the remote party has + // a fail crash _after_ accepting the new state, but _before_ sending + // their signature to us. + case broadcastStateNum >= currentStateNum: walletLog.Infof("Unilateral close of ChannelPoint(%v) "+ "detected", lc.channelState.ChanID) @@ -927,7 +933,6 @@ func (lc *LightningChannel) closeObserver(channelCloseNtfn *chainntnfs.SpendEven // channel to allow the observer the use the breach retribution // to sweep ALL funds. lc.ContractBreach <- retribution - case broadcastStateNum > currentStateNum: } }