mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-18 22:15:40 +00:00
Invulnerabiity from slashing for certain validators (#1355)
* Invulnerabiity from slashing * Update srml/staking/src/lib.rs Co-Authored-By: gavofyork <github@gavwood.com>
This commit is contained in:
@@ -224,6 +224,11 @@ decl_module! {
|
||||
let new: u32 = new.into();
|
||||
<OfflineSlashGrace<T>>::put(new);
|
||||
}
|
||||
|
||||
/// Set the validators who cannot be slashed (if any).
|
||||
fn set_invulnerables(validators: Vec<T::AccountId>) {
|
||||
<Invulerables<T>>::put(validators);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,6 +265,10 @@ decl_storage! {
|
||||
/// The length of the bonding duration in blocks.
|
||||
pub BondingDuration get(bonding_duration) config(): T::BlockNumber = T::BlockNumber::sa(1000);
|
||||
|
||||
/// Any validators that may never be slashed or forcible kicked. It's a Vec since they're easy to initialise
|
||||
/// and the performance hit is minimal (we expect no more than four invulnerables) and restricted to testnets.
|
||||
pub Invulerables get(invulnerables) config(): Vec<T::AccountId>;
|
||||
|
||||
/// The current era index.
|
||||
pub CurrentEra get(current_era) config(): T::BlockNumber;
|
||||
/// Preferences that a validator has.
|
||||
@@ -501,6 +510,11 @@ impl<T: Trait> Module<T> {
|
||||
pub fn on_offline_validator(v: T::AccountId, count: usize) {
|
||||
use primitives::traits::CheckedShl;
|
||||
|
||||
// Early exit if validator is invulnerable.
|
||||
if Self::invulnerables().contains(&v) {
|
||||
return
|
||||
}
|
||||
|
||||
for _ in 0..count {
|
||||
let slash_count = Self::slash_count(&v);
|
||||
<SlashCount<T>>::insert(v.clone(), slash_count + 1);
|
||||
|
||||
Reference in New Issue
Block a user