Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cf670f2
feat(pruner): respect batch size per run
shekhirin Aug 17, 2023
689d267
new batch logic
shekhirin Aug 18, 2023
d9115be
fix engine prune event
shekhirin Aug 18, 2023
bbf5c0c
more trace logs
shekhirin Aug 18, 2023
adffcf6
even more logs
shekhirin Aug 18, 2023
8fa4757
fix short-circuit
shekhirin Aug 18, 2023
80a53ef
improve log fields
shekhirin Aug 18, 2023
1d149e0
increase batch sizes to 1000
shekhirin Aug 18, 2023
54a67f6
add comments
shekhirin Aug 18, 2023
4939ab9
Merge remote-tracking branch 'origin/main' into alexey/pruner-batch-size
shekhirin Aug 21, 2023
8451bed
fix stage checkpoint tests
shekhirin Aug 21, 2023
c10eeb5
fixes of receipts by logs pruner checkpoint
shekhirin Aug 21, 2023
df14e1e
return early if receipts by logs block range is empty
shekhirin Aug 22, 2023
0498b18
Revert "return early if receipts by logs block range is empty"
shekhirin Aug 22, 2023
a092d72
check empty tx range
shekhirin Aug 22, 2023
bedb5a4
check tip block number
shekhirin Aug 22, 2023
1ac798b
Merge remote-tracking branch 'origin/main' into alexey/pruner-batch-size
shekhirin Aug 22, 2023
08f71e2
add another log for contracts by logs pruning
shekhirin Aug 22, 2023
b941ed4
prune receipts by logs with range instead of iterator
shekhirin Aug 22, 2023
9b4925a
Merge remote-tracking branch 'origin/main' into alexey/pruner-batch-size
shekhirin Aug 22, 2023
ceded5f
feat(primitives): move prune batch sizes to ChainSpec
shekhirin Aug 22, 2023
cc581aa
don't skip prune_batch_sizes from serde
shekhirin Aug 22, 2023
7d6f561
account for block interval
shekhirin Aug 22, 2023
8c06a5d
fix doc
shekhirin Aug 22, 2023
e9cbd3a
adjust mainnet batch sizes
shekhirin Aug 22, 2023
bd0808f
fix tests
shekhirin Aug 22, 2023
de2d739
Merge remote-tracking branch 'origin/main' into alexey/pruner-batch-size
shekhirin Aug 22, 2023
d9595b7
Merge remote-tracking branch 'origin/alexey/pruner-batch-size' into a…
shekhirin Aug 22, 2023
d4e760a
fix checkpoints for contract log filtering on live sync
joshieDo Aug 22, 2023
a042bf6
fix lint
shekhirin Aug 23, 2023
7d43486
fixes after review
shekhirin Aug 23, 2023
2d40ea1
Merge remote-tracking branch 'origin/alexey/pruner-batch-size' into a…
shekhirin Aug 23, 2023
407bdcc
Merge remote-tracking branch 'origin/main' into alexey/pruner-batch-size
shekhirin Aug 23, 2023
3e511ca
Merge remote-tracking branch 'origin/alexey/pruner-batch-size' into a…
shekhirin Aug 23, 2023
623f3a5
Merge remote-tracking branch 'origin/main' into alexey/chain-spec-pru…
shekhirin Aug 23, 2023
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
3 changes: 1 addition & 2 deletions bin/reth/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ use reth_provider::{
providers::BlockchainProvider, BlockHashReader, BlockReader, CanonStateSubscriptions,
HeaderProvider, ProviderFactory, StageCheckpointReader,
};
use reth_prune::BatchSizes;
use reth_revm::Factory;
use reth_revm_inspectors::stack::Hook;
use reth_rpc_engine_api::EngineApi;
Expand Down Expand Up @@ -429,7 +428,7 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
self.chain.clone(),
prune_config.block_interval,
prune_config.parts,
BatchSizes::default(),
self.chain.prune_batch_sizes,
)
});

