@aztec/prover-client 0.0.1-commit.d3ec352c → 0.0.1-commit.e310a4c8

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 (107) hide show
  1. package/dest/config.d.ts +2 -2
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +1 -1
  4. package/dest/light/index.d.ts +2 -0
  5. package/dest/light/index.d.ts.map +1 -0
  6. package/dest/light/index.js +1 -0
  7. package/dest/light/lightweight_checkpoint_builder.d.ts +33 -15
  8. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
  9. package/dest/light/lightweight_checkpoint_builder.js +116 -23
  10. package/dest/mocks/fixtures.d.ts +1 -1
  11. package/dest/mocks/fixtures.d.ts.map +1 -1
  12. package/dest/mocks/fixtures.js +4 -3
  13. package/dest/mocks/test_context.d.ts +5 -3
  14. package/dest/mocks/test_context.d.ts.map +1 -1
  15. package/dest/mocks/test_context.js +21 -8
  16. package/dest/orchestrator/block-building-helpers.d.ts +3 -3
  17. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  18. package/dest/orchestrator/block-building-helpers.js +3 -3
  19. package/dest/orchestrator/block-proving-state.d.ts +2 -2
  20. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  21. package/dest/orchestrator/block-proving-state.js +1 -1
  22. package/dest/orchestrator/checkpoint-proving-state.d.ts +16 -3
  23. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
  24. package/dest/orchestrator/checkpoint-proving-state.js +36 -2
  25. package/dest/orchestrator/epoch-proving-state.d.ts +5 -4
  26. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  27. package/dest/orchestrator/epoch-proving-state.js +35 -1
  28. package/dest/orchestrator/orchestrator.d.ts +20 -5
  29. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  30. package/dest/orchestrator/orchestrator.js +535 -134
  31. package/dest/orchestrator/orchestrator_metrics.d.ts +1 -3
  32. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
  33. package/dest/orchestrator/orchestrator_metrics.js +2 -15
  34. package/dest/orchestrator/tx-proving-state.d.ts +6 -5
  35. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  36. package/dest/orchestrator/tx-proving-state.js +8 -8
  37. package/dest/prover-client/factory.d.ts +3 -3
  38. package/dest/prover-client/factory.d.ts.map +1 -1
  39. package/dest/prover-client/prover-client.d.ts +3 -3
  40. package/dest/prover-client/prover-client.d.ts.map +1 -1
  41. package/dest/prover-client/prover-client.js +7 -4
  42. package/dest/prover-client/server-epoch-prover.d.ts +2 -2
  43. package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
  44. package/dest/proving_broker/broker_prover_facade.d.ts +7 -5
  45. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  46. package/dest/proving_broker/broker_prover_facade.js +6 -13
  47. package/dest/proving_broker/config.d.ts +6 -2
  48. package/dest/proving_broker/config.d.ts.map +1 -1
  49. package/dest/proving_broker/config.js +8 -2
  50. package/dest/proving_broker/fixtures.js +1 -1
  51. package/dest/proving_broker/proving_agent.d.ts +5 -9
  52. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  53. package/dest/proving_broker/proving_agent.js +4 -19
  54. package/dest/proving_broker/proving_broker.d.ts +1 -1
  55. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  56. package/dest/proving_broker/proving_broker.js +4 -10
  57. package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
  58. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  59. package/dest/proving_broker/proving_broker_database/persisted.js +389 -1
  60. package/dest/proving_broker/proving_broker_instrumentation.d.ts +1 -1
  61. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  62. package/dest/proving_broker/proving_broker_instrumentation.js +15 -35
  63. package/dest/proving_broker/proving_job_controller.d.ts +4 -3
  64. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  65. package/dest/proving_broker/proving_job_controller.js +8 -6
  66. package/dest/test/mock_proof_store.d.ts +3 -3
  67. package/dest/test/mock_proof_store.d.ts.map +1 -1
  68. package/dest/test/mock_prover.d.ts +2 -2
  69. package/dest/test/mock_prover.d.ts.map +1 -1
  70. package/dest/test/mock_prover.js +4 -4
  71. package/package.json +18 -17
  72. package/src/config.ts +1 -1
  73. package/src/light/index.ts +1 -0
  74. package/src/light/lightweight_checkpoint_builder.ts +177 -31
  75. package/src/mocks/fixtures.ts +4 -3
  76. package/src/mocks/test_context.ts +18 -6
  77. package/src/orchestrator/block-building-helpers.ts +3 -3
  78. package/src/orchestrator/block-proving-state.ts +1 -1
  79. package/src/orchestrator/checkpoint-proving-state.ts +49 -2
  80. package/src/orchestrator/epoch-proving-state.ts +56 -8
  81. package/src/orchestrator/orchestrator.ts +130 -114
  82. package/src/orchestrator/orchestrator_metrics.ts +2 -25
  83. package/src/orchestrator/tx-proving-state.ts +10 -14
  84. package/src/prover-client/factory.ts +6 -2
  85. package/src/prover-client/prover-client.ts +25 -15
  86. package/src/prover-client/server-epoch-prover.ts +1 -1
  87. package/src/proving_broker/broker_prover_facade.ts +10 -17
  88. package/src/proving_broker/config.ts +10 -1
  89. package/src/proving_broker/fixtures.ts +1 -1
  90. package/src/proving_broker/proving_agent.ts +6 -19
  91. package/src/proving_broker/proving_broker.ts +4 -8
  92. package/src/proving_broker/proving_broker_database/persisted.ts +15 -1
  93. package/src/proving_broker/proving_broker_instrumentation.ts +14 -35
  94. package/src/proving_broker/proving_job_controller.ts +11 -6
  95. package/src/test/mock_prover.ts +2 -14
  96. package/dest/block-factory/index.d.ts +0 -2
  97. package/dest/block-factory/index.d.ts.map +0 -1
  98. package/dest/block-factory/index.js +0 -1
  99. package/dest/block-factory/light.d.ts +0 -38
  100. package/dest/block-factory/light.d.ts.map +0 -1
  101. package/dest/block-factory/light.js +0 -108
  102. package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
  103. package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
  104. package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
  105. package/src/block-factory/index.ts +0 -1
  106. package/src/block-factory/light.ts +0 -137
  107. package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
