mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
Always clean up block download list, report error
This commit is contained in:
parent
361e39c87c
commit
957e402eae
1 changed files with 23 additions and 25 deletions
|
@ -142,14 +142,14 @@ impl Syncer {
|
||||||
/// downloading structure.
|
/// downloading structure.
|
||||||
fn request_bodies(&self) {
|
fn request_bodies(&self) {
|
||||||
let mut blocks_downloading = self.blocks_downloading.lock().unwrap();
|
let mut blocks_downloading = self.blocks_downloading.lock().unwrap();
|
||||||
if blocks_downloading.len() > MAX_BODY_DOWNLOADS {
|
|
||||||
// clean up potentially dead downloads
|
// clean up potentially dead downloads
|
||||||
let twenty_sec_ago = Instant::now() - Duration::from_secs(20);
|
let twenty_sec_ago = Instant::now() - Duration::from_secs(20);
|
||||||
blocks_downloading
|
blocks_downloading
|
||||||
.iter()
|
.iter()
|
||||||
.position(|&h| h.1 < twenty_sec_ago)
|
.position(|&h| h.1 < twenty_sec_ago)
|
||||||
.map(|n| blocks_downloading.remove(n));
|
.map(|n| blocks_downloading.remove(n));
|
||||||
} else {
|
|
||||||
// consume hashes from blocks to download, place them in downloading and
|
// consume hashes from blocks to download, place them in downloading and
|
||||||
// request them from the network
|
// request them from the network
|
||||||
let mut blocks_to_download = self.blocks_to_download.lock().unwrap();
|
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 h = blocks_to_download.pop().unwrap();
|
||||||
let peer = self.p2p.random_peer().unwrap();
|
let peer = self.p2p.random_peer().unwrap();
|
||||||
let send_result = peer.send_block_request(h);
|
let send_result = peer.send_block_request(h);
|
||||||
match send_result {
|
if let Err(e) = send_result {
|
||||||
Ok(_) => {}
|
debug!(LOGGER, "Error requesting block: {:?}", e);
|
||||||
Err(_) => {}
|
|
||||||
}
|
}
|
||||||
blocks_downloading.push((h, Instant::now()));
|
blocks_downloading.push((h, Instant::now()));
|
||||||
}
|
}
|
||||||
|
@ -169,7 +168,6 @@ impl Syncer {
|
||||||
blocks_to_download.len()
|
blocks_to_download.len()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// We added a block, clean up the downloading structure
|
/// We added a block, clean up the downloading structure
|
||||||
pub fn block_received(&self, bh: Hash) {
|
pub fn block_received(&self, bh: Hash) {
|
||||||
|
|
Loading…
Reference in a new issue