@aztec/prover-client 0.0.1-commit.b655e406 → 0.0.1-commit.b9865e97
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 +2 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +17 -3
- 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 +231 -0
- package/dest/mocks/fixtures.d.ts +1 -4
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +9 -18
- package/dest/mocks/test_context.d.ts +31 -46
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +133 -123
- package/dest/orchestrator/block-building-helpers.d.ts +18 -20
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +90 -115
- package/dest/orchestrator/block-proving-state.d.ts +20 -11
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +87 -19
- package/dest/orchestrator/checkpoint-proving-state.d.ts +29 -9
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +62 -21
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +107 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.js +151 -0
- package/dest/orchestrator/epoch-proving-context.d.ts +51 -0
- package/dest/orchestrator/epoch-proving-context.d.ts.map +1 -0
- package/dest/orchestrator/epoch-proving-context.js +81 -0
- package/dest/orchestrator/epoch-proving-state.d.ts +12 -10
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +40 -4
- package/dest/orchestrator/index.d.ts +4 -1
- package/dest/orchestrator/index.d.ts.map +1 -1
- package/dest/orchestrator/index.js +3 -0
- package/dest/orchestrator/orchestrator.d.ts +37 -32
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +568 -303
- package/dest/orchestrator/orchestrator_metrics.d.ts +1 -3
- package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator_metrics.js +2 -15
- package/dest/orchestrator/proving-scheduler.d.ts +72 -0
- package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
- package/dest/orchestrator/proving-scheduler.js +117 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts +83 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-orchestrator.js +182 -0
- package/dest/orchestrator/top-tree-proving-scheduler.d.ts +62 -0
- package/dest/orchestrator/top-tree-proving-scheduler.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-proving-scheduler.js +73 -0
- package/dest/orchestrator/top-tree-proving-state.d.ts +61 -0
- package/dest/orchestrator/top-tree-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-proving-state.js +185 -0
- package/dest/orchestrator/tx-proving-state.d.ts +6 -5
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +7 -16
- 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 +66 -7
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +64 -11
- package/dest/prover-client/server-epoch-prover.d.ts +8 -7
- package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
- package/dest/prover-client/server-epoch-prover.js +2 -2
- package/dest/proving_broker/broker_prover_facade.d.ts +25 -23
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +21 -33
- package/dest/proving_broker/config.d.ts +14 -62
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +29 -6
- package/dest/proving_broker/factory.d.ts +1 -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 +2 -1
- package/dest/proving_broker/index.d.ts.map +1 -1
- package/dest/proving_broker/index.js +1 -0
- 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 -2
- package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/index.js +1 -1
- 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 +5 -9
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.js +4 -19
- package/dest/proving_broker/proving_broker.d.ts +8 -5
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +74 -22
- 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/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 +394 -5
- 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 +5 -3
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.js +8 -6
- package/dest/proving_broker/rpc.d.ts +9 -5
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +87 -23
- package/dest/test/mock_proof_store.d.ts +1 -1
- package/dest/test/mock_proof_store.d.ts.map +1 -1
- package/dest/test/mock_prover.d.ts +5 -6
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +4 -4
- package/package.json +23 -22
- package/src/config.ts +19 -3
- package/src/light/index.ts +1 -0
- package/src/light/lightweight_checkpoint_builder.ts +320 -0
- package/src/mocks/fixtures.ts +9 -31
- package/src/mocks/test_context.ts +170 -185
- package/src/orchestrator/block-building-helpers.ts +129 -209
- package/src/orchestrator/block-proving-state.ts +109 -22
- package/src/orchestrator/checkpoint-proving-state.ts +89 -26
- package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +271 -0
- package/src/orchestrator/epoch-proving-context.ts +101 -0
- package/src/orchestrator/epoch-proving-state.ts +67 -15
- package/src/orchestrator/index.ts +8 -0
- package/src/orchestrator/orchestrator.ts +193 -354
- package/src/orchestrator/orchestrator_metrics.ts +2 -25
- package/src/orchestrator/proving-scheduler.ts +156 -0
- package/src/orchestrator/top-tree-orchestrator.ts +314 -0
- package/src/orchestrator/top-tree-proving-scheduler.ts +154 -0
- package/src/orchestrator/top-tree-proving-state.ts +220 -0
- package/src/orchestrator/tx-proving-state.ts +10 -27
- package/src/prover-client/factory.ts +6 -2
- package/src/prover-client/prover-client.ts +157 -24
- package/src/prover-client/server-epoch-prover.ts +6 -7
- package/src/proving_broker/broker_prover_facade.ts +46 -55
- package/src/proving_broker/config.ts +33 -3
- package/src/proving_broker/fixtures.ts +8 -3
- package/src/proving_broker/index.ts +1 -0
- 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 -1
- package/src/proving_broker/proving_agent.ts +6 -19
- package/src/proving_broker/proving_broker.ts +70 -17
- package/src/proving_broker/proving_broker_database/memory.ts +2 -1
- package/src/proving_broker/proving_broker_database/persisted.ts +22 -7
- 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 +13 -7
- package/src/proving_broker/rpc.ts +46 -20
- package/src/test/mock_prover.ts +2 -14
- package/dest/block-factory/index.d.ts +0 -2
- package/dest/block-factory/index.d.ts.map +0 -1
- package/dest/block-factory/index.js +0 -1
- package/dest/block-factory/light.d.ts +0 -38
- package/dest/block-factory/light.d.ts.map +0 -1
- package/dest/block-factory/light.js +0 -94
- 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 -52
- 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/block-factory/index.ts +0 -1
- package/src/block-factory/light.ts +0 -140
- package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
- package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
|
@@ -1,29 +1,401 @@
|
|
|
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 {
|
|
9
|
-
import {
|
|
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 {
|
|
17
|
-
import { createBlockEndMarker } from '@aztec/stdlib/block';
|
|
380
|
+
import { appendL1ToL2MessagesToTree } from '@aztec/stdlib/messaging';
|
|
18
381
|
import { BlockRootEmptyTxFirstRollupPrivateInputs, BlockRootFirstRollupPrivateInputs, BlockRootSingleTxFirstRollupPrivateInputs, BlockRootSingleTxRollupPrivateInputs, CheckpointRootSingleBlockRollupPrivateInputs, PrivateTxBaseRollupPrivateInputs } from '@aztec/stdlib/rollup';
|
|
19
382
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
20
383
|
import { Attributes, getTelemetryClient, trackSpan, wrapCallbackInSpan } from '@aztec/telemetry-client';
|
|
21
384
|
import { inspect } from 'util';
|
|
22
|
-
import {
|
|
385
|
+
import { buildHeaderFromCircuitOutputs, getLastSiblingPath, getPublicChonkVerifierPrivateInputsFromTx, getRootTreeSiblingPath, getSubtreeSiblingPath, getTreeSnapshot, insertSideEffectsAndBuildBaseRollupHints, validatePartialState, validateTx } from './block-building-helpers.js';
|
|
23
386
|
import { EpochProvingState } from './epoch-proving-state.js';
|
|
24
387
|
import { ProvingOrchestratorMetrics } from './orchestrator_metrics.js';
|
|
388
|
+
import { TopTreeProvingScheduler } from './top-tree-proving-scheduler.js';
|
|
25
389
|
import { TxProvingState } from './tx-proving-state.js';
|
|
26
|
-
|
|
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
|
+
}));
|
|
27
399
|
/**
|
|
28
400
|
* Implements an event driven proving scheduler to build the recursive proof tree. The idea being:
|
|
29
401
|
* 1. Transactions are provided to the scheduler post simulation.
|
|
@@ -35,23 +407,45 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
35
407
|
* The proving implementation is determined by the provided prover. This could be for example a local prover or a remote prover pool.
|
|
36
408
|
*/ /**
|
|
37
409
|
* The orchestrator, managing the flow of recursive proving operations required to build the rollup proof tree.
|
|
38
|
-
*/ export class ProvingOrchestrator {
|
|
410
|
+
*/ export class ProvingOrchestrator extends TopTreeProvingScheduler {
|
|
39
411
|
dbProvider;
|
|
40
|
-
prover;
|
|
41
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
|
+
}
|
|
42
443
|
provingState;
|
|
43
|
-
pendingProvingJobs;
|
|
44
444
|
provingPromise;
|
|
45
445
|
metrics;
|
|
46
446
|
dbs;
|
|
47
|
-
constructor(dbProvider, prover, proverId, telemetryClient = getTelemetryClient()){
|
|
48
|
-
this.dbProvider = dbProvider;
|
|
49
|
-
this.prover = prover;
|
|
50
|
-
this.proverId = proverId;
|
|
51
|
-
this.provingState = undefined;
|
|
52
|
-
this.pendingProvingJobs = [];
|
|
53
|
-
this.provingPromise = undefined;
|
|
54
|
-
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();
|
|
55
449
|
this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'ProvingOrchestrator');
|
|
56
450
|
}
|
|
57
451
|
get tracer() {
|
|
@@ -60,9 +454,21 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
60
454
|
getProverId() {
|
|
61
455
|
return this.proverId;
|
|
62
456
|
}
|
|
63
|
-
|
|
457
|
+
getNumActiveForks() {
|
|
458
|
+
return this.dbs.size;
|
|
459
|
+
}
|
|
460
|
+
cancelInternal() {
|
|
64
461
|
this.cancel();
|
|
65
|
-
|
|
462
|
+
}
|
|
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
|
+
});
|
|
66
472
|
}
|
|
67
473
|
startNewEpoch(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges) {
|
|
68
474
|
if (this.provingState?.verifyState()) {
|
|
@@ -73,11 +479,18 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
73
479
|
status: 'failure',
|
|
74
480
|
reason
|
|
75
481
|
}));
|
|
76
|
-
logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
482
|
+
this.logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
77
483
|
this.provingState = new EpochProvingState(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges, (provingState)=>this.checkAndEnqueueCheckpointRootRollup(provingState), resolve, reject);
|
|
78
484
|
this.provingPromise = promise;
|
|
79
485
|
}
|
|
80
|
-
|
|
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) {
|
|
81
494
|
if (!this.provingState) {
|
|
82
495
|
throw new Error('Empty epoch proving state. Call startNewEpoch before starting a checkpoint.');
|
|
83
496
|
}
|
|
@@ -87,13 +500,13 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
87
500
|
// Fork world state at the end of the immediately previous block.
|
|
88
501
|
const lastBlockNumber = headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber;
|
|
89
502
|
const db = await this.dbProvider.fork(lastBlockNumber);
|
|
90
|
-
const firstBlockNumber = lastBlockNumber + 1;
|
|
503
|
+
const firstBlockNumber = BlockNumber(lastBlockNumber + 1);
|
|
91
504
|
this.dbs.set(firstBlockNumber, db);
|
|
92
505
|
// Get archive sibling path before any block in this checkpoint lands.
|
|
93
506
|
const lastArchiveSiblingPath = await getLastSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
94
507
|
// Insert all the l1 to l2 messages into the db. And get the states before and after the insertion.
|
|
95
508
|
const { lastL1ToL2MessageTreeSnapshot, lastL1ToL2MessageSubtreeRootSiblingPath, newL1ToL2MessageTreeSnapshot, newL1ToL2MessageSubtreeRootSiblingPath } = await this.updateL1ToL2MessageTree(l1ToL2Messages, db);
|
|
96
|
-
this.provingState.startNewCheckpoint(checkpointIndex, constants, totalNumBlocks,
|
|
509
|
+
this.provingState.startNewCheckpoint(checkpointIndex, constants, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint, lastArchiveSiblingPath, l1ToL2Messages, lastL1ToL2MessageTreeSnapshot, lastL1ToL2MessageSubtreeRootSiblingPath, newL1ToL2MessageTreeSnapshot, newL1ToL2MessageSubtreeRootSiblingPath);
|
|
97
510
|
}
|
|
98
511
|
/**
|
|
99
512
|
* Starts off a new block
|
|
@@ -113,18 +526,18 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
113
526
|
throw new Error(`Checkpoint not accepting further blocks.`);
|
|
114
527
|
}
|
|
115
528
|
const constants = checkpointProvingState.constants;
|
|
116
|
-
logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber
|
|
529
|
+
this.logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
117
530
|
// Fork the db only when it's not already set. The db for the first block is set in `startNewCheckpoint`.
|
|
118
531
|
if (!this.dbs.has(blockNumber)) {
|
|
119
532
|
// Fork world state at the end of the immediately previous block
|
|
120
|
-
const db = await this.dbProvider.fork(blockNumber - 1);
|
|
533
|
+
const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
|
|
121
534
|
this.dbs.set(blockNumber, db);
|
|
122
535
|
}
|
|
123
|
-
const db = this.
|
|
536
|
+
const db = this.getDbForBlock(blockNumber);
|
|
124
537
|
// Get archive snapshot and sibling path before any txs in this block lands.
|
|
125
538
|
const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
126
539
|
const lastArchiveSiblingPath = await getRootTreeSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
127
|
-
const blockProvingState =
|
|
540
|
+
const blockProvingState = checkpointProvingState.startNewBlock(blockNumber, timestamp, totalNumTxs, lastArchiveTreeSnapshot, lastArchiveSiblingPath);
|
|
128
541
|
// Enqueue base parity circuits for the first block in the checkpoint.
|
|
129
542
|
if (blockProvingState.index === 0) {
|
|
130
543
|
for(let i = 0; i < NUM_BASE_PARITY_PER_ROOT_PARITY; i++){
|
|
@@ -134,12 +547,14 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
134
547
|
// Because `addTxs` won't be called for a block without txs, and that's where the sponge blob state is computed.
|
|
135
548
|
// We need to set its end sponge blob here, which will become the start sponge blob for the next block.
|
|
136
549
|
if (totalNumTxs === 0) {
|
|
550
|
+
const endState = await db.getStateReference();
|
|
551
|
+
blockProvingState.setEndState(endState);
|
|
137
552
|
const endSpongeBlob = blockProvingState.getStartSpongeBlob().clone();
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
]);
|
|
553
|
+
const blockEndBlobFields = blockProvingState.getBlockEndBlobFields();
|
|
554
|
+
await endSpongeBlob.absorb(blockEndBlobFields);
|
|
141
555
|
blockProvingState.setEndSpongeBlob(endSpongeBlob);
|
|
142
|
-
//
|
|
556
|
+
// Try to accumulate the out hashes and blobs as far as we can:
|
|
557
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
143
558
|
await this.provingState.setBlobAccumulators();
|
|
144
559
|
}
|
|
145
560
|
}
|
|
@@ -153,10 +568,10 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
153
568
|
if (!txs.length) {
|
|
154
569
|
// To avoid an ugly throw below. If we require an empty block, we can just call setBlockCompleted
|
|
155
570
|
// on a block with no txs. We cannot do that here because we cannot find the blockNumber without any txs.
|
|
156
|
-
logger.warn(`Provided no txs to orchestrator addTxs.`);
|
|
571
|
+
this.logger.warn(`Provided no txs to orchestrator addTxs.`);
|
|
157
572
|
return;
|
|
158
573
|
}
|
|
159
|
-
const blockNumber = txs[0].globalVariables.blockNumber;
|
|
574
|
+
const blockNumber = BlockNumber(txs[0].globalVariables.blockNumber);
|
|
160
575
|
const provingState = this.provingState.getBlockProvingStateByBlockNumber(blockNumber);
|
|
161
576
|
if (!provingState) {
|
|
162
577
|
throw new Error(`Proving state for block ${blockNumber} not found. Call startNewBlock first.`);
|
|
@@ -167,8 +582,8 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
167
582
|
if (!provingState.isAcceptingTxs()) {
|
|
168
583
|
throw new Error(`Block ${blockNumber} has been initialized with transactions.`);
|
|
169
584
|
}
|
|
170
|
-
logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
171
|
-
const db = this.
|
|
585
|
+
this.logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
586
|
+
const db = this.getDbForBlock(blockNumber);
|
|
172
587
|
const lastArchive = provingState.lastArchiveTreeSnapshot;
|
|
173
588
|
const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
|
|
174
589
|
const spongeBlobState = provingState.getStartSpongeBlob().clone();
|
|
@@ -178,7 +593,7 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
178
593
|
throw new Error(`Invalid proving state when adding a tx`);
|
|
179
594
|
}
|
|
180
595
|
validateTx(tx);
|
|
181
|
-
logger.
|
|
596
|
+
this.logger.debug(`Received transaction: ${tx.hash}`);
|
|
182
597
|
const startSpongeBlob = spongeBlobState.clone();
|
|
183
598
|
const [hints, treeSnapshots] = await this.prepareBaseRollupInputs(tx, lastArchive, newL1ToL2MessageTreeSnapshot, startSpongeBlob, db);
|
|
184
599
|
if (!provingState.verifyState()) {
|
|
@@ -189,10 +604,10 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
189
604
|
const txIndex = provingState.addNewTx(txProvingState);
|
|
190
605
|
if (txProvingState.requireAvmProof) {
|
|
191
606
|
this.getOrEnqueueChonkVerifier(provingState, txIndex);
|
|
192
|
-
logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
607
|
+
this.logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
193
608
|
this.enqueueVM(provingState, txIndex);
|
|
194
609
|
} else {
|
|
195
|
-
logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
610
|
+
this.logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
196
611
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
197
612
|
}
|
|
198
613
|
} catch (err) {
|
|
@@ -201,11 +616,13 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
201
616
|
});
|
|
202
617
|
}
|
|
203
618
|
}
|
|
204
|
-
await
|
|
205
|
-
|
|
206
|
-
|
|
619
|
+
const endState = await db.getStateReference();
|
|
620
|
+
provingState.setEndState(endState);
|
|
621
|
+
const blockEndBlobFields = provingState.getBlockEndBlobFields();
|
|
622
|
+
await spongeBlobState.absorb(blockEndBlobFields);
|
|
207
623
|
provingState.setEndSpongeBlob(spongeBlobState);
|
|
208
|
-
// Txs have been added to the block. Now try to accumulate the blobs as far as we can:
|
|
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();
|
|
209
626
|
await this.provingState.setBlobAccumulators();
|
|
210
627
|
}
|
|
211
628
|
/**
|
|
@@ -220,7 +637,7 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
220
637
|
const txHash = tx.getTxHash().toString();
|
|
221
638
|
const privateInputs = getPublicChonkVerifierPrivateInputsFromTx(tx, this.proverId.toField());
|
|
222
639
|
const tubeProof = promiseWithResolvers();
|
|
223
|
-
logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
640
|
+
this.logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
224
641
|
this.doEnqueueChonkVerifier(txHash, privateInputs, (proof)=>{
|
|
225
642
|
tubeProof.resolve(proof);
|
|
226
643
|
});
|
|
@@ -248,78 +665,82 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
248
665
|
if (provingState.isAcceptingTxs()) {
|
|
249
666
|
throw new Error(`Block ${blockNumber} is still accepting txs. Call setBlockCompleted after all txs have been added.`);
|
|
250
667
|
}
|
|
251
|
-
//
|
|
252
|
-
logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
253
|
-
const header = await
|
|
254
|
-
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
255
|
-
return header;
|
|
256
|
-
}
|
|
257
|
-
async buildL2BlockHeader(provingState, expectedHeader) {
|
|
258
|
-
// Collect all txs in this block to build the header. The function calling this has made sure that all txs have been added.
|
|
259
|
-
const txs = provingState.getProcessedTxs();
|
|
260
|
-
const startSpongeBlob = provingState.getStartSpongeBlob();
|
|
261
|
-
// Get db for this block
|
|
262
|
-
const db = this.dbs.get(provingState.blockNumber);
|
|
263
|
-
// Given we've applied every change from this block, now assemble the block header
|
|
264
|
-
// and update the archive tree, so we're ready to start processing the next block
|
|
265
|
-
const header = await buildBlockHeaderFromTxs(txs, provingState.getGlobalVariables(), startSpongeBlob, db);
|
|
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();
|
|
266
671
|
if (expectedHeader && !header.equals(expectedHeader)) {
|
|
267
|
-
logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
672
|
+
this.logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
268
673
|
throw new Error('Block header mismatch');
|
|
269
674
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
provingState.
|
|
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);
|
|
273
687
|
return header;
|
|
274
688
|
}
|
|
275
689
|
// Flagged as protected to disable in certain unit tests
|
|
276
690
|
async verifyBuiltBlockAgainstSyncedState(provingState) {
|
|
277
691
|
const builtBlockHeader = provingState.getBuiltBlockHeader();
|
|
278
692
|
if (!builtBlockHeader) {
|
|
279
|
-
logger.debug('Block header not built yet, skipping header check.');
|
|
693
|
+
this.logger.debug('Block header not built yet, skipping header check.');
|
|
280
694
|
return;
|
|
281
695
|
}
|
|
282
696
|
const output = provingState.getBlockRootRollupOutput();
|
|
283
697
|
if (!output) {
|
|
284
|
-
logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
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.');
|
|
285
704
|
return;
|
|
286
705
|
}
|
|
287
706
|
const header = await buildHeaderFromCircuitOutputs(output);
|
|
288
707
|
if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
|
|
289
|
-
logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
708
|
+
this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
290
709
|
provingState.reject(`Block header hash mismatch.`);
|
|
291
710
|
return;
|
|
292
711
|
}
|
|
293
|
-
// Get db for this block
|
|
294
712
|
const blockNumber = provingState.blockNumber;
|
|
295
|
-
const db = this.dbs.get(blockNumber);
|
|
296
|
-
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
297
713
|
const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
|
|
298
714
|
if (!syncedArchive.equals(newArchive)) {
|
|
299
|
-
logger.error(`Archive tree mismatch for block ${blockNumber}: 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)}`);
|
|
300
716
|
provingState.reject(`Archive tree mismatch.`);
|
|
301
717
|
return;
|
|
302
718
|
}
|
|
303
719
|
const circuitArchive = output.newArchive;
|
|
304
720
|
if (!newArchive.equals(circuitArchive)) {
|
|
305
|
-
logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
721
|
+
this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
306
722
|
provingState.reject(`New archive mismatch.`);
|
|
307
723
|
return;
|
|
308
724
|
}
|
|
309
|
-
// TODO(palla/prover): This closes the fork only on the happy path. If this epoch orchestrator
|
|
310
|
-
// is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
|
|
311
|
-
// but have to make sure it only runs once all operations are completed, otherwise some function here
|
|
312
|
-
// will attempt to access the fork after it was closed.
|
|
313
|
-
logger.debug(`Cleaning up world state fork for ${blockNumber}`);
|
|
314
|
-
void this.dbs.get(blockNumber)?.close().then(()=>this.dbs.delete(blockNumber)).catch((err)=>logger.error(`Error closing db for block ${blockNumber}`, err));
|
|
315
725
|
}
|
|
316
726
|
/**
|
|
317
|
-
* 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.
|
|
318
730
|
*/ cancel() {
|
|
319
|
-
|
|
320
|
-
controller.abort();
|
|
321
|
-
}
|
|
731
|
+
this.resetSchedulerState(this.cancelJobsOnStop);
|
|
322
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;
|
|
323
744
|
}
|
|
324
745
|
/**
|
|
325
746
|
* Returns the proof for the current epoch.
|
|
@@ -339,61 +760,11 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
339
760
|
});
|
|
340
761
|
return epochProofResult;
|
|
341
762
|
}
|
|
342
|
-
/**
|
|
343
|
-
* Enqueue a job to be scheduled
|
|
344
|
-
* @param provingState - The proving state object being operated on
|
|
345
|
-
* @param jobType - The type of job to be queued
|
|
346
|
-
* @param job - The actual job, returns a promise notifying of the job's completion
|
|
347
|
-
*/ deferredProving(provingState, request, callback) {
|
|
348
|
-
if (!provingState.verifyState()) {
|
|
349
|
-
logger.debug(`Not enqueuing job, state no longer valid`);
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
const controller = new AbortController();
|
|
353
|
-
this.pendingProvingJobs.push(controller);
|
|
354
|
-
// We use a 'safeJob'. We don't want promise rejections in the proving pool, we want to capture the error here
|
|
355
|
-
// and reject the proving job whilst keeping the event loop free of rejections
|
|
356
|
-
const safeJob = async ()=>{
|
|
357
|
-
try {
|
|
358
|
-
// there's a delay between enqueueing this job and it actually running
|
|
359
|
-
if (controller.signal.aborted) {
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
const result = await request(controller.signal);
|
|
363
|
-
if (!provingState.verifyState()) {
|
|
364
|
-
logger.debug(`State no longer valid, discarding result`);
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
// we could have been cancelled whilst waiting for the result
|
|
368
|
-
// and the prover ignored the signal. Drop the result in that case
|
|
369
|
-
if (controller.signal.aborted) {
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
await callback(result);
|
|
373
|
-
} catch (err) {
|
|
374
|
-
if (err instanceof AbortError) {
|
|
375
|
-
// operation was cancelled, probably because the block was cancelled
|
|
376
|
-
// drop this result
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
logger.error(`Error thrown when proving job`, err);
|
|
380
|
-
provingState.reject(`${err}`);
|
|
381
|
-
} finally{
|
|
382
|
-
const index = this.pendingProvingJobs.indexOf(controller);
|
|
383
|
-
if (index > -1) {
|
|
384
|
-
this.pendingProvingJobs.splice(index, 1);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
// let the callstack unwind before adding the job to the queue
|
|
389
|
-
setImmediate(()=>void safeJob());
|
|
390
|
-
}
|
|
391
763
|
async updateL1ToL2MessageTree(l1ToL2Messages, db) {
|
|
392
|
-
const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, 'Too many L1 to L2 messages');
|
|
393
764
|
const lastL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
394
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);
|
|
395
766
|
// Update the local trees to include the new l1 to l2 messages
|
|
396
|
-
await db
|
|
767
|
+
await appendL1ToL2MessagesToTree(db, l1ToL2Messages);
|
|
397
768
|
const newL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
398
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);
|
|
399
770
|
return {
|
|
@@ -432,17 +803,17 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
432
803
|
// Executes the next level of merge if all inputs are available
|
|
433
804
|
enqueueBaseRollup(provingState, txIndex) {
|
|
434
805
|
if (!provingState.verifyState()) {
|
|
435
|
-
logger.debug('Not running base rollup, state invalid');
|
|
806
|
+
this.logger.debug('Not running base rollup, state invalid');
|
|
436
807
|
return;
|
|
437
808
|
}
|
|
438
809
|
if (!provingState.tryStartProvingBase(txIndex)) {
|
|
439
|
-
logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
810
|
+
this.logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
440
811
|
return;
|
|
441
812
|
}
|
|
442
813
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
443
814
|
const { processedTx } = txProvingState;
|
|
444
815
|
const { rollupType, inputs } = txProvingState.getBaseRollupTypeAndInputs();
|
|
445
|
-
logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
816
|
+
this.logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
446
817
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, `ProvingOrchestrator.prover.${inputs instanceof PrivateTxBaseRollupPrivateInputs ? 'getPrivateTxBaseRollupProof' : 'getPublicTxBaseRollupProof'}`, {
|
|
447
818
|
[Attributes.TX_HASH]: processedTx.hash.toString(),
|
|
448
819
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
@@ -453,7 +824,7 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
453
824
|
return this.prover.getPublicTxBaseRollupProof(inputs, signal, provingState.epochNumber);
|
|
454
825
|
}
|
|
455
826
|
}), (result)=>{
|
|
456
|
-
logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
827
|
+
this.logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
457
828
|
validatePartialState(result.inputs.endTreeSnapshots, txProvingState.treeSnapshots);
|
|
458
829
|
const leafLocation = provingState.setBaseRollupProof(txIndex, result);
|
|
459
830
|
if (provingState.totalNumTxs === 1) {
|
|
@@ -467,14 +838,13 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
467
838
|
// Once completed, will enqueue the the public tx base rollup.
|
|
468
839
|
getOrEnqueueChonkVerifier(provingState, txIndex) {
|
|
469
840
|
if (!provingState.verifyState()) {
|
|
470
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
841
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
471
842
|
return;
|
|
472
843
|
}
|
|
473
844
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
474
845
|
const txHash = txProvingState.processedTx.hash.toString();
|
|
475
|
-
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH;
|
|
476
846
|
const handleResult = (result)=>{
|
|
477
|
-
logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, {
|
|
847
|
+
this.logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, {
|
|
478
848
|
txHash
|
|
479
849
|
});
|
|
480
850
|
txProvingState.setPublicChonkVerifierProof(result);
|
|
@@ -482,18 +852,18 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
482
852
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
483
853
|
};
|
|
484
854
|
if (this.provingState?.cachedChonkVerifierProofs.has(txHash)) {
|
|
485
|
-
logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, {
|
|
855
|
+
this.logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, {
|
|
486
856
|
txHash
|
|
487
857
|
});
|
|
488
858
|
void this.provingState.cachedChonkVerifierProofs.get(txHash).then(handleResult);
|
|
489
859
|
return;
|
|
490
860
|
}
|
|
491
|
-
logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
861
|
+
this.logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
492
862
|
this.doEnqueueChonkVerifier(txHash, txProvingState.getPublicChonkVerifierPrivateInputs(), handleResult);
|
|
493
863
|
}
|
|
494
864
|
doEnqueueChonkVerifier(txHash, inputs, handler, provingState = this.provingState) {
|
|
495
865
|
if (!provingState.verifyState()) {
|
|
496
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
866
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
497
867
|
return;
|
|
498
868
|
}
|
|
499
869
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getPublicChonkVerifierProof', {
|
|
@@ -505,11 +875,11 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
505
875
|
// Enqueues the next level of merge if all inputs are available
|
|
506
876
|
enqueueMergeRollup(provingState, location) {
|
|
507
877
|
if (!provingState.verifyState()) {
|
|
508
|
-
logger.debug('Not running merge rollup. State no longer valid.');
|
|
878
|
+
this.logger.debug('Not running merge rollup. State no longer valid.');
|
|
509
879
|
return;
|
|
510
880
|
}
|
|
511
881
|
if (!provingState.tryStartProvingMerge(location)) {
|
|
512
|
-
logger.debug('Merge rollup already started.');
|
|
882
|
+
this.logger.debug('Merge rollup already started.');
|
|
513
883
|
return;
|
|
514
884
|
}
|
|
515
885
|
const inputs = provingState.getMergeRollupInputs(location);
|
|
@@ -523,15 +893,15 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
523
893
|
// Executes the block root rollup circuit
|
|
524
894
|
enqueueBlockRootRollup(provingState) {
|
|
525
895
|
if (!provingState.verifyState()) {
|
|
526
|
-
logger.debug('Not running block root rollup, state no longer valid');
|
|
896
|
+
this.logger.debug('Not running block root rollup, state no longer valid');
|
|
527
897
|
return;
|
|
528
898
|
}
|
|
529
899
|
if (!provingState.tryStartProvingBlockRoot()) {
|
|
530
|
-
logger.debug('Block root rollup already started.');
|
|
900
|
+
this.logger.debug('Block root rollup already started.');
|
|
531
901
|
return;
|
|
532
902
|
}
|
|
533
903
|
const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs();
|
|
534
|
-
logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
904
|
+
this.logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
535
905
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getBlockRootRollupProof', {
|
|
536
906
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
537
907
|
}, (signal)=>{
|
|
@@ -547,15 +917,20 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
547
917
|
return this.prover.getBlockRootRollupProof(inputs, signal, provingState.epochNumber);
|
|
548
918
|
}
|
|
549
919
|
}), async (result)=>{
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
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
|
+
});
|
|
553
925
|
const leafLocation = provingState.setBlockRootRollupProof(result);
|
|
554
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);
|
|
555
930
|
if (checkpointProvingState.totalNumBlocks === 1) {
|
|
556
|
-
this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
931
|
+
await this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
557
932
|
} else {
|
|
558
|
-
this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
933
|
+
await this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
559
934
|
}
|
|
560
935
|
});
|
|
561
936
|
}
|
|
@@ -563,11 +938,11 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
563
938
|
// Enqueues the root parity circuit if all inputs are available
|
|
564
939
|
enqueueBaseParityCircuit(checkpointProvingState, provingState, baseParityIndex) {
|
|
565
940
|
if (!provingState.verifyState()) {
|
|
566
|
-
logger.debug('Not running base parity. State no longer valid.');
|
|
941
|
+
this.logger.debug('Not running base parity. State no longer valid.');
|
|
567
942
|
return;
|
|
568
943
|
}
|
|
569
944
|
if (!provingState.tryStartProvingBaseParity(baseParityIndex)) {
|
|
570
|
-
logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
945
|
+
this.logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
571
946
|
return;
|
|
572
947
|
}
|
|
573
948
|
const inputs = checkpointProvingState.getBaseParityInputs(baseParityIndex);
|
|
@@ -588,11 +963,11 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
588
963
|
// Enqueues the root rollup proof if all inputs are available
|
|
589
964
|
enqueueRootParityCircuit(provingState) {
|
|
590
965
|
if (!provingState.verifyState()) {
|
|
591
|
-
logger.debug('Not running root parity. State no longer valid.');
|
|
966
|
+
this.logger.debug('Not running root parity. State no longer valid.');
|
|
592
967
|
return;
|
|
593
968
|
}
|
|
594
969
|
if (!provingState.tryStartProvingRootParity()) {
|
|
595
|
-
logger.debug('Root parity already started.');
|
|
970
|
+
this.logger.debug('Root parity already started.');
|
|
596
971
|
return;
|
|
597
972
|
}
|
|
598
973
|
const inputs = provingState.getParityRootInputs();
|
|
@@ -607,33 +982,38 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
607
982
|
// Enqueues the next level of merge if all inputs are available
|
|
608
983
|
enqueueBlockMergeRollup(provingState, location) {
|
|
609
984
|
if (!provingState.verifyState()) {
|
|
610
|
-
logger.debug('Not running block merge rollup. State no longer valid.');
|
|
985
|
+
this.logger.debug('Not running block merge rollup. State no longer valid.');
|
|
611
986
|
return;
|
|
612
987
|
}
|
|
613
988
|
if (!provingState.tryStartProvingBlockMerge(location)) {
|
|
614
|
-
logger.debug('Block merge rollup already started.');
|
|
989
|
+
this.logger.debug('Block merge rollup already started.');
|
|
615
990
|
return;
|
|
616
991
|
}
|
|
617
992
|
const inputs = provingState.getBlockMergeRollupInputs(location);
|
|
618
993
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getBlockMergeRollupProof', {
|
|
619
994
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-block-merge'
|
|
620
|
-
}, (signal)=>this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
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
|
+
});
|
|
621
1001
|
provingState.setBlockMergeRollupProof(location, result);
|
|
622
|
-
this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
1002
|
+
await this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
623
1003
|
});
|
|
624
1004
|
}
|
|
625
|
-
enqueueCheckpointRootRollup(provingState) {
|
|
1005
|
+
async enqueueCheckpointRootRollup(provingState) {
|
|
626
1006
|
if (!provingState.verifyState()) {
|
|
627
|
-
logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
1007
|
+
this.logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
628
1008
|
return;
|
|
629
1009
|
}
|
|
630
1010
|
if (!provingState.tryStartProvingCheckpointRoot()) {
|
|
631
|
-
logger.debug('Checkpoint root rollup already started.');
|
|
1011
|
+
this.logger.debug('Checkpoint root rollup already started.');
|
|
632
1012
|
return;
|
|
633
1013
|
}
|
|
634
1014
|
const rollupType = provingState.getCheckpointRootRollupType();
|
|
635
|
-
logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
636
|
-
const inputs = provingState.getCheckpointRootRollupInputs();
|
|
1015
|
+
this.logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
1016
|
+
const inputs = await provingState.getCheckpointRootRollupInputs();
|
|
637
1017
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointRootRollupProof', {
|
|
638
1018
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
639
1019
|
}, (signal)=>{
|
|
@@ -646,11 +1026,14 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
646
1026
|
const computedEndBlobAccumulatorState = provingState.getEndBlobAccumulator().toBlobAccumulator();
|
|
647
1027
|
const circuitEndBlobAccumulatorState = result.inputs.endBlobAccumulator;
|
|
648
1028
|
if (!circuitEndBlobAccumulatorState.equals(computedEndBlobAccumulatorState)) {
|
|
649
|
-
logger.error(`Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(computedEndBlobAccumulatorState)}`);
|
|
1029
|
+
this.logger.error(`Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(computedEndBlobAccumulatorState)}`);
|
|
650
1030
|
provingState.reject(`Blob accumulator state mismatch.`);
|
|
651
1031
|
return;
|
|
652
1032
|
}
|
|
653
|
-
logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}
|
|
1033
|
+
this.logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}`, {
|
|
1034
|
+
checkpointIndex: provingState.index,
|
|
1035
|
+
...result.inputs.toInspect()
|
|
1036
|
+
});
|
|
654
1037
|
const leafLocation = provingState.setCheckpointRootRollupProof(result);
|
|
655
1038
|
const epochProvingState = provingState.parentEpoch;
|
|
656
1039
|
if (epochProvingState.totalNumCheckpoints === 1) {
|
|
@@ -660,61 +1043,6 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
660
1043
|
}
|
|
661
1044
|
});
|
|
662
1045
|
}
|
|
663
|
-
enqueueCheckpointMergeRollup(provingState, location) {
|
|
664
|
-
if (!provingState.verifyState()) {
|
|
665
|
-
logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
666
|
-
return;
|
|
667
|
-
}
|
|
668
|
-
if (!provingState.tryStartProvingCheckpointMerge(location)) {
|
|
669
|
-
logger.debug('Checkpoint merge rollup already started.');
|
|
670
|
-
return;
|
|
671
|
-
}
|
|
672
|
-
const inputs = provingState.getCheckpointMergeRollupInputs(location);
|
|
673
|
-
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointMergeRollupProof', {
|
|
674
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-merge'
|
|
675
|
-
}, (signal)=>this.prover.getCheckpointMergeRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
676
|
-
logger.debug('Completed proof for checkpoint merge rollup.');
|
|
677
|
-
provingState.setCheckpointMergeRollupProof(location, result);
|
|
678
|
-
this.checkAndEnqueueNextCheckpointMergeRollup(provingState, location);
|
|
679
|
-
});
|
|
680
|
-
}
|
|
681
|
-
enqueueEpochPadding(provingState) {
|
|
682
|
-
if (!provingState.verifyState()) {
|
|
683
|
-
logger.debug('Not running epoch padding. State no longer valid.');
|
|
684
|
-
return;
|
|
685
|
-
}
|
|
686
|
-
if (!provingState.tryStartProvingPaddingCheckpoint()) {
|
|
687
|
-
logger.debug('Padding checkpoint already started.');
|
|
688
|
-
return;
|
|
689
|
-
}
|
|
690
|
-
logger.debug('Padding epoch proof with a padding block root proof.');
|
|
691
|
-
const inputs = provingState.getPaddingCheckpointInputs();
|
|
692
|
-
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointPaddingRollupProof', {
|
|
693
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-padding'
|
|
694
|
-
}, (signal)=>this.prover.getCheckpointPaddingRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
695
|
-
logger.debug('Completed proof for padding checkpoint.');
|
|
696
|
-
provingState.setCheckpointPaddingProof(result);
|
|
697
|
-
this.checkAndEnqueueRootRollup(provingState);
|
|
698
|
-
});
|
|
699
|
-
}
|
|
700
|
-
// Executes the root rollup circuit
|
|
701
|
-
enqueueRootRollup(provingState) {
|
|
702
|
-
if (!provingState.verifyState()) {
|
|
703
|
-
logger.debug('Not running root rollup, state no longer valid');
|
|
704
|
-
return;
|
|
705
|
-
}
|
|
706
|
-
logger.debug(`Preparing root rollup`);
|
|
707
|
-
const inputs = provingState.getRootRollupInputs();
|
|
708
|
-
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getRootRollupProof', {
|
|
709
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-root'
|
|
710
|
-
}, (signal)=>this.prover.getRootRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
711
|
-
logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
712
|
-
provingState.setRootRollupProof(result);
|
|
713
|
-
provingState.resolve({
|
|
714
|
-
status: 'success'
|
|
715
|
-
});
|
|
716
|
-
});
|
|
717
|
-
}
|
|
718
1046
|
checkAndEnqueueNextMergeRollup(provingState, currentLocation) {
|
|
719
1047
|
if (!provingState.isReadyForMergeRollup(currentLocation)) {
|
|
720
1048
|
return;
|
|
@@ -728,45 +1056,27 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
728
1056
|
}
|
|
729
1057
|
checkAndEnqueueBlockRootRollup(provingState) {
|
|
730
1058
|
if (!provingState.isReadyForBlockRootRollup()) {
|
|
731
|
-
logger.debug('Not ready for block root rollup');
|
|
1059
|
+
this.logger.debug('Not ready for block root rollup');
|
|
732
1060
|
return;
|
|
733
1061
|
}
|
|
734
1062
|
this.enqueueBlockRootRollup(provingState);
|
|
735
1063
|
}
|
|
736
|
-
checkAndEnqueueNextBlockMergeRollup(provingState, currentLocation) {
|
|
1064
|
+
async checkAndEnqueueNextBlockMergeRollup(provingState, currentLocation) {
|
|
737
1065
|
if (!provingState.isReadyForBlockMerge(currentLocation)) {
|
|
738
1066
|
return;
|
|
739
1067
|
}
|
|
740
1068
|
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
741
1069
|
if (parentLocation.level === 0) {
|
|
742
|
-
this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
1070
|
+
await this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
743
1071
|
} else {
|
|
744
1072
|
this.enqueueBlockMergeRollup(provingState, parentLocation);
|
|
745
1073
|
}
|
|
746
1074
|
}
|
|
747
|
-
checkAndEnqueueCheckpointRootRollup(provingState) {
|
|
1075
|
+
async checkAndEnqueueCheckpointRootRollup(provingState) {
|
|
748
1076
|
if (!provingState.isReadyForCheckpointRoot()) {
|
|
749
1077
|
return;
|
|
750
1078
|
}
|
|
751
|
-
this.enqueueCheckpointRootRollup(provingState);
|
|
752
|
-
}
|
|
753
|
-
checkAndEnqueueNextCheckpointMergeRollup(provingState, currentLocation) {
|
|
754
|
-
if (!provingState.isReadyForCheckpointMerge(currentLocation)) {
|
|
755
|
-
return;
|
|
756
|
-
}
|
|
757
|
-
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
758
|
-
if (parentLocation.level === 0) {
|
|
759
|
-
this.checkAndEnqueueRootRollup(provingState);
|
|
760
|
-
} else {
|
|
761
|
-
this.enqueueCheckpointMergeRollup(provingState, parentLocation);
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
checkAndEnqueueRootRollup(provingState) {
|
|
765
|
-
if (!provingState.isReadyForRootRollup()) {
|
|
766
|
-
logger.debug('Not ready for root rollup');
|
|
767
|
-
return;
|
|
768
|
-
}
|
|
769
|
-
this.enqueueRootRollup(provingState);
|
|
1079
|
+
await this.enqueueCheckpointRootRollup(provingState);
|
|
770
1080
|
}
|
|
771
1081
|
/**
|
|
772
1082
|
* Executes the VM circuit for a public function, will enqueue the corresponding kernel if the
|
|
@@ -775,41 +1085,19 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
775
1085
|
* @param txIndex - The index of the transaction being proven
|
|
776
1086
|
*/ enqueueVM(provingState, txIndex) {
|
|
777
1087
|
if (!provingState.verifyState()) {
|
|
778
|
-
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`);
|
|
779
1089
|
return;
|
|
780
1090
|
}
|
|
781
1091
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
782
|
-
// This function tries to do AVM proving. If there is a failure, it fakes the proof unless AVM_PROVING_STRICT is defined.
|
|
783
|
-
// Nothing downstream depends on the AVM proof yet. So having this mode lets us incrementally build the AVM circuit.
|
|
784
1092
|
const doAvmProving = wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getAvmProof', {
|
|
785
1093
|
[Attributes.TX_HASH]: txProvingState.processedTx.hash.toString()
|
|
786
1094
|
}, async (signal)=>{
|
|
787
1095
|
const inputs = txProvingState.getAvmInputs();
|
|
788
|
-
|
|
789
|
-
// TODO(#14234)[Unconditional PIs validation]: Remove the whole try-catch logic and
|
|
790
|
-
// just keep the next line but removing the second argument (false).
|
|
791
|
-
return await this.prover.getAvmProof(inputs, false, signal, provingState.epochNumber);
|
|
792
|
-
} catch (err) {
|
|
793
|
-
if (process.env.AVM_PROVING_STRICT) {
|
|
794
|
-
logger.error(`Error thrown when proving AVM circuit with AVM_PROVING_STRICT on`, err);
|
|
795
|
-
throw err;
|
|
796
|
-
} else {
|
|
797
|
-
logger.warn(`Error thrown when proving AVM circuit but AVM_PROVING_STRICT is off. Use snapshotted
|
|
798
|
-
AVM inputs and carrying on. ${inspect(err)}.`);
|
|
799
|
-
try {
|
|
800
|
-
this.metrics.incAvmFallback();
|
|
801
|
-
const snapshotAvmPrivateInputs = readAvmMinimalPublicTxInputsFromFile();
|
|
802
|
-
return await this.prover.getAvmProof(snapshotAvmPrivateInputs, true, signal, provingState.epochNumber);
|
|
803
|
-
} catch (err) {
|
|
804
|
-
logger.error(`Error thrown when proving snapshotted AVM inputs.`, err);
|
|
805
|
-
throw err;
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
}
|
|
1096
|
+
return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
|
|
809
1097
|
});
|
|
810
|
-
this.deferredProving(provingState, doAvmProving, (
|
|
811
|
-
logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
812
|
-
txProvingState.setAvmProof(
|
|
1098
|
+
this.deferredProving(provingState, doAvmProving, (proof)=>{
|
|
1099
|
+
this.logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1100
|
+
txProvingState.setAvmProof(proof);
|
|
813
1101
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
814
1102
|
});
|
|
815
1103
|
}
|
|
@@ -819,30 +1107,7 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
819
1107
|
return;
|
|
820
1108
|
}
|
|
821
1109
|
// We must have completed all proving (chonk verifier proof and (if required) vm proof are generated), we now move to the base rollup.
|
|
822
|
-
logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1110
|
+
this.logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
823
1111
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
824
1112
|
}
|
|
825
1113
|
}
|
|
826
|
-
_ts_decorate([
|
|
827
|
-
trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
828
|
-
[Attributes.BLOCK_NUMBER]: blockNumber
|
|
829
|
-
}))
|
|
830
|
-
], ProvingOrchestrator.prototype, "startNewBlock", null);
|
|
831
|
-
_ts_decorate([
|
|
832
|
-
trackSpan('ProvingOrchestrator.addTxs', (txs)=>({
|
|
833
|
-
[Attributes.BLOCK_TXS_COUNT]: txs.length
|
|
834
|
-
}))
|
|
835
|
-
], ProvingOrchestrator.prototype, "addTxs", null);
|
|
836
|
-
_ts_decorate([
|
|
837
|
-
trackSpan('ProvingOrchestrator.startChonkVerifierCircuits')
|
|
838
|
-
], ProvingOrchestrator.prototype, "startChonkVerifierCircuits", null);
|
|
839
|
-
_ts_decorate([
|
|
840
|
-
trackSpan('ProvingOrchestrator.setBlockCompleted', (blockNumber)=>({
|
|
841
|
-
[Attributes.BLOCK_NUMBER]: blockNumber
|
|
842
|
-
}))
|
|
843
|
-
], ProvingOrchestrator.prototype, "setBlockCompleted", null);
|
|
844
|
-
_ts_decorate([
|
|
845
|
-
trackSpan('ProvingOrchestrator.prepareBaseRollupInputs', (tx)=>({
|
|
846
|
-
[Attributes.TX_HASH]: tx.hash.toString()
|
|
847
|
-
}))
|
|
848
|
-
], ProvingOrchestrator.prototype, "prepareBaseRollupInputs", null);
|