Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Minor refactorings #223

Merged
merged 1 commit into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion node/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Extensions {

/// Helper function to generate a crypto pair from seed
pub fn get_public_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
TPublic::Pair::from_string(&format!("//{seed}"), None)
.expect("static values are valid; qed")
.public()
}
Expand Down
6 changes: 3 additions & 3 deletions node/src/chain_spec/stout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ fn testnet_genesis(
},
balances: BalancesConfig {
// Configure endowed accounts with initial balance of 1 << 60.
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
balances: endowed_accounts.into_iter().map(|k| (k, 1 << 60)).collect(),
},
parachain_info: stout_runtime::ParachainInfoConfig { parachain_id: id },
collator_selection: stout_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
invulnerables: invulnerables.iter().map(|(acc, _)| acc).cloned().collect(),
candidacy_bond: EXISTENTIAL_DEPOSIT * 16,
..Default::default()
},
Expand Down Expand Up @@ -146,7 +146,7 @@ fn testnet_genesis(
},
assets: AssetsConfig { assets: vec![], accounts: vec![], metadata: vec![] },
council: CouncilConfig {
members: invulnerables.iter().map(|x| x.0.clone()).collect::<Vec<_>>(),
members: invulnerables.into_iter().map(|x| x.0).collect::<Vec<_>>(),
phantom: Default::default(),
},
dex: Default::default(),
Expand Down
29 changes: 11 additions & 18 deletions node/src/chain_spec/trappist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ pub fn testnet_genesis(
},
balances: BalancesConfig {
// Configure endowed accounts with initial balance of 1 << 60.
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
balances: endowed_accounts.into_iter().map(|k| (k, 1 << 60)).collect(),
},
parachain_info: trappist_runtime::ParachainInfoConfig { parachain_id: id },
collator_selection: trappist_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
invulnerables: invulnerables.iter().map(|(acc, _)| acc).cloned().collect(),
candidacy_bond: EXISTENTIAL_DEPOSIT * 16,
..Default::default()
},
Expand Down Expand Up @@ -202,7 +202,7 @@ pub fn testnet_genesis(
},
assets: AssetsConfig { assets: vec![], accounts: vec![], metadata: vec![] },
council: CouncilConfig {
members: invulnerables.iter().map(|x| x.0.clone()).collect::<Vec<_>>(),
members: invulnerables.into_iter().map(|x| x.0).collect::<Vec<_>>(),
phantom: Default::default(),
},
treasury: Default::default(),
Expand Down Expand Up @@ -276,32 +276,25 @@ fn trappist_live_genesis(
balances: BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.chain(std::iter::once(root_key.clone()))
.map(|k| {
if k == root_key {
(k, 1_000_000_000_000_000_000)
} else {
(k, 1_500_000_000_000_000_000)
}
})
.map(|x| (x.clone(), 1_500_000_000_000_000_000))
.chain(std::iter::once((root_key.clone(), 1_000_000_000_000_000_000)))
.collect(),
},
parachain_info: trappist_runtime::ParachainInfoConfig { parachain_id: id },
collator_selection: trappist_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
invulnerables: invulnerables.iter().map(|(acc, _)| acc).cloned().collect(),
candidacy_bond: EXISTENTIAL_DEPOSIT * 16,
..Default::default()
},
democracy: Default::default(),
session: SessionConfig {
keys: invulnerables
.iter()
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc.clone(), // validator id
session_keys(aura.clone()), // session keys
acc.clone(), // account id
acc, // validator id
session_keys(aura), // session keys
)
})
.collect(),
Expand All @@ -319,7 +312,7 @@ fn trappist_live_genesis(
assets: AssetsConfig { assets: vec![], accounts: vec![], metadata: vec![] },
council: CouncilConfig {
// We set the endowed accounts with balance as members of the council.
members: endowed_accounts.iter().map(|x| x.clone()).collect::<Vec<_>>(),
members: endowed_accounts,
phantom: Default::default(),
},
treasury: Default::default(),
Expand Down
2 changes: 2 additions & 0 deletions node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! Trappist Node CLI.

#![warn(missing_docs)]
#![warn(unused_extern_crates)]

Expand Down
38 changes: 21 additions & 17 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,37 +707,41 @@ where
<<AuraId as AppKey>::Pair as Pair>::Signature:
TryFrom<Vec<u8>> + std::hash::Hash + sp_runtime::traits::Member + Codec,
{
let client2 = client.clone();
let aura_verifier = {
let client = client.clone();

let aura_verifier = move || {
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client2).unwrap();
move || {
let slot_duration =
cumulus_client_consensus_aura::slot_duration(client.as_ref()).unwrap();

Box::new(
cumulus_client_consensus_aura::build_verifier::<<AuraId as AppKey>::Pair, _, _, _>(
cumulus_client_consensus_aura::BuildVerifierParams {
client: client2.clone(),
create_inherent_data_providers: move |_, _| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
Box::new(cumulus_client_consensus_aura::build_verifier::<
<AuraId as AppKey>::Pair,
_,
_,
_,
>(cumulus_client_consensus_aura::BuildVerifierParams {
client,
create_inherent_data_providers: move |_, _| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();

let slot =
let slot =
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);

Ok((slot, timestamp))
},
telemetry: telemetry_handle,
Ok((slot, timestamp))
},
),
) as Box<_>
telemetry: telemetry_handle,
})) as Box<_>
}
};

