From 87be10dca01baf1ea8e661596b283d1ddbfea3a4 Mon Sep 17 00:00:00 2001 From: hamidra Date: Tue, 3 Aug 2021 16:10:04 -0700 Subject: [PATCH 01/10] add payment rpc to parachains --- polkadot-parachains/src/rpc.rs | 79 ++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 polkadot-parachains/src/rpc.rs diff --git a/polkadot-parachains/src/rpc.rs b/polkadot-parachains/src/rpc.rs new file mode 100644 index 00000000000..f7f4da6a592 --- /dev/null +++ b/polkadot-parachains/src/rpc.rs @@ -0,0 +1,79 @@ +// Copyright 2019-2021 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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 Cumulus. If not, see . + +//! Parachain-specific RPCs implementation. + +#![warn(missing_docs)] + +use std::sync::Arc; + +use polkadot_primitives::v1::{AccountId, Balance, Block, Hash, Nonce}; +use sc_client_api::AuxStore; +pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor}; +use sp_api::ProvideRuntimeApi; +use sp_block_builder::BlockBuilder; +use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; +use txpool_api::TransactionPool; + +/// A type representing all RPC extensions. +pub type RpcExtension = jsonrpc_core::IoHandler; + +/// Full client dependencies +pub struct FullDeps { + /// The client instance to use. + pub client: Arc, + /// Transaction pool instance. + pub pool: Arc

