nimbus-eth2/beacon_chain/rpc
Jacek Sieka 05ffe7b2bf
Prune `BlockRef` on finalization (#3513)
Up til now, the block dag has been using `BlockRef`, a structure adapted
for a full DAG, to represent all of chain history. This is a correct and
simple design, but does not exploit the linearity of the chain once
parts of it finalize.

By pruning the in-memory `BlockRef` structure at finalization, we save,
at the time of writing, a cool ~250mb (or 25%:ish) chunk of memory
landing us at a steady state of ~750mb normal memory usage for a
validating node.

Above all though, we prevent memory usage from growing proportionally
with the length of the chain, something that would not be sustainable
over time -  instead, the steady state memory usage is roughly
determined by the validator set size which grows much more slowly. With
these changes, the core should remain sustainable memory-wise post-merge
all the way to withdrawals (when the validator set is expected to grow).

In-memory indices are still used for the "hot" unfinalized portion of
the chain - this ensure that consensus performance remains unchanged.

What changes is that for historical access, we use a db-based linear
slot index which is cache-and-disk-friendly, keeping the cost for
accessing historical data at a similar level as before, achieving the
savings at no percievable cost to functionality or performance.

A nice collateral benefit is the almost-instant startup since we no
longer load any large indicies at dag init.

The cost of this functionality instead can be found in the complexity of
having to deal with two ways of traversing the chain - by `BlockRef` and
by slot.

* use `BlockId` instead of `BlockRef` where finalized / historical data
may be required
* simplify clearance pre-advancement
* remove dag.finalizedBlocks (~50:ish mb)
* remove `getBlockAtSlot` - use `getBlockIdAtSlot` instead
* `parent` and `atSlot` for `BlockId` now require a `ChainDAGRef`
instance, unlike `BlockRef` traversal
* prune `BlockRef` parents on finality (~200:ish mb)
* speed up ChainDAG init by not loading finalized history index
* mess up light client server error handling - this need revisiting :)
2022-03-17 17:42:56 +00:00
..
rest_api.nim Validator key management API (#2755) 2021-10-04 22:08:31 +03:00
rest_beacon_api.nim Prune `BlockRef` on finalization (#3513) 2022-03-17 17:42:56 +00:00
rest_config_api.nim rename random -> prev_randao in Bellatrix for CL specs v1.1.10 (#3460) 2022-03-03 16:08:14 +00:00
rest_constants.nim time: spring cleaning (#3262) 2022-01-11 11:01:54 +01:00
rest_debug_api.nim Prune `BlockRef` on finalization (#3513) 2022-03-17 17:42:56 +00:00
rest_event_api.nim Put `application/json` as a higher preference than `application/octet-stream` 2022-01-30 18:50:14 +02:00
rest_key_management_api.nim The remote Keymanager API was not using the URLs indicated in the spec 2022-03-03 11:10:00 +02:00
rest_nimbus_api.nim Prune `BlockRef` on finalization (#3513) 2022-03-17 17:42:56 +00:00
rest_node_api.nim Use HTTP status codes instead of status in body. 2022-01-28 15:36:27 +02:00
rest_utils.nim Prune `BlockRef` on finalization (#3513) 2022-03-17 17:42:56 +00:00
rest_validator_api.nim Prune `BlockRef` on finalization (#3513) 2022-03-17 17:42:56 +00:00
rpc_api.nim REST API client, JSON-RPC cleanups (#2756) 2021-08-03 17:17:11 +02:00
rpc_beacon_api.nim Prune `BlockRef` on finalization (#3513) 2022-03-17 17:42:56 +00:00
rpc_config_api.nim remove StateData (#3507) 2022-03-16 08:20:40 +01:00
rpc_debug_api.nim remove StateData (#3507) 2022-03-16 08:20:40 +01:00
rpc_event_api.nim import cleanup (#2997) 2021-10-19 16:09:26 +02:00
rpc_nimbus_api.nim Prune `BlockRef` on finalization (#3513) 2022-03-17 17:42:56 +00:00
rpc_node_api.nim REST cleanups (#3255) 2022-01-08 22:06:34 +02:00
rpc_utils.nim Prune `BlockRef` on finalization (#3513) 2022-03-17 17:42:56 +00:00
rpc_validator_api.nim remove StateData (#3507) 2022-03-16 08:20:40 +01:00
state_ttl_cache.nim Prune `BlockRef` on finalization (#3513) 2022-03-17 17:42:56 +00:00