@aztec/prover-client 0.0.1-commit.d3ec352c → 0.0.1-commit.e3c1de76

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 (107) hide show
  1. package/dest/config.d.ts +2 -2
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +1 -1
  4. package/dest/light/index.d.ts +2 -0
  5. package/dest/light/index.d.ts.map +1 -0
  6. package/dest/light/index.js +1 -0
  7. package/dest/light/lightweight_checkpoint_builder.d.ts +33 -15
  8. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
  9. package/dest/light/lightweight_checkpoint_builder.js +116 -23
  10. package/dest/mocks/fixtures.d.ts +1 -1
  11. package/dest/mocks/fixtures.d.ts.map +1 -1
  12. package/dest/mocks/fixtures.js +4 -3
  13. package/dest/mocks/test_context.d.ts +5 -3
  14. package/dest/mocks/test_context.d.ts.map +1 -1
  15. package/dest/mocks/test_context.js +21 -8
  16. package/dest/orchestrator/block-building-helpers.d.ts +3 -3
  17. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  18. package/dest/orchestrator/block-building-helpers.js +3 -3
  19. package/dest/orchestrator/block-proving-state.d.ts +2 -2
  20. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  21. package/dest/orchestrator/block-proving-state.js +1 -1
  22. package/dest/orchestrator/checkpoint-proving-state.d.ts +16 -3
  23. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
  24. package/dest/orchestrator/checkpoint-proving-state.js +36 -2
  25. package/dest/orchestrator/epoch-proving-state.d.ts +5 -4
  26. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  27. package/dest/orchestrator/epoch-proving-state.js +35 -1
  28. package/dest/orchestrator/orchestrator.d.ts +20 -5
  29. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  30. package/dest/orchestrator/orchestrator.js +535 -134
  31. package/dest/orchestrator/orchestrator_metrics.d.ts +1 -3
  32. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
  33. package/dest/orchestrator/orchestrator_metrics.js +2 -15
  34. package/dest/orchestrator/tx-proving-state.d.ts +6 -5
  35. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  36. package/dest/orchestrator/tx-proving-state.js +8 -8
  37. package/dest/prover-client/factory.d.ts +3 -3
  38. package/dest/prover-client/factory.d.ts.map +1 -1
  39. package/dest/prover-client/prover-client.d.ts +3 -3
  40. package/dest/prover-client/prover-client.d.ts.map +1 -1
  41. package/dest/prover-client/prover-client.js +7 -4
  42. package/dest/prover-client/server-epoch-prover.d.ts +2 -2
  43. package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
  44. package/dest/proving_broker/broker_prover_facade.d.ts +7 -5
  45. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  46. package/dest/proving_broker/broker_prover_facade.js +6 -13
  47. package/dest/proving_broker/config.d.ts +6 -2
  48. package/dest/proving_broker/config.d.ts.map +1 -1
  49. package/dest/proving_broker/config.js +8 -2
  50. package/dest/proving_broker/fixtures.js +1 -1
  51. package/dest/proving_broker/proving_agent.d.ts +5 -9
  52. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  53. package/dest/proving_broker/proving_agent.js +4 -19
  54. package/dest/proving_broker/proving_broker.d.ts +1 -1
  55. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  56. package/dest/proving_broker/proving_broker.js +4 -10
  57. package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
  58. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  59. package/dest/proving_broker/proving_broker_database/persisted.js +389 -1
  60. package/dest/proving_broker/proving_broker_instrumentation.d.ts +1 -1
  61. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  62. package/dest/proving_broker/proving_broker_instrumentation.js +15 -35
  63. package/dest/proving_broker/proving_job_controller.d.ts +4 -3
  64. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  65. package/dest/proving_broker/proving_job_controller.js +8 -6
  66. package/dest/test/mock_proof_store.d.ts +3 -3
  67. package/dest/test/mock_proof_store.d.ts.map +1 -1
  68. package/dest/test/mock_prover.d.ts +2 -2
  69. package/dest/test/mock_prover.d.ts.map +1 -1
  70. package/dest/test/mock_prover.js +4 -4
  71. package/package.json +18 -17
  72. package/src/config.ts +1 -1
  73. package/src/light/index.ts +1 -0
  74. package/src/light/lightweight_checkpoint_builder.ts +177 -31
  75. package/src/mocks/fixtures.ts +4 -3
  76. package/src/mocks/test_context.ts +18 -6
  77. package/src/orchestrator/block-building-helpers.ts +3 -3
  78. package/src/orchestrator/block-proving-state.ts +1 -1
  79. package/src/orchestrator/checkpoint-proving-state.ts +49 -2
  80. package/src/orchestrator/epoch-proving-state.ts +56 -8
  81. package/src/orchestrator/orchestrator.ts +130 -114
  82. package/src/orchestrator/orchestrator_metrics.ts +2 -25
  83. package/src/orchestrator/tx-proving-state.ts +10 -14
  84. package/src/prover-client/factory.ts +6 -2
  85. package/src/prover-client/prover-client.ts +25 -15
  86. package/src/prover-client/server-epoch-prover.ts +1 -1
  87. package/src/proving_broker/broker_prover_facade.ts +10 -17
  88. package/src/proving_broker/config.ts +10 -1
  89. package/src/proving_broker/fixtures.ts +1 -1
  90. package/src/proving_broker/proving_agent.ts +6 -19
  91. package/src/proving_broker/proving_broker.ts +4 -8
  92. package/src/proving_broker/proving_broker_database/persisted.ts +15 -1
  93. package/src/proving_broker/proving_broker_instrumentation.ts +14 -35
  94. package/src/proving_broker/proving_job_controller.ts +11 -6
  95. package/src/test/mock_prover.ts +2 -14
  96. package/dest/block-factory/index.d.ts +0 -2
  97. package/dest/block-factory/index.d.ts.map +0 -1
  98. package/dest/block-factory/index.js +0 -1
  99. package/dest/block-factory/light.d.ts +0 -38
  100. package/dest/block-factory/light.d.ts.map +0 -1
  101. package/dest/block-factory/light.js +0 -108
  102. package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
  103. package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
  104. package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
  105. package/src/block-factory/index.ts +0 -1
  106. package/src/block-factory/light.ts +0 -137
  107. package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
