Skip to content

feat(rpc): impl Filecoin.ChainGetTipSetFinalityStatus#6811

Merged
hanabi1224 merged 20 commits intomainfrom
hm/ChainGetTipSetFinalityStatus
Apr 7, 2026
Merged

feat(rpc): impl Filecoin.ChainGetTipSetFinalityStatus#6811
hanabi1224 merged 20 commits intomainfrom
hm/ChainGetTipSetFinalityStatus

Conversation

@hanabi1224
Copy link
Copy Markdown
Contributor

@hanabi1224 hanabi1224 commented Mar 29, 2026

Summary of changes

Part of #6769

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

Release Notes

  • New Features

    • Added Filecoin.ChainGetTipSetFinalityStatus RPC method for querying tip set finality information, including EC and F3 finalization thresholds, finalized tip sets, and current chain head details.
  • Chores

    • Updated API comparison test infrastructure to reflect new method availability.

@hanabi1224 hanabi1224 added the RPC requires calibnet RPC checks to run on CI label Mar 29, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 29, 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

This PR implements the Filecoin.ChainGetTipSetFinalityStatus RPC method, exposing EC finality calculations and finalized tipset resolution. Changes include updating finality calculator constants, making the ec_finality module publicly accessible, and adding the new RPC endpoint with supporting types and test infrastructure.

Changes

Cohort / File(s) Summary
Finality Calculator Constants
src/chain/ec_finality/calculator/mod.rs
Increased BISECT_HIGH from 200 to 450, changed DEFAULT_SAFETY_EXPONENT type from i64 to i32, added DEFAULT_GUARANTEE lazy-initialized constant, and removed redundant #[allow(dead_code)] attributes.
Calculator Tests
src/chain/ec_finality/calculator/tests.rs
Replaced explicit guarantee computation with DEFAULT_GUARANTEE references and updated degraded-chain test fixture from all-2s to all-1s chain.
Module Visibility
src/chain/ec_finality/mod.rs, src/chain/mod.rs
Made calculator and ec_finality submodules publicly exported.
RPC Implementation
src/rpc/methods/chain.rs
Added new ChainGetTipSetFinalityStatus RPC method with helper functions for computing EC finality thresholds, finalized tipsets, and cached threshold lookups. Updated collection calls to collect_vec().
RPC Types
src/rpc/methods/chain/types.rs
Added ChainFinalityStatus struct with fields for EC/F3 finality data, threshold depth, and head tipset.
RPC Registration
src/rpc/mod.rs
Registered ChainGetTipSetFinalityStatus in the for_each_rpc_method! macro enumeration.
API Testing
src/tool/subcommands/api_cmd/api_compare_tests.rs, test_snapshots.txt
Added offline parameter to chain_tests() with conditional logic for ChainHead and new ChainGetTipSetFinalityStatus tests; registered snapshot.
Filter List & Documentation
scripts/tests/api_compare/filter-list-gateway, CHANGELOG.md
Added method to not-supported filter list and documented feature in changelog.

Sequence Diagram

sequenceDiagram
    actor Client
    participant RPC Handler
    participant EC Finality Calculator
    participant Blockstore/Chain
    
    Client->>RPC Handler: Filecoin.ChainGetTipSetFinalityStatus()
    RPC Handler->>RPC Handler: Check cached threshold
    alt Cache Miss
        RPC Handler->>Blockstore/Chain: Get current head tipset
        RPC Handler->>Blockstore/Chain: Walk parent epochs (building chain)
        RPC Handler->>EC Finality Calculator: find_threshold_depth(parent_epochs)
        EC Finality Calculator-->>RPC Handler: threshold_depth
        RPC Handler->>Blockstore/Chain: Get tipset at threshold height
        RPC Handler->>RPC Handler: Cache result by head
    end
    alt Both EC and F3 finalized exist
        RPC Handler->>RPC Handler: Select finalized_tip_set by epoch
    else EC only or F3 only
        RPC Handler->>RPC Handler: Use whichever is present
    end
    RPC Handler-->>Client: ChainFinalityStatus {ec_finality_threshold_depth, ec_finalized_tip_set, f3_finalized_tip_set, finalized_tip_set, head}
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • LesnyRumcajs
  • sudo-shashank
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat(rpc): impl Filecoin.ChainGetTipSetFinalityStatus' clearly and accurately summarizes the main change: implementation of a new RPC method.

