enable nonce tracer

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2024-09-27 14:13:18 +00:00
parent f4114d4047
commit d638fd5426
2 changed files with 21 additions and 18 deletions

View file

@ -72,11 +72,14 @@ type live struct {
hash common.Hash hash common.Hash
once sync.Once once sync.Once
offsetFile string offsetFile string
enableNonceTracer bool
} }
type liveTracerConfig struct { type liveTracerConfig struct {
Path string `json:"path"` // Path to the directory where the tracer logs will be stored Path string `json:"path"` // Path to the directory where the tracer data will be stored
Config json.RawMessage `json:"config"` Config json.RawMessage `json:"config"`
EnableNonceTracer bool `json:"enableNonceTracer"`
} }
func toTraceTable(name string) string { func toTraceTable(name string) string {
@ -169,6 +172,8 @@ func newLive(cfg json.RawMessage, stack tracers.LiveApiRegister, backend tracing
traces: traces, traces: traces,
tracer: t, tracer: t,
offsetFile: path.Join(frpath, "OFFSET"), offsetFile: path.Join(frpath, "OFFSET"),
enableNonceTracer: config.EnableNonceTracer,
} }
offset := 0 offset := 0
if _, err := os.Stat(l.offsetFile); err == nil || os.IsExist(err) { if _, err := os.Stat(l.offsetFile); err == nil || os.IsExist(err) {
@ -203,15 +208,13 @@ func newLive(cfg json.RawMessage, stack tracers.LiveApiRegister, backend tracing
OnStorageChange: t.OnStorageChange, OnStorageChange: t.OnStorageChange,
OnLog: t.OnLog, OnLog: t.OnLog,
} }
apis := []rpc.API{
{ var apis []rpc.API
Namespace: "trace", if len(muxTracers) > 0 {
Service: &traceAPI{backend: backend, live: l}, apis = append(apis, rpc.API{Namespace: "trace", Service: &traceAPI{backend: backend, live: l}})
}, }
{ if config.EnableNonceTracer {
Namespace: "eth", apis = append(apis, rpc.API{Namespace: "eth", Service: &ethAPI{backend: backend, live: l}})
Service: &ethAPI{backend: backend, live: l},
},
} }
stack.RegisterAPIs(apis) stack.RegisterAPIs(apis)
@ -245,11 +248,13 @@ func (f *live) OnBlockStart(ev tracing.BlockEvent) {
} }
func (f *live) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) { func (f *live) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
if f.enableNonceTracer {
key := append(from.Bytes(), encodeNumber(tx.Nonce())...) key := append(from.Bytes(), encodeNumber(tx.Nonce())...)
val := tx.Hash().Bytes() val := tx.Hash().Bytes()
if err := f.kvdb.Put(key, val); err != nil { if err := f.kvdb.Put(key, val); err != nil {
log.Warn("Failed to put nonce into kvdb", "err", err) log.Warn("Failed to put nonce into kvdb", "err", err)
} }
}
f.tracer.OnTxStart(env, tx, from) f.tracer.OnTxStart(env, tx, from)
} }

View file

@ -23,9 +23,7 @@ type traceConfig struct {
Tracer string `json:"tracer"` Tracer string `json:"tracer"`
} }
var defaultTraceConfig = &traceConfig{ var defaultTraceConfig = &traceConfig{Tracer: "callTracer"}
Tracer: "callTracer",
}
func (api *traceAPI) isSupportedTracer(tracer string) bool { func (api *traceAPI) isSupportedTracer(tracer string) bool {
_, ok := api.live.tracer.Tracers()[tracer] _, ok := api.live.tracer.Tracers()[tracer]