Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Minor fix in chain supplier and light provider #8906

Merged
merged 2 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions ethcore/light/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub trait Provider: Send + Sync {
/// results within must adhere to the `skip` and `reverse` parameters.
fn block_headers(&self, req: request::CompleteHeadersRequest) -> Option<request::HeadersResponse> {
use request::HashOrNumber;
const MAX_HEADERS_TO_SEND: u64 = 512;

if req.max == 0 { return None }

Expand Down Expand Up @@ -82,10 +83,12 @@ pub trait Provider: Send + Sync {
}
};

let headers: Vec<_> = (0u64..req.max as u64)
.map(|x: u64| x.saturating_mul(req.skip + 1))
let max = ::std::cmp::min(MAX_HEADERS_TO_SEND, req.max);

let headers: Vec<_> = (0u64..max)
.map(|x: u64| x.saturating_mul(req.skip.saturating_add(1)))
.take_while(|x| if req.reverse { x < &start_num } else { best_num.saturating_sub(start_num) >= *x })
.map(|x| if req.reverse { start_num - x } else { start_num + x })
.map(|x| if req.reverse { start_num.saturating_sub(x) } else { start_num.saturating_add(x) })
.map(|x| self.block_header(BlockId::Number(x)))
.take_while(|x| x.is_some())
.flat_map(|x| x)
Expand Down
6 changes: 3 additions & 3 deletions ethcore/sync/src/chain/supplier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl SyncSupplier {
let max_count = cmp::min(MAX_HEADERS_TO_SEND, max_headers);
let mut count = 0;
let mut data = Bytes::new();
let inc = (skip + 1) as BlockNumber;
let inc = skip.saturating_add(1) as BlockNumber;
let overlay = io.chain_overlay().read();

// We are checking the `overlay` as well since it's where the ForkBlock
Expand All @@ -155,9 +155,9 @@ impl SyncSupplier {
if number <= inc || number == 0 {
break;
}
number -= inc;
number = number.saturating_sub(inc);
} else {
number += inc;
number = number.saturating_add(inc);
}
}
let mut rlp = RlpStream::new_list(count as usize);
Expand Down