Skip to content

Commit a923d78

Browse files
tmigonenate-staked
andauthored
add --auto-allocation-max-batch-size indexer-agent option (#1177)
Signed-off-by: Tomás Migone <tomas@edgeandnode.com> Co-authored-by: Nate Gentile <nate.gentile@kraken.com>
1 parent 8390cbc commit a923d78

4 files changed

Lines changed: 42 additions & 8 deletions

File tree

packages/indexer-agent/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ Indexer Infrastructure
5050
inside a batch for auto allocation
5151
management. No obvious upperbound, with
5252
default of 1 [number] [default: 1]
53+
--auto-allocation-max-batch-size Maximum number of allocation transactions
54+
inside a batch for auto allocation
55+
management. Limits the number of actions
56+
processed per batch to prevent multicall
57+
failures when there are many allocations.
58+
Remaining actions will be processed in
59+
subsequent batches. [number]
5360
5461
Postgres
5562
--postgres-host Postgres host [string] [required]

packages/indexer-agent/src/commands/start.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,12 @@ export const start = {
348348
default: 1,
349349
group: 'Indexer Infrastructure',
350350
})
351+
.option('auto-allocation-max-batch-size', {
352+
description: `Maximum number of allocation transactions inside a batch for auto allocation management. Limits the number of actions processed per batch to prevent multicall failures when there are many allocations. Remaining actions will be processed in subsequent batches.`,
353+
type: 'number',
354+
required: false,
355+
group: 'Indexer Infrastructure',
356+
})
351357
.check(argv => {
352358
if (
353359
!argv['network-subgraph-endpoint'] &&
@@ -408,6 +414,7 @@ export async function createNetworkSpecification(
408414
voucherRedemptionMaxBatchSize: argv.voucherRedemptionMaxBatchSize,
409415
allocationManagementMode: argv.allocationManagement,
410416
autoAllocationMinBatchSize: argv.autoAllocationMinBatchSize,
417+
autoAllocationMaxBatchSize: argv.autoAllocationMaxBatchSize,
411418
allocateOnNetworkSubgraph: argv.allocateOnNetworkSubgraph,
412419
register: argv.register,
413420
maxProvisionInitialSize: argv.maxProvisionInitialSize,

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

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,10 @@ export class ActionManager {
323323
status: [ActionStatus.APPROVED, ActionStatus.DEPLOYING],
324324
protocolNetwork,
325325
},
326-
order: [['priority', 'ASC']],
326+
order: [
327+
['priority', 'ASC'],
328+
['id', 'ASC'],
329+
],
327330
transaction,
328331
lock: transaction.LOCK.UPDATE,
329332
})
@@ -355,13 +358,29 @@ export class ActionManager {
355358
logger.error('Failed to query approved actions for network', { error })
356359
return []
357360
}
358-
// mark all approved actions as DEPLOYING, this serves as a lock on other processing of them
359-
await this.markActions(
360-
approvedAndDeployingActions,
361-
transaction,
362-
ActionStatus.DEPLOYING,
363-
)
364-
return approvedAndDeployingActions
361+
362+
// Limit batch size to prevent multicall failures when there are many allocations
363+
const maxBatchSize =
364+
network.specification.indexerOptions.autoAllocationMaxBatchSize
365+
let actionsToExecute = approvedAndDeployingActions
366+
if (maxBatchSize && approvedAndDeployingActions.length > maxBatchSize) {
367+
actionsToExecute = approvedAndDeployingActions.slice(0, maxBatchSize)
368+
logger.info(
369+
`Limiting batch size to ${maxBatchSize} actions (${approvedAndDeployingActions.length} total approved). ` +
370+
`Remaining ${
371+
approvedAndDeployingActions.length - maxBatchSize
372+
} actions will be processed in subsequent batches.`,
373+
{
374+
totalApproved: approvedAndDeployingActions.length,
375+
maxBatchSize,
376+
actionsInThisBatch: actionsToExecute.length,
377+
},
378+
)
379+
}
380+
381+
// mark actions to execute as DEPLOYING, this serves as a lock on other processing of them
382+
await this.markActions(actionsToExecute, transaction, ActionStatus.DEPLOYING)
383+
return actionsToExecute
365384
},
366385
)
367386

packages/indexer-common/src/network-specification.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const IndexerOptions = z
6161
.default('auto')
6262
.transform((x) => x as AllocationManagementMode),
6363
autoAllocationMinBatchSize: positiveNumber().default(1),
64+
autoAllocationMaxBatchSize: positiveNumber().optional(),
6465
allocateOnNetworkSubgraph: z.boolean().default(false),
6566
register: z.boolean().default(true),
6667
maxProvisionInitialSize: GRT()

0 commit comments

Comments
 (0)