Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add randomization in sync retry batch peer selection #5822

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions beacon_node/network/src/sync/backfill_sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,24 +918,22 @@ impl<T: BeaconChainTypes> BackFillSync<T> {
// Find a peer to request the batch
let failed_peers = batch.failed_peers();

let new_peer = {
let mut priorized_peers = self
.network_globals
.peers
.read()
.synced_peers()
.map(|peer| {
(
failed_peers.contains(peer),
self.active_requests.get(peer).map(|v| v.len()).unwrap_or(0),
*peer,
)
})
.collect::<Vec<_>>();
let new_peer = self
.network_globals
.peers
.read()
.synced_peers()
.map(|peer| {
(
failed_peers.contains(peer),
self.active_requests.get(peer).map(|v| v.len()).unwrap_or(0),
rand::random::<u32>(),
*peer,
)
})
// Sort peers prioritizing unrelated peers with less active requests.
priorized_peers.sort_unstable();
priorized_peers.first().map(|&(_, _, peer)| peer)
};
.min()
.map(|(_, _, _, peer)| peer);

if let Some(peer) = new_peer {
self.participating_peers.insert(peer);
Expand Down
24 changes: 14 additions & 10 deletions beacon_node/network/src/sync/range_sync/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use beacon_chain::block_verification_types::RpcBlock;
use beacon_chain::BeaconChainTypes;
use fnv::FnvHashMap;
use lighthouse_network::{PeerAction, PeerId};
use rand::seq::SliceRandom;
use rand::{seq::SliceRandom, Rng};
use slog::{crit, debug, o, warn};
use std::collections::{btree_map::Entry, BTreeMap, HashSet};
use std::hash::{Hash, Hasher};
Expand Down Expand Up @@ -874,16 +874,20 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
// Find a peer to request the batch
let failed_peers = batch.failed_peers();

let new_peer = {
let mut priorized_peers = self
.peers
.iter()
.map(|(peer, requests)| (failed_peers.contains(peer), requests.len(), *peer))
.collect::<Vec<_>>();
let new_peer = self
.peers
.iter()
.map(|(peer, requests)| {
(
failed_peers.contains(peer),
requests.len(),
rand::thread_rng().gen::<u32>(),
*peer,
)
})
// Sort peers prioritizing unrelated peers with less active requests.
priorized_peers.sort_unstable();
priorized_peers.first().map(|&(_, _, peer)| peer)
};
.min()
.map(|(_, _, _, peer)| peer);

if let Some(peer) = new_peer {
self.send_batch(network, batch_id, peer)
Expand Down
Loading