diff --git a/client/rpc/src/eth/block.rs b/client/rpc/src/eth/block.rs index 7f1c2cb06c..04c9a6c08d 100644 --- a/client/rpc/src/eth/block.rs +++ b/client/rpc/src/eth/block.rs @@ -89,7 +89,6 @@ where ) -> RpcResult> { let client = Arc::clone(&self.client); let block_data_cache = Arc::clone(&self.block_data_cache); - let backend = Arc::clone(&self.backend); let graph = Arc::clone(&self.graph); match self.backend.block_id(Some(number_or_hash)).await { diff --git a/client/rpc/src/eth/filter.rs b/client/rpc/src/eth/filter.rs index e2b84e6297..708ae6ba5a 100644 --- a/client/rpc/src/eth/filter.rs +++ b/client/rpc/src/eth/filter.rs @@ -473,17 +473,14 @@ where let mut ret: Vec = Vec::new(); if let Some(hash) = filter.block_hash { - let substrate_hash = match frontier_backend_client::load_hash::( - client.as_ref(), - backend.as_ref(), - hash, - ) - .await - .map_err(|err| internal_err(format!("{:?}", err)))? - { - Some(hash) => hash, - _ => return Err(crate::err(-32000, "unknown block", None)), - }; + let substrate_hash = + match frontier_backend_client::load_hash::(backend.as_ref(), hash) + .await + .map_err(|err| internal_err(format!("{:?}", err)))? + { + Some(hash) => hash, + _ => return Err(crate::err(-32000, "unknown block", None)), + }; let schema = fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash); let block = block_data_cache.current_block(schema, substrate_hash).await; diff --git a/client/rpc/src/eth/mod.rs b/client/rpc/src/eth/mod.rs index 944836e0ee..3708e8780d 100644 --- a/client/rpc/src/eth/mod.rs +++ b/client/rpc/src/eth/mod.rs @@ -166,17 +166,14 @@ where &self, eth_block_hash: H256, ) -> RpcResult> { - let substrate_hash = match frontier_backend_client::load_hash::( - self.client.as_ref(), - self.backend.as_ref(), - eth_block_hash, - ) - .await - .map_err(|err| internal_err(format!("{:?}", err)))? - { - Some(hash) => hash, - _ => return Ok(BlockInfo::default()), - }; + let substrate_hash = + match frontier_backend_client::load_hash::(self.backend.as_ref(), eth_block_hash) + .await + .map_err(|err| internal_err(format!("{:?}", err)))? + { + Some(hash) => hash, + _ => return Ok(BlockInfo::default()), + }; self.block_info_by_substrate_hash(substrate_hash).await } @@ -186,7 +183,6 @@ where ethereum_tx_hash: H256, ) -> RpcResult<(BlockInfo, usize)> { let (eth_block_hash, index) = match frontier_backend_client::load_transactions::( - self.client.as_ref(), self.backend.as_ref(), ethereum_tx_hash, true, @@ -198,17 +194,14 @@ where None => return Ok((BlockInfo::default(), 0)), }; - let substrate_hash = match frontier_backend_client::load_hash::( - self.client.as_ref(), - self.backend.as_ref(), - eth_block_hash, - ) - .await - .map_err(|err| internal_err(format!("{:?}", err)))? - { - Some(hash) => hash, - _ => return Ok((BlockInfo::default(), 0)), - }; + let substrate_hash = + match frontier_backend_client::load_hash::(self.backend.as_ref(), eth_block_hash) + .await + .map_err(|err| internal_err(format!("{:?}", err)))? + { + Some(hash) => hash, + _ => return Ok((BlockInfo::default(), 0)), + }; Ok(( self.block_info_by_substrate_hash(substrate_hash).await?, diff --git a/client/rpc/src/eth/transaction.rs b/client/rpc/src/eth/transaction.rs index cf15d394bd..6884156dc6 100644 --- a/client/rpc/src/eth/transaction.rs +++ b/client/rpc/src/eth/transaction.rs @@ -53,75 +53,74 @@ where let backend = Arc::clone(&self.backend); let graph = Arc::clone(&self.graph); - let (eth_block_hash, index) = match frontier_backend_client::load_transactions::( - client.as_ref(), - backend.as_ref(), - hash, - true, - ) - .await - .map_err(|err| internal_err(format!("{:?}", err)))? - { - Some((eth_block_hash, index)) => (eth_block_hash, index as usize), - None => { - let api = client.runtime_api(); - let best_block = client.info().best_hash; + let (eth_block_hash, index) = + match frontier_backend_client::load_transactions::(backend.as_ref(), hash, true) + .await + .map_err(|err| internal_err(format!("{:?}", err)))? + { + Some((eth_block_hash, index)) => (eth_block_hash, index as usize), + None => { + let api = client.runtime_api(); + let best_block = client.info().best_hash; - let api_version = if let Ok(Some(api_version)) = - api.api_version::>(best_block) - { - api_version - } else { - return Err(internal_err("failed to retrieve Runtime Api version")); - }; - // If the transaction is not yet mapped in the frontier db, - // check for it in the transaction pool. - let mut xts: Vec<::Extrinsic> = Vec::new(); - // Collect transactions in the ready validated pool. - xts.extend( - graph - .validated_pool() - .ready() - .map(|in_pool_tx| in_pool_tx.data().clone()) - .collect::::Extrinsic>>(), - ); + let api_version = if let Ok(Some(api_version)) = + api.api_version::>(best_block) + { + api_version + } else { + return Err(internal_err("failed to retrieve Runtime Api version")); + }; + // If the transaction is not yet mapped in the frontier db, + // check for it in the transaction pool. + let mut xts: Vec<::Extrinsic> = Vec::new(); + // Collect transactions in the ready validated pool. + xts.extend( + graph + .validated_pool() + .ready() + .map(|in_pool_tx| in_pool_tx.data().clone()) + .collect::::Extrinsic>>(), + ); - // Collect transactions in the future validated pool. - xts.extend( - graph - .validated_pool() - .futures() - .iter() - .map(|(_hash, extrinsic)| extrinsic.clone()) - .collect::::Extrinsic>>(), - ); + // Collect transactions in the future validated pool. + xts.extend( + graph + .validated_pool() + .futures() + .iter() + .map(|(_hash, extrinsic)| extrinsic.clone()) + .collect::::Extrinsic>>(), + ); - let ethereum_transactions: Vec = if api_version > 1 { - api.extrinsic_filter(best_block, xts).map_err(|err| { - internal_err(format!("fetch runtime extrinsic filter failed: {:?}", err)) - })? - } else { - #[allow(deprecated)] - let legacy = api.extrinsic_filter_before_version_2(best_block, xts) - .map_err(|err| { + let ethereum_transactions: Vec = if api_version > 1 { + api.extrinsic_filter(best_block, xts).map_err(|err| { internal_err(format!( "fetch runtime extrinsic filter failed: {:?}", err )) - })?; - legacy.into_iter().map(|tx| tx.into()).collect() - }; + })? + } else { + #[allow(deprecated)] + let legacy = api.extrinsic_filter_before_version_2(best_block, xts) + .map_err(|err| { + internal_err(format!( + "fetch runtime extrinsic filter failed: {:?}", + err + )) + })?; + legacy.into_iter().map(|tx| tx.into()).collect() + }; - for txn in ethereum_transactions { - let inner_hash = txn.hash(); - if hash == inner_hash { - return Ok(Some(transaction_build(txn, None, None, None))); + for txn in ethereum_transactions { + let inner_hash = txn.hash(); + if hash == inner_hash { + return Ok(Some(transaction_build(txn, None, None, None))); + } } + // Unknown transaction. + return Ok(None); } - // Unknown transaction. - return Ok(None); - } - }; + }; let BlockInfo { block, diff --git a/client/rpc/src/lib.rs b/client/rpc/src/lib.rs index d82751c903..4fcf3c101c 100644 --- a/client/rpc/src/lib.rs +++ b/client/rpc/src/lib.rs @@ -70,13 +70,8 @@ pub mod frontier_backend_client { }; use sp_blockchain::HeaderBackend; use sp_io::hashing::{blake2_128, twox_128}; - use sp_runtime::{ - generic::BlockId, - traits::{Block as BlockT, HashingFor, UniqueSaturatedInto, Zero}, - }; + use sp_runtime::traits::{Block as BlockT, HashingFor}; use sp_state_machine::OverlayedChanges; - // Frontier - use fc_rpc_core::types::BlockNumberOrHash; /// Implements a default runtime storage override. /// It assumes that the balances and nonces are stored in pallet `system.account`, and @@ -189,7 +184,6 @@ pub mod frontier_backend_client { } pub async fn load_hash( - client: &C, backend: &dyn fc_api::Backend, hash: H256, ) -> RpcResult> @@ -213,7 +207,6 @@ pub mod frontier_backend_client { } pub async fn load_transactions( - client: &C, backend: &dyn fc_api::Backend, transaction_hash: H256, only_canonical: bool, @@ -375,7 +368,6 @@ mod tests { // Expect B1 to be canon assert_eq!( futures::executor::block_on(super::frontier_backend_client::load_hash( - client.as_ref(), backend.as_ref(), ethereum_block_hash )) @@ -404,7 +396,6 @@ mod tests { // Still expect B1 to be canon assert_eq!( futures::executor::block_on(super::frontier_backend_client::load_hash( - client.as_ref(), backend.as_ref(), ethereum_block_hash )) @@ -424,7 +415,6 @@ mod tests { // Expect B2 to be new canon assert_eq!( futures::executor::block_on(super::frontier_backend_client::load_hash( - client.as_ref(), backend.as_ref(), ethereum_block_hash ))