@aztec/prover-node 0.0.1-commit.a5db02d → 0.0.1-commit.aa0c64f

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 (42) hide show
  1. package/README.md +95 -34
  2. package/dest/actions/rerun-epoch-proving-job.d.ts +11 -2
  3. package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -1
  4. package/dest/actions/rerun-epoch-proving-job.js +195 -55
  5. package/dest/checkpoint-store.d.ts +9 -2
  6. package/dest/checkpoint-store.d.ts.map +1 -1
  7. package/dest/checkpoint-store.js +9 -0
  8. package/dest/config.d.ts +3 -1
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +7 -0
  11. package/dest/factory.d.ts +4 -1
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +2 -1
  14. package/dest/job/checkpoint-prover.d.ts +34 -4
  15. package/dest/job/checkpoint-prover.d.ts.map +1 -1
  16. package/dest/job/checkpoint-prover.js +41 -8
  17. package/dest/job/epoch-session.d.ts +14 -2
  18. package/dest/job/epoch-session.d.ts.map +1 -1
  19. package/dest/job/epoch-session.js +24 -2
  20. package/dest/prover-node-publisher.d.ts +4 -1
  21. package/dest/prover-node-publisher.d.ts.map +1 -1
  22. package/dest/prover-node-publisher.js +5 -3
  23. package/dest/prover-node.d.ts +37 -8
  24. package/dest/prover-node.d.ts.map +1 -1
  25. package/dest/prover-node.js +82 -19
  26. package/dest/prover-publisher-factory.d.ts +3 -1
  27. package/dest/prover-publisher-factory.d.ts.map +1 -1
  28. package/dest/prover-publisher-factory.js +1 -0
  29. package/dest/session-manager.d.ts +16 -16
  30. package/dest/session-manager.d.ts.map +1 -1
  31. package/dest/session-manager.js +62 -62
  32. package/package.json +24 -23
  33. package/src/actions/rerun-epoch-proving-job.ts +139 -66
  34. package/src/checkpoint-store.ts +20 -2
  35. package/src/config.ts +10 -0
  36. package/src/factory.ts +5 -0
  37. package/src/job/checkpoint-prover.ts +61 -7
  38. package/src/job/epoch-session.ts +26 -2
  39. package/src/prover-node-publisher.ts +7 -3
  40. package/src/prover-node.ts +97 -20
  41. package/src/prover-publisher-factory.ts +3 -0
  42. package/src/session-manager.ts +70 -66
