per-block processing: minor fixups

This commit is contained in:
Michael Sproul 2019-05-21 16:40:48 +10:00
parent 0b2aa26f2d
commit 468dc2ceb0
No known key found for this signature in database
GPG Key ID: 77B1309D2E54E914
3 changed files with 11 additions and 8 deletions

View File

@ -35,7 +35,7 @@ pub fn get_genesis_beacon_state<T: EthSpec>(
// Set all the active index roots to be the genesis active index root. // Set all the active index roots to be the genesis active index root.
let active_validator_indices = state let active_validator_indices = state
.get_cached_active_validator_indices(RelativeEpoch::Current, spec)? .get_cached_active_validator_indices(RelativeEpoch::Current)?
.to_vec(); .to_vec();
let genesis_active_index_root = Hash256::from_slice(&active_validator_indices.tree_hash_root()); let genesis_active_index_root = Hash256::from_slice(&active_validator_indices.tree_hash_root());
state.fill_active_index_roots_with(genesis_active_index_root); state.fill_active_index_roots_with(genesis_active_index_root);

View File

@ -4,9 +4,7 @@ use rayon::prelude::*;
use tree_hash::{SignedRoot, TreeHash}; use tree_hash::{SignedRoot, TreeHash};
use types::*; use types::*;
pub use self::verify_attester_slashing::{ pub use self::verify_attester_slashing::{get_slashable_indices, verify_attester_slashing};
gather_attester_slashing_indices, get_slashable_indices, verify_attester_slashing,
};
pub use self::verify_proposer_slashing::verify_proposer_slashing; pub use self::verify_proposer_slashing::verify_proposer_slashing;
pub use validate_attestation::{ pub use validate_attestation::{
validate_attestation, validate_attestation_time_independent_only, validate_attestation, validate_attestation_time_independent_only,
@ -91,9 +89,11 @@ fn per_block_processing_signature_optional<T: EthSpec>(
process_proposer_slashings(&mut state, &block.body.proposer_slashings, spec)?; process_proposer_slashings(&mut state, &block.body.proposer_slashings, spec)?;
process_attester_slashings(&mut state, &block.body.attester_slashings, spec)?; process_attester_slashings(&mut state, &block.body.attester_slashings, spec)?;
process_attestations(&mut state, &block.body.attestations, spec)?; process_attestations(&mut state, &block.body.attestations, spec)?;
/*
process_deposits(&mut state, &block.body.deposits, spec)?; process_deposits(&mut state, &block.body.deposits, spec)?;
process_exits(&mut state, &block.body.voluntary_exits, spec)?; process_exits(&mut state, &block.body.voluntary_exits, spec)?;
process_transfers(&mut state, &block.body.transfers, spec)?; process_transfers(&mut state, &block.body.transfers, spec)?;
*/
Ok(()) Ok(())
} }
@ -293,7 +293,7 @@ pub fn process_attester_slashings<T: EthSpec>(
let slashable_indices = get_slashable_indices(&state, &attester_slashing, spec) let slashable_indices = get_slashable_indices(&state, &attester_slashing, spec)
.map_err(|e| e.into_with_index(i))?; .map_err(|e| e.into_with_index(i))?;
for i in indexed_indices { for i in slashable_indices {
slash_validator(state, i as usize, None, spec)?; slash_validator(state, i as usize, None, spec)?;
} }
} }
@ -350,6 +350,7 @@ pub fn process_attestations<T: EthSpec>(
Ok(()) Ok(())
} }
/*
/// Validates each `Deposit` and updates the state, short-circuiting on an invalid object. /// Validates each `Deposit` and updates the state, short-circuiting on an invalid object.
/// ///
/// Returns `Ok(())` if the validation and state updates completed successfully, otherwise returns /// Returns `Ok(())` if the validation and state updates completed successfully, otherwise returns
@ -481,3 +482,4 @@ pub fn process_transfers<T: EthSpec>(
Ok(()) Ok(())
} }
*/

View File

@ -1,5 +1,6 @@
use super::errors::{AttesterSlashingInvalid as Invalid, AttesterSlashingValidationError as Error}; use super::errors::{AttesterSlashingInvalid as Invalid, AttesterSlashingValidationError as Error};
use super::verify_indexed_attestation::verify_indexed_attestation; use super::verify_indexed_attestation::verify_indexed_attestation;
use std::collections::HashSet;
use types::*; use types::*;
/// Indicates if an `AttesterSlashing` is valid to be included in a block in the current epoch of the given /// Indicates if an `AttesterSlashing` is valid to be included in a block in the current epoch of the given
@ -19,8 +20,8 @@ pub fn verify_attester_slashing<T: EthSpec>(
// Spec: is_slashable_attestation_data // Spec: is_slashable_attestation_data
verify!( verify!(
attestation_1.is_double_vote(attestation_2, spec) attestation_1.is_double_vote(attestation_2)
|| attestation_1.is_surround_vote(attestation_2, spec), || attestation_1.is_surround_vote(attestation_2),
Invalid::NotSlashable Invalid::NotSlashable
); );
@ -44,7 +45,7 @@ pub fn get_slashable_indices<T: EthSpec>(
attester_slashing: &AttesterSlashing, attester_slashing: &AttesterSlashing,
spec: &ChainSpec, spec: &ChainSpec,
) -> Result<Vec<u64>, Error> { ) -> Result<Vec<u64>, Error> {
gather_attester_slashing_indices_modular( get_slashable_indices_modular(
state, state,
attester_slashing, attester_slashing,
|_, validator| validator.is_slashable_at(state.current_epoch()), |_, validator| validator.is_slashable_at(state.current_epoch()),