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

Commit

Permalink
feat(driver): improve SyncProgressTracker
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Apr 14, 2024
1 parent 70913c6 commit 6645104
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
13 changes: 13 additions & 0 deletions driver/chain_syncer/beaconsync/progress_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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() {

Check failure on line 253 in driver/chain_syncer/beaconsync/progress_tracker.go

View workflow job for this annotation

GitHub Actions / Lint

receiver-naming: receiver name s should be consistent with previous receiver name t for SyncProgressTracker (revive)
s.finished = true
}

// Finished returns whether the current beacon sync has been finished.
func (s *SyncProgressTracker) Finished() bool {

Check failure on line 258 in driver/chain_syncer/beaconsync/progress_tracker.go

View workflow job for this annotation

GitHub Actions / Lint

receiver-naming: receiver name s should be consistent with previous receiver name t for SyncProgressTracker (revive)
return s.finished
}
11 changes: 7 additions & 4 deletions driver/chain_syncer/chain_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6645104

Please sign in to comment.