diff --git a/packages/taiko-client/driver/chain_syncer/chain_syncer.go b/packages/taiko-client/driver/chain_syncer/chain_syncer.go index 75b930b2eae..4f64b8f1fa3 100644 --- a/packages/taiko-client/driver/chain_syncer/chain_syncer.go +++ b/packages/taiko-client/driver/chain_syncer/chain_syncer.go @@ -93,23 +93,38 @@ func New( // Sync performs a sync operation to L2 execution engine's local chain. func (s *L2ChainSyncer) Sync() error { if s.blockGenerator != nil { - // Generate synthetic blocks - parent, err := s.rpc.L2.HeaderByNumber(s.ctx, nil) - if err != nil { - return err - } - - execData := s.blockGenerator.GenerateBlock(parent) - - // Insert block directly via Engine API - status, err := s.rpc.L2Engine.NewPayload(s.ctx, execData) - if err != nil { - return fmt.Errorf("failed to insert synthetic block: %w", err) - } - - if status.Status != "VALID" { - return fmt.Errorf("invalid synthetic block: %s", status.Status) - } + ticker := time.NewTicker(200 * time.Millisecond) + defer ticker.Stop() + + go func() { + for { + select { + case <-s.ctx.Done(): + return + case <-ticker.C: + // Generate synthetic blocks + parent, err := s.rpc.L2.HeaderByNumber(s.ctx, nil) + if err != nil { + log.Error("Failed to get parent header", "error", err) + continue + } + + execData := s.blockGenerator.GenerateBlock(parent) + + // Insert block directly via Engine API + status, err := s.rpc.L2Engine.NewPayload(s.ctx, execData) + if err != nil { + log.Error("Failed to insert synthetic block", "error", err) + continue + } + + if status.Status != "VALID" { + log.Error("Invalid synthetic block", "status", status.Status) + continue + } + } + } + }() return nil }