From 5018c31c9e9429c759f16289655bcfbaae90e5fe Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 27 Nov 2023 21:56:40 +0100 Subject: [PATCH 1/2] Choose randomly who to connect to and open slots with --- light-base/src/network_service.rs | 10 ++++++++-- wasm-node/CHANGELOG.md | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/light-base/src/network_service.rs b/light-base/src/network_service.rs index 5ab9b8d891..5b43482145 100644 --- a/light-base/src/network_service.rs +++ b/light-base/src/network_service.rs @@ -57,6 +57,7 @@ use futures_lite::FutureExt as _; use futures_util::{future, stream, StreamExt as _}; use hashbrown::{HashMap, HashSet}; use itertools::Itertools as _; +use rand::seq::IteratorRandom as _; use rand_chacha::rand_core::SeedableRng as _; use smoldot::{ header, @@ -1003,7 +1004,12 @@ async fn background_task(mut task: BackgroundTask) { WakeUpReason::NetworkEvent(event) } else if let Some(start_connect) = { let x = (task.num_recent_connection_opening < task.connections_open_pool_size) - .then(|| task.network.unconnected_desired().next().cloned()) + .then(|| { + task.network + .unconnected_desired() + .choose(&mut task.randomness) + .cloned() + }) .flatten(); x } { @@ -1012,7 +1018,7 @@ async fn background_task(mut task: BackgroundTask) { let x = task .network .connected_unopened_gossip_desired() - .next() + .choose(&mut task.randomness) .map(|(peer_id, chain_id, _)| (peer_id.clone(), chain_id)); x } { diff --git a/wasm-node/CHANGELOG.md b/wasm-node/CHANGELOG.md index 469fc8280f..e4e41e5a72 100644 --- a/wasm-node/CHANGELOG.md +++ b/wasm-node/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Changed + +- The order in which smoldot connects to peers is now random rather than depending on the peer. + ## 2.0.12 - 2023-11-27 ### Fixed From b0509432fe56098383729dfea42fb877a9e56e5a Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 27 Nov 2023 21:58:31 +0100 Subject: [PATCH 2/2] PR link --- wasm-node/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasm-node/CHANGELOG.md b/wasm-node/CHANGELOG.md index e4e41e5a72..f2d9cbc04a 100644 --- a/wasm-node/CHANGELOG.md +++ b/wasm-node/CHANGELOG.md @@ -4,7 +4,7 @@ ### Changed -- The order in which smoldot connects to peers is now random rather than depending on the peer. +- The order in which smoldot connects to peers is now random rather than depending on the peer. ([#1424](https://github.com/smol-dot/smoldot/pull/1424)) ## 2.0.12 - 2023-11-27