Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix try runtime kusama #1675

Merged
merged 3 commits into from
Feb 28, 2025
Merged
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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 [email protected]

Expand All @@ -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 [email protected]

Expand Down
35 changes: 35 additions & 0 deletions pallets/fee-share/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,38 @@ impl<T: Config> OnRuntimeUpgrade for FeeShareOnRuntimeUpgrade<T> {
Ok(())
}
}

pub struct BifrostKusamaFeeShareOnRuntimeUpgrade<T>(PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for BifrostKusamaFeeShareOnRuntimeUpgrade<T> {
fn on_runtime_upgrade() -> Weight {
log::info!("Bifrost `on_runtime_upgrade`...");

if StorageVersion::get::<Pallet<T>>() == 0 {
log::info!("Migrating fee-share storage to v1");
StorageVersion::new(1).put::<Pallet<T>>();
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_std::prelude::Vec<u8>, sp_runtime::DispatchError> {
log::info!(
"fee-share before migration: version: {:?}",
StorageVersion::get::<Pallet<T>>(),
);

Ok(sp_std::prelude::Vec::new())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_: sp_std::prelude::Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
log::info!(
"fee-share after migration: version: {:?}",
StorageVersion::get::<Pallet<T>>(),
);
Ok(())
}
}
1 change: 1 addition & 0 deletions runtime/bifrost-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,7 @@ pub mod migrations {
pub type Unreleased = (
// permanent migration, do not remove
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
bifrost_fee_share::migration::BifrostKusamaFeeShareOnRuntimeUpgrade<Runtime>,
bifrost_system_staking::migration::SystemStakingOnRuntimeUpgrade<Runtime>,
bifrost_parachain_staking::migrations::v1::MigrateToV1<Runtime>,
bifrost_vtoken_voting::migration::v5::MigrateToV5<Runtime>,
Expand Down
68 changes: 37 additions & 31 deletions runtime/bifrost-kusama/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,46 +794,52 @@ 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};

pub struct MigrateReferendumInfoFor;

impl OnRuntimeUpgrade for MigrateReferendumInfoFor {
fn on_runtime_upgrade() -> Weight {
let current_block_number = frame_system::Pallet::<Runtime>::block_number();
let mut weight: Weight = Weight::zero();

// Translate the storage and update accordingly
ReferendumInfoFor::<Runtime>::translate::<ReferendumInfoOf<Runtime, ()>, _>(
|_: ReferendumIndex, value: ReferendumInfoOf<Runtime, ()>| {
weight += <Runtime as frame_system::Config>::DbWeight::get().reads(1);

if let ReferendumInfoOf::<Runtime, ()>::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::<Referenda>() == 1 {
let current_block_number = frame_system::Pallet::<Runtime>::block_number();
let mut weight: Weight = Weight::zero();

// Translate the storage and update accordingly
ReferendumInfoFor::<Runtime>::translate::<ReferendumInfoOf<Runtime, ()>, _>(
|_: ReferendumIndex, value: ReferendumInfoOf<Runtime, ()>| {
weight += <Runtime as frame_system::Config>::DbWeight::get().reads(1);

if let ReferendumInfoOf::<Runtime, ()>::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::<Runtime, ()>::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::<Runtime, ()>::Ongoing(status))
} else {
// If the status isn't Ongoing, return it unchanged
Some(value)
}
},
);

weight + <Runtime as frame_system::Config>::DbWeight::get().writes(1)
weight + <Runtime as frame_system::Config>::DbWeight::get().writes(1)
} else {
<Runtime as frame_system::Config>::DbWeight::get().reads(1)
}
}
}
}