From 6d66e0f053cd666da82a0d21997ee59efbad9c22 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Wed, 24 Jan 2024 18:57:54 +0100 Subject: [PATCH] refactor: CrossAccountId moved to up-common, RuntimeApiDep and node simplified --- Cargo.lock | 38 +++++----- Cargo.toml | 28 +++---- node/cli/src/command.rs | 41 +++-------- node/cli/src/rpc.rs | 12 +-- node/cli/src/service.rs | 73 ++++++------------- primitives/common/Cargo.toml | 2 + primitives/common/src/types.rs | 30 +++++--- runtime/common/config/ethereum.rs | 4 +- .../common/config/pallets/foreign_asset.rs | 18 ++--- runtime/common/config/substrate.rs | 4 +- runtime/common/instance.rs | 7 -- runtime/common/mod.rs | 1 - runtime/common/runtime_apis.rs | 2 +- 13 files changed, 105 insertions(+), 155 deletions(-) delete mode 100644 runtime/common/instance.rs diff --git a/Cargo.lock b/Cargo.lock index 62e79b387c..ea73c1cfde 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3342,7 +3342,7 @@ dependencies = [ [[package]] name = "fc-api" version = "1.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0#2b684850edc955bcd3c3943216e451364ff0afa3" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0-newbcci#e0d4a04f1d801cc914734efe7da2c2f17bf0b9d7" dependencies = [ "async-trait", "fp-storage", @@ -3354,7 +3354,7 @@ dependencies = [ [[package]] name = "fc-consensus" version = "2.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0#2b684850edc955bcd3c3943216e451364ff0afa3" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0-newbcci#e0d4a04f1d801cc914734efe7da2c2f17bf0b9d7" dependencies = [ "async-trait", "fp-consensus", @@ -3370,7 +3370,7 @@ dependencies = [ [[package]] name = "fc-db" version = "2.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0#2b684850edc955bcd3c3943216e451364ff0afa3" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0-newbcci#e0d4a04f1d801cc914734efe7da2c2f17bf0b9d7" dependencies = [ "async-trait", "fc-api", @@ -3391,7 +3391,7 @@ dependencies = [ [[package]] name = "fc-mapping-sync" version = "2.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0#2b684850edc955bcd3c3943216e451364ff0afa3" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0-newbcci#e0d4a04f1d801cc914734efe7da2c2f17bf0b9d7" dependencies = [ "fc-db", "fc-storage", @@ -3412,7 +3412,7 @@ dependencies = [ [[package]] name = "fc-rpc" version = "2.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0#2b684850edc955bcd3c3943216e451364ff0afa3" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0-newbcci#e0d4a04f1d801cc914734efe7da2c2f17bf0b9d7" dependencies = [ "ethereum", "ethereum-types", @@ -3466,7 +3466,7 @@ dependencies = [ [[package]] name = "fc-rpc-core" version = "1.1.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0#2b684850edc955bcd3c3943216e451364ff0afa3" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0-newbcci#e0d4a04f1d801cc914734efe7da2c2f17bf0b9d7" dependencies = [ "ethereum", "ethereum-types", @@ -3479,7 +3479,7 @@ dependencies = [ [[package]] name = "fc-storage" version = "1.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0#2b684850edc955bcd3c3943216e451364ff0afa3" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0-newbcci#e0d4a04f1d801cc914734efe7da2c2f17bf0b9d7" dependencies = [ "ethereum", "ethereum-types", @@ -3632,7 +3632,7 @@ dependencies = [ [[package]] name = "fp-account" version = "1.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0#2b684850edc955bcd3c3943216e451364ff0afa3" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0-newbcci#e0d4a04f1d801cc914734efe7da2c2f17bf0b9d7" dependencies = [ "hex", "impl-serde", @@ -3651,7 +3651,7 @@ dependencies = [ [[package]] name = "fp-consensus" version = "2.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0#2b684850edc955bcd3c3943216e451364ff0afa3" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0-newbcci#e0d4a04f1d801cc914734efe7da2c2f17bf0b9d7" dependencies = [ "ethereum", "parity-scale-codec", @@ -3663,7 +3663,7 @@ dependencies = [ [[package]] name = "fp-ethereum" version = "1.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0#2b684850edc955bcd3c3943216e451364ff0afa3" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0-newbcci#e0d4a04f1d801cc914734efe7da2c2f17bf0b9d7" dependencies = [ "ethereum", "ethereum-types", @@ -3676,7 +3676,7 @@ dependencies = [ [[package]] name = "fp-evm" version = "3.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0#2b684850edc955bcd3c3943216e451364ff0afa3" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0-newbcci#e0d4a04f1d801cc914734efe7da2c2f17bf0b9d7" dependencies = [ "evm", "frame-support", @@ -3692,7 +3692,7 @@ dependencies = [ [[package]] name = "fp-rpc" version = "3.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0#2b684850edc955bcd3c3943216e451364ff0afa3" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0-newbcci#e0d4a04f1d801cc914734efe7da2c2f17bf0b9d7" dependencies = [ "ethereum", "ethereum-types", @@ -3709,7 +3709,7 @@ dependencies = [ [[package]] name = "fp-self-contained" version = "1.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0#2b684850edc955bcd3c3943216e451364ff0afa3" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0-newbcci#e0d4a04f1d801cc914734efe7da2c2f17bf0b9d7" dependencies = [ "frame-support", "parity-scale-codec", @@ -3721,7 +3721,7 @@ dependencies = [ [[package]] name = "fp-storage" version = "2.0.0" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0#2b684850edc955bcd3c3943216e451364ff0afa3" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0-newbcci#e0d4a04f1d801cc914734efe7da2c2f17bf0b9d7" dependencies = [ "parity-scale-codec", "serde", @@ -6988,7 +6988,7 @@ dependencies = [ [[package]] name = "pallet-base-fee" version = "1.0.0" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0#2b684850edc955bcd3c3943216e451364ff0afa3" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0-newbcci#e0d4a04f1d801cc914734efe7da2c2f17bf0b9d7" dependencies = [ "fp-evm", "frame-support", @@ -7272,7 +7272,7 @@ dependencies = [ [[package]] name = "pallet-ethereum" version = "4.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0#2b684850edc955bcd3c3943216e451364ff0afa3" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0-newbcci#e0d4a04f1d801cc914734efe7da2c2f17bf0b9d7" dependencies = [ "ethereum", "ethereum-types", @@ -7295,8 +7295,9 @@ dependencies = [ [[package]] name = "pallet-evm" version = "6.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0#2b684850edc955bcd3c3943216e451364ff0afa3" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0-newbcci#e0d4a04f1d801cc914734efe7da2c2f17bf0b9d7" dependencies = [ + "derivative", "environmental", "evm", "fp-account", @@ -7377,7 +7378,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-simple" version = "2.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0#2b684850edc955bcd3c3943216e451364ff0afa3" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.3.0-newbcci#e0d4a04f1d801cc914734efe7da2c2f17bf0b9d7" dependencies = [ "fp-evm", "ripemd", @@ -15142,6 +15143,7 @@ dependencies = [ "fp-self-contained", "frame-support", "pallet-evm", + "serde", "sp-consensus-aura", "sp-core", "sp-runtime", diff --git a/Cargo.toml b/Cargo.toml index c7bb61f678..d809eec35c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,22 +69,22 @@ quartz-runtime = { path = "runtime/quartz" } unique-runtime = { path = "runtime/unique" } # Frontier (Unique patches over the Parity version) -fc-api = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0" } -fc-consensus = { git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0" } -fc-db = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0" } -fc-mapping-sync = { git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0" } -fc-rpc = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0" } -fc-rpc-core = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0" } -fp-evm = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0" } -fp-rpc = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0" } +fc-api = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0-newbcci" } +fc-consensus = { git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0-newbcci" } +fc-db = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0-newbcci" } +fc-mapping-sync = { git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0-newbcci" } +fc-rpc = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0-newbcci" } +fc-rpc-core = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0-newbcci" } +fp-evm = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0-newbcci" } +fp-rpc = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0-newbcci" } fp-self-contained = { default-features = false, features = [ "serde", -], git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0" } -fp-storage = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0" } -pallet-base-fee = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0" } -pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0" } -pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0" } -pallet-evm-precompile-simple = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0" } +], git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0-newbcci" } +fp-storage = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0-newbcci" } +pallet-base-fee = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0-newbcci" } +pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0-newbcci" } +pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0-newbcci" } +pallet-evm-precompile-simple = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v1.3.0-newbcci" } # Parity codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = "3.6.5" } diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index 6ed625d191..e490a35948 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -163,16 +163,14 @@ impl SubstrateCli for RelayChainCli { macro_rules! async_run_with_runtime { ( - $runtime:path, $runtime_api:path, $executor:path, + $runtime_api:path, $executor:path, $runner:ident, $components:ident, $cli:ident, $cmd:ident, $config:ident, $( $code:tt )* ) => { $runner.async_run(|$config| { - let $components = new_partial::< - $runtime, $runtime_api, $executor, _ - >( + let $components = new_partial::<$runtime_api, $executor, _>( &$config, - crate::service::parachain_build_import_queue::<$runtime, _, _>, + crate::service::parachain_build_import_queue, )?; let task_manager = $components.task_manager; @@ -188,18 +186,18 @@ macro_rules! construct_async_run { match runner.config().chain_spec.runtime_id() { #[cfg(feature = "unique-runtime")] RuntimeId::Unique => async_run_with_runtime!( - unique_runtime::Runtime, unique_runtime::RuntimeApi, UniqueRuntimeExecutor, + unique_runtime::RuntimeApi, UniqueRuntimeExecutor, runner, $components, $cli, $cmd, $config, $( $code )* ), #[cfg(feature = "quartz-runtime")] RuntimeId::Quartz => async_run_with_runtime!( - quartz_runtime::Runtime, quartz_runtime::RuntimeApi, QuartzRuntimeExecutor, + quartz_runtime::RuntimeApi, QuartzRuntimeExecutor, runner, $components, $cli, $cmd, $config, $( $code )* ), RuntimeId::Opal => async_run_with_runtime!( - opal_runtime::Runtime, opal_runtime::RuntimeApi, OpalRuntimeExecutor, + opal_runtime::RuntimeApi, OpalRuntimeExecutor, runner, $components, $cli, $cmd, $config, $( $code )* ), @@ -215,11 +213,9 @@ macro_rules! sync_run_with_runtime { $( $code:tt )* ) => { $runner.sync_run(|$config| { - let $components = new_partial::< - $runtime, $runtime_api, $executor, _ - >( + let $components = new_partial::<$runtime_api, $executor, _>( &$config, - crate::service::parachain_build_import_queue::<$runtime, _, _>, + crate::service::parachain_build_import_queue, )?; $( $code )* @@ -259,20 +255,17 @@ macro_rules! start_node_using_chain_runtime { match $config.chain_spec.runtime_id() { #[cfg(feature = "unique-runtime")] RuntimeId::Unique => $start_node_fn::< - unique_runtime::Runtime, unique_runtime::RuntimeApi, UniqueRuntimeExecutor, >($config $(, $($args),+)?) $($code)*, #[cfg(feature = "quartz-runtime")] RuntimeId::Quartz => $start_node_fn::< - quartz_runtime::Runtime, quartz_runtime::RuntimeApi, QuartzRuntimeExecutor, >($config $(, $($args),+)?) $($code)*, RuntimeId::Opal => $start_node_fn::< - opal_runtime::Runtime, opal_runtime::RuntimeApi, OpalRuntimeExecutor, >($config $(, $($args),+)?) $($code)*, @@ -361,26 +354,16 @@ pub fn run() -> Result<()> { runner.sync_run(|config| cmd.run::(config)) } BenchmarkCmd::Block(cmd) => runner.sync_run(|config| { - let partials = new_partial::< - opal_runtime::Runtime, - opal_runtime::RuntimeApi, - OpalRuntimeExecutor, - _, - >( + let partials = new_partial::( &config, - crate::service::parachain_build_import_queue::, + crate::service::parachain_build_import_queue, )?; cmd.run(partials.client) }), BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| { - let partials = new_partial::< - opal_runtime::Runtime, - opal_runtime::RuntimeApi, - OpalRuntimeExecutor, - _, - >( + let partials = new_partial::( &config, - crate::service::parachain_build_import_queue::, + crate::service::parachain_build_import_queue, )?; let db = partials.backend.expose_db(); let storage = partials.backend.expose_storage(); diff --git a/node/cli/src/rpc.rs b/node/cli/src/rpc.rs index 2e52d5ffbc..2f27f79dd4 100644 --- a/node/cli/src/rpc.rs +++ b/node/cli/src/rpc.rs @@ -65,7 +65,7 @@ pub struct FullDeps { } /// Instantiate all Full RPC extensions. -pub fn create_full( +pub fn create_full( io: &mut RpcModule<()>, deps: FullDeps, ) -> Result<(), Box> @@ -74,18 +74,15 @@ where C: HeaderBackend + HeaderMetadata + 'static, C: Send + Sync + 'static, C: BlockchainEvents, - C::Api: RuntimeApiDep, + C::Api: RuntimeApiDep, B: sc_client_api::Backend + Send + Sync + 'static, P: TransactionPool + 'static, - R: RuntimeInstance + Send + Sync + 'static, - ::CrossAccountId: serde::Serialize, C: sp_api::CallApiAt< sp_runtime::generic::Block< sp_runtime::generic::Header, sp_runtime::OpaqueExtrinsic, >, >, - for<'de> ::CrossAccountId: serde::Deserialize<'de>, { // use pallet_contracts_rpc::{Contracts, ContractsApi}; use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; @@ -165,7 +162,7 @@ pub struct EthDeps { pub pending_create_inherent_data_providers: CIDP, } -pub fn create_eth( +pub fn create_eth( io: &mut RpcModule<()>, deps: EthDeps, subscription_task_executor: SubscriptionTaskExecutor, @@ -176,14 +173,13 @@ where C: Send + Sync + 'static, C: BlockchainEvents, C: UsageProvider, - C::Api: RuntimeApiDep, + C::Api: RuntimeApiDep, P: TransactionPool + 'static, CA: ChainApi + 'static, B: sc_client_api::Backend + Send + Sync + 'static, C: sp_api::CallApiAt, CIDP: CreateInherentDataProviders + Send + 'static, EC: EthConfig, - R: RuntimeInstance, { use fc_rpc::{ Eth, EthApiServer, EthDevSigner, EthFilter, EthFilterApiServer, EthPubSub, diff --git a/node/cli/src/service.rs b/node/cli/src/service.rs index 5f954078c8..f86cc2a611 100644 --- a/node/cli/src/service.rs +++ b/node/cli/src/service.rs @@ -65,7 +65,6 @@ use sc_network_sync::SyncingService; use sc_rpc::SubscriptionTaskExecutor; use sc_service::{Configuration, PartialComponents, TaskManager}; use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; -use serde::{Deserialize, Serialize}; use sp_api::{ProvideRuntimeApi, StateBackend}; use sp_block_builder::BlockBuilder; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; @@ -193,23 +192,23 @@ type ParachainBlockImport = /// Generate a supertrait based on bounds, and blanket impl for it. macro_rules! ez_bounds { - ($vis:vis trait $name:ident$(<$($gen:ident $(: $($(+)? $bound:path)*)?),* $(,)?>)? $(:)? $($(+)? $super:path)* {}) => { - $vis trait $name $(<$($gen $(: $($bound+)*)?,)*>)?: $($super +)* {} + ($vis:vis trait $name:ident$(<$($gen:ident $(: $($(+)? $bound:path)*)?),* $(,)?>)? $(:)? $($lt:lifetime)? $($(+)? $super:path)* {}) => { + $vis trait $name $(<$($gen $(: $($bound+)*)?,)*>)?: $($lt +)? $($super +)* {} impl $name$(<$($gen,)*>)? for T - where T: $($super +)* {} + where T: $($lt +)? $($super +)* {} } } ez_bounds!( - pub trait RuntimeApiDep: - sp_transaction_pool::runtime_api::TaggedTransactionQueue + pub trait RuntimeApiDep: 'static + + sp_transaction_pool::runtime_api::TaggedTransactionQueue + sp_consensus_aura::AuraApi + fp_rpc::EthereumRuntimeRPCApi + sp_session::SessionKeys + sp_block_builder::BlockBuilder + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi + sp_api::ApiExt - + up_rpc::UniqueApi - + app_promotion_rpc::AppPromotionApi + + up_rpc::UniqueApi + + app_promotion_rpc::AppPromotionApi + up_pov_estimate_rpc::PovEstimateApi + substrate_frame_rpc_system::AccountNonceApi + sp_api::Metadata @@ -234,7 +233,7 @@ ez_bounds!( /// Use this macro if you don't actually need the full service, but just the builder in order to /// be able to perform chain operations. #[allow(clippy::type_complexity)] -pub fn new_partial( +pub fn new_partial( config: &Configuration, build_import_queue: BIQ, ) -> Result< @@ -254,8 +253,7 @@ where + Send + Sync + 'static, - RuntimeApi::RuntimeApi: RuntimeApiDep + 'static, - Runtime: RuntimeInstance, + RuntimeApi::RuntimeApi: RuntimeApiDep, ExecutorDispatch: NativeExecutionDispatch + 'static, BIQ: FnOnce( Arc>, @@ -348,7 +346,7 @@ macro_rules! clone { /// /// This is the actual implementation that is abstract over the executor and the runtime api. #[sc_tracing::logging::prefix_logs_with("Parachain")] -pub async fn start_node( +pub async fn start_node( parachain_config: Configuration, polkadot_config: Configuration, collator_options: CollatorOptions, @@ -357,21 +355,17 @@ pub async fn start_node( ) -> sc_service::error::Result<(TaskManager, Arc>)> where sc_client_api::StateBackendFor: sp_api::StateBackend, - Runtime: RuntimeInstance + Send + Sync + 'static, - ::CrossAccountId: Serialize, - for<'de> ::CrossAccountId: Deserialize<'de>, RuntimeApi: sp_api::ConstructRuntimeApi> + Send + Sync + 'static, - RuntimeApi::RuntimeApi: RuntimeApiDep + 'static, + RuntimeApi::RuntimeApi: RuntimeApiDep, RuntimeApi::RuntimeApi: LookaheadApiDep, - Runtime: RuntimeInstance, ExecutorDispatch: NativeExecutionDispatch + 'static, { let parachain_config = prepare_node_config(parachain_config); - let params = new_partial::( + let params = new_partial::( ¶chain_config, parachain_build_import_queue, )?; @@ -508,7 +502,7 @@ where select_chain, }; - create_full::<_, _, _, Runtime, _>(&mut rpc_handle, full_deps)?; + create_full(&mut rpc_handle, full_deps)?; let eth_deps = EthDeps { client, @@ -531,15 +525,7 @@ where pending_create_inherent_data_providers: |_, ()| async move { Ok(()) }, }; - create_eth::< - _, - _, - _, - _, - _, - _, - DefaultEthConfig>, - >( + create_eth::<_, _, _, _, _, DefaultEthConfig>>( &mut rpc_handle, eth_deps, subscription_task_executor.clone(), @@ -634,7 +620,7 @@ where } /// Build the import queue for the the parachain runtime. -pub fn parachain_build_import_queue( +pub fn parachain_build_import_queue( client: Arc>, backend: Arc, config: &Configuration, @@ -646,8 +632,7 @@ where + Send + Sync + 'static, - RuntimeApi::RuntimeApi: RuntimeApiDep + 'static, - Runtime: RuntimeInstance, + RuntimeApi::RuntimeApi: RuntimeApiDep, ExecutorDispatch: NativeExecutionDispatch + 'static, { let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?; @@ -699,7 +684,7 @@ pub struct StartConsensusParameters<'a> { // Clones ignored for optional lookahead collator #[allow(clippy::redundant_clone)] -pub fn start_consensus( +pub fn start_consensus( client: Arc>, transaction_pool: Arc< sc_transaction_pool::FullPool>, @@ -712,9 +697,8 @@ where + Send + Sync + 'static, - RuntimeApi::RuntimeApi: RuntimeApiDep + 'static, + RuntimeApi::RuntimeApi: RuntimeApiDep, RuntimeApi::RuntimeApi: LookaheadApiDep, - Runtime: RuntimeInstance, { let StartConsensusParameters { backend, @@ -835,21 +819,18 @@ where /// Builds a new development service. This service uses instant seal, and mocks /// the parachain inherent -pub fn start_dev_node( +pub fn start_dev_node( config: Configuration, autoseal_interval: u64, autoseal_finalize_delay: Option, disable_autoseal_on_tx: bool, ) -> sc_service::error::Result where - Runtime: RuntimeInstance + Send + Sync + 'static, - ::CrossAccountId: Serialize, - for<'de> ::CrossAccountId: Deserialize<'de>, RuntimeApi: sp_api::ConstructRuntimeApi> + Send + Sync + 'static, - RuntimeApi::RuntimeApi: RuntimeApiDep + 'static, + RuntimeApi::RuntimeApi: RuntimeApiDep, ExecutorDispatch: NativeExecutionDispatch + 'static, { use fc_consensus::FrontierBlockImport; @@ -873,7 +854,7 @@ where eth_backend, telemetry_worker_handle: _, }, - } = new_partial::( + } = new_partial::( &config, dev_build_import_queue::, )?; @@ -1091,7 +1072,7 @@ where select_chain, }; - create_full::<_, _, _, Runtime, _>(&mut rpc_module, full_deps)?; + create_full(&mut rpc_module, full_deps)?; let eth_deps = EthDeps { client, @@ -1115,15 +1096,7 @@ where pending_create_inherent_data_providers: |_, ()| async move { Ok(()) }, }; - create_eth::< - _, - _, - _, - _, - _, - _, - DefaultEthConfig>, - >( + create_eth::<_, _, _, _, _, DefaultEthConfig>>( &mut rpc_module, eth_deps, subscription_task_executor.clone(), diff --git a/primitives/common/Cargo.toml b/primitives/common/Cargo.toml index 4b12b4a027..80efbdb6f3 100644 --- a/primitives/common/Cargo.toml +++ b/primitives/common/Cargo.toml @@ -20,6 +20,7 @@ std = [ 'sp-core/std', 'sp-runtime/std', 'sp-std/std', + 'serde/std', ] [dependencies] @@ -32,3 +33,4 @@ sp-consensus-aura = { workspace = true } sp-core = { workspace = true } sp-runtime = { workspace = true } sp-std = { workspace = true } +serde = { workspace = true } diff --git a/primitives/common/src/types.rs b/primitives/common/src/types.rs index 06e751100f..bbef3f5269 100644 --- a/primitives/common/src/types.rs +++ b/primitives/common/src/types.rs @@ -16,7 +16,7 @@ use sp_runtime::{ generic, - traits::{IdentifyAccount, Verify}, + traits::{BlakeTwo256, IdentifyAccount, Verify}, MultiSignature, }; @@ -25,9 +25,11 @@ use sp_runtime::{ /// of data like extrinsics, allowing for them to continue syncing the network through upgrades /// to even the core data structures. pub mod opaque { - pub use sp_runtime::{generic, traits::BlakeTwo256, OpaqueExtrinsic as UncheckedExtrinsic}; + pub use sp_runtime::{generic, OpaqueExtrinsic as UncheckedExtrinsic}; - pub use super::{AccountId, AuraId, Balance, BlockNumber, Hash, Signature}; + pub use super::{ + AccountId, AuraId, Balance, BlockNumber, CrossAccountId, Hash, Hashing, Signature, + }; #[derive(Debug, Clone)] pub enum RuntimeId { @@ -37,16 +39,9 @@ pub mod opaque { Unknown(sp_std::vec::Vec), } - pub type Header = generic::Header; + pub type Header = generic::Header; pub type Block = generic::Block; - - pub trait RuntimeInstance { - type CrossAccountId: pallet_evm::account::CrossAccountId - + Send - + Sync - + 'static; - } } pub type SessionHandlers = (); @@ -61,6 +56,16 @@ pub type Signature = MultiSignature; /// to the public key of our transaction signing scheme. pub type AccountId = <::Signer as IdentifyAccount>::AccountId; +pub struct CrossAccountConfig; +impl pallet_evm::account::CrossAccountConfig for CrossAccountConfig { + type AccountId = AccountId; + type AddressMapping = pallet_evm::HashedAddressMapping; + type BackwardsAddressMapping = pallet_evm::HashedAddressMapping; +} + +/// Way to identify both Substrate and Ethereum accounts. +pub type CrossAccountId = pallet_evm::account::BasicCrossAccountId; + /// The type for looking up accounts. We don't expect more than 4 billion of them, but you /// never know... pub type AccountIndex = u32; @@ -74,6 +79,9 @@ pub type Nonce = u32; /// A hash of some data used by the chain. pub type Hash = sp_core::H256; +/// The hashing algorithm used. +pub type Hashing = BlakeTwo256; + /// Digest item type. pub type DigestItem = generic::DigestItem; diff --git a/runtime/common/config/ethereum.rs b/runtime/common/config/ethereum.rs index 6c8e5d58d0..729a6df347 100644 --- a/runtime/common/config/ethereum.rs +++ b/runtime/common/config/ethereum.rs @@ -8,7 +8,7 @@ use pallet_ethereum::PostLogContent; use pallet_evm::{EnsureAddressTruncated, HashedAddressMapping}; use sp_core::{H160, U256}; use sp_runtime::{traits::ConstU32, Perbill, RuntimeAppPublic}; -use up_common::constants::*; +use up_common::{constants::*, types::CrossAccountId}; use crate::{ runtime_common::{ @@ -20,8 +20,6 @@ use crate::{ Aura, Balances, ChainId, Runtime, RuntimeEvent, }; -pub type CrossAccountId = pallet_evm::account::BasicCrossAccountId; - // Assuming PoV size per read is 96 bytes: 16 for twox128(Evm), 16 for twox128(Storage), 32 for storage key, and 32 for storage value const EVM_SLOAD_PROOF_SIZE: u64 = 96; diff --git a/runtime/common/config/pallets/foreign_asset.rs b/runtime/common/config/pallets/foreign_asset.rs index 60924bdea2..1c732c3af9 100644 --- a/runtime/common/config/pallets/foreign_asset.rs +++ b/runtime/common/config/pallets/foreign_asset.rs @@ -1,18 +1,16 @@ use frame_support::{parameter_types, PalletId}; #[cfg(not(feature = "governance"))] use frame_system::EnsureRoot; -use pallet_evm::account::CrossAccountId; +use pallet_evm::account::CrossAccountId as CrossAccountIdT; use sp_core::H160; use staging_xcm::prelude::*; use staging_xcm_builder::AccountKey20Aliases; +use up_common::types::CrossAccountId; #[cfg(feature = "governance")] use crate::runtime_common::config::governance; use crate::{ - runtime_common::config::{ - ethereum::CrossAccountId as ConfigCrossAccountId, - xcm::{LocationToAccountId, SelfLocation}, - }, + runtime_common::config::xcm::{LocationToAccountId, SelfLocation}, RelayNetwork, Runtime, RuntimeEvent, }; @@ -21,17 +19,15 @@ parameter_types! { } pub struct LocationToCrossAccountId; -impl staging_xcm_executor::traits::ConvertLocation - for LocationToCrossAccountId -{ - fn convert_location(location: &MultiLocation) -> Option { +impl staging_xcm_executor::traits::ConvertLocation for LocationToCrossAccountId { + fn convert_location(location: &MultiLocation) -> Option { LocationToAccountId::convert_location(location) - .map(ConfigCrossAccountId::from_sub) + .map(CrossAccountId::from_sub) .or_else(|| { let eth_address = AccountKey20Aliases::::convert_location(location)?; - Some(ConfigCrossAccountId::from_eth(eth_address)) + Some(CrossAccountId::from_eth(eth_address)) }) } } diff --git a/runtime/common/config/substrate.rs b/runtime/common/config/substrate.rs index 1977555f8c..9ca33be329 100644 --- a/runtime/common/config/substrate.rs +++ b/runtime/common/config/substrate.rs @@ -34,7 +34,7 @@ use frame_system::{ use pallet_transaction_payment::{ConstFeeMultiplier, Multiplier}; use sp_arithmetic::traits::One; use sp_runtime::{ - traits::{AccountIdLookup, BlakeTwo256, IdentityLookup}, + traits::{AccountIdLookup, IdentityLookup}, Perbill, Percent, Permill, }; use sp_std::vec; @@ -96,7 +96,7 @@ impl frame_system::Config for Runtime { /// The type for hashing blocks and tries. type Hash = Hash; /// The hashing algorithm used. - type Hashing = BlakeTwo256; + type Hashing = Hashing; /// The index type for storing how many extrinsics an account has signed. type Nonce = Nonce; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. diff --git a/runtime/common/instance.rs b/runtime/common/instance.rs deleted file mode 100644 index 2df06bcd14..0000000000 --- a/runtime/common/instance.rs +++ /dev/null @@ -1,7 +0,0 @@ -use up_common::types::opaque::RuntimeInstance; - -use crate::{runtime_common::config::ethereum::CrossAccountId, Runtime}; - -impl RuntimeInstance for Runtime { - type CrossAccountId = CrossAccountId; -} diff --git a/runtime/common/mod.rs b/runtime/common/mod.rs index 2c9793dd9a..73acb42885 100644 --- a/runtime/common/mod.rs +++ b/runtime/common/mod.rs @@ -19,7 +19,6 @@ pub mod construct_runtime; pub mod dispatch; pub mod ethereum; pub mod identity; -pub mod instance; pub mod maintenance; pub mod runtime_apis; diff --git a/runtime/common/runtime_apis.rs b/runtime/common/runtime_apis.rs index 6997e4f1fe..0d517b7a59 100644 --- a/runtime/common/runtime_apis.rs +++ b/runtime/common/runtime_apis.rs @@ -57,8 +57,8 @@ macro_rules! impl_common_runtime_apis { use runtime_common::{ sponsoring::{SponsorshipPredict, UniqueSponsorshipPredict}, dispatch::CollectionDispatch, - config::ethereum::CrossAccountId, }; + use up_common::types::CrossAccountId; use up_data_structs::*; impl_runtime_apis! {