Skip to content

Commit

Permalink
fixed merge conflicts, updated migration code
Browse files Browse the repository at this point in the history
  • Loading branch information
zees-dev committed Sep 6, 2023
1 parent 58e0278 commit 64c0b72
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
16 changes: 8 additions & 8 deletions runtime/src/migrations/futurepass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use frame_support::{
pub struct Upgrade;
impl OnRuntimeUpgrade for Upgrade {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
fn pre_upgrade() -> Result<crate::Vec<u8>, &'static str> {
Ok(v1::pre_upgrade()?)
}

Expand All @@ -44,7 +44,7 @@ impl OnRuntimeUpgrade for Upgrade {
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
fn post_upgrade(_state: crate::Vec<u8>) -> Result<(), &'static str> {
Ok(v1::post_upgrade()?)
}
}
Expand Down Expand Up @@ -84,13 +84,13 @@ pub mod v1 {
/// - validate value is retrievable from the key via using twoxconcat hashing algorithm
/// - validate value is not retrievable from the key using black2_128concat hashing algorithm
#[cfg(feature = "try-runtime")]
pub fn pre_upgrade() -> Result<(), &'static str> {
pub fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
log::info!(target: "🛠️ Migration", "Futurepass: Upgrade to v1 Pre Upgrade.");

let onchain = Futurepass::on_chain_storage_version();
// return early if upgrade has already been done
if onchain == 1 {
return Ok(())
return Ok(crate::Vec::new())
}
assert_eq!(onchain, 0);

Expand Down Expand Up @@ -126,15 +126,15 @@ pub mod v1 {
return Err("🛑 Futurepass: Value found for the key using blake2_128concat hashing algorithm in pre-upgrade check");
}

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

pub fn migrate<T: pallet_futurepass::Config>() -> Weight
where
<T as frame_system::Config>::AccountId:
From<sp_core::H160> + EncodeLike<seed_primitives::AccountId>,
{
let mut weight = 0;
let mut weight = Weight::from_ref_time(0u64);
for (key, value) in migration::storage_key_iter::<T::AccountId, T::AccountId, Twox64Concat>(
MODULE_PREFIX,
STORAGE_ITEM_NAME,
Expand Down Expand Up @@ -228,13 +228,13 @@ pub mod v1 {
sp_io::storage::set(&storage_location_twox64concat, &bob_futurepass.encode());

// validate pre-upgrade checks pass
Upgrade::pre_upgrade().unwrap();
let state_data = Upgrade::pre_upgrade().unwrap();

// perform runtime upgrade
Upgrade::on_runtime_upgrade();

// validate post-upgrade checks pass
Upgrade::post_upgrade().unwrap();
Upgrade::post_upgrade(state_data).unwrap();
});
}
}
Expand Down
22 changes: 7 additions & 15 deletions runtime/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,22 @@ use sp_std::vec::Vec;

pub struct AllMigrations;
impl OnRuntimeUpgrade for AllMigrations {
// #[cfg(feature = "try-runtime")]
// fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
// let data = Vec::new();
// Ok(data)
// }

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

fn on_runtime_upgrade() -> Weight {
let mut weight = Weight::from(0u32);
let mut weight = Weight::from_ref_time(0u64);
weight += futurepass::Upgrade::on_runtime_upgrade();
weight
}

// #[cfg(feature = "try-runtime")]
// fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
futurepass::Upgrade::post_upgrade()?;
Ok(())
fn post_upgrade(state: Vec<u8>) -> Result<(), &'static str> {
Ok(futurepass::Upgrade::post_upgrade(state)?)
// Ok(())
}
}

Expand Down

0 comments on commit 64c0b72

Please sign in to comment.