mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 11:31:08 +03:00
Merge pull request #1751 from yourowncrypto/peers-round-robin
Use round robin for peer selection in body sync
This commit is contained in:
commit
7290d4b93f
1 changed files with 11 additions and 10 deletions
|
@ -126,9 +126,14 @@ impl BodySync {
|
||||||
// if we have 5 peers to sync from then ask for 50 blocks total (peer_count *
|
// if we have 5 peers to sync from then ask for 50 blocks total (peer_count *
|
||||||
// 10) max will be 80 if all 8 peers are advertising more work
|
// 10) max will be 80 if all 8 peers are advertising more work
|
||||||
// also if the chain is already saturated with orphans, throttle
|
// also if the chain is already saturated with orphans, throttle
|
||||||
let peer_count = self.peers.more_work_peers().len();
|
let peers = if oldest_height < header_head.height.saturating_sub(horizon) {
|
||||||
|
self.peers.more_work_archival_peers()
|
||||||
|
} else {
|
||||||
|
self.peers.more_work_peers()
|
||||||
|
};
|
||||||
|
|
||||||
let block_count = cmp::min(
|
let block_count = cmp::min(
|
||||||
cmp::min(100, peer_count * 10),
|
cmp::min(100, peers.len() * 10),
|
||||||
chain::MAX_ORPHAN_SIZE.saturating_sub(self.chain.orphans_len()) + 1,
|
chain::MAX_ORPHAN_SIZE.saturating_sub(self.chain.orphans_len()) + 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -148,17 +153,13 @@ impl BodySync {
|
||||||
body_head.height,
|
body_head.height,
|
||||||
header_head.height,
|
header_head.height,
|
||||||
hashes_to_get,
|
hashes_to_get,
|
||||||
peer_count,
|
peers.len(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let mut peers_iter = peers.iter().cycle();
|
||||||
|
|
||||||
for hash in hashes_to_get.clone() {
|
for hash in hashes_to_get.clone() {
|
||||||
// only archival peers can be expected to have blocks older than horizon
|
if let Some(peer) = peers_iter.next() {
|
||||||
let peer = if oldest_height < header_head.height.saturating_sub(horizon) {
|
|
||||||
self.peers.more_work_archival_peer()
|
|
||||||
} else {
|
|
||||||
self.peers.more_work_peer()
|
|
||||||
};
|
|
||||||
if let Some(peer) = peer {
|
|
||||||
if let Err(e) = peer.send_block_request(*hash) {
|
if let Err(e) = peer.send_block_request(*hash) {
|
||||||
debug!(LOGGER, "Skipped request to {}: {:?}", peer.info.addr, e);
|
debug!(LOGGER, "Skipped request to {}: {:?}", peer.info.addr, e);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue