diff --git a/Cargo.lock b/Cargo.lock index a0b7d23b3..ba4565716 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10640,6 +10640,24 @@ dependencies = [ "thiserror", ] +[[package]] +name = "sc-network-statement" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.1.0#c8d2251cafadc108ba2f1f8a3208dc547ff38901" +dependencies = [ + "array-bytes", + "async-channel 1.9.0", + "futures 0.3.30", + "libp2p", + "log", + "parity-scale-codec", + "sc-network", + "sc-network-common", + "sp-consensus", + "sp-statement-store", + "substrate-prometheus-endpoint", +] + [[package]] name = "sc-network-sync" version = "0.10.0-dev" @@ -14790,7 +14808,9 @@ dependencies = [ "sc-executor", "sc-keystore", "sc-network", - "sc-network-common", + "sc-network-statement", + "sc-network-sync", + "sc-offchain", "sc-rpc", "sc-rpc-api", "sc-service", diff --git a/Cargo.toml b/Cargo.toml index 3d05054d1..e957289c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -143,7 +143,9 @@ sc-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk", bra sc-executor = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } sc-keystore = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } sc-network = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } -sc-network-common = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } +sc-network-statement = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } +sc-network-sync = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } +sc-offchain = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } sc-rpc = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } sc-rpc-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } sc-service = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } diff --git a/Makefile b/Makefile index 537b0b49c..e7dd74154 100644 --- a/Makefile +++ b/Makefile @@ -18,11 +18,7 @@ check-dummy: # Pseudo private target is invoked by public targets for different chains --try-runtime: RUST_LOG=runtime=trace,try-runtime::cli=trace,executor=trace \ - cargo run \ - --bin=zeitgeist \ - --features=parachain,try-runtime \ try-runtime \ - --chain=${TRYRUNTIME_CHAIN} \ --runtime=${RUNTIME_PATH} \ on-runtime-upgrade \ --checks=all \ @@ -30,15 +26,13 @@ check-dummy: --uri=${TRYRUNTIME_URL} try-runtime-upgrade-battery-station: - @$(MAKE) TRYRUNTIME_CHAIN="battery_station_staging" \ - TRYRUNTIME_URL="wss://bsr.zeitgeist.pm:443" \ + @$(MAKE) TRYRUNTIME_URL="wss://bsr.zeitgeist.pm:443" \ RUNTIME_PATH="./target/debug/wbuild/battery-station-runtime/battery_station_runtime.compact.compressed.wasm" \ -- \ --try-runtime try-runtime-upgrade-zeitgeist: - @$(MAKE) TRYRUNTIME_CHAIN="zeitgeist_staging" \ - TRYRUNTIME_URL="wss://zeitgeist-rpc.dwellir.com:443" \ + @$(MAKE) TRYRUNTIME_URL="wss://zeitgeist-rpc.dwellir.com:443" \ RUNTIME_PATH="./target/debug/wbuild/zeitgeist-runtime/zeitgeist_runtime.compact.compressed.wasm" \ -- \ --try-runtime diff --git a/node/Cargo.toml b/node/Cargo.toml index cb75bb0bf..22907791d 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -17,6 +17,9 @@ sc-client-db = { workspace = true } sc-consensus = { workspace = true } sc-executor = { workspace = true } sc-keystore = { workspace = true } +sc-network = { workspace = true } +sc-network-statement = { workspace = true } +sc-offchain = { workspace = true } sc-rpc = { workspace = true } sc-rpc-api = { workspace = true } sc-service = { workspace = true } @@ -75,8 +78,7 @@ pallet-author-inherent = { workspace = true, features = ["default"], optional = pallet-parachain-staking = { workspace = true, features = ["default"], optional = true } parity-scale-codec = { workspace = true, features = ["default"], optional = true } sc-chain-spec = { workspace = true, optional = true } -sc-network = { workspace = true, optional = true } -sc-network-common = { workspace = true, optional = true } +sc-network-sync = { workspace = true, optional = true } sc-tracing = { workspace = true, optional = true } serde = { workspace = true, features = ["default"], optional = true } session-keys-primitives = { workspace = true, features = ["default"], optional = true } @@ -148,8 +150,7 @@ parachain = [ "parity-scale-codec", "session-keys-primitives", "sc-chain-spec", - "sc-network", - "sc-network-common", + "sc-network-sync", "sc-tracing", "serde", "sp-keystore", diff --git a/node/src/chain_spec/additional_chain_spec.rs b/node/src/chain_spec/additional_chain_spec.rs index b7d39e7ae..45250d34c 100644 --- a/node/src/chain_spec/additional_chain_spec.rs +++ b/node/src/chain_spec/additional_chain_spec.rs @@ -40,5 +40,5 @@ pub struct AdditionalChainSpec { #[cfg(not(feature = "parachain"))] pub struct AdditionalChainSpec { pub initial_authorities: - Vec<(sp_consensus_aura::sr25519::AuthorityId, sp_finality_grandpa::AuthorityId)>, + Vec<(sp_consensus_aura::sr25519::AuthorityId, sp_consensus_grandpa::AuthorityId)>, } diff --git a/node/src/chain_spec/battery_station.rs b/node/src/chain_spec/battery_station.rs index 058222791..9c49a94cc 100644 --- a/node/src/chain_spec/battery_station.rs +++ b/node/src/chain_spec/battery_station.rs @@ -48,10 +48,10 @@ cfg_if::cfg_if! { pub(super) const DEFAULT_STAKING_AMOUNT_BATTERY_STATION: u128 = 2_000 * BASE; const DEFAULT_COLLATOR_BALANCE_BATTERY_STATION: Option = DEFAULT_STAKING_AMOUNT_BATTERY_STATION.checked_add(CollatorDeposit::get()); - pub type BatteryStationChainSpec = sc_service::GenericChainSpec; + pub type BatteryStationChainSpec = sc_service::GenericChainSpec; const NUM_SELECTED_CANDIDATES: u32 = 8; } else { - pub type BatteryStationChainSpec = sc_service::GenericChainSpec; + pub type BatteryStationChainSpec = sc_service::GenericChainSpec; } } diff --git a/node/src/chain_spec/dev.rs b/node/src/chain_spec/dev.rs index 75782f73b..99771873f 100644 --- a/node/src/chain_spec/dev.rs +++ b/node/src/chain_spec/dev.rs @@ -49,10 +49,10 @@ const INITIAL_BALANCE: Balance = Balance::MAX >> 4; #[cfg(not(feature = "parachain"))] fn authority_keys_from_seed( s: &str, -) -> (sp_consensus_aura::sr25519::AuthorityId, sp_finality_grandpa::AuthorityId) { +) -> (sp_consensus_aura::sr25519::AuthorityId, sp_consensus_grandpa::AuthorityId) { ( get_from_seed::(s), - get_from_seed::(s), + get_from_seed::(s), ) } diff --git a/node/src/chain_spec/mod.rs b/node/src/chain_spec/mod.rs index 4d9849948..575fea004 100644 --- a/node/src/chain_spec/mod.rs +++ b/node/src/chain_spec/mod.rs @@ -108,8 +108,8 @@ macro_rules! generate_generic_genesis_function { acs: AdditionalChainSpec, endowed_accounts: Vec, wasm_binary: &[u8], - ) -> $runtime::GenesisConfig { - $runtime::GenesisConfig { + ) -> $runtime::RuntimeGenesisConfig { + $runtime::RuntimeGenesisConfig { // Common genesis advisory_committee: Default::default(), advisory_committee_membership: $runtime::AdvisoryCommitteeMembershipConfig { @@ -125,6 +125,7 @@ macro_rules! generate_generic_genesis_function { #[cfg(feature = "parachain")] author_filter: $runtime::AuthorFilterConfig { eligible_count: EligibilityValue::new_unchecked(1), + ..Default::default() }, #[cfg(feature = "parachain")] author_mapping: $runtime::AuthorMappingConfig { @@ -147,13 +148,17 @@ macro_rules! generate_generic_genesis_function { #[cfg(not(feature = "parachain"))] grandpa: $runtime::GrandpaConfig { authorities: acs.initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(), + ..Default::default() }, liquidity_mining: $runtime::LiquidityMiningConfig { initial_balance: LIQUIDITY_MINING, per_block_distribution: LIQUIDITY_MINING_PTD.mul_ceil(LIQUIDITY_MINING), }, #[cfg(feature = "parachain")] - parachain_info: $runtime::ParachainInfoConfig { parachain_id: acs.parachain_id }, + parachain_info: $runtime::ParachainInfoConfig { + parachain_id: acs.parachain_id, + ..Default::default() + }, #[cfg(feature = "parachain")] parachain_staking: $runtime::ParachainStakingConfig { blocks_per_round: acs.blocks_per_round, @@ -174,7 +179,7 @@ macro_rules! generate_generic_genesis_function { #[cfg(feature = "parachain")] // Default should use the pallet configuration polkadot_xcm: PolkadotXcmConfig::default(), - system: $runtime::SystemConfig { code: wasm_binary.to_vec() }, + system: $runtime::SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, technical_committee: Default::default(), technical_committee_membership: $runtime::TechnicalCommitteeMembershipConfig { members: vec![].try_into().unwrap(), @@ -230,7 +235,7 @@ pub struct Extensions { /// The relay chain of the Parachain. pub relay_chain: String, /// Known bad block hashes. - pub bad_blocks: sc_client_api::BadBlocks, + pub bad_blocks: sc_client_api::BadBlocks, } #[cfg(feature = "parachain")] diff --git a/node/src/chain_spec/zeitgeist.rs b/node/src/chain_spec/zeitgeist.rs index c98d38a26..f1cdbaddd 100644 --- a/node/src/chain_spec/zeitgeist.rs +++ b/node/src/chain_spec/zeitgeist.rs @@ -36,19 +36,19 @@ use { zeitgeist_primitives::constants::ztg::{STAKING_PTD, TOTAL_INITIAL_ZTG}, zeitgeist_runtime::{ CollatorDeposit, DefaultBlocksPerRound, DefaultCollatorCommission, - DefaultParachainBondReservePercent, EligibilityValue, MinCollatorStk, PolkadotXcmConfig, + DefaultParachainBondReservePercent, EligibilityValue, MinCandidateStk, PolkadotXcmConfig, }, }; cfg_if::cfg_if! { if #[cfg(feature = "parachain")] { - const DEFAULT_STAKING_AMOUNT_ZEITGEIST: u128 = MinCollatorStk::get(); + const DEFAULT_STAKING_AMOUNT_ZEITGEIST: u128 = MinCandidateStk::get(); const DEFAULT_COLLATOR_BALANCE_ZEITGEIST: Option = DEFAULT_STAKING_AMOUNT_ZEITGEIST.checked_add(CollatorDeposit::get()); const NUM_SELECTED_CANDIDATES: u32 = 8; - pub type ZeitgeistChainSpec = sc_service::GenericChainSpec; + pub type ZeitgeistChainSpec = sc_service::GenericChainSpec; } else { - pub type ZeitgeistChainSpec = sc_service::GenericChainSpec; + pub type ZeitgeistChainSpec = sc_service::GenericChainSpec; } } diff --git a/node/src/cli.rs b/node/src/cli.rs index 31c9dffda..13bf908f4 100644 --- a/node/src/cli.rs +++ b/node/src/cli.rs @@ -20,22 +20,15 @@ #[cfg(feature = "parachain")] mod cli_parachain; -use super::service::{ - AdditionalRuntimeApiCollection, FullBackend, FullClient, IdentifyVariant, RuntimeApiCollection, -}; +use super::service::{FullBackend, FullClient, IdentifyVariant}; use clap::Parser; #[cfg(feature = "parachain")] pub use cli_parachain::RelayChainCli; -use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli}; -use sc_client_api::{Backend as BackendT, BlockchainEvents, KeyIterator}; -use sp_api::{CallApiAt, NumberFor, ProvideRuntimeApi}; -use sp_blockchain::HeaderBackend; +use sc_cli::{ChainSpec, SubstrateCli}; +use sc_client_api::{KeysIter, PairsIter}; +use sp_api::NumberFor; use sp_consensus::BlockStatus; -use sp_runtime::{ - generic::SignedBlock, - traits::{BlakeTwo256, Block as BlockT}, - Justifications, -}; +use sp_runtime::{generic::SignedBlock, traits::Block as BlockT, Justifications}; use sp_storage::{ChildInfo, StorageData, StorageKey}; use std::sync::Arc; use zeitgeist_primitives::types::{Block, Header}; @@ -166,11 +159,6 @@ pub enum Subcommand { Revert(sc_cli::RevertCmd), /// Try some command against runtime state. - #[cfg(feature = "try-runtime")] - TryRuntime(try_runtime_cli::TryRuntimeCmd), - - /// Try some command against runtime state. Note: `try-runtime` feature must be enabled. - #[cfg(not(feature = "try-runtime"))] TryRuntime, } @@ -212,6 +200,20 @@ pub struct Cli { pub storage_monitor: sc_storage_monitor::StorageMonitorParams, } +#[cfg(feature = "parachain")] +impl Cli { + pub(crate) fn runtime_version(spec: &Box) -> sc_cli::RuntimeVersion { + match spec { + #[cfg(feature = "with-zeitgeist-runtime")] + spec if spec.is_zeitgeist() => zeitgeist_runtime::VERSION, + #[cfg(feature = "with-battery-station-runtime")] + _ => battery_station_runtime::VERSION, + #[cfg(not(feature = "with-battery-station-runtime"))] + _ => panic!("{}", crate::BATTERY_STATION_RUNTIME_NOT_AVAILABLE), + } + } +} + impl SubstrateCli for Cli { fn author() -> String { env!("CARGO_PKG_AUTHORS").into() @@ -237,105 +239,11 @@ impl SubstrateCli for Cli { load_spec(id) } - fn native_runtime_version(spec: &Box) -> &'static RuntimeVersion { - match spec { - spec if spec.is_zeitgeist() => { - #[cfg(feature = "with-zeitgeist-runtime")] - return &zeitgeist_runtime::VERSION; - #[cfg(not(feature = "with-zeitgeist-runtime"))] - panic!("{}", crate::ZEITGEIST_RUNTIME_NOT_AVAILABLE); - } - _spec => { - #[cfg(feature = "with-battery-station-runtime")] - return &battery_station_runtime::VERSION; - #[cfg(not(feature = "with-battery-station-runtime"))] - panic!("{}", crate::BATTERY_STATION_RUNTIME_NOT_AVAILABLE); - } - } - } - fn support_url() -> String { SUPPORT_URL.into() } } -/// Config that abstracts over all available client implementations. -/// -/// For a concrete type there exists [`Client`]. -pub trait AbstractClient: - BlockchainEvents - + Sized - + Send - + Sync - + ProvideRuntimeApi - + HeaderBackend - + CallApiAt -where - Block: BlockT, - Backend: BackendT, - Backend::State: sp_api::StateBackend, - Self::Api: RuntimeApiCollection - + AdditionalRuntimeApiCollection, -{ -} - -impl AbstractClient for Client -where - Block: BlockT, - Backend: BackendT, - Backend::State: sp_api::StateBackend, - Client: BlockchainEvents - + ProvideRuntimeApi - + HeaderBackend - + Sized - + Send - + Sync - + CallApiAt, - Client::Api: RuntimeApiCollection - + AdditionalRuntimeApiCollection, -{ -} - -/// Execute something with the client instance. -/// -/// As there exist multiple chains inside Zeitgeist, like Zeitgeist itself, -/// Battery Station etc., there can exist different kinds of client types. As these -/// client types differ in the generics that are being used, we can not easily -/// return them from a function. For returning them from a function there exists -/// [`Client`]. However, the problem on how to use this client instance still -/// exists. This trait "solves" it in a dirty way. It requires a type to -/// implement this trait and than the [`execute_with_client`](ExecuteWithClient::execute_with_client) -/// function can be called with any possible client -/// instance. -/// -/// In a perfect world, we could make a closure work in this way. -pub trait ExecuteWithClient { - /// The return type when calling this instance. - type Output; - - /// Execute whatever should be executed with the given client instance. - fn execute_with_client(self, client: Arc) -> Self::Output - where - >::StateBackend: sp_api::StateBackend, - Backend: sc_client_api::Backend, - Backend::State: sp_api::StateBackend, - Api: RuntimeApiCollection - + AdditionalRuntimeApiCollection, - Client: AbstractClient + 'static; -} - -/// A handle to a Zeitgeist client instance. -/// -/// The Zeitgeist service supports multiple different runtimes (Zeitgeist, Battery -/// Station, etc.). As each runtime has a specialized client, we need to hide them -/// behind a trait. This is this trait. -/// -/// When wanting to work with the inner client, you need to use `execute_with`. -pub trait ClientHandle { - /// Execute the given something with the client. - fn execute_with(&self, t: T) -> T::Output; -} - /// A client instance of Zeitgeist. #[derive(Clone)] pub enum Client { @@ -359,21 +267,6 @@ impl From>> for Client { } } -impl ClientHandle for Client { - fn execute_with(&self, t: T) -> T::Output { - match self { - #[cfg(feature = "with-battery-station-runtime")] - Self::BatteryStation(client) => { - T::execute_with_client::<_, _, FullBackend>(t, client.clone()) - } - #[cfg(feature = "with-zeitgeist-runtime")] - Self::Zeitgeist(client) => { - T::execute_with_client::<_, _, FullBackend>(t, client.clone()) - } - } - } -} - macro_rules! match_client { ($self:ident, $method:ident($($param:ident),*)) => { match $self { @@ -459,14 +352,6 @@ impl sc_client_api::StorageProvider for Client { match_client!(self, storage(hash, key)) } - fn storage_keys( - &self, - hash: ::Hash, - key_prefix: &StorageKey, - ) -> sp_blockchain::Result> { - match_client!(self, storage_keys(hash, key_prefix)) - } - fn storage_hash( &self, hash: ::Hash, @@ -475,23 +360,25 @@ impl sc_client_api::StorageProvider for Client { match_client!(self, storage_hash(hash, key)) } - fn storage_pairs( + fn storage_keys( &self, hash: ::Hash, - key_prefix: &StorageKey, - ) -> sp_blockchain::Result> { - match_client!(self, storage_pairs(hash, key_prefix)) + prefix: Option<&StorageKey>, + start_key: Option<&StorageKey>, + ) -> sp_blockchain::Result>::State, Block>> + { + match_client!(self, storage_keys(hash, prefix, start_key)) } - fn storage_keys_iter( + fn storage_pairs( &self, hash: ::Hash, - prefix: Option<&StorageKey>, + key_prefix: Option<&StorageKey>, start_key: Option<&StorageKey>, ) -> sp_blockchain::Result< - KeyIterator<>::State, Block>, + PairsIter<>::State, Block>, > { - match_client!(self, storage_keys_iter(hash, prefix, start_key)) + match_client!(self, storage_pairs(hash, key_prefix, start_key)) } fn child_storage( @@ -504,24 +391,14 @@ impl sc_client_api::StorageProvider for Client { } fn child_storage_keys( - &self, - hash: ::Hash, - child_info: &ChildInfo, - key_prefix: &StorageKey, - ) -> sp_blockchain::Result> { - match_client!(self, child_storage_keys(hash, child_info, key_prefix)) - } - - fn child_storage_keys_iter( &self, hash: ::Hash, child_info: ChildInfo, prefix: Option<&StorageKey>, start_key: Option<&StorageKey>, - ) -> sp_blockchain::Result< - KeyIterator<>::State, Block>, - > { - match_client!(self, child_storage_keys_iter(hash, child_info, prefix, start_key)) + ) -> sp_blockchain::Result>::State, Block>> + { + match_client!(self, child_storage_keys(hash, child_info, prefix, start_key)) } fn child_storage_hash( diff --git a/node/src/cli/cli_parachain.rs b/node/src/cli/cli_parachain.rs index 9b7810f18..4a8d8f75a 100644 --- a/node/src/cli/cli_parachain.rs +++ b/node/src/cli/cli_parachain.rs @@ -18,11 +18,10 @@ use clap::Parser; use sc_cli::{ - self, ChainSpec, ImportParams, KeystoreParams, NetworkParams, RuntimeVersion, SharedParams, - SubstrateCli, + self, ChainSpec, ImportParams, KeystoreParams, NetworkParams, SharedParams, SubstrateCli, }; use sc_service::config::{BasePath, PrometheusConfig}; -use std::{net::SocketAddr, path::PathBuf}; +use std::path::PathBuf; const BATTERY_STATION_RELAY_ID: &str = "battery_station_relay_v3"; @@ -46,12 +45,13 @@ impl RelayChainCli { ) -> Self { 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(chain_id.clone().unwrap_or_else(|| "polkadot".into()))); + let base_path = para_config.base_path.path().join("polkadot"); - Self { base_path, chain_id, base: clap::Parser::parse_from(relay_chain_args) } + Self { + base_path: Some(base_path), + chain_id, + base: polkadot_cli::RunCmd::parse_from(relay_chain_args), + } } } @@ -127,24 +127,12 @@ impl sc_cli::CliConfiguration for RelayChainCli { self.base.base.rpc_cors(is_dev) } - fn rpc_http(&self, default_listen_port: u16) -> sc_cli::Result> { - self.base.base.rpc_http(default_listen_port) - } - - fn rpc_ipc(&self) -> sc_cli::Result> { - self.base.base.rpc_ipc() - } - fn rpc_methods(&self) -> sc_cli::Result { self.base.base.rpc_methods() } - fn rpc_ws(&self, default_listen_port: u16) -> sc_cli::Result> { - self.base.base.rpc_ws(default_listen_port) - } - - fn rpc_ws_max_connections(&self) -> sc_cli::Result> { - self.base.base.rpc_ws_max_connections() + fn rpc_max_connections(&self) -> sc_cli::Result { + self.base.base.rpc_max_connections() } fn shared_params(&self) -> &SharedParams { @@ -168,11 +156,7 @@ impl sc_cli::DefaultConfigurationValues for RelayChainCli { 9616 } - fn rpc_http_listen_port() -> u16 { - 9934 - } - - fn rpc_ws_listen_port() -> u16 { + fn rpc_listen_port() -> u16 { 9945 } } @@ -211,10 +195,6 @@ impl sc_cli::SubstrateCli for RelayChainCli { } } - fn native_runtime_version(chain_spec: &Box) -> &'static RuntimeVersion { - polkadot_cli::Cli::native_runtime_version(chain_spec) - } - fn support_url() -> String { crate::cli::SUPPORT_URL.into() } diff --git a/node/src/command.rs b/node/src/command.rs index 2491aa822..bf365d4be 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -20,7 +20,7 @@ use super::{ benchmarking::{inherent_benchmark_data, RemarksExtrinsicBuilder, TransferKeepAliveBuilder}, cli::{Cli, Subcommand}, - service::{new_chain_ops, new_full, IdentifyVariant}, + service::{new_chain_ops, new_full, HostFunctions, IdentifyVariant}, }; use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE_HARDWARE}; use sc_cli::SubstrateCli; @@ -68,26 +68,24 @@ pub fn run() -> sc_cli::Result<()> { // This switch needs to be in the client, since the client decides // which sub-commands it wants to support. BenchmarkCmd::Pallet(cmd) => { - if !cfg!(feature = "runtime-benchmarks") { + if cfg!(feature = "runtime-benchmarks") { + match chain_spec { + #[cfg(feature = "with-zeitgeist-runtime")] + spec if spec.is_zeitgeist() => runner.sync_run(|config| { + cmd.run::(config) + }), + #[cfg(feature = "with-battery-station-runtime")] + _ => runner.sync_run(|config| { + cmd.run::(config) + }), + #[cfg(not(feature = "with-battery-station-runtime"))] + _ => panic!("{}", crate::BATTERY_STATION_RUNTIME_NOT_AVAILABLE), + } + } else { return Err("Runtime benchmarking wasn't enabled when building the node. \ You can enable it with `--features runtime-benchmarks`." .into()); } - - match chain_spec { - #[cfg(feature = "with-zeitgeist-runtime")] - spec if spec.is_zeitgeist() => runner.sync_run(|config| { - cmd.run::(config) - }), - #[cfg(feature = "with-battery-station-runtime")] - _ => runner.sync_run(|config| { - cmd.run::( - config, - ) - }), - #[cfg(not(feature = "with-battery-station-runtime"))] - _ => panic!("{}", crate::BATTERY_STATION_RUNTIME_NOT_AVAILABLE), - } } BenchmarkCmd::Block(cmd) => match chain_spec { #[cfg(feature = "with-zeitgeist-runtime")] @@ -320,7 +318,7 @@ pub fn run() -> sc_cli::Result<()> { let _ = builder.init(); let chain_spec = &crate::cli::load_spec(¶ms.shared_params.chain.clone().unwrap_or_default())?; - let state_version = Cli::native_runtime_version(chain_spec).state_version(); + let state_version = Cli::runtime_version(chain_spec).state_version(); let buf = match chain_spec { #[cfg(feature = "with-zeitgeist-runtime")] @@ -432,57 +430,10 @@ pub fn run() -> sc_cli::Result<()> { Ok((cmd.run(client, backend, None), task_manager)) }) } - #[cfg(feature = "try-runtime")] - Some(Subcommand::TryRuntime(cmd)) => { - use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch}; - - let runner = cli.create_runner(cmd)?; - let chain_spec = &runner.config().chain_spec; - - match chain_spec { - #[cfg(feature = "with-zeitgeist-runtime")] - spec if spec.is_zeitgeist() => { - runner.async_run(|config| { - // we don't need any of the components of new_partial, just a runtime, or a task - // manager to do `async_run`. - let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry); - let task_manager = - sc_service::TaskManager::new(config.tokio_handle.clone(), registry) - .map_err(|e| { - sc_cli::Error::Service(sc_service::Error::Prometheus(e)) - })?; - return Ok(( - cmd.run::::ExtendHostFunctions, - >>(), - task_manager, - )); - }) - } - #[cfg(feature = "with-battery-station-runtime")] - _ => runner.async_run(|config| { - let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry); - let task_manager = - sc_service::TaskManager::new(config.tokio_handle.clone(), registry) - .map_err(|e| { - sc_cli::Error::Service(sc_service::Error::Prometheus(e)) - })?; - return Ok(( - cmd.run::::ExtendHostFunctions, - >>(), - task_manager, - )); - }), - #[cfg(not(feature = "with-battery-station-runtime"))] - _ => Err("Invalid chain spec"), - } - } - #[cfg(not(feature = "try-runtime"))] - Some(Subcommand::TryRuntime) => Err("TryRuntime wasn't enabled when building the node. \ - You can enable it with `--features try-runtime`." + 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 => none_command(cli), } @@ -515,10 +466,10 @@ fn none_command(cli: Cli) -> sc_cli::Result<()> { cli.parachain_id.or(parachain_id_extension).unwrap_or(super::POLKADOT_PARACHAIN_ID), ); let parachain_account = - AccountIdConversion::::into_account_truncating( + AccountIdConversion::::into_account_truncating( ¶chain_id, ); - let state_version = Cli::native_runtime_version(chain_spec).state_version(); + let state_version = Cli::runtime_version(chain_spec).state_version(); let block: zeitgeist_runtime::Block = cumulus_client_cli::generate_genesis_block(&**chain_spec, state_version) .map_err(|e| format!("{:?}", e))?; @@ -545,7 +496,7 @@ fn none_command(cli: Cli) -> sc_cli::Result<()> { if parachain_config.role.is_authority() { "yes" } else { "no" } ); - if !collator_options.relay_chain_rpc_urls.is_empty() && !cli.relaychain_args.is_empty() { + if !cli.run.relay_chain_rpc_urls.is_empty() && !cli.relaychain_args.is_empty() { log::warn!( "Detected relay chain node arguments together with --relay-chain-rpc-url. This \ command starts a minimal Polkadot node that only uses a network-related subset \ diff --git a/node/src/rpc.rs b/node/src/rpc.rs index ffa85bead..c4543bd60 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -29,7 +29,7 @@ use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; use std::sync::Arc; -use zeitgeist_primitives::types::{AccountId, Balance, Block, Index as Nonce, MarketId, PoolId}; +use zeitgeist_primitives::types::{AccountId, Balance, Block, MarketId, Nonce, PoolId}; /// Full client dependencies. pub struct FullDeps { diff --git a/node/src/service.rs b/node/src/service.rs index dd9f57b4b..6e832325f 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -21,8 +21,7 @@ mod service_parachain; #[cfg(not(feature = "parachain"))] mod service_standalone; -use sp_runtime::traits::BlakeTwo256; -use zeitgeist_primitives::types::{AccountId, Balance, Block, Index, MarketId, PoolId}; +use zeitgeist_primitives::types::{AccountId, Balance, Block, MarketId, Nonce, PoolId}; use super::cli::Client; use sc_executor::NativeExecutionDispatch; @@ -34,18 +33,20 @@ pub use service_parachain::{new_full, new_partial, FullBackend, FullClient}; #[cfg(not(feature = "parachain"))] pub use service_standalone::{new_full, new_partial, FullBackend, FullClient}; use sp_api::ConstructRuntimeApi; -use sp_trie::PrefixedMemoryDB; use std::sync::Arc; +#[cfg(feature = "runtime-benchmarks")] +pub type HostFunctions = + (frame_benchmarking::benchmarking::HostFunctions, sp_io::SubstrateHostFunctions); +#[cfg(not(feature = "runtime-benchmarks"))] +pub type HostFunctions = (sp_io::SubstrateHostFunctions,); + #[cfg(feature = "with-battery-station-runtime")] pub struct BatteryStationExecutor; #[cfg(feature = "with-battery-station-runtime")] impl sc_executor::NativeExecutionDispatch for BatteryStationExecutor { - #[cfg(feature = "runtime-benchmarks")] - type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; - #[cfg(not(feature = "runtime-benchmarks"))] - type ExtendHostFunctions = (); + type ExtendHostFunctions = HostFunctions; fn dispatch(method: &str, data: &[u8]) -> Option> { battery_station_runtime::api::dispatch(method, data) @@ -61,10 +62,7 @@ pub struct ZeitgeistExecutor; #[cfg(feature = "with-zeitgeist-runtime")] impl sc_executor::NativeExecutionDispatch for ZeitgeistExecutor { - #[cfg(feature = "runtime-benchmarks")] - type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; - #[cfg(not(feature = "runtime-benchmarks"))] - type ExtendHostFunctions = (); + type ExtendHostFunctions = HostFunctions; fn dispatch(method: &str, data: &[u8]) -> Option> { zeitgeist_runtime::api::dispatch(method, data) @@ -78,18 +76,11 @@ impl sc_executor::NativeExecutionDispatch for ZeitgeistExecutor { /// Can be called for a `Configuration` to check if it is a configuration for /// the `Zeitgeist` network. pub trait IdentifyVariant { - /// Returns `true` if this is a configuration for the `Battery Station` network. - fn is_battery_station(&self) -> bool; - /// Returns `true` if this is a configuration for the `Zeitgeist` network. fn is_zeitgeist(&self) -> bool; } impl IdentifyVariant for Box { - fn is_battery_station(&self) -> bool { - self.id().starts_with("battery_station") - } - fn is_zeitgeist(&self) -> bool { self.id().starts_with("zeitgeist") } @@ -100,29 +91,25 @@ pub trait RuntimeApiCollection: sp_transaction_pool::runtime_api::TaggedTransactionQueue + sp_api::ApiExt + sp_block_builder::BlockBuilder - + substrate_frame_rpc_system::AccountNonceApi + + substrate_frame_rpc_system::AccountNonceApi + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi + sp_api::Metadata + sp_offchain::OffchainWorkerApi + sp_session::SessionKeys + zrml_swaps_rpc::SwapsRuntimeApi -where - >::StateBackend: sp_api::StateBackend, { } -impl RuntimeApiCollection for Api -where +impl RuntimeApiCollection for Api where Api: sp_transaction_pool::runtime_api::TaggedTransactionQueue + sp_api::ApiExt + sp_block_builder::BlockBuilder - + substrate_frame_rpc_system::AccountNonceApi + + substrate_frame_rpc_system::AccountNonceApi + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi + sp_api::Metadata + sp_offchain::OffchainWorkerApi + sp_session::SessionKeys - + zrml_swaps_rpc::SwapsRuntimeApi, - >::StateBackend: sp_api::StateBackend, + + zrml_swaps_rpc::SwapsRuntimeApi { } @@ -134,8 +121,6 @@ cfg_if::cfg_if! { + nimbus_primitives::NimbusApi + cumulus_primitives_core::CollectCollationInfo + session_keys_primitives::VrfApi - where - >::StateBackend: sp_api::StateBackend, { } @@ -145,26 +130,23 @@ cfg_if::cfg_if! { + nimbus_primitives::NimbusApi + cumulus_primitives_core::CollectCollationInfo + session_keys_primitives::VrfApi, - >::StateBackend: sp_api::StateBackend, { } } else { /// Additional APIs for standalone runtimes pub trait AdditionalRuntimeApiCollection: sp_api::ApiExt - + sp_finality_grandpa::GrandpaApi + + sp_consensus_grandpa::GrandpaApi + sp_consensus_aura::AuraApi where - >::StateBackend: sp_api::StateBackend, { } impl AdditionalRuntimeApiCollection for Api where Api: sp_api::ApiExt - + sp_finality_grandpa::GrandpaApi + + sp_consensus_grandpa::GrandpaApi + sp_consensus_aura::AuraApi, - >::StateBackend: sp_api::StateBackend, { } } @@ -175,12 +157,7 @@ cfg_if::cfg_if! { pub fn new_chain_ops( config: &mut Configuration, ) -> Result< - ( - Arc, - Arc, - sc_consensus::BasicQueue>, - TaskManager, - ), + (Arc, Arc, sc_consensus::BasicQueue, TaskManager), ServiceError, > { match &config.chain_spec { @@ -201,22 +178,14 @@ pub fn new_chain_ops( fn new_chain_ops_inner( config: &mut Configuration, ) -> Result< - ( - Arc, - Arc, - sc_consensus::BasicQueue>, - TaskManager, - ), + (Arc, Arc, sc_consensus::BasicQueue, TaskManager), ServiceError, > where Client: From>>, RuntimeApi: ConstructRuntimeApi> + Send + Sync + 'static, - RuntimeApi::RuntimeApi: RuntimeApiCollection> - + AdditionalRuntimeApiCollection< - StateBackend = sc_client_api::StateBackendFor, - >, + RuntimeApi::RuntimeApi: RuntimeApiCollection + AdditionalRuntimeApiCollection, Executor: NativeExecutionDispatch + 'static, { config.keystore = sc_service::config::KeystoreConfig::InMemory; diff --git a/node/src/service/service_parachain.rs b/node/src/service/service_parachain.rs index 2a3db0ca2..59eef3ef7 100644 --- a/node/src/service/service_parachain.rs +++ b/node/src/service/service_parachain.rs @@ -24,26 +24,34 @@ use cumulus_client_cli::CollatorOptions; use cumulus_client_consensus_common::{ ParachainBlockImport as TParachainBlockImport, ParachainConsensus, }; -use cumulus_client_network::BlockAnnounceValidator; +use cumulus_client_service::{build_network, BuildNetworkParams, CollatorSybilResistance}; +#[allow(deprecated)] +// TODO(#1326): Resolve deprecation after upgrade to polkadot-v1.3.0 use cumulus_client_service::{ build_relay_chain_interface, prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams, }; use cumulus_primitives_core::ParaId; use cumulus_relay_chain_interface::RelayChainInterface; +use futures::FutureExt; use nimbus_consensus::{BuildNimbusConsensusParams, NimbusConsensus}; use nimbus_primitives::NimbusId; +use sc_client_api::Backend; use sc_consensus::ImportQueue; -use sc_executor::{NativeElseWasmExecutor, NativeExecutionDispatch}; -use sc_network::NetworkService; -use sc_network_common::service::NetworkBlock; +use sc_executor::{ + HeapAllocStrategy, NativeElseWasmExecutor, NativeExecutionDispatch, WasmExecutor, + DEFAULT_HEAP_ALLOC_STRATEGY, +}; +use sc_network::{config::FullNetworkConfiguration, NetworkBlock}; +use sc_network_sync::SyncingService; use sc_service::{ error::{Error as ServiceError, Result as ServiceResult}, Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager, }; use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; +use sc_transaction_pool_api::OffchainTransactionPoolFactory; use sp_api::ConstructRuntimeApi; -use sp_keystore::SyncCryptoStorePtr; +use sp_keystore::KeystorePtr; use std::sync::Arc; use substrate_prometheus_endpoint::Registry; use zeitgeist_primitives::types::{Block, Hash}; @@ -55,7 +63,7 @@ pub type ParachainPartialComponents = PartialComponents< FullClient, FullBackend, (), - sc_consensus::DefaultImportQueue>, + sc_consensus::DefaultImportQueue, sc_transaction_pool::FullPool>, (ParachainBlockImport, Option, Option), >; @@ -73,10 +81,7 @@ pub async fn new_full( where RuntimeApi: ConstructRuntimeApi> + Send + Sync + 'static, - RuntimeApi::RuntimeApi: RuntimeApiCollection> - + AdditionalRuntimeApiCollection< - StateBackend = sc_client_api::StateBackendFor, - >, + RuntimeApi::RuntimeApi: RuntimeApiCollection + AdditionalRuntimeApiCollection, Executor: NativeExecutionDispatch + 'static, { do_new_full( @@ -172,10 +177,7 @@ pub fn new_partial( where RuntimeApi: ConstructRuntimeApi> + Send + Sync + 'static, - RuntimeApi::RuntimeApi: RuntimeApiCollection> - + AdditionalRuntimeApiCollection< - StateBackend = sc_client_api::StateBackendFor, - >, + RuntimeApi::RuntimeApi: RuntimeApiCollection + AdditionalRuntimeApiCollection, Executor: NativeExecutionDispatch + 'static, { let telemetry = config @@ -189,29 +191,32 @@ where }) .transpose()?; - let executor = NativeElseWasmExecutor::::new( - config.wasm_method, - config.default_heap_pages, - config.max_runtime_instances, - config.runtime_cache_size, - ); + let heap_pages = config + .default_heap_pages + .map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| HeapAllocStrategy::Static { extra_pages: h as _ }); + + let wasm_builder = WasmExecutor::builder() + .with_execution_method(config.wasm_method) + .with_onchain_heap_alloc_strategy(heap_pages) + .with_offchain_heap_alloc_strategy(heap_pages) + .with_ignore_onchain_heap_pages(true) + .with_max_runtime_instances(config.max_runtime_instances) + .with_runtime_cache_size(config.runtime_cache_size); + let wasm_executor = wasm_builder.build(); + let executor = NativeElseWasmExecutor::::new_with_wasm_executor(wasm_executor); let (client, backend, keystore_container, task_manager) = sc_service::new_full_parts::( config, telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), executor, )?; - let client = Arc::new(client); - let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle()); - let telemetry = telemetry.map(|(worker, telemetry)| { task_manager.spawn_handle().spawn("telemetry", None, worker.run()); telemetry }); - let transaction_pool = sc_transaction_pool::BasicPool::new_full( config.transaction_pool.clone(), config.role.is_authority().into(), @@ -219,7 +224,6 @@ where task_manager.spawn_essential_handle(), client.clone(), ); - let block_import = ParachainBlockImport::::new(client.clone(), backend.clone()); let import_queue = nimbus_consensus::import_queue( @@ -253,7 +257,7 @@ where async fn do_new_full( parachain_config: Configuration, polkadot_config: Configuration, - id: polkadot_primitives::v2::Id, + id: polkadot_primitives::Id, build_consensus: BIC, hwbench: Option, collator_options: CollatorOptions, @@ -261,10 +265,7 @@ async fn do_new_full( where RuntimeApi: ConstructRuntimeApi> + Send + Sync + 'static, - RuntimeApi::RuntimeApi: RuntimeApiCollection> - + AdditionalRuntimeApiCollection< - StateBackend = sc_client_api::StateBackendFor, - >, + RuntimeApi::RuntimeApi: RuntimeApiCollection + AdditionalRuntimeApiCollection, Executor: NativeExecutionDispatch + 'static, BIC: FnOnce( Arc>, @@ -274,8 +275,8 @@ where &TaskManager, Arc, Arc>>, - Arc>, - SyncCryptoStorePtr, + Arc>, + KeystorePtr, bool, ) -> Result>, ServiceError>, { @@ -299,31 +300,44 @@ where .await .map_err(|e| ServiceError::Application(Box::new(e) as Box<_>))?; - let block_announce_validator = BlockAnnounceValidator::new(relay_chain_interface.clone(), id); let force_authoring = parachain_config.force_authoring; let collator = 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(); - let (network, system_rpc_tx, tx_handler_controller, start_network) = - sc_service::build_network(sc_service::BuildNetworkParams { - config: ¶chain_config, + let net_config = FullNetworkConfiguration::new(¶chain_config.network); + let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) = + build_network(BuildNetworkParams { + parachain_config: ¶chain_config, client: client.clone(), transaction_pool: transaction_pool.clone(), spawn_handle: task_manager.spawn_handle(), import_queue: params.import_queue, - block_announce_validator_builder: Some(Box::new(|_| { - Box::new(block_announce_validator) - })), - warp_sync: None, - })?; + para_id: id, + relay_chain_interface: relay_chain_interface.clone(), + net_config, + sybil_resistance_level: CollatorSybilResistance::Resistant, + }) + .await?; if parachain_config.offchain_worker.enabled { - sc_service::build_offchain_workers( - ¶chain_config, - task_manager.spawn_handle(), - client.clone(), - network.clone(), + task_manager.spawn_handle().spawn( + "offchain-workers-runner", + "offchain-work", + sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions { + runtime_api_provider: client.clone(), + keystore: Some(params.keystore_container.keystore()), + offchain_db: backend.offchain_storage(), + transaction_pool: Some(OffchainTransactionPoolFactory::new( + transaction_pool.clone(), + )), + network_provider: network.clone(), + is_validator: parachain_config.role.is_authority(), + enable_http_requests: false, + custom_extensions: move |_| vec![], + }) + .run(client.clone(), task_manager.spawn_handle()) + .boxed(), ); } @@ -343,10 +357,11 @@ where backend: backend.clone(), client: client.clone(), config: parachain_config, - keystore: params.keystore_container.sync_keystore(), + keystore: params.keystore_container.keystore(), network: network.clone(), rpc_builder, tx_handler_controller, + sync_service: sync_service.clone(), system_rpc_tx, task_manager: &mut task_manager, telemetry: telemetry.as_mut(), @@ -367,11 +382,13 @@ where } let announce_block = { - let network = network.clone(); - Arc::new(move |hash, data| network.announce_block(hash, data)) + let sync_service = sync_service.clone(); + Arc::new(move |hash, data| sync_service.announce_block(hash, data)) }; - let relay_chain_slot_duration = POLKADOT_BLOCK_DURATION; + let overseer_handle = relay_chain_interface + .overseer_handle() + .map_err(|e| sc_service::Error::Application(Box::new(e)))?; if collator { let parachain_consensus = build_consensus( @@ -382,8 +399,8 @@ where &task_manager, relay_chain_interface.clone(), transaction_pool, - network, - params.keystore_container.sync_keystore(), + sync_service.clone(), + params.keystore_container.keystore(), force_authoring, )?; @@ -399,11 +416,15 @@ where spawner, parachain_consensus, import_queue: import_queue_service, + recovery_handle: Box::new(overseer_handle), collator_key: collator_key .ok_or_else(|| ServiceError::Other("Collator Key is None".to_string()))?, relay_chain_slot_duration, + sync_service, }; + #[allow(deprecated)] + // TODO(#1326): Resolve deprecation after upgrade to polkadot-v1.3.0 start_collator(params).await?; } else { let params = StartFullNodeParams { @@ -411,11 +432,15 @@ where announce_block, task_manager: &mut task_manager, para_id: id, + recovery_handle: Box::new(overseer_handle), relay_chain_interface, relay_chain_slot_duration, import_queue: import_queue_service, + sync_service, }; + #[allow(deprecated)] + // TODO(#1326): Resolve deprecation after upgrade to polkadot-v1.3.0 start_full_node(params)?; } diff --git a/node/src/service/service_standalone.rs b/node/src/service/service_standalone.rs index 28b8dc043..bca68473f 100644 --- a/node/src/service/service_standalone.rs +++ b/node/src/service/service_standalone.rs @@ -22,15 +22,16 @@ use crate::{ cli::Cli, service::{AdditionalRuntimeApiCollection, RuntimeApiCollection}, }; -use sc_client_api::BlockBackend; +use futures::FutureExt; +use sc_client_api::{Backend, BlockBackend}; use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams}; +use sc_consensus_grandpa::{protocol_standard_name, SharedVoterState}; use sc_executor::{NativeElseWasmExecutor, NativeExecutionDispatch}; -use sc_finality_grandpa::{grandpa_peers_set_config, protocol_standard_name, SharedVoterState}; -use sc_keystore::LocalKeystore; use sc_service::{ error::Error as ServiceError, Configuration, TFullBackend, TFullClient, TaskManager, }; use sc_telemetry::{Telemetry, TelemetryWorker}; +use sc_transaction_pool_api::OffchainTransactionPoolFactory; use sp_api::ConstructRuntimeApi; use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; use std::{sync::Arc, time::Duration}; @@ -41,18 +42,19 @@ pub type FullClient = pub type FullBackend = TFullBackend; type FullSelectChain = sc_consensus::LongestChain; +/// The minimum period of blocks on which justifications will be +/// imported and generated. +const GRANDPA_JUSTIFICATION_PERIOD: u32 = 512; + /// Builds a new service for a full client. pub fn new_full( - mut config: Configuration, + config: Configuration, cli: Cli, ) -> Result where RuntimeApi: ConstructRuntimeApi> + Send + Sync + 'static, - RuntimeApi::RuntimeApi: RuntimeApiCollection> - + AdditionalRuntimeApiCollection< - StateBackend = sc_client_api::StateBackendFor, - >, + RuntimeApi::RuntimeApi: RuntimeApiCollection + AdditionalRuntimeApiCollection, Executor: NativeExecutionDispatch + 'static, { let hwbench = (cli.no_hardware_benchmarks) @@ -67,56 +69,47 @@ where backend, mut task_manager, import_queue, - mut keystore_container, + keystore_container, select_chain, transaction_pool, other: (block_import, grandpa_link, mut telemetry), } = new_partial::(&config)?; - if let Some(url) = &config.keystore_remote { - match remote_keystore(url) { - Ok(k) => keystore_container.set_remote_keystore(k), - Err(e) => { - return Err(ServiceError::Other(format!( - "Error hooking up remote keystore for {}: {}", - url, e - ))); - } - }; - } + let mut net_config = sc_network::config::FullNetworkConfiguration::new(&config.network); let grandpa_protocol_name = protocol_standard_name( &client.block_hash(0).ok().flatten().expect("Genesis block exists; qed"), &config.chain_spec, ); - config.network.extra_sets.push(grandpa_peers_set_config(grandpa_protocol_name.clone())); - let warp_sync = Arc::new(sc_finality_grandpa::warp_proof::NetworkProvider::new( + net_config.add_notification_protocol(sc_consensus_grandpa::grandpa_peers_set_config( + grandpa_protocol_name.clone(), + )); + + let statement_handler_proto = sc_network_statement::StatementHandlerPrototype::new( + client.block_hash(0u32.into()).ok().flatten().expect("Genesis block exists; qed"), + config.chain_spec.fork_id(), + ); + net_config.add_notification_protocol(statement_handler_proto.set_config()); + + let warp_sync = Arc::new(sc_consensus_grandpa::warp_proof::NetworkProvider::new( backend.clone(), grandpa_link.shared_authority_set().clone(), Vec::default(), )); - let (network, system_rpc_tx, tx_handler_controller, network_starter) = + 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, block_announce_validator_builder: None, - warp_sync: Some(warp_sync), + warp_sync_params: Some(sc_service::WarpSyncParams::WithProvider(warp_sync)), })?; - if config.offchain_worker.enabled { - sc_service::build_offchain_workers( - &config, - task_manager.spawn_handle(), - client.clone(), - network.clone(), - ); - } - let role = config.role.clone(); let force_authoring = config.force_authoring; let backoff_authoring_blocks: Option<()> = None; @@ -124,6 +117,7 @@ where let enable_grandpa = !config.disable_grandpa; let prometheus_registry = config.prometheus_registry().cloned(); let database = config.database.clone(); + let enable_offchain_worker = config.offchain_worker.enabled; let rpc_builder = { let client = client.clone(); @@ -140,14 +134,15 @@ where let _rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams { network: network.clone(), client: client.clone(), - keystore: keystore_container.sync_keystore(), + keystore: keystore_container.keystore(), task_manager: &mut task_manager, transaction_pool: transaction_pool.clone(), rpc_builder: rpc_builder, tx_handler_controller: tx_handler_controller, - backend, + backend: backend.clone(), system_rpc_tx, config: config, + sync_service: sync_service.clone(), telemetry: telemetry.as_mut(), })?; @@ -168,7 +163,7 @@ where let proposer_factory = sc_basic_authorship::ProposerFactory::new( task_manager.spawn_handle(), client.clone(), - transaction_pool, + transaction_pool.clone(), prometheus_registry.as_ref(), telemetry.as_ref().map(|x| x.handle()), ); @@ -178,7 +173,7 @@ where let aura = sc_consensus_aura::start_aura::( StartAuraParams { slot_duration, - client, + client: client.clone(), select_chain, block_import, proposer_factory, @@ -195,9 +190,9 @@ where }, force_authoring, backoff_authoring_blocks, - keystore: keystore_container.sync_keystore(), - sync_oracle: network.clone(), - justification_sync_link: network.clone(), + keystore: keystore_container.keystore(), + sync_oracle: sync_service.clone(), + justification_sync_link: sync_service.clone(), block_proposal_slot_portion: SlotProportion::new(2f32 / 3f32), max_block_proposal_slot_portion: None, telemetry: telemetry.as_ref().map(|x| x.handle()), @@ -209,7 +204,8 @@ where cli.storage_monitor, database, &task_manager.spawn_essential_handle(), - )?; + ) + .map_err(|e| ServiceError::Application(e.into()))?; // the AURA authoring task is considered essential, i.e. if it // fails we take down the service with it. @@ -218,16 +214,15 @@ where // if the node isn't actively participating in consensus then it doesn't // need a keystore, regardless of which protocol we use below. - let keystore = - if role.is_authority() { Some(keystore_container.sync_keystore()) } else { None }; + let keystore = if role.is_authority() { Some(keystore_container.keystore()) } else { None }; - let grandpa_config = sc_finality_grandpa::Config { + let grandpa_config = sc_consensus_grandpa::Config { gossip_duration: Duration::from_millis(333), - justification_period: 512, + justification_generation_period: GRANDPA_JUSTIFICATION_PERIOD, name: Some(name), observer_enabled: false, keystore, - local_role: role, + local_role: role.clone(), telemetry: telemetry.as_ref().map(|x| x.handle()), protocol_name: grandpa_protocol_name, }; @@ -239,14 +234,16 @@ where // and vote data availability than the observer. The observer has not // been tested extensively yet and having most nodes in a network run it // could lead to finality stalls. - let grandpa_config = sc_finality_grandpa::GrandpaParams { + let grandpa_config = sc_consensus_grandpa::GrandpaParams { config: grandpa_config, link: grandpa_link, - network, - voting_rule: sc_finality_grandpa::VotingRulesBuilder::default().build(), + network: network.clone(), + sync: Arc::new(sync_service), + voting_rule: sc_consensus_grandpa::VotingRulesBuilder::default().build(), prometheus_registry, shared_voter_state: SharedVoterState::empty(), telemetry: telemetry.as_ref().map(|x| x.handle()), + offchain_tx_pool_factory: OffchainTransactionPoolFactory::new(transaction_pool.clone()), }; // the GRANDPA voter task is considered infallible, i.e. @@ -254,7 +251,26 @@ where task_manager.spawn_essential_handle().spawn_blocking( "grandpa-voter", None, - sc_finality_grandpa::run_grandpa_voter(grandpa_config)?, + sc_consensus_grandpa::run_grandpa_voter(grandpa_config)?, + ); + } + + if enable_offchain_worker { + task_manager.spawn_handle().spawn( + "offchain-workers-runner", + "offchain-work", + sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions { + runtime_api_provider: client.clone(), + keystore: Some(keystore_container.keystore()), + offchain_db: backend.offchain_storage(), + transaction_pool: Some(OffchainTransactionPoolFactory::new(transaction_pool)), + network_provider: network.clone(), + is_validator: role.is_authority(), + enable_http_requests: true, + custom_extensions: move |_| vec![], + }) + .run(client.clone(), task_manager.spawn_handle()) + .boxed(), ); } @@ -269,16 +285,20 @@ pub fn new_partial( FullClient, FullBackend, FullSelectChain, - sc_consensus::DefaultImportQueue>, + sc_consensus::DefaultImportQueue, sc_transaction_pool::FullPool>, ( - sc_finality_grandpa::GrandpaBlockImport< + sc_consensus_grandpa::GrandpaBlockImport< FullBackend, Block, FullClient, FullSelectChain, >, - sc_finality_grandpa::LinkHalf, FullSelectChain>, + sc_consensus_grandpa::LinkHalf< + Block, + FullClient, + FullSelectChain, + >, Option, ), >, @@ -287,16 +307,9 @@ pub fn new_partial( where RuntimeApi: ConstructRuntimeApi> + Send + Sync + 'static, - RuntimeApi::RuntimeApi: RuntimeApiCollection> - + AdditionalRuntimeApiCollection< - StateBackend = sc_client_api::StateBackendFor, - >, + RuntimeApi::RuntimeApi: RuntimeApiCollection + AdditionalRuntimeApiCollection, Executor: NativeExecutionDispatch + 'static, { - if config.keystore_remote.is_some() { - return Err(ServiceError::Other(format!("Remote Keystores are not supported."))); - } - let telemetry = config .telemetry_endpoints .clone() @@ -308,12 +321,7 @@ where }) .transpose()?; - let executor = NativeElseWasmExecutor::::new( - config.wasm_method, - config.default_heap_pages, - config.max_runtime_instances, - config.runtime_cache_size, - ); + let executor = sc_service::new_native_or_wasm_executor(&config); let (client, backend, keystore_container, task_manager) = sc_service::new_full_parts::( @@ -338,15 +346,15 @@ where client.clone(), ); - let (grandpa_block_import, grandpa_link) = sc_finality_grandpa::block_import( + let (grandpa_block_import, grandpa_link) = sc_consensus_grandpa::block_import( client.clone(), + GRANDPA_JUSTIFICATION_PERIOD, &(client.clone() as Arc<_>), select_chain.clone(), telemetry.as_ref().map(|x| x.handle()), )?; let slot_duration = sc_consensus_aura::slot_duration(&*client)?; - let import_queue = sc_consensus_aura::import_queue::( ImportQueueParams { block_import: grandpa_block_import.clone(), @@ -382,10 +390,3 @@ where other: (grandpa_block_import, grandpa_link, telemetry), }) } - -fn remote_keystore(_url: &String) -> Result, &'static str> { - // FIXME: here would the concrete keystore be built, - // must return a concrete type (NOT `LocalKeystore`) that - // implements `CryptoStore` and `SyncCryptoStore` - Err("Remote Keystore not supported.") -} diff --git a/zrml/swaps/rpc/src/lib.rs b/zrml/swaps/rpc/src/lib.rs index 5591fb2f9..7de3901ef 100644 --- a/zrml/swaps/rpc/src/lib.rs +++ b/zrml/swaps/rpc/src/lib.rs @@ -30,10 +30,7 @@ use jsonrpsee::{ use parity_scale_codec::{Codec, HasCompact, MaxEncodedLen}; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; -use sp_runtime::{ - generic::BlockId, - traits::{Block as BlockT, MaybeDisplay, MaybeFromStr, NumberFor}, -}; +use sp_runtime::traits::{Block as BlockT, MaybeDisplay, MaybeFromStr, NumberFor}; use zeitgeist_primitives::types::Asset; pub use zrml_swaps_runtime_api::SwapsApi as SwapsRuntimeApi; @@ -133,11 +130,8 @@ where at: Option<::Hash>, ) -> RpcResult> { let api = self.client.runtime_api(); - let at = BlockId::hash(at.unwrap_or_else(|| - //if the block hash is not supplied assume the best block - self.client.info().best_hash)); - - let res = api.pool_shares_id(&at, pool_id).map_err(|e| { + let hash = at.unwrap_or_else(|| self.client.info().best_hash); + let res = api.pool_shares_id(hash, pool_id).map_err(|e| { CallError::Custom(ErrorObject::owned( Error::RuntimeError.into(), "Unable to get pool shares identifier.", @@ -153,11 +147,8 @@ where at: Option<::Hash>, ) -> RpcResult { let api = self.client.runtime_api(); - let at = BlockId::hash(at.unwrap_or_else(|| - //if the block hash is not supplied assume the best block - self.client.info().best_hash)); - - let res = api.pool_account_id(&at, &pool_id).map_err(|e| { + let hash = at.unwrap_or_else(|| self.client.info().best_hash); + let res = api.pool_account_id(hash, &pool_id).map_err(|e| { CallError::Custom(ErrorObject::owned( Error::RuntimeError.into(), "Unable to get pool account identifier.", @@ -177,9 +168,9 @@ where at: Option<::Hash>, ) -> RpcResult { let api = self.client.runtime_api(); - let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash)); + let hash = at.unwrap_or_else(|| self.client.info().best_hash); let res = - api.get_spot_price(&at, &pool_id, &asset_in, &asset_out, with_fees).map_err(|e| { + api.get_spot_price(hash, &pool_id, &asset_in, &asset_out, with_fees).map_err(|e| { CallError::Custom(ErrorObject::owned( Error::RuntimeError.into(), "Unable to get spot price.", @@ -200,10 +191,14 @@ where let api = self.client.runtime_api(); blocks .into_iter() - .map(|block| { - let hash = BlockId::number(block); + .map(|block_number| { + let hash = self + .client + .hash(block_number) + .unwrap_or(Some(self.client.info().best_hash)) + .unwrap_or(self.client.info().best_hash); let res = api - .get_spot_price(&hash, &pool_id, &asset_in, &asset_out, with_fees) + .get_spot_price(hash, &pool_id, &asset_in, &asset_out, with_fees) .map_err(|e| { CallError::Custom(ErrorObject::owned( Error::RuntimeError.into(),