add debug tool

This commit is contained in:
andri lim 2019-01-09 15:35:02 +07:00 committed by zah
parent 49bb7bb6e4
commit 729686ff57
3 changed files with 51 additions and 2 deletions

View File

@ -45,11 +45,13 @@ method persistBlocks*(c: Chain, headers: openarray[BlockHeader], bodies: openarr
let vmState = newBaseVMState(head, c.db)
let validationResult = processBlock(c.db, head, headers[i], bodies[i], vmState)
when not defined(release):
when not defined(release) and not defined(debugging_tool):
if validationResult == ValidationResult.Error:
dumpDebuggingMetaData(c.db, headers[i], bodies[i], vmState.receipts)
assert(validationResult == ValidationResult.OK)
if validationResult != ValidationResult.OK:
result = validationResult
return
discard c.db.persistHeaderToDb(headers[i])
if c.db.getCanonicalHead().blockHash != headers[i].blockHash:

46
premix/debug.nim Normal file
View File

@ -0,0 +1,46 @@
import
json, os, stint, eth_trie/db, byteutils, eth_common,
../nimbus/db/[db_chain], ../nimbus/p2p/chain,
chronicles
proc prepareBlockEnv(node: JsonNode, memoryDB: TrieDatabaseRef) =
let state = node["state"]
for k, v in state:
let key = hexToSeqByte(k)
let value = hexToSeqByte(v.getStr())
memoryDB.put(key, value)
proc executeBlock(memoryDB: TrieDatabaseRef, blockNumber: Uint256) =
let
chainDB = newBaseChainDB(memoryDB, false)
parentNumber = blockNumber - 1
parent = chainDB.getBlockHeader(parentNumber)
header = chainDB.getBlockHeader(blockNumber)
headerHash = header.blockHash
body = chainDB.getBlockBody(headerHash)
chain = newChain(chainDB)
headers = @[header]
bodies = @[body]
chainDB.setHead(parent, true)
let validationResult = chain.persistBlocks(headers, bodies)
if validationResult != ValidationResult.OK:
error "block validation error", validationResult
else:
info "block validation success", validationResult, blockNumber
proc main() =
if paramCount() == 0:
echo "usage: debug blockxxx.json"
quit(QuitFailure)
let
blockEnv = json.parseFile(paramStr(1))
memoryDB = newMemoryDB()
blockNumber = UInt256.fromHex(blockEnv["blockNumber"].getStr())
prepareBlockEnv(blockEnv, memoryDB)
executeBlock(memoryDB, blockNumber)
main()

1
premix/debug.nim.cfg Normal file
View File

@ -0,0 +1 @@
-d:debugging_tool