lighthouse/consensus/types/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
..
beacon_state Add mainnet merge values 🐼 (#3462) 2022-08-17 02:36:38 +00:00
test_utils Realized unrealized experimentation (#3322) 2022-07-25 23:53:26 +00:00
aggregate_and_proof.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
application_domain.rs Register validator api (#3194) 2022-06-30 00:49:21 +00:00
attestation_data.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
attestation_duty.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
attestation.rs Use SmallVec in Bitfield (#3025) 2022-02-17 23:55:04 +00:00
attester_slashing.rs Update for clippy 1.50 (#2193) 2021-02-15 00:09:12 +00:00
beacon_block_body.rs Use async code when interacting with EL (#3244) 2022-07-03 05:36:50 +00:00
beacon_block_header.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
beacon_block.rs Add mainnet merge values 🐼 (#3462) 2022-08-17 02:36:38 +00:00
beacon_committee.rs Directory Restructure (#1163) 2020-05-18 21:24:23 +10:00
beacon_state.rs Optimize historic committee calculation for the HTTP API (#3272) 2022-07-04 02:56:11 +00:00
builder_bid.rs Builder Specs v0.2.0 (#3134) 2022-07-30 00:22:37 +00:00
chain_spec.rs Add mainnet merge values 🐼 (#3462) 2022-08-17 02:36:38 +00:00
checkpoint.rs Bump all spec tags to v0.12.1 (#1275) 2020-06-19 11:18:27 +10:00
config_and_preset.rs Serve Bellatrix preset in BN API (#3425) 2022-08-10 07:52:59 +00:00
consts.rs v1.1.6 Fork Choice changes (#2822) 2021-12-13 20:43:22 +00:00
contribution_and_proof.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
deposit_data.rs Lazy hashing for SignedBeaconBlock in sync (#2916) 2022-01-14 07:20:54 +00:00
deposit_message.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
deposit.rs Lazy hashing for SignedBeaconBlock in sync (#2916) 2022-01-14 07:20:54 +00:00
enr_fork_id.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
eth1_data.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
eth_spec.rs Native support for Gnosis Beacon Chain network (#2931) 2022-01-27 22:58:33 +00:00
execution_block_hash.rs Builder Specs v0.2.0 (#3134) 2022-07-30 00:22:37 +00:00
execution_payload_header.rs Kiln mev boost (#3062) 2022-03-31 07:52:23 +00:00
execution_payload.rs Kiln mev boost (#3062) 2022-03-31 07:52:23 +00:00
fork_context.rs Update to spec v1.1.8 (#2893) 2022-01-19 00:24:19 +00:00
fork_data.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
fork_name.rs Serve Bellatrix preset in BN API (#3425) 2022-08-10 07:52:59 +00:00
fork.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
free_attestation.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
graffiti.rs Lazy hashing for SignedBeaconBlock in sync (#2916) 2022-01-14 07:20:54 +00:00
historical_batch.rs Bump all spec tags to v0.12.1 (#1275) 2020-06-19 11:18:27 +10:00
indexed_attestation.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
lib.rs Serve Bellatrix preset in BN API (#3425) 2022-08-10 07:52:59 +00:00
participation_flags.rs Quoted altair fields (2.0) (#2712) 2021-10-14 02:58:12 +00:00
participation_list.rs Rust 1.54.0 lints (#2483) 2021-07-30 01:11:47 +00:00
payload.rs Builder Specs v0.2.0 (#3134) 2022-07-30 00:22:37 +00:00
pending_attestation.rs Get arbitrary check passing (2.0) (#2710) 2021-10-14 02:58:11 +00:00
preset.rs Native support for Gnosis Beacon Chain network (#2931) 2022-01-27 22:58:33 +00:00
proposer_preparation_data.rs Proposer preparation data quoted validator index in API (#3080) 2022-03-13 21:57:05 +00:00
proposer_slashing.rs Refactor op pool for speed and correctness (#3312) 2022-08-29 09:10:26 +00:00
relative_epoch.rs Remove saturating arith from state_processing (#1644) 2020-09-25 05:18:21 +00:00
selection_proof.rs Altair consensus changes and refactors (#2279) 2021-07-09 06:15:32 +00:00
shuffling_id.rs Optimize validator duties (#2243) 2021-03-17 05:09:57 +00:00
signed_aggregate_and_proof.rs [Altair] Sync committee pools (#2321) 2021-07-15 00:52:02 +00:00
signed_beacon_block_header.rs Lazy hashing for SignedBeaconBlock in sync (#2916) 2022-01-14 07:20:54 +00:00
signed_beacon_block.rs Use async code when interacting with EL (#3244) 2022-07-03 05:36:50 +00:00
signed_contribution_and_proof.rs [Altair] Sync committee pools (#2321) 2021-07-15 00:52:02 +00:00
signed_voluntary_exit.rs Lazy hashing for SignedBeaconBlock in sync (#2916) 2022-01-14 07:20:54 +00:00
signing_data.rs Consensus updates for v0.12 (#1228) 2020-06-03 14:56:54 +10:00
slot_data.rs [Altair] Sync committee pools (#2321) 2021-07-15 00:52:02 +00:00
slot_epoch_macros.rs Updated to comply with new clippy formatting rules (#2336) 2021-05-10 00:53:09 +00:00
slot_epoch.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
sqlite.rs Directory Restructure (#1163) 2020-05-18 21:24:23 +10:00
subnet_id.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
sync_aggregate.rs Lazy hashing for SignedBeaconBlock in sync (#2916) 2022-01-14 07:20:54 +00:00
sync_aggregator_selection_data.rs Web3Signer support for VC (#2522) 2021-09-16 03:26:33 +00:00
sync_committee_contribution.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
sync_committee_message.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
sync_committee_subscription.rs Add quoted u64/u64_vec to SyncCommitteeSubscription (#2589) 2021-09-11 23:56:16 +00:00
sync_committee.rs Validator monitor support for sync committees (#2476) 2021-08-31 23:31:36 +00:00
sync_duty.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
sync_selection_proof.rs [Altair] Sync committee pools (#2321) 2021-07-15 00:52:02 +00:00
sync_subnet_id.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
tree_hash_impls.rs Rust 1.54.0 lints (#2483) 2021-07-30 01:11:47 +00:00
validator_registration_data.rs Register validator api (#3194) 2022-06-30 00:49:21 +00:00
validator_subscription.rs Implement standard eth2.0 API (#1569) 2020-10-01 11:12:36 +10:00
validator.rs Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
voluntary_exit.rs Lazy hashing for SignedBeaconBlock in sync (#2916) 2022-01-14 07:20:54 +00:00