Skip to content

Commit

Permalink
feat: only snap sync to the highest safe block
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Nov 17, 2024
1 parent ea20873 commit e3303dd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
9 changes: 4 additions & 5 deletions packages/taiko-client/driver/chain_syncer/chain_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,14 @@ func (s *L2ChainSyncer) needNewBeaconSyncTriggered() (uint64, bool, error) {

// 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
)
var blockID uint64
switch s.syncMode {
case downloader.SnapSync.String():
if blockID, err = s.rpc.L2CheckPoint.BlockNumber(s.ctx); err != nil {
headL1Origin, err := s.rpc.L2CheckPoint.HeadL1Origin(s.ctx)
if err != nil {
return 0, false, err
}
blockID = headL1Origin.BlockID.Uint64()
case downloader.FullSync.String():
stateVars, err := s.rpc.GetProtocolStateVariables(&bind.CallOpts{Context: s.ctx})
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions packages/taiko-client/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func (s *DriverTestSuite) TestInsertSoftBlocks() {
s.Equal(false, l1Origin.EndOfBlock)
s.Equal(false, l1Origin.EndOfPreconf)
s.Equal(uint64(0), l1Origin.BatchID.Uint64())
s.True(l1Origin.IsSoftblock())
s.True(l1Origin.IsSoftBlock())

// Try to patch a soft block with batch ID 1
s.True(s.insertSoftBlock(url, l1Head1, l2Head2.Number.Uint64()+1, 1, true, false).IsSuccess())
Expand All @@ -422,7 +422,7 @@ func (s *DriverTestSuite) TestInsertSoftBlocks() {
s.Equal(true, l1Origin2.EndOfBlock)
s.Equal(false, l1Origin2.EndOfPreconf)
s.Equal(uint64(1), l1Origin2.BatchID.Uint64())
s.True(l1Origin2.IsSoftblock())
s.True(l1Origin2.IsSoftBlock())

canonicalL1Origin, err := s.RPCClient.L2.HeadL1Origin(context.Background())
s.Nil(err)
Expand Down Expand Up @@ -454,7 +454,7 @@ func (s *DriverTestSuite) TestInsertSoftBlocks() {
s.Equal(false, l1Origin3.EndOfBlock)
s.Equal(false, l1Origin3.EndOfPreconf)
s.Equal(uint64(0), l1Origin3.BatchID.Uint64())
s.False(l1Origin3.IsSoftblock())
s.False(l1Origin3.IsSoftBlock())
}

func (s *DriverTestSuite) TestInsertSoftBlocksAfterEOB() {
Expand Down Expand Up @@ -505,12 +505,12 @@ func (s *DriverTestSuite) TestInsertSoftBlocksAfterEOB() {
s.Equal(l2Head2.Number.Uint64(), l1Origin.BlockID.Uint64())
s.Equal(false, l1Origin.EndOfBlock)
s.Equal(true, l1Origin.EndOfPreconf)
s.True(l1Origin.IsSoftblock())
s.True(l1Origin.IsSoftBlock())

headL1Origin, err = s.RPCClient.L2.HeadL1Origin(context.Background())
s.Nil(err)
s.Equal(l2Head.Number.Uint64(), headL1Origin.BlockID.Uint64())
s.False(headL1Origin.IsSoftblock())
s.False(headL1Origin.IsSoftBlock())

s.ProposeAndInsertEmptyBlocks(s.p, s.d.ChainSyncer().BlobSyncer())

Expand All @@ -521,7 +521,7 @@ func (s *DriverTestSuite) TestInsertSoftBlocksAfterEOB() {
headL1Origin, err = s.RPCClient.L2.HeadL1Origin(context.Background())
s.Nil(err)
s.Equal(l2Head3.Number.Uint64(), headL1Origin.BlockID.Uint64())
s.False(headL1Origin.IsSoftblock())
s.False(headL1Origin.IsSoftBlock())
}

func (s *DriverTestSuite) TestInsertSoftBlocksAfterEOP() {
Expand Down
2 changes: 1 addition & 1 deletion packages/taiko-client/pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func (c *Client) GetPoolContent(
timestamp = uint64(time.Now().Unix())
)

if l1Origin != nil && l1Origin.IsSoftblock() && !l1Origin.EndOfPreconf && !l1Origin.EndOfBlock {
if l1Origin != nil && l1Origin.IsSoftBlock() && !l1Origin.EndOfPreconf && !l1Origin.EndOfBlock {
// Check if this is an unfinished soft block, if not, we will use the latest L1 / L2 block number from the L1Origin.
// Otherwise, we will use the L1 / L2 block number in L1Origin.
L1HeadNum = l1Origin.L1BlockHeight
Expand Down

0 comments on commit e3303dd

Please sign in to comment.