From 512a5c899bee0edd6bd314c7bc76a7cb17f79774 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 10 Aug 2017 21:43:14 -0700 Subject: [PATCH] rpc: only set balance params when force closing if output not dust MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes an existing bug that would cause a force closed channel to stay pending forever. In this instance, if one force closes a channel while they have a dust output, and restart before the channel is fully closed, then it wouldn’t have been closed automatically (within the database) by the autopilot agent. --- rpcserver.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 4e19cbe9..e7b97c34 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -776,18 +776,29 @@ func (r *rpcServer) forceCloseChan(channel *lnwallet.LightningChannel) (*chainha // we'll mark this channel as being in the pending closed state. The // UTXO nursery will mark the channel as fully closed once all the // outputs have been swept. + // + // TODO(roasbeef): don't set local balance if close summary detects + // dust output? chanPoint := channel.ChannelPoint() chanInfo := channel.StateSnapshot() closeInfo := &channeldb.ChannelCloseSummary{ - ChanPoint: *chanPoint, - ClosingTXID: closeTx.TxHash(), - RemotePub: &chanInfo.RemoteIdentity, - Capacity: chanInfo.Capacity, - SettledBalance: chanInfo.LocalBalance, - TimeLockedBalance: chanInfo.LocalBalance, - CloseType: channeldb.ForceClose, - IsPending: true, + ChanPoint: *chanPoint, + ClosingTXID: closeTx.TxHash(), + RemotePub: &chanInfo.RemoteIdentity, + Capacity: chanInfo.Capacity, + CloseType: channeldb.ForceClose, + IsPending: true, } + + // If our commitment output isn't dust or we have active HTLC's on the + // commitment transaction, then we'll populate the balances on the + // close channel summary. + if closeSummary.SelfOutputSignDesc != nil || + len(closeSummary.HtlcResolutions) == 0 { + closeInfo.SettledBalance = chanInfo.LocalBalance + closeInfo.TimeLockedBalance = chanInfo.LocalBalance + } + if err := channel.DeleteState(closeInfo); err != nil { return nil, nil, err }