Skip to content

Commit 10f056f

Browse files
committed
Refactor for readability
1 parent 9e70cc2 commit 10f056f

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

op-node/rollup/driver/driver.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -269,27 +269,39 @@ func (s *Driver) eventLoop() {
269269
syncCheckInterval := time.Duration(s.SyncDeriver.Config.BlockTime) * time.Second * 2
270270
altSyncTicker := time.NewTicker(syncCheckInterval)
271271
defer altSyncTicker.Stop()
272+
272273
lastUnsafeL2 := s.SyncDeriver.Engine.UnsafeL2Head()
273274

275+
unsafeOnly := s.SyncDeriver.SyncCfg.UnsafeOnly
276+
277+
resetAltSync := func(newHead eth.L2BlockRef, derivationReady bool) {
278+
s.log.Debug(
279+
"altSyncTicker reset",
280+
"head", newHead,
281+
"lastUnsafeL2", lastUnsafeL2,
282+
"derivationReady", derivationReady,
283+
"unsafeOnly", unsafeOnly,
284+
)
285+
lastUnsafeL2 = newHead
286+
altSyncTicker.Reset(syncCheckInterval)
287+
}
288+
274289
for {
275290
if s.driverCtx.Err() != nil { // don't try to schedule/handle more work when we are closing.
276291
return
277292
}
278293

279294
planSequencerAction()
280295

281-
// Reset the alt-sync ticker when either:
282-
// - The unsafe L2 head has changed, or
283-
// - Derivation is not yet ready (unless derivation is intentionally disabled via UnsafeOnly).
284-
// This prevents requesting L2 blocks unnecessarily while we are already syncing.
285-
//
286-
// When UnsafeOnly is enabled, derivation will never become ready. Without the
287-
// !UnsafeOnly guard, the alt-sync ticker would reset indefinitely, preventing
288-
// normal alt-sync progress.
289-
if head := s.SyncDeriver.Engine.UnsafeL2Head(); head != lastUnsafeL2 || (!s.SyncDeriver.Derivation.DerivationReady() && !s.SyncDeriver.SyncCfg.UnsafeOnly) {
290-
s.log.Debug("altSyncTicker reset", "head", head, "lastUnsafeL2", lastUnsafeL2, "derivationReady", s.SyncDeriver.Derivation.DerivationReady(), "unsafeOnly", s.SyncDeriver.SyncCfg.UnsafeOnly)
291-
lastUnsafeL2 = head
292-
altSyncTicker.Reset(syncCheckInterval)
296+
head := s.SyncDeriver.Engine.UnsafeL2Head()
297+
derivationReady := s.SyncDeriver.Derivation.DerivationReady()
298+
299+
if lastUnsafeL2 != head {
300+
// Unsafe head changed: reset alt-sync to avoid redundant L2 requests while syncing.
301+
resetAltSync(head, derivationReady)
302+
} else if !unsafeOnly && !derivationReady {
303+
// Derivation enabled but not yet ready: reset alt-sync while it catches up.
304+
resetAltSync(head, derivationReady)
293305
}
294306

295307
select {

0 commit comments

Comments
 (0)