Verify StoreConfig
This commit is contained in:
parent
00ca21e84c
commit
b2abec5d35
@ -563,8 +563,8 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
|
|||||||
Arg::with_name("epochs-per-blob-prune")
|
Arg::with_name("epochs-per-blob-prune")
|
||||||
.long("epochs-per-blob-prune")
|
.long("epochs-per-blob-prune")
|
||||||
.help("The epoch interval with which to prune blobs from Lighthouse's \
|
.help("The epoch interval with which to prune blobs from Lighthouse's \
|
||||||
database when they are older than the data data availability \
|
database when they are older than the data availability boundary \
|
||||||
boundary relative to the current epoch.")
|
relative to the current epoch.")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.default_value("1")
|
.default_value("1")
|
||||||
)
|
)
|
||||||
|
@ -109,6 +109,7 @@ pub enum HotColdDBError {
|
|||||||
slots_per_historical_root: u64,
|
slots_per_historical_root: u64,
|
||||||
slots_per_epoch: u64,
|
slots_per_epoch: u64,
|
||||||
},
|
},
|
||||||
|
ZeroEpochsPerBlobPrune,
|
||||||
RestorePointBlockHashError(BeaconStateError),
|
RestorePointBlockHashError(BeaconStateError),
|
||||||
IterationError {
|
IterationError {
|
||||||
unexpected_key: BytesKey,
|
unexpected_key: BytesKey,
|
||||||
@ -126,7 +127,7 @@ impl<E: EthSpec> HotColdDB<E, MemoryStore<E>, MemoryStore<E>> {
|
|||||||
spec: ChainSpec,
|
spec: ChainSpec,
|
||||||
log: Logger,
|
log: Logger,
|
||||||
) -> Result<HotColdDB<E, MemoryStore<E>, MemoryStore<E>>, Error> {
|
) -> Result<HotColdDB<E, MemoryStore<E>, MemoryStore<E>>, Error> {
|
||||||
Self::verify_slots_per_restore_point(config.slots_per_restore_point)?;
|
Self::verify_config(&config)?;
|
||||||
|
|
||||||
let db = HotColdDB {
|
let db = HotColdDB {
|
||||||
split: RwLock::new(Split::default()),
|
split: RwLock::new(Split::default()),
|
||||||
@ -1522,6 +1523,12 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
|
|||||||
self.hot_db.get(state_root)
|
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.
|
/// Check that the restore point frequency is valid.
|
||||||
///
|
///
|
||||||
/// Specifically, check that it is:
|
/// Specifically, check that it is:
|
||||||
@ -1552,6 +1559,16 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.
|
/// Run a compaction pass to free up space used by deleted states.
|
||||||
pub fn compact(&self) -> Result<(), Error> {
|
pub fn compact(&self) -> Result<(), Error> {
|
||||||
self.hot_db.compact()?;
|
self.hot_db.compact()?;
|
||||||
|
Loading…
Reference in New Issue
Block a user