Skip to content

Commit ca4e19e

Browse files
committed
Merge branch 'main' into shashank/EthGetCodeV2
2 parents 2dcb083 + 0066ae3 commit ca4e19e

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
- [#6490](https://github.com/ChainSafe/forest/pull/6490): Implemented `Filecoin.EthGetCode` for API v2.
4143

4244
### Changed

src/rpc/methods/eth.rs

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3707,26 +3707,50 @@ impl RpcMethod<1> for EthTraceBlock {
37073707
const PARAM_NAMES: [&'static str; 1] = ["blockParam"];
37083708
const API_PATHS: BitFlags<ApiPaths> = ApiPaths::all();
37093709
const PERMISSION: Permission = Permission::Read;
3710+
const DESCRIPTION: Option<&'static str> = Some("Returns traces created at given block.");
3711+
37103712
type Params = (ExtBlockNumberOrHash,);
37113713
type Ok = Vec<EthBlockTrace>;
37123714
async fn handle(
37133715
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
37143716
(block_param,): Self::Params,
37153717
) -> Result<Self::Ok, ServerError> {
3716-
trace_block(ctx, block_param).await
3718+
let ts = tipset_by_ext_block_number_or_hash(
3719+
ctx.chain_store(),
3720+
block_param,
3721+
ResolveNullTipset::TakeOlder,
3722+
)?;
3723+
eth_trace_block(&ctx, &ts).await
37173724
}
37183725
}
37193726

3720-
async fn trace_block<B: Blockstore + Send + Sync + 'static>(
3721-
ctx: Ctx<B>,
3722-
block_param: ExtBlockNumberOrHash,
3723-
) -> Result<Vec<EthBlockTrace>, ServerError> {
3724-
let ts = tipset_by_ext_block_number_or_hash(
3725-
ctx.chain_store(),
3726-
block_param,
3727-
ResolveNullTipset::TakeOlder,
3728-
)?;
3729-
let (state_root, trace) = ctx.state_manager.execution_trace(&ts)?;
3727+
pub enum EthTraceBlockV2 {}
3728+
impl RpcMethod<1> for EthTraceBlockV2 {
3729+
const NAME: &'static str = "Filecoin.EthTraceBlock";
3730+
const NAME_ALIAS: Option<&'static str> = Some("trace_block");
3731+
const N_REQUIRED_PARAMS: usize = 1;
3732+
const PARAM_NAMES: [&'static str; 1] = ["blockParam"];
3733+
const API_PATHS: BitFlags<ApiPaths> = make_bitflags!(ApiPaths::V2);
3734+
const PERMISSION: Permission = Permission::Read;
3735+
const DESCRIPTION: Option<&'static str> = Some("Returns traces created at given block.");
3736+
3737+
type Params = (ExtBlockNumberOrHash,);
3738+
type Ok = Vec<EthBlockTrace>;
3739+
async fn handle(
3740+
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
3741+
(block_param,): Self::Params,
3742+
) -> Result<Self::Ok, ServerError> {
3743+
let ts = tipset_by_block_number_or_hash_v2(&ctx, block_param, ResolveNullTipset::TakeOlder)
3744+
.await?;
3745+
eth_trace_block(&ctx, &ts).await
3746+
}
3747+
}
3748+
3749+
async fn eth_trace_block<DB>(ctx: &Ctx<DB>, ts: &Tipset) -> Result<Vec<EthBlockTrace>, ServerError>
3750+
where
3751+
DB: Blockstore + Send + Sync + 'static,
3752+
{
3753+
let (state_root, trace) = ctx.state_manager.execution_trace(ts)?;
37303754
let state = StateTree::new_from_root(ctx.store_owned(), &state_root)?;
37313755
let cid = ts.key().cid()?;
37323756
let block_hash: EthHash = cid.into();
@@ -3788,14 +3812,17 @@ impl RpcMethod<1> for EthTraceTransaction {
37883812
.await?
37893813
.ok_or(ServerError::internal_error("transaction not found", None))?;
37903814

3791-
let traces = trace_block(
3792-
ctx,
3815+
let ts = tipset_by_ext_block_number_or_hash(
3816+
ctx.chain_store(),
37933817
ExtBlockNumberOrHash::from_block_number(eth_txn.block_number.0 as i64),
3794-
)
3795-
.await?
3796-
.into_iter()
3797-
.filter(|trace| trace.transaction_hash == eth_hash)
3798-
.collect();
3818+
ResolveNullTipset::TakeOlder,
3819+
)?;
3820+
3821+
let traces = eth_trace_block(&ctx, &ts)
3822+
.await?
3823+
.into_iter()
3824+
.filter(|trace| trace.transaction_hash == eth_hash)
3825+
.collect();
37993826
Ok(traces)
38003827
}
38013828
}

src/rpc/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ macro_rules! for_each_rpc_method {
147147
$callback!($crate::rpc::eth::EthSubscribe);
148148
$callback!($crate::rpc::eth::EthSyncing);
149149
$callback!($crate::rpc::eth::EthTraceBlock);
150+
$callback!($crate::rpc::eth::EthTraceBlockV2);
150151
$callback!($crate::rpc::eth::EthTraceFilter);
151152
$callback!($crate::rpc::eth::EthTraceTransaction);
152153
$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
@@ -2292,6 +2292,34 @@ fn eth_tests_with_tipset<DB: Blockstore>(store: &Arc<DB>, shared_tipset: &Tipset
22922292
),))
22932293
.unwrap(),
22942294
),
2295+
RpcTest::identity(
2296+
EthTraceBlockV2::request((ExtBlockNumberOrHash::from_block_number(
2297+
shared_tipset.epoch(),
2298+
),))
2299+
.unwrap(),
2300+
),
2301+
RpcTest::basic(
2302+
EthTraceBlockV2::request((ExtBlockNumberOrHash::from_predefined(
2303+
ExtPredefined::Pending,
2304+
),))
2305+
.unwrap(),
2306+
),
2307+
RpcTest::basic(
2308+
EthTraceBlockV2::request((ExtBlockNumberOrHash::from_predefined(
2309+
ExtPredefined::Latest,
2310+
),))
2311+
.unwrap(),
2312+
),
2313+
RpcTest::basic(
2314+
EthTraceBlockV2::request((ExtBlockNumberOrHash::from_predefined(ExtPredefined::Safe),))
2315+
.unwrap(),
2316+
),
2317+
RpcTest::basic(
2318+
EthTraceBlockV2::request((ExtBlockNumberOrHash::from_predefined(
2319+
ExtPredefined::Finalized,
2320+
),))
2321+
.unwrap(),
2322+
),
22952323
RpcTest::identity(
22962324
EthTraceReplayBlockTransactions::request((
22972325
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
@@ -102,6 +102,11 @@ filecoin_ethnewfilter_1741781607617949.rpcsnap.json.zst
102102
filecoin_ethnewpendingtransactionfilter_1741781890872902.rpcsnap.json.zst
103103
filecoin_ethprotocolversion_1737446676698826.rpcsnap.json.zst
104104
filecoin_ethtraceblock_1737446676736475.rpcsnap.json.zst
105+
filecoin_ethtraceblock_1768911857430141.rpcsnap.json.zst
106+
filecoin_ethtraceblock_v2_finalized_1769092405093534.rpcsnap.json.zst
107+
filecoin_ethtraceblock_v2_latest_1769092400908495.rpcsnap.json.zst
108+
filecoin_ethtraceblock_v2_pending_1769092400918744.rpcsnap.json.zst
109+
filecoin_ethtraceblock_v2_safe_1769092401374979.rpcsnap.json.zst
105110
filecoin_ethtracefilter_1742371405673188.rpcsnap.json.zst
106111
filecoin_ethtracefilter_1742983898701553.rpcsnap.json.zst
107112
filecoin_ethtracefilter_1746449543820062.rpcsnap.json.zst

0 commit comments

Comments
 (0)