diff --git a/beacon_node/beacon_chain/src/attestation_aggregator.rs b/beacon_node/beacon_chain/src/attestation_aggregator.rs index 54f178068..75cfd7ee5 100644 --- a/beacon_node/beacon_chain/src/attestation_aggregator.rs +++ b/beacon_node/beacon_chain/src/attestation_aggregator.rs @@ -1,10 +1,8 @@ use log::trace; -use state_processing::validate_attestation_without_signature; +use ssz::TreeHash; +use state_processing::per_block_processing::validate_attestation_without_signature; use std::collections::{HashMap, HashSet}; -use types::{ - AggregateSignature, Attestation, AttestationData, BeaconState, BeaconStateError, Bitfield, - ChainSpec, FreeAttestation, Signature, -}; +use types::*; const PHASE_0_CUSTODY_BIT: bool = false; @@ -84,11 +82,11 @@ impl AttestationAggregator { /// - The signature is verified against that of the validator at `validator_index`. pub fn process_free_attestation( &mut self, - cached_state: &BeaconState, + state: &BeaconState, free_attestation: &FreeAttestation, spec: &ChainSpec, ) -> Result { - let attestation_duties = match cached_state.attestation_slot_and_shard_for_validator( + let attestation_duties = match state.attestation_slot_and_shard_for_validator( free_attestation.validator_index as usize, spec, ) { @@ -119,9 +117,13 @@ impl AttestationAggregator { invalid_outcome!(Message::BadShard); } - let signable_message = free_attestation.data.signable_message(PHASE_0_CUSTODY_BIT); + let signable_message = AttestationDataAndCustodyBit { + data: free_attestation.data.clone(), + custody_bit: PHASE_0_CUSTODY_BIT, + } + .hash_tree_root(); - let validator_record = match cached_state + let validator_record = match state .validator_registry .get(free_attestation.validator_index as usize) { @@ -131,9 +133,7 @@ impl AttestationAggregator { if !free_attestation.signature.verify( &signable_message, - cached_state - .fork - .get_domain(cached_state.current_epoch(spec), spec.domain_attestation), + spec.get_domain(state.current_epoch(spec), Domain::Attestation, &state.fork), &validator_record.pubkey, ) { invalid_outcome!(Message::BadSignature); diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index ddb9514db..93a806864 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -10,7 +10,8 @@ use parking_lot::{RwLock, RwLockReadGuard}; use slot_clock::SlotClock; use ssz::ssz_encode; use state_processing::{ - BlockProcessable, BlockProcessingError, SlotProcessable, SlotProcessingError, + per_block_processing, per_block_processing_without_verifying_block_signature, + per_slot_processing, BlockProcessingError, SlotProcessingError, }; use std::sync::Arc; use types::{ @@ -65,7 +66,7 @@ pub struct BeaconChain { pub slot_clock: U, pub attestation_aggregator: RwLock, pub deposits_for_inclusion: RwLock>, - pub exits_for_inclusion: RwLock>, + pub exits_for_inclusion: RwLock>, pub proposer_slashings_for_inclusion: RwLock>, pub attester_slashings_for_inclusion: RwLock>, canonical_head: RwLock, @@ -214,9 +215,7 @@ where let state_slot = self.state.read().slot; let head_block_root = self.head().beacon_block_root; for _ in state_slot.as_u64()..slot.as_u64() { - self.state - .write() - .per_slot_processing(head_block_root, &self.spec)?; + per_slot_processing(&mut *self.state.write(), head_block_root, &self.spec)?; } Ok(()) } @@ -333,10 +332,10 @@ where shard, beacon_block_root: self.head().beacon_block_root, epoch_boundary_root, - shard_block_root: Hash256::zero(), + crosslink_data_root: Hash256::zero(), latest_crosslink: Crosslink { epoch: self.state.read().slot.epoch(self.spec.slots_per_epoch), - shard_block_root: Hash256::zero(), + crosslink_data_root: Hash256::zero(), }, justified_epoch, justified_block_root, @@ -411,7 +410,7 @@ where } /// Accept some exit and queue it for inclusion in an appropriate block. - pub fn receive_exit_for_inclusion(&self, exit: Exit) { + pub fn receive_exit_for_inclusion(&self, exit: VoluntaryExit) { // TODO: exits are not checked for validity; check them. // // https://github.com/sigp/lighthouse/issues/276 @@ -419,7 +418,7 @@ where } /// Return a vec of exits suitable for inclusion in some block. - pub fn get_exits_for_block(&self) -> Vec { + pub fn get_exits_for_block(&self) -> Vec { // TODO: exits are indiscriminately included; check them for validity. // // https://github.com/sigp/lighthouse/issues/275 @@ -430,7 +429,7 @@ where /// inclusion queue. /// /// This ensures that `Deposits` are not included twice in successive blocks. - pub fn set_exits_as_included(&self, included_exits: &[Exit]) { + pub fn set_exits_as_included(&self, included_exits: &[VoluntaryExit]) { // TODO: method does not take forks into account; consider this. let mut indices_to_delete = vec![]; @@ -647,7 +646,7 @@ where // Transition the parent state to the present slot. let mut state = parent_state; for _ in state.slot.as_u64()..present_slot.as_u64() { - if let Err(e) = state.per_slot_processing(parent_block_root, &self.spec) { + if let Err(e) = per_slot_processing(&mut state, parent_block_root, &self.spec) { return Ok(BlockProcessingOutcome::InvalidBlock( InvalidBlock::SlotProcessingError(e), )); @@ -656,7 +655,7 @@ where // Apply the received block to its parent state (which has been transitioned into this // slot). - if let Err(e) = state.per_block_processing(&block, &self.spec) { + if let Err(e) = per_block_processing(&mut state, &block, &self.spec) { return Ok(BlockProcessingOutcome::InvalidBlock( InvalidBlock::PerBlockProcessingError(e), )); @@ -736,14 +735,15 @@ where attester_slashings: self.get_attester_slashings_for_block(), attestations, deposits: self.get_deposits_for_block(), - exits: self.get_exits_for_block(), + voluntary_exits: self.get_exits_for_block(), + transfers: vec![], }, }; trace!("BeaconChain::produce_block: updating state for new block.",); let result = - state.per_block_processing_without_verifying_block_signature(&block, &self.spec); + per_block_processing_without_verifying_block_signature(&mut state, &block, &self.spec); debug!( "BeaconNode::produce_block: state processing result: {:?}", result