@@ -1,20 +1,386 @@
1
- function _ts_decorate(decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1
+ function applyDecs2203RFactory() {
2
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
3
+ return function addInitializer(initializer) {
4
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
5
+ assertCallable(initializer, "An initializer");
6
+ initializers.push(initializer);
7
+ };
8
+ }
9
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
10
+ var kindStr;
11
+ switch(kind){
12
+ case 1:
13
+ kindStr = "accessor";
14
+ break;
15
+ case 2:
16
+ kindStr = "method";
17
+ break;
18
+ case 3:
19
+ kindStr = "getter";
20
+ break;
21
+ case 4:
22
+ kindStr = "setter";
23
+ break;
24
+ default:
25
+ kindStr = "field";
26
+ }
27
+ var ctx = {
28
+ kind: kindStr,
29
+ name: isPrivate ? "#" + name : name,
30
+ static: isStatic,
31
+ private: isPrivate,
32
+ metadata: metadata
33
+ };
34
+ var decoratorFinishedRef = {
35
+ v: false
36
+ };
37
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
38
+ var get, set;
39
+ if (kind === 0) {
40
+ if (isPrivate) {
41
+ get = desc.get;
42
+ set = desc.set;
43
+ } else {
44
+ get = function() {
45
+ return this[name];
46
+ };
47
+ set = function(v) {
48
+ this[name] = v;
49
+ };
50
+ }
51
+ } else if (kind === 2) {
52
+ get = function() {
53
+ return desc.value;
54
+ };
55
+ } else {
56
+ if (kind === 1 || kind === 3) {
57
+ get = function() {
58
+ return desc.get.call(this);
59
+ };
60
+ }
61
+ if (kind === 1 || kind === 4) {
62
+ set = function(v) {
63
+ desc.set.call(this, v);
64
+ };
65
+ }
66
+ }
67
+ ctx.access = get && set ? {
68
+ get: get,
69
+ set: set
70
+ } : get ? {
71
+ get: get
72
+ } : {
73
+ set: set
74
+ };
75
+ try {
76
+ return dec(value, ctx);
77
+ } finally{
78
+ decoratorFinishedRef.v = true;
79
+ }
80
+ }
81
+ function assertNotFinished(decoratorFinishedRef, fnName) {
82
+ if (decoratorFinishedRef.v) {
83
+ throw new Error("attempted to call " + fnName + " after decoration was finished");
84
+ }
85
+ }
86
+ function assertCallable(fn, hint) {
87
+ if (typeof fn !== "function") {
88
+ throw new TypeError(hint + " must be a function");
89
+ }
90
+ }
91
+ function assertValidReturnValue(kind, value) {
92
+ var type = typeof value;
93
+ if (kind === 1) {
94
+ if (type !== "object" || value === null) {
95
+ throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
96
+ }
97
+ if (value.get !== undefined) {
98
+ assertCallable(value.get, "accessor.get");
99
+ }
100
+ if (value.set !== undefined) {
101
+ assertCallable(value.set, "accessor.set");
102
+ }
103
+ if (value.init !== undefined) {
104
+ assertCallable(value.init, "accessor.init");
105
+ }
106
+ } else if (type !== "function") {
107
+ var hint;
108
+ if (kind === 0) {
109
+ hint = "field";
110
+ } else if (kind === 10) {
111
+ hint = "class";
112
+ } else {
113
+ hint = "method";
114
+ }
115
+ throw new TypeError(hint + " decorators must return a function or void 0");
116
+ }
117
+ }
118
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
119
+ var decs = decInfo[0];
120
+ var desc, init, value;
121
+ if (isPrivate) {
122
+ if (kind === 0 || kind === 1) {
123
+ desc = {
124
+ get: decInfo[3],
125
+ set: decInfo[4]
126
+ };
127
+ } else if (kind === 3) {
128
+ desc = {
129
+ get: decInfo[3]
130
+ };
131
+ } else if (kind === 4) {
132
+ desc = {
133
+ set: decInfo[3]
134
+ };
135
+ } else {
136
+ desc = {
137
+ value: decInfo[3]
138
+ };
139
+ }
140
+ } else if (kind !== 0) {
141
+ desc = Object.getOwnPropertyDescriptor(base, name);
142
+ }
143
+ if (kind === 1) {
144
+ value = {
145
+ get: desc.get,
146
+ set: desc.set
147
+ };
148
+ } else if (kind === 2) {
149
+ value = desc.value;
150
+ } else if (kind === 3) {
151
+ value = desc.get;
152
+ } else if (kind === 4) {
153
+ value = desc.set;
154
+ }
155
+ var newValue, get, set;
156
+ if (typeof decs === "function") {
157
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
158
+ if (newValue !== void 0) {
159
+ assertValidReturnValue(kind, newValue);
160
+ if (kind === 0) {
161
+ init = newValue;
162
+ } else if (kind === 1) {
163
+ init = newValue.init;
164
+ get = newValue.get || value.get;
165
+ set = newValue.set || value.set;
166
+ value = {
167
+ get: get,
168
+ set: set
169
+ };
170
+ } else {
171
+ value = newValue;
172
+ }
173
+ }
174
+ } else {
175
+ for(var i = decs.length - 1; i >= 0; i--){
176
+ var dec = decs[i];
177
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
178
+ if (newValue !== void 0) {
179
+ assertValidReturnValue(kind, newValue);
180
+ var newInit;
181
+ if (kind === 0) {
182
+ newInit = newValue;
183
+ } else if (kind === 1) {
184
+ newInit = newValue.init;
185
+ get = newValue.get || value.get;
186
+ set = newValue.set || value.set;
187
+ value = {
188
+ get: get,
189
+ set: set
190
+ };
191
+ } else {
192
+ value = newValue;
193
+ }
194
+ if (newInit !== void 0) {
195
+ if (init === void 0) {
196
+ init = newInit;
197
+ } else if (typeof init === "function") {
198
+ init = [
199
+ init,
200
+ newInit
201
+ ];
202
+ } else {
203
+ init.push(newInit);
204
+ }
205
+ }
206
+ }
207
+ }
208
+ }
209
+ if (kind === 0 || kind === 1) {
210
+ if (init === void 0) {
211
+ init = function(instance, init) {
212
+ return init;
213
+ };
214
+ } else if (typeof init !== "function") {
215
+ var ownInitializers = init;
216
+ init = function(instance, init) {
217
+ var value = init;
218
+ for(var i = 0; i < ownInitializers.length; i++){
219
+ value = ownInitializers[i].call(instance, value);
220
+ }
221
+ return value;
222
+ };
223
+ } else {
224
+ var originalInitializer = init;
225
+ init = function(instance, init) {
226
+ return originalInitializer.call(instance, init);
227
+ };
228
+ }
229
+ ret.push(init);
230
+ }
231
+ if (kind !== 0) {
232
+ if (kind === 1) {
233
+ desc.get = value.get;
234
+ desc.set = value.set;
235
+ } else if (kind === 2) {
236
+ desc.value = value;
237
+ } else if (kind === 3) {
238
+ desc.get = value;
239
+ } else if (kind === 4) {
240
+ desc.set = value;
241
+ }
242
+ if (isPrivate) {
243
+ if (kind === 1) {
244
+ ret.push(function(instance, args) {
245
+ return value.get.call(instance, args);
246
+ });
247
+ ret.push(function(instance, args) {
248
+ return value.set.call(instance, args);
249
+ });
250
+ } else if (kind === 2) {
251
+ ret.push(value);
252
+ } else {
253
+ ret.push(function(instance, args) {
254
+ return value.call(instance, args);
255
+ });
256
+ }
257
+ } else {
258
+ Object.defineProperty(base, name, desc);
259
+ }
260
+ }
261
+ }
262
+ function applyMemberDecs(Class, decInfos, metadata) {
263
+ var ret = [];
264
+ var protoInitializers;
265
+ var staticInitializers;
266
+ var existingProtoNonFields = new Map();
267
+ var existingStaticNonFields = new Map();
268
+ for(var i = 0; i < decInfos.length; i++){
269
+ var decInfo = decInfos[i];
270
+ if (!Array.isArray(decInfo)) continue;
271
+ var kind = decInfo[1];
272
+ var name = decInfo[2];
273
+ var isPrivate = decInfo.length > 3;
274
+ var isStatic = kind >= 5;
275
+ var base;
276
+ var initializers;
277
+ if (isStatic) {
278
+ base = Class;
279
+ kind = kind - 5;
280
+ staticInitializers = staticInitializers || [];
281
+ initializers = staticInitializers;
282
+ } else {
283
+ base = Class.prototype;
284
+ protoInitializers = protoInitializers || [];
285
+ initializers = protoInitializers;
286
+ }
287
+ if (kind !== 0 && !isPrivate) {
288
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
289
+ var existingKind = existingNonFields.get(name) || 0;
290
+ if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
291
+ throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
292
+ } else if (!existingKind && kind > 2) {
293
+ existingNonFields.set(name, kind);
294
+ } else {
295
+ existingNonFields.set(name, true);
296
+ }
297
+ }
298
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
299
+ }
300
+ pushInitializers(ret, protoInitializers);
301
+ pushInitializers(ret, staticInitializers);
302
+ return ret;
303
+ }
304
+ function pushInitializers(ret, initializers) {
305
+ if (initializers) {
306
+ ret.push(function(instance) {
307
+ for(var i = 0; i < initializers.length; i++){
308
+ initializers[i].call(instance);
309
+ }
310
+ return instance;
311
+ });
312
+ }
313
+ }
314
+ function applyClassDecs(targetClass, classDecs, metadata) {
315
+ if (classDecs.length > 0) {
316
+ var initializers = [];
317
+ var newClass = targetClass;
318
+ var name = targetClass.name;
319
+ for(var i = classDecs.length - 1; i >= 0; i--){
320
+ var decoratorFinishedRef = {
321
+ v: false
322
+ };
323
+ try {
324
+ var nextNewClass = classDecs[i](newClass, {
325
+ kind: "class",
326
+ name: name,
327
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
328
+ metadata
329
+ });
330
+ } finally{
331
+ decoratorFinishedRef.v = true;
332
+ }
333
+ if (nextNewClass !== undefined) {
334
+ assertValidReturnValue(10, nextNewClass);
335
+ newClass = nextNewClass;
336
+ }
337
+ }
338
+ return [
339
+ defineMetadata(newClass, metadata),
340
+ function() {
341
+ for(var i = 0; i < initializers.length; i++){
342
+ initializers[i].call(newClass);
343
+ }
344
+ }
345
+ ];
346
+ }
347
+ }
348
+ function defineMetadata(Class, metadata) {
349
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
350
+ configurable: true,
351
+ enumerable: true,
352
+ value: metadata
353
+ });
354
+ }
355
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
356
+ if (parentClass !== void 0) {
357
+ var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
358
+ }
359
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
360
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
361
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
362
+ return {
363
+ e: e,
364
+ get c () {
365
+ return applyClassDecs(targetClass, classDecs, metadata);
366
+ }
367
+ };
368
+ };
369
+ }
370
+ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
371
+ return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
6
372
  }
