Skip to content

Commit

Permalink
feat: integrate generic primitives into pruner (paradigmxyz#12995)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored Nov 29, 2024
1 parent 9fe459e commit 3f9816e
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 40 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 2 additions & 12 deletions crates/primitives-traits/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::fmt;

use crate::{
Block, BlockBody, BlockHeader, FullBlock, FullBlockBody, FullBlockHeader, FullReceipt,
FullSignedTx, FullTxType, MaybeArbitrary, MaybeSerde,
FullSignedTx, FullTxType, MaybeArbitrary, MaybeSerde, Receipt,
};

/// Configures all the primitive types of the node.
Expand Down Expand Up @@ -38,17 +38,7 @@ pub trait NodePrimitives:
+ MaybeArbitrary
+ 'static;
/// A receipt.
type Receipt: Send
+ Sync
+ Unpin
+ Clone
+ Default
+ fmt::Debug
+ PartialEq
+ Eq
+ MaybeSerde
+ MaybeArbitrary
+ 'static;
type Receipt: Receipt;
}
/// Helper trait that sets trait bounds on [`NodePrimitives`].
pub trait FullNodePrimitives
Expand Down
2 changes: 2 additions & 0 deletions crates/prune/prune/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ reth-provider.workspace = true
reth-tokio-util.workspace = true
reth-config.workspace = true
reth-prune-types.workspace = true
reth-primitives-traits.workspace = true
reth-static-file-types.workspace = true

# ethereum
alloy-consensus.workspace = true
alloy-eips.workspace = true

