From bc238ee84c5d6688a9900f5a313d4cc12662a218 Mon Sep 17 00:00:00 2001 From: eugene Date: Mon, 22 Feb 2021 12:07:21 -0500 Subject: [PATCH] lnd+lnwallet: make capacity check stricter by adding fee Also patches breacharbiter tests by using the correct commitment fee and balances. --- breacharbiter_test.go | 10 ++++++---- lnwallet/commitment.go | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/breacharbiter_test.go b/breacharbiter_test.go index 0aef6fde..ce1ae42c 100644 --- a/breacharbiter_test.go +++ b/breacharbiter_test.go @@ -1843,22 +1843,24 @@ func createInitChannels(revocationWindow int) (*lnwallet.LightningChannel, *lnwa return nil, nil, nil, err } + commitFee := feePerKw.FeeForWeight(input.CommitWeight) + // TODO(roasbeef): need to factor in commit fee? aliceCommit := channeldb.ChannelCommitment{ CommitHeight: 0, - LocalBalance: lnwire.NewMSatFromSatoshis(channelBal), + LocalBalance: lnwire.NewMSatFromSatoshis(channelBal - commitFee), RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal), FeePerKw: btcutil.Amount(feePerKw), - CommitFee: 8688, + CommitFee: commitFee, CommitTx: aliceCommitTx, CommitSig: bytes.Repeat([]byte{1}, 71), } bobCommit := channeldb.ChannelCommitment{ CommitHeight: 0, LocalBalance: lnwire.NewMSatFromSatoshis(channelBal), - RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal), + RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal - commitFee), FeePerKw: btcutil.Amount(feePerKw), - CommitFee: 8688, + CommitFee: commitFee, CommitTx: bobCommitTx, CommitSig: bytes.Repeat([]byte{1}, 71), } diff --git a/lnwallet/commitment.go b/lnwallet/commitment.go index 4d58822d..96960f9d 100644 --- a/lnwallet/commitment.go +++ b/lnwallet/commitment.go @@ -589,11 +589,11 @@ func (cb *CommitmentBuilder) createUnsignedCommitmentTx(ourBalance, for _, txOut := range commitTx.TxOut { totalOut += btcutil.Amount(txOut.Value) } - if totalOut > cb.chanState.Capacity { + if totalOut+commitFee > cb.chanState.Capacity { return nil, fmt.Errorf("height=%v, for ChannelPoint(%v) "+ "attempts to consume %v while channel capacity is %v", height, cb.chanState.FundingOutpoint, - totalOut, cb.chanState.Capacity) + totalOut+commitFee, cb.chanState.Capacity) } return &unsignedCommitmentTx{