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

Commit

Permalink
feat(driver): check the mismatch of last verified block (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Jun 25, 2023
1 parent c57f6e8 commit 79fda87
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions driver/chain_syncer/calldata/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,35 @@ func (s *Syncer) onBlockProposed(

if !s.progressTracker.Triggered() {
// Check whteher we need to reorg the L2 chain at first.
reorged, l1CurrentToReset, lastInsertedBlockIDToReset, err := s.rpc.CheckL1Reorg(
ctx,
new(big.Int).Sub(event.Id, common.Big1),
// 1. Last verified block
var (
reorged bool
l1CurrentToReset *types.Header
lastInsertedBlockIDToReset *big.Int
err error
)
reorged, err = s.checkLastVerifiedBlockMismatch(ctx)
if err != nil {
return fmt.Errorf("failed to check whether L1 chain has been reorged: %w", err)
return fmt.Errorf("failed to check if last verified block in L2 EE has been reorged: %w", err)
}

// 2. Parent block
if reorged {
genesisL1Header, err := s.rpc.GetGenesisL1Header(ctx)
if err != nil {
return fmt.Errorf("failed to fetch genesis L1 header: %w", err)
}

l1CurrentToReset = genesisL1Header
lastInsertedBlockIDToReset = common.Big0
} else {
reorged, l1CurrentToReset, lastInsertedBlockIDToReset, err = s.rpc.CheckL1Reorg(
ctx,
new(big.Int).Sub(event.Id, common.Big1),
)
if err != nil {
return fmt.Errorf("failed to check whether L1 chain has been reorged: %w", err)
}
}

if reorged {
Expand Down Expand Up @@ -427,3 +450,15 @@ func (s *Syncer) createExecutionPayloads(

return payload, nil
}

// checkLastVerifiedBlockMismatch checks if there is a mismatch between protocol's last verified block hash and
// the corresponding L2 EE block hash.
func (s *Syncer) checkLastVerifiedBlockMismatch(ctx context.Context) (bool, error) {
lastVerifiedBlockInfo := s.state.GetLatestVerifiedBlock()
l2Header, err := s.rpc.L2.HeaderByNumber(ctx, lastVerifiedBlockInfo.Height)
if err != nil {
return false, err
}

return l2Header.Hash() != lastVerifiedBlockInfo.Hash, nil
}

0 comments on commit 79fda87

Please sign in to comment.