Skip to content

Commit

Permalink
common: Improve collision resistance of allocation ids
Browse files Browse the repository at this point in the history
- Effectively, allow user to allocate and reallocate to a deployment
within the same epoch
  • Loading branch information
fordN committed Aug 14, 2024
1 parent b2188e6 commit 016bd08
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/indexer-common/src/indexer-management/allocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import pMap from 'p-map'

export interface TransactionPreparationContext {
activeAllocations: Allocation[]
recentlyClosedAllocations: Allocation[]
currentEpoch: BigNumber
indexingStatuses: IndexingStatus[]
}
Expand Down Expand Up @@ -239,11 +240,17 @@ export class AllocationManager {
}

async prepareTransactions(actions: Action[]): Promise<PopulateTransactionResult[]> {
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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 016bd08

Please sign in to comment.