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 in sync status checking (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshliu authored Feb 20, 2023
1 parent 80fc0e9 commit 4b21027
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions driver/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ func (s *State) startSubscriptions(ctx context.Context) {
case e := <-s.headerSyncedCh:
// Verify the protocol synced block, check if it exists in
// L2 execution engine.
if s.GetL2Head().Number.Cmp(e.Height) >= 0 {
if err := s.VerifyL2Block(ctx, e.SrcHash); err != nil {
if s.GetL2Head().Number.Cmp(e.SrcHeight) >= 0 {
if err := s.VerifyL2Block(ctx, e.SrcHeight, e.SrcHash); err != nil {
log.Error("Check new verified L2 block error", "error", err)
continue
}
Expand Down Expand Up @@ -276,22 +276,21 @@ func (s *State) SubL1HeadsFeed(ch chan *types.Header) event.Subscription {
}

// VerifyL2Block checks whether the given block is in L2 execution engine's local chain.
func (s *State) VerifyL2Block(ctx context.Context, protocolBlockHash common.Hash) error {
header, err := s.rpc.L2.HeaderByHash(ctx, protocolBlockHash)
func (s *State) VerifyL2Block(ctx context.Context, height *big.Int, hash common.Hash) error {
header, err := s.rpc.L2.HeaderByNumber(ctx, height)
if err != nil {
return err
}

if header.Hash() != protocolBlockHash {
if header.Hash() != hash {
// TODO(david): do not exit but re-sync from genesis?
log.Crit(
"Verified block hash mismatch",
"protocolBlockHash", protocolBlockHash,
"protocolBlockHash", hash,
"block number in L2 execution engine", header.Number,
"block hash in L2 execution engine", header.Hash(),
)
}

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion driver/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (s *DriverStateTestSuite) TestVerifyL2Block() {
head, err := s.RpcClient.L2.HeaderByNumber(context.Background(), nil)

s.Nil(err)
s.Nil(s.s.VerifyL2Block(context.Background(), head.Hash()))
s.Nil(s.s.VerifyL2Block(context.Background(), head.Number, head.Hash()))
}

func (s *DriverStateTestSuite) TestGetL1Head() {
Expand Down

0 comments on commit 4b21027

Please sign in to comment.