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
30 changes: 25 additions & 5 deletions crates/rbuilder-operator/src/blocks_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use serde_with::{serde_as, DisplayFromStr};
use std::{sync::Arc, time::Duration};
use time::format_description::well_known;
use tracing::{error, warn, Span};
use uuid::Uuid;

use crate::metrics::inc_submit_block_errors;

Expand Down Expand Up @@ -67,7 +66,7 @@ struct BlocksProcessorHeader {
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
#[serde(rename_all = "camelCase")]
pub struct BlockProcessorDelayedPayments {
pub source: Uuid,
pub source: String,
pub value: U256,
pub address: Address,
}
Expand Down Expand Up @@ -177,7 +176,7 @@ impl<HttpClientType: ClientT> BlocksProcessorClient<HttpClientType> {

let used_share_bundles = Self::get_used_sbundles(built_block_trace);

let delayed_payments = built_block_trace
let mut delayed_payments: Vec<_> = built_block_trace
.included_orders
.iter()
.filter_map(|res| {
Expand All @@ -200,12 +199,17 @@ impl<HttpClientType: ClientT> BlocksProcessorClient<HttpClientType> {
};

Some(BlockProcessorDelayedPayments {
source: bundle_uuid,
source: bundle_uuid.to_string(),
value: delayed_kickback.payout_value,
address: delayed_kickback.recipient,
})
})
.collect();
delayed_payments.push(BlockProcessorDelayedPayments {
source: "mev_blocker".into(),
value: built_block_trace.mev_blocker_price,
address: Address::ZERO,
});

let params: ConsumeBuiltBlockRequest = (
header,
Expand Down Expand Up @@ -379,6 +383,8 @@ fn backoff() -> Backoff {

#[cfg(test)]
mod tests {
use uuid::Uuid;

use super::*;

#[test]
Expand All @@ -402,13 +408,27 @@ mod tests {
let value = BlockProcessorDelayedPayments {
address: alloy_primitives::address!("93Ea7cB31f76B982601321b2A0d93Ec9A948236D"),
value: U256::from(16),
source: Uuid::try_parse("ff7b2232-b30d-4889-9258-c3632ba4bfc0").unwrap(),
source: Uuid::try_parse("ff7b2232-b30d-4889-9258-c3632ba4bfc0")
.unwrap()
.to_string(),
};

let value_str = serde_json::to_string(&value).unwrap();

let expected_str = r#"{"source":"ff7b2232-b30d-4889-9258-c3632ba4bfc0","value":"0x10","address":"0x93ea7cb31f76b982601321b2a0d93ec9a948236d"}"#;

assert_eq!(value_str, expected_str);

let value = BlockProcessorDelayedPayments {
address: Address::ZERO,
value: U256::from(16),
source: "mev_blocker".into(),
};

let value_str = serde_json::to_string(&value).unwrap();

let expected_str = r#"{"source":"mev_blocker","value":"0x10","address":"0x0000000000000000000000000000000000000000"}"#;

assert_eq!(value_str, expected_str);
}
}
6 changes: 5 additions & 1 deletion crates/rbuilder-operator/src/flashbots_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! This code has lots of copy/paste from the example config but it's not really copy/paste since we use our own private types.
//! @Pending make this copy/paste generic code on the library

use alloy_primitives::U256;
use alloy_primitives::{Address, U256};
use alloy_signer_local::PrivateKeySigner;
use derivative::Derivative;
use eyre::Context;
Expand Down Expand Up @@ -112,6 +112,10 @@ pub struct FlashbotsConfig {
/// For production we always need some tbv push (since it's used by smart-multiplexing.) so:
/// !Some(key_registration_url) => Some(tbv_push_redis)
tbv_push_redis: Option<TBVPushRedisConfig>,

/// Bundles with refund identity or signer set to these will not receive any redistributions.
#[serde(default)]
pub backtest_ignored_signers: Vec<Address>,
}

impl LiveBuilderConfig for FlashbotsConfig {
Expand Down
2 changes: 1 addition & 1 deletion crates/rbuilder/src/backtest/backtest_build_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ fn spawn_block_fetcher(
as u64,
)) {
Ok(mut block) => {
block.filter_out_ignored_signers(&ignored_signers);
block.filter_out_ignored_signers(&ignored_signers, false);
Some(block)
}
Err(err) => {
Expand Down
13 changes: 11 additions & 2 deletions crates/rbuilder/src/backtest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,19 @@ impl BlockData {
});
}

pub fn filter_out_ignored_signers(&mut self, ignored_signers: &[Address]) {
pub fn filter_out_ignored_signers(
&mut self,
ignored_signers: &[Address],
use_refund_identity: bool,
) {
self.available_orders.retain(|orders| {
let order = &orders.order;
let signer = if let Some(signer) = order.signer() {
let signer = if use_refund_identity {
order.metadata().refund_identity.or_else(|| order.signer())
} else {
order.signer()
};
let signer = if let Some(signer) = signer {
signer
} else {
return true;
Expand Down
17 changes: 15 additions & 2 deletions crates/rbuilder/src/backtest/redistribute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ pub fn calc_redistributions<P, ConfigType>(
block_data: BlockData,
distribute_to_mempool_txs: bool,
blocklist: BlockList,
ignored_signers: &[Address],
) -> eyre::Result<RedistributionBlockOutput>
where
P: StateProviderFactory + Clone + 'static,
Expand All @@ -133,14 +134,21 @@ where
let _block_span = info_span!("block", block = block_data.block_number).entered();
let protect_signers = config.base_config().backtest_protect_bundle_signers.clone();

info!(?protect_signers, "Protect signers");
info!(
?protect_signers,
?ignored_signers,
blocklist_len = blocklist.len(),
distribute_to_mempool_txs,
"Started to calculate redistribution"
);

if protect_signers.is_empty() {
warn!("Protect signers are not set");
}

let start = Instant::now();
let (onchain_block_profit, block_data, built_block_data) =
prepare_block_data(config, block_data)?;
prepare_block_data(config, block_data, ignored_signers)?;

let included_orders_available =
get_available_orders(&block_data, &built_block_data, distribute_to_mempool_txs);
Expand Down Expand Up @@ -269,6 +277,7 @@ where
fn prepare_block_data<ConfigType>(
config: &ConfigType,
mut block_data: BlockData,
ignored_signers: &[Address],
) -> eyre::Result<(U256, BlockData, BuiltBlockData)>
where
ConfigType: LiveBuilderConfig,
Expand Down Expand Up @@ -296,6 +305,7 @@ where
// @TODO filter cancellations properly, for this we need actual cancellations in the backtest data
// filter bundles made out of mempool txs
block_data.filter_bundles_from_mempool();
block_data.filter_out_ignored_signers(ignored_signers, true);

let filtered = orders_before_filtering - block_data.available_orders.len();

Expand Down Expand Up @@ -355,6 +365,9 @@ fn get_available_orders(
Some(OrderFilteredReason::MempoolTxs) => {
info!(order = ?id, "Included order was filtered because all txs are from mempool");
}
Some(OrderFilteredReason::Signer) => {
info!(order = ?id, "Included order was filtered because signer is explicitly ignored");
}
Some(reason) => {
error!(order = ?id, ?reason, "Included order was filtered from available orders");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ impl<

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.mev_blocker_price = self.building_context().mev_blocker_price;
Ok(())
}

Expand Down
3 changes: 3 additions & 0 deletions crates/rbuilder/src/building/built_block_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub struct BuiltBlockTrace {
pub coinbase_reward: U256,
/// True block value (coinbase balance delta) excluding the cost of the payout to validator
pub true_bid_value: U256,
/// Amount that is left out on the coinbase to pay for mev blocker orderflow
pub mev_blocker_price: U256,
/// Timestamp of the moment we stopped considering new orders for this block.
pub orders_closed_at: OffsetDateTime,
/// UnfinishedBuiltBlocksInput chose this block as the best block and sent it downstream
Expand Down Expand Up @@ -75,6 +77,7 @@ impl BuiltBlockTrace {
bid_value: U256::from(0),
coinbase_reward: U256::from(0),
true_bid_value: U256::from(0),
mev_blocker_price: U256::from(0),
orders_closed_at: OffsetDateTime::now_utc(),
orders_sealed_at: OffsetDateTime::now_utc(),
fill_time: Duration::from_secs(0),
Expand Down
Loading