Add attester slashing support to block processing

At spec v0.2.0
This commit is contained in:
Paul Hauner
2019-03-03 11:18:12 +11:00
parent 59128f842a
commit 76a0ba2d6c
2 changed files with 80 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
use self::verify_slashable_attestation::verify_slashable_attestation;
use crate::SlotProcessingError;
use hashing::hash;
use int_to_bytes::int_to_bytes32;
@@ -5,6 +6,8 @@ use log::{debug, trace};
use ssz::{ssz_encode, TreeHash};
use types::*;
mod verify_slashable_attestation;
const PHASE_0_CUSTODY_BIT: bool = false;
#[derive(Debug, PartialEq)]
@@ -23,7 +26,9 @@ pub enum Error {
BadRandaoSignature,
MaxProposerSlashingsExceeded,
BadProposerSlashing,
MaxAttesterSlashingsExceed,
MaxAttestationsExceeded,
BadAttesterSlashing,
InvalidAttestation(AttestationValidationError),
NoBlockRoot,
MaxDepositsExceeded,
@@ -82,7 +87,7 @@ impl BlockProcessable for BeaconState {
}
fn per_block_processing_signature_optional(
state: &mut BeaconState,
mut state: &mut BeaconState,
block: &BeaconBlock,
verify_block_signature: bool,
spec: &ChainSpec,
@@ -205,6 +210,17 @@ fn per_block_processing_signature_optional(
state.penalize_validator(proposer_slashing.proposer_index as usize, spec)?;
}
/*
* Attester slashings
*/
ensure!(
block.body.attester_slashings.len() as u64 <= spec.max_attester_slashings,
Error::MaxAttesterSlashingsExceed
);
for attester_slashing in &block.body.attester_slashings {
verify_slashable_attestation(&mut state, &attester_slashing, spec)?;
}
/*
* Attestations
*/