nimbus-eth2/beacon_chain/rpc
Jacek Sieka 61342c2449
limit by-root requests to non-finalized blocks (#3293)
* limit by-root requests to non-finalized blocks

Presently, we keep a mapping from block root to `BlockRef` in memory -
this has simplified reasoning about the dag, but is not sustainable with
the chain growing.

We can distinguish between two cases where by-root access is useful:

* unfinalized blocks - this is where the beacon chain is operating
generally, by validating incoming data as interesting for future fork
choice decisions - bounded by the length of the unfinalized period
* finalized blocks - historical access in the REST API etc - no bounds,
really

In this PR, we limit the by-root block index to the first use case:
finalized chain data can more efficiently be addressed by slot number.

Future work includes:

* limiting the `BlockRef` horizon in general - each instance is 40
bytes+overhead which adds up - this needs further refactoring to deal
with the tail vs state problem
* persisting the finalized slot-to-hash index - this one also keeps
growing unbounded (albeit slowly)

Anyway, this PR easily shaves ~128mb of memory usage at the time of
writing.

* No longer honor `BeaconBlocksByRoot` requests outside of the
non-finalized period - previously, Nimbus would generously return any
block through this libp2p request - per the spec, finalized blocks
should be fetched via `BeaconBlocksByRange` instead.
* return `Opt[BlockRef]` instead of `nil` when blocks can't be found -
this becomes a lot more common now and thus deserves more attention
* `dag.blocks` -> `dag.forkBlocks` - this index only carries unfinalized
blocks from now - `finalizedBlocks` covers the other `BlockRef`
instances
* in backfill, verify that the last backfilled block leads back to
genesis, or panic
* add backfill timings to log
* fix missing check that `BlockRef` block can be fetched with
`getForkedBlock` reliably
* shortcut doppelganger check when feature is not enabled
* in REST/JSON-RPC, fetch blocks without involving `BlockRef`

* fix dag.blocks ref
2022-01-21 13:33:16 +02:00
..
rest_api.nim Validator key management API (#2755) 2021-10-04 22:08:31 +03:00
rest_beacon_api.nim limit by-root requests to non-finalized blocks (#3293) 2022-01-21 13:33:16 +02:00
rest_config_api.nim rename MERGE_FORK_VERSION to BELLATRIX_FORK_VERSION 2022-01-20 19:33:05 +02:00
rest_constants.nim time: spring cleaning (#3262) 2022-01-11 11:01:54 +01:00
rest_debug_api.nim REST JSON support improvements (#3232) 2022-01-06 08:38:40 +01:00
rest_event_api.nim REST JSON support improvements (#3232) 2022-01-06 08:38:40 +01:00
rest_key_management_api.nim shift block_sim fork epochs; allow VC to work with non-multiple-of-3 SECONDS_PER_SLOT (#3244) 2022-01-05 13:41:39 +00:00
rest_nimbus_api.nim Support more content-types when specifying the Graffiti string 2022-01-06 10:56:59 +02:00
rest_node_api.nim REST cleanups (#3255) 2022-01-08 22:06:34 +02:00
rest_utils.nim limit by-root requests to non-finalized blocks (#3293) 2022-01-21 13:33:16 +02:00
rest_validator_api.nim limit by-root requests to non-finalized blocks (#3293) 2022-01-21 13:33:16 +02:00
rpc_api.nim REST API client, JSON-RPC cleanups (#2756) 2021-08-03 17:17:11 +02:00
rpc_beacon_api.nim limit by-root requests to non-finalized blocks (#3293) 2022-01-21 13:33:16 +02:00
rpc_config_api.nim REST cleanups (#3255) 2022-01-08 22:06:34 +02:00
rpc_debug_api.nim import cleanup (#2997) 2021-10-19 16:09:26 +02:00
rpc_event_api.nim import cleanup (#2997) 2021-10-19 16:09:26 +02:00
rpc_nimbus_api.nim Handle access to historical data for which there is no state (#3217) 2022-01-05 19:38:04 +01:00
rpc_node_api.nim REST cleanups (#3255) 2022-01-08 22:06:34 +02:00
rpc_utils.nim limit by-root requests to non-finalized blocks (#3293) 2022-01-21 13:33:16 +02:00
rpc_validator_api.nim move `state_transition` to `Result` (#3284) 2022-01-17 12:19:58 +01:00
state_ttl_cache.nim Implement #3129 (Optimized history traversals in the REST API) (#3219) 2022-01-05 15:49:10 +01:00