@aztec/prover-node 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f

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 (49) hide show
  1. package/dest/actions/download-epoch-proving-job.d.ts +1 -1
  2. package/dest/actions/download-epoch-proving-job.js +1 -1
  3. package/dest/actions/rerun-epoch-proving-job.d.ts +5 -3
  4. package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -1
  5. package/dest/actions/rerun-epoch-proving-job.js +9 -7
  6. package/dest/actions/upload-epoch-proof-failure.d.ts +2 -2
  7. package/dest/actions/upload-epoch-proof-failure.d.ts.map +1 -1
  8. package/dest/bin/run-failed-epoch.js +6 -5
  9. package/dest/config.d.ts +5 -8
  10. package/dest/config.d.ts.map +1 -1
  11. package/dest/config.js +16 -19
  12. package/dest/factory.d.ts +19 -15
  13. package/dest/factory.d.ts.map +1 -1
  14. package/dest/factory.js +45 -64
  15. package/dest/index.d.ts +2 -1
  16. package/dest/index.d.ts.map +1 -1
  17. package/dest/index.js +1 -0
  18. package/dest/job/epoch-proving-job.d.ts +7 -2
  19. package/dest/job/epoch-proving-job.d.ts.map +1 -1
  20. package/dest/job/epoch-proving-job.js +600 -52
  21. package/dest/metrics.d.ts +21 -1
  22. package/dest/metrics.d.ts.map +1 -1
  23. package/dest/metrics.js +73 -100
  24. package/dest/monitors/epoch-monitor.d.ts +1 -1
  25. package/dest/monitors/epoch-monitor.d.ts.map +1 -1
  26. package/dest/monitors/epoch-monitor.js +12 -19
  27. package/dest/prover-node-publisher.d.ts +25 -5
  28. package/dest/prover-node-publisher.d.ts.map +1 -1
  29. package/dest/prover-node-publisher.js +210 -14
  30. package/dest/prover-node.d.ts +20 -11
  31. package/dest/prover-node.d.ts.map +1 -1
  32. package/dest/prover-node.js +429 -46
  33. package/dest/prover-publisher-factory.d.ts +7 -5
  34. package/dest/prover-publisher-factory.d.ts.map +1 -1
  35. package/dest/prover-publisher-factory.js +7 -5
  36. package/package.json +24 -23
  37. package/src/actions/download-epoch-proving-job.ts +1 -1
  38. package/src/actions/rerun-epoch-proving-job.ts +20 -7
  39. package/src/actions/upload-epoch-proof-failure.ts +1 -1
  40. package/src/bin/run-failed-epoch.ts +5 -3
  41. package/src/config.ts +23 -31
  42. package/src/factory.ts +77 -104
  43. package/src/index.ts +1 -0
  44. package/src/job/epoch-proving-job.ts +151 -47
  45. package/src/metrics.ts +91 -83
  46. package/src/monitors/epoch-monitor.ts +6 -14
  47. package/src/prover-node-publisher.ts +245 -19
  48. package/src/prover-node.ts +31 -31
  49. package/src/prover-publisher-factory.ts +16 -10
@@ -1,5 +1,5 @@
1
1
  import { BatchedBlob, getEthBlobEvaluationInputs } from '@aztec/blob-lib';
2
- import { AZTEC_MAX_EPOCH_DURATION } from '@aztec/constants';
2
+ import { MAX_CHECKPOINTS_PER_EPOCH } from '@aztec/constants';
3
3
  import type { RollupContract, ViemCommitteeAttestation } from '@aztec/ethereum/contracts';
4
4
  import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
5
5
  import { makeTuple } from '@aztec/foundation/array';
@@ -7,21 +7,23 @@ import { CheckpointNumber, EpochNumber } from '@aztec/foundation/branded-types';
7
7
  import { areArraysEqual } from '@aztec/foundation/collection';
8
8
  import { Fr } from '@aztec/foundation/curves/bn254';
9
9
  import { EthAddress } from '@aztec/foundation/eth-address';
10
- import { createLogger } from '@aztec/foundation/log';
10
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
11
+ import { retryUntil } from '@aztec/foundation/retry';
11
12
  import type { Tuple } from '@aztec/foundation/serialize';
12
13
  import { Timer } from '@aztec/foundation/timer';
13
14
  import { RollupAbi } from '@aztec/l1-artifacts';
14
15
  import type { PublisherConfig, TxSenderConfig } from '@aztec/sequencer-client';
