Skip to content

Commit

Permalink
Shared detector
Browse files Browse the repository at this point in the history
  • Loading branch information
squadgazzz committed Dec 20, 2024
1 parent ec35222 commit 4b2de81
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion crates/driver/src/domain/competition/bad_tokens/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {super::Quality, crate::domain::eth, dashmap::DashMap, std::sync::Arc};
/// have participated in at least `REQUIRED_MEASUREMENTS` attempts to be
/// evaluated. If, at that point, the ratio of failures is greater than or equal
/// to `FAILURE_RATIO`, the token is considered unsupported.
#[derive(Default)]
#[derive(Default, Clone)]
pub struct Detector(Arc<Inner>);

#[derive(Default)]
Expand Down
4 changes: 2 additions & 2 deletions crates/driver/src/domain/competition/bad_tokens/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ impl Detector {
}

/// Enables detection of unsupported tokens based on heuristics.
pub fn enable_heuristic_detector(&mut self) -> &mut Self {
self.metrics = Some(metrics::Detector::default());
pub fn with_metrics_detector(&mut self, detector: metrics::Detector) -> &mut Self {
self.metrics = Some(detector);
self
}

Expand Down
6 changes: 4 additions & 2 deletions crates/driver/src/infra/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ impl Api {
app = routes::metrics(app);
app = routes::healthz(app);

let metrics_bad_token_detector = bad_tokens::metrics::Detector::default();

// Multiplex each solver as part of the API. Multiple solvers are multiplexed
// on the same driver so only one liquidity collector collects the liquidity
// for all of them. This is important because liquidity collection is
Expand All @@ -82,9 +84,9 @@ impl Api {

if solver
.bad_token_detection()
.enable_heuristic_based_bad_token_detection
.enable_metrics_based_bad_token_detection
{
bad_tokens.enable_heuristic_detector();
bad_tokens.with_metrics_detector(metrics_bad_token_detector.clone());
}

let router = router.with_state(State(Arc::new(Inner {
Expand Down
2 changes: 1 addition & 1 deletion crates/driver/src/infra/config/file/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub async fn load(chain: chain::Id, path: &Path) -> infra::Config {
.collect(),
enable_simulation_based_bad_token_detection: config
.enable_simulation_bad_token_detection,
enable_heuristic_based_bad_token_detection: config
enable_metrics_based_bad_token_detection: config
.enable_heuristic_based_bad_token_detection,
},
}
Expand Down
2 changes: 1 addition & 1 deletion crates/driver/src/infra/solver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,5 +307,5 @@ pub struct BadTokenDetection {
/// Tokens that are explicitly allow- or deny-listed.
pub tokens_supported: HashMap<eth::TokenAddress, bad_tokens::Quality>,
pub enable_simulation_based_bad_token_detection: bool,
pub enable_heuristic_based_bad_token_detection: bool,
pub enable_metrics_based_bad_token_detection: bool,
}

0 comments on commit 4b2de81

Please sign in to comment.