lnd+lnwallet: make capacity check stricter by adding fee

Also patches breacharbiter tests by using the correct commitment
fee and balances.
This commit is contained in:
eugene 2021-02-22 12:07:21 -05:00
parent c9ed5927f6
commit bc238ee84c
No known key found for this signature in database
GPG Key ID: 118759E83439A9B1
2 changed files with 8 additions and 6 deletions

@ -1843,22 +1843,24 @@ func createInitChannels(revocationWindow int) (*lnwallet.LightningChannel, *lnwa
return nil, nil, nil, err return nil, nil, nil, err
} }
commitFee := feePerKw.FeeForWeight(input.CommitWeight)
// TODO(roasbeef): need to factor in commit fee? // TODO(roasbeef): need to factor in commit fee?
aliceCommit := channeldb.ChannelCommitment{ aliceCommit := channeldb.ChannelCommitment{
CommitHeight: 0, CommitHeight: 0,
LocalBalance: lnwire.NewMSatFromSatoshis(channelBal), LocalBalance: lnwire.NewMSatFromSatoshis(channelBal - commitFee),
RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal), RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal),
FeePerKw: btcutil.Amount(feePerKw), FeePerKw: btcutil.Amount(feePerKw),
CommitFee: 8688, CommitFee: commitFee,
CommitTx: aliceCommitTx, CommitTx: aliceCommitTx,
CommitSig: bytes.Repeat([]byte{1}, 71), CommitSig: bytes.Repeat([]byte{1}, 71),
} }
bobCommit := channeldb.ChannelCommitment{ bobCommit := channeldb.ChannelCommitment{
CommitHeight: 0, CommitHeight: 0,
LocalBalance: lnwire.NewMSatFromSatoshis(channelBal), LocalBalance: lnwire.NewMSatFromSatoshis(channelBal),
RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal), RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal - commitFee),
FeePerKw: btcutil.Amount(feePerKw), FeePerKw: btcutil.Amount(feePerKw),
CommitFee: 8688, CommitFee: commitFee,
CommitTx: bobCommitTx, CommitTx: bobCommitTx,
CommitSig: bytes.Repeat([]byte{1}, 71), CommitSig: bytes.Repeat([]byte{1}, 71),
} }

@ -589,11 +589,11 @@ func (cb *CommitmentBuilder) createUnsignedCommitmentTx(ourBalance,
for _, txOut := range commitTx.TxOut { for _, txOut := range commitTx.TxOut {
totalOut += btcutil.Amount(txOut.Value) 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) "+ return nil, fmt.Errorf("height=%v, for ChannelPoint(%v) "+
"attempts to consume %v while channel capacity is %v", "attempts to consume %v while channel capacity is %v",
height, cb.chanState.FundingOutpoint, height, cb.chanState.FundingOutpoint,
totalOut, cb.chanState.Capacity) totalOut+commitFee, cb.chanState.Capacity)
} }
return &unsignedCommitmentTx{ return &unsignedCommitmentTx{