Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7007862
Migrate pallet-membership to new pallet attribute macro
koushiro Jun 11, 2021
1e658b0
Add migrations
koushiro Jun 16, 2021
170de2a
more general
koushiro Jun 16, 2021
ca1f821
fix event metadata
koushiro Jun 16, 2021
a3fc53a
some nits
koushiro Jun 16, 2021
29ed84d
fix some nits
koushiro Jun 16, 2021
94ebe35
apply suggestion
koushiro Jun 17, 2021
e7d5ced
some nits
koushiro Jun 23, 2021
4f790e8
Merge remote-tracking branch 'upstream/master' into migrate-pallet-me…
koushiro Jun 24, 2021
c51c30c
Fix
koushiro Jul 22, 2021
a38faa7
Merge remote-tracking branch 'upstream/master' into migrate-pallet-me…
koushiro Jul 22, 2021
e69ad82
Merge remote-tracking branch 'upstream/master' into migrate-pallet-me…
koushiro Aug 13, 2021
03876de
Remove useless
koushiro Aug 13, 2021
e1c0989
Fix migration
koushiro Aug 13, 2021
0fceccd
Fix format
koushiro Aug 13, 2021
0cc05b2
Fix
koushiro Aug 13, 2021
826fdcd
Merge remote-tracking branch 'upstream/master' into migrate-pallet-me…
koushiro Aug 13, 2021
2e3a766
Merge remote-tracking branch 'origin/master' into 9080
gui1117 Aug 27, 2021
01b5ecd
Fix migration
gui1117 Aug 27, 2021
e282784
Merge remote-tracking branch 'upstream/master' into migrate-pallet-me…
koushiro Sep 7, 2021
06d0c00
Merge remote-tracking branch 'myfork/migrate-pallet-membership' into …
koushiro Sep 7, 2021
1994b8a
Fix migration and Add migration test
koushiro Sep 7, 2021
965b451
Fix
koushiro Sep 7, 2021
cf58b30
Fix format
koushiro Sep 7, 2021
aed1182
Use new_test_ext
koushiro Sep 7, 2021
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
Prev Previous commit
Next Next commit
more general
Signed-off-by: koushiro <[email protected]>
  • Loading branch information
koushiro committed Jun 16, 2021
commit 170de2ab5c6c87180c7f01f5d0dbb0c0a30a29cd
24 changes: 11 additions & 13 deletions frame/membership/src/migrations/v3_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ use frame_support::{
};
use sp_io::hashing::twox_128;

/// The old prefix.
pub const OLD_PREFIX: &[u8] = b"Instance1Membership";

/// Migrate the entire storage of this pallet to a new prefix.
///
/// This new prefix must be the same as the one set in construct_runtime. For safety, use
Expand All @@ -35,8 +32,8 @@ pub fn migrate<
T: frame_system::Config,
P: GetPalletVersion,
N: AsRef<str>
>(new_pallet_name: N) -> Weight {
if new_pallet_name.as_ref().as_bytes() == OLD_PREFIX {
>(old_pallet_name: N, new_pallet_name: N) -> Weight {
if new_pallet_name.as_ref() == old_pallet_name.as_ref() {
log::info!(
target: "runtime::membership",
"New pallet name is equal to the old prefix. No migration needs to be done.",
Expand All @@ -54,7 +51,7 @@ pub fn migrate<
Some(storage_version) if storage_version <= PalletVersion::new(3, 0, 0) => {
log::info!(target: "runtime::membership", "new prefix: {}", new_pallet_name.as_ref());
frame_support::storage::migration::move_pallet(
OLD_PREFIX,
old_pallet_name.as_ref().as_bytes(),
new_pallet_name.as_ref().as_bytes(),
);
<T as frame_system::Config>::BlockWeights::get().max_block
Expand All @@ -78,13 +75,13 @@ pub fn pre_migration<
T: frame_system::Config,
P: GetPalletVersion + 'static,
N: AsRef<str>,
>(new: N) {
>(old: N, new: N) {
let new = new.as_ref();
log::info!("pre-migration membership test with new = {}", new);

// the next key must exist, and start with the hash of `OLD_PREFIX`.
let next_key = sp_io::storage::next_key(&twox_128(OLD_PREFIX)).unwrap();
assert!(next_key.starts_with(&twox_128(OLD_PREFIX)));
// the next key must exist, and start with the hash of old prefix.
let next_key = sp_io::storage::next_key(&twox_128(old.as_ref().as_bytes())).unwrap();
assert!(next_key.starts_with(&twox_128(old.as_ref().as_bytes())));

// The pallet version is already stored using the pallet name
let storage_key = PalletVersion::storage_key::<T::PalletInfo, P>().unwrap();
Expand Down Expand Up @@ -117,14 +114,15 @@ pub fn pre_migration<
/// [`frame_support::traits::OnRuntimeUpgrade::post_upgrade`] for further testing.
///
/// Panics if anything goes wrong.
pub fn post_migration<P: GetPalletVersion>() {
pub fn post_migration<P: GetPalletVersion, N: AsRef<str>>(old_pallet_name: N) {
log::info!("post-migration membership");

let old_pallet_name = old_pallet_name.as_ref().as_bytes();
// Assert that nothing remains at the old prefix
assert!(
sp_io::storage::next_key(&twox_128(OLD_PREFIX)).map_or(
sp_io::storage::next_key(&twox_128(old_pallet_name)).map_or(
true,
|next_key| !next_key.starts_with(&twox_128(OLD_PREFIX))
|next_key| !next_key.starts_with(&twox_128(old_pallet_name))
)
);
// ensure we've been updated to v4 by the automatic write of crate version -> storage version.
Expand Down