diff --git a/runtime/common/src/crowdloan/migration.rs b/runtime/common/src/crowdloan/migration.rs index 1ba1f20e8060..2d80ff878c4a 100644 --- a/runtime/common/src/crowdloan/migration.rs +++ b/runtime/common/src/crowdloan/migration.rs @@ -15,7 +15,50 @@ // along with Polkadot. If not, see . use super::*; -use frame_support::{storage_alias, Twox64Concat}; +use frame_support::{ + dispatch::GetStorageVersion, storage_alias, traits::OnRuntimeUpgrade, Twox64Concat, +}; + +pub struct MigrateToTrackInactive(sp_std::marker::PhantomData); +impl OnRuntimeUpgrade for MigrateToTrackInactive { + fn on_runtime_upgrade() -> Weight { + let current_version = Pallet::::current_storage_version(); + let onchain_version = Pallet::::on_chain_storage_version(); + + if onchain_version == 0 && current_version == 1 { + let mut translated = 0u64; + for index in Funds::::iter_keys() { + let b = CurrencyOf::::total_balance(&Pallet::::fund_account_id(index.into())); + CurrencyOf::::deactivate(b); + translated.saturating_inc(); + } + current_version.put::>(); + log::info!(target: "runtime::crowdloan", "Summed {} funds, storage to version {:?}", translated, current_version); + T::DbWeight::get().reads_writes(translated * 2 + 1, translated * 2 + 1) + } else { + log::info!(target: "runtime::crowdloan", "Migration did not execute. This probably should be removed"); + T::DbWeight::get().reads(1) + } + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + let total = Funds::::iter_keys() + .map(|index| { + CurrencyOf::::total_balance(&Pallet::::fund_account_id(index.into())) + }) + .fold(BalanceOf::::zero(), |a, i| a.saturating_add(i)); + Ok((total, CurrencyOf::::active_issuance()).encode()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(total: Vec) -> Result<(), &'static str> { + let (total, active) = <(BalanceOf, BalanceOf)>::decode(&mut total.as_slice()) + .expect("the state parameter should be something that was generated by pre_upgrade"); + assert_eq!(active - total, CurrencyOf::::active_issuance(), "the total be correct"); + Ok(()) + } +} /// Migrations for using fund index to create fund accounts instead of para ID. pub mod crowdloan_index_migration { diff --git a/runtime/common/src/crowdloan/mod.rs b/runtime/common/src/crowdloan/mod.rs index 1f84af3f2ee9..cedcb464775c 100644 --- a/runtime/common/src/crowdloan/mod.rs +++ b/runtime/common/src/crowdloan/mod.rs @@ -51,6 +51,8 @@ pub mod migration; +// TODO: Expose the total amount held. + use crate::{ slot_range::SlotRange, traits::{Auctioneer, Registrar}, @@ -488,6 +490,7 @@ pub mod pallet { ensure!(balance > Zero::zero(), Error::::NoContributions); CurrencyOf::::transfer(&fund_account, &who, balance, AllowDeath)?; + CurrencyOf::::reactivate(balance); Self::contribution_kill(fund.fund_index, &who); fund.raised = fund.raised.saturating_sub(balance); @@ -527,6 +530,7 @@ pub mod pallet { break } CurrencyOf::::transfer(&fund_account, &who, balance, AllowDeath)?; + CurrencyOf::::reactivate(balance); Self::contribution_kill(fund.fund_index, &who); fund.raised = fund.raised.saturating_sub(balance); refund_count += 1; @@ -777,6 +781,7 @@ impl Pallet { } CurrencyOf::::transfer(&who, &fund_account, value, existence)?; + CurrencyOf::::deactivate(value); let balance = old_balance.saturating_add(value); Self::contribution_put(fund.fund_index, &who, &balance, &memo); diff --git a/runtime/kusama/constants/src/lib.rs b/runtime/kusama/constants/src/lib.rs index a8d047241b24..923f71b94dd8 100644 --- a/runtime/kusama/constants/src/lib.rs +++ b/runtime/kusama/constants/src/lib.rs @@ -26,8 +26,8 @@ pub mod currency { pub const EXISTENTIAL_DEPOSIT: Balance = 1 * CENTS; pub const UNITS: Balance = 1_000_000_000_000; - pub const CENTS: Balance = UNITS / 30_000; - pub const QUID: Balance = CENTS * 100; + pub const QUID: Balance = UNITS / 30; + pub const CENTS: Balance = QUID / 100; pub const GRAND: Balance = QUID * 1_000; pub const MILLICENTS: Balance = CENTS / 1_000; diff --git a/runtime/kusama/src/governance/fellowship.rs b/runtime/kusama/src/governance/fellowship.rs index 52ab8d0bebc8..6d01780ebc0c 100644 --- a/runtime/kusama/src/governance/fellowship.rs +++ b/runtime/kusama/src/governance/fellowship.rs @@ -50,7 +50,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, - min_enactment_period: 4, + min_enactment_period: 1 * MINUTES, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -72,7 +72,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, - min_enactment_period: 4, + min_enactment_period: 1 * MINUTES, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -94,7 +94,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, - min_enactment_period: 4, + min_enactment_period: 1 * MINUTES, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -138,7 +138,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, - min_enactment_period: 4, + min_enactment_period: 1 * MINUTES, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -160,7 +160,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, - min_enactment_period: 4, + min_enactment_period: 1 * MINUTES, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -182,7 +182,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, - min_enactment_period: 4, + min_enactment_period: 1 * MINUTES, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -204,7 +204,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, - min_enactment_period: 4, + min_enactment_period: 1 * MINUTES, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -226,7 +226,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, - min_enactment_period: 4, + min_enactment_period: 1 * MINUTES, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -248,7 +248,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, - min_enactment_period: 4, + min_enactment_period: 1 * MINUTES, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), diff --git a/runtime/kusama/src/governance/mod.rs b/runtime/kusama/src/governance/mod.rs index 03a1aa03c3a1..6b45dbade57d 100644 --- a/runtime/kusama/src/governance/mod.rs +++ b/runtime/kusama/src/governance/mod.rs @@ -47,7 +47,8 @@ impl pallet_conviction_voting::Config for Runtime { type Currency = Balances; type VoteLockingPeriod = VoteLockingPeriod; type MaxVotes = ConstU32<512>; - type MaxTurnout = frame_support::traits::TotalIssuanceOf; + type MaxTurnout = + frame_support::traits::tokens::currency::ActiveIssuanceOf; type Polls = Referenda; } diff --git a/runtime/kusama/src/governance/origins.rs b/runtime/kusama/src/governance/origins.rs index 780f9472e95a..b02ff53f3bab 100644 --- a/runtime/kusama/src/governance/origins.rs +++ b/runtime/kusama/src/governance/origins.rs @@ -174,6 +174,7 @@ pub mod pallet_custom_origins { SmallSpender = 10 * GRAND, MediumSpender = 100 * GRAND, BigSpender = 1_000 * GRAND, + Treasurer = 10_000 * GRAND, } } diff --git a/runtime/kusama/src/governance/tracks.rs b/runtime/kusama/src/governance/tracks.rs index fd1c94118507..b802d21c04f5 100644 --- a/runtime/kusama/src/governance/tracks.rs +++ b/runtime/kusama/src/governance/tracks.rs @@ -63,7 +63,7 @@ const SUP_BIG_SPENDER: Curve = Curve::make_reciprocal(20, 28, percent(1), percen const APP_WHITELISTED_CALLER: Curve = Curve::make_reciprocal(16, 28 * 24, percent(96), percent(50), percent(100)); const SUP_WHITELISTED_CALLER: Curve = - Curve::make_reciprocal(1, 28, percent(20), percent(10), percent(50)); + Curve::make_reciprocal(1, 28, percent(20), percent(5), percent(50)); const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 15] = [ ( @@ -71,9 +71,9 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 15 pallet_referenda::TrackInfo { name: "root", max_deciding: 1, - decision_deposit: 1_000 * GRAND, - prepare_period: 3 * HOURS, - decision_period: 28 * DAYS, + decision_deposit: 100 * GRAND, + prepare_period: 4 * HOURS, + decision_period: 14 * DAYS, confirm_period: 3 * HOURS, min_enactment_period: 3 * HOURS, min_approval: APP_ROOT, @@ -84,10 +84,10 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 15 1, pallet_referenda::TrackInfo { name: "whitelisted_caller", - max_deciding: 10, - decision_deposit: 10_000 * GRAND, - prepare_period: 3 * HOURS, - decision_period: 28 * DAYS, + max_deciding: 30, + decision_deposit: 100 * GRAND, + prepare_period: 4 * HOURS, + decision_period: 14 * DAYS, confirm_period: 10 * MINUTES, min_enactment_period: 30 * MINUTES, min_approval: APP_WHITELISTED_CALLER, @@ -100,8 +100,8 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 15 name: "staking_admin", max_deciding: 10, decision_deposit: 5 * GRAND, - prepare_period: 4, - decision_period: 28 * DAYS, + prepare_period: 4 * HOURS, + decision_period: 14 * DAYS, confirm_period: 3 * HOURS, min_enactment_period: 2 * DAYS, min_approval: APP_STAKING_ADMIN, @@ -114,8 +114,8 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 15 name: "treasurer", max_deciding: 10, decision_deposit: 5 * GRAND, - prepare_period: 4, - decision_period: 28 * DAYS, + prepare_period: 4 * HOURS, + decision_period: 14 * DAYS, confirm_period: 3 * HOURS, min_enactment_period: 2 * DAYS, min_approval: APP_TREASURER, @@ -128,8 +128,8 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 15 name: "lease_admin", max_deciding: 10, decision_deposit: 5 * GRAND, - prepare_period: 4, - decision_period: 28 * DAYS, + prepare_period: 4 * HOURS, + decision_period: 14 * DAYS, confirm_period: 3 * HOURS, min_enactment_period: 2 * DAYS, min_approval: APP_LEASE_ADMIN, @@ -142,8 +142,8 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 15 name: "fellowship_admin", max_deciding: 10, decision_deposit: 5 * GRAND, - prepare_period: 4, - decision_period: 28 * DAYS, + prepare_period: 4 * HOURS, + decision_period: 14 * DAYS, confirm_period: 3 * HOURS, min_enactment_period: 2 * DAYS, min_approval: APP_FELLOWSHIP_ADMIN, @@ -156,8 +156,8 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 15 name: "general_admin", max_deciding: 10, decision_deposit: 5 * GRAND, - prepare_period: 4, - decision_period: 28 * DAYS, + prepare_period: 4 * HOURS, + decision_period: 14 * DAYS, confirm_period: 3 * HOURS, min_enactment_period: 2 * DAYS, min_approval: APP_GENERAL_ADMIN, @@ -170,8 +170,8 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 15 name: "auction_admin", max_deciding: 10, decision_deposit: 5 * GRAND, - prepare_period: 4, - decision_period: 28 * DAYS, + prepare_period: 4 * HOURS, + decision_period: 14 * DAYS, confirm_period: 3 * HOURS, min_enactment_period: 2 * DAYS, min_approval: APP_AUCTION_ADMIN, @@ -184,8 +184,8 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 15 name: "referendum_canceller", max_deciding: 1_000, decision_deposit: 50 * GRAND, - prepare_period: 4, - decision_period: 28 * DAYS, + prepare_period: 4 * HOURS, + decision_period: 7 * DAYS, confirm_period: 3 * HOURS, min_enactment_period: 10 * MINUTES, min_approval: APP_REFERENDUM_CANCELLER, @@ -198,8 +198,8 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 15 name: "referendum_killer", max_deciding: 1_000, decision_deposit: 50 * GRAND, - prepare_period: 4, - decision_period: 28 * DAYS, + prepare_period: 4 * HOURS, + decision_period: 14 * DAYS, confirm_period: 3 * HOURS, min_enactment_period: 10 * MINUTES, min_approval: APP_REFERENDUM_KILLER, @@ -212,10 +212,10 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 15 name: "small_tipper", max_deciding: 200, decision_deposit: 5 * QUID, - prepare_period: 4, - decision_period: 28 * DAYS, + prepare_period: 4 * HOURS, + decision_period: 7 * DAYS, confirm_period: 3 * HOURS, - min_enactment_period: 28 * DAYS, + min_enactment_period: 24 * HOURS, min_approval: APP_SMALL_TIPPER, min_support: SUP_SMALL_TIPPER, }, @@ -226,10 +226,10 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 15 name: "big_tipper", max_deciding: 100, decision_deposit: 50 * QUID, - prepare_period: 4, - decision_period: 28 * DAYS, + prepare_period: 4 * HOURS, + decision_period: 7 * DAYS, confirm_period: 6 * HOURS, - min_enactment_period: 28 * DAYS, + min_enactment_period: 24 * HOURS, min_approval: APP_BIG_TIPPER, min_support: SUP_BIG_TIPPER, }, @@ -240,10 +240,10 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 15 name: "small_spender", max_deciding: 50, decision_deposit: 500 * QUID, - prepare_period: 4, - decision_period: 28 * DAYS, + prepare_period: 4 * HOURS, + decision_period: 14 * DAYS, confirm_period: 12 * HOURS, - min_enactment_period: 28 * DAYS, + min_enactment_period: 24 * HOURS, min_approval: APP_SMALL_SPENDER, min_support: SUP_SMALL_SPENDER, }, @@ -254,10 +254,10 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 15 name: "medium_spender", max_deciding: 20, decision_deposit: 1_500 * QUID, - prepare_period: 4, - decision_period: 28 * DAYS, + prepare_period: 4 * HOURS, + decision_period: 14 * DAYS, confirm_period: 24 * HOURS, - min_enactment_period: 28 * DAYS, + min_enactment_period: 24 * HOURS, min_approval: APP_MEDIUM_SPENDER, min_support: SUP_MEDIUM_SPENDER, }, @@ -268,10 +268,10 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 15 name: "big_spender", max_deciding: 10, decision_deposit: 5 * GRAND, - prepare_period: 4, - decision_period: 28 * DAYS, + prepare_period: 4 * HOURS, + decision_period: 14 * DAYS, confirm_period: 48 * HOURS, - min_enactment_period: 28 * DAYS, + min_enactment_period: 24 * HOURS, min_approval: APP_BIG_SPENDER, min_support: SUP_BIG_SPENDER, }, diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index 20dbc6ac7ec9..50d8062183ec 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -109,6 +109,7 @@ use governance::{ old::CouncilCollective, pallet_custom_origins, AuctionAdmin, GeneralAdmin, LeaseAdmin, StakingAdmin, Treasurer, TreasurySpender, }; +use xcm_config::CheckAccount; #[cfg(test)] mod tests; @@ -1480,6 +1481,11 @@ impl Get<&'static str> for StakingMigrationV11OldPallet { } } +pub type Migrations = ( + pallet_balances::migration::MigrateToTrackInactive, + crowdloan::migration::MigrateToTrackInactive, +); + /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; @@ -1490,7 +1496,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - (), + Migrations, >; /// The payload being signed in the transactions. pub type SignedPayload = generic::SignedPayload; @@ -2071,7 +2077,7 @@ mod tests_fess { // ensure this number does not change, or that it is checked after each change. // a 1 MB solution should need around 0.16 KSM deposit let deposit = SignedDepositBase::get() + (SignedDepositByte::get() * 1024 * 1024); - assert_eq_error_rate!(deposit, UNITS * 16 / 100, UNITS / 100); + assert_eq_error_rate!(deposit, UNITS * 167 / 100, UNITS / 100); } } diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index be1430a62f9e..17ff253d196f 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -1598,6 +1598,11 @@ impl Get<&'static str> for StakingMigrationV11OldPallet { } } +pub type Migrations = ( + pallet_balances::migration::MigrateToTrackInactive, + crowdloan::migration::MigrateToTrackInactive, +); + /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; @@ -1608,7 +1613,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - (), + Migrations, >; /// The payload being signed in transactions. diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index 763184e8bda6..bcf0a03c9456 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -1476,6 +1476,12 @@ pub type SignedExtra = ( /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; + +pub type Migrations = ( + pallet_balances::migration::MigrateToTrackInactive, + crowdloan::migration::MigrateToTrackInactive, +); + /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< Runtime, @@ -1483,7 +1489,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - (), + Migrations, >; /// The payload being signed in transactions. pub type SignedPayload = generic::SignedPayload; diff --git a/runtime/test-runtime/src/lib.rs b/runtime/test-runtime/src/lib.rs index e4abb2392727..a30d4d350715 100644 --- a/runtime/test-runtime/src/lib.rs +++ b/runtime/test-runtime/src/lib.rs @@ -744,6 +744,7 @@ pub type SignedExtra = ( /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; + /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< Runtime, diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 2fee85a336a2..b6ae141f3b50 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -1212,6 +1212,11 @@ impl Get<&'static str> for StakingMigrationV11OldPallet { } } +pub type Migrations = ( + pallet_balances::migration::MigrateToTrackInactive, + crowdloan::migration::MigrateToTrackInactive, +); + /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; @@ -1222,7 +1227,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - (), + Migrations, >; /// The payload being signed in transactions. pub type SignedPayload = generic::SignedPayload; diff --git a/xcm/xcm-builder/src/currency_adapter.rs b/xcm/xcm-builder/src/currency_adapter.rs index 5e259195c4a0..f231bf1094b4 100644 --- a/xcm/xcm-builder/src/currency_adapter.rs +++ b/xcm/xcm-builder/src/currency_adapter.rs @@ -125,6 +125,9 @@ impl< AllowDeath, ) .is_ok(); + if ok { + Currency::reactivate(amount); + } debug_assert!( ok, "`can_check_in` must have returned `true` immediately prior; qed" @@ -138,6 +141,7 @@ impl< if let Some(amount) = Matcher::matches_fungible(what) { if let Some(checked_account) = CheckedAccount::get() { Currency::deposit_creating(&checked_account, amount); + Currency::deactivate(amount); } } }