rpc: only set balance params when force closing if output not dust

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.
This commit is contained in:
Olaoluwa Osuntokun 2017-08-10 21:43:14 -07:00
parent ece1d09a9f
commit 512a5c899b
No known key found for this signature in database
GPG Key ID: 3D0A94DB79743DF5

@ -776,6 +776,9 @@ 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{
@ -783,11 +786,19 @@ func (r *rpcServer) forceCloseChan(channel *lnwallet.LightningChannel) (*chainha
ClosingTXID: closeTx.TxHash(),
RemotePub: &chanInfo.RemoteIdentity,
Capacity: chanInfo.Capacity,
SettledBalance: chanInfo.LocalBalance,
TimeLockedBalance: chanInfo.LocalBalance,
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
}