@aztec/prover-client 0.0.0-test.1 → 0.0.1-commit.017a351

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 (185) hide show
  1. package/dest/config.d.ts +8 -8
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +26 -2
  4. package/dest/index.d.ts +1 -1
  5. package/dest/light/index.d.ts +2 -0
  6. package/dest/light/index.d.ts.map +1 -0
  7. package/dest/light/index.js +1 -0
  8. package/dest/light/lightweight_checkpoint_builder.d.ts +52 -0
  9. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
  10. package/dest/light/lightweight_checkpoint_builder.js +231 -0
  11. package/dest/mocks/fixtures.d.ts +8 -8
  12. package/dest/mocks/fixtures.d.ts.map +1 -1
  13. package/dest/mocks/fixtures.js +36 -17
  14. package/dest/mocks/test_context.d.ts +45 -32
  15. package/dest/mocks/test_context.d.ts.map +1 -1
  16. package/dest/mocks/test_context.js +162 -90
  17. package/dest/orchestrator/block-building-helpers.d.ts +36 -29
  18. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  19. package/dest/orchestrator/block-building-helpers.js +170 -189
  20. package/dest/orchestrator/block-proving-state.d.ts +73 -48
  21. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  22. package/dest/orchestrator/block-proving-state.js +289 -177
  23. package/dest/orchestrator/checkpoint-proving-state.d.ts +83 -0
  24. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
  25. package/dest/orchestrator/checkpoint-proving-state.js +252 -0
  26. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +107 -0
  27. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
  28. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.js +151 -0
  29. package/dest/orchestrator/epoch-proving-context.d.ts +51 -0
  30. package/dest/orchestrator/epoch-proving-context.d.ts.map +1 -0
  31. package/dest/orchestrator/epoch-proving-context.js +81 -0
  32. package/dest/orchestrator/epoch-proving-state.d.ts +43 -28
  33. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  34. package/dest/orchestrator/epoch-proving-state.js +179 -73
  35. package/dest/orchestrator/index.d.ts +4 -1
  36. package/dest/orchestrator/index.d.ts.map +1 -1
  37. package/dest/orchestrator/index.js +3 -0
  38. package/dest/orchestrator/orchestrator.d.ts +59 -51
  39. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  40. package/dest/orchestrator/orchestrator.js +808 -385
  41. package/dest/orchestrator/orchestrator_metrics.d.ts +1 -1
  42. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
  43. package/dest/orchestrator/orchestrator_metrics.js +2 -6
  44. package/dest/orchestrator/proving-scheduler.d.ts +72 -0
  45. package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
  46. package/dest/orchestrator/proving-scheduler.js +117 -0
  47. package/dest/orchestrator/top-tree-orchestrator.d.ts +83 -0
  48. package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
  49. package/dest/orchestrator/top-tree-orchestrator.js +182 -0
  50. package/dest/orchestrator/top-tree-proving-scheduler.d.ts +62 -0
  51. package/dest/orchestrator/top-tree-proving-scheduler.d.ts.map +1 -0
  52. package/dest/orchestrator/top-tree-proving-scheduler.js +73 -0
  53. package/dest/orchestrator/top-tree-proving-state.d.ts +61 -0
  54. package/dest/orchestrator/top-tree-proving-state.d.ts.map +1 -0
  55. package/dest/orchestrator/top-tree-proving-state.js +185 -0
  56. package/dest/orchestrator/tx-proving-state.d.ts +15 -12
  57. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  58. package/dest/orchestrator/tx-proving-state.js +27 -44
  59. package/dest/prover-client/factory.d.ts +3 -3
  60. package/dest/prover-client/factory.d.ts.map +1 -1
  61. package/dest/prover-client/index.d.ts +1 -1
  62. package/dest/prover-client/prover-client.d.ts +68 -9
  63. package/dest/prover-client/prover-client.d.ts.map +1 -1
  64. package/dest/prover-client/prover-client.js +68 -14
  65. package/dest/prover-client/server-epoch-prover.d.ts +16 -12
  66. package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
  67. package/dest/prover-client/server-epoch-prover.js +11 -11
  68. package/dest/proving_broker/broker_prover_facade.d.ts +28 -19
  69. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  70. package/dest/proving_broker/broker_prover_facade.js +74 -61
  71. package/dest/proving_broker/config.d.ts +18 -61
  72. package/dest/proving_broker/config.d.ts.map +1 -1
  73. package/dest/proving_broker/config.js +43 -9
  74. package/dest/proving_broker/factory.d.ts +2 -2
  75. package/dest/proving_broker/factory.d.ts.map +1 -1
  76. package/dest/proving_broker/factory.js +5 -1
  77. package/dest/proving_broker/fixtures.d.ts +3 -2
  78. package/dest/proving_broker/fixtures.d.ts.map +1 -1
  79. package/dest/proving_broker/fixtures.js +3 -2
  80. package/dest/proving_broker/index.d.ts +2 -1
  81. package/dest/proving_broker/index.d.ts.map +1 -1
  82. package/dest/proving_broker/index.js +1 -0
  83. package/dest/proving_broker/proof_store/factory.d.ts +2 -5
  84. package/dest/proving_broker/proof_store/factory.d.ts.map +1 -1
  85. package/dest/proving_broker/proof_store/factory.js +7 -30
  86. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts +18 -0
  87. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts.map +1 -0
  88. package/dest/proving_broker/proof_store/file_store_proof_store.js +60 -0
  89. package/dest/proving_broker/proof_store/index.d.ts +2 -1
  90. package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
  91. package/dest/proving_broker/proof_store/index.js +1 -0
  92. package/dest/proving_broker/proof_store/inline_proof_store.d.ts +1 -1
  93. package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -1
  94. package/dest/proving_broker/proof_store/proof_store.d.ts +1 -1
  95. package/dest/proving_broker/proving_agent.d.ts +8 -12
  96. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  97. package/dest/proving_broker/proving_agent.js +86 -65
  98. package/dest/proving_broker/proving_broker.d.ts +18 -6
  99. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  100. package/dest/proving_broker/proving_broker.js +108 -44
  101. package/dest/proving_broker/proving_broker_database/memory.d.ts +3 -2
  102. package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
  103. package/dest/proving_broker/proving_broker_database/memory.js +1 -1
  104. package/dest/proving_broker/proving_broker_database/persisted.d.ts +5 -3
  105. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  106. package/dest/proving_broker/proving_broker_database/persisted.js +401 -11
  107. package/dest/proving_broker/proving_broker_database.d.ts +3 -2
  108. package/dest/proving_broker/proving_broker_database.d.ts.map +1 -1
  109. package/dest/proving_broker/proving_broker_instrumentation.d.ts +3 -1
  110. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  111. package/dest/proving_broker/proving_broker_instrumentation.js +22 -35
  112. package/dest/proving_broker/proving_job_controller.d.ts +11 -10
  113. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  114. package/dest/proving_broker/proving_job_controller.js +92 -62
  115. package/dest/proving_broker/rpc.d.ts +9 -7
  116. package/dest/proving_broker/rpc.d.ts.map +1 -1
  117. package/dest/proving_broker/rpc.js +88 -27
  118. package/dest/test/mock_proof_store.d.ts +9 -0
  119. package/dest/test/mock_proof_store.d.ts.map +1 -0
  120. package/dest/test/mock_proof_store.js +10 -0
  121. package/dest/test/mock_prover.d.ts +23 -17
  122. package/dest/test/mock_prover.d.ts.map +1 -1
  123. package/dest/test/mock_prover.js +38 -20
  124. package/package.json +34 -33
  125. package/src/config.ts +41 -9
  126. package/src/light/index.ts +1 -0
  127. package/src/light/lightweight_checkpoint_builder.ts +320 -0
  128. package/src/mocks/fixtures.ts +46 -40
  129. package/src/mocks/test_context.ts +231 -120
  130. package/src/orchestrator/block-building-helpers.ts +258 -334
  131. package/src/orchestrator/block-proving-state.ts +334 -231
  132. package/src/orchestrator/checkpoint-proving-state.ts +362 -0
  133. package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +271 -0
  134. package/src/orchestrator/epoch-proving-context.ts +101 -0
  135. package/src/orchestrator/epoch-proving-state.ts +239 -111
  136. package/src/orchestrator/index.ts +8 -0
  137. package/src/orchestrator/orchestrator.ts +591 -451
  138. package/src/orchestrator/orchestrator_metrics.ts +2 -6
  139. package/src/orchestrator/proving-scheduler.ts +156 -0
  140. package/src/orchestrator/top-tree-orchestrator.ts +314 -0
  141. package/src/orchestrator/top-tree-proving-scheduler.ts +154 -0
  142. package/src/orchestrator/top-tree-proving-state.ts +220 -0
  143. package/src/orchestrator/tx-proving-state.ts +48 -66
  144. package/src/prover-client/factory.ts +6 -2
  145. package/src/prover-client/prover-client.ts +173 -38
  146. package/src/prover-client/server-epoch-prover.ts +40 -22
  147. package/src/proving_broker/broker_prover_facade.ts +227 -149
  148. package/src/proving_broker/config.ts +49 -8
  149. package/src/proving_broker/factory.ts +2 -1
  150. package/src/proving_broker/fixtures.ts +8 -3
  151. package/src/proving_broker/index.ts +1 -0
  152. package/src/proving_broker/proof_store/factory.ts +10 -32
  153. package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
  154. package/src/proving_broker/proof_store/index.ts +1 -0
  155. package/src/proving_broker/proof_store/inline_proof_store.ts +1 -1
  156. package/src/proving_broker/proving_agent.ts +95 -66
  157. package/src/proving_broker/proving_broker.ts +121 -49
  158. package/src/proving_broker/proving_broker_database/memory.ts +3 -2
  159. package/src/proving_broker/proving_broker_database/persisted.ts +31 -15
  160. package/src/proving_broker/proving_broker_database.ts +2 -1
  161. package/src/proving_broker/proving_broker_instrumentation.ts +23 -35
  162. package/src/proving_broker/proving_job_controller.ts +100 -83
  163. package/src/proving_broker/rpc.ts +46 -25
  164. package/src/test/mock_proof_store.ts +14 -0
  165. package/src/test/mock_prover.ts +156 -64
  166. package/dest/bin/get-proof-inputs.d.ts +0 -2
  167. package/dest/bin/get-proof-inputs.d.ts.map +0 -1
  168. package/dest/bin/get-proof-inputs.js +0 -51
  169. package/dest/block_builder/index.d.ts +0 -6
  170. package/dest/block_builder/index.d.ts.map +0 -1
  171. package/dest/block_builder/index.js +0 -1
  172. package/dest/block_builder/light.d.ts +0 -33
  173. package/dest/block_builder/light.d.ts.map +0 -1
  174. package/dest/block_builder/light.js +0 -82
  175. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +0 -14
  176. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +0 -1
  177. package/dest/proving_broker/proof_store/gcs_proof_store.js +0 -51
  178. package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
  179. package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
  180. package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
  181. package/src/bin/get-proof-inputs.ts +0 -59
  182. package/src/block_builder/index.ts +0 -6
  183. package/src/block_builder/light.ts +0 -101
  184. package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -72
  185. package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
