mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 04:01:51 +00:00
## 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.
48 lines
1.4 KiB
Rust
48 lines
1.4 KiB
Rust
use crate::beacon_fork_choice_store::{
|
|
PersistedForkChoiceStoreV1, PersistedForkChoiceStoreV7, PersistedForkChoiceStoreV8,
|
|
};
|
|
use ssz::{Decode, Encode};
|
|
use ssz_derive::{Decode, Encode};
|
|
use store::{DBColumn, Error, StoreItem};
|
|
use superstruct::superstruct;
|
|
|
|
// If adding a new version you should update this type alias and fix the breakages.
|
|
pub type PersistedForkChoice = PersistedForkChoiceV8;
|
|
|
|
#[superstruct(
|
|
variants(V1, V7, V8),
|
|
variant_attributes(derive(Encode, Decode)),
|
|
no_enum
|
|
)]
|
|
pub struct PersistedForkChoice {
|
|
pub fork_choice: fork_choice::PersistedForkChoice,
|
|
#[superstruct(only(V1))]
|
|
pub fork_choice_store: PersistedForkChoiceStoreV1,
|
|
#[superstruct(only(V7))]
|
|
pub fork_choice_store: PersistedForkChoiceStoreV7,
|
|
#[superstruct(only(V8))]
|
|
pub fork_choice_store: PersistedForkChoiceStoreV8,
|
|
}
|
|
|
|
macro_rules! impl_store_item {
|
|
($type:ty) => {
|
|
impl StoreItem for $type {
|
|
fn db_column() -> DBColumn {
|
|
DBColumn::ForkChoice
|
|
}
|
|
|
|
fn as_store_bytes(&self) -> Vec<u8> {
|
|
self.as_ssz_bytes()
|
|
}
|
|
|
|
fn from_store_bytes(bytes: &[u8]) -> std::result::Result<Self, Error> {
|
|
Self::from_ssz_bytes(bytes).map_err(Into::into)
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
impl_store_item!(PersistedForkChoiceV1);
|
|
impl_store_item!(PersistedForkChoiceV7);
|
|
impl_store_item!(PersistedForkChoiceV8);
|