8000 Clean up `AssetManager` migration code by ghzlatarev · Pull Request #531 · Manta-Network/Manta · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Clean up AssetManager migration code #531

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

Merged
merged 1 commit into from
May 5, 2022
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
76 changes: 1 addition & 75 deletions pallets/asset-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ mod tests;
pub mod pallet {

use crate::weights::WeightInfo;
use frame_support::{
migration::have_storage_value, pallet_prelude::*, transactional, PalletId, StorageHasher,
};
use frame_support::{pallet_prelude::*, transactional, PalletId};
use frame_system::pallet_prelude::*;
use manta_primitives::{
assets::{
Expand Down Expand Up @@ -396,78 +394,6 @@ pub mod pallet {
pub fn account_id() -> T::AccountId {
T::PalletId::get().into_account()
}

pub fn set_genesis_configuration() -> Weight {
let mut weight: Weight = T::DbWeight::get().reads(1);
if have_storage_value(Self::name().as_bytes(), b"NextAssetId", &[]) {
log::warn!(" !!! Aborting, NextAssetId was already set.");
return weight;
}

weight = weight.saturating_add(T::DbWeight::get().reads(4));
let asset_id = <T::AssetConfig as AssetConfig<T>>::NativeAssetId::get();
let metadata = <T::AssetConfig as AssetConfig<T>>::NativeAssetMetadata::get();
let location = <T::AssetConfig as AssetConfig<T>>::NativeAssetLocation::get();
if have_storage_value(
Self::name().as_bytes(),
b"AssetIdLocation",
&Blake2_128Concat::hash(&asset_id.encode()),
) {
log::warn!(" !!! Aborting, AssetIdLocation was already set.");
return weight;
}

weight = weight.saturating_add(T::DbWeight::get().reads(1));
if have_storage_value(
Self::name().as_bytes(),
b"AssetIdMetadata",
&Blake2_128Concat::hash(&asset_id.encode()),
) {
log::warn!(" !!! Aborting, AssetIdMetadata was already set.");
return weight;
}

weight = weight.saturating_add(T::DbWeight::get().reads(1));
if have_storage_value(
Self::name().as_bytes(),
b"LocationAssetId",
&Blake2_128Concat::hash(&location.encode()),
) {
log::warn!(" !!! Aborting, LocationAssetId was already set.");
return weight;
}

weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));
let start_non_native_asset_id =
<T::AssetConfig as AssetConfig<T>>::StartNonNativeAssetId::get();
NextAssetId::<T>::set(start_non_native_asset_id);
log::info!(
" >>> NextAssetId set the value {}",
start_non_native_asset_id
);

weight = weight.saturating_add(T::DbWeight::get().reads_writes(0, 3));
AssetIdLocation::<T>::insert(&asset_id, &location);
log::info!(
" >>> AssetIdLocation inserted the key:value pair {}:{:?}",
asset_id,
location
);
AssetIdMetadata::<T>::insert(&asset_id, &metadata);
log::info!(
" >>> AssetIdMetadata inserted the key:value pair {}:{:?}",
asset_id,
metadata
);
LocationAssetId::<T>::insert(&location, &asset_id);
log::info!(
" >>> LocationAssetId inserted the key:value pair {:?}:{}",
location,
asset_id
);

weight
}
}

#[cfg(feature = "std")]
Expand Down
22 changes: 2 additions & 20 deletions runtime/calamari/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ use sp_version::RuntimeVersion;

use frame_support::{
construct_runtime, parameter_types,
traits::{
ConstU16, ConstU32, ConstU8, Contains, Currency, EnsureOneOf, OnRuntimeUpgrade,
PrivilegeCmp,
},
traits::{ConstU16, ConstU32, ConstU8, Contains, Currency, EnsureOneOf, PrivilegeCmp},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, WEIGHT_PER_SECOND},
DispatchClass, Weight,
Expand Down Expand Up @@ -748,24 +745,9 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsReversedWithSystemFirst,
SetAssetManagerGenesisConfiguration,
(),
>;

pub struct SetAssetManagerGenesisConfiguration;
impl OnRuntimeUpgrade for SetAssetManagerGenesisConfiguration {
fn on_runtime_upgrade() -> Weight {
AssetManager::set_genesis_configuration()
}
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
Ok(())
}
#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
Ok(())
}
}

impl_runtime_apis! {
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration {
Expand Down
0