Improvements

This commit is contained in:
Sina Mahmoodi 2025-06-16 11:26:29 +02:00
parent 2b92a78b48
commit e76d9dc483

View file

@ -19,6 +19,7 @@ package native
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"errors"
"math/big" "math/big"
"sync/atomic" "sync/atomic"
@ -75,7 +76,7 @@ type prestateTracerConfig struct {
DiffMode bool `json:"diffMode"` // If true, this tracer will return state modifications DiffMode bool `json:"diffMode"` // If true, this tracer will return state modifications
DisableCode bool `json:"disableCode"` // If true, this tracer will not return the contract code DisableCode bool `json:"disableCode"` // If true, this tracer will not return the contract code
DisableStorage bool `json:"disableStorage"` // If true, this tracer will not return the contract storage DisableStorage bool `json:"disableStorage"` // If true, this tracer will not return the contract storage
EnableEmpty bool `json:"enableEmpty"` // If true, this tracer will return empty state objects IncludeEmpty bool `json:"includeEmpty"` // If true, this tracer will return empty state objects
} }
func newPrestateTracer(ctx *tracers.Context, cfg json.RawMessage, chainConfig *params.ChainConfig) (*tracers.Tracer, error) { func newPrestateTracer(ctx *tracers.Context, cfg json.RawMessage, chainConfig *params.ChainConfig) (*tracers.Tracer, error) {
@ -83,6 +84,11 @@ func newPrestateTracer(ctx *tracers.Context, cfg json.RawMessage, chainConfig *p
if err := json.Unmarshal(cfg, &config); err != nil { if err := json.Unmarshal(cfg, &config); err != nil {
return nil, err return nil, err
} }
// Diff mode has special semantics around account creating and deletion which
// requires it to include empty accounts and storage.
if config.DiffMode && config.IncludeEmpty {
return nil, errors.New("cannot use diffMode with includeEmpty")
}
t := &prestateTracer{ t := &prestateTracer{
pre: stateMap{}, pre: stateMap{},
post: stateMap{}, post: stateMap{},
@ -181,7 +187,7 @@ func (t *prestateTracer) OnTxEnd(receipt *types.Receipt, err error) {
// the new created contracts' prestate were empty, so delete them // the new created contracts' prestate were empty, so delete them
for a := range t.created { for a := range t.created {
// the created contract maybe exists in statedb before the creating tx // the created contract maybe exists in statedb before the creating tx
if s := t.pre[a]; s != nil && s.empty && !t.config.EnableEmpty { if s := t.pre[a]; s != nil && s.empty && !t.config.IncludeEmpty {
delete(t.pre, a) delete(t.pre, a)
} }
} }