Skip to content

Commit

Permalink
drop unnecessary mutex in AuctionSchedule
Browse files Browse the repository at this point in the history
  • Loading branch information
ralexstokes committed Apr 22, 2024
1 parent 4229200 commit 4dd89e3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 19 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion mev-build-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ tokio = { version = "1.0", features = ["full"] }
tokio-stream = "0.1.15"
tracing = "0.1"
async-trait = "0.1.53"
parking_lot = "0.12.1"
pin-project = "1.0.12"
futures-util = { workspace = true }

Expand Down
22 changes: 6 additions & 16 deletions mev-build-rs/src/auction_schedule.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use ethereum_consensus::primitives::{BlsPublicKey, ExecutionAddress, Slot};
use mev_rs::{types::ProposerSchedule, Relay};
use parking_lot::Mutex;
use std::{
collections::{HashMap, HashSet},
sync::Arc,
Expand All @@ -18,32 +17,23 @@ pub struct Proposer {

#[derive(Debug, Default)]
pub struct AuctionSchedule {
state: Mutex<State>,
}

#[derive(Debug, Default)]
struct State {
// TODO: use CL to also restrict builds by proposer
schedule: HashMap<Slot, Proposals>,
}

impl AuctionSchedule {
pub fn clear(&self, retain_slot: Slot) {
let mut state = self.state.lock();
state.schedule.retain(|&slot, _| slot >= retain_slot);
pub fn clear(&mut self, retain_slot: Slot) {
self.schedule.retain(|&slot, _| slot >= retain_slot);
}

pub fn take_matching_proposals(&self, slot: Slot) -> Option<Proposals> {
let mut state = self.state.lock();
state.schedule.remove(&slot)
pub fn take_matching_proposals(&mut self, slot: Slot) -> Option<Proposals> {
self.schedule.remove(&slot)
}

pub fn process(&self, relay: Arc<Relay>, schedule: &[ProposerSchedule]) -> Vec<Slot> {
pub fn process(&mut self, relay: Arc<Relay>, schedule: &[ProposerSchedule]) -> Vec<Slot> {
let mut slots = Vec::with_capacity(schedule.len());
let mut state = self.state.lock();
for entry in schedule {
slots.push(entry.slot);
let slot = state.schedule.entry(entry.slot).or_default();
let slot = self.schedule.entry(entry.slot).or_default();
let registration = &entry.entry.message;
let proposer = Proposer {
public_key: registration.public_key.clone(),
Expand Down
1 change: 0 additions & 1 deletion mev-build-rs/src/auctioneer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ pub struct Auctioneer {
clock: broadcast::Receiver<ClockMessage>,
builder: Sender<BuilderMessage>,
relays: Vec<Arc<Relay>>,
// TODO: can drop mutex on inner
auction_schedule: AuctionSchedule,
open_auctions: HashMap<PayloadId, Arc<AuctionContext>>,
executor: TaskExecutor,
Expand Down

0 comments on commit 4dd89e3

Please sign in to comment.