lighthouse/beacon_node/http_api/tests
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
..
broadcast_validation_tests.rs Add broadcast validation routes to Beacon Node HTTP API (#4316) 2023-06-29 12:02:38 +00:00
fork_tests.rs Remove hidden re-exports to appease Rust 1.73 (#4495) 2023-07-12 07:06:00 +00:00
interactive_tests.rs Fix HTTP state API bug and add --epochs-per-migration (#4236) 2023-07-17 00:14:12 +00:00
main.rs Add broadcast validation routes to Beacon Node HTTP API (#4316) 2023-06-29 12:02:38 +00:00
status_tests.rs Update node health endpoint (#4310) 2023-06-30 01:13:04 +00:00
tests.rs Update node health endpoint (#4310) 2023-06-30 01:13:04 +00:00