diff --git a/driver/chain_syncer/beaconsync/syncer.go b/driver/chain_syncer/beaconsync/syncer.go index e239aabff..9f0921007 100644 --- a/driver/chain_syncer/beaconsync/syncer.go +++ b/driver/chain_syncer/beaconsync/syncer.go @@ -7,6 +7,7 @@ import ( "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-client/bindings/encoding" @@ -20,6 +21,7 @@ type Syncer struct { ctx context.Context rpc *rpc.Client state *state.State + syncMode string progressTracker *SyncProgressTracker // Sync progress tracker } @@ -28,9 +30,10 @@ func NewSyncer( ctx context.Context, rpc *rpc.Client, state *state.State, + syncMode string, progressTracker *SyncProgressTracker, ) *Syncer { - return &Syncer{ctx, rpc, state, progressTracker} + return &Syncer{ctx, rpc, state, syncMode, progressTracker} } // TriggerBeaconSync triggers the L2 execution engine to start performing a beacon sync, if the @@ -102,9 +105,11 @@ func (s *Syncer) getVerifiedBlockPayload(ctx context.Context, blockID uint64) (* return nil, err } - if header.Hash() != blockInfo.Ts.BlockHash { + if s.syncMode == downloader.FullSync.String() && header.Hash() != blockInfo.Ts.BlockHash { return nil, fmt.Errorf( - "latest verified block hash mismatch: %s != %s", header.Hash(), common.BytesToHash(blockInfo.Ts.BlockHash[:]), + "latest verified block hash mismatch: %s != %s", + header.Hash(), + common.BytesToHash(blockInfo.Ts.BlockHash[:]), ) } diff --git a/driver/chain_syncer/chain_syncer.go b/driver/chain_syncer/chain_syncer.go index 2f356296d..8596eb112 100644 --- a/driver/chain_syncer/chain_syncer.go +++ b/driver/chain_syncer/chain_syncer.go @@ -50,7 +50,7 @@ func New( tracker := beaconsync.NewSyncProgressTracker(rpc.L2, p2pSyncTimeout) go tracker.Track(ctx) - beaconSyncer := beaconsync.NewSyncer(ctx, rpc, state, tracker) + beaconSyncer := beaconsync.NewSyncer(ctx, rpc, state, syncMode, tracker) calldataSyncer, err := calldata.NewSyncer(ctx, rpc, state, tracker, maxRetrieveExponent) if err != nil { return nil, err @@ -161,21 +161,22 @@ func (s *L2ChainSyncer) needNewBeaconSyncTriggered() (uint64, bool, error) { return 0, false, nil } - stateVars, err := s.rpc.GetProtocolStateVariables(&bind.CallOpts{Context: s.ctx}) - if err != nil { - return 0, false, err - } - // full sync mode will use the verified block head. // snap sync mode will use the latest block head. - var blockID uint64 + var ( + blockID uint64 + err error + ) switch s.syncMode { case downloader.SnapSync.String(): - blockID, err = s.rpc.L2CheckPoint.BlockNumber(s.ctx) - if err != nil { + 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)