mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 10:22:38 +00:00
Allow user to set an epoch margin for pruning
This commit is contained in:
@@ -9,6 +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<u64> = None;
|
||||
|
||||
/// Database configuration parameters.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@@ -29,8 +30,11 @@ pub struct StoreConfig {
|
||||
pub prune_payloads: bool,
|
||||
/// Whether to prune blobs older than the blob data availability boundary.
|
||||
pub prune_blobs: bool,
|
||||
/// Frequency of blob pruning. Default: every epoch.
|
||||
/// Frequency of blob pruning in epochs. Default: every epoch.
|
||||
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<u64>,
|
||||
}
|
||||
|
||||
/// Variant of `StoreConfig` that gets written to disk. Contains immutable configuration params.
|
||||
@@ -57,6 +61,7 @@ impl Default for StoreConfig {
|
||||
prune_payloads: true,
|
||||
prune_blobs: true,
|
||||
epochs_per_blob_prune: DEFAULT_EPOCHS_PER_BLOB_PRUNE,
|
||||
blob_prune_margin_epochs: DEFAULT_BLOB_PUNE_MARGIN_EPOCHS,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1798,8 +1798,20 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
|
||||
|
||||
let mut ops = vec![];
|
||||
let mut last_pruned_block_root = None;
|
||||
// Prune up until the data availability boundary.
|
||||
let end_slot = (data_availability_boundary - 1).end_slot(E::slots_per_epoch());
|
||||
|
||||
// At most prune up until the data availability boundary epoch, leaving at least blobs in
|
||||
// the data availability boundary epoch and younger.
|
||||
let end_slot = {
|
||||
let earliest_prunable_epoch = data_availability_boundary - 1;
|
||||
// Stop pruning before reaching the data availability boundary if a margin is
|
||||
// configured.
|
||||
let end_epoch = if let Some(margin) = self.get_config().blob_prune_margin_epochs {
|
||||
earliest_prunable_epoch - margin
|
||||
} else {
|
||||
earliest_prunable_epoch
|
||||
};
|
||||
end_epoch.end_slot(E::slots_per_epoch())
|
||||
};
|
||||
|
||||
for res in self.forwards_block_roots_iterator_until(
|
||||
oldest_blob_slot,
|
||||
|
||||
Reference in New Issue
Block a user