From bcc13b0661bdd85bc29c5fc0181e460377359489 Mon Sep 17 00:00:00 2001 From: Viraj Bhartiya Date: Fri, 29 Nov 2024 14:59:04 +0530 Subject: [PATCH 1/2] feat: implement EthGetBlockReceiptsLimited RPC method (#5018) Co-authored-by: hanabi1224 --- CHANGELOG.md | 3 ++ src/rpc/methods/eth.rs | 94 ++++++++++++++++++++++----------- src/rpc/mod.rs | 1 + src/tool/subcommands/api_cmd.rs | 3 ++ 4 files changed, 70 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd4d0775815..5b8f2a7698c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,9 @@ for more details. - [#4839](https://github.com/ChainSafe/forest/issues/4839) Add support for the `Filecoin.EthGetBlockReceipts` RPC method. +- [#5017](https://github.com/ChainSafe/forest/issues/5017) Add support for the + `Filecoin.EthGetBlockReceiptsLimited` RPC method. + - [#4943](https://github.com/ChainSafe/forest/pull/4943) Add generation of method aliases for `forest-tool shed openrpc` subcommand and sort all methods in lexicographic order. diff --git a/src/rpc/methods/eth.rs b/src/rpc/methods/eth.rs index 8de8f6901a2..66923f786da 100644 --- a/src/rpc/methods/eth.rs +++ b/src/rpc/methods/eth.rs @@ -1280,6 +1280,51 @@ impl RpcMethod<2> for EthGetBlockByNumber { } } +async fn get_block_receipts( + ctx: &Ctx, + block_hash: EthHash, + limit: Option, +) -> Result, ServerError> { + let ts = get_tipset_from_hash(ctx.chain_store(), &block_hash)?; + let ts_ref = Arc::new(ts); + let ts_key = ts_ref.key(); + let (state_root, msgs_and_receipts) = execute_tipset(ctx, &ts_ref).await?; + + let msgs_and_receipts = if let Some(limit) = limit { + msgs_and_receipts.into_iter().take(limit).collect() + } else { + msgs_and_receipts + }; + + let mut receipts = Vec::with_capacity(msgs_and_receipts.len()); + let state = StateTree::new_from_root(ctx.store_owned(), &state_root)?; + + for (i, (msg, receipt)) in msgs_and_receipts.into_iter().enumerate() { + let return_dec = receipt.return_data().deserialize().unwrap_or(Ipld::Null); + + let message_lookup = MessageLookup { + receipt, + tipset: ts_key.clone(), + height: ts_ref.epoch(), + message: msg.cid(), + return_dec, + }; + + let tx = new_eth_tx( + ctx, + &state, + ts_ref.epoch(), + &ts_key.cid()?, + &msg.cid(), + i as u64, + )?; + + let tx_receipt = new_eth_tx_receipt(ctx, &tx, &message_lookup).await?; + receipts.push(tx_receipt); + } + Ok(receipts) +} + pub enum EthGetBlockReceipts {} impl RpcMethod<1> for EthGetBlockReceipts { const NAME: &'static str = "Filecoin.EthGetBlockReceipts"; @@ -1294,38 +1339,25 @@ impl RpcMethod<1> for EthGetBlockReceipts { ctx: Ctx, (block_hash,): Self::Params, ) -> Result { - let ts = get_tipset_from_hash(ctx.chain_store(), &block_hash)?; - let ts_ref = Arc::new(ts); - let ts_key = ts_ref.key(); - let (state_root, msgs_and_receipts) = execute_tipset(&ctx, &ts_ref).await?; - let mut receipts = Vec::with_capacity(msgs_and_receipts.len()); - - let state = StateTree::new_from_root(ctx.store_owned(), &state_root)?; - - for (i, (msg, receipt)) in msgs_and_receipts.into_iter().enumerate() { - let return_dec = receipt.return_data().deserialize().unwrap_or(Ipld::Null); - - let message_lookup = MessageLookup { - receipt, - tipset: ts_key.clone(), - height: ts_ref.epoch(), - message: msg.cid(), - return_dec, - }; + get_block_receipts(&ctx, block_hash, None).await + } +} - let tx = new_eth_tx( - &ctx, - &state, - ts_ref.epoch(), - &ts_key.cid()?, - &msg.cid(), - i as u64, - )?; - - let tx_receipt = new_eth_tx_receipt(&ctx, &tx, &message_lookup).await?; - receipts.push(tx_receipt); - } - Ok(receipts) +pub enum EthGetBlockReceiptsLimited {} +impl RpcMethod<2> for EthGetBlockReceiptsLimited { + const NAME: &'static str = "Filecoin.EthGetBlockReceiptsLimited"; + const NAME_ALIAS: Option<&'static str> = Some("eth_getBlockReceiptsLimited"); + const PARAM_NAMES: [&'static str; 2] = ["block_hash", "limit"]; + const API_PATHS: ApiPaths = ApiPaths::V1; + const PERMISSION: Permission = Permission::Read; + type Params = (EthHash, EthUint64); + type Ok = Vec; + + async fn handle( + ctx: Ctx, + (block_hash, EthUint64(limit)): Self::Params, + ) -> Result { + get_block_receipts(&ctx, block_hash, Some(limit as usize)).await } } diff --git a/src/rpc/mod.rs b/src/rpc/mod.rs index f128a18f8fc..cb1c9856f0e 100644 --- a/src/rpc/mod.rs +++ b/src/rpc/mod.rs @@ -81,6 +81,7 @@ macro_rules! for_each_method { $callback!(crate::rpc::eth::EthGetBlockByHash); $callback!(crate::rpc::eth::EthGetBlockByNumber); $callback!(crate::rpc::eth::EthGetBlockReceipts); + $callback!(crate::rpc::eth::EthGetBlockReceiptsLimited); $callback!(crate::rpc::eth::EthGetBlockTransactionCountByHash); $callback!(crate::rpc::eth::EthGetBlockTransactionCountByNumber); $callback!(crate::rpc::eth::EthGetCode); diff --git a/src/tool/subcommands/api_cmd.rs b/src/tool/subcommands/api_cmd.rs index 06c07080451..745f2699f0b 100644 --- a/src/tool/subcommands/api_cmd.rs +++ b/src/tool/subcommands/api_cmd.rs @@ -1443,6 +1443,9 @@ fn eth_tests_with_tipset(store: &Arc, shared_tipset: &Tipset RpcTest::identity( EthGetBlockTransactionCountByHash::request((block_hash.clone(),)).unwrap(), ), + RpcTest::identity( + EthGetBlockReceiptsLimited::request((block_hash.clone(), EthUint64(800))).unwrap(), + ), RpcTest::identity( EthGetBlockTransactionCountByNumber::request((EthInt64(shared_tipset.epoch()),)) .unwrap(), From d08dacf2d423a52434a2624eced8954d161ff53d Mon Sep 17 00:00:00 2001 From: Hubert Date: Sun, 1 Dec 2024 12:39:26 +0100 Subject: [PATCH 2/2] chore: update known blocks (#5022) --- build/known_blocks.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build/known_blocks.yaml b/build/known_blocks.yaml index 864d2a675ee..515bf2fe35a 100644 --- a/build/known_blocks.yaml +++ b/build/known_blocks.yaml @@ -7,6 +7,8 @@ # # This file is maintained monthly - see `CHECKPOINT_ISSUE_TEMPLATE.md` calibnet: + 2160000: bafy2bzaceaq6zgokrh5zrmwj42vsjqecog3sf4s467rw7oydh5zpglj2dh6x2 + 2073600: bafy2bzacedcwoydjsj6cchl5jjsr3xxtkwrzw6odlr2cdqcoayf2n7ckt726q 1987200: bafy2bzacebzdntcwbrm3v3lnbg2rklmszioovtgl5zhht63monwh7bl42xctm 1900800: bafy2bzacecgfzkibii4on2zpa4mq25oqwi3bonyhd7rfr6niiwdxwqxsdhu5q 1814400: bafy2bzaceadeoq4mbrw5grvighyda6hlre6vfyzlxsn6s2tre2qrchminyc4i @@ -31,6 +33,8 @@ calibnet: 172800: bafy2bzacebluce5la2lbyjlgmup6mx4xytnnilsf4oy6v4omon2ivyduqwlsq 86400: bafy2bzaceatx7tlwdhez6vyias5qlhaxa54vjftigbuqzfsmdqduc6jdiclzc mainnet: + 4406400: bafy2bzacecgml5dar3tlve23wx25ebsq4r6gk3nnlf36vbgyq3ntl3ifbmvyw + 4320000: bafy2bzacea6lfgw5gmi7fznzwfy4hcd6krludno6rfne62ys6wmhdynix4dqi 4233600: bafy2bzacecqo64vedu4l2xwzhu63dnbcmbfi4uamk7lkegxv6luxfkaoel376 4147200: bafy2bzaceajjwa7iygiarg2e7w43sut2kee5ipydo4mcfxuugl5r2hh2oogpm 4060800: bafy2bzaceahjb2kcrph6abe4kvrly7dyosslkq57nu2jgz4hkfnelbzax6ud2