Skip to content

Commit aaad560

Browse files
committed
Always get up to chunk_size heights to request headers for
1 parent e7c1357 commit aaad560

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/blockchain/electrum.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,26 @@ impl Blockchain for ElectrumBlockchain {
112112
}
113113

114114
Request::Conftime(conftimereq) => {
115-
let needs_block_height = conftimereq
116-
.request()
117-
.filter_map(|txid| txid_to_height.get(txid).cloned())
118-
.filter(|height| block_times.get(height).is_none())
119-
.take(chunk_size)
120-
.collect::<HashSet<_>>();
121-
122-
let new_block_headers =
123-
self.client.batch_block_header(needs_block_height.clone())?;
115+
// collect up to chunk_size heights to fetch from electrum
116+
let needs_block_height = {
117+
let mut needs_block_height_iter = conftimereq
118+
.request()
119+
.filter_map(|txid| txid_to_height.get(txid).cloned())
120+
.filter(|height| block_times.get(height).is_none());
121+
let mut needs_block_height = HashSet::new();
122+
123+
while needs_block_height.len() < chunk_size {
124+
match needs_block_height_iter.next() {
125+
Some(height) => needs_block_height.insert(height),
126+
None => break,
127+
};
128+
}
129+
needs_block_height
130+
};
131+
132+
let new_block_headers = self
133+
.client
134+
.batch_block_header(needs_block_height.iter().cloned())?;
124135

125136
for (height, header) in needs_block_height.into_iter().zip(new_block_headers) {
126137
block_times.insert(height, header.time);

0 commit comments

Comments
 (0)