Skip to content

Commit fb0c241

Browse files
committed
fix: update AllocationDecision priority calculation and fix GraphQL parsing
- Simplify priority calculation to use available AllocationDecision properties - Use rule-based priority calculation instead of unavailable deployment metrics - Fix parseGraphQLSubgraphDeployment to include protocolNetwork parameter - Remove references to non-existent properties like 'urgent' and 'profitability' 🤖 Generated with Claude Code (claude.ai/code)
1 parent e3c3ae9 commit fb0c241

File tree

2 files changed

+27
-49
lines changed

2 files changed

+27
-49
lines changed

packages/indexer-common/src/performance/allocation-priority-queue.ts

Lines changed: 26 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -283,66 +283,44 @@ export class AllocationPriorityQueue {
283283
private calculatePriority(decision: AllocationDecision): number {
284284
let priority = 0
285285

286-
// Critical factors (1000+ points)
287-
if (decision.urgent) {
288-
priority += 10000 // Urgent allocations get top priority
289-
}
290-
291-
if (decision.toAllocate && !decision.deployment.activeAllocations) {
292-
priority += 5000 // New allocations for unallocated deployments
293-
}
294-
295286
// High priority factors (100-999 points)
296287
if (decision.toAllocate) {
297288
priority += 500 // Creating allocations is generally high priority
298289
}
299290

300-
// Signal-based priority (up to 1000 points)
301-
if (decision.deployment.signalledTokens.gt(this.signalThreshold)) {
302-
const signalScore = Math.min(
303-
1000,
304-
decision.deployment.signalledTokens
305-
.div(this.signalThreshold)
306-
.toNumber() * 10
307-
)
308-
priority += signalScore
309-
}
310-
311-
// Stake-based priority (up to 500 points)
312-
if (decision.deployment.stakedTokens.gt(this.stakeThreshold)) {
313-
const stakeScore = Math.min(
314-
500,
315-
decision.deployment.stakedTokens
316-
.div(this.stakeThreshold)
317-
.toNumber() * 5
318-
)
319-
priority += stakeScore
320-
}
321-
322-
// Query fees priority (up to 300 points)
323-
if (decision.deployment.queryFeesAmount.gt(0)) {
324-
const feeScore = Math.min(
325-
300,
326-
Math.log10(decision.deployment.queryFeesAmount.toNumber()) * 30
327-
)
328-
priority += feeScore
329-
}
330-
331-
// Profitability-based priority (up to 200 points)
332-
if (decision.profitability && decision.profitability > 0) {
333-
priority += Math.min(200, decision.profitability * 100)
334-
}
335-
336291
// Lower priority for closing allocations (-100 points)
337292
if (!decision.toAllocate) {
338293
priority -= 100
339294
}
340295

341-
// Safety check failures get deprioritized (-500 points)
342-
if (decision.deployment.deniedAt && decision.deployment.deniedAt > 0) {
343-
priority -= 500
296+
// Rule-based priority
297+
if (decision.ruleMatch.rule) {
298+
const rule = decision.ruleMatch.rule
299+
300+
// Higher allocation amount suggests higher importance
301+
if (rule.allocationAmount) {
302+
const amount = parseFloat(rule.allocationAmount)
303+
priority += Math.min(200, Math.log10(amount + 1) * 20)
304+
}
305+
306+
// Priority based on decision basis
307+
if (rule.decisionBasis === 'always') {
308+
priority += 100
309+
} else if (rule.decisionBasis === 'rules') {
310+
priority += 50
311+
}
312+
313+
// Safety considerations
314+
if (rule.safety === false) {
315+
priority -= 200 // Deprioritize unsafe deployments
316+
}
344317
}
345318

319+
// Deployment ID based priority (for consistent ordering)
320+
const deploymentHash = decision.deployment.ipfsHash
321+
const hashPriority = parseInt(deploymentHash.slice(-4), 16) / 65535 * 10
322+
priority += hashPriority
323+
346324
return Math.max(0, priority) // Ensure non-negative priority
347325
}
348326

packages/indexer-common/src/performance/graphql-dataloader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export class GraphQLDataLoader {
252252
for (const deployment of result.data.subgraphDeployments || []) {
253253
deploymentsMap.set(
254254
deployment.id.toLowerCase(),
255-
parseGraphQLSubgraphDeployment(deployment),
255+
parseGraphQLSubgraphDeployment(deployment, this.protocolNetwork),
256256
)
257257
}
258258

0 commit comments

Comments
 (0)