✏️ 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 hm/ChainGetTipSetFinalityStatus
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hm/ChainGetTipSetFinalityStatus

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

@hanabi1224 hanabi1224 force-pushed the hm/ChainGetTipSetFinalityStatus branch from 50e2ab7 to 00abf12 Compare March 31, 2026 00:07
@hanabi1224 hanabi1224 force-pushed the hm/ChainGetTipSetFinalityStatus branch from 59f3462 to 6db0a02 Compare March 31, 2026 09:26
@hanabi1224 hanabi1224 marked this pull request as ready for review March 31, 2026 09:57
@hanabi1224 hanabi1224 requested a review from a team as a code owner March 31, 2026 09:57
@hanabi1224 hanabi1224 requested review from LesnyRumcajs and sudo-shashank and removed request for a team March 31, 2026 09:57
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: 2

🧹 Nitpick comments (2)
src/rpc/methods/chain.rs (2)

1236-1245: Redundant .clone() on tipset.

The ts is already owned from the Ok(ts) binding, so the .clone() is unnecessary.

Proposed fix
         let finalized = if depth >= 0
             && let Ok(ts) = ctx.chain_index().tipset_by_height(
                 (head.epoch() - depth).max(0),
                 head,
                 ResolveNullTipset::TakeOlder,
             ) {
-            Some(ts.clone())
+            Some(ts)
         } else {
             None
         };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/rpc/methods/chain.rs` around lines 1236 - 1245, The code constructs
`finalized` by matching `let Ok(ts) = ctx.chain_index().tipset_by_height(...)`
but then calls `ts.clone()` even though `ts` is already moved into the `Ok(ts)`
binding; remove the redundant `.clone()` and use `ts` directly when returning
`Some(ts)` in the `finalized` assignment (the change affects the block that
references `finalized`, the `let Ok(ts)` pattern,
`ctx.chain_index().tipset_by_height`, `head`, and
`ResolveNullTipset::TakeOlder`).

1261-1267: Consider async blocking for cache miss path.

On a cache miss, get_finality_status walks ~905 epochs through the blockstore and runs a binary search with floating-point probability calculations via find_threshold_depth. While blockstore lookups are cached and the binary search is bounded (O(log 450)), this synchronous work could briefly block the async runtime on every new block when the cache invalidates.

Cache hits will be frequent in practice since the cache invalidates only when heaviest_tipset changes, which happens infrequently compared to typical RPC request rates. However, if high RPC concurrency is a concern for your load patterns, consider using tokio::task::spawn_blocking for the cache miss path, consistent with similar CPU-bound work like eth.rs::execution_trace.

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

In `@src/rpc/methods/chain.rs` around lines 1261 - 1267, The handler currently
calls get_finality_status synchronously inside handle, which can perform heavy
CPU/blocking work on cache misses; change handle to offload that work to a
blocking thread by invoking tokio::task::spawn_blocking (or equivalent) for
get_finality_status and awaiting its JoinHandle so the async runtime isn't
blocked on the ~905-epoch walk and binary search; update the handle function to
call spawn_blocking(|| Self::get_finality_status(&ctx)) and await the result,
mirroring the pattern used for other CPU-bound work like
eth.rs::execution_trace.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/chain/ec_finality/calculator/mod.rs`:
- Around line 27-29: Update the test comment in the EC finality calculator tests
to reflect the new BISECT_HIGH value (450) instead of 200: locate the comment
above the all-ones chain test in tests.rs (referencing the BISECT/BisectHigh
behavior) and change its text to mention "BisectHigh=450" or "BISECT_HIGH=450"
(e.g., "// All-1s chain is too degraded to achieve 2^-30 within the bisect
search range (BisectHigh=450), so threshold is not found"); no logic changes
needed—the test already references the BISECT_HIGH constant.

In `@src/rpc/methods/chain/types.rs`:
- Around line 14-16: The doc comment block above the type that begins "Describes
how the node is currently determining finality" has a regular comment line ("//
combining probabilistic...") which breaks the doc comment flow; change that line
to a doc comment ("/// combining probabilistic...") so the entire comment block
is contiguous and will appear in generated documentation for the associated
type/enum in types.rs.

---

Nitpick comments:
In `@src/rpc/methods/chain.rs`:
- Around line 1236-1245: The code constructs `finalized` by matching `let Ok(ts)
= ctx.chain_index().tipset_by_height(...)` but then calls `ts.clone()` even
though `ts` is already moved into the `Ok(ts)` binding; remove the redundant
`.clone()` and use `ts` directly when returning `Some(ts)` in the `finalized`
assignment (the change affects the block that references `finalized`, the `let
Ok(ts)` pattern, `ctx.chain_index().tipset_by_height`, `head`, and
`ResolveNullTipset::TakeOlder`).
- Around line 1261-1267: The handler currently calls get_finality_status
synchronously inside handle, which can perform heavy CPU/blocking work on cache
misses; change handle to offload that work to a blocking thread by invoking
tokio::task::spawn_blocking (or equivalent) for get_finality_status and awaiting
its JoinHandle so the async runtime isn't blocked on the ~905-epoch walk and
binary search; update the handle function to call spawn_blocking(||
Self::get_finality_status(&ctx)) and await the result, mirroring the pattern
used for other CPU-bound work like eth.rs::execution_trace.
🪄 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: 3713c0e0-a502-4285-a18b-3d12c21fceb8

📥 Commits

Reviewing files that changed from the base of the PR and between d52a294 and 6db0a02.

⛔ Files ignored due to path filters (1)
  • src/rpc/snapshots/forest__rpc__tests__rpc__v2.snap is excluded by !**/*.snap
📒 Files selected for processing (11)
  • scripts/tests/api_compare/.env
  • scripts/tests/api_compare/filter-list-gateway
  • src/chain/ec_finality/calculator/mod.rs
  • src/chain/ec_finality/calculator/tests.rs
  • src/chain/ec_finality/mod.rs
  • src/chain/mod.rs
  • src/rpc/methods/chain.rs
  • src/rpc/methods/chain/types.rs
  • src/rpc/mod.rs
  • src/tool/subcommands/api_cmd/api_compare_tests.rs
  • src/tool/subcommands/api_cmd/test_snapshots.txt

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 83.72093% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.04%. Comparing base (733c7fe) to head (5942523).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/rpc/methods/chain.rs 83.52% 13 Missing and 1 partial ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/chain/ec_finality/calculator/mod.rs 92.19% <100.00%> (+0.03%) ⬆️
src/chain/mod.rs 75.00% <ø> (ø)
src/rpc/mod.rs 89.20% <ø> (ø)
src/rpc/methods/chain.rs 55.68% <83.52%> (+2.50%) ⬆️

... and 13 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 733c7fe...5942523. 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.

@LesnyRumcajs
Copy link
Copy Markdown
Member

no green checkmark, no review!

@hanabi1224 hanabi1224 mentioned this pull request Apr 3, 2026
6 tasks
@hanabi1224 hanabi1224 requested a review from LesnyRumcajs April 7, 2026 11:54
@hanabi1224 hanabi1224 enabled auto-merge April 7, 2026 22:41
@hanabi1224 hanabi1224 added this pull request to the merge queue Apr 7, 2026
Merged via the queue into main with commit 19d1045 Apr 7, 2026
56 checks passed
@hanabi1224 hanabi1224 deleted the hm/ChainGetTipSetFinalityStatus branch April 7, 2026 23:01
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