add dumper tool

This commit is contained in:
andri lim 2019-01-10 15:23:18 +07:00 committed by zah
parent 000af79b03
commit 0a6b3505f2
4 changed files with 64 additions and 15 deletions

View File

@ -240,20 +240,14 @@ proc dumpDebuggingMetaData*(chainDB: BaseChainDB, header: BlockHeader, blockBody
captureTrieDB = trieDB captureDB captureTrieDB = trieDB captureDB
captureChainDB = newBaseChainDB(captureTrieDB, false) captureChainDB = newBaseChainDB(captureTrieDB, false)
let
txTraces = traceTransactions(captureChainDB, header, blockBody)
stateDump = dumpBlockState(captureChainDB, header, blockBody)
blockTrace = traceBlock(captureChainDB, header, blockBody, {DisableState})
receipts = toJson(receipts)
var metaData = %{ var metaData = %{
"blockNumber": %blockNumber.toHex, "blockNumber": %blockNumber.toHex,
"txTraces": txTraces, "txTraces": traceTransactions(captureChainDB, header, blockBody),
"stateDump": stateDump, "stateDump": dumpBlockState(captureChainDB, header, blockBody),
"blockTrace": blockTrace, "blockTrace": traceBlock(captureChainDB, header, blockBody, {DisableState}),
"receipts": receipts "receipts": toJson(receipts)
} }
metaData.dumpMemoryDB(memoryDB) metaData.dumpMemoryDB(memoryDB)
# this is a placeholder until premix debugging tool is ready # this is a placeholder until premix debugging tool is ready
writeFile("debug_meta_data.json", metaData.pretty()) writeFile("debug" & $blockNumber & ".json", metaData.pretty())

55
premix/dumper.nim Normal file
View File

@ -0,0 +1,55 @@
#
# helper tool to dump debugging data for persisted block
# usage: dumper [--datadir:your_path] --head:blockNumber
#
import
configuration, stint, eth_common,
../nimbus/db/[storage_types, db_chain, select_backend, capturedb],
eth_trie/[hexary, db, defs], ../nimbus/p2p/executor,
../nimbus/[tracer, vm_state]
proc dumpDebug(chainDB: BaseChainDB, blockNumber: Uint256) =
var
memoryDB = newMemoryDB()
captureDB = newCaptureDB(chainDB.db, memoryDB)
captureTrieDB = trieDB captureDB
captureChainDB = newBaseChainDB(captureTrieDB, false)
let
parentNumber = blockNumber - 1
parent = captureChainDB.getBlockHeader(parentNumber)
header = captureChainDB.getBlockHeader(blockNumber)
headerHash = header.blockHash
body = captureChainDB.getBlockBody(headerHash)
vmState = newBaseVMState(parent, captureChainDB)
captureChainDB.setHead(parent, true)
let validationResult = processBlock(captureChainDB, parent, header, body, vmState)
dumpDebuggingMetaData(captureChainDB, header, body, vmState.receipts)
proc main() =
let conf = getConfiguration()
let db = newChainDb(conf.dataDir)
let trieDB = trieDB db
let chainDB = newBaseChainDB(trieDB, false)
if conf.head != 0.u256:
dumpDebug(chainDB, conf.head)
when isMainModule:
var message: string
## Processing command line arguments
if processArguments(message) != Success:
echo message
quit(QuitFailure)
else:
if len(message) > 0:
echo message
quit(QuitSuccess)
try:
main()
except:
echo getCurrentExceptionMsg()

View File

@ -34,7 +34,7 @@ proc main() =
# 52029 first block with receipts logs # 52029 first block with receipts logs
# 66407 failed transaction # 66407 failed transaction
var conf = getConfiguration() let conf = getConfiguration()
let db = newChainDb(conf.dataDir) let db = newChainDb(conf.dataDir)
let trieDB = trieDB db let trieDB = trieDB db
let chainDB = newBaseChainDB(trieDB, false) let chainDB = newBaseChainDB(trieDB, false)

View File

@ -67,7 +67,7 @@ proc requestPostState(thisBlock: Block): JsonNode =
proc copyAccount(acc: JsonNode): JsonNode = proc copyAccount(acc: JsonNode): JsonNode =
result = newJObject() result = newJObject()
result["balance"] = newJString(acc["balance"].getStr) result["balance"] = newJString(acc["balance"].getStr)
result["nonce"] = newJString(acc["nonce"].getStr) result["nonce"] = newJString(toHex(acc["nonce"].getInt))
result["code"] = newJString(acc["code"].getStr) result["code"] = newJString(acc["code"].getStr)
var storage = newJObject() var storage = newJObject()
for k, v in acc["storage"]: for k, v in acc["storage"]:
@ -76,7 +76,7 @@ proc copyAccount(acc: JsonNode): JsonNode =
proc updateAccount(a, b: JsonNode) = proc updateAccount(a, b: JsonNode) =
a["balance"] = newJString(b["balance"].getStr) a["balance"] = newJString(b["balance"].getStr)
a["nonce"] = newJString(b["nonce"].getStr) a["nonce"] = newJString(toHex(b["nonce"].getInt))
a["code"] = newJString(b["code"].getStr) a["code"] = newJString(b["code"].getStr)
var storage = a["storage"] var storage = a["storage"]
for k, v in b["storage"]: for k, v in b["storage"]:
@ -133,7 +133,7 @@ Happy bug hunting
proc main() = proc main() =
if paramCount() == 0: if paramCount() == 0:
echo "usage: premix debug_meta_data.json" echo "usage: premix debugxxx.json"
quit(QuitFailure) quit(QuitFailure)
try: try: