nimbus-eth2/beacon_chain
Jacek Sieka 4207b127f9
era: load blocks and states (#3394)
* era: load blocks and states

Era files contain finalized history and can be thought of as an
alternative source for block and state data that allows clients to avoid
syncing this information from the P2P network - the P2P network is then
used to "top up" the client with the most recent data. They can be
freely shared in the community via whatever means (http, torrent, etc)
and serve as a permanent cold store of consensus data (and, after the
merge, execution data) for history buffs and bean counters alike.

This PR gently introduces support for loading blocks and states in two
cases: block requests from rest/p2p and frontfilling when doing
checkpoint sync.

The era files are used as a secondary source if the information is not
found in the database - compared to the database, there are a few key
differences:

* the database stores the block indexed by block root while the era file
indexes by slot - the former is used only in rest, while the latter is
used both by p2p and rest.
* when loading blocks from era files, the root is no longer trivially
available - if it is needed, it must either be computed (slow) or cached
(messy) - the good news is that for p2p requests, it is not needed
* in era files, "framed" snappy encoding is used while in the database
we store unframed snappy - for p2p2 requests, the latter requires
recompression while the former could avoid it
* front-filling is the process of using era files to replace backfilling
- in theory this front-filling could happen from any block and
front-fills with gaps could also be entertained, but our backfilling
algorithm cannot take advantage of this because there's no (simple) way
to tell it to "skip" a range.
* front-filling, as implemented, is a bit slow (10s to load mainnet): we
load the full BeaconState for every era to grab the roots of the blocks
- it would be better to partially load the state - as such, it would
also be good to be able to partially decompress snappy blobs
* lookups from REST via root are served by first looking up a block
summary in the database, then using the slot to load the block data from
the era file - however, there needs to be an option to create the
summary table from era files to fully support historical queries

To test this, `ncli_db` has an era file exporter: the files it creates
should be placed in an `era` folder next to `db` in the data directory.
What's interesting in particular about this setup is that `db` remains
as the source of truth for security purposes - it stores the latest
synced head root which in turn determines where a node "starts" its
consensus participation - the era directory however can be freely shared
between nodes / people without any (significant) security implications,
assuming the era files are consistent / not broken.

There's lots of future improvements to be had:

* we can drop the in-memory `BlockRef` index almost entirely - at this
point, resident memory usage of Nimbus should drop to a cool 500-600 mb
* we could serve era files via REST trivially: this would drop backfill
times to whatever time it takes to download the files - unlike the
current implementation that downloads block by block, downloading an era
at a time almost entirely cuts out request overhead
* we can "reasonably" recreate detailed state history from almost any
point in time, turning an O(slot) process into O(1) effectively - we'll
still need caches and indices to do this with sufficient efficiency for
the rest api, but at least it cuts the whole process down to minutes
instead of hours, for arbitrary points in time

* CI: ignore failures with Nim-1.6 (temporary)

* test fixes

Co-authored-by: Ștefan Talpalaru <stefantalpalaru@yahoo.com>
2022-03-23 09:58:17 +01:00
..
consensus_object_pools era: load blocks and states (#3394) 2022-03-23 09:58:17 +01:00
eth1 better error messages on directory creation failure (#3536) 2022-03-22 17:06:21 +00:00
fork_choice era: load blocks and states (#3394) 2022-03-23 09:58:17 +01:00
gossip_processing introduce light client processor (#3509) 2022-03-17 23:26:56 +01:00
networking enable chronosStrictException (#3533) 2022-03-22 09:42:28 +01:00
rpc Prune `BlockRef` on finalization (#3513) 2022-03-17 17:42:56 +00:00
spec era: load blocks and states (#3394) 2022-03-23 09:58:17 +01:00
sync era: load blocks and states (#3394) 2022-03-23 09:58:17 +01:00
validator_client VC: Fix forks handling. (#3389) 2022-02-16 12:31:23 +01:00
validators refer to `syncCommitteeMsgPool` consistently (#3537) 2022-03-23 07:46:48 +01: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 era: load blocks and states (#3394) 2022-03-23 09:58:17 +01:00
beacon_chain_db_immutable.nim rename random -> prev_randao in Bellatrix for CL specs v1.1.10 (#3460) 2022-03-03 16:08:14 +00:00
beacon_clock.nim automated CL spec ref URL updates from v1.1.9 to v1.1.10 (#3455) 2022-03-02 10:00:21 +00:00
beacon_node.nim move wallet/deposit commands to separate files (#3372) 2022-02-11 21:40:49 +01:00
beacon_node_status.nim EH cleanup (#2455) 2021-03-26 07:52:01 +01:00
conf.nim era: load blocks and states (#3394) 2022-03-23 09:58:17 +01:00
deposits.nim better error messages on directory creation failure (#3536) 2022-03-22 17:06:21 +00:00
era_db.nim era: load blocks and states (#3394) 2022-03-23 09:58:17 +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 enable chronosStrictException (#3533) 2022-03-22 09:42:28 +01:00
nimbus_beacon_node.nim era: load blocks and states (#3394) 2022-03-23 09:58:17 +01: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 Helpful error message when the user fails to use an array type in TOML 2022-03-09 19:11:41 +02:00
nimbus_signing_node.nim Allow running Nimbus as a Windows service (--run-as-service) 2022-03-05 15:53:47 +02: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 Allow running Nimbus as a Windows service (--run-as-service) 2022-03-05 15:53:47 +02:00
nimbus_validator_client.nim.cfg Revert writing backfill root to database (#3215) 2021-12-21 11:40:14 +01:00
sszdump.nim introduce light client processor (#3509) 2022-03-17 23:26:56 +01: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 tns: checkpoint wal periodically while backfilling (#3516) 2022-03-18 12:32:20 +01:00
version.nim Final v22.3.0: Add examples for migrating from JSON-RCP to REST 2022-03-10 16:46:11 +02:00
wallets.nim move wallet/deposit commands to separate files (#3372) 2022-02-11 21:40:49 +01:00