diff --git a/packages/indexer-agent/src/agent.ts b/packages/indexer-agent/src/agent.ts index 2d2033cf2..8b2c51a33 100644 --- a/packages/indexer-agent/src/agent.ts +++ b/packages/indexer-agent/src/agent.ts @@ -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, + ) + } + } } } } diff --git a/packages/indexer-common/src/indexer-management/allocations.ts b/packages/indexer-common/src/indexer-management/allocations.ts index 9f53d970d..1fd78e540 100644 --- a/packages/indexer-common/src/indexer-management/allocations.ts +++ b/packages/indexer-common/src/indexer-management/allocations.ts @@ -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(