@aztec/prover-node 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f

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 (49) hide show
  1. package/dest/actions/download-epoch-proving-job.d.ts +1 -1
  2. package/dest/actions/download-epoch-proving-job.js +1 -1
  3. package/dest/actions/rerun-epoch-proving-job.d.ts +5 -3
  4. package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -1
  5. package/dest/actions/rerun-epoch-proving-job.js +9 -7
  6. package/dest/actions/upload-epoch-proof-failure.d.ts +2 -2
  7. package/dest/actions/upload-epoch-proof-failure.d.ts.map +1 -1
  8. package/dest/bin/run-failed-epoch.js +6 -5
  9. package/dest/config.d.ts +5 -8
  10. package/dest/config.d.ts.map +1 -1
  11. package/dest/config.js +16 -19
  12. package/dest/factory.d.ts +19 -15
  13. package/dest/factory.d.ts.map +1 -1
  14. package/dest/factory.js +45 -64
  15. package/dest/index.d.ts +2 -1
  16. package/dest/index.d.ts.map +1 -1
  17. package/dest/index.js +1 -0
  18. package/dest/job/epoch-proving-job.d.ts +7 -2
  19. package/dest/job/epoch-proving-job.d.ts.map +1 -1
  20. package/dest/job/epoch-proving-job.js +600 -52
  21. package/dest/metrics.d.ts +21 -1
  22. package/dest/metrics.d.ts.map +1 -1
  23. package/dest/metrics.js +73 -100
  24. package/dest/monitors/epoch-monitor.d.ts +1 -1
  25. package/dest/monitors/epoch-monitor.d.ts.map +1 -1
  26. package/dest/monitors/epoch-monitor.js +12 -19
  27. package/dest/prover-node-publisher.d.ts +25 -5
  28. package/dest/prover-node-publisher.d.ts.map +1 -1
  29. package/dest/prover-node-publisher.js +210 -14
  30. package/dest/prover-node.d.ts +20 -11
  31. package/dest/prover-node.d.ts.map +1 -1
  32. package/dest/prover-node.js +429 -46
  33. package/dest/prover-publisher-factory.d.ts +7 -5
  34. package/dest/prover-publisher-factory.d.ts.map +1 -1
  35. package/dest/prover-publisher-factory.js +7 -5
  36. package/package.json +24 -23
  37. package/src/actions/download-epoch-proving-job.ts +1 -1
  38. package/src/actions/rerun-epoch-proving-job.ts +20 -7
  39. package/src/actions/upload-epoch-proof-failure.ts +1 -1
  40. package/src/bin/run-failed-epoch.ts +5 -3
  41. package/src/config.ts +23 -31
  42. package/src/factory.ts +77 -104
  43. package/src/index.ts +1 -0
  44. package/src/job/epoch-proving-job.ts +151 -47
  45. package/src/metrics.ts +91 -83
  46. package/src/monitors/epoch-monitor.ts +6 -14
  47. package/src/prover-node-publisher.ts +245 -19
  48. package/src/prover-node.ts +31 -31
  49. package/src/prover-publisher-factory.ts +16 -10
@@ -1,27 +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;
6
33
  }
7
- import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
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;
8
439
  import { asyncPool } from '@aztec/foundation/async-pool';
9
440
  import { BlockNumber } from '@aztec/foundation/branded-types';
10
- import { padArrayEnd } from '@aztec/foundation/collection';
11
- import { Fr } from '@aztec/foundation/curves/bn254';
12
441
  import { createLogger } from '@aztec/foundation/log';
13
442
  import { RunningPromise, promiseWithResolvers } from '@aztec/foundation/promise';
14
443
  import { Timer } from '@aztec/foundation/timer';
444
+ import { AVM_MAX_CONCURRENT_SIMULATIONS } from '@aztec/native';
15
445
  import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
16
446
  import { protocolContractsHash } from '@aztec/protocol-contracts';
17
447
  import { buildFinalBlobChallenges } from '@aztec/prover-client/helpers';
18
448
  import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
19
449
  import { EpochProvingJobTerminalState } from '@aztec/stdlib/interfaces/server';
450
+ import { appendL1ToL2MessagesToTree } from '@aztec/stdlib/messaging';
20
451
  import { CheckpointConstantData } from '@aztec/stdlib/rollup';
21
- import { MerkleTreeId } from '@aztec/stdlib/trees';
22
452
  import { Attributes, trackSpan } from '@aztec/telemetry-client';
23
453
  import * as crypto from 'node:crypto';
