Optimise balances cache in case of skipped slots (#2849)

## Proposed Changes

Remove the `is_first_block_in_epoch` logic from the balances cache update logic, as it was incorrect in the case of skipped slots. The updated code is simpler because regardless of whether the block is the first in the epoch we can check if an entry for the epoch boundary root already exists in the cache, and update the cache accordingly.

Additionally, to assist with flip-flopping justified epochs, move to cloning the balance cache rather than moving it. This should still be very fast in practice because the balances cache is a ~1.6MB `Vec`, and this operation is expected to only occur infrequently.
This commit is contained in:
Michael Sproul
2021-12-13 23:35:57 +00:00
parent b22ac95d7f
commit a43d5e161f
5 changed files with 137 additions and 75 deletions

View File

@@ -4,7 +4,7 @@ use ssz::{Decode, Encode};
use ssz_derive::{Decode, Encode};
use types::{Checkpoint, Hash256, Slot};
pub const CURRENT_SCHEMA_VERSION: SchemaVersion = SchemaVersion(7);
pub const CURRENT_SCHEMA_VERSION: SchemaVersion = SchemaVersion(8);
// All the keys that get stored under the `BeaconMeta` column.
//