From 6293b58644752d1269c28aedfe34e4fb94b65bed Mon Sep 17 00:00:00 2001 From: Daniel Werner Date: Wed, 23 Oct 2024 09:00:51 -0700 Subject: [PATCH] agent: allow expired allocations to be reallocated with force --- packages/indexer-common/src/actions.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/indexer-common/src/actions.ts b/packages/indexer-common/src/actions.ts index 9aec66814..57d568c90 100644 --- a/packages/indexer-common/src/actions.ts +++ b/packages/indexer-common/src/actions.ts @@ -137,7 +137,14 @@ export const validateActionInputs = async ( // allocationID must belong to active allocation // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const allocation = await networkMonitor.allocation(action.allocationID!) - if (allocation.status !== AllocationStatus.ACTIVE) { + + const forcedReallocate = + action.type === ActionType.REALLOCATE && action.force === true + // TODO && isZeroPOI(action.poi) + + if (forcedReallocate) { + logger.info(`forcing reallocate of id = '${action.allocationID}'`) + } else if (allocation.status !== AllocationStatus.ACTIVE) { throw new Error( `An active allocation does not exist with id = '${action.allocationID}'`, ) @@ -151,6 +158,10 @@ export const validateActionInputs = async ( } } } + + function isZeroPOI(poi: string | undefined): boolean { + return (typeof poi == 'number' && poi == 0) || (typeof poi == 'string' && poi == '0') + } } export interface ActionFilter {