prysm-pulse/beacon-chain/slasher
Manu NALEPA 4030614df0
Slasher: Reduce cold start duration. (#13620)
* `getChunk` ==> `getChunkFromDatabase`.

* `loadChunks`: Rename variables.

* `Update`: Use explicit arguments.

* `detect_attestations.go`: Reduce abstraction layers.

* `loadAndUpdateChunks`: Change arguments order.

* `updatedChunkByChunkIndex`: Update all known validators in the chunk.

* `LastEpochWrittenForValidators`: Avoid avoidable `for`loop.

* `chunks.go`: Ensure implementations respect the interface.

* `LastEpochWrittenForValidators`: Stop considering lack of epoch as genesis epoch.

* `updatedChunkByChunkIndex`: Don't update latest updated epoch.

And add a bunch of tests.

* Improve slasher cold boot duration.

Before this commit, on a slasher cold boot (aka, without any db),
the `updatedChunkByChunkIndex` function looped for all validators
AND for all epochs between the genesis epoch and the current epoch.

This could take several dozen of minutes, and it is useless since the
min/max spans are actually a circular buffer with a limited lenght.
Cells of min/max spans can be overwritten (with the same value)
plenty of times.

After this commit, the `updatedChunkByChunkIndex` function loops
for all validators AND AT most 'historyLength' lenght.
Every cell of min/max spans are written AT MOST once.

Time needed for slasher boot goes from `O(nm)` to "only" `O(m)`, where:
- `n` is the number of epochs since the genesis.
- `m` is the number of validators.
2024-02-16 10:10:26 +00:00
..
types Update to V5 (#13622) 2024-02-15 05:46:47 +00:00
BUILD.bazel Update to V5 (#13622) 2024-02-15 05:46:47 +00:00
chunks_test.go Slasher: Reduce cold start duration. (#13620) 2024-02-16 10:10:26 +00:00
chunks.go Slasher: Reduce cold start duration. (#13620) 2024-02-16 10:10:26 +00:00
detect_attestations_test.go Slasher: Reduce cold start duration. (#13620) 2024-02-16 10:10:26 +00:00
detect_attestations.go Slasher: Reduce cold start duration. (#13620) 2024-02-16 10:10:26 +00:00
detect_blocks_test.go Update to V5 (#13622) 2024-02-15 05:46:47 +00:00
detect_blocks.go Update to V5 (#13622) 2024-02-15 05:46:47 +00:00
doc.go Enable dupword linter & fix findings (#12271) 2023-04-18 22:01:27 +00:00
helpers_test.go Update to V5 (#13622) 2024-02-15 05:46:47 +00:00
helpers.go Update to V5 (#13622) 2024-02-15 05:46:47 +00:00
log.go Slasher Simulator Code for Testing Optimized Slasher Behavior (#9695) 2021-09-29 02:27:21 +00:00
metrics.go Slasher Min/Max Chunk Logic (#9673) 2021-09-28 02:04:32 +00:00
params_test.go Update to V5 (#13622) 2024-02-15 05:46:47 +00:00
params.go Update to V5 (#13622) 2024-02-15 05:46:47 +00:00
process_slashings_test.go Update to V5 (#13622) 2024-02-15 05:46:47 +00:00
process_slashings.go Update to V5 (#13622) 2024-02-15 05:46:47 +00:00
queue_test.go Update to V5 (#13622) 2024-02-15 05:46:47 +00:00
queue.go Update to V5 (#13622) 2024-02-15 05:46:47 +00:00
receive_test.go Update to V5 (#13622) 2024-02-15 05:46:47 +00:00
receive.go Update to V5 (#13622) 2024-02-15 05:46:47 +00:00
service_test.go Update to V5 (#13622) 2024-02-15 05:46:47 +00:00
service.go Update to V5 (#13622) 2024-02-15 05:46:47 +00:00