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

update action statuses and indexing rules #665

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
Loading