mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 11:41:02 +00:00
Update polkadot inflation to take into account auctions (#5872)
* Update polkadot inflation to take into account auctions * a possible solution -- but needs a rather untrivial data seeding * some additional comments * Use LOWEST_PUBLIC_ID as a guide to filter out system/common good para ids * Fixes * move tests * fix Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -72,7 +72,6 @@ pallet-session = { git = "https://github.com/paritytech/substrate", branch = "ma
|
||||
pallet-society = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
pallet-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
pallet-staking-reward-fn = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
frame-system = {git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
@@ -170,7 +169,6 @@ std = [
|
||||
"pallet-session/std",
|
||||
"pallet-society/std",
|
||||
"pallet-staking/std",
|
||||
"pallet-staking-reward-fn/std",
|
||||
"pallet-timestamp/std",
|
||||
"pallet-tips/std",
|
||||
"pallet-treasury/std",
|
||||
|
||||
@@ -26,6 +26,7 @@ use primitives::v2::{
|
||||
CoreState, GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage,
|
||||
Moment, Nonce, OccupiedCoreAssumption, PersistedValidationData, ScrapedOnChainVotes,
|
||||
SessionInfo, Signature, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex,
|
||||
LOWEST_PUBLIC_ID,
|
||||
};
|
||||
use runtime_common::{
|
||||
auctions, claims, crowdloan, impl_runtime_weights, impls::DealWithFees, paras_registrar,
|
||||
@@ -504,45 +505,6 @@ impl pallet_bags_list::Config<VoterBagsListInstance> for Runtime {
|
||||
type Score = sp_npos_elections::VoteWeight;
|
||||
}
|
||||
|
||||
fn era_payout(
|
||||
total_staked: Balance,
|
||||
non_gilt_issuance: Balance,
|
||||
max_annual_inflation: Perquintill,
|
||||
period_fraction: Perquintill,
|
||||
auctioned_slots: u64,
|
||||
) -> (Balance, Balance) {
|
||||
use pallet_staking_reward_fn::compute_inflation;
|
||||
use sp_arithmetic::traits::Saturating;
|
||||
|
||||
let min_annual_inflation = Perquintill::from_rational(25u64, 1000u64);
|
||||
let delta_annual_inflation = max_annual_inflation.saturating_sub(min_annual_inflation);
|
||||
|
||||
// 30% reserved for up to 60 slots.
|
||||
let auction_proportion = Perquintill::from_rational(auctioned_slots.min(60), 200u64);
|
||||
|
||||
// Therefore the ideal amount at stake (as a percentage of total issuance) is 75% less the amount that we expect
|
||||
// to be taken up with auctions.
|
||||
let ideal_stake = Perquintill::from_percent(75).saturating_sub(auction_proportion);
|
||||
|
||||
let stake = Perquintill::from_rational(total_staked, non_gilt_issuance);
|
||||
let falloff = Perquintill::from_percent(5);
|
||||
let adjustment = compute_inflation(stake, ideal_stake, falloff);
|
||||
let staking_inflation =
|
||||
min_annual_inflation.saturating_add(delta_annual_inflation * adjustment);
|
||||
|
||||
let max_payout = period_fraction * max_annual_inflation * non_gilt_issuance;
|
||||
let staking_payout = (period_fraction * staking_inflation) * non_gilt_issuance;
|
||||
let rest = max_payout.saturating_sub(staking_payout);
|
||||
|
||||
let other_issuance = non_gilt_issuance.saturating_sub(total_staked);
|
||||
if total_staked > other_issuance {
|
||||
let _cap_rest = Perquintill::from_rational(other_issuance, total_staked) * staking_payout;
|
||||
// We don't do anything with this, but if we wanted to, we could introduce a cap on the treasury amount
|
||||
// with: `rest = rest.min(cap_rest);`
|
||||
}
|
||||
(staking_payout, rest)
|
||||
}
|
||||
|
||||
pub struct EraPayout;
|
||||
impl pallet_staking::EraPayout<Balance> for EraPayout {
|
||||
fn era_payout(
|
||||
@@ -550,13 +512,18 @@ impl pallet_staking::EraPayout<Balance> for EraPayout {
|
||||
_total_issuance: Balance,
|
||||
era_duration_millis: u64,
|
||||
) -> (Balance, Balance) {
|
||||
// TODO: #3011 Update with proper auctioned slots tracking.
|
||||
// This should be fine for the first year of parachains.
|
||||
let auctioned_slots: u64 = auctions::Pallet::<Runtime>::auction_counter().into();
|
||||
// all para-ids that are currently active.
|
||||
let auctioned_slots = Paras::parachains()
|
||||
.into_iter()
|
||||
// all active para-ids that do not belong to a system or common good chain is the number
|
||||
// of parachains that we should take into account for inflation.
|
||||
.filter(|i| *i >= LOWEST_PUBLIC_ID)
|
||||
.count() as u64;
|
||||
|
||||
const MAX_ANNUAL_INFLATION: Perquintill = Perquintill::from_percent(10);
|
||||
const MILLISECONDS_PER_YEAR: u64 = 1000 * 3600 * 24 * 36525 / 100;
|
||||
|
||||
era_payout(
|
||||
runtime_common::impls::era_payout(
|
||||
total_staked,
|
||||
Gilt::issuance().non_gilt,
|
||||
MAX_ANNUAL_INFLATION,
|
||||
|
||||
@@ -137,40 +137,6 @@ fn nominator_limit() {
|
||||
println!("can support {} nominators to yield a weight of {}", active, weight_with(active));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compute_inflation_should_give_sensible_results() {
|
||||
assert_eq!(
|
||||
pallet_staking_reward_fn::compute_inflation(
|
||||
Perquintill::from_percent(75),
|
||||
Perquintill::from_percent(75),
|
||||
Perquintill::from_percent(5),
|
||||
),
|
||||
Perquintill::one()
|
||||
);
|
||||
assert_eq!(
|
||||
pallet_staking_reward_fn::compute_inflation(
|
||||
Perquintill::from_percent(50),
|
||||
Perquintill::from_percent(75),
|
||||
Perquintill::from_percent(5),
|
||||
),
|
||||
Perquintill::from_rational(2u64, 3u64)
|
||||
);
|
||||
assert_eq!(
|
||||
pallet_staking_reward_fn::compute_inflation(
|
||||
Perquintill::from_percent(80),
|
||||
Perquintill::from_percent(75),
|
||||
Perquintill::from_percent(5),
|
||||
),
|
||||
Perquintill::from_rational(1u64, 2u64)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn era_payout_should_give_sensible_results() {
|
||||
assert_eq!(era_payout(75, 100, Perquintill::from_percent(10), Perquintill::one(), 0,), (10, 0));
|
||||
assert_eq!(era_payout(80, 100, Perquintill::from_percent(10), Perquintill::one(), 0,), (6, 4));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_size() {
|
||||
RuntimeCall::assert_size_under(230);
|
||||
|
||||
Reference in New Issue
Block a user