From 65f763b5629c75056abc49e824e1bb5536d7cd4e Mon Sep 17 00:00:00 2001 From: David Date: Thu, 16 Jan 2025 09:12:23 +0800 Subject: [PATCH] chore(taiko-client): make full sync to sync to the latest header (#18771) --- .../driver/chain_syncer/beaconsync/syncer.go | 37 +------------------ .../driver/chain_syncer/chain_syncer.go | 34 ++--------------- 2 files changed, 5 insertions(+), 66 deletions(-) diff --git a/packages/taiko-client/driver/chain_syncer/beaconsync/syncer.go b/packages/taiko-client/driver/chain_syncer/beaconsync/syncer.go index 0860dc9d46e..1187e3789aa 100644 --- a/packages/taiko-client/driver/chain_syncer/beaconsync/syncer.go +++ b/packages/taiko-client/driver/chain_syncer/beaconsync/syncer.go @@ -6,11 +6,8 @@ import ( "math/big" "github.com/ethereum/go-ethereum/beacon/engine" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/log" - "github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings" "github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/encoding" "github.com/taikoxyz/taiko-mono/packages/taiko-client/driver/state" "github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/rpc" @@ -22,7 +19,6 @@ type Syncer struct { ctx context.Context rpc *rpc.Client state *state.State - syncMode string progressTracker *SyncProgressTracker // Sync progress tracker } @@ -31,10 +27,9 @@ func NewSyncer( ctx context.Context, rpc *rpc.Client, state *state.State, - syncMode string, progressTracker *SyncProgressTracker, ) *Syncer { - return &Syncer{ctx, rpc, state, syncMode, progressTracker} + return &Syncer{ctx, rpc, state, progressTracker} } // TriggerBeaconSync triggers the L2 execution engine to start performing a beacon sync, if the @@ -101,36 +96,6 @@ func (s *Syncer) getBlockPayload(ctx context.Context, blockID uint64) (*engine.E return nil, err } - // If the sync mode is `full`, we need to verify the protocol verified block hash before syncing. - if s.syncMode == downloader.FullSync.String() { - blockNum := new(big.Int).SetUint64(blockID) - var blockInfo bindings.TaikoDataBlockV2 - if s.state.IsOnTake(blockNum) { - blockInfo, err = s.rpc.GetL2BlockInfoV2(ctx, blockNum) - } else { - blockInfo, err = s.rpc.GetL2BlockInfo(ctx, blockNum) - } - if err != nil { - return nil, err - } - ts, err := s.rpc.GetTransition( - ctx, - new(big.Int).SetUint64(blockInfo.BlockId), - - uint32(blockInfo.VerifiedTransitionId.Uint64()), - ) - if err != nil { - return nil, err - } - if header.Hash() != ts.BlockHash { - return nil, fmt.Errorf( - "latest verified block hash mismatch: %s != %s", - header.Hash(), - common.BytesToHash(ts.BlockHash[:]), - ) - } - } - log.Info("Block header to sync retrieved", "hash", header.Hash()) return encoding.ToExecutableData(header), nil diff --git a/packages/taiko-client/driver/chain_syncer/chain_syncer.go b/packages/taiko-client/driver/chain_syncer/chain_syncer.go index 218a78871c6..b7e834a4f05 100644 --- a/packages/taiko-client/driver/chain_syncer/chain_syncer.go +++ b/packages/taiko-client/driver/chain_syncer/chain_syncer.go @@ -6,8 +6,6 @@ import ( "net/url" "time" - "github.com/ethereum/go-ethereum/accounts/abi/bind" - "github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/log" "github.com/taikoxyz/taiko-mono/packages/taiko-client/driver/chain_syncer/beaconsync" @@ -30,9 +28,6 @@ type L2ChainSyncer struct { // Monitors progressTracker *beaconsync.SyncProgressTracker - // Sync mode - syncMode string - // If this flag is activated, will try P2P beacon sync if current node is behind of the protocol's // the latest verified block head p2pSync bool @@ -52,11 +47,7 @@ func New( tracker := beaconsync.NewSyncProgressTracker(rpc.L2, p2pSyncTimeout) go tracker.Track(ctx) - syncMode, err := rpc.L2.GetSyncMode(ctx) - if err != nil { - return nil, err - } - beaconSyncer := beaconsync.NewSyncer(ctx, rpc, state, syncMode, tracker) + beaconSyncer := beaconsync.NewSyncer(ctx, rpc, state, tracker) blobSyncer, err := blob.NewSyncer( ctx, rpc, @@ -77,7 +68,6 @@ func New( beaconSyncer: beaconSyncer, blobSyncer: blobSyncer, progressTracker: tracker, - syncMode: syncMode, p2pSync: p2pSync, }, nil } @@ -193,25 +183,9 @@ func (s *L2ChainSyncer) needNewBeaconSyncTriggered() (uint64, bool, error) { return 0, false, nil } - // For full sync mode, we will use the verified block head, - // and for snap sync mode, we will use the latest block head. - var ( - blockID uint64 - err error - ) - switch s.syncMode { - case downloader.SnapSync.String(): - if blockID, err = s.rpc.L2CheckPoint.BlockNumber(s.ctx); err != nil { - return 0, false, err - } - case downloader.FullSync.String(): - stateVars, err := s.rpc.GetProtocolStateVariables(&bind.CallOpts{Context: s.ctx}) - if err != nil { - return 0, false, err - } - blockID = stateVars.B.LastVerifiedBlockId - default: - return 0, false, fmt.Errorf("invalid sync mode: %s", s.syncMode) + blockID, err := s.rpc.L2CheckPoint.BlockNumber(s.ctx) + if err != nil { + return 0, false, err } // If the protocol's block head is zero, we simply return false.