-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_sync_rate.go
55 lines (47 loc) · 1.63 KB
/
check_sync_rate.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"time"
"github.com/sedraxnet/sedrax/stability-tests/common/rpc"
"github.com/pkg/errors"
)
func checkSyncRate(syncerClient, syncedClient *rpc.Client) error {
log.Info("Checking the sync rate")
syncerBlockCountResponse, err := syncerClient.GetBlockCount()
if err != nil {
return err
}
syncerGetSelectedTipHashResponse, err := syncerClient.GetSelectedTipHash()
if err != nil {
return err
}
syncerHeadersCount := syncerBlockCountResponse.HeaderCount
syncerBlockCount := syncerBlockCountResponse.BlockCount
log.Infof("SYNCER block count: %d headers and %d blocks", syncerHeadersCount, syncerBlockCount)
// We give 5 seconds for IBD to start and then 100 milliseconds for each block.
expectedTime := time.Now().Add(5*time.Second + time.Duration(syncerHeadersCount)*100*time.Millisecond)
start := time.Now()
const tickDuration = 10 * time.Second
ticker := time.NewTicker(tickDuration)
defer ticker.Stop()
for range ticker.C {
log.Info("Getting SYNCED block count")
syncedBlockCountResponse, err := syncedClient.GetBlockCount()
if err != nil {
return err
}
log.Infof("SYNCED block count: %d headers and %d blocks", syncedBlockCountResponse.HeaderCount,
syncedBlockCountResponse.BlockCount)
syncedGetSelectedTipHashResponse, err := syncedClient.GetSelectedTipHash()
if err != nil {
return err
}
if syncedGetSelectedTipHashResponse.SelectedTipHash == syncerGetSelectedTipHashResponse.SelectedTipHash {
break
}
if time.Now().After(expectedTime) {
return errors.Errorf("SYNCED is not synced in the expected rate")
}
}
log.Infof("IBD took approximately %s", time.Since(start))
return nil
}