@aztec/prover-node 0.0.0-test.0 → 0.0.1-commit.001888fc

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 (82) hide show
  1. package/dest/actions/download-epoch-proving-job.d.ts +18 -0
  2. package/dest/actions/download-epoch-proving-job.d.ts.map +1 -0
  3. package/dest/actions/download-epoch-proving-job.js +37 -0
  4. package/dest/actions/index.d.ts +3 -0
  5. package/dest/actions/index.d.ts.map +1 -0
  6. package/dest/actions/index.js +2 -0
  7. package/dest/actions/rerun-epoch-proving-job.d.ts +12 -0
  8. package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -0
  9. package/dest/actions/rerun-epoch-proving-job.js +40 -0
  10. package/dest/actions/upload-epoch-proof-failure.d.ts +15 -0
  11. package/dest/actions/upload-epoch-proof-failure.d.ts.map +1 -0
  12. package/dest/actions/upload-epoch-proof-failure.js +78 -0
  13. package/dest/bin/run-failed-epoch.d.ts +2 -0
  14. package/dest/bin/run-failed-epoch.d.ts.map +1 -0
  15. package/dest/bin/run-failed-epoch.js +70 -0
  16. package/dest/config.d.ts +17 -16
  17. package/dest/config.d.ts.map +1 -1
  18. package/dest/config.js +93 -28
  19. package/dest/factory.d.ts +26 -18
  20. package/dest/factory.d.ts.map +1 -1
  21. package/dest/factory.js +72 -42
  22. package/dest/index.d.ts +3 -2
  23. package/dest/index.d.ts.map +1 -1
  24. package/dest/index.js +2 -1
  25. package/dest/job/epoch-proving-job-data.d.ts +18 -0
  26. package/dest/job/epoch-proving-job-data.d.ts.map +1 -0
  27. package/dest/job/epoch-proving-job-data.js +59 -0
  28. package/dest/job/epoch-proving-job.d.ts +27 -18
  29. package/dest/job/epoch-proving-job.d.ts.map +1 -1
  30. package/dest/job/epoch-proving-job.js +604 -97
  31. package/dest/metrics.d.ts +40 -5
  32. package/dest/metrics.d.ts.map +1 -1
  33. package/dest/metrics.js +136 -73
  34. package/dest/monitors/epoch-monitor.d.ts +5 -2
  35. package/dest/monitors/epoch-monitor.d.ts.map +1 -1
  36. package/dest/monitors/epoch-monitor.js +18 -15
  37. package/dest/monitors/index.d.ts +1 -1
  38. package/dest/prover-node-publisher.d.ts +19 -19
  39. package/dest/prover-node-publisher.d.ts.map +1 -1
  40. package/dest/prover-node-publisher.js +90 -84
  41. package/dest/prover-node.d.ts +61 -46
  42. package/dest/prover-node.d.ts.map +1 -1
  43. package/dest/prover-node.js +592 -135
  44. package/dest/prover-publisher-factory.d.ts +25 -0
  45. package/dest/prover-publisher-factory.d.ts.map +1 -0
  46. package/dest/prover-publisher-factory.js +28 -0
  47. package/dest/test/index.d.ts +5 -3
  48. package/dest/test/index.d.ts.map +1 -1
  49. package/dest/test/index.js +1 -3
  50. package/package.json +40 -33
  51. package/src/actions/download-epoch-proving-job.ts +44 -0
  52. package/src/actions/index.ts +2 -0
  53. package/src/actions/rerun-epoch-proving-job.ts +63 -0
  54. package/src/actions/upload-epoch-proof-failure.ts +88 -0
  55. package/src/bin/run-failed-epoch.ts +80 -0
  56. package/src/config.ts +123 -45
  57. package/src/factory.ts +146 -66
  58. package/src/index.ts +2 -1
  59. package/src/job/epoch-proving-job-data.ts +82 -0
  60. package/src/job/epoch-proving-job.ts +295 -85
  61. package/src/metrics.ts +153 -72
  62. package/src/monitors/epoch-monitor.ts +21 -17
  63. package/src/prover-node-publisher.ts +139 -119
  64. package/src/prover-node.ts +238 -149
  65. package/src/prover-publisher-factory.ts +45 -0
  66. package/src/test/index.ts +7 -4
  67. package/dest/http.d.ts +0 -8
  68. package/dest/http.d.ts.map +0 -1
  69. package/dest/http.js +0 -9
  70. package/dest/prover-coordination/config.d.ts +0 -7
  71. package/dest/prover-coordination/config.d.ts.map +0 -1
  72. package/dest/prover-coordination/config.js +0 -11
  73. package/dest/prover-coordination/factory.d.ts +0 -22
  74. package/dest/prover-coordination/factory.d.ts.map +0 -1
  75. package/dest/prover-coordination/factory.js +0 -42
  76. package/dest/prover-coordination/index.d.ts +0 -3
  77. package/dest/prover-coordination/index.d.ts.map +0 -1
  78. package/dest/prover-coordination/index.js +0 -2
  79. package/src/http.ts +0 -13
  80. package/src/prover-coordination/config.ts +0 -17
  81. package/src/prover-coordination/factory.ts +0 -72
  82. package/src/prover-coordination/index.ts +0 -2
