Skip to content

Commit

Permalink
[EASY] Drop solvable orders cache update background task (#3026)
Browse files Browse the repository at this point in the history
The code is not used anymore since this is now a part of the maintenance
task.
  • Loading branch information
squadgazzz authored Oct 1, 2024
1 parent af9d499 commit 7229d93
Showing 1 changed file with 1 addition and 61 deletions.
62 changes: 1 addition & 61 deletions crates/autopilot/src/solvable_orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use {
anyhow::{Context, Result},
bigdecimal::BigDecimal,
database::order_events::OrderEventLabel,
ethrpc::block_stream::CurrentBlockWatcher,
futures::{future::join_all, FutureExt},
indexmap::IndexSet,
itertools::{Either, Itertools},
Expand All @@ -32,12 +31,11 @@ use {
std::{
collections::{btree_map::Entry, BTreeMap, HashMap, HashSet},
future::Future,
sync::{Arc, Weak},
sync::Arc,
time::Duration,
},
strum::VariantNames,
tokio::{sync::Mutex, time::Instant},
tracing::Instrument,
};

#[derive(prometheus_metric_storage::MetricStorage)]
Expand Down Expand Up @@ -137,19 +135,6 @@ impl SolvableOrdersCache {
self_
}

/// Spawns a task that periodically updates the set of open orders
/// and builds a new auction with them.
pub fn spawn_background_task(
cache: &Arc<Self>,
block_stream: CurrentBlockWatcher,
update_interval: Duration,
) {
tokio::task::spawn(
update_task(Arc::downgrade(cache), update_interval, block_stream)
.instrument(tracing::info_span!("solvable_orders_cache")),
);
}

pub async fn current_auction(&self) -> Option<domain::RawAuctionData> {
self.cache
.lock()
Expand Down Expand Up @@ -569,51 +554,6 @@ fn filter_dust_orders(mut orders: Vec<Order>, balances: &Balances) -> Vec<Order>
orders
}

/// Keep updating the cache every N seconds or when an update notification
/// happens. Exits when this becomes the only reference to the cache.
async fn update_task(
cache: Weak<SolvableOrdersCache>,
update_interval: Duration,
current_block: CurrentBlockWatcher,
) {
loop {
// We are not updating on block changes because
// - the state of orders could change even when the block does not like when an
// order gets cancelled off chain
// - the event updater takes some time to run and if we go first we would not
// update the orders with the most recent events.
let start = Instant::now();
let cache = match cache.upgrade() {
Some(self_) => self_,
None => {
tracing::debug!("exiting solvable orders update task");
break;
}
};
let block = current_block.borrow().number;
match cache.update(block).await {
Ok(()) => {
cache.track_auction_update("success");
tracing::debug!(
%block,
"updated solvable orders in {}s",
start.elapsed().as_secs_f32()
)
}
Err(err) => {
cache.track_auction_update("failure");
tracing::warn!(
?err,
%block,
"failed to update solvable orders in {}s",
start.elapsed().as_secs_f32()
)
}
}
tokio::time::sleep_until(start + update_interval).await;
}
}

async fn get_orders_with_native_prices(
orders: Vec<Order>,
native_price_estimator: &CachingNativePriceEstimator,
Expand Down

0 comments on commit 7229d93

Please sign in to comment.