From 340ff4eb69bbe63f514c9942259d8bede42402ba Mon Sep 17 00:00:00 2001 From: Qinxuan Chen Date: Wed, 1 Mar 2023 17:42:55 +0800 Subject: [PATCH] chore(client): remove useless trait bound (#1009) --- Cargo.lock | 2 - client/cli/src/frontier_db_cmd/mapping_db.rs | 6 +- client/cli/src/frontier_db_cmd/mod.rs | 6 +- client/cli/src/frontier_db_cmd/tests.rs | 70 +++++++++---------- client/consensus/Cargo.toml | 1 - client/consensus/src/lib.rs | 15 ++-- client/db/src/lib.rs | 5 +- client/db/src/parity_db_adapter.rs | 5 +- client/db/src/upgrade.rs | 46 +++++------- client/db/src/utils.rs | 36 +++------- client/mapping-sync/src/lib.rs | 44 +++++++----- client/mapping-sync/src/worker.rs | 21 +++--- client/rpc/Cargo.toml | 1 - client/rpc/src/eth/block.rs | 14 ++-- client/rpc/src/eth/cache/mod.rs | 16 ++--- client/rpc/src/eth/client.rs | 15 ++-- client/rpc/src/eth/execute.rs | 17 ++--- client/rpc/src/eth/fee.rs | 13 ++-- client/rpc/src/eth/filter.rs | 22 +++--- client/rpc/src/eth/mod.rs | 28 ++++---- client/rpc/src/eth/state.rs | 16 ++--- client/rpc/src/eth/submit.rs | 17 ++--- client/rpc/src/eth/transaction.rs | 13 ++-- client/rpc/src/eth_pubsub.rs | 16 ++--- client/rpc/src/lib.rs | 51 +++++++------- client/rpc/src/net.rs | 6 +- client/rpc/src/web3.rs | 5 +- client/storage/src/lib.rs | 5 +- .../src/overrides/schema_v1_override.rs | 4 +- .../src/overrides/schema_v2_override.rs | 4 +- .../src/overrides/schema_v3_override.rs | 4 +- template/node/src/rpc/eth.rs | 23 +++--- template/node/src/rpc/mod.rs | 19 +++-- 33 files changed, 259 insertions(+), 307 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9ddd29b03..3697523a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1868,7 +1868,6 @@ dependencies = [ "fc-db", "fp-consensus", "fp-rpc", - "sc-client-api", "sc-consensus", "sp-api", "sp-block-builder", @@ -1956,7 +1955,6 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-storage", "substrate-prometheus-endpoint", "substrate-test-runtime-client", "tempfile", diff --git a/client/cli/src/frontier_db_cmd/mapping_db.rs b/client/cli/src/frontier_db_cmd/mapping_db.rs index e8847b1b6..cf12ee96d 100644 --- a/client/cli/src/frontier_db_cmd/mapping_db.rs +++ b/client/cli/src/frontier_db_cmd/mapping_db.rs @@ -21,6 +21,8 @@ use std::sync::Arc; use ethereum_types::H256; use serde::Deserialize; // Substrate +use sp_api::ProvideRuntimeApi; +use sp_blockchain::HeaderBackend; use sp_runtime::{generic::BlockId, traits::Block as BlockT}; // Frontier use fp_rpc::EthereumRuntimeRPCApi; @@ -46,9 +48,9 @@ pub struct MappingDb<'a, C, B: BlockT> { impl<'a, C, B: BlockT> MappingDb<'a, C, B> where - C: sp_api::ProvideRuntimeApi, + C: ProvideRuntimeApi, C::Api: EthereumRuntimeRPCApi, - C: sp_blockchain::HeaderBackend, + C: HeaderBackend, { pub fn new(cmd: &'a FrontierDbCmd, client: Arc, backend: Arc>) -> Self { Self { diff --git a/client/cli/src/frontier_db_cmd/mod.rs b/client/cli/src/frontier_db_cmd/mod.rs index 976697deb..b3f8762e3 100644 --- a/client/cli/src/frontier_db_cmd/mod.rs +++ b/client/cli/src/frontier_db_cmd/mod.rs @@ -29,6 +29,8 @@ use ethereum_types::H256; use serde::Deserialize; // Substrate use sc_cli::{PruningParams, SharedParams}; +use sp_api::ProvideRuntimeApi; +use sp_blockchain::HeaderBackend; use sp_runtime::traits::Block as BlockT; use self::{ @@ -102,9 +104,9 @@ impl FrontierDbCmd { backend: Arc>, ) -> sc_cli::Result<()> where - C: sp_api::ProvideRuntimeApi, + C: ProvideRuntimeApi, C::Api: fp_rpc::EthereumRuntimeRPCApi, - C: sp_blockchain::HeaderBackend, + C: HeaderBackend, { match self.column { Column::Meta => { diff --git a/client/cli/src/frontier_db_cmd/tests.rs b/client/cli/src/frontier_db_cmd/tests.rs index 9e16e143e..f3e22c5c9 100644 --- a/client/cli/src/frontier_db_cmd/tests.rs +++ b/client/cli/src/frontier_db_cmd/tests.rs @@ -26,6 +26,7 @@ use tempfile::tempdir; // Substrate use sc_block_builder::BlockBuilderProvider; use sc_cli::DatabasePruningMode; +use sp_blockchain::HeaderBackend; use sp_consensus::BlockOrigin; use sp_io::hashing::twox_128; use sp_runtime::{ @@ -45,14 +46,11 @@ use crate::frontier_db_cmd::{Column, FrontierDbCmd, Operation}; type OpaqueBlock = Block, substrate_test_runtime_client::runtime::Extrinsic>; -pub fn open_frontier_backend( +pub fn open_frontier_backend>( client: Arc, path: PathBuf, -) -> Result>, String> -where - C: sp_blockchain::HeaderBackend, -{ - Ok(Arc::new(fc_db::Backend::::new( +) -> Result>, String> { + Ok(Arc::new(fc_db::Backend::::new( client, &fc_db::DatabaseSettings { source: sc_client_db::DatabaseSource::RocksDb { @@ -129,8 +127,8 @@ fn schema_create_success_if_value_is_empty() { let (client, _) = TestClientBuilder::new().build_with_native_executor::(None); let client = Arc::new(client); // Create a temporary frontier secondary DB. - let backend = - open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created"); + let backend = open_frontier_backend::(client.clone(), tmp.into_path()) + .expect("a temporary db was created"); assert_eq!(backend.meta().ethereum_schema(), Ok(None)); @@ -160,8 +158,8 @@ fn schema_create_fails_if_value_is_not_empty() { let (client, _) = TestClientBuilder::new().build_with_native_executor::(None); let client = Arc::new(client); // Create a temporary frontier secondary DB. - let backend = - open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created"); + let backend = open_frontier_backend::(client.clone(), tmp.into_path()) + .expect("a temporary db was created"); let data_before = vec![(EthereumStorageSchema::V2, H256::default())]; @@ -191,8 +189,8 @@ fn schema_read_works() { let (client, _) = TestClientBuilder::new().build_with_native_executor::(None); let client = Arc::new(client); // Create a temporary frontier secondary DB. - let backend = - open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created"); + let backend = open_frontier_backend::(client.clone(), tmp.into_path()) + .expect("a temporary db was created"); assert_eq!(backend.meta().ethereum_schema(), Ok(None)); @@ -223,8 +221,8 @@ fn schema_update_works() { let (client, _) = TestClientBuilder::new().build_with_native_executor::(None); let client = Arc::new(client); // Create a temporary frontier secondary DB. - let backend = - open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created"); + let backend = open_frontier_backend::(client.clone(), tmp.into_path()) + .expect("a temporary db was created"); assert_eq!(backend.meta().ethereum_schema(), Ok(None)); // Run the command @@ -250,8 +248,8 @@ fn schema_delete_works() { let (client, _) = TestClientBuilder::new().build_with_native_executor::(None); let client = Arc::new(client); // Create a temporary frontier secondary DB. - let backend = - open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created"); + let backend = open_frontier_backend::(client.clone(), tmp.into_path()) + .expect("a temporary db was created"); let data = vec![(EthereumStorageSchema::V2, H256::default())]; @@ -281,8 +279,8 @@ fn tips_create_success_if_value_is_empty() { let (client, _) = TestClientBuilder::new().build_with_native_executor::(None); let client = Arc::new(client); // Create a temporary frontier secondary DB. - let backend = - open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created"); + let backend = open_frontier_backend::(client.clone(), tmp.into_path()) + .expect("a temporary db was created"); assert_eq!(backend.meta().current_syncing_tips(), Ok(vec![])); // Run the command @@ -310,8 +308,8 @@ fn tips_create_fails_if_value_is_not_empty() { let (client, _) = TestClientBuilder::new().build_with_native_executor::(None); let client = Arc::new(client); // Create a temporary frontier secondary DB. - let backend = - open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created"); + let backend = open_frontier_backend::(client.clone(), tmp.into_path()) + .expect("a temporary db was created"); let data_before = vec![H256::default()]; @@ -340,8 +338,8 @@ fn tips_read_works() { let (client, _) = TestClientBuilder::new().build_with_native_executor::(None); let client = Arc::new(client); // Create a temporary frontier secondary DB. - let backend = - open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created"); + let backend = open_frontier_backend::(client.clone(), tmp.into_path()) + .expect("a temporary db was created"); assert_eq!(backend.meta().current_syncing_tips(), Ok(vec![])); @@ -371,8 +369,8 @@ fn tips_update_works() { let (client, _) = TestClientBuilder::new().build_with_native_executor::(None); let client = Arc::new(client); // Create a temporary frontier secondary DB. - let backend = - open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created"); + let backend = open_frontier_backend::(client.clone(), tmp.into_path()) + .expect("a temporary db was created"); assert_eq!(backend.meta().current_syncing_tips(), Ok(vec![])); // Run the command @@ -398,8 +396,8 @@ fn tips_delete_works() { let (client, _) = TestClientBuilder::new().build_with_native_executor::(None); let client = Arc::new(client); // Create a temporary frontier secondary DB. - let backend = - open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created"); + let backend = open_frontier_backend::(client.clone(), tmp.into_path()) + .expect("a temporary db was created"); let data = vec![H256::default()]; @@ -429,8 +427,8 @@ fn non_existent_meta_static_keys_are_no_op() { let (client, _) = TestClientBuilder::new().build_with_native_executor::(None); let client = Arc::new(client); // Create a temporary frontier secondary DB. - let backend = - open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created"); + let backend = open_frontier_backend::(client.clone(), tmp.into_path()) + .expect("a temporary db was created"); let client = client; let data = vec![(EthereumStorageSchema::V1, H256::default())]; @@ -503,8 +501,8 @@ fn not_deserializable_input_value_is_no_op() { let (client, _) = TestClientBuilder::new().build_with_native_executor::(None); let client = Arc::new(client); // Create a temporary frontier secondary DB. - let backend = - open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created"); + let backend = open_frontier_backend::(client.clone(), tmp.into_path()) + .expect("a temporary db was created"); let client = client; // Run the Create command @@ -560,8 +558,8 @@ fn commitment_create() { let test_value_path = test_json_file(&tmp, &TestValue::Commitment(block_hash)); // Create a temporary frontier secondary DB. - let backend = - open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created"); + let backend = open_frontier_backend::(client.clone(), tmp.into_path()) + .expect("a temporary db was created"); // Run the command using some ethereum block hash as key. let ethereum_block_hash = H256::default(); @@ -645,8 +643,8 @@ fn commitment_update() { let test_value_path = test_json_file(&tmp, &TestValue::Commitment(block_a1_hash)); // Create a temporary frontier secondary DB. - let backend = - open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created"); + let backend = open_frontier_backend::(client.clone(), tmp.into_path()) + .expect("a temporary db was created"); // Run the command using some ethereum block hash as key. let ethereum_block_hash = H256::default(); @@ -767,8 +765,8 @@ fn mapping_read_works() { let test_value_path = test_json_file(&tmp, &TestValue::Commitment(block_hash)); // Create a temporary frontier secondary DB. - let backend = - open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created"); + let backend = open_frontier_backend::(client.clone(), tmp.into_path()) + .expect("a temporary db was created"); // Create command using some ethereum block hash as key. let ethereum_block_hash = H256::default(); diff --git a/client/consensus/Cargo.toml b/client/consensus/Cargo.toml index f95f5454e..83b8e69a6 100644 --- a/client/consensus/Cargo.toml +++ b/client/consensus/Cargo.toml @@ -14,7 +14,6 @@ targets = ["x86_64-unknown-linux-gnu"] async-trait = "0.1" thiserror = "1.0" # Substrate -sc-client-api = { workspace = true } sc-consensus = { workspace = true } sp-api = { workspace = true } sp-block-builder = { workspace = true, features = ["std"] } diff --git a/client/consensus/src/lib.rs b/client/consensus/src/lib.rs index 88b3a4361..39b17cce1 100644 --- a/client/consensus/src/lib.rs +++ b/client/consensus/src/lib.rs @@ -19,11 +19,10 @@ use std::{collections::HashMap, marker::PhantomData, sync::Arc}; // Substrate -use sc_client_api::{backend::AuxStore, BlockOf}; use sc_consensus::{BlockCheckParams, BlockImport, BlockImportParams, ImportResult}; use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder as BlockBuilderApi; -use sp_blockchain::{well_known_cache_keys::Id as CacheKeyId, HeaderBackend}; +use sp_blockchain::well_known_cache_keys::Id as CacheKeyId; use sp_consensus::Error as ConsensusError; use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; // Frontier @@ -82,11 +81,10 @@ impl, C> Clone for FrontierBlockImp impl FrontierBlockImport where B: BlockT, - I: BlockImport> + Send + Sync, + I: BlockImport>, I::Error: Into, - C: ProvideRuntimeApi + Send + Sync + HeaderBackend + AuxStore + BlockOf, - C::Api: EthereumRuntimeRPCApi, - C::Api: BlockBuilderApi, + C: ProvideRuntimeApi, + C::Api: BlockBuilderApi + EthereumRuntimeRPCApi, { pub fn new(inner: I, client: Arc, backend: Arc>) -> Self { Self { @@ -104,9 +102,8 @@ where B: BlockT, I: BlockImport> + Send + Sync, I::Error: Into, - C: ProvideRuntimeApi + Send + Sync + HeaderBackend + AuxStore + BlockOf, - C::Api: EthereumRuntimeRPCApi, - C::Api: BlockBuilderApi, + C: ProvideRuntimeApi + Send + Sync, + C::Api: BlockBuilderApi + EthereumRuntimeRPCApi, { type Error = ConsensusError; type Transaction = sp_api::TransactionFor; diff --git a/client/db/src/lib.rs b/client/db/src/lib.rs index 64c43533a..8f7499dde 100644 --- a/client/db/src/lib.rs +++ b/client/db/src/lib.rs @@ -31,6 +31,7 @@ use parking_lot::Mutex; use scale_codec::{Decode, Encode}; // Substrate pub use sc_client_db::DatabaseSource; +use sp_blockchain::HeaderBackend; use sp_core::H256; pub use sp_database::Database; use sp_runtime::traits::Block as BlockT; @@ -71,7 +72,7 @@ pub fn frontier_database_dir(db_config_dir: &Path, db_path: &str) -> PathBuf { } impl Backend { - pub fn open>( + pub fn open>( client: Arc, database: &DatabaseSource, db_config_dir: &Path, @@ -102,7 +103,7 @@ impl Backend { ) } - pub fn new>( + pub fn new>( client: Arc, config: &DatabaseSettings, ) -> Result { diff --git a/client/db/src/parity_db_adapter.rs b/client/db/src/parity_db_adapter.rs index 26168ec34..e527c2f11 100644 --- a/client/db/src/parity_db_adapter.rs +++ b/client/db/src/parity_db_adapter.rs @@ -16,9 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use sp_database::{error::DatabaseError, Change, ColumnId, Transaction}; - -use crate::Database; +// Substrate +use sp_database::{error::DatabaseError, Change, ColumnId, Database, Transaction}; fn handle_err(result: parity_db::Result) -> T { match result { diff --git a/client/db/src/upgrade.rs b/client/db/src/upgrade.rs index cd00239f2..523918a9d 100644 --- a/client/db/src/upgrade.rs +++ b/client/db/src/upgrade.rs @@ -24,11 +24,12 @@ use std::{ }; use scale_codec::{Decode, Encode}; +// Substrate +use sc_client_db::DatabaseSource; +use sp_blockchain::HeaderBackend; use sp_core::H256; use sp_runtime::traits::Block as BlockT; -use crate::DatabaseSource; - /// Version file name. const VERSION_FILE_NAME: &str = "db_version"; @@ -90,14 +91,11 @@ impl fmt::Display for UpgradeError { } /// Upgrade database to current version. -pub(crate) fn upgrade_db( +pub(crate) fn upgrade_db>( client: Arc, db_path: &Path, source: &DatabaseSource, -) -> UpgradeResult<()> -where - C: sp_blockchain::HeaderBackend + Send + Sync, -{ +) -> UpgradeResult<()> { let db_version = current_version(db_path)?; match db_version { 0 => return Err(UpgradeError::UnsupportedVersion(db_version)), @@ -167,13 +165,10 @@ fn version_file_path(path: &Path) -> PathBuf { /// Migration from version1 to version2: /// - The format of the Ethereum<>Substrate block mapping changed to support equivocation. /// - Migrating schema from One-to-one to One-to-many (EthHash: Vec) relationship. -pub(crate) fn migrate_1_to_2_rocks_db( +pub(crate) fn migrate_1_to_2_rocks_db>( client: Arc, db_path: &Path, -) -> UpgradeResult -where - C: sp_blockchain::HeaderBackend + Send + Sync, -{ +) -> UpgradeResult { log::info!("🔨 Running Frontier DB migration from version 1 to version 2. Please wait."); let mut res = UpgradeVersion1To2Summary { success: 0, @@ -251,13 +246,10 @@ where Ok(res) } -pub(crate) fn migrate_1_to_2_parity_db( +pub(crate) fn migrate_1_to_2_parity_db>( client: Arc, db_path: &Path, -) -> UpgradeResult -where - C: sp_blockchain::HeaderBackend + Send + Sync, -{ +) -> UpgradeResult { log::info!("🔨 Running Frontier DB migration from version 1 to version 2. Please wait."); let mut res = UpgradeVersion1To2Summary { success: 0, @@ -342,26 +334,22 @@ mod tests { }; use scale_codec::Encode; + use sp_blockchain::HeaderBackend; use sp_core::H256; use sp_runtime::{ generic::{Block, BlockId, Header}, - traits::BlakeTwo256, + traits::{BlakeTwo256, Block as BlockT}, }; use tempfile::tempdir; type OpaqueBlock = Block, substrate_test_runtime_client::runtime::Extrinsic>; - pub fn open_frontier_backend( + pub fn open_frontier_backend>( client: Arc, setting: &crate::DatabaseSettings, - ) -> Result>, String> - where - C: sp_blockchain::HeaderBackend, - { - Ok(Arc::new(crate::Backend::::new( - client, setting, - )?)) + ) -> Result>, String> { + Ok(Arc::new(crate::Backend::::new(client, setting)?)) } #[test] @@ -406,7 +394,7 @@ mod tests { let mut transaction_hashes = vec![]; { // Create a temporary frontier secondary DB. - let backend = open_frontier_backend(client.clone(), &setting) + let backend = open_frontier_backend::(client.clone(), &setting) .expect("a temporary db was created"); // Fill the tmp db with some data @@ -487,8 +475,8 @@ mod tests { let _ = super::upgrade_db::(client.clone(), &path, &setting.source); // Check data after migration - let backend = - open_frontier_backend(client, &setting).expect("a temporary db was created"); + let backend = open_frontier_backend::(client, &setting) + .expect("a temporary db was created"); for (i, original_ethereum_hash) in ethereum_hashes.iter().enumerate() { let canon_substrate_block_hash = substrate_hashes.get(i).expect("Block hash"); let mapped_block = backend diff --git a/client/db/src/utils.rs b/client/db/src/utils.rs index bf11e7d9f..777ac3309 100644 --- a/client/db/src/utils.rs +++ b/client/db/src/utils.rs @@ -18,17 +18,15 @@ use std::{path::Path, sync::Arc}; +use sp_blockchain::HeaderBackend; use sp_runtime::traits::Block as BlockT; use crate::{Database, DatabaseSettings, DatabaseSource, DbHash}; -pub fn open_database( +pub fn open_database>( client: Arc, config: &DatabaseSettings, -) -> Result>, String> -where - C: sp_blockchain::HeaderBackend + Send + Sync, -{ +) -> Result>, String> { let db: Arc> = match &config.source { DatabaseSource::ParityDb { path } => { open_parity_db::(client, path, &config.source)? @@ -53,15 +51,12 @@ where } #[cfg(feature = "kvdb-rocksdb")] -fn open_kvdb_rocksdb( +fn open_kvdb_rocksdb>( client: Arc, path: &Path, create: bool, _source: &DatabaseSource, -) -> Result>, String> -where - C: sp_blockchain::HeaderBackend + Send + Sync, -{ +) -> Result>, String> { // first upgrade database to required version #[cfg(not(test))] match crate::upgrade::upgrade_db::(client, path, _source) { @@ -80,27 +75,21 @@ where } #[cfg(not(feature = "kvdb-rocksdb"))] -fn open_kvdb_rocksdb( +fn open_kvdb_rocksdb>( _client: Arc, _path: &Path, _create: bool, _source: &DatabaseSource, -) -> Result>, String> -where - C: sp_blockchain::HeaderBackend + Send + Sync, -{ +) -> Result>, String> { Err("Missing feature flags `kvdb-rocksdb`".to_string()) } #[cfg(feature = "parity-db")] -fn open_parity_db( +fn open_parity_db>( client: Arc, path: &Path, _source: &DatabaseSource, -) -> Result>, String> -where - C: sp_blockchain::HeaderBackend + Send + Sync, -{ +) -> Result>, String> { // first upgrade database to required version #[cfg(not(test))] match crate::upgrade::upgrade_db::(client, path, _source) { @@ -118,13 +107,10 @@ where } #[cfg(not(feature = "parity-db"))] -fn open_parity_db( +fn open_parity_db>( _client: Arc, _path: &Path, _source: &DatabaseSource, -) -> Result>, String> -where - C: sp_blockchain::HeaderBackend + Send + Sync, -{ +) -> Result>, String> { Err("Missing feature flags `parity-db`".to_string()) } diff --git a/client/mapping-sync/src/lib.rs b/client/mapping-sync/src/lib.rs index c9a0bb4d8..f84397b32 100644 --- a/client/mapping-sync/src/lib.rs +++ b/client/mapping-sync/src/lib.rs @@ -23,9 +23,9 @@ mod worker; pub use worker::{MappingSyncWorker, SyncStrategy}; // Substrate -use sc_client_api::BlockOf; +use sc_client_api::backend::Backend; use sp_api::{ApiExt, ProvideRuntimeApi}; -use sp_blockchain::HeaderBackend; +use sp_blockchain::{Backend as _, HeaderBackend}; use sp_runtime::{ generic::BlockId, traits::{Block as BlockT, Header as HeaderT, Zero}, @@ -66,7 +66,7 @@ pub fn sync_genesis_block( header: &Block::Header, ) -> Result<(), String> where - C: ProvideRuntimeApi + Send + Sync + HeaderBackend + BlockOf, + C: ProvideRuntimeApi, C::Api: EthereumRuntimeRPCApi, { let id = BlockId::Hash(header.hash()); @@ -106,22 +106,26 @@ where Ok(()) } -pub fn sync_one_block( +pub fn sync_one_block( client: &C, - substrate_backend: &B, + substrate_backend: &BE, frontier_backend: &fc_db::Backend, sync_from: ::Number, strategy: SyncStrategy, ) -> Result where - C: ProvideRuntimeApi + Send + Sync + HeaderBackend + BlockOf, + C: ProvideRuntimeApi, C::Api: EthereumRuntimeRPCApi, - B: sp_blockchain::HeaderBackend + sp_blockchain::Backend, + C: HeaderBackend, + BE: Backend, { let mut current_syncing_tips = frontier_backend.meta().current_syncing_tips()?; if current_syncing_tips.is_empty() { - let mut leaves = substrate_backend.leaves().map_err(|e| format!("{:?}", e))?; + let mut leaves = substrate_backend + .blockchain() + .leaves() + .map_err(|e| format!("{:?}", e))?; if leaves.is_empty() { return Ok(false); } @@ -130,9 +134,12 @@ where let mut operating_header = None; while let Some(checking_tip) = current_syncing_tips.pop() { - if let Some(checking_header) = - fetch_header(substrate_backend, frontier_backend, checking_tip, sync_from)? - { + if let Some(checking_header) = fetch_header( + substrate_backend.blockchain(), + frontier_backend, + checking_tip, + sync_from, + )? { operating_header = Some(checking_header); break; } @@ -170,18 +177,19 @@ where } } -pub fn sync_blocks( +pub fn sync_blocks( client: &C, - substrate_backend: &B, + substrate_backend: &BE, frontier_backend: &fc_db::Backend, limit: usize, sync_from: ::Number, strategy: SyncStrategy, ) -> Result where - C: ProvideRuntimeApi + Send + Sync + HeaderBackend + BlockOf, + C: ProvideRuntimeApi, C::Api: EthereumRuntimeRPCApi, - B: sp_blockchain::HeaderBackend + sp_blockchain::Backend, + C: HeaderBackend, + BE: Backend, { let mut synced_any = false; @@ -199,14 +207,14 @@ where Ok(synced_any) } -pub fn fetch_header( - substrate_backend: &B, +pub fn fetch_header( + substrate_backend: &BE, frontier_backend: &fc_db::Backend, checking_tip: Block::Hash, sync_from: ::Number, ) -> Result, String> where - B: sp_blockchain::HeaderBackend + sp_blockchain::Backend, + BE: HeaderBackend, { if frontier_backend.mapping().is_synced(&checking_tip)? { return Ok(None); diff --git a/client/mapping-sync/src/worker.rs b/client/mapping-sync/src/worker.rs index d62c2047a..6fbe25d70 100644 --- a/client/mapping-sync/src/worker.rs +++ b/client/mapping-sync/src/worker.rs @@ -25,7 +25,7 @@ use futures::{ use futures_timer::Delay; use log::debug; // Substrate -use sc_client_api::{BlockOf, ImportNotifications}; +use sc_client_api::{backend::Backend, client::ImportNotifications}; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; @@ -38,13 +38,13 @@ pub enum SyncStrategy { Parachain, } -pub struct MappingSyncWorker { +pub struct MappingSyncWorker { import_notifications: ImportNotifications, timeout: Duration, inner_delay: Option, client: Arc, - substrate_backend: Arc, + substrate_backend: Arc, frontier_backend: Arc>, have_next: bool, @@ -53,14 +53,14 @@ pub struct MappingSyncWorker { strategy: SyncStrategy, } -impl Unpin for MappingSyncWorker {} +impl Unpin for MappingSyncWorker {} -impl MappingSyncWorker { +impl MappingSyncWorker { pub fn new( import_notifications: ImportNotifications, timeout: Duration, client: Arc, - substrate_backend: Arc, + substrate_backend: Arc, frontier_backend: Arc>, retry_times: usize, sync_from: ::Number, @@ -83,11 +83,12 @@ impl MappingSyncWorker { } } -impl Stream for MappingSyncWorker +impl Stream for MappingSyncWorker where - C: ProvideRuntimeApi + Send + Sync + HeaderBackend + BlockOf, + C: ProvideRuntimeApi, C::Api: EthereumRuntimeRPCApi, - B: sc_client_api::Backend, + C: HeaderBackend, + BE: Backend, { type Item = (); @@ -123,7 +124,7 @@ where match crate::sync_blocks( self.client.as_ref(), - self.substrate_backend.blockchain(), + self.substrate_backend.as_ref(), self.frontier_backend.as_ref(), self.retry_times, self.sync_from, diff --git a/client/rpc/Cargo.toml b/client/rpc/Cargo.toml index 0870f14bc..6775cb5ea 100644 --- a/client/rpc/Cargo.toml +++ b/client/rpc/Cargo.toml @@ -42,7 +42,6 @@ sp-consensus = { workspace = true } sp-core = { workspace = true } sp-io = { workspace = true } sp-runtime = { workspace = true } -sp-storage = { workspace = true } # Frontier fc-db = { workspace = true } fc-rpc-core = { workspace = true } diff --git a/client/rpc/src/eth/block.rs b/client/rpc/src/eth/block.rs index f2324af95..96a357382 100644 --- a/client/rpc/src/eth/block.rs +++ b/client/rpc/src/eth/block.rs @@ -21,16 +21,13 @@ use std::sync::Arc; use ethereum_types::{H256, U256}; use jsonrpsee::core::RpcResult as Result; // Substrate -use sc_client_api::backend::{Backend, StateBackend, StorageProvider}; +use sc_client_api::backend::{Backend, StorageProvider}; use sc_network_common::ExHashT; use sc_transaction_pool::ChainApi; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_core::hashing::keccak_256; -use sp_runtime::{ - generic::BlockId, - traits::{BlakeTwo256, Block as BlockT}, -}; +use sp_runtime::{generic::BlockId, traits::Block as BlockT}; // Frontier use fc_rpc_core::types::*; use fp_rpc::EthereumRuntimeRPCApi; @@ -42,12 +39,11 @@ use crate::{ impl Eth where - B: BlockT + Send + Sync + 'static, - C: StorageProvider + HeaderBackend + Send + Sync + 'static, + B: BlockT, C: ProvideRuntimeApi, C::Api: EthereumRuntimeRPCApi, - BE: Backend + 'static, - BE::State: StateBackend, + C: HeaderBackend + StorageProvider + 'static, + BE: Backend, { pub async fn block_by_hash(&self, hash: H256, full: bool) -> Result> { let client = Arc::clone(&self.client); diff --git a/client/rpc/src/eth/cache/mod.rs b/client/rpc/src/eth/cache/mod.rs index de9d94b91..1dcd755e3 100644 --- a/client/rpc/src/eth/cache/mod.rs +++ b/client/rpc/src/eth/cache/mod.rs @@ -25,12 +25,12 @@ use std::{ }; use ethereum::BlockV2 as EthereumBlock; -use ethereum_types::{H256, U256}; +use ethereum_types::U256; use futures::StreamExt; use tokio::sync::{mpsc, oneshot}; // Substrate use sc_client_api::{ - backend::{Backend, StateBackend, StorageProvider}, + backend::{Backend, StorageProvider}, client::BlockchainEvents, }; use sc_service::SpawnTaskHandle; @@ -38,7 +38,7 @@ use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_runtime::{ generic::BlockId, - traits::{BlakeTwo256, Block as BlockT, Header as HeaderT, UniqueSaturatedInto}, + traits::{Block as BlockT, Header as HeaderT, UniqueSaturatedInto}, }; // Frontier use fc_rpc_core::types::*; @@ -274,12 +274,12 @@ pub struct EthTask(PhantomData<(B, C, BE)>); impl EthTask where - B: BlockT, - C: ProvideRuntimeApi + StorageProvider + BlockchainEvents, - C: HeaderBackend + Send + Sync + 'static, + B: BlockT, + C: ProvideRuntimeApi, C::Api: EthereumRuntimeRPCApi, + C: BlockchainEvents + 'static, + C: HeaderBackend + StorageProvider, BE: Backend + 'static, - BE::State: StateBackend, { pub async fn filter_pool_task( client: Arc, @@ -311,7 +311,7 @@ where } // Calculates the cache for a single block #[rustfmt::skip] - let fee_history_cache_item = |hash: H256| -> ( + let fee_history_cache_item = |hash: B::Hash| -> ( FeeHistoryCacheItem, Option ) { diff --git a/client/rpc/src/eth/client.rs b/client/rpc/src/eth/client.rs index b7d585aee..17f97bdf1 100644 --- a/client/rpc/src/eth/client.rs +++ b/client/rpc/src/eth/client.rs @@ -16,10 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use ethereum_types::{H160, H256, U256, U64}; +use ethereum_types::{H160, U256, U64}; use jsonrpsee::core::RpcResult as Result; // Substrate -use sc_client_api::backend::{Backend, StateBackend, StorageProvider}; +use sc_client_api::backend::{Backend, StorageProvider}; use sc_network_common::ExHashT; use sc_transaction_pool::ChainApi; use sp_api::ProvideRuntimeApi; @@ -27,7 +27,7 @@ use sp_blockchain::HeaderBackend; use sp_consensus::SyncOracle; use sp_runtime::{ generic::BlockId, - traits::{BlakeTwo256, Block as BlockT, UniqueSaturatedInto}, + traits::{Block as BlockT, UniqueSaturatedInto}, }; // Frontier use fc_rpc_core::types::*; @@ -37,12 +37,11 @@ use crate::{eth::Eth, internal_err}; impl Eth where - B: BlockT + Send + Sync + 'static, - C: ProvideRuntimeApi + StorageProvider, - C: HeaderBackend + Send + Sync + 'static, + B: BlockT, + C: ProvideRuntimeApi, C::Api: EthereumRuntimeRPCApi, - BE: Backend + 'static, - BE::State: StateBackend, + C: HeaderBackend + StorageProvider + 'static, + BE: Backend, { pub fn protocol_version(&self) -> Result { Ok(1) diff --git a/client/rpc/src/eth/execute.rs b/client/rpc/src/eth/execute.rs index a96a17fd7..e377d29bb 100644 --- a/client/rpc/src/eth/execute.rs +++ b/client/rpc/src/eth/execute.rs @@ -18,21 +18,17 @@ use std::sync::Arc; -use ethereum_types::{H256, U256}; +use ethereum_types::U256; use evm::{ExitError, ExitReason}; use jsonrpsee::core::RpcResult as Result; // Substrate -use sc_client_api::backend::{Backend, StateBackend, StorageProvider}; +use sc_client_api::backend::{Backend, StorageProvider}; use sc_network_common::ExHashT; use sc_transaction_pool::ChainApi; use sp_api::{ApiExt, ProvideRuntimeApi}; use sp_block_builder::BlockBuilder as BlockBuilderApi; use sp_blockchain::HeaderBackend; -use sp_runtime::{ - generic::BlockId, - traits::{BlakeTwo256, Block as BlockT}, - SaturatedConversion, -}; +use sp_runtime::{generic::BlockId, traits::Block as BlockT, SaturatedConversion}; // Frontier use fc_rpc_core::types::*; use fp_rpc::EthereumRuntimeRPCApi; @@ -65,12 +61,11 @@ impl EstimateGasAdapter for () { impl Eth where - B: BlockT + Send + Sync + 'static, - C: ProvideRuntimeApi + StorageProvider, - C: HeaderBackend + Send + Sync + 'static, + B: BlockT, + C: ProvideRuntimeApi, C::Api: BlockBuilderApi + EthereumRuntimeRPCApi, + C: HeaderBackend + StorageProvider + 'static, BE: Backend + 'static, - BE::State: StateBackend, A: ChainApi + 'static, EGA: EstimateGasAdapter, { diff --git a/client/rpc/src/eth/fee.rs b/client/rpc/src/eth/fee.rs index 2c9412a5c..94c6b1bff 100644 --- a/client/rpc/src/eth/fee.rs +++ b/client/rpc/src/eth/fee.rs @@ -16,17 +16,17 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use ethereum_types::{H256, U256}; +use ethereum_types::U256; use jsonrpsee::core::RpcResult as Result; // Substrate -use sc_client_api::backend::{Backend, StateBackend, StorageProvider}; +use sc_client_api::backend::{Backend, StorageProvider}; use sc_network_common::ExHashT; use sc_transaction_pool::ChainApi; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_runtime::{ generic::BlockId, - traits::{BlakeTwo256, Block as BlockT, UniqueSaturatedInto}, + traits::{Block as BlockT, UniqueSaturatedInto}, }; // Frontier use fc_rpc_core::types::*; @@ -36,12 +36,11 @@ use crate::{eth::Eth, frontier_backend_client, internal_err}; impl Eth where - B: BlockT + Send + Sync + 'static, - C: ProvideRuntimeApi + StorageProvider, - C: HeaderBackend + Send + Sync + 'static, + B: BlockT, + C: ProvideRuntimeApi, C::Api: EthereumRuntimeRPCApi, + C: HeaderBackend + StorageProvider + 'static, BE: Backend + 'static, - BE::State: StateBackend, { pub fn gas_price(&self) -> Result { let block = BlockId::Hash(self.client.info().best_hash); diff --git a/client/rpc/src/eth/filter.rs b/client/rpc/src/eth/filter.rs index e651a38b1..ef2380010 100644 --- a/client/rpc/src/eth/filter.rs +++ b/client/rpc/src/eth/filter.rs @@ -22,13 +22,13 @@ use ethereum::BlockV2 as EthereumBlock; use ethereum_types::{H256, U256}; use jsonrpsee::core::{async_trait, RpcResult as Result}; // Substrate -use sc_client_api::backend::{Backend, StateBackend, StorageProvider}; +use sc_client_api::backend::{Backend, StorageProvider}; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_core::hashing::keccak_256; use sp_runtime::{ generic::BlockId, - traits::{BlakeTwo256, Block as BlockT, NumberFor, One, Saturating, UniqueSaturatedInto}, + traits::{Block as BlockT, NumberFor, One, Saturating, UniqueSaturatedInto}, }; // Frontier use fc_rpc_core::{types::*, EthFilterApiServer}; @@ -69,8 +69,8 @@ impl EthFilter { impl EthFilter where - B: BlockT + Send + Sync + 'static, - C: HeaderBackend + Send + Sync + 'static, + B: BlockT, + C: HeaderBackend, { fn create_filter(&self, filter_type: FilterType) -> Result { let block_number = @@ -111,12 +111,11 @@ where #[async_trait] impl EthFilterApiServer for EthFilter where - B: BlockT + Send + Sync + 'static, - C: ProvideRuntimeApi + StorageProvider, - C: HeaderBackend + Send + Sync + 'static, + B: BlockT, + C: ProvideRuntimeApi, C::Api: EthereumRuntimeRPCApi, + C: HeaderBackend + StorageProvider + 'static, BE: Backend + 'static, - BE::State: StateBackend, { fn new_filter(&self, filter: Filter) -> Result { self.create_filter(FilterType::Log(filter)) @@ -426,12 +425,11 @@ async fn filter_range_logs( to: NumberFor, ) -> Result<()> where - B: BlockT + Send + Sync + 'static, - C: ProvideRuntimeApi + StorageProvider, - C: HeaderBackend + Send + Sync + 'static, + B: BlockT, + C: ProvideRuntimeApi, C::Api: EthereumRuntimeRPCApi, + C: HeaderBackend + StorageProvider + 'static, BE: Backend + 'static, - BE::State: StateBackend, { // Max request duration of 10 seconds. let max_duration = time::Duration::from_secs(10); diff --git a/client/rpc/src/eth/mod.rs b/client/rpc/src/eth/mod.rs index f481b06be..864d79dab 100644 --- a/client/rpc/src/eth/mod.rs +++ b/client/rpc/src/eth/mod.rs @@ -34,7 +34,7 @@ use ethereum::{BlockV2 as EthereumBlock, TransactionV2 as EthereumTransaction}; use ethereum_types::{H160, H256, H512, H64, U256, U64}; use jsonrpsee::core::{async_trait, RpcResult as Result}; // Substrate -use sc_client_api::backend::{Backend, StateBackend, StorageProvider}; +use sc_client_api::backend::{Backend, StorageProvider}; use sc_network::NetworkService; use sc_network_common::ExHashT; use sc_transaction_pool::{ChainApi, Pool}; @@ -45,12 +45,14 @@ use sp_blockchain::HeaderBackend; use sp_core::hashing::keccak_256; use sp_runtime::{ generic::BlockId, - traits::{BlakeTwo256, Block as BlockT, UniqueSaturatedInto}, + traits::{Block as BlockT, UniqueSaturatedInto}, }; // Frontier use fc_rpc_core::{types::*, EthApiServer}; use fc_storage::OverrideHandle; -use fp_rpc::{ConvertTransactionRuntimeApi, EthereumRuntimeRPCApi, TransactionStatus}; +use fp_rpc::{ + ConvertTransaction, ConvertTransactionRuntimeApi, EthereumRuntimeRPCApi, TransactionStatus, +}; use crate::{internal_err, public_key, signer::EthSigner}; @@ -158,14 +160,13 @@ impl Eth EthApiServer for Eth where - B: BlockT + Send + Sync + 'static, - C: ProvideRuntimeApi + StorageProvider, - C: HeaderBackend + Send + Sync + 'static, + B: BlockT, + C: ProvideRuntimeApi, C::Api: BlockBuilderApi + ConvertTransactionRuntimeApi + EthereumRuntimeRPCApi, - P: TransactionPool + Send + Sync + 'static, - CT: fp_rpc::ConvertTransaction<::Extrinsic> + Send + Sync + 'static, + C: HeaderBackend + StorageProvider + 'static, BE: Backend + 'static, - BE::State: StateBackend, + P: TransactionPool + 'static, + CT: ConvertTransaction<::Extrinsic> + Send + Sync + 'static, A: ChainApi + 'static, EGA: EstimateGasAdapter + Send + Sync + 'static, { @@ -507,12 +508,11 @@ fn pending_runtime_api<'a, B: BlockT, C, BE, A: ChainApi>( graph: &'a Pool, ) -> Result> where - B: BlockT + Send + Sync + 'static, - C: ProvideRuntimeApi + StorageProvider, - C: HeaderBackend + Send + Sync + 'static, + B: BlockT, + C: ProvideRuntimeApi, C::Api: BlockBuilderApi + EthereumRuntimeRPCApi, - BE: Backend + 'static, - BE::State: StateBackend, + C: HeaderBackend + StorageProvider + 'static, + BE: Backend, A: ChainApi + 'static, { // In case of Pending, we need an overlayed state to query over. diff --git a/client/rpc/src/eth/state.rs b/client/rpc/src/eth/state.rs index 953c416d3..ce26afb9c 100644 --- a/client/rpc/src/eth/state.rs +++ b/client/rpc/src/eth/state.rs @@ -20,17 +20,14 @@ use ethereum_types::{H160, H256, U256}; use jsonrpsee::core::RpcResult as Result; use scale_codec::Encode; // Substrate -use sc_client_api::backend::{Backend, StateBackend, StorageProvider}; +use sc_client_api::backend::{Backend, StorageProvider}; use sc_network_common::ExHashT; use sc_transaction_pool::ChainApi; use sc_transaction_pool_api::{InPoolTransaction, TransactionPool}; use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder as BlockBuilderApi; use sp_blockchain::HeaderBackend; -use sp_runtime::{ - generic::BlockId, - traits::{BlakeTwo256, Block as BlockT}, -}; +use sp_runtime::{generic::BlockId, traits::Block as BlockT}; // Frontier use fc_rpc_core::types::*; use fp_rpc::EthereumRuntimeRPCApi; @@ -42,13 +39,12 @@ use crate::{ impl Eth where - B: BlockT + Send + Sync + 'static, - C: ProvideRuntimeApi + StorageProvider, - C: HeaderBackend + Send + Sync + 'static, + B: BlockT, + C: ProvideRuntimeApi, C::Api: BlockBuilderApi + EthereumRuntimeRPCApi, + C: HeaderBackend + StorageProvider + 'static, BE: Backend + 'static, - BE::State: StateBackend, - P: TransactionPool + Send + Sync + 'static, + P: TransactionPool + 'static, A: ChainApi + 'static, { pub fn balance(&self, address: H160, number: Option) -> Result { diff --git a/client/rpc/src/eth/submit.rs b/client/rpc/src/eth/submit.rs index dbfabd650..ee4a676f4 100644 --- a/client/rpc/src/eth/submit.rs +++ b/client/rpc/src/eth/submit.rs @@ -20,7 +20,7 @@ use ethereum_types::H256; use futures::future::TryFutureExt; use jsonrpsee::core::RpcResult as Result; // Substrate -use sc_client_api::backend::{Backend, StateBackend, StorageProvider}; +use sc_client_api::backend::{Backend, StorageProvider}; use sc_network_common::ExHashT; use sc_transaction_pool::ChainApi; use sc_transaction_pool_api::TransactionPool; @@ -28,9 +28,7 @@ use sp_api::{ApiExt, ProvideRuntimeApi}; use sp_block_builder::BlockBuilder as BlockBuilderApi; use sp_blockchain::HeaderBackend; use sp_runtime::{ - generic::BlockId, - traits::{BlakeTwo256, Block as BlockT}, - transaction_validity::TransactionSource, + generic::BlockId, traits::Block as BlockT, transaction_validity::TransactionSource, }; // Frontier use fc_rpc_core::types::*; @@ -43,14 +41,13 @@ use crate::{ impl Eth where - B: BlockT + Send + Sync + 'static, - C: ProvideRuntimeApi + StorageProvider, - C: HeaderBackend + Send + Sync + 'static, + B: BlockT, + C: ProvideRuntimeApi, C::Api: BlockBuilderApi + ConvertTransactionRuntimeApi + EthereumRuntimeRPCApi, + C: HeaderBackend + StorageProvider + 'static, BE: Backend + 'static, - BE::State: StateBackend, - P: TransactionPool + Send + Sync + 'static, - CT: ConvertTransaction<::Extrinsic> + Send + Sync + 'static, + P: TransactionPool + 'static, + CT: ConvertTransaction<::Extrinsic> + 'static, A: ChainApi + 'static, { pub async fn send_transaction(&self, request: TransactionRequest) -> Result { diff --git a/client/rpc/src/eth/transaction.rs b/client/rpc/src/eth/transaction.rs index 861382a11..9405416f2 100644 --- a/client/rpc/src/eth/transaction.rs +++ b/client/rpc/src/eth/transaction.rs @@ -22,17 +22,14 @@ use ethereum::TransactionV2 as EthereumTransaction; use ethereum_types::{H256, U256, U64}; use jsonrpsee::core::RpcResult as Result; // Substrate -use sc_client_api::backend::{Backend, StateBackend, StorageProvider}; +use sc_client_api::backend::{Backend, StorageProvider}; use sc_network_common::ExHashT; use sc_transaction_pool::ChainApi; use sc_transaction_pool_api::InPoolTransaction; use sp_api::{ApiExt, ProvideRuntimeApi}; use sp_blockchain::HeaderBackend; use sp_core::hashing::keccak_256; -use sp_runtime::{ - generic::BlockId, - traits::{BlakeTwo256, Block as BlockT}, -}; +use sp_runtime::{generic::BlockId, traits::Block as BlockT}; // Frontier use fc_rpc_core::types::*; use fp_rpc::EthereumRuntimeRPCApi; @@ -44,11 +41,11 @@ use crate::{ impl Eth where - B: BlockT + Send + Sync + 'static, - C: ProvideRuntimeApi + StorageProvider + HeaderBackend + Send + Sync + 'static, + B: BlockT, + C: ProvideRuntimeApi, C::Api: EthereumRuntimeRPCApi, + C: HeaderBackend + StorageProvider + 'static, BE: Backend + 'static, - BE::State: StateBackend, A: ChainApi + 'static, { pub async fn transaction_by_hash(&self, hash: H256) -> Result> { diff --git a/client/rpc/src/eth_pubsub.rs b/client/rpc/src/eth_pubsub.rs index 235015d8b..8e7bd9e39 100644 --- a/client/rpc/src/eth_pubsub.rs +++ b/client/rpc/src/eth_pubsub.rs @@ -24,7 +24,7 @@ use futures::{FutureExt as _, StreamExt as _}; use jsonrpsee::{types::SubscriptionResult, SubscriptionSink}; // Substrate use sc_client_api::{ - backend::{Backend, StateBackend, StorageProvider}, + backend::{Backend, StorageProvider}, client::BlockchainEvents, }; use sc_network::{NetworkService, NetworkStatusProvider}; @@ -35,7 +35,7 @@ use sp_api::{ApiExt, BlockId, ProvideRuntimeApi}; use sp_blockchain::HeaderBackend; use sp_consensus::SyncOracle; use sp_core::hashing::keccak_256; -use sp_runtime::traits::{BlakeTwo256, Block as BlockT, UniqueSaturatedInto}; +use sp_runtime::traits::{Block as BlockT, UniqueSaturatedInto}; // Frontier use fc_rpc_core::{ types::{ @@ -69,7 +69,7 @@ pub struct EthPubSub { impl EthPubSub where - C: HeaderBackend + Send + Sync + 'static, + C: HeaderBackend, { pub fn new( pool: Arc

, @@ -195,13 +195,13 @@ impl EthSubscriptionResult { impl EthPubSubApiServer for EthPubSub where - B: BlockT + Send + Sync + 'static, - P: TransactionPool + Send + Sync + 'static, - C: ProvideRuntimeApi + StorageProvider + BlockchainEvents, - C: HeaderBackend + Send + Sync + 'static, + B: BlockT, + P: TransactionPool + 'static, + C: ProvideRuntimeApi, C::Api: EthereumRuntimeRPCApi, + C: BlockchainEvents + 'static, + C: HeaderBackend + StorageProvider, BE: Backend + 'static, - BE::State: StateBackend, { fn subscribe( &self, diff --git a/client/rpc/src/lib.rs b/client/rpc/src/lib.rs index 5388bdb89..58c50b75d 100644 --- a/client/rpc/src/lib.rs +++ b/client/rpc/src/lib.rs @@ -68,8 +68,8 @@ pub mod frontier_backend_client { number: Option, ) -> RpcResult>> where - B: BlockT + Send + Sync + 'static, - C: HeaderBackend + Send + Sync + 'static, + B: BlockT, + C: HeaderBackend + 'static, { Ok(match number.unwrap_or(BlockNumber::Latest) { BlockNumber::Hash { hash, .. } => { @@ -94,8 +94,8 @@ pub mod frontier_backend_client { hash: H256, ) -> RpcResult> where - B: BlockT + Send + Sync + 'static, - C: HeaderBackend + Send + Sync + 'static, + B: BlockT, + C: HeaderBackend + 'static, { let substrate_hashes = backend .mapping() @@ -116,8 +116,8 @@ pub mod frontier_backend_client { backend: &fc_db::Backend, ) -> RpcResult>> where - B: BlockT + Send + Sync + 'static, - C: HeaderBackend + Send + Sync + 'static, + B: BlockT, + C: HeaderBackend + 'static, { let cache = backend .meta() @@ -131,8 +131,8 @@ pub mod frontier_backend_client { new_cache: Vec<(EthereumStorageSchema, H256)>, ) -> RpcResult<()> where - B: BlockT + Send + Sync + 'static, - C: HeaderBackend + Send + Sync + 'static, + B: BlockT, + C: HeaderBackend + 'static, { backend .meta() @@ -141,10 +141,10 @@ pub mod frontier_backend_client { Ok(()) } - pub fn is_canon(client: &C, target_hash: H256) -> bool + pub fn is_canon(client: &C, target_hash: B::Hash) -> bool where - B: BlockT + Send + Sync + 'static, - C: HeaderBackend + Send + Sync + 'static, + B: BlockT, + C: HeaderBackend + 'static, { if let Ok(Some(number)) = client.number(target_hash) { if let Ok(Some(hash)) = client.hash(number) { @@ -161,8 +161,8 @@ pub mod frontier_backend_client { only_canonical: bool, ) -> RpcResult> where - B: BlockT + Send + Sync + 'static, - C: HeaderBackend + Send + Sync + 'static, + B: BlockT, + C: HeaderBackend + 'static, { let transaction_metadata = backend .mapping() @@ -245,10 +245,11 @@ mod tests { use futures::executor; use sc_block_builder::BlockBuilderProvider; + use sp_blockchain::HeaderBackend; use sp_consensus::BlockOrigin; use sp_runtime::{ generic::{Block, BlockId, Header}, - traits::BlakeTwo256, + traits::{BlakeTwo256, Block as BlockT}, }; use substrate_test_runtime_client::{ prelude::*, DefaultTestClientBuilderExt, TestClientBuilder, @@ -258,14 +259,11 @@ mod tests { type OpaqueBlock = Block, substrate_test_runtime_client::runtime::Extrinsic>; - fn open_frontier_backend( + fn open_frontier_backend>( client: Arc, path: PathBuf, - ) -> Result>, String> - where - C: sp_blockchain::HeaderBackend, - { - Ok(Arc::new(fc_db::Backend::::new( + ) -> Result>, String> { + Ok(Arc::new(fc_db::Backend::::new( client, &fc_db::DatabaseSettings { source: sc_client_db::DatabaseSource::RocksDb { @@ -287,7 +285,8 @@ mod tests { let mut client = Arc::new(client); // Create a temporary frontier secondary DB. - let frontier_backend = open_frontier_backend(client.clone(), tmp.into_path()).unwrap(); + let backend = open_frontier_backend::(client.clone(), tmp.into_path()) + .expect("a temporary db was created"); // A random ethereum block hash to use let ethereum_block_hash = sp_core::H256::random(); @@ -314,13 +313,13 @@ mod tests { ethereum_block_hash, ethereum_transaction_hashes: vec![], }; - let _ = frontier_backend.mapping().write_hashes(commitment); + let _ = backend.mapping().write_hashes(commitment); // Expect B1 to be canon assert_eq!( super::frontier_backend_client::load_hash( client.as_ref(), - frontier_backend.as_ref(), + backend.as_ref(), ethereum_block_hash ) .unwrap() @@ -343,13 +342,13 @@ mod tests { ethereum_block_hash, ethereum_transaction_hashes: vec![], }; - let _ = frontier_backend.mapping().write_hashes(commitment); + let _ = backend.mapping().write_hashes(commitment); // Still expect B1 to be canon assert_eq!( super::frontier_backend_client::load_hash( client.as_ref(), - frontier_backend.as_ref(), + backend.as_ref(), ethereum_block_hash ) .unwrap() @@ -369,7 +368,7 @@ mod tests { assert_eq!( super::frontier_backend_client::load_hash( client.as_ref(), - frontier_backend.as_ref(), + backend.as_ref(), ethereum_block_hash ) .unwrap() diff --git a/client/rpc/src/net.rs b/client/rpc/src/net.rs index 6066a11f2..4b12efc01 100644 --- a/client/rpc/src/net.rs +++ b/client/rpc/src/net.rs @@ -18,7 +18,6 @@ use std::sync::Arc; -use ethereum_types::H256; use jsonrpsee::core::RpcResult as Result; // Substrate use sc_network::NetworkService; @@ -55,9 +54,10 @@ impl Net { impl NetApiServer for Net where - B: BlockT + Send + Sync + 'static, - C: HeaderBackend + ProvideRuntimeApi + Send + Sync + 'static, + B: BlockT, + C: ProvideRuntimeApi, C::Api: EthereumRuntimeRPCApi, + C: HeaderBackend + 'static, { fn version(&self) -> Result { let hash = self.client.info().best_hash; diff --git a/client/rpc/src/web3.rs b/client/rpc/src/web3.rs index 417db683b..4f97b7831 100644 --- a/client/rpc/src/web3.rs +++ b/client/rpc/src/web3.rs @@ -48,9 +48,10 @@ impl Web3 { impl Web3ApiServer for Web3 where - B: BlockT + Send + Sync + 'static, - C: HeaderBackend + ProvideRuntimeApi + Send + Sync + 'static, + B: BlockT, + C: ProvideRuntimeApi, C::Api: EthereumRuntimeRPCApi, + C: HeaderBackend + 'static, { fn client_version(&self) -> Result { let hash = self.client.info().best_hash; diff --git a/client/storage/src/lib.rs b/client/storage/src/lib.rs index 88ef59f8e..b9496a6e6 100644 --- a/client/storage/src/lib.rs +++ b/client/storage/src/lib.rs @@ -29,13 +29,14 @@ use sp_blockchain::HeaderBackend; use sp_runtime::traits::Block as BlockT; use sp_storage::StorageKey; // Frontier +use fp_rpc::EthereumRuntimeRPCApi; use fp_storage::{EthereumStorageSchema, PALLET_ETHEREUM_SCHEMA}; pub fn overrides_handle(client: Arc) -> Arc> where B: BlockT, C: ProvideRuntimeApi, - C::Api: fp_rpc::EthereumRuntimeRPCApi, + C::Api: EthereumRuntimeRPCApi, C: HeaderBackend + StorageProvider + 'static, BE: Backend + 'static, { @@ -62,7 +63,7 @@ where pub fn onchain_storage_schema(client: &C, hash: B::Hash) -> EthereumStorageSchema where B: BlockT, - C: StorageProvider + HeaderBackend, + C: HeaderBackend + StorageProvider, BE: Backend, { match client.storage(hash, &StorageKey(PALLET_ETHEREUM_SCHEMA.to_vec())) { diff --git a/client/storage/src/overrides/schema_v1_override.rs b/client/storage/src/overrides/schema_v1_override.rs index 477699cc7..088e7fd0d 100644 --- a/client/storage/src/overrides/schema_v1_override.rs +++ b/client/storage/src/overrides/schema_v1_override.rs @@ -49,7 +49,7 @@ impl SchemaV1Override { impl SchemaV1Override where B: BlockT, - C: StorageProvider + HeaderBackend + Send + Sync + 'static, + C: HeaderBackend + StorageProvider + 'static, BE: Backend + 'static, { fn query_storage(&self, block_hash: B::Hash, key: &StorageKey) -> Option { @@ -65,7 +65,7 @@ where impl StorageOverride for SchemaV1Override where B: BlockT, - C: StorageProvider + HeaderBackend + Send + Sync + 'static, + C: HeaderBackend + StorageProvider + 'static, BE: Backend + 'static, { /// For a given account address, returns pallet_evm::AccountCodes. diff --git a/client/storage/src/overrides/schema_v2_override.rs b/client/storage/src/overrides/schema_v2_override.rs index fef92aa9a..d21cf1e40 100644 --- a/client/storage/src/overrides/schema_v2_override.rs +++ b/client/storage/src/overrides/schema_v2_override.rs @@ -49,7 +49,7 @@ impl SchemaV2Override { impl SchemaV2Override where B: BlockT, - C: StorageProvider + HeaderBackend + Send + Sync + 'static, + C: HeaderBackend + StorageProvider + 'static, BE: Backend + 'static, { fn query_storage(&self, block_hash: B::Hash, key: &StorageKey) -> Option { @@ -65,7 +65,7 @@ where impl StorageOverride for SchemaV2Override where B: BlockT, - C: StorageProvider + HeaderBackend + Send + Sync + 'static, + C: HeaderBackend + StorageProvider + 'static, BE: Backend + 'static, { /// For a given account address, returns pallet_evm::AccountCodes. diff --git a/client/storage/src/overrides/schema_v3_override.rs b/client/storage/src/overrides/schema_v3_override.rs index a833d0aa5..6dd3494bb 100644 --- a/client/storage/src/overrides/schema_v3_override.rs +++ b/client/storage/src/overrides/schema_v3_override.rs @@ -49,7 +49,7 @@ impl SchemaV3Override { impl SchemaV3Override where B: BlockT, - C: StorageProvider + HeaderBackend + Send + Sync + 'static, + C: HeaderBackend + StorageProvider + 'static, BE: Backend + 'static, { fn query_storage(&self, block_hash: B::Hash, key: &StorageKey) -> Option { @@ -65,7 +65,7 @@ where impl StorageOverride for SchemaV3Override where B: BlockT, - C: StorageProvider + HeaderBackend + Send + Sync + 'static, + C: HeaderBackend + StorageProvider + 'static, BE: Backend + 'static, { /// For a given account address, returns pallet_evm::AccountCodes. diff --git a/template/node/src/rpc/eth.rs b/template/node/src/rpc/eth.rs index 8cdd13b96..5e6158554 100644 --- a/template/node/src/rpc/eth.rs +++ b/template/node/src/rpc/eth.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use jsonrpsee::RpcModule; // Substrate use sc_client_api::{ - backend::{AuxStore, Backend, StateBackend, StorageProvider}, + backend::{Backend, StorageProvider}, client::BlockchainEvents, }; use sc_network::NetworkService; @@ -11,14 +11,15 @@ use sc_rpc::SubscriptionTaskExecutor; use sc_transaction_pool::{ChainApi, Pool}; use sc_transaction_pool_api::TransactionPool; use sp_api::ProvideRuntimeApi; +use sp_block_builder::BlockBuilder as BlockBuilderApi; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; -use sp_core::H256; -use sp_runtime::traits::{BlakeTwo256, Block as BlockT, Header as HeaderT}; +use sp_runtime::traits::Block as BlockT; // Frontier use fc_db::Backend as FrontierBackend; pub use fc_rpc::{EthBlockDataCacheTask, OverrideHandle, StorageOverride}; pub use fc_rpc_core::types::{FeeHistoryCache, FeeHistoryCacheLimit, FilterPool}; pub use fc_storage::overrides_handle; +use fp_rpc::{ConvertTransaction, ConvertTransactionRuntimeApi, EthereumRuntimeRPCApi}; /// Extra dependencies for Ethereum compatibility. pub struct EthDeps { @@ -84,19 +85,15 @@ pub fn create_eth( subscription_task_executor: SubscriptionTaskExecutor, ) -> Result, Box> where - C: ProvideRuntimeApi + StorageProvider + AuxStore, - C: BlockchainEvents, - C: HeaderBackend + HeaderMetadata + 'static, - C::Api: sp_block_builder::BlockBuilder, - C::Api: fp_rpc::EthereumRuntimeRPCApi, - C::Api: fp_rpc::ConvertTransactionRuntimeApi, + B: BlockT, + C: ProvideRuntimeApi, + C::Api: BlockBuilderApi + EthereumRuntimeRPCApi + ConvertTransactionRuntimeApi, + C: BlockchainEvents + 'static, + C: HeaderBackend + HeaderMetadata + StorageProvider, BE: Backend + 'static, - BE::State: StateBackend, P: TransactionPool + 'static, A: ChainApi + 'static, - CT: fp_rpc::ConvertTransaction<::Extrinsic> + Send + Sync + 'static, - B: BlockT, - B::Header: HeaderT, + CT: ConvertTransaction<::Extrinsic> + Send + Sync + 'static, { use fc_rpc::{ Eth, EthApiServer, EthDevSigner, EthFilter, EthFilterApiServer, EthPubSub, diff --git a/template/node/src/rpc/mod.rs b/template/node/src/rpc/mod.rs index e5e016505..c8ece5713 100644 --- a/template/node/src/rpc/mod.rs +++ b/template/node/src/rpc/mod.rs @@ -6,7 +6,7 @@ use futures::channel::mpsc; use jsonrpsee::RpcModule; // Substrate use sc_client_api::{ - backend::{AuxStore, Backend, StateBackend, StorageProvider}, + backend::{Backend, StorageProvider}, client::BlockchainEvents, }; use sc_consensus_manual_seal::rpc::EngineCommand; @@ -15,9 +15,8 @@ use sc_rpc_api::DenyUnsafe; use sc_service::TransactionPool; use sc_transaction_pool::ChainApi; use sp_api::ProvideRuntimeApi; -use sp_block_builder::BlockBuilder; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; -use sp_runtime::traits::{BlakeTwo256, Block as BlockT}; +use sp_runtime::traits::Block as BlockT; // Runtime use frontier_template_runtime::{opaque::Block, AccountId, Balance, Hash, Index}; @@ -44,17 +43,17 @@ pub fn create_full( subscription_task_executor: SubscriptionTaskExecutor, ) -> Result, Box> where - BE: Backend + 'static, - BE::State: StateBackend, - C: ProvideRuntimeApi + StorageProvider + AuxStore, - C: BlockchainEvents, - C: HeaderBackend + HeaderMetadata, - C: Send + Sync + 'static, + C: ProvideRuntimeApi, C::Api: substrate_frame_rpc_system::AccountNonceApi, - C::Api: BlockBuilder, + C::Api: sp_block_builder::BlockBuilder, C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, C::Api: fp_rpc::ConvertTransactionRuntimeApi, C::Api: fp_rpc::EthereumRuntimeRPCApi, + C: BlockchainEvents + 'static, + C: HeaderBackend + + HeaderMetadata + + StorageProvider, + BE: Backend + 'static, P: TransactionPool + 'static, A: ChainApi + 'static, CT: fp_rpc::ConvertTransaction<::Extrinsic> + Send + Sync + 'static,