Skip to content

Commit

Permalink
Migrate to humantime (#2194)
Browse files Browse the repository at this point in the history
# Description
Fully closes the #2085.
Since DEX solvers are about to migrate to a separate repo, it's a good
time to change the config format. It will be much more difficult later.

# Changes
Use `humantime` to parse `Duration` config params.

## How to test
e2e + staging

## Related Issues

Fixes #2085
  • Loading branch information
squadgazzz authored Dec 21, 2023
1 parent b6510bb commit fc018fb
Show file tree
Hide file tree
Showing 35 changed files with 222 additions and 229 deletions.
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ futures = "0.3"
gas-estimation = { git = "https://github.com/cowprotocol/gas-estimation", tag = "v0.7.3", features = ["web3_", "tokio_"] }
hex = { version = "0.4", default-features = false }
hex-literal = "0.4"
humantime = "2.1.0"
humantime-serde = "1.1.1"
itertools = "0.11"
lazy_static = "1"
maplit = "1"
Expand Down
1 change: 1 addition & 0 deletions crates/alerter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license = "MIT OR Apache-2.0"
anyhow = { workspace = true }
chrono = { workspace = true }
clap = { workspace = true }
humantime = { workspace = true }
observe = { path = "../observe" }
model = { path = "../model" }
number = { path = "../number" }
Expand Down
18 changes: 9 additions & 9 deletions crates/alerter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,35 +329,35 @@ struct Arguments {
#[clap(
long,
env,
default_value = "30",
value_parser = shared::arguments::duration_from_seconds,
default_value = "30s",
value_parser = humantime::parse_duration,
)]
update_interval: Duration,

/// Minimum time without a trade before alerting.
#[clap(
long,
env,
default_value = "600",
value_parser = shared::arguments::duration_from_seconds,
default_value = "10m",
value_parser = humantime::parse_duration,
)]
time_without_trade: Duration,

/// Minimum time an order must have been matchable for before alerting.
#[clap(
long,
env,
default_value = "180",
value_parser = shared::arguments::duration_from_seconds,
default_value = "3m",
value_parser = humantime::parse_duration,
)]
min_order_age: Duration,

/// Do not repeat the alert more often than this.
#[clap(
long,
env,
default_value = "1800",
value_parser = shared::arguments::duration_from_seconds,
default_value = "30m",
value_parser = humantime::parse_duration,
)]
min_alert_interval: Duration,

Expand All @@ -374,7 +374,7 @@ struct Arguments {

/// Minimum time between get order requests to the api. Without this the api
/// can rate limit us.
#[clap(long, env, default_value = "0.2", value_parser = shared::arguments::duration_from_seconds)]
#[clap(long, env, default_value = "200ms", value_parser = humantime::parse_duration)]
api_get_order_min_interval: Duration,

#[clap(long, env)]
Expand Down
1 change: 1 addition & 0 deletions crates/autopilot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ gas-estimation = { workspace = true }
observe = { path = "../observe" }
hex = { workspace = true }
hex-literal = { workspace = true }
humantime = { workspace = true }
itertools = { workspace = true }
maplit = { workspace = true }
model = { path = "../model" }
Expand Down
48 changes: 19 additions & 29 deletions crates/autopilot/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ use {
http_client,
price_estimation::{self, NativePriceEstimators},
},
std::{
net::SocketAddr,
num::{NonZeroUsize, ParseFloatError},
str::FromStr,
time::Duration,
},
std::{net::SocketAddr, num::NonZeroUsize, str::FromStr, time::Duration},
url::Url,
};

Expand Down Expand Up @@ -74,13 +69,13 @@ pub struct Arguments {
#[clap(long, env, use_value_delimiter = true)]
pub unsupported_tokens: Vec<H160>,

/// The amount of time in seconds a classification of a token into good or
/// The amount of time a classification of a token into good or
/// bad is valid for.
#[clap(
long,
env,
default_value = "600",
value_parser = shared::arguments::duration_from_seconds,
default_value = "10m",
value_parser = humantime::parse_duration,
)]
pub token_quality_cache_expiry: Duration,

Expand All @@ -102,12 +97,12 @@ pub struct Arguments {
#[clap(long, env, default_value = "2")]
pub native_price_estimation_results_required: NonZeroUsize,

/// The minimum amount of time in seconds an order has to be valid for.
/// The minimum amount of time an order has to be valid for.
#[clap(
long,
env,
default_value = "60",
value_parser = shared::arguments::duration_from_seconds,
default_value = "1m",
value_parser = humantime::parse_duration,
)]
pub min_order_validity_period: Duration,

Expand All @@ -120,16 +115,16 @@ pub struct Arguments {
#[clap(
long,
env,
default_value = "300",
value_parser = shared::arguments::duration_from_seconds,
default_value = "5m",
value_parser = humantime::parse_duration,
)]
pub max_auction_age: Duration,

