From ecee19207f1571145ce110af064ab142e1ef2774 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Tue, 28 Mar 2023 19:23:47 -0400 Subject: [PATCH] fix: determine if eth_getProof blockid arg is latest (#2019) --- crates/rpc/rpc/src/eth/api/state.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/rpc/rpc/src/eth/api/state.rs b/crates/rpc/rpc/src/eth/api/state.rs index 4227983499..03622bd410 100644 --- a/crates/rpc/rpc/src/eth/api/state.rs +++ b/crates/rpc/rpc/src/eth/api/state.rs @@ -54,10 +54,21 @@ where keys: Vec, block_id: Option, ) -> EthResult { + let chain_info = self.client().chain_info()?; let block_id = block_id.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest)); + // if we are trying to create a proof for the latest block, but have a BlockId as input + // that is not BlockNumberOrTag::Latest, then we need to figure out whether or not the + // BlockId corresponds to the latest block + let is_blockid_latest = match block_id { + BlockId::Number(BlockNumberOrTag::Number(num)) => num == chain_info.best_number, + BlockId::Hash(hash) => hash == chain_info.best_hash.into(), + BlockId::Number(BlockNumberOrTag::Latest) => true, + _ => false, + }; + // TODO: remove when HistoricalStateProviderRef::proof is implemented - if !block_id.is_latest() { + if !is_blockid_latest { return Err(EthApiError::InvalidBlockRange) }