Skip to content

Commit

Permalink
EVM-778 Debug Transaction endpoint - use one structure for logs (#1817)
Browse files Browse the repository at this point in the history
  • Loading branch information
igorcrevar authored Aug 16, 2023
1 parent 6862b7d commit b302fdb
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 383 deletions.
36 changes: 5 additions & 31 deletions state/runtime/evm/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,31 +236,31 @@ func (c *state) Run() ([]byte, error) {
inst := dispatchTable[op]
if inst.inst == nil {
c.exit(errOpCodeNotFound)
c.captureExecutionError(op.String(), c.ip, gasCopy, 0)
c.captureExecution(op.String(), uint64(c.ip), gasCopy, 0)

break
}

// check if the depth of the stack is enough for the instruction
if c.sp < inst.stack {
c.exit(&runtime.StackUnderflowError{StackLen: c.sp, Required: inst.stack})
c.captureExecutionError(op.String(), c.ip, gasCopy, inst.gas)
c.captureExecution(op.String(), uint64(c.ip), gasCopy, inst.gas)

break
}

// consume the gas of the instruction
if !c.consumeGas(inst.gas) {
c.exit(errOutOfGas)
c.captureExecutionError(op.String(), c.ip, gasCopy, inst.gas)
c.captureExecution(op.String(), uint64(c.ip), gasCopy, inst.gas)

break
}

// execute the instruction
inst.inst(c)

c.captureSuccessfulExecution(op.String(), ipCopy, gasCopy, gasCopy-c.gas)
c.captureExecution(op.String(), ipCopy, gasCopy, gasCopy-c.gas)

// check if stack size exceeds the max size
if c.sp > stackSize {
Expand Down Expand Up @@ -390,14 +390,13 @@ func (c *state) captureState(opCode int) {
)
}

func (c *state) captureSuccessfulExecution(
func (c *state) captureExecution(
opCode string,
ip uint64,
gas uint64,
consumedGas uint64,
) {
tracer := c.host.GetTracer()

if tracer == nil {
return
}
Expand All @@ -414,28 +413,3 @@ func (c *state) captureSuccessfulExecution(
c.host,
)
}

func (c *state) captureExecutionError(
opCode string,
ip int,
gas uint64,
consumedGas uint64,
) {
tracer := c.host.GetTracer()

if tracer == nil {
return
}

tracer.ExecuteState(
c.msg.Address,
uint64(ip),
opCode,
gas,
consumedGas,
c.returnData,
c.msg.Depth,
c.err,
c.host,
)
}
Loading

0 comments on commit b302fdb

Please sign in to comment.