diff --git a/beacon_chain/beacon_node.nim b/beacon_chain/beacon_node.nim index 5d40d14ce..aba4d1631 100644 --- a/beacon_chain/beacon_node.nim +++ b/beacon_chain/beacon_node.nim @@ -281,6 +281,12 @@ proc makeAttestation(node: BeaconNode, shard: uint64, committeeLen: int, indexInCommittee: int) {.async.} = + + # TODO - move that to "updateState" + # Epoch underflow - https://github.com/status-im/nim-beacon-chain/issues/207 + doAssert node.state.data.current_justified_epoch != GENESIS_EPOCH - 1, + "Underflow in justified epoch field before making attestation" + let attestationData = makeAttestationData(node.state.data, shard, node.state.blck.root) diff --git a/beacon_chain/spec/validator.nim b/beacon_chain/spec/validator.nim index b00bb7c72..1ee4cac46 100644 --- a/beacon_chain/spec/validator.nim +++ b/beacon_chain/spec/validator.nim @@ -125,7 +125,11 @@ func get_next_epoch_committee_count(state: BeaconState): uint64 = # https://github.com/ethereum/eth2.0-specs/blob/v0.5.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``. - get_current_epoch(state) - 1 + let epoch = get_current_epoch(state) + if epoch == GENESIS_EPOCH: + raise newException(OverflowError, "Underflow: trying to get the previous epoch of epoch 0 (genesis).") + epoch - 1 + # https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#get_crosslink_committees_at_slot func get_crosslink_committees_at_slot*(state: BeaconState, slot: Slot|uint64,