@aztec/prover-node 0.0.1-commit.2f68f620 → 0.0.1-commit.3100065
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +511 -0
- package/dest/actions/rerun-epoch-proving-job.d.ts +3 -3
- package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -1
- package/dest/actions/rerun-epoch-proving-job.js +106 -104
- package/dest/checkpoint-store.d.ts +88 -0
- package/dest/checkpoint-store.d.ts.map +1 -0
- package/dest/checkpoint-store.js +169 -0
- package/dest/config.d.ts +1 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +1 -8
- package/dest/factory.d.ts +1 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +1 -7
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/job/checkpoint-prover.d.ts +124 -0
- package/dest/job/checkpoint-prover.d.ts.map +1 -0
- package/dest/job/checkpoint-prover.js +330 -0
- package/dest/job/epoch-session.d.ts +146 -0
- package/dest/job/epoch-session.d.ts.map +1 -0
- package/dest/job/epoch-session.js +720 -0
- package/dest/job/top-tree-job.d.ts +82 -0
- package/dest/job/top-tree-job.d.ts.map +1 -0
- package/dest/job/top-tree-job.js +152 -0
- package/dest/metrics.d.ts +25 -8
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +64 -14
- package/dest/proof-publishing-service.d.ts +161 -0
- package/dest/proof-publishing-service.d.ts.map +1 -0
- package/dest/proof-publishing-service.js +335 -0
- package/dest/prover-node-publisher.d.ts +7 -22
- package/dest/prover-node-publisher.d.ts.map +1 -1
- package/dest/prover-node-publisher.js +41 -101
- package/dest/prover-node.d.ts +105 -67
- package/dest/prover-node.d.ts.map +1 -1
- package/dest/prover-node.js +472 -261
- package/dest/prover-publisher-factory.d.ts +1 -3
- package/dest/prover-publisher-factory.d.ts.map +1 -1
- package/dest/prover-publisher-factory.js +0 -1
- package/dest/session-manager.d.ts +158 -0
- package/dest/session-manager.d.ts.map +1 -0
- package/dest/session-manager.js +482 -0
- package/dest/test/index.d.ts +7 -6
- package/dest/test/index.d.ts.map +1 -1
- package/package.json +23 -23
- package/src/actions/rerun-epoch-proving-job.ts +102 -27
- package/src/checkpoint-store.ts +194 -0
- package/src/config.ts +2 -11
- package/src/factory.ts +0 -9
- package/src/index.ts +1 -0
- package/src/job/checkpoint-prover.ts +442 -0
- package/src/job/epoch-session.ts +436 -0
- package/src/job/top-tree-job.ts +227 -0
- package/src/metrics.ts +65 -23
- package/src/proof-publishing-service.ts +427 -0
- package/src/prover-node-publisher.ts +54 -127
- package/src/prover-node.ts +545 -282
- package/src/prover-publisher-factory.ts +0 -3
- package/src/session-manager.ts +583 -0
- package/src/test/index.ts +6 -6
- package/dest/job/epoch-proving-job.d.ts +0 -67
- package/dest/job/epoch-proving-job.d.ts.map +0 -1
- package/dest/job/epoch-proving-job.js +0 -912
- package/src/job/epoch-proving-job.ts +0 -531
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { SerialQueue } from '@aztec/foundation/queue';
|
|
4
|
+
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
5
|
+
import { getEpochAtSlot, getProofSubmissionDeadlineTimestamp, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
6
|
+
import { CheckpointProver } from './job/checkpoint-prover.js';
|
|
7
|
+
import { EpochSession, specKey } from './job/epoch-session.js';
|
|
8
|
+
/**
|
|
9
|
+
* Owns the lifecycle of every `EpochSession`. Each L2BlockStream event and periodic tick
|
|
10
|
+
* arrives via a dedicated entry point (`onCheckpointAdded`, `onPrune`, `onTick`, etc.) which
|
|
11
|
+
* schedules a `reconcile(trigger)` on a serial queue. Reconcile walks both session
|
|
12
|
+
* maps, cancels any session whose canonical content has shifted, re-creates it with
|
|
13
|
+
* the same spec but new content, and opens fresh full sessions for any epoch implicated
|
|
14
|
+
* by the trigger.
|
|
15
|
+
*/ export class SessionManager {
|
|
16
|
+
deps;
|
|
17
|
+
log;
|
|
18
|
+
fullSessions;
|
|
19
|
+
partialSessions;
|
|
20
|
+
/**
|
|
21
|
+
* Serialises every reconcile call. The trigger sources (L2BlockStream events, the
|
|
22
|
+
* periodic tick, JSON-RPC `startProof`) run independently, so without this queue two
|
|
23
|
+
* reconciles could interleave on the `await session.cancel(...)` step and orphan a
|
|
24
|
+
* freshly-constructed session.
|
|
25
|
+
*/ reconcileQueue;
|
|
26
|
+
/** Cached L1 constants, populated on first read. */ cachedL1Constants;
|
|
27
|
+
/**
|
|
28
|
+
* Highest epoch for which the periodic tick has successfully created a full session.
|
|
29
|
+
* Monotonic high-water mark: once the tick observes a session for epoch X, it stops
|
|
30
|
+
* trying to open one — even if that session subsequently fails (only a new checkpoint
|
|
31
|
+
* event reopens it). Crucially, the mark only advances when a session actually exists
|
|
32
|
+
* post-open, so transient blockers (atMaxSessionLimit, archiver still indexing) leave
|
|
33
|
+
* the mark in place and the next tick retries.
|
|
34
|
+
*/ lastTickEpoch;
|
|
35
|
+
/** Test-only hooks applied to every session this manager constructs. */ sessionHooks;
|
|
36
|
+
/** Periodic tick that nudges reconcile to pick up newly-complete epochs. Started by `start()`. */ epochTicker;
|
|
37
|
+
constructor(deps){
|
|
38
|
+
this.deps = deps;
|
|
39
|
+
this.fullSessions = new Map();
|
|
40
|
+
this.partialSessions = new Map();
|
|
41
|
+
this.reconcileQueue = new SerialQueue();
|
|
42
|
+
this.log = createLogger('prover-node:session-manager', deps.bindings);
|
|
43
|
+
this.reconcileQueue.start();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Starts the periodic tick. Separated from the constructor so tests can drive `onTick()`
|
|
47
|
+
* manually without the background ticker interleaving. Idempotent.
|
|
48
|
+
*/ start() {
|
|
49
|
+
if (this.epochTicker) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this.epochTicker = new RunningPromise(()=>this.onTick(), this.log, this.deps.config.tickIntervalMs);
|
|
53
|
+
this.epochTicker.start();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Installs hooks applied to every session constructed from now on. Used by the e2e
|
|
57
|
+
* harness to interpose around top-tree proving (gate it, override it, observe it)
|
|
58
|
+
* without monkey-patching the orchestrator factory.
|
|
59
|
+
*/ setSessionHooks(hooks) {
|
|
60
|
+
this.sessionHooks = hooks;
|
|
61
|
+
}
|
|
62
|
+
// ---------------- read-only views ----------------
|
|
63
|
+
/** Every live (non-terminal) session. */ allSessions() {
|
|
64
|
+
return [
|
|
65
|
+
...this.fullSessions.values(),
|
|
66
|
+
...this.partialSessions.values()
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
/** Returns the full session for `epoch`, if any. */ getFullSession(epoch) {
|
|
70
|
+
return this.fullSessions.get(epoch);
|
|
71
|
+
}
|
|
72
|
+
/** Returns the partial session for `spec`, if any. */ getPartialSession(spec) {
|
|
73
|
+
return this.partialSessions.get(specKey(spec));
|
|
74
|
+
}
|
|
75
|
+
/** Observability summary used by the prover-node API. */ getJobs() {
|
|
76
|
+
return this.allSessions().map((s)=>({
|
|
77
|
+
uuid: s.getId(),
|
|
78
|
+
status: s.getState(),
|
|
79
|
+
epochNumber: s.getEpochNumber()
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
// ---------------- event entry points ----------------
|
|
83
|
+
/** Called by ProverNode after a chain-checkpointed event has been added to the store. */ onCheckpointAdded(epoch) {
|
|
84
|
+
return this.scheduleReconcile({
|
|
85
|
+
kind: 'checkpoint',
|
|
86
|
+
epoch
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/** Called by ProverNode after a chain-pruned event has flipped store provers to pruned. */ onPrune(affectedEpochs) {
|
|
90
|
+
return this.scheduleReconcile({
|
|
91
|
+
kind: 'prune',
|
|
92
|
+
affectedEpochs
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Called periodically by ProverNode's ticker. Picks up epochs that have become complete
|
|
97
|
+
* by time without a fresh checkpoint event (e.g. the epoch's last slots are empty), and
|
|
98
|
+
* advances to the next epoch once the previous one is proven on L1.
|
|
99
|
+
*/ onTick() {
|
|
100
|
+
return this.scheduleReconcile({
|
|
101
|
+
kind: 'tick'
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
// ---------------- public API ----------------
|
|
105
|
+
/**
|
|
106
|
+
* Schedules a proof attempt for the supplied epoch and returns the job id without waiting for
|
|
107
|
+
* the proof to complete — proving can far outlast an HTTP request, so callers poll `getJobs()`
|
|
108
|
+
* for the outcome. Every session — full or partial — begins at the epoch's first slot; the
|
|
109
|
+
* partial's spec stops at the last canonical slot, while the full's stops at the epoch's last
|
|
110
|
+
* slot. Dedupes against any existing session covering the same range, returning its id.
|
|
111
|
+
*/ async startProof(epoch) {
|
|
112
|
+
const canonical = await this.deps.checkpointStore.listForEpoch(epoch);
|
|
113
|
+
if (canonical.length === 0) {
|
|
114
|
+
throw new EmptyEpochError(epoch);
|
|
115
|
+
}
|
|
116
|
+
// Don't re-prove an epoch the L1 proven chain already encompasses — it was already proven
|
|
117
|
+
// (possibly by another prover node), so a fresh proof would be wasted work.
|
|
118
|
+
if (await this.isProvenChainEncompassing(canonical)) {
|
|
119
|
+
throw new EpochAlreadyProvenError(epoch);
|
|
120
|
+
}
|
|
121
|
+
const l1Constants = await this.getL1Constants();
|
|
122
|
+
const [fromSlot] = getSlotRangeForEpoch(epoch, l1Constants);
|
|
123
|
+
const toSlot = canonical[canonical.length - 1].slotNumber;
|
|
124
|
+
const spec = {
|
|
125
|
+
kind: 'partial',
|
|
126
|
+
epochNumber: epoch,
|
|
127
|
+
fromSlot,
|
|
128
|
+
toSlot
|
|
129
|
+
};
|
|
130
|
+
// Reuse a session already covering this exact range rather than scheduling a duplicate.
|
|
131
|
+
const existingFull = this.getFullSession(epoch);
|
|
132
|
+
if (existingFull && !existingFull.isTerminal() && existingFull.getSpec().fromSlot === fromSlot && existingFull.getSpec().toSlot === toSlot) {
|
|
133
|
+
return existingFull.getId();
|
|
134
|
+
}
|
|
135
|
+
const existingPartial = this.getPartialSession(spec);
|
|
136
|
+
if (existingPartial && !existingPartial.isTerminal()) {
|
|
137
|
+
return existingPartial.getId();
|
|
138
|
+
}
|
|
139
|
+
await this.scheduleReconcile({
|
|
140
|
+
kind: 'start-proof',
|
|
141
|
+
spec
|
|
142
|
+
});
|
|
143
|
+
const created = this.getPartialSession(spec);
|
|
144
|
+
if (!created) {
|
|
145
|
+
throw new Error(`Failed to schedule partial proof for epoch ${epoch}`);
|
|
146
|
+
}
|
|
147
|
+
return created.getId();
|
|
148
|
+
}
|
|
149
|
+
/** Stops the tick, drains the reconcile queue, and cancels every live session. */ async stop() {
|
|
150
|
+
await this.epochTicker?.stop();
|
|
151
|
+
await this.reconcileQueue.cancel();
|
|
152
|
+
const sessions = this.allSessions();
|
|
153
|
+
await Promise.allSettled(sessions.map((s)=>s.cancel('prover-node stopping')));
|
|
154
|
+
}
|
|
155
|
+
// ---------------- reconcile ----------------
|
|
156
|
+
scheduleReconcile(trigger) {
|
|
157
|
+
return this.reconcileQueue.put(()=>this.reconcile(trigger));
|
|
158
|
+
}
|
|
159
|
+
async reconcile(trigger) {
|
|
160
|
+
this.log.debug(`Reconciling`, {
|
|
161
|
+
trigger
|
|
162
|
+
});
|
|
163
|
+
this.recreateInvalidSessions();
|
|
164
|
+
const implicatedEpochs = await this.epochsForTrigger(trigger);
|
|
165
|
+
for (const epoch of implicatedEpochs){
|
|
166
|
+
await this.openFullSessionIfReady(epoch);
|
|
167
|
+
}
|
|
168
|
+
// Advance the tick high-water mark only once a session actually exists for the epoch.
|
|
169
|
+
// `openFullSessionIfReady` can early-return without creating one (atMaxSessionLimit,
|
|
170
|
+
// archiver still indexing, etc.); in those cases we want the next tick to try again
|
|
171
|
+
// rather than skip the epoch forever.
|
|
172
|
+
if (trigger.kind === 'tick' && implicatedEpochs.length === 1) {
|
|
173
|
+
const epoch = implicatedEpochs[0];
|
|
174
|
+
if (this.fullSessions.has(epoch)) {
|
|
175
|
+
this.lastTickEpoch = epoch;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (trigger.kind === 'start-proof') {
|
|
179
|
+
this.openPartialSession(trigger.spec);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
recreateInvalidSessions() {
|
|
183
|
+
for (const [key, session] of Array.from(this.fullSessions.entries())){
|
|
184
|
+
if (session.isTerminal()) {
|
|
185
|
+
this.fullSessions.delete(key);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const canonical = this.checkpointsForSpec(session.getSpec());
|
|
189
|
+
if (!this.checkpointsMatch(session.getCheckpoints(), canonical)) {
|
|
190
|
+
this.fireAndForgetCancel(session, 'canonical content changed');
|
|
191
|
+
this.fullSessions.delete(key);
|
|
192
|
+
if (canonical.length > 0) {
|
|
193
|
+
const newSession = this.constructSession(session.getSpec(), canonical);
|
|
194
|
+
this.fullSessions.set(key, newSession);
|
|
195
|
+
void this.runSession(newSession);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
for (const [key, session] of Array.from(this.partialSessions.entries())){
|
|
200
|
+
if (session.isTerminal()) {
|
|
201
|
+
this.partialSessions.delete(key);
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
const canonical = this.checkpointsForSpec(session.getSpec());
|
|
205
|
+
if (!this.checkpointsMatch(session.getCheckpoints(), canonical)) {
|
|
206
|
+
this.fireAndForgetCancel(session, 'canonical content changed');
|
|
207
|
+
this.partialSessions.delete(key);
|
|
208
|
+
if (canonical.length > 0) {
|
|
209
|
+
const newSession = this.constructSession(session.getSpec(), canonical);
|
|
210
|
+
this.partialSessions.set(key, newSession);
|
|
211
|
+
void this.runSession(newSession);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
async openFullSessionIfReady(epoch) {
|
|
217
|
+
// `recreateInvalidSessions` runs at the top of every reconcile and deletes terminal sessions
|
|
218
|
+
// before this is called, so a session present here is live and already covers the epoch.
|
|
219
|
+
if (this.fullSessions.has(epoch)) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (this.atMaxSessionLimit()) {
|
|
223
|
+
this.log.debug(`Skipping full-session open for epoch ${epoch}: max pending jobs reached`);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (!await this.deps.l2BlockSource.isEpochComplete(epoch)) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const l1Constants = await this.getL1Constants();
|
|
230
|
+
const archiverCps = await this.deps.l2BlockSource.getCheckpoints({
|
|
231
|
+
epoch
|
|
232
|
+
});
|
|
233
|
+
if (archiverCps.length === 0) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const [fromSlot, toSlot] = getSlotRangeForEpoch(epoch, l1Constants);
|
|
237
|
+
const canonical = this.deps.checkpointStore.listInSlotRange(fromSlot, toSlot);
|
|
238
|
+
if (!this.archiverFullyCovered(archiverCps, canonical)) {
|
|
239
|
+
this.log.debug(`Skipping full-session open for epoch ${epoch}: archiver checkpoints not all in store`, {
|
|
240
|
+
archiverCount: archiverCps.length,
|
|
241
|
+
storeCount: canonical.length
|
|
242
|
+
});
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const spec = {
|
|
246
|
+
kind: 'full',
|
|
247
|
+
epochNumber: epoch,
|
|
248
|
+
fromSlot,
|
|
249
|
+
toSlot
|
|
250
|
+
};
|
|
251
|
+
const session = this.constructSession(spec, canonical);
|
|
252
|
+
this.fullSessions.set(epoch, session);
|
|
253
|
+
void this.runSession(session);
|
|
254
|
+
}
|
|
255
|
+
openPartialSession(spec) {
|
|
256
|
+
const canonical = this.deps.checkpointStore.listInSlotRange(spec.fromSlot, spec.toSlot);
|
|
257
|
+
if (canonical.length === 0) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
// Reuse a live partial session for this epoch whose checkpoint set already matches the
|
|
261
|
+
// canonical content — e.g. a repeated `startProof` with no new checkpoints mined since the
|
|
262
|
+
// last one. Reconstructing would re-prove identical content and burn a pending-job slot.
|
|
263
|
+
const existing = Array.from(this.partialSessions.values()).find((s)=>s.getSpec().epochNumber === spec.epochNumber && !s.isTerminal() && this.checkpointsMatch(s.getCheckpoints(), canonical));
|
|
264
|
+
if (existing) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (this.atMaxSessionLimit()) {
|
|
268
|
+
throw new Error(`Maximum pending proving jobs ${this.deps.config.maxPendingJobs} reached.`);
|
|
269
|
+
}
|
|
270
|
+
const session = this.constructSession(spec, canonical);
|
|
271
|
+
this.partialSessions.set(specKey(spec), session);
|
|
272
|
+
void this.runSession(session);
|
|
273
|
+
}
|
|
274
|
+
// ---------------- session construction ----------------
|
|
275
|
+
constructSession(spec, checkpoints) {
|
|
276
|
+
return this.doConstructSession(spec, checkpoints, this.buildSessionDeps(spec.epochNumber), this.sessionHooks);
|
|
277
|
+
}
|
|
278
|
+
/** Extracted for test override. */ doConstructSession(spec, checkpoints, sessionDeps, hooks) {
|
|
279
|
+
return new EpochSession(spec, checkpoints, {
|
|
280
|
+
...sessionDeps,
|
|
281
|
+
hooks
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
buildSessionDeps(epochNumber) {
|
|
285
|
+
const config = {
|
|
286
|
+
finalizationDelayMs: this.deps.config.finalizationDelayMs
|
|
287
|
+
};
|
|
288
|
+
return {
|
|
289
|
+
proverFactory: this.deps.proverFactory,
|
|
290
|
+
proverId: this.deps.proverId,
|
|
291
|
+
publishingService: this.deps.publishingService,
|
|
292
|
+
metrics: this.deps.metrics,
|
|
293
|
+
dateProvider: this.deps.dateProvider,
|
|
294
|
+
deadline: this.computeDeadline(epochNumber),
|
|
295
|
+
config,
|
|
296
|
+
bindings: this.deps.bindings
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
computeDeadline(epochNumber) {
|
|
300
|
+
if (!this.cachedL1Constants) {
|
|
301
|
+
return undefined;
|
|
302
|
+
}
|
|
303
|
+
const ts = getProofSubmissionDeadlineTimestamp(epochNumber, this.cachedL1Constants);
|
|
304
|
+
return new Date(Number(ts) * 1000);
|
|
305
|
+
}
|
|
306
|
+
async runSession(session) {
|
|
307
|
+
// A reconcile may have cancelled this session before it starts (content-change
|
|
308
|
+
// recreation). Don't proceed — start() would build a TopTreeJob that should never run.
|
|
309
|
+
if (session.isTerminal()) {
|
|
310
|
+
this.log.debug(`Skipping start for ${session.getId()}: already terminal (${session.getState()})`);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const state = await session.start();
|
|
314
|
+
this.log.info(`Session ${session.getId()} exited with state ${state}`);
|
|
315
|
+
if (state === 'failed' && this.deps.onSessionFailed) {
|
|
316
|
+
// Best-effort suppression of the spurious post-mortem upload a prune produces: if the session's
|
|
317
|
+
// checkpoints no longer match the store's current set, the failure was caused by the content
|
|
318
|
+
// changing under it, not a genuine proving fault, so skip the upload. This is inherently racy —
|
|
319
|
+
// the store lags the world-state unwind, so a fault observed before the prune is reconciled here
|
|
320
|
+
// still uploads. The epoch is recovered regardless by recreating the session on re-add.
|
|
321
|
+
if (!this.checkpointsMatch(session.getCheckpoints(), this.checkpointsForSpec(session.getSpec()))) {
|
|
322
|
+
this.log.info(`Skipping failure upload for session ${session.getId()}: canonical content changed`, {
|
|
323
|
+
...session.getSpec()
|
|
324
|
+
});
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
try {
|
|
328
|
+
await this.deps.onSessionFailed(session);
|
|
329
|
+
} catch (err) {
|
|
330
|
+
this.log.error(`Error in onSessionFailed callback for ${session.getSpec().epochNumber}`, err);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Builds the EpochProvingJobData snapshot for failure upload. Includes every checkpoint
|
|
336
|
+
* referenced by the session, regardless of whether sub-tree proving completed —
|
|
337
|
+
* partial state is still useful for post-mortem analysis.
|
|
338
|
+
*/ static buildSessionProvingData(session) {
|
|
339
|
+
const checkpoints = session.getCheckpoints();
|
|
340
|
+
const txs = new Map();
|
|
341
|
+
const l1ToL2Messages = {};
|
|
342
|
+
for (const c of checkpoints){
|
|
343
|
+
for (const [hash, tx] of c.txs){
|
|
344
|
+
txs.set(hash, tx);
|
|
345
|
+
}
|
|
346
|
+
l1ToL2Messages[c.checkpoint.number] = c.l1ToL2Messages;
|
|
347
|
+
}
|
|
348
|
+
return {
|
|
349
|
+
epochNumber: session.getSpec().epochNumber,
|
|
350
|
+
checkpoints: checkpoints.map((c)=>c.checkpoint),
|
|
351
|
+
txs,
|
|
352
|
+
l1ToL2Messages,
|
|
353
|
+
previousBlockHeader: checkpoints[0].previousBlockHeader,
|
|
354
|
+
attestations: []
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
// ---------------- reconcile helpers ----------------
|
|
358
|
+
atMaxSessionLimit() {
|
|
359
|
+
const { maxPendingJobs: max } = this.deps.config;
|
|
360
|
+
if (!max || max <= 0) {
|
|
361
|
+
return false;
|
|
362
|
+
}
|
|
363
|
+
const live = this.allSessions().filter((s)=>!s.isTerminal()).length;
|
|
364
|
+
return live >= max;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Maps a reconcile trigger to the epochs whose full session should be (re)opened.
|
|
368
|
+
*
|
|
369
|
+
* This is where the "don't retry a genuinely-failed epoch, but do recover a pruned one" invariant
|
|
370
|
+
* lives — enforced by which triggers are gated by `lastTickEpoch`:
|
|
371
|
+
*
|
|
372
|
+
* - The periodic `tick` IS gated: once a tick has opened a session for an epoch, `lastTickEpoch`
|
|
373
|
+
* advances to it and later ticks skip it (`epoch <= lastTickEpoch`). So a failed attempt is never
|
|
374
|
+
* resubmitted on a loop by the tick.
|
|
375
|
+
* - `checkpoint` and `prune` are deliberately NOT gated. They only fire when the epoch's canonical
|
|
376
|
+
* content actually changes — a checkpoint arrives, or a reorg prunes/replaces one — which is
|
|
377
|
+
* exactly when re-attempting is correct.
|
|
378
|
+
*
|
|
379
|
+
* A genuine proving failure produces no content change, hence no checkpoint/prune event, so only
|
|
380
|
+
* the gated tick could reopen it — and it won't. A prune + re-add fires ungated events, so the
|
|
381
|
+
* epoch is reopened through this path (and `openFullSessionIfReady` rebuilds over the fresh
|
|
382
|
+
* provers). See the "onTick does not retry ... but recovers ... re-added" test.
|
|
383
|
+
*/ async epochsForTrigger(trigger) {
|
|
384
|
+
switch(trigger.kind){
|
|
385
|
+
case 'checkpoint':
|
|
386
|
+
return [
|
|
387
|
+
trigger.epoch
|
|
388
|
+
];
|
|
389
|
+
case 'prune':
|
|
390
|
+
return trigger.affectedEpochs;
|
|
391
|
+
case 'tick':
|
|
392
|
+
{
|
|
393
|
+
const epoch = await this.nextUnprovenEpoch();
|
|
394
|
+
if (epoch === undefined || this.lastTickEpoch !== undefined && epoch <= this.lastTickEpoch) {
|
|
395
|
+
return [];
|
|
396
|
+
}
|
|
397
|
+
return [
|
|
398
|
+
epoch
|
|
399
|
+
];
|
|
400
|
+
}
|
|
401
|
+
case 'start-proof':
|
|
402
|
+
return [];
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* The next epoch to prove: the epoch containing the first block after the proven tip.
|
|
407
|
+
* Returns undefined when that block has not been mined yet (e.g. nothing new to prove).
|
|
408
|
+
* Subsequent ticks advance only once the chain's proven height moves forward, so epochs
|
|
409
|
+
* are proven in order rather than all at once.
|
|
410
|
+
*/ async nextUnprovenEpoch() {
|
|
411
|
+
const lastProven = await this.deps.l2BlockSource.getBlockNumber({
|
|
412
|
+
tag: 'proven'
|
|
413
|
+
}) ?? BlockNumber.ZERO;
|
|
414
|
+
const firstToProve = BlockNumber(lastProven + 1);
|
|
415
|
+
const header = (await this.deps.l2BlockSource.getBlockData({
|
|
416
|
+
number: firstToProve
|
|
417
|
+
}))?.header;
|
|
418
|
+
if (!header) {
|
|
419
|
+
return undefined;
|
|
420
|
+
}
|
|
421
|
+
return getEpochAtSlot(header.getSlot(), await this.getL1Constants());
|
|
422
|
+
}
|
|
423
|
+
checkpointsForSpec(spec) {
|
|
424
|
+
return this.deps.checkpointStore.listInSlotRange(spec.fromSlot, spec.toSlot);
|
|
425
|
+
}
|
|
426
|
+
fireAndForgetCancel(session, reason) {
|
|
427
|
+
void session.cancel(reason).catch((err)=>this.log.warn(`Error cancelling session ${session.getId()}`, err));
|
|
428
|
+
}
|
|
429
|
+
checkpointsMatch(a, b) {
|
|
430
|
+
if (a.length !== b.length) {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
for(let i = 0; i < a.length; i++){
|
|
434
|
+
if (a[i].id !== b[i].id || a[i].isCancelled()) {
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return true;
|
|
439
|
+
}
|
|
440
|
+
archiverFullyCovered(archiverCps, storeCps) {
|
|
441
|
+
if (storeCps.length < archiverCps.length) {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
// Compare by content-addressed id (number, slot, archive root) rather than checkpoint number:
|
|
445
|
+
// a reorg can keep the number while changing the checkpoint's post-state archive root.
|
|
446
|
+
const storeIds = new Set(storeCps.map((p)=>p.id));
|
|
447
|
+
return archiverCps.every((cp)=>storeIds.has(CheckpointProver.idFor(cp.checkpoint)));
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Returns true if the L1 proven tip already covers every canonical checkpoint in the set — i.e.
|
|
451
|
+
* the epoch has already been fully proven, so there is no point starting a new proof for it.
|
|
452
|
+
* Conservatively returns false when nothing is proven yet.
|
|
453
|
+
*/ async isProvenChainEncompassing(canonical) {
|
|
454
|
+
const provenBlock = await this.deps.l2BlockSource.getBlockNumber({
|
|
455
|
+
tag: 'proven'
|
|
456
|
+
});
|
|
457
|
+
if (!provenBlock || provenBlock <= 0) {
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
const lastCheckpoint = canonical[canonical.length - 1].checkpoint;
|
|
461
|
+
const lastBlock = lastCheckpoint.blocks[lastCheckpoint.blocks.length - 1].number;
|
|
462
|
+
return provenBlock >= lastBlock;
|
|
463
|
+
}
|
|
464
|
+
async getL1Constants() {
|
|
465
|
+
if (!this.cachedL1Constants) {
|
|
466
|
+
this.cachedL1Constants = await this.deps.l2BlockSource.getL1Constants();
|
|
467
|
+
}
|
|
468
|
+
return this.cachedL1Constants;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
class EmptyEpochError extends Error {
|
|
472
|
+
constructor(epochNumber){
|
|
473
|
+
super(`No blocks found for epoch ${epochNumber}`);
|
|
474
|
+
this.name = 'EmptyEpochError';
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
class EpochAlreadyProvenError extends Error {
|
|
478
|
+
constructor(epochNumber){
|
|
479
|
+
super(`Epoch ${epochNumber} is already proven on L1`);
|
|
480
|
+
this.name = 'EpochAlreadyProvenError';
|
|
481
|
+
}
|
|
482
|
+
}
|
package/dest/test/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import type { EpochProverFactory } from '@aztec/prover-client';
|
|
1
2
|
import type { EpochProverManager } from '@aztec/stdlib/interfaces/server';
|
|
2
|
-
import type {
|
|
3
|
-
import type { ProverNodePublisher } from '../prover-node-publisher.js';
|
|
3
|
+
import type { ProofPublishingService } from '../proof-publishing-service.js';
|
|
4
4
|
import { ProverNode } from '../prover-node.js';
|
|
5
|
+
import type { SessionManager } from '../session-manager.js';
|
|
5
6
|
declare abstract class TestProverNodeClass extends ProverNode {
|
|
6
|
-
prover: EpochProverManager;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
prover: EpochProverManager & EpochProverFactory;
|
|
8
|
+
publishingService: ProofPublishingService;
|
|
9
|
+
sessionManager: SessionManager;
|
|
9
10
|
}
|
|
10
11
|
export type TestProverNode = TestProverNodeClass;
|
|
11
12
|
export {};
|
|
12
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
13
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0L2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGtCQUFrQixFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFDL0QsT0FBTyxLQUFLLEVBQUUsa0JBQWtCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUUxRSxPQUFPLEtBQUssRUFBRSxzQkFBc0IsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBQzdFLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUMvQyxPQUFPLEtBQUssRUFBRSxjQUFjLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUU1RCx1QkFBZSxtQkFBb0IsU0FBUSxVQUFVO0lBQ3BDLE1BQU0sRUFBRSxrQkFBa0IsR0FBRyxrQkFBa0IsQ0FBQztJQUNoRCxpQkFBaUIsRUFBRSxzQkFBc0IsQ0FBQztJQUMxQyxjQUFjLEVBQUUsY0FBYyxDQUFDO0NBQy9DO0FBRUQsTUFBTSxNQUFNLGNBQWMsR0FBRyxtQkFBbUIsQ0FBQyJ9
|
package/dest/test/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAE1E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,uBAAe,mBAAoB,SAAQ,UAAU;IACpC,MAAM,EAAE,kBAAkB,GAAG,kBAAkB,CAAC;IAChD,iBAAiB,EAAE,sBAAsB,CAAC;IAC1C,cAAc,EAAE,cAAc,CAAC;CAC/C;AAED,MAAM,MAAM,cAAc,GAAG,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/prover-node",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.3100065",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -56,28 +56,28 @@
|
|
|
56
56
|
]
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@aztec/archiver": "0.0.1-commit.
|
|
60
|
-
"@aztec/bb-prover": "0.0.1-commit.
|
|
61
|
-
"@aztec/blob-client": "0.0.1-commit.
|
|
62
|
-
"@aztec/blob-lib": "0.0.1-commit.
|
|
63
|
-
"@aztec/constants": "0.0.1-commit.
|
|
64
|
-
"@aztec/epoch-cache": "0.0.1-commit.
|
|
65
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
66
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
67
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
68
|
-
"@aztec/l1-artifacts": "0.0.1-commit.
|
|
69
|
-
"@aztec/native": "0.0.1-commit.
|
|
70
|
-
"@aztec/node-keystore": "0.0.1-commit.
|
|
71
|
-
"@aztec/node-lib": "0.0.1-commit.
|
|
72
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
73
|
-
"@aztec/p2p": "0.0.1-commit.
|
|
74
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
75
|
-
"@aztec/prover-client": "0.0.1-commit.
|
|
76
|
-
"@aztec/sequencer-client": "0.0.1-commit.
|
|
77
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
78
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
79
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
80
|
-
"@aztec/world-state": "0.0.1-commit.
|
|
59
|
+
"@aztec/archiver": "0.0.1-commit.3100065",
|
|
60
|
+
"@aztec/bb-prover": "0.0.1-commit.3100065",
|
|
61
|
+
"@aztec/blob-client": "0.0.1-commit.3100065",
|
|
62
|
+
"@aztec/blob-lib": "0.0.1-commit.3100065",
|
|
63
|
+
"@aztec/constants": "0.0.1-commit.3100065",
|
|
64
|
+
"@aztec/epoch-cache": "0.0.1-commit.3100065",
|
|
65
|
+
"@aztec/ethereum": "0.0.1-commit.3100065",
|
|
66
|
+
"@aztec/foundation": "0.0.1-commit.3100065",
|
|
67
|
+
"@aztec/kv-store": "0.0.1-commit.3100065",
|
|
68
|
+
"@aztec/l1-artifacts": "0.0.1-commit.3100065",
|
|
69
|
+
"@aztec/native": "0.0.1-commit.3100065",
|
|
70
|
+
"@aztec/node-keystore": "0.0.1-commit.3100065",
|
|
71
|
+
"@aztec/node-lib": "0.0.1-commit.3100065",
|
|
72
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.3100065",
|
|
73
|
+
"@aztec/p2p": "0.0.1-commit.3100065",
|
|
74
|
+
"@aztec/protocol-contracts": "0.0.1-commit.3100065",
|
|
75
|
+
"@aztec/prover-client": "0.0.1-commit.3100065",
|
|
76
|
+
"@aztec/sequencer-client": "0.0.1-commit.3100065",
|
|
77
|
+
"@aztec/simulator": "0.0.1-commit.3100065",
|
|
78
|
+
"@aztec/stdlib": "0.0.1-commit.3100065",
|
|
79
|
+
"@aztec/telemetry-client": "0.0.1-commit.3100065",
|
|
80
|
+
"@aztec/world-state": "0.0.1-commit.3100065",
|
|
81
81
|
"source-map-support": "^0.5.21",
|
|
82
82
|
"tslib": "^2.4.0",
|
|
83
83
|
"viem": "npm:@aztec/viem@2.38.2"
|