Skip to content

Commit b8e6d79

Browse files
authored
[EASY] Remove unused code (#2977)
# Description Related to supporting multiple winners per Auction. `get_winning_solution` was initially added to implement part of the circuit breaker functionalities - recover winning solution during competition, make sure the quality of proposed versus delivered solution is respected etc. Since this functionality is not used currently, decided to remove it until circuit breaker is implemented, which resolves to few places less to support multiple settlements. We can easily revert the PR from git history when needed.
1 parent d1458fa commit b8e6d79

File tree

2 files changed

+2
-131
lines changed
  • crates/autopilot/src

2 files changed

+2
-131
lines changed

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

-27
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,10 @@ pub enum Error {
151151
pub enum InconsistentData {
152152
#[error("auction not found in the persistence layer")]
153153
AuctionNotFound,
154-
#[error("proposed solution not found in the persistence layer")]
155-
SolutionNotFound,
156154
#[error("invalid fee policy fetched from persistence layer: {0} for order: {1}")]
157155
InvalidFeePolicy(infra::persistence::dto::fee_policy::Error, domain::OrderUid),
158156
#[error("invalid fetched price from persistence layer for token: {0:?}")]
159157
InvalidPrice(eth::TokenAddress),
160-
#[error(
161-
"invalid score fetched from persistence layer for a coresponding competition solution, \
162-
err: {0}"
163-
)]
164-
InvalidScore(anyhow::Error),
165-
#[error("invalid solver competition data fetched from persistence layer: {0}")]
166-
InvalidSolverCompetition(anyhow::Error),
167158
}
168159

169160
impl From<infra::persistence::error::Auction> for Error {
@@ -183,24 +174,6 @@ impl From<infra::persistence::error::Auction> for Error {
183174
}
184175
}
185176

