diff --git a/beacon_chain/beacon_node.nim b/beacon_chain/beacon_node.nim index ff90bc561..65b0db75a 100644 --- a/beacon_chain/beacon_node.nim +++ b/beacon_chain/beacon_node.nim @@ -89,7 +89,7 @@ proc sync*(node: BeaconNode): Future[bool] {.async.} = node.beaconState = await obtainTrustedStateSnapshot(node.db) else: node.beaconState = persistedState[] - var targetSlot = (toSlot timeSinceGenesis(node.beaconState)) + var targetSlot = toSlot timeSinceGenesis(node.beaconState) let t = now() if t < node.beaconState.genesisTime * 1000: diff --git a/beacon_chain/spec/helpers.nim b/beacon_chain/spec/helpers.nim index 101146a41..8307a741f 100644 --- a/beacon_chain/spec/helpers.nim +++ b/beacon_chain/spec/helpers.nim @@ -208,7 +208,7 @@ func get_randao_mix*(state: BeaconState, func get_active_index_root(state: BeaconState, epoch: EpochNumber): Eth2Digest = # Returns the index root at a recent ``epoch``. assert get_current_epoch(state) - LATEST_INDEX_ROOTS_LENGTH < epoch - assert epoch <= get_current_epoch(state) + assert epoch <= get_current_epoch(state) + 1 state.latest_index_roots[epoch mod LATEST_INDEX_ROOTS_LENGTH] func generate_seed*(state: BeaconState, epoch: EpochNumber): Eth2Digest = diff --git a/beacon_chain/state_transition.nim b/beacon_chain/state_transition.nim index 0d6382a10..ebfc182c6 100644 --- a/beacon_chain/state_transition.nim +++ b/beacon_chain/state_transition.nim @@ -730,15 +730,15 @@ func processEpoch(state: var BeaconState) = state.latest_crosslinks[(state.current_epoch_start_shard + it.uint64) mod SHARD_COUNT].epoch > state.validator_registry_update_epoch): update_validator_registry(state) + state.current_calculation_epoch = next_epoch state.current_epoch_start_shard = (state.current_epoch_start_shard + get_current_epoch_committee_count(state) * EPOCH_LENGTH) mod SHARD_COUNT state.current_epoch_seed = generate_seed(state, state.current_calculation_epoch) - state.current_calculation_epoch = next_epoch else: # If a validator registry change does NOT happen let epochs_since_last_registry_change = current_epoch - state.validator_registry_update_epoch if is_power_of_2(epochs_since_last_registry_change): - state.current_epoch_seed = generate_seed(state, state.current_calculation_epoch) state.current_calculation_epoch = next_epoch + state.current_epoch_seed = generate_seed(state, state.current_calculation_epoch) # /Note/ that state.current_epoch_start_shard is left unchanged # TODO run process_penalties_and_exits