From 3801b496a33e0b3b2fe470c1e6eeb5f0d70f36eb 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 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/indexer-common/src/actions.ts b/packages/indexer-common/src/actions.ts index 9aec66814..7e1d95723 100644 --- a/packages/indexer-common/src/actions.ts +++ b/packages/indexer-common/src/actions.ts @@ -137,7 +137,15 @@ 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 && + 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 +159,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 {