Skip to content

feat(rpc): integrate ec finality calulator into Eth TipsetResolver#6897

Merged
LesnyRumcajs merged 5 commits intomainfrom
hm/ec-finality-calculator-integration
Apr 14, 2026
Merged

feat(rpc): integrate ec finality calulator into Eth TipsetResolver#6897
LesnyRumcajs merged 5 commits intomainfrom
hm/ec-finality-calculator-integration

Conversation

@hanabi1224
Copy link
Copy Markdown
Contributor

@hanabi1224 hanabi1224 commented Apr 13, 2026

Summary of changes

Changes introduced in this pull request:

Reference issue to close (if applicable)

Closes #6769

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

  • Changed

    • Integrated expected-consensus finality into Ethereum RPC methods and chain methods.
    • Refactored finalized tipset resolution to use centralized finality status computation with cached results and fallback handling.
  • Tests

    • Updated API test snapshots and test coverage for finalized tipset resolution.

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

coderabbitai Bot commented Apr 13, 2026

Walkthrough

This PR integrates EC (Expected Consensus) finality resolution into RPC tipset resolution paths, makes the EC finality helper public, updates tipset resolver and chain RPC usage to call that helper, adjusts module visibility for tipset_resolver, and updates related tests and snapshot filenames.

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Added entry noting EC finality integration into Eth RPC methods.
RPC — Chain finality
src/rpc/methods/chain.rs
Replaced older F3-vs-EC fallback logic with a direct call to ChainGetTipSetFinalityStatus::get_finality_status(...).finalized_tip_set; made get_ec_finality_threshold_depth_and_tipset_with_cache public; use head.shallow_clone() in finality computation and loosened final fallback to tipset_by_height(..., head, ResolveNullTipset::TakeOlder).ok().
RPC — Eth tipset resolver
src/rpc/methods/eth/tipset_resolver.rs, src/rpc/methods/eth.rs
tipset_resolver module visibility changed to pub mod tipset_resolver;; get_ec_finalized_tipset now delegates to the chain finality helper (get_ec_finality_threshold_depth_and_tipset_with_cache) and wraps errors with context.
Tests & Snapshots
src/tool/subcommands/api_cmd/api_compare_tests.rs, src/tool/subcommands/api_cmd/test_snapshots.txt
Moved ChainGetFinalizedTipset RPC test from per-tipset generation to a single global chain test; updated two snapshot filenames.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant EthRPC as Eth RPC
  participant TipsetResolver as TipsetResolver
  participant Finality as ChainGetTipSetFinalityStatus
  participant Chain as Chain / TipsetLookup
  Client->>EthRPC: eth_getFinalizedTipset request
  EthRPC->>TipsetResolver: resolve tipset
  TipsetResolver->>Finality: get_ec_finality_threshold_depth_and_tipset_with_cache(ctx, head)
  Finality->>Chain: compute/lookup tipset (may call tipset_by_height)
  Chain-->>Finality: tipset (or None)
  Finality-->>TipsetResolver: finalized tipset (Option)
  TipsetResolver-->>EthRPC: resolved tipset or error
  EthRPC-->>Client: response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • sudo-shashank
  • LesnyRumcajs
  • akaladarshi
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: integrating the EC finality calculator into the Eth TipsetResolver, which is reflected across multiple files in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 80.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 hm/ec-finality-calculator-integration
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hm/ec-finality-calculator-integration

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

@hanabi1224 hanabi1224 marked this pull request as ready for review April 13, 2026 12:50
@hanabi1224 hanabi1224 requested a review from a team as a code owner April 13, 2026 12:50
@hanabi1224 hanabi1224 requested review from LesnyRumcajs and sudo-shashank and removed request for a team April 13, 2026 12:50
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/rpc/methods/chain.rs (1)

1157-1174: ⚠️ Potential issue | 🟡 Minor

Document the newly public cache helper.

This helper is now pub, but its contract is non-obvious: the cache is process-global, keyed by head, and -1/None mean calculator failure rather than “no finalized tipset”. Please add a doc comment before exposing it cross-module.

As per coding guidelines, "Document public functions and structs with doc comments".

🤖 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 1157 - 1174, Add a doc comment above
the newly pub function get_ec_finality_threshold_depth_and_tipset_with_cache
describing its contract: that it uses a process-global cache (the static CACHE)
keyed only by the provided head Tipset, that it returns (i64, Option<Tipset>)
where a value of -1 for the i64 and None for the Tipset indicate a calculation
failure (not “no finalized tipset”), and note that the cached Tipset is
shallow-cloned and callers should not assume ownership semantics; include brief
notes on thread-safety (parking_lot Mutex) and that ctx is used for underlying
calculation.
🧹 Nitpick comments (2)
CHANGELOG.md (1)

40-40: Prefer explicit “expected-consensus (EC) finality” wording in changelog text.

This improves terminology consistency and avoids ambiguity for external readers.