@@ -1,33 +1,401 @@
1
- function _ts_decorate(decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1
+ function applyDecs2203RFactory() {
2
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
3
+ return function addInitializer(initializer) {
4
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
5
+ assertCallable(initializer, "An initializer");
6
+ initializers.push(initializer);
7
+ };
8
+ }
9
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
10
+ var kindStr;
11
+ switch(kind){
12
+ case 1:
13
+ kindStr = "accessor";
14
+ break;
15
+ case 2:
16
+ kindStr = "method";
17
+ break;
18
+ case 3:
19
+ kindStr = "getter";
20
+ break;
21
+ case 4:
22
+ kindStr = "setter";
23
+ break;
24
+ default:
25
+ kindStr = "field";
26
+ }
27
+ var ctx = {
28
+ kind: kindStr,
29
+ name: isPrivate ? "#" + name : name,
30
+ static: isStatic,
31
+ private: isPrivate,
32
+ metadata: metadata
33
+ };
34
+ var decoratorFinishedRef = {
35
+ v: false
36
+ };
37
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
38
+ var get, set;
39
+ if (kind === 0) {
40
+ if (isPrivate) {
41
+ get = desc.get;
42
+ set = desc.set;
43
+ } else {
44
+ get = function() {
45
+ return this[name];
46
+ };
47
+ set = function(v) {
48
+ this[name] = v;
49
+ };
50
+ }
51
+ } else if (kind === 2) {
52
+ get = function() {
53
+ return desc.value;
54
+ };
55
+ } else {
56
+ if (kind === 1 || kind === 3) {
57
+ get = function() {
58
+ return desc.get.call(this);
59
+ };
60
+ }
61
+ if (kind === 1 || kind === 4) {
62
+ set = function(v) {
63
+ desc.set.call(this, v);
64
+ };
65
+ }
66
+ }
67
+ ctx.access = get && set ? {
68
+ get: get,
69
+ set: set
70
+ } : get ? {
71
+ get: get
72
+ } : {
73
+ set: set
74
+ };
75
+ try {
76
+ return dec(value, ctx);
77
+ } finally{
78
+ decoratorFinishedRef.v = true;
79
+ }
80
+ }
81
+ function assertNotFinished(decoratorFinishedRef, fnName) {
82
+ if (decoratorFinishedRef.v) {
83
+ throw new Error("attempted to call " + fnName + " after decoration was finished");
84
+ }
85
+ }
86
+ function assertCallable(fn, hint) {
87
+ if (typeof fn !== "function") {
88
+ throw new TypeError(hint + " must be a function");
89
+ }
90
+ }
91
+ function assertValidReturnValue(kind, value) {
92
+ var type = typeof value;
93
+ if (kind === 1) {
94
+ if (type !== "object" || value === null) {
95
+ throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
96
+ }
97
+ if (value.get !== undefined) {
98
+ assertCallable(value.get, "accessor.get");
99
+ }
100
+ if (value.set !== undefined) {
101
+ assertCallable(value.set, "accessor.set");
102
+ }
103
+ if (value.init !== undefined) {
104
+ assertCallable(value.init, "accessor.init");
105
+ }
106
+ } else if (type !== "function") {
107
+ var hint;
108
+ if (kind === 0) {
109
+ hint = "field";
110
+ } else if (kind === 10) {
111
+ hint = "class";
112
+ } else {
113
+ hint = "method";
114
+ }
115
+ throw new TypeError(hint + " decorators must return a function or void 0");
116
+ }
117
+ }
118
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
119
+ var decs = decInfo[0];
120
+ var desc, init, value;
121
+ if (isPrivate) {
122
+ if (kind === 0 || kind === 1) {
123
+ desc = {
124
+ get: decInfo[3],
125
+ set: decInfo[4]
126
+ };
127
+ } else if (kind === 3) {
128
+ desc = {
129
+ get: decInfo[3]
130
+ };
131
+ } else if (kind === 4) {
132
+ desc = {
133
+ set: decInfo[3]
134
+ };
135
+ } else {
136
+ desc = {
137
+ value: decInfo[3]
138
+ };
139
+ }
140
+ } else if (kind !== 0) {
141
+ desc = Object.getOwnPropertyDescriptor(base, name);
142
+ }
143
+ if (kind === 1) {
144
+ value = {
145
+ get: desc.get,
146
+ set: desc.set
147
+ };
148
+ } else if (kind === 2) {
149
+ value = desc.value;
150
+ } else if (kind === 3) {
151
+ value = desc.get;
152
+ } else if (kind === 4) {
153
+ value = desc.set;
154
+ }
155
+ var newValue, get, set;
156
+ if (typeof decs === "function") {
157
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
158
+ if (newValue !== void 0) {
159
+ assertValidReturnValue(kind, newValue);
160
+ if (kind === 0) {
161
+ init = newValue;
162
+ } else if (kind === 1) {
163
+ init = newValue.init;
164
+ get = newValue.get || value.get;
165
+ set = newValue.set || value.set;
166
+ value = {
167
+ get: get,
168
+ set: set
169
+ };
170
+ } else {
171
+ value = newValue;
172
+ }
173
+ }
174
+ } else {
175
+ for(var i = decs.length - 1; i >= 0; i--){
176
+ var dec = decs[i];
177
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
178
+ if (newValue !== void 0) {
179
+ assertValidReturnValue(kind, newValue);
180
+ var newInit;
181
+ if (kind === 0) {
182
+ newInit = newValue;
183
+ } else if (kind === 1) {
184
+ newInit = newValue.init;
185
+ get = newValue.get || value.get;
186
+ set = newValue.set || value.set;
187
+ value = {
188
+ get: get,
189
+ set: set
190
+ };
191
+ } else {
192
+ value = newValue;
193
+ }
194
+ if (newInit !== void 0) {
195
+ if (init === void 0) {
196
+ init = newInit;
197
+ } else if (typeof init === "function") {
198
+ init = [
199
+ init,
200
+ newInit
201
+ ];
202
+ } else {
203
+ init.push(newInit);
204
+ }
205
+ }
206
+ }
207
+ }
208
+ }
209
+ if (kind === 0 || kind === 1) {
210
+ if (init === void 0) {
211
+ init = function(instance, init) {
212
+ return init;
213
+ };
214
+ } else if (typeof init !== "function") {
215
+ var ownInitializers = init;
216
+ init = function(instance, init) {
217
+ var value = init;
218
+ for(var i = 0; i < ownInitializers.length; i++){
219
+ value = ownInitializers[i].call(instance, value);
220
+ }
221
+ return value;
222
+ };
223
+ } else {
224
+ var originalInitializer = init;
225
+ init = function(instance, init) {
226
+ return originalInitializer.call(instance, init);
227
+ };
228
+ }
229
+ ret.push(init);
230
+ }
231
+ if (kind !== 0) {
232
+ if (kind === 1) {
233
+ desc.get = value.get;
234
+ desc.set = value.set;
235
+ } else if (kind === 2) {
236
+ desc.value = value;
237
+ } else if (kind === 3) {
238
+ desc.get = value;
239
+ } else if (kind === 4) {
240
+ desc.set = value;
241
+ }
242
+ if (isPrivate) {
243
+ if (kind === 1) {
244
+ ret.push(function(instance, args) {
245
+ return value.get.call(instance, args);
246
+ });
247
+ ret.push(function(instance, args) {
248
+ return value.set.call(instance, args);
249
+ });
250
+ } else if (kind === 2) {
251
+ ret.push(value);
252
+ } else {
253
+ ret.push(function(instance, args) {
254
+ return value.call(instance, args);
255
+ });
256
+ }
257
+ } else {
258
+ Object.defineProperty(base, name, desc);
259
+ }
260
+ }
261
+ }
262
+ function applyMemberDecs(Class, decInfos, metadata) {
263
+ var ret = [];
264
+ var protoInitializers;
265
+ var staticInitializers;
266
+ var existingProtoNonFields = new Map();
267
+ var existingStaticNonFields = new Map();
268
+ for(var i = 0; i < decInfos.length; i++){
269
+ var decInfo = decInfos[i];
270
+ if (!Array.isArray(decInfo)) continue;
271
+ var kind = decInfo[1];
272
+ var name = decInfo[2];
273
+ var isPrivate = decInfo.length > 3;
274
+ var isStatic = kind >= 5;
275
+ var base;
276
+ var initializers;
277
+ if (isStatic) {
278
+ base = Class;
279
+ kind = kind - 5;
280
+ staticInitializers = staticInitializers || [];
281
+ initializers = staticInitializers;
282
+ } else {
283
+ base = Class.prototype;
284
+ protoInitializers = protoInitializers || [];
285
+ initializers = protoInitializers;
286
+ }
287
+ if (kind !== 0 && !isPrivate) {
288
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
289
+ var existingKind = existingNonFields.get(name) || 0;
290
+ if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
291
+ throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
292
+ } else if (!existingKind && kind > 2) {
293
+ existingNonFields.set(name, kind);
294
+ } else {
295
+ existingNonFields.set(name, true);
296
+ }
297
+ }
298
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
299
+ }
300
+ pushInitializers(ret, protoInitializers);
301
+ pushInitializers(ret, staticInitializers);
302
+ return ret;
303
+ }
304
+ function pushInitializers(ret, initializers) {
305
+ if (initializers) {
306
+ ret.push(function(instance) {
307
+ for(var i = 0; i < initializers.length; i++){
308
+ initializers[i].call(instance);
309
+ }
310
+ return instance;
311
+ });
312
+ }
313
+ }
314
+ function applyClassDecs(targetClass, classDecs, metadata) {
315
+ if (classDecs.length > 0) {
316
+ var initializers = [];
317
+ var newClass = targetClass;
318
+ var name = targetClass.name;
319
+ for(var i = classDecs.length - 1; i >= 0; i--){
320
+ var decoratorFinishedRef = {
321
+ v: false
322
+ };
323
+ try {
324
+ var nextNewClass = classDecs[i](newClass, {
325
+ kind: "class",
326
+ name: name,
327
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
328
+ metadata
329
+ });
330
+ } finally{
331
+ decoratorFinishedRef.v = true;
332
+ }
333
+ if (nextNewClass !== undefined) {
334
+ assertValidReturnValue(10, nextNewClass);
335
+ newClass = nextNewClass;
336
+ }
337
+ }
338
+ return [
339
+ defineMetadata(newClass, metadata),
340
+ function() {
341
+ for(var i = 0; i < initializers.length; i++){
342
+ initializers[i].call(newClass);
343
+ }
344
+ }
345
+ ];
346
+ }
347
+ }
348
+ function defineMetadata(Class, metadata) {
349
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
350
+ configurable: true,
351
+ enumerable: true,
352
+ value: metadata
353
+ });
354
+ }
355
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
356
+ if (parentClass !== void 0) {
357
+ var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
358
+ }
359
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
360
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
361
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
362
+ return {
363
+ e: e,
364
+ get c () {
365
+ return applyClassDecs(targetClass, classDecs, metadata);
366
+ }
367
+ };
368
+ };
369
+ }
370
+ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
371
+ return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
6
372
  }
