@aztec/prover-node 0.0.0-test.1 → 0.0.1-commit.017a351

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