From 2bd12035a7bcbca0ae176d06decf0683a67e7632 Mon Sep 17 00:00:00 2001 From: yooml Date: Fri, 28 Feb 2025 11:25:36 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=F0=9F=90=9B=20add=20BifrostKusamaFe?= =?UTF-8?q?eShareOnRuntimeUpgrade?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pallets/fee-share/src/migration.rs | 35 ++++++++++++++++++++++++++++++ runtime/bifrost-kusama/src/lib.rs | 1 + 2 files changed, 36 insertions(+) diff --git a/pallets/fee-share/src/migration.rs b/pallets/fee-share/src/migration.rs index fd496d1eb..b77d487e3 100644 --- a/pallets/fee-share/src/migration.rs +++ b/pallets/fee-share/src/migration.rs @@ -79,3 +79,38 @@ impl OnRuntimeUpgrade for FeeShareOnRuntimeUpgrade { Ok(()) } } + +pub struct BifrostKusamaFeeShareOnRuntimeUpgrade(PhantomData); +impl OnRuntimeUpgrade for BifrostKusamaFeeShareOnRuntimeUpgrade { + fn on_runtime_upgrade() -> Weight { + log::info!("Bifrost `on_runtime_upgrade`..."); + + if StorageVersion::get::>() == 0 { + log::info!("Migrating fee-share storage to v1"); + StorageVersion::new(1).put::>(); + T::DbWeight::get().reads(1) + T::DbWeight::get().writes(1) + } else { + log::warn!("fee-share StorageVersion should be 0."); + T::DbWeight::get().reads(1) + } + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, sp_runtime::DispatchError> { + log::info!( + "fee-share before migration: version: {:?}", + StorageVersion::get::>(), + ); + + Ok(sp_std::prelude::Vec::new()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_: sp_std::prelude::Vec) -> Result<(), sp_runtime::DispatchError> { + log::info!( + "fee-share after migration: version: {:?}", + StorageVersion::get::>(), + ); + Ok(()) + } +} diff --git a/runtime/bifrost-kusama/src/lib.rs b/runtime/bifrost-kusama/src/lib.rs index 93a9e3add..c8ebdc575 100644 --- a/runtime/bifrost-kusama/src/lib.rs +++ b/runtime/bifrost-kusama/src/lib.rs @@ -1916,6 +1916,7 @@ pub mod migrations { pub type Unreleased = ( // permanent migration, do not remove pallet_xcm::migration::MigrateToLatestXcmVersion, + bifrost_fee_share::migration::BifrostKusamaFeeShareOnRuntimeUpgrade, bifrost_system_staking::migration::SystemStakingOnRuntimeUpgrade, bifrost_parachain_staking::migrations::v1::MigrateToV1, bifrost_vtoken_voting::migration::v5::MigrateToV5, From f7ebcbcaa0b031efca8526f9a01191b105e795e1 Mon Sep 17 00:00:00 2001 From: SunTiebing <1045060705@qq.com> Date: Fri, 28 Feb 2025 12:49:22 +0800 Subject: [PATCH 2/3] fix referenda migration --- runtime/bifrost-kusama/src/migration.rs | 68 ++++++++++++++----------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/runtime/bifrost-kusama/src/migration.rs b/runtime/bifrost-kusama/src/migration.rs index aad249620..58b43c839 100644 --- a/runtime/bifrost-kusama/src/migration.rs +++ b/runtime/bifrost-kusama/src/migration.rs @@ -794,7 +794,8 @@ pub mod vsbond_auction { } pub mod update_referenda_referendum_info { - use crate::{Runtime, Weight}; + use crate::{Referenda, Runtime, Weight}; + use frame_support::pallet_prelude::StorageVersion; use frame_support::traits::OnRuntimeUpgrade; use pallet_referenda::{ReferendumIndex, ReferendumInfoFor, ReferendumInfoOf}; @@ -802,38 +803,43 @@ pub mod update_referenda_referendum_info { impl OnRuntimeUpgrade for MigrateReferendumInfoFor { fn on_runtime_upgrade() -> Weight { - let current_block_number = frame_system::Pallet::::block_number(); - let mut weight: Weight = Weight::zero(); - - // Translate the storage and update accordingly - ReferendumInfoFor::::translate::, _>( - |_: ReferendumIndex, value: ReferendumInfoOf| { - weight += ::DbWeight::get().reads(1); - - if let ReferendumInfoOf::::Ongoing(mut status) = value { - // Check if there's an alarm and update the block numbers - if let Some((mut block, (mut end_schedule_block, value))) = status.alarm { - block = block - .saturating_sub(current_block_number) - .saturating_add(block); - end_schedule_block = end_schedule_block - .saturating_sub(current_block_number) - .saturating_add(end_schedule_block); - - // Update the status with the new block numbers - status.alarm = Some((block, (end_schedule_block, value))); - } + if StorageVersion::get::() == 1 { + let current_block_number = frame_system::Pallet::::block_number(); + let mut weight: Weight = Weight::zero(); + + // Translate the storage and update accordingly + ReferendumInfoFor::::translate::, _>( + |_: ReferendumIndex, value: ReferendumInfoOf| { + weight += ::DbWeight::get().reads(1); + + if let ReferendumInfoOf::::Ongoing(mut status) = value { + // Check if there's an alarm and update the block numbers + if let Some((mut block, (mut end_schedule_block, value))) = status.alarm + { + block = block + .saturating_sub(current_block_number) + .saturating_add(block); + end_schedule_block = end_schedule_block + .saturating_sub(current_block_number) + .saturating_add(end_schedule_block); + + // Update the status with the new block numbers + status.alarm = Some((block, (end_schedule_block, value))); + } - // Wrap the updated status back into the ReferendumInfo enum - Some(ReferendumInfoOf::::Ongoing(status)) - } else { - // If the status isn't Ongoing, return it unchanged - Some(value) - } - }, - ); + // Wrap the updated status back into the ReferendumInfo enum + Some(ReferendumInfoOf::::Ongoing(status)) + } else { + // If the status isn't Ongoing, return it unchanged + Some(value) + } + }, + ); - weight + ::DbWeight::get().writes(1) + weight + ::DbWeight::get().writes(1) + } else { + ::DbWeight::get().reads(1) + } } } } From 71ef07b69ee92dc95ed74935f3c45e5f15054d8f Mon Sep 17 00:00:00 2001 From: SunTiebing <1045060705@qq.com> Date: Fri, 28 Feb 2025 15:21:47 +0800 Subject: [PATCH 3/3] Remove idempotent check restrictions --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index d700c66f1..7eb9310a8 100644 --- a/Makefile +++ b/Makefile @@ -139,6 +139,7 @@ try-kusama-runtime-upgrade:build-try-runtime --runtime \ target/release/wbuild/bifrost-kusama-runtime/bifrost_kusama_runtime.compact.compressed.wasm \ on-runtime-upgrade \ + --disable-idempotency-checks \ live \ --uri wss://hk.bifrost-rpc.liebi.com:443/ws @@ -148,6 +149,7 @@ try-polkadot-runtime-upgrade:build-try-runtime --runtime \ target/release/wbuild/bifrost-polkadot-runtime/bifrost_polkadot_runtime.compact.compressed.wasm \ on-runtime-upgrade \ + --disable-idempotency-checks \ live \ --uri wss://hk.p.bifrost-rpc.liebi.com:443/ws @@ -161,6 +163,7 @@ try-polkadot-runtime-upgrade-snap:build-try-runtime --runtime \ target/release/wbuild/bifrost-polkadot-runtime/bifrost_polkadot_runtime.compact.compressed.wasm \ on-runtime-upgrade \ + --disable-idempotency-checks \ --checks=all \ snap -p bifrost_polkadot@latest.snap @@ -174,6 +177,7 @@ try-kusama-runtime-upgrade-snap:build-try-runtime --runtime \ target/release/wbuild/bifrost-kusama-runtime/bifrost_kusama_runtime.compact.compressed.wasm \ on-runtime-upgrade \ + --disable-idempotency-checks \ --checks=all \ snap -p bifrost@latest.snap