reorder captureDB in traceTransaction

This commit is contained in:
andri lim 2018-12-04 08:53:21 +07:00
parent 2552d6452a
commit 8d42ad997e
1 changed files with 10 additions and 8 deletions

View File

@ -11,18 +11,19 @@ proc prefixHex(x: openArray[byte]): string =
proc traceTransaction*(db: BaseChainDB, header: BlockHeader,
body: BlockBody, txIndex: int, tracerFlags: set[TracerFlags]): JsonNode =
let parent = db.getParentHeader(header)
var stateDb = newAccountStateDB(db.db, parent.stateRoot, db.pruneTrie)
assert(body.transactions.calcTxRoot == header.txRoot)
if header.txRoot == BLANK_ROOT_HASH: return
let
parent = db.getParentHeader(header)
# we add a memory layer between backend/upper layer db
# and capture state db snapshot during transaction execution
memoryDB = newMemoryDB()
captureDB = newCaptureDB(db.db, memoryDB)
captureTrieDB = trieDB captureDB
captureChainDB = newBaseChainDB(captureTrieDB, false) # prune or not prune?
let vmState = newBaseVMState(parent, captureChainDB, tracerFlags + {TracerFlags.EnableTracing})
captureChainDB = newBaseChainDB(captureTrieDB, false) # prune or not prune?
vmState = newBaseVMState(parent, captureChainDB, tracerFlags + {TracerFlags.EnableTracing})
var stateDb = newAccountStateDB(captureTrieDB, parent.stateRoot, db.pruneTrie)
if header.txRoot == BLANK_ROOT_HASH: return
assert(body.transactions.calcTxRoot == header.txRoot)
assert(body.transactions.len != 0)
var gasUsed: GasInt
@ -38,6 +39,7 @@ proc traceTransaction*(db: BaseChainDB, header: BlockHeader,
result = vmState.getTracingResult()
result["gas"] = %gasUsed
# now we dump captured state db
var n = newJObject()
for k, v in pairsInMemoryDB(memoryDB):
n[k.prefixHex] = %v.prefixHex