chore: remove prune_modes from BlockWriter (#9231)

This commit is contained in:
Dan Cline
2024-07-02 15:40:07 -04:00
committed by GitHub
parent e95c6dba9d
commit 405b730455
19 changed files with 105 additions and 117 deletions

View File

@ -18,7 +18,7 @@ use reth_primitives::{
TransactionSigned, TransactionSignedNoHash, TxHash, TxNumber, Withdrawal, Withdrawals, B256,
U256,
};
use reth_prune_types::{PruneCheckpoint, PruneSegment};
use reth_prune_types::{PruneCheckpoint, PruneModes, PruneSegment};
use reth_stages_types::{StageCheckpoint, StageId};
use reth_storage_errors::provider::ProviderResult;
use revm::primitives::{BlockEnv, CfgEnvWithHandlerCfg};
@ -46,6 +46,8 @@ pub struct ProviderFactory<DB> {
chain_spec: Arc<ChainSpec>,
/// Static File Provider
static_file_provider: StaticFileProvider,
/// Optional pruning configuration
prune_modes: PruneModes,
}
impl<DB> ProviderFactory<DB> {
@ -55,7 +57,7 @@ impl<DB> ProviderFactory<DB> {
chain_spec: Arc<ChainSpec>,
static_file_provider: StaticFileProvider,
) -> Self {
Self { db: Arc::new(db), chain_spec, static_file_provider }
Self { db: Arc::new(db), chain_spec, static_file_provider, prune_modes: PruneModes::none() }
}
/// Enables metrics on the static file provider.
@ -64,6 +66,12 @@ impl<DB> ProviderFactory<DB> {
self
}
/// Sets the pruning configuration for an existing [`ProviderFactory`].
pub fn with_prune_modes(mut self, prune_modes: PruneModes) -> Self {
self.prune_modes = prune_modes;
self
}
/// Returns reference to the underlying database.
pub fn db_ref(&self) -> &DB {
&self.db
@ -89,6 +97,7 @@ impl ProviderFactory<DatabaseEnv> {
db: Arc::new(init_db(path, args).map_err(RethError::msg)?),
chain_spec,
static_file_provider,
prune_modes: PruneModes::none(),
})
}
}
@ -97,12 +106,16 @@ impl<DB: Database> ProviderFactory<DB> {
/// Returns a provider with a created `DbTx` inside, which allows fetching data from the
/// database using different types of providers. Example: [`HeaderProvider`]
/// [`BlockHashReader`]. This may fail if the inner read database transaction fails to open.
///
/// This sets the [`PruneModes`] to [`None`], because they should only be relevant for writing
/// data.
#[track_caller]
pub fn provider(&self) -> ProviderResult<DatabaseProviderRO<DB>> {
Ok(DatabaseProvider::new(
self.db.tx()?,
self.chain_spec.clone(),
self.static_file_provider.clone(),
self.prune_modes.clone(),
))
}
@ -116,6 +129,7 @@ impl<DB: Database> ProviderFactory<DB> {
self.db.tx_mut()?,
self.chain_spec.clone(),
self.static_file_provider.clone(),
self.prune_modes.clone(),
)))
}
@ -576,6 +590,7 @@ impl<DB> Clone for ProviderFactory<DB> {
db: Arc::clone(&self.db),
chain_spec: self.chain_spec.clone(),
static_file_provider: self.static_file_provider.clone(),
prune_modes: self.prune_modes.clone(),
}
}
}
@ -661,7 +676,7 @@ mod tests {
{
let provider = factory.provider_rw().unwrap();
assert_matches!(
provider.insert_block(block.clone().try_seal_with_senders().unwrap(), None),
provider.insert_block(block.clone().try_seal_with_senders().unwrap()),
Ok(_)
);
assert_matches!(
@ -672,16 +687,14 @@ mod tests {
}
{
let provider = factory.provider_rw().unwrap();
let prune_modes = PruneModes {
sender_recovery: Some(PruneMode::Full),
transaction_lookup: Some(PruneMode::Full),
..PruneModes::none()
};
let provider = factory.with_prune_modes(prune_modes).provider_rw().unwrap();
assert_matches!(
provider.insert_block(
block.clone().try_seal_with_senders().unwrap(),
Some(&PruneModes {
sender_recovery: Some(PruneMode::Full),
transaction_lookup: Some(PruneMode::Full),
..PruneModes::none()
})
),
provider.insert_block(block.clone().try_seal_with_senders().unwrap(),),
Ok(_)
);
assert_matches!(provider.transaction_sender(0), Ok(None));
@ -701,7 +714,7 @@ mod tests {
let provider = factory.provider_rw().unwrap();
assert_matches!(
provider.insert_block(block.clone().try_seal_with_senders().unwrap(), None),
provider.insert_block(block.clone().try_seal_with_senders().unwrap()),
Ok(_)
);