373
+ var _dec, _dec1, _dec2, _dec3, _dec4, _initProto;
7
374
  import { L1_TO_L2_MSG_SUBTREE_HEIGHT, L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, NUM_BASE_PARITY_PER_ROOT_PARITY } from '@aztec/constants';
8
375
  import { BlockNumber } from '@aztec/foundation/branded-types';
9
376
  import { padArrayEnd } from '@aztec/foundation/collection';
377
+ import { Fr } from '@aztec/foundation/curves/bn254';
10
378
  import { AbortError } from '@aztec/foundation/error';
11
- import { Fr } from '@aztec/foundation/fields';
12
379
  import { createLogger } from '@aztec/foundation/log';
13
380
  import { promiseWithResolvers } from '@aztec/foundation/promise';
14
381
  import { assertLength } from '@aztec/foundation/serialize';
15
382
  import { pushTestData } from '@aztec/foundation/testing';
16
383
  import { elapsed } from '@aztec/foundation/timer';
17
- import { readAvmMinimalPublicTxInputsFromFile } from '@aztec/simulator/public/fixtures';
18
384
  import { BlockRootEmptyTxFirstRollupPrivateInputs, BlockRootFirstRollupPrivateInputs, BlockRootSingleTxFirstRollupPrivateInputs, BlockRootSingleTxRollupPrivateInputs, CheckpointRootSingleBlockRollupPrivateInputs, PrivateTxBaseRollupPrivateInputs } from '@aztec/stdlib/rollup';
19
385
  import { MerkleTreeId } from '@aztec/stdlib/trees';
20
386
  import { Attributes, getTelemetryClient, trackSpan, wrapCallbackInSpan } from '@aztec/telemetry-client';
