Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(downloader): replace database with header provider #5472

Merged
merged 3 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

6 changes: 5 additions & 1 deletion bin/reth/src/chain/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ impl ImportCommand {
.into_task();

let body_downloader = BodiesDownloaderBuilder::from(config.stages.bodies)
.build(file_client.clone(), consensus.clone(), db.clone())
.build(
file_client.clone(),
consensus.clone(),
ProviderFactory::new(db.clone(), self.chain.clone()),
)
.into_task();

let (tip_tx, tip_rx) = watch::channel(B256::ZERO);
Expand Down
6 changes: 5 additions & 1 deletion bin/reth/src/debug_cmd/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ impl Command {
.into_task_with(task_executor);

let body_downloader = BodiesDownloaderBuilder::from(config.stages.bodies)
.build(client, Arc::clone(&consensus), db.clone())
.build(
client,
Arc::clone(&consensus),
ProviderFactory::new(db.clone(), self.chain.clone()),
)
.into_task_with(task_executor);

let stage_conf = &config.stages;
Expand Down
6 changes: 5 additions & 1 deletion bin/reth/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,11 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
.into_task_with(task_executor);

let body_downloader = BodiesDownloaderBuilder::from(config.stages.bodies)
.build(client, Arc::clone(&consensus), db.clone())
.build(
client,
Arc::clone(&consensus),
ProviderFactory::new(db.clone(), self.chain.clone()),
)
.into_task_with(task_executor);

let pipeline = self
Expand Down
8 changes: 5 additions & 3 deletions bin/reth/src/stage/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ impl Command {

let default_peers_path = data_dir.known_peers_path();

let provider_factory =
Arc::new(ProviderFactory::new(db.clone(), self.chain.clone()));

let network = self
.network
.network_config(
Expand All @@ -171,7 +174,7 @@ impl Command {
p2p_secret_key,
default_peers_path,
)
.build(Arc::new(ProviderFactory::new(db.clone(), self.chain.clone())))
.build(provider_factory.clone())
.start_network()
.await?;
let fetch_client = Arc::new(network.fetch_client().await?);
Expand All @@ -187,9 +190,8 @@ impl Command {
config.stages.bodies.downloader_min_concurrent_requests..=
config.stages.bodies.downloader_max_concurrent_requests,
)
.build(fetch_client, consensus.clone(), db.clone()),
.build(fetch_client, consensus.clone(), provider_factory),
);

(Box::new(stage), None)
}
StageEnum::Senders => (Box::new(SenderRecoveryStage::new(batch_size)), None),
Expand Down
7 changes: 4 additions & 3 deletions crates/consensus/beacon/src/engine/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ where
pub fn build(self) -> (TestBeaconConsensusEngine<Client>, TestEnv<Arc<DatabaseEnv>>) {
reth_tracing::init_test_tracing();
let db = create_test_rw_db();
let provider_factory =
ProviderFactory::new(db.clone(), self.base_config.chain_spec.clone());

let consensus: Arc<dyn Consensus> = match self.base_config.consensus {
TestConsensusConfig::Real => {
Expand Down Expand Up @@ -496,7 +498,7 @@ where
.into_task();

let body_downloader = BodiesDownloaderBuilder::default()
.build(client.clone(), consensus.clone(), db.clone())
.build(client.clone(), consensus.clone(), provider_factory.clone())
.into_task();

Pipeline::builder().add_stages(DefaultStages::new(
Expand Down Expand Up @@ -527,9 +529,8 @@ where
let tree = ShareableBlockchainTree::new(
BlockchainTree::new(externals, config, None).expect("failed to create tree"),
);
let shareable_db = ProviderFactory::new(db.clone(), self.base_config.chain_spec.clone());
let latest = self.base_config.chain_spec.genesis_header().seal_slow();
let blockchain_provider = BlockchainProvider::with_latest(shareable_db, tree, latest);
let blockchain_provider = BlockchainProvider::with_latest(provider_factory, tree, latest);

let pruner = Pruner::new(
db.clone(),
Expand Down
6 changes: 3 additions & 3 deletions crates/interfaces/src/p2p/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::headers::client::HeadersRequest;
use crate::{consensus::ConsensusError, db};
use crate::{consensus::ConsensusError, provider::ProviderError};
use reth_network_api::ReputationChangeKind;
use reth_primitives::{
BlockHashOrNumber, BlockNumber, GotExpected, GotExpectedBoxed, Header, WithPeerId, B256,
Expand Down Expand Up @@ -177,9 +177,9 @@ pub enum DownloadError {
/// Error while executing the request.
#[error(transparent)]
RequestError(#[from] RequestError),
/// Error while reading data from database.
/// Provider error.
#[error(transparent)]
DatabaseError(#[from] db::DatabaseError),
Provider(#[from] ProviderError),
}

#[cfg(test)]
Expand Down
5 changes: 3 additions & 2 deletions crates/net/downloaders/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ description = "Implementations of various block downloaders"
# reth
reth-interfaces.workspace = true
reth-primitives.workspace = true
reth-db.workspace = true
reth-tasks.workspace = true
reth-provider.workspace = true

# async
futures.workspace = true
Expand All @@ -33,6 +33,7 @@ rayon.workspace = true
thiserror.workspace = true

# optional deps for the test-utils feature
reth-db = { workspace = true, optional = true }
alloy-rlp = { workspace = true, optional = true }
tempfile = { workspace = true, optional = true }
itertools = { workspace = true, optional = true }
Expand All @@ -50,4 +51,4 @@ itertools.workspace = true
tempfile.workspace = true

[features]
test-utils = ["dep:alloy-rlp", "dep:tempfile", "dep:itertools", "reth-interfaces/test-utils"]
test-utils = ["dep:alloy-rlp", "dep:tempfile", "dep:itertools", "reth-db/test-utils", "reth-interfaces/test-utils"]
Loading
Loading