@@ -56,6 +56,42 @@ const (
56
56
// multiAddrConnectionStagger is the number of seconds to wait between
57
57
// attempting to a peer with each of its advertised addresses.
58
58
multiAddrConnectionStagger = 10 * time .Second
59
+
60
+ // bootstrapConnTimeout defines the timeout used when connecting to
61
+ // peers during bootstrapping.
62
+ //
63
+ // TODO: tune timeout? 3 seconds might be *too* aggressive but works
64
+ // well.
65
+ bootstrapConnTimeout = 3 * time .Second
66
+
67
+ // We'll use a 15 second backoff, and double the time every time an
68
+ // epoch fails up to a ceiling.
69
+ bootstrapBackoff = 15 * time .Second
70
+
71
+ // We'll start off by waiting 2 seconds between failed attempts, then
72
+ // double each time we fail until we hit the bootstrapBackOffCeiling.
73
+ bootstrapDelayTime = 2 * time .Second
74
+
75
+ // bootstrapBackOffCeiling is the maximum amount of time we'll wait
76
+ // between failed attempts to locate a set of bootstrap peers. We'll
77
+ // slowly double our query back off each time we encounter a failure.
78
+ bootstrapBackOffCeiling = time .Minute * 5
79
+
80
+ // As want to be more aggressive, we'll use a lower back off celling
81
+ // then the main peer bootstrap logic.
82
+ initalBootstrapBackoffCeiling = time .Minute
83
+
84
+ // Using 1/10 of our duration as a margin, compute a random offset to
85
+ // avoid the nodes entering connection cycles.
86
+ nextBackoffMargin = 10
87
+
88
+ // connRetryDuration is the duration to wait before retrying connection
89
+ // requests.
90
+ connRetryDuration = 5 * time .Second
91
+
92
+ // outboundNum is the number of outbound network connections to
93
+ // maintain.
94
+ outboundNum = 100
59
95
)
60
96
61
97
var (
@@ -214,8 +250,8 @@ func (p *PeerConnManager) Start() error {
214
250
cmgr , err := connmgr .New (& connmgr.Config {
215
251
Listeners : p .Config .Listeners ,
216
252
OnAccept : p .InboundPeerConnected ,
217
- RetryDuration : time . Second * 5 ,
218
- TargetOutbound : 100 ,
253
+ RetryDuration : connRetryDuration ,
254
+ TargetOutbound : outboundNum ,
219
255
Dial : noiseDial (
220
256
p .IdentityECDH , p .Config .Net , p .Config .ConnectionTimeout ,
221
257
),
@@ -452,7 +488,7 @@ func (p *PeerConnManager) PeerBootstrapper(numTargetPeers uint32,
452
488
//
453
489
// We'll use a 15 second backoff, and double the time every time an
454
490
// epoch fails up to a ceiling.
455
- backOff := time . Second * 15
491
+ backOff := bootstrapBackoff
456
492
457
493
// We'll create a new ticker to wake us up every 15 seconds so we can
458
494
// see if we've reached our minimum number of peers.
@@ -564,11 +600,6 @@ func (p *PeerConnManager) PeerBootstrapper(numTargetPeers uint32,
564
600
}
565
601
}
566
602
567
- // bootstrapBackOffCeiling is the maximum amount of time we'll wait between
568
- // failed attempts to locate a set of bootstrap peers. We'll slowly double our
569
- // query back off each time we encounter a failure.
570
- const bootstrapBackOffCeiling = time .Minute * 5
571
-
572
603
// initialPeerBootstrap attempts to continuously connect to peers on startup
573
604
// until the target number of peers has been reached. This ensures that nodes
574
605
// receive an up to date network view as soon as possible.
@@ -582,11 +613,11 @@ func (p *PeerConnManager) initialPeerBootstrap(ignore map[autopilot.NodeID]struc
582
613
// We'll start off by waiting 2 seconds between failed attempts, then
583
614
// double each time we fail until we hit the bootstrapBackOffCeiling.
584
615
var delaySignal <- chan time.Time
585
- delayTime := time . Second * 2
616
+ delayTime := bootstrapDelayTime
586
617
587
618
// As want to be more aggressive, we'll use a lower back off celling
588
619
// then the main peer bootstrap logic.
589
- backOffCeiling := bootstrapBackOffCeiling / 5
620
+ backOffCeiling := initalBootstrapBackoffCeiling
590
621
591
622
for attempts := 0 ; ; attempts ++ {
592
623
// Check if the server has been requested to shut down in order
@@ -665,9 +696,8 @@ func (p *PeerConnManager) initialPeerBootstrap(ignore map[autopilot.NodeID]struc
665
696
}
666
697
connLog .Errorf ("Unable to connect to " +
667
698
"%v: %v" , addr , err )
668
- // TODO: tune timeout? 3 seconds might be *too*
669
- // aggressive but works well.
670
- case <- time .After (3 * time .Second ):
699
+
700
+ case <- time .After (bootstrapConnTimeout ):
671
701
connLog .Tracef ("Skipping peer %v due " +
672
702
"to not establishing a " +
673
703
"connection within 3 seconds" ,
@@ -2146,7 +2176,7 @@ func computeNextBackoff(currBackoff, maxBackoff time.Duration) time.Duration {
2146
2176
2147
2177
// Using 1/10 of our duration as a margin, compute a random offset to
2148
2178
// avoid the nodes entering connection cycles.
2149
- margin := nextBackoff / 10
2179
+ margin := nextBackoff / nextBackoffMargin
2150
2180
2151
2181
var wiggle big.Int
2152
2182
wiggle .SetUint64 (uint64 (margin ))
0 commit comments