Skip to content

Commit 86591f4

Browse files
committed
fix: handle legacy verification job payloads
1 parent 5cc0b03 commit 86591f4

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

apps/contract-verification/src/job-runner.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import { runVerificationJob } from '#route.verify.ts'
77

88
const logger = getLogger(['tempo', 'job-runner'])
99

10+
type LegacyStoredJob = Pick<
11+
VerificationJob,
12+
'jobId' | 'chainId' | 'address'
13+
> & {
14+
body: Omit<VerificationJob, 'jobId' | 'chainId' | 'address'>
15+
}
16+
1017
export class VerificationJobRunner extends DurableObject<Cloudflare.Env> {
1118
async enqueue(job: VerificationJob): Promise<void> {
1219
logger.info('job_enqueued', {
@@ -20,12 +27,27 @@ export class VerificationJobRunner extends DurableObject<Cloudflare.Env> {
2027
}
2128

2229
override async alarm(): Promise<void> {
23-
const job = await this.ctx.storage.get<VerificationJob>('job')
24-
if (!job) {
30+
const storedJob = await this.ctx.storage.get<
31+
VerificationJob | LegacyStoredJob
32+
>('job')
33+
if (!storedJob) {
2534
logger.warn('alarm_job_missing')
2635
return
2736
}
2837

38+
const job =
39+
'body' in storedJob
40+
? {
41+
jobId: storedJob.jobId,
42+
chainId: storedJob.chainId,
43+
address: storedJob.address,
44+
stdJsonInput: storedJob.body.stdJsonInput,
45+
compilerVersion: storedJob.body.compilerVersion,
46+
contractIdentifier: storedJob.body.contractIdentifier,
47+
creationTransactionHash: storedJob.body.creationTransactionHash,
48+
}
49+
: storedJob
50+
2951
logger.info('job_started', {
3052
jobId: job.jobId,
3153
chainId: job.chainId,

apps/contract-verification/test/unit/job-runner-do.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,34 @@ describe('VerificationJobRunner Durable Object', () => {
182182
expect(row?.errorCode).toBe('internal_error')
183183
})
184184

185+
it('handles legacy stored job payloads written before the schema flattening change', async () => {
186+
const jobId = globalThis.crypto.randomUUID()
187+
await insertJobRow(jobId)
188+
189+
const stub = getStub(jobId)
190+
await runInDurableObject(stub, async (_instance, state) => {
191+
const job = makeJob(jobId)
192+
await state.storage.put('job', {
193+
jobId: job.jobId,
194+
chainId: job.chainId,
195+
address: job.address,
196+
body: {
197+
stdJsonInput: job.stdJsonInput,
198+
compilerVersion: job.compilerVersion,
199+
contractIdentifier: job.contractIdentifier,
200+
creationTransactionHash: job.creationTransactionHash,
201+
},
202+
})
203+
await state.storage.setAlarm(Date.now() + 60_000)
204+
})
205+
206+
await runDurableObjectAlarm(stub)
207+
208+
const row = await getJobRow(jobId)
209+
expect(row).not.toBeNull()
210+
expect(row?.completedAt).not.toBeNull()
211+
})
212+
185213
it('does not leave a dangling alarm after processing', async () => {
186214
const jobId = globalThis.crypto.randomUUID()
187215
await insertJobRow(jobId)

0 commit comments

Comments
 (0)