diff --git a/polkadot/.gitlab-ci.yml b/polkadot/.gitlab-ci.yml index 530e00c1c2..4c978e1484 100644 --- a/polkadot/.gitlab-ci.yml +++ b/polkadot/.gitlab-ci.yml @@ -223,6 +223,17 @@ check-runtime-benchmarks: - ./scripts/gitlab/check_runtime_benchmarks.sh - sccache -s +check-no-default-features: + stage: test + <<: *rules-test + <<: *docker-env + <<: *compiler-info + <<: *vault-secrets + script: + # Check that polkadot-cli will compile no default features. + - ./scripts/gitlab/check_no_default_features.sh + - sccache -s + spellcheck: stage: test <<: *docker-env diff --git a/polkadot/cli/Cargo.toml b/polkadot/cli/Cargo.toml index 27dc1a0002..7d56222f31 100644 --- a/polkadot/cli/Cargo.toml +++ b/polkadot/cli/Cargo.toml @@ -36,7 +36,7 @@ sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master", substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "master" } [features] -default = [ "wasmtime", "db", "cli", "full-node", "trie-memory-tracker" ] +default = [ "wasmtime", "db", "cli", "full-node", "trie-memory-tracker", "polkadot-native" ] wasmtime = [ "sc-cli/wasmtime" ] db = [ "service/db" ] cli = [ @@ -59,9 +59,10 @@ trie-memory-tracker = [ "sp-trie/memory-tracker" ] full-node = [ "service/full-node" ] try-runtime = [ "service/try-runtime" ] -# Configure the native runtimes to use. Polkadot is always enabled by default. +# Configure the native runtimes to use. Polkadot is enabled by default. # # Validators require the native runtime currently +polkadot-native = [ "service/polkadot-native" ] kusama-native = [ "service/kusama-native" ] westend-native = [ "service/westend-native" ] rococo-native = [ "service/rococo-native" ] diff --git a/polkadot/cli/src/command.rs b/polkadot/cli/src/command.rs index a4f8214601..c9ba571e82 100644 --- a/polkadot/cli/src/command.rs +++ b/polkadot/cli/src/command.rs @@ -102,8 +102,11 @@ impl SubstrateCli for Cli { name if name.starts_with("kusama-") && !name.ends_with(".json") => Err(format!("`{}` only supported with `kusama-native` feature enabled.", name))?, "polkadot" => Box::new(service::chain_spec::polkadot_config()?), + #[cfg(feature = "polkadot-native")] "polkadot-dev" | "dev" => Box::new(service::chain_spec::polkadot_development_config()?), + #[cfg(feature = "polkadot-native")] "polkadot-local" => Box::new(service::chain_spec::polkadot_local_testnet_config()?), + #[cfg(feature = "polkadot-native")] "polkadot-staging" => Box::new(service::chain_spec::polkadot_staging_testnet_config()?), "rococo" => Box::new(service::chain_spec::rococo_config()?), #[cfg(feature = "rococo-native")] @@ -177,7 +180,13 @@ impl SubstrateCli for Cli { )))] let _ = spec; - &service::polkadot_runtime::VERSION + #[cfg(feature = "polkadot-native")] + { + return &service::polkadot_runtime::VERSION + } + + #[cfg(not(feature = "polkadot-native"))] + panic!("No runtime feature (polkadot, kusama, westend, rococo) is enabled") } } @@ -394,12 +403,17 @@ pub fn run() -> Result<()> { } // else we assume it is polkadot. - Ok(runner.sync_run(|config| { - cmd.run::( - config, - ) - .map_err(|e| Error::SubstrateCli(e)) - })?) + #[cfg(feature = "polkadot-native")] + { + return Ok(runner.sync_run(|config| { + cmd.run::( + config, + ) + .map_err(|e| Error::SubstrateCli(e)) + })?) + } + #[cfg(not(feature = "polkadot-native"))] + panic!("No runtime feature (polkadot, kusama, westend, rococo) is enabled") }, Some(Subcommand::Key(cmd)) => Ok(cmd.run(&cli)?), #[cfg(feature = "try-runtime")] @@ -441,15 +455,20 @@ pub fn run() -> Result<()> { }) } // else we assume it is polkadot. - runner.async_run(|config| { - Ok(( - cmd.run::( - config, - ) - .map_err(Error::SubstrateCli), - task_manager, - )) - }) + #[cfg(feature = "polkadot-native")] + { + return runner.async_run(|config| { + Ok(( + cmd.run::( + config, + ) + .map_err(Error::SubstrateCli), + task_manager, + )) + }) + } + #[cfg(not(feature = "polkadot-native"))] + panic!("No runtime feature (polkadot, kusama, westend, rococo) is enabled") }, #[cfg(not(feature = "try-runtime"))] Some(Subcommand::TryRuntime) => Err(Error::Other( diff --git a/polkadot/cli/src/lib.rs b/polkadot/cli/src/lib.rs index bdd230fa2b..b7b45ed66a 100644 --- a/polkadot/cli/src/lib.rs +++ b/polkadot/cli/src/lib.rs @@ -23,9 +23,10 @@ mod cli; #[cfg(feature = "cli")] mod command; -pub use service::{ - self, Block, CoreApi, IdentifyVariant, ProvideRuntimeApi, RuntimeApiCollection, TFullClient, -}; +#[cfg(feature = "full-node")] +pub use service::RuntimeApiCollection; +#[cfg(feature = "service")] +pub use service::{self, Block, CoreApi, IdentifyVariant, ProvideRuntimeApi, TFullClient}; #[cfg(feature = "malus")] pub use service::create_default_subsystems; diff --git a/polkadot/node/client/Cargo.toml b/polkadot/node/client/Cargo.toml index 15daaac226..63dd404ffc 100644 --- a/polkadot/node/client/Cargo.toml +++ b/polkadot/node/client/Cargo.toml @@ -32,7 +32,7 @@ pallet-mmr-primitives = { git = "https://github.com/paritytech/substrate", branc beefy-primitives = { git = "https://github.com/paritytech/grandpa-bridge-gadget", branch = "master" } # Polkadot Runtimes -polkadot-runtime = { path = "../../runtime/polkadot" } +polkadot-runtime = { path = "../../runtime/polkadot", optional = true } kusama-runtime = { path = "../../runtime/kusama", optional = true } westend-runtime = { path = "../../runtime/westend", optional = true } rococo-runtime = { path = "../../runtime/rococo", optional = true } @@ -40,6 +40,8 @@ rococo-runtime = { path = "../../runtime/rococo", optional = true } polkadot-primitives = { path = "../../primitives" } [features] +default = ["polkadot"] +polkadot = ["polkadot-runtime"] kusama = ["kusama-runtime"] rococo = ["rococo-runtime"] westend = ["westend-runtime"] diff --git a/polkadot/node/client/src/lib.rs b/polkadot/node/client/src/lib.rs index 4c4ff10082..d9166bb50c 100644 --- a/polkadot/node/client/src/lib.rs +++ b/polkadot/node/client/src/lib.rs @@ -40,9 +40,19 @@ pub type FullBackend = sc_service::TFullBackend; pub type FullClient = sc_service::TFullClient>; +#[cfg(not(any( + feature = "rococo", + feature = "kusama", + feature = "westend", + feature = "polkadot" +)))] +compile_error!("at least one runtime feature must be enabled"); + /// The native executor instance for Polkadot. +#[cfg(feature = "polkadot")] pub struct PolkadotExecutorDispatch; +#[cfg(feature = "polkadot")] impl sc_executor::NativeExecutionDispatch for PolkadotExecutorDispatch { type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; @@ -233,6 +243,7 @@ macro_rules! with_client { } } => { match $self { + #[cfg(feature = "polkadot")] Self::Polkadot($client) => { $( $code )* }, #[cfg(feature = "westend")] Self::Westend($client) => { $( $code )* }, @@ -249,6 +260,7 @@ macro_rules! with_client { /// See [`ExecuteWithClient`] for more information. #[derive(Clone)] pub enum Client { + #[cfg(feature = "polkadot")] Polkadot(Arc>), #[cfg(feature = "westend")] Westend(Arc>), diff --git a/polkadot/node/service/Cargo.toml b/polkadot/node/service/Cargo.toml index 054967155b..80178da110 100644 --- a/polkadot/node/service/Cargo.toml +++ b/polkadot/node/service/Cargo.toml @@ -72,7 +72,7 @@ async-trait = "0.1.51" # Polkadot polkadot-node-core-parachains-inherent = { path = "../core/parachains-inherent" } polkadot-overseer = { path = "../overseer" } -polkadot-client = { path = "../client" } +polkadot-client = { path = "../client", default-features = false, optional = true } polkadot-parachain = { path = "../../parachain" } polkadot-primitives = { path = "../../primitives" } polkadot-node-primitives = { path = "../primitives" } @@ -83,7 +83,7 @@ polkadot-runtime-parachains = { path = "../../runtime/parachains" } polkadot-node-network-protocol = { path = "../network/protocol" } # Polkadot Runtimes -polkadot-runtime = { path = "../../runtime/polkadot" } +polkadot-runtime = { path = "../../runtime/polkadot", optional = true } kusama-runtime = { path = "../../runtime/kusama", optional = true } westend-runtime = { path = "../../runtime/westend", optional = true } rococo-runtime = { path = "../../runtime/rococo", optional = true } @@ -119,7 +119,7 @@ log = "0.4.14" assert_matches = "1.5.0" [features] -default = ["db", "full-node"] +default = ["db", "full-node", "polkadot-native"] db = [ "service/db" @@ -131,6 +131,7 @@ full-node = [ "polkadot-availability-bitfield-distribution", "polkadot-availability-distribution", "polkadot-availability-recovery", + "polkadot-client", "polkadot-collator-protocol", "polkadot-dispute-distribution", "polkadot-gossip-support", @@ -152,9 +153,10 @@ full-node = [ light-node = [] -# Configure the native runtimes to use. Polkadot is always enabled by default. +# Configure the native runtimes to use. Polkadot is enabled by default. # # Validators require the native runtime currently +polkadot-native = [ "polkadot-runtime", "polkadot-client/polkadot" ] kusama-native = [ "kusama-runtime", "polkadot-client/kusama" ] westend-native = [ "westend-runtime", "polkadot-client/westend" ] rococo-native = [ "rococo-runtime", "polkadot-client/rococo" ] diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index e2ed37334a..f1cca5509b 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -24,8 +24,10 @@ use kusama_runtime as kusama; use kusama_runtime::constants::currency::UNITS as KSM; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_staking::Forcing; +#[cfg(feature = "polkadot-native")] use polkadot::constants::currency::UNITS as DOT; use polkadot_primitives::v1::{AccountId, AccountPublic, AssignmentId, ValidatorId}; +#[cfg(feature = "polkadot-native")] use polkadot_runtime as polkadot; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_babe::AuthorityId as BabeId; @@ -44,6 +46,7 @@ use westend_runtime as westend; #[cfg(feature = "westend-native")] use westend_runtime::constants::currency::UNITS as WND; +#[cfg(feature = "polkadot-native")] const POLKADOT_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; #[cfg(feature = "kusama-native")] const KUSAMA_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; @@ -71,34 +74,42 @@ pub struct Extensions { } /// The `ChainSpec` parameterized for the polkadot runtime. +#[cfg(feature = "polkadot-native")] pub type PolkadotChainSpec = service::GenericChainSpec; +// Dummy chain spec, in case when we don't have the native runtime. +pub type DummyChainSpec = service::GenericChainSpec<(), Extensions>; + +// Dummy chain spec, but that is fine when we don't have the native runtime. +#[cfg(not(feature = "polkadot-native"))] +pub type PolkadotChainSpec = DummyChainSpec; + /// The `ChainSpec` parameterized for the kusama runtime. #[cfg(feature = "kusama-native")] pub type KusamaChainSpec = service::GenericChainSpec; /// The `ChainSpec` parameterized for the kusama runtime. -// This actually uses the polkadot chain spec, but that is fine when we don't have the native runtime. +// Dummy chain spec, but that is fine when we don't have the native runtime. #[cfg(not(feature = "kusama-native"))] -pub type KusamaChainSpec = PolkadotChainSpec; +pub type KusamaChainSpec = DummyChainSpec; /// The `ChainSpec` parameterized for the westend runtime. #[cfg(feature = "westend-native")] pub type WestendChainSpec = service::GenericChainSpec; /// The `ChainSpec` parameterized for the westend runtime. -// This actually uses the polkadot chain spec, but that is fine when we don't have the native runtime. +// Dummy chain spec, but that is fine when we don't have the native runtime. #[cfg(not(feature = "westend-native"))] -pub type WestendChainSpec = PolkadotChainSpec; +pub type WestendChainSpec = DummyChainSpec; /// The `ChainSpec` parameterized for the rococo runtime. #[cfg(feature = "rococo-native")] pub type RococoChainSpec = service::GenericChainSpec; /// The `ChainSpec` parameterized for the rococo runtime. -// This actually uses the polkadot chain spec, but that is fine when we don't have the native runtime. +// Dummy chain spec, but that is fine when we don't have the native runtime. #[cfg(not(feature = "rococo-native"))] -pub type RococoChainSpec = PolkadotChainSpec; +pub type RococoChainSpec = DummyChainSpec; /// Extension for the Rococo genesis config to support a custom changes to the genesis state. #[derive(serde::Serialize, serde::Deserialize)] @@ -195,6 +206,7 @@ fn default_parachains_host_configuration( } } +#[cfg(feature = "polkadot-native")] fn polkadot_session_keys( babe: BabeId, grandpa: GrandpaId, @@ -272,6 +284,7 @@ fn rococo_session_keys( } } +#[cfg(feature = "polkadot-native")] fn polkadot_staging_testnet_config_genesis(wasm_binary: &[u8]) -> polkadot::GenesisConfig { // subkey inspect "$SECRET" let endowed_accounts = vec![]; @@ -1053,6 +1066,7 @@ fn rococo_staging_testnet_config_genesis(wasm_binary: &[u8]) -> rococo_runtime:: } /// Polkadot staging testnet config. +#[cfg(feature = "polkadot-native")] pub fn polkadot_staging_testnet_config() -> Result { let wasm_binary = polkadot::WASM_BINARY.ok_or("Polkadot development wasm not available")?; let boot_nodes = vec![]; @@ -1218,6 +1232,7 @@ fn testnet_accounts() -> Vec { } /// Helper function to create polkadot `GenesisConfig` for testing +#[cfg(feature = "polkadot-native")] pub fn polkadot_testnet_genesis( wasm_binary: &[u8], initial_authorities: Vec<( @@ -1557,6 +1572,7 @@ pub fn rococo_testnet_genesis( } } +#[cfg(feature = "polkadot-native")] fn polkadot_development_config_genesis(wasm_binary: &[u8]) -> polkadot::GenesisConfig { polkadot_testnet_genesis( wasm_binary, @@ -1597,6 +1613,7 @@ fn rococo_development_config_genesis(wasm_binary: &[u8]) -> rococo_runtime::Gene } /// Polkadot development config (single validator Alice) +#[cfg(feature = "polkadot-native")] pub fn polkadot_development_config() -> Result { let wasm_binary = polkadot::WASM_BINARY.ok_or("Polkadot development wasm not available")?; @@ -1694,6 +1711,7 @@ pub fn wococo_development_config() -> Result { )) } +#[cfg(feature = "polkadot-native")] fn polkadot_local_testnet_genesis(wasm_binary: &[u8]) -> polkadot::GenesisConfig { polkadot_testnet_genesis( wasm_binary, @@ -1707,6 +1725,7 @@ fn polkadot_local_testnet_genesis(wasm_binary: &[u8]) -> polkadot::GenesisConfig } /// Polkadot local testnet config (multivalidator Alice + Bob) +#[cfg(feature = "polkadot-native")] pub fn polkadot_local_testnet_config() -> Result { let wasm_binary = polkadot::WASM_BINARY.ok_or("Polkadot development wasm not available")?; diff --git a/polkadot/node/service/src/lib.rs b/polkadot/node/service/src/lib.rs index 72277434b5..bcb181fa04 100644 --- a/polkadot/node/service/src/lib.rs +++ b/polkadot/node/service/src/lib.rs @@ -82,11 +82,15 @@ pub use polkadot_client::WestendExecutorDispatch; #[cfg(feature = "kusama-native")] pub use polkadot_client::KusamaExecutorDispatch; +#[cfg(feature = "polkadot-native")] +pub use polkadot_client::PolkadotExecutorDispatch; + pub use chain_spec::{KusamaChainSpec, PolkadotChainSpec, RococoChainSpec, WestendChainSpec}; pub use consensus_common::{block_validation::Chain, Proposal, SelectChain}; +#[cfg(feature = "full-node")] pub use polkadot_client::{ AbstractClient, Client, ClientHandle, ExecuteWithClient, FullBackend, FullClient, - PolkadotExecutorDispatch, RuntimeApiCollection, + RuntimeApiCollection, }; pub use polkadot_primitives::v1::{Block, BlockId, CollatorPair, Hash, Id as ParaId}; pub use sc_client_api::{Backend, CallExecutor, ExecutionStrategy}; @@ -110,6 +114,7 @@ pub use sp_runtime::{ #[cfg(feature = "kusama-native")] pub use kusama_runtime; +#[cfg(feature = "polkadot-native")] pub use polkadot_runtime; #[cfg(feature = "rococo-native")] pub use rococo_runtime; @@ -226,6 +231,10 @@ pub enum Error { #[cfg(feature = "full-node")] #[error("Creating a custom database is required for validators")] DatabasePathRequired, + + #[cfg(feature = "full-node")] + #[error("Expected at least one of polkadot, kusama, westend or rococo runtime feature")] + NoRuntime, } /// Can be called for a `Configuration` to identify which network the configuration targets. @@ -1268,13 +1277,19 @@ pub fn new_chain_ops( return Ok((Arc::new(Client::Westend(client)), backend, import_queue, task_manager)) } - let service::PartialComponents { client, backend, import_queue, task_manager, .. } = - new_partial::( - config, - jaeger_agent, - None, - )?; - Ok((Arc::new(Client::Polkadot(client)), backend, import_queue, task_manager)) + #[cfg(feature = "polkadot-native")] + { + let service::PartialComponents { client, backend, import_queue, task_manager, .. } = + new_partial::( + config, + jaeger_agent, + None, + )?; + return Ok((Arc::new(Client::Polkadot(client)), backend, import_queue, task_manager)) + } + + #[cfg(not(feature = "polkadot-native"))] + Err(Error::NoRuntime) } /// Build a new light node. @@ -1295,7 +1310,13 @@ pub fn build_light(config: Configuration) -> Result<(TaskManager, RpcHandlers), return new_light::(config) } - new_light::(config) + #[cfg(feature = "polkadot-native")] + { + return new_light::(config) + } + + #[cfg(not(feature = "polkadot-native"))] + Err(Error::NoRuntime) } #[cfg(feature = "full-node")] @@ -1353,15 +1374,21 @@ pub fn build_full( .map(|full| full.with_client(Client::Westend)) } - new_full::( - config, - is_collator, - grandpa_pause, - disable_beefy, - jaeger_agent, - telemetry_worker_handle, - None, - overseer_gen, - ) - .map(|full| full.with_client(Client::Polkadot)) + #[cfg(feature = "polkadot-native")] + { + return new_full::( + config, + is_collator, + grandpa_pause, + disable_beefy, + jaeger_agent, + telemetry_worker_handle, + None, + overseer_gen, + ) + .map(|full| full.with_client(Client::Polkadot)) + } + + #[cfg(not(feature = "polkadot-native"))] + Err(Error::NoRuntime) } diff --git a/polkadot/scripts/gitlab/check_no_default_features.sh b/polkadot/scripts/gitlab/check_no_default_features.sh new file mode 100755 index 0000000000..455e5e72e5 --- /dev/null +++ b/polkadot/scripts/gitlab/check_no_default_features.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -e + +pushd node/service && cargo check --no-default-features && popd +pushd cli && cargo check --no-default-features --features "service" && popd