Replace the usage of cligen with confutils (#68)
This commit is contained in:
parent
53952dd0c9
commit
a0712e691a
|
@ -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") =
|
||||
|
|
|
@ -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 <number-of-validators> <out-path>"
|
||||
|
||||
# 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)
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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,
|
||||
cli do(slots = 1945,
|
||||
validators = EPOCH_LENGTH, # One per shard is minimum
|
||||
json_interval = EPOCH_LENGTH,
|
||||
prefix = 0,
|
||||
attesterRatio = 0.0,
|
||||
validate = false) =
|
||||
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" }
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue