Skip to content

Commit 5065797

Browse files
millkendustinxie
andcommitted
[gRPC] trace transaction struct logs (#2970)
* add debug transaction method * debug transaction * fix return * fix golint * update context func name * fix comments * update gRPC server * fix comments * fix comments * fix mock version * fix mock * fix test * fix comments * revert mock * update mock * update grpcserver.go * update iotex-proto version Co-authored-by: dustinxie <dahuaxie@gmail.com>
1 parent 95ef796 commit 5065797

File tree

31 files changed

+2382
-2164
lines changed

31 files changed

+2382
-2164
lines changed

action/protocol/context.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"math/big"
1212
"time"
1313

14+
"github.com/ethereum/go-ethereum/core/vm"
1415
"github.com/iotexproject/go-pkgs/hash"
1516
"github.com/iotexproject/iotex-address/address"
1617
"github.com/iotexproject/iotex-core/blockchain/genesis"
@@ -30,6 +31,8 @@ type (
3031

3132
featureWithHeightContextKey struct{}
3233

34+
vmConfigContextKey struct{}
35+
3336
// TipInfo contains the tip block information
3437
TipInfo struct {
3538
Height uint64
@@ -284,3 +287,14 @@ func MustGetFeatureWithHeightCtx(ctx context.Context) FeatureWithHeightCtx {
284287
}
285288
return fc
286289
}
290+
291+
// WithVMConfigCtx adds vm config to context
292+
func WithVMConfigCtx(ctx context.Context, vmConfig vm.Config) context.Context {
293+
return context.WithValue(ctx, vmConfigContextKey{}, vmConfig)
294+
}
295+
296+
// GetVMConfigCtx returns the vm config from context
297+
func GetVMConfigCtx(ctx context.Context) (vm.Config, bool) {
298+
cfg, ok := ctx.Value(vmConfigContextKey{}).(vm.Config)
299+
return cfg, ok
300+
}

action/protocol/context_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"testing"
1212
"time"
1313

14+
"github.com/ethereum/go-ethereum/core/vm"
1415
"github.com/iotexproject/go-pkgs/hash"
1516
"github.com/iotexproject/iotex-address/address"
1617
"github.com/stretchr/testify/require"
@@ -157,3 +158,17 @@ func TestMustGetActionCtx(t *testing.T) {
157158
// Case II: Panic
158159
require.Panics(func() { MustGetActionCtx(context.Background()) }, "Miss action context")
159160
}
161+
162+
func TestWithVMConfigCtx(t *testing.T) {
163+
require := require.New(t)
164+
require.NotNil(WithVMConfigCtx(context.Background(), vm.Config{Debug: true}))
165+
}
166+
167+
func TestGetVMConfigCtx(t *testing.T) {
168+
require := require.New(t)
169+
ctx := WithVMConfigCtx(context.Background(), vm.Config{Debug: true})
170+
require.NotNil(ctx)
171+
ret, ok := GetVMConfigCtx(ctx)
172+
require.True(ok)
173+
require.True(ret.Debug)
174+
}

action/protocol/execution/evm/evm.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func ExecuteContract(
191191
if err != nil {
192192
return nil, nil, err
193193
}
194-
retval, depositGas, remainingGas, contractAddress, statusCode, err := executeInEVM(ps, stateDB, g.Blockchain, blkCtx.GasLimit, blkCtx.BlockHeight)
194+
retval, depositGas, remainingGas, contractAddress, statusCode, err := executeInEVM(ctx, ps, stateDB, g.Blockchain, blkCtx.GasLimit, blkCtx.BlockHeight)
195195
if err != nil {
196196
return nil, nil, err
197197
}
@@ -313,13 +313,16 @@ func getChainConfig(g genesis.Blockchain, height uint64) *params.ChainConfig {
313313
}
314314

315315
//Error in executeInEVM is a consensus issue
316-
func executeInEVM(evmParams *Params, stateDB *StateDBAdapter, g genesis.Blockchain, gasLimit uint64, blockHeight uint64) ([]byte, uint64, uint64, string, uint64, error) {
316+
func executeInEVM(ctx context.Context, evmParams *Params, stateDB *StateDBAdapter, g genesis.Blockchain, gasLimit uint64, blockHeight uint64) ([]byte, uint64, uint64, string, uint64, error) {
317317
remainingGas := evmParams.gas
318318
if err := securityDeposit(evmParams, stateDB, gasLimit); err != nil {
319319
log.L().Warn("unexpected error: not enough security deposit", zap.Error(err))
320320
return nil, 0, 0, action.EmptyAddress, uint64(iotextypes.ReceiptStatus_Failure), err
321321
}
322322
var config vm.Config
323+
if vmCfg, ok := protocol.GetVMConfigCtx(ctx); ok {
324+
config = vmCfg
325+
}
323326
chainConfig := getChainConfig(g, blockHeight)
324327
evm := vm.NewEVM(evmParams.context, evmParams.txCtx, stateDB, chainConfig, config)
325328
intriGas, err := intrinsicGas(evmParams.data)

0 commit comments

Comments
 (0)