EPM and staking events improvement (#13035)

* EPM and staking events improvement

* Uses RawOrigin in ElectionCompute event

* Refactors new phase events to PhaseTransition event

* PhaseTransitioned and remove RawOrigin from event

* Adds helpers for epm phase transition and staking force new

* addresses review comments

* nit: removes unecessary clone

* fixes benchmarks

Co-authored-by: parity-processbot <>
This commit is contained in:
Gonçalo Pestana
2023-01-09 16:06:47 +00:00
committed by GitHub
parent b929e0282d
commit fcdd8a88ad
7 changed files with 369 additions and 124 deletions
@@ -1055,7 +1055,7 @@ mod tests {
Runtime, RuntimeCall, RuntimeOrigin, System, TestNposSolution, TrimHelpers,
UnsignedPhase,
},
CurrentPhase, Event, InvalidTransaction, Phase, QueuedSolution, TransactionSource,
Event, InvalidTransaction, Phase, QueuedSolution, TransactionSource,
TransactionValidityError,
};
use codec::Decode;
@@ -1128,7 +1128,7 @@ mod tests {
assert!(<MultiPhase as ValidateUnsigned>::pre_dispatch(&call).is_ok());
// unsigned -- but not enabled.
<CurrentPhase<Runtime>>::put(Phase::Unsigned((false, 25)));
MultiPhase::phase_transition(Phase::Unsigned((false, 25)));
assert!(MultiPhase::current_phase().is_unsigned());
assert!(matches!(
<MultiPhase as ValidateUnsigned>::validate_unsigned(
@@ -1321,10 +1321,15 @@ mod tests {
assert_eq!(
multi_phase_events(),
vec![
Event::SignedPhaseStarted { round: 1 },
Event::UnsignedPhaseStarted { round: 1 },
Event::PhaseTransitioned { from: Phase::Off, to: Phase::Signed, round: 1 },
Event::PhaseTransitioned {
from: Phase::Signed,
to: Phase::Unsigned((true, 25)),
round: 1
},
Event::SolutionStored {
compute: ElectionCompute::Unsigned,
origin: None,
prev_ejected: false
}
]
@@ -1661,7 +1666,7 @@ mod tests {
let current_block = block_plus(offchain_repeat * 2 + 2);
// force the unsigned phase to start on the current block.
CurrentPhase::<Runtime>::set(Phase::Unsigned((true, current_block)));
MultiPhase::phase_transition(Phase::Unsigned((true, current_block)));
// clear the cache and create a solution since we are on the first block of the unsigned
// phase.
@@ -1673,8 +1678,12 @@ mod tests {
assert_eq!(
multi_phase_events(),
vec![
Event::SignedPhaseStarted { round: 1 },
Event::UnsignedPhaseStarted { round: 1 },
Event::PhaseTransitioned { from: Phase::Off, to: Phase::Signed, round: 1 },
Event::PhaseTransitioned {
from: Phase::Signed,
to: Phase::Unsigned((true, 25)),
round: 1
},
Event::ElectionFinalized {
compute: ElectionCompute::Fallback,
score: ElectionScore {
@@ -1682,7 +1691,12 @@ mod tests {
sum_stake: 0,
sum_stake_squared: 0
}
}
},
Event::PhaseTransitioned {
from: Phase::Unsigned((true, 25)),
to: Phase::Unsigned((true, 37)),
round: 1
},
]
);
})