let relay_chain_verifier =
Box::new(RelayChainVerifier::new(client.clone(), |_, _| async { Ok(()) })) as Box<_>;
Box::new(RelayChainVerifier::new(client.clone(), |_, _| async { Ok(()) }));

let verifier = Verifier {
client: client.clone(),
client,
relay_chain_verifier,
aura_verifier: BuildOnAccess::Uninitialized(Some(Box::new(aura_verifier))),
_phantom: PhantomData,
Expand Down
8 changes: 2 additions & 6 deletions pallets/lockdown-mode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub mod pallet {
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
fn build(&self) {
LockdownModeStatus::<T>::put(&self.initial_status);
LockdownModeStatus::<T>::put(self.initial_status);
}
}

Expand Down Expand Up @@ -149,11 +149,7 @@ pub mod pallet {

impl<T: Config> Contains<T::RuntimeCall> for Pallet<T> {
fn contains(call: &T::RuntimeCall) -> bool {
if LockdownModeStatus::<T>::get() {
T::BlackListedCalls::contains(call)
} else {
return true
}
!LockdownModeStatus::<T>::get() || T::BlackListedCalls::contains(call)
}
}

Expand Down
5 changes: 2 additions & 3 deletions runtime/trappist/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ pub mod currency {

/// Fee-related.
pub mod fee {
use super::currency::CENTS;
use frame_support::weights::{
constants::{ExtrinsicBaseWeight, WEIGHT_REF_TIME_PER_SECOND},
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients,
WeightToFeePolynomial,
};
use polkadot_core_primitives::Balance;
use smallvec::smallvec;
Expand Down
22 changes: 11 additions & 11 deletions runtime/trappist/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ where
pub struct RuntimeBlackListedCalls;
impl Contains<RuntimeCall> for RuntimeBlackListedCalls {
fn contains(call: &RuntimeCall) -> bool {
match call {
RuntimeCall::Balances(_) => false,
RuntimeCall::Assets(_) => false,
RuntimeCall::Dex(_) => false,
RuntimeCall::PolkadotXcm(_) => false,
RuntimeCall::Treasury(_) => false,
RuntimeCall::Contracts(_) => false,
RuntimeCall::Uniques(_) => false,
RuntimeCall::AssetRegistry(_) => false,
_ => true,
}
!matches!(
call,
RuntimeCall::Balances(_) |
RuntimeCall::Assets(_) |
RuntimeCall::Dex(_) |
RuntimeCall::PolkadotXcm(_) |
RuntimeCall::Treasury(_) |
RuntimeCall::Contracts(_) |
RuntimeCall::Uniques(_) |
RuntimeCall::AssetRegistry(_)
)
}
}

Expand Down
26 changes: 15 additions & 11 deletions runtime/trappist/src/weights/block_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// limitations under the License.

//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-06-08 (Y/M/D)
//! DATE: 2023-06-09 (Y/M/D)
//! HOSTNAME: `kalan-x1x`, CPU: `12th Gen Intel(R) Core(TM) i7-12800H`
//!
//! SHORT-NAME: `block`, LONG-NAME: `BlockExecution`, RUNTIME: `Trappist Development`
Expand All @@ -28,9 +28,13 @@
// target/debug/trappist-node
// benchmark
// overhead
// --chain
// dev
// --chain=trappist-dev
// --execution=wasm
// --wasm-execution=compiled
// --weight-path=./runtime/trappist/src/weights
// --warmup=10
// --repeat=100
// --header=./templates/file_header.txt

use sp_core::parameter_types;
use sp_weights::{constants::WEIGHT_REF_TIME_PER_NANOS, Weight};
Expand All @@ -40,17 +44,17 @@ parameter_types! {
/// Calculated by multiplying the *Average* with `1.0` and adding `0`.
///
/// Stats nanoseconds:
/// Min, Max: 5_120_602, 10_113_574
/// Average: 6_901_058
/// Median: 6_276_001
/// Std-Dev: 1393716.66
/// Min, Max: 3_950_018, 4_495_760
/// Average: 4_098_356
/// Median: 4_070_795
/// Std-Dev: 83926.18
///
/// Percentiles nanoseconds:
/// 99th: 9_958_901
/// 95th: 8_509_417
/// 75th: 8_216_945
/// 99th: 4_389_302
/// 95th: 4_241_334
/// 75th: 4_137_615
pub const BlockExecutionWeight: Weight =
Weight::from_ref_time(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(6_901_058));
Weight::from_ref_time(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(4_098_356));
}

#[cfg(test)]
Expand Down
26 changes: 15 additions & 11 deletions runtime/trappist/src/weights/extrinsic_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// limitations under the License.

//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-06-08 (Y/M/D)
//! DATE: 2023-06-09 (Y/M/D)
//! HOSTNAME: `kalan-x1x`, CPU: `12th Gen Intel(R) Core(TM) i7-12800H`
//!
//! SHORT-NAME: `extrinsic`, LONG-NAME: `ExtrinsicBase`, RUNTIME: `Trappist Development`
Expand All @@ -28,9 +28,13 @@
// target/debug/trappist-node
// benchmark
// overhead
// --chain
// dev
// --chain=trappist-dev
// --execution=wasm
// --wasm-execution=compiled
// --weight-path=./runtime/trappist/src/weights
// --warmup=10
// --repeat=100
// --header=./templates/file_header.txt

use sp_core::parameter_types;
use sp_weights::{constants::WEIGHT_REF_TIME_PER_NANOS, Weight};
Expand All @@ -40,17 +44,17 @@ parameter_types! {
/// Calculated by multiplying the *Average* with `1.0` and adding `0`.
///
/// Stats nanoseconds:
/// Min, Max: 1_538_002, 2_494_865
/// Average: 1_980_785
/// Median: 2_006_809
/// Std-Dev: 131423.95
/// Min, Max: 921_024, 963_714
/// Average: 930_758
/// Median: 928_324
/// Std-Dev: 7978.85
///
/// Percentiles nanoseconds:
/// 99th: 2_378_849
/// 95th: 2_080_265
/// 75th: 2_030_767
/// 99th: 958_566
/// 95th: 948_841
/// 75th: 932_871
pub const ExtrinsicBaseWeight: Weight =
Weight::from_ref_time(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(1_980_785));
Weight::from_ref_time(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(930_758));
}

#[cfg(test)]
Expand Down
11 changes: 5 additions & 6 deletions runtime/trappist/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::Runtime;
use frame_support::weights::Weight;
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
use sp_std::{cmp, prelude::*};
use sp_std::cmp;
use xcm::{
latest::{prelude::*, Weight as XCMWeight},
DoubleEncoded,
Expand All @@ -37,8 +37,7 @@ const MAX_ASSETS: u32 = 100;
impl WeighMultiAssets for MultiAssetFilter {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight {
let weight = match self {
Self::Definite(assets) =>
weight.saturating_mul(assets.inner().into_iter().count() as u64),
Self::Definite(assets) => weight.saturating_mul(assets.inner().iter().count() as u64),
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
};
weight.ref_time()
Expand All @@ -47,7 +46,7 @@ impl WeighMultiAssets for MultiAssetFilter {

impl WeighMultiAssets for MultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight {
weight.saturating_mul(self.inner().into_iter().count() as u64).ref_time()
weight.saturating_mul(self.inner().iter().count() as u64).ref_time()
}
}

Expand Down Expand Up @@ -119,7 +118,7 @@ impl<Call> XcmWeightInfo<Call> for TrappistXcmWeight<Call> {
_dest: &MultiLocation,
) -> XCMWeight {
// Hardcoded till the XCM pallet is fixed
let hardcoded_weight = Weight::from_ref_time(1_000_000_000 as u64).ref_time();
let hardcoded_weight = Weight::from_ref_time(1_000_000_000).ref_time();
let weight = assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_asset());
cmp::min(hardcoded_weight, weight)
}
Expand Down Expand Up @@ -147,7 +146,7 @@ impl<Call> XcmWeightInfo<Call> for TrappistXcmWeight<Call> {
_xcm: &Xcm<()>,
) -> XCMWeight {
// Hardcoded till the XCM pallet is fixed
let hardcoded_weight = Weight::from_ref_time(200_000_000 as u64).ref_time();
let hardcoded_weight = Weight::from_ref_time(200_000_000).ref_time();
let weight = assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport());
cmp::min(hardcoded_weight, weight)
}
Expand Down
2 changes: 1 addition & 1 deletion templates/file_header.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
// 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.
// limitations under the License.