Skip to content

Commit

Permalink
chore: remove prune_modes from BlockWriter
Browse files Browse the repository at this point in the history
This removes the `prune_modes` argument from the `BlockWriter` trait,
because the argument leaks a node implementation detail into the storage
abstraction. Instead, the it is included as a field in
`ProviderFactory`, as well as `DatabaseProvider`, although it is only
used in the RW version of `DatabaseProvider`.

When the blockchain tree is initialized, the prune modes are set, so
that we achieve the same behavior as before when writing.
  • Loading branch information
Rjected committed Jul 1, 2024
1 parent d317b4a commit 88fa01e
Show file tree
Hide file tree
Showing 28 changed files with 99 additions and 80 deletions.
7 changes: 4 additions & 3 deletions bin/reth/src/commands/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ impl EnvironmentArgs {
static_file_provider: StaticFileProvider,
) -> eyre::Result<ProviderFactory<Arc<DatabaseEnv>>> {
let has_receipt_pruning = config.prune.as_ref().map_or(false, |a| a.has_receipts_pruning());
let factory = ProviderFactory::new(db, self.chain.clone(), static_file_provider);
let prune_modes = config.prune.clone().map(|prune| prune.segments);
let factory =
ProviderFactory::new(db, self.chain.clone(), static_file_provider, prune_modes.clone());

info!(target: "reth::cli", "Verifying storage consistency.");

Expand All @@ -123,14 +125,13 @@ impl EnvironmentArgs {
return Ok(factory)
}

let prune_modes = config.prune.clone().map(|prune| prune.segments).unwrap_or_default();

// Highly unlikely to happen, and given its destructive nature, it's better to panic
// instead.
assert_ne!(unwind_target, PipelineTarget::Unwind(0), "A static file <> database inconsistency was found that would trigger an unwind to block 0");

info!(target: "reth::cli", unwind_target = %unwind_target, "Executing an unwind after a failed storage consistency check.");

let prune_modes = prune_modes.unwrap_or_default();
let (_tip_tx, tip_rx) = watch::channel(B256::ZERO);

// Builds and executes an unwind-only pipeline
Expand Down
1 change: 0 additions & 1 deletion bin/reth/src/commands/debug_cmd/build_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ impl Command {
execution_outcome,
hashed_post_state,
trie_updates,
None,
)?;
info!(target: "reth::cli", "Successfully appended built block");
}
Expand Down
1 change: 0 additions & 1 deletion bin/reth/src/commands/debug_cmd/in_memory_merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ impl Command {
.clone()
.try_seal_with_senders()
.map_err(|_| BlockValidationError::SenderRecoveryError)?,
None,
)?;
execution_outcome.write_to_storage(provider_rw.tx_ref(), None, OriginalValuesKnown::No)?;
let storage_lists = provider_rw.changed_storages_with_range(block.number..=block.number)?;
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/commands/debug_cmd/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl Command {
.map_err(|block| eyre::eyre!("Error sealing block with senders: {block:?}"))?;
trace!(target: "reth::cli", block_number, "Executing block");

provider_rw.insert_block(sealed_block.clone(), None)?;
provider_rw.insert_block(sealed_block.clone())?;

td += sealed_block.difficulty;
let mut executor = executor_provider.batch_executor(
Expand Down
1 change: 1 addition & 0 deletions bin/reth/src/commands/p2p/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ impl Command {
noop_db,
self.chain.clone(),
StaticFileProvider::read_write(data_dir.static_files())?,
None,
)))
.start_network()
.await?;
Expand Down
1 change: 1 addition & 0 deletions bin/reth/src/commands/stage/dump/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub(crate) async fn dump_execution_stage<DB: Database>(
output_db,
db_tool.chain(),
StaticFileProvider::read_write(output_datadir.static_files())?,
None,
),
to,
from,
Expand Down
1 change: 1 addition & 0 deletions bin/reth/src/commands/stage/dump/hashing_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub(crate) async fn dump_hashing_account_stage<DB: Database>(
output_db,
db_tool.chain(),
StaticFileProvider::read_write(output_datadir.static_files())?,
None,
),
to,
from,
Expand Down
1 change: 1 addition & 0 deletions bin/reth/src/commands/stage/dump/hashing_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub(crate) async fn dump_hashing_storage_stage<DB: Database>(
output_db,
db_tool.chain(),
StaticFileProvider::read_write(output_datadir.static_files())?,
None,
),
to,
from,
Expand Down
1 change: 1 addition & 0 deletions bin/reth/src/commands/stage/dump/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub(crate) async fn dump_merkle_stage<DB: Database>(
output_db,
db_tool.chain(),
StaticFileProvider::read_write(output_datadir.static_files())?,
None,
),
to,
from,
Expand Down
11 changes: 4 additions & 7 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ pub struct BlockchainTree<DB, E> {
externals: TreeExternals<DB, E>,
/// Tree configuration
config: BlockchainTreeConfig,
/// Prune modes.
prune_modes: Option<PruneModes>,
/// Broadcast channel for canon state changes notifications.
canon_state_notification_sender: CanonStateNotificationSender,
/// Metrics for sync stages.
Expand Down Expand Up @@ -115,7 +113,7 @@ where
/// storage space efficiently. It's important to validate this configuration to ensure it does
/// not lead to unintended data loss.
pub fn new(
externals: TreeExternals<DB, E>,
mut externals: TreeExternals<DB, E>,
config: BlockchainTreeConfig,
prune_modes: Option<PruneModes>,
) -> ProviderResult<Self> {
Expand All @@ -125,6 +123,9 @@ where
let (canon_state_notification_sender, _receiver) =
tokio::sync::broadcast::channel(max_reorg_depth * 2);

// Set the prune modes argument, on the provider
externals.provider_factory = externals.provider_factory.with_prune_modes(prune_modes);

let last_canonical_hashes =
externals.fetch_latest_canonical_hashes(config.num_of_canonical_hashes() as usize)?;

Expand All @@ -138,7 +139,6 @@ where
config.max_unconnected_blocks(),
),
config,
prune_modes,
canon_state_notification_sender,
sync_metrics_tx: None,
metrics: Default::default(),
Expand Down Expand Up @@ -1258,7 +1258,6 @@ where
state,
hashed_state,
trie_updates,
self.prune_modes.as_ref(),
)
.map_err(|e| CanonicalError::CanonicalCommit(e.to_string()))?;

