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

Commit

Permalink
fix(driver): fix an issue for P2P sync timeout (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Jun 7, 2023
1 parent 2d1fda9 commit 3aee10c
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions driver/chain_syncer/chain_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,31 +90,18 @@ func (s *L2ChainSyncer) Sync(l1End *types.Header) error {
return err
}

// Make sure the execution engine's chain head is recorded in protocol.
l2HeadHash, err := s.rpc.TaikoL1.GetCrossChainBlockHash(nil, l2Head.Number)
if err != nil {
return err
}
log.Info(
"L2 head information",
"number", l2Head.Number,
"hash", l2Head.Hash(),
"LastSyncedVerifiedBlockID", s.progressTracker.LastSyncedVerifiedBlockID(),
"lastSyncedVerifiedBlockHash", s.progressTracker.LastSyncedVerifiedBlockHash(),
)

heightOrID := &state.HeightOrID{Height: l2Head.Number}
// If there is a verified block hash mismatch, log the error and then try to re-sync from genesis one by one.
if l2Head.Hash() != l2HeadHash {
log.Error(
"L2 block hash mismatch, re-sync from genesis",
"height", l2Head.Number,
"hash in protocol", common.Hash(l2HeadHash),
"hash in execution engine", l2Head.Hash(),
)

heightOrID.ID = common.Big0
heightOrID.Height = common.Big0
if l2HeadHash, err = s.rpc.TaikoL1.GetCrossChainBlockHash(nil, common.Big0); err != nil {
return err
}
}

// If the L2 execution engine has synced to latest verified block.
if l2HeadHash == s.progressTracker.LastSyncedVerifiedBlockHash() {
if l2Head.Hash() == s.progressTracker.LastSyncedVerifiedBlockHash() {
heightOrID.ID = s.progressTracker.LastSyncedVerifiedBlockID()
}

Expand All @@ -125,7 +112,7 @@ func (s *L2ChainSyncer) Sync(l1End *types.Header) error {
}

// Reset to the latest L2 execution engine's chain status.
s.progressTracker.UpdateMeta(blockID, heightOrID.Height, l2HeadHash)
s.progressTracker.UpdateMeta(blockID, heightOrID.Height, l2Head.Hash())
}

// Insert the proposed block one by one.
Expand Down

0 comments on commit 3aee10c

Please sign in to comment.