@aztec/prover-node 0.0.1-commit.2f68f620 → 0.0.1-commit.3100065

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 (65) hide show
  1. package/README.md +511 -0
  2. package/dest/actions/rerun-epoch-proving-job.d.ts +3 -3
  3. package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -1
  4. package/dest/actions/rerun-epoch-proving-job.js +106 -104
  5. package/dest/checkpoint-store.d.ts +88 -0
  6. package/dest/checkpoint-store.d.ts.map +1 -0
  7. package/dest/checkpoint-store.js +169 -0
  8. package/dest/config.d.ts +1 -3
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +1 -8
  11. package/dest/factory.d.ts +1 -1
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +1 -7
  14. package/dest/index.d.ts +2 -1
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +1 -0
  17. package/dest/job/checkpoint-prover.d.ts +124 -0
  18. package/dest/job/checkpoint-prover.d.ts.map +1 -0
  19. package/dest/job/checkpoint-prover.js +330 -0
  20. package/dest/job/epoch-session.d.ts +146 -0
  21. package/dest/job/epoch-session.d.ts.map +1 -0
  22. package/dest/job/epoch-session.js +720 -0
  23. package/dest/job/top-tree-job.d.ts +82 -0
  24. package/dest/job/top-tree-job.d.ts.map +1 -0
  25. package/dest/job/top-tree-job.js +152 -0
  26. package/dest/metrics.d.ts +25 -8
  27. package/dest/metrics.d.ts.map +1 -1
  28. package/dest/metrics.js +64 -14
  29. package/dest/proof-publishing-service.d.ts +161 -0
  30. package/dest/proof-publishing-service.d.ts.map +1 -0
  31. package/dest/proof-publishing-service.js +335 -0
  32. package/dest/prover-node-publisher.d.ts +7 -22
  33. package/dest/prover-node-publisher.d.ts.map +1 -1
  34. package/dest/prover-node-publisher.js +41 -101
  35. package/dest/prover-node.d.ts +105 -67
  36. package/dest/prover-node.d.ts.map +1 -1
  37. package/dest/prover-node.js +472 -261
  38. package/dest/prover-publisher-factory.d.ts +1 -3
  39. package/dest/prover-publisher-factory.d.ts.map +1 -1
  40. package/dest/prover-publisher-factory.js +0 -1
  41. package/dest/session-manager.d.ts +158 -0
  42. package/dest/session-manager.d.ts.map +1 -0
  43. package/dest/session-manager.js +482 -0
  44. package/dest/test/index.d.ts +7 -6
  45. package/dest/test/index.d.ts.map +1 -1
  46. package/package.json +23 -23
  47. package/src/actions/rerun-epoch-proving-job.ts +102 -27
  48. package/src/checkpoint-store.ts +194 -0
  49. package/src/config.ts +2 -11
  50. package/src/factory.ts +0 -9
  51. package/src/index.ts +1 -0
  52. package/src/job/checkpoint-prover.ts +442 -0
  53. package/src/job/epoch-session.ts +436 -0
  54. package/src/job/top-tree-job.ts +227 -0
  55. package/src/metrics.ts +65 -23
  56. package/src/proof-publishing-service.ts +427 -0
  57. package/src/prover-node-publisher.ts +54 -127
  58. package/src/prover-node.ts +545 -282
  59. package/src/prover-publisher-factory.ts +0 -3
  60. package/src/session-manager.ts +583 -0
  61. package/src/test/index.ts +6 -6
  62. package/dest/job/epoch-proving-job.d.ts +0 -67
  63. package/dest/job/epoch-proving-job.d.ts.map +0 -1
  64. package/dest/job/epoch-proving-job.js +0 -912
  65. package/src/job/epoch-proving-job.ts +0 -531
