|
| 1 | +package elsync |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/ethereum-optimism/optimism/op-devstack/devtest" |
| 7 | + "github.com/ethereum-optimism/optimism/op-devstack/presets" |
| 8 | + "github.com/ethereum-optimism/optimism/op-service/eth" |
| 9 | + "github.com/ethereum-optimism/optimism/op-supervisor/supervisor/types" |
| 10 | +) |
| 11 | + |
| 12 | +func TestELSyncAfterInitialELSync(gt *testing.T) { |
| 13 | + t := devtest.SerialT(gt) |
| 14 | + sys := presets.NewSingleChainMultiNodeWithoutCheck(t) |
| 15 | + require := t.Require() |
| 16 | + |
| 17 | + sys.L2CL.Advanced(types.LocalUnsafe, 7, 30) |
| 18 | + |
| 19 | + // batcher down so safe not advanced |
| 20 | + require.Equal(uint64(0), sys.L2CL.HeadBlockRef(types.LocalSafe).Number) |
| 21 | + require.Equal(uint64(0), sys.L2CLB.HeadBlockRef(types.LocalSafe).Number) |
| 22 | + // verifier not advanced unsafe head |
| 23 | + require.Equal(uint64(0), sys.L2CLB.HeadBlockRef(types.LocalUnsafe).Number) |
| 24 | + |
| 25 | + // Finish EL sync by supplying the first block |
| 26 | + // EL Sync finished because underlying EL has states to validate the payload for block 1 |
| 27 | + sys.L2CLB.SignalTarget(sys.L2EL, 1) |
| 28 | + |
| 29 | + // Note: Below non-canonical payload caching behavior was only observed after the initial EL Sync has finished |
| 30 | + |
| 31 | + // Send payloads for block 3, 4, 5, 7 which will make non-canonical blocks, block 2 missed |
| 32 | + // Non-canonical payloads will be buffered at the L2EL |
| 33 | + // Order does not matter |
| 34 | + for _, target := range []uint64{5, 3, 4, 7} { |
| 35 | + sys.L2CLB.SignalTarget(sys.L2EL, target) |
| 36 | + // Canonical unsafe head never advances because of the gap |
| 37 | + require.Equal(uint64(1), sys.L2ELB.BlockRefByLabel(eth.Unsafe).Number) |
| 38 | + } |
| 39 | + |
| 40 | + // Send missing gap, payload 2 |
| 41 | + sys.L2CLB.SignalTarget(sys.L2EL, 2) |
| 42 | + |
| 43 | + retries := 2 |
| 44 | + // Gap filled and payload 2, 3, 4, 5 became canonical. Payload 7 is still non canonical |
| 45 | + sys.L2ELB.Reached(eth.Unsafe, 5, retries) |
| 46 | + |
| 47 | + // Send missing gap, payload 6 |
| 48 | + sys.L2CLB.SignalTarget(sys.L2EL, 6) |
| 49 | + |
| 50 | + // Gap filled and block 6, 7 became canonical |
| 51 | + sys.L2ELB.Reached(eth.Unsafe, 7, retries) |
| 52 | +} |
0 commit comments