diff --git a/packages/taiko-client/driver/chain_syncer/beaconsync/progress_tracker.go b/packages/taiko-client/driver/chain_syncer/beaconsync/progress_tracker.go index 301eeaa29d..b16fae3e6a 100644 --- a/packages/taiko-client/driver/chain_syncer/beaconsync/progress_tracker.go +++ b/packages/taiko-client/driver/chain_syncer/beaconsync/progress_tracker.go @@ -150,16 +150,6 @@ func (t *SyncProgressTracker) UpdateMeta(id *big.Int, blockHash common.Hash) { t.lastSyncedBlockHash = blockHash } -// ClearMeta cleans the inner beacon sync metadata. -func (t *SyncProgressTracker) ClearMeta() { - t.mutex.Lock() - defer t.mutex.Unlock() - - log.Debug("Clear sync progress tracker meta") - - t.triggered = false -} - // NeedReSync checks if a new beacon sync request will be needed: // 1, if the beacon sync has not been triggered yet // 2, if there is 64 blocks gap between the last head to sync and the new block diff --git a/packages/taiko-client/driver/chain_syncer/beaconsync/progress_tracker_test.go b/packages/taiko-client/driver/chain_syncer/beaconsync/progress_tracker_test.go index dd5bb47f1a..3558d71d39 100644 --- a/packages/taiko-client/driver/chain_syncer/beaconsync/progress_tracker_test.go +++ b/packages/taiko-client/driver/chain_syncer/beaconsync/progress_tracker_test.go @@ -49,12 +49,6 @@ func (s *BeaconSyncProgressTrackerTestSuite) TestSyncProgressed() { s.True(syncProgressed(ðereum.SyncProgress{HealingBytecode: 0}, ðereum.SyncProgress{HealingBytecode: 1})) } -func (s *BeaconSyncProgressTrackerTestSuite) TestClearMeta() { - s.t.triggered = true - s.t.ClearMeta() - s.False(s.t.triggered) -} - func (s *BeaconSyncProgressTrackerTestSuite) TestHeadChanged() { s.True(s.t.NeedReSync(common.Big256)) s.t.triggered = true diff --git a/packages/taiko-client/driver/chain_syncer/blob/syncer.go b/packages/taiko-client/driver/chain_syncer/blob/syncer.go index 7b5e8c1ddc..1ed31d8526 100644 --- a/packages/taiko-client/driver/chain_syncer/blob/syncer.go +++ b/packages/taiko-client/driver/chain_syncer/blob/syncer.go @@ -176,30 +176,28 @@ func (s *Syncer) onBlockProposed( // If we are not inserting a block whose parent block is the latest verified block in protocol, // and the node hasn't just finished the P2P sync, we check if the L1 chain has been reorged. - if !s.progressTracker.Triggered() { - reorgCheckResult, err := s.checkReorg(ctx, meta.GetBlockID()) - if err != nil { - return err - } + reorgCheckResult, err := s.checkReorg(ctx, meta.GetBlockID()) + if err != nil { + return err + } + if reorgCheckResult.IsReorged { + log.Info( + "Reset L1Current cursor due to L1 reorg", + "l1CurrentHeightOld", s.state.GetL1Current().Number, + "l1CurrentHashOld", s.state.GetL1Current().Hash(), + "l1CurrentHeightNew", reorgCheckResult.L1CurrentToReset.Number, + "l1CurrentHashNew", reorgCheckResult.L1CurrentToReset.Hash(), + "lastInsertedBlockIDOld", s.lastInsertedBlockID, + "lastInsertedBlockIDNew", reorgCheckResult.LastHandledBlockIDToReset, + ) + s.state.SetL1Current(reorgCheckResult.L1CurrentToReset) + s.lastInsertedBlockID = reorgCheckResult.LastHandledBlockIDToReset + s.reorgDetectedFlag = true + endIter() - if reorgCheckResult.IsReorged { - log.Info( - "Reset L1Current cursor due to L1 reorg", - "l1CurrentHeightOld", s.state.GetL1Current().Number, - "l1CurrentHashOld", s.state.GetL1Current().Hash(), - "l1CurrentHeightNew", reorgCheckResult.L1CurrentToReset.Number, - "l1CurrentHashNew", reorgCheckResult.L1CurrentToReset.Hash(), - "lastInsertedBlockIDOld", s.lastInsertedBlockID, - "lastInsertedBlockIDNew", reorgCheckResult.LastHandledBlockIDToReset, - ) - s.state.SetL1Current(reorgCheckResult.L1CurrentToReset) - s.lastInsertedBlockID = reorgCheckResult.LastHandledBlockIDToReset - s.reorgDetectedFlag = true - endIter() - - return nil - } + return nil } + // Ignore those already inserted blocks. if s.lastInsertedBlockID != nil && meta.GetBlockID().Cmp(s.lastInsertedBlockID) <= 0 { return nil @@ -221,20 +219,11 @@ func (s *Syncer) onBlockProposed( // Fetch the L2 parent block, if the node is just finished a P2P sync, we simply use the tracker's // last synced verified block as the parent, otherwise, we fetch the parent block from L2 EE. - var ( - parent *types.Header - err error - ) - if s.progressTracker.Triggered() { - // Already synced through beacon sync, just skip this event. - if meta.GetBlockID().Cmp(s.progressTracker.LastSyncedBlockID()) <= 0 { - return nil - } - - parent, err = s.rpc.L2.HeaderByHash(ctx, s.progressTracker.LastSyncedBlockHash()) - } else { - parent, err = s.rpc.L2ParentByBlockID(ctx, meta.GetBlockID()) + // Already synced through beacon sync, just skip this event. + if meta.GetBlockID().Cmp(s.progressTracker.LastSyncedBlockID()) <= 0 { + return nil } + parent, err := s.rpc.L2.HeaderByHash(ctx, s.progressTracker.LastSyncedBlockHash()) if err != nil { return fmt.Errorf("failed to fetch L2 parent block: %w", err) } @@ -243,7 +232,6 @@ func (s *Syncer) onBlockProposed( "Parent block", "blockID", parent.Number, "hash", parent.Hash(), - "beaconSyncTriggered", s.progressTracker.Triggered(), ) tx, err := s.rpc.L1.TransactionInBlock(ctx, meta.GetRawBlockHash(), meta.GetTxIndex()) @@ -299,10 +287,6 @@ func (s *Syncer) onBlockProposed( metrics.DriverL1CurrentHeightGauge.Set(float64(meta.GetRawBlockHeight().Uint64())) s.lastInsertedBlockID = meta.GetBlockID() - if s.progressTracker.Triggered() { - s.progressTracker.ClearMeta() - } - return nil } diff --git a/packages/taiko-client/driver/chain_syncer/chain_syncer.go b/packages/taiko-client/driver/chain_syncer/chain_syncer.go index 15c6cd69c8..541568d4d0 100644 --- a/packages/taiko-client/driver/chain_syncer/chain_syncer.go +++ b/packages/taiko-client/driver/chain_syncer/chain_syncer.go @@ -104,38 +104,28 @@ func (s *L2ChainSyncer) Sync() error { // we will only check and trigger P2P sync progress once right after the driver starts s.progressTracker.MarkFinished() - // We have triggered at least a beacon sync in L2 execution engine, we should reset the L1Current - // cursor at first, before start inserting pending L2 blocks one by one. - if s.progressTracker.Triggered() { - log.Info( - "Switch to insert pending blocks one by one", - "p2pEnabled", s.p2pSync, - "p2pOutOfSync", s.progressTracker.OutOfSync(), - ) - - // Get the execution engine's chain head. - l2Head, err := s.rpc.L2.HeaderByNumber(s.ctx, nil) - if err != nil { - return fmt.Errorf("failed to get L2 chain head: %w", err) - } - - log.Info( - "L2 head information", - "number", l2Head.Number, - "hash", l2Head.Hash(), - "lastSyncedBlockID", s.progressTracker.LastSyncedBlockID(), - "lastSyncedBlockHash", s.progressTracker.LastSyncedBlockHash(), - ) + // Get the execution engine's chain head. + l2Head, err := s.rpc.L2.HeaderByNumber(s.ctx, nil) + if err != nil { + return fmt.Errorf("failed to get L2 chain head: %w", err) + } - // Reset the L1Current cursor. - if err := s.state.ResetL1Current(s.ctx, l2Head.Number); err != nil { - return fmt.Errorf("failed to reset L1 current cursor: %w", err) - } + log.Info( + "L2 head information", + "number", l2Head.Number, + "hash", l2Head.Hash(), + "lastSyncedBlockID", s.progressTracker.LastSyncedBlockID(), + "lastSyncedBlockHash", s.progressTracker.LastSyncedBlockHash(), + ) - // Reset to the latest L2 execution engine's chain status. - s.progressTracker.UpdateMeta(l2Head.Number, l2Head.Hash()) + // Reset the L1Current cursor. + if err := s.state.ResetL1Current(s.ctx, l2Head.Number); err != nil { + return fmt.Errorf("failed to reset L1 current cursor: %w", err) } + // Reset to the latest L2 execution engine's chain status. + s.progressTracker.UpdateMeta(l2Head.Number, l2Head.Hash()) + // Insert the proposed block one by one. return s.blobSyncer.ProcessL1Blocks(s.ctx) }