Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
eb49fda
try_kill_gov_v1_storage test poc
liamaharon Mar 28, 2023
5ab6c31
log key counts and clear keys
liamaharon Mar 28, 2023
f95ab4b
move count_keys into remote_tests
liamaharon Mar 28, 2023
a1702ee
remove code duplication
liamaharon Mar 28, 2023
cefdab5
improve comment
liamaharon Mar 28, 2023
a812fa6
cleanup syntax
liamaharon Mar 28, 2023
b6ef384
typo
liamaharon Mar 28, 2023
10654e2
migrate removal functionality from test to onruntimeupgrade
liamaharon Mar 29, 2023
359d8eb
fix formatting
liamaharon Mar 29, 2023
cb0dbc9
Merge branch 'master' of github.com:paritytech/polkadot into liam-rem…
liamaharon Mar 29, 2023
b1864d6
formatting
liamaharon Mar 29, 2023
53a0316
improve error log
liamaharon Mar 29, 2023
212e6a1
use struct const syntax
liamaharon Mar 29, 2023
69feee0
refactor to generic RemovePallet
liamaharon Mar 29, 2023
49865f8
count initial prefix read in weight
liamaharon Mar 29, 2023
28b499c
improve comment
liamaharon Mar 29, 2023
abc6c93
add licence and docs
liamaharon Mar 29, 2023
cd46283
revert redundant change
liamaharon Mar 29, 2023
4069109
typo
liamaharon Mar 29, 2023
b2044f1
Merge branch 'master' of github.com:paritytech/polkadot into liam-rem…
liamaharon Mar 30, 2023
e5934b2
use helper storage methods
liamaharon Mar 30, 2023
ba87f37
remove tips storage
liamaharon Mar 30, 2023
a3f3b31
Merge branch 'master' of github.com:paritytech/polkadot into liam-rem…
liamaharon Mar 31, 2023
c0081eb
usage docs
liamaharon Mar 31, 2023
f181f1c
make parameter types consts
liamaharon Mar 31, 2023
9d0ce58
move docs to struct
liamaharon Mar 31, 2023
afa82e9
Update runtime/common/src/remove_pallet.rs
liamaharon Mar 31, 2023
e477c92
add error log if clear_prefix returns unexpected result
liamaharon Mar 31, 2023
0bf4140
Merge branch 'liam-remove-kusama-gov-v1-storage' of github.com:parity…
liamaharon Mar 31, 2023
fc37d00
return error from post_upgrade in case of failure
liamaharon Mar 31, 2023
a0fbaa7
typo
liamaharon Mar 31, 2023
dd6cab9
improve outer comment
liamaharon Mar 31, 2023
7766cb1
Update runtime/common/src/remove_pallet.rs
liamaharon Mar 31, 2023
39ce205
Merge branch 'liam-remove-kusama-gov-v1-storage' of github.com:parity…
liamaharon Apr 1, 2023
f935984
Update runtime/common/src/remove_pallet.rs
liamaharon Apr 5, 2023
e0632be
Update runtime/common/src/remove_pallet.rs
liamaharon Apr 5, 2023
fb39cbe
Merge branch 'master' of github.com:paritytech/polkadot into liam-rem…
liamaharon Apr 5, 2023
299ce74
remove kusama gov v1 storage deletion
liamaharon Apr 5, 2023
21baa56
fix universal alias function signature
liamaharon Apr 5, 2023
29848c7
generic DbWeight
liamaharon Apr 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use runtime_common::{
SlowAdjustingFeeUpdate, U256ToBalance,
};
use scale_info::TypeInfo;
use sp_io::hashing::twox_128;
use sp_std::{cmp::Ordering, collections::btree_map::BTreeMap, prelude::*};

