Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Make ED of zero (kind of) work #13655

Merged
merged 13 commits into from
Mar 24, 2023
16 changes: 10 additions & 6 deletions frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ pub mod pallet {
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
let who = T::Lookup::lookup(who)?;
let existential_deposit = T::ExistentialDeposit::get();
let existential_deposit = Self::ed();

let wipeout = new_free < existential_deposit;
let new_free = if wipeout { Zero::zero() } else { new_free };
Expand Down Expand Up @@ -716,7 +716,7 @@ pub mod pallet {
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
let who = T::Lookup::lookup(who)?;
let existential_deposit = T::ExistentialDeposit::get();
let existential_deposit = Self::ed();

let wipeout = new_free < existential_deposit;
let new_free = if wipeout { Zero::zero() } else { new_free };
Expand All @@ -742,6 +742,9 @@ pub mod pallet {
}

impl<T: Config<I>, I: 'static> Pallet<T, I> {
fn ed() -> T::Balance {
T::ExistentialDeposit::get()
}
/// Ensure the account `who` is using the new logic.
///
/// Returns `true` if the account did get upgraded, `false` if it didn't need upgrading.
Expand All @@ -756,7 +759,7 @@ pub mod pallet {
// Gah!! We have a non-zero reserve balance but no provider refs :(
// This shouldn't practically happen, but we need a failsafe anyway: let's give
// them enough for an ED.
a.free = a.free.min(T::ExistentialDeposit::get());
a.free = a.free.min(Self::ed());
system::Pallet::<T>::inc_providers(who);
}
let _ = system::Pallet::<T>::inc_consumers(who).defensive();
Expand Down Expand Up @@ -885,13 +888,14 @@ pub mod pallet {
let result = T::AccountStore::try_mutate_exists(who, |maybe_account| {
let is_new = maybe_account.is_none();
let mut account = maybe_account.take().unwrap_or_default();
let did_provide = account.free >= T::ExistentialDeposit::get();
let did_provide =
account.free >= Self::ed() && frame_system::Pallet::<T>::providers(who) > 0;
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
let did_consume =
!is_new && (!account.reserved.is_zero() || !account.frozen.is_zero());

let result = f(&mut account, is_new)?;

let does_provide = account.free >= T::ExistentialDeposit::get();
let does_provide = account.free >= Self::ed();
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
let does_consume = !account.reserved.is_zero() || !account.frozen.is_zero();

if !did_provide && does_provide {
Expand Down Expand Up @@ -930,7 +934,7 @@ pub mod pallet {
//
// We should never be dropping if reserved is non-zero. Reserved being non-zero
// should imply that we have a consumer ref, so this is economically safe.
let ed = T::ExistentialDeposit::get();
let ed = Self::ed();
let maybe_dust = if account.free < ed && account.reserved.is_zero() {
if account.free.is_zero() {
None
Expand Down
2 changes: 1 addition & 1 deletion frame/balances/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ parameter_types! {
frame_system::limits::BlockWeights::simple_max(
frame_support::weights::Weight::from_parts(1024, u64::MAX),
);
pub static ExistentialDeposit: u64 = 0;
pub static ExistentialDeposit: u64 = 1;
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
Expand Down
2 changes: 1 addition & 1 deletion frame/vesting/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ parameter_types! {
pub const MinVestedTransfer: u64 = 256 * 2;
pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons =
WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE);
pub static ExistentialDeposit: u64 = 0;
pub static ExistentialDeposit: u64 = 1;
}
impl Config for Test {
type BlockNumberToBalance = Identity;
Expand Down