Skip to content

Add nonce-fix and replace mpool tools#7084

Open
sudo-shashank wants to merge 9 commits into
mainfrom
shashank/mpool-tools
Open

Add nonce-fix and replace mpool tools#7084
sudo-shashank wants to merge 9 commits into
mainfrom
shashank/mpool-tools

Conversation

@sudo-shashank
Copy link
Copy Markdown
Contributor

@sudo-shashank sudo-shashank commented May 20, 2026

Summary of changes

Changes introduced in this pull request:

  • Implement mpool nonce-fix and replace cli commands with test.
  • Fix GasPriceTooLow condition to check if gas_premium < min_price instead of gas_premium <= min_price.

Reference issue to close (if applicable)

Closes #7085
Closes #7086

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 mpool nonce-fix (auto/manual) and mpool replace (auto/manual RBF) CLI commands.
  • Documentation

    • CLI reference expanded with full nonce-fix and replace usage and options.
  • Tests

    • New integration tests for nonce-fix and replace, shared test helpers, and an additional mpool_tools test; wallet test docs broadened.
  • Chores

    • Consolidated Calibnet integration feature and updated test task invocations.
  • Other

    • Dictionary updated with two new entries.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds mpool nonce-fix and mpool replace CLI commands with helpers for nonce-fill ranges and replacement gas (including RBF enforcement), extracts compute_rbf_min_premium into msgpool utils, updates message-pool usage, adds unit and integration tests, updates test wiring, and documents the new CLI subcommands.

Changes

Mempool CLI nonce-fix and replace commands

Layer / File(s) Summary
RBF minimum premium helper extraction
src/message_pool/msgpool/utils.rs, src/message_pool/mod.rs, src/rpc/methods/gas.rs
Add compute_rbf_min_premium() in utils, re-export from message_pool at pub(crate) scope, and widen cap_gas_fee to pub(crate) for crate use.
Message pool RBF integration
src/message_pool/msgpool/msg_set.rs
Refactor MsgSet::add to call compute_rbf_min_premium() for RBF floor checks instead of inline arithmetic.
CLI mpool nonce-fix and replace commands
src/cli/subcommands/mpool_cmd.rs
Add NonceFix and Replace variants with argument parsing, implement fill-range calculation (--auto vs manual), pending-message lookup, replacement gas computation enforcing RBF and optional fee capping, and command runtimes that sign and push messages. Includes unit tests for helpers and gas logic.
Integration test infrastructure
Cargo.toml, mise.toml, tests/calibnet_wallet.rs, tests/common/calibnet_wallet_helpers.rs
Introduce unified calibnet-integration feature, add mpool_tools test target, update mise task to run both tests, and add/refactor test helpers: forest_cli, mpool_nonce, pending_nonces_for, poll_until_pending_nonce.
Mpool CLI integration tests
tests/calibnet_mpool_tools.rs
Add integration tests that exercise mpool nonce-fix --auto and mpool replace --auto, using polling helpers to assert pending-nonce state changes.
CLI reference documentation
docs/docs/users/reference/cli.md, CHANGELOG.md
Document nonce-fix and replace subcommands with usage and flags; add changelog entries for both features.
Dictionary updates
.config/forest.dic
Add RBF and signable entries and increment dictionary header count from 271 to 273.

Sequence Diagram

sequenceDiagram
  participant User
  participant CLI as forest-cli mpool
  participant RPC as Filecoin RPC (MpoolPending / ChainNonce)
  participant MsgPool as MessagePool (MsgSet / push)

  User->>CLI: run `mpool nonce-fix --auto` / `mpool replace --auto`
  CLI->>RPC: query actor nonce and MpoolPending
  CLI->>CLI: compute fill range / find pending message
  CLI->>CLI: compute_replacement_gas() -> compute_rbf_min_premium()
  CLI->>RPC: (optional) gas estimation via RPC
  CLI->>MsgPool: push signed filler or replacement messages
  MsgPool->>RPC: messages propagated to network / mempool state updated
  CLI->>User: print new CID / success
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • ChainSafe/forest#6535: Modifies MsgSet::add RBF path and relates to RBF/gas handling changes in this PR.
  • ChainSafe/forest#6983: Adds the Calibnet test helpers module; this PR extends those helpers with CLI/RPC helpers and integration tests.

Suggested reviewers

  • hanabi1224
  • akaladarshi
  • 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 describes the main change: adding two new mpool CLI subcommands (nonce-fix and replace) as referenced throughout the changeset.
