Always clean up block download list, report error

This commit is contained in:
Ignotus Peverell 2017-10-12 19:36:57 +00:00
parent 361e39c87c
commit 957e402eae
No known key found for this signature in database
GPG key ID: 99CD25F39F8F8211

View file

@ -142,14 +142,14 @@ impl Syncer {
/// downloading structure.
fn request_bodies(&self) {
let mut blocks_downloading = self.blocks_downloading.lock().unwrap();
if blocks_downloading.len() > MAX_BODY_DOWNLOADS {
// clean up potentially dead downloads
let twenty_sec_ago = Instant::now() - Duration::from_secs(20);
blocks_downloading
.iter()
.position(|&h| h.1 < twenty_sec_ago)
.map(|n| blocks_downloading.remove(n));
} else {
// consume hashes from blocks to download, place them in downloading and
// request them from the network
let mut blocks_to_download = self.blocks_to_download.lock().unwrap();
@ -157,9 +157,8 @@ impl Syncer {
let h = blocks_to_download.pop().unwrap();
let peer = self.p2p.random_peer().unwrap();
let send_result = peer.send_block_request(h);
match send_result {
Ok(_) => {}
Err(_) => {}
if let Err(e) = send_result {
debug!(LOGGER, "Error requesting block: {:?}", e);
}
blocks_downloading.push((h, Instant::now()));
}
@ -169,7 +168,6 @@ impl Syncer {
blocks_to_download.len()
);
}
}
/// We added a block, clean up the downloading structure
pub fn block_received(&self, bh: Hash) {