Slightly safer testnet reset detection

This commit is contained in:
Zahary Karadjov 2019-12-09 17:30:02 +02:00 committed by zah
parent 98656377a3
commit 6ae4070d3f
1 changed files with 11 additions and 6 deletions

View File

@ -66,12 +66,17 @@ cli do (testnetName {.argument.}: string):
depositContractOpt = "--deposit-contract=" & readFile(depositContractFile).strip depositContractOpt = "--deposit-contract=" & readFile(depositContractFile).strip
if system.dirExists(dataDir): if system.dirExists(dataDir):
if system.fileExists(dataDir/genesisFile): block resetDataDir:
let localGenesisContent = readFile(dataDir/genesisFile) # We reset the testnet data dir if the existing data dir is
let testnetGenesisContent = readFile(testnetDir/genesisFile) # incomplete (it misses a genesis file) or if it has a genesis
if localGenesisContent != testnetGenesisContent: # file from an older testnet:
echo "Detected testnet restart. Deleting previous database..." if system.fileExists(dataDir/genesisFile):
rmDir dataDir 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 cd rootDir
exec &"""nim c {nimFlags} -d:"const_preset={preset}" -o:"{beaconNodeBinary}" beacon_chain/beacon_node.nim""" exec &"""nim c {nimFlags} -d:"const_preset={preset}" -o:"{beaconNodeBinary}" beacon_chain/beacon_node.nim"""