Operation pool: refactor verify_deposit/exit

This commit is contained in:
Michael Sproul
2019-03-20 15:57:41 +11:00
parent 03c01c8a8d
commit b2fe14e12c
5 changed files with 118 additions and 61 deletions

View File

@@ -7,17 +7,30 @@ use types::*;
///
/// Returns `Ok(())` if the `Exit` is valid, otherwise indicates the reason for invalidity.
///
/// The `check_future_epoch` argument determines whether the exit's epoch should be checked
/// against the state's current epoch to ensure it doesn't occur in the future.
/// It should ordinarily be set to true, except for operations stored for
/// some time (such as in the OperationPool).
///
/// Spec v0.5.0
pub fn verify_exit(
state: &BeaconState,
exit: &VoluntaryExit,
spec: &ChainSpec,
check_future_epoch: bool,
) -> Result<(), Error> {
verify_exit_parametric(state, exit, spec, false)
}
/// Like `verify_exit` but doesn't run checks which may become true in future states.
pub fn verify_exit_time_independent_only(
state: &BeaconState,
exit: &VoluntaryExit,
spec: &ChainSpec,
) -> Result<(), Error> {
verify_exit_parametric(state, exit, spec, true)
}
/// Parametric version of `verify_exit` that skips some checks if `time_independent_only` is true.
fn verify_exit_parametric(
state: &BeaconState,
exit: &VoluntaryExit,
spec: &ChainSpec,
time_independent_only: bool,
) -> Result<(), Error> {
let validator = state
.validator_registry
@@ -38,7 +51,7 @@ pub fn verify_exit(
// Exits must specify an epoch when they become valid; they are not valid before then.
verify!(
!check_future_epoch || state.current_epoch(spec) >= exit.epoch,
time_independent_only || state.current_epoch(spec) >= exit.epoch,
Invalid::FutureEpoch {
state: state.current_epoch(spec),
exit: exit.epoch