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

indexer-agent: Fix bug in stake usage summary #801

Merged
merged 1 commit into from
Nov 1, 2023
Merged
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
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
Loading