From b984ff19acd20a3434f2b2ff481266413c9b8f4f Mon Sep 17 00:00:00 2001 From: Qinxuan Chen Date: Tue, 28 Feb 2023 18:34:37 +0800 Subject: [PATCH] feat: add fc-storage (#1005) * feat: add fc-storage move storage overrides of `fc-rpc` into a new crate `fc-storage` * move onchain_storage_schema function into fc-storage * remove useless trait bound * move overrides_handle function into fc-storage * ignore some explicit generic --- Cargo.lock | 20 ++++- Cargo.toml | 2 + client/rpc/Cargo.toml | 1 + client/rpc/src/eth/block.rs | 20 +---- client/rpc/src/eth/cache/mod.rs | 10 +-- client/rpc/src/eth/client.rs | 5 +- client/rpc/src/eth/execute.rs | 6 +- client/rpc/src/eth/fee.rs | 6 +- client/rpc/src/eth/filter.rs | 14 +--- client/rpc/src/eth/mod.rs | 3 +- client/rpc/src/eth/state.rs | 10 +-- client/rpc/src/eth/transaction.rs | 20 +---- client/rpc/src/eth_pubsub.rs | 21 +++--- client/rpc/src/lib.rs | 34 ++------- client/storage/CHANGELOG.md | 1 + client/storage/Cargo.toml | 27 +++++++ client/storage/src/lib.rs | 74 +++++++++++++++++++ client/{rpc => storage}/src/overrides/mod.rs | 17 +++-- .../src/overrides/schema_v1_override.rs | 13 +--- .../src/overrides/schema_v2_override.rs | 13 +--- .../src/overrides/schema_v3_override.rs | 13 +--- template/node/Cargo.toml | 2 +- template/node/src/rpc/eth.rs | 41 +--------- 23 files changed, 188 insertions(+), 185 deletions(-) create mode 100644 client/storage/CHANGELOG.md create mode 100644 client/storage/Cargo.toml create mode 100644 client/storage/src/lib.rs rename client/{rpc => storage}/src/overrides/mod.rs (94%) rename client/{rpc => storage}/src/overrides/schema_v1_override.rs (92%) rename client/{rpc => storage}/src/overrides/schema_v2_override.rs (93%) rename client/{rpc => storage}/src/overrides/schema_v3_override.rs (92%) diff --git a/Cargo.lock b/Cargo.lock index cf14f081c..9ddd29b03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1926,6 +1926,7 @@ dependencies = [ "evm", "fc-db", "fc-rpc-core", + "fc-storage", "fp-ethereum", "fp-rpc", "fp-storage", @@ -1974,6 +1975,23 @@ dependencies = [ "serde_json", ] +[[package]] +name = "fc-storage" +version = "1.0.0-dev" +dependencies = [ + "ethereum", + "ethereum-types", + "fp-rpc", + "fp-storage", + "parity-scale-codec", + "sc-client-api", + "sp-api", + "sp-blockchain", + "sp-io", + "sp-runtime", + "sp-storage", +] + [[package]] name = "fdlimit" version = "0.2.1" @@ -2398,10 +2416,10 @@ dependencies = [ "fc-mapping-sync", "fc-rpc", "fc-rpc-core", + "fc-storage", "fp-dynamic-fee", "fp-evm", "fp-rpc", - "fp-storage", "frame-benchmarking", "frame-benchmarking-cli", "frame-system", diff --git a/Cargo.toml b/Cargo.toml index e22ed2bf3..93769f35d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ members = [ "client/rpc-core", "client/rpc", "client/db", + "client/storage", "client/mapping-sync", "primitives/consensus", "primitives/dynamic-fee", @@ -121,6 +122,7 @@ fc-db = { version = "2.0.0-dev", path = "client/db" } fc-mapping-sync = { version = "2.0.0-dev", path = "client/mapping-sync" } fc-rpc = { version = "2.0.0-dev", path = "client/rpc" } fc-rpc-core = { version = "1.1.0-dev", path = "client/rpc-core" } +fc-storage = { version = "1.0.0-dev", path = "client/storage" } # Frontier Primitive fp-consensus = { version = "2.0.0-dev", path = "primitives/consensus", default-features = false } fp-dynamic-fee = { version = "1.0.0", path = "primitives/dynamic-fee", default-features = false } diff --git a/client/rpc/Cargo.toml b/client/rpc/Cargo.toml index f45fedeb8..0870f14bc 100644 --- a/client/rpc/Cargo.toml +++ b/client/rpc/Cargo.toml @@ -46,6 +46,7 @@ sp-storage = { workspace = true } # Frontier fc-db = { workspace = true } fc-rpc-core = { workspace = true } +fc-storage = { workspace = true } fp-ethereum = { workspace = true, features = ["std"] } fp-rpc = { workspace = true, features = ["std"] } fp-storage = { workspace = true, features = ["std"] } diff --git a/client/rpc/src/eth/block.rs b/client/rpc/src/eth/block.rs index 556286b6a..f2324af95 100644 --- a/client/rpc/src/eth/block.rs +++ b/client/rpc/src/eth/block.rs @@ -65,10 +65,7 @@ where _ => return Ok(None), }; - let schema = frontier_backend_client::onchain_storage_schema::( - client.as_ref(), - substrate_hash, - ); + let schema = fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash); let block = block_data_cache.current_block(schema, substrate_hash).await; let statuses = block_data_cache @@ -113,10 +110,7 @@ where .expect_block_hash_from_id(&id) .map_err(|_| internal_err(format!("Expect block number from id: {}", id)))?; - let schema = frontier_backend_client::onchain_storage_schema::( - client.as_ref(), - substrate_hash, - ); + let schema = fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash); let block = block_data_cache.current_block(schema, substrate_hash).await; let statuses = block_data_cache @@ -152,10 +146,7 @@ where Some(hash) => hash, _ => return Ok(None), }; - let schema = frontier_backend_client::onchain_storage_schema::( - self.client.as_ref(), - substrate_hash, - ); + let schema = fc_storage::onchain_storage_schema(self.client.as_ref(), substrate_hash); let block = self .overrides .schemas @@ -189,10 +180,7 @@ where .client .expect_block_hash_from_id(&id) .map_err(|_| internal_err(format!("Expect block number from id: {}", id)))?; - let schema = frontier_backend_client::onchain_storage_schema::( - self.client.as_ref(), - substrate_hash, - ); + let schema = fc_storage::onchain_storage_schema(self.client.as_ref(), substrate_hash); let block = self .overrides .schemas diff --git a/client/rpc/src/eth/cache/mod.rs b/client/rpc/src/eth/cache/mod.rs index 839131784..de9d94b91 100644 --- a/client/rpc/src/eth/cache/mod.rs +++ b/client/rpc/src/eth/cache/mod.rs @@ -42,14 +42,11 @@ use sp_runtime::{ }; // Frontier use fc_rpc_core::types::*; +use fc_storage::{OverrideHandle, StorageOverride}; use fp_rpc::{EthereumRuntimeRPCApi, TransactionStatus}; use fp_storage::EthereumStorageSchema; use self::lru_cache::LRUCacheByteLimited; -use crate::{ - frontier_backend_client, - overrides::{OverrideHandle, StorageOverride}, -}; type WaitList = HashMap>>>; @@ -198,7 +195,7 @@ impl EthBlockDataCacheTask { handler_call: F, ) where T: Clone + scale_codec::Encode, - F: FnOnce(&Box + Send + Sync>) -> EthBlockDataCacheMessage, + F: FnOnce(&Box>) -> EthBlockDataCacheMessage, F: Send + 'static, { // Data is cached, we respond immediately. @@ -318,8 +315,7 @@ where FeeHistoryCacheItem, Option ) { - let schema = - frontier_backend_client::onchain_storage_schema::(client.as_ref(), hash); + let schema = fc_storage::onchain_storage_schema(client.as_ref(), hash); let handler = overrides .schemas .get(&schema) diff --git a/client/rpc/src/eth/client.rs b/client/rpc/src/eth/client.rs index 54f8c7717..b7d585aee 100644 --- a/client/rpc/src/eth/client.rs +++ b/client/rpc/src/eth/client.rs @@ -33,7 +33,7 @@ use sp_runtime::{ use fc_rpc_core::types::*; use fp_rpc::EthereumRuntimeRPCApi; -use crate::{eth::Eth, frontier_backend_client, internal_err}; +use crate::{eth::Eth, internal_err}; impl Eth where @@ -70,8 +70,7 @@ where pub fn author(&self) -> Result { let hash = self.client.info().best_hash; - let schema = - frontier_backend_client::onchain_storage_schema::(self.client.as_ref(), hash); + let schema = fc_storage::onchain_storage_schema(self.client.as_ref(), hash); Ok(self .overrides diff --git a/client/rpc/src/eth/execute.rs b/client/rpc/src/eth/execute.rs index ae17c2887..a96a17fd7 100644 --- a/client/rpc/src/eth/execute.rs +++ b/client/rpc/src/eth/execute.rs @@ -362,12 +362,8 @@ where }; let block_gas_limit = { - let schema = frontier_backend_client::onchain_storage_schema::( - &client, - substrate_hash, - ); + let schema = fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash); let block = block_data_cache.current_block(schema, substrate_hash).await; - block .ok_or_else(|| internal_err("block unavailable, cannot query gas limit"))? .header diff --git a/client/rpc/src/eth/fee.rs b/client/rpc/src/eth/fee.rs index f734fbcb0..2c9412a5c 100644 --- a/client/rpc/src/eth/fee.rs +++ b/client/rpc/src/eth/fee.rs @@ -135,10 +135,8 @@ where self.client.expect_block_hash_from_id(&id).map_err(|_| { internal_err(format!("Expect block number from id: {}", id)) })?; - let schema = frontier_backend_client::onchain_storage_schema::( - self.client.as_ref(), - substrate_hash, - ); + let schema = + fc_storage::onchain_storage_schema(self.client.as_ref(), substrate_hash); let handler = self .overrides .schemas diff --git a/client/rpc/src/eth/filter.rs b/client/rpc/src/eth/filter.rs index 226023b5a..e651a38b1 100644 --- a/client/rpc/src/eth/filter.rs +++ b/client/rpc/src/eth/filter.rs @@ -247,10 +247,8 @@ where internal_err(format!("Expect block number from id: {}", id)) })?; - let schema = frontier_backend_client::onchain_storage_schema::( - client.as_ref(), - substrate_hash, - ); + let schema = + fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash); let block = block_data_cache.current_block(schema, substrate_hash).await; if let Some(block) = block { @@ -376,10 +374,7 @@ where Some(hash) => hash, _ => return Ok(Vec::new()), }; - let schema = frontier_backend_client::onchain_storage_schema::( - client.as_ref(), - substrate_hash, - ); + let schema = fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash); let block = block_data_cache.current_block(schema, substrate_hash).await; let statuses = block_data_cache @@ -460,8 +455,7 @@ where .expect_block_hash_from_id(&id) .map_err(|_| internal_err(format!("Expect block number from id: {}", id)))?; - let schema = - frontier_backend_client::onchain_storage_schema::(client, substrate_hash); + let schema = fc_storage::onchain_storage_schema(client, 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 04d49079c..f481b06be 100644 --- a/client/rpc/src/eth/mod.rs +++ b/client/rpc/src/eth/mod.rs @@ -49,9 +49,10 @@ use sp_runtime::{ }; // Frontier use fc_rpc_core::{types::*, EthApiServer}; +use fc_storage::OverrideHandle; use fp_rpc::{ConvertTransactionRuntimeApi, EthereumRuntimeRPCApi, TransactionStatus}; -use crate::{internal_err, overrides::OverrideHandle, public_key, signer::EthSigner}; +use crate::{internal_err, public_key, signer::EthSigner}; pub use self::{ cache::{EthBlockDataCacheTask, EthTask}, diff --git a/client/rpc/src/eth/state.rs b/client/rpc/src/eth/state.rs index e631fd0ad..953c416d3 100644 --- a/client/rpc/src/eth/state.rs +++ b/client/rpc/src/eth/state.rs @@ -96,10 +96,7 @@ where .client .expect_block_hash_from_id(&id) .map_err(|_| internal_err(format!("Expect block number from id: {}", id)))?; - let schema = frontier_backend_client::onchain_storage_schema::( - self.client.as_ref(), - substrate_hash, - ); + let schema = fc_storage::onchain_storage_schema(self.client.as_ref(), substrate_hash); Ok(self .overrides .schemas @@ -173,10 +170,7 @@ where .client .expect_block_hash_from_id(&id) .map_err(|_| internal_err(format!("Expect block number from id: {}", id)))?; - let schema = frontier_backend_client::onchain_storage_schema::( - self.client.as_ref(), - substrate_hash, - ); + let schema = fc_storage::onchain_storage_schema(self.client.as_ref(), substrate_hash); Ok(self .overrides diff --git a/client/rpc/src/eth/transaction.rs b/client/rpc/src/eth/transaction.rs index d87388f0e..861382a11 100644 --- a/client/rpc/src/eth/transaction.rs +++ b/client/rpc/src/eth/transaction.rs @@ -137,10 +137,7 @@ where _ => return Ok(None), }; - let schema = frontier_backend_client::onchain_storage_schema::( - client.as_ref(), - substrate_hash, - ); + let schema = fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash); let block = block_data_cache.current_block(schema, substrate_hash).await; let statuses = block_data_cache @@ -185,10 +182,7 @@ where let index = index.value(); - let schema = frontier_backend_client::onchain_storage_schema::( - client.as_ref(), - substrate_hash, - ); + let schema = fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash); let block = block_data_cache.current_block(schema, substrate_hash).await; let statuses = block_data_cache @@ -241,10 +235,7 @@ where .map_err(|_| internal_err(format!("Expect block number from id: {}", id)))?; let index = index.value(); - let schema = frontier_backend_client::onchain_storage_schema::( - client.as_ref(), - substrate_hash, - ); + let schema = fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash); let block = block_data_cache.current_block(schema, substrate_hash).await; let statuses = block_data_cache @@ -301,10 +292,7 @@ where _ => return Ok(None), }; - let schema = frontier_backend_client::onchain_storage_schema::( - client.as_ref(), - substrate_hash, - ); + let schema = fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash); let handler = overrides .schemas .get(&schema) diff --git a/client/rpc/src/eth_pubsub.rs b/client/rpc/src/eth_pubsub.rs index 01dacaf34..235015d8b 100644 --- a/client/rpc/src/eth_pubsub.rs +++ b/client/rpc/src/eth_pubsub.rs @@ -44,10 +44,9 @@ use fc_rpc_core::{ }, EthPubSubApiServer, }; +use fc_storage::OverrideHandle; use fp_rpc::EthereumRuntimeRPCApi; -use crate::{frontier_backend_client, overrides::OverrideHandle}; - #[derive(Debug)] pub struct EthereumSubIdProvider; @@ -231,11 +230,10 @@ where if notification.is_new_best { let substrate_hash = notification.hash; - let schema = frontier_backend_client::onchain_storage_schema::< - B, - C, - BE, - >(client.as_ref(), notification.hash); + let schema = fc_storage::onchain_storage_schema( + client.as_ref(), + substrate_hash, + ); let handler = overrides .schemas .get(&schema) @@ -269,11 +267,10 @@ where .import_notification_stream() .filter_map(move |notification| { if notification.is_new_best { - let schema = frontier_backend_client::onchain_storage_schema::< - B, - C, - BE, - >(client.as_ref(), notification.hash); + let schema = fc_storage::onchain_storage_schema( + client.as_ref(), + notification.hash, + ); let handler = overrides .schemas .get(&schema) diff --git a/client/rpc/src/lib.rs b/client/rpc/src/lib.rs index 3c65bccf0..5388bdb89 100644 --- a/client/rpc/src/lib.rs +++ b/client/rpc/src/lib.rs @@ -28,7 +28,6 @@ mod eth; mod eth_pubsub; mod net; -mod overrides; mod signer; mod web3; @@ -36,10 +35,6 @@ pub use self::{ eth::{format, EstimateGasAdapter, Eth, EthBlockDataCacheTask, EthFilter, EthTask}, eth_pubsub::{EthPubSub, EthereumSubIdProvider}, net::Net, - overrides::{ - OverrideHandle, RuntimeApiStorageOverride, SchemaV1Override, SchemaV2Override, - SchemaV3Override, StorageOverride, - }, signer::{EthDevSigner, EthSigner}, web3::Web3, }; @@ -47,24 +42,25 @@ pub use ethereum::TransactionV2 as EthereumTransaction; pub use fc_rpc_core::{ EthApiServer, EthFilterApiServer, EthPubSubApiServer, NetApiServer, Web3ApiServer, }; +pub use fc_storage::{ + OverrideHandle, RuntimeApiStorageOverride, SchemaV1Override, SchemaV2Override, + SchemaV3Override, StorageOverride, +}; pub mod frontier_backend_client { use super::internal_err; use ethereum_types::H256; use jsonrpsee::core::RpcResult; - use scale_codec::Decode; // Substrate - use sc_client_api::backend::{Backend, StateBackend, StorageProvider}; use sp_blockchain::HeaderBackend; use sp_runtime::{ generic::BlockId, - traits::{BlakeTwo256, Block as BlockT, UniqueSaturatedInto, Zero}, + traits::{Block as BlockT, UniqueSaturatedInto, Zero}, }; - use sp_storage::StorageKey; // Frontier use fc_rpc_core::types::BlockNumber; - use fp_storage::{EthereumStorageSchema, PALLET_ETHEREUM_SCHEMA}; + use fp_storage::EthereumStorageSchema; pub fn native_block_id( client: &C, @@ -145,24 +141,6 @@ pub mod frontier_backend_client { Ok(()) } - pub fn onchain_storage_schema( - client: &C, - hash: B::Hash, - ) -> EthereumStorageSchema - where - B: BlockT + Send + Sync + 'static, - C: StorageProvider + HeaderBackend + Send + Sync + 'static, - BE: Backend + 'static, - BE::State: StateBackend, - { - match client.storage(hash, &StorageKey(PALLET_ETHEREUM_SCHEMA.to_vec())) { - Ok(Some(bytes)) => Decode::decode(&mut &bytes.0[..]) - .ok() - .unwrap_or(EthereumStorageSchema::Undefined), - _ => EthereumStorageSchema::Undefined, - } - } - pub fn is_canon(client: &C, target_hash: H256) -> bool where B: BlockT + Send + Sync + 'static, diff --git a/client/storage/CHANGELOG.md b/client/storage/CHANGELOG.md new file mode 100644 index 000000000..96727b78f --- /dev/null +++ b/client/storage/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog for `fc-storage` diff --git a/client/storage/Cargo.toml b/client/storage/Cargo.toml new file mode 100644 index 000000000..b259cb0c6 --- /dev/null +++ b/client/storage/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "fc-storage" +version = "1.0.0-dev" +license = "GPL-3.0-or-later WITH Classpath-exception-2.0" +description = "Ethereum storage compatibility layer for Substrate." +authors = { workspace = true } +edition = { workspace = true } +repository = { workspace = true } + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +ethereum = { workspace = true, features = ["with-codec"] } +ethereum-types = { workspace = true } +scale-codec = { package = "parity-scale-codec", workspace = true } + +# Substrate +sc-client-api = { workspace = true } +sp-api = { workspace = true } +sp-blockchain = { workspace = true } +sp-io = { workspace = true } +sp-runtime = { workspace = true } +sp-storage = { workspace = true } +# Frontier +fp-rpc = { workspace = true, features = ["default"] } +fp-storage = { workspace = true, features = ["default"] } diff --git a/client/storage/src/lib.rs b/client/storage/src/lib.rs new file mode 100644 index 000000000..88ef59f8e --- /dev/null +++ b/client/storage/src/lib.rs @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// This file is part of Frontier. +// +// Copyright (c) 2020-2022 Parity Technologies (UK) Ltd. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +mod overrides; +pub use self::overrides::*; + +use std::{collections::BTreeMap, sync::Arc}; + +use scale_codec::Decode; +// Substrate +use sc_client_api::{backend::Backend, StorageProvider}; +use sp_api::ProvideRuntimeApi; +use sp_blockchain::HeaderBackend; +use sp_runtime::traits::Block as BlockT; +use sp_storage::StorageKey; +// Frontier +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: HeaderBackend + StorageProvider + 'static, + BE: Backend + 'static, +{ + let mut overrides_map = BTreeMap::new(); + overrides_map.insert( + EthereumStorageSchema::V1, + Box::new(SchemaV1Override::new(client.clone())) as Box>, + ); + overrides_map.insert( + EthereumStorageSchema::V2, + Box::new(SchemaV2Override::new(client.clone())) as Box>, + ); + overrides_map.insert( + EthereumStorageSchema::V3, + Box::new(SchemaV3Override::new(client.clone())) as Box>, + ); + + Arc::new(OverrideHandle { + schemas: overrides_map, + fallback: Box::new(RuntimeApiStorageOverride::::new(client)), + }) +} + +pub fn onchain_storage_schema(client: &C, hash: B::Hash) -> EthereumStorageSchema +where + B: BlockT, + C: StorageProvider + HeaderBackend, + BE: Backend, +{ + match client.storage(hash, &StorageKey(PALLET_ETHEREUM_SCHEMA.to_vec())) { + Ok(Some(bytes)) => Decode::decode(&mut &bytes.0[..]) + .ok() + .unwrap_or(EthereumStorageSchema::Undefined), + _ => EthereumStorageSchema::Undefined, + } +} diff --git a/client/rpc/src/overrides/mod.rs b/client/storage/src/overrides/mod.rs similarity index 94% rename from client/rpc/src/overrides/mod.rs rename to client/storage/src/overrides/mod.rs index f54e56ef1..3f2966b06 100644 --- a/client/rpc/src/overrides/mod.rs +++ b/client/storage/src/overrides/mod.rs @@ -32,13 +32,14 @@ mod schema_v1_override; mod schema_v2_override; mod schema_v3_override; -pub use schema_v1_override::SchemaV1Override; -pub use schema_v2_override::SchemaV2Override; -pub use schema_v3_override::SchemaV3Override; +pub use self::{ + schema_v1_override::SchemaV1Override, schema_v2_override::SchemaV2Override, + schema_v3_override::SchemaV3Override, +}; pub struct OverrideHandle { - pub schemas: BTreeMap + Send + Sync>>, - pub fallback: Box + Send + Sync>, + pub schemas: BTreeMap>>, + pub fallback: Box>, } /// Something that can fetch Ethereum-related data. This trait is quite similar to the runtime API, @@ -46,7 +47,7 @@ pub struct OverrideHandle { /// Having this trait is useful because it allows optimized implementations that fetch data from a /// State Backend with some assumptions about pallet-ethereum's storage schema. Using such an /// optimized implementation avoids spawning a runtime and the overhead associated with it. -pub trait StorageOverride { +pub trait StorageOverride: Send + Sync { /// For a given account address, returns pallet_evm::AccountCodes. fn account_code_at(&self, block_hash: Block::Hash, address: H160) -> Option>; /// For a given account address and index, returns pallet_evm::AccountStorages. @@ -94,8 +95,8 @@ impl RuntimeApiStorageOverride { impl StorageOverride for RuntimeApiStorageOverride where - Block: BlockT + Send + Sync + 'static, - C: ProvideRuntimeApi + Send + Sync + 'static, + Block: BlockT, + C: ProvideRuntimeApi + Send + Sync, C::Api: EthereumRuntimeRPCApi, { /// For a given account address, returns pallet_evm::AccountCodes. diff --git a/client/rpc/src/overrides/schema_v1_override.rs b/client/storage/src/overrides/schema_v1_override.rs similarity index 92% rename from client/rpc/src/overrides/schema_v1_override.rs rename to client/storage/src/overrides/schema_v1_override.rs index 4c4a91cd2..477699cc7 100644 --- a/client/rpc/src/overrides/schema_v1_override.rs +++ b/client/storage/src/overrides/schema_v1_override.rs @@ -21,12 +21,9 @@ use std::{marker::PhantomData, sync::Arc}; use ethereum_types::{H160, H256, U256}; use scale_codec::Decode; // Substrate -use sc_client_api::backend::{Backend, StateBackend, StorageProvider}; +use sc_client_api::backend::{Backend, StorageProvider}; use sp_blockchain::HeaderBackend; -use sp_runtime::{ - traits::{BlakeTwo256, Block as BlockT}, - Permill, -}; +use sp_runtime::{traits::Block as BlockT, Permill}; use sp_storage::StorageKey; // Frontier use fp_rpc::TransactionStatus; @@ -51,10 +48,9 @@ impl SchemaV1Override { impl SchemaV1Override where - B: BlockT + Send + Sync + 'static, + B: BlockT, C: StorageProvider + HeaderBackend + Send + Sync + 'static, BE: Backend + 'static, - BE::State: StateBackend, { fn query_storage(&self, block_hash: B::Hash, key: &StorageKey) -> Option { if let Ok(Some(data)) = self.client.storage(block_hash, key) { @@ -68,10 +64,9 @@ where impl StorageOverride for SchemaV1Override where - B: BlockT + Send + Sync + 'static, + B: BlockT, C: StorageProvider + HeaderBackend + Send + Sync + 'static, BE: Backend + 'static, - BE::State: StateBackend, { /// For a given account address, returns pallet_evm::AccountCodes. fn account_code_at(&self, block_hash: B::Hash, address: H160) -> Option> { diff --git a/client/rpc/src/overrides/schema_v2_override.rs b/client/storage/src/overrides/schema_v2_override.rs similarity index 93% rename from client/rpc/src/overrides/schema_v2_override.rs rename to client/storage/src/overrides/schema_v2_override.rs index b8ba3f120..fef92aa9a 100644 --- a/client/rpc/src/overrides/schema_v2_override.rs +++ b/client/storage/src/overrides/schema_v2_override.rs @@ -21,12 +21,9 @@ use std::{marker::PhantomData, sync::Arc}; use ethereum_types::{H160, H256, U256}; use scale_codec::Decode; // Substrate -use sc_client_api::backend::{Backend, StateBackend, StorageProvider}; +use sc_client_api::backend::{Backend, StorageProvider}; use sp_blockchain::HeaderBackend; -use sp_runtime::{ - traits::{BlakeTwo256, Block as BlockT}, - Permill, -}; +use sp_runtime::{traits::Block as BlockT, Permill}; use sp_storage::StorageKey; // Frontier use fp_rpc::TransactionStatus; @@ -51,10 +48,9 @@ impl SchemaV2Override { impl SchemaV2Override where - B: BlockT + Send + Sync + 'static, + B: BlockT, C: StorageProvider + HeaderBackend + Send + Sync + 'static, BE: Backend + 'static, - BE::State: StateBackend, { fn query_storage(&self, block_hash: B::Hash, key: &StorageKey) -> Option { if let Ok(Some(data)) = self.client.storage(block_hash, key) { @@ -68,10 +64,9 @@ where impl StorageOverride for SchemaV2Override where - B: BlockT + Send + Sync + 'static, + B: BlockT, C: StorageProvider + HeaderBackend + Send + Sync + 'static, BE: Backend + 'static, - BE::State: StateBackend, { /// For a given account address, returns pallet_evm::AccountCodes. fn account_code_at(&self, block_hash: B::Hash, address: H160) -> Option> { diff --git a/client/rpc/src/overrides/schema_v3_override.rs b/client/storage/src/overrides/schema_v3_override.rs similarity index 92% rename from client/rpc/src/overrides/schema_v3_override.rs rename to client/storage/src/overrides/schema_v3_override.rs index aaa053543..a833d0aa5 100644 --- a/client/rpc/src/overrides/schema_v3_override.rs +++ b/client/storage/src/overrides/schema_v3_override.rs @@ -21,12 +21,9 @@ use std::{marker::PhantomData, sync::Arc}; use ethereum_types::{H160, H256, U256}; use scale_codec::Decode; // Substrate -use sc_client_api::backend::{Backend, StateBackend, StorageProvider}; +use sc_client_api::backend::{Backend, StorageProvider}; use sp_blockchain::HeaderBackend; -use sp_runtime::{ - traits::{BlakeTwo256, Block as BlockT}, - Permill, -}; +use sp_runtime::{traits::Block as BlockT, Permill}; use sp_storage::StorageKey; // Frontier use fp_rpc::TransactionStatus; @@ -51,10 +48,9 @@ impl SchemaV3Override { impl SchemaV3Override where - B: BlockT + Send + Sync + 'static, + B: BlockT, C: StorageProvider + HeaderBackend + Send + Sync + 'static, BE: Backend + 'static, - BE::State: StateBackend, { fn query_storage(&self, block_hash: B::Hash, key: &StorageKey) -> Option { if let Ok(Some(data)) = self.client.storage(block_hash, key) { @@ -68,10 +64,9 @@ where impl StorageOverride for SchemaV3Override where - B: BlockT + Send + Sync + 'static, + B: BlockT, C: StorageProvider + HeaderBackend + Send + Sync + 'static, BE: Backend + 'static, - BE::State: StateBackend, { /// For a given account address, returns pallet_evm::AccountCodes. fn account_code_at(&self, block_hash: B::Hash, address: H160) -> Option> { diff --git a/template/node/Cargo.toml b/template/node/Cargo.toml index 84aa127aa..d2d679656 100644 --- a/template/node/Cargo.toml +++ b/template/node/Cargo.toml @@ -71,10 +71,10 @@ fc-db = { workspace = true } fc-mapping-sync = { workspace = true } fc-rpc = { workspace = true } fc-rpc-core = { workspace = true } +fc-storage = { workspace = true } fp-dynamic-fee = { workspace = true, features = ["std"] } fp-evm = { workspace = true, features = ["std"] } fp-rpc = { workspace = true, features = ["std"] } -fp-storage = { workspace = true, features = ["std"] } frontier-template-runtime = { workspace = true, features = ["std"] } [build-dependencies] diff --git a/template/node/src/rpc/eth.rs b/template/node/src/rpc/eth.rs index b71431c4e..8cdd13b96 100644 --- a/template/node/src/rpc/eth.rs +++ b/template/node/src/rpc/eth.rs @@ -1,4 +1,4 @@ -use std::{collections::BTreeMap, sync::Arc}; +use std::sync::Arc; use jsonrpsee::RpcModule; // Substrate @@ -16,12 +16,9 @@ use sp_core::H256; use sp_runtime::traits::{BlakeTwo256, Block as BlockT, Header as HeaderT}; // Frontier use fc_db::Backend as FrontierBackend; -pub use fc_rpc::{ - EthBlockDataCacheTask, OverrideHandle, RuntimeApiStorageOverride, SchemaV1Override, - SchemaV2Override, SchemaV3Override, StorageOverride, -}; +pub use fc_rpc::{EthBlockDataCacheTask, OverrideHandle, StorageOverride}; pub use fc_rpc_core::types::{FeeHistoryCache, FeeHistoryCacheLimit, FilterPool}; -use fp_storage::EthereumStorageSchema; +pub use fc_storage::overrides_handle; /// Extra dependencies for Ethereum compatibility. pub struct EthDeps { @@ -80,38 +77,6 @@ impl Clone for EthDeps } } -pub fn overrides_handle(client: Arc) -> Arc> -where - C: ProvideRuntimeApi + StorageProvider + AuxStore, - C: HeaderBackend + HeaderMetadata + 'static, - C::Api: fp_rpc::EthereumRuntimeRPCApi, - BE: Backend + 'static, - BE::State: StateBackend, - B: BlockT, -{ - let mut overrides_map = BTreeMap::new(); - overrides_map.insert( - EthereumStorageSchema::V1, - Box::new(SchemaV1Override::new(client.clone())) - as Box + Send + Sync>, - ); - overrides_map.insert( - EthereumStorageSchema::V2, - Box::new(SchemaV2Override::new(client.clone())) - as Box + Send + Sync>, - ); - overrides_map.insert( - EthereumStorageSchema::V3, - Box::new(SchemaV3Override::new(client.clone())) - as Box + Send + Sync>, - ); - - Arc::new(OverrideHandle { - schemas: overrides_map, - fallback: Box::new(RuntimeApiStorageOverride::::new(client)), - }) -} - /// Instantiate Ethereum-compatible RPC extensions. pub fn create_eth( mut io: RpcModule<()>,