@@ -23,7 +389,15 @@ import { buildHeaderFromCircuitOutputs, getLastSiblingPath, getPublicChonkVerifi
23
389
  import { EpochProvingState } from './epoch-proving-state.js';
24
390
  import { ProvingOrchestratorMetrics } from './orchestrator_metrics.js';
25
391
  import { TxProvingState } from './tx-proving-state.js';
26
- const logger = createLogger('prover-client:orchestrator');
392
+ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
393
+ [Attributes.BLOCK_NUMBER]: blockNumber
394
+ })), _dec1 = trackSpan('ProvingOrchestrator.addTxs', (txs)=>({
395
+ [Attributes.BLOCK_TXS_COUNT]: txs.length
396
+ })), _dec2 = trackSpan('ProvingOrchestrator.startChonkVerifierCircuits'), _dec3 = trackSpan('ProvingOrchestrator.setBlockCompleted', (blockNumber)=>({
397
+ [Attributes.BLOCK_NUMBER]: blockNumber
398
+ })), _dec4 = trackSpan('ProvingOrchestrator.prepareBaseRollupInputs', (tx)=>({
399
+ [Attributes.TX_HASH]: tx.hash.toString()
400
+ }));
27
401
  /**
28
402
  * Implements an event driven proving scheduler to build the recursive proof tree. The idea being:
29
403
  * 1. Transactions are provided to the scheduler post simulation.
@@ -39,20 +413,53 @@ const logger = createLogger('prover-client:orchestrator');
39
413
  dbProvider;
40
414
  prover;
41
415
  proverId;
416
+ cancelJobsOnStop;
417
+ static{
418
+ ({ e: [_initProto] } = _apply_decs_2203_r(this, [
419
+ [
420
+ _dec,
421
+ 2,
422
+ "startNewBlock"
423
+ ],
424
+ [
425
+ _dec1,
426
+ 2,
427
+ "addTxs"
428
+ ],
429
+ [
430
+ _dec2,
431
+ 2,
432
+ "startChonkVerifierCircuits"
433
+ ],
434
+ [
435
+ _dec3,
436
+ 2,
437
+ "setBlockCompleted"
438
+ ],
439
+ [
440
+ _dec4,
441
+ 2,
442
+ "prepareBaseRollupInputs"
443
+ ]
444
+ ], []));
445
+ }
42
446
  provingState;
43
447
  pendingProvingJobs;
44
448
  provingPromise;
45
449
  metrics;
46
450
  // eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
47
451
  dbs;
48
- constructor(dbProvider, prover, proverId, telemetryClient = getTelemetryClient()){
452
+ logger;
453
+ constructor(dbProvider, prover, proverId, cancelJobsOnStop = false, telemetryClient = getTelemetryClient(), bindings){
49
454
  this.dbProvider = dbProvider;
50
455
  this.prover = prover;
51
456
  this.proverId = proverId;
52
- this.provingState = undefined;
457
+ this.cancelJobsOnStop = cancelJobsOnStop;
458
+ this.provingState = (_initProto(this), undefined);
53
459
  this.pendingProvingJobs = [];
54
460
  this.provingPromise = undefined;
55
461
  this.dbs = new Map();
462
+ this.logger = createLogger('prover-client:orchestrator', bindings);
56
463
  this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'ProvingOrchestrator');
57
464
  }
58
465
  get tracer() {
@@ -61,6 +468,9 @@ const logger = createLogger('prover-client:orchestrator');
61
468
  getProverId() {
62
469
  return this.proverId;
63
470
  }
471
+ getNumActiveForks() {
472
+ return this.dbs.size;
473
+ }
64
474
  stop() {
65
475
  this.cancel();
66
476
  return Promise.resolve();
@@ -74,11 +484,18 @@ const logger = createLogger('prover-client:orchestrator');
74
484
  status: 'failure',
75
485
  reason
76
486
  }));
77
- logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
487
+ this.logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
78
488
  this.provingState = new EpochProvingState(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges, (provingState)=>this.checkAndEnqueueCheckpointRootRollup(provingState), resolve, reject);
79
489
  this.provingPromise = promise;
80
490
  }
81
- async startNewCheckpoint(checkpointIndex, constants, l1ToL2Messages, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint) {
491
+ /**
492
+ * Starts a new checkpoint.
493
+ * @param checkpointIndex - The index of the checkpoint in the epoch.
494
+ * @param constants - The constants for this checkpoint.
495
+ * @param l1ToL2Messages - The set of L1 to L2 messages to be inserted at the beginning of this checkpoint.
496
+ * @param totalNumBlocks - The total number of blocks expected in the checkpoint (must be at least one).
497
+ * @param headerOfLastBlockInPreviousCheckpoint - The header of the last block in the previous checkpoint.
498
+ */ async startNewCheckpoint(checkpointIndex, constants, l1ToL2Messages, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint) {
82
499
  if (!this.provingState) {
83
500
  throw new Error('Empty epoch proving state. Call startNewEpoch before starting a checkpoint.');
84
501
  }
@@ -89,7 +506,10 @@ const logger = createLogger('prover-client:orchestrator');
89
506
  const lastBlockNumber = headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber;
90
507
  const db = await this.dbProvider.fork(lastBlockNumber);
91
508
  const firstBlockNumber = BlockNumber(lastBlockNumber + 1);
92
- this.dbs.set(firstBlockNumber, db);
509
+ this.dbs.set(firstBlockNumber, {
510
+ fork: db,
511
+ cleanupPromise: undefined
512
+ });
93
513
  // Get archive sibling path before any block in this checkpoint lands.
94
514
  const lastArchiveSiblingPath = await getLastSiblingPath(MerkleTreeId.ARCHIVE, db);
95
515
  // Insert all the l1 to l2 messages into the db. And get the states before and after the insertion.
@@ -114,14 +534,17 @@ const logger = createLogger('prover-client:orchestrator');
114
534
  throw new Error(`Checkpoint not accepting further blocks.`);
115
535
  }
116
536
  const constants = checkpointProvingState.constants;
117
- logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
537
+ this.logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
118
538
  // Fork the db only when it's not already set. The db for the first block is set in `startNewCheckpoint`.
119
539
  if (!this.dbs.has(blockNumber)) {
120
540
  // Fork world state at the end of the immediately previous block
121
541
  const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
122
- this.dbs.set(blockNumber, db);
542
+ this.dbs.set(blockNumber, {
543
+ fork: db,
544
+ cleanupPromise: undefined
545
+ });
123
546
  }
124
- const db = this.dbs.get(blockNumber);
547
+ const db = this.dbs.get(blockNumber).fork;
125
548
  // Get archive snapshot and sibling path before any txs in this block lands.
126
549
  const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
127
550
  const lastArchiveSiblingPath = await getRootTreeSiblingPath(MerkleTreeId.ARCHIVE, db);
@@ -141,7 +564,8 @@ const logger = createLogger('prover-client:orchestrator');
141
564
  const blockEndBlobFields = blockProvingState.getBlockEndBlobFields();
142
565
  await endSpongeBlob.absorb(blockEndBlobFields);
143
566
  blockProvingState.setEndSpongeBlob(endSpongeBlob);
144
- // And also try to accumulate the blobs as far as we can:
567
+ // Try to accumulate the out hashes and blobs as far as we can:
568
+ await this.provingState.accumulateCheckpointOutHashes();
145
569
  await this.provingState.setBlobAccumulators();
146
570
  }
147
571
  }
@@ -155,7 +579,7 @@ const logger = createLogger('prover-client:orchestrator');
155
579
  if (!txs.length) {
156
580
  // To avoid an ugly throw below. If we require an empty block, we can just call setBlockCompleted
157
581
  // on a block with no txs. We cannot do that here because we cannot find the blockNumber without any txs.
158
- logger.warn(`Provided no txs to orchestrator addTxs.`);
582
+ this.logger.warn(`Provided no txs to orchestrator addTxs.`);
159
583
  return;
160
584
  }
161
585
  const blockNumber = BlockNumber(txs[0].globalVariables.blockNumber);
@@ -169,8 +593,8 @@ const logger = createLogger('prover-client:orchestrator');
169
593
  if (!provingState.isAcceptingTxs()) {
170
594
  throw new Error(`Block ${blockNumber} has been initialized with transactions.`);
171
595
  }
172
- logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
173
- const db = this.dbs.get(blockNumber);
596
+ this.logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
597
+ const db = this.dbs.get(blockNumber).fork;
174
598
  const lastArchive = provingState.lastArchiveTreeSnapshot;
175
599
  const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
176
600
  const spongeBlobState = provingState.getStartSpongeBlob().clone();
@@ -180,7 +604,7 @@ const logger = createLogger('prover-client:orchestrator');
180
604
  throw new Error(`Invalid proving state when adding a tx`);
181
605
  }
182
606
  validateTx(tx);
183
- logger.info(`Received transaction: ${tx.hash}`);
607
+ this.logger.debug(`Received transaction: ${tx.hash}`);
184
608
  const startSpongeBlob = spongeBlobState.clone();
