Skip to content

Commit

Permalink
Merge pull request ralexstokes#269 from ralexstokes/backport-interop-…
Browse files Browse the repository at this point in the history
…fixes

Backport interop fixes
  • Loading branch information
ralexstokes authored Oct 1, 2024
2 parents f17cb87 + f8696b4 commit 27cf655
Show file tree
Hide file tree
Showing 18 changed files with 149 additions and 172 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
target/
target/
result/
*local*
6 changes: 4 additions & 2 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,4 @@ rand = "0.8.5"
clap = "4.1.4"

[patch.crates-io]
c-kzg = { git = "https://github.com/ethereum/c-kzg-4844", tag = "v1.0.1" }
libffi-sys = { git = "https://github.com/tov/libffi-rs", rev = "d0704d634b6f3ffef5b6fc7e07fe965a1cff5c7b" }
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.77-bullseye AS chef
FROM rust:1.81-bullseye AS chef
RUN cargo install cargo-chef
WORKDIR /app

Expand Down
3 changes: 3 additions & 0 deletions bin/utils/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use beacon_api_client::{mainnet::Client, BlockId};
use mev_rs::{types::AuctionRequest, BlindedBlockRelayer, Relay, RelayEndpoint};
use url::Url;

// TODO: Remove once this is fixed between clippy and tokio
// https://github.com/rust-lang/rust-clippy/pull/13464
#[allow(clippy::needless_return)]
#[tokio::main]
async fn main() {
let endpoint = Url::parse("http://localhost:5052").unwrap();
Expand Down
63 changes: 12 additions & 51 deletions flake.lock

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

1 change: 0 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
};
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
};

