Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into ao-subsystem-do-not-use-ourviewchange
Browse files Browse the repository at this point in the history
* master:
  cargo +nightly fmt (#3540)
  • Loading branch information
ordian committed Aug 2, 2021
2 parents 4093836 + c4ee9d4 commit c59f302
Show file tree
Hide file tree
Showing 350 changed files with 20,714 additions and 21,356 deletions.
10 changes: 9 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ check-line-width:
- ./scripts/gitlab/check_line_width.sh
allow_failure: true

cargo-fmt:
stage: test
<<: *kubernetes-env
<<: *rules-pr-only
script:
- cargo +nightly fmt --all -- --check
allow_failure: true

test-deterministic-wasm:
stage: test
<<: *rules-test
Expand Down Expand Up @@ -172,7 +180,7 @@ spellcheck:
- cargo spellcheck --version
# compare with the commit parent to the PR, given it's from a default branch
- git fetch origin +${CI_DEFAULT_BRANCH}:${CI_DEFAULT_BRANCH}
- time cargo spellcheck check -vvv --cfg=scripts/gitlab/spellcheck.toml --checkers hunspell --code 1
- time cargo spellcheck check -vvv --cfg=scripts/gitlab/spellcheck.toml --checkers hunspell --code 1
-r $(git diff --name-only ${CI_COMMIT_SHA} $(git merge-base ${CI_COMMIT_SHA} ${CI_DEFAULT_BRANCH}))
allow_failure: true

Expand Down
7 changes: 5 additions & 2 deletions bridges/modules/dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ mod tests {
#![allow(clippy::from_over_into)]

use super::*;
use frame_support::{parameter_types, weights::Weight, dispatch::GetDispatchInfo};
use frame_support::{dispatch::GetDispatchInfo, parameter_types, weights::Weight};
use frame_system::{EventRecord, Phase};
use sp_core::H256;
use sp_runtime::{
Expand Down Expand Up @@ -603,7 +603,10 @@ mod tests {
let call_weight = call.get_dispatch_info().weight;
let mut message = prepare_root_message(call);
message.weight = 7;
assert!(call_weight != 7, "needed for test to actually trigger a weight mismatch");
assert!(
call_weight != 7,
"needed for test to actually trigger a weight mismatch"
);

System::set_block_number(1);
let result = Dispatch::dispatch(SOURCE_CHAIN_ID, TARGET_CHAIN_ID, id, Ok(message), |_, _| unreachable!());
Expand Down
12 changes: 8 additions & 4 deletions cli/src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ pub fn start_client(chain_spec: String, log_level: String) -> Result<Client, JsV
start_inner(chain_spec, log_level).map_err(|err| JsValue::from_str(&err.to_string()))
}

fn start_inner(chain_spec: String, log_directives: String) -> Result<Client, Box<dyn std::error::Error>> {
fn start_inner(
chain_spec: String,
log_directives: String,
) -> Result<Client, Box<dyn std::error::Error>> {
set_console_error_panic_hook();
init_logging(&log_directives)?;

let chain_spec =
service::PolkadotChainSpec::from_json_bytes(chain_spec.as_bytes().to_vec()).map_err(|e| format!("{:?}", e))?;
let chain_spec = service::PolkadotChainSpec::from_json_bytes(chain_spec.as_bytes().to_vec())
.map_err(|e| format!("{:?}", e))?;
let config = browser_configuration(chain_spec)?;

info!("Polkadot browser node");
Expand All @@ -40,7 +43,8 @@ fn start_inner(chain_spec: String, log_directives: String) -> Result<Client, Box
info!("👤 Role: {}", config.display_role());

// Create the service. This is the most heavy initialization step.
let (task_manager, rpc_handlers) = service::build_light(config).map_err(|e| format!("{:?}", e))?;
let (task_manager, rpc_handlers) =
service::build_light(config).map_err(|e| format!("{:?}", e))?;

Ok(browser_utils::start_client(task_manager, rpc_handlers))
}
5 changes: 1 addition & 4 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ pub enum Subcommand {
PvfExecuteWorker(ValidationWorkerCommand),

/// The custom benchmark subcommand benchmarking runtime pallets.
#[structopt(
name = "benchmark",
about = "Benchmark runtime pallets."
)]
#[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),

/// Try some command against runtime state.
Expand Down
138 changes: 85 additions & 53 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use log::info;
use service::{IdentifyVariant, self};
use sc_cli::{SubstrateCli, RuntimeVersion, Role};
use crate::cli::{Cli, Subcommand};
use futures::future::TryFutureExt;
use log::info;
use sc_cli::{Role, RuntimeVersion, SubstrateCli};
use service::{self, IdentifyVariant};

#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand Down Expand Up @@ -51,28 +51,45 @@ fn get_exec_name() -> Option<String> {
}

impl SubstrateCli for Cli {
fn impl_name() -> String { "Parity Polkadot".into() }
fn impl_name() -> String {
"Parity Polkadot".into()
}

fn impl_version() -> String { env!("SUBSTRATE_CLI_IMPL_VERSION").into() }
fn impl_version() -> String {
env!("SUBSTRATE_CLI_IMPL_VERSION").into()
}

fn description() -> String { env!("CARGO_PKG_DESCRIPTION").into() }
fn description() -> String {
env!("CARGO_PKG_DESCRIPTION").into()
}

fn author() -> String { env!("CARGO_PKG_AUTHORS").into() }
fn author() -> String {
env!("CARGO_PKG_AUTHORS").into()
}

fn support_url() -> String { "https://github.com/paritytech/polkadot/issues/new".into() }
fn support_url() -> String {
"https://github.com/paritytech/polkadot/issues/new".into()
}

fn copyright_start_year() -> i32 { 2017 }
fn copyright_start_year() -> i32 {
2017
}

fn executable_name() -> String { "polkadot".into() }
fn executable_name() -> String {
"polkadot".into()
}

fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
let id = if id == "" {
let n = get_exec_name().unwrap_or_default();
["polkadot", "kusama", "westend", "rococo"].iter()
["polkadot", "kusama", "westend", "rococo"]
.iter()
.cloned()
.find(|&chain| n.starts_with(chain))
.unwrap_or("polkadot")
} else { id };
} else {
id
};
Ok(match id {
"kusama" => Box::new(service::chain_spec::kusama_config()?),
#[cfg(feature = "kusama-native")]
Expand Down Expand Up @@ -119,7 +136,8 @@ impl SubstrateCli for Cli {
path => {
let path = std::path::PathBuf::from(path);

let chain_spec = Box::new(service::PolkadotChainSpec::from_json_file(path.clone())?) as Box<dyn service::ChainSpec>;
let chain_spec = Box::new(service::PolkadotChainSpec::from_json_file(path.clone())?)
as Box<dyn service::ChainSpec>;

// When `force_*` is given or the file name starts with the name of one of the known chains,
// we use the chain spec for the specific chain.
Expand Down Expand Up @@ -152,7 +170,11 @@ impl SubstrateCli for Cli {
return &service::rococo_runtime::VERSION
}

#[cfg(not(all(feature = "rococo-native", feature = "westend-native", feature = "kusama-native")))]
#[cfg(not(all(
feature = "rococo-native",
feature = "westend-native",
feature = "kusama-native"
)))]
let _ = spec;

&service::polkadot_runtime::VERSION
Expand Down Expand Up @@ -193,8 +215,7 @@ pub fn run_node(cli: Cli, overseer_gen: impl service::OverseerGen) -> Result<()>
}

fn run_node_inner(cli: Cli, overseer_gen: impl service::OverseerGen) -> Result<()> {
let runner = cli.create_runner(&cli.run.base)
.map_err(Error::from)?;
let runner = cli.create_runner(&cli.run.base).map_err(Error::from)?;
let chain_spec = &runner.config().chain_spec;

set_default_ss58_version(chain_spec);
Expand All @@ -220,7 +241,9 @@ fn run_node_inner(cli: Cli, overseer_gen: impl service::OverseerGen) -> Result<(

match role {
#[cfg(feature = "browser")]
Role::Light => service::build_light(config).map(|(task_manager, _)| task_manager).map_err(Into::into),
Role::Light => service::build_light(config)
.map(|(task_manager, _)| task_manager)
.map_err(Into::into),
#[cfg(not(feature = "browser"))]
Role::Light => Err(Error::Other("Light client not enabled".into())),
_ => service::build_full(
Expand All @@ -231,7 +254,9 @@ fn run_node_inner(cli: Cli, overseer_gen: impl service::OverseerGen) -> Result<(
jaeger_agent,
None,
overseer_gen,
).map(|full| full.task_manager).map_err(Into::into)
)
.map(|full| full.task_manager)
.map_err(Into::into),
}
})
}
Expand All @@ -244,19 +269,17 @@ pub fn run() -> Result<()> {
None => run_node_inner(cli, service::RealOverseerGen),
Some(Subcommand::BuildSpec(cmd)) => {
let runner = cli.create_runner(cmd)?;
Ok(runner.sync_run(|config| {
cmd.run(config.chain_spec, config.network)
})?)
Ok(runner.sync_run(|config| cmd.run(config.chain_spec, config.network))?)
},
Some(Subcommand::CheckBlock(cmd)) => {
let runner = cli.create_runner(cmd)
.map_err(Error::SubstrateCli)?;
let runner = cli.create_runner(cmd).map_err(Error::SubstrateCli)?;
let chain_spec = &runner.config().chain_spec;

set_default_ss58_version(chain_spec);

runner.async_run(|mut config| {
let (client, _, import_queue, task_manager) = service::new_chain_ops(&mut config, None)?;
let (client, _, import_queue, task_manager) =
service::new_chain_ops(&mut config, None)?;
Ok((cmd.run(client, import_queue).map_err(Error::SubstrateCli), task_manager))
})
},
Expand All @@ -267,8 +290,8 @@ pub fn run() -> Result<()> {
set_default_ss58_version(chain_spec);

Ok(runner.async_run(|mut config| {
let (client, _, _, task_manager) = service::new_chain_ops(&mut config, None)
.map_err(Error::PolkadotService)?;
let (client, _, _, task_manager) =
service::new_chain_ops(&mut config, None).map_err(Error::PolkadotService)?;
Ok((cmd.run(client, config.database).map_err(Error::SubstrateCli), task_manager))
})?)
},
Expand All @@ -290,7 +313,8 @@ pub fn run() -> Result<()> {
set_default_ss58_version(chain_spec);

Ok(runner.async_run(|mut config| {
let (client, _, import_queue, task_manager) = service::new_chain_ops(&mut config, None)?;
let (client, _, import_queue, task_manager) =
service::new_chain_ops(&mut config, None)?;
Ok((cmd.run(client, import_queue).map_err(Error::SubstrateCli), task_manager))
})?)
},
Expand All @@ -316,9 +340,10 @@ pub fn run() -> Result<()> {

#[cfg(any(target_os = "android", feature = "browser"))]
{
return Err(
sc_cli::Error::Input("PVF preparation workers are not supported under this platform".into()).into()
);
return Err(sc_cli::Error::Input(
"PVF preparation workers are not supported under this platform".into(),
)
.into())
}

#[cfg(not(any(target_os = "android", feature = "browser")))]
Expand All @@ -334,9 +359,10 @@ pub fn run() -> Result<()> {

#[cfg(any(target_os = "android", feature = "browser"))]
{
return Err(
sc_cli::Error::Input("PVF execution workers are not supported under this platform".into()).into()
);
return Err(sc_cli::Error::Input(
"PVF execution workers are not supported under this platform".into(),
)
.into())
}

#[cfg(not(any(target_os = "android", feature = "browser")))]
Expand Down Expand Up @@ -383,45 +409,51 @@ pub fn run() -> Result<()> {

use sc_service::TaskManager;
let registry = &runner.config().prometheus_config.as_ref().map(|cfg| &cfg.registry);
let task_manager = TaskManager::new(
runner.config().task_executor.clone(),
*registry,
).map_err(|e| Error::SubstrateService(sc_service::Error::Prometheus(e)))?;
let task_manager =
TaskManager::new(runner.config().task_executor.clone(), *registry)
.map_err(|e| Error::SubstrateService(sc_service::Error::Prometheus(e)))?;

ensure_dev(chain_spec).map_err(Error::Other)?;

#[cfg(feature = "kusama-native")]
if chain_spec.is_kusama() {
return runner.async_run(|config| {
Ok((cmd.run::<
service::kusama_runtime::Block,
service::KusamaExecutor,
>(config).map_err(Error::SubstrateCli), task_manager))
Ok((
cmd.run::<service::kusama_runtime::Block, service::KusamaExecutor>(config)
.map_err(Error::SubstrateCli),
task_manager,
))
})
}

#[cfg(feature = "westend-native")]
if chain_spec.is_westend() {
return runner.async_run(|config| {
Ok((cmd.run::<
service::westend_runtime::Block,
service::WestendExecutor,
>(config).map_err(Error::SubstrateCli), task_manager))
Ok((
cmd.run::<service::westend_runtime::Block, service::WestendExecutor>(
config,
)
.map_err(Error::SubstrateCli),
task_manager,
))
})
}
// else we assume it is polkadot.
runner.async_run(|config| {
Ok((cmd.run::<
service::polkadot_runtime::Block,
service::PolkadotExecutor,
>(config).map_err(Error::SubstrateCli), task_manager))
Ok((
cmd.run::<service::polkadot_runtime::Block, service::PolkadotExecutor>(config)
.map_err(Error::SubstrateCli),
task_manager,
))
})
},
#[cfg(not(feature = "try-runtime"))]
Some(Subcommand::TryRuntime) => {
Err(Error::Other("TryRuntime wasn't enabled when building the node. \
You can enable it with `--features try-runtime`.".into()).into())
},
Some(Subcommand::TryRuntime) => Err(Error::Other(
"TryRuntime wasn't enabled when building the node. \
You can enable it with `--features try-runtime`."
.into(),
)
.into()),
}?;
Ok(())
}
4 changes: 1 addition & 3 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ mod cli;
mod command;

pub use service::{
self,
ProvideRuntimeApi, CoreApi, IdentifyVariant,
Block, RuntimeApiCollection, TFullClient,
self, Block, CoreApi, IdentifyVariant, ProvideRuntimeApi, RuntimeApiCollection, TFullClient,
};

#[cfg(feature = "malus")]
Expand Down
10 changes: 7 additions & 3 deletions core-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@
//!
//! These core Polkadot types are used by the relay chain and the Parachains.
use sp_runtime::{generic, MultiSignature, traits::{Verify, IdentifyAccount}};
use parity_scale_codec::{Encode, Decode};
use parity_scale_codec::{Decode, Encode};
#[cfg(feature = "std")]
use parity_util_mem::MallocSizeOf;
use sp_runtime::{
generic,
traits::{IdentifyAccount, Verify},
MultiSignature,
};

pub use sp_runtime::traits::{BlakeTwo256, Hash as HashT};

Expand Down Expand Up @@ -64,7 +68,7 @@ pub type Hash = sp_core::H256;
#[cfg_attr(feature = "std", derive(MallocSizeOf))]
pub struct CandidateHash(pub Hash);

#[cfg(feature="std")]
#[cfg(feature = "std")]
impl std::fmt::Display for CandidateHash {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
Expand Down
Loading

0 comments on commit c59f302

Please sign in to comment.