Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: Improve collision resistance of allocation ids #981

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading