Skip to content

Commit

Permalink
fix: guard against stale proving jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Dec 13, 2024
1 parent 2461ba6 commit b6e7c10
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b6e7c10

Please sign in to comment.