lnwallet: use availableBalance in max fee calc
In this commit we ensure that the max fee calculated in the MaxFeeRate function takes the local reserve amount into account along with any pending HTLCs. This is done by calling the avaialbeBalance function.
This commit is contained in:
2 files changed
+20
-16
No files matched your search
+15
-11
@@ -6998,9 +6998,10 @@ func (lc *LightningChannel) CalcFee(feeRate chainfee.SatPerKWeight) btcutil.Amou
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MaxFeeRate returns the maximum fee rate given an allocation of the channel
|
// MaxFeeRate returns the maximum fee rate given an allocation of the channel
|
||||||
// initiator's spendable balance. This can be useful to determine when we should
|
// initiator's spendable balance along with the local reserve amount. This can
|
||||||
// stop proposing fee updates that exceed our maximum allocation. We also take
|
// be useful to determine when we should stop proposing fee updates that exceed
|
||||||
// a fee rate cap that should be used for anchor type channels.
|
// our maximum allocation. We also take a fee rate cap that should be used for
|
||||||
|
// anchor type channels.
|
||||||
//
|
//
|
||||||
// NOTE: This should only be used for channels in which the local commitment is
|
// NOTE: This should only be used for channels in which the local commitment is
|
||||||
// the initiator.
|
// the initiator.
|
||||||
@@ -7010,16 +7011,19 @@ func (lc *LightningChannel) MaxFeeRate(maxAllocation float64,
|
|||||||
lc.RLock()
|
lc.RLock()
|
||||||
defer lc.RUnlock()
|
defer lc.RUnlock()
|
||||||
|
|
||||||
// The maximum fee depends of the available balance that can be
|
// The maximum fee depends on the available balance that can be
|
||||||
// committed towards fees.
|
// committed towards fees. It takes into account our local reserve
|
||||||
commit := lc.channelState.LocalCommitment
|
// balance.
|
||||||
feeBalance := float64(
|
availableBalance, weight := lc.availableBalance()
|
||||||
commit.LocalBalance.ToSatoshis() + commit.CommitFee,
|
|
||||||
)
|
oldFee := lc.localCommitChain.tip().feePerKw.FeeForWeight(weight)
|
||||||
maxFee := feeBalance * maxAllocation
|
|
||||||
|
// baseBalance is the maximum amount available for us to spend on fees.
|
||||||
|
baseBalance := availableBalance.ToSatoshis() + oldFee
|
||||||
|
|
||||||
|
maxFee := float64(baseBalance) * maxAllocation
|
||||||
|
|
||||||
// Ensure the fee rate doesn't dip below the fee floor.
|
// Ensure the fee rate doesn't dip below the fee floor.
|
||||||
_, weight := lc.availableBalance()
|
|
||||||
maxFeeRate := maxFee / (float64(weight) / 1000)
|
maxFeeRate := maxFee / (float64(weight) / 1000)
|
||||||
feeRate := chainfee.SatPerKWeight(
|
feeRate := chainfee.SatPerKWeight(
|
||||||
math.Max(maxFeeRate, float64(chainfee.FeePerKwFloor)),
|
math.Max(maxFeeRate, float64(chainfee.FeePerKwFloor)),
|
||||||
|
|||||||
@@ -8024,9 +8024,9 @@ func TestChannelMaxFeeRate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
|
|
||||||
assertMaxFeeRate(aliceChannel, 1.0, 0, 690607734)
|
assertMaxFeeRate(aliceChannel, 1.0, 0, 676794154)
|
||||||
assertMaxFeeRate(aliceChannel, 0.001, 0, 690607)
|
assertMaxFeeRate(aliceChannel, 0.001, 0, 676794)
|
||||||
assertMaxFeeRate(aliceChannel, 0.000001, 0, 690)
|
assertMaxFeeRate(aliceChannel, 0.000001, 0, 676)
|
||||||
assertMaxFeeRate(aliceChannel, 0.0000001, 0, chainfee.FeePerKwFloor)
|
assertMaxFeeRate(aliceChannel, 0.0000001, 0, chainfee.FeePerKwFloor)
|
||||||
|
|
||||||
// Check that anchor channels are capped at their max fee rate.
|
// Check that anchor channels are capped at their max fee rate.
|
||||||
@@ -8044,9 +8044,9 @@ func TestChannelMaxFeeRate(t *testing.T) {
|
|||||||
anchorChannel, 1.0, chainfee.FeePerKwFloor,
|
anchorChannel, 1.0, chainfee.FeePerKwFloor,
|
||||||
chainfee.FeePerKwFloor,
|
chainfee.FeePerKwFloor,
|
||||||
)
|
)
|
||||||
assertMaxFeeRate(anchorChannel, 0.001, 1000000, 444839)
|
assertMaxFeeRate(anchorChannel, 0.001, 1000000, 435941)
|
||||||
assertMaxFeeRate(anchorChannel, 0.001, 300000, 300000)
|
assertMaxFeeRate(anchorChannel, 0.001, 300000, 300000)
|
||||||
assertMaxFeeRate(anchorChannel, 0.000001, 700, 444)
|
assertMaxFeeRate(anchorChannel, 0.000001, 700, 435)
|
||||||
assertMaxFeeRate(
|
assertMaxFeeRate(
|
||||||
anchorChannel, 0.0000001, 1000000, chainfee.FeePerKwFloor,
|
anchorChannel, 0.0000001, 1000000, chainfee.FeePerKwFloor,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in new issue
Block a user