@aztec/prover-client 0.0.0-test.0 → 0.0.1-commit.001888fc
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.
- package/dest/config.d.ts +8 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +12 -2
- package/dest/index.d.ts +1 -1
- package/dest/light/index.d.ts +2 -0
- package/dest/light/index.d.ts.map +1 -0
- package/dest/light/index.js +1 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts +52 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
- package/dest/light/lightweight_checkpoint_builder.js +223 -0
- package/dest/mocks/fixtures.d.ts +8 -8
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +36 -17
- package/dest/mocks/test_context.d.ts +43 -32
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +152 -87
- package/dest/orchestrator/block-building-helpers.d.ts +36 -29
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +170 -189
- package/dest/orchestrator/block-proving-state.d.ts +73 -48
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +289 -177
- package/dest/orchestrator/checkpoint-proving-state.d.ts +76 -0
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-proving-state.js +243 -0
- package/dest/orchestrator/epoch-proving-state.d.ts +43 -28
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +179 -73
- package/dest/orchestrator/index.d.ts +1 -1
- package/dest/orchestrator/orchestrator.d.ts +55 -35
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +874 -314
- package/dest/orchestrator/orchestrator_metrics.d.ts +1 -1
- package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator_metrics.js +2 -6
- package/dest/orchestrator/tx-proving-state.d.ts +15 -12
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +27 -44
- package/dest/prover-client/factory.d.ts +3 -3
- package/dest/prover-client/factory.d.ts.map +1 -1
- package/dest/prover-client/index.d.ts +1 -1
- package/dest/prover-client/prover-client.d.ts +8 -8
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +19 -13
- package/dest/prover-client/server-epoch-prover.d.ts +16 -12
- package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
- package/dest/prover-client/server-epoch-prover.js +11 -11
- package/dest/proving_broker/broker_prover_facade.d.ts +28 -19
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +64 -45
- package/dest/proving_broker/config.d.ts +32 -11
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +42 -8
- package/dest/proving_broker/factory.d.ts +2 -2
- package/dest/proving_broker/factory.d.ts.map +1 -1
- package/dest/proving_broker/factory.js +5 -1
- package/dest/proving_broker/fixtures.d.ts +3 -2
- package/dest/proving_broker/fixtures.d.ts.map +1 -1
- package/dest/proving_broker/fixtures.js +3 -2
- package/dest/proving_broker/index.d.ts +1 -1
- package/dest/proving_broker/proof_store/factory.d.ts +2 -5
- package/dest/proving_broker/proof_store/factory.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/factory.js +7 -30
- package/dest/proving_broker/proof_store/file_store_proof_store.d.ts +18 -0
- package/dest/proving_broker/proof_store/file_store_proof_store.d.ts.map +1 -0
- package/dest/proving_broker/proof_store/file_store_proof_store.js +60 -0
- package/dest/proving_broker/proof_store/index.d.ts +2 -1
- package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/index.js +1 -0
- package/dest/proving_broker/proof_store/inline_proof_store.d.ts +1 -1
- package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/proof_store.d.ts +1 -1
- package/dest/proving_broker/proving_agent.d.ts +8 -12
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.js +86 -65
- package/dest/proving_broker/proving_broker.d.ts +17 -5
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +76 -37
- package/dest/proving_broker/proving_broker_database/memory.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/memory.js +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.d.ts +5 -3
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.js +401 -11
- package/dest/proving_broker/proving_broker_database.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts +3 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.js +22 -35
- package/dest/proving_broker/proving_job_controller.d.ts +11 -10
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.js +92 -62
- package/dest/proving_broker/rpc.d.ts +7 -7
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +9 -4
- package/dest/test/mock_proof_store.d.ts +9 -0
- package/dest/test/mock_proof_store.d.ts.map +1 -0
- package/dest/test/mock_proof_store.js +10 -0
- package/dest/test/mock_prover.d.ts +23 -17
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +38 -20
- package/package.json +34 -33
- package/src/config.ts +25 -9
- package/src/light/index.ts +1 -0
- package/src/light/lightweight_checkpoint_builder.ts +312 -0
- package/src/mocks/fixtures.ts +46 -40
- package/src/mocks/test_context.ts +223 -116
- package/src/orchestrator/block-building-helpers.ts +258 -334
- package/src/orchestrator/block-proving-state.ts +334 -231
- package/src/orchestrator/checkpoint-proving-state.ts +349 -0
- package/src/orchestrator/epoch-proving-state.ts +239 -111
- package/src/orchestrator/orchestrator.ts +674 -355
- package/src/orchestrator/orchestrator_metrics.ts +2 -6
- package/src/orchestrator/tx-proving-state.ts +48 -66
- package/src/prover-client/factory.ts +6 -2
- package/src/prover-client/prover-client.ts +49 -38
- package/src/prover-client/server-epoch-prover.ts +40 -22
- package/src/proving_broker/broker_prover_facade.ts +219 -133
- package/src/proving_broker/config.ts +48 -8
- package/src/proving_broker/factory.ts +2 -1
- package/src/proving_broker/fixtures.ts +8 -3
- package/src/proving_broker/proof_store/factory.ts +10 -32
- package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
- package/src/proving_broker/proof_store/index.ts +1 -0
- package/src/proving_broker/proof_store/inline_proof_store.ts +1 -1
- package/src/proving_broker/proving_agent.ts +95 -66
- package/src/proving_broker/proving_broker.ts +94 -44
- package/src/proving_broker/proving_broker_database/memory.ts +3 -2
- package/src/proving_broker/proving_broker_database/persisted.ts +29 -13
- package/src/proving_broker/proving_broker_database.ts +2 -1
- package/src/proving_broker/proving_broker_instrumentation.ts +23 -35
- package/src/proving_broker/proving_job_controller.ts +100 -83
- package/src/proving_broker/rpc.ts +14 -5
- package/src/test/mock_proof_store.ts +14 -0
- package/src/test/mock_prover.ts +156 -64
- package/dest/bin/get-proof-inputs.d.ts +0 -2
- package/dest/bin/get-proof-inputs.d.ts.map +0 -1
- package/dest/bin/get-proof-inputs.js +0 -51
- package/dest/block_builder/index.d.ts +0 -6
- package/dest/block_builder/index.d.ts.map +0 -1
- package/dest/block_builder/index.js +0 -1
- package/dest/block_builder/light.d.ts +0 -33
- package/dest/block_builder/light.d.ts.map +0 -1
- package/dest/block_builder/light.js +0 -82
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +0 -14
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +0 -1
- package/dest/proving_broker/proof_store/gcs_proof_store.js +0 -51
- package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
- package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
- package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
- package/src/bin/get-proof-inputs.ts +0 -59
- package/src/block_builder/index.ts +0 -6
- package/src/block_builder/light.ts +0 -101
- package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -72
- package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
|
@@ -1,33 +1,405 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
8
|
-
import {
|
|
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, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, NUM_BASE_PARITY_PER_ROOT_PARITY } from '@aztec/constants';
|
|
375
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
376
|
+
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
377
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
9
378
|
import { AbortError } from '@aztec/foundation/error';
|
|
10
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
11
379
|
import { createLogger } from '@aztec/foundation/log';
|
|
12
380
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
381
|
+
import { SerialQueue } from '@aztec/foundation/queue';
|
|
13
382
|
import { assertLength } from '@aztec/foundation/serialize';
|
|
383
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
14
384
|
import { pushTestData } from '@aztec/foundation/testing';
|
|
15
385
|
import { elapsed } from '@aztec/foundation/timer';
|
|
16
|
-
import {
|
|
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';
|
|
386
|
+
import { BlockRootEmptyTxFirstRollupPrivateInputs, BlockRootFirstRollupPrivateInputs, BlockRootSingleTxFirstRollupPrivateInputs, BlockRootSingleTxRollupPrivateInputs, CheckpointRootSingleBlockRollupPrivateInputs, PrivateTxBaseRollupPrivateInputs } from '@aztec/stdlib/rollup';
|
|
21
387
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
22
|
-
import { toNumBlobFields } from '@aztec/stdlib/tx';
|
|
23
|
-
import { VerificationKeyData } from '@aztec/stdlib/vks';
|
|
24
388
|
import { Attributes, getTelemetryClient, trackSpan, wrapCallbackInSpan } from '@aztec/telemetry-client';
|
|
25
389
|
import { inspect } from 'util';
|
|
26
|
-
import {
|
|
390
|
+
import { buildHeaderFromCircuitOutputs, getLastSiblingPath, getPublicChonkVerifierPrivateInputsFromTx, getRootTreeSiblingPath, getSubtreeSiblingPath, getTreeSnapshot, insertSideEffectsAndBuildBaseRollupHints, validatePartialState, validateTx } from './block-building-helpers.js';
|
|
27
391
|
import { EpochProvingState } from './epoch-proving-state.js';
|
|
28
392
|
import { ProvingOrchestratorMetrics } from './orchestrator_metrics.js';
|
|
29
393
|
import { TxProvingState } from './tx-proving-state.js';
|
|
30
|
-
|
|
394
|
+
_dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
395
|
+
[Attributes.BLOCK_NUMBER]: blockNumber
|
|
396
|
+
})), _dec1 = trackSpan('ProvingOrchestrator.addTxs', (txs)=>({
|
|
397
|
+
[Attributes.BLOCK_TXS_COUNT]: txs.length
|
|
398
|
+
})), _dec2 = trackSpan('ProvingOrchestrator.startChonkVerifierCircuits'), _dec3 = trackSpan('ProvingOrchestrator.setBlockCompleted', (blockNumber)=>({
|
|
399
|
+
[Attributes.BLOCK_NUMBER]: blockNumber
|
|
400
|
+
})), _dec4 = trackSpan('ProvingOrchestrator.prepareBaseRollupInputs', (tx)=>({
|
|
401
|
+
[Attributes.TX_HASH]: tx.hash.toString()
|
|
402
|
+
}));
|
|
31
403
|
/**
|
|
32
404
|
* Implements an event driven proving scheduler to build the recursive proof tree. The idea being:
|
|
33
405
|
* 1. Transactions are provided to the scheduler post simulation.
|
|
@@ -43,20 +415,59 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
43
415
|
dbProvider;
|
|
44
416
|
prover;
|
|
45
417
|
proverId;
|
|
418
|
+
cancelJobsOnStop;
|
|
419
|
+
enqueueConcurrency;
|
|
420
|
+
static{
|
|
421
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
422
|
+
[
|
|
423
|
+
_dec,
|
|
424
|
+
2,
|
|
425
|
+
"startNewBlock"
|
|
426
|
+
],
|
|
427
|
+
[
|
|
428
|
+
_dec1,
|
|
429
|
+
2,
|
|
430
|
+
"addTxs"
|
|
431
|
+
],
|
|
432
|
+
[
|
|
433
|
+
_dec2,
|
|
434
|
+
2,
|
|
435
|
+
"startChonkVerifierCircuits"
|
|
436
|
+
],
|
|
437
|
+
[
|
|
438
|
+
_dec3,
|
|
439
|
+
2,
|
|
440
|
+
"setBlockCompleted"
|
|
441
|
+
],
|
|
442
|
+
[
|
|
443
|
+
_dec4,
|
|
444
|
+
2,
|
|
445
|
+
"prepareBaseRollupInputs"
|
|
446
|
+
]
|
|
447
|
+
], []));
|
|
448
|
+
}
|
|
46
449
|
provingState;
|
|
47
450
|
pendingProvingJobs;
|
|
48
451
|
provingPromise;
|
|
49
452
|
metrics;
|
|
453
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
50
454
|
dbs;
|
|
51
|
-
|
|
455
|
+
logger;
|
|
456
|
+
deferredJobQueue;
|
|
457
|
+
constructor(dbProvider, prover, proverId, cancelJobsOnStop = false, enqueueConcurrency, telemetryClient = getTelemetryClient(), bindings){
|
|
52
458
|
this.dbProvider = dbProvider;
|
|
53
459
|
this.prover = prover;
|
|
54
460
|
this.proverId = proverId;
|
|
55
|
-
this.
|
|
461
|
+
this.cancelJobsOnStop = cancelJobsOnStop;
|
|
462
|
+
this.enqueueConcurrency = enqueueConcurrency;
|
|
463
|
+
this.provingState = (_initProto(this), undefined);
|
|
56
464
|
this.pendingProvingJobs = [];
|
|
57
465
|
this.provingPromise = undefined;
|
|
58
466
|
this.dbs = new Map();
|
|
467
|
+
this.deferredJobQueue = new SerialQueue();
|
|
468
|
+
this.logger = createLogger('prover-client:orchestrator', bindings);
|
|
59
469
|
this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'ProvingOrchestrator');
|
|
470
|
+
this.deferredJobQueue.start(this.enqueueConcurrency);
|
|
60
471
|
}
|
|
61
472
|
get tracer() {
|
|
62
473
|
return this.metrics.tracer;
|
|
@@ -64,85 +475,154 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
64
475
|
getProverId() {
|
|
65
476
|
return this.proverId;
|
|
66
477
|
}
|
|
67
|
-
|
|
478
|
+
getNumActiveForks() {
|
|
479
|
+
return this.dbs.size;
|
|
480
|
+
}
|
|
481
|
+
async stop() {
|
|
482
|
+
// Grab the old queue before cancel() replaces it, so we can await its draining.
|
|
483
|
+
const oldQueue = this.deferredJobQueue;
|
|
68
484
|
this.cancel();
|
|
69
|
-
|
|
485
|
+
await oldQueue.cancel();
|
|
70
486
|
}
|
|
71
|
-
startNewEpoch(epochNumber,
|
|
487
|
+
startNewEpoch(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges) {
|
|
488
|
+
if (this.provingState?.verifyState()) {
|
|
489
|
+
throw new Error(`Cannot start epoch ${epochNumber} when epoch ${this.provingState.epochNumber} is still being processed.`);
|
|
490
|
+
}
|
|
72
491
|
const { promise: _promise, resolve, reject } = promiseWithResolvers();
|
|
73
492
|
const promise = _promise.catch((reason)=>({
|
|
74
493
|
status: 'failure',
|
|
75
494
|
reason
|
|
76
495
|
}));
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
logger.info(`Starting epoch ${epochNumber} with ${totalNumBlocks} blocks`);
|
|
81
|
-
this.provingState = new EpochProvingState(epochNumber, firstBlockNumber, totalNumBlocks, resolve, reject);
|
|
496
|
+
this.logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
497
|
+
this.provingState = new EpochProvingState(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges, (provingState)=>this.checkAndEnqueueCheckpointRootRollup(provingState), resolve, reject);
|
|
82
498
|
this.provingPromise = promise;
|
|
83
499
|
}
|
|
84
500
|
/**
|
|
501
|
+
* Starts a new checkpoint.
|
|
502
|
+
* @param checkpointIndex - The index of the checkpoint in the epoch.
|
|
503
|
+
* @param constants - The constants for this checkpoint.
|
|
504
|
+
* @param l1ToL2Messages - The set of L1 to L2 messages to be inserted at the beginning of this checkpoint.
|
|
505
|
+
* @param totalNumBlocks - The total number of blocks expected in the checkpoint (must be at least one).
|
|
506
|
+
* @param headerOfLastBlockInPreviousCheckpoint - The header of the last block in the previous checkpoint.
|
|
507
|
+
*/ async startNewCheckpoint(checkpointIndex, constants, l1ToL2Messages, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint) {
|
|
508
|
+
if (!this.provingState) {
|
|
509
|
+
throw new Error('Empty epoch proving state. Call startNewEpoch before starting a checkpoint.');
|
|
510
|
+
}
|
|
511
|
+
if (!this.provingState.isAcceptingCheckpoints()) {
|
|
512
|
+
throw new Error(`Epoch not accepting further checkpoints.`);
|
|
513
|
+
}
|
|
514
|
+
// Fork world state at the end of the immediately previous block.
|
|
515
|
+
const lastBlockNumber = headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber;
|
|
516
|
+
const db = await this.dbProvider.fork(lastBlockNumber);
|
|
517
|
+
const firstBlockNumber = BlockNumber(lastBlockNumber + 1);
|
|
518
|
+
this.dbs.set(firstBlockNumber, db);
|
|
519
|
+
// Get archive sibling path before any block in this checkpoint lands.
|
|
520
|
+
const lastArchiveSiblingPath = await getLastSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
521
|
+
// Insert all the l1 to l2 messages into the db. And get the states before and after the insertion.
|
|
522
|
+
const { lastL1ToL2MessageTreeSnapshot, lastL1ToL2MessageSubtreeRootSiblingPath, newL1ToL2MessageTreeSnapshot, newL1ToL2MessageSubtreeRootSiblingPath } = await this.updateL1ToL2MessageTree(l1ToL2Messages, db);
|
|
523
|
+
this.provingState.startNewCheckpoint(checkpointIndex, constants, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint, lastArchiveSiblingPath, l1ToL2Messages, lastL1ToL2MessageTreeSnapshot, lastL1ToL2MessageSubtreeRootSiblingPath, newL1ToL2MessageTreeSnapshot, newL1ToL2MessageSubtreeRootSiblingPath);
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
85
526
|
* Starts off a new block
|
|
86
|
-
* @param
|
|
87
|
-
* @param
|
|
88
|
-
*
|
|
89
|
-
|
|
527
|
+
* @param blockNumber - The block number
|
|
528
|
+
* @param timestamp - The timestamp of the block. This is only required for constructing the private inputs for the
|
|
529
|
+
* block that doesn't have any txs.
|
|
530
|
+
* @param totalNumTxs - The total number of txs in the block
|
|
531
|
+
*/ async startNewBlock(blockNumber, timestamp, totalNumTxs) {
|
|
90
532
|
if (!this.provingState) {
|
|
91
|
-
throw new Error(
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
533
|
+
throw new Error('Empty epoch proving state. Call startNewEpoch before starting a block.');
|
|
534
|
+
}
|
|
535
|
+
const checkpointProvingState = this.provingState.getCheckpointProvingStateByBlockNumber(blockNumber);
|
|
536
|
+
if (!checkpointProvingState) {
|
|
537
|
+
throw new Error(`Checkpoint not started. Call startNewCheckpoint first.`);
|
|
538
|
+
}
|
|
539
|
+
if (!checkpointProvingState.isAcceptingBlocks()) {
|
|
540
|
+
throw new Error(`Checkpoint not accepting further blocks.`);
|
|
541
|
+
}
|
|
542
|
+
const constants = checkpointProvingState.constants;
|
|
543
|
+
this.logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
544
|
+
// Fork the db only when it's not already set. The db for the first block is set in `startNewCheckpoint`.
|
|
545
|
+
if (!this.dbs.has(blockNumber)) {
|
|
546
|
+
// Fork world state at the end of the immediately previous block
|
|
547
|
+
const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
|
|
548
|
+
this.dbs.set(blockNumber, db);
|
|
549
|
+
}
|
|
550
|
+
const db = this.getDbForBlock(blockNumber);
|
|
551
|
+
// Get archive snapshot and sibling path before any txs in this block lands.
|
|
552
|
+
const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
553
|
+
const lastArchiveSiblingPath = await getRootTreeSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
554
|
+
const blockProvingState = checkpointProvingState.startNewBlock(blockNumber, timestamp, totalNumTxs, lastArchiveTreeSnapshot, lastArchiveSiblingPath);
|
|
555
|
+
// Enqueue base parity circuits for the first block in the checkpoint.
|
|
556
|
+
if (blockProvingState.index === 0) {
|
|
557
|
+
for(let i = 0; i < NUM_BASE_PARITY_PER_ROOT_PARITY; i++){
|
|
558
|
+
this.enqueueBaseParityCircuit(checkpointProvingState, blockProvingState, i);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
// Because `addTxs` won't be called for a block without txs, and that's where the sponge blob state is computed.
|
|
562
|
+
// We need to set its end sponge blob here, which will become the start sponge blob for the next block.
|
|
563
|
+
if (totalNumTxs === 0) {
|
|
564
|
+
const endState = await db.getStateReference();
|
|
565
|
+
blockProvingState.setEndState(endState);
|
|
566
|
+
const endSpongeBlob = blockProvingState.getStartSpongeBlob().clone();
|
|
567
|
+
const blockEndBlobFields = blockProvingState.getBlockEndBlobFields();
|
|
568
|
+
await endSpongeBlob.absorb(blockEndBlobFields);
|
|
569
|
+
blockProvingState.setEndSpongeBlob(endSpongeBlob);
|
|
570
|
+
// Try to accumulate the out hashes and blobs as far as we can:
|
|
571
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
572
|
+
await this.provingState.setBlobAccumulators();
|
|
109
573
|
}
|
|
110
574
|
}
|
|
111
575
|
/**
|
|
112
576
|
* The interface to add simulated transactions to the scheduler. This can only be called once per block.
|
|
113
577
|
* @param txs - The transactions to be proven
|
|
114
578
|
*/ async addTxs(txs) {
|
|
579
|
+
if (!this.provingState) {
|
|
580
|
+
throw new Error(`Empty epoch proving state. Call startNewEpoch before adding txs.`);
|
|
581
|
+
}
|
|
115
582
|
if (!txs.length) {
|
|
116
583
|
// To avoid an ugly throw below. If we require an empty block, we can just call setBlockCompleted
|
|
117
584
|
// 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.`);
|
|
585
|
+
this.logger.warn(`Provided no txs to orchestrator addTxs.`);
|
|
119
586
|
return;
|
|
120
587
|
}
|
|
121
|
-
const blockNumber = txs[0].
|
|
122
|
-
const provingState = this.provingState
|
|
588
|
+
const blockNumber = BlockNumber(txs[0].globalVariables.blockNumber);
|
|
589
|
+
const provingState = this.provingState.getBlockProvingStateByBlockNumber(blockNumber);
|
|
123
590
|
if (!provingState) {
|
|
124
|
-
throw new Error(`
|
|
591
|
+
throw new Error(`Proving state for block ${blockNumber} not found. Call startNewBlock first.`);
|
|
592
|
+
}
|
|
593
|
+
if (provingState.totalNumTxs !== txs.length) {
|
|
594
|
+
throw new Error(`Block ${blockNumber} should be filled with ${provingState.totalNumTxs} txs. Received ${txs.length} txs.`);
|
|
125
595
|
}
|
|
126
|
-
if (provingState.
|
|
596
|
+
if (!provingState.isAcceptingTxs()) {
|
|
127
597
|
throw new Error(`Block ${blockNumber} has been initialized with transactions.`);
|
|
128
598
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
599
|
+
this.logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
600
|
+
const db = this.getDbForBlock(blockNumber);
|
|
601
|
+
const lastArchive = provingState.lastArchiveTreeSnapshot;
|
|
602
|
+
const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
|
|
603
|
+
const spongeBlobState = provingState.getStartSpongeBlob().clone();
|
|
132
604
|
for (const tx of txs){
|
|
133
605
|
try {
|
|
134
606
|
if (!provingState.verifyState()) {
|
|
135
607
|
throw new Error(`Invalid proving state when adding a tx`);
|
|
136
608
|
}
|
|
137
609
|
validateTx(tx);
|
|
138
|
-
logger.
|
|
139
|
-
const
|
|
140
|
-
const
|
|
610
|
+
this.logger.debug(`Received transaction: ${tx.hash}`);
|
|
611
|
+
const startSpongeBlob = spongeBlobState.clone();
|
|
612
|
+
const [hints, treeSnapshots] = await this.prepareBaseRollupInputs(tx, lastArchive, newL1ToL2MessageTreeSnapshot, startSpongeBlob, db);
|
|
613
|
+
if (!provingState.verifyState()) {
|
|
614
|
+
throw new Error(`Unable to add transaction, preparing base inputs failed`);
|
|
615
|
+
}
|
|
616
|
+
await spongeBlobState.absorb(tx.txEffect.toBlobFields());
|
|
617
|
+
const txProvingState = new TxProvingState(tx, hints, treeSnapshots, this.proverId.toField());
|
|
141
618
|
const txIndex = provingState.addNewTx(txProvingState);
|
|
142
|
-
this.getOrEnqueueTube(provingState, txIndex);
|
|
143
619
|
if (txProvingState.requireAvmProof) {
|
|
144
|
-
|
|
620
|
+
this.getOrEnqueueChonkVerifier(provingState, txIndex);
|
|
621
|
+
this.logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
145
622
|
this.enqueueVM(provingState, txIndex);
|
|
623
|
+
} else {
|
|
624
|
+
this.logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
625
|
+
this.enqueueBaseRollup(provingState, txIndex);
|
|
146
626
|
}
|
|
147
627
|
} catch (err) {
|
|
148
628
|
throw new Error(`Error adding transaction ${tx.hash.toString()} to block ${blockNumber}: ${err.message}`, {
|
|
@@ -150,22 +630,34 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
150
630
|
});
|
|
151
631
|
}
|
|
152
632
|
}
|
|
633
|
+
const endState = await db.getStateReference();
|
|
634
|
+
provingState.setEndState(endState);
|
|
635
|
+
const blockEndBlobFields = provingState.getBlockEndBlobFields();
|
|
636
|
+
await spongeBlobState.absorb(blockEndBlobFields);
|
|
637
|
+
provingState.setEndSpongeBlob(spongeBlobState);
|
|
638
|
+
// Txs have been added to the block. Now try to accumulate the out hashes and blobs as far as we can:
|
|
639
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
640
|
+
await this.provingState.setBlobAccumulators();
|
|
153
641
|
}
|
|
154
642
|
/**
|
|
155
|
-
* Kickstarts
|
|
156
|
-
* Note that if the
|
|
157
|
-
*/
|
|
643
|
+
* Kickstarts chonk verifier circuits for the specified txs. These will be used during epoch proving.
|
|
644
|
+
* Note that if the chonk verifier circuits are not started this way, they will be started nontheless after processing.
|
|
645
|
+
*/ startChonkVerifierCircuits(txs) {
|
|
158
646
|
if (!this.provingState?.verifyState()) {
|
|
159
|
-
throw new Error(`
|
|
647
|
+
throw new Error(`Empty epoch proving state. call startNewEpoch before starting chonk verifier circuits.`);
|
|
160
648
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const
|
|
649
|
+
const publicTxs = txs.filter((tx)=>tx.data.forPublic);
|
|
650
|
+
for (const tx of publicTxs){
|
|
651
|
+
const txHash = tx.getTxHash().toString();
|
|
652
|
+
const privateInputs = getPublicChonkVerifierPrivateInputsFromTx(tx, this.proverId.toField());
|
|
164
653
|
const tubeProof = promiseWithResolvers();
|
|
165
|
-
logger.debug(`Starting
|
|
166
|
-
this.
|
|
167
|
-
|
|
654
|
+
this.logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
655
|
+
this.doEnqueueChonkVerifier(txHash, privateInputs, (proof)=>{
|
|
656
|
+
tubeProof.resolve(proof);
|
|
657
|
+
});
|
|
658
|
+
this.provingState.cachedChonkVerifierProofs.set(txHash, tubeProof.promise);
|
|
168
659
|
}
|
|
660
|
+
return Promise.resolve();
|
|
169
661
|
}
|
|
170
662
|
/**
|
|
171
663
|
* Marks the block as completed.
|
|
@@ -175,74 +667,114 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
175
667
|
if (!provingState) {
|
|
176
668
|
throw new Error(`Block proving state for ${blockNumber} not found`);
|
|
177
669
|
}
|
|
178
|
-
if
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
670
|
+
// Abort with specific error for the block if there's one.
|
|
671
|
+
const error = provingState.getError();
|
|
672
|
+
if (error) {
|
|
673
|
+
throw new Error(`Block proving failed: ${error}`);
|
|
182
674
|
}
|
|
675
|
+
// Abort if the proving state is not valid due to errors occurred elsewhere.
|
|
183
676
|
if (!provingState.verifyState()) {
|
|
184
|
-
throw new Error(`
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
//
|
|
190
|
-
|
|
191
|
-
|
|
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);
|
|
677
|
+
throw new Error(`Invalid proving state when completing block ${blockNumber}.`);
|
|
678
|
+
}
|
|
679
|
+
if (provingState.isAcceptingTxs()) {
|
|
680
|
+
throw new Error(`Block ${blockNumber} is still accepting txs. Call setBlockCompleted after all txs have been added.`);
|
|
681
|
+
}
|
|
682
|
+
// Given we've applied every change from this block, now assemble the block header:
|
|
683
|
+
this.logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
684
|
+
const header = await provingState.buildBlockHeader();
|
|
208
685
|
if (expectedHeader && !header.equals(expectedHeader)) {
|
|
209
|
-
logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
686
|
+
this.logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
210
687
|
throw new Error('Block header mismatch');
|
|
211
688
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
689
|
+
// Get db for this block and remove from map — no other code should use it after this point.
|
|
690
|
+
const db = this.getDbForBlock(provingState.blockNumber);
|
|
691
|
+
this.dbs.delete(provingState.blockNumber);
|
|
692
|
+
// Update the archive tree, capture the snapshot, and close the fork deterministically.
|
|
693
|
+
try {
|
|
694
|
+
this.logger.verbose(`Updating archive tree with block ${provingState.blockNumber} header ${(await header.hash()).toString()}`);
|
|
695
|
+
await db.updateArchive(header);
|
|
696
|
+
provingState.setBuiltArchive(await getTreeSnapshot(MerkleTreeId.ARCHIVE, db));
|
|
697
|
+
} finally{
|
|
698
|
+
await db.close();
|
|
699
|
+
}
|
|
700
|
+
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
701
|
+
return header;
|
|
220
702
|
}
|
|
221
703
|
// Flagged as protected to disable in certain unit tests
|
|
222
|
-
async verifyBuiltBlockAgainstSyncedState(
|
|
223
|
-
const
|
|
704
|
+
async verifyBuiltBlockAgainstSyncedState(provingState) {
|
|
705
|
+
const builtBlockHeader = provingState.getBuiltBlockHeader();
|
|
706
|
+
if (!builtBlockHeader) {
|
|
707
|
+
this.logger.debug('Block header not built yet, skipping header check.');
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
const output = provingState.getBlockRootRollupOutput();
|
|
711
|
+
if (!output) {
|
|
712
|
+
this.logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
const newArchive = provingState.getBuiltArchive();
|
|
716
|
+
if (!newArchive) {
|
|
717
|
+
this.logger.debug('Archive snapshot not yet captured, skipping header check.');
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
const header = await buildHeaderFromCircuitOutputs(output);
|
|
721
|
+
if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
|
|
722
|
+
this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
723
|
+
provingState.reject(`Block header hash mismatch.`);
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
const blockNumber = provingState.blockNumber;
|
|
727
|
+
const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
|
|
224
728
|
if (!syncedArchive.equals(newArchive)) {
|
|
225
|
-
|
|
729
|
+
this.logger.error(`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(syncedArchive)} but built ${inspect(newArchive)}`);
|
|
730
|
+
provingState.reject(`Archive tree mismatch.`);
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
const circuitArchive = output.newArchive;
|
|
734
|
+
if (!newArchive.equals(circuitArchive)) {
|
|
735
|
+
this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
736
|
+
provingState.reject(`New archive mismatch.`);
|
|
737
|
+
return;
|
|
226
738
|
}
|
|
227
739
|
}
|
|
228
740
|
/**
|
|
229
|
-
* Cancel any further proving
|
|
741
|
+
* Cancel any further proving.
|
|
742
|
+
* If cancelJobsOnStop is true, aborts all pending jobs with the broker (which marks them as 'Aborted').
|
|
743
|
+
* If cancelJobsOnStop is false (default), jobs remain in the broker queue and can be reused on restart/reorg.
|
|
230
744
|
*/ cancel() {
|
|
231
|
-
|
|
232
|
-
|
|
745
|
+
void this.deferredJobQueue.cancel();
|
|
746
|
+
// Recreate the queue so it can accept jobs for subsequent epochs.
|
|
747
|
+
this.deferredJobQueue = new SerialQueue();
|
|
748
|
+
this.deferredJobQueue.start(this.enqueueConcurrency);
|
|
749
|
+
if (this.cancelJobsOnStop) {
|
|
750
|
+
for (const controller of this.pendingProvingJobs){
|
|
751
|
+
controller.abort();
|
|
752
|
+
}
|
|
233
753
|
}
|
|
234
754
|
this.provingState?.cancel();
|
|
755
|
+
for (const [blockNumber, db] of this.dbs.entries()){
|
|
756
|
+
void db.close().catch((err)=>this.logger.error(`Error closing db for block ${blockNumber}`, err));
|
|
757
|
+
}
|
|
758
|
+
this.dbs.clear();
|
|
759
|
+
}
|
|
760
|
+
getDbForBlock(blockNumber) {
|
|
761
|
+
const db = this.dbs.get(blockNumber);
|
|
762
|
+
if (!db) {
|
|
763
|
+
throw new Error(`World state fork for block ${blockNumber} not found.`);
|
|
764
|
+
}
|
|
765
|
+
return db;
|
|
235
766
|
}
|
|
236
767
|
/**
|
|
237
768
|
* Returns the proof for the current epoch.
|
|
238
|
-
*/ async
|
|
769
|
+
*/ async finalizeEpoch() {
|
|
239
770
|
if (!this.provingState || !this.provingPromise) {
|
|
240
|
-
throw new Error(`Invalid proving state, an epoch must be proven before it can be
|
|
771
|
+
throw new Error(`Invalid proving state, an epoch must be proven before it can be finalized`);
|
|
241
772
|
}
|
|
242
773
|
const result = await this.provingPromise;
|
|
243
774
|
if (result.status === 'failure') {
|
|
244
775
|
throw new Error(`Epoch proving failed: ${result.reason}`);
|
|
245
776
|
}
|
|
777
|
+
await this.provingState.finalizeBatchedBlob();
|
|
246
778
|
const epochProofResult = this.provingState.getEpochProofResult();
|
|
247
779
|
pushTestData('epochProofResult', {
|
|
248
780
|
proof: epochProofResult.proof.toString(),
|
|
@@ -251,25 +783,13 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
251
783
|
return epochProofResult;
|
|
252
784
|
}
|
|
253
785
|
/**
|
|
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
786
|
* Enqueue a job to be scheduled
|
|
267
787
|
* @param provingState - The proving state object being operated on
|
|
268
788
|
* @param jobType - The type of job to be queued
|
|
269
789
|
* @param job - The actual job, returns a promise notifying of the job's completion
|
|
270
790
|
*/ deferredProving(provingState, request, callback) {
|
|
271
|
-
if (!provingState
|
|
272
|
-
logger.debug(`Not enqueuing job, state no longer valid`);
|
|
791
|
+
if (!provingState.verifyState()) {
|
|
792
|
+
this.logger.debug(`Not enqueuing job, state no longer valid`);
|
|
273
793
|
return;
|
|
274
794
|
}
|
|
275
795
|
const controller = new AbortController();
|
|
@@ -283,8 +803,8 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
283
803
|
return;
|
|
284
804
|
}
|
|
285
805
|
const result = await request(controller.signal);
|
|
286
|
-
if (!provingState
|
|
287
|
-
logger.debug(`State no longer valid, discarding result`);
|
|
806
|
+
if (!provingState.verifyState()) {
|
|
807
|
+
this.logger.debug(`State no longer valid, discarding result`);
|
|
288
808
|
return;
|
|
289
809
|
}
|
|
290
810
|
// we could have been cancelled whilst waiting for the result
|
|
@@ -299,7 +819,7 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
299
819
|
// drop this result
|
|
300
820
|
return;
|
|
301
821
|
}
|
|
302
|
-
logger.error(`Error thrown when proving job`, err);
|
|
822
|
+
this.logger.error(`Error thrown when proving job`, err);
|
|
303
823
|
provingState.reject(`${err}`);
|
|
304
824
|
} finally{
|
|
305
825
|
const index = this.pendingProvingJobs.indexOf(controller);
|
|
@@ -308,32 +828,32 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
308
828
|
}
|
|
309
829
|
}
|
|
310
830
|
};
|
|
311
|
-
|
|
312
|
-
|
|
831
|
+
void this.deferredJobQueue.put(async ()=>{
|
|
832
|
+
void safeJob();
|
|
833
|
+
// we yield here to the macro task queue such to give Nodejs a chance to run other operatoins in between enqueues
|
|
834
|
+
await sleep(0);
|
|
835
|
+
});
|
|
313
836
|
}
|
|
314
|
-
async
|
|
837
|
+
async updateL1ToL2MessageTree(l1ToL2Messages, db) {
|
|
315
838
|
const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, 'Too many L1 to L2 messages');
|
|
316
|
-
const
|
|
317
|
-
const
|
|
839
|
+
const lastL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
840
|
+
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
841
|
// Update the local trees to include the new l1 to l2 messages
|
|
319
842
|
await db.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
320
|
-
const
|
|
843
|
+
const newL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
844
|
+
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
845
|
return {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
846
|
+
lastL1ToL2MessageTreeSnapshot,
|
|
847
|
+
lastL1ToL2MessageSubtreeRootSiblingPath,
|
|
848
|
+
newL1ToL2MessageTreeSnapshot,
|
|
849
|
+
newL1ToL2MessageSubtreeRootSiblingPath
|
|
325
850
|
};
|
|
326
851
|
}
|
|
327
852
|
// Updates the merkle trees for a transaction. The first enqueued job for a transaction
|
|
328
|
-
async prepareBaseRollupInputs(
|
|
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);
|
|
853
|
+
async prepareBaseRollupInputs(tx, lastArchive, newL1ToL2MessageTreeSnapshot, startSpongeBlob, db) {
|
|
334
854
|
// We build the base rollup inputs using a mock proof and verification key.
|
|
335
|
-
// These will be overwritten later once we have proven the
|
|
336
|
-
const [ms, hints] = await elapsed(
|
|
855
|
+
// These will be overwritten later once we have proven the chonk verifier circuit and any public kernels
|
|
856
|
+
const [ms, hints] = await elapsed(insertSideEffectsAndBuildBaseRollupHints(tx, lastArchive, newL1ToL2MessageTreeSnapshot, startSpongeBlob, this.proverId.toField(), db));
|
|
337
857
|
this.metrics.recordBaseRollupInputs(ms);
|
|
338
858
|
const promises = [
|
|
339
859
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
@@ -349,10 +869,6 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
349
869
|
obj.key,
|
|
350
870
|
obj.value
|
|
351
871
|
]));
|
|
352
|
-
if (!provingState.verifyState()) {
|
|
353
|
-
logger.debug(`Discarding proving job, state no longer valid`);
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
872
|
return [
|
|
357
873
|
hints,
|
|
358
874
|
treeSnapshots
|
|
@@ -362,138 +878,150 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
362
878
|
// Executes the next level of merge if all inputs are available
|
|
363
879
|
enqueueBaseRollup(provingState, txIndex) {
|
|
364
880
|
if (!provingState.verifyState()) {
|
|
365
|
-
logger.debug('Not running base rollup, state invalid');
|
|
881
|
+
this.logger.debug('Not running base rollup, state invalid');
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
if (!provingState.tryStartProvingBase(txIndex)) {
|
|
885
|
+
this.logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
366
886
|
return;
|
|
367
887
|
}
|
|
368
888
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
369
889
|
const { processedTx } = txProvingState;
|
|
370
890
|
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
|
|
891
|
+
this.logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
892
|
+
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, `ProvingOrchestrator.prover.${inputs instanceof PrivateTxBaseRollupPrivateInputs ? 'getPrivateTxBaseRollupProof' : 'getPublicTxBaseRollupProof'}`, {
|
|
373
893
|
[Attributes.TX_HASH]: processedTx.hash.toString(),
|
|
374
|
-
[Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
|
|
375
894
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
376
895
|
}, (signal)=>{
|
|
377
|
-
if (inputs instanceof
|
|
378
|
-
return this.prover.
|
|
896
|
+
if (inputs instanceof PrivateTxBaseRollupPrivateInputs) {
|
|
897
|
+
return this.prover.getPrivateTxBaseRollupProof(inputs, signal, provingState.epochNumber);
|
|
379
898
|
} else {
|
|
380
|
-
return this.prover.
|
|
899
|
+
return this.prover.getPublicTxBaseRollupProof(inputs, signal, provingState.epochNumber);
|
|
381
900
|
}
|
|
382
|
-
}),
|
|
383
|
-
logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
384
|
-
validatePartialState(result.inputs.
|
|
901
|
+
}), (result)=>{
|
|
902
|
+
this.logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
903
|
+
validatePartialState(result.inputs.endTreeSnapshots, txProvingState.treeSnapshots);
|
|
385
904
|
const leafLocation = provingState.setBaseRollupProof(txIndex, result);
|
|
386
905
|
if (provingState.totalNumTxs === 1) {
|
|
387
|
-
|
|
906
|
+
this.checkAndEnqueueBlockRootRollup(provingState);
|
|
388
907
|
} else {
|
|
389
|
-
|
|
908
|
+
this.checkAndEnqueueNextMergeRollup(provingState, leafLocation);
|
|
390
909
|
}
|
|
391
910
|
});
|
|
392
911
|
}
|
|
393
|
-
// Enqueues the
|
|
394
|
-
// Once completed, will enqueue the
|
|
395
|
-
|
|
912
|
+
// Enqueues the public chonk verifier circuit for a given transaction index, or reuses the one already enqueued.
|
|
913
|
+
// Once completed, will enqueue the the public tx base rollup.
|
|
914
|
+
getOrEnqueueChonkVerifier(provingState, txIndex) {
|
|
396
915
|
if (!provingState.verifyState()) {
|
|
397
|
-
logger.debug('Not running
|
|
916
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
398
917
|
return;
|
|
399
918
|
}
|
|
400
919
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
401
920
|
const txHash = txProvingState.processedTx.hash.toString();
|
|
921
|
+
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH;
|
|
402
922
|
const handleResult = (result)=>{
|
|
403
|
-
logger.debug(`Got
|
|
923
|
+
this.logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, {
|
|
404
924
|
txHash
|
|
405
925
|
});
|
|
406
|
-
txProvingState.
|
|
407
|
-
this.provingState?.
|
|
408
|
-
this.
|
|
926
|
+
txProvingState.setPublicChonkVerifierProof(result);
|
|
927
|
+
this.provingState?.cachedChonkVerifierProofs.delete(txHash);
|
|
928
|
+
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
409
929
|
};
|
|
410
|
-
if (this.provingState?.
|
|
411
|
-
logger.debug(`
|
|
930
|
+
if (this.provingState?.cachedChonkVerifierProofs.has(txHash)) {
|
|
931
|
+
this.logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, {
|
|
412
932
|
txHash
|
|
413
933
|
});
|
|
414
|
-
void this.provingState.
|
|
934
|
+
void this.provingState.cachedChonkVerifierProofs.get(txHash).then(handleResult);
|
|
415
935
|
return;
|
|
416
936
|
}
|
|
417
|
-
logger.debug(`Enqueuing
|
|
418
|
-
this.
|
|
937
|
+
this.logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
938
|
+
this.doEnqueueChonkVerifier(txHash, txProvingState.getPublicChonkVerifierPrivateInputs(), handleResult);
|
|
419
939
|
}
|
|
420
|
-
|
|
421
|
-
if (!provingState
|
|
422
|
-
logger.debug('Not running
|
|
940
|
+
doEnqueueChonkVerifier(txHash, inputs, handler, provingState = this.provingState) {
|
|
941
|
+
if (!provingState.verifyState()) {
|
|
942
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
423
943
|
return;
|
|
424
944
|
}
|
|
425
|
-
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.
|
|
945
|
+
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getPublicChonkVerifierProof', {
|
|
426
946
|
[Attributes.TX_HASH]: txHash,
|
|
427
|
-
[Attributes.
|
|
428
|
-
|
|
429
|
-
}, (signal)=>this.prover.getTubeProof(inputs, signal, this.provingState.epochNumber)), handler);
|
|
947
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'chonk-verifier-public'
|
|
948
|
+
}, (signal)=>this.prover.getPublicChonkVerifierProof(inputs, signal, provingState.epochNumber)), handler);
|
|
430
949
|
}
|
|
431
950
|
// Executes the merge rollup circuit and stored the output as intermediate state for the parent merge/block root circuit
|
|
432
951
|
// Enqueues the next level of merge if all inputs are available
|
|
433
952
|
enqueueMergeRollup(provingState, location) {
|
|
434
953
|
if (!provingState.verifyState()) {
|
|
435
|
-
logger.debug('Not running merge rollup. State no longer valid.');
|
|
954
|
+
this.logger.debug('Not running merge rollup. State no longer valid.');
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
if (!provingState.tryStartProvingMerge(location)) {
|
|
958
|
+
this.logger.debug('Merge rollup already started.');
|
|
436
959
|
return;
|
|
437
960
|
}
|
|
438
961
|
const inputs = provingState.getMergeRollupInputs(location);
|
|
439
|
-
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.
|
|
440
|
-
[Attributes.
|
|
441
|
-
|
|
442
|
-
}, (signal)=>this.prover.getMergeRollupProof(inputs, signal, provingState.epochNumber)), async (result)=>{
|
|
962
|
+
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getTxMergeRollupProof', {
|
|
963
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-tx-merge'
|
|
964
|
+
}, (signal)=>this.prover.getTxMergeRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
443
965
|
provingState.setMergeRollupProof(location, result);
|
|
444
|
-
|
|
966
|
+
this.checkAndEnqueueNextMergeRollup(provingState, location);
|
|
445
967
|
});
|
|
446
968
|
}
|
|
447
969
|
// Executes the block root rollup circuit
|
|
448
|
-
|
|
970
|
+
enqueueBlockRootRollup(provingState) {
|
|
449
971
|
if (!provingState.verifyState()) {
|
|
450
|
-
logger.debug('Not running block root rollup, state no longer valid');
|
|
972
|
+
this.logger.debug('Not running block root rollup, state no longer valid');
|
|
451
973
|
return;
|
|
452
974
|
}
|
|
453
|
-
provingState.
|
|
454
|
-
|
|
455
|
-
|
|
975
|
+
if (!provingState.tryStartProvingBlockRoot()) {
|
|
976
|
+
this.logger.debug('Block root rollup already started.');
|
|
977
|
+
return;
|
|
978
|
+
}
|
|
979
|
+
const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs();
|
|
980
|
+
this.logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
456
981
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getBlockRootRollupProof', {
|
|
457
|
-
[Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
|
|
458
982
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
459
983
|
}, (signal)=>{
|
|
460
|
-
if (inputs instanceof
|
|
461
|
-
return this.prover.
|
|
462
|
-
} else if (inputs instanceof
|
|
463
|
-
return this.prover.
|
|
984
|
+
if (inputs instanceof BlockRootFirstRollupPrivateInputs) {
|
|
985
|
+
return this.prover.getBlockRootFirstRollupProof(inputs, signal, provingState.epochNumber);
|
|
986
|
+
} else if (inputs instanceof BlockRootSingleTxFirstRollupPrivateInputs) {
|
|
987
|
+
return this.prover.getBlockRootSingleTxFirstRollupProof(inputs, signal, provingState.epochNumber);
|
|
988
|
+
} else if (inputs instanceof BlockRootEmptyTxFirstRollupPrivateInputs) {
|
|
989
|
+
return this.prover.getBlockRootEmptyTxFirstRollupProof(inputs, signal, provingState.epochNumber);
|
|
990
|
+
} else if (inputs instanceof BlockRootSingleTxRollupPrivateInputs) {
|
|
991
|
+
return this.prover.getBlockRootSingleTxRollupProof(inputs, signal, provingState.epochNumber);
|
|
464
992
|
} else {
|
|
465
993
|
return this.prover.getBlockRootRollupProof(inputs, signal, provingState.epochNumber);
|
|
466
994
|
}
|
|
467
995
|
}), async (result)=>{
|
|
468
|
-
provingState.
|
|
469
|
-
const
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
const epochProvingState = this.provingState;
|
|
477
|
-
const leafLocation = epochProvingState.setBlockRootRollupProof(provingState.index, result);
|
|
478
|
-
if (epochProvingState.totalNumBlocks === 1) {
|
|
479
|
-
await this.enqueueEpochPadding(epochProvingState);
|
|
996
|
+
this.logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
|
|
997
|
+
const leafLocation = provingState.setBlockRootRollupProof(result);
|
|
998
|
+
const checkpointProvingState = provingState.parentCheckpoint;
|
|
999
|
+
// Verification is called from both here and setBlockCompleted. Whichever runs last
|
|
1000
|
+
// will be the first to see all three pieces (header, proof output, archive) and run the checks.
|
|
1001
|
+
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
1002
|
+
if (checkpointProvingState.totalNumBlocks === 1) {
|
|
1003
|
+
await this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
480
1004
|
} else {
|
|
481
|
-
this.checkAndEnqueueNextBlockMergeRollup(
|
|
1005
|
+
await this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
482
1006
|
}
|
|
483
1007
|
});
|
|
484
1008
|
}
|
|
485
1009
|
// Executes the base parity circuit and stores the intermediate state for the root parity circuit
|
|
486
1010
|
// Enqueues the root parity circuit if all inputs are available
|
|
487
|
-
enqueueBaseParityCircuit(
|
|
1011
|
+
enqueueBaseParityCircuit(checkpointProvingState, provingState, baseParityIndex) {
|
|
488
1012
|
if (!provingState.verifyState()) {
|
|
489
|
-
logger.debug('Not running base parity. State no longer valid.');
|
|
1013
|
+
this.logger.debug('Not running base parity. State no longer valid.');
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
if (!provingState.tryStartProvingBaseParity(baseParityIndex)) {
|
|
1017
|
+
this.logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
490
1018
|
return;
|
|
491
1019
|
}
|
|
1020
|
+
const inputs = checkpointProvingState.getBaseParityInputs(baseParityIndex);
|
|
492
1021
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getBaseParityProof', {
|
|
493
|
-
[Attributes.
|
|
494
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'base-parity'
|
|
1022
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'parity-base'
|
|
495
1023
|
}, (signal)=>this.prover.getBaseParityProof(inputs, signal, provingState.epochNumber)), (provingOutput)=>{
|
|
496
|
-
provingState.setBaseParityProof(
|
|
1024
|
+
provingState.setBaseParityProof(baseParityIndex, provingOutput);
|
|
497
1025
|
this.checkAndEnqueueRootParityCircuit(provingState);
|
|
498
1026
|
});
|
|
499
1027
|
}
|
|
@@ -507,112 +1035,182 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
507
1035
|
// Enqueues the root rollup proof if all inputs are available
|
|
508
1036
|
enqueueRootParityCircuit(provingState) {
|
|
509
1037
|
if (!provingState.verifyState()) {
|
|
510
|
-
logger.debug('Not running root parity. State no longer valid.');
|
|
1038
|
+
this.logger.debug('Not running root parity. State no longer valid.');
|
|
511
1039
|
return;
|
|
512
1040
|
}
|
|
513
|
-
|
|
1041
|
+
if (!provingState.tryStartProvingRootParity()) {
|
|
1042
|
+
this.logger.debug('Root parity already started.');
|
|
1043
|
+
return;
|
|
1044
|
+
}
|
|
1045
|
+
const inputs = provingState.getParityRootInputs();
|
|
514
1046
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getRootParityProof', {
|
|
515
|
-
[Attributes.
|
|
516
|
-
|
|
517
|
-
}, (signal)=>this.prover.getRootParityProof(inputs, signal, provingState.epochNumber)), async (result)=>{
|
|
1047
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'parity-root'
|
|
1048
|
+
}, (signal)=>this.prover.getRootParityProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
518
1049
|
provingState.setRootParityProof(result);
|
|
519
|
-
|
|
1050
|
+
this.checkAndEnqueueBlockRootRollup(provingState);
|
|
520
1051
|
});
|
|
521
1052
|
}
|
|
522
1053
|
// Executes the block merge rollup circuit and stored the output as intermediate state for the parent merge/block root circuit
|
|
523
1054
|
// Enqueues the next level of merge if all inputs are available
|
|
524
1055
|
enqueueBlockMergeRollup(provingState, location) {
|
|
525
1056
|
if (!provingState.verifyState()) {
|
|
526
|
-
logger.debug('Not running block merge rollup. State no longer valid.');
|
|
1057
|
+
this.logger.debug('Not running block merge rollup. State no longer valid.');
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
if (!provingState.tryStartProvingBlockMerge(location)) {
|
|
1061
|
+
this.logger.debug('Block merge rollup already started.');
|
|
527
1062
|
return;
|
|
528
1063
|
}
|
|
529
1064
|
const inputs = provingState.getBlockMergeRollupInputs(location);
|
|
530
1065
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getBlockMergeRollupProof', {
|
|
531
|
-
[Attributes.
|
|
532
|
-
|
|
533
|
-
}, (signal)=>this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
1066
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-block-merge'
|
|
1067
|
+
}, (signal)=>this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber)), async (result)=>{
|
|
534
1068
|
provingState.setBlockMergeRollupProof(location, result);
|
|
535
|
-
this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
1069
|
+
await this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
async enqueueCheckpointRootRollup(provingState) {
|
|
1073
|
+
if (!provingState.verifyState()) {
|
|
1074
|
+
this.logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
if (!provingState.tryStartProvingCheckpointRoot()) {
|
|
1078
|
+
this.logger.debug('Checkpoint root rollup already started.');
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
const rollupType = provingState.getCheckpointRootRollupType();
|
|
1082
|
+
this.logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
1083
|
+
const inputs = await provingState.getCheckpointRootRollupInputs();
|
|
1084
|
+
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointRootRollupProof', {
|
|
1085
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
1086
|
+
}, (signal)=>{
|
|
1087
|
+
if (inputs instanceof CheckpointRootSingleBlockRollupPrivateInputs) {
|
|
1088
|
+
return this.prover.getCheckpointRootSingleBlockRollupProof(inputs, signal, provingState.epochNumber);
|
|
1089
|
+
} else {
|
|
1090
|
+
return this.prover.getCheckpointRootRollupProof(inputs, signal, provingState.epochNumber);
|
|
1091
|
+
}
|
|
1092
|
+
}), (result)=>{
|
|
1093
|
+
const computedEndBlobAccumulatorState = provingState.getEndBlobAccumulator().toBlobAccumulator();
|
|
1094
|
+
const circuitEndBlobAccumulatorState = result.inputs.endBlobAccumulator;
|
|
1095
|
+
if (!circuitEndBlobAccumulatorState.equals(computedEndBlobAccumulatorState)) {
|
|
1096
|
+
this.logger.error(`Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(computedEndBlobAccumulatorState)}`);
|
|
1097
|
+
provingState.reject(`Blob accumulator state mismatch.`);
|
|
1098
|
+
return;
|
|
1099
|
+
}
|
|
1100
|
+
this.logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
|
|
1101
|
+
const leafLocation = provingState.setCheckpointRootRollupProof(result);
|
|
1102
|
+
const epochProvingState = provingState.parentEpoch;
|
|
1103
|
+
if (epochProvingState.totalNumCheckpoints === 1) {
|
|
1104
|
+
this.enqueueEpochPadding(epochProvingState);
|
|
1105
|
+
} else {
|
|
1106
|
+
this.checkAndEnqueueNextCheckpointMergeRollup(epochProvingState, leafLocation);
|
|
1107
|
+
}
|
|
536
1108
|
});
|
|
537
1109
|
}
|
|
538
|
-
|
|
1110
|
+
enqueueCheckpointMergeRollup(provingState, location) {
|
|
539
1111
|
if (!provingState.verifyState()) {
|
|
540
|
-
logger.debug('Not running
|
|
1112
|
+
this.logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
541
1113
|
return;
|
|
542
1114
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
1115
|
+
if (!provingState.tryStartProvingCheckpointMerge(location)) {
|
|
1116
|
+
this.logger.debug('Checkpoint merge rollup already started.');
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
const inputs = provingState.getCheckpointMergeRollupInputs(location);
|
|
1120
|
+
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointMergeRollupProof', {
|
|
1121
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-merge'
|
|
1122
|
+
}, (signal)=>this.prover.getCheckpointMergeRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
1123
|
+
this.logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1124
|
+
provingState.setCheckpointMergeRollupProof(location, result);
|
|
1125
|
+
this.checkAndEnqueueNextCheckpointMergeRollup(provingState, location);
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
enqueueEpochPadding(provingState) {
|
|
1129
|
+
if (!provingState.verifyState()) {
|
|
1130
|
+
this.logger.debug('Not running epoch padding. State no longer valid.');
|
|
1131
|
+
return;
|
|
1132
|
+
}
|
|
1133
|
+
if (!provingState.tryStartProvingPaddingCheckpoint()) {
|
|
1134
|
+
this.logger.debug('Padding checkpoint already started.');
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
this.logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1138
|
+
const inputs = provingState.getPaddingCheckpointInputs();
|
|
1139
|
+
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointPaddingRollupProof', {
|
|
1140
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-padding'
|
|
1141
|
+
}, (signal)=>this.prover.getCheckpointPaddingRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
1142
|
+
this.logger.debug('Completed proof for padding checkpoint.');
|
|
1143
|
+
provingState.setCheckpointPaddingProof(result);
|
|
551
1144
|
this.checkAndEnqueueRootRollup(provingState);
|
|
552
1145
|
});
|
|
553
1146
|
}
|
|
554
1147
|
// Executes the root rollup circuit
|
|
555
1148
|
enqueueRootRollup(provingState) {
|
|
556
1149
|
if (!provingState.verifyState()) {
|
|
557
|
-
logger.debug('Not running root rollup, state no longer valid');
|
|
1150
|
+
this.logger.debug('Not running root rollup, state no longer valid');
|
|
558
1151
|
return;
|
|
559
1152
|
}
|
|
560
|
-
logger.debug(`Preparing root rollup`);
|
|
561
|
-
const inputs = provingState.getRootRollupInputs(
|
|
1153
|
+
this.logger.debug(`Preparing root rollup`);
|
|
1154
|
+
const inputs = provingState.getRootRollupInputs();
|
|
562
1155
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getRootRollupProof', {
|
|
563
|
-
[Attributes.
|
|
564
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'root-rollup'
|
|
1156
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-root'
|
|
565
1157
|
}, (signal)=>this.prover.getRootRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
566
|
-
logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
1158
|
+
this.logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
567
1159
|
provingState.setRootRollupProof(result);
|
|
568
1160
|
provingState.resolve({
|
|
569
1161
|
status: 'success'
|
|
570
1162
|
});
|
|
571
1163
|
});
|
|
572
1164
|
}
|
|
573
|
-
|
|
1165
|
+
checkAndEnqueueNextMergeRollup(provingState, currentLocation) {
|
|
574
1166
|
if (!provingState.isReadyForMergeRollup(currentLocation)) {
|
|
575
1167
|
return;
|
|
576
1168
|
}
|
|
577
1169
|
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
578
1170
|
if (parentLocation.level === 0) {
|
|
579
|
-
|
|
1171
|
+
this.checkAndEnqueueBlockRootRollup(provingState);
|
|
580
1172
|
} else {
|
|
581
1173
|
this.enqueueMergeRollup(provingState, parentLocation);
|
|
582
1174
|
}
|
|
583
1175
|
}
|
|
584
|
-
|
|
1176
|
+
checkAndEnqueueBlockRootRollup(provingState) {
|
|
585
1177
|
if (!provingState.isReadyForBlockRootRollup()) {
|
|
586
|
-
logger.debug('Not ready for root rollup');
|
|
1178
|
+
this.logger.debug('Not ready for block root rollup');
|
|
587
1179
|
return;
|
|
588
1180
|
}
|
|
589
|
-
|
|
590
|
-
|
|
1181
|
+
this.enqueueBlockRootRollup(provingState);
|
|
1182
|
+
}
|
|
1183
|
+
async checkAndEnqueueNextBlockMergeRollup(provingState, currentLocation) {
|
|
1184
|
+
if (!provingState.isReadyForBlockMerge(currentLocation)) {
|
|
591
1185
|
return;
|
|
592
1186
|
}
|
|
593
|
-
const
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
1187
|
+
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
1188
|
+
if (parentLocation.level === 0) {
|
|
1189
|
+
await this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
1190
|
+
} else {
|
|
1191
|
+
this.enqueueBlockMergeRollup(provingState, parentLocation);
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
async checkAndEnqueueCheckpointRootRollup(provingState) {
|
|
1195
|
+
if (!provingState.isReadyForCheckpointRoot()) {
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
1198
|
+
await this.enqueueCheckpointRootRollup(provingState);
|
|
1199
|
+
}
|
|
1200
|
+
checkAndEnqueueNextCheckpointMergeRollup(provingState, currentLocation) {
|
|
1201
|
+
if (!provingState.isReadyForCheckpointMerge(currentLocation)) {
|
|
604
1202
|
return;
|
|
605
1203
|
}
|
|
606
1204
|
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
607
1205
|
if (parentLocation.level === 0) {
|
|
608
1206
|
this.checkAndEnqueueRootRollup(provingState);
|
|
609
1207
|
} else {
|
|
610
|
-
this.
|
|
1208
|
+
this.enqueueCheckpointMergeRollup(provingState, parentLocation);
|
|
611
1209
|
}
|
|
612
1210
|
}
|
|
613
1211
|
checkAndEnqueueRootRollup(provingState) {
|
|
614
1212
|
if (!provingState.isReadyForRootRollup()) {
|
|
615
|
-
logger.debug('Not ready for root rollup');
|
|
1213
|
+
this.logger.debug('Not ready for root rollup');
|
|
616
1214
|
return;
|
|
617
1215
|
}
|
|
618
1216
|
this.enqueueRootRollup(provingState);
|
|
@@ -624,67 +1222,29 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
624
1222
|
* @param txIndex - The index of the transaction being proven
|
|
625
1223
|
*/ enqueueVM(provingState, txIndex) {
|
|
626
1224
|
if (!provingState.verifyState()) {
|
|
627
|
-
logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1225
|
+
this.logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
628
1226
|
return;
|
|
629
1227
|
}
|
|
630
1228
|
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
1229
|
const doAvmProving = wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getAvmProof', {
|
|
634
1230
|
[Attributes.TX_HASH]: txProvingState.processedTx.hash.toString()
|
|
635
1231
|
}, async (signal)=>{
|
|
636
1232
|
const inputs = txProvingState.getAvmInputs();
|
|
637
|
-
|
|
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
|
-
}
|
|
1233
|
+
return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
|
|
651
1234
|
});
|
|
652
|
-
this.deferredProving(provingState, doAvmProving, (
|
|
653
|
-
logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
654
|
-
txProvingState.setAvmProof(
|
|
655
|
-
this.
|
|
1235
|
+
this.deferredProving(provingState, doAvmProving, (proof)=>{
|
|
1236
|
+
this.logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1237
|
+
txProvingState.setAvmProof(proof);
|
|
1238
|
+
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
656
1239
|
});
|
|
657
1240
|
}
|
|
658
|
-
|
|
1241
|
+
checkAndEnqueueBaseRollup(provingState, txIndex) {
|
|
659
1242
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
660
1243
|
if (!txProvingState.ready()) {
|
|
661
1244
|
return;
|
|
662
1245
|
}
|
|
663
|
-
// We must have completed all proving (
|
|
664
|
-
logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1246
|
+
// We must have completed all proving (chonk verifier proof and (if required) vm proof are generated), we now move to the base rollup.
|
|
1247
|
+
this.logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
665
1248
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
666
1249
|
}
|
|
667
1250
|
}
|
|
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);
|