Skip to content

Commit

Permalink
fix(node): periodic replicate shall have a wider range
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed Jan 20, 2025
1 parent 0102fe4 commit 5364562
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions ant-networking/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,11 +1133,18 @@ impl SwarmDriver {
}

// Replies with in-range replicate candidates
// Fall back to CLOSE_GROUP_SIZE peers if range is too narrow.
// Fall back to expected_candidates peers if range is too narrow.
// Note that:
// * For general replication, replicate candidates shall be the closest to self
// * For general replication, replicate candidates shall be closest to self, but with wider range
// * For replicate fresh records, the replicate candidates shall be the closest to data
pub(crate) fn get_replicate_candidates(&mut self, target: &NetworkAddress) -> Vec<PeerId> {
let is_periodic_replicate = target.as_peer_id().is_some();
let expected_candidates = if is_periodic_replicate {
CLOSE_GROUP_SIZE + 2
} else {
CLOSE_GROUP_SIZE
};

// get closest peers from buckets, sorted by increasing distance to the target
let kbucket_key = target.as_kbucket_key();
let closest_k_peers: Vec<PeerId> = self
Expand All @@ -1158,15 +1165,15 @@ impl SwarmDriver {
{
let peers_in_range = get_peers_in_range(&closest_k_peers, target, responsible_range);

if peers_in_range.len() >= CLOSE_GROUP_SIZE {
if peers_in_range.len() >= expected_candidates {
return peers_in_range;
}
}

// In case the range is too narrow, fall back to at least CLOSE_GROUP_SIZE peers.
// In case the range is too narrow, fall back to at least expected_candidates peers.
closest_k_peers
.iter()
.take(CLOSE_GROUP_SIZE)
.take(expected_candidates)
.cloned()
.collect()
}
Expand Down

0 comments on commit 5364562

Please sign in to comment.