Skip to content

Commit 63a0306

Browse files
apollo_network: backoff bootstrap re-dial on connection close (#13941)
1 parent 134e0b1 commit 63a0306

4 files changed

Lines changed: 18 additions & 7 deletions

File tree

crates/apollo_network/src/discovery/behaviours/bootstrapping/bootstrap_peer.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,14 @@ impl BootstrapPeerEventStream {
8484
}) if peer_id == self.peer_id && remaining_established == 0 => {
8585
self.dial_mode = DialMode::Disconnected;
8686
self.should_add_peer_to_kad_routing_table = true;
87-
self.time_for_next_bootstrap_dial = now;
87+
let delta_duration = self
88+
.dial_retry_strategy
89+
.next()
90+
.expect("Dial sleep strategy ended even though it's an infinite iterator.");
91+
self.time_for_next_bootstrap_dial = now + delta_duration;
92+
// Drop any sleeper armed for the previous deadline so poll_next builds a fresh
93+
// one against the new time_for_next_bootstrap_dial.
94+
self.sleeper = None;
8895
self.wake_if_needed();
8996
}
9097
FromSwarm::AddressChange(AddressChange { peer_id, .. }) if peer_id == self.peer_id => {

crates/apollo_network/src/discovery/behaviours/bootstrapping/bootstrap_test.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ async fn bootstrapping_redials_when_all_connections_closed(
337337
let (bootstrap_peers, mut behaviour) = make_and_connect_bootstrap_nodes(peer_count).await;
338338

339339
close_all_connections(&mut behaviour, &bootstrap_peers, 0);
340+
assert_no_event_happens_before_duration(&mut behaviour, BOOTSTRAP_DIAL_SLEEP_BASE).await;
340341
consume_dial_events(&mut behaviour, bootstrap_peers.clone()).await;
341342
assert_no_event_happens_before_duration(&mut behaviour, BOOTSTRAP_DIAL_SLEEP_MAX * 2).await;
342343
}
@@ -374,14 +375,17 @@ async fn bootstrapping_redials_in_accordance_with_strategy_when_all_connections_
374375
assert_no_event_happens_before_duration(&mut behaviour, BOOTSTRAP_DIAL_SLEEP_MAX * 2).await;
375376

376377
close_all_connections(&mut behaviour, &bootstrap_peers, 0);
378+
assert_no_event_happens_before_duration(&mut behaviour, BOOTSTRAP_DIAL_SLEEP_BASE).await;
377379
consume_dial_events(&mut behaviour, bootstrap_peers.clone()).await;
378-
assert_no_event_happens_before_duration(&mut behaviour, BOOTSTRAP_DIAL_SLEEP_MAX * 2).await;
380+
assert_no_event(&mut behaviour);
379381

380382
for i in 1..=NUMBER_OF_DIAL_RETRIES {
381383
fail_all_dial_attempts(&mut behaviour, &bootstrap_peers);
384+
// ConnectionClosed already consumed one strategy step, so iteration `i` of this loop
385+
// observes BOOTSTRAP_DIAL_SLEEP_BASE_MILLIS.pow(i + 1).
382386
let current_retry_duration = min(
383387
BOOTSTRAP_DIAL_SLEEP_MAX,
384-
Duration::from_millis(BOOTSTRAP_DIAL_SLEEP_BASE_MILLIS.pow(i)),
388+
Duration::from_millis(BOOTSTRAP_DIAL_SLEEP_BASE_MILLIS.pow(i + 1)),
385389
);
386390
assert_no_event_happens_before_duration(&mut behaviour, current_retry_duration).await;
387391
consume_dial_events(&mut behaviour, bootstrap_peers.clone()).await;

crates/apollo_network/src/discovery/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pub struct RetryConfig {
200200

201201
impl Default for RetryConfig {
202202
fn default() -> Self {
203-
Self { base_delay_millis: 2, max_delay_seconds: Duration::from_secs(5), factor: 5 }
203+
Self { base_delay_millis: 1000, max_delay_seconds: Duration::from_secs(5), factor: 5 }
204204
}
205205
}
206206

crates/apollo_node/resources/config_schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,7 +2537,7 @@
25372537
"consensus_manager_config.network_config.discovery_config.bootstrap_dial_retry_config.base_delay_millis": {
25382538
"description": "The base delay in milliseconds for the exponential backoff strategy.",
25392539
"privacy": "Public",
2540-
"value": 2
2540+
"value": 1000
25412541
},
25422542
"consensus_manager_config.network_config.discovery_config.bootstrap_dial_retry_config.factor": {
25432543
"description": "The factor for the exponential backoff strategy.",
@@ -3177,7 +3177,7 @@
31773177
"mempool_p2p_config.network_config.discovery_config.bootstrap_dial_retry_config.base_delay_millis": {
31783178
"description": "The base delay in milliseconds for the exponential backoff strategy.",
31793179
"privacy": "Public",
3180-
"value": 2
3180+
"value": 1000
31813181
},
31823182
"mempool_p2p_config.network_config.discovery_config.bootstrap_dial_retry_config.factor": {
31833183
"description": "The factor for the exponential backoff strategy.",
@@ -3477,7 +3477,7 @@
34773477
"state_sync_config.static_config.network_config.discovery_config.bootstrap_dial_retry_config.base_delay_millis": {
34783478
"description": "The base delay in milliseconds for the exponential backoff strategy.",
34793479
"privacy": "Public",
3480-
"value": 2
3480+
"value": 1000
34813481
},
34823482
"state_sync_config.static_config.network_config.discovery_config.bootstrap_dial_retry_config.factor": {
34833483
"description": "The factor for the exponential backoff strategy.",

0 commit comments

Comments
 (0)