Skip to content

Commit

Permalink
Don't use peers.iter().next() in bodysync
Browse files Browse the repository at this point in the history
- We don't actually need to mutate this value at all.  We can just take the peer by index
- This also removes cycle behavior in bodysync as it pertains to peerlist polling
- Result is that we request 1 block from 1 peer, at a given time
  • Loading branch information
who-biz committed Nov 7, 2023
1 parent 4f17617 commit 0991826
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions servers/src/epic/sync/body_sync.rs
Expand Up @@ -135,15 +135,17 @@ impl BodySync {
self.blocks_requested = 0;
self.receive_timeout = Utc::now() + Duration::seconds(6);

let mut peers_iter = peers.iter().cycle();
let mut peer_idx = 0;
for hash in hashes_to_get.clone() {
if let Some(peer) = peers_iter.next() {
if let Err(e) = peer.send_block_request(*hash, chain::Options::SYNC) {
debug!("Skipped request to {}: {:?}", peer.info.addr, e);
peer.stop();
} else {
self.blocks_requested += 1;
}
if let Err(e) = peers[peer_idx].send_block_request(*hash, chain::Options::SYNC) {
debug!("Skipped request to {}: {:?}", peers[peer_idx].info.addr, e);
peers[peer_idx].stop();
} else {
self.blocks_requested += 1;
}
peer_idx += 1;
if peer_idx == peers.len() {
break;
}
}
}
Expand Down

0 comments on commit 0991826

Please sign in to comment.