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

Validator Re-Enabling #5724

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
3d438de
expand DisabledValidators with severity
Overkillus Aug 27, 2024
b2d21dd
comment
Overkillus Aug 26, 2024
4c01a56
migration to disabling with severity
Overkillus Aug 28, 2024
996dfab
initial func tests
Overkillus Aug 28, 2024
d908f65
session val index enabling
Overkillus Aug 28, 2024
ec350ff
Disabling Decision Abstraction
Overkillus Aug 28, 2024
927d686
DisablingDecision struct refactor
Overkillus Aug 30, 2024
533025b
prdoc
Overkillus Sep 17, 2024
29111f0
extra staking func tests
Overkillus Sep 17, 2024
a9d2450
decision docs
Overkillus Sep 17, 2024
dbaa856
migration desc in prdoc
Overkillus Sep 17, 2024
7bcfd3e
severity update todo
Overkillus Sep 17, 2024
9fe1cac
migration cleanup
Overkillus Sep 17, 2024
0d994ad
repeated offences can update severity
Overkillus Sep 23, 2024
50dbecf
extra severity update tests
Overkillus Sep 23, 2024
1db6a26
refactor match in add_offending_validator
Overkillus Sep 23, 2024
29c59a6
reenabling test update
Overkillus Sep 23, 2024
2b78972
reenabling test updates p2
Overkillus Sep 23, 2024
32941ab
changing config and default to reenabling strategy
Overkillus Sep 23, 2024
c153fc0
Mock tests and disabling events
Overkillus Sep 24, 2024
63cca97
fmt
Overkillus Sep 24, 2024
ca99191
prdoc format fix
Overkillus Sep 24, 2024
27c698f
storage version bump
Overkillus Oct 1, 2024
0baf1ed
import clean
Overkillus Oct 1, 2024
14f5545
westend bump
Overkillus Oct 2, 2024
1880ee5
try runtime checks
Overkillus Oct 2, 2024
02c5d51
try runtime tests
Overkillus Oct 2, 2024
e0970c7
fmt
Overkillus Oct 2, 2024
cb75b92
changelog
Overkillus Oct 2, 2024
e4dfd4a
Update prdoc/pr_5724.prdoc
Overkillus Oct 15, 2024
12d88d0
decision doc fix
Overkillus Oct 15, 2024
9ebd8a7
changelog fixes
Overkillus Oct 15, 2024
a3aa92f
#64 fix
Overkillus Oct 30, 2024
ece9025
reverting #64 fix in paras runtime
Overkillus Oct 31, 2024
1e1bc48
perbill -> OffenceSeverity wrapper
Overkillus Oct 31, 2024
3382397
OffenceSeverity adjusted tests
Overkillus Oct 31, 2024
bd7cd72
deduplicate disable_limit
Overkillus Nov 4, 2024
a07a7e8
typo
Overkillus Nov 4, 2024
675b2be
non-cumulative assumption for re-enabling strategy impl
Overkillus Nov 4, 2024
f07d895
Merge branch 'master' into mkz-re-enabling
Overkillus Nov 4, 2024
273342a
md fmt
Overkillus Nov 4, 2024
cac5a61
fmt
Overkillus Nov 4, 2024
b8f6e04
clean
Overkillus Nov 4, 2024
2fe9b6d
typo
Overkillus Nov 5, 2024
beaf472
Merge branch 'master' into mkz-re-enabling
Overkillus Nov 5, 2024
dcd312e
Merge branch 'master' into mkz-re-enabling
Overkillus Nov 11, 2024
f7f9096
Merge branch 'master' into mkz-re-enabling
Ank4n Nov 12, 2024
3802d74
defensive
Overkillus Nov 13, 2024
73bd23b
Merge branch 'master' into mkz-re-enabling
Overkillus Nov 13, 2024
c4a19f5
fmt
Overkillus Nov 13, 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
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ impl<H: Hasher> CacheProvider<H> {
}

