@aztec-labs/prover-client 6.0.0-nightly.20260829

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 (170) hide show
  1. package/README.md +1 -0
  2. package/dest/config.d.ts +17 -0
  3. package/dest/config.d.ts.map +1 -0
  4. package/dest/config.js +63 -0
  5. package/dest/index.d.ts +4 -0
  6. package/dest/index.d.ts.map +1 -0
  7. package/dest/index.js +2 -0
  8. package/dest/light/index.d.ts +2 -0
  9. package/dest/light/index.d.ts.map +1 -0
  10. package/dest/light/index.js +1 -0
  11. package/dest/light/lightweight_checkpoint_builder.d.ts +58 -0
  12. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
  13. package/dest/light/lightweight_checkpoint_builder.js +243 -0
  14. package/dest/mocks/fixtures.d.ts +20 -0
  15. package/dest/mocks/fixtures.d.ts.map +1 -0
  16. package/dest/mocks/fixtures.js +96 -0
  17. package/dest/mocks/test_context.d.ts +93 -0
  18. package/dest/mocks/test_context.d.ts.map +1 -0
  19. package/dest/mocks/test_context.js +354 -0
  20. package/dest/orchestrator/block-building-helpers.d.ts +67 -0
  21. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -0
  22. package/dest/orchestrator/block-building-helpers.js +274 -0
  23. package/dest/orchestrator/block-proving-state.d.ts +107 -0
  24. package/dest/orchestrator/block-proving-state.d.ts.map +1 -0
  25. package/dest/orchestrator/block-proving-state.js +339 -0
  26. package/dest/orchestrator/checkpoint-proving-state.d.ts +67 -0
  27. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
  28. package/dest/orchestrator/checkpoint-proving-state.js +175 -0
  29. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +169 -0
  30. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
  31. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.js +1047 -0
  32. package/dest/orchestrator/chonk-cache.d.ts +39 -0
  33. package/dest/orchestrator/chonk-cache.d.ts.map +1 -0
  34. package/dest/orchestrator/chonk-cache.js +80 -0
  35. package/dest/orchestrator/index.d.ts +4 -0
  36. package/dest/orchestrator/index.d.ts.map +1 -0
  37. package/dest/orchestrator/index.js +3 -0
  38. package/dest/orchestrator/orchestrator_metrics.d.ts +8 -0
  39. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -0
  40. package/dest/orchestrator/orchestrator_metrics.js +13 -0
  41. package/dest/orchestrator/proving-scheduler.d.ts +81 -0
  42. package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
  43. package/dest/orchestrator/proving-scheduler.js +120 -0
  44. package/dest/orchestrator/top-tree-orchestrator.d.ts +89 -0
  45. package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
  46. package/dest/orchestrator/top-tree-orchestrator.js +233 -0
  47. package/dest/orchestrator/top-tree-proving-state.d.ts +61 -0
  48. package/dest/orchestrator/top-tree-proving-state.d.ts.map +1 -0
  49. package/dest/orchestrator/top-tree-proving-state.js +185 -0
  50. package/dest/orchestrator/tx-proving-state.d.ts +37 -0
  51. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -0
  52. package/dest/orchestrator/tx-proving-state.js +77 -0
  53. package/dest/prover-client/factory.d.ts +6 -0
  54. package/dest/prover-client/factory.d.ts.map +1 -0
  55. package/dest/prover-client/factory.js +5 -0
  56. package/dest/prover-client/index.d.ts +3 -0
  57. package/dest/prover-client/index.d.ts.map +1 -0
  58. package/dest/prover-client/index.js +2 -0
  59. package/dest/prover-client/prover-client.d.ts +99 -0
  60. package/dest/prover-client/prover-client.d.ts.map +1 -0
  61. package/dest/prover-client/prover-client.js +163 -0
  62. package/dest/proving_broker/broker_prover_facade.d.ts +52 -0
  63. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -0
  64. package/dest/proving_broker/broker_prover_facade.js +360 -0
  65. package/dest/proving_broker/config.d.ts +40 -0
  66. package/dest/proving_broker/config.d.ts.map +1 -0
  67. package/dest/proving_broker/config.js +138 -0
  68. package/dest/proving_broker/factory.d.ts +5 -0
  69. package/dest/proving_broker/factory.d.ts.map +1 -0
  70. package/dest/proving_broker/factory.js +13 -0
  71. package/dest/proving_broker/fixtures.d.ts +6 -0
  72. package/dest/proving_broker/fixtures.d.ts.map +1 -0
  73. package/dest/proving_broker/fixtures.js +13 -0
  74. package/dest/proving_broker/index.d.ts +11 -0
  75. package/dest/proving_broker/index.d.ts.map +1 -0
  76. package/dest/proving_broker/index.js +10 -0
  77. package/dest/proving_broker/proof_store/factory.d.ts +3 -0
  78. package/dest/proving_broker/proof_store/factory.d.ts.map +1 -0
  79. package/dest/proving_broker/proof_store/factory.js +13 -0
  80. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts +18 -0
  81. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts.map +1 -0
  82. package/dest/proving_broker/proof_store/file_store_proof_store.js +60 -0
  83. package/dest/proving_broker/proof_store/index.d.ts +5 -0
  84. package/dest/proving_broker/proof_store/index.d.ts.map +1 -0
  85. package/dest/proving_broker/proof_store/index.js +4 -0
  86. package/dest/proving_broker/proof_store/inline_proof_store.d.ts +15 -0
  87. package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -0
  88. package/dest/proving_broker/proof_store/inline_proof_store.js +41 -0
  89. package/dest/proving_broker/proof_store/proof_store.d.ts +36 -0
  90. package/dest/proving_broker/proof_store/proof_store.d.ts.map +1 -0
  91. package/dest/proving_broker/proof_store/proof_store.js +3 -0
  92. package/dest/proving_broker/proving_agent.d.ts +42 -0
  93. package/dest/proving_broker/proving_agent.d.ts.map +1 -0
  94. package/dest/proving_broker/proving_agent.js +155 -0
  95. package/dest/proving_broker/proving_broker.d.ts +77 -0
  96. package/dest/proving_broker/proving_broker.d.ts.map +1 -0
  97. package/dest/proving_broker/proving_broker.js +780 -0
  98. package/dest/proving_broker/proving_broker_database/memory.d.ts +20 -0
  99. package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -0
  100. package/dest/proving_broker/proving_broker_database/memory.js +67 -0
  101. package/dest/proving_broker/proving_broker_database/persisted.d.ts +40 -0
  102. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -0
  103. package/dest/proving_broker/proving_broker_database/persisted.js +623 -0
  104. package/dest/proving_broker/proving_broker_database.d.ts +66 -0
  105. package/dest/proving_broker/proving_broker_database.d.ts.map +1 -0
  106. package/dest/proving_broker/proving_broker_database.js +3 -0
  107. package/dest/proving_broker/proving_broker_instrumentation.d.ts +31 -0
  108. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -0
  109. package/dest/proving_broker/proving_broker_instrumentation.js +97 -0
  110. package/dest/proving_broker/proving_job_controller.d.ts +34 -0
  111. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -0
  112. package/dest/proving_broker/proving_job_controller.js +184 -0
  113. package/dest/proving_broker/rpc.d.ts +38 -0
  114. package/dest/proving_broker/rpc.d.ts.map +1 -0
  115. package/dest/proving_broker/rpc.js +138 -0
  116. package/dest/test/epoch_settlement.d.ts +36 -0
  117. package/dest/test/epoch_settlement.d.ts.map +1 -0
  118. package/dest/test/epoch_settlement.js +52 -0
  119. package/dest/test/index.d.ts +2 -0
  120. package/dest/test/index.d.ts.map +1 -0
  121. package/dest/test/index.js +1 -0
  122. package/dest/test/mock_proof_store.d.ts +9 -0
  123. package/dest/test/mock_proof_store.d.ts.map +1 -0
  124. package/dest/test/mock_proof_store.js +10 -0
  125. package/dest/test/mock_prover.d.ts +38 -0
  126. package/dest/test/mock_prover.d.ts.map +1 -0
  127. package/dest/test/mock_prover.js +91 -0
  128. package/package.json +113 -0
  129. package/src/config.ts +87 -0
  130. package/src/index.ts +4 -0
  131. package/src/light/index.ts +1 -0
  132. package/src/light/lightweight_checkpoint_builder.ts +342 -0
  133. package/src/mocks/fixtures.ts +120 -0
  134. package/src/mocks/test_context.ts +477 -0
  135. package/src/orchestrator/block-building-helpers.ts +486 -0
  136. package/src/orchestrator/block-proving-state.ts +457 -0
  137. package/src/orchestrator/checkpoint-proving-state.ts +247 -0
  138. package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +1010 -0
  139. package/src/orchestrator/chonk-cache.ts +99 -0
  140. package/src/orchestrator/index.ts +12 -0
  141. package/src/orchestrator/orchestrator_metrics.ts +18 -0
  142. package/src/orchestrator/proving-scheduler.ts +160 -0
  143. package/src/orchestrator/top-tree-orchestrator.ts +394 -0
  144. package/src/orchestrator/top-tree-proving-state.ts +219 -0
  145. package/src/orchestrator/tx-proving-state.ts +121 -0
  146. package/src/prover-client/factory.ts +18 -0
  147. package/src/prover-client/index.ts +2 -0
  148. package/src/prover-client/prover-client.ts +286 -0
  149. package/src/proving_broker/broker_prover_facade.ts +626 -0
  150. package/src/proving_broker/config.ts +178 -0
  151. package/src/proving_broker/factory.ts +19 -0
  152. package/src/proving_broker/fixtures.ts +20 -0
  153. package/src/proving_broker/index.ts +10 -0
  154. package/src/proving_broker/proof_store/factory.ts +20 -0
  155. package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
  156. package/src/proving_broker/proof_store/index.ts +4 -0
  157. package/src/proving_broker/proof_store/inline_proof_store.ts +63 -0
  158. package/src/proving_broker/proof_store/proof_store.ts +54 -0
  159. package/src/proving_broker/proving_agent.ts +210 -0
  160. package/src/proving_broker/proving_broker.ts +888 -0
  161. package/src/proving_broker/proving_broker_database/memory.ts +78 -0
  162. package/src/proving_broker/proving_broker_database/persisted.ts +296 -0
  163. package/src/proving_broker/proving_broker_database.ts +75 -0
  164. package/src/proving_broker/proving_broker_instrumentation.ts +133 -0
  165. package/src/proving_broker/proving_job_controller.ts +199 -0
  166. package/src/proving_broker/rpc.ts +131 -0
  167. package/src/test/epoch_settlement.ts +82 -0
  168. package/src/test/index.ts +1 -0
  169. package/src/test/mock_proof_store.ts +14 -0
  170. package/src/test/mock_prover.ts +304 -0
