Skip to content

Conversation

@akaladarshi
Copy link
Collaborator

@akaladarshi akaladarshi commented Sep 24, 2025

Summary of changes

Changes introduced in this pull request:

  • Adding ChainGetFinalizedTipset API
  • The API is currently unimplemented only used as spec for forest-tool to generate API spec. It will be implemented in a follow up PR tracking here Implement ChainGetFinalizedTipset API #6113

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.

Summary by CodeRabbit

  • New Features

    • Added a discoverable RPC endpoint Filecoin.ChainGetFinalizedTipSet to expose the latest finalized tipset; visible in the API so clients can plan integration.
    • Endpoint description clarifies it prefers F3 finality and falls back to Expected Consensus when appropriate.
  • Chores

    • Registered the new command in the test snapshots ignore list.

@akaladarshi akaladarshi requested a review from a team as a code owner September 24, 2025 11:59
@akaladarshi akaladarshi requested review from LesnyRumcajs and sudo-shashank and removed request for a team September 24, 2025 11:59
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 24, 2025

Walkthrough

Adds a new public RPC method Filecoin.ChainGetFinalizedTipSet (no params, returns Tipset) with metadata that prefers F3 finality and may fall back to EC finality; the handler is stubbed. The method is registered in the RPC macro and added to test snapshot ignores; make_bitflags import was added.

Changes

Cohort / File(s) Summary
Chain RPC method definition
src/rpc/methods/chain.rs
Added public enum ChainGetFinalizedTipset and impl RpcMethod<0>: NAME = "Filecoin.ChainGetFinalizedTipSet", zero params, API_PATHS = make_bitflags!(ApiPaths::V1), PERMISSION = Read, updated DESCRIPTION to state F3-first then EC fallback, Params = (), Ok = Tipset, and handle returns a stubbed ServerError. Imported make_bitflags from enumflags2.
RPC method registration
src/rpc/mod.rs
Registered ChainGetFinalizedTipset in the for_each_rpc_method macro so the RPC is exposed.
Test snapshots ignore list
src/tool/subcommands/api_cmd/test_snapshots_ignored.txt
Added Filecoin.ChainGetFinalizedTipset to the list of ignored API test snapshots.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Client
  participant S as RPC Server
  participant CH as Chain RPC Handler

  C->>S: Filecoin.ChainGetFinalizedTipSet()
  S->>CH: invoke ChainGetFinalizedTipset::handle()
  note right of CH: handler is stubbed / not implemented<br/>metadata: prefer F3 finality, fallback to EC
  CH-->>S: Error (stubbed)
  S-->>C: JSON-RPC error response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "spec: Add ChainGetFinalizedTipset API" is concise and clearly identifies the primary change: adding a spec-only RPC method for ChainGetFinalizedTipset. It accurately reflects the changes which add an unimplemented RPC method, register it in the RPC module, and update test snapshot ignores. The phrasing is specific enough for reviewers to understand the PR's intent and scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch akaladarshi/add-f3-finalised-tipset-api-spec

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c91a62f and 152bcc6.

📒 Files selected for processing (2)
  • src/rpc/methods/chain.rs (2 hunks)
  • src/tool/subcommands/api_cmd/test_snapshots_ignored.txt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/rpc/methods/chain.rs
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: hanabi1224
PR: ChainSafe/forest#5944
File: src/chain/store/index.rs:0-0
Timestamp: 2025-08-18T03:09:47.932Z
Learning: In Forest's tipset_by_height caching implementation, hanabi1224 prefers performance-conscious solutions that leverage finality guarantees rather than expensive chain walking for fork detection. The approach of constraining cache lookups to finalized epochs (using CHECKPOINT_INTERVAL >= CHAIN_FINALITY) provides fork safety without the performance cost of ancestry verification.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Build Ubuntu
  • GitHub Check: Build MacOS
  • GitHub Check: cargo-publish-dry-run
  • GitHub Check: tests
  • GitHub Check: tests-release
  • GitHub Check: Build forest binaries on Linux AMD64
  • GitHub Check: All lint checks
