mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Merge remote-tracking branch 'origin' into gav-xcm-v3
This commit is contained in:
@@ -9,18 +9,14 @@ repository = "https://github.com/paritytech/cumulus/"
|
||||
edition = "2021"
|
||||
build = "build.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "parachain-collator"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "3.1", features = ["derive"] }
|
||||
clap = { version = "3.2.16", features = ["derive"] }
|
||||
derive_more = "0.99.2"
|
||||
log = "0.4.16"
|
||||
log = "0.4.17"
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0" }
|
||||
serde = { version = "1.0.132", features = ["derive"] }
|
||||
serde = { version = "1.0.143", features = ["derive"] }
|
||||
hex-literal = "0.3.4"
|
||||
jsonrpc-core = "18.0.0"
|
||||
jsonrpsee = { version = "0.15.1", features = ["server"] }
|
||||
|
||||
# Local
|
||||
parachain-template-runtime = { path = "../runtime" }
|
||||
@@ -37,9 +33,11 @@ sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "mast
|
||||
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master", features = ["wasmtime"] }
|
||||
sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-network-common = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-rpc-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master", features = ["wasmtime"] }
|
||||
sc-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-telemetry = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
@@ -1,18 +1,8 @@
|
||||
use crate::chain_spec;
|
||||
use clap::Parser;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Sub-commands supported by the collator.
|
||||
#[derive(Debug, clap::Subcommand)]
|
||||
pub enum Subcommand {
|
||||
/// Export the genesis state of the parachain.
|
||||
#[clap(name = "export-genesis-state")]
|
||||
ExportGenesisState(ExportGenesisStateCommand),
|
||||
|
||||
/// Export the genesis wasm of the parachain.
|
||||
#[clap(name = "export-genesis-wasm")]
|
||||
ExportGenesisWasm(ExportGenesisWasmCommand),
|
||||
|
||||
/// Build a chain specification.
|
||||
BuildSpec(sc_cli::BuildSpecCmd),
|
||||
|
||||
@@ -28,11 +18,17 @@ pub enum Subcommand {
|
||||
/// Import blocks.
|
||||
ImportBlocks(sc_cli::ImportBlocksCmd),
|
||||
|
||||
/// Revert the chain to a previous state.
|
||||
Revert(sc_cli::RevertCmd),
|
||||
|
||||
/// Remove the whole chain.
|
||||
PurgeChain(cumulus_client_cli::PurgeChainCmd),
|
||||
|
||||
/// Revert the chain to a previous state.
|
||||
Revert(sc_cli::RevertCmd),
|
||||
/// Export the genesis state of the parachain.
|
||||
ExportGenesisState(cumulus_client_cli::ExportGenesisStateCommand),
|
||||
|
||||
/// Export the genesis wasm of the parachain.
|
||||
ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand),
|
||||
|
||||
/// Sub-commands concerned with benchmarking.
|
||||
/// The pallet benchmarking moved to the `pallet` sub-command.
|
||||
@@ -43,39 +39,7 @@ pub enum Subcommand {
|
||||
TryRuntime(try_runtime_cli::TryRuntimeCmd),
|
||||
}
|
||||
|
||||
/// Command for exporting the genesis state of the parachain
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct ExportGenesisStateCommand {
|
||||
/// Output file name or stdout if unspecified.
|
||||
#[clap(parse(from_os_str))]
|
||||
pub output: Option<PathBuf>,
|
||||
|
||||
/// Write output in binary. Default is to write in hex.
|
||||
#[clap(short, long)]
|
||||
pub raw: bool,
|
||||
|
||||
/// The name of the chain for that the genesis state should be exported.
|
||||
#[clap(long)]
|
||||
pub chain: Option<String>,
|
||||
}
|
||||
|
||||
/// Command for exporting the genesis wasm file.
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct ExportGenesisWasmCommand {
|
||||
/// Output file name or stdout if unspecified.
|
||||
#[clap(parse(from_os_str))]
|
||||
pub output: Option<PathBuf>,
|
||||
|
||||
/// Write output in binary. Default is to write in hex.
|
||||
#[clap(short, long)]
|
||||
pub raw: bool,
|
||||
|
||||
/// The name of the chain for that the genesis wasm file should be exported.
|
||||
#[clap(long)]
|
||||
pub chain: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[derive(Debug, clap::Parser)]
|
||||
#[clap(
|
||||
propagate_version = true,
|
||||
args_conflicts_with_subcommands = true,
|
||||
@@ -88,6 +52,16 @@ pub struct Cli {
|
||||
#[clap(flatten)]
|
||||
pub run: cumulus_client_cli::RunCmd,
|
||||
|
||||
/// Disable automatic hardware benchmarks.
|
||||
///
|
||||
/// By default these benchmarks are automatically ran at startup and measure
|
||||
/// the CPU speed, the memory bandwidth and the disk speed.
|
||||
///
|
||||
/// The results are then printed out in the logs, and also sent as part of
|
||||
/// telemetry, if telemetry is enabled.
|
||||
#[clap(long)]
|
||||
pub no_hardware_benchmarks: bool,
|
||||
|
||||
/// Relay chain arguments
|
||||
#[clap(raw = true)]
|
||||
pub relay_chain_args: Vec<String>,
|
||||
@@ -111,9 +85,9 @@ impl RelayChainCli {
|
||||
para_config: &sc_service::Configuration,
|
||||
relay_chain_args: impl Iterator<Item = &'a String>,
|
||||
) -> Self {
|
||||
let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec);
|
||||
let extension = crate::chain_spec::Extensions::try_get(&*para_config.chain_spec);
|
||||
let chain_id = extension.map(|e| e.relay_chain.clone());
|
||||
let base_path = para_config.base_path.as_ref().map(|x| x.path().join("polkadot"));
|
||||
Self { base_path, chain_id, base: polkadot_cli::RunCmd::parse_from(relay_chain_args) }
|
||||
Self { base_path, chain_id, base: clap::Parser::parse_from(relay_chain_args) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
use crate::{
|
||||
chain_spec,
|
||||
cli::{Cli, RelayChainCli, Subcommand},
|
||||
service::{new_partial, TemplateRuntimeExecutor},
|
||||
};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use codec::Encode;
|
||||
use cumulus_client_service::genesis::generate_genesis_block;
|
||||
use cumulus_client_cli::generate_genesis_block;
|
||||
use cumulus_primitives_core::ParaId;
|
||||
use frame_benchmarking_cli::BenchmarkCmd;
|
||||
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
|
||||
use log::info;
|
||||
use parachain_template_runtime::{Block, RuntimeApi};
|
||||
use polkadot_parachain::primitives::AccountIdConversion;
|
||||
use sc_cli::{
|
||||
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,
|
||||
NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,
|
||||
@@ -19,10 +15,15 @@ use sc_service::{
|
||||
TaskManager,
|
||||
};
|
||||
use sp_core::hexdisplay::HexDisplay;
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use std::{io::Write, net::SocketAddr};
|
||||
use sp_runtime::traits::{AccountIdConversion, Block as BlockT};
|
||||
|
||||
fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
|
||||
use crate::{
|
||||
chain_spec,
|
||||
cli::{Cli, RelayChainCli, Subcommand},
|
||||
service::{new_partial, TemplateRuntimeExecutor},
|
||||
};
|
||||
|
||||
fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
|
||||
Ok(match id {
|
||||
"dev" => Box::new(chain_spec::development_config()),
|
||||
"template-rococo" => Box::new(chain_spec::local_testnet_config()),
|
||||
@@ -41,11 +42,13 @@ impl SubstrateCli for Cli {
|
||||
}
|
||||
|
||||
fn description() -> String {
|
||||
"Parachain Collator Template\n\nThe command-line arguments provided first will be \
|
||||
format!(
|
||||
"Parachain Collator Template\n\nThe command-line arguments provided first will be \
|
||||
passed to the parachain node, while the arguments provided after -- will be passed \
|
||||
to the relay chain node.\n\n\
|
||||
parachain-collator <parachain-args> -- <relay-chain-args>"
|
||||
.into()
|
||||
{} <parachain-args> -- <relay-chain-args>",
|
||||
Self::executable_name()
|
||||
)
|
||||
}
|
||||
|
||||
fn author() -> String {
|
||||
@@ -79,11 +82,13 @@ impl SubstrateCli for RelayChainCli {
|
||||
}
|
||||
|
||||
fn description() -> String {
|
||||
"Parachain Collator Template\n\nThe command-line arguments provided first will be \
|
||||
format!(
|
||||
"Parachain Collator Template\n\nThe command-line arguments provided first will be \
|
||||
passed to the parachain node, while the arguments provided after -- will be passed \
|
||||
to the relay chain node.\n\n\
|
||||
parachain-collator <parachain-args> -- <relay-chain-args>"
|
||||
.into()
|
||||
{} <parachain-args> -- <relay-chain-args>",
|
||||
Self::executable_name()
|
||||
)
|
||||
}
|
||||
|
||||
fn author() -> String {
|
||||
@@ -107,16 +112,6 @@ impl SubstrateCli for RelayChainCli {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::borrowed_box)]
|
||||
fn extract_genesis_wasm(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<Vec<u8>> {
|
||||
let mut storage = chain_spec.build_storage()?;
|
||||
|
||||
storage
|
||||
.top
|
||||
.remove(sp_core::storage::well_known_keys::CODE)
|
||||
.ok_or_else(|| "Could not find wasm file in genesis state!".into())
|
||||
}
|
||||
|
||||
macro_rules! construct_async_run {
|
||||
(|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{
|
||||
let runner = $cli.create_runner($cmd)?;
|
||||
@@ -164,6 +159,11 @@ pub fn run() -> Result<()> {
|
||||
Ok(cmd.run(components.client, components.import_queue))
|
||||
})
|
||||
},
|
||||
Some(Subcommand::Revert(cmd)) => {
|
||||
construct_async_run!(|components, cli, cmd, config| {
|
||||
Ok(cmd.run(components.client, components.backend, None))
|
||||
})
|
||||
},
|
||||
Some(Subcommand::PurgeChain(cmd)) => {
|
||||
let runner = cli.create_runner(cmd)?;
|
||||
|
||||
@@ -183,54 +183,20 @@ pub fn run() -> Result<()> {
|
||||
cmd.run(config, polkadot_config)
|
||||
})
|
||||
},
|
||||
Some(Subcommand::Revert(cmd)) => {
|
||||
construct_async_run!(|components, cli, cmd, config| {
|
||||
Ok(cmd.run(components.client, components.backend, None))
|
||||
Some(Subcommand::ExportGenesisState(cmd)) => {
|
||||
let runner = cli.create_runner(cmd)?;
|
||||
runner.sync_run(|_config| {
|
||||
let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
|
||||
let state_version = Cli::native_runtime_version(&spec).state_version();
|
||||
cmd.run::<Block>(&*spec, state_version)
|
||||
})
|
||||
},
|
||||
Some(Subcommand::ExportGenesisState(params)) => {
|
||||
let mut builder = sc_cli::LoggerBuilder::new("");
|
||||
builder.with_profiling(sc_tracing::TracingReceiver::Log, "");
|
||||
let _ = builder.init();
|
||||
|
||||
let spec = load_spec(¶ms.chain.clone().unwrap_or_default())?;
|
||||
let state_version = Cli::native_runtime_version(&spec).state_version();
|
||||
let block: Block = generate_genesis_block(&spec, state_version)?;
|
||||
let raw_header = block.header().encode();
|
||||
let output_buf = if params.raw {
|
||||
raw_header
|
||||
} else {
|
||||
format!("0x{:?}", HexDisplay::from(&block.header().encode())).into_bytes()
|
||||
};
|
||||
|
||||
if let Some(output) = ¶ms.output {
|
||||
std::fs::write(output, output_buf)?;
|
||||
} else {
|
||||
std::io::stdout().write_all(&output_buf)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
},
|
||||
Some(Subcommand::ExportGenesisWasm(params)) => {
|
||||
let mut builder = sc_cli::LoggerBuilder::new("");
|
||||
builder.with_profiling(sc_tracing::TracingReceiver::Log, "");
|
||||
let _ = builder.init();
|
||||
|
||||
let raw_wasm_blob =
|
||||
extract_genesis_wasm(&cli.load_spec(¶ms.chain.clone().unwrap_or_default())?)?;
|
||||
let output_buf = if params.raw {
|
||||
raw_wasm_blob
|
||||
} else {
|
||||
format!("0x{:?}", HexDisplay::from(&raw_wasm_blob)).into_bytes()
|
||||
};
|
||||
|
||||
if let Some(output) = ¶ms.output {
|
||||
std::fs::write(output, output_buf)?;
|
||||
} else {
|
||||
std::io::stdout().write_all(&output_buf)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
Some(Subcommand::ExportGenesisWasm(cmd)) => {
|
||||
let runner = cli.create_runner(cmd)?;
|
||||
runner.sync_run(|_config| {
|
||||
let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
|
||||
cmd.run(&*spec)
|
||||
})
|
||||
},
|
||||
Some(Subcommand::Benchmark(cmd)) => {
|
||||
let runner = cli.create_runner(cmd)?;
|
||||
@@ -261,7 +227,12 @@ pub fn run() -> Result<()> {
|
||||
|
||||
cmd.run(config, partials.client.clone(), db, storage)
|
||||
}),
|
||||
BenchmarkCmd::Overhead(_) => Err("Unsupported benchmarking command".into()),
|
||||
BenchmarkCmd::Machine(cmd) =>
|
||||
runner.sync_run(|config| cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone())),
|
||||
// NOTE: this allows the Client to leniently implement
|
||||
// new benchmark commands without requiring a companion MR.
|
||||
#[allow(unreachable_patterns)]
|
||||
_ => Err("Benchmarking sub-command unsupported".into()),
|
||||
}
|
||||
},
|
||||
Some(Subcommand::TryRuntime(cmd)) => {
|
||||
@@ -286,6 +257,15 @@ pub fn run() -> Result<()> {
|
||||
let collator_options = cli.run.collator_options();
|
||||
|
||||
runner.run_node_until_exit(|config| async move {
|
||||
let hwbench = if !cli.no_hardware_benchmarks {
|
||||
config.database.path().map(|database_path| {
|
||||
let _ = std::fs::create_dir_all(&database_path);
|
||||
sc_sysinfo::gather_hwbench(Some(database_path))
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let para_id = chain_spec::Extensions::try_get(&*config.chain_spec)
|
||||
.map(|e| e.para_id)
|
||||
.ok_or_else(|| "Could not find parachain ID in chain-spec.")?;
|
||||
@@ -298,11 +278,10 @@ pub fn run() -> Result<()> {
|
||||
let id = ParaId::from(para_id);
|
||||
|
||||
let parachain_account =
|
||||
AccountIdConversion::<polkadot_primitives::v2::AccountId>::into_account(&id);
|
||||
AccountIdConversion::<polkadot_primitives::v2::AccountId>::into_account_truncating(&id);
|
||||
|
||||
let state_version =
|
||||
RelayChainCli::native_runtime_version(&config.chain_spec).state_version();
|
||||
let block: Block = generate_genesis_block(&config.chain_spec, state_version)
|
||||
let state_version = Cli::native_runtime_version(&config.chain_spec).state_version();
|
||||
let block: Block = generate_genesis_block(&*config.chain_spec, state_version)
|
||||
.map_err(|e| format!("{:?}", e))?;
|
||||
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
|
||||
|
||||
@@ -316,10 +295,16 @@ pub fn run() -> Result<()> {
|
||||
info!("Parachain genesis state: {}", genesis_state);
|
||||
info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" });
|
||||
|
||||
crate::service::start_parachain_node(config, polkadot_config, collator_options, id)
|
||||
.await
|
||||
.map(|r| r.0)
|
||||
.map_err(Into::into)
|
||||
crate::service::start_parachain_node(
|
||||
config,
|
||||
polkadot_config,
|
||||
collator_options,
|
||||
id,
|
||||
hwbench,
|
||||
)
|
||||
.await
|
||||
.map(|r| r.0)
|
||||
.map_err(Into::into)
|
||||
})
|
||||
},
|
||||
}
|
||||
@@ -410,8 +395,8 @@ impl CliConfiguration<Self> for RelayChainCli {
|
||||
self.base.base.role(is_dev)
|
||||
}
|
||||
|
||||
fn transaction_pool(&self) -> Result<sc_service::config::TransactionPoolOptions> {
|
||||
self.base.base.transaction_pool()
|
||||
fn transaction_pool(&self, is_dev: bool) -> Result<sc_service::config::TransactionPoolOptions> {
|
||||
self.base.base.transaction_pool(is_dev)
|
||||
}
|
||||
|
||||
fn state_cache_child_ratio(&self) -> Result<Option<usize>> {
|
||||
|
||||
@@ -17,7 +17,7 @@ use sp_block_builder::BlockBuilder;
|
||||
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
|
||||
|
||||
/// A type representing all RPC extensions.
|
||||
pub type RpcExtension = jsonrpc_core::IoHandler<sc_rpc::Metadata>;
|
||||
pub type RpcExtension = jsonrpsee::RpcModule<()>;
|
||||
|
||||
/// Full client dependencies
|
||||
pub struct FullDeps<C, P> {
|
||||
@@ -30,7 +30,9 @@ pub struct FullDeps<C, P> {
|
||||
}
|
||||
|
||||
/// Instantiate all RPC extensions.
|
||||
pub fn create_full<C, P>(deps: FullDeps<C, P>) -> RpcExtension
|
||||
pub fn create_full<C, P>(
|
||||
deps: FullDeps<C, P>,
|
||||
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
|
||||
where
|
||||
C: ProvideRuntimeApi<Block>
|
||||
+ HeaderBackend<Block>
|
||||
@@ -44,14 +46,13 @@ where
|
||||
C::Api: BlockBuilder<Block>,
|
||||
P: TransactionPool + Sync + Send + 'static,
|
||||
{
|
||||
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
|
||||
use substrate_frame_rpc_system::{FullSystem, SystemApi};
|
||||
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
|
||||
use substrate_frame_rpc_system::{System, SystemApiServer};
|
||||
|
||||
let mut io = jsonrpc_core::IoHandler::default();
|
||||
let mut module = RpcExtension::new(());
|
||||
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)));
|
||||
|
||||
io
|
||||
module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
|
||||
module.merge(TransactionPayment::new(client).into_rpc())?;
|
||||
Ok(module)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
// std
|
||||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
// rpc
|
||||
use jsonrpsee::RpcModule;
|
||||
|
||||
use cumulus_client_cli::CollatorOptions;
|
||||
// Local Runtime Types
|
||||
use parachain_template_runtime::{
|
||||
@@ -19,13 +22,14 @@ use cumulus_client_service::{
|
||||
use cumulus_primitives_core::ParaId;
|
||||
use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain;
|
||||
use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult};
|
||||
use cumulus_relay_chain_rpc_interface::RelayChainRPCInterface;
|
||||
use cumulus_relay_chain_rpc_interface::{create_client_and_start_worker, RelayChainRpcInterface};
|
||||
|
||||
// Substrate Imports
|
||||
use sc_client_api::ExecutorProvider;
|
||||
use sc_executor::NativeElseWasmExecutor;
|
||||
use sc_network::NetworkService;
|
||||
use sc_service::{Configuration, PartialComponents, Role, TFullBackend, TFullClient, TaskManager};
|
||||
use sc_network_common::service::NetworkBlock;
|
||||
use sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager};
|
||||
use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};
|
||||
use sp_api::ConstructRuntimeApi;
|
||||
use sp_keystore::SyncCryptoStorePtr;
|
||||
@@ -170,15 +174,19 @@ async fn build_relay_chain_interface(
|
||||
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
|
||||
task_manager: &mut TaskManager,
|
||||
collator_options: CollatorOptions,
|
||||
hwbench: Option<sc_sysinfo::HwBench>,
|
||||
) -> RelayChainResult<(Arc<(dyn RelayChainInterface + 'static)>, Option<CollatorPair>)> {
|
||||
match collator_options.relay_chain_rpc_url {
|
||||
Some(relay_chain_url) =>
|
||||
Ok((Arc::new(RelayChainRPCInterface::new(relay_chain_url).await?) as Arc<_>, None)),
|
||||
Some(relay_chain_url) => {
|
||||
let client = create_client_and_start_worker(relay_chain_url, task_manager).await?;
|
||||
Ok((Arc::new(RelayChainRpcInterface::new(client)) as Arc<_>, None))
|
||||
},
|
||||
None => build_inprocess_relay_chain(
|
||||
polkadot_config,
|
||||
parachain_config,
|
||||
telemetry_worker_handle,
|
||||
task_manager,
|
||||
hwbench,
|
||||
),
|
||||
}
|
||||
}
|
||||
@@ -195,6 +203,7 @@ async fn start_node_impl<RuntimeApi, Executor, RB, BIQ, BIC>(
|
||||
_rpc_ext_builder: RB,
|
||||
build_import_queue: BIQ,
|
||||
build_consensus: BIC,
|
||||
hwbench: Option<sc_sysinfo::HwBench>,
|
||||
) -> sc_service::error::Result<(
|
||||
TaskManager,
|
||||
Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>>,
|
||||
@@ -219,7 +228,7 @@ where
|
||||
Executor: sc_executor::NativeExecutionDispatch + 'static,
|
||||
RB: Fn(
|
||||
Arc<TFullClient<Block, RuntimeApi, Executor>>,
|
||||
) -> Result<jsonrpc_core::IoHandler<sc_rpc::Metadata>, sc_service::Error>
|
||||
) -> Result<RpcModule<()>, sc_service::Error>
|
||||
+ Send
|
||||
+ 'static,
|
||||
BIQ: FnOnce(
|
||||
@@ -251,10 +260,6 @@ where
|
||||
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)?;
|
||||
@@ -270,6 +275,7 @@ where
|
||||
telemetry_worker_handle,
|
||||
&mut task_manager,
|
||||
collator_options.clone(),
|
||||
hwbench.clone(),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| match e {
|
||||
@@ -297,7 +303,7 @@ where
|
||||
warp_sync: None,
|
||||
})?;
|
||||
|
||||
let rpc_extensions_builder = {
|
||||
let rpc_builder = {
|
||||
let client = client.clone();
|
||||
let transaction_pool = transaction_pool.clone();
|
||||
|
||||
@@ -308,12 +314,12 @@ where
|
||||
deny_unsafe,
|
||||
};
|
||||
|
||||
Ok(crate::rpc::create_full(deps))
|
||||
crate::rpc::create_full(deps).map_err(Into::into)
|
||||
})
|
||||
};
|
||||
|
||||
sc_service::spawn_tasks(sc_service::SpawnTasksParams {
|
||||
rpc_extensions_builder,
|
||||
rpc_builder,
|
||||
client: client.clone(),
|
||||
transaction_pool: transaction_pool.clone(),
|
||||
task_manager: &mut task_manager,
|
||||
@@ -325,6 +331,19 @@ where
|
||||
telemetry: telemetry.as_mut(),
|
||||
})?;
|
||||
|
||||
if let Some(hwbench) = hwbench {
|
||||
sc_sysinfo::print_hwbench(&hwbench);
|
||||
|
||||
if let Some(ref mut telemetry) = telemetry {
|
||||
let telemetry_handle = telemetry.handle();
|
||||
task_manager.spawn_handle().spawn(
|
||||
"telemetry_hwbench",
|
||||
None,
|
||||
sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let announce_block = {
|
||||
let network = network.clone();
|
||||
Arc::new(move |hash, data| network.announce_block(hash, data))
|
||||
@@ -434,6 +453,7 @@ pub async fn start_parachain_node(
|
||||
polkadot_config: Configuration,
|
||||
collator_options: CollatorOptions,
|
||||
id: ParaId,
|
||||
hwbench: Option<sc_sysinfo::HwBench>,
|
||||
) -> sc_service::error::Result<(
|
||||
TaskManager,
|
||||
Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<TemplateRuntimeExecutor>>>,
|
||||
@@ -443,7 +463,7 @@ pub async fn start_parachain_node(
|
||||
polkadot_config,
|
||||
collator_options,
|
||||
id,
|
||||
|_| Ok(Default::default()),
|
||||
|_| Ok(RpcModule::new(())),
|
||||
parachain_build_import_queue,
|
||||
|client,
|
||||
prometheus_registry,
|
||||
@@ -508,6 +528,7 @@ pub async fn start_parachain_node(
|
||||
},
|
||||
))
|
||||
},
|
||||
hwbench,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
},
|
||||
"parachains": [
|
||||
{
|
||||
"bin": "../target/release/parachain-collator",
|
||||
"bin": "../target/release/polkadot-parachain",
|
||||
"id": "200",
|
||||
"balance": "1000000000000000000000",
|
||||
"nodes": [
|
||||
|
||||
@@ -17,10 +17,10 @@ substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", bran
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
|
||||
hex-literal = { version = "0.3.4", optional = true }
|
||||
log = { version = "0.4.16", default-features = false }
|
||||
log = { version = "0.4.17", default-features = false }
|
||||
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
|
||||
serde = { version = "1.0.132", optional = true, features = ["derive"] }
|
||||
smallvec = "1.6.1"
|
||||
serde = { version = "1.0.143", optional = true, features = ["derive"] }
|
||||
smallvec = "1.9.0"
|
||||
|
||||
# Local
|
||||
pallet-template = { path = "../pallets/template", default-features = false }
|
||||
@@ -73,7 +73,7 @@ cumulus-primitives-core = { path = "../../primitives/core", default-features = f
|
||||
cumulus-primitives-timestamp = { path = "../../primitives/timestamp", default-features = false }
|
||||
cumulus-primitives-utility = { path = "../../primitives/utility", default-features = false }
|
||||
pallet-collator-selection = { path = "../../pallets/collator-selection", default-features = false }
|
||||
parachain-info = { path = "../../polkadot-parachains/pallets/parachain-info", default-features = false }
|
||||
parachain-info = { path = "../../parachains/pallets/parachain-info", default-features = false }
|
||||
|
||||
[features]
|
||||
default = [
|
||||
|
||||
@@ -9,6 +9,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
mod weights;
|
||||
pub mod xcm_config;
|
||||
|
||||
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
|
||||
use smallvec::smallvec;
|
||||
use sp_api::impl_runtime_apis;
|
||||
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
|
||||
@@ -353,6 +354,7 @@ parameter_types! {
|
||||
}
|
||||
|
||||
impl pallet_transaction_payment::Config for Runtime {
|
||||
type Event = Event;
|
||||
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
|
||||
type WeightToFee = WeightToFee;
|
||||
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
|
||||
@@ -369,11 +371,12 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
|
||||
type Event = Event;
|
||||
type OnSystemEvent = ();
|
||||
type SelfParaId = parachain_info::Pallet<Runtime>;
|
||||
type OutboundXcmpMessageSource = XcmpQueue;
|
||||
type DmpMessageHandler = DmpQueue;
|
||||
type ReservedDmpWeight = ReservedDmpWeight;
|
||||
type OutboundXcmpMessageSource = XcmpQueue;
|
||||
type XcmpMessageHandler = XcmpQueue;
|
||||
type ReservedXcmpWeight = ReservedXcmpWeight;
|
||||
type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases;
|
||||
}
|
||||
|
||||
impl parachain_info::Config for Runtime {}
|
||||
@@ -474,7 +477,7 @@ construct_runtime!(
|
||||
|
||||
// Monetary stuff.
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 10,
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 11,
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>} = 11,
|
||||
|
||||
// Collator support. The order of these 4 are important and shall not change.
|
||||
Authorship: pallet_authorship::{Pallet, Call, Storage} = 20,
|
||||
|
||||
@@ -2,8 +2,9 @@ use super::{
|
||||
AccountId, Balances, Call, Event, Origin, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime,
|
||||
WeightToFee, XcmpQueue,
|
||||
};
|
||||
use core::marker::PhantomData;
|
||||
use frame_support::{
|
||||
match_types, parameter_types,
|
||||
log, match_types, parameter_types,
|
||||
traits::{ConstU32, Everything, Nothing},
|
||||
weights::Weight,
|
||||
};
|
||||
@@ -18,7 +19,7 @@ use xcm_builder::{
|
||||
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
|
||||
UsingComponents,
|
||||
};
|
||||
use xcm_executor::XcmExecutor;
|
||||
use xcm_executor::{traits::ShouldExecute, XcmExecutor};
|
||||
|
||||
parameter_types! {
|
||||
pub const RelayLocation: MultiLocation = MultiLocation::parent();
|
||||
@@ -88,12 +89,79 @@ match_types! {
|
||||
};
|
||||
}
|
||||
|
||||
pub type Barrier = (
|
||||
TakeWeightCredit,
|
||||
AllowTopLevelPaidExecutionFrom<Everything>,
|
||||
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
|
||||
// ^^^ Parent and its exec plurality get free execution
|
||||
);
|
||||
//TODO: move DenyThenTry to polkadot's xcm module.
|
||||
/// Deny executing the xcm message if it matches any of the Deny filter regardless of anything else.
|
||||
/// If it passes the Deny, and matches one of the Allow cases then it is let through.
|
||||
pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)
|
||||
where
|
||||
Deny: ShouldExecute,
|
||||
Allow: ShouldExecute;
|
||||
|
||||
impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>
|
||||
where
|
||||
Deny: ShouldExecute,
|
||||
Allow: ShouldExecute,
|
||||
{
|
||||
fn should_execute<Call>(
|
||||
origin: &MultiLocation,
|
||||
message: &mut Xcm<Call>,
|
||||
max_weight: Weight,
|
||||
weight_credit: &mut Weight,
|
||||
) -> Result<(), ()> {
|
||||
Deny::should_execute(origin, message, max_weight, weight_credit)?;
|
||||
Allow::should_execute(origin, message, max_weight, weight_credit)
|
||||
}
|
||||
}
|
||||
|
||||
// See issue #5233
|
||||
pub struct DenyReserveTransferToRelayChain;
|
||||
impl ShouldExecute for DenyReserveTransferToRelayChain {
|
||||
fn should_execute<Call>(
|
||||
origin: &MultiLocation,
|
||||
message: &mut Xcm<Call>,
|
||||
_max_weight: Weight,
|
||||
_weight_credit: &mut Weight,
|
||||
) -> Result<(), ()> {
|
||||
if message.0.iter().any(|inst| {
|
||||
matches!(
|
||||
inst,
|
||||
InitiateReserveWithdraw {
|
||||
reserve: MultiLocation { parents: 1, interior: Here },
|
||||
..
|
||||
} | DepositReserveAsset { dest: MultiLocation { parents: 1, interior: Here }, .. } |
|
||||
TransferReserveAsset {
|
||||
dest: MultiLocation { parents: 1, interior: Here },
|
||||
..
|
||||
}
|
||||
)
|
||||
}) {
|
||||
return Err(()) // Deny
|
||||
}
|
||||
|
||||
// An unexpected reserve transfer has arrived from the Relay Chain. Generally, `IsReserve`
|
||||
// should not allow this, but we just log it here.
|
||||
if matches!(origin, MultiLocation { parents: 1, interior: Here }) &&
|
||||
message.0.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. }))
|
||||
{
|
||||
log::warn!(
|
||||
target: "xcm::barriers",
|
||||
"Unexpected ReserveAssetDeposited from the Relay Chain",
|
||||
);
|
||||
}
|
||||
// Permit everything else
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub type Barrier = DenyThenTry<
|
||||
DenyReserveTransferToRelayChain,
|
||||
(
|
||||
TakeWeightCredit,
|
||||
AllowTopLevelPaidExecutionFrom<Everything>,
|
||||
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
|
||||
// ^^^ Parent and its exec plurality get free execution
|
||||
),
|
||||
>;
|
||||
|
||||
pub struct XcmConfig;
|
||||
impl xcm_executor::Config for XcmConfig {
|
||||
|
||||
Reference in New Issue
Block a user