From c91a62fefcdb424d39ecd5f83bec69077a2008b7 Mon Sep 17 00:00:00 2001 From: Aryan Tikarya Date: Wed, 24 Sep 2025 17:14:30 +0530 Subject: [PATCH 1/2] add chain get finalized tipset API spec --- src/rpc/methods/chain.rs | 24 +++++++++++++++++++++++- src/rpc/mod.rs | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/rpc/methods/chain.rs b/src/rpc/methods/chain.rs index 78edc95bd797..dd235a17fd6f 100644 --- a/src/rpc/methods/chain.rs +++ b/src/rpc/methods/chain.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0, MIT mod types; -use enumflags2::BitFlags; +use enumflags2::{BitFlags, make_bitflags}; use types::*; #[cfg(test)] @@ -127,6 +127,28 @@ pub(crate) fn logs( (receiver, handle) } +/// 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. +pub enum ChainGetFinalizedTipset {} +impl RpcMethod<0> for ChainGetFinalizedTipset { + const NAME: &'static str = "Filecoin.ChainGetFinalizedTipSet"; + const PARAM_NAMES: [&'static str; 0] = []; + const API_PATHS: BitFlags = 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.", + ); + + type Params = (); + type Ok = Tipset; + + async fn handle(_ctx: Ctx, (): Self::Params) -> Result { + Err(anyhow::anyhow!("ChainGetFinalizedTipset is not yet implemented").into()) + } +} + pub enum ChainGetMessage {} impl RpcMethod<1> for ChainGetMessage { const NAME: &'static str = "Filecoin.ChainGetMessage"; diff --git a/src/rpc/mod.rs b/src/rpc/mod.rs index a05735400ecf..defd30c9ff51 100644 --- a/src/rpc/mod.rs +++ b/src/rpc/mod.rs @@ -65,6 +65,7 @@ macro_rules! for_each_rpc_method { $callback!($crate::rpc::chain::ChainGetBlockMessages); $callback!($crate::rpc::chain::ChainGetEvents); $callback!($crate::rpc::chain::ChainGetGenesis); + $callback!($crate::rpc::chain::ChainGetFinalizedTipset); $callback!($crate::rpc::chain::ChainGetMessage); $callback!($crate::rpc::chain::ChainGetMessagesInTipset); $callback!($crate::rpc::chain::ChainGetMinBaseFee); From 152bcc6f8abb7f003f30b052b64c343fac29817e Mon Sep 17 00:00:00 2001 From: Aryan Tikarya Date: Wed, 24 Sep 2025 17:57:33 +0530 Subject: [PATCH 2/2] address comments --- src/rpc/methods/chain.rs | 8 ++------ src/tool/subcommands/api_cmd/test_snapshots_ignored.txt | 1 + 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/rpc/methods/chain.rs b/src/rpc/methods/chain.rs index dd235a17fd6f..b24d249c0975 100644 --- a/src/rpc/methods/chain.rs +++ b/src/rpc/methods/chain.rs @@ -127,10 +127,6 @@ pub(crate) fn logs( (receiver, handle) } -/// 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. pub enum ChainGetFinalizedTipset {} impl RpcMethod<0> for ChainGetFinalizedTipset { const NAME: &'static str = "Filecoin.ChainGetFinalizedTipSet"; @@ -138,14 +134,14 @@ impl RpcMethod<0> for ChainGetFinalizedTipset { const API_PATHS: BitFlags = 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.", + "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.", ); type Params = (); type Ok = Tipset; async fn handle(_ctx: Ctx, (): Self::Params) -> Result { - Err(anyhow::anyhow!("ChainGetFinalizedTipset is not yet implemented").into()) + Err(ServerError::stubbed_for_openrpc()) } } diff --git a/src/tool/subcommands/api_cmd/test_snapshots_ignored.txt b/src/tool/subcommands/api_cmd/test_snapshots_ignored.txt index 3a679e3e0d03..7f8b7a4da9a2 100644 --- a/src/tool/subcommands/api_cmd/test_snapshots_ignored.txt +++ b/src/tool/subcommands/api_cmd/test_snapshots_ignored.txt @@ -13,6 +13,7 @@ Filecoin.AuthNew Filecoin.AuthVerify Filecoin.ChainExport Filecoin.ChainGetEvents +Filecoin.ChainGetFinalizedTipset Filecoin.ChainSetHead Filecoin.EthEstimateGas Filecoin.EthGetFilterChanges