7
- import { AVM_PROOF_LENGTH_IN_FIELDS, AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS, L1_TO_L2_MSG_SUBTREE_HEIGHT, L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, NUM_BASE_PARITY_PER_ROOT_PARITY } from '@aztec/constants';
8
- import { padArrayEnd, times } from '@aztec/foundation/collection';
9
- import { AbortError } from '@aztec/foundation/error';
10
- import { Fr } from '@aztec/foundation/fields';
11
- import { createLogger } from '@aztec/foundation/log';
373
+ var _dec, _dec1, _dec2, _dec3, _dec4, _initProto;
374
+ import { L1_TO_L2_MSG_SUBTREE_HEIGHT, L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH, NUM_BASE_PARITY_PER_ROOT_PARITY } from '@aztec/constants';
375
+ import { BlockNumber } from '@aztec/foundation/branded-types';
12
376
  import { promiseWithResolvers } from '@aztec/foundation/promise';
13
377
  import { assertLength } from '@aztec/foundation/serialize';
14
378
  import { pushTestData } from '@aztec/foundation/testing';
15
379
  import { elapsed } from '@aztec/foundation/timer';
16
- import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
17
- import { L2Block } from '@aztec/stdlib/block';
18
- import { BaseParityInputs } from '@aztec/stdlib/parity';
19
- import { makeEmptyRecursiveProof } from '@aztec/stdlib/proofs';
20
- import { EmptyBlockRootRollupInputs, PrivateBaseRollupInputs, SingleTxBlockRootRollupInputs, TubeInputs } from '@aztec/stdlib/rollup';
380
+ import { appendL1ToL2MessagesToTree } from '@aztec/stdlib/messaging';
381
+ import { BlockRootEmptyTxFirstRollupPrivateInputs, BlockRootFirstRollupPrivateInputs, BlockRootSingleTxFirstRollupPrivateInputs, BlockRootSingleTxRollupPrivateInputs, CheckpointRootSingleBlockRollupPrivateInputs, PrivateTxBaseRollupPrivateInputs } from '@aztec/stdlib/rollup';
21
382
  import { MerkleTreeId } from '@aztec/stdlib/trees';
22
- import { toNumBlobFields } from '@aztec/stdlib/tx';
23
- import { VerificationKeyData } from '@aztec/stdlib/vks';
24
383
  import { Attributes, getTelemetryClient, trackSpan, wrapCallbackInSpan } from '@aztec/telemetry-client';
25
384
  import { inspect } from 'util';
26
- import { buildBaseRollupHints, buildHeaderAndBodyFromTxs, getRootTreeSiblingPath, getSubtreeSiblingPath, getTreeSnapshot, validatePartialState, validateTx } from './block-building-helpers.js';
385
+ import { buildHeaderFromCircuitOutputs, getLastSiblingPath, getPublicChonkVerifierPrivateInputsFromTx, getRootTreeSiblingPath, getSubtreeSiblingPath, getTreeSnapshot, insertSideEffectsAndBuildBaseRollupHints, validatePartialState, validateTx } from './block-building-helpers.js';
27
386
  import { EpochProvingState } from './epoch-proving-state.js';
28
387
  import { ProvingOrchestratorMetrics } from './orchestrator_metrics.js';
388
+ import { TopTreeProvingScheduler } from './top-tree-proving-scheduler.js';
29
389
  import { TxProvingState } from './tx-proving-state.js';
