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 fbf588bae12..2aef42313bb 100644 --- a/packages/taiko-client/driver/chain_syncer/beaconsync/progress_tracker.go +++ b/packages/taiko-client/driver/chain_syncer/beaconsync/progress_tracker.go @@ -160,7 +160,6 @@ func (t *SyncProgressTracker) ClearMeta() { t.triggered = false t.lastSyncedBlockID = nil t.lastSyncedBlockHash = common.Hash{} - t.outOfSync = false } // NeedReSync checks if a new beacon sync request will be needed: @@ -171,11 +170,6 @@ func (t *SyncProgressTracker) NeedReSync(newID *big.Int) (bool, error) { t.mutex.RLock() defer t.mutex.RUnlock() - // If the beacon sync has not been triggered yet, we will simply trigger it. - if !t.triggered { - return true, nil - } - if t.lastSyncedBlockID == nil { return true, nil } @@ -242,22 +236,11 @@ func syncProgressed(last *ethereum.SyncProgress, new *ethereum.SyncProgress) boo return false } - if new == nil { - return true - } - - // Block - if new.CurrentBlock > last.CurrentBlock { - return true - } - - // Fast sync fields - if new.PulledStates > last.PulledStates { - return true - } - // Snap sync fields - if new.SyncedAccounts > last.SyncedAccounts || + return new == nil || + new.CurrentBlock > last.CurrentBlock || + new.PulledStates > last.PulledStates || + new.SyncedAccounts > last.SyncedAccounts || new.SyncedAccountBytes > last.SyncedAccountBytes || new.SyncedBytecodes > last.SyncedBytecodes || new.SyncedBytecodeBytes > last.SyncedBytecodeBytes || @@ -268,11 +251,7 @@ func syncProgressed(last *ethereum.SyncProgress, new *ethereum.SyncProgress) boo new.HealedBytecodes > last.HealedBytecodes || new.HealedBytecodeBytes > last.HealedBytecodeBytes || new.HealingTrienodes > last.HealingTrienodes || - new.HealingBytecode > last.HealingBytecode { - return true - } - - return false + new.HealingBytecode > last.HealingBytecode } // MarkFinished marks the current beacon sync as finished. diff --git a/packages/taiko-client/driver/chain_syncer/blob/syncer.go b/packages/taiko-client/driver/chain_syncer/blob/syncer.go index 7a0fe0b901d..30bf17e18a4 100644 --- a/packages/taiko-client/driver/chain_syncer/blob/syncer.go +++ b/packages/taiko-client/driver/chain_syncer/blob/syncer.go @@ -172,29 +172,26 @@ 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 - } - - 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() + 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() - return nil - } + return nil } // Ignore those already inserted blocks. if s.lastInsertedBlockID != nil && meta.GetBlockID().Cmp(s.lastInsertedBlockID) <= 0 { @@ -217,10 +214,7 @@ 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 - ) + var parent *types.Header if s.progressTracker.Triggered() { // Already synced through beacon sync, just skip this event. if meta.GetBlockID().Cmp(s.progressTracker.LastSyncedBlockID()) <= 0 { diff --git a/packages/taiko-client/driver/chain_syncer/chain_syncer.go b/packages/taiko-client/driver/chain_syncer/chain_syncer.go index 218a78871c6..9a76a520fe7 100644 --- a/packages/taiko-client/driver/chain_syncer/chain_syncer.go +++ b/packages/taiko-client/driver/chain_syncer/chain_syncer.go @@ -168,14 +168,14 @@ func (s *L2ChainSyncer) AheadOfHeadToSync(heightToSync uint64) bool { // If the L2 execution engine's chain is ahead of the block head to sync, // we can mark the beacon sync progress as finished. - if s.progressTracker.LastSyncedBlockID() != nil { + if id := s.progressTracker.LastSyncedBlockID(); id != nil && s.state.GetL2Head().Number.Uint64() < id.Uint64() { log.Info( "L2 execution engine is ahead of the head to sync", "heightToSync", heightToSync, "executionEngineHead", s.state.GetL2Head().Number, - "lastSyncedBlockID", s.progressTracker.LastSyncedBlockID(), + "lastSyncedBlockID", id, ) - return s.state.GetL2Head().Number.Uint64() >= s.progressTracker.LastSyncedBlockID().Uint64() + return false } return true diff --git a/packages/taiko-client/driver/state/state.go b/packages/taiko-client/driver/state/state.go index bae8c311cf7..2bb5b6a46cf 100644 --- a/packages/taiko-client/driver/state/state.go +++ b/packages/taiko-client/driver/state/state.go @@ -5,6 +5,7 @@ import ( "math/big" "sync" "sync/atomic" + "time" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" @@ -126,6 +127,7 @@ func (s *State) eventLoop(ctx context.Context) { l2BlockVerifiedV2Sub = rpc.SubscribeBlockVerifiedV2(s.rpc.TaikoL1, blockVerifiedV2Ch) l2BlockProposedV2Sub = rpc.SubscribeBlockProposedV2(s.rpc.TaikoL1, blockProposedV2Ch) l2TransitionProvedV2Sub = rpc.SubscribeTransitionProvedV2(s.rpc.TaikoL1, transitionProvedV2Ch) + tick = time.NewTicker(time.Minute * 10) ) defer func() { @@ -137,12 +139,15 @@ func (s *State) eventLoop(ctx context.Context) { l2BlockVerifiedV2Sub.Unsubscribe() l2BlockProposedV2Sub.Unsubscribe() l2TransitionProvedV2Sub.Unsubscribe() + tick.Stop() }() for { select { case <-ctx.Done(): return + case <-tick.C: + log.Info("state log, current L2 head", "blockID", s.GetL2Head().Number) case e := <-blockProposedCh: s.setHeadBlockID(e.BlockId) case e := <-blockProposedV2Ch: