lighthouse/beacon_node/http_api/src
Michael Sproul 6c375205fb Fix HTTP state API bug and add --epochs-per-migration (#4236)
## Issue Addressed

Fix an issue observed by `@zlan` on Discord where Lighthouse would sometimes return this error when looking up states via the API:

> {"code":500,"message":"UNHANDLED_ERROR: ForkChoiceError(MissingProtoArrayBlock(0xc9cf1495421b6ef3215d82253b388d77321176a1dcef0db0e71a0cd0ffc8cdb7))","stacktraces":[]}

## Proposed Changes

The error stems from a faulty assumption in the HTTP API logic: that any state in the hot database must have its block in fork choice. This isn't true because the state's hot database may update much less frequently than the fork choice store, e.g. if reconstructing states (where freezer migration pauses), or if the freezer migration runs slowly. There could also be a race between loading the hot state and checking fork choice, e.g. even if the finalization migration of DB+fork choice were atomic, the update could happen between the 1st and 2nd calls.

To address this I've changed the HTTP API logic to use the finalized block's execution status as a fallback where it is safe to do so. In the case where a block is non-canonical and prior to finalization (permanently orphaned) we default `execution_optimistic` to `true`.

## Additional Info

I've also added a new CLI flag to reduce the frequency of the finalization migration as this is useful for several purposes:

- Spacing out database writes (less frequent, larger batches)
- Keeping a limited chain history with high availability, e.g. the last month in the hot database.

This new flag made it _substantially_ easier to test this change. It was extracted from `tree-states` (where it's called `--db-migration-period`), which is why this PR also carries the `tree-states` label.
2023-07-17 00:14:12 +00:00
..
attestation_performance.rs improve error message (#4141) 2023-03-28 22:07:05 +00:00
attester_duties.rs Add finalized to HTTP API responses (#3753) 2023-03-30 06:08:37 +00:00
block_id.rs Add finalized to HTTP API responses (#3753) 2023-03-30 06:08:37 +00:00
block_packing_efficiency.rs Separate execution payloads in the DB (#3157) 2022-05-12 00:42:17 +00:00
block_rewards.rs Cache target attester balances for unrealized FFG progression calculation (#4362) 2023-06-30 01:13:06 +00:00
database.rs Use async code when interacting with EL (#3244) 2022-07-03 05:36:50 +00:00
lib.rs Update node health endpoint (#4310) 2023-06-30 01:13:04 +00:00
metrics.rs Reduce false positive logging for late builder blocks (#4073) 2023-03-17 00:44:03 +00:00
proposer_duties.rs Add finalized to HTTP API responses (#3753) 2023-03-30 06:08:37 +00:00
publish_blocks.rs Add broadcast validation routes to Beacon Node HTTP API (#4316) 2023-06-29 12:02:38 +00:00
standard_block_rewards.rs Add finalized to HTTP API responses (#3753) 2023-03-30 06:08:37 +00:00
state_id.rs Fix HTTP state API bug and add --epochs-per-migration (#4236) 2023-07-17 00:14:12 +00:00
sync_committee_rewards.rs Add finalized to HTTP API responses (#3753) 2023-03-30 06:08:37 +00:00
sync_committees.rs Aggregate subsets (#3493) 2023-06-27 01:06:49 +00:00
test_utils.rs Logging via the HTTP API (#4074) 2023-05-22 05:57:08 +00:00
ui.rs Split common crates out into their own repos (#3890) 2023-04-28 01:15:40 +00:00
validator_inclusion.rs Add finalized to HTTP API responses (#3753) 2023-03-30 06:08:37 +00:00
version.rs Add finalized to HTTP API responses (#3753) 2023-03-30 06:08:37 +00:00