-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description Tackles checkboxes 1 and 2 from #2041 (comment) ![timeouts](https://github.com/cowprotocol/services/assets/19595624/0f7490e7-6c36-4278-bbcf-9a4ca0f91f1a) # Changes This is my attempt to make timeouts more explicit and clear. First, we split the deadline given to driver into 3 pieces: 1. Solving time given to solvers 2. Competition time, used to validate, merge, simulate, score and rank solutions. 3. Http delay, to cover potential slow propagating of http response back to autopilot (`http_delay`) The time is split in a following way: competition time and http delay are values read from the configuration (so hardcoded), while the solving time is whatever is left after deducting those two from the deadline given to driver. It's important to note that: 1. Http delay is reduced from driver deadline at the very beginning of the solve/quote handling, because it's a non-domain information. Core domain logic doesn't care about network delays. 2. Competition time is reduced from deadline in the domain, because how we split given time to solving and competition is actually domain related. For some solvers we want 19s for solving and 1s for competition, while for some others like Baseline, we might want 10s for solving and 10s for competition. Default values are set to something like: /solve: 20s given to driver, http delay is 0.5s, competition is 4.5s, solving time 15s /quote: 3s given to driver, http delay is 0.5s, competition time 1s, solving time 1.5s Release notes: check the default timeouts and if they need to be adjusted.
- Loading branch information
Showing
17 changed files
with
224 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use { | ||
crate::infra::{ | ||
solver::Timeouts, | ||
{self}, | ||
}, | ||
thiserror::Error, | ||
}; | ||
|
||
/// Deadlines for different parts of the driver execution. | ||
/// The driver is expected to return the solution to the autopilot before the | ||
/// driver deadline. | ||
/// The solvers are expected to return the solution to the driver before the | ||
/// solvers deadline. | ||
#[derive(Copy, Clone, Debug, Default)] | ||
pub struct Deadline { | ||
driver: chrono::DateTime<chrono::Utc>, | ||
solvers: chrono::DateTime<chrono::Utc>, | ||
} | ||
|
||
impl Deadline { | ||
pub fn new(deadline: chrono::DateTime<chrono::Utc>, timeouts: Timeouts) -> Self { | ||
let deadline = deadline - timeouts.http_delay; | ||
Self { | ||
driver: deadline, | ||
solvers: { | ||
let now = infra::time::now(); | ||
let duration = deadline - now; | ||
now + duration * (timeouts.solving_share_of_deadline.get() * 100.0).round() as i32 | ||
/ 100 | ||
}, | ||
} | ||
} | ||
|
||
/// Remaining time until the deadline for driver to return solution to | ||
/// autopilot is reached. | ||
pub fn driver(self) -> Result<chrono::Duration, DeadlineExceeded> { | ||
Self::remaining(self.driver) | ||
} | ||
|
||
/// Remaining time until the deadline for solvers to return solution to | ||
/// driver is reached. | ||
pub fn solvers(self) -> Result<chrono::Duration, DeadlineExceeded> { | ||
Self::remaining(self.solvers) | ||
} | ||
|
||
fn remaining( | ||
deadline: chrono::DateTime<chrono::Utc>, | ||
) -> Result<chrono::Duration, DeadlineExceeded> { | ||
let deadline = deadline - infra::time::now(); | ||
if deadline <= chrono::Duration::zero() { | ||
Err(DeadlineExceeded) | ||
} else { | ||
Ok(deadline) | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Error)] | ||
#[error("the deadline has been exceeded")] | ||
pub struct DeadlineExceeded; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.