From 24a6f803c5508d10fa1db6e9fcfd2fb6177257e3 Mon Sep 17 00:00:00 2001 From: Uncle Stretch Date: Tue, 29 Jul 2025 14:53:50 +0300 Subject: [PATCH] rustfmt common runtime and fix typos Signed-off-by: Uncle Stretch --- runtime/common/Cargo.toml | 2 +- runtime/common/src/benchmarking.rs | 22 ++++++++++---- runtime/common/src/elections.rs | 6 ++-- runtime/common/src/impls.rs | 47 ++++++++++++++++++++++-------- runtime/common/src/lib.rs | 13 ++++----- runtime/common/src/try_runtime.rs | 15 ++++++---- 6 files changed, 70 insertions(+), 35 deletions(-) diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 59d6924..eded932 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ghost-runtime-common" -version = "0.4.2" +version = "0.4.3" authors.workspace = true edition.workspace = true homepage.workspace = true diff --git a/runtime/common/src/benchmarking.rs b/runtime/common/src/benchmarking.rs index c3dc46e..6f4fd3f 100644 --- a/runtime/common/src/benchmarking.rs +++ b/runtime/common/src/benchmarking.rs @@ -1,11 +1,13 @@ -use primitives::{AccountId, Balance}; -use pallet_treasury::ArgumentsFactory; -use sp_core::crypto::FromEntropy; use frame_support::traits::tokens::{Pay, PaymentStatus}; +use pallet_treasury::ArgumentsFactory; +use primitives::{AccountId, Balance}; +use sp_core::crypto::FromEntropy; pub struct BenchmarkTreasuryHelper; impl ArgumentsFactory<(), AccountId> for BenchmarkTreasuryHelper { - fn create_asset_kind(_seed: u32) -> () { () } + fn create_asset_kind(_seed: u32) -> () { + () + } fn create_beneficiary(seed: [u8; 32]) -> AccountId { AccountId::from_entropy(&mut seed.as_slice()).unwrap() } @@ -19,8 +21,16 @@ impl Pay for BenchmarkTreasuryPaymaster { type AssetKind = (); type Error = (); - fn pay(_: &Self::Beneficiary, _: Self::AssetKind, _: Self::Balance) -> Result { Ok(()) } - fn check_payment(_: Self::Id) -> PaymentStatus { PaymentStatus::Success } + fn pay( + _: &Self::Beneficiary, + _: Self::AssetKind, + _: Self::Balance, + ) -> Result { + Ok(()) + } + fn check_payment(_: Self::Id) -> PaymentStatus { + PaymentStatus::Success + } fn ensure_successful(_: &Self::Beneficiary, _: Self::AssetKind, _: Self::Balance) {} fn ensure_concluded(_: Self::Id) {} } diff --git a/runtime/common/src/elections.rs b/runtime/common/src/elections.rs index 980bd4c..dba9dcd 100644 --- a/runtime/common/src/elections.rs +++ b/runtime/common/src/elections.rs @@ -4,7 +4,7 @@ macro_rules! impl_elections_weights { parameter_types! { /// A limit for off-chain phragmen unsigned solution submission. /// - /// We want to keep it as high as possible, but can't risk having + /// We want to keep it as high as possible, but can't risk having /// it reject, so we always substract the base block execution weight. pub OffchainSolutionWeightLimit: Weight = BlockWeights::get() .get(DispatchClass::Normal) @@ -23,8 +23,8 @@ macro_rules! impl_elections_weights { }; } -/// The number configured here could always be more than the maximum limits of -/// staking pallet to ensure election snapshot will not run out of memory. For +/// The number configured here could always be more than the maximum limits of +/// staking pallet to ensure election snapshot will not run out of memory. For /// now, we set them to smaller values since the staking is bounded and the weight /// pipeline takes for this single pallet. pub struct BenchmarkConfig; diff --git a/runtime/common/src/impls.rs b/runtime/common/src/impls.rs index 271c5ba..2efd7ff 100644 --- a/runtime/common/src/impls.rs +++ b/runtime/common/src/impls.rs @@ -51,13 +51,13 @@ mod tests { use super::*; use frame_support::{ derive_impl, - dispatch::DispatchClass, - parameter_types, + dispatch::DispatchClass, + parameter_types, traits::{ tokens::{PayFromAccount, UnityAssetBalanceConversion}, - ConstU32, FindAuthor + ConstU32, FindAuthor, }, - weights::Weight, + weights::Weight, PalletId, }; use frame_system::limits; @@ -65,14 +65,14 @@ mod tests { use sp_core::{ConstU64, H256}; use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, - Perbill, BuildStorage, + BuildStorage, Perbill, }; type Block = frame_system::mocking::MockingBlock; const TEST_ACCOUNT: AccountId = AccountId::new([1; 32]); frame_support::construct_runtime!( - pub enum Test + pub enum Test { System: frame_system, Authorship: pallet_authorship, @@ -172,7 +172,10 @@ mod tests { pub struct OneAuthor; impl FindAuthor for OneAuthor { - fn find_author<'a, I>(_: I) -> Option where I: 'a { + fn find_author<'a, I>(_: I) -> Option + where + I: 'a, + { Some(TEST_ACCOUNT) } } @@ -185,7 +188,9 @@ mod tests { } pub fn new_test_ext() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + let mut t = frame_system::GenesisConfig::default() + .build_storage::() + .unwrap(); // We use default for brevity, but you can configure as desired if needed. pallet_balances::GenesisConfig::::default() .assimilate_storage(&mut t) @@ -196,8 +201,14 @@ mod tests { #[test] fn test_fees_and_tips_split() { new_test_ext().execute_with(|| { - let fee = as frame_support::traits::fungible::Balanced>::issue(10); - let tip = as frame_support::traits::fungible::Balanced>::issue(20); + let fee = + as frame_support::traits::fungible::Balanced< + AccountId, + >>::issue(10); + let tip = + as frame_support::traits::fungible::Balanced< + AccountId, + >>::issue(20); assert_eq!(Balances::free_balance(Treasury::account_id()), 0); assert_eq!(Balances::free_balance(TEST_ACCOUNT), 0); @@ -242,11 +253,23 @@ mod tests { #[test] fn era_payout_should_give_sensible_results() { assert_eq!( - era_payout(75, 100, Perquintill::from_percent(10), Perquintill::one(), 0, ), + era_payout( + 75, + 100, + Perquintill::from_percent(10), + Perquintill::one(), + 0, + ), (10, 0) ); assert_eq!( - era_payout(80, 100, Perquintill::from_percent(10), Perquintill::one(), 0, ), + era_payout( + 80, + 100, + Perquintill::from_percent(10), + Perquintill::one(), + 0, + ), (6, 4) ); } diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 2c9b97b..7740134 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -1,7 +1,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -pub mod impls; pub mod elections; +pub mod impls; #[cfg(feature = "try-runtime")] pub mod elections; @@ -10,7 +10,8 @@ pub mod elections; pub mod benchmarking; use frame_support::{ - parameter_types, traits::ConstU32, + parameter_types, + traits::ConstU32, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, }; use frame_system::limits; @@ -92,8 +93,8 @@ macro_rules! impl_runtime_weights { use frame_system::limits; use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment}; pub use runtime_common::{ - impl_elections_weights, AVERAGE_ON_INITIALIZE_RATIO, - MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, + impl_elections_weights, AVERAGE_ON_INITIALIZE_RATIO, MAXIMUM_BLOCK_WEIGHT, + NORMAL_DISPATCH_RATIO, }; use sp_runtime::{FixedPointNumber, Perquintill}; @@ -101,8 +102,7 @@ macro_rules! impl_runtime_weights { // Expose the weight from the runtime constants module. pub use $runtime::weights::{ - BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, - ParityDbWeight, + BlockExecutionWeight, ExtrinsicBaseWeight, ParityDbWeight, RocksDbWeight, }; parameter_types! { @@ -129,7 +129,6 @@ macro_rules! impl_runtime_weights { }; } - /// The type used for currency conversion. /// /// This must be only be used as long as the balance type is `u128`. diff --git a/runtime/common/src/try_runtime.rs b/runtime/common/src/try_runtime.rs index 7652b92..f644196 100644 --- a/runtime/common/src/try_runtime.rs +++ b/runtime/common/src/try_runtime.rs @@ -4,7 +4,7 @@ use frame_support::{ }; use pallet_fast_unstake::{Pallet as FastUnstake, *}; use pallet_staking::*; -use sp_std::{collections::btree_set::BTreeSet, prelude:*}; +use sp_std::{collections::btree_set::BTreeSet, prelude::*}; /// Register all inactive nominators for fast unstake, and progress until they /// have all benn processed. @@ -16,7 +16,9 @@ where let mut unstaked_err = 0; let mut unstaked_slashed = 0; - let all_stakers = Ledger::::iter().map(|(ctrl, l)| (ctrl, l.stash)).collect::>(); + let all_stakers = Ledger::::iter() + .map(|(ctrl, l)| (ctrl, l.stash)) + .collect::>(); let mut all_exposed = BTreeSet::new(); ErasStakers::::iter().for_each(|(_, val, expo)| { all_exposed.insert(val); @@ -55,7 +57,7 @@ where let weight = ::BlockWeights::get().max_block; let consumed = FastUnstake::::on_idle(now, weight); log::debug!( - target: "runtime::test", + target: "runtime::test", "consumed {:?} ({})", consumed, consumed.ref_time() as f32 / weight.ref_time() as f32, @@ -70,15 +72,16 @@ where maybe_fast_unstake_event }) .for_each(|e: pallet_fast_unstake::Event| match e { - pallet_fast_unstake::Event::Unstaked { result, .. } => + pallet_fast_unstake::Event::::Unstaked { result, .. } => { if result.is_ok() { unstaked_ok += 1; } else { unstaked_err += 1; - }, + } + } pallet_fast_unstake::Event::::Slashed { .. } => unstaked_slashed += 1, pallet_fast_unstake::Event::::InternalError { .. } => unreachable!(), - _ => {}, + _ => {} }); if now % 100u32.into() == sp_runtime::traits::Zero::zero() {