Linked Issues check ✅ Passed The pull request implements all coding requirements from both linked issues: nonce-fix with auto/manual modes and integration test [#7085], replace with auto/manual gas modes and integration test [#7086], plus supporting utilities and refactoring.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the two mpool tools: CLI subcommands, helper utilities, tests, documentation, and related refactoring of RBF logic. No unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% 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/mpool-tools
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch shashank/mpool-tools

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

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: 3

🤖 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 `@docs/docs/users/reference/cli.md`:
- Line 678: Two fenced code blocks in the markdown use bare backticks (``` ) and
need explicit language tags for markdownlint MD040; update the two blocks that
currently start and end with ``` to use ```text as the opening fence so the
examples "Fill an on-chain nonce gap..." and "Replace a pending message in the
mempool..." are fenced with ```text ... ``` instead of just ```, keeping the
content unchanged and only modifying the opening fences to include the language
tag.

In `@src/cli/subcommands/mpool_cmd.rs`:
- Around line 553-564: The Manual branch should validate that gas_feecap >=
gas_premium before calling compute_replacement_gas to avoid late runtime
rejection; add a pre-check where the variables gas_premium and gas_feecap are
available (the Manual branch handling that constructs ReplaceGasInput::Manual)
and return a user-facing error if gas_feecap < gas_premium (e.g. via
context/bail/Err) so the CLI rejects the input immediately rather than letting
compute_replacement_gas or downstream code fail.
- Around line 507-523: When --cid is passed the code currently derives
sender/sequence from ChainGetMessage and then calls find_pending_message(sender,
sequence, &pending), which can match a different pending message if the nonce
was superseded; instead, in the branch where cid is Some(msg_cid) use the
pending list to locate the exact pending entry whose .cid() equals msg_cid (or
otherwise compare the Cid from MpoolPending entries) and use that entry as
original_msg; keep the ChainGetMessage/sequence logic only for the
fallback/no-cid path and ensure find_pending_message is only used when matching
by sender+nonce.
🪄 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: 93adfebf-9a5e-495c-b3ed-1bbebb33f1fe

📥 Commits

Reviewing files that changed from the base of the PR and between 3f55831 and 00255b3.

📒 Files selected for processing (12)
  • .config/forest.dic
  • Cargo.toml
  • docs/docs/users/reference/cli.md
  • mise.toml
  • src/cli/subcommands/mpool_cmd.rs
  • src/message_pool/mod.rs
  • src/message_pool/msgpool/msg_set.rs
  • src/message_pool/msgpool/utils.rs
  • src/rpc/methods/gas.rs
  • tests/calibnet_mpool_tools.rs
  • tests/calibnet_wallet.rs
  • tests/common/calibnet_wallet_helpers.rs

Comment thread docs/docs/users/reference/cli.md
Comment thread src/cli/subcommands/mpool_cmd.rs
Comment thread src/cli/subcommands/mpool_cmd.rs
@sudo-shashank sudo-shashank marked this pull request as ready for review May 20, 2026 22:09
@sudo-shashank sudo-shashank requested a review from a team as a code owner May 20, 2026 22:09
@sudo-shashank sudo-shashank requested review from akaladarshi and hanabi1224 and removed request for a team May 20, 2026 22:09
@sudo-shashank sudo-shashank added the RPC requires calibnet RPC checks to run on CI label May 20, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

❌ Patch coverage is 76.53759% with 103 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.30%. Comparing base (3b7dcd7) to head (10c1b66).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/cli/subcommands/mpool_cmd.rs 75.76% 103 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/message_pool/msgpool/msg_set.rs 95.45% <100.00%> (-0.03%) ⬇️
src/message_pool/msgpool/utils.rs 75.00% <100.00%> (+6.70%) ⬆️
src/rpc/methods/gas.rs 86.07% <100.00%> (ø)
src/cli/subcommands/mpool_cmd.rs 72.22% <75.76%> (+4.81%) ⬆️

... and 11 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 3b7dcd7...10c1b66. 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.

Comment thread docs/docs/users/reference/cli.md Outdated
Comment thread docs/docs/users/reference/cli.md Outdated
Comment thread src/cli/subcommands/mpool_cmd.rs Outdated
Comment thread src/cli/subcommands/mpool_cmd.rs Outdated
Comment thread src/cli/subcommands/mpool_cmd.rs
},
}

fn compute_replacement_gas(input: ReplaceGasInput) -> anyhow::Result<Message> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you please add clear comments/documentaion explaining what are the different calculations happening and why, so we can have clarity and verify the correct behaviour.

}

pub(crate) fn compute_rbf_min_premium(premium: &TokenAmount) -> TokenAmount {
premium + (premium * RBF_NUM).div_floor(RBF_DENOM) + TokenAmount::from_atto(1u8)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@sudo-shashank If we are matching the calculation with lotus then it doesn't match, the constant we are using has different values.

Lotus made changes here: filecoin-project/lotus@58900a7.

please verify all the constants and calculations and provide documentation for explaining if we are intentionally diverging from lotus or not. It will be helpful later on.

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.

Implement replace tool to replace a message in the mempool Implement nonce fix tool to fill mempool nonce gaps

2 participants