Skip to content

fix(taiko-client): only update the lookahead once per epoch #19483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
69 changes: 53 additions & 16 deletions packages/taiko-client/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,29 +483,66 @@ func (d *Driver) cacheLookaheadLoop() {
return err
}

// push into our 3‑epoch ring
log.Debug("Pushing into window", "epoch", currentEpoch, "currOp", currOp.Hex(), "nextOp", nextOp.Hex())
opWin.Push(currentEpoch, currOp, nextOp)
l := d.preconfBlockServer.GetLookahead()
// we dont need to update the lookahead on every slot, we just need to make sure we do it
// once per epoch, since we push the next operator as the current range when we check.
// so, this means we should use a reliable slot past 0 where the operator has no possible
// way to change. mid-epooch works, so we use slot 16.
if l == nil || l.LastEpochUpdated < currentEpoch && slotInEpoch >= 15 {
log.Info("Pushing into window for current epoch",
"epoch", currentEpoch,
"currentSlot", currentSlot,
"slotInEpoch", slotInEpoch,
"currOp", currOp.Hex(),
"nextOp", nextOp.Hex(),
)
opWin.Push(currentEpoch, currOp, nextOp)

// Push next epoch
log.Info("Pushing into window for next epoch",
"epoch", currentEpoch+1,
"currentSlot", currentSlot,
"slotInEpoch", slotInEpoch,
"currOp", nextOp.Hex(), // currOp becomes nextOp at next epoch
)
opWin.Push(currentEpoch+1, nextOp, common.Address{}) // we don't know next-next-op, safe to leave zero

var (
currRanges = opWin.SequencingWindowSplit(d.PreconfOperatorAddress, true)
nextRanges = opWin.SequencingWindowSplit(d.PreconfOperatorAddress, false)
)

d.preconfBlockServer.UpdateLookahead(&preconfBlocks.Lookahead{
CurrOperator: currOp,
NextOperator: nextOp,
CurrRanges: currRanges,
NextRanges: nextRanges,
UpdatedAt: time.Now().UTC(),
LastEpochUpdated: currentEpoch,
})

log.Info(
"Lookahead updated",
"currentSlot", currentSlot,
"currentEpoch", currentEpoch,
"slotsLeftInEpoch", slotsLeftInEpoch,
"slotInEpoch", slotInEpoch,
"currOp", currOp.Hex(),
"nextOp", nextOp.Hex(),
"currRanges", currRanges,
"nextRanges", nextRanges,
)

// Push next epoch (nextOp becomes currOp at next epoch)
log.Debug("Pushing into window", "epoch", currentEpoch+1, "currOp", nextOp.Hex(), "nextOp", common.Address{})
opWin.Push(currentEpoch+1, nextOp, common.Address{}) // we don't know next-next-op, safe to leave zero
return nil
}

// otherwise, just log out information
var (
currRanges = opWin.SequencingWindowSplit(d.PreconfOperatorAddress, true)
nextRanges = opWin.SequencingWindowSplit(d.PreconfOperatorAddress, false)
)

d.preconfBlockServer.UpdateLookahead(&preconfBlocks.Lookahead{
CurrOperator: currOp,
NextOperator: nextOp,
CurrRanges: currRanges,
NextRanges: nextRanges,
UpdatedAt: time.Now().UTC(),
})

log.Info(
"Lookahead information refreshed",
log.Info("Lookahead tick",
"currentSlot", currentSlot,
"currentEpoch", currentEpoch,
"slotsLeftInEpoch", slotsLeftInEpoch,
Expand Down
11 changes: 6 additions & 5 deletions packages/taiko-client/driver/preconf_blocks/lookahead.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ func (w *opWindow) SequencingWindowSplit(operator common.Address, curr bool) []S

// Lookahead holds the up‑to‑date sequencing window and operator addrs.
type Lookahead struct {
CurrOperator common.Address `json:"currOperator"`
NextOperator common.Address `json:"nextOperator"`
CurrRanges []SlotRange `json:"currRanges"` // slots allowed for CurrOperator (0..threshold-1)
NextRanges []SlotRange `json:"nextRanges"` // slots allowed for NextOperator (threshold..slotsPerEpoch-1)
UpdatedAt time.Time `json:"updatedAt"`
CurrOperator common.Address `json:"currOperator"`
NextOperator common.Address `json:"nextOperator"`
CurrRanges []SlotRange `json:"currRanges"` // slots allowed for CurrOperator (0..threshold-1)
NextRanges []SlotRange `json:"nextRanges"` // slots allowed for NextOperator (threshold..slotsPerEpoch-1)
UpdatedAt time.Time `json:"updatedAt"`
LastEpochUpdated uint64 `json:"lastUpdatedEpoch"`
}
8 changes: 8 additions & 0 deletions packages/taiko-client/driver/preconf_blocks/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,14 @@ func (s *PreconfBlockAPIServer) UpdateLookahead(lookahead *Lookahead) {
s.lookahead = lookahead
}

// GetLookahead updates the lookahead information.
func (s *PreconfBlockAPIServer) GetLookahead() *Lookahead {
s.lookaheadMutex.Lock()
defer s.lookaheadMutex.Unlock()

return s.lookahead
}

// CheckLookaheadHandover returns nil if feeRecipient is allowed to build at slot globalSlot (absolute L1 slot).
// and checks the handover window to see if we need to request the end of sequencing
// block.
Expand Down