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
11 changed files with 32 additions and 36 deletions

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)