, + /// Whether to deny unsafe calls + pub deny_unsafe: DenyUnsafe, +} + +/// Instantiate all RPC extensions. +pub fn create_full(deps: FullDeps) -> RpcExtension +where + C: ProvideRuntimeApi + + HeaderBackend + + AuxStore + + HeaderMetadata + + Send + + Sync + + 'static, + C::Api: frame_rpc_system::AccountNonceApi, + C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, + C::Api: BlockBuilder, + P: TransactionPool + Sync + Send + 'static, +{ + use frame_rpc_system::{FullSystem, SystemApi}; + use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi}; + + let mut io = jsonrpc_core::IoHandler::default(); + let FullDeps { + client, + pool, + deny_unsafe, + } = deps; + + io.extend_with(SystemApi::to_delegate(FullSystem::new( + client.clone(), + pool, + deny_unsafe, + ))); + io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new( + client.clone(), + ))); + + io +} From f12278db70bfb1c792ae7e5a6a2b5ce5a6712b00 Mon Sep 17 00:00:00 2001 From: hamidra Date: Tue, 3 Aug 2021 16:12:01 -0700 Subject: [PATCH 02/10] connect payment rpc to parachains clients --- Cargo.lock | 3 +++ polkadot-parachains/Cargo.toml | 3 +++ polkadot-parachains/src/main.rs | 1 + polkadot-parachains/src/service.rs | 37 +++++++++++++++++++++++++----- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bfb37834c2e..ca7127079df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6681,6 +6681,7 @@ dependencies = [ "jsonrpc-core", "log", "nix", + "pallet-transaction-payment-rpc", "parity-scale-codec", "parking_lot 0.10.2", "polkadot-cli", @@ -6702,6 +6703,7 @@ dependencies = [ "sc-telemetry", "sc-tracing", "sc-transaction-pool", + "sc-transaction-pool-api", "serde", "shell-runtime", "sp-api", @@ -6723,6 +6725,7 @@ dependencies = [ "statemint-runtime", "structopt", "substrate-build-script-utils", + "substrate-frame-rpc-system", "substrate-prometheus-endpoint", "tempfile", "tokio 0.2.24", diff --git a/polkadot-parachains/Cargo.toml b/polkadot-parachains/Cargo.toml index fc142b46a89..dee9098ee09 100644 --- a/polkadot-parachains/Cargo.toml +++ b/polkadot-parachains/Cargo.toml @@ -64,6 +64,9 @@ substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate # RPC related dependencies jsonrpc-core = "15.1.0" +txpool-api = { package = "sc-transaction-pool-api", git = "https://github.com/paritytech/substrate", branch = "master" } +frame-rpc-system = { package = "substrate-frame-rpc-system", git = "https://github.com/paritytech/substrate", branch = "master" } +pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } # Cumulus dependencies cumulus-client-cli = { path = "../client/cli" } diff --git a/polkadot-parachains/src/main.rs b/polkadot-parachains/src/main.rs index 7d02fd46489..d114d2f5f2c 100644 --- a/polkadot-parachains/src/main.rs +++ b/polkadot-parachains/src/main.rs @@ -24,6 +24,7 @@ mod chain_spec; mod service; mod cli; mod command; +mod rpc; fn main() -> sc_cli::Result<()> { command::run() diff --git a/polkadot-parachains/src/service.rs b/polkadot-parachains/src/service.rs index 517a925caf9..3c99dd07169 100644 --- a/polkadot-parachains/src/service.rs +++ b/polkadot-parachains/src/service.rs @@ -29,6 +29,7 @@ use cumulus_primitives_core::{ ParaId, }; +use crate::rpc as parachain_rpc; use cumulus_client_consensus_relay_chain::Verifier as RelayChainVerifier; use futures::lock::Mutex; use sc_client_api::ExecutorProvider; @@ -37,6 +38,7 @@ use sc_consensus::{ BlockImportParams, }; use sc_executor::native_executor_instance; +pub use sc_executor::NativeExecutor; use sc_network::NetworkService; use sc_service::{Configuration, PartialComponents, Role, TFullBackend, TFullClient, TaskManager}; use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; @@ -51,7 +53,6 @@ use sp_runtime::{ use std::sync::Arc; use substrate_prometheus_endpoint::Registry; -pub use sc_executor::NativeExecutor; type BlockNumber = u32; type Header = sp_runtime::generic::Header; @@ -110,7 +111,14 @@ pub fn new_partial( (), sc_consensus::DefaultImportQueue>, sc_transaction_pool::FullPool>, - (Option, Option), + ( + impl Fn( + parachain_rpc::DenyUnsafe, + parachain_rpc::SubscriptionTaskExecutor, + ) -> parachain_rpc::RpcExtension, + Option, + Option, + ), >, sc_service::Error, > @@ -179,6 +187,23 @@ where &task_manager, )?; + let rpc_extensions_builder = { + let client = client.clone(); + let transaction_pool = transaction_pool.clone(); + + move |deny_unsafe, + subscription_executor: parachain_rpc::SubscriptionTaskExecutor| + -> parachain_rpc::RpcExtension { + let deps = parachain_rpc::FullDeps { + client: client.clone(), + pool: transaction_pool.clone(), + deny_unsafe, + }; + + parachain_rpc::create_full(deps) + } + }; + let params = PartialComponents { backend, client, @@ -187,7 +212,7 @@ where task_manager, transaction_pool, select_chain: (), - other: (telemetry, telemetry_worker_handle), + other: (rpc_extensions_builder, telemetry, telemetry_worker_handle), }; Ok(params) @@ -234,7 +259,7 @@ where ) -> Result< sc_consensus::DefaultImportQueue>, sc_service::Error, - >, + > + 'static, BIC: FnOnce( Arc>, Option<&Registry>, @@ -254,7 +279,7 @@ where let parachain_config = prepare_node_config(parachain_config); let params = new_partial::(¶chain_config, build_import_queue)?; - let (mut telemetry, telemetry_worker_handle) = params.other; + let (rpc_extensions_builder, mut telemetry, telemetry_worker_handle) = params.other; let relay_chain_full_node = cumulus_client_service::build_polkadot_full_node(polkadot_config, telemetry_worker_handle) @@ -291,7 +316,7 @@ where })?; let rpc_client = client.clone(); - let rpc_extensions_builder = Box::new(move |_, _| rpc_ext_builder(rpc_client.clone())); + let rpc_extensions_builder = Box::new(rpc_extensions_builder); sc_service::spawn_tasks(sc_service::SpawnTasksParams { on_demand: None, From 16fef5b2870b410470b29b87b9cfd91042c77844 Mon Sep 17 00:00:00 2001 From: hamidra Date: Wed, 4 Aug 2021 19:16:41 -0700 Subject: [PATCH 03/10] fix the rumtime_api bound/ add separate start node implementation for shell --- Cargo.lock | 2 + polkadot-parachains/rococo/Cargo.toml | 2 + polkadot-parachains/rococo/src/lib.rs | 21 +++ polkadot-parachains/src/rpc.rs | 2 +- polkadot-parachains/src/service.rs | 230 +++++++++++++++++++++----- 5 files changed, 218 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ca7127079df..3359e48853c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8626,6 +8626,7 @@ dependencies = [ "frame-executive", "frame-support", "frame-system", + "frame-system-rpc-runtime-api", "hex", "hex-literal 0.3.1", "log", @@ -8636,6 +8637,7 @@ dependencies = [ "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", "pallet-xcm", "parachain-info", "parity-scale-codec", diff --git a/polkadot-parachains/rococo/Cargo.toml b/polkadot-parachains/rococo/Cargo.toml index b118ac416fa..e7312f2f2a3 100644 --- a/polkadot-parachains/rococo/Cargo.toml +++ b/polkadot-parachains/rococo/Cargo.toml @@ -28,6 +28,7 @@ sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-f frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-assets = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } @@ -35,6 +36,7 @@ pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-fe pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } # Cumulus dependencies cumulus-pallet-aura-ext = { path = "../../pallets/aura-ext", default-features = false } diff --git a/polkadot-parachains/rococo/src/lib.rs b/polkadot-parachains/rococo/src/lib.rs index 6206d89aca6..0c4bd48007c 100644 --- a/polkadot-parachains/rococo/src/lib.rs +++ b/polkadot-parachains/rococo/src/lib.rs @@ -586,6 +586,27 @@ impl_runtime_apis! { } } + impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { + fn account_nonce(account: AccountId) -> Index { + System::account_nonce(account) + } + } + + impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi for Runtime { + fn query_info( + uxt: ::Extrinsic, + len: u32, + ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo { + TransactionPayment::query_info(uxt, len) + } + fn query_fee_details( + uxt: ::Extrinsic, + len: u32, + ) -> pallet_transaction_payment::FeeDetails { + TransactionPayment::query_fee_details(uxt, len) + } + } + impl cumulus_primitives_core::CollectCollationInfo for Runtime { fn collect_collation_info() -> cumulus_primitives_core::CollationInfo { ParachainSystem::collect_collation_info() diff --git a/polkadot-parachains/src/rpc.rs b/polkadot-parachains/src/rpc.rs index f7f4da6a592..7d575a2822f 100644 --- a/polkadot-parachains/src/rpc.rs +++ b/polkadot-parachains/src/rpc.rs @@ -20,7 +20,7 @@ use std::sync::Arc; -use polkadot_primitives::v1::{AccountId, Balance, Block, Hash, Nonce}; +use polkadot_primitives::v1::{AccountId, Balance, Block, Nonce}; use sc_client_api::AuxStore; pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor}; use sp_api::ProvideRuntimeApi; diff --git a/polkadot-parachains/src/service.rs b/polkadot-parachains/src/service.rs index 3c99dd07169..65965bd7091 100644 --- a/polkadot-parachains/src/service.rs +++ b/polkadot-parachains/src/service.rs @@ -13,7 +13,6 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . - use cumulus_client_consensus_aura::{ build_aura_consensus, BuildAuraConsensusParams, SlotProportion, }; @@ -28,6 +27,7 @@ use cumulus_primitives_core::{ relay_chain::v1::{Hash as PHash, PersistedValidationData}, ParaId, }; +pub use polkadot_primitives::v1::{AccountId, Balance, Block, Hash, Nonce}; use crate::rpc as parachain_rpc; use cumulus_client_consensus_relay_chain::Verifier as RelayChainVerifier; @@ -53,11 +53,8 @@ use sp_runtime::{ use std::sync::Arc; use substrate_prometheus_endpoint::Registry; - type BlockNumber = u32; type Header = sp_runtime::generic::Header; -pub type Block = sp_runtime::generic::Block; -type Hash = sp_core::H256; // Native executor instance. native_executor_instance!( @@ -111,14 +108,7 @@ pub fn new_partial( (), sc_consensus::DefaultImportQueue>, sc_transaction_pool::FullPool>, - ( - impl Fn( - parachain_rpc::DenyUnsafe, - parachain_rpc::SubscriptionTaskExecutor, - ) -> parachain_rpc::RpcExtension, - Option, - Option, - ), + (Option, Option), >, sc_service::Error, > @@ -187,23 +177,6 @@ where &task_manager, )?; - let rpc_extensions_builder = { - let client = client.clone(); - let transaction_pool = transaction_pool.clone(); - - move |deny_unsafe, - subscription_executor: parachain_rpc::SubscriptionTaskExecutor| - -> parachain_rpc::RpcExtension { - let deps = parachain_rpc::FullDeps { - client: client.clone(), - pool: transaction_pool.clone(), - deny_unsafe, - }; - - parachain_rpc::create_full(deps) - } - }; - let params = PartialComponents { backend, client, @@ -212,17 +185,17 @@ where task_manager, transaction_pool, select_chain: (), - other: (rpc_extensions_builder, telemetry, telemetry_worker_handle), + other: (telemetry, telemetry_worker_handle), }; Ok(params) } -/// Start a node with the given parachain `Configuration` and relay chain `Configuration`. +/// Start a shell node with the given parachain `Configuration` and relay chain `Configuration`. /// -/// This is the actual implementation that is abstract over the executor and the runtime api. +/// This is the actual implementation that is abstract over the executor and the runtime api for shell nodes. #[sc_tracing::logging::prefix_logs_with("Parachain")] -async fn start_node_impl( +async fn start_shell_node_impl( parachain_config: Configuration, polkadot_config: Configuration, id: ParaId, @@ -259,7 +232,7 @@ where ) -> Result< sc_consensus::DefaultImportQueue>, sc_service::Error, - > + 'static, + >, BIC: FnOnce( Arc>, Option<&Registry>, @@ -279,7 +252,7 @@ where let parachain_config = prepare_node_config(parachain_config); let params = new_partial::(¶chain_config, build_import_queue)?; - let (rpc_extensions_builder, mut telemetry, telemetry_worker_handle) = params.other; + let (mut telemetry, telemetry_worker_handle) = params.other; let relay_chain_full_node = cumulus_client_service::build_polkadot_full_node(polkadot_config, telemetry_worker_handle) @@ -316,7 +289,186 @@ where })?; let rpc_client = client.clone(); - let rpc_extensions_builder = Box::new(rpc_extensions_builder); + let rpc_extensions_builder = Box::new(move |_, _| rpc_ext_builder(rpc_client.clone())); + + sc_service::spawn_tasks(sc_service::SpawnTasksParams { + on_demand: None, + remote_blockchain: None, + rpc_extensions_builder, + client: client.clone(), + transaction_pool: transaction_pool.clone(), + task_manager: &mut task_manager, + config: parachain_config, + keystore: params.keystore_container.sync_keystore(), + backend: backend.clone(), + network: network.clone(), + system_rpc_tx, + telemetry: telemetry.as_mut(), + })?; + + let announce_block = { + let network = network.clone(); + Arc::new(move |hash, data| network.announce_block(hash, data)) + }; + + if validator { + let parachain_consensus = build_consensus( + client.clone(), + prometheus_registry.as_ref(), + telemetry.as_ref().map(|t| t.handle()), + &task_manager, + &relay_chain_full_node, + transaction_pool, + network, + params.keystore_container.sync_keystore(), + force_authoring, + )?; + + let spawner = task_manager.spawn_handle(); + + let params = StartCollatorParams { + para_id: id, + block_status: client.clone(), + announce_block, + client: client.clone(), + task_manager: &mut task_manager, + relay_chain_full_node, + spawner, + parachain_consensus, + import_queue, + }; + + start_collator(params).await?; + } else { + let params = StartFullNodeParams { + client: client.clone(), + announce_block, + task_manager: &mut task_manager, + para_id: id, + relay_chain_full_node, + }; + + start_full_node(params)?; + } + + start_network.start_network(); + + Ok((task_manager, client)) +} + +/// Start a node with the given parachain `Configuration` and relay chain `Configuration`. +/// +/// This is the actual implementation that is abstract over the executor and the runtime api. +#[sc_tracing::logging::prefix_logs_with("Parachain")] +async fn start_node_impl( + parachain_config: Configuration, + polkadot_config: Configuration, + id: ParaId, + _rpc_ext_builder: RB, + build_import_queue: BIQ, + build_consensus: BIC, +) -> sc_service::error::Result<(TaskManager, Arc>)> +where + RuntimeApi: ConstructRuntimeApi> + + Send + + Sync + + 'static, + RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue + + sp_api::Metadata + + sp_session::SessionKeys + + sp_api::ApiExt< + Block, + StateBackend = sc_client_api::StateBackendFor, Block>, + > + sp_offchain::OffchainWorkerApi + + sp_block_builder::BlockBuilder + + cumulus_primitives_core::CollectCollationInfo + + pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi + + frame_rpc_system::AccountNonceApi, + sc_client_api::StateBackendFor, Block>: sp_api::StateBackend, + Executor: sc_executor::NativeExecutionDispatch + 'static, + RB: Fn( + Arc>, + ) -> jsonrpc_core::IoHandler + + Send + + 'static, + BIQ: FnOnce( + Arc>, + &Configuration, + Option, + &TaskManager, + ) -> Result< + sc_consensus::DefaultImportQueue>, + sc_service::Error, + > + 'static, + BIC: FnOnce( + Arc>, + Option<&Registry>, + Option, + &TaskManager, + &polkadot_service::NewFull, + Arc>>, + Arc>, + SyncCryptoStorePtr, + bool, + ) -> Result>, sc_service::Error>, +{ + if matches!(parachain_config.role, Role::Light) { + return Err("Light client not supported!".into()); + } + + let parachain_config = prepare_node_config(parachain_config); + + let params = new_partial::(¶chain_config, build_import_queue)?; + let (mut telemetry, telemetry_worker_handle) = params.other; + + let relay_chain_full_node = + cumulus_client_service::build_polkadot_full_node(polkadot_config, telemetry_worker_handle) + .map_err(|e| match e { + polkadot_service::Error::Sub(x) => x, + s => format!("{}", s).into(), + })?; + + let client = params.client.clone(); + let backend = params.backend.clone(); + let block_announce_validator = build_block_announce_validator( + relay_chain_full_node.client.clone(), + id, + Box::new(relay_chain_full_node.network.clone()), + relay_chain_full_node.backend.clone(), + ); + + let force_authoring = parachain_config.force_authoring; + let validator = parachain_config.role.is_authority(); + let prometheus_registry = parachain_config.prometheus_registry().cloned(); + let transaction_pool = params.transaction_pool.clone(); + let mut task_manager = params.task_manager; + let import_queue = cumulus_client_service::SharedImportQueue::new(params.import_queue); + let (network, system_rpc_tx, start_network) = + sc_service::build_network(sc_service::BuildNetworkParams { + config: ¶chain_config, + client: client.clone(), + transaction_pool: transaction_pool.clone(), + spawn_handle: task_manager.spawn_handle(), + import_queue: import_queue.clone(), + on_demand: None, + block_announce_validator_builder: Some(Box::new(|_| block_announce_validator)), + warp_sync: None, + })?; + + let rpc_extensions_builder = { + let client = client.clone(); + let transaction_pool = transaction_pool.clone(); + + Box::new(move |deny_unsafe, _| -> parachain_rpc::RpcExtension { + let deps = parachain_rpc::FullDeps { + client: client.clone(), + pool: transaction_pool.clone(), + deny_unsafe, + }; + + parachain_rpc::create_full(deps) + }) + }; sc_service::spawn_tasks(sc_service::SpawnTasksParams { on_demand: None, @@ -557,7 +709,7 @@ pub async fn start_shell_node( TaskManager, Arc>, )> { - start_node_impl::( + start_shell_node_impl::( parachain_config, polkadot_config, id, @@ -826,7 +978,9 @@ where > + sp_offchain::OffchainWorkerApi + sp_block_builder::BlockBuilder + cumulus_primitives_core::CollectCollationInfo - + sp_consensus_aura::AuraApi, + + sp_consensus_aura::AuraApi + + pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi + + frame_rpc_system::AccountNonceApi, sc_client_api::StateBackendFor, Block>: sp_api::StateBackend, Executor: sc_executor::NativeExecutionDispatch + 'static, { From 6fb988efc156940bc6cee104476716c39d9c946b Mon Sep 17 00:00:00 2001 From: hamidra Date: Thu, 5 Aug 2021 10:06:28 -0700 Subject: [PATCH 04/10] use cumulus/parachain specific primitives --- polkadot-parachains/src/rpc.rs | 12 +++++++++++- polkadot-parachains/src/service.rs | 10 +++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/polkadot-parachains/src/rpc.rs b/polkadot-parachains/src/rpc.rs index 7d575a2822f..f407b72d980 100644 --- a/polkadot-parachains/src/rpc.rs +++ b/polkadot-parachains/src/rpc.rs @@ -20,7 +20,6 @@ use std::sync::Arc; -use polkadot_primitives::v1::{AccountId, Balance, Block, Nonce}; use sc_client_api::AuxStore; pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor}; use sp_api::ProvideRuntimeApi; @@ -28,6 +27,17 @@ use sp_block_builder::BlockBuilder; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; use txpool_api::TransactionPool; +/// Alias to 512-bit hash when used in the context of a transaction signature on the chain. +pub type Signature = sp_runtime::MultiSignature; +/// Some way of identifying an account on the chain. We intentionally make it equivalent +/// to the public key of our transaction signing scheme. +pub type AccountId = <::Signer as sp_runtime::traits::IdentifyAccount>::AccountId; +type BlockNumber = u32; +type Header = sp_runtime::generic::Header; +pub type Block = sp_runtime::generic::Block; +type Balance = u128; +type Nonce = u32; + /// A type representing all RPC extensions. pub type RpcExtension = jsonrpc_core::IoHandler; diff --git a/polkadot-parachains/src/service.rs b/polkadot-parachains/src/service.rs index 65965bd7091..80f0491e255 100644 --- a/polkadot-parachains/src/service.rs +++ b/polkadot-parachains/src/service.rs @@ -27,7 +27,6 @@ use cumulus_primitives_core::{ relay_chain::v1::{Hash as PHash, PersistedValidationData}, ParaId, }; -pub use polkadot_primitives::v1::{AccountId, Balance, Block, Hash, Nonce}; use crate::rpc as parachain_rpc; use cumulus_client_consensus_relay_chain::Verifier as RelayChainVerifier; @@ -53,8 +52,17 @@ use sp_runtime::{ use std::sync::Arc; use substrate_prometheus_endpoint::Registry; +/// Alias to 512-bit hash when used in the context of a transaction signature on the chain. +pub type Signature = sp_runtime::MultiSignature; +/// Some way of identifying an account on the chain. We intentionally make it equivalent +/// to the public key of our transaction signing scheme. +pub type AccountId = <::Signer as sp_runtime::traits::IdentifyAccount>::AccountId; type BlockNumber = u32; type Header = sp_runtime::generic::Header; +pub type Block = sp_runtime::generic::Block; +type Hash = sp_core::H256; +type Balance = u128; +type Nonce = u32; // Native executor instance. native_executor_instance!( From c817513ce66e8220a7b098ea855f022f831292e4 Mon Sep 17 00:00:00 2001 From: hamidra Date: Thu, 5 Aug 2021 10:56:43 -0700 Subject: [PATCH 05/10] Update polkadot-parachains/src/rpc.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- polkadot-parachains/src/rpc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot-parachains/src/rpc.rs b/polkadot-parachains/src/rpc.rs index f407b72d980..34f8a36a543 100644 --- a/polkadot-parachains/src/rpc.rs +++ b/polkadot-parachains/src/rpc.rs @@ -1,4 +1,4 @@ -// Copyright 2019-2021 Parity Technologies (UK) Ltd. +// Copyright 2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify From 5c2cdc7740dc8655fba6e58fd110830118077bfa Mon Sep 17 00:00:00 2001 From: hamidra Date: Thu, 5 Aug 2021 11:07:06 -0700 Subject: [PATCH 06/10] rename txpool dependency --- polkadot-parachains/Cargo.toml | 2 +- polkadot-parachains/src/rpc.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/polkadot-parachains/Cargo.toml b/polkadot-parachains/Cargo.toml index dee9098ee09..cc2d97f4683 100644 --- a/polkadot-parachains/Cargo.toml +++ b/polkadot-parachains/Cargo.toml @@ -64,7 +64,7 @@ substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate # RPC related dependencies jsonrpc-core = "15.1.0" -txpool-api = { package = "sc-transaction-pool-api", git = "https://github.com/paritytech/substrate", branch = "master" } +sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-rpc-system = { package = "substrate-frame-rpc-system", git = "https://github.com/paritytech/substrate", branch = "master" } pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/polkadot-parachains/src/rpc.rs b/polkadot-parachains/src/rpc.rs index 34f8a36a543..b2f0a1044dc 100644 --- a/polkadot-parachains/src/rpc.rs +++ b/polkadot-parachains/src/rpc.rs @@ -25,7 +25,7 @@ pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor}; use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; -use txpool_api::TransactionPool; +use sc-transaction-pool-api::TransactionPool; /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. pub type Signature = sp_runtime::MultiSignature; From 98e7f5043a16fa76949ec0c4577762fa6451c9d2 Mon Sep 17 00:00:00 2001 From: hamidra Date: Thu, 5 Aug 2021 13:48:33 -0700 Subject: [PATCH 07/10] fix the package name --- polkadot-parachains/src/rpc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot-parachains/src/rpc.rs b/polkadot-parachains/src/rpc.rs index b2f0a1044dc..a47965dffdc 100644 --- a/polkadot-parachains/src/rpc.rs +++ b/polkadot-parachains/src/rpc.rs @@ -22,10 +22,10 @@ use std::sync::Arc; use sc_client_api::AuxStore; pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor}; +use sc_transaction_pool_api::TransactionPool; use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; -use sc-transaction-pool-api::TransactionPool; /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. pub type Signature = sp_runtime::MultiSignature; From 9d3b7247ebd3dd2f8274363adccf72bb1bdea65d Mon Sep 17 00:00:00 2001 From: hamidra Date: Mon, 9 Aug 2021 11:26:02 -0700 Subject: [PATCH 08/10] move parachain primitives to separate module --- polkadot-parachains/src/main.rs | 1 + polkadot-parachains/src/primitives.rs | 11 +++++++++++ polkadot-parachains/src/rpc.rs | 11 +---------- polkadot-parachains/src/service.rs | 22 ++++++---------------- 4 files changed, 19 insertions(+), 26 deletions(-) create mode 100644 polkadot-parachains/src/primitives.rs diff --git a/polkadot-parachains/src/main.rs b/polkadot-parachains/src/main.rs index d114d2f5f2c..febb3d4932d 100644 --- a/polkadot-parachains/src/main.rs +++ b/polkadot-parachains/src/main.rs @@ -24,6 +24,7 @@ mod chain_spec; mod service; mod cli; mod command; +mod primitives; mod rpc; fn main() -> sc_cli::Result<()> { diff --git a/polkadot-parachains/src/primitives.rs b/polkadot-parachains/src/primitives.rs new file mode 100644 index 00000000000..2693a09082c --- /dev/null +++ b/polkadot-parachains/src/primitives.rs @@ -0,0 +1,11 @@ +/// Alias to 512-bit hash when used in the context of a transaction signature on the chain. +pub type Signature = sp_runtime::MultiSignature; +/// Some way of identifying an account on the chain. We intentionally make it equivalent +/// to the public key of our transaction signing scheme. +pub type AccountId = <::Signer as sp_runtime::traits::IdentifyAccount>::AccountId; +pub type BlockNumber = u32; +pub type Header = sp_runtime::generic::Header; +pub type Block = sp_runtime::generic::Block; +pub type Hash = sp_core::H256; +pub type Balance = u128; +pub type Nonce = u32; diff --git a/polkadot-parachains/src/rpc.rs b/polkadot-parachains/src/rpc.rs index a47965dffdc..5a617c0cf14 100644 --- a/polkadot-parachains/src/rpc.rs +++ b/polkadot-parachains/src/rpc.rs @@ -27,16 +27,7 @@ use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; -/// Alias to 512-bit hash when used in the context of a transaction signature on the chain. -pub type Signature = sp_runtime::MultiSignature; -/// Some way of identifying an account on the chain. We intentionally make it equivalent -/// to the public key of our transaction signing scheme. -pub type AccountId = <::Signer as sp_runtime::traits::IdentifyAccount>::AccountId; -type BlockNumber = u32; -type Header = sp_runtime::generic::Header; -pub type Block = sp_runtime::generic::Block; -type Balance = u128; -type Nonce = u32; +use crate::primitives::{AccountId, Balance, Block, Nonce}; /// A type representing all RPC extensions. pub type RpcExtension = jsonrpc_core::IoHandler; diff --git a/polkadot-parachains/src/service.rs b/polkadot-parachains/src/service.rs index 80f0491e255..f55b9dde4f0 100644 --- a/polkadot-parachains/src/service.rs +++ b/polkadot-parachains/src/service.rs @@ -28,7 +28,9 @@ use cumulus_primitives_core::{ ParaId, }; -use crate::rpc as parachain_rpc; +pub use crate::primitives::{AccountId, Balance, Block, Hash, Header, Nonce}; +use crate::rpc; + use cumulus_client_consensus_relay_chain::Verifier as RelayChainVerifier; use futures::lock::Mutex; use sc_client_api::ExecutorProvider; @@ -52,18 +54,6 @@ use sp_runtime::{ use std::sync::Arc; use substrate_prometheus_endpoint::Registry; -/// Alias to 512-bit hash when used in the context of a transaction signature on the chain. -pub type Signature = sp_runtime::MultiSignature; -/// Some way of identifying an account on the chain. We intentionally make it equivalent -/// to the public key of our transaction signing scheme. -pub type AccountId = <::Signer as sp_runtime::traits::IdentifyAccount>::AccountId; -type BlockNumber = u32; -type Header = sp_runtime::generic::Header; -pub type Block = sp_runtime::generic::Block; -type Hash = sp_core::H256; -type Balance = u128; -type Nonce = u32; - // Native executor instance. native_executor_instance!( pub RococoParachainRuntimeExecutor, @@ -467,14 +457,14 @@ where let client = client.clone(); let transaction_pool = transaction_pool.clone(); - Box::new(move |deny_unsafe, _| -> parachain_rpc::RpcExtension { - let deps = parachain_rpc::FullDeps { + Box::new(move |deny_unsafe, _| -> rpc::RpcExtension { + let deps = rpc::FullDeps { client: client.clone(), pool: transaction_pool.clone(), deny_unsafe, }; - parachain_rpc::create_full(deps) + rpc::create_full(deps) }) }; From 069e125ed976cb14860802ee9ba7b0ebc4db66a6 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 17 Aug 2021 12:54:45 +0200 Subject: [PATCH 09/10] Refactor Shared Primitves for Payment Info (#577) * rename to parachains-common * refactor shared opaque * remove primitives --- Cargo.lock | 54 ++-- Cargo.toml | 2 +- polkadot-parachains/Cargo.toml | 2 +- .../Cargo.toml | 4 +- .../src/impls.rs | 22 +- .../src/lib.rs | 34 ++- polkadot-parachains/src/chain_spec.rs | 240 ++++++++++-------- polkadot-parachains/src/main.rs | 1 - polkadot-parachains/src/primitives.rs | 11 - polkadot-parachains/src/rpc.rs | 2 +- polkadot-parachains/src/service.rs | 2 +- polkadot-parachains/statemine/Cargo.toml | 4 +- polkadot-parachains/statemine/src/lib.rs | 44 ++-- polkadot-parachains/statemint/Cargo.toml | 4 +- polkadot-parachains/statemint/src/lib.rs | 47 ++-- polkadot-parachains/westmint/Cargo.toml | 4 +- polkadot-parachains/westmint/src/lib.rs | 49 ++-- 17 files changed, 263 insertions(+), 263 deletions(-) rename polkadot-parachains/{statemint-common => parachains-common}/Cargo.toml (96%) rename polkadot-parachains/{statemint-common => parachains-common}/src/impls.rs (94%) rename polkadot-parachains/{statemint-common => parachains-common}/src/lib.rs (76%) delete mode 100644 polkadot-parachains/src/primitives.rs diff --git a/Cargo.lock b/Cargo.lock index 3359e48853c..f71ee140f7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6114,6 +6114,29 @@ dependencies = [ "serde", ] +[[package]] +name = "parachains-common" +version = "1.0.0" +dependencies = [ + "frame-executive", + "frame-support", + "frame-system", + "node-primitives", + "pallet-authorship", + "pallet-balances", + "pallet-collator-selection", + "parity-scale-codec", + "polkadot-primitives", + "polkadot-runtime-common", + "serde", + "sp-consensus-aura", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "substrate-wasm-builder", +] + [[package]] name = "parity-db" version = "0.2.4" @@ -6682,6 +6705,7 @@ dependencies = [ "log", "nix", "pallet-transaction-payment-rpc", + "parachains-common", "parity-scale-codec", "parking_lot 0.10.2", "polkadot-cli", @@ -6721,7 +6745,6 @@ dependencies = [ "sp-timestamp", "sp-transaction-pool", "statemine-runtime", - "statemint-common", "statemint-runtime", "structopt", "substrate-build-script-utils", @@ -11119,6 +11142,7 @@ dependencies = [ "pallet-utility", "pallet-xcm", "parachain-info", + "parachains-common", "parity-scale-codec", "polkadot-parachain", "polkadot-runtime-common", @@ -11136,36 +11160,12 @@ dependencies = [ "sp-std", "sp-transaction-pool", "sp-version", - "statemint-common", "substrate-wasm-builder", "xcm", "xcm-builder", "xcm-executor", ] -[[package]] -name = "statemint-common" -version = "1.0.0" -dependencies = [ - "frame-executive", - "frame-support", - "frame-system", - "node-primitives", - "pallet-authorship", - "pallet-balances", - "pallet-collator-selection", - "parity-scale-codec", - "polkadot-primitives", - "polkadot-runtime-common", - "serde", - "sp-consensus-aura", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std", - "substrate-wasm-builder", -] - [[package]] name = "statemint-runtime" version = "1.0.0" @@ -11207,6 +11207,7 @@ dependencies = [ "pallet-utility", "pallet-xcm", "parachain-info", + "parachains-common", "parity-scale-codec", "polkadot-parachain", "polkadot-runtime-common", @@ -11224,7 +11225,6 @@ dependencies = [ "sp-std", "sp-transaction-pool", "sp-version", - "statemint-common", "substrate-wasm-builder", "xcm", "xcm-builder", @@ -12914,6 +12914,7 @@ dependencies = [ "pallet-utility", "pallet-xcm", "parachain-info", + "parachains-common", "parity-scale-codec", "polkadot-parachain", "polkadot-runtime-common", @@ -12931,7 +12932,6 @@ dependencies = [ "sp-std", "sp-transaction-pool", "sp-version", - "statemint-common", "substrate-wasm-builder", "xcm", "xcm-builder", diff --git a/Cargo.toml b/Cargo.toml index ae84d34ea5c..7917dc11817 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ members = [ "polkadot-parachains/pallets/ping", "polkadot-parachains/rococo", "polkadot-parachains/shell", - "polkadot-parachains/statemint-common", + "polkadot-parachains/parachains-common", "polkadot-parachains/statemint", "polkadot-parachains/statemine", "polkadot-parachains/westmint", diff --git a/polkadot-parachains/Cargo.toml b/polkadot-parachains/Cargo.toml index cc2d97f4683..f2f5339e9d4 100644 --- a/polkadot-parachains/Cargo.toml +++ b/polkadot-parachains/Cargo.toml @@ -28,7 +28,7 @@ shell-runtime = { path = "shell" } statemint-runtime = { path = "statemint" } statemine-runtime = { path = "statemine" } westmint-runtime = { path = "westmint" } -statemint-common = { path = "statemint-common" } +parachains-common = { path = "parachains-common" } # Substrate dependencies frame-benchmarking = { git = 'https://github.com/paritytech/substrate', branch = "master" } diff --git a/polkadot-parachains/statemint-common/Cargo.toml b/polkadot-parachains/parachains-common/Cargo.toml similarity index 96% rename from polkadot-parachains/statemint-common/Cargo.toml rename to polkadot-parachains/parachains-common/Cargo.toml index 683cb2197eb..9ab9d6c4abb 100644 --- a/polkadot-parachains/statemint-common/Cargo.toml +++ b/polkadot-parachains/parachains-common/Cargo.toml @@ -1,9 +1,9 @@ [package] -name = "statemint-common" +name = "parachains-common" version = "1.0.0" authors = ["Parity Technologies "] edition = "2018" -description = "Logic which is common to all Statemint variant runtimes" +description = "Logic which is common to all parachain runtimes" [package.metadata.docs.rs] targets = ['x86_64-unknown-linux-gnu'] diff --git a/polkadot-parachains/statemint-common/src/impls.rs b/polkadot-parachains/parachains-common/src/impls.rs similarity index 94% rename from polkadot-parachains/statemint-common/src/impls.rs rename to polkadot-parachains/parachains-common/src/impls.rs index b73f54c74e0..23ded7464f3 100644 --- a/polkadot-parachains/statemint-common/src/impls.rs +++ b/polkadot-parachains/parachains-common/src/impls.rs @@ -13,12 +13,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Auxillary struct/enums for Statemint runtime. -//! Taken from polkadot/runtime/common (at a21cd64) and adapted for Statemint. +//! Auxillary struct/enums for parachain runtimes. +//! Taken from polkadot/runtime/common (at a21cd64) and adapted for parachains. use frame_support::traits::{Currency, Imbalance, OnUnbalanced}; -pub type NegativeImbalance = as Currency<::AccountId>>::NegativeImbalance; +pub type NegativeImbalance = as Currency< + ::AccountId, +>>::NegativeImbalance; /// Logic for the author to get a portion of fees. pub struct ToStakingPot(sp_std::marker::PhantomData); @@ -32,10 +34,7 @@ where fn on_nonzero_unbalanced(amount: NegativeImbalance) { let numeric_amount = amount.peek(); let staking_pot = >::account_id(); - >::resolve_creating( - &staking_pot, - amount, - ); + >::resolve_creating(&staking_pot, amount); >::deposit_event(pallet_balances::Event::Deposit( staking_pot, numeric_amount, @@ -64,9 +63,13 @@ where #[cfg(test)] mod tests { use super::*; - use frame_support::traits::FindAuthor; - use frame_support::{parameter_types, PalletId, traits::ValidatorRegistration}; + use frame_support::{ + parameter_types, + traits::{FindAuthor, ValidatorRegistration}, + PalletId, + }; use frame_system::{limits, EnsureRoot}; + use pallet_collator_selection::IdentityCollator; use polkadot_primitives::v1::AccountId; use sp_core::H256; use sp_runtime::{ @@ -74,7 +77,6 @@ mod tests { traits::{BlakeTwo256, IdentityLookup}, Perbill, }; - use pallet_collator_selection::IdentityCollator; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; diff --git a/polkadot-parachains/statemint-common/src/lib.rs b/polkadot-parachains/parachains-common/src/lib.rs similarity index 76% rename from polkadot-parachains/statemint-common/src/lib.rs rename to polkadot-parachains/parachains-common/src/lib.rs index 8f048cde3ba..a9462f00095 100644 --- a/polkadot-parachains/statemint-common/src/lib.rs +++ b/polkadot-parachains/parachains-common/src/lib.rs @@ -16,12 +16,12 @@ #![cfg_attr(not(feature = "std"), no_std)] pub mod impls; -pub use types::*; pub use constants::*; - -/// Common types of statemint and statemine. +pub use opaque::*; +pub use types::*; +/// Common types of parachains. mod types { - use sp_runtime::traits::{Verify, IdentifyAccount, BlakeTwo256}; + use sp_runtime::traits::{IdentifyAccount, Verify}; /// An index to a block. pub type BlockNumber = u32; @@ -46,21 +46,18 @@ mod types { /// A hash of some data used by the chain. pub type Hash = sp_core::H256; - /// Block header type as expected by this runtime. - pub type Header = sp_runtime::generic::Header; - /// Digest item type. pub type DigestItem = sp_runtime::generic::DigestItem; - + // Aura consensus authority. pub type AuraId = sp_consensus_aura::sr25519::AuthorityId; } -/// Common constants of statemint and statemine +/// Common constants of parachains. mod constants { use super::types::BlockNumber; + use frame_support::weights::{constants::WEIGHT_PER_SECOND, Weight}; use sp_runtime::Perbill; - use frame_support::weights::{Weight, constants::WEIGHT_PER_SECOND}; /// This determines the average expected block time that we are targeting. Blocks will be /// produced at a minimum duration defined by `SLOT_DURATION`. `SLOT_DURATION` is picked up by /// `pallet_timestamp` which is in turn picked up by `pallet_aura` to implement `fn @@ -85,3 +82,20 @@ mod constants { /// We allow for 0.5 seconds of compute with a 6 second average block time. pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND / 2; } + +/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know +/// the specifics of the runtime. They can then be made to be agnostic over specific formats +/// of data like extrinsics, allowing for them to continue syncing the network through upgrades +/// to even the core data structures. +pub mod opaque { + use super::*; + use sp_runtime::{generic, traits::BlakeTwo256}; + + pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; + /// Opaque block header type. + pub type Header = generic::Header; + /// Opaque block type. + pub type Block = generic::Block; + /// Opaque block identifier type. + pub type BlockId = generic::BlockId; +} diff --git a/polkadot-parachains/src/chain_spec.rs b/polkadot-parachains/src/chain_spec.rs index 780d56a6426..f1cce9fedc5 100644 --- a/polkadot-parachains/src/chain_spec.rs +++ b/polkadot-parachains/src/chain_spec.rs @@ -24,7 +24,8 @@ use sp_core::{crypto::UncheckedInto, sr25519, Pair, Public}; use sp_runtime::traits::{IdentifyAccount, Verify}; /// Specialized `ChainSpec` for the normal parachain runtime. -pub type ChainSpec = sc_service::GenericChainSpec; +pub type ChainSpec = + sc_service::GenericChainSpec; /// Specialized `ChainSpec` for the shell parachain runtime. pub type ShellChainSpec = sc_service::GenericChainSpec; @@ -56,7 +57,8 @@ impl Extensions { type AccountPublic = ::Signer; /// Helper function to generate an account ID from seed -pub fn get_account_id_from_seed(seed: &str) -> AccountId where +pub fn get_account_id_from_seed(seed: &str) -> AccountId +where AccountPublic: From<::Public>, { AccountPublic::from(get_from_seed::(seed)).into_account() @@ -195,12 +197,15 @@ fn shell_testnet_genesis(parachain_id: ParaId) -> shell_runtime::GenesisConfig { } } -use statemint_common::Balance as StatemintBalance; +use parachains_common::Balance as StatemintBalance; /// Specialized `ChainSpec` for the normal parachain runtime. -pub type StatemintChainSpec = sc_service::GenericChainSpec; -pub type StatemineChainSpec = sc_service::GenericChainSpec; -pub type WestmintChainSpec = sc_service::GenericChainSpec; +pub type StatemintChainSpec = + sc_service::GenericChainSpec; +pub type StatemineChainSpec = + sc_service::GenericChainSpec; +pub type WestmintChainSpec = + sc_service::GenericChainSpec; const STATEMINT_ED: StatemintBalance = statemint_runtime::constants::currency::EXISTENTIAL_DEPOSIT; const STATEMINE_ED: StatemintBalance = statemine_runtime::constants::currency::EXISTENTIAL_DEPOSIT; @@ -223,22 +228,22 @@ pub fn get_collator_keys_from_seed(seed: &str) -> AuraId { /// Generate the session keys from individual elements. /// /// The input must be a tuple of individual keys (a single arg for now since we have just one key). -pub fn statemint_session_keys(keys: AuraId) -> statemint_runtime::opaque::SessionKeys { - statemint_runtime::opaque::SessionKeys { aura: keys } +pub fn statemint_session_keys(keys: AuraId) -> statemint_runtime::SessionKeys { + statemint_runtime::SessionKeys { aura: keys } } /// Generate the session keys from individual elements. /// /// The input must be a tuple of individual keys (a single arg for now since we have just one key). -pub fn statemine_session_keys(keys: AuraId) -> statemine_runtime::opaque::SessionKeys { - statemine_runtime::opaque::SessionKeys { aura: keys } +pub fn statemine_session_keys(keys: AuraId) -> statemine_runtime::SessionKeys { + statemine_runtime::SessionKeys { aura: keys } } /// Generate the session keys from individual elements. /// /// The input must be a tuple of individual keys (a single arg for now since we have just one key). -pub fn westmint_session_keys(keys: AuraId) -> westmint_runtime::opaque::SessionKeys { - westmint_runtime::opaque::SessionKeys { aura: keys } +pub fn westmint_session_keys(keys: AuraId) -> westmint_runtime::SessionKeys { + westmint_runtime::SessionKeys { aura: keys } } pub fn statemint_development_config(id: ParaId) -> StatemintChainSpec { @@ -255,12 +260,10 @@ pub fn statemint_development_config(id: ParaId) -> StatemintChainSpec { move || { statemint_genesis( // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice"), - ) - ], + vec![( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed("Alice"), + )], vec![ get_account_id_from_seed::("Alice"), get_account_id_from_seed::("Bob"), @@ -295,14 +298,15 @@ pub fn statemint_local_config(id: ParaId) -> StatemintChainSpec { move || { statemint_genesis( // initial collators. - vec![( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice") - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed("Bob") - ), + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed("Bob"), + ), ], vec![ get_account_id_from_seed::("Alice"), @@ -358,11 +362,17 @@ fn statemint_genesis( ..Default::default() }, session: statemint_runtime::SessionConfig { - keys: invulnerables.iter().cloned().map(|(acc, aura)| ( - acc.clone(), // account id - acc.clone(), // validator id - statemint_session_keys(aura), // session keys - )).collect() + keys: invulnerables + .iter() + .cloned() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc.clone(), // validator id + statemint_session_keys(aura), // session keys + ) + }) + .collect(), }, // no need to pass anything to aura, in fact it will panic if we do. Session will take care // of this. @@ -386,12 +396,10 @@ pub fn statemine_development_config(id: ParaId) -> StatemineChainSpec { move || { statemine_genesis( // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice"), - ) - ], + vec![( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed("Alice"), + )], vec![ get_account_id_from_seed::("Alice"), get_account_id_from_seed::("Bob"), @@ -426,14 +434,15 @@ pub fn statemine_local_config(id: ParaId) -> StatemineChainSpec { move || { statemine_genesis( // initial collators. - vec![( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice") - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed("Bob") - ), + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed("Bob"), + ), ], vec![ get_account_id_from_seed::("Alice"), @@ -477,22 +486,31 @@ pub fn statemine_config(id: ParaId) -> StatemineChainSpec { move || { statemine_genesis( // initial collators. - vec![( - hex!("50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d349730").into(), - hex!("50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d349730").unchecked_into() - ), - ( - hex!("fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a").into(), - hex!("fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a").unchecked_into() - ), - ( - hex!("38144b5398e5d0da5ec936a3af23f5a96e782f676ab19d45f29075ee92eca76a").into(), - hex!("38144b5398e5d0da5ec936a3af23f5a96e782f676ab19d45f29075ee92eca76a").unchecked_into() - ), - ( - hex!("3253947640e309120ae70fa458dcacb915e2ddd78f930f52bd3679ec63fc4415").into(), - hex!("3253947640e309120ae70fa458dcacb915e2ddd78f930f52bd3679ec63fc4415").unchecked_into() - ), + vec![ + ( + hex!("50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d349730") + .into(), + hex!("50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d349730") + .unchecked_into(), + ), + ( + hex!("fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a") + .into(), + hex!("fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a") + .unchecked_into(), + ), + ( + hex!("38144b5398e5d0da5ec936a3af23f5a96e782f676ab19d45f29075ee92eca76a") + .into(), + hex!("38144b5398e5d0da5ec936a3af23f5a96e782f676ab19d45f29075ee92eca76a") + .unchecked_into(), + ), + ( + hex!("3253947640e309120ae70fa458dcacb915e2ddd78f930f52bd3679ec63fc4415") + .into(), + hex!("3253947640e309120ae70fa458dcacb915e2ddd78f930f52bd3679ec63fc4415") + .unchecked_into(), + ), ], vec![], id, @@ -535,11 +553,17 @@ fn statemine_genesis( ..Default::default() }, session: statemine_runtime::SessionConfig { - keys: invulnerables.iter().cloned().map(|(acc, aura)| ( - acc.clone(), // account id - acc.clone(), // validator id - statemine_session_keys(aura), // session keys - )).collect() + keys: invulnerables + .iter() + .cloned() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc.clone(), // validator id + statemine_session_keys(aura), // session keys + ) + }) + .collect(), }, aura: Default::default(), aura_ext: Default::default(), @@ -561,12 +585,10 @@ pub fn westmint_development_config(id: ParaId) -> WestmintChainSpec { move || { westmint_genesis( // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice"), - ) - ], + vec![( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed("Alice"), + )], vec![ get_account_id_from_seed::("Alice"), get_account_id_from_seed::("Bob"), @@ -602,14 +624,15 @@ pub fn westmint_local_config(id: ParaId) -> WestmintChainSpec { move || { westmint_genesis( // initial collators. - vec![( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice") - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed("Bob") - ), + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed("Bob"), + ), ], vec![ get_account_id_from_seed::("Alice"), @@ -654,22 +677,31 @@ pub fn westmint_config(id: ParaId) -> WestmintChainSpec { move || { westmint_genesis( // initial collators. - vec![( - hex!("9cfd429fa002114f33c1d3e211501d62830c9868228eb3b4b8ae15a83de04325").into(), - hex!("9cfd429fa002114f33c1d3e211501d62830c9868228eb3b4b8ae15a83de04325").unchecked_into() - ), - ( - hex!("12a03fb4e7bda6c9a07ec0a11d03c24746943e054ff0bb04938970104c783876").into(), - hex!("12a03fb4e7bda6c9a07ec0a11d03c24746943e054ff0bb04938970104c783876").unchecked_into() - ), - ( - hex!("1256436307dfde969324e95b8c62cb9101f520a39435e6af0f7ac07b34e1931f").into(), - hex!("1256436307dfde969324e95b8c62cb9101f520a39435e6af0f7ac07b34e1931f").unchecked_into() - ), - ( - hex!("98102b7bca3f070f9aa19f58feed2c0a4e107d203396028ec17a47e1ed80e322").into(), - hex!("98102b7bca3f070f9aa19f58feed2c0a4e107d203396028ec17a47e1ed80e322").unchecked_into() - ), + vec![ + ( + hex!("9cfd429fa002114f33c1d3e211501d62830c9868228eb3b4b8ae15a83de04325") + .into(), + hex!("9cfd429fa002114f33c1d3e211501d62830c9868228eb3b4b8ae15a83de04325") + .unchecked_into(), + ), + ( + hex!("12a03fb4e7bda6c9a07ec0a11d03c24746943e054ff0bb04938970104c783876") + .into(), + hex!("12a03fb4e7bda6c9a07ec0a11d03c24746943e054ff0bb04938970104c783876") + .unchecked_into(), + ), + ( + hex!("1256436307dfde969324e95b8c62cb9101f520a39435e6af0f7ac07b34e1931f") + .into(), + hex!("1256436307dfde969324e95b8c62cb9101f520a39435e6af0f7ac07b34e1931f") + .unchecked_into(), + ), + ( + hex!("98102b7bca3f070f9aa19f58feed2c0a4e107d203396028ec17a47e1ed80e322") + .into(), + hex!("98102b7bca3f070f9aa19f58feed2c0a4e107d203396028ec17a47e1ed80e322") + .unchecked_into(), + ), ], vec![], // re-use the Westend sudo key @@ -716,11 +748,17 @@ fn westmint_genesis( ..Default::default() }, session: westmint_runtime::SessionConfig { - keys: invulnerables.iter().cloned().map(|(acc, aura)| ( - acc.clone(), // account id - acc.clone(), // validator id - westmint_session_keys(aura), // session keys - )).collect() + keys: invulnerables + .iter() + .cloned() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc.clone(), // validator id + westmint_session_keys(aura), // session keys + ) + }) + .collect(), }, // no need to pass anything to aura, in fact it will panic if we do. Session will take care // of this. diff --git a/polkadot-parachains/src/main.rs b/polkadot-parachains/src/main.rs index febb3d4932d..d114d2f5f2c 100644 --- a/polkadot-parachains/src/main.rs +++ b/polkadot-parachains/src/main.rs @@ -24,7 +24,6 @@ mod chain_spec; mod service; mod cli; mod command; -mod primitives; mod rpc; fn main() -> sc_cli::Result<()> { diff --git a/polkadot-parachains/src/primitives.rs b/polkadot-parachains/src/primitives.rs deleted file mode 100644 index 2693a09082c..00000000000 --- a/polkadot-parachains/src/primitives.rs +++ /dev/null @@ -1,11 +0,0 @@ -/// Alias to 512-bit hash when used in the context of a transaction signature on the chain. -pub type Signature = sp_runtime::MultiSignature; -/// Some way of identifying an account on the chain. We intentionally make it equivalent -/// to the public key of our transaction signing scheme. -pub type AccountId = <::Signer as sp_runtime::traits::IdentifyAccount>::AccountId; -pub type BlockNumber = u32; -pub type Header = sp_runtime::generic::Header; -pub type Block = sp_runtime::generic::Block; -pub type Hash = sp_core::H256; -pub type Balance = u128; -pub type Nonce = u32; diff --git a/polkadot-parachains/src/rpc.rs b/polkadot-parachains/src/rpc.rs index 5a617c0cf14..231b257061d 100644 --- a/polkadot-parachains/src/rpc.rs +++ b/polkadot-parachains/src/rpc.rs @@ -27,7 +27,7 @@ use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; -use crate::primitives::{AccountId, Balance, Block, Nonce}; +use parachains_common::{AccountId, Balance, Block, Index as Nonce}; /// A type representing all RPC extensions. pub type RpcExtension = jsonrpc_core::IoHandler; diff --git a/polkadot-parachains/src/service.rs b/polkadot-parachains/src/service.rs index f55b9dde4f0..7329c65d67f 100644 --- a/polkadot-parachains/src/service.rs +++ b/polkadot-parachains/src/service.rs @@ -28,8 +28,8 @@ use cumulus_primitives_core::{ ParaId, }; -pub use crate::primitives::{AccountId, Balance, Block, Hash, Header, Nonce}; use crate::rpc; +pub use parachains_common::{AccountId, Balance, Block, Hash, Header, Index as Nonce}; use cumulus_client_consensus_relay_chain::Verifier as RelayChainVerifier; use futures::lock::Mutex; diff --git a/polkadot-parachains/statemine/Cargo.toml b/polkadot-parachains/statemine/Cargo.toml index ac79b250f50..36218a6c89d 100644 --- a/polkadot-parachains/statemine/Cargo.toml +++ b/polkadot-parachains/statemine/Cargo.toml @@ -62,7 +62,7 @@ cumulus-pallet-xcm = { path = "../../pallets/xcm", default-features = false } cumulus-pallet-session-benchmarking = {path = "../../pallets/session-benchmarking", default-features = false, version = "3.0.0"} cumulus-ping = { path = "../pallets/ping", default-features = false } pallet-collator-selection = { path = "../../pallets/collator-selection", default-features = false } -statemint-common = { path = "../statemint-common", default-features = false } +parachains-common = { path = "../parachains-common", default-features = false } # Polkadot dependencies polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } @@ -149,5 +149,5 @@ std = [ "xcm-executor/std", "sp-consensus-aura/std", "node-primitives/std", - "statemint-common/std", + "parachains-common/std", ] diff --git a/polkadot-parachains/statemine/src/lib.rs b/polkadot-parachains/statemine/src/lib.rs index 7463b742e2d..2f00371d582 100644 --- a/polkadot-parachains/statemine/src/lib.rs +++ b/polkadot-parachains/statemine/src/lib.rs @@ -54,12 +54,13 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureOneOf, EnsureRoot, }; -use sp_runtime::Perbill; -pub use statemint_common as common; -use statemint_common::{ - impls::DealWithFees, AccountId, AuraId, Balance, BlockNumber, Hash, Header, Index, Signature, - AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, +pub use parachains_common as common; +use parachains_common::{ + impls::DealWithFees, opaque, AccountId, AuraId, Balance, BlockNumber, Hash, Header, Index, + Signature, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, + SLOT_DURATION, }; +use sp_runtime::Perbill; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; @@ -78,23 +79,9 @@ use xcm_builder::{ }; use xcm_executor::{Config, XcmExecutor}; -/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know -/// the specifics of the runtime. They can then be made to be agnostic over specific formats -/// of data like extrinsics, allowing for them to continue syncing the network through upgrades -/// to even the core data structures. -pub mod opaque { - use super::*; - pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; - /// Opaque block header type. - pub type Header = generic::Header; - /// Opaque block type. - pub type Block = generic::Block; - /// Opaque block identifier type. - pub type BlockId = generic::BlockId; - impl_opaque_keys! { - pub struct SessionKeys { - pub aura: Aura, - } +impl_opaque_keys! { + pub struct SessionKeys { + pub aura: Aura, } } @@ -145,7 +132,9 @@ parameter_types! { pub struct BaseFilter; impl Filter for BaseFilter { - fn filter(_c: &Call) -> bool { true } + fn filter(_c: &Call) -> bool { + true + } } // Configure FRAME pallets to include in runtime. @@ -615,9 +604,8 @@ impl pallet_session::Config for Runtime { type NextSessionRotation = pallet_session::PeriodicSessions; type SessionManager = CollatorSelection; // Essentially just Aura, but lets be pedantic. - type SessionHandler = - ::KeyTypeIdProviders; - type Keys = opaque::SessionKeys; + type SessionHandler = ::KeyTypeIdProviders; + type Keys = SessionKeys; type DisabledValidatorsThreshold = DisabledValidatorsThreshold; type WeightInfo = weights::pallet_session::WeightInfo; } @@ -811,13 +799,13 @@ impl_runtime_apis! { impl sp_session::SessionKeys for Runtime { fn generate_session_keys(seed: Option>) -> Vec { - opaque::SessionKeys::generate(seed) + SessionKeys::generate(seed) } fn decode_session_keys( encoded: Vec, ) -> Option, KeyTypeId)>> { - opaque::SessionKeys::decode_into_raw_public_keys(&encoded) + SessionKeys::decode_into_raw_public_keys(&encoded) } } diff --git a/polkadot-parachains/statemint/Cargo.toml b/polkadot-parachains/statemint/Cargo.toml index cb7269130b1..9027ad4ec28 100644 --- a/polkadot-parachains/statemint/Cargo.toml +++ b/polkadot-parachains/statemint/Cargo.toml @@ -62,7 +62,7 @@ cumulus-pallet-xcm = { path = "../../pallets/xcm", default-features = false } cumulus-pallet-session-benchmarking = { path = "../../pallets/session-benchmarking", default-features = false, version = "3.0.0" } cumulus-ping = { path = "../pallets/ping", default-features = false } pallet-collator-selection = { path = "../../pallets/collator-selection", default-features = false } -statemint-common = { path = "../statemint-common", default-features = false } +parachains-common = { path = "../parachains-common", default-features = false } # Polkadot dependencies polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } @@ -149,5 +149,5 @@ std = [ "xcm-executor/std", "sp-consensus-aura/std", "node-primitives/std", - "statemint-common/std", + "parachains-common/std", ] diff --git a/polkadot-parachains/statemint/src/lib.rs b/polkadot-parachains/statemint/src/lib.rs index c6696034e8c..bb1d6f580c6 100644 --- a/polkadot-parachains/statemint/src/lib.rs +++ b/polkadot-parachains/statemint/src/lib.rs @@ -54,12 +54,13 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureOneOf, EnsureRoot, }; -use sp_runtime::Perbill; -pub use statemint_common as common; -use statemint_common::{ - impls::DealWithFees, AccountId, AuraId, Balance, BlockNumber, Hash, Header, Index, Signature, - AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, +pub use parachains_common as common; +use parachains_common::{ + impls::DealWithFees, opaque, AccountId, AuraId, Balance, BlockNumber, Hash, Header, Index, + Signature, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, + SLOT_DURATION, }; +use sp_runtime::Perbill; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; @@ -78,23 +79,9 @@ use xcm_builder::{ }; use xcm_executor::{Config, XcmExecutor}; -/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know -/// the specifics of the runtime. They can then be made to be agnostic over specific formats -/// of data like extrinsics, allowing for them to continue syncing the network through upgrades -/// to even the core data structures. -pub mod opaque { - use super::*; - pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; - /// Opaque block header type. - pub type Header = generic::Header; - /// Opaque block type. - pub type Block = generic::Block; - /// Opaque block identifier type. - pub type BlockId = generic::BlockId; - impl_opaque_keys! { - pub struct SessionKeys { - pub aura: Aura, - } +impl_opaque_keys! { + pub struct SessionKeys { + pub aura: Aura, } } @@ -327,10 +314,9 @@ impl InstanceFilter for ProxyType { fn filter(&self, c: &Call) -> bool { match self { ProxyType::Any => true, - ProxyType::NonTransfer => !matches!( - c, - Call::Balances(..) | Call::Assets(..) | Call::Uniques(..) - ), + ProxyType::NonTransfer => { + !matches!(c, Call::Balances(..) | Call::Assets(..) | Call::Uniques(..)) + } ProxyType::CancelProxy => matches!( c, Call::Proxy(pallet_proxy::Call::reject_announcement(..)) @@ -583,9 +569,8 @@ impl pallet_session::Config for Runtime { type NextSessionRotation = pallet_session::PeriodicSessions; type SessionManager = CollatorSelection; // Essentially just Aura, but lets be pedantic. - type SessionHandler = - ::KeyTypeIdProviders; - type Keys = opaque::SessionKeys; + type SessionHandler = ::KeyTypeIdProviders; + type Keys = SessionKeys; type DisabledValidatorsThreshold = DisabledValidatorsThreshold; type WeightInfo = weights::pallet_session::WeightInfo; } @@ -798,13 +783,13 @@ impl_runtime_apis! { impl sp_session::SessionKeys for Runtime { fn generate_session_keys(seed: Option>) -> Vec { - opaque::SessionKeys::generate(seed) + SessionKeys::generate(seed) } fn decode_session_keys( encoded: Vec, ) -> Option, KeyTypeId)>> { - opaque::SessionKeys::decode_into_raw_public_keys(&encoded) + SessionKeys::decode_into_raw_public_keys(&encoded) } } diff --git a/polkadot-parachains/westmint/Cargo.toml b/polkadot-parachains/westmint/Cargo.toml index fdc4c5063c0..9cf94d12def 100644 --- a/polkadot-parachains/westmint/Cargo.toml +++ b/polkadot-parachains/westmint/Cargo.toml @@ -62,7 +62,7 @@ cumulus-pallet-xcm = { path = "../../pallets/xcm", default-features = false } cumulus-pallet-session-benchmarking = {path = "../../pallets/session-benchmarking", default-features = false, version = "3.0.0"} cumulus-ping = { path = "../pallets/ping", default-features = false } pallet-collator-selection = { path = "../../pallets/collator-selection", default-features = false } -statemint-common = { path = "../statemint-common", default-features = false } +parachains-common = { path = "../parachains-common", default-features = false } # Polkadot dependencies polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } @@ -149,5 +149,5 @@ std = [ "xcm-executor/std", "sp-consensus-aura/std", "node-primitives/std", - "statemint-common/std", + "parachains-common/std", ] diff --git a/polkadot-parachains/westmint/src/lib.rs b/polkadot-parachains/westmint/src/lib.rs index d67fa30d451..f67ca3643df 100644 --- a/polkadot-parachains/westmint/src/lib.rs +++ b/polkadot-parachains/westmint/src/lib.rs @@ -54,12 +54,13 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, }; -use sp_runtime::Perbill; -pub use statemint_common as common; -use statemint_common::{ - impls::DealWithFees, AccountId, AuraId, Balance, BlockNumber, Hash, Header, Index, Signature, - AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, +pub use parachains_common as common; +use parachains_common::{ + impls::DealWithFees, opaque, AccountId, AuraId, Balance, BlockNumber, Hash, Header, Index, + Signature, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, + SLOT_DURATION, }; +use sp_runtime::Perbill; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; @@ -78,23 +79,9 @@ use xcm_builder::{ }; use xcm_executor::{Config, XcmExecutor}; -/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know -/// the specifics of the runtime. They can then be made to be agnostic over specific formats -/// of data like extrinsics, allowing for them to continue syncing the network through upgrades -/// to even the core data structures. -pub mod opaque { - use super::*; - pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; - - /// Opaque block type. - pub type Block = generic::Block; - - pub type SessionHandlers = (); - - impl_opaque_keys! { - pub struct SessionKeys { - pub aura: Aura, - } +impl_opaque_keys! { + pub struct SessionKeys { + pub aura: Aura, } } @@ -233,7 +220,7 @@ impl pallet_sudo::Config for Runtime { type Call = Call; } -pub type AssetsForceOrigin = EnsureRoot; +pub type AssetsForceOrigin = EnsureRoot; parameter_types! { pub const AssetDeposit: Balance = 100 * UNITS; // 100 WND deposit to create asset @@ -326,10 +313,9 @@ impl InstanceFilter for ProxyType { fn filter(&self, c: &Call) -> bool { match self { ProxyType::Any => true, - ProxyType::NonTransfer => !matches!( - c, - Call::Balances(..) | Call::Assets(..) | Call::Uniques(..) - ), + ProxyType::NonTransfer => { + !matches!(c, Call::Balances(..) | Call::Assets(..) | Call::Uniques(..)) + } ProxyType::CancelProxy => matches!( c, Call::Proxy(pallet_proxy::Call::reject_announcement(..)) @@ -581,9 +567,8 @@ impl pallet_session::Config for Runtime { type NextSessionRotation = pallet_session::PeriodicSessions; type SessionManager = CollatorSelection; // Essentially just Aura, but lets be pedantic. - type SessionHandler = - ::KeyTypeIdProviders; - type Keys = opaque::SessionKeys; + type SessionHandler = ::KeyTypeIdProviders; + type Keys = SessionKeys; type DisabledValidatorsThreshold = DisabledValidatorsThreshold; type WeightInfo = weights::pallet_session::WeightInfo; } @@ -799,13 +784,13 @@ impl_runtime_apis! { impl sp_session::SessionKeys for Runtime { fn generate_session_keys(seed: Option>) -> Vec { - opaque::SessionKeys::generate(seed) + SessionKeys::generate(seed) } fn decode_session_keys( encoded: Vec, ) -> Option, KeyTypeId)>> { - opaque::SessionKeys::decode_into_raw_public_keys(&encoded) + SessionKeys::decode_into_raw_public_keys(&encoded) } } From 6b5aa52e8281350fc6b81e585f0065b5a10f1b22 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 17 Aug 2021 14:20:29 +0200 Subject: [PATCH 10/10] Update service.rs --- polkadot-parachains/src/service.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/polkadot-parachains/src/service.rs b/polkadot-parachains/src/service.rs index 2acd9bb63b7..8c51971002a 100644 --- a/polkadot-parachains/src/service.rs +++ b/polkadot-parachains/src/service.rs @@ -386,7 +386,7 @@ where Executor: sc_executor::NativeExecutionDispatch + 'static, RB: Fn( Arc>, - ) -> jsonrpc_core::IoHandler + ) -> Result, sc_service::Error> + Send + 'static, BIQ: FnOnce( @@ -457,14 +457,14 @@ where let client = client.clone(); let transaction_pool = transaction_pool.clone(); - Box::new(move |deny_unsafe, _| -> rpc::RpcExtension { + Box::new(move |deny_unsafe, _| { let deps = rpc::FullDeps { client: client.clone(), pool: transaction_pool.clone(), deny_unsafe, }; - rpc::create_full(deps) + Ok(rpc::create_full(deps)) }) };