🔇 Additional comments (1)
src/tool/subcommands/api_cmd/test_snapshots_ignored.txt (1)

16-16: Approve — confirm RPC method name casing (Tipset vs TipSet) & unignore later

Add is fine; verify the RPC method name matches the RPC registration/spec across the repo (watch Tipset vs TipSet casing). Remove from the ignore list once the handler is implemented and outputs stabilize.

Run locally:

rg -n -S -P '\bChainGetFinalizedTip[Ss]et\b|Filecoin\.ChainGetFinalizedTip[Ss]et\b' || true
rg -n -C2 -S 'ChainGetFinalizedTip' || true

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

@akaladarshi akaladarshi requested review from a team and AlexeyKrasnoperov September 24, 2025 11:59
Copy link
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: 0

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

130-150: Rename type to ChainGetFinalizedTipSet; tighten docs; align API_PATHS style.

  • Type name uses “Tipset” but the codebase consistently uses “TipSet” in public RPC type names (e.g., ChainGetTipSet). Recommend renaming for consistency and to avoid confusion.
  • Improve the doc comment grammar and casing for F3.
  • Prefer constructing BitFlags without the macro for consistency/readability.

Apply:

-/// Returns the latest finalized tipset.
-/// It uses the current F3 instance to determine the finalized tipset.
-/// If F3 is operational and finalizing in this node. If not, it will fall back
-/// to the Expected Consensus (EC) finality definition of head - 900 epochs.
+/// Returns the latest finalized tipset.
+/// Uses the current F3 instance to determine the finalized tipset when F3 is operational on this node;
+/// otherwise falls back to the Expected Consensus (EC) definition (head - 900 epochs).
-
-pub enum ChainGetFinalizedTipset {}
-impl RpcMethod<0> for ChainGetFinalizedTipset {
+pub enum ChainGetFinalizedTipSet {}
+impl RpcMethod<0> for ChainGetFinalizedTipSet {
     const NAME: &'static str = "Filecoin.ChainGetFinalizedTipSet";
     const PARAM_NAMES: [&'static str; 0] = [];
-    const API_PATHS: BitFlags<ApiPaths> = make_bitflags!(ApiPaths::V1);
+    const API_PATHS: BitFlags<ApiPaths> = BitFlags::from_flag(ApiPaths::V1);
     const PERMISSION: Permission = Permission::Read;
     const DESCRIPTION: Option<&'static str> = Some(
-        "Returns the latest finalized tipset. It uses the f3 instance or Expected Consensus (EC) definition (head - 900 epochs) to get the finalized tipset.",
+        "Returns the latest finalized tipset. It uses the F3 instance or Expected Consensus (EC) definition (head - 900 epochs) to get the finalized tipset.",
     );
 
     type Params = ();
     type Ok = Tipset;
 
     async fn handle(_ctx: Ctx<impl Blockstore>, (): Self::Params) -> Result<Self::Ok, ServerError> {
-        Err(anyhow::anyhow!("ChainGetFinalizedTipset is not yet implemented").into())
+        Err(anyhow::anyhow!("ChainGetFinalizedTipSet is not yet implemented").into())
     }
 }

5-5: Avoid importing the macro; use BitFlags::from_flag instead.

Drop make_bitflags and use BitFlags::from_flag(ApiPaths::V1) to keep imports lean and consistent with the rest of the file.

-use enumflags2::{BitFlags, make_bitflags};
+use enumflags2::BitFlags;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22d626c and c91a62f.

📒 Files selected for processing (2)
  • src/rpc/methods/chain.rs (2 hunks)
  • src/rpc/mod.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: hanabi1224
PR: ChainSafe/forest#5944
File: src/chain/store/index.rs:0-0
Timestamp: 2025-08-18T03:09:47.932Z
Learning: In Forest's tipset_by_height caching implementation, hanabi1224 prefers performance-conscious solutions that leverage finality guarantees rather than expensive chain walking for fork detection. The approach of constraining cache lookups to finalized epochs (using CHECKPOINT_INTERVAL >= CHAIN_FINALITY) provides fork safety without the performance cost of ancestry verification.
🧬 Code graph analysis (1)
src/rpc/methods/chain.rs (1)
src/rpc/methods/state.rs (16)
  • handle (109-114)
  • handle (132-138)
  • handle (151-157)
  • handle (172-178)
  • handle (196-205)
  • handle (223-231)
  • handle (248-255)
  • handle (272-282)
  • handle (298-305)
  • handle (335-465)
  • handle (484-492)
  • handle (508-538)
  • handle (555-561)
  • handle (577-597)
  • handle (615-624)
  • handle (641-663)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Build Ubuntu
  • GitHub Check: Build MacOS
  • GitHub Check: cargo-publish-dry-run
  • GitHub Check: tests-release
  • GitHub Check: tests
  • GitHub Check: All lint checks
  • GitHub Check: Build forest binaries on Linux AMD64
🔇 Additional comments (1)
src/rpc/mod.rs (1)

68-68: Ignore suggested rename — repository still uses ChainGetFinalizedTipset

The repo defines pub enum ChainGetFinalizedTipset (src/rpc/methods/chain.rs) and the registration in src/rpc/mod.rs:68 uses that same name; the suggested change to ChainGetFinalizedTipSet is not present.

Likely an incorrect or invalid review comment.

const API_PATHS: BitFlags<ApiPaths> = make_bitflags!(ApiPaths::V1);
const PERMISSION: Permission = Permission::Read;
const DESCRIPTION: Option<&'static str> = Some(
"Returns the latest finalized tipset. It uses the f3 instance or Expected Consensus (EC) definition (head - 900 epochs) to get the finalized tipset.",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Returns the latest finalized tipset. It uses the f3 instance or Expected Consensus (EC) definition (head - 900 epochs) to get the finalized tipset.",
"Returns the latest F3 finalized tipset, or falls back to EC finality if F3 is not operational on the node or if the F3 finalized tipset is further back than EC finalized tipset.",

Let's just use the text from filecoin-project/FIPs#1199?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Replaced

Comment on lines 130 to 133
/// Returns the latest finalized tipset.
/// It uses the current F3 instance to determine the finalized tipset.
/// If F3 is operational and finalizing in this node. If not, it will fall back
/// to the Expected Consensus (EC) finality definition of head - 900 epochs.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Returns the latest finalized tipset.
/// It uses the current F3 instance to determine the finalized tipset.
/// If F3 is operational and finalizing in this node. If not, it will fall back
/// to the Expected Consensus (EC) finality definition of head - 900 epochs.

redundant

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed

type Ok = Tipset;

async fn handle(_ctx: Ctx<impl Blockstore>, (): Self::Params) -> Result<Self::Ok, ServerError> {
Err(anyhow::anyhow!("ChainGetFinalizedTipset is not yet implemented").into())
Copy link
Member

Choose a reason for hiding this comment

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

There's a dedicated method for this.

forest/src/rpc/error.rs

Lines 63 to 74 in 22d626c

/// We are only including this method to get the JSON Schemas for our OpenRPC
/// machinery
pub fn stubbed_for_openrpc() -> Self {
Self::new(
4528,
"unimplemented",
Some(
"This method is stubbed as part of https://github.com/ChainSafe/forest/issues/4528"
.into(),
),
)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank 🙏, Didn't knew about this.

Done.

@sudo-shashank sudo-shashank added this pull request to the merge queue Sep 30, 2025
Merged via the queue into main with commit 4bd1056 Sep 30, 2025
63 of 64 checks passed
@sudo-shashank sudo-shashank deleted the akaladarshi/add-f3-finalised-tipset-api-spec branch September 30, 2025 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants