lighthouse/consensus
Paul Hauner 88cc222204 Advance state to next slot after importing block (#2174)
## Issue Addressed

NA

## Proposed Changes

Add an optimization to perform `per_slot_processing` from the *leading-edge* of block processing to the *trailing-edge*. Ultimately, this allows us to import the block at slot `n` faster because we used the tail-end of slot `n - 1` to perform `per_slot_processing`.

Additionally, add a "block proposer cache" which allows us to cache the block proposer for some epoch. Since we're now doing trailing-edge `per_slot_processing`, we can prime this cache with the values for the next epoch before those blocks arrive (assuming those blocks don't have some weird forking).

There were several ancillary changes required to achieve this: 

- Remove the `state_root` field  of `BeaconSnapshot`, since there's no need to know it on a `pre_state` and in all other cases we can just read it from `block.state_root()`.
    - This caused some "dust" changes of `snapshot.beacon_state_root` to `snapshot.beacon_state_root()`, where the `BeaconSnapshot::beacon_state_root()` func just reads the state root from the block.
- Rename `types::ShuffingId` to `AttestationShufflingId`. I originally did this because I added a `ProposerShufflingId` struct which turned out to be not so useful. I thought this new name was more descriptive so I kept it.
- Address https://github.com/ethereum/eth2.0-specs/pull/2196
- Add a debug log when we get a block with an unknown parent. There was previously no logging around this case.
- Add a function to `BeaconState` to compute all proposers for an epoch without re-computing the active indices for each slot.

## Additional Info

- ~~Blocked on #2173~~
- ~~Blocked on #2179~~ That PR was wrapped into this PR.
- There's potentially some places where we could avoid computing the proposer indices in `per_block_processing` but I haven't done this here. These would be an optimization beyond the issue at hand (improving block propagation times) and I think this PR is already doing enough. We can come back for that later.

## TODO

- [x] Tidy, improve comments.
- [x] ~~Try avoid computing proposer index in `per_block_processing`?~~
2021-02-15 07:17:52 +00:00
..
cached_tree_hash Clippy 1.49.0 updates and dht persistence test fix (#2156) 2021-01-19 00:34:28 +00:00
fork_choice Advance state to next slot after importing block (#2174) 2021-02-15 07:17:52 +00:00
int_to_bytes Update to tokio 1.1 (#2172) 2021-02-10 23:29:49 +00:00
merkle_proof Implement matches! macro (#1777) 2020-10-15 21:42:43 +00:00
proto_array Advance state to next slot after importing block (#2174) 2021-02-15 07:17:52 +00:00
safe_arith Remove saturating arith from state_processing (#1644) 2020-09-25 05:18:21 +00:00
serde_utils Fix new clippy lints (#2036) 2020-12-03 01:10:26 +00:00
ssz Fix clippy errors on tests (#2160) 2021-01-28 23:31:06 +00:00
ssz_derive Clippy 1.49.0 updates and dht persistence test fix (#2156) 2021-01-19 00:34:28 +00:00
ssz_types Fix clippy errors on tests (#2160) 2021-01-28 23:31:06 +00:00
state_processing Advance state to next slot after importing block (#2174) 2021-02-15 07:17:52 +00:00
swap_or_not_shuffle Update for clippy 1.50 (#2193) 2021-02-15 00:09:12 +00:00
tree_hash fix a couple typos in comments in merkle_hasher (#2171) 2021-02-03 04:52:22 +00:00
tree_hash_derive Clippy 1.49.0 updates and dht persistence test fix (#2156) 2021-01-19 00:34:28 +00:00
types Advance state to next slot after importing block (#2174) 2021-02-15 07:17:52 +00:00