Skip to content

Commit

Permalink
Make times between auction run_loops configurable (#1994)
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
fleupold authored Oct 20, 2023
1 parent f63fa1b commit addef7a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions crates/autopilot/src/run_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit addef7a

Please sign in to comment.