This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Adds integration test for slashed/chilled validator with subsequent validation intention #13717
Merged
paritytech-processbot
merged 9 commits into
master
from
gpestana/integration_test_chilled
May 15, 2023
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
65e791a
Adds integration test for slashed/chilled validator with subsequent v…
gpestana 0176561
Removes unecessary comment
gpestana 33a922c
Merge remote-tracking branch 'origin/master' into gpestana/integratio…
e475716
Update frame/election-provider-multi-phase/test-staking-e2e/src/lib.rs
gpestana d359331
Update frame/election-provider-multi-phase/test-staking-e2e/src/lib.rs
gpestana 6eb5e72
Addresses PR review comments
gpestana 96f9267
Merge branch 'master' into gpestana/integration_test_chilled
gpestana 7f71737
Fixes after conflict resolved
gpestana e1828d0
Merge remote-tracking branch 'origin/master' into gpestana/integratio…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
76 changes: 41 additions & 35 deletions
76
frame/election-provider-multi-phase/test-staking-e2e/Cargo.lock
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ mod mock; | |
|
|
||
| pub(crate) const LOG_TARGET: &str = "tests::e2e-epm"; | ||
|
|
||
| use frame_support::assert_ok; | ||
| use mock::*; | ||
| use sp_core::Get; | ||
| use sp_npos_elections::{to_supports, StakedAssignment}; | ||
|
|
@@ -204,3 +205,68 @@ fn continous_slashes_below_offending_threshold() { | |
| } | ||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| /// When validators are slashed, they are chilled and removed from the current `VoterList`. Thus, | ||
| /// the slashed validator should not be considered in the next validator set. However, if the | ||
| /// slashed validator sets its intention to validate again in the same era when it was slashed and | ||
| /// chilled, the validator may not be removed from the active validator set across eras, provided | ||
| /// it is selected in the subsequent era after slashed. Nominations of the slashed validator will | ||
| /// also through the slash and chilling process, as expected, and they will be active after the | ||
| /// validator re-set the intention to be validating again. | ||
| /// Related to <https://github.com/paritytech/substrate/issues/13714>. | ||
| fn set_validation_intention_after_chilled() { | ||
| use frame_election_provider_support::SortedListProvider; | ||
| use pallet_staking::{Event, Forcing, Nominators, ValidatorPrefs}; | ||
|
|
||
| let staking_builder = StakingExtBuilder::default(); | ||
| let epm_builder = EpmExtBuilder::default(); | ||
|
|
||
| ExtBuilder::default() | ||
| .staking(staking_builder) | ||
| .epm(epm_builder) | ||
| .build_and_execute(|| { | ||
| assert_eq!(active_era(), 0); | ||
| // validator is part of the validator set. | ||
| assert!(Session::validators().contains(&11)); | ||
| assert!(<Runtime as pallet_staking::Config>::VoterList::contains(&11)); | ||
|
|
||
| // nominate validator 11. | ||
| assert_ok!(Staking::nominate(RuntimeOrigin::signed(20), vec![11])); | ||
| assert_eq!(Nominators::<Runtime>::get(21).unwrap().targets, vec![11]); | ||
|
|
||
| // validator is slashed. it is removed from the `VoterList` through chilling but in the | ||
| // current era, the validator is still part of the active validator set. | ||
| add_slash(&11); | ||
| assert!(Session::validators().contains(&11)); | ||
| assert!(<Runtime as pallet_staking::Config>::VoterList::contains(&11) == false); | ||
| assert_eq!( | ||
| staking_events(), | ||
| [ | ||
| Event::Chilled { stash: 11 }, | ||
|
||
| Event::ForceEra { mode: Forcing::ForceNew }, | ||
| Event::SlashReported { | ||
| validator: 11, | ||
| slash_era: 0, | ||
| fraction: Perbill::from_percent(10) | ||
| } | ||
| ], | ||
| ); | ||
|
|
||
| // after the nominator is slashed and chilled, the nominations remain. | ||
| assert_eq!(Nominators::<Runtime>::get(21).unwrap().targets, vec![11]); | ||
gpestana marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // validator sets intention to stake again in the same era it was chilled. | ||
| assert_ok!(Staking::validate(RuntimeOrigin::signed(10), ValidatorPrefs::default())); | ||
gpestana marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // progress era and check that the slashed validator is still part of the validator | ||
| // set. | ||
| assert!(start_next_active_era().is_ok()); | ||
| assert_eq!(active_era(), 1); | ||
| assert!(Session::validators().contains(&11)); | ||
| assert!(<Runtime as pallet_staking::Config>::VoterList::contains(&11)); | ||
|
|
||
| // nominations are still active as before the slash. | ||
| assert_eq!(Nominators::<Runtime>::get(21).unwrap().targets, vec![11]); | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.