mark comments documenting functions as a whole as such (#1613)

This commit is contained in:
tersec 2020-09-08 08:54:55 +00:00 committed by Mamy Ratsimbazafy
parent 7e3f20236f
commit 45dd971955
4 changed files with 52 additions and 53 deletions

View File

@ -37,14 +37,14 @@ func is_valid_merkle_branch*(leaf: Eth2Digest, branch: openarray[Eth2Digest],
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#increase_balance # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#increase_balance
func increase_balance*( func increase_balance*(
state: var BeaconState, index: ValidatorIndex, delta: Gwei) = state: var BeaconState, index: ValidatorIndex, delta: Gwei) =
# Increase the validator balance at index ``index`` by ``delta``. ## Increase the validator balance at index ``index`` by ``delta``.
state.balances[index] += delta state.balances[index] += delta
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#decrease_balance # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#decrease_balance
func decrease_balance*( func decrease_balance*(
state: var BeaconState, index: ValidatorIndex, delta: Gwei) = state: var BeaconState, index: ValidatorIndex, delta: Gwei) =
# Decrease the validator balance at index ``index`` by ``delta``, with ## Decrease the validator balance at index ``index`` by ``delta``, with
# underflow protection. ## underflow protection.
state.balances[index] = state.balances[index] =
if delta > state.balances[index]: if delta > state.balances[index]:
0'u64 0'u64
@ -73,7 +73,7 @@ proc process_deposit*(preset: RuntimePreset,
state: var BeaconState, state: var BeaconState,
deposit: Deposit, deposit: Deposit,
flags: UpdateFlags = {}): Result[void, cstring] {.nbench.}= flags: UpdateFlags = {}): Result[void, cstring] {.nbench.}=
# Process an Eth1 deposit, registering a validator or increasing its balance. ## Process an Eth1 deposit, registering a validator or increasing its balance.
# Verify the Merkle branch # Verify the Merkle branch
if not is_valid_merkle_branch( if not is_valid_merkle_branch(
@ -129,7 +129,7 @@ func compute_activation_exit_epoch*(epoch: Epoch): Epoch =
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_validator_churn_limit # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_validator_churn_limit
func get_validator_churn_limit(state: BeaconState, cache: var StateCache): uint64 = func get_validator_churn_limit(state: BeaconState, cache: var StateCache): uint64 =
# Return the validator churn limit for the current epoch. ## Return the validator churn limit for the current epoch.
max( max(
MIN_PER_EPOCH_CHURN_LIMIT, MIN_PER_EPOCH_CHURN_LIMIT,
count_active_validators( count_active_validators(
@ -138,7 +138,7 @@ func get_validator_churn_limit(state: BeaconState, cache: var StateCache): uint6
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#initiate_validator_exit # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#initiate_validator_exit
func initiate_validator_exit*(state: var BeaconState, func initiate_validator_exit*(state: var BeaconState,
index: ValidatorIndex, cache: var StateCache) = index: ValidatorIndex, cache: var StateCache) =
# Initiate the exit of the validator with index ``index``. ## Initiate the exit of the validator with index ``index``.
# Return if validator already initiated exit # Return if validator already initiated exit
let validator = addr state.validators[index] let validator = addr state.validators[index]
@ -167,7 +167,7 @@ func initiate_validator_exit*(state: var BeaconState,
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#slash_validator # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#slash_validator
proc slash_validator*(state: var BeaconState, slashed_index: ValidatorIndex, proc slash_validator*(state: var BeaconState, slashed_index: ValidatorIndex,
cache: var StateCache) = cache: var StateCache) =
# Slash the validator with index ``index``. ## Slash the validator with index ``index``.
let epoch = get_current_epoch(state) let epoch = get_current_epoch(state)
initiate_validator_exit(state, slashed_index, cache) initiate_validator_exit(state, slashed_index, cache)
let validator = addr state.validators[slashed_index] let validator = addr state.validators[slashed_index]
@ -320,7 +320,7 @@ func get_initial_beacon_block*(state: BeaconState): SignedBeaconBlock =
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_block_root_at_slot # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_block_root_at_slot
func get_block_root_at_slot*(state: BeaconState, func get_block_root_at_slot*(state: BeaconState,
slot: Slot): Eth2Digest = slot: Slot): Eth2Digest =
# Return the block root at a recent ``slot``. ## Return the block root at a recent ``slot``.
# Potential overflow/wrap shouldn't occur, as get_block_root_at_slot() called # Potential overflow/wrap shouldn't occur, as get_block_root_at_slot() called
# from internally controlled sources, but flag this explicitly, in case. # from internally controlled sources, but flag this explicitly, in case.
@ -332,7 +332,7 @@ func get_block_root_at_slot*(state: BeaconState,
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_block_root # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_block_root
func get_block_root*(state: BeaconState, epoch: Epoch): Eth2Digest = func get_block_root*(state: BeaconState, epoch: Epoch): Eth2Digest =
# Return the block root at the start of a recent ``epoch``. ## Return the block root at the start of a recent ``epoch``.
get_block_root_at_slot(state, compute_start_slot_at_epoch(epoch)) get_block_root_at_slot(state, compute_start_slot_at_epoch(epoch))
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_total_balance # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_total_balance
@ -346,14 +346,14 @@ func get_total_balance*(state: BeaconState, validators: auto): Gwei =
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#is_eligible_for_activation_queue # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#is_eligible_for_activation_queue
func is_eligible_for_activation_queue(validator: Validator): bool = func is_eligible_for_activation_queue(validator: Validator): bool =
# Check if ``validator`` is eligible to be placed into the activation queue. ## Check if ``validator`` is eligible to be placed into the activation queue.
validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH and validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH and
validator.effective_balance == MAX_EFFECTIVE_BALANCE validator.effective_balance == MAX_EFFECTIVE_BALANCE
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#is_eligible_for_activation # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#is_eligible_for_activation
func is_eligible_for_activation(state: BeaconState, validator: Validator): func is_eligible_for_activation(state: BeaconState, validator: Validator):
bool = bool =
# Check if ``validator`` is eligible for activation. ## Check if ``validator`` is eligible for activation.
# Placement in queue is finalized # Placement in queue is finalized
validator.activation_eligibility_epoch <= state.finalized_checkpoint.epoch and validator.activation_eligibility_epoch <= state.finalized_checkpoint.epoch and
@ -423,8 +423,8 @@ proc process_registry_updates*(state: var BeaconState,
proc is_valid_indexed_attestation*( proc is_valid_indexed_attestation*(
state: BeaconState, indexed_attestation: SomeIndexedAttestation, state: BeaconState, indexed_attestation: SomeIndexedAttestation,
flags: UpdateFlags): Result[void, cstring] = flags: UpdateFlags): Result[void, cstring] =
# Check if ``indexed_attestation`` is not empty, has sorted and unique ## Check if ``indexed_attestation`` is not empty, has sorted and unique
# indices and has a valid aggregate signature. ## indices and has a valid aggregate signature.
template is_sorted_and_unique(s: untyped): bool = template is_sorted_and_unique(s: untyped): bool =
var res = true var res = true
@ -491,7 +491,7 @@ func get_attesting_indices*(state: BeaconState,
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_indexed_attestation # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_indexed_attestation
func get_indexed_attestation*(state: BeaconState, attestation: Attestation, func get_indexed_attestation*(state: BeaconState, attestation: Attestation,
cache: var StateCache): IndexedAttestation = cache: var StateCache): IndexedAttestation =
# Return the indexed attestation corresponding to ``attestation``. ## Return the indexed attestation corresponding to ``attestation``.
let let
attesting_indices = attesting_indices =
get_attesting_indices( get_attesting_indices(
@ -507,7 +507,7 @@ func get_indexed_attestation*(state: BeaconState, attestation: Attestation,
func get_indexed_attestation*(state: BeaconState, attestation: TrustedAttestation, func get_indexed_attestation*(state: BeaconState, attestation: TrustedAttestation,
cache: var StateCache): TrustedIndexedAttestation = cache: var StateCache): TrustedIndexedAttestation =
# Return the indexed attestation corresponding to ``attestation``. ## Return the indexed attestation corresponding to ``attestation``.
let let
attesting_indices = attesting_indices =
get_attesting_indices( get_attesting_indices(

View File

@ -24,7 +24,7 @@ type
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#integer_squareroot # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#integer_squareroot
func integer_squareroot*(n: SomeInteger): SomeInteger = func integer_squareroot*(n: SomeInteger): SomeInteger =
# Return the largest integer ``x`` such that ``x**2 <= n``. ## Return the largest integer ``x`` such that ``x**2 <= n``.
doAssert n >= 0'u64 doAssert n >= 0'u64
var var
@ -37,7 +37,7 @@ func integer_squareroot*(n: SomeInteger): SomeInteger =
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#compute_epoch_at_slot # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#compute_epoch_at_slot
func compute_epoch_at_slot*(slot: Slot|uint64): Epoch = func compute_epoch_at_slot*(slot: Slot|uint64): Epoch =
# Return the epoch number at ``slot``. ## Return the epoch number at ``slot``.
(slot div SLOTS_PER_EPOCH).Epoch (slot div SLOTS_PER_EPOCH).Epoch
template epoch*(slot: Slot): Epoch = template epoch*(slot: Slot): Epoch =
@ -48,25 +48,25 @@ template isEpoch*(slot: Slot): bool =
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#compute_start_slot_at_epoch # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#compute_start_slot_at_epoch
func compute_start_slot_at_epoch*(epoch: Epoch): Slot = func compute_start_slot_at_epoch*(epoch: Epoch): Slot =
# Return the start slot of ``epoch``. ## Return the start slot of ``epoch``.
(epoch * SLOTS_PER_EPOCH).Slot (epoch * SLOTS_PER_EPOCH).Slot
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#is_active_validator # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#is_active_validator
func is_active_validator*(validator: Validator, epoch: Epoch): bool = func is_active_validator*(validator: Validator, epoch: Epoch): bool =
### Check if ``validator`` is active ## Check if ``validator`` is active
validator.activation_epoch <= epoch and epoch < validator.exit_epoch validator.activation_epoch <= epoch and epoch < validator.exit_epoch
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_active_validator_indices # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_active_validator_indices
func get_active_validator_indices*(state: BeaconState, epoch: Epoch): func get_active_validator_indices*(state: BeaconState, epoch: Epoch):
seq[ValidatorIndex] = seq[ValidatorIndex] =
# Return the sequence of active validator indices at ``epoch``. ## Return the sequence of active validator indices at ``epoch``.
for idx, val in state.validators: for idx, val in state.validators:
if is_active_validator(val, epoch): if is_active_validator(val, epoch):
result.add idx.ValidatorIndex result.add idx.ValidatorIndex
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_current_epoch # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_current_epoch
func get_current_epoch*(state: BeaconState): Epoch = func get_current_epoch*(state: BeaconState): Epoch =
# Return the current epoch. ## Return the current epoch.
doAssert state.slot >= GENESIS_SLOT, $state.slot doAssert state.slot >= GENESIS_SLOT, $state.slot
compute_epoch_at_slot(state.slot) compute_epoch_at_slot(state.slot)
@ -101,10 +101,10 @@ func uint_to_bytes4*(x: uint64): array[4, byte] =
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#compute_fork_data_root # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#compute_fork_data_root
func compute_fork_data_root(current_version: Version, func compute_fork_data_root(current_version: Version,
genesis_validators_root: Eth2Digest): Eth2Digest = genesis_validators_root: Eth2Digest): Eth2Digest =
# Return the 32-byte fork data root for the ``current_version`` and ## Return the 32-byte fork data root for the ``current_version`` and
# ``genesis_validators_root``. ## ``genesis_validators_root``.
# This is used primarily in signature domains to avoid collisions across ## This is used primarily in signature domains to avoid collisions across
# forks/chains. ## forks/chains.
hash_tree_root(ForkData( hash_tree_root(ForkData(
current_version: current_version, current_version: current_version,
genesis_validators_root: genesis_validators_root genesis_validators_root: genesis_validators_root
@ -113,10 +113,10 @@ func compute_fork_data_root(current_version: Version,
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#compute_fork_digest # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#compute_fork_digest
func compute_fork_digest*(current_version: Version, func compute_fork_digest*(current_version: Version,
genesis_validators_root: Eth2Digest): ForkDigest = genesis_validators_root: Eth2Digest): ForkDigest =
# Return the 4-byte fork digest for the ``current_version`` and ## Return the 4-byte fork digest for the ``current_version`` and
# ``genesis_validators_root``. ## ``genesis_validators_root``.
# This is a digest primarily used for domain separation on the p2p layer. ## This is a digest primarily used for domain separation on the p2p layer.
# 4-bytes suffices for practical separation of forks/chains. ## 4-bytes suffices for practical separation of forks/chains.
array[4, byte](result)[0..3] = array[4, byte](result)[0..3] =
compute_fork_data_root( compute_fork_data_root(
current_version, genesis_validators_root).data.toOpenArray(0, 3) current_version, genesis_validators_root).data.toOpenArray(0, 3)
@ -126,7 +126,7 @@ func compute_domain*(
domain_type: DomainType, domain_type: DomainType,
fork_version: Version, fork_version: Version,
genesis_validators_root: Eth2Digest = ZERO_HASH): Domain = genesis_validators_root: Eth2Digest = ZERO_HASH): Domain =
# Return the domain for the ``domain_type`` and ``fork_version``. ## Return the domain for the ``domain_type`` and ``fork_version``.
let fork_data_root = let fork_data_root =
compute_fork_data_root(fork_version, genesis_validators_root) compute_fork_data_root(fork_version, genesis_validators_root)
result[0..3] = uint_to_bytes4(domain_type.uint64) result[0..3] = uint_to_bytes4(domain_type.uint64)
@ -152,8 +152,8 @@ func get_domain*(
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#compute_signing_root # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#compute_signing_root
func compute_signing_root*(ssz_object: auto, domain: Domain): Eth2Digest = func compute_signing_root*(ssz_object: auto, domain: Domain): Eth2Digest =
# Return the signing root of an object by calculating the root of the ## Return the signing root of an object by calculating the root of the
# object-domain tree. ## object-domain tree.
let domain_wrapped_object = SigningData( let domain_wrapped_object = SigningData(
object_root: hash_tree_root(ssz_object), object_root: hash_tree_root(ssz_object),
domain: domain domain: domain
@ -162,7 +162,7 @@ func compute_signing_root*(ssz_object: auto, domain: Domain): Eth2Digest =
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_seed # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_seed
func get_seed*(state: BeaconState, epoch: Epoch, domain_type: DomainType): Eth2Digest = func get_seed*(state: BeaconState, epoch: Epoch, domain_type: DomainType): Eth2Digest =
# Return the seed at ``epoch``. ## Return the seed at ``epoch``.
var seed_input : array[4+8+32, byte] var seed_input : array[4+8+32, byte]

View File

@ -55,12 +55,11 @@ declareGauge beacon_current_epoch, "Current epoch"
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_total_active_balance # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_total_active_balance
func get_total_active_balance*(state: BeaconState, cache: var StateCache): Gwei = func get_total_active_balance*(state: BeaconState, cache: var StateCache): Gwei =
# Return the combined effective balance of the active validators. ## Return the combined effective balance of the active validators.
# Note: ``get_total_balance`` returns ``EFFECTIVE_BALANCE_INCREMENT`` Gwei # Note: ``get_total_balance`` returns ``EFFECTIVE_BALANCE_INCREMENT`` Gwei
# minimum to avoid divisions by zero. # minimum to avoid divisions by zero.
let let epoch = state.get_current_epoch()
epoch = state.get_current_epoch()
get_total_balance( get_total_balance(
state, cache.get_shuffled_active_validator_indices(state, epoch)) state, cache.get_shuffled_active_validator_indices(state, epoch))
@ -92,8 +91,8 @@ func get_matching_head_attestations(state: BeaconState, epoch: Epoch):
func get_attesting_balance( func get_attesting_balance(
state: BeaconState, attestations: seq[PendingAttestation], state: BeaconState, attestations: seq[PendingAttestation],
stateCache: var StateCache): Gwei = stateCache: var StateCache): Gwei =
# Return the combined effective balance of the set of unslashed validators ## Return the combined effective balance of the set of unslashed validators
# participating in ``attestations``. ## participating in ``attestations``.
# Note: ``get_total_balance`` returns ``EFFECTIVE_BALANCE_INCREMENT`` Gwei # Note: ``get_total_balance`` returns ``EFFECTIVE_BALANCE_INCREMENT`` Gwei
# minimum to avoid divisions by zero. # minimum to avoid divisions by zero.
get_total_balance(state, get_unslashed_attesting_indices( get_total_balance(state, get_unslashed_attesting_indices(
@ -308,7 +307,7 @@ func get_attestation_component_deltas(state: BeaconState,
func get_source_deltas*( func get_source_deltas*(
state: BeaconState, total_balance: Gwei, cache: var StateCache): state: BeaconState, total_balance: Gwei, cache: var StateCache):
tuple[a: seq[Gwei], b: seq[Gwei]] = tuple[a: seq[Gwei], b: seq[Gwei]] =
# Return attester micro-rewards/penalties for source-vote for each validator. ## Return attester micro-rewards/penalties for source-vote for each validator.
get_attestation_component_deltas( get_attestation_component_deltas(
state, state,
@ -318,7 +317,7 @@ func get_source_deltas*(
func get_target_deltas*( func get_target_deltas*(
state: BeaconState, total_balance: Gwei, cache: var StateCache): state: BeaconState, total_balance: Gwei, cache: var StateCache):
tuple[a: seq[Gwei], b: seq[Gwei]] = tuple[a: seq[Gwei], b: seq[Gwei]] =
# Return attester micro-rewards/penalties for target-vote for each validator. ## Return attester micro-rewards/penalties for target-vote for each validator.
let matching_target_attestations = let matching_target_attestations =
get_matching_target_attestations(state, get_previous_epoch(state)) get_matching_target_attestations(state, get_previous_epoch(state))
get_attestation_component_deltas( get_attestation_component_deltas(
@ -327,7 +326,7 @@ func get_target_deltas*(
func get_head_deltas*( func get_head_deltas*(
state: BeaconState, total_balance: Gwei, cache: var StateCache): state: BeaconState, total_balance: Gwei, cache: var StateCache):
tuple[a: seq[Gwei], b: seq[Gwei]] = tuple[a: seq[Gwei], b: seq[Gwei]] =
# Return attester micro-rewards/penalties for head-vote for each validator. ## Return attester micro-rewards/penalties for head-vote for each validator.
let matching_head_attestations = let matching_head_attestations =
get_matching_head_attestations(state, get_previous_epoch(state)) get_matching_head_attestations(state, get_previous_epoch(state))
get_attestation_component_deltas( get_attestation_component_deltas(
@ -336,7 +335,7 @@ func get_head_deltas*(
func get_inclusion_delay_deltas*( func get_inclusion_delay_deltas*(
state: BeaconState, total_balance: Gwei, cache: var StateCache): state: BeaconState, total_balance: Gwei, cache: var StateCache):
seq[Gwei] = seq[Gwei] =
# Return proposer and inclusion delay micro-rewards/penalties for each validator. ## Return proposer and inclusion delay micro-rewards/penalties for each validator.
var var
rewards = repeat(0'u64, len(state.validators)) rewards = repeat(0'u64, len(state.validators))
matching_source_attestations = matching_source_attestations =
@ -380,7 +379,7 @@ func get_inclusion_delay_deltas*(
func get_inactivity_penalty_deltas*( func get_inactivity_penalty_deltas*(
state: BeaconState, total_balance: Gwei, cache: var StateCache): state: BeaconState, total_balance: Gwei, cache: var StateCache):
seq[Gwei] = seq[Gwei] =
# Return inactivity reward/penalty deltas for each validator. ## Return inactivity reward/penalty deltas for each validator.
var penalties = repeat(0'u64, len(state.validators)) var penalties = repeat(0'u64, len(state.validators))
if is_in_inactivity_leak(state): if is_in_inactivity_leak(state):
let let
@ -408,7 +407,7 @@ func get_inactivity_penalty_deltas*(
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_attestation_deltas # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#get_attestation_deltas
func get_attestation_deltas(state: BeaconState, cache: var StateCache): func get_attestation_deltas(state: BeaconState, cache: var StateCache):
tuple[a: seq[Gwei], b: seq[Gwei]] = tuple[a: seq[Gwei], b: seq[Gwei]] =
# Return attestation reward/penalty deltas for each validator. ## Return attestation reward/penalty deltas for each validator.
let let
total_balance = get_total_active_balance(state, cache) total_balance = get_total_active_balance(state, cache)
(source_rewards, source_penalties) = (source_rewards, source_penalties) =

View File

@ -227,7 +227,7 @@ func compute_committee_len*(
func get_beacon_committee*( func get_beacon_committee*(
state: BeaconState, slot: Slot, index: CommitteeIndex, state: BeaconState, slot: Slot, index: CommitteeIndex,
cache: var StateCache): seq[ValidatorIndex] = cache: var StateCache): seq[ValidatorIndex] =
# Return the beacon committee at ``slot`` for ``index``. ## Return the beacon committee at ``slot`` for ``index``.
let let
epoch = compute_epoch_at_slot(slot) epoch = compute_epoch_at_slot(slot)
committees_per_slot = get_committee_count_per_slot(state, epoch, cache) committees_per_slot = get_committee_count_per_slot(state, epoch, cache)
@ -257,7 +257,7 @@ func get_beacon_committee_len*(
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#compute_shuffled_index # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#compute_shuffled_index
func compute_shuffled_index( func compute_shuffled_index(
index: uint64, index_count: uint64, seed: Eth2Digest): uint64 = index: uint64, index_count: uint64, seed: Eth2Digest): uint64 =
# Return the shuffled index corresponding to ``seed`` (and ``index_count``). ## Return the shuffled index corresponding to ``seed`` (and ``index_count``).
doAssert index < index_count doAssert index < index_count
var var
@ -295,7 +295,7 @@ func compute_shuffled_index(
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#compute_proposer_index # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#compute_proposer_index
func compute_proposer_index(state: BeaconState, indices: seq[ValidatorIndex], func compute_proposer_index(state: BeaconState, indices: seq[ValidatorIndex],
seed: Eth2Digest): Option[ValidatorIndex] = seed: Eth2Digest): Option[ValidatorIndex] =
# Return from ``indices`` a random index sampled by effective balance. ## Return from ``indices`` a random index sampled by effective balance.
const MAX_RANDOM_BYTE = 255 const MAX_RANDOM_BYTE = 255
if len(indices) == 0: if len(indices) == 0:
@ -361,12 +361,12 @@ func get_committee_assignment*(
state: BeaconState, epoch: Epoch, state: BeaconState, epoch: Epoch,
validator_index: ValidatorIndex): validator_index: ValidatorIndex):
Option[tuple[a: seq[ValidatorIndex], b: CommitteeIndex, c: Slot]] = Option[tuple[a: seq[ValidatorIndex], b: CommitteeIndex, c: Slot]] =
# Return the committee assignment in the ``epoch`` for ``validator_index``. ## Return the committee assignment in the ``epoch`` for ``validator_index``.
# ``assignment`` returned is a tuple of the following form: ## ``assignment`` returned is a tuple of the following form:
# * ``assignment[0]`` is the list of validators in the committee ## * ``assignment[0]`` is the list of validators in the committee
# * ``assignment[1]`` is the index to which the committee is assigned ## * ``assignment[1]`` is the index to which the committee is assigned
# * ``assignment[2]`` is the slot at which the committee is assigned ## * ``assignment[2]`` is the slot at which the committee is assigned
# Return None if no assignment. ## Return None if no assignment.
let next_epoch = get_current_epoch(state) + 1 let next_epoch = get_current_epoch(state) + 1
doAssert epoch <= next_epoch doAssert epoch <= next_epoch