lnwallet: fix validateFeeRate
The validateFeeRate function uses the availableBalance function to get the current spendable balance of a channel, adds the old fee and then ensures that the new fee is not larger than the amount we have available to spend. This commit also removes the local reserve check in the validateFeeRate function since the balance returned from availableBalance already takes the local reserve into acccount.
This commit is contained in:
2 files changed
+51
-12
No files matched your search
+4
-12
@@ -6821,7 +6821,10 @@ func (lc *LightningChannel) validateFeeRate(feePerKw chainfee.SatPerKWeight) err
|
||||
// be above our reserve balance. Otherwise, we'll reject the fee
|
||||
// update.
|
||||
availableBalance, txWeight := lc.availableBalance()
|
||||
oldFee := lnwire.NewMSatFromSatoshis(lc.localCommitChain.tip().fee)
|
||||
|
||||
oldFee := lnwire.NewMSatFromSatoshis(
|
||||
lc.localCommitChain.tip().feePerKw.FeeForWeight(txWeight),
|
||||
)
|
||||
|
||||
// Our base balance is the total amount of satoshis we can commit
|
||||
// towards fees before factoring in the channel reserve.
|
||||
@@ -6843,17 +6846,6 @@ func (lc *LightningChannel) validateFeeRate(feePerKw chainfee.SatPerKWeight) err
|
||||
newFee, baseBalance)
|
||||
}
|
||||
|
||||
// If this new balance is below our reserve, then we can't accommodate
|
||||
// the fee change, so we'll reject it.
|
||||
balanceAfterFee := baseBalance - newFee
|
||||
if balanceAfterFee.ToSatoshis() < lc.channelState.LocalChanCfg.ChanReserve {
|
||||
return fmt.Errorf("cannot apply fee_update=%v sat/kw, "+
|
||||
"new balance=%v would dip below channel reserve=%v",
|
||||
int64(feePerKw),
|
||||
balanceAfterFee.ToSatoshis(),
|
||||
lc.channelState.LocalChanCfg.ChanReserve)
|
||||
}
|
||||
|
||||
// TODO(halseth): should fail if fee update is unreasonable,
|
||||
// as specified in BOLT#2.
|
||||
// * COMMENT(roasbeef): can cross-check with our ideal fee rate
|
||||
|
||||
Reference in new issue
Block a user