Skip to content

Commit 606a8e7

Browse files
committed
fix: allocation cli bugs
Signed-off-by: Tomás Migone <[email protected]>
1 parent 2b44aaa commit 606a8e7

File tree

4 files changed

+44
-30
lines changed

4 files changed

+44
-30
lines changed

packages/indexer-cli/src/commands/indexer/allocations/reallocate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ${chalk.dim('Options:')}
2323
2424
${chalk.dim('Arguments:')}
2525
<id> The allocation id to close
26+
<amount> The amount of GRT to reallocate
2627
<poi> (optional) The POI to close the allocation with
2728
<blockNumber> (optional, horizon only) The block number the POI was computed at. Must be set if POI is provided.
2829
<publicPOI> (optional, horizon only) The public POI to close the allocation with. Must be same block height as POI.

packages/indexer-common/src/errors.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ export enum IndexerErrorCode {
9494
IE081 = 'IE081',
9595
IE082 = 'IE082',
9696
IE083 = 'IE083',
97+
IE084 = 'IE084',
98+
IE085 = 'IE085',
9799
}
98100

99101
export const INDEXER_ERROR_MESSAGES: Record<IndexerErrorCode, string> = {
@@ -181,6 +183,8 @@ export const INDEXER_ERROR_MESSAGES: Record<IndexerErrorCode, string> = {
181183
IE081: 'Multiple provisions found',
182184
IE082: 'Graph Horizon protocol not detected',
183185
IE083: 'Failed to thaw stake from provision',
186+
IE084: 'Could not resolve POI block number',
187+
IE085: 'Could not resolve public POI',
184188
}
185189

186190
export type IndexerErrorCause = unknown

packages/indexer-common/src/indexer-management/monitor.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class NetworkMonitor {
5656
private networkSubgraph: SubgraphClient,
5757
private ethereum: Provider,
5858
private epochSubgraph: SubgraphClient,
59-
) {}
59+
) { }
6060

