@aztec/prover-client 3.0.3 → 3.9.9-nightly.20260312

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 (118) hide show
  1. package/dest/light/index.d.ts +2 -0
  2. package/dest/light/index.d.ts.map +1 -0
  3. package/dest/light/index.js +1 -0
  4. package/dest/light/lightweight_checkpoint_builder.d.ts +34 -14
  5. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
  6. package/dest/light/lightweight_checkpoint_builder.js +124 -27
  7. package/dest/mocks/fixtures.d.ts +1 -1
  8. package/dest/mocks/fixtures.d.ts.map +1 -1
  9. package/dest/mocks/fixtures.js +2 -1
  10. package/dest/mocks/test_context.d.ts +4 -2
  11. package/dest/mocks/test_context.d.ts.map +1 -1
  12. package/dest/mocks/test_context.js +22 -5
  13. package/dest/orchestrator/block-building-helpers.d.ts +5 -5
  14. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  15. package/dest/orchestrator/block-building-helpers.js +4 -4
  16. package/dest/orchestrator/block-proving-state.d.ts +4 -1
  17. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  18. package/dest/orchestrator/block-proving-state.js +7 -0
  19. package/dest/orchestrator/checkpoint-proving-state.d.ts +17 -4
  20. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
  21. package/dest/orchestrator/checkpoint-proving-state.js +37 -4
  22. package/dest/orchestrator/epoch-proving-state.d.ts +7 -6
  23. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  24. package/dest/orchestrator/epoch-proving-state.js +37 -1
  25. package/dest/orchestrator/orchestrator.d.ts +21 -4
  26. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  27. package/dest/orchestrator/orchestrator.js +559 -154
  28. package/dest/orchestrator/orchestrator_metrics.d.ts +1 -3
  29. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
  30. package/dest/orchestrator/orchestrator_metrics.js +2 -15
  31. package/dest/orchestrator/tx-proving-state.d.ts +5 -4
  32. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  33. package/dest/orchestrator/tx-proving-state.js +6 -6
  34. package/dest/prover-client/factory.d.ts +3 -3
  35. package/dest/prover-client/factory.d.ts.map +1 -1
  36. package/dest/prover-client/prover-client.d.ts +6 -6
  37. package/dest/prover-client/prover-client.d.ts.map +1 -1
  38. package/dest/prover-client/prover-client.js +15 -10
  39. package/dest/proving_broker/broker_prover_facade.d.ts +7 -5
  40. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  41. package/dest/proving_broker/broker_prover_facade.js +8 -15
  42. package/dest/proving_broker/config.d.ts +13 -1
  43. package/dest/proving_broker/config.d.ts.map +1 -1
  44. package/dest/proving_broker/config.js +19 -2
  45. package/dest/proving_broker/proof_store/factory.d.ts +2 -5
  46. package/dest/proving_broker/proof_store/factory.d.ts.map +1 -1
  47. package/dest/proving_broker/proof_store/factory.js +7 -30
  48. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts +18 -0
  49. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts.map +1 -0
  50. package/dest/proving_broker/proof_store/file_store_proof_store.js +60 -0
  51. package/dest/proving_broker/proof_store/index.d.ts +2 -2
  52. package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
  53. package/dest/proving_broker/proof_store/index.js +1 -1
  54. package/dest/proving_broker/proving_agent.d.ts +5 -9
  55. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  56. package/dest/proving_broker/proving_agent.js +4 -19
  57. package/dest/proving_broker/proving_broker.d.ts +7 -4
  58. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  59. package/dest/proving_broker/proving_broker.js +40 -14
  60. package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
  61. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  62. package/dest/proving_broker/proving_broker_database/persisted.js +389 -1
  63. package/dest/proving_broker/proving_broker_instrumentation.d.ts +3 -1
  64. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  65. package/dest/proving_broker/proving_broker_instrumentation.js +22 -35
  66. package/dest/proving_broker/proving_job_controller.d.ts +4 -3
  67. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  68. package/dest/proving_broker/proving_job_controller.js +7 -5
  69. package/dest/proving_broker/rpc.d.ts +4 -2
  70. package/dest/proving_broker/rpc.d.ts.map +1 -1
  71. package/dest/proving_broker/rpc.js +8 -0
  72. package/dest/test/mock_proof_store.d.ts +3 -3
  73. package/dest/test/mock_proof_store.d.ts.map +1 -1
  74. package/dest/test/mock_prover.d.ts +5 -5
  75. package/dest/test/mock_prover.d.ts.map +1 -1
  76. package/dest/test/mock_prover.js +4 -4
  77. package/package.json +17 -18
  78. package/src/light/index.ts +1 -0
  79. package/src/light/lightweight_checkpoint_builder.ts +188 -34
  80. package/src/mocks/fixtures.ts +2 -1
  81. package/src/mocks/test_context.ts +17 -4
  82. package/src/orchestrator/block-building-helpers.ts +4 -4
  83. package/src/orchestrator/block-proving-state.ts +9 -0
  84. package/src/orchestrator/checkpoint-proving-state.ts +51 -5
  85. package/src/orchestrator/epoch-proving-state.ts +59 -9
  86. package/src/orchestrator/orchestrator.ts +160 -138
  87. package/src/orchestrator/orchestrator_metrics.ts +2 -25
  88. package/src/orchestrator/tx-proving-state.ts +8 -11
  89. package/src/prover-client/factory.ts +6 -2
  90. package/src/prover-client/prover-client.ts +33 -24
  91. package/src/proving_broker/broker_prover_facade.ts +18 -20
  92. package/src/proving_broker/config.ts +22 -0
  93. package/src/proving_broker/proof_store/factory.ts +10 -32
  94. package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
  95. package/src/proving_broker/proof_store/index.ts +1 -1
  96. package/src/proving_broker/proving_agent.ts +6 -19
  97. package/src/proving_broker/proving_broker.ts +41 -11
  98. package/src/proving_broker/proving_broker_database/persisted.ts +15 -1
  99. package/src/proving_broker/proving_broker_instrumentation.ts +23 -35
  100. package/src/proving_broker/proving_job_controller.ts +10 -5
  101. package/src/proving_broker/rpc.ts +14 -0
  102. package/src/test/mock_prover.ts +2 -14
  103. package/dest/block-factory/index.d.ts +0 -2
  104. package/dest/block-factory/index.d.ts.map +0 -1
  105. package/dest/block-factory/index.js +0 -1
  106. package/dest/block-factory/light.d.ts +0 -38
  107. package/dest/block-factory/light.d.ts.map +0 -1
  108. package/dest/block-factory/light.js +0 -108
  109. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +0 -14
  110. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +0 -1
  111. package/dest/proving_broker/proof_store/gcs_proof_store.js +0 -52
  112. package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
  113. package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
  114. package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
  115. package/src/block-factory/index.ts +0 -1
  116. package/src/block-factory/light.ts +0 -137
  117. package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
  118. package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
