From 15bbdb1ab903fc860556021ebf962ae2c0247d52 Mon Sep 17 00:00:00 2001 From: Lorenzo Delgado Date: Mon, 19 Feb 2024 16:22:10 +0100 Subject: [PATCH] chore(indexer-selection): remove dependency on toolshed crate --- Cargo.lock | 127 +++++++++++++---------------------- indexer-selection/Cargo.toml | 3 +- indexer-selection/src/lib.rs | 58 +++++++++++++--- 3 files changed, 98 insertions(+), 90 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7904ead..c300291 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,21 +12,6 @@ dependencies = [ "regex", ] -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "aho-corasick" version = "1.1.2" @@ -143,7 +128,7 @@ dependencies = [ "ark-std 0.4.0", "derivative", "digest 0.10.7", - "itertools", + "itertools 0.10.5", "num-bigint", "num-traits", "paste", @@ -373,21 +358,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "backtrace" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - [[package]] name = "base16ct" version = "0.2.0" @@ -591,6 +561,29 @@ dependencies = [ "typenum", ] +[[package]] +name = "custom_debug" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14e715bf0e503e909c7076c052e39dd215202e8edeb32f1c194fd630c314d256" +dependencies = [ + "custom_debug_derive", +] + +[[package]] +name = "custom_debug_derive" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f731440b39c73910e253cb465ec1fac97732b3c7af215639881ec0c2a38f4f69" +dependencies = [ + "darling", + "itertools 0.12.1", + "proc-macro2", + "quote", + "syn 2.0.49", + "synstructure", +] + [[package]] name = "darling" version = "0.20.6" @@ -979,12 +972,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - [[package]] name = "group" version = "0.13.0" @@ -1151,10 +1138,11 @@ name = "indexer-selection" version = "0.1.0" dependencies = [ "candidate-selection", + "custom_debug", "proptest", "rand", "thegraph", - "toolshed", + "url", ] [[package]] @@ -1188,6 +1176,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.10" @@ -1278,15 +1275,6 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - [[package]] name = "multer" version = "3.0.0" @@ -1362,15 +1350,6 @@ dependencies = [ "syn 2.0.49", ] -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - [[package]] name = "once_cell" version = "1.19.0" @@ -1780,12 +1759,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e666a5496a0b2186dbcd0ff6106e29e093c15591bde62c20d3842007c6978a09" -[[package]] -name = "rustc-demangle" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" - [[package]] name = "rustc-hex" version = "2.1.0" @@ -2138,6 +2111,17 @@ dependencies = [ "syn 2.0.49", ] +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.49", +] + [[package]] name = "tap" version = "1.0.1" @@ -2248,16 +2232,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" -[[package]] -name = "tokio" -version = "1.36.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" -dependencies = [ - "backtrace", - "pin-project-lite", -] - [[package]] name = "toml_datetime" version = "0.6.5" @@ -2297,15 +2271,6 @@ dependencies = [ "winnow", ] -[[package]] -name = "toolshed" -version = "0.5.0" -source = "git+https://github.com/edgeandnode/toolshed?tag=toolshed-v0.5.0#211f7d7c4ede10f35b6ebd123a4d3ec8342c9f5e" -dependencies = [ - "tokio", - "url", -] - [[package]] name = "typenum" version = "1.17.0" diff --git a/indexer-selection/Cargo.toml b/indexer-selection/Cargo.toml index 924d619..2ecdd94 100644 --- a/indexer-selection/Cargo.toml +++ b/indexer-selection/Cargo.toml @@ -5,9 +5,10 @@ edition = "2021" [dependencies] candidate-selection = { path = "../candidate-selection" } +custom_debug = "0.6.1" rand = { version = "0.8.5", default-features = false } thegraph = { git = "https://github.com/edgeandnode/toolshed", tag = "thegraph-v0.6.0" } -toolshed = { git = "https://github.com/edgeandnode/toolshed", tag = "toolshed-v0.5.0" } +url = "2.5.0" [dev-dependencies] proptest = "1.4.0" diff --git a/indexer-selection/src/lib.rs b/indexer-selection/src/lib.rs index f6b8c44..480c99b 100644 --- a/indexer-selection/src/lib.rs +++ b/indexer-selection/src/lib.rs @@ -1,19 +1,24 @@ -#[cfg(test)] -mod test; - -use candidate_selection::criteria::performance::expected_value_probabilities; -pub use candidate_selection::criteria::performance::{ExpectedPerformance, Performance}; -pub use candidate_selection::{ArrayVec, Normalized}; use std::collections::hash_map::DefaultHasher; use std::f64::consts::E; +use std::fmt::Display; use std::hash::{Hash as _, Hasher as _}; + +use custom_debug::CustomDebug; use thegraph::types::{Address, DeploymentId}; -use toolshed::url::Url; +use url::Url; + +pub use candidate_selection::{ArrayVec, Normalized}; +pub use candidate_selection::criteria::performance::{ExpectedPerformance, Performance}; +use candidate_selection::criteria::performance::expected_value_probabilities; -#[derive(Debug)] +#[cfg(test)] +mod test; + +#[derive(CustomDebug)] pub struct Candidate { pub indexer: Address, pub deployment: DeploymentId, + #[debug(with = Display::fmt)] pub url: Url, pub perf: ExpectedPerformance, pub fee: Normalized, @@ -164,3 +169,40 @@ pub fn score_latency(latency_ms: u32) -> Normalized { fn score_success_rate(success_rate: Normalized) -> Normalized { Normalized::new(success_rate.as_f64().powi(7).max(0.01)).unwrap() } + +#[cfg(test)] +mod tests { + use candidate_selection::criteria::performance::ExpectedPerformance; + use candidate_selection::Normalized; + + use super::Candidate; + + #[test] + fn candidate_should_use_url_display_for_debug() { + //* Given + let expected_url = "https://example.com/candidate/test/url"; + + let candidate = Candidate { + indexer: Default::default(), + deployment: "QmWmyoMoctfbAaiEs2G46gpeUmhqFRDW6KWo64y5r581Vz".parse().unwrap(), + url: expected_url.parse().expect("valid url"), + perf: ExpectedPerformance { + success_rate: Normalized::ONE, + latency_success_ms: 0, + latency_failure_ms: 0, + }, + fee: Normalized::ONE, + seconds_behind: 0, + slashable_usd: 0, + subgraph_versions_behind: 0, + zero_allocation: false, + }; + + //* When + let debug = format!("{:?}", candidate); + + //* Then + // Assert that the debug string contains the url in the expected format + assert!(debug.contains(expected_url)); + } +}