Handles BlocksByRange step parameter around skip slots (#1146)

This commit is contained in:
Age Manning 2020-05-14 22:41:02 +10:00 committed by GitHub
parent 01f42a4d17
commit 1cb274008d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -359,13 +359,28 @@ impl<T: BeaconChainTypes> Processor<T> {
}
};
let mut block_roots = forwards_block_root_iter
// pick out the required blocks, ignoring skip-slots and stepping by the step parameter;
let mut last_block_root = None;
let block_roots = forwards_block_root_iter
.take_while(|(_root, slot)| slot.as_u64() < req.start_slot + req.count * req.step)
// map skip slots to None
.map(|(root, _slot)| {
let result = if Some(root) == last_block_root {
None
} else {
Some(root)
};
last_block_root = Some(root);
result
})
.step_by(req.step as usize)
.map(|(root, _slot)| root)
.collect::<Vec<_>>();
block_roots.dedup();
// remove all skip slots
let block_roots = block_roots
.into_iter()
.filter_map(|root| root)
.collect::<Vec<_>>();
let mut blocks_sent = 0;
for root in block_roots {