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

Commit

Permalink
refactor(pkg): remove timeout in WaitTillL2ExecutionEngineSynced (#654
Browse files Browse the repository at this point in the history
)

Co-authored-by: maskpp <[email protected]>
Co-authored-by: David <[email protected]>
  • Loading branch information
3 people authored Mar 22, 2024
1 parent eb3cd58 commit 9ac73ba
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,18 @@ func (c *Client) ensureGenesisMatched(ctx context.Context) error {

// WaitTillL2ExecutionEngineSynced keeps waiting until the L2 execution engine is fully synced.
func (c *Client) WaitTillL2ExecutionEngineSynced(ctx context.Context) error {
if ctx.Err() != nil {
if ctx.Err() != nil && !errors.Is(ctx.Err(), context.DeadlineExceeded) {
return ctx.Err()
}
start := time.Now()
return backoff.Retry(
func() error {
if ctx.Err() != nil {
if ctx.Err() != nil && !errors.Is(ctx.Err(), context.DeadlineExceeded) {
return ctx.Err()
}
progress, err := c.L2ExecutionEngineSyncProgress(ctx)
newCtx, cancel := context.WithTimeout(ctx, defaultTimeout)
defer cancel()
progress, err := c.L2ExecutionEngineSyncProgress(newCtx)
if err != nil {
log.Error("Fetch L2 execution engine sync progress error", "error", err)
return err
Expand All @@ -101,6 +104,7 @@ func (c *Client) WaitTillL2ExecutionEngineSynced(ctx context.Context) error {
"currentBlockID", progress.CurrentBlockID,
"highestBlockID", progress.HighestBlockID,
"progress", progress.SyncProgress,
"time", time.Since(start),
)
return errSyncing
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/rpc/methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"context"
"crypto/rand"
"testing"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/require"
"github.com/taikoxyz/taiko-client/bindings/encoding"
"golang.org/x/sync/errgroup"
)

var (
Expand Down Expand Up @@ -115,6 +117,24 @@ func TestWaitTillL2ExecutionEngineSyncedContextErr(t *testing.T) {
require.ErrorContains(t, err, "context canceled")
}

func TestWaitTillL2ExecutionEngineSyncedTimeoutErr(t *testing.T) {
client := newTestClient(t)
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
time.Sleep(1 * time.Second)
g, ctx := errgroup.WithContext(ctx)
g.Go(func() error {
err := client.WaitTillL2ExecutionEngineSynced(ctx)
if err != nil {
return err
}
return nil
})
cancel()
err := g.Wait()
require.ErrorContains(t, err, "context canceled")
}

func TestGetPoolContentValid(t *testing.T) {
client := newTestClient(t)
configs, err := client.TaikoL1.GetConfig(&bind.CallOpts{Context: context.Background()})
Expand Down

0 comments on commit 9ac73ba

Please sign in to comment.