@@ -1,60 +1,448 @@
1
- function _ts_decorate(decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1
+ function applyDecs2203RFactory() {
2
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
3
+ return function addInitializer(initializer) {
4
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
5
+ assertCallable(initializer, "An initializer");
6
+ initializers.push(initializer);
7
+ };
8
+ }
9
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
10
+ var kindStr;
11
+ switch(kind){
12
+ case 1:
13
+ kindStr = "accessor";
14
+ break;
15
+ case 2:
16
+ kindStr = "method";
17
+ break;
18
+ case 3:
19
+ kindStr = "getter";
20
+ break;
21
+ case 4:
22
+ kindStr = "setter";
23
+ break;
24
+ default:
25
+ kindStr = "field";
26
+ }
27
+ var ctx = {
28
+ kind: kindStr,
29
+ name: isPrivate ? "#" + name : name,
30
+ static: isStatic,
31
+ private: isPrivate,
32
+ metadata: metadata
33
+ };
34
+ var decoratorFinishedRef = {
35
+ v: false
36
+ };
37
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
38
+ var get, set;
39
+ if (kind === 0) {
40
+ if (isPrivate) {
41
+ get = desc.get;
42
+ set = desc.set;
43
+ } else {
44
+ get = function() {
45
+ return this[name];
46
+ };
47
+ set = function(v) {
48
+ this[name] = v;
49
+ };
50
+ }
51
+ } else if (kind === 2) {
52
+ get = function() {
53
+ return desc.value;
54
+ };
55
+ } else {
56
+ if (kind === 1 || kind === 3) {
57
+ get = function() {
58
+ return desc.get.call(this);
59
+ };
60
+ }
61
+ if (kind === 1 || kind === 4) {
62
+ set = function(v) {
63
+ desc.set.call(this, v);
64
+ };
65
+ }
66
+ }
67
+ ctx.access = get && set ? {
68
+ get: get,
69
+ set: set
70
+ } : get ? {
71
+ get: get
72
+ } : {
73
+ set: set
74
+ };
75
+ try {
76
+ return dec(value, ctx);
77
+ } finally{
78
+ decoratorFinishedRef.v = true;
79
+ }
80
+ }
81
+ function assertNotFinished(decoratorFinishedRef, fnName) {
82
+ if (decoratorFinishedRef.v) {
83
+ throw new Error("attempted to call " + fnName + " after decoration was finished");
84
+ }
85
+ }
86
+ function assertCallable(fn, hint) {
87
+ if (typeof fn !== "function") {
88
+ throw new TypeError(hint + " must be a function");
89
+ }
90
+ }
91
+ function assertValidReturnValue(kind, value) {
92
+ var type = typeof value;
93
+ if (kind === 1) {
94
+ if (type !== "object" || value === null) {
95
+ throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
96
+ }
97
+ if (value.get !== undefined) {
98
+ assertCallable(value.get, "accessor.get");
99
+ }
100
+ if (value.set !== undefined) {
101
+ assertCallable(value.set, "accessor.set");
102
+ }
103
+ if (value.init !== undefined) {
104
+ assertCallable(value.init, "accessor.init");
105
+ }
106
+ } else if (type !== "function") {
107
+ var hint;
108
+ if (kind === 0) {
109
+ hint = "field";
110
+ } else if (kind === 10) {
111
+ hint = "class";
112
+ } else {
113
+ hint = "method";
114
+ }
115
+ throw new TypeError(hint + " decorators must return a function or void 0");
116
+ }
117
+ }
118
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
119
+ var decs = decInfo[0];
120
+ var desc, init, value;
121
+ if (isPrivate) {
122
+ if (kind === 0 || kind === 1) {
123
+ desc = {
124
+ get: decInfo[3],
125
+ set: decInfo[4]
126
+ };
127
+ } else if (kind === 3) {
128
+ desc = {
129
+ get: decInfo[3]
130
+ };
131
+ } else if (kind === 4) {
132
+ desc = {
133
+ set: decInfo[3]
134
+ };
135
+ } else {
136
+ desc = {
137
+ value: decInfo[3]
138
+ };
139
+ }
140
+ } else if (kind !== 0) {
141
+ desc = Object.getOwnPropertyDescriptor(base, name);
142
+ }
143
+ if (kind === 1) {
144
+ value = {
145
+ get: desc.get,
146
+ set: desc.set
147
+ };
148
+ } else if (kind === 2) {
149
+ value = desc.value;
150
+ } else if (kind === 3) {
151
+ value = desc.get;
152
+ } else if (kind === 4) {
153
+ value = desc.set;
154
+ }
155
+ var newValue, get, set;
156
+ if (typeof decs === "function") {
157
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
158
+ if (newValue !== void 0) {
159
+ assertValidReturnValue(kind, newValue);
160
+ if (kind === 0) {
161
+ init = newValue;
162
+ } else if (kind === 1) {
163
+ init = newValue.init;
164
+ get = newValue.get || value.get;
165
+ set = newValue.set || value.set;
166
+ value = {
167
+ get: get,
168
+ set: set
169
+ };
170
+ } else {
171
+ value = newValue;
172
+ }
173
+ }
174
+ } else {
175
+ for(var i = decs.length - 1; i >= 0; i--){
176
+ var dec = decs[i];
177
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
178
+ if (newValue !== void 0) {
179
+ assertValidReturnValue(kind, newValue);
180
+ var newInit;
181
+ if (kind === 0) {
182
+ newInit = newValue;
183
+ } else if (kind === 1) {
184
+ newInit = newValue.init;
185
+ get = newValue.get || value.get;
186
+ set = newValue.set || value.set;
187
+ value = {
188
+ get: get,
189
+ set: set
190
+ };
191
+ } else {
192
+ value = newValue;
193
+ }
194
+ if (newInit !== void 0) {
195
+ if (init === void 0) {
196
+ init = newInit;
197
+ } else if (typeof init === "function") {
198
+ init = [
199
+ init,
200
+ newInit
201
+ ];
202
+ } else {
203
+ init.push(newInit);
204
+ }
205
+ }
206
+ }
207
+ }
208
+ }
209
+ if (kind === 0 || kind === 1) {
210
+ if (init === void 0) {
211
+ init = function(instance, init) {
212
+ return init;
213
+ };
214
+ } else if (typeof init !== "function") {
215
+ var ownInitializers = init;
216
+ init = function(instance, init) {
217
+ var value = init;
218
+ for(var i = 0; i < ownInitializers.length; i++){
219
+ value = ownInitializers[i].call(instance, value);
220
+ }
221
+ return value;
222
+ };
223
+ } else {
224
+ var originalInitializer = init;
225
+ init = function(instance, init) {
226
+ return originalInitializer.call(instance, init);
227
+ };
228
+ }
229
+ ret.push(init);
230
+ }
231
+ if (kind !== 0) {
232
+ if (kind === 1) {
233
+ desc.get = value.get;
234
+ desc.set = value.set;
235
+ } else if (kind === 2) {
236
+ desc.value = value;
237
+ } else if (kind === 3) {
238
+ desc.get = value;
239
+ } else if (kind === 4) {
240
+ desc.set = value;
241
+ }
242
+ if (isPrivate) {
243
+ if (kind === 1) {
244
+ ret.push(function(instance, args) {
245
+ return value.get.call(instance, args);
246
+ });
247
+ ret.push(function(instance, args) {
248
+ return value.set.call(instance, args);
249
+ });
250
+ } else if (kind === 2) {
251
+ ret.push(value);
252
+ } else {
253
+ ret.push(function(instance, args) {
254
+ return value.call(instance, args);
255
+ });
256
+ }
257
+ } else {
258
+ Object.defineProperty(base, name, desc);
259
+ }
260
+ }
261
+ }
262
+ function applyMemberDecs(Class, decInfos, metadata) {
263
+ var ret = [];
264
+ var protoInitializers;
265
+ var staticInitializers;
266
+ var existingProtoNonFields = new Map();
267
+ var existingStaticNonFields = new Map();
268
+ for(var i = 0; i < decInfos.length; i++){
269
+ var decInfo = decInfos[i];
270
+ if (!Array.isArray(decInfo)) continue;
271
+ var kind = decInfo[1];
272
+ var name = decInfo[2];
273
+ var isPrivate = decInfo.length > 3;
274
+ var isStatic = kind >= 5;
275
+ var base;
276
+ var initializers;
277
+ if (isStatic) {
278
+ base = Class;
279
+ kind = kind - 5;
280
+ staticInitializers = staticInitializers || [];
281
+ initializers = staticInitializers;
282
+ } else {
283
+ base = Class.prototype;
284
+ protoInitializers = protoInitializers || [];
285
+ initializers = protoInitializers;
286
+ }
287
+ if (kind !== 0 && !isPrivate) {
288
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
289
+ var existingKind = existingNonFields.get(name) || 0;
290
+ if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
291
+ throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
292
+ } else if (!existingKind && kind > 2) {
293
+ existingNonFields.set(name, kind);
294
+ } else {
295
+ existingNonFields.set(name, true);
296
+ }
297
+ }
298
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
299
+ }
300
+ pushInitializers(ret, protoInitializers);
301
+ pushInitializers(ret, staticInitializers);
302
+ return ret;
303
+ }
304
+ function pushInitializers(ret, initializers) {
305
+ if (initializers) {
306
+ ret.push(function(instance) {
307
+ for(var i = 0; i < initializers.length; i++){
308
+ initializers[i].call(instance);
309
+ }
310
+ return instance;
311
+ });
312
+ }
313
+ }
314
+ function applyClassDecs(targetClass, classDecs, metadata) {
315
+ if (classDecs.length > 0) {
316
+ var initializers = [];
317
+ var newClass = targetClass;
318
+ var name = targetClass.name;
319
+ for(var i = classDecs.length - 1; i >= 0; i--){
320
+ var decoratorFinishedRef = {
321
+ v: false
322
+ };
323
+ try {
324
+ var nextNewClass = classDecs[i](newClass, {
325
+ kind: "class",
326
+ name: name,
327
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
328
+ metadata
329
+ });
330
+ } finally{
331
+ decoratorFinishedRef.v = true;
332
+ }
333
+ if (nextNewClass !== undefined) {
334
+ assertValidReturnValue(10, nextNewClass);
335
+ newClass = nextNewClass;
336
+ }
337
+ }
338
+ return [
339
+ defineMetadata(newClass, metadata),
340
+ function() {
341
+ for(var i = 0; i < initializers.length; i++){
342
+ initializers[i].call(newClass);
343
+ }
344
+ }
345
+ ];
346
+ }
347
+ }
348
+ function defineMetadata(Class, metadata) {
349
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
350
+ configurable: true,
351
+ enumerable: true,
352
+ value: metadata
353
+ });
354
+ }
355
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
356
+ if (parentClass !== void 0) {
357
+ var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
358
+ }
359
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
360
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
361
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
362
+ return {
363
+ e: e,
364
+ get c () {
365
+ return applyClassDecs(targetClass, classDecs, metadata);
366
+ }
367
+ };
368
+ };
369
+ }
370
+ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
371
+ return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
6
372
  }
