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 1.6k
disputes rewards #5862
Merged
Merged
disputes rewards #5862
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
500c094
refactor backing points to only reward active set
855a077
impl disputes::RewardValidators
1c67070
enable rewards on westend, kusama, polkadot
f81f1ae
fmt
3e70157
make dispute points same as backing
5665053
Merge branch 'master' into ao-disputes-rewards
5b8d2a4
disable on polkadot for now
e71e64c
Merge branch 'master' into ao-disputes-rewards
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
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
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 |
|---|---|---|
|
|
@@ -22,42 +22,71 @@ | |
| //! for the time being, although we will build schemes to do so in the future. | ||
| use crate::{session_info, shared}; | ||
| use frame_support::traits::ValidatorSet; | ||
| use primitives::v2::ValidatorIndex; | ||
| use frame_support::traits::{Defensive, ValidatorSet}; | ||
| use primitives::v2::{SessionIndex, ValidatorIndex}; | ||
| use sp_std::collections::btree_set::BTreeSet; | ||
|
|
||
| /// The amount of era points given by backing a candidate that is included. | ||
| pub const BACKING_POINTS: u32 = 20; | ||
| /// The amount of era points given by dispute voting on a candidate. | ||
| pub const DISPUTE_STATEMENT_POINTS: u32 = 15; | ||
ordian marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// Rewards validators for participating in parachains with era points in pallet-staking. | ||
| pub struct RewardValidatorsWithEraPoints<C>(sp_std::marker::PhantomData<C>); | ||
|
|
||
| impl<C> crate::inclusion::RewardValidators for RewardValidatorsWithEraPoints<C> | ||
| impl<C> RewardValidatorsWithEraPoints<C> | ||
| where | ||
| C: pallet_staking::Config + shared::Config + session_info::Config, | ||
| C: pallet_staking::Config + session_info::Config, | ||
| C::ValidatorSet: ValidatorSet<C::AccountId, ValidatorId = C::AccountId>, | ||
| { | ||
| fn reward_backing(indices: impl IntoIterator<Item = ValidatorIndex>) { | ||
| // Fetch the validators from the _session_ because sessions are offset from eras | ||
| // and we are rewarding for behavior in current session. | ||
| let session_index = shared::Pallet::<C>::session_index(); | ||
| /// Reward validators in session with points, but only if they are in the active set. | ||
| fn reward_only_active( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe DQ: Shouldn't we be checking also they participated in parachain consensus ? The active set is much larger than the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| session_index: SessionIndex, | ||
| indices: impl IntoIterator<Item = ValidatorIndex>, | ||
| points: u32, | ||
| ) { | ||
| let validators = session_info::Pallet::<C>::account_keys(&session_index); | ||
| let validators = match validators { | ||
| let validators = match validators | ||
| .defensive_proof("account_keys are present for dispute_period sessions") | ||
| { | ||
| Some(validators) => validators, | ||
| None => { | ||
| // Account keys are missing for the current session. | ||
| // This might happen only for the first session after | ||
| // `AccountKeys` were introduced via runtime upgrade. | ||
| return | ||
| }, | ||
| None => return, | ||
| }; | ||
| // limit rewards to the active validator set | ||
| let active_set: BTreeSet<_> = C::ValidatorSet::validators().into_iter().collect(); | ||
eskimor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| let rewards = indices | ||
| .into_iter() | ||
| .filter_map(|i| validators.get(i.0 as usize).cloned()) | ||
| .map(|v| (v, BACKING_POINTS)); | ||
| .filter(|v| active_set.contains(v)) | ||
| .map(|v| (v, points)); | ||
|
|
||
| <pallet_staking::Pallet<C>>::reward_by_ids(rewards); | ||
| } | ||
| } | ||
|
|
||
| impl<C> crate::inclusion::RewardValidators for RewardValidatorsWithEraPoints<C> | ||
| where | ||
| C: pallet_staking::Config + shared::Config + session_info::Config, | ||
| C::ValidatorSet: ValidatorSet<C::AccountId, ValidatorId = C::AccountId>, | ||
| { | ||
| fn reward_backing(indices: impl IntoIterator<Item = ValidatorIndex>) { | ||
| let session_index = shared::Pallet::<C>::session_index(); | ||
| Self::reward_only_active(session_index, indices, BACKING_POINTS); | ||
| } | ||
|
|
||
| fn reward_bitfields(_validators: impl IntoIterator<Item = ValidatorIndex>) {} | ||
| } | ||
|
|
||
| impl<C> crate::disputes::RewardValidators for RewardValidatorsWithEraPoints<C> | ||
| where | ||
| C: pallet_staking::Config + session_info::Config, | ||
| C::ValidatorSet: ValidatorSet<C::AccountId, ValidatorId = C::AccountId>, | ||
| { | ||
| fn reward_dispute_statement( | ||
| session: SessionIndex, | ||
| validators: impl IntoIterator<Item = ValidatorIndex>, | ||
| ) { | ||
| Self::reward_only_active(session, validators, DISPUTE_STATEMENT_POINTS); | ||
| } | ||
| } | ||
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
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.