@@ -8,21 +8,21 @@ import {
8
8
  } from '@aztec/constants';
9
9
  import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
10
10
  import { padArrayEnd } from '@aztec/foundation/collection';
11
+ import { Fr } from '@aztec/foundation/curves/bn254';
11
12
  import { AbortError } from '@aztec/foundation/error';
12
- import { Fr } from '@aztec/foundation/fields';
13
- import { createLogger } from '@aztec/foundation/log';
13
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
14
14
  import { promiseWithResolvers } from '@aztec/foundation/promise';
15
15
  import { assertLength } from '@aztec/foundation/serialize';
16
16
  import { pushTestData } from '@aztec/foundation/testing';
17
17
  import { elapsed } from '@aztec/foundation/timer';
18
18
  import type { TreeNodeLocation } from '@aztec/foundation/trees';
19
- import { readAvmMinimalPublicTxInputsFromFile } from '@aztec/simulator/public/fixtures';
20
19
  import { EthAddress } from '@aztec/stdlib/block';
21
20
  import type {
22
21
  EpochProver,
23
22
  ForkMerkleTreeOperations,
24
23
  MerkleTreeWriteOperations,
25
24
  PublicInputsAndRecursiveProof,
25
+ ReadonlyWorldStateAccess,
26
26
  ServerCircuitProver,
27
27
  } from '@aztec/stdlib/interfaces/server';
28
28
  import type { Proof } from '@aztec/stdlib/proofs';
@@ -71,7 +71,10 @@ import { EpochProvingState, type ProvingResult, type TreeSnapshots } from './epo
71
71
  import { ProvingOrchestratorMetrics } from './orchestrator_metrics.js';
72
72
  import { TxProvingState } from './tx-proving-state.js';
73
73
 
74
- const logger = createLogger('prover-client:orchestrator');
74
+ type WorldStateFork = {
75
+ fork: MerkleTreeWriteOperations;
76
+ cleanupPromise: Promise<void> | undefined;
77
+ };
75
78
 
