Skip to content

Commit

Permalink
New parallel builder config.
Browse files Browse the repository at this point in the history
Changes on LiveBuilderConfig.
  • Loading branch information
ZanCorDX committed Nov 8, 2024
1 parent 8cf6b36 commit f7dcf06
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 32 deletions.
28 changes: 22 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ http = "0.2.9"
hyper = "0.14"
futures-util = "0.3"

metrics_macros = { git = "https://github.com/flashbots/rbuilder.git", rev = "d96e7215483bac0ab145459f4ddaa811d99459d6"}
metrics_macros = { git = "https://github.com/flashbots/rbuilder.git", rev = "5d152e8edc3c2027263c40b7661323a468a5f01b"}

rbuilder = { git = "https://github.com/flashbots/rbuilder.git", rev = "d96e7215483bac0ab145459f4ddaa811d99459d6"}
rbuilder = { git = "https://github.com/flashbots/rbuilder.git", rev = "5d152e8edc3c2027263c40b7661323a468a5f01b"}

[build-dependencies]
built = { version = "0.7.1", features = ["git2", "chrono"] }
Expand Down
7 changes: 3 additions & 4 deletions config-live-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ key_registration_url = "http://127.0.0.1:8090"
ignore_cancellable_orders = true

sbundle_mergeabe_signers = []
live_builders = ["mp-ordering", "mgp-ordering", "merging"]
live_builders = ["mp-ordering", "mgp-ordering", "parallel"]

top_bid_ws_url = "env:TOP_BID_WS_URL"
top_bid_ws_basic_auth = "env:TOP_BID_WS_BASIC_AUTH"
Expand Down Expand Up @@ -63,8 +63,7 @@ failed_order_retries = 1
drop_failed_orders = true

[[builders]]
name = "merging"
algo = "merging-builder"
name = "parallel"
algo = "parallel-builder"
discard_txs = true
num_threads = 5
merge_wait_time_ms = 100
50 changes: 30 additions & 20 deletions src/flashbots_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use alloy_signer_local::PrivateKeySigner;
use eyre::Context;
use http::StatusCode;
use jsonrpsee::RpcModule;
use rbuilder::building::builders::merging_builder::merging_build_backtest;
use rbuilder::building::builders::parallel_builder::parallel_build_backtest;
use rbuilder::building::builders::UnfinishedBlockBuildingSinkFactory;
use rbuilder::live_builder::base_config::EnvOrValue;
use rbuilder::live_builder::block_output::bid_observer::{BidObserver, NullBidObserver};
Expand All @@ -30,8 +30,8 @@ use rbuilder::{
utils::build_info::Version,
};
use reth::payload::database::CachedReads;
use reth::providers::ProviderFactory;
use reth_db::DatabaseEnv;
use reth::providers::{DatabaseProviderFactory, HeaderProvider, StateProviderFactory};
use reth_db::Database;
use serde::Deserialize;
use serde_with::serde_as;
use tokio_util::sync::CancellationToken;
Expand Down Expand Up @@ -118,17 +118,17 @@ impl LiveBuilderConfig for FlashbotsConfig {
&self.base_config
}

async fn create_builder(
async fn new_builder<P, DB>(
&self,
provider: P,
cancellation_token: CancellationToken,
) -> eyre::Result<LiveBuilder<Arc<DatabaseEnv>, MevBoostSlotDataGenerator>> {
let provider_factory = self.base_config.provider_factory()?;

) -> eyre::Result<LiveBuilder<P, DB, MevBoostSlotDataGenerator>>
where
DB: Database + Clone + 'static,
P: DatabaseProviderFactory<DB> + StateProviderFactory + HeaderProvider + Clone + 'static,
{
let (sink_factory, relays, bidding_service_win_control) = self
.create_sink_factory_and_relays(
provider_factory.provider_factory_unchecked(),
cancellation_token.clone(),
)
.create_sink_factory_and_relays(provider.clone(), cancellation_token.clone())
.await?;

let payload_event = MevBoostSlotDataGenerator::new(
Expand All @@ -144,7 +144,7 @@ impl LiveBuilderConfig for FlashbotsConfig {
cancellation_token.clone(),
sink_factory,
payload_event,
provider_factory,
provider,
)
.await?;

Expand All @@ -170,19 +170,25 @@ impl LiveBuilderConfig for FlashbotsConfig {
}

/// @Pending fix this ugly copy/paste
fn build_backtest_block(
fn build_backtest_block<P, DB>(
&self,
building_algorithm_name: &str,
input: BacktestSimulateBlockInput<'_, Arc<DatabaseEnv>>,
) -> eyre::Result<(Block, CachedReads)> {
input: BacktestSimulateBlockInput<'_, P>,
) -> eyre::Result<(Block, CachedReads)>
where
DB: Database + Clone + 'static,
P: DatabaseProviderFactory<DB> + StateProviderFactory + Clone + 'static,
{
let builder_cfg = self.builder(building_algorithm_name)?;
match builder_cfg.builder {
SpecificBuilderConfig::OrderingBuilder(config) => {
rbuilder::building::builders::ordering_builder::backtest_simulate_block(
config, input,
)
}
SpecificBuilderConfig::MergingBuilder(config) => merging_build_backtest(input, config),
SpecificBuilderConfig::ParallelBuilder(config) => {
parallel_build_backtest(input, config)
}
}
}
}
Expand Down Expand Up @@ -282,15 +288,19 @@ impl FlashbotsConfig {
/// BlockSealingBidderFactory: performs sealing/bidding. Sends bids to the RelaySubmitSinkFactory
/// UnfinishedBlockBuildingSinkFactoryWrapper: sends all the tbv info via redis and forwards to BlockSealingBidderFactory
#[allow(clippy::type_complexity)]
async fn create_sink_factory_and_relays(
async fn create_sink_factory_and_relays<P, DB>(
&self,
provider_factory: ProviderFactory<Arc<DatabaseEnv>>,
provider: P,
cancellation_token: CancellationToken,
) -> eyre::Result<(
Box<dyn UnfinishedBlockBuildingSinkFactory>,
Vec<MevBoostRelay>,
Arc<dyn BiddingServiceWinControl>,
)> {
)>
where
DB: Database + Clone + 'static,
P: DatabaseProviderFactory<DB> + StateProviderFactory + HeaderProvider + Clone + 'static,
{
let block_processor_key = if let Some(key_registration_url) = &self.key_registration_url {
if self.blocks_processor_url.is_none() {
return Self::bail_blocks_processor_url_not_set();
Expand All @@ -307,7 +317,7 @@ impl FlashbotsConfig {

// BlockSealingBidderFactory
let (wallet_balance_watcher, wallet_history) = WalletBalanceWatcher::new(
provider_factory,
provider,
self.base_config.coinbase_signer()?.address,
WALLET_INIT_HISTORY_SIZE,
)?;
Expand Down

0 comments on commit f7dcf06

Please sign in to comment.