@aztec/prover-node 0.0.1-commit.993d240 → 0.0.1-commit.9a89641

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 +572 -0
  2. package/dest/actions/rerun-epoch-proving-job.d.ts +12 -3
  3. package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -1
  4. package/dest/actions/rerun-epoch-proving-job.js +240 -20
  5. package/dest/checkpoint-store.d.ts +95 -0
  6. package/dest/checkpoint-store.d.ts.map +1 -0
  7. package/dest/checkpoint-store.js +178 -0
  8. package/dest/config.d.ts +3 -1
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +8 -1
  11. package/dest/factory.d.ts +4 -1
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +2 -6
  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 +165 -0
  18. package/dest/job/checkpoint-prover.d.ts.map +1 -0
  19. package/dest/job/checkpoint-prover.js +405 -0
  20. package/dest/job/epoch-session.d.ts +160 -0
  21. package/dest/job/epoch-session.d.ts.map +1 -0
  22. package/dest/job/epoch-session.js +744 -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 +10 -19
  33. package/dest/prover-node-publisher.d.ts.map +1 -1
  34. package/dest/prover-node-publisher.js +43 -99
  35. package/dest/prover-node.d.ts +133 -65
  36. package/dest/prover-node.d.ts.map +1 -1
  37. package/dest/prover-node.js +531 -212
  38. package/dest/prover-publisher-factory.d.ts +3 -1
  39. package/dest/prover-publisher-factory.d.ts.map +1 -1
  40. package/dest/prover-publisher-factory.js +1 -0
  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 +492 -0
  44. package/dest/test/index.d.ts +7 -6
  45. package/dest/test/index.d.ts.map +1 -1
  46. package/package.json +24 -23
  47. package/src/actions/rerun-epoch-proving-job.ts +177 -29
  48. package/src/checkpoint-store.ts +212 -0
  49. package/src/config.ts +12 -1
  50. package/src/factory.ts +5 -8
  51. package/src/index.ts +1 -0
  52. package/src/job/checkpoint-prover.ts +538 -0
  53. package/src/job/epoch-session.ts +462 -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 +58 -123
  58. package/src/prover-node.ts +618 -233
  59. package/src/prover-publisher-factory.ts +3 -0
  60. package/src/session-manager.ts +592 -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,31 +1,130 @@
1
1
  import { createArchiverStore, createContractDataSource } from '@aztec/archiver';
2
2
  import type { L1ContractsConfig } from '@aztec/ethereum/config';
3
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
4
  import type { Logger } from '@aztec/foundation/log';
5
+ import { DateProvider } from '@aztec/foundation/timer';
4
6
  import { type ProverClientConfig, createProverClient } from '@aztec/prover-client';
5
7
  import { ProverBrokerConfig, createAndStartProvingBroker } from '@aztec/prover-client/broker';
