fix: cap fee estimator bucket index#5248
Open
chenyukang wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Caps WeightUnitsFlow fee estimator bucket indexing to prevent extreme fee-rate transactions from triggering large bucket allocations and expensive bucket-filling loops during estimate_fee_rate.
Changes:
- Introduce maximum fee-rate and bucket-index caps for bucket sizing.
- Update
max_bucket_index_by_fee_rateto clamp very large fee rates to the highest supported bucket. - Adjust and extend unit tests to cover the new cap behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+353
to
+357
| fn max_bucket_index_by_fee_rate(fee_rate: FeeRate) -> usize { | ||
| let t = FEE_RATE_UNIT; | ||
| let index = match fee_rate.as_u64() { | ||
| let fee_rate = fee_rate.as_u64(); | ||
| if fee_rate >= MAX_BUCKET_FEE_RATE { | ||
| return MAX_BUCKET_INDEX; |
Comment on lines
+67
to
+69
| // Bucket 135 is the last explicitly defined bucket in | ||
| // `lowest_fee_rate_by_bucket_index`: 116 starts at 1_050_000 and each following | ||
| // bucket adds 50_000, so bucket 135 starts at 2_000_000 shannons/KW. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
WeightUnitsFlowderives its bucket vector length from the highest fee rate currently in the tx-pool. Extremely high fee-rate transactions can therefore makeestimate_fee_rateallocate very largeVec<u64>buffers and perform long linear bucket-filling loops.The estimator is optional and only active when configured with
WeightUnitsFlow, but once enabled, a high fee-rate valid transaction plus anestimate_fee_rateRPC call can cause avoidable memory and CPU amplification.What's Changed:
Related changes
owner/repo:Check List
Tests
Side effects