Expand Down
2 changes: 1 addition & 1 deletion mev-boost-rs/src/relay_mux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl RelayMux {

pub fn on_slot(&self, slot: Slot) {
debug!(slot, "processing");
let retain_slot = slot - AUCTION_LIFETIME;
let retain_slot = slot.checked_sub(AUCTION_LIFETIME).unwrap_or_default();
let mut state = self.state.lock();
state.outstanding_bids.retain(|_, auction| auction.slot >= retain_slot);
}
Expand Down
3 changes: 3 additions & 0 deletions mev-boost-rs/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ fn create_proposers<R: rand::Rng>(rng: &mut R, count: usize) -> Vec<Proposer> {
.collect()
}

// TODO: Remove once this is fixed between clippy and tokio
// https://github.com/rust-lang/rust-clippy/pull/13464
#[allow(clippy::needless_return)]
#[tokio::test]
async fn test_end_to_end() {
setup_logging();
Expand Down
9 changes: 5 additions & 4 deletions mev-build-rs/src/auctioneer/service.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{
auctioneer::auction_schedule::{AuctionSchedule, Proposals, Proposer, RelayIndex, RelaySet},
bidder::Service as Bidder,
compat::{to_blobs_bundle, to_bytes20, to_bytes32, to_execution_payload},
payload::attributes::{BuilderPayloadBuilderAttributes, ProposalAttributes},
service::ClockMessage,
utils::compat::{to_blobs_bundle, to_bytes20, to_bytes32, to_execution_payload},
Error,
};
use ethereum_consensus::{
Expand Down Expand Up @@ -59,9 +59,10 @@ fn prepare_submission(
gas_used: payload.block().gas_used,
value: payload.fees(),
};
let execution_payload = to_execution_payload(payload.block());
let fork = context.fork_for(auction_context.slot);
let execution_payload = to_execution_payload(payload.block(), fork)?;
let signature = sign_builder_message(&message, signing_key, context)?;
let submission = match execution_payload.version() {
let submission = match fork {
Fork::Bellatrix => {
SignedBidSubmission::Bellatrix(block_submission::bellatrix::SignedBidSubmission {
message,
Expand All @@ -82,7 +83,7 @@ fn prepare_submission(
blobs_bundle: to_blobs_bundle(payload.sidecars())?,
signature,
}),
other => unreachable!("fork {other} is not reachable from this type"),
fork => return Err(Error::UnsupportedFork(fork)),
};
Ok(submission)
}
Expand Down
108 changes: 108 additions & 0 deletions mev-build-rs/src/compat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
use crate::Error;
use ethereum_consensus::{
crypto::{KzgCommitment, KzgProof},
primitives::{Bytes32, ExecutionAddress},
ssz::prelude::{ByteList, ByteVector, SimpleSerializeError, U256},
Fork,
};
use mev_rs::types::{BlobsBundle, ExecutionPayload};
use reth::primitives::{Address, BlobTransactionSidecar, Bloom, SealedBlock, B256};

#[cfg(not(feature = "minimal-preset"))]
use ethereum_consensus::deneb::mainnet as deneb;
#[cfg(feature = "minimal-preset")]
use ethereum_consensus::deneb::minimal as deneb;

pub fn to_bytes32(value: B256) -> Bytes32 {
Bytes32::try_from(value.as_ref()).unwrap()
}

pub fn to_bytes20(value: Address) -> ExecutionAddress {
ExecutionAddress::try_from(value.as_ref()).unwrap()
}

fn to_byte_vector(value: Bloom) -> ByteVector<256> {
ByteVector::<256>::try_from(value.as_ref()).unwrap()
}

pub fn to_execution_payload(value: &SealedBlock, fork: Fork) -> Result<ExecutionPayload, Error> {
let hash = value.hash();
let header = &value.header;
let transactions = &value.body;
let withdrawals = &value.withdrawals;
match fork {
Fork::Deneb => {
let transactions = transactions
.iter()
.map(|t| deneb::Transaction::try_from(t.envelope_encoded().as_ref()).unwrap())
.collect::<Vec<_>>();
let withdrawals = withdrawals
.as_ref()
.unwrap()
.iter()
.map(|w| deneb::Withdrawal {
index: w.index as usize,
validator_index: w.validator_index as usize,
address: to_bytes20(w.address),
amount: w.amount,
})
.collect::<Vec<_>>();

let payload = deneb::ExecutionPayload {
parent_hash: to_bytes32(header.parent_hash),
fee_recipient: to_bytes20(header.beneficiary),
state_root: to_bytes32(header.state_root),
receipts_root: to_bytes32(header.receipts_root),
logs_bloom: to_byte_vector(header.logs_bloom),
prev_randao: to_bytes32(header.mix_hash),
block_number: header.number,
gas_limit: header.gas_limit,
gas_used: header.gas_used,
timestamp: header.timestamp,
extra_data: ByteList::try_from(header.extra_data.as_ref()).unwrap(),
base_fee_per_gas: U256::from(header.base_fee_per_gas.unwrap_or_default()),
block_hash: to_bytes32(hash),
transactions: TryFrom::try_from(transactions).unwrap(),
withdrawals: TryFrom::try_from(withdrawals).unwrap(),
blob_gas_used: header.blob_gas_used.unwrap(),
excess_blob_gas: header.excess_blob_gas.unwrap(),
};
Ok(ExecutionPayload::Deneb(payload))
}
fork => Err(Error::UnsupportedFork(fork)),
}
}

pub fn to_blobs_bundle(sidecars: &[BlobTransactionSidecar]) -> Result<BlobsBundle, Error> {
let mut commitments = vec![];
let mut proofs = vec![];
let mut blobs = vec![];

for sidecar in sidecars {
for commitment in &sidecar.commitments {
let commitment = KzgCommitment::try_from(commitment.as_slice()).unwrap();
commitments.push(commitment);
}
for proof in &sidecar.proofs {
let proof = KzgProof::try_from(proof.as_slice()).unwrap();
proofs.push(proof);
}
for blob in &sidecar.blobs {
let blob = deneb::Blob::try_from(blob.as_ref()).unwrap();
blobs.push(blob);
}
}

Ok(BlobsBundle {
commitments: commitments
.try_into()
.map_err(|(_, err): (_, SimpleSerializeError)| Error::Consensus(err.into()))?,
proofs: proofs
.try_into()
.map_err(|(_, err): (_, SimpleSerializeError)| Error::Consensus(err.into()))?,

blobs: blobs
.try_into()
.map_err(|(_, err): (_, SimpleSerializeError)| Error::Consensus(err.into()))?,
})
}
4 changes: 3 additions & 1 deletion mev-build-rs/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use alloy_signer_wallet::WalletError;
use ethereum_consensus::Error as ConsensusError;
use ethereum_consensus::{Error as ConsensusError, Fork};
use reth::payload::error::PayloadBuilderError;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
#[error("fork {0} is not supported for this operation")]
UnsupportedFork(Fork),
#[error(transparent)]
Consensus(#[from] ConsensusError),
#[error(transparent)]
Expand Down
2 changes: 1 addition & 1 deletion mev-build-rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
mod auctioneer;
mod bidder;
mod compat;
mod error;
mod node;
mod payload;
mod service;
mod utils;

pub use crate::error::Error;
pub use service::{launch, Config};
Loading

0 comments on commit 27cf655

Please sign in to comment.