From 459583ca041fcefe9f61d04566da620b582b22e6 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sun, 14 May 2017 19:07:08 -0700 Subject: [PATCH] breacharbiter: don't watch for channel closes if time locked balance is non-zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes a slight logic error in the breachArbiter. Previously we wouldn’t watch a pending channel for closure if the regular (settled) balance was non-zero. However, this was incorrect, as it’s possible for us to be on the receiving side of a channel force closure. This error would leave certain channels as “pending close zombies” forever until a user manually deleted the entry (or promoted it to be fully closed). To fix this, we now utilize the new `TimeLockedBalance` field to make a better judgment as to if the utxoNursery is watching over a channel or not. --- breacharbiter.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/breacharbiter.go b/breacharbiter.go index eb5c010d..4c444710 100644 --- a/breacharbiter.go +++ b/breacharbiter.go @@ -139,10 +139,11 @@ func (b *breachArbiter) Start() error { } for _, pendingClose := range pendingCloseChans { // If this channel was force closed, and we have a non-zero - // balance, then the utxoNursery is currently watching over it. - // As a result we don't need to watch over it. + // time-locked balance, then the utxoNursery is currently + // watching over it. As a result we don't need to watch over + // it. if pendingClose.CloseType == channeldb.ForceClose && - pendingClose.OurBalance != 0 { + pendingClose.TimeLockedBalance != 0 { continue } @@ -482,13 +483,13 @@ func (b *breachArbiter) breachObserver(contract *lnwallet.LightningChannel, b.htlcSwitch.CloseLink(chanPoint, CloseBreach) chanInfo := contract.StateSnapshot() closeInfo := &channeldb.ChannelCloseSummary{ - ChanPoint: *chanPoint, - ClosingTXID: breachInfo.BreachTransaction.TxHash(), - RemotePub: &chanInfo.RemoteIdentity, - Capacity: chanInfo.Capacity, - OurBalance: chanInfo.LocalBalance, - CloseType: channeldb.BreachClose, - IsPending: true, + ChanPoint: *chanPoint, + ClosingTXID: breachInfo.BreachTransaction.TxHash(), + RemotePub: &chanInfo.RemoteIdentity, + Capacity: chanInfo.Capacity, + SettledBalance: chanInfo.LocalBalance, + CloseType: channeldb.BreachClose, + IsPending: true, } if err := contract.DeleteState(closeInfo); err != nil { brarLog.Errorf("unable to delete channel state: %v", err)