From a0b65755078d4947d88a20ec866bda642baea5a9 Mon Sep 17 00:00:00 2001 From: alexshliu <104080237+alexshliu@users.noreply.github.com> Date: Mon, 20 Feb 2023 15:24:49 +0800 Subject: [PATCH] fix(driver): fix an issue in sync status checking (#162) --- driver/state/state.go | 13 ++++++------- driver/state/state_test.go | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/driver/state/state.go b/driver/state/state.go index 6f06f5a04..d22b6c5cd 100644 --- a/driver/state/state.go +++ b/driver/state/state.go @@ -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 } @@ -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 } diff --git a/driver/state/state_test.go b/driver/state/state_test.go index e2f8c9c88..2da5c7743 100644 --- a/driver/state/state_test.go +++ b/driver/state/state_test.go @@ -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() {