Skip to content

Commit 2dac2d9

Browse files
holiman0xTylerHolmess1na
authored andcommitted
all: remove debug-field from vm config (ethereum#27048)
This PR removes the Debug field from vmconfig, making it so that if a tracer is set, debug=true is implied. --------- Co-authored-by: 0xTylerHolmes <[email protected]> Co-authored-by: Sina Mahmoodi <[email protected]>
1 parent d1bcd84 commit 2dac2d9

File tree

20 files changed

+32
-45
lines changed

20 files changed

+32
-45
lines changed

cmd/evm/internal/t8ntool/execution.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
174174
return nil, nil, err
175175
}
176176
vmConfig.Tracer = tracer
177-
vmConfig.Debug = (tracer != nil)
178177
statedb.SetTxContext(tx.Hash(), txIndex)
179178

180179
var (

cmd/evm/internal/t8ntool/transition.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ func Transition(ctx *cli.Context) error {
180180

181181
vmConfig := vm.Config{
182182
Tracer: tracer,
183-
Debug: (tracer != nil),
184183
}
185184
// Construct the chainconfig
186185
var chainConfig *params.ChainConfig

cmd/evm/runner.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ func runCmd(ctx *cli.Context) error {
218218
BlockNumber: new(big.Int).SetUint64(genesisConfig.Number),
219219
EVMConfig: vm.Config{
220220
Tracer: tracer,
221-
Debug: ctx.Bool(DebugFlag.Name) || ctx.Bool(MachineFlag.Name),
222221
},
223222
}
224223

cmd/evm/staterunner.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ func stateTestCmd(ctx *cli.Context) error {
9292
// Iterate over all the tests, run them and aggregate the results
9393
cfg := vm.Config{
9494
Tracer: tracer,
95-
Debug: ctx.Bool(DebugFlag.Name) || ctx.Bool(MachineFlag.Name),
9695
}
9796
results := make([]StatetestResult, 0, len(tests))
9897
for key, test := range tests {

core/blockchain.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
233233
if cacheConfig == nil {
234234
cacheConfig = defaultCacheConfig
235235
}
236-
237236
// Open trie database with provided config
238237
triedb := trie.NewDatabaseWithConfig(db, &trie.Config{
239238
Cache: cacheConfig.TrieCleanLimit,

core/blockchain_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3024,7 +3024,6 @@ func TestDeleteRecreateSlots(t *testing.T) {
30243024
})
30253025
// Import the canonical chain
30263026
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, engine, vm.Config{
3027-
Debug: true,
30283027
Tracer: logger.NewJSONLogger(nil, os.Stdout),
30293028
}, nil, nil)
30303029
if err != nil {
@@ -3102,7 +3101,6 @@ func TestDeleteRecreateAccount(t *testing.T) {
31023101
})
31033102
// Import the canonical chain
31043103
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, engine, vm.Config{
3105-
Debug: true,
31063104
Tracer: logger.NewJSONLogger(nil, os.Stdout),
31073105
}, nil, nil)
31083106
if err != nil {

core/state_transition.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,10 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
324324
return nil, err
325325
}
326326

327-
if st.evm.Config.Debug {
328-
st.evm.Config.Tracer.CaptureTxStart(st.initialGas)
327+
if tracer := st.evm.Config.Tracer; tracer != nil {
328+
tracer.CaptureTxStart(st.initialGas)
329329
defer func() {
330-
st.evm.Config.Tracer.CaptureTxEnd(st.gasRemaining)
330+
tracer.CaptureTxEnd(st.gasRemaining)
331331
}()
332332
}
333333

core/vm/evm.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,12 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
179179
}
180180
snapshot := evm.StateDB.Snapshot()
181181
p, isPrecompile := evm.Precompile(addr)
182+
debug := evm.Config.Tracer != nil
182183

183184
if !evm.StateDB.Exist(addr) {
184185
if !isPrecompile && evm.chainRules.IsEIP158 && value.Sign() == 0 {
185186
// Calling a non existing account, don't do anything, but ping the tracer
186-
if evm.Config.Debug {
187+
if debug {
187188
if evm.depth == 0 {
188189
evm.Config.Tracer.CaptureStart(evm, caller.Address(), addr, false, input, gas, value)
189190
evm.Config.Tracer.CaptureEnd(ret, 0, nil)
@@ -199,7 +200,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
199200
evm.Context.Transfer(evm.StateDB, caller.Address(), addr, value)
200201

201202
// Capture the tracer start/end events in debug mode
202-
if evm.Config.Debug {
203+
if debug {
203204
if evm.depth == 0 {
204205
evm.Config.Tracer.CaptureStart(evm, caller.Address(), addr, false, input, gas, value)
205206
defer func(startGas uint64) { // Lazy evaluation of the parameters
@@ -270,7 +271,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
270271
snapshot := evm.StateDB.Snapshot()
271272

272273
// Invoke tracer hooks that signal entering/exiting a call frame
273-
if evm.Config.Debug {
274+
if evm.Config.Tracer != nil {
274275
evm.Config.Tracer.CaptureEnter(CALLCODE, caller.Address(), addr, input, gas, value)
275276
defer func(startGas uint64) {
276277
evm.Config.Tracer.CaptureExit(ret, startGas-gas, err)
@@ -311,7 +312,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
311312
snapshot := evm.StateDB.Snapshot()
312313

313314
// Invoke tracer hooks that signal entering/exiting a call frame
314-
if evm.Config.Debug {
315+
if evm.Config.Tracer != nil {
315316
// NOTE: caller must, at all times be a contract. It should never happen
316317
// that caller is something other than a Contract.
317318
parent := caller.(*Contract)
@@ -365,7 +366,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
365366
evm.StateDB.AddBalance(addr, big0)
366367

367368
// Invoke tracer hooks that signal entering/exiting a call frame
368-
if evm.Config.Debug {
369+
if evm.Config.Tracer != nil {
369370
evm.Config.Tracer.CaptureEnter(STATICCALL, caller.Address(), addr, input, gas, nil)
370371
defer func(startGas uint64) {
371372
evm.Config.Tracer.CaptureExit(ret, startGas-gas, err)
@@ -449,7 +450,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
449450
contract := NewContract(caller, AccountRef(address), value, gas)
450451
contract.SetCodeOptionalHash(&address, codeAndHash)
451452

452-
if evm.Config.Debug {
453+
if evm.Config.Tracer != nil {
453454
if evm.depth == 0 {
454455
evm.Config.Tracer.CaptureStart(evm, caller.Address(), address, true, codeAndHash.code, gas, value)
455456
} else {
@@ -492,7 +493,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
492493
}
493494
}
494495

495-
if evm.Config.Debug {
496+
if evm.Config.Tracer != nil {
496497
if evm.depth == 0 {
497498
evm.Config.Tracer.CaptureEnd(ret, gas-contract.Gas, err)
498499
} else {

core/vm/instructions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,9 @@ func opSelfdestruct(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext
822822
balance := interpreter.evm.StateDB.GetBalance(scope.Contract.Address())
823823
interpreter.evm.StateDB.AddBalance(beneficiary.Bytes20(), balance)
824824
interpreter.evm.StateDB.Suicide(scope.Contract.Address())
825-
if interpreter.evm.Config.Debug {
826-
interpreter.evm.Config.Tracer.CaptureEnter(SELFDESTRUCT, scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance)
827-
interpreter.evm.Config.Tracer.CaptureExit([]byte{}, 0, nil)
825+
if tracer := interpreter.evm.Config.Tracer; tracer != nil {
826+
tracer.CaptureEnter(SELFDESTRUCT, scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance)
827+
tracer.CaptureExit([]byte{}, 0, nil)
828828
}
829829
return nil, errStopToken
830830
}

core/vm/interpreter.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525

2626
// Config are the configuration options for the Interpreter
2727
type Config struct {
28-
Debug bool // Enables debugging
2928
Tracer EVMLogger // Opcode logger
3029
NoBaseFee bool // Forces the EIP-1559 baseFee to 0 (needed for 0 price calls)
3130
EnablePreimageRecording bool // Enables recording of SHA3/keccak preimages
@@ -145,6 +144,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
145144
gasCopy uint64 // for EVMLogger to log gas remaining before execution
146145
logged bool // deferred EVMLogger should ignore already logged steps
147146
res []byte // result of the opcode execution function
147+
debug = in.evm.Config.Tracer != nil
148148
)
149149
// Don't move this deferred function, it's placed before the capturestate-deferred method,
150150
// so that it get's executed _after_: the capturestate needs the stacks before
@@ -154,7 +154,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
154154
}()
155155
contract.Input = input
156156

157-
if in.evm.Config.Debug {
157+
if debug {
158158
defer func() {
159159
if err != nil {
160160
if !logged {
@@ -170,7 +170,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
170170
// the execution of one of the operations or until the done flag is set by the
171171
// parent context.
172172
for {
173-
if in.evm.Config.Debug {
173+
if debug {
174174
// Capture pre-execution values for tracing.
175175
logged, pcCopy, gasCopy = false, pc, contract.Gas
176176
}
@@ -215,14 +215,14 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
215215
return nil, ErrOutOfGas
216216
}
217217
// Do tracing before memory expansion
218-
if in.evm.Config.Debug {
218+
if debug {
219219
in.evm.Config.Tracer.CaptureState(pc, op, gasCopy, cost, callContext, in.returnData, in.evm.depth, err)
220220
logged = true
221221
}
222222
if memorySize > 0 {
223223
mem.Resize(memorySize)
224224
}
225-
} else if in.evm.Config.Debug {
225+
} else if debug {
226226
in.evm.Config.Tracer.CaptureState(pc, op, gasCopy, cost, callContext, in.returnData, in.evm.depth, err)
227227
logged = true
228228
}

0 commit comments

Comments
 (0)