Skip to content

Commit

Permalink
Fix 956 (#721)
Browse files Browse the repository at this point in the history
* fix moonbeam bifrost-parachain account

* move slp migration to runtime

* fix paraId in bifrost-polkadot runtime
  • Loading branch information
herryho authored Aug 30, 2022
1 parent 1edf9ff commit ca5cb6f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 17 deletions.
8 changes: 2 additions & 6 deletions pallets/slp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use sp_io::hashing::blake2_256;
use sp_runtime::traits::TrailingZeroInput;

mod agents;
mod migration;
pub mod migration;
mod mock;
pub mod primitives;
mod tests;
Expand All @@ -79,7 +79,7 @@ pub const TIMEOUT_BLOCKS: u32 = 1000;
pub const BASE_WEIGHT: Weight = 1000;
type Hash<T> = <T as frame_system::Config>::Hash;
type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
type BalanceOf<T> = <<T as Config>::MultiCurrency as MultiCurrency<AccountIdOf<T>>>::Balance;
pub type BalanceOf<T> = <<T as Config>::MultiCurrency as MultiCurrency<AccountIdOf<T>>>::Balance;
type StakingAgentBoxType<T> = Box<
dyn StakingAgent<
MultiLocation,
Expand Down Expand Up @@ -657,10 +657,6 @@ pub mod pallet {
// Calculate weight
BASE_WEIGHT.saturating_mul(counter.into())
}

fn on_runtime_upgrade() -> Weight {
migration::update_minimums_maximums::<T>()
}
}

#[pallet::call]
Expand Down
7 changes: 1 addition & 6 deletions pallets/slp/src/tests/moonriver_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ fn initialize_moonriver_delegator() {
// let bifrost_parachain_account_id_20: [u8; 20] =
// hex_literal::hex!["7369626cd1070000000000000000000000000000"].into();
let bifrost_parachain_account_id_20: [u8; 20] =
<Runtime as frame_system::Config>::AccountId::encode(
&ParaId::from(2001u32).into_account_truncating(),
)
.as_slice()[..20]
.try_into()
.unwrap();
ParaId::from(2001).into_account_truncating();

// subaccount_id_0: 0x863c1faef3c3b8f8735ecb7f8ed18996356dd3de
let subaccount_id_0 = Slp::derivative_account_id_20(bifrost_parachain_account_id_20, 0);
Expand Down
58 changes: 55 additions & 3 deletions runtime/bifrost-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ use core::convert::TryInto;

use bifrost_slp::QueryResponseManager;
// A few exports that help ease life for downstream crates.
#[cfg(feature = "try-runtime")]
use crate::sp_api_hidden_includes_construct_runtime::hidden_include::traits::OnRuntimeUpgradeHelpersExt;
#[cfg(feature = "try-runtime")]
use bifrost_slp::{migration::DeprecatedMinimumsMaximums, BalanceOf, MinimumsMaximums};
#[cfg(feature = "try-runtime")]
use frame_support::ensure;
use frame_support::traits::OnRuntimeUpgrade;
pub use frame_support::{
construct_runtime, match_types, parameter_types,
traits::{
Expand All @@ -43,6 +50,8 @@ pub use frame_support::{
PalletId, RuntimeDebug, StorageValue,
};
use frame_system::limits::{BlockLength, BlockWeights};
#[cfg(feature = "try-runtime")]
use node_primitives::TokenInfo;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_timestamp::Call as TimestampCall;
use pallet_xcm::QueryStatus;
Expand Down Expand Up @@ -1549,7 +1558,7 @@ impl bifrost_flexible_fee::Config for Runtime {
}

parameter_types! {
pub BifrostParachainAccountId20: [u8; 20] = hex_literal::hex!["7369626cd1070000000000000000000000000000"].into();
pub BifrostParachainAccountId20: [u8; 20] = cumulus_primitives_core::ParaId::from(ParachainInfo::get()).into_account_truncating();
}

pub fn create_x2_multilocation(index: u16, currency_id: CurrencyId) -> MultiLocation {
Expand All @@ -1561,7 +1570,8 @@ pub fn create_x2_multilocation(index: u16, currency_id: CurrencyId) -> MultiLoca
AccountKey20 {
network: NetworkId::Any,
key: Slp::derivative_account_id_20(
hex_literal::hex!["7369626cd1070000000000000000000000000000"].into(),
cumulus_primitives_core::ParaId::from(ParachainInfo::get())
.into_account_truncating(),
index,
)
.into(),
Expand Down Expand Up @@ -2136,9 +2146,51 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
(),
SlpMigration,
>;

pub struct SlpMigration;
impl OnRuntimeUpgrade for SlpMigration {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
bifrost_slp::migration::update_minimums_maximums::<Runtime>()
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
for (currency_id, original_mins_max) in bifrost_slp::MinimumsAndMaximums::<Runtime>::iter()
{
Self::set_temp_storage(original_mins_max, currency_id.name().unwrap());
}

Ok(())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
for (currency_id, post_migration) in bifrost_slp::MinimumsAndMaximums::<Runtime>::iter() {
let mins_maxs: DeprecatedMinimumsMaximums<BalanceOf<Runtime>> =
Self::get_temp_storage(currency_id.name().unwrap()).unwrap();
let pre_migration = MinimumsMaximums::<BalanceOf<Runtime>> {
delegator_bonded_minimum: mins_maxs.delegator_bonded_minimum,
bond_extra_minimum: mins_maxs.bond_extra_minimum,
unbond_minimum: mins_maxs.unbond_minimum,
rebond_minimum: mins_maxs.rebond_minimum,
unbond_record_maximum: mins_maxs.unbond_record_maximum,
validators_back_maximum: mins_maxs.validators_back_maximum,
delegator_active_staking_maximum: mins_maxs.delegator_active_staking_maximum,
validators_reward_maximum: mins_maxs.validators_reward_maximum,
delegation_amount_minimum: mins_maxs.delegation_amount_minimum,
delegators_maximum: 100u16,
validators_maximum: 300u16,
};

ensure!(post_migration == pre_migration, "error ...");
}

Ok(())
}
}

#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
extern crate frame_benchmarking;
Expand Down
5 changes: 3 additions & 2 deletions runtime/bifrost-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ impl bifrost_flexible_fee::Config for Runtime {
}

parameter_types! {
pub BifrostParachainAccountId20: [u8; 20] = hex_literal::hex!["7369626cd1070000000000000000000000000000"].into();
pub BifrostParachainAccountId20: [u8; 20] = cumulus_primitives_core::ParaId::from(ParachainInfo::get()).into_account_truncating();
}

pub fn create_x2_multilocation(index: u16, currency_id: CurrencyId) -> MultiLocation {
Expand All @@ -1334,7 +1334,8 @@ pub fn create_x2_multilocation(index: u16, currency_id: CurrencyId) -> MultiLoca
AccountKey20 {
network: NetworkId::Any,
key: Slp::derivative_account_id_20(
hex_literal::hex!["7369626cd1070000000000000000000000000000"].into(),
cumulus_primitives_core::ParaId::from(ParachainInfo::get())
.into_account_truncating(),
index,
)
.into(),
Expand Down

0 comments on commit ca5cb6f

Please # to comment.