tracing opcode return value

This commit is contained in:
andri lim 2018-12-04 15:53:03 +07:00
parent 7a3ddfec87
commit 572de41507
5 changed files with 15 additions and 6 deletions

View File

@ -39,6 +39,11 @@ proc traceTransaction*(db: BaseChainDB, header: BlockHeader,
result = vmState.getTracingResult()
result["gas"] = %gasUsed
const returnValue = "returnValue"
let j = result["structLogs"].elems[^1]
if j.hasKey(returnValue):
result[returnValue] = j[returnValue]
# now we dump captured state db
if TracerFlags.DisableState notin tracerFlags:
var n = newJObject()

View File

@ -59,6 +59,7 @@ func output*(c: BaseComputation): seq[byte] =
func `output=`*(c: var BaseComputation, value: openarray[byte]) =
c.rawOutput = @value
c.lastOpCodeHasRetVal = true
proc outputHex*(c: BaseComputation): string =
if c.shouldEraseReturnData:

View File

@ -194,6 +194,7 @@ proc opTableToCaseStmt(opTable: array[Op, NimNode], computation: NimNode): NimNo
if `computation`.tracingEnabled:
`computation`.traceOpCodeStarted($`asOp`)
`computation`.gasMeter.consumeGas(`computation`.gasCosts[`asOp`].cost, reason = $`asOp`)
`computation`.lastOpCodeHasRetVal = false
`opImpl`(`computation`)
if `computation`.tracingEnabled:
`computation`.traceOpCodeEnded()
@ -202,6 +203,7 @@ proc opTableToCaseStmt(opTable: array[Op, NimNode], computation: NimNode): NimNo
quote do:
if `computation`.tracingEnabled:
`computation`.traceOpCodeStarted($`asOp`)
`computation`.lastOpCodeHasRetVal = false
`opImpl`(`computation`)
if `computation`.tracingEnabled:
`computation`.traceOpCodeEnded()

View File

@ -1,10 +1,7 @@
import
json, strutils,
eth_common, stint, byteutils,
../vm_types, memory, stack,
../db/[db_chain, state_db],
eth_trie/hexary, ./message,
ranges/typedranges
json, strutils, nimcrypto, eth_common, stint,
../vm_types, memory, stack, ../db/[db_chain, state_db],
eth_trie/hexary, ./message, ranges/typedranges
proc initTracer*(tracer: var TransactionTracer, flags: set[TracerFlags] = {}) =
tracer.trace = newJObject()
@ -60,6 +57,9 @@ proc traceOpCodeEnded*(tracer: var TransactionTracer, c: BaseComputation) =
j["gasCost"] = %(tracer.gasRemaining - c.gasMeter.gasRemaining)
if c.lastOpCodeHasRetVal:
j["returnValue"] = %("0x" & toHex(c.rawOutput, true))
proc traceError*(tracer: var TransactionTracer, c: BaseComputation) =
let j = tracer.trace["structLogs"].elems[^1]

View File

@ -59,6 +59,7 @@ type
opcodes*: Table[Op, proc(computation: var BaseComputation){.nimcall.}]
gasCosts*: GasCosts # TODO - will be hidden at a lower layer
opCodeExec*: OpcodeExecutor
lastOpCodeHasRetVal*: bool
Error* = ref object
info*: string