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

refactor(rpc): add isSyncing method #379

Merged
merged 2 commits into from
Sep 4, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 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,17 @@ type L2SyncProgress struct {
HighestBlockID *big.Int
}

// isSyncing returns true if the L2 execution engine is syncing with L1.
func (p *L2SyncProgress) isSyncing() bool {
if p.SyncProgress != nil ||
p.CurrentBlockID == nil ||
p.HighestBlockID == nil ||
p.CurrentBlockID.Cmp(p.HighestBlockID) < 0 {
return true
}
return false
davidtaikocha marked this conversation as resolved.
Show resolved Hide resolved
}

// 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