Skip to content

Commit

Permalink
Merge pull request #15 from taikoxyz/rbuilder-fix
Browse files Browse the repository at this point in the history
Basic support for multiple L2s
  • Loading branch information
Brechtpd authored Oct 24, 2024
2 parents 036e3de + 12ce35e commit 45a5043
Show file tree
Hide file tree
Showing 23 changed files with 436 additions and 298 deletions.
4 changes: 3 additions & 1 deletion config-gwyneth-reth.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ reth_datadir = "/data/reth/execution-data/"
# We can have multiple, separated by comma
l2_reth_datadirs = ["/data/reth/gwyneth-167010"]

gwyneth_chain_ids = [167010, 167011]

coinbase_secret_key = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
relay_secret_key = "5eae315483f028b5cdd5d1090ff0c7618b18737ea9bf3c35047189db22835c48"
optimistic_relay_secret_key = "env:OPTIMISTIC_RELAY_SECRET_KEY"

# This shall be something like: "http://172.16.152.12:4000". To gather the correct IP, in (host machine) terminal we can query by:
# This shall be something like: "http://172.16.152.12:4000". To gather the correct IP, in (host machine) terminal we can query by:
# docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' CL_CONTAINER_HASH
# but it is auto-filled from now by the taiko reth's 'make install' process
cl_node_url = [""]
Expand Down
6 changes: 4 additions & 2 deletions crates/rbuilder/src/backtest/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
primitives::SimulatedOrder,
utils::clean_extradata,
};
use ahash::HashSet;
use ahash::{HashMap, HashSet};
use alloy_primitives::{Address, U256};
use reth::providers::ProviderFactory;
use reth_chainspec::ChainSpec;
Expand Down Expand Up @@ -86,8 +86,10 @@ pub fn backtest_prepare_ctx_for_block<DB: Database + Clone>(
block_data.winning_bid_trace.proposer_fee_recipient,
Some(builder_signer),
);
let mut provider_factories = HashMap::default();
provider_factories.insert(chain_spec.chain.id(), provider_factory.clone());
let (sim_orders, sim_errors) =
simulate_all_orders_with_sim_tree(provider_factory.clone(), &ctx, &orders, false)?;
simulate_all_orders_with_sim_tree(provider_factories, &ctx, &orders, false)?;
Ok(BacktestBlockInput {
ctx,
sim_orders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn sim_historical_block(
let txs = extract_onchain_block_txs(&onchain_block)?;

let suggested_fee_recipient = find_suggested_fee_recipient(&onchain_block, &txs);
let coinbase = onchain_block.header.miner;
let coinbase = ChainAddress(chain_spec.chain.id(), onchain_block.header.miner);

let ctx = BlockBuildingContext::from_onchain_block(
onchain_block,
Expand All @@ -50,7 +50,7 @@ pub fn sim_historical_block(
None,
);

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

Expand All @@ -62,8 +62,6 @@ pub fn sim_historical_block(
let mut cumulative_blob_gas_used = 0;
let mut written_slots: HashMap<SlotKey, Vec<B256>> = HashMap::default();

let coinbase = ChainAddress(chain_spec.chain.id(), coinbase);

for (idx, tx) in txs.into_iter().enumerate() {
let coinbase_balance_before = state.balance(coinbase)?;
let mut accumulator_tracer = AccumulatorSimulationTracer::default();
Expand Down
3 changes: 2 additions & 1 deletion crates/rbuilder/src/bin/debug-bench-machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use rbuilder::{
use reth::providers::BlockNumReader;
use reth_payload_builder::database::SyncCachedReads as CachedReads;
use reth_provider::StateProvider;
use revm_primitives::ChainAddress;
use std::{path::PathBuf, sync::Arc, time::Instant};
use tracing::{debug, info};

Expand Down Expand Up @@ -62,7 +63,7 @@ async fn main() -> eyre::Result<()> {
txs.len()
);

let coinbase = onchain_block.header.miner;
let coinbase = ChainAddress(chain_spec.chain.id(), onchain_block.header.miner);

let ctx = BlockBuildingContext::from_onchain_block(
onchain_block,
Expand Down
2 changes: 1 addition & 1 deletion crates/rbuilder/src/bin/dummy-builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl DummyBuildingAlgorithm {
&self,
orders: Vec<SimulatedOrder>,
provider_factory: HashMap<u64, ProviderFactory<DB>>,
ctx: &HashMap<u64, BlockBuildingContext>,
ctx: &BlockBuildingContext,
) -> eyre::Result<Box<dyn BlockBuildingHelper>> {
let mut block_building_helper = BlockBuildingHelperFromDB::new(
provider_factory.clone(),
Expand Down
Loading

0 comments on commit 45a5043

Please sign in to comment.