From f92db449e1af8d9a10804f505b8cdfe9cb451648 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Tue, 29 Oct 2019 01:07:31 +0200 Subject: [PATCH] nims script for connecting to testnets published in the eth2-testnets repo See https://github.com/ethereum/eth2.0-pm/pull/93 for more info --- scripts/connect_to_testnet.nims | 71 +++++++++++++++++++++++++++++++++ vendor/nim-confutils | 2 +- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 scripts/connect_to_testnet.nims diff --git a/scripts/connect_to_testnet.nims b/scripts/connect_to_testnet.nims new file mode 100644 index 000000000..5f56ff71c --- /dev/null +++ b/scripts/connect_to_testnet.nims @@ -0,0 +1,71 @@ +import + confutils, strutils, strformat, ospaths + +const + rootDir = thisDir() / ".." + bootstrapFile = "bootstrap_nodes.txt" + depositContractFile = "deposit_contract.txt" + genesisFile = "genesis.ssz" + configFile = "config.yaml" + clientsOrg = "zah" # "eth2-clients" + testnetsRepo = "eth2-testnets" + testnetsRepoGitUrl = "git://github.com/" & clientsOrg & "/" & testnetsRepo + +proc validateTestnetName(parts: openarray[string]): auto = + if parts.len != 2: + echo "The testnet name should have the format `client/network-name`" + quit 1 + (parts[0], parts[1]) + +cli do (testnetName {.argument.}: string): + let + nameParts = testnetName.split "/" + (team, testnet) = if nameParts.len > 1: validateTestnetName nameParts + else: ("nimbus", testnetName) + + let + buildDir = rootDir / "build" + allTestnetsDir = buildDir / testnetsRepo + + if not dirExists(allTestnetsDir): + cd buildDir + exec &"git clone {testnetsRepoGitUrl}" + + cd allTestnetsDir + exec &"git remote set-url origin {testnetsRepoGitUrl}" + exec "git reset --hard master" + exec "git pull" + + let testnetDir = allTestnetsDir / team / testnet + if not dirExists(testnetDir): + echo &"No metadata files exists for the '{testnetName}' testnet" + quit 1 + + proc checkRequiredFile(fileName: string) = + let filePath = testnetDir / fileName + if not fileExists(filePath): + echo &"The required file {fileName} is not present in '{testnetDir}'." + quit 1 + + checkRequiredFile bootstrapFile + checkRequiredFile depositContractFile + checkRequiredFile genesisFile + + var preset = testnetDir / configFile + if not fileExists(preset): preset = "minimal" + + let + depositContract = readFile(testnetDir / depositContractFile).strip + dataDirName = testnetName.replace("/", "_") + dataDir = buildDir / "data" / dataDirName + beaconNodeBinary = buildDir / "beacon_node_" & dataDirName + nimFlags = "-d:release --lineTrace:on -d:chronicles_log_level=DEBUG" + + cd rootDir + exec &"""nim c {nimFlags} -d:"const_preset={preset}" -o:"{beaconNodeBinary}" beacon_chain/beacon_node.nim""" + exec replace(&"""{beaconNodeBinary} + --data-dir="{dataDir}" + --bootstrap-file="{testnetDir/bootstrapFile}" + --state-snapshot="{testnetDir/genesisFile}" + --deposit-contract={depositContract}""", "\n", " ") + diff --git a/vendor/nim-confutils b/vendor/nim-confutils index 36645f132..533a621d4 160000 --- a/vendor/nim-confutils +++ b/vendor/nim-confutils @@ -1 +1 @@ -Subproject commit 36645f1322c64deba03432d34dd75a9dafbd95ed +Subproject commit 533a621d4a596eb3bccb27572234dbe4d2eebfac