multi: make sure CPFP won't exceed max allowed fee rate
This commit updates the `fee()` method in `weightEstimator` to make sure when doing CPFP we are not exceeding the max allowed fee rate. In order to use the max fee rate, we need to modify several methods to pass the configured value to the estimator.
This commit is contained in:
1 parent
42ff52bbfb
commit
24fa35ec80
12 files changed
+132
-48
No files matched your search
@@ -16,13 +16,19 @@ type weightEstimator struct {
|
||||
parents map[chainhash.Hash]struct{}
|
||||
parentsFee btcutil.Amount
|
||||
parentsWeight int64
|
||||
|
||||
// maxFeeRate is the max allowed fee rate configured by the user.
|
||||
maxFeeRate chainfee.SatPerKWeight
|
||||
}
|
||||
|
||||
// newWeightEstimator instantiates a new sweeper weight estimator.
|
||||
func newWeightEstimator(feeRate chainfee.SatPerKWeight) *weightEstimator {
|
||||
func newWeightEstimator(
|
||||
feeRate, maxFeeRate chainfee.SatPerKWeight) *weightEstimator {
|
||||
|
||||
return &weightEstimator{
|
||||
feeRate: feeRate,
|
||||
parents: make(map[chainhash.Hash]struct{}),
|
||||
feeRate: feeRate,
|
||||
maxFeeRate: maxFeeRate,
|
||||
parents: make(map[chainhash.Hash]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,5 +125,24 @@ func (w *weightEstimator) fee() btcutil.Amount {
|
||||
fee = childFee
|
||||
}
|
||||
|
||||
// Exit early if maxFeeRate is not set.
|
||||
if w.maxFeeRate == 0 {
|
||||
return fee
|
||||
}
|
||||
|
||||
// Clamp the fee to the max fee rate.
|
||||
maxFee := w.maxFeeRate.FeeForWeight(childWeight)
|
||||
if fee > maxFee {
|
||||
// Calculate the effective fee rate for logging.
|
||||
childFeeRate := chainfee.SatPerKWeight(
|
||||
fee * 1000 / btcutil.Amount(childWeight),
|
||||
)
|
||||
log.Warnf("Child fee rate %v exceeds max allowed fee rate %v, "+
|
||||
"returning fee %v instead of %v", childFeeRate,
|
||||
w.maxFeeRate, maxFee, fee)
|
||||
|
||||
fee = maxFee
|
||||
}
|
||||
|
||||
return fee
|
||||
}
|
||||
Reference in new issue
Block a user