Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate pallet-balances to umbrella style #6977

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 1 addition & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cumulus/bin/pov-validator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ sc-executor.workspace = true
sp-core.workspace = true
sp-io.workspace = true
sp-maybe-compressed-blob.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true

[lints]
workspace = true
32 changes: 7 additions & 25 deletions substrate/frame/balances/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,28 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { features = ["derive", "max-encoded-len"], workspace = true }
docify = { workspace = true }
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
log = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }
scale-info = { features = ["derive"], workspace = true }
sp-runtime = { workspace = true }

[dev-dependencies]
frame-support = { features = ["experimental"], workspace = true, default-features = true }
pallet-transaction-payment = { workspace = true, default-features = true }
paste = { workspace = true, default-features = true }
sp-core = { workspace = true, default-features = true }
sp-io = { workspace = true, default-features = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-transaction-payment/std",
"frame/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
]
# Enable support for setting the existential deposit to zero.
insecure_zero_ed = []
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"frame/runtime-benchmarks",
"pallet-transaction-payment/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame/try-runtime",
"pallet-transaction-payment/try-runtime",
"sp-runtime/try-runtime",
]

# Enable support for setting the existential deposit to zero.
insecure_zero_ed = []
9 changes: 2 additions & 7 deletions substrate/frame/balances/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@

#![cfg(feature = "runtime-benchmarks")]

use super::*;
use crate::Pallet as Balances;

use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
use sp_runtime::traits::Bounded;
use types::ExtraFlags;
use super::{Pallet as Balances, *};
use frame::benchmarking::prelude::*;

const SEED: u32 = 0;
// existential deposit multiplier
Expand Down
35 changes: 14 additions & 21 deletions substrate/frame/balances/src/impl_currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,21 @@
//! Note that `WithdrawReasons` are intentionally not used for anything in this implementation and
//! are expected to be removed in the near future, once migration to `fungible::*` traits is done.

pub use imbalances::{NegativeImbalance, PositiveImbalance};

use super::*;
use frame_support::{
ensure,
pallet_prelude::DispatchResult,
traits::{
tokens::{fungible, BalanceStatus as Status, Fortitude::Polite, Precision::BestEffort},
Currency, DefensiveSaturating, ExistenceRequirement,
ExistenceRequirement::AllowDeath,
Get, Imbalance, InspectLockableCurrency, LockIdentifier, LockableCurrency,
NamedReservableCurrency, ReservableCurrency, SignedImbalance, TryDrop, WithdrawReasons,
},
use core::cmp;
use frame::traits::{
tokens::{imbalance::TryMerge, Precision::*},
DefensiveSaturating, Imbalance, InspectLockableCurrency, LockIdentifier, LockableCurrency,
NamedReservableCurrency, SameOrOther, SignedImbalance, TryDrop, WithdrawReasons,
};
use frame_system::pallet_prelude::BlockNumberFor;
pub use imbalances::{NegativeImbalance, PositiveImbalance};
use sp_runtime::traits::Bounded;
use ExistenceRequirement::*;

// wrapping these imbalances in a private module is necessary to ensure absolute privacy
// of the inner member.
mod imbalances {
use super::*;
use core::mem;
use frame_support::traits::{tokens::imbalance::TryMerge, SameOrOther};

/// Opaque, move-only struct with private fields that serves as a token denoting that
/// funds have been created without any equal and opposite accounting.
Expand Down Expand Up @@ -70,7 +63,7 @@ mod imbalances {
}

impl<T: Config<I>, I: 'static> TryDrop for PositiveImbalance<T, I> {
fn try_drop(self) -> result::Result<(), Self> {
fn try_drop(self) -> Result<(), Self> {
self.drop_zero()
}
}
Expand All @@ -87,7 +80,7 @@ mod imbalances {
fn zero() -> Self {
Self(Zero::zero())
}
fn drop_zero(self) -> result::Result<(), Self> {
fn drop_zero(self) -> Result<(), Self> {
if self.0.is_zero() {
Ok(())
} else {
Expand Down Expand Up @@ -140,7 +133,7 @@ mod imbalances {
}

impl<T: Config<I>, I: 'static> TryDrop for NegativeImbalance<T, I> {
fn try_drop(self) -> result::Result<(), Self> {
fn try_drop(self) -> Result<(), Self> {
self.drop_zero()
}
}
Expand All @@ -157,7 +150,7 @@ mod imbalances {
fn zero() -> Self {
Self(Zero::zero())
}
fn drop_zero(self) -> result::Result<(), Self> {
fn drop_zero(self) -> Result<(), Self> {
if self.0.is_zero() {
Ok(())
} else {
Expand Down Expand Up @@ -366,7 +359,7 @@ where
|account, _is_new| -> Result<(Self::NegativeImbalance, Self::Balance), DispatchError> {
// Best value is the most amount we can slash following liveness rules.
let ed = T::ExistentialDeposit::get();
let actual = match system::Pallet::<T>::can_dec_provider(who) {
let actual = match frame_system::Pallet::<T>::can_dec_provider(who) {
true => value.min(account.free),
false => value.min(account.free.saturating_sub(ed)),
};
Expand Down Expand Up @@ -451,7 +444,7 @@ where
value: Self::Balance,
reasons: WithdrawReasons,
liveness: ExistenceRequirement,
) -> result::Result<Self::NegativeImbalance, DispatchError> {
) -> Result<Self::NegativeImbalance, DispatchError> {
if value.is_zero() {
return Ok(NegativeImbalance::zero())
}
Expand Down
9 changes: 5 additions & 4 deletions substrate/frame/balances/src/impl_fungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
// limitations under the License.

//! Implementation of `fungible` traits for Balances pallet.

use super::*;
use frame_support::traits::{
use frame::traits::{
tokens::{
Fortitude,
Preservation::{self, Preserve, Protect},
Provenance::{self, Minted},
DepositConsequence, Preservation,
Provenance::{self, *},
WithdrawConsequence,
},
AccountTouch,
};
Expand Down
Loading
Loading