Skip to content

Commit

Permalink
fix: use random id for proving jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed May 1, 2024
1 parent 885cda7 commit 402d8d4
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions yarn-project/prover-client/src/prover-pool/memory-proving-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -35,12 +36,17 @@ type ProvingJobWithResolvers<T extends ProvingRequest = ProvingRequest> = {
signal?: AbortSignal;
} & PromiseWithResolvers<ProvingRequestResult<T['type']>>;

// 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<ProvingJobWithResolvers>();
private jobsInProgress = new Map<string, ProvingJobWithResolvers>();

constructor(private generateId = defaultIdGenerator) {}

async getProvingJob({ timeoutSec = 1 } = {}): Promise<ProvingJob<ProvingRequest> | undefined> {
try {
const job = await this.queue.get(timeoutSec);
Expand Down Expand Up @@ -105,7 +111,7 @@ export class MemoryProvingQueue implements CircuitProver, ProvingJobSource {
): Promise<ProvingRequestResult<T['type']>> {
const { promise, resolve, reject } = promiseWithResolvers<ProvingRequestResult<T['type']>>();
const item: ProvingJobWithResolvers<T> = {
id: String(this.jobId++),
id: this.generateId(),
request,
signal,
promise,
Expand Down

0 comments on commit 402d8d4

Please sign in to comment.