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

EPM: allow duplicate submissions #12237

Merged
merged 15 commits into from
Oct 19, 2022
Merged
Prev Previous commit
Next Next commit
Master.into()
  • Loading branch information
kianenigma committed Oct 6, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit cbac13a4ef6f329c51aa20cc5452b7340815d433
29 changes: 27 additions & 2 deletions frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
@@ -2075,7 +2075,7 @@ mod tests {
assert!(MultiPhase::snapshot_metadata().is_none());
assert!(MultiPhase::desired_targets().is_none());
assert!(MultiPhase::queued_solution().is_none());
assert!(MultiPhase::signed_submissions().len().is_zero());
assert!(MultiPhase::signed_submissions().is_empty());
})
}

@@ -2111,7 +2111,32 @@ mod tests {
assert!(MultiPhase::snapshot_metadata().is_none());
assert!(MultiPhase::desired_targets().is_none());
assert!(MultiPhase::queued_solution().is_none());
assert!(MultiPhase::signed_submissions().len().is_zero());
assert!(MultiPhase::signed_submissions().is_empty());

assert_eq!(
multi_phase_events(),
vec![
Event::SignedPhaseStarted { round: 1 },
Event::SolutionStored { compute: ElectionCompute::Signed, prev_ejected: false },
Event::SolutionStored { compute: ElectionCompute::Signed, prev_ejected: false },
Event::SolutionStored { compute: ElectionCompute::Signed, prev_ejected: false },
Event::SolutionStored { compute: ElectionCompute::Signed, prev_ejected: false },
Event::SolutionStored { compute: ElectionCompute::Signed, prev_ejected: false },
Event::Slashed { account: 99, value: 5 },
Event::Slashed { account: 99, value: 5 },
Event::Slashed { account: 99, value: 5 },
Event::Slashed { account: 99, value: 5 },
Event::Slashed { account: 99, value: 5 },
Event::ElectionFinalized {
compute: ElectionCompute::Fallback,
score: ElectionScore {
minimal_stake: 0,
sum_stake: 0,
sum_stake_squared: 0
}
}
]
);
})
}

15 changes: 10 additions & 5 deletions frame/election-provider-multi-phase/src/signed.rs
Original file line number Diff line number Diff line change
@@ -127,6 +127,11 @@ pub struct SignedSubmissions<T: Config> {
}

impl<T: Config> SignedSubmissions<T> {
/// `true` if the structure is empty.
pub fn is_empty(&self) -> bool {
self.indices.is_empty()
}

/// Get the length of submitted solutions.
pub fn len(&self) -> usize {
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
self.indices.len()
@@ -867,7 +872,7 @@ mod tests {
#[test]
fn replace_weakest_by_score_works() {
ExtBuilder::default().signed_max_submission(3).build_and_execute(|| {
roll_to(15);
roll_to_signed();
assert!(MultiPhase::current_phase().is_signed());

for s in 1..SignedMaxSubmissions::get() {
@@ -988,7 +993,7 @@ mod tests {
score: ElectionScore { minimal_stake: 5, ..Default::default() },
..Default::default()
};
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(solution)));
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution)));

assert_eq!(
MultiPhase::signed_submissions()
@@ -1003,7 +1008,7 @@ mod tests {
score: ElectionScore { minimal_stake: 5, ..Default::default() },
..Default::default()
};
assert_ok!(MultiPhase::submit(Origin::signed(999), Box::new(solution)));
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(999), Box::new(solution)));

assert_eq!(
MultiPhase::signed_submissions()
@@ -1017,7 +1022,7 @@ mod tests {
score: ElectionScore { minimal_stake: 6, ..Default::default() },
..Default::default()
};
assert_ok!(MultiPhase::submit(Origin::signed(9999), Box::new(solution)));
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(9999), Box::new(solution)));

assert_eq!(
MultiPhase::signed_submissions()
@@ -1040,7 +1045,7 @@ mod tests {
roll_to((15 + i).into());
let solution = raw_solution();
assert_ok!(MultiPhase::submit(
Origin::signed(100 + i as AccountId),
RuntimeOrigin::signed(100 + i as AccountId),
Box::new(solution)
));
}
You are viewing a condensed version of this merge commit. You can view the full changes here.