@aztec/prover-node 5.0.0-private.20260319 → 5.0.0-rc.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.
Files changed (71) hide show
  1. package/README.md +506 -0
  2. package/dest/actions/download-epoch-proving-job.js +1 -1
  3. package/dest/actions/rerun-epoch-proving-job.d.ts +4 -3
  4. package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -1
  5. package/dest/actions/rerun-epoch-proving-job.js +103 -21
  6. package/dest/bin/run-failed-epoch.js +1 -3
  7. package/dest/checkpoint-store.d.ts +83 -0
  8. package/dest/checkpoint-store.d.ts.map +1 -0
  9. package/dest/checkpoint-store.js +181 -0
  10. package/dest/config.d.ts +1 -1
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +1 -1
  13. package/dest/factory.d.ts +1 -1
  14. package/dest/factory.d.ts.map +1 -1
  15. package/dest/factory.js +22 -8
  16. package/dest/index.d.ts +2 -1
  17. package/dest/index.d.ts.map +1 -1
  18. package/dest/index.js +1 -0
  19. package/dest/job/checkpoint-prover.d.ts +134 -0
  20. package/dest/job/checkpoint-prover.d.ts.map +1 -0
  21. package/dest/job/checkpoint-prover.js +350 -0
  22. package/dest/job/epoch-session.d.ts +146 -0
  23. package/dest/job/epoch-session.d.ts.map +1 -0
  24. package/dest/job/epoch-session.js +709 -0
  25. package/dest/job/top-tree-job.d.ts +82 -0
  26. package/dest/job/top-tree-job.d.ts.map +1 -0
  27. package/dest/job/top-tree-job.js +152 -0
  28. package/dest/metrics.d.ts +29 -5
  29. package/dest/metrics.d.ts.map +1 -1
  30. package/dest/metrics.js +73 -9
  31. package/dest/monitors/epoch-monitor.js +6 -2
  32. package/dest/proof-publishing-service.d.ts +159 -0
  33. package/dest/proof-publishing-service.d.ts.map +1 -0
  34. package/dest/proof-publishing-service.js +334 -0
  35. package/dest/prover-node-publisher.d.ts +18 -11
  36. package/dest/prover-node-publisher.d.ts.map +1 -1
  37. package/dest/prover-node-publisher.js +195 -57
  38. package/dest/prover-node.d.ts +96 -68
  39. package/dest/prover-node.d.ts.map +1 -1
  40. package/dest/prover-node.js +382 -227
  41. package/dest/prover-publisher-factory.d.ts +2 -2
  42. package/dest/prover-publisher-factory.d.ts.map +1 -1
  43. package/dest/prover-publisher-factory.js +3 -3
  44. package/dest/session-manager.d.ts +158 -0
  45. package/dest/session-manager.d.ts.map +1 -0
  46. package/dest/session-manager.js +452 -0
  47. package/dest/test/index.d.ts +7 -6
  48. package/dest/test/index.d.ts.map +1 -1
  49. package/package.json +23 -23
  50. package/src/actions/download-epoch-proving-job.ts +1 -1
  51. package/src/actions/rerun-epoch-proving-job.ts +114 -28
  52. package/src/bin/run-failed-epoch.ts +1 -2
  53. package/src/checkpoint-store.ts +213 -0
  54. package/src/config.ts +2 -1
  55. package/src/factory.ts +18 -10
  56. package/src/index.ts +1 -0
  57. package/src/job/checkpoint-prover.ts +465 -0
  58. package/src/job/epoch-session.ts +424 -0
  59. package/src/job/top-tree-job.ts +227 -0
  60. package/src/metrics.ts +88 -12
  61. package/src/monitors/epoch-monitor.ts +2 -2
  62. package/src/proof-publishing-service.ts +424 -0
  63. package/src/prover-node-publisher.ts +220 -67
  64. package/src/prover-node.ts +439 -249
  65. package/src/prover-publisher-factory.ts +3 -3
  66. package/src/session-manager.ts +552 -0
  67. package/src/test/index.ts +6 -6
  68. package/dest/job/epoch-proving-job.d.ts +0 -63
  69. package/dest/job/epoch-proving-job.d.ts.map +0 -1
  70. package/dest/job/epoch-proving-job.js +0 -762
  71. package/src/job/epoch-proving-job.ts +0 -465
