@aztec/prover-node 0.0.1-commit.24de95ac → 0.0.1-commit.2606882

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 (58) hide show
  1. package/dest/actions/download-epoch-proving-job.d.ts +4 -4
  2. package/dest/actions/download-epoch-proving-job.js +1 -1
  3. package/dest/actions/index.d.ts +1 -1
  4. package/dest/actions/rerun-epoch-proving-job.d.ts +5 -3
  5. package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -1
  6. package/dest/actions/rerun-epoch-proving-job.js +9 -7
  7. package/dest/actions/upload-epoch-proof-failure.d.ts +2 -2
  8. package/dest/actions/upload-epoch-proof-failure.d.ts.map +1 -1
  9. package/dest/bin/run-failed-epoch.d.ts +1 -1
  10. package/dest/bin/run-failed-epoch.js +6 -5
  11. package/dest/config.d.ts +8 -10
  12. package/dest/config.d.ts.map +1 -1
  13. package/dest/config.js +19 -21
  14. package/dest/factory.d.ts +20 -16
  15. package/dest/factory.d.ts.map +1 -1
  16. package/dest/factory.js +48 -63
  17. package/dest/index.d.ts +2 -1
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +1 -0
  20. package/dest/job/epoch-proving-job-data.d.ts +8 -6
  21. package/dest/job/epoch-proving-job-data.d.ts.map +1 -1
  22. package/dest/job/epoch-proving-job-data.js +25 -18
  23. package/dest/job/epoch-proving-job.d.ts +11 -13
  24. package/dest/job/epoch-proving-job.d.ts.map +1 -1
  25. package/dest/job/epoch-proving-job.js +669 -111
  26. package/dest/metrics.d.ts +24 -3
  27. package/dest/metrics.d.ts.map +1 -1
  28. package/dest/metrics.js +77 -98
  29. package/dest/monitors/epoch-monitor.d.ts +3 -2
  30. package/dest/monitors/epoch-monitor.d.ts.map +1 -1
  31. package/dest/monitors/epoch-monitor.js +14 -20
  32. package/dest/monitors/index.d.ts +1 -1
  33. package/dest/prover-node-publisher.d.ts +33 -11
  34. package/dest/prover-node-publisher.d.ts.map +1 -1
  35. package/dest/prover-node-publisher.js +248 -46
  36. package/dest/prover-node.d.ts +30 -19
  37. package/dest/prover-node.d.ts.map +1 -1
  38. package/dest/prover-node.js +512 -81
  39. package/dest/prover-publisher-factory.d.ts +10 -6
  40. package/dest/prover-publisher-factory.d.ts.map +1 -1
  41. package/dest/prover-publisher-factory.js +7 -5
  42. package/dest/test/index.d.ts +1 -1
  43. package/dest/test/index.d.ts.map +1 -1
  44. package/package.json +27 -25
  45. package/src/actions/download-epoch-proving-job.ts +1 -1
  46. package/src/actions/rerun-epoch-proving-job.ts +20 -7
  47. package/src/actions/upload-epoch-proof-failure.ts +1 -1
  48. package/src/bin/run-failed-epoch.ts +5 -3
  49. package/src/config.ts +27 -33
  50. package/src/factory.ts +81 -103
  51. package/src/index.ts +1 -0
  52. package/src/job/epoch-proving-job-data.ts +31 -25
  53. package/src/job/epoch-proving-job.ts +228 -117
  54. package/src/metrics.ts +102 -82
  55. package/src/monitors/epoch-monitor.ts +10 -17
  56. package/src/prover-node-publisher.ts +302 -66
  57. package/src/prover-node.ts +135 -86
  58. package/src/prover-publisher-factory.ts +19 -11
@@ -1,25 +1,462 @@
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;
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);
6
437
  }
7
- import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
438
+ var _dec, _initProto;
8
439
  import { asyncPool } from '@aztec/foundation/async-pool';
