diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index edef13620c..9428631be3 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -37,7 +37,8 @@ impl Extensions { type AccountPublic = ::Signer; /// Helper function to generate an account ID from seed -pub fn get_account_id_from_seed(seed: &str) -> AccountId where +pub fn get_account_id_from_seed(seed: &str) -> AccountId +where AccountPublic: From<::Public>, { AccountPublic::from(get_from_seed::(seed)).into_account() @@ -51,10 +52,7 @@ pub fn get_chain_spec(id: ParaId) -> ChainSpec { move || { testnet_genesis( get_account_id_from_seed::("Alice"), - vec![ - get_from_seed::("Alice"), - get_from_seed::("Bob"), - ], + vec![get_from_seed::("Alice"), get_from_seed::("Bob")], vec![ get_account_id_from_seed::("Alice"), get_account_id_from_seed::("Bob"), @@ -76,10 +74,7 @@ pub fn get_chain_spec(id: ParaId) -> ChainSpec { None, None, None, - Extensions { - relay_chain: "westend".into(), - para_id: id.into(), - }, + Extensions { relay_chain: "westend".into(), para_id: id.into() }, ) } @@ -100,7 +95,7 @@ pub fn staging_test_net(id: ParaId) -> ChainSpec { .unchecked_into(), ], vec![ - hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into(), + hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into() ], id, ) @@ -109,10 +104,7 @@ pub fn staging_test_net(id: ParaId) -> ChainSpec { None, None, None, - Extensions { - relay_chain: "westend".into(), - para_id: id.into(), - }, + Extensions { relay_chain: "westend".into(), para_id: id.into() }, ) } @@ -122,7 +114,6 @@ fn testnet_genesis( endowed_accounts: Vec, id: ParaId, ) -> parachain_runtime::GenesisConfig { - let num_endowed_accounts = endowed_accounts.len(); parachain_runtime::GenesisConfig { @@ -133,28 +124,23 @@ fn testnet_genesis( changes_trie_config: Default::default(), }, balances: parachain_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, 1 << 60)) - .collect(), + balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), }, sudo: parachain_runtime::SudoConfig { key: root_key }, parachain_info: parachain_runtime::ParachainInfoConfig { parachain_id: id }, democracy: parachain_runtime::DemocracyConfig::default(), council: parachain_runtime::CouncilConfig::default(), technical_committee: parachain_runtime::TechnicalCommitteeConfig { - members: endowed_accounts.iter() - .take((num_endowed_accounts + 1) / 2) - .cloned() - .collect(), + members: endowed_accounts + .iter() + .take((num_endowed_accounts + 1) / 2) + .cloned() + .collect(), phantom: Default::default(), }, treasury: Default::default(), - aura: parachain_runtime::AuraConfig { - authorities: initial_authorities, - }, + aura: parachain_runtime::AuraConfig { authorities: initial_authorities }, aura_ext: Default::default(), parachain_system: Default::default(), } -} \ No newline at end of file +} diff --git a/node/src/cli.rs b/node/src/cli.rs index 6623d2ad71..9f1634e7a8 100644 --- a/node/src/cli.rs +++ b/node/src/cli.rs @@ -112,14 +112,7 @@ impl RelayChainCli { ) -> Self { let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec); let chain_id = extension.map(|e| e.relay_chain.clone()); - let base_path = para_config - .base_path - .as_ref() - .map(|x| x.path().join("polkadot")); - Self { - base_path, - chain_id, - base: polkadot_cli::RunCmd::from_iter(relay_chain_args), - } + let base_path = para_config.base_path.as_ref().map(|x| x.path().join("polkadot")); + Self { base_path, chain_id, base: polkadot_cli::RunCmd::from_iter(relay_chain_args) } } -} \ No newline at end of file +} diff --git a/node/src/command.rs b/node/src/command.rs index 2bc27eb355..8fb9e60467 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -29,7 +29,7 @@ fn load_spec( path => { let chain_spec = chain_spec::ChainSpec::from_json_file(path.into())?; Box::new(chain_spec) - } + }, }) } @@ -149,27 +149,27 @@ pub fn run() -> Result<()> { Some(Subcommand::BuildSpec(cmd)) => { let runner = cli.create_runner(cmd)?; runner.sync_run(|config| cmd.run(config.chain_spec, config.network)) - } + }, Some(Subcommand::CheckBlock(cmd)) => { construct_async_run!(|components, cli, cmd, config| { Ok(cmd.run(components.client, components.import_queue)) }) - } + }, Some(Subcommand::ExportBlocks(cmd)) => { construct_async_run!(|components, cli, cmd, config| { Ok(cmd.run(components.client, config.database)) }) - } + }, Some(Subcommand::ExportState(cmd)) => { construct_async_run!(|components, cli, cmd, config| { Ok(cmd.run(components.client, config.chain_spec)) }) - } + }, Some(Subcommand::ImportBlocks(cmd)) => { construct_async_run!(|components, cli, cmd, config| { Ok(cmd.run(components.client, components.import_queue)) }) - } + }, Some(Subcommand::PurgeChain(cmd)) => { let runner = cli.create_runner(cmd)?; @@ -190,7 +190,7 @@ pub fn run() -> Result<()> { cmd.run(config, polkadot_config) }) - } + }, Some(Subcommand::Revert(cmd)) => construct_async_run!(|components, cli, cmd, config| { Ok(cmd.run(components.client, components.backend)) }), @@ -217,7 +217,7 @@ pub fn run() -> Result<()> { } Ok(()) - } + }, Some(Subcommand::ExportGenesisWasm(params)) => { let mut builder = sc_cli::LoggerBuilder::new(""); builder.with_profiling(sc_tracing::TracingReceiver::Log, ""); @@ -238,12 +238,11 @@ pub fn run() -> Result<()> { } Ok(()) - } + }, None => { let runner = cli.create_runner(&cli.run.normalize())?; runner.run_node_until_exit(|config| async move { - let para_id = chain_spec::Extensions::try_get(&*config.chain_spec).map(|e| e.para_id); @@ -271,23 +270,14 @@ pub fn run() -> Result<()> { info!("Parachain id: {:?}", id); info!("Parachain Account: {}", parachain_account); info!("Parachain genesis state: {}", genesis_state); - info!( - "Is collating: {}", - if config.role.is_authority() { - "yes" - } else { - "no" - } - ); - + info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" }); crate::service::start_rococo_parachain_node(config, polkadot_config, id) .await .map(|r| r.0) .map_err(Into::into) - }) - } + }, } } @@ -356,11 +346,7 @@ impl CliConfiguration for RelayChainCli { fn chain_id(&self, is_dev: bool) -> Result { let chain_id = self.base.base.chain_id(is_dev)?; - Ok(if chain_id.is_empty() { - self.chain_id.clone().unwrap_or_default() - } else { - chain_id - }) + Ok(if chain_id.is_empty() { self.chain_id.clone().unwrap_or_default() } else { chain_id }) } fn role(&self, is_dev: bool) -> Result { @@ -417,4 +403,4 @@ impl CliConfiguration for RelayChainCli { ) -> Result> { self.base.base.telemetry_endpoints(chain_spec) } -} \ No newline at end of file +} diff --git a/node/src/main.rs b/node/src/main.rs index a3bcf9be24..c71f714513 100644 --- a/node/src/main.rs +++ b/node/src/main.rs @@ -8,4 +8,4 @@ mod command; fn main() -> sc_cli::Result<()> { command::run() -} \ No newline at end of file +} diff --git a/node/src/service.rs b/node/src/service.rs index f756e87351..ef00b4871f 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -186,7 +186,7 @@ where ) -> Result>, sc_service::Error>, { if matches!(parachain_config.role, Role::Light) { - return Err("Light client not supported!".into()); + return Err("Light client not supported!".into()) } let parachain_config = prepare_node_config(parachain_config); @@ -194,14 +194,12 @@ where let params = new_partial::(¶chain_config, build_import_queue)?; let (mut telemetry, telemetry_worker_handle) = params.other; - let relay_chain_full_node = cumulus_client_service::build_polkadot_full_node( - polkadot_config, - telemetry_worker_handle, - ) - .map_err(|e| match e { - polkadot_service::Error::Sub(x) => x, - s => format!("{}", s).into(), - })?; + let relay_chain_full_node = + cumulus_client_service::build_polkadot_full_node(polkadot_config, telemetry_worker_handle) + .map_err(|e| match e { + polkadot_service::Error::Sub(x) => x, + s => format!("{}", s).into(), + })?; let client = params.client.clone(); let backend = params.backend.clone(); @@ -234,7 +232,10 @@ where if parachain_config.offchain_worker.enabled { sc_service::build_offchain_workers( - ¶chain_config, task_manager.spawn_handle(), client.clone(), network.clone(), + ¶chain_config, + task_manager.spawn_handle(), + client.clone(), + network.clone(), ); }; @@ -305,9 +306,7 @@ where /// Build the import queue for the rococo parachain runtime. pub fn rococo_parachain_build_import_queue( - client: Arc< - TFullClient, - >, + client: Arc>, config: &Configuration, telemetry: Option, task_manager: &TaskManager, @@ -320,29 +319,33 @@ pub fn rococo_parachain_build_import_queue( > { let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?; - cumulus_client_consensus_aura::import_queue::( - cumulus_client_consensus_aura::ImportQueueParams { - block_import: client.clone(), - client: client.clone(), - create_inherent_data_providers: move |_, _| async move { - let time = sp_timestamp::InherentDataProvider::from_system_time(); + cumulus_client_consensus_aura::import_queue::< + sp_consensus_aura::sr25519::AuthorityPair, + _, + _, + _, + _, + _, + _, + >(cumulus_client_consensus_aura::ImportQueueParams { + block_import: client.clone(), + client: client.clone(), + create_inherent_data_providers: move |_, _| async move { + let time = sp_timestamp::InherentDataProvider::from_system_time(); - let slot = - sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration( - *time, - slot_duration.slot_duration(), - ); + let slot = + sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration( + *time, + slot_duration.slot_duration(), + ); - Ok((time, slot)) - }, - registry: config.prometheus_registry().clone(), - can_author_with: sp_consensus::CanAuthorWithNativeVersion::new( - client.executor().clone(), - ), - spawner: &task_manager.spawn_essential_handle(), - telemetry, + Ok((time, slot)) }, - ) + registry: config.prometheus_registry().clone(), + can_author_with: sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()), + spawner: &task_manager.spawn_essential_handle(), + telemetry, + }) .map_err(Into::into) } diff --git a/runtime/build.rs b/runtime/build.rs index bbc5009b46..9b53d2457d 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -6,4 +6,4 @@ fn main() { .export_heap_base() .import_memory() .build() -} \ No newline at end of file +} diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 9ca9670acb..2572f9aa39 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -24,25 +24,27 @@ use sp_version::RuntimeVersion; // A few exports that help ease life for downstream crates. pub use frame_support::{ - construct_runtime, parameter_types, RuntimeDebug, PalletId, match_type, - traits::{Randomness, InstanceFilter, IsInVec, All, MaxEncodedLen}, + construct_runtime, match_type, parameter_types, + traits::{All, InstanceFilter, IsInVec, MaxEncodedLen, Randomness}, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, DispatchClass, IdentityFee, Weight, }, - StorageValue, + PalletId, RuntimeDebug, StorageValue, }; use frame_system::{ - EnsureRoot, EnsureOneOf, - limits::{BlockLength, BlockWeights} -};pub use pallet_balances::Call as BalancesCall; + limits::{BlockLength, BlockWeights}, + EnsureOneOf, EnsureRoot, +}; +pub use pallet_balances::Call as BalancesCall; pub use pallet_timestamp::Call as TimestampCall; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; -pub use sp_runtime::{Percent, Perbill, Permill}; +pub use sp_runtime::{Perbill, Percent, Permill}; // XCM imports +use codec::{Decode, Encode}; use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough}; use polkadot_parachain::primitives::Sibling; use xcm::v0::{BodyId, Junction::*, MultiAsset, MultiLocation, MultiLocation::*, NetworkId, Xcm}; @@ -54,7 +56,6 @@ use xcm_builder::{ SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, }; use xcm_executor::{Config, XcmExecutor}; -use codec::{Encode, Decode}; pub type SessionHandlers = (); @@ -104,10 +105,7 @@ pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4); /// The version information used to identify this runtime when compiled natively. #[cfg(feature = "std")] pub fn native_version() -> NativeVersion { - NativeVersion { - runtime_version: VERSION, - can_author_with: Default::default(), - } + NativeVersion { runtime_version: VERSION, can_author_with: Default::default() } } /// We assume that ~10% of the block weight is consumed by `on_initalize` handlers. @@ -196,27 +194,31 @@ parameter_types! { } /// The type used to represent the kinds of proxying allowed. -#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, MaxEncodedLen)] +#[derive( + Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, MaxEncodedLen, +)] pub enum ProxyType { Any, NonTransfer, Governance, } -impl Default for ProxyType { fn default() -> Self { Self::Any } } + +impl Default for ProxyType { + fn default() -> Self { + Self::Any + } +} + impl InstanceFilter for ProxyType { fn filter(&self, c: &Call) -> bool { match self { ProxyType::Any => true, - ProxyType::NonTransfer => !matches!( - c, - Call::Balances(..) - ), + ProxyType::NonTransfer => !matches!(c, Call::Balances(..)), ProxyType::Governance => matches!( c, Call::Democracy(..) | - Call::Council(..) | - Call::TechnicalCommittee(..) | - Call::Treasury(..) + Call::Council(..) | Call::TechnicalCommittee(..) | + Call::Treasury(..) ), } } @@ -347,20 +349,26 @@ impl pallet_democracy::Config for Runtime { type VotingPeriod = VotingPeriod; type MinimumDeposit = MinimumDeposit; /// A straight majority of the council can decide what their next motion is. - type ExternalOrigin = pallet_collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>; + type ExternalOrigin = + pallet_collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>; /// A super-majority can have the next scheduled referendum be a straight majority-carries vote. - type ExternalMajorityOrigin = pallet_collective::EnsureProportionAtLeast<_3, _4, AccountId, CouncilCollective>; + type ExternalMajorityOrigin = + pallet_collective::EnsureProportionAtLeast<_3, _4, AccountId, CouncilCollective>; /// A unanimous council can have the next scheduled referendum be a straight default-carries /// (NTB) vote. - type ExternalDefaultOrigin = pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, CouncilCollective>; + type ExternalDefaultOrigin = + pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, CouncilCollective>; /// Two thirds of the technical committee can have an ExternalMajority/ExternalDefault vote /// be tabled immediately and with a shorter voting/enactment period. - type FastTrackOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechnicalCollective>; - type InstantOrigin = pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>; + type FastTrackOrigin = + pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechnicalCollective>; + type InstantOrigin = + pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>; type InstantAllowed = InstantAllowed; type FastTrackVotingPeriod = FastTrackVotingPeriod; // To cancel a proposal which has been passed, 2/3 of the council must agree to it. - type CancellationOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>; + type CancellationOrigin = + pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>; // To cancel a proposal before it has been passed, the technical committee must be unanimous or // Root must agree. type CancelProposalOrigin = EnsureOneOf< @@ -444,12 +452,12 @@ impl pallet_treasury::Config for Runtime { type ApproveOrigin = EnsureOneOf< AccountId, EnsureRoot, - pallet_collective::EnsureProportionAtLeast<_3, _5, AccountId, CouncilCollective> + pallet_collective::EnsureProportionAtLeast<_3, _5, AccountId, CouncilCollective>, >; type RejectOrigin = EnsureOneOf< AccountId, EnsureRoot, - pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective> + pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>, >; type Event = Event; type OnSlash = (); @@ -631,8 +639,7 @@ impl cumulus_ping::Config for Runtime { impl pallet_account_linker::Config for Runtime { type Event = Event; - type WeightInfo = pallet_account_linker::weights::SubstrateWeight; - + type WeightInfo = pallet_account_linker::weights::SubstrateWeight; } parameter_types! { @@ -663,14 +670,9 @@ where public: ::Signer, account: AccountId, index: Index, - ) -> Option<( - Call, - ::SignaturePayload, - )> { + ) -> Option<(Call, ::SignaturePayload)> { let period = BlockHashCount::get() as u64; - let current_block = System::block_number() - .saturated_into::() - .saturating_sub(1); + let current_block = System::block_number().saturated_into::().saturating_sub(1); let tip = 0; let extra: SignedExtra = ( frame_system::CheckSpecVersion::::new(), diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000000..6005fb8234 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,20 @@ +# Basic +hard_tabs = true +max_width = 100 +use_small_heuristics = "Max" +# Imports +imports_granularity = "Crate" +reorder_imports = true +# Consistency +newline_style = "Unix" +# Misc +chain_width = 80 +spaces_around_ranges = false +binop_separator = "Back" +reorder_impl_items = false +match_arm_leading_pipes = "Preserve" +match_arm_blocks = false +match_block_trailing_comma = true +trailing_comma = "Vertical" +trailing_semicolon = false +use_field_init_shorthand = true \ No newline at end of file