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 Dec 7, 2023
1 parent 0c995ad commit 3d6c8dc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
33 changes: 32 additions & 1 deletion packages/indexer-common/src/indexer-management/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export class ActionManager {
}

private async updateActionStatuses(
action_ids: number[],
results: AllocationResult[],
transaction: Transaction,
): Promise<Action[]> {
Expand All @@ -220,6 +221,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)

// action ids are not found in transaction result
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 @@ -279,7 +301,16 @@ export class ActionManager {
logger.debug('Completed batch action execution', {
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) {
logger.error(`Failed to execute batch tx on staking contract: ${error}`)
throw indexerError(IndexerErrorCode.IE072, error)
Expand Down
23 changes: 11 additions & 12 deletions packages/indexer-common/src/indexer-management/allocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,29 +618,28 @@ export class AllocationManager {
indexingRewards: rewardsAssigned,
})

logger.info('Identifying receipts worth collecting', {
allocation: closeAllocationEventLogs.allocationID,
})
const allocation = await this.network.networkMonitor.allocation(allocationID)
// Collect query fees for this allocation
const isCollectingQueryFees = await this.network.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,
protocolNetwork: this.network.specification.networkIdentifier,
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.network.networkMonitor.allocation(allocationID)
// Collect query fees for this allocation
const isCollectingQueryFees = await this.network.receiptCollector.collectReceipts(
actionID,
allocation,
)

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

0 comments on commit 3d6c8dc

Please sign in to comment.