2019-09-23 15:00:10 +00:00
|
|
|
# beacon_chain
|
2020-01-27 11:36:17 +00:00
|
|
|
# Copyright (c) 2018-2020 Status Research & Development GmbH
|
2019-09-23 15:00:10 +00:00
|
|
|
# Licensed and distributed under either of
|
2019-11-25 15:30:02 +00:00
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
2019-09-23 15:00:10 +00:00
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2020-04-22 05:53:02 +00:00
|
|
|
{.push raises: [Defect].}
|
|
|
|
|
2019-09-23 15:00:10 +00:00
|
|
|
import
|
|
|
|
# Standard library
|
2020-07-27 16:04:44 +00:00
|
|
|
std/sets,
|
2019-09-23 15:00:10 +00:00
|
|
|
# Internals
|
2020-07-27 16:04:44 +00:00
|
|
|
./datatypes, ./beaconstate
|
2019-09-23 15:00:10 +00:00
|
|
|
|
|
|
|
# Helpers used in epoch transition and trace-level block transition
|
|
|
|
# --------------------------------------------------------
|
|
|
|
|
2020-07-27 16:49:46 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#helper-functions-1
|
2019-11-12 15:35:12 +00:00
|
|
|
func get_attesting_indices*(
|
2020-07-22 21:01:44 +00:00
|
|
|
state: BeaconState, attestations: openArray[PendingAttestation],
|
2020-07-27 16:04:44 +00:00
|
|
|
cache: var StateCache): HashSet[ValidatorIndex] =
|
2019-11-21 09:15:10 +00:00
|
|
|
# This is part of get_unslashed_attesting_indices(...) in spec.
|
2020-05-20 13:50:03 +00:00
|
|
|
# Exported bceause of external trace-level chronicles logging.
|
2019-11-15 11:04:49 +00:00
|
|
|
result = initHashSet[ValidatorIndex]()
|
2019-09-23 15:00:10 +00:00
|
|
|
for a in attestations:
|
2020-07-21 16:35:43 +00:00
|
|
|
result.incl get_attesting_indices(
|
2020-07-27 16:04:44 +00:00
|
|
|
state, a.data, a.aggregation_bits, cache)
|
2019-09-23 15:00:10 +00:00
|
|
|
|
2020-07-27 16:49:46 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#helper-functions-1
|
2019-09-23 15:00:10 +00:00
|
|
|
func get_unslashed_attesting_indices*(
|
2020-07-22 21:01:44 +00:00
|
|
|
state: BeaconState, attestations: openArray[PendingAttestation],
|
2020-07-27 16:04:44 +00:00
|
|
|
cache: var StateCache): HashSet[ValidatorIndex] =
|
|
|
|
result = get_attesting_indices(state, attestations, cache)
|
2020-08-17 01:09:27 +00:00
|
|
|
var slashedIndices = initHashSet[ValidatorIndex]()
|
2019-09-23 15:00:10 +00:00
|
|
|
for index in result:
|
|
|
|
if state.validators[index].slashed:
|
2020-08-17 01:09:27 +00:00
|
|
|
slashedIndices.incl index
|
|
|
|
result.excl slashedIndices
|