diff --git a/eth2/state_processing/src/common/exit.rs b/eth2/state_processing/src/common/exit.rs index 9d6a8f488c..996dcdb2a4 100644 --- a/eth2/state_processing/src/common/exit.rs +++ b/eth2/state_processing/src/common/exit.rs @@ -19,7 +19,7 @@ pub fn initiate_validator_exit( } // Compute exit queue epoch - let delayed_epoch = state.get_delayed_activation_exit_epoch(state.current_epoch(spec), spec); + let delayed_epoch = state.get_delayed_activation_exit_epoch(state.current_epoch(), spec); let mut exit_queue_epoch = state .exit_cache .max_epoch() diff --git a/eth2/state_processing/src/common/exit_validator.rs b/eth2/state_processing/src/common/exit_validator.rs index 529f5e1616..7a817b1261 100644 --- a/eth2/state_processing/src/common/exit_validator.rs +++ b/eth2/state_processing/src/common/exit_validator.rs @@ -12,7 +12,7 @@ pub fn exit_validator( return Err(Error::UnknownValidator); } - let delayed_epoch = state.get_delayed_activation_exit_epoch(state.current_epoch(spec), spec); + let delayed_epoch = state.get_delayed_activation_exit_epoch(state.current_epoch(), spec); if state.validator_registry[validator_index].exit_epoch > delayed_epoch { state.validator_registry[validator_index].exit_epoch = delayed_epoch; diff --git a/eth2/state_processing/src/common/slash_validator.rs b/eth2/state_processing/src/common/slash_validator.rs index c293ad3e8d..3fce3756eb 100644 --- a/eth2/state_processing/src/common/slash_validator.rs +++ b/eth2/state_processing/src/common/slash_validator.rs @@ -14,7 +14,7 @@ pub fn slash_validator( return Err(BeaconStateError::UnknownValidator); } - let current_epoch = state.current_epoch(spec); + let current_epoch = state.current_epoch(); initiate_validator_exit(state, slashed_index, spec)?; diff --git a/eth2/state_processing/src/per_block_processing.rs b/eth2/state_processing/src/per_block_processing.rs index 29166c8f73..9f40bffd7a 100644 --- a/eth2/state_processing/src/per_block_processing.rs +++ b/eth2/state_processing/src/per_block_processing.rs @@ -164,7 +164,7 @@ pub fn process_randao( // Verify the RANDAO is a valid signature of the proposer. verify!( block.body.randao_reveal.verify( - &state.current_epoch(spec).tree_hash_root()[..], + &state.current_epoch().tree_hash_root()[..], spec.get_domain( block.slot.epoch(spec.slots_per_epoch), Domain::Randao, @@ -176,7 +176,7 @@ pub fn process_randao( ); // Update the current epoch RANDAO mix. - state.update_randao_mix(state.current_epoch(spec), &block.body.randao_reveal, spec)?; + state.update_randao_mix(state.current_epoch(), &block.body.randao_reveal, spec)?; Ok(()) } @@ -330,7 +330,7 @@ pub fn process_attestations( let pending_attestation = PendingAttestation::from_attestation(attestation, state.slot); let attestation_epoch = attestation.data.slot.epoch(spec.slots_per_epoch); - if attestation_epoch == state.current_epoch(spec) { + if attestation_epoch == state.current_epoch() { state.current_epoch_attestations.push(pending_attestation) } else if attestation_epoch == state.previous_epoch(spec) { state.previous_epoch_attestations.push(pending_attestation) diff --git a/eth2/state_processing/src/per_block_processing/verify_exit.rs b/eth2/state_processing/src/per_block_processing/verify_exit.rs index 333638a8d1..865942ef41 100644 --- a/eth2/state_processing/src/per_block_processing/verify_exit.rs +++ b/eth2/state_processing/src/per_block_processing/verify_exit.rs @@ -51,9 +51,9 @@ fn verify_exit_parametric( // Exits must specify an epoch when they become valid; they are not valid before then. verify!( - time_independent_only || state.current_epoch(spec) >= exit.epoch, + time_independent_only || state.current_epoch() >= exit.epoch, Invalid::FutureEpoch { - state: state.current_epoch(spec), + state: state.current_epoch(), exit: exit.epoch } ); diff --git a/eth2/state_processing/src/per_epoch_processing.rs b/eth2/state_processing/src/per_epoch_processing.rs index b8f459efd7..7a4d0a4128 100644 --- a/eth2/state_processing/src/per_epoch_processing.rs +++ b/eth2/state_processing/src/per_epoch_processing.rs @@ -88,12 +88,12 @@ pub fn process_justification_and_finalization( total_balances: &TotalBalances, spec: &ChainSpec, ) -> Result<(), Error> { - if state.current_epoch(spec) == spec.genesis_epoch { + if state.current_epoch() == spec.genesis_epoch { return Ok(()); } - let previous_epoch = state.previous_epoch(spec); - let current_epoch = state.current_epoch(spec); + let previous_epoch = state.previous_epoch(); + let current_epoch = state.current_epoch(); let old_previous_justified_epoch = state.previous_justified_epoch; let old_current_justified_epoch = state.current_justified_epoch; @@ -159,7 +159,7 @@ pub fn process_crosslinks( state.previous_crosslinks = state.current_crosslinks.clone(); - for epoch in vec![state.previous_epoch(spec), state.current_epoch(spec)] { + for epoch in vec![state.previous_epoch(), state.current_epoch()] { for offset in 0..state.get_epoch_committee_count(epoch, spec) { let shard = (state.get_epoch_start_shard(epoch, spec) + offset) % spec.shard_count; let crosslink_committee = state.get_crosslink_committee(epoch, shard, spec)?; @@ -188,8 +188,8 @@ pub fn process_final_updates( state: &mut BeaconState, spec: &ChainSpec, ) -> Result<(), Error> { - let current_epoch = state.current_epoch(spec); - let next_epoch = state.next_epoch(spec); + let current_epoch = state.current_epoch(); + let next_epoch = state.next_epoch(); // Reset eth1 data votes. if (state.slot + 1) % spec.slots_per_eth1_voting_period == 0 { @@ -233,11 +233,7 @@ pub fn process_final_updates( state.set_slashed_balance(next_epoch, state.get_slashed_balance(current_epoch)?)?; // Set randao mix - state.set_randao_mix( - next_epoch, - *state.get_randao_mix(current_epoch, spec)?, - spec, - )?; + state.set_randao_mix(next_epoch, *state.get_randao_mix(current_epoch)?)?; state.slot -= 1; } diff --git a/eth2/state_processing/src/per_epoch_processing/apply_rewards.rs b/eth2/state_processing/src/per_epoch_processing/apply_rewards.rs index 5452dd2513..7f98f3ae5b 100644 --- a/eth2/state_processing/src/per_epoch_processing/apply_rewards.rs +++ b/eth2/state_processing/src/per_epoch_processing/apply_rewards.rs @@ -39,7 +39,7 @@ pub fn process_rewards_and_penalties( winning_root_for_shards: &WinningRootHashSet, spec: &ChainSpec, ) -> Result<(), Error> { - if state.current_epoch(spec) == spec.genesis_epoch { + if state.current_epoch() == spec.genesis_epoch { return Ok(()); } @@ -118,7 +118,7 @@ fn get_attestation_deltas( validator_statuses: &ValidatorStatuses, spec: &ChainSpec, ) -> Result<(), Error> { - let finality_delay = (state.previous_epoch(spec) - state.finalized_epoch).as_u64(); + let finality_delay = (state.previous_epoch() - state.finalized_epoch).as_u64(); for (index, validator) in validator_statuses.statuses.iter().enumerate() { let base_reward = get_base_reward( diff --git a/eth2/state_processing/src/per_epoch_processing/process_slashings.rs b/eth2/state_processing/src/per_epoch_processing/process_slashings.rs index e9b8143767..020534f804 100644 --- a/eth2/state_processing/src/per_epoch_processing/process_slashings.rs +++ b/eth2/state_processing/src/per_epoch_processing/process_slashings.rs @@ -8,7 +8,7 @@ pub fn process_slashings( current_total_balance: u64, spec: &ChainSpec, ) -> Result<(), Error> { - let current_epoch = state.current_epoch(spec); + let current_epoch = state.current_epoch(); let total_at_start = state.get_slashed_balance(current_epoch + 1)?; let total_at_end = state.get_slashed_balance(current_epoch)?; diff --git a/eth2/state_processing/src/per_epoch_processing/registry_updates.rs b/eth2/state_processing/src/per_epoch_processing/registry_updates.rs index 6f867b3aff..469a14fddd 100644 --- a/eth2/state_processing/src/per_epoch_processing/registry_updates.rs +++ b/eth2/state_processing/src/per_epoch_processing/registry_updates.rs @@ -14,7 +14,7 @@ pub fn process_registry_updates( // Collect eligible and exiting validators (we need to avoid mutating the state while iterating). // We assume it's safe to re-order the change in eligibility and `initiate_validator_exit`. // Rest assured exiting validators will still be exited in the same order as in the spec. - let current_epoch = state.current_epoch(spec); + let current_epoch = state.current_epoch(); let is_eligible = |validator: &Validator| { validator.activation_eligibility_epoch == spec.far_future_epoch && validator.effective_balance >= spec.max_effective_balance diff --git a/eth2/state_processing/src/per_epoch_processing/update_registry_and_shuffling_data.rs b/eth2/state_processing/src/per_epoch_processing/update_registry_and_shuffling_data.rs index f6548fb67b..39f18b7c84 100644 --- a/eth2/state_processing/src/per_epoch_processing/update_registry_and_shuffling_data.rs +++ b/eth2/state_processing/src/per_epoch_processing/update_registry_and_shuffling_data.rs @@ -15,7 +15,7 @@ pub fn update_registry_and_shuffling_data( state.previous_shuffling_start_shard = state.previous_shuffling_start_shard; state.previous_shuffling_seed = state.previous_shuffling_seed; - let current_epoch = state.current_epoch(spec); + let current_epoch = state.current_epoch(); let next_epoch = current_epoch + 1; // Check we should update, and if so, update. @@ -84,7 +84,7 @@ pub fn update_validator_registry( current_total_balance: u64, spec: &ChainSpec, ) -> Result<(), Error> { - let current_epoch = state.current_epoch(spec); + let current_epoch = state.current_epoch(); let max_balance_churn = std::cmp::max( spec.max_deposit_amount, @@ -140,7 +140,7 @@ pub fn activate_validator( is_genesis: bool, spec: &ChainSpec, ) { - let current_epoch = state.current_epoch(spec); + let current_epoch = state.current_epoch(); state.validator_registry[validator_index].activation_epoch = if is_genesis { spec.genesis_epoch diff --git a/eth2/state_processing/src/per_epoch_processing/validator_statuses.rs b/eth2/state_processing/src/per_epoch_processing/validator_statuses.rs index ad8d068664..266b358448 100644 --- a/eth2/state_processing/src/per_epoch_processing/validator_statuses.rs +++ b/eth2/state_processing/src/per_epoch_processing/validator_statuses.rs @@ -175,17 +175,17 @@ impl ValidatorStatuses { let mut status = ValidatorStatus { is_slashed: validator.slashed, is_withdrawable_in_current_epoch: validator - .is_withdrawable_at(state.current_epoch(spec)), + .is_withdrawable_at(state.current_epoch()), current_epoch_effective_balance: effective_balance, ..ValidatorStatus::default() }; - if validator.is_active_at(state.current_epoch(spec)) { + if validator.is_active_at(state.current_epoch()) { status.is_active_in_current_epoch = true; total_balances.current_epoch += effective_balance; } - if validator.is_active_at(state.previous_epoch(spec)) { + if validator.is_active_at(state.previous_epoch()) { status.is_active_in_previous_epoch = true; total_balances.previous_epoch += effective_balance; } @@ -220,17 +220,17 @@ impl ValidatorStatuses { // Profile this attestation, updating the total balances and generating an // `ValidatorStatus` object that applies to all participants in the attestation. - if is_from_epoch(a, state.current_epoch(spec)) { + if is_from_epoch(a, state.current_epoch()) { status.is_current_epoch_attester = true; - if target_matches_epoch_start_block(a, state, state.current_epoch(spec), spec)? { + if target_matches_epoch_start_block(a, state, state.current_epoch(), spec)? { status.is_current_epoch_target_attester = true; } - } else if is_from_epoch(a, state.previous_epoch(spec)) { + } else if is_from_epoch(a, state.previous_epoch()) { status.is_previous_epoch_attester = true; // The inclusion slot and distance are only required for previous epoch attesters. - let attestation_slot = state.get_attestation_slot(&a.data, spec)?; + let attestation_slot = state.get_attestation_slot(&a.data)?; let inclusion_slot = attestation_slot + a.inclusion_delay; let relative_epoch = RelativeEpoch::from_slot(state.slot, inclusion_slot, spec)?; status.inclusion_info = Some(InclusionInfo { @@ -243,7 +243,7 @@ impl ValidatorStatuses { )?, }); - if target_matches_epoch_start_block(a, state, state.previous_epoch(spec), spec)? { + if target_matches_epoch_start_block(a, state, state.previous_epoch(), spec)? { status.is_previous_epoch_target_attester = true; } @@ -296,7 +296,7 @@ impl ValidatorStatuses { spec: &ChainSpec, ) -> Result<(), BeaconStateError> { // Loop through each slot in the previous epoch. - for slot in state.previous_epoch(spec).slot_iter(spec.slots_per_epoch) { + for slot in state.previous_epoch().slot_iter(spec.slots_per_epoch) { let crosslink_committees_at_slot = state.get_crosslink_committees_at_slot(slot, spec)?; @@ -353,7 +353,7 @@ fn has_common_beacon_block_root( state: &BeaconState, spec: &ChainSpec, ) -> Result { - let attestation_slot = state.get_attestation_slot(&a.data, spec)?; + let attestation_slot = state.get_attestation_slot(&a.data)?; let state_block_root = *state.get_block_root(attestation_slot)?; Ok(a.data.beacon_block_root == state_block_root)