From 69ef658bdec0c2302a8b5c2d68ce82a1adb88291 Mon Sep 17 00:00:00 2001 From: bear Date: Wed, 24 Apr 2024 09:54:27 +0800 Subject: [PATCH] Replace the is_canon --- client/rpc/src/eth/block.rs | 2 +- client/rpc/src/eth/execute.rs | 2 +- client/rpc/src/eth/fee.rs | 2 +- client/rpc/src/eth/state.rs | 2 +- client/rpc/src/lib.rs | 72 ++++++++--------------------------- 5 files changed, 20 insertions(+), 60 deletions(-) diff --git a/client/rpc/src/eth/block.rs b/client/rpc/src/eth/block.rs index 571c904a27..7f1c2cb06c 100644 --- a/client/rpc/src/eth/block.rs +++ b/client/rpc/src/eth/block.rs @@ -34,7 +34,7 @@ use fp_rpc::EthereumRuntimeRPCApi; use crate::{ eth::{rich_block_build, BlockInfo, Eth, EthConfig}, - frontier_backend_client, internal_err, + internal_err, }; impl Eth diff --git a/client/rpc/src/eth/execute.rs b/client/rpc/src/eth/execute.rs index bf8df228c7..0279cf78e2 100644 --- a/client/rpc/src/eth/execute.rs +++ b/client/rpc/src/eth/execute.rs @@ -43,7 +43,7 @@ use fp_storage::{EVM_ACCOUNT_CODES, PALLET_EVM}; use crate::{ eth::{Eth, EthConfig}, - frontier_backend_client, internal_err, + internal_err, }; /// Default JSONRPC error code return by geth diff --git a/client/rpc/src/eth/fee.rs b/client/rpc/src/eth/fee.rs index d40a64f101..912740bcd9 100644 --- a/client/rpc/src/eth/fee.rs +++ b/client/rpc/src/eth/fee.rs @@ -30,7 +30,7 @@ use fp_rpc::EthereumRuntimeRPCApi; use crate::{ eth::{Eth, EthConfig}, - frontier_backend_client, internal_err, + internal_err, }; impl Eth diff --git a/client/rpc/src/eth/state.rs b/client/rpc/src/eth/state.rs index fca69be9b5..8d8f872776 100644 --- a/client/rpc/src/eth/state.rs +++ b/client/rpc/src/eth/state.rs @@ -34,7 +34,7 @@ use fp_rpc::EthereumRuntimeRPCApi; use crate::{ eth::{Eth, EthConfig}, - frontier_backend_client, internal_err, + internal_err, }; impl Eth diff --git a/client/rpc/src/lib.rs b/client/rpc/src/lib.rs index b4935289fe..d82751c903 100644 --- a/client/rpc/src/lib.rs +++ b/client/rpc/src/lib.rs @@ -188,32 +188,6 @@ pub mod frontier_backend_client { } } - // pub async fn native_block_id( - // client: &C, - // backend: &dyn fc_api::Backend, - // number: Option, - // ) -> RpcResult>> - // where - // B: BlockT, - // C: HeaderBackend + 'static, - // { - // Ok(match number.unwrap_or(BlockNumberOrHash::Latest) { - // BlockNumberOrHash::Hash { hash, .. } => { - // if let Ok(Some(hash)) = load_hash::(client, backend, hash).await { - // Some(BlockId::Hash(hash)) - // } else { - // None - // } - // } - // BlockNumberOrHash::Num(number) => Some(BlockId::Number(number.unique_saturated_into())), - // BlockNumberOrHash::Latest => Some(BlockId::Hash(client.info().best_hash)), - // BlockNumberOrHash::Earliest => Some(BlockId::Number(Zero::zero())), - // BlockNumberOrHash::Pending => None, - // BlockNumberOrHash::Safe => Some(BlockId::Hash(client.info().finalized_hash)), - // BlockNumberOrHash::Finalized => Some(BlockId::Hash(client.info().finalized_hash)), - // }) - // } - pub async fn load_hash( client: &C, backend: &dyn fc_api::Backend, @@ -230,7 +204,7 @@ pub mod frontier_backend_client { if let Some(substrate_hashes) = substrate_hashes { for substrate_hash in substrate_hashes { - if is_canon::(client, substrate_hash) { + if backend.is_canon(substrate_hash).await { return Ok(Some(substrate_hash)); } } @@ -238,19 +212,6 @@ pub mod frontier_backend_client { Ok(None) } - pub fn is_canon(client: &C, target_hash: B::Hash) -> bool - where - B: BlockT, - C: HeaderBackend + 'static, - { - if let Ok(Some(number)) = client.number(target_hash) { - if let Ok(Some(hash)) = client.hash(number) { - return hash == target_hash; - } - } - false - } - pub async fn load_transactions( client: &C, backend: &dyn fc_api::Backend, @@ -266,22 +227,21 @@ pub mod frontier_backend_client { .await .map_err(|err| internal_err(format!("fetch aux store failed: {:?}", err)))?; - transaction_metadata - .iter() - .find(|meta| is_canon::(client, meta.substrate_block_hash)) - .map_or_else( - || { - if !only_canonical && transaction_metadata.len() > 0 { - Ok(Some(( - transaction_metadata[0].ethereum_block_hash, - transaction_metadata[0].ethereum_index, - ))) - } else { - Ok(None) - } - }, - |meta| Ok(Some((meta.ethereum_block_hash, meta.ethereum_index))), - ) + for meta in &transaction_metadata { + if backend.is_canon(meta.substrate_block_hash).await { + return Ok(Some((meta.ethereum_block_hash, meta.ethereum_index))); + } else { + if !only_canonical && transaction_metadata.len() > 0 { + return Ok(Some(( + transaction_metadata[0].ethereum_block_hash, + transaction_metadata[0].ethereum_index, + ))); + } else { + return Ok(None); + } + } + } + Ok(None) } }