From ef5413ba9d407a3d6aea2071bc241c0bf75e1ed2 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 20 Feb 2023 11:40:39 +0800 Subject: [PATCH 1/2] fix: protocol sync check bug --- driver/state/state.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/state/state.go b/driver/state/state.go index 6f06f5a04..26e9db9dc 100644 --- a/driver/state/state.go +++ b/driver/state/state.go @@ -181,7 +181,7 @@ 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 s.GetL2Head().Number.Cmp(e.SrcHeight) >= 0 { if err := s.VerifyL2Block(ctx, e.SrcHash); err != nil { log.Error("Check new verified L2 block error", "error", err) continue From 95f5e7b05fdeabdc6a6692c9cc140d55922e38c3 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 20 Feb 2023 11:47:27 +0800 Subject: [PATCH 2/2] fix: verifyL1Block bug --- driver/state/state.go | 11 +++++------ driver/state/state_test.go | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/driver/state/state.go b/driver/state/state.go index 26e9db9dc..d22b6c5cd 100644 --- a/driver/state/state.go +++ b/driver/state/state.go @@ -182,7 +182,7 @@ func (s *State) startSubscriptions(ctx context.Context) { // Verify the protocol synced block, check if it exists in // L2 execution engine. if s.GetL2Head().Number.Cmp(e.SrcHeight) >= 0 { - if err := s.VerifyL2Block(ctx, e.SrcHash); err != nil { + 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() {