mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 08:11:03 +00:00
Add Transaction Fee RPC to Statemint/Statemine (#559)
* add payment rpc to parachains * connect payment rpc to parachains clients * fix the rumtime_api bound/ add separate start node implementation for shell * use cumulus/parachain specific primitives * Update polkadot-parachains/src/rpc.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * rename txpool dependency * fix the package name * move parachain primitives to separate module * Refactor Shared Primitves for Payment Info (#577) * rename to parachains-common * refactor shared opaque * remove primitives * Update service.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -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<rococo_parachain_runtime::GenesisConfig, Extensions>;
|
||||
pub type ChainSpec =
|
||||
sc_service::GenericChainSpec<rococo_parachain_runtime::GenesisConfig, Extensions>;
|
||||
|
||||
/// Specialized `ChainSpec` for the shell parachain runtime.
|
||||
pub type ShellChainSpec = sc_service::GenericChainSpec<shell_runtime::GenesisConfig, Extensions>;
|
||||
@@ -56,7 +57,8 @@ impl Extensions {
|
||||
type AccountPublic = <Signature as Verify>::Signer;
|
||||
|
||||
/// Helper function to generate an account ID from seed
|
||||
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId where
|
||||
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
|
||||
where
|
||||
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
|
||||
{
|
||||
AccountPublic::from(get_from_seed::<TPublic>(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<statemint_runtime::GenesisConfig, Extensions>;
|
||||
pub type StatemineChainSpec = sc_service::GenericChainSpec<statemine_runtime::GenesisConfig, Extensions>;
|
||||
pub type WestmintChainSpec = sc_service::GenericChainSpec<westmint_runtime::GenesisConfig, Extensions>;
|
||||
pub type StatemintChainSpec =
|
||||
sc_service::GenericChainSpec<statemint_runtime::GenesisConfig, Extensions>;
|
||||
pub type StatemineChainSpec =
|
||||
sc_service::GenericChainSpec<statemine_runtime::GenesisConfig, Extensions>;
|
||||
pub type WestmintChainSpec =
|
||||
sc_service::GenericChainSpec<westmint_runtime::GenesisConfig, Extensions>;
|
||||
|
||||
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::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed("Alice"),
|
||||
)
|
||||
],
|
||||
vec![(
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed("Alice"),
|
||||
)],
|
||||
vec![
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
@@ -295,14 +298,15 @@ pub fn statemint_local_config(id: ParaId) -> StatemintChainSpec {
|
||||
move || {
|
||||
statemint_genesis(
|
||||
// initial collators.
|
||||
vec![(
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed("Alice")
|
||||
),
|
||||
(
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_collator_keys_from_seed("Bob")
|
||||
),
|
||||
vec![
|
||||
(
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed("Alice"),
|
||||
),
|
||||
(
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_collator_keys_from_seed("Bob"),
|
||||
),
|
||||
],
|
||||
vec![
|
||||
get_account_id_from_seed::<sr25519::Public>("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::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed("Alice"),
|
||||
)
|
||||
],
|
||||
vec![(
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed("Alice"),
|
||||
)],
|
||||
vec![
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
@@ -426,14 +434,15 @@ pub fn statemine_local_config(id: ParaId) -> StatemineChainSpec {
|
||||
move || {
|
||||
statemine_genesis(
|
||||
// initial collators.
|
||||
vec![(
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed("Alice")
|
||||
),
|
||||
(
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_collator_keys_from_seed("Bob")
|
||||
),
|
||||
vec![
|
||||
(
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed("Alice"),
|
||||
),
|
||||
(
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_collator_keys_from_seed("Bob"),
|
||||
),
|
||||
],
|
||||
vec![
|
||||
get_account_id_from_seed::<sr25519::Public>("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::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed("Alice"),
|
||||
)
|
||||
],
|
||||
vec![(
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed("Alice"),
|
||||
)],
|
||||
vec![
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
@@ -602,14 +624,15 @@ pub fn westmint_local_config(id: ParaId) -> WestmintChainSpec {
|
||||
move || {
|
||||
westmint_genesis(
|
||||
// initial collators.
|
||||
vec![(
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed("Alice")
|
||||
),
|
||||
(
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_collator_keys_from_seed("Bob")
|
||||
),
|
||||
vec![
|
||||
(
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed("Alice"),
|
||||
),
|
||||
(
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_collator_keys_from_seed("Bob"),
|
||||
),
|
||||
],
|
||||
vec![
|
||||
get_account_id_from_seed::<sr25519::Public>("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.
|
||||
|
||||
@@ -24,6 +24,7 @@ mod chain_spec;
|
||||
mod service;
|
||||
mod cli;
|
||||
mod command;
|
||||
mod rpc;
|
||||
|
||||
fn main() -> sc_cli::Result<()> {
|
||||
command::run()
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
// Copyright 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Parachain-specific RPCs implementation.
|
||||
|
||||
#![warn(missing_docs)]
|
||||
|
||||
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 parachains_common::{AccountId, Balance, Block, Index as Nonce};
|
||||
|
||||
/// A type representing all RPC extensions.
|
||||
pub type RpcExtension = jsonrpc_core::IoHandler<sc_rpc::Metadata>;
|
||||
|
||||
/// Full client dependencies
|
||||
pub struct FullDeps<C, P> {
|
||||
/// The client instance to use.
|
||||
pub client: Arc<C>,
|
||||
/// Transaction pool instance.
|
||||
pub pool: Arc<P>,
|
||||
/// Whether to deny unsafe calls
|
||||
pub deny_unsafe: DenyUnsafe,
|
||||
}
|
||||
|
||||
/// Instantiate all RPC extensions.
|
||||
pub fn create_full<C, P>(deps: FullDeps<C, P>) -> RpcExtension
|
||||
where
|
||||
C: ProvideRuntimeApi<Block>
|
||||
+ HeaderBackend<Block>
|
||||
+ AuxStore
|
||||
+ HeaderMetadata<Block, Error = BlockChainError>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
C::Api: frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
|
||||
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
|
||||
C::Api: BlockBuilder<Block>,
|
||||
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
|
||||
}
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use cumulus_client_consensus_aura::{
|
||||
build_aura_consensus, BuildAuraConsensusParams, SlotProportion,
|
||||
};
|
||||
@@ -29,6 +28,9 @@ use cumulus_primitives_core::{
|
||||
ParaId,
|
||||
};
|
||||
|
||||
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;
|
||||
use sc_client_api::ExecutorProvider;
|
||||
@@ -37,6 +39,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,13 +54,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<BlockNumber, sp_runtime::traits::BlakeTwo256>;
|
||||
pub type Block = sp_runtime::generic::Block<Header, sp_runtime::OpaqueExtrinsic>;
|
||||
type Hash = sp_core::H256;
|
||||
|
||||
// Native executor instance.
|
||||
native_executor_instance!(
|
||||
pub RococoParachainRuntimeExecutor,
|
||||
@@ -193,11 +189,11 @@ where
|
||||
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<RuntimeApi, Executor, RB, BIQ, BIC>(
|
||||
async fn start_shell_node_impl<RuntimeApi, Executor, RB, BIQ, BIC>(
|
||||
parachain_config: Configuration,
|
||||
polkadot_config: Configuration,
|
||||
id: ParaId,
|
||||
@@ -358,6 +354,185 @@ where
|
||||
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<RuntimeApi, Executor, RB, BIQ, BIC>(
|
||||
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<TFullClient<Block, RuntimeApi, Executor>>)>
|
||||
where
|
||||
RuntimeApi: ConstructRuntimeApi<Block, TFullClient<Block, RuntimeApi, Executor>>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
|
||||
+ sp_api::Metadata<Block>
|
||||
+ sp_session::SessionKeys<Block>
|
||||
+ sp_api::ApiExt<
|
||||
Block,
|
||||
StateBackend = sc_client_api::StateBackendFor<TFullBackend<Block>, Block>,
|
||||
> + sp_offchain::OffchainWorkerApi<Block>
|
||||
+ sp_block_builder::BlockBuilder<Block>
|
||||
+ cumulus_primitives_core::CollectCollationInfo<Block>
|
||||
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
|
||||
+ frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
|
||||
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>,
|
||||
Executor: sc_executor::NativeExecutionDispatch + 'static,
|
||||
RB: Fn(
|
||||
Arc<TFullClient<Block, RuntimeApi, Executor>>,
|
||||
) -> Result<jsonrpc_core::IoHandler<sc_rpc::Metadata>, sc_service::Error>
|
||||
+ Send
|
||||
+ 'static,
|
||||
BIQ: FnOnce(
|
||||
Arc<TFullClient<Block, RuntimeApi, Executor>>,
|
||||
&Configuration,
|
||||
Option<TelemetryHandle>,
|
||||
&TaskManager,
|
||||
) -> Result<
|
||||
sc_consensus::DefaultImportQueue<Block, TFullClient<Block, RuntimeApi, Executor>>,
|
||||
sc_service::Error,
|
||||
> + 'static,
|
||||
BIC: FnOnce(
|
||||
Arc<TFullClient<Block, RuntimeApi, Executor>>,
|
||||
Option<&Registry>,
|
||||
Option<TelemetryHandle>,
|
||||
&TaskManager,
|
||||
&polkadot_service::NewFull<polkadot_service::Client>,
|
||||
Arc<sc_transaction_pool::FullPool<Block, TFullClient<Block, RuntimeApi, Executor>>>,
|
||||
Arc<NetworkService<Block, Hash>>,
|
||||
SyncCryptoStorePtr,
|
||||
bool,
|
||||
) -> Result<Box<dyn ParachainConsensus<Block>>, 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::<RuntimeApi, Executor, BIQ>(¶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, _| {
|
||||
let deps = rpc::FullDeps {
|
||||
client: client.clone(),
|
||||
pool: transaction_pool.clone(),
|
||||
deny_unsafe,
|
||||
};
|
||||
|
||||
Ok(rpc::create_full(deps))
|
||||
})
|
||||
};
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
/// Build the import queue for the rococo parachain runtime.
|
||||
pub fn rococo_parachain_build_import_queue(
|
||||
client: Arc<
|
||||
@@ -532,7 +707,7 @@ pub async fn start_shell_node(
|
||||
TaskManager,
|
||||
Arc<TFullClient<Block, shell_runtime::RuntimeApi, ShellRuntimeExecutor>>,
|
||||
)> {
|
||||
start_node_impl::<shell_runtime::RuntimeApi, ShellRuntimeExecutor, _, _, _>(
|
||||
start_shell_node_impl::<shell_runtime::RuntimeApi, ShellRuntimeExecutor, _, _, _>(
|
||||
parachain_config,
|
||||
polkadot_config,
|
||||
id,
|
||||
@@ -801,7 +976,9 @@ where
|
||||
> + sp_offchain::OffchainWorkerApi<Block>
|
||||
+ sp_block_builder::BlockBuilder<Block>
|
||||
+ cumulus_primitives_core::CollectCollationInfo<Block>
|
||||
+ sp_consensus_aura::AuraApi<Block, AuraId>,
|
||||
+ sp_consensus_aura::AuraApi<Block, AuraId>
|
||||
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
|
||||
+ frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
|
||||
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>,
|
||||
Executor: sc_executor::NativeExecutionDispatch + 'static,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user