forked from cometbft/cometbft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wait.go
35 lines (30 loc) · 1.11 KB
/
wait.go
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
package main
import (
"context"
"time"
"github.com/KYVENetwork/cometbft/v38/libs/log"
e2e "github.com/KYVENetwork/cometbft/v38/test/e2e/pkg"
)
// Wait waits for a number of blocks to be produced, and for all nodes to catch
// up with it.
func Wait(ctx context.Context, testnet *e2e.Testnet, blocks int64) error {
block, _, err := waitForHeight(ctx, testnet, 0)
if err != nil {
return err
}
return WaitUntil(ctx, testnet, block.Height+blocks)
}
// WaitUntil waits until a given height has been reached.
func WaitUntil(ctx context.Context, testnet *e2e.Testnet, height int64) error {
logger.Info("wait until", "msg", log.NewLazySprintf("Waiting for all nodes to reach height %v...", height))
_, err := waitForAllNodes(ctx, testnet, height, waitingTime(len(testnet.Nodes), height))
if err != nil {
return err
}
return nil
}
// waitingTime estimates how long it should take for a node to reach the height.
// More nodes in a network implies we may expect a slower network and may have to wait longer.
func waitingTime(nodes int, height int64) time.Duration {
return time.Duration(20+(int64(nodes)*height)) * time.Second
}