From addef7acbdd8671d4f5a41f937be207b6be5938e Mon Sep 17 00:00:00 2001 From: Felix Leupold Date: Fri, 20 Oct 2023 13:00:57 +0200 Subject: [PATCH] Make times between auction run_loops configurable (#1994) # Description We were made aware that we are currently sending *a lot* of auctions on xdai staging. This is because the auctions are mainly empty (or solvers quickly return an empty solution) and then our run_loop sleeps for a hardcoded amount of 1s, which is way to short. This PR makes this value configurable. It reuses the existing `auction_update_interval` which decides how often we prepare a new auction. Maybe this value should be separate, but at least we shouldn't dispatch auctions more often than we update them (otherwise we may dispatch the same auction multiple times which is likely not going to change the outcome) # Changes - Make the sleep between run_loops configurable - Deduct the time the run loop has take from this value to make sure we don't wait for a long time if a solution was found and mined ## How to test Run autopilot on an empty orderbook. See new auctions are now created much slower than before --- crates/autopilot/src/run_loop.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/autopilot/src/run_loop.rs b/crates/autopilot/src/run_loop.rs index b3e4be06a5..c784ee09e9 100644 --- a/crates/autopilot/src/run_loop.rs +++ b/crates/autopilot/src/run_loop.rs @@ -64,11 +64,19 @@ pub struct RunLoop { impl RunLoop { pub async fn run_forever(self) -> ! { + let mut last_auction_id = None; + let mut last_block = None; loop { if let Some(AuctionWithId { id, auction }) = self.next_auction().await { - self.single_run(id, &auction) - .instrument(tracing::info_span!("auction", id)) - .await; + let current_block = self.current_block.borrow().hash; + // Only run the solvers if the auction or block has changed. + if last_auction_id.replace(id) != Some(id) + || last_block.replace(current_block) != Some(current_block) + { + self.single_run(id, &auction) + .instrument(tracing::info_span!("auction", id)) + .await; + } }; tokio::time::sleep(Duration::from_secs(1)).await; }