373
+ var _dec, _initProto;
374
+ import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
7
375
  import { asyncPool } from '@aztec/foundation/async-pool';
376
+ import { BlockNumber } from '@aztec/foundation/branded-types';
377
+ import { padArrayEnd } from '@aztec/foundation/collection';
378
+ import { Fr } from '@aztec/foundation/curves/bn254';
8
379
  import { createLogger } from '@aztec/foundation/log';
9
- import { promiseWithResolvers } from '@aztec/foundation/promise';
380
+ import { RunningPromise, promiseWithResolvers } from '@aztec/foundation/promise';
10
381
  import { Timer } from '@aztec/foundation/timer';
382
+ import { AVM_MAX_CONCURRENT_SIMULATIONS } from '@aztec/native';
383
+ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
384
+ import { protocolContractsHash } from '@aztec/protocol-contracts';
385
+ import { buildFinalBlobChallenges } from '@aztec/prover-client/helpers';
386
+ import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
11
387
  import { EpochProvingJobTerminalState } from '@aztec/stdlib/interfaces/server';
388
+ import { CheckpointConstantData } from '@aztec/stdlib/rollup';
389
+ import { MerkleTreeId } from '@aztec/stdlib/trees';
12
390
  import { Attributes, trackSpan } from '@aztec/telemetry-client';
