From 0e0fc585b9329371e5f89accf10ff1b7a08749c0 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 7 May 2024 07:33:26 +0300 Subject: [PATCH] fix: use random id for proving jobs (#6084) This PR removes the incrementing numeric id for proving jobs with a random string --- .../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 1f93a17f3e8..9980a093e7e 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,