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

feat: introduce pallet-parameters to Westend to parameterize inflation #4938

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
81da185
feat: setup pallet-parameters in westend runtime
marcuspang Jul 3, 2024
e84a472
feat: introduce dynamic params for staking reward params
marcuspang Jul 3, 2024
e8d2ec5
feat: add new era relay payout function
marcuspang Jul 4, 2024
77a28cc
feat: add new era payout fn with dynamic params
marcuspang Jul 4, 2024
b010d0b
fix: total stakable value + remove NIS
marcuspang Jul 5, 2024
30caa8c
chore: remove unused weight params
marcuspang Jul 5, 2024
08b9287
build: remove unused reward staking curve pallet
marcuspang Jul 5, 2024
282aa21
chore: remove unused era_payout function
marcuspang Jul 5, 2024
ff9e782
chore: leave deprecated function in crate
marcuspang Jul 5, 2024
90f031d
Merge branch 'master' into feat/make-westend-inflation-parameterizable
kianenigma Jul 8, 2024
ae01d45
test: add unit test to ensure payout logic is same using legacy aucti…
marcuspang Jul 10, 2024
aa563f5
fix: add allow deprecated macro for tests
marcuspang Jul 10, 2024
ae0a72d
fix: missing default trait for runtimeparameters
marcuspang Jul 10, 2024
451f622
docs: add comments for era payout params
marcuspang Jul 10, 2024
849604c
Merge branch 'master' into feat/make-westend-inflation-parameterizable
kianenigma Jul 10, 2024
e866cd9
doc: update stakable amount description
marcuspang Jul 11, 2024
833d209
refactor: move deprecated fn to test module
marcuspang Jul 11, 2024
2ea077f
Merge branch 'master' into feat/make-westend-inflation-parameterizable
kianenigma Jul 17, 2024
8843d73
works
kianenigma Jul 17, 2024
704e13c
add weight file
kianenigma Jul 17, 2024
4884a48
fmt toml
kianenigma Jul 17, 2024
c7ee56c
Merge branch 'master' into feat/make-westend-inflation-parameterizable
kianenigma Jul 17, 2024
ede367a
remove api
kianenigma Jul 17, 2024
fdeaacd
Merge branch 'feat/make-westend-inflation-parameterizable' of github.…
kianenigma Jul 17, 2024
c866a69
update lock
kianenigma Jul 17, 2024
7ce4449
fix
kianenigma Jul 17, 2024
e8037de
remove more unused stuff
kianenigma Jul 17, 2024
8d62d46
add prodoc
kianenigma Jul 18, 2024
810b2b0
Merge branch 'master' of github.com:paritytech/polkadot-sdk into feat…
kianenigma Jul 18, 2024
d8760c7
add release related stuff
kianenigma Jul 18, 2024
026dcb6
revert
kianenigma Jul 18, 2024
2e128ac
".git/.scripts/commands/fmt/fmt.sh"
Jul 18, 2024
8a6d11e
remove unused
kianenigma Jul 18, 2024
6ab2d43
Merge branch 'master' of github.com:paritytech/polkadot-sdk into feat…
kianenigma Jul 18, 2024
e993b59
Merge branch 'feat/make-westend-inflation-parameterizable' of github.…
kianenigma Jul 18, 2024
e520f23
Empty-Commit
kianenigma Jul 18, 2024
28c1c2d
Merge branch 'master' into feat/make-westend-inflation-parameterizable
kianenigma Jul 18, 2024
98d7d91
Merge branch 'master' into feat/make-westend-inflation-parameterizable
kianenigma Jul 19, 2024
4f6316a
Merge branch 'master' into feat/make-westend-inflation-parameterizable
kianenigma Jul 19, 2024
b972461
Merge branch 'master' into feat/make-westend-inflation-parameterizable
kianenigma Jul 22, 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
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.

