nimbus-eth1/premix/debug.nim

45 lines
1.3 KiB
Nim
Raw Normal View History

2019-01-09 08:35:02 +00:00
import
json, os, stint, eth_trie/db, byteutils, eth_common,
2019-01-12 12:49:08 +00:00
../nimbus/db/[db_chain], chronicles, ../nimbus/vm_state,
../nimbus/p2p/executor
2019-01-09 08:35:02 +00:00
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
parentNumber = blockNumber - 1
2019-01-12 12:49:08 +00:00
chainDB = newBaseChainDB(memoryDB, false)
2019-01-09 08:35:02 +00:00
parent = chainDB.getBlockHeader(parentNumber)
header = chainDB.getBlockHeader(blockNumber)
2019-01-12 12:49:08 +00:00
body = chainDB.getBlockBody(header.blockHash)
let
vmState = newBaseVMState(parent, chainDB)
validationResult = processBlock(chainDB, parent, header, body, vmState)
2019-01-09 08:35:02 +00:00
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()