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 26, 2021
1 parent d68fb91 commit fe08ce6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
28 changes: 27 additions & 1 deletion bin/node/runtime/pangolin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,11 +902,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 All @@ -916,7 +940,9 @@ impl OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
// let _ = Ring::deposit_creating(&BridgeMillauMessages::relayer_fund_account_id(), 1 << 50);
// --->

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

RuntimeBlockWeights::get().max_block
}
}

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 fe08ce6

Please sign in to comment.