Skip to content

Commit

Permalink
fix: use latest allocation per indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus committed Aug 10, 2023
1 parent f06c6ce commit 84176b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 6 additions & 3 deletions graph-gateway/src/network_subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ impl Client {

#[allow(clippy::obfuscated_if_else)]
async fn poll_subgraphs(&mut self) -> Result<(), String> {
// TODO: `indexerAllocations(first: 500` is for the MIPs program. Under normal circumstances
// we would not expect so many indexers per deployment.
// last allocation is latest by indexing: 9936786a-e286-45f3-9190-8409d8389e88
let query = format!(
r#"
subgraphs(
Expand All @@ -156,7 +155,11 @@ impl Client {
metadataHash
subgraphDeployment {{
ipfsHash
indexerAllocations(first: 100, where: {{ status: Active }}) {{
indexerAllocations(
first: 100
orderBy: createdAt, orderDirection: asc
where: {{ status: Active }}
) {{
id
allocatedTokens
indexer {{
Expand Down
8 changes: 3 additions & 5 deletions graph-gateway/src/topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,10 @@ impl GraphNetwork {
.map(|indexer| (*indexer.id, indexer))
.into_group_map()
.into_iter()
.filter_map(|(_, allocations)| {
.filter_map(|(_, mut allocations)| {
let total_allocation: GRT = allocations.iter().map(|a| a.allocated_tokens).sum();
let max_allocation = allocations.iter().map(|a| a.allocated_tokens).max()?;
let mut indexer = allocations
.into_iter()
.find(|a| a.allocated_tokens == max_allocation)?;
// last allocation is latest: 9936786a-e286-45f3-9190-8409d8389e88
let mut indexer = allocations.pop()?;
indexer.allocated_tokens = total_allocation;
Some(indexer)
})
Expand Down

0 comments on commit 84176b2

Please sign in to comment.