Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
use checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mask-pp committed Apr 8, 2024
1 parent a6d978c commit cf13e78
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
11 changes: 8 additions & 3 deletions driver/chain_syncer/beaconsync/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -20,6 +21,7 @@ type Syncer struct {
ctx context.Context
rpc *rpc.Client
state *state.State
syncMode string
progressTracker *SyncProgressTracker // Sync progress tracker
}

Expand All @@ -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
Expand Down Expand Up @@ -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[:]),
)
}

Expand Down
19 changes: 10 additions & 9 deletions driver/chain_syncer/chain_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cf13e78

Please sign in to comment.