@aztec/prover-node 0.0.1-fake-ceab37513c → 0.0.2-commit.217f559981

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 (54) hide show
  1. package/dest/actions/download-epoch-proving-job.d.ts +4 -4
  2. package/dest/actions/index.d.ts +1 -1
  3. package/dest/actions/rerun-epoch-proving-job.d.ts +3 -2
  4. package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -1
  5. package/dest/actions/rerun-epoch-proving-job.js +5 -3
  6. package/dest/actions/upload-epoch-proof-failure.d.ts +1 -1
  7. package/dest/bin/run-failed-epoch.d.ts +1 -1
  8. package/dest/bin/run-failed-epoch.js +5 -2
  9. package/dest/config.d.ts +8 -10
  10. package/dest/config.d.ts.map +1 -1
  11. package/dest/config.js +17 -19
  12. package/dest/factory.d.ts +20 -15
  13. package/dest/factory.d.ts.map +1 -1
  14. package/dest/factory.js +30 -62
  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-data.d.ts +8 -6
  19. package/dest/job/epoch-proving-job-data.d.ts.map +1 -1
  20. package/dest/job/epoch-proving-job-data.js +25 -18
  21. package/dest/job/epoch-proving-job.d.ts +7 -13
  22. package/dest/job/epoch-proving-job.d.ts.map +1 -1
  23. package/dest/job/epoch-proving-job.js +513 -89
  24. package/dest/metrics.d.ts +4 -3
  25. package/dest/metrics.d.ts.map +1 -1
  26. package/dest/metrics.js +30 -98
  27. package/dest/monitors/epoch-monitor.d.ts +3 -2
  28. package/dest/monitors/epoch-monitor.d.ts.map +1 -1
  29. package/dest/monitors/epoch-monitor.js +3 -11
  30. package/dest/monitors/index.d.ts +1 -1
  31. package/dest/prover-node-publisher.d.ts +14 -11
  32. package/dest/prover-node-publisher.d.ts.map +1 -1
  33. package/dest/prover-node-publisher.js +53 -46
  34. package/dest/prover-node.d.ts +26 -15
  35. package/dest/prover-node.d.ts.map +1 -1
  36. package/dest/prover-node.js +441 -57
  37. package/dest/prover-publisher-factory.d.ts +9 -5
  38. package/dest/prover-publisher-factory.d.ts.map +1 -1
  39. package/dest/prover-publisher-factory.js +4 -2
  40. package/dest/test/index.d.ts +1 -1
  41. package/dest/test/index.d.ts.map +1 -1
  42. package/package.json +26 -25
  43. package/src/actions/rerun-epoch-proving-job.ts +5 -3
  44. package/src/bin/run-failed-epoch.ts +5 -2
  45. package/src/config.ts +26 -32
  46. package/src/factory.ts +68 -99
  47. package/src/index.ts +1 -0
  48. package/src/job/epoch-proving-job-data.ts +31 -25
  49. package/src/job/epoch-proving-job.ts +155 -92
  50. package/src/metrics.ts +31 -82
  51. package/src/monitors/epoch-monitor.ts +5 -11
  52. package/src/prover-node-publisher.ts +76 -61
  53. package/src/prover-node.ts +60 -50
  54. package/src/prover-publisher-factory.ts +16 -8
@@ -1,18 +1,13 @@
1
+ import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
1
2
  import { createLogger } from '@aztec/foundation/log';
2
3
  import { RunningPromise } from '@aztec/foundation/running-promise';
3
4
  import { sleep } from '@aztec/foundation/sleep';
4
5
  import type { L2BlockSource } from '@aztec/stdlib/block';