30
- const logger = createLogger('prover-client:orchestrator');
390
+ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
391
+ [Attributes.BLOCK_NUMBER]: blockNumber
392
+ })), _dec1 = trackSpan('ProvingOrchestrator.addTxs', (txs)=>({
393
+ [Attributes.BLOCK_TXS_COUNT]: txs.length
394
+ })), _dec2 = trackSpan('ProvingOrchestrator.startChonkVerifierCircuits'), _dec3 = trackSpan('ProvingOrchestrator.setBlockCompleted', (blockNumber)=>({
395
+ [Attributes.BLOCK_NUMBER]: blockNumber
396
+ })), _dec4 = trackSpan('ProvingOrchestrator.prepareBaseRollupInputs', (tx)=>({
397
+ [Attributes.TX_HASH]: tx.hash.toString()
398
+ }));
31
399
  /**
32
400
  * Implements an event driven proving scheduler to build the recursive proof tree. The idea being:
33
401
  * 1. Transactions are provided to the scheduler post simulation.
@@ -39,23 +407,45 @@ const logger = createLogger('prover-client:orchestrator');
39
407
  * The proving implementation is determined by the provided prover. This could be for example a local prover or a remote prover pool.
40
408
  */ /**
41
409
  * The orchestrator, managing the flow of recursive proving operations required to build the rollup proof tree.
42
- */ export class ProvingOrchestrator {
410
+ */ export class ProvingOrchestrator extends TopTreeProvingScheduler {
43
411
  dbProvider;
44
- prover;
45
412
  proverId;
413
+ cancelJobsOnStop;
414
+ static{
415
+ ({ e: [_initProto] } = _apply_decs_2203_r(this, [
416
+ [
417
+ _dec,
418
+ 2,
419
+ "startNewBlock"
420
+ ],
421
+ [
422
+ _dec1,
423
+ 2,
424
+ "addTxs"
425
+ ],
426
+ [
427
+ _dec2,
428
+ 2,
429
+ "startChonkVerifierCircuits"
430
+ ],
431
+ [
432
+ _dec3,
433
+ 2,
434
+ "setBlockCompleted"
435
+ ],
436
+ [
437
+ _dec4,
438
+ 2,
439
+ "prepareBaseRollupInputs"
440
+ ]
441
+ ], []));
442
+ }
46
443
  provingState;
47
- pendingProvingJobs;
48
444
  provingPromise;
49
445
  metrics;
50
446
  dbs;
51
- constructor(dbProvider, prover, proverId = Fr.ZERO, telemetryClient = getTelemetryClient()){
52
- this.dbProvider = dbProvider;
53
- this.prover = prover;
54
- this.proverId = proverId;
55
- this.provingState = undefined;
56
- this.pendingProvingJobs = [];
57
- this.provingPromise = undefined;
58
- this.dbs = new Map();
447
+ constructor(dbProvider, prover, proverId, cancelJobsOnStop = false, enqueueConcurrency, telemetryClient = getTelemetryClient(), bindings){
448
+ super(prover, enqueueConcurrency, 'prover-client:orchestrator', bindings), this.dbProvider = dbProvider, this.proverId = proverId, this.cancelJobsOnStop = cancelJobsOnStop, this.provingState = (_initProto(this), undefined), this.provingPromise = undefined, this.dbs = new Map();
59
449
  this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'ProvingOrchestrator');
60
450
  }
61
451
  get tracer() {
@@ -64,85 +454,161 @@ const logger = createLogger('prover-client:orchestrator');
64
454
  getProverId() {
65
455
  return this.proverId;
66
456
  }
67
- stop() {
457
+ getNumActiveForks() {
458
+ return this.dbs.size;
459
+ }
460
+ cancelInternal() {
68
461
  this.cancel();
69
- return Promise.resolve();
70
462
  }
71
- startNewEpoch(epochNumber, firstBlockNumber, totalNumBlocks) {
463
+ wrapCircuitCall(circuitName, fn) {
464
+ return wrapCallbackInSpan(this.tracer, `ProvingOrchestrator.prover.${circuitName}`, {
465
+ [Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName
466
+ }, fn);
467
+ }
468
+ onRootRollupComplete(state) {
469
+ state.resolve({
470
+ status: 'success'
471
+ });
472
+ }
473
+ startNewEpoch(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges) {
474
+ if (this.provingState?.verifyState()) {
475
+ throw new Error(`Cannot start epoch ${epochNumber} when epoch ${this.provingState.epochNumber} is still being processed.`);
476
+ }
72
477
  const { promise: _promise, resolve, reject } = promiseWithResolvers();
73
478
  const promise = _promise.catch((reason)=>({
74
479
  status: 'failure',
75
480
  reason
76
481
  }));
77
- if (totalNumBlocks <= 0 || !Number.isInteger(totalNumBlocks)) {
78
- throw new Error(`Invalid number of blocks for epoch (got ${totalNumBlocks})`);
79
- }
80
- logger.info(`Starting epoch ${epochNumber} with ${totalNumBlocks} blocks`);
81
- this.provingState = new EpochProvingState(epochNumber, firstBlockNumber, totalNumBlocks, resolve, reject);
482
+ this.logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
483
+ this.provingState = new EpochProvingState(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges, (provingState)=>this.checkAndEnqueueCheckpointRootRollup(provingState), resolve, reject);
82
484
  this.provingPromise = promise;
83
485
  }
84
486
  /**
487
+ * Starts a new checkpoint.
488
+ * @param checkpointIndex - The index of the checkpoint in the epoch.
489
+ * @param constants - The constants for this checkpoint.
490
+ * @param l1ToL2Messages - The set of L1 to L2 messages to be inserted at the beginning of this checkpoint.
491
+ * @param totalNumBlocks - The total number of blocks expected in the checkpoint (must be at least one).
492
+ * @param headerOfLastBlockInPreviousCheckpoint - The header of the last block in the previous checkpoint.
493
+ */ async startNewCheckpoint(checkpointIndex, constants, l1ToL2Messages, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint) {
494
+ if (!this.provingState) {
495
+ throw new Error('Empty epoch proving state. Call startNewEpoch before starting a checkpoint.');
496
+ }
497
+ if (!this.provingState.isAcceptingCheckpoints()) {
498
+ throw new Error(`Epoch not accepting further checkpoints.`);
499
+ }
500
+ // Fork world state at the end of the immediately previous block.
501
+ const lastBlockNumber = headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber;
502
+ const db = await this.dbProvider.fork(lastBlockNumber);
503
+ const firstBlockNumber = BlockNumber(lastBlockNumber + 1);
504
+ this.dbs.set(firstBlockNumber, db);
505
+ // Get archive sibling path before any block in this checkpoint lands.
506
+ const lastArchiveSiblingPath = await getLastSiblingPath(MerkleTreeId.ARCHIVE, db);
507
+ // Insert all the l1 to l2 messages into the db. And get the states before and after the insertion.
508
+ const { lastL1ToL2MessageTreeSnapshot, lastL1ToL2MessageSubtreeRootSiblingPath, newL1ToL2MessageTreeSnapshot, newL1ToL2MessageSubtreeRootSiblingPath } = await this.updateL1ToL2MessageTree(l1ToL2Messages, db);
509
+ this.provingState.startNewCheckpoint(checkpointIndex, constants, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint, lastArchiveSiblingPath, l1ToL2Messages, lastL1ToL2MessageTreeSnapshot, lastL1ToL2MessageSubtreeRootSiblingPath, newL1ToL2MessageTreeSnapshot, newL1ToL2MessageSubtreeRootSiblingPath);
510
+ }
511
+ /**
85
512
  * Starts off a new block
86
- * @param globalVariables - The global variables for the block
87
- * @param l1ToL2Messages - The l1 to l2 messages for the block
88
- * @returns A proving ticket, containing a promise notifying of proving completion
89
- */ async startNewBlock(globalVariables, l1ToL2Messages, previousBlockHeader) {
513
+ * @param blockNumber - The block number
514
+ * @param timestamp - The timestamp of the block. This is only required for constructing the private inputs for the
515
+ * block that doesn't have any txs.
516
+ * @param totalNumTxs - The total number of txs in the block
517
+ */ async startNewBlock(blockNumber, timestamp, totalNumTxs) {
90
518
  if (!this.provingState) {
91
- throw new Error(`Invalid proving state, call startNewEpoch before starting a block`);
92
- }
93
- if (!this.provingState?.isAcceptingBlocks()) {
94
- throw new Error(`Epoch not accepting further blocks`);
95
- }
96
- logger.info(`Starting block ${globalVariables.blockNumber.toNumber()} for slot ${globalVariables.slotNumber.toNumber()}`);
97
- // Fork world state at the end of the immediately previous block
98
- const db = await this.dbProvider.fork(globalVariables.blockNumber.toNumber() - 1);
99
- this.dbs.set(globalVariables.blockNumber.toNumber(), db);
100
- // we start the block by enqueueing all of the base parity circuits
101
- const { l1ToL2MessageSubtreeSiblingPath, l1ToL2MessageTreeSnapshotAfterInsertion, baseParityInputs } = await this.prepareBaseParityInputs(l1ToL2Messages, db);
102
- // Get archive snapshot before this block lands
103
- const lastArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
104
- const newArchiveSiblingPath = await getRootTreeSiblingPath(MerkleTreeId.ARCHIVE, db);
105
- const blockProvingState = this.provingState.startNewBlock(globalVariables, l1ToL2Messages, l1ToL2MessageSubtreeSiblingPath, l1ToL2MessageTreeSnapshotAfterInsertion, lastArchive, newArchiveSiblingPath, previousBlockHeader);
106
- // Enqueue base parity circuits for the block
107
- for(let i = 0; i < baseParityInputs.length; i++){
108
- this.enqueueBaseParityCircuit(blockProvingState, baseParityInputs[i], i);
519
+ throw new Error('Empty epoch proving state. Call startNewEpoch before starting a block.');
520
+ }
521
+ const checkpointProvingState = this.provingState.getCheckpointProvingStateByBlockNumber(blockNumber);
522
+ if (!checkpointProvingState) {
523
+ throw new Error(`Checkpoint not started. Call startNewCheckpoint first.`);
524
+ }
525
+ if (!checkpointProvingState.isAcceptingBlocks()) {
526
+ throw new Error(`Checkpoint not accepting further blocks.`);
527
+ }
528
+ const constants = checkpointProvingState.constants;
529
+ this.logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
530
+ // Fork the db only when it's not already set. The db for the first block is set in `startNewCheckpoint`.
531
+ if (!this.dbs.has(blockNumber)) {
532
+ // Fork world state at the end of the immediately previous block
533
+ const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
534
+ this.dbs.set(blockNumber, db);
535
+ }
536
+ const db = this.getDbForBlock(blockNumber);
537
+ // Get archive snapshot and sibling path before any txs in this block lands.
538
+ const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
539
+ const lastArchiveSiblingPath = await getRootTreeSiblingPath(MerkleTreeId.ARCHIVE, db);
540
+ const blockProvingState = checkpointProvingState.startNewBlock(blockNumber, timestamp, totalNumTxs, lastArchiveTreeSnapshot, lastArchiveSiblingPath);
541
+ // Enqueue base parity circuits for the first block in the checkpoint.
542
+ if (blockProvingState.index === 0) {
543
+ for(let i = 0; i < NUM_BASE_PARITY_PER_ROOT_PARITY; i++){
544
+ this.enqueueBaseParityCircuit(checkpointProvingState, blockProvingState, i);
545
+ }
546
+ }
547
+ // Because `addTxs` won't be called for a block without txs, and that's where the sponge blob state is computed.
548
+ // We need to set its end sponge blob here, which will become the start sponge blob for the next block.
549
+ if (totalNumTxs === 0) {
550
+ const endState = await db.getStateReference();
551
+ blockProvingState.setEndState(endState);
552
+ const endSpongeBlob = blockProvingState.getStartSpongeBlob().clone();
553
+ const blockEndBlobFields = blockProvingState.getBlockEndBlobFields();
554
+ await endSpongeBlob.absorb(blockEndBlobFields);
555
+ blockProvingState.setEndSpongeBlob(endSpongeBlob);
556
+ // Try to accumulate the out hashes and blobs as far as we can:
557
+ await this.provingState.accumulateCheckpointOutHashes();
558
+ await this.provingState.setBlobAccumulators();
109
559
  }
110
560
  }
111
561
  /**
112
562
  * The interface to add simulated transactions to the scheduler. This can only be called once per block.
113
563
  * @param txs - The transactions to be proven
114
564
  */ async addTxs(txs) {
565
+ if (!this.provingState) {
566
+ throw new Error(`Empty epoch proving state. Call startNewEpoch before adding txs.`);
567
+ }
115
568
  if (!txs.length) {
116
569
  // To avoid an ugly throw below. If we require an empty block, we can just call setBlockCompleted
117
570
  // on a block with no txs. We cannot do that here because we cannot find the blockNumber without any txs.
118
- logger.warn(`Provided no txs to orchestrator addTxs.`);
571
+ this.logger.warn(`Provided no txs to orchestrator addTxs.`);
119
572
  return;
120
573
  }
121
- const blockNumber = txs[0].constants.globalVariables.blockNumber.toNumber();
122
- const provingState = this.provingState?.getBlockProvingStateByBlockNumber(blockNumber);
574
+ const blockNumber = BlockNumber(txs[0].globalVariables.blockNumber);
575
+ const provingState = this.provingState.getBlockProvingStateByBlockNumber(blockNumber);
123
576
  if (!provingState) {
124
- throw new Error(`Block proving state for ${blockNumber} not found`);
577
+ throw new Error(`Proving state for block ${blockNumber} not found. Call startNewBlock first.`);
125
578
  }
126
- if (provingState.totalNumTxs) {
579
+ if (provingState.totalNumTxs !== txs.length) {
580
+ throw new Error(`Block ${blockNumber} should be filled with ${provingState.totalNumTxs} txs. Received ${txs.length} txs.`);
581
+ }
582
+ if (!provingState.isAcceptingTxs()) {
127
583
  throw new Error(`Block ${blockNumber} has been initialized with transactions.`);
128
584
  }
129
- const numBlobFields = toNumBlobFields(txs);
130
- provingState.startNewBlock(txs.length, numBlobFields);
131
- logger.info(`Adding ${txs.length} transactions with ${numBlobFields} blob fields to block ${provingState.blockNumber}`);
585
+ this.logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
586
+ const db = this.getDbForBlock(blockNumber);
587
+ const lastArchive = provingState.lastArchiveTreeSnapshot;
588
+ const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
589
+ const spongeBlobState = provingState.getStartSpongeBlob().clone();
132
590
  for (const tx of txs){
133
591
  try {
134
592
  if (!provingState.verifyState()) {
135
593
  throw new Error(`Invalid proving state when adding a tx`);
136
594
  }
137
595
  validateTx(tx);
138
- logger.info(`Received transaction: ${tx.hash}`);
139
- const [hints, treeSnapshots] = await this.prepareTransaction(tx, provingState);
140
- const txProvingState = new TxProvingState(tx, hints, treeSnapshots);
596
+ this.logger.debug(`Received transaction: ${tx.hash}`);
597
+ const startSpongeBlob = spongeBlobState.clone();
598
+ const [hints, treeSnapshots] = await this.prepareBaseRollupInputs(tx, lastArchive, newL1ToL2MessageTreeSnapshot, startSpongeBlob, db);
599
+ if (!provingState.verifyState()) {
600
+ throw new Error(`Unable to add transaction, preparing base inputs failed`);
601
+ }
602
+ await spongeBlobState.absorb(tx.txEffect.toBlobFields());
603
+ const txProvingState = new TxProvingState(tx, hints, treeSnapshots, this.proverId.toField());
141
604
  const txIndex = provingState.addNewTx(txProvingState);
142
- this.getOrEnqueueTube(provingState, txIndex);
143
605
  if (txProvingState.requireAvmProof) {
144
- logger.debug(`Enqueueing public VM for tx ${txIndex}`);
606
+ this.getOrEnqueueChonkVerifier(provingState, txIndex);
607
+ this.logger.debug(`Enqueueing public VM for tx ${txIndex}`);
145
608
  this.enqueueVM(provingState, txIndex);
609
+ } else {
610
+ this.logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
611
+ this.enqueueBaseRollup(provingState, txIndex);
146
612
  }
147
613
  } catch (err) {
148
614
  throw new Error(`Error adding transaction ${tx.hash.toString()} to block ${blockNumber}: ${err.message}`, {
@@ -150,22 +616,34 @@ const logger = createLogger('prover-client:orchestrator');
150
616
  });
151
617
  }
152
618
  }
619
+ const endState = await db.getStateReference();
620
+ provingState.setEndState(endState);
621
+ const blockEndBlobFields = provingState.getBlockEndBlobFields();
622
+ await spongeBlobState.absorb(blockEndBlobFields);
623
+ provingState.setEndSpongeBlob(spongeBlobState);
624
+ // Txs have been added to the block. Now try to accumulate the out hashes and blobs as far as we can:
625
+ await this.provingState.accumulateCheckpointOutHashes();
626
+ await this.provingState.setBlobAccumulators();
153
627
  }
154
628
  /**
155
- * Kickstarts tube circuits for the specified txs. These will be used during epoch proving.
156
- * Note that if the tube circuits are not started this way, they will be started nontheless after processing.
157
- */ async startTubeCircuits(txs) {
629
+ * Kickstarts chonk verifier circuits for the specified txs. These will be used during epoch proving.
630
+ * Note that if the chonk verifier circuits are not started this way, they will be started nontheless after processing.
631
+ */ startChonkVerifierCircuits(txs) {
158
632
  if (!this.provingState?.verifyState()) {
159
- throw new Error(`Invalid proving state, call startNewEpoch before starting tube circuits`);
633
+ throw new Error(`Empty epoch proving state. call startNewEpoch before starting chonk verifier circuits.`);
160
634
  }
161
- for (const tx of txs){
162
- const txHash = (await tx.getTxHash()).toString();
163
- const tubeInputs = new TubeInputs(tx.clientIvcProof);
635
+ const publicTxs = txs.filter((tx)=>tx.data.forPublic);
636
+ for (const tx of publicTxs){
637
+ const txHash = tx.getTxHash().toString();
638
+ const privateInputs = getPublicChonkVerifierPrivateInputsFromTx(tx, this.proverId.toField());
164
639
  const tubeProof = promiseWithResolvers();
165
- logger.debug(`Starting tube circuit for tx ${txHash}`);
166
- this.doEnqueueTube(txHash, tubeInputs, (proof)=>tubeProof.resolve(proof));
167
- this.provingState?.cachedTubeProofs.set(txHash, tubeProof.promise);
640
+ this.logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
641
+ this.doEnqueueChonkVerifier(txHash, privateInputs, (proof)=>{
642
+ tubeProof.resolve(proof);
643
+ });
644
+ this.provingState.cachedChonkVerifierProofs.set(txHash, tubeProof.promise);
168
645
  }
646
+ return Promise.resolve();
169
647
  }
170
648
  /**
171
649
  * Marks the block as completed.
@@ -175,74 +653,106 @@ const logger = createLogger('prover-client:orchestrator');
175
653
  if (!provingState) {
176
654
  throw new Error(`Block proving state for ${blockNumber} not found`);
177
655
  }
178
- if (!provingState.spongeBlobState) {
179
- // If we are completing an empty block, initialise the provingState.
180
- // We will have 0 txs and no blob fields.
181
- provingState.startNewBlock(0, 0);
656
+ // Abort with specific error for the block if there's one.
657
+ const error = provingState.getError();
658
+ if (error) {
659
+ throw new Error(`Block proving failed: ${error}`);
182
660
  }
661
+ // Abort if the proving state is not valid due to errors occurred elsewhere.
183
662
  if (!provingState.verifyState()) {
184
- throw new Error(`Block proving failed: ${provingState.error}`);
185
- }
186
- // And build the block header
187
- logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
188
- await this.buildBlock(provingState, expectedHeader);
189
- // If the proofs were faster than the block building, then we need to try the block root rollup again here
190
- await this.checkAndEnqueueBlockRootRollup(provingState);
191
- return provingState.block;
192
- }
193
- /** Returns the block as built for a given index. */ getBlock(index) {
194
- const block = this.provingState?.blocks[index]?.block;
195
- if (!block) {
196
- throw new Error(`Block at index ${index} not available`);
197
- }
198
- return block;
199
- }
200
- async buildBlock(provingState, expectedHeader) {
201
- // Collect all new nullifiers, commitments, and contracts from all txs in this block to build body
202
- const txs = provingState.allTxs.map((a)=>a.processedTx);
203
- // Get db for this block
204
- const db = this.dbs.get(provingState.blockNumber);
205
- // Given we've applied every change from this block, now assemble the block header
206
- // and update the archive tree, so we're ready to start processing the next block
207
- const { header, body } = await buildHeaderAndBodyFromTxs(txs, provingState.globalVariables, provingState.newL1ToL2Messages, db);
663
+ throw new Error(`Invalid proving state when completing block ${blockNumber}.`);
664
+ }
665
+ if (provingState.isAcceptingTxs()) {
666
+ throw new Error(`Block ${blockNumber} is still accepting txs. Call setBlockCompleted after all txs have been added.`);
667
+ }
668
+ // Given we've applied every change from this block, now assemble the block header:
669
+ this.logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
670
+ const header = await provingState.buildBlockHeader();
208
671
  if (expectedHeader && !header.equals(expectedHeader)) {
209
- logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
672
+ this.logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
210
673
  throw new Error('Block header mismatch');
211
674
  }
212
- logger.verbose(`Updating archive tree with block ${provingState.blockNumber} header ${(await header.hash()).toString()}`);
213
- await db.updateArchive(header);
214
- // Assemble the L2 block
215
- const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
216
- const l2Block = new L2Block(newArchive, header, body);
217
- await this.verifyBuiltBlockAgainstSyncedState(l2Block, newArchive);
218
- logger.verbose(`Orchestrator finalised block ${l2Block.number}`);
219
- provingState.block = l2Block;
675
+ // Get db for this block and remove from map — no other code should use it after this point.
676
+ const db = this.getDbForBlock(provingState.blockNumber);
677
+ this.dbs.delete(provingState.blockNumber);
678
+ // Update the archive tree, capture the snapshot, and close the fork deterministically.
679
+ try {
680
+ this.logger.verbose(`Updating archive tree with block ${provingState.blockNumber} header ${(await header.hash()).toString()}`);
681
+ await db.updateArchive(header);
682
+ provingState.setBuiltArchive(await getTreeSnapshot(MerkleTreeId.ARCHIVE, db));
683
+ } finally{
684
+ await db.close();
685
+ }
686
+ await this.verifyBuiltBlockAgainstSyncedState(provingState);
687
+ return header;
220
688
  }
221
689
  // Flagged as protected to disable in certain unit tests
222
- async verifyBuiltBlockAgainstSyncedState(l2Block, newArchive) {
223
- const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(l2Block.number));
690
+ async verifyBuiltBlockAgainstSyncedState(provingState) {
691
+ const builtBlockHeader = provingState.getBuiltBlockHeader();
692
+ if (!builtBlockHeader) {
693
+ this.logger.debug('Block header not built yet, skipping header check.');
694
+ return;
695
+ }
696
+ const output = provingState.getBlockRootRollupOutput();
697
+ if (!output) {
698
+ this.logger.debug('Block root rollup proof not built yet, skipping header check.');
699
+ return;
700
+ }
701
+ const newArchive = provingState.getBuiltArchive();
702
+ if (!newArchive) {
703
+ this.logger.debug('Archive snapshot not yet captured, skipping header check.');
704
+ return;
705
+ }
706
+ const header = await buildHeaderFromCircuitOutputs(output);
707
+ if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
708
+ this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
709
+ provingState.reject(`Block header hash mismatch.`);
710
+ return;
711
+ }
712
+ const blockNumber = provingState.blockNumber;
713
+ const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
224
714
  if (!syncedArchive.equals(newArchive)) {
225
- throw new Error(`Archive tree mismatch for block ${l2Block.number}: world state synced to ${inspect(syncedArchive)} but built ${inspect(newArchive)}`);
715
+ this.logger.error(`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(syncedArchive)} but built ${inspect(newArchive)}`);
716
+ provingState.reject(`Archive tree mismatch.`);
717
+ return;
718
+ }
719
+ const circuitArchive = output.newArchive;
720
+ if (!newArchive.equals(circuitArchive)) {
721
+ this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
722
+ provingState.reject(`New archive mismatch.`);
723
+ return;
226
724
  }
227
725
  }
228
726
  /**
229
- * Cancel any further proving
727
+ * Cancel any further proving.
728
+ * If cancelJobsOnStop is true, aborts all pending jobs with the broker (which marks them as 'Aborted').
729
+ * If cancelJobsOnStop is false (default), jobs remain in the broker queue and can be reused on restart/reorg.
230
730
  */ cancel() {
231
- for (const controller of this.pendingProvingJobs){
232
- controller.abort();
233
- }
731
+ this.resetSchedulerState(this.cancelJobsOnStop);
234
732
  this.provingState?.cancel();
733
+ for (const [blockNumber, db] of this.dbs.entries()){
734
+ void db.close().catch((err)=>this.logger.error(`Error closing db for block ${blockNumber}`, err));
735
+ }
736
+ this.dbs.clear();
737
+ }
738
+ getDbForBlock(blockNumber) {
739
+ const db = this.dbs.get(blockNumber);
740
+ if (!db) {
741
+ throw new Error(`World state fork for block ${blockNumber} not found.`);
742
+ }
743
+ return db;
235
744
  }
236
745
  /**
237
746
  * Returns the proof for the current epoch.
238
- */ async finaliseEpoch() {
747
+ */ async finalizeEpoch() {
239
748
  if (!this.provingState || !this.provingPromise) {
240
- throw new Error(`Invalid proving state, an epoch must be proven before it can be finalised`);
749
+ throw new Error(`Invalid proving state, an epoch must be proven before it can be finalized`);
241
750
  }
242
751
  const result = await this.provingPromise;
243
752
  if (result.status === 'failure') {
244
753
  throw new Error(`Epoch proving failed: ${result.reason}`);
245
754
  }
755
+ await this.provingState.finalizeBatchedBlob();
246
756
  const epochProofResult = this.provingState.getEpochProofResult();
247
757
  pushTestData('epochProofResult', {
248
758
  proof: epochProofResult.proof.toString(),
@@ -250,90 +760,25 @@ const logger = createLogger('prover-client:orchestrator');
250
760
  });
251
761
  return epochProofResult;
252
762
  }
253
- /**
254
- * Starts the proving process for the given transaction and adds it to our state
255
- * @param tx - The transaction whose proving we wish to commence
256
- * @param provingState - The proving state being worked on
257
- */ async prepareTransaction(tx, provingState) {
258
- const txInputs = await this.prepareBaseRollupInputs(provingState, tx);
259
- if (!txInputs) {
260
- // This should not be possible
261
- throw new Error(`Unable to add transaction, preparing base inputs failed`);
262
- }
263
- return txInputs;
264
- }
265
- /**
266
- * Enqueue a job to be scheduled
267
- * @param provingState - The proving state object being operated on
268
- * @param jobType - The type of job to be queued
269
- * @param job - The actual job, returns a promise notifying of the job's completion
270
- */ deferredProving(provingState, request, callback) {
271
- if (!provingState?.verifyState()) {
272
- logger.debug(`Not enqueuing job, state no longer valid`);
273
- return;
274
- }
275
- const controller = new AbortController();
276
- this.pendingProvingJobs.push(controller);
277
- // We use a 'safeJob'. We don't want promise rejections in the proving pool, we want to capture the error here
278
- // and reject the proving job whilst keeping the event loop free of rejections
279
- const safeJob = async ()=>{
280
- try {
281
- // there's a delay between enqueueing this job and it actually running
282
- if (controller.signal.aborted) {
283
- return;
284
- }
285
- const result = await request(controller.signal);
286
- if (!provingState?.verifyState()) {
287
- logger.debug(`State no longer valid, discarding result`);
288
- return;
289
- }
290
- // we could have been cancelled whilst waiting for the result
291
- // and the prover ignored the signal. Drop the result in that case
292
- if (controller.signal.aborted) {
293
- return;
294
- }
295
- await callback(result);
296
- } catch (err) {
297
- if (err instanceof AbortError) {
298
- // operation was cancelled, probably because the block was cancelled
299
- // drop this result
300
- return;
301
- }
302
- logger.error(`Error thrown when proving job`, err);
303
- provingState.reject(`${err}`);
304
- } finally{
305
- const index = this.pendingProvingJobs.indexOf(controller);
306
- if (index > -1) {
307
- this.pendingProvingJobs.splice(index, 1);
308
- }
309
- }
310
- };
311
- // let the callstack unwind before adding the job to the queue
312
- setImmediate(()=>void safeJob());
313
- }
314
- async prepareBaseParityInputs(l1ToL2Messages, db) {
315
- const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, 'Too many L1 to L2 messages');
316
- const baseParityInputs = times(NUM_BASE_PARITY_PER_ROOT_PARITY, (i)=>BaseParityInputs.fromSlice(l1ToL2MessagesPadded, i, getVKTreeRoot()));
317
- const l1ToL2MessageSubtreeSiblingPath = assertLength(await getSubtreeSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, L1_TO_L2_MSG_SUBTREE_HEIGHT, db), L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH);
763
+ async updateL1ToL2MessageTree(l1ToL2Messages, db) {
764
+ const lastL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
765
+ const lastL1ToL2MessageSubtreeRootSiblingPath = assertLength(await getSubtreeSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, L1_TO_L2_MSG_SUBTREE_HEIGHT, db), L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH);
318
766
  // Update the local trees to include the new l1 to l2 messages
319
- await db.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
320
- const l1ToL2MessageTreeSnapshotAfterInsertion = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
767
+ await appendL1ToL2MessagesToTree(db, l1ToL2Messages);
768
+ const newL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
769
+ const newL1ToL2MessageSubtreeRootSiblingPath = assertLength(await getSubtreeSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, L1_TO_L2_MSG_SUBTREE_HEIGHT, db), L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH);
321
770
  return {
322
- l1ToL2MessageSubtreeSiblingPath,
323
- l1ToL2MessageTreeSnapshotAfterInsertion,
324
- baseParityInputs
771
+ lastL1ToL2MessageTreeSnapshot,
772
+ lastL1ToL2MessageSubtreeRootSiblingPath,
773
+ newL1ToL2MessageTreeSnapshot,
774
+ newL1ToL2MessageSubtreeRootSiblingPath
325
775
  };
326
776
  }
327
777
  // Updates the merkle trees for a transaction. The first enqueued job for a transaction
328
- async prepareBaseRollupInputs(provingState, tx) {
329
- if (!provingState.verifyState() || !provingState.spongeBlobState) {
330
- logger.debug('Not preparing base rollup inputs, state invalid');
331
- return;
332
- }
333
- const db = this.dbs.get(provingState.blockNumber);
778
+ async prepareBaseRollupInputs(tx, lastArchive, newL1ToL2MessageTreeSnapshot, startSpongeBlob, db) {
334
779
  // We build the base rollup inputs using a mock proof and verification key.
335
- // These will be overwritten later once we have proven the tube circuit and any public kernels
336
- const [ms, hints] = await elapsed(buildBaseRollupHints(tx, provingState.globalVariables, db, provingState.spongeBlobState));
780
+ // These will be overwritten later once we have proven the chonk verifier circuit and any public kernels
781
+ const [ms, hints] = await elapsed(insertSideEffectsAndBuildBaseRollupHints(tx, lastArchive, newL1ToL2MessageTreeSnapshot, startSpongeBlob, this.proverId.toField(), db));
337
782
  this.metrics.recordBaseRollupInputs(ms);
338
783
  const promises = [
339
784
  MerkleTreeId.NOTE_HASH_TREE,
@@ -349,10 +794,6 @@ const logger = createLogger('prover-client:orchestrator');
349
794
  obj.key,
350
795
  obj.value
351
796
  ]));
352
- if (!provingState.verifyState()) {
353
- logger.debug(`Discarding proving job, state no longer valid`);
354
- return;
355
- }
356
797
  return [
357
798
  hints,
358
799
  treeSnapshots
@@ -362,138 +803,153 @@ const logger = createLogger('prover-client:orchestrator');
362
803
  // Executes the next level of merge if all inputs are available
363
804
  enqueueBaseRollup(provingState, txIndex) {
364
805
  if (!provingState.verifyState()) {
365
- logger.debug('Not running base rollup, state invalid');
806
+ this.logger.debug('Not running base rollup, state invalid');
807
+ return;
808
+ }
809
+ if (!provingState.tryStartProvingBase(txIndex)) {
810
+ this.logger.debug(`Base rollup for tx ${txIndex} already started.`);
366
811
  return;
367
812
  }
368
813
  const txProvingState = provingState.getTxProvingState(txIndex);
369
814
  const { processedTx } = txProvingState;
370
815
  const { rollupType, inputs } = txProvingState.getBaseRollupTypeAndInputs();
371
- logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
372
- this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, `ProvingOrchestrator.prover.${inputs instanceof PrivateBaseRollupInputs ? 'getPrivateBaseRollupProof' : 'getPublicBaseRollupProof'}`, {
816
+ this.logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
817
+ this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, `ProvingOrchestrator.prover.${inputs instanceof PrivateTxBaseRollupPrivateInputs ? 'getPrivateTxBaseRollupProof' : 'getPublicTxBaseRollupProof'}`, {
373
818
  [Attributes.TX_HASH]: processedTx.hash.toString(),
374
- [Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
375
819
  [Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
376
820
  }, (signal)=>{
377
- if (inputs instanceof PrivateBaseRollupInputs) {
378
- return this.prover.getPrivateBaseRollupProof(inputs, signal, provingState.epochNumber);
821
+ if (inputs instanceof PrivateTxBaseRollupPrivateInputs) {
822
+ return this.prover.getPrivateTxBaseRollupProof(inputs, signal, provingState.epochNumber);
379
823
  } else {
380
- return this.prover.getPublicBaseRollupProof(inputs, signal, provingState.epochNumber);
824
+ return this.prover.getPublicTxBaseRollupProof(inputs, signal, provingState.epochNumber);
381
825
  }
382
- }), async (result)=>{
383
- logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
384
- validatePartialState(result.inputs.end, txProvingState.treeSnapshots);
826
+ }), (result)=>{
827
+ this.logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
828
+ validatePartialState(result.inputs.endTreeSnapshots, txProvingState.treeSnapshots);
385
829
  const leafLocation = provingState.setBaseRollupProof(txIndex, result);
386
830
  if (provingState.totalNumTxs === 1) {
387
- await this.checkAndEnqueueBlockRootRollup(provingState);
831
+ this.checkAndEnqueueBlockRootRollup(provingState);
388
832
  } else {
389
- await this.checkAndEnqueueNextMergeRollup(provingState, leafLocation);
833
+ this.checkAndEnqueueNextMergeRollup(provingState, leafLocation);
390
834
  }
391
835
  });
392
836
  }
393
- // Enqueues the tube circuit for a given transaction index, or reuses the one already enqueued
394
- // Once completed, will enqueue the next circuit, either a public kernel or the base rollup
395
- getOrEnqueueTube(provingState, txIndex) {
837
+ // Enqueues the public chonk verifier circuit for a given transaction index, or reuses the one already enqueued.
838
+ // Once completed, will enqueue the the public tx base rollup.
839
+ getOrEnqueueChonkVerifier(provingState, txIndex) {
396
840
  if (!provingState.verifyState()) {
397
- logger.debug('Not running tube circuit, state invalid');
841
+ this.logger.debug('Not running chonk verifier circuit, state invalid');
398
842
  return;
399
843
  }
400
844
  const txProvingState = provingState.getTxProvingState(txIndex);
401
845
  const txHash = txProvingState.processedTx.hash.toString();
402
846
  const handleResult = (result)=>{
403
- logger.debug(`Got tube proof for tx index: ${txIndex}`, {
847
+ this.logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, {
404
848
  txHash
405
849
  });
406
- txProvingState.setTubeProof(result);
407
- this.provingState?.cachedTubeProofs.delete(txHash);
408
- this.checkAndEnqueueNextTxCircuit(provingState, txIndex);
850
+ txProvingState.setPublicChonkVerifierProof(result);
851
+ this.provingState?.cachedChonkVerifierProofs.delete(txHash);
852
+ this.checkAndEnqueueBaseRollup(provingState, txIndex);
409
853
  };
410
- if (this.provingState?.cachedTubeProofs.has(txHash)) {
411
- logger.debug(`Tube proof already enqueued for tx index: ${txIndex}`, {
854
+ if (this.provingState?.cachedChonkVerifierProofs.has(txHash)) {
855
+ this.logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, {
412
856
  txHash
413
857
  });
414
- void this.provingState.cachedTubeProofs.get(txHash).then(handleResult);
858
+ void this.provingState.cachedChonkVerifierProofs.get(txHash).then(handleResult);
415
859
  return;
416
860
  }
417
- logger.debug(`Enqueuing tube circuit for tx index: ${txIndex}`);
418
- this.doEnqueueTube(txHash, txProvingState.getTubeInputs(), handleResult);
861
+ this.logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
862
+ this.doEnqueueChonkVerifier(txHash, txProvingState.getPublicChonkVerifierPrivateInputs(), handleResult);
419
863
  }
420
- doEnqueueTube(txHash, inputs, handler, provingState = this.provingState) {
421
- if (!provingState?.verifyState()) {
422
- logger.debug('Not running tube circuit, state invalid');
864
+ doEnqueueChonkVerifier(txHash, inputs, handler, provingState = this.provingState) {
865
+ if (!provingState.verifyState()) {
866
+ this.logger.debug('Not running chonk verifier circuit, state invalid');
423
867
  return;
424
868
  }
425
- this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getTubeProof', {
869
+ this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getPublicChonkVerifierProof', {
426
870
  [Attributes.TX_HASH]: txHash,
427
- [Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
428
- [Attributes.PROTOCOL_CIRCUIT_NAME]: 'tube-circuit'
429
- }, (signal)=>this.prover.getTubeProof(inputs, signal, this.provingState.epochNumber)), handler);
871
+ [Attributes.PROTOCOL_CIRCUIT_NAME]: 'chonk-verifier-public'
872
+ }, (signal)=>this.prover.getPublicChonkVerifierProof(inputs, signal, provingState.epochNumber)), handler);
430
873
  }
431
874
  // Executes the merge rollup circuit and stored the output as intermediate state for the parent merge/block root circuit
432
875
  // Enqueues the next level of merge if all inputs are available
433
876
  enqueueMergeRollup(provingState, location) {
434
877
  if (!provingState.verifyState()) {
435
- logger.debug('Not running merge rollup. State no longer valid.');
878
+ this.logger.debug('Not running merge rollup. State no longer valid.');
879
+ return;
880
+ }
881
+ if (!provingState.tryStartProvingMerge(location)) {
882
+ this.logger.debug('Merge rollup already started.');
436
883
  return;
437
884
  }
438
885
  const inputs = provingState.getMergeRollupInputs(location);
439
- this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getMergeRollupProof', {
440
- [Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
441
- [Attributes.PROTOCOL_CIRCUIT_NAME]: 'merge-rollup'
442
- }, (signal)=>this.prover.getMergeRollupProof(inputs, signal, provingState.epochNumber)), async (result)=>{
886
+ this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getTxMergeRollupProof', {
887
+ [Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-tx-merge'
888
+ }, (signal)=>this.prover.getTxMergeRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
443
889
  provingState.setMergeRollupProof(location, result);
444
- await this.checkAndEnqueueNextMergeRollup(provingState, location);
890
+ this.checkAndEnqueueNextMergeRollup(provingState, location);
445
891
  });
446
892
  }
447
893
  // Executes the block root rollup circuit
448
- async enqueueBlockRootRollup(provingState) {
894
+ enqueueBlockRootRollup(provingState) {
449
895
  if (!provingState.verifyState()) {
450
- logger.debug('Not running block root rollup, state no longer valid');
896
+ this.logger.debug('Not running block root rollup, state no longer valid');
897
+ return;
898
+ }
899
+ if (!provingState.tryStartProvingBlockRoot()) {
900
+ this.logger.debug('Block root rollup already started.');
451
901
  return;
452
902
  }
453
- provingState.blockRootRollupStarted = true;
454
- const { rollupType, inputs } = await provingState.getBlockRootRollupTypeAndInputs(this.proverId);
455
- logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber} with ${provingState.newL1ToL2Messages.length} l1 to l2 msgs.`);
903
+ const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs();
904
+ this.logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
456
905
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getBlockRootRollupProof', {
457
- [Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
458
906
  [Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
459
907
  }, (signal)=>{
460
- if (inputs instanceof EmptyBlockRootRollupInputs) {
461
- return this.prover.getEmptyBlockRootRollupProof(inputs, signal, provingState.epochNumber);
462
- } else if (inputs instanceof SingleTxBlockRootRollupInputs) {
463
- return this.prover.getSingleTxBlockRootRollupProof(inputs, signal, provingState.epochNumber);
908
+ if (inputs instanceof BlockRootFirstRollupPrivateInputs) {
909
+ return this.prover.getBlockRootFirstRollupProof(inputs, signal, provingState.epochNumber);
910
+ } else if (inputs instanceof BlockRootSingleTxFirstRollupPrivateInputs) {
911
+ return this.prover.getBlockRootSingleTxFirstRollupProof(inputs, signal, provingState.epochNumber);
912
+ } else if (inputs instanceof BlockRootEmptyTxFirstRollupPrivateInputs) {
913
+ return this.prover.getBlockRootEmptyTxFirstRollupProof(inputs, signal, provingState.epochNumber);
914
+ } else if (inputs instanceof BlockRootSingleTxRollupPrivateInputs) {
915
+ return this.prover.getBlockRootSingleTxRollupProof(inputs, signal, provingState.epochNumber);
464
916
  } else {
465
917
  return this.prover.getBlockRootRollupProof(inputs, signal, provingState.epochNumber);
466
918
  }
467
919
  }), async (result)=>{
468
- provingState.setBlockRootRollupProof(result);
469
- const header = await provingState.buildHeaderFromProvingOutputs(logger);
470
- if (!(await header.hash()).equals(await provingState.block.header.hash())) {
471
- logger.error(`Block header mismatch\nCircuit:${inspect(header)}\nComputed:${inspect(provingState.block.header)}`);
472
- provingState.reject(`Block header hash mismatch`);
473
- }
474
- logger.debug(`Completed ${rollupType} proof for block ${provingState.block.number}`);
475
- // validatePartialState(result.inputs.end, tx.treeSnapshots); // TODO(palla/prover)
476
- const epochProvingState = this.provingState;
477
- const leafLocation = epochProvingState.setBlockRootRollupProof(provingState.index, result);
478
- if (epochProvingState.totalNumBlocks === 1) {
479
- await this.enqueueEpochPadding(epochProvingState);
920
+ this.logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`, {
921
+ blockNumber: provingState.blockNumber,
922
+ checkpointIndex: provingState.parentCheckpoint.index,
923
+ ...result.inputs.toInspect()
924
+ });
925
+ const leafLocation = provingState.setBlockRootRollupProof(result);
926
+ const checkpointProvingState = provingState.parentCheckpoint;
927
+ // Verification is called from both here and setBlockCompleted. Whichever runs last
928
+ // will be the first to see all three pieces (header, proof output, archive) and run the checks.
929
+ await this.verifyBuiltBlockAgainstSyncedState(provingState);
930
+ if (checkpointProvingState.totalNumBlocks === 1) {
931
+ await this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
480
932
  } else {
481
- this.checkAndEnqueueNextBlockMergeRollup(epochProvingState, leafLocation);
933
+ await this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
482
934
  }
483
935
  });
484
936
  }
485
937
  // Executes the base parity circuit and stores the intermediate state for the root parity circuit
486
938
  // Enqueues the root parity circuit if all inputs are available
487
- enqueueBaseParityCircuit(provingState, inputs, index) {
939
+ enqueueBaseParityCircuit(checkpointProvingState, provingState, baseParityIndex) {
488
940
  if (!provingState.verifyState()) {
489
- logger.debug('Not running base parity. State no longer valid.');
941
+ this.logger.debug('Not running base parity. State no longer valid.');
490
942
  return;
491
943
  }
944
+ if (!provingState.tryStartProvingBaseParity(baseParityIndex)) {
945
+ this.logger.warn(`Base parity ${baseParityIndex} already started.`);
946
+ return;
947
+ }
948
+ const inputs = checkpointProvingState.getBaseParityInputs(baseParityIndex);
492
949
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getBaseParityProof', {
493
- [Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
494
- [Attributes.PROTOCOL_CIRCUIT_NAME]: 'base-parity'
950
+ [Attributes.PROTOCOL_CIRCUIT_NAME]: 'parity-base'
495
951
  }, (signal)=>this.prover.getBaseParityProof(inputs, signal, provingState.epochNumber)), (provingOutput)=>{
496
- provingState.setBaseParityProof(index, provingOutput);
952
+ provingState.setBaseParityProof(baseParityIndex, provingOutput);
497
953
  this.checkAndEnqueueRootParityCircuit(provingState);
498
954
  });
499
955
  }
@@ -507,115 +963,120 @@ const logger = createLogger('prover-client:orchestrator');
507
963
  // Enqueues the root rollup proof if all inputs are available
508
964
  enqueueRootParityCircuit(provingState) {
509
965
  if (!provingState.verifyState()) {
510
- logger.debug('Not running root parity. State no longer valid.');
966
+ this.logger.debug('Not running root parity. State no longer valid.');
511
967
  return;
512
968
  }
513
- const inputs = provingState.getRootParityInputs();
969
+ if (!provingState.tryStartProvingRootParity()) {
970
+ this.logger.debug('Root parity already started.');
971
+ return;
972
+ }
973
+ const inputs = provingState.getParityRootInputs();
514
974
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getRootParityProof', {
515
- [Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
516
- [Attributes.PROTOCOL_CIRCUIT_NAME]: 'root-parity'
517
- }, (signal)=>this.prover.getRootParityProof(inputs, signal, provingState.epochNumber)), async (result)=>{
975
+ [Attributes.PROTOCOL_CIRCUIT_NAME]: 'parity-root'
976
+ }, (signal)=>this.prover.getRootParityProof(inputs, signal, provingState.epochNumber)), (result)=>{
518
977
  provingState.setRootParityProof(result);
519
- await this.checkAndEnqueueBlockRootRollup(provingState);
978
+ this.checkAndEnqueueBlockRootRollup(provingState);
520
979
  });
521
980
  }
