nimbus-eth2/beacon_chain/spec/state_transition_helpers.nim

40 lines
1.7 KiB
Nim
Raw Normal View History

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
# * 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.
{.push raises: [Defect].}
2019-09-23 15:00:10 +00:00
import
# Standard library
std/sets,
2019-09-23 15:00:10 +00:00
# Internals
./datatypes, ./beaconstate
2019-09-23 15:00:10 +00:00
# Helpers used in epoch transition and trace-level block transition
# --------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.3/specs/phase0/beacon-chain.md#helper-functions-1
2019-11-12 15:35:12 +00:00
func get_attesting_indices*(
state: BeaconState, attestations: openArray[PendingAttestation],
cache: var StateCache): HashSet[ValidatorIndex] =
# This is part of get_unslashed_attesting_indices(...) in spec.
# 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:
result.incl get_attesting_indices(
state, a.data, a.aggregation_bits, cache)
2019-09-23 15:00:10 +00:00
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.3/specs/phase0/beacon-chain.md#helper-functions-1
2019-09-23 15:00:10 +00:00
func get_unslashed_attesting_indices*(
state: BeaconState, attestations: openArray[PendingAttestation],
cache: var StateCache): HashSet[ValidatorIndex] =
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