Skip to content

Implement Filecoin.MpoolGetConfig and align replace_by_fee_ratio#7141

Merged
sudo-shashank merged 7 commits into
mainfrom
shashank/impl-mpool-get-config
Jun 4, 2026
Merged

Implement Filecoin.MpoolGetConfig and align replace_by_fee_ratio#7141
sudo-shashank merged 7 commits into
mainfrom
shashank/impl-mpool-get-config

Conversation

@sudo-shashank

@sudo-shashank sudo-shashank commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary of changes

Changes introduced in this pull request:

  • Implement Filecoin.MpoolGetConfig RPC to return the current mpool configuration and add parity test.
  • Add Percent type (125 = 1.25×) matching types.Percent and use it for replace_by_fee_ratio in MpoolConfig and RBF helpers.

Reference issue to close (if applicable)

Closes #7100

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

  • New Features

    • Added Filecoin.MpoolGetConfig RPC method to retrieve current mempool configuration settings.
  • Tests

    • Added test coverage for the new RPC method with test snapshots and API comparison tests.

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8ee93f76-264b-49b4-b4ec-56edb6f0615f

📥 Commits

Reviewing files that changed from the base of the PR and between 40bd22c and 2e6b0e7.

📒 Files selected for processing (1)
  • scripts/tests/api_compare/filter-list-gateway

Walkthrough

This PR implements the Filecoin.MpoolGetConfig RPC method to expose mempool configuration, introduces a Percent type shim for typed replace-by-fee ratios, and updates the CLI mpool replace --auto command to fetch and use the runtime ratio instead of a hardcoded default.

Changes

MpoolGetConfig RPC Feature

Layer / File(s) Summary
Percent type shim and Lotus JSON support
src/shim/percent.rs, src/shim/mod.rs, src/lotus_json/percent.rs, src/lotus_json/mod.rs
Introduces Percent(u64) newtype with Serde and derive-more support, implements HasLotusJson to serialize as f64 (hundredths), and adds quickcheck::Arbitrary for property-based testing.
Mempool config type updates
src/message_pool/config.rs, src/message_pool/msgpool/mod.rs, src/message_pool/msgpool/msg_pool.rs, src/message_pool/msgpool/utils.rs
Updates MpoolConfig.replace_by_fee_ratio and REPLACE_BY_FEE_RATIO_MIN from u64 to Percent, adds MessagePool::config() accessor method, and changes compute_rbf function signature to accept Percent parameter with updated tests.
MpoolGetConfig RPC method implementation
src/rpc/methods/mpool.rs, src/rpc/mod.rs
Adds ApiMpoolConfig struct with Lotus JSON field adapters for priority_addrs, replace_by_fee_ratio, and prune_cooldown; implements MpoolGetConfig RPC method returning current config; registers method in RPC dispatcher.
CLI replace command integration
src/cli/subcommands/mpool_cmd.rs
Updates Replace { auto: true } flow to fetch MpoolGetConfig and pass the runtime replace_by_fee_ratio to auto_compute_replacement_gas; adjusts function signature and all tests accordingly.
Testing and documentation
src/tool/subcommands/api_cmd/api_compare_tests.rs, src/tool/subcommands/api_cmd/test_snapshots.txt, scripts/tests/api_compare/filter-list-gateway, CHANGELOG.md
Adds RPC identity test for MpoolGetConfig, snapshot test file reference, marks method as unsupported by lotus-gateway, and adds changelog entry for the new RPC.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • ChainSafe/forest#7084: Both PRs modify the mempool CLI "replace" flow in src/cli/subcommands/mpool_cmd.rs—the main PR wires Replace auto gas estimation to the config-derived replace_by_fee_ratio via the new Filecoin.MpoolGetConfig, while the retrieved PR introduces/updates the mpool replace command and its replace-by-fee gas/RBF handling.

Suggested reviewers

  • akaladarshi
  • hanabi1224
  • LesnyRumcajs
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the two main changes: implementing MpoolGetConfig and aligning replace_by_fee_ratio to use the Percent type.
Linked Issues check ✅ Passed The PR fully addresses both requirements from #7100: implements MpoolGetConfig RPC [#7141] and updates mpool replace --auto to use runtime replace_by_fee_ratio via Percent type.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing MpoolGetConfig and refactoring replace_by_fee_ratio to Percent type; no extraneous modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 90.91% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch shashank/impl-mpool-get-config
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch shashank/impl-mpool-get-config

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@CHANGELOG.md`:
- Line 32: Replace the PR reference with the issue reference for the changelog
entry mentioning Filecoin.MpoolGetConfig: change the linked text and URL from PR
`#7141` to issue `#7100` (i.e., update the markdown line that currently reads
"[`#7141`](.../pull/7141): Implemented `Filecoin.MpoolGetConfig` RPC method." to
reference issue 7100 and its issues URL instead).

In `@src/lotus_json/percent.rs`:
- Around line 19-25: The from_lotus_json implementation must reject non-finite,
negative, or out-of-range f64 values before performing the saturating cast;
update Percent::from_lotus_json (using the lotus_json, scaled and rounded
locals) to first assert lotus_json.is_finite() and lotus_json >= 0.0 (panic on
failure), then compute scaled = lotus_json * 100.0 and keep the existing
two-decimal check, and finally ensure rounded is within 0.0..=u64::MAX as f64
(panic if not) before returning Percent(rounded as u64).
🪄 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: 3769cda7-8be1-4761-8638-18f9371af631

