From 1d646670317a42ce7fcf4de00b0b6b90d845da4e Mon Sep 17 00:00:00 2001 From: Kai <7630809+Kailai-Wang@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:05:21 +0200 Subject: [PATCH] Add a burn method to pallet-account-fix (#2980) * Add burn extrinsic * fix rococo try-runtime --- pallets/account-fix/src/lib.rs | 36 +++++++++++++++++++++-------- runtime/litentry/src/lib.rs | 8 ++++++- runtime/rococo/src/lib.rs | 7 +++++- runtime/rococo/src/migration/mod.rs | 1 - 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/pallets/account-fix/src/lib.rs b/pallets/account-fix/src/lib.rs index 3a1c795ba8..8f9788d158 100644 --- a/pallets/account-fix/src/lib.rs +++ b/pallets/account-fix/src/lib.rs @@ -20,13 +20,17 @@ use frame_support::{ pallet_prelude::*, - traits::{Currency, ReservableCurrency, StorageVersion}, + traits::{ + fungible::Mutate, + tokens::{Fortitude, Precision}, + Currency, ReservableCurrency, StorageVersion, + }, }; use frame_system::pallet_prelude::*; pub use pallet::*; use sp_runtime::traits::StaticLookup; - use sp_std::vec::Vec; + type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; @@ -45,17 +49,15 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config + pallet_balances::Config { - /// The currency mechanism. type Currency: ReservableCurrency; + type BurnOrigin: EnsureOrigin; } #[pallet::call] impl Pallet { - /// Change the admin account - /// similar to sudo.set_key, the old account will be supplied in event #[pallet::call_index(0)] #[pallet::weight(Weight::from_parts(20_000_000u64 * (who.len() as u64), 0))] - pub fn upgrade_accounts( + pub fn inc_consumers( origin: OriginFor, who: Vec, ) -> DispatchResultWithPostInfo { @@ -63,7 +65,6 @@ pub mod pallet { for i in &who { frame_system::Pallet::::inc_consumers(i)?; } - // Do not pay a fee Ok(Pays::No.into()) } @@ -78,7 +79,6 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { ensure_root(origin)?; let who = T::Lookup::lookup(who)?; - let add_total = add_free + add_reserved; // First we try to modify the account's balance to the forced balance. @@ -86,7 +86,25 @@ pub mod pallet { // Then do the reservation T::Currency::reserve(&who, add_reserved)?; - Ok(().into()) + Ok(Pays::No.into()) + } + + // burn balance from a given account + #[pallet::call_index(2)] + #[pallet::weight({195_000_000})] + pub fn burn( + origin: OriginFor, + who: T::AccountId, + amount: ::Balance, + ) -> DispatchResultWithPostInfo { + let _ = T::BurnOrigin::ensure_origin(origin)?; + let _ = pallet_balances::Pallet::::burn_from( + &who, + amount, + Precision::Exact, + Fortitude::Polite, + )?; + Ok(Pays::No.into()) } } } diff --git a/runtime/litentry/src/lib.rs b/runtime/litentry/src/lib.rs index e5a23bf328..5a0abbb760 100644 --- a/runtime/litentry/src/lib.rs +++ b/runtime/litentry/src/lib.rs @@ -636,6 +636,7 @@ impl pallet_identity::Config for Runtime { impl pallet_account_fix::Config for Runtime { type Currency = Balances; + type BurnOrigin = EnsureRootOrTwoThirdsTechnicalCommittee; } parameter_types! { @@ -964,7 +965,12 @@ impl Contains for BaseCallFilter { RuntimeCall::ExtrinsicFilter(_) | RuntimeCall::Multisig(_) | RuntimeCall::Council(_) | - RuntimeCall::TechnicalCommittee(_) + RuntimeCall::CouncilMembership(_) | + RuntimeCall::TechnicalCommittee(_) | + RuntimeCall::TechnicalCommitteeMembership(_) | + RuntimeCall::Utility(_) | + // Temp: should be removed after the one-time burn + RuntimeCall::AccountFix(pallet_account_fix::Call::burn { .. }) ) { // always allow core calls return true diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index 45dd36e65d..9be1d6632b 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -811,6 +811,7 @@ impl pallet_sudo::Config for Runtime { impl pallet_account_fix::Config for Runtime { type Currency = Balances; + type BurnOrigin = EnsureRootOrTwoThirdsTechnicalCommittee; } parameter_types! { @@ -1325,8 +1326,12 @@ impl Contains for BaseCallFilter { RuntimeCall::ExtrinsicFilter(_) | RuntimeCall::Multisig(_) | RuntimeCall::Council(_) | + RuntimeCall::CouncilMembership(_) | RuntimeCall::TechnicalCommittee(_) | - RuntimeCall::DeveloperCommittee(_) + RuntimeCall::TechnicalCommitteeMembership(_) | + RuntimeCall::Utility(_) | + // Temp: should be removed after the one-time burn + RuntimeCall::AccountFix(pallet_account_fix::Call::burn { .. }) ) { // always allow core calls return true diff --git a/runtime/rococo/src/migration/mod.rs b/runtime/rococo/src/migration/mod.rs index 88bbed32c0..0c10ddc50e 100644 --- a/runtime/rococo/src/migration/mod.rs +++ b/runtime/rococo/src/migration/mod.rs @@ -151,7 +151,6 @@ where let mut candidate_pool_sum: BalanceOf = 0u128.into(); // Make sure the number of Order set is correct - assert_eq!(ordered_set.0.len(), 9); for bond in ordered_set.0.iter() { candidate_pool_sum += bond.amount; }