From 3c2bde36fe45af75a64f7b57a856dff55834ef8f Mon Sep 17 00:00:00 2001 From: Igor Papandinas Date: Fri, 29 Mar 2024 16:56:23 +0400 Subject: [PATCH] chore: fmt --- .../manual-seal/src/consensus/babe.rs | 7 ++- client/consensus/manual-seal/src/rpc.rs | 4 +- .../consensus/manual-seal/src/seal_block.rs | 14 +++-- frame/balances/src/benchmarking.rs | 5 +- frame/balances/src/impl_currency.rs | 57 ++++++++++--------- frame/balances/src/impl_fungible.rs | 22 +++---- frame/balances/src/lib.rs | 50 +++++++++------- frame/balances/src/tests/currency_tests.rs | 6 +- frame/balances/src/types.rs | 7 ++- node/src/command.rs | 7 ++- runtime/src/chain_extensions.rs | 1 - runtime/src/lib.rs | 2 - 12 files changed, 99 insertions(+), 83 deletions(-) diff --git a/client/consensus/manual-seal/src/consensus/babe.rs b/client/consensus/manual-seal/src/consensus/babe.rs index bb0984a..a12b953 100644 --- a/client/consensus/manual-seal/src/consensus/babe.rs +++ b/client/consensus/manual-seal/src/consensus/babe.rs @@ -127,7 +127,7 @@ where authorities: Vec<(AuthorityId, BabeAuthorityWeight)>, ) -> Result { if authorities.is_empty() { - return Err(Error::StringError("Cannot supply empty authority set!".into())) + return Err(Error::StringError("Cannot supply empty authority set!".into())); } let config = sc_consensus_babe::configuration(&*client)?; @@ -277,14 +277,15 @@ where // manually hard code epoch descriptor epoch_descriptor = match epoch_descriptor { - ViableEpochDescriptor::Signaled(identifier, _header) => + ViableEpochDescriptor::Signaled(identifier, _header) => { ViableEpochDescriptor::Signaled( identifier, EpochHeader { start_slot: slot, end_slot: (*slot * self.config.epoch_length).into(), }, - ), + ) + }, _ => unreachable!( "we're not in the authorities, so this isn't the genesis epoch; qed" ), diff --git a/client/consensus/manual-seal/src/rpc.rs b/client/consensus/manual-seal/src/rpc.rs index d719179..29abae6 100644 --- a/client/consensus/manual-seal/src/rpc.rs +++ b/client/consensus/manual-seal/src/rpc.rs @@ -170,7 +170,7 @@ where if height <= best_number { return Err(JsonRpseeError::Custom( "Target height is lower than current best height".into(), - )) + )); } let diff = height - best_number; @@ -200,7 +200,7 @@ where if height >= best_number { return Err(JsonRpseeError::Custom( "Target height is higher than current best height".into(), - )) + )); } let diff = best_number - height; diff --git a/client/consensus/manual-seal/src/seal_block.rs b/client/consensus/manual-seal/src/seal_block.rs index 390c41b..fcb6cd6 100644 --- a/client/consensus/manual-seal/src/seal_block.rs +++ b/client/consensus/manual-seal/src/seal_block.rs @@ -74,15 +74,16 @@ pub async fn seal_block( { let future = async { if pool.status().ready == 0 && !create_empty { - return Err(Error::EmptyTransactionPool) + return Err(Error::EmptyTransactionPool); } // get the header to build this new block on. // use the parent_hash supplied via `EngineCommand` // or fetch the best_block. let parent = match parent_hash { - Some(hash) => - client.header(hash)?.ok_or_else(|| Error::BlockNotFound(format!("{}", hash)))?, + Some(hash) => { + client.header(hash)?.ok_or_else(|| Error::BlockNotFound(format!("{}", hash)))? + }, None => select_chain.best_chain().await?, }; @@ -113,7 +114,7 @@ pub async fn seal_block( .await?; if proposal.block.extrinsics().len() == inherents_len && !create_empty { - return Err(Error::EmptyTransactionPool) + return Err(Error::EmptyTransactionPool); } let (header, body) = proposal.block.deconstruct(); @@ -136,8 +137,9 @@ pub async fn seal_block( post_header.digest_mut().logs.extend(params.post_digests.iter().cloned()); match block_import.import_block(params).await? { - ImportResult::Imported(aux) => - Ok(CreatedBlock { hash: ::Header::hash(&post_header), aux }), + ImportResult::Imported(aux) => { + Ok(CreatedBlock { hash: ::Header::hash(&post_header), aux }) + }, other => Err(other.into()), } }; diff --git a/frame/balances/src/benchmarking.rs b/frame/balances/src/benchmarking.rs index ac5f7a6..4c53732 100644 --- a/frame/balances/src/benchmarking.rs +++ b/frame/balances/src/benchmarking.rs @@ -159,8 +159,9 @@ mod benchmarks { // and reap this user. let recipient: T::AccountId = account("recipient", 0, SEED); let recipient_lookup = T::Lookup::unlookup(recipient.clone()); - let transfer_amount = - existential_deposit.saturating_mul((ED_MULTIPLIER - 1).into()).saturating_add(1u32.into()); + let transfer_amount = existential_deposit + .saturating_mul((ED_MULTIPLIER - 1).into()) + .saturating_add(1u32.into()); #[extrinsic_call] _(RawOrigin::Root, source_lookup, recipient_lookup, transfer_amount); diff --git a/frame/balances/src/impl_currency.rs b/frame/balances/src/impl_currency.rs index baa153c..533521f 100644 --- a/frame/balances/src/impl_currency.rs +++ b/frame/balances/src/impl_currency.rs @@ -215,7 +215,7 @@ where // Check if `value` amount of free balance can be slashed from `who`. fn can_slash(who: &T::AccountId, value: Self::Balance) -> bool { if value.is_zero() { - return true + return true; } Self::free_balance(who) >= value } @@ -244,7 +244,7 @@ where // Is a no-op if amount to be burned is zero. fn burn(mut amount: Self::Balance) -> Self::PositiveImbalance { if amount.is_zero() { - return PositiveImbalance::zero() + return PositiveImbalance::zero(); } >::mutate(|issued| { *issued = issued.checked_sub(&amount).unwrap_or_else(|| { @@ -260,7 +260,7 @@ where // Is a no-op if amount to be issued it zero. fn issue(mut amount: Self::Balance) -> Self::NegativeImbalance { if amount.is_zero() { - return NegativeImbalance::zero() + return NegativeImbalance::zero(); } >::mutate(|issued| { *issued = issued.checked_add(&amount).unwrap_or_else(|| { @@ -285,7 +285,7 @@ where new_balance: T::Balance, ) -> DispatchResult { if amount.is_zero() { - return Ok(()) + return Ok(()); } ensure!(new_balance >= Self::account(who).frozen, Error::::LiquidityRestrictions); Ok(()) @@ -300,7 +300,7 @@ where existence_requirement: ExistenceRequirement, ) -> DispatchResult { if value.is_zero() || transactor == dest { - return Ok(()) + return Ok(()); } let keep_alive = match existence_requirement { ExistenceRequirement::KeepAlive => Preserve, @@ -321,10 +321,10 @@ where /// inconsistent or `can_slash` wasn't used appropriately. fn slash(who: &T::AccountId, value: Self::Balance) -> (Self::NegativeImbalance, Self::Balance) { if value.is_zero() { - return (NegativeImbalance::zero(), Zero::zero()) + return (NegativeImbalance::zero(), Zero::zero()); } if Self::total_balance(who).is_zero() { - return (NegativeImbalance::zero(), value) + return (NegativeImbalance::zero(), value); } let result = match Self::try_mutate_account_handling_dust( @@ -361,7 +361,7 @@ where value: Self::Balance, ) -> Result { if value.is_zero() { - return Ok(PositiveImbalance::zero()) + return Ok(PositiveImbalance::zero()); } Self::try_mutate_account_handling_dust( @@ -386,7 +386,7 @@ where /// - `value` is so large it would cause the balance of `who` to overflow. fn deposit_creating(who: &T::AccountId, value: Self::Balance) -> Self::PositiveImbalance { if value.is_zero() { - return Self::PositiveImbalance::zero() + return Self::PositiveImbalance::zero(); } Self::try_mutate_account_handling_dust( @@ -419,7 +419,7 @@ where liveness: ExistenceRequirement, ) -> result::Result { if value.is_zero() { - return Ok(NegativeImbalance::zero()) + return Ok(NegativeImbalance::zero()); } Self::try_mutate_account_handling_dust( @@ -487,11 +487,11 @@ where /// Always `true` if value to be reserved is zero. fn can_reserve(who: &T::AccountId, value: Self::Balance) -> bool { if value.is_zero() { - return true + return true; } Self::account(who).free.checked_sub(&value).map_or(false, |new_balance| { - new_balance >= T::ExistentialDeposit::get() && - Self::ensure_can_withdraw(who, value, WithdrawReasons::RESERVE, new_balance) + new_balance >= T::ExistentialDeposit::get() + && Self::ensure_can_withdraw(who, value, WithdrawReasons::RESERVE, new_balance) .is_ok() }) } @@ -505,7 +505,7 @@ where /// Is a no-op if value to be reserved is zero. fn reserve(who: &T::AccountId, value: Self::Balance) -> DispatchResult { if value.is_zero() { - return Ok(()) + return Ok(()); } Self::try_mutate_account_handling_dust(who, |account, _| -> DispatchResult { @@ -527,10 +527,10 @@ where /// NOTE: returns amount value which wasn't successfully unreserved. fn unreserve(who: &T::AccountId, value: Self::Balance) -> Self::Balance { if value.is_zero() { - return Zero::zero() + return Zero::zero(); } if Self::total_balance(who).is_zero() { - return value + return value; } let actual = match Self::mutate_account_handling_dust(who, |account| { @@ -546,7 +546,7 @@ where // This should never happen since we don't alter the total amount in the account. // If it ever does, then we should fail gracefully though, indicating that nothing // could be done. - return value + return value; }, }; @@ -563,10 +563,10 @@ where value: Self::Balance, ) -> (Self::NegativeImbalance, Self::Balance) { if value.is_zero() { - return (NegativeImbalance::zero(), Zero::zero()) + return (NegativeImbalance::zero(), Zero::zero()); } if Self::total_balance(who).is_zero() { - return (NegativeImbalance::zero(), value) + return (NegativeImbalance::zero(), value); } // NOTE: `mutate_account` may fail if it attempts to reduce the balance to the point that an @@ -634,7 +634,7 @@ where value: Self::Balance, ) -> DispatchResult { if value.is_zero() { - return Ok(()) + return Ok(()); } Reserves::::try_mutate(who, |reserves| -> DispatchResult { @@ -663,7 +663,7 @@ where value: Self::Balance, ) -> Self::Balance { if value.is_zero() { - return Zero::zero() + return Zero::zero(); } Reserves::::mutate_exists(who, |maybe_reserves| -> Self::Balance { @@ -710,7 +710,7 @@ where value: Self::Balance, ) -> (Self::NegativeImbalance, Self::Balance) { if value.is_zero() { - return (NegativeImbalance::zero(), Zero::zero()) + return (NegativeImbalance::zero(), Zero::zero()); } Reserves::::mutate(who, |reserves| -> (Self::NegativeImbalance, Self::Balance) { @@ -749,15 +749,16 @@ where status: Status, ) -> Result { if value.is_zero() { - return Ok(Zero::zero()) + return Ok(Zero::zero()); } if slashed == beneficiary { return match status { Status::Free => Ok(Self::unreserve_named(id, slashed, value)), - Status::Reserved => - Ok(value.saturating_sub(Self::reserved_balance_named(id, slashed))), - } + Status::Reserved => { + Ok(value.saturating_sub(Self::reserved_balance_named(id, slashed))) + }, + }; } Reserves::::try_mutate(slashed, |reserves| -> Result { @@ -855,7 +856,7 @@ where ) { if reasons.is_empty() || amount.is_zero() { Self::remove_lock(id, who); - return + return; } let mut new_lock = Some(BalanceLock { id, amount, reasons: reasons.into() }); @@ -878,7 +879,7 @@ where reasons: WithdrawReasons, ) { if amount.is_zero() || reasons.is_empty() { - return + return; } let mut new_lock = Some(BalanceLock { id, amount, reasons: reasons.into() }); let mut locks = Self::locks(who) diff --git a/frame/balances/src/impl_fungible.rs b/frame/balances/src/impl_fungible.rs index f8f8fe1..f56caec 100644 --- a/frame/balances/src/impl_fungible.rs +++ b/frame/balances/src/impl_fungible.rs @@ -74,11 +74,11 @@ impl, I: 'static> fungible::Inspect for Pallet provenance: Provenance, ) -> DepositConsequence { if amount.is_zero() { - return DepositConsequence::Success + return DepositConsequence::Success; } if provenance == Minted && TotalIssuance::::get().checked_add(&amount).is_none() { - return DepositConsequence::Overflow + return DepositConsequence::Overflow; } let account = Self::account(who); @@ -103,11 +103,11 @@ impl, I: 'static> fungible::Inspect for Pallet amount: Self::Balance, ) -> WithdrawConsequence { if amount.is_zero() { - return WithdrawConsequence::Success + return WithdrawConsequence::Success; } if TotalIssuance::::get().checked_sub(&amount).is_none() { - return WithdrawConsequence::Underflow + return WithdrawConsequence::Underflow; } let account = Self::account(who); @@ -118,7 +118,7 @@ impl, I: 'static> fungible::Inspect for Pallet let liquid = Self::reducible_balance(who, Expendable, Polite); if amount > liquid { - return WithdrawConsequence::Frozen + return WithdrawConsequence::Frozen; } // Provider restriction - total account balance cannot be reduced to zero if it cannot @@ -130,7 +130,7 @@ impl, I: 'static> fungible::Inspect for Pallet if frame_system::Pallet::::can_dec_provider(who) { WithdrawConsequence::ReducedToZero(new_free_balance) } else { - return WithdrawConsequence::WouldDie + return WithdrawConsequence::WouldDie; } } else { WithdrawConsequence::Success @@ -140,7 +140,7 @@ impl, I: 'static> fungible::Inspect for Pallet // Eventual free funds must be no less than the frozen balance. if new_total_balance < account.frozen { - return WithdrawConsequence::Frozen + return WithdrawConsequence::Frozen; } success @@ -232,11 +232,11 @@ impl, I: 'static> fungible::InspectHold for Pallet bool { if frame_system::Pallet::::providers(who) == 0 { - return false + return false; } let holds = Holds::::get(who); if holds.is_full() && !holds.iter().any(|x| &x.id == reason) { - return false + return false; } true } @@ -302,7 +302,7 @@ impl, I: 'static> fungible::InspectFreeze for Pallet< impl, I: 'static> fungible::MutateFreeze for Pallet { fn set_freeze(id: &Self::Id, who: &T::AccountId, amount: Self::Balance) -> DispatchResult { if amount.is_zero() { - return Self::thaw(id, who) + return Self::thaw(id, who); } let mut locks = Freezes::::get(who); if let Some(i) = locks.iter_mut().find(|x| &x.id == id) { @@ -317,7 +317,7 @@ impl, I: 'static> fungible::MutateFreeze for Pallet DispatchResult { if amount.is_zero() { - return Ok(()) + return Ok(()); } let mut locks = Freezes::::get(who); if let Some(i) = locks.iter_mut().find(|x| &x.id == id) { diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index de15bf1..085f963 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -205,7 +205,10 @@ type AccountIdLookupOf = <::Lookup as StaticLookup #[frame_support::pallet] pub mod pallet { use super::*; - use frame_support::{pallet_prelude::*, traits::{fungible::Credit, tokens::Precision}}; + use frame_support::{ + pallet_prelude::*, + traits::{fungible::Credit, tokens::Precision}, + }; use frame_system::pallet_prelude::*; pub type CreditOf = Credit<::AccountId, Pallet>; @@ -669,21 +672,22 @@ pub mod pallet { let existential_deposit = T::ExistentialDeposit::get(); // First we try to modify the account's balance to the forced balance. - let (old_free, old_reserved, new_free, new_reserved) = Self::mutate_account_handling_dust(&who, |account| { - let old_free = account.free; - let old_reserved = account.reserved; + let (old_free, old_reserved, new_free, new_reserved) = + Self::mutate_account_handling_dust(&who, |account| { + let old_free = account.free; + let old_reserved = account.reserved; - let wipeout = new_free < existential_deposit; + let wipeout = new_free < existential_deposit; - let new_free = if wipeout { Zero::zero() } else { new_free }; - // No change on reserved_balance unless account is wiped out. - let new_reserved = if wipeout { Zero::zero() } else { old_reserved }; + let new_free = if wipeout { Zero::zero() } else { new_free }; + // No change on reserved_balance unless account is wiped out. + let new_reserved = if wipeout { Zero::zero() } else { old_reserved }; - account.free = new_free; - account.reserved = new_reserved; - - (old_free, old_reserved, new_free, new_reserved) - })?; + account.free = new_free; + account.reserved = new_reserved; + + (old_free, old_reserved, new_free, new_reserved) + })?; // This will adjust the total issuance, which was not done by the `mutate_account` // above. @@ -806,7 +810,7 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { ensure_signed(origin)?; if who.is_empty() { - return Ok(Pays::Yes.into()) + return Ok(Pays::Yes.into()); } let mut upgrade_count = 0; for i in &who { @@ -889,7 +893,7 @@ pub mod pallet { pub fn ensure_upgraded(who: &T::AccountId) -> bool { let mut a = T::AccountStore::get(who); if a.flags.is_new_logic() { - return false + return false; } a.flags.set_new_logic(); if !a.reserved.is_zero() && a.frozen.is_zero() { @@ -913,7 +917,7 @@ pub mod pallet { Ok(()) }); Self::deposit_event(Event::Upgraded { who: who.clone() }); - return true + return true; } /// Get the free balance of an account. @@ -1236,7 +1240,7 @@ pub mod pallet { status: Status, ) -> Result { if value.is_zero() { - return Ok(Zero::zero()) + return Ok(Zero::zero()); } let max = >::reducible_total_balance_on_hold( @@ -1251,7 +1255,7 @@ pub mod pallet { return match status { Status::Free => Ok(actual.saturating_sub(Self::unreserve(slashed, actual))), Status::Reserved => Ok(actual), - } + }; } let ((_, maybe_dust_1), maybe_dust_2) = Self::try_mutate_account( @@ -1260,16 +1264,18 @@ pub mod pallet { ensure!(!is_new, Error::::DeadAccount); Self::try_mutate_account(slashed, |from_account, _| -> DispatchResult { match status { - Status::Free => + Status::Free => { to_account.free = to_account .free .checked_add(&actual) - .ok_or(ArithmeticError::Overflow)?, - Status::Reserved => + .ok_or(ArithmeticError::Overflow)? + }, + Status::Reserved => { to_account.reserved = to_account .reserved .checked_add(&actual) - .ok_or(ArithmeticError::Overflow)?, + .ok_or(ArithmeticError::Overflow)? + }, } from_account.reserved.saturating_reduce(actual); Ok(()) diff --git a/frame/balances/src/tests/currency_tests.rs b/frame/balances/src/tests/currency_tests.rs index 8e3f67e..e25b122 100644 --- a/frame/balances/src/tests/currency_tests.rs +++ b/frame/balances/src/tests/currency_tests.rs @@ -20,7 +20,11 @@ use super::*; use crate::NegativeImbalance; use frame_support::traits::{ - BalanceStatus::{Free, Reserved}, Currency, ExistenceRequirement::{self, AllowDeath}, Hooks, LockIdentifier, LockableCurrency, NamedReservableCurrency, ReservableCurrency, WithdrawReasons + BalanceStatus::{Free, Reserved}, + Currency, + ExistenceRequirement::{self, AllowDeath}, + Hooks, LockIdentifier, LockableCurrency, NamedReservableCurrency, ReservableCurrency, + WithdrawReasons, }; const ID_1: LockIdentifier = *b"1 "; diff --git a/frame/balances/src/types.rs b/frame/balances/src/types.rs index db007de..3878802 100644 --- a/frame/balances/src/types.rs +++ b/frame/balances/src/types.rs @@ -20,7 +20,10 @@ use crate::{Config, CreditOf, Event, Pallet}; use codec::{Decode, Encode, MaxEncodedLen}; use core::ops::BitOr; -use frame_support::{traits::{Imbalance, LockIdentifier, OnUnbalanced, WithdrawReasons}, RuntimeDebug}; +use frame_support::{ + traits::{Imbalance, LockIdentifier, OnUnbalanced, WithdrawReasons}, + RuntimeDebug, +}; use scale_info::TypeInfo; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; @@ -53,7 +56,7 @@ impl BitOr for Reasons { type Output = Reasons; fn bitor(self, other: Reasons) -> Reasons { if self == other { - return self + return self; } Reasons::All } diff --git a/node/src/command.rs b/node/src/command.rs index 62dea5e..1de970a 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -109,7 +109,7 @@ pub fn run() -> sc_cli::Result<()> { "Runtime benchmarking wasn't enabled when building the node. \ You can enable it with `--features runtime-benchmarks`." .into(), - ) + ); } cmd.run::(config) @@ -128,8 +128,9 @@ pub fn run() -> sc_cli::Result<()> { }, BenchmarkCmd::Overhead(_) => Err("Benchmark overhead not supported.".into()), BenchmarkCmd::Extrinsic(_) => Err("Benchmark extrinsic not supported.".into()), - BenchmarkCmd::Machine(cmd) => - cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone()), + BenchmarkCmd::Machine(cmd) => { + cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone()) + }, } }) }, diff --git a/runtime/src/chain_extensions.rs b/runtime/src/chain_extensions.rs index dd73d52..2e210d0 100644 --- a/runtime/src/chain_extensions.rs +++ b/runtime/src/chain_extensions.rs @@ -6,7 +6,6 @@ use pallet_contracts::chain_extension::RegisteredChainExtension; // Following impls defines chain extension IDs. - impl RegisteredChainExtension for AssetsExtension { const ID: u16 = 2; } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 6f3ad69..3d0e0a0 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -127,7 +127,6 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { /// 2^128-1 Relay chain token (KSM) pub type AssetId = u128; - /// The version information used to identify this runtime when compiled natively. #[cfg(feature = "std")] pub fn native_version() -> NativeVersion { @@ -155,7 +154,6 @@ pub const MILLIUNIT: Balance = 1_000 * MICROUNIT; pub const UNIT: Balance = 1_000 * MILLIUNIT; pub const EXISTENTIAL_DEPOSIT: Balance = MILLIUNIT; - pub const STORAGE_BYTE_FEE: Balance = 100 * MICROUNIT; /// Charge fee for stored bytes and items.