Skip to content

Commit ef0d25d

Browse files
authored
Implement debug_trace* related APIs (#4690)
1 parent d420d5d commit ef0d25d

File tree

19 files changed

+559
-310
lines changed

19 files changed

+559
-310
lines changed

Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ ALL_PKGS := $(shell go list ./... )
3333
PKGS := $(shell go list ./... | grep -v /test/ )
3434
ROOT_PKG := "github.com/iotexproject/iotex-core"
3535
TEST_PKGS := $(shell go list ./... | grep -E -v 'pb$|testdata|mock')
36+
TEST_PKGS_NO_E2E := $(shell go list ./... | grep -E -v 'pb$|testdata|mock|e2etest')
37+
E2E_TEST_PKGS := $(shell go list ./... | grep e2etest)
3638

3739
# Docker parameters
3840
DOCKERCMD=docker
@@ -124,7 +126,19 @@ lint-rich:
124126

125127
.PHONY: test
126128
test: fmt
127-
@$(GOTEST) -gcflags="all=-N -l" -short -race ${TEST_PKGS}
129+
@echo "Running unit tests with race detector..."
130+
@$(GOTEST) -gcflags="all=-N -l" -short -race ${TEST_PKGS_NO_E2E}
131+
@echo "Running e2e tests without race detector..."
132+
@$(GOTEST) -gcflags="all=-N -l" -short ${E2E_TEST_PKGS}
133+
134+
.PHONY: test-unit
135+
test-unit: fmt
136+
@$(GOTEST) -gcflags="all=-N -l" -short -race ${TEST_PKGS_NO_E2E}
137+
138+
.PHONY: test-e2e
139+
test-e2e: fmt
140+
@echo "Running e2e tests without race detector..."
141+
@$(GOTEST) -gcflags="all=-N -l" -short ${E2E_TEST_PKGS}
128142

129143
.PHONY: test-rich
130144
test-rich:

action/protocol/context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ type (
7878
ExcessBlobGas uint64
7979
// SkipSidecarValidation dictates to validate sidecar (for blob tx) or not
8080
SkipSidecarValidation bool
81+
// Simulate is used for read-only APIs
82+
Simulate bool
8183
}
8284

8385
// ActionCtx provides action auxiliary information.

action/protocol/execution/evm/context.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,26 @@ package evm
33
import (
44
"context"
55

6+
"github.com/iotexproject/iotex-core/v2/action"
67
"github.com/iotexproject/iotex-core/v2/action/protocol"
78
"github.com/iotexproject/iotex-core/v2/pkg/log"
89
)
910

1011
type (
1112
helperContextKey struct{}
1213

14+
tracerContextKey struct{}
15+
1316
// HelperContext is the context for EVM helper
1417
HelperContext struct {
1518
GetBlockHash GetBlockHash
1619
GetBlockTime GetBlockTime
1720
DepositGasFunc protocol.DepositGas
1821
}
22+
// TracerContext is the context for EVM tracer
23+
TracerContext struct {
24+
CaptureTx func([]byte, *action.Receipt)
25+
}
1926
)
2027

2128
// WithHelperCtx returns a new context with helper context
@@ -31,3 +38,14 @@ func mustGetHelperCtx(ctx context.Context) HelperContext {
3138
}
3239
return hc
3340
}
41+
42+
// WithTracerCtx returns a new context with tracer context
43+
func WithTracerCtx(ctx context.Context, tctx TracerContext) context.Context {
44+
return context.WithValue(ctx, tracerContextKey{}, tctx)
45+
}
46+
47+
// GetTracerCtx returns the tracer context from the context
48+
func GetTracerCtx(ctx context.Context) (TracerContext, bool) {
49+
tc, ok := ctx.Value(tracerContextKey{}).(TracerContext)
50+
return tc, ok
51+
}

action/protocol/execution/evm/evm.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ func ExecuteContract(
332332
receipt.SetExecutionRevertMsg(revertMsg)
333333
}
334334
log.S().Debugf("Retval: %x, Receipt: %+v, %v", retval, receipt, err)
335+
if tCtx, ok := GetTracerCtx(ctx); ok && tCtx.CaptureTx != nil {
336+
tCtx.CaptureTx(retval, receipt)
337+
}
335338
return retval, receipt, nil
336339
}
337340

@@ -558,6 +561,12 @@ func executeInEVM(ctx context.Context, evmParams *Params, stateDB stateDB) ([]by
558561
refund uint64
559562
amount = uint256.MustFromBig(evmParams.amount)
560563
)
564+
if evm.Config.Tracer != nil {
565+
evm.Config.Tracer.CaptureTxStart(remainingGas)
566+
defer func() {
567+
evm.Config.Tracer.CaptureTxEnd(remainingGas)
568+
}()
569+
}
561570
if evmParams.contract == nil {
562571
// create contract
563572
var evmContractAddress common.Address

0 commit comments

Comments
 (0)