some comment changes noting further 0.4.0-spec-update progress, but no meaningful semantic changes (#161)

This commit is contained in:
Dustin Brody 2019-03-08 18:23:42 +00:00 committed by GitHub
parent b777e43e56
commit 0b47acae37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 20 deletions

View File

@ -249,7 +249,7 @@ func get_initial_beacon_block*(state: BeaconState): BeaconBlock =
state_root: Eth2Digest(data: hash_tree_root(state))
)
# https://github.com/ethereum/eth2.0-specs/blob/v0.3.0/specs/core/0_beacon-chain.md#get_block_root
# https://github.com/ethereum/eth2.0-specs/blob/0.4.0/specs/core/0_beacon-chain.md#get_block_root
func get_block_root*(state: BeaconState,
slot: Slot): Eth2Digest =
# Return the block root at a recent ``slot``.
@ -306,7 +306,7 @@ func process_ejections*(state: var BeaconState) =
if state.validator_balances[index] < EJECTION_BALANCE:
exit_validator(state, index)
# https://github.com/ethereum/eth2.0-specs/blob/v0.3.0/specs/core/0_beacon-chain.md#get_total_balance
# https://github.com/ethereum/eth2.0-specs/blob/0.4.0/specs/core/0_beacon-chain.md#get_total_balance
func get_total_balance*(state: BeaconState, validators: auto): Gwei =
# Return the combined effective balance of an array of validators.
foldl(validators, a + get_effective_balance(state, b), 0'u64)

View File

@ -464,7 +464,7 @@ type
crosslink_data_root*: Eth2Digest ##\
## Shard data since the previous crosslink
# https://github.com/ethereum/eth2.0-specs/blob/v0.3.0/specs/core/0_beacon-chain.md#pendingattestation
# https://github.com/ethereum/eth2.0-specs/blob/0.4.0/specs/core/0_beacon-chain.md#pendingattestation
PendingAttestation* = object
aggregation_bitfield*: seq[byte] # Attester participation bitfield
data*: AttestationData # Attestation data

View File

@ -155,7 +155,7 @@ func is_active_validator*(validator: Validator, epoch: Epoch): bool =
### Checks if validator is active
validator.activation_epoch <= epoch and epoch < validator.exit_epoch
# https://github.com/ethereum/eth2.0-specs/blob/v0.3.0/specs/core/0_beacon-chain.md#get_active_validator_indices
# https://github.com/ethereum/eth2.0-specs/blob/0.4.0/specs/core/0_beacon-chain.md#get_active_validator_indices
func get_active_validator_indices*(validators: openArray[Validator], epoch: Epoch): seq[ValidatorIndex] =
## Gets indices of active validators from validators
for idx, val in validators:

View File

@ -119,15 +119,10 @@ func get_next_epoch_committee_count(state: BeaconState): uint64 =
)
get_epoch_committee_count(len(next_active_validators))
# https://github.com/ethereum/eth2.0-specs/blob/v0.3.0/specs/core/0_beacon-chain.md#get_previous_epoch
func get_previous_epoch(state: BeaconState): Epoch =
# https://github.com/ethereum/eth2.0-specs/blob/0.4.0/specs/core/0_beacon-chain.md#get_previous_epoch
func get_previous_epoch*(state: BeaconState): Epoch =
## Return the previous epoch of the given ``state``.
## If the current epoch is ``GENESIS_EPOCH``, return ``GENESIS_EPOCH``.
let current_epoch = get_current_epoch(state)
if current_epoch == GENESIS_EPOCH:
GENESIS_EPOCH
else:
current_epoch - 1
max(get_current_epoch(state) - 1, GENESIS_EPOCH)
# https://github.com/ethereum/eth2.0-specs/blob/v0.3.0/specs/core/0_beacon-chain.md#get_crosslink_committees_at_slot
func get_crosslink_committees_at_slot*(state: BeaconState, slot: Slot,

View File

@ -546,21 +546,17 @@ func process_exit_queue(state: var BeaconState) =
break
prepare_validator_for_withdrawal(state, index)
# https://github.com/ethereum/eth2.0-specs/blob/v0.3.0/specs/core/0_beacon-chain.md#per-epoch-processing
func processEpoch(state: var BeaconState) =
if (state.slot + 1) mod SLOTS_PER_EPOCH != 0:
return
# https://github.com/ethereum/eth2.0-specs/blob/v0.3.0/specs/core/0_beacon-chain.md#helper-variables
# https://github.com/ethereum/eth2.0-specs/blob/0.4.0/specs/core/0_beacon-chain.md#helper-variables
let
current_epoch = get_current_epoch(state)
previous_epoch =
if current_epoch > GENESIS_EPOCH:
current_epoch - 1
else:
current_epoch
previous_epoch = get_previous_epoch(state)
next_epoch = (current_epoch + 1).Epoch
# Spec grabs this later, but it's part of current_total_balance
active_validator_indices =
get_active_validator_indices(state.validator_registry, current_epoch)
@ -678,6 +674,9 @@ func processEpoch(state: var BeaconState) =
get_total_balance(
statePtr[], attesting_validator_indices(crosslink_committee))
## Regarding inclusion_slot and inclusion_distance, as defined they result in
## O(n^2) behavior, so implement slightly differently.
# https://github.com/ethereum/eth2.0-specs/blob/v0.3.0/specs/core/0_beacon-chain.md#eth1-data-1
block:
if next_epoch mod EPOCHS_PER_ETH1_VOTING_PERIOD == 0:
@ -872,7 +871,7 @@ func processEpoch(state: var BeaconState) =
state.validator_balances[proposer_index] +=
base_reward(state, v) div ATTESTATION_INCLUSION_REWARD_QUOTIENT
# https://github.com/ethereum/eth2.0-specs/blob/v0.3.0/specs/core/0_beacon-chain.md#crosslinks-1
# https://github.com/ethereum/eth2.0-specs/blob/0.4.0/specs/core/0_beacon-chain.md#crosslinks-1
block:
for slot in get_epoch_start_slot(previous_epoch) ..< get_epoch_start_slot(current_epoch):
let crosslink_committees_at_slot = get_crosslink_committees_at_slot(state, slot)