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

Commit

Permalink
feat(pkg): add isSyncing method (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshliu authored and davidtaikocha committed Sep 4, 2023
1 parent d156853 commit 074a002
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ func (c *Client) WaitTillL2ExecutionEngineSynced(ctx context.Context) error {
return err
}

if progress.SyncProgress != nil ||
progress.CurrentBlockID == nil ||
progress.HighestBlockID == nil ||
progress.CurrentBlockID.Cmp(progress.HighestBlockID) < 0 {
if progress.isSyncing() {
log.Info("L2 execution engine is syncing", "progress", progress)
return errSyncing
}
Expand Down Expand Up @@ -281,6 +278,14 @@ type L2SyncProgress struct {
HighestBlockID *big.Int
}

// isSyncing returns true if the L2 execution engine is syncing with L1.
func (p *L2SyncProgress) isSyncing() bool {
return p.SyncProgress != nil ||
p.CurrentBlockID == nil ||
p.HighestBlockID == nil ||
p.CurrentBlockID.Cmp(p.HighestBlockID) < 0
}

// L2ExecutionEngineSyncProgress fetches the sync progress of the given L2 execution engine.
func (c *Client) L2ExecutionEngineSyncProgress(ctx context.Context) (*L2SyncProgress, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, defaultTimeout)
Expand Down

0 comments on commit 074a002

Please sign in to comment.