Skip to content

Commit

Permalink
feat(rpc): implement EthGetTransactionByBlockNumberAndIndex (#5030)
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume Potier <[email protected]>
  • Loading branch information
virajbhartiya and elmattic authored Dec 16, 2024
1 parent f3c65e8 commit eb11869
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

### Added

- [#5020](https://github.com/ChainSafe/forest/issues/5020) Add support for the
`Filecoin.EthGetTransactionByBlockNumberAndIndex` RPC method.

### Changed

### Removed
Expand Down Expand Up @@ -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.

Expand Down
1 change: 0 additions & 1 deletion scripts/tests/api_compare/filter-list
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion scripts/tests/api_compare/filter-list-offline
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 30 additions & 6 deletions src/rpc/methods/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ApiEthTx>;

async fn handle(
_ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(_p1, _p2): Self::Params,
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(block_param, tx_index): Self::Params,
) -> Result<Self::Ok, ServerError> {
// 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))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tool/subcommands/api_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,7 @@ fn eth_tests_with_tipset<DB: Blockstore>(store: &Arc<DB>, shared_tipset: &Tipset
),
RpcTest::identity(
EthGetTransactionByBlockNumberAndIndex::request((
(shared_tipset.epoch() as u64).into(),
BlockNumberOrPredefined::BlockNumber(shared_tipset.epoch().into()),
0.into(),
))
.unwrap(),
Expand Down

0 comments on commit eb11869

Please sign in to comment.