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 5, 2024
1 parent 980a62e commit f1dc188
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -38,12 +39,15 @@ type ProvingJobWithResolvers<T extends ProvingRequest = ProvingRequest> = {

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<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 @@ -119,7 +123,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 f1dc188

Please sign in to comment.