Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

staking: only disable slashed validators and keep them disabled for whole era #9448

Merged
11 commits merged into from
Oct 6, 2021
7 changes: 2 additions & 5 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,6 @@ impl_opaque_keys! {
}
}

parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(17);
}

impl pallet_session::Config for Runtime {
type Event = Event;
type ValidatorId = <Self as frame_system::Config>::AccountId;
Expand All @@ -472,7 +468,6 @@ impl pallet_session::Config for Runtime {
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, Staking>;
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type WeightInfo = pallet_session::weights::SubstrateWeight<Runtime>;
}

Expand All @@ -498,6 +493,7 @@ parameter_types! {
pub const SlashDeferDuration: pallet_staking::EraIndex = 24 * 7; // 1/4 the bonding duration.
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 256;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
andresilva marked this conversation as resolved.
Show resolved Hide resolved
pub OffchainRepeat: BlockNumber = 5;
}

Expand Down Expand Up @@ -529,6 +525,7 @@ impl pallet_staking::Config for Runtime {
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type ElectionProvider = ElectionProviderMultiPhase;
type GenesisElectionProvider = onchain::OnChainSequentialPhragmen<Self>;
// Alternatively, use pallet_staking::UseNominatorsMap<Runtime> to just use the nominators map.
Expand Down
2 changes: 1 addition & 1 deletion frame/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
}
}

fn on_disabled(i: usize) {
fn on_disabled(i: u32) {
let log: DigestItem<T::Hash> = DigestItem::Consensus(
AURA_ENGINE_ID,
ConsensusLog::<T::AuthorityId>::OnDisabled(i as AuthorityIndex).encode(),
Expand Down
5 changes: 2 additions & 3 deletions frame/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
}
}

fn on_disabled(_i: usize) {
fn on_disabled(_i: u32) {
// ignore
}
}
Expand Down Expand Up @@ -218,7 +218,6 @@ mod tests {
type Event = Event;
type ValidatorId = AuthorityId;
type ValidatorIdOf = ConvertInto;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
type WeightInfo = ();
}
Expand Down Expand Up @@ -276,7 +275,7 @@ mod tests {
) {
}

fn on_disabled(_validator_index: usize) {}
fn on_disabled(_validator_index: u32) {}

fn on_genesis_session<Ks: OpaqueKeys>(_validators: &[(AuthorityId, Ks)]) {}
}
Expand Down
4 changes: 2 additions & 2 deletions frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,8 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
Self::enact_epoch_change(bounded_authorities, next_bounded_authorities)
}

fn on_disabled(i: usize) {
Self::deposit_consensus(ConsensusLog::OnDisabled(i as u32))
fn on_disabled(i: u32) {
Self::deposit_consensus(ConsensusLog::OnDisabled(i))
}
}

