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

Fix offchain election to respect the weight #7215

Merged
25 commits merged into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
051d71e
Mockup
kianenigma Sep 24, 2020
46686d6
Fix offchain election to respect the weight
kianenigma Sep 25, 2020
649a6d6
Fix builds a bit
kianenigma Sep 25, 2020
ad19e02
Update frame/staking/src/offchain_election.rs
kianenigma Sep 28, 2020
08aec98
Update frame/staking/src/offchain_election.rs
kianenigma Sep 28, 2020
a1feaf8
Make it build, binary search
kianenigma Sep 28, 2020
b7138f9
Merge branch 'kiz-staking-OCW-check-size' of github.com:paritytech/su…
kianenigma Sep 28, 2020
2274196
Fix a number of grumbles
kianenigma Sep 28, 2020
2572e4b
one more fix.
kianenigma Sep 28, 2020
3f53149
remove unwrap.
kianenigma Sep 28, 2020
cc89113
better alg.
kianenigma Sep 28, 2020
a72069f
Better alg again.
kianenigma Sep 29, 2020
8048e4f
Merge branch 'master' of github.com:paritytech/substrate into kiz-sta…
kianenigma Sep 29, 2020
0e3c91f
Final fixes
kianenigma Sep 29, 2020
47d69f7
Fix
kianenigma Sep 30, 2020
86d24a3
Rollback to normal
kianenigma Sep 30, 2020
0b618d4
Merge branch 'master' of github.com:paritytech/substrate into kiz-sta…
kianenigma Oct 2, 2020
6b6ef3e
Final touches.
kianenigma Oct 2, 2020
addd535
Better tests.
kianenigma Oct 2, 2020
e11ab9d
Update frame/staking/src/lib.rs
kianenigma Oct 2, 2020
f1d9f2b
Proper maxExtWeight
kianenigma Oct 2, 2020
4573d36
Merge branch 'kiz-staking-OCW-check-size' of github.com:paritytech/su…
kianenigma Oct 2, 2020
a1ef1b4
Merge branch 'master' of github.com:paritytech/substrate into kiz-sta…
kianenigma Oct 2, 2020
43b149c
Final fix
kianenigma Oct 2, 2020
3ff8c0a
Final fix for the find_voter
kianenigma Oct 2, 2020
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ rls*.log
**/hfuzz_target/
**/hfuzz_workspace/
.cargo/
.cargo-remote.toml
2 changes: 2 additions & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ parameter_types! {
pub const MaxIterations: u32 = 10;
// 0.05%. The higher the value, the more strict solution acceptance becomes.
pub MinSolutionScoreBump: Perbill = Perbill::from_rational_approximation(5u32, 10_000);
pub MaximumUnsignedWeight: Weight = PerbilL::from_percent(90) * MaximumBlockWeight::get();
}

