Skip to content

Commit

Permalink
Slightly safer testnet reset detection
Browse files Browse the repository at this point in the history
  • Loading branch information
zah committed Dec 10, 2019
1 parent e34cf6e commit 3fe03fb
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions scripts/connect_to_testnet.nims
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,17 @@ cli do (testnetName {.argument.}: string):
depositContractOpt = "--deposit-contract=" & readFile(depositContractFile).strip

if system.dirExists(dataDir):
if system.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
block resetDataDir:
# We reset the testnet data dir if the existing data dir is
# incomplete (it misses a genesis file) or if it has a genesis
# file from an older testnet:
if system.fileExists(dataDir/genesisFile):
let localGenesisContent = readFile(dataDir/genesisFile)
let testnetGenesisContent = readFile(testnetDir/genesisFile)
if localGenesisContent == testnetGenesisContent:
break
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"""
Expand Down

0 comments on commit 3fe03fb

Please sign in to comment.