Skip to content

Commit 7f2f0db

Browse files
Add support for the Filecoin.EthGetBlockTransactionCountByNumber V2 (#6465)
1 parent aadcb55 commit 7f2f0db

File tree

6 files changed

+61
-4
lines changed

6 files changed

+61
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,21 @@
3131

3232
### Added
3333

34-
- [#6466](https://github.com/ChainSafe/forest/pull/6466) Enabled `Filecoin.EthGetBlockTransactionCountByHash` for API v2.
34+
- [#6465](https://github.com/ChainSafe/forest/pull/6465): Implemented `Filecoin.EthGetBlockTransactionCountByNumber` for API v2.
3535

36-
- [#6469](https://github.com/ChainSafe/forest/pull/6469) Implemented `Filecoin.EthGetTransactionByBlockNumberAndIndex` for API v2.
36+
- [#6466](https://github.com/ChainSafe/forest/pull/6466): Enabled `Filecoin.EthGetBlockTransactionCountByHash` for API v2.
37+
38+
- [#6469](https://github.com/ChainSafe/forest/pull/6469): Implemented `Filecoin.EthGetTransactionByBlockNumberAndIndex` for API v2.
3739

3840
### Changed
3941

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

4244
### Removed
4345

4446
### Fixed
4547

46-
- [#6467](https://github.com/ChainSafe/forest/pull/6467) Fixed: `Filecoin.EthGetBlockByNumber` now only supports retrieving a block by its block number or a special tag.
48+
- [#6467](https://github.com/ChainSafe/forest/pull/6467): `Filecoin.EthGetBlockByNumber` now only supports retrieving a block by its block number or a special tag.
4749

4850
## Forest v0.31.1 "Quadrantids"
4951

scripts/tests/api_compare/filter-list-offline

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
# Offline server won't provide correct results for finality-related methods
2727
!Filecoin.EthGetBlockByNumber
2828
!eth_getBlockByNumber
29+
!Filecoin.EthGetBlockTransactionCountByNumber
30+
!eth_getBlockTransactionCountByNumber
2931
!Filecoin.EthGetTransactionByBlockNumberAndIndex
3032
!eth_getTransactionByBlockNumberAndIndex
3133
!Filecoin.ChainSetHead

src/rpc/methods/eth.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,8 @@ impl RpcMethod<1> for EthGetBlockTransactionCountByNumber {
17871787
const PARAM_NAMES: [&'static str; 1] = ["blockNumber"];
17881788
const API_PATHS: BitFlags<ApiPaths> = ApiPaths::all();
17891789
const PERMISSION: Permission = Permission::Read;
1790+
const DESCRIPTION: Option<&'static str> =
1791+
Some("Returns the number of transactions in a block identified by its block number.");
17901792

17911793
type Params = (EthInt64,);
17921794
type Ok = EthUint64;
@@ -1808,6 +1810,35 @@ impl RpcMethod<1> for EthGetBlockTransactionCountByNumber {
18081810
}
18091811
}
18101812

1813+
pub enum EthGetBlockTransactionCountByNumberV2 {}
1814+
impl RpcMethod<1> for EthGetBlockTransactionCountByNumberV2 {
1815+
const NAME: &'static str = "Filecoin.EthGetBlockTransactionCountByNumber";
1816+
const NAME_ALIAS: Option<&'static str> = Some("eth_getBlockTransactionCountByNumber");
1817+
const PARAM_NAMES: [&'static str; 1] = ["blockNumber"];
1818+
const API_PATHS: BitFlags<ApiPaths> = make_bitflags!(ApiPaths::V2);
1819+
const PERMISSION: Permission = Permission::Read;
1820+
const DESCRIPTION: Option<&'static str> = Some(
1821+
"Returns the number of transactions in a block identified by its block number or a special tag.",
1822+
);
1823+
1824+
type Params = (BlockNumberOrPredefined,);
1825+
type Ok = EthUint64;
1826+
1827+
async fn handle(
1828+
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
1829+
(block_number,): Self::Params,
1830+
) -> Result<Self::Ok, ServerError> {
1831+
let ts = tipset_by_block_number_or_hash_v2(
1832+
&ctx,
1833+
block_number.into(),
1834+
ResolveNullTipset::TakeOlder,
1835+
)
1836+
.await?;
1837+
let count = count_messages_in_tipset(ctx.store(), &ts)?;
1838+
Ok(EthUint64(count as _))
1839+
}
1840+
}
1841+
18111842
pub enum EthGetMessageCidByTransactionHash {}
18121843
impl RpcMethod<1> for EthGetMessageCidByTransactionHash {
18131844
const NAME: &'static str = "Filecoin.EthGetMessageCidByTransactionHash";

src/rpc/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ macro_rules! for_each_rpc_method {
119119
$callback!($crate::rpc::eth::EthGetBlockReceiptsLimited);
120120
$callback!($crate::rpc::eth::EthGetBlockTransactionCountByHash);
121121
$callback!($crate::rpc::eth::EthGetBlockTransactionCountByNumber);
122+
$callback!($crate::rpc::eth::EthGetBlockTransactionCountByNumberV2);
122123
$callback!($crate::rpc::eth::EthGetCode);
123124
$callback!($crate::rpc::eth::EthGetLogs);
124125
$callback!($crate::rpc::eth::EthGetFilterLogs);

src/tool/subcommands/api_cmd/api_compare_tests.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,24 @@ fn eth_tests_with_tipset<DB: Blockstore>(store: &Arc<DB>, shared_tipset: &Tipset
18491849
EthGetBlockTransactionCountByNumber::request((EthInt64(shared_tipset.epoch()),))
18501850
.unwrap(),
18511851
),
1852+
RpcTest::identity(
1853+
EthGetBlockTransactionCountByNumberV2::request((BlockNumberOrPredefined::BlockNumber(
1854+
EthInt64(shared_tipset.epoch()),
1855+
),))
1856+
.unwrap(),
1857+
),
1858+
RpcTest::identity(
1859+
EthGetBlockTransactionCountByNumberV2::request((
1860+
BlockNumberOrPredefined::PredefinedBlock(ExtPredefined::Safe),
1861+
))
1862+
.unwrap(),
1863+
),
1864+
RpcTest::identity(
1865+
EthGetBlockTransactionCountByNumberV2::request((
1866+
BlockNumberOrPredefined::PredefinedBlock(ExtPredefined::Finalized),
1867+
))
1868+
.unwrap(),
1869+
),
18521870
RpcTest::identity(
18531871
EthGetTransactionCount::request((
18541872
EthAddress::from_str("0xff000000000000000000000000000000000003ec").unwrap(),

src/tool/subcommands/api_cmd/test_snapshots.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ filecoin_ethgetblockreceipts_1740132537907751.rpcsnap.json.zst
6767
filecoin_ethgetblockreceiptslimited_1740132537908421.rpcsnap.json.zst
6868
filecoin_ethgetblocktransactioncountbyhash_1740132538001911.rpcsnap.json.zst
6969
filecoin_ethgetblocktransactioncountbynumber_1737446676697272.rpcsnap.json.zst
70+
filecoin_ethgetblocktransactioncountbynumber_v2_1769099953133906.rpcsnap.json.zst
71+
filecoin_ethgetblocktransactioncountbynumber_v2_1769099953134061.rpcsnap.json.zst
72+
filecoin_ethgetblocktransactioncountbynumber_v2_1769099953141937.rpcsnap.json.zst
7073
filecoin_ethgetcode_1765803672602510.rpcsnap.json.zst # latest
7174
filecoin_ethgetcode_1765803672604518.rpcsnap.json.zst # concrete
7275
filecoin_ethgetcode_1765803672655291.rpcsnap.json.zst # pending

0 commit comments

Comments
 (0)