185
609
  const [hints, treeSnapshots] = await this.prepareBaseRollupInputs(tx, lastArchive, newL1ToL2MessageTreeSnapshot, startSpongeBlob, db);
186
610
  if (!provingState.verifyState()) {
@@ -191,10 +615,10 @@ const logger = createLogger('prover-client:orchestrator');
191
615
  const txIndex = provingState.addNewTx(txProvingState);
192
616
  if (txProvingState.requireAvmProof) {
193
617
  this.getOrEnqueueChonkVerifier(provingState, txIndex);
194
- logger.debug(`Enqueueing public VM for tx ${txIndex}`);
618
+ this.logger.debug(`Enqueueing public VM for tx ${txIndex}`);
195
619
  this.enqueueVM(provingState, txIndex);
196
620
  } else {
197
- logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
621
+ this.logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
198
622
  this.enqueueBaseRollup(provingState, txIndex);
199
623
  }
200
624
  } catch (err) {
@@ -208,7 +632,8 @@ const logger = createLogger('prover-client:orchestrator');
208
632
  const blockEndBlobFields = provingState.getBlockEndBlobFields();
209
633
  await spongeBlobState.absorb(blockEndBlobFields);
210
634
  provingState.setEndSpongeBlob(spongeBlobState);
211
- // Txs have been added to the block. Now try to accumulate the blobs as far as we can:
635
+ // Txs have been added to the block. Now try to accumulate the out hashes and blobs as far as we can:
636
+ await this.provingState.accumulateCheckpointOutHashes();
212
637
  await this.provingState.setBlobAccumulators();
213
638
  }
214
639
  /**
@@ -223,7 +648,7 @@ const logger = createLogger('prover-client:orchestrator');
223
648
  const txHash = tx.getTxHash().toString();
224
649
  const privateInputs = getPublicChonkVerifierPrivateInputsFromTx(tx, this.proverId.toField());
225
650
  const tubeProof = promiseWithResolvers();
226
- logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
651
+ this.logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
227
652
  this.doEnqueueChonkVerifier(txHash, privateInputs, (proof)=>{
228
653
  tubeProof.resolve(proof);
229
654
  });
@@ -252,16 +677,16 @@ const logger = createLogger('prover-client:orchestrator');
252
677
  throw new Error(`Block ${blockNumber} is still accepting txs. Call setBlockCompleted after all txs have been added.`);
253
678
  }
254
679
  // Given we've applied every change from this block, now assemble the block header:
255
- logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
680
+ this.logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
256
681
  const header = await provingState.buildBlockHeader();
257
682
  if (expectedHeader && !header.equals(expectedHeader)) {
258
- logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
683
+ this.logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
259
684
  throw new Error('Block header mismatch');
260
685
  }
261
686
  // Get db for this block
262
- const db = this.dbs.get(provingState.blockNumber);
687
+ const db = this.dbs.get(provingState.blockNumber).fork;
263
688
  // Update the archive tree, so we're ready to start processing the next block:
264
- logger.verbose(`Updating archive tree with block ${provingState.blockNumber} header ${(await header.hash()).toString()}`);
689
+ this.logger.verbose(`Updating archive tree with block ${provingState.blockNumber} header ${(await header.hash()).toString()}`);
265
690
  await db.updateArchive(header);
266
691
  await this.verifyBuiltBlockAgainstSyncedState(provingState);
267
692
  return header;
@@ -270,33 +695,33 @@ const logger = createLogger('prover-client:orchestrator');
270
695
  async verifyBuiltBlockAgainstSyncedState(provingState) {
271
696
  const builtBlockHeader = provingState.getBuiltBlockHeader();
272
697
  if (!builtBlockHeader) {
273
- logger.debug('Block header not built yet, skipping header check.');
698
+ this.logger.debug('Block header not built yet, skipping header check.');
274
699
  return;
275
700
  }
276
701
  const output = provingState.getBlockRootRollupOutput();
277
702
  if (!output) {
278
- logger.debug('Block root rollup proof not built yet, skipping header check.');
703
+ this.logger.debug('Block root rollup proof not built yet, skipping header check.');
279
704
  return;
280
705
  }
281
706
  const header = await buildHeaderFromCircuitOutputs(output);
282
707
  if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
283
- logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
708
+ this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
284
709
  provingState.reject(`Block header hash mismatch.`);
285
710
  return;
286
711
  }
287
712
  // Get db for this block
288
713
  const blockNumber = provingState.blockNumber;
289
- const db = this.dbs.get(blockNumber);
714
+ const db = this.dbs.get(blockNumber).fork;
290
715
  const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
291
716
  const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
292
717
  if (!syncedArchive.equals(newArchive)) {
293
- logger.error(`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(syncedArchive)} but built ${inspect(newArchive)}`);
718
+ this.logger.error(`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(syncedArchive)} but built ${inspect(newArchive)}`);
294
719
  provingState.reject(`Archive tree mismatch.`);
295
720
  return;
296
721
  }
297
722
  const circuitArchive = output.newArchive;
298
723
  if (!newArchive.equals(circuitArchive)) {
299
- logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
724
+ this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
300
725
  provingState.reject(`New archive mismatch.`);
301
726
  return;
302
727
  }
@@ -304,14 +729,17 @@ const logger = createLogger('prover-client:orchestrator');
304
729
  // is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
305
730
  // but have to make sure it only runs once all operations are completed, otherwise some function here
306
731
  // will attempt to access the fork after it was closed.
307
- logger.debug(`Cleaning up world state fork for ${blockNumber}`);
308
- void this.dbs.get(blockNumber)?.close().then(()=>this.dbs.delete(blockNumber)).catch((err)=>logger.error(`Error closing db for block ${blockNumber}`, err));
732
+ void this.cleanupDBFork(blockNumber);
309
733
  }
310
734
  /**
311
- * Cancel any further proving
735
+ * Cancel any further proving.
736
+ * If cancelJobsOnStop is true, aborts all pending jobs with the broker (which marks them as 'Aborted').
737
+ * If cancelJobsOnStop is false (default), jobs remain in the broker queue and can be reused on restart/reorg.
312
738
  */ cancel() {
313
- for (const controller of this.pendingProvingJobs){
314
- controller.abort();
739
+ if (this.cancelJobsOnStop) {
740
+ for (const controller of this.pendingProvingJobs){
741
+ controller.abort();
742
+ }
315
743
  }
316
744
  this.provingState?.cancel();
317
745
  }
@@ -333,6 +761,22 @@ const logger = createLogger('prover-client:orchestrator');
333
761
  });
334
762
  return epochProofResult;
335
763
  }
