Commit e3cf320f authored by zhiqiangxu's avatar zhiqiangxu Committed by GitHub

discard candidate when ahead (#11874)

* discard candidate when ahead

* also discard result.Unsafe for consistency

* remove unnecessary type convertion for FakeGenesis

* Revert "also discard result.Unsafe for consistency"

This reverts commit d2288d4a01bb4176fd1a3c6e1901646c7bb404c7.

* remove type cast
parent ea665b5a
...@@ -214,6 +214,8 @@ func FindL2Heads(ctx context.Context, cfg *rollup.Config, l1 L1Chain, l2 L2Chain ...@@ -214,6 +214,8 @@ func FindL2Heads(ctx context.Context, cfg *rollup.Config, l1 L1Chain, l2 L2Chain
} }
if ahead { if ahead {
// discard previous candidate
highestL2WithCanonicalL1Origin = eth.L2BlockRef{}
// keep the unsafe head if we can't tell if its L1 origin is canonical or not yet. // keep the unsafe head if we can't tell if its L1 origin is canonical or not yet.
} else if l1Block.Hash == n.L1Origin.Hash { } else if l1Block.Hash == n.L1Origin.Hash {
// if L2 matches canonical chain, even if unsafe, // if L2 matches canonical chain, even if unsafe,
......
...@@ -26,7 +26,7 @@ func (c *syncStartTestCase) generateFakeL2(t *testing.T) (*testutils.FakeChainSo ...@@ -26,7 +26,7 @@ func (c *syncStartTestCase) generateFakeL2(t *testing.T) (*testutils.FakeChainSo
log := testlog.Logger(t, log.LevelError) log := testlog.Logger(t, log.LevelError)
chain := testutils.NewFakeChainSource([]string{c.L1, c.NewL1}, []string{c.L2}, int(c.GenesisL1Num), log) chain := testutils.NewFakeChainSource([]string{c.L1, c.NewL1}, []string{c.L2}, int(c.GenesisL1Num), log)
chain.SetL2Head(len(c.L2) - 1) chain.SetL2Head(len(c.L2) - 1)
genesis := testutils.FakeGenesis(c.GenesisL1, c.GenesisL2, int(c.GenesisL1Num)) genesis := testutils.FakeGenesis(c.GenesisL1, c.GenesisL2, c.GenesisL1Num)
chain.ReorgL1() chain.ReorgL1()
for i := 0; i < len(c.NewL1)-1; i++ { for i := 0; i < len(c.NewL1)-1; i++ {
chain.AdvanceL1() chain.AdvanceL1()
......
...@@ -14,9 +14,9 @@ import ( ...@@ -14,9 +14,9 @@ import (
"github.com/ethereum-optimism/optimism/op-service/eth" "github.com/ethereum-optimism/optimism/op-service/eth"
) )
func FakeGenesis(l1 rune, l2 rune, l1GenesisNumber int) rollup.Genesis { func FakeGenesis(l1 rune, l2 rune, l1GenesisNumber uint64) rollup.Genesis {
return rollup.Genesis{ return rollup.Genesis{
L1: fakeID(l1, uint64(l1GenesisNumber)), L1: fakeID(l1, l1GenesisNumber),
L2: fakeID(l2, 0), L2: fakeID(l2, 0),
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment