Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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 sp_std::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>(
sp_std::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 @@ -347,9 +347,7 @@ pub mod migration {
Runtime,
XcmOverBridgeHubRococoInstance,
AssetHubWestendToAssetHubRococoMessagesLane,
// the lanes are already created for AHR<>AHW, but we need to link them to the bridge
// structs
ConstBool<false>,
ConstBool<true>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we changing this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I removed data from live BHW

AssetHubWestendLocation,
AssetHubRococoUniversalLocation,
>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,14 @@ pub type Migrations = (
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