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

OpenGov improvements for Kusama #6372

Merged
merged 12 commits into from
Dec 5, 2022
Prev Previous commit
Next Next commit
Introduce migrations
  • Loading branch information
gavofyork committed Dec 3, 2022
commit 0ebf85c7658a9a9ce2fbe2046fa71e1bdb36829b
362 changes: 181 additions & 181 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions runtime/common/src/crowdloan/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use super::*;
use frame_support::{storage_alias, Twox64Concat, traits::OnRuntimeUpgrade};
use frame_support::{
dispatch::GetStorageVersion, storage_alias, traits::OnRuntimeUpgrade, Twox64Concat,
};

pub struct MigrateToTrackInactive<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToTrackInactive<T> {
Expand All @@ -26,7 +28,7 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToTrackInactive<T> {
if onchain_version == 0 && current_version == 1 {
let mut translated = 0u64;
for index in Funds::<T>::iter_keys() {
let b = CurrencyOf::<T>::total_balance(&Pallet::<T>::fund_account_id(index));
let b = CurrencyOf::<T>::total_balance(&Pallet::<T>::fund_account_id(index.into()));
CurrencyOf::<T>::deactivate(b);
translated.saturating_inc();
}
Expand All @@ -49,9 +51,8 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToTrackInactive<T> {

#[cfg(feature = "try-runtime")]
fn post_upgrade(total: Vec<u8>) -> Result<(), &'static str> {
let (total, active) = <(BalanceOf::<T>, BalanceOf::<T>)>::decode(&mut total.as_slice()).expect(
"the state parameter should be something that was generated by pre_upgrade",
);
let (total, active) = <(BalanceOf<T>, BalanceOf<T>)>::decode(&mut total.as_slice())
.expect("the state parameter should be something that was generated by pre_upgrade");
assert_eq!(active - total, CurrencyOf::<T>::active_issuance(), "the total be correct");
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/common/src/crowdloan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ impl<T: Config> Pallet<T> {
}

CurrencyOf::<T>::transfer(&who, &fund_account, value, existence)?;
CurrencyOf::<T>::deactivate(balance);
CurrencyOf::<T>::deactivate(value);

let balance = old_balance.saturating_add(value);
Self::contribution_put(fund.fund_index, &who, &balance, &memo);
Expand Down
4 changes: 2 additions & 2 deletions runtime/kusama/src/governance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ impl pallet_conviction_voting::Config for Runtime {
type Currency = Balances;
type VoteLockingPeriod = VoteLockingPeriod;
type MaxVotes = ConstU32<512>;
// TODO: Should be `total_issuance` minus funds trapped in system pots/checked
type MaxTurnout = frame_support::traits::ActiveIssuanceOf<Balances, Self::AccountId>;
type MaxTurnout =
frame_support::traits::tokens::currency::ActiveIssuanceOf<Balances, Self::AccountId>;
type Polls = Referenda;
}

Expand Down
8 changes: 7 additions & 1 deletion runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ use governance::{
old::CouncilCollective, pallet_custom_origins, AuctionAdmin, GeneralAdmin, LeaseAdmin,
StakingAdmin, Treasurer, TreasurySpender,
};
use xcm_config::CheckAccount;

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -1453,6 +1454,11 @@ impl Get<&'static str> for StakingMigrationV11OldPallet {
}
}

pub type Migrations = (
pallet_balances::migration::MigrateToTrackInactive<Runtime, CheckAccount>,
crowdloan::migration::MigrateToTrackInactive<Runtime>,
);

/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
Expand All @@ -1463,7 +1469,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
(),
Migrations,
>;
/// The payload being signed in the transactions.
pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;
Expand Down
7 changes: 6 additions & 1 deletion runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,11 @@ impl Get<&'static str> for StakingMigrationV11OldPallet {
}
}

pub type Migrations = (
pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckAccount>,
crowdloan::migration::MigrateToTrackInactive<Runtime>,
);

/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
Expand All @@ -1609,7 +1614,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
(),
Migrations,
>;

/// The payload being signed in transactions.
Expand Down
8 changes: 7 additions & 1 deletion runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1449,14 +1449,20 @@ pub type SignedExtra = (
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;

pub type Migrations = (
pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckAccount>,
crowdloan::migration::MigrateToTrackInactive<Runtime>,
);

/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
(),
Migrations,
>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;
Expand Down
1 change: 1 addition & 0 deletions runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ pub type SignedExtra = (
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;

/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Runtime,
Expand Down
7 changes: 6 additions & 1 deletion runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,11 @@ impl Get<&'static str> for StakingMigrationV11OldPallet {
}
}

pub type Migrations = (
pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckAccount>,
crowdloan::migration::MigrateToTrackInactive<Runtime>,
);

/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
Expand All @@ -1222,7 +1227,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
(),
Migrations,
>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;
Expand Down