Skip to content

Commit

Permalink
feat: Add BuiltBlockTracerError (#21)
Browse files Browse the repository at this point in the history
## 📝 Summary

- Add BuitlBlockTracerError
- Add .code and .idea to `.gitignore`
- And lint

## 💡 Motivation and Context

<!--- (Optional) Why is this change required? What problem does it
solve? Remove this section if not applicable. -->

---

## ✅ I have completed the following steps:

* [x] Run `make lint`
* [x] Run `make test`
* [ ] Added tests (if applicable)
  • Loading branch information
jn authored Jul 5, 2024
1 parent a25f33b commit c1564f7
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 27 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
/mev-test-contract/out
/target
/scripts/benchmark-results.*
/test/
/test/

# editors
.code
.idea
7 changes: 4 additions & 3 deletions crates/rbuilder/src/bin/debug-bench-machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ use rbuilder::{
roothash::RootHashMode,
utils::{default_cfg_env, Signer},
};
use reth::providers::BlockReader;
use reth::{
payload::PayloadId, primitives::revm_primitives::BlobExcessGasAndPrice,
providers::BlockNumReader, revm::primitives::BlockEnv,
payload::PayloadId,
primitives::revm_primitives::BlobExcessGasAndPrice,
providers::{BlockNumReader, BlockReader},
revm::primitives::BlockEnv,
};
use reth_payload_builder::{database::CachedReads, EthPayloadBuilderAttributes};
use revm::primitives::SpecId;
Expand Down
2 changes: 1 addition & 1 deletion crates/rbuilder/src/building/builders/ordering_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
//! The described algorithm is ran continuously adding new SimulatedOrders (they arrive on real time!) on each iteration until we run out of time (slot ends).
//! Sorting criteria are described on [`Sorting`].
//! For some more details see [`OrderingBuilderConfig`]
use crate::building::block_orders_from_sim_orders;
use crate::{
building::{
block_orders_from_sim_orders,
builders::{LiveBuilderInput, OrderIntakeConsumer},
estimate_payout_gas_limit, BlockBuildingContext, BlockOrders, BlockState, BuiltBlockTrace,
ExecutionError, PartialBlock, Sorting,
Expand Down
30 changes: 21 additions & 9 deletions crates/rbuilder/src/building/built_block_trace.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{BundleErr, ExecutionError, ExecutionResult, OrderErr};
use crate::primitives::Order;
use crate::primitives::{Order, OrderReplacementKey};
use ahash::{HashMap, HashSet};
use alloy_primitives::{Address, U256};
use std::time::Duration;
Expand Down Expand Up @@ -29,6 +29,18 @@ impl Default for BuiltBlockTrace {
}
}

#[derive(thiserror::Error, Debug)]
pub enum BuiltBlockTraceError {
#[error("More than one order is included with the same replacement data: {0:?}")]
DuplicateReplacementData(OrderReplacementKey),
#[error("Included order had different number of txs and receipts")]
DifferentTxsAndReceipts,
#[error("Included order had tx from or to blocked address")]
BlockedAddress,
#[error("Bundle tx reverted that is not revertable")]
BundleTxReverted,
}

impl BuiltBlockTrace {
pub fn new() -> Self {
Self {
Expand Down Expand Up @@ -78,24 +90,24 @@ impl BuiltBlockTrace {
})
}

pub fn verify_bundle_consistency(&self, blocklist: &HashSet<Address>) -> eyre::Result<()> {
pub fn verify_bundle_consistency(
&self,
blocklist: &HashSet<Address>,
) -> Result<(), BuiltBlockTraceError> {
let mut replacement_data_count: HashSet<_> = HashSet::default();

for res in &self.included_orders {
for order in res.order.original_orders() {
if let Some(data) = order.replacement_key() {
if replacement_data_count.contains(&data) {
eyre::bail!(
"More than one order is included with the same replacement data: {:?}",
data
);
return Err(BuiltBlockTraceError::DuplicateReplacementData(data));
}
replacement_data_count.insert(data);
}
}

if res.txs.len() != res.receipts.len() {
eyre::bail!("Included order had different number of txs and receipts");
return Err(BuiltBlockTraceError::DifferentTxsAndReceipts);
}

let mut executed_tx_hashes = Vec::with_capacity(res.txs.len());
Expand All @@ -105,7 +117,7 @@ impl BuiltBlockTrace {
if blocklist.contains(&tx.signer())
|| tx.to().map(|to| blocklist.contains(&to)).unwrap_or(false)
{
eyre::bail!("Included order had tx from or to blocked address");
return Err(BuiltBlockTraceError::BlockedAddress);
}
}

Expand All @@ -118,7 +130,7 @@ impl BuiltBlockTrace {
for (executed_hash, success) in executed_tx_hashes {
if let Some(can_revert) = bundle_txs.get(&executed_hash) {
if !success && !can_revert {
eyre::bail!("Bundle tx reverted that is not revertable");
return Err(BuiltBlockTraceError::BundleTxReverted);
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions crates/rbuilder/src/live_builder/base_config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//! Config should always be deserializable, default values should be used
//!
use crate::live_builder::bidding::DummyBiddingService;
use crate::live_builder::building::relay_submit::RelaySubmitSinkFactory;
use crate::live_builder::order_input::OrderInputConfig;
use crate::live_builder::LiveBuilder;
use crate::{
flashbots::BlocksProcessorClient,
live_builder::building::SubmissionConfig,
live_builder::{
bidding::DummyBiddingService,
building::{relay_submit::RelaySubmitSinkFactory, SubmissionConfig},
order_input::OrderInputConfig,
LiveBuilder,
},
mev_boost::BLSBlockSigner,
primitives::mev_boost::MevBoostRelay,
telemetry::{setup_reloadable_tracing_subscriber, LoggerConfig},
Expand Down
17 changes: 9 additions & 8 deletions crates/rbuilder/src/live_builder/config.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//! Config should always be deserializable, default values should be used
//!
use crate::building::builders::ordering_builder::OrderingBuildingAlgorithm;
use crate::building::builders::{
BacktestSimulateBlockInput, BestBlockCell, Block, BlockBuildingAlgorithm,
};
use crate::live_builder::cli::LiveBuilderConfig;
use crate::utils::build_info::rbuilder_version;
use crate::{
building::{builders::ordering_builder::OrderingBuilderConfig, Sorting},
utils::{ProviderFactoryReopener, Signer},
building::{
builders::{
ordering_builder::{OrderingBuilderConfig, OrderingBuildingAlgorithm},
BacktestSimulateBlockInput, BestBlockCell, Block, BlockBuildingAlgorithm,
},
Sorting,
},
live_builder::cli::LiveBuilderConfig,
utils::{build_info::rbuilder_version, ProviderFactoryReopener, Signer},
};
use alloy_primitives::{Address, B256};
use eyre::Context;
Expand Down

0 comments on commit c1564f7

Please sign in to comment.