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

fix(driver): fix protocol sync status check bug #162

Merged
merged 2 commits into from
Feb 20, 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
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