Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

disputes rewards #5862

Merged
merged 8 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ impl parachains_initializer::Config for Runtime {

impl parachains_disputes::Config for Runtime {
type Event = Event;
type RewardValidators = ();
type RewardValidators = parachains_reward_points::RewardValidatorsWithEraPoints<Runtime>;
eskimor marked this conversation as resolved.
Show resolved Hide resolved
type PunishValidators = ();
type WeightInfo = weights::runtime_parachains_disputes::WeightInfo<Runtime>;
}
Expand Down
61 changes: 45 additions & 16 deletions runtime/parachains/src/reward_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 20;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both work and risk are the same as for backing, if we consider an individual validator:

  1. Fetch data + Evaluate + Vote
  2. Risk getting slashed

Therefore era points similar to what we have for backing seems very sensible to me.

Comment on lines 30 to +32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these numbers made up or sensible in some way?

How many era points do people get on average? and compared to making blocks and being online and whatever?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backing points were introduced in #2089 and there's some discussion on the PR, but not much about the actual amount.

For dispute rewards, @eskimor made an argument above that it should be the same as for backing.

The main difference between these two is that backing should normally happen on each block (at most 1 per validator) and disputes should never normally happen, although they currently do happen.

This only applies to parachain validators, which is currently a 200 validators randomly selected from the active set.

As for era points people get on Kusama, it's around 4.5k per era per validator according to https://polkachu.com/kusama/era_summaries.


/// 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(
Copy link
Contributor

Choose a reason for hiding this comment

The 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 max_validators setting (200 on Kusama/Polkadot).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

account_keys is restricted to paravalidators, so it's filtered in filter_map(|i| validators.get(i.0 as usize).cloned()).
The reason to also filter those in the active set is because staking pallet can only reward current era (or even session) active validators AFAIK.

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);
}
}
2 changes: 1 addition & 1 deletion runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ impl assigned_slots::Config for Runtime {

impl parachains_disputes::Config for Runtime {
type Event = Event;
type RewardValidators = ();
type RewardValidators = parachains_reward_points::RewardValidatorsWithEraPoints<Runtime>;
type PunishValidators = ();
type WeightInfo = weights::runtime_parachains_disputes::WeightInfo<Runtime>;
}
Expand Down