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
This commit is contained in:
Dustin Brody 2019-07-13 15:58:01 +00:00 committed by GitHub
parent b6e2d4f30a
commit c92806b950
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 4 deletions

View File

@ -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..<paramCount():
extra_params &= " " & paramStr(i)
exec "nim " & lang & " --out:./build/" & name & " " & extra_params & " " & srcDir & name & ".nim"
exec "nim " & lang & " --out:./build/" & name & " " & extra_params & " " & srcDir & name & ".nim" & " " & cmdParams
### tasks
task test, "Run all tests":
@ -47,3 +47,5 @@ task test, "Run all tests":
buildBinary "all_tests", "tests/", "-r -d:release -d:chronicles_log_level=ERROR"
# Minimal config
buildBinary "all_tests", "tests/", "-r -d:release -d:chronicles_log_level=ERROR -d:const_preset=minimal"
# State sim; getting into 3rd epoch useful
buildBinary "state_sim", "research/", "-r -d:release", "--validators=128 --slots=140"

View File

@ -473,6 +473,11 @@ chronicles.formatIt Epoch: it.humaneEpochNum
chronicles.formatIt BeaconBlock: it.shortLog
chronicles.formatIt AttestationData: it.shortLog
static:
# Ensure that get_crosslink_committee(...) can access all committees, which
# requires that SHARD_COUNT >= get_committee_count(...)
doAssert SHARD_COUNT >= SLOTS_PER_EPOCH
import nimcrypto, json_serialization
export json_serialization
export writeValue, readValue, append, read

View File

@ -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 =

View File

@ -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