Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
EVM-671 Fix block tracker WithBlockMaxBacklog for state_sync_relayer
Browse files Browse the repository at this point in the history
  • Loading branch information
igorcrevar committed May 25, 2023
1 parent 40c5cfd commit bc216ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
17 changes: 9 additions & 8 deletions e2e-polybft/framework/test-cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
14 changes: 13 additions & 1 deletion tracker/event_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/umbracle/ethgo/tracker"
)

const minBlockMaxBacklog = 96

type eventSubscription interface {
AddLog(log *ethgo.Log)
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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.Now().UTC().Sub(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
})

Expand Down

0 comments on commit bc216ef

Please sign in to comment.