Skip to content

fix: cap fee estimator bucket index#5248

Open
chenyukang wants to merge 2 commits into
nervosnetwork:developfrom
chenyukang:security/fee-estimator-bucket-limit
Open

fix: cap fee estimator bucket index#5248
chenyukang wants to merge 2 commits into
nervosnetwork:developfrom
chenyukang:security/fee-estimator-bucket-limit

Conversation

@chenyukang

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

WeightUnitsFlow derives its bucket vector length from the highest fee rate currently in the tx-pool. Extremely high fee-rate transactions can therefore make estimate_fee_rate allocate very large Vec<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 an estimate_fee_rate RPC call can cause avoidable memory and CPU amplification.

What's Changed:

Related changes

  • PR to update owner/repo:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression
  • Breaking backward compatibility

Copilot AI review requested due to automatic review settings June 17, 2026 10:47
@chenyukang chenyukang requested a review from a team as a code owner June 17, 2026 10:47
@chenyukang chenyukang requested review from quake and removed request for a team June 17, 2026 10:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_rate to 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants