Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Rollback to normal
  • Loading branch information
kianenigma committed Sep 30, 2020
commit 86d24a3dc613c88e64eb0a0c8991bb8adc5bfd20
11 changes: 3 additions & 8 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,6 @@ 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);
// The unsigned solution is mandatory, and this is the absolute maximum weight that we allow for
// it.
pub OffchainSolutionWeightLimit: Weight =
MaximumBlockWeight::get()
.saturating_sub(BlockExecutionWeight::get())
.saturating_sub(ExtrinsicBaseWeight::get())
.saturating_sub(AVERAGE_ON_INITIALIZE_WEIGHT * MaximumBlockWeight::get());
}

impl pallet_staking::Trait for Runtime {
Expand Down Expand Up @@ -476,7 +469,9 @@ impl pallet_staking::Trait for Runtime {
type MinSolutionScoreBump = MinSolutionScoreBump;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type UnsignedPriority = StakingUnsignedPriority;
type OffchainSolutionWeightLimit = OffchainSolutionWeightLimit;
// The unsigned solution weight targeted by the OCW. We set it to the maximum possible value of
// a single extrinsic.
type OffchainSolutionWeightLimit = MaximumExtrinsicWeight;
type WeightInfo = weights::pallet_staking::WeightInfo<Runtime>;
}

Expand Down
28 changes: 7 additions & 21 deletions frame/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1239,8 +1239,6 @@ decl_error! {
OffchainElectionBogusScore,
/// The election size is invalid.
OffchainElectionBogusElectionSize,
/// The election weight is invalid.
OffchainElectionBogusElectionWeight,
/// The call is not allowed at the given time due to restrictions of election period.
CallNotAllowed,
/// Incorrect previous history depth input provided.
Expand Down Expand Up @@ -1303,6 +1301,7 @@ decl_module! {
consumed_weight += T::DbWeight::get().reads_writes(reads, writes);
consumed_weight += weight;
};

if
// if we don't have any ongoing offchain compute.
Self::era_election_status().is_closed() &&
Expand Down Expand Up @@ -2150,15 +2149,14 @@ decl_module! {
/// transaction in the block.
///
/// # <weight>
/// The weight of this call is not enforced by the system module and is enforced in this
/// module directly.
/// See [`submit_election_solution`].
/// # </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::Mandatory)]
)]
pub fn submit_election_solution_unsigned(
origin,
winners: Vec<ValidatorIndex>,
Expand All @@ -2168,13 +2166,6 @@ decl_module! {
size: ElectionSize,
) -> DispatchResultWithPostInfo {
ensure_none(origin)?;
// The signed solution is `Normal` and the system module checks the weight. But for this
// mandatory one, we need to do it.
ensure!(
Self::check_unsigned_solution_weight(&winners, &compact, &size),
Error::<T>::OffchainElectionBogusElectionWeight.with_weight(0),
);

let adjustments = Self::check_and_replace_solution(
winners,
compact,
Expand Down Expand Up @@ -3378,11 +3369,11 @@ impl<T: Trait> frame_support::unsigned::ValidateUnsigned for Module<T> {
type Call = Call<T>;
fn validate_unsigned(source: TransactionSource, call: &Self::Call) -> TransactionValidity {
if let Call::submit_election_solution_unsigned(
winners,
compact,
_,
_,
score,
era,
size,
_,
) = call {
use offchain_election::DEFAULT_LONGEVITY;

Expand All @@ -3395,11 +3386,6 @@ impl<T: Trait> frame_support::unsigned::ValidateUnsigned for Module<T> {
}
}

// discard solution if it is too big.
if !Self::check_unsigned_solution_weight(winners, compact, size) {
return Err(InvalidTransaction::ExhaustsResources.into())
}

if let Err(error_with_post_info) = Self::pre_dispatch_checks(*score, *era) {
let invalid = to_invalid(error_with_post_info);
log!(
Expand Down