mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 12:51:05 +00:00
[Staking] Adds a round check at signed solution submission (#2690)
This PR adds a round check to the `Call::submit` extrinsic to make sure that the solution submission has been prepared for the current election round and avoid penalties for delayed submissions. Related to https://github.com/paritytech-secops/srlabs_findings/issues/329 --------- Co-authored-by: command-bot <>
This commit is contained in:
@@ -571,6 +571,40 @@ mod tests {
|
||||
use frame_support::{assert_noop, assert_ok, assert_storage_noop};
|
||||
use sp_runtime::Percent;
|
||||
|
||||
#[test]
|
||||
fn cannot_submit_on_different_round() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
// roll to a few rounds ahead.
|
||||
roll_to_round(5);
|
||||
assert_eq!(MultiPhase::round(), 5);
|
||||
|
||||
roll_to_signed();
|
||||
assert_eq!(MultiPhase::current_phase(), Phase::Signed);
|
||||
|
||||
// create a temp snapshot only for this test.
|
||||
MultiPhase::create_snapshot().unwrap();
|
||||
let mut solution = raw_solution();
|
||||
|
||||
// try a solution prepared in a previous round.
|
||||
solution.round = MultiPhase::round() - 1;
|
||||
|
||||
assert_noop!(
|
||||
MultiPhase::submit(RuntimeOrigin::signed(10), Box::new(solution)),
|
||||
Error::<Runtime>::PreDispatchDifferentRound,
|
||||
);
|
||||
|
||||
// try a solution prepared in a later round (not expected to happen, but in any case).
|
||||
MultiPhase::create_snapshot().unwrap();
|
||||
let mut solution = raw_solution();
|
||||
solution.round = MultiPhase::round() + 1;
|
||||
|
||||
assert_noop!(
|
||||
MultiPhase::submit(RuntimeOrigin::signed(10), Box::new(solution)),
|
||||
Error::<Runtime>::PreDispatchDifferentRound,
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_submit_too_early() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
|
||||
Reference in New Issue
Block a user