Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Polkadot ideal staking rate #26

Merged
merged 17 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions relay/polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pallet-session = { git = "https://github.com/paritytech/substrate", branch = "ma
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-curve = { git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-staking-reward-fn = { git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-staking-runtime-api = { 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 }
Expand Down
50 changes: 49 additions & 1 deletion relay/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,54 @@ parameter_types! {
pub const MaxNominations: u32 = <NposCompactSolution16 as frame_election_provider_support::NposSolution>::LIMIT as u32;
}

/// Custom version of `runtime_commong::era_payout` somewhat tailored for Polkadot's crowdloan
/// unlock history. The only tweak should be
///
/// ```diff
/// - let auction_proportion = Perquintill::from_rational(auctioned_slots.min(60), 200u64);
/// + let auction_proportion = Perquintill::from_rational(auctioned_slots.min(60), 300u64);
/// ```
///
/// See https://forum.polkadot.network/t/adjusting-polkadots-ideal-staking-rate-calculation/3897/2
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
fn polkadot_era_payout(
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
total_staked: Balance,
total_stakable: Balance,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i also think it would be sensible to peek in on what this value currently is on Polkadot and ensure it makes sense.

max_annual_inflation: Perquintill,
period_fraction: Perquintill,
auctioned_slots: u64,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont remember the current status, but back when this was originally written, i believe the auctioned slots counter was not exactly correct.

has this logic been updated?

) -> (Balance, Balance) {
use pallet_staking_reward_fn::compute_inflation;
use sp_runtime::traits::Saturating;

let min_annual_inflation = Perquintill::from_rational(25u64, 1000u64);
let delta_annual_inflation = max_annual_inflation.saturating_sub(min_annual_inflation);

// 20% reserved for up to 60 slots.
let auction_proportion = Perquintill::from_rational(auctioned_slots.min(60), 300u64);

// 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, total_stakable);
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 * total_stakable;
let staking_payout = (period_fraction * staking_inflation) * total_stakable;
let rest = max_payout.saturating_sub(staking_payout);

let other_issuance = total_stakable.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(
Expand All @@ -561,7 +609,7 @@ impl pallet_staking::EraPayout<Balance> for EraPayout {
const MAX_ANNUAL_INFLATION: Perquintill = Perquintill::from_percent(10);
const MILLISECONDS_PER_YEAR: u64 = 1000 * 3600 * 24 * 36525 / 100;

runtime_common::impls::era_payout(
polkadot_era_payout(
total_staked,
total_issuance,
MAX_ANNUAL_INFLATION,
Expand Down