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
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 8 additions & 12 deletions crates/rbuilder-operator/src/blocks_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use rbuilder_primitives::{
serialize::{RawBundle, RawShareBundle},
Bundle, Order, OrderId,
};
use reth_primitives::SealedBlock;
use serde::{Deserialize, Serialize};
use serde_json::value::RawValue;
use serde_with::{serde_as, DisplayFromStr};
Expand Down Expand Up @@ -134,20 +133,20 @@ impl<HttpClientType: ClientT> BlocksProcessorClient<HttpClientType> {
}
pub async fn submit_built_block(
&self,
sealed_block: &SealedBlock,
submit_block_request: &SubmitBlockRequest,
built_block_trace: &BuiltBlockTrace,
builder_name: String,
best_bid_value: U256,
) -> eyre::Result<()> {
let execution_payload_v1 = submit_block_request.execution_payload_v1();
let header = BlocksProcessorHeader {
hash: sealed_block.hash(),
gas_limit: U256::from(sealed_block.gas_limit),
gas_used: U256::from(sealed_block.gas_used),
base_fee_per_gas: sealed_block.base_fee_per_gas.map(U256::from),
parent_hash: sealed_block.parent_hash,
timestamp: U256::from(sealed_block.timestamp),
number: Some(U256::from(sealed_block.number)),
hash: execution_payload_v1.block_hash,
gas_limit: U256::from(execution_payload_v1.gas_limit),
gas_used: U256::from(execution_payload_v1.gas_used),
base_fee_per_gas: Some(execution_payload_v1.base_fee_per_gas),
parent_hash: execution_payload_v1.parent_hash,
timestamp: U256::from(execution_payload_v1.timestamp),
number: Some(U256::from(execution_payload_v1.block_number)),
};
let closed_at = built_block_trace
.orders_closed_at
Expand Down Expand Up @@ -343,21 +342,18 @@ impl<HttpClientType: ClientT + Clone + Send + Sync + std::fmt::Debug + 'static>
fn block_submitted(
&self,
_slot_data: &MevBoostSlotData,
sealed_block: &SealedBlock,
submit_block_request: &SubmitBlockRequest,
built_block_trace: &BuiltBlockTrace,
builder_name: String,
best_bid_value: U256,
) {
let client = self.client.clone();
let parent_span = Span::current();
let sealed_block = sealed_block.clone();
let submit_block_request = submit_block_request.clone();
let built_block_trace = built_block_trace.clone();
tokio::spawn(async move {
let block_processor_result = client
.submit_built_block(
&sealed_block,
&submit_block_request,
&built_block_trace,
builder_name,
Expand Down
4 changes: 0 additions & 4 deletions crates/rbuilder-operator/src/flashbots_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use rbuilder::{
};
use rbuilder_config::EnvOrValue;
use rbuilder_primitives::mev_boost::SubmitBlockRequest;
use reth_primitives::SealedBlock;
use serde::Deserialize;
use serde_with::serde_as;
use tokio_util::sync::CancellationToken;
Expand Down Expand Up @@ -427,7 +426,6 @@ impl BidObserver for RbuilderOperatorBidObserver {
fn block_submitted(
&self,
slot_data: &MevBoostSlotData,
sealed_block: &SealedBlock,
submit_block_request: &SubmitBlockRequest,
built_block_trace: &BuiltBlockTrace,
builder_name: String,
Expand All @@ -436,7 +434,6 @@ impl BidObserver for RbuilderOperatorBidObserver {
if let Some(p) = self.block_processor.as_ref() {
p.block_submitted(
slot_data,
sealed_block,
submit_block_request,
built_block_trace,
builder_name.clone(),
Expand All @@ -446,7 +443,6 @@ impl BidObserver for RbuilderOperatorBidObserver {
if let Some(p) = self.tbv_pusher.as_ref() {
p.block_submitted(
slot_data,
sealed_block,
submit_block_request,
built_block_trace,
builder_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use rbuilder::{
};
use rbuilder_primitives::mev_boost::SubmitBlockRequest;
use redis::RedisError;
use reth_primitives::SealedBlock;
use tokio_util::sync::CancellationToken;

use super::{
Expand Down Expand Up @@ -74,7 +73,6 @@ impl BidObserver for BestTrueValueObserver {
fn block_submitted(
&self,
slot_data: &MevBoostSlotData,
_sealed_block: &SealedBlock,
_submit_block_request: &SubmitBlockRequest,
built_block_trace: &BuiltBlockTrace,
builder_name: String,
Expand Down
22 changes: 13 additions & 9 deletions crates/rbuilder-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,20 @@ alloy-rpc-types-eth.workspace = true
revm.workspace = true
revm-inspectors.workspace = true

# reth
reth-chainspec.workspace = true
reth-primitives-traits.workspace = true
reth-primitives.workspace = true
reth-ethereum-primitives.workspace = true
reth-transaction-pool.workspace = true

ethereum-consensus.workspace = true
ethereum_ssz.workspace = true
ethereum_ssz_derive.workspace = true
ssz_types = "0.8.0"
tree_hash = "0.8.0"
tree_hash_derive = "0.8.0"
typenum = "1.17.0"

# misc
derivative.workspace = true
Expand All @@ -38,18 +51,9 @@ tracing.workspace = true
time.workspace = true
thiserror.workspace = true
eyre.workspace = true
ethereum_ssz_derive.workspace = true
ethereum_ssz.workspace = true
serde.workspace = true
derive_more.workspace = true
serde_json.workspace = true

# reth
reth-chainspec.workspace = true
reth-primitives-traits.workspace = true
reth-primitives.workspace = true
reth-ethereum-primitives.workspace = true
reth-transaction-pool.workspace = true

[dev-dependencies]
rand.workspace = true
29 changes: 21 additions & 8 deletions crates/rbuilder-primitives/src/built_block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::mev_boost::{
BidAdjustmentData, CapellaSubmitBlockRequest, DenebSubmitBlockRequest,
BidAdjustmentDataV1, CapellaSubmitBlockRequest, DenebSubmitBlockRequest,
ElectraSubmitBlockRequest, FuluSubmitBlockRequest, SubmitBlockRequest,
};
use alloy_eips::{
Expand Down Expand Up @@ -37,10 +37,27 @@ pub struct SignedBuiltBlock {
}

impl SignedBuiltBlock {
pub fn into_request(
/// Convert the signed block into [`SubmitBlockRequest`].
/// NOTE: This does not set bid adjustment data. Use [`Self::into_request_with_adjustment_data`] instead.
pub fn into_request(self, chain_spec: &ChainSpec) -> eyre::Result<SubmitBlockRequest> {
self.into_request_inner(chain_spec, None)
}

/// Convert the signed block into [`SubmitBlockRequest`] with ad
pub fn into_request_with_adjustment_data(
self,
chain_spec: &ChainSpec,
adjustment_data: Option<BidAdjustmentDataV1>,
) -> eyre::Result<SubmitBlockRequest> {
self.into_request_inner(chain_spec, adjustment_data)
}

/// Convert the signed block into [`SubmitBlockRequest`].
/// NOTE:
fn into_request_inner(
self,
chain_spec: &ChainSpec,
adjustment_data: Option<BidAdjustmentData>,
adjustment_data: Option<BidAdjustmentDataV1>,
) -> eyre::Result<SubmitBlockRequest> {
match self.execution_payload {
ExecutionPayload::V1(_v1) => {
Expand Down Expand Up @@ -183,11 +200,7 @@ pub fn block_to_execution_payload(
.body()
.transactions
.iter()
.map(|tx| {
let mut buf = Vec::new();
tx.encode_2718(&mut buf);
buf.into()
})
.map(|tx| tx.encoded_2718().into())
.collect();
let payload_v1 = ExecutionPayloadV1 {
parent_hash: sealed_block.parent_hash,
Expand Down
84 changes: 83 additions & 1 deletion crates/rbuilder-primitives/src/mev_boost/adjustment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use alloy_primitives::{Address, Bloom, Bytes, B256};
ssz_derive::Encode,
ssz_derive::Decode,
)]
pub struct BidAdjustmentData {
pub struct BidAdjustmentDataV1 {
/// State root of the payload.
pub state_root: B256,
/// Transactions root of the payload.
Expand Down Expand Up @@ -84,3 +84,85 @@ pub struct BidAdjustmentDataV2 {
/// New in V2: Logs bloom accrued until but not including the last (payment) transaction.
pub pre_payment_logs_bloom: Bloom,
}

/// Common bid adjustment information that can be used for creating bid adjustment data.
#[derive(Clone, Debug)]
pub struct BidAdjustmentData {
/// State root of the payload.
pub state_root: B256,
/// Transactions root of the payload.
pub el_transactions_root: B256,
/// Withdrawals root of the payload.
pub el_withdrawals_root: B256,
/// Receipts root of the payload.
pub receipts_root: B256,
/// The merkle proof for the last transaction in the block, which will be overwritten with a
/// payment from `fee_payer` to `fee_recipient` if we adjust the bid.
pub el_placeholder_transaction_proof: Vec<Bytes>,
/// New in V2: SSZ merkle proof for last transaction
pub cl_placeholder_transaction_proof: Vec<B256>,
/// The merkle proof for the receipt of the placeholder transaction. It's required for
/// adjusting payments to contract addresses.
pub placeholder_receipt_proof: Vec<Bytes>,
/// New in V2: Logs bloom accrued until but not including the last (payment) transaction.
pub pre_payment_logs_bloom: Bloom,
/// State proofs.
pub state_proofs: BidAdjustmentStateProofs,
}

impl BidAdjustmentData {
/// Convert bid adjustment data into [`BidAdjustmentDataV1`].
pub fn into_v1(self) -> BidAdjustmentDataV1 {
BidAdjustmentDataV1 {
state_root: self.state_root,
transactions_root: self.el_transactions_root,
receipts_root: self.receipts_root,
builder_address: self.state_proofs.builder_address,
builder_proof: self.state_proofs.builder_proof,
fee_recipient_address: self.state_proofs.fee_recipient_address,
fee_recipient_proof: self.state_proofs.fee_recipient_proof,
fee_payer_address: self.state_proofs.fee_payer_address,
fee_payer_proof: self.state_proofs.fee_payer_proof,
placeholder_transaction_proof: self.el_placeholder_transaction_proof,
placeholder_receipt_proof: self.placeholder_receipt_proof,
}
}

/// Convert bid adjustment data into [`BidAdjustmentDataV2`].
pub fn into_v2(self) -> BidAdjustmentDataV2 {
BidAdjustmentDataV2 {
el_transactions_root: self.el_transactions_root,
el_withdrawals_root: self.el_withdrawals_root,
builder_address: self.state_proofs.builder_address,
builder_proof: self.state_proofs.builder_proof,
fee_recipient_address: self.state_proofs.fee_recipient_address,
fee_recipient_proof: self.state_proofs.fee_recipient_proof,
fee_payer_address: self.state_proofs.fee_payer_address,
fee_payer_proof: self.state_proofs.fee_payer_proof,
el_placeholder_transaction_proof: self.el_placeholder_transaction_proof,
cl_placeholder_transaction_proof: self.cl_placeholder_transaction_proof,
placeholder_receipt_proof: self.placeholder_receipt_proof,
pre_payment_logs_bloom: self.pre_payment_logs_bloom,
}
}
}

/// Bid adjustment state proofs.
#[derive(Clone, Debug)]
pub struct BidAdjustmentStateProofs {
/// The usual builder address that pays the proposer in the last transaction of the block.
/// When we adjust a bid, this transaction is overwritten by a transaction from the collateral
/// account `fee_payer_address`. If we don't adjust the bid, `builder_address` pays the
/// proposer as per usual.
pub builder_address: Address,
/// The state proof for the builder account.
pub builder_proof: Vec<Bytes>,
/// The proposer's fee recipient.
pub fee_recipient_address: Address,
/// The state proof for the fee recipient account.
pub fee_recipient_proof: Vec<Bytes>,
/// The fee payer address that is custodied by the relay.
pub fee_payer_address: Address,
/// The state proof for the fee payer account.
pub fee_payer_proof: Vec<Bytes>,
}
10 changes: 6 additions & 4 deletions crates/rbuilder-primitives/src/mev_boost/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ use alloy_rpc_types_engine::{BlobsBundleV1, BlobsBundleV2, ExecutionPayloadV3};
use reqwest::Url;
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DisplayFromStr};
use std::time::Duration;
use std::{sync::Arc, time::Duration};

mod submit_block;
pub use submit_block::*;

mod submit_header;
pub use submit_header::*;

pub mod ssz_roots;

mod optimistic_v3;
pub use optimistic_v3::*;

Expand Down Expand Up @@ -208,7 +210,7 @@ pub struct BidValueMetadata {

#[derive(Clone, Debug)]
pub struct SubmitBlockRequestWithMetadata {
pub submission: SubmitBlockRequest,
pub submission: Arc<SubmitBlockRequest>,
pub metadata: BidMetadata,
}

Expand All @@ -232,7 +234,7 @@ impl serde::Serialize for SubmitBlockRequestNoBlobs<'_> {
blobs_bundle: &'a BlobsBundleV1,
signature: &'a BlsSignature,
#[serde(skip_serializing_if = "Option::is_none")]
adjustment_data: &'a Option<BidAdjustmentData>,
adjustment_data: &'a Option<BidAdjustmentDataV1>,
}

SignedBidSubmissionV3Ref {
Expand All @@ -254,7 +256,7 @@ impl serde::Serialize for SubmitBlockRequestNoBlobs<'_> {
execution_requests: &'a ExecutionRequestsV4,
signature: &'a BlsSignature,
#[serde(skip_serializing_if = "Option::is_none")]
adjustment_data: &'a Option<BidAdjustmentData>,
adjustment_data: &'a Option<BidAdjustmentDataV1>,
}

SignedBidSubmissionV4Ref {
Expand Down
Loading
Loading