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

Commit

Permalink
add migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavier Lau committed Jul 27, 2021
1 parent ac47ddd commit 979d9f5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
24 changes: 24 additions & 0 deletions bin/node/runtime/pangolin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,11 +968,35 @@ pub struct CustomOnRuntimeUpgrade;
impl OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
// --- paritytech ---
use frame_support::{migration, Identity};
// --- darwinia-network ---
use darwinia_header_mmr::NodeIndex;

// <--- Hack for local test
use frame_support::traits::Currency;
let _ = Ring::deposit_creating(&BridgeMillauMessages::relayer_fund_account_id(), 1 << 50);
// --->

darwinia_header_mmr::migration::migrate(b"HeaderMMR");

assert!(migration::storage_key_iter::<NodeIndex, Hash, Identity>(
b"HeaderMMR",
b"MMRNodeList"
)
.next()
.is_none());
assert!(!migration::have_storage_value(
b"HeaderMMR",
b"MMRNodeList",
&[]
));
assert!(!migration::have_storage_value(
b"HeaderMMR",
b"PruningConfiguration",
&[]
));

Ok(())
}

Expand Down
13 changes: 7 additions & 6 deletions frame/header-mmr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ pub mod pallet {
#[pallet::getter(fn mmr_size)]
pub type MmrSize<T> = StorageValue<_, NodeIndex, ValueQuery>;

/// MMR struct of the previous blocks, from first(genesis) to parent hash.
#[pallet::storage]
#[pallet::getter(fn mmr_node_list)]
pub type MMRNodeList<T: Config> = StorageMap<_, Identity, NodeIndex, T::Hash, OptionQuery>;

/// Peaks of the MMR
#[pallet::storage]
#[pallet::getter(fn peak_of)]
Expand Down Expand Up @@ -212,5 +207,11 @@ pub mod migration {
}
}

pub fn migrate() {}
pub fn migrate(module: impl AsRef<[u8]>) {
// --- paritytech ---
use frame_support::migration;

migration::remove_storage_prefix(module.as_ref(), b"MMRNodeList", &[]);
migration::remove_storage_prefix(module.as_ref(), b"PruningConfiguration", &[]);
}
}

0 comments on commit 979d9f5

Please sign in to comment.