@@ -1,9 +1,376 @@
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
+ };
6
369
  }
370
+ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
371
+ return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
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';
@@ -11,10 +378,10 @@ import { Fr } from '@aztec/foundation/curves/bn254';
11
378
  import { AbortError } from '@aztec/foundation/error';
12
379
  import { createLogger } from '@aztec/foundation/log';
13
380
  import { promiseWithResolvers } from '@aztec/foundation/promise';
381
+ import { SerialQueue } from '@aztec/foundation/queue';
14
382
  import { assertLength } from '@aztec/foundation/serialize';
15
383
  import { pushTestData } from '@aztec/foundation/testing';
16
384
  import { elapsed } from '@aztec/foundation/timer';
17
- import { readAvmMinimalPublicTxInputsFromFile } from '@aztec/simulator/public/fixtures';
18
385
  import { BlockRootEmptyTxFirstRollupPrivateInputs, BlockRootFirstRollupPrivateInputs, BlockRootSingleTxFirstRollupPrivateInputs, BlockRootSingleTxRollupPrivateInputs, CheckpointRootSingleBlockRollupPrivateInputs, PrivateTxBaseRollupPrivateInputs } from '@aztec/stdlib/rollup';
19
386
  import { MerkleTreeId } from '@aztec/stdlib/trees';
20
387
  import { Attributes, getTelemetryClient, trackSpan, wrapCallbackInSpan } from '@aztec/telemetry-client';
