diff --git a/CHANGELOG.md b/CHANGELOG.md index 280c9b7b187d..e94e2ef8abdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,8 @@ - [#6403](https://github.com/ChainSafe/forest/pull/6403) Implemented `Filecoin.EthGetBalance` for API v2. +- [#6404](https://github.com/ChainSafe/forest/pull/6404) Implemented `Filecoin.EthGetBlockByNumber` for API v2. + ### Changed - [#6368](https://github.com/ChainSafe/forest/pull/6368): Migrated build and development tooling from Makefile to `mise`. Contributors should install `mise` and use `mise run` commands instead of `make` commands. diff --git a/src/rpc/methods/eth.rs b/src/rpc/methods/eth.rs index 7e75961fd009..5af30750bace 100644 --- a/src/rpc/methods/eth.rs +++ b/src/rpc/methods/eth.rs @@ -1620,6 +1620,28 @@ impl RpcMethod<2> for EthGetBlockByNumber { } } +pub enum EthGetBlockByNumberV2 {} +impl RpcMethod<2> for EthGetBlockByNumberV2 { + const NAME: &'static str = "Filecoin.EthGetBlockByNumber"; + const NAME_ALIAS: Option<&'static str> = Some("eth_getBlockByNumber"); + const PARAM_NAMES: [&'static str; 2] = ["blockParam", "fullTxInfo"]; + const API_PATHS: BitFlags = make_bitflags!(ApiPaths::V2); + const PERMISSION: Permission = Permission::Read; + + type Params = (ExtBlockNumberOrHash, bool); + type Ok = Block; + + async fn handle( + ctx: Ctx, + (block_param, full_tx_info): Self::Params, + ) -> Result { + let ts = tipset_by_block_number_or_hash_v2(&ctx, block_param, ResolveNullTipset::TakeOlder) + .await?; + let block = block_from_filecoin_tipset(ctx, ts, full_tx_info).await?; + Ok(block) + } +} + async fn get_block_receipts( ctx: &Ctx, block_param: BlockNumberOrHash, diff --git a/src/rpc/mod.rs b/src/rpc/mod.rs index 6234a80df68c..4e46d91aaf71 100644 --- a/src/rpc/mod.rs +++ b/src/rpc/mod.rs @@ -113,6 +113,7 @@ macro_rules! for_each_rpc_method { $callback!($crate::rpc::eth::EthGetBalanceV2); $callback!($crate::rpc::eth::EthGetBlockByHash); $callback!($crate::rpc::eth::EthGetBlockByNumber); + $callback!($crate::rpc::eth::EthGetBlockByNumberV2); $callback!($crate::rpc::eth::EthGetBlockReceipts); $callback!($crate::rpc::eth::EthGetBlockReceiptsLimited); $callback!($crate::rpc::eth::EthGetBlockTransactionCountByHash); diff --git a/src/tool/subcommands/api_cmd/api_compare_tests.rs b/src/tool/subcommands/api_cmd/api_compare_tests.rs index f5941de0b523..7460ae909972 100644 --- a/src/tool/subcommands/api_cmd/api_compare_tests.rs +++ b/src/tool/subcommands/api_cmd/api_compare_tests.rs @@ -1763,6 +1763,56 @@ fn eth_tests_with_tipset(store: &Arc, shared_tipset: &Tipset )) .unwrap(), ), + RpcTest::identity( + EthGetBlockByNumberV2::request(( + ExtBlockNumberOrHash::from_block_number(shared_tipset.epoch()), + false, + )) + .unwrap(), + ), + RpcTest::identity( + EthGetBlockByNumberV2::request(( + ExtBlockNumberOrHash::from_block_number(shared_tipset.epoch()), + true, + )) + .unwrap(), + ), + RpcTest::identity( + EthGetBlockByNumberV2::request(( + ExtBlockNumberOrHash::from_predefined(ExtPredefined::Earliest), + true, + )) + .unwrap(), + ) + .policy_on_rejected(PolicyOnRejected::PassWithQuasiIdenticalError), + RpcTest::basic( + EthGetBlockByNumberV2::request(( + ExtBlockNumberOrHash::from_predefined(ExtPredefined::Pending), + true, + )) + .unwrap(), + ), + RpcTest::basic( + EthGetBlockByNumberV2::request(( + ExtBlockNumberOrHash::from_predefined(ExtPredefined::Latest), + true, + )) + .unwrap(), + ), + RpcTest::basic( + EthGetBlockByNumberV2::request(( + ExtBlockNumberOrHash::from_predefined(ExtPredefined::Safe), + true, + )) + .unwrap(), + ), + RpcTest::basic( + EthGetBlockByNumberV2::request(( + ExtBlockNumberOrHash::from_predefined(ExtPredefined::Finalized), + true, + )) + .unwrap(), + ), RpcTest::identity( EthGetBlockReceipts::request((BlockNumberOrHash::from_block_hash_object( block_hash.clone(), diff --git a/src/tool/subcommands/api_cmd/test_snapshots.txt b/src/tool/subcommands/api_cmd/test_snapshots.txt index a49df7afa940..7adf87862686 100644 --- a/src/tool/subcommands/api_cmd/test_snapshots.txt +++ b/src/tool/subcommands/api_cmd/test_snapshots.txt @@ -62,6 +62,7 @@ filecoin_ethgetbalance_1740048634848277.rpcsnap.json.zst filecoin_ethgetbalance_v2_1768188109932986.rpcsnap.json.zst filecoin_ethgetblockbyhash_1740132537807408.rpcsnap.json.zst filecoin_ethgetblockbynumber_1737446676696328.rpcsnap.json.zst +filecoin_ethgetblockbynumber_v2_1768192171057588.rpcsnap.json.zst filecoin_ethgetblockreceipts_1740132537907751.rpcsnap.json.zst filecoin_ethgetblockreceiptslimited_1740132537908421.rpcsnap.json.zst filecoin_ethgetblocktransactioncountbyhash_1740132538001911.rpcsnap.json.zst