diff --git a/ant-networking/src/cmd.rs b/ant-networking/src/cmd.rs index bb0d9d022d..641d00c656 100644 --- a/ant-networking/src/cmd.rs +++ b/ant-networking/src/cmd.rs @@ -1149,7 +1149,7 @@ impl SwarmDriver { ) -> Result> { let is_periodic_replicate = target.as_peer_id().is_some(); let expected_candidates = if is_periodic_replicate { - CLOSE_GROUP_SIZE + 4 + CLOSE_GROUP_SIZE * 2 } else { CLOSE_GROUP_SIZE }; diff --git a/ant-networking/src/replication_fetcher.rs b/ant-networking/src/replication_fetcher.rs index 6ccf29850e..be6740c0e6 100644 --- a/ant-networking/src/replication_fetcher.rs +++ b/ant-networking/src/replication_fetcher.rs @@ -466,16 +466,19 @@ impl ReplicationFetcher { "Distance to target {addr:?} is {distance:?}, against range {distance_range:?}" ); let mut is_in_range = distance <= *distance_range; - if !is_in_range { + // For middle-range records, they could be farther than distance_range, + // but still supposed to be held by the closest group to us. + if !is_in_range && distance - *distance_range < *distance_range { closest_k_peers.sort_by_key(|key| key.distance(addr)); let closest_group: HashSet<_> = closest_k_peers.iter().take(CLOSE_GROUP_SIZE).collect(); if closest_group.contains(&self_address) { debug!("Record {addr:?} has a far distance but still among {CLOSE_GROUP_SIZE} closest within {} neighbourd.", closest_k_peers.len()); is_in_range = true; - } else { - out_of_range_keys.push(addr.clone()); } } + if !is_in_range { + out_of_range_keys.push(addr.clone()); + } is_in_range }); }