@@ -23,7 +390,15 @@ import { buildHeaderFromCircuitOutputs, getLastSiblingPath, getPublicChonkVerifi
23
390
  import { EpochProvingState } from './epoch-proving-state.js';
24
391
  import { ProvingOrchestratorMetrics } from './orchestrator_metrics.js';
25
392
  import { TxProvingState } from './tx-proving-state.js';
26
- const logger = createLogger('prover-client:orchestrator');
393
+ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
394
+ [Attributes.BLOCK_NUMBER]: blockNumber
395
+ })), _dec1 = trackSpan('ProvingOrchestrator.addTxs', (txs)=>({
396
+ [Attributes.BLOCK_TXS_COUNT]: txs.length
397
+ })), _dec2 = trackSpan('ProvingOrchestrator.startChonkVerifierCircuits'), _dec3 = trackSpan('ProvingOrchestrator.setBlockCompleted', (blockNumber)=>({
398
+ [Attributes.BLOCK_NUMBER]: blockNumber
399
+ })), _dec4 = trackSpan('ProvingOrchestrator.prepareBaseRollupInputs', (tx)=>({
400
+ [Attributes.TX_HASH]: tx.hash.toString()
401
+ }));
27
402
  /**
28
403
  * Implements an event driven proving scheduler to build the recursive proof tree. The idea being:
29
404
  * 1. Transactions are provided to the scheduler post simulation.
@@ -39,21 +414,59 @@ const logger = createLogger('prover-client:orchestrator');
39
414
  dbProvider;
40
415
  prover;
41
416
  proverId;
417
+ cancelJobsOnStop;
418
+ enqueueConcurrency;
419
+ static{
420
+ ({ e: [_initProto] } = _apply_decs_2203_r(this, [
421
+ [
422
+ _dec,
423
+ 2,
424
+ "startNewBlock"
425
+ ],
426
+ [
427
+ _dec1,
428
+ 2,
429
+ "addTxs"
430
+ ],
431
+ [
432
+ _dec2,
433
+ 2,
434
+ "startChonkVerifierCircuits"
435
+ ],
436
+ [
437
+ _dec3,
438
+ 2,
439
+ "setBlockCompleted"
440
+ ],
441
+ [
442
+ _dec4,
443
+ 2,
444
+ "prepareBaseRollupInputs"
445
+ ]
446
+ ], []));
447
+ }
42
448
  provingState;
43
449
  pendingProvingJobs;
44
450
  provingPromise;
45
451
  metrics;
46
452
  // eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
47
453
  dbs;
48
- constructor(dbProvider, prover, proverId, telemetryClient = getTelemetryClient()){
454
+ logger;
455
+ deferredJobQueue;
456
+ constructor(dbProvider, prover, proverId, cancelJobsOnStop = false, enqueueConcurrency, telemetryClient = getTelemetryClient(), bindings){
49
457
  this.dbProvider = dbProvider;
50
458
  this.prover = prover;
51
459
  this.proverId = proverId;
52
- this.provingState = undefined;
460
+ this.cancelJobsOnStop = cancelJobsOnStop;
461
+ this.enqueueConcurrency = enqueueConcurrency;
462
+ this.provingState = (_initProto(this), undefined);
53
463
  this.pendingProvingJobs = [];
54
464
  this.provingPromise = undefined;
55
465
  this.dbs = new Map();
466
+ this.deferredJobQueue = new SerialQueue();
467
+ this.logger = createLogger('prover-client:orchestrator', bindings);
56
468
  this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'ProvingOrchestrator');
469
+ this.deferredJobQueue.start(this.enqueueConcurrency);
57
470
  }
58
471
  get tracer() {
59
472
  return this.metrics.tracer;
@@ -61,9 +474,14 @@ const logger = createLogger('prover-client:orchestrator');
61
474
  getProverId() {
62
475
  return this.proverId;
63
476
  }
64
- stop() {
477
+ getNumActiveForks() {
478
+ return this.dbs.size;
479
+ }
480
+ async stop() {
481
+ // Grab the old queue before cancel() replaces it, so we can await its draining.
482
+ const oldQueue = this.deferredJobQueue;
65
483
  this.cancel();
66
- return Promise.resolve();
484
+ await oldQueue.cancel();
67
485
  }
68
486
  startNewEpoch(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges) {
69
487
  if (this.provingState?.verifyState()) {
@@ -74,11 +492,18 @@ const logger = createLogger('prover-client:orchestrator');
74
492
  status: 'failure',
75
493
  reason
76
494
  }));
77
- logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
495
+ this.logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
78
496
  this.provingState = new EpochProvingState(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges, (provingState)=>this.checkAndEnqueueCheckpointRootRollup(provingState), resolve, reject);
79
497
  this.provingPromise = promise;
80
498
  }
81
- async startNewCheckpoint(checkpointIndex, constants, l1ToL2Messages, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint) {
499
+ /**
500
+ * Starts a new checkpoint.
501
+ * @param checkpointIndex - The index of the checkpoint in the epoch.
502
+ * @param constants - The constants for this checkpoint.
503
+ * @param l1ToL2Messages - The set of L1 to L2 messages to be inserted at the beginning of this checkpoint.
504
+ * @param totalNumBlocks - The total number of blocks expected in the checkpoint (must be at least one).
505
+ * @param headerOfLastBlockInPreviousCheckpoint - The header of the last block in the previous checkpoint.
506
+ */ async startNewCheckpoint(checkpointIndex, constants, l1ToL2Messages, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint) {
82
507
  if (!this.provingState) {
83
508
  throw new Error('Empty epoch proving state. Call startNewEpoch before starting a checkpoint.');
84
509
  }
@@ -114,14 +539,14 @@ const logger = createLogger('prover-client:orchestrator');
114
539
  throw new Error(`Checkpoint not accepting further blocks.`);
115
540
  }
116
541
  const constants = checkpointProvingState.constants;
117
- logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
542
+ this.logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
118
543
  // Fork the db only when it's not already set. The db for the first block is set in `startNewCheckpoint`.
119
544
  if (!this.dbs.has(blockNumber)) {
120
545
  // Fork world state at the end of the immediately previous block
121
546
  const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
122
547
  this.dbs.set(blockNumber, db);
123
548
  }
124
- const db = this.dbs.get(blockNumber);
549
+ const db = this.getDbForBlock(blockNumber);
125
550
  // Get archive snapshot and sibling path before any txs in this block lands.
126
551
  const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
127
552
  const lastArchiveSiblingPath = await getRootTreeSiblingPath(MerkleTreeId.ARCHIVE, db);
@@ -141,7 +566,8 @@ const logger = createLogger('prover-client:orchestrator');
141
566
  const blockEndBlobFields = blockProvingState.getBlockEndBlobFields();
142
567
  await endSpongeBlob.absorb(blockEndBlobFields);
143
568
  blockProvingState.setEndSpongeBlob(endSpongeBlob);
144
- // And also try to accumulate the blobs as far as we can:
569
+ // Try to accumulate the out hashes and blobs as far as we can:
570
+ await this.provingState.accumulateCheckpointOutHashes();
145
571
  await this.provingState.setBlobAccumulators();
146
572
  }
147
573
  }
@@ -155,7 +581,7 @@ const logger = createLogger('prover-client:orchestrator');
155
581
  if (!txs.length) {
156
582
  // To avoid an ugly throw below. If we require an empty block, we can just call setBlockCompleted
157
583
  // 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.`);
584
+ this.logger.warn(`Provided no txs to orchestrator addTxs.`);
159
585
  return;
160
586
  }
161
587
  const blockNumber = BlockNumber(txs[0].globalVariables.blockNumber);
@@ -169,8 +595,8 @@ const logger = createLogger('prover-client:orchestrator');
169
595
  if (!provingState.isAcceptingTxs()) {
170
596
  throw new Error(`Block ${blockNumber} has been initialized with transactions.`);
171
597
  }
172
- logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
173
- const db = this.dbs.get(blockNumber);
598
+ this.logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
599
+ const db = this.getDbForBlock(blockNumber);
174
600
  const lastArchive = provingState.lastArchiveTreeSnapshot;
175
601
  const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
176
602
  const spongeBlobState = provingState.getStartSpongeBlob().clone();
@@ -180,7 +606,7 @@ const logger = createLogger('prover-client:orchestrator');
180
606
  throw new Error(`Invalid proving state when adding a tx`);
