From 9701fc79619b7fae5eaffe3e199e817b1042a7bf Mon Sep 17 00:00:00 2001 From: Dusan Stanivukovic Date: Fri, 24 Nov 2023 12:24:36 +0100 Subject: [PATCH] Don't send empty solutions to the driver (#2076) # Description I don't find empty solutions useful in driver/solvers communication. Currently, all solvers except legacy solvers return empty vector when they can't find a solution, while legacy sends empty solution: https://production-6de61f.kb.eu-central-1.aws.cloud.es.io/app/r/s/ldj1i I find it hard to read. Solvers should be consistent. This PR changes legacy solver to send no solutions to the driver. I still we should still keep the proper handling of empty solutions in the `driver` since we won't control the solvers forever. --- crates/solvers/src/domain/solution.rs | 4 ++++ crates/solvers/src/domain/solver/legacy.rs | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/solvers/src/domain/solution.rs b/crates/solvers/src/domain/solution.rs index 931755e9e7..216b54cf1a 100644 --- a/crates/solvers/src/domain/solution.rs +++ b/crates/solvers/src/domain/solution.rs @@ -112,6 +112,10 @@ impl Solution { self } + + pub fn is_empty(&self) -> bool { + self.prices.0.is_empty() && self.trades.is_empty() && self.interactions.is_empty() + } } /// A solution for a settling a single order. diff --git a/crates/solvers/src/domain/solver/legacy.rs b/crates/solvers/src/domain/solver/legacy.rs index 1ae641ef1b..cfc55edf8d 100644 --- a/crates/solvers/src/domain/solver/legacy.rs +++ b/crates/solvers/src/domain/solver/legacy.rs @@ -29,7 +29,13 @@ impl Legacy { pub async fn solve(&self, auction: auction::Auction) -> Vec { match self.0.solve(&auction).await { - Ok(solution) => vec![solution.with_id(solution::Id(0))], + Ok(solution) => { + if solution.is_empty() { + vec![] + } else { + vec![solution] + } + } Err(err) => { tracing::warn!(?err, "failed to solve auction"); if err.is_timeout() {