-
Notifications
You must be signed in to change notification settings - Fork 101
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
Kusama: Make the current inflation formula adjustable. #364
Merged
fellowship-merge-bot
merged 57 commits into
polkadot-fellows:main
from
kianenigma:kiz-inflation
Aug 20, 2024
Merged
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
8ab7024
Blueprint of how to fix inflation
kianenigma 6fa5130
Update to 1.14
ggwpez d99131f
Update Collectives
ggwpez ec4914b
Disable Encointer runtime
ggwpez 4143885
Update Kusama coretime
ggwpez 1c0af2d
Update Treasury
ggwpez 7fed1b4
Update collectives
ggwpez 0265664
Mock weights
ggwpez 36c9a7f
Kusama coretime revenue integration (#384)
s0me0ne-unkn0wn 6ca6fcb
re-enable & bump encointer to polkadot-v1.14.0 (#385)
clangenb 0be46e0
Clippy
ggwpez af19be5
Merge remote-tracking branch 'origin/main' into oty-update-1-14
ggwpez b0b1a81
Update CHANGELOG
ggwpez 4104b17
Clippy
ggwpez 235d14e
Clippy
ggwpez 129d1f7
Master.into()
kianenigma 522b881
update kusama
kianenigma b2be560
Fixes
ggwpez 30d1345
Fix changelog
ggwpez e3fca1e
Re-enable `request_revenue_info_at` in CoretimeInterface (#393)
seadanda 9740965
Merge remote-tracking branch 'origin/main' into oty-update-1-14
ggwpez 4882727
add TODO
kianenigma 324ff5a
Merge remote-tracking branch 'upstream/main' into kiz-inflation
kianenigma d60bfae
fix some params
kianenigma bd87a03
merged
kianenigma 4089a71
add tests
kianenigma 6eb9e73
update
kianenigma a9ab9ca
merged
kianenigma 28adc6b
fmt
kianenigma 70743e9
fix
kianenigma a31186b
fix
kianenigma 175020f
fix lock file
kianenigma f6d2aae
fmt and more test
kianenigma 93479de
add runtime api
kianenigma c65d843
fmt
kianenigma ce1ae0f
changelog
kianenigma 532f71d
Update relay/kusama/src/lib.rs
kianenigma 1e019dd
Update relay/kusama/src/lib.rs
kianenigma 0ea2ec3
Update relay/kusama/src/lib.rs
kianenigma 18629c0
Master.into()
kianenigma 2ad531a
fix a few things
kianenigma 432cf2f
Merge branch 'kiz-inflation' of github.com:kianenigma/runtimes into k…
kianenigma db131fa
move to shared crate for relay common
kianenigma 01fb284
fmt
kianenigma d695ad6
remove unused dep
kianenigma 91195e9
clippy
kianenigma c1c31b2
zepter
kianenigma 5d63355
Merge branch 'main' into kiz-inflation
kianenigma 978da88
fix build
kianenigma 31d667e
Merge branch 'main' into kiz-inflation
kianenigma 0d52761
Master.into()
kianenigma 758e76c
fmt
kianenigma c0432c5
Merge branch 'kiz-inflation' of github.com:kianenigma/runtimes into k…
kianenigma 79ca6cf
fmt again
kianenigma 95367f2
Doc nits
joepetrowski e657bda
Merge branch 'main' into kiz-inflation
joepetrowski d581b9c
Merge branch 'main' into kiz-inflation
fellowship-merge-bot[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[package] | ||
authors.workspace = true | ||
description = "Shared utilities between relay runtimes" | ||
edition.workspace = true | ||
license.workspace = true | ||
name = "relay-common" | ||
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 } | ||
|
||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"codec/std", | ||
"scale-info/std", | ||
|
||
"sp-api/std", | ||
"sp-runtime/std", | ||
"polkadot-primitives/std", | ||
"pallet-staking-reward-fn/std", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// This file is part of Polkadot. | ||
|
||
// Polkadot is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Polkadot is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! Shared code between the Kusama nd Polkadot RC Runtimes. | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
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)] | ||
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 | ||
|
||
#[derive(Debug, Clone)] | ||
/// Parameters passed into [`relay_era_payout`] function. | ||
pub struct EraPayoutParams { | ||
/// Total staked amount. | ||
pub total_staked: Balance, | ||
/// Total stakable amount. | ||
/// | ||
/// Usually, this is equal to the total issuance, except if a large part of the issuance is | ||
/// locked in another sub-system. | ||
pub total_stakable: Balance, | ||
/// Ideal stake ratio, which is reduced by `legacy_auction_proportion` if not `None`. | ||
pub ideal_stake: Perquintill, | ||
/// Maximum inflation rate. | ||
pub max_annual_inflation: Perquintill, | ||
/// Minimum inflation rate. | ||
pub min_annual_inflation: Perquintill, | ||
/// Falloff used to calculate era payouts. | ||
pub falloff: Perquintill, | ||
/// Fraction of the era period used to calculate era payouts. | ||
pub period_fraction: Perquintill, | ||
/// Legacy auction proportion, which, if not `None`, is subtracted from `ideal_stake`. | ||
pub legacy_auction_proportion: Option<Perquintill>, | ||
} | ||
|
||
/// A specialized function to compute the inflation of the staking system, tailored for Polkadot | ||
/// Relay Chains, such as Polkadot, Kusama, and Westend. | ||
pub fn relay_era_payout(params: EraPayoutParams) -> (Balance, Balance) { | ||
let EraPayoutParams { | ||
total_staked, | ||
total_stakable, | ||
ideal_stake, | ||
max_annual_inflation, | ||
min_annual_inflation, | ||
falloff, | ||
period_fraction, | ||
legacy_auction_proportion, | ||
} = params; | ||
|
||
let delta_annual_inflation = max_annual_inflation.saturating_sub(min_annual_inflation); | ||
|
||
let ideal_stake = ideal_stake.saturating_sub(legacy_auction_proportion.unwrap_or_default()); | ||
|
||
let stake = Perquintill::from_rational(total_staked, total_stakable); | ||
let adjustment = pallet_staking_reward_fn::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) | ||
} | ||
|
||
// ---- TODO: Above is copy pasted from sdk, remove once we pull the version containing | ||
// https://github.com/paritytech/polkadot-sdk/pull/4938 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be better if you referenced the crate name and (min) version required, instead of this PR, otherwise it becomes a non-trivial chore to figure out when this can be removed and no one will do it :)
(same above)