Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(pruner): remove deletion limit per block, make it per run #9446

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions crates/consensus/beacon/src/engine/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,13 @@ where

// Setup blockchain tree
let externals = TreeExternals::new(provider_factory.clone(), consensus, executor_factory);
let config = BlockchainTreeConfig::new(1, 2, 3, 2);
let tree = Arc::new(ShareableBlockchainTree::new(
BlockchainTree::new(externals, config, PruneModes::default())
.expect("failed to create tree"),
BlockchainTree::new(
externals,
BlockchainTreeConfig::new(1, 2, 3, 2),
PruneModes::default(),
)
.expect("failed to create tree"),
));
let latest = self.base_config.chain_spec.genesis_header().seal_slow();
let blockchain_provider =
Expand All @@ -405,7 +408,6 @@ where
vec![],
5,
self.base_config.chain_spec.prune_delete_limit,
config.max_reorg_depth() as usize,
None,
watch::channel(FinishedExExHeight::NoExExs).1,
);
Expand Down
4 changes: 1 addition & 3 deletions crates/node/builder/src/launch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,11 @@ where

let initial_target = ctx.node_config().debug.tip;

let mut pruner_builder =
ctx.pruner_builder().max_reorg_depth(ctx.tree_config().max_reorg_depth() as usize);
let mut pruner_builder = ctx.pruner_builder();
if let Some(exex_manager_handle) = &exex_manager_handle {
pruner_builder =
pruner_builder.finished_exex_height(exex_manager_handle.finished_height());
}

let pruner = pruner_builder.build(ctx.provider_factory().clone());

let pruner_events = pruner.events();
Expand Down
16 changes: 2 additions & 14 deletions crates/prune/prune/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ pub struct PrunerBuilder {
block_interval: usize,
/// Pruning configuration for every part of the data that can be pruned.
segments: PruneModes,
/// The number of blocks that can be re-orged.
max_reorg_depth: usize,
/// The delete limit for pruner, per block. In the actual pruner run it will be multiplied by
/// the amount of blocks between pruner runs to account for the difference in amount of new
/// data coming in.
/// The delete limit for pruner, per run.
prune_delete_limit: usize,
/// Time a pruner job can run before timing out.
timeout: Option<Duration>,
Expand Down Expand Up @@ -50,13 +46,7 @@ impl PrunerBuilder {
self
}

/// Sets the number of blocks that can be re-orged.
pub const fn max_reorg_depth(mut self, max_reorg_depth: usize) -> Self {
self.max_reorg_depth = max_reorg_depth;
self
}

/// Sets the delete limit for pruner, per block.
/// Sets the delete limit for pruner, per run.
pub const fn prune_delete_limit(mut self, prune_delete_limit: usize) -> Self {
self.prune_delete_limit = prune_delete_limit;
self
Expand Down Expand Up @@ -89,7 +79,6 @@ impl PrunerBuilder {
segments.into_vec(),
self.block_interval,
self.prune_delete_limit,
self.max_reorg_depth,
self.timeout,
self.finished_exex_height,
)
Expand All @@ -101,7 +90,6 @@ impl Default for PrunerBuilder {
Self {
block_interval: 5,
segments: PruneModes::none(),
max_reorg_depth: 64,
prune_delete_limit: MAINNET.prune_delete_limit,
timeout: None,
finished_exex_height: watch::channel(FinishedExExHeight::NoExExs).1,
Expand Down
34 changes: 5 additions & 29 deletions crates/prune/prune/src/pruner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@ pub struct Pruner<DB> {
/// number is updated with the tip block number the pruner was called with. It's used in
/// conjunction with `min_block_interval` to determine when the pruning needs to be initiated.
previous_tip_block_number: Option<BlockNumber>,
/// Maximum total entries to prune (delete from database) per block.
delete_limit_per_block: usize,
/// Maximum number of blocks to be pruned per run, as an additional restriction to
/// `previous_tip_block_number`.
prune_max_blocks_per_run: usize,
/// Maximum total entries to prune (delete from database) per run.
delete_limit: usize,
/// Maximum time for a one pruner run.
timeout: Option<Duration>,
/// The finished height of all `ExEx`'s.
Expand All @@ -59,7 +56,6 @@ impl<DB: Database> Pruner<DB> {
segments: Vec<Box<dyn Segment<DB>>>,
min_block_interval: usize,
delete_limit: usize,
prune_max_blocks_per_run: usize,
timeout: Option<Duration>,
finished_exex_height: watch::Receiver<FinishedExExHeight>,
) -> Self {
Expand All @@ -68,8 +64,7 @@ impl<DB: Database> Pruner<DB> {
segments,
min_block_interval,
previous_tip_block_number: None,
delete_limit_per_block: delete_limit,
prune_max_blocks_per_run,
delete_limit,
timeout,
finished_exex_height,
metrics: Metrics::default(),
Expand Down Expand Up @@ -105,25 +100,7 @@ impl<DB: Database> Pruner<DB> {
debug!(target: "pruner", %tip_block_number, "Pruner started");
let start = Instant::now();

// Multiply `self.delete_limit` (number of rows to delete per block) by number of blocks
// since last pruner run. `self.previous_tip_block_number` is close to
// `tip_block_number`, usually within `self.block_interval` blocks, so
// `delete_limit` will not be too high. If it's too high, we additionally limit it by
// `self.prune_max_blocks_per_run`.
//
// Also see docs for `self.previous_tip_block_number`.
let blocks_since_last_run = self
.previous_tip_block_number
.map_or(1, |previous_tip_block_number| {
// Saturating subtraction is needed for the case when the chain was reverted,
// meaning current block number might be less than the previous tip
// block number.
tip_block_number.saturating_sub(previous_tip_block_number) as usize
})
.min(self.prune_max_blocks_per_run);

let mut limiter = PruneLimiter::default()
.set_deleted_entries_limit(self.delete_limit_per_block * blocks_since_last_run);
let mut limiter = PruneLimiter::default().set_deleted_entries_limit(self.delete_limit);
if let Some(timeout) = self.timeout {
limiter = limiter.set_time_limit(timeout);
};
Expand Down Expand Up @@ -352,8 +329,7 @@ mod tests {
let (finished_exex_height_tx, finished_exex_height_rx) =
tokio::sync::watch::channel(FinishedExExHeight::NoExExs);

let mut pruner =
Pruner::new(provider_factory, vec![], 5, 0, 5, None, finished_exex_height_rx);
let mut pruner = Pruner::new(provider_factory, vec![], 5, 0, None, finished_exex_height_rx);

// No last pruned block number was set before
let first_block_number = 1;
Expand Down
2 changes: 1 addition & 1 deletion crates/prune/types/src/limiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
/// or the time it can run.
#[derive(Debug, Clone, Default)]
pub struct PruneLimiter {
/// Maximum entries (rows in the database) to delete from the database per block.
/// Maximum entries (rows in the database) to delete from the database per run.
deleted_entries_limit: Option<PruneDeletedEntriesLimit>,
/// Maximum duration of one prune run.
time_limit: Option<PruneTimeLimit>,
Expand Down
Loading