522
981
  // Executes the block merge rollup circuit and stored the output as intermediate state for the parent merge/block root circuit
523
982
  // Enqueues the next level of merge if all inputs are available
524
983
  enqueueBlockMergeRollup(provingState, location) {
525
984
  if (!provingState.verifyState()) {
526
- logger.debug('Not running block merge rollup. State no longer valid.');
985
+ this.logger.debug('Not running block merge rollup. State no longer valid.');
986
+ return;
987
+ }
988
+ if (!provingState.tryStartProvingBlockMerge(location)) {
989
+ this.logger.debug('Block merge rollup already started.');
527
990
  return;
528
991
  }
529
992
  const inputs = provingState.getBlockMergeRollupInputs(location);
530
993
  this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getBlockMergeRollupProof', {
531
- [Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
532
- [Attributes.PROTOCOL_CIRCUIT_NAME]: 'block-merge-rollup'
533
- }, (signal)=>this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
994
+ [Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-block-merge'
995
+ }, (signal)=>this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber)), async (result)=>{
996
+ this.logger.debug(`Completed block merge rollup proof for checkpoint ${provingState.index}`, {
997
+ checkpointIndex: provingState.index,
998
+ mergeLocation: location,
999
+ ...result.inputs.toInspect()
1000
+ });
534
1001
  provingState.setBlockMergeRollupProof(location, result);
535
- this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
1002
+ await this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
536
1003
  });
