Skip to content

Commit

Permalink
fix: remove existential deposit (#4243)
Browse files Browse the repository at this point in the history
  • Loading branch information
dandanlen authored Nov 15, 2023
1 parent 4b82a20 commit 5fdba98
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 81 deletions.
1 change: 0 additions & 1 deletion state-chain/cf-integration-tests/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ impl Cli {
}

pub fn register_as_validator(account: &NodeId) {
System::inc_providers(account);
assert_ok!(<AccountRoles as AccountRoleRegistry<Runtime>>::register_account_role(
account,
AccountRole::Validator
Expand Down
5 changes: 0 additions & 5 deletions state-chain/pallets/cf-emissions/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ impl system::Config for Test {
impl_mock_chainflip!(Test);
impl_mock_callback!(RuntimeOrigin);

parameter_types! {
pub const ExistentialDeposit: u128 = 10;
}

parameter_types! {
pub const BlocksPerDay: u64 = 14400;
}
Expand All @@ -94,7 +90,6 @@ impl_mock_waived_fees!(AccountId, RuntimeCall);
impl pallet_cf_flip::Config for Test {
type RuntimeEvent = RuntimeEvent;
type Balance = u128;
type ExistentialDeposit = ExistentialDeposit;
type BlocksPerDay = BlocksPerDay;
type OnAccountFunded = MockOnAccountFunded;
type WeightInfo = ();
Expand Down
32 changes: 1 addition & 31 deletions state-chain/pallets/cf-flip/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub use on_charge_transaction::FlipTransactionPayment;

use frame_support::{
ensure,
traits::{Get, HandleLifetime, Hooks, Imbalance, OnKilledAccount, SignedImbalance},
traits::{Get, Imbalance, OnKilledAccount, SignedImbalance},
};

use codec::{Decode, Encode, MaxEncodedLen};
Expand Down Expand Up @@ -62,10 +62,6 @@ pub mod pallet {
+ Debug
+ From<u128>;

/// The minimum amount required to keep an account open.
#[pallet::constant]
type ExistentialDeposit: Get<Self::Balance>;

/// Blocks per day.
#[pallet::constant]
type BlocksPerDay: Get<BlockNumberFor<Self>>;
Expand Down Expand Up @@ -149,32 +145,6 @@ pub mod pallet {
NoPendingRedemptionForThisID,
}

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
/// Reap any accounts that are below `T::ExistentialDeposit`, and burn the dust.
fn on_idle(_block_number: BlockNumberFor<T>, remaining_weight: Weight) -> Weight {
let max_accounts_to_reap = remaining_weight
.ref_time()
.checked_div(T::WeightInfo::reap_one_account().ref_time())
.unwrap_or_default();
if max_accounts_to_reap == 0 {
return Weight::zero()
}

let mut number_of_accounts_reaped = 0u64;
Account::<T>::iter()
.filter(|(_account_id, flip_account)| {
flip_account.total() < T::ExistentialDeposit::get()
})
.take(max_accounts_to_reap as usize)
.for_each(|(account_id, _flip_account)| {
let _reap_result = frame_system::Provider::<T>::killed(&account_id);
number_of_accounts_reaped += 1u64;
});
T::WeightInfo::reap_one_account().saturating_mul(number_of_accounts_reaped)
}
}

#[pallet::call]
impl<T: Config> Pallet<T> {
/// Set the PER BLOCK slashing rate.
Expand Down
5 changes: 0 additions & 5 deletions state-chain/pallets/cf-flip/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ impl frame_system::Config for Test {

impl_mock_chainflip!(Test);

parameter_types! {
pub const ExistentialDeposit: FlipBalance = 10;
}

parameter_types! {
pub const BlocksPerDay: u64 = 14400;
}
Expand All @@ -76,7 +72,6 @@ impl_mock_waived_fees!(AccountId, RuntimeCall);
impl pallet_cf_flip::Config for Test {
type RuntimeEvent = RuntimeEvent;
type Balance = FlipBalance;
type ExistentialDeposit = ExistentialDeposit;
type BlocksPerDay = BlocksPerDay;
type OnAccountFunded = MockOnAccountFunded;
type WeightInfo = ();
Expand Down
31 changes: 3 additions & 28 deletions state-chain/pallets/cf-flip/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

use super::*;
use crate::{
mock::*, Account, Bonder, Error, FlipAccount, FlipIssuance, FlipSlasher, OffchainFunds,
Reserve, SlashingRate, TotalIssuance,
mock::*, Account, Bonder, Error, FlipIssuance, FlipSlasher, OffchainFunds, Reserve,
SlashingRate, TotalIssuance,
};
use cf_primitives::FlipBalance;
use cf_traits::{AccountInfo, Bonding, Funding, Issuance, Slashing};
use frame_support::{
assert_noop,
traits::{HandleLifetime, Hooks, Imbalance},
weights::Weight,
traits::{HandleLifetime, Imbalance},
};
use quickcheck::{Arbitrary, Gen, TestResult};
use quickcheck_macros::quickcheck;
Expand Down Expand Up @@ -635,27 +634,3 @@ mod test_tx_payments {
});
}
}

#[test]
fn can_reap_dust_account() {
new_test_ext().execute_with(|| {
Account::<Test>::insert(ALICE, FlipAccount { balance: 9, bond: 0 });
Account::<Test>::insert(BOB, FlipAccount { balance: 10, bond: 0 });
Account::<Test>::insert(CHARLIE, FlipAccount { balance: 11, bond: 0 });

// Dust accounts are reaped on_idle
Flip::on_idle(1, Weight::from_parts(1_000_000_000_000, 0));

assert!(!Account::<Test>::contains_key(ALICE));
assert_eq!(Account::<Test>::get(BOB), FlipAccount { balance: 10, bond: 0 });

assert_eq!(Account::<Test>::get(CHARLIE), FlipAccount { balance: 11, bond: 0 });
System::assert_has_event(RuntimeEvent::Flip(crate::Event::AccountReaped {
who: ALICE,
dust_burned: 9,
}));
System::assert_last_event(RuntimeEvent::System(frame_system::Event::KilledAccount {
account: ALICE,
}));
});
}
6 changes: 0 additions & 6 deletions state-chain/pallets/cf-funding/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use std::time::Duration;

// Use a realistic account id for compatibility with `RegisterRedemption`.
type AccountId = AccountId32;
type Balance = u128;
type Block = frame_system::mocking::MockBlock<Test>;

// Configure a mock runtime to test the pallet.
Expand Down Expand Up @@ -68,10 +67,6 @@ parameter_types! {
pub const CeremonyRetryDelay: BlockNumberFor<Test> = 1;
}

parameter_types! {
pub const ExistentialDeposit: Balance = 10;
}

parameter_types! {
pub const BlocksPerDay: u64 = 14400;
}
Expand All @@ -82,7 +77,6 @@ impl_mock_waived_fees!(AccountId, RuntimeCall);
impl pallet_cf_flip::Config for Test {
type RuntimeEvent = RuntimeEvent;
type Balance = u128;
type ExistentialDeposit = ExistentialDeposit;
type BlocksPerDay = BlocksPerDay;
type OnAccountFunded = MockOnAccountFunded;
type WeightInfo = ();
Expand Down
4 changes: 0 additions & 4 deletions state-chain/pallets/cf-tokenholder-governance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ impl system::Config for Test {
impl_mock_chainflip!(Test);
impl_mock_ensure_witnessed_for_origin!(RuntimeOrigin);

parameter_types! {
pub const ExistentialDeposit: u128 = 10;
}

parameter_types! {
pub const BlocksPerDay: u64 = 14400;
}
Expand Down
1 change: 0 additions & 1 deletion state-chain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ impl pallet_authorship::Config for Runtime {
impl pallet_cf_flip::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = FlipBalance;
type ExistentialDeposit = ConstU128<500>;
type BlocksPerDay = ConstU32<DAYS>;
type OnAccountFunded = pallet_cf_validator::UpdateBackupMapping<Self>;
type WeightInfo = pallet_cf_flip::weights::PalletWeight<Runtime>;
Expand Down

0 comments on commit 5fdba98

Please sign in to comment.