diff --git a/driver/chain_syncer/beaconsync/progress_tracker.go b/driver/chain_syncer/beaconsync/progress_tracker.go index 6135f8f9f..84ce02e34 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 (t *SyncProgressTracker) MarkFinished() { + t.finished = true +} + +// Finished returns whether the current beacon sync has been finished. +func (t *SyncProgressTracker) Finished() bool { + return t.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