mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-15 03:51:23 +01:00
lnwallet/channel: add feerate sanity check
This commit is contained in:
parent
ea94dbbe34
commit
21c5a957bc
1 changed files with 23 additions and 0 deletions
|
@ -2372,6 +2372,29 @@ func (lc *LightningChannel) fetchCommitmentView(remoteChain bool,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We'll assert that there hasn't been a mistake during fee calculation
|
||||||
|
// leading to a fee too low.
|
||||||
|
var totalOut btcutil.Amount
|
||||||
|
for _, txOut := range commitTx.txn.TxOut {
|
||||||
|
totalOut += btcutil.Amount(txOut.Value)
|
||||||
|
}
|
||||||
|
fee := lc.channelState.Capacity - totalOut
|
||||||
|
|
||||||
|
// Since the transaction is not signed yet, we use the witness weight
|
||||||
|
// used for weight calculation.
|
||||||
|
uTx := btcutil.NewTx(commitTx.txn)
|
||||||
|
weight := blockchain.GetTransactionWeight(uTx) +
|
||||||
|
input.WitnessCommitmentTxWeight
|
||||||
|
|
||||||
|
effFeeRate := chainfee.SatPerKWeight(fee) * 1000 /
|
||||||
|
chainfee.SatPerKWeight(weight)
|
||||||
|
if effFeeRate < chainfee.FeePerKwFloor {
|
||||||
|
return nil, fmt.Errorf("height=%v, for ChannelPoint(%v) "+
|
||||||
|
"attempts to create commitment wigh feerate %v: %v",
|
||||||
|
nextHeight, lc.channelState.FundingOutpoint,
|
||||||
|
effFeeRate, spew.Sdump(commitTx))
|
||||||
|
}
|
||||||
|
|
||||||
// With the commitment view created, store the resulting balances and
|
// With the commitment view created, store the resulting balances and
|
||||||
// transaction with the other parameters for this height.
|
// transaction with the other parameters for this height.
|
||||||
c := &commitment{
|
c := &commitment{
|
||||||
|
|
Loading…
Add table
Reference in a new issue