5
6
  import { type L1RollupConstants, getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
6
- import {
7
- type TelemetryClient,
8
- type Traceable,
9
- type Tracer,
10
- getTelemetryClient,
11
- trackSpan,
12
- } from '@aztec/telemetry-client';
7
+ import { type TelemetryClient, type Traceable, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
13
8
 
14
9
  export interface EpochMonitorHandler {
15
- handleEpochReadyToProve(epochNumber: bigint): Promise<boolean>;
10
+ handleEpochReadyToProve(epochNumber: EpochNumber): Promise<boolean>;
16
11
  }
17
12
 
18
13
  /**
@@ -32,7 +27,7 @@ export class EpochMonitor implements Traceable {
32
27
  public readonly tracer: Tracer;
33
28
 
34
29
  private handler: EpochMonitorHandler | undefined;
35
- private latestEpochNumber: bigint | undefined;
30
+ private latestEpochNumber: EpochNumber | undefined;
36
31
 
37
32
  constructor(
38
33
  private readonly l2BlockSource: L2BlockSource,
@@ -72,7 +67,6 @@ export class EpochMonitor implements Traceable {
72
67
  this.log.info('Stopped EpochMonitor');
73
68
  }
74
69
 
75
- @trackSpan('EpochMonitor.work')
76
70
  public async work() {
77
71
  const { epochToProve, blockNumber, slotNumber } = await this.getEpochNumberToProve();
78
72
  this.log.debug(`Epoch to prove: ${epochToProve}`, { blockNumber, slotNumber });
@@ -104,7 +98,7 @@ export class EpochMonitor implements Traceable {
104
98
 
105
99
  private async getEpochNumberToProve() {
106
100
  const lastBlockProven = await this.l2BlockSource.getProvenBlockNumber();
107
- const firstBlockToProve = lastBlockProven + 1;
101
+ const firstBlockToProve = BlockNumber(lastBlockProven + 1);
108
102
  const firstBlockHeaderToProve = await this.l2BlockSource.getBlockHeader(firstBlockToProve);
109
103
  if (!firstBlockHeaderToProve) {
110
104
  return { epochToProve: undefined, blockNumber: firstBlockToProve };
@@ -1,11 +1,13 @@
1
- import { type BatchedBlob, FinalBlobAccumulatorPublicInputs } from '@aztec/blob-lib';
2
- import { AZTEC_MAX_EPOCH_DURATION } from '@aztec/constants';
3
- import type { L1TxUtils, RollupContract, ViemCommitteeAttestation } from '@aztec/ethereum';
1
+ import { BatchedBlob, getEthBlobEvaluationInputs } from '@aztec/blob-lib';
2
+ import { MAX_CHECKPOINTS_PER_EPOCH } from '@aztec/constants';
3
+ import type { RollupContract, ViemCommitteeAttestation } from '@aztec/ethereum/contracts';
4
+ import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
4
5
  import { makeTuple } from '@aztec/foundation/array';
6
+ import { CheckpointNumber, EpochNumber } from '@aztec/foundation/branded-types';
5
7
  import { areArraysEqual } from '@aztec/foundation/collection';
8
+ import { Fr } from '@aztec/foundation/curves/bn254';
6
9
  import { EthAddress } from '@aztec/foundation/eth-address';
7
- import { Fr } from '@aztec/foundation/fields';
8
- import { createLogger } from '@aztec/foundation/log';
10
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
9
11
  import type { Tuple } from '@aztec/foundation/serialize';
10
12
  import { Timer } from '@aztec/foundation/timer';
11
13
  import { RollupAbi } from '@aztec/l1-artifacts';
@@ -29,7 +31,7 @@ export type L1SubmitEpochProofArgs = {
29
31
  endTimestamp: Fr;
30
32
  outHash: Fr;
31
33
  proverId: Fr;
32
- fees: Tuple<FeeRecipient, typeof AZTEC_MAX_EPOCH_DURATION>;
34
+ fees: Tuple<FeeRecipient, typeof MAX_CHECKPOINTS_PER_EPOCH>;
33
35
  proof: Proof;
34
36
  };
35
37
 
@@ -37,7 +39,7 @@ export class ProverNodePublisher {
37
39
  private interrupted = false;
38
40
  private metrics: ProverNodePublisherMetrics;
39
41
 
40
- protected log = createLogger('prover-node:l1-tx-publisher');
42
+ protected log: Logger;
41
43
 
42
44
  protected rollupContract: RollupContract;
43
45
 
@@ -50,10 +52,12 @@ export class ProverNodePublisher {
50
52
  l1TxUtils: L1TxUtils;
51
53
  telemetry?: TelemetryClient;
52
54
  },
55
+ bindings?: LoggerBindings,
53
56
  ) {
54
57
  const telemetry = deps.telemetry ?? getTelemetryClient();
55
58
 
56
59
  this.metrics = new ProverNodePublisherMetrics(telemetry, 'ProverNode');
60
+ this.log = createLogger('prover-node:l1-tx-publisher', bindings);
57
61
 
58
62
  this.rollupContract = deps.rollupContract;
59
63
  this.l1TxUtils = deps.l1TxUtils;
@@ -85,16 +89,17 @@ export class ProverNodePublisher {
85
89
  }
86
90
 
87
91
  public async submitEpochProof(args: {
88
- epochNumber: number;
89
- fromBlock: number;
90
- toBlock: number;
92
+ epochNumber: EpochNumber;
93
+ fromCheckpoint: CheckpointNumber;
94
+ toCheckpoint: CheckpointNumber;
91
95
  publicInputs: RootRollupPublicInputs;
92
96
  proof: Proof;
93
97
  batchedBlobInputs: BatchedBlob;
94
98
  attestations: ViemCommitteeAttestation[];
95
99
  }): Promise<boolean> {
96
- const { epochNumber, fromBlock, toBlock } = args;
97
- const ctx = { epochNumber, fromBlock, toBlock };
100
+ const { epochNumber, fromCheckpoint, toCheckpoint } = args;
101
+ const ctx = { epochNumber, fromCheckpoint, toCheckpoint };
102
+
98
103
  if (!this.interrupted) {
99
104
  const timer = new Timer();
100
105
  // Validate epoch proof range and hashes are correct before submitting
@@ -102,6 +107,7 @@ export class ProverNodePublisher {
102
107
 
103
108
  const txReceipt = await this.sendSubmitEpochProofTx(args);
104
109
  if (!txReceipt) {
110
+ this.log.error(`Failed to mine submitEpochProof tx`, undefined, ctx);
105
111
  return false;
106
112
  }
107
113
 
@@ -134,54 +140,59 @@ export class ProverNodePublisher {
134
140
  }
135
141
 
136
142
  this.metrics.recordFailedTx();
137
- this.log.error(`Rollup.submitEpochProof tx status failed ${txReceipt.transactionHash}`, undefined, ctx);
143
+ this.log.error(`Rollup submitEpochProof tx reverted ${txReceipt.transactionHash}`, undefined, ctx);
138
144
  }
139
145
 
140
- this.log.verbose('L2 block data syncing interrupted', ctx);
146
+ this.log.verbose('Checkpoint data syncing interrupted', ctx);
141
147
  return false;
142
148
  }
143
149
 
144
150
  private async validateEpochProofSubmission(args: {
145
- fromBlock: number;
146
- toBlock: number;
151
+ fromCheckpoint: CheckpointNumber;
152
+ toCheckpoint: CheckpointNumber;
147
153
  publicInputs: RootRollupPublicInputs;
148
154
  proof: Proof;
149
155
  batchedBlobInputs: BatchedBlob;
150
156
  attestations: ViemCommitteeAttestation[];
151
157
  }) {
152
- const { fromBlock, toBlock, publicInputs, batchedBlobInputs } = args;
158
+ const { fromCheckpoint, toCheckpoint, publicInputs, batchedBlobInputs } = args;
153
159
 
154
- // Check that the block numbers match the expected epoch to be proven
155
- const { pendingBlockNumber: pending, provenBlockNumber: proven } = await this.rollupContract.getTips();
156
- // Don't publish if proven is beyond our toBlock, pointless to do so
157
- if (proven > BigInt(toBlock)) {
158
- throw new Error(`Cannot submit epoch proof for ${fromBlock}-${toBlock} as proven block is ${proven}`);
160
+ // Check that the checkpoint numbers match the expected epoch to be proven
161
+ const { pending, proven } = await this.rollupContract.getTips();
162
+ // Don't publish if proven is beyond our toCheckpoint, pointless to do so
163
+ if (proven > toCheckpoint) {
164
+ throw new Error(
165
+ `Cannot submit epoch proof for ${fromCheckpoint}-${toCheckpoint} as proven checkpoint is ${proven}`,
166
+ );
159
167
  }
160
- // toBlock can't be greater than pending
161
- if (toBlock > pending) {
162
- throw new Error(`Cannot submit epoch proof for ${fromBlock}-${toBlock} as pending block is ${pending}`);
168
+ // toCheckpoint can't be greater than pending
169
+ if (toCheckpoint > pending) {
170
+ throw new Error(
171
+ `Cannot submit epoch proof for ${fromCheckpoint}-${toCheckpoint} as pending checkpoint is ${pending}`,
172
+ );
163
173
  }
164
174
 
165
- // Check the archive for the immediate block before the epoch
166
- const blockLog = await this.rollupContract.getBlock(BigInt(fromBlock - 1));
167
- if (publicInputs.previousArchiveRoot.toString() !== blockLog.archive) {
175
+ // Check the archive for the immediate checkpoint before the epoch
176
+ const checkpointLog = await this.rollupContract.getCheckpoint(CheckpointNumber(fromCheckpoint - 1));
177
+ if (!publicInputs.previousArchiveRoot.equals(checkpointLog.archive)) {
168
178
  throw new Error(
169
- `Previous archive root mismatch: ${publicInputs.previousArchiveRoot.toString()} !== ${blockLog.archive}`,
179
+ `Previous archive root mismatch: ${publicInputs.previousArchiveRoot.toString()} !== ${checkpointLog.archive.toString()}`,
170
180
  );
171
181
  }
172
182
 
173
- // Check the archive for the last block in the epoch
174
- const endBlockLog = await this.rollupContract.getBlock(BigInt(toBlock));
175
- if (publicInputs.endArchiveRoot.toString() !== endBlockLog.archive) {
183
+ // Check the archive for the last checkpoint in the epoch
184
+ const endCheckpointLog = await this.rollupContract.getCheckpoint(toCheckpoint);
185
+ if (!publicInputs.endArchiveRoot.equals(endCheckpointLog.archive)) {
176
186
  throw new Error(
177
- `End archive root mismatch: ${publicInputs.endArchiveRoot.toString()} !== ${endBlockLog.archive}`,
187
+ `End archive root mismatch: ${publicInputs.endArchiveRoot.toString()} !== ${endCheckpointLog.archive.toString()}`,
178
188
  );
179
189
  }
180
190
 
181
191
  // Check the batched blob inputs from the root rollup against the batched blob computed in ts
182
- if (!publicInputs.blobPublicInputs.equals(FinalBlobAccumulatorPublicInputs.fromBatchedBlob(batchedBlobInputs))) {
192
+ const finalBlobAccumulator = batchedBlobInputs.toFinalBlobAccumulator();
193
+ if (!publicInputs.blobPublicInputs.equals(finalBlobAccumulator)) {
183
194
  throw new Error(
184
- `Batched blob mismatch: ${inspect(publicInputs.blobPublicInputs)} !== ${inspect(FinalBlobAccumulatorPublicInputs.fromBatchedBlob(batchedBlobInputs))}`,
195
+ `Batched blob mismatch: ${inspect(publicInputs.blobPublicInputs)} !== ${inspect(finalBlobAccumulator)}`,
185
196
  );
186
197
  }
187
198
 
@@ -191,7 +202,7 @@ export class ProverNodePublisher {
191
202
  );
192
203
  const argsPublicInputs = [...publicInputs.toFields()];
193
204
 
194
- if (!areArraysEqual(rollupPublicInputs.map(Fr.fromHexString), argsPublicInputs, (a, b) => a.equals(b))) {
205
+ if (!areArraysEqual(rollupPublicInputs, argsPublicInputs, (a, b) => a.equals(b))) {
195
206
  const fmt = (inputs: Fr[] | readonly string[]) => inputs.map(x => x.toString()).join(', ');
196
207
  throw new Error(
197
208
  `Root rollup public inputs mismatch:\nRollup: ${fmt(rollupPublicInputs)}\nComputed:${fmt(argsPublicInputs)}`,
@@ -200,8 +211,8 @@ export class ProverNodePublisher {
200
211
  }
201
212
 
202
213
  private async sendSubmitEpochProofTx(args: {
203
- fromBlock: number;
204
- toBlock: number;
214
+ fromCheckpoint: CheckpointNumber;
215
+ toCheckpoint: CheckpointNumber;
205
216
  publicInputs: RootRollupPublicInputs;
206
217
  proof: Proof;
207
218
  batchedBlobInputs: BatchedBlob;
@@ -211,8 +222,8 @@ export class ProverNodePublisher {
211
222
 
212
223
  this.log.info(`Submitting epoch proof to L1 rollup contract`, {
213
224
  proofSize: args.proof.withoutPublicInputs().length,
214
- fromBlock: args.fromBlock,
215
- toBlock: args.toBlock,
225
+ fromCheckpoint: args.fromCheckpoint,
226
+ toCheckpoint: args.toCheckpoint,
216
227
  });
217
228
  const data = encodeFunctionData({
218
229
  abi: RollupAbi,
@@ -221,53 +232,57 @@ export class ProverNodePublisher {
221
232
  });
222
233
  try {
223
234
  const { receipt } = await this.l1TxUtils.sendAndMonitorTransaction({ to: this.rollupContract.address, data });
235
+ if (receipt.status !== 'success') {
236
+ const errorMsg = await this.l1TxUtils.tryGetErrorFromRevertedTx(
237
+ data,
238
+ {
239
+ args: [...txArgs],
240
+ functionName: 'submitEpochRootProof',
241
+ abi: RollupAbi,
242
+ address: this.rollupContract.address,
243
+ },
244
+ /*blobInputs*/ undefined,
245
+ /*stateOverride*/ [],
246
+ );
247
+ this.log.error(`Rollup submit epoch proof tx reverted with ${errorMsg ?? 'unknown error'}`);
248
+ return undefined;
249
+ }
224
250
  return receipt;
