From de14cf890ca91d869e02c5c74ccd2297f17c2ab1 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 25 Jul 2023 16:45:30 +0800 Subject: [PATCH] feat(pkg): optimize `CheckL1ReorgFromL1Cursor` (#329) --- pkg/rpc/methods.go | 10 +++++----- pkg/rpc/methods_test.go | 6 +++--- prover/prover.go | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/rpc/methods.go b/pkg/rpc/methods.go index 133db20ce..749c0266a 100644 --- a/pkg/rpc/methods.go +++ b/pkg/rpc/methods.go @@ -430,7 +430,7 @@ func (c *Client) CheckL1ReorgFromL1Cursor( ctx context.Context, l1Current *types.Header, genesisHeightL1 uint64, -) (bool, *types.Header, error) { +) (bool, *types.Header, *big.Int, error) { var ( reorged bool l1CurrentToReset *types.Header @@ -439,7 +439,7 @@ func (c *Client) CheckL1ReorgFromL1Cursor( if l1Current.Number.Uint64() <= genesisHeightL1 { newL1Current, err := c.L1.HeaderByNumber(ctx, new(big.Int).SetUint64(genesisHeightL1)) if err != nil { - return false, nil, err + return false, nil, nil, err } l1CurrentToReset = newL1Current @@ -452,7 +452,7 @@ func (c *Client) CheckL1ReorgFromL1Cursor( continue } - return false, nil, err + return false, nil, nil, err } if l1Header.Hash() != l1Current.Hash() { @@ -464,7 +464,7 @@ func (c *Client) CheckL1ReorgFromL1Cursor( ) reorged = true if l1Current, err = c.L1.HeaderByHash(ctx, l1Current.ParentHash); err != nil { - return false, nil, err + return false, nil, nil, err } continue } @@ -480,7 +480,7 @@ func (c *Client) CheckL1ReorgFromL1Cursor( "l1CurrentToResetHash", l1CurrentToReset.Hash(), ) - return reorged, l1CurrentToReset, nil + return reorged, l1CurrentToReset, nil, nil } // IsJustSyncedByP2P checks whether the given L2 execution engine has just finished a P2P diff --git a/pkg/rpc/methods_test.go b/pkg/rpc/methods_test.go index 93432e861..0786309e8 100644 --- a/pkg/rpc/methods_test.go +++ b/pkg/rpc/methods_test.go @@ -71,7 +71,7 @@ func TestCheckL1ReorgFromL1Cursor(t *testing.T) { l1Head, err := client.L1.HeaderByNumber(context.Background(), nil) require.Nil(t, err) - _, newL1Current, err := client.CheckL1ReorgFromL1Cursor(context.Background(), l1Head, l1Head.Number.Uint64()) + _, newL1Current, _, err := client.CheckL1ReorgFromL1Cursor(context.Background(), l1Head, l1Head.Number.Uint64()) require.Nil(t, err) require.Equal(t, l1Head.Number.Uint64(), newL1Current.Number.Uint64()) @@ -79,13 +79,13 @@ func TestCheckL1ReorgFromL1Cursor(t *testing.T) { stateVar, err := client.TaikoL1.GetStateVariables(nil) require.Nil(t, err) - reorged, _, err := client.CheckL1ReorgFromL1Cursor(context.Background(), l1Head, stateVar.GenesisHeight) + reorged, _, _, err := client.CheckL1ReorgFromL1Cursor(context.Background(), l1Head, stateVar.GenesisHeight) require.Nil(t, err) require.False(t, reorged) l1Head.BaseFee = new(big.Int).Add(l1Head.BaseFee, common.Big1) - reorged, newL1Current, err = client.CheckL1ReorgFromL1Cursor(context.Background(), l1Head, stateVar.GenesisHeight) + reorged, newL1Current, _, err = client.CheckL1ReorgFromL1Cursor(context.Background(), l1Head, stateVar.GenesisHeight) require.Nil(t, err) require.True(t, reorged) require.Equal(t, l1Head.ParentHash, newL1Current.Hash()) diff --git a/prover/prover.go b/prover/prover.go index 16ae46159..ceb64ad54 100644 --- a/prover/prover.go +++ b/prover/prover.go @@ -350,7 +350,7 @@ func (p *Prover) onBlockProposed( // then check the l1Current cursor at first, to see if the L1 chain has been reorged. if !reorged { - if reorged, l1CurrentToReset, err = p.rpc.CheckL1ReorgFromL1Cursor( + if reorged, l1CurrentToReset, lastHandledBlockIDToReset, err = p.rpc.CheckL1ReorgFromL1Cursor( ctx, p.l1Current, p.genesisHeightL1,