Skip to content

Commit

Permalink
feat: accept block params instead of block hash (#5346)
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs authored Feb 26, 2025
1 parent 9386975 commit c6fc7a7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@

- [#5342](https://github.com/ChainSafe/forest/pull/5342) Improved the ergonomics of handling addresses in the `Filecoin.EthGetLogs` and `Filecoin.EthNewFilter` to accept both single addresses and arrays of addresses. This conforms to the Ethereum RPC API.

- [#5346](https://github.com/ChainSafe/forest/pull/5346) `Filecoin.EthGetBlockReceipts` and `Filecoin.EthGetBlockReceiptsLimited` now accepts predefined block parameters on top of the block hash, e.g., `latest`, `earliest`, `pending`.

### Changed

- [#5237](https://github.com/ChainSafe/forest/pull/5237) Stylistic changes to FIL pretty printing.
Expand Down
20 changes: 10 additions & 10 deletions src/rpc/methods/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1409,11 +1409,11 @@ impl RpcMethod<2> for EthGetBlockByNumber {

async fn get_block_receipts<DB: Blockstore + Send + Sync + 'static>(
ctx: &Ctx<DB>,
block_hash: EthHash,
block_param: BlockNumberOrHash,
// TODO(forest): https://github.com/ChainSafe/forest/issues/5177
_limit: Option<usize>,
) -> Result<Vec<EthTxReceipt>, ServerError> {
let ts = get_tipset_from_hash(ctx.chain_store(), &block_hash)?;
let ts = tipset_by_block_number_or_hash(ctx.chain_store(), block_param)?;
let ts_ref = Arc::new(ts);
let ts_key = ts_ref.key();

Expand Down Expand Up @@ -1444,35 +1444,35 @@ pub enum EthGetBlockReceipts {}
impl RpcMethod<1> for EthGetBlockReceipts {
const NAME: &'static str = "Filecoin.EthGetBlockReceipts";
const NAME_ALIAS: Option<&'static str> = Some("eth_getBlockReceipts");
const PARAM_NAMES: [&'static str; 1] = ["block_hash"];
const PARAM_NAMES: [&'static str; 1] = ["block_param"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;
type Params = (EthHash,);
type Params = (BlockNumberOrHash,);
type Ok = Vec<EthTxReceipt>;

async fn handle(
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(block_hash,): Self::Params,
(block_param,): Self::Params,
) -> Result<Self::Ok, ServerError> {
get_block_receipts(&ctx, block_hash, None).await
get_block_receipts(&ctx, block_param, None).await
}
}

pub enum EthGetBlockReceiptsLimited {}
impl RpcMethod<2> for EthGetBlockReceiptsLimited {
const NAME: &'static str = "Filecoin.EthGetBlockReceiptsLimited";
const NAME_ALIAS: Option<&'static str> = Some("eth_getBlockReceiptsLimited");
const PARAM_NAMES: [&'static str; 2] = ["block_hash", "limit"];
const PARAM_NAMES: [&'static str; 2] = ["block_param", "limit"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;
type Params = (EthHash, ChainEpoch);
type Params = (BlockNumberOrHash, ChainEpoch);
type Ok = Vec<EthTxReceipt>;

async fn handle(
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(block_hash, limit): Self::Params,
(block_param, limit): Self::Params,
) -> Result<Self::Ok, ServerError> {
get_block_receipts(&ctx, block_hash, Some(limit as usize)).await
get_block_receipts(&ctx, block_param, Some(limit as usize)).await
}
}

Expand Down
23 changes: 21 additions & 2 deletions src/tool/subcommands/api_cmd/api_compare_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1388,11 +1388,30 @@ fn eth_tests_with_tipset<DB: Blockstore>(store: &Arc<DB>, shared_tipset: &Tipset
))
.unwrap(),
),
RpcTest::identity(EthGetBlockReceipts::request((block_hash.clone(),)).unwrap()),
RpcTest::identity(
EthGetBlockReceipts::request((BlockNumberOrHash::from_block_hash_object(
block_hash.clone(),
true,
),))
.unwrap(),
),
// Nodes might be synced to different epochs, so we can't assert the exact result here.
// Regardless, we want to check if the node returns a valid response and accepts predefined
// values.
RpcTest::basic(
EthGetBlockReceipts::request((BlockNumberOrHash::from_predefined(Predefined::Latest),))
.unwrap(),
),
RpcTest::identity(
EthGetBlockTransactionCountByHash::request((block_hash.clone(),)).unwrap(),
),
RpcTest::identity(EthGetBlockReceiptsLimited::request((block_hash.clone(), 800)).unwrap()),
RpcTest::identity(
EthGetBlockReceiptsLimited::request((
BlockNumberOrHash::from_block_hash_object(block_hash.clone(), true),
800,
))
.unwrap(),
),
RpcTest::identity(
EthGetBlockTransactionCountByNumber::request((EthInt64(shared_tipset.epoch()),))
.unwrap(),
Expand Down

0 comments on commit c6fc7a7

Please sign in to comment.