diff --git a/CHANGELOG.md b/CHANGELOG.md index aadd1e794b3..0993c3420be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,9 @@ ### Added +- [#5020](https://github.com/ChainSafe/forest/issues/5020) Add support for the + `Filecoin.EthGetTransactionByBlockNumberAndIndex` RPC method. + ### Changed ### Removed @@ -83,6 +86,8 @@ methods, fixes (notably to the garbage collection), and other improvements. - [#4701](https://github.com/ChainSafe/forest/issues/4701) Add support for the `Filecoin.EthGetTransactionByBlockHashAndIndex` RPC method. +### Changed + - [#5053](https://github.com/ChainSafe/forest/pull/5053) Added support for the NV25 _Teep_ network upgrade for `2k` and `butterflynet` networks. diff --git a/scripts/tests/api_compare/filter-list b/scripts/tests/api_compare/filter-list index e6f7d921321..81ae2ea45ec 100644 --- a/scripts/tests/api_compare/filter-list +++ b/scripts/tests/api_compare/filter-list @@ -11,7 +11,6 @@ # TODO: https://github.com/ChainSafe/forest/issues/4996 !Filecoin.EthGetTransactionReceipt !Filecoin.EthGetTransactionReceiptLimited -!Filecoin.EthGetTransactionByBlockNumberAndIndex # TODO: https://github.com/ChainSafe/forest/issues/5006 !Filecoin.EthGetBlockReceipts # TODO: https://github.com/ChainSafe/forest/issues/5085 diff --git a/scripts/tests/api_compare/filter-list-offline b/scripts/tests/api_compare/filter-list-offline index 68b179f21b4..d1ddba7338d 100644 --- a/scripts/tests/api_compare/filter-list-offline +++ b/scripts/tests/api_compare/filter-list-offline @@ -41,7 +41,6 @@ # TODO: https://github.com/ChainSafe/forest/issues/4996 !Filecoin.EthGetTransactionReceipt !Filecoin.EthGetTransactionReceiptLimited -!Filecoin.EthGetTransactionByBlockNumberAndIndex # TODO: https://github.com/ChainSafe/forest/issues/5006 !Filecoin.EthGetBlockReceipts # TODO: https://github.com/ChainSafe/forest/issues/5085 diff --git a/src/rpc/methods/eth.rs b/src/rpc/methods/eth.rs index 5b121111949..820614cb2c1 100644 --- a/src/rpc/methods/eth.rs +++ b/src/rpc/methods/eth.rs @@ -2015,19 +2015,43 @@ pub enum EthGetTransactionByBlockNumberAndIndex {} impl RpcMethod<2> for EthGetTransactionByBlockNumberAndIndex { const NAME: &'static str = "Filecoin.EthGetTransactionByBlockNumberAndIndex"; const NAME_ALIAS: Option<&'static str> = Some("eth_getTransactionByBlockNumberAndIndex"); - const PARAM_NAMES: [&'static str; 2] = ["p1", "p2"]; + const PARAM_NAMES: [&'static str; 2] = ["block_param", "tx_index"]; const API_PATHS: ApiPaths = ApiPaths::V1; const PERMISSION: Permission = Permission::Read; - type Params = (EthUint64, EthUint64); + type Params = (BlockNumberOrPredefined, EthUint64); type Ok = Option; async fn handle( - _ctx: Ctx, - (_p1, _p2): Self::Params, + ctx: Ctx, + (block_param, tx_index): Self::Params, ) -> Result { - // Lotus doesn't support this method (v1.29.0), so do we. - Err(ServerError::unsupported_method()) + let ts = tipset_by_block_number_or_hash(ctx.chain_store(), block_param.into())?; + + let messages = ctx.chain_store().messages_for_tipset(&ts)?; + + let EthUint64(index) = tx_index; + let msg = messages.get(index as usize).with_context(|| { + format!( + "failed to get transaction at index {}: index {} out of range: tipset contains {} messages", + index, + index, + messages.len() + ) + })?; + + let state = StateTree::new_from_root(ctx.store_owned(), ts.parent_state())?; + + let tx = new_eth_tx( + &ctx, + &state, + ts.epoch(), + &ts.key().cid()?, + &msg.cid(), + index, + )?; + + Ok(Some(tx)) } } diff --git a/src/tool/subcommands/api_cmd.rs b/src/tool/subcommands/api_cmd.rs index 5bcc3cae821..e709a86dad6 100644 --- a/src/tool/subcommands/api_cmd.rs +++ b/src/tool/subcommands/api_cmd.rs @@ -1499,7 +1499,7 @@ fn eth_tests_with_tipset(store: &Arc, shared_tipset: &Tipset ), RpcTest::identity( EthGetTransactionByBlockNumberAndIndex::request(( - (shared_tipset.epoch() as u64).into(), + BlockNumberOrPredefined::BlockNumber(shared_tipset.epoch().into()), 0.into(), )) .unwrap(),