lighthouse/beacon_node
Paul Hauner 5276dd0cb0 Fix edge-case when finding the finalized descendant (#3924)
## Issue Addressed

NA

## Description

We were missing an edge case when checking to see if a block is a descendant of the finalized checkpoint. This edge case is described for one of the tests in this PR:

a119edc739/consensus/proto_array/src/proto_array_fork_choice.rs (L1018-L1047)

This bug presented itself in the following mainnet log:

```
Jan 26 15:12:42.841 ERRO Unable to validate attestation error: MissingBeaconState(0x7c30cb80ec3d4ec624133abfa70e4c6cfecfca456bfbbbff3393e14e5b20bf25), peer_id: 16Uiu2HAm8RPRciXJYtYc5c3qtCRdrZwkHn2BXN3XP1nSi1gxHYit, type: "unaggregated", slot: Slot(5660161), beacon_block_root: 0x4a45e59da7cb9487f4836c83bdd1b741b4f31c67010c7ae343fa6771b3330489
```

Here the BN is rejecting an attestation because of a "missing beacon state". Whilst it was correct to reject the attestation, it should have rejected it because it attests to a block that conflicts with finality rather than claiming that the database is inconsistent.

The block that this attestation points to (`0x4a45`) is block `C` in the above diagram. It is a non-canonical block in the first slot of an epoch that conflicts with the finalized checkpoint. Due to our lazy pruning of proto array, `0x4a45` was still present in proto-array. Our missed edge-case in [`ForkChoice::is_descendant_of_finalized`](38514c07f2/consensus/fork_choice/src/fork_choice.rs (L1375-L1379)) would have indicated to us that the block is a descendant of the finalized block. Therefore, we would have accepted the attestation thinking that it attests to a descendant of the finalized *checkpoint*.

Since we didn't have the shuffling for this erroneously processed block, we attempted to read its state from the database. This failed because we prune states from the database by keeping track of the tips of the chain and iterating back until we find a finalized block. This would have deleted `C` from the database, hence the `MissingBeaconState` error.
2023-02-09 23:51:18 +00:00
..
beacon_chain Fix edge-case when finding the finalized descendant (#3924) 2023-02-09 23:51:18 +00:00
builder_client Verify execution block hashes during finalized sync (#3794) 2023-01-09 03:11:59 +00:00
client Improve validator monitor experience for high validator counts (#3728) 2023-01-09 08:18:55 +00:00
eth1 Clippy lints for rust 1.66 (#3810) 2022-12-16 04:04:00 +00:00
execution_layer Verify execution block hashes during finalized sync (#3794) 2023-01-09 03:11:59 +00:00
genesis Super small improvement: Remove unnecessary mut (#3736) 2022-11-21 03:15:54 +00:00
http_api Implement block_rewards API (per-validator reward) (#3907) 2023-02-07 08:33:23 +00:00
http_metrics Support IPv6 in BN and VC HTTP APIs (#3104) 2022-03-24 00:04:49 +00:00
lighthouse_network Self rate limiting dev flag (#3928) 2023-02-08 02:18:53 +00:00
network light client optimistic update reprocessing (#3799) 2023-01-24 22:17:50 +00:00
operation_pool Implement block_rewards API (per-validator reward) (#3907) 2023-02-07 08:33:23 +00:00
src Self rate limiting dev flag (#3928) 2023-02-08 02:18:53 +00:00
store Clippy lints for rust 1.66 (#3810) 2022-12-16 04:04:00 +00:00
tests Altair consensus changes and refactors (#2279) 2021-07-09 06:15:32 +00:00
timer Use async code when interacting with EL (#3244) 2022-07-03 05:36:50 +00:00
Cargo.toml Release v3.4.0 (#3862) 2023-01-11 03:27:08 +00:00