mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-18 09:27:05 +00:00
When the connect_to_testnet script is invoked it will first verify that the genesis file of the testnet hasn't changed. If it has changed, any previously created database associated with the testnet will be erased. To facilitate this, the genesis file of each network is written to the data folder of the beacon node. The beacon node will refuse to start if it detects a discrepancy between the data folder and any state snapshot specified on the command-line. Since the testnet sharing spec requires us to use SSZ snapshots, the Json support is now phased out. To help with the transition and to preserve the functionality of the multinet scripts, the beacon node now supports a CLI query command that can extract any data from the genesis state. This is based on new developments in the SSZ navigators.
81 lines
2.6 KiB
Nim
81 lines
2.6 KiB
Nim
import
|
|
confutils, strutils, strformat, ospaths
|
|
|
|
const
|
|
rootDir = thisDir() / ".."
|
|
bootstrapFile = "bootstrap_nodes.txt"
|
|
depositContractFile = "deposit_contract.txt"
|
|
genesisFile = "genesis.ssz"
|
|
configFile = "config.yaml"
|
|
testnetsRepo = "eth2-testnets"
|
|
|
|
let
|
|
testnetsOrg = getEnv("ETH2_TESTNETS_ORG", "eth2-clients")
|
|
testnetsGitUrl = getEnv("ETH2_TESTNETS_GIT_URL", "https://github.com/" & testnetsOrg & "/" & testnetsRepo)
|
|
|
|
mode = Verbose
|
|
|
|
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
|
|
|
|
rmDir(allTestnetsDir)
|
|
cd buildDir
|
|
exec &"git clone --quiet --depth=1 {testnetsGitUrl}"
|
|
|
|
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 genesisFile
|
|
|
|
var preset = testnetDir / configFile
|
|
if not fileExists(preset): preset = "minimal"
|
|
|
|
let
|
|
dataDirName = testnetName.replace("/", "_")
|
|
dataDir = buildDir / "data" / dataDirName
|
|
beaconNodeBinary = buildDir / "beacon_node_" & dataDirName
|
|
nimFlags = "-d:release --lineTrace:on -d:chronicles_log_level=DEBUG " & getEnv("NIM_PARAMS")
|
|
|
|
var depositContractOpt = ""
|
|
let depositContractFile = testnetDir / depositContractFile
|
|
if fileExists(depositContractFile):
|
|
depositContractOpt = "--deposit-contract=" & readFile(depositContractFile).strip
|
|
|
|
if dirExists(dataDir):
|
|
if fileExists(dataDir/genesisFile):
|
|
let localGenesisContent = readFile(dataDir/genesisFile)
|
|
let testnetGenesisContent = readFile(testnetDir/genesisFile)
|
|
if localGenesisContent != testnetGenesisContent:
|
|
echo "Detected testnet restart. Deleting previous database..."
|
|
rmDir dataDir
|
|
|
|
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}" """ & depositContractOpt, "\n", " ")
|
|
|