lighthouse-pulse/consensus
Michael Sproul b82f7843ff Use peeking_take_while in BlockReplayer (#4803)
## Issue Addressed

While reviewing #4801 I noticed that our use of `take_while` in the block replayer means that if a state root iterator _with gaps_ is provided, some additonal state roots will be dropped unnecessarily. In practice the impact is small, because once there's _one_ state root miss, the whole tree hash cache needs to be built anyway, and subsequent misses are less costly. However this was still a little inefficient, so I figured it's better to fix it.

## Proposed Changes

Use [`peeking_take_while`](https://docs.rs/itertools/latest/itertools/trait.Itertools.html#method.peeking_take_while) to avoid consuming the next element when checking whether it satisfies the slot predicate.

## Additional Info

There's a gist here that shows the basic dynamics in isolation: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=40b623cc0febf9ed51705d476ab140c5. Changing the `peeking_take_while` to a `take_while` causes the assert to fail. Similarly I've added a new test `block_replayer_peeking_state_roots` which fails if the same change is applied inside `get_state_root`.
2023-10-05 06:03:24 +00:00
..
cached_tree_hash Move dependencies to workspace (#4650) 2023-09-22 04:30:56 +00:00
fork_choice Move dependencies to workspace (#4650) 2023-09-22 04:30:56 +00:00
int_to_bytes Move dependencies to workspace (#4650) 2023-09-22 04:30:56 +00:00
merkle_proof Move dependencies to workspace (#4650) 2023-09-22 04:30:56 +00:00
proto_array Move dependencies to workspace (#4650) 2023-09-22 04:30:56 +00:00
safe_arith Move dependencies to workspace (#4650) 2023-09-22 04:30:56 +00:00
state_processing Use peeking_take_while in BlockReplayer (#4803) 2023-10-05 06:03:24 +00:00
swap_or_not_shuffle Move dependencies to workspace (#4650) 2023-09-22 04:30:56 +00:00
types Use only lighthouse types in the mock builder (#4793) 2023-10-03 17:59:28 +00:00