diff --git a/graph-gateway/src/client_query.rs b/graph-gateway/src/client_query.rs index 8d9071a9..e4447b5c 100644 --- a/graph-gateway/src/client_query.rs +++ b/graph-gateway/src/client_query.rs @@ -417,6 +417,13 @@ async fn handle_client_query_inner( budget_grt = f64::from(budget.0) as f32, ); + let versions_behind: BTreeMap = deployments + .iter() + .rev() + .enumerate() + .map(|(index, deployment)| (deployment.id, index.try_into().unwrap_or(u8::MAX))) + .collect(); + let candidates: Vec = candidates .into_iter() .filter_map(|indexing| { @@ -432,7 +439,11 @@ async fn handle_client_query_inner( return None; } }; - Some(Candidate { indexing, fee }) + Some(Candidate { + indexing, + fee, + versions_behind: *versions_behind.get(&indexing.deployment).unwrap_or(&0), + }) }) .collect(); diff --git a/graph-gateway/src/main.rs b/graph-gateway/src/main.rs index fc50a689..1d4a0f31 100644 --- a/graph-gateway/src/main.rs +++ b/graph-gateway/src/main.rs @@ -444,13 +444,11 @@ async fn write_indexer_inputs( let mut indexings: HashMap = HashMap::new(); let mut allocations: HashMap = HashMap::new(); - for (versions_behind, (deployment, indexer)) in deployments.values().flat_map(|deployment| { + for (deployment, indexer) in deployments.values().flat_map(|deployment| { deployment .indexers .iter() .map(move |indexer| (deployment.as_ref(), indexer.as_ref())) - .rev() - .enumerate() }) { let indexing = Indexing { indexer: indexer.id, @@ -469,7 +467,6 @@ async fn write_indexer_inputs( behind_reported_block: false, min_block: status.min_block, }), - versions_behind: versions_behind.try_into().unwrap_or(u8::MAX), }; allocations.insert(indexing, indexer.largest_allocation); indexings.insert(indexing, update); diff --git a/indexer-selection/src/indexing.rs b/indexer-selection/src/indexing.rs index 8c8fc980..fbe69454 100644 --- a/indexer-selection/src/indexing.rs +++ b/indexer-selection/src/indexing.rs @@ -35,7 +35,6 @@ pub struct IndexingStatus { pub stake: GRT, pub allocation: GRT, pub block: Option, - pub versions_behind: u8, } /// We compare candidate indexers based on their last reported block. Any observation of the indexer diff --git a/indexer-selection/src/lib.rs b/indexer-selection/src/lib.rs index 7387bf20..5fc822e0 100644 --- a/indexer-selection/src/lib.rs +++ b/indexer-selection/src/lib.rs @@ -44,6 +44,7 @@ const MIN_SCORE_CUTOFF: f64 = 0.25; pub struct Candidate { pub indexing: Indexing, pub fee: GRT, + pub versions_behind: u8, } #[derive(Clone, Debug)] @@ -288,7 +289,7 @@ impl State { params, reliability, perf_success, - state.status.versions_behind, + candidate.versions_behind, blocks_behind, slashable_usd, zero_allocation, @@ -300,7 +301,7 @@ impl State { Ok(SelectionFactors { indexing: candidate.indexing, url: state.status.url.clone(), - versions_behind: state.status.versions_behind, + versions_behind: candidate.versions_behind, reliability, perf_success, perf_failure: state.perf_failure.expected_value(), diff --git a/indexer-selection/src/simulation.rs b/indexer-selection/src/simulation.rs index d99740c0..94c4f625 100644 --- a/indexer-selection/src/simulation.rs +++ b/indexer-selection/src/simulation.rs @@ -71,7 +71,6 @@ pub async fn simulate( behind_reported_block: false, min_block: None, }), - versions_behind: 0, }, ); } @@ -84,6 +83,7 @@ pub async fn simulate( deployment, }, fee: c.fee, + versions_behind: 0, }) .collect(); let characteristics: HashMap<&Address, &IndexerCharacteristics> = diff --git a/indexer-selection/src/test.rs b/indexer-selection/src/test.rs index 3bd4f524..227f2e22 100644 --- a/indexer-selection/src/test.rs +++ b/indexer-selection/src/test.rs @@ -55,7 +55,6 @@ fn base_indexing_status() -> IndexingStatus { behind_reported_block: false, min_block: None, }), - versions_behind: 0, } } @@ -265,6 +264,7 @@ async fn fuzz() { Candidate { fee: *topology.fees.get(&indexing).unwrap(), indexing, + versions_behind: 0, } }) .collect(); @@ -284,6 +284,10 @@ async fn fuzz() { fn favor_higher_version() { let mut rng = SmallRng::from_entropy(); + let mut versions_behind = [rng.gen_range(0..3), rng.gen_range(0..3)]; + if versions_behind[0] == versions_behind[1] { + versions_behind[1] += 1; + } let candidates: Vec = (0..2) .map(|i| Candidate { indexing: Indexing { @@ -291,12 +295,9 @@ fn favor_higher_version() { deployment: bytes_from_id(i).into(), }, fee: GRT(UDecimal18::from(1)), + versions_behind: versions_behind[i], }) .collect(); - let mut versions_behind = [rng.gen_range(0..3), rng.gen_range(0..3)]; - if versions_behind[0] == versions_behind[1] { - versions_behind[1] += 1; - } let mut state = State { network_params: NetworkParameters { @@ -307,17 +308,11 @@ fn favor_higher_version() { }; state.indexings.insert( candidates[0].indexing, - IndexingState::new(IndexingStatus { - versions_behind: versions_behind[0], - ..base_indexing_status() - }), + IndexingState::new(base_indexing_status()), ); state.indexings.insert( candidates[1].indexing, - IndexingState::new(IndexingStatus { - versions_behind: versions_behind[1], - ..base_indexing_status() - }), + IndexingState::new(base_indexing_status()), ); let params = utiliy_params(