Skip to content

Commit

Permalink
indexer-agent: Fix bug in stake usage summary, improve logging
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
fordN committed Oct 13, 2023
1 parent 44cbddc commit b363d18
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export const invalidUnallocateAction = {
allocationID: '0x8f63930129e585c69482b56390a09b6b176f4a4c',
deploymentID: subgraphDeployment1,
amount: undefined,
poi: undefined,
poi: '0x0000000000000000000000000000000000000000000000000000000000000000',
force: false,
source: 'indexerAgent',
reason: 'indexingRule',
Expand All @@ -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',
Expand Down
26 changes: 17 additions & 9 deletions packages/indexer-common/src/indexer-management/allocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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()) {
Expand All @@ -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,
)
Expand Down

0 comments on commit b363d18

Please sign in to comment.