diff options
Diffstat (limited to 'dex/api_tracer.go')
-rw-r--r-- | dex/api_tracer.go | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/dex/api_tracer.go b/dex/api_tracer.go index 70f482bca..b8f4e46da 100644 --- a/dex/api_tracer.go +++ b/dex/api_tracer.go @@ -203,7 +203,7 @@ func (api *PrivateDebugAPI) traceChain(ctx context.Context, start, end *types.Bl // Trace all the transactions contained within for i, tx := range task.block.Transactions() { msg, _ := tx.AsMessage(signer) - vmctx := core.NewEVMContext(msg, task.block.Header(), api.dex.blockchain, nil) + vmctx := core.NewVMContext(msg, task.block.Header(), api.dex.blockchain, nil) res, err := api.traceTx(ctx, msg, vmctx, task.statedb, config) if err != nil { @@ -285,7 +285,10 @@ func (api *PrivateDebugAPI) traceChain(ctx context.Context, start, end *types.Bl traced += uint64(len(txs)) } // Generate the next state snapshot fast without tracing - _, _, _, err := api.dex.blockchain.Processor().Process(block, statedb, evm.Config{}) + + vmConfig := [vm.NUMS]interface{}{} + vmConfig[vm.EVM] = evm.Config{} + _, _, _, err := api.dex.blockchain.Processor().Process(block, statedb, vmConfig) if err != nil { failed = err break @@ -474,7 +477,7 @@ func (api *PrivateDebugAPI) traceBlock(ctx context.Context, block *types.Block, // Fetch and execute the next transaction trace tasks for task := range jobs { msg, _ := txs[task.index].AsMessage(signer) - vmctx := core.NewEVMContext(msg, block.Header(), api.dex.blockchain, nil) + vmctx := core.NewVMContext(msg, block.Header(), api.dex.blockchain, nil) res, err := api.traceTx(ctx, msg, vmctx, task.statedb, config) if err != nil { @@ -493,10 +496,12 @@ func (api *PrivateDebugAPI) traceBlock(ctx context.Context, block *types.Block, // Generate the next state snapshot fast without tracing msg, _ := tx.AsMessage(signer) - vmctx := core.NewEVMContext(msg, block.Header(), api.dex.blockchain, nil) + vmctx := core.NewVMContext(msg, block.Header(), api.dex.blockchain, nil) - vmenv := evm.NewEVM(vmctx, statedb, api.config, evm.Config{}) - if _, _, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())); err != nil { + vmConfig := [vm.NUMS]interface{}{} + vmConfig[vm.EVM] = evm.Config{} + pack := vm.NewExecPack(vmctx, statedb, api.config, vmConfig) + if _, _, _, err := core.ApplyMessage(&pack, msg, new(core.GasPool).AddGas(msg.Gas())); err != nil { failed = err break } @@ -567,7 +572,7 @@ func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block // Prepare the trasaction for un-traced execution var ( msg, _ = tx.AsMessage(signer) - vmctx = core.NewEVMContext(msg, block.Header(), api.dex.blockchain, nil) + vmctx = core.NewVMContext(msg, block.Header(), api.dex.blockchain, nil) vmConf evm.Config dump *os.File @@ -592,8 +597,10 @@ func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block } } // Execute the transaction and flush any traces to disk - vmenv := evm.NewEVM(vmctx, statedb, api.config, vmConf) - _, _, _, err = core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())) + vmConfigs := [vm.NUMS]interface{}{} + vmConfigs[vm.EVM] = vmConf + pack := vm.NewExecPack(vmctx, statedb, api.config, vmConfigs) + _, _, _, err = core.ApplyMessage(&pack, msg, new(core.GasPool).AddGas(msg.Gas())) if dump != nil { dump.Close() @@ -604,7 +611,7 @@ func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block } // Finalize the state so any modifications are written to the trie // Only delete empty objects if EIP158/161 (a.k.a Spurious Dragon) is in effect - statedb.Finalise(vmenv.ChainConfig().IsEIP158(block.Number())) + statedb.Finalise(pack.ChainConfig.IsEIP158(block.Number())) // If we've traced the transaction we were looking for, abort if tx.Hash() == txHash { @@ -660,7 +667,10 @@ func (api *PrivateDebugAPI) computeStateDB(block *types.Block, reexec uint64) (* if block = api.dex.blockchain.GetBlockByNumber(block.NumberU64() + 1); block == nil { return nil, fmt.Errorf("block #%d not found", block.NumberU64()+1) } - _, _, _, err := api.dex.blockchain.Processor().Process(block, statedb, evm.Config{}) + + vmConfig := [vm.NUMS]interface{}{} + vmConfig[vm.EVM] = evm.Config{} + _, _, _, err := api.dex.blockchain.Processor().Process(block, statedb, vmConfig) if err != nil { return nil, fmt.Errorf("processing block %d failed: %v", block.NumberU64(), err) } @@ -706,7 +716,7 @@ func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, hash common.Ha // traceTx configures a new tracer according to the provided configuration, and // executes the given message in the provided environment. The return value will // be tracer dependent. -func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, vmctx vm.Context, statedb *state.StateDB, config *TraceConfig) (interface{}, error) { +func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, vmctx *vm.Context, statedb *state.StateDB, config *TraceConfig) (interface{}, error) { // Assemble the structured logger or the JavaScript tracer var ( tracer evm.Tracer @@ -740,9 +750,11 @@ func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, v tracer = evm.NewStructLogger(config.LogConfig) } // Run the transaction with tracing enabled. - vmenv := evm.NewEVM(vmctx, statedb, api.config, evm.Config{Debug: true, Tracer: tracer}) + vmConfig := [vm.NUMS]interface{}{} + vmConfig[vm.EVM] = evm.Config{Tracer: tracer} + pack := vm.NewExecPack(vmctx, statedb, api.config, vmConfig) - ret, gas, failed, err := core.ApplyMessage(vmenv, message, new(core.GasPool).AddGas(message.Gas())) + ret, gas, failed, err := core.ApplyMessage(&pack, message, new(core.GasPool).AddGas(message.Gas())) if err != nil { return nil, fmt.Errorf("tracing failed: %v", err) } @@ -765,19 +777,19 @@ func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, v } // computeTxEnv returns the execution environment of a certain transaction. -func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, reexec uint64) (core.Message, vm.Context, *state.StateDB, error) { +func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, reexec uint64) (core.Message, *vm.Context, *state.StateDB, error) { // Create the parent state database block := api.dex.blockchain.GetBlockByHash(blockHash) if block == nil { - return nil, vm.Context{}, nil, fmt.Errorf("block %#x not found", blockHash) + return nil, &vm.Context{}, nil, fmt.Errorf("block %#x not found", blockHash) } parent := api.dex.blockchain.GetBlock(block.ParentHash(), block.NumberU64()-1) if parent == nil { - return nil, vm.Context{}, nil, fmt.Errorf("parent %#x not found", block.ParentHash()) + return nil, &vm.Context{}, nil, fmt.Errorf("parent %#x not found", block.ParentHash()) } statedb, err := api.computeStateDB(parent, reexec) if err != nil { - return nil, vm.Context{}, nil, err + return nil, &vm.Context{}, nil, err } // Recompute transactions up to the target index. signer := types.MakeSigner(api.config, block.Number()) @@ -785,17 +797,19 @@ func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, ree for idx, tx := range block.Transactions() { // Assemble the transaction call message and return if the requested offset msg, _ := tx.AsMessage(signer) - context := core.NewEVMContext(msg, block.Header(), api.dex.blockchain, nil) + context := core.NewVMContext(msg, block.Header(), api.dex.blockchain, nil) if idx == txIndex { return msg, context, statedb, nil } // Not yet the searched for transaction, execute on top of the current state - vmenv := evm.NewEVM(context, statedb, api.config, evm.Config{}) - if _, _, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas())); err != nil { - return nil, vm.Context{}, nil, fmt.Errorf("tx %#x failed: %v", tx.Hash(), err) + vmConfig := [vm.NUMS]interface{}{} + vmConfig[vm.EVM] = evm.Config{} + pack := vm.NewExecPack(context, statedb, api.config, vmConfig) + if _, _, _, err := core.ApplyMessage(&pack, msg, new(core.GasPool).AddGas(tx.Gas())); err != nil { + return nil, &vm.Context{}, nil, fmt.Errorf("tx %#x failed: %v", tx.Hash(), err) } // Ensure any modifications are committed to the state statedb.Finalise(true) } - return nil, vm.Context{}, nil, fmt.Errorf("transaction index %d out of range for block %#x", txIndex, blockHash) + return nil, &vm.Context{}, nil, fmt.Errorf("transaction index %d out of range for block %#x", txIndex, blockHash) } |