Skip to content

Commit

Permalink
Merge pull request #241 from ralexstokes/relay-data-apis
Browse files Browse the repository at this point in the history
Relay data apis
  • Loading branch information
ralexstokes authored May 4, 2024
2 parents 4444a0d + e2e8654 commit 0d44616
Show file tree
Hide file tree
Showing 11 changed files with 469 additions and 57 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ default-members = ["bin/mev"]
version = "0.3.0"

[workspace.dependencies]
ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "0ead81b3401ee696d9f7f6abef0bf2c662555dc6" }
beacon-api-client = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "0ead81b3401ee696d9f7f6abef0bf2c662555dc6" }
ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "2ce2ca4d59ef2985088168b0f69a4a8c4f953241" }
beacon-api-client = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "2ce2ca4d59ef2985088168b0f69a4a8c4f953241" }

reth = { git = "https://github.com/paradigmxyz/reth", rev = "8e65cb3" }
reth-db = { git = "https://github.com/paradigmxyz/reth", rev = "8e65cb3" }
Expand Down
87 changes: 75 additions & 12 deletions mev-relay-rs/src/auction_context.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
use ethereum_consensus::{
primitives::{BlsPublicKey, U256},
ssz::prelude::*,
state_transition::Context,
};
use mev_rs::{
signing::{sign_builder_message, SecretKey},
types::{
auction_contents, builder_bid, AuctionContents, BlobsBundle, BuilderBid, ExecutionPayload,
ExecutionPayloadHeader, SignedBidSubmission, SignedBuilderBid,
auction_contents, builder_bid, AuctionContents, BidTrace, BlobsBundle, BuilderBid,
ExecutionPayload, ExecutionPayloadHeader, SignedBidSubmission, SignedBuilderBid,
},
Error,
};
use std::{
hash::{Hash, Hasher},
time::Duration,
};

fn to_header(execution_payload: &ExecutionPayload) -> Result<ExecutionPayloadHeader, Error> {
let header = match execution_payload {
Expand All @@ -25,13 +30,28 @@ fn to_header(execution_payload: &ExecutionPayload) -> Result<ExecutionPayloadHea
pub mod bellatrix {
use super::*;

#[derive(Debug)]
#[derive(Debug, PartialEq, Eq)]
pub struct AuctionContext {
pub builder_public_key: BlsPublicKey,
pub bid_trace: BidTrace,
pub receive_duration: Duration,
pub signed_builder_bid: SignedBuilderBid,
pub execution_payload: ExecutionPayload,
pub value: U256,
}

impl Hash for AuctionContext {
fn hash<H: Hasher>(&self, state: &mut H) {
self.builder_public_key.hash(state);
self.bid_trace.hash(state);
self.receive_duration.hash(state);
self.signed_builder_bid.hash(state);
let payload_root =
self.execution_payload.hash_tree_root().expect("can get hash tree root");
payload_root.hash(state);
self.value.hash(state);
}
}
}

pub mod capella {
Expand All @@ -41,17 +61,35 @@ pub mod capella {
pub mod deneb {
use super::*;

#[derive(Debug)]
#[derive(Debug, PartialEq, Eq)]
pub struct AuctionContext {
pub builder_public_key: BlsPublicKey,
pub bid_trace: BidTrace,
pub receive_duration: Duration,
pub signed_builder_bid: SignedBuilderBid,
pub execution_payload: ExecutionPayload,
pub value: U256,
pub blobs_bundle: BlobsBundle,
}

impl Hash for AuctionContext {
fn hash<H: Hasher>(&self, state: &mut H) {
self.builder_public_key.hash(state);
self.bid_trace.hash(state);
self.receive_duration.hash(state);
self.signed_builder_bid.hash(state);
let payload_root =
self.execution_payload.hash_tree_root().expect("can get hash tree root");
payload_root.hash(state);
self.value.hash(state);
let blobs_bundle_root =
self.blobs_bundle.hash_tree_root().expect("can get hash tree root");
blobs_bundle_root.hash(state);
}
}
}

#[derive(Debug)]
#[derive(Debug, PartialEq, Eq, Hash)]
pub enum AuctionContext {
Bellatrix(bellatrix::AuctionContext),
Capella(capella::AuctionContext),
Expand All @@ -61,6 +99,7 @@ pub enum AuctionContext {
impl AuctionContext {
pub fn new(
signed_submission: SignedBidSubmission,
receive_duration: Duration,
relay_public_key: BlsPublicKey,
relay_secret_key: &SecretKey,
context: &Context,
Expand Down Expand Up @@ -101,20 +140,28 @@ impl AuctionContext {
let signed_builder_bid = SignedBuilderBid { message: bid, signature };

let auction_context = match signed_submission {
SignedBidSubmission::Bellatrix(_) => Self::Bellatrix(bellatrix::AuctionContext {
builder_public_key,
signed_builder_bid,
execution_payload,
value,
}),
SignedBidSubmission::Capella(_) => Self::Capella(capella::AuctionContext {
SignedBidSubmission::Bellatrix(submission) => {
Self::Bellatrix(bellatrix::AuctionContext {
builder_public_key,
bid_trace: submission.message,
receive_duration,
signed_builder_bid,
execution_payload,
value,
})
}
SignedBidSubmission::Capella(submission) => Self::Capella(capella::AuctionContext {
builder_public_key,
bid_trace: submission.message,
receive_duration,
signed_builder_bid,
execution_payload,
value,
}),
SignedBidSubmission::Deneb(submission) => Self::Deneb(deneb::AuctionContext {
builder_public_key,
bid_trace: submission.message,
receive_duration,
signed_builder_bid,
execution_payload,
value,
Expand All @@ -133,6 +180,22 @@ impl AuctionContext {
}
}

pub fn bid_trace(&self) -> &BidTrace {
match self {
Self::Bellatrix(context) => &context.bid_trace,
Self::Capella(context) => &context.bid_trace,
Self::Deneb(context) => &context.bid_trace,
}
}

pub fn receive_duration(&self) -> Duration {
match self {
Self::Bellatrix(context) => context.receive_duration,
Self::Capella(context) => context.receive_duration,
Self::Deneb(context) => context.receive_duration,
}
}

pub fn signed_builder_bid(&self) -> &SignedBuilderBid {
match self {
Self::Bellatrix(context) => &context.signed_builder_bid,
Expand Down
Loading

0 comments on commit 0d44616

Please sign in to comment.