@aztec/prover-client 0.47.1 → 0.49.2

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.
Files changed (58) hide show
  1. package/dest/config.d.ts +2 -2
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +23 -30
  4. package/dest/mocks/fixtures.d.ts.map +1 -1
  5. package/dest/mocks/fixtures.js +11 -7
  6. package/dest/mocks/test_context.d.ts +1 -1
  7. package/dest/mocks/test_context.d.ts.map +1 -1
  8. package/dest/mocks/test_context.js +5 -23
  9. package/dest/orchestrator/block-building-helpers.d.ts +3 -3
  10. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  11. package/dest/orchestrator/block-building-helpers.js +6 -5
  12. package/dest/orchestrator/index.d.ts +2 -0
  13. package/dest/orchestrator/index.d.ts.map +1 -0
  14. package/dest/orchestrator/index.js +2 -0
  15. package/dest/orchestrator/orchestrator.d.ts +12 -7
  16. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  17. package/dest/orchestrator/orchestrator.js +115 -89
  18. package/dest/orchestrator/orchestrator_metrics.d.ts +8 -0
  19. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -0
  20. package/dest/orchestrator/orchestrator_metrics.js +19 -0
  21. package/dest/orchestrator/proving-state.d.ts +2 -0
  22. package/dest/orchestrator/proving-state.d.ts.map +1 -1
  23. package/dest/orchestrator/proving-state.js +5 -1
  24. package/dest/orchestrator/tx-proving-state.d.ts +3 -2
  25. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  26. package/dest/orchestrator/tx-proving-state.js +26 -8
  27. package/dest/prover-agent/memory-proving-queue.d.ts +15 -13
  28. package/dest/prover-agent/memory-proving-queue.d.ts.map +1 -1
  29. package/dest/prover-agent/memory-proving-queue.js +37 -55
  30. package/dest/prover-agent/prover-agent.d.ts.map +1 -1
  31. package/dest/prover-agent/prover-agent.js +24 -7
  32. package/dest/prover-agent/queue_metrics.d.ts +10 -0
  33. package/dest/prover-agent/queue_metrics.d.ts.map +1 -0
  34. package/dest/prover-agent/queue_metrics.js +23 -0
  35. package/dest/prover-agent/rpc.d.ts.map +1 -1
  36. package/dest/prover-agent/rpc.js +4 -2
  37. package/dest/tx-prover/factory.d.ts +1 -3
  38. package/dest/tx-prover/factory.d.ts.map +1 -1
  39. package/dest/tx-prover/factory.js +3 -3
  40. package/dest/tx-prover/tx-prover.d.ts +8 -33
  41. package/dest/tx-prover/tx-prover.d.ts.map +1 -1
  42. package/dest/tx-prover/tx-prover.js +18 -46
  43. package/package.json +12 -11
  44. package/src/config.ts +23 -49
  45. package/src/mocks/fixtures.ts +14 -4
  46. package/src/mocks/test_context.ts +5 -25
  47. package/src/orchestrator/block-building-helpers.ts +6 -5
  48. package/src/orchestrator/index.ts +1 -0
  49. package/src/orchestrator/orchestrator.ts +199 -105
  50. package/src/orchestrator/orchestrator_metrics.ts +32 -0
  51. package/src/orchestrator/proving-state.ts +5 -0
  52. package/src/orchestrator/tx-proving-state.ts +33 -7
  53. package/src/prover-agent/memory-proving-queue.ts +54 -70
  54. package/src/prover-agent/prover-agent.ts +35 -6
  55. package/src/prover-agent/queue_metrics.ts +29 -0
  56. package/src/prover-agent/rpc.ts +3 -0
  57. package/src/tx-prover/factory.ts +2 -9
  58. package/src/tx-prover/tx-prover.ts +21 -64
@@ -31,35 +31,43 @@ import type {
31
31
  } from '@aztec/circuits.js';
32
32
  import { randomBytes } from '@aztec/foundation/crypto';
