Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
fix migrations
  • Loading branch information
Michal Swietek committed Nov 22, 2022
commit 7d1aff2372359be07ba640cd7c2976d9ecdafa4b
2 changes: 1 addition & 1 deletion bin/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ parameter_types! {
pub DeletionQueueDepth: u32 = DeletionWeightLimit::get().saturating_div((
<Runtime as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(1) -
<Runtime as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(0)
).ref_time()) * 10).ref_time() as u32; // 2228
).ref_time() * 10).ref_time() as u32; // 2228
pub Schedule: pallet_contracts::Schedule<Runtime> = Default::default();
}

Expand Down
6 changes: 3 additions & 3 deletions pallets/aleph/src/migrations/v0_to_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
#[storage_alias]
type SessionForValidatorsChange = StorageValue<Aleph, Option<SessionIndex>>;
#[storage_alias]
Expand All @@ -90,11 +90,11 @@ impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
Self::store_temp("session", SessionForValidatorsChange::get());
Self::store_temp("validators", Validators::<T>::get());

Ok(())
Ok(Vec::new())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
ensure_storage_version::<P>(1)?;

let new_session = SessionForValidatorsChange::get();
Expand Down
8 changes: 5 additions & 3 deletions pallets/aleph/src/migrations/v1_to_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use frame_support::{
#[cfg(feature = "try-runtime")]
use pallets_support::ensure_storage_version;
use pallets_support::StorageMigration;
use sp_std::vec::Vec;

use crate::Config;

Expand Down Expand Up @@ -81,12 +82,13 @@ impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
ensure_storage_version::<P>(1)
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
ensure_storage_version::<P>(1)?;
Ok(Vec::new())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
ensure_storage_version::<P>(2)?;

ensure!(
Expand Down
6 changes: 3 additions & 3 deletions pallets/elections/src/migrations/v0_to_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
ensure_storage_version::<P>(0)?;

let members = Members::<T>::get().ok_or("No `Members` storage")?;
Self::store_temp("members", members);

Ok(())
Ok(Vec::new())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
ensure_storage_version::<P>(1)?;

let mps = MembersPerSession::get().ok_or("No `MembersPerSession` in the storage")?;
Expand Down
7 changes: 4 additions & 3 deletions pallets/elections/src/migrations/v1_to_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use frame_support::{
#[cfg(feature = "try-runtime")]
use pallets_support::ensure_storage_version;
use pallets_support::StorageMigration;
use sp_std::vec::Vec;

use crate::{migrations::Validators, Config, EraValidators};

Expand Down Expand Up @@ -82,7 +83,7 @@ impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
ensure_storage_version::<P>(1)?;

let members_per_session =
Expand All @@ -100,11 +101,11 @@ impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
let eras_members = ErasMembers::<T>::get().ok_or("No `ErasMembers` in the storage")?;
Self::store_temp("eras_members", eras_members);

Ok(())
Ok(Vec::new())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
ensure_storage_version::<P>(2)?;

let committee_size = CommitteeSize::get().ok_or("No `CommitteeSize` in the storage")?;
Expand Down
7 changes: 4 additions & 3 deletions pallets/elections/src/migrations/v2_to_v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use frame_support::{
use pallets_support::ensure_storage_version;
use pallets_support::StorageMigration;
use primitives::CommitteeSeats;
use sp_std::vec::Vec;

use crate::{migrations::Validators, Config, EraValidators};

Expand Down Expand Up @@ -97,7 +98,7 @@ impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
#[storage_alias]
type CommitteeSize = StorageValue<Elections, u32>;
#[storage_alias]
Expand All @@ -111,11 +112,11 @@ impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
let next_era_committee_size = NextEraCommitteeSize::get();
Self::store_temp("next_era_committee_size", next_era_committee_size);

Ok(())
Ok(Vec::new())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
ensure_storage_version::<P>(3)?;

let new_committee_size = CommitteeSize::get().ok_or("No `CommitteeSize` in the storage")?;
Expand Down
3 changes: 2 additions & 1 deletion pallets/support/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use frame_support::{
use frame_support::{
pallet_prelude::{PalletInfoAccess, StorageVersion, Weight},
traits::OnRuntimeUpgrade,
sp_std::vec::Vec
};

/// In order to run both pre- and post- checks around every migration, we entangle methods of
Expand All @@ -25,7 +26,7 @@ pub trait StorageMigration: OnRuntimeUpgrade {
let weight = Self::on_runtime_upgrade();

#[cfg(feature = "try-runtime")]
Self::post_upgrade().expect("Post upgrade should succeed");
Self::post_upgrade(Vec::new()).expect("Post upgrade should succeed");

weight
}
Expand Down