Skip to content

Commit 668ec50

Browse files
authored
feat(l1, l2): add EIP-1898 blockHash support to eth_call (#6130)
## Summary - Add support for the `blockHash` parameter to `eth_call` as specified in [EIP-1898](https://eips.ethereum.org/EIPS/eip-1898) - Previously, 5 of 6 EIP-1898 methods supported block hashes; only `eth_call` used `BlockIdentifier` instead of `BlockIdentifierOrHash` - Now all 6 methods are consistent: `eth_getBalance`, `eth_getStorageAt`, `eth_getTransactionCount`, `eth_getCode`, `eth_call`, and `eth_getProof` ## Changes - Add `resolve_block_header()` method to `BlockIdentifierOrHash` in `block_identifier.rs` - Update `CallRequest` struct to use `BlockIdentifierOrHash` instead of `BlockIdentifier` in `transaction.rs` ## Test plan - [x] `cargo build -p ethrex-rpc` passes - [x] `cargo test -p ethrex-rpc` passes (46 tests)
1 parent c13cd03 commit 668ec50

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

crates/networking/rpc/eth/transaction.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
eth::block,
55
rpc::{RpcApiContext, RpcHandler},
66
types::{
7-
block_identifier::BlockIdentifier,
7+
block_identifier::{BlockIdentifier, BlockIdentifierOrHash},
88
transaction::{RpcTransaction, SendRawTransactionRequest},
99
},
1010
utils::RpcErr,
@@ -30,7 +30,7 @@ pub const TRANSACTION_GAS: u64 = 21_000; // Per transaction not creating a contr
3030

3131
pub struct CallRequest {
3232
transaction: GenericTransaction,
33-
block: Option<BlockIdentifier>,
33+
block: Option<BlockIdentifierOrHash>,
3434
}
3535

3636
pub struct GetTransactionByBlockNumberAndIndexRequest {
@@ -90,7 +90,7 @@ impl RpcHandler for CallRequest {
9090
}
9191
let block = match params.get(1) {
9292
// Differentiate between missing and bad block param
93-
Some(value) => Some(BlockIdentifier::parse(value.clone(), 1)?),
93+
Some(value) => Some(BlockIdentifierOrHash::parse(value.clone(), 1)?),
9494
None => None,
9595
};
9696
Ok(CallRequest {
@@ -99,7 +99,10 @@ impl RpcHandler for CallRequest {
9999
})
100100
}
101101
async fn handle(&self, context: RpcApiContext) -> Result<Value, RpcErr> {
102-
let block = self.block.clone().unwrap_or_default();
102+
let block = self
103+
.block
104+
.clone()
105+
.unwrap_or(BlockIdentifierOrHash::Identifier(BlockIdentifier::default()));
103106
debug!("Requested call on block: {}", block);
104107
let header = match block.resolve_block_header(&context.storage).await? {
105108
Some(header) => header,

crates/networking/rpc/types/block_identifier.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,16 @@ impl BlockIdentifier {
9090
}
9191

9292
impl BlockIdentifierOrHash {
93-
#[allow(unused)]
93+
pub async fn resolve_block_header(
94+
&self,
95+
storage: &Store,
96+
) -> Result<Option<BlockHeader>, StoreError> {
97+
match self.resolve_block_number(storage).await? {
98+
Some(block_number) => storage.get_block_header(block_number),
99+
_ => Ok(None),
100+
}
101+
}
102+
94103
pub async fn resolve_block_number(
95104
&self,
96105
storage: &Store,

0 commit comments

Comments
 (0)