764
+ async cleanupDBFork(blockNumber) {
765
+ this.logger.debug(`Cleaning up world state fork for ${blockNumber}`);
766
+ const fork = this.dbs.get(blockNumber);
767
+ if (!fork) {
768
+ return;
769
+ }
770
+ try {
771
+ if (!fork.cleanupPromise) {
772
+ fork.cleanupPromise = fork.fork.close();
773
+ }
774
+ await fork.cleanupPromise;
775
+ this.dbs.delete(blockNumber);
776
+ } catch (err) {
777
+ this.logger.error(`Error closing db for block ${blockNumber}`, err);
778
+ }
779
+ }
336
780
  /**
337
781
  * Enqueue a job to be scheduled
338
782
  * @param provingState - The proving state object being operated on
@@ -340,7 +784,7 @@ const logger = createLogger('prover-client:orchestrator');
340
784
  * @param job - The actual job, returns a promise notifying of the job's completion
341
785
  */ deferredProving(provingState, request, callback) {
342
786
  if (!provingState.verifyState()) {
343
- logger.debug(`Not enqueuing job, state no longer valid`);
787
+ this.logger.debug(`Not enqueuing job, state no longer valid`);
344
788
  return;
345
789
  }
346
790
  const controller = new AbortController();
@@ -355,7 +799,7 @@ const logger = createLogger('prover-client:orchestrator');
355
799
  }
356
800
  const result = await request(controller.signal);
357
801
  if (!provingState.verifyState()) {
358
- logger.debug(`State no longer valid, discarding result`);
802
+ this.logger.debug(`State no longer valid, discarding result`);
359
803
  return;
360
804
  }
361
805
  // we could have been cancelled whilst waiting for the result
@@ -370,7 +814,7 @@ const logger = createLogger('prover-client:orchestrator');
370
814
  // drop this result
371
815
  return;
372
816
  }
373
- logger.error(`Error thrown when proving job`, err);
817
+ this.logger.error(`Error thrown when proving job`, err);
374
818
  provingState.reject(`${err}`);