225
251
  } catch (err) {
226
252
  this.log.error(`Rollup submit epoch proof failed`, err);
227
- const errorMsg = await this.l1TxUtils.tryGetErrorFromRevertedTx(
228
- data,
229
- {
230
- args: [...txArgs],
231
- functionName: 'submitEpochRootProof',
232
- abi: RollupAbi,
233
- address: this.rollupContract.address,
234
- },
235
- /*blobInputs*/ undefined,
236
- /*stateOverride*/ [],
237
- );
238
- this.log.error(`Rollup submit epoch proof tx reverted. ${errorMsg}`);
239
253
  return undefined;
240
254
  }
241
255
  }
242
256
 
243
257
  private getEpochProofPublicInputsArgs(args: {
244
- fromBlock: number;
245
- toBlock: number;
258
+ fromCheckpoint: CheckpointNumber;
259
+ toCheckpoint: CheckpointNumber;
246
260
  publicInputs: RootRollupPublicInputs;
247
261
  batchedBlobInputs: BatchedBlob;
248
262
  attestations: ViemCommitteeAttestation[];
249
263
  }) {
250
264
  // Returns arguments for EpochProofLib.sol -> getEpochProofPublicInputs()
251
265
  return [
252
- BigInt(args.fromBlock) /*_start*/,
253
- BigInt(args.toBlock) /*_end*/,
266
+ BigInt(args.fromCheckpoint) /*_start*/,
267
+ BigInt(args.toCheckpoint) /*_end*/,
254
268
  {
255
269
  previousArchive: args.publicInputs.previousArchiveRoot.toString(),
256
270
  endArchive: args.publicInputs.endArchiveRoot.toString(),
257
- proverId: EthAddress.fromField(args.publicInputs.proverId).toString(),
271
+ outHash: args.publicInputs.outHash.toString(),
272
+ proverId: EthAddress.fromField(args.publicInputs.constants.proverId).toString(),
258
273
  } /*_args*/,
259
- makeTuple(AZTEC_MAX_EPOCH_DURATION * 2, i =>
274
+ makeTuple(MAX_CHECKPOINTS_PER_EPOCH * 2, i =>
260
275
  i % 2 === 0
261
276
  ? args.publicInputs.fees[i / 2].recipient.toField().toString()
262
277
  : args.publicInputs.fees[(i - 1) / 2].value.toString(),
263
278
  ) /*_fees*/,
264
- args.batchedBlobInputs.getEthBlobEvaluationInputs() /*_blobPublicInputs*/,
279
+ getEthBlobEvaluationInputs(args.batchedBlobInputs) /*_blobPublicInputs*/,
265
280
  ] as const;
266
281
  }
267
282
 
268
283
  private getSubmitEpochProofArgs(args: {
269
- fromBlock: number;
270
- toBlock: number;
284
+ fromCheckpoint: CheckpointNumber;
285
+ toCheckpoint: CheckpointNumber;
271
286
  publicInputs: RootRollupPublicInputs;
272
287
  proof: Proof;
273
288
  batchedBlobInputs: BatchedBlob;
@@ -1,20 +1,23 @@
1
1
  import type { Archiver } from '@aztec/archiver';
2
- import type { RollupContract } from '@aztec/ethereum';
2
+ import type { RollupContract } from '@aztec/ethereum/contracts';
3
+ import type { Delayer } from '@aztec/ethereum/l1-tx-utils';
4
+ import { BlockNumber, CheckpointNumber, EpochNumber } from '@aztec/foundation/branded-types';
3
5
  import { assertRequired, compact, pick, sum } from '@aztec/foundation/collection';
6
+ import type { Fr } from '@aztec/foundation/curves/bn254';
4
7
  import { memoize } from '@aztec/foundation/decorators';
5
- import type { Fr } from '@aztec/foundation/fields';
6
8
  import { createLogger } from '@aztec/foundation/log';
7
9
  import { DateProvider } from '@aztec/foundation/timer';
8
10
  import type { DataStoreConfig } from '@aztec/kv-store/config';
9
- import type { P2PClient } from '@aztec/p2p';
10
11
  import { PublicProcessorFactory } from '@aztec/simulator/server';
11
- import type { L2Block, L2BlockSource } from '@aztec/stdlib/block';
12
+ import type { L2BlockSource } from '@aztec/stdlib/block';
13
+ import type { Checkpoint } from '@aztec/stdlib/checkpoint';
12
14
  import type { ChainConfig } from '@aztec/stdlib/config';
13
15
  import type { ContractDataSource } from '@aztec/stdlib/contract';
14
16
  import { getProofSubmissionDeadlineTimestamp } from '@aztec/stdlib/epoch-helpers';
15
17
  import {
16
18
  type EpochProverManager,
17
19
  EpochProvingJobTerminalState,
20
+ type ITxProvider,
18
21
  type ProverNodeApi,
19
22
  type Service,
20
23
  type WorldStateSyncStatus,
@@ -22,7 +25,6 @@ import {
22
25
  tryStop,
23
26
  } from '@aztec/stdlib/interfaces/server';
24
27
  import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
25
- import type { P2PClientType } from '@aztec/stdlib/p2p';
26
28
  import type { Tx } from '@aztec/stdlib/tx';
27
29
  import {
28
30
  Attributes,
@@ -53,7 +55,6 @@ type DataStoreOptions = Pick<DataStoreConfig, 'dataDirectory'> & Pick<ChainConfi
53
55
  */
54
56
  export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable {
55
57
  private log = createLogger('prover-node');
56
- private dateProvider = new DateProvider();
57
58
 
58
59
  private jobs: Map<string, EpochProvingJob> = new Map();
59
60
  private config: ProverNodeOptions;
@@ -71,12 +72,14 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
71
72
  protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
72
73
  protected readonly contractDataSource: ContractDataSource,
73
74
  protected readonly worldState: WorldStateSynchronizer,
74
- protected readonly p2pClient: Pick<P2PClient<P2PClientType.Prover>, 'getTxProvider'> & Partial<Service>,
75
+ protected readonly p2pClient: { getTxProvider(): ITxProvider } & Partial<Service>,
75
76
  protected readonly epochsMonitor: EpochMonitor,
76
77
  protected readonly rollupContract: RollupContract,
77
78
  protected readonly l1Metrics: L1Metrics,
78
79
  config: Partial<ProverNodeOptions> = {},
79
80
  protected readonly telemetryClient: TelemetryClient = getTelemetryClient(),
81
+ private delayer?: Delayer,
82
+ private readonly dateProvider: DateProvider = new DateProvider(),
80
83
  ) {
81
84
  this.config = {
82
85
  proverNodePollingIntervalMs: 1_000,
@@ -109,12 +112,17 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
109
112
  return this.p2pClient;
110
113
  }
111
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
+
112
120
  /**
113
121
  * Handles an epoch being completed by starting a proof for it if there are no active jobs for it.
114
122
  * @param epochNumber - The epoch number that was just completed.
115
123
  * @returns false if there is an error, true otherwise
116
124
  */
117
- async handleEpochReadyToProve(epochNumber: bigint): Promise<boolean> {
125
+ async handleEpochReadyToProve(epochNumber: EpochNumber): Promise<boolean> {
118
126
  try {
119
127
  this.log.debug(`Running jobs as ${epochNumber} is ready to prove`, {
120
128
  jobs: Array.from(this.jobs.values()).map(job => `${job.getEpochNumber()}:${job.getId()}`),
@@ -153,17 +161,15 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
153
161
 
154
162
  /**
155
163
  * Stops the prover node and all its dependencies.
164
+ * Resources not owned by this node (shared with the parent aztec-node) are skipped.
156
165
  */
157
166
  async stop() {
158
167
  this.log.info('Stopping ProverNode');
159
168
  await this.epochsMonitor.stop();
160
169
  await this.prover.stop();
161
- await tryStop(this.p2pClient);
162
- await tryStop(this.l2BlockSource);
163
170
  await tryStop(this.publisherFactory);
164
171
  this.publisher?.interrupt();
165
172
  await Promise.all(Array.from(this.jobs.values()).map(job => job.stop()));
166
- await this.worldState.stop();
167
173
  this.rewardsMetrics.stop();
168
174
  this.l1Metrics.stop();
169
175
  await this.telemetryClient.stop();
@@ -184,8 +190,8 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
184
190
  /**
185
191
  * Starts a proving process and returns immediately.
186
192
  */
187
- public async startProof(epochNumber: number | bigint) {
188
- const job = await this.createProvingJob(BigInt(epochNumber), { skipEpochCheck: true });
193
+ public async startProof(epochNumber: EpochNumber) {
194
+ const job = await this.createProvingJob(epochNumber, { skipEpochCheck: true });
189
195
  void this.runJob(job);
190
196
  }
191
197
 
@@ -238,21 +244,20 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
238
244
  /**
239
245
  * Returns an array of jobs being processed.
240
246
  */
241
- public getJobs(): Promise<{ uuid: string; status: EpochProvingJobState; epochNumber: number }[]> {
247
+ public getJobs(): Promise<{ uuid: string; status: EpochProvingJobState; epochNumber: EpochNumber }[]> {
242
248
  return Promise.resolve(
243
249
  Array.from(this.jobs.entries()).map(([uuid, job]) => ({
244
250
  uuid,
245
251
  status: job.getState(),
246
- epochNumber: Number(job.getEpochNumber()),
252
+ epochNumber: job.getEpochNumber(),
247
253
  })),
248
254
  );
249
255
  }
250
256
 
251
257
  protected async getActiveJobsForEpoch(
252
- epochBigInt: bigint,
258
+ epochNumber: EpochNumber,
253
259
  ): Promise<{ uuid: string; status: EpochProvingJobState }[]> {
254
260
  const jobs = await this.getJobs();
255
- const epochNumber = Number(epochBigInt);
256
261
  return jobs.filter(job => job.epochNumber === epochNumber && !EpochProvingJobTerminalState.includes(job.status));
257
262
  }
258
263
 
@@ -263,18 +268,21 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
263
268
  }
264
269
  }
265
270
 
266
- @trackSpan('ProverNode.createProvingJob', epochNumber => ({ [Attributes.EPOCH_NUMBER]: Number(epochNumber) }))
267
- private async createProvingJob(epochNumber: bigint, opts: { skipEpochCheck?: boolean } = {}) {
271
+ @trackSpan('ProverNode.createProvingJob', epochNumber => ({ [Attributes.EPOCH_NUMBER]: epochNumber }))
272
+ private async createProvingJob(epochNumber: EpochNumber, opts: { skipEpochCheck?: boolean } = {}) {
268
273
  this.checkMaximumPendingJobs();
269
274
 
270
275
  this.publisher = await this.publisherFactory.create();
271
276
 
272
277
  // Gather all data for this epoch
273
278
  const epochData = await this.gatherEpochData(epochNumber);
274
-
275
- const fromBlock = epochData.blocks[0].number;
276
- const toBlock = epochData.blocks.at(-1)!.number;
277
- this.log.verbose(`Creating proving job for epoch ${epochNumber} for block range ${fromBlock} to ${toBlock}`);
279
+ const fromCheckpoint = epochData.checkpoints[0].number;
280
+ const toCheckpoint = epochData.checkpoints.at(-1)!.number;
281
+ const fromBlock = epochData.checkpoints[0].blocks[0].number;
282
+ const toBlock = epochData.checkpoints.at(-1)!.blocks.at(-1)!.number;
283
+ this.log.verbose(
284
+ `Creating proving job for epoch ${epochNumber} for checkpoint range ${fromCheckpoint} to ${toCheckpoint} and block range ${fromBlock} to ${toBlock}`,
285
+ );
278
286
 
279
287
  // Fast forward world state to right before the target block and get a fork
280
288
  await this.worldState.syncImmediate(toBlock);
@@ -284,12 +292,12 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
284
292
  this.contractDataSource,
285
293
  this.dateProvider,
286
294
  this.telemetryClient,
295
+ this.log.getBindings(),
287
296
  );
288
297
 
289
298
  // Set deadline for this job to run. It will abort if it takes too long.
290
299
  const deadlineTs = getProofSubmissionDeadlineTimestamp(epochNumber, await this.getL1Constants());
291
300
  const deadline = new Date(Number(deadlineTs) * 1000);
292
-
293
301
  const job = this.doCreateEpochProvingJob(epochData, deadline, publicProcessorFactory, this.publisher, opts);
294
302
  this.jobs.set(job.getId(), job);
295
303
  return job;
@@ -300,30 +308,32 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
300
308
  return this.l2BlockSource.getL1Constants();
301
309
  }
302
310
 
303
- @trackSpan('ProverNode.gatherEpochData', epochNumber => ({ [Attributes.EPOCH_NUMBER]: Number(epochNumber) }))
304
- private async gatherEpochData(epochNumber: bigint): Promise<EpochProvingJobData> {
305
- const blocks = await this.gatherBlocks(epochNumber);
306
- const txArray = await this.gatherTxs(epochNumber, blocks);
311
+ @trackSpan('ProverNode.gatherEpochData', epochNumber => ({ [Attributes.EPOCH_NUMBER]: epochNumber }))
312
+ private async gatherEpochData(epochNumber: EpochNumber): Promise<EpochProvingJobData> {
313
+ const checkpoints = await this.gatherCheckpoints(epochNumber);
314
+ const txArray = await this.gatherTxs(epochNumber, checkpoints);
307
315
  const txs = new Map<string, Tx>(txArray.map(tx => [tx.getTxHash().toString(), tx]));
308
- const l1ToL2Messages = await this.gatherMessages(epochNumber, blocks);
309
- const previousBlockHeader = await this.gatherPreviousBlockHeader(epochNumber, blocks[0]);
310
- const [lastBlock] = await this.l2BlockSource.getPublishedBlocks(blocks.at(-1)!.number, 1);
311
- const attestations = lastBlock?.attestations ?? [];
316
+ const l1ToL2Messages = await this.gatherMessages(epochNumber, checkpoints);
317
+ const [firstBlock] = checkpoints[0].blocks;
318
+ const previousBlockHeader = await this.gatherPreviousBlockHeader(epochNumber, firstBlock.number - 1);
319
+ const [lastPublishedCheckpoint] = await this.l2BlockSource.getCheckpoints(checkpoints.at(-1)!.number, 1);
320
+ const attestations = lastPublishedCheckpoint?.attestations ?? [];
312
321
 
313
- return { blocks, txs, l1ToL2Messages, epochNumber, previousBlockHeader, attestations };
322
+ return { checkpoints, txs, l1ToL2Messages, epochNumber, previousBlockHeader, attestations };
314
323
  }
315
324
 
316
- private async gatherBlocks(epochNumber: bigint) {
317
- const blocks = await this.l2BlockSource.getBlocksForEpoch(epochNumber);
318
- if (blocks.length === 0) {
325
+ private async gatherCheckpoints(epochNumber: EpochNumber) {
326
+ const checkpoints = await this.l2BlockSource.getCheckpointsForEpoch(epochNumber);
327
+ if (checkpoints.length === 0) {
319
328
  throw new EmptyEpochError(epochNumber);
320
329
  }
321
- return blocks;
330
+ return checkpoints;
322
331
  }
323
332
 
324
- private async gatherTxs(epochNumber: bigint, blocks: L2Block[]) {
333
+ private async gatherTxs(epochNumber: EpochNumber, checkpoints: Checkpoint[]) {
325
334
  const deadline = new Date(this.dateProvider.now() + this.config.txGatheringTimeoutMs);
326
335
  const txProvider = this.p2pClient.getTxProvider();
336
+ const blocks = checkpoints.flatMap(checkpoint => checkpoint.blocks);
327
337
  const txsByBlock = await Promise.all(blocks.map(block => txProvider.getTxsForBlock(block, { deadline })));
328
338
  const txs = txsByBlock.map(({ txs }) => txs).flat();
329
339
  const missingTxs = txsByBlock.map(({ missingTxs }) => missingTxs).flat();
@@ -336,25 +346,24 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
336
346
  throw new Error(`Txs not found for epoch ${epochNumber}: ${missingTxs.map(hash => hash.toString()).join(', ')}`);
337
347
  }
338
348
 
339
- private async gatherMessages(epochNumber: bigint, blocks: L2Block[]) {
340
- const messages = await Promise.all(blocks.map(b => this.l1ToL2MessageSource.getL1ToL2Messages(b.number)));
349
+ private async gatherMessages(epochNumber: EpochNumber, checkpoints: Checkpoint[]) {
350
+ const messages = await Promise.all(checkpoints.map(c => this.l1ToL2MessageSource.getL1ToL2Messages(c.number)));
341
351
  const messageCount = sum(messages.map(m => m.length));
342
352
  this.log.verbose(`Gathered all ${messageCount} messages for epoch ${epochNumber}`, { epochNumber });
343
- const messagesByBlock: Record<number, Fr[]> = {};
344
- for (let i = 0; i < blocks.length; i++) {
345
- messagesByBlock[blocks[i].number] = messages[i];
353
+ const messagesByCheckpoint: Record<CheckpointNumber, Fr[]> = {};
354
+ for (let i = 0; i < checkpoints.length; i++) {
355
+ messagesByCheckpoint[checkpoints[i].number] = messages[i];
346
356
  }
347
- return messagesByBlock;
357
+ return messagesByCheckpoint;
348
358
  }
349
359
 
350
- private async gatherPreviousBlockHeader(epochNumber: bigint, initialBlock: L2Block) {
351
- const previousBlockNumber = initialBlock.number - 1;
360
+ private async gatherPreviousBlockHeader(epochNumber: EpochNumber, previousBlockNumber: number) {
352
361
  const header = await (previousBlockNumber === 0
353
362
  ? this.worldState.getCommitted().getInitialHeader()
354
- : this.l2BlockSource.getBlockHeader(previousBlockNumber));
363
+ : this.l2BlockSource.getBlockHeader(BlockNumber(previousBlockNumber)));
355
364
 
356
365
  if (!header) {
357
- throw new Error(`Previous block header ${initialBlock.number} not found for proving epoch ${epochNumber}`);
366
+ throw new Error(`Previous block header ${previousBlockNumber} not found for proving epoch ${epochNumber}`);
358
367
  }
359
368
 
360
369
  this.log.verbose(`Gathered previous block header ${header.getBlockNumber()} for epoch ${epochNumber}`);
@@ -380,6 +389,7 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
380
389
  this.jobMetrics,
381
390
  deadline,
382
391
  { parallelBlockLimit, skipSubmitProof: proverNodeDisableProofPublish, ...opts },
392
+ this.log.getBindings(),
383
393
  );
384
394
  }
385
395
 
@@ -391,7 +401,7 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
391
401
  private validateConfig() {
392
402
  if (
393
403
  this.config.proverNodeFailedEpochStore &&
394
- (!this.config.dataDirectory || !this.config.l1ChainId || !this.config.rollupVersion)
404
+ (!this.config.dataDirectory || !this.config.l1ChainId || this.config.rollupVersion === undefined)
395
405
  ) {
396
406
  this.log.warn(
397
407
  `Invalid prover-node config (missing dataDirectory, l1ChainId, or rollupVersion)`,
@@ -405,7 +415,7 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
405
415
  }
406
416
 
407
417
  class EmptyEpochError extends Error {
408
- constructor(epochNumber: bigint) {
418
+ constructor(epochNumber: EpochNumber) {
409
419
  super(`No blocks found for epoch ${epochNumber}`);
410
420
  this.name = 'EmptyEpochError';
411
421
  }
@@ -1,17 +1,21 @@
1
- import type { L1TxUtils, PublisherManager, RollupContract } from '@aztec/ethereum';
2
- import type { PublisherConfig, TxSenderConfig } from '@aztec/sequencer-client';
1
+ import type { RollupContract } from '@aztec/ethereum/contracts';
2
+ import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
3
+ import type { PublisherManager } from '@aztec/ethereum/publisher-manager';
4
+ import type { LoggerBindings } from '@aztec/foundation/log';
5
+ import type { ProverPublisherConfig, ProverTxSenderConfig } from '@aztec/sequencer-client';
3
6
  import type { TelemetryClient } from '@aztec/telemetry-client';
4
7
 
5
8
  import { ProverNodePublisher } from './prover-node-publisher.js';
6
9
 
7
10
  export class ProverPublisherFactory {
8
11
  constructor(
9
- private config: TxSenderConfig & PublisherConfig,
12
+ private config: ProverTxSenderConfig & ProverPublisherConfig,
10
13
  private deps: {
11
14
  rollupContract: RollupContract;
12
15
  publisherManager: PublisherManager<L1TxUtils>;
13
16
  telemetry?: TelemetryClient;
14
17
  },
18
+ private bindings?: LoggerBindings,
15
19
  ) {}
16
20
 
17
21
  public async start() {
@@ -28,10 +32,14 @@ export class ProverPublisherFactory {
28
32
  */
29
33
  public async create(): Promise<ProverNodePublisher> {
30
34
  const l1Publisher = await this.deps.publisherManager.getAvailablePublisher();
31
- return new ProverNodePublisher(this.config, {
32
- rollupContract: this.deps.rollupContract,
33
- l1TxUtils: l1Publisher,
34
- telemetry: this.deps.telemetry,
35
- });
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
+ );
36
44
  }
37
45
  }