6
- import { PublicProcessorFactory } from '@aztec/simulator/server';
8
+ import { getLastSiblingPath } from '@aztec/prover-client/helpers';
9
+ import { ChonkCache } from '@aztec/prover-client/orchestrator';
10
+ import { AvmSimulatorPool, PublicProcessorFactory } from '@aztec/simulator/server';
11
+ import type { L2Block } from '@aztec/stdlib/block';
12
+ import { getEpochAtSlot, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
13
+ import type { ITxProvider } from '@aztec/stdlib/interfaces/server';
7
14
  import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
15
+ import { MerkleTreeId } from '@aztec/stdlib/trees';
16
+ import type { Tx, TxHash } from '@aztec/stdlib/tx';
8
17
  import type { GenesisData } from '@aztec/stdlib/world-state';
9
18
  import { getTelemetryClient } from '@aztec/telemetry-client';
10
19
  import { createWorldState } from '@aztec/world-state';
11
20
 
12
21
  import { readFileSync } from 'fs';
13
22
 
14
- import { deserializeEpochProvingJobData } from '../job/epoch-proving-job-data.js';
15
- import { EpochProvingJob } from '../job/epoch-proving-job.js';
23
+ import { CheckpointProver } from '../job/checkpoint-prover.js';
24
+ import { type EpochProvingJobData, deserializeEpochProvingJobData } from '../job/epoch-proving-job-data.js';
25
+ import { EpochSession, type SessionSpec } from '../job/epoch-session.js';
16
26
  import { ProverNodeJobMetrics } from '../metrics.js';
17
27
 
28
+ type RerunConfig = DataStoreConfig &
29
+ ProverBrokerConfig &
30
+ ProverClientConfig &
31
+ Pick<L1ContractsConfig, 'aztecEpochDuration'>;
32
+
18
33
  /**
19
34
  * Given a local folder where `downloadEpochProvingJob` was called, creates a new archiver and world state
20
- * using the state snapshots, and creates a new epoch proving job to prove the downloaded proving job.
35
+ * using the state snapshots, and creates a new epoch proving session to prove the downloaded proving job.
21
36
  * Proving is done with a local proving broker and agents as specified by the config.
22
37
  */
23
- export async function rerunEpochProvingJob(
38
+ export async function rerunEpochProvingJob(localPath: string, log: Logger, config: RerunConfig, genesis?: GenesisData) {
39
+ await using ctx = await createRerunContext(localPath, log, config, genesis);
40
+ const { jobData, prover, metrics } = ctx;
41
+
42
+ log.info(`Rerunning epoch proving for epoch ${jobData.epochNumber}`);
43
+
44
+ const provers: CheckpointProver[] = [];
45
+ for (let i = 0; i < jobData.checkpoints.length; i++) {
46
+ provers.push(await buildCheckpointProver(ctx, i, log));
47
+ }
48
+
49
+ // Local rerun never publishes — stub the service so submit() always resolves 'published'
50
+ // and withdraw is a no-op.
51
+ const publishingService = {
52
+ submit: () => Promise.resolve('published' as const),
53
+ withdraw: () => {},
54
+ };
55
+
56
+ const l1Constants = { epochDuration: config.aztecEpochDuration };
57
+ const [fromSlot, toSlot] = getSlotRangeForEpoch(jobData.epochNumber, l1Constants);
58
+ const spec: SessionSpec = { kind: 'full', epochNumber: jobData.epochNumber, fromSlot, toSlot };
59
+
60
+ const session = new EpochSession(spec, provers, {
61
+ proverFactory: prover,
62
+ proverId: prover.getProverId(),
63
+ publishingService,
64
+ metrics,
65
+ dateProvider: new DateProvider(),
66
+ deadline: undefined,
67
+ config: {},
68
+ bindings: log.getBindings(),
69
+ });
70
+
71
+ const finalState = await session.start();
72
+ log.info(`Completed proving for epoch ${jobData.epochNumber} with status ${finalState}`, {
73
+ derivedEpoch: getEpochAtSlot(provers[0].slotNumber, l1Constants),
74
+ });
75
+ return finalState;
76
+ }
77
+
78
+ /**
79
+ * Re-proves a single downloaded checkpoint proving job (as uploaded by a `CheckpointProver` failure).
80
+ * Reconstructs just that checkpoint's sub-tree prover from the snapshot and awaits its block proofs — no
81
+ * epoch top-tree, no L1 submission — so a checkpoint-level failure can be reproduced offline in isolation.
82
+ * Returns the block-rollup proof outputs on success; throws if the checkpoint fails to prove again.
83
+ */
84
+ export async function rerunCheckpointProvingJob(
24
85
  localPath: string,
25
86
  log: Logger,
26
- config: DataStoreConfig & ProverBrokerConfig & ProverClientConfig & Pick<L1ContractsConfig, 'aztecEpochDuration'>,
87
+ config: RerunConfig,
27
88
  genesis?: GenesisData,
28
89
  ) {
90
+ await using ctx = await createRerunContext(localPath, log, config, genesis);
91
+ const { jobData } = ctx;
92
+ const checkpointNumber = jobData.checkpoints[0].number;
93
+
94
+ log.info(`Rerunning checkpoint proving for checkpoint ${checkpointNumber} (epoch ${jobData.epochNumber})`);
95
+
96
+ const prover = await buildCheckpointProver(ctx, 0, log);
97
+ try {
98
+ const blockProofs = await prover.whenBlockProofsReady();
99
+ log.info(`Completed proving for checkpoint ${checkpointNumber} with ${blockProofs.length} block proof(s)`);
100
+ return blockProofs;
101
+ } finally {
102
+ prover.cancel({ routine: true });
103
+ await prover.whenDone();
104
+ }
105
+ }
106
+
107
+ /** Everything a rerun needs, reconstructed from the downloaded snapshot + job data. */
108
+ type RerunContext = {
109
+ jobData: EpochProvingJobData;
110
+ metrics: ProverNodeJobMetrics;
111
+ worldState: Awaited<ReturnType<typeof createWorldState>>;
112
+ publicProcessorFactory: PublicProcessorFactory;
113
+ prover: Awaited<ReturnType<typeof createProverClient>>;
114
+ chonkCache: ChonkCache;
115
+ txProvider: ITxProvider;
116
+ } & AsyncDisposable;
117
+
118
+ /**
119
+ * Rebuilds the offline proving environment from a downloaded job: world state + archiver from the
120
+ * snapshots, a local proving broker + client, a chonk cache, and a tx provider that replays the job's txs.
121
+ */
122
+ async function createRerunContext(
123
+ localPath: string,
124
+ log: Logger,
125
+ config: RerunConfig,
126
+ genesis?: GenesisData,
127
+ ): Promise<RerunContext> {
29
128
  const jobData = deserializeEpochProvingJobData(readFileSync(localPath));
30
129
  log.info(`Loaded proving job data for epoch ${jobData.epochNumber}`);
31
130
 
@@ -34,41 +133,90 @@ export async function rerunEpochProvingJob(
34
133
  const worldState = await createWorldState(config, genesis);
35
134
  const initialBlockHash = await worldState.getInitialHeader().hash();
36
135
  const archiver = await createArchiverStore(config, initialBlockHash);
136
+ const avmSimulator = await AvmSimulatorPool.spawn({ wsdbIpcPath: worldState.getIpcPath() });
37
137
  const publicProcessorFactory = new PublicProcessorFactory(
38
138
  createContractDataSource(archiver),
139
+ avmSimulator,
39
140
  undefined,
40
141
  undefined,
41
142
  log.getBindings(),
42
143
  );
43
-
44
- const publisher = {
45
- submitEpochProof: () => Promise.resolve(true),
46
- analyzeEpochProofSubmission: () => Promise.resolve(),
47
- };
48
- const l2BlockSourceForReorgDetection = undefined;
49
- const deadline = undefined;
50
-
51
- // This starts a local proving broker that does not get exposed as a service. This should be good enough for
52
- // smallish epochs to be proven if we run on a large machine, but as epochs grow larger, we may want to switch
53
- // this out for a live proving broker with multiple agents that we can connect to.
54
144
  const broker = await createAndStartProvingBroker(config, telemetry);
55
145
  const prover = await createProverClient(config, worldState, broker, telemetry);
146
+ const chonkCache = new ChonkCache(log.getBindings());
147
+ const txProvider = makeReplayingTxProvider(jobData.txs);
56
148
 
57
- const provingJob = new EpochProvingJob(
149
+ return {
58
150
  jobData,
151
+ metrics,
59
152
  worldState,
60
- prover.createEpochProver(),
61
153
  publicProcessorFactory,
62
- publisher,
63
- l2BlockSourceForReorgDetection,
64
- metrics,
65
- deadline,
66
- { skipEpochCheck: true },
67
- log.getBindings(),
154
+ prover,
155
+ chonkCache,
156
+ txProvider,
157
+ async [Symbol.asyncDispose]() {
158
+ await avmSimulator[Symbol.asyncDispose]();
159
+ await worldState[Symbol.asyncDispose]();
160
+ },
161
+ };
162
+ }
163
+
164
+ /** Reconstructs the `CheckpointProver` for the checkpoint at `index` in the job, ready to prove. */
165
+ async function buildCheckpointProver(ctx: RerunContext, index: number, log: Logger): Promise<CheckpointProver> {
166
+ const { jobData, worldState, prover, chonkCache, publicProcessorFactory, txProvider, metrics } = ctx;
167
+ const checkpoint = jobData.checkpoints[index];
168
+ const previousBlockHeader =
169
+ index === 0 ? jobData.previousBlockHeader : jobData.checkpoints[index - 1].blocks.at(-1)!.header;
170
+ const l1ToL2Messages = jobData.l1ToL2Messages[checkpoint.number] ?? [];
171
+ const previousArchiveSiblingPath = await getLastSiblingPath(
172
+ MerkleTreeId.ARCHIVE,
173
+ worldState.getSnapshot(BlockNumber(checkpoint.blocks[0].number - 1)),
68
174
  );
175
+ const attestations = checkpoint.number === jobData.checkpoints.at(-1)!.number ? jobData.attestations : [];
176
+ return new CheckpointProver(
177
+ {
178
+ checkpoint,
179
+ epochNumber: jobData.epochNumber,
180
+ attestations,
181
+ previousBlockHeader,
182
+ l1ToL2Messages,
183
+ previousArchiveSiblingPath,
184
+ },
185
+ {
186
+ proverFactory: prover,
187
+ chonkCache,
188
+ publicProcessorFactory,
189
+ dbProvider: worldState,
190
+ txProvider,
191
+ dateProvider: new DateProvider(),
192
+ proverId: prover.getProverId(),
193
+ metrics,
194
+ txGatheringTimeoutMs: 120_000,
195
+ deadline: undefined,
196
+ log,
197
+ },
198
+ );
199
+ }
69
200
 
70
- log.info(`Rerunning epoch proving job for epoch ${jobData.epochNumber}`);
71
- await provingJob.run();
72
- log.info(`Completed job for epoch ${jobData.epochNumber} with status ${provingJob.getState()}`);
73
- return provingJob.getState();
201
+ /** Build a synthetic ITxProvider that returns the supplied txs map by lookup. */
202
+ function makeReplayingTxProvider(txs: Map<string, Tx>): ITxProvider {
203
+ const lookup = (hashes: TxHash[]) => {
204
+ const found: Tx[] = [];
205
+ const missing: TxHash[] = [];
206
+ for (const hash of hashes) {
207
+ const tx = txs.get(hash.toString());
208
+ if (tx) {
209
+ found.push(tx);
210
+ } else {
211
+ missing.push(hash);
212
+ }
213
+ }
214
+ return { txs: found, missingTxs: missing };
215
+ };
216
+ return {
217
+ getAvailableTxs: hashes => Promise.resolve(lookup(hashes)),
218
+ hasTxs: hashes => Promise.resolve(hashes.map(h => txs.has(h.toString()))),
219
+ getTxsForBlockProposal: () => Promise.resolve({ txs: [], missingTxs: [] }),
220
+ getTxsForBlock: (block: L2Block) => Promise.resolve(lookup(block.body.txEffects.map(e => e.txHash))),
221
+ };
74
222
  }
@@ -0,0 +1,212 @@
1
+ import type { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
3
+ import type { L2BlockSource } from '@aztec/stdlib/block';
4
+ import type { Checkpoint } from '@aztec/stdlib/checkpoint';
5
+ import { type L1RollupConstants, getEpochAtSlot, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
6
+
7
+ import {
8
+ CheckpointProver,
9
+ type CheckpointProverArgs,
10
+ type CheckpointProverDeps,
11
+ type CheckpointProverTestHooks,
12
+ } from './job/checkpoint-prover.js';
13
+
14
+ /** Register-time data needed to construct a `CheckpointProver` (everything except the checkpoint + epoch). */
15
+ export type RegisterCheckpointData = Omit<CheckpointProverArgs, 'checkpoint' | 'epochNumber'>;
16
+
17
+ /** Factory used by the store to construct new provers. Tests can inject a stub. */
18
+ export type CheckpointProverFactory = (args: CheckpointProverArgs, deps: CheckpointProverDeps) => CheckpointProver;
19
+
20
+ /**
21
+ * Prover-node-wide registry of `CheckpointProver` instances, content-addressed by
22
+ * `(checkpoint number, slot, checkpoint archive root)`.
23
+ *
24
+ * The store survives every epoch / session boundary. A prover lives from its first
25
+ * `addOrUpdate` call until either:
26
+ * - its checkpoint is pruned by an L1 reorg (`cancelAndRemoveAboveBlock`), or
27
+ * - its epoch's proof-submission window has closed (`reapExpired`), so the proof could no
28
+ * longer be accepted on L1 even if produced.
29
+ *
30
+ * A prover's sub-tree work forks world-state per block and does not survive a prune of a base
31
+ * block, so there is nothing to preserve across a reorg: a pruned prover is cancelled and
32
+ * dropped, and a re-add (even of identical content) constructs a fresh prover.
33
+ */
34
+ export class CheckpointStore {
35
+ private readonly provers = new Map<string, CheckpointProver>();
36
+ /**
37
+ * Teardowns of provers already removed from `provers` (by prune or reap), awaited on `stop()`.
38
+ * Keyed by a monotonic id rather than the prover's content id: a prune-then-re-add can leave two
39
+ * teardowns for the same content id in flight at once, which a content-id key would clobber.
40
+ */
41
+ private readonly pendingTeardowns = new Map<number, Promise<void>>();
42
+ private nextTeardownId = 0;
43
+ /** Test-only hooks injected into every prover this store constructs. */
44
+ private testHooks: CheckpointProverTestHooks = {};
45
+ private readonly log: Logger;
46
+
47
+ constructor(
48
+ private readonly l2BlockSource: Pick<L2BlockSource, 'getL1Constants'>,
49
+ private readonly proverDeps: Omit<CheckpointProverDeps, 'log'>,
50
+ bindings?: LoggerBindings,
51
+ private readonly proverFactoryFn: CheckpointProverFactory = (args, deps) => new CheckpointProver(args, deps),
52
+ ) {
53
+ this.log = createLogger('prover-node:checkpoint-store', bindings);
54
+ }
55
+
56
+ public start(): Promise<void> {
57
+ return Promise.resolve();
58
+ }
59
+
60
+ public async stop(): Promise<void> {
61
+ // Cancel every live prover, then await both their teardown and any still in flight for provers
62
+ // already removed by a prune or reap.
63
+ const provers = Array.from(this.provers.values());
64
+ this.provers.clear();
65
+ for (const prover of provers) {
66
+ prover.cancel();
67
+ }
68
+ await Promise.allSettled([...provers.map(p => p.whenDone()), ...this.pendingTeardowns.values()]);
69
+ }
70
+
71
+ /**
72
+ * Tracks the teardown of a prover just removed from the store so `stop()` can await it. The entry
73
+ * removes itself once teardown settles, so the map stays bounded by the number in flight.
74
+ */
75
+ private trackTeardown(prover: CheckpointProver): void {
76
+ const id = this.nextTeardownId++;
77
+ const done = prover.whenDone();
78
+ this.pendingTeardowns.set(id, done);
79
+ void done.finally(() => this.pendingTeardowns.delete(id));
80
+ }
81
+
82
+ /**
83
+ * Registers a checkpoint with the store. If a prover already exists for the
84
+ * `(number, slot, archive root)` content key it is reused (an at-least-once re-registration of
85
+ * still-canonical content); otherwise a new prover is constructed.
86
+ */
87
+ public async addOrUpdate(checkpoint: Checkpoint, data: RegisterCheckpointData): Promise<CheckpointProver> {
88
+ const l1Constants = await this.l2BlockSource.getL1Constants();
89
+ const epochNumber = getEpochAtSlot(checkpoint.header.slotNumber, l1Constants);
90
+ const id = CheckpointProver.idFor(checkpoint);
91
+
92
+ const existing = this.provers.get(id);
93
+ if (existing) {
94
+ return existing;
95
+ }
96
+
97
+ // At most one canonical checkpoint per slot. A different checkpoint at the same slot means the
98
+ // caller forgot to prune the old chain before adding the replacement — surface it rather than
99
+ // silently creating a parallel canonical chain. A pruned checkpoint has already been removed,
100
+ // so every prover still in the store is canonical.
101
+ for (const prover of this.provers.values()) {
102
+ if (prover.slotNumber === checkpoint.header.slotNumber) {
103
+ throw new Error(
104
+ `Cannot add checkpoint ${checkpoint.number} (archive ${checkpoint.archive.root}) at slot ${checkpoint.header.slotNumber}: ` +
105
+ `a different checkpoint already occupies this slot. Prune it first.`,
106
+ );
107
+ }
108
+ }
109
+
110
+ const prover = this.proverFactoryFn(
111
+ { ...data, checkpoint, epochNumber },
112
+ { ...this.proverDeps, checkpointProveOverride: this.testHooks.checkpointProveOverride, log: this.log },
113
+ );
114
+ this.provers.set(id, prover);
115
+ return prover;
116
+ }
117
+
118
+ /**
119
+ * Installs test-only hooks applied to every prover constructed from now on. Used by the e2e harness to
120
+ * force a checkpoint sub-tree failure without monkey-patching the prover factory.
121
+ */
122
+ public setTestHooks(hooks: CheckpointProverTestHooks): void {
123
+ this.testHooks = hooks;
124
+ }
125
+
126
+ /**
127
+ * Cancels and removes every prover that holds a block above the prune target. A checkpoint is orphaned by a prune to
128
+ * block `targetBlockNumber` iff its last block sits above the target — including a checkpoint whose range straddles
129
+ * the target (partially orphaned), which block-range marking catches without boundary ambiguity. Keying off the
130
+ * surviving block number (rather than a checkpoint number) is correct even when the source has already
131
+ * re-checkpointed past the divergence: the prune event reports the highest surviving block, which by construction
132
+ * survives on the source, whereas the source's current checkpointed tip can sit above the prune target.
133
+ *
134
+ * The prover's in-flight sub-tree work forks world-state per block and faults once its base block is pruned, so it
135
+ * cannot be reused; it is cancelled (aborting the fork reads) and dropped. A subsequent re-add constructs a fresh
136
+ * prover. Returns the removed provers.
137
+ */
138
+ public cancelAndRemoveAboveBlock(targetBlockNumber: BlockNumber): CheckpointProver[] {
139
+ const affected: CheckpointProver[] = [];
140
+ for (const [id, prover] of Array.from(this.provers.entries())) {
141
+ const lastBlockNumber = prover.checkpoint.blocks.at(-1)!.number;
142
+ if (lastBlockNumber > targetBlockNumber) {
143
+ prover.cancel();
144
+ this.trackTeardown(prover);
145
+ this.provers.delete(id);
146
+ affected.push(prover);
147
+ }
148
+ }
149
+ return affected;
150
+ }
151
+
152
+ /**
153
+ * Drops provers whose epoch is at or below the supplied expired epoch. Once an epoch's
154
+ * proof-submission window has closed, its proof can no longer be accepted on L1, so the
155
+ * prover is no longer needed.
156
+ */
157
+ public reapExpired(expiredEpoch: EpochNumber): void {
158
+ const reaped: { id: string; checkpointNumber: CheckpointNumber; epochNumber: EpochNumber }[] = [];
159
+ for (const [id, prover] of Array.from(this.provers.entries())) {
160
+ if (prover.epochNumber <= expiredEpoch) {
161
+ reaped.push({ id, checkpointNumber: prover.checkpoint.number, epochNumber: prover.epochNumber });
162
+ prover.cancel({ routine: true });
163
+ this.trackTeardown(prover);
164
+ this.provers.delete(id);
165
+ }
166
+ }
167
+ if (reaped.length > 0) {
168
+ this.log.info(`Reaped ${reaped.length} expired CheckpointProver(s) for expiredEpoch ${expiredEpoch}`, {
169
+ expiredEpoch,
170
+ reapedCount: reaped.length,
171
+ reaped,
172
+ });
173
+ }
174
+ }
175
+
176
+ /** Returns the prover with the supplied id, or undefined. */
177
+ public get(id: string): CheckpointProver | undefined {
178
+ return this.provers.get(id);
179
+ }
180
+
181
+ /** Returns the prover for the supplied checkpoint (by its content-addressed id), or undefined. */
182
+ public getByCheckpoint(checkpoint: Checkpoint): CheckpointProver | undefined {
183
+ return this.provers.get(CheckpointProver.idFor(checkpoint));
184
+ }
185
+
186
+ /** Every prover currently in the store, in insertion order. */
187
+ public listAll(): CheckpointProver[] {
188
+ return Array.from(this.provers.values());
189
+ }
190
+
191
+ /** Provers in the store, sorted by checkpoint number. */
192
+ public list(): CheckpointProver[] {
193
+ return Array.from(this.provers.values()).sort((a, b) => a.checkpoint.number - b.checkpoint.number);
194
+ }
195
+
196
+ /**
197
+ * Provers whose slot is in the supplied epoch's slot range, sorted by checkpoint number.
198
+ */
199
+ public async listForEpoch(epoch: EpochNumber): Promise<CheckpointProver[]> {
200
+ const l1Constants = await this.l2BlockSource.getL1Constants();
201
+ const [fromSlot, toSlot] = getSlotRangeForEpoch(epoch, l1Constants);
202
+ return this.listInSlotRange(fromSlot, toSlot);
203
+ }
204
+
205
+ /** Provers whose slot falls within `[fromSlot, toSlot]`, sorted by checkpoint number. */
206
+ public listInSlotRange(fromSlot: SlotNumber, toSlot: SlotNumber): CheckpointProver[] {
207
+ return this.list().filter(p => p.slotNumber >= fromSlot && p.slotNumber <= toSlot);
208
+ }
209
+ }
210
+
211
+ /** Sub-set of `L1RollupConstants` actually consumed by the store's slot helpers. */
212
+ export type CheckpointStoreL1Constants = Pick<L1RollupConstants, 'epochDuration'>;
package/src/config.ts CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  numberConfigHelper,
7
7
  pickConfigMappings,
8
8
  } from '@aztec/foundation/config';
9
+ import { EthAddress } from '@aztec/foundation/eth-address';
9
10
  import { type KeyStoreConfig, keyStoreConfigMappings } from '@aztec/node-keystore/config';
10
11
  import { ethPrivateKeySchema } from '@aztec/node-keystore/schemas';
11
12
  import type { KeyStore } from '@aztec/node-keystore/types';
@@ -44,6 +45,7 @@ export type SpecificProverNodeConfig = {
44
45
  txGatheringIntervalMs: number;
45
46
  txGatheringBatchSize: number;
46
47
  txGatheringMaxParallelRequestsPerNode: number;
48
+ proofSubmissionTargetAddress?: EthAddress;
47
49
  };
48
50
 
49
51
  export const specificProverNodeConfigMappings: ConfigMappingsType<SpecificProverNodeConfig> = {
@@ -68,7 +70,8 @@ export const specificProverNodeConfigMappings: ConfigMappingsType<SpecificProver
68
70
  defaultValue: undefined,
69
71
  },
70
72
  proverNodeEpochProvingDelayMs: {
71
- description: 'Optional delay in milliseconds to wait before proving a new epoch',
73
+ description:
74
+ 'Optional delay in milliseconds to wait for late-arriving events (e.g. reorgs) to settle before starting top-tree proving for an epoch',
72
75
  defaultValue: undefined,
73
76
  },
74
77
  txGatheringIntervalMs: {
@@ -96,6 +99,14 @@ export const specificProverNodeConfigMappings: ConfigMappingsType<SpecificProver
96
99
  description: 'Whether the prover node skips publishing proofs to L1',
97
100
  ...booleanConfigHelper(false),
98
101
  },
102
+ proofSubmissionTargetAddress: {
103
+ env: 'PROVER_NODE_PROOF_SUBMISSION_TARGET_ADDRESS',
104
+ description:
105
+ 'Optional L1 address the submitEpochRootProof tx is sent to. Must expose the identical submitEpochRootProof ABI ' +
106
+ 'and forward to the rollup. Defaults to the rollup address.',
107
+ parseEnv: (val: string) => EthAddress.fromString(val),
108
+ defaultValue: undefined,
109
+ },
99
110
  };
100
111
 
101
112
  export const proverNodeConfigMappings: ConfigMappingsType<ProverNodeConfig> = {
package/src/factory.ts CHANGED
@@ -19,6 +19,7 @@ import {
19
19
  type ProverTxSenderConfig,
20
20
  getPublisherConfigFromProverConfig,
21
21
  } from '@aztec/sequencer-client';
22
+ import type { AvmSimulator } from '@aztec/simulator/server';
22
23
  import type {
23
24
  ITxProvider,
24
25
  ProverConfig,
@@ -31,7 +32,6 @@ import { L1Metrics, type TelemetryClient, getTelemetryClient } from '@aztec/tele
31
32
  import { createPublicClient } from 'viem';
32
33
 
33
34
  import type { SpecificProverNodeConfig } from './config.js';
34
- import { EpochMonitor } from './monitors/epoch-monitor.js';
35
35
  import { ProverNode } from './prover-node.js';
36
36
  import { ProverPublisherFactory } from './prover-publisher-factory.js';
37
37
 
@@ -48,6 +48,8 @@ export type ProverNodeDeps = {
48
48
  epochCache: EpochCacheInterface;
49
49
  blobClient: BlobClientInterface;
50
50
  keyStoreManager?: KeystoreManager;
51
+ /** AVM execution backend (simulator pool + CDB server) for public simulation. */
52
+ avmSimulator: AvmSimulator;
51
53
  };
52
54
 
53
55
  /** Creates a new prover node subsystem given a config and dependencies */
@@ -136,6 +138,7 @@ export async function createProverNode(
136
138
  deps.publisherFactory ??
137
139
  new ProverPublisherFactory(config, {
138
140
  rollupContract,
141
+ proofSubmissionTarget: config.proofSubmissionTargetAddress,
139
142
  publisherManager: new PublisherManager(l1TxUtils, getPublisherConfigFromProverConfig(config), {
140
143
  bindings: log.getBindings(),
141
144
  funder: funderL1TxUtils,
@@ -161,12 +164,6 @@ export async function createProverNode(
161
164
  ),
162
165
  };
163
166
 
164
- const epochMonitor = await EpochMonitor.create(
165
- archiver,
166
- { pollingIntervalMs: config.proverNodePollingIntervalMs, provingDelayMs: config.proverNodeEpochProvingDelayMs },
167
- telemetry,
168
- );
169
-
170
167
  const l1Metrics = new L1Metrics(
171
168
  telemetry.getMeter('ProverNodeL1Metrics'),
172
169
  publicClient,
@@ -184,9 +181,9 @@ export async function createProverNode(
184
181
  archiver,
185
182
  worldStateSynchronizer,
186
183
  p2pClient,
187
- epochMonitor,
188
184
  rollupContract,
189
185
  l1Metrics,
186
+ deps.avmSimulator,
190
187
  proverNodeConfig,
191
188
  telemetry,
192
189
  delayer,
package/src/index.ts CHANGED
@@ -2,5 +2,6 @@ export * from './actions/index.js';
2
2
  export * from './config.js';
3
3
  export * from './factory.js';
4
4
  export * from './monitors/index.js';
5
+ export * from './proof-publishing-service.js';
5
6
  export * from './prover-node-publisher.js';
6
7
  export * from './prover-node.js';