From 1d3dd3517594377a552aa853abea8a99928a55dc Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 4 Aug 2020 17:50:19 +1000 Subject: [PATCH] fix: Include the current tip in the block locator The state service was providing block locators starting at the parent of the current tip. Instead, include the current tip in the block locator. Also handle an edge case where we could include the genesis block twice, if the current tip height was a power of two. Fixes an instance of #818 where we re-download the current tip. --- zebra-state/src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/zebra-state/src/lib.rs b/zebra-state/src/lib.rs index a37309cd..06dd883a 100644 --- a/zebra-state/src/lib.rs +++ b/zebra-state/src/lib.rs @@ -142,9 +142,12 @@ pub enum Response { /// Get the heights of the blocks for constructing a block_locator list fn block_locator_heights(tip_height: BlockHeight) -> impl Iterator { - iter::successors(Some(1u32), |h| h.checked_mul(2)) + let locators = iter::successors(Some(1u32), |h| h.checked_mul(2)) .flat_map(move |step| tip_height.0.checked_sub(step)) - .map(BlockHeight) + .filter(|&height| height != 0) + .map(BlockHeight); + iter::once(tip_height) + .chain(locators) .chain(iter::once(BlockHeight(0))) }