@aztec/prover-client 0.62.0 → 0.63.1
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/mocks/fixtures.d.ts +2 -4
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +8 -15
- package/dest/mocks/test_context.d.ts +3 -2
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +16 -15
- package/dest/orchestrator/block-building-helpers.d.ts +5 -13
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +28 -16
- package/dest/orchestrator/orchestrator.d.ts +3 -2
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +23 -22
- package/dest/orchestrator/tx-proving-state.d.ts +3 -3
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +31 -22
- package/dest/prover-agent/memory-proving-queue.d.ts +8 -9
- package/dest/prover-agent/memory-proving-queue.d.ts.map +1 -1
- package/dest/prover-agent/memory-proving-queue.js +6 -9
- package/dest/prover-agent/prover-agent.d.ts +7 -6
- package/dest/prover-agent/prover-agent.d.ts.map +1 -1
- package/dest/prover-agent/prover-agent.js +18 -10
- package/dest/prover-agent/rpc.d.ts +4 -5
- package/dest/prover-agent/rpc.d.ts.map +1 -1
- package/dest/prover-agent/rpc.js +9 -72
- package/dest/proving_broker/proving_broker.d.ts +45 -0
- package/dest/proving_broker/proving_broker.d.ts.map +1 -0
- package/dest/proving_broker/proving_broker.js +298 -0
- package/dest/proving_broker/proving_broker_interface.d.ts +61 -0
- package/dest/proving_broker/proving_broker_interface.d.ts.map +1 -0
- package/dest/proving_broker/proving_broker_interface.js +2 -0
- package/dest/proving_broker/proving_job_database/memory.d.ts +14 -0
- package/dest/proving_broker/proving_job_database/memory.d.ts.map +1 -0
- package/dest/proving_broker/proving_job_database/memory.js +35 -0
- package/dest/proving_broker/proving_job_database/persisted.d.ts +15 -0
- package/dest/proving_broker/proving_job_database/persisted.d.ts.map +1 -0
- package/dest/proving_broker/proving_job_database/persisted.js +34 -0
- package/dest/proving_broker/proving_job_database.d.ts +35 -0
- package/dest/proving_broker/proving_job_database.d.ts.map +1 -0
- package/dest/proving_broker/proving_job_database.js +2 -0
- package/dest/test/mock_prover.d.ts +5 -6
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +5 -8
- package/dest/tx-prover/tx-prover.js +2 -2
- package/package.json +13 -12
- package/src/mocks/fixtures.ts +12 -36
- package/src/mocks/test_context.ts +21 -32
- package/src/orchestrator/block-building-helpers.ts +35 -18
- package/src/orchestrator/orchestrator.ts +41 -27
- package/src/orchestrator/tx-proving-state.ts +45 -32
- package/src/prover-agent/memory-proving-queue.ts +15 -24
- package/src/prover-agent/prover-agent.ts +29 -16
- package/src/prover-agent/rpc.ts +9 -120
- package/src/proving_broker/proving_broker.ts +372 -0
- package/src/proving_broker/proving_broker_interface.ts +74 -0
- package/src/proving_broker/proving_job_database/memory.ts +43 -0
- package/src/proving_broker/proving_job_database/persisted.ts +44 -0
- package/src/proving_broker/proving_job_database.ts +44 -0
- package/src/test/mock_prover.ts +17 -15
- package/src/tx-prover/tx-prover.ts +1 -1
|
@@ -16,11 +16,10 @@ import {
|
|
|
16
16
|
PrivateBaseRollupInputs,
|
|
17
17
|
PrivateTubeData,
|
|
18
18
|
PublicBaseRollupInputs,
|
|
19
|
-
|
|
19
|
+
PublicTubeData,
|
|
20
20
|
type TUBE_PROOF_LENGTH,
|
|
21
21
|
TUBE_VK_INDEX,
|
|
22
22
|
TubeInputs,
|
|
23
|
-
VMCircuitPublicInputs,
|
|
24
23
|
VkWitnessData,
|
|
25
24
|
} from '@aztec/circuits.js';
|
|
26
25
|
import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types';
|
|
@@ -31,8 +30,8 @@ import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-type
|
|
|
31
30
|
* Also stores the inputs to the base rollup for this transaction and the tree snapshots
|
|
32
31
|
*/
|
|
33
32
|
export class TxProvingState {
|
|
34
|
-
private tube?: ProofAndVerificationKey<
|
|
35
|
-
private avm?: ProofAndVerificationKey<
|
|
33
|
+
private tube?: ProofAndVerificationKey<typeof TUBE_PROOF_LENGTH>;
|
|
34
|
+
private avm?: ProofAndVerificationKey<typeof AVM_PROOF_LENGTH_IN_FIELDS>;
|
|
36
35
|
|
|
37
36
|
constructor(
|
|
38
37
|
public readonly processedTx: ProcessedTx,
|
|
@@ -65,13 +64,13 @@ export class TxProvingState {
|
|
|
65
64
|
}
|
|
66
65
|
|
|
67
66
|
const vkData = this.getTubeVkData();
|
|
68
|
-
const tubeData = new PrivateTubeData(this.processedTx.data, this.tube.proof, vkData);
|
|
67
|
+
const tubeData = new PrivateTubeData(this.processedTx.data.toKernelCircuitPublicInputs(), this.tube.proof, vkData);
|
|
69
68
|
|
|
70
69
|
return new PrivateBaseRollupInputs(tubeData, this.baseRollupHints);
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
public getPublicBaseInputs() {
|
|
74
|
-
if (!this.
|
|
73
|
+
if (!this.processedTx.avmProvingRequest) {
|
|
75
74
|
throw new Error('Should create private base rollup for a tx not requiring avm proof.');
|
|
76
75
|
}
|
|
77
76
|
if (!this.tube) {
|
|
@@ -81,15 +80,14 @@ export class TxProvingState {
|
|
|
81
80
|
throw new Error('Tx not ready for proving base rollup: avm proof undefined');
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const tubeData = new PrivateTubeData(this.processedTx.data, this.tube.proof, this.getTubeVkData());
|
|
83
|
+
const tubeData = new PublicTubeData(
|
|
84
|
+
this.processedTx.data.toPublicKernelCircuitPublicInputs(),
|
|
85
|
+
this.tube.proof,
|
|
86
|
+
this.getTubeVkData(),
|
|
87
|
+
);
|
|
90
88
|
|
|
91
89
|
const avmProofData = new AvmProofData(
|
|
92
|
-
|
|
90
|
+
this.processedTx.avmProvingRequest.inputs.output,
|
|
93
91
|
this.avm.proof,
|
|
94
92
|
this.getAvmVkData(),
|
|
95
93
|
);
|
|
@@ -97,42 +95,57 @@ export class TxProvingState {
|
|
|
97
95
|
return new PublicBaseRollupInputs(tubeData, avmProofData, this.baseRollupHints);
|
|
98
96
|
}
|
|
99
97
|
|
|
100
|
-
public assignTubeProof(tubeProofAndVk: ProofAndVerificationKey<
|
|
98
|
+
public assignTubeProof(tubeProofAndVk: ProofAndVerificationKey<typeof TUBE_PROOF_LENGTH>) {
|
|
101
99
|
this.tube = tubeProofAndVk;
|
|
102
100
|
}
|
|
103
101
|
|
|
104
|
-
public assignAvmProof(avmProofAndVk: ProofAndVerificationKey<
|
|
102
|
+
public assignAvmProof(avmProofAndVk: ProofAndVerificationKey<typeof AVM_PROOF_LENGTH_IN_FIELDS>) {
|
|
105
103
|
this.avm = avmProofAndVk;
|
|
106
104
|
}
|
|
107
105
|
|
|
108
106
|
public verifyStateOrReject(): string | undefined {
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
107
|
+
const txEffect = this.processedTx.txEffect;
|
|
108
|
+
const fromPrivate = this.processedTx.data;
|
|
109
|
+
|
|
110
|
+
const noteEncryptedLogsHashes = [
|
|
111
|
+
fromPrivate.forRollup?.end.noteEncryptedLogsHashes || [],
|
|
112
|
+
fromPrivate.forPublic?.nonRevertibleAccumulatedData.noteEncryptedLogsHashes || [],
|
|
113
|
+
fromPrivate.forPublic?.revertibleAccumulatedData.noteEncryptedLogsHashes || [],
|
|
114
|
+
].flat();
|
|
115
|
+
const txNoteEncryptedLogsHash = EncryptedNoteTxL2Logs.hashNoteLogs(
|
|
116
|
+
noteEncryptedLogsHashes.filter(log => !log.isEmpty()).map(log => log.value.toBuffer()),
|
|
113
117
|
);
|
|
114
|
-
if (!
|
|
115
|
-
return `Note encrypted logs hash mismatch: ${Fr.fromBuffer(
|
|
116
|
-
|
|
118
|
+
if (!txNoteEncryptedLogsHash.equals(txEffect.noteEncryptedLogs.hash())) {
|
|
119
|
+
return `Note encrypted logs hash mismatch: ${Fr.fromBuffer(txNoteEncryptedLogsHash)} === ${Fr.fromBuffer(
|
|
120
|
+
txEffect.noteEncryptedLogs.hash(),
|
|
117
121
|
)}`;
|
|
118
122
|
}
|
|
119
123
|
|
|
120
|
-
const
|
|
121
|
-
|
|
124
|
+
const encryptedLogsHashes = [
|
|
125
|
+
fromPrivate.forRollup?.end.encryptedLogsHashes || [],
|
|
126
|
+
fromPrivate.forPublic?.nonRevertibleAccumulatedData.encryptedLogsHashes || [],
|
|
127
|
+
fromPrivate.forPublic?.revertibleAccumulatedData.encryptedLogsHashes || [],
|
|
128
|
+
].flat();
|
|
129
|
+
const txEncryptedLogsHash = EncryptedTxL2Logs.hashSiloedLogs(
|
|
130
|
+
encryptedLogsHashes.filter(log => !log.isEmpty()).map(log => log.getSiloedHash()),
|
|
122
131
|
);
|
|
123
|
-
if (!
|
|
132
|
+
if (!txEncryptedLogsHash.equals(txEffect.encryptedLogs.hash())) {
|
|
124
133
|
// @todo This rejection messages is never seen. Never making it out to the logs
|
|
125
|
-
return `Encrypted logs hash mismatch: ${Fr.fromBuffer(
|
|
126
|
-
|
|
134
|
+
return `Encrypted logs hash mismatch: ${Fr.fromBuffer(txEncryptedLogsHash)} === ${Fr.fromBuffer(
|
|
135
|
+
txEffect.encryptedLogs.hash(),
|
|
127
136
|
)}`;
|
|
128
137
|
}
|
|
129
138
|
|
|
130
|
-
const
|
|
131
|
-
|
|
139
|
+
const avmOutput = this.processedTx.avmProvingRequest?.inputs.output;
|
|
140
|
+
const unencryptedLogsHashes = avmOutput
|
|
141
|
+
? avmOutput.accumulatedData.unencryptedLogsHashes
|
|
142
|
+
: fromPrivate.forRollup!.end.unencryptedLogsHashes;
|
|
143
|
+
const txUnencryptedLogsHash = UnencryptedTxL2Logs.hashSiloedLogs(
|
|
144
|
+
unencryptedLogsHashes.filter(log => !log.isEmpty()).map(log => log.getSiloedHash()),
|
|
132
145
|
);
|
|
133
|
-
if (!
|
|
134
|
-
return `Unencrypted logs hash mismatch: ${Fr.fromBuffer(
|
|
135
|
-
|
|
146
|
+
if (!txUnencryptedLogsHash.equals(txEffect.unencryptedLogs.hash())) {
|
|
147
|
+
return `Unencrypted logs hash mismatch: ${Fr.fromBuffer(txUnencryptedLogsHash)} === ${Fr.fromBuffer(
|
|
148
|
+
txEffect.unencryptedLogs.hash(),
|
|
136
149
|
)}`;
|
|
137
150
|
}
|
|
138
151
|
}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
type ProvingJob,
|
|
4
4
|
type ProvingJobSource,
|
|
5
5
|
type ProvingRequest,
|
|
6
|
-
type
|
|
6
|
+
type ProvingRequestResultFor,
|
|
7
7
|
ProvingRequestType,
|
|
8
8
|
type PublicInputsAndRecursiveProof,
|
|
9
9
|
type ServerCircuitProver,
|
|
@@ -20,12 +20,11 @@ import type {
|
|
|
20
20
|
KernelCircuitPublicInputs,
|
|
21
21
|
MergeRollupInputs,
|
|
22
22
|
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
23
|
+
ParityPublicInputs,
|
|
23
24
|
PrivateBaseRollupInputs,
|
|
24
25
|
PrivateKernelEmptyInputData,
|
|
25
26
|
PublicBaseRollupInputs,
|
|
26
27
|
RECURSIVE_PROOF_LENGTH,
|
|
27
|
-
RecursiveProof,
|
|
28
|
-
RootParityInput,
|
|
29
28
|
RootParityInputs,
|
|
30
29
|
RootRollupInputs,
|
|
31
30
|
RootRollupPublicInputs,
|
|
@@ -42,7 +41,7 @@ import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
|
42
41
|
import { ProvingQueueMetrics } from './queue_metrics.js';
|
|
43
42
|
|
|
44
43
|
type ProvingJobWithResolvers<T extends ProvingRequest = ProvingRequest> = ProvingJob<T> &
|
|
45
|
-
PromiseWithResolvers<
|
|
44
|
+
PromiseWithResolvers<ProvingRequestResultFor<T['type']>> & {
|
|
46
45
|
signal?: AbortSignal;
|
|
47
46
|
epochNumber?: number;
|
|
48
47
|
attempts: number;
|
|
@@ -131,7 +130,7 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
|
|
|
131
130
|
}
|
|
132
131
|
}
|
|
133
132
|
|
|
134
|
-
resolveProvingJob<T extends ProvingRequestType>(jobId: string, result:
|
|
133
|
+
resolveProvingJob<T extends ProvingRequestType>(jobId: string, result: ProvingRequestResultFor<T>): Promise<void> {
|
|
135
134
|
if (!this.runningPromise.isRunning()) {
|
|
136
135
|
throw new Error('Proving queue is not running.');
|
|
137
136
|
}
|
|
@@ -150,7 +149,7 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
|
|
|
150
149
|
return Promise.resolve();
|
|
151
150
|
}
|
|
152
151
|
|
|
153
|
-
rejectProvingJob(jobId: string,
|
|
152
|
+
rejectProvingJob(jobId: string, reason: string): Promise<void> {
|
|
154
153
|
if (!this.runningPromise.isRunning()) {
|
|
155
154
|
throw new Error('Proving queue is not running.');
|
|
156
155
|
}
|
|
@@ -171,7 +170,7 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
|
|
|
171
170
|
if (job.attempts < MAX_RETRIES && job.request.type !== ProvingRequestType.PUBLIC_VM) {
|
|
172
171
|
job.attempts++;
|
|
173
172
|
this.log.warn(
|
|
174
|
-
`Job id=${job.id} type=${ProvingRequestType[job.request.type]} failed with error: ${
|
|
173
|
+
`Job id=${job.id} type=${ProvingRequestType[job.request.type]} failed with error: ${reason}. Retry ${
|
|
175
174
|
job.attempts
|
|
176
175
|
}/${MAX_RETRIES}`,
|
|
177
176
|
);
|
|
@@ -181,8 +180,8 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
|
|
|
181
180
|
job.request.type === ProvingRequestType.PUBLIC_VM && !process.env.AVM_PROVING_STRICT
|
|
182
181
|
? this.log.warn
|
|
183
182
|
: this.log.error;
|
|
184
|
-
logFn(`Job id=${job.id} type=${ProvingRequestType[job.request.type]} failed with error: ${
|
|
185
|
-
job.reject(
|
|
183
|
+
logFn(`Job id=${job.id} type=${ProvingRequestType[job.request.type]} failed with error: ${reason}`);
|
|
184
|
+
job.reject(new Error(reason));
|
|
186
185
|
}
|
|
187
186
|
return Promise.resolve();
|
|
188
187
|
}
|
|
@@ -228,12 +227,12 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
|
|
|
228
227
|
request: T,
|
|
229
228
|
signal?: AbortSignal,
|
|
230
229
|
epochNumber?: number,
|
|
231
|
-
): Promise<
|
|
230
|
+
): Promise<ProvingRequestResultFor<T['type']>['result']> {
|
|
232
231
|
if (!this.runningPromise.isRunning()) {
|
|
233
232
|
return Promise.reject(new Error('Proving queue is not running.'));
|
|
234
233
|
}
|
|
235
234
|
|
|
236
|
-
const { promise, resolve, reject } = promiseWithResolvers<
|
|
235
|
+
const { promise, resolve, reject } = promiseWithResolvers<ProvingRequestResultFor<T['type']>>();
|
|
237
236
|
const item: ProvingJobWithResolvers<T> = {
|
|
238
237
|
id: this.generateId(),
|
|
239
238
|
request,
|
|
@@ -261,7 +260,7 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
|
|
|
261
260
|
const byteSize = serializeToBuffer(item.request.inputs).length;
|
|
262
261
|
this.metrics.recordNewJob(item.request.type, byteSize);
|
|
263
262
|
|
|
264
|
-
return promise;
|
|
263
|
+
return promise.then(({ result }) => result);
|
|
265
264
|
}
|
|
266
265
|
|
|
267
266
|
getEmptyPrivateKernelProof(
|
|
@@ -276,18 +275,10 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
|
|
|
276
275
|
inputs: TubeInputs,
|
|
277
276
|
signal?: AbortSignal,
|
|
278
277
|
epochNumber?: number,
|
|
279
|
-
): Promise<ProofAndVerificationKey<
|
|
278
|
+
): Promise<ProofAndVerificationKey<typeof RECURSIVE_PROOF_LENGTH>> {
|
|
280
279
|
return this.enqueue({ type: ProvingRequestType.TUBE_PROOF, inputs }, signal, epochNumber);
|
|
281
280
|
}
|
|
282
281
|
|
|
283
|
-
getEmptyTubeProof(
|
|
284
|
-
inputs: PrivateKernelEmptyInputData,
|
|
285
|
-
signal?: AbortSignal,
|
|
286
|
-
epochNumber?: number,
|
|
287
|
-
): Promise<PublicInputsAndRecursiveProof<KernelCircuitPublicInputs>> {
|
|
288
|
-
return this.enqueue({ type: ProvingRequestType.PRIVATE_KERNEL_EMPTY, inputs }, signal, epochNumber);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
282
|
/**
|
|
292
283
|
* Creates a proof for the given input.
|
|
293
284
|
* @param input - Input to the circuit.
|
|
@@ -296,7 +287,7 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
|
|
|
296
287
|
inputs: BaseParityInputs,
|
|
297
288
|
signal?: AbortSignal,
|
|
298
289
|
epochNumber?: number,
|
|
299
|
-
): Promise<
|
|
290
|
+
): Promise<PublicInputsAndRecursiveProof<ParityPublicInputs, typeof RECURSIVE_PROOF_LENGTH>> {
|
|
300
291
|
return this.enqueue({ type: ProvingRequestType.BASE_PARITY, inputs }, signal, epochNumber);
|
|
301
292
|
}
|
|
302
293
|
|
|
@@ -308,7 +299,7 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
|
|
|
308
299
|
inputs: RootParityInputs,
|
|
309
300
|
signal?: AbortSignal,
|
|
310
301
|
epochNumber?: number,
|
|
311
|
-
): Promise<
|
|
302
|
+
): Promise<PublicInputsAndRecursiveProof<ParityPublicInputs, typeof NESTED_RECURSIVE_PROOF_LENGTH>> {
|
|
312
303
|
return this.enqueue({ type: ProvingRequestType.ROOT_PARITY, inputs }, signal, epochNumber);
|
|
313
304
|
}
|
|
314
305
|
|
|
@@ -391,7 +382,7 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
|
|
|
391
382
|
inputs: AvmCircuitInputs,
|
|
392
383
|
signal?: AbortSignal,
|
|
393
384
|
epochNumber?: number,
|
|
394
|
-
): Promise<ProofAndVerificationKey<
|
|
385
|
+
): Promise<ProofAndVerificationKey<typeof AVM_PROOF_LENGTH_IN_FIELDS>> {
|
|
395
386
|
return this.enqueue({ type: ProvingRequestType.PUBLIC_VM, inputs }, signal, epochNumber);
|
|
396
387
|
}
|
|
397
388
|
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
|
+
type ProverAgentApi,
|
|
2
3
|
type ProvingJob,
|
|
3
4
|
type ProvingJobSource,
|
|
4
5
|
type ProvingRequest,
|
|
5
|
-
type
|
|
6
|
+
type ProvingRequestResultFor,
|
|
6
7
|
ProvingRequestType,
|
|
7
8
|
type ServerCircuitProver,
|
|
9
|
+
makeProvingRequestResult,
|
|
8
10
|
} from '@aztec/circuit-types';
|
|
9
11
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
10
12
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
11
13
|
import { elapsed } from '@aztec/foundation/timer';
|
|
12
14
|
|
|
13
|
-
import { ProvingError } from './proving-error.js';
|
|
14
|
-
|
|
15
15
|
const PRINT_THRESHOLD_NS = 6e10; // 60 seconds
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* A helper class that encapsulates a circuit prover and connects it to a job source.
|
|
19
19
|
*/
|
|
20
|
-
export class ProverAgent {
|
|
20
|
+
export class ProverAgent implements ProverAgentApi {
|
|
21
21
|
private inFlightPromises = new Map<
|
|
22
22
|
string,
|
|
23
23
|
{
|
|
@@ -38,11 +38,12 @@ export class ProverAgent {
|
|
|
38
38
|
private log = createDebugLogger('aztec:prover-client:prover-agent'),
|
|
39
39
|
) {}
|
|
40
40
|
|
|
41
|
-
setMaxConcurrency(maxConcurrency: number): void {
|
|
41
|
+
setMaxConcurrency(maxConcurrency: number): Promise<void> {
|
|
42
42
|
if (maxConcurrency < 1) {
|
|
43
43
|
throw new Error('Concurrency must be at least 1');
|
|
44
44
|
}
|
|
45
45
|
this.maxConcurrency = maxConcurrency;
|
|
46
|
+
return Promise.resolve();
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
setCircuitProver(circuitProver: ServerCircuitProver): void {
|
|
@@ -50,11 +51,17 @@ export class ProverAgent {
|
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
isRunning() {
|
|
54
|
+
return Promise.resolve(this.#isRunning());
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
#isRunning() {
|
|
53
58
|
return this.runningPromise?.isRunning() ?? false;
|
|
54
59
|
}
|
|
55
60
|
|
|
56
|
-
getCurrentJobs(): { id: string; type: string }[] {
|
|
57
|
-
return
|
|
61
|
+
getCurrentJobs(): Promise<{ id: string; type: string }[]> {
|
|
62
|
+
return Promise.resolve(
|
|
63
|
+
Array.from(this.inFlightPromises.values()).map(({ id, type }) => ({ id, type: ProvingRequestType[type] })),
|
|
64
|
+
);
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
start(jobSource: ProvingJobSource): void {
|
|
@@ -123,15 +130,17 @@ export class ProverAgent {
|
|
|
123
130
|
this.log.info('Agent stopped');
|
|
124
131
|
}
|
|
125
132
|
|
|
126
|
-
private async work
|
|
133
|
+
private async work<TRequest extends ProvingRequest>(
|
|
134
|
+
jobSource: ProvingJobSource,
|
|
135
|
+
job: ProvingJob<TRequest>,
|
|
136
|
+
): Promise<void> {
|
|
127
137
|
try {
|
|
128
138
|
this.log.debug(`Picked up proving job id=${job.id} type=${ProvingRequestType[job.request.type]}`);
|
|
139
|
+
const type: TRequest['type'] = job.request.type;
|
|
129
140
|
const [time, result] = await elapsed(this.getProof(job.request));
|
|
130
|
-
if (this
|
|
131
|
-
this.log.verbose(
|
|
132
|
-
|
|
133
|
-
);
|
|
134
|
-
await jobSource.resolveProvingJob(job.id, result);
|
|
141
|
+
if (this.#isRunning()) {
|
|
142
|
+
this.log.verbose(`Processed proving job id=${job.id} type=${ProvingRequestType[type]} duration=${time}ms`);
|
|
143
|
+
await jobSource.resolveProvingJob(job.id, makeProvingRequestResult(type, result));
|
|
135
144
|
} else {
|
|
136
145
|
this.log.verbose(
|
|
137
146
|
`Dropping proving job id=${job.id} type=${
|
|
@@ -141,20 +150,24 @@ export class ProverAgent {
|
|
|
141
150
|
}
|
|
142
151
|
} catch (err) {
|
|
143
152
|
const type = ProvingRequestType[job.request.type];
|
|
144
|
-
if (this
|
|
153
|
+
if (this.#isRunning()) {
|
|
145
154
|
if (job.request.type === ProvingRequestType.PUBLIC_VM && !process.env.AVM_PROVING_STRICT) {
|
|
146
155
|
this.log.warn(`Expected error processing VM proving job id=${job.id} type=${type}: ${err}`);
|
|
147
156
|
} else {
|
|
148
157
|
this.log.error(`Error processing proving job id=${job.id} type=${type}: ${err}`, err);
|
|
149
158
|
}
|
|
150
|
-
|
|
159
|
+
const reason = (err as any)?.message ?? String(err);
|
|
160
|
+
await jobSource.rejectProvingJob(job.id, reason);
|
|
151
161
|
} else {
|
|
152
162
|
this.log.verbose(`Dropping proving job id=${job.id} type=${type}: agent stopped: ${(err as any).stack || err}`);
|
|
153
163
|
}
|
|
154
164
|
}
|
|
155
165
|
}
|
|
156
166
|
|
|
157
|
-
private getProof
|
|
167
|
+
private getProof<TRequest extends ProvingRequest>(
|
|
168
|
+
request: TRequest,
|
|
169
|
+
): Promise<ProvingRequestResultFor<TRequest['type']>['result']>;
|
|
170
|
+
private getProof(request: ProvingRequest): Promise<ProvingRequestResultFor<typeof type>['result']> {
|
|
158
171
|
const { type, inputs } = request;
|
|
159
172
|
switch (type) {
|
|
160
173
|
case ProvingRequestType.PUBLIC_VM: {
|
package/src/prover-agent/rpc.ts
CHANGED
|
@@ -1,133 +1,22 @@
|
|
|
1
|
-
import { type ProvingJobSource } from '@aztec/circuit-types';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
AztecAddress,
|
|
5
|
-
BaseOrMergeRollupPublicInputs,
|
|
6
|
-
BaseParityInputs,
|
|
7
|
-
BlockMergeRollupInputs,
|
|
8
|
-
BlockRootOrBlockMergePublicInputs,
|
|
9
|
-
BlockRootRollupInputs,
|
|
10
|
-
EmptyBlockRootRollupInputs,
|
|
11
|
-
EthAddress,
|
|
12
|
-
Fr,
|
|
13
|
-
Header,
|
|
14
|
-
KernelCircuitPublicInputs,
|
|
15
|
-
MergeRollupInputs,
|
|
16
|
-
ParityPublicInputs,
|
|
17
|
-
PrivateBaseRollupInputs,
|
|
18
|
-
PrivateKernelEmptyInputData,
|
|
19
|
-
Proof,
|
|
20
|
-
PublicBaseRollupInputs,
|
|
21
|
-
PublicKernelCircuitPublicInputs,
|
|
22
|
-
RecursiveProof,
|
|
23
|
-
RootParityInput,
|
|
24
|
-
RootParityInputs,
|
|
25
|
-
RootRollupInputs,
|
|
26
|
-
RootRollupPublicInputs,
|
|
27
|
-
TubeInputs,
|
|
28
|
-
VMCircuitPublicInputs,
|
|
29
|
-
VerificationKeyData,
|
|
30
|
-
} from '@aztec/circuits.js';
|
|
31
|
-
import { createJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client';
|
|
32
|
-
import { JsonRpcServer } from '@aztec/foundation/json-rpc/server';
|
|
1
|
+
import { ProverAgentApiSchema, type ProvingJobSource, ProvingJobSourceSchema } from '@aztec/circuit-types';
|
|
2
|
+
import { createSafeJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client';
|
|
3
|
+
import { createSafeJsonRpcServer } from '@aztec/foundation/json-rpc/server';
|
|
33
4
|
|
|
34
5
|
import { type ProverAgent } from './prover-agent.js';
|
|
35
|
-
import { ProvingError } from './proving-error.js';
|
|
36
6
|
|
|
37
|
-
export function createProvingJobSourceServer(queue: ProvingJobSource)
|
|
38
|
-
return
|
|
39
|
-
queue,
|
|
40
|
-
{
|
|
41
|
-
AvmCircuitInputs,
|
|
42
|
-
BaseOrMergeRollupPublicInputs,
|
|
43
|
-
BaseParityInputs,
|
|
44
|
-
PrivateBaseRollupInputs,
|
|
45
|
-
PublicBaseRollupInputs,
|
|
46
|
-
Fr,
|
|
47
|
-
Header,
|
|
48
|
-
KernelCircuitPublicInputs,
|
|
49
|
-
MergeRollupInputs,
|
|
50
|
-
ParityPublicInputs,
|
|
51
|
-
Proof,
|
|
52
|
-
ProvingError,
|
|
53
|
-
PrivateKernelEmptyInputData,
|
|
54
|
-
VMCircuitPublicInputs,
|
|
55
|
-
PublicKernelCircuitPublicInputs,
|
|
56
|
-
RecursiveProof,
|
|
57
|
-
RootParityInput,
|
|
58
|
-
RootParityInputs,
|
|
59
|
-
RootRollupInputs,
|
|
60
|
-
RootRollupPublicInputs,
|
|
61
|
-
TubeInputs,
|
|
62
|
-
VerificationKeyData,
|
|
63
|
-
BlockRootOrBlockMergePublicInputs,
|
|
64
|
-
BlockMergeRollupInputs,
|
|
65
|
-
BlockRootRollupInputs,
|
|
66
|
-
EmptyBlockRootRollupInputs,
|
|
67
|
-
},
|
|
68
|
-
{},
|
|
69
|
-
);
|
|
7
|
+
export function createProvingJobSourceServer(queue: ProvingJobSource) {
|
|
8
|
+
return createSafeJsonRpcServer(queue, ProvingJobSourceSchema);
|
|
70
9
|
}
|
|
71
10
|
|
|
72
|
-
export function createProvingJobSourceClient(
|
|
73
|
-
url
|
|
74
|
-
namespace?: string,
|
|
75
|
-
fetch = makeFetch([1, 2, 3], false),
|
|
76
|
-
): ProvingJobSource {
|
|
77
|
-
return createJsonRpcClient(
|
|
78
|
-
url,
|
|
79
|
-
{
|
|
80
|
-
AvmCircuitInputs,
|
|
81
|
-
BaseOrMergeRollupPublicInputs,
|
|
82
|
-
BaseParityInputs,
|
|
83
|
-
PrivateBaseRollupInputs,
|
|
84
|
-
PublicBaseRollupInputs,
|
|
85
|
-
Fr,
|
|
86
|
-
Header,
|
|
87
|
-
KernelCircuitPublicInputs,
|
|
88
|
-
MergeRollupInputs,
|
|
89
|
-
ParityPublicInputs,
|
|
90
|
-
Proof,
|
|
91
|
-
ProvingError,
|
|
92
|
-
PrivateKernelEmptyInputData,
|
|
93
|
-
VMCircuitPublicInputs,
|
|
94
|
-
PublicKernelCircuitPublicInputs,
|
|
95
|
-
RecursiveProof,
|
|
96
|
-
RootParityInput,
|
|
97
|
-
RootParityInputs,
|
|
98
|
-
RootRollupPublicInputs,
|
|
99
|
-
RootRollupInputs,
|
|
100
|
-
TubeInputs,
|
|
101
|
-
VerificationKeyData,
|
|
102
|
-
BlockRootOrBlockMergePublicInputs,
|
|
103
|
-
BlockMergeRollupInputs,
|
|
104
|
-
BlockRootRollupInputs,
|
|
105
|
-
EmptyBlockRootRollupInputs,
|
|
106
|
-
},
|
|
107
|
-
{},
|
|
108
|
-
false,
|
|
109
|
-
namespace,
|
|
110
|
-
fetch,
|
|
111
|
-
) as ProvingJobSource;
|
|
11
|
+
export function createProvingJobSourceClient(url: string, fetch = makeFetch([1, 2, 3], false)): ProvingJobSource {
|
|
12
|
+
return createSafeJsonRpcClient(url, ProvingJobSourceSchema, false, 'provingJobSource', fetch);
|
|
112
13
|
}
|
|
113
14
|
|
|
114
15
|
/**
|
|
115
16
|
* Wrap a ProverAgent instance with a JSON RPC HTTP server.
|
|
116
|
-
* @param
|
|
17
|
+
* @param agent - The Prover Agent
|
|
117
18
|
* @returns An JSON-RPC HTTP server
|
|
118
19
|
*/
|
|
119
20
|
export function createProverAgentRpcServer(agent: ProverAgent) {
|
|
120
|
-
|
|
121
|
-
agent,
|
|
122
|
-
{
|
|
123
|
-
AztecAddress,
|
|
124
|
-
EthAddress,
|
|
125
|
-
Fr,
|
|
126
|
-
Header,
|
|
127
|
-
},
|
|
128
|
-
{},
|
|
129
|
-
// disable methods
|
|
130
|
-
['start', 'stop', 'setCircuitProver', 'work', 'getProof'],
|
|
131
|
-
);
|
|
132
|
-
return rpc;
|
|
21
|
+
return createSafeJsonRpcServer(agent, ProverAgentApiSchema);
|
|
133
22
|
}
|