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

fix(driver): fix an issue in checkLastVerifiedBlockMismatch #297

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions driver/chain_syncer/calldata/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (s *Syncer) onBlockProposed(
"blockID", event.Id,
"height", payloadData.Number,
"hash", payloadData.BlockHash,
"latestVerifiedBlockHeight", s.state.GetLatestVerifiedBlock().Height,
"latestVerifiedBlockID", s.state.GetLatestVerifiedBlock().ID,
"latestVerifiedBlockHash", s.state.GetLatestVerifiedBlock().Hash,
"transactions", len(payloadData.Transactions),
"baseFee", payloadData.BaseFeePerGas,
Expand Down Expand Up @@ -455,7 +455,11 @@ func (s *Syncer) createExecutionPayloads(
// 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 s.state.GetL2Head().Number.Cmp(lastVerifiedBlockInfo.ID) < 0 {
return false, nil
}

l2Header, err := s.rpc.L2.HeaderByNumber(ctx, lastVerifiedBlockInfo.ID)
if err != nil {
return false, err
}
Expand Down
4 changes: 2 additions & 2 deletions driver/chain_syncer/chain_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (s *L2ChainSyncer) Sync(l1End *types.Header) error {

// AheadOfProtocolVerifiedHead checks whether the L2 chain is ahead of verified head in protocol.
func (s *L2ChainSyncer) AheadOfProtocolVerifiedHead() bool {
verifiedHeightToCompare := s.state.GetLatestVerifiedBlock().Height.Uint64()
verifiedHeightToCompare := s.state.GetLatestVerifiedBlock().ID.Uint64()
log.Debug(
"Checking whether the execution engine is ahead of protocol's verified head",
"latestVerifiedBlock", verifiedHeightToCompare,
Expand Down Expand Up @@ -150,7 +150,7 @@ func (s *L2ChainSyncer) AheadOfProtocolVerifiedHead() bool {
// another new beacon sync.
func (s *L2ChainSyncer) needNewBeaconSyncTriggered() bool {
return s.p2pSyncVerifiedBlocks &&
s.state.GetLatestVerifiedBlock().Height.Uint64() > 0 &&
s.state.GetLatestVerifiedBlock().ID.Uint64() > 0 &&
!s.AheadOfProtocolVerifiedHead() &&
!s.progressTracker.OutOfSync()
}
Expand Down
7 changes: 3 additions & 4 deletions driver/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,15 @@ func (s *State) GetL2Head() *types.Header {

// VerifiedHeaderInfo contains information about a verified L2 block header.
type VerifiedHeaderInfo struct {
ID *big.Int
Hash common.Hash
Height *big.Int
ID *big.Int
Hash common.Hash
}

// setLatestVerifiedBlockHash sets the latest verified L2 block hash concurrent safely.
func (s *State) setLatestVerifiedBlockHash(id *big.Int, height *big.Int, hash common.Hash) {
log.Debug("New verified block", "height", height, "hash", hash)
metrics.DriverL2VerifiedHeightGauge.Update(height.Int64())
s.l2VerifiedHead.Store(&VerifiedHeaderInfo{ID: id, Height: height, Hash: hash})
s.l2VerifiedHead.Store(&VerifiedHeaderInfo{ID: id, Hash: hash})
}

// GetLatestVerifiedBlock reads the latest verified L2 block concurrent safely.
Expand Down