Skip to content

Commit

Permalink
Rename disabling_threshold -> disabling_limit
Browse files Browse the repository at this point in the history
  • Loading branch information
tdimitrov committed Nov 16, 2023
1 parent 06e79d9 commit 9f8c598
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ pub(crate) fn add_slash(who: &AccountId) {
// Slashes enough validators to cross the `Staking::OffendingValidatorsThreshold`.
pub(crate) fn slash_through_offending_threshold() {
let validators = Session::validators();
let mut remaining_slashes = pallet_staking::disabling_threshold(validators.len());
let mut remaining_slashes = pallet_staking::disabling_limit(validators.len());

for v in validators.into_iter() {
if remaining_slashes != 0 {
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ pub use sp_staking::{Exposure, IndividualExposure, StakerStatus};
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
pub use weights::WeightInfo;

pub use pallet::{disabling_threshold, pallet::*, UseNominatorsAndValidatorsMap, UseValidatorsMap};
pub use pallet::{disabling_limit, pallet::*, UseNominatorsAndValidatorsMap, UseValidatorsMap};

pub(crate) const STAKING_ID: LockIdentifier = *b"staking ";
pub(crate) const LOG_TARGET: &str = "runtime::staking";
Expand Down
6 changes: 3 additions & 3 deletions substrate/frame/staking/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1873,8 +1873,8 @@ fn is_sorted_and_unique(list: &[u32]) -> bool {
list.windows(2).all(|w| w[0] < w[1])
}

/// Disabling threshold calculated from the total number of validators in the active set. When
/// reached no more validators will be disabled.
pub fn disabling_threshold(validators_len: usize) -> usize {
/// Disabling limit calculated from the total number of validators in the active set. When reached
/// no more validators will be disabled.
pub fn disabling_limit(validators_len: usize) -> usize {
validators_len.saturating_sub(1) / 3
}
4 changes: 2 additions & 2 deletions substrate/frame/staking/src/slashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
//! Based on research at <https://research.web3.foundation/en/latest/polkadot/slashing/npos.html>

use crate::{
pallet::disabling_threshold, BalanceOf, Config, DisabledValidators, Error, Exposure,
pallet::disabling_limit, BalanceOf, Config, DisabledValidators, Error, Exposure,
NegativeImbalanceOf, NominatorSlashInEra, Pallet, Perbill, SessionInterface, SpanSlash,
UnappliedSlash, ValidatorSlashInEra,
};
Expand Down Expand Up @@ -336,7 +336,7 @@ fn add_offending_validator<T: Config>(stash: &T::AccountId) {
// this is a new offending validator

// we don't want to disable too many validators otherwise we will break consensus
if offending.len() >= disabling_threshold(validators.len()) as usize {
if offending.len() >= disabling_limit(validators.len()) as usize {
return
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3424,7 +3424,7 @@ fn offence_threshold_doesnt_trigger_new_era() {
mock::start_active_era(1);
assert_eq_uvec!(Session::validators(), vec![11, 21, 31, 41]);

assert_eq!(crate::disabling_threshold(Session::validators().len()), 1);
assert_eq!(crate::disabling_limit(Session::validators().len()), 1);

// we have 4 validators and an offending validator threshold of 1/3,
// even if the third validator commits an offence a new era should not be forced
Expand Down

0 comments on commit 9f8c598

Please sign in to comment.