Skip to content

fix(rpc): bound nEpochs in StateCompute#7374

Merged
hanabi1224 merged 5 commits into
mainfrom
hm/bound-n-epochs
Jul 17, 2026
Merged

fix(rpc): bound nEpochs in StateCompute#7374
hanabi1224 merged 5 commits into
mainfrom
hm/bound-n-epochs

Conversation

@hanabi1224

@hanabi1224 hanabi1224 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary of changes

Changes introduced in this pull request:

Reference issue to close (if applicable)

Closes

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 an env-configurable upper bound for nEpochs in Forest.StateCompute, defaulting to 2,000.
    • Added concurrency limiting during state computation to improve throughput control.
  • Bug Fixes
    • Requests with nEpochs exceeding the configured maximum are now rejected early.
  • Breaking Changes
    • n_epochs / nEpochs now use NonZeroU32 for both the state compute CLI and Forest.StateCompute RPC.
  • Documentation
    • Documented FOREST_STATE_COMPUTE_MAX_RANGE (default 2,000, example 100).

@hanabi1224 hanabi1224 added the RPC requires calibnet RPC checks to run on CI label Jul 16, 2026
@hanabi1224
hanabi1224 marked this pull request as ready for review July 16, 2026 13:49
@hanabi1224
hanabi1224 requested a review from a team as a code owner July 16, 2026 13:49
@hanabi1224
hanabi1224 requested review from LesnyRumcajs and akaladarshi and removed request for a team July 16, 2026 13:49
@coderabbitai

coderabbitai Bot commented Jul 16, 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: a3256543-0d16-42b4-8b6f-b2f01408c0d3

📥 Commits

Reviewing files that changed from the base of the PR and between 60f179d and 22e88a0.

📒 Files selected for processing (1)
  • CHANGELOG.md
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md

Walkthrough

Forest.StateCompute now bounds nEpochs through a configurable environment variable and limits per-tipset processing with a shared semaphore. CLI and JSON types use NonZeroU32, with documentation and changelog entries added.

Changes

State computation limits

Layer / File(s) Summary
Align nEpochs types and serialization
src/cli/subcommands/state_cmd.rs, src/lotus_json/mod.rs, src/rpc/methods/state.rs
CLI and RPC nEpochs parameters use NonZeroU32, with Lotus JSON support for the type.
Configure and validate computation bounds
src/rpc/methods/state.rs, docs/docs/users/reference/env_variables.md, CHANGELOG.md
Forest.StateCompute reads FOREST_STATE_COMPUTE_MAX_RANGE, defaults to 2000, rejects values above the limit, uses saturating epoch arithmetic, and documents the breaking change.
Limit per-tipset execution
src/rpc/methods/state.rs
Per-tipset tasks and result processing acquire shared semaphore permits; semaphore closure produces contextual errors.

Estimated code review effort: 3 (Moderate) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ForestStateCompute
  participant Semaphore
  participant TipsetTask
  Client->>ForestStateCompute: submit nEpochs
  ForestStateCompute->>ForestStateCompute: validate configured maximum
  ForestStateCompute->>TipsetTask: spawn per-tipset computation
  TipsetTask->>Semaphore: acquire permit
  Semaphore-->>TipsetTask: permit
  TipsetTask-->>ForestStateCompute: completed tipset result
  ForestStateCompute->>Semaphore: acquire processing permit
  ForestStateCompute->>Client: return state computation result
Loading

Possibly related PRs

Suggested reviewers: akaladarshi, elmattic, lesnyrumcajs

🚥 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 title accurately summarizes the main change: bounding nEpochs in StateCompute.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hm/bound-n-epochs
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hm/bound-n-epochs

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

@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: 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/env_variables.md`:
- Line 78: In the FOREST_STATE_COMPUTE_MAX_RANGE documentation entry, correct
the description typo by changing “accpets” to “accepts” without altering the
surrounding table content.

In `@src/rpc/methods/state.rs`:
- Around line 1659-1664: Keep the semaphore permit acquired in the spawned task
alive until the corresponding compute_tipset_state call completes in the parent
loop. Propagate or retain the permit alongside the spawned task’s result, then
release it only after state computation finishes, preserving the shared
concurrency limit across concurrent Forest.StateCompute requests.
- Around line 1620-1628: Update the n_epochs conversion in the state computation
flow to use try_into() instead of an unchecked cast to ChainEpoch. Return a
contextual error if the conversion fails, while preserving the existing
maximum-range validation and successful epoch-range behavior.
🪄 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: 85218c9d-6069-485c-b8c9-d2577e6abdb6

📥 Commits

Reviewing files that changed from the base of the PR and between 5c99bb0 and 8ea038c.

📒 Files selected for processing (2)
  • docs/docs/users/reference/env_variables.md
  • src/rpc/methods/state.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)

Comment thread docs/docs/users/reference/env_variables.md Outdated
Comment thread src/rpc/methods/state.rs Outdated
Comment thread src/rpc/methods/state.rs

@LesnyRumcajs LesnyRumcajs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This a breaking change in the unlikely case that someone was using this internal (but exposed) method.

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.99%. Comparing base (5c99bb0) to head (22e88a0).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/rpc/methods/state.rs 0.00% 31 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/cli/subcommands/state_cmd.rs 0.00% <ø> (ø)
src/lotus_json/mod.rs 75.00% <ø> (ø)
src/rpc/methods/state.rs 44.06% <0.00%> (-0.66%) ⬇️

... and 12 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 5c99bb0...22e88a0. 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.

@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: 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/rpc/methods/state.rs`:
- Around line 1627-1628: Update the epoch endpoint calculation in the
surrounding RPC method to use checked addition and subtraction instead of
`from_epoch + n_epochs - 1`. Propagate a contextual error when either operation
overflows, while preserving the existing epoch range behavior for valid inputs.
🪄 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: f129f6b8-a859-4005-869d-c71a8fc5cd54

📥 Commits

Reviewing files that changed from the base of the PR and between 8ea038c and f8e51cd.

⛔ 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 (5)
  • CHANGELOG.md
  • docs/docs/users/reference/env_variables.md
  • src/cli/subcommands/state_cmd.rs
  • src/lotus_json/mod.rs
  • src/rpc/methods/state.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/docs/users/reference/env_variables.md

Comment thread src/rpc/methods/state.rs Outdated
Comment thread CHANGELOG.md Outdated
@hanabi1224
hanabi1224 enabled auto-merge July 17, 2026 08:37
@hanabi1224
hanabi1224 added this pull request to the merge queue Jul 17, 2026
Merged via the queue into main with commit c76868f Jul 17, 2026
46 checks passed
@hanabi1224
hanabi1224 deleted the hm/bound-n-epochs branch July 17, 2026 08:57
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.

2 participants