Skip to content

Commit

Permalink
Merge pull request #8 from taikoxyz/gwyneth-block-building
Browse files Browse the repository at this point in the history
Block building
  • Loading branch information
Brechtpd authored Oct 5, 2024
2 parents 8d62793 + 84006e9 commit 3e38a94
Show file tree
Hide file tree
Showing 35 changed files with 832 additions and 280 deletions.
4 changes: 4 additions & 0 deletions config-gwyneth-reth.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ sbundle_mergeabe_signers = []
# slot_delta_to_start_submits_ms = -5000
live_builders = ["mp-ordering"]

# Currently the l1_rpc_url, l1_proposer_pk and l1_smart_contract_address are static. If we change smth on the smart contract "system" it might changes (depending on the deployment).
[[relays]]
name = "gwyneth"
url = "http://0xac6e77dfe25ecd6110b8e780608cce0dab71fdd5ebea22a16c0205200f2f8e2e3ad3b71d3499c54ad14d6c21b41a37ae@localhost:5555"
priority = 0
use_ssz_for_submit = false
use_gzip_for_submit = false
l1_rpc_url = "http://localhost:8545"
l1_proposer_pk = "39725efee3fb28614de3bacaffe4cc4bd8c436257e2c8bb887c4b5c4be45e76d"
l1_smart_contract_address = "0x9fCF7D13d10dEdF17d0f24C62f0cf4ED462f65b7"

