From ec04016ce43e19b93f307b4bf47dd0c65b09f294 Mon Sep 17 00:00:00 2001 From: bear Date: Thu, 3 Nov 2022 13:34:27 +0800 Subject: [PATCH 1/6] Add grandpa migration --- node/runtime/pangolin/src/migrations.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/node/runtime/pangolin/src/migrations.rs b/node/runtime/pangolin/src/migrations.rs index 5403a3ea2..d102bfb96 100644 --- a/node/runtime/pangolin/src/migrations.rs +++ b/node/runtime/pangolin/src/migrations.rs @@ -39,6 +39,14 @@ fn migrate() -> Weight { items.iter().for_each(|item| migration::remove_storage_prefix(module, item, hash)); }); + use bridge_runtime_common::migrate_pallet_operation_mode; + let grandpa_modules = + vec![b"BridgePangoroGrandpa", b"BridgeRococoGrandpa", b"BridgeMoonbaseRelayGrandpa"]; + for module in grandpa_modules { + migrate_pallet_operation_mode(module); + // TODO, migrate BestFinalized + } + // 0 RuntimeBlockWeights::get().max_block } From a6a22478b011ff283c20aaa1778a00e665c78846 Mon Sep 17 00:00:00 2001 From: bear Date: Thu, 3 Nov 2022 14:15:58 +0800 Subject: [PATCH 2/6] Add message migration --- node/runtime/pangolin/src/migrations.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/node/runtime/pangolin/src/migrations.rs b/node/runtime/pangolin/src/migrations.rs index d102bfb96..9adc3123b 100644 --- a/node/runtime/pangolin/src/migrations.rs +++ b/node/runtime/pangolin/src/migrations.rs @@ -39,7 +39,9 @@ fn migrate() -> Weight { items.iter().for_each(|item| migration::remove_storage_prefix(module, item, hash)); }); - use bridge_runtime_common::migrate_pallet_operation_mode; + use bridge_runtime_common::{ + migrate_message_pallet_operation_mode, migrate_pallet_operation_mode, + }; let grandpa_modules = vec![b"BridgePangoroGrandpa", b"BridgeRococoGrandpa", b"BridgeMoonbaseRelayGrandpa"]; for module in grandpa_modules { @@ -47,6 +49,15 @@ fn migrate() -> Weight { // TODO, migrate BestFinalized } + let message_modules = vec![ + b"BridgePangoroMessages", + b"BridgePangolinParachainMessages", + b"BridgePangolinParachainAlphaMessages", + ]; + for module in message_modules { + migrate_message_pallet_operation_mode(module); + } + // 0 RuntimeBlockWeights::get().max_block } From c81137e4cf0d30245e0c413a34af5fbba875c25b Mon Sep 17 00:00:00 2001 From: bear Date: Thu, 3 Nov 2022 16:12:12 +0800 Subject: [PATCH 3/6] Add parachains migration --- Cargo.lock | 1 + node/runtime/pangolin/Cargo.toml | 2 + node/runtime/pangolin/src/migrations.rs | 73 +++++++++++++++++++++++-- 3 files changed, 70 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f7f9e5a2a..f331f541d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5827,6 +5827,7 @@ dependencies = [ "bp-darwinia-core", "bp-message-dispatch", "bp-messages", + "bp-parachains", "bp-polkadot-core", "bp-runtime", "bridge-runtime-common", diff --git a/node/runtime/pangolin/Cargo.toml b/node/runtime/pangolin/Cargo.toml index d0935deb3..a6ad40a30 100644 --- a/node/runtime/pangolin/Cargo.toml +++ b/node/runtime/pangolin/Cargo.toml @@ -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" } @@ -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", diff --git a/node/runtime/pangolin/src/migrations.rs b/node/runtime/pangolin/src/migrations.rs index 9adc3123b..32bebfba0 100644 --- a/node/runtime/pangolin/src/migrations.rs +++ b/node/runtime/pangolin/src/migrations.rs @@ -23,6 +23,20 @@ impl OnRuntimeUpgrade for CustomOnRuntimeUpgrade { } fn migrate() -> Weight { + // paritytech + use codec::Decode; + use frame_support::{storage::migration::storage_key_iter, Blake2_128Concat, StorageHasher}; + // 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; + use sp_api::HeaderT; + migration::move_pallet(b"BridgeRococoParachains", b"BridgeRococoParachain"); migration::move_pallet(b"BridgeMoonbaseRelayParachains", b"BridgeMoonbaseRelayParachain"); @@ -39,17 +53,29 @@ fn migrate() -> Weight { items.iter().for_each(|item| migration::remove_storage_prefix(module, item, hash)); }); - use bridge_runtime_common::{ - migrate_message_pallet_operation_mode, migrate_pallet_operation_mode, - }; - let grandpa_modules = + // Grandpa pallets + let grandpa_modules: Vec<&[u8]> = vec![b"BridgePangoroGrandpa", b"BridgeRococoGrandpa", b"BridgeMoonbaseRelayGrandpa"]; for module in grandpa_modules { + let item = b"BestFinalized"; + let hash = &[]; + if let Some(block_hash) = migration::take_storage_value::(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::
( + module, + imported_header_item, + &imported_header_hash, + ) { + migration::put_storage_value(module, item, hash, (header.number(), header.hash())); + } + } + migrate_pallet_operation_mode(module); - // TODO, migrate BestFinalized } - let message_modules = vec![ + // Message pallets + let message_modules: Vec<&[u8]> = vec![ b"BridgePangoroMessages", b"BridgePangolinParachainMessages", b"BridgePangolinParachainAlphaMessages", @@ -58,6 +84,41 @@ fn migrate() -> Weight { migrate_message_pallet_operation_mode(module); } + // Parachains pallets + #[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"]; + for module in parachains_modules { + for (para_id, best_para_head) in + storage_key_iter::(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(¶_id.encode()), + para_info, + ); + } + + put_pallet_operation_mode(module, BasicOperatingMode::Normal); + } + // 0 RuntimeBlockWeights::get().max_block } From 430f8f57a88b5dc879cc1b3054dbc893754d03b0 Mon Sep 17 00:00:00 2001 From: bear Date: Thu, 3 Nov 2022 16:21:56 +0800 Subject: [PATCH 4/6] Pangoro migration --- node/runtime/pangolin/src/migrations.rs | 1 + node/runtime/pangoro/src/migrations.rs | 29 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/node/runtime/pangolin/src/migrations.rs b/node/runtime/pangolin/src/migrations.rs index 32bebfba0..29b749c35 100644 --- a/node/runtime/pangolin/src/migrations.rs +++ b/node/runtime/pangolin/src/migrations.rs @@ -40,6 +40,7 @@ fn migrate() -> Weight { migration::move_pallet(b"BridgeRococoParachains", b"BridgeRococoParachain"); migration::move_pallet(b"BridgeMoonbaseRelayParachains", b"BridgeMoonbaseRelayParachain"); + // Removed pallets let removed_items: &[(&[u8], &[&[u8]])] = &[ ( b"ToPangolinParachainBacking", diff --git a/node/runtime/pangoro/src/migrations.rs b/node/runtime/pangoro/src/migrations.rs index 7120347b4..5e181569e 100644 --- a/node/runtime/pangoro/src/migrations.rs +++ b/node/runtime/pangoro/src/migrations.rs @@ -23,8 +23,37 @@ impl OnRuntimeUpgrade for CustomOnRuntimeUpgrade { } fn migrate() -> Weight { + // paritytech + use sp_api::HeaderT; + // darwinia-network + use bridge_runtime_common::{ + migrate_message_pallet_operation_mode, migrate_pallet_operation_mode, + }; + use frame_support::StorageHasher; + + // 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::(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::
( + 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 } From b57d024b9cde6c471bc834eeed82c0ecd0ea53cb Mon Sep 17 00:00:00 2001 From: bear Date: Thu, 3 Nov 2022 16:27:21 +0800 Subject: [PATCH 5/6] Self review --- node/runtime/pangolin/src/migrations.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/node/runtime/pangolin/src/migrations.rs b/node/runtime/pangolin/src/migrations.rs index 29b749c35..c8ded0ad7 100644 --- a/node/runtime/pangolin/src/migrations.rs +++ b/node/runtime/pangolin/src/migrations.rs @@ -54,12 +54,12 @@ fn migrate() -> Weight { items.iter().for_each(|item| migration::remove_storage_prefix(module, item, hash)); }); - // Grandpa pallets + // Grandpa let grandpa_modules: Vec<&[u8]> = vec![b"BridgePangoroGrandpa", b"BridgeRococoGrandpa", b"BridgeMoonbaseRelayGrandpa"]; - for module in grandpa_modules { - let item = b"BestFinalized"; - let hash = &[]; + let item = b"BestFinalized"; + let hash = &[]; + grandpa_modules.iter().for_each(|module| { if let Some(block_hash) = migration::take_storage_value::(module, item, hash) { let imported_header_item = b"ImportedHeaders"; let imported_header_hash = frame_support::Identity::hash(&block_hash.encode()); @@ -73,7 +73,7 @@ fn migrate() -> Weight { } migrate_pallet_operation_mode(module); - } + }); // Message pallets let message_modules: Vec<&[u8]> = vec![ @@ -81,11 +81,11 @@ fn migrate() -> Weight { b"BridgePangolinParachainMessages", b"BridgePangolinParachainAlphaMessages", ]; - for module in message_modules { + message_modules.iter().for_each(|module| { migrate_message_pallet_operation_mode(module); - } + }); - // Parachains pallets + // Parachains #[derive(Encode, Decode)] pub struct BestParaHead { pub at_relay_block_number: RelayBlockNumber, @@ -97,7 +97,7 @@ fn migrate() -> Weight { let parachains_modules: Vec<&[u8]> = vec![b"BridgeRococoParachain", b"BridgeMoonbaseRelayParachain"]; - for module in parachains_modules { + parachains_modules.iter().for_each(|module| { for (para_id, best_para_head) in storage_key_iter::(module, old_item).drain() { @@ -118,7 +118,7 @@ fn migrate() -> Weight { } put_pallet_operation_mode(module, BasicOperatingMode::Normal); - } + }); // 0 RuntimeBlockWeights::get().max_block From 3d14f5cc1a25ceee81140e4e3810f54c221bed13 Mon Sep 17 00:00:00 2001 From: bear Date: Thu, 3 Nov 2022 16:28:58 +0800 Subject: [PATCH 6/6] Format --- node/runtime/pangolin/src/migrations.rs | 2 +- node/runtime/pangoro/src/migrations.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/node/runtime/pangolin/src/migrations.rs b/node/runtime/pangolin/src/migrations.rs index c8ded0ad7..c48880b9d 100644 --- a/node/runtime/pangolin/src/migrations.rs +++ b/node/runtime/pangolin/src/migrations.rs @@ -26,6 +26,7 @@ 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}; @@ -35,7 +36,6 @@ fn migrate() -> Weight { put_pallet_operation_mode, }; use pallet_bridge_parachains::RelayBlockNumber; - use sp_api::HeaderT; migration::move_pallet(b"BridgeRococoParachains", b"BridgeRococoParachain"); migration::move_pallet(b"BridgeMoonbaseRelayParachains", b"BridgeMoonbaseRelayParachain"); diff --git a/node/runtime/pangoro/src/migrations.rs b/node/runtime/pangoro/src/migrations.rs index 5e181569e..393f73b0d 100644 --- a/node/runtime/pangoro/src/migrations.rs +++ b/node/runtime/pangoro/src/migrations.rs @@ -24,12 +24,12 @@ 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, }; - use frame_support::StorageHasher; // Removed pallets migration::remove_storage_prefix(b"TransactionPause", b"PausedTransactions", &[]);