15
16
  import { CommitteeAttestation, CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
17
+ import { getProofSubmissionDeadlineTimestamp } from '@aztec/stdlib/epoch-helpers';
16
18
  import type { Proof } from '@aztec/stdlib/proofs';
17
19
  import type { FeeRecipient, RootRollupPublicInputs } from '@aztec/stdlib/rollup';
18
20
  import type { L1PublishProofStats } from '@aztec/stdlib/stats';
19
21
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
20
22
 
21
23
  import { inspect } from 'util';
22
- import { type Hex, type TransactionReceipt, encodeFunctionData } from 'viem';
24
+ import { type Hex, type TransactionReceipt, encodeFunctionData, formatEther, formatGwei } from 'viem';
23
25
 
24
- import { ProverNodePublisherMetrics } from './metrics.js';
26
+ import { type EstimatedSubmitProofStats, ProverNodePublisherMetrics } from './metrics.js';
25
27
 
26
28
  /** Arguments to the submitEpochProof method of the rollup contract */
27
29
  export type L1SubmitEpochProofArgs = {
@@ -31,7 +33,7 @@ export type L1SubmitEpochProofArgs = {
31
33
  endTimestamp: Fr;
32
34
  outHash: Fr;
33
35
  proverId: Fr;
34
- fees: Tuple<FeeRecipient, typeof AZTEC_MAX_EPOCH_DURATION>;
36
+ fees: Tuple<FeeRecipient, typeof MAX_CHECKPOINTS_PER_EPOCH>;
35
37
  proof: Proof;
36
38
  };
37
39
 
@@ -39,7 +41,7 @@ export class ProverNodePublisher {
39
41
  private interrupted = false;
40
42
  private metrics: ProverNodePublisherMetrics;
41
43
 
42
- protected log = createLogger('prover-node:l1-tx-publisher');
44
+ protected log: Logger;
43
45
 
44
46
  protected rollupContract: RollupContract;
45
47
 
@@ -52,10 +54,12 @@ export class ProverNodePublisher {
52
54
  l1TxUtils: L1TxUtils;
53
55
  telemetry?: TelemetryClient;
54
56
  },
57
+ bindings?: LoggerBindings,
55
58
  ) {
56
59
  const telemetry = deps.telemetry ?? getTelemetryClient();
57
60
 
58
61
  this.metrics = new ProverNodePublisherMetrics(telemetry, 'ProverNode');
62
+ this.log = createLogger('prover-node:l1-tx-publisher', bindings);
59
63
 
60
64
  this.rollupContract = deps.rollupContract;
61
65
  this.l1TxUtils = deps.l1TxUtils;
@@ -99,6 +103,11 @@ export class ProverNodePublisher {
99
103
  const ctx = { epochNumber, fromCheckpoint, toCheckpoint };
100
104
 
101
105
  if (!this.interrupted) {
106
+ if (!(await this.waitUntilStartBuildsOnProven(args))) {
107
+ this.log.verbose('Checkpoint data syncing interrupted', ctx);
108
+ return false;
109
+ }
110
+
102
111
  const timer = new Timer();
103
112
  // Validate epoch proof range and hashes are correct before submitting
104
113
  await this.validateEpochProofSubmission(args);
@@ -145,6 +154,53 @@ export class ProverNodePublisher {
145
154
  return false;
146
155
  }
147
156
 
157
+ private async waitUntilStartBuildsOnProven(args: { epochNumber: EpochNumber; fromCheckpoint: CheckpointNumber }) {
158
+ const { epochNumber, fromCheckpoint } = args;
159
+ const provenCheckpoint = await this.getProvenCheckpoint();
160
+ if (this.isStartBuildingOnProven(fromCheckpoint, provenCheckpoint)) {
161
+ return true;
162
+ }
163
+
164
+ const timeout = await this.getSecondsUntilProofSubmissionWindowEnd(epochNumber);
165
+ this.log.info(`Waiting for proven checkpoint to reach proof start`, {
166
+ epochNumber,
167
+ fromCheckpoint,
168
+ provenCheckpoint,
169
+ timeout,
170
+ });
171
+
172
+ await retryUntil(
173
+ async () => {
174
+ if (this.interrupted) {
175
+ return true;
176
+ }
177
+
178
+ const proven = await this.getProvenCheckpoint();
179
+ this.log.verbose(`Proven checkpoint is at ${proven} (waiting for ${fromCheckpoint - 1})`, { epochNumber });
180
+ return this.isStartBuildingOnProven(fromCheckpoint, proven) ? true : undefined;
181
+ },
182
+ `proven checkpoint to reach ${fromCheckpoint - 1}`,
183
+ timeout,
184
+ 4,
185
+ );
186
+
187
+ return !this.interrupted;
188
+ }
189
+
190
+ private async getProvenCheckpoint() {
191
+ return (await this.rollupContract.getTips()).proven;
192
+ }
193
+
194
+ private isStartBuildingOnProven(fromCheckpoint: CheckpointNumber, provenCheckpoint: CheckpointNumber) {
195
+ return fromCheckpoint - 1 <= provenCheckpoint;
196
+ }
197
+
198
+ private async getSecondsUntilProofSubmissionWindowEnd(epochNumber: EpochNumber) {
199
+ const deadline = getProofSubmissionDeadlineTimestamp(epochNumber, await this.rollupContract.getRollupConstants());
200
+ const now = BigInt(Math.floor(Date.now() / 1000));
201
+ return Math.max(Number(deadline - now), 0.001);
202
+ }
203
+
148
204
  private async validateEpochProofSubmission(args: {
149
205
  fromCheckpoint: CheckpointNumber;
150
206
  toCheckpoint: CheckpointNumber;
@@ -166,23 +222,23 @@ export class ProverNodePublisher {
166
222
  // toCheckpoint can't be greater than pending
167
223
  if (toCheckpoint > pending) {
168
224
  throw new Error(
169
- `Cannot submit epoch proof for ${fromCheckpoint}-${toCheckpoint} as pending checkpoint is ${pending}`,
225
+ `Cannot submit epoch proof for ${fromCheckpoint}-${toCheckpoint} as proposed checkpoint is ${pending}`,
170
226
  );
171
227
  }
172
228
 
173
229
  // Check the archive for the immediate checkpoint before the epoch
174
230
  const checkpointLog = await this.rollupContract.getCheckpoint(CheckpointNumber(fromCheckpoint - 1));
175
- if (publicInputs.previousArchiveRoot.toString() !== checkpointLog.archive) {
231
+ if (!publicInputs.previousArchiveRoot.equals(checkpointLog.archive)) {
176
232
  throw new Error(
177
- `Previous archive root mismatch: ${publicInputs.previousArchiveRoot.toString()} !== ${checkpointLog.archive}`,
233
+ `Previous archive root mismatch: ${publicInputs.previousArchiveRoot.toString()} !== ${checkpointLog.archive.toString()}`,
178
234
  );
179
235
  }
180
236
 
181
237
  // Check the archive for the last checkpoint in the epoch
182
238
  const endCheckpointLog = await this.rollupContract.getCheckpoint(toCheckpoint);
183
- if (publicInputs.endArchiveRoot.toString() !== endCheckpointLog.archive) {
239
+ if (!publicInputs.endArchiveRoot.equals(endCheckpointLog.archive)) {
184
240
  throw new Error(
185
- `End archive root mismatch: ${publicInputs.endArchiveRoot.toString()} !== ${endCheckpointLog.archive}`,
241
+ `End archive root mismatch: ${publicInputs.endArchiveRoot.toString()} !== ${endCheckpointLog.archive.toString()}`,
186
242
  );
187
243
  }
188
244
 
@@ -200,14 +256,86 @@ export class ProverNodePublisher {
200
256
  );
201
257
  const argsPublicInputs = [...publicInputs.toFields()];
202
258
 
203
- if (!areArraysEqual(rollupPublicInputs.map(Fr.fromHexString), argsPublicInputs, (a, b) => a.equals(b))) {
204
- const fmt = (inputs: Fr[] | readonly string[]) => inputs.map(x => x.toString()).join(', ');
205
- throw new Error(
206
- `Root rollup public inputs mismatch:\nRollup: ${fmt(rollupPublicInputs)}\nComputed:${fmt(argsPublicInputs)}`,
207
- );
259
+ if (!areArraysEqual(rollupPublicInputs, argsPublicInputs, (a, b) => a.equals(b))) {
260
+ throw await reportPublicInputsMismatch({
261
+ rollupPublicInputs,
262
+ argsPublicInputs,
263
+ fromCheckpoint,
264
+ toCheckpoint,
265
+ rollupContract: this.rollupContract,
266
+ log: this.log,
267
+ });
208
268
  }
209
269
  }
210
270
 
271
+ /**
272
+ * Estimates what submitting the epoch proof would have cost on L1 without actually sending it.
273
+ * Runs the same validation as `submitEpochProof`, encodes the calldata, estimates gas, and records metrics.
274
+ * Used when proof publishing is disabled (e.g. PROVER_NODE_DISABLE_PROOF_PUBLISH=true on mainnet).
275
+ */
276
+ public async analyzeEpochProofSubmission(args: {
277
+ epochNumber: EpochNumber;
278
+ fromCheckpoint: CheckpointNumber;
279
+ toCheckpoint: CheckpointNumber;
280
+ publicInputs: RootRollupPublicInputs;
281
+ proof: Proof;
282
+ batchedBlobInputs: BatchedBlob;
283
+ attestations: ViemCommitteeAttestation[];
284
+ }): Promise<void> {
285
+ const { epochNumber, fromCheckpoint, toCheckpoint } = args;
286
+
287
+ await this.validateEpochProofSubmission(args);
288
+
289
+ const data = this.encodeSubmitEpochProofCalldata(args);
290
+ const senderAddress = this.l1TxUtils.getSenderAddress();
291
+
292
+ const [gasLimit, gasPrice, latestBlock] = await Promise.all([
293
+ this.l1TxUtils.estimateGas(senderAddress.toString() as `0x${string}`, { to: this.rollupContract.address, data }),
294
+ this.l1TxUtils.getGasPrice(),
295
+ this.l1TxUtils.client.getBlock({ blockTag: 'latest' }),
296
+ ]);
297
+
298
+ const baseFeePerGas = latestBlock.baseFeePerGas ?? 0n;
299
+ const { maxPriorityFeePerGas } = gasPrice;
300
+
301
+ const effectiveFeePerGas = baseFeePerGas + maxPriorityFeePerGas;
302
+ const estimatedTotalFee = gasLimit * effectiveFeePerGas;
303
+
304
+ const stats: EstimatedSubmitProofStats = {
305
+ gasLimit,
306
+ baseFeePerGas,
307
+ maxPriorityFeePerGas,
308
+ estimatedTotalFee,
309
+ };
310
+
311
+ this.log.info(`Estimated epoch proof submission cost (not submitted)`, {
312
+ epochNumber,
313
+ fromCheckpoint,
314
+ toCheckpoint,
315
+ gasLimit: gasLimit.toString(),
316
+ baseFeePerGas: formatGwei(baseFeePerGas),
317
+ maxPriorityFeePerGas: formatGwei(maxPriorityFeePerGas),
318
+ estimatedTotalFeeEth: formatEther(estimatedTotalFee),
319
+ });
320
+
321
+ this.metrics.recordEstimatedSubmitProof(stats);
322
+ }
323
+
324
+ private encodeSubmitEpochProofCalldata(args: {
325
+ fromCheckpoint: CheckpointNumber;
326
+ toCheckpoint: CheckpointNumber;
327
+ publicInputs: RootRollupPublicInputs;
328
+ proof: Proof;
329
+ batchedBlobInputs: BatchedBlob;
330
+ attestations: ViemCommitteeAttestation[];
331
+ }): Hex {
332
+ return encodeFunctionData({
333
+ abi: RollupAbi,
334
+ functionName: 'submitEpochRootProof',
335
+ args: [this.getSubmitEpochProofArgs(args)],
336
+ });
337
+ }
338
+
211
339
  private async sendSubmitEpochProofTx(args: {
212
340
  fromCheckpoint: CheckpointNumber;
213
341
  toCheckpoint: CheckpointNumber;
@@ -266,9 +394,10 @@ export class ProverNodePublisher {
266
394
  {
267
395
  previousArchive: args.publicInputs.previousArchiveRoot.toString(),
268
396
  endArchive: args.publicInputs.endArchiveRoot.toString(),
397
+ outHash: args.publicInputs.outHash.toString(),
269
398
  proverId: EthAddress.fromField(args.publicInputs.constants.proverId).toString(),
270
399
  } /*_args*/,
271
- makeTuple(AZTEC_MAX_EPOCH_DURATION * 2, i =>
400
+ makeTuple(MAX_CHECKPOINTS_PER_EPOCH * 2, i =>
272
401
  i % 2 === 0
273
402
  ? args.publicInputs.fees[i / 2].recipient.toField().toString()
274
403
  : args.publicInputs.fees[(i - 1) / 2].value.toString(),
@@ -293,11 +422,108 @@ export class ProverNodePublisher {
293
422
  end: argsArray[1],
294
423
  args: argsArray[2],
295
424
  fees: argsArray[3],
296
- attestations: new CommitteeAttestationsAndSigners(
425
+ attestations: CommitteeAttestationsAndSigners.packAttestations(
297
426
  args.attestations.map(a => CommitteeAttestation.fromViem(a)),
298
- ).getPackedAttestations(),
427
+ ),
299
428
  blobInputs: argsArray[4],
300
429
  proof: proofHex,
301
430
  };
302
431
  }
303
432
  }
433
+
434
+ /**
435
+ * Decodes a `Root rollup public inputs mismatch`, fetches the on-chain CheckpointLog for any
436
+ * mismatching `checkpointHeaderHashes[i]`, emits a structured error log, and returns a thrown-ready
437
+ * Error with a human-readable summary.
438
+ *
439
+ * Layout of `RootRollupPublicInputs.toFields()`:
440
+ * [0] previousArchiveRoot
441
+ * [1] endArchiveRoot
442
+ * [2] outHash
443
+ * [3 .. 3+N-1] checkpointHeaderHashes[i] for i in 0..N-1 (N = MAX_CHECKPOINTS_PER_EPOCH)
444
+ * [3+N .. 3+3N-1] fees[i] = (recipient, value) for i in 0..N-1
445
+ * [3+3N .. 3+3N+4] EpochConstantData (chainId, version, vkTreeRoot, protocolContractsHash, proverId)
446
+ * [3+3N+5 ..] blobPublicInputs (FinalBlobAccumulator)
447
+ */
448
+ async function reportPublicInputsMismatch(input: {
449
+ rollupPublicInputs: readonly Fr[];
450
+ argsPublicInputs: readonly Fr[];
451
+ fromCheckpoint: CheckpointNumber;
452
+ toCheckpoint: CheckpointNumber;
453
+ rollupContract: RollupContract;
454
+ log: Logger;
455
+ }): Promise<Error> {
456
+ const { rollupPublicInputs, argsPublicInputs, fromCheckpoint, toCheckpoint, rollupContract, log } = input;
457
+ const N = MAX_CHECKPOINTS_PER_EPOCH;
458
+ const constantsStart = 3 + 3 * N;
459
+ const blobStart = constantsStart + 5;
460
+ const constantLabels = ['chainId', 'version', 'vkTreeRoot', 'protocolContractsHash', 'proverId'];
461
+
462
+ const diffs: { index: number; label: string; rollup: Fr; computed: Fr; checkpointIndex?: number }[] = [];
463
+ const len = Math.max(rollupPublicInputs.length, argsPublicInputs.length);
464
+ for (let i = 0; i < len; i++) {
465
+ const a = rollupPublicInputs[i] ?? Fr.ZERO;
466
+ const b = argsPublicInputs[i] ?? Fr.ZERO;
467
+ if (a.equals(b)) {
468
+ continue;
469
+ }
470
+ let label: string;
471
+ let checkpointIndex: number | undefined;
472
+ if (i === 0) {
473
+ label = 'previousArchiveRoot';
474
+ } else if (i === 1) {
475
+ label = 'endArchiveRoot';
476
+ } else if (i === 2) {
477
+ label = 'outHash';
478
+ } else if (i < 3 + N) {
479
+ checkpointIndex = i - 3;
480
+ label = `checkpointHeaderHashes[${checkpointIndex}]`;
481
+ } else if (i < 3 + 3 * N) {
482
+ const feePairIndex = i - (3 + N);
483
+ const feeIndex = Math.floor(feePairIndex / 2);
484
+ const sub = feePairIndex % 2 === 0 ? 'recipient' : 'value';
485
+ label = `fees[${feeIndex}].${sub}`;
486
+ } else if (i < blobStart) {
487
+ label = `constants.${constantLabels[i - constantsStart]}`;
488
+ } else {
489
+ label = `blobPublicInputs[${i - blobStart}]`;
490
+ }
491
+ diffs.push({ index: i, label, rollup: a, computed: b, checkpointIndex });
492
+ }
493
+
494
+ // For each mismatching checkpointHeaderHash, fetch the L1 CheckpointLog so the operator can
495
+ // see what was published on-chain alongside the prover's recomputed hash.
496
+ const onChainCheckpoints = await Promise.all(
497
+ diffs
498
+ .filter(d => d.checkpointIndex !== undefined)
499
+ .map(async d => {
500
+ const checkpointNumber = CheckpointNumber(fromCheckpoint + d.checkpointIndex!);
501
+ try {
502
+ const cp = await rollupContract.getCheckpoint(checkpointNumber);
503
+ return { checkpointIndex: d.checkpointIndex!, checkpointNumber, headerHash: cp.headerHash.toString() };
504
+ } catch (err) {
505
+ return { checkpointIndex: d.checkpointIndex!, checkpointNumber, error: (err as Error).message };
506
+ }
507
+ }),
508
+ );
509
+
510
+ log.error(`Root rollup public inputs mismatch`, undefined, {
511
+ fromCheckpoint,
512
+ toCheckpoint,
513
+ numDiffs: diffs.length,
514
+ diffs: diffs.map(d => ({
515
+ index: d.index,
516
+ label: d.label,
517
+ rollup: d.rollup.toString(),
518
+ computed: d.computed.toString(),
519
+ })),
520
+ onChainCheckpoints,
521
+ });
522
+
523
+ const fmt = (inputs: readonly Fr[]) => inputs.map(x => x.toString()).join(', ');
524
+ const summary = diffs.map(d => `[${d.index} ${d.label}] L1=${d.rollup} prover=${d.computed}`).join('\n');
525
+ return new Error(
526
+ `Root rollup public inputs mismatch (${diffs.length} fields differ):\n${summary}\n` +
527
+ `Rollup: ${fmt(rollupPublicInputs)}\nComputed:${fmt(argsPublicInputs)}`,
528
+ );
529
+ }
@@ -1,13 +1,12 @@
1
1
  import type { Archiver } from '@aztec/archiver';
2
2
  import type { RollupContract } from '@aztec/ethereum/contracts';
3
+ import type { Delayer } from '@aztec/ethereum/l1-tx-utils';
3
4
  import { BlockNumber, CheckpointNumber, EpochNumber } from '@aztec/foundation/branded-types';
4
5
  import { assertRequired, compact, pick, sum } from '@aztec/foundation/collection';
5
6
  import type { Fr } from '@aztec/foundation/curves/bn254';
6
7
  import { memoize } from '@aztec/foundation/decorators';
7
8
  import { createLogger } from '@aztec/foundation/log';
8
9
  import { DateProvider } from '@aztec/foundation/timer';
9
- import type { DataStoreConfig } from '@aztec/kv-store/config';
10
- import type { P2PClient } from '@aztec/p2p';
11
10
  import { PublicProcessorFactory } from '@aztec/simulator/server';
12
11
  import type { L2BlockSource } from '@aztec/stdlib/block';
13
12
  import type { Checkpoint } from '@aztec/stdlib/checkpoint';
@@ -17,14 +16,15 @@ import { getProofSubmissionDeadlineTimestamp } from '@aztec/stdlib/epoch-helpers
17
16
  import {
18
17
  type EpochProverManager,
19
18
  EpochProvingJobTerminalState,
19
+ type ITxProvider,
20
20
  type ProverNodeApi,
21
21
  type Service,
22
22
  type WorldStateSyncStatus,
23
23
  type WorldStateSynchronizer,
24
24
  tryStop,
25
25
  } from '@aztec/stdlib/interfaces/server';
26
+ import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
26
27
  import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
27
- import type { P2PClientType } from '@aztec/stdlib/p2p';
28
28
  import type { Tx } from '@aztec/stdlib/tx';
29
29
  import {
30
30
  Attributes,
@@ -55,7 +55,6 @@ type DataStoreOptions = Pick<DataStoreConfig, 'dataDirectory'> & Pick<ChainConfi
55
55
  */
56
56
  export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable {
57
57
  private log = createLogger('prover-node');
58
- private dateProvider = new DateProvider();
59
58
 
60
59
  private jobs: Map<string, EpochProvingJob> = new Map();
61
60
  private config: ProverNodeOptions;
@@ -73,17 +72,19 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
73
72
  protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
74
73
  protected readonly contractDataSource: ContractDataSource,
75
74
  protected readonly worldState: WorldStateSynchronizer,
76
- protected readonly p2pClient: Pick<P2PClient<P2PClientType.Prover>, 'getTxProvider'> & Partial<Service>,
75
+ protected readonly p2pClient: { getTxProvider(): ITxProvider } & Partial<Service>,
77
76
  protected readonly epochsMonitor: EpochMonitor,
78
77
  protected readonly rollupContract: RollupContract,
79
78
  protected readonly l1Metrics: L1Metrics,
80
79
  config: Partial<ProverNodeOptions> = {},
81
80
  protected readonly telemetryClient: TelemetryClient = getTelemetryClient(),
81
+ private delayer?: Delayer,
82
+ private readonly dateProvider: DateProvider = new DateProvider(),
82
83
  ) {
83
84
  this.config = {
84
85
  proverNodePollingIntervalMs: 1_000,
85
86
  proverNodeMaxPendingJobs: 100,
86
- proverNodeMaxParallelBlocksPerEpoch: 32,
87
+ proverNodeMaxParallelBlocksPerEpoch: 0,
87
88
  txGatheringIntervalMs: 1_000,
88
89
  txGatheringBatchSize: 10,
89
90
  txGatheringMaxParallelRequestsPerNode: 100,
@@ -111,6 +112,11 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
111
112
  return this.p2pClient;
112
113
  }
113
114
 
115
+ /** Returns the shared tx delayer for prover L1 txs, if enabled. Test-only. */
116
+ public getDelayer(): Delayer | undefined {
117
+ return this.delayer;
118
+ }
119
+
114
120
  /**
115
121
  * Handles an epoch being completed by starting a proof for it if there are no active jobs for it.
116
122
  * @param epochNumber - The epoch number that was just completed.
@@ -155,17 +161,15 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
155
161
 
156
162
  /**
157
163
  * Stops the prover node and all its dependencies.
164
+ * Resources not owned by this node (shared with the parent aztec-node) are skipped.
158
165
  */
159
166
  async stop() {
160
167
  this.log.info('Stopping ProverNode');
161
168
  await this.epochsMonitor.stop();
162
- await this.prover.stop();
163
- await tryStop(this.p2pClient);
164
- await tryStop(this.l2BlockSource);
165
- await tryStop(this.publisherFactory);
166
169
  this.publisher?.interrupt();
167
170
  await Promise.all(Array.from(this.jobs.values()).map(job => job.stop()));
168
- await this.worldState.stop();
171
+ await this.prover.stop();
172
+ await tryStop(this.publisherFactory);
169
173
  this.rewardsMetrics.stop();
170
174
  this.l1Metrics.stop();
171
175
  await this.telemetryClient.stop();
@@ -275,19 +279,22 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
275
279
  const fromCheckpoint = epochData.checkpoints[0].number;
276
280
  const toCheckpoint = epochData.checkpoints.at(-1)!.number;
277
281
  const fromBlock = epochData.checkpoints[0].blocks[0].number;
278
- const toBlock = epochData.checkpoints.at(-1)!.blocks.at(-1)!.number;
282
+ const lastBlock = epochData.checkpoints.at(-1)!.blocks.at(-1)!;
283
+ const toBlock = lastBlock.number;
279
284
  this.log.verbose(
280
285
  `Creating proving job for epoch ${epochNumber} for checkpoint range ${fromCheckpoint} to ${toCheckpoint} and block range ${fromBlock} to ${toBlock}`,
281
286
  );
282
287
 
283
288
  // Fast forward world state to right before the target block and get a fork
284
- await this.worldState.syncImmediate(toBlock);
289
+ const lastBlockHash = await lastBlock.header.hash();
290
+ await this.worldState.syncImmediate(toBlock, lastBlockHash);
285
291
 
286
292
  // Create a processor factory
287
293
  const publicProcessorFactory = new PublicProcessorFactory(
288
294
  this.contractDataSource,
289
295
  this.dateProvider,
290
296
  this.telemetryClient,
297
+ this.log.getBindings(),
291
298
  );
292
299
 
293
300
  // Set deadline for this job to run. It will abort if it takes too long.
@@ -305,26 +312,21 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
305
312
 
306
313
  @trackSpan('ProverNode.gatherEpochData', epochNumber => ({ [Attributes.EPOCH_NUMBER]: epochNumber }))
307
314
  private async gatherEpochData(epochNumber: EpochNumber): Promise<EpochProvingJobData> {
308
- const checkpoints = await this.gatherCheckpoints(epochNumber);
315
+ const publishedCheckpoints = await this.l2BlockSource.getCheckpoints({ epoch: epochNumber });
316
+ if (publishedCheckpoints.length === 0) {
317
+ throw new EmptyEpochError(epochNumber);
318
+ }
319
+ const checkpoints = publishedCheckpoints.map(p => p.checkpoint);
320
+ const attestations = publishedCheckpoints.at(-1)?.attestations ?? [];
309
321
  const txArray = await this.gatherTxs(epochNumber, checkpoints);
310
322
  const txs = new Map<string, Tx>(txArray.map(tx => [tx.getTxHash().toString(), tx]));
311
323
  const l1ToL2Messages = await this.gatherMessages(epochNumber, checkpoints);
312
324
  const [firstBlock] = checkpoints[0].blocks;
313
325
  const previousBlockHeader = await this.gatherPreviousBlockHeader(epochNumber, firstBlock.number - 1);
314
- const [lastPublishedCheckpoint] = await this.l2BlockSource.getPublishedCheckpoints(checkpoints.at(-1)!.number, 1);
315
- const attestations = lastPublishedCheckpoint?.attestations ?? [];
316
326
 
317
327
  return { checkpoints, txs, l1ToL2Messages, epochNumber, previousBlockHeader, attestations };
318
328
  }
319
329
 
320
- private async gatherCheckpoints(epochNumber: EpochNumber) {
321
- const checkpoints = await this.l2BlockSource.getCheckpointsForEpoch(epochNumber);
322
- if (checkpoints.length === 0) {
323
- throw new EmptyEpochError(epochNumber);
324
- }
325
- return checkpoints;
326
- }
327
-
328
330
  private async gatherTxs(epochNumber: EpochNumber, checkpoints: Checkpoint[]) {
329
331
  const deadline = new Date(this.dateProvider.now() + this.config.txGatheringTimeoutMs);
330
332
  const txProvider = this.p2pClient.getTxProvider();
@@ -353,16 +355,13 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
353
355
  }
354
356
 
355
357
  private async gatherPreviousBlockHeader(epochNumber: EpochNumber, previousBlockNumber: number) {
356
- const header = await (previousBlockNumber === 0
357
- ? this.worldState.getCommitted().getInitialHeader()
358
- : this.l2BlockSource.getBlockHeader(BlockNumber(previousBlockNumber)));
359
-
360
- if (!header) {
358
+ const data = await this.l2BlockSource.getBlockData({ number: BlockNumber(previousBlockNumber) });
359
+ if (!data?.header) {
361
360
  throw new Error(`Previous block header ${previousBlockNumber} not found for proving epoch ${epochNumber}`);
362
361
  }
363
362
 
364
- this.log.verbose(`Gathered previous block header ${header.getBlockNumber()} for epoch ${epochNumber}`);
365
- return header;
363
+ this.log.verbose(`Gathered previous block header ${data.header.getBlockNumber()} for epoch ${epochNumber}`);
364
+ return data.header;
366
365
  }
367
366
 
368
367
  /** Extracted for testing purposes. */
@@ -384,6 +383,7 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
384
383
  this.jobMetrics,
385
384
  deadline,
386
385
  { parallelBlockLimit, skipSubmitProof: proverNodeDisableProofPublish, ...opts },
386
+ this.log.getBindings(),
387
387
  );
388
388
  }
389
389
 
@@ -1,27 +1,29 @@
1
1
  import type { RollupContract } from '@aztec/ethereum/contracts';
2
2
  import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
3
3
  import type { PublisherManager } from '@aztec/ethereum/publisher-manager';
4
- import type { PublisherConfig, TxSenderConfig } from '@aztec/sequencer-client';
4
+ import type { LoggerBindings } from '@aztec/foundation/log';
5
+ import type { ProverPublisherConfig, ProverTxSenderConfig } from '@aztec/sequencer-client';
5
6
  import type { TelemetryClient } from '@aztec/telemetry-client';
6
7
 
7
8
  import { ProverNodePublisher } from './prover-node-publisher.js';
8
9
 
9
10
  export class ProverPublisherFactory {
10
11
  constructor(
11
- private config: TxSenderConfig & PublisherConfig,
12
+ private config: ProverTxSenderConfig & ProverPublisherConfig,
12
13
  private deps: {
13
14
  rollupContract: RollupContract;
14
15
  publisherManager: PublisherManager<L1TxUtils>;
15
16
  telemetry?: TelemetryClient;
16
17
  },
18
+ private bindings?: LoggerBindings,
17
19
  ) {}
18
20
 
19
21
  public async start() {
20
- await this.deps.publisherManager.loadState();
22
+ await this.deps.publisherManager.start();
21
23
  }
22
24
 
23
- public stop() {
24
- this.deps.publisherManager.interrupt();
25
+ public async stop() {
26
+ await this.deps.publisherManager.stop();
25
27
  }
26
28
 
27
29
  /**
@@ -30,10 +32,14 @@ export class ProverPublisherFactory {
30
32
  */
31
33
  public async create(): Promise<ProverNodePublisher> {
32
34
  const l1Publisher = await this.deps.publisherManager.getAvailablePublisher();
33
- return new ProverNodePublisher(this.config, {
34
- rollupContract: this.deps.rollupContract,
35
- l1TxUtils: l1Publisher,
36
- telemetry: this.deps.telemetry,
37
- });
35
+ return new ProverNodePublisher(
36
+ this.config,
37
+ {
38
+ rollupContract: this.deps.rollupContract,
39
+ l1TxUtils: l1Publisher,
40
+ telemetry: this.deps.telemetry,
41
+ },
42
+ this.bindings,
43
+ );
38
44
  }
39
45
  }