Skip to content

Commit

Permalink
Respect deadline in solvers crate (#1751)
Browse files Browse the repository at this point in the history
Progress on #1672

Fixes #1664
  • Loading branch information
sunce86 authored Aug 11, 2023
1 parent d8dc807 commit 3f2c71d
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions crates/solvers/src/domain/solver/dex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,27 @@ impl Dex {
// * order prioritization
// * skip liquidity orders
// * concurrency
// * respecting auction deadline

let mut solutions = Vec::new();
for order in auction.orders.iter().cloned() {
let span = tracing::info_span!("solve", order = %order.uid);
if let Some(solution) = self
.solve_order(order, &auction.tokens, auction.gas_price)
.instrument(span)
.await
{
solutions.push(solution);
let solve_orders = async {
for order in auction.orders.iter().cloned() {
let span = tracing::info_span!("solve", order = %order.uid);
if let Some(solution) = self
.solve_order(order, &auction.tokens, auction.gas_price)
.instrument(span)
.await
{
solutions.push(solution);
}
}
};
let deadline = auction
.deadline
.signed_duration_since(chrono::offset::Utc::now())
.to_std()
.unwrap_or_default();
if tokio::time::timeout(deadline, solve_orders).await.is_err() {
tracing::debug!("reached deadline; stopping to solve");
}

self.fills.collect_garbage();
Expand Down

0 comments on commit 3f2c71d

Please sign in to comment.