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

feat(driver): only allow one successful beacon sync #718

Merged
merged 3 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (t *SyncProgressTracker) MarkFinished() {
t.finished = true
}

// Finished returns whether the current beacon sync has been finished.
func (t *SyncProgressTracker) Finished() bool {
return t.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
Loading