@@ -1,531 +0,0 @@
1
- import { asyncPool } from '@aztec/foundation/async-pool';
2
- import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
3
- import { Fr } from '@aztec/foundation/curves/bn254';
4
- import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
5
- import { RunningPromise, promiseWithResolvers } from '@aztec/foundation/promise';
6
- import { Timer } from '@aztec/foundation/timer';
7
- import { AVM_MAX_CONCURRENT_SIMULATIONS } from '@aztec/native';
8
- import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
9
- import { protocolContractsHash } from '@aztec/protocol-contracts';
10
- import { buildFinalBlobChallenges } from '@aztec/prover-client/helpers';
11
- import type { PublicProcessor, PublicProcessorFactory } from '@aztec/simulator/server';
12
- import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
13
- import type { L2Block, L2BlockSource } from '@aztec/stdlib/block';
14
- import type { Checkpoint } from '@aztec/stdlib/checkpoint';
15
- import {
16
- type EpochProver,
17
- type EpochProvingJobState,
18
- EpochProvingJobTerminalState,
19
- type ForkMerkleTreeOperations,
20
- } from '@aztec/stdlib/interfaces/server';
21
- import { appendL1ToL2MessagesToTree } from '@aztec/stdlib/messaging';
22
- import { CheckpointConstantData } from '@aztec/stdlib/rollup';
23
- import type { ProcessedTx, Tx } from '@aztec/stdlib/tx';
24
- import { Attributes, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
25
-
26
- import * as crypto from 'node:crypto';
27
-
28
- import type { ProverNodeJobMetrics } from '../metrics.js';
29
- import type { ProverNodePublisher } from '../prover-node-publisher.js';
30
- import { type EpochProvingJobData, validateEpochProvingJobData } from './epoch-proving-job-data.js';
31
-
32
- export type EpochProvingJobOptions = {
33
- parallelBlockLimit?: number;
34
- skipEpochCheck?: boolean;
35
- skipSubmitProof?: boolean;
36
- };
37
-
38
- /**
39
- * Job that grabs a range of blocks from the unfinalized chain from L1, gets their txs given their hashes,
40
- * re-executes their public calls, generates a rollup proof, and submits it to L1. This job will update the
41
- * world state as part of public call execution via the public processor.
42
- */
43
- export class EpochProvingJob implements Traceable {
44
- private state: EpochProvingJobState = 'initialized';
45
- private log: Logger;
46
- private uuid: string;
47
-
48
- private runPromise: Promise<void> | undefined;
49
- private abortController = new AbortController();
50
- private epochCheckPromise: RunningPromise | undefined;
51
- private deadlineTimeoutHandler: NodeJS.Timeout | undefined;
52
-
53
- public readonly tracer: Tracer;
54
-
55
- constructor(
56
- private data: EpochProvingJobData,
57
- private dbProvider: Pick<ForkMerkleTreeOperations, 'fork'>,
58
- private prover: EpochProver,
59
- private publicProcessorFactory: PublicProcessorFactory,
60
- private publisher: Pick<ProverNodePublisher, 'submitEpochProof' | 'analyzeEpochProofSubmission'>,
61
- private l2BlockSource: L2BlockSource | undefined,
62
- private metrics: ProverNodeJobMetrics,
63
- private deadline: Date | undefined,
64
- private config: EpochProvingJobOptions,
65
- bindings?: LoggerBindings,
66
- ) {
67
- validateEpochProvingJobData(data);
68
- this.uuid = crypto.randomUUID();
69
- this.log = createLogger('prover-node:epoch-proving-job', {
70
- ...bindings,
71
- instanceId: `epoch-${data.epochNumber}`,
72
- });
73
- this.tracer = metrics.tracer;
74
- }
75
-
76
- public getId(): string {
77
- return this.uuid;
78
- }
79
-
80
- public getState(): EpochProvingJobState {
81
- return this.state;
82
- }
83
-
84
- public getEpochNumber(): EpochNumber {
85
- return this.data.epochNumber;
86
- }
87
-
88
- public getDeadline(): Date | undefined {
89
- return this.deadline;
90
- }
91
-
92
- public getProvingData(): EpochProvingJobData {
93
- return this.data;
94
- }
95
-
96
- private get epochNumber() {
97
- return this.data.epochNumber;
98
- }
99
-
100
- private get checkpoints() {
101
- return this.data.checkpoints;
102
- }
103
-
104
- private get txs() {
105
- return this.data.txs;
106
- }
107
-
108
- private get attestations() {
109
- return this.data.attestations;
110
- }
111
-
112
- /**
113
- * Proves the given epoch and submits the proof to L1.
114
- */
115
- @trackSpan('EpochProvingJob.run', function () {
116
- return { [Attributes.EPOCH_NUMBER]: this.data.epochNumber };
117
- })
118
- public async run() {
119
- this.scheduleDeadlineStop();
120
- if (!this.config.skipEpochCheck) {
121
- await this.scheduleEpochCheck();
122
- }
123
-
124
- const attestations = this.attestations.map(attestation => attestation.toViem());
125
- const epochNumber = this.epochNumber;
126
- const epochSizeCheckpoints = this.checkpoints.length;
127
- const epochSizeBlocks = this.checkpoints.reduce((accum, checkpoint) => accum + checkpoint.blocks.length, 0);
128
- const epochSizeTxs = this.checkpoints.reduce(
129
- (accum, checkpoint) =>
130
- accum + checkpoint.blocks.reduce((accumC, block) => accumC + block.body.txEffects.length, 0),
131
- 0,
132
- );
133
- const fromCheckpoint = this.checkpoints[0].number;
134
- const toCheckpoint = this.checkpoints.at(-1)!.number;
135
- const fromBlock = this.checkpoints[0].blocks[0].number;
136
- const toBlock = this.checkpoints.at(-1)!.blocks.at(-1)!.number;
137
- this.log.info(`Starting epoch ${epochNumber} proving job with checkpoints ${fromCheckpoint} to ${toCheckpoint}`, {
138
- fromBlock,
139
- toBlock,
140
- epochSizeTxs,
141
- epochNumber,
142
- uuid: this.uuid,
143
- });
144
-
145
- this.progressState('processing');
146
- const timer = new Timer();
147
- const { promise, resolve } = promiseWithResolvers<void>();
148
- this.runPromise = promise;
149
-
150
- try {
151
- const blobTimer = new Timer();
152
- const blobFieldsPerCheckpoint = this.checkpoints.map(checkpoint => checkpoint.toBlobFields());
153
- const finalBlobBatchingChallenges = await buildFinalBlobChallenges(blobFieldsPerCheckpoint);
154
- this.metrics.recordBlobProcessing(blobTimer.ms());
155
-
156
- this.prover.startNewEpoch(epochNumber, epochSizeCheckpoints, finalBlobBatchingChallenges);
157
- const chonkTimer = new Timer();
158
- await this.prover.startChonkVerifierCircuits(Array.from(this.txs.values()));
159
- this.metrics.recordChonkVerifier(chonkTimer.ms());
160
-
161
- // Everything in the epoch should have the same chainId and version.
162
- const { chainId, version } = this.checkpoints[0].blocks[0].header.globalVariables;
163
-
164
- const previousBlockHeaders = this.gatherPreviousBlockHeaders();
165
-
166
- const allCheckpointsTimer = new Timer();
167
-
168
- const parallelism = this.config.parallelBlockLimit
169
- ? this.config.parallelBlockLimit
170
- : AVM_MAX_CONCURRENT_SIMULATIONS > 0
171
- ? AVM_MAX_CONCURRENT_SIMULATIONS
172
- : this.checkpoints.length;
173
-
174
- await this.processCheckpoints(parallelism, async checkpoint => {
175
- this.checkState();
176
- const checkpointTimer = new Timer();
177
-
178
- const checkpointIndex = checkpoint.number - fromCheckpoint;
179
- const checkpointConstants = CheckpointConstantData.from({
180
- chainId,
181
- version,
182
- vkTreeRoot: getVKTreeRoot(),
183
- protocolContractsHash: protocolContractsHash,
184
- proverId: this.prover.getProverId().toField(),
185
- slotNumber: checkpoint.header.slotNumber,
186
- coinbase: checkpoint.header.coinbase,
187
- feeRecipient: checkpoint.header.feeRecipient,
188
- gasFees: checkpoint.header.gasFees,
189
- });
190
- const previousHeader = previousBlockHeaders[checkpointIndex];
191
- const l1ToL2Messages = this.getL1ToL2Messages(checkpoint);
192
-
193
- this.log.debug(`Starting processing checkpoint ${checkpoint.number}`, {
194
- number: checkpoint.number,
195
- checkpointHash: checkpoint.hash().toString(),
196
- headerHash: checkpoint.header.hash().toString(),
197
- numL1ToL2Messages: l1ToL2Messages.length,
198
- previousBlockNumber: previousHeader.globalVariables.blockNumber,
199
- uuid: this.uuid,
200
- });
201
-
202
- await this.prover.startNewCheckpoint(
203
- checkpointIndex,
204
- checkpointConstants,
205
- l1ToL2Messages,
206
- checkpoint.blocks.length,
207
- previousHeader,
208
- );
209
-
210
- for (let blockIndex = 0; blockIndex < checkpoint.blocks.length; blockIndex++) {
211
- const blockTimer = new Timer();
212
- const block = checkpoint.blocks[blockIndex];
213
- const globalVariables = block.header.globalVariables;
214
- const txs = this.getTxs(block);
215
-
216
- this.log.verbose(`Starting processing block ${block.number}`, {
217
- number: block.number,
218
- blockHash: (await block.hash()).toString(),
219
- lastArchive: block.header.lastArchive.root,
220
- noteHashTreeRoot: block.header.state.partial.noteHashTree.root,
221
- nullifierTreeRoot: block.header.state.partial.nullifierTree.root,
222
- publicDataTreeRoot: block.header.state.partial.publicDataTree.root,
223
- ...globalVariables,
224
- numTxs: txs.length,
225
- });
226
-
227
- // Start block proving
228
- await this.prover.startNewBlock(block.number, globalVariables.timestamp, txs.length);
229
-
230
- // Process public fns. L1 to L2 messages are only inserted for the first block of a checkpoint,
231
- // as the fork for subsequent blocks already includes them from the previous block's synced state.
232
- {
233
- await using db = await this.createFork(
234
- BlockNumber(block.number - 1),
235
- blockIndex === 0 ? l1ToL2Messages : undefined,
236
- );
237
- this.checkState();
238
- const config = PublicSimulatorConfig.from({
239
- proverId: this.prover.getProverId().toField(),
240
- skipFeeEnforcement: false,
241
- collectDebugLogs: false,
242
- collectHints: true,
243
- collectPublicInputs: true,
244
- collectStatistics: false,
245
- });
246
- const publicProcessor = this.publicProcessorFactory.create(db, globalVariables, config);
247
- const processed = await this.processTxs(publicProcessor, txs);
248
- this.checkState();
249
- await this.prover.addTxs(processed);
250
- }
251
- this.checkState();
252
- this.log.verbose(`Processed all ${txs.length} txs for block ${block.number}`, {
253
- blockNumber: block.number,
254
- blockHash: (await block.hash()).toString(),
255
- uuid: this.uuid,
256
- });
257
-
258
- // Mark block as completed to pad it
259
- const expectedBlockHeader = block.header;
260
- await this.prover.setBlockCompleted(block.number, expectedBlockHeader);
261
- this.metrics.recordBlockProcessing(blockTimer.ms());
262
- }
263
- this.metrics.recordCheckpointProcessing(checkpointTimer.ms());
264
- });
265
- this.metrics.recordAllCheckpointsProcessing(allCheckpointsTimer.ms());
266
-
267
- const executionTime = timer.ms();
268
-
269
- this.progressState('awaiting-prover');
270
- const { publicInputs, proof, batchedBlobInputs } = await this.prover.finalizeEpoch();
271
- this.log.info(`Finalized proof for epoch ${epochNumber}`, { epochNumber, uuid: this.uuid, duration: timer.ms() });
272
-
273
- this.progressState('publishing-proof');
274
-
275
- if (this.config.skipSubmitProof) {
276
- this.log.info(
277
- `Proof publishing is disabled. Analyzing estimated L1 fees for epoch ${epochNumber} (checkpoints ${fromCheckpoint} to ${toCheckpoint})`,
278
- );
279
- try {
280
- await this.publisher.analyzeEpochProofSubmission({
281
- fromCheckpoint,
282
- toCheckpoint,
283
- epochNumber,
284
- publicInputs,
285
- proof,
286
- batchedBlobInputs,
287
- attestations,
288
- });
289
- } catch (err) {
290
- this.log.warn(`Failed to analyze estimated L1 fees for epoch ${epochNumber}`, err);
291
- }
292
- this.state = 'completed';
293
- this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeCheckpoints, epochSizeBlocks, epochSizeTxs);
294
- return;
295
- }
296
-
297
- const success = await this.publisher.submitEpochProof({
298
- fromCheckpoint,
299
- toCheckpoint,
300
- epochNumber,
301
- publicInputs,
302
- proof,
303
- batchedBlobInputs,
304
- attestations,
305
- });
306
- if (!success) {
307
- throw new Error('Failed to submit epoch proof to L1');
308
- }
309
-
310
- this.log.info(`Submitted proof for epoch ${epochNumber} (checkpoints ${fromCheckpoint} to ${toCheckpoint})`, {
311
- epochNumber,
312
- uuid: this.uuid,
313
- });
314
- this.state = 'completed';
315
- this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeCheckpoints, epochSizeBlocks, epochSizeTxs);
316
- } catch (err: any) {
317
- if (err && err.name === 'HaltExecutionError') {
318
- this.log.warn(`Halted execution of epoch ${epochNumber} prover job`, {
319
- uuid: this.uuid,
320
- epochNumber,
321
- details: err.message,
322
- });
323
- return;
324
- }
325
- this.log.error(`Error running epoch ${epochNumber} prover job`, err, { uuid: this.uuid, epochNumber });
326
- if (this.state === 'processing' || this.state === 'awaiting-prover' || this.state === 'publishing-proof') {
327
- this.state = 'failed';
328
- }
329
- } finally {
330
- clearTimeout(this.deadlineTimeoutHandler);
331
- await this.epochCheckPromise?.stop();
332
- await this.prover.stop();
333
- resolve();
334
- }
335
- }
336
-
337
- /**
338
- * Create a new db fork for tx processing, optionally inserting L1 to L2 messages.
339
- * L1 to L2 messages should only be inserted for the first block in a checkpoint,
340
- * as subsequent blocks' synced state already includes them.
341
- * REFACTOR: The prover already spawns a db fork of its own for each block, so we may be able to do away with just one fork.
342
- */
343
- private async createFork(blockNumber: BlockNumber, l1ToL2Messages: Fr[] | undefined) {
344
- this.log.verbose(`Creating fork at ${blockNumber}`, { blockNumber });
345
- // temporary stack to control fork lifetime
346
- await using cleanup = new AsyncDisposableStack();
347
- const db = cleanup.use(await this.dbProvider.fork(blockNumber));
348
-
349
- if (l1ToL2Messages !== undefined) {
350
- this.log.verbose(`Inserting ${l1ToL2Messages.length} L1 to L2 messages in fork`, {
351
- blockNumber,
352
- l1ToL2Messages: l1ToL2Messages.map(m => m.toString()),
353
- });
354
- await appendL1ToL2MessagesToTree(db, l1ToL2Messages);
355
- }
356
-
357
- // everything run succesfully so we can release this stack and give control of the fork's lifetime to the caller
358
- cleanup.move();
359
- return db;
360
- }
361
-
362
- private async processCheckpoints(
363
- parallelism: number,
364
- processCheckpoint: (checkpoint: Checkpoint) => Promise<void>,
365
- ): Promise<void> {
366
- let hasError = false;
367
- let firstError: unknown;
368
-
369
- await asyncPool(Math.max(parallelism, 1), this.checkpoints, async checkpoint => {
370
- if (hasError || this.abortController.signal.aborted) {
371
- return;
372
- }
373
-
374
- try {
375
- this.checkState();
376
- await processCheckpoint(checkpoint);
377
- } catch (err) {
378
- if (!hasError) {
379
- hasError = true;
380
- firstError = err;
381
- this.failProcessing();
382
- }
383
- }
384
- });
385
-
386
- if (hasError) {
387
- throw firstError;
388
- }
389
-
390
- if (this.abortController.signal.aborted) {
391
- this.checkState();
392
- }
393
- }
394
-
395
- private progressState(state: EpochProvingJobState) {
396
- this.checkState();
397
- this.state = state;
398
- }
399
-
400
- private checkState() {
401
- if (this.state === 'timed-out' || this.state === 'stopped' || this.state === 'failed' || this.state === 'reorg') {
402
- throw new HaltExecutionError(this.state);
403
- }
404
- }
405
-
406
- public async stop(state: EpochProvingJobTerminalState = 'stopped') {
407
- this.state = state;
408
- this.interruptProcessing();
409
- if (this.runPromise) {
410
- await this.runPromise;
411
- }
412
- }
413
-
414
- private failProcessing() {
415
- if (!EpochProvingJobTerminalState.includes(this.state)) {
416
- this.state = 'failed';
417
- }
418
- this.interruptProcessing();
419
- }
420
-
421
- private interruptProcessing() {
422
- this.abortController.abort();
423
- this.prover.cancel();
424
- }
425
-
426
- private scheduleDeadlineStop() {
427
- const deadline = this.deadline;
428
- if (deadline) {
429
- const timeout = deadline.getTime() - Date.now();
430
- if (timeout <= 0) {
431
- throw new Error('Cannot start job with deadline in the past');
432
- }
433
-
434
- this.deadlineTimeoutHandler = setTimeout(() => {
435
- if (EpochProvingJobTerminalState.includes(this.state)) {
436
- return;
437
- }
438
- this.log.warn('Stopping job due to deadline hit', { uuid: this.uuid, epochNumber: this.epochNumber });
439
- this.stop('timed-out').catch(err => {
440
- this.log.error('Error stopping job', err, { uuid: this.uuid, epochNumber: this.epochNumber });
441
- });
442
- }, timeout);
443
- }
444
- }
445
-
446
- /**
447
- * Kicks off a running promise that queries the archiver for the set of L2 blocks of the current epoch.
448
- * If those change, stops the proving job with a `rerun` state, so the node re-enqueues it.
449
- */
450
- private async scheduleEpochCheck() {
451
- const l2BlockSource = this.l2BlockSource;
452
- if (!l2BlockSource) {
453
- this.log.warn(`No L2 block source available, skipping epoch check`);
454
- return;
455
- }
456
-
457
- const intervalMs = Math.ceil((await l2BlockSource.getL1Constants()).ethereumSlotDuration / 2) * 1000;
458
- this.epochCheckPromise = new RunningPromise(
459
- async () => {
460
- const blockHeaders = (
461
- await l2BlockSource.getBlocksData({ epoch: this.epochNumber, onlyCheckpointed: true })
462
- ).map(d => d.header);
463
- const blockHashes = await Promise.all(blockHeaders.map(header => header.hash()));
464
- const thisBlocks = this.checkpoints.flatMap(checkpoint => checkpoint.blocks);
465
- const thisBlockHashes = await Promise.all(thisBlocks.map(block => block.hash()));
466
- if (
467
- blockHeaders.length !== thisBlocks.length ||
468
- !blockHashes.every((block, i) => block.equals(thisBlockHashes[i]))
469
- ) {
470
- this.log.warn('Epoch blocks changed underfoot', {
471
- uuid: this.uuid,
472
- epochNumber: this.epochNumber,
473
- oldBlockHashes: thisBlockHashes,
474
- newBlockHashes: blockHashes,
475
- });
476
- void this.stop('reorg');
477
- }
478
- },
479
- this.log,
480
- intervalMs,
481
- ).start();
482
- this.log.verbose(`Scheduled epoch check for epoch ${this.epochNumber} every ${intervalMs}ms`);
483
- }
484
-
485
- /* Returns the last block header in the previous checkpoint for all checkpoints in the epoch */
486
- private gatherPreviousBlockHeaders() {
487
- const lastBlocks = this.checkpoints.map(checkpoint => checkpoint.blocks.at(-1)!);
488
- return [this.data.previousBlockHeader, ...lastBlocks.map(block => block.header).slice(0, -1)];
489
- }
490
-
491
- private getTxs(block: L2Block): Tx[] {
492
- return block.body.txEffects.map(txEffect => this.txs.get(txEffect.txHash.toString())!);
493
- }
494
-
495
- private getL1ToL2Messages(checkpoint: Checkpoint) {
496
- return this.data.l1ToL2Messages[checkpoint.number];
497
- }
498
-
499
- private async processTxs(publicProcessor: PublicProcessor, txs: Tx[]): Promise<ProcessedTx[]> {
500
- const { deadline } = this;
501
- const [processedTxs, failedTxs] = await publicProcessor.process(txs, {
502
- deadline,
503
- signal: this.abortController.signal,
504
- });
505
- this.checkState();
506
-
507
- if (failedTxs.length) {
508
- const failedTxHashes = await Promise.all(failedTxs.map(({ tx }) => tx.getTxHash()));
509
- throw new Error(
510
- `Txs failed processing: ${failedTxs
511
- .map(({ error }, index) => `${failedTxHashes[index]} (${error})`)
512
- .join(', ')}`,
513
- );
514
- }
515
-
516
- if (processedTxs.length !== txs.length) {
517
- throw new Error(`Failed to process all txs: processed ${processedTxs.length} out of ${txs.length}`);
518
- }
519
-
520
- return processedTxs;
521
- }
522
- }
523
-
524
- class HaltExecutionError extends Error {
525
- constructor(public readonly state: EpochProvingJobState) {
526
- super(`Halted execution due to state ${state}`);
527
- this.name = 'HaltExecutionError';
528
- }
529
- }
530
-
531
- export { type EpochProvingJobState };