#[clap(long, env, default_value = "0")]
pub limit_order_price_factor: f64,

/// The time between auction updates.
#[clap(long, env, default_value = "10", value_parser = shared::arguments::duration_from_seconds)]
#[clap(long, env, default_value = "10s", value_parser = humantime::parse_duration)]
pub auction_update_interval: Duration,

/// Fee scaling factor for objective value. This controls the constant
Expand All @@ -153,8 +148,8 @@ pub struct Arguments {
#[clap(
long,
env,
default_value = "3600",
value_parser = shared::arguments::duration_from_seconds,
default_value = "1h",
value_parser = humantime::parse_duration,
)]
pub trusted_tokens_update_interval: Duration,

Expand Down Expand Up @@ -188,8 +183,8 @@ pub struct Arguments {
#[clap(
long,
env,
default_value = "60",
value_parser = shared::arguments::duration_from_seconds,
default_value = "1m",
value_parser = humantime::parse_duration,
)]
pub max_settlement_transaction_wait: Duration,

Expand All @@ -204,12 +199,12 @@ pub struct Arguments {
#[clap(long, env)]
pub shadow: Option<Url>,

/// Time in seconds solvers have to compute a score per auction.
/// Time solvers have to compute a score per auction.
#[clap(
long,
env,
default_value = "15",
value_parser = shared::arguments::duration_from_seconds,
default_value = "15s",
value_parser = humantime::parse_duration,
)]
pub solve_deadline: Duration,

Expand All @@ -219,12 +214,12 @@ pub struct Arguments {

/// Time interval in days between each cleanup operation of the
/// `order_events` database table.
#[clap(long, env, default_value = "1", value_parser = duration_from_days)]
#[clap(long, env, default_value = "1d", value_parser = humantime::parse_duration)]
pub order_events_cleanup_interval: Duration,

/// Age threshold in days for order events to be eligible for cleanup in the
/// `order_events` database table.
#[clap(long, env, default_value = "30", value_parser = duration_from_days)]
#[clap(long, env, default_value = "30d", value_parser = humantime::parse_duration)]
pub order_events_cleanup_threshold: Duration,
}

Expand Down Expand Up @@ -374,8 +369,3 @@ impl FromStr for FeePolicyKind {
}
}
}

fn duration_from_days(s: &str) -> Result<Duration, ParseFloatError> {
let days = s.parse::<f64>()?;
Ok(Duration::from_secs_f64(days * 86_400.0))
}
8 changes: 4 additions & 4 deletions crates/autopilot/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub async fn run(args: Arguments) {
number_of_entries_to_auto_update: args.pool_cache_lru_size,
maximum_recent_block_age: args.shared.pool_cache_maximum_recent_block_age,
max_retries: args.shared.pool_cache_maximum_retries,
delay_between_retries: args.shared.pool_cache_delay_between_retries_seconds,
delay_between_retries: args.shared.pool_cache_delay_between_retries,
};
let pool_fetcher = Arc::new(
PoolCache::new(
Expand Down Expand Up @@ -481,15 +481,15 @@ pub async fn run(args: Arguments) {
Arc::new(db.clone()),
order_quoting::Validity {
eip1271_onchain_quote: chrono::Duration::from_std(
args.order_quoting.eip1271_onchain_quote_validity_seconds,
args.order_quoting.eip1271_onchain_quote_validity,
)
.unwrap(),
presign_onchain_quote: chrono::Duration::from_std(
args.order_quoting.presign_onchain_quote_validity_seconds,
args.order_quoting.presign_onchain_quote_validity,
)
.unwrap(),
standard_quote: chrono::Duration::from_std(
args.order_quoting.standard_offchain_quote_validity_seconds,
args.order_quoting.standard_offchain_quote_validity,
)
.unwrap(),
},
Expand Down
2 changes: 2 additions & 0 deletions crates/driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ ethrpc = { path = "../ethrpc" }
futures = "0.3"
hex = "0.4"
hex-literal = "0.4"
humantime = { workspace = true }
humantime-serde = { workspace = true }
hyper = "0.14"
lazy_static = { workspace = true }
indexmap = { version = "2", features = ["serde"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/driver/src/boundary/liquidity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Fetcher {
/// Creates a new fetcher for the specified configuration.
pub async fn new(eth: &Ethereum, config: &infra::liquidity::Config) -> Result<Self> {
let blocks = current_block::Arguments {
block_stream_poll_interval_seconds: BLOCK_POLL_INTERVAL,
block_stream_poll_interval: BLOCK_POLL_INTERVAL,
};

let block_stream = blocks.stream(boundary::web3(eth)).await?;
Expand Down
Loading

0 comments on commit fc018fb

Please sign in to comment.