From 0a6b3505f2da66e5fa998804a30c09a85bbe6bc7 Mon Sep 17 00:00:00 2001 From: andri lim Date: Thu, 10 Jan 2019 15:23:18 +0700 Subject: [PATCH] add dumper tool --- nimbus/tracer.nim | 16 +++++--------- premix/dumper.nim | 55 ++++++++++++++++++++++++++++++++++++++++++++++ premix/persist.nim | 2 +- premix/premix.nim | 6 ++--- 4 files changed, 64 insertions(+), 15 deletions(-) create mode 100644 premix/dumper.nim diff --git a/nimbus/tracer.nim b/nimbus/tracer.nim index 9f1fda735..a77a5c7ce 100644 --- a/nimbus/tracer.nim +++ b/nimbus/tracer.nim @@ -240,20 +240,14 @@ proc dumpDebuggingMetaData*(chainDB: BaseChainDB, header: BlockHeader, blockBody captureTrieDB = trieDB captureDB 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 = %{ "blockNumber": %blockNumber.toHex, - "txTraces": txTraces, - "stateDump": stateDump, - "blockTrace": blockTrace, - "receipts": receipts + "txTraces": traceTransactions(captureChainDB, header, blockBody), + "stateDump": dumpBlockState(captureChainDB, header, blockBody), + "blockTrace": traceBlock(captureChainDB, header, blockBody, {DisableState}), + "receipts": toJson(receipts) } metaData.dumpMemoryDB(memoryDB) # this is a placeholder until premix debugging tool is ready - writeFile("debug_meta_data.json", metaData.pretty()) + writeFile("debug" & $blockNumber & ".json", metaData.pretty()) diff --git a/premix/dumper.nim b/premix/dumper.nim new file mode 100644 index 000000000..083cd5e82 --- /dev/null +++ b/premix/dumper.nim @@ -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() diff --git a/premix/persist.nim b/premix/persist.nim index 925100e40..af91295d6 100644 --- a/premix/persist.nim +++ b/premix/persist.nim @@ -34,7 +34,7 @@ proc main() = # 52029 first block with receipts logs # 66407 failed transaction - var conf = getConfiguration() + let conf = getConfiguration() let db = newChainDb(conf.dataDir) let trieDB = trieDB db let chainDB = newBaseChainDB(trieDB, false) diff --git a/premix/premix.nim b/premix/premix.nim index ce9112236..587572019 100644 --- a/premix/premix.nim +++ b/premix/premix.nim @@ -67,7 +67,7 @@ proc requestPostState(thisBlock: Block): JsonNode = proc copyAccount(acc: JsonNode): JsonNode = result = newJObject() 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) var storage = newJObject() for k, v in acc["storage"]: @@ -76,7 +76,7 @@ proc copyAccount(acc: JsonNode): JsonNode = proc updateAccount(a, b: JsonNode) = 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) var storage = a["storage"] for k, v in b["storage"]: @@ -133,7 +133,7 @@ Happy bug hunting proc main() = if paramCount() == 0: - echo "usage: premix debug_meta_data.json" + echo "usage: premix debugxxx.json" quit(QuitFailure) try: