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

Implements partial inflation minting to treasury #1483

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
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 polkadot/runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ impl pallet_staking::Config for Runtime {
type AdminOrigin = EitherOf<EnsureRoot<Self::AccountId>, StakingAdmin>;
type SessionInterface = Self;
type EraPayout = EraPayout;
type TreasuryPalletId = TreasuryPalletId;
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
Expand Down
11 changes: 11 additions & 0 deletions polkadot/runtime/kusama/src/weights/pallet_staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,4 +793,15 @@ impl<T: frame_system::Config> pallet_staking::WeightInfo for WeightInfo<T> {
.saturating_add(Weight::from_parts(0, 0))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: Staking TreasuryInflationTreasury (r:0 w:1)
/// Proof: Staking TreasuryInflationTreasury (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn set_treasury_fraction() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 3_415_000 picoseconds.
Weight::from_parts(3_315_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}

}
1 change: 1 addition & 0 deletions polkadot/runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ impl pallet_staking::Config for Runtime {
type AdminOrigin = EitherOf<EnsureRoot<Self::AccountId>, StakingAdmin>;
type SessionInterface = Self;
type EraPayout = EraPayout;
type TreasuryPalletId = TreasuryPalletId;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
Expand Down
10 changes: 10 additions & 0 deletions polkadot/runtime/polkadot/src/weights/pallet_staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,4 +793,14 @@ impl<T: frame_system::Config> pallet_staking::WeightInfo for WeightInfo<T> {
.saturating_add(Weight::from_parts(0, 0))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: Staking TreasuryInflationTreasury (r:0 w:1)
/// Proof: Staking TreasuryInflationTreasury (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn set_treasury_fraction() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 3_415_000 picoseconds.
Weight::from_parts(3_175_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
}
3 changes: 3 additions & 0 deletions polkadot/runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use frame_election_provider_support::{
use frame_support::{
construct_runtime, parameter_types,
traits::{Everything, KeyOwnerProofSystem, WithdrawReasons},
PalletId,
};
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId};
use pallet_session::historical as session_historical;
Expand Down Expand Up @@ -321,6 +322,7 @@ parameter_types! {
pub const OnChainMaxWinners: u32 = u32::MAX;
// Unbounded number of election targets and voters.
pub ElectionBoundsOnChain: ElectionBounds = ElectionBoundsBuilder::default().build();
pub const BurnAccountId: PalletId = PalletId(*b"burnburn");
}

pub struct OnChainSeqPhragmen;
Expand Down Expand Up @@ -351,6 +353,7 @@ impl pallet_staking::Config for Runtime {
type AdminOrigin = frame_system::EnsureNever<()>;
type SessionInterface = Self;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type TreasuryPalletId = BurnAccountId; // burn inflation if treasury fraction > 0.
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
Expand Down
2 changes: 2 additions & 0 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ parameter_types! {
pub const MaxNominatorRewardedPerValidator: u32 = 64;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
pub const MaxNominations: u32 = <NposCompactSolution16 as frame_election_provider_support::NposSolution>::LIMIT as u32;
pub const BurnAccountId: PalletId = PalletId(*b"burnburn");
}

impl pallet_staking::Config for Runtime {
Expand All @@ -636,6 +637,7 @@ impl pallet_staking::Config for Runtime {
type AdminOrigin = EnsureRoot<AccountId>;
type SessionInterface = Self;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type TreasuryPalletId = BurnAccountId; // burn inflation if treasury fraction > 0.
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
Expand Down
10 changes: 10 additions & 0 deletions polkadot/runtime/westend/src/weights/pallet_staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,4 +793,14 @@ impl<T: frame_system::Config> pallet_staking::WeightInfo for WeightInfo<T> {
.saturating_add(Weight::from_parts(0, 0))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: Staking TreasuryInflationTreasury (r:0 w:1)
/// Proof: Staking TreasuryInflationTreasury (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn set_treasury_fraction() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 3_415_000 picoseconds.
Weight::from_parts(3_488_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
}
1 change: 1 addition & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ impl pallet_staking::Config for Runtime {
>;
type SessionInterface = Self;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type TreasuryPalletId = TreasuryPalletId;
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ parameter_types! {
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(16);
pub static ElectionsBounds: ElectionBounds = ElectionBoundsBuilder::default().build();
pub const BurnAccountId: frame_support::PalletId = frame_support::PalletId(*b"burnburn");
}

pub struct OnChainSeqPhragmen;
Expand Down Expand Up @@ -193,6 +194,7 @@ impl pallet_staking::Config for Test {
type SessionInterface = Self;
type UnixTime = pallet_timestamp::Pallet<Test>;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type TreasuryPalletId = BurnAccountId; // burn inflation if treasury fraction > 0.
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/beefy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ parameter_types! {
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
pub static ElectionsBoundsOnChain: ElectionBounds = ElectionBoundsBuilder::default().build();
pub const BurnAccountId: frame_support::PalletId = frame_support::PalletId(*b"burnburn");
}

pub struct OnChainSeqPhragmen;
Expand Down Expand Up @@ -215,6 +216,7 @@ impl pallet_staking::Config for Test {
type SessionInterface = Self;
type UnixTime = pallet_timestamp::Pallet<Test>;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type TreasuryPalletId = BurnAccountId; // burn inflation if treasury fraction > 0.
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ parameter_types! {
pub const MaxNominatorRewardedPerValidator: u32 = 256;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(40);
pub HistoryDepth: u32 = 84;
pub const BurnAccountId: frame_support::PalletId = frame_support::PalletId(*b"burnburn");
}

impl pallet_bags_list::Config for Runtime {
Expand Down Expand Up @@ -270,6 +271,7 @@ impl pallet_staking::Config for Runtime {
type AdminOrigin = EnsureRoot<AccountId>; // root can cancel slashes
type SessionInterface = Self;
type EraPayout = ();
type TreasuryPalletId = BurnAccountId; // burn inflation if treasury fraction > 0.
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/fast-unstake/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ parameter_types! {
pub static CurrentEra: u32 = 0;
pub static Ongoing: bool = false;
pub static MaxWinners: u32 = 100;
pub const BurnAccountId: frame_support::PalletId = frame_support::PalletId(*b"burnburn");
}

pub struct MockElection;
Expand Down Expand Up @@ -149,6 +150,7 @@ impl pallet_staking::Config for Runtime {
type BondingDuration = BondingDuration;
type SessionInterface = ();
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type TreasuryPalletId = BurnAccountId; // burn inflation if treasury fraction > 0.
type NextNewSession = ();
type HistoryDepth = ConstU32<84>;
type MaxNominatorRewardedPerValidator = ConstU32<64>;
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/grandpa/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ parameter_types! {
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
pub static ElectionsBoundsOnChain: ElectionBounds = ElectionBoundsBuilder::default().build();
pub const BurnAccountId: frame_support::PalletId = frame_support::PalletId(*b"burnburn");
}

pub struct OnChainSeqPhragmen;
Expand Down Expand Up @@ -195,6 +196,7 @@ impl pallet_staking::Config for Test {
type SessionInterface = Self;
type UnixTime = pallet_timestamp::Pallet<Test>;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type TreasuryPalletId = BurnAccountId; // burn inflation if treasury fraction > 0.
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/nomination-pools/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pallet_staking_reward_curve::build! {
}
parameter_types! {
pub const RewardCurve: &'static sp_runtime::curve::PiecewiseLinear<'static> = &I_NPOS;
pub const BurnAccountId: frame_support::PalletId = frame_support::PalletId(*b"burnburn");
}
impl pallet_staking::Config for Runtime {
type Currency = Balances;
Expand All @@ -108,6 +109,7 @@ impl pallet_staking::Config for Runtime {
type BondingDuration = ConstU32<3>;
type SessionInterface = ();
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type TreasuryPalletId = BurnAccountId; // burn inflation if treasury fraction > 0.
type NextNewSession = ();
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type OffendingValidatorsThreshold = ();
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/nomination-pools/test-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pallet_staking_reward_curve::build! {
parameter_types! {
pub const RewardCurve: &'static sp_runtime::curve::PiecewiseLinear<'static> = &I_NPOS;
pub static BondingDuration: u32 = 3;
pub const BurnAccountId: frame_support::PalletId = frame_support::PalletId(*b"burnburn");
}

impl pallet_staking::Config for Runtime {
Expand All @@ -122,6 +123,7 @@ impl pallet_staking::Config for Runtime {
type BondingDuration = BondingDuration;
type SessionInterface = ();
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type TreasuryPalletId = BurnAccountId; // burn inflation if treasury fraction > 0.
type NextNewSession = ();
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type OffendingValidatorsThreshold = ();
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/offences/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ pallet_staking_reward_curve::build! {
parameter_types! {
pub const RewardCurve: &'static sp_runtime::curve::PiecewiseLinear<'static> = &I_NPOS;
pub static ElectionsBounds: ElectionBounds = ElectionBoundsBuilder::default().build();
pub const BurnAccountId: frame_support::PalletId = frame_support::PalletId(*b"burnburn");
}

pub type Extrinsic = sp_runtime::testing::TestXt<RuntimeCall, ()>;
Expand Down Expand Up @@ -174,6 +175,7 @@ impl pallet_staking::Config for Test {
type BondingDuration = ();
type SessionInterface = Self;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type TreasuryPalletId = BurnAccountId; // burn inflation if treasury fraction > 0.
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type OffendingValidatorsThreshold = ();
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/root-offences/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ parameter_types! {
pub const BondingDuration: EraIndex = 3;
pub static LedgerSlashPerEra: (BalanceOf<Test>, BTreeMap<EraIndex, BalanceOf<Test>>) = (Zero::zero(), BTreeMap::new());
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(75);
pub const BurnAccountId: frame_support::PalletId = frame_support::PalletId(*b"burnburn");
}

impl pallet_staking::Config for Test {
Expand All @@ -177,6 +178,7 @@ impl pallet_staking::Config for Test {
type BondingDuration = BondingDuration;
type SessionInterface = Self;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type TreasuryPalletId = BurnAccountId; // burn inflation if treasury fraction > 0.
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/session/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pallet_staking_reward_curve::build! {
parameter_types! {
pub const RewardCurve: &'static sp_runtime::curve::PiecewiseLinear<'static> = &I_NPOS;
pub static ElectionsBounds: ElectionBounds = ElectionBoundsBuilder::default().build();
pub const BurnAccountId: frame_support::PalletId = frame_support::PalletId(*b"burnburn");
}

pub struct OnChainSeqPhragmen;
Expand Down Expand Up @@ -171,6 +172,7 @@ impl pallet_staking::Config for Test {
type BondingDuration = ();
type SessionInterface = Self;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type TreasuryPalletId = BurnAccountId; // burn inflation if treasury fraction > 0.
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type OffendingValidatorsThreshold = ();
Expand Down
7 changes: 7 additions & 0 deletions substrate/frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,13 @@ benchmarks! {
assert_eq!(MinCommission::<T>::get(), Perbill::from_percent(100));
}

set_treasury_fraction {
let treasury_fraction = Percent::max_value();
}: _(RawOrigin::Root, treasury_fraction)
verify {
assert_eq!(TreasuryInflationFraction::<T>::get(), Some(Percent::from_parts(100)));
}

impl_benchmark_test_suite!(
Staking,
crate::mock::ExtBuilder::default().has_stakers(true),
Expand Down
18 changes: 16 additions & 2 deletions substrate/frame/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ use frame_support::{
OnUnbalanced, OneSessionHandler,
},
weights::constants::RocksDbWeight,
PalletId,
};
use frame_system::{EnsureRoot, EnsureSignedBy};
use sp_core::H256;
use sp_io;
use sp_runtime::{
curve::PiecewiseLinear,
testing::UintAuthorityId,
traits::{IdentityLookup, Zero},
BuildStorage,
traits::{AccountIdConversion, IdentityLookup, Zero},
BuildStorage, Percent,
};
use sp_staking::offence::{DisableStrategy, OffenceDetails, OnOffenceHandler};

Expand Down Expand Up @@ -237,6 +238,7 @@ parameter_types! {
pub static MaxWinners: u32 = 100;
pub static ElectionsBounds: ElectionBounds = ElectionBoundsBuilder::default().build();
pub static AbsoluteMaxNominations: u32 = 16;
pub const TreasuryPalletId: PalletId = PalletId(*b"Treasury");
}

type VoterBagsListInstance = pallet_bags_list::Instance1;
Expand Down Expand Up @@ -298,6 +300,7 @@ impl crate::pallet::pallet::Config for Test {
type BondingDuration = BondingDuration;
type SessionInterface = Self;
type EraPayout = ConvertCurve<RewardCurve>;
type TreasuryPalletId = TreasuryPalletId;
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
Expand Down Expand Up @@ -346,6 +349,7 @@ pub struct ExtBuilder {
pub min_nominator_bond: Balance,
min_validator_bond: Balance,
balance_factor: Balance,
treasury_fraction: Percent,
status: BTreeMap<AccountId, StakerStatus<AccountId>>,
stakes: BTreeMap<AccountId, Balance>,
stakers: Vec<(AccountId, AccountId, Balance, StakerStatus<AccountId>)>,
Expand All @@ -358,6 +362,7 @@ impl Default for ExtBuilder {
validator_count: 2,
minimum_validator_count: 0,
balance_factor: 1,
treasury_fraction: Percent::from_percent(0),
invulnerables: vec![],
has_stakers: true,
initialize_first_session: true,
Expand Down Expand Up @@ -445,6 +450,10 @@ impl ExtBuilder {
self.balance_factor = factor;
self
}
pub fn treasury_fraction(mut self, fraction: u8) -> Self {
self.treasury_fraction = Percent::from_parts(fraction);
self
}
fn build(self) -> sp_io::TestExternalities {
sp_tracing::try_init_simple();
let mut storage = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
Expand Down Expand Up @@ -532,6 +541,7 @@ impl ExtBuilder {
slash_reward_fraction: Perbill::from_percent(10),
min_nominator_bond: self.min_nominator_bond,
min_validator_bond: self.min_validator_bond,
treasury_inflation_fraction: self.treasury_fraction,
..Default::default()
}
.assimilate_storage(&mut storage);
Expand Down Expand Up @@ -777,6 +787,10 @@ pub(crate) fn make_all_reward_payment(era: EraIndex) {
}
}

pub(crate) fn treasury_account_id() -> AccountId {
TreasuryPalletId::get().into_account_truncating()
}

#[macro_export]
macro_rules! assert_session_era {
($session:expr, $era:expr) => {
Expand Down
Loading