fix(cli): set start header (#7725)

Co-authored-by: Roman Krasiuk <rokrassyuk@gmail.com>
This commit is contained in:
Emilia Hane
2024-04-25 13:47:27 +02:00
committed by GitHub
parent 0f7e3541b1
commit c7008deef8
4 changed files with 21 additions and 15 deletions

8
Cargo.lock generated
View File

@ -8934,18 +8934,18 @@ checksum = "a38c90d48152c236a3ab59271da4f4ae63d678c5d7ad6b7714d7cb9760be5e4b"
[[package]]
name = "thiserror"
version = "1.0.59"
version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa"
checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.59"
version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66"
checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7"
dependencies = [
"proc-macro2",
"quote",

View File

@ -316,7 +316,7 @@ lint:
make fmt && \
make lint-reth && \
make lint-op-reth && \
make lint-other-targets \
make lint-other-targets && \
make lint-codespell
fix-lint-reth:

View File

@ -29,7 +29,10 @@ use reth_node_core::init::init_genesis;
use reth_node_ethereum::EthEvmConfig;
use reth_node_events::node::NodeEvent;
use reth_primitives::{stage::StageId, ChainSpec, PruneModes, B256};
use reth_provider::{HeaderSyncMode, ProviderFactory, StageCheckpointReader};
use reth_provider::{
BlockNumReader, HeaderProvider, HeaderSyncMode, ProviderError, ProviderFactory,
StageCheckpointReader,
};
use reth_stages::{
prelude::*,
stages::{ExecutionStage, ExecutionStageThresholds, SenderRecoveryStage},
@ -158,8 +161,7 @@ impl ImportCommand {
"Importing chain file chunk"
);
// override the tip
let tip = file_client.tip().expect("file client has no tip");
let tip = file_client.tip().ok_or(eyre::eyre!("file client has no tip"))?;
info!(target: "reth::cli", "Chain file chunk read");
let (mut pipeline, events) = self
@ -221,15 +223,25 @@ impl ImportCommand {
eyre::bail!("unable to import non canonical blocks");
}
// Retrieve latest header found in the database.
let last_block_number = provider_factory.last_block_number()?;
let local_head = provider_factory
.sealed_header(last_block_number)?
.ok_or(ProviderError::HeaderNotFound(last_block_number.into()))?;
let mut header_downloader = ReverseHeadersDownloaderBuilder::new(config.stages.headers)
.build(file_client.clone(), consensus.clone())
.into_task();
header_downloader.update_local_head(file_client.start_header().unwrap());
// TODO: The pipeline should correctly configure the downloader on its own.
// Find the possibility to remove unnecessary pre-configuration.
header_downloader.update_local_head(local_head);
header_downloader.update_sync_target(SyncTarget::Tip(file_client.tip().unwrap()));
let mut body_downloader = BodiesDownloaderBuilder::new(config.stages.bodies)
.build(file_client.clone(), consensus.clone(), provider_factory.clone())
.into_task();
// TODO: The pipeline should correctly configure the downloader on its own.
// Find the possibility to remove unnecessary pre-configuration.
body_downloader
.set_download_range(file_client.min_block().unwrap()..=file_client.max_block().unwrap())
.expect("failed to set download range");

View File

@ -179,12 +179,6 @@ impl FileClient {
self.headers.get(&self.max_block()?).map(|h| h.clone().seal_slow())
}
/// Clones and returns the lowest header of this client has or `None` if empty. Seals header
/// before returning.
pub fn start_header(&self) -> Option<SealedHeader> {
self.headers.get(&self.min_block()?).map(|h| h.clone().seal_slow())
}
/// Returns true if all blocks are canonical (no gaps)
pub fn has_canonical_blocks(&self) -> bool {
if self.headers.is_empty() {