537
1004
  }
538
- async enqueueEpochPadding(provingState) {
1005
+ async enqueueCheckpointRootRollup(provingState) {
539
1006
  if (!provingState.verifyState()) {
540
- logger.debug('Not running epoch padding. State no longer valid.');
1007
+ this.logger.debug('Not running checkpoint root rollup. State no longer valid.');
541
1008
  return;
542
1009
  }
543
- logger.debug('Padding epoch proof with an empty block root proof.');
544
- const inputs = await provingState.getPaddingBlockRootInputs(this.proverId);
545
- this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getEmptyBlockRootRollupProof', {
546
- [Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
547
- [Attributes.PROTOCOL_CIRCUIT_NAME]: 'empty-block-root-rollup'
548
- }, (signal)=>this.prover.getEmptyBlockRootRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
549
- logger.debug('Completed proof for padding block root.');
550
- provingState.setPaddingBlockRootProof(result);
551
- this.checkAndEnqueueRootRollup(provingState);
552
- });
553
- }
554
- // Executes the root rollup circuit
555
- enqueueRootRollup(provingState) {
556
- if (!provingState.verifyState()) {
557
- logger.debug('Not running root rollup, state no longer valid');
1010
+ if (!provingState.tryStartProvingCheckpointRoot()) {
1011
+ this.logger.debug('Checkpoint root rollup already started.');
558
1012
  return;
559
1013
  }
560
- logger.debug(`Preparing root rollup`);
561
- const inputs = provingState.getRootRollupInputs(this.proverId);
562
- this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getRootRollupProof', {
563
- [Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
564
- [Attributes.PROTOCOL_CIRCUIT_NAME]: 'root-rollup'
565
- }, (signal)=>this.prover.getRootRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
566
- logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
567
- provingState.setRootRollupProof(result);
568
- provingState.resolve({
569
- status: 'success'
1014
+ const rollupType = provingState.getCheckpointRootRollupType();
1015
+ this.logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
1016
+ const inputs = await provingState.getCheckpointRootRollupInputs();
1017
+ this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointRootRollupProof', {
1018
+ [Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
1019
+ }, (signal)=>{
1020
+ if (inputs instanceof CheckpointRootSingleBlockRollupPrivateInputs) {
1021
+ return this.prover.getCheckpointRootSingleBlockRollupProof(inputs, signal, provingState.epochNumber);
1022
+ } else {
1023
+ return this.prover.getCheckpointRootRollupProof(inputs, signal, provingState.epochNumber);
1024
+ }
1025
+ }), (result)=>{
1026
+ const computedEndBlobAccumulatorState = provingState.getEndBlobAccumulator().toBlobAccumulator();
1027
+ const circuitEndBlobAccumulatorState = result.inputs.endBlobAccumulator;
1028
+ if (!circuitEndBlobAccumulatorState.equals(computedEndBlobAccumulatorState)) {
1029
+ this.logger.error(`Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(computedEndBlobAccumulatorState)}`);
1030
+ provingState.reject(`Blob accumulator state mismatch.`);
1031
+ return;
1032
+ }
1033
+ this.logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}`, {
1034
+ checkpointIndex: provingState.index,
1035
+ ...result.inputs.toInspect()
570
1036
  });
1037
+ const leafLocation = provingState.setCheckpointRootRollupProof(result);
1038
+ const epochProvingState = provingState.parentEpoch;
1039
+ if (epochProvingState.totalNumCheckpoints === 1) {
1040
+ this.enqueueEpochPadding(epochProvingState);
1041
+ } else {
1042
+ this.checkAndEnqueueNextCheckpointMergeRollup(epochProvingState, leafLocation);
1043
+ }
571
1044
  });
572
1045
  }
573
- async checkAndEnqueueNextMergeRollup(provingState, currentLocation) {
1046
+ checkAndEnqueueNextMergeRollup(provingState, currentLocation) {
574
1047
  if (!provingState.isReadyForMergeRollup(currentLocation)) {
575
1048
  return;
576
1049
  }
577
1050
  const parentLocation = provingState.getParentLocation(currentLocation);
578
1051
  if (parentLocation.level === 0) {
579
- await this.checkAndEnqueueBlockRootRollup(provingState);
1052
+ this.checkAndEnqueueBlockRootRollup(provingState);
580
1053
  } else {
581
1054
  this.enqueueMergeRollup(provingState, parentLocation);
582
1055
  }
583
1056
  }
584
- async checkAndEnqueueBlockRootRollup(provingState) {
1057
+ checkAndEnqueueBlockRootRollup(provingState) {
585
1058
  if (!provingState.isReadyForBlockRootRollup()) {
586
- logger.debug('Not ready for root rollup');
587
- return;
588
- }
589
- if (provingState.blockRootRollupStarted) {
590
- logger.debug('Block root rollup already started');
1059
+ this.logger.debug('Not ready for block root rollup');
591
1060
  return;
592
1061
  }
593
- const blockNumber = provingState.blockNumber;
594
- // TODO(palla/prover): This closes the fork only on the happy path. If this epoch orchestrator
595
- // is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
596
- // but have to make sure it only runs once all operations are completed, otherwise some function here
597
- // will attempt to access the fork after it was closed.
598
- logger.debug(`Cleaning up world state fork for ${blockNumber}`);
599
- void this.dbs.get(blockNumber)?.close().then(()=>this.dbs.delete(blockNumber)).catch((err)=>logger.error(`Error closing db for block ${blockNumber}`, err));
600
- await this.enqueueBlockRootRollup(provingState);
601
- }
602
- checkAndEnqueueNextBlockMergeRollup(provingState, currentLocation) {
1062
+ this.enqueueBlockRootRollup(provingState);
1063
+ }
1064
+ async checkAndEnqueueNextBlockMergeRollup(provingState, currentLocation) {
603
1065
  if (!provingState.isReadyForBlockMerge(currentLocation)) {
604
1066
  return;
605
1067
  }
606
1068
  const parentLocation = provingState.getParentLocation(currentLocation);
607
1069
  if (parentLocation.level === 0) {
608
- this.checkAndEnqueueRootRollup(provingState);
1070
+ await this.checkAndEnqueueCheckpointRootRollup(provingState);
609
1071
  } else {
610
1072
  this.enqueueBlockMergeRollup(provingState, parentLocation);
611
1073
  }
612
1074
  }
613
- checkAndEnqueueRootRollup(provingState) {
614
- if (!provingState.isReadyForRootRollup()) {
615
- logger.debug('Not ready for root rollup');
1075
+ async checkAndEnqueueCheckpointRootRollup(provingState) {
1076
+ if (!provingState.isReadyForCheckpointRoot()) {
616
1077
  return;
617
1078
  }
618
- this.enqueueRootRollup(provingState);
1079
+ await this.enqueueCheckpointRootRollup(provingState);
619
1080
  }
620
1081
  /**
621
1082
  * Executes the VM circuit for a public function, will enqueue the corresponding kernel if the
@@ -624,67 +1085,29 @@ const logger = createLogger('prover-client:orchestrator');
624
1085
  * @param txIndex - The index of the transaction being proven
625
1086
  */ enqueueVM(provingState, txIndex) {
626
1087
  if (!provingState.verifyState()) {
627
- logger.debug(`Not running VM circuit as state is no longer valid`);
1088
+ this.logger.debug(`Not running VM circuit as state is no longer valid`);
628
1089
  return;
629
1090
  }
630
1091
  const txProvingState = provingState.getTxProvingState(txIndex);
631
- // This function tries to do AVM proving. If there is a failure, it fakes the proof unless AVM_PROVING_STRICT is defined.
632
- // Nothing downstream depends on the AVM proof yet. So having this mode lets us incrementally build the AVM circuit.
633
1092
  const doAvmProving = wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getAvmProof', {
634
1093
  [Attributes.TX_HASH]: txProvingState.processedTx.hash.toString()
635
1094
  }, async (signal)=>{
636
1095
  const inputs = txProvingState.getAvmInputs();
637
- try {
638
- return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
639
- } catch (err) {
640
- if (process.env.AVM_PROVING_STRICT) {
641
- logger.error(`Error thrown when proving AVM circuit with AVM_PROVING_STRICT on`, err);
642
- throw err;
643
- } else {
644
- logger.warn(`Error thrown when proving AVM circuit but AVM_PROVING_STRICT is off. Faking AVM proof and carrying on. ${inspect(err)}.`);
645
- return {
646
- proof: makeEmptyRecursiveProof(AVM_PROOF_LENGTH_IN_FIELDS),
647
- verificationKey: VerificationKeyData.makeFake(AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS)
648
- };
649
- }
650
- }
1096
+ return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
651
1097
  });
652
- this.deferredProving(provingState, doAvmProving, (proofAndVk)=>{
653
- logger.debug(`Proven VM for tx index: ${txIndex}`);
654
- txProvingState.setAvmProof(proofAndVk);
655
- this.checkAndEnqueueNextTxCircuit(provingState, txIndex);
1098
+ this.deferredProving(provingState, doAvmProving, (proof)=>{
1099
+ this.logger.debug(`Proven VM for tx index: ${txIndex}`);
1100
+ txProvingState.setAvmProof(proof);
1101
+ this.checkAndEnqueueBaseRollup(provingState, txIndex);
656
1102
  });
657
1103
  }
658
- checkAndEnqueueNextTxCircuit(provingState, txIndex) {
1104
+ checkAndEnqueueBaseRollup(provingState, txIndex) {
659
1105
  const txProvingState = provingState.getTxProvingState(txIndex);
660
1106
  if (!txProvingState.ready()) {
661
1107
  return;
662
1108
  }
663
- // We must have completed all proving (tube proof and (if required) vm proof are generated), we now move to the base rollup.
664
- logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
1109
+ // We must have completed all proving (chonk verifier proof and (if required) vm proof are generated), we now move to the base rollup.
1110
+ this.logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
665
1111
  this.enqueueBaseRollup(provingState, txIndex);
666
1112
  }
667
1113
  }
668
- _ts_decorate([
669
- trackSpan('ProvingOrchestrator.startNewBlock', (globalVariables)=>({
670
- [Attributes.BLOCK_NUMBER]: globalVariables.blockNumber.toNumber()
671
- }))
672
- ], ProvingOrchestrator.prototype, "startNewBlock", null);
673
- _ts_decorate([
674
- trackSpan('ProvingOrchestrator.addTxs', (txs)=>({
675
- [Attributes.BLOCK_TXS_COUNT]: txs.length
676
- }))
677
- ], ProvingOrchestrator.prototype, "addTxs", null);
678
- _ts_decorate([
679
- trackSpan('ProvingOrchestrator.startTubeCircuits')
680
- ], ProvingOrchestrator.prototype, "startTubeCircuits", null);
681
- _ts_decorate([
682
- trackSpan('ProvingOrchestrator.setBlockCompleted', (blockNumber)=>({
683
- [Attributes.BLOCK_NUMBER]: blockNumber
684
- }))
685
- ], ProvingOrchestrator.prototype, "setBlockCompleted", null);
686
- _ts_decorate([
687
- trackSpan('ProvingOrchestrator.prepareBaseRollupInputs', (_, tx)=>({
688
- [Attributes.TX_HASH]: tx.hash.toString()
689
- }))
690
- ], ProvingOrchestrator.prototype, "prepareBaseRollupInputs", null);