Skip to content

Commit

Permalink
check trusted state before L1 data (0xPolygonHermez#2022)
Browse files Browse the repository at this point in the history
check trusted state before L1 data to avoid havan incomplete trusted state
  • Loading branch information
ARR552 authored Apr 20, 2023
1 parent e0d453c commit 95c57ea
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions synchronizer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,6 @@ func (s *ClientSynchronizer) Sync() error {
case <-s.ctx.Done():
return nil
case <-time.After(waitDuration):
//Sync L1Blocks
if lastEthBlockSynced, err = s.syncBlocks(lastEthBlockSynced); err != nil {
log.Warn("error syncing blocks: ", err)
lastEthBlockSynced, err = s.state.GetLastBlock(s.ctx, nil)
if err != nil {
log.Fatal("error getting lastEthBlockSynced to resume the synchronization... Error: ", err)
}
if s.ctx.Err() != nil {
continue
}
}
latestSequencedBatchNumber, err := s.etherMan.GetLatestBatchNumber()
if err != nil {
log.Warn("error getting latest sequenced batch in the rollup. Error: ", err)
Expand All @@ -150,6 +139,7 @@ func (s *ClientSynchronizer) Sync() error {
log.Warn("error getting latest batch synced. Error: ", err)
continue
}
// Sync trusted state
if latestSyncedBatch >= latestSequencedBatchNumber {
log.Info("L1 state fully synchronized")
err = s.syncTrustedState(latestSyncedBatch)
Expand All @@ -159,6 +149,17 @@ func (s *ClientSynchronizer) Sync() error {
}
waitDuration = s.cfg.SyncInterval.Duration
}
//Sync L1Blocks
if lastEthBlockSynced, err = s.syncBlocks(lastEthBlockSynced); err != nil {
log.Warn("error syncing blocks: ", err)
lastEthBlockSynced, err = s.state.GetLastBlock(s.ctx, nil)
if err != nil {
log.Fatal("error getting lastEthBlockSynced to resume the synchronization... Error: ", err)
}
if s.ctx.Err() != nil {
continue
}
}
}
}
}
Expand Down

0 comments on commit 95c57ea

Please sign in to comment.