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

Xcm v5 migration for bhw #6391

Merged
merged 8 commits into from
Nov 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,50 @@ pub mod benchmark_helpers {
}
}
}

pub(crate) mod migrations {
use frame_support::pallet_prelude::*;
use snowbridge_core::TokenId;
use alloc::vec::Vec;

#[frame_support::storage_alias]
pub type OldNativeToForeignId<T: snowbridge_pallet_system::Config> = StorageMap<
snowbridge_pallet_system::Pallet<T>,
Blake2_128Concat,
xcm::v4::Location,
TokenId,
OptionQuery,
>;

/// One shot migration for NetworkId::Westend to NetworkId::ByGenesis(WESTEND_GENESIS_HASH)
pub struct MigrationForXcmV5<T: snowbridge_pallet_system::Config>(
core::marker::PhantomData<T>,
);
impl<T: snowbridge_pallet_system::Config> frame_support::traits::OnRuntimeUpgrade
for MigrationForXcmV5<T>
{
fn on_runtime_upgrade() -> Weight {
let mut weight = T::DbWeight::get().reads(1);

let translate_westend = |pre: xcm::v4::Location| -> Option<xcm::v5::Location> {
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1));
Some(xcm::v5::Location::try_from(pre).expect("valid location"))
};
snowbridge_pallet_system::ForeignToNativeId::<T>::translate_values(translate_westend);

let old_keys = OldNativeToForeignId::<T>::iter_keys().collect::<Vec<_>>();
for old_key in old_keys {
if let Some(old_val) = OldNativeToForeignId::<T>::get(&old_key) {
snowbridge_pallet_system::NativeToForeignId::<T>::insert(
&xcm::v5::Location::try_from(old_key.clone()).expect("valid location"),
old_val,
);
}
OldNativeToForeignId::<T>::remove(old_key);
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2));
}

weight
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -334,26 +334,13 @@ mod tests {
pub mod migration {
use super::*;
use bp_messages::LegacyLaneId;
use frame_support::traits::ConstBool;

parameter_types! {
pub AssetHubWestendToAssetHubRococoMessagesLane: LegacyLaneId = LegacyLaneId([0, 0, 0, 2]);
pub AssetHubWestendLocation: Location = Location::new(1, [Parachain(bp_asset_hub_westend::ASSET_HUB_WESTEND_PARACHAIN_ID)]);
pub AssetHubRococoUniversalLocation: InteriorLocation = [GlobalConsensus(RococoGlobalConsensusNetwork::get()), Parachain(bp_asset_hub_rococo::ASSET_HUB_ROCOCO_PARACHAIN_ID)].into();
}

/// Ensure that the existing lanes for the AHW<>AHR bridge are correctly configured.
pub type StaticToDynamicLanes = pallet_xcm_bridge_hub::migration::OpenBridgeForLane<
Runtime,
XcmOverBridgeHubRococoInstance,
AssetHubWestendToAssetHubRococoMessagesLane,
// the lanes are already created for AHR<>AHW, but we need to link them to the bridge
// structs
ConstBool<false>,
AssetHubWestendLocation,
AssetHubRococoUniversalLocation,
>;

mod v1_wrong {
use bp_messages::{LaneState, MessageNonce, UnrewardedRelayer};
use bp_runtime::AccountIdOf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,20 @@ pub type Migrations = (
Runtime,
bridge_to_rococo_config::WithBridgeHubRococoMessagesInstance,
>,
bridge_to_rococo_config::migration::StaticToDynamicLanes,
frame_support::migrations::RemoveStorage<
BridgeRococoMessagesPalletName,
OutboundLanesCongestedSignalsKey,
RocksDbWeight,
>,
pallet_bridge_relayers::migration::v1::MigrationToV1<Runtime, ()>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
snowbridge_pallet_system::migration::v0::InitializeOnUpgrade<
Runtime,
ConstU32<BRIDGE_HUB_ID>,
ConstU32<ASSET_HUB_ID>,
>,
bridge_to_ethereum_config::migrations::MigrationForXcmV5<Runtime>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
);

parameter_types! {
Expand Down
Loading