use runtime_parachains::{
Expand Down Expand Up @@ -1326,6 +1327,97 @@ impl pallet_nomination_pools::Config for Runtime {
type MaxPointsToBalance = MaxPointsToBalance;
}

pub struct RemoveGovV1Storage;
impl RemoveGovV1Storage {
fn get_pallets() -> Vec<&'static str> {
vec![
"Democracy",
"Council",
"TechnicalCommittee",
"PhragmenElection",
"TechnicalMembership",
"Treasury",
]
}

fn count_keys(prefix: &[u8]) -> u32 {
let mut current = prefix.clone().to_vec();
let mut counter = 0;
while let Some(next) = sp_io::storage::next_key(&current[..]) {
if !next.starts_with(prefix) {
return counter
}
counter += 1;
current = next;
}
0
}
}
impl frame_support::traits::OnRuntimeUpgrade for RemoveGovV1Storage {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
use frame_support::dispatch::GetDispatchInfo;
use sp_runtime::traits::Dispatchable;

// Create a 'kill_prefix' call for each pallet we wish to remove keys for
let mut total_keys = 0;
let calls = Self::get_pallets()
.iter()
.map(|pallet| {
let prefix = twox_128(pallet.as_bytes());
let subkeys = Self::count_keys(&prefix);
total_keys += subkeys;
RuntimeCall::System(frame_system::Call::<Runtime>::kill_prefix {
prefix: prefix.to_vec(),
subkeys,
})
})
.collect::<Vec<_>>();

if total_keys > 0 {
// Wrap all 'kill_prefix' calls in a single batch transaction
log::info!(target: "runtime::kusama", "removing {} Gov V1 keys 💣", total_keys);
let batch = pallet_utility::Call::<Runtime>::batch { calls };
let estimated_weight = batch.get_dispatch_info().weight;
match RuntimeCall::Utility(batch).dispatch(RuntimeOrigin::root()) {
Ok(post_info) => post_info.actual_weight.unwrap_or_default(),
Err(_) => estimated_weight,
}
} else {
log::info!(target: "runtime::kusama", "Gov V1 keys already removed 🤙");
<Runtime as frame_system::Config>::DbWeight::get()
.reads(Self::get_pallets().len() as u64)
}
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
Self::get_pallets().iter().for_each(|p| {
let prefix = twox_128(p.as_bytes());
let subkeys = Self::count_keys(&prefix);
if subkeys > 0 {
log::info!(target: "runtime::kusama", "Found {} keys for Gov V1 pallet {} pre-removal", subkeys, p);
} else {
log::warn!(target: "runtime::kusama", "No keys found for Gov V1 pallet {} pre-removal", p)
};
});
Ok(vec![])
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
Self::get_pallets().iter().for_each(|p| {
let prefix = twox_128(p.as_bytes());
let subkeys = Self::count_keys(&prefix);
if subkeys > 0 {
log::error!(target: "runtime::kusama", "{} Gov V1 pallet {} keys remaining post-removal ❗", subkeys, p);
} else {
log::info!(target: "runtime::kusama", "No {} keys remaining post-removal 🎉", p)
}
});
Ok(())
}
}

construct_runtime! {
pub enum Runtime where
Block = Block,
Expand Down Expand Up @@ -1491,6 +1583,7 @@ pub type Migrations = (
// Unreleased - add new migrations here:
pallet_nomination_pools::migration::v5::MigrateToV5<Runtime>,
parachains_configuration::migration::v5::MigrateToV5<Runtime>,
RemoveGovV1Storage,
);

/// Unchecked extrinsic type as expected by this runtime.
Expand Down
3 changes: 1 addition & 2 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2362,8 +2362,7 @@ mod remote_tests {
#[ignore = "this test is meant to be executed manually"]
async fn try_fast_unstake_all() {
sp_tracing::try_init_simple();
let transport: Transport =
var("WS").unwrap_or("wss://rpc.polkadot.io:443".to_string()).into();
let transport: Transport = var("WS").unwrap_or("ws://localhost:9944".to_string()).into();
let maybe_state_snapshot: Option<SnapshotConfig> = var("SNAP").map(|s| s.into()).ok();
let mut ext = Builder::<Block>::default()
.mode(if let Some(state_snapshot) = maybe_state_snapshot {
Expand Down