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 88afa9859ed..617c168d9fa 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 @@ -8,20 +8,21 @@ import { type PublicKernelNonTailRequest, type PublicKernelTailRequest, } from '@aztec/circuit-types'; -import type { - BaseOrMergeRollupPublicInputs, - BaseParityInputs, - BaseRollupInputs, - KernelCircuitPublicInputs, - MergeRollupInputs, - NESTED_RECURSIVE_PROOF_LENGTH, - PublicKernelCircuitPublicInputs, - RECURSIVE_PROOF_LENGTH, - RootParityInput, - RootParityInputs, - RootRollupInputs, - RootRollupPublicInputs, +import { + type BaseOrMergeRollupPublicInputs, + type BaseParityInputs, + type BaseRollupInputs, + type KernelCircuitPublicInputs, + type MergeRollupInputs, + type NESTED_RECURSIVE_PROOF_LENGTH, + type PublicKernelCircuitPublicInputs, + type RECURSIVE_PROOF_LENGTH, + type RootParityInput, + type RootParityInputs, + type RootRollupInputs, + type 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'; @@ -35,12 +36,17 @@ type ProvingJobWithResolvers = { signal?: AbortSignal; } & PromiseWithResolvers>; +// this doesn't need to be crazy high as it's only meant to be unique while the job is active +// 4 bytes -> 2^32 jobs in the queue +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); @@ -105,7 +111,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,