From ee1b76dcbc1412378863d9e054e60bc7dcbd1ec3 Mon Sep 17 00:00:00 2001 From: hopeyen Date: Thu, 7 Dec 2023 14:24:46 -0600 Subject: [PATCH] indexer-common: update action statuses and indexing rules --- .../src/indexer-management/actions.ts | 33 ++++++++++++++++++- .../src/indexer-management/allocations.ts | 24 +++++++------- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/packages/indexer-common/src/indexer-management/actions.ts b/packages/indexer-common/src/indexer-management/actions.ts index 7efbbafcb..e6c344f50 100644 --- a/packages/indexer-common/src/indexer-management/actions.ts +++ b/packages/indexer-common/src/indexer-management/actions.ts @@ -200,6 +200,7 @@ export class ActionManager { } private async updateActionStatuses( + action_ids: number[], results: AllocationResult[], transaction: Transaction, ): Promise { @@ -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 } @@ -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) diff --git a/packages/indexer-common/src/indexer-management/allocations.ts b/packages/indexer-common/src/indexer-management/allocations.ts index 5e08ed1d4..f24076fc9 100644 --- a/packages/indexer-common/src/indexer-management/allocations.ts +++ b/packages/indexer-common/src/indexer-management/allocations.ts @@ -618,29 +618,29 @@ 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 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',