mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-23 23:04:53 +00:00
Shrink persisted fork choice data (#7805)
Closes: - https://github.com/sigp/lighthouse/issues/7760 - [x] Remove `balances_cache` from `PersistedForkChoiceStore` (~65 MB saving on mainnet) - [x] Remove `justified_balances` from `PersistedForkChoiceStore` (~16 MB saving on mainnet) - [x] Remove `balances` from `ProtoArray`/`SszContainer`. - [x] Implement zstd compression for votes - [x] Fix bug in justified state usage - [x] Bump schema version to V28 and implement migration.
This commit is contained in:
@@ -1,16 +1,30 @@
|
||||
use crate::beacon_fork_choice_store::PersistedForkChoiceStoreV17;
|
||||
use crate::{
|
||||
beacon_fork_choice_store::{PersistedForkChoiceStoreV17, PersistedForkChoiceStoreV28},
|
||||
metrics,
|
||||
};
|
||||
use ssz::{Decode, Encode};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use store::{DBColumn, Error, StoreItem};
|
||||
use store::{DBColumn, Error, KeyValueStoreOp, StoreConfig, StoreItem};
|
||||
use superstruct::superstruct;
|
||||
use types::Hash256;
|
||||
|
||||
// If adding a new version you should update this type alias and fix the breakages.
|
||||
pub type PersistedForkChoice = PersistedForkChoiceV17;
|
||||
pub type PersistedForkChoice = PersistedForkChoiceV28;
|
||||
|
||||
#[superstruct(variants(V17), variant_attributes(derive(Encode, Decode)), no_enum)]
|
||||
#[superstruct(
|
||||
variants(V17, V28),
|
||||
variant_attributes(derive(Encode, Decode)),
|
||||
no_enum
|
||||
)]
|
||||
pub struct PersistedForkChoice {
|
||||
pub fork_choice: fork_choice::PersistedForkChoice,
|
||||
pub fork_choice_store: PersistedForkChoiceStoreV17,
|
||||
#[superstruct(only(V17))]
|
||||
pub fork_choice_v17: fork_choice::PersistedForkChoiceV17,
|
||||
#[superstruct(only(V28))]
|
||||
pub fork_choice: fork_choice::PersistedForkChoiceV28,
|
||||
#[superstruct(only(V17))]
|
||||
pub fork_choice_store_v17: PersistedForkChoiceStoreV17,
|
||||
#[superstruct(only(V28))]
|
||||
pub fork_choice_store: PersistedForkChoiceStoreV28,
|
||||
}
|
||||
|
||||
macro_rules! impl_store_item {
|
||||
@@ -32,3 +46,35 @@ macro_rules! impl_store_item {
|
||||
}
|
||||
|
||||
impl_store_item!(PersistedForkChoiceV17);
|
||||
|
||||
impl PersistedForkChoiceV28 {
|
||||
pub fn from_bytes(bytes: &[u8], store_config: &StoreConfig) -> Result<Self, Error> {
|
||||
let decompressed_bytes = store_config
|
||||
.decompress_bytes(bytes)
|
||||
.map_err(Error::Compression)?;
|
||||
Self::from_ssz_bytes(&decompressed_bytes).map_err(Into::into)
|
||||
}
|
||||
|
||||
pub fn as_bytes(&self, store_config: &StoreConfig) -> Result<Vec<u8>, Error> {
|
||||
let encode_timer = metrics::start_timer(&metrics::FORK_CHOICE_ENCODE_TIMES);
|
||||
let ssz_bytes = self.as_ssz_bytes();
|
||||
drop(encode_timer);
|
||||
|
||||
let _compress_timer = metrics::start_timer(&metrics::FORK_CHOICE_COMPRESS_TIMES);
|
||||
store_config
|
||||
.compress_bytes(&ssz_bytes)
|
||||
.map_err(Error::Compression)
|
||||
}
|
||||
|
||||
pub fn as_kv_store_op(
|
||||
&self,
|
||||
key: Hash256,
|
||||
store_config: &StoreConfig,
|
||||
) -> Result<KeyValueStoreOp, Error> {
|
||||
Ok(KeyValueStoreOp::PutKeyValue(
|
||||
DBColumn::ForkChoice,
|
||||
key.as_slice().to_vec(),
|
||||
self.as_bytes(store_config)?,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user