Commit 9ff8c3ab authored by Arkadiy Paronyan's avatar Arkadiy Paronyan Committed by Gavin Wood
Browse files

Support both polkadot and kusama runtimes (#704)



* Allow both polkadot and kusama runtimes

* Allow both polkadot and kusama runtimes

* Make `collator` build

* Removed kusama runtime

* Introduced common runtime

* Updated for latest substrate

* Updated CI targets

* Updated CI version check

* Removed unused dependency

* Pulled latests substrate

* Pulled latest substrate

* Fixed version

* Apply suggestions from code review
Co-Authored-By: default avatarBastian Köcher <bkchr@users.noreply.github.com>

* NEW_HEADS_IDENTIFIER moved to primitives

* Updated CI check script

* Fixed script

* Set epoch duration for polkadot

* ci: check_runtime for both runtimes
Co-authored-by: default avatarBastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: default avatargabriel klawitter <gabreal@users.noreply.github.com>
parent dd113a7b
Pipeline #73251 passed with stages
in 17 minutes and 17 seconds
......@@ -150,12 +150,12 @@ check-web-wasm: &test
script:
# WASM support is in progress. As more and more crates support WASM, we
# should add entries here. See https://github.com/paritytech/polkadot/issues/625
- time cargo build --locked --target=wasm32-unknown-unknown --manifest-path executor/Cargo.toml
- time cargo build --locked --target=wasm32-unknown-unknown --manifest-path runtime/polkadot/Cargo.toml
- time cargo build --locked --target=wasm32-unknown-unknown --manifest-path runtime/kusama/Cargo.toml
- time cargo build --locked --target=wasm32-unknown-unknown --manifest-path erasure-coding/Cargo.toml
- time cargo build --locked --target=wasm32-unknown-unknown --manifest-path parachain/Cargo.toml
- time cargo build --locked --target=wasm32-unknown-unknown --manifest-path primitives/Cargo.toml
- time cargo build --locked --target=wasm32-unknown-unknown --manifest-path rpc/Cargo.toml
- time cargo build --locked --target=wasm32-unknown-unknown --manifest-path runtime/Cargo.toml
- time cargo build --locked --target=wasm32-unknown-unknown --manifest-path statement-table/Cargo.toml
- sccache -s
......
......@@ -2029,6 +2029,72 @@ dependencies = [
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "kusama-runtime"
version = "0.7.11"
dependencies = [
"bitvec 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
"frame-executive 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"frame-support 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"frame-system 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"frame-system-rpc-runtime-api 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libsecp256k1 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"pallet-authority-discovery 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-authorship 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-babe 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-balances 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-collective 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-democracy 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-elections-phragmen 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-finality-tracker 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-grandpa 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-identity 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-im-online 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-indices 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-membership 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-nicks 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-offences 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-randomness-collective-flip 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-session 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-staking 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-staking-reward-curve 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-timestamp 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-transaction-payment 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-transaction-payment-rpc-runtime-api 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-treasury 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-utility 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"polkadot-parachain 0.7.11",
"polkadot-primitives 0.7.11",
"polkadot-runtime-common 0.7.10",
"rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
"sp-api 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-authority-discovery 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-block-builder 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-consensus-babe 0.8.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-core 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-inherents 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-io 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-keyring 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-offchain 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-runtime 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-session 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-staking 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-std 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-transaction-pool 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-trie 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-version 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"substrate-wasm-builder-runner 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"tiny-keccak 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "kv-log-macro"
version = "1.0.4"
......@@ -3639,7 +3705,6 @@ dependencies = [
"parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"polkadot-erasure-coding 0.7.11",
"polkadot-primitives 0.7.11",
"polkadot-runtime 0.7.11",
"sc-client 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sc-client-api 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sc-keystore 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
......@@ -3686,16 +3751,16 @@ dependencies = [
"polkadot-cli 0.7.11",
"polkadot-network 0.7.11",
"polkadot-primitives 0.7.11",
"polkadot-runtime 0.7.11",
"polkadot-service 0.7.11",
"polkadot-validation 0.7.11",
"sc-client 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sc-client-api 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sc-network 0.8.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-blockchain 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-consensus 0.8.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-core 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-keyring 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -3710,14 +3775,6 @@ dependencies = [
"sp-trie 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
]
[[package]]
name = "polkadot-executor"
version = "0.7.11"
dependencies = [
"polkadot-runtime 0.7.11",
"sc-executor 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
]
[[package]]
name = "polkadot-network"
version = "0.7.11"
......@@ -3774,6 +3831,7 @@ dependencies = [
"sp-api 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-application-crypto 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-core 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-inherents 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-runtime 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-serializer 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-std 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
......@@ -3787,8 +3845,8 @@ version = "0.7.11"
dependencies = [
"jsonrpc-core 14.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"pallet-transaction-payment-rpc 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"polkadot-primitives 0.7.11",
"polkadot-runtime 0.7.11",
"sc-client 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sc-rpc 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-runtime 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
......@@ -3831,10 +3889,10 @@ dependencies = [
"pallet-transaction-payment 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-transaction-payment-rpc-runtime-api 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-treasury 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-utility 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"polkadot-parachain 0.7.11",
"polkadot-primitives 0.7.11",
"polkadot-runtime-common 0.7.10",
"rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -3846,11 +3904,9 @@ dependencies = [
"sp-consensus-babe 0.8.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-core 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-inherents 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-io 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-keyring 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-offchain 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-runtime 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-serializer 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-session 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-staking 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-std 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
......@@ -3862,21 +3918,63 @@ dependencies = [
"trie-db 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "polkadot-runtime-common"
version = "0.7.10"
dependencies = [
"bitvec 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
"frame-support 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"frame-system 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libsecp256k1 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"pallet-authorship 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-babe 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-balances 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-randomness-collective-flip 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-session 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-staking 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-staking-reward-curve 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-timestamp 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-treasury 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"polkadot-parachain 0.7.11",
"polkadot-primitives 0.7.11",
"rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
"sp-api 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-core 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-inherents 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-io 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-keyring 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-runtime 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-staking 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-std 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-trie 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"tiny-keccak 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "polkadot-service"
version = "0.7.11"
dependencies = [
"frame-system-rpc-runtime-api 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"kusama-runtime 0.7.11",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"pallet-babe 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-im-online 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-staking 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"pallet-transaction-payment-rpc-runtime-api 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"polkadot-availability-store 0.7.11",
"polkadot-executor 0.7.11",
"polkadot-network 0.7.11",
"polkadot-primitives 0.7.11",
"polkadot-rpc 0.7.11",
......@@ -3897,13 +3995,17 @@ dependencies = [
"slog 2.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"sp-api 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-authority-discovery 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-block-builder 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-blockchain 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-consensus 0.8.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-consensus-babe 0.8.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-core 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-finality-grandpa 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-inherents 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-io 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-offchain 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-runtime 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-session 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sp-transaction-pool 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
]
......@@ -3933,7 +4035,6 @@ dependencies = [
"polkadot-erasure-coding 0.7.11",
"polkadot-parachain 0.7.11",
"polkadot-primitives 0.7.11",
"polkadot-runtime 0.7.11",
"polkadot-statement-table 0.7.11",
"sc-block-builder 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sc-client-api 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
......
......@@ -24,10 +24,11 @@ members = [
"cli",
"collator",
"erasure-coding",
"executor",
"network",
"primitives",
"runtime",
"runtime/common",
"runtime/polkadot",
"runtime/kusama",
"service",
"statement-table",
"service",
......@@ -37,7 +38,8 @@ members = [
"test-parachains/adder/collator",
]
exclude = [
"runtime/wasm",
"runtime/polkadot/wasm",
"runtime/kusama/wasm",
"test-parachains/adder/wasm",
]
......
......@@ -8,7 +8,6 @@ edition = "2018"
[dependencies]
polkadot-primitives = { path = "../primitives" }
polkadot-erasure-coding = { path = "../erasure-coding" }
polkadot-runtime = { path = "../runtime" }
parking_lot = "0.9.0"
derive_more = "0.99"
log = "0.4.8"
......
......@@ -41,12 +41,19 @@ impl Default for ChainSpec {
/// Get a chain config from a spec setting.
impl ChainSpec {
pub(crate) fn load(self) -> Result<service::ChainSpec, String> {
Ok(match self {
ChainSpec::Kusama => service::chain_spec::kusama_config()?,
ChainSpec::Development => service::chain_spec::development_config(),
ChainSpec::LocalTestnet => service::chain_spec::local_testnet_config(),
ChainSpec::StagingTestnet => service::chain_spec::staging_testnet_config(),
})
match self {
ChainSpec::Development => Ok(service::chain_spec::development_config()),
ChainSpec::LocalTestnet => Ok(service::chain_spec::local_testnet_config()),
ChainSpec::StagingTestnet => Ok(service::chain_spec::staging_testnet_config()),
ChainSpec::Kusama => service::chain_spec::kusama_config(),
}
}
pub(crate) fn is_kusama(&self) -> bool {
match self {
ChainSpec::Development | ChainSpec::LocalTestnet | ChainSpec::StagingTestnet => false,
ChainSpec::Kusama => true,
}
}
pub(crate) fn from(s: &str) -> Option<Self> {
......
......@@ -26,53 +26,27 @@ mod browser;
use chain_spec::ChainSpec;
use futures::{
Future, FutureExt, TryFutureExt, future::select, channel::oneshot, compat::Future01CompatExt,
task::Spawn
};
use tokio::runtime::Runtime;
use log::{info, error};
use log::info;
use structopt::StructOpt;
pub use service::{
AbstractService, CustomConfiguration,
ProvideRuntimeApi, CoreApi, ParachainHost,
AbstractService, CustomConfiguration, ProvideRuntimeApi, CoreApi, ParachainHost, IsKusama, self,
WrappedExecutor
};
pub use cli::{VersionInfo, IntoExit, NoCustom};
pub use cli::{VersionInfo, IntoExit, NoCustom, SharedParams};
pub use cli::{display_role, error};
fn load_spec(id: &str) -> Result<Option<service::ChainSpec>, String> {
/// Load the `ChainSpec` for the given `id`.
pub fn load_spec(id: &str) -> Result<Option<service::ChainSpec>, String> {
Ok(match ChainSpec::from(id) {
Some(spec) => Some(spec.load()?),
None => None,
})
}
/// Additional worker making use of the node, to run asynchronously before shutdown.
///
/// This will be invoked with the service and spawn a future that resolves
/// when complete.
pub trait Worker: IntoExit {
/// A future that resolves when the work is done or the node should exit.
/// This will be run on a tokio runtime.
type Work: Future<Output=()> + Unpin + Send + 'static;
/// Return configuration for the polkadot node.
// TODO: make this the full configuration, so embedded nodes don't need
// string CLI args (https://github.com/paritytech/polkadot/issues/111)
fn configuration(&self) -> service::CustomConfiguration { Default::default() }
/// Do work and schedule exit.
fn work<S, SC, B, CE, SP>(self, service: &S, spawner: SP) -> Self::Work
where S: AbstractService<Block = service::Block, RuntimeApi = service::RuntimeApi,
Backend = B, SelectChain = SC,
NetworkSpecialization = service::PolkadotProtocol, CallExecutor = CE>,
SC: service::SelectChain<service::Block> + 'static,
B: service::Backend<service::Block, service::Blake2Hasher> + 'static,
CE: service::CallExecutor<service::Block, service::Blake2Hasher> + Clone + Send + Sync + 'static,
SP: Spawn + Clone + Send + Sync + 'static;
}
#[derive(Debug, StructOpt, Clone)]
enum PolkadotSubCommands {
#[structopt(name = "validation-worker", setting = structopt::clap::AppSettings::Hidden)]
......@@ -96,21 +70,58 @@ struct PolkadotSubParams {
}
/// Parses polkadot specific CLI arguments and run the service.
pub fn run<W>(worker: W, version: cli::VersionInfo) -> error::Result<()> where
W: Worker,
{
match cli::parse_and_prepare::<PolkadotSubCommands, PolkadotSubParams, _>(
pub fn run<E: IntoExit>(exit: E, version: cli::VersionInfo) -> error::Result<()> {
let cmd = cli::parse_and_prepare::<PolkadotSubCommands, PolkadotSubParams, _>(
&version,
"parity-polkadot",
std::env::args(),
) {
cli::ParseAndPrepare::Run(cmd) => cmd.run(load_spec, worker,
|worker, _cli_args, custom_args, mut config| {
);
if cmd
.shared_params()
.and_then(|p| p.chain.as_ref())
.and_then(|c| ChainSpec::from(c))
.map_or(false, |c| c.is_kusama())
{
execute_cmd_with_runtime::<
service::kusama_runtime::RuntimeApi,
service::KusamaExecutor,
service::kusama_runtime::UncheckedExtrinsic,
_
>(exit, &version, cmd)
} else {
execute_cmd_with_runtime::<
service::polkadot_runtime::RuntimeApi,
service::PolkadotExecutor,
service::polkadot_runtime::UncheckedExtrinsic,
_
>(exit, &version, cmd)
}
}
/// Execute the given `cmd` with the given runtime.
fn execute_cmd_with_runtime<R, D, E, X>(
exit: X,
version: &cli::VersionInfo,
cmd: cli::ParseAndPrepare<PolkadotSubCommands, PolkadotSubParams>,
) -> error::Result<()>
where
R: service::ConstructRuntimeApi<service::Block, service::TFullClient<service::Block, R, D>>
+ service::ConstructRuntimeApi<service::Block, service::TLightClient<service::Block, R, D>>
+ Send + Sync + 'static,
<R as service::ConstructRuntimeApi<service::Block, service::TFullClient<service::Block, R, D>>>::RuntimeApi: service::RuntimeApiCollection<E>,
<R as service::ConstructRuntimeApi<service::Block, service::TLightClient<service::Block, R, D>>>::RuntimeApi: service::RuntimeApiCollection<E>,
E: service::Codec + Send + Sync + 'static,
D: service::NativeExecutionDispatch + 'static,
X: IntoExit,
{
match cmd {
cli::ParseAndPrepare::Run(cmd) => cmd.run(&load_spec, exit,
|exit, _cli_args, custom_args, mut config| {
info!("{}", version.name);
info!(" version {}", config.full_version());
info!(" by {}, 2017-2019", version.author);
info!("Chain specification: {}", config.chain_spec.name());
if config.chain_spec.name().starts_with("Kusama") {
if config.is_kusama() {
info!("----------------------------");
info!("This chain is not in any way");
info!(" endorsed by the ");
......@@ -119,33 +130,33 @@ pub fn run<W>(worker: W, version: cli::VersionInfo) -> error::Result<()> where
}
info!("Node name: {}", config.name);
info!("Roles: {}", display_role(&config));
config.custom = worker.configuration();
config.custom = service::CustomConfiguration::default();
config.custom.authority_discovery_enabled = custom_args.authority_discovery_enabled;
let runtime = Runtime::new().map_err(|e| format!("{:?}", e))?;
match config.roles {
service::Roles::LIGHT =>
run_until_exit(
runtime,
service::new_light(config).map_err(|e| format!("{:?}", e))?,
worker
service::new_light::<R, D, E>(config).map_err(|e| format!("{:?}", e))?,
exit.into_exit(),
),
_ => run_until_exit(
runtime,
service::new_full(config).map_err(|e| format!("{:?}", e))?,
worker
service::new_full::<R, D, E>(config).map_err(|e| format!("{:?}", e))?,
exit.into_exit(),
),
}.map_err(|e| format!("{:?}", e))
}),
cli::ParseAndPrepare::BuildSpec(cmd) => cmd.run::<NoCustom, _, _, _>(load_spec),
cli::ParseAndPrepare::ExportBlocks(cmd) => cmd.run_with_builder::<(), _, _, _, _, _, _>(|config|
Ok(service::new_chain_ops(config)?), load_spec, worker),
cli::ParseAndPrepare::ImportBlocks(cmd) => cmd.run_with_builder::<(), _, _, _, _, _, _>(|config|
Ok(service::new_chain_ops(config)?), load_spec, worker),
cli::ParseAndPrepare::CheckBlock(cmd) => cmd.run_with_builder::<(), _, _, _, _, _, _>(|config|
Ok(service::new_chain_ops(config)?), load_spec, worker),
cli::ParseAndPrepare::PurgeChain(cmd) => cmd.run(load_spec),
cli::ParseAndPrepare::RevertChain(cmd) => cmd.run_with_builder::<(), _, _, _, _, _>(|config|
Ok(service::new_chain_ops(config)?), load_spec),
cli::ParseAndPrepare::BuildSpec(cmd) => cmd.run::<NoCustom, _, _, _>(&load_spec),
cli::ParseAndPrepare::ExportBlocks(cmd) => cmd.run_with_builder::<_, _, _, _, _, _, _>(|config|
Ok(service::new_chain_ops::<R, D, E>(config)?), &load_spec, exit),
cli::ParseAndPrepare::ImportBlocks(cmd) => cmd.run_with_builder::<_, _, _, _, _, _, _>(|config|
Ok(service::new_chain_ops::<R, D, E>(config)?), &load_spec, exit),
cli::ParseAndPrepare::CheckBlock(cmd) => cmd.run_with_builder::<_, _, _, _, _, _, _>(|config|
Ok(service::new_chain_ops::<R, D, E>(config)?), &load_spec, exit),
cli::ParseAndPrepare::PurgeChain(cmd) => cmd.run(&load_spec),
cli::ParseAndPrepare::RevertChain(cmd) => cmd.run_with_builder::<_, _, _, _, _, _>(|config|
Ok(service::new_chain_ops::<R, D, E>(config)?), &load_spec),
cli::ParseAndPrepare::CustomCommand(PolkadotSubCommands::ValidationWorker(args)) => {
if cfg!(feature = "browser") {
Err(error::Error::Input("Cannot run validation worker in browser".into()))
......@@ -158,19 +169,12 @@ pub fn run<W>(worker: W, version: cli::VersionInfo) -> error::Result<()> where
}
}
fn run_until_exit<T, SC, B, CE, W>(
/// Run the given `service` using the `runtime` until it exits or `e` fires.
pub fn run_until_exit(
mut runtime: Runtime,
service: T,
worker: W,
) -> error::Result<()>
where
T: AbstractService<Block = service::Block, RuntimeApi = service::RuntimeApi,
SelectChain = SC, Backend = B, NetworkSpecialization = service::PolkadotProtocol, CallExecutor = CE>,
SC: service::SelectChain<service::Block> + 'static,
B: service::Backend<service::Block, service::Blake2Hasher> + 'static,
CE: service::CallExecutor<service::Block, service::Blake2Hasher> + Clone + Send + Sync + 'static,
W: Worker,
{
service: impl AbstractService,
e: impl Future<Output = ()> + Send + Unpin + 'static,
) -> error::Result<()> {
let (exit_send, exit) = oneshot::channel();
let executor = runtime.executor();
......@@ -185,20 +189,21 @@ fn run_until_exit<T, SC, B, CE, W>(
// but we need to keep holding a reference to the global telemetry guard
let _telemetry = service.telemetry();
let work = worker.work(&service, WrappedExecutor(executor));
let service_res = {
let service = service
.map_err(|err| error!("Error while running Service: {}", err))
.map_err(|err| error::Error::Service(err))
.compat();
let future = select(service, work)
.map(|_| Ok::<_, ()>(()))
let select = select(service, e)
.map(|_| Ok(()))
.compat();
let _ = runtime.block_on(future);
runtime.block_on(select)
};
let _ = exit_send.send(());
use futures01::Future;
// TODO [andre]: timeout this future substrate/#1318
let _ = runtime.shutdown_on_idle().wait();
Ok(())
service_res
}
......@@ -11,15 +11,15 @@ client = { package = "sc-client", git = "https://github.com/paritytech/substrate
client-api = { package = "sc-client-api", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
primitives = { package = "sp-core", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
consensus_common = { package = "sp-consensus", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
polkadot-runtime = { path = "../runtime" }
polkadot-primitives = { path = "../primitives" }
polkadot-cli = { path = "../cli" }
polkadot-network = { path = "../network" }
polkadot-validation = { path = "../validation" }
polkadot-service = { path = "../service" }
log = "0.4.8"
tokio = "0.2.1"
tokio = "0.1.22"
futures-timer = "1.0"
[dev-dependencies]
......
......@@ -51,7 +51,7 @@ use std::time::Duration;
use std::pin::Pin;
use futures::{future, Future, Stream, FutureExt, TryFutureExt, StreamExt, task::Spawn};
use log::{warn, error};
use log::warn;
use client::BlockchainEvents;
use primitives::{Pair, Blake2Hasher};
use polkadot_primitives::{
......@@ -62,13 +62,12 @@ use polkadot_primitives::{
}
};
use polkadot_cli::{
Worker, IntoExit, ProvideRuntimeApi, AbstractService, CustomConfiguration, ParachainHost,
ProvideRuntimeApi, AbstractService, ParachainHost, IsKusama, WrappedExecutor,
service::{self, Roles, SelectChain}
};
use polkadot_network::validation::{LeafWorkParams, ValidationNetwork};
use polkadot_network::PolkadotProtocol;
use polkadot_runtime::RuntimeApi;
pub use polkadot_cli::VersionInfo;
pub use polkadot_cli::{VersionInfo, load_spec, service::Configuration};
pub use polkadot_network::validation::Incoming;
pub use polkadot_validation::SignedStatement;
pub use polkadot_primitives::parachain::CollatorId;
......@@ -129,7 +128,7 @@ impl<R: fmt::Display> fmt::Display for Error<R> {
}
/// The Polkadot client type.
pub type PolkadotClient<B, E> = client::Client<B, E, Block, RuntimeApi>;
pub type PolkadotClient<B, E, R> = client::Client<B, E, Block, R>;
/// Something that can build a `ParachainContext`.
pub trait BuildParachainContext {
......@@ -137,9 +136,9 @@ pub trait BuildParachainContext {
type ParachainContext: self::ParachainContext;
/// Build the `ParachainContext`.
fn build<B, E, SP>(
fn build<B, E, R, SP>(
self,
client: Arc<PolkadotClient<B, E>>,
client: Arc<PolkadotClient<B, E, R>>,
spawner: SP,
network: Arc<dyn Network>,