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

Kusama: Make the current inflation formula adjustable. #364

Merged
merged 57 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
8ab7024
Blueprint of how to fix inflation
kianenigma Jun 27, 2024
6fa5130
Update to 1.14
ggwpez Jul 14, 2024
d99131f
Update Collectives
ggwpez Jul 14, 2024
ec4914b
Disable Encointer runtime
ggwpez Jul 14, 2024
4143885
Update Kusama coretime
ggwpez Jul 14, 2024
1c0af2d
Update Treasury
ggwpez Jul 14, 2024
7fed1b4
Update collectives
ggwpez Jul 14, 2024
0265664
Mock weights
ggwpez Jul 14, 2024
36c9a7f
Kusama coretime revenue integration (#384)
s0me0ne-unkn0wn Jul 17, 2024
6ca6fcb
re-enable & bump encointer to polkadot-v1.14.0 (#385)
clangenb Jul 17, 2024
0be46e0
Clippy
ggwpez Jul 17, 2024
af19be5
Merge remote-tracking branch 'origin/main' into oty-update-1-14
ggwpez Jul 17, 2024
b0b1a81
Update CHANGELOG
ggwpez Jul 17, 2024
4104b17
Clippy
ggwpez Jul 17, 2024
235d14e
Clippy
ggwpez Jul 17, 2024
129d1f7
Master.into()
kianenigma Jul 17, 2024
522b881
update kusama
kianenigma Jul 17, 2024
b2be560
Fixes
ggwpez Jul 17, 2024
30d1345
Fix changelog
ggwpez Jul 17, 2024
e3fca1e
Re-enable `request_revenue_info_at` in CoretimeInterface (#393)
seadanda Jul 18, 2024
9740965
Merge remote-tracking branch 'origin/main' into oty-update-1-14
ggwpez Jul 18, 2024
4882727
add TODO
kianenigma Jul 19, 2024
324ff5a
Merge remote-tracking branch 'upstream/main' into kiz-inflation
kianenigma Jul 19, 2024
d60bfae
fix some params
kianenigma Jul 19, 2024
bd87a03
merged
kianenigma Jul 19, 2024
4089a71
add tests
kianenigma Jul 19, 2024
6eb9e73
update
kianenigma Aug 1, 2024
a9ab9ca
merged
kianenigma Aug 1, 2024
28adc6b
fmt
kianenigma Aug 1, 2024
70743e9
fix
kianenigma Aug 1, 2024
a31186b
fix
kianenigma Aug 1, 2024
175020f
fix lock file
kianenigma Aug 1, 2024
f6d2aae
fmt and more test
kianenigma Aug 1, 2024
93479de
add runtime api
kianenigma Aug 1, 2024
c65d843
fmt
kianenigma Aug 1, 2024
ce1ae0f
changelog
kianenigma Aug 1, 2024
532f71d
Update relay/kusama/src/lib.rs
kianenigma Aug 6, 2024
1e019dd
Update relay/kusama/src/lib.rs
kianenigma Aug 13, 2024
0ea2ec3
Update relay/kusama/src/lib.rs
kianenigma Aug 13, 2024
18629c0
Master.into()
kianenigma Aug 15, 2024
2ad531a
fix a few things
kianenigma Aug 15, 2024
432cf2f
Merge branch 'kiz-inflation' of github.com:kianenigma/runtimes into k…
kianenigma Aug 15, 2024
db131fa
move to shared crate for relay common
kianenigma Aug 15, 2024
01fb284
fmt
kianenigma Aug 15, 2024
d695ad6
remove unused dep
kianenigma Aug 15, 2024
91195e9
clippy
kianenigma Aug 15, 2024
c1c31b2
zepter
kianenigma Aug 15, 2024
5d63355
Merge branch 'main' into kiz-inflation
kianenigma Aug 15, 2024
978da88
fix build
kianenigma Aug 15, 2024
31d667e
Merge branch 'main' into kiz-inflation
kianenigma Aug 16, 2024
0d52761
Master.into()
kianenigma Aug 16, 2024
758e76c
fmt
kianenigma Aug 16, 2024
c0432c5
Merge branch 'kiz-inflation' of github.com:kianenigma/runtimes into k…
kianenigma Aug 16, 2024
79ca6cf
fmt again
kianenigma Aug 16, 2024
95367f2
Doc nits
joepetrowski Aug 20, 2024
e657bda
Merge branch 'main' into kiz-inflation
joepetrowski Aug 20, 2024
d581b9c
Merge branch 'main' into kiz-inflation
fellowship-merge-bot[bot] Aug 20, 2024
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add the Polkadot Coretime Chain runtime ([polkadot-fellows/runtimes#410](https://github.com/polkadot-fellows/runtimes/pull/410))
- Kusama: Add a "Spokesperson" proxy type only allowed to send remarks ([polkadot-fellows/runtimes#430](https://github.com/polkadot-fellows/runtimes/pull/430))
- Add the Polkadot and Kusama Coretime Chain specs ([polkadot-fellows/runtimes#432](https://github.com/polkadot-fellows/runtimes/pull/432))
- Kusama: Make the current inflation formula adjustable ([polkadot-fellows/runtimes#364](https://github.com/polkadot-fellows/runtimes/pull/364))
- Port Agile Coretime migration from polkadot-sdk in order to fix leases with gaps handling([polkadot-fellows/runtimes#426](https://github.com/polkadot-fellows/runtimes/pull/426))


#### From [#322](https://github.com/polkadot-fellows/runtimes/pull/322):

- Add `claim_assets` extrinsic to `pallet-xcm` ([SDK v1.9 #3403](https://github.com/paritytech/polkadot-sdk/pull/3403)).
Expand Down
38 changes: 36 additions & 2 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ pallet-nomination-pools-benchmarking = { version = "34.0.0", default-features =
pallet-nomination-pools-runtime-api = { version = "31.0.0", default-features = false }
pallet-offences = { version = "35.0.0", default-features = false }
pallet-offences-benchmarking = { version = "36.0.0", default-features = false }
pallet-parameters = { version = "0.7.0", default-features = false }
pallet-preimage = { version = "36.0.0", default-features = false }
pallet-proxy = { version = "36.0.0", default-features = false }
pallet-ranked-collective = { version = "36.0.0", default-features = false }
Expand Down Expand Up @@ -243,6 +244,8 @@ subxt = { version = "0.35.0", default-features = false }
tracing-subscriber = { version = "0.3.18" }
zombienet-sdk = { version = "0.2.4" }
tuplex = { version = "0.1.0", default-features = false }
relay-common = { path = "relay/common", default-features = false }
ss58-registry = { version = "1.47.0" }

[workspace]
resolver = "2"
Expand Down Expand Up @@ -275,6 +278,7 @@ members = [
"integration-tests/emulated/tests/people/people-kusama",
"integration-tests/emulated/tests/people/people-polkadot",
"integration-tests/zombienet",
"relay/common",
"relay/kusama",
"relay/kusama/constants",
"relay/polkadot",
Expand Down
30 changes: 30 additions & 0 deletions relay/common/Cargo.toml
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",
]
115 changes: 115 additions & 0 deletions relay/common/src/lib.rs
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 deducted by `legacy_auction_proportion` if not `None`.
joepetrowski marked this conversation as resolved.
Show resolved Hide resolved
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 substracts from `ideal_stake` if not `None`.
joepetrowski marked this conversation as resolved.
Show resolved Hide resolved
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.
joepetrowski marked this conversation as resolved.
Show resolved Hide resolved
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
Comment on lines +114 to +115
Copy link
Contributor

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)

7 changes: 7 additions & 0 deletions relay/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pallet-whitelist = { workspace = true }
pallet-xcm = { workspace = true }
pallet-xcm-benchmarks = { optional = true, workspace = true }
frame-election-provider-support = { workspace = true }
pallet-parameters = { workspace = true }

frame-benchmarking = { optional = true, workspace = true }
frame-try-runtime = { optional = true, workspace = true }
Expand All @@ -105,6 +106,7 @@ xcm-builder = { workspace = true }
xcm-runtime-apis = { workspace = true }

sp-debug-derive = { workspace = true }
relay-common = { workspace = true }

[dev-dependencies]
sp-keyring = { workspace = true }
Expand All @@ -113,6 +115,7 @@ separator = { workspace = true }
remote-externalities = { workspace = true }
tokio = { features = ["macros"], workspace = true }
sp-tracing = { workspace = true }
ss58-registry = { workspace = true }

[build-dependencies]
substrate-wasm-builder = { workspace = true, optional = true }
Expand Down Expand Up @@ -166,6 +169,7 @@ std = [
"pallet-offences/std",
"pallet-preimage/std",
"pallet-proxy/std",
"pallet-parameters/std",
"pallet-ranked-collective/std",
"pallet-recovery/std",
"pallet-referenda/std",
Expand All @@ -186,6 +190,7 @@ std = [
"pallet-xcm/std",
"polkadot-primitives/std",
"polkadot-runtime-common/std",
"relay-common/std",
"runtime-parachains/std",
"scale-info/std",
"serde_json/std",
Expand Down Expand Up @@ -241,6 +246,7 @@ runtime-benchmarks = [
"pallet-nomination-pools/runtime-benchmarks",
"pallet-offences-benchmarking/runtime-benchmarks",
"pallet-offences/runtime-benchmarks",
"pallet-parameters/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-ranked-collective/runtime-benchmarks",
Expand Down Expand Up @@ -314,6 +320,7 @@ try-runtime = [
"polkadot-runtime-common/try-runtime",
"runtime-parachains/try-runtime",
"sp-runtime/try-runtime",
"pallet-parameters/try-runtime",
]

# Enable metadata hash generation at compile time for the `CheckMetadataHash` extension.
Expand Down
Loading
Loading