24
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
+ });
25
460
  /**
26
461
  * Job that grabs a range of blocks from the unfinalized chain from L1, gets their txs given their hashes,
27
462
  * re-executes their public calls, generates a rollup proof, and submits it to L1. This job will update the
@@ -36,14 +471,24 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
36
471
  metrics;
37
472
  deadline;
38
473
  config;
474
+ static{
475
+ ({ e: [_initProto] } = _apply_decs_2203_r(this, [
476
+ [
477
+ _dec,
478
+ 2,
479
+ "run"
480
+ ]
481
+ ], []));
482
+ }
39
483
  state;
40
484
  log;
41
485
  uuid;
42
486
  runPromise;
487
+ abortController;
43
488
  epochCheckPromise;
44
489
  deadlineTimeoutHandler;
45
490
  tracer;
46
- constructor(data, dbProvider, prover, publicProcessorFactory, publisher, l2BlockSource, metrics, deadline, config){
491
+ constructor(data, dbProvider, prover, publicProcessorFactory, publisher, l2BlockSource, metrics, deadline, config, bindings){
47
492
  this.data = data;
48
493
  this.dbProvider = dbProvider;
49
494
  this.prover = prover;
@@ -53,10 +498,14 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
53
498
  this.metrics = metrics;
54
499
  this.deadline = deadline;
55
500
  this.config = config;
56
- this.state = 'initialized';
57
- this.log = createLogger('prover-node:epoch-proving-job');
501
+ this.state = (_initProto(this), 'initialized');
502
+ this.abortController = new AbortController();
58
503
  validateEpochProvingJobData(data);
59
504
  this.uuid = crypto.randomUUID();
505
+ this.log = createLogger('prover-node:epoch-proving-job', {
506
+ ...bindings,
507
+ instanceId: `epoch-${data.epochNumber}`
508
+ });
60
509
  this.tracer = metrics.tracer;
61
510
  }
62
511
  getId() {
@@ -114,15 +563,22 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
114
563
  const { promise, resolve } = promiseWithResolvers();
115
564
  this.runPromise = promise;
116
565
  try {
566
+ const blobTimer = new Timer();
117
567
  const blobFieldsPerCheckpoint = this.checkpoints.map((checkpoint)=>checkpoint.toBlobFields());
118
568
  const finalBlobBatchingChallenges = await buildFinalBlobChallenges(blobFieldsPerCheckpoint);
569
+ this.metrics.recordBlobProcessing(blobTimer.ms());
119
570
  this.prover.startNewEpoch(epochNumber, epochSizeCheckpoints, finalBlobBatchingChallenges);
571
+ const chonkTimer = new Timer();
120
572
  await this.prover.startChonkVerifierCircuits(Array.from(this.txs.values()));
573
+ this.metrics.recordChonkVerifier(chonkTimer.ms());
121
574
  // Everything in the epoch should have the same chainId and version.
122
575
  const { chainId, version } = this.checkpoints[0].blocks[0].header.globalVariables;
123
576
  const previousBlockHeaders = this.gatherPreviousBlockHeaders();
124
- await asyncPool(this.config.parallelBlockLimit ?? 32, this.checkpoints, async (checkpoint)=>{
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)=>{
125
580
  this.checkState();
581
+ const checkpointTimer = new Timer();
126
582
  const checkpointIndex = checkpoint.number - fromCheckpoint;
127
583
  const checkpointConstants = CheckpointConstantData.from({
128
584
  chainId,
@@ -137,15 +593,18 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
137
593
  });
138
594
  const previousHeader = previousBlockHeaders[checkpointIndex];
139
595
  const l1ToL2Messages = this.getL1ToL2Messages(checkpoint);
140
- this.log.verbose(`Starting processing checkpoint ${checkpoint.number}`, {
596
+ this.log.debug(`Starting processing checkpoint ${checkpoint.number}`, {
141
597
  number: checkpoint.number,
142
598
  checkpointHash: checkpoint.hash().toString(),
143
- lastArchive: checkpoint.header.lastArchiveRoot,
144
- previousHeader: previousHeader.hash(),
599
+ headerHash: checkpoint.header.hash().toString(),
600
+ numL1ToL2Messages: l1ToL2Messages.length,
601
+ previousBlockNumber: previousHeader.globalVariables.blockNumber,
145
602
  uuid: this.uuid
146
603
  });
147
604
  await this.prover.startNewCheckpoint(checkpointIndex, checkpointConstants, l1ToL2Messages, checkpoint.blocks.length, previousHeader);
148
- for (const block of checkpoint.blocks){
605
+ for(let blockIndex = 0; blockIndex < checkpoint.blocks.length; blockIndex++){
606
+ const blockTimer = new Timer();
607
+ const block = checkpoint.blocks[blockIndex];
149
608
  const globalVariables = block.header.globalVariables;
150
609
  const txs = this.getTxs(block);
151
610
  this.log.verbose(`Starting processing block ${block.number}`, {
@@ -160,20 +619,38 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
160
619
  });
161
620
  // Start block proving
162
621
  await this.prover.startNewBlock(block.number, globalVariables.timestamp, txs.length);
163
- // Process public fns
164
- const db = await this.createFork(BlockNumber(block.number - 1), l1ToL2Messages);
165
- const config = PublicSimulatorConfig.from({
166
- proverId: this.prover.getProverId().toField(),
167
- skipFeeEnforcement: false,
168
- collectDebugLogs: false,
169
- collectHints: true,
170
- collectPublicInputs: true,
171
- collectStatistics: false
172
- });
173
- const publicProcessor = this.publicProcessorFactory.create(db, globalVariables, config);
174
- const processed = await this.processTxs(publicProcessor, txs);
175
- await this.prover.addTxs(processed);
176
- await db.close();
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();
177
654
  this.log.verbose(`Processed all ${txs.length} txs for block ${block.number}`, {
178
655
  blockNumber: block.number,
179
656
  blockHash: (await block.hash()).toString(),
@@ -182,8 +659,11 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
182
659
  // Mark block as completed to pad it
183
660
  const expectedBlockHeader = block.header;
184
661
  await this.prover.setBlockCompleted(block.number, expectedBlockHeader);
662
+ this.metrics.recordBlockProcessing(blockTimer.ms());
185
663
  }
664
+ this.metrics.recordCheckpointProcessing(checkpointTimer.ms());
186
665
  });
666
+ this.metrics.recordAllCheckpointsProcessing(allCheckpointsTimer.ms());
187
667
  const executionTime = timer.ms();
188
668
  this.progressState('awaiting-prover');
189
669
  const { publicInputs, proof, batchedBlobInputs } = await this.prover.finalizeEpoch();
@@ -194,7 +674,20 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
194
674
  });
195
675
  this.progressState('publishing-proof');
196
676
  if (this.config.skipSubmitProof) {
197
- this.log.info(`Proof publishing is disabled. Dropping valid proof for epoch ${epochNumber} (checkpoints ${fromCheckpoint} to ${toCheckpoint})`);
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
+ }
198
691
  this.state = 'completed';
199
692
  this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeCheckpoints, epochSizeBlocks, epochSizeTxs);
200
693
  return;
@@ -241,17 +734,64 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
241
734
  }
242
735
  }
243
736
  /**
244
- * 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.
245
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.
246
741
  */ async createFork(blockNumber, l1ToL2Messages) {
247
- const db = await this.dbProvider.fork(blockNumber);
248
- const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, 'Too many L1 to L2 messages');
249
- this.log.verbose(`Creating fork at ${blockNumber} with ${l1ToL2Messages.length} L1 to L2 messages`, {
250
- blockNumber,
251
- l1ToL2Messages: l1ToL2Messages.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
+ }
252
788
  });
