diff --git a/yarn-project/prover-client/src/proving_broker/proving_broker.test.ts b/yarn-project/prover-client/src/proving_broker/proving_broker.test.ts index 42ce07819f2..e0609ce22dd 100644 --- a/yarn-project/prover-client/src/proving_broker/proving_broker.test.ts +++ b/yarn-project/prover-client/src/proving_broker/proving_broker.test.ts @@ -63,6 +63,28 @@ describe.each([ await broker.stop(); }); + it('refuses stale jobs', async () => { + const id = makeProvingJobId(); + await broker.enqueueProvingJob({ + id, + epochNumber: 42, + type: ProvingRequestType.BASE_PARITY, + inputsUri: makeInputsUri(), + }); + expect(await broker.getProvingJobStatus(id)).toEqual({ status: 'in-queue' }); + + const id2 = makeProvingJobId(); + await expect( + broker.enqueueProvingJob({ + id: id2, + epochNumber: 1, + type: ProvingRequestType.PRIVATE_BASE_ROLLUP, + inputsUri: makeInputsUri(), + }), + ).rejects.toThrow(); + await assertJobStatus(id2, 'not-found'); + }); + it('enqueues jobs', async () => { const id = makeProvingJobId(); await broker.enqueueProvingJob({ @@ -210,15 +232,7 @@ describe.each([ inputsUri: makeInputsUri(), }; - const provingJob3: ProvingJob = { - id: makeProvingJobId(), - type: ProvingRequestType.BASE_PARITY, - epochNumber: 3, - inputsUri: makeInputsUri(), - }; - await broker.enqueueProvingJob(provingJob2); - await broker.enqueueProvingJob(provingJob3); await broker.enqueueProvingJob(provingJob1); await getAndAssertNextJobId(provingJob1.id, ProvingRequestType.BASE_PARITY); diff --git a/yarn-project/prover-client/src/proving_broker/proving_broker.ts b/yarn-project/prover-client/src/proving_broker/proving_broker.ts index 4086c5b3803..6edf6c824e2 100644 --- a/yarn-project/prover-client/src/proving_broker/proving_broker.ts +++ b/yarn-project/prover-client/src/proving_broker/proving_broker.ts @@ -181,6 +181,13 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Tr return; } + if (this.isJobStale(job)) { + this.logger.warn(`Tried enqueueing stale proving job id=${job.id} epochNumber=${job.epochNumber}`, { + provingJobId: job.id, + }); + throw new Error(`Epoch too old: job epoch ${job.epochNumber}, current epoch: ${this.epochHeight}`); + } + this.logger.info(`New proving job id=${job.id} epochNumber=${job.epochNumber}`, { provingJobId: job.id }); try { // do this first so it acts as a "lock". If this job is enqueued again while we're saving it the if at the top will catch it.