mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
enable nonce tracer
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
f4114d4047
commit
d638fd5426
2 changed files with 21 additions and 18 deletions
|
|
@ -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: ðAPI{backend: backend, live: l}})
|
||||||
Service: ðAPI{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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue