Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/autopilot/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ pub struct Arguments {
/// and not cut any auctions.
#[clap(long, env, default_value = "false", action = clap::ArgAction::Set)]
pub enable_leader_lock: bool,

/// Limits the amount of time the autopilot may spend running the
/// maintenance logic between 2 auctions. When this times out we prefer
/// running a not fully updated auction over stalling the protocol any
/// further.
#[clap(long, env, default_value = "5s", value_parser = humantime::parse_duration)]
pub max_maintenance_timeout: Duration,
}

#[derive(Debug, clap::Parser)]
Expand Down Expand Up @@ -399,6 +406,7 @@ impl std::fmt::Display for Arguments {
disable_1271_order_balance_filter,
disable_1271_order_sig_filter,
enable_leader_lock,
max_maintenance_timeout,
} = self;

write!(f, "{shared}")?;
Expand Down Expand Up @@ -481,6 +489,7 @@ impl std::fmt::Display for Arguments {
"disable_1271_order_sig_filter: {disable_1271_order_sig_filter}"
)?;
writeln!(f, "enable_leader_lock: {enable_leader_lock}")?;
writeln!(f, "max_maintenance_timeout: {max_maintenance_timeout:?}")?;
Ok(())
}
}
Expand Down
16 changes: 14 additions & 2 deletions crates/autopilot/src/maintenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ use {
core::{AtomicU64, GenericGauge},
},
shared::{event_handling::AlloyEventRetriever, maintenance::Maintaining},
std::{future::Future, sync::Arc, time::Instant},
std::{
future::Future,
sync::Arc,
time::{Duration, Instant},
},
tokio::sync::Mutex,
};

Expand All @@ -36,18 +40,25 @@ pub struct Maintenance {
cow_amm_indexer: Vec<Arc<dyn Maintaining>>,
/// On which block we last ran an update successfully.
last_processed: Mutex<BlockInfo>,
/// Limits the amount of time the autopilot may spend running the
/// maintenance logic between 2 auctions. When this times out we prefer
/// running a not fully updated auction over stalling the protocol any
/// further.
timeout: Duration,
}

impl Maintenance {
pub fn new(
settlement_indexer: EventUpdater<Indexer, AlloyEventRetriever<GPv2SettlementContract>>,
db_cleanup: Postgres,
timeout: Duration,
) -> Self {
Self {
settlement_indexer,
db_cleanup,
cow_amm_indexer: Default::default(),
last_processed: Default::default(),
timeout,
}
}

Expand All @@ -62,7 +73,8 @@ impl Maintenance {
}

let start = Instant::now();
if let Err(err) = self.update_inner().await {

if let Err(err) = tokio::time::timeout(self.timeout, self.update_inner()).await {
tracing::warn!(?err, block = new_block.number, "failed to run maintenance");
metrics().updates.with_label_values(&["error"]).inc();
return;
Expand Down
6 changes: 5 additions & 1 deletion crates/autopilot/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,11 @@ pub async fn run(args: Arguments, shutdown_controller: ShutdownController) {
let trusted_tokens =
AutoUpdatingTokenList::from_configuration(market_makable_token_list_configuration).await;

let mut maintenance = Maintenance::new(settlement_event_indexer, db_write.clone());
let mut maintenance = Maintenance::new(
settlement_event_indexer,
db_write.clone(),
args.max_maintenance_timeout,
);
maintenance.with_cow_amms(&cow_amm_registry);

if !args.ethflow_contracts.is_empty() {
Expand Down
Loading