diff --git a/beacon_chain/fork_choice/fork_choice.nim b/beacon_chain/fork_choice/fork_choice.nim index 542de59e3..d64a81ac2 100644 --- a/beacon_chain/fork_choice/fork_choice.nim +++ b/beacon_chain/fork_choice/fork_choice.nim @@ -290,8 +290,6 @@ proc process_block*(self: var ForkChoice, continue if attestation.data.beacon_block_root in self.backend: let - epochRef = - dag.getEpochRef(targetBlck, attestation.data.target.epoch) participants = get_attesting_indices( epochRef, attestation.data, attestation.aggregation_bits) diff --git a/beacon_chain/spec/beaconstate.nim b/beacon_chain/spec/beaconstate.nim index a29beb1a3..f1710da70 100644 --- a/beacon_chain/spec/beaconstate.nim +++ b/beacon_chain/spec/beaconstate.nim @@ -595,8 +595,6 @@ proc process_attestation*( # In the spec, attestation validation is mixed with state mutation, so here # we've split it into two functions so that the validation logic can be # reused when looking for suitable blocks to include in attestations. - # TODO don't log warnings when looking for attestations (return - # Result[void, cstring] instead of logging in check_attestation?) let proposer_index = get_beacon_proposer_index(state, cache) if proposer_index.isNone: diff --git a/beacon_chain/spec/state_transition_epoch.nim b/beacon_chain/spec/state_transition_epoch.nim index a05e27009..40834d1c9 100644 --- a/beacon_chain/spec/state_transition_epoch.nim +++ b/beacon_chain/spec/state_transition_epoch.nim @@ -66,8 +66,8 @@ func get_total_active_balance*(state: BeaconState, cache: var StateCache): Gwei state, cache.get_shuffled_active_validator_indices(state, epoch)) # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#helper-functions-1 -func get_matching_source_attestations(state: BeaconState, - epoch: Epoch): seq[PendingAttestation] = +template get_matching_source_attestations(state: BeaconState, + epoch: Epoch): seq[PendingAttestation] = doAssert epoch in [get_current_epoch(state), get_previous_epoch(state)] if epoch == get_current_epoch(state): state.current_epoch_attestations.asSeq @@ -309,10 +309,11 @@ func get_source_deltas*( state: BeaconState, total_balance: Gwei, cache: var StateCache): tuple[a: seq[Gwei], b: seq[Gwei]] = # Return attester micro-rewards/penalties for source-vote for each validator. - let matching_source_attestations = - get_matching_source_attestations(state, get_previous_epoch(state)) + get_attestation_component_deltas( - state, matching_source_attestations, total_balance, cache) + state, + get_matching_source_attestations(state, get_previous_epoch(state)), + total_balance, cache) func get_target_deltas*( state: BeaconState, total_balance: Gwei, cache: var StateCache): diff --git a/beacon_chain/spec/state_transition_helpers.nim b/beacon_chain/spec/state_transition_helpers.nim index bfcda8f8a..024c3846e 100644 --- a/beacon_chain/spec/state_transition_helpers.nim +++ b/beacon_chain/spec/state_transition_helpers.nim @@ -31,9 +31,9 @@ func get_attesting_indices*( func get_unslashed_attesting_indices*( state: BeaconState, attestations: openArray[PendingAttestation], cache: var StateCache): HashSet[ValidatorIndex] = - result = get_attesting_indices(state, attestations, cache) - var slashedIndices = initHashSet[ValidatorIndex]() - for index in result: - if state.validators[index].slashed: - slashedIndices.incl index - result.excl slashedIndices + result = initHashSet[ValidatorIndex]() + for a in attestations: + for idx in get_attesting_indices( + state, a.data, a.aggregation_bits, cache): + if not state.validators[idx].slashed: + result.incl idx