Skip to content

Commit

Permalink
Choose randomly who to connect to and open slots with (#1424)
Browse files Browse the repository at this point in the history
* Choose randomly who to connect to and open slots with

* PR link
  • Loading branch information
tomaka authored Nov 28, 2023
1 parent dd2901e commit 72a0855
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions light-base/src/network_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1003,7 +1004,12 @@ async fn background_task<TPlat: PlatformRef>(mut task: BackgroundTask<TPlat>) {
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
} {
Expand All @@ -1012,7 +1018,7 @@ async fn background_task<TPlat: PlatformRef>(mut task: BackgroundTask<TPlat>) {
let x = task
.network
.connected_unopened_gossip_desired()
.next()
.choose(&mut task.randomness)
.map(|(peer_id, chain_id, _)| (peer_id.clone(), chain_id));
x
} {
Expand Down
1 change: 1 addition & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Changed

- 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))
- Increase the rate at which connections are opened to 10 per second, with a pool of 8 simultaneous connections openings. ([#1425](https://github.com/smol-dot/smoldot/pull/1425))

## 2.0.12 - 2023-11-27
Expand Down

0 comments on commit 72a0855

Please sign in to comment.