remove lastOpCodeHasRetVal, make it simpler

This commit is contained in:
andri lim 2018-12-11 16:23:15 +07:00 committed by zah
parent 26ee2fce26
commit b159b5c945
4 changed files with 14 additions and 17 deletions

View File

@ -63,7 +63,6 @@ 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:
@ -295,11 +294,11 @@ proc getGasRemaining*(c: BaseComputation): GasInt =
proc tracingEnabled*(c: BaseComputation): bool =
c.vmState.tracingEnabled
proc traceOpCodeStarted*(c: BaseComputation, op: string) =
traceOpCodeStarted(c.vmState.tracer, c, op)
proc traceOpCodeStarted*(c: BaseComputation, op: Op) =
c.vmState.tracer.traceOpCodeStarted(c, op)
proc traceOpCodeEnded*(c: BaseComputation) =
c.vmState.tracer.traceOpCodeEnded(c)
proc traceOpCodeEnded*(c: BaseComputation, op: Op) =
c.vmState.tracer.traceOpCodeEnded(c, op)
proc traceError*(c: BaseComputation) =
c.vmState.tracer.traceError(c)

View File

@ -197,21 +197,19 @@ proc opTableToCaseStmt(opTable: array[Op, NimNode], computation: NimNode): NimNo
if BaseGasCosts[op].kind == GckFixed:
quote do:
if `computation`.tracingEnabled:
`computation`.traceOpCodeStarted($`asOp`)
`computation`.traceOpCodeStarted(`asOp`)
`computation`.gasMeter.consumeGas(`computation`.gasCosts[`asOp`].cost, reason = $`asOp`)
`computation`.lastOpCodeHasRetVal = false
`opImpl`(`computation`)
if `computation`.tracingEnabled:
`computation`.traceOpCodeEnded()
`computation`.traceOpCodeEnded(`asOp`)
`instr` = `computation`.code.next()
else:
quote do:
if `computation`.tracingEnabled:
`computation`.traceOpCodeStarted($`asOp`)
`computation`.lastOpCodeHasRetVal = false
`computation`.traceOpCodeStarted(`asOp`)
`opImpl`(`computation`)
if `computation`.tracingEnabled:
`computation`.traceOpCodeEnded()
`computation`.traceOpCodeEnded(`asOp`)
when `asOp` in {Return, Revert, SelfDestruct}:
break
else:

View File

@ -2,7 +2,8 @@ import
json, strutils,
chronicles, nimcrypto, eth_common, stint,
../vm_types, memory, stack, ../db/[db_chain, state_db],
eth_trie/hexary, ./message, ranges/typedranges
eth_trie/hexary, ./message, ranges/typedranges,
./interpreter/opcode_values
logScope:
topics = "vm opcode"
@ -18,14 +19,14 @@ proc initTracer*(tracer: var TransactionTracer, flags: set[TracerFlags] = {}) =
tracer.trace["structLogs"] = newJArray()
tracer.flags = flags
proc traceOpCodeStarted*(tracer: var TransactionTracer, c: BaseComputation, op: string) =
proc traceOpCodeStarted*(tracer: var TransactionTracer, c: BaseComputation, op: Op) =
if unlikely tracer.trace.isNil:
tracer.initTracer()
let j = newJObject()
tracer.trace["structLogs"].add(j)
j["op"] = %op.toUpperAscii
j["op"] = %(($op).toUpperAscii)
j["pc"] = %(c.code.pc - 1)
j["depth"] = %1 # stub
j["gas"] = %c.gasMeter.gasRemaining
@ -47,7 +48,7 @@ proc traceOpCodeStarted*(tracer: var TransactionTracer, c: BaseComputation, op:
mem.add(%c.memory.bytes.toOpenArray(i * chunkLen, (i + 1) * chunkLen - 1).toHex())
j["memory"] = mem
proc traceOpCodeEnded*(tracer: var TransactionTracer, c: BaseComputation) =
proc traceOpCodeEnded*(tracer: var TransactionTracer, c: BaseComputation, op: Op) =
let j = tracer.trace["structLogs"].elems[^1]
# TODO: figure out how to get storage
@ -61,7 +62,7 @@ proc traceOpCodeEnded*(tracer: var TransactionTracer, c: BaseComputation) =
j["gasCost"] = %(tracer.gasRemaining - c.gasMeter.gasRemaining)
if c.lastOpCodeHasRetVal:
if op in {Return, Revert}:
let returnValue = %("0x" & toHex(c.rawOutput, true))
j["returnValue"] = returnValue
tracer.trace["returnValue"] = returnValue

View File

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