@@ -19,6 +19,7 @@ package vm
19
19
import (
20
20
"math/big"
21
21
"sync/atomic"
22
+ "time"
22
23
23
24
"github.com/ethereum/go-ethereum/common"
24
25
"github.com/ethereum/go-ethereum/crypto"
@@ -165,13 +166,23 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
165
166
}
166
167
evm .Transfer (evm .StateDB , caller .Address (), to .Address (), value )
167
168
168
- // initialise a new contract and set the code that is to be used by the
169
- // E The contract is a scoped environment for this execution context
170
- // only.
169
+ // Initialise a new contract and set the code that is to be used by the EVM.
170
+ // The contract is a scoped environment for this execution context only.
171
171
contract := NewContract (caller , to , value , gas )
172
172
contract .SetCallCode (& addr , evm .StateDB .GetCodeHash (addr ), evm .StateDB .GetCode (addr ))
173
173
174
+ start := time .Now ()
175
+
176
+ // Capture the tracer start/end events in debug mode
177
+ if evm .vmConfig .Debug && evm .depth == 0 {
178
+ evm .vmConfig .Tracer .CaptureStart (caller .Address (), addr , false , input , gas , value )
179
+
180
+ defer func () { // Lazy evaluation of the parameters
181
+ evm .vmConfig .Tracer .CaptureEnd (ret , gas - contract .Gas , time .Since (start ), err )
182
+ }()
183
+ }
174
184
ret , err = run (evm , contract , input )
185
+
175
186
// When an error was returned by the EVM or when setting the creation code
176
187
// above we revert to the snapshot and consume any gas remaining. Additionally
177
188
// when we're in homestead this also counts for code storage gas errors.
@@ -338,7 +349,14 @@ func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.I
338
349
if evm .vmConfig .NoRecursion && evm .depth > 0 {
339
350
return nil , contractAddr , gas , nil
340
351
}
352
+
353
+ if evm .vmConfig .Debug && evm .depth == 0 {
354
+ evm .vmConfig .Tracer .CaptureStart (caller .Address (), contractAddr , true , code , gas , value )
355
+ }
356
+ start := time .Now ()
357
+
341
358
ret , err = run (evm , contract , nil )
359
+
342
360
// check whether the max code size has been exceeded
343
361
maxCodeSizeExceeded := evm .ChainConfig ().IsEIP158 (evm .BlockNumber ) && len (ret ) > params .MaxCodeSize
344
362
// if the contract creation ran successfully and no errors were returned
@@ -367,6 +385,9 @@ func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.I
367
385
if maxCodeSizeExceeded && err == nil {
368
386
err = errMaxCodeSizeExceeded
369
387
}
388
+ if evm .vmConfig .Debug && evm .depth == 0 {
389
+ evm .vmConfig .Tracer .CaptureEnd (ret , gas - contract .Gas , time .Since (start ), err )
390
+ }
370
391
return ret , contractAddr , contract .Gas , err
371
392
}
372
393
0 commit comments