Skip to content

Commit fde008a

Browse files
kianenigmaggwpezbkchr
authored
Fix AH Inflation back to what RC was (#998)
While copying configs from RC to AH, the fixed total issuance noted in [Referendum 1139](https://polkadot.subsquare.io/referenda/1139) was misplaced with sth else. This PR fixes this. **Note to all validators and stakers: Until this fix is deployed, the staking rewards are expected to be about 60% less than before.** - [x] move `experimental_inflation_prediction_info` to AH. - [x] use `async_backing::MINUTES`! --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Bastian Köcher <git@kchr.de>
1 parent 0a7679f commit fde008a

File tree

14 files changed

+169
-122
lines changed

14 files changed

+169
-122
lines changed

.github/workflows/check-migrations.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
CHECKS="pre-and-post"
7878
else
7979
echo "Enabling weight checks since we are not on a relay"
80-
80+
8181
echo "Enabling try-state checks on the non-relay"
8282
CHECKS="all"
8383
fi

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## [Unreleased]
88

9-
### Fixed
9+
### Fixed
1010

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

1314
## [2.0.1] 04.11.2025

Cargo.lock

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

relay/common/Cargo.toml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,15 @@ repository.workspace = true
88
version.workspace = true
99

1010
[dependencies]
11-
codec = { features = ["derive", "max-encoded-len"], workspace = true }
12-
scale-info = { features = ["derive"], workspace = true }
13-
14-
sp-api = { workspace = true }
1511
sp-runtime = { workspace = true }
16-
polkadot-primitives = { workspace = true }
1712
pallet-staking-reward-fn = { workspace = true }
13+
polkadot-primitives = { workspace = true }
1814

1915
[features]
2016
default = ["std"]
2117
std = [
22-
"codec/std",
23-
"scale-info/std",
24-
2518
"pallet-staking-reward-fn/std",
2619
"polkadot-primitives/std",
27-
"sp-api/std",
2820
"sp-runtime/std",
2921
]
3022
runtime-benchmarks = [

relay/common/src/lib.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,6 @@
2020
use polkadot_primitives::Balance;
2121
use sp_runtime::{Perquintill, Saturating};
2222

23-
/// Extra runtime APIs for kusama runtime.
24-
pub mod apis {
25-
/// Information about the current inflation rate of the system.
26-
///
27-
/// Both fields should be treated as best-effort, given that the inflation rate might not be
28-
/// fully predict-able.
29-
#[derive(scale_info::TypeInfo, codec::Encode, codec::Decode)]
30-
#[cfg_attr(feature = "std", derive(Debug))]
31-
pub struct InflationInfo {
32-
/// The rate of inflation estimated per annum.
33-
pub inflation: sp_runtime::Perquintill,
34-
/// Next amount that we anticipate to mint.
35-
///
36-
/// First item is the amount that goes to stakers, second is the leftover that is usually
37-
/// forwarded to the treasury.
38-
pub next_mint: (polkadot_primitives::Balance, polkadot_primitives::Balance),
39-
}
40-
41-
sp_api::decl_runtime_apis! {
42-
pub trait Inflation {
43-
/// Return the current estimates of the inflation amount.
44-
///
45-
/// This is marked as experimental in light of RFC#89. Nonetheless, its usage is highly
46-
/// recommended over trying to read-storage, or re-create the onchain logic.
47-
fn experimental_inflation_prediction_info() -> InflationInfo;
48-
}
49-
}
50-
}
51-
5223
// ---- TODO: Below is copy pasted from sdk, remove once we pull the version containing
5324
// https://github.com/paritytech/polkadot-sdk/pull/4938
5425

relay/kusama/src/lib.rs

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ use polkadot_runtime_common::{
9797
paras_registrar, prod_or_fast, slots, BalanceToU256, BlockHashCount, BlockLength,
9898
CurrencyToVote, SlowAdjustingFeeUpdate, U256ToBalance,
9999
};
100-
use relay_common::apis::*;
101100
use runtime_parachains::{
102101
assigner_coretime as parachains_assigner_coretime,
103102
configuration::{
@@ -124,7 +123,7 @@ use sp_runtime::{
124123
generic, impl_opaque_keys,
125124
traits::{
126125
AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, Convert, ConvertInto,
127-
Get, IdentityLookup, Keccak256, OpaqueKeys, SaturatedConversion, Saturating, Verify,
126+
Get, IdentityLookup, Keccak256, OpaqueKeys, SaturatedConversion, Verify,
128127
},
129128
transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity},
130129
ApplyExtrinsicResult, FixedU128, KeyTypeId, OpaqueValue, Perbill, Percent, Permill,
@@ -2437,43 +2436,7 @@ mod benches {
24372436
#[cfg(feature = "runtime-benchmarks")]
24382437
use benches::*;
24392438

2440-
impl Runtime {
2441-
fn impl_experimental_inflation_info() -> InflationInfo {
2442-
use pallet_staking::{ActiveEra, EraPayout, ErasTotalStake};
2443-
let (staked, _start) = ActiveEra::<Runtime>::get()
2444-
.map(|ae| (ErasTotalStake::<Runtime>::get(ae.index), ae.start.unwrap_or(0)))
2445-
.unwrap_or((0, 0));
2446-
2447-
let ideal_staking_rate = dynamic_params::inflation::IdealStake::get();
2448-
let inflation = if dynamic_params::inflation::UseAuctionSlots::get() {
2449-
let auctioned_slots = parachains_paras::Parachains::<Runtime>::get()
2450-
.into_iter()
2451-
// All active para-ids that do not belong to a system chain is the number of
2452-
// parachains that we should take into account for inflation.
2453-
.filter(|i| *i >= LOWEST_PUBLIC_ID)
2454-
.count() as u64;
2455-
ideal_staking_rate
2456-
.saturating_sub(Perquintill::from_rational(auctioned_slots.min(60), 200u64))
2457-
} else {
2458-
ideal_staking_rate
2459-
};
2460-
2461-
// We assume un-delayed 6h eras.
2462-
let era_duration = 6 * (HOURS as Moment) * MILLISECS_PER_BLOCK;
2463-
let next_mint =
2464-
<Self as pallet_staking::Config>::EraPayout::era_payout(staked, 0, era_duration);
2465-
2466-
InflationInfo { inflation, next_mint }
2467-
}
2468-
}
2469-
24702439
sp_api::impl_runtime_apis! {
2471-
impl relay_common::apis::Inflation<Block> for Runtime {
2472-
fn experimental_inflation_prediction_info() -> InflationInfo {
2473-
Runtime::impl_experimental_inflation_info()
2474-
}
2475-
}
2476-
24772440
impl sp_api::Core<Block> for Runtime {
24782441
fn version() -> RuntimeVersion {
24792442
VERSION

relay/polkadot/src/lib.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ use sp_runtime::traits::Convert;
9494

9595
use pallet_staking_async_ah_client as ah_client;
9696
use pallet_staking_async_rc_client as rc_client;
97-
use relay_common::apis::InflationInfo;
9897
use runtime_parachains::{
9998
assigner_coretime as parachains_assigner_coretime, configuration as parachains_configuration,
10099
configuration::ActiveConfigHrmpChannelSizeAndCapacityRatio,
@@ -2261,39 +2260,7 @@ mod benches {
22612260
#[cfg(feature = "runtime-benchmarks")]
22622261
use benches::*;
22632262

2264-
impl Runtime {
2265-
fn impl_experimental_inflation_info() -> InflationInfo {
2266-
use pallet_staking::{ActiveEra, EraPayout, ErasTotalStake};
2267-
let (staked, _start) = ActiveEra::<Runtime>::get()
2268-
.map(|ae| (ErasTotalStake::<Runtime>::get(ae.index), ae.start.unwrap_or(0)))
2269-
.unwrap_or((0, 0));
2270-
let stake_able_issuance = Balances::total_issuance();
2271-
2272-
// We assume un-delayed 24h eras.
2273-
let era_duration = 24 * (HOURS as Moment) * MILLISECS_PER_BLOCK;
2274-
let next_mint = <Self as pallet_staking::Config>::EraPayout::era_payout(
2275-
staked,
2276-
stake_able_issuance,
2277-
era_duration,
2278-
);
2279-
// reverse-engineer the current inflation by looking at the total minted against the total
2280-
// issuance.
2281-
let inflation = Perquintill::from_rational(
2282-
(next_mint.0 + next_mint.1) * 36525 / 100,
2283-
stake_able_issuance,
2284-
);
2285-
2286-
InflationInfo { inflation, next_mint }
2287-
}
2288-
}
2289-
22902263
sp_api::impl_runtime_apis! {
2291-
impl relay_common::apis::Inflation<Block> for Runtime {
2292-
fn experimental_inflation_prediction_info() -> InflationInfo {
2293-
Runtime::impl_experimental_inflation_info()
2294-
}
2295-
}
2296-
22972264
impl sp_api::Core<Block> for Runtime {
22982265
fn version() -> RuntimeVersion {
22992266
VERSION
@@ -3618,7 +3585,6 @@ mod remote_tests {
36183585
log::info!(target: LOG_TARGET, "era-duration = {average_era_duration_millis:?}");
36193586
log::info!(target: LOG_TARGET, "maxStakingRewards = {:?}", pallet_staking::MaxStakedRewards::<Runtime>::get());
36203587
log::info!(target: LOG_TARGET, "💰 Inflation ==> staking = {:?} / leftover = {:?}", token.amount(staking), token.amount(leftover));
3621-
log::info!(target: LOG_TARGET, "inflation_rate runtime API: {:?}", Runtime::impl_experimental_inflation_info());
36223588
});
36233589
}
36243590
}

system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,15 +1440,17 @@ pub mod dynamic_params {
14401440
pub mod staking_election {
14411441
/// 10m worth of local 6s blocks for signed phase.
14421442
#[codec(index = 0)]
1443-
pub static SignedPhase: BlockNumber = 10 * system_parachains_constants::MINUTES;
1443+
pub static SignedPhase: BlockNumber =
1444+
10 * system_parachains_constants::async_backing::MINUTES;
14441445

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

1449-
/// 10m for unsigned phase...
1450+
/// 5m for unsigned phase...
14501451
#[codec(index = 2)]
1451-
pub static UnsignedPhase: BlockNumber = 10 * system_parachains_constants::MINUTES;
1452+
pub static UnsignedPhase: BlockNumber =
1453+
5 * system_parachains_constants::async_backing::MINUTES;
14521454

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

2655+
impl system_parachains_common::apis::Inflation<Block> for Runtime {
2656+
fn experimental_issuance_prediction_info() -> system_parachains_common::apis::InflationInfo {
2657+
crate::staking::EraPayout::impl_experimental_inflation_info()
2658+
}
2659+
}
2660+
26532661
#[cfg(feature = "try-runtime")]
26542662
impl frame_try_runtime::TryRuntime<Block> for Runtime {
26552663
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {

system-parachains/asset-hubs/asset-hub-kusama/src/staking/mod.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use pallet_staking_async_rc_client as rc_client;
3030
use scale_info::TypeInfo;
3131
use sp_runtime::{transaction_validity::TransactionPriority, Perquintill};
3232
use sp_staking::SessionIndex;
33+
use system_parachains_common::apis::InflationInfo;
3334
use xcm::v5::prelude::*;
3435

3536
// alias for the ones backed by parameters-pallet.
@@ -332,6 +333,30 @@ impl pallet_staking_async::EraPayout<Balance> for EraPayout {
332333
}
333334
}
334335

336+
impl EraPayout {
337+
pub(crate) fn impl_experimental_inflation_info() -> InflationInfo {
338+
use pallet_staking_async::{ActiveEra, ActiveEraInfo, ErasTotalStake};
339+
let staked = ActiveEra::<Runtime>::get()
340+
.map(|ActiveEraInfo { index, .. }| ErasTotalStake::<Runtime>::get(index))
341+
.unwrap_or(0);
342+
let ti = pallet_balances::Pallet::<Runtime>::total_issuance();
343+
344+
// We assume un-delayed 6h eras.
345+
let era_duration = 6 * 60 * 60 * 1000;
346+
let next_mint = <Self as pallet_staking_async::EraPayout<Balance>>::era_payout(
347+
staked,
348+
ti,
349+
era_duration,
350+
);
351+
let total = next_mint.0 + next_mint.1;
352+
const NUM_ERAS_PER_DAY: u128 = 4;
353+
let annual_issuance = total * 36525 * NUM_ERAS_PER_DAY / 100;
354+
let issuance = Perquintill::from_rational(annual_issuance, ti);
355+
356+
InflationInfo { issuance, next_mint }
357+
}
358+
}
359+
335360
parameter_types! {
336361
pub const SessionsPerEra: SessionIndex = 6;
337362
/// Note: This is measured in RC block time. Our calculation of when to plan a new era might get
@@ -557,6 +582,23 @@ mod tests {
557582
);
558583
assert_eq!(staking, 844_606070970705);
559584
assert_eq!(treasury, 320_110565207524);
585+
586+
pallet_balances::TotalIssuance::<Runtime>::put(17016510054564053390u128);
587+
pallet_staking_async::ActiveEra::<Runtime>::put(pallet_staking_async::ActiveEraInfo {
588+
index: 777,
589+
start: None,
590+
});
591+
pallet_staking_async::ErasTotalStake::<Runtime>::insert(777, 8085567183241128549u128);
592+
let expected_issuance_parts = 99999999999999249;
593+
assert_eq!(
594+
super::EraPayout::impl_experimental_inflation_info(),
595+
InflationInfo {
596+
issuance: Perquintill::from_parts(99999999999999249),
597+
next_mint: (staking, treasury),
598+
}
599+
);
600+
// around 9% now
601+
assert_eq!(expected_issuance_parts * 100 / 10u64.pow(18), 9)
560602
});
561603
}
562604

@@ -566,6 +608,7 @@ mod tests {
566608
// session `n` and the results to be ready before the end of that session. Atm RC and KAH
567609
// have the same block time, 6s.
568610
sp_io::TestExternalities::new_empty().execute_with(|| {
611+
sp_tracing::try_init_simple();
569612
let duration = <<Runtime as pallet_staking_async::Config>::ElectionProvider as ElectionProvider>::duration();
570613
let session = RelaySessionDuration::get();
571614
log::info!(target: "runtime::asset-hub-kusama", "election duration is {duration:?}, relay session {session:?}",);

system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ collectives-polkadot-runtime-constants = { workspace = true }
2727
kusama-runtime-constants = { workspace = true }
2828
polkadot-runtime-constants = { workspace = true }
2929
system-parachains-constants = { workspace = true }
30+
system-parachains-common = { workspace = true }
3031

3132
# Substrate
3233
frame-benchmarking = { optional = true, workspace = true }
@@ -217,6 +218,7 @@ runtime-benchmarks = [
217218
"snowbridge-runtime-common/runtime-benchmarks",
218219
"sp-runtime/runtime-benchmarks",
219220
"sp-staking/runtime-benchmarks",
221+
"system-parachains-common/runtime-benchmarks",
220222
"system-parachains-constants/runtime-benchmarks",
221223
"xcm-builder/runtime-benchmarks",
222224
"xcm-executor/runtime-benchmarks",
@@ -281,6 +283,7 @@ try-runtime = [
281283
"snowbridge-pallet-system-frontend/try-runtime",
282284
"snowbridge-runtime-common/try-runtime",
283285
"sp-runtime/try-runtime",
286+
"system-parachains-common/try-runtime",
284287
]
285288
std = [
286289
"pallet-ah-migrator/std",
@@ -388,6 +391,7 @@ std = [
388391
"sp-version/std",
389392
"sp-weights/std",
390393
"substrate-wasm-builder",
394+
"system-parachains-common/std",
391395
"system-parachains-constants/std",
392396
"xcm-builder/std",
393397
"xcm-executor/std",

0 commit comments

Comments
 (0)