Fix some BeaconState API changes in state proc.

This commit is contained in:
Paul Hauner 2019-05-19 15:56:24 +10:00
parent 9eb8c7411f
commit 03849de319
No known key found for this signature in database
GPG Key ID: 5E2CFF9B75FA63DF
11 changed files with 32 additions and 36 deletions

View File

@ -19,7 +19,7 @@ pub fn initiate_validator_exit<T: EthSpec>(
}
// 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()

View File

@ -12,7 +12,7 @@ pub fn exit_validator<T: EthSpec>(
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;

View File

@ -14,7 +14,7 @@ pub fn slash_validator<T: EthSpec>(
return Err(BeaconStateError::UnknownValidator);
}
let current_epoch = state.current_epoch(spec);
let current_epoch = state.current_epoch();
initiate_validator_exit(state, slashed_index, spec)?;

View File

@ -164,7 +164,7 @@ pub fn process_randao<T: EthSpec>(
// 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<T: EthSpec>(
);
// 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<T: EthSpec>(
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)

View File

@ -51,9 +51,9 @@ fn verify_exit_parametric<T: EthSpec>(
// 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
}
);

View File

@ -88,12 +88,12 @@ pub fn process_justification_and_finalization<T: EthSpec>(
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<T: EthSpec>(
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<T: EthSpec>(
state: &mut BeaconState<T>,
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<T: EthSpec>(
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;
}

View File

@ -39,7 +39,7 @@ pub fn process_rewards_and_penalties<T: EthSpec>(
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<T: EthSpec>(
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(

View File

@ -8,7 +8,7 @@ pub fn process_slashings<T: EthSpec>(
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)?;

View File

@ -14,7 +14,7 @@ pub fn process_registry_updates<T: EthSpec>(
// 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

View File

@ -15,7 +15,7 @@ pub fn update_registry_and_shuffling_data<T: EthSpec>(
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<T: EthSpec>(
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<T: EthSpec>(
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

View File

@ -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<T: EthSpec>(
state: &BeaconState<T>,
spec: &ChainSpec,
) -> Result<bool, BeaconStateError> {
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)