-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add persisted database of proving jobs (#9942)
This PR adds a new proving job store for the ProvingBroker. In this implementation the jobs are stored in an lmdb database and on disk (assuming the broker will have access to a persistent disk) Fix #9532
- Loading branch information
Showing
5 changed files
with
157 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
yarn-project/prover-client/src/proving_broker/proving_job_database/memory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { V2ProofOutput, V2ProvingJob, V2ProvingJobId, V2ProvingJobResult } from '@aztec/circuit-types'; | ||
|
||
import { type ProvingJobDatabase } from '../proving_job_database.js'; | ||
|
||
export class InMemoryDatabase implements ProvingJobDatabase { | ||
private jobs = new Map<V2ProvingJobId, V2ProvingJob>(); | ||
private results = new Map<V2ProvingJobId, V2ProvingJobResult>(); | ||
|
||
getProvingJob(id: V2ProvingJobId): V2ProvingJob | undefined { | ||
return this.jobs.get(id); | ||
} | ||
|
||
getProvingJobResult(id: V2ProvingJobId): V2ProvingJobResult | undefined { | ||
return this.results.get(id); | ||
} | ||
|
||
addProvingJob(request: V2ProvingJob): Promise<void> { | ||
this.jobs.set(request.id, request); | ||
return Promise.resolve(); | ||
} | ||
|
||
setProvingJobResult(id: V2ProvingJobId, value: V2ProofOutput): Promise<void> { | ||
this.results.set(id, { value }); | ||
return Promise.resolve(); | ||
} | ||
|
||
setProvingJobError(id: V2ProvingJobId, error: Error): Promise<void> { | ||
this.results.set(id, { error: String(error) }); | ||
return Promise.resolve(); | ||
} | ||
|
||
deleteProvingJobAndResult(id: V2ProvingJobId): Promise<void> { | ||
this.jobs.delete(id); | ||
this.results.delete(id); | ||
return Promise.resolve(); | ||
} | ||
|
||
*allProvingJobs(): Iterable<[V2ProvingJob, V2ProvingJobResult | undefined]> { | ||
for (const item of this.jobs.values()) { | ||
yield [item, this.results.get(item.id)] as const; | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
yarn-project/prover-client/src/proving_broker/proving_job_database/persisted.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { type V2ProofOutput, V2ProvingJob, type V2ProvingJobId, V2ProvingJobResult } from '@aztec/circuit-types'; | ||
import { type AztecKVStore, type AztecMap } from '@aztec/kv-store'; | ||
|
||
import { type ProvingJobDatabase } from '../proving_job_database.js'; | ||
|
||
export class PersistedProvingJobDatabase implements ProvingJobDatabase { | ||
private jobs: AztecMap<V2ProvingJobId, string>; | ||
private jobResults: AztecMap<V2ProvingJobId, string>; | ||
|
||
constructor(private store: AztecKVStore) { | ||
this.jobs = store.openMap('proving_jobs'); | ||
this.jobResults = store.openMap('proving_job_results'); | ||
} | ||
|
||
async addProvingJob(job: V2ProvingJob): Promise<void> { | ||
await this.jobs.set(job.id, JSON.stringify(job)); | ||
} | ||
|
||
*allProvingJobs(): Iterable<[V2ProvingJob, V2ProvingJobResult | undefined]> { | ||
for (const jobStr of this.jobs.values()) { | ||
const job = V2ProvingJob.parse(JSON.parse(jobStr)); | ||
const resultStr = this.jobResults.get(job.id); | ||
const result = resultStr ? V2ProvingJobResult.parse(JSON.parse(resultStr)) : undefined; | ||
yield [job, result]; | ||
} | ||
} | ||
|
||
deleteProvingJobAndResult(id: V2ProvingJobId): Promise<void> { | ||
return this.store.transaction(() => { | ||
void this.jobs.delete(id); | ||
void this.jobResults.delete(id); | ||
}); | ||
} | ||
|
||
async setProvingJobError(id: V2ProvingJobId, err: Error): Promise<void> { | ||
const res: V2ProvingJobResult = { error: err.message }; | ||
await this.jobResults.set(id, JSON.stringify(res)); | ||
} | ||
|
||
async setProvingJobResult(id: V2ProvingJobId, value: V2ProofOutput): Promise<void> { | ||
const res: V2ProvingJobResult = { value }; | ||
await this.jobResults.set(id, JSON.stringify(res)); | ||
} | ||
} |