From 0b47acae3795e6a2750302682d20b724dc15fd6e Mon Sep 17 00:00:00 2001 From: Dustin Brody Date: Fri, 8 Mar 2019 18:23:42 +0000 Subject: [PATCH] some comment changes noting further 0.4.0-spec-update progress, but no meaningful semantic changes (#161) --- beacon_chain/spec/beaconstate.nim | 4 ++-- beacon_chain/spec/datatypes.nim | 2 +- beacon_chain/spec/helpers.nim | 2 +- beacon_chain/spec/validator.nim | 11 +++-------- beacon_chain/state_transition.nim | 15 +++++++-------- 5 files changed, 14 insertions(+), 20 deletions(-) diff --git a/beacon_chain/spec/beaconstate.nim b/beacon_chain/spec/beaconstate.nim index 5971b3c2e..90d990712 100644 --- a/beacon_chain/spec/beaconstate.nim +++ b/beacon_chain/spec/beaconstate.nim @@ -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) diff --git a/beacon_chain/spec/datatypes.nim b/beacon_chain/spec/datatypes.nim index 6c5e70b76..53ea878e0 100644 --- a/beacon_chain/spec/datatypes.nim +++ b/beacon_chain/spec/datatypes.nim @@ -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 diff --git a/beacon_chain/spec/helpers.nim b/beacon_chain/spec/helpers.nim index 0034442d6..6223167cd 100644 --- a/beacon_chain/spec/helpers.nim +++ b/beacon_chain/spec/helpers.nim @@ -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: diff --git a/beacon_chain/spec/validator.nim b/beacon_chain/spec/validator.nim index a5e074b00..b85ba25c8 100644 --- a/beacon_chain/spec/validator.nim +++ b/beacon_chain/spec/validator.nim @@ -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, diff --git a/beacon_chain/state_transition.nim b/beacon_chain/state_transition.nim index 446e1c525..ac8cd46a5 100644 --- a/beacon_chain/state_transition.nim +++ b/beacon_chain/state_transition.nim @@ -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)