Skip to content

Commit

Permalink
Merge pull request #22 from taikoxyz/disable-testing-mode
Browse files Browse the repository at this point in the history
misc fixes and improvements
  • Loading branch information
Brechtpd authored Jan 28, 2025
2 parents 073fe2b + a1f43d2 commit cc414f8
Show file tree
Hide file tree
Showing 22 changed files with 740 additions and 282 deletions.
313 changes: 203 additions & 110 deletions Cargo.lock

Large diffs are not rendered by default.

50 changes: 26 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ reth-provider = { git = "https://github.com/paradigmxyz/reth", tag = "v1.0.6", f
reth-chainspec = { git = "https://github.com/paradigmxyz/reth", tag = "v1.0.6" }
reth-evm = { git = "https://github.com/paradigmxyz/reth", tag = "v1.0.6" }
reth-evm-ethereum = { git = "https://github.com/paradigmxyz/reth", tag = "v1.0.6" }
reth-stages = { git = "https://github.com/paradigmxyz/reth", tag = "v1.0.6" }

# version is copied from reth "v1.0.6" dependencies
revm = { version = "14.0.0", features = [
Expand Down Expand Up @@ -85,32 +86,33 @@ bincode = "1.3"
# revm-primitives = { git = "https://github.com/taikoxyz/revm.git", branch = "v43-gwyneth" }
# revm-interpreter = { git = "https://github.com/taikoxyz/revm.git", branch = "v43-gwyneth" }
# revm-precompile = { git = "https://github.com/taikoxyz/revm.git", branch = "v43-gwyneth" }
revm = { git = "https://github.com/taikoxyz/revm.git", branch = "changeset" }
revm-primitives = { git = "https://github.com/taikoxyz/revm.git", branch = "changeset" }
revm-interpreter = { git = "https://github.com/taikoxyz/revm.git", branch = "changeset" }
revm-precompile = { git = "https://github.com/taikoxyz/revm.git", branch = "changeset" }
revm-inspectors = { git = "https://github.com/taikoxyz/revm-inspectors.git", branch = "main-rbuilder" }
revm = { git = "https://github.com/taikoxyz/revm.git", branch = "v43-gwyneth" }
revm-primitives = { git = "https://github.com/taikoxyz/revm.git", branch = "v43-gwyneth" }
revm-interpreter = { git = "https://github.com/taikoxyz/revm.git", branch = "v43-gwyneth" }
revm-precompile = { git = "https://github.com/taikoxyz/revm.git", branch = "v43-gwyneth" }
revm-inspectors = { git = "https://github.com/taikoxyz/revm-inspectors.git", branch = "v0.7.4-gwyneth" }

[patch."https://github.com/paradigmxyz/reth"]
reth = { git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth-db = {git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth-db-common = { git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth-errors = { git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth-libmdbx = { git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth-payload-builder = { git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth-node-api = { git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth-trie = { git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth-trie-parallel = { git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth-basic-payload-builder = { git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth-node-core = { git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth-primitives = { git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth-provider = { git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth-chainspec = { git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth-evm = { git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth-evm-ethereum = { git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth-db-api = { git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth-execution-errors = { git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth-trie-db = { git = "https://github.com/taikoxyz/gwyneth", branch = "changeset" }
reth = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-db = {git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-db-common = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-errors = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-libmdbx = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-payload-builder = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-node-api = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-trie = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-trie-parallel = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-basic-payload-builder = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-node-core = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-primitives = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-provider = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-chainspec = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-evm = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-evm-ethereum = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-db-api = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-execution-errors = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-trie-db = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }
reth-stages = { git = "https://github.com/taikoxyz/gwyneth", branch = "gwyneth" }

#reth = { path = "../../revm-dani/gwyneth/bin/reth" }
#reth-db = { path = "../../revm-dani/gwyneth/crates/storage/db" }
Expand Down
2 changes: 2 additions & 0 deletions crates/rbuilder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ reth-provider.workspace = true
reth-chainspec.workspace = true
reth-evm.workspace = true
reth-evm-ethereum.workspace = true
reth-stages.workspace = true
revm.workspace = true
revm-primitives.workspace = true
revm-inspectors.workspace = true
Expand Down Expand Up @@ -131,6 +132,7 @@ derivative = "2.2.0"
mockall = "0.12.1"
shellexpand = "3.1.0"
async-trait = "0.1.80"
parking_lot = "0.12.3"

eth-sparse-mpt = { git = "https://github.com/flashbots/eth-sparse-mpt", rev = "664759b" }

Expand Down
24 changes: 16 additions & 8 deletions crates/rbuilder/src/building/builders/block_building_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
},
primitives::SimulatedOrder,
roothash::RootHashConfig,
telemetry,
telemetry, utils::check_provider_factory_health,
};

use super::Block;
Expand Down Expand Up @@ -122,6 +122,8 @@ pub enum BlockBuildingHelperError {
FinalizeError(#[from] FinalizeError),
#[error("Payout tx not allowed for block")]
PayoutTxNotAllowed,
#[error("Historical block error")]
HistoricalBlockError,
}

impl BlockBuildingHelperError {
Expand Down Expand Up @@ -168,6 +170,9 @@ impl<DB: Database + Clone + 'static> BlockBuildingHelperFromDB<DB> {
// @Maybe an issue - we have 2 db txs here (one for hash and one for finalize)
let mut state_providers: HashMap<u64, Arc<dyn StateProvider>> = HashMap::default();
for (chain_id, provider_factory) in provider_factory.iter() {
//let last_committed_block = building_ctx.chains[chain_id].block() - 1;
//check_provider_factory_health(last_committed_block, provider_factory).map_err(|_| BlockBuildingHelperError::HistoricalBlockError)?;

state_providers.insert(
*chain_id,
provider_factory.history_by_block_hash(building_ctx.chains[chain_id].attributes.parent)?.into(),
Expand Down Expand Up @@ -284,9 +289,9 @@ impl<DB: Database + Clone + 'static> BlockBuildingHelperFromDB<DB> {
let bid_value = U256::from(self.partial_block.gas_used);
let true_value = U256::from(self.partial_block.gas_used);

if self.partial_block.gas_used > 0 {
println!("gas used: {:?}", self.partial_block.gas_used);
}
// if self.partial_block.gas_used > 0 {
// println!("gas used: {:?}", self.partial_block.gas_used);
// }
// Since some extra money might arrived directly the suggested_fee_recipient (when suggested_fee_recipient != coinbase)
// we check the fee_recipient delta and make our bid include that! This is supposed to be what the relay will check.
let fee_recipient_balance_after = self
Expand All @@ -298,7 +303,7 @@ impl<DB: Database + Clone + 'static> BlockBuildingHelperFromDB<DB> {
self.built_block_trace.bid_value = max(bid_value, fee_recipient_balance_diff);
self.built_block_trace.true_bid_value = true_value;

self.built_block_trace.bid_value = U256::from(self.partial_block.gas_used);
self.built_block_trace.bid_value = U256::from(self.building_context().block() * 30000000 + self.partial_block.gas_used);
self.built_block_trace.true_bid_value = self.built_block_trace.bid_value;

Ok(())
Expand All @@ -314,7 +319,7 @@ impl<DB: Database + Clone + 'static> BlockBuildingHelper for BlockBuildingHelper
let result =
self.partial_block
.commit_order(order, &self.building_ctx, &mut self.block_state);
println!("commit order: {:?}", order);
//println!("commit order: {:?}", order);
match result {
Ok(ok_result) => match ok_result {
Ok(res) => {
Expand Down Expand Up @@ -371,9 +376,11 @@ impl<DB: Database + Clone + 'static> BlockBuildingHelper for BlockBuildingHelper

let provider_factory = &self.provider_factory[&self.building_ctx.parent_chain_id];

let body = self.partial_block.executed_tx.iter().cloned().map(|t| t.tx.into()).collect();

let sim_gas_used = self.partial_block.tracer.used_gas;
let block_number = self.building_context().block();
let finalized_block = match self.partial_block.clone().finalize(
let finalized_block = match self.partial_block.finalize(
&mut self.block_state,
&self.building_ctx,
self.provider_factory.clone(),
Expand All @@ -390,6 +397,7 @@ impl<DB: Database + Clone + 'static> BlockBuildingHelper for BlockBuildingHelper
block_number,
last_block_number, "Can't build on this head, cancelling slot"
);
println!("Err: {:?}", err);
self.cancel_on_fatal_error.cancel();
}
return Err(BlockBuildingHelperError::FinalizeError(err));
Expand All @@ -415,7 +423,7 @@ impl<DB: Database + Clone + 'static> BlockBuildingHelper for BlockBuildingHelper
builder_name: self.builder_name.clone(),
};

block.sealed_block.body = self.partial_block.executed_tx.into_iter().map(|t| t.tx.into()).collect();
block.sealed_block.body = body;

Ok(FinalizeBlockResult {
block,
Expand Down
16 changes: 8 additions & 8 deletions crates/rbuilder/src/building/builders/ordering_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ pub fn run_ordering_builder<DB: Database + Clone + 'static>(
input.sink.new_block(block);
}
Err(err) => {
if !handle_building_error(err) {
break 'building;
}
println!("Error while building block: {:?}", err);
// if !handle_building_error(err) {
// break 'building;
// }
}
}
if config.drop_failed_orders {
Expand Down Expand Up @@ -257,8 +258,7 @@ impl<DB: Database + Clone + 'static> OrderingBuilderContext<DB> {

// Create a new ctx to remove builder_signer if necessary
let new_ctx = self.ctx.clone();
for (chain_id, provider_factory) in self.provider_factory.iter() {
check_provider_factory_health(self.ctx.chains[chain_id].block(), provider_factory)?;
for (chain_id, _) in self.provider_factory.iter() {
if use_suggested_fee_recipient_as_coinbase {
self.ctx.chains.get_mut(chain_id).unwrap().modify_use_suggested_fee_recipient_as_coinbase();
}
Expand Down Expand Up @@ -291,9 +291,9 @@ impl<DB: Database + Clone + 'static> OrderingBuilderContext<DB> {
mut block_orders: BlockOrders,
build_start: Instant,
) -> eyre::Result<()> {
if block_orders.get_all_orders().len() > 0 {
println!("fill_orders: {:?}", block_orders);
}
// if block_orders.get_all_orders().len() > 0 {
// println!("fill_orders: {:?}", block_orders);
// }
let mut order_attempts: HashMap<OrderId, usize> = HashMap::default();
// @Perf when gas left is too low we should break.
while let Some(sim_order) = block_orders.pop_order() {
Expand Down
27 changes: 16 additions & 11 deletions crates/rbuilder/src/building/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use revm::{
primitives::{BlobExcessGasAndPrice, BlockEnv, CfgEnvWithHandlerCfg, SpecId}, TransitionState,
};
use serde::Deserialize;
use std::{hash::Hash, str::FromStr, sync::Arc};
use std::{hash::Hash, str::FromStr, sync::Arc, thread::sleep, time::Duration};
use thiserror::Error;
use time::OffsetDateTime;

Expand Down Expand Up @@ -551,13 +551,13 @@ impl<Tracer: SimulationTracer> PartialBlock<Tracer> {
ctx: &BlockBuildingContext,
state: &mut BlockState,
) -> Result<Result<ExecutionResult, ExecutionError>, CriticalCommitOrderError> {
println!("commit_order: {:?}", order.order);
if ctx.builder_signer.is_none() && !order.sim_value.paid_kickbacks.is_empty() {
// Return here to avoid wasting time on a call to fork.commit_order that 99% will fail
return Ok(Err(ExecutionError::OrderError(OrderErr::Bundle(
BundleErr::NoSigner,
))));
}
// println!("commit_order: {:?}", order.order);
// if ctx.builder_signer.is_none() && !order.sim_value.paid_kickbacks.is_empty() {
// // Return here to avoid wasting time on a call to fork.commit_order that 99% will fail
// return Ok(Err(ExecutionError::OrderError(OrderErr::Bundle(
// BundleErr::NoSigner,
// ))));
// }

let mut fork = PartialBlockFork::new(state).with_tracer(&mut self.tracer);
let rollback = fork.rollback_point();
Expand Down Expand Up @@ -767,7 +767,9 @@ impl<Tracer: SimulationTracer> PartialBlock<Tracer> {

// Brecht: state root calculation
// TODO Brecht: Fix
let root_hash_config = root_hash_config.clone();
//let mut root_hash_config = root_hash_config.clone();
//root_hash_config.mode = RootHashMode::IgnoreParentHash;
//println!("root_hash_config: {:?}", root_hash_config);
let state_root = calculate_state_root(
provider_factories.get(&chain_id).unwrap().clone(),
ctx.attributes.parent,
Expand All @@ -776,6 +778,7 @@ impl<Tracer: SimulationTracer> PartialBlock<Tracer> {
ctx.shared_sparse_mpt_cache.clone(),
root_hash_config.clone(),
)?;
//let state_root = B256::ZERO;

// create the block header
let transactions_root = proofs::calculate_transaction_root(&self.executed_tx);
Expand Down Expand Up @@ -877,7 +880,7 @@ impl<Tracer: SimulationTracer> PartialBlock<Tracer> {
requests_root,
};

println!("chain {} header: {:?}", chain_id, header);
//println!("chain {} header: {:?}", chain_id, header);

let block = Block {
header,
Expand All @@ -894,7 +897,9 @@ impl<Tracer: SimulationTracer> PartialBlock<Tracer> {

let sealed_block = block.seal_slow();

println!("chain {} calculated block hash: {:?}", chain_id, sealed_block.hash());
sleep(Duration::from_millis(10));

println!("[{}] chain {} calculated block hash: {:?}", super_ctx.block(), chain_id, sealed_block.hash());

blocks.insert(chain_id, sealed_block);
}
Expand Down
6 changes: 5 additions & 1 deletion crates/rbuilder/src/building/order_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,10 @@ impl<'a, 'b, Tracer: SimulationTracer> PartialBlockFork<'a, 'b, Tracer> {
logs: res.result.logs().to_vec(),
};

// if !res.result.is_success() {
// println!("tx reverted with reason: {:?}", res.result);
// }

Ok(Ok(TransactionOk {
exec_result: res.result,
gas_used,
Expand Down Expand Up @@ -1168,7 +1172,7 @@ fn coinbase_profit(
if coinbase_balance_after >= coinbase_balance_before {
Ok(coinbase_balance_after - coinbase_balance_before)
} else {
Ok(U256::ZERO)
Ok(U256::from(1))
// Err(OrderErr::NegativeProfit(
// coinbase_balance_before - coinbase_balance_after,
// ))
Expand Down
6 changes: 4 additions & 2 deletions crates/rbuilder/src/building/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl<DB: Database> SimTree<DB> {
continue;
}
Ordering::Greater => {
println!("nonce invalid");
println!("nonce invalid greater");
// nonce invalid, maybe its optional
if !nonce.optional {
// this order will never be valid
Expand All @@ -177,8 +177,9 @@ impl<DB: Database> SimTree<DB> {
}
}
Ordering::Less => {
println!("nonce invalid");
println!("nonce invalid less");
if onchain_nonces_incremented.contains(&nonce.address) {
println!("Already seen it");
// we already considered this account nonce
continue;
}
Expand All @@ -191,6 +192,7 @@ impl<DB: Database> SimTree<DB> {
};

if let Some(sim_id) = self.sims_that_update_one_nonce.get(&nonce_key) {
println!("sims_that_update_one_nonce");
// we have something that fills this nonce
let sim = self.sims.get(sim_id).expect("we never delete sims");
parent_orders.extend_from_slice(&sim.previous_orders);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ impl ParallelSealerBidMakerProcess {

/// block.finalize_block + self.sink.new_block inside spawn_blocking.
async fn check_for_new_bid(&mut self) {
println!("ParallelSealerBidMakerProcess: check_for_new_bid");
if *self.seal_control.seals_in_progress.lock().unwrap() >= self.max_concurrent_seals {
println!("can't seal: max_concurrent_seals reached");
return;
}
if let Some(bid) = self.pending_bid.consume_bid() {
println!("check_for_new_bid");
//println!("there is a bid");
let payout_tx_val = bid.payout_tx_value();
let block = bid.block();
let block_number = block.building_context().block();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl PendingBid {
}
}
pub async fn wait_for_change(&self) {
//println!("wait_for_change bid");
self.bid_notify.notified().await
}
/// Updates bid, replacing on current (we assume they are always increasing but we don't check it).
Expand Down Expand Up @@ -88,13 +89,18 @@ impl SequentialSealerBidMakerProcess {

/// block.finalize_block + self.sink.new_block inside spawn_blocking.
async fn check_for_new_bid(&mut self) {
//println!("SequentialSealerBidMakerProcess: check_for_new_bid");
if let Some(bid) = self.pending_bid.consume_bid() {
//println!("there is a bid");
let payout_tx_val = bid.payout_tx_value();
let block = bid.block();
let block_number = block.building_context().block();
match tokio::task::spawn_blocking(move || block.finalize_block(payout_tx_val)).await {
Ok(finalize_res) => match finalize_res {
Ok(res) => self.sink.new_block(res.block),
Ok(res) => {
//println!("sending finalized block to sink");
self.sink.new_block(res.block)
},
Err(error) => {
if error.is_critical() {
error!(
Expand Down
Loading

0 comments on commit cc414f8

Please sign in to comment.