181
607
  }
182
608
  validateTx(tx);
183
- logger.info(`Received transaction: ${tx.hash}`);
609
+ this.logger.debug(`Received transaction: ${tx.hash}`);
184
610
  const startSpongeBlob = spongeBlobState.clone();
185
611
  const [hints, treeSnapshots] = await this.prepareBaseRollupInputs(tx, lastArchive, newL1ToL2MessageTreeSnapshot, startSpongeBlob, db);
186
612
  if (!provingState.verifyState()) {
@@ -191,10 +617,10 @@ const logger = createLogger('prover-client:orchestrator');
191
617
  const txIndex = provingState.addNewTx(txProvingState);
192
618
  if (txProvingState.requireAvmProof) {
193
619
  this.getOrEnqueueChonkVerifier(provingState, txIndex);
194
- logger.debug(`Enqueueing public VM for tx ${txIndex}`);
620
+ this.logger.debug(`Enqueueing public VM for tx ${txIndex}`);
195
621
  this.enqueueVM(provingState, txIndex);
196
622
  } else {
197
- logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
623
+ this.logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
198
624
  this.enqueueBaseRollup(provingState, txIndex);
199
625
  }
200
626
  } catch (err) {
@@ -208,7 +634,8 @@ const logger = createLogger('prover-client:orchestrator');
208
634
  const blockEndBlobFields = provingState.getBlockEndBlobFields();
209
635
  await spongeBlobState.absorb(blockEndBlobFields);
210
636
  provingState.setEndSpongeBlob(spongeBlobState);
211
- // Txs have been added to the block. Now try to accumulate the blobs as far as we can:
637
+ // Txs have been added to the block. Now try to accumulate the out hashes and blobs as far as we can:
638
+ await this.provingState.accumulateCheckpointOutHashes();
212
639
  await this.provingState.setBlobAccumulators();
213
640
  }
214
641
  /**
@@ -223,7 +650,7 @@ const logger = createLogger('prover-client:orchestrator');
223
650
  const txHash = tx.getTxHash().toString();
224
651
  const privateInputs = getPublicChonkVerifierPrivateInputsFromTx(tx, this.proverId.toField());
225
652
  const tubeProof = promiseWithResolvers();
226
- logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
653
+ this.logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
227
654
  this.doEnqueueChonkVerifier(txHash, privateInputs, (proof)=>{
228
655
  tubeProof.resolve(proof);
229
656
  });
@@ -252,17 +679,23 @@ const logger = createLogger('prover-client:orchestrator');
252
679
  throw new Error(`Block ${blockNumber} is still accepting txs. Call setBlockCompleted after all txs have been added.`);
253
680
  }
254
681
  // Given we've applied every change from this block, now assemble the block header:
255
- logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
682
+ this.logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
256
683
  const header = await provingState.buildBlockHeader();
257
684
  if (expectedHeader && !header.equals(expectedHeader)) {
258
- logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
685
+ this.logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
259
686
  throw new Error('Block header mismatch');
260
687
  }
261
- // Get db for this block
262
- const db = this.dbs.get(provingState.blockNumber);
263
- // 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()}`);
265
- await db.updateArchive(header);
688
+ // Get db for this block and remove from map — no other code should use it after this point.
689
+ const db = this.getDbForBlock(provingState.blockNumber);
690
+ this.dbs.delete(provingState.blockNumber);
691
+ // Update the archive tree, capture the snapshot, and close the fork deterministically.
692
+ try {
693
+ this.logger.verbose(`Updating archive tree with block ${provingState.blockNumber} header ${(await header.hash()).toString()}`);
694
+ await db.updateArchive(header);
695
+ provingState.setBuiltArchive(await getTreeSnapshot(MerkleTreeId.ARCHIVE, db));
696
+ } finally{
697
+ await db.close();
698
+ }
266
699
  await this.verifyBuiltBlockAgainstSyncedState(provingState);
267
700
  return header;
268
701
  }
@@ -270,50 +703,65 @@ const logger = createLogger('prover-client:orchestrator');
270
703
  async verifyBuiltBlockAgainstSyncedState(provingState) {
271
704
  const builtBlockHeader = provingState.getBuiltBlockHeader();
272
705
  if (!builtBlockHeader) {
273
- logger.debug('Block header not built yet, skipping header check.');
706
+ this.logger.debug('Block header not built yet, skipping header check.');
274
707
  return;
275
708
  }
276
709
  const output = provingState.getBlockRootRollupOutput();
277
710
  if (!output) {
278
- logger.debug('Block root rollup proof not built yet, skipping header check.');
711
+ this.logger.debug('Block root rollup proof not built yet, skipping header check.');
712
+ return;
713
+ }
714
+ const newArchive = provingState.getBuiltArchive();
715
+ if (!newArchive) {
716
+ this.logger.debug('Archive snapshot not yet captured, skipping header check.');
279
717
  return;
280
718
  }
281
719
  const header = await buildHeaderFromCircuitOutputs(output);
282
720
  if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
283
- logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
721
+ this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
284
722
  provingState.reject(`Block header hash mismatch.`);
285
723
  return;
286
724
  }
287
- // Get db for this block
288
725
  const blockNumber = provingState.blockNumber;
289
- const db = this.dbs.get(blockNumber);
290
- const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
291
726
  const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
292
727
  if (!syncedArchive.equals(newArchive)) {
293
- logger.error(`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(syncedArchive)} but built ${inspect(newArchive)}`);
728
+ this.logger.error(`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(syncedArchive)} but built ${inspect(newArchive)}`);
294
729
  provingState.reject(`Archive tree mismatch.`);
295
730
  return;
296
731
  }
297
732
  const circuitArchive = output.newArchive;
298
733
  if (!newArchive.equals(circuitArchive)) {
299
- logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
734
+ this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
300
735
  provingState.reject(`New archive mismatch.`);
301
736
  return;
302
737
  }
303
- // TODO(palla/prover): This closes the fork only on the happy path. If this epoch orchestrator
304
- // is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
305
- // but have to make sure it only runs once all operations are completed, otherwise some function here
306
- // 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));
309
738
  }
310
739
  /**
311
- * Cancel any further proving
740
+ * Cancel any further proving.
741
+ * If cancelJobsOnStop is true, aborts all pending jobs with the broker (which marks them as 'Aborted').
742
+ * If cancelJobsOnStop is false (default), jobs remain in the broker queue and can be reused on restart/reorg.
312
743
  */ cancel() {
313
- for (const controller of this.pendingProvingJobs){
314
- controller.abort();
744
+ void this.deferredJobQueue.cancel();
745
+ // Recreate the queue so it can accept jobs for subsequent epochs.
746
+ this.deferredJobQueue = new SerialQueue();
747
+ this.deferredJobQueue.start(this.enqueueConcurrency);
748
+ if (this.cancelJobsOnStop) {
749
+ for (const controller of this.pendingProvingJobs){
750
+ controller.abort();
751
+ }
315
752
  }
316
753
  this.provingState?.cancel();
754
+ for (const [blockNumber, db] of this.dbs.entries()){
755
+ void db.close().catch((err)=>this.logger.error(`Error closing db for block ${blockNumber}`, err));
756
+ }
757
+ this.dbs.clear();
758
+ }
759
+ getDbForBlock(blockNumber) {
760
+ const db = this.dbs.get(blockNumber);
761
+ if (!db) {
762
+ throw new Error(`World state fork for block ${blockNumber} not found.`);
763
+ }
764
+ return db;
317
765
  }
318
766
  /**
319
767
  * Returns the proof for the current epoch.
@@ -340,7 +788,7 @@ const logger = createLogger('prover-client:orchestrator');
340
788
  * @param job - The actual job, returns a promise notifying of the job's completion
341
789
  */ deferredProving(provingState, request, callback) {
342
790
  if (!provingState.verifyState()) {
343
- logger.debug(`Not enqueuing job, state no longer valid`);
791
+ this.logger.debug(`Not enqueuing job, state no longer valid`);
344
792
  return;
345
793
  }
346
794
  const controller = new AbortController();
@@ -355,7 +803,7 @@ const logger = createLogger('prover-client:orchestrator');
355
803
  }
356
804
  const result = await request(controller.signal);
357
805
  if (!provingState.verifyState()) {
358
- logger.debug(`State no longer valid, discarding result`);
806
+ this.logger.debug(`State no longer valid, discarding result`);
359
807
  return;
360
808
  }
361
809
  // we could have been cancelled whilst waiting for the result
@@ -370,7 +818,7 @@ const logger = createLogger('prover-client:orchestrator');
370
818
  // drop this result
371
819
  return;
372
820
  }
