From bc7d0f556e4bbdd1518fa2605181205fc306654b Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Mon, 29 Apr 2024 15:20:57 +0000 Subject: [PATCH] fix: use random id for proving jobs --- .../prover-client/src/prover-pool/memory-proving-queue.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/yarn-project/prover-client/src/prover-pool/memory-proving-queue.ts b/yarn-project/prover-client/src/prover-pool/memory-proving-queue.ts index c3e5194f0276..242b9395498c 100644 --- a/yarn-project/prover-client/src/prover-pool/memory-proving-queue.ts +++ b/yarn-project/prover-client/src/prover-pool/memory-proving-queue.ts @@ -22,6 +22,7 @@ import type { RootRollupInputs, RootRollupPublicInputs, } from '@aztec/circuits.js'; +import { randomBytes } from '@aztec/foundation/crypto'; import { AbortedError, TimeoutError } from '@aztec/foundation/error'; import { MemoryFifo } from '@aztec/foundation/fifo'; import { createDebugLogger } from '@aztec/foundation/log'; @@ -38,12 +39,15 @@ type ProvingJobWithResolvers = { const MAX_RETRIES = 3; +const defaultIdGenerator = () => randomBytes(4).toString('hex'); + export class MemoryProvingQueue implements CircuitProver, ProvingJobSource { - private jobId = 0; private log = createDebugLogger('aztec:prover-client:prover-pool:queue'); private queue = new MemoryFifo(); private jobsInProgress = new Map(); + constructor(private generateId = defaultIdGenerator) {} + async getProvingJob({ timeoutSec = 1 } = {}): Promise | undefined> { try { const job = await this.queue.get(timeoutSec); @@ -119,7 +123,7 @@ export class MemoryProvingQueue implements CircuitProver, ProvingJobSource { ): Promise> { const { promise, resolve, reject } = promiseWithResolvers>(); const item: ProvingJobWithResolvers = { - id: String(this.jobId++), + id: this.generateId(), request, signal, promise,