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

Commit

Permalink
feat(driver): fix the latest verified block hash check when using sna…
Browse files Browse the repository at this point in the history
…p sync (#700)
  • Loading branch information
mask-pp authored Apr 9, 2024
1 parent 993d491 commit 3cae4ea
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions driver/chain_syncer/beaconsync/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,22 @@ func (s *Syncer) getVerifiedBlockPayload(ctx context.Context, blockID uint64) (*
return nil, err
}

blockInfo, err := s.rpc.GetL2BlockInfo(ctx, new(big.Int).SetUint64(blockID))
if err != nil {
return nil, err
}
ts, err := s.rpc.GetTransition(ctx, new(big.Int).SetUint64(blockInfo.BlockId), blockInfo.VerifiedTransitionId)
if err != nil {
return nil, err
}

if s.syncMode == downloader.FullSync.String() && header.Hash() != ts.BlockHash {
return nil, fmt.Errorf(
"latest verified block hash mismatch: %s != %s",
header.Hash(),
common.BytesToHash(ts.BlockHash[:]),
)
if s.syncMode == downloader.FullSync.String() {
blockInfo, err := s.rpc.GetL2BlockInfo(ctx, new(big.Int).SetUint64(blockID))
if err != nil {
return nil, err
}
ts, err := s.rpc.GetTransition(ctx, new(big.Int).SetUint64(blockInfo.BlockId), blockInfo.VerifiedTransitionId)
if err != nil {
return nil, err
}
if header.Hash() != ts.BlockHash {
return nil, fmt.Errorf(
"latest verified block hash mismatch: %s != %s",
header.Hash(),
common.BytesToHash(ts.BlockHash[:]),
)
}
}

log.Info("Latest verified block header retrieved", "hash", header.Hash())
Expand Down

0 comments on commit 3cae4ea

Please sign in to comment.