186-
impl From<infra::persistence::error::Solution> for Error {
187-
fn from(err: infra::persistence::error::Solution) -> Self {
188-
match err {
189-
infra::persistence::error::Solution::DatabaseError(err) => Self::Infra(err.into()),
190-
infra::persistence::error::Solution::NotFound => {
191-
Self::InconsistentData(InconsistentData::SolutionNotFound)
192-
}
193-
infra::persistence::error::Solution::InvalidScore(err) => {
194-
Self::InconsistentData(InconsistentData::InvalidScore(err))
195-
}
196-
infra::persistence::error::Solution::InvalidSolverCompetition(err) => {
197-
Self::InconsistentData(InconsistentData::InvalidSolverCompetition(err))
198-
}
199-
infra::persistence::error::Solution::InvalidPrice(_) => todo!(),
200-
}
201-
}
202-
}
203-
204177
impl From<infra::persistence::DatabaseError> for Error {
205178
fn from(err: infra::persistence::DatabaseError) -> Self {
206179
Self::Infra(err.0)

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

+2-104
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use {
22
crate::{
33
boundary,
44
database::{order_events::store_order_events, Postgres},
5-
domain::{self, competition, eth},
5+
domain::{self, eth},
66
infra::persistence::dto::AuctionId,
77
},
88
anyhow::Context,
@@ -26,7 +26,7 @@ use {
2626
},
2727
futures::{StreamExt, TryStreamExt},
2828
number::conversions::{big_decimal_to_u256, u256_to_big_decimal, u256_to_big_uint},
29-
primitive_types::{H160, H256},
29+
primitive_types::H256,
3030
shared::db_order_conversions::full_order_into_model_order,
3131
std::{
3232
collections::{HashMap, HashSet},
@@ -313,94 +313,6 @@ impl Persistence {
313313
})
314314
}
315315

316-
/// Returns the proposed solver solution that won the competition for a
317-
/// given auction.
318-
///
319-
/// It is expected for a solution to exist, so missing data is considered an
320-
/// error.
321-
///
322-
/// Returns error for old non-colocated auctions.
323-
pub async fn get_winning_solution(
324-
&self,
325-
auction_id: domain::auction::Id,
326-
) -> Result<domain::competition::Solution, error::Solution> {
327-
let _timer = Metrics::get()
328-
.database_queries
329-
.with_label_values(&["get_competition_winner"])
330-
.start_timer();
331-
332-
let mut ex = self
333-
.postgres
334-
.pool
335-
.begin()
336-
.await
337-
.map_err(error::Solution::DatabaseError)?;
338-
339-
let competition = database::settlement_scores::fetch(&mut ex, auction_id)
340-
.await
341-
.map_err(error::Solution::DatabaseError)?
342-
.ok_or(error::Solution::NotFound)?;
343-
344-
let winner = H160(competition.winner.0).into();
345-
let score = competition::Score::new(
346-
big_decimal_to_u256(&competition.winning_score)
347-
.ok_or(error::Solution::InvalidScore(anyhow::anyhow!(
348-
"database score"
349-
)))?
350-
.into(),
351-
)
352-
.map_err(|err| error::Solution::InvalidScore(anyhow::anyhow!("score, {}", err)))?;
353-
354-
let solution = {
355-
// TODO: stabilize the solver competition table to get promised solution.
356-
let solver_competition = database::solver_competition::load_by_id(&mut ex, auction_id)
357-
.await
358-
.map_err(error::Solution::DatabaseError)?
359-
.ok_or(error::Solution::NotFound)?;
360-
let competition: model::solver_competition::SolverCompetitionDB =
361-
serde_json::from_value(solver_competition.json)
362-
.context("deserialize SolverCompetitionDB")
363-
.map_err(error::Solution::InvalidSolverCompetition)?;
364-
let winning_solution = competition
365-
.solutions
366-
.last()
367-
.ok_or(error::Solution::NotFound)?;
368-
let mut orders = HashMap::new();
369-
for order in winning_solution.orders.iter() {
370-
match order {
371-
model::solver_competition::Order::Colocated {
372-
id,
373-
sell_amount,
374-
buy_amount,
375-
} => {
376-
orders.insert(
377-
domain::OrderUid(id.0),
378-
competition::TradedAmounts {
379-
sell: (*sell_amount).into(),
380-
buy: (*buy_amount).into(),
381-
},
382-
);
383-
}
384-
model::solver_competition::Order::Legacy {
385-
id: _,
386-
executed_amount: _,
387-
} => return Err(error::Solution::NotFound),
388-
}
389-
}
390-
let mut prices = HashMap::new();
391-
for (token, price) in winning_solution.clearing_prices.clone().into_iter() {
392-
prices.insert(
393-
token.into(),
394-
domain::auction::Price::new(price.into())
395-
.map_err(|_| error::Solution::InvalidPrice(eth::TokenAddress(token)))?,
396-
);
397-
}
398-
competition::Solution::new(winner, score, orders, prices)
399-
};
400-
401-
Ok(solution)
402-
}
403-
404316
/// Computes solvable orders based on the latest observed block number,
405317
/// order creation timestamp, and minimum validity period.
406318
pub async fn solvable_orders_after(
@@ -746,18 +658,4 @@ pub mod error {
746658
#[error("invalid price fetched from database for token: {0:?}")]
747659
InvalidPrice(eth::TokenAddress),
748660
}
749-
750-
#[derive(Debug, thiserror::Error)]
751-
pub enum Solution {
752-
#[error("failed communication with the database: {0}")]
753-
DatabaseError(#[from] sqlx::Error),
754-
#[error("solution not found")]
755-
NotFound,
756-
#[error("invalid score fetched from database: {0}")]
757-
InvalidScore(anyhow::Error),
758-
#[error("invalid price fetched from database for token: {0:?}")]
759-
InvalidPrice(eth::TokenAddress),
760-
#[error("invalid solver competition data fetched from database: {0}")]
761-
InvalidSolverCompetition(anyhow::Error),
762-
}
763661
}

0 commit comments

Comments
 (0)