Skip to content

Commit

Permalink
minimize diff
Browse files Browse the repository at this point in the history
  • Loading branch information
Brechtpd committed Oct 11, 2024
1 parent a2e6ec3 commit 6ec8589
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 43 deletions.
4 changes: 2 additions & 2 deletions crates/rbuilder/src/backtest/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use alloy_primitives::{Address, U256};
use reth::providers::ProviderFactory;
use reth_chainspec::ChainSpec;
use reth_db::{database::Database, DatabaseEnv};
use reth_payload_builder::database::{CachedReads, SyncCachedReads};
use reth_payload_builder::database::SyncCachedReads as CachedReads;
use serde::{Deserialize, Serialize};
use std::sync::Arc;

Expand Down Expand Up @@ -151,7 +151,7 @@ pub fn backtest_simulate_block<ConfigType: LiveBuilderConfig>(
let simulated_total_gas = sim_orders.iter().map(|o| o.sim_value.gas_used).sum();
let mut builder_outputs = Vec::new();

let mut cached_reads = Some(SyncCachedReads::default());
let mut cached_reads = Some(CachedReads::default());
for building_algorithm_name in builders_names {
let input = BacktestSimulateBlockInput {
ctx: ctx.clone(),
Expand Down
6 changes: 2 additions & 4 deletions crates/rbuilder/src/bin/debug-bench-machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//! This only works when reth node is stopped and the chain moved forward form its synced state
//! It downloads block aftre the last one synced and re-executes all the txs in it.
use alloy_provider::Provider;
use ahash::HashMap;
use alloy_primitives::{B256, U256};
use clap::Parser;
use eyre::Context;
use itertools::Itertools;
Expand All @@ -13,7 +11,7 @@ use rbuilder::{
utils::{extract_onchain_block_txs, find_suggested_fee_recipient, http_provider},
};
use reth::providers::BlockNumReader;
use reth_payload_builder::database::{CachedReads, SyncCachedReads};
use reth_payload_builder::database::SyncCachedReads as CachedReads;
use reth_provider::StateProvider;
use std::{path::PathBuf, sync::Arc, time::Instant};
use tracing::{debug, info};
Expand Down Expand Up @@ -85,7 +83,7 @@ async fn main() -> eyre::Result<()> {

let mut build_times_ms = Vec::new();
let mut finalize_time_ms = Vec::new();
let mut cached_reads = Some(SyncCachedReads::default());
let mut cached_reads = Some(CachedReads::default());
for _ in 0..cli.iters {
let ctx = ctx.clone();
let txs = txs.clone();
Expand Down
16 changes: 8 additions & 8 deletions crates/rbuilder/src/building/builders/block_building_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ahash::HashMap;
use alloy_primitives::U256;
use reth::tasks::pool::BlockingTaskPool;
use reth_db::database::Database;
use reth_payload_builder::database::{CachedReads, SyncCachedReads};
use reth_payload_builder::database::SyncCachedReads as CachedReads;
use reth_primitives::format_ether;
use reth_provider::{BlockNumReader, ProviderFactory, StateProvider};
use revm_primitives::ChainAddress;
Expand Down Expand Up @@ -69,7 +69,7 @@ pub trait BlockBuildingHelper: Send + Sync {
) -> Result<FinalizeBlockResult, BlockBuildingHelperError>;

/// Useful if we want to give away this object but keep on building some other way.
fn clone_cached_reads(&self) -> SyncCachedReads;
fn clone_cached_reads(&self) -> CachedReads;

/// BuiltBlockTrace for current state.
fn built_block_trace(&self) -> &BuiltBlockTrace;
Expand All @@ -78,7 +78,7 @@ pub trait BlockBuildingHelper: Send + Sync {
fn building_context(&self) -> &BlockBuildingContext;

/// Updates the cached reads for the block state.
fn update_cached_reads(&mut self, cached_reads: SyncCachedReads);
fn update_cached_reads(&mut self, cached_reads: CachedReads);
}

/// Implementation of BlockBuildingHelper based on a ProviderFactory<DB>
Expand Down Expand Up @@ -142,7 +142,7 @@ impl BlockBuildingHelperError {
pub struct FinalizeBlockResult {
pub block: Block,
/// Since finalize_block eats the object we need the cached_reads in case we create a new
pub cached_reads: SyncCachedReads,
pub cached_reads: CachedReads,
}

impl<DB: Database + Clone + 'static> BlockBuildingHelperFromDB<DB> {
Expand All @@ -157,7 +157,7 @@ impl<DB: Database + Clone + 'static> BlockBuildingHelperFromDB<DB> {
root_hash_task_pool: BlockingTaskPool,
root_hash_config: RootHashConfig,
building_ctx: HashMap<u64, BlockBuildingContext>,
cached_reads: Option<SyncCachedReads>,
cached_reads: Option<CachedReads>,
builder_name: String,
discard_txs: bool,
enforce_sorting: Option<Sorting>,
Expand Down Expand Up @@ -365,7 +365,7 @@ impl<DB: Database + Clone + 'static> BlockBuildingHelper for BlockBuildingHelper

let sim_gas_used = self.partial_block.tracer.used_gas;
let mut blocks = HashMap::default();
let mut cached_reads = SyncCachedReads::default();
let mut cached_reads = CachedReads::default();
for (chain_id, provider_factory) in self.provider_factory.iter() {
// TODO Brecht: fix
if *chain_id == 160010 {
Expand Down Expand Up @@ -444,7 +444,7 @@ impl<DB: Database + Clone + 'static> BlockBuildingHelper for BlockBuildingHelper
})
}

fn clone_cached_reads(&self) -> SyncCachedReads {
fn clone_cached_reads(&self) -> CachedReads {
self.block_state.clone_cached_reads()
}

Expand All @@ -460,7 +460,7 @@ impl<DB: Database + Clone + 'static> BlockBuildingHelper for BlockBuildingHelper
Box::new(self.clone())
}

fn update_cached_reads(&mut self, cached_reads: SyncCachedReads) {
fn update_cached_reads(&mut self, cached_reads: CachedReads) {
self.block_state = self.block_state.clone().with_cached_reads(cached_reads);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
primitives::SimulatedOrder,
};
use alloy_primitives::U256;
use reth_payload_builder::database::{CachedReads, SyncCachedReads};
use reth_payload_builder::database::SyncCachedReads as CachedReads;
use reth_primitives::SealedBlock;
use time::OffsetDateTime;

Expand Down Expand Up @@ -85,12 +85,12 @@ impl BlockBuildingHelper for MockBlockBuildingHelper {

Ok(FinalizeBlockResult {
block,
cached_reads: SyncCachedReads::default(),
cached_reads: CachedReads::default(),
})
}

fn clone_cached_reads(&self) -> SyncCachedReads {
SyncCachedReads::default()
fn clone_cached_reads(&self) -> CachedReads {
CachedReads::default()
}

fn built_block_trace(&self) -> &BuiltBlockTrace {
Expand All @@ -101,7 +101,7 @@ impl BlockBuildingHelper for MockBlockBuildingHelper {
&self.block_building_context
}

fn update_cached_reads(&mut self, _cached_reads: SyncCachedReads) {
fn update_cached_reads(&mut self, _cached_reads: CachedReads) {
unimplemented!()
}
}
4 changes: 2 additions & 2 deletions crates/rbuilder/src/building/builders/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use reth::{
tasks::pool::BlockingTaskPool,
};
use reth_db::database::Database;
use reth_payload_builder::database::{CachedReads, SyncCachedReads};
use reth_payload_builder::database::SyncCachedReads as CachedReads;
use std::sync::Arc;
use tokio::sync::{broadcast, broadcast::error::TryRecvError};
use tokio_util::sync::CancellationToken;
Expand Down Expand Up @@ -230,7 +230,7 @@ pub struct BacktestSimulateBlockInput<'a, DB> {
pub sbundle_mergeabe_signers: Vec<Address>,
pub sim_orders: &'a Vec<SimulatedOrder>,
pub provider_factory: ProviderFactory<DB>,
pub cached_reads: Option<SyncCachedReads>,
pub cached_reads: Option<CachedReads>,
}

/// Handles error from block filling stage.
Expand Down
10 changes: 5 additions & 5 deletions crates/rbuilder/src/building/builders/ordering_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use tokio_util::sync::CancellationToken;

use crate::{roothash::RootHashConfig, utils::check_provider_factory_health};
use reth::tasks::pool::BlockingTaskPool;
use reth_payload_builder::database::{CachedReads, SyncCachedReads};
use reth_payload_builder::database::SyncCachedReads as CachedReads;
use serde::Deserialize;
use std::{os::unix::fs::lchown, time::{Duration, Instant}};
use tracing::{error, info_span, trace};
Expand Down Expand Up @@ -131,7 +131,7 @@ pub fn run_ordering_builder<DB: Database + Clone + 'static>(
pub fn backtest_simulate_block<DB: Database + Clone + 'static>(
ordering_config: OrderingBuilderConfig,
input: BacktestSimulateBlockInput<'_, DB>,
) -> eyre::Result<(Block, SyncCachedReads)> {
) -> eyre::Result<(Block, CachedReads)> {

let mut provider_factories = HashMap::default();
provider_factories.insert(input.ctx.chain_spec.chain.id(), input.provider_factory.clone());
Expand Down Expand Up @@ -186,7 +186,7 @@ pub struct OrderingBuilderContext<DB> {
root_hash_config: RootHashConfig,

// caches
cached_reads: Option<SyncCachedReads>,
cached_reads: Option<CachedReads>,

// scratchpad
failed_orders: HashSet<OrderId>,
Expand Down Expand Up @@ -215,14 +215,14 @@ impl<DB: Database + Clone + 'static> OrderingBuilderContext<DB> {
}
}

pub fn with_cached_reads(self, cached_reads: SyncCachedReads) -> Self {
pub fn with_cached_reads(self, cached_reads: CachedReads) -> Self {
Self {
cached_reads: Some(cached_reads),
..self
}
}

pub fn take_cached_reads(&mut self) -> Option<SyncCachedReads> {
pub fn take_cached_reads(&mut self) -> Option<CachedReads> {
self.cached_reads.take()
}

Expand Down
4 changes: 2 additions & 2 deletions crates/rbuilder/src/building/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use reth_evm::system_calls::{
};
use reth_evm_ethereum::{eip6110::parse_deposits_from_receipts, revm_spec, EthEvmConfig};
use reth_node_api::PayloadBuilderAttributes;
use reth_payload_builder::{database::{CachedReads, SyncCachedReads}, EthPayloadBuilderAttributes};
use reth_payload_builder::{database::SyncCachedReads as CachedReads, EthPayloadBuilderAttributes};
use revm::{
db::states::bundle_state::BundleRetention::{self, PlainState},
primitives::{BlobExcessGasAndPrice, BlockEnv, CfgEnvWithHandlerCfg, SpecId},
Expand Down Expand Up @@ -405,7 +405,7 @@ impl ExecutionError {

pub struct FinalizeResult {
pub sealed_block: SealedBlock,
pub cached_reads: SyncCachedReads,
pub cached_reads: CachedReads,
// sidecars for all txs in SealedBlock
pub txs_blob_sidecars: Vec<Arc<BlobTransactionSidecar>>,
}
Expand Down
14 changes: 7 additions & 7 deletions crates/rbuilder/src/building/order_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use alloy_primitives::{Address, B256, U256};

use reth::revm::database::{StateProviderDatabase, SyncStateProviderDatabase};
use reth_errors::ProviderError;
use reth_payload_builder::database::{CachedReads, SyncCachedReads};
use reth_payload_builder::database::SyncCachedReads as CachedReads;
use reth_primitives::{
constants::eip4844::{DATA_GAS_PER_BLOB, MAX_DATA_GAS_PER_BLOCK},
transaction::FillTxEnv,
Expand All @@ -36,7 +36,7 @@ use thiserror::Error;
#[derive(Clone)]
pub struct BlockState {
providers: HashMap<u64, Arc<dyn StateProvider>>,
cached_reads: SyncCachedReads,
cached_reads: CachedReads,
bundle_state: Option<BundleState>,
}

Expand All @@ -50,7 +50,7 @@ impl BlockState {
pub fn new_arc(providers: HashMap<u64, Arc<dyn StateProvider>>) -> Self {
Self {
providers,
cached_reads: SyncCachedReads::default(),
cached_reads: CachedReads::default(),
bundle_state: Some(BundleState::default()),
}
}
Expand All @@ -69,7 +69,7 @@ impl BlockState {
self.providers[&chain_id].clone()
}

pub fn with_cached_reads(mut self, cached_reads:SyncCachedReads) -> Self {
pub fn with_cached_reads(mut self, cached_reads:CachedReads) -> Self {
self.cached_reads = cached_reads;
self
}
Expand All @@ -79,11 +79,11 @@ impl BlockState {
self
}

pub fn into_parts(self) -> (SyncCachedReads, BundleState, HashMap<u64, Arc<dyn StateProvider>>) {
pub fn into_parts(self) -> (CachedReads, BundleState, HashMap<u64, Arc<dyn StateProvider>>) {
(self.cached_reads, self.bundle_state.unwrap(), self.providers)
}

pub fn clone_bundle_and_cache(&self) -> (SyncCachedReads, BundleState) {
pub fn clone_bundle_and_cache(&self) -> (CachedReads, BundleState) {
(
self.cached_reads.clone(),
self.bundle_state.clone().unwrap(),
Expand Down Expand Up @@ -129,7 +129,7 @@ impl BlockState {
.unwrap_or_else(|| KECCAK_EMPTY))
}

pub fn clone_cached_reads(&self) -> SyncCachedReads {
pub fn clone_cached_reads(&self) -> CachedReads {
self.cached_reads.clone()
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/rbuilder/src/building/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rand::seq::SliceRandom;
use reth::providers::ProviderFactory;
use reth_db::database::Database;
use reth_errors::ProviderError;
use reth_payload_builder::database::{CachedReads, SyncCachedReads};
use reth_payload_builder::database::SyncCachedReads as CachedReads;
use reth_provider::StateProvider;
use std::{
cmp::{max, min, Ordering},
Expand Down Expand Up @@ -338,7 +338,7 @@ pub fn simulate_all_orders_with_sim_tree<DB: Database + Clone>(
ctx.chain_spec.chain.id(),
Arc::<dyn StateProvider>::from(factory.history_by_block_hash(ctx.attributes.parent)?),
);
let mut cache_reads = Some(SyncCachedReads::default());
let mut cache_reads = Some(CachedReads::default());
loop {
// mix new orders into the sim_tree
if randomize_insertion && !orders.is_empty() {
Expand Down
4 changes: 2 additions & 2 deletions crates/rbuilder/src/live_builder/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{path::PathBuf, sync::Arc};

use clap::Parser;
use reth_db::DatabaseEnv;
use reth_payload_builder::database::{CachedReads, SyncCachedReads};
use reth_payload_builder::database::SyncCachedReads as CachedReads;
use tokio::signal::ctrl_c;
use tokio_util::sync::CancellationToken;

Expand Down Expand Up @@ -52,7 +52,7 @@ pub trait LiveBuilderConfig: std::fmt::Debug + serde::de::DeserializeOwned {
&self,
building_algorithm_name: &str,
input: BacktestSimulateBlockInput<'_, Arc<DatabaseEnv>>,
) -> eyre::Result<(Block, SyncCachedReads)>;
) -> eyre::Result<(Block, CachedReads)>;
}

/// print_version_info func that will be called on command Cli::Version
Expand Down
4 changes: 2 additions & 2 deletions crates/rbuilder/src/live_builder/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use eyre::Context;
use reth::tasks::pool::BlockingTaskPool;
use reth_chainspec::{Chain, ChainSpec, NamedChain};
use reth_db::DatabaseEnv;
use reth_payload_builder::database::{CachedReads, SyncCachedReads};
use reth_payload_builder::database::SyncCachedReads as CachedReads;
use reth_primitives::StaticFileSegment;
use reth_provider::StaticFileProviderFactory;
use serde::Deserialize;
Expand Down Expand Up @@ -364,7 +364,7 @@ impl LiveBuilderConfig for Config {
&self,
building_algorithm_name: &str,
input: BacktestSimulateBlockInput<'_, Arc<DatabaseEnv>>,
) -> eyre::Result<(Block, SyncCachedReads)> {
) -> eyre::Result<(Block, CachedReads)> {
let builder_cfg = self.builder(building_algorithm_name)?;
match builder_cfg.builder {
SpecificBuilderConfig::OrderingBuilder(config) => {
Expand Down
4 changes: 2 additions & 2 deletions crates/rbuilder/src/live_builder/simulation/sim_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
};
use ahash::HashMap;
use reth_db::database::Database;
use reth_payload_builder::database::{CachedReads, SyncCachedReads};
use reth_payload_builder::database::SyncCachedReads as CachedReads;
use std::{
sync::{Arc, Mutex},
thread::sleep,
Expand Down Expand Up @@ -59,7 +59,7 @@ pub fn run_sim_worker<DB: Database + Clone + Send + 'static>(
}
};

let mut cached_reads = SyncCachedReads::default();
let mut cached_reads = CachedReads::default();
let mut last_sim_finished = Instant::now();
while let Ok(task) = current_sim_context.requests.recv() {
let sim_thread_wait_time = last_sim_finished.elapsed();
Expand Down

0 comments on commit 6ec8589

Please sign in to comment.