Skip to content

Add nonce-fix and replace mpool tools#7084

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

Add nonce-fix and replace mpool tools#7084
sudo-shashank wants to merge 19 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.
  • Updated replace-by-fee calculation to match Lotus, reducing the minimum premium bump for replacement messages from 1.25x to 1.10x. Ports filecoin-project/lotus#10416.

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 and shared test helpers for nonce-fix and replace; added mpool_tools test; wallet test doc broadened.
  • Chores

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

    • Dictionary updated with two new entries; default RBF ratio/config adjusted.

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
  • ✅ Review completed - (🔄 Check again to review again)

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
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%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 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.38554% with 98 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.43%. Comparing base (df636b3) to head (de7ac9a).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/cli/subcommands/mpool_cmd.rs 75.12% 98 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/message_pool/config.rs 90.47% <100.00%> (ø)
src/message_pool/msgpool/mod.rs 97.91% <ø> (ø)
src/message_pool/msgpool/msg_set.rs 95.45% <100.00%> (-0.03%) ⬇️
src/message_pool/msgpool/utils.rs 77.58% <100.00%> (+9.29%) ⬆️
src/rpc/methods/gas.rs 86.07% <100.00%> (ø)
src/cli/subcommands/mpool_cmd.rs 71.71% <75.12%> (+4.29%) ⬆️

... and 10 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 df636b3...de7ac9a. 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
Comment thread src/cli/subcommands/mpool_cmd.rs
Comment thread src/message_pool/msgpool/utils.rs Outdated
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

🤖 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 `@src/cli/subcommands/mpool_cmd.rs`:
- Around line 9-10: The auto RBF logic in compute_replacement_gas uses the
hardcoded REPLACE_BY_FEE_RATIO_DEFAULT when calling compute_rbf, which can
underbid if the node runs a non-default mpool ratio; instead retrieve the
runtime replace_by_fee_ratio from the mpool configuration/API (the same place
the node exposes its mpool settings), pass that value into compute_rbf, and stop
using REPLACE_BY_FEE_RATIO_DEFAULT in compute_replacement_gas (also update the
mirror occurrences around lines 196-207). Ensure you obtain the ratio before
calling compute_rbf and propagate it into cap_gas_fee/compute_rbf calls so the
auto replacement floor matches the running mpool configuration.
🪄 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: ab4093cc-db37-49c2-bc96-000c5361d5e2

📥 Commits

Reviewing files that changed from the base of the PR and between 39795f8 and 071d13e.

📒 Files selected for processing (10)
  • CHANGELOG.md
  • Cargo.toml
  • docs/docs/users/reference/cli.md
  • src/cli/subcommands/mpool_cmd.rs
  • src/message_pool/config.rs
  • src/message_pool/mod.rs
  • src/message_pool/msgpool/mod.rs
  • src/message_pool/msgpool/utils.rs
  • src/rpc/methods/gas.rs
  • tests/common/calibnet_wallet_helpers.rs
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md

Comment thread src/cli/subcommands/mpool_cmd.rs
Comment thread src/cli/subcommands/mpool_cmd.rs Outdated
Comment thread src/message_pool/config.rs
Comment thread src/cli/subcommands/mpool_cmd.rs Outdated
Comment thread src/message_pool/msgpool/mod.rs
.with_context(|| format!("no pending message found from {from} with nonce {nonce}"))
}

enum ReplaceGasInput {
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.

I missed this one earlier sorry, same goes here this is also not needed because it is also just being used to pass to the free functions.

/// using [`REPLACE_BY_FEE_RATIO_MIN`].
///
/// See <https://github.com/filecoin-project/lotus/blob/v1.36.0/chain/messagepool/messagepool.go#L210-L213>
pub(crate) fn compute_rbf_min_premium(premium: &TokenAmount) -> TokenAmount {
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.

I would have love to know why these values but I guess lotus also doesn't provide any info on these. If you know please add them.

@akaladarshi
Copy link
Copy Markdown
Collaborator

@sudo-shashank Last couple of comments, otherwise LGTM.

}

#[test]
fn nonce_fix_fill_range_auto() {
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.

You can use rstest here to be consistent.

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