13
391
  import * as crypto from 'node:crypto';
392
+ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
393
+ _dec = trackSpan('EpochProvingJob.run', function() {
394
+ return {
395
+ [Attributes.EPOCH_NUMBER]: this.data.epochNumber
396
+ };
397
+ });
14
398
  /**
15
- * Job that grabs a range of blocks from the unfinalised chain from L1, gets their txs given their hashes,
399
+ * Job that grabs a range of blocks from the unfinalized chain from L1, gets their txs given their hashes,
16
400
  * re-executes their public calls, generates a rollup proof, and submits it to L1. This job will update the
17
401
  * world state as part of public call execution via the public processor.
18
402
  */ export class EpochProvingJob {
403
+ data;
19
404
  dbProvider;
20
- epochNumber;
21
- blocks;
22
- txs;
23
405
  prover;
24
406
  publicProcessorFactory;
25
407
  publisher;
26
408
  l2BlockSource;
27
- l1ToL2MessageSource;
28
409
  metrics;
29
410
  deadline;
30
411
  config;
31
- cleanUp;
412
+ static{
413
+ ({ e: [_initProto] } = _apply_decs_2203_r(this, [
414
+ [
415
+ _dec,
416
+ 2,
417
+ "run"
418
+ ]
419
+ ], []));
420
+ }
32
421
  state;
33
422
  log;
34
423
  uuid;
35
424
  runPromise;
425
+ epochCheckPromise;
36
426
  deadlineTimeoutHandler;
37
427
  tracer;
38
- constructor(dbProvider, epochNumber, blocks, txs, prover, publicProcessorFactory, publisher, l2BlockSource, l1ToL2MessageSource, metrics, deadline, config = {
39
- parallelBlockLimit: 32
40
- }, cleanUp = ()=>Promise.resolve()){
428
+ constructor(data, dbProvider, prover, publicProcessorFactory, publisher, l2BlockSource, metrics, deadline, config, bindings){
429
+ this.data = data;
41
430
  this.dbProvider = dbProvider;
42
- this.epochNumber = epochNumber;
43
- this.blocks = blocks;
44
- this.txs = txs;
45
431
  this.prover = prover;
46
432
  this.publicProcessorFactory = publicProcessorFactory;
47
433
  this.publisher = publisher;
48
434
  this.l2BlockSource = l2BlockSource;
49
- this.l1ToL2MessageSource = l1ToL2MessageSource;
50
435
  this.metrics = metrics;
51
436
  this.deadline = deadline;
52
437
  this.config = config;
53
- this.cleanUp = cleanUp;
54
- this.state = 'initialized';
55
- this.log = createLogger('prover-node:epoch-proving-job');
438
+ this.state = (_initProto(this), 'initialized');
439
+ validateEpochProvingJobData(data);
56
440
  this.uuid = crypto.randomUUID();
57
- this.tracer = metrics.client.getTracer('EpochProvingJob');
441
+ this.log = createLogger('prover-node:epoch-proving-job', {
442
+ ...bindings,
443
+ instanceId: `epoch-${data.epochNumber}`
444
+ });
445
+ this.tracer = metrics.tracer;
58
446
  }
59
447
  getId() {
60
448
  return this.uuid;
@@ -63,23 +451,46 @@ import * as crypto from 'node:crypto';
63
451
  return this.state;
64
452
  }
65
453
  getEpochNumber() {
66
- return this.epochNumber;
454
+ return this.data.epochNumber;
455
+ }
456
+ getDeadline() {
457
+ return this.deadline;
458
+ }
459
+ getProvingData() {
460
+ return this.data;
461
+ }
462
+ get epochNumber() {
463
+ return this.data.epochNumber;
464
+ }
465
+ get checkpoints() {
466
+ return this.data.checkpoints;
467
+ }
468
+ get txs() {
469
+ return this.data.txs;
470
+ }
471
+ get attestations() {
472
+ return this.data.attestations;
67
473
  }
68
474
  /**
69
475
  * Proves the given epoch and submits the proof to L1.
70
476
  */ async run() {
71
477
  this.scheduleDeadlineStop();
72
- const epochNumber = Number(this.epochNumber);
73
- const epochSizeBlocks = this.blocks.length;
74
- const epochSizeTxs = this.blocks.reduce((total, current)=>total + current.body.txEffects.length, 0);
75
- const [fromBlock, toBlock] = [
76
- this.blocks[0].number,
77
- this.blocks.at(-1).number
78
- ];
79
- this.log.info(`Starting epoch ${epochNumber} proving job with blocks ${fromBlock} to ${toBlock}`, {
478
+ if (!this.config.skipEpochCheck) {
479
+ await this.scheduleEpochCheck();
480
+ }
481
+ const attestations = this.attestations.map((attestation)=>attestation.toViem());
482
+ const epochNumber = this.epochNumber;
483
+ const epochSizeCheckpoints = this.checkpoints.length;
484
+ const epochSizeBlocks = this.checkpoints.reduce((accum, checkpoint)=>accum + checkpoint.blocks.length, 0);
485
+ const epochSizeTxs = this.checkpoints.reduce((accum, checkpoint)=>accum + checkpoint.blocks.reduce((accumC, block)=>accumC + block.body.txEffects.length, 0), 0);
486
+ const fromCheckpoint = this.checkpoints[0].number;
487
+ const toCheckpoint = this.checkpoints.at(-1).number;
488
+ const fromBlock = this.checkpoints[0].blocks[0].number;
489
+ const toBlock = this.checkpoints.at(-1).blocks.at(-1).number;
490
+ this.log.info(`Starting epoch ${epochNumber} proving job with checkpoints ${fromCheckpoint} to ${toCheckpoint}`, {
80
491
  fromBlock,
81
492
  toBlock,
82
- epochSizeBlocks,
493
+ epochSizeTxs,
83
494
  epochNumber,
84
495
  uuid: this.uuid
85
496
  });
@@ -88,71 +499,128 @@ import * as crypto from 'node:crypto';
88
499
  const { promise, resolve } = promiseWithResolvers();
89
500
  this.runPromise = promise;
90
501
  try {
91
- this.prover.startNewEpoch(epochNumber, fromBlock, epochSizeBlocks);
92
- await this.prover.startTubeCircuits(this.txs);
93
- await asyncPool(this.config.parallelBlockLimit, this.blocks, async (block)=>{
502
+ const blobTimer = new Timer();
503
+ const blobFieldsPerCheckpoint = this.checkpoints.map((checkpoint)=>checkpoint.toBlobFields());
504
+ const finalBlobBatchingChallenges = await buildFinalBlobChallenges(blobFieldsPerCheckpoint);
505
+ this.metrics.recordBlobProcessing(blobTimer.ms());
506
+ this.prover.startNewEpoch(epochNumber, epochSizeCheckpoints, finalBlobBatchingChallenges);
507
+ const chonkTimer = new Timer();
508
+ await this.prover.startChonkVerifierCircuits(Array.from(this.txs.values()));
509
+ this.metrics.recordChonkVerifier(chonkTimer.ms());
510
+ // Everything in the epoch should have the same chainId and version.
511
+ const { chainId, version } = this.checkpoints[0].blocks[0].header.globalVariables;
512
+ const previousBlockHeaders = this.gatherPreviousBlockHeaders();
513
+ const allCheckpointsTimer = new Timer();
514
+ const parallelism = this.config.parallelBlockLimit ? this.config.parallelBlockLimit : AVM_MAX_CONCURRENT_SIMULATIONS > 0 ? AVM_MAX_CONCURRENT_SIMULATIONS : this.checkpoints.length;
515
+ await asyncPool(parallelism, this.checkpoints, async (checkpoint)=>{
94
516
  this.checkState();
95
- const globalVariables = block.header.globalVariables;
96
- const txs = await this.getTxs(block);
97
- const l1ToL2Messages = await this.getL1ToL2Messages(block);
98
- const previousHeader = await this.getBlockHeader(block.number - 1);
99
- this.log.verbose(`Starting processing block ${block.number}`, {
100
- number: block.number,
101
- blockHash: (await block.hash()).toString(),
102
- lastArchive: block.header.lastArchive.root,
103
- noteHashTreeRoot: block.header.state.partial.noteHashTree.root,
104
- nullifierTreeRoot: block.header.state.partial.nullifierTree.root,
105
- publicDataTreeRoot: block.header.state.partial.publicDataTree.root,
106
- previousHeader: previousHeader.hash(),
107
- uuid: this.uuid,
108
- ...globalVariables
517
+ const checkpointTimer = new Timer();
518
+ const checkpointIndex = checkpoint.number - fromCheckpoint;
519
+ const checkpointConstants = CheckpointConstantData.from({
520
+ chainId,
521
+ version,
522
+ vkTreeRoot: getVKTreeRoot(),
523
+ protocolContractsHash: protocolContractsHash,
524
+ proverId: this.prover.getProverId().toField(),
525
+ slotNumber: checkpoint.header.slotNumber,
526
+ coinbase: checkpoint.header.coinbase,
527
+ feeRecipient: checkpoint.header.feeRecipient,
528
+ gasFees: checkpoint.header.gasFees
109
529
  });
110
- // Start block proving
111
- await this.prover.startNewBlock(globalVariables, l1ToL2Messages, previousHeader);
112
- // Process public fns
113
- const db = await this.dbProvider.fork(block.number - 1);
114
- const publicProcessor = this.publicProcessorFactory.create(db, globalVariables, true);
115
- const processed = await this.processTxs(publicProcessor, txs);
116
- await this.prover.addTxs(processed);
117
- await db.close();
118
- this.log.verbose(`Processed all ${txs.length} txs for block ${block.number}`, {
119
- blockNumber: block.number,
120
- blockHash: (await block.hash()).toString(),
530
+ const previousHeader = previousBlockHeaders[checkpointIndex];
531
+ const l1ToL2Messages = this.getL1ToL2Messages(checkpoint);
532
+ this.log.verbose(`Starting processing checkpoint ${checkpoint.number}`, {
533
+ number: checkpoint.number,
534
+ checkpointHash: checkpoint.hash().toString(),
535
+ lastArchive: checkpoint.header.lastArchiveRoot,
536
+ previousHeader: previousHeader.hash(),
121
537
  uuid: this.uuid
122
538
  });
123
- // Mark block as completed to pad it
124
- await this.prover.setBlockCompleted(block.number, block.header);
539
+ await this.prover.startNewCheckpoint(checkpointIndex, checkpointConstants, l1ToL2Messages, checkpoint.blocks.length, previousHeader);
540
+ for(let blockIndex = 0; blockIndex < checkpoint.blocks.length; blockIndex++){
541
+ const blockTimer = new Timer();
542
+ const block = checkpoint.blocks[blockIndex];
543
+ const globalVariables = block.header.globalVariables;
544
+ const txs = this.getTxs(block);
545
+ this.log.verbose(`Starting processing block ${block.number}`, {
546
+ number: block.number,
547
+ blockHash: (await block.hash()).toString(),
548
+ lastArchive: block.header.lastArchive.root,
549
+ noteHashTreeRoot: block.header.state.partial.noteHashTree.root,
550
+ nullifierTreeRoot: block.header.state.partial.nullifierTree.root,
551
+ publicDataTreeRoot: block.header.state.partial.publicDataTree.root,
552
+ ...globalVariables,
553
+ numTxs: txs.length
554
+ });
555
+ // Start block proving
556
+ await this.prover.startNewBlock(block.number, globalVariables.timestamp, txs.length);
557
+ // Process public fns. L1 to L2 messages are only inserted for the first block of a checkpoint,
558
+ // as the fork for subsequent blocks already includes them from the previous block's synced state.
559
+ const db = await this.createFork(BlockNumber(block.number - 1), blockIndex === 0 ? l1ToL2Messages : undefined);
560
+ const config = PublicSimulatorConfig.from({
561
+ proverId: this.prover.getProverId().toField(),
562
+ skipFeeEnforcement: false,
563
+ collectDebugLogs: false,
564
+ collectHints: true,
565
+ collectPublicInputs: true,
566
+ collectStatistics: false
567
+ });
568
+ const publicProcessor = this.publicProcessorFactory.create(db, globalVariables, config);
569
+ const processed = await this.processTxs(publicProcessor, txs);
570
+ await this.prover.addTxs(processed);
571
+ await db.close();
572
+ this.log.verbose(`Processed all ${txs.length} txs for block ${block.number}`, {
573
+ blockNumber: block.number,
574
+ blockHash: (await block.hash()).toString(),
575
+ uuid: this.uuid
576
+ });
577
+ // Mark block as completed to pad it
578
+ const expectedBlockHeader = block.header;
579
+ await this.prover.setBlockCompleted(block.number, expectedBlockHeader);
580
+ this.metrics.recordBlockProcessing(blockTimer.ms());
581
+ }
582
+ this.metrics.recordCheckpointProcessing(checkpointTimer.ms());
125
583
  });
584
+ this.metrics.recordAllCheckpointsProcessing(allCheckpointsTimer.ms());
126
585
  const executionTime = timer.ms();
127
586
  this.progressState('awaiting-prover');
128
- const { publicInputs, proof } = await this.prover.finaliseEpoch();
129
- this.log.info(`Finalised proof for epoch ${epochNumber}`, {
587
+ const { publicInputs, proof, batchedBlobInputs } = await this.prover.finalizeEpoch();
588
+ this.log.info(`Finalized proof for epoch ${epochNumber}`, {
130
589
  epochNumber,
131
590
  uuid: this.uuid,
132
591
  duration: timer.ms()
133
592
  });
134
593
  this.progressState('publishing-proof');
594
+ if (this.config.skipSubmitProof) {
595
+ this.log.info(`Proof publishing is disabled. Dropping valid proof for epoch ${epochNumber} (checkpoints ${fromCheckpoint} to ${toCheckpoint})`);
596
+ this.state = 'completed';
597
+ this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeCheckpoints, epochSizeBlocks, epochSizeTxs);
598
+ return;
599
+ }
135
600
  const success = await this.publisher.submitEpochProof({
136
- fromBlock,
137
- toBlock,
601
+ fromCheckpoint,
602
+ toCheckpoint,
138
603
  epochNumber,
139
604
  publicInputs,
140
- proof
605
+ proof,
606
+ batchedBlobInputs,
607
+ attestations
141
608
  });
142
609
  if (!success) {
143
610
  throw new Error('Failed to submit epoch proof to L1');
144
611
  }
145
- this.log.info(`Submitted proof for epoch ${epochNumber} (blocks ${fromBlock} to ${toBlock})`, {
612
+ this.log.info(`Submitted proof for epoch ${epochNumber} (checkpoints ${fromCheckpoint} to ${toCheckpoint})`, {
146
613
  epochNumber,
147
614
  uuid: this.uuid
148
615
  });
149
616
  this.state = 'completed';
150
- this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeBlocks, epochSizeTxs);
617
+ this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeCheckpoints, epochSizeBlocks, epochSizeTxs);
151
618
  } catch (err) {
152
619
  if (err && err.name === 'HaltExecutionError') {
153
620
  this.log.warn(`Halted execution of epoch ${epochNumber} prover job`, {
154
621
  uuid: this.uuid,
155
- epochNumber
622
+ epochNumber,
623
+ details: err.message
156
624
  });
157
625
  return;
158
626
  }
@@ -160,27 +628,48 @@ import * as crypto from 'node:crypto';
160
628
  uuid: this.uuid,
161
629
  epochNumber
162
630
  });
163
- this.state = 'failed';
631
+ if (this.state === 'processing' || this.state === 'awaiting-prover' || this.state === 'publishing-proof') {
632
+ this.state = 'failed';
633
+ }
164
634
  } finally{
165
635
  clearTimeout(this.deadlineTimeoutHandler);
166
- await this.cleanUp(this);
636
+ await this.epochCheckPromise?.stop();
167
637
  await this.prover.stop();
168
638
  resolve();
169
639
  }
170
640
  }
641
+ /**
642
+ * Create a new db fork for tx processing, optionally inserting L1 to L2 messages.
643
+ * L1 to L2 messages should only be inserted for the first block in a checkpoint,
644
+ * as subsequent blocks' synced state already includes them.
645
+ * REFACTOR: The prover already spawns a db fork of its own for each block, so we may be able to do away with just one fork.
646
+ */ async createFork(blockNumber, l1ToL2Messages) {
647
+ this.log.verbose(`Creating fork at ${blockNumber}`, {
648
+ blockNumber
649
+ });
650
+ const db = await this.dbProvider.fork(blockNumber);
651
+ if (l1ToL2Messages !== undefined) {
652
+ this.log.verbose(`Inserting ${l1ToL2Messages.length} L1 to L2 messages in fork`, {
653
+ blockNumber,
654
+ l1ToL2Messages: l1ToL2Messages.map((m)=>m.toString())
655
+ });
656
+ const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, 'Too many L1 to L2 messages');
657
+ await db.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
658
+ }
659
+ return db;
660
+ }
171
661
  progressState(state) {
172
662
  this.checkState();
173
663
  this.state = state;
174
664
  }
175
665
  checkState() {
176
- if (this.state === 'timed-out' || this.state === 'stopped' || this.state === 'failed') {
666
+ if (this.state === 'timed-out' || this.state === 'stopped' || this.state === 'failed' || this.state === 'reorg') {
177
667
  throw new HaltExecutionError(this.state);
178
668
  }
179
669
  }
180
670
  async stop(state = 'stopped') {
181
671
  this.state = state;
182
672
  this.prover.cancel();
183
- // TODO(palla/prover): Stop the publisher as well
184
673
  if (this.runPromise) {
185
674
  await this.runPromise;
186
675
  }
@@ -209,22 +698,45 @@ import * as crypto from 'node:crypto';
209
698
  }, timeout);
210
699
  }
211
700
  }
212
- /* Returns the header for the given block number, or the genesis block for block zero. */ async getBlockHeader(blockNumber) {
213
- if (blockNumber === 0) {
214
- return (await this.dbProvider.fork()).getInitialHeader();
701
+ /**
702
+ * Kicks off a running promise that queries the archiver for the set of L2 blocks of the current epoch.
703
+ * If those change, stops the proving job with a `rerun` state, so the node re-enqueues it.
704
+ */ async scheduleEpochCheck() {
705
+ const l2BlockSource = this.l2BlockSource;
706
+ if (!l2BlockSource) {
707
+ this.log.warn(`No L2 block source available, skipping epoch check`);
708
+ return;
215
709
  }
216
- return this.l2BlockSource.getBlockHeader(blockNumber);
710
+ const intervalMs = Math.ceil((await l2BlockSource.getL1Constants()).ethereumSlotDuration / 2) * 1000;
711
+ this.epochCheckPromise = new RunningPromise(async ()=>{
712
+ const blockHeaders = await l2BlockSource.getCheckpointedBlockHeadersForEpoch(this.epochNumber);
713
+ const blockHashes = await Promise.all(blockHeaders.map((header)=>header.hash()));
714
+ const thisBlocks = this.checkpoints.flatMap((checkpoint)=>checkpoint.blocks);
715
+ const thisBlockHashes = await Promise.all(thisBlocks.map((block)=>block.hash()));
716
+ if (blockHeaders.length !== thisBlocks.length || !blockHashes.every((block, i)=>block.equals(thisBlockHashes[i]))) {
717
+ this.log.warn('Epoch blocks changed underfoot', {
718
+ uuid: this.uuid,
719
+ epochNumber: this.epochNumber,
720
+ oldBlockHashes: thisBlockHashes,
721
+ newBlockHashes: blockHashes
722
+ });
723
+ void this.stop('reorg');
724
+ }
725
+ }, this.log, intervalMs).start();
726
+ this.log.verbose(`Scheduled epoch check for epoch ${this.epochNumber} every ${intervalMs}ms`);
727
+ }
728
+ /* Returns the last block header in the previous checkpoint for all checkpoints in the epoch */ gatherPreviousBlockHeaders() {
729
+ const lastBlocks = this.checkpoints.map((checkpoint)=>checkpoint.blocks.at(-1));
730
+ return [
731
+ this.data.previousBlockHeader,
732
+ ...lastBlocks.map((block)=>block.header).slice(0, -1)
733
+ ];
217
734
  }
218
- async getTxs(block) {
219
- const txHashes = block.body.txEffects.map((tx)=>tx.txHash.toBigInt());
220
- const txsAndHashes = await Promise.all(this.txs.map(async (tx)=>({
221
- tx,
222
- hash: await tx.getTxHash()
223
- })));
224
- return txsAndHashes.filter((txAndHash)=>txHashes.includes(txAndHash.hash.toBigInt())).map((txAndHash)=>txAndHash.tx);
735
+ getTxs(block) {
736
+ return block.body.txEffects.map((txEffect)=>this.txs.get(txEffect.txHash.toString()));
225
737
  }
226
- getL1ToL2Messages(block) {
227
- return this.l1ToL2MessageSource.getL1ToL2Messages(BigInt(block.number));
738
+ getL1ToL2Messages(checkpoint) {
739
+ return this.data.l1ToL2Messages[checkpoint.number];
228
740
  }
229
741
  async processTxs(publicProcessor, txs) {
230
742
  const { deadline } = this;
@@ -232,7 +744,8 @@ import * as crypto from 'node:crypto';
232
744
  deadline
233
745
  });
234
746
  if (failedTxs.length) {
235
- throw new Error(`Txs failed processing: ${failedTxs.map(({ tx, error })=>`${tx.getTxHash()} (${error})`).join(', ')}`);
747
+ const failedTxHashes = await Promise.all(failedTxs.map(({ tx })=>tx.getTxHash()));
748
+ throw new Error(`Txs failed processing: ${failedTxs.map(({ error }, index)=>`${failedTxHashes[index]} (${error})`).join(', ')}`);
236
749
  }
237
750
  if (processedTxs.length !== txs.length) {
238
751
  throw new Error(`Failed to process all txs: processed ${processedTxs.length} out of ${txs.length}`);
@@ -240,16 +753,10 @@ import * as crypto from 'node:crypto';
240
753
  return processedTxs;
241
754
  }
242
755
  }
243
- _ts_decorate([
244
- trackSpan('EpochProvingJob.run', function() {
245
- return {
246
- [Attributes.EPOCH_NUMBER]: Number(this.epochNumber)
247
- };
248
- })
249
- ], EpochProvingJob.prototype, "run", null);
250
756
  class HaltExecutionError extends Error {
757
+ state;
251
758
  constructor(state){
252
- super(`Halted execution due to state ${state}`);
759
+ super(`Halted execution due to state ${state}`), this.state = state;
253
760
  this.name = 'HaltExecutionError';
254
761
  }
255
762
  }