From c92806b9503a6e65ee941ebe3bf41b3b1a615af4 Mon Sep 17 00:00:00 2001 From: Dustin Brody Date: Sat, 13 Jul 2019 15:58:01 +0000 Subject: [PATCH] include both static and dynamic check for invariants to ensure that get_crosslink_committee(...) can access all committees by ensure that SHARD_COUNT >= SLOTS_PER_EPOCH (#318) * include both static and dynamic check for invariants to ensure that get_crosslink_committee(...) can access all committees by ensure that SHARD_COUNT >= SLOTS_PER_EPOCH * add state_sim to CI, to ensure that it also doesn't break SHARD_COUNT/SLOTS_PER_EPOCH assumptions, along with just in general not breaking --- beacon_chain.nimble | 6 ++++-- beacon_chain/spec/datatypes.nim | 5 +++++ beacon_chain/spec/helpers.nim | 5 ++++- beacon_chain/spec/presets/minimal.nim | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/beacon_chain.nimble b/beacon_chain.nimble index 4c6c36c34..6b5a7b17b 100644 --- a/beacon_chain.nimble +++ b/beacon_chain.nimble @@ -32,14 +32,14 @@ requires "nim >= 0.19.0", "libp2p" ### Helper functions -proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") = +proc buildBinary(name: string, srcDir = "./", params = "", cmdParams = "", lang = "c") = if not dirExists "build": mkDir "build" # allow something like "nim test --verbosity:0 --hints:off beacon_chain.nims" var extra_params = params for i in 2..= get_committee_count(...) + doAssert SHARD_COUNT >= SLOTS_PER_EPOCH + import nimcrypto, json_serialization export json_serialization export writeValue, readValue, append, read diff --git a/beacon_chain/spec/helpers.nim b/beacon_chain/spec/helpers.nim index bd33d2d81..3d1107c45 100644 --- a/beacon_chain/spec/helpers.nim +++ b/beacon_chain/spec/helpers.nim @@ -87,7 +87,10 @@ func get_committee_count*(state: BeaconState, epoch: Epoch): uint64 = let committees_per_slot = clamp( len(active_validator_indices) div SLOTS_PER_EPOCH div TARGET_COMMITTEE_SIZE, 1, SHARD_COUNT div SLOTS_PER_EPOCH).uint64 - committees_per_slot * SLOTS_PER_EPOCH + result = committees_per_slot * SLOTS_PER_EPOCH + + # Otherwise, get_crosslink_committee(...) cannot access some committees. + doAssert SHARD_COUNT >= result # https://github.com/ethereum/eth2.0-specs/blob/v0.8.0/specs/core/0_beacon-chain.md#get_current_epoch func get_current_epoch*(state: BeaconState): Epoch = diff --git a/beacon_chain/spec/presets/minimal.nim b/beacon_chain/spec/presets/minimal.nim index 51fd6e0f2..162560c7b 100644 --- a/beacon_chain/spec/presets/minimal.nim +++ b/beacon_chain/spec/presets/minimal.nim @@ -80,7 +80,7 @@ const MIN_ATTESTATION_INCLUSION_DELAY* = 1 # Changed - SLOTS_PER_EPOCH* {.intdefine.} = 64 + SLOTS_PER_EPOCH* {.intdefine.} = 8 # Unchanged MIN_SEED_LOOKAHEAD* = 1