Expand Down Expand Up @@ -1424,7 +1423,6 @@ mod tests {
provider
.insert_historical_block(
genesis.try_seal_with_senders().expect("invalid tx signature in genesis"),
None,
)
.unwrap();

Expand Down Expand Up @@ -1545,7 +1543,6 @@ mod tests {
SealedBlock::new(chain_spec.sealed_genesis_header(), Default::default())
.try_seal_with_senders()
.unwrap(),
None,
)
.unwrap();
let account = Account { balance: initial_signer_balance, ..Default::default() };
Expand Down
11 changes: 10 additions & 1 deletion crates/consensus/beacon/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2159,7 +2159,6 @@ mod tests {
provider
.insert_block(
b.clone().try_seal_with_senders().expect("invalid tx signature in block"),
None,
)
.map(drop)
})
Expand Down Expand Up @@ -2233,6 +2232,7 @@ mod tests {
env.db.as_ref(),
chain_spec.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
None,
),
[&genesis, &block1].into_iter(),
);
Expand Down Expand Up @@ -2293,6 +2293,7 @@ mod tests {
env.db.as_ref(),
chain_spec.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
None,
),
[&genesis, &block1].into_iter(),
);
Expand All @@ -2317,6 +2318,7 @@ mod tests {
env.db.as_ref(),
chain_spec.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
None,
),
std::iter::once(&next_head),
);
Expand Down Expand Up @@ -2361,6 +2363,7 @@ mod tests {
env.db.as_ref(),
chain_spec.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
None,
),
[&genesis, &block1].into_iter(),
);
Expand Down Expand Up @@ -2416,6 +2419,7 @@ mod tests {
env.db.as_ref(),
chain_spec.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
None,
),
[&genesis, &block1, &block2, &block3].into_iter(),
);
Expand Down Expand Up @@ -2465,6 +2469,7 @@ mod tests {
env.db.as_ref(),
chain_spec.clone(),
StaticFileProvider::read_write(temp_dir_path).unwrap(),
None,
),
[&genesis, &block1].into_iter(),
);
Expand Down Expand Up @@ -2569,6 +2574,7 @@ mod tests {
env.db.as_ref(),
chain_spec.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
None,
),
[&genesis, &block1, &block2].into_iter(),
);
Expand Down Expand Up @@ -2641,6 +2647,7 @@ mod tests {
env.db.as_ref(),
chain_spec.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
None,
),
[&genesis, &block1].into_iter(),
);
Expand Down Expand Up @@ -2688,6 +2695,7 @@ mod tests {
env.db.as_ref(),
chain_spec.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
None,
),
std::iter::once(&genesis),
);
Expand Down Expand Up @@ -2755,6 +2763,7 @@ mod tests {
env.db.as_ref(),
chain_spec.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
None,
),
[&data.genesis, &block1].into_iter(),
);
Expand Down
1 change: 0 additions & 1 deletion crates/exex/exex/src/backfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ mod tests {
outcome_batch,
Default::default(),
Default::default(),
None,
)?;
provider_rw.commit()?;

Expand Down
6 changes: 6 additions & 0 deletions crates/net/downloaders/src/bodies/bodies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ mod tests {
db,
MAINNET.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
None,
),
);
downloader.set_download_range(0..=19).expect("failed to set download range");
Expand Down Expand Up @@ -684,6 +685,7 @@ mod tests {
db,
MAINNET.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
None,
),
);
downloader.set_download_range(0..=199).expect("failed to set download range");
Expand Down Expand Up @@ -718,6 +720,7 @@ mod tests {
db,
MAINNET.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
None,
),
);

Expand Down Expand Up @@ -754,6 +757,7 @@ mod tests {
db,
MAINNET.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
None,
),
);

Expand Down Expand Up @@ -800,6 +804,7 @@ mod tests {
db,
MAINNET.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
None,
),
);

Expand Down Expand Up @@ -837,6 +842,7 @@ mod tests {
db,
MAINNET.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
None,
),
);

Expand Down
1 change: 1 addition & 0 deletions crates/node/builder/src/launch/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ where
self.right().clone(),
self.chain_spec(),
StaticFileProvider::read_write(self.data_dir().static_files())?,
self.prune_modes(),
)
.with_static_files_metrics();

Expand Down
1 change: 1 addition & 0 deletions crates/prune/prune/src/pruner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ mod tests {
db,
MAINNET.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
None,
);

let (finished_exex_height_tx, finished_exex_height_rx) =
Expand Down
Loading

0 comments on commit 88fa01e

Please sign in to comment.