Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Keszey Dániel authored and Keszey Dániel committed Nov 7, 2024
1 parent f0db504 commit 92e0d5b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
39 changes: 20 additions & 19 deletions crates/rbuilder/src/live_builder/building/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use reth_provider::{DatabaseProviderFactory, StateProviderFactory};
use reth_provider::ProviderFactory;
use tokio::sync::{broadcast, mpsc};
use tokio_util::sync::CancellationToken;
use tracing::{debug, trace};
use tracing::{error, trace};

use super::{
order_input::{
Expand All @@ -40,7 +40,7 @@ pub struct BlockBuildingPool<P, DB> {
impl<P, DB> BlockBuildingPool<P, DB>
where
DB: Database + Clone + 'static,
P: DatabaseProviderFactory<DB> + StateProviderFactory + Clone + ProviderFactoryReopener<DB> + 'static,
P: DatabaseProviderFactory<DB> + StateProviderFactory + Clone + 'static,
{
pub fn new(
provider_factory: HashMap<u64, P>,
Expand Down Expand Up @@ -113,24 +113,26 @@ where
// Brecht: start building
let builder_sink = self.sink_factory.create_sink(slot_data, cancel.clone());
let (broadcast_input, _) = broadcast::channel(10_000);

let provider_factories: HashMap<u64, ProviderFactory<DB>> = self
.provider_factory.iter().map(|(chain_id, provider_factory)| {
let block_number = ctx.chains[chain_id].block_env.number.to::<u64>();
match provider_factory.check_consistency_and_reopen_if_needed(block_number)
{
Ok(provider_factory) => (*chain_id, provider_factory),
Err(err) => {
panic!("Error while reopening provider factory");
}

// Get provider factories for each chain
let provider_factories: HashMap<u64, P> = self
.provider_factory
.iter()
.filter_map(|(chain_id, provider_factory)| {
let block_number = ctx.chains[chain_id].block_env.number.to::<u64>();
match provider_factory.check_consistency_and_reopen_if_needed(block_number) {
Ok(_) => Some((*chain_id, provider_factory.clone())), // Keep original provider type
Err(err) => {
error!(?err, "Error while reopening provider factory");
None
}
}).collect();
}
})
.collect();

for builder in self.builders.iter() {
//let builder_name = builder.name();
//debug!(block = block_number, builder_name, "Spawning builder job");
let input = BlockBuildingAlgorithmInput::<DB> {
provider_factory: provider_factories.clone(),
let input = BlockBuildingAlgorithmInput {
provider_factory: provider_factories.clone(), // Now using the correct type P
ctx: ctx.clone(),
input: broadcast_input.subscribe(),
sink: builder_sink.clone(),
Expand All @@ -139,7 +141,6 @@ where
let builder = builder.clone();
tokio::task::spawn_blocking(move || {
builder.build_blocks(input);
//debug!(block = block_number, builder_name, "Stopped builder job");
});
}

Expand All @@ -155,7 +156,7 @@ where
tokio::task::spawn_blocking(move || {
run_trie_prefetcher(
chain_ctx.chains[&chain_id].attributes.parent,
chain_ctx.chains[&chain_id].shared_sparse_mpt_cache,
chain_ctx.chains[&chain_id].shared_sparse_mpt_cache.clone(),
provider,
chain_input,
chain_cancel,
Expand Down
6 changes: 3 additions & 3 deletions crates/rbuilder/src/live_builder/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl LiveBuilderConfig for Config {
}
async fn new_builder<P, DB>(
&self,
provider: P,
provider_factory: P,
cancellation_token: tokio_util::sync::CancellationToken,
) -> eyre::Result<super::LiveBuilder<P, DB, MevBoostSlotDataGenerator>>
where
Expand All @@ -305,7 +305,7 @@ impl LiveBuilderConfig for Config {
)?;

let (wallet_balance_watcher, wallet_history) = WalletBalanceWatcher::new(
provider_factory.provider_factory_unchecked(),
provider_factory,
self.base_config.coinbase_signer()?.address.1,
WALLET_INIT_HISTORY_SIZE,
)?;
Expand Down Expand Up @@ -333,7 +333,7 @@ impl LiveBuilderConfig for Config {
sink_factory,
payload_event,
self.base_config.gwyneth_chain_ids.clone(),
provider_factory,
provider_factory.clone(),
)
.await?;
let root_hash_config = self.base_config.live_root_hash_config()?;
Expand Down
3 changes: 0 additions & 3 deletions crates/rbuilder/src/utils/provider_factory_reopen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ pub struct ProviderFactoryReopener<DB> {
/// Patch to disable checking on test mode. Is ugly but ProviderFactoryReopener should die shortly (5/24/2024).
testing_mode: bool,
}
pub trait ProviderFactoryReopener<DB> {
fn check_consistency_and_reopen_if_needed(&self, block_number: u64) -> eyre::Result<ProviderFactory<DB>>;
}

impl<DB: Database + Clone> ProviderFactoryReopener<DB> {
pub fn new(db: DB, chain_spec: Arc<ChainSpec>, static_files_path: PathBuf) -> RethResult<Self> {
Expand Down

0 comments on commit 92e0d5b

Please sign in to comment.