📥 Commits

Reviewing files that changed from the base of the PR and between 5dd3c0c and edb13ff.

⛔ Files ignored due to path filters (2)
  • src/rpc/snapshots/forest__rpc__tests__rpc__v0.snap is excluded by !**/*.snap
  • src/rpc/snapshots/forest__rpc__tests__rpc__v1.snap is excluded by !**/*.snap
📒 Files selected for processing (14)
  • CHANGELOG.md
  • src/cli/subcommands/mpool_cmd.rs
  • src/lotus_json/mod.rs
  • src/lotus_json/percent.rs
  • src/message_pool/config.rs
  • src/message_pool/msgpool/mod.rs
  • src/message_pool/msgpool/msg_pool.rs
  • src/message_pool/msgpool/utils.rs
  • src/rpc/methods/mpool.rs
  • src/rpc/mod.rs
  • src/shim/mod.rs
  • src/shim/percent.rs
  • src/tool/subcommands/api_cmd/api_compare_tests.rs
  • src/tool/subcommands/api_cmd/test_snapshots.txt

Comment thread CHANGELOG.md
Comment thread src/lotus_json/percent.rs Outdated

@coderabbitai coderabbitai Bot 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.

♻️ Duplicate comments (1)
src/lotus_json/percent.rs (1)

21-29: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Prevent saturated f64 -> i64 cast from accepting invalid large ratios

On Line 28, scaled as i64 can saturate for oversized/non-finite inputs, then still pass u64::try_from, yielding an unintended accepted value instead of a hard reject. Validate finiteness/non-negativity/range before integer casting.

💡 Proposed fix
-use std::convert::TryFrom;
@@
     fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
         let scaled = format!("{lotus_json}e2")
             .parse::<f64>()
             .expect("unable to parse ratio");
+        assert!(
+            scaled.is_finite() && scaled >= 0.0,
+            "ratio must be a finite non-negative number: {lotus_json}"
+        );
         assert!(
             scaled.trunc() == scaled,
             "ratio may only have two decimals: {lotus_json}"
         );
-        Percent(u64::try_from(scaled as i64).expect("ratio out of range"))
+        assert!(scaled <= u64::MAX as f64, "ratio out of range: {lotus_json}");
+        Percent(scaled as u64)
     }
In Rust stable, what are the exact semantics of casting `f64` to `i64` using `as` for out-of-range values, `NaN`, and infinities?
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lotus_json/percent.rs` around lines 21 - 29, The current conversion uses
`scaled as i64` which can saturate for NaN/Infinity/out-of-range values; before
casting validate that `scaled` is finite, non-negative, integral (use the
existing scaled.trunc()==scaled check) and within the i64 bounds (scaled <=
i64::MAX as f64), reject otherwise; only after those checks perform the integer
cast and then `u64::try_from` to construct `Percent` (refer to the local
variable `scaled` and the `Percent(...)` construction).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@src/lotus_json/percent.rs`:
- Around line 21-29: The current conversion uses `scaled as i64` which can
saturate for NaN/Infinity/out-of-range values; before casting validate that
`scaled` is finite, non-negative, integral (use the existing
scaled.trunc()==scaled check) and within the i64 bounds (scaled <= i64::MAX as
f64), reject otherwise; only after those checks perform the integer cast and
then `u64::try_from` to construct `Percent` (refer to the local variable
`scaled` and the `Percent(...)` construction).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 357a3b6c-0634-4ebb-8c85-0b1bde1c3296

📥 Commits

Reviewing files that changed from the base of the PR and between edb13ff and 40bd22c.

📒 Files selected for processing (2)
  • src/lotus_json/percent.rs
  • src/shim/percent.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/shim/percent.rs

@sudo-shashank sudo-shashank added the RPC requires calibnet RPC checks to run on CI label Jun 4, 2026
@sudo-shashank sudo-shashank marked this pull request as ready for review June 4, 2026 14:33
@sudo-shashank sudo-shashank requested a review from a team as a code owner June 4, 2026 14:33
@sudo-shashank sudo-shashank requested review from akaladarshi and hanabi1224 and removed request for a team June 4, 2026 14:33
@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.04478% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.34%. Comparing base (1805998) to head (2e6b0e7).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/cli/subcommands/mpool_cmd.rs 76.92% 6 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/lotus_json/mod.rs 75.00% <ø> (ø)
src/lotus_json/percent.rs 100.00% <100.00%> (ø)
src/message_pool/config.rs 90.47% <ø> (ø)
src/message_pool/msgpool/mod.rs 97.91% <ø> (ø)
src/message_pool/msgpool/msg_pool.rs 87.96% <100.00%> (+0.21%) ⬆️
src/message_pool/msgpool/utils.rs 77.58% <100.00%> (ø)
src/rpc/methods/mpool.rs 14.47% <100.00%> (+9.36%) ⬆️
src/rpc/mod.rs 89.49% <ø> (ø)
src/cli/subcommands/mpool_cmd.rs 67.52% <76.92%> (+0.25%) ⬆️

... and 16 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5dd3c0c...2e6b0e7. 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.

@sudo-shashank sudo-shashank added this pull request to the merge queue Jun 4, 2026
Merged via the queue into main with commit 1081229 Jun 4, 2026
71 of 72 checks passed
@sudo-shashank sudo-shashank deleted the shashank/impl-mpool-get-config branch June 4, 2026 21:27
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 MpoolGetConfig RPC and use runtime RBF ratio in mpool replace --auto

2 participants