@@ -7,7 +7,10 @@ use graph::components::network_provider::ProviderName;
77use graph:: endpoint:: EndpointMetrics ;
88use graph:: firehose:: { AvailableCapacity , SubgraphLimit } ;
99use graph:: prelude:: rand:: {
10- self , distr:: { weighted:: WeightedIndex , Distribution } , seq:: IteratorRandom , Rng
10+ self ,
11+ distr:: { weighted:: WeightedIndex , Distribution } ,
12+ seq:: IteratorRandom ,
13+ Rng ,
1114} ;
1215use itertools:: Itertools ;
1316use std:: sync:: Arc ;
@@ -199,11 +202,11 @@ impl EthereumNetworkAdapters {
199202
200203 /// Main adapter selection entry point that handles both weight-based distribution
201204 /// and error retesting logic.
202- ///
205+ ///
203206 /// The selection process:
204207 /// 1. First selects an adapter based on weights (if enabled) or random selection
205208 /// 2. Occasionally overrides the selection to retest adapters with errors
206- ///
209+ ///
207210 /// The error retesting happens AFTER weight-based selection to minimize
208211 /// distribution skew while still allowing periodic health checks of errored endpoints.
209212 fn cheapest_from (
@@ -213,7 +216,7 @@ impl EthereumNetworkAdapters {
213216 ) -> Result < Arc < EthereumAdapter > , Error > {
214217 // Select adapter based on weights or random strategy
215218 let selected_adapter = self . select_best_adapter ( input. clone ( ) , required_capabilities) ?;
216-
219+
217220 // Occasionally override selection to retest errored adapters
218221 // This happens AFTER weight-based selection to minimize distribution skew
219222 let retest_rng: f64 = rand:: rng ( ) . random ( ) ;
@@ -227,11 +230,10 @@ impl EthereumNetworkAdapters {
227230 return Ok ( most_errored. adapter . clone ( ) ) ;
228231 }
229232 }
230-
233+
231234 Ok ( selected_adapter)
232235 }
233236
234-
235237 /// Selects the best adapter based on the configured strategy (weighted or random).
236238 /// If weighted mode is enabled, uses weight-based probabilistic selection.
237239 /// Otherwise, falls back to random selection with error count consideration.
@@ -248,11 +250,11 @@ impl EthereumNetworkAdapters {
248250 }
249251
250252 /// Performs weighted random selection of adapters based on their configured weights.
251- ///
253+ ///
252254 /// Weights are relative values between 0.0 and 1.0 that determine the probability
253255 /// of selecting each adapter. They don't need to sum to 1.0 as they're normalized
254256 /// internally by the WeightedIndex distribution.
255- ///
257+ ///
256258 /// Falls back to random selection if weights are invalid (e.g., all zeros).
257259 fn select_weighted_adapter (
258260 & self ,
@@ -276,7 +278,7 @@ impl EthereumNetworkAdapters {
276278 }
277279
278280 /// Performs random selection of adapters with preference for those with fewer errors.
279- ///
281+ ///
280282 /// Randomly selects up to 3 adapters from the available pool, then chooses the one
281283 /// with the lowest error count. This provides a balance between load distribution
282284 /// and avoiding problematic endpoints.
@@ -285,9 +287,7 @@ impl EthereumNetworkAdapters {
285287 input : Vec < & EthereumNetworkAdapter > ,
286288 required_capabilities : & NodeCapabilities ,
287289 ) -> Result < Arc < EthereumAdapter > , Error > {
288- let choices = input
289- . into_iter ( )
290- . choose_multiple ( & mut rand:: rng ( ) , 3 ) ;
290+ let choices = input. into_iter ( ) . choose_multiple ( & mut rand:: rng ( ) , 3 ) ;
291291 if let Some ( adapter) = choices. iter ( ) . min_by_key ( |a| a. current_error_count ( ) ) {
292292 Ok ( adapter. adapter . clone ( ) )
293293 } else {
@@ -390,10 +390,7 @@ mod tests {
390390 use graph:: http:: HeaderMap ;
391391 use graph:: slog:: { o, Discard , Logger } ;
392392 use graph:: {
393- endpoint:: EndpointMetrics ,
394- firehose:: SubgraphLimit ,
395- prelude:: MetricsRegistry ,
396- tokio,
393+ endpoint:: EndpointMetrics , firehose:: SubgraphLimit , prelude:: MetricsRegistry , tokio,
397394 url:: Url ,
398395 } ;
399396 use std:: sync:: Arc ;
0 commit comments