2019-09-23 15:00:10 +00:00
|
|
|
# beacon_chain
|
|
|
|
# Copyright (c) 2018-2019 Status Research & Development GmbH
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
import
|
|
|
|
# Standard library
|
|
|
|
sets,
|
|
|
|
# Internals
|
|
|
|
./datatypes, ./digest, ./beaconstate
|
|
|
|
|
|
|
|
# Logging utilities
|
|
|
|
# --------------------------------------------------------
|
|
|
|
|
|
|
|
# TODO: gather all logging utilities
|
|
|
|
# from crypto, digest, etc in a single file
|
|
|
|
func shortLog*(x: Checkpoint): string =
|
|
|
|
"(epoch: " & $x.epoch & ", root: \"" & shortLog(x.root) & "\")"
|
|
|
|
|
|
|
|
# Helpers used in epoch transition and trace-level block transition
|
|
|
|
# --------------------------------------------------------
|
|
|
|
|
2019-11-22 08:29:04 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#helper-functions-1
|
2019-11-12 15:35:12 +00:00
|
|
|
func get_attesting_indices*(
|
2019-09-23 15:00:10 +00:00
|
|
|
state: BeaconState, attestations: openarray[PendingAttestation],
|
|
|
|
stateCache: var StateCache): HashSet[ValidatorIndex] =
|
2019-11-21 09:15:10 +00:00
|
|
|
# This is part of get_unslashed_attesting_indices(...) in spec.
|
2019-11-15 11:04:49 +00:00
|
|
|
result = initHashSet[ValidatorIndex]()
|
2019-09-23 15:00:10 +00:00
|
|
|
for a in attestations:
|
|
|
|
result = result.union(get_attesting_indices(
|
|
|
|
state, a.data, a.aggregation_bits, stateCache))
|
|
|
|
|
2019-12-18 09:19:21 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#helper-functions-1
|
2019-09-23 15:00:10 +00:00
|
|
|
func get_unslashed_attesting_indices*(
|
|
|
|
state: BeaconState, attestations: openarray[PendingAttestation],
|
|
|
|
stateCache: var StateCache): HashSet[ValidatorIndex] =
|
|
|
|
result = get_attesting_indices(state, attestations, stateCache)
|
|
|
|
for index in result:
|
|
|
|
if state.validators[index].slashed:
|
|
|
|
result.excl index
|