Skip to content

Commit

Permalink
Merge pull request #217 from ralexstokes/builder/finish-initial-rewrite
Browse files Browse the repository at this point in the history
finish rest of builder rewrite
  • Loading branch information
ralexstokes authored Apr 27, 2024
2 parents 7913b81 + aa78177 commit 0d28337
Show file tree
Hide file tree
Showing 22 changed files with 1,265 additions and 193 deletions.
73 changes: 70 additions & 3 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ beacon-api-client = { git = "https://github.com/ralexstokes/ethereum-consensus",
reth = { git = "https://github.com/paradigmxyz/reth", rev = "71f8e678aa53f75c2c35badaa5848262de594cdc" }
reth-db = { git = "https://github.com/paradigmxyz/reth", rev = "71f8e678aa53f75c2c35badaa5848262de594cdc" }
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "71f8e678aa53f75c2c35badaa5848262de594cdc" }
reth-evm-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "71f8e678aa53f75c2c35badaa5848262de594cdc" }
reth-basic-payload-builder = { git = "https://github.com/paradigmxyz/reth", rev = "71f8e678aa53f75c2c35badaa5848262de594cdc" }
reth-ethereum-payload-builder = { git = "https://github.com/paradigmxyz/reth", rev = "71f8e678aa53f75c2c35badaa5848262de594cdc" }
alloy-signer = { git = "https://github.com/alloy-rs/alloy", rev = "188c4f8" }
alloy-signer-wallet = { git = "https://github.com/alloy-rs/alloy", rev = "188c4f8" }

eyre = "0.6.8"
futures-util = "0.3.30"
sha2 = "0.10.8"

[patch.crates-io]
c-kzg = { git = "https://github.com/ethereum/c-kzg-4844", tag = "v1.0.1" }
9 changes: 5 additions & 4 deletions example.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ accepted_builders = [
]

[builder]
# extra data to write into built execution payload
extra_data = "0x68656C6C6F20776F726C640A" # "hello world"
# wallet seed for builder to author payment transactions
execution_mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
# number of milliseconds to submit bids ahead of the target slot
bidding_deadline_ms = 1000
# amount of value to bid as a fraction of the payload's revenue
Expand All @@ -39,4 +35,9 @@ relays = [
"https://0x845bd072b7cd566f02faeb0a4033ce9399e42839ced64e8b2adcfc859ed1e8e1a5a293336a49feac6d9a5edb779be53a@boost-relay-sepolia.flashbots.net",
]
[builder.builder]
# address to collect transaction fees
fee_recipient = "0x0000000000000000000000000000000000000000"
# [optional] extra data to write into built execution payload
extra_data = "0x68656C6C6F20776F726C640A" # "hello world"
# wallet seed for builder to author payment transactions
execution_mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
5 changes: 4 additions & 1 deletion mev-build-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ mev-rs = { path = "../mev-rs" }
reth = { workspace = true }
reth-db = { workspace = true }
reth-node-ethereum = { workspace = true }
reth-evm-ethereum = { workspace = true }
reth-basic-payload-builder = { workspace = true }
reth-ethereum-payload-builder = { workspace = true }
alloy-signer = { workspace = true }
alloy-signer-wallet = { workspace = true, features = ["mnemonic"] }

