From 08d3a50cee02695b3290495a0de51f7a8a503e9e Mon Sep 17 00:00:00 2001 From: arya2 Date: Thu, 26 Oct 2023 18:44:32 -0400 Subject: [PATCH 1/2] Fixes bug where Zebra won't reconnect to peers after brief loss of network connectivity --- zebra-network/src/peer_set/initialize.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/zebra-network/src/peer_set/initialize.rs b/zebra-network/src/peer_set/initialize.rs index 6919b2ad09c..376d179c2a4 100644 --- a/zebra-network/src/peer_set/initialize.rs +++ b/zebra-network/src/peer_set/initialize.rs @@ -896,7 +896,7 @@ where // There weren't any peers, so try to get more peers. debug!("demand for peers but no available candidates"); - crawl(candidates, demand_tx).await?; + crawl(candidates, demand_tx, false).await?; Ok(DemandCrawlFinished) } @@ -918,7 +918,7 @@ where "crawling for more peers in response to the crawl timer" ); - crawl(candidates, demand_tx).await?; + crawl(candidates, demand_tx, true).await?; Ok(TimerCrawlFinished) } @@ -957,11 +957,12 @@ where } /// Try to get more peers using `candidates`, then queue a connection attempt using `demand_tx`. -/// If there were no new peers, the connection attempt is skipped. +/// If there were no new peers and `should_always_dial` is false, the connection attempt is skipped. #[instrument(skip(candidates, demand_tx))] async fn crawl( candidates: Arc>>, mut demand_tx: futures::channel::mpsc::Sender, + should_always_dial: bool, ) -> Result<(), BoxError> where S: Service + Send + Sync + 'static, @@ -976,7 +977,7 @@ where result }; let more_peers = match result { - Ok(more_peers) => more_peers, + Ok(more_peers) => more_peers.or_else(|| should_always_dial.then_some(MorePeers)), Err(e) => { info!( ?e, From 5f3bf474307b9935ad409b536719690f2d9062fe Mon Sep 17 00:00:00 2001 From: arya2 Date: Thu, 26 Oct 2023 20:33:17 -0400 Subject: [PATCH 2/2] only dial on timercrawl when theres a new address or zero active outbound conns --- zebra-network/src/peer_set/initialize.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zebra-network/src/peer_set/initialize.rs b/zebra-network/src/peer_set/initialize.rs index 376d179c2a4..9dc74d99f6c 100644 --- a/zebra-network/src/peer_set/initialize.rs +++ b/zebra-network/src/peer_set/initialize.rs @@ -910,6 +910,7 @@ where Ok(TimerCrawl { tick }) => { let candidates = candidates.clone(); let demand_tx = demand_tx.clone(); + let should_always_dial = active_outbound_connections.update_count() == 0; let crawl_handle = tokio::spawn( async move { @@ -918,7 +919,7 @@ where "crawling for more peers in response to the crawl timer" ); - crawl(candidates, demand_tx, true).await?; + crawl(candidates, demand_tx, should_always_dial).await?; Ok(TimerCrawlFinished) }