9
- import { padArrayEnd } from '@aztec/foundation/collection';
10
- import { Fr } from '@aztec/foundation/fields';
440
+ import { BlockNumber } from '@aztec/foundation/branded-types';
11
441
  import { createLogger } from '@aztec/foundation/log';
12
442
  import { RunningPromise, promiseWithResolvers } from '@aztec/foundation/promise';
13
443
  import { Timer } from '@aztec/foundation/timer';
444
+ import { AVM_MAX_CONCURRENT_SIMULATIONS } from '@aztec/native';
14
445
  import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
15
446
  import { protocolContractsHash } from '@aztec/protocol-contracts';
16
447
  import { buildFinalBlobChallenges } from '@aztec/prover-client/helpers';
448
+ import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
17
449
  import { EpochProvingJobTerminalState } from '@aztec/stdlib/interfaces/server';
450
+ import { appendL1ToL2MessagesToTree } from '@aztec/stdlib/messaging';
18
451
  import { CheckpointConstantData } from '@aztec/stdlib/rollup';
19
- import { MerkleTreeId } from '@aztec/stdlib/trees';
20
452
  import { Attributes, trackSpan } from '@aztec/telemetry-client';
21
453
  import * as crypto from 'node:crypto';
22
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
+ });
23
460
  /**
24
461
  * Job that grabs a range of blocks from the unfinalized chain from L1, gets their txs given their hashes,
25
462
  * re-executes their public calls, generates a rollup proof, and submits it to L1. This job will update the
@@ -34,14 +471,24 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
34
471
  metrics;
35
472
  deadline;
36
473
  config;
474
+ static{
475
+ ({ e: [_initProto] } = _apply_decs_2203_r(this, [
476
+ [
477
+ _dec,
478
+ 2,
479
+ "run"
480
+ ]
481
+ ], []));
482
+ }
37
483
  state;
38
484
  log;
39
485
  uuid;
40
486
  runPromise;
487
+ abortController;
41
488
  epochCheckPromise;
42
489
  deadlineTimeoutHandler;
43
490
  tracer;
44
- constructor(data, dbProvider, prover, publicProcessorFactory, publisher, l2BlockSource, metrics, deadline, config){
491
+ constructor(data, dbProvider, prover, publicProcessorFactory, publisher, l2BlockSource, metrics, deadline, config, bindings){
45
492
  this.data = data;
46
493
  this.dbProvider = dbProvider;
47
494
  this.prover = prover;
@@ -51,10 +498,14 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
51
498
  this.metrics = metrics;
52
499
  this.deadline = deadline;
53
500
  this.config = config;
54
- this.state = 'initialized';
55
- this.log = createLogger('prover-node:epoch-proving-job');
501
+ this.state = (_initProto(this), 'initialized');
502
+ this.abortController = new AbortController();
56
503
  validateEpochProvingJobData(data);
57
504
  this.uuid = crypto.randomUUID();
505
+ this.log = createLogger('prover-node:epoch-proving-job', {
506
+ ...bindings,
507
+ instanceId: `epoch-${data.epochNumber}`
508
+ });
58
509
  this.tracer = metrics.tracer;
59
510
  }
60
511
  getId() {
@@ -75,8 +526,8 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
75
526
  get epochNumber() {
76
527
  return this.data.epochNumber;
77
528
  }
78
- get blocks() {
79
- return this.data.blocks;
529
+ get checkpoints() {
530
+ return this.data.checkpoints;
80
531
  }
81
532
  get txs() {
82
533
  return this.data.txs;
@@ -92,17 +543,18 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
92
543
  await this.scheduleEpochCheck();
93
544
  }
94
545
  const attestations = this.attestations.map((attestation)=>attestation.toViem());
95
- const epochNumber = Number(this.epochNumber);
96
- const epochSizeBlocks = this.blocks.length;
97
- const epochSizeTxs = this.blocks.reduce((total, current)=>total + current.body.txEffects.length, 0);
98
- const [fromBlock, toBlock] = [
99
- this.blocks[0].number,
100
- this.blocks.at(-1).number
101
- ];
102
- this.log.info(`Starting epoch ${epochNumber} proving job with blocks ${fromBlock} to ${toBlock}`, {
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}`, {
103
555
  fromBlock,
104
556
  toBlock,
105
- epochSizeBlocks,
557
+ epochSizeTxs,
106
558
  epochNumber,
107
559
  uuid: this.uuid
108
560
  });
@@ -111,67 +563,107 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
111
563
  const { promise, resolve } = promiseWithResolvers();
112
564
  this.runPromise = promise;
113
565
  try {
114
- const blobFieldsPerCheckpoint = this.blocks.map((block)=>block.getCheckpointBlobFields());
566
+ const blobTimer = new Timer();
567
+ const blobFieldsPerCheckpoint = this.checkpoints.map((checkpoint)=>checkpoint.toBlobFields());
115
568
  const finalBlobBatchingChallenges = await buildFinalBlobChallenges(blobFieldsPerCheckpoint);
116
- // TODO(#17027): Enable multiple blocks per checkpoint.
117
- // Total number of checkpoints equals number of blocks because we currently build a checkpoint with only one block.
118
- const totalNumCheckpoints = epochSizeBlocks;
119
- this.prover.startNewEpoch(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges);
569
+ this.metrics.recordBlobProcessing(blobTimer.ms());
570
+ this.prover.startNewEpoch(epochNumber, epochSizeCheckpoints, finalBlobBatchingChallenges);
571
+ const chonkTimer = new Timer();
120
572
  await this.prover.startChonkVerifierCircuits(Array.from(this.txs.values()));
121
- await asyncPool(this.config.parallelBlockLimit ?? 32, this.blocks, async (block)=>{
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)=>{
122
580
  this.checkState();
123
- const globalVariables = block.header.globalVariables;
124
- const txs = this.getTxs(block);
125
- const l1ToL2Messages = this.getL1ToL2Messages(block);
126
- const previousHeader = this.getBlockHeader(block.number - 1);
127
- this.log.verbose(`Starting processing block ${block.number}`, {
128
- number: block.number,
129
- blockHash: (await block.hash()).toString(),
130
- lastArchive: block.header.lastArchive.root,
131
- noteHashTreeRoot: block.header.state.partial.noteHashTree.root,
132
- nullifierTreeRoot: block.header.state.partial.nullifierTree.root,
133
- publicDataTreeRoot: block.header.state.partial.publicDataTree.root,
134
- previousHeader: previousHeader.hash(),
135
- uuid: this.uuid,
136
- ...globalVariables
137
- });
581
+ const checkpointTimer = new Timer();
582
+ const checkpointIndex = checkpoint.number - fromCheckpoint;
138
583
  const checkpointConstants = CheckpointConstantData.from({
139
- chainId: globalVariables.chainId,
140
- version: globalVariables.version,
584
+ chainId,
585
+ version,
141
586
  vkTreeRoot: getVKTreeRoot(),
142
587
  protocolContractsHash: protocolContractsHash,
143
588
  proverId: this.prover.getProverId().toField(),
144
- slotNumber: globalVariables.slotNumber,
145
- coinbase: globalVariables.coinbase,
146
- feeRecipient: globalVariables.feeRecipient,
147
- gasFees: globalVariables.gasFees
589
+ slotNumber: checkpoint.header.slotNumber,
590
+ coinbase: checkpoint.header.coinbase,
591
+ feeRecipient: checkpoint.header.feeRecipient,
592
+ gasFees: checkpoint.header.gasFees
148
593
  });
149
- // TODO(#17027): Enable multiple blocks per checkpoint.
150
- // Each checkpoint has only one block.
151
- const totalNumBlocks = 1;
152
- const checkpointIndex = block.number - fromBlock;
153
- await this.prover.startNewCheckpoint(checkpointIndex, checkpointConstants, l1ToL2Messages, totalNumBlocks, blobFieldsPerCheckpoint[checkpointIndex].length, previousHeader);
154
- // Start block proving
155
- await this.prover.startNewBlock(block.number, globalVariables.timestamp, txs.length);
156
- // Process public fns
157
- const db = await this.createFork(block.number - 1, l1ToL2Messages);
158
- const publicProcessor = this.publicProcessorFactory.create(db, globalVariables, {
159
- skipFeeEnforcement: true,
160
- clientInitiatedSimulation: false,
161
- proverId: this.prover.getProverId().toField()
162
- });
163
- const processed = await this.processTxs(publicProcessor, txs);
164
- await this.prover.addTxs(processed);
165
- await db.close();
166
- this.log.verbose(`Processed all ${txs.length} txs for block ${block.number}`, {
167
- blockNumber: block.number,
168
- 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,
169
602
  uuid: this.uuid
170
603
  });
171
- // Mark block as completed to pad it
172
- const expectedBlockHeader = block.getBlockHeader();
173
- await this.prover.setBlockCompleted(block.number, expectedBlockHeader);
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());
174
665
  });
666
+ this.metrics.recordAllCheckpointsProcessing(allCheckpointsTimer.ms());
175
667
  const executionTime = timer.ms();
176
668
  this.progressState('awaiting-prover');
177
669
  const { publicInputs, proof, batchedBlobInputs } = await this.prover.finalizeEpoch();
@@ -182,14 +674,27 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
182
674
  });
183
675
  this.progressState('publishing-proof');
184
676
  if (this.config.skipSubmitProof) {
185
- this.log.info(`Proof publishing is disabled. Dropping valid proof for epoch ${epochNumber} (blocks ${fromBlock} to ${toBlock})`);
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
+ }
186
691
  this.state = 'completed';
187
- this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeBlocks, epochSizeTxs);
692
+ this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeCheckpoints, epochSizeBlocks, epochSizeTxs);
188
693
  return;
189
694
  }
190
695
  const success = await this.publisher.submitEpochProof({
191
- fromBlock,
192
- toBlock,
696
+ fromCheckpoint,
697
+ toCheckpoint,
193
698
  epochNumber,
194
699
  publicInputs,
195
700
  proof,
@@ -199,12 +704,12 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
199
704
  if (!success) {
200
705
  throw new Error('Failed to submit epoch proof to L1');
201
706
  }
202
- 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})`, {
203
708
  epochNumber,
204
709
  uuid: this.uuid
205
710
  });
206
711
  this.state = 'completed';
207
- this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeBlocks, epochSizeTxs);
712
+ this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeCheckpoints, epochSizeBlocks, epochSizeTxs);
208
713
  } catch (err) {
209
714
  if (err && err.name === 'HaltExecutionError') {
210
715
  this.log.warn(`Halted execution of epoch ${epochNumber} prover job`, {
@@ -229,17 +734,64 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
229
734
  }
230
735
  }
231
736
  /**
232
- * Create a new db fork for tx processing, inserting all L1 to L2.
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.
233
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.
234
741
  */ async createFork(blockNumber, l1ToL2Messages) {
235
- const db = await this.dbProvider.fork(blockNumber);
236
- const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, 'Too many L1 to L2 messages');
237
- this.log.verbose(`Creating fork at ${blockNumber} with ${l1ToL2Messages.length} L1 to L2 messages`, {
238
- blockNumber,
239
- l1ToL2Messages: l1ToL2MessagesPadded.map((m)=>m.toString())
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
+ }
240
788
  });
