nimbus-eth2/beacon_chain/spec
Etan Kissling ea97e93e74
accelerate `getShufflingRef` (#4911)
When an uncached `ShufflingRef` is requested, we currently replay state
which can take several seconds. Acceleration is possible by:

1. Start from any state with locked-in `get_active_validator_indices`.
   Any blocks / slots applied to such a state can only affect that
   result for future epochs, so are viable for querying target epoch.
   `compute_activation_exit_epoch(state.slot.epoch) > target.epoch`

2. Determine highest common ancestor among `state` and `target.blck`.
   At the ancestor slot, same rules re `get_active_validator_indices`.
   `compute_activation_exit_epoch(ancestorSlot.epoch) > target.epoch`

3. We now have a `state` that shares history with `target.blck` up
   through a common ancestor slot. Any blocks / slots that the `state`
   contains, which are not part of the `target.blck` history, affect
   `get_active_validator_indices` at epochs _after_ `target.epoch`.

4. Select `state.randao_mixes[N]` that is closest to common ancestor.
   Either direction is fine (above / below ancestor).

5. From that RANDAO mix, mix in / out all RANDAO reveals from blocks
   in-between. This is just an XOR operation, so fully reversible.
   `mix = mix xor SHA256(blck.message.body.randao_reveal)`

6. Compute the attester dependent slot from `target.epoch`.
   `if epoch >= 2: (target.epoch - 1).start_slot - 1 else: GENESIS_SLOT`

7. Trace back from `target.blck` to the attester dependent slot.
   We now have the destination for which we want to obtain RANDAO.

8. Mix in all RANDAO reveals from blocks up through the `dependentBlck`.
   Same method, no special handling necessary for epoch transitions.

9. Combine `get_active_validator_indices` from `state` at `target.epoch`
   with the recovered RANDAO value at `dependentBlck` to obtain the
   requested shuffling, and construct the `ShufflingRef` without replay.

* more tests and simplify logic

* test with different number of deposits per branch

* Update beacon_chain/consensus_object_pools/blockchain_dag.nim

Co-authored-by: Jacek Sieka <jacek@status.im>

* `commonAncestor` tests

* lint

---------

Co-authored-by: Jacek Sieka <jacek@status.im>
2023-05-12 19:36:59 +02:00
..
datatypes remove unused definitions (#4937) 2023-05-11 14:39:36 +00:00
eth2_apis fix SSZ response for `produceBlindedBlock` (#4943) 2023-05-12 15:40:45 +00:00
mev More blob tweaks/fixes from running in devnet (#4933) 2023-05-11 00:36:35 +00:00
presets capella preset for Gnosis (#4936) 2023-05-11 09:56:32 +00:00
beacon_time.nim more consensus-specs v1.3.0 bumps (#4898) 2023-05-05 20:38:51 +00:00
beaconstate.nim reorder `get_initial_beacon_block` by fork (#4899) 2023-05-06 10:32:59 +00:00
block_id.nim remove Nim 1.2-compatible `push raise`s and update copyright notice years (#4528) 2023-01-20 14:14:37 +00:00
crypto.nim more consensus-specs v1.3.0 bumps (#4898) 2023-05-05 20:38:51 +00:00
deposit_snapshots.nim eip4844 block/slot sanity and transition tests (#4399) 2022-12-08 02:07:41 +00:00
digest.nim bump more consensus-specs refs to v1.3.0 (with comments) (#4901) 2023-05-05 20:37:56 +00:00
engine_authentication.nim update engine API URLs from v1.0.0-beta.2 to beta.3 (#4828) 2023-04-17 20:11:28 +00:00
english_word_list.txt
eth2_merkleization.nim remove Nim 1.2-compatible `push raise`s and update copyright notice years (#4528) 2023-01-20 14:14:37 +00:00
eth2_ssz_serialization.nim Remove SignedBeaconBlockAndBlobsSidecar (#4683) 2023-03-02 15:12:04 +01:00
forks.nim `bls_to_execution_changes` check alternative (#4916) 2023-05-09 17:24:02 +00:00
forks_light_client.nim `excess_data_gas` after `withdrawals` cleanup (#4900) 2023-05-05 23:15:47 +00:00
helpers.nim accelerate `getShufflingRef` (#4911) 2023-05-12 19:36:59 +02:00
keystore.nim more v1.3.0 consensus-specs bumps (#4915) 2023-05-09 17:20:37 +00:00
light_client_sync.nim more v1.3.0 consensus-specs bumps (#4915) 2023-05-09 17:20:37 +00:00
network.nim more v1.3.0 consensus-specs bumps (#4915) 2023-05-09 17:20:37 +00:00
presets.nim remove unused definitions (#4937) 2023-05-11 14:39:36 +00:00
signatures.nim more v1.3.0 consensus-specs bumps (#4915) 2023-05-09 17:20:37 +00:00
signatures_batch.nim consensus-specs v1.3.0 bumps with cleanup (#4918) 2023-05-09 20:16:49 +02:00
ssz_codec.nim remove Nim 1.2-compatible `push raise`s and update copyright notice years (#4528) 2023-01-20 14:14:37 +00:00
state_transition.nim final portion of trivial v1.3.0 bumps (#4926) 2023-05-11 09:54:29 +00:00
state_transition_block.nim update some beacon API spec URLs; fix some Name and DuplicateModuleImport hints (#4929) 2023-05-10 10:20:55 +00:00
state_transition_epoch.nim cleanup `state_transition_epoch` and bump to v1.3.0 (#4922) 2023-05-10 04:31:23 +02:00
validator.nim accelerate `getShufflingRef` (#4911) 2023-05-12 19:36:59 +02:00
weak_subjectivity.nim update weak subjectivity calculations (#4923) 2023-05-10 08:23:59 +00:00