feat(op): allow import without state (#7661)

This commit is contained in:
Emilia Hane
2024-04-19 14:17:31 +02:00
committed by GitHub
parent cf163ba9d8
commit f4dda95cbd
3 changed files with 127 additions and 92 deletions

View File

@ -41,6 +41,17 @@ use std::{path::PathBuf, sync::Arc};
use tokio::sync::watch;
use tracing::{debug, info};
/// Stages that require state.
const STATE_STAGES: &[StageId] = &[
StageId::Execution,
StageId::MerkleUnwind,
StageId::AccountHashing,
StageId::StorageHashing,
StageId::MerkleExecute,
StageId::IndexStorageHistory,
StageId::IndexAccountHistory,
];
/// Syncs RLP encoded blocks from a file.
#[derive(Debug, Parser)]
pub struct ImportCommand {
@ -70,9 +81,9 @@ pub struct ImportCommand {
)]
chain: Arc<ChainSpec>,
/// Disables execution stage.
/// Disables stages that require state.
#[arg(long, verbatim_doc_comment)]
disable_execution: bool,
no_state: bool,
/// Import OP Mainnet chain below Bedrock. Caution! Flag must be set as env var, since the env
/// var is read by another process too, in order to make below Bedrock import work.
@ -100,12 +111,12 @@ impl ImportCommand {
info!(target: "reth::cli", "reth {} starting", SHORT_VERSION);
if self.op_mainnet_below_bedrock {
self.disable_execution = true;
self.no_state = true;
debug!(target: "reth::cli", "Importing OP mainnet below bedrock");
}
if self.disable_execution {
debug!(target: "reth::cli", "Execution stage disabled");
if self.no_state {
debug!(target: "reth::cli", "Stages requiring state disabled");
}
debug!(target: "reth::cli",
@ -163,7 +174,7 @@ impl ImportCommand {
provider_factory.static_file_provider(),
PruneModes::default(),
),
self.disable_execution,
self.no_state,
)
.await?;
@ -201,7 +212,7 @@ impl ImportCommand {
consensus: &Arc<C>,
file_client: Arc<FileClient>,
static_file_producer: StaticFileProducer<DB>,
disable_execution: bool,
no_state: bool,
) -> eyre::Result<(Pipeline<DB>, impl Stream<Item = NodeEvent>)>
where
DB: Database + Clone + Unpin + 'static,
@ -263,7 +274,7 @@ impl ImportCommand {
.max(config.stages.storage_hashing.clean_threshold),
config.prune.clone().map(|prune| prune.segments).unwrap_or_default(),
))
.disable_if(StageId::Execution, || disable_execution),
.disable_all_if(STATE_STAGES, || no_state),
)
.build(provider_factory, static_file_producer);