From 857c4ed2db4d8485117ede7b37e308d21d281d1e Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Mon, 20 May 2019 15:08:20 +1000 Subject: [PATCH] spec v0.6.1: process proposer/attester slashings --- eth2/state_processing/src/lib.rs | 8 +++----- eth2/state_processing/src/per_block_processing.rs | 15 +++++++-------- eth2/types/src/beacon_state.rs | 4 ++-- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/eth2/state_processing/src/lib.rs b/eth2/state_processing/src/lib.rs index 547df0147..e040c1525 100644 --- a/eth2/state_processing/src/lib.rs +++ b/eth2/state_processing/src/lib.rs @@ -2,17 +2,15 @@ mod macros; pub mod common; -//pub mod get_genesis_state; +pub mod get_genesis_state; pub mod per_block_processing; pub mod per_epoch_processing; -//pub mod per_slot_processing; +pub mod per_slot_processing; -/* -pub use get_genesis_state::get_genesis_state; +pub use get_genesis_state::get_genesis_beacon_state; pub use per_block_processing::{ errors::{BlockInvalid, BlockProcessingError}, per_block_processing, per_block_processing_without_verifying_block_signature, }; pub use per_epoch_processing::{errors::EpochProcessingError, per_epoch_processing}; pub use per_slot_processing::{per_slot_processing, Error as SlotProcessingError}; -*/ diff --git a/eth2/state_processing/src/per_block_processing.rs b/eth2/state_processing/src/per_block_processing.rs index 7b3c51295..6a4cc5643 100644 --- a/eth2/state_processing/src/per_block_processing.rs +++ b/eth2/state_processing/src/per_block_processing.rs @@ -5,8 +5,7 @@ use tree_hash::{SignedRoot, TreeHash}; use types::*; pub use self::verify_attester_slashing::{ - gather_attester_slashing_indices, gather_attester_slashing_indices_modular, - verify_attester_slashing, + gather_attester_slashing_indices, get_slashable_indices, verify_attester_slashing, }; pub use self::verify_proposer_slashing::verify_proposer_slashing; pub use validate_attestation::{ @@ -214,7 +213,7 @@ pub fn process_eth1_data( /// Returns `Ok(())` if the validation and state updates completed successfully, otherwise returns /// an `Err` describing the invalid object or cause of failure. /// -/// Spec v0.5.1 +/// Spec v0.6.1 pub fn process_proposer_slashings( state: &mut BeaconState, proposer_slashings: &[ProposerSlashing], @@ -236,18 +235,18 @@ pub fn process_proposer_slashings( // Update the state. for proposer_slashing in proposer_slashings { - slash_validator(state, proposer_slashing.proposer_index as usize, spec)?; + slash_validator(state, proposer_slashing.proposer_index as usize, None, spec)?; } Ok(()) } -/// Validates each `AttesterSlsashing` and updates the state, short-circuiting on an invalid object. +/// Validates each `AttesterSlashing` and updates the state, short-circuiting on an invalid object. /// /// Returns `Ok(())` if the validation and state updates completed successfully, otherwise returns /// an `Err` describing the invalid object or cause of failure. /// -/// Spec v0.5.1 +/// Spec v0.6.1 pub fn process_attester_slashings( state: &mut BeaconState, attester_slashings: &[AttesterSlashing], @@ -289,11 +288,11 @@ pub fn process_attester_slashings( ) .map_err(|e| e.into_with_index(i))?; - let indexed_indices = gather_attester_slashing_indices(&state, &attester_slashing, spec) + let slashable_indices = get_slashable_indices(&state, &attester_slashing, spec) .map_err(|e| e.into_with_index(i))?; for i in indexed_indices { - slash_validator(state, i as usize, spec)?; + slash_validator(state, i as usize, None, spec)?; } } diff --git a/eth2/types/src/beacon_state.rs b/eth2/types/src/beacon_state.rs index 9d9e713e8..441210d84 100644 --- a/eth2/types/src/beacon_state.rs +++ b/eth2/types/src/beacon_state.rs @@ -546,10 +546,10 @@ impl BeaconState { /// Replace `active_index_roots` with clones of `index_root`. /// - /// Spec v0.5.1 + /// Spec v0.6.1 pub fn fill_active_index_roots_with(&mut self, index_root: Hash256) { self.latest_active_index_roots = - vec![index_root; self.latest_active_index_roots.len() as usize].into() + vec![index_root; self.latest_active_index_roots.len()].into() } /// Safely obtains the index for latest state roots, given some `slot`.