33
33
  import { AbortError, TimeoutError } from '@aztec/foundation/error';
34
- import { MemoryFifo } from '@aztec/foundation/fifo';
35
34
  import { createDebugLogger } from '@aztec/foundation/log';
36
35
  import { type PromiseWithResolvers, RunningPromise, promiseWithResolvers } from '@aztec/foundation/promise';
37
-
38
- type ProvingJobWithResolvers<T extends ProvingRequest = ProvingRequest> = {
39
- id: string;
40
- request: T;
41
- signal?: AbortSignal;
42
- attempts: number;
43
- heartbeat: number;
44
- } & PromiseWithResolvers<ProvingRequestResult<T['type']>>;
36
+ import { PriorityMemoryQueue } from '@aztec/foundation/queue';
37
+ import { serializeToBuffer } from '@aztec/foundation/serialize';
38
+ import { type TelemetryClient } from '@aztec/telemetry-client';
39
+
40
+ import { ProvingQueueMetrics } from './queue_metrics.js';
41
+
42
+ type ProvingJobWithResolvers<T extends ProvingRequest = ProvingRequest> = ProvingJob<T> &
43
+ PromiseWithResolvers<ProvingRequestResult<T['type']>> & {
44
+ signal?: AbortSignal;
45
+ epochNumber?: number;
46
+ attempts: number;
47
+ heartbeat: number;
48
+ };
45
49
 
46
50
  const MAX_RETRIES = 3;
47
51
 
48
52
  const defaultIdGenerator = () => randomBytes(4).toString('hex');
49
53
  const defaultTimeSource = () => Date.now();
50
-
51
54
  /**
52
55
  * A helper class that sits in between services that need proofs created and agents that can create them.
53
- * The queue accumulates jobs and provides them to agents in FIFO order.
56
+ * The queue accumulates jobs and provides them to agents prioritized by block number.
54
57
  */
55
58
  export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource {
56
59
  private log = createDebugLogger('aztec:prover-client:prover-pool:queue');
57
- private queue = new MemoryFifo<ProvingJobWithResolvers>();
60
+ private queue = new PriorityMemoryQueue<ProvingJobWithResolvers>(
61
+ (a, b) => (a.epochNumber ?? 0) - (b.epochNumber ?? 0),
62
+ );
58
63
  private jobsInProgress = new Map<string, ProvingJobWithResolvers>();
59
64
 
60
65
  private runningPromise: RunningPromise;
61
66
 
67
+ private metrics: ProvingQueueMetrics;
68
+
62
69
  constructor(
70
+ client: TelemetryClient,
63
71
  /** Timeout the job if an agent doesn't report back in this time */
64
72
  private jobTimeoutMs = 60 * 1000,
65
73
  /** How often to check for timed out jobs */
@@ -67,6 +75,7 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
67
75
  private generateId = defaultIdGenerator,
68
76
  private timeSource = defaultTimeSource,
69
77
  ) {
78
+ this.metrics = new ProvingQueueMetrics(client, 'MemoryProvingQueue');
70
79
  this.runningPromise = new RunningPromise(this.poll, pollingIntervalMs);
71
80
  }
72
81
 
@@ -156,7 +165,8 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
156
165
  return Promise.resolve();
157
166
  }
158
167
 
