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

Allow 24 nominations per validator and publish count #7929

Closed
wants to merge 17 commits into from
Closed
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
1 change: 1 addition & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ impl pallet_staking::Config for Runtime {
// The unsigned solution weight targeted by the OCW. We set it to the maximum possible value of
// a single extrinsic.
type OffchainSolutionWeightLimit = OffchainSolutionWeightLimit;
type CompactSolution = pallet_staking::default_solution::CompactSolution24;
type WeightInfo = pallet_staking::weights::SubstrateWeight<Runtime>;
}

Expand Down
1 change: 1 addition & 0 deletions frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ impl pallet_staking::Config for Test {
type MaxIterations = ();
type MinSolutionScoreBump = ();
type OffchainSolutionWeightLimit = ();
type CompactSolution = pallet_staking::default_solution::CompactSolution24;
type WeightInfo = ();
}

Expand Down
2 changes: 1 addition & 1 deletion frame/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ mod tests {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type SS58Prefix = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions frame/grandpa/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ impl pallet_staking::Config for Test {
type MaxIterations = ();
type MinSolutionScoreBump = ();
type OffchainSolutionWeightLimit = ();
type CompactSolution = pallet_staking::default_solution::CompactSolution24;
type WeightInfo = ();
}

Expand Down
9 changes: 5 additions & 4 deletions frame/offences/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ use pallet_session::historical::{Config as HistoricalConfig, IdentificationTuple
use pallet_session::{Config as SessionConfig, SessionManager};
use pallet_staking::{
Module as Staking, Config as StakingConfig, RewardDestination, ValidatorPrefs,
Exposure, IndividualExposure, ElectionStatus, MAX_NOMINATIONS, Event as StakingEvent
Exposure, IndividualExposure, ElectionStatus, Event as StakingEvent,
default_solution::CompactSolution,
};

const SEED: u32 = 0;
Expand Down Expand Up @@ -236,7 +237,7 @@ benchmarks! {
let r in 1 .. MAX_REPORTERS;
// we skip 1 offender, because in such case there is no slashing
let o in 2 .. MAX_OFFENDERS;
let n in 0 .. MAX_NOMINATORS.min(MAX_NOMINATIONS as u32);
let n in 0 .. MAX_NOMINATORS.min(<T as pallet_staking::Config>::CompactSolution::LIMIT as u32);
Copy link
Contributor

Choose a reason for hiding this comment

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

I kinda blindly changed these and didn't check the full scope, they were 16 before, and now they are 24, just different syntax.

Copy link
Contributor

Choose a reason for hiding this comment

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

we can reexecute benchmarks to see


// Make r reporters
let mut reporters = vec![];
Expand Down Expand Up @@ -310,7 +311,7 @@ benchmarks! {
}

report_offence_grandpa {
let n in 0 .. MAX_NOMINATORS.min(MAX_NOMINATIONS as u32);
let n in 0 .. MAX_NOMINATORS.min(<T as pallet_staking::Config>::CompactSolution::LIMIT as u32);

// for grandpa equivocation reports the number of reporters
// and offenders is always 1
Expand Down Expand Up @@ -346,7 +347,7 @@ benchmarks! {
}

report_offence_babe {
let n in 0 .. MAX_NOMINATORS.min(MAX_NOMINATIONS as u32);
let n in 0 .. MAX_NOMINATORS.min(<T as pallet_staking::Config>::CompactSolution::LIMIT as u32);

// for babe equivocation reports the number of reporters
// and offenders is always 1
Expand Down
1 change: 1 addition & 0 deletions frame/offences/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ impl pallet_staking::Config for Test {
type MaxIterations = ();
type MinSolutionScoreBump = ();
type OffchainSolutionWeightLimit = ();
type CompactSolution = pallet_staking::default_solution::CompactSolution24;
type WeightInfo = ();
}

Expand Down
11 changes: 6 additions & 5 deletions frame/session/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ use frame_system::RawOrigin;
use pallet_session::{historical::Module as Historical, Module as Session, *};
use pallet_staking::{
benchmarking::create_validator_with_nominators, testing_utils::create_validators,
MAX_NOMINATIONS, RewardDestination,
default_solution::CompactSolution,
RewardDestination,
};
use sp_runtime::traits::{One, StaticLookup};

Expand All @@ -52,10 +53,10 @@ impl<T: Config> OnInitialize<T::BlockNumber> for Module<T> {

benchmarks! {
set_keys {
let n = MAX_NOMINATIONS as u32;
let n = <T as pallet_staking::Config>::CompactSolution::LIMIT as u32;
let (v_stash, _) = create_validator_with_nominators::<T>(
n,
MAX_NOMINATIONS as u32,
<T as pallet_staking::Config>::CompactSolution::LIMIT as u32,
false,
RewardDestination::Staked,
)?;
Expand All @@ -68,10 +69,10 @@ benchmarks! {
}: _(RawOrigin::Signed(v_controller), keys, proof)

purge_keys {
let n = MAX_NOMINATIONS as u32;
let n = <T as pallet_staking::Config>::CompactSolution::LIMIT as u32;
let (v_stash, _) = create_validator_with_nominators::<T>(
n,
MAX_NOMINATIONS as u32,
<T as pallet_staking::Config>::CompactSolution::LIMIT as u32,
false,
RewardDestination::Staked
)?;
Expand Down
1 change: 1 addition & 0 deletions frame/session/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ impl pallet_staking::Config for Test {
type MaxIterations = ();
type MinSolutionScoreBump = ();
type OffchainSolutionWeightLimit = ();
type CompactSolution = pallet_staking::default_solution::CompactSolution24;
type WeightInfo = ();
}

Expand Down
1 change: 1 addition & 0 deletions frame/staking/fuzzer/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,6 @@ impl pallet_staking::Config for Test {
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type UnsignedPriority = ();
type OffchainSolutionWeightLimit = ();
type CompactSolution = pallet_staking::default_solution::CompactSolution24;
type WeightInfo = ();
}
1 change: 1 addition & 0 deletions frame/staking/fuzzer/src/submit_solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ fn main() {
num_nominators,
edge_per_voter as usize,
true,
1000,
None,
));

Expand Down
67 changes: 39 additions & 28 deletions frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,22 @@ benchmarks! {
}

kick {
// scenario: we want to kick `k` nominators from nominating us (we are a validator).
// we'll assume that `k` is under 128 for the purposes of determining the slope.
// each nominator should have `MAX_NOMINATIONS` validators nominated, and our validator
// should be somewhere in there.
// scenario: we want to kick `k` nominators from nominating us (we are a validator). we'll
// assume that `k` is under 128 for the purposes of determining the slope. each nominator
// should have `T::CompactSolution::LIMIT` validators nominated, and our validator should be
// somewhere in there.
let k in 1 .. 128;

// these are the other validators; there are `MAX_NOMINATIONS - 1` of them, so there are a
// total of `MAX_NOMINATIONS` validators in the system.
let rest_of_validators = create_validators::<T>(MAX_NOMINATIONS as u32 - 1, 100)?;
// these are the other validators; there are `T::CompactSolution::LIMIT - 1` of them, so
// there are a total of `T::CompactSolution::LIMIT` validators in the system.
let rest_of_validators = create_validators::<T>(T::CompactSolution::LIMIT as u32 - 1, 100)?;

// this is the validator that will be kicking.
let (stash, controller) = create_stash_controller::<T>(MAX_NOMINATIONS as u32 - 1, 100, Default::default())?;
let (stash, controller) = create_stash_controller::<T>(
T::CompactSolution::LIMIT as u32 - 1,
100,
Default::default(),
)?;
let stash_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(stash.clone());

// they start validating.
Expand All @@ -222,7 +226,8 @@ benchmarks! {
let mut nominator_stashes = Vec::with_capacity(k as usize);
for i in 0 .. k {
// create a nominator stash.
let (n_stash, n_controller) = create_stash_controller::<T>(MAX_NOMINATIONS as u32 + i, 100, Default::default())?;
let (n_stash, n_controller) =
create_stash_controller::<T>(T::CompactSolution::LIMIT as u32 + i, 100, Default::default())?;

// bake the nominations; we first clone them from the rest of the validators.
let mut nominations = rest_of_validators.clone();
Expand Down Expand Up @@ -254,9 +259,9 @@ benchmarks! {
}
}

// Worst case scenario, MAX_NOMINATIONS
// Worst case scenario, T::CompactSolution::LIMIT
nominate {
let n in 1 .. MAX_NOMINATIONS as u32;
let n in 1 .. T::CompactSolution::LIMIT as u32;
let (stash, controller) = create_stash_controller::<T>(n + 1, 100, Default::default())?;
let validators = create_validators::<T>(n, 100)?;
whitelist_account!(controller);
Expand Down Expand Up @@ -438,7 +443,11 @@ benchmarks! {
CurrentEra::put(e);
for i in 0 .. e {
<ErasStakers<T>>::insert(i, T::AccountId::default(), Exposure::<T::AccountId, BalanceOf<T>>::default());
<ErasStakersClipped<T>>::insert(i, T::AccountId::default(), Exposure::<T::AccountId, BalanceOf<T>>::default());
<ErasStakersClipped<T>>::insert(
i,
T::AccountId::default(),
Exposure::<T::AccountId, BalanceOf<T>>::default(),
);
<ErasValidatorPrefs<T>>::insert(i, T::AccountId::default(), ValidatorPrefs::default());
<ErasValidatorReward<T>>::insert(i, BalanceOf::<T>::one());
<ErasRewardPoints<T>>::insert(i, EraRewardPoints::<T::AccountId>::default());
Expand All @@ -465,7 +474,7 @@ benchmarks! {
let v in 1 .. 10;
let n in 1 .. 100;

create_validators_with_nominators_for_era::<T>(v, n, MAX_NOMINATIONS, false, None)?;
create_validators_with_nominators_for_era::<T>(v, n, T::CompactSolution::LIMIT, false, 1000, None)?;
let session_index = SessionIndex::one();
}: {
let validators = Staking::<T>::new_era(session_index).ok_or("`new_era` failed")?;
Expand All @@ -476,7 +485,7 @@ benchmarks! {
payout_all {
let v in 1 .. 10;
let n in 1 .. 100;
create_validators_with_nominators_for_era::<T>(v, n, MAX_NOMINATIONS, false, None)?;
create_validators_with_nominators_for_era::<T>(v, n, T::CompactSolution::LIMIT, false, 1000, None)?;
// Start a new Era
let new_validators = Staking::<T>::new_era(SessionIndex::one()).unwrap();
assert!(new_validators.len() == v as usize);
Expand Down Expand Up @@ -550,22 +559,23 @@ benchmarks! {
// `compact.len()`.
let a in 200 .. 400;
// number of winners, also ValidatorCount. This will be equal to `winner.len()`.
let w in 16 .. 100;
let w in 24 .. 100;

ensure!(w as usize >= MAX_NOMINATIONS, "doesn't support lower value");
assert!(w as usize >= T::CompactSolution::LIMIT, "doesn't support lower value");

let winners = create_validators_with_nominators_for_era::<T>(
v,
n,
MAX_NOMINATIONS,
T::CompactSolution::LIMIT,
false,
1000,
Some(w),
)?;

// needed for the solution to be generates.
// needed for the solution to be generated.
assert!(<Staking<T>>::create_stakers_snapshot().0);

// set number of winners
// set number of winners.
ValidatorCount::put(w);

// create a assignments in total for the w winners.
Expand Down Expand Up @@ -612,7 +622,7 @@ benchmarks! {
assert_eq!(<Staking<T>>::queued_score().unwrap(), score);
}

// same as submit_solution_initial but we place a very weak solution on chian first.
// same as submit_solution_initial but we place a very weak solution on chain first.
submit_solution_better {
// number of validator intention.
let v in 200 .. 400;
Expand All @@ -621,15 +631,16 @@ benchmarks! {
// number of assignments. Basically, number of active nominators.
let a in 200 .. 400;
// number of winners, also ValidatorCount.
let w in 16 .. 100;
let w in 24 .. 100;

ensure!(w as usize >= MAX_NOMINATIONS, "doesn't support lower value");
assert!(w as usize >= T::CompactSolution::LIMIT, "doesn't support lower value");

let winners = create_validators_with_nominators_for_era::<T>(
v,
n,
MAX_NOMINATIONS,
T::CompactSolution::LIMIT,
false,
1000,
Some(w),
)?;

Expand Down Expand Up @@ -713,7 +724,7 @@ benchmarks! {
// number of nominator intention.
let n in 500 .. 1000;

create_validators_with_nominators_for_era::<T>(v, n, MAX_NOMINATIONS, false, None)?;
create_validators_with_nominators_for_era::<T>(v, n, T::CompactSolution::LIMIT, false, 1000, None)?;

// needed for the solution to be generates.
assert!(<Staking<T>>::create_stakers_snapshot().0);
Expand Down Expand Up @@ -767,7 +778,7 @@ benchmarks! {
#[cfg(test)]
mod tests {
use super::*;
use crate::mock::{ExtBuilder, Test, Balances, Staking, Origin};
use crate::mock::{ExtBuilder, Test, Balances, Staking, Origin, TestSolution,};
use frame_support::assert_ok;

#[test]
Expand All @@ -776,7 +787,7 @@ mod tests {
let v = 10;
let n = 100;

create_validators_with_nominators_for_era::<Test>(v, n, MAX_NOMINATIONS, false, None)
create_validators_with_nominators_for_era::<Test>(v, n, TestSolution::LIMIT, false, 1000, None)
.unwrap();

let count_validators = Validators::<Test>::iter().count();
Expand Down Expand Up @@ -891,15 +902,15 @@ mod tests {
assert_ok!(test_benchmark_do_slash::<Test>());
assert_ok!(test_benchmark_payout_all::<Test>());
// only run one of them to same time on the CI. ignore the other two.
assert_ok!(test_benchmark_submit_solution_initial::<Test>());
assert_ok!(test_benchmark_submit_solution_better::<Test>());
});
}

#[test]
#[ignore]
fn test_benchmarks_offchain() {
ExtBuilder::default().has_stakers(false).build().execute_with(|| {
assert_ok!(test_benchmark_submit_solution_better::<Test>());
assert_ok!(test_benchmark_submit_solution_initial::<Test>());
assert_ok!(test_benchmark_submit_solution_weaker::<Test>());
});
}
Expand Down
Loading