@@ -60,8 +60,9 @@ export type SessionManagerDeps = {
60
60
  dateProvider: DateProvider;
61
61
  config: SessionManagerConfig;
62
62
  /**
63
- * Optional callback fired when a session terminates with `failed`. The session manager
64
- * doesn't own the failure-upload action; it just notifies the owner.
63
+ * Fired once when a full session ends in its own genuine failure (`EpochSession.hasFailed()` top-tree
64
+ * or submit failed with every prover healthy). The owner uploads a post-mortem here. Not fired for a
65
+ * `stopped` session (a prover under it failed — possibly a prune), which is recovered on re-add instead.
65
66
  */
66
67
  onSessionFailed?: (session: EpochSession) => Promise<void>;
67
68
  bindings?: LoggerBindings;
@@ -88,15 +89,6 @@ export class SessionManager {
88
89
  private readonly reconcileQueue = new SerialQueue();
89
90
  /** Cached L1 constants, populated on first read. */
90
91
  private cachedL1Constants: L1RollupConstants | undefined;
91
- /**
92
- * Highest epoch for which the periodic tick has successfully created a full session.
93
- * Monotonic high-water mark: once the tick observes a session for epoch X, it stops
94
- * trying to open one — even if that session subsequently fails (only a new checkpoint
95
- * event reopens it). Crucially, the mark only advances when a session actually exists
96
- * post-open, so transient blockers (atMaxSessionLimit, archiver still indexing) leave
97
- * the mark in place and the next tick retries.
98
- */
99
- private lastTickEpoch: EpochNumber | undefined;
100
92
  /** Test-only hooks applied to every session this manager constructs. */
101
93
  private sessionHooks: EpochSessionHooks | undefined;
102
94
  /** Periodic tick that nudges reconcile to pick up newly-complete epochs. Started by `start()`. */
@@ -248,17 +240,6 @@ export class SessionManager {
248
240
  await this.openFullSessionIfReady(epoch);
249
241
  }
250
242
 
251
- // Advance the tick high-water mark only once a session actually exists for the epoch.
252
- // `openFullSessionIfReady` can early-return without creating one (atMaxSessionLimit,
253
- // archiver still indexing, etc.); in those cases we want the next tick to try again
254
- // rather than skip the epoch forever.
255
- if (trigger.kind === 'tick' && implicatedEpochs.length === 1) {
256
- const epoch = implicatedEpochs[0];
257
- if (this.fullSessions.has(epoch)) {
258
- this.lastTickEpoch = epoch;
259
- }
260
- }
261
-
262
243
  if (trigger.kind === 'start-proof') {
263
244
  this.openPartialSession(trigger.spec);
264
245
  }
@@ -266,15 +247,30 @@ export class SessionManager {
266
247
 
267
248
  private recreateInvalidSessions(): void {
268
249
  for (const [key, session] of Array.from(this.fullSessions.entries())) {
250
+ const canonical = this.checkpointsForSpec(session.getSpec());
251
+ const contentChanged = !this.checkpointsMatch(session.getCheckpoints(), canonical);
252
+
269
253
  if (session.isTerminal()) {
254
+ // A full session that failed on its own account is retained as a "do not re-prove" marker while
255
+ // its content is unchanged — this is what stops the tick re-proving a deterministically-failing
256
+ // epoch. When the content changes (a re-add), it is replaced so the epoch retries over the new
257
+ // provers. Any other terminal full session is simply dropped.
258
+ if (session.hasFailed() && !contentChanged) {
259
+ continue;
260
+ }
270
261
  this.fullSessions.delete(key);
262
+ if (contentChanged && this.canBuildOver(canonical)) {
263
+ const newSession = this.constructSession(session.getSpec(), canonical);
264
+ this.fullSessions.set(key, newSession);
265
+ void this.runSession(newSession);
266
+ }
271
267
  continue;
272
268
  }
273
- const canonical = this.checkpointsForSpec(session.getSpec());
274
- if (!this.checkpointsMatch(session.getCheckpoints(), canonical)) {
269
+
270
+ if (contentChanged) {
275
271
  this.fireAndForgetCancel(session, 'canonical content changed');
276
272
  this.fullSessions.delete(key);
277
- if (canonical.length > 0) {
273
+ if (this.canBuildOver(canonical)) {
278
274
  const newSession = this.constructSession(session.getSpec(), canonical);
279
275
  this.fullSessions.set(key, newSession);
280
276
  void this.runSession(newSession);
@@ -290,7 +286,7 @@ export class SessionManager {
290
286
  if (!this.checkpointsMatch(session.getCheckpoints(), canonical)) {
291
287
  this.fireAndForgetCancel(session, 'canonical content changed');
292
288
  this.partialSessions.delete(key);
293
- if (canonical.length > 0) {
289
+ if (this.canBuildOver(canonical)) {
294
290
  const newSession = this.constructSession(session.getSpec(), canonical);
295
291
  this.partialSessions.set(key, newSession);
296
292
  void this.runSession(newSession);
@@ -299,9 +295,15 @@ export class SessionManager {
299
295
  }
300
296
  }
301
297
 
298
+ /** A session may be built over a checkpoint set only when it is non-empty and contains no failed prover. */
299
+ private canBuildOver(canonical: readonly CheckpointProver[]): boolean {
300
+ return canonical.length > 0 && !this.hasFailedProver(canonical);
301
+ }
302
+
302
303
  private async openFullSessionIfReady(epoch: EpochNumber): Promise<void> {
303
- // `recreateInvalidSessions` runs at the top of every reconcile and deletes terminal sessions
304
- // before this is called, so a session present here is live and already covers the epoch.
304
+ // A session present here already covers the epoch: either live, or a retained genuinely-failed
305
+ // session kept by `recreateInvalidSessions` as a "do not re-prove" marker. Either way, don't open
306
+ // another — the retained-failed one is replaced only when its canonical content changes.
305
307
  if (this.fullSessions.has(epoch)) {
306
308
  return;
307
309
  }
@@ -326,6 +328,13 @@ export class SessionManager {
326
328
  });
327
329
  return;
328
330
  }
331
+ if (this.hasFailedProver(canonical)) {
332
+ // A checkpoint prover in the set has failed (a sub-tree fault or a prune-induced fork fault), so a
333
+ // session over it would fail immediately. Don't re-create it every tick — it recovers when a
334
+ // prune/re-add replaces the failed prover with a fresh one, or fails for good at expiry.
335
+ this.log.debug(`Skipping full-session open for epoch ${epoch}: a checkpoint prover has failed`, { epoch });
336
+ return;
337
+ }
329
338
  const spec: SessionSpec = { kind: 'full', epochNumber: epoch, fromSlot, toSlot };
330
339
  const session = this.constructSession(spec, canonical);
331
340
  this.fullSessions.set(epoch, session);
@@ -334,7 +343,7 @@ export class SessionManager {
334
343
 
335
344
  private openPartialSession(spec: SessionSpec): void {
336
345
  const canonical = this.deps.checkpointStore.listInSlotRange(spec.fromSlot, spec.toSlot);
337
- if (canonical.length === 0) {
346
+ if (canonical.length === 0 || this.hasFailedProver(canonical)) {
338
347
  return;
339
348
  }
340
349
  // Reuse a live partial session for this epoch whose checkpoint set already matches the
@@ -406,33 +415,30 @@ export class SessionManager {
406
415
  }
407
416
  const state = await session.start();
408
417
  this.log.info(`Session ${session.getId()} exited with state ${state}`);
409
- if (state === 'failed' && this.deps.onSessionFailed) {
410
- // Best-effort suppression of the spurious post-mortem upload a prune produces: if the session's
411
- // checkpoints no longer match the store's current set, the failure was caused by the content
412
- // changing under it, not a genuine proving fault, so skip the upload. This is inherently racy
413
- // the store lags the world-state unwind, so a fault observed before the prune is reconciled here
414
- // still uploads. The epoch is recovered regardless by recreating the session on re-add.
415
- if (!this.checkpointsMatch(session.getCheckpoints(), this.checkpointsForSpec(session.getSpec()))) {
416
- this.log.info(`Skipping failure upload for session ${session.getId()}: canonical content changed`, {
417
- ...session.getSpec(),
418
- });
419
- return;
420
- }
418
+
419
+ // A full session that failed on its own account (top-tree/submit failed with every prover healthy)
420
+ // is a genuine, race-free failure: upload its post-mortem once. `recreateInvalidSessions` retains
421
+ // the terminal session so this fires exactly once (it is never re-run over the same content). A
422
+ // `stopped` session (a prover under it failed) is not uploaded it may be a prune, and recovers on
423
+ // re-add.
424
+ if (session.getKind() === 'full' && session.hasFailed() && this.deps.onSessionFailed) {
421
425
  try {
422
426
  await this.deps.onSessionFailed(session);
423
427
  } catch (err) {
424
- this.log.error(`Error in onSessionFailed callback for ${session.getSpec().epochNumber}`, err);
428
+ this.log.error(`Error in onSessionFailed callback for epoch ${session.getEpochNumber()}`, err);
425
429
  }
426
430
  }
427
431
  }
428
432
 
429
433
  /**
430
- * Builds the EpochProvingJobData snapshot for failure upload. Includes every checkpoint
431
- * referenced by the session, regardless of whether sub-tree proving completed —
432
- * partial state is still useful for post-mortem analysis.
434
+ * Builds the EpochProvingJobData snapshot for a post-mortem failure upload from a set of
435
+ * checkpoint provers. Includes every checkpoint regardless of whether sub-tree proving
436
+ * completed — partial state is still useful for post-mortem analysis.
433
437
  */
434
- public static buildSessionProvingData(session: EpochSession): EpochProvingJobData {
435
- const checkpoints = session.getCheckpoints();
438
+ public static buildProvingData(checkpoints: readonly CheckpointProver[]): EpochProvingJobData {
439
+ if (checkpoints.length === 0) {
440
+ throw new Error('Cannot build proving data from an empty checkpoint set');
441
+ }
436
442
  const txs = new Map();
437
443
  const l1ToL2Messages: Record<number, Fr[]> = {};
438
444
  for (const c of checkpoints) {
@@ -442,7 +448,7 @@ export class SessionManager {
442
448
  l1ToL2Messages[c.checkpoint.number] = c.l1ToL2Messages;
443
449
  }
444
450
  return {
445
- epochNumber: session.getSpec().epochNumber,
451
+ epochNumber: checkpoints[0].epochNumber,
446
452
  checkpoints: checkpoints.map(c => c.checkpoint),
447
453
  txs,
448
454
  l1ToL2Messages,
@@ -465,20 +471,12 @@ export class SessionManager {
465
471
  /**
466
472
  * Maps a reconcile trigger to the epochs whose full session should be (re)opened.
467
473
  *
468
- * This is where the "don't retry a genuinely-failed epoch, but do recover a pruned one" invariant
469
- * lives enforced by which triggers are gated by `lastTickEpoch`:
470
- *
471
- * - The periodic `tick` IS gated: once a tick has opened a session for an epoch, `lastTickEpoch`
472
- * advances to it and later ticks skip it (`epoch <= lastTickEpoch`). So a failed attempt is never
473
- * resubmitted on a loop by the tick.
474
- * - `checkpoint` and `prune` are deliberately NOT gated. They only fire when the epoch's canonical
475
- * content actually changes — a checkpoint arrives, or a reorg prunes/replaces one — which is
476
- * exactly when re-attempting is correct.
477
- *
478
- * A genuine proving failure produces no content change, hence no checkpoint/prune event, so only
479
- * the gated tick could reopen it — and it won't. A prune + re-add fires ungated events, so the
480
- * epoch is reopened through this path (and `openFullSessionIfReady` rebuilds over the fresh
481
- * provers). See the "onTick does not retry ... but recovers ... re-added" test.
474
+ * The periodic `tick` returns the next unproven epoch every time; it does not track prior attempts.
475
+ * `openFullSessionIfReady` is what keeps this from re-proving a doomed epoch: it refuses to build a
476
+ * session when any checkpoint prover in the set has failed, so a stuck epoch is cheaply skipped each
477
+ * tick rather than re-proved. `checkpoint` and `prune` fire when an epoch's canonical content changes
478
+ * (a checkpoint arrives, or a reorg prunes/replaces one) which is what installs a fresh prover in
479
+ * place of a failed one, letting the next open succeed and recovering a pruned-then-re-added epoch.
482
480
  */
483
481
  private async epochsForTrigger(trigger: ReconcileTrigger): Promise<EpochNumber[]> {
484
482
  switch (trigger.kind) {
@@ -488,10 +486,7 @@ export class SessionManager {
488
486
  return trigger.affectedEpochs;
489
487
  case 'tick': {
490
488
  const epoch = await this.nextUnprovenEpoch();
491
- if (epoch === undefined || (this.lastTickEpoch !== undefined && epoch <= this.lastTickEpoch)) {
492
- return [];
493
- }
494
- return [epoch];
489
+ return epoch === undefined ? [] : [epoch];
495
490
  }
496
491
  case 'start-proof':
497
492
  return [];
@@ -518,6 +513,15 @@ export class SessionManager {
518
513
  return this.deps.checkpointStore.listInSlotRange(spec.fromSlot, spec.toSlot);
519
514
  }
520
515
 
516
+ /**
517
+ * True if any prover in the set has failed. The epoch cannot be proven over a failed prover (it can
518
+ * never produce its block proofs), so a session must not be built or rebuilt over it until a prune/re-add
519
+ * has replaced it with a fresh prover.
520
+ */
521
+ private hasFailedProver(checkpoints: readonly CheckpointProver[]): boolean {
522
+ return checkpoints.some(c => c.isFailed());
523
+ }
524
+
521
525
  private fireAndForgetCancel(session: EpochSession, reason: string): void {
522
526
  void session.cancel(reason).catch(err => this.log.warn(`Error cancelling session ${session.getId()}`, err));
523
527
  }