From 66451042dc7045394febd6778c3029a437a32e45 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 14 Apr 2024 23:17:59 +0800 Subject: [PATCH 1/2] feat(driver): improve `SyncProgressTracker` --- driver/chain_syncer/beaconsync/progress_tracker.go | 13 +++++++++++++ driver/chain_syncer/chain_syncer.go | 11 +++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/driver/chain_syncer/beaconsync/progress_tracker.go b/driver/chain_syncer/beaconsync/progress_tracker.go index 6135f8f9f..de3a6faab 100644 --- a/driver/chain_syncer/beaconsync/progress_tracker.go +++ b/driver/chain_syncer/beaconsync/progress_tracker.go @@ -36,6 +36,9 @@ type SyncProgressTracker struct { outOfSync bool ticker *time.Ticker + // A marker to indicate whether the beacon sync has been finished. + finished bool + // Read-write mutex mutex sync.RWMutex } @@ -245,3 +248,13 @@ func syncProgressed(last *ethereum.SyncProgress, new *ethereum.SyncProgress) boo return false } + +// MarkFinished marks the current beacon sync as finished. +func (s *SyncProgressTracker) MarkFinished() { + s.finished = true +} + +// Finished returns whether the current beacon sync has been finished. +func (s *SyncProgressTracker) Finished() bool { + return s.finished +} diff --git a/driver/chain_syncer/chain_syncer.go b/driver/chain_syncer/chain_syncer.go index ea87f6ec8..fd5dd049e 100644 --- a/driver/chain_syncer/chain_syncer.go +++ b/driver/chain_syncer/chain_syncer.go @@ -100,6 +100,9 @@ func (s *L2ChainSyncer) Sync() error { "p2pOutOfSync", s.progressTracker.OutOfSync(), ) + // Mark the beacon sync progress as finished. + s.progressTracker.MarkFinished() + // Get the execution engine's chain head. l2Head, err := s.rpc.L2.HeaderByNumber(s.ctx, nil) if err != nil { @@ -162,13 +165,13 @@ func (s *L2ChainSyncer) AheadOfProtocolVerifiedHead(verifiedHeightToCompare uint // 3. The L2 execution engine's chain is behind of the protocol's latest verified block head. // 4. The L2 execution engine's chain have met a sync timeout issue. func (s *L2ChainSyncer) needNewBeaconSyncTriggered() (uint64, bool, error) { - // If the flag is not set, we simply return false. - if !s.p2pSyncVerifiedBlocks { + // If the flag is not set or there was a finished beacon sync, we simply return false. + if !s.p2pSyncVerifiedBlocks || s.progressTracker.Finished() { return 0, false, nil } - // full sync mode will use the verified block head. - // snap sync mode will use the latest block head. + // For full sync mode, we will use the verified block head, + // And for snap sync mode, we will use the latest block head. var ( blockID uint64 err error From 9fe2e2acbdf43100de2c9329a926d803788c1e22 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 14 Apr 2024 23:23:34 +0800 Subject: [PATCH 2/2] fix: fix lint --- driver/chain_syncer/beaconsync/progress_tracker.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/driver/chain_syncer/beaconsync/progress_tracker.go b/driver/chain_syncer/beaconsync/progress_tracker.go index de3a6faab..84ce02e34 100644 --- a/driver/chain_syncer/beaconsync/progress_tracker.go +++ b/driver/chain_syncer/beaconsync/progress_tracker.go @@ -250,11 +250,11 @@ func syncProgressed(last *ethereum.SyncProgress, new *ethereum.SyncProgress) boo } // MarkFinished marks the current beacon sync as finished. -func (s *SyncProgressTracker) MarkFinished() { - s.finished = true +func (t *SyncProgressTracker) MarkFinished() { + t.finished = true } // Finished returns whether the current beacon sync has been finished. -func (s *SyncProgressTracker) Finished() bool { - return s.finished +func (t *SyncProgressTracker) Finished() bool { + return t.finished }