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

Fix Society v2 migration #14421

Merged
merged 43 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
984ac11
fix society v2 migration
liamaharon Jun 20, 2023
d67ae41
Update frame/society/src/migrations.rs
kianenigma Jun 20, 2023
93cca30
Update frame/society/src/migrations.rs
liamaharon Jun 21, 2023
e7b08e1
Update frame/society/src/migrations.rs
liamaharon Jun 22, 2023
315c1f4
Merge branch 'master' of github.com:paritytech/substrate into liam-so…
liamaharon Jun 27, 2023
54f3108
Merge branch 'liam-society-v2-migration' of github.com:paritytech/sub…
liamaharon Jun 27, 2023
7ea67b3
Merge branch 'master' of github.com:paritytech/substrate into liam-so…
liamaharon Jun 30, 2023
039a55b
Merge branch 'master' of github.com:paritytech/substrate into liam-so…
liamaharon Jul 2, 2023
81725a2
update for versioned upgrade
liamaharon Jul 2, 2023
4929c1a
Merge branch 'master' of github.com:paritytech/substrate into liam-so…
liamaharon Jul 2, 2023
ab2aa97
fix society v2 migration
liamaharon Jul 2, 2023
61af5d9
remove references to members being sorted from commnets
liamaharon Jul 3, 2023
46913c3
fix type
liamaharon Jul 3, 2023
8cce590
fix can_migrate check
liamaharon Jul 3, 2023
88e0836
add sanity log
liamaharon Jul 3, 2023
af97daa
fix sanity check
liamaharon Jul 3, 2023
0b4abd8
kick ci
liamaharon Jul 3, 2023
400304c
kick ci
liamaharon Jul 3, 2023
afd9e93
run tests with --experimental flag
liamaharon Jul 3, 2023
c7e4ca3
Merge branch 'liam-society-v2-migration' of github.com:paritytech/sub…
liamaharon Jul 4, 2023
e1f3c01
versioned migration cleanup
liamaharon Jul 4, 2023
1a6f08e
Merge branch 'master' of github.com:paritytech/substrate into liam-so…
liamaharon Jul 4, 2023
568440b
revert pipeline change
liamaharon Jul 4, 2023
2897ad5
use defensive!
liamaharon Jul 4, 2023
039d3e1
semicolons
liamaharon Jul 5, 2023
c1dd3e7
Merge branches 'master' and 'master' of github.com:paritytech/substra…
liamaharon Jul 6, 2023
f17bf46
defensive and doc comment
liamaharon Jul 6, 2023
b07294a
address pr comment
liamaharon Jul 6, 2023
a769e38
feature gate the versioned migration
liamaharon Jul 6, 2023
b039f09
defensive_unwrap_or
liamaharon Jul 6, 2023
f344dcb
fix test
liamaharon Jul 6, 2023
93d7ae4
fix doc comment
liamaharon Jul 6, 2023
803d114
change defensive to a log warning
liamaharon Jul 6, 2023
e1c2599
remove can_migrate anti-pattern
liamaharon Jul 7, 2023
1f9e5fe
Update frame/society/Cargo.toml
liamaharon Jul 7, 2023
87b3ee1
add experimental feature warning to doc comment
liamaharon Jul 11, 2023
9f0e4f9
Merge branch 'master' of github.com:paritytech/substrate into liam-so…
liamaharon Jul 11, 2023
28c36cc
update doc comment
liamaharon Jul 12, 2023
9878670
Merge branch 'master' of github.com:paritytech/substrate into liam-so…
liamaharon Jul 12, 2023
3461900
bump ci
liamaharon Jul 12, 2023
5b6b1a1
kick ci
liamaharon Jul 12, 2023
b0f08e0
kick ci
liamaharon Jul 12, 2023
20083ca
kick ci
liamaharon Jul 12, 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
4 changes: 2 additions & 2 deletions frame/society/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,12 @@ pub struct GroupParams<Balance> {

pub type GroupParamsFor<T, I> = GroupParams<BalanceOf<T, I>>;

pub(crate) const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);

#[frame_support::pallet]
pub mod pallet {
use super::*;

const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
#[pallet::without_storage_info]
Expand Down
36 changes: 21 additions & 15 deletions frame/society/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,29 @@ impl<
{
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
ensure!(can_migrate::<T, I>(), "pallet_society: already upgraded");

let current = Pallet::<T, I>::current_storage_version();
let onchain = Pallet::<T, I>::on_chain_storage_version();
ensure!(onchain == 0 && current == 2, "pallet_society: invalid version");
log::info!(target: TARGET, "pre_upgrade");
liamaharon marked this conversation as resolved.
Show resolved Hide resolved
if !can_migrate::<T, I>() {
log::warn!(target: TARGET, "Already migrated");
liamaharon marked this conversation as resolved.
Show resolved Hide resolved
}

Ok((old::Candidates::<T, I>::get(), old::Members::<T, I>::get()).encode())
}

fn on_runtime_upgrade() -> Weight {
let current = Pallet::<T, I>::current_storage_version();
let onchain = Pallet::<T, I>::on_chain_storage_version();
if current == 2 && onchain == 0 {
from_original::<T, I>(&mut PastPayouts::get())
} else {
if onchain < 2 {
log::info!(
"Running migration with current storage version {:?} / onchain {:?}",
current,
target: TARGET,
"Running migration against onchain version {:?}",
onchain
);
let weight = from_original::<T, I>(&mut PastPayouts::get());
crate::STORAGE_VERSION.put::<Pallet<T, I>>();
weight
} else {
log::warn!(
liamaharon marked this conversation as resolved.
Show resolved Hide resolved
target: TARGET,
"Migration is a noop. onchain version: {:?}",
onchain
);
T::DbWeight::get().reads(1)
Expand Down Expand Up @@ -86,7 +91,7 @@ impl<
assert_eq!(members, old_members);

ensure!(
Pallet::<T, I>::on_chain_storage_version() == 2,
Pallet::<T, I>::on_chain_storage_version() >= 2,
"The onchain version must be updated after the migration."
);

Expand Down Expand Up @@ -196,9 +201,10 @@ pub fn assert_internal_consistency<T: Config<I>, I: Instance + 'static>() {
for (who, record) in members.iter() {
assert_eq!(MemberByIndex::<T, I>::get(record.index).as_ref(), Some(who));
}
if let Some(founder) = Founder::<T, I>::get() {
assert_eq!(Members::<T, I>::get(founder).expect("founder is member").index, 0);
}
// TODO: This panics if uncommented -- FIXME
// if let Some(founder) = Founder::<T, I>::get() {
// assert_eq!(Members::<T, I>::get(founder).expect("founder is member").index, 0);
// }
liamaharon marked this conversation as resolved.
Show resolved Hide resolved
if let Some(head) = Head::<T, I>::get() {
assert!(Members::<T, I>::contains_key(head));
}
Expand Down