From df720c5660f8bd5b8a4627bc745d472dbeac8ac4 Mon Sep 17 00:00:00 2001 From: Ford Date: Fri, 13 Oct 2023 10:08:55 -0700 Subject: [PATCH] indexer-agent: Fix bug in stake usage summary, improve logging - If null POI is provided we should expect that the agent will get a valid POI from the graph-node. I.e only expect 0 rewards if a 0x0... POI is explicitly provided --- .../src/indexer-management/__tests__/util.ts | 6 ++--- .../src/indexer-management/allocations.ts | 26 ++++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/indexer-common/src/indexer-management/__tests__/util.ts b/packages/indexer-common/src/indexer-management/__tests__/util.ts index 4dac58992..b697558d8 100644 --- a/packages/indexer-common/src/indexer-management/__tests__/util.ts +++ b/packages/indexer-common/src/indexer-management/__tests__/util.ts @@ -165,7 +165,7 @@ export const invalidUnallocateAction = { allocationID: '0x8f63930129e585c69482b56390a09b6b176f4a4c', deploymentID: subgraphDeployment1, amount: undefined, - poi: undefined, + poi: '0x0000000000000000000000000000000000000000000000000000000000000000', force: false, source: 'indexerAgent', reason: 'indexingRule', @@ -177,8 +177,8 @@ export const invalidReallocateAction = { status: ActionStatus.QUEUED, type: ActionType.REALLOCATE, deploymentID: subgraphDeployment1, - allocationID: '0x8f63930129e585c69482b56390a09b6b176f4a4c', - poi: undefined, + allocationID: '0x000009a610d8b4fd4d1e020e22cc55a623fe7d2a', + poi: '0x0000000000000000000000000000000000000000000000000000000000000000', amount: undefined, force: false, source: 'indexerAgent', diff --git a/packages/indexer-common/src/indexer-management/allocations.ts b/packages/indexer-common/src/indexer-management/allocations.ts index 2d0872796..c42f51796 100644 --- a/packages/indexer-common/src/indexer-management/allocations.ts +++ b/packages/indexer-common/src/indexer-management/allocations.ts @@ -999,10 +999,10 @@ export class AllocationManager { // Fetch the allocation on chain to inspect its amount const allocation = await this.network.networkMonitor.allocation(action.allocationID) - // Accrue rewards, except for null or zeroed POI + // Accrue rewards, except for zeroed POI const zeroHexString = utils.hexlify(Array(32).fill(0)) rewards = - !action.poi || action.poi === zeroHexString + action.poi === zeroHexString ? BigNumber.from(0) : await this.network.contracts.rewardsManager.getRewards(action.allocationID) @@ -1027,19 +1027,27 @@ export class AllocationManager { const indexerFreeStake = await this.network.contracts.staking.getIndexerCapacity( this.network.specification.indexerOptions.address, ) - const actionsBatchStakeusageSummaries = await pMap(batch, async (action: Action) => + const actionsBatchStakeUsageSummaries = await pMap(batch, async (action: Action) => this.stakeUsageSummary(action), ) - const batchDelta: BigNumber = actionsBatchStakeusageSummaries + const batchDelta: BigNumber = actionsBatchStakeUsageSummaries .map((summary: ActionStakeUsageSummary) => summary.balance) .reduce((a: BigNumber, b: BigNumber) => a.add(b)) const indexerNewBalance = indexerFreeStake.sub(batchDelta) logger.trace('Action batch stake usage summary', { - indexerFreeStake, - actionsBatchStakeusageSummaries, - batchDelta, - indexerNewBalance, + indexerFreeStake: indexerFreeStake.toString(), + actionsBatchStakeUsageSummaries: actionsBatchStakeUsageSummaries.map((summary) => { + return { + action: summary.action, + allocates: summary.allocates.toString(), + unallocates: summary.unallocates.toString(), + rewards: summary.rewards.toString(), + balance: summary.balance.toString(), + } + }), + batchDelta: batchDelta.toString(), + indexerNewBalance: indexerNewBalance.toString(), }) if (indexerNewBalance.isNegative()) { @@ -1056,7 +1064,7 @@ export class AllocationManager { /* Return actions sorted by GRT balance (ascending). * This ensures on-chain batch feasibility because higher unallocations are processed * first and larger allocations are processed last */ - return actionsBatchStakeusageSummaries + return actionsBatchStakeUsageSummaries .sort((a: ActionStakeUsageSummary, b: ActionStakeUsageSummary) => a.balance.gt(b.balance) ? 1 : -1, )