# metrics
Expand Down
9 changes: 6 additions & 3 deletions crates/prune/prune/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use crate::{segments::SegmentSet, Pruner};
use alloy_eips::eip2718::Encodable2718;
use reth_chainspec::MAINNET;
use reth_config::PruneConfig;
use reth_db::transaction::DbTxMut;
use reth_db::{table::Value, transaction::DbTxMut};
use reth_exex_types::FinishedExExHeight;
use reth_primitives_traits::NodePrimitives;
use reth_provider::{
providers::StaticFileProvider, BlockReader, DBProvider, DatabaseProviderFactory,
NodePrimitivesProvider, PruneCheckpointWriter, StaticFileProviderFactory,
Expand Down Expand Up @@ -80,7 +81,9 @@ impl PrunerBuilder {
PF: DatabaseProviderFactory<
ProviderRW: PruneCheckpointWriter
+ BlockReader<Transaction: Encodable2718>
+ StaticFileProviderFactory,
+ StaticFileProviderFactory<
Primitives: NodePrimitives<SignedTx: Value, Receipt: Value>,
>,
> + StaticFileProviderFactory<
Primitives = <PF::ProviderRW as NodePrimitivesProvider>::Primitives,
>,
Expand All @@ -104,7 +107,7 @@ impl PrunerBuilder {
static_file_provider: StaticFileProvider<Provider::Primitives>,
) -> Pruner<Provider, ()>
where
Provider: StaticFileProviderFactory
Provider: StaticFileProviderFactory<Primitives: NodePrimitives<SignedTx: Value, Receipt: Value>>
+ DBProvider<Tx: DbTxMut>
+ BlockReader<Transaction: Encodable2718>
+ PruneCheckpointWriter,
Expand Down
16 changes: 11 additions & 5 deletions crates/prune/prune/src/segments/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
//! node after static file producer has finished

use crate::{db_ext::DbTxPruneExt, segments::PruneInput, PrunerError};
use reth_db::{tables, transaction::DbTxMut};
use reth_db::{table::Value, tables, transaction::DbTxMut};
use reth_primitives_traits::NodePrimitives;
use reth_provider::{
errors::provider::ProviderResult, BlockReader, DBProvider, PruneCheckpointWriter,
TransactionsProvider,
errors::provider::ProviderResult, BlockReader, DBProvider, NodePrimitivesProvider,
PruneCheckpointWriter, TransactionsProvider,
};
use reth_prune_types::{
PruneCheckpoint, PruneProgress, PruneSegment, SegmentOutput, SegmentOutputCheckpoint,
Expand All @@ -21,7 +22,10 @@ pub(crate) fn prune<Provider>(
input: PruneInput,
) -> Result<SegmentOutput, PrunerError>
where
Provider: DBProvider<Tx: DbTxMut> + TransactionsProvider + BlockReader,
Provider: DBProvider<Tx: DbTxMut>
+ TransactionsProvider
+ BlockReader
+ NodePrimitivesProvider<Primitives: NodePrimitives<Receipt: Value>>,
{
let tx_range = match input.get_next_tx_num_range(provider)? {
Some(range) => range,
Expand All @@ -35,7 +39,9 @@ where
let mut limiter = input.limiter;

let mut last_pruned_transaction = tx_range_end;
let (pruned, done) = provider.tx_ref().prune_table_with_range::<tables::Receipts>(
let (pruned, done) = provider.tx_ref().prune_table_with_range::<tables::Receipts<
<Provider::Primitives as NodePrimitives>::Receipt,
>>(
tx_range,
&mut limiter,
|_| false,
Expand Down
5 changes: 3 additions & 2 deletions crates/prune/prune/src/segments/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use crate::segments::{
UserReceipts,
};
use alloy_eips::eip2718::Encodable2718;
use reth_db::transaction::DbTxMut;
use reth_db::{table::Value, transaction::DbTxMut};
use reth_primitives_traits::NodePrimitives;
use reth_provider::{
providers::StaticFileProvider, BlockReader, DBProvider, PruneCheckpointWriter,
StaticFileProviderFactory,
Expand Down Expand Up @@ -46,7 +47,7 @@ impl<Provider> SegmentSet<Provider> {

impl<Provider> SegmentSet<Provider>
where
Provider: StaticFileProviderFactory
Provider: StaticFileProviderFactory<Primitives: NodePrimitives<SignedTx: Value, Receipt: Value>>
+ DBProvider<Tx: DbTxMut>
+ PruneCheckpointWriter
+ BlockReader<Transaction: Encodable2718>,
Expand Down
5 changes: 3 additions & 2 deletions crates/prune/prune/src/segments/static_file/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::{
segments::{PruneInput, Segment},
PrunerError,
};
use reth_db::transaction::DbTxMut;
use reth_db::{table::Value, transaction::DbTxMut};
use reth_primitives_traits::NodePrimitives;
use reth_provider::{
errors::provider::ProviderResult, providers::StaticFileProvider, BlockReader, DBProvider,
PruneCheckpointWriter, StaticFileProviderFactory, TransactionsProvider,
Expand All @@ -23,7 +24,7 @@ impl<N> Receipts<N> {

impl<Provider> Segment<Provider> for Receipts<Provider::Primitives>
where
Provider: StaticFileProviderFactory
Provider: StaticFileProviderFactory<Primitives: NodePrimitives<Receipt: Value>>
+ DBProvider<Tx: DbTxMut>
+ PruneCheckpointWriter
+ TransactionsProvider
Expand Down
13 changes: 9 additions & 4 deletions crates/prune/prune/src/segments/static_file/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use crate::{
segments::{PruneInput, Segment},
PrunerError,
};
use reth_db::{tables, transaction::DbTxMut};
use reth_db::{table::Value, tables, transaction::DbTxMut};
use reth_primitives_traits::NodePrimitives;
use reth_provider::{
providers::StaticFileProvider, BlockReader, DBProvider, StaticFileProviderFactory,
TransactionsProvider,
Expand All @@ -27,8 +28,10 @@ impl<N> Transactions<N> {

impl<Provider> Segment<Provider> for Transactions<Provider::Primitives>
where
Provider:
DBProvider<Tx: DbTxMut> + TransactionsProvider + BlockReader + StaticFileProviderFactory,
Provider: DBProvider<Tx: DbTxMut>
+ TransactionsProvider
+ BlockReader
+ StaticFileProviderFactory<Primitives: NodePrimitives<SignedTx: Value>>,
{
fn segment(&self) -> PruneSegment {
PruneSegment::Transactions
Expand Down Expand Up @@ -56,7 +59,9 @@ where
let mut limiter = input.limiter;

let mut last_pruned_transaction = *tx_range.end();
let (pruned, done) = provider.tx_ref().prune_table_with_range::<tables::Transactions>(
let (pruned, done) = provider.tx_ref().prune_table_with_range::<tables::Transactions<
<Provider::Primitives as NodePrimitives>::SignedTx,
>>(
tx_range,
&mut limiter,
|_| false,
Expand Down
13 changes: 9 additions & 4 deletions crates/prune/prune/src/segments/user/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use crate::{
segments::{PruneInput, Segment},
PrunerError,
};
use reth_db::transaction::DbTxMut;
use reth_db::{table::Value, transaction::DbTxMut};
use reth_primitives_traits::NodePrimitives;
use reth_provider::{
errors::provider::ProviderResult, BlockReader, DBProvider, PruneCheckpointWriter,
TransactionsProvider,
errors::provider::ProviderResult, BlockReader, DBProvider, NodePrimitivesProvider,
PruneCheckpointWriter, TransactionsProvider,
};
use reth_prune_types::{PruneCheckpoint, PruneMode, PrunePurpose, PruneSegment, SegmentOutput};
use tracing::instrument;
Expand All @@ -23,7 +24,11 @@ impl Receipts {

impl<Provider> Segment<Provider> for Receipts
where
Provider: DBProvider<Tx: DbTxMut> + PruneCheckpointWriter + TransactionsProvider + BlockReader,
Provider: DBProvider<Tx: DbTxMut>
+ PruneCheckpointWriter
+ TransactionsProvider
+ BlockReader
+ NodePrimitivesProvider<Primitives: NodePrimitives<Receipt: Value>>,
{
fn segment(&self) -> PruneSegment {
PruneSegment::Receipts
Expand Down
20 changes: 15 additions & 5 deletions crates/prune/prune/src/segments/user/receipts_by_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ use crate::{
segments::{PruneInput, Segment},
PrunerError,
};
use reth_db::{tables, transaction::DbTxMut};
use reth_provider::{BlockReader, DBProvider, PruneCheckpointWriter, TransactionsProvider};
use alloy_consensus::TxReceipt;
use reth_db::{table::Value, tables, transaction::DbTxMut};
use reth_primitives_traits::NodePrimitives;
use reth_provider::{
BlockReader, DBProvider, NodePrimitivesProvider, PruneCheckpointWriter, TransactionsProvider,
};
use reth_prune_types::{
PruneCheckpoint, PruneMode, PruneProgress, PrunePurpose, PruneSegment, ReceiptsLogPruneConfig,
SegmentOutput, MINIMUM_PRUNING_DISTANCE,
Expand All @@ -23,7 +27,11 @@ impl ReceiptsByLogs {

impl<Provider> Segment<Provider> for ReceiptsByLogs
where
Provider: DBProvider<Tx: DbTxMut> + PruneCheckpointWriter + TransactionsProvider + BlockReader,
Provider: DBProvider<Tx: DbTxMut>
+ PruneCheckpointWriter
+ TransactionsProvider
+ BlockReader
+ NodePrimitivesProvider<Primitives: NodePrimitives<Receipt: Value>>,
{
fn segment(&self) -> PruneSegment {
PruneSegment::ContractLogs
Expand Down Expand Up @@ -141,12 +149,14 @@ where
// Delete receipts, except the ones in the inclusion list
let mut last_skipped_transaction = 0;
let deleted;
(deleted, done) = provider.tx_ref().prune_table_with_range::<tables::Receipts>(
(deleted, done) = provider.tx_ref().prune_table_with_range::<tables::Receipts<
<Provider::Primitives as NodePrimitives>::Receipt,
>>(
tx_range,
&mut limiter,
|(tx_num, receipt)| {
let skip = num_addresses > 0 &&
receipt.logs.iter().any(|log| {
receipt.logs().iter().any(|log| {
filtered_addresses[..num_addresses].contains(&&log.address)
});

Expand Down
7 changes: 4 additions & 3 deletions crates/stages/stages/src/stages/prune.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use reth_db::transaction::DbTxMut;
use reth_db::{table::Value, transaction::DbTxMut};
use reth_primitives::NodePrimitives;
use reth_provider::{
BlockReader, DBProvider, PruneCheckpointReader, PruneCheckpointWriter,
StaticFileProviderFactory,
Expand Down Expand Up @@ -41,7 +42,7 @@ where
+ PruneCheckpointReader
+ PruneCheckpointWriter
+ BlockReader
+ StaticFileProviderFactory,
+ StaticFileProviderFactory<Primitives: NodePrimitives<SignedTx: Value, Receipt: Value>>,
{
fn id(&self) -> StageId {
StageId::Prune
Expand Down Expand Up @@ -130,7 +131,7 @@ where
+ PruneCheckpointReader
+ PruneCheckpointWriter
+ BlockReader
+ StaticFileProviderFactory,
+ StaticFileProviderFactory<Primitives: NodePrimitives<SignedTx: Value, Receipt: Value>>,
{
fn id(&self) -> StageId {
StageId::PruneSenderRecovery
Expand Down

0 comments on commit 3f9816e

Please sign in to comment.