lighthouse/consensus
Paul Hauner a17f74896a Fix bad assumption when checking finalized descendant (#1629)
## Issue Addressed

- Resolves #1616

## Proposed Changes

Fixes a bug where we are unable to read the finalized block from fork choice.

## Detail

I had made an assumption that the finalized block always has a parent root of `None`:

e5fc6bab48/consensus/fork_choice/src/fork_choice.rs (L749-L752)

This was a faulty assumption, we don't set parent *roots* to `None`. Instead we *sometimes* set parent *indices* to `None`, depending if this pruning condition is satisfied: 

e5fc6bab48/consensus/proto_array/src/proto_array.rs (L229-L232) 

The bug manifested itself like this:

1. We attempt to get the finalized block from fork choice
1. We try to check that the block is descendant of the finalized block (note: they're the same block).
1. We expect the parent root to be `None`, but it's actually the parent root of the finalized root.
1. We therefore end up checking if the parent of the finalized root is a descendant of itself. (note: it's an *ancestor* not a *descendant*).
1. We therefore declare that the finalized block is not a descendant of (or eq to) the finalized block. Bad.

## Additional Info

In reflection, I made a poor assumption in the quest to obtain a probably negligible performance gain. The performance gain wasn't worth the risk and we got burnt.
2020-09-18 05:14:31 +00:00
..
cached_tree_hash Update smallvec (#1339) 2020-07-07 16:57:27 +10:00
fork_choice Fix bad assumption when checking finalized descendant (#1629) 2020-09-18 05:14:31 +00:00
int_to_bytes Directory Restructure (#1163) 2020-05-18 21:24:23 +10:00
merkle_proof Deny warnings on CI (#1372) 2020-07-21 05:51:33 +00:00
proto_array Shift HTTP server heavy-lifting to blocking executor (#1518) 2020-08-24 03:06:10 +00:00
safe_arith Directory Restructure (#1163) 2020-05-18 21:24:23 +10:00
serde_hex Directory Restructure (#1163) 2020-05-18 21:24:23 +10:00
serde_utils Add serde_utils module with quoted u64 support (#1588) 2020-09-07 01:03:53 +00:00
ssz Fix clippy warnings (#1385) 2020-07-23 14:18:00 +00:00
ssz_derive Fix eval order lint in ssz_derive (#1210) 2020-05-28 11:37:40 +10:00
ssz_types Fix clippy warnings (#1385) 2020-07-23 14:18:00 +00:00
state_processing Remove redundant decompression in process_deposit (#1610) 2020-09-14 10:58:15 +00:00
swap_or_not_shuffle Bump all spec tags to v0.12.1 (#1275) 2020-06-19 11:18:27 +10:00
tree_hash Add caching for state.eth1_data_votes (#919) 2020-07-24 02:19:47 +00:00
tree_hash_derive Directory Restructure (#1163) 2020-05-18 21:24:23 +10:00
types Don't quote slot and epoch, for now (#1597) 2020-09-08 02:12:36 +00:00