@@ -0,0 +1,623 @@
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);
372
+ }
373
+ var _dec, _initProto;
374
+ import { EpochNumber } from '@aztec-labs/foundation/branded-types';
375
+ import { jsonParseWithSchema, jsonStringify } from '@aztec-labs/foundation/json-rpc';
376
+ import { createLogger } from '@aztec-labs/foundation/log';
377
+ import { BatchQueue } from '@aztec-labs/foundation/queue';
378
+ import { openVersionedStoreAt } from '@aztec-labs/kv-store/lmdb-v2';
379
+ import { ProvingJob, ProvingJobSettledResult, getEpochFromProvingJobId } from '@aztec-labs/stdlib/interfaces/server';
380
+ import { Attributes, LmdbMetrics, getTelemetryClient, trackSpan } from '@aztec-labs/telemetry-client';
381
+ import { mkdir, readdir } from 'fs/promises';
382
+ import { join } from 'path';
383
+ class SingleEpochDatabase {
384
+ store;
385
+ static SCHEMA_VERSION = 2;
386
+ jobs;
387
+ jobResults;
388
+ constructor(store){
389
+ this.store = store;
390
+ this.jobs = store.openMap('proving_jobs');
391
+ this.jobResults = store.openMap('proving_job_results');
392
+ }
393
+ estimateSize() {
394
+ return this.store.estimateSize();
395
+ }
396
+ async batchWrite(jobs, results, deletedResults = []) {
397
+ await this.store.transactionAsync(async ()=>{
398
+ for (const job of jobs){
399
+ await this.jobs.set(job.id, jsonStringify(job));
400
+ }
401
+ for (const [id, result] of results){
402
+ await this.jobResults.set(id, jsonStringify(result));
403
+ }
404
+ // Deletes are applied after sets so that, if a set and a delete for the same id land in one
405
+ // batch (e.g. an abort immediately followed by a revive's result-delete), the delete wins.
406
+ for (const id of deletedResults){
407
+ await this.jobResults.delete(id);
408
+ }
409
+ });
410
+ }
411
+ async *allProvingJobs() {
412
+ for await (const jobStr of this.jobs.valuesAsync()){
413
+ const job = jsonParseWithSchema(jobStr, ProvingJob);
414
+ const resultStr = await this.jobResults.getAsync(job.id);
415
+ const result = resultStr ? jsonParseWithSchema(resultStr, ProvingJobSettledResult) : undefined;
416
+ yield [
417
+ job,
418
+ result
419
+ ];
420
+ }
421
+ }
422
+ async getProvingJobInputs(id) {
423
+ const jobStr = await this.jobs.getAsync(id);
424
+ return jobStr ? jsonParseWithSchema(jobStr, ProvingJob).inputsUri : undefined;
425
+ }
426
+ async getProvingJobResult(id) {
427
+ const resultStr = await this.jobResults.getAsync(id);
428
+ return resultStr ? jsonParseWithSchema(resultStr, ProvingJobSettledResult) : undefined;
429
+ }
430
+ async setProvingJobError(id, reason) {
431
+ const result = {
432
+ status: 'rejected',
433
+ reason
434
+ };
435
+ await this.jobResults.set(id, jsonStringify(result));
436
+ }
437
+ async setProvingJobAborted(id) {
438
+ const result = {
439
+ status: 'aborted'
440
+ };
441
+ await this.jobResults.set(id, jsonStringify(result));
442
+ }
443
+ async setProvingJobResult(id, value) {
444
+ const result = {
445
+ status: 'fulfilled',
446
+ value
447
+ };
448
+ await this.jobResults.set(id, jsonStringify(result));
449
+ }
450
+ delete() {
451
+ return this.store.delete();
452
+ }
453
+ close() {
454
+ return this.store.close();
455
+ }
456
+ }
457
+ _dec = trackSpan('KVBrokerDatabase.deleteAllProvingJobsOlderThanEpoch', (epochNumber)=>({
458
+ [Attributes.EPOCH_NUMBER]: epochNumber
459
+ }));
460
+ export class KVBrokerDatabase {
461
+ epochs;
462
+ config;
463
+ logger;
464
+ static{
465
+ ({ e: [_initProto] } = _apply_decs_2203_r(this, [
466
+ [
467
+ _dec,
468
+ 2,
469
+ "deleteAllProvingJobsOlderThanEpoch"
470
+ ]
471
+ ], []));
472
+ }
473
+ metrics;
474
+ batchQueue;
475
+ tracer;
476
+ constructor(epochs, config, client = getTelemetryClient(), logger){
477
+ this.epochs = epochs;
478
+ this.config = config;
479
+ this.logger = logger;
480
+ _initProto(this);
481
+ this.metrics = new LmdbMetrics(client.getMeter('KVBrokerDatabase'), {
482
+ [Attributes.DB_DATA_TYPE]: 'prover-broker'
483
+ }, ()=>this.estimateSize());
484
+ this.tracer = client.getTracer('KVBrokerDatabase');
485
+ this.batchQueue = new BatchQueue((items, key)=>this.commitWrites(items, key), config.proverBrokerBatchSize, config.proverBrokerBatchIntervalMs, createLogger('proving-client:proving-broker-database:batch-queue'));
486
+ }
487
+ // exposed for testing
488
+ async commitWrites(items, epochNumber) {
489
+ const jobsToAdd = items.filter((item)=>'id' in item);
490
+ const resultOps = items.filter((item)=>Array.isArray(item));
491
+ const resultsToSet = resultOps.filter((op)=>op[1] !== undefined);
492
+ const resultsToDelete = resultOps.filter((op)=>op[1] === undefined).map(([id])=>id);
493
+ const db = await this.getEpochDatabase(EpochNumber(epochNumber));
494
+ await db.batchWrite(jobsToAdd, resultsToSet, resultsToDelete);
495
+ }
496
+ async estimateSize() {
497
+ const sizes = await Promise.all(Array.from(this.epochs.values()).map((x)=>x.estimateSize()));
498
+ return {
499
+ mappingSize: this.config.dataStoreMapSizeKb,
500
+ physicalFileSize: sizes.reduce((prev, curr)=>prev + curr.physicalFileSize, 0),
501
+ numItems: sizes.reduce((prev, curr)=>prev + curr.numItems, 0),
502
+ actualSize: sizes.reduce((prev, curr)=>prev + curr.actualSize, 0)
503
+ };
504
+ }
505
+ static async new(config, client = getTelemetryClient(), logger = createLogger('prover-client:proving-broker-database')) {
506
+ const epochs = new Map();
507
+ const files = await readdir(config.dataDirectory, {
508
+ recursive: false,
509
+ withFileTypes: true
510
+ });
511
+ for (const file of files){
512
+ if (!file.isDirectory()) {
513
+ continue;
514
+ }
515
+ const fullDirectory = join(config.dataDirectory, file.name);
516
+ const epochDirectory = file.name;
517
+ const epochNumber = parseInt(epochDirectory, 10);
518
+ if (!Number.isSafeInteger(epochNumber) || epochNumber < 0) {
519
+ logger.warn(`Found invalid epoch directory ${fullDirectory} when loading epoch databases, ignoring`);
520
+ continue;
521
+ }
522
+ logger.info(`Loading broker database for epoch ${epochNumber} from ${fullDirectory} with map size ${config.dataStoreMapSizeKb}KB`);
523
+ const db = await openVersionedStoreAt(fullDirectory, SingleEpochDatabase.SCHEMA_VERSION, config.rollupAddress, config.dataStoreMapSizeKb);
524
+ const epochDb = new SingleEpochDatabase(db);
525
+ epochs.set(epochNumber, epochDb);
526
+ }
527
+ const db = new KVBrokerDatabase(epochs, config, client, logger);
528
+ db.start();
529
+ return db;
530
+ }
531
+ start() {
532
+ this.batchQueue.start();
533
+ }
534
+ async close() {
535
+ await this.batchQueue.stop();
536
+ for (const [_, v] of this.epochs){
537
+ await v.close();
538
+ }
539
+ }
540
+ async deleteAllProvingJobsOlderThanEpoch(epochNumber) {
541
+ const oldEpochs = Array.from(this.epochs.keys()).filter((e)=>e < Number(epochNumber));
542
+ for (const old of oldEpochs){
543
+ const db = this.epochs.get(old);
544
+ if (!db) {
545
+ continue;
546
+ }
547
+ this.logger.verbose(`Deleting broker database for epoch ${old}`);
548
+ await db.delete();
549
+ this.epochs.delete(old);
550
+ }
551
+ }
552
+ // Key jobs by the id-derived epoch, the same epoch results are written under (setProvingJobResult et
553
+ // al.). This keeps a job's inputs and its result co-located in one epoch database so both can be read
554
+ // back with a single keyed lookup (getProvingJobInputs/getProvingJobResult) rather than a scan. The id
555
+ // embeds the epoch and equals `job.epochNumber` at every construction site, so this matches the prior
556
+ // storage epoch while making the id the single source of truth for placement.
557
+ addProvingJob(job) {
558
+ return this.batchQueue.put(job, getEpochFromProvingJobId(job.id));
559
+ }
560
+ async *allProvingJobs() {
561
+ const iterators = Array.from(this.epochs.values()).map((x)=>x.allProvingJobs());
562
+ for (const it of iterators){
563
+ yield* it;
564
+ }
565
+ }
566
+ // A job id is `${epochNumber}:${type}:${inputsHash}`, so its epoch is recoverable directly and maps to
567
+ // exactly one epoch database. Results are already written under this same id-derived epoch (see
568
+ // setProvingJobResult et al.), and a job's `epochNumber` equals its id-epoch at every construction site,
569
+ // so inputs live there too. Use `epochs.get` (not `getEpochDatabase`, which would create the store on a
570
+ // miss) so a read for an unknown id has no side effects.
571
+ getProvingJobInputs(id) {
572
+ return this.epochs.get(getEpochFromProvingJobId(id))?.getProvingJobInputs(id) ?? Promise.resolve(undefined);
573
+ }
574
+ getProvingJobResult(id) {
575
+ return this.epochs.get(getEpochFromProvingJobId(id))?.getProvingJobResult(id) ?? Promise.resolve(undefined);
576
+ }
577
+ setProvingJobError(id, reason) {
578
+ return this.batchQueue.put([
579
+ id,
580
+ {
581
+ status: 'rejected',
582
+ reason
583
+ }
584
+ ], getEpochFromProvingJobId(id));
585
+ }
586
+ setProvingJobAborted(id) {
587
+ return this.batchQueue.put([
588
+ id,
589
+ {
590
+ status: 'aborted'
591
+ }
592
+ ], getEpochFromProvingJobId(id));
593
+ }
594
+ deleteProvingJobResult(id) {
595
+ return this.batchQueue.put([
596
+ id,
597
+ undefined
598
+ ], getEpochFromProvingJobId(id));
599
+ }
600
+ setProvingJobResult(id, value) {
601
+ return this.batchQueue.put([
602
+ id,
603
+ {
604
+ status: 'fulfilled',
605
+ value
606
+ }
607
+ ], getEpochFromProvingJobId(id));
608
+ }
609
+ async getEpochDatabase(epochNumber) {
610
+ let epochDb = this.epochs.get(epochNumber);
611
+ if (!epochDb) {
612
+ const newEpochDirectory = join(this.config.dataDirectory, epochNumber.toString());
613
+ await mkdir(newEpochDirectory, {
614
+ recursive: true
615
+ });
616
+ this.logger.info(`Creating broker database for epoch ${epochNumber} at ${newEpochDirectory} with map size ${this.config.dataStoreMapSizeKb}`);
617
+ const db = await openVersionedStoreAt(newEpochDirectory, SingleEpochDatabase.SCHEMA_VERSION, this.config.rollupAddress, this.config.dataStoreMapSizeKb);
618
+ epochDb = new SingleEpochDatabase(db);
619
+ this.epochs.set(epochNumber, epochDb);
620
+ }
621
+ return epochDb;
622
+ }
623
+ }
@@ -0,0 +1,66 @@
1
+ import { EpochNumber } from '@aztec-labs/foundation/branded-types';
2
+ import type { ProofUri, ProvingJob, ProvingJobId, ProvingJobSettledResult } from '@aztec-labs/stdlib/interfaces/server';
3
+ /**
4
+ * A database for storing proof requests and their results
5
+ */
6
+ export interface ProvingBrokerDatabase {
7
+ /**
8
+ * Saves a proof request so it can be retrieved later
9
+ * @param job - The proof request to save
10
+ */
11
+ addProvingJob(job: ProvingJob): Promise<void>;
12
+ /**
13
+ * Deletes all proving jobs belonging to epochs older than the given epoch
14
+ * @param epochNumber - The epoch number beyond which jobs should be deleted
15
+ */
16
+ deleteAllProvingJobsOlderThanEpoch(epochNumber: EpochNumber): Promise<void>;
17
+ /**
18
+ * Returns an iterator over all saved proving jobs
19
+ */
20
+ allProvingJobs(): AsyncIterableIterator<[ProvingJob, ProvingJobSettledResult | undefined]>;
21
+ /**
22
+ * Reads a single job's inputs URI by id, or undefined if the job is unknown. The broker keeps only
23
+ * job metadata in memory and reads the (large) inputs from here on demand when dispatching to an agent.
24
+ * @param id - The ID of the proof request
25
+ */
26
+ getProvingJobInputs(id: ProvingJobId): Promise<ProofUri | undefined>;
27
+ /**
28
+ * Reads a single job's settled result by id, or undefined if not settled. The broker keeps only the
29
+ * settled status in memory and reads the (large) fulfilled proof from here on demand.
30
+ * @param id - The ID of the proof request
31
+ */
32
+ getProvingJobResult(id: ProvingJobId): Promise<ProvingJobSettledResult | undefined>;
33
+ /**
34
+ * Saves the result of a proof request
35
+ * @param id - The ID of the proof request to save the result for
36
+ * @param ProvingRequestType - The type of proof that was requested
37
+ * @param value - The result of the proof request
38
+ */
39
+ setProvingJobResult(id: ProvingJobId, value: ProofUri): Promise<void>;
40
+ /**
41
+ * Saves an error that occurred while processing a proof request
42
+ * @param id - The ID of the proof request to save the error for
43
+ * @param ProvingRequestType - The type of proof that was requested
44
+ * @param err - The error that occurred while processing the proof request
45
+ */
46
+ setProvingJobError(id: ProvingJobId, err: string): Promise<void>;
47
+ /**
48
+ * Records that a proof request was cancelled. Unlike a result or error this is not terminal:
49
+ * re-enqueuing the same job id revives it, so the aborted state can survive a restart without
50
+ * permanently blocking the proof.
51
+ * @param id - The ID of the cancelled proof request
52
+ */
53
+ setProvingJobAborted(id: ProvingJobId): Promise<void>;
54
+ /**
55
+ * Clears any stored result for a proof request, returning it to the pending state while keeping
56
+ * the job itself. Used when reviving an aborted job so the revival is persisted and a restart
57
+ * cannot resurrect the stale aborted state.
58
+ * @param id - The ID of the proof request whose result should be cleared
59
+ */
60
+ deleteProvingJobResult(id: ProvingJobId): Promise<void>;
61
+ /**
62
+ * Closes the database
63
+ */
64
+ close(): Promise<void>;
65
+ }
66
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvdmluZ19icm9rZXJfZGF0YWJhc2UuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wcm92aW5nX2Jyb2tlci9wcm92aW5nX2Jyb2tlcl9kYXRhYmFzZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU0sc0NBQXNDLENBQUM7QUFDbkUsT0FBTyxLQUFLLEVBQUUsUUFBUSxFQUFFLFVBQVUsRUFBRSxZQUFZLEVBQUUsdUJBQXVCLEVBQUUsTUFBTSxzQ0FBc0MsQ0FBQztBQUV4SDs7R0FFRztBQUNILE1BQU0sV0FBVyxxQkFBcUI7SUFDcEM7OztPQUdHO0lBQ0gsYUFBYSxDQUFDLEdBQUcsRUFBRSxVQUFVLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBRTlDOzs7T0FHRztJQUNILGtDQUFrQyxDQUFDLFdBQVcsRUFBRSxXQUFXLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBRTVFOztPQUVHO0lBQ0gsY0FBYyxJQUFJLHFCQUFxQixDQUFDLENBQUMsVUFBVSxFQUFFLHVCQUF1QixHQUFHLFNBQVMsQ0FBQyxDQUFDLENBQUM7SUFFM0Y7Ozs7T0FJRztJQUNILG1CQUFtQixDQUFDLEVBQUUsRUFBRSxZQUFZLEdBQUcsT0FBTyxDQUFDLFFBQVEsR0FBRyxTQUFTLENBQUMsQ0FBQztJQUVyRTs7OztPQUlHO0lBQ0gsbUJBQW1CLENBQUMsRUFBRSxFQUFFLFlBQVksR0FBRyxPQUFPLENBQUMsdUJBQXVCLEdBQUcsU0FBUyxDQUFDLENBQUM7SUFFcEY7Ozs7O09BS0c7SUFDSCxtQkFBbUIsQ0FBQyxFQUFFLEVBQUUsWUFBWSxFQUFFLEtBQUssRUFBRSxRQUFRLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBRXRFOzs7OztPQUtHO0lBQ0gsa0JBQWtCLENBQUMsRUFBRSxFQUFFLFlBQVksRUFBRSxHQUFHLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQztJQUVqRTs7Ozs7T0FLRztJQUNILG9CQUFvQixDQUFDLEVBQUUsRUFBRSxZQUFZLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBRXREOzs7OztPQUtHO0lBQ0gsc0JBQXNCLENBQUMsRUFBRSxFQUFFLFlBQVksR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7SUFFeEQ7O09BRUc7SUFDSCxLQUFLLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0NBQ3hCIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proving_broker_database.d.ts","sourceRoot":"","sources":["../../src/proving_broker/proving_broker_database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAExH;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9C;;;OAGG;IACH,kCAAkC,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5E;;OAEG;IACH,cAAc,IAAI,qBAAqB,CAAC,CAAC,UAAU,EAAE,uBAAuB,GAAG,SAAS,CAAC,CAAC,CAAC;IAE3F;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,EAAE,YAAY,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC;IAErE;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,EAAE,YAAY,GAAG,OAAO,CAAC,uBAAuB,GAAG,SAAS,CAAC,CAAC;IAEpF;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtE;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjE;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtD;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExD;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}