diff --git a/beacon_chain.nimble b/beacon_chain.nimble index cedf249f5..0abca462d 100644 --- a/beacon_chain.nimble +++ b/beacon_chain.nimble @@ -23,8 +23,7 @@ requires "nim >= 0.18.0", "confutils", "serialization", "json_serialization", - "json_rpc", - "cligen 0.9.18" + "json_rpc" ### Helper functions proc test(name: string, defaultLang = "c") = diff --git a/beacon_chain/validator_keygen.nim b/beacon_chain/validator_keygen.nim index e314e1f54..1558408c5 100644 --- a/beacon_chain/validator_keygen.nim +++ b/beacon_chain/validator_keygen.nim @@ -1,6 +1,6 @@ import os, ospaths, strutils, strformat, - asyncdispatch2, milagro_crypto, nimcrypto, json_serialization, + asyncdispatch2, milagro_crypto, nimcrypto, json_serialization, confutils, spec/[datatypes, digest, crypto], conf, randao, time, ssz, ../tests/testutil @@ -20,9 +20,6 @@ proc genSingleValidator(path: string): (ValidatorPubKey, return (v.privKey.pubKey(), v.privKey, v.randao.initialCommitment) -proc printUsage() = - echo "Usage: validator_keygen " - # TODO: Make these more comprehensive and find them a new home type Ether* = distinct int64 @@ -31,24 +28,20 @@ type template eth*(x: SomeInteger): Ether = Ether(x) template gwei*(x: Ether): Gwei = Gwei(int(x) * 1000000000) -proc main() = - if paramCount() != 2: - printUsage() - return +cli do (validators: int, + outputDir: string, + startupDelay = 0): - let totalValidators = parseInt paramStr(1) - if totalValidators < 64: + if validators < 64: echo "The number of validators must be higher than ", EPOCH_LENGTH, " (EPOCH_LENGTH)" echo "There must be at least one validator assigned per slot." quit 1 - let outPath = paramStr(2) - var startupData: ChainStartupData - for i in 1 .. totalValidators: + for i in 1 .. validators: let (pubKey, privKey, randaoCommitment) = - genSingleValidator(outPath / &"validator-{i:02}.json") + genSingleValidator(outputDir / &"validator-{i:02}.json") let withdrawalCredentials = makeFakeHash(i) @@ -71,10 +64,7 @@ proc main() = withdrawal_credentials: withdrawalCredentials, randao_commitment: randaoCommitment))) - startupData.genesisTime = (now() div 1000) + startupData.genesisTime = uint64(int(now() div 1000) + startupDelay) - writeFile(outPath / "startup.json", startupData) - -when isMainModule: - main() + writeFile(outputDir / "startup.json", startupData) diff --git a/research/serialized_sizes.nim b/research/serialized_sizes.nim index 033cd3a73..c879b10b9 100644 --- a/research/serialized_sizes.nim +++ b/research/serialized_sizes.nim @@ -1,8 +1,8 @@ import + confutils, ../beacon_chain/[extras, ssz], ../beacon_chain/spec/[beaconstate, datatypes, digest], - ../tests/testutil, - cligen + ../tests/testutil proc stateSize(deposits: int, maxContent = false) = var state = get_initial_beacon_state( diff --git a/research/state_sim.nim b/research/state_sim.nim index f4a4dd947..71016721f 100644 --- a/research/state_sim.nim +++ b/research/state_sim.nim @@ -1,5 +1,5 @@ import - cligen, + confutils, json, strformat, options, sequtils, random, milagro_crypto, @@ -17,13 +17,12 @@ proc writeJson*(prefix, slot, v: auto) = discard open(f, fmt"{prefix:04}-{slot:08}.json", fmWrite) write(f, pretty(%*(v))) -proc transition( - slots = 1945, - validators = EPOCH_LENGTH, # One per shard is minimum - json_interval = EPOCH_LENGTH, - prefix = 0, - attesterRatio = 0.0, - validate = false) = +cli do(slots = 1945, + validators = EPOCH_LENGTH, # One per shard is minimum + json_interval = EPOCH_LENGTH, + prefix = 0, + attesterRatio {.desc: "ratio of validators that attest in each round"} = 0.0, + validate = false): let flags = if validate: {} else: {skipValidation} genesisState = get_initial_beacon_state( @@ -84,7 +83,3 @@ proc transition( echo "done!" -dispatch( - transition, - help = { "attesterRatio": "ratio of validators that attest in each round" } -) diff --git a/tests/simulation/start.sh b/tests/simulation/start.sh index 9742b4e8f..482743947 100755 --- a/tests/simulation/start.sh +++ b/tests/simulation/start.sh @@ -29,7 +29,7 @@ if [[ -z "$SKIP_BUILDS" ]]; then fi if [ ! -f $STARTUP_FILE ]; then - $VALIDATOR_KEYGEN_BIN $NUMBER_OF_VALIDATORS "$SIMULATION_DIR" + $VALIDATOR_KEYGEN_BIN --validators=$NUMBER_OF_VALIDATORS --outputDir="$SIMULATION_DIR" fi if [ ! -f $SNAPSHOT_FILE ]; then