Jacek Sieka d583e8e4ac
Store finalized block roots in database (3s startup) (#3320)
* Store finalized block roots in database (3s startup)

When the chain has finalized a checkpoint, the history from that point
onwards becomes linear - this is exploited in `.era` files to allow
constant-time by-slot lookups.

In the database, we can do the same by storing finalized block roots in
a simple sparse table indexed by slot, bringing the two representations
closer to each other in terms of conceptual layout and performance.

Doing so has a number of interesting effects:

* mainnet startup time is improved 3-5x (3s on my laptop)
* the _first_ startup might take slightly longer as the new index is
being built - ~10s on the same laptop
* we no longer rely on the beacon block summaries to load the full dag -
this is a lot faster because we no longer have to look up each block by
parent root
* a collateral benefit is that we no longer need to load the full
summaries table into memory - we get the RSS benefits of #3164 without
the CPU hit.

Other random stuff:

* simplify forky block generics
* fix withManyWrites multiple evaluation
* fix validator key cache not being updated properly in chaindag
read-only mode
* drop pre-altair summaries from `kvstore`
* recreate missing summaries from altair+ blocks as well (in case
database has lost some to an involuntary restart)
* print database startup timings in chaindag load log
* avoid allocating superfluos state at startup
* use a recursive sql query to load the summaries of the unfinalized
blocks
2022-01-30 18:51:04 +02:00
..
2021-09-29 14:19:20 +03:00
2021-02-02 19:02:52 +01:00
2021-08-20 18:39:18 +00:00
2021-11-09 13:33:53 +02:00
2021-08-20 18:39:18 +00:00
2022-01-16 18:26:21 +02:00
2022-01-05 17:33:23 +01:00
2021-08-20 18:39:18 +00:00
2020-10-06 15:46:22 +03:00
2021-01-07 13:12:37 +01:00
2021-08-20 18:39:18 +00:00
2021-02-02 19:02:52 +01:00
2022-01-11 09:35:20 +00:00
2021-10-14 14:13:51 +03:00
2020-03-18 17:20:34 +01:00
2021-08-20 18:39:18 +00:00
2021-02-25 14:20:26 +02:00