Skip to content

fix: include strict bound in blocks included for calculating gas premium#6849

Merged
akaladarshi merged 4 commits intomainfrom
akaladarshi/fix-gas-premium-cal
Apr 2, 2026
Merged

fix: include strict bound in blocks included for calculating gas premium#6849
akaladarshi merged 4 commits intomainfrom
akaladarshi/fix-gas-premium-cal

Conversation

@akaladarshi
Copy link
Copy Markdown
Collaborator

@akaladarshi akaladarshi commented Apr 2, 2026

Summary of changes

Changes introduced in this pull request:

  • While calculating gas premium there should strict bound number of block included (128)

Reference issue to close (if applicable)

Closes #6825

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Outside contributions

  • I have read and agree to the CONTRIBUTING document.
  • I have read and agree to the AI Policy document. I understand that failure to comply with the guidelines will lead to rejection of the pull request.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected gas premium calculation so strict bounds are applied consistently, improving fee estimates.
    • Improved gas estimation by capping historical samples to 128 blocks and clamping input values, yielding more stable and predictable estimates.

@akaladarshi akaladarshi requested a review from a team as a code owner April 2, 2026 08:16
@akaladarshi akaladarshi requested review from LesnyRumcajs and hanabi1224 and removed request for a team April 2, 2026 08:16
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

Walkthrough

Clamp nblocksincl for GasEstimateGasPremium by introducing MAX_GAS_HISTORY = 128 and applying the bound in estimate_gas_premium; update changelog and a comment referencing Lotus v1.35.1.

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Added a "Fixed" entry documenting the stricter bound for GasEstimateGasPremium (PR #6849).
Gas Premium Estimation
src/rpc/methods/gas.rs
Added MAX_GAS_HISTORY = 128 and changed estimate_gas_premium to clamp nblocksincl to 1..=128; updated comment reference to Lotus v1.35.1.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • LesnyRumcajs
  • wjmelements
  • hanabi1224
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately and concisely describes the main change: adding a strict bound to blocks included in gas premium calculations.
Linked Issues check ✅ Passed The PR successfully implements the required strict MaxGasHistory bound (128 blocks) for GasEstimateGasPremium calculations, addressing all coding requirements from issue #6825.
Out of Scope Changes check ✅ Passed All changes are directly related to the objective: MAX_GAS_HISTORY constant introduction, clamping logic in estimate_gas_premium, and a Lotus version reference update in comments.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch akaladarshi/fix-gas-premium-cal
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch akaladarshi/fix-gas-premium-cal

Comment @coderabbitai help to get the list of available commands and usage tips.

@akaladarshi akaladarshi enabled auto-merge April 2, 2026 08:19
@akaladarshi akaladarshi added the RPC requires calibnet RPC checks to run on CI label Apr 2, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/rpc/methods/gas.rs (1)

114-118: Add boundary regression tests for the new clamp behavior.

Please add tests for nblocksincl normalization (0, 1, 128, 129) to lock in this compatibility fix and prevent regressions.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/rpc/methods/gas.rs` around lines 114 - 118, Add unit tests that exercise
the nblocksincl normalization logic around the MAX_GAS_HISTORY clamp in
src/rpc/methods/gas.rs: specifically assert that input nblocksincl values 0 and
1 normalize to 1, and that values 128 and 129 normalize to MAX_GAS_HISTORY
(e.g., 128), to lock in the compatibility fix; add these as table-driven cases
in the same test module (or a new test) with clear names like
test_nblocksincl_normalizes_zero_to_one and test_nblocksincl_clamps_above_max,
call the function or logic that performs the normalization (the code that
reads/sets nblocksincl) and assert the normalized result equals the expected
value for each case.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@CHANGELOG.md`:
- Line 48: The changelog entry references the PR number instead of the issue;
update the line that mentions "GasEstimateGasPremium" to use issue `#6825` rather
than PR `#6849` by replacing the link and bracketed number ([`#6849`](...)) with the
issue link and number ([`#6825`](...)) so the entry reads "[`#6825`]: Included
strict bound in blocks included for calculating gas premium
`GasEstimateGasPremium`." Ensure the URL points to the issue, not the PR.

---

Nitpick comments:
In `@src/rpc/methods/gas.rs`:
- Around line 114-118: Add unit tests that exercise the nblocksincl
normalization logic around the MAX_GAS_HISTORY clamp in src/rpc/methods/gas.rs:
specifically assert that input nblocksincl values 0 and 1 normalize to 1, and
that values 128 and 129 normalize to MAX_GAS_HISTORY (e.g., 128), to lock in the
compatibility fix; add these as table-driven cases in the same test module (or a
new test) with clear names like test_nblocksincl_normalizes_zero_to_one and
test_nblocksincl_clamps_above_max, call the function or logic that performs the
normalization (the code that reads/sets nblocksincl) and assert the normalized
result equals the expected value for each case.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e3fd9c2b-f58e-4e53-ac96-0b1b5401fa48

📥 Commits

Reviewing files that changed from the base of the PR and between d8c8417 and 9352106.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • src/rpc/methods/gas.rs

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.82%. Comparing base (92e96e6) to head (e6ce922).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
Files with missing lines Coverage Δ
src/rpc/methods/gas.rs 86.59% <100.00%> (-0.08%) ⬇️

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 92e96e6...e6ce922. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/rpc/methods/gas.rs (1)

114-114: Consider adding unit tests for the clamping behavior.

The clamping logic is straightforward, but adding tests for edge cases would improve confidence:

  • nblocksincl = 0 → should clamp to 1
  • nblocksincl > 128 → should clamp to 128

This could be a simple unit test for estimate_gas_premium or a dedicated test for the clamping behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/rpc/methods/gas.rs` at line 114, Add unit tests that assert the clamping
behavior of nblocksincl in estimate_gas_premium: specifically test that when
nblocksincl is 0 it clamps to 1 and when nblocksincl exceeds MAX_GAS_HISTORY
(e.g., 129) it clamps to MAX_GAS_HISTORY (128). Create tests that call
estimate_gas_premium (or a small helper that performs the clamp) with values 0,
1, MAX_GAS_HISTORY, and MAX_GAS_HISTORY+1 and verify the effective nblocksincl
used or the resulting output matches the expected clamped behavior; reference
the nblocksincl variable and MAX_GAS_HISTORY constant in assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/rpc/methods/gas.rs`:
- Line 114: Add unit tests that assert the clamping behavior of nblocksincl in
estimate_gas_premium: specifically test that when nblocksincl is 0 it clamps to
1 and when nblocksincl exceeds MAX_GAS_HISTORY (e.g., 129) it clamps to
MAX_GAS_HISTORY (128). Create tests that call estimate_gas_premium (or a small
helper that performs the clamp) with values 0, 1, MAX_GAS_HISTORY, and
MAX_GAS_HISTORY+1 and verify the effective nblocksincl used or the resulting
output matches the expected clamped behavior; reference the nblocksincl variable
and MAX_GAS_HISTORY constant in assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ffa1ac94-c697-4a7c-9457-ad9a9b9b2f37

📥 Commits

Reviewing files that changed from the base of the PR and between 9352106 and f582ca4.

📒 Files selected for processing (1)
  • src/rpc/methods/gas.rs

@akaladarshi akaladarshi added this pull request to the merge queue Apr 2, 2026
Merged via the queue into main with commit bbaf243 Apr 2, 2026
42 of 43 checks passed
@akaladarshi akaladarshi deleted the akaladarshi/fix-gas-premium-cal branch April 2, 2026 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RPC requires calibnet RPC checks to run on CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add stricter bound on GasEstimateGasPremium look-back

3 participants