Download bodies for validated hash chain only
This commit is contained in:
parent
7ad7996144
commit
1fe575bf7b
@ -660,10 +660,7 @@ impl ChainSync {
|
||||
let mut needed_numbers: Vec<BlockNumber> = Vec::new();
|
||||
|
||||
if self.have_common_block && !self.headers.is_empty() && self.headers.range_iter().next().unwrap().0 == self.current_base_block() + 1 {
|
||||
for (start, ref items) in self.headers.range_iter() {
|
||||
if needed_bodies.len() >= MAX_BODIES_TO_REQUEST {
|
||||
break;
|
||||
}
|
||||
if let Some((start, ref items)) = self.headers.range_iter().next() {
|
||||
let mut index: BlockNumber = 0;
|
||||
while index != items.len() as BlockNumber && needed_bodies.len() < MAX_BODIES_TO_REQUEST {
|
||||
let block = start + index;
|
||||
@ -848,18 +845,8 @@ impl ChainSync {
|
||||
/// Remove downloaded bocks/headers starting from specified number.
|
||||
/// Used to recover from an error and re-download parts of the chain detected as bad.
|
||||
fn remove_downloaded_blocks(&mut self, start: BlockNumber) {
|
||||
for n in self.headers.get_tail(&start) {
|
||||
if let Some(ref header_data) = self.headers.find_item(&n) {
|
||||
let header_to_delete = HeaderView::new(&header_data.data);
|
||||
let header_id = HeaderId {
|
||||
transactions_root: header_to_delete.transactions_root(),
|
||||
uncles: header_to_delete.uncles_hash()
|
||||
};
|
||||
self.header_ids.remove(&header_id);
|
||||
}
|
||||
self.downloading_bodies.remove(&n);
|
||||
self.downloading_headers.remove(&n);
|
||||
}
|
||||
self.downloading_bodies.clear();
|
||||
self.downloading_headers.clear();
|
||||
self.headers.remove_from(&start);
|
||||
self.bodies.remove_from(&start);
|
||||
}
|
||||
|
@ -300,12 +300,17 @@ fn test_range() {
|
||||
let mut r = ranges.clone();
|
||||
r.remove_from(&20);
|
||||
assert_eq!(r.range_iter().cmp(vec![(2, &['b', 'c', 'd'][..]), (16, &['p', 'q', 'r'][..])]), Ordering::Equal);
|
||||
r.remove_from(&17);
|
||||
assert_eq!(r.range_iter().cmp(vec![(2, &['b', 'c', 'd'][..]), (16, &['p'][..])]), Ordering::Equal);
|
||||
r.remove_from(&15);
|
||||
r.remove_from(&18);
|
||||
assert!(!r.have_item(&18));
|
||||
assert_eq!(r.range_iter().cmp(vec![(2, &['b', 'c', 'd'][..]), (16, &['p', 'q'][..])]), Ordering::Equal);
|
||||
r.remove_from(&16);
|
||||
assert!(!r.have_item(&16));
|
||||
assert_eq!(r.range_iter().cmp(vec![(2, &['b', 'c', 'd'][..])]), Ordering::Equal);
|
||||
r.remove_from(&3);
|
||||
assert_eq!(r.range_iter().cmp(vec![(2, &['b'][..])]), Ordering::Equal);
|
||||
r.remove_from(&1);
|
||||
assert_eq!(r.range_iter().next(), None);
|
||||
let mut r = ranges.clone();
|
||||
r.remove_from(&2);
|
||||
assert_eq!(r.range_iter().next(), None);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user