Skip to content

Commit 0066ae3

Browse files
feat(rpc): Add support for the EthTraceBlock V2 API (#6451)
Co-authored-by: Shashank <[email protected]>
1 parent 7f2f0db commit 0066ae3

File tree

5 files changed

+81
-18
lines changed

5 files changed

+81
-18
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
- [#6469](https://github.com/ChainSafe/forest/pull/6469): Implemented `Filecoin.EthGetTransactionByBlockNumberAndIndex` for API v2.
3939

40+
- [#6451](https://github.com/ChainSafe/forest/pull/6451): Implemented `Filecoin.EthTraceBlock` for API v2.
41+
4042
### Changed
4143

4244
- [#6471](https://github.com/ChainSafe/forest/pull/6471): Moved `forest-tool state` subcommand to `forest-dev`.

src/rpc/methods/eth.rs

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3669,26 +3669,50 @@ impl RpcMethod<1> for EthTraceBlock {
36693669
const PARAM_NAMES: [&'static str; 1] = ["blockParam"];
36703670
const API_PATHS: BitFlags<ApiPaths> = ApiPaths::all();
36713671
const PERMISSION: Permission = Permission::Read;
3672+
const DESCRIPTION: Option<&'static str> = Some("Returns traces created at given block.");
3673+
36723674
type Params = (ExtBlockNumberOrHash,);
36733675
type Ok = Vec<EthBlockTrace>;
36743676
async fn handle(
36753677
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
36763678
(block_param,): Self::Params,
36773679
) -> Result<Self::Ok, ServerError> {
3678-
trace_block(ctx, block_param).await
3680+
let ts = tipset_by_ext_block_number_or_hash(
3681+
ctx.chain_store(),
3682+
block_param,
3683+
ResolveNullTipset::TakeOlder,
3684+
)?;
3685+
eth_trace_block(&ctx, &ts).await
36793686
}
36803687
}
36813688

3682-
async fn trace_block<B: Blockstore + Send + Sync + 'static>(
3683-
ctx: Ctx<B>,
3684-
block_param: ExtBlockNumberOrHash,
3685-
) -> Result<Vec<EthBlockTrace>, ServerError> {
3686-
let ts = tipset_by_ext_block_number_or_hash(
3687-
ctx.chain_store(),
3688-
block_param,
3689-
ResolveNullTipset::TakeOlder,
3690-
)?;
3691-
let (state_root, trace) = ctx.state_manager.execution_trace(&ts)?;
3689+
pub enum EthTraceBlockV2 {}
3690+
impl RpcMethod<1> for EthTraceBlockV2 {
3691+
const NAME: &'static str = "Filecoin.EthTraceBlock";
3692+
const NAME_ALIAS: Option<&'static str> = Some("trace_block");
3693+
const N_REQUIRED_PARAMS: usize = 1;
3694+
const PARAM_NAMES: [&'static str; 1] = ["blockParam"];
3695+
const API_PATHS: BitFlags<ApiPaths> = make_bitflags!(ApiPaths::V2);
3696+
const PERMISSION: Permission = Permission::Read;
3697+
const DESCRIPTION: Option<&'static str> = Some("Returns traces created at given block.");
3698+
3699+
type Params = (ExtBlockNumberOrHash,);
3700+
type Ok = Vec<EthBlockTrace>;
3701+
async fn handle(
3702+
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
3703+
(block_param,): Self::Params,
3704+
) -> Result<Self::Ok, ServerError> {
3705+
let ts = tipset_by_block_number_or_hash_v2(&ctx, block_param, ResolveNullTipset::TakeOlder)
3706+
.await?;
3707+
eth_trace_block(&ctx, &ts).await
3708+
}
3709+
}
3710+
3711+
async fn eth_trace_block<DB>(ctx: &Ctx<DB>, ts: &Tipset) -> Result<Vec<EthBlockTrace>, ServerError>
3712+
where
3713+
DB: Blockstore + Send + Sync + 'static,
3714+
{
3715+
let (state_root, trace) = ctx.state_manager.execution_trace(ts)?;
36923716
let state = StateTree::new_from_root(ctx.store_owned(), &state_root)?;
36933717
let cid = ts.key().cid()?;
36943718
let block_hash: EthHash = cid.into();
@@ -3750,14 +3774,17 @@ impl RpcMethod<1> for EthTraceTransaction {
37503774
.await?
37513775
.ok_or(ServerError::internal_error("transaction not found", None))?;
37523776

3753-
let traces = trace_block(
3754-
ctx,
3777+
let ts = tipset_by_ext_block_number_or_hash(
3778+
ctx.chain_store(),
37553779
ExtBlockNumberOrHash::from_block_number(eth_txn.block_number.0 as i64),
3756-
)
3757-
.await?
3758-
.into_iter()
3759-
.filter(|trace| trace.transaction_hash == eth_hash)
3760-
.collect();
3780+
ResolveNullTipset::TakeOlder,
3781+
)?;
3782+
3783+
let traces = eth_trace_block(&ctx, &ts)
3784+
.await?
3785+
.into_iter()
3786+
.filter(|trace| trace.transaction_hash == eth_hash)
3787+
.collect();
37613788
Ok(traces)
37623789
}
37633790
}

src/rpc/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ macro_rules! for_each_rpc_method {
146146
$callback!($crate::rpc::eth::EthSubscribe);
147147
$callback!($crate::rpc::eth::EthSyncing);
148148
$callback!($crate::rpc::eth::EthTraceBlock);
149+
$callback!($crate::rpc::eth::EthTraceBlockV2);
149150
$callback!($crate::rpc::eth::EthTraceFilter);
150151
$callback!($crate::rpc::eth::EthTraceTransaction);
151152
$callback!($crate::rpc::eth::EthTraceReplayBlockTransactions);

src/tool/subcommands/api_cmd/api_compare_tests.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,6 +2270,34 @@ fn eth_tests_with_tipset<DB: Blockstore>(store: &Arc<DB>, shared_tipset: &Tipset
22702270
),))
22712271
.unwrap(),
22722272
),
2273+
RpcTest::identity(
2274+
EthTraceBlockV2::request((ExtBlockNumberOrHash::from_block_number(
2275+
shared_tipset.epoch(),
2276+
),))
2277+
.unwrap(),
2278+
),
2279+
RpcTest::basic(
2280+
EthTraceBlockV2::request((ExtBlockNumberOrHash::from_predefined(
2281+
ExtPredefined::Pending,
2282+
),))
2283+
.unwrap(),
2284+
),
2285+
RpcTest::basic(
2286+
EthTraceBlockV2::request((ExtBlockNumberOrHash::from_predefined(
2287+
ExtPredefined::Latest,
2288+
),))
2289+
.unwrap(),
2290+
),
2291+
RpcTest::basic(
2292+
EthTraceBlockV2::request((ExtBlockNumberOrHash::from_predefined(ExtPredefined::Safe),))
2293+
.unwrap(),
2294+
),
2295+
RpcTest::basic(
2296+
EthTraceBlockV2::request((ExtBlockNumberOrHash::from_predefined(
2297+
ExtPredefined::Finalized,
2298+
),))
2299+
.unwrap(),
2300+
),
22732301
RpcTest::identity(
22742302
EthTraceReplayBlockTransactions::request((
22752303
ExtBlockNumberOrHash::from_block_number(shared_tipset.epoch()),

src/tool/subcommands/api_cmd/test_snapshots.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ filecoin_ethnewfilter_1741781607617949.rpcsnap.json.zst
9999
filecoin_ethnewpendingtransactionfilter_1741781890872902.rpcsnap.json.zst
100100
filecoin_ethprotocolversion_1737446676698826.rpcsnap.json.zst
101101
filecoin_ethtraceblock_1737446676736475.rpcsnap.json.zst
102+
filecoin_ethtraceblock_1768911857430141.rpcsnap.json.zst
103+
filecoin_ethtraceblock_v2_finalized_1769092405093534.rpcsnap.json.zst
104+
filecoin_ethtraceblock_v2_latest_1769092400908495.rpcsnap.json.zst
105+
filecoin_ethtraceblock_v2_pending_1769092400918744.rpcsnap.json.zst
106+
filecoin_ethtraceblock_v2_safe_1769092401374979.rpcsnap.json.zst
102107
filecoin_ethtracefilter_1742371405673188.rpcsnap.json.zst
103108
filecoin_ethtracefilter_1742983898701553.rpcsnap.json.zst
104109
filecoin_ethtracefilter_1746449543820062.rpcsnap.json.zst

0 commit comments

Comments
 (0)