From 5b1d29432aed4822a8aa31d1b812f8080d24d3bc Mon Sep 17 00:00:00 2001 From: Ardit Marku Date: Thu, 22 Aug 2024 13:37:41 +0300 Subject: [PATCH 1/2] Add return early statement for empty blocks --- services/traces/engine.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/traces/engine.go b/services/traces/engine.go index a302ea75..7babb16a 100644 --- a/services/traces/engine.go +++ b/services/traces/engine.go @@ -69,6 +69,12 @@ func (e *Engine) Notify(data any) { return } + // If the block has no transactions, we simply return early + // as there are no transaction traces to index. + if len(block.TransactionHashes) == 0 { + return + } + l := e.logger.With().Uint64("evm-height", block.Height).Logger() cadenceID, err := e.blocks.GetCadenceID(block.Height) From a5f395ea3fcee5b0bc0d8819bdd4f3853039ac22 Mon Sep 17 00:00:00 2001 From: Ardit Marku Date: Thu, 22 Aug 2024 13:38:52 +0300 Subject: [PATCH 2/2] Remove unused initEVMHeight argument from NewTracesIngestionEngine method --- bootstrap/bootstrap.go | 5 ----- services/traces/engine.go | 5 ----- services/traces/engine_test.go | 27 ++++++++++++++++++++++++--- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/bootstrap/bootstrap.go b/bootstrap/bootstrap.go index d125e0c9..fb6497fd 100644 --- a/bootstrap/bootstrap.go +++ b/bootstrap/bootstrap.go @@ -201,12 +201,7 @@ func startIngestion( return err } - initHeight, err := blocks.LatestEVMHeight() - if err != nil { - return err - } tracesEngine := traces.NewTracesIngestionEngine( - initHeight, blocksPublisher, blocks, trace, diff --git a/services/traces/engine.go b/services/traces/engine.go index 7babb16a..5227e2ab 100644 --- a/services/traces/engine.go +++ b/services/traces/engine.go @@ -3,7 +3,6 @@ package traces import ( "context" "sync" - "sync/atomic" "time" "github.com/google/uuid" @@ -30,7 +29,6 @@ type Engine struct { } func NewTracesIngestionEngine( - initEVMHeight uint64, blocksPublisher *models.Publisher, blocks storage.BlockIndexer, traces storage.TraceIndexer, @@ -38,9 +36,6 @@ func NewTracesIngestionEngine( logger zerolog.Logger, collector metrics.Collector, ) *Engine { - height := &atomic.Uint64{} - height.Store(initEVMHeight) - return &Engine{ status: models.NewEngineStatus(), logger: logger.With().Str("component", "trace-ingestion").Logger(), diff --git a/services/traces/engine_test.go b/services/traces/engine_test.go index 6cd2a4a9..6bd18711 100644 --- a/services/traces/engine_test.go +++ b/services/traces/engine_test.go @@ -81,7 +81,14 @@ func TestTraceIngestion(t *testing.T) { return nil }) - engine := NewTracesIngestionEngine(latestHeight, blockPublisher, blocks, trace, downloader, zerolog.Nop(), metrics.NopCollector) + engine := NewTracesIngestionEngine( + blockPublisher, + blocks, + trace, + downloader, + zerolog.Nop(), + metrics.NopCollector, + ) err := engine.Run(context.Background()) require.NoError(t, err) @@ -172,7 +179,14 @@ func TestTraceIngestion(t *testing.T) { return nil }) - engine := NewTracesIngestionEngine(latestHeight, blocksPublisher, blocks, trace, downloader, zerolog.Nop(), metrics.NopCollector) + engine := NewTracesIngestionEngine( + blocksPublisher, + blocks, + trace, + downloader, + zerolog.Nop(), + metrics.NopCollector, + ) err := engine.Run(context.Background()) require.NoError(t, err) @@ -252,7 +266,14 @@ func TestTraceIngestion(t *testing.T) { return nil, fmt.Errorf("failed download") }) - engine := NewTracesIngestionEngine(latestHeight, blockBroadcaster, blocks, trace, downloader, logger, collector) + engine := NewTracesIngestionEngine( + blockBroadcaster, + blocks, + trace, + downloader, + logger, + collector, + ) err := engine.Run(context.Background()) require.NoError(t, err)