diff --git a/Cargo.lock b/Cargo.lock index 40ad2af830..9530792689 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1472,7 +1472,6 @@ dependencies = [ "sha3 0.8.2", "sp-api", "sp-blockchain", - "sp-consensus", "sp-io", "sp-runtime", "sp-storage", diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 12a46df934..56e4a74069 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -19,7 +19,6 @@ frontier-rpc-primitives = { path = "primitives" } sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "frontier" } sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "frontier" } sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "frontier" } -sp-consensus = { git = "https://github.com/paritytech/substrate.git", branch = "frontier" } sp-transaction-pool = { git = "https://github.com/paritytech/substrate.git", branch = "frontier" } sp-storage = { git = "https://github.com/paritytech/substrate.git", branch = "frontier" } sp-blockchain = { git = "https://github.com/paritytech/substrate.git", branch = "frontier" } diff --git a/rpc/src/eth.rs b/rpc/src/eth.rs index 3a53850fe8..d02e354308 100644 --- a/rpc/src/eth.rs +++ b/rpc/src/eth.rs @@ -20,10 +20,9 @@ use ethereum::{Block as EthereumBlock, Transaction as EthereumTransaction}; use ethereum_types::{H160, H256, H64, U256, U64, H512}; use jsonrpc_core::{BoxFuture, Result, futures::future::{self, Future}}; use futures::future::TryFutureExt; -use sp_runtime::traits::{Block as BlockT, Header as _, UniqueSaturatedInto, Zero, One, Saturating}; +use sp_runtime::traits::{Block as BlockT, UniqueSaturatedInto, Zero, One, Saturating}; use sp_runtime::transaction_validity::TransactionSource; use sp_api::{ProvideRuntimeApi, BlockId}; -use sp_consensus::SelectChain; use sp_transaction_pool::TransactionPool; use sc_client_api::backend::{StorageProvider, Backend, StateBackend, AuxStore}; use sha3::{Keccak256, Digest}; @@ -39,24 +38,22 @@ use crate::internal_err; pub use frontier_rpc_core::{EthApiServer, NetApiServer}; -pub struct EthApi { +pub struct EthApi { pool: Arc

, client: Arc, - select_chain: SC, convert_transaction: CT, is_authority: bool, _marker: PhantomData<(B, BE)>, } -impl EthApi { +impl EthApi { pub fn new( client: Arc, - select_chain: SC, pool: Arc

, convert_transaction: CT, is_authority: bool ) -> Self { - Self { client, select_chain, pool, convert_transaction, is_authority, _marker: PhantomData } + Self { client, pool, convert_transaction, is_authority, _marker: PhantomData } } } @@ -171,7 +168,7 @@ fn transaction_build( } } -impl EthApi where +impl EthApi where C: ProvideRuntimeApi + StorageProvider + AuxStore, C: HeaderBackend + HeaderMetadata + 'static, C::Api: EthereumRuntimeRPCApi, @@ -179,7 +176,6 @@ impl EthApi where BE::State: StateBackend, B: BlockT + Send + Sync + 'static, C: Send + Sync + 'static, - SC: SelectChain + Clone + 'static, P: TransactionPool + Send + Sync + 'static, CT: ConvertTransaction<::Extrinsic> + Send + Sync + 'static, { @@ -193,9 +189,7 @@ impl EthApi where }, BlockNumber::Latest => { Some(BlockId::Hash( - self.select_chain.best_chain() - .map_err(|err| internal_err(format!("fetch header failed: {:?}", err)))? - .hash() + self.client.info().best_hash )) }, BlockNumber::Earliest => { @@ -233,7 +227,7 @@ impl EthApi where } } -impl EthApiT for EthApi where +impl EthApiT for EthApi where C: ProvideRuntimeApi + StorageProvider + AuxStore, C: HeaderBackend + HeaderMetadata + 'static, C::Api: EthereumRuntimeRPCApi, @@ -241,7 +235,6 @@ impl EthApiT for EthApi where BE::State: StateBackend, B: BlockT + Send + Sync + 'static, C: Send + Sync + 'static, - SC: SelectChain + Clone + 'static, P: TransactionPool + Send + Sync + 'static, CT: ConvertTransaction<::Extrinsic> + Send + Sync + 'static, { @@ -250,12 +243,7 @@ impl EthApiT for EthApi where } fn syncing(&self) -> Result { - let header = self - .select_chain - .best_chain() - .map_err(|err| internal_err(format!("fetch header failed: {:?}", err)))?; - - let block_number = U256::from(header.number().clone().unique_saturated_into()); + let block_number = U256::from(self.client.info().best_number.clone().unique_saturated_into()); Ok(SyncStatus::Info(SyncInfo { starting_block: U256::zero(), @@ -271,14 +259,12 @@ impl EthApiT for EthApi where } fn author(&self) -> Result { - let header = self.select_chain - .best_chain() - .map_err(|err| internal_err(format!("fetch header failed: {:?}", err)))?; + let hash = self.client.info().best_hash; Ok( self.client .runtime_api() - .author(&BlockId::Hash(header.hash())) + .author(&BlockId::Hash(hash)) .map_err(|err| internal_err(format!("fetch runtime chain id failed: {:?}", err)))?.into() ) } @@ -288,21 +274,17 @@ impl EthApiT for EthApi where } fn chain_id(&self) -> Result> { - let header = self.select_chain.best_chain() - .map_err(|err| internal_err(format!("fetch header failed: {:?}", err)))?; - Ok(Some(self.client.runtime_api().chain_id(&BlockId::Hash(header.hash())) + let hash = self.client.info().best_hash; + Ok(Some(self.client.runtime_api().chain_id(&BlockId::Hash(hash)) .map_err(|err| internal_err(format!("fetch runtime chain id failed: {:?}", err)))?.into())) } fn gas_price(&self) -> Result { - let header = self - .select_chain - .best_chain() - .map_err(|err| internal_err(format!("fetch header failed: {:?}", err)))?; + let hash = self.client.info().best_hash; Ok( self.client .runtime_api() - .gas_price(&BlockId::Hash(header.hash())) + .gas_price(&BlockId::Hash(hash)) .map_err(|err| internal_err(format!("fetch runtime chain id failed: {:?}", err)))? .into(), ) @@ -313,11 +295,7 @@ impl EthApiT for EthApi where } fn block_number(&self) -> Result { - let header = self - .select_chain - .best_chain() - .map_err(|err| internal_err(format!("fetch header failed: {:?}", err)))?; - Ok(U256::from(header.number().clone().unique_saturated_into())) + Ok(U256::from(self.client.info().best_number.clone().unique_saturated_into())) } fn balance(&self, address: H160, number: Option) -> Result { @@ -483,17 +461,11 @@ impl EthApiT for EthApi where let transaction_hash = H256::from_slice( Keccak256::digest(&rlp::encode(&transaction)).as_slice() ); - let header = match self.select_chain.best_chain() { - Ok(header) => header, - Err(_) => return Box::new( - future::result(Err(internal_err("fetch header failed"))) - ), - }; - let best_block_hash = header.hash(); + let hash = self.client.info().best_hash; Box::new( self.pool .submit_one( - &BlockId::hash(best_block_hash), + &BlockId::hash(hash), TransactionSource::Local, self.convert_transaction.convert_transaction(transaction), ) @@ -504,10 +476,7 @@ impl EthApiT for EthApi where } fn call(&self, request: CallRequest, _: Option) -> Result { - let header = self - .select_chain - .best_chain() - .map_err(|err| internal_err(format!("fetch header failed: {:?}", err)))?; + let hash = self.client.info().best_hash; let from = request.from.unwrap_or_default(); let to = request.to.unwrap_or_default(); @@ -519,7 +488,7 @@ impl EthApiT for EthApi where let (ret, _) = self.client.runtime_api() .call( - &BlockId::Hash(header.hash()), + &BlockId::Hash(hash), from, data, value, @@ -535,10 +504,7 @@ impl EthApiT for EthApi where } fn estimate_gas(&self, request: CallRequest, _: Option) -> Result { - let header = self - .select_chain - .best_chain() - .map_err(|err| internal_err(format!("fetch header failed: {:?}", err)))?; + let hash = self.client.info().best_hash; let from = request.from.unwrap_or_default(); let gas_price = request.gas_price; @@ -549,7 +515,7 @@ impl EthApiT for EthApi where let (_, used_gas) = self.client.runtime_api() .call( - &BlockId::Hash(header.hash()), + &BlockId::Hash(hash), from, data, value, @@ -778,18 +744,14 @@ impl EthApiT for EthApi where .and_then(|v| v.to_min_block_num()) .map(|s| s.unique_saturated_into()) .unwrap_or( - *self.select_chain.best_chain() - .map_err(|err| internal_err(format!("fetch header failed: {:?}", err)))? - .number() + self.client.info().best_number ); let from_number = filter.from_block .and_then(|v| v.to_min_block_num()) .map(|s| s.unique_saturated_into()) .unwrap_or( - *self.select_chain.best_chain() - .map_err(|err| internal_err(format!("fetch header failed: {:?}", err)))? - .number() + self.client.info().best_number ); while current_number >= from_number { @@ -886,32 +848,29 @@ impl EthApiT for EthApi where } } -pub struct NetApi { - select_chain: SC, +pub struct NetApi { client: Arc, _marker: PhantomData<(B, BE)>, } -impl NetApi { +impl NetApi { pub fn new( client: Arc, - select_chain: SC, ) -> Self { Self { client: client, - select_chain: select_chain, _marker: PhantomData, } } } -impl NetApiT for NetApi where +impl NetApiT for NetApi where C: ProvideRuntimeApi + StorageProvider + AuxStore, + C: HeaderBackend + HeaderMetadata + 'static, C::Api: EthereumRuntimeRPCApi, BE: Backend + 'static, BE::State: StateBackend, C: Send + Sync + 'static, - SC: SelectChain + Clone + 'static, B: BlockT + Send + Sync + 'static, { fn is_listening(&self) -> Result { @@ -923,9 +882,8 @@ impl NetApiT for NetApi where } fn version(&self) -> Result { - let header = self.select_chain.best_chain() - .map_err(|_| internal_err("fetch header failed"))?; - Ok(self.client.runtime_api().chain_id(&BlockId::Hash(header.hash())) + let hash = self.client.info().best_hash; + Ok(self.client.runtime_api().chain_id(&BlockId::Hash(hash)) .map_err(|_| internal_err("fetch runtime chain id failed"))?.to_string()) } } diff --git a/rpc/src/eth_pubsub.rs b/rpc/src/eth_pubsub.rs index a9701772e9..80d8b584b5 100644 --- a/rpc/src/eth_pubsub.rs +++ b/rpc/src/eth_pubsub.rs @@ -1,12 +1,12 @@ use std::{marker::PhantomData, sync::Arc}; use std::collections::BTreeMap; use sp_runtime::traits::{ - Block as BlockT, Header as _, BlakeTwo256, + Block as BlockT, BlakeTwo256, UniqueSaturatedInto }; use sp_transaction_pool::TransactionPool; use sp_api::{ProvideRuntimeApi, BlockId}; -use sp_blockchain::HeaderBackend; +use sp_blockchain::{Error as BlockChainError, HeaderMetadata, HeaderBackend}; use sp_storage::{StorageKey, StorageData}; use sp_io::hashing::twox_128; use sc_client_api::{ @@ -14,7 +14,6 @@ use sc_client_api::{ client::BlockchainEvents }; use sc_rpc::Metadata; -use sp_consensus::SelectChain; use log::warn; use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId, manager::SubscriptionManager}; @@ -36,44 +35,37 @@ use frontier_rpc_primitives::{EthereumRuntimeRPCApi, TransactionStatus}; use sc_network::{NetworkService, ExHashT}; use crate::internal_err; -pub struct EthPubSubApi { +pub struct EthPubSubApi { _pool: Arc

, client: Arc, - select_chain: SC, network: Arc>, subscriptions: SubscriptionManager, _marker: PhantomData<(B, BE)>, } -impl EthPubSubApi { +impl EthPubSubApi { pub fn new( _pool: Arc

, client: Arc, - select_chain: SC, network: Arc>, subscriptions: SubscriptionManager, ) -> Self { - Self { _pool, client, select_chain, network, subscriptions, _marker: PhantomData } + Self { _pool, client, network, subscriptions, _marker: PhantomData } } } -impl EthPubSubApi where +impl EthPubSubApi where B: BlockT + Send + Sync + 'static, P: TransactionPool + Send + Sync + 'static, C: ProvideRuntimeApi + StorageProvider + - BlockchainEvents + HeaderBackend + AuxStore, + BlockchainEvents + AuxStore, + C: HeaderBackend + HeaderMetadata + 'static, C::Api: EthereumRuntimeRPCApi, C: Send + Sync + 'static, BE: Backend + 'static, BE::State: StateBackend, - SC: SelectChain + Clone + 'static, { fn native_block_number(&self, number: Option) -> JsonRpcResult> { - let header = self - .select_chain - .best_chain() - .map_err(|_| internal_err("fetch header failed"))?; - let mut native_number: Option = None; if let Some(number) = number { @@ -93,7 +85,7 @@ impl EthPubSubApi where }, BlockNumber::Latest => { native_number = Some( - header.number().clone().unique_saturated_into() as u32 + self.client.info().best_number.clone().unique_saturated_into() as u32 ); }, BlockNumber::Earliest => { @@ -105,7 +97,7 @@ impl EthPubSubApi where }; } else { native_number = Some( - header.number().clone().unique_saturated_into() as u32 + self.client.info().best_number.clone().unique_saturated_into() as u32 ); } Ok(native_number) @@ -377,17 +369,17 @@ macro_rules! stream_build { }}; } -impl EthPubSubApiT for EthPubSubApi +impl EthPubSubApiT for EthPubSubApi where B: BlockT + Send + Sync + 'static, P: TransactionPool + Send + Sync + 'static, C: ProvideRuntimeApi + StorageProvider + - BlockchainEvents + HeaderBackend + AuxStore, + BlockchainEvents + AuxStore, + C: HeaderBackend + HeaderMetadata + 'static, C: Send + Sync + 'static, C::Api: EthereumRuntimeRPCApi, BE: Backend + 'static, BE::State: StateBackend, - SC: SelectChain + Clone + 'static, { type Metadata = Metadata; fn subscribe( diff --git a/template/node/src/rpc.rs b/template/node/src/rpc.rs index 414d742afd..74ce5b5935 100644 --- a/template/node/src/rpc.rs +++ b/template/node/src/rpc.rs @@ -24,7 +24,6 @@ use frontier_template_runtime::{Hash, AccountId, Index, opaque::Block, Balance}; use sp_api::ProvideRuntimeApi; use sp_transaction_pool::TransactionPool; use sp_blockchain::{Error as BlockChainError, HeaderMetadata, HeaderBackend}; -use sp_consensus::SelectChain; use sc_rpc_api::DenyUnsafe; use sc_client_api::{ backend::{StorageProvider, Backend, StateBackend, AuxStore}, @@ -49,13 +48,11 @@ pub struct LightDeps { } /// Full client dependencies. -pub struct FullDeps { +pub struct FullDeps { /// The client instance to use. pub client: Arc, /// Transaction pool instance. pub pool: Arc

, - /// The SelectChain Strategy - pub select_chain: SC, /// Whether to deny unsafe calls pub deny_unsafe: DenyUnsafe, /// The Node authority flag @@ -67,15 +64,15 @@ pub struct FullDeps { } /// Instantiate all Full RPC extensions. -pub fn create_full( - deps: FullDeps, +pub fn create_full( + deps: FullDeps, subscription_task_executor: SubscriptionTaskExecutor ) -> jsonrpc_core::IoHandler where BE: Backend + 'static, BE::State: StateBackend, C: ProvideRuntimeApi + StorageProvider + AuxStore, C: BlockchainEvents, - C: HeaderBackend + HeaderMetadata + 'static, + C: HeaderBackend + HeaderMetadata, C: Send + Sync + 'static, C::Api: substrate_frame_rpc_system::AccountNonceApi, C::Api: BlockBuilder, @@ -83,7 +80,6 @@ pub fn create_full( C::Api: frontier_rpc_primitives::EthereumRuntimeRPCApi, ::Error: fmt::Debug, P: TransactionPool + 'static, - SC: SelectChain +'static, { use substrate_frame_rpc_system::{FullSystem, SystemApi}; use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi}; @@ -93,7 +89,6 @@ pub fn create_full( let FullDeps { client, pool, - select_chain, deny_unsafe, is_authority, network, @@ -109,7 +104,6 @@ pub fn create_full( io.extend_with( EthApiServer::to_delegate(EthApi::new( client.clone(), - select_chain.clone(), pool.clone(), frontier_template_runtime::TransactionConverter, is_authority, @@ -119,14 +113,12 @@ pub fn create_full( io.extend_with( NetApiServer::to_delegate(NetApi::new( client.clone(), - select_chain.clone(), )) ); io.extend_with( EthPubSubApiServer::to_delegate(EthPubSubApi::new( pool.clone(), client.clone(), - select_chain.clone(), network.clone(), SubscriptionManager::new(Arc::new(subscription_task_executor)), )) diff --git a/template/node/src/service.rs b/template/node/src/service.rs index 5acee24aa1..6997440b8e 100644 --- a/template/node/src/service.rs +++ b/template/node/src/service.rs @@ -181,14 +181,12 @@ pub fn new_full(config: Configuration, manual_seal: bool) -> Result