From 5f5e4554cbf8d037dd4db6402b1a0fed6f171ee4 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 24 Feb 2018 19:15:25 -0800 Subject: [PATCH] lnwallet: if the initiator is unable to pay fees, then consume their entire output In this commit, we add logic to account for an edge case in the protocol. If they initiator if unable to pay the fees for a commitment, then their *entire* output is meant to go to fees. The recent change to properly interpret balances as unsigned integers (within the protocol) let to the discovery of this missed edge case. --- lnwallet/channel.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 66036dfa..0a0b1e29 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -2142,10 +2142,19 @@ func (lc *LightningChannel) createCommitmentTx(c *commitment, // Currently, within the protocol, the initiator always pays the fees. // So we'll subtract the fee amount from the balance of the current - // initiator. - if lc.channelState.IsInitiator { + // initiator. If the initiator is unable to pay the fee fully, then + // their entire output is consumed. + switch { + case lc.channelState.IsInitiator && commitFee > ourBalance.ToSatoshis(): + ourBalance = 0 + + case lc.channelState.IsInitiator: ourBalance -= lnwire.NewMSatFromSatoshis(commitFee) - } else if !lc.channelState.IsInitiator { + + case !lc.channelState.IsInitiator && commitFee > theirBalance.ToSatoshis(): + theirBalance = 0 + + case !lc.channelState.IsInitiator: theirBalance -= lnwire.NewMSatFromSatoshis(commitFee) }