From 2c37b482a87ebaa4ba8ac48b8a9d8e2b44181efd Mon Sep 17 00:00:00 2001 From: Igor Crevar Date: Wed, 24 May 2023 11:32:57 +0200 Subject: [PATCH] EVM-671 Fix block tracker WithBlockMaxBacklog for state_sync_relayer --- e2e-polybft/framework/test-cluster.go | 17 +++++++++-------- tracker/event_tracker.go | 14 +++++++++++++- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/e2e-polybft/framework/test-cluster.go b/e2e-polybft/framework/test-cluster.go index 47526249e1..6b532af931 100644 --- a/e2e-polybft/framework/test-cluster.go +++ b/e2e-polybft/framework/test-cluster.go @@ -378,14 +378,15 @@ func NewTestCluster(t *testing.T, validatorsCount int, opts ...ClusterOption) *T var err error config := &TestClusterConfig{ - t: t, - WithLogs: isTrueEnv(envLogsEnabled), - WithStdout: isTrueEnv(envStdoutEnabled), - Binary: resolveBinary(), - EpochSize: 10, - EpochReward: 1, - BlockGasLimit: 1e7, // 10M - StakeAmounts: []string{}, + t: t, + WithLogs: isTrueEnv(envLogsEnabled), + WithStdout: isTrueEnv(envStdoutEnabled), + Binary: resolveBinary(), + EpochSize: 10, + EpochReward: 1, + BlockGasLimit: 1e7, // 10M + StakeAmounts: []string{}, + NumBlockConfirmations: 1, } if config.ValidatorPrefix == "" { diff --git a/tracker/event_tracker.go b/tracker/event_tracker.go index 2a2895c02e..32ffbe862b 100644 --- a/tracker/event_tracker.go +++ b/tracker/event_tracker.go @@ -12,6 +12,8 @@ import ( "github.com/umbracle/ethgo/tracker" ) +const minBlockMaxBacklog = 96 + type eventSubscription interface { AddLog(log *ethgo.Log) } @@ -63,7 +65,11 @@ func (e *EventTracker) Start(ctx context.Context) error { return err } - blockMaxBacklog := e.numBlockConfirmations*2 + 1 + blockMaxBacklog := e.numBlockConfirmations * 2 + if blockMaxBacklog < minBlockMaxBacklog { + blockMaxBacklog = minBlockMaxBacklog + } + blockTracker := blocktracker.NewBlockTracker(provider.Eth(), blocktracker.WithBlockMaxBacklog(blockMaxBacklog)) go func() { @@ -74,18 +80,24 @@ func (e *EventTracker) Start(ctx context.Context) error { // Init and start block tracker concurrently, retrying indefinitely go common.RetryForever(ctx, time.Second, func(context.Context) error { + start := time.Now().UTC() + if err := blockTracker.Init(); err != nil { e.logger.Error("failed to init blocktracker", "error", err) return err } + elapsed := time.Since(start) // Calculate the elapsed time + if err := blockTracker.Start(); err != nil { e.logger.Error("failed to start blocktracker", "error", err) return err } + e.logger.Info("Block tracker has been started", "max backlog", blockMaxBacklog, "init time", elapsed) + return nil })