Skip to content

Commit ab1a404

Browse files
holiman0xTylerHolmess1na
authored
all: remove debug-field from vm config (#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 0b76eb3 commit ab1a404

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
@@ -182,11 +182,12 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
182182
}
183183
snapshot := evm.StateDB.Snapshot()
184184
p, isPrecompile := evm.precompile(addr)
185+
debug := evm.Config.Tracer != nil
185186

186187
if !evm.StateDB.Exist(addr) {
187188
if !isPrecompile && evm.chainRules.IsEIP158 && value.Sign() == 0 {
188189
// Calling a non existing account, don't do anything, but ping the tracer
189-
if evm.Config.Debug {
190+
if debug {
190191
if evm.depth == 0 {
191192
evm.Config.Tracer.CaptureStart(evm, caller.Address(), addr, false, input, gas, value)
192193
evm.Config.Tracer.CaptureEnd(ret, 0, nil)
@@ -202,7 +203,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
202203
evm.Context.Transfer(evm.StateDB, caller.Address(), addr, value)
203204

204205
// Capture the tracer start/end events in debug mode
205-
if evm.Config.Debug {
206+
if debug {
206207
if evm.depth == 0 {
207208
evm.Config.Tracer.CaptureStart(evm, caller.Address(), addr, false, input, gas, value)
208209
defer func(startGas uint64) { // Lazy evaluation of the parameters
@@ -272,7 +273,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
272273
var snapshot = evm.StateDB.Snapshot()
273274

274275
// Invoke tracer hooks that signal entering/exiting a call frame
275-
if evm.Config.Debug {
276+
if evm.Config.Tracer != nil {
276277
evm.Config.Tracer.CaptureEnter(CALLCODE, caller.Address(), addr, input, gas, value)
277278
defer func(startGas uint64) {
278279
evm.Config.Tracer.CaptureExit(ret, startGas-gas, err)
@@ -313,7 +314,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
313314
var snapshot = evm.StateDB.Snapshot()
314315

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

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

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

496-
if evm.Config.Debug {
497+
if evm.Config.Tracer != nil {
497498
if evm.depth == 0 {
498499
evm.Config.Tracer.CaptureEnd(ret, gas-contract.Gas, err)
499500
} 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
@@ -143,6 +142,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
143142
gasCopy uint64 // for EVMLogger to log gas remaining before execution
144143
logged bool // deferred EVMLogger should ignore already logged steps
145144
res []byte // result of the opcode execution function
145+
debug = in.evm.Config.Tracer != nil
146146
)
147147
// Don't move this deferred function, it's placed before the capturestate-deferred method,
148148
// so that it get's executed _after_: the capturestate needs the stacks before
@@ -152,7 +152,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
152152
}()
153153
contract.Input = input
154154

155-
if in.evm.Config.Debug {
155+
if debug {
156156
defer func() {
157157
if err != nil {
158158
if !logged {
@@ -168,7 +168,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
168168
// the execution of one of the operations or until the done flag is set by the
169169
// parent context.
170170
for {
171-
if in.evm.Config.Debug {
171+
if debug {
172172
// Capture pre-execution values for tracing.
173173
logged, pcCopy, gasCopy = false, pc, contract.Gas
174174
}
@@ -213,14 +213,14 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
213213
return nil, ErrOutOfGas
214214
}
215215
// Do tracing before memory expansion
216-
if in.evm.Config.Debug {
216+
if debug {
217217
in.evm.Config.Tracer.CaptureState(pc, op, gasCopy, cost, callContext, in.returnData, in.evm.depth, err)
218218
logged = true
219219
}
220220
if memorySize > 0 {
221221
mem.Resize(memorySize)
222222
}
223-
} else if in.evm.Config.Debug {
223+
} else if debug {
224224
in.evm.Config.Tracer.CaptureState(pc, op, gasCopy, cost, callContext, in.returnData, in.evm.depth, err)
225225
logged = true
226226
}

0 commit comments

Comments
 (0)