22aedda1be
## Issue Addressed Closes #673 ## Proposed Changes Store a schema version in the database so that future releases can check they're running against a compatible database version. This would also enable automatic migration on breaking database changes, but that's left as future work. The database config is also stored in the database so that the `slots_per_restore_point` value can be checked for consistency, which closes #673
59 lines
1.8 KiB
Rust
59 lines
1.8 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 DEFAULT_SLOTS_PER_RESTORE_POINT: u64 = 2048;
|
|
pub const DEFAULT_BLOCK_CACHE_SIZE: usize = 5;
|
|
|
|
/// Database configuration parameters.
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Encode, Decode)]
|
|
pub struct StoreConfig {
|
|
/// Number of slots to wait between storing restore points in the freezer database.
|
|
pub slots_per_restore_point: u64,
|
|
/// Maximum number of blocks to store in the in-memory block cache.
|
|
pub block_cache_size: usize,
|
|
}
|
|
|
|
#[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,
|
|
block_cache_size: DEFAULT_BLOCK_CACHE_SIZE,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl StoreConfig {
|
|
pub fn check_compatibility(&self, on_disk_config: &Self) -> 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 StoreConfig {
|
|
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)?)
|
|
}
|
|
}
|