mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-30 23:53:41 +02:00
lnwallet+sweep: cap conf target used in fee estimator
This commit is contained in:
@@ -276,6 +276,16 @@ func (l *LinearFeeFunction) estimateFeeRate(
|
||||
ConfTarget: confTarget,
|
||||
}
|
||||
|
||||
// If the conf target is greater or equal to the max allowed value
|
||||
// (1008), we will use the min relay fee instead.
|
||||
if confTarget >= chainfee.MaxBlockTarget {
|
||||
minFeeRate := l.estimator.RelayFeePerKW()
|
||||
log.Debugf("Conf target %v is greater than max block target, "+
|
||||
"using min relay fee rate %v", confTarget, minFeeRate)
|
||||
|
||||
return minFeeRate, nil
|
||||
}
|
||||
|
||||
// endingFeeRate comes from budget/txWeight, which means the returned
|
||||
// fee rate will always be capped by this value, hence we don't need to
|
||||
// worry about overpay.
|
||||
|
@@ -19,6 +19,7 @@ func TestLinearFeeFunctionNew(t *testing.T) {
|
||||
// Create testing params.
|
||||
maxFeeRate := chainfee.SatPerKWeight(10000)
|
||||
estimatedFeeRate := chainfee.SatPerKWeight(500)
|
||||
minRelayFeeRate := chainfee.SatPerKWeight(100)
|
||||
confTarget := uint32(6)
|
||||
|
||||
// Assert init fee function with zero conf value returns an error.
|
||||
@@ -62,6 +63,23 @@ func TestLinearFeeFunctionNew(t *testing.T) {
|
||||
rt.ErrorContains(err, "fee rate delta is zero")
|
||||
rt.Nil(f)
|
||||
|
||||
// When the conf target is >= 1008, the min relay fee should be used.
|
||||
//
|
||||
// Mock the fee estimator to reutrn the fee rate.
|
||||
estimator.On("RelayFeePerKW").Return(minRelayFeeRate).Once()
|
||||
|
||||
largeConf := uint32(1008)
|
||||
f, err = NewLinearFeeFunction(maxFeeRate, largeConf, estimator)
|
||||
rt.NoError(err)
|
||||
rt.NotNil(f)
|
||||
|
||||
// Assert the internal state.
|
||||
rt.Equal(minRelayFeeRate, f.startingFeeRate)
|
||||
rt.Equal(maxFeeRate, f.endingFeeRate)
|
||||
rt.Equal(minRelayFeeRate, f.currentFeeRate)
|
||||
rt.NotZero(f.deltaFeeRate)
|
||||
rt.Equal(largeConf, f.width)
|
||||
|
||||
// Check a successfully created fee function.
|
||||
//
|
||||
// Mock the fee estimator to return the fee rate.
|
||||
|
Reference in New Issue
Block a user