Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions simulators/optimism/p2p/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,29 @@ func runP2PTests(t *hivesim.T) {

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
readyCh := make(chan struct{})
errCh := make(chan error, 20)
t.Log("awaiting initial sync")
go func() {
tick := time.NewTicker(250 * time.Millisecond)
for {
select {
case <-tick.C:
seqHead, err := seqRollupCl.SyncStatus(ctx)
require.NoError(t, err)
if err != nil {
errCh <- err
return
}
if seqHead.UnsafeL2.Number == seqHead.SafeL2.Number {
continue
}
ready := true
for i := 1; i <= replicaCount; i++ {
repRollupCl := d.GetOpNode(i).RollupClient()
repHead, err := repRollupCl.SyncStatus(ctx)
require.NoError(t, err)
if err != nil {
errCh <- err
return
}
if seqHead.UnsafeL2.Number-repHead.UnsafeL2.Number >= 2 {
ready = false
break
Expand All @@ -196,6 +203,9 @@ func runP2PTests(t *hivesim.T) {
}()

select {
case err := <-errCh:
t.Fatalf("Error awaiting for initial sync", "err", err)

case <-readyCh:
cancel()
t.Log("initial sync complete")
Expand All @@ -204,7 +214,7 @@ func runP2PTests(t *hivesim.T) {
}

ctx, cancel = context.WithTimeout(context.Background(), 5*time.Minute)
errCh := make(chan error, 20)
errCh = make(chan error, 20)
defer cancel()

getSyncStat := func(ctx context.Context, i int) *driver.SyncStatus {
Expand Down