mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 19:51:47 +00:00
Process exits and slashings off the network (#1253)
* Process exits and slashings off the network * Fix rest_api tests * Add op verification tests * Add tests for pruning of slashings in the op pool * Address Paul's review comments
This commit is contained in:
@@ -9,6 +9,7 @@ pub mod per_block_processing;
|
||||
pub mod per_epoch_processing;
|
||||
pub mod per_slot_processing;
|
||||
pub mod test_utils;
|
||||
pub mod verify_operation;
|
||||
|
||||
pub use genesis::{
|
||||
eth2_genesis_time, initialize_beacon_state_from_eth1, is_valid_genesis_state,
|
||||
@@ -20,3 +21,4 @@ pub use per_block_processing::{
|
||||
};
|
||||
pub use per_epoch_processing::{errors::EpochProcessingError, per_epoch_processing};
|
||||
pub use per_slot_processing::{per_slot_processing, Error as SlotProcessingError};
|
||||
pub use verify_operation::{SigVerifiedOp, VerifyOperation};
|
||||
|
||||
73
consensus/state_processing/src/verify_operation.rs
Normal file
73
consensus/state_processing/src/verify_operation.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
use crate::per_block_processing::{
|
||||
errors::{
|
||||
AttesterSlashingValidationError, ExitValidationError, ProposerSlashingValidationError,
|
||||
},
|
||||
verify_attester_slashing, verify_exit, verify_proposer_slashing,
|
||||
};
|
||||
use crate::VerifySignatures;
|
||||
use types::{
|
||||
AttesterSlashing, BeaconState, ChainSpec, EthSpec, ProposerSlashing, SignedVoluntaryExit,
|
||||
};
|
||||
|
||||
/// Wrapper around an operation type that acts as proof that its signature has been checked.
|
||||
///
|
||||
/// The inner field is private, meaning instances of this type can only be constructed
|
||||
/// by calling `validate`.
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub struct SigVerifiedOp<T>(T);
|
||||
|
||||
impl<T> SigVerifiedOp<T> {
|
||||
pub fn into_inner(self) -> T {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait for operations that can be verified and transformed into a `SigVerifiedOp`.
|
||||
pub trait VerifyOperation<E: EthSpec>: Sized {
|
||||
type Error;
|
||||
|
||||
fn validate(
|
||||
self,
|
||||
state: &BeaconState<E>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<SigVerifiedOp<Self>, Self::Error>;
|
||||
}
|
||||
|
||||
impl<E: EthSpec> VerifyOperation<E> for SignedVoluntaryExit {
|
||||
type Error = ExitValidationError;
|
||||
|
||||
fn validate(
|
||||
self,
|
||||
state: &BeaconState<E>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<SigVerifiedOp<Self>, Self::Error> {
|
||||
verify_exit(state, &self, VerifySignatures::True, spec)?;
|
||||
Ok(SigVerifiedOp(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> VerifyOperation<E> for AttesterSlashing<E> {
|
||||
type Error = AttesterSlashingValidationError;
|
||||
|
||||
fn validate(
|
||||
self,
|
||||
state: &BeaconState<E>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<SigVerifiedOp<Self>, Self::Error> {
|
||||
verify_attester_slashing(state, &self, VerifySignatures::True, spec)?;
|
||||
Ok(SigVerifiedOp(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> VerifyOperation<E> for ProposerSlashing {
|
||||
type Error = ProposerSlashingValidationError;
|
||||
|
||||
fn validate(
|
||||
self,
|
||||
state: &BeaconState<E>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<SigVerifiedOp<Self>, Self::Error> {
|
||||
verify_proposer_slashing(&self, state, VerifySignatures::True, spec)?;
|
||||
Ok(SigVerifiedOp(self))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user