241
- await db.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
242
- return db;
789
+ if (hasError) {
790
+ throw firstError;
791
+ }
792
+ if (this.abortController.signal.aborted) {
793
+ this.checkState();
794
+ }
243
795
  }
244
796
  progressState(state) {
245
797
  this.checkState();
@@ -252,11 +804,21 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
252
804
  }
253
805
  async stop(state = 'stopped') {
254
806
  this.state = state;
255
- this.prover.cancel();
807
+ this.interruptProcessing();
256
808
  if (this.runPromise) {
257
809
  await this.runPromise;
258
810
  }
259
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
+ }
260
822
  scheduleDeadlineStop() {
261
823
  const deadline = this.deadline;
262
824
  if (deadline) {
@@ -292,10 +854,14 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
292
854
  }
293
855
  const intervalMs = Math.ceil((await l2BlockSource.getL1Constants()).ethereumSlotDuration / 2) * 1000;
294
856
  this.epochCheckPromise = new RunningPromise(async ()=>{
295
- const blocks = await l2BlockSource.getBlockHeadersForEpoch(this.epochNumber);
296
- const blockHashes = await Promise.all(blocks.map((block)=>block.hash()));
297
- const thisBlockHashes = await Promise.all(this.blocks.map((block)=>block.hash()));
298
- if (blocks.length !== this.blocks.length || !blockHashes.every((block, i)=>block.equals(thisBlockHashes[i]))) {
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]))) {
299
865
  this.log.warn('Epoch blocks changed underfoot', {
300
866
  uuid: this.uuid,
301
867
  epochNumber: this.epochNumber,
@@ -307,27 +873,26 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
307
873
  }, this.log, intervalMs).start();
308
874
  this.log.verbose(`Scheduled epoch check for epoch ${this.epochNumber} every ${intervalMs}ms`);
309
875
  }
