Skip to content
This repository was archived by the owner on Mar 13, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions node/runtime/pangolin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ to-tron-backing = { default-features = false, path = "../.
bp-darwinia-core = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "darwinia-v0.13.0" }
bp-message-dispatch = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "darwinia-v0.13.0" }
bp-messages = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "darwinia-v0.13.0" }
bp-parachains = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "darwinia-v0.13.0" }
bp-polkadot-core = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "darwinia-v0.13.0" }
bp-runtime = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "darwinia-v0.13.0" }
bridge-runtime-common = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "darwinia-v0.13.0" }
Expand Down Expand Up @@ -148,6 +149,7 @@ std = [
"bp-darwinia-core/std",
"bp-messages/std",
"bp-message-dispatch/std",
"bp-parachains/std",
"bp-polkadot-core/std",
"bp-runtime/std",
"bridge-runtime-common/std",
Expand Down
81 changes: 81 additions & 0 deletions node/runtime/pangolin/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,24 @@ impl OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
}

fn migrate() -> Weight {
// paritytech
use codec::Decode;
use frame_support::{storage::migration::storage_key_iter, Blake2_128Concat, StorageHasher};
use sp_api::HeaderT;
// darwinia-network
use bp_parachains::{BestParaHeadHash, ParaInfo};
use bp_polkadot_core::parachains::{ParaHash, ParaId};
use bp_runtime::BasicOperatingMode;
use bridge_runtime_common::{
migrate_message_pallet_operation_mode, migrate_pallet_operation_mode,
put_pallet_operation_mode,
};
use pallet_bridge_parachains::RelayBlockNumber;

migration::move_pallet(b"BridgeRococoParachains", b"BridgeRococoParachain");
migration::move_pallet(b"BridgeMoonbaseRelayParachains", b"BridgeMoonbaseRelayParachain");

// Removed pallets
let removed_items: &[(&[u8], &[&[u8]])] = &[
(
b"ToPangolinParachainBacking",
Expand All @@ -39,6 +54,72 @@ fn migrate() -> Weight {
items.iter().for_each(|item| migration::remove_storage_prefix(module, item, hash));
});

// Grandpa
let grandpa_modules: Vec<&[u8]> =
vec![b"BridgePangoroGrandpa", b"BridgeRococoGrandpa", b"BridgeMoonbaseRelayGrandpa"];
let item = b"BestFinalized";
let hash = &[];
grandpa_modules.iter().for_each(|module| {
if let Some(block_hash) = migration::take_storage_value::<Hash>(module, item, hash) {
let imported_header_item = b"ImportedHeaders";
let imported_header_hash = frame_support::Identity::hash(&block_hash.encode());
if let Some(header) = migration::get_storage_value::<Header>(
module,
imported_header_item,
&imported_header_hash,
) {
migration::put_storage_value(module, item, hash, (header.number(), header.hash()));
}
}

migrate_pallet_operation_mode(module);
});

// Message pallets
let message_modules: Vec<&[u8]> = vec![
b"BridgePangoroMessages",
b"BridgePangolinParachainMessages",
b"BridgePangolinParachainAlphaMessages",
];
message_modules.iter().for_each(|module| {
migrate_message_pallet_operation_mode(module);
});

// Parachains
#[derive(Encode, Decode)]
pub struct BestParaHead {
pub at_relay_block_number: RelayBlockNumber,
pub head_hash: ParaHash,
pub next_imported_hash_position: u32,
}
let old_item = b"BestParaHeads";
let new_item = b"ParasInfo";

let parachains_modules: Vec<&[u8]> =
vec![b"BridgeRococoParachain", b"BridgeMoonbaseRelayParachain"];
parachains_modules.iter().for_each(|module| {
for (para_id, best_para_head) in
storage_key_iter::<ParaId, BestParaHead, Blake2_128Concat>(module, old_item).drain()
{
let para_info = ParaInfo {
best_head_hash: BestParaHeadHash {
at_relay_block_number: best_para_head.at_relay_block_number,
head_hash: best_para_head.head_hash,
},
next_imported_hash_position: best_para_head.next_imported_hash_position,
};

migration::put_storage_value(
module,
new_item,
&Blake2_128Concat::hash(&para_id.encode()),
para_info,
);
}

put_pallet_operation_mode(module, BasicOperatingMode::Normal);
});

// 0
RuntimeBlockWeights::get().max_block
}
29 changes: 29 additions & 0 deletions node/runtime/pangoro/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,37 @@ impl OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
}

fn migrate() -> Weight {
// paritytech
use frame_support::StorageHasher;
use sp_api::HeaderT;
// darwinia-network
use bridge_runtime_common::{
migrate_message_pallet_operation_mode, migrate_pallet_operation_mode,
};

// Removed pallets
migration::remove_storage_prefix(b"TransactionPause", b"PausedTransactions", &[]);

// Grandpa
let module = b"BridgePangolinGrandpa";
let item = b"BestFinalized";
let hash = &[];
if let Some(block_hash) = migration::take_storage_value::<Hash>(module, item, hash) {
let imported_header_item = b"ImportedHeaders";
let imported_header_hash = frame_support::Identity::hash(&block_hash.encode());
if let Some(header) = migration::get_storage_value::<Header>(
module,
imported_header_item,
&imported_header_hash,
) {
migration::put_storage_value(module, item, hash, (header.number(), header.hash()));
}
}
migrate_pallet_operation_mode(module);

// Message
migrate_message_pallet_operation_mode(b"BridgePangolinMessages");

// 0
RuntimeBlockWeights::get().max_block
}