From b2abec5d352c980f69b0effe8ca5063f23d3492a Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Tue, 24 Jan 2023 17:58:54 +0100 Subject: [PATCH] Verify StoreConfig --- beacon_node/src/cli.rs | 4 ++-- beacon_node/store/src/hot_cold_store.rs | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/beacon_node/src/cli.rs b/beacon_node/src/cli.rs index 1ce3b995c..e711dfca9 100644 --- a/beacon_node/src/cli.rs +++ b/beacon_node/src/cli.rs @@ -563,8 +563,8 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> { Arg::with_name("epochs-per-blob-prune") .long("epochs-per-blob-prune") .help("The epoch interval with which to prune blobs from Lighthouse's \ - database when they are older than the data data availability \ - boundary relative to the current epoch.") + database when they are older than the data availability boundary \ + relative to the current epoch.") .takes_value(true) .default_value("1") ) diff --git a/beacon_node/store/src/hot_cold_store.rs b/beacon_node/store/src/hot_cold_store.rs index 201ee72d4..2cffa4571 100644 --- a/beacon_node/store/src/hot_cold_store.rs +++ b/beacon_node/store/src/hot_cold_store.rs @@ -109,6 +109,7 @@ pub enum HotColdDBError { slots_per_historical_root: u64, slots_per_epoch: u64, }, + ZeroEpochsPerBlobPrune, RestorePointBlockHashError(BeaconStateError), IterationError { unexpected_key: BytesKey, @@ -126,7 +127,7 @@ impl HotColdDB, MemoryStore> { spec: ChainSpec, log: Logger, ) -> Result, MemoryStore>, Error> { - Self::verify_slots_per_restore_point(config.slots_per_restore_point)?; + Self::verify_config(&config)?; let db = HotColdDB { split: RwLock::new(Split::default()), @@ -1522,6 +1523,12 @@ impl, Cold: ItemStore> HotColdDB self.hot_db.get(state_root) } + /// Verify that a parsed config. + fn verify_config(config: &StoreConfig) -> Result<(), HotColdDBError> { + Self::verify_slots_per_restore_point(config.slots_per_restore_point)?; + Self::verify_epochs_per_blob_prune(config.epochs_per_blob_prune) + } + /// Check that the restore point frequency is valid. /// /// Specifically, check that it is: @@ -1552,6 +1559,16 @@ impl, Cold: ItemStore> HotColdDB } } + // Check that epochs_per_blob_prune is at least 1 epoch to avoid attempting to prune the same + // epochs over and over again. + fn verify_epochs_per_blob_prune(epochs_per_blob_prune: u64) -> Result<(), HotColdDBError> { + if epochs_per_blob_prune > 0 { + Ok(()) + } else { + Err(HotColdDBError::ZeroEpochsPerBlobPrune) + } + } + /// Run a compaction pass to free up space used by deleted states. pub fn compact(&self) -> Result<(), Error> { self.hot_db.compact()?;