Skip to content

Commit

Permalink
fix clippy lint about using a potentially mutable type in HashSet
Browse files Browse the repository at this point in the history
  • Loading branch information
ralexstokes committed May 3, 2024
1 parent 2e06806 commit 3cda0ed
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
14 changes: 6 additions & 8 deletions mev-build-rs/src/auctioneer/auction_schedule.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use ethereum_consensus::primitives::{BlsPublicKey, Slot};
use mev_rs::{types::ProposerSchedule, Relay};
use mev_rs::types::ProposerSchedule;
use reth::primitives::Address;
use std::{
collections::{HashMap, HashSet},
sync::Arc,
};
use std::collections::{HashMap, HashSet};

pub type RelaySet = HashSet<Arc<Relay>>;
pub type RelayIndex = usize;
pub type RelaySet = HashSet<RelayIndex>;
pub type Proposals = HashMap<Proposer, RelaySet>;

#[derive(Debug, Clone, Default, Hash, PartialEq, Eq)]
Expand All @@ -30,7 +28,7 @@ impl AuctionSchedule {
self.schedule.get(&slot)
}

pub fn process(&mut self, relay: Arc<Relay>, schedule: &[ProposerSchedule]) -> Vec<Slot> {
pub fn process(&mut self, relay: RelayIndex, schedule: &[ProposerSchedule]) -> Vec<Slot> {
let mut slots = Vec::with_capacity(schedule.len());
for entry in schedule {
slots.push(entry.slot);
Expand All @@ -42,7 +40,7 @@ impl AuctionSchedule {
gas_limit: registration.gas_limit,
};
let relays = slot.entry(proposer).or_default();
relays.insert(relay.clone());
relays.insert(relay);
}
slots
}
Expand Down
30 changes: 19 additions & 11 deletions mev-build-rs/src/auctioneer/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub struct Service<
clock: broadcast::Receiver<ClockMessage>,
builder: PayloadBuilderHandle<Engine>,
payload_store: PayloadStore<Engine>,
relays: Vec<Arc<Relay>>,
relays: Vec<Relay>,
config: Config,
context: Arc<Context>,
// TODO consolidate this somewhere...
Expand Down Expand Up @@ -155,10 +155,8 @@ impl<
context: Arc<Context>,
genesis_time: u64,
) -> Self {
let relays = parse_relay_endpoints(&config.relays)
.into_iter()
.map(|endpoint| Arc::new(Relay::from(endpoint)))
.collect::<Vec<_>>();
let relays =
parse_relay_endpoints(&config.relays).into_iter().map(Relay::from).collect::<Vec<_>>();

config.public_key = config.secret_key.public_key();

Expand All @@ -185,10 +183,12 @@ impl<
// and not block others at this interval
// TODO: batch updates to auction schedule
// TODO: consider fast data access once this stabilizes
for relay in self.relays.iter() {
// TODO: rework `auction_schedule` so there is no issue with confusing relays and their
// indices
for (relay_index, relay) in self.relays.iter().enumerate() {
match relay.get_proposal_schedule().await {
Ok(schedule) => {
let slots = self.auction_schedule.process(relay.clone(), &schedule);
let slots = self.auction_schedule.process(relay_index, &schedule);
info!(?slots, %relay, "processed proposer schedule");
}
Err(err) => {
Expand Down Expand Up @@ -354,11 +354,19 @@ impl<
&self.context,
) {
Ok(signed_submission) => {
let relays = &auction.relays;
// TODO: parallel dispatch
for relay in relays {
if let Err(err) = relay.submit_bid(&signed_submission).await {
warn!(%err, ?relay, slot = auction.slot, "could not submit payload");
for &relay_index in &auction.relays {
match self.relays.get(relay_index) {
Some(relay) => {
if let Err(err) = relay.submit_bid(&signed_submission).await {
warn!(%err, ?relay, slot = auction.slot, "could not submit payload");
}
}
None => {
// NOTE: this arm signals a violation of an internal invariant
// Please fix if you see this error
error!(relay_index, "could not dispatch to unknown relay");
}
}
}
}
Expand Down

0 comments on commit 3cda0ed

Please sign in to comment.