Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agent,common: Improve control of subgraph deployment health safety check #852

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 60 additions & 28 deletions packages/indexer-agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1073,36 +1073,68 @@ export class Agent {
epoch,
)
case true: {
// If no active allocations, create one
// If no active allocations and subgraph health passes safety check, create one
const indexingStatuses = await this.graphNode.indexingStatus([
deploymentAllocationDecision.deployment,
])
const indexingStatus = indexingStatuses.find(
status =>
status.subgraphDeployment ==
deploymentAllocationDecision.deployment,
)
const failsHealthCheck =
(indexingStatus &&
indexingStatus.health == 'failed' &&
deploymentAllocationDecision.ruleMatch.rule?.safety) ||
!indexingStatus
if (activeDeploymentAllocations.length === 0) {
// Fetch the latest closed allocation, if any
const mostRecentlyClosedAllocation = (
await network.networkMonitor.closedAllocations(
deploymentAllocationDecision.deployment,
if (failsHealthCheck) {
logger.warn(
'Subgraph deployment has failed health check, skipping allocate',
{
indexingStatus,
safety: deploymentAllocationDecision.ruleMatch.rule?.safety,
},
)
)[0]
return await operator.createAllocation(
logger,
deploymentAllocationDecision,
mostRecentlyClosedAllocation,
)
}

// Refresh any expiring allocations
const expiringAllocations = await this.identifyExpiringAllocations(
logger,
activeDeploymentAllocations,
deploymentAllocationDecision,
epoch,
maxAllocationEpochs,
network,
)
if (expiringAllocations.length > 0) {
await operator.refreshExpiredAllocations(
logger,
deploymentAllocationDecision,
expiringAllocations,
)
} else {
// Fetch the latest closed allocation, if any
const mostRecentlyClosedAllocation = (
await network.networkMonitor.closedAllocations(
deploymentAllocationDecision.deployment,
)
)[0]
return await operator.createAllocation(
logger,
deploymentAllocationDecision,
mostRecentlyClosedAllocation,
)
}
} else if (activeDeploymentAllocations.length > 0) {
if (failsHealthCheck) {
return await operator.closeEligibleAllocations(
logger,
deploymentAllocationDecision,
activeDeploymentAllocations,
epoch,
)
} else {
// Refresh any expiring allocations
const expiringAllocations = await this.identifyExpiringAllocations(
logger,
activeDeploymentAllocations,
deploymentAllocationDecision,
epoch,
maxAllocationEpochs,
network,
)
if (expiringAllocations.length > 0) {
await operator.refreshExpiredAllocations(
logger,
deploymentAllocationDecision,
expiringAllocations,
)
}
}
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions packages/indexer-common/src/indexer-management/allocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,6 @@ export class AllocationManager {
`Subgraph deployment, '${deployment.ipfsHash}', is not syncing`,
)
}
if (status && status.health == 'failed') {
throw indexerError(
IndexerErrorCode.IE020,
`Subgraph deployment, '${deployment.ipfsHash}', failed during syncing`,
)
}

logger.debug('Obtain a unique Allocation ID')
const { allocationSigner, allocationId } = uniqueAllocationID(
Expand Down
Loading