Skip to content

Commit

Permalink
indexer-common: update action statuses and indexing rules
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed May 17, 2023
1 parent 7ebf16d commit 592960a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
32 changes: 31 additions & 1 deletion packages/indexer-common/src/indexer-management/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export class ActionManager {
}

private async updateActionStatuses(
action_ids: number[],
results: AllocationResult[],
transaction: Transaction,
): Promise<Action[]> {
Expand All @@ -128,6 +129,27 @@ export class ActionManager {
)
updatedActions = updatedActions.concat(updatedAction)
}
// approved actions that did not have an allocation result
const resultedActionIDs = results.map((result) => result.actionID)
const unfoundActionIDs = action_ids.filter((id) => id in resultedActionIDs)

// Assume they have failed
for (const id of unfoundActionIDs) {
const status = ActionStatus.FAILED
const [, updatedAction] = await this.models.Action.update(
{
status: status,
transaction: null,
failureReason: 'No correlating transaction',
},
{
where: { id },
returning: true,
transaction,
},
)
updatedActions = updatedActions.concat(updatedAction)
}
return updatedActions
}

Expand Down Expand Up @@ -163,7 +185,15 @@ export class ActionManager {
results,
})

updatedActions = await this.updateActionStatuses(results, transaction)
updatedActions = await this.updateActionStatuses(
approvedActions.map((action) => action.id),
results,
transaction,
)

this.logger.debug('Completed action statuses update', {
updatedActions,
})
} catch (error) {
this.logger.error(`Failed to execute batch tx on staking contract: ${error}`)
throw indexerError(IndexerErrorCode.IE072, error)
Expand Down
22 changes: 11 additions & 11 deletions packages/indexer-common/src/indexer-management/allocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,28 +628,28 @@ export class AllocationManager {
indexingRewards: rewardsAssigned,
})

logger.info('Identifying receipts worth collecting', {
allocation: closeAllocationEventLogs.allocationID,
})
const allocation = await this.networkMonitor.allocation(allocationID)
// Collect query fees for this allocation
const isCollectingQueryFees = await this.receiptCollector.collectReceipts(
actionID,
allocation,
)

// Upsert a rule so the agent keeps the deployment synced but doesn't allocate to it
logger.debug(
`Updating indexing rules so indexer-agent keeps the deployment synced but doesn't reallocate to it`,
)
const offchainIndexingRule = {
identifier: allocation.subgraphDeployment.id.ipfsHash,
identifier: subgraphDeploymentID.ipfsHash,
identifierType: SubgraphIdentifierType.DEPLOYMENT,
decisionBasis: IndexingDecisionBasis.OFFCHAIN,
} as Partial<IndexingRuleAttributes>

await upsertIndexingRule(logger, this.models, offchainIndexingRule)

logger.info('Identifying receipts worth collecting', {
allocation: closeAllocationEventLogs.allocationID,
})
const allocation = await this.networkMonitor.allocation(allocationID)
// Collect query fees for this allocation
const isCollectingQueryFees = await this.receiptCollector.collectReceipts(
actionID,
allocation,
)

return {
actionID,
type: 'unallocate',
Expand Down

0 comments on commit 592960a

Please sign in to comment.