Skip to content

Commit 90579f9

Browse files
Add support for the Filecoin.EthGetBlockByNumber V2 (#6404)
1 parent 7d9b1b1 commit 90579f9

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

CHANGELOG.md

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

4040
- [#6403](https://github.com/ChainSafe/forest/pull/6403) Implemented `Filecoin.EthGetBalance` for API v2.
4141

42+
- [#6404](https://github.com/ChainSafe/forest/pull/6404) Implemented `Filecoin.EthGetBlockByNumber` for API v2.
43+
4244
### Changed
4345

4446
- [#6368](https://github.com/ChainSafe/forest/pull/6368): Migrated build and development tooling from Makefile to `mise`. Contributors should install `mise` and use `mise run` commands instead of `make` commands.

src/rpc/methods/eth.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,28 @@ impl RpcMethod<2> for EthGetBlockByNumber {
16201620
}
16211621
}
16221622

1623+
pub enum EthGetBlockByNumberV2 {}
1624+
impl RpcMethod<2> for EthGetBlockByNumberV2 {
1625+
const NAME: &'static str = "Filecoin.EthGetBlockByNumber";
1626+
const NAME_ALIAS: Option<&'static str> = Some("eth_getBlockByNumber");
1627+
const PARAM_NAMES: [&'static str; 2] = ["blockParam", "fullTxInfo"];
1628+
const API_PATHS: BitFlags<ApiPaths> = make_bitflags!(ApiPaths::V2);
1629+
const PERMISSION: Permission = Permission::Read;
1630+
1631+
type Params = (ExtBlockNumberOrHash, bool);
1632+
type Ok = Block;
1633+
1634+
async fn handle(
1635+
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
1636+
(block_param, full_tx_info): Self::Params,
1637+
) -> Result<Self::Ok, ServerError> {
1638+
let ts = tipset_by_block_number_or_hash_v2(&ctx, block_param, ResolveNullTipset::TakeOlder)
1639+
.await?;
1640+
let block = block_from_filecoin_tipset(ctx, ts, full_tx_info).await?;
1641+
Ok(block)
1642+
}
1643+
}
1644+
16231645
async fn get_block_receipts<DB: Blockstore + Send + Sync + 'static>(
16241646
ctx: &Ctx<DB>,
16251647
block_param: BlockNumberOrHash,

src/rpc/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ macro_rules! for_each_rpc_method {
113113
$callback!($crate::rpc::eth::EthGetBalanceV2);
114114
$callback!($crate::rpc::eth::EthGetBlockByHash);
115115
$callback!($crate::rpc::eth::EthGetBlockByNumber);
116+
$callback!($crate::rpc::eth::EthGetBlockByNumberV2);
116117
$callback!($crate::rpc::eth::EthGetBlockReceipts);
117118
$callback!($crate::rpc::eth::EthGetBlockReceiptsLimited);
118119
$callback!($crate::rpc::eth::EthGetBlockTransactionCountByHash);

src/tool/subcommands/api_cmd/api_compare_tests.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,6 +1763,56 @@ fn eth_tests_with_tipset<DB: Blockstore>(store: &Arc<DB>, shared_tipset: &Tipset
17631763
))
17641764
.unwrap(),
17651765
),
1766+
RpcTest::identity(
1767+
EthGetBlockByNumberV2::request((
1768+
ExtBlockNumberOrHash::from_block_number(shared_tipset.epoch()),
1769+
false,
1770+
))
1771+
.unwrap(),
1772+
),
1773+
RpcTest::identity(
1774+
EthGetBlockByNumberV2::request((
1775+
ExtBlockNumberOrHash::from_block_number(shared_tipset.epoch()),
1776+
true,
1777+
))
1778+
.unwrap(),
1779+
),
1780+
RpcTest::identity(
1781+
EthGetBlockByNumberV2::request((
1782+
ExtBlockNumberOrHash::from_predefined(ExtPredefined::Earliest),
1783+
true,
1784+
))
1785+
.unwrap(),
1786+
)
1787+
.policy_on_rejected(PolicyOnRejected::PassWithQuasiIdenticalError),
1788+
RpcTest::basic(
1789+
EthGetBlockByNumberV2::request((
1790+
ExtBlockNumberOrHash::from_predefined(ExtPredefined::Pending),
1791+
true,
1792+
))
1793+
.unwrap(),
1794+
),
1795+
RpcTest::basic(
1796+
EthGetBlockByNumberV2::request((
1797+
ExtBlockNumberOrHash::from_predefined(ExtPredefined::Latest),
1798+
true,
1799+
))
1800+
.unwrap(),
1801+
),
1802+
RpcTest::basic(
1803+
EthGetBlockByNumberV2::request((
1804+
ExtBlockNumberOrHash::from_predefined(ExtPredefined::Safe),
1805+
true,
1806+
))
1807+
.unwrap(),
1808+
),
1809+
RpcTest::basic(
1810+
EthGetBlockByNumberV2::request((
1811+
ExtBlockNumberOrHash::from_predefined(ExtPredefined::Finalized),
1812+
true,
1813+
))
1814+
.unwrap(),
1815+
),
17661816
RpcTest::identity(
17671817
EthGetBlockReceipts::request((BlockNumberOrHash::from_block_hash_object(
17681818
block_hash.clone(),

src/tool/subcommands/api_cmd/test_snapshots.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ filecoin_ethgetbalance_1740048634848277.rpcsnap.json.zst
6262
filecoin_ethgetbalance_v2_1768188109932986.rpcsnap.json.zst
6363
filecoin_ethgetblockbyhash_1740132537807408.rpcsnap.json.zst
6464
filecoin_ethgetblockbynumber_1737446676696328.rpcsnap.json.zst
65+
filecoin_ethgetblockbynumber_v2_1768192171057588.rpcsnap.json.zst
6566
filecoin_ethgetblockreceipts_1740132537907751.rpcsnap.json.zst
6667
filecoin_ethgetblockreceiptslimited_1740132537908421.rpcsnap.json.zst
6768
filecoin_ethgetblocktransactioncountbyhash_1740132538001911.rpcsnap.json.zst

0 commit comments

Comments
 (0)