From 18aee34680f80e18b40e42ed41dd52223d9b7282 Mon Sep 17 00:00:00 2001 From: Kailai Wang Date: Fri, 9 Aug 2024 13:24:52 +0000 Subject: [PATCH 1/2] Add burn extrinsic --- pallets/account-fix/src/lib.rs | 36 +++++++++++++++++++++++++--------- runtime/litentry/src/lib.rs | 8 +++++++- runtime/rococo/src/lib.rs | 7 ++++++- 3 files changed, 40 insertions(+), 11 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 7b7289a739..b87ba4c079 100644 --- a/runtime/litentry/src/lib.rs +++ b/runtime/litentry/src/lib.rs @@ -648,6 +648,7 @@ impl pallet_identity::Config for Runtime { impl pallet_account_fix::Config for Runtime { type Currency = Balances; + type BurnOrigin = EnsureRootOrTwoThirdsTechnicalCommittee; } parameter_types! { @@ -976,7 +977,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 aac01af3f7..20de9d1b84 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -821,6 +821,7 @@ impl pallet_sudo::Config for Runtime { impl pallet_account_fix::Config for Runtime { type Currency = Balances; + type BurnOrigin = EnsureRootOrTwoThirdsTechnicalCommittee; } parameter_types! { @@ -1335,8 +1336,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 From ef7f44a7137faba49f6fdbfe5fe5436f01b1eb6e Mon Sep 17 00:00:00 2001 From: Kailai Wang Date: Fri, 9 Aug 2024 13:33:30 +0000 Subject: [PATCH 2/2] fix rococo try-runtime --- runtime/rococo/src/migration/mod.rs | 1 - 1 file changed, 1 deletion(-) 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; }