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