diff --git a/driver/chain_syncer/beaconsync/progress_tracker.go b/driver/chain_syncer/beaconsync/progress_tracker.go index 11dd9dad0..85dcf24c3 100644 --- a/driver/chain_syncer/beaconsync/progress_tracker.go +++ b/driver/chain_syncer/beaconsync/progress_tracker.go @@ -13,7 +13,7 @@ import ( ) var ( - syncProgressCheckInterval = 10 * time.Second + syncProgressCheckInterval = 12 * time.Second ) // SyncProgressTracker is responsible for tracking the L2 execution engine's sync progress, after @@ -24,10 +24,9 @@ type SyncProgressTracker struct { client *rpc.EthClient // Meta data - triggered bool - lastSyncedVerifiedBlockID *big.Int - lastSyncedVerifiedBlockHeight *big.Int - lastSyncedVerifiedBlockHash common.Hash + triggered bool + lastSyncedVerifiedBlockID *big.Int + lastSyncedVerifiedBlockHash common.Hash // Out-of-sync check related lastSyncProgress *ethereum.SyncProgress @@ -94,12 +93,11 @@ func (t *SyncProgressTracker) track(ctx context.Context) { return } - if new(big.Int).SetUint64(headHeight).Cmp(t.lastSyncedVerifiedBlockHeight) >= 0 { + if new(big.Int).SetUint64(headHeight).Cmp(t.lastSyncedVerifiedBlockID) >= 0 { t.lastProgressedTime = time.Now() log.Info("L2 execution engine has finished the P2P sync work, all verified blocks synced, "+ "will switch to insert pending blocks one by one", "lastSyncedVerifiedBlockID", t.lastSyncedVerifiedBlockID, - "lastSyncedVerifiedBlockHeight", t.lastSyncedVerifiedBlockHeight, "lastSyncedVerifiedBlockHash", t.lastSyncedVerifiedBlockHash, ) return @@ -134,11 +132,11 @@ func (t *SyncProgressTracker) track(ctx context.Context) { } // UpdateMeta updates the inner beacon sync meta data. -func (t *SyncProgressTracker) UpdateMeta(id, height *big.Int, blockHash common.Hash) { +func (t *SyncProgressTracker) UpdateMeta(id *big.Int, blockHash common.Hash) { t.mutex.Lock() defer t.mutex.Unlock() - log.Debug("Update sync progress tracker meta", "id", id, "height", height, "hash", blockHash) + log.Debug("Update sync progress tracker meta", "id", id, "hash", blockHash) if !t.triggered { t.lastProgressedTime = time.Now() @@ -146,7 +144,6 @@ func (t *SyncProgressTracker) UpdateMeta(id, height *big.Int, blockHash common.H t.triggered = true t.lastSyncedVerifiedBlockID = id - t.lastSyncedVerifiedBlockHeight = height t.lastSyncedVerifiedBlockHash = blockHash } @@ -203,18 +200,6 @@ func (t *SyncProgressTracker) LastSyncedVerifiedBlockID() *big.Int { return new(big.Int).Set(t.lastSyncedVerifiedBlockID) } -// LastSyncedVerifiedBlockHeight returns tracker.lastSyncedVerifiedBlockHeight. -func (t *SyncProgressTracker) LastSyncedVerifiedBlockHeight() *big.Int { - t.mutex.RLock() - defer t.mutex.RUnlock() - - if t.lastSyncedVerifiedBlockHeight == nil { - return nil - } - - return new(big.Int).Set(t.lastSyncedVerifiedBlockHeight) -} - // LastSyncedVerifiedBlockHash returns tracker.lastSyncedVerifiedBlockHash. func (t *SyncProgressTracker) LastSyncedVerifiedBlockHash() common.Hash { t.mutex.RLock() diff --git a/driver/chain_syncer/beaconsync/progress_tracker_test.go b/driver/chain_syncer/beaconsync/progress_tracker_test.go index f4fcfd0ba..470ef26d7 100644 --- a/driver/chain_syncer/beaconsync/progress_tracker_test.go +++ b/driver/chain_syncer/beaconsync/progress_tracker_test.go @@ -58,7 +58,7 @@ func (s *BeaconSyncProgressTrackerTestSuite) TestTrack() { // Triggered ctx, cancel = context.WithCancel(context.Background()) - s.t.UpdateMeta(common.Big256, common.Big256, testutils.RandomHash()) + s.t.UpdateMeta(common.Big256, testutils.RandomHash()) go s.t.Track(ctx) time.Sleep(syncProgressCheckInterval + 5*time.Second) cancel() @@ -90,12 +90,6 @@ func (s *BeaconSyncProgressTrackerTestSuite) TestLastSyncedVerifiedBlockID() { s.Equal(common.Big1.Uint64(), s.t.LastSyncedVerifiedBlockID().Uint64()) } -func (s *BeaconSyncProgressTrackerTestSuite) TestLastSyncedVerifiedBlockHeight() { - s.Nil(s.t.LastSyncedVerifiedBlockHeight()) - s.t.lastSyncedVerifiedBlockHeight = common.Big1 - s.Equal(common.Big1.Uint64(), s.t.LastSyncedVerifiedBlockHeight().Uint64()) -} - func (s *BeaconSyncProgressTrackerTestSuite) TestLastSyncedVerifiedBlockHash() { s.Equal( common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), diff --git a/driver/chain_syncer/beaconsync/syncer.go b/driver/chain_syncer/beaconsync/syncer.go index cba804857..3c70ae00a 100644 --- a/driver/chain_syncer/beaconsync/syncer.go +++ b/driver/chain_syncer/beaconsync/syncer.go @@ -47,7 +47,7 @@ func (s *Syncer) TriggerBeaconSync() error { if s.progressTracker.lastSyncProgress == nil { log.Info( "Syncing beacon headers, please check L2 execution engine logs for progress", - "currentSyncHead", s.progressTracker.LastSyncedVerifiedBlockHeight(), + "currentSyncHead", s.progressTracker.LastSyncedVerifiedBlockID(), "newBlockID", blockID, ) } @@ -80,14 +80,12 @@ func (s *Syncer) TriggerBeaconSync() error { // Update sync status. s.progressTracker.UpdateMeta( blockID, - new(big.Int).SetUint64(latestVerifiedHeadPayload.Number), latestVerifiedHeadPayload.BlockHash, ) log.Info( "⛓️ Beacon sync triggered", "newHeadID", blockID, - "newHeadHeight", s.progressTracker.LastSyncedVerifiedBlockHeight(), "newHeadHash", s.progressTracker.LastSyncedVerifiedBlockHash(), ) diff --git a/driver/chain_syncer/chain_syncer.go b/driver/chain_syncer/chain_syncer.go index 61a9fca11..6fedf1e6b 100644 --- a/driver/chain_syncer/chain_syncer.go +++ b/driver/chain_syncer/chain_syncer.go @@ -104,7 +104,7 @@ func (s *L2ChainSyncer) Sync(l1End *types.Header) error { } // Reset to the latest L2 execution engine's chain status. - s.progressTracker.UpdateMeta(l2Head.Number, l2Head.Number, l2Head.Hash()) + s.progressTracker.UpdateMeta(l2Head.Number, l2Head.Hash()) } // Insert the proposed block one by one. @@ -131,8 +131,8 @@ func (s *L2ChainSyncer) AheadOfProtocolVerifiedHead() bool { return false } - if s.progressTracker.LastSyncedVerifiedBlockHeight() != nil { - return s.state.GetL2Head().Number.Uint64() >= s.progressTracker.LastSyncedVerifiedBlockHeight().Uint64() + if s.progressTracker.LastSyncedVerifiedBlockID() != nil { + return s.state.GetL2Head().Number.Uint64() >= s.progressTracker.LastSyncedVerifiedBlockID().Uint64() } return true