Skip to content
Open
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
126 changes: 126 additions & 0 deletions Cargo.lock

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

7 changes: 5 additions & 2 deletions mev-boost-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ version.workspace = true
edition = "2021"
license = "MIT OR Apache-2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { version = "1.0", features = ["full"] }
tracing = "0.1"
Expand All @@ -30,3 +28,8 @@ url = { version = "2.2.2", default-features = false }
serde_json = "1.0.81"
mev-build-rs = { path = "../mev-build-rs" }
mev-relay-rs = { path = "../mev-relay-rs" }
criterion = { version = "0.5", features = ["html_reports"] }

[[bench]]
name = "relay"
harness = false
22 changes: 22 additions & 0 deletions mev-boost-rs/benches/relay.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rand::prelude::SliceRandom;

fn choose(mut v: Vec<usize>) {
let mut rng = rand::thread_rng();
let i = v.choose(&mut rng).expect("at least one element");
v.remove(v.iter().position(|x| x == i).expect("element not found"));
}

fn shuffle(mut v: Vec<usize>) {
let mut rng = rand::thread_rng();
v.shuffle(&mut rng);
let (_, _) = v.split_first().expect("at least on element");
}

fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("choose", |b| b.iter(|| choose(black_box(vec![2, 5, 3, 5]))));
c.bench_function("shuffle", |b| b.iter(|| shuffle(black_box(vec![2, 5, 3, 5]))));
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
22 changes: 11 additions & 11 deletions mev-boost-rs/src/relay_mux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn validate_bid(
bid: bid_public_key.clone(),
relay: public_key.clone(),
}
.into())
.into());
}
Ok(bid.verify_signature(context)?)
}
Expand Down Expand Up @@ -195,7 +195,7 @@ impl BlindedBlockProvider for RelayMux {

if bids.is_empty() {
info!(%auction_request, "no relays had bids prepared");
return Err(Error::NoBidPrepared(auction_request.clone()))
return Err(Error::NoBidPrepared(auction_request.clone()));
}

// TODO: change `value` so it does the copy internally
Expand All @@ -204,17 +204,17 @@ impl BlindedBlockProvider for RelayMux {

// if multiple distinct bids with same bid value, break tie by randomly picking one
let mut rng = rand::thread_rng();
best_bid_indices.shuffle(&mut rng);
let best_bid_index = *best_bid_indices.choose(&mut rng).expect("there is at least one bid");
best_bid_indices.remove(
best_bid_indices.iter().position(|x| x == &best_bid_index).expect("bid not found"),
);

let (best_bid_index, rest) =
best_bid_indices.split_first().expect("there is at least one bid");

let (best_relay, best_bid) = &bids[*best_bid_index];
let (best_relay, best_bid) = &bids[best_bid_index];
let best_block_hash = best_bid.message.header().block_hash();

let mut best_relays = vec![best_relay.clone()];
for bid_index in rest {
let (relay, bid) = &bids[*bid_index];
for bid_index in best_bid_indices {
let (relay, bid) = &bids[bid_index];
if bid.message.header().block_hash() == best_block_hash {
best_relays.push(relay.clone());
}
Expand Down Expand Up @@ -273,7 +273,7 @@ impl BlindedBlockProvider for RelayMux {
let block_hash = auction_contents.execution_payload().block_hash();
if block_hash == expected_block_hash {
info!(%auction_request, %block_hash, %relay, "acquired payload");
return Ok(auction_contents)
return Ok(auction_contents);
} else {
warn!(?block_hash, ?expected_block_hash, %relay, "incorrect block hash delivered by relay");
}
Expand Down Expand Up @@ -316,7 +316,7 @@ mod tests {
assert_eq!(expected, best_bid_indices);

if best_bid_indices.is_empty() {
continue
continue;
}

// NOTE: test randomization logic
Expand Down