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.
This commit is contained in:
Olaoluwa Osuntokun 2018-02-24 19:15:25 -08:00
parent 19bc477b9a
commit 5f5e4554cb
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
1 changed files with 12 additions and 3 deletions

View File

@ -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)
}