253
- await db.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
254
- return db;
789
+ if (hasError) {
790
+ throw firstError;
791
+ }
792
+ if (this.abortController.signal.aborted) {
793
+ this.checkState();
794
+ }
255
795
  }
256
796
  progressState(state) {
257
797
  this.checkState();
@@ -264,11 +804,21 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
264
804
  }
265
805
  async stop(state = 'stopped') {
266
806
  this.state = state;
267
- this.prover.cancel();
807
+ this.interruptProcessing();
268
808
  if (this.runPromise) {
269
809
  await this.runPromise;
270
810
  }
271
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
+ }
272
822
  scheduleDeadlineStop() {
273
823
  const deadline = this.deadline;
274
824
  if (deadline) {
@@ -304,11 +854,14 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
304
854
  }
305
855
  const intervalMs = Math.ceil((await l2BlockSource.getL1Constants()).ethereumSlotDuration / 2) * 1000;
306
856
  this.epochCheckPromise = new RunningPromise(async ()=>{
307
- const blocks = await l2BlockSource.getBlockHeadersForEpoch(this.epochNumber);
308
- const blockHashes = await Promise.all(blocks.map((block)=>block.hash()));
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()));
309
862
  const thisBlocks = this.checkpoints.flatMap((checkpoint)=>checkpoint.blocks);
310
863
  const thisBlockHashes = await Promise.all(thisBlocks.map((block)=>block.hash()));
311
- if (blocks.length !== thisBlocks.length || !blockHashes.every((block, i)=>block.equals(thisBlockHashes[i]))) {
864
+ if (blockHeaders.length !== thisBlocks.length || !blockHashes.every((block, i)=>block.equals(thisBlockHashes[i]))) {
312
865
  this.log.warn('Epoch blocks changed underfoot', {
313
866
  uuid: this.uuid,
314
867
  epochNumber: this.epochNumber,
@@ -336,8 +889,10 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
336
889
  async processTxs(publicProcessor, txs) {
337
890
  const { deadline } = this;
338
891
  const [processedTxs, failedTxs] = await publicProcessor.process(txs, {
339
- deadline
892
+ deadline,
893
+ signal: this.abortController.signal
340
894
  });
895
+ this.checkState();
341
896
  if (failedTxs.length) {
342
897
  const failedTxHashes = await Promise.all(failedTxs.map(({ tx })=>tx.getTxHash()));
343
898
  throw new Error(`Txs failed processing: ${failedTxs.map(({ error }, index)=>`${failedTxHashes[index]} (${error})`).join(', ')}`);
@@ -348,13 +903,6 @@ import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
348
903
  return processedTxs;
349
904
  }
350
905
  }
351
- _ts_decorate([
352
- trackSpan('EpochProvingJob.run', function() {
353
- return {
354
- [Attributes.EPOCH_NUMBER]: this.data.epochNumber
355
- };
356
- })
357
- ], EpochProvingJob.prototype, "run", null);
358
906
  class HaltExecutionError extends Error {
359
907
  state;
360
908
  constructor(state){