Always get up to chunk_size heights to request headers for
This commit is contained in:
parent
e7c13575c8
commit
aaad560a91
@ -112,15 +112,26 @@ impl Blockchain for ElectrumBlockchain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Request::Conftime(conftimereq) => {
|
Request::Conftime(conftimereq) => {
|
||||||
let needs_block_height = conftimereq
|
// collect up to chunk_size heights to fetch from electrum
|
||||||
.request()
|
let needs_block_height = {
|
||||||
.filter_map(|txid| txid_to_height.get(txid).cloned())
|
let mut needs_block_height_iter = conftimereq
|
||||||
.filter(|height| block_times.get(height).is_none())
|
.request()
|
||||||
.take(chunk_size)
|
.filter_map(|txid| txid_to_height.get(txid).cloned())
|
||||||
.collect::<HashSet<_>>();
|
.filter(|height| block_times.get(height).is_none());
|
||||||
|
let mut needs_block_height = HashSet::new();
|
||||||
|
|
||||||
let new_block_headers =
|
while needs_block_height.len() < chunk_size {
|
||||||
self.client.batch_block_header(needs_block_height.clone())?;
|
match needs_block_height_iter.next() {
|
||||||
|
Some(height) => needs_block_height.insert(height),
|
||||||
|
None => break,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
needs_block_height
|
||||||
|
};
|
||||||
|
|
||||||
|
let new_block_headers = self
|
||||||
|
.client
|
||||||
|
.batch_block_header(needs_block_height.iter().cloned())?;
|
||||||
|
|
||||||
for (height, header) in needs_block_height.into_iter().zip(new_block_headers) {
|
for (height, header) in needs_block_height.into_iter().zip(new_block_headers) {
|
||||||
block_times.insert(height, header.time);
|
block_times.insert(height, header.time);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user