Helpful scripts for resetting the testnets
This commit is contained in:
parent
6a35d3584d
commit
42ca6afae2
|
@ -47,7 +47,8 @@ proc downloadFile(url: string): Future[string] {.async.} =
|
|||
return fileContents
|
||||
|
||||
proc updateTestnetMetadata(conf: BeaconNodeConf): Future[NetworkMetadata] {.async.} =
|
||||
let latestMetadata = await downloadFile(testnetsBaseUrl // $conf.network // networkMetadataFile)
|
||||
let latestMetadata = await downloadFile(testnetsBaseUrl // $conf.network //
|
||||
netBackendName & "-" & networkMetadataFile)
|
||||
|
||||
let localMetadataFile = conf.dataDir / networkMetadataFile
|
||||
if fileExists(localMetadataFile) and readFile(localMetadataFile).string == latestMetadata:
|
||||
|
@ -716,28 +717,24 @@ when isMainModule:
|
|||
of updateTestnet:
|
||||
discard waitFor updateTestnetMetadata(config)
|
||||
|
||||
of importValidator:
|
||||
of importValidators:
|
||||
template reportFailureFor(keyExpr) =
|
||||
error "Failed to import validator key", key = keyExpr
|
||||
programResult = 1
|
||||
|
||||
var downloadKey = true
|
||||
|
||||
if config.key.isSome:
|
||||
downloadKey = false
|
||||
for key in config.keys:
|
||||
try:
|
||||
ValidatorPrivKey.init(config.key.get).saveValidatorKey(config)
|
||||
ValidatorPrivKey.init(key).saveValidatorKey(config)
|
||||
except:
|
||||
reportFailureFor config.key.get
|
||||
reportFailureFor key
|
||||
|
||||
if config.keyFile.isSome:
|
||||
downloadKey = false
|
||||
for keyFile in config.keyFiles:
|
||||
try:
|
||||
config.keyFile.get.load.saveValidatorKey(config)
|
||||
keyFile.load.saveValidatorKey(config)
|
||||
except:
|
||||
reportFailureFor config.keyFile.get.string
|
||||
reportFailureFor keyFile.string
|
||||
|
||||
if downloadKey:
|
||||
if (config.keys.len + config.keyFiles.len) == 0:
|
||||
if config.network in ["testnet0", "testnet1"]:
|
||||
try:
|
||||
let key = waitFor obtainTestnetKey(config)
|
||||
|
|
|
@ -12,7 +12,7 @@ type
|
|||
StartUpCommand* = enum
|
||||
noCommand
|
||||
createTestnet
|
||||
importValidator
|
||||
importValidators
|
||||
updateTestnet
|
||||
|
||||
BeaconNodeConf* = object
|
||||
|
@ -107,12 +107,14 @@ type
|
|||
outputNetwork* {.
|
||||
desc: "Output file where to write the initial state snapshot".}: OutFile
|
||||
|
||||
of importValidator:
|
||||
keyFile* {.
|
||||
desc: "File with validator key to be imported (in hex form)".}: Option[ValidatorKeyPath]
|
||||
of importValidators:
|
||||
keyFiles* {.
|
||||
longform: "keyfile"
|
||||
desc: "File with validator key to be imported (in hex form)".}: seq[ValidatorKeyPath]
|
||||
|
||||
key* {.
|
||||
desc: "Validator key to be imported (in hex form)".}: Option[string]
|
||||
keys* {.
|
||||
longform: "key"
|
||||
desc: "Validator key to be imported (in hex form)".}: seq[string]
|
||||
|
||||
of updateTestnet:
|
||||
discard
|
||||
|
|
|
@ -13,6 +13,9 @@ when useRLPx:
|
|||
export
|
||||
p2p, rlp, gossipsub_protocol
|
||||
|
||||
const
|
||||
netBackendName* = "rlpx"
|
||||
|
||||
type
|
||||
Eth2Node* = EthereumNode
|
||||
BootstrapAddr* = ENode
|
||||
|
@ -82,6 +85,9 @@ else:
|
|||
type
|
||||
BootstrapAddr* = PeerInfo
|
||||
|
||||
const
|
||||
netBackendName* = "libp2p"
|
||||
|
||||
proc writeValue*(writer: var JsonWriter, value: PeerID) {.inline.} =
|
||||
writer.writeValue value.pretty
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -eu
|
||||
|
||||
cd $(dirname "$0")
|
||||
|
||||
NETWORK_NAME=$1
|
||||
source "$NETWORK_NAME.env"
|
||||
|
||||
cd ..
|
||||
|
||||
if [ -f .env ]; then
|
||||
# allow server overrides for WWW_DIR and DATA_DIR
|
||||
source .env
|
||||
fi
|
||||
|
||||
PUBLIC_IP=$(curl -s ifconfig.me)
|
||||
NETWORK_DIR=$WWW_DIR/$NETWORK_NAME
|
||||
|
||||
regenTestnetFiles() {
|
||||
NIM_FLAGS="-d:release -d:SHARD_COUNT=$SHARD_COUNT -d:SLOTS_PER_EPOCH=$SLOTS_PER_EPOCH ${2:-}"
|
||||
NETWORK_FLAVOUR=$1
|
||||
|
||||
if [ ! -f $NETWORK_DIR/genesis.json ]; then
|
||||
rm $NETWORK_DIR/*
|
||||
nim c -r $NIM_FLAGS beacon_chain/validator_keygen \
|
||||
--validators=$VALIDATOR_COUNT \
|
||||
--outputDir="$NETWORK_DIR"
|
||||
fi
|
||||
|
||||
nim c -r $NIM_FLAGS beacon_chain/beacon_node --dataDir=$DATA_DIR/node-0 \
|
||||
createTestnet \
|
||||
--networkId=$NETWORK_ID \
|
||||
--validatorsDir=$NETWORK_DIR \
|
||||
--numValidators=$VALIDATOR_COUNT \
|
||||
--firstUserValidator=$FIRST_USER_VALIDATOR \
|
||||
--outputGenesis=$NETWORK_DIR/genesis.json \
|
||||
--outputNetwork=$NETWORK_DIR/$NETWORK_FLAVOUR-network.json \
|
||||
--bootstrapAddress=$PUBLIC_IP \
|
||||
--genesisOffset=600 # Delay in seconds
|
||||
}
|
||||
|
||||
regenTestnetFiles rlpx
|
||||
# regenTestnetFiles libp2p -d:withLibP2P
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd $(dirname "$0")
|
||||
./reset_testnet.sh testnet0
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd $(dirname "$0")
|
||||
./reset_testnet.sh testnet1
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
NETWORK_ID=1000000
|
||||
SHARD_COUNT=8
|
||||
SLOTS_PER_EPOCH=8
|
||||
VALIDATOR_COUNT=400
|
||||
FIRST_USER_VALIDATOR=340
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
NETWORK_ID=2000000
|
||||
SHARD_COUNT=128
|
||||
SLOTS_PER_EPOCH=64
|
||||
VALIDATOR_COUNT=20000
|
||||
FIRST_USER_VALIDATOR=19000
|
||||
|
Loading…
Reference in New Issue