6161
poiDisputeMonitoringEnabled(): boolean {
6262
return this.indexerOptions.poiDisputeMonitoring
@@ -285,8 +285,7 @@ export class NetworkMonitor {
285285

286286
if (allocations.length === 0) {
287287
this.logger.warn(
288-
`No ${
289-
AllocationStatus[status.toUpperCase() as keyof typeof AllocationStatus]
288+
`No ${AllocationStatus[status.toUpperCase() as keyof typeof AllocationStatus]
290289
} allocations found for indexer '${this.indexerOptions.address}'`,
291290
)
292291
}
@@ -1560,11 +1559,10 @@ Please submit an issue at https://github.com/graphprotocol/block-oracle/issues/n
15601559
IndexerErrorCode.IE067,
15611560
`POI not available for deployment at current epoch start block.
15621561
currentEpochStartBlock: ${epochStartBlock.number}
1563-
deploymentStatus: ${
1564-
deploymentStatus.length > 0
1562+
deploymentStatus: ${deploymentStatus.length > 0
15651563
? JSON.stringify(deploymentStatus)
15661564
: 'not deployed'
1567-
}`,
1565+
}`,
15681566
)
15691567
} else {
15701568
return [poi, epochStartBlock.number]
@@ -1599,7 +1597,7 @@ Please submit an issue at https://github.com/graphprotocol/block-oracle/issues/n
15991597
let returnBlockNumber = 0
16001598
if (generatedPOIBlockNumber === 0) {
16011599
if (blockNumber === undefined) {
1602-
throw indexerError(IndexerErrorCode.IE067, 'Could not resolve POI block number')
1600+
throw indexerError(IndexerErrorCode.IE084, 'No block number generated and none provided')
16031601
}
16041602
returnBlockNumber = blockNumber
16051603
} else if (blockNumber === undefined || generatedPOIBlockNumber === blockNumber) {
@@ -1640,7 +1638,7 @@ Please submit an issue at https://github.com/graphprotocol/block-oracle/issues/n
16401638
let returnPublicPOI: string
16411639
if (generatedPublicPOI === undefined) {
16421640
if (publicPOI === undefined) {
1643-
throw indexerError(IndexerErrorCode.IE067, 'Could not resolve public POI')
1641+
throw indexerError(IndexerErrorCode.IE085, 'No public POI generated and none provided')
16441642
}
16451643
returnPublicPOI = publicPOI
16461644
} else if (publicPOI === undefined || generatedPublicPOI === publicPOI) {

packages/indexer-common/src/indexer-management/resolvers/allocations.ts

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,8 @@ async function closeHorizonAllocation(
803803
const closeAllocationEventLogs = transactionManager.findEvent(
804804
'ServiceStopped',
805805
contracts.SubgraphService.interface,
806-
'data',
807-
closeAllocationData,
806+
'serviceProvider',
807+
address,
808808
receipt,
809809
logger,
810810
)
@@ -840,6 +840,7 @@ async function closeHorizonAllocation(
840840
return { txHash: receipt.hash, rewardsAssigned }
841841
}
842842

843+
// isHorizon: false
843844
async function reallocateLegacyAllocation(
844845
allocation: Allocation,
845846
allocationAmount: bigint,
@@ -1056,6 +1057,7 @@ async function reallocateLegacyAllocation(
10561057
return { txHash: receipt.hash, rewardsAssigned, newAllocationId }
10571058
}
10581059

1060+
// isHorizon: true and allocation: not legacy
10591061
async function reallocateHorizonAllocation(
10601062
allocation: Allocation,
10611063
allocationAmount: bigint,
@@ -1073,20 +1075,6 @@ async function reallocateHorizonAllocation(
10731075
// Double-check whether the allocation is still active on chain, to
10741076
// avoid unnecessary transactions.
10751077
const allocationData = await contracts.SubgraphService.getAllocation(allocation.id)
1076-
const legacyAllocation = await contracts.SubgraphService.getLegacyAllocation(
1077-
allocation.id,
1078-
)
1079-
const existsSubgraphService = allocationData.createdAt !== 0n
1080-
const existsLegacyAllocation = legacyAllocation.indexer !== ZeroAddress
1081-
if (existsSubgraphService || existsLegacyAllocation) {
1082-
logger.warn(`Skipping allocation as it already exists onchain`, {
1083-
indexer: address,
1084-
allocation: allocation.id,
1085-
existsSubgraphService,
1086-
existsLegacyAllocation,
1087-
})
1088-
throw indexerError(IndexerErrorCode.IE066, 'AllocationID already exists')
1089-
}
10901078

10911079
if (allocationData.closedAt !== 0n) {
10921080
logger.warn(`Allocation has already been closed`)
@@ -1254,8 +1242,8 @@ async function reallocateHorizonAllocation(
12541242
const createAllocationEventLogs = network.transactionManager.findEvent(
12551243
'ServiceStarted',
12561244
network.contracts.SubgraphService.interface,
1257-
'data',
1258-
createAllocationData,
1245+
'serviceProvider',
1246+
address,
12591247
receipt,
12601248
logger,
12611249
)
@@ -1292,8 +1280,8 @@ async function reallocateHorizonAllocation(
12921280
const closeAllocationEventLogs = transactionManager.findEvent(
12931281
'ServiceStopped',
12941282
contracts.SubgraphService.interface,
1295-
'data',
1296-
closeAllocationData,
1283+
'serviceProvider',
1284+
address,
12971285
receipt,
12981286
logger,
12991287
)
@@ -1322,6 +1310,7 @@ async function reallocateHorizonAllocation(
13221310
return { txHash: receipt.hash, rewardsAssigned, newAllocationId }
13231311
}
13241312

1313+
// isHorizon: true and allocation: legacy
13251314
async function migrateLegacyAllocationToHorizon(
13261315
allocation: Allocation,
13271316
allocationAmount: bigint,
@@ -1487,11 +1476,16 @@ export default {
14871476

14881477
try {
14891478
const currentEpoch = await network.contracts.EpochManager.currentEpoch()
1479+
const isHorizon = await network.isHorizon.value()
1480+
1481+
logger.debug('createAllocation: Checking allocation resolution path', {
1482+
isHorizon,
1483+
})
14901484

14911485
let txHash: string
14921486
let allocationId: Address
1493-
if (await network.isHorizon.value()) {
1494-
logger.info('Creating horizon allocation')
1487+
if (isHorizon) {
1488+
logger.debug('Creating horizon allocation')
14951489
const result = await createHorizonAllocation(
14961490
network,
14971491
graphNode,
@@ -1505,6 +1499,7 @@ export default {
15051499
txHash = result.txHash
15061500
allocationId = result.allocationId
15071501
} else {
1502+
logger.debug('Creating legacy allocation')
15081503
const result = await createLegacyAllocation(
15091504
network,
15101505
graphNode,
@@ -1603,16 +1598,22 @@ export default {
16031598
)
16041599
logger.debug('POI resolved', {
16051600
userProvidedPOI: poi,
1601+
userProvidedPublicPOI: publicPOI,
16061602
userProvidedBlockNumber: blockNumber,
16071603
poi: poiData.poi,
16081604
publicPOI: poiData.publicPOI,
16091605
blockNumber: poiData.blockNumber,
16101606
force,
16111607
})
16121608

1609+
logger.debug('closeAllocation: Checking allocation resolution path', {
1610+
allocationIsLegacy: allocationData.isLegacy,
1611+
})
1612+
16131613
let txHash: string
16141614
let rewardsAssigned: bigint
16151615
if (allocationData.isLegacy) {
1616+
logger.debug('Closing legacy allocation')
16161617
const result = await closeLegacyAllocation(
16171618
allocationData,
16181619
poiData.poi,
@@ -1622,6 +1623,7 @@ export default {
16221623
txHash = result.txHash
16231624
rewardsAssigned = result.rewardsAssigned
16241625
} else {
1626+
logger.debug('Closing horizon allocation')
16251627
const result = await closeHorizonAllocation(
16261628
allocationData,
16271629
poiData,
@@ -1736,6 +1738,7 @@ export default {
17361738
)
17371739
logger.debug('POI resolved', {
17381740
userProvidedPOI: poi,
1741+
userProvidedPublicPOI: publicPOI,
17391742
userProvidedBlockNumber: blockNumber,
17401743
poi: poiData.poi,
17411744
publicPOI: poiData.publicPOI,
@@ -1745,10 +1748,16 @@ export default {
17451748

17461749
const isHorizon = await network.isHorizon.value()
17471750

1751+
logger.debug('reallocateAllocation: Checking allocation resolution path', {
1752+
isHorizon,
1753+
allocationIsLegacy: allocationData.isLegacy,
1754+
})
1755+
17481756
let txHash: string
17491757
let rewardsAssigned: bigint
17501758
let newAllocationId: Address
17511759
if (!isHorizon) {
1760+
logger.debug('Reallocating legacy allocation')
17521761
const result = await reallocateLegacyAllocation(
17531762
allocationData,
17541763
allocationAmount,
@@ -1761,6 +1770,7 @@ export default {
17611770
rewardsAssigned = result.rewardsAssigned
17621771
newAllocationId = result.newAllocationId
17631772
} else if (allocationData.isLegacy) {
1773+
logger.debug('Migrating legacy allocation to horizon')
17641774
const result = await migrateLegacyAllocationToHorizon(
17651775
allocationData,
17661776
allocationAmount,
@@ -1774,6 +1784,7 @@ export default {
17741784
rewardsAssigned = result.rewardsAssigned
17751785
newAllocationId = result.newAllocationId
17761786
} else {
1787+
logger.debug('Reallocating horizon allocation')
17771788
const result = await reallocateHorizonAllocation(
17781789
allocationData,
17791790
allocationAmount,

0 commit comments

Comments
 (0)