373
- logger.error(`Error thrown when proving job`, err);
821
+ this.logger.error(`Error thrown when proving job`, err);
374
822
  provingState.reject(`${err}`);
375
823
  } finally{
376
824
  const index = this.pendingProvingJobs.indexOf(controller);
@@ -379,8 +827,9 @@ const logger = createLogger('prover-client:orchestrator');
379
827
  }
380
828
  }
381
829
  };
382
- // let the callstack unwind before adding the job to the queue
383
- setImmediate(()=>void safeJob());
830
+ // Enqueue onto the serial queue with limited workers to avoid starving the event loop.
831
+ // Workers yield between jobs via await, allowing I/O callbacks to process.
832
+ void this.deferredJobQueue.put(()=>safeJob());
384
833
  }
385
834
  async updateL1ToL2MessageTree(l1ToL2Messages, db) {
386
835
  const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, 'Too many L1 to L2 messages');
@@ -426,17 +875,17 @@ const logger = createLogger('prover-client:orchestrator');
426
875
  // Executes the next level of merge if all inputs are available
427
876
  enqueueBaseRollup(provingState, txIndex) {
428
877
  if (!provingState.verifyState()) {
429
- logger.debug('Not running base rollup, state invalid');
878
+ this.logger.debug('Not running base rollup, state invalid');
430
879
  return;
431
880
  }
432
881
  if (!provingState.tryStartProvingBase(txIndex)) {
433
- logger.debug(`Base rollup for tx ${txIndex} already started.`);
882
+ this.logger.debug(`Base rollup for tx ${txIndex} already started.`);
434
883
  return;
435
884
  }
436
885
  const txProvingState = provingState.getTxProvingState(txIndex);
437
886
  const { processedTx } = txProvingState;
438
887
  const { rollupType, inputs } = txProvingState.getBaseRollupTypeAndInputs();
439
- logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
888
+ this.logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
440
889
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, `ProvingOrchestrator.prover.${inputs instanceof PrivateTxBaseRollupPrivateInputs ? 'getPrivateTxBaseRollupProof' : 'getPublicTxBaseRollupProof'}`, {
441
890
  [Attributes.TX_HASH]: processedTx.hash.toString(),
442
891
  [Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
@@ -447,7 +896,7 @@ const logger = createLogger('prover-client:orchestrator');
447
896
  return this.prover.getPublicTxBaseRollupProof(inputs, signal, provingState.epochNumber);
448
897
  }
449
898
  }), (result)=>{
450
- logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
899
+ this.logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
451
900
  validatePartialState(result.inputs.endTreeSnapshots, txProvingState.treeSnapshots);
452
901
  const leafLocation = provingState.setBaseRollupProof(txIndex, result);
453
902
  if (provingState.totalNumTxs === 1) {
@@ -461,14 +910,14 @@ const logger = createLogger('prover-client:orchestrator');
461
910
  // Once completed, will enqueue the the public tx base rollup.
462
911
  getOrEnqueueChonkVerifier(provingState, txIndex) {
463
912
  if (!provingState.verifyState()) {
464
- logger.debug('Not running chonk verifier circuit, state invalid');
913
+ this.logger.debug('Not running chonk verifier circuit, state invalid');
465
914
  return;
466
915
  }
467
916
  const txProvingState = provingState.getTxProvingState(txIndex);
468
917
  const txHash = txProvingState.processedTx.hash.toString();
469
918
  NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH;
470
919
  const handleResult = (result)=>{
471
- logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, {
920
+ this.logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, {
472
921
  txHash
473
922
  });
474
923
  txProvingState.setPublicChonkVerifierProof(result);
@@ -476,18 +925,18 @@ const logger = createLogger('prover-client:orchestrator');
476
925
  this.checkAndEnqueueBaseRollup(provingState, txIndex);
477
926
  };
478
927
  if (this.provingState?.cachedChonkVerifierProofs.has(txHash)) {
479
- logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, {
928
+ this.logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, {
480
929
  txHash
481
930
  });
482
931
  void this.provingState.cachedChonkVerifierProofs.get(txHash).then(handleResult);
483
932
  return;
484
933
  }
485
- logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
934
+ this.logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
486
935
  this.doEnqueueChonkVerifier(txHash, txProvingState.getPublicChonkVerifierPrivateInputs(), handleResult);
487
936
  }
488
937
  doEnqueueChonkVerifier(txHash, inputs, handler, provingState = this.provingState) {
489
938
  if (!provingState.verifyState()) {
490
- logger.debug('Not running chonk verifier circuit, state invalid');
939
+ this.logger.debug('Not running chonk verifier circuit, state invalid');
491
940
  return;
492
941
  }
493
942
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getPublicChonkVerifierProof', {
@@ -499,11 +948,11 @@ const logger = createLogger('prover-client:orchestrator');
499
948
  // Enqueues the next level of merge if all inputs are available
500
949
  enqueueMergeRollup(provingState, location) {
501
950
  if (!provingState.verifyState()) {
502
- logger.debug('Not running merge rollup. State no longer valid.');
951
+ this.logger.debug('Not running merge rollup. State no longer valid.');
503
952
  return;
504
953
  }
505
954
  if (!provingState.tryStartProvingMerge(location)) {
506
- logger.debug('Merge rollup already started.');
955
+ this.logger.debug('Merge rollup already started.');
507
956
  return;
508
957
  }
509
958
  const inputs = provingState.getMergeRollupInputs(location);
@@ -517,15 +966,15 @@ const logger = createLogger('prover-client:orchestrator');
517
966
  // Executes the block root rollup circuit
518
967
  enqueueBlockRootRollup(provingState) {
519
968
  if (!provingState.verifyState()) {
520
- logger.debug('Not running block root rollup, state no longer valid');
969
+ this.logger.debug('Not running block root rollup, state no longer valid');
521
970
  return;
522
971
  }
523
972
  if (!provingState.tryStartProvingBlockRoot()) {
524
- logger.debug('Block root rollup already started.');
973
+ this.logger.debug('Block root rollup already started.');
525
974
  return;
526
975
  }
527
976
  const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs();
528
- logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
977
+ this.logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
529
978
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getBlockRootRollupProof', {
530
979
  [Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
531
980
  }, (signal)=>{
@@ -541,15 +990,16 @@ const logger = createLogger('prover-client:orchestrator');
541
990
  return this.prover.getBlockRootRollupProof(inputs, signal, provingState.epochNumber);
542
991
  }
543
992
  }), 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}`);
993
+ this.logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
547
994
  const leafLocation = provingState.setBlockRootRollupProof(result);
548
995
  const checkpointProvingState = provingState.parentCheckpoint;
996
+ // Verification is called from both here and setBlockCompleted. Whichever runs last
997
+ // will be the first to see all three pieces (header, proof output, archive) and run the checks.
998
+ await this.verifyBuiltBlockAgainstSyncedState(provingState);
549
999
  if (checkpointProvingState.totalNumBlocks === 1) {
550
- this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
1000
+ await this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
551
1001
  } else {
552
- this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
1002
+ await this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
553
1003
  }
554
1004
  });
555
1005
  }
@@ -557,11 +1007,11 @@ const logger = createLogger('prover-client:orchestrator');
557
1007
  // Enqueues the root parity circuit if all inputs are available
558
1008
  enqueueBaseParityCircuit(checkpointProvingState, provingState, baseParityIndex) {
559
1009
  if (!provingState.verifyState()) {
560
- logger.debug('Not running base parity. State no longer valid.');
1010
+ this.logger.debug('Not running base parity. State no longer valid.');
561
1011
  return;
562
1012
  }
563
1013
  if (!provingState.tryStartProvingBaseParity(baseParityIndex)) {
564
- logger.warn(`Base parity ${baseParityIndex} already started.`);
1014
+ this.logger.warn(`Base parity ${baseParityIndex} already started.`);
565
1015
  return;
566
1016
  }
567
1017
  const inputs = checkpointProvingState.getBaseParityInputs(baseParityIndex);
@@ -582,11 +1032,11 @@ const logger = createLogger('prover-client:orchestrator');
582
1032
  // Enqueues the root rollup proof if all inputs are available
583
1033
  enqueueRootParityCircuit(provingState) {
584
1034
  if (!provingState.verifyState()) {
585
- logger.debug('Not running root parity. State no longer valid.');
1035
+ this.logger.debug('Not running root parity. State no longer valid.');
586
1036
  return;
587
1037
  }
588
1038
  if (!provingState.tryStartProvingRootParity()) {
589
- logger.debug('Root parity already started.');
1039
+ this.logger.debug('Root parity already started.');
590
1040
  return;
591
1041
  }
592
1042
  const inputs = provingState.getParityRootInputs();
@@ -601,33 +1051,33 @@ const logger = createLogger('prover-client:orchestrator');
601
1051
  // Enqueues the next level of merge if all inputs are available
602
1052
  enqueueBlockMergeRollup(provingState, location) {
603
1053
  if (!provingState.verifyState()) {
604
- logger.debug('Not running block merge rollup. State no longer valid.');
1054
+ this.logger.debug('Not running block merge rollup. State no longer valid.');
605
1055
  return;
606
1056
  }
607
1057
  if (!provingState.tryStartProvingBlockMerge(location)) {
608
- logger.debug('Block merge rollup already started.');
1058
+ this.logger.debug('Block merge rollup already started.');
609
1059
  return;
610
1060
  }
611
1061
  const inputs = provingState.getBlockMergeRollupInputs(location);
612
1062
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getBlockMergeRollupProof', {
613
1063
  [Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-block-merge'
614
- }, (signal)=>this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
1064
+ }, (signal)=>this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber)), async (result)=>{
615
1065
  provingState.setBlockMergeRollupProof(location, result);
616
- this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
1066
+ await this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
617
1067
  });
618
1068
  }
619
- enqueueCheckpointRootRollup(provingState) {
1069
+ async enqueueCheckpointRootRollup(provingState) {
620
1070
  if (!provingState.verifyState()) {
621
- logger.debug('Not running checkpoint root rollup. State no longer valid.');
1071
+ this.logger.debug('Not running checkpoint root rollup. State no longer valid.');
622
1072
  return;
623
1073
  }
624
1074
  if (!provingState.tryStartProvingCheckpointRoot()) {
625
- logger.debug('Checkpoint root rollup already started.');
1075
+ this.logger.debug('Checkpoint root rollup already started.');
626
1076
  return;
627
1077
  }
628
1078
  const rollupType = provingState.getCheckpointRootRollupType();
629
- logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
630
- const inputs = provingState.getCheckpointRootRollupInputs();
1079
+ this.logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
1080
+ const inputs = await provingState.getCheckpointRootRollupInputs();
631
1081
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointRootRollupProof', {
632
1082
  [Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
633
1083
  }, (signal)=>{
@@ -640,11 +1090,11 @@ const logger = createLogger('prover-client:orchestrator');
640
1090
  const computedEndBlobAccumulatorState = provingState.getEndBlobAccumulator().toBlobAccumulator();
641
1091
  const circuitEndBlobAccumulatorState = result.inputs.endBlobAccumulator;
642
1092
  if (!circuitEndBlobAccumulatorState.equals(computedEndBlobAccumulatorState)) {
643
- logger.error(`Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(computedEndBlobAccumulatorState)}`);
1093
+ this.logger.error(`Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(computedEndBlobAccumulatorState)}`);
644
1094
  provingState.reject(`Blob accumulator state mismatch.`);
645
1095
  return;
646
1096
  }
647
- logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
1097
+ this.logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
648
1098
  const leafLocation = provingState.setCheckpointRootRollupProof(result);
649
1099
  const epochProvingState = provingState.parentEpoch;
650
1100
  if (epochProvingState.totalNumCheckpoints === 1) {
@@ -656,37 +1106,37 @@ const logger = createLogger('prover-client:orchestrator');
656
1106
  }
657
1107
  enqueueCheckpointMergeRollup(provingState, location) {
658
1108
  if (!provingState.verifyState()) {
659
- logger.debug('Not running checkpoint merge rollup. State no longer valid.');
1109
+ this.logger.debug('Not running checkpoint merge rollup. State no longer valid.');
660
1110
  return;
661
1111
  }
662
1112
  if (!provingState.tryStartProvingCheckpointMerge(location)) {
663
- logger.debug('Checkpoint merge rollup already started.');
1113
+ this.logger.debug('Checkpoint merge rollup already started.');
664
1114
  return;
665
1115
  }
666
1116
  const inputs = provingState.getCheckpointMergeRollupInputs(location);
667
1117
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointMergeRollupProof', {
668
1118
  [Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-merge'
669
1119
  }, (signal)=>this.prover.getCheckpointMergeRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
670
- logger.debug('Completed proof for checkpoint merge rollup.');
1120
+ this.logger.debug('Completed proof for checkpoint merge rollup.');
671
1121
  provingState.setCheckpointMergeRollupProof(location, result);
672
1122
  this.checkAndEnqueueNextCheckpointMergeRollup(provingState, location);
673
1123
  });
674
1124
  }
675
1125
  enqueueEpochPadding(provingState) {
676
1126
  if (!provingState.verifyState()) {
677
- logger.debug('Not running epoch padding. State no longer valid.');
1127
+ this.logger.debug('Not running epoch padding. State no longer valid.');
678
1128
  return;
679
1129
  }
680
1130
  if (!provingState.tryStartProvingPaddingCheckpoint()) {
681
- logger.debug('Padding checkpoint already started.');
1131
+ this.logger.debug('Padding checkpoint already started.');
682
1132
  return;
683
1133
  }
684
- logger.debug('Padding epoch proof with a padding block root proof.');
1134
+ this.logger.debug('Padding epoch proof with a padding block root proof.');
685
1135
  const inputs = provingState.getPaddingCheckpointInputs();
686
1136
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointPaddingRollupProof', {
687
1137
  [Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-padding'
688
1138
  }, (signal)=>this.prover.getCheckpointPaddingRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
689
- logger.debug('Completed proof for padding checkpoint.');
1139
+ this.logger.debug('Completed proof for padding checkpoint.');
690
1140
  provingState.setCheckpointPaddingProof(result);
691
1141
  this.checkAndEnqueueRootRollup(provingState);
692
1142
  });
@@ -694,15 +1144,15 @@ const logger = createLogger('prover-client:orchestrator');
694
1144
  // Executes the root rollup circuit
695
1145
  enqueueRootRollup(provingState) {
696
1146
  if (!provingState.verifyState()) {
697
- logger.debug('Not running root rollup, state no longer valid');
1147
+ this.logger.debug('Not running root rollup, state no longer valid');
698
1148
  return;
699
1149
  }
700
- logger.debug(`Preparing root rollup`);
1150
+ this.logger.debug(`Preparing root rollup`);
701
1151
  const inputs = provingState.getRootRollupInputs();
702
1152
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getRootRollupProof', {
703
1153
  [Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-root'
704
1154
  }, (signal)=>this.prover.getRootRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
705
- logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
1155
+ this.logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
706
1156
  provingState.setRootRollupProof(result);
707
1157
  provingState.resolve({
708
1158
  status: 'success'
@@ -722,27 +1172,27 @@ const logger = createLogger('prover-client:orchestrator');
722
1172
  }
723
1173
  checkAndEnqueueBlockRootRollup(provingState) {
724
1174
  if (!provingState.isReadyForBlockRootRollup()) {
725
- logger.debug('Not ready for block root rollup');
1175
+ this.logger.debug('Not ready for block root rollup');
726
1176
  return;
727
1177
  }
728
1178
  this.enqueueBlockRootRollup(provingState);
729
1179
  }
730
- checkAndEnqueueNextBlockMergeRollup(provingState, currentLocation) {
1180
+ async checkAndEnqueueNextBlockMergeRollup(provingState, currentLocation) {
731
1181
  if (!provingState.isReadyForBlockMerge(currentLocation)) {
732
1182
  return;
733
1183
  }
734
1184
  const parentLocation = provingState.getParentLocation(currentLocation);
735
1185
  if (parentLocation.level === 0) {
736
- this.checkAndEnqueueCheckpointRootRollup(provingState);
1186
+ await this.checkAndEnqueueCheckpointRootRollup(provingState);
737
1187
  } else {
738
1188
  this.enqueueBlockMergeRollup(provingState, parentLocation);
739
1189
  }
740
1190
  }
741
- checkAndEnqueueCheckpointRootRollup(provingState) {
1191
+ async checkAndEnqueueCheckpointRootRollup(provingState) {
742
1192
  if (!provingState.isReadyForCheckpointRoot()) {
743
1193
  return;
744
1194
  }
745
- this.enqueueCheckpointRootRollup(provingState);
1195
+ await this.enqueueCheckpointRootRollup(provingState);
746
1196
  }
747
1197
  checkAndEnqueueNextCheckpointMergeRollup(provingState, currentLocation) {
748
1198
  if (!provingState.isReadyForCheckpointMerge(currentLocation)) {
@@ -757,7 +1207,7 @@ const logger = createLogger('prover-client:orchestrator');
757
1207
  }
758
1208
  checkAndEnqueueRootRollup(provingState) {
759
1209
  if (!provingState.isReadyForRootRollup()) {
760
- logger.debug('Not ready for root rollup');
1210
+ this.logger.debug('Not ready for root rollup');
761
1211
  return;
762
1212
  }
763
1213
  this.enqueueRootRollup(provingState);
@@ -769,41 +1219,19 @@ const logger = createLogger('prover-client:orchestrator');
769
1219
  * @param txIndex - The index of the transaction being proven
770
1220
  */ enqueueVM(provingState, txIndex) {
771
1221
  if (!provingState.verifyState()) {
772
- logger.debug(`Not running VM circuit as state is no longer valid`);
1222
+ this.logger.debug(`Not running VM circuit as state is no longer valid`);
773
1223
  return;
774
1224
  }
775
1225
  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
1226
  const doAvmProving = wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getAvmProof', {
779
1227
  [Attributes.TX_HASH]: txProvingState.processedTx.hash.toString()
780
1228
  }, async (signal)=>{
781
1229
  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
- }
1230
+ return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
803
1231
  });
804
- this.deferredProving(provingState, doAvmProving, (proofAndVk)=>{
805
- logger.debug(`Proven VM for tx index: ${txIndex}`);
806
- txProvingState.setAvmProof(proofAndVk);
1232
+ this.deferredProving(provingState, doAvmProving, (proof)=>{
1233
+ this.logger.debug(`Proven VM for tx index: ${txIndex}`);
1234
+ txProvingState.setAvmProof(proof);
807
1235
  this.checkAndEnqueueBaseRollup(provingState, txIndex);
808
1236
  });
809
1237
  }
@@ -813,30 +1241,7 @@ const logger = createLogger('prover-client:orchestrator');
813
1241
  return;
814
1242
  }
815
1243
  // 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`);
1244
+ this.logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
817
1245
  this.enqueueBaseRollup(provingState, txIndex);
818
1246
  }
819
1247
  }
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);