[[builders]]
name = "mgp-ordering"
Expand Down
4 changes: 4 additions & 0 deletions crates/rbuilder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ build = "build.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
alloy-sol-types = { version = "0.7.2", default-features = false }
alloy-contract = { version = "0.1", default-features = false }
ethers = { version = "2.0", features = ["ws", "rustls", "ipc"] }
web3 = "0.19.0"
ethers-providers = { version = "2.0", features = ["ipc"] }
rlp = "0.6.1"
tokio = "1.38.0"
serde = "1.0.188"
serde_json = "1.0.105"
Expand Down
1 change: 1 addition & 0 deletions crates/rbuilder/src/backtest/fetch/mev_boost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl Default for PayloadDeliveredFetcher {
use_gzip_for_submit: false, //Don't use submit so don't care
optimistic: false,
submission_rate_limiter: None,
block_proposer: None,
}
})
.collect::<Vec<_>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn sim_historical_block(

let ctx = BlockBuildingContext::from_onchain_block(
onchain_block,
chain_spec,
chain_spec.clone(),
None,
HashSet::default(),
coinbase,
Expand All @@ -47,7 +47,7 @@ pub fn sim_historical_block(

let state_provider = provider_factory.history_by_block_hash(ctx.attributes.parent)?;
let mut partial_block = PartialBlock::new(true, None);
let mut state = BlockState::new(state_provider);
let mut state = BlockState::new(state_provider, chain_spec.chain().id());

partial_block
.pre_block_call(&ctx, &mut state)
Expand Down
5 changes: 3 additions & 2 deletions crates/rbuilder/src/bin/debug-bench-machine.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! App to benchmark/test the tx block execution.
//! It loads the last landed block and re-executes all the txs in it.
use ahash::HashMap;
use alloy_primitives::{B256, U256};
use clap::Parser;
use itertools::Itertools;
Expand Down Expand Up @@ -115,7 +116,7 @@ async fn main() -> eyre::Result<()> {
for _ in 0..cli.iters {
let mut partial_block = PartialBlock::new(true, None);
let mut block_state =
BlockState::new_arc(state_provider).with_cached_reads(cached_reads.unwrap_or_default());
BlockState::new_arc_single(state_provider, chain.chain.id()).with_cached_reads(cached_reads.unwrap_or_default());
let build_time = Instant::now();
partial_block.pre_block_call(&ctx, &mut block_state)?;
for order in &sim_orders {
Expand All @@ -137,7 +138,7 @@ async fn main() -> eyre::Result<()> {

build_times_mus.push(build_time.as_micros());
finalize_time_mus.push(finalize_time.as_micros());
state_provider = block_state.into_provider();
state_provider = block_state.into_provider(chain.chain.id());
}
report_time_data("build", &build_times_mus);
report_time_data("finalize", &finalize_time_mus);
Expand Down
19 changes: 8 additions & 11 deletions crates/rbuilder/src/bin/dummy-builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! This is NOT intended to be run in production so it has no nice configuration, poor error checking and some hardcoded values.
use std::{path::PathBuf, sync::Arc, thread::sleep, time::Duration};

use ahash::HashMap;
use jsonrpsee::RpcModule;
use rbuilder::{
beacon_api_client::Client,
Expand All @@ -20,15 +21,10 @@ use rbuilder::{
base_config::{
DEFAULT_EL_NODE_IPC_PATH, DEFAULT_ERROR_STORAGE_PATH, DEFAULT_INCOMING_BUNDLES_PORT,
DEFAULT_IP, DEFAULT_RETH_DB_PATH,
},
config::create_provider_factory,
order_input::{
}, config::create_provider_factory, layer2_info::Layer2Info, order_input::{
OrderInputConfig, DEFAULT_INPUT_CHANNEL_BUFFER_SIZE, DEFAULT_RESULTS_CHANNEL_TIMEOUT,
DEFAULT_SERVE_MAX_CONNECTIONS,
},
payload_events::{MevBoostSlotData, MevBoostSlotDataGenerator},
simulation::SimulatedOrderCommand,
LiveBuilder,
}, payload_events::{MevBoostSlotData, MevBoostSlotDataGenerator}, simulation::SimulatedOrderCommand, LiveBuilder
},
primitives::{
mev_boost::{MevBoostRelay, RelayConfig},
Expand Down Expand Up @@ -99,7 +95,7 @@ async fn main() -> eyre::Result<()> {
extra_rpc: RpcModule::new(()),
sink_factory: Box::new(TraceBlockSinkFactory {}),
builders: vec![Arc::new(DummyBuildingAlgorithm::new(10))],
layer2_info: None,
layer2_info: Layer2Info::new(vec![], HashMap::default()).await?,
};

let ctrlc = tokio::spawn(async move {
Expand Down Expand Up @@ -133,6 +129,7 @@ struct TracingBlockSink {}

impl UnfinishedBlockBuildingSink for TracingBlockSink {
fn new_block(&self, block: Box<dyn BlockBuildingHelper>) {
println!("UnfinishedBlockBuildingSink::new_block");
info!(
order_count =? block.built_block_trace().included_orders.len(),
"Block generated. Throwing it away!"
Expand Down Expand Up @@ -194,8 +191,8 @@ impl DummyBuildingAlgorithm {
fn build_block<DB: Database + Clone + 'static>(
&self,
orders: Vec<SimulatedOrder>,
provider_factory: ProviderFactory<DB>,
ctx: &BlockBuildingContext,
provider_factory: HashMap<u64, ProviderFactory<DB>>,
ctx: &HashMap<u64, BlockBuildingContext>,
) -> eyre::Result<Box<dyn BlockBuildingHelper>> {
let mut block_building_helper = BlockBuildingHelperFromDB::new(
provider_factory.clone(),
Expand Down Expand Up @@ -225,7 +222,7 @@ impl<DB: Database + Clone + 'static> BlockBuildingAlgorithm<DB> for DummyBuildin
fn build_blocks(&self, input: BlockBuildingAlgorithmInput<DB>) {
if let Some(orders) = self.wait_for_orders(&input.cancel, input.input) {
let block = self
.build_block(orders, input.provider_factory, &input.ctx)
.build_block(orders, input.provider_factory.clone(), &input.ctx)
.unwrap();
input.sink.new_block(block);
}
Expand Down
Loading

0 comments on commit 3e38a94

Please sign in to comment.