375e2b49b3
## Proposed Changes Increase the default `--slots-per-restore-point` to 8192 for a 4x reduction in freezer DB disk usage. Existing nodes that use the previous default of 2048 will be left unchanged. Newly synced nodes (with or without checkpoint sync) will use the new 8192 default. Long-term we could do away with the freezer DB entirely for validator-only nodes, but this change is much simpler and grants us some extra space in the short term. We can also roll it out gradually across our nodes by purging databases one by one, while keeping the Ansible config the same. ## Additional Info We ignore a change from 2048 to 8192 if the user hasn't set the 8192 explicitly. We fire a debug log in the case where we do ignore: ``` DEBG Ignoring slots-per-restore-point config in favour of on-disk value, on_disk: 2048, config: 8192 ```
84 lines
2.7 KiB
Rust
84 lines
2.7 KiB
Rust
use crate::{DBColumn, Error, StoreItem};
|
|
use serde_derive::{Deserialize, Serialize};
|
|
use ssz::{Decode, Encode};
|
|
use ssz_derive::{Decode, Encode};
|
|
use types::{EthSpec, MinimalEthSpec};
|
|
|
|
pub const PREV_DEFAULT_SLOTS_PER_RESTORE_POINT: u64 = 2048;
|
|
pub const DEFAULT_SLOTS_PER_RESTORE_POINT: u64 = 8192;
|
|
pub const DEFAULT_BLOCK_CACHE_SIZE: usize = 5;
|
|
|
|
/// Database configuration parameters.
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct StoreConfig {
|
|
/// Number of slots to wait between storing restore points in the freezer database.
|
|
pub slots_per_restore_point: u64,
|
|
/// Flag indicating whether the `slots_per_restore_point` was set explicitly by the user.
|
|
pub slots_per_restore_point_set_explicitly: bool,
|
|
/// Maximum number of blocks to store in the in-memory block cache.
|
|
pub block_cache_size: usize,
|
|
/// Whether to compact the database on initialization.
|
|
pub compact_on_init: bool,
|
|
/// Whether to compact the database during database pruning.
|
|
pub compact_on_prune: bool,
|
|
}
|
|
|
|
/// Variant of `StoreConfig` that gets written to disk. Contains immutable configuration params.
|
|
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
|
|
pub struct OnDiskStoreConfig {
|
|
pub slots_per_restore_point: u64,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub enum StoreConfigError {
|
|
MismatchedSlotsPerRestorePoint { config: u64, on_disk: u64 },
|
|
}
|
|
|
|
impl Default for StoreConfig {
|
|
fn default() -> Self {
|
|
Self {
|
|
// Safe default for tests, shouldn't ever be read by a CLI node.
|
|
slots_per_restore_point: MinimalEthSpec::slots_per_historical_root() as u64,
|
|
slots_per_restore_point_set_explicitly: false,
|
|
block_cache_size: DEFAULT_BLOCK_CACHE_SIZE,
|
|
compact_on_init: false,
|
|
compact_on_prune: true,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl StoreConfig {
|
|
pub fn as_disk_config(&self) -> OnDiskStoreConfig {
|
|
OnDiskStoreConfig {
|
|
slots_per_restore_point: self.slots_per_restore_point,
|
|
}
|
|
}
|
|
|
|
pub fn check_compatibility(
|
|
&self,
|
|
on_disk_config: &OnDiskStoreConfig,
|
|
) -> Result<(), StoreConfigError> {
|
|
if self.slots_per_restore_point != on_disk_config.slots_per_restore_point {
|
|
return Err(StoreConfigError::MismatchedSlotsPerRestorePoint {
|
|
config: self.slots_per_restore_point,
|
|
on_disk: on_disk_config.slots_per_restore_point,
|
|
});
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
impl StoreItem for OnDiskStoreConfig {
|
|
fn db_column() -> DBColumn {
|
|
DBColumn::BeaconMeta
|
|
}
|
|
|
|
fn as_store_bytes(&self) -> Vec<u8> {
|
|
self.as_ssz_bytes()
|
|
}
|
|
|
|
fn from_store_bytes(bytes: &[u8]) -> Result<Self, Error> {
|
|
Ok(Self::from_ssz_bytes(bytes)?)
|
|
}
|
|
}
|