@aztec/prover-client 0.0.0-test.1 → 0.0.1-commit.023c3e5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/config.d.ts +8 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +12 -2
- package/dest/index.d.ts +1 -1
- package/dest/light/index.d.ts +2 -0
- package/dest/light/index.d.ts.map +1 -0
- package/dest/light/index.js +1 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts +47 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
- package/dest/light/lightweight_checkpoint_builder.js +200 -0
- package/dest/mocks/fixtures.d.ts +8 -8
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +36 -17
- package/dest/mocks/test_context.d.ts +43 -32
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +149 -87
- package/dest/orchestrator/block-building-helpers.d.ts +37 -30
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +170 -189
- package/dest/orchestrator/block-proving-state.d.ts +70 -48
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +282 -177
- package/dest/orchestrator/checkpoint-proving-state.d.ts +76 -0
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-proving-state.js +243 -0
- package/dest/orchestrator/epoch-proving-state.d.ts +43 -28
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +177 -73
- package/dest/orchestrator/index.d.ts +1 -1
- package/dest/orchestrator/orchestrator.d.ts +53 -35
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +855 -302
- package/dest/orchestrator/orchestrator_metrics.d.ts +1 -1
- package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator_metrics.js +2 -6
- package/dest/orchestrator/tx-proving-state.d.ts +15 -12
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +27 -44
- package/dest/prover-client/factory.d.ts +3 -3
- package/dest/prover-client/factory.d.ts.map +1 -1
- package/dest/prover-client/index.d.ts +1 -1
- package/dest/prover-client/prover-client.d.ts +5 -5
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +11 -7
- package/dest/prover-client/server-epoch-prover.d.ts +16 -12
- package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
- package/dest/prover-client/server-epoch-prover.js +11 -11
- package/dest/proving_broker/broker_prover_facade.d.ts +28 -19
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +62 -43
- package/dest/proving_broker/config.d.ts +23 -10
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +29 -6
- package/dest/proving_broker/factory.d.ts +2 -2
- package/dest/proving_broker/factory.d.ts.map +1 -1
- package/dest/proving_broker/factory.js +5 -1
- package/dest/proving_broker/fixtures.d.ts +3 -2
- package/dest/proving_broker/fixtures.d.ts.map +1 -1
- package/dest/proving_broker/fixtures.js +3 -2
- package/dest/proving_broker/index.d.ts +1 -1
- package/dest/proving_broker/proof_store/factory.d.ts +2 -2
- package/dest/proving_broker/proof_store/factory.js +1 -1
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +1 -1
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/gcs_proof_store.js +1 -0
- package/dest/proving_broker/proof_store/index.d.ts +2 -1
- package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/index.js +1 -0
- package/dest/proving_broker/proof_store/inline_proof_store.d.ts +1 -1
- package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/proof_store.d.ts +1 -1
- package/dest/proving_broker/proving_agent.d.ts +8 -12
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.js +86 -65
- package/dest/proving_broker/proving_broker.d.ts +13 -4
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +40 -33
- package/dest/proving_broker/proving_broker_database/memory.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/memory.js +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.d.ts +5 -3
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.js +401 -11
- package/dest/proving_broker/proving_broker_database.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.js +15 -35
- package/dest/proving_broker/proving_job_controller.d.ts +11 -10
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.js +92 -62
- package/dest/proving_broker/rpc.d.ts +4 -6
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +1 -4
- package/dest/test/mock_proof_store.d.ts +9 -0
- package/dest/test/mock_proof_store.d.ts.map +1 -0
- package/dest/test/mock_proof_store.js +10 -0
- package/dest/test/mock_prover.d.ts +23 -17
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +38 -20
- package/package.json +33 -31
- package/src/config.ts +25 -9
- package/src/light/index.ts +1 -0
- package/src/light/lightweight_checkpoint_builder.ts +289 -0
- package/src/mocks/fixtures.ts +46 -40
- package/src/mocks/test_context.ts +223 -116
- package/src/orchestrator/block-building-helpers.ts +258 -334
- package/src/orchestrator/block-proving-state.ts +325 -231
- package/src/orchestrator/checkpoint-proving-state.ts +349 -0
- package/src/orchestrator/epoch-proving-state.ts +237 -111
- package/src/orchestrator/orchestrator.ts +653 -343
- package/src/orchestrator/orchestrator_metrics.ts +2 -6
- package/src/orchestrator/tx-proving-state.ts +48 -66
- package/src/prover-client/factory.ts +6 -2
- package/src/prover-client/prover-client.ts +41 -29
- package/src/prover-client/server-epoch-prover.ts +40 -22
- package/src/proving_broker/broker_prover_facade.ts +212 -131
- package/src/proving_broker/config.ts +34 -7
- package/src/proving_broker/factory.ts +2 -1
- package/src/proving_broker/fixtures.ts +8 -3
- package/src/proving_broker/proof_store/factory.ts +1 -1
- package/src/proving_broker/proof_store/gcs_proof_store.ts +5 -1
- package/src/proving_broker/proof_store/index.ts +1 -0
- package/src/proving_broker/proof_store/inline_proof_store.ts +1 -1
- package/src/proving_broker/proving_agent.ts +95 -66
- package/src/proving_broker/proving_broker.ts +57 -41
- package/src/proving_broker/proving_broker_database/memory.ts +3 -2
- package/src/proving_broker/proving_broker_database/persisted.ts +29 -13
- package/src/proving_broker/proving_broker_database.ts +2 -1
- package/src/proving_broker/proving_broker_instrumentation.ts +14 -35
- package/src/proving_broker/proving_job_controller.ts +100 -83
- package/src/proving_broker/rpc.ts +1 -6
- package/src/test/mock_proof_store.ts +14 -0
- package/src/test/mock_prover.ts +156 -64
- package/dest/bin/get-proof-inputs.d.ts +0 -2
- package/dest/bin/get-proof-inputs.d.ts.map +0 -1
- package/dest/bin/get-proof-inputs.js +0 -51
- package/dest/block_builder/index.d.ts +0 -6
- package/dest/block_builder/index.d.ts.map +0 -1
- package/dest/block_builder/index.js +0 -1
- package/dest/block_builder/light.d.ts +0 -33
- package/dest/block_builder/light.d.ts.map +0 -1
- package/dest/block_builder/light.js +0 -82
- package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
- package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
- package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
- package/src/bin/get-proof-inputs.ts +0 -59
- package/src/block_builder/index.ts +0 -6
- package/src/block_builder/light.ts +0 -101
- package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
|
@@ -52,7 +52,7 @@ export class InlineProofStore implements ProofStore {
|
|
|
52
52
|
return (PREFIX + SEPARATOR + encoded) as ProofUri;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
private decode<T>(uri: ProofUri, schema: ZodFor<T>):
|
|
55
|
+
private decode<T>(uri: ProofUri, schema: ZodFor<T>): T {
|
|
56
56
|
const [prefix, data] = uri.split(SEPARATOR);
|
|
57
57
|
if (prefix !== PREFIX) {
|
|
58
58
|
throw new Error('Invalid proof input URI: ' + prefix);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbortError } from '@aztec/foundation/error';
|
|
2
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
2
3
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
3
4
|
import { truncate } from '@aztec/foundation/string';
|
|
4
|
-
import { Timer } from '@aztec/foundation/timer';
|
|
5
5
|
import { ProvingError } from '@aztec/stdlib/errors';
|
|
6
6
|
import type {
|
|
7
|
-
|
|
7
|
+
GetProvingJobResponse,
|
|
8
|
+
ProverAgentStatus,
|
|
8
9
|
ProvingJobConsumer,
|
|
9
10
|
ProvingJobId,
|
|
10
11
|
ProvingJobInputs,
|
|
@@ -12,28 +13,17 @@ import type {
|
|
|
12
13
|
ServerCircuitProver,
|
|
13
14
|
} from '@aztec/stdlib/interfaces/server';
|
|
14
15
|
import { ProvingRequestType } from '@aztec/stdlib/proofs';
|
|
15
|
-
import {
|
|
16
|
-
type TelemetryClient,
|
|
17
|
-
type Traceable,
|
|
18
|
-
type Tracer,
|
|
19
|
-
getTelemetryClient,
|
|
20
|
-
trackSpan,
|
|
21
|
-
} from '@aztec/telemetry-client';
|
|
22
16
|
|
|
23
17
|
import type { ProofStore } from './proof_store/index.js';
|
|
24
|
-
import { ProvingAgentInstrumentation } from './proving_agent_instrumentation.js';
|
|
25
18
|
import { ProvingJobController, ProvingJobControllerStatus } from './proving_job_controller.js';
|
|
26
19
|
|
|
27
20
|
/**
|
|
28
21
|
* A helper class that encapsulates a circuit prover and connects it to a job source.
|
|
29
22
|
*/
|
|
30
|
-
export class ProvingAgent
|
|
23
|
+
export class ProvingAgent {
|
|
31
24
|
private currentJobController?: ProvingJobController;
|
|
32
25
|
private runningPromise: RunningPromise;
|
|
33
|
-
private
|
|
34
|
-
private idleTimer: Timer | undefined;
|
|
35
|
-
|
|
36
|
-
public readonly tracer: Tracer;
|
|
26
|
+
private log: Logger;
|
|
37
27
|
|
|
38
28
|
constructor(
|
|
39
29
|
/** The source of proving jobs */
|
|
@@ -46,12 +36,9 @@ export class ProvingAgent implements Traceable {
|
|
|
46
36
|
private proofAllowList: Array<ProvingRequestType> = [],
|
|
47
37
|
/** How long to wait between jobs */
|
|
48
38
|
private pollIntervalMs = 1000,
|
|
49
|
-
|
|
50
|
-
client: TelemetryClient = getTelemetryClient(),
|
|
51
|
-
private log = createLogger('prover-client:proving-agent'),
|
|
39
|
+
bindings?: LoggerBindings,
|
|
52
40
|
) {
|
|
53
|
-
this.
|
|
54
|
-
this.instrumentation = new ProvingAgentInstrumentation(client);
|
|
41
|
+
this.log = createLogger('prover-client:proving-agent', bindings);
|
|
55
42
|
this.runningPromise = new RunningPromise(this.work.bind(this), this.log, this.pollIntervalMs);
|
|
56
43
|
}
|
|
57
44
|
|
|
@@ -64,7 +51,6 @@ export class ProvingAgent implements Traceable {
|
|
|
64
51
|
}
|
|
65
52
|
|
|
66
53
|
public start(): void {
|
|
67
|
-
this.idleTimer = new Timer();
|
|
68
54
|
this.runningPromise.start();
|
|
69
55
|
}
|
|
70
56
|
|
|
@@ -73,41 +59,77 @@ export class ProvingAgent implements Traceable {
|
|
|
73
59
|
await this.runningPromise.stop();
|
|
74
60
|
}
|
|
75
61
|
|
|
76
|
-
|
|
62
|
+
public getStatus(): ProverAgentStatus {
|
|
63
|
+
if (this.currentJobController) {
|
|
64
|
+
return {
|
|
65
|
+
status: 'proving',
|
|
66
|
+
jobId: this.currentJobController.getJobId(),
|
|
67
|
+
proofType: this.currentJobController.getProofType(),
|
|
68
|
+
startedAtISO: new Date(this.currentJobController.getStartedAt()).toISOString(),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return this.runningPromise.isRunning() ? { status: 'running' } : { status: 'stopped' };
|
|
73
|
+
}
|
|
74
|
+
|
|
77
75
|
private async work() {
|
|
78
|
-
// every tick we need to
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
76
|
+
// every tick we need to take one of the following actions:
|
|
77
|
+
// 1. send a hearbeat to the broker that we're working on some job
|
|
78
|
+
// 2. if the job is complete, send its result to the broker
|
|
79
|
+
// 3. get a job from the broker
|
|
80
|
+
// Any one of these actions could give us a new job to work on. If that happens we abort the current job.
|
|
81
|
+
//
|
|
82
|
+
// This loop gets triggered in one of two ways:
|
|
83
|
+
// - either on a timer (see pollIntervalMs)
|
|
84
|
+
// - or when a proof completes
|
|
85
|
+
let maybeJob: GetProvingJobResponse | undefined;
|
|
86
|
+
|
|
87
|
+
if (this.currentJobController) {
|
|
88
|
+
const status = this.currentJobController.getStatus();
|
|
89
|
+
const jobId = this.currentJobController.getJobId();
|
|
90
|
+
const proofType = this.currentJobController.getProofType();
|
|
91
|
+
const startedAt = this.currentJobController.getStartedAt();
|
|
92
|
+
const result = this.currentJobController.getResult();
|
|
93
|
+
|
|
94
|
+
if (status === ProvingJobControllerStatus.RUNNING) {
|
|
95
|
+
maybeJob = await this.broker.reportProvingJobProgress(jobId, startedAt, { allowList: this.proofAllowList });
|
|
96
|
+
} else if (status === ProvingJobControllerStatus.DONE) {
|
|
97
|
+
if (result) {
|
|
98
|
+
maybeJob = await this.reportResult(jobId, proofType, result);
|
|
99
|
+
} else {
|
|
100
|
+
this.log.warn(
|
|
101
|
+
`Job controller for job ${this.currentJobController.getJobId()} is done but doesn't have a result`,
|
|
102
|
+
{ jobId },
|
|
103
|
+
);
|
|
104
|
+
maybeJob = await this.reportResult(
|
|
105
|
+
jobId,
|
|
106
|
+
proofType,
|
|
107
|
+
new ProvingError('No result found after proving', undefined, /* retry */ true),
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
this.currentJobController = undefined;
|
|
112
|
+
} else {
|
|
113
|
+
// IDLE status should not be seen because a job is started as soon as it is created
|
|
114
|
+
this.log.warn(`Idle job controller for job: ${this.currentJobController.getJobId()}. Skipping main loop work`, {
|
|
115
|
+
jobId: this.currentJobController.getJobId(),
|
|
116
|
+
});
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
89
119
|
} else {
|
|
90
120
|
maybeJob = await this.broker.getProvingJob({ allowList: this.proofAllowList });
|
|
91
121
|
}
|
|
92
122
|
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (this.idleTimer) {
|
|
98
|
-
this.instrumentation.recordIdleTime(this.idleTimer);
|
|
123
|
+
if (maybeJob) {
|
|
124
|
+
await this.startJob(maybeJob);
|
|
99
125
|
}
|
|
100
|
-
this.idleTimer = undefined;
|
|
101
|
-
|
|
102
|
-
const { job, time } = maybeJob;
|
|
103
|
-
await this.startJob(job, time);
|
|
104
126
|
}
|
|
105
127
|
|
|
106
|
-
private async startJob(job:
|
|
128
|
+
private async startJob({ job, time: startedAt }: GetProvingJobResponse): Promise<void> {
|
|
107
129
|
let abortedProofJobId: string | undefined;
|
|
108
130
|
let abortedProofName: string | undefined;
|
|
109
131
|
|
|
110
|
-
if (this.currentJobController?.getStatus() === ProvingJobControllerStatus.
|
|
132
|
+
if (this.currentJobController?.getStatus() === ProvingJobControllerStatus.RUNNING) {
|
|
111
133
|
abortedProofJobId = this.currentJobController.getJobId();
|
|
112
134
|
abortedProofName = this.currentJobController.getProofTypeName();
|
|
113
135
|
this.currentJobController?.abort();
|
|
@@ -116,13 +138,13 @@ export class ProvingAgent implements Traceable {
|
|
|
116
138
|
let inputs: ProvingJobInputs;
|
|
117
139
|
try {
|
|
118
140
|
inputs = await this.proofStore.getProofInput(job.inputsUri);
|
|
119
|
-
} catch
|
|
141
|
+
} catch {
|
|
120
142
|
const maybeJob = await this.broker.reportProvingJobError(job.id, 'Failed to load proof inputs', true, {
|
|
121
143
|
allowList: this.proofAllowList,
|
|
122
144
|
});
|
|
123
145
|
|
|
124
146
|
if (maybeJob) {
|
|
125
|
-
return this.startJob(maybeJob
|
|
147
|
+
return this.startJob(maybeJob);
|
|
126
148
|
}
|
|
127
149
|
|
|
128
150
|
return;
|
|
@@ -134,7 +156,12 @@ export class ProvingAgent implements Traceable {
|
|
|
134
156
|
job.epochNumber,
|
|
135
157
|
startedAt,
|
|
136
158
|
this.circuitProver,
|
|
137
|
-
|
|
159
|
+
() => {
|
|
160
|
+
// trigger a run of the main work loop when proving completes
|
|
161
|
+
// no need to await this here. The controller will stay alive (in DONE state) until the result is send to the broker
|
|
162
|
+
void this.runningPromise.trigger();
|
|
163
|
+
},
|
|
164
|
+
this.log.getBindings(),
|
|
138
165
|
);
|
|
139
166
|
|
|
140
167
|
if (abortedProofJobId) {
|
|
@@ -154,28 +181,30 @@ export class ProvingAgent implements Traceable {
|
|
|
154
181
|
this.currentJobController.start();
|
|
155
182
|
}
|
|
156
183
|
|
|
157
|
-
|
|
184
|
+
private async reportResult<T extends ProvingRequestType>(
|
|
158
185
|
jobId: ProvingJobId,
|
|
159
186
|
type: T,
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
187
|
+
result: ProvingJobResultsMap[T] | Error,
|
|
188
|
+
): Promise<GetProvingJobResponse | undefined> {
|
|
189
|
+
let maybeJob: GetProvingJobResponse | undefined;
|
|
190
|
+
if (result instanceof AbortError) {
|
|
191
|
+
// no-op
|
|
192
|
+
this.log.warn(`Job id=${jobId} was aborted. Not reporting result back to broker`, result);
|
|
193
|
+
} else if (result instanceof Error) {
|
|
194
|
+
const retry = result.name === ProvingError.NAME ? (result as ProvingError).retry : false;
|
|
195
|
+
this.log.error(
|
|
196
|
+
`Job id=${jobId} type=${ProvingRequestType[type]} failed err=${result.message} retry=${retry}`,
|
|
197
|
+
result,
|
|
198
|
+
);
|
|
199
|
+
maybeJob = await this.broker.reportProvingJobError(jobId, result.message, retry, {
|
|
200
|
+
allowList: this.proofAllowList,
|
|
201
|
+
});
|
|
202
|
+
} else {
|
|
169
203
|
const outputUri = await this.proofStore.saveProofOutput(jobId, type, result);
|
|
170
204
|
this.log.info(`Job id=${jobId} type=${ProvingRequestType[type]} completed outputUri=${truncate(outputUri)}`);
|
|
171
205
|
maybeJob = await this.broker.reportProvingJobSuccess(jobId, outputUri, { allowList: this.proofAllowList });
|
|
172
206
|
}
|
|
173
207
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
await this.startJob(job, time);
|
|
177
|
-
} else {
|
|
178
|
-
this.idleTimer = new Timer();
|
|
179
|
-
}
|
|
180
|
-
};
|
|
208
|
+
return maybeJob;
|
|
209
|
+
}
|
|
181
210
|
}
|
|
@@ -1,26 +1,22 @@
|
|
|
1
|
+
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
3
|
import { type PromiseWithResolvers, RunningPromise, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
3
4
|
import { PriorityMemoryQueue } from '@aztec/foundation/queue';
|
|
4
5
|
import { Timer } from '@aztec/foundation/timer';
|
|
5
|
-
import
|
|
6
|
-
GetProvingJobResponse,
|
|
7
|
-
ProofUri,
|
|
8
|
-
ProvingJob,
|
|
9
|
-
ProvingJobConsumer,
|
|
10
|
-
ProvingJobFilter,
|
|
11
|
-
ProvingJobId,
|
|
12
|
-
ProvingJobProducer,
|
|
13
|
-
ProvingJobSettledResult,
|
|
14
|
-
ProvingJobStatus,
|
|
6
|
+
import {
|
|
7
|
+
type GetProvingJobResponse,
|
|
8
|
+
type ProofUri,
|
|
9
|
+
type ProvingJob,
|
|
10
|
+
type ProvingJobConsumer,
|
|
11
|
+
type ProvingJobFilter,
|
|
12
|
+
type ProvingJobId,
|
|
13
|
+
type ProvingJobProducer,
|
|
14
|
+
type ProvingJobSettledResult,
|
|
15
|
+
type ProvingJobStatus,
|
|
16
|
+
tryStop,
|
|
15
17
|
} from '@aztec/stdlib/interfaces/server';
|
|
16
18
|
import { ProvingRequestType } from '@aztec/stdlib/proofs';
|
|
17
|
-
import {
|
|
18
|
-
type TelemetryClient,
|
|
19
|
-
type Traceable,
|
|
20
|
-
type Tracer,
|
|
21
|
-
getTelemetryClient,
|
|
22
|
-
trackSpan,
|
|
23
|
-
} from '@aztec/telemetry-client';
|
|
19
|
+
import { type TelemetryClient, type Traceable, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
24
20
|
|
|
25
21
|
import assert from 'assert';
|
|
26
22
|
|
|
@@ -43,20 +39,33 @@ type EnqueuedProvingJob = Pick<ProvingJob, 'id' | 'epochNumber'>;
|
|
|
43
39
|
export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Traceable {
|
|
44
40
|
private queues: ProvingQueues = {
|
|
45
41
|
[ProvingRequestType.PUBLIC_VM]: new PriorityMemoryQueue<EnqueuedProvingJob>(provingJobComparator),
|
|
46
|
-
[ProvingRequestType.
|
|
42
|
+
[ProvingRequestType.PUBLIC_CHONK_VERIFIER]: new PriorityMemoryQueue<EnqueuedProvingJob>(provingJobComparator),
|
|
47
43
|
|
|
48
|
-
[ProvingRequestType.
|
|
49
|
-
[ProvingRequestType.
|
|
50
|
-
[ProvingRequestType.
|
|
44
|
+
[ProvingRequestType.PRIVATE_TX_BASE_ROLLUP]: new PriorityMemoryQueue<EnqueuedProvingJob>(provingJobComparator),
|
|
45
|
+
[ProvingRequestType.PUBLIC_TX_BASE_ROLLUP]: new PriorityMemoryQueue<EnqueuedProvingJob>(provingJobComparator),
|
|
46
|
+
[ProvingRequestType.TX_MERGE_ROLLUP]: new PriorityMemoryQueue<EnqueuedProvingJob>(provingJobComparator),
|
|
51
47
|
[ProvingRequestType.ROOT_ROLLUP]: new PriorityMemoryQueue<EnqueuedProvingJob>(provingJobComparator),
|
|
52
48
|
|
|
53
49
|
[ProvingRequestType.BLOCK_MERGE_ROLLUP]: new PriorityMemoryQueue<EnqueuedProvingJob>(provingJobComparator),
|
|
50
|
+
[ProvingRequestType.BLOCK_ROOT_FIRST_ROLLUP]: new PriorityMemoryQueue<EnqueuedProvingJob>(provingJobComparator),
|
|
51
|
+
[ProvingRequestType.BLOCK_ROOT_SINGLE_TX_FIRST_ROLLUP]: new PriorityMemoryQueue<EnqueuedProvingJob>(
|
|
52
|
+
provingJobComparator,
|
|
53
|
+
),
|
|
54
|
+
[ProvingRequestType.BLOCK_ROOT_EMPTY_TX_FIRST_ROLLUP]: new PriorityMemoryQueue<EnqueuedProvingJob>(
|
|
55
|
+
provingJobComparator,
|
|
56
|
+
),
|
|
54
57
|
[ProvingRequestType.BLOCK_ROOT_ROLLUP]: new PriorityMemoryQueue<EnqueuedProvingJob>(provingJobComparator),
|
|
55
|
-
[ProvingRequestType.
|
|
56
|
-
|
|
58
|
+
[ProvingRequestType.BLOCK_ROOT_SINGLE_TX_ROLLUP]: new PriorityMemoryQueue<EnqueuedProvingJob>(provingJobComparator),
|
|
59
|
+
|
|
60
|
+
[ProvingRequestType.CHECKPOINT_ROOT_ROLLUP]: new PriorityMemoryQueue<EnqueuedProvingJob>(provingJobComparator),
|
|
61
|
+
[ProvingRequestType.CHECKPOINT_ROOT_SINGLE_BLOCK_ROLLUP]: new PriorityMemoryQueue<EnqueuedProvingJob>(
|
|
62
|
+
provingJobComparator,
|
|
63
|
+
),
|
|
64
|
+
[ProvingRequestType.CHECKPOINT_MERGE_ROLLUP]: new PriorityMemoryQueue<EnqueuedProvingJob>(provingJobComparator),
|
|
65
|
+
[ProvingRequestType.CHECKPOINT_PADDING_ROLLUP]: new PriorityMemoryQueue<EnqueuedProvingJob>(provingJobComparator),
|
|
57
66
|
|
|
58
|
-
[ProvingRequestType.
|
|
59
|
-
[ProvingRequestType.
|
|
67
|
+
[ProvingRequestType.PARITY_BASE]: new PriorityMemoryQueue<EnqueuedProvingJob>(provingJobComparator),
|
|
68
|
+
[ProvingRequestType.PARITY_ROOT]: new PriorityMemoryQueue<EnqueuedProvingJob>(provingJobComparator),
|
|
60
69
|
};
|
|
61
70
|
|
|
62
71
|
// holds a copy of the database in memory in order to quickly fulfill requests
|
|
@@ -93,7 +102,7 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Tr
|
|
|
93
102
|
/**
|
|
94
103
|
* The broker keeps track of the highest epoch its seen.
|
|
95
104
|
* This information is used for garbage collection: once it reaches the next epoch, it can start pruning the database of old state.
|
|
96
|
-
* It is important that this value is
|
|
105
|
+
* It is important that this value is initialized to zero. This ensures that we don't delete any old jobs until the current
|
|
97
106
|
* process instance receives a job request informing it of the actual current highest epoch
|
|
98
107
|
* Example:
|
|
99
108
|
* proving epoch 11 - the broker will wipe all jobs for epochs 9 and lower
|
|
@@ -184,7 +193,7 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Tr
|
|
|
184
193
|
this.logger.warn('ProvingBroker not started');
|
|
185
194
|
return Promise.resolve();
|
|
186
195
|
}
|
|
187
|
-
await this.cleanupPromise
|
|
196
|
+
await tryStop(this.cleanupPromise);
|
|
188
197
|
}
|
|
189
198
|
|
|
190
199
|
public enqueueProvingJob(job: ProvingJob): Promise<ProvingJobStatus> {
|
|
@@ -287,6 +296,7 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Tr
|
|
|
287
296
|
this.resultsCache.delete(id);
|
|
288
297
|
this.inProgress.delete(id);
|
|
289
298
|
this.retries.delete(id);
|
|
299
|
+
this.enqueuedAt.delete(id);
|
|
290
300
|
}
|
|
291
301
|
}
|
|
292
302
|
|
|
@@ -313,7 +323,6 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Tr
|
|
|
313
323
|
return Promise.resolve(notifications.concat(completedJobs));
|
|
314
324
|
}
|
|
315
325
|
|
|
316
|
-
// eslint-disable-next-line require-await
|
|
317
326
|
#getProvingJob(filter: ProvingJobFilter = { allowList: [] }): { job: ProvingJob; time: number } | undefined {
|
|
318
327
|
const allowedProofs: ProvingRequestType[] =
|
|
319
328
|
Array.isArray(filter.allowList) && filter.allowList.length > 0
|
|
@@ -340,6 +349,8 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Tr
|
|
|
340
349
|
const enqueuedAt = this.enqueuedAt.get(job.id);
|
|
341
350
|
if (enqueuedAt) {
|
|
342
351
|
this.instrumentation.recordJobWait(job.type, enqueuedAt);
|
|
352
|
+
// we can clear this flag now.
|
|
353
|
+
this.enqueuedAt.delete(job.id);
|
|
343
354
|
}
|
|
344
355
|
|
|
345
356
|
return { job, time };
|
|
@@ -548,13 +559,12 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Tr
|
|
|
548
559
|
return this.#getProvingJob(filter);
|
|
549
560
|
}
|
|
550
561
|
|
|
551
|
-
@trackSpan('ProvingBroker.cleanupPass')
|
|
552
562
|
private async cleanupPass() {
|
|
553
563
|
this.cleanupStaleJobs();
|
|
554
564
|
this.reEnqueueExpiredJobs();
|
|
555
565
|
const oldestEpochToKeep = this.oldestEpochToKeep();
|
|
556
566
|
if (oldestEpochToKeep > 0) {
|
|
557
|
-
await this.database.deleteAllProvingJobsOlderThanEpoch(oldestEpochToKeep);
|
|
567
|
+
await this.database.deleteAllProvingJobsOlderThanEpoch(EpochNumber(oldestEpochToKeep));
|
|
558
568
|
this.logger.trace(`Deleted all epochs older than ${oldestEpochToKeep}`);
|
|
559
569
|
}
|
|
560
570
|
}
|
|
@@ -571,7 +581,7 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Tr
|
|
|
571
581
|
|
|
572
582
|
if (jobsToClean.length > 0) {
|
|
573
583
|
this.cleanUpProvingJobState(jobsToClean);
|
|
574
|
-
this.logger.
|
|
584
|
+
this.logger.verbose(`Cleaned up proving jobs=${jobsToClean.length}`);
|
|
575
585
|
}
|
|
576
586
|
}
|
|
577
587
|
|
|
@@ -671,17 +681,23 @@ function proofTypeComparator(a: ProvingRequestType, b: ProvingRequestType): -1 |
|
|
|
671
681
|
* The aim is that this will speed up block proving as the closer we get to a block's root proof the more likely it
|
|
672
682
|
* is to get picked up by agents
|
|
673
683
|
*/
|
|
674
|
-
const PROOF_TYPES_IN_PRIORITY_ORDER: ProvingRequestType[] = [
|
|
684
|
+
export const PROOF_TYPES_IN_PRIORITY_ORDER: ProvingRequestType[] = [
|
|
685
|
+
ProvingRequestType.ROOT_ROLLUP,
|
|
686
|
+
ProvingRequestType.BLOCK_ROOT_FIRST_ROLLUP,
|
|
687
|
+
ProvingRequestType.BLOCK_ROOT_SINGLE_TX_FIRST_ROLLUP,
|
|
688
|
+
ProvingRequestType.BLOCK_ROOT_EMPTY_TX_FIRST_ROLLUP,
|
|
675
689
|
ProvingRequestType.BLOCK_ROOT_ROLLUP,
|
|
676
|
-
ProvingRequestType.
|
|
690
|
+
ProvingRequestType.BLOCK_ROOT_SINGLE_TX_ROLLUP,
|
|
677
691
|
ProvingRequestType.BLOCK_MERGE_ROLLUP,
|
|
678
|
-
ProvingRequestType.
|
|
679
|
-
ProvingRequestType.
|
|
680
|
-
ProvingRequestType.
|
|
681
|
-
ProvingRequestType.
|
|
692
|
+
ProvingRequestType.CHECKPOINT_ROOT_ROLLUP,
|
|
693
|
+
ProvingRequestType.CHECKPOINT_ROOT_SINGLE_BLOCK_ROLLUP,
|
|
694
|
+
ProvingRequestType.CHECKPOINT_MERGE_ROLLUP,
|
|
695
|
+
ProvingRequestType.CHECKPOINT_PADDING_ROLLUP,
|
|
696
|
+
ProvingRequestType.TX_MERGE_ROLLUP,
|
|
697
|
+
ProvingRequestType.PUBLIC_TX_BASE_ROLLUP,
|
|
698
|
+
ProvingRequestType.PRIVATE_TX_BASE_ROLLUP,
|
|
682
699
|
ProvingRequestType.PUBLIC_VM,
|
|
683
|
-
ProvingRequestType.
|
|
684
|
-
ProvingRequestType.
|
|
685
|
-
ProvingRequestType.
|
|
686
|
-
ProvingRequestType.EMPTY_BLOCK_ROOT_ROLLUP,
|
|
700
|
+
ProvingRequestType.PUBLIC_CHONK_VERIFIER,
|
|
701
|
+
ProvingRequestType.PARITY_ROOT,
|
|
702
|
+
ProvingRequestType.PARITY_BASE,
|
|
687
703
|
];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import {
|
|
2
3
|
type ProofUri,
|
|
3
4
|
type ProvingJob,
|
|
@@ -43,7 +44,7 @@ export class InMemoryBrokerDatabase implements ProvingBrokerDatabase {
|
|
|
43
44
|
return Promise.resolve();
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
deleteAllProvingJobsOlderThanEpoch(epochNumber:
|
|
47
|
+
deleteAllProvingJobsOlderThanEpoch(epochNumber: EpochNumber): Promise<void> {
|
|
47
48
|
const toDelete = [
|
|
48
49
|
...Array.from(this.jobs.keys()).filter(x => getEpochFromProvingJobId(x) < epochNumber),
|
|
49
50
|
...Array.from(this.results.keys()).filter(x => getEpochFromProvingJobId(x) < epochNumber),
|
|
@@ -52,7 +53,7 @@ export class InMemoryBrokerDatabase implements ProvingBrokerDatabase {
|
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
async *allProvingJobs(): AsyncIterableIterator<[ProvingJob, ProvingJobSettledResult | undefined]> {
|
|
55
|
-
for
|
|
56
|
+
for (const item of this.jobs.values()) {
|
|
56
57
|
yield [item, this.results.get(item.id)] as const;
|
|
57
58
|
}
|
|
58
59
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { jsonParseWithSchema, jsonStringify } from '@aztec/foundation/json-rpc';
|
|
2
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { BatchQueue } from '@aztec/foundation/queue';
|
|
@@ -10,7 +11,14 @@ import {
|
|
|
10
11
|
ProvingJobSettledResult,
|
|
11
12
|
getEpochFromProvingJobId,
|
|
12
13
|
} from '@aztec/stdlib/interfaces/server';
|
|
13
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
Attributes,
|
|
16
|
+
LmdbMetrics,
|
|
17
|
+
type TelemetryClient,
|
|
18
|
+
type Tracer,
|
|
19
|
+
getTelemetryClient,
|
|
20
|
+
trackSpan,
|
|
21
|
+
} from '@aztec/telemetry-client';
|
|
14
22
|
|
|
15
23
|
import { mkdir, readdir } from 'fs/promises';
|
|
16
24
|
import { join } from 'path';
|
|
@@ -46,9 +54,9 @@ class SingleEpochDatabase {
|
|
|
46
54
|
|
|
47
55
|
async *allProvingJobs(): AsyncIterableIterator<[ProvingJob, ProvingJobSettledResult | undefined]> {
|
|
48
56
|
for await (const jobStr of this.jobs.valuesAsync()) {
|
|
49
|
-
const job =
|
|
57
|
+
const job = jsonParseWithSchema(jobStr, ProvingJob);
|
|
50
58
|
const resultStr = await this.jobResults.getAsync(job.id);
|
|
51
|
-
const result = resultStr ?
|
|
59
|
+
const result = resultStr ? jsonParseWithSchema(resultStr, ProvingJobSettledResult) : undefined;
|
|
52
60
|
yield [job, result];
|
|
53
61
|
}
|
|
54
62
|
}
|
|
@@ -77,6 +85,8 @@ export class KVBrokerDatabase implements ProvingBrokerDatabase {
|
|
|
77
85
|
|
|
78
86
|
private batchQueue: BatchQueue<ProvingJob | [ProvingJobId, ProvingJobSettledResult], number>;
|
|
79
87
|
|
|
88
|
+
public readonly tracer: Tracer;
|
|
89
|
+
|
|
80
90
|
private constructor(
|
|
81
91
|
private epochs: Map<number, SingleEpochDatabase>,
|
|
82
92
|
private config: ProverBrokerConfig,
|
|
@@ -91,6 +101,8 @@ export class KVBrokerDatabase implements ProvingBrokerDatabase {
|
|
|
91
101
|
() => this.estimateSize(),
|
|
92
102
|
);
|
|
93
103
|
|
|
104
|
+
this.tracer = client.getTracer('KVBrokerDatabase');
|
|
105
|
+
|
|
94
106
|
this.batchQueue = new BatchQueue(
|
|
95
107
|
(items, key) => this.commitWrites(items, key),
|
|
96
108
|
config.proverBrokerBatchSize,
|
|
@@ -104,14 +116,15 @@ export class KVBrokerDatabase implements ProvingBrokerDatabase {
|
|
|
104
116
|
const jobsToAdd = items.filter((item): item is ProvingJob => 'id' in item);
|
|
105
117
|
const resultsToAdd = items.filter((item): item is [ProvingJobId, ProvingJobSettledResult] => Array.isArray(item));
|
|
106
118
|
|
|
107
|
-
const db = await this.getEpochDatabase(epochNumber);
|
|
119
|
+
const db = await this.getEpochDatabase(EpochNumber(epochNumber));
|
|
108
120
|
await db.batchWrite(jobsToAdd, resultsToAdd);
|
|
109
121
|
}
|
|
110
122
|
|
|
111
123
|
private async estimateSize() {
|
|
112
124
|
const sizes = await Promise.all(Array.from(this.epochs.values()).map(x => x.estimateSize()));
|
|
113
125
|
return {
|
|
114
|
-
mappingSize: this.config.
|
|
126
|
+
mappingSize: this.config.dataStoreMapSizeKb,
|
|
127
|
+
physicalFileSize: sizes.reduce((prev, curr) => prev + curr.physicalFileSize, 0),
|
|
115
128
|
numItems: sizes.reduce((prev, curr) => prev + curr.numItems, 0),
|
|
116
129
|
actualSize: sizes.reduce((prev, curr) => prev + curr.actualSize, 0),
|
|
117
130
|
};
|
|
@@ -136,13 +149,13 @@ export class KVBrokerDatabase implements ProvingBrokerDatabase {
|
|
|
136
149
|
continue;
|
|
137
150
|
}
|
|
138
151
|
logger.info(
|
|
139
|
-
`Loading broker database for epoch ${epochNumber} from ${fullDirectory} with map size ${config.
|
|
152
|
+
`Loading broker database for epoch ${epochNumber} from ${fullDirectory} with map size ${config.dataStoreMapSizeKb}KB`,
|
|
140
153
|
);
|
|
141
154
|
const db = await openVersionedStoreAt(
|
|
142
155
|
fullDirectory,
|
|
143
156
|
SingleEpochDatabase.SCHEMA_VERSION,
|
|
144
157
|
config.l1Contracts.rollupAddress,
|
|
145
|
-
config.
|
|
158
|
+
config.dataStoreMapSizeKb,
|
|
146
159
|
);
|
|
147
160
|
const epochDb = new SingleEpochDatabase(db);
|
|
148
161
|
epochs.set(epochNumber, epochDb);
|
|
@@ -163,14 +176,17 @@ export class KVBrokerDatabase implements ProvingBrokerDatabase {
|
|
|
163
176
|
}
|
|
164
177
|
}
|
|
165
178
|
|
|
166
|
-
|
|
167
|
-
|
|
179
|
+
@trackSpan('KVBrokerDatabase.deleteAllProvingJobsOlderThanEpoch', epochNumber => ({
|
|
180
|
+
[Attributes.EPOCH_NUMBER]: epochNumber,
|
|
181
|
+
}))
|
|
182
|
+
async deleteAllProvingJobsOlderThanEpoch(epochNumber: EpochNumber): Promise<void> {
|
|
183
|
+
const oldEpochs = Array.from(this.epochs.keys()).filter(e => e < Number(epochNumber));
|
|
168
184
|
for (const old of oldEpochs) {
|
|
169
185
|
const db = this.epochs.get(old);
|
|
170
186
|
if (!db) {
|
|
171
187
|
continue;
|
|
172
188
|
}
|
|
173
|
-
this.logger.
|
|
189
|
+
this.logger.verbose(`Deleting broker database for epoch ${old}`);
|
|
174
190
|
await db.delete();
|
|
175
191
|
this.epochs.delete(old);
|
|
176
192
|
}
|
|
@@ -195,19 +211,19 @@ export class KVBrokerDatabase implements ProvingBrokerDatabase {
|
|
|
195
211
|
return this.batchQueue.put([id, { status: 'fulfilled', value }], getEpochFromProvingJobId(id));
|
|
196
212
|
}
|
|
197
213
|
|
|
198
|
-
private async getEpochDatabase(epochNumber:
|
|
214
|
+
private async getEpochDatabase(epochNumber: EpochNumber): Promise<SingleEpochDatabase> {
|
|
199
215
|
let epochDb = this.epochs.get(epochNumber);
|
|
200
216
|
if (!epochDb) {
|
|
201
217
|
const newEpochDirectory = join(this.config.dataDirectory!, epochNumber.toString());
|
|
202
218
|
await mkdir(newEpochDirectory, { recursive: true });
|
|
203
219
|
this.logger.info(
|
|
204
|
-
`Creating broker database for epoch ${epochNumber} at ${newEpochDirectory} with map size ${this.config.
|
|
220
|
+
`Creating broker database for epoch ${epochNumber} at ${newEpochDirectory} with map size ${this.config.dataStoreMapSizeKb}`,
|
|
205
221
|
);
|
|
206
222
|
const db = await openVersionedStoreAt(
|
|
207
223
|
newEpochDirectory,
|
|
208
224
|
SingleEpochDatabase.SCHEMA_VERSION,
|
|
209
225
|
this.config.l1Contracts.rollupAddress,
|
|
210
|
-
this.config.
|
|
226
|
+
this.config.dataStoreMapSizeKb,
|
|
211
227
|
);
|
|
212
228
|
epochDb = new SingleEpochDatabase(db);
|
|
213
229
|
this.epochs.set(epochNumber, epochDb);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import type { ProofUri, ProvingJob, ProvingJobId, ProvingJobSettledResult } from '@aztec/stdlib/interfaces/server';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -14,7 +15,7 @@ export interface ProvingBrokerDatabase {
|
|
|
14
15
|
* Deletes all proving jobs belonging to epochs older than the given epoch
|
|
15
16
|
* @param epochNumber - The epoch number beyond which jobs should be deleted
|
|
16
17
|
*/
|
|
17
|
-
deleteAllProvingJobsOlderThanEpoch(epochNumber:
|
|
18
|
+
deleteAllProvingJobsOlderThanEpoch(epochNumber: EpochNumber): Promise<void>;
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Returns an iterator over all saved proving jobs
|