From 605b9aff8c88abe1297d0c198be71b1478749593 Mon Sep 17 00:00:00 2001 From: Ford Date: Mon, 5 Aug 2024 15:38:52 -0700 Subject: [PATCH] common: Improve collision resistance of allocation ids - Effectively, allow user to allocate and reallocate to a deployment within the same epoch --- .../src/indexer-management/allocations.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/indexer-common/src/indexer-management/allocations.ts b/packages/indexer-common/src/indexer-management/allocations.ts index 569632408..91a714efd 100644 --- a/packages/indexer-common/src/indexer-management/allocations.ts +++ b/packages/indexer-common/src/indexer-management/allocations.ts @@ -47,6 +47,7 @@ import pMap from 'p-map' export interface TransactionPreparationContext { activeAllocations: Allocation[] + recentlyClosedAllocations: Allocation[] currentEpoch: BigNumber indexingStatuses: IndexingStatus[] } @@ -239,11 +240,17 @@ export class AllocationManager { } async prepareTransactions(actions: Action[]): Promise { + const currentEpoch = await this.network.contracts.epochManager.currentEpoch() const context: TransactionPreparationContext = { activeAllocations: await this.network.networkMonitor.allocations( AllocationStatus.ACTIVE, ), - currentEpoch: await this.network.contracts.epochManager.currentEpoch(), + recentlyClosedAllocations: + await this.network.networkMonitor.recentlyClosedAllocations( + currentEpoch.toNumber(), + 2, + ), + currentEpoch, indexingStatuses: await this.graphNode.indexingStatus([]), } return await pMap( @@ -389,11 +396,15 @@ export class AllocationManager { } logger.debug('Obtain a unique Allocation ID') + const activeAndRecentlyClosedAllocations: Allocation[] = [ + ...context.recentlyClosedAllocations, + ...context.activeAllocations, + ] const { allocationSigner, allocationId } = uniqueAllocationID( this.network.transactionManager.wallet.mnemonic.phrase, context.currentEpoch.toNumber(), deployment, - context.activeAllocations.map((allocation) => allocation.id), + activeAndRecentlyClosedAllocations.map((allocation) => allocation.id), ) // Double-check whether the allocationID already exists on chain, to