Expand Down
4 changes: 2 additions & 2 deletions frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ frame_support::construct_runtime!(

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(16);
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
Expand Down Expand Up @@ -122,7 +121,6 @@ impl pallet_session::Config for Test {
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, Staking>;
type SessionHandler = <MockSessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = MockSessionKeys;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type WeightInfo = ();
}

Expand Down Expand Up @@ -189,6 +187,7 @@ parameter_types! {
pub const MaxNominatorRewardedPerValidator: u32 = 64;
pub const ElectionLookahead: u64 = 0;
pub const StakingUnsignedPriority: u64 = u64::MAX / 2;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(16);
}

impl onchain::Config for Test {
Expand All @@ -212,6 +211,7 @@ impl pallet_staking::Config for Test {
type UnixTime = pallet_timestamp::Pallet<Test>;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
type ElectionProvider = onchain::OnChainSequentialPhragmen<Self>;
type GenesisElectionProvider = Self::ElectionProvider;
Expand Down
3 changes: 0 additions & 3 deletions frame/beefy-mmr/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use sp_runtime::{
impl_opaque_keys,
testing::Header,
traits::{BlakeTwo256, ConvertInto, IdentityLookup, Keccak256, OpaqueKeys},
Perbill,
};

use crate as pallet_beefy_mmr;
Expand Down Expand Up @@ -92,7 +91,6 @@ impl frame_system::Config for Test {
parameter_types! {
pub const Period: u64 = 1;
pub const Offset: u64 = 0;
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(33);
}

impl pallet_session::Config for Test {
Expand All @@ -104,7 +102,6 @@ impl pallet_session::Config for Test {
type SessionManager = MockSessionManager;
type SessionHandler = <MockSessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = MockSessionKeys;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type WeightInfo = ();
}

Expand Down
2 changes: 1 addition & 1 deletion frame/beefy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
}
}

fn on_disabled(i: usize) {
fn on_disabled(i: u32) {
let log: DigestItem<T::Hash> = DigestItem::Consensus(
BEEFY_ENGINE_ID,
ConsensusLog::<T::BeefyId>::OnDisabled(i as AuthorityIndex).encode(),
Expand Down
1 change: 0 additions & 1 deletion frame/beefy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ impl pallet_session::Config for Test {
type SessionManager = MockSessionManager;
type SessionHandler = <MockSessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = MockSessionKeys;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type WeightInfo = ();
}

Expand Down
2 changes: 1 addition & 1 deletion frame/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ where
SetIdSession::<T>::insert(current_set_id, &session_index);
}

fn on_disabled(i: usize) {
fn on_disabled(i: u32) {
Self::deposit_log(ConsensusLog::OnDisabled(i as u64))
}
}
4 changes: 2 additions & 2 deletions frame/grandpa/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ where
parameter_types! {
pub const Period: u64 = 1;
pub const Offset: u64 = 0;
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(17);
}

/// Custom `SessionHandler` since we use `TestSessionKeys` as `Keys`.
Expand All @@ -124,7 +123,6 @@ impl pallet_session::Config for Test {
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, Staking>;
type SessionHandler = <TestSessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = TestSessionKeys;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type WeightInfo = ();
}

Expand Down Expand Up @@ -191,6 +189,7 @@ parameter_types! {
pub const MaxNominatorRewardedPerValidator: u32 = 64;
pub const ElectionLookahead: u64 = 0;
pub const StakingUnsignedPriority: u64 = u64::MAX / 2;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
}

impl onchain::Config for Test {
Expand All @@ -214,6 +213,7 @@ impl pallet_staking::Config for Test {
type UnixTime = pallet_timestamp::Pallet<Test>;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
type ElectionProvider = onchain::OnChainSequentialPhragmen<Self>;
type GenesisElectionProvider = Self::ElectionProvider;
Expand Down
2 changes: 1 addition & 1 deletion frame/im-online/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
}
}

fn on_disabled(_i: usize) {
fn on_disabled(_i: u32) {
// ignore
}
}
Expand Down
7 changes: 1 addition & 6 deletions frame/im-online/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use sp_core::H256;
use sp_runtime::{
testing::{Header, TestXt, UintAuthorityId},
traits::{BlakeTwo256, ConvertInto, IdentityLookup},
Perbill, Permill,
Permill,
};
use sp_staking::{
offence::{OffenceError, ReportOffence},
Expand Down Expand Up @@ -146,10 +146,6 @@ parameter_types! {
pub const Offset: u64 = 0;
}

parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(33);
}

impl pallet_session::Config for Runtime {
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
type SessionManager =
Expand All @@ -159,7 +155,6 @@ impl pallet_session::Config for Runtime {
type ValidatorIdOf = ConvertInto;
type Keys = UintAuthorityId;
type Event = Event;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
type WeightInfo = ();
}
Expand Down
4 changes: 2 additions & 2 deletions frame/offences/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl pallet_session::SessionHandler<AccountId> for TestSessionHandler {
) {
}

fn on_disabled(_: usize) {}
fn on_disabled(_: u32) {}
}

parameter_types! {
Expand All @@ -129,7 +129,6 @@ impl pallet_session::Config for Test {
type Event = Event;
type ValidatorId = AccountId;
type ValidatorIdOf = pallet_staking::StashOf<Test>;
type DisabledValidatorsThreshold = ();
type WeightInfo = ();
}

Expand Down Expand Up @@ -175,6 +174,7 @@ impl pallet_staking::Config for Test {
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type OffendingValidatorsThreshold = ();
type ElectionProvider = onchain::OnChainSequentialPhragmen<Self>;
type GenesisElectionProvider = Self::ElectionProvider;
type SortedListProvider = pallet_staking::UseNominatorsMap<Self>;
Expand Down
4 changes: 2 additions & 2 deletions frame/session/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl pallet_session::SessionHandler<AccountId> for TestSessionHandler {
) {
}

fn on_disabled(_: usize) {}
fn on_disabled(_: u32) {}
}

impl pallet_session::Config for Test {
Expand All @@ -129,7 +129,6 @@ impl pallet_session::Config for Test {
type Event = Event;
type ValidatorId = AccountId;
type ValidatorIdOf = pallet_staking::StashOf<Test>;
type DisabledValidatorsThreshold = ();
type WeightInfo = ();
}
pallet_staking_reward_curve::build! {
Expand Down Expand Up @@ -180,6 +179,7 @@ impl pallet_staking::Config for Test {
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type OffendingValidatorsThreshold = ();
type ElectionProvider = onchain::OnChainSequentialPhragmen<Self>;
type GenesisElectionProvider = Self::ElectionProvider;
type SortedListProvider = pallet_staking::UseNominatorsMap<Self>;
Expand Down
Loading