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

feat(pruner): shared deletion limit #4880

Merged
merged 8 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 8 deletions bin/reth/src/node/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,8 @@ impl NodeState {

fn handle_pruner_event(&self, event: PrunerEvent) {
match event {
PrunerEvent::Finished { tip_block_number, elapsed, done, parts_done } => {
info!(
tip_block_number = tip_block_number,
elapsed = ?elapsed,
done = done,
parts_done = ?parts_done,
"Pruner finished"
);
PrunerEvent::Finished { tip_block_number, elapsed, parts } => {
info!(tip_block_number, ?elapsed, ?parts, "Pruner finished");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
self.chain.clone(),
prune_config.block_interval,
prune_config.parts,
self.chain.prune_batch_sizes,
self.chain.prune_delete_limit,
highest_snapshots_rx,
);
let events = pruner.events();
Expand Down
4 changes: 2 additions & 2 deletions crates/consensus/beacon/src/engine/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use reth_interfaces::{
test_utils::{NoopFullBlockClient, TestConsensus},
};
use reth_payload_builder::test_utils::spawn_test_payload_service;
use reth_primitives::{BlockNumber, ChainSpec, PruneBatchSizes, PruneModes, B256, U256};
use reth_primitives::{BlockNumber, ChainSpec, PruneModes, B256, U256};
use reth_provider::{
providers::BlockchainProvider, test_utils::TestExecutorFactory, BlockExecutor,
BundleStateWithReceipts, ExecutorFactory, ProviderFactory, PrunableBlockExecutor,
Expand Down Expand Up @@ -520,7 +520,7 @@ where
self.base_config.chain_spec.clone(),
5,
PruneModes::none(),
PruneBatchSizes::default(),
self.base_config.chain_spec.prune_delete_limit,
watch::channel(None).1,
);

Expand Down
2 changes: 1 addition & 1 deletion crates/interfaces/src/blockchain_tree/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub enum BlockchainTreeError {
}

/// Result alias for `CanonicalError`
pub type CanonicalResult<T> = std::result::Result<T, CanonicalError>;
pub type CanonicalResult<T> = Result<T, CanonicalError>;

/// Canonical Errors
#[allow(missing_docs)]
Expand Down
16 changes: 8 additions & 8 deletions crates/interfaces/src/test_utils/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn rng() -> StdRng {
/// The headers are assumed to not be correct if validated.
pub fn random_header_range<R: Rng>(
rng: &mut R,
range: std::ops::Range<u64>,
range: Range<u64>,
head: B256,
) -> Vec<SealedHeader> {
let mut headers = Vec::with_capacity(range.end.saturating_sub(range.start) as usize);
Expand Down Expand Up @@ -204,8 +204,8 @@ pub fn random_changeset_range<'a, R: Rng, IBlk, IAcc>(
rng: &mut R,
blocks: IBlk,
accounts: IAcc,
n_storage_changes: std::ops::Range<u64>,
key_range: std::ops::Range<u64>,
n_storage_changes: Range<u64>,
key_range: Range<u64>,
) -> (Vec<ChangeSet>, BTreeMap<Address, AccountState>)
where
IBlk: IntoIterator<Item = &'a SealedBlock>,
Expand Down Expand Up @@ -280,8 +280,8 @@ where
pub fn random_account_change<R: Rng>(
rng: &mut R,
valid_addresses: &Vec<Address>,
n_storage_changes: std::ops::Range<u64>,
key_range: std::ops::Range<u64>,
n_storage_changes: Range<u64>,
key_range: Range<u64>,
) -> (Address, Address, U256, Vec<StorageEntry>) {
let mut addresses = valid_addresses.choose_multiple(rng, 2).cloned();

Expand All @@ -302,7 +302,7 @@ pub fn random_account_change<R: Rng>(
}

/// Generate a random storage change.
pub fn random_storage_entry<R: Rng>(rng: &mut R, key_range: std::ops::Range<u64>) -> StorageEntry {
pub fn random_storage_entry<R: Rng>(rng: &mut R, key_range: Range<u64>) -> StorageEntry {
let key = B256::new({
let n = key_range.sample_single(rng);
let mut m = [0u8; 32];
Expand All @@ -326,7 +326,7 @@ pub fn random_eoa_account<R: Rng>(rng: &mut R) -> (Address, Account) {
/// Generate random Externally Owned Accounts
pub fn random_eoa_account_range<R: Rng>(
rng: &mut R,
acc_range: std::ops::Range<u64>,
acc_range: Range<u64>,
) -> Vec<(Address, Account)> {
let mut accounts = Vec::with_capacity(acc_range.end.saturating_sub(acc_range.start) as usize);
for _ in acc_range {
Expand All @@ -338,7 +338,7 @@ pub fn random_eoa_account_range<R: Rng>(
/// Generate random Contract Accounts
pub fn random_contract_account_range<R: Rng>(
rng: &mut R,
acc_range: &mut std::ops::Range<u64>,
acc_range: &mut Range<u64>,
) -> Vec<(Address, Account)> {
let mut accounts = Vec::with_capacity(acc_range.end.saturating_sub(acc_range.start) as usize);
for _ in acc_range {
Expand Down
16 changes: 8 additions & 8 deletions crates/primitives/src/chain/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
header::Head,
proofs::genesis_state_root,
Address, BlockNumber, Chain, ForkFilter, ForkHash, ForkId, Genesis, Hardfork, Header,
PruneBatchSizes, SealedHeader, B256, EMPTY_OMMER_ROOT, U256,
SealedHeader, B256, EMPTY_OMMER_ROOT, U256,
};
use once_cell::sync::Lazy;
use revm_primitives::{address, b256};
Expand Down Expand Up @@ -64,7 +64,7 @@ pub static MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
b256!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"),
)),
base_fee_params: BaseFeeParams::ethereum(),
prune_batch_sizes: PruneBatchSizes::mainnet(),
prune_delete_limit: 3500,
snapshot_block_interval: 500_000,
}
.into()
Expand Down Expand Up @@ -107,7 +107,7 @@ pub static GOERLI: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
b256!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"),
)),
base_fee_params: BaseFeeParams::ethereum(),
prune_batch_sizes: PruneBatchSizes::testnet(),
prune_delete_limit: 1700,
snapshot_block_interval: 1_000_000,
}
.into()
Expand Down Expand Up @@ -154,7 +154,7 @@ pub static SEPOLIA: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
b256!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"),
)),
base_fee_params: BaseFeeParams::ethereum(),
prune_batch_sizes: PruneBatchSizes::testnet(),
prune_delete_limit: 1700,
snapshot_block_interval: 1_000_000,
}
.into()
Expand Down Expand Up @@ -196,7 +196,7 @@ pub static HOLESKY: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
b256!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"),
)),
base_fee_params: BaseFeeParams::ethereum(),
prune_batch_sizes: PruneBatchSizes::testnet(),
prune_delete_limit: 1700,
snapshot_block_interval: 1_000_000,
}
.into()
Expand Down Expand Up @@ -302,11 +302,11 @@ pub struct ChainSpec {
/// The parameters that configure how a block's base fee is computed
pub base_fee_params: BaseFeeParams,

/// The batch sizes for pruner, per block. In the actual pruner run it will be multiplied by
/// 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.
#[serde(default)]
pub prune_batch_sizes: PruneBatchSizes,
pub prune_delete_limit: usize,

/// The block interval for creating snapshots. Each snapshot will have that much blocks in it.
pub snapshot_block_interval: u64,
Expand All @@ -323,7 +323,7 @@ impl Default for ChainSpec {
hardforks: Default::default(),
deposit_contract: Default::default(),
base_fee_params: BaseFeeParams::ethereum(),
prune_batch_sizes: Default::default(),
prune_delete_limit: MAINNET.prune_delete_limit,
snapshot_block_interval: Default::default(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub use net::{
};
pub use peer::{PeerId, WithPeerId};
pub use prune::{
PruneBatchSizes, PruneCheckpoint, PruneMode, PruneModes, PrunePart, PrunePartError,
PruneCheckpoint, PruneMode, PruneModes, PrunePart, PrunePartError, PruneProgress,
ReceiptsLogPruneConfig, MINIMUM_PRUNING_DISTANCE,
};
pub use receipt::{Receipt, ReceiptWithBloom, ReceiptWithBloomRef, Receipts};
Expand Down
83 changes: 0 additions & 83 deletions crates/primitives/src/prune/batch_sizes.rs

This file was deleted.

30 changes: 28 additions & 2 deletions crates/primitives/src/prune/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
mod batch_sizes;
mod checkpoint;
mod mode;
mod part;
mod target;

use crate::{Address, BlockNumber};
pub use batch_sizes::PruneBatchSizes;
pub use checkpoint::PruneCheckpoint;
pub use mode::PruneMode;
pub use part::{PrunePart, PrunePartError};
Expand Down Expand Up @@ -88,3 +86,31 @@ impl ReceiptsLogPruneConfig {
Ok(lowest.map(|lowest| lowest.max(pruned_block)))
}
}

/// Progress of pruning.
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum PruneProgress {
/// There is more data to prune.
HasMoreData,
/// Pruning has been finished.
Finished,
}

impl PruneProgress {
/// Creates new [PruneProgress] from `done` boolean value.
///
/// If `done == true`, returns [PruneProgress::Finished], otherwise [PruneProgress::HasMoreData]
/// is returned.
pub fn from_done(done: bool) -> Self {
if done {
Self::Finished
} else {
Self::HasMoreData
}
}

/// Returns `true` if pruning has been finished.
pub fn is_finished(&self) -> bool {
matches!(self, Self::Finished)
}
}
5 changes: 2 additions & 3 deletions crates/prune/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use reth_primitives::{BlockNumber, PrunePart};
use reth_primitives::{BlockNumber, PrunePart, PruneProgress};
use std::{collections::BTreeMap, time::Duration};

/// An event emitted by a [Pruner][crate::Pruner].
Expand All @@ -8,7 +8,6 @@ pub enum PrunerEvent {
Finished {
tip_block_number: BlockNumber,
elapsed: Duration,
done: bool,
parts_done: BTreeMap<PrunePart, bool>,
parts: BTreeMap<PrunePart, (PruneProgress, usize)>,
},
}
Loading
Loading