2019-10-28 23:07:31 +00:00
|
|
|
import
|
2019-11-12 14:57:33 +00:00
|
|
|
confutils, strutils, strformat, os
|
2019-10-28 23:07:31 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
rootDir = thisDir() / ".."
|
|
|
|
bootstrapFile = "bootstrap_nodes.txt"
|
|
|
|
depositContractFile = "deposit_contract.txt"
|
|
|
|
genesisFile = "genesis.ssz"
|
|
|
|
configFile = "config.yaml"
|
|
|
|
testnetsRepo = "eth2-testnets"
|
2019-11-05 13:00:11 +00:00
|
|
|
|
|
|
|
let
|
2019-11-09 10:46:34 +00:00
|
|
|
testnetsOrg = getEnv("ETH2_TESTNETS_ORG", "eth2-clients")
|
2019-11-05 13:00:11 +00:00
|
|
|
testnetsGitUrl = getEnv("ETH2_TESTNETS_GIT_URL", "https://github.com/" & testnetsOrg & "/" & testnetsRepo)
|
2019-10-28 23:07:31 +00:00
|
|
|
|
2019-11-09 10:46:34 +00:00
|
|
|
mode = Verbose
|
|
|
|
|
2019-10-28 23:07:31 +00:00
|
|
|
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
|
|
|
|
|
2019-11-07 20:10:59 +00:00
|
|
|
rmDir(allTestnetsDir)
|
|
|
|
cd buildDir
|
2019-11-05 13:00:11 +00:00
|
|
|
exec &"git clone --quiet --depth=1 {testnetsGitUrl}"
|
2019-10-28 23:07:31 +00:00
|
|
|
|
|
|
|
let testnetDir = allTestnetsDir / team / testnet
|
2019-11-12 14:57:33 +00:00
|
|
|
if not system.dirExists(testnetDir):
|
2019-10-28 23:07:31 +00:00
|
|
|
echo &"No metadata files exists for the '{testnetName}' testnet"
|
|
|
|
quit 1
|
|
|
|
|
|
|
|
proc checkRequiredFile(fileName: string) =
|
|
|
|
let filePath = testnetDir / fileName
|
2019-11-12 14:57:33 +00:00
|
|
|
if not system.fileExists(filePath):
|
2019-10-28 23:07:31 +00:00
|
|
|
echo &"The required file {fileName} is not present in '{testnetDir}'."
|
|
|
|
quit 1
|
|
|
|
|
|
|
|
checkRequiredFile bootstrapFile
|
|
|
|
checkRequiredFile genesisFile
|
|
|
|
|
|
|
|
var preset = testnetDir / configFile
|
2019-11-12 14:57:33 +00:00
|
|
|
if not system.fileExists(preset): preset = "minimal"
|
2019-10-28 23:07:31 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
dataDirName = testnetName.replace("/", "_")
|
|
|
|
dataDir = buildDir / "data" / dataDirName
|
|
|
|
beaconNodeBinary = buildDir / "beacon_node_" & dataDirName
|
2019-11-25 14:36:25 +00:00
|
|
|
nimFlags = "-d:chronicles_log_level=DEBUG " & getEnv("NIM_PARAMS")
|
2019-10-28 23:07:31 +00:00
|
|
|
|
2019-10-29 00:27:13 +00:00
|
|
|
var depositContractOpt = ""
|
|
|
|
let depositContractFile = testnetDir / depositContractFile
|
2019-11-12 14:57:33 +00:00
|
|
|
if system.fileExists(depositContractFile):
|
2019-10-29 00:27:13 +00:00
|
|
|
depositContractOpt = "--deposit-contract=" & readFile(depositContractFile).strip
|
|
|
|
|
2019-11-12 14:57:33 +00:00
|
|
|
if system.dirExists(dataDir):
|
|
|
|
if system.fileExists(dataDir/genesisFile):
|
2019-11-09 10:46:34 +00:00
|
|
|
let localGenesisContent = readFile(dataDir/genesisFile)
|
|
|
|
let testnetGenesisContent = readFile(testnetDir/genesisFile)
|
|
|
|
if localGenesisContent != testnetGenesisContent:
|
|
|
|
echo "Detected testnet restart. Deleting previous database..."
|
|
|
|
rmDir dataDir
|
|
|
|
|
2019-10-28 23:07:31 +00:00
|
|
|
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}"
|
2019-10-29 00:27:13 +00:00
|
|
|
--state-snapshot="{testnetDir/genesisFile}" """ & depositContractOpt, "\n", " ")
|
2019-10-28 23:07:31 +00:00
|
|
|
|