Skip to content

Commit

Permalink
discard candidate when ahead (ethereum-optimism#11874)
Browse files Browse the repository at this point in the history
* 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 d2288d4.

* remove type cast
  • Loading branch information
zhiqiangxu authored and samlaf committed Nov 10, 2024
1 parent a41fec6 commit 4ed9eca
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions op-node/rollup/sync/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ func FindL2Heads(ctx context.Context, cfg *rollup.Config, l1 L1Chain, l2 L2Chain
}

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.
} else if l1Block.Hash == n.L1Origin.Hash {
// if L2 matches canonical chain, even if unsafe,
Expand Down
2 changes: 1 addition & 1 deletion op-node/rollup/sync/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (c *syncStartTestCase) generateFakeL2(t *testing.T) (*testutils.FakeChainSo
log := testlog.Logger(t, log.LevelError)
chain := testutils.NewFakeChainSource([]string{c.L1, c.NewL1}, []string{c.L2}, int(c.GenesisL1Num), log)
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()
for i := 0; i < len(c.NewL1)-1; i++ {
chain.AdvanceL1()
Expand Down
4 changes: 2 additions & 2 deletions op-service/testutils/fake_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"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{
L1: fakeID(l1, uint64(l1GenesisNumber)),
L1: fakeID(l1, l1GenesisNumber),
L2: fakeID(l2, 0),
}
}
Expand Down

0 comments on commit 4ed9eca

Please sign in to comment.