sha2 = { workspace = true }
ethers = "2.0"
eyre = { workspace = true }
clap = { version = "4.1.4", features = ["derive", "env"] }
7 changes: 4 additions & 3 deletions mev-build-rs/src/auction_schedule.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use ethereum_consensus::primitives::{BlsPublicKey, ExecutionAddress, Slot};
use ethereum_consensus::primitives::{BlsPublicKey, Slot};
use mev_rs::{types::ProposerSchedule, Relay};
use reth::primitives::Address;
use std::{
collections::{HashMap, HashSet},
sync::Arc,
Expand All @@ -11,7 +12,7 @@ pub type Proposals = HashMap<Proposer, RelaySet>;
#[derive(Debug, Default, Hash, PartialEq, Eq)]
pub struct Proposer {
pub public_key: BlsPublicKey,
pub fee_recipient: ExecutionAddress,
pub fee_recipient: Address,
pub gas_limit: u64,
}

Expand All @@ -37,7 +38,7 @@ impl AuctionSchedule {
let registration = &entry.entry.message;
let proposer = Proposer {
public_key: registration.public_key.clone(),
fee_recipient: registration.fee_recipient.clone(),
fee_recipient: Address::from_slice(registration.fee_recipient.as_ref()),
gas_limit: registration.gas_limit,
};
let relays = slot.entry(proposer).or_default();
Expand Down
51 changes: 32 additions & 19 deletions mev-build-rs/src/auctioneer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
bidder::{AuctionContext, BidRequest, DeadlineBidder},
builder::{KeepAlive, Message as BuilderMessage},
service::ClockMessage,
utils::compat::{to_bytes32, to_execution_payload},
utils::compat::{to_bytes20, to_bytes32, to_execution_payload},
Error,
};
use ethereum_consensus::{
Expand All @@ -18,6 +18,7 @@ use mev_rs::{
BlindedBlockRelayer, Relay,
};
use reth::{
api::PayloadBuilderAttributes,
payload::{EthBuiltPayload, PayloadId},
tasks::TaskExecutor,
};
Expand All @@ -39,11 +40,11 @@ fn prepare_submission(
) -> Result<SignedBidSubmission, Error> {
let message = BidTrace {
slot: auction_context.slot,
parent_hash: to_bytes32(auction_context.attributes.parent),
parent_hash: to_bytes32(auction_context.attributes.inner.parent),
block_hash: to_bytes32(payload.block().hash()),
builder_public_key: public_key.clone(),
proposer_public_key: auction_context.proposer.public_key.clone(),
proposer_fee_recipient: auction_context.proposer.fee_recipient.clone(),
proposer_fee_recipient: to_bytes20(auction_context.proposer.fee_recipient),
gas_limit: payload.block().gas_limit,
gas_used: payload.block().gas_used,
value: payload.fees(),
Expand Down Expand Up @@ -113,7 +114,8 @@ impl Auctioneer {
self.auction_schedule.take_matching_proposals(slot)
}

fn process_new_auction(&mut self, payload_id: PayloadId, auction: AuctionContext) {
fn process_new_auction(&mut self, auction: AuctionContext) {
let payload_id = auction.attributes.payload_id();
self.open_auctions.insert(payload_id, Arc::new(auction));
let auction = self.open_auctions.get(&payload_id).unwrap().clone();

Expand All @@ -136,8 +138,7 @@ impl Auctioneer {

fn process_new_auctions(&mut self, auctions: Vec<AuctionContext>) {
for auction in auctions {
let payload_id = auction.attributes.payload_id();
self.process_new_auction(payload_id, auction);
self.process_new_auction(auction);
}
}

Expand All @@ -162,19 +163,35 @@ impl Auctioneer {
self.open_auctions.retain(|_, auction| auction.slot >= slot);
}

async fn dispatch_payload(&self, payload: EthBuiltPayload) {
async fn submit_payload(&self, payload: EthBuiltPayload) {
let auction = self.open_auctions.get(&payload.id()).expect("has auction");
let signed_submission = prepare_submission(
info!(
slot = auction.slot,
block_number = payload.block().number,
block_hash = %payload.block().hash(),
value = %payload.fees(),
relays=?auction.relays,
"submitting payload"
);
// TODO: should convert to ExecutionPayloadV3 etc. for blobs etc.
match prepare_submission(
payload,
&self.config.secret_key,
&self.config.public_key,
auction,
&self.context,
)
.expect("can prepare bid");
let relays = &auction.relays;
for relay in relays {
relay.submit_bid(&signed_submission).await.expect("was ok");
) {
Ok(signed_submission) => {
let relays = &auction.relays;
for relay in relays {
if let Err(err) = relay.submit_bid(&signed_submission).await {
warn!(%err, ?relay, slot = auction.slot, "could not submit payload");
}
}
}
Err(err) => {
warn!(%err, slot = auction.slot, "could not prepare submission")
}
}
}

Expand All @@ -185,12 +202,8 @@ impl Auctioneer {
let proposals = self.take_proposals(slot);
tx.send(proposals).expect("can send");
}
NewAuctions(auctions) => {
self.process_new_auctions(auctions);
}
BuiltPayload(payload) => {
self.dispatch_payload(payload).await;
}
NewAuctions(auctions) => self.process_new_auctions(auctions),
BuiltPayload(payload) => self.submit_payload(payload).await,
}
}

Expand Down
7 changes: 4 additions & 3 deletions mev-build-rs/src/bidder.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use crate::{
auction_schedule::{Proposer, RelaySet},
payload::builder_attributes::BuilderPayloadBuilderAttributes,
utils::payload_job::duration_until,
};
use ethereum_consensus::primitives::Slot;
use reth::payload::{EthPayloadBuilderAttributes, PayloadId};
use reth::{api::PayloadBuilderAttributes, payload::PayloadId};
use std::time::Duration;
use tokio::time::sleep;

#[derive(Debug)]
pub struct AuctionContext {
pub slot: Slot,
pub attributes: EthPayloadBuilderAttributes,
pub attributes: BuilderPayloadBuilderAttributes,
pub proposer: Proposer,
pub relays: RelaySet,
}
Expand All @@ -34,7 +35,7 @@ impl DeadlineBidder {
}

pub async fn make_bid(&self, auction: &AuctionContext) -> BidRequest {
let target = duration_until(auction.attributes.timestamp);
let target = duration_until(auction.attributes.timestamp());
let duration = target.checked_sub(self.deadline).unwrap_or_default();
sleep(duration).await;
BidRequest::Ready(auction.attributes.payload_id())
Expand Down
Loading

0 comments on commit 0d28337

Please sign in to comment.