Repository navigation
fees: return block_policy fee rate estimate when mempool_policy is not ready - #36182
ismaelsadeeq wants to merge 5 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/36182. ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. LLM Linter (✨ experimental)Possible places where named args for integral literals may be used (e.g.
2026-09-28 09:21:25 |
|
Concept ACK |
|
Concept ACK Are we too late to get this for v32? Would be nice to fix this, specially case 1 if #34075 is getting into v32. |
Not too late. Fixes can also still be made after branch off, if it not ends up making it in by the 10th. |
There was a problem hiding this comment.
reviewed b5c1242
Overall the patch looks pretty good to me :)
b5c1242 to
a089204
Compare
|
Concept ACK I'm not sure how useful it is to fallback to the block policy estimator for fresh starts as it also requires seeing a number of blocks before it works. However, I think it makes sense to fallback to block policy if it is available and mempool policy is not. |
jeanpablojp
left a comment
There was a problem hiding this comment.
Concept ACK
A question on the warm-up. The window keeps three of the six pre-restart blocks, and GetMempoolHealthCheck sums across the whole window, so those three still carry the ratio. Sweeping the three fresh blocks that follow, the check turns healthy once they reach 50% coverage, with the retained blocks fully covered and of the same weight, against 75% for a window of six fresh blocks.
So how far the bar drops is set by the blocks on their way out, not by the fresh ones being measured against it. Is that intended?
doc/release-notes-34075.md and one test comment still describe the old behaviour. Worth updating them here?
the two places
The release note still says the combined estimate returns an error when too few recent blocks have been observed, and the comment above the restart in test_estimatesmartfee_return_mempool_estimates says the same.
a089204 to
abd2982
Compare
|
re: #36182 (review) AFAICT, it's the same moving mempool representation ratio, now used as a proxy for mempool inflow. The same assumption holds even before a restart: if the first 3 blocks have 100% coverage, we only need 50% from the next 3 to stay healthy. In the case you mentioned, 100% coverage before and then 50% after is a good sign your peers are relaying with sane policy rules, and the drop in coverage is most likely just your own lost mempool so using it for fee estimation won't be wildly off. I fixed the docs as you suggested. The CI failure seems unrelated. Thanks for the review. |
pseudoramdom
left a comment
There was a problem hiding this comment.
Concept ACK. Left a few comments.
| "\"none\" returns the lower of the block policy and mempool estimates. If the mempool\n" | ||
| "estimate is unavailable, it returns that error instead of falling back to the block\n" | ||
| "policy estimate; use \"block_policy\" in that case to get the block policy estimate.\n" | ||
| "\"none\" (the default) combines both estimators, returning the lower of the block policy and\n" |
There was a problem hiding this comment.
Unrelated to this PR -
It's weird that setting none uses all available estimators. This should probably have been called auto or combined and the enum case to be FeeRateEstimatorType::AUTOMATIC
|
Forced pushed 651b0a9db877..86ef5cc277
|
|
Approach ACK. I was feeling very uneasy about the amount of complexity (process flow more so than code) being tacked on in the state prior to the latest force-push (352283b..86ef5cc). I think the current approach of simply erroring (and falling back to block policy) whenever the mempool seems like it can't produce an estimate is the best choice for this backport. Solving the biggest problem with the least amount of complexity. There are now a few quirks with empty percentiles never resulting in a mempool estimate, but I think their impact is limited enough that this remains a good approach. Some quirks:
I would prefer addressing these in a follow-up where we have less time pressure to find a good solution. nit: the message of 247d470 still says the change is necessary for "the warmup fallback", which is no longer part of this PR. |
| const FeePerVSize feerate_estimate{conservative ? percentiles.p50 : percentiles.p75}; | ||
| // An empty percentile means the mempool was too sparse to fill that fraction of a block. | ||
| if (feerate_estimate.IsEmpty()) { | ||
| return EstimationError(strprintf("%s: Insufficient mempool transaction data", FeeRateEstimatorTypeToString(estimator_type))); |
There was a problem hiding this comment.
86ef5cc (fees: return an error instead of a floored mempool fee rate estimate)
In the case of a node with a healthy view of the mempool, but a mempool that has less than a p50 or p75 of transactions, don't we actually want to return the floored estimate instead of falling back to the block policy estimator. Not frequent but from looking at the mempool.space chart it has happened as recently as February of this year on mainnet:
And I also imagine this will in practice make the mempool estimator never engage on testnet/signet.
Question: why can't we just rely on the mempool health metrics here?
What are the odds that someone loads a mempool.dat that happens to do a good job matching the catch-up blocks during loading and that someone asks for a fee estimate during that time? And the current approach will only stop the fee estimate if that happens and at the same time the mempool happens to be kind of empty around the time the fee is being requested which isn't necessarily the case.
I wonder if maybe a check should be added to GetMempoolHealth() that the current tip height is close to the best known header or something like that but I'll have to look closer tomorrow.
There was a problem hiding this comment.
Valid observation, we do want to return the floor in that case, but as it is now, we do not have a correct and final approach mechanism that differentiates whether we are indeed empty, have just connected, have lots of our mempool, on testnets etc. So a valid e2e fix can be pursued in a follow-up, given that it is very infrequent, this minimal fix is okay, I think.
There was a problem hiding this comment.
I'm not sure I agree, I think it would be better to drop the last two commits entirely from this PR, since it only sometimes fixes a problem that likely no one will ever run into:
- Fee misestimation because a user starts their node after a day off and their mempool.dat happened to be healthy for 6 blocks in a row (I think this is the thing that's most unlikely) and they request a feerate at that time and it happens that at that time their mempool is nearly empty [if not nearly empty the mempool estimator will still return a stale estimate]
And creates a problem that all users will run into infrequently:
- Overestimating fees whenever the mempool is starved.
The actual fix would be to use a heuristic to decide whether or not we are at or close to the tip, and only return a block estimate then. I think using mempool is empty as a proxy for mempool is stale both produces false positives e.g. when the mempool is actually <3MvB and I suspect produces lots of false negatives, i.e. I suspect that if you restart a node after a few hours or a day of being offline that it will happen quite often that the mempool does not drain but I would have to check that it's just an assumption.
86ef5cc to
3f68d2c
Compare
|
Forced pushed 86ef5cc...3f68d2c to address feedback by @stickies-v and @davidgumberg
|
|
I’m generally happy with the PR now. One API naming question before 32.0: should we rename I know it's not been introduced here, but this PR might be our best chance to fix the public name before 32.0 is released... As we coerce all unknown values to It could also be it's own tiny "bugfix" PR perhaps, too. Happy to ACK this with or without that change, but wanted to see what folks reviewing this thought. |
3f68d2c to
dd85315
Compare
|
Forced pushed 3f68d2c...dd85315 I added a commit here to fix #36182 (comment) |
"none" read as though fee estimation was disabled, when it actually selects the default combined behavior: the lower of the block policy and mempool fee rate estimates, falling back to the block policy estimate when the mempool estimator can't produce one. Rename the public value (and the FeeRateEstimatorType::NONE enumerator) to "auto", which describes what it does. Unknown values are still treated as to auto, so the previous "none" spelling works.
…mate When the mempool policy estimator cannot produce an estimate, GetFeeRateEstimate() now returns the block policy estimate rather than an error. The combined estimate starts from the block policy estimate and lowers it with the mempool estimate only when present, so the fallback path shares the log that reports the selected fee rate. An error is returned only when the block policy estimate itself is unavailable.
When the mempool fails to load at startup (persistence disabled, or a missing or corrupt mempool.dat), init notifies the fee_rate_estimator_man, which clears its tracked mined-block window. Otherwise the estimator would keep a window describing a mempool the node no longer has and, once the mempool refilled, serve an estimate built on it. Clearing makes the estimator report insufficient data until the window refills from the current tip, so the combined estimate falls back to the block policy estimate meanwhile.
Hoist the Percentiles struct to file scope and cache the raw p50/p75 percentiles, applying the relay floor on each call rather than caching the already-floored conservative/economical fee rates. The template build moves into GetOrBuildPercentiles(). Flooring per call lets a later commit tell an unfilled percentile apart from a floored one, so it can return an error instead of the floor and let the combined estimate fall back to the block policy estimate.
When the block template does not fill both the 50th and 75th percentiles of a block, EstimateFeeRate() returns an error rather than flooring the estimate to the higher of the minimum relay fee and the mempool minimum fee, so the combined estimator falls back to the block policy estimate. Both percentiles are required together so the economical (p75) estimate cannot end up above the conservative (p50) one, which could happen if only p50 were served while p75 fell back to the block policy estimate.
dd85315 to
eb28c15
Compare
|
@davidgumberg raised a concern that, with the last two commits, we may overestimate for everyone when the mempool is empty (see thread: #36182 (comment)). My rationale for including those two commits before 32.0 is that they preserve the status quo: an empty mempool occurs rarely, whereas users restarting after a while and losing their transaction backlog happens more often. However, an empty mempool is also a valid state and with the last two commits when it occur we overestimate for everyone else. I discussed this offline with @davidgumberg, and we concluded that the core issue is being able to distinguish a genuinely empty mempool from a missing backlog. We decided to move forward with the first three commits and discuss the issue further and also these are very edge cases that may not warrant the energy. I split the PR and converted this one into a draft. The first three commits are, IMO, what should be in the 32.x milestone. Thanks for the review and feedback, all. |
5b77288 fees: clear mined-block stats when the mempool load fails (ismaelsadeeq) c0b7ca3 fees: fall back to block_policy when the mempool estimator can't estimate (ismaelsadeeq) 4056908 fees: rename the default fee_rate_estimator value to "auto" (ismaelsadeeq) Pull request description: This is split from #36182 to allow review of the first three commits that we want to backport to 32.x. This is a simple PR that does three things: 1. A minor, non-breaking `estimatesmartfee` API update: it renames the default estimator option from "none" to "auto". See the rationale here: #36182 (comment) 2. Falls back to the `block_policy` fee rate estimator when `mempool_policy` is not available. This preserves the previous behavior and lets users who update their node keep using `block_policy` estimates until the mempool policy has finished gathering stats and is ready to serve estimates. 3. After a restart in which mempool loading fails, we clear the data gathered by the mempool fee rate estimator, to prevent it from returning the fee rate floor just because the node lost its mempool transactions. ACKs for top commit: davidgumberg: re-crACK 5b77288 achow101: ACK 5b77288 willcl-ark: reACK 5b77288 w0xlt: ACK 5b77288 Tree-SHA512: 4e5742899992ae6d0f062e436ed4da159896b02b7c60ce6aec0d2e4beb635e922d34154995256d33972e77269f5e60141432d6276df58e2e8b75300d3043de83
|
🐙 This pull request conflicts with the target branch and needs rebase. |
…nor api change 5b77288673e2b74de1512180a8911f435311ca7a fees: clear mined-block stats when the mempool load fails (ismaelsadeeq) c0b7ca3dbdbaecdd045c8a36d9758470358880a0 fees: fall back to block_policy when the mempool estimator can't estimate (ismaelsadeeq) 4056908f0feae2a1caf9b53cfbe77bb8091246c9 fees: rename the default fee_rate_estimator value to "auto" (ismaelsadeeq) Pull request description: This is split from #36182 to allow review of the first three commits that we want to backport to 32.x. This is a simple PR that does three things: 1. A minor, non-breaking `estimatesmartfee` API update: it renames the default estimator option from "none" to "auto". See the rationale here: bitcoin/bitcoin#36182 (comment) 2. Falls back to the `block_policy` fee rate estimator when `mempool_policy` is not available. This preserves the previous behavior and lets users who update their node keep using `block_policy` estimates until the mempool policy has finished gathering stats and is ready to serve estimates. 3. After a restart in which mempool loading fails, we clear the data gathered by the mempool fee rate estimator, to prevent it from returning the fee rate floor just because the node lost its mempool transactions. ACKs for top commit: davidgumberg: re-crACK bitcoin/bitcoin@5b77288 achow101: ACK 5b77288673e2b74de1512180a8911f435311ca7a willcl-ark: reACK 5b77288673e2b74de1512180a8911f435311ca7a w0xlt: ACK 5b77288673e2b74de1512180a8911f435311ca7a Tree-SHA512: 4e5742899992ae6d0f062e436ed4da159896b02b7c60ce6aec0d2e4beb635e922d34154995256d33972e77269f5e60141432d6276df58e2e8b75300d3043de83
|
Closing this due to the merge of the minimal approach in #36365, mempool backlog concerns and recovery discussed here can be revisited. I am not working on it at the moment, but I will review any related work or may pick it up again. |
The first commit of this PR has a minor non breaking API change, it renames the
estimatesmartfeedefault estimator option name from "none" to "auto"The mempool fee rate estimator can't always return an estimate:
i) right after first startup (or after re-syncing through IBD) it hasn't tracked
enough recent blocks yet;
ii) the mempool is empty or too sparse to fill the requested block percentile,
e.g. after a cold restart with persistence off or a missing/corrupt
mempool.dat.
iii) recent blocks cover too little of the mempool (low coverage); and
iv) the mempool is still loading.
Previously, case (ii) with a healthy mempool will returned the fee rate
floor (the higher of the minimum relay fee and the current mempool minimum fee).
This can be a significant underestimation, since the now-missing mempool may have
held much higher-feerate transactions. The remaining cases surfaced the mempool
error directly from the combined estimate.
This PR makes the combined estimate (
estimatesmartfeewithfee_rate_estimator=none, the default) fall back to the block policy estimatewhenever the mempool estimator isn't ready, instead of returning the floor or
surfacing the error:
percentile, so an empty/sparse mempool is treated like any other not-ready
state rather than potentially silently underestimating.
with the mempool estimate when one is available. An error is returned only when
the block policy estimate itself is unavailable.
estimatesmartfeewithfee_rate_estimator=mempool_policyexplicitlystill returns the failure.
When the mempool fails to load at startup (persistence off, or a missing/corrupt
mempool.dat), init notifies the estimator, which clears its tracked mined-block
window. Otherwise the estimator would keep a window describing a mempool the node
no longer has; clearing it makes the estimator report insufficient data until the
window refills from the current tip, so the combined estimate falls back to block
policy meanwhile.
This is an alternative to #36095.