Refactor block prod. to produce for forks

This commit is contained in:
Paul Hauner
2019-06-19 03:01:58 +10:00
parent 55196dff64
commit 55818e285a
4 changed files with 100 additions and 36 deletions

View File

@@ -182,7 +182,7 @@ impl<T: BeaconChainTypes> SimpleSync<T> {
&& (!self
.chain
.rev_iter_block_roots(local.best_slot)
.any(|root| root == remote.latest_finalized_root))
.any(|(root, _slot)| root == remote.latest_finalized_root))
&& (local.latest_finalized_root != spec.zero_hash)
&& (remote.latest_finalized_root != spec.zero_hash)
{
@@ -266,11 +266,12 @@ impl<T: BeaconChainTypes> SimpleSync<T> {
"start_slot" => req.start_slot,
);
let mut roots: Vec<Hash256> = self
let mut roots: Vec<BlockRootSlot> = self
.chain
.rev_iter_block_roots(req.start_slot + req.count)
.skip(1)
.take(req.count as usize)
.map(|(block_root, slot)| BlockRootSlot { slot, block_root })
.collect();
if roots.len() as u64 != req.count {
@@ -285,16 +286,6 @@ impl<T: BeaconChainTypes> SimpleSync<T> {
}
roots.reverse();
let mut roots: Vec<BlockRootSlot> = roots
.iter()
.enumerate()
.map(|(i, block_root)| BlockRootSlot {
slot: req.start_slot + Slot::from(i),
block_root: *block_root,
})
.collect();
roots.dedup_by_key(|brs| brs.block_root);
network.send_rpc_response(
@@ -392,6 +383,7 @@ impl<T: BeaconChainTypes> SimpleSync<T> {
.chain
.rev_iter_block_roots(req.start_slot + (count - 1))
.take(count as usize)
.map(|(root, _slot)| root)
.collect();
roots.reverse();