-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathutils.go
More file actions
55 lines (48 loc) · 1.87 KB
/
utils.go
File metadata and controls
55 lines (48 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package flashblocks
import (
"context"
"sync"
"time"
"github.com/ethereum-optimism/optimism/op-devstack/devtest"
"github.com/ethereum-optimism/optimism/op-devstack/presets"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/sources"
"github.com/ethereum-optimism/optimism/op-test-sequencer/sequencer/seqtypes"
"github.com/stretchr/testify/require"
)
// driveViaTestSequencer explicitly builds a few blocks to ensure the builder/rollup-boost
// have payloads to serve before we start listening for flashblocks.
func driveViaTestSequencer(t devtest.T, sys *presets.SingleChainWithFlashblocks, count int) {
t.Helper()
ts := sys.TestSequencer.Escape().ControlAPI(sys.L2Chain.ChainID())
ctx := t.Ctx()
head := sys.L2EL.BlockRefByLabel(eth.Unsafe)
for range count {
require.NoError(t, ts.New(ctx, seqtypes.BuildOpts{Parent: head.Hash}))
require.NoError(t, ts.Next(ctx))
head = sys.L2EL.BlockRefByLabel(eth.Unsafe)
}
// Ensure the sequencer EL has produced at least one unsafe block before subscribing.
sys.L2EL.WaitForBlockNumber(1)
// Wait until L2 time catches up to wall clock time before relying on flashblocks.
// During startup the builder may report "unsafe block timestamp is too old" /
// "FCU arrived too late" while the sequencer is still catching up, which makes
// early flashblock receipt assertions flaky.
sys.L2EL.WaitForTime(uint64(time.Now().Unix()))
// Log the latest unsafe head and L1 origin to confirm block production before listening.
head = sys.L2EL.BlockRefByLabel(eth.Unsafe)
sys.Log.Info("Pre-listen unsafe head", "unsafe", head)
}
func startClient(t devtest.T, client *sources.FlashblockClient) {
ctx, cancel := context.WithCancel(t.Ctx())
var wg sync.WaitGroup
t.Cleanup(func() {
cancel()
wg.Wait()
})
wg.Add(1)
go func() {
defer wg.Done()
t.Require().NoError(client.Start(ctx))
}()
}