310
- /* Returns the header for the given block number based on the epoch proving job data. */ getBlockHeader(blockNumber) {
311
- const block = this.blocks.find((b)=>b.number === blockNumber);
312
- if (block) {
313
- return block.getBlockHeader();
314
- }
315
- if (blockNumber === Number(this.data.previousBlockHeader.getBlockNumber())) {
316
- return this.data.previousBlockHeader;
317
- }
318
- throw new Error(`Block header not found for block number ${blockNumber} (got ${this.blocks.map((b)=>b.number).join(', ')} and previous header ${this.data.previousBlockHeader.getBlockNumber()})`);
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
+ ];
319
882
  }
320
883
  getTxs(block) {
321
884
  return block.body.txEffects.map((txEffect)=>this.txs.get(txEffect.txHash.toString()));
322
885
  }
323
- getL1ToL2Messages(block) {
324
- return this.data.l1ToL2Messages[block.number];
886
+ getL1ToL2Messages(checkpoint) {
887
+ return this.data.l1ToL2Messages[checkpoint.number];
325
888
  }
326
889
  async processTxs(publicProcessor, txs) {
327
890
  const { deadline } = this;
328
891
  const [processedTxs, failedTxs] = await publicProcessor.process(txs, {
329
- deadline
892
+ deadline,
893
+ signal: this.abortController.signal
330
894
  });
895
+ this.checkState();
331
896
  if (failedTxs.length) {
332
897
  const failedTxHashes = await Promise.all(failedTxs.map(({ tx })=>tx.getTxHash()));
333
898
  throw new Error(`Txs failed processing: ${failedTxs.map(({ error }, index)=>`${failedTxHashes[index]} (${error})`).join(', ')}`);
@@ -338,13 +903,6 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
338
903
  return processedTxs;
339
904
  }
340
905
  }
341
- _ts_decorate([
342
- trackSpan('EpochProvingJob.run', function() {
343
- return {
344
- [Attributes.EPOCH_NUMBER]: Number(this.data.epochNumber)
345
- };
346
- })
347
- ], EpochProvingJob.prototype, "run", null);
348
906
  class HaltExecutionError extends Error {
349
907
  state;
350
908
  constructor(state){