diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 55cf9fb65..1eb1b0f10 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -4603,10 +4603,13 @@ func (lc *LightningChannel) CreateCloseProposal(proposedFee btcutil.Amount, ourBalance := localCommit.LocalBalance.ToSatoshis() theirBalance := localCommit.RemoteBalance.ToSatoshis() + // We'll make sure we account for the complete balance by adding the + // current dangling commitment fee to the balance of the initiator. + commitFee := localCommit.CommitFee if lc.channelState.IsInitiator { - ourBalance = ourBalance - proposedFee + ourBalance = ourBalance - proposedFee + commitFee } else { - theirBalance = theirBalance - proposedFee + theirBalance = theirBalance - proposedFee + commitFee } closeTx := CreateCooperativeCloseTx(lc.fundingTxIn, @@ -4665,10 +4668,13 @@ func (lc *LightningChannel) CompleteCooperativeClose(localSig, remoteSig, ourBalance := localCommit.LocalBalance.ToSatoshis() theirBalance := localCommit.RemoteBalance.ToSatoshis() + // We'll make sure we account for the complete balance by adding the + // current dangling commitment fee to the balance of the initiator. + commitFee := localCommit.CommitFee if lc.channelState.IsInitiator { - ourBalance = ourBalance - proposedFee + ourBalance = ourBalance - proposedFee + commitFee } else { - theirBalance = theirBalance - proposedFee + theirBalance = theirBalance - proposedFee + commitFee } // Create the transaction used to return the current settled balance diff --git a/lnwallet/channel_test.go b/lnwallet/channel_test.go index 0a44c212e..b8b603dc4 100644 --- a/lnwallet/channel_test.go +++ b/lnwallet/channel_test.go @@ -1807,7 +1807,7 @@ func TestCooperativeCloseDustAdherence(t *testing.T) { // Both sides currently have over 1 BTC settled as part of their // balances. As a result, performing a cooperative closure now result // in both sides having an output within the closure transaction. - aliceFee := btcutil.Amount(aliceChannel.CalcFee(aliceFeeRate)) + aliceFee := btcutil.Amount(aliceChannel.CalcFee(aliceFeeRate)) + 1000 aliceSig, err := aliceChannel.CreateCloseProposal(aliceFee, aliceDeliveryScript, bobDeliveryScript) if err != nil { @@ -1815,7 +1815,7 @@ func TestCooperativeCloseDustAdherence(t *testing.T) { } aliceCloseSig := append(aliceSig, byte(txscript.SigHashAll)) - bobFee := btcutil.Amount(bobChannel.CalcFee(bobFeeRate)) + bobFee := btcutil.Amount(bobChannel.CalcFee(bobFeeRate)) + 1000 bobSig, err := bobChannel.CreateCloseProposal(bobFee, bobDeliveryScript, aliceDeliveryScript) if err != nil { @@ -1874,10 +1874,12 @@ func TestCooperativeCloseDustAdherence(t *testing.T) { t.Fatalf("close tx has wrong number of outputs: expected %v "+ "got %v", 1, len(closeTx.TxOut)) } - if closeTx.TxOut[0].Value != int64(aliceBal.ToSatoshis()-calcStaticFee(0)) { + commitFee := aliceChannel.channelState.LocalCommitment.CommitFee + aliceExpectedBalance := aliceBal.ToSatoshis() - aliceFee + commitFee + if closeTx.TxOut[0].Value != int64(aliceExpectedBalance) { t.Fatalf("alice's balance is incorrect: expected %v, got %v", - int64(aliceBal.ToSatoshis()-calcStaticFee(0)), - closeTx.TxOut[0].Value) + aliceExpectedBalance, + int64(closeTx.TxOut[0].Value)) } // Finally, we'll modify the current balances and dust limits such that