diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 05834f11d1944..b98e859182bc3 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -146,7 +146,7 @@ test-linux-stable: &test-linux
- awk '/^warning:/,/^$/ { print }' output.log > ${CI_COMMIT_SHORT_SHA}_warnings.log
artifacts:
name: $CI_COMMIT_SHORT_SHA
- expire_in: 24 hrs
+ expire_in: 3 days
paths:
- ${CI_COMMIT_SHORT_SHA}_warnings.log
@@ -210,7 +210,7 @@ test-linux-stable-int:
artifacts:
name: $CI_COMMIT_SHORT_SHA
when: on_failure
- expire_in: 24 hrs
+ expire_in: 3 days
paths:
- ${CI_COMMIT_SHORT_SHA}_int_failure.log
diff --git a/Cargo.lock b/Cargo.lock
index 86d274da59b81..da87ea8549aef 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3192,8 +3192,6 @@ dependencies = [
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"node-template-runtime 2.0.0",
- "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sc-basic-authorship 0.8.0",
"sc-cli 0.8.0",
"sc-client 0.8.0",
@@ -3208,12 +3206,10 @@ dependencies = [
"sp-core 2.0.0",
"sp-finality-grandpa 2.0.0",
"sp-inherents 2.0.0",
- "sp-io 2.0.0",
"sp-runtime 2.0.0",
"sp-transaction-pool 2.0.0",
"substrate-build-script-utils 2.0.0",
"tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "trie-root 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
"vergen 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -4515,6 +4511,15 @@ dependencies = [
"prost-derive 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "prost"
+version = "0.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bytes 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "prost-derive 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "prost-build"
version = "0.5.0"
@@ -4544,6 +4549,18 @@ dependencies = [
"syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "prost-derive"
+version = "0.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "anyhow 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
+ "itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "prost-types"
version = "0.5.0"
@@ -5035,7 +5052,7 @@ dependencies = [
"libp2p 0.14.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "prost 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"prost-build 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"quickcheck 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -7001,7 +7018,7 @@ version = "2.0.0"
[[package]]
name = "substrate-wasm-builder"
-version = "1.0.8"
+version = "1.0.9"
dependencies = [
"atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
"build-helper 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -8621,8 +8638,10 @@ dependencies = [
"checksum procinfo 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f42e8578852a3306838981aedad8c5642ba794929aa12af0c9eb6c072b77af6c"
"checksum prometheus 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5567486d5778e2c6455b1b90ff1c558f29e751fc018130fa182e15828e728af1"
"checksum prost 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96d14b1c185652833d24aaad41c5832b0be5616a590227c1fbff57c616754b23"
+"checksum prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce49aefe0a6144a45de32927c77bd2859a5f7677b55f220ae5b744e87389c212"
"checksum prost-build 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eb788126ea840817128183f8f603dce02cb7aea25c2a0b764359d8e20010702e"
"checksum prost-derive 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5e7dc378b94ac374644181a2247cebf59a6ec1c88b49ac77f3a94b86b79d0e11"
+"checksum prost-derive 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "537aa19b95acde10a12fec4301466386f757403de4cd4e5b4fa78fb5ecb18f72"
"checksum prost-types 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1de482a366941c8d56d19b650fac09ca08508f2a696119ee7513ad590c8bac6f"
"checksum protobuf 2.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40361836defdd5871ff7e84096c6f6444af7fc157f8ef1789f54f147687caa20"
"checksum pwasm-utils 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4f7a12f176deee919f4ba55326ee17491c8b707d0987aed822682c821b660192"
diff --git a/bin/node-template/Cargo.toml b/bin/node-template/Cargo.toml
index f956bbb22193a..cf3d7509f45d3 100644
--- a/bin/node-template/Cargo.toml
+++ b/bin/node-template/Cargo.toml
@@ -14,10 +14,6 @@ futures = "0.3.1"
ctrlc = { version = "3.1.3", features = ["termination"] }
log = "0.4.8"
tokio = { version = "0.2", features = ["rt-threaded"] }
-parking_lot = "0.9.0"
-codec = { package = "parity-scale-codec", version = "1.0.0" }
-trie-root = "0.15.2"
-sp-io = { version = "2.0.0", path = "../../primitives/io" }
sc-cli = { version = "0.8.0", path = "../../client/cli" }
sp-core = { version = "2.0.0", path = "../../primitives/core" }
sc-executor = { version = "0.8", path = "../../client/executor" }
diff --git a/bin/node-template/runtime/build.rs b/bin/node-template/runtime/build.rs
index ed0e28ec0d140..8bdf7584bb81a 100644
--- a/bin/node-template/runtime/build.rs
+++ b/bin/node-template/runtime/build.rs
@@ -1,25 +1,9 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
-// This file is part of Substrate.
-
-// Substrate is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Substrate is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Substrate. If not, see .
-
use wasm_builder_runner::{build_current_project_with_rustflags, WasmBuilderSource};
fn main() {
build_current_project_with_rustflags(
"wasm_binary.rs",
- WasmBuilderSource::Crates("1.0.8"),
+ WasmBuilderSource::Crates("1.0.9"),
// This instructs LLD to export __heap_base as a global variable, which is used by the
// external memory allocator.
"-Clink-arg=--export=__heap_base",
diff --git a/bin/node-template/src/chain_spec.rs b/bin/node-template/src/chain_spec.rs
index fae9feaf5113b..6afb67547bd6c 100644
--- a/bin/node-template/src/chain_spec.rs
+++ b/bin/node-template/src/chain_spec.rs
@@ -56,17 +56,19 @@ impl Alternative {
Alternative::Development => ChainSpec::from_genesis(
"Development",
"dev",
- || testnet_genesis(vec![
- get_authority_keys_from_seed("Alice"),
- ],
- get_account_id_from_seed::("Alice"),
- vec![
+ || testnet_genesis(
+ vec![
+ get_authority_keys_from_seed("Alice"),
+ ],
get_account_id_from_seed::("Alice"),
- get_account_id_from_seed::("Bob"),
- get_account_id_from_seed::("Alice//stash"),
- get_account_id_from_seed::("Bob//stash"),
- ],
- true),
+ vec![
+ get_account_id_from_seed::("Alice"),
+ get_account_id_from_seed::("Bob"),
+ get_account_id_from_seed::("Alice//stash"),
+ get_account_id_from_seed::("Bob//stash"),
+ ],
+ true,
+ ),
vec![],
None,
None,
@@ -76,26 +78,28 @@ impl Alternative {
Alternative::LocalTestnet => ChainSpec::from_genesis(
"Local Testnet",
"local_testnet",
- || testnet_genesis(vec![
- get_authority_keys_from_seed("Alice"),
- get_authority_keys_from_seed("Bob"),
- ],
- get_account_id_from_seed::("Alice"),
- vec![
+ || testnet_genesis(
+ vec![
+ get_authority_keys_from_seed("Alice"),
+ get_authority_keys_from_seed("Bob"),
+ ],
get_account_id_from_seed::("Alice"),
- get_account_id_from_seed::("Bob"),
- get_account_id_from_seed::("Charlie"),
- get_account_id_from_seed::("Dave"),
- get_account_id_from_seed::("Eve"),
- get_account_id_from_seed::("Ferdie"),
- get_account_id_from_seed::("Alice//stash"),
- get_account_id_from_seed::("Bob//stash"),
- get_account_id_from_seed::("Charlie//stash"),
- get_account_id_from_seed::("Dave//stash"),
- get_account_id_from_seed::("Eve//stash"),
- get_account_id_from_seed::("Ferdie//stash"),
- ],
- true),
+ vec![
+ get_account_id_from_seed::("Alice"),
+ get_account_id_from_seed::("Bob"),
+ get_account_id_from_seed::("Charlie"),
+ get_account_id_from_seed::("Dave"),
+ get_account_id_from_seed::("Eve"),
+ get_account_id_from_seed::("Ferdie"),
+ get_account_id_from_seed::("Alice//stash"),
+ get_account_id_from_seed::("Bob//stash"),
+ get_account_id_from_seed::("Charlie//stash"),
+ get_account_id_from_seed::("Dave//stash"),
+ get_account_id_from_seed::("Eve//stash"),
+ get_account_id_from_seed::("Ferdie//stash"),
+ ],
+ true,
+ ),
vec![],
None,
None,
diff --git a/bin/node-template/src/cli.rs b/bin/node-template/src/cli.rs
index 44764e5c9db41..fcfd330816cd1 100644
--- a/bin/node-template/src/cli.rs
+++ b/bin/node-template/src/cli.rs
@@ -18,7 +18,7 @@ pub fn run(args: I, exit: E, version: VersionInfo) -> error::Result<()>
type Config = Configuration<(), T>;
match parse_and_prepare::(&version, "substrate-node", args) {
ParseAndPrepare::Run(cmd) => cmd.run(load_spec, exit,
- |exit, _cli_args, _custom_args, config: Config<_>| {
+ |exit, _cli_args, _custom_args, mut config: Config<_>| {
info!("{}", version.name);
info!(" version {}", config.full_version());
info!(" by {}, 2017, 2018", version.author);
@@ -26,6 +26,10 @@ pub fn run(args: I, exit: E, version: VersionInfo) -> error::Result<()>
info!("Node name: {}", config.name);
info!("Roles: {}", display_role(&config));
let runtime = Runtime::new().map_err(|e| format!("{:?}", e))?;
+ config.tasks_executor = {
+ let runtime_handle = runtime.handle().clone();
+ Some(Box::new(move |fut| { runtime_handle.spawn(fut); }))
+ };
match config.roles {
ServiceRoles::LIGHT => run_until_exit(
runtime,
diff --git a/bin/node-template/src/main.rs b/bin/node-template/src/main.rs
index 2942bb68a37aa..ea64bc1413642 100644
--- a/bin/node-template/src/main.rs
+++ b/bin/node-template/src/main.rs
@@ -1,7 +1,5 @@
//! Substrate Node Template CLI library.
-
#![warn(missing_docs)]
-#![warn(unused_extern_crates)]
mod chain_spec;
#[macro_use]
diff --git a/bin/node/cli/src/cli.rs b/bin/node/cli/src/cli.rs
index dcc5d39dbb7e7..5ade700513e53 100644
--- a/bin/node/cli/src/cli.rs
+++ b/bin/node/cli/src/cli.rs
@@ -98,7 +98,7 @@ pub fn run(args: I, exit: E, version: sc_cli::VersionInfo) -> error::Re
match parse_and_prepare::(&version, "substrate-node", args) {
ParseAndPrepare::Run(cmd) => cmd.run(load_spec, exit,
- |exit, _cli_args, _custom_args, config: Config<_, _>| {
+ |exit, _cli_args, _custom_args, mut config: Config<_, _>| {
info!("{}", version.name);
info!(" version {}", config.full_version());
info!(" by Parity Technologies, 2017-2019");
@@ -108,8 +108,13 @@ pub fn run(args: I, exit: E, version: sc_cli::VersionInfo) -> error::Re
let runtime = RuntimeBuilder::new()
.thread_name("main-tokio-")
.threaded_scheduler()
+ .enable_all()
.build()
.map_err(|e| format!("{:?}", e))?;
+ config.tasks_executor = {
+ let runtime_handle = runtime.handle().clone();
+ Some(Box::new(move |fut| { runtime_handle.spawn(fut); }))
+ };
match config.roles {
ServiceRoles::LIGHT => run_until_exit(
runtime,
@@ -140,7 +145,12 @@ pub fn run(args: I, exit: E, version: sc_cli::VersionInfo) -> error::Re
&version,
None,
)?;
- sc_cli::fill_import_params(&mut config, &cli_args.import_params, ServiceRoles::FULL)?;
+ sc_cli::fill_import_params(
+ &mut config,
+ &cli_args.import_params,
+ ServiceRoles::FULL,
+ cli_args.shared_params.dev,
+ )?;
match ChainSpec::from(config.chain_spec.id()) {
Some(ref c) if c == &ChainSpec::Development || c == &ChainSpec::LocalTestnet => {},
diff --git a/bin/node/runtime/build.rs b/bin/node/runtime/build.rs
index 1ed2fa43e685c..9c81ea6f38b8d 100644
--- a/bin/node/runtime/build.rs
+++ b/bin/node/runtime/build.rs
@@ -21,7 +21,7 @@ fn main() {
"wasm_binary.rs",
WasmBuilderSource::CratesOrPath {
path: "../../../utils/wasm-builder",
- version: "1.0.8",
+ version: "1.0.9",
},
// This instructs LLD to export __heap_base as a global variable, which is used by the
// external memory allocator.
diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs
index d769be7b505d5..e158cbe2cbb88 100644
--- a/bin/node/runtime/src/lib.rs
+++ b/bin/node/runtime/src/lib.rs
@@ -236,14 +236,13 @@ parameter_types! {
}
impl pallet_session::Trait for Runtime {
- type OnSessionEnding = Staking;
+ type SessionManager = Staking;
type SessionHandler = ::KeyTypeIdProviders;
type ShouldEndSession = Babe;
type Event = Event;
type Keys = SessionKeys;
type ValidatorId = ::AccountId;
type ValidatorIdOf = pallet_staking::StashOf;
- type SelectInitialValidators = Staking;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
}
diff --git a/client/authority-discovery/Cargo.toml b/client/authority-discovery/Cargo.toml
index 7381e5add19a1..25c3f161d4018 100644
--- a/client/authority-discovery/Cargo.toml
+++ b/client/authority-discovery/Cargo.toml
@@ -16,7 +16,7 @@ futures = "0.3.1"
futures-timer = "2.0"
libp2p = { version = "0.14.0-alpha.1", default-features = false, features = ["secp256k1", "libp2p-websocket"] }
log = "0.4.8"
-prost = "0.5.0"
+prost = "0.6.1"
rand = "0.7.2"
sc-client-api = { version = "2.0.0", path = "../api" }
sc-keystore = { version = "2.0.0", path = "../keystore" }
diff --git a/client/authority-discovery/src/lib.rs b/client/authority-discovery/src/lib.rs
index ee2b655b925a6..6260ac9a85b12 100644
--- a/client/authority-discovery/src/lib.rs
+++ b/client/authority-discovery/src/lib.rs
@@ -315,10 +315,10 @@ where
let remote_addresses: Vec = values.into_iter()
.map(|(_k, v)| {
- let schema::SignedAuthorityAddresses {
- signature,
- addresses,
- } = schema::SignedAuthorityAddresses::decode(v).map_err(Error::DecodingProto)?;
+ let schema::SignedAuthorityAddresses { signature, addresses } =
+ schema::SignedAuthorityAddresses::decode(v.as_slice())
+ .map_err(Error::DecodingProto)?;
+
let signature = AuthoritySignature::decode(&mut &signature[..])
.map_err(Error::EncodingDecodingScale)?;
@@ -326,7 +326,7 @@ where
return Err(Error::VerifyingDhtPayload);
}
- let addresses: Vec = schema::AuthorityAddresses::decode(addresses)
+ let addresses = schema::AuthorityAddresses::decode(addresses.as_slice())
.map(|a| a.addresses)
.map_err(Error::DecodingProto)?
.into_iter()
diff --git a/client/cli/src/execution_strategy.rs b/client/cli/src/execution_strategy.rs
index fe353da80ddef..888d7b6c4a096 100644
--- a/client/cli/src/execution_strategy.rs
+++ b/client/cli/src/execution_strategy.rs
@@ -20,7 +20,7 @@ use structopt::clap::arg_enum;
arg_enum! {
/// How to execute blocks
- #[derive(Debug, Clone, Copy)]
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ExecutionStrategy {
// Execute with native build (if available, WebAssembly otherwise).
Native,
@@ -33,3 +33,25 @@ arg_enum! {
}
}
+impl ExecutionStrategy {
+ /// Returns the variant as `'&static str`.
+ pub fn as_str(&self) -> &'static str {
+ match self {
+ Self::Native => "Native",
+ Self::Wasm => "Wasm",
+ Self::Both => "Both",
+ Self::NativeElseWasm => "NativeElseWasm",
+ }
+ }
+}
+
+/// Default value for the `--execution-syncing` parameter.
+pub const DEFAULT_EXECUTION_SYNCING: ExecutionStrategy = ExecutionStrategy::NativeElseWasm;
+/// Default value for the `--execution-import-block` parameter.
+pub const DEFAULT_EXECUTION_IMPORT_BLOCK: ExecutionStrategy = ExecutionStrategy::NativeElseWasm;
+/// Default value for the `--execution-block-construction` parameter.
+pub const DEFAULT_EXECUTION_BLOCK_CONSTRUCTION: ExecutionStrategy = ExecutionStrategy::Wasm;
+/// Default value for the `--execution-offchain-worker` parameter.
+pub const DEFAULT_EXECUTION_OFFCHAIN_WORKER: ExecutionStrategy = ExecutionStrategy::Native;
+/// Default value for the `--execution-other` parameter.
+pub const DEFAULT_EXECUTION_OTHER: ExecutionStrategy = ExecutionStrategy::Native;
diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs
index 79afaa03b4269..785f1919247e0 100644
--- a/client/cli/src/lib.rs
+++ b/client/cli/src/lib.rs
@@ -40,6 +40,7 @@ use sc_network::{
},
};
use sp_core::H256;
+use execution_strategy::*;
use std::{
io::{Write, Read, Seek, Cursor, stdin, stdout, ErrorKind}, iter, fmt::Debug, fs::{self, File},
@@ -556,7 +557,12 @@ impl<'a> ParseAndPrepareImport<'a> {
self.version,
None,
)?;
- fill_import_params(&mut config, &self.params.import_params, sc_service::Roles::FULL)?;
+ fill_import_params(
+ &mut config,
+ &self.params.import_params,
+ sc_service::Roles::FULL,
+ self.params.shared_params.dev,
+ )?;
let file: Box = match self.params.input {
Some(filename) => Box::new(File::open(filename)?),
@@ -620,7 +626,12 @@ impl<'a> CheckBlock<'a> {
self.version,
None,
)?;
- fill_import_params(&mut config, &self.params.import_params, sc_service::Roles::FULL)?;
+ fill_import_params(
+ &mut config,
+ &self.params.import_params,
+ sc_service::Roles::FULL,
+ self.params.shared_params.dev,
+ )?;
fill_config_keystore_in_memory(&mut config)?;
let input = if self.params.input.starts_with("0x") { &self.params.input[2..] } else { &self.params.input[..] };
@@ -904,6 +915,7 @@ pub fn fill_import_params(
config: &mut Configuration,
cli: &ImportParams,
role: sc_service::Roles,
+ is_dev: bool,
) -> error::Result<()>
where
C: Default,
@@ -943,13 +955,22 @@ pub fn fill_import_params(
config.wasm_method = cli.wasm_method.into();
let exec = &cli.execution_strategies;
- let exec_all_or = |strat: ExecutionStrategy| exec.execution.unwrap_or(strat).into();
+ let exec_all_or = |strat: ExecutionStrategy, default: ExecutionStrategy| {
+ exec.execution.unwrap_or(if strat == default && is_dev {
+ ExecutionStrategy::Native
+ } else {
+ strat
+ }).into()
+ };
+
config.execution_strategies = ExecutionStrategies {
- syncing: exec_all_or(exec.execution_syncing),
- importing: exec_all_or(exec.execution_import_block),
- block_construction: exec_all_or(exec.execution_block_construction),
- offchain_worker: exec_all_or(exec.execution_offchain_worker),
- other: exec_all_or(exec.execution_other),
+ syncing: exec_all_or(exec.execution_syncing, DEFAULT_EXECUTION_SYNCING),
+ importing: exec_all_or(exec.execution_import_block, DEFAULT_EXECUTION_IMPORT_BLOCK),
+ block_construction:
+ exec_all_or(exec.execution_block_construction, DEFAULT_EXECUTION_BLOCK_CONSTRUCTION),
+ offchain_worker:
+ exec_all_or(exec.execution_offchain_worker, DEFAULT_EXECUTION_OFFCHAIN_WORKER),
+ other: exec_all_or(exec.execution_other, DEFAULT_EXECUTION_OTHER),
};
Ok(())
}
@@ -987,7 +1008,7 @@ where
sc_service::Roles::FULL
};
- fill_import_params(&mut config, &cli.import_params, role)?;
+ fill_import_params(&mut config, &cli.import_params, role, is_dev)?;
config.impl_name = impl_name;
config.impl_commit = version.commit;
diff --git a/client/cli/src/params.rs b/client/cli/src/params.rs
index b9aa6f172cd8c..4d5164ea7e874 100644
--- a/client/cli/src/params.rs
+++ b/client/cli/src/params.rs
@@ -18,6 +18,7 @@ use crate::traits::GetSharedParams;
use std::{str::FromStr, path::PathBuf};
use structopt::{StructOpt, StructOptInternal, clap::{arg_enum, App, AppSettings, SubCommand, Arg}};
+use crate::execution_strategy::*;
pub use crate::execution_strategy::ExecutionStrategy;
@@ -321,7 +322,7 @@ pub struct ExecutionStrategies {
value_name = "STRATEGY",
possible_values = &ExecutionStrategy::variants(),
case_insensitive = true,
- default_value = "NativeElseWasm"
+ default_value = DEFAULT_EXECUTION_SYNCING.as_str(),
)]
pub execution_syncing: ExecutionStrategy,
@@ -331,7 +332,7 @@ pub struct ExecutionStrategies {
value_name = "STRATEGY",
possible_values = &ExecutionStrategy::variants(),
case_insensitive = true,
- default_value = "NativeElseWasm"
+ default_value = DEFAULT_EXECUTION_IMPORT_BLOCK.as_str(),
)]
pub execution_import_block: ExecutionStrategy,
@@ -341,7 +342,7 @@ pub struct ExecutionStrategies {
value_name = "STRATEGY",
possible_values = &ExecutionStrategy::variants(),
case_insensitive = true,
- default_value = "Wasm"
+ default_value = DEFAULT_EXECUTION_BLOCK_CONSTRUCTION.as_str(),
)]
pub execution_block_construction: ExecutionStrategy,
@@ -351,7 +352,7 @@ pub struct ExecutionStrategies {
value_name = "STRATEGY",
possible_values = &ExecutionStrategy::variants(),
case_insensitive = true,
- default_value = "Native"
+ default_value = DEFAULT_EXECUTION_OFFCHAIN_WORKER.as_str(),
)]
pub execution_offchain_worker: ExecutionStrategy,
@@ -361,7 +362,7 @@ pub struct ExecutionStrategies {
value_name = "STRATEGY",
possible_values = &ExecutionStrategy::variants(),
case_insensitive = true,
- default_value = "Native"
+ default_value = DEFAULT_EXECUTION_OTHER.as_str(),
)]
pub execution_other: ExecutionStrategy,
diff --git a/client/consensus/slots/src/lib.rs b/client/consensus/slots/src/lib.rs
index 3aa243af72b06..c6185d5d307b9 100644
--- a/client/consensus/slots/src/lib.rs
+++ b/client/consensus/slots/src/lib.rs
@@ -45,7 +45,7 @@ use parking_lot::Mutex;
/// The changes that need to applied to the storage to create the state for a block.
///
-/// See [`state_machine::StorageChanges`] for more information.
+/// See [`sp_state_machine::StorageChanges`] for more information.
pub type StorageChanges =
sp_state_machine::StorageChanges, NumberFor>;
diff --git a/client/executor/runtime-test/build.rs b/client/executor/runtime-test/build.rs
index 1ed2fa43e685c..9c81ea6f38b8d 100644
--- a/client/executor/runtime-test/build.rs
+++ b/client/executor/runtime-test/build.rs
@@ -21,7 +21,7 @@ fn main() {
"wasm_binary.rs",
WasmBuilderSource::CratesOrPath {
path: "../../../utils/wasm-builder",
- version: "1.0.8",
+ version: "1.0.9",
},
// This instructs LLD to export __heap_base as a global variable, which is used by the
// external memory allocator.
diff --git a/client/finality-grandpa/src/communication/gossip.rs b/client/finality-grandpa/src/communication/gossip.rs
index ec74393d80ff1..7b21c1d0797d3 100644
--- a/client/finality-grandpa/src/communication/gossip.rs
+++ b/client/finality-grandpa/src/communication/gossip.rs
@@ -1445,6 +1445,7 @@ impl sc_network_gossip::Validator for GossipValidator> NetworkBridge {
return Ok(None);
}
- match &msg.message.message {
- PrimaryPropose(propose) => {
- telemetry!(CONSENSUS_INFO; "afg.received_propose";
- "voter" => ?format!("{}", msg.message.id),
- "target_number" => ?propose.target_number,
- "target_hash" => ?propose.target_hash,
- );
- },
- Prevote(prevote) => {
- telemetry!(CONSENSUS_INFO; "afg.received_prevote";
- "voter" => ?format!("{}", msg.message.id),
- "target_number" => ?prevote.target_number,
- "target_hash" => ?prevote.target_hash,
- );
- },
- Precommit(precommit) => {
- telemetry!(CONSENSUS_INFO; "afg.received_precommit";
- "voter" => ?format!("{}", msg.message.id),
- "target_number" => ?precommit.target_number,
- "target_hash" => ?precommit.target_hash,
- );
- },
- };
+ if voters.len() <= TELEMETRY_VOTERS_LIMIT {
+ match &msg.message.message {
+ PrimaryPropose(propose) => {
+ telemetry!(CONSENSUS_INFO; "afg.received_propose";
+ "voter" => ?format!("{}", msg.message.id),
+ "target_number" => ?propose.target_number,
+ "target_hash" => ?propose.target_hash,
+ );
+ },
+ Prevote(prevote) => {
+ telemetry!(CONSENSUS_INFO; "afg.received_prevote";
+ "voter" => ?format!("{}", msg.message.id),
+ "target_number" => ?prevote.target_number,
+ "target_hash" => ?prevote.target_hash,
+ );
+ },
+ Precommit(precommit) => {
+ telemetry!(CONSENSUS_INFO; "afg.received_precommit";
+ "voter" => ?format!("{}", msg.message.id),
+ "target_number" => ?precommit.target_number,
+ "target_hash" => ?precommit.target_hash,
+ );
+ },
+ };
+ }
Ok(Some(msg.message))
}
@@ -474,11 +481,13 @@ fn incoming_global(
format!("{}", a)
}).collect();
- telemetry!(CONSENSUS_INFO; "afg.received_commit";
- "contains_precommits_signed_by" => ?precommits_signed_by,
- "target_number" => ?msg.message.target_number.clone(),
- "target_hash" => ?msg.message.target_hash.clone(),
- );
+ if voters.len() <= TELEMETRY_VOTERS_LIMIT {
+ telemetry!(CONSENSUS_INFO; "afg.received_commit";
+ "contains_precommits_signed_by" => ?precommits_signed_by,
+ "target_number" => ?msg.message.target_number.clone(),
+ "target_hash" => ?msg.message.target_hash.clone(),
+ );
+ }
if let Err(cost) = check_compact_commit::(
&msg.message,
@@ -600,8 +609,28 @@ impl> Clone for NetworkBridge {
}
}
-pub(crate) fn localized_payload(round: RoundNumber, set_id: SetIdNumber, message: &E) -> Vec {
- (message, round, set_id).encode()
+/// Encode round message localized to a given round and set id.
+pub(crate) fn localized_payload(
+ round: RoundNumber,
+ set_id: SetIdNumber,
+ message: &E,
+) -> Vec {
+ let mut buf = Vec::new();
+ localized_payload_with_buffer(round, set_id, message, &mut buf);
+ buf
+}
+
+/// Encode round message localized to a given round and set id using the given
+/// buffer. The given buffer will be cleared and the resulting encoded payload
+/// will always be written to the start of the buffer.
+pub(crate) fn localized_payload_with_buffer(
+ round: RoundNumber,
+ set_id: SetIdNumber,
+ message: &E,
+ buf: &mut Vec,
+) {
+ buf.clear();
+ (message, round, set_id).encode_to(buf)
}
/// Type-safe wrapper around a round number.
@@ -612,17 +641,41 @@ pub struct Round(pub RoundNumber);
#[derive(Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Encode, Decode)]
pub struct SetId(pub SetIdNumber);
-// check a message.
+/// Check a message signature by encoding the message as a localized payload and
+/// verifying the provided signature using the expected authority id.
pub(crate) fn check_message_sig(
message: &Message,
id: &AuthorityId,
signature: &AuthoritySignature,
round: RoundNumber,
set_id: SetIdNumber,
+) -> Result<(), ()> {
+ check_message_sig_with_buffer::(
+ message,
+ id,
+ signature,
+ round,
+ set_id,
+ &mut Vec::new(),
+ )
+}
+
+/// Check a message signature by encoding the message as a localized payload and
+/// verifying the provided signature using the expected authority id.
+/// The encoding necessary to verify the signature will be done using the given
+/// buffer, the original content of the buffer will be cleared.
+pub(crate) fn check_message_sig_with_buffer(
+ message: &Message,
+ id: &AuthorityId,
+ signature: &AuthoritySignature,
+ round: RoundNumber,
+ set_id: SetIdNumber,
+ buf: &mut Vec,
) -> Result<(), ()> {
let as_public = id.clone();
- let encoded_raw = localized_payload(round, set_id, message);
- if AuthorityPair::verify(signature, &encoded_raw, &as_public) {
+ localized_payload_with_buffer(round, set_id, message, buf);
+
+ if AuthorityPair::verify(signature, buf, &as_public) {
Ok(())
} else {
debug!(target: "afg", "Bad signature on message from {:?}", id);
@@ -752,6 +805,7 @@ fn check_compact_commit(
}
// check signatures on all contained precommits.
+ let mut buf = Vec::new();
for (i, (precommit, &(ref sig, ref id))) in msg.precommits.iter()
.zip(&msg.auth_data)
.enumerate()
@@ -759,12 +813,13 @@ fn check_compact_commit(
use crate::communication::gossip::Misbehavior;
use finality_grandpa::Message as GrandpaMessage;
- if let Err(()) = check_message_sig::(
+ if let Err(()) = check_message_sig_with_buffer::(
&GrandpaMessage::Precommit(precommit.clone()),
id,
sig,
round.0,
set_id.0,
+ &mut buf,
) {
debug!(target: "afg", "Bad commit message signature {}", id);
telemetry!(CONSENSUS_DEBUG; "afg.bad_commit_msg_signature"; "id" => ?id);
@@ -836,6 +891,7 @@ fn check_catch_up(
round: RoundNumber,
set_id: SetIdNumber,
mut signatures_checked: usize,
+ buf: &mut Vec,
) -> Result where
B: BlockT,
I: Iterator- , &'a AuthorityId, &'a AuthoritySignature)>,
@@ -845,12 +901,13 @@ fn check_catch_up(
for (msg, id, sig) in messages {
signatures_checked += 1;
- if let Err(()) = check_message_sig::(
+ if let Err(()) = check_message_sig_with_buffer::(
&msg,
id,
sig,
round,
set_id,
+ buf,
) {
debug!(target: "afg", "Bad catch up message signature {}", id);
telemetry!(CONSENSUS_DEBUG; "afg.bad_catch_up_msg_signature"; "id" => ?id);
@@ -866,6 +923,8 @@ fn check_catch_up(
Ok(signatures_checked)
}
+ let mut buf = Vec::new();
+
// check signatures on all contained prevotes.
let signatures_checked = check_signatures::(
msg.prevotes.iter().map(|vote| {
@@ -874,6 +933,7 @@ fn check_catch_up(
msg.round_number,
set_id.0,
0,
+ &mut buf,
)?;
// check signatures on all contained precommits.
@@ -884,6 +944,7 @@ fn check_catch_up(
msg.round_number,
set_id.0,
signatures_checked,
+ &mut buf,
)?;
Ok(())
diff --git a/client/finality-grandpa/src/justification.rs b/client/finality-grandpa/src/justification.rs
index 308056725f67b..ad96956454fd7 100644
--- a/client/finality-grandpa/src/justification.rs
+++ b/client/finality-grandpa/src/justification.rs
@@ -132,14 +132,16 @@ impl GrandpaJustification {
}
}
+ let mut buf = Vec::new();
let mut visited_hashes = HashSet::new();
for signed in self.commit.precommits.iter() {
- if let Err(_) = communication::check_message_sig::(
+ if let Err(_) = communication::check_message_sig_with_buffer::(
&finality_grandpa::Message::Precommit(signed.precommit.clone()),
&signed.id,
&signed.signature,
self.round,
set_id,
+ &mut buf,
) {
return Err(ClientError::BadJustification(
"invalid signature for precommit in grandpa justification".to_string()).into());
diff --git a/client/network/src/protocol.rs b/client/network/src/protocol.rs
index 2aa29ea2793e3..6914ea9efe138 100644
--- a/client/network/src/protocol.rs
+++ b/client/network/src/protocol.rs
@@ -74,7 +74,7 @@ const MAX_KNOWN_BLOCKS: usize = 1024; // ~32kb per peer + LruHashSet overhead
const MAX_KNOWN_EXTRINSICS: usize = 4096; // ~128kb per peer + overhead
/// Current protocol version.
-pub(crate) const CURRENT_VERSION: u32 = 5;
+pub(crate) const CURRENT_VERSION: u32 = 6;
/// Lowest version we support
pub(crate) const MIN_VERSION: u32 = 3;
diff --git a/client/network/src/protocol/message.rs b/client/network/src/protocol/message.rs
index 30f0c34175aa5..ef7d550de6cbe 100644
--- a/client/network/src/protocol/message.rs
+++ b/client/network/src/protocol/message.rs
@@ -252,7 +252,29 @@ pub mod generic {
}
/// Status sent on connection.
+ // TODO https://github.com/paritytech/substrate/issues/4674: replace the `Status`
+ // struct with this one, after waiting a few releases beyond `NetworkSpecialization`'s
+ // removal (https://github.com/paritytech/substrate/pull/4665)
+ //
+ // and set MIN_VERSION to 6.
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
+ pub struct CompactStatus {
+ /// Protocol version.
+ pub version: u32,
+ /// Minimum supported version.
+ pub min_supported_version: u32,
+ /// Supported roles.
+ pub roles: Roles,
+ /// Best block number.
+ pub best_number: Number,
+ /// Best block hash.
+ pub best_hash: Hash,
+ /// Genesis block hash.
+ pub genesis_hash: Hash,
+ }
+
+ /// Status sent on connection.
+ #[derive(Debug, PartialEq, Eq, Clone, Encode)]
pub struct Status {
/// Protocol version.
pub version: u32,
@@ -266,10 +288,44 @@ pub mod generic {
pub best_hash: Hash,
/// Genesis block hash.
pub genesis_hash: Hash,
- /// Chain-specific status.
+ /// DEPRECATED. Chain-specific status.
pub chain_status: Vec,
}
+ impl Decode for Status {
+ fn decode(value: &mut I) -> Result {
+ const LAST_CHAIN_STATUS_VERSION: u32 = 5;
+ let compact = CompactStatus::decode(value)?;
+ let chain_status = match >::decode(value) {
+ Ok(v) => v,
+ Err(e) => if compact.version <= LAST_CHAIN_STATUS_VERSION {
+ return Err(e)
+ } else {
+ Vec::new()
+ }
+ };
+
+ let CompactStatus {
+ version,
+ min_supported_version,
+ roles,
+ best_number,
+ best_hash,
+ genesis_hash,
+ } = compact;
+
+ Ok(Status {
+ version,
+ min_supported_version,
+ roles,
+ best_number,
+ best_hash,
+ genesis_hash,
+ chain_status,
+ })
+ }
+ }
+
/// Request block data from a peer.
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
pub struct BlockRequest {
diff --git a/client/network/src/protocol/specialization.rs b/client/network/src/protocol/specialization.rs
index 9b1452160e535..af6d5f7a239cd 100644
--- a/client/network/src/protocol/specialization.rs
+++ b/client/network/src/protocol/specialization.rs
@@ -57,6 +57,32 @@ pub trait NetworkSpecialization: Send + Sync + 'static {
fn on_block_imported(&mut self, _ctx: &mut dyn Context, _hash: B::Hash, _header: &B::Header) { }
}
+/// A specialization that does nothing.
+#[derive(Clone)]
+pub struct DummySpecialization;
+
+impl NetworkSpecialization for DummySpecialization {
+ fn status(&self) -> Vec {
+ vec![]
+ }
+
+ fn on_connect(
+ &mut self,
+ _ctx: &mut dyn Context,
+ _peer_id: PeerId,
+ _status: crate::message::Status
+ ) {}
+
+ fn on_disconnect(&mut self, _ctx: &mut dyn Context, _peer_id: PeerId) {}
+
+ fn on_message(
+ &mut self,
+ _ctx: &mut dyn Context,
+ _peer_id: PeerId,
+ _message: Vec,
+ ) {}
+}
+
/// Construct a simple protocol that is composed of several sub protocols.
/// Each "sub protocol" needs to implement `Specialization` and needs to provide a `new()` function.
/// For more fine grained implementations, this macro is not usable.
diff --git a/client/network/test/src/lib.rs b/client/network/test/src/lib.rs
index f1b7fa478c6c8..1b13e83343e58 100644
--- a/client/network/test/src/lib.rs
+++ b/client/network/test/src/lib.rs
@@ -62,6 +62,7 @@ use substrate_test_runtime_client::{self, AccountKeyring};
pub use substrate_test_runtime_client::runtime::{Block, Extrinsic, Hash, Transfer};
pub use substrate_test_runtime_client::{TestClient, TestClientBuilder, TestClientBuilderExt};
+pub use sc_network::specialization::DummySpecialization;
type AuthorityId = sp_consensus_babe::AuthorityId;
@@ -101,32 +102,6 @@ impl Verifier for PassThroughVerifier {
}
}
-/// The test specialization.
-#[derive(Clone)]
-pub struct DummySpecialization;
-
-impl NetworkSpecialization for DummySpecialization {
- fn status(&self) -> Vec {
- vec![]
- }
-
- fn on_connect(
- &mut self,
- _ctx: &mut dyn Context,
- _peer_id: PeerId,
- _status: sc_network::message::Status
- ) {}
-
- fn on_disconnect(&mut self, _ctx: &mut dyn Context, _peer_id: PeerId) {}
-
- fn on_message(
- &mut self,
- _ctx: &mut dyn Context,
- _peer_id: PeerId,
- _message: Vec,
- ) {}
-}
-
pub type PeersFullClient =
sc_client::Client;
pub type PeersLightClient =
diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs
index ec336de37de32..60b0888112eec 100644
--- a/client/service/src/builder.rs
+++ b/client/service/src/builder.rs
@@ -1255,7 +1255,11 @@ ServiceBuilder<
essential_failed_rx,
to_spawn_tx,
to_spawn_rx,
- to_poll: Vec::new(),
+ tasks_executor: if let Some(exec) = config.tasks_executor {
+ exec
+ } else {
+ return Err(Error::TasksExecutorRequired);
+ },
rpc_handlers,
_rpc: rpc,
_telemetry: telemetry,
diff --git a/client/service/src/config.rs b/client/service/src/config.rs
index 994ef2e3723b9..0404018216e90 100644
--- a/client/service/src/config.rs
+++ b/client/service/src/config.rs
@@ -21,7 +21,7 @@ pub use sc_client_db::{kvdb::KeyValueDB, PruningMode};
pub use sc_network::config::{ExtTransport, NetworkConfiguration, Roles};
pub use sc_executor::WasmExecutionMethod;
-use std::{path::{PathBuf, Path}, net::SocketAddr, sync::Arc};
+use std::{future::Future, path::{PathBuf, Path}, pin::Pin, net::SocketAddr, sync::Arc};
pub use sc_transaction_pool::txpool::Options as TransactionPoolOptions;
use sc_chain_spec::{ChainSpec, RuntimeGenesis, Extension, NoExtension};
use sp_core::crypto::Protected;
@@ -29,7 +29,6 @@ use target_info::Target;
use sc_telemetry::TelemetryEndpoints;
/// Service configuration.
-#[derive(Clone)]
pub struct Configuration {
/// Implementation name
pub impl_name: &'static str,
@@ -39,6 +38,8 @@ pub struct Configuration {
pub impl_commit: &'static str,
/// Node roles.
pub roles: Roles,
+ /// How to spawn background tasks. Mandatory, otherwise creating a `Service` will error.
+ pub tasks_executor: Option + Send>>) + Send>>,
/// Extrinsic pool configuration.
pub transaction_pool: TransactionPoolOptions,
/// Network configuration.
@@ -160,6 +161,7 @@ impl Configuration where
config_dir: config_dir.clone(),
name: Default::default(),
roles: Roles::FULL,
+ tasks_executor: None,
transaction_pool: Default::default(),
network: Default::default(),
keystore: KeystoreConfig::None,
diff --git a/client/service/src/error.rs b/client/service/src/error.rs
index 4cbd172e4b2b3..e434cbf6de256 100644
--- a/client/service/src/error.rs
+++ b/client/service/src/error.rs
@@ -40,6 +40,9 @@ pub enum Error {
/// Best chain selection strategy is missing.
#[display(fmt="Best chain selection strategy (SelectChain) is not provided.")]
SelectChainRequired,
+ /// Tasks executor is missing.
+ #[display(fmt="Tasks executor hasn't been provided.")]
+ TasksExecutorRequired,
/// Other error.
Other(String),
}
diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs
index 87327d0967583..c1b87e4491904 100644
--- a/client/service/src/lib.rs
+++ b/client/service/src/lib.rs
@@ -38,7 +38,7 @@ use parking_lot::Mutex;
use sc_client::Client;
use exit_future::Signal;
use futures::{
- Future, FutureExt, Stream, StreamExt, TryFutureExt,
+ Future, FutureExt, Stream, StreamExt,
future::select, channel::mpsc,
compat::*,
sink::SinkExt,
@@ -95,10 +95,8 @@ pub struct Service {
to_spawn_tx: mpsc::UnboundedSender + Send>>>,
/// Receiver for futures that must be spawned as background tasks.
to_spawn_rx: mpsc::UnboundedReceiver + Send>>>,
- /// List of futures to poll from `poll`.
- /// If spawning a background task is not possible, we instead push the task into this `Vec`.
- /// The elements must then be polled manually.
- to_poll: Vec + Send>>>,
+ /// How to spawn background tasks.
+ tasks_executor: Box + Send>>) + Send>,
rpc_handlers: sc_rpc_server::RpcHandler,
_rpc: Box,
_telemetry: Option,
@@ -322,22 +320,7 @@ impl Future for
}
while let Poll::Ready(Some(task_to_spawn)) = Pin::new(&mut this.to_spawn_rx).poll_next(cx) {
- // TODO: Update to tokio 0.2 when libp2p get switched to std futures (#4383)
- let executor = tokio_executor::DefaultExecutor::current();
- use futures01::future::Executor;
- if let Err(err) = executor.execute(task_to_spawn.unit_error().compat()) {
- debug!(
- target: "service",
- "Failed to spawn background task: {:?}; falling back to manual polling",
- err
- );
- this.to_poll.push(Box::pin(err.into_future().compat().map(drop)));
- }
- }
-
- // Polling all the `to_poll` futures.
- while let Some(pos) = this.to_poll.iter_mut().position(|t| Pin::new(t).poll(cx).is_ready()) {
- let _ = this.to_poll.remove(pos);
+ (this.tasks_executor)(task_to_spawn);
}
// The service future never ends.
diff --git a/client/service/test/src/lib.rs b/client/service/test/src/lib.rs
index c9a01b2b2f2c8..7e3838fb2c8aa 100644
--- a/client/service/test/src/lib.rs
+++ b/client/service/test/src/lib.rs
@@ -19,9 +19,11 @@
use std::iter;
use std::sync::{Arc, Mutex, MutexGuard};
use std::net::Ipv4Addr;
+use std::pin::Pin;
use std::time::Duration;
use log::info;
use futures01::{Future, Stream, Poll};
+use futures::{FutureExt as _, TryFutureExt as _};
use tempfile::TempDir;
use tokio::{runtime::Runtime, prelude::FutureExt};
use tokio::timer::Interval;
@@ -131,6 +133,7 @@ fn node_config (
index: usize,
spec: &ChainSpec,
role: Roles,
+ tasks_executor: Box + Send>>) + Send>,
key_seed: Option,
base_port: u16,
root: &TempDir,
@@ -172,6 +175,7 @@ fn node_config (
impl_version: "0.1",
impl_commit: "",
roles: role,
+ tasks_executor: Some(tasks_executor),
transaction_pool: Default::default(),
network: network_config,
keystore: KeystoreConfig::Path {
@@ -251,10 +255,15 @@ impl TestNet where
let executor = self.runtime.executor();
for (key, authority) in authorities {
+ let tasks_executor = {
+ let executor = executor.clone();
+ Box::new(move |fut: Pin + Send>>| executor.spawn(fut.unit_error().compat()))
+ };
let node_config = node_config(
self.nodes,
&self.chain_spec,
Roles::AUTHORITY,
+ tasks_executor,
Some(key),
self.base_port,
&temp,
@@ -270,7 +279,11 @@ impl TestNet where
}
for full in full {
- let node_config = node_config(self.nodes, &self.chain_spec, Roles::FULL, None, self.base_port, &temp);
+ let tasks_executor = {
+ let executor = executor.clone();
+ Box::new(move |fut: Pin + Send>>| executor.spawn(fut.unit_error().compat()))
+ };
+ let node_config = node_config(self.nodes, &self.chain_spec, Roles::FULL, tasks_executor, None, self.base_port, &temp);
let addr = node_config.network.listen_addresses.iter().next().unwrap().clone();
let (service, user_data) = full(node_config).expect("Error creating test node service");
let service = SyncService::from(service);
@@ -282,7 +295,11 @@ impl TestNet where
}
for light in light {
- let node_config = node_config(self.nodes, &self.chain_spec, Roles::LIGHT, None, self.base_port, &temp);
+ let tasks_executor = {
+ let executor = executor.clone();
+ Box::new(move |fut: Pin + Send>>| executor.spawn(fut.unit_error().compat()))
+ };
+ let node_config = node_config(self.nodes, &self.chain_spec, Roles::LIGHT, tasks_executor, None, self.base_port, &temp);
let addr = node_config.network.listen_addresses.iter().next().unwrap().clone();
let service = SyncService::from(light(node_config).expect("Error creating test node service"));
diff --git a/client/src/lib.rs b/client/src/lib.rs
index db2d4785a2c98..8aa71c5ec5c88 100644
--- a/client/src/lib.rs
+++ b/client/src/lib.rs
@@ -20,20 +20,20 @@
//! parts:
//!
//! - A database containing the blocks and chain state, generally referred to as
-//! the [`Backend`](backend::Backend).
+//! the [`Backend`](sc_client_api::backend::Backend).
//! - A runtime environment, generally referred to as the [`Executor`](CallExecutor).
//!
//! # Initialization
//!
//! Creating a [`Client`] is done by calling the `new` method and passing to it a
-//! [`Backend`](backend::Backend) and an [`Executor`](CallExecutor).
+//! [`Backend`](sc_client_api::backend::Backend) and an [`Executor`](CallExecutor).
//!
//! The former is typically provided by the `sc-client-db` crate.
//!
//! The latter typically requires passing one of:
//!
//! - A [`LocalCallExecutor`] running the runtime locally.
-//! - A [`RemoteCallExecutor`](light::call_executor::RemoteCallExecutor) that will ask a
+//! - A [`RemoteCallExecutor`](light::call_executor::RemoteCallRequest) that will ask a
//! third-party to perform the executions.
//! - A [`RemoteOrLocalCallExecutor`](light::call_executor::RemoteOrLocalCallExecutor), combination
//! of the two.
diff --git a/frame/authority-discovery/src/lib.rs b/frame/authority-discovery/src/lib.rs
index b3911859f4787..c427043397075 100644
--- a/frame/authority-discovery/src/lib.rs
+++ b/frame/authority-discovery/src/lib.rs
@@ -109,26 +109,18 @@ mod tests {
pub struct Test;
impl Trait for Test {}
- pub struct TestOnSessionEnding;
- impl pallet_session::OnSessionEnding for TestOnSessionEnding {
- fn on_session_ending(_: SessionIndex, _: SessionIndex) -> Option> {
- None
- }
- }
-
parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(33);
}
impl pallet_session::Trait for Test {
- type OnSessionEnding = TestOnSessionEnding;
+ type SessionManager = ();
type Keys = UintAuthorityId;
type ShouldEndSession = pallet_session::PeriodicSessions;
type SessionHandler = TestSessionHandler;
type Event = ();
type ValidatorId = AuthorityId;
type ValidatorIdOf = ConvertInto;
- type SelectInitialValidators = ();
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
}
diff --git a/frame/babe/src/mock.rs b/frame/babe/src/mock.rs
index 3f0c42a6cb9c6..e65f305dc4de2 100644
--- a/frame/babe/src/mock.rs
+++ b/frame/babe/src/mock.rs
@@ -79,9 +79,8 @@ impl pallet_session::Trait for Test {
type ValidatorId = ::AccountId;
type ShouldEndSession = Babe;
type SessionHandler = (Babe,Babe,);
- type OnSessionEnding = ();
+ type SessionManager = ();
type ValidatorIdOf = ();
- type SelectInitialValidators = ();
type Keys = MockSessionKeys;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
}
diff --git a/frame/contracts/src/exec.rs b/frame/contracts/src/exec.rs
index 2c77173135077..9d786c320b5a9 100644
--- a/frame/contracts/src/exec.rs
+++ b/frame/contracts/src/exec.rs
@@ -782,7 +782,7 @@ where
fn deposit_event(&mut self, topics: Vec, data: Vec) {
self.ctx.deferred.push(DeferredAction::DepositEvent {
topics,
- event: RawEvent::Contract(self.ctx.self_account.clone(), data),
+ event: RawEvent::ContractExecution(self.ctx.self_account.clone(), data),
});
}
diff --git a/frame/contracts/src/lib.rs b/frame/contracts/src/lib.rs
index df8da8866020d..40ce86518a5e4 100644
--- a/frame/contracts/src/lib.rs
+++ b/frame/contracts/src/lib.rs
@@ -786,7 +786,12 @@ impl Module {
rent_allowance,
delta,
} => {
- let _result = Self::restore_to(donor, dest, code_hash, rent_allowance, delta);
+ let result = Self::restore_to(
+ donor.clone(), dest.clone(), code_hash.clone(), rent_allowance.clone(), delta
+ );
+ Self::deposit_event(
+ RawEvent::Restored(donor, dest, code_hash, rent_allowance, result.is_ok())
+ );
}
}
});
@@ -896,6 +901,25 @@ decl_event! {
/// Contract deployed by address at the specified address.
Instantiated(AccountId, AccountId),
+ /// Contract has been evicted and is now in tombstone state.
+ ///
+ /// # Params
+ ///
+ /// - `contract`: `AccountId`: The account ID of the evicted contract.
+ /// - `tombstone`: `bool`: True if the evicted contract left behind a tombstone.
+ Evicted(AccountId, bool),
+
+ /// Restoration for a contract has been initiated.
+ ///
+ /// # Params
+ ///
+ /// - `donor`: `AccountId`: Account ID of the restoring contract
+ /// - `dest`: `AccountId`: Account ID of the restored contract
+ /// - `code_hash`: `Hash`: Code hash of the restored contract
+ /// - `rent_allowance: `Balance`: Rent allowance of the restored contract
+ /// - `success`: `bool`: True if the restoration was successful
+ Restored(AccountId, AccountId, Hash, Balance, bool),
+
/// Code with the specified hash has been stored.
CodeStored(Hash),
@@ -906,8 +930,8 @@ decl_event! {
/// successful execution or not.
Dispatched(AccountId, bool),
- /// An event from contract of account.
- Contract(AccountId, Vec),
+ /// An event deposited upon execution of a contract from the account.
+ ContractExecution(AccountId, Vec),
}
}
diff --git a/frame/contracts/src/rent.rs b/frame/contracts/src/rent.rs
index 59c8b02d199cf..508511da4cbe3 100644
--- a/frame/contracts/src/rent.rs
+++ b/frame/contracts/src/rent.rs
@@ -14,7 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see .
-use crate::{BalanceOf, ContractInfo, ContractInfoOf, TombstoneContractInfo, Trait, AliveContractInfo};
+use crate::{Module, RawEvent, BalanceOf, ContractInfo, ContractInfoOf, TombstoneContractInfo,
+ Trait, AliveContractInfo};
use sp_runtime::traits::{Bounded, CheckedDiv, CheckedMul, Saturating, Zero,
SaturatedConversion};
use frame_support::traits::{Currency, ExistenceRequirement, Get, WithdrawReason, OnUnbalanced};
@@ -101,6 +102,7 @@ fn try_evict_or_and_pay_rent(
// The contract cannot afford to leave a tombstone, so remove the contract info altogether.
>::remove(account);
child::kill_storage(&contract.trie_id, contract.child_trie_unique_id());
+ >::deposit_event(RawEvent::Evicted(account.clone(), false));
return (RentOutcome::Evicted, None);
}
@@ -160,6 +162,8 @@ fn try_evict_or_and_pay_rent(
child::kill_storage(&contract.trie_id, contract.child_trie_unique_id());
+ >::deposit_event(RawEvent::Evicted(account.clone(), true));
+
return (RentOutcome::Evicted, Some(tombstone_info));
}
diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs
index 91679a9216a16..9a2ef36bb86f0 100644
--- a/frame/contracts/src/tests.rs
+++ b/frame/contracts/src/tests.rs
@@ -453,7 +453,7 @@ fn instantiate_and_call_and_deposit_event() {
},
EventRecord {
phase: Phase::ApplyExtrinsic(0),
- event: MetaEvent::contract(RawEvent::Contract(BOB, vec![1, 2, 3, 4])),
+ event: MetaEvent::contract(RawEvent::ContractExecution(BOB, vec![1, 2, 3, 4])),
topics: vec![],
},
EventRecord {
@@ -650,7 +650,7 @@ fn dispatch_call_not_dispatched_after_top_level_transaction_failure() {
100_000,
vec![],
),
- "during execution"
+ "contract trapped during execution"
);
assert_eq!(System::events(), vec![
EventRecord {
@@ -1139,8 +1139,16 @@ fn call_removed_contract() {
Contract::call(Origin::signed(ALICE), BOB, 0, 100_000, call::null()),
"contract has been evicted"
);
+ // Calling a contract that is about to evict shall emit an event.
+ assert_eq!(System::events(), vec![
+ EventRecord {
+ phase: Phase::ApplyExtrinsic(0),
+ event: MetaEvent::contract(RawEvent::Evicted(BOB, true)),
+ topics: vec![],
+ },
+ ]);
- // Subsequent contract calls should also fail.
+ // Subsequent contract calls should also fail.
assert_err!(
Contract::call(Origin::signed(ALICE), BOB, 0, 100_000, call::null()),
"contract has been evicted"
@@ -1367,6 +1375,9 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
// Advance 4 blocks, to the 5th.
initialize_block(5);
+ /// Preserve `BOB`'s code hash for later introspection.
+ let bob_code_hash = ContractInfoOf::::get(BOB).unwrap()
+ .get_alive().unwrap().code_hash;
// Call `BOB`, which makes it pay rent. Since the rent allowance is set to 0
// we expect that it will get removed leaving tombstone.
assert_err!(
@@ -1374,6 +1385,15 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
"contract has been evicted"
);
assert!(ContractInfoOf::::get(BOB).unwrap().get_tombstone().is_some());
+ assert_eq!(System::events(), vec![
+ EventRecord {
+ phase: Phase::ApplyExtrinsic(0),
+ event: MetaEvent::contract(
+ RawEvent::Evicted(BOB.clone(), true)
+ ),
+ topics: vec![],
+ },
+ ]);
/// Create another account with the address `DJANGO` with `CODE_RESTORATION`.
///
@@ -1416,6 +1436,60 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
assert_eq!(django_contract.storage_size, 16);
assert_eq!(django_contract.trie_id, django_trie_id);
assert_eq!(django_contract.deduct_block, System::block_number());
+ match (test_different_storage, test_restore_to_with_dirty_storage) {
+ (true, false) => {
+ assert_eq!(System::events(), vec![
+ EventRecord {
+ phase: Phase::ApplyExtrinsic(0),
+ event: MetaEvent::contract(
+ RawEvent::Restored(DJANGO, BOB, bob_code_hash, 50, false)
+ ),
+ topics: vec![],
+ },
+ ]);
+ }
+ (_, true) => {
+ assert_eq!(System::events(), vec![
+ EventRecord {
+ phase: Phase::ApplyExtrinsic(0),
+ event: MetaEvent::contract(RawEvent::Evicted(BOB, true)),
+ topics: vec![],
+ },
+ EventRecord {
+ phase: Phase::ApplyExtrinsic(0),
+ event: MetaEvent::balances(pallet_balances::RawEvent::NewAccount(CHARLIE, 1_000_000)),
+ topics: vec![],
+ },
+ EventRecord {
+ phase: Phase::ApplyExtrinsic(0),
+ event: MetaEvent::balances(pallet_balances::RawEvent::NewAccount(DJANGO, 30_000)),
+ topics: vec![],
+ },
+ EventRecord {
+ phase: Phase::ApplyExtrinsic(0),
+ event: MetaEvent::contract(RawEvent::Transfer(CHARLIE, DJANGO, 30_000)),
+ topics: vec![],
+ },
+ EventRecord {
+ phase: Phase::ApplyExtrinsic(0),
+ event: MetaEvent::contract(RawEvent::Instantiated(CHARLIE, DJANGO)),
+ topics: vec![],
+ },
+ EventRecord {
+ phase: Phase::ApplyExtrinsic(0),
+ event: MetaEvent::contract(RawEvent::Restored(
+ DJANGO,
+ BOB,
+ bob_code_hash,
+ 50,
+ false,
+ )),
+ topics: vec![],
+ },
+ ]);
+ }
+ _ => unreachable!(),
+ }
} else {
// Here we expect that the restoration is succeeded. Check that the restoration
// contract `DJANGO` ceased to exist and that `BOB` returned back.
@@ -1427,6 +1501,20 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
assert_eq!(bob_contract.trie_id, django_trie_id);
assert_eq!(bob_contract.deduct_block, System::block_number());
assert!(ContractInfoOf::::get(DJANGO).is_none());
+ assert_eq!(System::events(), vec![
+ EventRecord {
+ phase: Phase::ApplyExtrinsic(0),
+ event: MetaEvent::balances(balances::RawEvent::ReapedAccount(DJANGO, 0)),
+ topics: vec![],
+ },
+ EventRecord {
+ phase: Phase::ApplyExtrinsic(0),
+ event: MetaEvent::contract(
+ RawEvent::Restored(DJANGO, BOB, bob_contract.code_hash, 50, true)
+ ),
+ topics: vec![],
+ },
+ ]);
}
});
}
@@ -1533,7 +1621,7 @@ fn storage_max_value_limit() {
100_000,
Encode::encode(&(self::MaxValueSize::get() + 1)),
),
- "during execution"
+ "contract trapped during execution"
);
});
}
@@ -2056,7 +2144,7 @@ fn cannot_self_destruct_while_live() {
100_000,
vec![0],
),
- "during execution"
+ "contract trapped during execution"
);
// Check that BOB is still alive.
diff --git a/frame/contracts/src/wasm/mod.rs b/frame/contracts/src/wasm/mod.rs
index 8e02eb482bb8a..60402cf3a09cf 100644
--- a/frame/contracts/src/wasm/mod.rs
+++ b/frame/contracts/src/wasm/mod.rs
@@ -1430,7 +1430,9 @@ mod tests {
MockExt::default(),
&mut gas_meter
),
- Err(ExecError { reason: DispatchError::Other("during execution"), buffer: _ })
+ Err(ExecError {
+ reason: DispatchError::Other("contract trapped during execution"), buffer: _
+ })
);
}
@@ -1472,7 +1474,7 @@ mod tests {
MockExt::default(),
&mut gas_meter
),
- Err(ExecError { reason: DispatchError::Other("during execution"), buffer: _ })
+ Err(ExecError { reason: DispatchError::Other("contract trapped during execution"), buffer: _ })
);
}
diff --git a/frame/contracts/src/wasm/runtime.rs b/frame/contracts/src/wasm/runtime.rs
index 81b0809f82b02..75751b6d359a3 100644
--- a/frame/contracts/src/wasm/runtime.rs
+++ b/frame/contracts/src/wasm/runtime.rs
@@ -109,7 +109,7 @@ pub(crate) fn to_execution_result(
Err(ExecError { reason: "validation error".into(), buffer: runtime.scratch_buf }),
// Any other kind of a trap should result in a failure.
Err(sp_sandbox::Error::Execution) | Err(sp_sandbox::Error::OutOfBounds) =>
- Err(ExecError { reason: "during execution".into(), buffer: runtime.scratch_buf }),
+ Err(ExecError { reason: "contract trapped during execution".into(), buffer: runtime.scratch_buf }),
}
}
diff --git a/frame/im-online/src/mock.rs b/frame/im-online/src/mock.rs
index 387ff47c09fa5..5c428c38582ff 100644
--- a/frame/im-online/src/mock.rs
+++ b/frame/im-online/src/mock.rs
@@ -43,28 +43,25 @@ thread_local! {
pub static VALIDATORS: RefCell