Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions crates/rbuilder/src/building/builders/ordering_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use crate::{
block_building_helper::BlockBuildingHelper, BuiltBlockId, LiveBuilderInput,
OrderIntakeConsumer,
},
BlockBuildingContext, ExecutionError, NullPartialBlockExecutionTracer, OrderPriority,
PartialBlockExecutionTracer, PrioritizedOrderStore, SimulatedOrderSink, Sorting,
ThreadBlockBuildingContext,
order_is_worth_executing, BlockBuildingContext, ExecutionError,
NullPartialBlockExecutionTracer, OrderPriority, PartialBlockExecutionTracer,
PrioritizedOrderStore, SimulatedOrderSink, Sorting, ThreadBlockBuildingContext,
},
live_builder::building::built_block_cache::BuiltBlockCache,
provider::StateProviderFactory,
Expand Down Expand Up @@ -423,14 +423,17 @@ impl OrderingBuilderContext {
}
Err(err) => {
if let ExecutionError::LowerInsertedValue { inplace, .. } = &err {
// try to reinsert order into the map
let order_attempts = self.order_attempts.entry(sim_order.id()).or_insert(0);
if *order_attempts < self.config.failed_order_retries {
let mut new_order = (*sim_order).clone();
new_order.sim_value = inplace.clone();
block_orders.insert_order(Arc::new(new_order));
*order_attempts += 1;
reinserted = true;
if order_is_worth_executing(inplace).is_ok() {
// try to reinsert order into the map
let order_attempts =
self.order_attempts.entry(sim_order.id()).or_insert(0);
if *order_attempts < self.config.failed_order_retries {
let mut new_order = (*sim_order).clone();
new_order.sim_value = inplace.clone();
block_orders.insert_order(Arc::new(new_order));
*order_attempts += 1;
reinserted = true;
}
}
}
if !reinserted {
Expand Down
19 changes: 18 additions & 1 deletion crates/rbuilder/src/building/order_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use itertools::Itertools;
use rbuilder_primitives::{
evm_inspector::{RBuilderEVMInspector, UsedStateTrace},
BlockSpace, Bundle, Order, OrderId, RefundConfig, ShareBundle, ShareBundleBody,
ShareBundleInner, TransactionSignedEcRecoveredWithBlobs,
ShareBundleInner, SimValue, TransactionSignedEcRecoveredWithBlobs,
};
use reth::{
consensus_common::validation::MAX_RLP_BLOCK_SIZE, revm::database::StateProviderDatabase,
Expand Down Expand Up @@ -345,10 +345,27 @@ pub enum OrderErr {
Transaction(#[from] TransactionErr),
#[error("Bundle error: {0}")]
Bundle(#[from] BundleErr),
/// This is not really an error from order execution. We should probably move it away from here.
/// It's used after simulation to reject orders with no exclusive profit (only profit from mempool txs)
#[error("No exclusive profit")]
NoExclusiveProfit,
#[error("Negative profit: {0}")]
NegativeProfit(U256),
}

/// Sometimes we want to reject orders that pass simulation but we think are not going to be good for the block.
pub fn order_is_worth_executing(sim_value: &SimValue) -> Result<(), OrderErr> {
if sim_value
.non_mempool_profit_info()
.coinbase_profit()
.is_zero()
{
Err(OrderErr::NoExclusiveProfit)
} else {
Ok(())
}
}

/// Tracer for PartialBlockFork execution.
/// Passing the NullPartialBlockForkExecutionTracer should have 0 overhead (compiler should optimize it out).
pub trait PartialBlockForkExecutionTracer {
Expand Down
7 changes: 5 additions & 2 deletions crates/rbuilder/src/building/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use super::{
};
use crate::{
building::{
BlockBuildingContext, BlockBuildingSpaceState, BlockState, CriticalCommitOrderError,
NullPartialBlockForkExecutionTracer,
order_is_worth_executing, BlockBuildingContext, BlockBuildingSpaceState, BlockState,
CriticalCommitOrderError, NullPartialBlockForkExecutionTracer,
},
live_builder::order_input::mempool_txs_detector::MempoolTxsDetector,
provider::StateProviderFactory,
Expand Down Expand Up @@ -466,6 +466,9 @@ pub fn simulate_order_using_fork<Tracer: SimulationTracer>(
match result {
Ok(res) => {
let sim_value = create_sim_value(&order, &res, mempool_tx_detector);
if let Err(err) = order_is_worth_executing(&sim_value) {
return Ok(OrderSimResult::Failed(err));
}
let new_nonces = res.nonces_updated.into_iter().collect::<Vec<_>>();
Ok(OrderSimResult::Success(
Arc::new(SimulatedOrder {
Expand Down
Loading