9 changes: 8 additions & 1 deletion polkadot/runtime/westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pallet-multisig = { workspace = true }
pallet-nomination-pools = { workspace = true }
pallet-conviction-voting = { workspace = true }
pallet-offences = { workspace = true }
pallet-parameters = { workspace = true }
pallet-preimage = { workspace = true }
pallet-proxy = { workspace = true }
pallet-recovery = { workspace = true }
Expand Down Expand Up @@ -174,6 +175,7 @@ std = [
"pallet-nomination-pools/std",
"pallet-offences-benchmarking?/std",
"pallet-offences/std",
"pallet-parameters/std",
"pallet-preimage/std",
"pallet-proxy/std",
"pallet-recovery/std",
Expand Down Expand Up @@ -261,6 +263,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-recovery/runtime-benchmarks",
Expand Down Expand Up @@ -319,6 +322,7 @@ try-runtime = [
"pallet-multisig/try-runtime",
"pallet-nomination-pools/try-runtime",
"pallet-offences/try-runtime",
"pallet-parameters/try-runtime",
"pallet-preimage/try-runtime",
"pallet-proxy/try-runtime",
"pallet-recovery/try-runtime",
Expand Down Expand Up @@ -348,7 +352,10 @@ metadata-hash = ["substrate-wasm-builder/metadata-hash"]
# Set timing constants (e.g. session period) to faster versions to speed up testing.
fast-runtime = []

runtime-metrics = ["polkadot-runtime-parachains/runtime-metrics", "sp-io/with-tracing"]
runtime-metrics = [
"polkadot-runtime-parachains/runtime-metrics",
"sp-io/with-tracing",
]

# A feature that should be enabled when the runtime should be built for on-chain
# deployment. This will disable stuff that shouldn't be part of the on-chain wasm
Expand Down
73 changes: 64 additions & 9 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ use codec::{Decode, Encode, MaxEncodedLen};
use frame_election_provider_support::{bounds::ElectionBoundsBuilder, onchain, SequentialPhragmen};
use frame_support::{
derive_impl,
dynamic_params::{dynamic_pallet_params, dynamic_params},
genesis_builder_helper::{build_state, get_preset},
parameter_types,
traits::{
fungible::HoldConsideration, tokens::UnityOrOuterConversion, ConstU32, Contains, EitherOf,
EitherOfDiverse, EverythingBut, FromContains, InstanceFilter, KeyOwnerProofSystem,
LinearStoragePrice, ProcessMessage, ProcessMessageError, VariantCountOf, WithdrawReasons,
EitherOfDiverse, EnsureOriginWithArg, EverythingBut, FromContains, InstanceFilter,
KeyOwnerProofSystem, LinearStoragePrice, ProcessMessage, ProcessMessageError,
VariantCountOf, WithdrawReasons,
},
weights::{ConstantMultiplier, WeightMeter, WeightToFee as _},
PalletId,
Expand Down Expand Up @@ -241,6 +243,56 @@ parameter_types! {
pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage);
}

/// Dynamic params that can be adjusted at runtime.
#[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::<Runtime>)]
pub mod dynamic_params {
use super::*;

#[dynamic_pallet_params]
#[codec(index = 0)]
pub mod staking_reward_curve {
marcuspang marked this conversation as resolved.
Show resolved Hide resolved
#[codec(index = 0)]
pub static MinInflation: u32 = 0_025_000;
#[codec(index = 1)]
pub static MaxInflation: u32 = 0_100_000;
#[codec(index = 2)]
pub static IdealStake: u32 = 0_500_000;
#[codec(index = 3)]
pub static Falloff: u32 = 0_050_000;
#[codec(index = 4)]
pub static MaxPieceCount: u32 = 40;
#[codec(index = 5)]
pub static TestPrecision: u32 = 0_005_000;
}
}

impl pallet_parameters::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeParameters = RuntimeParameters;
type AdminOrigin = DynamicParameterOrigin;
// TODO: add benchmarking and update weight info
type WeightInfo = ();
}

/// Defines what origin can modify which dynamic parameters.
pub struct DynamicParameterOrigin;
impl EnsureOriginWithArg<RuntimeOrigin, RuntimeParametersKey> for DynamicParameterOrigin {
type Success = ();

fn try_origin(
origin: RuntimeOrigin,
key: &RuntimeParametersKey,
) -> Result<Self::Success, RuntimeOrigin> {
use crate::{dynamic_params::*, governance::*, RuntimeParametersKey::*};
// TODO: update to correct origin

match key {
StakingRewardCurve(_) => frame_system::ensure_root(origin.clone()),
}
.map_err(|_| origin)
}
}

impl pallet_preimage::Config for Runtime {
type WeightInfo = weights::pallet_preimage::WeightInfo<Runtime>;
type RuntimeEvent = RuntimeEvent;
Expand Down Expand Up @@ -598,12 +650,12 @@ impl pallet_bags_list::Config<VoterBagsListInstance> for Runtime {

pallet_staking_reward_curve::build! {
const REWARD_CURVE: PiecewiseLinear<'static> = curve!(
min_inflation: 0_025_000,
max_inflation: 0_100_000,
ideal_stake: 0_500_000,
falloff: 0_050_000,
max_piece_count: 40,
test_precision: 0_005_000,
min_inflation: 0_025_000, // dynamic_params::staking_reward_curve::MinInflation,
max_inflation: 0_100_000, // dynamic_params::staking_reward_curve::MaxInflation::get(),
ideal_stake: 0_500_000, // dynamic_params::staking_reward_curve::IdealStake::get(),
falloff: 0_050_000, // dynamic_params::staking_reward_curve::Falloff::get(),
max_piece_count: 40, // dynamic_params::staking_reward_curve::MaxPieceCount::get(),
test_precision: 0_005_000, // dynamic_params::staking_reward_curve::TestPrecision::get(),
marcuspang marked this conversation as resolved.
Show resolved Hide resolved
);
}

Expand Down Expand Up @@ -1008,7 +1060,8 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
matches!(
c,
RuntimeCall::Staking(..) |
RuntimeCall::Session(..) | RuntimeCall::Utility(..) |
RuntimeCall::Session(..) |
RuntimeCall::Utility(..) |
RuntimeCall::FastUnstake(..) |
RuntimeCall::VoterList(..) |
RuntimeCall::NominationPools(..)
Expand Down Expand Up @@ -1475,6 +1528,8 @@ mod runtime {
pub type Offences = pallet_offences;
#[runtime::pallet_index(27)]
pub type Historical = session_historical;
#[runtime::pallet_index(70)]
pub type Parameters = pallet_parameters;

#[runtime::pallet_index(8)]
pub type Session = pallet_session;
Expand Down