impl<H: Hasher> TrieCacheProvider<H> for CacheProvider<H> {
type Cache<'a> = TrieCache<'a, H> where H: 'a;
type Cache<'a>
= TrieCache<'a, H>
where
H: 'a;

fn as_trie_db_cache(&self, storage_root: <H as Hasher>::Out) -> Self::Cache<'_> {
TrieCache {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ impl<H: Hasher> SizeOnlyRecorderProvider<H> {
}

impl<H: trie_db::Hasher> sp_trie::TrieRecorderProvider<H> for SizeOnlyRecorderProvider<H> {
type Recorder<'a> = SizeOnlyRecorder<'a, H> where H: 'a;
type Recorder<'a>
= SizeOnlyRecorder<'a, H>
where
H: 'a;

fn drain_storage_proof(self) -> Option<StorageProof> {
None
Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ impl pallet_staking::Config for Runtime {
type BenchmarkingConfig = polkadot_runtime_common::StakingBenchmarkingConfig;
type EventListeners = ();
type WeightInfo = ();
type DisablingStrategy = pallet_staking::UpToLimitDisablingStrategy;
type DisablingStrategy = pallet_staking::UpToLimitWithReEnablingDisablingStrategy;
}

parameter_types! {
Expand Down
5 changes: 3 additions & 2 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("westend"),
impl_name: create_runtime_str!("parity-westend"),
authoring_version: 2,
spec_version: 1_016_001,
spec_version: 1_016_002,
Overkillus marked this conversation as resolved.
Show resolved Hide resolved
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 26,
Expand Down Expand Up @@ -754,7 +754,7 @@ impl pallet_staking::Config for Runtime {
type BenchmarkingConfig = polkadot_runtime_common::StakingBenchmarkingConfig;
type EventListeners = (NominationPools, DelegatedStaking);
type WeightInfo = weights::pallet_staking::WeightInfo<Runtime>;
type DisablingStrategy = pallet_staking::UpToLimitDisablingStrategy;
type DisablingStrategy = pallet_staking::UpToLimitWithReEnablingDisablingStrategy;
}

impl pallet_fast_unstake::Config for Runtime {
Expand Down Expand Up @@ -1837,6 +1837,7 @@ pub mod migrations {
>,
parachains_shared::migration::MigrateToV1<Runtime>,
parachains_scheduler::migration::MigrateV2ToV3<Runtime>,
pallet_staking::migrations::v16::MigrateV15ToV16<Runtime>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
);
Expand Down
37 changes: 37 additions & 0 deletions prdoc/pr_5724.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Validator Re-Enabling (master PR)

doc:
- audience: Runtime Dev
description: |
Implementation of the Stage 3 for the New Disabling Strategy: https://github.com/paritytech/polkadot-sdk/issues/4359

This PR changes when an active validator node gets disabled for comitting offences.
When Byzantine Threshold Validators (1/3) are already disabled instead of no longer
disabling the highest offenders will be disabled potentially re-enabling low offenders.

- audience: Node Operator
description: |
Implementation of the Stage 3 for the New Disabling Strategy: https://github.com/paritytech/polkadot-sdk/issues/4359

This PR changes when an active validator node gets disabled within parachain consensus (reduced responsibilities and
Overkillus marked this conversation as resolved.
Show resolved Hide resolved
reduced rewards) for comitting offences. This should not affect active validators on a day-to-day basis and will only
be relevant when the network is under attack or there is a wide spread malfunction causing slashes. In that case
lowest offenders might get eventually re-enabled (back to normal responsibilities and normal rewards).

migrations:
db: []
runtime:
- reference: pallet-staking
description: |
Migrating `DisabledValidators` from `Vec<u32>` to `Vec<(u32, PerBill)>` where the PerBill represents the severity
of the offence in terms of the % slash.

crates:
- name: pallet-staking
bump: minor

- name: pallet-session
bump: minor
2 changes: 1 addition & 1 deletion substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ impl pallet_staking::Config for Runtime {
type EventListeners = NominationPools;
type WeightInfo = pallet_staking::weights::SubstrateWeight<Runtime>;
type BenchmarkingConfig = StakingBenchmarkingConfig;
type DisablingStrategy = pallet_staking::UpToLimitDisablingStrategy;
type DisablingStrategy = pallet_staking::UpToLimitWithReEnablingDisablingStrategy;
}

impl pallet_fast_unstake::Config for Runtime {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,9 @@ fn mass_slash_doesnt_enter_emergency_phase() {
assert_eq!(active_set_size_before_slash, active_set_size_after_slash);

// Slashed validators are disabled up to a limit
slashed.truncate(
pallet_staking::UpToLimitDisablingStrategy::<SLASHING_DISABLING_FACTOR>::disable_limit(
active_set_size_after_slash,
),
);
slashed.truncate(pallet_staking::UpToLimitWithReEnablingDisablingStrategy::<
SLASHING_DISABLING_FACTOR,
>::disable_limit(active_set_size_after_slash));

// Find the indices of the disabled validators
let active_set = Session::validators();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ impl pallet_staking::Config for Runtime {
type MaxUnlockingChunks = MaxUnlockingChunks;
type EventListeners = Pools;
type WeightInfo = pallet_staking::weights::SubstrateWeight<Runtime>;
type DisablingStrategy = pallet_staking::UpToLimitDisablingStrategy<SLASHING_DISABLING_FACTOR>;
type DisablingStrategy =
pallet_staking::UpToLimitWithReEnablingDisablingStrategy<SLASHING_DISABLING_FACTOR>;
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
}

Expand Down
17 changes: 17 additions & 0 deletions substrate/frame/session/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,23 @@ impl<T: Config> Pallet<T> {
})
}

/// Re-enable the validator of index `i`, returns `false` if the validator was already enabled.
pub fn enable_index(i: u32) -> bool {
if i >= Validators::<T>::decode_len().unwrap_or(0) as u32 {
Overkillus marked this conversation as resolved.
Show resolved Hide resolved
return false
}
Overkillus marked this conversation as resolved.
Show resolved Hide resolved

// If the validator is not disabled, return false.
DisabledValidators::<T>::mutate(|disabled| {
if let Ok(index) = disabled.binary_search(&i) {
disabled.remove(index);
true
} else {
false
}
})
}

/// Disable the validator identified by `c`. (If using with the staking pallet,
/// this would be their *stash* account.)
///
Expand Down
12 changes: 12 additions & 0 deletions substrate/frame/staking/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). We maintain a
single integer version number for staking pallet to keep track of all storage
migrations.

## [v16]


### Added

- New default implementation of `DisablingStrategy` - `UpToLimitWithReEnablingDisablingStrategy`.
Same as `UpToLimitDisablingStrategy` except when a limit (1/3 default) is reached. When limit is
reached the offender is only disabled if his offence is greater or equal than some other already
disabled offender. The smallest possible offender is re-enabled to make space for the new greater
offender. A limit should thus always be respected.
- `DisabledValidators` changed format to include severity of the offence.

## [v15]

### Added
Expand Down
Loading
Loading