Skip to content

Commit

Permalink
Fix BNC metadata (#1170)
Browse files Browse the repository at this point in the history
* Fix BNC metadata

* Remove `--disable-spec-version-check`
  • Loading branch information
ark930 authored Feb 1, 2024
1 parent f0de594 commit 6f7d0a9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 34 deletions.
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ try-kusama-runtime-upgrade:build-try-runtime
--runtime \
target/release/wbuild/bifrost-kusama-runtime/bifrost_kusama_runtime.compact.compressed.wasm \
on-runtime-upgrade \
--disable-spec-version-check \
--disable-idempotency-checks \
live \
--uri wss://hk.bifrost-rpc.liebi.com:443/ws
Expand All @@ -137,7 +136,6 @@ try-polkadot-runtime-upgrade:build-try-runtime
--runtime \
target/release/wbuild/bifrost-polkadot-runtime/bifrost_polkadot_runtime.compact.compressed.wasm \
on-runtime-upgrade \
--disable-spec-version-check \
--disable-idempotency-checks \
live \
--uri wss://hk.p.bifrost-rpc.liebi.com:443/ws
Expand All @@ -152,7 +150,6 @@ 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-spec-version-check \
--disable-idempotency-checks \
snap -p [email protected]

Expand All @@ -166,7 +163,6 @@ 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-spec-version-check \
--disable-idempotency-checks \
snap -p [email protected]

Expand Down
55 changes: 26 additions & 29 deletions pallets/asset-registry/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ pub fn update_blp_metadata<T: Config>(pool_count: u32) -> Weight {
T::DbWeight::get().reads(pool_count.into()) + T::DbWeight::get().writes(pool_count.into())
}

const BNC_LOCATION: MultiLocation = MultiLocation {
parents: 0,
interior: X1(GeneralKey {
length: 2,
data: [
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0,
],
}),
};

pub struct InsertBNCMetadata<T>(PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for InsertBNCMetadata<T> {
fn on_runtime_upgrade() -> Weight {
Expand All @@ -56,26 +67,16 @@ impl<T: Config> OnRuntimeUpgrade for InsertBNCMetadata<T> {
},
);

CurrencyIdToLocations::<T>::insert(
BNC,
MultiLocation {
parents: 0,
interior: X1(GeneralKey {
length: 2,
data: [
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
],
}),
},
);
Weight::from(T::DbWeight::get().reads_writes(2 as u64 + 1, 2 as u64 + 1))
CurrencyIdToLocations::<T>::insert(BNC, BNC_LOCATION);

LocationToCurrencyIds::<T>::insert(BNC_LOCATION, BNC);

Weight::from(T::DbWeight::get().reads_writes(3 as u64 + 1, 3 as u64 + 1))
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
assert!(CurrencyMetadatas::<T>::get(BNC).is_none());
assert!(CurrencyIdToLocations::<T>::get(BNC).is_none());
assert!(LocationToCurrencyIds::<T>::get(BNC_LOCATION).is_none());

Ok(sp_std::vec![])
}
Expand All @@ -99,26 +100,22 @@ impl<T: Config> OnRuntimeUpgrade for InsertBNCMetadata<T> {
);

let location = CurrencyIdToLocations::<T>::get(BNC);
assert_eq!(
location,
Some(MultiLocation {
parents: 0,
interior: X1(GeneralKey {
length: 2,
data: [
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0
]
}),
})
);
assert_eq!(location, Some(BNC_LOCATION));

log::info!(
target: LOG_TARGET,
"InsertBNCMetadata post-migrate storage: {:?}",
location
);

let currency = LocationToCurrencyIds::<T>::get(BNC_LOCATION);
assert_eq!(currency, Some(BNC));
log::info!(
target: LOG_TARGET,
"InsertBNCMetadata post-migrate storage: {:?}",
currency
);

Ok(())
}
}
2 changes: 1 addition & 1 deletion runtime/bifrost-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,7 @@ pub mod migrations {
use super::*;

/// Unreleased migrations. Add new ones here:
pub type Unreleased = ();
pub type Unreleased = (bifrost_asset_registry::migration::InsertBNCMetadata<Runtime>,);
}

/// Executive: handles dispatch to the various modules.
Expand Down

0 comments on commit 6f7d0a9

Please sign in to comment.