catch premix and persit tool exception

This commit is contained in:
andri lim 2019-01-09 19:10:58 +07:00 committed by zah
parent b0f4a236fa
commit da75707912
2 changed files with 39 additions and 14 deletions

View File

@ -2,7 +2,8 @@
import
eth_common, stint, byteutils, nimcrypto,
chronicles, rlp, downloader, configuration
chronicles, rlp, downloader, configuration,
../nimbus/errors
import
eth_trie/[hexary, db, defs],
@ -73,7 +74,7 @@ proc main() =
if numBlocks == numBlocksToCommit:
persistToDb(db):
if chain.persistBlocks(headers, bodies) != ValidationResult.OK:
break
raise newException(ValidationError, "Error when validating blocks")
numBlocks = 0
headers.setLen(0)
bodies.setLen(0)
@ -84,7 +85,8 @@ proc main() =
if numBlocks > 0:
persistToDb(db):
discard chain.persistBlocks(headers, bodies)
if chain.persistBlocks(headers, bodies) != ValidationResult.OK:
raise newException(ValidationError, "Error when validating blocks")
when isMainModule:
var message: string
@ -98,4 +100,7 @@ when isMainModule:
echo message
quit(QuitSuccess)
main()
try:
main()
except:
echo getCurrentExceptionMsg()

View File

@ -1,5 +1,5 @@
import
json, downloader, stint, strutils,
json, downloader, stint, strutils, os,
../nimbus/tracer, chronicles, prestate
proc fakeAlloc(n: JsonNode) =
@ -93,15 +93,35 @@ proc generatePremixData(nimbus: JsonNode, blockNumber: Uint256, thisBlock: Block
var data = "var debugMetaData = " & metaData.pretty & "\n"
writeFile("premixData.js", data)
proc main() =
let
nimbus = parseFile("debug_meta_data.json")
blockNumber = UInt256.fromHex(nimbus["blockNumber"].getStr())
thisBlock = downloader.requestBlock(blockNumber, {DownloadReceipts, DownloadTxTrace})
postState = requestPostState(thisBlock)
accounts = processPostState(postState)
proc printDebugInstruction(blockNumber: Uint256) =
var text = """
generatePremixData(nimbus, blockNumber, thisBlock, postState, accounts)
generatePrestate(nimbus, blockNumber, thisBlock)
Successfully created debugging environment for block $1.
You can continue to find nimbus EVM bug by viewing premix report page `./index.html`.
After that you can try to debug that single block using `nim c -r debug block$1.json` command.
Happy bug hunting
""" % [$blockNumber]
echo text
proc main() =
if paramCount() == 0:
echo "usage: premix debug_meta_data.json"
quit(QuitFailure)
try:
let
nimbus = json.parseFile(paramStr(1))
blockNumber = UInt256.fromHex(nimbus["blockNumber"].getStr())
thisBlock = downloader.requestBlock(blockNumber, {DownloadReceipts, DownloadTxTrace})
postState = requestPostState(thisBlock)
accounts = processPostState(postState)
generatePremixData(nimbus, blockNumber, thisBlock, postState, accounts)
generatePrestate(nimbus, blockNumber, thisBlock)
printDebugInstruction(blockNumber)
except:
echo getCurrentExceptionMsg()
main()