From d216b0b460cf10dcc48001f4db3333cce1bd6649 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 1 Sep 2023 13:36:16 +0800 Subject: [PATCH 1/2] refact: add isSyncing method --- pkg/rpc/methods.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/rpc/methods.go b/pkg/rpc/methods.go index 9e40dc68e..1abb54664 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,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 +} + // 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) From 84407789ff5d4d692dfd2d602f0ffc858b987227 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 4 Sep 2023 11:44:51 +0800 Subject: [PATCH 2/2] refactor: more simple code --- pkg/rpc/methods.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pkg/rpc/methods.go b/pkg/rpc/methods.go index 1abb54664..3e7d486fd 100644 --- a/pkg/rpc/methods.go +++ b/pkg/rpc/methods.go @@ -280,13 +280,10 @@ type L2SyncProgress struct { // isSyncing returns true if the L2 execution engine is syncing with L1. func (p *L2SyncProgress) isSyncing() bool { - if p.SyncProgress != nil || + return p.SyncProgress != nil || p.CurrentBlockID == nil || p.HighestBlockID == nil || - p.CurrentBlockID.Cmp(p.HighestBlockID) < 0 { - return true - } - return false + p.CurrentBlockID.Cmp(p.HighestBlockID) < 0 } // L2ExecutionEngineSyncProgress fetches the sync progress of the given L2 execution engine.