Skip to content

Commit

Permalink
repeat pushing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Bitar committed Nov 5, 2024
1 parent f0c584b commit 0d277e2
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions packages/taiko-client/driver/chain_syncer/chain_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 0d277e2

Please sign in to comment.