Expand Down
4 changes: 2 additions & 2 deletions crates/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,14 @@ impl Default for IndexHistoryConfig {
#[serde(default)]
pub struct PruneConfig {
/// Minimum pruning interval measured in blocks.
pub block_interval: u64,
pub block_interval: usize,
/// Pruning configuration for every part of the data that can be pruned.
pub parts: PruneModes,
}

impl Default for PruneConfig {
fn default() -> Self {
Self { block_interval: 10, parts: PruneModes::default() }
Self { block_interval: 5, parts: PruneModes::default() }
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/consensus/beacon/src/engine/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ use reth_interfaces::{
test_utils::{NoopFullBlockClient, TestConsensus},
};
use reth_payload_builder::test_utils::spawn_test_payload_service;
use reth_primitives::{BlockNumber, ChainSpec, PruneModes, H256, U256};
use reth_primitives::{BlockNumber, ChainSpec, PruneBatchSizes, PruneModes, H256, U256};
use reth_provider::{
providers::BlockchainProvider, test_utils::TestExecutorFactory, BlockExecutor, ExecutorFactory,
ProviderFactory, StateProvider,
};
use reth_prune::{BatchSizes, Pruner};
use reth_prune::Pruner;
use reth_revm::Factory;
use reth_rpc_types::engine::{ExecutionPayload, ForkchoiceState, ForkchoiceUpdated, PayloadStatus};
use reth_stages::{
Expand Down Expand Up @@ -470,7 +470,7 @@ where
self.base_config.chain_spec.clone(),
5,
PruneModes::default(),
BatchSizes::default(),
PruneBatchSizes::default(),
);

let (mut engine, handle) = BeaconConsensusEngine::new(
Expand Down
22 changes: 16 additions & 6 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,
SealedHeader, H160, H256, U256,
PruneBatchSizes, SealedHeader, H160, H256, U256,
};
use hex_literal::hex;
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -63,7 +63,8 @@ pub static MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
11052984,
H256(hex!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5")),
)),
..Default::default()
base_fee_params: BaseFeeParams::ethereum(),
prune_batch_sizes: PruneBatchSizes::mainnet(),
Comment on lines +66 to +67
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

}
.into()
});
Expand Down Expand Up @@ -104,7 +105,8 @@ pub static GOERLI: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
4367322,
H256(hex!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5")),
)),
..Default::default()
base_fee_params: BaseFeeParams::ethereum(),
prune_batch_sizes: PruneBatchSizes::testnet(),
}
.into()
});
Expand Down Expand Up @@ -149,7 +151,8 @@ pub static SEPOLIA: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
1273020,
H256(hex!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5")),
)),
..Default::default()
base_fee_params: BaseFeeParams::ethereum(),
prune_batch_sizes: PruneBatchSizes::testnet(),
}
.into()
});
Expand Down Expand Up @@ -203,7 +206,7 @@ pub struct BaseFeeParams {
}

