From 9c7a19a1f32ea6a8ba7082bfff2deb04f8826a05 Mon Sep 17 00:00:00 2001 From: alexshliu <104080237+alexshliu@users.noreply.github.com> Date: Mon, 4 Sep 2023 14:31:48 +0800 Subject: [PATCH] feat(pkg): add `isSyncing` method (#379) --- pkg/rpc/methods.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/rpc/methods.go b/pkg/rpc/methods.go index 9e40dc68e..3e7d486fd 100644 --- a/pkg/rpc/methods.go +++ b/pkg/rpc/methods.go @@ -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 } @@ -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)