Skip to content

Commit 73b01eb

Browse files
authored
Merge pull request #939 from onflow/mpeter/remove-tx-trace-generation
Remove tx trace generation & storage from ingestion engine
2 parents 576c361 + 262a177 commit 73b01eb

File tree

8 files changed

+28
-401
lines changed

8 files changed

+28
-401
lines changed

api/debug.go

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package api
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
7-
"strings"
86

97
gethCommon "github.com/ethereum/go-ethereum/common"
108
gethTypes "github.com/ethereum/go-ethereum/core/types"
@@ -21,9 +19,7 @@ import (
2119
"github.com/onflow/flow-evm-gateway/config"
2220
ethTypes "github.com/onflow/flow-evm-gateway/eth/types"
2321
"github.com/onflow/flow-evm-gateway/models"
24-
errs "github.com/onflow/flow-evm-gateway/models/errors"
2522
"github.com/onflow/flow-evm-gateway/services/evm"
26-
"github.com/onflow/flow-evm-gateway/services/replayer"
2723
"github.com/onflow/flow-evm-gateway/services/requester"
2824
"github.com/onflow/flow-evm-gateway/storage"
2925
"github.com/onflow/flow-evm-gateway/storage/pebble"
@@ -279,28 +275,6 @@ func (d *DebugAPI) traceTransaction(
279275
hash gethCommon.Hash,
280276
config *tracers.TraceConfig,
281277
) (json.RawMessage, error) {
282-
// If the given trace config is equal to the default call tracer used
283-
// in block replay during ingestion, then we fetch the trace result
284-
// from the Traces DB.
285-
if isDefaultCallTracer(config) {
286-
trace, err := d.tracer.GetTransaction(hash)
287-
// If there is no error, we return the trace result from the DB.
288-
if err == nil {
289-
return trace, nil
290-
}
291-
292-
// If we got an error of `ErrEntityNotFound`, for whatever reason,
293-
// we simply re-compute the trace below. If we got any other error,
294-
// we return it.
295-
if !errors.Is(err, errs.ErrEntityNotFound) {
296-
d.logger.Error().Err(err).Msgf(
297-
"failed to retrieve default call trace for tx: %s",
298-
hash,
299-
)
300-
return nil, err
301-
}
302-
}
303-
304278
receipt, err := d.receipts.GetByTransactionID(hash)
305279
if err != nil {
306280
return nil, err
@@ -371,23 +345,6 @@ func (d *DebugAPI) traceBlockByNumber(
371345

372346
results := make([]*txTraceResult, len(block.TransactionHashes))
373347

374-
// If the given trace config is equal to the default call tracer used
375-
// in block replay during ingestion, then we fetch the trace result
376-
// from the Traces DB.
377-
if isDefaultCallTracer(config) {
378-
for i, hash := range block.TransactionHashes {
379-
trace, err := d.traceTransaction(hash, config)
380-
381-
if err != nil {
382-
results[i] = &txTraceResult{TxHash: hash, Error: err.Error()}
383-
} else {
384-
results[i] = &txTraceResult{TxHash: hash, Result: trace}
385-
}
386-
}
387-
388-
return results, nil
389-
}
390-
391348
blockExecutor, err := d.executorAtBlock(block)
392349
if err != nil {
393350
return nil, err
@@ -480,19 +437,3 @@ func (d *DebugAPI) tracerForReceipt(
480437
d.evmChainConfig,
481438
)
482439
}
483-
484-
func isDefaultCallTracer(config *tracers.TraceConfig) bool {
485-
if config == nil {
486-
return false
487-
}
488-
489-
if config.Tracer == nil || *config.Tracer != replayer.TracerName {
490-
return false
491-
}
492-
493-
// The default tracer config is `{"onlyTopCall":true}`, if the user adds
494-
// any whitespace, e.g `{ "onlyTopCall": true }`, the comparison will fail.
495-
// That's why we need to trim out all whitespace characters.
496-
trimmedConfig := strings.ReplaceAll(string(config.TracerConfig), " ", "")
497-
return trimmedConfig == replayer.TracerConfig
498-
}

bootstrap/bootstrap.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,23 +168,14 @@ func (b *Bootstrap) StartEventIngestion(ctx context.Context) error {
168168
nextCadenceHeight,
169169
)
170170

171-
callTracerCollector, err := replayer.NewCallTracerCollector(
172-
b.config.EVMNetworkID,
173-
b.logger,
174-
)
175-
if err != nil {
176-
return err
177-
}
178171
blocksProvider := replayer.NewBlocksProvider(
179172
b.storages.Blocks,
180173
chainID,
181-
callTracerCollector.TxTracer(),
182174
)
183175
replayerConfig := replayer.Config{
184-
ChainID: chainID,
185-
RootAddr: evm.StorageAccountAddress(chainID),
186-
CallTracerCollector: callTracerCollector,
187-
ValidateResults: true,
176+
ChainID: chainID,
177+
RootAddr: evm.StorageAccountAddress(chainID),
178+
ValidateResults: true,
188179
}
189180

190181
// initialize event ingestion engine
@@ -196,7 +187,6 @@ func (b *Bootstrap) StartEventIngestion(ctx context.Context) error {
196187
b.storages.Blocks,
197188
b.storages.Receipts,
198189
b.storages.Transactions,
199-
b.storages.Traces,
200190
b.publishers.Block,
201191
b.publishers.Logs,
202192
b.logger,

services/ingestion/engine.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ type Engine struct {
4747
blocks storage.BlockIndexer
4848
receipts storage.ReceiptIndexer
4949
transactions storage.TransactionIndexer
50-
traces storage.TraceIndexer
5150
log zerolog.Logger
5251
evmLastHeight *models.SequentialHeight
5352
blocksPublisher *models.Publisher[*models.Block]
@@ -64,7 +63,6 @@ func NewEventIngestionEngine(
6463
blocks storage.BlockIndexer,
6564
receipts storage.ReceiptIndexer,
6665
transactions storage.TransactionIndexer,
67-
traces storage.TraceIndexer,
6866
blocksPublisher *models.Publisher[*models.Block],
6967
logsPublisher *models.Publisher[[]*gethTypes.Log],
7068
log zerolog.Logger,
@@ -83,7 +81,6 @@ func NewEventIngestionEngine(
8381
blocks: blocks,
8482
receipts: receipts,
8583
transactions: transactions,
86-
traces: traces,
8784
log: log,
8885
blocksPublisher: blocksPublisher,
8986
logsPublisher: logsPublisher,
@@ -242,7 +239,7 @@ func (e *Engine) indexEvents(events *models.CadenceEvents, batch *pebbleDB.Batch
242239
e.registerStore,
243240
e.blocksProvider,
244241
e.log,
245-
e.replayerConfig.CallTracerCollector.TxTracer(),
242+
nil,
246243
e.replayerConfig.ValidateResults,
247244
)
248245

@@ -293,20 +290,6 @@ func (e *Engine) indexEvents(events *models.CadenceEvents, batch *pebbleDB.Batch
293290
return fmt.Errorf("failed to index receipts for block %d event: %w", events.Block().Height, err)
294291
}
295292

296-
traceCollector := e.replayerConfig.CallTracerCollector
297-
for _, tx := range events.Transactions() {
298-
txHash := tx.Hash()
299-
traceResult, err := traceCollector.Collect(txHash)
300-
if err != nil {
301-
return err
302-
}
303-
304-
err = e.traces.StoreTransaction(txHash, traceResult, batch)
305-
if err != nil {
306-
return err
307-
}
308-
}
309-
310293
blockCreation := time.Unix(int64(events.Block().Timestamp), 0)
311294
e.collector.BlockIngestionTime(blockCreation)
312295

services/ingestion/engine_test.go

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package ingestion
33
import (
44
"context"
55
"encoding/hex"
6-
"encoding/json"
76
"math/big"
87
"testing"
98

@@ -53,8 +52,6 @@ func TestSerialBlockIngestion(t *testing.T) {
5352
}).
5453
Once() // make sure this isn't called multiple times
5554

56-
traces := &storageMock.TraceIndexer{}
57-
5855
eventsChan := make(chan models.BlockEvents)
5956

6057
subscriber := &mocks.EventSubscriber{}
@@ -66,13 +63,12 @@ func TestSerialBlockIngestion(t *testing.T) {
6663

6764
engine := NewEventIngestionEngine(
6865
subscriber,
69-
replayer.NewBlocksProvider(blocks, flowGo.Emulator, nil),
66+
replayer.NewBlocksProvider(blocks, flowGo.Emulator),
7067
store,
7168
registerStore,
7269
blocks,
7370
receipts,
7471
transactions,
75-
traces,
7672
models.NewPublisher[*models.Block](),
7773
models.NewPublisher[[]*gethTypes.Log](),
7874
zerolog.Nop(),
@@ -133,8 +129,6 @@ func TestSerialBlockIngestion(t *testing.T) {
133129
}).
134130
Once() // make sure this isn't called multiple times
135131

136-
traces := &storageMock.TraceIndexer{}
137-
138132
eventsChan := make(chan models.BlockEvents)
139133
subscriber := &mocks.EventSubscriber{}
140134
subscriber.
@@ -145,13 +139,12 @@ func TestSerialBlockIngestion(t *testing.T) {
145139

146140
engine := NewEventIngestionEngine(
147141
subscriber,
148-
replayer.NewBlocksProvider(blocks, flowGo.Emulator, nil),
142+
replayer.NewBlocksProvider(blocks, flowGo.Emulator),
149143
store,
150144
registerStore,
151145
blocks,
152146
receipts,
153147
transactions,
154-
traces,
155148
models.NewPublisher[*models.Block](),
156149
models.NewPublisher[[]*gethTypes.Log](),
157150
zerolog.Nop(),
@@ -256,23 +249,14 @@ func TestBlockAndTransactionIngestion(t *testing.T) {
256249
blockCdc, block, blockEvent, err := newBlock(nextHeight, []gethCommon.Hash{result.TxHash})
257250
require.NoError(t, err)
258251

259-
traces := &storageMock.TraceIndexer{}
260-
traces.
261-
On("StoreTransaction", mock.AnythingOfType("common.Hash"), mock.AnythingOfType("json.RawMessage"), mock.Anything).
262-
Return(func(txID gethCommon.Hash, trace json.RawMessage, batch *pebbleDB.Batch) error {
263-
assert.Equal(t, transaction.Hash(), txID)
264-
return nil
265-
})
266-
267252
engine := NewEventIngestionEngine(
268253
subscriber,
269-
replayer.NewBlocksProvider(blocks, flowGo.Emulator, nil),
254+
replayer.NewBlocksProvider(blocks, flowGo.Emulator),
270255
store,
271256
registerStore,
272257
blocks,
273258
receipts,
274259
transactions,
275-
traces,
276260
models.NewPublisher[*models.Block](),
277261
models.NewPublisher[[]*gethTypes.Log](),
278262
zerolog.Nop(),
@@ -359,28 +343,19 @@ func TestBlockAndTransactionIngestion(t *testing.T) {
359343
return eventsChan
360344
})
361345

362-
txCdc, txEvent, transaction, res, err := newTransaction(nextHeight)
346+
txCdc, txEvent, _, res, err := newTransaction(nextHeight)
363347
require.NoError(t, err)
364348
blockCdc, _, blockEvent, err := newBlock(nextHeight, []gethCommon.Hash{res.TxHash})
365349
require.NoError(t, err)
366350

367-
traces := &storageMock.TraceIndexer{}
368-
traces.
369-
On("StoreTransaction", mock.AnythingOfType("common.Hash"), mock.AnythingOfType("json.RawMessage"), mock.Anything).
370-
Return(func(txID gethCommon.Hash, trace json.RawMessage, batch *pebbleDB.Batch) error {
371-
assert.Equal(t, transaction.Hash(), txID)
372-
return nil
373-
})
374-
375351
engine := NewEventIngestionEngine(
376352
subscriber,
377-
replayer.NewBlocksProvider(blocks, flowGo.Emulator, nil),
353+
replayer.NewBlocksProvider(blocks, flowGo.Emulator),
378354
store,
379355
registerStore,
380356
blocks,
381357
receipts,
382358
transactions,
383-
traces,
384359
models.NewPublisher[*models.Block](),
385360
models.NewPublisher[[]*gethTypes.Log](),
386361
zerolog.Nop(),
@@ -455,8 +430,6 @@ func TestBlockAndTransactionIngestion(t *testing.T) {
455430
}).
456431
Once() // make sure this isn't called multiple times
457432

458-
traces := &storageMock.TraceIndexer{}
459-
460433
eventsChan := make(chan models.BlockEvents)
461434
subscriber := &mocks.EventSubscriber{}
462435
subscriber.
@@ -468,13 +441,12 @@ func TestBlockAndTransactionIngestion(t *testing.T) {
468441

469442
engine := NewEventIngestionEngine(
470443
subscriber,
471-
replayer.NewBlocksProvider(blocks, flowGo.Emulator, nil),
444+
replayer.NewBlocksProvider(blocks, flowGo.Emulator),
472445
store,
473446
registerStore,
474447
blocks,
475448
receipts,
476449
transactions,
477-
traces,
478450
models.NewPublisher[*models.Block](),
479451
models.NewPublisher[[]*gethTypes.Log](),
480452
zerolog.Nop(),
@@ -517,13 +489,6 @@ func TestBlockAndTransactionIngestion(t *testing.T) {
517489
Return(func(receipts []*models.Receipt, _ *pebbleDB.Batch) error { return nil }).
518490
Once()
519491

520-
traces.
521-
On("StoreTransaction", mock.AnythingOfType("common.Hash"), mock.AnythingOfType("json.RawMessage"), mock.Anything).
522-
Return(func(txID gethCommon.Hash, trace json.RawMessage, batch *pebbleDB.Batch) error {
523-
assert.Equal(t, transaction.Hash(), txID)
524-
return nil
525-
})
526-
527492
events = append(events, flow.Event{
528493
Type: string(txEvent.Etype),
529494
Value: txCdc,
@@ -628,10 +593,9 @@ func newTransaction(height uint64) (cadence.Event, *events.Event, models.Transac
628593

629594
func defaultReplayerConfig() replayer.Config {
630595
return replayer.Config{
631-
ChainID: flowGo.Emulator,
632-
RootAddr: evm.StorageAccountAddress(flowGo.Emulator),
633-
CallTracerCollector: replayer.NopTracer,
634-
ValidateResults: false,
596+
ChainID: flowGo.Emulator,
597+
RootAddr: evm.StorageAccountAddress(flowGo.Emulator),
598+
ValidateResults: false,
635599
}
636600
}
637601

services/replayer/blocks_provider.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55

66
gethCommon "github.com/ethereum/go-ethereum/common"
7-
"github.com/ethereum/go-ethereum/eth/tracers"
87
"github.com/onflow/flow-evm-gateway/models"
98
"github.com/onflow/flow-evm-gateway/storage"
109
"github.com/onflow/flow-go/fvm/evm/offchain/blocks"
@@ -37,7 +36,7 @@ func (bs *blockSnapshot) BlockContext() (evmTypes.BlockContext, error) {
3736
return blockHash
3837
},
3938
bs.block.PrevRandao,
40-
bs.tracer,
39+
nil,
4140
)
4241
}
4342

@@ -51,7 +50,6 @@ func (bs *blockSnapshot) BlockContext() (evmTypes.BlockContext, error) {
5150
type BlocksProvider struct {
5251
blocks storage.BlockIndexer
5352
chainID flowGo.ChainID
54-
tracer *tracers.Tracer
5553
latestBlock *models.Block
5654
}
5755

@@ -60,12 +58,10 @@ var _ evmTypes.BlockSnapshotProvider = (*BlocksProvider)(nil)
6058
func NewBlocksProvider(
6159
blocks storage.BlockIndexer,
6260
chainID flowGo.ChainID,
63-
tracer *tracers.Tracer,
6461
) *BlocksProvider {
6562
return &BlocksProvider{
6663
blocks: blocks,
6764
chainID: chainID,
68-
tracer: tracer,
6965
}
7066
}
7167

0 commit comments

Comments
 (0)