159
- if (job.attempts < MAX_RETRIES) {
168
+ // every job should be retried with the exception of the public VM since its in development and can fail
169
+ if (job.attempts < MAX_RETRIES && job.request.type !== ProvingRequestType.PUBLIC_VM) {
160
170
  job.attempts++;
161
171
  this.log.warn(
162
172
  `Job id=${job.id} type=${ProvingRequestType[job.request.type]} failed with error: ${err}. Retry ${
@@ -190,6 +200,7 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
190
200
 
191
201
  private poll = () => {
192
202
  const now = this.timeSource();
203
+ this.metrics.recordQueueSize(this.queue.length());
193
204
 
194
205
  for (const job of this.jobsInProgress.values()) {
195
206
  if (job.signal?.aborted) {
@@ -210,6 +221,7 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
210
221
  private enqueue<T extends ProvingRequest>(
211
222
  request: T,
212
223
  signal?: AbortSignal,
224
+ epochNumber?: number,
213
225
  ): Promise<ProvingRequestResult<T['type']>> {
214
226
  if (!this.runningPromise.isRunning()) {
215
227
  return Promise.reject(new Error('Proving queue is not running.'));
@@ -225,6 +237,7 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
225
237
  reject,
226
238
  attempts: 1,
227
239
  heartbeat: 0,
240
+ epochNumber,
228
241
  };
229
242
 
230
243
  if (signal) {
@@ -239,28 +252,34 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
239
252
  throw new Error();
240
253
  }
241
254
 
255
+ const byteSize = serializeToBuffer(item.request.inputs).length;
256
+ this.metrics.recordNewJob(item.request.type, byteSize);
257
+
242
258
  return promise;
243
259
  }
244
260
 
245
261
  getEmptyPrivateKernelProof(
246
262
  inputs: PrivateKernelEmptyInputData,
247
263
  signal?: AbortSignal,
264
+ epochNumber?: number,
248
265
  ): Promise<PublicInputsAndRecursiveProof<KernelCircuitPublicInputs>> {
249
- return this.enqueue({ type: ProvingRequestType.PRIVATE_KERNEL_EMPTY, inputs }, signal);
266
+ return this.enqueue({ type: ProvingRequestType.PRIVATE_KERNEL_EMPTY, inputs }, signal, epochNumber);
250
267
  }
251
268
 
252
269
  getTubeProof(
253
270
  inputs: TubeInputs,
254
- signal?: AbortSignal | undefined,
271
+ signal?: AbortSignal,
272
+ epochNumber?: number,
255
273
  ): Promise<{ tubeVK: VerificationKeyData; tubeProof: RecursiveProof<typeof RECURSIVE_PROOF_LENGTH> }> {
256
- return this.enqueue({ type: ProvingRequestType.TUBE_PROOF, inputs }, signal);
274
+ return this.enqueue({ type: ProvingRequestType.TUBE_PROOF, inputs }, signal, epochNumber);
257
275
  }
258
276
 
259
277
  getEmptyTubeProof(
260
278
  inputs: PrivateKernelEmptyInputData,
261
279
  signal?: AbortSignal,
280
+ epochNumber?: number,
262
281
  ): Promise<PublicInputsAndRecursiveProof<KernelCircuitPublicInputs>> {
263
- return this.enqueue({ type: ProvingRequestType.PRIVATE_KERNEL_EMPTY, inputs }, signal);
282
+ return this.enqueue({ type: ProvingRequestType.PRIVATE_KERNEL_EMPTY, inputs }, signal, epochNumber);
264
283
  }
265
284
 
266
285
  /**
@@ -270,14 +289,9 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
270
289
  getBaseParityProof(
271
290
  inputs: BaseParityInputs,
272
291
  signal?: AbortSignal,
292
+ epochNumber?: number,
273
293
  ): Promise<RootParityInput<typeof RECURSIVE_PROOF_LENGTH>> {
274
- return this.enqueue(
275
- {
276
- type: ProvingRequestType.BASE_PARITY,
277
- inputs,
278
- },
279
- signal,
280
- );
294
+ return this.enqueue({ type: ProvingRequestType.BASE_PARITY, inputs }, signal, epochNumber);
281
295
  }
282
296
 
283
297
  /**
@@ -287,14 +301,9 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
287
301
  getRootParityProof(
288
302
  inputs: RootParityInputs,
289
303
  signal?: AbortSignal,
304
+ epochNumber?: number,
290
305
  ): Promise<RootParityInput<typeof NESTED_RECURSIVE_PROOF_LENGTH>> {
291
- return this.enqueue(
292
- {
293
- type: ProvingRequestType.ROOT_PARITY,
294
- inputs,
295
- },
296
- signal,
297
- );
306
+ return this.enqueue({ type: ProvingRequestType.ROOT_PARITY, inputs }, signal, epochNumber);
298
307
  }
299
308
 
300
309
  /**
@@ -304,14 +313,9 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
304
313
  getBaseRollupProof(
305
314
  baseRollupInput: BaseRollupInputs,
306
315
  signal?: AbortSignal,
316
+ epochNumber?: number,
307
317
  ): Promise<PublicInputsAndRecursiveProof<BaseOrMergeRollupPublicInputs>> {
308
- return this.enqueue(
309
- {
310
- type: ProvingRequestType.BASE_ROLLUP,
311
- inputs: baseRollupInput,
312
- },
313
- signal,
314
- );
318
+ return this.enqueue({ type: ProvingRequestType.BASE_ROLLUP, inputs: baseRollupInput }, signal, epochNumber);
315
319
  }
316
320
 
317
321
  /**
@@ -321,14 +325,9 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
321
325
  getMergeRollupProof(
322
326
  input: MergeRollupInputs,
323
327
  signal?: AbortSignal,
328
+ epochNumber?: number,
324
329
  ): Promise<PublicInputsAndRecursiveProof<BaseOrMergeRollupPublicInputs>> {
325
- return this.enqueue(
326
- {
327
- type: ProvingRequestType.MERGE_ROLLUP,
328
- inputs: input,
329
- },
330
- signal,
331
- );
330
+ return this.enqueue({ type: ProvingRequestType.MERGE_ROLLUP, inputs: input }, signal, epochNumber);
332
331
  }
333
332
 
334
333
  /**
@@ -338,14 +337,9 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
338
337
  getRootRollupProof(
339
338
  input: RootRollupInputs,
340
339
  signal?: AbortSignal,
340
+ epochNumber?: number,
341
341
  ): Promise<PublicInputsAndRecursiveProof<RootRollupPublicInputs>> {
342
- return this.enqueue(
343
- {
344
- type: ProvingRequestType.ROOT_ROLLUP,
345
- inputs: input,
346
- },
347
- signal,
348
- );
342
+ return this.enqueue({ type: ProvingRequestType.ROOT_ROLLUP, inputs: input }, signal, epochNumber);
349
343
  }
350
344
 
351
345
  /**
@@ -355,14 +349,12 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
355
349
  getPublicKernelProof(
356
350
  kernelRequest: PublicKernelNonTailRequest,
357
351
  signal?: AbortSignal,
352
+ epochNumber?: number,
358
353
  ): Promise<PublicInputsAndRecursiveProof<PublicKernelCircuitPublicInputs>> {
359
354
  return this.enqueue(
360
- {
361
- type: ProvingRequestType.PUBLIC_KERNEL_NON_TAIL,
362
- kernelType: kernelRequest.type,
363
- inputs: kernelRequest.inputs,
364
- },
355
+ { type: ProvingRequestType.PUBLIC_KERNEL_NON_TAIL, kernelType: kernelRequest.type, inputs: kernelRequest.inputs },
365
356
  signal,
357
+ epochNumber,
366
358
  );
367
359
  }
368
360
 
@@ -373,28 +365,20 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource
373
365
  getPublicTailProof(
374
366
  kernelRequest: PublicKernelTailRequest,
375
367
  signal?: AbortSignal,
368
+ epochNumber?: number,
376
369
  ): Promise<PublicInputsAndRecursiveProof<KernelCircuitPublicInputs>> {
377
370
  return this.enqueue(
378
- {
379
- type: ProvingRequestType.PUBLIC_KERNEL_TAIL,
380
- kernelType: kernelRequest.type,
381
- inputs: kernelRequest.inputs,
382
- },
371
+ { type: ProvingRequestType.PUBLIC_KERNEL_TAIL, kernelType: kernelRequest.type, inputs: kernelRequest.inputs },
383
372
  signal,
373
+ epochNumber,
384
374
  );
385
375
  }
386
376
 
387
377
  /**
388
378
  * Creates an AVM proof.
389
379
  */
390
- getAvmProof(inputs: AvmCircuitInputs, signal?: AbortSignal | undefined): Promise<ProofAndVerificationKey> {
391
- return this.enqueue(
392
- {
393
- type: ProvingRequestType.PUBLIC_VM,
394
- inputs,
395
- },
396
- signal,
397
- );
380
+ getAvmProof(inputs: AvmCircuitInputs, signal?: AbortSignal, epochNumber?: number): Promise<ProofAndVerificationKey> {
381
+ return this.enqueue({ type: ProvingRequestType.PUBLIC_VM, inputs }, signal, epochNumber);
398
382
  }
399
383
 
400
384
  /**
@@ -12,11 +12,20 @@ import { elapsed } from '@aztec/foundation/timer';
12
12
 
13
13
  import { ProvingError } from './proving-error.js';
14
14
 
15
+ const PRINT_THRESHOLD_NS = 6e10; // 60 seconds
16
+
15
17
  /**
16
18
  * A helper class that encapsulates a circuit prover and connects it to a job source.
17
19
  */
18
20
  export class ProverAgent {
19
- private inFlightPromises = new Map<string, Promise<any>>();
21
+ private inFlightPromises = new Map<
22
+ string,
23
+ {
24
+ id: string;
25
+ type: ProvingRequestType;
26
+ promise: Promise<any>;
27
+ }
28
+ >();
20
29
  private runningPromise?: RunningPromise;
21
30
 
22
31
  constructor(
@@ -49,11 +58,26 @@ export class ProverAgent {
49
58
  throw new Error('Agent is already running');
50
59
  }
51
60
 
61
+ let lastPrint = process.hrtime.bigint();
62
+
52
63
  this.runningPromise = new RunningPromise(async () => {
53
64
  for (const jobId of this.inFlightPromises.keys()) {
54
65
  await jobSource.heartbeat(jobId);
55
66
  }
56
67
 
68
+ const now = process.hrtime.bigint();
69
+
70
+ if (now - lastPrint >= PRINT_THRESHOLD_NS) {
71
+ // only log if we're actually doing work
72
+ if (this.inFlightPromises.size > 0) {
73
+ const jobs = Array.from(this.inFlightPromises.values())
74
+ .map(job => `id=${job.id},type=${ProvingRequestType[job.type]}`)
75
+ .join(' ');
76
+ this.log.info(`Agent is running with ${this.inFlightPromises.size} in-flight jobs: ${jobs}`);
77
+ }
78
+ lastPrint = now;
79
+ }
80
+
57
81
  while (this.inFlightPromises.size < this.maxConcurrency) {
58
82
  try {
59
83
  const job = await jobSource.getProvingJob();
@@ -64,14 +88,18 @@ export class ProverAgent {
64
88
 
65
89
  try {
66
90
  const promise = this.work(jobSource, job).finally(() => this.inFlightPromises.delete(job.id));
67
- this.inFlightPromises.set(job.id, promise);
91
+ this.inFlightPromises.set(job.id, {
92
+ id: job.id,
93
+ type: job.request.type,
94
+ promise,
95
+ });
68
96
  } catch (err) {
69
97
  this.log.warn(
70
98
  `Error processing job! type=${ProvingRequestType[job.request.type]}: ${err}. ${(err as Error).stack}`,
71
99
  );
72
100
  }
73
101
  } catch (err) {
74
- // no-op
102
+ this.log.error(`Error fetching job`, err);
75
103
  }
76
104
  }
77
105
  }, this.pollIntervalMs);
@@ -96,12 +124,12 @@ export class ProverAgent {
96
124
  this.log.debug(`Picked up proving job id=${job.id} type=${ProvingRequestType[job.request.type]}`);
97
125
  const [time, result] = await elapsed(this.getProof(job.request));
98
126
  if (this.isRunning()) {
99
- this.log.debug(
127
+ this.log.verbose(
100
128
  `Processed proving job id=${job.id} type=${ProvingRequestType[job.request.type]} duration=${time}ms`,
101
129
  );
102
130
  await jobSource.resolveProvingJob(job.id, result);
103
131
  } else {
104
- this.log.debug(
132
+ this.log.verbose(
105
133
  `Dropping proving job id=${job.id} type=${
106
134
  ProvingRequestType[job.request.type]
107
135
  } duration=${time}ms: agent stopped`,
@@ -113,10 +141,11 @@ export class ProverAgent {
113
141
  `Error processing proving job id=${job.id} type=${ProvingRequestType[job.request.type]}: ${
114
142
  (err as any).stack || err
115
143
  }`,
144
+ err,
116
145
  );
117
146
  await jobSource.rejectProvingJob(job.id, new ProvingError((err as any)?.message ?? String(err)));
118
147
  } else {
119
- this.log.debug(
148
+ this.log.verbose(
120
149
  `Dropping proving job id=${job.id} type=${ProvingRequestType[job.request.type]}: agent stopped: ${
121
150
  (err as any).stack || err
122
151
  }`,
@@ -0,0 +1,29 @@
1
+ import { ProvingRequestType } from '@aztec/circuit-types';
2
+ import { Attributes, type Gauge, type Histogram, Metrics, type TelemetryClient } from '@aztec/telemetry-client';
3
+
4
+ export class ProvingQueueMetrics {
5
+ private jobSize: Histogram;
6
+ private queueSize: Gauge;
7
+
8
+ constructor(client: TelemetryClient, name = 'ProvingQueueMetrics') {
9
+ const meter = client.getMeter(name);
10
+ this.jobSize = meter.createHistogram(Metrics.PROVING_QUEUE_JOB_SIZE, {
11
+ description: 'Size of proving job',
12
+ unit: 'by',
13
+ });
14
+
15
+ this.queueSize = meter.createGauge(Metrics.PROVING_QUEUE_SIZE, {
16
+ description: 'Size of proving queue',
17
+ });
18
+ }
19
+
20
+ recordNewJob(type: ProvingRequestType, size: number) {
21
+ this.jobSize.record(size, {
22
+ [Attributes.PROVING_JOB_TYPE]: ProvingRequestType[type],
23
+ });
24
+ }
25
+
26
+ recordQueueSize(size: number) {
27
+ this.queueSize.record(size);
28
+ }
29
+ }
@@ -9,6 +9,7 @@ import {
9
9
  KernelCircuitPublicInputs,
10
10
  MergeRollupInputs,
11
11
  ParityPublicInputs,
12
+ PrivateKernelEmptyInputData,
12
13
  Proof,
13
14
  PublicKernelCircuitPrivateInputs,
14
15
  PublicKernelCircuitPublicInputs,
@@ -41,6 +42,7 @@ export function createProvingJobSourceServer(queue: ProvingJobSource): JsonRpcSe
41
42
  ParityPublicInputs,
42
43
  Proof,
43
44
  ProvingError,
45
+ PrivateKernelEmptyInputData,
44
46
  PublicKernelCircuitPrivateInputs,
45
47
  PublicKernelCircuitPublicInputs,
46
48
  PublicKernelTailCircuitPrivateInputs,
@@ -75,6 +77,7 @@ export function createProvingJobSourceClient(
75
77
  ParityPublicInputs,
76
78
  Proof,
77
79
  ProvingError,
80
+ PrivateKernelEmptyInputData,
78
81
  PublicKernelCircuitPrivateInputs,
79
82
  PublicKernelCircuitPublicInputs,
80
83
  PublicKernelTailCircuitPrivateInputs,
@@ -1,16 +1,9 @@
1
- import { type L2BlockSource } from '@aztec/circuit-types';
2
1
  import { type TelemetryClient } from '@aztec/telemetry-client';
3
2
  import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
4
- import { type WorldStateSynchronizer } from '@aztec/world-state';
5
3
 
6
4
  import { type ProverClientConfig } from '../config.js';
7
5
  import { TxProver } from './tx-prover.js';
8
6
 
9
- export function createProverClient(
10
- config: ProverClientConfig,
11
- worldStateSynchronizer: WorldStateSynchronizer,
12
- blockSource: L2BlockSource,
13
- telemetry: TelemetryClient = new NoopTelemetryClient(),
14
- ) {
15
- return config.disableProver ? undefined : TxProver.new(config, worldStateSynchronizer, blockSource, telemetry);
7
+ export function createProverClient(config: ProverClientConfig, telemetry: TelemetryClient = new NoopTelemetryClient()) {
8
+ return TxProver.new(config, telemetry);
16
9
  }
@@ -1,16 +1,14 @@
1
1
  import { BBNativeRollupProver, TestCircuitProver } from '@aztec/bb-prover';
2
- import { type L2BlockSource, type ProcessedTx } from '@aztec/circuit-types';
3
2
  import {
4
- type BlockResult,
3
+ type BlockProver,
5
4
  type ProverClient,
6
5
  type ProvingJobSource,
7
- type ProvingTicket,
8
6
  type ServerCircuitProver,
9
7
  } from '@aztec/circuit-types/interfaces';
10
- import { type Fr, type GlobalVariables } from '@aztec/circuits.js';
8
+ import { Fr } from '@aztec/circuits.js';
11
9
  import { NativeACVMSimulator } from '@aztec/simulator';
12
10
  import { type TelemetryClient } from '@aztec/telemetry-client';
13
- import { type WorldStateSynchronizer } from '@aztec/world-state';
11
+ import { type MerkleTreeOperations } from '@aztec/world-state';
14
12
 
15
13
  import { type ProverClientConfig } from '../config.js';
16
14
  import { ProvingOrchestrator } from '../orchestrator/orchestrator.js';
@@ -18,21 +16,29 @@ import { MemoryProvingQueue } from '../prover-agent/memory-proving-queue.js';
18
16
  import { ProverAgent } from '../prover-agent/prover-agent.js';
19
17
 
20
18
  /**
21
- * A prover accepting individual transaction requests
19
+ * A prover factory.
20
+ * TODO(palla/prover-node): Rename this class
22
21
  */
23
22
  export class TxProver implements ProverClient {
24
- private orchestrator: ProvingOrchestrator;
25
23
  private queue: MemoryProvingQueue;
26
24
  private running = false;
27
25
 
28
26
  private constructor(
29
27
  private config: ProverClientConfig,
30
- private worldStateSynchronizer: WorldStateSynchronizer,
31
28
  private telemetry: TelemetryClient,
32
29
  private agent?: ProverAgent,
33
30
  ) {
34
- this.queue = new MemoryProvingQueue(config.proverJobTimeoutMs, config.proverJobPollIntervalMs);
35
- this.orchestrator = new ProvingOrchestrator(worldStateSynchronizer.getLatest(), this.queue, telemetry);
31
+ // TODO(palla/prover-node): Cache the paddingTx here, and not in each proving orchestrator,
32
+ // so it can be reused across multiple ones and not recomputed every time.
33
+ this.queue = new MemoryProvingQueue(telemetry, config.proverJobTimeoutMs, config.proverJobPollIntervalMs);
34
+ }
35
+
36
+ public createBlockProver(db: MerkleTreeOperations): BlockProver {
37
+ return new ProvingOrchestrator(db, this.queue, this.telemetry, this.config.proverId);
38
+ }
39
+
40
+ public getProverId(): Fr {
41
+ return this.config.proverId ?? Fr.ZERO;
36
42
  }
37
43
 
38
44
  async updateProverConfig(config: Partial<ProverClientConfig>): Promise<void> {
@@ -48,7 +54,7 @@ export class TxProver implements ProverClient {
48
54
  }
49
55
 
50
56
  if (!this.config.realProofs && newConfig.realProofs) {
51
- this.orchestrator.reset();
57
+ // TODO(palla/prover-node): Reset padding tx here once we cache it at this class
52
58
  }
53
59
 
54
60
  this.config = newConfig;
@@ -76,6 +82,8 @@ export class TxProver implements ProverClient {
76
82
  return;
77
83
  }
78
84
  this.running = false;
85
+
86
+ // TODO(palla/prover-node): Keep a reference to all proving orchestrators that are alive and stop them?
79
87
  await this.agent?.stop();
80
88
  await this.queue.stop();
81
89
  }
@@ -87,12 +95,7 @@ export class TxProver implements ProverClient {
87
95
  * @param worldStateSynchronizer - An instance of the world state
88
96
  * @returns An instance of the prover, constructed and started.
89
97
  */
90
- public static async new(
91
- config: ProverClientConfig,
92
- worldStateSynchronizer: WorldStateSynchronizer,
93
- blockSource: L2BlockSource,
94
- telemetry: TelemetryClient,
95
- ) {
98
+ public static async new(config: ProverClientConfig, telemetry: TelemetryClient) {
96
99
  const agent = config.proverAgentEnabled
97
100
  ? new ProverAgent(
98
101
  await TxProver.buildCircuitProver(config, telemetry),
@@ -101,7 +104,7 @@ export class TxProver implements ProverClient {
101
104
  )
102
105
  : undefined;
103
106
 
104
- const prover = new TxProver(config, worldStateSynchronizer, telemetry, agent);
107
+ const prover = new TxProver(config, telemetry, agent);
105
108
  await prover.start();
106
109
  return prover;
107
110
  }
@@ -121,52 +124,6 @@ export class TxProver implements ProverClient {
121
124
  return new TestCircuitProver(telemetry, simulationProvider);
122
125
  }
123
126
 
124
- /**
125
- * Cancels any block that is currently being built and prepares for a new one to be built
126
- * @param numTxs - The complete size of the block, must be a power of 2
127
- * @param globalVariables - The global variables for this block
128
- * @param l1ToL2Messages - The set of L1 to L2 messages to be included in this block
129
- */
130
- public async startNewBlock(
131
- numTxs: number,
132
- globalVariables: GlobalVariables,
133
- newL1ToL2Messages: Fr[],
134
- ): Promise<ProvingTicket> {
135
- const previousBlockNumber = globalVariables.blockNumber.toNumber() - 1;
136
- await this.worldStateSynchronizer.syncImmediate(previousBlockNumber);
137
- return this.orchestrator.startNewBlock(numTxs, globalVariables, newL1ToL2Messages);
138
- }
139
-
140
- /**
141
- * Add a processed transaction to the current block
142
- * @param tx - The transaction to be added
143
- */
144
- public addNewTx(tx: ProcessedTx): Promise<void> {
145
- return this.orchestrator.addNewTx(tx);
146
- }
147
-
148
- /**
149
- * Cancels the block currently being proven. Proofs already bring built may continue but further proofs should not be started.
150
- */
151
- public cancelBlock(): void {
152
- this.orchestrator.cancelBlock();
153
- }
154
-
155
- /**
156
- * Performs the final archive tree insertion for this block and returns the L2Block and Proof instances
157
- */
158
- public finaliseBlock(): Promise<BlockResult> {
159
- return this.orchestrator.finaliseBlock();
160
- }
161
-
162
- /**
163
- * Mark the block as having all the transactions it is going to contain.
164
- * Will pad the block to it's complete size with empty transactions and prove all the way to the root rollup.
165
- */
166
- public setBlockCompleted(): Promise<void> {
167
- return this.orchestrator.setBlockCompleted();
168
- }
169
-
170
127
  public getProvingJobSource(): ProvingJobSource {
171
128
  return this.queue;
172
129
  }