nimbus-eth2/beacon_chain
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
..
consensus_object_pools limit by-root requests to non-finalized blocks (#3293) 2022-01-21 13:33:16 +02:00
eth1 allow Eth1 monitor to run without genesis_deposit_contract_snapshot.ssz (#3279) 2022-01-21 12:59:09 +02:00
fork_choice limit by-root requests to non-finalized blocks (#3293) 2022-01-21 13:33:16 +02:00
gossip_processing limit by-root requests to non-finalized blocks (#3293) 2022-01-21 13:33:16 +02:00
networking rename *_{MERGE => BELLATRIX} constant names (#3296) 2022-01-18 16:31:05 +00:00
rpc limit by-root requests to non-finalized blocks (#3293) 2022-01-21 13:33:16 +02:00
spec rename MERGE_FORK_VERSION to BELLATRIX_FORK_VERSION 2022-01-20 19:33:05 +02:00
sync limit by-root requests to non-finalized blocks (#3293) 2022-01-21 13:33:16 +02:00
validator_client time: spring cleaning (#3262) 2022-01-11 11:01:54 +01:00
validators limit by-root requests to non-finalized blocks (#3293) 2022-01-21 13:33:16 +02:00
.editorconfig Add .editorconfig file and remove trailing newlines 2021-09-14 12:12:49 +03:00
.gitignore Rename binaries; Mimic the original repo layout in the distribution 2020-11-09 11:38:52 +02:00
beacon_chain_db.nim Precise per-component ETH-denominated rewards tracking 2022-01-18 01:56:56 +02:00
beacon_chain_db_immutable.nim Precise per-component ETH-denominated rewards tracking 2022-01-18 01:56:56 +02:00
beacon_clock.nim time: spring cleaning (#3262) 2022-01-11 11:01:54 +01:00
beacon_node.nim Backfiller (#3263) 2022-01-20 08:25:45 +01:00
beacon_node_status.nim EH cleanup (#2455) 2021-03-26 07:52:01 +01:00
conf.nim Backfiller (#3263) 2022-01-20 08:25:45 +01:00
extras.nim use ForkedHashedBeaconState in StateData (#2634) 2021-06-11 20:51:46 +03:00
filepath.nim EH cleanup (#2455) 2021-03-26 07:52:01 +01:00
interop.nim bump `nim-stint` (#2969) 2021-10-14 14:13:51 +03:00
nim.cfg Revert writing backfill root to database (#3215) 2021-12-21 11:40:14 +01:00
nimbus_beacon_node.nim allow Eth1 monitor to run without genesis_deposit_contract_snapshot.ssz (#3279) 2022-01-21 12:59:09 +02:00
nimbus_beacon_node.nim.cfg Revert writing backfill root to database (#3215) 2021-12-21 11:40:14 +01:00
nimbus_binary_common.nim time: spring cleaning (#3262) 2022-01-11 11:01:54 +01:00
nimbus_signing_node.nim complete switch to beacon_chain/specs/datatypes/bellatrix (#3295) 2022-01-18 13:36:52 +00:00
nimbus_signing_node.nim.cfg Revert writing backfill root to database (#3215) 2021-12-21 11:40:14 +01:00
nimbus_validator_client.nim time: spring cleaning (#3262) 2022-01-11 11:01:54 +01:00
nimbus_validator_client.nim.cfg Revert writing backfill root to database (#3215) 2021-12-21 11:40:14 +01:00
sszdump.nim complete switch to beacon_chain/specs/datatypes/bellatrix (#3295) 2022-01-18 13:36:52 +00:00
statediff.nim time: spring cleaning (#3262) 2022-01-11 11:01:54 +01:00
statusbar.nim switch result = foo to expression return; unexport rest of logtrace symbols (#2788) 2021-08-17 09:51:39 +00:00
trusted_node_sync.nim limit by-root requests to non-finalized blocks (#3293) 2022-01-21 13:33:16 +02:00
version.nim Version 1.6.0 2022-01-14 13:52:06 +02:00