impl BaseFeeParams {
/// Get the base fee parameters for ethereum mainnet
/// Get the base fee parameters for Ethereum mainnet
pub const fn ethereum() -> BaseFeeParams {
BaseFeeParams {
max_change_denominator: EIP1559_DEFAULT_BASE_FEE_MAX_CHANGE_DENOMINATOR,
Expand Down Expand Up @@ -247,12 +250,18 @@ pub struct ChainSpec {
/// The active hard forks and their activation conditions
pub hardforks: BTreeMap<Hardfork, ForkCondition>,

/// The deposit contract deployed for PoS.
/// The deposit contract deployed for PoS
#[serde(skip, default)]
pub deposit_contract: Option<DepositContract>,

/// 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 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,
}

impl Default for ChainSpec {
Expand All @@ -266,6 +275,7 @@ impl Default for ChainSpec {
hardforks: Default::default(),
deposit_contract: Default::default(),
base_fee_params: BaseFeeParams::ethereum(),
prune_batch_sizes: Default::default(),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ pub use net::{
};
pub use peer::{PeerId, WithPeerId};
pub use prune::{
PruneCheckpoint, PruneMode, PruneModes, PrunePart, PrunePartError, ReceiptsLogPruneConfig,
MINIMUM_PRUNING_DISTANCE,
PruneBatchSizes, PruneCheckpoint, PruneMode, PruneModes, PrunePart, PrunePartError,
ReceiptsLogPruneConfig, MINIMUM_PRUNING_DISTANCE,
};
pub use receipt::{Receipt, ReceiptWithBloom, ReceiptWithBloomRef};
pub use revm_primitives::JumpMap;
Expand Down
83 changes: 83 additions & 0 deletions crates/primitives/src/prune/batch_sizes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
use paste::paste;
use serde::{Deserialize, Serialize};

/// Batch sizes for configuring the pruner.
/// The batch size for each prune part should be both large enough to prune the data which was
/// generated with each new block, and small enough to not generate an excessive load on the
/// database due to deletion of too many rows at once.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct PruneBatchSizes {
/// Maximum number of receipts to prune, per block.
receipts: usize,
/// Maximum number of transaction lookup entries to prune, per block.
transaction_lookup: usize,
/// Maximum number of transaction senders to prune, per block.
transaction_senders: usize,
/// Maximum number of account history entries to prune, per block.
/// Measured in the number of `AccountChangeSet` table rows.
account_history: usize,
/// Maximum number of storage history entries to prune, per block.
/// Measured in the number of `StorageChangeSet` table rows.
storage_history: usize,
}

macro_rules! impl_prune_batch_size_methods {
($(($human_name:expr, $name:ident)),+) => {
paste! {
impl PruneBatchSizes {
$(
#[doc = concat!("Maximum number of ", $human_name, " to prune, accounting for the block interval.")]
pub fn $name(&self, block_interval: usize) -> usize {
self.$name * block_interval
}

#[doc = concat!("Set the maximum number of ", $human_name, " to prune per block.")]
pub fn [<with_ $name>](mut self, batch_size: usize) -> Self {
self.$name = batch_size;
self
}
)+
}
}
};
}

impl_prune_batch_size_methods!(
("receipts", receipts),
("transaction lookup entries", transaction_lookup),
("transaction senders", transaction_senders),
("account history entries", account_history),
("storage history entries", storage_history)
);

impl PruneBatchSizes {
/// Default prune batch sizes for Ethereum mainnet.
/// These settings are sufficient to prune more data than generated with each new block.
pub const fn mainnet() -> Self {
Self {
receipts: 250,
transaction_lookup: 250,
transaction_senders: 250,
account_history: 1000,
Comment on lines +55 to +61
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assuming these are heuristics/made up?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • receipts, transaction_lookup and transaction_senders – basically transactions per block which currently sits at 150 avg, occasionally jumping up to 250
  • account_historyAccountChangeSet table on avg grows for 200 entries per block, AccountHistory is cleared up based on the results of clearing the changesets
  • storage_historyStorageChangeSet table on avg grows for 500 entries per block, StorageHistory is cleared up based on the results of clearing the changesets

I just added a new DB metric #4316 which will allow to measure these values more accurately, as I was gathering the data just snapshotting the db stats

storage_history: 1000,
}
}

/// Default prune batch sizes for Ethereum testnets.
/// These settings are sufficient to prune more data than generated with each new block.
pub const fn testnet() -> Self {
Self {
receipts: 100,
transaction_lookup: 100,
transaction_senders: 100,
account_history: 500,
storage_history: 500,
}
}
}

impl Default for PruneBatchSizes {
fn default() -> Self {
Self::mainnet()
}
}
2 changes: 2 additions & 0 deletions crates/primitives/src/prune/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
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
2 changes: 1 addition & 1 deletion crates/prune/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ mod pruner;

use crate::metrics::Metrics;
pub use error::PrunerError;
pub use pruner::{BatchSizes, Pruner, PrunerResult, PrunerWithResult};
pub use pruner::{Pruner, PrunerResult, PrunerWithResult};
Loading