diff --git a/Cargo.lock b/Cargo.lock index c49cccb..3049b1f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1753,6 +1753,22 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "humantime-serde" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57a3db5ea5923d99402c94e9feb261dc5ee9b4efa158b0315f788cf549cc200c" +dependencies = [ + "humantime", + "serde", +] + [[package]] name = "hyper" version = "0.14.27" @@ -3386,6 +3402,8 @@ dependencies = [ "futures", "glob", "hex", + "humantime", + "humantime-serde", "hyper", "itertools 0.11.0", "num", diff --git a/Cargo.toml b/Cargo.toml index 351b321..30e039a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,8 @@ clap = { version = "4", features = ["derive", "env"] } ethereum-types = "0.14" futures = "0.3" hex = "0.4" +humantime = "2.1.0" +humantime-serde = "1.1.1" hyper = "0.14" itertools = "0.11" num = "0.4" diff --git a/src/infra/config/dex/file.rs b/src/infra/config/dex/file.rs index 2449543..aafcbec 100644 --- a/src/infra/config/dex/file.rs +++ b/src/infra/config/dex/file.rs @@ -54,12 +54,12 @@ struct Config { back_off_growth_factor: f64, /// Minimum back-off time in seconds for rate limiting. - #[serde(default = "default_min_back_off")] - min_back_off: u64, + #[serde(with = "humantime_serde", default = "default_min_back_off")] + min_back_off: Duration, /// Maximum back-off time in seconds for rate limiting. - #[serde(default = "default_max_back_off")] - max_back_off: u64, + #[serde(with = "humantime_serde", default = "default_max_back_off")] + max_back_off: Duration, /// Settings specific to the wrapped dex API. dex: toml::Value, @@ -81,12 +81,12 @@ fn default_back_off_growth_factor() -> f64 { 2.0 } -fn default_min_back_off() -> u64 { - 1 +fn default_min_back_off() -> Duration { + Duration::from_secs(1) } -fn default_max_back_off() -> u64 { - 8 +fn default_max_back_off() -> Duration { + Duration::from_secs(8) } /// Loads the base solver configuration from a TOML file. @@ -144,8 +144,8 @@ pub async fn load(path: &Path) -> (super::Config, T) { }, rate_limiting_strategy: RateLimitingStrategy::try_new( config.back_off_growth_factor, - Duration::from_secs(config.min_back_off), - Duration::from_secs(config.max_back_off), + config.min_back_off, + config.max_back_off, ) .unwrap(), };