375
819
  } finally{
376
820
  const index = this.pendingProvingJobs.indexOf(controller);
@@ -426,17 +870,17 @@ const logger = createLogger('prover-client:orchestrator');
426
870
  // Executes the next level of merge if all inputs are available
427
871
  enqueueBaseRollup(provingState, txIndex) {
428
872
  if (!provingState.verifyState()) {
429
- logger.debug('Not running base rollup, state invalid');
873
+ this.logger.debug('Not running base rollup, state invalid');
430
874
  return;
431
875
  }
432
876
  if (!provingState.tryStartProvingBase(txIndex)) {
433
- logger.debug(`Base rollup for tx ${txIndex} already started.`);
877
+ this.logger.debug(`Base rollup for tx ${txIndex} already started.`);
434
878
  return;
435
879
  }
436
880
  const txProvingState = provingState.getTxProvingState(txIndex);
437
881
  const { processedTx } = txProvingState;
438
882
  const { rollupType, inputs } = txProvingState.getBaseRollupTypeAndInputs();
439
- logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
883
+ this.logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
440
884
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, `ProvingOrchestrator.prover.${inputs instanceof PrivateTxBaseRollupPrivateInputs ? 'getPrivateTxBaseRollupProof' : 'getPublicTxBaseRollupProof'}`, {
441
885
  [Attributes.TX_HASH]: processedTx.hash.toString(),
442
886
  [Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
@@ -447,7 +891,7 @@ const logger = createLogger('prover-client:orchestrator');
447
891
  return this.prover.getPublicTxBaseRollupProof(inputs, signal, provingState.epochNumber);
448
892
  }
449
893
  }), (result)=>{
450
- logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
894
+ this.logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
451
895
  validatePartialState(result.inputs.endTreeSnapshots, txProvingState.treeSnapshots);
452
896
  const leafLocation = provingState.setBaseRollupProof(txIndex, result);
453
897
  if (provingState.totalNumTxs === 1) {
@@ -461,14 +905,14 @@ const logger = createLogger('prover-client:orchestrator');
461
905
  // Once completed, will enqueue the the public tx base rollup.
462
906
  getOrEnqueueChonkVerifier(provingState, txIndex) {
463
907
  if (!provingState.verifyState()) {
464
- logger.debug('Not running chonk verifier circuit, state invalid');
908
+ this.logger.debug('Not running chonk verifier circuit, state invalid');
465
909
  return;
466
910
  }
467
911
  const txProvingState = provingState.getTxProvingState(txIndex);
468
912
  const txHash = txProvingState.processedTx.hash.toString();
469
913
  NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH;
470
914
  const handleResult = (result)=>{
471
- logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, {
915
+ this.logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, {
472
916
  txHash
473
917
  });
474
918
  txProvingState.setPublicChonkVerifierProof(result);
@@ -476,18 +920,18 @@ const logger = createLogger('prover-client:orchestrator');
476
920
  this.checkAndEnqueueBaseRollup(provingState, txIndex);
477
921
  };
478
922
  if (this.provingState?.cachedChonkVerifierProofs.has(txHash)) {
479
- logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, {
923
+ this.logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, {
480
924
  txHash
481
925
  });
482
926
  void this.provingState.cachedChonkVerifierProofs.get(txHash).then(handleResult);
483
927
  return;
484
928
  }
485
- logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
929
+ this.logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
486
930
  this.doEnqueueChonkVerifier(txHash, txProvingState.getPublicChonkVerifierPrivateInputs(), handleResult);
487
931
  }
488
932
  doEnqueueChonkVerifier(txHash, inputs, handler, provingState = this.provingState) {
489
933
  if (!provingState.verifyState()) {
490
- logger.debug('Not running chonk verifier circuit, state invalid');
934
+ this.logger.debug('Not running chonk verifier circuit, state invalid');
491
935
  return;
492
936
  }
493
937
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getPublicChonkVerifierProof', {
@@ -499,11 +943,11 @@ const logger = createLogger('prover-client:orchestrator');
499
943
  // Enqueues the next level of merge if all inputs are available
500
944
  enqueueMergeRollup(provingState, location) {
501
945
  if (!provingState.verifyState()) {
502
- logger.debug('Not running merge rollup. State no longer valid.');
946
+ this.logger.debug('Not running merge rollup. State no longer valid.');
503
947
  return;
504
948
  }
505
949
  if (!provingState.tryStartProvingMerge(location)) {
506
- logger.debug('Merge rollup already started.');
950
+ this.logger.debug('Merge rollup already started.');
507
951
  return;
508
952
  }
509
953
  const inputs = provingState.getMergeRollupInputs(location);
@@ -517,15 +961,15 @@ const logger = createLogger('prover-client:orchestrator');
517
961
  // Executes the block root rollup circuit
518
962
  enqueueBlockRootRollup(provingState) {
519
963
  if (!provingState.verifyState()) {
520
- logger.debug('Not running block root rollup, state no longer valid');
964
+ this.logger.debug('Not running block root rollup, state no longer valid');
521
965
  return;
522
966
  }
523
967
  if (!provingState.tryStartProvingBlockRoot()) {
524
- logger.debug('Block root rollup already started.');
968
+ this.logger.debug('Block root rollup already started.');
525
969
  return;
526
970
  }
527
971
  const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs();
528
- logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
972
+ this.logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
529
973
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getBlockRootRollupProof', {
530
974
  [Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
531
975
  }, (signal)=>{
@@ -541,27 +985,29 @@ const logger = createLogger('prover-client:orchestrator');
541
985
  return this.prover.getBlockRootRollupProof(inputs, signal, provingState.epochNumber);
542
986
  }
543
987
  }), async (result)=>{
544
- // If the proofs were slower than the block header building, then we need to try validating the block header hashes here.
545
- await this.verifyBuiltBlockAgainstSyncedState(provingState);
546
- logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
988
+ this.logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
547
989
  const leafLocation = provingState.setBlockRootRollupProof(result);
548
990
  const checkpointProvingState = provingState.parentCheckpoint;
991
+ // If the proofs were slower than the block header building, then we need to try validating the block header hashes here.
992
+ await this.verifyBuiltBlockAgainstSyncedState(provingState);
549
993
  if (checkpointProvingState.totalNumBlocks === 1) {
550
994
  this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
551
995
  } else {
552
996
  this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
553
997
  }
998
+ // We are finished with the block at this point, ensure the fork is cleaned up
999
+ void this.cleanupDBFork(provingState.blockNumber);
554
1000
  });
555
1001
  }
556
1002
  // Executes the base parity circuit and stores the intermediate state for the root parity circuit
557
1003
  // Enqueues the root parity circuit if all inputs are available
558
1004
  enqueueBaseParityCircuit(checkpointProvingState, provingState, baseParityIndex) {
559
1005
  if (!provingState.verifyState()) {
560
- logger.debug('Not running base parity. State no longer valid.');
1006
+ this.logger.debug('Not running base parity. State no longer valid.');
561
1007
  return;
562
1008
  }
563
1009
  if (!provingState.tryStartProvingBaseParity(baseParityIndex)) {
564
- logger.warn(`Base parity ${baseParityIndex} already started.`);
1010
+ this.logger.warn(`Base parity ${baseParityIndex} already started.`);
565
1011
  return;
566
1012
  }
567
1013
  const inputs = checkpointProvingState.getBaseParityInputs(baseParityIndex);
@@ -582,11 +1028,11 @@ const logger = createLogger('prover-client:orchestrator');
582
1028
  // Enqueues the root rollup proof if all inputs are available
583
1029
  enqueueRootParityCircuit(provingState) {
584
1030
  if (!provingState.verifyState()) {
585
- logger.debug('Not running root parity. State no longer valid.');
1031
+ this.logger.debug('Not running root parity. State no longer valid.');
586
1032
  return;
587
1033
  }
588
1034
  if (!provingState.tryStartProvingRootParity()) {
589
- logger.debug('Root parity already started.');
1035
+ this.logger.debug('Root parity already started.');
590
1036
  return;
591
1037
  }
592
1038
  const inputs = provingState.getParityRootInputs();
@@ -601,11 +1047,11 @@ const logger = createLogger('prover-client:orchestrator');
601
1047
  // Enqueues the next level of merge if all inputs are available
602
1048
  enqueueBlockMergeRollup(provingState, location) {
603
1049
  if (!provingState.verifyState()) {
604
- logger.debug('Not running block merge rollup. State no longer valid.');
1050
+ this.logger.debug('Not running block merge rollup. State no longer valid.');
605
1051
  return;
606
1052
  }
607
1053
  if (!provingState.tryStartProvingBlockMerge(location)) {
608
- logger.debug('Block merge rollup already started.');
1054
+ this.logger.debug('Block merge rollup already started.');
609
1055
  return;
610
1056
  }
611
1057
  const inputs = provingState.getBlockMergeRollupInputs(location);
@@ -618,15 +1064,15 @@ const logger = createLogger('prover-client:orchestrator');
618
1064
  }
619
1065
  enqueueCheckpointRootRollup(provingState) {
620
1066
  if (!provingState.verifyState()) {
621
- logger.debug('Not running checkpoint root rollup. State no longer valid.');
1067
+ this.logger.debug('Not running checkpoint root rollup. State no longer valid.');
622
1068
  return;
623
1069
  }
624
1070
  if (!provingState.tryStartProvingCheckpointRoot()) {
625
- logger.debug('Checkpoint root rollup already started.');
1071
+ this.logger.debug('Checkpoint root rollup already started.');
626
1072
  return;
627
1073
  }
628
1074
  const rollupType = provingState.getCheckpointRootRollupType();
629
- logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
1075
+ this.logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
630
1076
  const inputs = provingState.getCheckpointRootRollupInputs();
631
1077
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointRootRollupProof', {
632
1078
  [Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
@@ -640,11 +1086,11 @@ const logger = createLogger('prover-client:orchestrator');
640
1086
  const computedEndBlobAccumulatorState = provingState.getEndBlobAccumulator().toBlobAccumulator();
641
1087
  const circuitEndBlobAccumulatorState = result.inputs.endBlobAccumulator;
642
1088
  if (!circuitEndBlobAccumulatorState.equals(computedEndBlobAccumulatorState)) {
643
- logger.error(`Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(computedEndBlobAccumulatorState)}`);
1089
+ this.logger.error(`Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(computedEndBlobAccumulatorState)}`);
644
1090
  provingState.reject(`Blob accumulator state mismatch.`);
645
1091
  return;
646
1092
  }
647
- logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
1093
+ this.logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
648
1094
  const leafLocation = provingState.setCheckpointRootRollupProof(result);
649
1095
  const epochProvingState = provingState.parentEpoch;
650
1096
  if (epochProvingState.totalNumCheckpoints === 1) {
@@ -656,37 +1102,37 @@ const logger = createLogger('prover-client:orchestrator');
656
1102
  }
657
1103
  enqueueCheckpointMergeRollup(provingState, location) {
658
1104
  if (!provingState.verifyState()) {
659
- logger.debug('Not running checkpoint merge rollup. State no longer valid.');
1105
+ this.logger.debug('Not running checkpoint merge rollup. State no longer valid.');
660
1106
  return;
661
1107
  }
662
1108
  if (!provingState.tryStartProvingCheckpointMerge(location)) {
663
- logger.debug('Checkpoint merge rollup already started.');
1109
+ this.logger.debug('Checkpoint merge rollup already started.');
664
1110
  return;
665
1111
  }
666
1112
  const inputs = provingState.getCheckpointMergeRollupInputs(location);
667
1113
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointMergeRollupProof', {
668
1114
  [Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-merge'
669
1115
  }, (signal)=>this.prover.getCheckpointMergeRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
670
- logger.debug('Completed proof for checkpoint merge rollup.');
1116
+ this.logger.debug('Completed proof for checkpoint merge rollup.');
671
1117
  provingState.setCheckpointMergeRollupProof(location, result);
672
1118
  this.checkAndEnqueueNextCheckpointMergeRollup(provingState, location);
673
1119
  });
674
1120
  }
675
1121
  enqueueEpochPadding(provingState) {
676
1122
  if (!provingState.verifyState()) {
677
- logger.debug('Not running epoch padding. State no longer valid.');
1123
+ this.logger.debug('Not running epoch padding. State no longer valid.');
678
1124
  return;
679
1125
  }
680
1126
  if (!provingState.tryStartProvingPaddingCheckpoint()) {
681
- logger.debug('Padding checkpoint already started.');
1127
+ this.logger.debug('Padding checkpoint already started.');
682
1128
  return;
683
1129
  }
684
- logger.debug('Padding epoch proof with a padding block root proof.');
1130
+ this.logger.debug('Padding epoch proof with a padding block root proof.');
685
1131
  const inputs = provingState.getPaddingCheckpointInputs();
686
1132
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointPaddingRollupProof', {
687
1133
  [Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-padding'
688
1134
  }, (signal)=>this.prover.getCheckpointPaddingRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
689
- logger.debug('Completed proof for padding checkpoint.');
1135
+ this.logger.debug('Completed proof for padding checkpoint.');
690
1136
  provingState.setCheckpointPaddingProof(result);
691
1137
  this.checkAndEnqueueRootRollup(provingState);
692
1138
  });
@@ -694,15 +1140,15 @@ const logger = createLogger('prover-client:orchestrator');
694
1140
  // Executes the root rollup circuit
695
1141
  enqueueRootRollup(provingState) {
696
1142
  if (!provingState.verifyState()) {
697
- logger.debug('Not running root rollup, state no longer valid');
1143
+ this.logger.debug('Not running root rollup, state no longer valid');
698
1144
  return;
699
1145
  }
700
- logger.debug(`Preparing root rollup`);
1146
+ this.logger.debug(`Preparing root rollup`);
701
1147
  const inputs = provingState.getRootRollupInputs();
702
1148
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getRootRollupProof', {
703
1149
  [Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-root'
704
1150
  }, (signal)=>this.prover.getRootRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
705
- logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
1151
+ this.logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
706
1152
  provingState.setRootRollupProof(result);
707
1153
  provingState.resolve({
708
1154
  status: 'success'
@@ -722,7 +1168,7 @@ const logger = createLogger('prover-client:orchestrator');
722
1168
  }
723
1169
  checkAndEnqueueBlockRootRollup(provingState) {
724
1170
  if (!provingState.isReadyForBlockRootRollup()) {
725
- logger.debug('Not ready for block root rollup');
1171
+ this.logger.debug('Not ready for block root rollup');
726
1172
  return;
727
1173
  }
728
1174
  this.enqueueBlockRootRollup(provingState);
@@ -757,7 +1203,7 @@ const logger = createLogger('prover-client:orchestrator');
757
1203
  }
758
1204
  checkAndEnqueueRootRollup(provingState) {
759
1205
  if (!provingState.isReadyForRootRollup()) {
760
- logger.debug('Not ready for root rollup');
1206
+ this.logger.debug('Not ready for root rollup');
761
1207
  return;
762
1208
  }
763
1209
  this.enqueueRootRollup(provingState);
@@ -769,41 +1215,19 @@ const logger = createLogger('prover-client:orchestrator');
769
1215
  * @param txIndex - The index of the transaction being proven
770
1216
  */ enqueueVM(provingState, txIndex) {
771
1217
  if (!provingState.verifyState()) {
772
- logger.debug(`Not running VM circuit as state is no longer valid`);
1218
+ this.logger.debug(`Not running VM circuit as state is no longer valid`);
773
1219
  return;
774
1220
  }
775
1221
  const txProvingState = provingState.getTxProvingState(txIndex);
776
- // This function tries to do AVM proving. If there is a failure, it fakes the proof unless AVM_PROVING_STRICT is defined.
777
- // Nothing downstream depends on the AVM proof yet. So having this mode lets us incrementally build the AVM circuit.
778
1222
  const doAvmProving = wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getAvmProof', {
779
1223
  [Attributes.TX_HASH]: txProvingState.processedTx.hash.toString()
780
1224
  }, async (signal)=>{
781
1225
  const inputs = txProvingState.getAvmInputs();
782
- try {
783
- // TODO(#14234)[Unconditional PIs validation]: Remove the whole try-catch logic and
784
- // just keep the next line but removing the second argument (false).
785
- return await this.prover.getAvmProof(inputs, false, signal, provingState.epochNumber);
786
- } catch (err) {
787
- if (process.env.AVM_PROVING_STRICT) {
788
- logger.error(`Error thrown when proving AVM circuit with AVM_PROVING_STRICT on`, err);
789
- throw err;
790
- } else {
791
- logger.warn(`Error thrown when proving AVM circuit but AVM_PROVING_STRICT is off. Use snapshotted
792
- AVM inputs and carrying on. ${inspect(err)}.`);
793
- try {
794
- this.metrics.incAvmFallback();
795
- const snapshotAvmPrivateInputs = readAvmMinimalPublicTxInputsFromFile();
796
- return await this.prover.getAvmProof(snapshotAvmPrivateInputs, true, signal, provingState.epochNumber);
797
- } catch (err) {
798
- logger.error(`Error thrown when proving snapshotted AVM inputs.`, err);
799
- throw err;
800
- }
801
- }
802
- }
1226
+ return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
803
1227
  });
804
- this.deferredProving(provingState, doAvmProving, (proofAndVk)=>{
805
- logger.debug(`Proven VM for tx index: ${txIndex}`);
806
- txProvingState.setAvmProof(proofAndVk);
1228
+ this.deferredProving(provingState, doAvmProving, (proof)=>{
1229
+ this.logger.debug(`Proven VM for tx index: ${txIndex}`);
1230
+ txProvingState.setAvmProof(proof);
807
1231
  this.checkAndEnqueueBaseRollup(provingState, txIndex);
808
1232
  });
809
1233
  }
@@ -813,30 +1237,7 @@ const logger = createLogger('prover-client:orchestrator');
813
1237
  return;
814
1238
  }
815
1239
  // We must have completed all proving (chonk verifier proof and (if required) vm proof are generated), we now move to the base rollup.
816
- logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
1240
+ this.logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
817
1241
  this.enqueueBaseRollup(provingState, txIndex);
818
1242
  }
819
1243
  }
820
- _ts_decorate([
821
- trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
822
- [Attributes.BLOCK_NUMBER]: blockNumber
823
- }))
824
- ], ProvingOrchestrator.prototype, "startNewBlock", null);
825
- _ts_decorate([
826
- trackSpan('ProvingOrchestrator.addTxs', (txs)=>({
827
- [Attributes.BLOCK_TXS_COUNT]: txs.length
828
- }))
829
- ], ProvingOrchestrator.prototype, "addTxs", null);
830
- _ts_decorate([
831
- trackSpan('ProvingOrchestrator.startChonkVerifierCircuits')
832
- ], ProvingOrchestrator.prototype, "startChonkVerifierCircuits", null);
833
- _ts_decorate([
834
- trackSpan('ProvingOrchestrator.setBlockCompleted', (blockNumber)=>({
835
- [Attributes.BLOCK_NUMBER]: blockNumber
836
- }))
837
- ], ProvingOrchestrator.prototype, "setBlockCompleted", null);
838
- _ts_decorate([
839
- trackSpan('ProvingOrchestrator.prepareBaseRollupInputs', (tx)=>({
840
- [Attributes.TX_HASH]: tx.hash.toString()
841
- }))
842
- ], ProvingOrchestrator.prototype, "prepareBaseRollupInputs", null);