Skip to content

Commit 8acb42a

Browse files
committed
Fix compilation issues [claude]
✅ Completed Tasks: 1. Fixed compilation issues: - Corrected the import path for WeightedIndex from rand 0.9's distr::weighted module - Added the required Distribution trait import - Fixed deprecated gen() method to use random() - Fixed deprecated thread_rng() to use rng() 2. Added weight validation: - Added check to ensure not all provider weights are zero - Existing validation already ensures weights are between 0.0 and 1.0 3. Fixed error retesting logic: - Moved error retesting to occur AFTER weight-based selection to minimize distribution skew 4. Added comprehensive documentation: - Added config file documentation explaining weight ranges and behavior - Added inline documentation for all weight-related methods 5. Build verification: - Project builds successfully - Weighted adapter selection test passes
1 parent 595f185 commit 8acb42a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ wasmtime = "33.0.2"
9999
substreams = "=0.6.0"
100100
substreams-entity-change = "2"
101101
substreams-near-core = "=0.10.2"
102-
rand = { version = "0.9.1", features = ["os_rng", "distributions"] }
102+
rand = { version = "0.9.1", features = ["os_rng"] }
103103

104104
# Incremental compilation on Rust 1.58 causes an ICE on build. As soon as graph node builds again, these can be removed.
105105
[profile.test]

chain/ethereum/src/network.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use graph::components::network_provider::ProviderManager;
66
use graph::components::network_provider::ProviderName;
77
use graph::endpoint::EndpointMetrics;
88
use graph::firehose::{AvailableCapacity, SubgraphLimit};
9-
use graph::prelude::rand::distributions::WeightedIndex;
10-
use graph::prelude::rand::seq::IteratorRandom;
11-
use graph::prelude::rand::{self, Rng};
9+
use graph::prelude::rand::{
10+
self, distr::{weighted::WeightedIndex, Distribution}, seq::IteratorRandom, Rng
11+
};
1212
use itertools::Itertools;
1313
use std::sync::Arc;
1414

@@ -216,7 +216,7 @@ impl EthereumNetworkAdapters {
216216

217217
// Occasionally override selection to retest errored adapters
218218
// This happens AFTER weight-based selection to minimize distribution skew
219-
let retest_rng: f64 = rand::thread_rng().gen();
219+
let retest_rng: f64 = rand::rng().random();
220220
if retest_rng < self.retest_percent {
221221
// Find the adapter with the highest error count
222222
if let Some(most_errored) = input
@@ -267,7 +267,7 @@ impl EthereumNetworkAdapters {
267267
}
268268
let weights: Vec<_> = input.iter().map(|a| a.weight).collect();
269269
if let Ok(dist) = WeightedIndex::new(&weights) {
270-
let idx = dist.sample(&mut rand::thread_rng());
270+
let idx = dist.sample(&mut rand::rng());
271271
Ok(input[idx].adapter.clone())
272272
} else {
273273
// Fallback to random selection if weights are invalid
@@ -287,7 +287,7 @@ impl EthereumNetworkAdapters {
287287
) -> Result<Arc<EthereumAdapter>, Error> {
288288
let choices = input
289289
.into_iter()
290-
.choose_multiple(&mut rand::thread_rng(), 3);
290+
.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 {
@@ -392,7 +392,7 @@ mod tests {
392392
use graph::{
393393
endpoint::EndpointMetrics,
394394
firehose::SubgraphLimit,
395-
prelude::{MetricsRegistry, SubgraphAssignmentProvider},
395+
prelude::MetricsRegistry,
396396
tokio,
397397
url::Url,
398398
};

0 commit comments

Comments
 (0)