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

Commit

Permalink
feat(pkg): optimize CheckL1ReorgFromL1Cursor (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Jul 25, 2023
1 parent eb5d11a commit 12e2dc4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -452,7 +452,7 @@ func (c *Client) CheckL1ReorgFromL1Cursor(
continue
}

return false, nil, err
return false, nil, nil, err
}

if l1Header.Hash() != l1Current.Hash() {
Expand All @@ -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
}
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/rpc/methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,21 @@ 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())

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())
Expand Down
2 changes: 1 addition & 1 deletion prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,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,
Expand Down

0 comments on commit 12e2dc4

Please sign in to comment.