impl pallet_staking::Trait for Runtime {
Expand Down Expand Up @@ -469,6 +470,7 @@ impl pallet_staking::Trait for Runtime {
type MinSolutionScoreBump = MinSolutionScoreBump;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type UnsignedPriority = StakingUnsignedPriority;
type MaximumUnsignedWeight = StakingUnsignedPriority;
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
type WeightInfo = weights::pallet_staking::WeightInfo<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 @@ -218,6 +218,7 @@ impl pallet_staking::Trait for Test {
type UnsignedPriority = StakingUnsignedPriority;
type MaxIterations = ();
type MinSolutionScoreBump = ();
type MaximumUnsignedWeight = ();
type WeightInfo = ();
}

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 @@ -233,6 +233,7 @@ impl pallet_staking::Trait for Test {
type UnsignedPriority = StakingUnsignedPriority;
type MaxIterations = ();
type MinSolutionScoreBump = ();
type MaximumUnsignedWeight = ();
type WeightInfo = ();
}

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 @@ -183,6 +183,7 @@ impl pallet_staking::Trait for Test {
type UnsignedPriority = ();
type MaxIterations = ();
type MinSolutionScoreBump = ();
type MaximumUnsignedWeight = ();
type WeightInfo = ();
}

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 @@ -190,6 +190,7 @@ impl pallet_staking::Trait for Test {
type UnsignedPriority = UnsignedPriority;
type MaxIterations = ();
type MinSolutionScoreBump = ();
type MaximumUnsignedWeight = ();
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 @@ -195,5 +195,6 @@ impl pallet_staking::Trait for Test {
type MinSolutionScoreBump = ();
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type UnsignedPriority = ();
type MaximumUnsignedWeight = (); // TODO: this will now break the fuzzer.. this is complicated.
type WeightInfo = ();
}
10 changes: 7 additions & 3 deletions frame/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ pub enum ElectionStatus<BlockNumber> {
/// Note that these values must reflect the __total__ number, not only those that are present in the
/// solution. In short, these should be the same size as the size of the values dumped in
/// `SnapshotValidators` and `SnapshotNominators`.
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, Default)]
#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, RuntimeDebug, Default)]
pub struct ElectionSize {
/// Number of validators in the snapshot of the current election round.
#[codec(compact)]
Expand Down Expand Up @@ -883,6 +883,9 @@ pub trait Trait: frame_system::Trait + SendTransactionTypes<Call<Self>> {
/// multiple pallets send unsigned transactions.
type UnsignedPriority: Get<TransactionPriority>;

/// Maximum weight that the unsigned transaction can have.
type MaximumUnsignedWeight: Get<Weight>;

/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
}
Expand Down Expand Up @@ -2143,12 +2146,13 @@ decl_module! {
/// # <weight>
/// See `crate::weight` module.
/// # </weight>
#[weight = T::WeightInfo::submit_solution_better(
#[weight = (
T::WeightInfo::submit_solution_better(
size.validators.into(),
size.nominators.into(),
compact.len() as u32,
winners.len() as u32,
)]
), frame_support::weights::DispatchClass::Operational)]
pub fn submit_election_solution_unsigned(
tomusdrw marked this conversation as resolved.
Show resolved Hide resolved
origin,
winners: Vec<ValidatorIndex>,
Expand Down
39 changes: 25 additions & 14 deletions frame/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,32 @@

//! Test utilities

use std::{collections::HashSet, cell::RefCell};
use sp_runtime::Perbill;
use sp_runtime::curve::PiecewiseLinear;
use sp_runtime::traits::{IdentityLookup, Convert, SaturatedConversion, Zero};
use sp_runtime::testing::{Header, UintAuthorityId, TestXt};
use sp_staking::{SessionIndex, offence::{OffenceDetails, OnOffenceHandler}};
use sp_core::H256;
use crate::*;
use frame_support::{
assert_ok, impl_outer_origin, parameter_types, impl_outer_dispatch, impl_outer_event,
StorageValue, StorageMap, StorageDoubleMap, IterableStorageMap,
traits::{Currency, Get, FindAuthor, OnFinalize, OnInitialize},
weights::{Weight, constants::RocksDbWeight},
assert_ok, impl_outer_dispatch, impl_outer_event, impl_outer_origin, parameter_types,
traits::{Currency, FindAuthor, Get, OnFinalize, OnInitialize},
weights::{
constants::{RocksDbWeight, WEIGHT_PER_SECOND},
Weight,
},
IterableStorageMap, StorageDoubleMap, StorageMap, StorageValue,
};
use sp_core::H256;
use sp_io;
use sp_npos_elections::{
build_support_map, evaluate_support, reduce, ExtendedBalance, StakedAssignment, ElectionScore,
build_support_map, evaluate_support, reduce, ElectionScore, ExtendedBalance, StakedAssignment,
};
use crate::*;
use sp_runtime::{
curve::PiecewiseLinear,
testing::{Header, TestXt, UintAuthorityId},
traits::{Convert, IdentityLookup, SaturatedConversion, Zero},
Perbill,
};
use sp_staking::{
offence::{OffenceDetails, OnOffenceHandler},
SessionIndex,
};
use std::{cell::RefCell, collections::HashSet};

pub const INIT_TIMESTAMP: u64 = 30_000;

Expand Down Expand Up @@ -293,6 +301,7 @@ parameter_types! {
pub const MaxNominatorRewardedPerValidator: u32 = 64;
pub const UnsignedPriority: u64 = 1 << 20;
pub const MinSolutionScoreBump: Perbill = Perbill::zero();
pub const MaximumUnsignedWeight: Weight = MaximumBlockWeight::get();
}

thread_local! {
Expand Down Expand Up @@ -331,10 +340,12 @@ impl Trait for Test {
type MinSolutionScoreBump = MinSolutionScoreBump;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type UnsignedPriority = UnsignedPriority;
type MaximumUnsignedWeight = MaximumUnsignedWeight;
type WeightInfo = ();
}

impl<LocalCall> frame_system::offchain::SendTransactionTypes<LocalCall> for Test where
impl<LocalCall> frame_system::offchain::SendTransactionTypes<LocalCall> for Test
where
Call: From<LocalCall>,
{
type OverarchingCall = Call;
Expand Down
Loading