Skip to content

Commit 9b01756

Browse files
authored
Rename Participant to Bid (#4026)
# Description Follows [a suggestion](#4011 (comment)) from another PR, that basically renames the Participant struct into Bid, which makes more sense since this Bid now contains the score data. # Changes - The naming itself - Docs - Only the DB auction participants remain, which are basically participant addresses, which are valid names. ## How to test Existing tests.
1 parent ef94b8d commit 9b01756

File tree

7 files changed

+100
-118
lines changed

7 files changed

+100
-118
lines changed

crates/autopilot/src/domain/competition/participant.rs renamed to crates/autopilot/src/domain/competition/bid.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use {
99
pub type Scored = state::Scored<Score>;
1010
pub type Ranked = state::Ranked<Score>;
1111

12-
/// A solver's solution paired with the driver, progressing through the winner
13-
/// selection process.
12+
/// A solver's auction bid, which includes solution and corresponding driver
13+
/// data, progressing through the winner selection process.
1414
///
1515
/// It uses the type-state pattern to enforce correct state
1616
/// transitions at compile time. The state parameter tracks progression through
@@ -20,13 +20,13 @@ pub type Ranked = state::Ranked<Score>;
2020
/// 2. **Scored**: After computing surplus and fees for the solution
2121
/// 3. **Ranked**: After winner selection determines if this is a winner
2222
#[derive(Clone)]
23-
pub struct Participant<State = Ranked> {
23+
pub struct Bid<State = Ranked> {
2424
solution: Solution,
2525
driver: Arc<infra::Driver>,
2626
state: State,
2727
}
2828

29-
impl<T> Participant<T> {
29+
impl<T> Bid<T> {
3030
pub fn solution(&self) -> &Solution {
3131
&self.solution
3232
}
@@ -36,12 +36,12 @@ impl<T> Participant<T> {
3636
}
3737
}
3838

39-
impl<State> state::HasState for Participant<State> {
40-
type Next<NewState> = Participant<NewState>;
39+
impl<State> state::HasState for Bid<State> {
40+
type Next<NewState> = Bid<NewState>;
4141
type State = State;
4242

4343
fn with_state<NewState>(self, state: NewState) -> Self::Next<NewState> {
44-
Participant {
44+
Bid {
4545
solution: self.solution,
4646
driver: self.driver,
4747
state,
@@ -53,7 +53,7 @@ impl<State> state::HasState for Participant<State> {
5353
}
5454
}
5555

56-
impl Participant<Unscored> {
56+
impl Bid<Unscored> {
5757
pub fn new(solution: Solution, driver: Arc<infra::Driver>) -> Self {
5858
Self {
5959
solution,

crates/autopilot/src/domain/competition/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use {
77
std::collections::HashMap,
88
};
99

10-
mod participant;
10+
mod bid;
1111
mod participation_guard;
1212
pub mod winner_selection;
1313

1414
pub use {
15-
participant::{Participant, RankType, Ranked, Scored, Unscored},
15+
bid::{Bid, RankType, Ranked, Scored, Unscored},
1616
participation_guard::SolverParticipationGuard,
1717
};
1818

crates/autopilot/src/domain/competition/winner_selection.rs

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use {
2828
crate::domain::{
2929
self,
3030
auction::order,
31-
competition::{Participant, RankType, Ranked, Score, Solution, TradedOrder, Unscored},
31+
competition::{Bid, RankType, Ranked, Score, Solution, TradedOrder, Unscored},
3232
eth::{self, WrappedNativeToken},
3333
fee,
3434
},
@@ -45,7 +45,7 @@ pub struct Arbitrator(winsel::Arbitrator);
4545
/// 3. compute reference scores
4646
///
4747
/// The functions assume the `Arbitrator` is the only one
48-
/// changing the ordering or the `participants`.
48+
/// changing the ordering or the `bids`.
4949
impl Arbitrator {
5050
pub fn new(max_winners: usize, wrapped_native_token: WrappedNativeToken) -> Self {
5151
let token: eth::TokenAddress = wrapped_native_token.into();
@@ -56,19 +56,15 @@ impl Arbitrator {
5656
}
5757

5858
/// Runs the entire auction mechanism on the passed in solutions.
59-
pub fn arbitrate(
60-
&self,
61-
participants: Vec<Participant<Unscored>>,
62-
auction: &domain::Auction,
63-
) -> Ranking {
59+
pub fn arbitrate(&self, bids: Vec<Bid<Unscored>>, auction: &domain::Auction) -> Ranking {
6460
let context = auction.into();
65-
let mut participant_by_key = HashMap::with_capacity(participants.len());
66-
let mut solutions = Vec::with_capacity(participants.len());
61+
let mut bid_by_key = HashMap::with_capacity(bids.len());
62+
let mut solutions = Vec::with_capacity(bids.len());
6763

68-
for participant in participants {
69-
let key = SolutionKey::from(participant.solution());
70-
let solution = participant.solution().into();
71-
participant_by_key.insert(key, participant);
64+
for bid in bids {
65+
let key = SolutionKey::from(bid.solution());
66+
let solution = bid.solution().into();
67+
bid_by_key.insert(key, bid);
7268
solutions.push(solution);
7369
}
7470

@@ -85,27 +81,25 @@ impl Arbitrator {
8581
let mut filtered_out = Vec::with_capacity(ws_ranking.filtered_out.len());
8682
for ws_solution in ws_ranking.filtered_out {
8783
let key = SolutionKey::from(&ws_solution);
88-
let participant = participant_by_key
84+
let bid = bid_by_key
8985
.remove(&key)
90-
.expect("every ranked solution has a matching participant");
86+
.expect("every ranked solution has a matching bid");
9187
let score = ws_solution.score();
9288
filtered_out.push(
93-
participant
94-
.with_score(Score(eth::Ether(score)))
89+
bid.with_score(Score(eth::Ether(score)))
9590
.with_rank(RankType::FilteredOut),
9691
);
9792
}
9893

9994
let mut ranked = Vec::with_capacity(ws_ranking.ranked.len());
10095
for ranked_solution in ws_ranking.ranked {
10196
let key = SolutionKey::from(&ranked_solution);
102-
let participant = participant_by_key
97+
let bid = bid_by_key
10398
.remove(&key)
104-
.expect("every ranked solution has a matching participant");
99+
.expect("every ranked solution has a matching bid");
105100
let score = ranked_solution.score();
106101
ranked.push(
107-
participant
108-
.with_score(Score(eth::Ether(score)))
102+
bid.with_score(Score(eth::Ether(score)))
109103
.with_rank(ranked_solution.state().rank_type),
110104
);
111105
}
@@ -242,34 +236,34 @@ impl<S> From<&winsel::Solution<S>> for SolutionKey {
242236
pub struct Ranking {
243237
/// Solutions that were discarded because they were malformed
244238
/// in some way or deemed unfair by the selection mechanism.
245-
filtered_out: Vec<Participant<Ranked>>,
239+
filtered_out: Vec<Bid<Ranked>>,
246240
/// Final ranking of the solutions that passed the fairness
247241
/// check. Winners come before non-winners and higher total
248242
/// scores come before lower scores.
249-
ranked: Vec<Participant<Ranked>>,
243+
ranked: Vec<Bid<Ranked>>,
250244
/// Reference scores for each winning solver, used to compute rewards.
251245
reference_scores: HashMap<eth::Address, Score>,
252246
}
253247

254248
impl Ranking {
255249
/// All solutions including the ones that got filtered out.
256-
pub fn all(&self) -> impl Iterator<Item = &Participant<Ranked>> {
250+
pub fn all(&self) -> impl Iterator<Item = &Bid<Ranked>> {
257251
self.ranked.iter().chain(&self.filtered_out)
258252
}
259253

260254
/// Enumerates all solutions. The index is used as solution UID.
261-
pub fn enumerated(&self) -> impl Iterator<Item = (usize, &Participant<Ranked>)> {
255+
pub fn enumerated(&self) -> impl Iterator<Item = (usize, &Bid<Ranked>)> {
262256
self.all().enumerate()
263257
}
264258

265259
/// All solutions that won the right to get executed.
266-
pub fn winners(&self) -> impl Iterator<Item = &Participant<Ranked>> {
267-
self.ranked.iter().filter(|p| p.is_winner())
260+
pub fn winners(&self) -> impl Iterator<Item = &Bid<Ranked>> {
261+
self.ranked.iter().filter(|b| b.is_winner())
268262
}
269263

270264
/// All solutions that were not filtered out but also did not win.
271-
pub fn non_winners(&self) -> impl Iterator<Item = &Participant<Ranked>> {
272-
self.ranked.iter().filter(|p| !p.is_winner())
265+
pub fn non_winners(&self) -> impl Iterator<Item = &Bid<Ranked>> {
266+
self.ranked.iter().filter(|b| !b.is_winner())
273267
}
274268

275269
/// Reference scores for each winning solver, used to compute rewards.
@@ -278,7 +272,7 @@ impl Ranking {
278272
}
279273

280274
/// All solutions that passed the filtering step.
281-
pub fn ranked(&self) -> impl Iterator<Item = &Participant<Ranked>> {
275+
pub fn ranked(&self) -> impl Iterator<Item = &Bid<Ranked>> {
282276
self.ranked.iter()
283277
}
284278
}
@@ -295,7 +289,7 @@ mod tests {
295289
Price,
296290
order::{self, AppDataHash},
297291
},
298-
competition::{Participant, Solution, TradedOrder, Unscored},
292+
competition::{Bid, Solution, TradedOrder, Unscored},
299293
eth::{self, TokenAddress},
300294
},
301295
infra::Driver,
@@ -998,7 +992,7 @@ mod tests {
998992
// map (solver id -> solver address) for later reference during the test
999993
let mut solver_map = HashMap::new();
1000994

1001-
// map (solution id -> participant) for later reference during the test
995+
// map (solution id -> bid) for later reference during the test
1002996
let mut solution_map = HashMap::new();
1003997
for (solution_id, solution) in &self.solutions {
1004998
// generate solver address deterministically from the id
@@ -1021,13 +1015,13 @@ mod tests {
10211015
let solution_uid = hash(solution_id);
10221016
solution_map.insert(
10231017
solution_id,
1024-
create_solution(solution_uid, solver_address, trades, None).await,
1018+
create_bid(solution_uid, solver_address, trades, None).await,
10251019
);
10261020
}
10271021

10281022
// filter solutions
1029-
let participants = solution_map.values().cloned().collect();
1030-
let ranking = arbitrator.arbitrate(participants, &auction);
1023+
let bids = solution_map.values().cloned().collect();
1024+
let ranking = arbitrator.arbitrate(bids, &auction);
10311025
assert_eq!(ranking.ranked.len(), self.expected_fair_solutions.len());
10321026
for solution_id in &self.expected_fair_solutions {
10331027
let solution_uid = solution_map.get(&solution_id).unwrap().solution().id;
@@ -1199,12 +1193,12 @@ mod tests {
11991193
}
12001194
}
12011195

1202-
async fn create_solution(
1196+
async fn create_bid(
12031197
solution_id: u64,
12041198
solver_address: Address,
12051199
trades: Vec<(OrderUid, TradedOrder)>,
12061200
prices: Option<HashMap<TokenAddress, Price>>,
1207-
) -> Participant<Unscored> {
1201+
) -> Bid<Unscored> {
12081202
// The prices of the tokens do not affect the result but they keys must exist
12091203
// for every token of every trade
12101204
let prices = prices.unwrap_or({
@@ -1230,7 +1224,7 @@ mod tests {
12301224
.await
12311225
.unwrap();
12321226

1233-
Participant::new(solution, std::sync::Arc::new(driver))
1227+
Bid::new(solution, std::sync::Arc::new(driver))
12341228
}
12351229

12361230
fn amount(value: u128) -> String {
@@ -1242,8 +1236,8 @@ mod tests {
12421236
value * 10u128.pow(15)
12431237
}
12441238

1245-
fn filter_winners(solutions: &[Participant]) -> Vec<&Participant> {
1246-
solutions.iter().filter(|s| s.is_winner()).collect()
1239+
fn filter_winners(bids: &[Bid]) -> Vec<&Bid> {
1240+
bids.iter().filter(|b| b.is_winner()).collect()
12471241
}
12481242

12491243
// Used to generate deterministic identifiers (e.g., UIDs, addresses) from

crates/autopilot/src/infra/persistence/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl Persistence {
207207
pub async fn save_solutions(
208208
&self,
209209
auction_id: domain::auction::Id,
210-
solutions: impl Iterator<Item = &domain::competition::Participant>,
210+
solutions: impl Iterator<Item = &domain::competition::Bid>,
211211
) -> Result<(), DatabaseError> {
212212
let _timer = Metrics::get()
213213
.database_queries
@@ -221,17 +221,17 @@ impl Persistence {
221221
auction_id,
222222
&solutions
223223
.enumerate()
224-
.map(|(uid, participant)| {
224+
.map(|(uid, bid)| {
225225
let solution = Solution {
226226
uid: uid.try_into().context("uid overflow")?,
227-
id: u256_to_big_decimal(&participant.solution().id().into()),
228-
solver: ByteArray(participant.solution().solver().0.0),
229-
is_winner: participant.is_winner(),
230-
filtered_out: participant.is_filtered_out(),
227+
id: u256_to_big_decimal(&bid.solution().id().into()),
228+
solver: ByteArray(bid.solution().solver().0.0),
229+
is_winner: bid.is_winner(),
230+
filtered_out: bid.is_filtered_out(),
231231
score: number::conversions::alloy::u256_to_big_decimal(
232-
&participant.score().get().0,
232+
&bid.score().get().0,
233233
),
234-
orders: participant
234+
orders: bid
235235
.solution()
236236
.orders()
237237
.iter()
@@ -254,13 +254,13 @@ impl Persistence {
254254
side: order.side.into(),
255255
})
256256
.collect(),
257-
price_tokens: participant
257+
price_tokens: bid
258258
.solution()
259259
.prices()
260260
.keys()
261261
.map(|token| ByteArray(token.0.0.0))
262262
.collect(),
263-
price_values: participant
263+
price_values: bid
264264
.solution()
265265
.prices()
266266
.values()

0 commit comments

Comments
 (0)