lighthouse/book/src
Michael Sproul 66eca1a882 Refactor op pool for speed and correctness (#3312)
## Proposed Changes

This PR has two aims: to speed up attestation packing in the op pool, and to fix bugs in the verification of attester slashings, proposer slashings and voluntary exits. The changes are bundled into a single database schema upgrade (v12).

Attestation packing is sped up by removing several inefficiencies: 

- No more recalculation of `attesting_indices` during packing.
- No (unnecessary) examination of the `ParticipationFlags`: a bitfield suffices. See `RewardCache`.
- No re-checking of attestation validity during packing: the `AttestationMap` provides attestations which are "correct by construction" (I have checked this using Hydra).
- No SSZ re-serialization for the clunky `AttestationId` type (it can be removed in a future release).

So far the speed-up seems to be roughly 2-10x, from 500ms down to 50-100ms.

Verification of attester slashings, proposer slashings and voluntary exits is fixed by:

- Tracking the `ForkVersion`s that were used to verify each message inside the `SigVerifiedOp`. This allows us to quickly re-verify that they match the head state's opinion of what the `ForkVersion` should be at the epoch(s) relevant to the message.
- Storing the `SigVerifiedOp` on disk rather than the raw operation. This allows us to continue track the fork versions after a reboot.

This is mostly contained in this commit 52bb1840ae5c4356a8fc3a51e5df23ed65ed2c7f.

## Additional Info

The schema upgrade uses the justified state to re-verify attestations and compute `attesting_indices` for them. It will drop any attestations that fail to verify, by the logic that attestations are most valuable in the few slots after they're observed, and are probably stale and useless by the time a node restarts. Exits and proposer slashings and similarly re-verified to obtain `SigVerifiedOp`s.

This PR contains a runtime killswitch `--paranoid-block-proposal` which opts out of all the optimisations in favour of closely verifying every included message. Although I'm quite sure that the optimisations are correct this flag could be useful in the event of an unforeseen emergency.

Finally, you might notice that the `RewardCache` appears quite useless in its current form because it is only updated on the hot-path immediately before proposal. My hope is that in future we can shift calls to `RewardCache::update` into the background, e.g. while performing the state advance. It is also forward-looking to `tree-states` compatibility, where iterating and indexing `state.{previous,current}_epoch_participation` is expensive and needs to be minimised.
2022-08-29 09:10:26 +00:00
..
css Make API friendly to block explorers (#702) 2019-12-19 11:45:28 +11:00
js Add support for multiple testnet flags (#1396) 2020-07-29 06:39:29 +00:00
advanced_database.md Reformat tables and add borders (#3377) 2022-07-27 00:51:07 +00:00
advanced_metrics.md Add metrics to VC (#1954) 2020-11-26 01:10:51 +00:00
advanced_networking.md Fix typos in docs (#3121) 2022-03-28 07:14:15 +00:00
advanced-datadir.md Support legacy data directories (#2846) 2021-12-02 14:29:59 +11:00
advanced-pre-releases.md Fix links in docs (#3219) 2022-05-31 06:09:07 +00:00
advanced-release-candidates.md Use "release candidate" in book (#2920) 2022-01-17 06:09:58 +00:00
advanced.md Document the freezer DB space-time trade-off (#808) 2020-01-20 10:01:58 +11:00
api-bn.md Correct typos book (#3099) 2022-03-20 22:48:15 +00:00
api-lighthouse.md Merge readiness endpoint (#3349) 2022-07-21 05:45:39 +00:00
api-vc-auth-header.md Implement standard keystore API (#2736) 2022-01-30 23:22:04 +00:00
api-vc-endpoints.md Reformat tables and add borders (#3377) 2022-07-27 00:51:07 +00:00
api-vc-sig-header.md Implement VC API (#1657) 2020-10-02 09:42:19 +00:00
api-vc.md Implement standard keystore API (#2736) 2022-01-30 23:22:04 +00:00
api.md Rename Eth1/Eth2 in documents (#3021) 2022-03-02 01:05:08 +00:00
builders.md Standard gas limit api (#3450) 2022-08-15 01:30:58 +00:00
checkpoint-sync.md Add a section on using infura as the checkpoint sync provider (#2797) 2021-11-10 23:43:12 +00:00
cli.md Rename Eth1/Eth2 in documents (#3021) 2022-03-02 01:05:08 +00:00
contributing.md [Contribution docs] Add GitPOAP Badge to Display Number of Minted GitPOAPs for Contributors (#3343) 2022-08-09 02:27:04 +00:00
cross-compiling.md Modularise slasher backend (#3443) 2022-08-15 01:30:56 +00:00
database-migrations.md Refactor op pool for speed and correctness (#3312) 2022-08-29 09:10:26 +00:00
docker.md Fix some typos (#3376) 2022-07-27 00:51:06 +00:00
faq.md Tidy eth1/deposit contract logging (#3397) 2022-08-01 07:20:43 +00:00
graffiti.md Set graffiti per validator (#2044) 2021-03-02 22:35:46 +00:00
homebrew.md Document Homebrew package (#2885) 2022-01-08 01:15:07 +00:00
http.md Rename Eth1/Eth2 in documents (#3021) 2022-03-02 01:05:08 +00:00
installation-binaries.md More merge doc updates (#3509) 2022-08-26 21:47:50 +00:00
installation-priorities.md Reformat tables and add borders (#3377) 2022-07-27 00:51:07 +00:00
installation-source.md More merge doc updates (#3509) 2022-08-26 21:47:50 +00:00
installation.md More merge doc updates (#3509) 2022-08-26 21:47:50 +00:00
intro.md Rename Eth1/Eth2 in documents (#3021) 2022-03-02 01:05:08 +00:00
key-management.md Rename Eth1/Eth2 in documents (#3021) 2022-03-02 01:05:08 +00:00
key-recovery.md Rename Eth1/Eth2 in documents (#3021) 2022-03-02 01:05:08 +00:00
mainnet-validator.md Fix some typos (#3376) 2022-07-27 00:51:06 +00:00
merge-migration.md More merge doc updates (#3509) 2022-08-26 21:47:50 +00:00
pi.md Fix broken links in book (#2912) 2022-01-14 00:38:04 +00:00
redundancy.md More merge doc updates (#3509) 2022-08-26 21:47:50 +00:00
setup.md Fix some typos (#3376) 2022-07-27 00:51:06 +00:00
slasher.md Modularise slasher backend (#3443) 2022-08-15 01:30:56 +00:00
slashing-protection.md Fix some typos (#3376) 2022-07-27 00:51:06 +00:00
suggested-fee-recipient.md More merge doc updates (#3509) 2022-08-26 21:47:50 +00:00
SUMMARY.md Builder Specs v0.2.0 (#3134) 2022-07-30 00:22:37 +00:00
system-requirements.md Document system requirements (#1934) 2020-11-19 21:23:56 +00:00
testnet-validator.md Rename Eth1/Eth2 in documents (#3021) 2022-03-02 01:05:08 +00:00
validator-create.md Rename Eth1/Eth2 in documents (#3021) 2022-03-02 01:05:08 +00:00
validator-doppelganger.md Rename Eth1/Eth2 in documents (#3021) 2022-03-02 01:05:08 +00:00
validator-import-launchpad.md Fix some typos (#3376) 2022-07-27 00:51:06 +00:00
validator-inclusion.md Rename Eth1/Eth2 in documents (#3021) 2022-03-02 01:05:08 +00:00
validator-management.md Change --testnet flag to --network (#1751) 2020-11-23 23:54:03 +00:00
validator-monitoring.md Update broken api links (#2665) 2021-10-06 00:46:09 +00:00
validator-web3signer.md Add client authentication to Web3Signer validators (#3170) 2022-05-18 23:14:37 +00:00
voluntary-exit.md Correct typos book (#3099) 2022-03-20 22:48:15 +00:00
wallet-create.md Rename Eth1/Eth2 in documents (#3021) 2022-03-02 01:05:08 +00:00