special for parity traces

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2024-08-19 15:56:48 +00:00
parent efa411ffb7
commit c1f6d4efcb

View file

@ -30,7 +30,8 @@ func init() {
} }
const ( const (
tableSize = 2 * 1024 * 1024 * 1024 tableSize = 2 * 1024 * 1024 * 1024
parityTracer = "parityTracer"
) )
type traceResult struct { type traceResult struct {
@ -66,7 +67,7 @@ type filter struct {
blockCh chan uint64 blockCh chan uint64
stopCh chan struct{} stopCh chan struct{}
tables map[string]bool tables map[string]bool
traces map[string][]*traceResult traces map[string][]interface{}
tracer *native.MuxTracer tracer *native.MuxTracer
latest atomic.Uint64 latest atomic.Uint64
offset atomic.Uint64 offset atomic.Uint64
@ -97,12 +98,16 @@ func toKVKey(name string, number uint64, hash common.Hash) []byte {
switch name { switch name {
case "callTracer": case "callTracer":
typo = byte('C') typo = byte('C')
case "prestateTracer":
typo = byte('S')
case "flatCallTracer": case "flatCallTracer":
typo = byte('F')
case parityTracer:
typo = byte('P') typo = byte('P')
default: default:
panic("not supported yet") panic("not supported yet")
} }
// TODO: have some prefix? // TODO: need some prefix?
key := append(encodeBlockNumber(number), hash.Bytes()...) key := append(encodeBlockNumber(number), hash.Bytes()...)
key = append(key, typo) key = append(key, typo)
@ -137,7 +142,7 @@ func newFilter(cfg json.RawMessage, backend tracers.Backend) (*tracing.Hooks, []
muxTracers := t.Tracers() muxTracers := t.Tracers()
tables := make(map[string]bool, len(muxTracers)) tables := make(map[string]bool, len(muxTracers))
traces := make(map[string][]*traceResult, len(muxTracers)) traces := make(map[string][]interface{}, len(muxTracers))
for name := range muxTracers { for name := range muxTracers {
tables[toTraceTable(name)] = false tables[toTraceTable(name)] = false
traces[name] = nil traces[name] = nil
@ -230,7 +235,7 @@ func (f *filter) OnBlockStart(ev tracing.BlockEvent) {
// reset local cache // reset local cache
txs := ev.Block.Transactions().Len() txs := ev.Block.Transactions().Len()
for name := range f.traces { for name := range f.traces {
f.traces[name] = make([]*traceResult, 0, txs) f.traces[name] = make([]interface{}, 0, txs)
} }
// save the earliest arrived blknum as the offset // save the earliest arrived blknum as the offset
@ -252,8 +257,12 @@ func (f *filter) OnTxEnd(receipt *types.Receipt, err error) {
for name, tt := range f.tracer.Tracers() { for name, tt := range f.tracer.Tracers() {
trace := &traceResult{TxHash: receipt.TxHash} trace := &traceResult{TxHash: receipt.TxHash}
result, err := tt.GetResult() result, err := tt.GetResult()
if name == parityTracer {
f.traces[name] = append(f.traces[name], result)
continue
}
if err != nil { if err != nil {
log.Error("Failed to get tracer results", "number", f.latest.Load(), "error", err) log.Error("Failed to get tracer result", "number", f.latest.Load(), "txhash", receipt.TxHash, "error", err)
trace.Error = err.Error() trace.Error = err.Error()
} else { } else {
trace.Result = result trace.Result = result