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
2 changes: 1 addition & 1 deletion .github/workflows/check-migrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
CHECKS="pre-and-post"
else
echo "Enabling weight checks since we are not on a relay"

echo "Enabling try-state checks on the non-relay"
CHECKS="all"
fi
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Fixed
### Fixed

- Fix AH staking inflation calculation to use correct total issuance (https://github.com/polkadot-fellows/runtimes/pull/998).
- Set invulnerable deposit for Polkadot AssetHub staking election ([#993](https://github.com/polkadot-fellows/runtimes/pull/993))

## [2.0.1] 04.11.2025
Expand Down
8 changes: 5 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions relay/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,15 @@ repository.workspace = true
version.workspace = true

[dependencies]
codec = { features = ["derive", "max-encoded-len"], workspace = true }
scale-info = { features = ["derive"], workspace = true }

sp-api = { workspace = true }
sp-runtime = { workspace = true }
polkadot-primitives = { workspace = true }
pallet-staking-reward-fn = { workspace = true }
polkadot-primitives = { workspace = true }

[features]
default = ["std"]
std = [
"codec/std",
"scale-info/std",

"pallet-staking-reward-fn/std",
"polkadot-primitives/std",
"sp-api/std",
"sp-runtime/std",
]
runtime-benchmarks = [
Expand Down
29 changes: 0 additions & 29 deletions relay/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,6 @@
use polkadot_primitives::Balance;
use sp_runtime::{Perquintill, Saturating};

/// Extra runtime APIs for kusama runtime.
pub mod apis {
/// Information about the current inflation rate of the system.
///
/// Both fields should be treated as best-effort, given that the inflation rate might not be
/// fully predict-able.
#[derive(scale_info::TypeInfo, codec::Encode, codec::Decode)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct InflationInfo {
/// The rate of inflation estimated per annum.
pub inflation: sp_runtime::Perquintill,
/// Next amount that we anticipate to mint.
///
/// First item is the amount that goes to stakers, second is the leftover that is usually
/// forwarded to the treasury.
pub next_mint: (polkadot_primitives::Balance, polkadot_primitives::Balance),
}

sp_api::decl_runtime_apis! {
pub trait Inflation {
/// Return the current estimates of the inflation amount.
///
/// This is marked as experimental in light of RFC#89. Nonetheless, its usage is highly
/// recommended over trying to read-storage, or re-create the onchain logic.
fn experimental_inflation_prediction_info() -> InflationInfo;
}
}
}

// ---- TODO: Below is copy pasted from sdk, remove once we pull the version containing
// https://github.com/paritytech/polkadot-sdk/pull/4938

Expand Down
39 changes: 1 addition & 38 deletions relay/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ use polkadot_runtime_common::{
paras_registrar, prod_or_fast, slots, BalanceToU256, BlockHashCount, BlockLength,
CurrencyToVote, SlowAdjustingFeeUpdate, U256ToBalance,
};
use relay_common::apis::*;
use runtime_parachains::{
assigner_coretime as parachains_assigner_coretime,
configuration::{
Expand All @@ -124,7 +123,7 @@ use sp_runtime::{
generic, impl_opaque_keys,
traits::{
AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, Convert, ConvertInto,
Get, IdentityLookup, Keccak256, OpaqueKeys, SaturatedConversion, Saturating, Verify,
Get, IdentityLookup, Keccak256, OpaqueKeys, SaturatedConversion, Verify,
},
transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity},
ApplyExtrinsicResult, FixedU128, KeyTypeId, OpaqueValue, Perbill, Percent, Permill,
Expand Down Expand Up @@ -2437,43 +2436,7 @@ mod benches {
#[cfg(feature = "runtime-benchmarks")]
use benches::*;

impl Runtime {
fn impl_experimental_inflation_info() -> InflationInfo {
use pallet_staking::{ActiveEra, EraPayout, ErasTotalStake};
let (staked, _start) = ActiveEra::<Runtime>::get()
.map(|ae| (ErasTotalStake::<Runtime>::get(ae.index), ae.start.unwrap_or(0)))
.unwrap_or((0, 0));

let ideal_staking_rate = dynamic_params::inflation::IdealStake::get();
let inflation = if dynamic_params::inflation::UseAuctionSlots::get() {
let auctioned_slots = parachains_paras::Parachains::<Runtime>::get()
.into_iter()
// All active para-ids that do not belong to a system chain is the number of
// parachains that we should take into account for inflation.
.filter(|i| *i >= LOWEST_PUBLIC_ID)
.count() as u64;
ideal_staking_rate
.saturating_sub(Perquintill::from_rational(auctioned_slots.min(60), 200u64))
} else {
ideal_staking_rate
};

// We assume un-delayed 6h eras.
let era_duration = 6 * (HOURS as Moment) * MILLISECS_PER_BLOCK;
let next_mint =
<Self as pallet_staking::Config>::EraPayout::era_payout(staked, 0, era_duration);

InflationInfo { inflation, next_mint }
}
}

sp_api::impl_runtime_apis! {
impl relay_common::apis::Inflation<Block> for Runtime {
fn experimental_inflation_prediction_info() -> InflationInfo {
Runtime::impl_experimental_inflation_info()
}
}

impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
VERSION
Expand Down
34 changes: 0 additions & 34 deletions relay/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ use sp_runtime::traits::Convert;

use pallet_staking_async_ah_client as ah_client;
use pallet_staking_async_rc_client as rc_client;
use relay_common::apis::InflationInfo;
use runtime_parachains::{
assigner_coretime as parachains_assigner_coretime, configuration as parachains_configuration,
configuration::ActiveConfigHrmpChannelSizeAndCapacityRatio,
Expand Down Expand Up @@ -2261,39 +2260,7 @@ mod benches {
#[cfg(feature = "runtime-benchmarks")]
use benches::*;

impl Runtime {
fn impl_experimental_inflation_info() -> InflationInfo {
use pallet_staking::{ActiveEra, EraPayout, ErasTotalStake};
let (staked, _start) = ActiveEra::<Runtime>::get()
.map(|ae| (ErasTotalStake::<Runtime>::get(ae.index), ae.start.unwrap_or(0)))
.unwrap_or((0, 0));
let stake_able_issuance = Balances::total_issuance();

// We assume un-delayed 24h eras.
let era_duration = 24 * (HOURS as Moment) * MILLISECS_PER_BLOCK;
let next_mint = <Self as pallet_staking::Config>::EraPayout::era_payout(
staked,
stake_able_issuance,
era_duration,
);
// reverse-engineer the current inflation by looking at the total minted against the total
// issuance.
let inflation = Perquintill::from_rational(
(next_mint.0 + next_mint.1) * 36525 / 100,
stake_able_issuance,
);

InflationInfo { inflation, next_mint }
}
}

sp_api::impl_runtime_apis! {
impl relay_common::apis::Inflation<Block> for Runtime {
fn experimental_inflation_prediction_info() -> InflationInfo {
Runtime::impl_experimental_inflation_info()
}
}

impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
VERSION
Expand Down Expand Up @@ -3618,7 +3585,6 @@ mod remote_tests {
log::info!(target: LOG_TARGET, "era-duration = {average_era_duration_millis:?}");
log::info!(target: LOG_TARGET, "maxStakingRewards = {:?}", pallet_staking::MaxStakedRewards::<Runtime>::get());
log::info!(target: LOG_TARGET, "💰 Inflation ==> staking = {:?} / leftover = {:?}", token.amount(staking), token.amount(leftover));
log::info!(target: LOG_TARGET, "inflation_rate runtime API: {:?}", Runtime::impl_experimental_inflation_info());
});
}
}
14 changes: 11 additions & 3 deletions system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1440,15 +1440,17 @@ pub mod dynamic_params {
pub mod staking_election {
/// 10m worth of local 6s blocks for signed phase.
#[codec(index = 0)]
pub static SignedPhase: BlockNumber = 10 * system_parachains_constants::MINUTES;
pub static SignedPhase: BlockNumber =
10 * system_parachains_constants::async_backing::MINUTES;

/// Allow up to 16 signed solutions to be submitted.
#[codec(index = 1)]
pub static MaxSignedSubmissions: u32 = 16;

/// 10m for unsigned phase...
/// 5m for unsigned phase...
#[codec(index = 2)]
pub static UnsignedPhase: BlockNumber = 10 * system_parachains_constants::MINUTES;
pub static UnsignedPhase: BlockNumber =
5 * system_parachains_constants::async_backing::MINUTES;

/// .. in which we try and mine a 4-page solution.
#[codec(index = 3)]
Expand Down Expand Up @@ -2650,6 +2652,12 @@ pallet_revive::impl_runtime_apis_plus_revive!(
}
}

impl system_parachains_common::apis::Inflation<Block> for Runtime {
fn experimental_issuance_prediction_info() -> system_parachains_common::apis::InflationInfo {
crate::staking::EraPayout::impl_experimental_inflation_info()
}
}

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
Expand Down
43 changes: 43 additions & 0 deletions system-parachains/asset-hubs/asset-hub-kusama/src/staking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use pallet_staking_async_rc_client as rc_client;
use scale_info::TypeInfo;
use sp_runtime::{transaction_validity::TransactionPriority, Perquintill};
use sp_staking::SessionIndex;
use system_parachains_common::apis::InflationInfo;
use xcm::v5::prelude::*;

// alias for the ones backed by parameters-pallet.
Expand Down Expand Up @@ -332,6 +333,30 @@ impl pallet_staking_async::EraPayout<Balance> for EraPayout {
}
}

impl EraPayout {
pub(crate) fn impl_experimental_inflation_info() -> InflationInfo {
use pallet_staking_async::{ActiveEra, ActiveEraInfo, ErasTotalStake};
let staked = ActiveEra::<Runtime>::get()
.map(|ActiveEraInfo { index, .. }| ErasTotalStake::<Runtime>::get(index))
.unwrap_or(0);
let ti = pallet_balances::Pallet::<Runtime>::total_issuance();

// We assume un-delayed 6h eras.
let era_duration = 6 * 60 * 60 * 1000;
let next_mint = <Self as pallet_staking_async::EraPayout<Balance>>::era_payout(
staked,
ti,
era_duration,
);
let total = next_mint.0 + next_mint.1;
const NUM_ERAS_PER_DAY: u128 = 4;
let annual_issuance = total * 36525 * NUM_ERAS_PER_DAY / 100;
let issuance = Perquintill::from_rational(annual_issuance, ti);

InflationInfo { issuance, next_mint }
}
}

parameter_types! {
pub const SessionsPerEra: SessionIndex = 6;
/// Note: This is measured in RC block time. Our calculation of when to plan a new era might get
Expand Down Expand Up @@ -557,6 +582,23 @@ mod tests {
);
assert_eq!(staking, 844_606070970705);
assert_eq!(treasury, 320_110565207524);

pallet_balances::TotalIssuance::<Runtime>::put(17016510054564053390u128);
pallet_staking_async::ActiveEra::<Runtime>::put(pallet_staking_async::ActiveEraInfo {
index: 777,
start: None,
});
pallet_staking_async::ErasTotalStake::<Runtime>::insert(777, 8085567183241128549u128);
let expected_issuance_parts = 99999999999999249;
assert_eq!(
super::EraPayout::impl_experimental_inflation_info(),
InflationInfo {
issuance: Perquintill::from_parts(99999999999999249),
next_mint: (staking, treasury),
}
);
// around 9% now
assert_eq!(expected_issuance_parts * 100 / 10u64.pow(18), 9)
});
}

Expand All @@ -566,6 +608,7 @@ mod tests {
// session `n` and the results to be ready before the end of that session. Atm RC and KAH
// have the same block time, 6s.
sp_io::TestExternalities::new_empty().execute_with(|| {
sp_tracing::try_init_simple();
let duration = <<Runtime as pallet_staking_async::Config>::ElectionProvider as ElectionProvider>::duration();
let session = RelaySessionDuration::get();
log::info!(target: "runtime::asset-hub-kusama", "election duration is {duration:?}, relay session {session:?}",);
Expand Down
4 changes: 4 additions & 0 deletions system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ collectives-polkadot-runtime-constants = { workspace = true }
kusama-runtime-constants = { workspace = true }
polkadot-runtime-constants = { workspace = true }
system-parachains-constants = { workspace = true }
system-parachains-common = { workspace = true }

# Substrate
frame-benchmarking = { optional = true, workspace = true }
Expand Down Expand Up @@ -217,6 +218,7 @@ runtime-benchmarks = [
"snowbridge-runtime-common/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"sp-staking/runtime-benchmarks",
"system-parachains-common/runtime-benchmarks",
"system-parachains-constants/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
Expand Down Expand Up @@ -281,6 +283,7 @@ try-runtime = [
"snowbridge-pallet-system-frontend/try-runtime",
"snowbridge-runtime-common/try-runtime",
"sp-runtime/try-runtime",
"system-parachains-common/try-runtime",
]
std = [
"pallet-ah-migrator/std",
Expand Down Expand Up @@ -388,6 +391,7 @@ std = [
"sp-version/std",
"sp-weights/std",
"substrate-wasm-builder",
"system-parachains-common/std",
"system-parachains-constants/std",
"xcm-builder/std",
"xcm-executor/std",
Expand Down
10 changes: 8 additions & 2 deletions system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ use sp_runtime::{
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, Perbill, Permill,
};
use system_parachains_constants::MINUTES;
use system_parachains_constants::async_backing::MINUTES;
use xcm::latest::prelude::*;
use xcm_runtime_apis::{
dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
Expand Down Expand Up @@ -1230,7 +1230,7 @@ pub mod dynamic_params {
pub static MaxSignedSubmissions: u32 = 16;
/// Unsigned phase duration for election-provider-multi-block.
#[codec(index = 2)]
pub static UnsignedPhase: BlockNumber = 30 * MINUTES;
pub static UnsignedPhase: BlockNumber = 15 * MINUTES;
/// Miner pages for unsigned phase.
#[codec(index = 3)]
pub static MinerPages: u32 = 4;
Expand Down Expand Up @@ -2441,6 +2441,12 @@ impl_runtime_apis! {
}
}

impl system_parachains_common::apis::Inflation<Block> for Runtime {
fn experimental_issuance_prediction_info() -> system_parachains_common::apis::InflationInfo {
crate::staking::EraPayout::impl_experimental_inflation_info()
}
}

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
Expand Down
Loading
Loading