Skip to content

Commit 1962635

Browse files
committed
fix: remove unused one_f64 function and fix test compilation
- Remove unused one_f64() function that was causing CI warnings - Remove unused serde default attribute from Provider.weight field - Add missing weighted_rpc_steering field to test fixtures - Apply cargo fmt formatting fixes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude
1 parent 283980a commit 1962635

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

chain/ethereum/src/network.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use graph::components::network_provider::ProviderName;
77
use graph::endpoint::EndpointMetrics;
88
use graph::firehose::{AvailableCapacity, SubgraphLimit};
99
use 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
};
1215
use itertools::Itertools;
1316
use 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;

node/src/chain.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ mod test {
573573
ethereum_ws: vec![],
574574
ethereum_ipc: vec![],
575575
unsafe_config: false,
576+
weighted_rpc_steering: false,
576577
};
577578

578579
let metrics = Arc::new(EndpointMetrics::mock());

node/src/config.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ impl Chain {
549549
if labels.len() != self.providers.len() {
550550
return Err(anyhow!("Provider labels must be unique"));
551551
}
552-
552+
553553
// Check that not all provider weights are zero
554554
if !self.providers.is_empty() {
555555
let all_zero_weights = self.providers.iter().all(|p| p.weight == 0.0);
@@ -618,7 +618,6 @@ fn btree_map_to_http_headers(kvs: BTreeMap<String, String>) -> HeaderMap {
618618
pub struct Provider {
619619
pub label: String,
620620
pub details: ProviderDetails,
621-
#[serde(default = "one_f64")]
622621
pub weight: f64,
623622
}
624623

@@ -1196,10 +1195,6 @@ fn one() -> usize {
11961195
1
11971196
}
11981197

1199-
fn one_f64() -> f64 {
1200-
1.0
1201-
}
1202-
12031198
fn default_node_id() -> NodeId {
12041199
NodeId::new("default").unwrap()
12051200
}

0 commit comments

Comments
 (0)