Skip to content
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
38 changes: 3 additions & 35 deletions node/service/src/chain_spec/bifrost_kusama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@

use crate::chain_spec::{get_account_id_from_seed, get_from_seed, RelayExtensions};
use bifrost_kusama_runtime::{
AccountId, Balance, BalancesConfig, BlockNumber, InflationInfo, Range, SS58Prefix,
VestingConfig,
AccountId, Balance, BalancesConfig, BlockNumber, SS58Prefix, VestingConfig,
};
use bifrost_primitives::{
BifrostKusamaChainId, CurrencyId, CurrencyId::*, TokenInfo, TokenSymbol::*,
};
use bifrost_runtime_common::bridge_xcm_helper::DEFAULT_XCM_FEES_IK_PERSPECTIVE;
use bifrost_runtime_common::{constants::currency::DOLLARS, constants::time::HOURS, AuraId};
use bifrost_runtime_common::{constants::currency::DOLLARS, AuraId};
use cumulus_primitives_core::ParaId;
use frame_benchmarking::{account, whitelisted_caller};
use hex_literal::hex;
Expand All @@ -34,7 +33,7 @@ use sc_service::ChainType;
use serde::de::DeserializeOwned;
use serde_json as json;
use sp_core::{crypto::UncheckedInto, sr25519};
use sp_runtime::{traits::Zero, Perbill};
use sp_runtime::traits::Zero;
use std::{
collections::BTreeMap,
fs::{read_dir, File},
Expand All @@ -51,37 +50,6 @@ pub fn ENDOWMENT() -> u128 {
1_000_000 * DOLLARS
}

const BLOCKS_PER_ROUND: u32 = 2 * HOURS;

pub fn inflation_config() -> InflationInfo<Balance> {
fn to_round_inflation(annual: Range<Perbill>) -> Range<Perbill> {
use bifrost_parachain_staking::inflation::{
perbill_annual_to_perbill_round, BLOCKS_PER_YEAR,
};
perbill_annual_to_perbill_round(
annual,
// rounds per year
BLOCKS_PER_YEAR / BLOCKS_PER_ROUND,
)
}
let annual = Range {
min: Perbill::from_percent(4),
ideal: Perbill::from_percent(5),
max: Perbill::from_percent(5),
};
InflationInfo {
// staking expectations
expect: Range {
min: 100_000 * DOLLARS,
ideal: 200_000 * DOLLARS,
max: 500_000 * DOLLARS,
},
// annual inflation
annual,
round: to_round_inflation(annual),
}
}

fn bifrost_kusama_properties() -> Properties {
let mut properties = Properties::new();
let mut token_symbol: Vec<String> = vec![];
Expand Down
101 changes: 99 additions & 2 deletions pallets/parachain-staking/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use frame_support::{
pallet,
pallet_prelude::PhantomData,
storage_alias,
traits::{Get, OnRuntimeUpgrade, ReservableCurrency},
weights::Weight,
traits::{Get, LockableCurrency, OnRuntimeUpgrade, ReservableCurrency},
weights::{RuntimeDbWeight, Weight},
Twox64Concat,
};
#[cfg(feature = "try-runtime")]
Expand Down Expand Up @@ -63,6 +63,103 @@ const COLLATOR_COMMISSION: Perbill = Perbill::from_percent(10);
const PARACHAIN_BOND_RESERVE_PERCENT: Percent = Percent::from_percent(0);
const BLOCKS_PER_ROUND: u32 = 2 * 300;

/// Remove participant account locks before the pallet storage is deleted from a runtime.
pub struct RemoveStakingParticipantLocks<T, C, DbWeight>(PhantomData<(T, C, DbWeight)>);
impl<T, C, DbWeight> OnRuntimeUpgrade for RemoveStakingParticipantLocks<T, C, DbWeight>
where
T: frame_system::Config + pallet_balances::Config,
C: LockableCurrency<T::AccountId>,
DbWeight: Get<RuntimeDbWeight>,
{
fn on_runtime_upgrade() -> Weight {
let mut candidates = 0u64;
let mut delegators = 0u64;

for (account, _) in storage_key_iter::<
T::AccountId,
CandidateMetadata<<C as Currency<T::AccountId>>::Balance>,
Twox64Concat,
>(b"ParachainStaking", b"CandidateInfo")
{
C::remove_lock(COLLATOR_LOCK_ID, &account);
candidates = candidates.saturating_add(1);
}

for (account, _) in storage_key_iter::<
T::AccountId,
Delegator<T::AccountId, <C as Currency<T::AccountId>>::Balance>,
Twox64Concat,
>(b"ParachainStaking", b"DelegatorState")
{
C::remove_lock(DELEGATOR_LOCK_ID, &account);
delegators = delegators.saturating_add(1);
}

log::info!(
target: "parachain-staking-migration",
"Removed staking locks for {candidates} candidates and {delegators} delegators",
);

DbWeight::get().reads_writes(
candidates.saturating_add(delegators),
candidates.saturating_add(delegators),
)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
let candidate_accounts: Vec<T::AccountId> = storage_key_iter::<
T::AccountId,
CandidateMetadata<<C as Currency<T::AccountId>>::Balance>,
Twox64Concat,
>(b"ParachainStaking", b"CandidateInfo")
.map(|(account, _)| account)
.collect();
let delegator_accounts: Vec<T::AccountId> = storage_key_iter::<
T::AccountId,
Delegator<T::AccountId, <C as Currency<T::AccountId>>::Balance>,
Twox64Concat,
>(b"ParachainStaking", b"DelegatorState")
.map(|(account, _)| account)
.collect();

log::info!(
target: "parachain-staking-migration",
"pre_upgrade: {} candidate locks and {} delegator locks to remove",
candidate_accounts.len(),
delegator_accounts.len(),
);

Ok((candidate_accounts, delegator_accounts).encode())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(state: Vec<u8>) -> Result<(), TryRuntimeError> {
let (candidate_accounts, delegator_accounts): (Vec<T::AccountId>, Vec<T::AccountId>) =
Decode::decode(&mut state.as_slice()).map_err(|_| {
TryRuntimeError::Other("failed to decode staking participant lock migration state")
})?;

for account in candidate_accounts {
let locks = pallet_balances::Pallet::<T>::locks(&account);
ensure!(
!locks.iter().any(|lock| lock.id == COLLATOR_LOCK_ID),
"candidate staking lock still present after migration"
);
}

for account in delegator_accounts {
let locks = pallet_balances::Pallet::<T>::locks(&account);
ensure!(
!locks.iter().any(|lock| lock.id == DELEGATOR_LOCK_ID),
"delegator staking lock still present after migration"
);
}

Ok(())
}
}

/// Migration to purge staking storage bloat for `Points` and `AtStake` storage items
pub struct InitGenesisMigration<T>(PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for InitGenesisMigration<T> {
Expand Down
9 changes: 4 additions & 5 deletions runtime/bifrost-kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ bifrost-stable-asset = { workspace = true }
# Bifrost
bifrost-asset-registry = { workspace = true }
bifrost-p-k-bridge = { workspace = true }
bifrost-parachain-staking = { workspace = true }
bifrost-currencies = { workspace = true }
bifrost-farming = { workspace = true, features = ["kusama"] }
bifrost-farming-rpc-runtime-api = { workspace = true }
Expand All @@ -134,7 +135,6 @@ bifrost-vstoken-conversion = { workspace = true }
bifrost-vtoken-minting = { workspace = true, features = ["kusama"] }
bifrost-vtoken-voting = { workspace = true, features = [ "kusama" ] }
bifrost-xcm-interface = { workspace = true }
bifrost-parachain-staking = { workspace = true }
lend-market = { workspace = true }
lend-market-rpc-runtime-api = { workspace = true }
pallet-prices = { workspace = true }
Expand Down Expand Up @@ -239,6 +239,7 @@ std = [
"bifrost-primitives/std",
"bifrost-asset-registry/std",
"bifrost-p-k-bridge/std",
"bifrost-parachain-staking/std",
"bifrost-currencies/std",
"bifrost-farming-rpc-runtime-api/std",
"bifrost-farming/std",
Expand All @@ -264,7 +265,6 @@ std = [
"pallet-prices/std",
"leverage-staking/std",
"bifrost-stable-asset/std",
"bifrost-parachain-staking/std",
"bifrost-xcm-interface/std",
"bifrost-channel-commission/std",
"bifrost-vbnc-convert/std",
Expand Down Expand Up @@ -308,7 +308,6 @@ runtime-benchmarks = [
"bifrost-vstoken-conversion/runtime-benchmarks",
"bifrost-slp-v2/runtime-benchmarks",
"bifrost-asset-registry/runtime-benchmarks",
"bifrost-parachain-staking/runtime-benchmarks",
"sp-api/disable-logging",
"bifrost-fee-share/runtime-benchmarks",
"bifrost-slpx/runtime-benchmarks",
Expand Down Expand Up @@ -339,7 +338,6 @@ try-runtime = [
"pallet-session/try-runtime",
"pallet-aura/try-runtime",
"cumulus-pallet-aura-ext/try-runtime",
"bifrost-parachain-staking/try-runtime",
"pallet-collective/try-runtime",
"pallet-conviction-voting/try-runtime",
"pallet-membership/try-runtime",
Expand Down Expand Up @@ -370,6 +368,7 @@ try-runtime = [
"bifrost-flexible-fee/try-runtime",
"bifrost-salp/try-runtime",
"bifrost-token-issuer/try-runtime",
"bifrost-parachain-staking/try-runtime",
"bifrost-asset-registry/try-runtime",
"bifrost-vtoken-minting/try-runtime",
"bifrost-slp-v2/try-runtime",
Expand Down Expand Up @@ -412,4 +411,4 @@ fast-runtime = []
force-debug = ["sp-debug-derive/force-debug"]

# Enable sudo pallet.
sudo = ["pallet-sudo"]
sudo = ["pallet-sudo"]
Loading