mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 12:11:59 +00:00
* Add basic block processing benches * Start reviving state processing benches * Fix old block builders * Add optimization for faster pubkey add * Tidy benches, add another * Add extra block processing bench * Start working on faster BLS scheme * Add partially complete sig verify optimization * Add .gitignore to state processing * Add progress on faster signature verification * Fix SignatureSet for fake_crypto * Tidy attester slashings sig set * Tidy bulk signature verifier * Refactor signature sets to be cleaner * Start threading SignatureStrategy through code * Add (empty) test dir * Move BenchingBlockBuilder * Add initial block signature verification tests * Add tests for bulk signature verification * Start threading SignatureStrategy in block proc. * Refactor per_block_processing errors * Use sig set tuples instead of lists of two * Remove dead code * Thread VerifySignatures through per_block_processing * Add bulk signature verification * Introduce parallel bulk signature verification * Expand state processing benches * Fix additional compile errors * Fix issue where par iter chunks is 0 * Update milagro_bls dep * Remove debugs, code fragment in beacon chain * Tidy, add comments to block sig verifier * Fix various PR comments * Add block_root option to per_block_processing * Fix comment in block signature verifier * Fix comments from PR review * Remove old comment * Fix comment
92 lines
2.8 KiB
Rust
92 lines
2.8 KiB
Rust
use super::errors::{BlockOperationError, ExitInvalid};
|
|
use crate::per_block_processing::{signature_sets::exit_signature_set, VerifySignatures};
|
|
use types::*;
|
|
|
|
type Result<T> = std::result::Result<T, BlockOperationError<ExitInvalid>>;
|
|
|
|
fn error(reason: ExitInvalid) -> BlockOperationError<ExitInvalid> {
|
|
BlockOperationError::invalid(reason)
|
|
}
|
|
|
|
/// Indicates if an `Exit` is valid to be included in a block in the current epoch of the given
|
|
/// state.
|
|
///
|
|
/// Returns `Ok(())` if the `Exit` is valid, otherwise indicates the reason for invalidity.
|
|
///
|
|
/// Spec v0.8.0
|
|
pub fn verify_exit<T: EthSpec>(
|
|
state: &BeaconState<T>,
|
|
exit: &VoluntaryExit,
|
|
verify_signatures: VerifySignatures,
|
|
spec: &ChainSpec,
|
|
) -> Result<()> {
|
|
verify_exit_parametric(state, exit, verify_signatures, spec, false)
|
|
}
|
|
|
|
/// Like `verify_exit` but doesn't run checks which may become true in future states.
|
|
///
|
|
/// Spec v0.8.0
|
|
pub fn verify_exit_time_independent_only<T: EthSpec>(
|
|
state: &BeaconState<T>,
|
|
exit: &VoluntaryExit,
|
|
verify_signatures: VerifySignatures,
|
|
spec: &ChainSpec,
|
|
) -> Result<()> {
|
|
verify_exit_parametric(state, exit, verify_signatures, spec, true)
|
|
}
|
|
|
|
/// Parametric version of `verify_exit` that skips some checks if `time_independent_only` is true.
|
|
///
|
|
/// Spec v0.8.0
|
|
fn verify_exit_parametric<T: EthSpec>(
|
|
state: &BeaconState<T>,
|
|
exit: &VoluntaryExit,
|
|
verify_signatures: VerifySignatures,
|
|
spec: &ChainSpec,
|
|
time_independent_only: bool,
|
|
) -> Result<()> {
|
|
let validator = state
|
|
.validators
|
|
.get(exit.validator_index as usize)
|
|
.ok_or_else(|| error(ExitInvalid::ValidatorUnknown(exit.validator_index)))?;
|
|
|
|
// Verify the validator is active.
|
|
verify!(
|
|
validator.is_active_at(state.current_epoch()),
|
|
ExitInvalid::NotActive(exit.validator_index)
|
|
);
|
|
|
|
// Verify that the validator has not yet exited.
|
|
verify!(
|
|
validator.exit_epoch == spec.far_future_epoch,
|
|
ExitInvalid::AlreadyExited(exit.validator_index)
|
|
);
|
|
|
|
// Exits must specify an epoch when they become valid; they are not valid before then.
|
|
verify!(
|
|
time_independent_only || state.current_epoch() >= exit.epoch,
|
|
ExitInvalid::FutureEpoch {
|
|
state: state.current_epoch(),
|
|
exit: exit.epoch
|
|
}
|
|
);
|
|
|
|
// Verify the validator has been active long enough.
|
|
verify!(
|
|
state.current_epoch() >= validator.activation_epoch + spec.persistent_committee_period,
|
|
ExitInvalid::TooYoungToExit {
|
|
current_epoch: state.current_epoch(),
|
|
earliest_exit_epoch: validator.activation_epoch + spec.persistent_committee_period,
|
|
}
|
|
);
|
|
|
|
if verify_signatures.is_true() {
|
|
verify!(
|
|
exit_signature_set(state, exit, spec)?.is_valid(),
|
|
ExitInvalid::BadSignature
|
|
);
|
|
}
|
|
|
|
Ok(())
|
|
}
|