@@ -0,0 +1,465 @@
1
+ import { type ARCHIVE_HEIGHT, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
+ import { BlockNumber, type EpochNumber, type SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { padArrayEnd } from '@aztec/foundation/collection';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
5
+ import type { EthAddress } from '@aztec/foundation/eth-address';
6
+ import type { Logger } from '@aztec/foundation/log';
7
+ import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec/foundation/promise';
8
+ import type { Tuple } from '@aztec/foundation/serialize';
9
+ import { type DateProvider, Timer } from '@aztec/foundation/timer';
10
+ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
11
+ import { protocolContractsHash } from '@aztec/protocol-contracts';
12
+ import type { EpochProverFactory } from '@aztec/prover-client';
13
+ import type { CheckpointSubTreeOrchestrator, ChonkCache, SubTreeResult } from '@aztec/prover-client/orchestrator';
14
+ import type { PublicProcessor, PublicProcessorFactory } from '@aztec/simulator/server';
15
+ import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
16
+ import type { CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
17
+ import type { Checkpoint } from '@aztec/stdlib/checkpoint';
18
+ import type { ForkMerkleTreeOperations, ITxProvider } from '@aztec/stdlib/interfaces/server';
19
+ import { CheckpointConstantData } from '@aztec/stdlib/rollup';
20
+ import { MerkleTreeId } from '@aztec/stdlib/trees';
21
+ import type { BlockHeader, ProcessedTx, Tx } from '@aztec/stdlib/tx';
22
+
23
+ import type { ProverNodeJobMetrics } from '../metrics.js';
24
+
25
+ /** Dependencies a `CheckpointProver` needs at construction. */
26
+ export type CheckpointProverDeps = {
27
+ proverFactory: EpochProverFactory;
28
+ /** Shared chonk-verifier cache. Survives across all sessions / epochs. */
29
+ chonkCache: ChonkCache;
30
+ publicProcessorFactory: PublicProcessorFactory;
31
+ dbProvider: Pick<ForkMerkleTreeOperations, 'fork'>;
32
+ txProvider: ITxProvider;
33
+ /** Clock the prover-node operates against — e2e fixtures inject a cheat-controlled one. */
34
+ dateProvider: DateProvider;
35
+ proverId: EthAddress;
36
+ metrics: ProverNodeJobMetrics;
37
+ /** Tx gathering deadline. */
38
+ txGatheringTimeoutMs: number;
39
+ /** Public processor deadline. */
40
+ deadline: Date | undefined;
41
+ log: Logger;
42
+ };
43
+
44
+ /** Inputs that fully describe a checkpoint at register time. */
45
+ export type CheckpointProverArgs = {
46
+ checkpoint: Checkpoint;
47
+ /** Epoch the checkpoint belongs to (derivable from slot + L1 constants; cached at register time). */
48
+ epochNumber: EpochNumber;
49
+ attestations: CommitteeAttestation[];
50
+ previousBlockHeader: BlockHeader;
51
+ l1ToL2Messages: Fr[];
52
+ previousArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>;
53
+ };
54
+
55
+ /**
56
+ * Self-contained per-checkpoint prover, content-addressed by
57
+ * `(checkpoint number, slot number, checkpoint archive root)`.
58
+ *
59
+ * The store creates a CheckpointProver once per content-key. Keying on the checkpoint's
60
+ * own archive root (its post-state) means two checkpoints are "the same" iff they
61
+ * produce the same archive — so a reorg branch, or a replacement built on the same
62
+ * predecessor but with different content, keys to a distinct prover; an identical
63
+ * re-add keys to the same one and reuses its in-flight sub-tree work.
64
+ *
65
+ * The prover eagerly starts its own tx gather and sub-tree work in the constructor, so
66
+ * callers only need to call `whenBlockProofsReady()` to obtain the resulting block-rollup
67
+ * proofs.
68
+ *
69
+ * The prover survives prune/re-add cycles via `markPruned()` / `markCanonical()` —
70
+ * sub-tree proving keeps running underneath, so a checkpoint that is re-added after
71
+ * a brief reorg can be re-consumed with no re-proving.
72
+ *
73
+ * `cancel()` is idempotent. It aborts the gather + sub-tree, rejects the block-proof
74
+ * promise, and exposes a `whenDone()` that resolves once teardown has unwound.
75
+ */
76
+ export class CheckpointProver {
77
+ readonly id: string;
78
+ readonly checkpoint: Checkpoint;
79
+ readonly epochNumber: EpochNumber;
80
+ readonly slotNumber: SlotNumber;
81
+ readonly attestations: CommitteeAttestation[];
82
+ readonly previousBlockHeader: BlockHeader;
83
+ readonly l1ToL2Messages: Fr[];
84
+ readonly previousArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>;
85
+
86
+ /** Per-prover tx map — populated by the internal gather. Empty until then. */
87
+ readonly txs: Map<string, Tx> = new Map();
88
+
89
+ /** Resolved by the sub-tree on success, rejected on cancel/failure. */
90
+ private readonly blockProofs: PromiseWithResolvers<SubTreeResult['blockProofOutputs']> = promiseWithResolvers();
91
+
92
+ private cancelled = false;
93
+ private subTree?: CheckpointSubTreeOrchestrator;
94
+ private completed = false;
95
+ /** Pruned in the canonical chain but not yet reaped — sub-tree continues running. */
96
+ private pruned = false;
97
+ private readonly abortController = new AbortController();
98
+
99
+ /** Tracks the eager gather+execute task so `cancel()` and `whenDone()` can await its unwind. */
100
+ private readonly runPromise: Promise<void>;
101
+ /** Tracks the cancel-driven teardown so `whenDone()` can await it. */
102
+ private cancelPromise?: Promise<void>;
103
+
104
+ constructor(
105
+ args: CheckpointProverArgs,
106
+ private readonly deps: CheckpointProverDeps,
107
+ ) {
108
+ this.checkpoint = args.checkpoint;
109
+ this.epochNumber = args.epochNumber;
110
+ this.slotNumber = args.checkpoint.header.slotNumber;
111
+ this.attestations = args.attestations;
112
+ this.previousBlockHeader = args.previousBlockHeader;
113
+ this.l1ToL2Messages = args.l1ToL2Messages;
114
+ this.previousArchiveSiblingPath = args.previousArchiveSiblingPath;
115
+ this.id = CheckpointProver.idFor(args.checkpoint);
116
+ // Mark blockProofs as observed so a cancel that lands before any consumer awaits
117
+ // does not surface as an unhandled rejection.
118
+ this.blockProofs.promise.catch(() => {});
119
+ deps.log.info(`Created CheckpointProver ${this.id}`, {
120
+ checkpointNumber: this.checkpoint.number,
121
+ epochNumber: this.epochNumber,
122
+ slotNumber: this.slotNumber,
123
+ blockCount: this.checkpoint.blocks.length,
124
+ l1ToL2MessageCount: this.l1ToL2Messages.length,
125
+ archiveRoot: this.checkpoint.archive.root.toString(),
126
+ });
127
+ // Kick off the eager gather + sub-tree pipeline.
128
+ this.runPromise = this.gatherAndExecute();
129
+ }
130
+
131
+ /**
132
+ * Stable content-addressed identifier: `${checkpoint number}:${slot}:${archive root}`.
133
+ * The archive root is the checkpoint's post-state, so it distinguishes any two
134
+ * checkpoints that differ in history or content while collapsing identical re-adds.
135
+ */
136
+ public static idFor(checkpoint: Checkpoint): string {
137
+ return `${checkpoint.number}:${checkpoint.header.slotNumber}:${checkpoint.archive.root.toString()}`;
138
+ }
139
+
140
+ public isCancelled(): boolean {
141
+ return this.cancelled;
142
+ }
143
+
144
+ /** True once block-level proving has been fully *enqueued* (sub-tree completion may still be pending). */
145
+ public isCompleted(): boolean {
146
+ return this.completed;
147
+ }
148
+
149
+ public isPruned(): boolean {
150
+ return this.pruned;
151
+ }
152
+
153
+ /**
154
+ * Mark this prover as no longer present in the canonical chain. Sub-tree proving keeps
155
+ * running so the work survives if the checkpoint is re-added. Idempotent.
156
+ */
157
+ public markPruned(): void {
158
+ if (this.pruned) {
159
+ return;
160
+ }
161
+ this.pruned = true;
162
+ this.deps.log.info(`Marking CheckpointProver ${this.id} as pruned`, {
163
+ checkpointNumber: this.checkpoint.number,
164
+ slotNumber: this.slotNumber,
165
+ });
166
+ }
167
+
168
+ /** Mark this prover as part of the canonical chain again after a re-add. Idempotent. */
169
+ public markCanonical(): void {
170
+ if (!this.pruned) {
171
+ return;
172
+ }
173
+ this.pruned = false;
174
+ this.deps.log.info(`Marking CheckpointProver ${this.id} as canonical`, {
175
+ checkpointNumber: this.checkpoint.number,
176
+ slotNumber: this.slotNumber,
177
+ });
178
+ }
179
+
180
+ /** AbortSignal that fires on cancel — for callers that want to wire their own tasks. */
181
+ public getAbortSignal(): AbortSignal {
182
+ return this.abortController.signal;
183
+ }
184
+
185
+ /** Promise that resolves with the block-rollup proofs for this checkpoint (or rejects on cancel/failure). */
186
+ public whenBlockProofsReady(): Promise<SubTreeResult['blockProofOutputs']> {
187
+ return this.blockProofs.promise;
188
+ }
189
+
190
+ /** Resolves when all in-flight work for this prover has fully unwound. */
191
+ public async whenDone(): Promise<void> {
192
+ await this.runPromise.catch(() => {});
193
+ if (this.cancelPromise) {
194
+ await this.cancelPromise;
195
+ }
196
+ }
197
+
198
+ private async gatherAndExecute(): Promise<void> {
199
+ try {
200
+ const txs = await this.gatherTxs();
201
+ if (this.cancelled) {
202
+ return;
203
+ }
204
+ await this.executeCheckpoint(txs);
205
+ } catch (err) {
206
+ if (this.cancelled) {
207
+ this.deps.log.debug(`CheckpointProver ${this.id} cancelled during gather/execute`, {
208
+ checkpointNumber: this.checkpoint.number,
209
+ });
210
+ return;
211
+ }
212
+ this.deps.log.error(`Error in CheckpointProver ${this.id}`, err, {
213
+ checkpointNumber: this.checkpoint.number,
214
+ });
215
+ this.blockProofs.reject(err instanceof Error ? err : new Error(String(err)));
216
+ }
217
+ }
218
+
219
+ private async gatherTxs(): Promise<Map<string, Tx>> {
220
+ const deadline = new Date(this.deps.dateProvider.now() + this.deps.txGatheringTimeoutMs);
221
+ const txsByBlock = await Promise.all(
222
+ this.checkpoint.blocks.map(block => this.deps.txProvider.getTxsForBlock(block, { deadline })),
223
+ );
224
+ const txs = txsByBlock.map(({ txs }) => txs).flat();
225
+ const missingTxs = txsByBlock.map(({ missingTxs }) => missingTxs).flat();
226
+
227
+ if (missingTxs.length > 0) {
228
+ throw new Error(
229
+ `Txs not found for checkpoint ${this.checkpoint.number}: ${missingTxs.map(hash => hash.toString()).join(', ')}`,
230
+ );
231
+ }
232
+ return new Map<string, Tx>(txs.map(tx => [tx.getTxHash().toString(), tx]));
233
+ }
234
+
235
+ private async executeCheckpoint(txs: Map<string, Tx>): Promise<void> {
236
+ const signal = this.abortController.signal;
237
+ const checkpointTimer = new Timer();
238
+ let subTreeStarted = false;
239
+
240
+ try {
241
+ for (const [hash, tx] of txs) {
242
+ this.txs.set(hash, tx);
243
+ }
244
+
245
+ const { chainId, version } = this.checkpoint.blocks[0].header.globalVariables;
246
+ const checkpointConstants = CheckpointConstantData.from({
247
+ chainId,
248
+ version,
249
+ vkTreeRoot: getVKTreeRoot(),
250
+ protocolContractsHash: protocolContractsHash,
251
+ proverId: this.deps.proverId.toField(),
252
+ slotNumber: this.checkpoint.header.slotNumber,
253
+ coinbase: this.checkpoint.header.coinbase,
254
+ feeRecipient: this.checkpoint.header.feeRecipient,
255
+ gasFees: this.checkpoint.header.gasFees,
256
+ });
257
+
258
+ this.deps.log.info(`Starting processing checkpoint ${this.checkpoint.number}`, {
259
+ checkpointNumber: this.checkpoint.number,
260
+ checkpointHash: this.checkpoint.hash().toString(),
261
+ blockCount: this.checkpoint.blocks.length,
262
+ });
263
+
264
+ this.subTree = await this.deps.proverFactory.createCheckpointSubTreeOrchestrator(
265
+ this.deps.chonkCache,
266
+ this.epochNumber,
267
+ checkpointConstants,
268
+ this.l1ToL2Messages,
269
+ this.checkpoint.blocks.length,
270
+ this.previousBlockHeader,
271
+ );
272
+ subTreeStarted = true;
273
+ // Bridge the sub-tree's result onto blockProofs.
274
+ void this.subTree.getSubTreeResult().then(
275
+ result => {
276
+ this.deps.log.info(`Sub-tree block proofs ready for checkpoint ${this.checkpoint.number}`, {
277
+ checkpointNumber: this.checkpoint.number,
278
+ blockProofCount: result.blockProofOutputs.length,
279
+ });
280
+ this.blockProofs.resolve(result.blockProofOutputs);
281
+ },
282
+ err => this.blockProofs.reject(err),
283
+ );
284
+ if (signal.aborted) {
285
+ return;
286
+ }
287
+
288
+ const allTxs = this.checkpoint.blocks.flatMap(block =>
289
+ block.body.txEffects.map(txEffect => txs.get(txEffect.txHash.toString())!),
290
+ );
291
+ const publicTxs = allTxs.filter(tx => tx?.data.forPublic);
292
+ if (publicTxs.length > 0) {
293
+ await this.subTree.startChonkVerifierCircuits(publicTxs);
294
+ if (signal.aborted) {
295
+ return;
296
+ }
297
+ }
298
+
299
+ for (let blockIndex = 0; blockIndex < this.checkpoint.blocks.length; blockIndex++) {
300
+ const blockTimer = new Timer();
301
+ const block = this.checkpoint.blocks[blockIndex];
302
+ const globalVariables = block.header.globalVariables;
303
+ const blockTxs = this.getTxsForBlock(block, txs);
304
+
305
+ await this.subTree.startNewBlock(block.number, globalVariables.timestamp, blockTxs.length);
306
+ if (signal.aborted) {
307
+ return;
308
+ }
309
+
310
+ const db = await this.createFork(
311
+ BlockNumber(block.number - 1),
312
+ blockIndex === 0 ? this.l1ToL2Messages : undefined,
313
+ );
314
+ try {
315
+ if (signal.aborted) {
316
+ return;
317
+ }
318
+ const config = PublicSimulatorConfig.from({
319
+ proverId: this.deps.proverId.toField(),
320
+ skipFeeEnforcement: false,
321
+ collectDebugLogs: false,
322
+ collectHints: true,
323
+ collectPublicInputs: true,
324
+ collectStatistics: false,
325
+ });
326
+ const publicProcessor = this.deps.publicProcessorFactory.create(db, globalVariables, config);
327
+ const processed = await this.processTxs(publicProcessor, blockTxs);
328
+ if (signal.aborted) {
329
+ return;
330
+ }
331
+ await this.subTree.addTxs(processed);
332
+ } finally {
333
+ await db.close();
334
+ }
335
+ if (signal.aborted) {
336
+ return;
337
+ }
338
+
339
+ await this.subTree.setBlockCompleted(block.number, block.header);
340
+ this.deps.metrics.recordBlockProcessing(blockTimer.ms());
341
+ if (signal.aborted) {
342
+ return;
343
+ }
344
+ }
345
+
346
+ this.completed = true;
347
+ this.deps.metrics.recordCheckpointProcessing(checkpointTimer.ms());
348
+ this.deps.log.info(
349
+ `Finished enqueueing block-level proving for checkpoint ${this.checkpoint.number} in ${checkpointTimer.ms()}ms`,
350
+ {
351
+ checkpointNumber: this.checkpoint.number,
352
+ blockCount: this.checkpoint.blocks.length,
353
+ durationMs: checkpointTimer.ms(),
354
+ },
355
+ );
356
+ } finally {
357
+ if (!this.completed) {
358
+ if (subTreeStarted) {
359
+ await this.teardownSubTree();
360
+ }
361
+ this.blockProofs.reject(new Error(`Checkpoint ${this.id} did not complete block processing`));
362
+ }
363
+ }
364
+ }
365
+
366
+ /**
367
+ * Mark cancelled. Idempotent. Aborts in-flight work, rejects the block-proof promise,
368
+ * and kicks off a background teardown of the sub-tree. The teardown promise is exposed
369
+ * via `whenDone()`.
370
+ *
371
+ * `routine` distinguishes a post-finalize teardown (sub-tree already proven, fires
372
+ * once at prover exit) from a real abort (reorg, prune, deadline). Behaviour is
373
+ * identical either way; the flag only adjusts log verbosity.
374
+ */
375
+ public cancel({ routine = false }: { routine?: boolean } = {}): void {
376
+ if (this.cancelled) {
377
+ return;
378
+ }
379
+ this.cancelled = true;
380
+ // A teardown of a completed prover is routine regardless of the caller's flag —
381
+ // we logged the work as done already, so don't relabel it as a mid-flight cancel.
382
+ if (routine || this.completed) {
383
+ this.deps.log.verbose(`Tearing down CheckpointProver ${this.id}`, {
384
+ checkpointNumber: this.checkpoint.number,
385
+ wasCompleted: this.completed,
386
+ });
387
+ } else {
388
+ this.deps.log.info(`Cancelling in-flight CheckpointProver ${this.id}`, {
389
+ checkpointNumber: this.checkpoint.number,
390
+ wasCompleted: this.completed,
391
+ });
392
+ }
393
+ this.abortController.abort();
394
+ this.blockProofs.reject(new Error(`Checkpoint ${this.id} cancelled`));
395
+ this.cancelPromise = this.runCancel().catch(() => {});
396
+ }
397
+
398
+ private async runCancel(): Promise<void> {
399
+ if (this.subTree) {
400
+ try {
401
+ this.subTree.cancel();
402
+ } catch (err) {
403
+ this.deps.log.error('Error cancelling sub-tree', err);
404
+ }
405
+ }
406
+ await this.runPromise.catch(() => {});
407
+ if (this.subTree) {
408
+ await this.teardownSubTree();
409
+ }
410
+ }
411
+
412
+ private async teardownSubTree(): Promise<void> {
413
+ const { subTree } = this;
414
+ this.subTree = undefined;
415
+ if (subTree) {
416
+ this.deps.log.debug(`Tearing down sub-tree for checkpoint ${this.checkpoint.number}`, {
417
+ checkpointNumber: this.checkpoint.number,
418
+ });
419
+ try {
420
+ await subTree.stop();
421
+ } catch (err) {
422
+ this.deps.log.error('Error stopping sub-tree', err);
423
+ }
424
+ }
425
+ }
426
+
427
+ private getTxsForBlock(block: L2Block, txs: Map<string, Tx>): Tx[] {
428
+ return block.body.txEffects.map(txEffect => txs.get(txEffect.txHash.toString())!);
429
+ }
430
+
431
+ private async processTxs(publicProcessor: PublicProcessor, txs: Tx[]): Promise<ProcessedTx[]> {
432
+ const [processedTxs, failedTxs] = await publicProcessor.process(txs, { deadline: this.deps.deadline });
433
+
434
+ if (failedTxs.length) {
435
+ const failedTxHashes = await Promise.all(failedTxs.map(({ tx }) => tx.getTxHash()));
436
+ throw new Error(
437
+ `Txs failed processing: ${failedTxs
438
+ .map(({ error }, index) => `${failedTxHashes[index]} (${error})`)
439
+ .join(', ')}`,
440
+ );
441
+ }
442
+
443
+ if (processedTxs.length !== txs.length) {
444
+ throw new Error(`Failed to process all txs: processed ${processedTxs.length} out of ${txs.length}`);
445
+ }
446
+
447
+ return processedTxs;
448
+ }
449
+
450
+ private async createFork(blockNumber: BlockNumber, l1ToL2Messages: Fr[] | undefined) {
451
+ const db = await this.deps.dbProvider.fork(blockNumber);
452
+
453
+ if (l1ToL2Messages !== undefined) {
454
+ const l1ToL2MessagesPadded = padArrayEnd<Fr, number>(
455
+ l1ToL2Messages,
456
+ Fr.ZERO,
457
+ NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
458
+ 'Too many L1 to L2 messages',
459
+ );
460
+ await db.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
461
+ }
462
+
463
+ return db;
464
+ }
465
+ }