✏️ Proposed wording
-- [`#6897`](https://github.com/ChainSafe/forest/pull/6897): Integrated EC finality into Eth RPC methods.
+- [`#6897`](https://github.com/ChainSafe/forest/pull/6897): Integrated expected-consensus (EC) finality into Eth RPC methods.

Based on learnings: In the Forest codebase, ec in function names stands for "expected-consensus", and docs/descriptions should use "expected-consensus finality".

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

In `@CHANGELOG.md` at line 40, Update the changelog entry for PR `#6897` to replace
the ambiguous "EC finality" wording with the explicit phrase "expected-consensus
(EC) finality" (or "expected-consensus finality" depending on style) so the line
reading "[`#6897`]: Integrated EC finality into Eth RPC methods." becomes
"[`#6897`]: Integrated expected-consensus (EC) finality into Eth RPC methods." to
match the codebase convention where "ec" stands for expected-consensus.
src/rpc/methods/eth/tipset_resolver.rs (1)

186-198: Move this fallback helper out of eth::tipset_resolver.

This is generic chain-finality logic, but its current location forces src/rpc/methods/chain.rs to depend on an ETH-specific module. I'd keep it next to ChainGetTipSetFinalityStatus or in a small shared finality helper so both RPC paths reuse it without reversing the dependency direction.

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

In `@src/rpc/methods/eth/tipset_resolver.rs` around lines 186 - 198, The helper
get_fallback_ec_finalized_tipset currently lives in eth::tipset_resolver,
creating an unnecessary ETH-specific dependency for chain RPCs; move this
function into a shared finality helper module (or next to the
ChainGetTipSetFinalityStatus implementation) and update callers to import it
from that new module instead of eth::tipset_resolver. Ensure the function
signature and generic DB bound remain identical (pub fn
get_fallback_ec_finalized_tipset<DB: Blockstore>(cs: &ChainStore<DB>) ->
anyhow::Result<Tipset>) so ChainGetTipSetFinalityStatus and any ETH callers
simply change their use site import, and remove the eth module dependency from
src/rpc/methods/chain.rs.
🤖 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/rpc/methods/chain.rs`:
- Around line 1073-1076: The method currently returns a fallback tipset from
crate::rpc::eth::tipset_resolver::get_fallback_ec_finalized_tipset(ctx.chain_store())
when ChainGetTipSetFinalityStatus::get_finality_status(ctx) yields None, but the
status response still reports finalized_tip_set = None; update
ChainGetTipSetFinalityStatus::get_finality_status (or its caller) so that when
the calculator returns None you either (a) populate finalized_tip_set with the
fallback tipset returned by get_fallback_ec_finalized_tipset, or (b) add and
populate an explicit fallback/source field in the status response indicating the
returned fallback tipset and its origin; ensure you reference
ChainGetTipSetFinalityStatus::get_finality_status and
crate::rpc::eth::tipset_resolver::get_fallback_ec_finalized_tipset(ctx.chain_store())
when making the change so the two RPCs cannot disagree.

---

Outside diff comments:
In `@src/rpc/methods/chain.rs`:
- Around line 1157-1174: Add a doc comment above the newly pub function
get_ec_finality_threshold_depth_and_tipset_with_cache describing its contract:
that it uses a process-global cache (the static CACHE) keyed only by the
provided head Tipset, that it returns (i64, Option<Tipset>) where a value of -1
for the i64 and None for the Tipset indicate a calculation failure (not “no
finalized tipset”), and note that the cached Tipset is shallow-cloned and
callers should not assume ownership semantics; include brief notes on
thread-safety (parking_lot Mutex) and that ctx is used for underlying
calculation.

---

Nitpick comments:
In `@CHANGELOG.md`:
- Line 40: Update the changelog entry for PR `#6897` to replace the ambiguous "EC
finality" wording with the explicit phrase "expected-consensus (EC) finality"
(or "expected-consensus finality" depending on style) so the line reading
"[`#6897`]: Integrated EC finality into Eth RPC methods." becomes "[`#6897`]:
Integrated expected-consensus (EC) finality into Eth RPC methods." to match the
codebase convention where "ec" stands for expected-consensus.

In `@src/rpc/methods/eth/tipset_resolver.rs`:
- Around line 186-198: The helper get_fallback_ec_finalized_tipset currently
lives in eth::tipset_resolver, creating an unnecessary ETH-specific dependency
for chain RPCs; move this function into a shared finality helper module (or next
to the ChainGetTipSetFinalityStatus implementation) and update callers to import
it from that new module instead of eth::tipset_resolver. Ensure the function
signature and generic DB bound remain identical (pub fn
get_fallback_ec_finalized_tipset<DB: Blockstore>(cs: &ChainStore<DB>) ->
anyhow::Result<Tipset>) so ChainGetTipSetFinalityStatus and any ETH callers
simply change their use site import, and remove the eth module dependency from
src/rpc/methods/chain.rs.
🪄 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: b2fed9de-89e3-414d-aaf0-f2069cbcd242

📥 Commits

Reviewing files that changed from the base of the PR and between be0d0db and fb64974.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • src/rpc/methods/chain.rs
  • src/rpc/methods/eth.rs
  • src/rpc/methods/eth/tipset_resolver.rs
  • src/tool/subcommands/api_cmd/api_compare_tests.rs
  • src/tool/subcommands/api_cmd/test_snapshots.txt

Comment thread src/rpc/methods/chain.rs Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 68.42105% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.12%. Comparing base (be0d0db) to head (94e4e9b).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/rpc/methods/eth/tipset_resolver.rs 0.00% 6 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/rpc/methods/chain.rs 56.66% <100.00%> (+0.75%) ⬆️
src/rpc/methods/eth.rs 65.26% <ø> (ø)
src/rpc/methods/eth/tipset_resolver.rs 60.81% <0.00%> (+0.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 be0d0db...94e4e9b. 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!

@LesnyRumcajs LesnyRumcajs added this pull request to the merge queue Apr 14, 2026
Merged via the queue into main with commit 7e7196b Apr 14, 2026
104 of 107 checks passed
@LesnyRumcajs LesnyRumcajs deleted the hm/ec-finality-calculator-integration branch April 14, 2026 08:33
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.

feat: port Lotus PR #13547 - integrate EC finality calculator into API and Eth RPC (FRC-0089)

2 participants