Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc fixes running in kurtosis #230

Merged
merged 5 commits into from
May 2, 2024
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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ ENV FEATURES ${FEATURES}

RUN apt-get update && apt-get -y upgrade && apt-get install -y libclang-dev pkg-config

RUN cargo chef cook --profile ${BUILD_PROFILE} --features ${FEATURES} --recipe-path recipe.json
RUN cargo chef cook --profile ${BUILD_PROFILE} --features "$FEATURES" --recipe-path recipe.json

COPY . .
RUN cargo build --profile ${BUILD_PROFILE} --features ${FEATURES} --locked --bin mev
RUN cargo build --profile ${BUILD_PROFILE} --features "$FEATURES" --locked --bin mev

RUN cp /app/target/${BUILD_PROFILE}/mev /app/mev

Expand Down
6 changes: 3 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
validate-example-config:
cargo run config example.config.toml

docker-build:
build-docker:
docker build -t ralexstokes/mev-rs .
docker-push:
push-docker:
docker push ralexstokes/mev-rs
docker-update: docker-build docker-push
update-docker-hub: build-docker push-docker

test:
cargo test --all
Expand Down
6 changes: 3 additions & 3 deletions mev-build-rs/src/auctioneer/auction_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
pub type RelaySet = HashSet<Arc<Relay>>;
pub type Proposals = HashMap<Proposer, RelaySet>;

#[derive(Debug, Default, Hash, PartialEq, Eq)]
#[derive(Debug, Clone, Default, Hash, PartialEq, Eq)]
pub struct Proposer {
pub public_key: BlsPublicKey,
pub fee_recipient: Address,
Expand All @@ -26,8 +26,8 @@ impl AuctionSchedule {
self.schedule.retain(|&slot, _| slot >= retain_slot);
}

pub fn take_matching_proposals(&mut self, slot: Slot) -> Option<Proposals> {
self.schedule.remove(&slot)
pub fn get_matching_proposals(&self, slot: Slot) -> Option<&Proposals> {
self.schedule.get(&slot)
}

pub fn process(&mut self, relay: Arc<Relay>, schedule: &[ProposerSchedule]) -> Vec<Slot> {
Expand Down
46 changes: 33 additions & 13 deletions mev-build-rs/src/auctioneer/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ use reth::{
payload::{EthBuiltPayload, Events, PayloadBuilderHandle, PayloadId, PayloadStore},
};
use serde::Deserialize;
use std::{collections::HashMap, sync::Arc};
use std::{
collections::{HashMap, HashSet},
sync::Arc,
};
use tokio::sync::{
broadcast,
mpsc::{Receiver, Sender},
};
use tokio_stream::StreamExt;
use tracing::{error, info, warn};
use tracing::{error, info, trace, warn};

fn make_attributes_for_proposer(
attributes: &BuilderPayloadBuilderAttributes,
Expand Down Expand Up @@ -129,6 +132,7 @@ pub struct Service<

auction_schedule: AuctionSchedule,
open_auctions: HashMap<PayloadId, Arc<AuctionContext>>,
processed_payload_attributes: HashMap<Slot, HashSet<PayloadId>>,
}

impl<
Expand Down Expand Up @@ -168,6 +172,7 @@ impl<
bidder_rx,
auction_schedule: Default::default(),
open_auctions: Default::default(),
processed_payload_attributes: Default::default(),
}
}

Expand All @@ -188,29 +193,36 @@ impl<
}

// NOTE: clear stale state
let slot = epoch * self.context.slots_per_epoch;
self.auction_schedule.clear(slot);
self.open_auctions.retain(|_, auction| auction.slot >= slot);
let retain_slot = epoch * self.context.slots_per_epoch;
self.auction_schedule.clear(retain_slot);
self.open_auctions.retain(|_, auction| auction.slot >= retain_slot);
self.processed_payload_attributes.retain(|&slot, _| slot >= retain_slot);
}

fn take_proposals(&mut self, slot: Slot) -> Option<Proposals> {
self.auction_schedule.take_matching_proposals(slot)
fn get_proposals(&self, slot: Slot) -> Option<&Proposals> {
self.auction_schedule.get_matching_proposals(slot)
}

async fn process_proposals(
&self,
slot: Slot,
attributes: BuilderPayloadBuilderAttributes,
proposals: Proposals,
proposals: &Proposals,
) -> Vec<AuctionContext> {
let mut new_auctions = vec![];
for (proposer, relays) in proposals {
let attributes = make_attributes_for_proposer(&attributes, &proposer);
let attributes = make_attributes_for_proposer(&attributes, proposer);

if self.start_build(&attributes).await.is_some() {
// TODO: can likely skip full attributes in `AuctionContext`
// TODO: consider data layout here...
let auction = AuctionContext { slot, attributes, proposer, relays };
// TODO: can likely refactor around auction schedule to skip some clones...
let auction = AuctionContext {
slot,
attributes,
proposer: proposer.clone(),
relays: relays.clone(),
};
new_auctions.push(auction);
}
}
Expand Down Expand Up @@ -251,8 +263,17 @@ impl<
self.context.seconds_per_slot,
)
.expect("is past genesis");

let processed_set = self.processed_payload_attributes.entry(slot).or_default();
let is_new = processed_set.insert(attributes.payload_id());

if !is_new {
trace!(payload_id = %attributes.payload_id(), "ignoring duplicate payload attributes");
return
}

// TODO: consolidate once stable
if let Some(proposals) = self.take_proposals(slot) {
if let Some(proposals) = self.get_proposals(slot) {
let auctions = self.process_proposals(slot, attributes, proposals).await;
for auction in auctions {
self.process_new_auction(auction).await;
Expand Down Expand Up @@ -285,13 +306,12 @@ impl<
BidderMessage::Dispatch { payload_id, value: _value, keep_alive: _keep_alive } => {
// TODO: forward keep alive signal to builder
// TODO: sort out streaming comms to builder
// TOOD: backpressure on bidder...?
if let Some(payload) = self.payload_store.resolve(payload_id).await {
match payload {
Ok(payload) => self.submit_payload(payload).await,
Err(err) => warn!(%err, "payload resolution failed"),
}
} else {
warn!(%payload_id, "no payload could be retrieved from payload store for bid")
}
}
_ => {}
Expand Down
5 changes: 3 additions & 2 deletions mev-rs/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ pub async fn get_genesis_time(
}

// fallback
warn!("could not get genesis time from context or connection to consensus node; using best guess");
typical_genesis_time(context)
let genesis_time = typical_genesis_time(context);
warn!(genesis_time, "could not get genesis time from context or connection to consensus node; using best guess");
genesis_time
}
}
}
Loading