From 8f137df02e857db4c8ddec2dfd4a300d1709531a Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Tue, 24 Jan 2023 11:24:42 +0100 Subject: [PATCH] fixup! Allow user to set an epoch margin for pruning --- beacon_node/beacon_chain/src/beacon_chain.rs | 6 ++---- beacon_node/src/config.rs | 4 +--- beacon_node/store/src/config.rs | 4 ++-- beacon_node/store/src/hot_cold_store.rs | 18 ++++++------------ database_manager/src/lib.rs | 4 +--- lighthouse/tests/beacon_node.rs | 2 +- 6 files changed, 13 insertions(+), 25 deletions(-) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 2a1da6e4a..514b8410d 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -3018,10 +3018,8 @@ impl BeaconChain { // Only consider blobs if the eip4844 fork is enabled. if let Some(data_availability_boundary) = self.data_availability_boundary() { let block_epoch = block.slot().epoch(T::EthSpec::slots_per_epoch()); - let import_boundary = match self.store.get_config().blob_prune_margin_epochs { - Some(margin_epochs) => data_availability_boundary - margin_epochs, - None => data_availability_boundary, - }; + let margin_epochs = self.store.get_config().blob_prune_margin_epochs; + let import_boundary = data_availability_boundary - margin_epochs; // Only store blobs at the data availability boundary, minus any configured epochs // margin, or younger (of higher epoch number). diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index 4974acc25..7ced91274 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -424,9 +424,7 @@ pub fn get_config( if let Some(blob_prune_margin_epochs) = clap_utils::parse_optional(cli_args, "blob-prune-margin-epochs")? { - if blob_prune_margin_epochs > 0 { - client_config.store.blob_prune_margin_epochs = Some(blob_prune_margin_epochs); - } + client_config.store.blob_prune_margin_epochs = blob_prune_margin_epochs; } /* diff --git a/beacon_node/store/src/config.rs b/beacon_node/store/src/config.rs index f32afdecf..ec5ee382b 100644 --- a/beacon_node/store/src/config.rs +++ b/beacon_node/store/src/config.rs @@ -9,7 +9,7 @@ pub const DEFAULT_SLOTS_PER_RESTORE_POINT: u64 = 8192; pub const DEFAULT_BLOCK_CACHE_SIZE: usize = 5; pub const DEFAULT_BLOB_CACHE_SIZE: usize = 5; pub const DEFAULT_EPOCHS_PER_BLOB_PRUNE: u64 = 1; -pub const DEFAULT_BLOB_PUNE_MARGIN_EPOCHS: Option = None; +pub const DEFAULT_BLOB_PUNE_MARGIN_EPOCHS: u64 = 0; /// Database configuration parameters. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -34,7 +34,7 @@ pub struct StoreConfig { pub epochs_per_blob_prune: u64, /// The margin for blob pruning in epochs. The oldest blobs are pruned up until /// data_availability_boundary - blob_prune_margin_epochs. Default: 0. - pub blob_prune_margin_epochs: Option, + pub blob_prune_margin_epochs: u64, } /// Variant of `StoreConfig` that gets written to disk. Contains immutable configuration params. diff --git a/beacon_node/store/src/hot_cold_store.rs b/beacon_node/store/src/hot_cold_store.rs index c86f9f663..a614edad2 100644 --- a/beacon_node/store/src/hot_cold_store.rs +++ b/beacon_node/store/src/hot_cold_store.rs @@ -1779,18 +1779,12 @@ impl, Cold: ItemStore> HotColdDB // middle of an epoch otherwise the oldest blob slot is a start slot. let last_pruned_epoch = oldest_blob_slot.epoch(E::slots_per_epoch()) - 1; - // At most prune up until the data availability boundary epoch, leaving at least blobs in - // the data availability boundary epoch and younger. - let end_epoch = { - let earliest_prunable_epoch = data_availability_boundary - 1; - // Stop pruning before reaching the data availability boundary if a margin is - // configured. - if let Some(margin) = self.get_config().blob_prune_margin_epochs { - earliest_prunable_epoch - margin - } else { - earliest_prunable_epoch - } - }; + // At most prune blobs up until the data availability boundary epoch, leaving at least + // blobs of the data availability boundary epoch and younger. + let earliest_prunable_epoch = data_availability_boundary - 1; + // Stop pruning before reaching the data availability boundary if a margin is configured. + let margin_epochs = self.get_config().blob_prune_margin_epochs; + let end_epoch = earliest_prunable_epoch - margin_epochs; if !force { if last_pruned_epoch.as_u64() + self.get_config().epochs_per_blob_prune diff --git a/database_manager/src/lib.rs b/database_manager/src/lib.rs index 58d2103ac..a33e6c149 100644 --- a/database_manager/src/lib.rs +++ b/database_manager/src/lib.rs @@ -130,9 +130,7 @@ fn parse_client_config( if let Some(blob_prune_margin_epochs) = clap_utils::parse_optional(cli_args, "blob-prune-margin-epochs")? { - if blob_prune_margin_epochs > 0 { - client_config.store.blob_prune_margin_epochs = Some(blob_prune_margin_epochs); - } + client_config.store.blob_prune_margin_epochs = blob_prune_margin_epochs; } Ok(client_config) diff --git a/lighthouse/tests/beacon_node.rs b/lighthouse/tests/beacon_node.rs index f6db01a70..237ca2db5 100644 --- a/lighthouse/tests/beacon_node.rs +++ b/lighthouse/tests/beacon_node.rs @@ -1370,7 +1370,7 @@ fn epochs_per_blob_prune_on_startup_five() { fn blob_prune_margin_epochs_default() { CommandLineTest::new() .run_with_zero_port() - .with_config(|config| assert!(config.blob_prune_margin_epochs.is_none())); + .with_config(|config| assert!(config.blob_prune_margin_epochs == 0)); } #[test] fn blob_prune_margin_epochs_on_startup_ten() {