76
79
  /**
77
80
  * Implements an event driven proving scheduler to build the recursive proof tree. The idea being:
@@ -94,14 +97,18 @@ export class ProvingOrchestrator implements EpochProver {
94
97
  private provingPromise: Promise<ProvingResult> | undefined = undefined;
95
98
  private metrics: ProvingOrchestratorMetrics;
96
99
  // eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
97
- private dbs: Map<BlockNumber, MerkleTreeWriteOperations> = new Map();
100
+ private dbs: Map<BlockNumber, WorldStateFork> = new Map();
101
+ private logger: Logger;
98
102
 
99
103
  constructor(
100
- private dbProvider: ForkMerkleTreeOperations,
104
+ private dbProvider: ReadonlyWorldStateAccess & ForkMerkleTreeOperations,
101
105
  private prover: ServerCircuitProver,
102
106
  private readonly proverId: EthAddress,
107
+ private readonly cancelJobsOnStop: boolean = false,
103
108
  telemetryClient: TelemetryClient = getTelemetryClient(),
109
+ bindings?: LoggerBindings,
104
110
  ) {
111
+ this.logger = createLogger('prover-client:orchestrator', bindings);
105
112
  this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'ProvingOrchestrator');
106
113
  }
107
114
 
@@ -113,6 +120,10 @@ export class ProvingOrchestrator implements EpochProver {
113
120
  return this.proverId;
114
121
  }
115
122
 
123
+ public getNumActiveForks() {
124
+ return this.dbs.size;
125
+ }
126
+
116
127
  public stop(): Promise<void> {
117
128
  this.cancel();
118
129
  return Promise.resolve();
@@ -131,7 +142,7 @@ export class ProvingOrchestrator implements EpochProver {
131
142
 
132
143
  const { promise: _promise, resolve, reject } = promiseWithResolvers<ProvingResult>();
133
144
  const promise = _promise.catch((reason): ProvingResult => ({ status: 'failure', reason }));
134
- logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
145
+ this.logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
135
146
  this.provingState = new EpochProvingState(
136
147
  epochNumber,
137
148
  totalNumCheckpoints,
@@ -143,6 +154,14 @@ export class ProvingOrchestrator implements EpochProver {
143
154
  this.provingPromise = promise;
144
155
  }
145
156
 
157
+ /**
158
+ * Starts a new checkpoint.
159
+ * @param checkpointIndex - The index of the checkpoint in the epoch.
160
+ * @param constants - The constants for this checkpoint.
161
+ * @param l1ToL2Messages - The set of L1 to L2 messages to be inserted at the beginning of this checkpoint.
162
+ * @param totalNumBlocks - The total number of blocks expected in the checkpoint (must be at least one).
163
+ * @param headerOfLastBlockInPreviousCheckpoint - The header of the last block in the previous checkpoint.
164
+ */
146
165
  public async startNewCheckpoint(
147
166
  checkpointIndex: number,
148
167
  constants: CheckpointConstantData,
@@ -163,7 +182,7 @@ export class ProvingOrchestrator implements EpochProver {
163
182
  const db = await this.dbProvider.fork(lastBlockNumber);
164
183
 
165
184
  const firstBlockNumber = BlockNumber(lastBlockNumber + 1);
166
- this.dbs.set(firstBlockNumber, db);
185
+ this.dbs.set(firstBlockNumber, { fork: db, cleanupPromise: undefined });
167
186
 
168
187
  // Get archive sibling path before any block in this checkpoint lands.
169
188
  const lastArchiveSiblingPath = await getLastSiblingPath(MerkleTreeId.ARCHIVE, db);
@@ -215,15 +234,15 @@ export class ProvingOrchestrator implements EpochProver {
215
234
  }
216
235
 
217
236
  const constants = checkpointProvingState.constants;
218
- logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
237
+ this.logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
219
238
 
220
239
  // Fork the db only when it's not already set. The db for the first block is set in `startNewCheckpoint`.
221
240
  if (!this.dbs.has(blockNumber)) {
222
241
  // Fork world state at the end of the immediately previous block
223
242
  const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
224
- this.dbs.set(blockNumber, db);
243
+ this.dbs.set(blockNumber, { fork: db, cleanupPromise: undefined });
225
244
  }
226
- const db = this.dbs.get(blockNumber)!;
245
+ const db = this.dbs.get(blockNumber)!.fork;
227
246
 
228
247
  // Get archive snapshot and sibling path before any txs in this block lands.
229
248
  const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
@@ -255,7 +274,8 @@ export class ProvingOrchestrator implements EpochProver {
255
274
  await endSpongeBlob.absorb(blockEndBlobFields);
256
275
  blockProvingState.setEndSpongeBlob(endSpongeBlob);
257
276
 
258
- // And also try to accumulate the blobs as far as we can:
277
+ // Try to accumulate the out hashes and blobs as far as we can:
278
+ await this.provingState.accumulateCheckpointOutHashes();
259
279
  await this.provingState.setBlobAccumulators();
260
280
  }
261
281
  }
@@ -275,7 +295,7 @@ export class ProvingOrchestrator implements EpochProver {
275
295
  if (!txs.length) {
276
296
  // To avoid an ugly throw below. If we require an empty block, we can just call setBlockCompleted
277
297
  // on a block with no txs. We cannot do that here because we cannot find the blockNumber without any txs.
278
- logger.warn(`Provided no txs to orchestrator addTxs.`);
298
+ this.logger.warn(`Provided no txs to orchestrator addTxs.`);
279
299
  return;
280
300
  }
281
301
 
@@ -295,9 +315,9 @@ export class ProvingOrchestrator implements EpochProver {
295
315
  throw new Error(`Block ${blockNumber} has been initialized with transactions.`);
296
316
  }
297
317
 
298
- logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
318
+ this.logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
299
319
 
300
- const db = this.dbs.get(blockNumber)!;
320
+ const db = this.dbs.get(blockNumber)!.fork;
301
321
  const lastArchive = provingState.lastArchiveTreeSnapshot;
302
322
  const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
303
323
  const spongeBlobState = provingState.getStartSpongeBlob().clone();
@@ -310,7 +330,7 @@ export class ProvingOrchestrator implements EpochProver {
310
330
 
311
331
  validateTx(tx);
312
332
 
313
- logger.info(`Received transaction: ${tx.hash}`);
333
+ this.logger.debug(`Received transaction: ${tx.hash}`);
314
334
 
315
335
  const startSpongeBlob = spongeBlobState.clone();
316
336
  const [hints, treeSnapshots] = await this.prepareBaseRollupInputs(
@@ -331,10 +351,10 @@ export class ProvingOrchestrator implements EpochProver {
331
351
  const txIndex = provingState.addNewTx(txProvingState);
332
352
  if (txProvingState.requireAvmProof) {
333
353
  this.getOrEnqueueChonkVerifier(provingState, txIndex);
334
- logger.debug(`Enqueueing public VM for tx ${txIndex}`);
354
+ this.logger.debug(`Enqueueing public VM for tx ${txIndex}`);
335
355
  this.enqueueVM(provingState, txIndex);
336
356
  } else {
337
- logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
357
+ this.logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
338
358
  this.enqueueBaseRollup(provingState, txIndex);
339
359
  }
340
360
  } catch (err: any) {
@@ -352,7 +372,8 @@ export class ProvingOrchestrator implements EpochProver {
352
372
 
353
373
  provingState.setEndSpongeBlob(spongeBlobState);
354
374
 
355
- // Txs have been added to the block. Now try to accumulate the blobs as far as we can:
375
+ // Txs have been added to the block. Now try to accumulate the out hashes and blobs as far as we can:
376
+ await this.provingState.accumulateCheckpointOutHashes();
356
377
  await this.provingState.setBlobAccumulators();
357
378
  }
358
379
 
@@ -376,7 +397,7 @@ export class ProvingOrchestrator implements EpochProver {
376
397
  typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
377
398
  >
378
399
  >();
379
- logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
400
+ this.logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
380
401
  this.doEnqueueChonkVerifier(txHash, privateInputs, proof => {
381
402
  tubeProof.resolve(proof);
382
403
  });
@@ -416,19 +437,19 @@ export class ProvingOrchestrator implements EpochProver {
416
437
  }
417
438
 
418
439
  // Given we've applied every change from this block, now assemble the block header:
419
- logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
440
+ this.logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
420
441
  const header = await provingState.buildBlockHeader();
421
442
 
422
443
  if (expectedHeader && !header.equals(expectedHeader)) {
423
- logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
444
+ this.logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
424
445
  throw new Error('Block header mismatch');
425
446
  }
426
447
 
427
448
  // Get db for this block
428
- const db = this.dbs.get(provingState.blockNumber)!;
449
+ const db = this.dbs.get(provingState.blockNumber)!.fork;
429
450
 
430
451
  // Update the archive tree, so we're ready to start processing the next block:
431
- logger.verbose(
452
+ this.logger.verbose(
432
453
  `Updating archive tree with block ${provingState.blockNumber} header ${(await header.hash()).toString()}`,
433
454
  );
434
455
  await db.updateArchive(header);
@@ -442,31 +463,31 @@ export class ProvingOrchestrator implements EpochProver {
442
463
  protected async verifyBuiltBlockAgainstSyncedState(provingState: BlockProvingState) {
443
464
  const builtBlockHeader = provingState.getBuiltBlockHeader();
444
465
  if (!builtBlockHeader) {
445
- logger.debug('Block header not built yet, skipping header check.');
466
+ this.logger.debug('Block header not built yet, skipping header check.');
446
467
  return;
447
468
  }
448
469
 
449
470
  const output = provingState.getBlockRootRollupOutput();
450
471
  if (!output) {
451
- logger.debug('Block root rollup proof not built yet, skipping header check.');
472
+ this.logger.debug('Block root rollup proof not built yet, skipping header check.');
452
473
  return;
453
474
  }
454
475
  const header = await buildHeaderFromCircuitOutputs(output);
455
476
 
456
477
  if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
457
- logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
478
+ this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
458
479
  provingState.reject(`Block header hash mismatch.`);
459
480
  return;
460
481
  }
461
482
 
462
483
  // Get db for this block
463
484
  const blockNumber = provingState.blockNumber;
464
- const db = this.dbs.get(blockNumber)!;
485
+ const db = this.dbs.get(blockNumber)!.fork;
465
486
 
466
487
  const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
467
488
  const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
468
489
  if (!syncedArchive.equals(newArchive)) {
469
- logger.error(
490
+ this.logger.error(
470
491
  `Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(
471
492
  syncedArchive,
472
493
  )} but built ${inspect(newArchive)}`,
@@ -477,7 +498,7 @@ export class ProvingOrchestrator implements EpochProver {
477
498
 
478
499
  const circuitArchive = output.newArchive;
479
500
  if (!newArchive.equals(circuitArchive)) {
480
- logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
501
+ this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
481
502
  provingState.reject(`New archive mismatch.`);
482
503
  return;
483
504
  }
@@ -486,20 +507,19 @@ export class ProvingOrchestrator implements EpochProver {
486
507
  // is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
487
508
  // but have to make sure it only runs once all operations are completed, otherwise some function here
488
509
  // will attempt to access the fork after it was closed.
489
- logger.debug(`Cleaning up world state fork for ${blockNumber}`);
490
- void this.dbs
491
- .get(blockNumber)
492
- ?.close()
493
- .then(() => this.dbs.delete(blockNumber))
494
- .catch(err => logger.error(`Error closing db for block ${blockNumber}`, err));
510
+ void this.cleanupDBFork(blockNumber);
495
511
  }
496
512
 
497
513
  /**
498
- * Cancel any further proving
514
+ * Cancel any further proving.
515
+ * If cancelJobsOnStop is true, aborts all pending jobs with the broker (which marks them as 'Aborted').
516
+ * If cancelJobsOnStop is false (default), jobs remain in the broker queue and can be reused on restart/reorg.
499
517
  */
500
518
  public cancel() {
501
- for (const controller of this.pendingProvingJobs) {
502
- controller.abort();
519
+ if (this.cancelJobsOnStop) {
520
+ for (const controller of this.pendingProvingJobs) {
521
+ controller.abort();
522
+ }
503
523
  }
504
524
 
505
525
  this.provingState?.cancel();
@@ -534,6 +554,24 @@ export class ProvingOrchestrator implements EpochProver {
534
554
  return epochProofResult;
535
555
  }
536
556
 
557
+ private async cleanupDBFork(blockNumber: BlockNumber): Promise<void> {
558
+ this.logger.debug(`Cleaning up world state fork for ${blockNumber}`);
559
+ const fork = this.dbs.get(blockNumber);
560
+ if (!fork) {
561
+ return;
562
+ }
563
+
564
+ try {
565
+ if (!fork.cleanupPromise) {
566
+ fork.cleanupPromise = fork.fork.close();
567
+ }
568
+ await fork.cleanupPromise;
569
+ this.dbs.delete(blockNumber);
570
+ } catch (err) {
571
+ this.logger.error(`Error closing db for block ${blockNumber}`, err);
572
+ }
573
+ }
574
+
537
575
  /**
538
576
  * Enqueue a job to be scheduled
539
577
  * @param provingState - The proving state object being operated on
@@ -546,7 +584,7 @@ export class ProvingOrchestrator implements EpochProver {
546
584
  callback: (result: T) => void | Promise<void>,
547
585
  ) {
548
586
  if (!provingState.verifyState()) {
549
- logger.debug(`Not enqueuing job, state no longer valid`);
587
+ this.logger.debug(`Not enqueuing job, state no longer valid`);
550
588
  return;
551
589
  }
552
590
 
@@ -564,7 +602,7 @@ export class ProvingOrchestrator implements EpochProver {
564
602
 
565
603
  const result = await request(controller.signal);
566
604
  if (!provingState.verifyState()) {
567
- logger.debug(`State no longer valid, discarding result`);
605
+ this.logger.debug(`State no longer valid, discarding result`);
568
606
  return;
569
607
  }
570
608
 
@@ -582,7 +620,7 @@ export class ProvingOrchestrator implements EpochProver {
582
620
  return;
583
621
  }
584
622
 
585
- logger.error(`Error thrown when proving job`, err);
623
+ this.logger.error(`Error thrown when proving job`, err);
586
624
  provingState!.reject(`${err}`);
587
625
  } finally {
588
626
  const index = this.pendingProvingJobs.indexOf(controller);
@@ -667,12 +705,12 @@ export class ProvingOrchestrator implements EpochProver {
667
705
  // Executes the next level of merge if all inputs are available
668
706
  private enqueueBaseRollup(provingState: BlockProvingState, txIndex: number) {
669
707
  if (!provingState.verifyState()) {
670
- logger.debug('Not running base rollup, state invalid');
708
+ this.logger.debug('Not running base rollup, state invalid');
671
709
  return;
672
710
  }
673
711
 
674
712
  if (!provingState.tryStartProvingBase(txIndex)) {
675
- logger.debug(`Base rollup for tx ${txIndex} already started.`);
713
+ this.logger.debug(`Base rollup for tx ${txIndex} already started.`);
676
714
  return;
677
715
  }
678
716
 
@@ -680,7 +718,7 @@ export class ProvingOrchestrator implements EpochProver {
680
718
  const { processedTx } = txProvingState;
681
719
  const { rollupType, inputs } = txProvingState.getBaseRollupTypeAndInputs();
682
720
 
683
- logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
721
+ this.logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
684
722
 
685
723
  this.deferredProving(
686
724
  provingState,
@@ -704,7 +742,7 @@ export class ProvingOrchestrator implements EpochProver {
704
742
  },
705
743
  ),
706
744
  result => {
707
- logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
745
+ this.logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
708
746
  validatePartialState(result.inputs.endTreeSnapshots, txProvingState.treeSnapshots);
709
747
  const leafLocation = provingState.setBaseRollupProof(txIndex, result);
710
748
  if (provingState.totalNumTxs === 1) {
@@ -720,7 +758,7 @@ export class ProvingOrchestrator implements EpochProver {
720
758
  // Once completed, will enqueue the the public tx base rollup.
721
759
  private getOrEnqueueChonkVerifier(provingState: BlockProvingState, txIndex: number) {
722
760
  if (!provingState.verifyState()) {
723
- logger.debug('Not running chonk verifier circuit, state invalid');
761
+ this.logger.debug('Not running chonk verifier circuit, state invalid');
724
762
  return;
725
763
  }
726
764
 
@@ -733,19 +771,19 @@ export class ProvingOrchestrator implements EpochProver {
733
771
  typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
734
772
  >,
735
773
  ) => {
736
- logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, { txHash });
774
+ this.logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, { txHash });
737
775
  txProvingState.setPublicChonkVerifierProof(result);
738
776
  this.provingState?.cachedChonkVerifierProofs.delete(txHash);
739
777
  this.checkAndEnqueueBaseRollup(provingState, txIndex);
740
778
  };
741
779
 
742
780
  if (this.provingState?.cachedChonkVerifierProofs.has(txHash)) {
743
- logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, { txHash });
781
+ this.logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, { txHash });
744
782
  void this.provingState!.cachedChonkVerifierProofs.get(txHash)!.then(handleResult);
745
783
  return;
746
784
  }
747
785
 
748
- logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
786
+ this.logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
749
787
  this.doEnqueueChonkVerifier(txHash, txProvingState.getPublicChonkVerifierPrivateInputs(), handleResult);
750
788
  }
751
789
 
@@ -761,7 +799,7 @@ export class ProvingOrchestrator implements EpochProver {
761
799
  provingState: EpochProvingState | BlockProvingState = this.provingState!,
762
800
  ) {
763
801
  if (!provingState.verifyState()) {
764
- logger.debug('Not running chonk verifier circuit, state invalid');
802
+ this.logger.debug('Not running chonk verifier circuit, state invalid');
765
803
  return;
766
804
  }
767
805
 
@@ -784,12 +822,12 @@ export class ProvingOrchestrator implements EpochProver {
784
822
  // Enqueues the next level of merge if all inputs are available
785
823
  private enqueueMergeRollup(provingState: BlockProvingState, location: TreeNodeLocation) {
786
824
  if (!provingState.verifyState()) {
787
- logger.debug('Not running merge rollup. State no longer valid.');
825
+ this.logger.debug('Not running merge rollup. State no longer valid.');
788
826
  return;
789
827
  }
790
828
 
791
829
  if (!provingState.tryStartProvingMerge(location)) {
792
- logger.debug('Merge rollup already started.');
830
+ this.logger.debug('Merge rollup already started.');
793
831
  return;
794
832
  }
795
833
 
@@ -815,18 +853,18 @@ export class ProvingOrchestrator implements EpochProver {
815
853
  // Executes the block root rollup circuit
816
854
  private enqueueBlockRootRollup(provingState: BlockProvingState) {
817
855
  if (!provingState.verifyState()) {
818
- logger.debug('Not running block root rollup, state no longer valid');
856
+ this.logger.debug('Not running block root rollup, state no longer valid');
819
857
  return;
820
858
  }
821
859
 
822
860
  if (!provingState.tryStartProvingBlockRoot()) {
823
- logger.debug('Block root rollup already started.');
861
+ this.logger.debug('Block root rollup already started.');
824
862
  return;
825
863
  }
826
864
 
827
865
  const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs();
828
866
 
829
- logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
867
+ this.logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
830
868
 
831
869
  this.deferredProving(
832
870
  provingState,
@@ -851,19 +889,22 @@ export class ProvingOrchestrator implements EpochProver {
851
889
  },
852
890
  ),
853
891
  async result => {
854
- // If the proofs were slower than the block header building, then we need to try validating the block header hashes here.
855
- await this.verifyBuiltBlockAgainstSyncedState(provingState);
856
-
857
- logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
892
+ this.logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
858
893
 
859
894
  const leafLocation = provingState.setBlockRootRollupProof(result);
860
895
  const checkpointProvingState = provingState.parentCheckpoint;
861
896
 
897
+ // If the proofs were slower than the block header building, then we need to try validating the block header hashes here.
898
+ await this.verifyBuiltBlockAgainstSyncedState(provingState);
899
+
862
900
  if (checkpointProvingState.totalNumBlocks === 1) {
863
901
  this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
864
902
  } else {
865
903
  this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
866
904
  }
905
+
906
+ // We are finished with the block at this point, ensure the fork is cleaned up
907
+ void this.cleanupDBFork(provingState.blockNumber);
867
908
  },
868
909
  );
869
910
  }
@@ -876,12 +917,12 @@ export class ProvingOrchestrator implements EpochProver {
876
917
  baseParityIndex: number,
877
918
  ) {
878
919
  if (!provingState.verifyState()) {
879
- logger.debug('Not running base parity. State no longer valid.');
920
+ this.logger.debug('Not running base parity. State no longer valid.');
880
921
  return;
881
922
  }
882
923
 
883
924
  if (!provingState.tryStartProvingBaseParity(baseParityIndex)) {
884
- logger.warn(`Base parity ${baseParityIndex} already started.`);
925
+ this.logger.warn(`Base parity ${baseParityIndex} already started.`);
885
926
  return;
886
927
  }
887
928
 
@@ -916,12 +957,12 @@ export class ProvingOrchestrator implements EpochProver {
916
957
  // Enqueues the root rollup proof if all inputs are available
917
958
  private enqueueRootParityCircuit(provingState: BlockProvingState) {
918
959
  if (!provingState.verifyState()) {
919
- logger.debug('Not running root parity. State no longer valid.');
960
+ this.logger.debug('Not running root parity. State no longer valid.');
920
961
  return;
921
962
  }
922
963
 
923
964
  if (!provingState.tryStartProvingRootParity()) {
924
- logger.debug('Root parity already started.');
965
+ this.logger.debug('Root parity already started.');
925
966
  return;
926
967
  }
927
968
 
@@ -948,12 +989,12 @@ export class ProvingOrchestrator implements EpochProver {
948
989
  // Enqueues the next level of merge if all inputs are available
949
990
  private enqueueBlockMergeRollup(provingState: CheckpointProvingState, location: TreeNodeLocation) {
950
991
  if (!provingState.verifyState()) {
951
- logger.debug('Not running block merge rollup. State no longer valid.');
992
+ this.logger.debug('Not running block merge rollup. State no longer valid.');
952
993
  return;
953
994
  }
954
995
 
955
996
  if (!provingState.tryStartProvingBlockMerge(location)) {
956
- logger.debug('Block merge rollup already started.');
997
+ this.logger.debug('Block merge rollup already started.');
957
998
  return;
958
999
  }
959
1000
 
@@ -977,18 +1018,18 @@ export class ProvingOrchestrator implements EpochProver {
977
1018
 
978
1019
  private enqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
979
1020
  if (!provingState.verifyState()) {
980
- logger.debug('Not running checkpoint root rollup. State no longer valid.');
1021
+ this.logger.debug('Not running checkpoint root rollup. State no longer valid.');
981
1022
  return;
982
1023
  }
983
1024
 
984
1025
  if (!provingState.tryStartProvingCheckpointRoot()) {
985
- logger.debug('Checkpoint root rollup already started.');
1026
+ this.logger.debug('Checkpoint root rollup already started.');
986
1027
  return;
987
1028
  }
988
1029
 
989
1030
  const rollupType = provingState.getCheckpointRootRollupType();
990
1031
 
991
- logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
1032
+ this.logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
992
1033
 
993
1034
  const inputs = provingState.getCheckpointRootRollupInputs();
994
1035
 
@@ -1012,7 +1053,7 @@ export class ProvingOrchestrator implements EpochProver {
1012
1053
  const computedEndBlobAccumulatorState = provingState.getEndBlobAccumulator()!.toBlobAccumulator();
1013
1054
  const circuitEndBlobAccumulatorState = result.inputs.endBlobAccumulator;
1014
1055
  if (!circuitEndBlobAccumulatorState.equals(computedEndBlobAccumulatorState)) {
1015
- logger.error(
1056
+ this.logger.error(
1016
1057
  `Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(
1017
1058
  computedEndBlobAccumulatorState,
1018
1059
  )}`,
@@ -1021,7 +1062,7 @@ export class ProvingOrchestrator implements EpochProver {
1021
1062
  return;
1022
1063
  }
1023
1064
 
1024
- logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
1065
+ this.logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
1025
1066
 
1026
1067
  const leafLocation = provingState.setCheckpointRootRollupProof(result);
1027
1068
  const epochProvingState = provingState.parentEpoch;
@@ -1037,12 +1078,12 @@ export class ProvingOrchestrator implements EpochProver {
1037
1078
 
1038
1079
  private enqueueCheckpointMergeRollup(provingState: EpochProvingState, location: TreeNodeLocation) {
1039
1080
  if (!provingState.verifyState()) {
1040
- logger.debug('Not running checkpoint merge rollup. State no longer valid.');
1081
+ this.logger.debug('Not running checkpoint merge rollup. State no longer valid.');
1041
1082
  return;
1042
1083
  }
1043
1084
 
1044
1085
  if (!provingState.tryStartProvingCheckpointMerge(location)) {
1045
- logger.debug('Checkpoint merge rollup already started.');
1086
+ this.logger.debug('Checkpoint merge rollup already started.');
1046
1087
  return;
1047
1088
  }
1048
1089
 
@@ -1059,7 +1100,7 @@ export class ProvingOrchestrator implements EpochProver {
1059
1100
  signal => this.prover.getCheckpointMergeRollupProof(inputs, signal, provingState.epochNumber),
1060
1101
  ),
1061
1102
  result => {
1062
- logger.debug('Completed proof for checkpoint merge rollup.');
1103
+ this.logger.debug('Completed proof for checkpoint merge rollup.');
1063
1104
  provingState.setCheckpointMergeRollupProof(location, result);
1064
1105
  this.checkAndEnqueueNextCheckpointMergeRollup(provingState, location);
1065
1106
  },
@@ -1068,16 +1109,16 @@ export class ProvingOrchestrator implements EpochProver {
1068
1109
 
1069
1110
  private enqueueEpochPadding(provingState: EpochProvingState) {
1070
1111
  if (!provingState.verifyState()) {
1071
- logger.debug('Not running epoch padding. State no longer valid.');
1112
+ this.logger.debug('Not running epoch padding. State no longer valid.');
1072
1113
  return;
1073
1114
  }
1074
1115
 
1075
1116
  if (!provingState.tryStartProvingPaddingCheckpoint()) {
1076
- logger.debug('Padding checkpoint already started.');
1117
+ this.logger.debug('Padding checkpoint already started.');
1077
1118
  return;
1078
1119
  }
1079
1120
 
1080
- logger.debug('Padding epoch proof with a padding block root proof.');
1121
+ this.logger.debug('Padding epoch proof with a padding block root proof.');
1081
1122
 
1082
1123
  const inputs = provingState.getPaddingCheckpointInputs();
1083
1124
 
@@ -1092,7 +1133,7 @@ export class ProvingOrchestrator implements EpochProver {
1092
1133
  signal => this.prover.getCheckpointPaddingRollupProof(inputs, signal, provingState.epochNumber),
1093
1134
  ),
1094
1135
  result => {
1095
- logger.debug('Completed proof for padding checkpoint.');
1136
+ this.logger.debug('Completed proof for padding checkpoint.');
1096
1137
  provingState.setCheckpointPaddingProof(result);
1097
1138
  this.checkAndEnqueueRootRollup(provingState);
1098
1139
  },
@@ -1102,11 +1143,11 @@ export class ProvingOrchestrator implements EpochProver {
1102
1143
  // Executes the root rollup circuit
1103
1144
  private enqueueRootRollup(provingState: EpochProvingState) {
1104
1145
  if (!provingState.verifyState()) {
1105
- logger.debug('Not running root rollup, state no longer valid');
1146
+ this.logger.debug('Not running root rollup, state no longer valid');
1106
1147
  return;
1107
1148
  }
1108
1149
 
1109
- logger.debug(`Preparing root rollup`);
1150
+ this.logger.debug(`Preparing root rollup`);
1110
1151
 
1111
1152
  const inputs = provingState.getRootRollupInputs();
1112
1153
 
@@ -1121,7 +1162,7 @@ export class ProvingOrchestrator implements EpochProver {
1121
1162
  signal => this.prover.getRootRollupProof(inputs, signal, provingState.epochNumber),
1122
1163
  ),
1123
1164
  result => {
1124
- logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
1165
+ this.logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
1125
1166
  provingState.setRootRollupProof(result);
1126
1167
  provingState.resolve({ status: 'success' });
1127
1168
  },
@@ -1143,7 +1184,7 @@ export class ProvingOrchestrator implements EpochProver {
1143
1184
 
1144
1185
  private checkAndEnqueueBlockRootRollup(provingState: BlockProvingState) {
1145
1186
  if (!provingState.isReadyForBlockRootRollup()) {
1146
- logger.debug('Not ready for block root rollup');
1187
+ this.logger.debug('Not ready for block root rollup');
1147
1188
  return;
1148
1189
  }
1149
1190
 
@@ -1186,7 +1227,7 @@ export class ProvingOrchestrator implements EpochProver {
1186
1227
 
1187
1228
  private checkAndEnqueueRootRollup(provingState: EpochProvingState) {
1188
1229
  if (!provingState.isReadyForRootRollup()) {
1189
- logger.debug('Not ready for root rollup');
1230
+ this.logger.debug('Not ready for root rollup');
1190
1231
  return;
1191
1232
  }
1192
1233
 
@@ -1201,14 +1242,12 @@ export class ProvingOrchestrator implements EpochProver {
1201
1242
  */
1202
1243
  private enqueueVM(provingState: BlockProvingState, txIndex: number) {
1203
1244
  if (!provingState.verifyState()) {
1204
- logger.debug(`Not running VM circuit as state is no longer valid`);
1245
+ this.logger.debug(`Not running VM circuit as state is no longer valid`);
1205
1246
  return;
1206
1247
  }
1207
1248
 
1208
1249
  const txProvingState = provingState.getTxProvingState(txIndex);
1209
1250
 
1210
- // This function tries to do AVM proving. If there is a failure, it fakes the proof unless AVM_PROVING_STRICT is defined.
1211
- // Nothing downstream depends on the AVM proof yet. So having this mode lets us incrementally build the AVM circuit.
1212
1251
  const doAvmProving = wrapCallbackInSpan(
1213
1252
  this.tracer,
1214
1253
  'ProvingOrchestrator.prover.getAvmProof',
@@ -1217,36 +1256,13 @@ export class ProvingOrchestrator implements EpochProver {
1217
1256
  },
1218
1257
  async (signal: AbortSignal) => {
1219
1258
  const inputs = txProvingState.getAvmInputs();
1220
- try {
1221
- // TODO(#14234)[Unconditional PIs validation]: Remove the whole try-catch logic and
1222
- // just keep the next line but removing the second argument (false).
1223
- return await this.prover.getAvmProof(inputs, false, signal, provingState.epochNumber);
1224
- } catch (err) {
1225
- if (process.env.AVM_PROVING_STRICT) {
1226
- logger.error(`Error thrown when proving AVM circuit with AVM_PROVING_STRICT on`, err);
1227
- throw err;
1228
- } else {
1229
- logger.warn(
1230
- `Error thrown when proving AVM circuit but AVM_PROVING_STRICT is off. Use snapshotted
1231
- AVM inputs and carrying on. ${inspect(err)}.`,
1232
- );
1233
-
1234
- try {
1235
- this.metrics.incAvmFallback();
1236
- const snapshotAvmPrivateInputs = readAvmMinimalPublicTxInputsFromFile();
1237
- return await this.prover.getAvmProof(snapshotAvmPrivateInputs, true, signal, provingState.epochNumber);
1238
- } catch (err) {
1239
- logger.error(`Error thrown when proving snapshotted AVM inputs.`, err);
1240
- throw err;
1241
- }
1242
- }
1243
- }
1259
+ return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
1244
1260
  },
1245
1261
  );
1246
1262
 
1247
- this.deferredProving(provingState, doAvmProving, proofAndVk => {
1248
- logger.debug(`Proven VM for tx index: ${txIndex}`);
1249
- txProvingState.setAvmProof(proofAndVk);
1263
+ this.deferredProving(provingState, doAvmProving, proof => {
1264
+ this.logger.debug(`Proven VM for tx index: ${txIndex}`);
1265
+ txProvingState.setAvmProof(proof);
1250
1266
  this.checkAndEnqueueBaseRollup(provingState, txIndex);
1251
1267
  });
1252
1268
  }
@@ -1258,7 +1274,7 @@ export class ProvingOrchestrator implements EpochProver {
1258
1274
  }
1259
1275
 
1260
1276
  // We must have completed all proving (chonk verifier proof and (if required) vm proof are generated), we now move to the base rollup.
1261
- logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
1277
+ this.logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
1262
1278
 
1263
1279
  this.enqueueBaseRollup(provingState, txIndex);
1264
1280
  }