@@ -22,10 +22,8 @@ import (
22
22
const retryPeriodSeconds = 5
23
23
24
24
// Convenience function to initialize connections and check stake for all source blockchains.
25
- // Only returns an error if it fails to get a list of canonical validator or a valid warp config.
26
- //
27
- // Failing a sufficient stake check will only log an error but still return successfully
28
- // since each attempted relay will make an attempt at reconnecting to any missing validators.
25
+ // This function blocks until it successfully connects to sufficient stake for all source blockchains
26
+ // or returns an error if unable to fetch warpConfigs or to connect to sufficient stake before timeout.
29
27
//
30
28
// Sufficient stake is determined by the Warp quora of the configured supported destinations,
31
29
// or if the subnet supports all destinations, by the quora of all configured destinations.
@@ -43,7 +41,7 @@ func InitializeConnectionsAndCheckStake(
43
41
)
44
42
defer cancel ()
45
43
46
- var eg errgroup.Group
44
+ eg , ctx := errgroup .WithContext ( ctx )
47
45
for _ , sourceBlockchain := range cfg .SourceBlockchains {
48
46
if sourceBlockchain .GetSubnetID () == constants .PrimaryNetworkID {
49
47
eg .Go (func () error {
@@ -115,7 +113,7 @@ func connectToNonPrimaryNetworkPeers(
115
113
case <- ctx .Done ():
116
114
return ctx .Err ()
117
115
default :
118
- time .Sleep (5 * time .Second ) // Retry after a short delay
116
+ time .Sleep (retryPeriodSeconds * time .Second )
119
117
}
120
118
}
121
119
}
@@ -166,7 +164,7 @@ func connectToPrimaryNetworkPeers(
166
164
case <- ctx .Done ():
167
165
return ctx .Err ()
168
166
default :
169
- time .Sleep (retryPeriodSeconds )
167
+ time .Sleep (retryPeriodSeconds * time . Second )
170
168
}
171
169
}
172
170
}
0 commit comments