diff --git a/Cargo.toml b/Cargo.toml index d17f990..0f881d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [workspace.package] authors = ["anonymous"] edition = "2021" -version = "0.41.0" +version = "0.42.0" license = "Unlicense" homepage = "https://github.com/paritytech/substrate-contracts-node" repository = "https://github.com/paritytech/substrate-contracts-node" @@ -18,120 +18,122 @@ members = [ panic = 'unwind' [workspace.dependencies] -clap = { version = "4", features = ["derive"] } -codec = { package = "parity-scale-codec", version = "3.6.9", default-features = false, features = ["derive"] } +clap = { version = "4.5.10", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = ["derive"] } futures = "0.3.30" hex-literal = { version = "0.4.1"} -jsonrpsee = { version = "0.22", features = ["server"] } -log = { version = "0.4.20", default-features = false } -serde = { version = "1.0.195", features = ["derive"] } -serde_json = "1.0.111" +jsonrpsee = { version = "0.24.3", features = ["server"] } +log = { version = "0.4.22", default-features = false } +serde = { version = "1.0.209", features = ["derive"] } +serde_json = "1.0.127" scale-info = { version = "2.11.1", default-features = false, features = ["derive"] } -smallvec = "1.11.2" -color-print = "0.3.5" +smallvec = "1.11.0" +color-print = "0.3.4" wasmtime="8.0.1" # Substrate -frame-benchmarking = { version = "32.0.0", default-features = false } -frame-benchmarking-cli = { version = "36.0.0" } -frame-executive = { version = "32.0.0", default-features = false } -frame-support = { version = "32.0.0", default-features = false } -frame-system = { version = "32.0.0", default-features = false } -frame-system-benchmarking = { version = "32.0.0", default-features = false } -frame-system-rpc-runtime-api = { version = "30.0.0", default-features = false } -frame-try-runtime = { version = "0.38.0", default-features = false } -pallet-aura = { version = "31.0.0", default-features = false } -pallet-authorship = { version = "32.0.0", default-features = false } -pallet-balances = { version = "33.0.0", default-features = false } -pallet-session = { version = "32.0.0", default-features = false } -pallet-sudo = { version = "32.0.0", default-features = false } -pallet-timestamp = { version = "31.0.0", default-features = false } -pallet-transaction-payment = { version = "32.0.0", default-features = false } -pallet-message-queue = { version = "35.0.0", default-features = false } -pallet-transaction-payment-rpc = { version = "34.0.0" } -pallet-transaction-payment-rpc-runtime-api = { version = "32.0.0", default-features = false } -sc-basic-authorship = { version = "0.38.0" } -sc-chain-spec = { version = "31.0.0" } -sc-cli = { version = "0.40.0" } -sc-client-api = { version = "32.0.0" } -sc-consensus = { version = "0.37.0" } -sc-executor = { version = "0.36.0" } -sc-network = { version = "0.38.0" } -sc-network-sync = { version = "0.37.0" } -sc-offchain = { version = "33.0.0" } -sc-rpc = { version = "33.0.0" } -sc-service = { version = "0.39.0" } -sc-sysinfo = { version = "31.0.0" } -sc-telemetry = { version = "18.0.0" } -sc-tracing = { version = "32.0.0" } -sc-transaction-pool = { version = "32.0.0" } -sc-transaction-pool-api = { version = "32.0.0" } -sp-api = { version = "30.0.0", default-features = false } -sp-keyring = { version = "35.0.0", default-features = false } -sp-block-builder = { version = "30.0.0", default-features = false } -sp-blockchain = { version = "32.0.0" } -sp-consensus-aura = { version = "0.36.0", default-features = false } -sp-core = { version = "32.0.0", default-features = false } -sp-inherents = { version = "30.0.0", default-features = false } -sp-io = { version = "34.0.0", default-features = false } -sp-keystore = { version = "0.38.0" } -sp-offchain = { version = "30.0.0", default-features = false } -sp-runtime = { version = "35.0.0", default-features = false } -sp-session = { version = "31.0.0", default-features = false } +frame-benchmarking = { version = "38.0.0", default-features = false } +frame-benchmarking-cli = { version = "43.0.0" } +frame-executive = { version = "38.0.0", default-features = false } +frame-support = { version = "38.0.0", default-features = false } +frame-support-procedural = { version = "30.0.3", default-features = false } +frame-system = { version = "38.0.0", default-features = false } +frame-system-benchmarking = { version = "38.0.0", default-features = false } +frame-system-rpc-runtime-api = { version = "34.0.0", default-features = false } +frame-try-runtime = { version = "0.44.0", default-features = false } +pallet-aura = { version = "37.0.0", default-features = false } +pallet-authorship = { version = "38.0.0", default-features = false } +pallet-balances = { version = "39.0.0", default-features = false } +pallet-session = { version = "38.0.0", default-features = false } +pallet-sudo = { version = "38.0.0", default-features = false } +pallet-timestamp = { version = "37.0.0", default-features = false } +pallet-transaction-payment = { version = "38.0.0", default-features = false } +pallet-message-queue = { version = "41.0.2", default-features = false } +pallet-transaction-payment-rpc = { version = "41.0.0" } +pallet-transaction-payment-rpc-runtime-api = { version = "38.0.0", default-features = false } +sc-basic-authorship = { version = "0.45.0" } +sc-chain-spec = { version = "38.0.0" } +sc-cli = { version = "0.47.0" } +sc-client-api = { version = "37.0.0" } +sc-consensus = { version = "0.44.0" } +sc-executor = { version = "0.40.1" } +sc-network = { version = "0.45.1" } +sc-network-sync = { version = "0.44.1" } +sc-offchain = { version = "40.0.0" } +sc-rpc = { version = "40.0.0" } +sc-service = { version = "0.46.0" } +sc-sysinfo = { version = "38.0.0" } +sc-telemetry = { version = "25.0.0" } +sc-tracing = { version = "37.0.1" } +sc-transaction-pool = { version = "37.0.0" } +sc-transaction-pool-api = { version = "37.0.0" } +sp-api = { version = "34.0.0", default-features = false } +sp-keyring = { version = "39.0.0", default-features = false } +sp-block-builder = { version = "34.0.0", default-features = false } +sp-blockchain = { version = "37.0.1" } +sp-consensus-aura = { version = "0.40.0", default-features = false } +sp-core = { version = "34.0.0", default-features = false } +sp-inherents = { version = "34.0.0", default-features = false } +sp-io = { version = "38.0.0", default-features = false } +sp-keystore = { version = "0.40.0" } +sp-offchain = { version = "34.0.0", default-features = false } +sp-runtime = { version = "39.0.1", default-features = false } +sp-session = { version = "36.0.0", default-features = false } sp-std = { version = "14.0.0", default-features = false } -sp-timestamp = { version = "30.0.0" } -sp-transaction-pool = { version = "30.0.0", default-features = false } -sp-version = { version = "33.0.0", default-features = false } -substrate-frame-rpc-system = { version = "32.0.0" } -substrate-prometheus-endpoint = { version = "0.17.0" } -substrate-wasm-builder = { version = "21.0.0" } +sp-timestamp = { version = "34.0.0" } +sp-transaction-pool = { version = "34.0.0", default-features = false } +sp-version = { version = "37.0.0", default-features = false } +substrate-frame-rpc-system = { version = "39.0.0" } +prometheus-endpoint = { version = "0.17.0", default-features = false, package = "substrate-prometheus-endpoint" } +substrate-wasm-builder = { version = "24.0.1" } substrate-build-script-utils = { version = "11.0.0" } try-runtime-cli = { version = "0.42.0" } # extra deps for running a solo node on top of a parachain -pallet-grandpa = { version = "32.0.0", default-features = false } -sc-consensus-grandpa = { version = "0.23.0", default-features = false } -sp-consensus-grandpa = { version = "17.0.0", default-features = false } -sp-genesis-builder = { version = "0.11.0", default-features = false } +pallet-grandpa = { version = "38.0.0", default-features = false } +sc-consensus-grandpa = { version = "0.30.0", default-features = false } +sp-consensus-grandpa = { version = "21.0.0", default-features = false } +sp-genesis-builder = { version = "0.15.1", default-features = false } sp-storage = { version = "21.0.0", default-features = false } -sc-consensus-aura = { version = "0.38.0", default-features = false } -sc-consensus-manual-seal = { version = "0.39.0", default-features = false } +sc-consensus-aura = { version = "0.45.0", default-features = false } +sc-consensus-manual-seal = { version = "0.46.0", default-features = false } # extra deps for setting up pallet-contracts -pallet-contracts = { version = "31.0.0", default-features = false } -pallet-insecure-randomness-collective-flip = { version = "20.0.0", default-features = false } -pallet-assets = { version = "33.0.0", default-features = false } -pallet-utility = { version = "32.0.0", default-features = false } +pallet-contracts = { version = "38.0.0", default-features = false } +pallet-insecure-randomness-collective-flip = { version = "26.0.0", default-features = false } +pallet-assets = { version = "40.0.0", default-features = false } +pallet-utility = { version = "38.0.0", default-features = false } # Polkadot -pallet-xcm = { version = "11.0.0", default-features = false } -polkadot-cli = { version = "11.0.0", features = ["rococo-native"] } -polkadot-parachain-primitives = { version = "10.0.0", default-features = false } -polkadot-primitives = { version = "11.0.0" } -polkadot-runtime-common = { version = "11.0.0", default-features = false } -xcm = { version = "11.0.0", package = "staging-xcm", default-features = false } -xcm-builder = { version = "11.0.0", package = "staging-xcm-builder", default-features = false } -xcm-executor = { version = "11.0.0", package = "staging-xcm-executor", default-features = false } +pallet-xcm = { version = "17.0.1", default-features = false } +polkadot-cli = { version = "19.0.0", default-features = false } +polkadot-parachain-primitives = { version = "14.0.0", default-features = false } +polkadot-primitives = { version = "16.0.0" } +polkadot-runtime-common = { version = "17.0.0", default-features = false } +xcm = { version = "14.2.0", package = "staging-xcm", default-features = false } +xcm-builder = { version = "17.0.1", package = "staging-xcm-builder", default-features = false } +xcm-executor = { version = "17.0.0", package = "staging-xcm-executor", default-features = false } # Cumulus -cumulus-client-cli = { version = "0.11.0" } -cumulus-client-collator = { version = "0.11.0" } -cumulus-client-consensus-proposer = { version = "0.11.0" } -cumulus-client-consensus-aura = { version = "0.11.0" } -cumulus-client-consensus-common = { version = "0.11.0" } -cumulus-client-service = { version = "0.11.0" } -cumulus-pallet-aura-ext = { version = "0.11.0", default-features = false } -cumulus-pallet-dmp-queue = { version = "0.11.0", default-features = false } -cumulus-pallet-parachain-system = { version = "0.11.0", default-features = false, features = ["parameterized-consensus-hook",] } -cumulus-pallet-session-benchmarking = { version = "13.0.0", default-features = false } -cumulus-pallet-xcm = { version = "0.11.0", default-features = false } -cumulus-pallet-xcmp-queue = { version = "0.11.0", default-features = false } -cumulus-primitives-core = { version = "0.11.0", default-features = false } -cumulus-primitives-parachain-inherent = { version = "0.11.0" } -cumulus-primitives-timestamp = { version = "0.11.0", default-features = false } -cumulus-primitives-utility = { version = "0.11.0", default-features = false } -cumulus-relay-chain-interface = { version = "0.11.0" } -pallet-collator-selection = { version = "13.0.0", default-features = false } -parachain-info = { version = "0.11.0", package = "staging-parachain-info", default-features = false } -parachains-common = { version = "11.0.0", default-features = false } +cumulus-client-cli = { version = "0.18.0" } +cumulus-client-collator = { version = "0.18.0" } +cumulus-client-consensus-proposer = { version = "0.16.0" } +cumulus-client-consensus-aura = { version = "0.18.0" } +cumulus-client-consensus-common = { version = "0.18.0" } +cumulus-client-service = { version = "0.19.0" } +cumulus-pallet-aura-ext = { version = "0.17.0", default-features = false } +cumulus-pallet-dmp-queue = { version = "0.17.0", default-features = false } +cumulus-pallet-parachain-system = { version = "0.17.1", default-features = false } +cumulus-pallet-session-benchmarking = { version = "19.0.0", default-features = false } +cumulus-pallet-xcm = { version = "0.17.0", default-features = false } +cumulus-pallet-xcmp-queue = { version = "0.17.0", default-features = false } +cumulus-primitives-aura = { version = "0.15.0", default-features = false } +cumulus-primitives-core = { version = "0.16.0", default-features = false } +cumulus-primitives-parachain-inherent = { version = "0.16.0" } +cumulus-primitives-timestamp = { version = "0.16.0", default-features = false } +cumulus-primitives-utility = { version = "0.17.0", default-features = false } +cumulus-relay-chain-interface = { version = "0.18.0" } +pallet-collator-selection = { version = "19.0.0", default-features = false } +parachain-info = { version = "0.17.0", package = "staging-parachain-info", default-features = false } +parachains-common = { version = "18.0.0", default-features = false } diff --git a/node/Cargo.toml b/node/Cargo.toml index b16edea..a3e555c 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -27,8 +27,8 @@ serde_json = { workspace = true } wasmtime = { workspace = true } # Local -contracts-parachain-runtime = { path = "../parachain-runtime", features = ["parachain"], version = "0.41.0" } -contracts-node-runtime = { path = "../runtime", version = "0.41.0" } +contracts-parachain-runtime = { path = "../parachain-runtime", features = ["parachain"], version = "0.42.0" } +contracts-node-runtime = { path = "../runtime", version = "0.42.0" } # Substrate frame-benchmarking = { workspace = true } @@ -61,7 +61,7 @@ sp-io = { workspace = true } sp-runtime = { workspace = true } sp-timestamp = { workspace = true } substrate-frame-rpc-system = { workspace = true } -substrate-prometheus-endpoint = { workspace = true } +prometheus-endpoint = { workspace = true } try-runtime-cli = { workspace = true, optional = true } # extra for running solo-chain @@ -71,7 +71,7 @@ sc-consensus-aura = { workspace = true } sc-consensus-manual-seal = { workspace = true } # Polkadot -polkadot-cli = { workspace = true } +polkadot-cli = { features = ["rococo-native"], workspace = true } polkadot-primitives = { workspace = true } xcm = { workspace = true } diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index 6ad9978..d642616 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -9,7 +9,7 @@ use sp_core::{sr25519, Pair, Public}; use sp_runtime::traits::{IdentifyAccount, Verify}; /// Specialized `ChainSpec` for the normal parachain runtime. -pub type ChainSpec = sc_service::GenericChainSpec<(), Extensions>; +pub type ChainSpec = sc_service::GenericChainSpec; /// The default XCM version to set in genesis config. const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; @@ -26,8 +26,10 @@ pub fn get_from_seed(seed: &str) -> ::Pu #[serde(deny_unknown_fields)] pub struct Extensions { /// The relay chain of the Parachain. + #[serde(alias = "relayChain", alias = "RelayChain")] pub relay_chain: String, /// The id of the Parachain. + #[serde(alias = "paraId", alias = "ParaId")] pub para_id: u32, } diff --git a/node/src/chain_spec/dev.rs b/node/src/chain_spec/dev.rs index 435ac29..f94b334 100644 --- a/node/src/chain_spec/dev.rs +++ b/node/src/chain_spec/dev.rs @@ -1,10 +1,10 @@ -use contracts_node_runtime::{AccountId, RuntimeGenesisConfig, Signature, WASM_BINARY}; +use contracts_node_runtime::{AccountId, Signature, WASM_BINARY}; use sc_service::ChainType; use sp_core::{sr25519, Pair, Public}; use sp_runtime::traits::{IdentifyAccount, Verify}; /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. -pub type ChainSpec = sc_service::GenericChainSpec; +pub type ChainSpec = sc_service::GenericChainSpec; /// Generate a crypto pair from seed. pub fn get_from_seed(seed: &str) -> ::Public { @@ -24,35 +24,31 @@ where } pub fn development_config() -> Result { - Ok(ChainSpec::builder( - WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?, - None, - ) - .with_name("Development") - .with_id("dev") - .with_protocol_id("dev") - .with_chain_type(ChainType::Development) - .with_genesis_config_patch(testnet_genesis( - // Sudo account - get_account_id_from_seed::("Alice"), - // Pre-funded accounts - vec![ + Ok(ChainSpec::builder(WASM_BINARY.expect("Development wasm not available"), Default::default()) + .with_name("Development") + .with_id("dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(testnet_genesis( + // Sudo account get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Ferdie//stash"), - ], - true, - )) - .build()) + // Pre-funded accounts + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Ferdie//stash"), + ], + true, + )) + .build()) } /// Configure initial storage state for FRAME modules. diff --git a/node/src/cli.rs b/node/src/cli.rs index 70084e6..4985ceb 100644 --- a/node/src/cli.rs +++ b/node/src/cli.rs @@ -35,11 +35,6 @@ pub enum Subcommand { /// The pallet benchmarking moved to the `pallet` sub-command. #[command(subcommand)] Benchmark(frame_benchmarking_cli::BenchmarkCmd), - - /// Try-runtime has migrated to a standalone - /// [CLI](). The subcommand exists as a stub and - /// deprecation notice. It will be removed entirely some time after Janurary 2024. - TryRuntime, } const AFTER_HELP_EXAMPLE: &str = color_print::cstr!( diff --git a/node/src/command.rs b/node/src/command.rs index 6d3ade3..ec24881 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -1,15 +1,12 @@ -use std::net::SocketAddr; - use contracts_parachain_runtime::Block; use cumulus_primitives_core::ParaId; use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE}; use log::info; use sc_cli::{ ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, - NetworkParams, Result, SharedParams, SubstrateCli, + NetworkParams, Result, RpcEndpoint, SharedParams, SubstrateCli, }; use sc_service::config::{BasePath, PrometheusConfig}; -use sp_runtime::traits::AccountIdConversion; use crate::{ chain_spec, @@ -19,7 +16,7 @@ use crate::{ fn load_spec(id: &str) -> std::result::Result, String> { Ok(match id { - "" | "dev" => Box::new(chain_spec::dev::development_config().unwrap()), + "" | "dev" => Box::new(chain_spec::dev::development_config()?), "contracts-parachain-local" => Box::new(chain_spec::local_testnet_config()), path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?), }) @@ -185,7 +182,11 @@ pub fn run() -> Result<()> { match cmd { BenchmarkCmd::Pallet(cmd) => if cfg!(feature = "runtime-benchmarks") { - runner.sync_run(|config| cmd.run::, ()>(config)) + runner.sync_run(|config| { + cmd.run_with_spec::, ()>(Some( + config.chain_spec, + )) + }) } else { Err("Benchmarking wasn't enabled when building the node. \ You can enable it with `--features runtime-benchmarks`." @@ -196,13 +197,11 @@ pub fn run() -> Result<()> { cmd.run(partials.client) }), #[cfg(not(feature = "runtime-benchmarks"))] - BenchmarkCmd::Storage(_) => - return Err(sc_cli::Error::Input( - "Compile with --features=runtime-benchmarks \ + BenchmarkCmd::Storage(_) => Err(sc_cli::Error::Input( + "Compile with --features=runtime-benchmarks \ to enable storage benchmarks." - .into(), - ) - .into()), + .into(), + )), #[cfg(feature = "runtime-benchmarks")] BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| { let partials = new_partial(&config)?; @@ -218,20 +217,26 @@ pub fn run() -> Result<()> { _ => Err("Benchmarking sub-command unsupported".into()), } }, - Some(Subcommand::TryRuntime) => Err("The `try-runtime` subcommand has been migrated to a standalone CLI (https://github.com/paritytech/try-runtime-cli). It is no longer being maintained here and will be removed entirely some time after January 2024. Please remove this subcommand from your runtime and use the standalone CLI.".into()), None => { let runner = cli.create_runner(&cli.run.normalize())?; let collator_options = cli.run.collator_options(); runner.run_node_until_exit(|config| async move { if config.chain_spec.name() == "Development" { - return dev::new_full(config, cli.finalize_delay_sec.into()).map_err(sc_cli::Error::Service); + return dev::new_full::>( + config, + cli.finalize_delay_sec.into(), + ) + .map_err(sc_cli::Error::Service); } let hwbench = (!cli.no_hardware_benchmarks) .then_some(config.database.path().map(|database_path| { let _ = std::fs::create_dir_all(database_path); - sc_sysinfo::gather_hwbench(Some(database_path)) + sc_sysinfo::gather_hwbench( + Some(database_path), + &SUBSTRATE_REFERENCE_HARDWARE, + ) })) .flatten(); @@ -246,17 +251,11 @@ pub fn run() -> Result<()> { let id = ParaId::from(para_id); - let parachain_account = - AccountIdConversion::::into_account_truncating( - &id, - ); - let tokio_handle = config.tokio_handle.clone(); let polkadot_config = SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle) .map_err(|err| format!("Relay chain argument error: {}", err))?; - info!("Parachain Account: {parachain_account}"); info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" }); crate::service::start_parachain_node( @@ -312,7 +311,7 @@ impl CliConfiguration for RelayChainCli { .or_else(|| self.base_path.clone().map(Into::into))) } - fn rpc_addr(&self, default_listen_port: u16) -> Result> { + fn rpc_addr(&self, default_listen_port: u16) -> Result>> { self.base.base.rpc_addr(default_listen_port) } @@ -324,15 +323,9 @@ impl CliConfiguration for RelayChainCli { self.base.base.prometheus_config(default_listen_port, chain_spec) } - fn init( - &self, - _support_url: &String, - _impl_version: &String, - _logger_hook: F, - _config: &sc_service::Configuration, - ) -> Result<()> + fn init(&self, _support_url: &String, _impl_version: &String, _logger_hook: F) -> Result<()> where - F: FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration), + F: FnOnce(&mut sc_cli::LoggerBuilder), { unreachable!("PolkadotCli is never initialized; qed"); } diff --git a/node/src/rpc.rs b/node/src/rpc.rs index 60aaabf..70444f3 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -9,7 +9,6 @@ use std::sync::Arc; use contracts_parachain_runtime::{opaque::Block, AccountId, Balance, Nonce}; -pub use sc_rpc::DenyUnsafe; use sc_transaction_pool_api::TransactionPool; use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder; @@ -24,8 +23,6 @@ pub struct FullDeps { pub client: Arc, /// Transaction pool instance. pub pool: Arc

, - /// Whether to deny unsafe calls - pub deny_unsafe: DenyUnsafe, } /// Instantiate all RPC extensions. @@ -48,9 +45,9 @@ where use substrate_frame_rpc_system::{System, SystemApiServer}; let mut module = RpcExtension::new(()); - let FullDeps { client, pool, deny_unsafe } = deps; + let FullDeps { client, pool } = deps; - module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?; + module.merge(System::new(client.clone(), pool).into_rpc())?; module.merge(TransactionPayment::new(client).into_rpc())?; Ok(module) } diff --git a/node/src/service.rs b/node/src/service.rs index a0e39a6..a03bb37 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -11,9 +11,9 @@ use contracts_parachain_runtime::{ opaque::{Block, Hash}, RuntimeApi, }; - // Cumulus Imports use cumulus_client_collator::service::CollatorService; +use cumulus_client_consensus_aura::collators::lookahead::{self as aura, Params as AuraParams}; use cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport; use cumulus_client_consensus_proposer::Proposer; use cumulus_client_service::{ @@ -21,21 +21,23 @@ use cumulus_client_service::{ BuildNetworkParams, CollatorSybilResistance, DARecoveryProfile, ParachainHostFunctions, StartRelayChainTasksParams, }; -use cumulus_primitives_core::{relay_chain::CollatorPair, ParaId}; +use cumulus_primitives_core::{ + relay_chain::{CollatorPair, ValidationCode}, + ParaId, +}; use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface}; // Substrate Imports use frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE; +use prometheus_endpoint::Registry; use sc_client_api::Backend; use sc_consensus::ImportQueue; use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY}; use sc_network::NetworkBlock; -use sc_network_sync::SyncingService; use sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager}; use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; use sc_transaction_pool_api::OffchainTransactionPoolFactory; use sp_keystore::KeystorePtr; -use substrate_prometheus_endpoint::Registry; type ParachainExecutor = WasmExecutor; @@ -72,22 +74,24 @@ pub fn new_partial(config: &Configuration) -> Result .transpose()?; let heap_pages = config + .executor .default_heap_pages .map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| HeapAllocStrategy::Static { extra_pages: h as _ }); let executor = ParachainExecutor::builder() - .with_execution_method(config.wasm_method) + .with_execution_method(config.executor.wasm_method) .with_onchain_heap_alloc_strategy(heap_pages) .with_offchain_heap_alloc_strategy(heap_pages) - .with_max_runtime_instances(config.max_runtime_instances) - .with_runtime_cache_size(config.runtime_cache_size) + .with_max_runtime_instances(config.executor.max_runtime_instances) + .with_runtime_cache_size(config.executor.runtime_cache_size) .build(); let (client, backend, keystore_container, task_manager) = - sc_service::new_full_parts::( + sc_service::new_full_parts_record_import::( config, telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), executor, + true, )?; let client = Arc::new(client); @@ -114,7 +118,7 @@ pub fn new_partial(config: &Configuration) -> Result config, telemetry.as_ref().map(|telemetry| telemetry.handle()), &task_manager, - )?; + ); Ok(PartialComponents { backend, @@ -128,11 +132,98 @@ pub fn new_partial(config: &Configuration) -> Result }) } +/// Build the import queue for the parachain runtime. +fn build_import_queue( + client: Arc, + block_import: ParachainBlockImport, + config: &Configuration, + telemetry: Option, + task_manager: &TaskManager, +) -> sc_consensus::DefaultImportQueue { + cumulus_client_consensus_aura::equivocation_import_queue::fully_verifying_import_queue::< + sp_consensus_aura::sr25519::AuthorityPair, + _, + _, + _, + _, + >( + client, + block_import, + move |_, _| async move { + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + Ok(timestamp) + }, + &task_manager.spawn_essential_handle(), + config.prometheus_registry(), + telemetry, + ) +} + +#[allow(clippy::too_many_arguments)] +fn start_consensus( + client: Arc, + backend: Arc, + block_import: ParachainBlockImport, + prometheus_registry: Option<&Registry>, + telemetry: Option, + task_manager: &TaskManager, + relay_chain_interface: Arc, + transaction_pool: Arc>, + keystore: KeystorePtr, + relay_chain_slot_duration: Duration, + para_id: ParaId, + collator_key: CollatorPair, + overseer_handle: OverseerHandle, + announce_block: Arc>) + Send + Sync>, +) -> Result<(), sc_service::Error> { + let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( + task_manager.spawn_handle(), + client.clone(), + transaction_pool, + prometheus_registry, + telemetry.clone(), + ); + + let proposer = Proposer::new(proposer_factory); + + let collator_service = CollatorService::new( + client.clone(), + Arc::new(task_manager.spawn_handle()), + announce_block, + client.clone(), + ); + + let params = AuraParams { + create_inherent_data_providers: move |_, ()| async move { Ok(()) }, + block_import, + para_client: client.clone(), + para_backend: backend, + relay_client: relay_chain_interface, + code_hash_provider: move |block_hash| { + client.code_at(block_hash).ok().map(|c| ValidationCode::from(c).hash()) + }, + keystore, + collator_key, + para_id, + overseer_handle, + relay_chain_slot_duration, + proposer, + collator_service, + authoring_duration: Duration::from_millis(2000), + reinitialize: false, + }; + + let fut = aura::run::( + params, + ); + task_manager.spawn_essential_handle().spawn("aura", None, fut); + + Ok(()) +} + /// 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( +pub async fn start_parachain_node( parachain_config: Configuration, polkadot_config: Configuration, collator_options: CollatorOptions, @@ -143,7 +234,12 @@ async fn start_node_impl( let params = new_partial(¶chain_config)?; let (block_import, mut telemetry, telemetry_worker_handle) = params.other; - let net_config = sc_network::config::FullNetworkConfiguration::new(¶chain_config.network); + let prometheus_registry = parachain_config.prometheus_registry().cloned(); + let net_config = sc_network::config::FullNetworkConfiguration::< + _, + _, + sc_network::NetworkWorker, + >::new(¶chain_config.network, prometheus_registry.clone()); let client = params.client.clone(); let backend = params.backend.clone(); @@ -161,10 +257,11 @@ async fn start_node_impl( .map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))?; let validator = parachain_config.role.is_authority(); - let prometheus_registry = parachain_config.prometheus_registry().cloned(); let transaction_pool = params.transaction_pool.clone(); let import_queue_service = params.import_queue.service(); + // NOTE: because we use Aura here explicitly, we can use `CollatorSybilResistance::Resistant` + // when starting the network. let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) = build_network(BuildNetworkParams { parachain_config: ¶chain_config, @@ -192,7 +289,7 @@ async fn start_node_impl( transaction_pool: Some(OffchainTransactionPoolFactory::new( transaction_pool.clone(), )), - network_provider: network.clone(), + network_provider: Arc::new(network.clone()), is_validator: parachain_config.role.is_authority(), enable_http_requests: false, custom_extensions: move |_| vec![], @@ -206,12 +303,9 @@ async fn start_node_impl( let client = client.clone(); let transaction_pool = transaction_pool.clone(); - Box::new(move |deny_unsafe, _| { - let deps = crate::rpc::FullDeps { - client: client.clone(), - pool: transaction_pool.clone(), - deny_unsafe, - }; + Box::new(move |_| { + let deps = + crate::rpc::FullDeps { client: client.clone(), pool: transaction_pool.clone() }; crate::rpc::create_full(deps).map_err(Into::into) }) @@ -224,8 +318,8 @@ async fn start_node_impl( task_manager: &mut task_manager, config: parachain_config, keystore: params.keystore_container.keystore(), - backend, - network: network.clone(), + backend: backend.clone(), + network, sync_service: sync_service.clone(), system_rpc_tx, tx_handler_controller, @@ -237,7 +331,7 @@ async fn start_node_impl( // Here you can check whether the hardware meets your chains' requirements. Putting a link // in there and swapping out the requirements for your own are probably a good idea. The // requirements for a para-chain are dictated by its relay-chain. - match SUBSTRATE_REFERENCE_HARDWARE.check_hardware(&hwbench) { + match SUBSTRATE_REFERENCE_HARDWARE.check_hardware(&hwbench, false) { Err(err) if validator => { log::warn!( "⚠️ The hardware does not meet the minimal requirements {} for role 'Authority'.", @@ -288,13 +382,13 @@ async fn start_node_impl( if validator { start_consensus( client.clone(), + backend, block_import, prometheus_registry.as_ref(), telemetry.as_ref().map(|t| t.handle()), &task_manager, - relay_chain_interface.clone(), + relay_chain_interface, transaction_pool, - sync_service.clone(), params.keystore_container.keystore(), relay_chain_slot_duration, para_id, @@ -308,114 +402,3 @@ async fn start_node_impl( Ok((task_manager, client)) } - -/// Build the import queue for the parachain runtime. -fn build_import_queue( - client: Arc, - block_import: ParachainBlockImport, - config: &Configuration, - telemetry: Option, - task_manager: &TaskManager, -) -> Result, sc_service::Error> { - let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?; - - Ok(cumulus_client_consensus_aura::equivocation_import_queue::fully_verifying_import_queue::< - sp_consensus_aura::sr25519::AuthorityPair, - _, - _, - _, - _, - >( - client, - block_import, - move |_, _| async move { - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - Ok(timestamp) - }, - slot_duration, - &task_manager.spawn_essential_handle(), - config.prometheus_registry(), - telemetry, - )) -} - -fn start_consensus( - client: Arc, - block_import: ParachainBlockImport, - prometheus_registry: Option<&Registry>, - telemetry: Option, - task_manager: &TaskManager, - relay_chain_interface: Arc, - transaction_pool: Arc>, - sync_oracle: Arc>, - keystore: KeystorePtr, - relay_chain_slot_duration: Duration, - para_id: ParaId, - collator_key: CollatorPair, - overseer_handle: OverseerHandle, - announce_block: Arc>) + Send + Sync>, -) -> Result<(), sc_service::Error> { - use cumulus_client_consensus_aura::collators::basic::{ - self as basic_aura, Params as BasicAuraParams, - }; - - // NOTE: because we use Aura here explicitly, we can use `CollatorSybilResistance::Resistant` - // when starting the network. - - let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?; - - let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( - task_manager.spawn_handle(), - client.clone(), - transaction_pool, - prometheus_registry, - telemetry.clone(), - ); - - let proposer = Proposer::new(proposer_factory); - - let collator_service = CollatorService::new( - client.clone(), - Arc::new(task_manager.spawn_handle()), - announce_block, - client.clone(), - ); - - let params = BasicAuraParams { - create_inherent_data_providers: move |_, ()| async move { Ok(()) }, - block_import, - para_client: client, - relay_client: relay_chain_interface, - sync_oracle, - keystore, - collator_key, - para_id, - overseer_handle, - slot_duration, - relay_chain_slot_duration, - proposer, - collator_service, - // Very limited proposal time. - authoring_duration: Duration::from_millis(500), - collation_request_receiver: None, - }; - - let fut = - basic_aura::run::( - params, - ); - task_manager.spawn_essential_handle().spawn("aura", None, fut); - - Ok(()) -} - -/// Start a parachain node. -pub async fn start_parachain_node( - parachain_config: Configuration, - polkadot_config: Configuration, - collator_options: CollatorOptions, - para_id: ParaId, - hwbench: Option, -) -> sc_service::error::Result<(TaskManager, Arc)> { - start_node_impl(parachain_config, polkadot_config, collator_options, para_id, hwbench).await -} diff --git a/node/src/service/dev.rs b/node/src/service/dev.rs index 1dd21b1..48d9a1f 100644 --- a/node/src/service/dev.rs +++ b/node/src/service/dev.rs @@ -3,34 +3,16 @@ use contracts_node_runtime::{self, opaque::Block, RuntimeApi}; use futures::FutureExt; use sc_client_api::Backend; -pub use sc_executor::NativeElseWasmExecutor; use sc_service::{error::Error as ServiceError, Configuration, TaskManager}; use sc_telemetry::{Telemetry, TelemetryWorker}; use sc_transaction_pool_api::OffchainTransactionPoolFactory; use std::sync::Arc; -// Our native executor instance. -pub struct ExecutorDispatch; - -impl sc_executor::NativeExecutionDispatch for ExecutorDispatch { - /// Only enable the benchmarking host functions when we actually want to benchmark. - #[cfg(feature = "runtime-benchmarks")] - type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; - /// Otherwise we only use the default Substrate host functions. - #[cfg(not(feature = "runtime-benchmarks"))] - type ExtendHostFunctions = (); - - fn dispatch(method: &str, data: &[u8]) -> Option> { - contracts_node_runtime::api::dispatch(method, data) - } - - fn native_version() -> sc_executor::NativeVersion { - contracts_node_runtime::native_version() - } -} - -pub(crate) type FullClient = - sc_service::TFullClient>; +pub(crate) type FullClient = sc_service::TFullClient< + Block, + RuntimeApi, + sc_executor::WasmExecutor, +>; type FullBackend = sc_service::TFullBackend; type FullSelectChain = sc_consensus::LongestChain; @@ -43,7 +25,7 @@ pub fn new_partial( FullSelectChain, sc_consensus::DefaultImportQueue, sc_transaction_pool::FullPool, - (Option,), + Option, >, ServiceError, > { @@ -58,7 +40,7 @@ pub fn new_partial( }) .transpose()?; - let executor = sc_service::new_native_or_wasm_executor(config); + let executor = sc_service::new_wasm_executor(&config.executor); let (client, backend, keystore_container, task_manager) = sc_service::new_full_parts::( @@ -97,11 +79,13 @@ pub fn new_partial( keystore_container, select_chain, transaction_pool, - other: (telemetry,), + other: (telemetry), }) } -pub fn new_full( +pub fn new_full< + N: sc_network::NetworkBackend::Hash>, +>( config: Configuration, finalize_delay_sec: u64, ) -> Result { @@ -113,22 +97,29 @@ pub fn new_full( keystore_container, select_chain, transaction_pool, - other: (mut telemetry,), + other: mut telemetry, } = new_partial(&config)?; - let net_config = sc_network::config::FullNetworkConfiguration::new(&config.network); + let net_config = + sc_network::config::FullNetworkConfiguration::< + Block, + ::Hash, + N, + >::new(&config.network, config.prometheus_config.as_ref().map(|cfg| cfg.registry.clone())); + let metrics = N::register_notification_metrics(config.prometheus_registry()); let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) = sc_service::build_network(sc_service::BuildNetworkParams { config: &config, - net_config, client: client.clone(), transaction_pool: transaction_pool.clone(), spawn_handle: task_manager.spawn_handle(), import_queue, + net_config, block_announce_validator_builder: None, - warp_sync_params: None, + warp_sync_config: None, block_relay: None, + metrics, })?; if config.offchain_worker.enabled { @@ -143,7 +134,7 @@ pub fn new_full( transaction_pool: Some(OffchainTransactionPoolFactory::new( transaction_pool.clone(), )), - network_provider: network.clone(), + network_provider: Arc::new(network.clone()), enable_http_requests: true, custom_extensions: |_| vec![], }) @@ -157,15 +148,14 @@ pub fn new_full( let client = client.clone(); let pool = transaction_pool.clone(); - Box::new(move |deny_unsafe, _| { - let deps = - crate::rpc::FullDeps { client: client.clone(), pool: pool.clone(), deny_unsafe }; + Box::new(move |_| { + let deps = crate::rpc::FullDeps { client: client.clone(), pool: pool.clone() }; crate::rpc::create_full(deps).map_err(Into::into) }) }; - sc_service::spawn_tasks(sc_service::SpawnTasksParams { - network: network.clone(), + let _rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams { + network, client: client.clone(), keystore: keystore_container.keystore(), task_manager: &mut task_manager, @@ -174,7 +164,7 @@ pub fn new_full( backend, system_rpc_tx, tx_handler_controller, - sync_service: sync_service.clone(), + sync_service, config, telemetry: telemetry.as_mut(), })?; diff --git a/parachain-runtime/Cargo.toml b/parachain-runtime/Cargo.toml index baca861..b6d1885 100644 --- a/parachain-runtime/Cargo.toml +++ b/parachain-runtime/Cargo.toml @@ -14,10 +14,12 @@ targets = ["x86_64-unknown-linux-gnu"] substrate-wasm-builder = {workspace = true, optional = true } [dependencies] -codec = { package = "parity-scale-codec", version = "3.6.9", default-features = false, features = ["derive"] } +codec = { features = [ + "derive", +], workspace = true } hex-literal = { version = "0.4.1", optional = true } -log = { version = "0.4.20", default-features = false } -scale-info = { version = "2.11.1", default-features = false, features = ["derive"] } +log = { version = "0.4.21", default-features = false } +scale-info = { workspace = true } smallvec = "1.11.2" # Substrate @@ -65,6 +67,7 @@ cumulus-pallet-parachain-system = { workspace = true } cumulus-pallet-session-benchmarking = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } +cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } cumulus-primitives-timestamp = { workspace = true } cumulus-primitives-utility = { workspace = true } @@ -89,6 +92,7 @@ std = [ "cumulus-pallet-parachain-system/std", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", + "cumulus-primitives-aura/std", "cumulus-primitives-core/std", "cumulus-primitives-timestamp/std", "cumulus-primitives-utility/std", diff --git a/parachain-runtime/src/lib.rs b/parachain-runtime/src/lib.rs index 4bce121..b810336 100644 --- a/parachain-runtime/src/lib.rs +++ b/parachain-runtime/src/lib.rs @@ -12,6 +12,9 @@ mod contracts_config; mod weights; mod xcm_config; +extern crate alloc; + +use alloc::vec::Vec; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use smallvec::smallvec; @@ -24,16 +27,11 @@ use sp_runtime::{ ApplyExtrinsicResult, MultiSignature, }; -use sp_std::prelude::*; -#[cfg(feature = "std")] -use sp_version::NativeVersion; -use sp_version::RuntimeVersion; - use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ - construct_runtime, derive_impl, + derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, TransformOrigin}, weights::{ @@ -50,6 +48,9 @@ use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; pub use sp_runtime::{MultiAddress, Perbill, Permill}; +#[cfg(feature = "std")] +use sp_version::NativeVersion; +use sp_version::RuntimeVersion; use xcm_config::{RelayLocation, XcmOriginToTransactDispatchOrigin}; #[cfg(any(feature = "std", test))] @@ -97,6 +98,13 @@ pub type SignedBlock = generic::SignedBlock; /// BlockId type as expected by this runtime. pub type BlockId = generic::BlockId; +type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< + Runtime, + RELAY_CHAIN_SLOT_DURATION_MILLIS, + BLOCK_PROCESSING_VELOCITY, + UNINCLUDED_SEGMENT_CAPACITY, +>; + /// The SignedExtension to the basic transaction logic. pub type SignedExtra = ( frame_system::CheckNonZeroSender, @@ -189,17 +197,20 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { state_version: 1, }; -/// 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 slot_duration()`. -/// -/// Change this to adjust the block time. -pub const MILLISECS_PER_BLOCK: u64 = 12000; - -// NOTE: Currently it is not possible to change the slot duration after the chain has started. -// Attempting to do so will brick block production. -pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; +mod block_times { + /// 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 + /// slot_duration()`. + /// + /// Change this to adjust the block time. + pub const MILLISECS_PER_BLOCK: u64 = 6000; + + // NOTE: Currently it is not possible to change the slot duration after the chain has started. + // Attempting to do so will brick block production. + pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; +} +pub use block_times::*; // Time is measured by number of blocks. pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); @@ -222,20 +233,23 @@ const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5); /// `Operational` extrinsics. const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); -/// We allow for 0.5 of a second of compute with a 12 second average block time. +/// We allow for 2 seconds of compute with a 6 second average block time. const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts( - WEIGHT_REF_TIME_PER_SECOND.saturating_div(2), + WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2), cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64, ); -/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included -/// into the relay chain. -const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1; -/// How many parachain blocks are processed by the relay chain per parent. Limits the -/// number of blocks authored per slot. -const BLOCK_PROCESSING_VELOCITY: u32 = 1; -/// Relay chain slot duration, in milliseconds. -const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000; +mod async_backing_params { + /// Maximum number of blocks simultaneously accepted by the Runtime, not yet included + /// into the relay chain. + pub(crate) const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3; + /// How many parachain blocks are processed by the relay chain per parent. Limits the + /// number of blocks authored per slot. + pub(crate) const BLOCK_PROCESSING_VELOCITY: u32 = 1; + /// Relay chain slot duration, in milliseconds. + pub(crate) const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000; +} +pub(crate) use async_backing_params::*; /// The version information used to identify this runtime when compiled natively. #[cfg(feature = "std")] @@ -347,7 +361,7 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter; + type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter; type WeightToFee = WeightToFee; type LengthToFee = ConstantMultiplier; type FeeMultiplierUpdate = SlowAdjustingFeeUpdate; @@ -377,12 +391,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ReservedXcmpWeight; type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; - type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< - Runtime, - RELAY_CHAIN_SLOT_DURATION_MILLIS, - BLOCK_PROCESSING_VELOCITY, - UNINCLUDED_SEGMENT_CAPACITY, - >; + type ConsensusHook = ConsensusHook; } impl parachain_info::Config for Runtime {} @@ -408,8 +417,8 @@ impl pallet_message_queue::Config for Runtime { // The XCMP queue pallet is only ever able to handle the `Sibling(ParaId)` origin: type QueueChangeHandler = NarrowOriginToSibling; type QueuePausedQuery = NarrowOriginToSibling; - type HeapSize = sp_core::ConstU32<{ 64 * 1024 }>; - type MaxStale = sp_core::ConstU32<8>; + type HeapSize = ConstU32<{ 64 * 1024 }>; + type MaxStale = ConstU32<8>; type ServiceWeight = MessageQueueServiceWeight; type IdleMaxServiceWeight = (); } @@ -422,7 +431,9 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type VersionWrapper = (); // Enqueue XCMP messages from siblings for later processing. type XcmpQueue = TransformOrigin; - type MaxInboundSuspended = sp_core::ConstU32<1_000>; + type MaxInboundSuspended = ConstU32<1_000>; + type MaxActiveOutboundChannels = ConstU32<128>; + type MaxPageSize = ConstU32<{ 1 << 16 }>; type ControllerOrigin = EnsureRoot; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = (); @@ -495,37 +506,69 @@ impl pallet_utility::Config for Runtime { } // Create the runtime by composing the FRAME pallets that were previously configured. -construct_runtime!( - pub struct Runtime { - // Order should match with Runtime defined in runtime/src/lib.rs - System: frame_system, - RandomnessCollectiveFlip: pallet_insecure_randomness_collective_flip, - Utility: pallet_utility, - Timestamp: pallet_timestamp, - Balances: pallet_balances, - Authorship: pallet_authorship, - TransactionPayment: pallet_transaction_payment, - Sudo: pallet_sudo, - Contracts: pallet_contracts, - Assets: pallet_assets, - - // Parachain support stuff. - ParachainSystem: cumulus_pallet_parachain_system, - ParachainInfo: parachain_info, - - // Collator support. The order of these 4 are important and shall not change. - CollatorSelection: pallet_collator_selection, - Session: pallet_session, - Aura: pallet_aura, - AuraExt: cumulus_pallet_aura_ext, - - // XCM helpers. - XcmpQueue: cumulus_pallet_xcmp_queue, - PolkadotXcm: pallet_xcm, - CumulusXcm: cumulus_pallet_xcm, - MessageQueue: pallet_message_queue, - } -); +#[frame_support::runtime] +mod runtime { + + #[runtime::runtime] + #[runtime::derive( + RuntimeCall, + RuntimeEvent, + RuntimeError, + RuntimeOrigin, + RuntimeFreezeReason, + RuntimeHoldReason, + RuntimeSlashReason, + RuntimeLockId, + RuntimeTask + )] + pub struct Runtime; + + // Order should match with Runtime defined in runtime/src/lib.rs + #[runtime::pallet_index(0)] + pub type System = frame_system; + #[runtime::pallet_index(1)] + pub type RandomnessCollectiveFlip = pallet_insecure_randomness_collective_flip; + #[runtime::pallet_index(2)] + pub type Utility = pallet_utility; + #[runtime::pallet_index(3)] + pub type Timestamp = pallet_timestamp; + #[runtime::pallet_index(4)] + pub type Balances = pallet_balances; + #[runtime::pallet_index(5)] + pub type Authorship = pallet_authorship; + #[runtime::pallet_index(6)] + pub type TransactionPayment = pallet_transaction_payment; + #[runtime::pallet_index(7)] + pub type Sudo = pallet_sudo; + #[runtime::pallet_index(8)] + pub type Contracts = pallet_contracts; + #[runtime::pallet_index(9)] + pub type Assets = pallet_assets; + // Parachain support. + #[runtime::pallet_index(10)] + pub type ParachainSystem = cumulus_pallet_parachain_system; + #[runtime::pallet_index(11)] + pub type ParachainInfo = parachain_info; + + // Collator support. The order of these 4 are important and shall not change. + #[runtime::pallet_index(12)] + pub type CollatorSelection = pallet_collator_selection; + #[runtime::pallet_index(13)] + pub type Session = pallet_session; + #[runtime::pallet_index(14)] + pub type Aura = pallet_aura; + #[runtime::pallet_index(15)] + pub type AuraExt = cumulus_pallet_aura_ext; + // XCM helpers. + #[runtime::pallet_index(16)] + pub type XcmpQueue = cumulus_pallet_xcmp_queue; + #[runtime::pallet_index(17)] + pub type PolkadotXcm = pallet_xcm; + #[runtime::pallet_index(18)] + pub type CumulusXcm = cumulus_pallet_xcm; + #[runtime::pallet_index(19)] + pub type MessageQueue = pallet_message_queue; +} #[cfg(feature = "runtime-benchmarks")] mod benches { @@ -553,10 +596,11 @@ const CONTRACTS_DEBUG_OUTPUT: pallet_contracts::DebugInfo = pallet_contracts::DebugInfo::UnsafeDebug; const CONTRACTS_EVENTS: pallet_contracts::CollectEvents = pallet_contracts::CollectEvents::UnsafeCollect; + impl_runtime_apis! { impl sp_consensus_aura::AuraApi for Runtime { fn slot_duration() -> sp_consensus_aura::SlotDuration { - sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration()) + sp_consensus_aura::SlotDuration::from_millis(SLOT_DURATION) } fn authorities() -> Vec { @@ -564,6 +608,15 @@ impl_runtime_apis! { } } + impl cumulus_primitives_aura::AuraUnincludedSegmentApi for Runtime { + fn can_build_upon( + included_hash: ::Hash, + slot: cumulus_primitives_aura::Slot + ) -> bool { + ConsensusHook::can_build_upon(included_hash, slot) + } + } + impl sp_api::Core for Runtime { fn version() -> RuntimeVersion { VERSION @@ -587,7 +640,7 @@ impl_runtime_apis! { Runtime::metadata_at_version(version) } - fn metadata_versions() -> sp_std::vec::Vec { + fn metadata_versions() -> Vec { Runtime::metadata_versions() } } @@ -741,7 +794,7 @@ impl_runtime_apis! { use frame_system_benchmarking::Pallet as SystemBench; impl frame_system_benchmarking::Config for Runtime { - fn setup_set_code_requirements(code: &sp_std::vec::Vec) -> Result<(), BenchmarkError> { + fn setup_set_code_requirements(code: &Vec) -> Result<(), BenchmarkError> { ParachainSystem::initialize_for_set_code_benchmark(code.len() as u32); Ok(()) } @@ -834,12 +887,16 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) + } + + fn get_preset(id: &Option) -> Option> { + get_preset::(id, |_| None) } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn preset_names() -> Vec { + Default::default() } } } diff --git a/parachain-runtime/src/xcm_config.rs b/parachain-runtime/src/xcm_config.rs index 2565058..ff24663 100644 --- a/parachain-runtime/src/xcm_config.rs +++ b/parachain-runtime/src/xcm_config.rs @@ -146,6 +146,7 @@ impl xcm_executor::Config for XcmConfig { type HrmpNewChannelOpenRequestHandler = (); type HrmpChannelAcceptedHandler = (); type HrmpChannelClosingHandler = (); + type XcmRecorder = PolkadotXcm; } /// No local origins on this chain are allowed to dispatch XCM sends/executions. @@ -188,8 +189,6 @@ impl pallet_xcm::Config for Runtime { type SovereignAccountOf = LocationToAccountId; type MaxLockers = ConstU32<8>; type WeightInfo = pallet_xcm::TestWeightInfo; - #[cfg(feature = "runtime-benchmarks")] - type ReachableDest = ReachableDest; type AdminOrigin = EnsureRoot; type MaxRemoteLockConsumers = ConstU32<0>; type RemoteLockConsumerIdentifier = (); diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 39437e0..319354d 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -13,8 +13,10 @@ build = "build.rs" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -codec = { package = "parity-scale-codec", version = "3.6.9", default-features = false, features = ["derive"] } -scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } +codec = { features = [ + "derive", +], workspace = true } +scale-info = { workspace = true } frame-executive = { workspace = true } frame-support = { workspace = true } @@ -38,7 +40,6 @@ sp-inherents = { workspace = true } sp-offchain = { workspace = true } sp-runtime = { workspace = true } sp-session = { workspace = true } -sp-std = { workspace = true } sp-storage = { workspace = true } sp-transaction-pool = { workspace = true } sp-version = { workspace = true } @@ -93,7 +94,6 @@ std = [ "sp-offchain/std", "sp-runtime/std", "sp-session/std", - "sp-std/std", "sp-storage/std", "sp-transaction-pool/std", "sp-version/std", diff --git a/runtime/src/assets_config.rs b/runtime/src/assets_config.rs index 322d06e..bd2eb77 100644 --- a/runtime/src/assets_config.rs +++ b/runtime/src/assets_config.rs @@ -36,4 +36,6 @@ impl pallet_assets::Config for Runtime { type WeightInfo = pallet_assets::weights::SubstrateWeight; type RemoveItemsLimit = ConstU32<1000>; type CallbackHandle = (); + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = (); } diff --git a/runtime/src/contracts_config.rs b/runtime/src/contracts_config.rs index 6de5e94..98750d7 100644 --- a/runtime/src/contracts_config.rs +++ b/runtime/src/contracts_config.rs @@ -76,6 +76,7 @@ impl pallet_contracts::Config for Runtime { type MaxCodeLen = ConstU32<{ 256 * 1024 }>; type DefaultDepositLimit = DefaultDepositLimit; type MaxStorageKeyLen = ConstU32<128>; + type MaxTransientStorageSize = ConstU32<{ 1024 * 1024 }>; type MaxDebugBufferLen = ConstU32<{ 2 * 1024 * 1024 }>; type UnsafeUnstableInterface = ConstBool; type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent; diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 57e3cc5..6d6d774 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -9,10 +9,12 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); mod assets_config; mod contracts_config; +extern crate alloc; +use alloc::vec::Vec; use frame_support::{ derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, get_preset}, }; use frame_system::limits::{BlockLength, BlockWeights}; use polkadot_runtime_common::SlowAdjustingFeeUpdate; @@ -24,7 +26,6 @@ use sp_runtime::{ transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, MultiSignature, }; -use sp_std::prelude::*; #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; @@ -47,7 +48,7 @@ pub use frame_support::{ pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; pub use pallet_timestamp::Call as TimestampCall; -use pallet_transaction_payment::CurrencyAdapter; +use pallet_transaction_payment::FungibleAdapter; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; pub use sp_runtime::{Perbill, Permill}; @@ -246,7 +247,7 @@ impl pallet_balances::Config for Runtime { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = CurrencyAdapter; + type OnChargeTransaction = FungibleAdapter; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = IdentityFee; type LengthToFee = IdentityFee; @@ -267,20 +268,42 @@ impl pallet_utility::Config for Runtime { } // Create the runtime by composing the FRAME pallets that were previously configured. -construct_runtime!( - pub struct Runtime { - System: frame_system, - RandomnessCollectiveFlip: pallet_insecure_randomness_collective_flip, - Utility: pallet_utility, - Timestamp: pallet_timestamp, - Balances: pallet_balances, - Authorship: pallet_authorship, - TransactionPayment: pallet_transaction_payment, - Sudo: pallet_sudo, - Contracts: pallet_contracts, - Assets: pallet_assets, - } -); +#[frame_support::runtime] +mod runtime { + #[runtime::runtime] + #[runtime::derive( + RuntimeCall, + RuntimeEvent, + RuntimeError, + RuntimeOrigin, + RuntimeFreezeReason, + RuntimeHoldReason, + RuntimeSlashReason, + RuntimeLockId, + RuntimeTask + )] + pub struct Runtime; + #[runtime::pallet_index(0)] + pub type System = frame_system; + #[runtime::pallet_index(1)] + pub type RandomnessCollectiveFlip = pallet_insecure_randomness_collective_flip; + #[runtime::pallet_index(2)] + pub type Utility = pallet_utility; + #[runtime::pallet_index(3)] + pub type Timestamp = pallet_timestamp; + #[runtime::pallet_index(4)] + pub type Balances = pallet_balances; + #[runtime::pallet_index(5)] + pub type Authorship = pallet_authorship; + #[runtime::pallet_index(6)] + pub type TransactionPayment = pallet_transaction_payment; + #[runtime::pallet_index(7)] + pub type Sudo = pallet_sudo; + #[runtime::pallet_index(8)] + pub type Contracts = pallet_contracts; + #[runtime::pallet_index(9)] + pub type Assets = pallet_assets; +} /// The address format for describing accounts. pub type Address = sp_runtime::MultiAddress; @@ -342,7 +365,7 @@ impl_runtime_apis! { Runtime::metadata_at_version(version) } - fn metadata_versions() -> sp_std::vec::Vec { + fn metadata_versions() -> Vec { Runtime::metadata_versions() } } @@ -511,14 +534,17 @@ impl_runtime_apis! { } } - impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) + } + + fn get_preset(id: &Option) -> Option> { + get_preset::(id, |_| None) } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn preset_names() -> Vec { + Default::default() } } }