From d94c9a4a5e171d03df00aac49d98fe0cd54c8231 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Tue, 23 Apr 2024 11:59:38 -0400 Subject: [PATCH] Use a constant for the target amount of peer --- coordinator/src/p2p.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/coordinator/src/p2p.rs b/coordinator/src/p2p.rs index 387e4455..f8a3f952 100644 --- a/coordinator/src/p2p.rs +++ b/coordinator/src/p2p.rs @@ -370,6 +370,9 @@ impl LibP2p { IdentTopic::new(format!("{LIBP2P_TOPIC}-{}", hex::encode(set.encode()))) } + // TODO: If a network has less than TARGET_PEERS, this will cause retried ad infinitum + const TARGET_PEERS: usize = 8; + // The addrs we're currently dialing, and the networks associated with them let dialing_peers = Arc::new(RwLock::new(HashMap::new())); // The peers we're currently connected to, and the networks associated with them @@ -448,7 +451,7 @@ impl LibP2p { } } // If we do not, start connecting to this network again - if remaining_peers < 3 { + if remaining_peers < TARGET_PEERS { connect_to_network_send.send(net).expect( "couldn't send net to connect to due to disconnects (receiver dropped?)", ); @@ -476,7 +479,7 @@ impl LibP2p { if let Ok(mut nodes) = serai.p2p_validators(network).await { // If there's an insufficient amount of nodes known, connect to all yet add it // back and break - if nodes.len() < 3 { + if nodes.len() < TARGET_PEERS { log::warn!( "insufficient amount of P2P nodes known for {:?}: {}", network, @@ -643,7 +646,7 @@ impl LibP2p { } } // If we do not, start connecting to this network again - if remaining_peers < 3 { + if remaining_peers < TARGET_PEERS { connect_to_network_send .send(net) .expect(