, Error> {
- let p = utils::pair_from_suri::(uri, pass)?;
- Ok(p.public().as_ref().to_vec())
-}
diff --git a/client/cli/src/commands/insert_key.rs b/client/cli/src/commands/insert_key.rs
new file mode 100644
index 0000000000000000000000000000000000000000..90588f96d20b03bd683612d9d72b7cbddb2baf41
--- /dev/null
+++ b/client/cli/src/commands/insert_key.rs
@@ -0,0 +1,173 @@
+// This file is part of Substrate.
+
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: Apache-2.0
+
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+//! Implementation of the `insert` subcommand
+
+use crate::{
+ Error, KeystoreParams, CryptoSchemeFlag, SharedParams, utils, with_crypto_scheme,
+ SubstrateCli,
+};
+use std::{sync::Arc, convert::TryFrom};
+use structopt::StructOpt;
+use sp_core::{crypto::KeyTypeId, crypto::SecretString};
+use sp_keystore::{SyncCryptoStorePtr, SyncCryptoStore};
+use sc_keystore::LocalKeystore;
+use sc_service::config::{KeystoreConfig, BasePath};
+
+/// The `insert` command
+#[derive(Debug, StructOpt)]
+#[structopt(
+ name = "insert",
+ about = "Insert a key to the keystore of a node."
+)]
+pub struct InsertKeyCmd {
+ /// The secret key URI.
+ /// If the value is a file, the file content is used as URI.
+ /// If not given, you will be prompted for the URI.
+ #[structopt(long)]
+ suri: Option,
+
+ /// Key type, examples: "gran", or "imon"
+ #[structopt(long)]
+ key_type: String,
+
+ #[allow(missing_docs)]
+ #[structopt(flatten)]
+ pub shared_params: SharedParams,
+
+ #[allow(missing_docs)]
+ #[structopt(flatten)]
+ pub keystore_params: KeystoreParams,
+
+ #[allow(missing_docs)]
+ #[structopt(flatten)]
+ pub crypto_scheme: CryptoSchemeFlag,
+}
+
+impl InsertKeyCmd {
+ /// Run the command
+ pub fn run(&self, cli: &C) -> Result<(), Error> {
+ let suri = utils::read_uri(self.suri.as_ref())?;
+ let base_path = self.shared_params
+ .base_path()
+ .unwrap_or_else(|| BasePath::from_project("", "", &C::executable_name()));
+ let chain_id = self.shared_params.chain_id(self.shared_params.is_dev());
+ let chain_spec = cli.load_spec(&chain_id)?;
+ let config_dir = base_path.config_dir(chain_spec.id());
+
+ let (keystore, public) = match self.keystore_params.keystore_config(&config_dir)? {
+ (_, KeystoreConfig::Path { path, password }) => {
+ let public = with_crypto_scheme!(
+ self.crypto_scheme.scheme,
+ to_vec(&suri, password.clone())
+ )?;
+ let keystore: SyncCryptoStorePtr = Arc::new(LocalKeystore::open(path, password)?);
+ (keystore, public)
+ },
+ _ => unreachable!("keystore_config always returns path and password; qed")
+ };
+
+ let key_type = KeyTypeId::try_from(self.key_type.as_str()).map_err(|_| Error::KeyTypeInvalid)?;
+
+ SyncCryptoStore::insert_unknown(&*keystore, key_type, &suri, &public[..])
+ .map_err(|_| Error::KeyStoreOperation)?;
+
+ Ok(())
+ }
+}
+
+fn to_vec(uri: &str, pass: Option) -> Result, Error> {
+ let p = utils::pair_from_suri::(uri, pass)?;
+ Ok(p.public().as_ref().to_vec())
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use structopt::StructOpt;
+ use tempfile::TempDir;
+ use sp_core::{sr25519::Pair, Pair as _, Public};
+ use sc_service::{ChainSpec, GenericChainSpec, ChainType, NoExtension};
+
+ struct Cli;
+
+ impl SubstrateCli for Cli {
+ fn impl_name() -> String {
+ "test".into()
+ }
+
+ fn impl_version() -> String {
+ "2.0".into()
+ }
+
+ fn description() -> String {
+ "test".into()
+ }
+
+ fn support_url() -> String {
+ "test.test".into()
+ }
+
+ fn copyright_start_year() -> i32 {
+ 2020
+ }
+
+ fn author() -> String {
+ "test".into()
+ }
+
+ fn native_runtime_version(_: &Box) -> &'static sp_version::RuntimeVersion {
+ unimplemented!("Not required in tests")
+ }
+
+ fn load_spec(&self, _: &str) -> std::result::Result, String> {
+ Ok(
+ Box::new(
+ GenericChainSpec::from_genesis(
+ "test",
+ "test_id",
+ ChainType::Development,
+ || unimplemented!("Not required in tests"),
+ Vec::new(),
+ None,
+ None,
+ None,
+ NoExtension::None,
+ ),
+ ),
+ )
+ }
+ }
+
+ #[test]
+ fn insert_with_custom_base_path() {
+ let path = TempDir::new().unwrap();
+ let path_str = format!("{}", path.path().display());
+ let (key, uri, _) = Pair::generate_with_phrase(None);
+
+ let inspect = InsertKeyCmd::from_iter(
+ &["insert-key", "-d", &path_str, "--key-type", "test", "--suri", &uri],
+ );
+ assert!(inspect.run(&Cli).is_ok());
+
+ let keystore = LocalKeystore::open(
+ path.path().join("chains").join("test_id").join("keystore"),
+ None,
+ ).unwrap();
+ assert!(keystore.has_keys(&[(key.public().to_raw_vec(), KeyTypeId(*b"test"))]));
+ }
+}
diff --git a/client/cli/src/commands/inspect_key.rs b/client/cli/src/commands/inspect_key.rs
index fb3a7ef4f3b4413856ac738abc639d98f10378bc..2642eee88adcdd944b7b3a160417a99841eb433a 100644
--- a/client/cli/src/commands/inspect_key.rs
+++ b/client/cli/src/commands/inspect_key.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/client/cli/src/commands/inspect_node_key.rs b/client/cli/src/commands/inspect_node_key.rs
index be0b88589d5e9dfd2cc84d0a543ba2ccb4cd836f..4db32aefb5fbb51f1cb8e3719f8900e54dc8b275 100644
--- a/client/cli/src/commands/inspect_node_key.rs
+++ b/client/cli/src/commands/inspect_node_key.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/client/cli/src/commands/key.rs b/client/cli/src/commands/key.rs
index e5bce08145cb8bd482b1b150b81be8e3b2a1b5e2..546454159718d6da5f76de6029dd612e6fa14020 100644
--- a/client/cli/src/commands/key.rs
+++ b/client/cli/src/commands/key.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,11 +17,11 @@
//! Key related CLI utilities
-use crate::Error;
+use crate::{Error, SubstrateCli};
use structopt::StructOpt;
use super::{
- insert::InsertCmd,
+ insert_key::InsertKeyCmd,
inspect_key::InspectKeyCmd,
generate::GenerateCmd,
inspect_node_key::InspectNodeKeyCmd,
@@ -45,17 +45,17 @@ pub enum KeySubcommand {
InspectNodeKey(InspectNodeKeyCmd),
/// Insert a key to the keystore of a node.
- Insert(InsertCmd),
+ Insert(InsertKeyCmd),
}
impl KeySubcommand {
/// run the key subcommands
- pub fn run(&self) -> Result<(), Error> {
+ pub fn run(&self, cli: &C) -> Result<(), Error> {
match self {
KeySubcommand::GenerateNodeKey(cmd) => cmd.run(),
KeySubcommand::Generate(cmd) => cmd.run(),
KeySubcommand::InspectKey(cmd) => cmd.run(),
- KeySubcommand::Insert(cmd) => cmd.run(),
+ KeySubcommand::Insert(cmd) => cmd.run(cli),
KeySubcommand::InspectNodeKey(cmd) => cmd.run(),
}
}
diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs
index 9867f61cd277fc626144d5ba8d3aedbe73032c3e..8c0d6acd6a51159bc6ec83fe275895ff44a34a51 100644
--- a/client/cli/src/commands/mod.rs
+++ b/client/cli/src/commands/mod.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
@@ -28,7 +28,7 @@ mod revert_cmd;
mod run_cmd;
mod generate_node_key;
mod generate;
-mod insert;
+mod insert_key;
mod inspect_node_key;
mod inspect_key;
mod key;
@@ -43,7 +43,7 @@ pub use self::{
purge_chain_cmd::PurgeChainCmd,
sign::SignCmd,
generate::GenerateCmd,
- insert::InsertCmd,
+ insert_key::InsertKeyCmd,
inspect_key::InspectKeyCmd,
generate_node_key::GenerateNodeKeyCmd,
inspect_node_key::InspectNodeKeyCmd,
diff --git a/client/cli/src/commands/purge_chain_cmd.rs b/client/cli/src/commands/purge_chain_cmd.rs
index 9c9c6e91fb2416c56e8a6e9a3894a8a7aeb31c10..1902d92e6345ad166c557e21012097040a2ab71c 100644
--- a/client/cli/src/commands/purge_chain_cmd.rs
+++ b/client/cli/src/commands/purge_chain_cmd.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/cli/src/commands/revert_cmd.rs b/client/cli/src/commands/revert_cmd.rs
index b2e3c1bf8e2b674e4313253aa6abd2431701d587..2745ce2c652417b53bbadb90ace51e2cf9d207fd 100644
--- a/client/cli/src/commands/revert_cmd.rs
+++ b/client/cli/src/commands/revert_cmd.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/cli/src/commands/run_cmd.rs b/client/cli/src/commands/run_cmd.rs
index 019b760e5b4aefc394b01fb29e29ece2ee1956e8..bbb8d6f68d7f97e162efbac1b201a2d49e069407 100644
--- a/client/cli/src/commands/run_cmd.rs
+++ b/client/cli/src/commands/run_cmd.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
@@ -75,7 +75,8 @@ pub struct RunCmd {
/// Listen to all RPC interfaces.
///
/// Default is local. Note: not all RPC methods are safe to be exposed publicly. Use an RPC proxy
- /// server to filter out dangerous methods. More details: https://github.com/paritytech/substrate/wiki/Public-RPC.
+ /// server to filter out dangerous methods. More details:
+ /// .
/// Use `--unsafe-rpc-external` to suppress the warning if you understand the risks.
#[structopt(long = "rpc-external")]
pub rpc_external: bool,
@@ -105,7 +106,7 @@ pub struct RunCmd {
/// Listen to all Websocket interfaces.
///
/// Default is local. Note: not all RPC methods are safe to be exposed publicly. Use an RPC proxy
- /// server to filter out dangerous methods. More details: https://github.com/paritytech/substrate/wiki/Public-RPC.
+ /// server to filter out dangerous methods. More details: .
/// Use `--unsafe-ws-external` to suppress the warning if you understand the risks.
#[structopt(long = "ws-external")]
pub ws_external: bool,
@@ -142,7 +143,7 @@ pub struct RunCmd {
///
/// A comma-separated list of origins (protocol://domain or special `null`
/// value). Value of `all` will disable origin validation. Default is to
- /// allow localhost and https://polkadot.js.org origins. When running in
+ /// allow localhost and origins. When running in
/// --dev mode the default is to allow all origins.
#[structopt(long = "rpc-cors", value_name = "ORIGINS", parse(try_from_str = parse_cors))]
pub rpc_cors: Option,
diff --git a/client/cli/src/commands/sign.rs b/client/cli/src/commands/sign.rs
index 605fd5b12313f0c75fee8eef4951fafe9ee9f680..a39e14697b9956bf577c601b72969e265ba9184f 100644
--- a/client/cli/src/commands/sign.rs
+++ b/client/cli/src/commands/sign.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs
index 6e48d04e1328bda8ca234dd3e4bec2f2d1263f9b..1bbff392eca435b902729f725a912ee65c69d012 100644
--- a/client/cli/src/commands/utils.rs
+++ b/client/cli/src/commands/utils.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
@@ -57,7 +57,7 @@ pub fn read_uri(uri: Option<&String>) -> error::Result {
/// 2. Try to construct the `Pair` while using `uri` as input for [`sp_core::Pair::from_string_with_seed`].
///
/// 3. Try to construct the `Pair::Public` while using `uri` as input for
-/// [`sp_core::Pair::Public::from_string_with_version`].
+/// [`sp_core::crypto::Ss58Codec::from_string_with_version`].
pub fn print_from_uri(
uri: &str,
password: Option,
diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs
index 33b9025c13fbc2e8e3c82a20205ba97ac7a74c5b..da47e8bb26cc870b1eea88048894b3cd2efeef47 100644
--- a/client/cli/src/commands/vanity.rs
+++ b/client/cli/src/commands/vanity.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/cli/src/commands/verify.rs b/client/cli/src/commands/verify.rs
index 15abc04002f4c891d9be4f655e6915c6b7d28780..f5bd5a06060c6add64815e52d656de5f7d5038f8 100644
--- a/client/cli/src/commands/verify.rs
+++ b/client/cli/src/commands/verify.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/cli/src/config.rs b/client/cli/src/config.rs
index bf6b444c4d7330e201cf97517b04a7cae4f62b38..017d2b421683fd2357b03daacb9cc77a63ffa486 100644
--- a/client/cli/src/config.rs
+++ b/client/cli/src/config.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
@@ -22,7 +22,7 @@ use crate::arg_enums::Database;
use crate::error::Result;
use crate::{
init_logger, DatabaseParams, ImportParams, KeystoreParams, NetworkParams, NodeKeyParams,
- OffchainWorkerParams, PruningParams, SharedParams, SubstrateCli,
+ OffchainWorkerParams, PruningParams, SharedParams, SubstrateCli, InitLoggerParams,
};
use log::warn;
use names::{Generator, Name};
@@ -47,7 +47,7 @@ const RECOMMENDED_OPEN_FILE_DESCRIPTOR_LIMIT: u64 = 10_000;
/// Default configuration values used by Substrate
///
-/// These values will be used by [`CliConfiguritation`] to set
+/// These values will be used by [`CliConfiguration`] to set
/// default values for e.g. the listen port or the RPC port.
pub trait DefaultConfigurationValues {
/// The port Substrate should listen on for p2p connections.
@@ -186,11 +186,11 @@ pub trait CliConfiguration: Sized {
/// Get the keystore configuration.
///
- /// Bu default this is retrieved from `KeystoreParams` if it is available. Otherwise it uses
+ /// By default this is retrieved from `KeystoreParams` if it is available. Otherwise it uses
/// `KeystoreConfig::InMemory`.
- fn keystore_config(&self, base_path: &PathBuf) -> Result<(Option, KeystoreConfig)> {
+ fn keystore_config(&self, config_dir: &PathBuf) -> Result<(Option, KeystoreConfig)> {
self.keystore_params()
- .map(|x| x.keystore_config(base_path))
+ .map(|x| x.keystore_config(config_dir))
.unwrap_or_else(|| Ok((None, KeystoreConfig::InMemory)))
}
@@ -454,15 +454,11 @@ pub trait CliConfiguration: Sized {
) -> Result {
let is_dev = self.is_dev()?;
let chain_id = self.chain_id(is_dev)?;
- let chain_spec = cli.load_spec(chain_id.as_str())?;
+ let chain_spec = cli.load_spec(&chain_id)?;
let base_path = self
.base_path()?
.unwrap_or_else(|| BasePath::from_project("", "", &C::executable_name()));
- let config_dir = base_path
- .path()
- .to_path_buf()
- .join("chains")
- .join(chain_spec.id());
+ let config_dir = base_path.config_dir(chain_spec.id());
let net_config_dir = config_dir.join(DEFAULT_NETWORK_CONFIG_PATH);
let client_id = C::client_id();
let database_cache_size = self.database_cache_size()?.unwrap_or(128);
@@ -542,6 +538,11 @@ pub trait CliConfiguration: Sized {
Ok(self.shared_params().is_log_filter_reloading_disabled())
}
+ /// Should the log color output be disabled?
+ fn disable_log_color(&self) -> Result {
+ Ok(self.shared_params().disable_log_color())
+ }
+
/// Initialize substrate. This must be done only once per process.
///
/// This method:
@@ -554,15 +555,17 @@ pub trait CliConfiguration: Sized {
let tracing_receiver = self.tracing_receiver()?;
let tracing_targets = self.tracing_targets()?;
let disable_log_reloading = self.is_log_filter_reloading_disabled()?;
+ let disable_log_color = self.disable_log_color()?;
sp_panic_handler::set(&C::support_url(), &C::impl_version());
- init_logger(
- &logger_pattern,
+ init_logger(InitLoggerParams {
+ pattern: logger_pattern,
tracing_receiver,
tracing_targets,
disable_log_reloading,
- )?;
+ disable_log_color,
+ })?;
if let Some(new_limit) = fdlimit::raise_fd_limit() {
if new_limit < RECOMMENDED_OPEN_FILE_DESCRIPTOR_LIMIT {
diff --git a/client/cli/src/error.rs b/client/cli/src/error.rs
index 5190cae2c2ff89edc1b9a3916afe428c3969f51a..75867e2f76b280992b43ee1485515f739abee3df 100644
--- a/client/cli/src/error.rs
+++ b/client/cli/src/error.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
@@ -59,9 +59,6 @@ pub enum Error {
expected: usize,
},
- #[error("The base path is missing, please provide one")]
- MissingBasePath,
-
#[error("Unknown key type, must be a known 4-character sequence")]
KeyTypeInvalid,
diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs
index 80882924bd3ad2c67a2e16aba571c5a58bc46640..1402e5e7ae44c64d3e92f8a9c30da49311c78b41 100644
--- a/client/cli/src/lib.rs
+++ b/client/cli/src/lib.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
@@ -112,10 +112,7 @@ pub trait SubstrateCli: Sized {
///
/// Gets the struct from the command line arguments. Print the
/// error message and quit the program in case of failure.
- fn from_args() -> Self
- where
- Self: StructOpt + Sized,
- {
+ fn from_args() -> Self where Self: StructOpt + Sized {
::from_iter(&mut std::env::args_os())
}
@@ -240,30 +237,50 @@ pub trait SubstrateCli: Sized {
fn native_runtime_version(chain_spec: &Box) -> &'static RuntimeVersion;
}
+/// The parameters for [`init_logger`].
+#[derive(Default)]
+pub struct InitLoggerParams {
+ /// A comma seperated list of logging patterns.
+ ///
+ /// E.g.: `test-crate=debug`
+ pub pattern: String,
+ /// The tracing receiver.
+ pub tracing_receiver: sc_tracing::TracingReceiver,
+ /// Optional comma seperated list of tracing targets.
+ pub tracing_targets: Option,
+ /// Should log reloading be disabled?
+ pub disable_log_reloading: bool,
+ /// Should the log color output be disabled?
+ pub disable_log_color: bool,
+}
+
/// Initialize the global logger
///
/// This sets various global logging and tracing instances and thus may only be called once.
pub fn init_logger(
- pattern: &str,
- tracing_receiver: sc_tracing::TracingReceiver,
- profiling_targets: Option,
- disable_log_reloading: bool,
+ InitLoggerParams {
+ pattern,
+ tracing_receiver,
+ tracing_targets,
+ disable_log_reloading,
+ disable_log_color,
+ }: InitLoggerParams,
) -> std::result::Result<(), String> {
use sc_tracing::parse_default_directive;
// Accept all valid directives and print invalid ones
- fn parse_user_directives(mut env_filter: EnvFilter, dirs: &str) -> std::result::Result {
+ fn parse_user_directives(
+ mut env_filter: EnvFilter,
+ dirs: &str,
+ ) -> std::result::Result {
for dir in dirs.split(',') {
env_filter = env_filter.add_directive(parse_default_directive(&dir)?);
}
Ok(env_filter)
}
- if let Err(e) = tracing_log::LogTracer::init() {
- return Err(format!(
- "Registering Substrate logger failed: {:}!", e
- ))
- }
+ tracing_log::LogTracer::init()
+ .map_err(|e| format!("Registering Substrate logger failed: {:}!", e))?;
// Initialize filter - ensure to use `parse_default_directive` for any defaults to persist
// after log filter reloading by RPC
@@ -293,7 +310,7 @@ pub fn init_logger(
if pattern != "" {
// We're not sure if log or tracing is available at this moment, so silently ignore the
// parse error.
- env_filter = parse_user_directives(env_filter, pattern)?;
+ env_filter = parse_user_directives(env_filter, &pattern)?;
}
// If we're only logging `INFO` entries then we'll use a simplified logging format.
@@ -311,11 +328,11 @@ pub fn init_logger(
);
// Make sure to include profiling targets in the filter
- if let Some(profiling_targets) = profiling_targets.clone() {
- env_filter = parse_user_directives(env_filter, &profiling_targets)?;
+ if let Some(tracing_targets) = tracing_targets.clone() {
+ env_filter = parse_user_directives(env_filter, &tracing_targets)?;
}
- let enable_color = atty::is(atty::Stream::Stderr);
+ let enable_color = atty::is(atty::Stream::Stderr) && !disable_log_color;
let timer = ChronoLocal::with_format(if simple {
"%Y-%m-%d %H:%M:%S".to_string()
} else {
@@ -336,7 +353,7 @@ pub fn init_logger(
let subscriber = subscriber_builder
.finish()
.with(logging::NodeNameLayer);
- initialize_tracing(subscriber, tracing_receiver, profiling_targets)
+ initialize_tracing(subscriber, tracing_receiver, tracing_targets)
} else {
let subscriber_builder = subscriber_builder.with_filter_reloading();
let handle = subscriber_builder.reload_handle();
@@ -344,7 +361,7 @@ pub fn init_logger(
let subscriber = subscriber_builder
.finish()
.with(logging::NodeNameLayer);
- initialize_tracing(subscriber, tracing_receiver, profiling_targets)
+ initialize_tracing(subscriber, tracing_receiver, tracing_targets)
}
}
@@ -383,7 +400,9 @@ mod tests {
#[test]
fn test_logger_filters() {
let test_pattern = "afg=debug,sync=trace,client=warn,telemetry,something-with-dash=error";
- init_logger(&test_pattern, Default::default(), Default::default(), false).unwrap();
+ init_logger(
+ InitLoggerParams { pattern: test_pattern.into(), ..Default::default() },
+ ).unwrap();
tracing::dispatcher::get_default(|dispatcher| {
let test_filter = |target, level| {
@@ -442,7 +461,9 @@ mod tests {
fn log_something_with_dash_target_name() {
if env::var("ENABLE_LOGGING").is_ok() {
let test_pattern = "test-target=info";
- init_logger(&test_pattern, Default::default(), Default::default(), false).unwrap();
+ init_logger(
+ InitLoggerParams { pattern: test_pattern.into(), ..Default::default() },
+ ).unwrap();
log::info!(target: "test-target", "{}", EXPECTED_LOG_MESSAGE);
}
@@ -478,7 +499,9 @@ mod tests {
fn prefix_in_log_lines_entrypoint() {
if env::var("ENABLE_LOGGING").is_ok() {
let test_pattern = "test-target=info";
- init_logger(&test_pattern, Default::default(), Default::default(), false).unwrap();
+ init_logger(
+ InitLoggerParams { pattern: test_pattern.into(), ..Default::default() },
+ ).unwrap();
prefix_in_log_lines_process();
}
}
@@ -494,7 +517,7 @@ mod tests {
#[test]
fn do_not_write_with_colors_on_tty_entrypoint() {
if env::var("ENABLE_LOGGING").is_ok() {
- init_logger("", Default::default(), Default::default(), false).unwrap();
+ init_logger(InitLoggerParams::default()).unwrap();
log::info!("{}", ansi_term::Colour::Yellow.paint(EXPECTED_LOG_MESSAGE));
}
}
diff --git a/client/cli/src/params/database_params.rs b/client/cli/src/params/database_params.rs
index 24b23f6076a02302071c76a6da614c8e5c11e6a0..21529f65a56b0b76f6557d31a89e2adb66b4053f 100644
--- a/client/cli/src/params/database_params.rs
+++ b/client/cli/src/params/database_params.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/cli/src/params/import_params.rs b/client/cli/src/params/import_params.rs
index 376a72b8421f5446e4ccdfae606145478d329c73..7409dbf79dc0f7b1db5d08bc343ec1e4fbe0c5a5 100644
--- a/client/cli/src/params/import_params.rs
+++ b/client/cli/src/params/import_params.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/cli/src/params/keystore_params.rs b/client/cli/src/params/keystore_params.rs
index f03fafeb965c0bb3489972816bd7adc18192b48e..d75cdebc5a56839db2a9104a12da7fc8f346825e 100644
--- a/client/cli/src/params/keystore_params.rs
+++ b/client/cli/src/params/keystore_params.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
@@ -18,8 +18,7 @@
use crate::error::Result;
use sc_service::config::KeystoreConfig;
-use std::fs;
-use std::path::PathBuf;
+use std::{fs, path::{PathBuf, Path}};
use structopt::StructOpt;
use crate::error;
use sp_core::crypto::SecretString;
@@ -33,6 +32,7 @@ pub struct KeystoreParams {
/// Specify custom URIs to connect to for keystore-services
#[structopt(long = "keystore-uri")]
pub keystore_uri: Option,
+
/// Specify custom keystore path.
#[structopt(long = "keystore-path", value_name = "PATH", parse(from_os_str))]
pub keystore_path: Option,
@@ -64,15 +64,14 @@ pub struct KeystoreParams {
/// Parse a sercret string, returning a displayable error.
pub fn secret_string_from_str(s: &str) -> std::result::Result {
- Ok(std::str::FromStr::from_str(s)
- .map_err(|_e| "Could not get SecretString".to_string())?)
+ std::str::FromStr::from_str(s).map_err(|_| "Could not get SecretString".to_string())
}
impl KeystoreParams {
/// Get the keystore configuration for the parameters
- /// returns a vector of remote-urls and the local Keystore configuration
- pub fn keystore_config(&self, base_path: &PathBuf) -> Result<(Option, KeystoreConfig)> {
-
+ ///
+ /// Returns a vector of remote-urls and the local Keystore configuration
+ pub fn keystore_config(&self, config_dir: &Path) -> Result<(Option, KeystoreConfig)> {
let password = if self.password_interactive {
#[cfg(not(target_os = "unknown"))]
{
@@ -92,7 +91,7 @@ impl KeystoreParams {
let path = self
.keystore_path
.clone()
- .unwrap_or_else(|| base_path.join(DEFAULT_KEYSTORE_CONFIG_PATH));
+ .unwrap_or_else(|| config_dir.join(DEFAULT_KEYSTORE_CONFIG_PATH));
Ok((self.keystore_uri.clone(), KeystoreConfig::Path { path, password }))
}
diff --git a/client/cli/src/params/mod.rs b/client/cli/src/params/mod.rs
index 93467bc8ec63778e95d116b57cf8b6dc92c12636..8308b123f71f3c5e83fa709cf4ddbc9d910df132 100644
--- a/client/cli/src/params/mod.rs
+++ b/client/cli/src/params/mod.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/cli/src/params/network_params.rs b/client/cli/src/params/network_params.rs
index a973d61272ced7c47c65121f50e6c18054cc3416..130325a7f9d4fa588dbd7882d0d460b35e1d0e54 100644
--- a/client/cli/src/params/network_params.rs
+++ b/client/cli/src/params/network_params.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
@@ -18,7 +18,7 @@
use crate::params::node_key_params::NodeKeyParams;
use sc_network::{
- config::{NetworkConfiguration, NodeKeyConfig, NonReservedPeerMode, TransportConfig},
+ config::{NetworkConfiguration, NodeKeyConfig, NonReservedPeerMode, SetConfig, TransportConfig},
multiaddr::Protocol,
};
use sc_service::{ChainSpec, ChainType, config::{Multiaddr, MultiaddrWithPeerId}};
@@ -150,21 +150,23 @@ impl NetworkParams {
NetworkConfiguration {
boot_nodes,
net_config_path,
- reserved_nodes: self.reserved_nodes.clone(),
- non_reserved_mode: if self.reserved_only {
- NonReservedPeerMode::Deny
- } else {
- NonReservedPeerMode::Accept
+ default_peers_set: SetConfig {
+ in_peers: self.in_peers,
+ out_peers: self.out_peers,
+ reserved_nodes: self.reserved_nodes.clone(),
+ non_reserved_mode: if self.reserved_only {
+ NonReservedPeerMode::Deny
+ } else {
+ NonReservedPeerMode::Accept
+ },
},
listen_addresses,
public_addresses,
- notifications_protocols: Vec::new(),
+ extra_sets: Vec::new(),
request_response_protocols: Vec::new(),
node_key,
node_name: node_name.to_string(),
client_version: client_id.to_string(),
- in_peers: self.in_peers,
- out_peers: self.out_peers,
transport: TransportConfig::Normal {
enable_mdns: !is_dev && !self.no_mdns,
allow_private_ipv4: !self.no_private_ipv4,
diff --git a/client/cli/src/params/node_key_params.rs b/client/cli/src/params/node_key_params.rs
index 875411fbfb62000d3e8c5bfc00cce52d3082fa04..d43c87804dd3ba1404e5a3753effa5e3a63e8b09 100644
--- a/client/cli/src/params/node_key_params.rs
+++ b/client/cli/src/params/node_key_params.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/cli/src/params/offchain_worker_params.rs b/client/cli/src/params/offchain_worker_params.rs
index f8d48edc4729d5f97e4f389fe78dd3cd794423b9..ef39a1ed41be26bb8f94e5391fbcff1d62006f7f 100644
--- a/client/cli/src/params/offchain_worker_params.rs
+++ b/client/cli/src/params/offchain_worker_params.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/cli/src/params/pruning_params.rs b/client/cli/src/params/pruning_params.rs
index 7db808e6d8f2f8e249ff0e057a05297bfcf92a72..80118cafd8769b40c2dc4204b8b4b9de9bb9dbcf 100644
--- a/client/cli/src/params/pruning_params.rs
+++ b/client/cli/src/params/pruning_params.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/cli/src/params/shared_params.rs b/client/cli/src/params/shared_params.rs
index 52b1488ea9ccdf9383f2dd6222a478e9b3528fb4..45ce41846bf120319e3b2952ae112340938b3ac4 100644
--- a/client/cli/src/params/shared_params.rs
+++ b/client/cli/src/params/shared_params.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
@@ -46,6 +46,10 @@ pub struct SharedParams {
#[structopt(short = "l", long, value_name = "LOG_PATTERN")]
pub log: Vec,
+ /// Disable log color output.
+ #[structopt(long)]
+ pub disable_log_color: bool,
+
/// Disable feature to dynamically update and reload the log filter.
///
/// By default this feature is enabled, however it leads to a small performance decrease.
@@ -99,6 +103,11 @@ impl SharedParams {
&self.log
}
+ /// Should the log color output be disabled?
+ pub fn disable_log_color(&self) -> bool {
+ self.disable_log_color
+ }
+
/// Is log reloading disabled
pub fn is_log_filter_reloading_disabled(&self) -> bool {
self.disable_log_reloading
diff --git a/client/cli/src/params/transaction_pool_params.rs b/client/cli/src/params/transaction_pool_params.rs
index 3ad278426922ec99ccc42e192cbda9db1d04207b..bf0ed53e531c9745dcd8351b9edebd0a55808997 100644
--- a/client/cli/src/params/transaction_pool_params.rs
+++ b/client/cli/src/params/transaction_pool_params.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs
index e6d35282ada2b491cacbe2b9a112b5cba82bd968..9836471fb9fa2ddd413aeb2c76d7df677a2d8ca3 100644
--- a/client/cli/src/runner.rs
+++ b/client/cli/src/runner.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/consensus/aura/Cargo.toml b/client/consensus/aura/Cargo.toml
index ccc4d515a8e1104ebbd058abeec0595e6ba6be21..b7bdf220d90c5e5bf74b07b65abec294e8fe3e65 100644
--- a/client/consensus/aura/Cargo.toml
+++ b/client/consensus/aura/Cargo.toml
@@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
sp-application-crypto = { version = "2.0.0", path = "../../../primitives/application-crypto" }
sp-consensus-aura = { version = "0.8.0", path = "../../../primitives/consensus/aura" }
sp-block-builder = { version = "2.0.0", path = "../../../primitives/block-builder" }
-sc-block-builder = { version = "0.8.0", path = "../../../client/block-builder" }
+sc-block-builder = { version = "0.8.0", path = "../../block-builder" }
sc-client-api = { version = "2.0.0", path = "../../api" }
codec = { package = "parity-scale-codec", version = "1.3.4" }
sp-consensus = { version = "0.8.0", path = "../../../primitives/consensus/common" }
@@ -25,7 +25,7 @@ futures = "0.3.4"
futures-timer = "3.0.1"
sp-inherents = { version = "2.0.0", path = "../../../primitives/inherents" }
log = "0.4.8"
-parking_lot = "0.10.0"
+parking_lot = "0.11.1"
sp-core = { version = "2.0.0", path = "../../../primitives/core" }
sp-blockchain = { version = "2.0.0", path = "../../../primitives/blockchain" }
sp-io = { version = "2.0.0", path = "../../../primitives/io" }
@@ -37,6 +37,9 @@ sp-timestamp = { version = "2.0.0", path = "../../../primitives/timestamp" }
sp-keystore = { version = "0.8.0", path = "../../../primitives/keystore" }
sc-telemetry = { version = "2.0.0", path = "../../telemetry" }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../../utils/prometheus", version = "0.8.0"}
+# We enable it only for web-wasm check
+# See https://docs.rs/getrandom/0.2.1/getrandom/#webassembly-support
+getrandom = { version = "0.2", features = ["js"], optional = true }
[dev-dependencies]
sp-keyring = { version = "2.0.0", path = "../../../primitives/keyring" }
diff --git a/client/consensus/aura/src/digests.rs b/client/consensus/aura/src/digests.rs
index 3332e4c6a6dff99f2ee9ad367031fde15a33ada6..fec412b62d1eaf3b38f696a12510fdeeab31832f 100644
--- a/client/consensus/aura/src/digests.rs
+++ b/client/consensus/aura/src/digests.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/consensus/aura/src/lib.rs b/client/consensus/aura/src/lib.rs
index 246b39771277d3e54bc95db097e852a99447e68e..84d3783927e54c6588ffebf2cb8cc26c92dfe702 100644
--- a/client/consensus/aura/src/lib.rs
+++ b/client/consensus/aura/src/lib.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
@@ -256,7 +256,7 @@ where
) -> Option {
let expected_author = slot_author::(slot_number, epoch_data);
expected_author.and_then(|p| {
- if SyncCryptoStore::has_keys(
+ if SyncCryptoStore::has_keys(
&*self.keystore,
&[(p.to_raw_vec(), sp_application_crypto::key_types::AURA)],
) {
diff --git a/client/consensus/babe/Cargo.toml b/client/consensus/babe/Cargo.toml
index 2178f1cf970108ef935194baf1013dee182c3b55..1b97ba68cc8468a1e192afc2917036e7f59c24de 100644
--- a/client/consensus/babe/Cargo.toml
+++ b/client/consensus/babe/Cargo.toml
@@ -44,7 +44,7 @@ fork-tree = { version = "2.0.0", path = "../../../utils/fork-tree" }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../../utils/prometheus", version = "0.8.0"}
futures = "0.3.4"
futures-timer = "3.0.1"
-parking_lot = "0.10.0"
+parking_lot = "0.11.1"
log = "0.4.8"
schnorrkel = { version = "0.9.1", features = ["preaudit_deprecated"] }
rand = "0.7.2"
diff --git a/client/consensus/babe/rpc/src/lib.rs b/client/consensus/babe/rpc/src/lib.rs
index a90964cdf73f71860365d08a8f4067939e5dfea5..4d5c091e0cbbd88add7aa93d17aeef63e418a790 100644
--- a/client/consensus/babe/rpc/src/lib.rs
+++ b/client/consensus/babe/rpc/src/lib.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/consensus/babe/src/authorship.rs b/client/consensus/babe/src/authorship.rs
index 28a3692958e180430ba7a847505bdac5c68a8e0a..90ad12c4558c828cab7610b61c497ccabac9a361 100644
--- a/client/consensus/babe/src/authorship.rs
+++ b/client/consensus/babe/src/authorship.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! BABE authority selection and slot claiming.
diff --git a/client/consensus/babe/src/aux_schema.rs b/client/consensus/babe/src/aux_schema.rs
index 287121566a417247b835a6c8be55c781ecafb304..d399a12ea8a5b63f6d9c1c6da8235ea3a0a56475 100644
--- a/client/consensus/babe/src/aux_schema.rs
+++ b/client/consensus/babe/src/aux_schema.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Schema for BABE epoch changes in the aux-db.
diff --git a/client/consensus/babe/src/lib.rs b/client/consensus/babe/src/lib.rs
index 3f2a583482afb5d7486f44e0f6c45b7e0f5d6111..ea3ca29dad0e09011558475cb4d437e42bdd5eb1 100644
--- a/client/consensus/babe/src/lib.rs
+++ b/client/consensus/babe/src/lib.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! # BABE (Blind Assignment for Blockchain Extension)
//!
@@ -342,6 +344,11 @@ impl Config {
}
}
}
+
+ /// Get the inner slot duration, in milliseconds.
+ pub fn slot_duration(&self) -> u64 {
+ self.0.slot_duration()
+ }
}
impl std::ops::Deref for Config {
diff --git a/client/consensus/babe/src/tests.rs b/client/consensus/babe/src/tests.rs
index 6e0536c85ced76ff1242361e2ab4b4205a990642..82d8f9de5af02e12311e33afa0a02c789d789a6e 100644
--- a/client/consensus/babe/src/tests.rs
+++ b/client/consensus/babe/src/tests.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! BABE testsuite
diff --git a/client/consensus/babe/src/verification.rs b/client/consensus/babe/src/verification.rs
index fd3c27be4f34ef9bb00ba1ef12a4215d0e2a313d..47c4da0834d096c55c0cdf7c11b5e9c492ecd572 100644
--- a/client/consensus/babe/src/verification.rs
+++ b/client/consensus/babe/src/verification.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Verification for BABE headers.
use sp_runtime::{traits::Header, traits::DigestItemFor};
diff --git a/client/consensus/common/src/lib.rs b/client/consensus/common/src/lib.rs
index 1d9b072cfe964f168ac471b2bfcf3cac29009048..a53517c5c35ead9aa8d11c9280972564025251a2 100644
--- a/client/consensus/common/src/lib.rs
+++ b/client/consensus/common/src/lib.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Collection of common consensus specific implementations
mod longest_chain;
diff --git a/client/consensus/common/src/longest_chain.rs b/client/consensus/common/src/longest_chain.rs
index 981dbad0f607029671b7ad858f2327578fa24e94..8cf32a1dbd3c1587ea61dd9bb3fb23b40c71ddad 100644
--- a/client/consensus/common/src/longest_chain.rs
+++ b/client/consensus/common/src/longest_chain.rs
@@ -1,18 +1,21 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
+
//! Longest chain implementation
use std::sync::Arc;
@@ -98,4 +101,4 @@ impl SelectChain for LongestChain
self.backend.blockchain().best_containing(target_hash, maybe_max_number, import_lock)
.map_err(|e| ConsensusError::ChainLookup(e.to_string()).into())
}
-}
\ No newline at end of file
+}
diff --git a/client/consensus/epochs/Cargo.toml b/client/consensus/epochs/Cargo.toml
index d50ec29ed9c6e19a054d0b488e3d83bf2b13eb61..b7de4494bf7a5735bffe855629e076303b8f83fe 100644
--- a/client/consensus/epochs/Cargo.toml
+++ b/client/consensus/epochs/Cargo.toml
@@ -14,7 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { package = "parity-scale-codec", version = "1.3.4", features = ["derive"] }
-parking_lot = "0.10.0"
+parking_lot = "0.11.1"
fork-tree = { version = "2.0.0", path = "../../../utils/fork-tree" }
sp-runtime = { path = "../../../primitives/runtime" , version = "2.0.0"}
sp-blockchain = { version = "2.0.0", path = "../../../primitives/blockchain" }
diff --git a/client/consensus/epochs/src/lib.rs b/client/consensus/epochs/src/lib.rs
index acb07dd668a3c4f3b2c7a2350451d9ac93008926..76e8c8ed5419d3d013407d15648329978449358d 100644
--- a/client/consensus/epochs/src/lib.rs
+++ b/client/consensus/epochs/src/lib.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Generic utilities for epoch-based consensus engines.
diff --git a/client/consensus/epochs/src/migration.rs b/client/consensus/epochs/src/migration.rs
index e4717b5584e0ec67801ce3d264e90ff350286deb..6e7baba8053af65bfa06cd983b675b90e851d870 100644
--- a/client/consensus/epochs/src/migration.rs
+++ b/client/consensus/epochs/src/migration.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Migration types for epoch changes.
diff --git a/client/consensus/manual-seal/Cargo.toml b/client/consensus/manual-seal/Cargo.toml
index d50cb593652691ab378fcd055d8b7cdc423c32c1..80dbed3668c03c6308a0ace33b1fcf87b4c648e1 100644
--- a/client/consensus/manual-seal/Cargo.toml
+++ b/client/consensus/manual-seal/Cargo.toml
@@ -19,7 +19,7 @@ jsonrpc-core = "15.1.0"
jsonrpc-core-client = "15.1.0"
jsonrpc-derive = "15.1.0"
log = "0.4.8"
-parking_lot = "0.10.0"
+parking_lot = "0.11.1"
codec = { package = "parity-scale-codec", version = "1.3.1" }
serde = { version = "1.0", features=["derive"] }
assert_matches = "1.3.0"
diff --git a/client/consensus/manual-seal/src/consensus.rs b/client/consensus/manual-seal/src/consensus.rs
index 7bafeb50207d486f93055c20e5bfe2649586e743..0cfd99cab5c99419c219b2a6483efa2a30299780 100644
--- a/client/consensus/manual-seal/src/consensus.rs
+++ b/client/consensus/manual-seal/src/consensus.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/consensus/manual-seal/src/consensus/babe.rs b/client/consensus/manual-seal/src/consensus/babe.rs
index c2fdf6243c30407504a74b0aba4fd370b9595e3d..1566b647f2c01556acf9a1bc3388c4aaa406eecf 100644
--- a/client/consensus/manual-seal/src/consensus/babe.rs
+++ b/client/consensus/manual-seal/src/consensus/babe.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/consensus/manual-seal/src/error.rs b/client/consensus/manual-seal/src/error.rs
index e2628008c24c7c2a3c203af47c0088ea635d13b5..77140c835a3eea86c651f841de8b3c03ca25630a 100644
--- a/client/consensus/manual-seal/src/error.rs
+++ b/client/consensus/manual-seal/src/error.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/consensus/manual-seal/src/finalize_block.rs b/client/consensus/manual-seal/src/finalize_block.rs
index 5780a25f97256331eb1d11b2370dd838ec112ac7..76ae6eeeae5aceebab426be0af8c7f66f13c3aa5 100644
--- a/client/consensus/manual-seal/src/finalize_block.rs
+++ b/client/consensus/manual-seal/src/finalize_block.rs
@@ -1,18 +1,20 @@
-// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Block finalization utilities
diff --git a/client/consensus/manual-seal/src/lib.rs b/client/consensus/manual-seal/src/lib.rs
index 9c4465f82fda1ef57e2e18be6ba88be05518531a..5bf08571195d2b501b6850192ca1e85c3e3ab292 100644
--- a/client/consensus/manual-seal/src/lib.rs
+++ b/client/consensus/manual-seal/src/lib.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/consensus/manual-seal/src/rpc.rs b/client/consensus/manual-seal/src/rpc.rs
index 690b6c1eb9996d086d0a2397b00cdc2c1d5145d0..293d4487a5d5972adacb9c00482868ee90cf4135 100644
--- a/client/consensus/manual-seal/src/rpc.rs
+++ b/client/consensus/manual-seal/src/rpc.rs
@@ -1,18 +1,20 @@
-// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! RPC interface for the `ManualSeal` Engine.
diff --git a/client/consensus/manual-seal/src/seal_block.rs b/client/consensus/manual-seal/src/seal_block.rs
index a4afaa343e9052561204a60cadf731907c863c73..59b99349bf9b2a6b6834d6d8f166be8738bfbd95 100644
--- a/client/consensus/manual-seal/src/seal_block.rs
+++ b/client/consensus/manual-seal/src/seal_block.rs
@@ -1,18 +1,20 @@
-// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Block sealing utilities
diff --git a/client/consensus/pow/Cargo.toml b/client/consensus/pow/Cargo.toml
index fbb02ccc71121a1855932dffb624a765593dbbb4..cd4d12c37188d2bbc3fd13855df60909fecfef12 100644
--- a/client/consensus/pow/Cargo.toml
+++ b/client/consensus/pow/Cargo.toml
@@ -26,7 +26,7 @@ sp-consensus = { version = "0.8.0", path = "../../../primitives/consensus/common
log = "0.4.8"
futures = { version = "0.3.1", features = ["compat"] }
futures-timer = "3.0.1"
-parking_lot = "0.10.0"
+parking_lot = "0.11.1"
sp-timestamp = { version = "2.0.0", path = "../../../primitives/timestamp" }
derive_more = "0.99.2"
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../../utils/prometheus", version = "0.8.0"}
diff --git a/client/consensus/pow/src/lib.rs b/client/consensus/pow/src/lib.rs
index e353ed6358a00fc94f5069bbeff356ba93347cd6..975a6f17e795f34106448f77518ec2c3b2261ed0 100644
--- a/client/consensus/pow/src/lib.rs
+++ b/client/consensus/pow/src/lib.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/consensus/pow/src/worker.rs b/client/consensus/pow/src/worker.rs
index 4ed863dcd9ed986e6045ac1a96061a03b030a3b7..c19c5524d9774cf84863845ed911c8a8e160d5c4 100644
--- a/client/consensus/pow/src/worker.rs
+++ b/client/consensus/pow/src/worker.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/consensus/slots/Cargo.toml b/client/consensus/slots/Cargo.toml
index e8bd1f33631eaecfa4ddbfc65ea449dff8219690..35b08444d45dc3360c60637c37a95da8e85eb58d 100644
--- a/client/consensus/slots/Cargo.toml
+++ b/client/consensus/slots/Cargo.toml
@@ -30,7 +30,7 @@ sp-consensus = { version = "0.8.0", path = "../../../primitives/consensus/common
sp-inherents = { version = "2.0.0", path = "../../../primitives/inherents" }
futures = "0.3.4"
futures-timer = "3.0.1"
-parking_lot = "0.10.0"
+parking_lot = "0.11.1"
log = "0.4.11"
thiserror = "1.0.21"
diff --git a/client/consensus/slots/build.rs b/client/consensus/slots/build.rs
index 513cc234d4363a854961db1efdea1cbc7007ce56..57424f016f3e520e98345432cc105469a43efefc 100644
--- a/client/consensus/slots/build.rs
+++ b/client/consensus/slots/build.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
use std::env;
diff --git a/client/consensus/slots/src/aux_schema.rs b/client/consensus/slots/src/aux_schema.rs
index 1f1fe37068f82b2fef9c789bf0877068d0b1d0c3..c8095f238ec8cefb9235c314650189d61787bfab 100644
--- a/client/consensus/slots/src/aux_schema.rs
+++ b/client/consensus/slots/src/aux_schema.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Schema for slots in the aux-db.
diff --git a/client/consensus/slots/src/lib.rs b/client/consensus/slots/src/lib.rs
index 571766bc44b1ae3c584f384fd7872ff4c4c535e4..93d3614584f8f2b196afa4c107fb385d07a2adb1 100644
--- a/client/consensus/slots/src/lib.rs
+++ b/client/consensus/slots/src/lib.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Slots functionality for Substrate.
//!
diff --git a/client/consensus/slots/src/slots.rs b/client/consensus/slots/src/slots.rs
index e7c84a2c1fd283e437566a342e62cb3c75fe4e3f..0c93e16461ccb1c4783bdcce95bc06c5398b825b 100644
--- a/client/consensus/slots/src/slots.rs
+++ b/client/consensus/slots/src/slots.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Utility stream for yielding slots in a loop.
//!
diff --git a/client/consensus/uncles/src/lib.rs b/client/consensus/uncles/src/lib.rs
index 2a129b200063b97db9cd1bc8b3811d8b16abd75c..f38849300d0da2edf2a70cce0b6ff1c0556ddab1 100644
--- a/client/consensus/uncles/src/lib.rs
+++ b/client/consensus/uncles/src/lib.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Uncles functionality for Substrate.
#![forbid(unsafe_code, missing_docs)]
diff --git a/client/db/Cargo.toml b/client/db/Cargo.toml
index 70a0b19532593cb689c14320d7f44eb5906cf3d0..e5f5a59be9f5a8467bd37fad913d710fade0be76 100644
--- a/client/db/Cargo.toml
+++ b/client/db/Cargo.toml
@@ -13,14 +13,14 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
-parking_lot = "0.10.0"
+parking_lot = "0.11.1"
log = "0.4.8"
-kvdb = "0.7.0"
-kvdb-rocksdb = { version = "0.9.1", optional = true }
-kvdb-memorydb = "0.7.0"
+kvdb = "0.8.0"
+kvdb-rocksdb = { version = "0.10.0", optional = true }
+kvdb-memorydb = "0.8.0"
linked-hash-map = "0.5.2"
hash-db = "0.15.2"
-parity-util-mem = { version = "0.7.0", default-features = false, features = ["std"] }
+parity-util-mem = { version = "0.8.0", default-features = false, features = ["std"] }
codec = { package = "parity-scale-codec", version = "1.3.4", features = ["derive"] }
blake2-rfc = "0.2.18"
@@ -43,7 +43,7 @@ sp-keyring = { version = "2.0.0", path = "../../primitives/keyring" }
sp-tracing = { version = "2.0.0", path = "../../primitives/tracing" }
substrate-test-runtime-client = { version = "2.0.0", path = "../../test-utils/runtime/client" }
quickcheck = "0.9"
-kvdb-rocksdb = "0.9.1"
+kvdb-rocksdb = "0.10.0"
tempfile = "3"
[features]
diff --git a/client/db/src/bench.rs b/client/db/src/bench.rs
index 5696922b4fbb3006689a01f602c65554e81f8511..f0c187bd379f13071828e7fd337a82729dcb3e54 100644
--- a/client/db/src/bench.rs
+++ b/client/db/src/bench.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/db/src/cache/list_cache.rs b/client/db/src/cache/list_cache.rs
index 15ad339b1f2c1a387fd3e5dbac70eaef5df3a79b..341105b16a5b3f324fa35102a4e6085e8a6d1a78 100644
--- a/client/db/src/cache/list_cache.rs
+++ b/client/db/src/cache/list_cache.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/db/src/cache/list_entry.rs b/client/db/src/cache/list_entry.rs
index d14fab9274ccb830694082491b5f16bcf27ecf2b..94d4eb9f49b2739c3a0325da899c8a7b57dc3ad6 100644
--- a/client/db/src/cache/list_entry.rs
+++ b/client/db/src/cache/list_entry.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/db/src/cache/list_storage.rs b/client/db/src/cache/list_storage.rs
index 377d744effa60faf57521d2a490852ef757ce1bf..e4b3677b4ab310de91323f0a208ec6a327c57115 100644
--- a/client/db/src/cache/list_storage.rs
+++ b/client/db/src/cache/list_storage.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/db/src/cache/mod.rs b/client/db/src/cache/mod.rs
index 5501f0f1864c156745c6a3e63e4d8ced9a1cf25c..005d25b90f933491a7dde3a62ae7041a8c155a13 100644
--- a/client/db/src/cache/mod.rs
+++ b/client/db/src/cache/mod.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/db/src/changes_tries_storage.rs b/client/db/src/changes_tries_storage.rs
index a2299a82337a05f58ec7ba8dc867270813cc4444..6233eab3ea396fa70cb114552ebff1de4dc4ca8d 100644
--- a/client/db/src/changes_tries_storage.rs
+++ b/client/db/src/changes_tries_storage.rs
@@ -1,18 +1,20 @@
-// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! DB-backed changes tries storage.
diff --git a/client/db/src/children.rs b/client/db/src/children.rs
index bfba797cd467bdbc3f7a1db5d23b7f97511b5be5..62352e6d0614aced3ca0fccee9c33b47a258befe 100644
--- a/client/db/src/children.rs
+++ b/client/db/src/children.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Functionality for reading and storing children hashes from db.
diff --git a/client/db/src/lib.rs b/client/db/src/lib.rs
index e32e45a2f314aef92ba3615c4ec615d9156cf13e..e3b94b03c87d80696dcfb714f4d63aa59cda8dc2 100644
--- a/client/db/src/lib.rs
+++ b/client/db/src/lib.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/db/src/light.rs b/client/db/src/light.rs
index acfb6217ce9e034dd66324e34642aa78eb0a8a95..91f37dd374d9f8912f40529cf1bbe89acc58288c 100644
--- a/client/db/src/light.rs
+++ b/client/db/src/light.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/db/src/offchain.rs b/client/db/src/offchain.rs
index c4f0ce115ca54f1453e857cc34b96fd26918f8a8..aead4397343ea32c23142988ad9c1b36e3d94780 100644
--- a/client/db/src/offchain.rs
+++ b/client/db/src/offchain.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/db/src/parity_db.rs b/client/db/src/parity_db.rs
index 313069706f33f5128004ada17d58ab241855227f..e56ca4de6cb78d028dd527ad098c1c5ee001f085 100644
--- a/client/db/src/parity_db.rs
+++ b/client/db/src/parity_db.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/db/src/stats.rs b/client/db/src/stats.rs
index 8d208024b4bb29a1f064dfc00f3fa14b8df07f85..3fd93db931d029fcb2a8da73fa75f674f6a5b438 100644
--- a/client/db/src/stats.rs
+++ b/client/db/src/stats.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/db/src/storage_cache.rs b/client/db/src/storage_cache.rs
index 292d3c5162601af1ee02a0463406e62895be4fd9..bbbc8413be797923549973b54b04358f944df12b 100644
--- a/client/db/src/storage_cache.rs
+++ b/client/db/src/storage_cache.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Global cache state.
diff --git a/client/db/src/upgrade.rs b/client/db/src/upgrade.rs
index 95592d071f777db07cf15e8e2765225f0756bfb2..e87b11b69660cae962f34fa9f11ec27ee602967b 100644
--- a/client/db/src/upgrade.rs
+++ b/client/db/src/upgrade.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Database upgrade logic.
diff --git a/client/db/src/utils.rs b/client/db/src/utils.rs
index e999469c18ff0c96f40580f0ed1192aae5a5268a..dfc1e945b3a4cfa0c3e79e1713e9c99a0b33cf91 100644
--- a/client/db/src/utils.rs
+++ b/client/db/src/utils.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/executor/Cargo.toml b/client/executor/Cargo.toml
index c5ce4b86e12f5a0e05f4da82bf7bf463fe845ff4..44eb6b98b05678b6bd80dd1e5c41ae09a671dbdb 100644
--- a/client/executor/Cargo.toml
+++ b/client/executor/Cargo.toml
@@ -33,7 +33,7 @@ sp-externalities = { version = "0.8.0", path = "../../primitives/externalities"
sc-executor-common = { version = "0.8.0", path = "common" }
sc-executor-wasmi = { version = "0.8.0", path = "wasmi" }
sc-executor-wasmtime = { version = "0.8.0", path = "wasmtime", optional = true }
-parking_lot = "0.10.0"
+parking_lot = "0.11.1"
log = "0.4.8"
libsecp256k1 = "0.3.4"
@@ -44,12 +44,12 @@ hex-literal = "0.3.1"
sc-runtime-test = { version = "2.0.0", path = "runtime-test" }
substrate-test-runtime = { version = "2.0.0", path = "../../test-utils/runtime" }
sp-state-machine = { version = "0.8.0", path = "../../primitives/state-machine" }
-test-case = "0.3.3"
sp-runtime = { version = "2.0.0", path = "../../primitives/runtime" }
sp-tracing = { version = "2.0.0", path = "../../primitives/tracing" }
sc-tracing = { version = "2.0.0", path = "../tracing" }
tracing = "0.1.22"
tracing-subscriber = "0.2.15"
+paste = "0.1.6"
[features]
default = [ "std" ]
diff --git a/client/executor/common/src/error.rs b/client/executor/common/src/error.rs
index df0eaf8cc26101c7f611bf2f1ee46d07fd1fe6ee..0af148fd95809ef1d4c6de2f214fb647051d88a4 100644
--- a/client/executor/common/src/error.rs
+++ b/client/executor/common/src/error.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/executor/common/src/lib.rs b/client/executor/common/src/lib.rs
index df839d4ab65232bc0552e18864fdc2ab16903c12..050bad27d6c3056a7510ce8dd1bbebfa942b87eb 100644
--- a/client/executor/common/src/lib.rs
+++ b/client/executor/common/src/lib.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! A set of common definitions that are needed for defining execution engines.
diff --git a/client/executor/common/src/sandbox.rs b/client/executor/common/src/sandbox.rs
index b2c35b758271829c8771034da08aee46c52dd3db..8ed294bb83983099f5363c4573d2fb0cb61529ba 100644
--- a/client/executor/common/src/sandbox.rs
+++ b/client/executor/common/src/sandbox.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/executor/common/src/util.rs b/client/executor/common/src/util.rs
index 564f9dadcbec691e1344872f330a30bd3c543740..5947be4469cd07211b54e82eb5aaacf7c59a4473 100644
--- a/client/executor/common/src/util.rs
+++ b/client/executor/common/src/util.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/executor/common/src/wasm_runtime.rs b/client/executor/common/src/wasm_runtime.rs
index c407d9967cbf9839941772f17b9f75c74a89ea48..cca0d99c4b91cb5eee9e70cf033897d7a0465780 100644
--- a/client/executor/common/src/wasm_runtime.rs
+++ b/client/executor/common/src/wasm_runtime.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Definitions for a wasm runtime.
diff --git a/client/executor/runtime-test/build.rs b/client/executor/runtime-test/build.rs
index a83de21db7f0f387534d6feab29fbfc325474a90..9456d6bc90f4cf567d35a85765a9b0132233e2e9 100644
--- a/client/executor/runtime-test/build.rs
+++ b/client/executor/runtime-test/build.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
use substrate_wasm_builder::WasmBuilder;
diff --git a/client/executor/src/integration_tests/mod.rs b/client/executor/src/integration_tests/mod.rs
index d41784f5aa067d4d4826ffa1bd41370ce068a019..661d2c5d3d352052190d33329942acdf22aba560 100644
--- a/client/executor/src/integration_tests/mod.rs
+++ b/client/executor/src/integration_tests/mod.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
@@ -26,7 +26,6 @@ use sp_core::{
};
use sc_runtime_test::wasm_binary_unwrap;
use sp_state_machine::TestExternalities as CoreTestExternalities;
-use test_case::test_case;
use sp_trie::{TrieConfiguration, trie_types::Layout};
use sp_wasm_interface::HostFunctions as _;
use sp_runtime::traits::BlakeTwo256;
@@ -37,6 +36,34 @@ use crate::WasmExecutionMethod;
pub type TestExternalities = CoreTestExternalities;
type HostFunctions = sp_io::SubstrateHostFunctions;
+/// Simple macro that runs a given method as test with the available wasm execution methods.
+#[macro_export]
+macro_rules! test_wasm_execution {
+ ($method_name:ident) => {
+ paste::item! {
+ #[test]
+ fn [<$method_name _interpreted>]() {
+ $method_name(WasmExecutionMethod::Interpreted);
+ }
+
+ #[test]
+ #[cfg(feature = "wasmtime")]
+ fn [<$method_name _compiled>]() {
+ $method_name(WasmExecutionMethod::Compiled);
+ }
+ }
+ };
+
+ (interpreted_only $method_name:ident) => {
+ paste::item! {
+ #[test]
+ fn [<$method_name _interpreted>]() {
+ $method_name(WasmExecutionMethod::Interpreted);
+ }
+ }
+ };
+}
+
fn call_in_wasm(
function: &str,
call_data: &[u8],
@@ -59,8 +86,7 @@ fn call_in_wasm(
)
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(returning_should_work);
fn returning_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -74,8 +100,7 @@ fn returning_should_work(wasm_method: WasmExecutionMethod) {
assert_eq!(output, vec![0u8; 0]);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(call_not_existing_function);
fn call_not_existing_function(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -102,8 +127,7 @@ fn call_not_existing_function(wasm_method: WasmExecutionMethod) {
}
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(call_yet_another_not_existing_function);
fn call_yet_another_not_existing_function(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -130,8 +154,7 @@ fn call_yet_another_not_existing_function(wasm_method: WasmExecutionMethod) {
}
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(panicking_should_work);
fn panicking_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -161,8 +184,7 @@ fn panicking_should_work(wasm_method: WasmExecutionMethod) {
assert!(output.is_err());
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(storage_should_work);
fn storage_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
@@ -191,8 +213,7 @@ fn storage_should_work(wasm_method: WasmExecutionMethod) {
assert_eq!(ext, expected);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(clear_prefix_should_work);
fn clear_prefix_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
{
@@ -225,8 +246,7 @@ fn clear_prefix_should_work(wasm_method: WasmExecutionMethod) {
assert_eq!(expected, ext);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(blake2_256_should_work);
fn blake2_256_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -250,8 +270,7 @@ fn blake2_256_should_work(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(blake2_128_should_work);
fn blake2_128_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -275,8 +294,7 @@ fn blake2_128_should_work(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(sha2_256_should_work);
fn sha2_256_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -306,8 +324,7 @@ fn sha2_256_should_work(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(twox_256_should_work);
fn twox_256_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -335,8 +352,7 @@ fn twox_256_should_work(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(twox_128_should_work);
fn twox_128_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -360,8 +376,7 @@ fn twox_128_should_work(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(ed25519_verify_should_work);
fn ed25519_verify_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -397,8 +412,7 @@ fn ed25519_verify_should_work(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(sr25519_verify_should_work);
fn sr25519_verify_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -434,8 +448,7 @@ fn sr25519_verify_should_work(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(ordered_trie_root_should_work);
fn ordered_trie_root_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let trie_input = vec![b"zero".to_vec(), b"one".to_vec(), b"two".to_vec()];
@@ -450,8 +463,7 @@ fn ordered_trie_root_should_work(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(offchain_index);
fn offchain_index(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let (offchain, _state) = testing::TestOffchainExt::new();
@@ -472,11 +484,8 @@ fn offchain_index(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(offchain_local_storage_should_work);
fn offchain_local_storage_should_work(wasm_method: WasmExecutionMethod) {
- use sp_core::offchain::OffchainStorage;
-
let mut ext = TestExternalities::default();
let (offchain, state) = testing::TestOffchainExt::new();
ext.register_extension(OffchainExt::new(offchain));
@@ -489,11 +498,10 @@ fn offchain_local_storage_should_work(wasm_method: WasmExecutionMethod) {
).unwrap(),
true.encode(),
);
- assert_eq!(state.read().persistent_storage.get(b"", b"test"), Some(vec![]));
+ assert_eq!(state.read().persistent_storage.get(b"test"), Some(vec![]));
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(offchain_http_should_work);
fn offchain_http_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let (offchain, state) = testing::TestOffchainExt::new();
@@ -521,9 +529,7 @@ fn offchain_http_should_work(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
-#[should_panic(expected = "Allocator ran out of space")]
+test_wasm_execution!(should_trap_when_heap_exhausted);
fn should_trap_when_heap_exhausted(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
@@ -533,18 +539,20 @@ fn should_trap_when_heap_exhausted(wasm_method: WasmExecutionMethod) {
HostFunctions::host_functions(),
8,
);
- executor.call_in_wasm(
+
+ let err = executor.call_in_wasm(
&wasm_binary_unwrap()[..],
None,
"test_exhaust_heap",
&[0],
&mut ext.ext(),
sp_core::traits::MissingHostFunctions::Allow,
- ).unwrap();
+ ).unwrap_err();
+
+ assert!(err.contains("Allocator ran out of space"));
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(returns_mutable_static);
fn returns_mutable_static(wasm_method: WasmExecutionMethod) {
let runtime = crate::wasm_runtime::create_wasm_runtime_with_code(
wasm_method,
@@ -569,8 +577,7 @@ fn returns_mutable_static(wasm_method: WasmExecutionMethod) {
// returned to its initial value and thus the stack space is going to be leaked.
//
// See https://github.com/paritytech/substrate/issues/2967 for details
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(restoration_of_globals);
fn restoration_of_globals(wasm_method: WasmExecutionMethod) {
// Allocate 32 pages (of 65536 bytes) which gives the runtime 2048KB of heap to operate on
// (plus some additional space unused from the initial pages requested by the wasm runtime
@@ -598,7 +605,7 @@ fn restoration_of_globals(wasm_method: WasmExecutionMethod) {
assert!(res.is_ok());
}
-#[test_case(WasmExecutionMethod::Interpreted)]
+test_wasm_execution!(interpreted_only heap_is_reset_between_calls);
fn heap_is_reset_between_calls(wasm_method: WasmExecutionMethod) {
let runtime = crate::wasm_runtime::create_wasm_runtime_with_code(
wasm_method,
@@ -622,8 +629,7 @@ fn heap_is_reset_between_calls(wasm_method: WasmExecutionMethod) {
instance.call_export("check_and_set_in_heap", ¶ms).unwrap();
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(parallel_execution);
fn parallel_execution(wasm_method: WasmExecutionMethod) {
let executor = std::sync::Arc::new(crate::WasmExecutor::new(
wasm_method,
@@ -658,7 +664,7 @@ fn parallel_execution(wasm_method: WasmExecutionMethod) {
}
}
-#[test_case(WasmExecutionMethod::Interpreted)]
+test_wasm_execution!(wasm_tracing_should_work);
fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) {
use std::sync::{Arc, Mutex};
@@ -730,10 +736,8 @@ fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) {
assert_eq!(len, 2);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(spawning_runtime_instance_should_work);
fn spawning_runtime_instance_should_work(wasm_method: WasmExecutionMethod) {
-
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -745,10 +749,8 @@ fn spawning_runtime_instance_should_work(wasm_method: WasmExecutionMethod) {
).unwrap();
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(spawning_runtime_instance_nested_should_work);
fn spawning_runtime_instance_nested_should_work(wasm_method: WasmExecutionMethod) {
-
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -760,10 +762,8 @@ fn spawning_runtime_instance_nested_should_work(wasm_method: WasmExecutionMethod
).unwrap();
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(panic_in_spawned_instance_panics_on_joining_its_result);
fn panic_in_spawned_instance_panics_on_joining_its_result(wasm_method: WasmExecutionMethod) {
-
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
diff --git a/client/executor/src/integration_tests/sandbox.rs b/client/executor/src/integration_tests/sandbox.rs
index 447e395c2fb084aa0644504138987a673c40614d..7ce9c94a2db8ae667a9446b069220355db4cb246 100644
--- a/client/executor/src/integration_tests/sandbox.rs
+++ b/client/executor/src/integration_tests/sandbox.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
@@ -18,12 +18,11 @@
use super::{TestExternalities, call_in_wasm};
use crate::WasmExecutionMethod;
+use crate::test_wasm_execution;
use codec::Encode;
-use test_case::test_case;
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(sandbox_should_work);
fn sandbox_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -60,8 +59,7 @@ fn sandbox_should_work(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(sandbox_trap);
fn sandbox_trap(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -87,8 +85,7 @@ fn sandbox_trap(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(start_called);
fn start_called(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -131,8 +128,7 @@ fn start_called(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(invoke_args);
fn invoke_args(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -171,8 +167,7 @@ fn invoke_args(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(return_val);
fn return_val(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -199,8 +194,7 @@ fn return_val(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(unlinkable_module);
fn unlinkable_module(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -225,8 +219,7 @@ fn unlinkable_module(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(corrupted_module);
fn corrupted_module(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -245,8 +238,7 @@ fn corrupted_module(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(start_fn_ok);
fn start_fn_ok(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -274,8 +266,7 @@ fn start_fn_ok(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(start_fn_traps);
fn start_fn_traps(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
@@ -304,8 +295,7 @@ fn start_fn_traps(wasm_method: WasmExecutionMethod) {
);
}
-#[test_case(WasmExecutionMethod::Interpreted)]
-#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
+test_wasm_execution!(get_global_val_works);
fn get_global_val_works(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
diff --git a/client/executor/src/lib.rs b/client/executor/src/lib.rs
index 56a81b24b4076e39c1d66a7bc57058ae1dcd8e7d..ccb7aa1b445b222db65924526cfdf6e661017cb4 100644
--- a/client/executor/src/lib.rs
+++ b/client/executor/src/lib.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/executor/src/native_executor.rs b/client/executor/src/native_executor.rs
index b5d67b9e73f4226a1c20d637c3ad7cb0dc41ea87..766dada331cd1b866a4e41a81d56454d74503104 100644
--- a/client/executor/src/native_executor.rs
+++ b/client/executor/src/native_executor.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/executor/src/wasm_runtime.rs b/client/executor/src/wasm_runtime.rs
index 7288df35f31c42b02a6f66f1dc4222a3f60f446d..a7d8b0ce2387ef18b415ddf68e4e3dfe429f5a98 100644
--- a/client/executor/src/wasm_runtime.rs
+++ b/client/executor/src/wasm_runtime.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Traits and accessor functions for calling into the Substrate Wasm runtime.
//!
diff --git a/client/executor/wasmi/src/lib.rs b/client/executor/wasmi/src/lib.rs
index 17b92e04950c9766253af313a115073aed634690..e6a6ef3a61039e73b06e6909ca9bee765eb937f5 100644
--- a/client/executor/wasmi/src/lib.rs
+++ b/client/executor/wasmi/src/lib.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! This crate provides an implementation of `WasmModule` that is baked by wasmi.
diff --git a/client/executor/wasmtime/src/host.rs b/client/executor/wasmtime/src/host.rs
index 8d20c9a566dc8c5ad3300e4f50c8a3c4bdfdbdc4..c1eb77ff81f344728721405e316f3769783d255e 100644
--- a/client/executor/wasmtime/src/host.rs
+++ b/client/executor/wasmtime/src/host.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! This module defines `HostState` and `HostContext` structs which provide logic and state
//! required for execution of host.
diff --git a/client/executor/wasmtime/src/imports.rs b/client/executor/wasmtime/src/imports.rs
index add62df5cef45851451503ce2a00b3d2e537b45f..b5eaeae5e66cd51f1e0baa6f525430e17cd4cbe9 100644
--- a/client/executor/wasmtime/src/imports.rs
+++ b/client/executor/wasmtime/src/imports.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/executor/wasmtime/src/instance_wrapper.rs b/client/executor/wasmtime/src/instance_wrapper.rs
index 089d8cb237b56c42eb43e112d17dde718e6d94c3..2103ab9b7b98c463785aa6912f7e30576b825bd5 100644
--- a/client/executor/wasmtime/src/instance_wrapper.rs
+++ b/client/executor/wasmtime/src/instance_wrapper.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/executor/wasmtime/src/instance_wrapper/globals_snapshot.rs b/client/executor/wasmtime/src/instance_wrapper/globals_snapshot.rs
index 42935d851d95c638b22d35693d7a47d5147356cc..a6b1ed394150d86f38c952563370a1d25508c239 100644
--- a/client/executor/wasmtime/src/instance_wrapper/globals_snapshot.rs
+++ b/client/executor/wasmtime/src/instance_wrapper/globals_snapshot.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/executor/wasmtime/src/lib.rs b/client/executor/wasmtime/src/lib.rs
index 66e4e085235ac3adc2e4026679ec849d002ed94a..db7776d4c58455b7a9d1a571d8f30fbdf85477b8 100644
--- a/client/executor/wasmtime/src/lib.rs
+++ b/client/executor/wasmtime/src/lib.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
///! Defines a `WasmRuntime` that uses the Wasmtime JIT to execute.
diff --git a/client/executor/wasmtime/src/runtime.rs b/client/executor/wasmtime/src/runtime.rs
index 965b0675357218902a50a1f8bb53e4721c7f5f35..a17a034918db74e6749e5bf4fb6102c8c365144c 100644
--- a/client/executor/wasmtime/src/runtime.rs
+++ b/client/executor/wasmtime/src/runtime.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Defines the compiled Wasm runtime that uses Wasmtime internally.
diff --git a/client/executor/wasmtime/src/state_holder.rs b/client/executor/wasmtime/src/state_holder.rs
index 711d3bb735d7c04306525ba451f1e4be84ed9d21..0e2684cd25130b8aaffa6280a01a6281b773b4b0 100644
--- a/client/executor/wasmtime/src/state_holder.rs
+++ b/client/executor/wasmtime/src/state_holder.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/executor/wasmtime/src/util.rs b/client/executor/wasmtime/src/util.rs
index d2de95d4cc7150d6ed8768ad48181ae9f9885cb4..1437c6f8509bf0350ce65f302002dd899a7d2f22 100644
--- a/client/executor/wasmtime/src/util.rs
+++ b/client/executor/wasmtime/src/util.rs
@@ -1,18 +1,20 @@
-// Copyright 2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
use std::ops::Range;
diff --git a/client/finality-grandpa/Cargo.toml b/client/finality-grandpa/Cargo.toml
index 8966f5e8f657aa922688a10c02b7e806b9ffb6b3..69744691b820468be1693dff79065fb1f1459ebe 100644
--- a/client/finality-grandpa/Cargo.toml
+++ b/client/finality-grandpa/Cargo.toml
@@ -20,7 +20,7 @@ fork-tree = { version = "2.0.0", path = "../../utils/fork-tree" }
futures = "0.3.4"
futures-timer = "3.0.1"
log = "0.4.8"
-parking_lot = "0.10.0"
+parking_lot = "0.11.1"
rand = "0.7.2"
parity-scale-codec = { version = "1.3.4", features = ["derive"] }
sp-application-crypto = { version = "2.0.0", path = "../../primitives/application-crypto" }
@@ -28,7 +28,7 @@ sp-arithmetic = { version = "2.0.0", path = "../../primitives/arithmetic" }
sp-runtime = { version = "2.0.0", path = "../../primitives/runtime" }
sp-utils = { version = "2.0.0", path = "../../primitives/utils" }
sp-consensus = { version = "0.8.0", path = "../../primitives/consensus/common" }
-sc-consensus = { version = "0.8.0", path = "../../client/consensus/common" }
+sc-consensus = { version = "0.8.0", path = "../consensus/common" }
sp-core = { version = "2.0.0", path = "../../primitives/core" }
sp-keystore = { version = "0.8.0", path = "../../primitives/keystore" }
sp-api = { version = "2.0.0", path = "../../primitives/api" }
diff --git a/client/finality-grandpa/rpc/src/error.rs b/client/finality-grandpa/rpc/src/error.rs
index 6464acbe10ea076ed637d603fbf48692509fb8e6..6122db03f880517d7ae43fbd815a76e751562c68 100644
--- a/client/finality-grandpa/rpc/src/error.rs
+++ b/client/finality-grandpa/rpc/src/error.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/finality-grandpa/rpc/src/finality.rs b/client/finality-grandpa/rpc/src/finality.rs
index 640b108f5aef8e9e70a78394fc981bd34b206fe9..83a32a6340ca90f20f47af0c67f483577f47f514 100644
--- a/client/finality-grandpa/rpc/src/finality.rs
+++ b/client/finality-grandpa/rpc/src/finality.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/finality-grandpa/rpc/src/lib.rs b/client/finality-grandpa/rpc/src/lib.rs
index 36d3d5f49deeda0442f54dc4f97a730189d8f283..bef20de35530d1620942f11a9d0b8d27ba1df1e6 100644
--- a/client/finality-grandpa/rpc/src/lib.rs
+++ b/client/finality-grandpa/rpc/src/lib.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/finality-grandpa/rpc/src/notification.rs b/client/finality-grandpa/rpc/src/notification.rs
index fd03a622b21967c723bcdfb67a56bd70ffd5cdd3..4c9141be3631ae4acd359da36ecc0e6a247bd11d 100644
--- a/client/finality-grandpa/rpc/src/notification.rs
+++ b/client/finality-grandpa/rpc/src/notification.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/finality-grandpa/rpc/src/report.rs b/client/finality-grandpa/rpc/src/report.rs
index a635728cb938adf73d4ae94e1db1a63d5fcb9f50..0482d90f58f0a0bf67001d570c77686440a9f969 100644
--- a/client/finality-grandpa/rpc/src/report.rs
+++ b/client/finality-grandpa/rpc/src/report.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/finality-grandpa/src/authorities.rs b/client/finality-grandpa/src/authorities.rs
index 07297628c47ad8c3556f5fdfc0a9425a8ef83ba2..307cd33d890068d7e5333faee9a38866e61b6f7c 100644
--- a/client/finality-grandpa/src/authorities.rs
+++ b/client/finality-grandpa/src/authorities.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/finality-grandpa/src/aux_schema.rs b/client/finality-grandpa/src/aux_schema.rs
index f9dfbb59c73247441f0b5ba57b264dd347ffe5c3..c87db41d79137289b5fda1a6575b74c07df9336f 100644
--- a/client/finality-grandpa/src/aux_schema.rs
+++ b/client/finality-grandpa/src/aux_schema.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Schema for stuff in the aux-db.
diff --git a/client/finality-grandpa/src/communication/gossip.rs b/client/finality-grandpa/src/communication/gossip.rs
index 276529d555ffe062a12e79b8544cc3265272467e..c217218aecc4ff09502b0ea941aebb0ce9423a16 100644
--- a/client/finality-grandpa/src/communication/gossip.rs
+++ b/client/finality-grandpa/src/communication/gossip.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Gossip and politeness for polite-grandpa.
//!
diff --git a/client/finality-grandpa/src/communication/mod.rs b/client/finality-grandpa/src/communication/mod.rs
index 29fe8bc7471a0b74ac91e41bd77ad0cef832617f..77d2d15e5d0209e89ba86dbb2697096f8619f279 100644
--- a/client/finality-grandpa/src/communication/mod.rs
+++ b/client/finality-grandpa/src/communication/mod.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
@@ -846,7 +846,7 @@ fn check_catch_up(
}
Ok(())
- };
+ }
check_weight(
voters,
diff --git a/client/finality-grandpa/src/communication/periodic.rs b/client/finality-grandpa/src/communication/periodic.rs
index dadd7deb57fca1d34dd01baf0d434533f1a99fbe..377882ed5dd2d5d4bb2136fbd5314e0d557b890c 100644
--- a/client/finality-grandpa/src/communication/periodic.rs
+++ b/client/finality-grandpa/src/communication/periodic.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Periodic rebroadcast of neighbor packets.
diff --git a/client/finality-grandpa/src/communication/tests.rs b/client/finality-grandpa/src/communication/tests.rs
index 27a394a062bc8b99eca9f6af6022f681238991f7..b2e4c405b4f7926eadfc468b08858d59011ed3a2 100644
--- a/client/finality-grandpa/src/communication/tests.rs
+++ b/client/finality-grandpa/src/communication/tests.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Tests for the communication portion of the GRANDPA crate.
@@ -56,7 +58,11 @@ impl sc_network_gossip::Network for TestNetwork {
let _ = self.sender.unbounded_send(Event::Report(who, cost_benefit));
}
- fn disconnect_peer(&self, _: PeerId) {}
+ fn add_set_reserved(&self, _: PeerId, _: Cow<'static, str>) {}
+
+ fn remove_set_reserved(&self, _: PeerId, _: Cow<'static, str>) {}
+
+ fn disconnect_peer(&self, _: PeerId, _: Cow<'static, str>) {}
fn write_notification(&self, who: PeerId, _: Cow<'static, str>, message: Vec) {
let _ = self.sender.unbounded_send(Event::WriteNotification(who, message));
diff --git a/client/finality-grandpa/src/environment.rs b/client/finality-grandpa/src/environment.rs
index 790be2a22178878dade0e4961193eade7703df41..5e4203b2a40f634ffd8a2179e8d1ff494ccfd402 100644
--- a/client/finality-grandpa/src/environment.rs
+++ b/client/finality-grandpa/src/environment.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/finality-grandpa/src/finality_proof.rs b/client/finality-grandpa/src/finality_proof.rs
index 55948e01576133ca44ae22ad5008e03f1a0643d7..7e662ab16571ef91da655a0018a4ec955fd565e2 100644
--- a/client/finality-grandpa/src/finality_proof.rs
+++ b/client/finality-grandpa/src/finality_proof.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/finality-grandpa/src/import.rs b/client/finality-grandpa/src/import.rs
index 89f9d0c16ad7c6d0b52fb8d08a46b5795d7bf646..d9630e272ef9c0345ce555fbea100cae00f9b5ea 100644
--- a/client/finality-grandpa/src/import.rs
+++ b/client/finality-grandpa/src/import.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
@@ -25,7 +25,7 @@ use parking_lot::RwLockWriteGuard;
use sp_blockchain::{BlockStatus, well_known_cache_keys};
use sc_client_api::{backend::Backend, utils::is_descendent_of};
use sp_utils::mpsc::TracingUnboundedSender;
-use sp_api::{TransactionFor};
+use sp_api::TransactionFor;
use sp_consensus::{
BlockImport, Error as ConsensusError,
diff --git a/client/finality-grandpa/src/justification.rs b/client/finality-grandpa/src/justification.rs
index d5ca92d50e9371cf76e80945b69edc3c3f9e3c13..9429acff06d8ce9f160bc78de66bf16032a79918 100644
--- a/client/finality-grandpa/src/justification.rs
+++ b/client/finality-grandpa/src/justification.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/finality-grandpa/src/lib.rs b/client/finality-grandpa/src/lib.rs
index 62cddbcb6b2e0eb9691e427064855ff072f6d89e..96e1e7bdc2f8045957308d87c590fa3415c5d801 100644
--- a/client/finality-grandpa/src/lib.rs
+++ b/client/finality-grandpa/src/lib.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
@@ -122,7 +122,6 @@ mod until_imported;
mod voting_rule;
pub use authorities::{SharedAuthoritySet, AuthoritySet};
-pub use communication::GRANDPA_PROTOCOL_NAME;
pub use finality_proof::{FinalityProof, FinalityProofProvider};
pub use notification::{GrandpaJustificationSender, GrandpaJustificationStream};
pub use import::GrandpaBlockImport;
@@ -329,7 +328,7 @@ impl BlockStatus for Arc where
/// A trait that includes all the client functionalities grandpa requires.
/// Ideally this would be a trait alias, we're not there yet.
-/// tracking issue https://github.com/rust-lang/rust/issues/41517
+/// tracking issue
pub trait ClientForGrandpa:
LockImportRun + Finalizer + AuxStore
+ HeaderMetadata + HeaderBackend
@@ -656,7 +655,7 @@ pub struct GrandpaParams {
///
/// It is assumed that this network will feed us Grandpa notifications. When using the
/// `sc_network` crate, it is assumed that the Grandpa notifications protocol has been passed
- /// to the configuration of the networking.
+ /// to the configuration of the networking. See [`grandpa_peers_set_config`].
pub network: N,
/// If supplied, can be used to hook on telemetry connection established events.
pub telemetry_on_connect: Option>,
@@ -668,6 +667,20 @@ pub struct GrandpaParams {
pub shared_voter_state: SharedVoterState,
}
+/// Returns the configuration value to put in
+/// [`sc_network::config::NetworkConfiguration::extra_sets`].
+pub fn grandpa_peers_set_config() -> sc_network::config::NonDefaultSetConfig {
+ sc_network::config::NonDefaultSetConfig {
+ notifications_protocol: communication::GRANDPA_PROTOCOL_NAME.into(),
+ set_config: sc_network::config::SetConfig {
+ in_peers: 25,
+ out_peers: 25,
+ reserved_nodes: Vec::new(),
+ non_reserved_mode: sc_network::config::NonReservedPeerMode::Accept,
+ },
+ }
+}
+
/// Run a GRANDPA voter as a task. Provide configuration and a link to a
/// block import worker that has already been instantiated with `block_import`.
pub fn run_grandpa_voter(
diff --git a/client/finality-grandpa/src/notification.rs b/client/finality-grandpa/src/notification.rs
index 8415583051902330a99f5c4cb723311045844ed8..b545f0d8a637e8948939e02e2c2d8003af624524 100644
--- a/client/finality-grandpa/src/notification.rs
+++ b/client/finality-grandpa/src/notification.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/finality-grandpa/src/observer.rs b/client/finality-grandpa/src/observer.rs
index c61998225e32300f542f256f70acdc0aa20102a7..c9db917e1699a89f11c816e6b8edbc7a4f54fc47 100644
--- a/client/finality-grandpa/src/observer.rs
+++ b/client/finality-grandpa/src/observer.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/finality-grandpa/src/tests.rs b/client/finality-grandpa/src/tests.rs
index a6d7dd03424638e4267d307da1f2221f33ce7142..b94981838138a7f11e7db5d90b75c4d9c9e2b7a0 100644
--- a/client/finality-grandpa/src/tests.rs
+++ b/client/finality-grandpa/src/tests.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
@@ -1026,7 +1026,7 @@ fn voter_persists_its_votes() {
drop(_block_import);
r
})
- };
+ }
runtime.spawn(alice_voter1);
@@ -1068,7 +1068,7 @@ fn voter_persists_its_votes() {
let runtime_handle = runtime_handle.clone();
async move {
- if state.compare_and_swap(0, 1, Ordering::SeqCst) == 0 {
+ if state.compare_exchange(0, 1, Ordering::SeqCst, Ordering::SeqCst).unwrap() == 0 {
// the first message we receive should be a prevote from alice.
let prevote = match signed.message {
finality_grandpa::Message::Prevote(prevote) => prevote,
@@ -1114,7 +1114,7 @@ fn voter_persists_its_votes() {
// we send in a loop including a delay until items are received, this can be
// ignored for the sake of reduced complexity.
Pin::new(&mut *round_tx.lock()).start_send(finality_grandpa::Message::Prevote(prevote)).unwrap();
- } else if state.compare_and_swap(1, 2, Ordering::SeqCst) == 1 {
+ } else if state.compare_exchange(1, 2, Ordering::SeqCst, Ordering::SeqCst).unwrap() == 1 {
// the next message we receive should be our own prevote
let prevote = match signed.message {
finality_grandpa::Message::Prevote(prevote) => prevote,
@@ -1128,7 +1128,7 @@ fn voter_persists_its_votes() {
// therefore we won't ever receive it again since it will be a
// known message on the gossip layer
- } else if state.compare_and_swap(2, 3, Ordering::SeqCst) == 2 {
+ } else if state.compare_exchange(2, 3, Ordering::SeqCst, Ordering::SeqCst).unwrap() == 2 {
// we then receive a precommit from alice for block 15
// even though we casted a prevote for block 30
let precommit = match signed.message {
diff --git a/client/finality-grandpa/src/until_imported.rs b/client/finality-grandpa/src/until_imported.rs
index 3ac94f3b062f0273f975e714c7318b9539243dae..c27eab5351562557ee1fc1a182b98ba6211d859a 100644
--- a/client/finality-grandpa/src/until_imported.rs
+++ b/client/finality-grandpa/src/until_imported.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/finality-grandpa/src/voting_rule.rs b/client/finality-grandpa/src/voting_rule.rs
index 700b0aeb551cd2a647b8722c4ab148bc7885cd52..a861e792755feaed872caff1cc644ceab751e8b8 100644
--- a/client/finality-grandpa/src/voting_rule.rs
+++ b/client/finality-grandpa/src/voting_rule.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/informant/Cargo.toml b/client/informant/Cargo.toml
index 871cc3ef426ec5fc26bff690258a3b2c3d3df7de..7cc321e4001f74ac311eeaa84c565d32e175faa9 100644
--- a/client/informant/Cargo.toml
+++ b/client/informant/Cargo.toml
@@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
ansi_term = "0.12.1"
futures = "0.3.4"
log = "0.4.8"
-parity-util-mem = { version = "0.7.0", default-features = false, features = ["primitive-types"] }
+parity-util-mem = { version = "0.8.0", default-features = false, features = ["primitive-types"] }
sc-client-api = { version = "2.0.0", path = "../api" }
sc-network = { version = "0.8.0", path = "../network" }
sp-blockchain = { version = "2.0.0", path = "../../primitives/blockchain" }
diff --git a/client/informant/src/display.rs b/client/informant/src/display.rs
index 5c8f5f8ef84aa4354238cb4d02fa7b53896b96b1..0caef4e5fbae8fabc2c0a9b92ccc272d181b407c 100644
--- a/client/informant/src/display.rs
+++ b/client/informant/src/display.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
use crate::OutputFormat;
use ansi_term::Colour;
diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs
index d4f34cb488a9789eaa36223dd1a077bf071164c5..c955834c0f111dbcce7850b99cb259666ad79197 100644
--- a/client/informant/src/lib.rs
+++ b/client/informant/src/lib.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/keystore/Cargo.toml b/client/keystore/Cargo.toml
index c0c3acde25edfc6c252735176504808896e28c9d..d4d06b6f48d48b71693d0b4b705965f929b3427b 100644
--- a/client/keystore/Cargo.toml
+++ b/client/keystore/Cargo.toml
@@ -24,7 +24,7 @@ sp-core = { version = "2.0.0", path = "../../primitives/core" }
sp-keystore = { version = "0.8.0", path = "../../primitives/keystore" }
hex = "0.4.0"
merlin = { version = "2.0", default-features = false }
-parking_lot = "0.10.0"
+parking_lot = "0.11.1"
rand = "0.7.2"
serde_json = "1.0.41"
subtle = "2.1.1"
diff --git a/client/keystore/src/lib.rs b/client/keystore/src/lib.rs
index 0b6d654bc623ecda634b3612ac0df9350a342a28..9cad56efacfd66eb8aac3af9790957f15d02175b 100644
--- a/client/keystore/src/lib.rs
+++ b/client/keystore/src/lib.rs
@@ -1,18 +1,20 @@
-// Copyright 2017-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Keystore (and session key management) for ed25519 based chains like Polkadot.
diff --git a/client/keystore/src/local.rs b/client/keystore/src/local.rs
index a31e3e1f1e402df5bae884de80993d1f1fdcb630..866a50ae4c93ce43f7382db0053006a9dbabe35b 100644
--- a/client/keystore/src/local.rs
+++ b/client/keystore/src/local.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -167,9 +167,7 @@ impl SyncCryptoStore for LocalKeystore {
let all_keys = SyncCryptoStore::keys(self, id)?
.into_iter()
.collect::>();
- Ok(keys.into_iter()
- .filter(|key| all_keys.contains(key))
- .collect::>())
+ Ok(keys.into_iter().filter(|key| all_keys.contains(key)).collect::>())
}
fn sign_with(
diff --git a/client/light/Cargo.toml b/client/light/Cargo.toml
index d9fecb7aa8fa2c22e270d48a58269d17b37511d8..4516b5c4b6659de6abeb97ca0baaa8a1e3607f28 100644
--- a/client/light/Cargo.toml
+++ b/client/light/Cargo.toml
@@ -11,7 +11,7 @@ documentation = "https://docs.rs/sc-light"
readme = "README.md"
[dependencies]
-parking_lot = "0.10.0"
+parking_lot = "0.11.1"
lazy_static = "1.4.0"
hash-db = "0.15.2"
sp-runtime = { version = "2.0.0", path = "../../primitives/runtime" }
diff --git a/client/light/src/backend.rs b/client/light/src/backend.rs
index 74e1d613bcf56ae80b652cef2358fb45927b850c..27e0754eb552e9b29b364e9307436ff5c031af81 100644
--- a/client/light/src/backend.rs
+++ b/client/light/src/backend.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/light/src/blockchain.rs b/client/light/src/blockchain.rs
index 3b5753f2849d51c8199d98debb99bf8e440386f0..f682e6e35b3d098c6d913cc79a96acaf821ded5e 100644
--- a/client/light/src/blockchain.rs
+++ b/client/light/src/blockchain.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/light/src/call_executor.rs b/client/light/src/call_executor.rs
index 458ea2bd6b844b5b430f08823f94f283a785ad87..7115f24a77d67168ecebbced1c52cee9ec1488c1 100644
--- a/client/light/src/call_executor.rs
+++ b/client/light/src/call_executor.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/light/src/fetcher.rs b/client/light/src/fetcher.rs
index 60fce87b8d0c26ecddbdf22d2ebd09e08060a696..b71c4871803da4fa907959cefc924333912c2ef4 100644
--- a/client/light/src/fetcher.rs
+++ b/client/light/src/fetcher.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/light/src/lib.rs b/client/light/src/lib.rs
index 899d1ae31a3dd951a89090a0ed69cc6e5fb71f5f..e647b8743cc0f8865a84b793f9f6fc621dfda8a9 100644
--- a/client/light/src/lib.rs
+++ b/client/light/src/lib.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/network-gossip/Cargo.toml b/client/network-gossip/Cargo.toml
index bbbb83f206166a53ee01b9221146e3407e7a01d0..5c3990d320bb08cd62896d2b110ea1ffc3ec44c5 100644
--- a/client/network-gossip/Cargo.toml
+++ b/client/network-gossip/Cargo.toml
@@ -17,7 +17,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
futures = "0.3.4"
futures-timer = "3.0.1"
-libp2p = { version = "0.31.2", default-features = false }
+libp2p = { version = "0.33.0", default-features = false }
log = "0.4.8"
lru = "0.6.1"
sc-network = { version = "0.8.0", path = "../network" }
diff --git a/client/network-gossip/src/bridge.rs b/client/network-gossip/src/bridge.rs
index 4deaad6d748fd13f7dc11f3f8d41fcfe77976862..d444409d1cd3d9598c0bae9c11e8897f9dedb078 100644
--- a/client/network-gossip/src/bridge.rs
+++ b/client/network-gossip/src/bridge.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
use crate::{Network, Validator};
use crate::state_machine::{ConsensusGossip, TopicNotification, PERIODIC_MAINTENANCE_INTERVAL};
@@ -178,6 +180,12 @@ impl Future for GossipEngine {
ForwardingState::Idle => {
match this.network_event_stream.poll_next_unpin(cx) {
Poll::Ready(Some(event)) => match event {
+ Event::SyncConnected { remote } => {
+ this.network.add_set_reserved(remote, this.protocol.clone());
+ }
+ Event::SyncDisconnected { remote } => {
+ this.network.remove_set_reserved(remote, this.protocol.clone());
+ }
Event::NotificationStreamOpened { remote, protocol, role } => {
if protocol != this.protocol {
continue;
@@ -323,10 +331,16 @@ mod tests {
fn report_peer(&self, _: PeerId, _: ReputationChange) {
}
- fn disconnect_peer(&self, _: PeerId) {
+ fn disconnect_peer(&self, _: PeerId, _: Cow<'static, str>) {
unimplemented!();
}
+ fn add_set_reserved(&self, _: PeerId, _: Cow<'static, str>) {
+ }
+
+ fn remove_set_reserved(&self, _: PeerId, _: Cow<'static, str>) {
+ }
+
fn write_notification(&self, _: PeerId, _: Cow<'static, str>, _: Vec) {
unimplemented!();
}
diff --git a/client/network-gossip/src/lib.rs b/client/network-gossip/src/lib.rs
index 2b333610223e2a19c0c4553b8973eb77e65919ee..59c99088bdf24f87fa177d3ce14e1d6c225be613 100644
--- a/client/network-gossip/src/lib.rs
+++ b/client/network-gossip/src/lib.rs
@@ -1,18 +1,20 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
//! Polite gossiping.
//!
@@ -38,6 +40,11 @@
//! - Use the methods of the `GossipEngine` in order to send out messages and receive incoming
//! messages.
//!
+//! The `GossipEngine` will automatically use `Network::add_set_reserved` and
+//! `Network::remove_set_reserved` to maintain a set of peers equal to the set of peers the
+//! node is syncing from. See the documentation of `sc-network` for more explanations about the
+//! concepts of peer sets.
+//!
//! # What is a validator?
//!
//! The primary role of a `Validator` is to process incoming messages from peers, and decide
@@ -59,9 +66,9 @@ pub use self::state_machine::TopicNotification;
pub use self::validator::{DiscardAll, MessageIntent, Validator, ValidatorContext, ValidationResult};
use futures::prelude::*;
-use sc_network::{Event, ExHashT, NetworkService, PeerId, ReputationChange};
+use sc_network::{multiaddr, Event, ExHashT, NetworkService, PeerId, ReputationChange};
use sp_runtime::{traits::Block as BlockT};
-use std::{borrow::Cow, pin::Pin, sync::Arc};
+use std::{borrow::Cow, iter, pin::Pin, sync::Arc};
mod bridge;
mod state_machine;
@@ -75,8 +82,14 @@ pub trait Network {
/// Adjust the reputation of a node.
fn report_peer(&self, peer_id: PeerId, reputation: ReputationChange);
+ /// Adds the peer to the set of peers to be connected to with this protocol.
+ fn add_set_reserved(&self, who: PeerId, protocol: Cow<'static, str>);
+
+ /// Removes the peer from the set of peers to be connected to with this protocol.
+ fn remove_set_reserved(&self, who: PeerId, protocol: Cow<'static, str>);
+
/// Force-disconnect a peer.
- fn disconnect_peer(&self, who: PeerId);
+ fn disconnect_peer(&self, who: PeerId, protocol: Cow<'static, str>);
/// Send a notification to a peer.
fn write_notification(&self, who: PeerId, protocol: Cow<'static, str>, message: Vec);
@@ -97,8 +110,26 @@ impl Network for Arc> {
NetworkService::report_peer(self, peer_id, reputation);
}
- fn disconnect_peer(&self, who: PeerId) {
- NetworkService::disconnect_peer(self, who)
+ fn add_set_reserved(&self, who: PeerId, protocol: Cow<'static, str>) {
+ let addr = iter::once(multiaddr::Protocol::P2p(who.into()))
+ .collect::();
+ let result = NetworkService::add_to_peers_set(self, protocol, iter::once(addr).collect());
+ if let Err(err) = result {
+ log::error!(target: "gossip", "add_set_reserved failed: {}", err);
+ }
+ }
+
+ fn remove_set_reserved(&self, who: PeerId, protocol: Cow<'static, str>) {
+ let addr = iter::once(multiaddr::Protocol::P2p(who.into()))
+ .collect::();
+ let result = NetworkService::remove_from_peers_set(self, protocol, iter::once(addr).collect());
+ if let Err(err) = result {
+ log::error!(target: "gossip", "remove_set_reserved failed: {}", err);
+ }
+ }
+
+ fn disconnect_peer(&self, who: PeerId, protocol: Cow<'static, str>) {
+ NetworkService::disconnect_peer(self, who, protocol)
}
fn write_notification(&self, who: PeerId, protocol: Cow<'static, str>, message: Vec) {
diff --git a/client/network-gossip/src/state_machine.rs b/client/network-gossip/src/state_machine.rs
index 88f9d48375dec9e7c834651b87666fd2c7ad9717..58a0f62cb13049470c7e9a72f1d8df33a8eb5066 100644
--- a/client/network-gossip/src/state_machine.rs
+++ b/client/network-gossip/src/state_machine.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
@@ -495,10 +495,16 @@ mod tests {
self.inner.lock().unwrap().peer_reports.push((peer_id, reputation_change));
}
- fn disconnect_peer(&self, _: PeerId) {
+ fn disconnect_peer(&self, _: PeerId, _: Cow<'static, str>) {
unimplemented!();
}
+ fn add_set_reserved(&self, _: PeerId, _: Cow<'static, str>) {
+ }
+
+ fn remove_set_reserved(&self, _: PeerId, _: Cow<'static, str>) {
+ }
+
fn write_notification(&self, _: PeerId, _: Cow<'static, str>, _: Vec) {
unimplemented!();
}
diff --git a/client/network-gossip/src/validator.rs b/client/network-gossip/src/validator.rs
index fd29aaddafe6dcd89f2e722bdcfa07854fc04225..4b5440c1a06f3c7d7f6fa38b84a64a87e3543629 100644
--- a/client/network-gossip/src/validator.rs
+++ b/client/network-gossip/src/validator.rs
@@ -1,6 +1,6 @@
// This file is part of Substrate.
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
+// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
diff --git a/client/network/Cargo.toml b/client/network/Cargo.toml
index 0b8d3da928f5e3d95e3be75150c7a26e15a210ea..a300dac19bfccad7563cb6e02b3757dbfc388ae8 100644
--- a/client/network/Cargo.toml
+++ b/client/network/Cargo.toml
@@ -36,7 +36,6 @@ ip_network = "0.3.4"
linked-hash-map = "0.5.2"
linked_hash_set = "0.1.3"
log = "0.4.8"
-lru = "0.6.1"
nohash-hasher = "0.2.0"
parking_lot = "0.11.1"
pin-project = "0.4.6"
@@ -61,16 +60,16 @@ thiserror = "1"
unsigned-varint = { version = "0.5.0", features = ["futures", "futures-codec"] }
void = "1.0.2"
wasm-timer = "0.2"
-zeroize = "1.0.0"
+zeroize = "1.2.0"
[dependencies.libp2p]
-version = "0.31.2"
+version = "0.33.0"
default-features = false
-features = ["identify", "kad", "mdns-async-std", "mplex", "noise", "ping", "request-response", "tcp-async-std", "websocket", "yamux"]
+features = ["identify", "kad", "mdns", "mplex", "noise", "ping", "request-response", "tcp-async-std", "websocket", "yamux"]
[dev-dependencies]
assert_matches = "1.3"
-libp2p = { version = "0.31.2", default-features = false }
+libp2p = { version = "0.33.0", default-features = false }
quickcheck = "0.9.0"
rand = "0.7.2"
sp-keyring = { version = "2.0.0", path = "../../primitives/keyring" }
diff --git a/client/network/src/behaviour.rs b/client/network/src/behaviour.rs
index b2914a5e0a72b5a7d81fb83b19e9a97c7e4a9ff2..de983bd7139d7131ec07310b4d189753a2b8e682 100644
--- a/client/network/src/behaviour.rs
+++ b/client/network/src/behaviour.rs
@@ -1,34 +1,37 @@
-// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
-// Substrate is free software: you can redistribute it and/or modify
+// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
+// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
+
+// This program 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,
+// This program 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
+// 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 .
+// along with this program. If not, see .
use crate::{
- config::{ProtocolId, Role}, block_requests, light_client_handler,
- peer_info, request_responses, discovery::{DiscoveryBehaviour, DiscoveryConfig, DiscoveryOut},
+ config::{ProtocolId, Role}, light_client_handler, peer_info, request_responses,
+ discovery::{DiscoveryBehaviour, DiscoveryConfig, DiscoveryOut},
protocol::{message::Roles, CustomMessageOutcome, NotificationsSink, Protocol},
ObservedRole, DhtEvent, ExHashT,
};
use bytes::Bytes;
-use codec::Encode as _;
+use futures::channel::oneshot;
use libp2p::NetworkBehaviour;
use libp2p::core::{Multiaddr, PeerId, PublicKey};
use libp2p::identify::IdentifyInfo;
use libp2p::kad::record;
use libp2p::swarm::{NetworkBehaviourAction, NetworkBehaviourEventProcess, PollParameters};
use log::debug;
+use prost::Message;
use sp_consensus::{BlockOrigin, import_queue::{IncomingBlock, Origin}};
use sp_runtime::{traits::{Block as BlockT, NumberFor}, Justification};
use std::{
@@ -40,7 +43,7 @@ use std::{
};
pub use crate::request_responses::{
- ResponseFailure, InboundFailure, RequestFailure, OutboundFailure, RequestId, SendRequestError
+ ResponseFailure, InboundFailure, RequestFailure, OutboundFailure, RequestId,
};
/// General behaviour of the network. Combines all protocols together.
@@ -56,8 +59,6 @@ pub struct Behaviour {
discovery: DiscoveryBehaviour,
/// Generic request-reponse protocols.
request_responses: request_responses::RequestResponsesBehaviour,
- /// Block request handling.
- block_requests: block_requests::BlockRequests,
/// Light client request handling.
light_client_handler: light_client_handler::LightClientHandler,
@@ -68,6 +69,11 @@ pub struct Behaviour {
/// Role of our local node, as originally passed from the configuration.
#[behaviour(ignore)]
role: Role,
+
+ /// Protocol name used to send out block requests via
+ /// [`request_responses::RequestResponsesBehaviour`].
+ #[behaviour(ignore)]
+ block_request_protocol_name: String,
}
/// Event generated by `Behaviour`.
@@ -91,34 +97,18 @@ pub enum BehaviourOut {
result: Result,
},
- /// A request initiated using [`Behaviour::send_request`] has succeeded or failed.
- RequestFinished {
- /// Request that has succeeded.
- request_id: RequestId,
- /// Response sent by the remote or reason for failure.
- result: Result, RequestFailure>,
- },
-
- /// Started a new request with the given node.
+ /// A request has succeeded or failed.
///
- /// This event is for statistics purposes only. The request and response handling are entirely
- /// internal to the behaviour.
- OpaqueRequestStarted {
- peer: PeerId,
- /// Protocol name of the request.
- protocol: String,
- },
- /// Finished, successfully or not, a previously-started request.
- ///
- /// This event is for statistics purposes only. The request and response handling are entirely
- /// internal to the behaviour.
- OpaqueRequestFinished {
- /// Who we were requesting.
+ /// This event is generated for statistics purposes.
+ RequestFinished {
+ /// Peer that we send a request to.
peer: PeerId,
- /// Protocol name of the request.
- protocol: String,
- /// How long before the response came or the request got cancelled.
- request_duration: Duration,
+ /// Name of the protocol in question.
+ protocol: Cow<'static, str>,
+ /// Duration the request took.
+ duration: Duration,
+ /// Result of the request.
+ result: Result<(), RequestFailure>,
},
/// Opened a substream with the given node with the given notifications protocol.
@@ -166,6 +156,12 @@ pub enum BehaviourOut {
messages: Vec<(Cow<'static, str>, Bytes)>,
},
+ /// Now connected to a new peer for syncing purposes.
+ SyncConnected(PeerId),
+
+ /// No longer connected to a peer for syncing purposes.
+ SyncDisconnected(PeerId),
+
/// Events generated by a DHT as a response to get_value or put_value requests as well as the
/// request duration.
Dht(DhtEvent, Duration),
@@ -178,21 +174,28 @@ impl Behaviour {
role: Role,
user_agent: String,
local_public_key: PublicKey,
- block_requests: block_requests::BlockRequests,
light_client_handler: light_client_handler::LightClientHandler,
disco_config: DiscoveryConfig,
- request_response_protocols: Vec,
+ // Block request protocol config.
+ block_request_protocol_config: request_responses::ProtocolConfig,
+ // All remaining request protocol configs.
+ mut request_response_protocols: Vec,
) -> Result {
+ // Extract protocol name and add to `request_response_protocols`.
+ let block_request_protocol_name = block_request_protocol_config.name.to_string();
+ request_response_protocols.push(block_request_protocol_config);
+
Ok(Behaviour {
substrate,
peer_info: peer_info::PeerInfoBehaviour::new(user_agent, local_public_key),
discovery: disco_config.finish(),
request_responses:
request_responses::RequestResponsesBehaviour::new(request_response_protocols.into_iter())?,
- block_requests,
light_client_handler,
events: VecDeque::new(),
role,
+
+ block_request_protocol_name,
})
}
@@ -234,42 +237,14 @@ impl Behaviour {
}
/// Initiates sending a request.
- ///
- /// An error is returned if we are not connected to the target peer of if the protocol doesn't
- /// match one that has been registered.
- pub fn send_request(&mut self, target: &PeerId, protocol: &str, request: Vec)
- -> Result
- {
- self.request_responses.send_request(target, protocol, request)
- }
-
- /// Registers a new notifications protocol.
- ///
- /// Please call `event_stream` before registering a protocol, otherwise you may miss events
- /// about the protocol that you have registered.
- ///
- /// You are very strongly encouraged to call this method very early on. Any connection open
- /// will retain the protocols that were registered then, and not any new one.
- pub fn register_notifications_protocol(
+ pub fn send_request(
&mut self,
- protocol: impl Into>,
+ target: &PeerId,
+ protocol: &str,
+ request: Vec,
+ pending_response: oneshot::Sender, RequestFailure>>,
) {
- let protocol = protocol.into();
-
- // This is the message that we will send to the remote as part of the initial handshake.
- // At the moment, we force this to be an encoded `Roles`.
- let handshake_message = Roles::from(&self.role).encode();
-
- let list = self.substrate.register_notifications_protocol(protocol.clone(), handshake_message);
- for (remote, roles, notifications_sink) in list {
- let role = reported_roles_to_observed_role(&self.role, remote, roles);
- self.events.push_back(BehaviourOut::NotificationStreamOpened {
- remote: remote.clone(),
- protocol: protocol.clone(),
- role,
- notifications_sink: notifications_sink.clone(),
- });
- }
+ self.request_responses.send_request(target, protocol, request, pending_response)
}
/// Returns a shared reference to the user protocol.
@@ -329,61 +304,51 @@ Behaviour {
self.events.push_back(BehaviourOut::BlockImport(origin, blocks)),
CustomMessageOutcome::JustificationImport(origin, hash, nb, justification) =>
self.events.push_back(BehaviourOut::JustificationImport(origin, hash, nb, justification)),
- CustomMessageOutcome::BlockRequest { target, request } => {
- match self.block_requests.send_request(&target, request) {
- block_requests::SendRequestOutcome::Ok => {
- self.events.push_back(BehaviourOut::OpaqueRequestStarted {
- peer: target,
- protocol: self.block_requests.protocol_name().to_owned(),
- });
- },
- block_requests::SendRequestOutcome::Replaced { request_duration, .. } => {
- self.events.push_back(BehaviourOut::OpaqueRequestFinished {
- peer: target.clone(),
- protocol: self.block_requests.protocol_name().to_owned(),
- request_duration,
- });
- self.events.push_back(BehaviourOut::OpaqueRequestStarted {
- peer: target,
- protocol: self.block_requests.protocol_name().to_owned(),
- });
- }
- block_requests::SendRequestOutcome::NotConnected |
- block_requests::SendRequestOutcome::EncodeError(_) => {},
+ CustomMessageOutcome::BlockRequest { target, request, pending_response } => {
+ let mut buf = Vec::with_capacity(request.encoded_len());
+ if let Err(err) = request.encode(&mut buf) {
+ log::warn!(
+ target: "sync",
+ "Failed to encode block request {:?}: {:?}",
+ request, err
+ );
+ return
}
+
+ self.request_responses.send_request(
+ &target, &self.block_request_protocol_name, buf, pending_response,
+ );
},
- CustomMessageOutcome::NotificationStreamOpened { remote, protocols, roles, notifications_sink } => {
+ CustomMessageOutcome::NotificationStreamOpened { remote, protocol, roles, notifications_sink } => {
let role = reported_roles_to_observed_role(&self.role, &remote, roles);
- for protocol in protocols {
- self.events.push_back(BehaviourOut::NotificationStreamOpened {
- remote: remote.clone(),
- protocol,
- role: role.clone(),
- notifications_sink: notifications_sink.clone(),
- });
- }
+ self.events.push_back(BehaviourOut::NotificationStreamOpened {
+ remote,
+ protocol,
+ role: role.clone(),
+ notifications_sink: notifications_sink.clone(),
+ });
},
- CustomMessageOutcome::NotificationStreamReplaced { remote, protocols, notifications_sink } =>
- for protocol in protocols {
- self.events.push_back(BehaviourOut::NotificationStreamReplaced {
- remote: remote.clone(),
- protocol,
- notifications_sink: notifications_sink.clone(),
- });
- },
- CustomMessageOutcome::NotificationStreamClosed { remote, protocols } =>
- for protocol in protocols {
- self.events.push_back(BehaviourOut::NotificationStreamClosed {
- remote: remote.clone(),
- protocol,
- });
- },
+ CustomMessageOutcome::NotificationStreamReplaced { remote, protocol, notifications_sink } =>
+ self.events.push_back(BehaviourOut::NotificationStreamReplaced {
+ remote,
+ protocol,
+ notifications_sink,
+ }),
+ CustomMessageOutcome::NotificationStreamClosed { remote, protocol } =>
+ self.events.push_back(BehaviourOut::NotificationStreamClosed {
+ remote,
+ protocol,
+ }),
CustomMessageOutcome::NotificationsReceived { remote, messages } => {
self.events.push_back(BehaviourOut::NotificationsReceived { remote, messages });
},
CustomMessageOutcome::PeerNewBest(peer_id, number) => {
self.light_client_handler.update_best_block(&peer_id, number);
}
+ CustomMessageOutcome::SyncConnected(peer_id) =>
+ self.events.push_back(BehaviourOut::SyncConnected(peer_id)),
+ CustomMessageOutcome::SyncDisconnected(peer_id) =>
+ self.events.push_back(BehaviourOut::SyncDisconnected(peer_id)),
CustomMessageOutcome::None => {}
}
}
@@ -399,47 +364,11 @@ impl NetworkBehaviourEventProcess {
+ request_responses::Event::RequestFinished { peer, protocol, duration, result } => {
self.events.push_back(BehaviourOut::RequestFinished {
- request_id,
- result,
- });
- },
- }
- }
-}
-
-impl NetworkBehaviourEventProcess> for Behaviour {
- fn inject_event(&mut self, event: block_requests::Event) {
- match event {
- block_requests::Event::AnsweredRequest { peer, total_handling_time } => {
- self.events.push_back(BehaviourOut::InboundRequest {
- peer,
- protocol: self.block_requests.protocol_name().to_owned().into(),
- result: Ok(total_handling_time),
+ peer, protocol, duration, result,
});
},
- block_requests::Event::Response { peer, response, request_duration } => {
- self.events.push_back(BehaviourOut::OpaqueRequestFinished {
- peer: peer.clone(),
- protocol: self.block_requests.protocol_name().to_owned(),
- request_duration,
- });
- let ev = self.substrate.on_block_response(peer, response);
- self.inject_event(ev);
- }
- block_requests::Event::RequestCancelled { peer, request_duration, .. } |
- block_requests::Event::RequestTimeout { peer, request_duration, .. } => {
- // There doesn't exist any mechanism to report cancellations or timeouts yet, so
- // we process them by disconnecting the node.
- self.events.push_back(BehaviourOut::OpaqueRequestFinished {
- peer: peer.clone(),
- protocol: self.block_requests.protocol_name().to_owned(),
- request_duration,
- });
- self.substrate.on_block_request_failed(&peer);
- }
}
}
}
@@ -470,7 +399,7 @@ impl NetworkBehaviourEventProcess NetworkBehaviourEventProcess
// implementation for `PeerInfoEvent`.
}
DiscoveryOut::Discovered(peer_id) => {
- self.substrate.add_discovered_nodes(iter::once(peer_id));
+ self.substrate.add_default_set_discovered_nodes(iter::once(peer_id));
}
DiscoveryOut::ValueFound(results, duration) => {
self.events.push_back(BehaviourOut::Dht(DhtEvent::ValueFound(results), duration));
diff --git a/client/network/src/block_request_handler.rs b/client/network/src/block_request_handler.rs
new file mode 100644
index 0000000000000000000000000000000000000000..c88be52ecf0de503a42f332499eaf8d465468de0
--- /dev/null
+++ b/client/network/src/block_request_handler.rs
@@ -0,0 +1,220 @@
+// Copyright 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 .
+
+//! Helper for handling (i.e. answering) block requests from a remote peer via the
+//! [`crate::request_responses::RequestResponsesBehaviour`].
+
+use codec::{Encode, Decode};
+use crate::chain::Client;
+use crate::config::ProtocolId;
+use crate::protocol::{message::BlockAttributes};
+use crate::request_responses::{IncomingRequest, ProtocolConfig};
+use crate::schema::v1::block_request::FromBlock;
+use crate::schema::v1::{BlockResponse, Direction};
+use futures::channel::{mpsc, oneshot};
+use futures::stream::StreamExt;
+use log::debug;
+use prost::Message;
+use sp_runtime::generic::BlockId;
+use sp_runtime::traits::{Block as BlockT, Header, One, Zero};
+use std::cmp::min;
+use std::sync::{Arc};
+use std::time::Duration;
+
+const LOG_TARGET: &str = "block-request-handler";
+const MAX_BLOCKS_IN_RESPONSE: usize = 128;
+const MAX_BODY_BYTES: usize = 8 * 1024 * 1024;
+
+/// Generates a [`ProtocolConfig`] for the block request protocol, refusing incoming requests.
+pub fn generate_protocol_config(protocol_id: ProtocolId) -> ProtocolConfig {
+ ProtocolConfig {
+ name: generate_protocol_name(protocol_id).into(),
+ max_request_size: 1024 * 1024,
+ max_response_size: 16 * 1024 * 1024,
+ request_timeout: Duration::from_secs(40),
+ inbound_queue: None,
+ }
+}
+
+/// Generate the block protocol name from chain specific protocol identifier.
+fn generate_protocol_name(protocol_id: ProtocolId) -> String {
+ let mut s = String::new();
+ s.push_str("/");
+ s.push_str(protocol_id.as_ref());
+ s.push_str("/sync/2");
+ s
+}
+
+/// Handler for incoming block requests from a remote peer.
+pub struct BlockRequestHandler {
+ client: Arc>,
+ request_receiver: mpsc::Receiver,
+}
+
+impl BlockRequestHandler {
+ /// Create a new [`BlockRequestHandler`].
+ pub fn new(protocol_id: ProtocolId, client: Arc>) -> (Self, ProtocolConfig) {
+ // Rate of arrival multiplied with the waiting time in the queue equals the queue length.
+ //
+ // An average Polkadot sentry node serves less than 5 requests per second. The 95th percentile
+ // serving a request is less than 2 second. Thus one would estimate the queue length to be
+ // below 10.
+ //
+ // Choosing 20 as the queue length to give some additional buffer.
+ let (tx, request_receiver) = mpsc::channel(20);
+
+ let mut protocol_config = generate_protocol_config(protocol_id);
+ protocol_config.inbound_queue = Some(tx);
+
+ (Self { client, request_receiver }, protocol_config)
+ }
+
+ fn handle_request(
+ &self,
+ payload: Vec,
+ pending_response: oneshot::Sender>
+ ) -> Result<(), HandleRequestError> {
+ let request = crate::schema::v1::BlockRequest::decode(&payload[..])?;
+
+ let from_block_id = match request.from_block.ok_or(HandleRequestError::MissingFromField)? {
+ FromBlock::Hash(ref h) => {
+ let h = Decode::decode(&mut h.as_ref())?;
+ BlockId::::Hash(h)
+ }
+ FromBlock::Number(ref n) => {
+ let n = Decode::decode(&mut n.as_ref())?;
+ BlockId::::Number(n)
+ }
+ };
+
+ let max_blocks = if request.max_blocks == 0 {
+ MAX_BLOCKS_IN_RESPONSE
+ } else {
+ min(request.max_blocks as usize, MAX_BLOCKS_IN_RESPONSE)
+ };
+
+ let direction = Direction::from_i32(request.direction)
+ .ok_or(HandleRequestError::ParseDirection)?;
+ let attributes = BlockAttributes::from_be_u32(request.fields)?;
+ let get_header = attributes.contains(BlockAttributes::HEADER);
+ let get_body = attributes.contains(BlockAttributes::BODY);
+ let get_justification = attributes.contains(BlockAttributes::JUSTIFICATION);
+
+ let mut blocks = Vec::new();
+ let mut block_id = from_block_id;
+
+ let mut total_size: usize = 0;
+ while let Some(header) = self.client.header(block_id).unwrap_or(None) {
+ let number = *header.number();
+ let hash = header.hash();
+ let parent_hash = *header.parent_hash();
+ let justification = if get_justification {
+ self.client.justification(&BlockId::Hash(hash))?
+ } else {
+ None
+ };
+ let is_empty_justification = justification.as_ref().map(|j| j.is_empty()).unwrap_or(false);
+
+ let body = if get_body {
+ match self.client.block_body(&BlockId::Hash(hash))? {
+ Some(mut extrinsics) => extrinsics.iter_mut()
+ .map(|extrinsic| extrinsic.encode())
+ .collect(),
+ None => {
+ log::trace!(target: "sync", "Missing data for block request.");
+ break;
+ }
+ }
+ } else {
+ Vec::new()
+ };
+
+ let block_data = crate::schema::v1::BlockData {
+ hash: hash.encode(),
+ header: if get_header {
+ header.encode()
+ } else {
+ Vec::new()
+ },
+ body,
+ receipt: Vec::new(),
+ message_queue: Vec::new(),
+ justification: justification.unwrap_or_default(),
+ is_empty_justification,
+ };
+
+ total_size += block_data.body.len();
+ blocks.push(block_data);
+
+ if blocks.len() >= max_blocks as usize || total_size > MAX_BODY_BYTES {
+ break
+ }
+
+ match direction {
+ Direction::Ascending => {
+ block_id = BlockId::Number(number + One::one())
+ }
+ Direction::Descending => {
+ if number.is_zero() {
+ break
+ }
+ block_id = BlockId::Hash(parent_hash)
+ }
+ }
+ }
+
+ let res = BlockResponse { blocks };
+
+ let mut data = Vec::with_capacity(res.encoded_len());
+ res.encode(&mut data)?;
+
+ pending_response.send(data)
+ .map_err(|_| HandleRequestError::SendResponse)
+ }
+
+ /// Run [`BlockRequestHandler`].
+ pub async fn run(mut self) {
+ while let Some(request) = self.request_receiver.next().await {
+ let IncomingRequest { peer, payload, pending_response } = request;
+
+ match self.handle_request(payload, pending_response) {
+ Ok(()) => debug!(target: LOG_TARGET, "Handled block request from {}.", peer),
+ Err(e) => debug!(
+ target: LOG_TARGET,
+ "Failed to handle block request from {}: {}",
+ peer, e,
+ ),
+ }
+ }
+ }
+}
+
+#[derive(derive_more::Display, derive_more::From)]
+enum HandleRequestError {
+ #[display(fmt = "Failed to decode request: {}.", _0)]
+ DecodeProto(prost::DecodeError),
+ #[display(fmt = "Failed to encode response: {}.", _0)]
+ EncodeProto(prost::EncodeError),
+ #[display(fmt = "Failed to decode block hash: {}.", _0)]
+ DecodeScale(codec::Error),
+ #[display(fmt = "Missing `BlockRequest::from_block` field.")]
+ MissingFromField,
+ #[display(fmt = "Failed to parse BlockRequest::direction.")]
+ ParseDirection,
+ Client(sp_blockchain::Error),
+ #[display(fmt = "Failed to send response.")]
+ SendResponse,
+}
diff --git a/client/network/src/block_requests.rs b/client/network/src/block_requests.rs
deleted file mode 100644
index ace63e6e1cdd4b223ef94392da4ee360b77bed63..0000000000000000000000000000000000000000
--- a/client/network/src/block_requests.rs
+++ /dev/null
@@ -1,857 +0,0 @@
-// Copyright 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 .
-
-//! `NetworkBehaviour` implementation which handles incoming block requests.
-//!
-//! Every request is coming in on a separate connection substream which gets
-//! closed after we have sent the response back. Incoming requests are encoded
-//! as protocol buffers (cf. `api.v1.proto`).
-
-#![allow(unused)]
-
-use bytes::Bytes;
-use codec::{Encode, Decode};
-use crate::{
- chain::Client,
- config::ProtocolId,
- protocol::{message::{self, BlockAttributes}},
- schema,
-};
-use futures::{future::BoxFuture, prelude::*, stream::FuturesUnordered};
-use futures_timer::Delay;
-use libp2p::{
- core::{
- ConnectedPoint,
- Multiaddr,
- PeerId,
- connection::ConnectionId,
- upgrade::{InboundUpgrade, OutboundUpgrade, ReadOneError, UpgradeInfo, Negotiated},
- upgrade::{DeniedUpgrade, read_one, write_one}
- },
- swarm::{
- NegotiatedSubstream,
- NetworkBehaviour,
- NetworkBehaviourAction,
- NotifyHandler,
- OneShotHandler,
- OneShotHandlerConfig,
- PollParameters,
- SubstreamProtocol
- }
-};
-use prost::Message;
-use sp_runtime::{generic::BlockId, traits::{Block, Header, One, Zero}};
-use std::{
- cmp::min,
- collections::{HashMap, VecDeque},
- io,
- iter,
- marker::PhantomData,
- pin::Pin,
- sync::Arc,
- time::Duration,
- task::{Context, Poll}
-};
-use void::{Void, unreachable};
-use wasm_timer::Instant;
-
-// Type alias for convenience.
-pub type Error = Box;
-
-/// Event generated by the block requests behaviour.
-#[derive(Debug)]
-pub enum Event {
- /// A request came and we have successfully answered it.
- AnsweredRequest {
- /// Peer which has emitted the request.
- peer: PeerId,
- /// Time elapsed between when we received the request and when we sent back the response.
- total_handling_time: Duration,
- },
-
- /// A response to a block request has arrived.
- Response {
- peer: PeerId,
- response: message::BlockResponse,
- /// Time elapsed between the start of the request and the response.
- request_duration: Duration,
- },
-
- /// A request has been cancelled because the peer has disconnected.
- /// Disconnects can also happen as a result of violating the network protocol.
- ///
- /// > **Note**: This event is NOT emitted if a request is overridden by calling `send_request`.
- /// > For that, you must check the value returned by `send_request`.
- RequestCancelled {
- peer: PeerId,
- /// Time elapsed between the start of the request and the cancellation.
- request_duration: Duration,
- },
-
- /// A request has timed out.
- RequestTimeout {
- peer: PeerId,
- /// Time elapsed between the start of the request and the timeout.
- request_duration: Duration,
- }
-}
-
-/// Configuration options for `BlockRequests`.
-#[derive(Debug, Clone)]
-pub struct Config {
- max_block_data_response: u32,
- max_block_body_bytes: usize,
- max_request_len: usize,
- max_response_len: usize,
- inactivity_timeout: Duration,
- request_timeout: Duration,
- protocol: String,
-}
-
-impl Config {
- /// Create a fresh configuration with the following options:
- ///
- /// - max. block data in response = 128
- /// - max. request size = 1 MiB
- /// - max. response size = 16 MiB
- /// - inactivity timeout = 15s
- /// - request timeout = 40s
- pub fn new(id: &ProtocolId) -> Self {
- let mut c = Config {
- max_block_data_response: 128,
- max_block_body_bytes: 8 * 1024 * 1024,
- max_request_len: 1024 * 1024,
- max_response_len: 16 * 1024 * 1024,
- inactivity_timeout: Duration::from_secs(15),
- request_timeout: Duration::from_secs(40),
- protocol: String::new(),
- };
- c.set_protocol(id);
- c
- }
-
- /// Limit the max. number of block data in a response.
- pub fn set_max_block_data_response(&mut self, v: u32) -> &mut Self {
- self.max_block_data_response = v;
- self
- }
-
- /// Limit the max. length of incoming block request bytes.
- pub fn set_max_request_len(&mut self, v: usize) -> &mut Self {
- self.max_request_len = v;
- self
- }
-
- /// Limit the max. size of responses to our block requests.
- pub fn set_max_response_len(&mut self, v: usize) -> &mut Self {
- self.max_response_len = v;
- self
- }
-
- /// Limit the max. duration the substream may remain inactive before closing it.
- pub fn set_inactivity_timeout(&mut self, v: Duration) -> &mut Self {
- self.inactivity_timeout = v;
- self
- }
-
- /// Set the maximum total bytes of block bodies that are send in the response.
- /// Note that at least one block is always sent regardless of the limit.
- /// This should be lower than the value specified in `set_max_response_len`
- /// accounting for headers, justifications and encoding overhead.
- pub fn set_max_block_body_bytes(&mut self, v: usize) -> &mut Self {
- self.max_block_body_bytes = v;
- self
- }
-
- /// Set protocol to use for upgrade negotiation.
- pub fn set_protocol(&mut self, id: &ProtocolId) -> &mut Self {
- let mut s = String::new();
- s.push_str("/");
- s.push_str(id.as_ref());
- s.push_str("/sync/2");
- self.protocol = s;
- self
- }
-}
-
-/// The block request handling behaviour.
-pub struct BlockRequests {
- /// This behaviour's configuration.
- config: Config,
- /// Blockchain client.
- chain: Arc>,
- /// List of all active connections and the requests we've sent.
- peers: HashMap>>,
- /// Futures sending back the block request response. Returns the `PeerId` we sent back to, and
- /// the total time the handling of this request took.
- outgoing: FuturesUnordered>,
- /// Events to return as soon as possible from `poll`.
- pending_events: VecDeque, Event>>,
-}
-
-/// Local tracking of a libp2p connection.
-#[derive(Debug)]
-struct Connection {
- id: ConnectionId,
- ongoing_request: Option>,
-}
-
-#[derive(Debug)]
-struct OngoingRequest {
- /// `Instant` when the request has been emitted. Used for diagnostic purposes.
- emitted: Instant,
- request: message::BlockRequest,
- timeout: Delay,
-}
-
-/// Outcome of calling `send_request`.
-#[derive(Debug)]
-#[must_use]
-pub enum SendRequestOutcome {
- /// Request has been emitted.
- Ok,
- /// The request has been emitted and has replaced an existing request.
- Replaced {
- /// The previously-emitted request.
- previous: message::BlockRequest,
- /// Time that had elapsed since `previous` has been emitted.
- request_duration: Duration,
- },
- /// Didn't start a request because we have no connection to this node.
- /// If `send_request` returns that, it is as if the function had never been called.
- NotConnected,
- /// Error while serializing the request.
- EncodeError(prost::EncodeError),
-}
-
-impl BlockRequests
-where
- B: Block,
-{
- pub fn new(cfg: Config, chain: Arc>) -> Self {
- BlockRequests {
- config: cfg,
- chain,
- peers: HashMap::new(),
- outgoing: FuturesUnordered::new(),
- pending_events: VecDeque::new(),
- }
- }
-
- /// Returns the libp2p protocol name used on the wire (e.g. `/foo/sync/2`).
- pub fn protocol_name(&self) -> &str {
- &self.config.protocol
- }
-
- /// Issue a new block request.
- ///
- /// Cancels any existing request targeting the same `PeerId`.
- ///
- /// If the response doesn't arrive in time, or if the remote answers improperly, the target
- /// will be disconnected.
- pub fn send_request(&mut self, target: &PeerId, req: message::BlockRequest) -> SendRequestOutcome {
- // Determine which connection to send the request to.
- let connection = if let Some(peer) = self.peers.get_mut(target) {
- // We don't want to have multiple requests for any given node, so in priority try to
- // find a connection with an existing request, to override it.
- if let Some(entry) = peer.iter_mut().find(|c| c.ongoing_request.is_some()) {
- entry
- } else if let Some(entry) = peer.get_mut(0) {
- entry
- } else {
- log::error!(
- target: "sync",
- "State inconsistency: empty list of peer connections"
- );
- return SendRequestOutcome::NotConnected;
- }
- } else {
- return SendRequestOutcome::NotConnected;
- };
-
- let protobuf_rq = build_protobuf_block_request(
- req.fields,
- req.from.clone(),
- req.to.clone(),
- req.direction,
- req.max,
- );
-
- let mut buf = Vec::with_capacity(protobuf_rq.encoded_len());
- if let Err(err) = protobuf_rq.encode(&mut buf) {
- log::warn!(
- target: "sync",
- "Failed to encode block request {:?}: {:?}",
- protobuf_rq,
- err
- );
- return SendRequestOutcome::EncodeError(err);
- }
-
- let previous_request = connection.ongoing_request.take();
- connection.ongoing_request = Some(OngoingRequest {
- emitted: Instant::now(),
- request: req.clone(),
- timeout: Delay::new(self.config.request_timeout),
- });
-
- log::trace!(target: "sync", "Enqueueing block request to {:?}: {:?}", target, protobuf_rq);
- self.pending_events.push_back(NetworkBehaviourAction::NotifyHandler {
- peer_id: target.clone(),
- handler: NotifyHandler::One(connection.id),
- event: OutboundProtocol {
- request: buf,
- original_request: req,
- max_response_size: self.config.max_response_len,
- protocol: self.config.protocol.as_bytes().to_vec().into(),
- },
- });
-
- if let Some(previous_request) = previous_request {
- log::debug!(
- target: "sync",
- "Replacing existing block request on connection {:?}",
- connection.id
- );
- SendRequestOutcome::Replaced {
- previous: previous_request.request,
- request_duration: previous_request.emitted.elapsed(),
- }
- } else {
- SendRequestOutcome::Ok
- }
- }
-
- /// Callback, invoked when a new block request has been received from remote.
- fn on_block_request
- ( &mut self
- , peer: &PeerId
- , request: &schema::v1::BlockRequest
- ) -> Result
- {
- log::trace!(
- target: "sync",
- "Block request from peer {}: from block {:?} to block {:?}, max blocks {:?}",
- peer,
- request.from_block,
- request.to_block,
- request.max_blocks);
-
- let from_block_id =
- match request.from_block {
- Some(schema::v1::block_request::FromBlock::Hash(ref h)) => {
- let h = Decode::decode(&mut h.as_ref())?;
- BlockId::::Hash(h)
- }
- Some(schema::v1::block_request::FromBlock::Number(ref n)) => {
- let n = Decode::decode(&mut n.as_ref())?;
- BlockId::::Number(n)
- }
- None => {
- let msg = "missing `BlockRequest::from_block` field";
- return Err(io::Error::new(io::ErrorKind::Other, msg).into())
- }
- };
-
- let max_blocks =
- if request.max_blocks == 0 {
- self.config.max_block_data_response
- } else {
- min(request.max_blocks, self.config.max_block_data_response)
- };
-
- let direction =
- if request.direction == schema::v1::Direction::Ascending as i32 {
- schema::v1::Direction::Ascending
- } else if request.direction == schema::v1::Direction::Descending as i32 {
- schema::v1::Direction::Descending
- } else {
- let msg = format!("invalid `BlockRequest::direction` value: {}", request.direction);
- return Err(io::Error::new(io::ErrorKind::Other, msg).into())
- };
-
- let attributes = BlockAttributes::from_be_u32(request.fields)?;
- let get_header = attributes.contains(BlockAttributes::HEADER);
- let get_body = attributes.contains(BlockAttributes::BODY);
- let get_justification = attributes.contains(BlockAttributes::JUSTIFICATION);
-
- let mut blocks = Vec::new();
- let mut block_id = from_block_id;
- let mut total_size = 0;
- while let Some(header) = self.chain.header(block_id).unwrap_or(None) {
- if blocks.len() >= max_blocks as usize
- || (blocks.len() >= 1 && total_size > self.config.max_block_body_bytes)
- {
- break
- }
-
- let number = *header.number();
- let hash = header.hash();
- let parent_hash = *header.parent_hash();
- let justification = if get_justification {
- self.chain.justification(&BlockId::Hash(hash))?
- } else {
- None
- };
- let is_empty_justification = justification.as_ref().map(|j| j.is_empty()).unwrap_or(false);
-
- let body = if get_body {
- match self.chain.block_body(&BlockId::Hash(hash))? {
- Some(mut extrinsics) => extrinsics.iter_mut()
- .map(|extrinsic| extrinsic.encode())
- .collect(),
- None => {
- log::trace!(target: "sync", "Missing data for block request.");
- break;
- }
- }
- } else {
- Vec::new()
- };
-
- let block_data = schema::v1::BlockData {
- hash: hash.encode(),
- header: if get_header {
- header.encode()
- } else {
- Vec::new()
- },
- body,
- receipt: Vec::new(),
- message_queue: Vec::new(),
- justification: justification.unwrap_or_default(),
- is_empty_justification,
- };
-
- total_size += block_data.body.len();
- blocks.push(block_data);
-
- match direction {
- schema::v1::Direction::Ascending => {
- block_id = BlockId::Number(number + One::one())
- }
- schema::v1::Direction::Descending => {
- if number.is_zero() {
- break
- }
- block_id = BlockId::Hash(parent_hash)
- }
- }
- }
-
- Ok(schema::v1::BlockResponse { blocks })
- }
-}
-
-impl NetworkBehaviour for BlockRequests
-where
- B: Block
-{
- type ProtocolsHandler = OneShotHandler, OutboundProtocol, NodeEvent>;
- type OutEvent = Event;
-
- fn new_handler(&mut self) -> Self::ProtocolsHandler {
- let p = InboundProtocol {
- max_request_len: self.config.max_request_len,
- protocol: self.config.protocol.as_bytes().to_owned().into(),
- marker: PhantomData,
- };
- let mut cfg = OneShotHandlerConfig::default();
- cfg.keep_alive_timeout = self.config.inactivity_timeout;
- cfg.outbound_substream_timeout = self.config.request_timeout;
- OneShotHandler::new(SubstreamProtocol::new(p, ()), cfg)
- }
-
- fn addresses_of_peer(&mut self, _: &PeerId) -> Vec {
- Vec::new()
- }
-
- fn inject_connected(&mut self, _peer: &PeerId) {
- }
-
- fn inject_disconnected(&mut self, _peer: &PeerId) {
- }
-
- fn inject_connection_established(&mut self, peer_id: &PeerId, id: &ConnectionId, _: &ConnectedPoint) {
- self.peers.entry(peer_id.clone())
- .or_default()
- .push(Connection {
- id: *id,
- ongoing_request: None,
- });
- }
-
- fn inject_connection_closed(&mut self, peer_id: &PeerId, id: &ConnectionId, _: &ConnectedPoint) {
- let mut needs_remove = false;
- if let Some(entry) = self.peers.get_mut(peer_id) {
- if let Some(pos) = entry.iter().position(|i| i.id == *id) {
- let ongoing_request = entry.remove(pos).ongoing_request;
- if let Some(ongoing_request) = ongoing_request {
- log::debug!(
- target: "sync",
- "Connection {:?} with {} closed with ongoing sync request: {:?}",
- id,
- peer_id,
- ongoing_request
- );
- let ev = Event::RequestCancelled {
- peer: peer_id.clone(),
- request_duration: ongoing_request.emitted.elapsed(),
- };
- self.pending_events.push_back(NetworkBehaviourAction::GenerateEvent(ev));
- }
- if entry.is_empty() {
- needs_remove = true;
- }
- } else {
- log::error!(
- target: "sync",
- "State inconsistency: connection id not found in list"
- );
- }
- } else {
- log::error!(
- target: "sync",
- "State inconsistency: peer_id not found in list of connections"
- );
- }
- if needs_remove {
- self.peers.remove(peer_id);
- }
- }
-
- fn inject_event(
- &mut self,
- peer: PeerId,
- connection_id: ConnectionId,
- node_event: NodeEvent
- ) {
- match node_event {
- NodeEvent::Request(request, mut stream, handling_start) => {
- match self.on_block_request(&peer, &request) {
- Ok(res) => {
- log::trace!(
- target: "sync",
- "Enqueueing block response for peer {} with {} blocks",
- peer, res.blocks.len()
- );
- let mut data = Vec::with_capacity(res.encoded_len());
- if let Err(e) = res.encode(&mut data) {
- log::debug!(
- target: "sync",
- "Error encoding block response for peer {}: {}",
- peer, e
- )
- } else {
- self.outgoing.push(async move {
- if let Err(e) = write_one(&mut stream, data).await {
- log::debug!(
- target: "sync",
- "Error writing block response: {}",
- e
- );
- }
- (peer, handling_start.elapsed())
- }.boxed());
- }
- }
- Err(e) => log::debug!(
- target: "sync",
- "Error handling block request from peer {}: {}", peer, e
- )
- }
- }
- NodeEvent::Response(original_request, response) => {
- log::trace!(
- target: "sync",
- "Received block response from peer {} with {} blocks",
- peer, response.blocks.len()
- );
- let request_duration = if let Some(connections) = self.peers.get_mut(&peer) {
- if let Some(connection) = connections.iter_mut().find(|c| c.id == connection_id) {
- if let Some(ongoing_request) = &mut connection.ongoing_request {
- if ongoing_request.request == original_request {
- let request_duration = ongoing_request.emitted.elapsed();
- connection.ongoing_request = None;
- request_duration
- } else {
- // We're no longer interested in that request.
- log::debug!(
- target: "sync",
- "Received response from {} to obsolete block request {:?}",
- peer,
- original_request
- );
- return;
- }
- } else {
- // We remove from `self.peers` requests we're no longer interested in,
- // so this can legitimately happen.
- log::trace!(
- target: "sync",
- "Response discarded because it concerns an obsolete request"
- );
- return;
- }
- } else {
- log::error!(
- target: "sync",
- "State inconsistency: response on non-existing connection {:?}",
- connection_id
- );
- return;
- }
- } else {
- log::error!(
- target: "sync",
- "State inconsistency: response on non-connected peer {}",
- peer
- );
- return;
- };
-
- let blocks = response.blocks.into_iter().map(|block_data| {
- Ok(message::BlockData:: {
- hash: Decode::decode(&mut block_data.hash.as_ref())?,
- header: if !block_data.header.is_empty() {
- Some(Decode::decode(&mut block_data.header.as_ref())?)
- } else {
- None
- },
- body: if original_request.fields.contains(message::BlockAttributes::BODY) {
- Some(block_data.body.iter().map(|body| {
- Decode::decode(&mut body.as_ref())
- }).collect::, _>>()?)
- } else {
- None
- },
- receipt: if !block_data.message_queue.is_empty() {
- Some(block_data.receipt)
- } else {
- None
- },
- message_queue: if !block_data.message_queue.is_empty() {
- Some(block_data.message_queue)
- } else {
- None
- },
- justification: if !block_data.justification.is_empty() {
- Some(block_data.justification)
- } else if block_data.is_empty_justification {
- Some(Vec::new())
- } else {
- None
- },
- })
- }).collect::, codec::Error>>();
-
- match blocks {
- Ok(blocks) => {
- let id = original_request.id;
- let ev = Event::Response {
- peer,
- response: message::BlockResponse:: { id, blocks },
- request_duration,
- };
- self.pending_events.push_back(NetworkBehaviourAction::GenerateEvent(ev));
- }
- Err(err) => {
- log::debug!(
- target: "sync",
- "Failed to decode block response from peer {}: {}", peer, err
- );
- }
- }
- }
- }
- }
-
- fn poll(&mut self, cx: &mut Context, _: &mut impl PollParameters)
- -> Poll, Event>>
- {
- if let Some(ev) = self.pending_events.pop_front() {
- return Poll::Ready(ev);
- }
-
- // Check the request timeouts.
- for (peer, connections) in &mut self.peers {
- for connection in connections {
- let ongoing_request = match &mut connection.ongoing_request {
- Some(rq) => rq,
- None => continue,
- };
-
- if let Poll::Ready(_) = Pin::new(&mut ongoing_request.timeout).poll(cx) {
- let original_request = ongoing_request.request.clone();
- let request_duration = ongoing_request.emitted.elapsed();
- connection.ongoing_request = None;
- log::debug!(
- target: "sync",
- "Request timeout for {}: {:?}",
- peer, original_request
- );
- let ev = Event::RequestTimeout {
- peer: peer.clone(),
- request_duration,
- };
- return Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev));
- }
- }
- }
-
- if let Poll::Ready(Some((peer, total_handling_time))) = self.outgoing.poll_next_unpin(cx) {
- let ev = Event::AnsweredRequest {
- peer,
- total_handling_time,
- };
- return Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev));
- }
-
- Poll::Pending
- }
-}
-
-/// Output type of inbound and outbound substream upgrades.
-#[derive(Debug)]
-pub enum NodeEvent {
- /// Incoming request from remote, substream to use for the response, and when we started
- /// handling this request.
- Request(schema::v1::BlockRequest, T, Instant),
- /// Incoming response from remote.
- Response(message::BlockRequest, schema::v1::BlockResponse),
-}
-
-/// Substream upgrade protocol.
-///
-/// We attempt to parse an incoming protobuf encoded request (cf. `Request`)
-/// which will be handled by the `BlockRequests` behaviour, i.e. the request
-/// will become visible via `inject_node_event` which then dispatches to the
-/// relevant callback to process the message and prepare a response.
-#[derive(Debug, Clone)]
-pub struct InboundProtocol {
- /// The max. request length in bytes.
- max_request_len: usize,
- /// The protocol to use during upgrade negotiation.
- protocol: Bytes,
- /// Type of the block.
- marker: PhantomData,
-}
-
-impl UpgradeInfo for InboundProtocol {
- type Info = Bytes;
- type InfoIter = iter::Once;
-
- fn protocol_info(&self) -> Self::InfoIter {
- iter::once(self.protocol.clone())
- }
-}
-
-impl InboundUpgrade for InboundProtocol
-where
- B: Block,
- T: AsyncRead + AsyncWrite + Unpin + Send + 'static
-{
- type Output = NodeEvent;
- type Error = ReadOneError;
- type Future = BoxFuture<'static, Result>;
-
- fn upgrade_inbound(self, mut s: T, _: Self::Info) -> Self::Future {
- // This `Instant` will be passed around until the processing of this request is done.
- let handling_start = Instant::now();
-
- let future = async move {
- let len = self.max_request_len;
- let vec = read_one(&mut s, len).await?;
- match schema::v1::BlockRequest::decode(&vec[..]) {
- Ok(r) => Ok(NodeEvent::Request(r, s, handling_start)),
- Err(e) => Err(ReadOneError::Io(io::Error::new(io::ErrorKind::Other, e)))
- }
- };
- future.boxed()
- }
-}
-
-/// Substream upgrade protocol.
-///
-/// Sends a request to remote and awaits the response.
-#[derive(Debug, Clone)]
-pub struct OutboundProtocol {
- /// The serialized protobuf request.
- request: Vec,
- /// The original request. Passed back through the API when the response comes back.
- original_request: message::BlockRequest,
- /// The max. response length in bytes.
- max_response_size: usize,
- /// The protocol to use for upgrade negotiation.
- protocol: Bytes,
-}
-
-impl UpgradeInfo for OutboundProtocol {
- type Info = Bytes;
- type InfoIter = iter::Once;
-
- fn protocol_info(&self) -> Self::InfoIter {
- iter::once(self.protocol.clone())
- }
-}
-
-impl OutboundUpgrade for OutboundProtocol
-where
- B: Block,
- T: AsyncRead + AsyncWrite + Unpin + Send + 'static
-{
- type Output = NodeEvent;
- type Error = ReadOneError;
- type Future = BoxFuture<'static, Result