@aztec/prover-client 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0
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/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 +38 -15
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
- package/dest/light/lightweight_checkpoint_builder.js +162 -36
- package/dest/mocks/fixtures.d.ts +1 -1
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +4 -3
- package/dest/mocks/test_context.d.ts +15 -13
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +50 -36
- package/dest/orchestrator/block-building-helpers.d.ts +6 -6
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +5 -5
- package/dest/orchestrator/block-proving-state.d.ts +5 -2
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +8 -1
- package/dest/orchestrator/checkpoint-proving-state.d.ts +20 -23
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +23 -87
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +161 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.js +1066 -0
- package/dest/orchestrator/chonk-cache.d.ts +39 -0
- package/dest/orchestrator/chonk-cache.d.ts.map +1 -0
- package/dest/orchestrator/chonk-cache.js +80 -0
- package/dest/orchestrator/index.d.ts +4 -2
- package/dest/orchestrator/index.d.ts.map +1 -1
- package/dest/orchestrator/index.js +3 -1
- 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 +81 -0
- package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
- package/dest/orchestrator/proving-scheduler.js +120 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts +88 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-orchestrator.js +232 -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 +7 -6
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +8 -8
- package/dest/prover-client/factory.d.ts +3 -3
- package/dest/prover-client/factory.d.ts.map +1 -1
- package/dest/prover-client/prover-client.d.ts +65 -8
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +66 -14
- package/dest/proving_broker/broker_prover_facade.d.ts +8 -6
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +18 -31
- package/dest/proving_broker/config.d.ts +13 -65
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +23 -6
- package/dest/proving_broker/fixtures.js +1 -1
- 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/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 +72 -21
- package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.js +391 -3
- 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 +4 -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 +6 -2
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +87 -23
- package/dest/test/epoch_settlement.d.ts +36 -0
- package/dest/test/epoch_settlement.d.ts.map +1 -0
- package/dest/test/epoch_settlement.js +52 -0
- package/dest/test/index.d.ts +2 -0
- package/dest/test/index.d.ts.map +1 -0
- package/dest/test/index.js +1 -0
- package/dest/test/mock_proof_store.d.ts +3 -3
- package/dest/test/mock_proof_store.d.ts.map +1 -1
- package/dest/test/mock_prover.d.ts +5 -5
- 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 +229 -50
- package/src/mocks/fixtures.ts +4 -3
- package/src/mocks/test_context.ts +44 -48
- package/src/orchestrator/block-building-helpers.ts +5 -5
- package/src/orchestrator/block-proving-state.ts +10 -1
- package/src/orchestrator/checkpoint-proving-state.ts +22 -116
- package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +1044 -0
- package/src/orchestrator/chonk-cache.ts +99 -0
- package/src/orchestrator/index.ts +8 -1
- package/src/orchestrator/orchestrator_metrics.ts +2 -25
- package/src/orchestrator/proving-scheduler.ts +160 -0
- package/src/orchestrator/top-tree-orchestrator.ts +384 -0
- package/src/orchestrator/top-tree-proving-state.ts +219 -0
- package/src/orchestrator/tx-proving-state.ts +11 -15
- package/src/prover-client/factory.ts +6 -2
- package/src/prover-client/prover-client.ts +148 -29
- package/src/proving_broker/broker_prover_facade.ts +27 -37
- package/src/proving_broker/config.ts +26 -3
- package/src/proving_broker/fixtures.ts +1 -1
- 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 +68 -16
- package/src/proving_broker/proving_broker_database/persisted.ts +17 -3
- package/src/proving_broker/proving_broker_instrumentation.ts +23 -35
- package/src/proving_broker/proving_job_controller.ts +11 -6
- package/src/proving_broker/rpc.ts +46 -20
- package/src/test/epoch_settlement.ts +82 -0
- package/src/test/index.ts +1 -0
- package/src/test/mock_prover.ts +3 -15
- 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 -108
- package/dest/orchestrator/epoch-proving-state.d.ts +0 -74
- package/dest/orchestrator/epoch-proving-state.d.ts.map +0 -1
- package/dest/orchestrator/epoch-proving-state.js +0 -233
- package/dest/orchestrator/orchestrator.d.ts +0 -113
- package/dest/orchestrator/orchestrator.d.ts.map +0 -1
- package/dest/orchestrator/orchestrator.js +0 -842
- package/dest/prover-client/server-epoch-prover.d.ts +0 -32
- package/dest/prover-client/server-epoch-prover.d.ts.map +0 -1
- package/dest/prover-client/server-epoch-prover.js +0 -40
- 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 -137
- package/src/orchestrator/epoch-proving-state.ts +0 -330
- package/src/orchestrator/orchestrator.ts +0 -1265
- package/src/prover-client/server-epoch-prover.ts +0 -69
- package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
- package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
|
@@ -0,0 +1,1066 @@
|
|
|
1
|
+
function applyDecs2203RFactory() {
|
|
2
|
+
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
3
|
+
return function addInitializer(initializer) {
|
|
4
|
+
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
5
|
+
assertCallable(initializer, "An initializer");
|
|
6
|
+
initializers.push(initializer);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
|
|
10
|
+
var kindStr;
|
|
11
|
+
switch(kind){
|
|
12
|
+
case 1:
|
|
13
|
+
kindStr = "accessor";
|
|
14
|
+
break;
|
|
15
|
+
case 2:
|
|
16
|
+
kindStr = "method";
|
|
17
|
+
break;
|
|
18
|
+
case 3:
|
|
19
|
+
kindStr = "getter";
|
|
20
|
+
break;
|
|
21
|
+
case 4:
|
|
22
|
+
kindStr = "setter";
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
kindStr = "field";
|
|
26
|
+
}
|
|
27
|
+
var ctx = {
|
|
28
|
+
kind: kindStr,
|
|
29
|
+
name: isPrivate ? "#" + name : name,
|
|
30
|
+
static: isStatic,
|
|
31
|
+
private: isPrivate,
|
|
32
|
+
metadata: metadata
|
|
33
|
+
};
|
|
34
|
+
var decoratorFinishedRef = {
|
|
35
|
+
v: false
|
|
36
|
+
};
|
|
37
|
+
ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
|
|
38
|
+
var get, set;
|
|
39
|
+
if (kind === 0) {
|
|
40
|
+
if (isPrivate) {
|
|
41
|
+
get = desc.get;
|
|
42
|
+
set = desc.set;
|
|
43
|
+
} else {
|
|
44
|
+
get = function() {
|
|
45
|
+
return this[name];
|
|
46
|
+
};
|
|
47
|
+
set = function(v) {
|
|
48
|
+
this[name] = v;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
} else if (kind === 2) {
|
|
52
|
+
get = function() {
|
|
53
|
+
return desc.value;
|
|
54
|
+
};
|
|
55
|
+
} else {
|
|
56
|
+
if (kind === 1 || kind === 3) {
|
|
57
|
+
get = function() {
|
|
58
|
+
return desc.get.call(this);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (kind === 1 || kind === 4) {
|
|
62
|
+
set = function(v) {
|
|
63
|
+
desc.set.call(this, v);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
ctx.access = get && set ? {
|
|
68
|
+
get: get,
|
|
69
|
+
set: set
|
|
70
|
+
} : get ? {
|
|
71
|
+
get: get
|
|
72
|
+
} : {
|
|
73
|
+
set: set
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
return dec(value, ctx);
|
|
77
|
+
} finally{
|
|
78
|
+
decoratorFinishedRef.v = true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function assertNotFinished(decoratorFinishedRef, fnName) {
|
|
82
|
+
if (decoratorFinishedRef.v) {
|
|
83
|
+
throw new Error("attempted to call " + fnName + " after decoration was finished");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function assertCallable(fn, hint) {
|
|
87
|
+
if (typeof fn !== "function") {
|
|
88
|
+
throw new TypeError(hint + " must be a function");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function assertValidReturnValue(kind, value) {
|
|
92
|
+
var type = typeof value;
|
|
93
|
+
if (kind === 1) {
|
|
94
|
+
if (type !== "object" || value === null) {
|
|
95
|
+
throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
96
|
+
}
|
|
97
|
+
if (value.get !== undefined) {
|
|
98
|
+
assertCallable(value.get, "accessor.get");
|
|
99
|
+
}
|
|
100
|
+
if (value.set !== undefined) {
|
|
101
|
+
assertCallable(value.set, "accessor.set");
|
|
102
|
+
}
|
|
103
|
+
if (value.init !== undefined) {
|
|
104
|
+
assertCallable(value.init, "accessor.init");
|
|
105
|
+
}
|
|
106
|
+
} else if (type !== "function") {
|
|
107
|
+
var hint;
|
|
108
|
+
if (kind === 0) {
|
|
109
|
+
hint = "field";
|
|
110
|
+
} else if (kind === 10) {
|
|
111
|
+
hint = "class";
|
|
112
|
+
} else {
|
|
113
|
+
hint = "method";
|
|
114
|
+
}
|
|
115
|
+
throw new TypeError(hint + " decorators must return a function or void 0");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
|
|
119
|
+
var decs = decInfo[0];
|
|
120
|
+
var desc, init, value;
|
|
121
|
+
if (isPrivate) {
|
|
122
|
+
if (kind === 0 || kind === 1) {
|
|
123
|
+
desc = {
|
|
124
|
+
get: decInfo[3],
|
|
125
|
+
set: decInfo[4]
|
|
126
|
+
};
|
|
127
|
+
} else if (kind === 3) {
|
|
128
|
+
desc = {
|
|
129
|
+
get: decInfo[3]
|
|
130
|
+
};
|
|
131
|
+
} else if (kind === 4) {
|
|
132
|
+
desc = {
|
|
133
|
+
set: decInfo[3]
|
|
134
|
+
};
|
|
135
|
+
} else {
|
|
136
|
+
desc = {
|
|
137
|
+
value: decInfo[3]
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
} else if (kind !== 0) {
|
|
141
|
+
desc = Object.getOwnPropertyDescriptor(base, name);
|
|
142
|
+
}
|
|
143
|
+
if (kind === 1) {
|
|
144
|
+
value = {
|
|
145
|
+
get: desc.get,
|
|
146
|
+
set: desc.set
|
|
147
|
+
};
|
|
148
|
+
} else if (kind === 2) {
|
|
149
|
+
value = desc.value;
|
|
150
|
+
} else if (kind === 3) {
|
|
151
|
+
value = desc.get;
|
|
152
|
+
} else if (kind === 4) {
|
|
153
|
+
value = desc.set;
|
|
154
|
+
}
|
|
155
|
+
var newValue, get, set;
|
|
156
|
+
if (typeof decs === "function") {
|
|
157
|
+
newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
158
|
+
if (newValue !== void 0) {
|
|
159
|
+
assertValidReturnValue(kind, newValue);
|
|
160
|
+
if (kind === 0) {
|
|
161
|
+
init = newValue;
|
|
162
|
+
} else if (kind === 1) {
|
|
163
|
+
init = newValue.init;
|
|
164
|
+
get = newValue.get || value.get;
|
|
165
|
+
set = newValue.set || value.set;
|
|
166
|
+
value = {
|
|
167
|
+
get: get,
|
|
168
|
+
set: set
|
|
169
|
+
};
|
|
170
|
+
} else {
|
|
171
|
+
value = newValue;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
for(var i = decs.length - 1; i >= 0; i--){
|
|
176
|
+
var dec = decs[i];
|
|
177
|
+
newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
178
|
+
if (newValue !== void 0) {
|
|
179
|
+
assertValidReturnValue(kind, newValue);
|
|
180
|
+
var newInit;
|
|
181
|
+
if (kind === 0) {
|
|
182
|
+
newInit = newValue;
|
|
183
|
+
} else if (kind === 1) {
|
|
184
|
+
newInit = newValue.init;
|
|
185
|
+
get = newValue.get || value.get;
|
|
186
|
+
set = newValue.set || value.set;
|
|
187
|
+
value = {
|
|
188
|
+
get: get,
|
|
189
|
+
set: set
|
|
190
|
+
};
|
|
191
|
+
} else {
|
|
192
|
+
value = newValue;
|
|
193
|
+
}
|
|
194
|
+
if (newInit !== void 0) {
|
|
195
|
+
if (init === void 0) {
|
|
196
|
+
init = newInit;
|
|
197
|
+
} else if (typeof init === "function") {
|
|
198
|
+
init = [
|
|
199
|
+
init,
|
|
200
|
+
newInit
|
|
201
|
+
];
|
|
202
|
+
} else {
|
|
203
|
+
init.push(newInit);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (kind === 0 || kind === 1) {
|
|
210
|
+
if (init === void 0) {
|
|
211
|
+
init = function(instance, init) {
|
|
212
|
+
return init;
|
|
213
|
+
};
|
|
214
|
+
} else if (typeof init !== "function") {
|
|
215
|
+
var ownInitializers = init;
|
|
216
|
+
init = function(instance, init) {
|
|
217
|
+
var value = init;
|
|
218
|
+
for(var i = 0; i < ownInitializers.length; i++){
|
|
219
|
+
value = ownInitializers[i].call(instance, value);
|
|
220
|
+
}
|
|
221
|
+
return value;
|
|
222
|
+
};
|
|
223
|
+
} else {
|
|
224
|
+
var originalInitializer = init;
|
|
225
|
+
init = function(instance, init) {
|
|
226
|
+
return originalInitializer.call(instance, init);
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
ret.push(init);
|
|
230
|
+
}
|
|
231
|
+
if (kind !== 0) {
|
|
232
|
+
if (kind === 1) {
|
|
233
|
+
desc.get = value.get;
|
|
234
|
+
desc.set = value.set;
|
|
235
|
+
} else if (kind === 2) {
|
|
236
|
+
desc.value = value;
|
|
237
|
+
} else if (kind === 3) {
|
|
238
|
+
desc.get = value;
|
|
239
|
+
} else if (kind === 4) {
|
|
240
|
+
desc.set = value;
|
|
241
|
+
}
|
|
242
|
+
if (isPrivate) {
|
|
243
|
+
if (kind === 1) {
|
|
244
|
+
ret.push(function(instance, args) {
|
|
245
|
+
return value.get.call(instance, args);
|
|
246
|
+
});
|
|
247
|
+
ret.push(function(instance, args) {
|
|
248
|
+
return value.set.call(instance, args);
|
|
249
|
+
});
|
|
250
|
+
} else if (kind === 2) {
|
|
251
|
+
ret.push(value);
|
|
252
|
+
} else {
|
|
253
|
+
ret.push(function(instance, args) {
|
|
254
|
+
return value.call(instance, args);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
} else {
|
|
258
|
+
Object.defineProperty(base, name, desc);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function applyMemberDecs(Class, decInfos, metadata) {
|
|
263
|
+
var ret = [];
|
|
264
|
+
var protoInitializers;
|
|
265
|
+
var staticInitializers;
|
|
266
|
+
var existingProtoNonFields = new Map();
|
|
267
|
+
var existingStaticNonFields = new Map();
|
|
268
|
+
for(var i = 0; i < decInfos.length; i++){
|
|
269
|
+
var decInfo = decInfos[i];
|
|
270
|
+
if (!Array.isArray(decInfo)) continue;
|
|
271
|
+
var kind = decInfo[1];
|
|
272
|
+
var name = decInfo[2];
|
|
273
|
+
var isPrivate = decInfo.length > 3;
|
|
274
|
+
var isStatic = kind >= 5;
|
|
275
|
+
var base;
|
|
276
|
+
var initializers;
|
|
277
|
+
if (isStatic) {
|
|
278
|
+
base = Class;
|
|
279
|
+
kind = kind - 5;
|
|
280
|
+
staticInitializers = staticInitializers || [];
|
|
281
|
+
initializers = staticInitializers;
|
|
282
|
+
} else {
|
|
283
|
+
base = Class.prototype;
|
|
284
|
+
protoInitializers = protoInitializers || [];
|
|
285
|
+
initializers = protoInitializers;
|
|
286
|
+
}
|
|
287
|
+
if (kind !== 0 && !isPrivate) {
|
|
288
|
+
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
|
|
289
|
+
var existingKind = existingNonFields.get(name) || 0;
|
|
290
|
+
if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
|
|
291
|
+
throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
|
|
292
|
+
} else if (!existingKind && kind > 2) {
|
|
293
|
+
existingNonFields.set(name, kind);
|
|
294
|
+
} else {
|
|
295
|
+
existingNonFields.set(name, true);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
|
|
299
|
+
}
|
|
300
|
+
pushInitializers(ret, protoInitializers);
|
|
301
|
+
pushInitializers(ret, staticInitializers);
|
|
302
|
+
return ret;
|
|
303
|
+
}
|
|
304
|
+
function pushInitializers(ret, initializers) {
|
|
305
|
+
if (initializers) {
|
|
306
|
+
ret.push(function(instance) {
|
|
307
|
+
for(var i = 0; i < initializers.length; i++){
|
|
308
|
+
initializers[i].call(instance);
|
|
309
|
+
}
|
|
310
|
+
return instance;
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function applyClassDecs(targetClass, classDecs, metadata) {
|
|
315
|
+
if (classDecs.length > 0) {
|
|
316
|
+
var initializers = [];
|
|
317
|
+
var newClass = targetClass;
|
|
318
|
+
var name = targetClass.name;
|
|
319
|
+
for(var i = classDecs.length - 1; i >= 0; i--){
|
|
320
|
+
var decoratorFinishedRef = {
|
|
321
|
+
v: false
|
|
322
|
+
};
|
|
323
|
+
try {
|
|
324
|
+
var nextNewClass = classDecs[i](newClass, {
|
|
325
|
+
kind: "class",
|
|
326
|
+
name: name,
|
|
327
|
+
addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
|
|
328
|
+
metadata
|
|
329
|
+
});
|
|
330
|
+
} finally{
|
|
331
|
+
decoratorFinishedRef.v = true;
|
|
332
|
+
}
|
|
333
|
+
if (nextNewClass !== undefined) {
|
|
334
|
+
assertValidReturnValue(10, nextNewClass);
|
|
335
|
+
newClass = nextNewClass;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return [
|
|
339
|
+
defineMetadata(newClass, metadata),
|
|
340
|
+
function() {
|
|
341
|
+
for(var i = 0; i < initializers.length; i++){
|
|
342
|
+
initializers[i].call(newClass);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
];
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
function defineMetadata(Class, metadata) {
|
|
349
|
+
return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
|
|
350
|
+
configurable: true,
|
|
351
|
+
enumerable: true,
|
|
352
|
+
value: metadata
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
|
|
356
|
+
if (parentClass !== void 0) {
|
|
357
|
+
var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
358
|
+
}
|
|
359
|
+
var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
|
|
360
|
+
var e = applyMemberDecs(targetClass, memberDecs, metadata);
|
|
361
|
+
if (!classDecs.length) defineMetadata(targetClass, metadata);
|
|
362
|
+
return {
|
|
363
|
+
e: e,
|
|
364
|
+
get c () {
|
|
365
|
+
return applyClassDecs(targetClass, classDecs, metadata);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
371
|
+
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
372
|
+
}
|
|
373
|
+
var _dec, _dec1, _dec2, _dec3, _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';
|
|
376
|
+
import { AbortError } from '@aztec/foundation/error';
|
|
377
|
+
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
378
|
+
import { assertLength } from '@aztec/foundation/serialize';
|
|
379
|
+
import { appendL1ToL2MessagesToTree } from '@aztec/stdlib/messaging';
|
|
380
|
+
import { BlockRootEmptyTxFirstRollupPrivateInputs, BlockRootFirstRollupPrivateInputs, BlockRootSingleTxFirstRollupPrivateInputs, BlockRootSingleTxRollupPrivateInputs, PrivateTxBaseRollupPrivateInputs } from '@aztec/stdlib/rollup';
|
|
381
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
382
|
+
import { Attributes, getTelemetryClient, trackSpan, wrapCallbackInSpan } from '@aztec/telemetry-client';
|
|
383
|
+
import { inspect } from 'util';
|
|
384
|
+
import { buildHeaderFromCircuitOutputs, getLastSiblingPath, getPublicChonkVerifierPrivateInputsFromTx, getRootTreeSiblingPath, getSubtreeSiblingPath, getTreeSnapshot, insertSideEffectsAndBuildBaseRollupHints, validatePartialState, validateTx } from './block-building-helpers.js';
|
|
385
|
+
import { CheckpointProvingState } from './checkpoint-proving-state.js';
|
|
386
|
+
import { ProvingOrchestratorMetrics } from './orchestrator_metrics.js';
|
|
387
|
+
import { ProvingScheduler } from './proving-scheduler.js';
|
|
388
|
+
import { TxProvingState } from './tx-proving-state.js';
|
|
389
|
+
_dec = trackSpan('CheckpointSubTreeOrchestrator.startNewBlock', (blockNumber)=>({
|
|
390
|
+
[Attributes.BLOCK_NUMBER]: blockNumber
|
|
391
|
+
})), _dec1 = trackSpan('CheckpointSubTreeOrchestrator.addTxs', (txs)=>({
|
|
392
|
+
[Attributes.BLOCK_TXS_COUNT]: txs.length
|
|
393
|
+
})), _dec2 = trackSpan('CheckpointSubTreeOrchestrator.setBlockCompleted', (blockNumber)=>({
|
|
394
|
+
[Attributes.BLOCK_NUMBER]: blockNumber
|
|
395
|
+
})), _dec3 = trackSpan('CheckpointSubTreeOrchestrator.prepareBaseRollupInputs', (tx)=>({
|
|
396
|
+
[Attributes.TX_HASH]: tx.hash.toString()
|
|
397
|
+
}));
|
|
398
|
+
/**
|
|
399
|
+
* Orchestrates block-level proving for a single checkpoint, stopping at the boundary
|
|
400
|
+
* where checkpoint root rollup would otherwise begin. Used by the per-checkpoint
|
|
401
|
+
* `CheckpointProver` in production; the top-tree orchestrator then composes the
|
|
402
|
+
* sub-tree's block proofs into the epoch proof.
|
|
403
|
+
*
|
|
404
|
+
* Wiring: a single-checkpoint mini-proving session is owned by the constructor. The
|
|
405
|
+
* canonical way to obtain a fully-started sub-tree is the `start` static factory,
|
|
406
|
+
* which also drives the single internal `startCheckpoint` call. The sub-tree never
|
|
407
|
+
* escalates past the checkpoint root boundary; `getSubTreeResult()` resolves once
|
|
408
|
+
* every block-level proof in the checkpoint's tree is ready.
|
|
409
|
+
*/ export class CheckpointSubTreeOrchestrator extends ProvingScheduler {
|
|
410
|
+
dbProvider;
|
|
411
|
+
prover;
|
|
412
|
+
proverId;
|
|
413
|
+
chonkCache;
|
|
414
|
+
epochNumber;
|
|
415
|
+
cancelJobsOnStop;
|
|
416
|
+
static{
|
|
417
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
418
|
+
[
|
|
419
|
+
_dec,
|
|
420
|
+
2,
|
|
421
|
+
"startNewBlock"
|
|
422
|
+
],
|
|
423
|
+
[
|
|
424
|
+
_dec1,
|
|
425
|
+
2,
|
|
426
|
+
"addTxs"
|
|
427
|
+
],
|
|
428
|
+
[
|
|
429
|
+
_dec2,
|
|
430
|
+
2,
|
|
431
|
+
"setBlockCompleted"
|
|
432
|
+
],
|
|
433
|
+
[
|
|
434
|
+
_dec3,
|
|
435
|
+
2,
|
|
436
|
+
"prepareBaseRollupInputs"
|
|
437
|
+
]
|
|
438
|
+
], []));
|
|
439
|
+
}
|
|
440
|
+
/** The single checkpoint proving state this sub-tree owns. Allocated in the `start` factory. */ provingState;
|
|
441
|
+
subTreeResult;
|
|
442
|
+
metrics;
|
|
443
|
+
dbs;
|
|
444
|
+
constructor(dbProvider, prover, proverId, /**
|
|
445
|
+
* Shared chonk-verifier proof cache. Every chonk-verifier proof started by this
|
|
446
|
+
* sub-tree lives on the cache and survives the sub-tree's cancellation, so a tx
|
|
447
|
+
* whose original checkpoint is reorged out and re-appears in a replacement
|
|
448
|
+
* checkpoint reuses the cached proof.
|
|
449
|
+
*/ chonkCache, /** The epoch this sub-tree proves into. */ epochNumber, cancelJobsOnStop = false, deferredJobQueue, telemetryClient = getTelemetryClient(), bindings){
|
|
450
|
+
super(deferredJobQueue, 'prover-client:checkpoint-sub-tree-orchestrator', bindings), this.dbProvider = dbProvider, this.prover = prover, this.proverId = proverId, this.chonkCache = chonkCache, this.epochNumber = epochNumber, this.cancelJobsOnStop = cancelJobsOnStop, this.provingState = (_initProto(this), undefined), this.dbs = new Map(), this.cancelled = false;
|
|
451
|
+
this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'CheckpointSubTreeOrchestrator');
|
|
452
|
+
this.subTreeResult = promiseWithResolvers();
|
|
453
|
+
// Mark the rejection branch as observed so a `cancel()` or proving failure does not
|
|
454
|
+
// surface an unhandled rejection when no consumer awaits getSubTreeResult().
|
|
455
|
+
this.subTreeResult.promise.catch(()=>{});
|
|
456
|
+
}
|
|
457
|
+
/** Tracks whether `cancel()` has been called; flows into the checkpoint state's isAlive hook. */ cancelled;
|
|
458
|
+
get tracer() {
|
|
459
|
+
return this.metrics.tracer;
|
|
460
|
+
}
|
|
461
|
+
getProverId() {
|
|
462
|
+
return this.proverId;
|
|
463
|
+
}
|
|
464
|
+
getNumActiveForks() {
|
|
465
|
+
return this.dbs.size;
|
|
466
|
+
}
|
|
467
|
+
/** Returns a promise that resolves when block-level proving completes for the checkpoint. */ getSubTreeResult() {
|
|
468
|
+
return this.subTreeResult.promise;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Returns the archive sibling path captured at the internal checkpoint start.
|
|
472
|
+
* Available synchronously once `start` has resolved, before block-level proving
|
|
473
|
+
* completes. The top-tree consumer uses this to assemble checkpoint root rollup hints
|
|
474
|
+
* up-front so checkpoint root proofs can pipeline against in-flight sub-tree proving.
|
|
475
|
+
*/ getPreviousArchiveSiblingPath() {
|
|
476
|
+
if (!this.provingState) {
|
|
477
|
+
throw new Error('Checkpoint not started; call CheckpointSubTreeOrchestrator.start first.');
|
|
478
|
+
}
|
|
479
|
+
return this.provingState.getLastArchiveSiblingPath();
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Constructs and starts a sub-tree for a single checkpoint. The returned sub-tree
|
|
483
|
+
* has had its single internal checkpoint state allocated; callers proceed directly
|
|
484
|
+
* to per-block `startNewBlock` / `addTxs` / `setBlockCompleted`.
|
|
485
|
+
*
|
|
486
|
+
* If the internal start rejects, the partially-constructed sub-tree is stopped
|
|
487
|
+
* before the error propagates, so no broker resources leak.
|
|
488
|
+
*/ static async start(dbProvider, prover, proverId, chonkCache, epochNumber, cancelJobsOnStop, deferredJobQueue, checkpointConstants, l1ToL2Messages, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint, telemetryClient = getTelemetryClient(), bindings) {
|
|
489
|
+
const subTree = new CheckpointSubTreeOrchestrator(dbProvider, prover, proverId, chonkCache, epochNumber, cancelJobsOnStop, deferredJobQueue, telemetryClient, bindings);
|
|
490
|
+
try {
|
|
491
|
+
await subTree.startCheckpoint(checkpointConstants, l1ToL2Messages, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint);
|
|
492
|
+
return subTree;
|
|
493
|
+
} catch (err) {
|
|
494
|
+
await subTree.stop().catch(()=>{});
|
|
495
|
+
throw err;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Kickstart chonk-verifier circuits via the shared `ChonkCache`. The cache owns the
|
|
500
|
+
* broker job lifecycle, so the proof survives this sub-tree's `cancel()` — a tx that
|
|
501
|
+
* ends up in a replacement checkpoint after a reorg can pick the cached promise up
|
|
502
|
+
* and skip re-proving.
|
|
503
|
+
*/ startChonkVerifierCircuits(txs) {
|
|
504
|
+
if (!this.provingState?.verifyState()) {
|
|
505
|
+
return Promise.reject(new Error('Sub-tree proving state is not active.'));
|
|
506
|
+
}
|
|
507
|
+
const publicTxs = txs.filter((tx)=>tx.data.forPublic);
|
|
508
|
+
for (const tx of publicTxs){
|
|
509
|
+
const txHash = tx.getTxHash().toString();
|
|
510
|
+
const inputs = getPublicChonkVerifierPrivateInputsFromTx(tx, this.getProverId().toField());
|
|
511
|
+
// Fire and forget — getOrEnqueueChonkVerifier later picks up the cached promise
|
|
512
|
+
// when the tx is processed inside its block.
|
|
513
|
+
void this.chonkCache.getOrCompute(txHash, (signal)=>this.prover.getPublicChonkVerifierProof(inputs, signal, this.epochNumber));
|
|
514
|
+
}
|
|
515
|
+
return Promise.resolve();
|
|
516
|
+
}
|
|
517
|
+
// ---------------- per-block driving (called by the per-checkpoint CheckpointProver) ----------------
|
|
518
|
+
/**
|
|
519
|
+
* Starts off a new block.
|
|
520
|
+
* @param blockNumber - The block number
|
|
521
|
+
* @param timestamp - The timestamp of the block. Required for empty blocks to construct private inputs.
|
|
522
|
+
* @param totalNumTxs - The total number of txs in the block.
|
|
523
|
+
*/ async startNewBlock(blockNumber, timestamp, totalNumTxs) {
|
|
524
|
+
if (!this.provingState) {
|
|
525
|
+
throw new Error('Empty proving state. The checkpoint sub-tree has not been started.');
|
|
526
|
+
}
|
|
527
|
+
if (!this.provingState.isAcceptingBlocks()) {
|
|
528
|
+
throw new Error(`Checkpoint not accepting further blocks.`);
|
|
529
|
+
}
|
|
530
|
+
const constants = this.provingState.constants;
|
|
531
|
+
this.logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
532
|
+
// Fork the db only when it's not already set. The db for the first block is set in startCheckpoint.
|
|
533
|
+
if (!this.dbs.has(blockNumber)) {
|
|
534
|
+
// Fork world state at the end of the immediately previous block.
|
|
535
|
+
const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
|
|
536
|
+
this.dbs.set(blockNumber, db);
|
|
537
|
+
}
|
|
538
|
+
const db = this.getDbForBlock(blockNumber);
|
|
539
|
+
// Get archive snapshot and sibling path before any txs in this block lands.
|
|
540
|
+
const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
541
|
+
const lastArchiveSiblingPath = await getRootTreeSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
542
|
+
const blockProvingState = this.provingState.startNewBlock(blockNumber, timestamp, totalNumTxs, lastArchiveTreeSnapshot, lastArchiveSiblingPath);
|
|
543
|
+
// Enqueue base parity circuits for the first block in the checkpoint.
|
|
544
|
+
if (blockProvingState.index === 0) {
|
|
545
|
+
for(let i = 0; i < NUM_BASE_PARITY_PER_ROOT_PARITY; i++){
|
|
546
|
+
this.enqueueBaseParityCircuit(this.provingState, blockProvingState, i);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
// Because `addTxs` won't be called for a block without txs, and that's where the sponge blob state is computed,
|
|
550
|
+
// set its end sponge blob here. This becomes the start sponge blob for the next block.
|
|
551
|
+
if (totalNumTxs === 0) {
|
|
552
|
+
const endState = await db.getStateReference();
|
|
553
|
+
blockProvingState.setEndState(endState);
|
|
554
|
+
const endSpongeBlob = blockProvingState.getStartSpongeBlob().clone();
|
|
555
|
+
const blockEndBlobFields = blockProvingState.getBlockEndBlobFields();
|
|
556
|
+
await endSpongeBlob.absorb(blockEndBlobFields);
|
|
557
|
+
blockProvingState.setEndSpongeBlob(endSpongeBlob);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* The interface to add simulated transactions to the scheduler. Called at most once per block.
|
|
562
|
+
* @param txs - The transactions to be proven
|
|
563
|
+
*/ async addTxs(txs) {
|
|
564
|
+
if (!this.provingState) {
|
|
565
|
+
throw new Error(`Empty proving state. The checkpoint sub-tree has not been started.`);
|
|
566
|
+
}
|
|
567
|
+
if (!txs.length) {
|
|
568
|
+
// Empty block: setBlockCompleted handles this without addTxs being called. Bail to
|
|
569
|
+
// avoid the throw below (we cannot find the blockNumber without any txs).
|
|
570
|
+
this.logger.verbose(`Provided no txs to addTxs.`);
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
const blockNumber = BlockNumber(txs[0].globalVariables.blockNumber);
|
|
574
|
+
const provingState = this.provingState.getBlockProvingStateByBlockNumber(blockNumber);
|
|
575
|
+
if (!provingState) {
|
|
576
|
+
throw new Error(`Proving state for block ${blockNumber} not found. Call startNewBlock first.`);
|
|
577
|
+
}
|
|
578
|
+
if (provingState.totalNumTxs !== txs.length) {
|
|
579
|
+
throw new Error(`Block ${blockNumber} should be filled with ${provingState.totalNumTxs} txs. Received ${txs.length} txs.`);
|
|
580
|
+
}
|
|
581
|
+
if (!provingState.isAcceptingTxs()) {
|
|
582
|
+
throw new Error(`Block ${blockNumber} has been initialized with transactions.`);
|
|
583
|
+
}
|
|
584
|
+
this.logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
585
|
+
const db = this.getDbForBlock(blockNumber);
|
|
586
|
+
const lastArchive = provingState.lastArchiveTreeSnapshot;
|
|
587
|
+
const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
|
|
588
|
+
const spongeBlobState = provingState.getStartSpongeBlob().clone();
|
|
589
|
+
for (const tx of txs){
|
|
590
|
+
try {
|
|
591
|
+
if (!provingState.verifyState()) {
|
|
592
|
+
throw new Error(`Invalid proving state when adding a tx`);
|
|
593
|
+
}
|
|
594
|
+
validateTx(tx);
|
|
595
|
+
this.logger.debug(`Received transaction: ${tx.hash}`);
|
|
596
|
+
const startSpongeBlob = spongeBlobState.clone();
|
|
597
|
+
const [hints, treeSnapshots] = await this.prepareBaseRollupInputs(tx, lastArchive, newL1ToL2MessageTreeSnapshot, startSpongeBlob, db);
|
|
598
|
+
if (!provingState.verifyState()) {
|
|
599
|
+
throw new Error(`Unable to add transaction, preparing base inputs failed`);
|
|
600
|
+
}
|
|
601
|
+
await spongeBlobState.absorb(tx.txEffect.toBlobFields());
|
|
602
|
+
const txProvingState = new TxProvingState(tx, hints, treeSnapshots, this.proverId.toField());
|
|
603
|
+
const txIndex = provingState.addNewTx(txProvingState);
|
|
604
|
+
if (txProvingState.requireAvmProof) {
|
|
605
|
+
this.getOrEnqueueChonkVerifier(provingState, txIndex);
|
|
606
|
+
this.logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
607
|
+
this.enqueueVM(provingState, txIndex);
|
|
608
|
+
} else {
|
|
609
|
+
this.logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
610
|
+
this.enqueueBaseRollup(provingState, txIndex);
|
|
611
|
+
}
|
|
612
|
+
} catch (err) {
|
|
613
|
+
throw new Error(`Error adding transaction ${tx.hash.toString()} to block ${blockNumber}: ${err.message}`, {
|
|
614
|
+
cause: err
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
const endState = await db.getStateReference();
|
|
619
|
+
provingState.setEndState(endState);
|
|
620
|
+
const blockEndBlobFields = provingState.getBlockEndBlobFields();
|
|
621
|
+
await spongeBlobState.absorb(blockEndBlobFields);
|
|
622
|
+
provingState.setEndSpongeBlob(spongeBlobState);
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Marks the block as completed.
|
|
626
|
+
* Computes the block header and updates the archive tree.
|
|
627
|
+
*/ async setBlockCompleted(blockNumber, expectedHeader) {
|
|
628
|
+
const provingState = this.provingState?.getBlockProvingStateByBlockNumber(blockNumber);
|
|
629
|
+
if (!provingState) {
|
|
630
|
+
throw new Error(`Block proving state for ${blockNumber} not found`);
|
|
631
|
+
}
|
|
632
|
+
// Abort with specific error for the block if there's one.
|
|
633
|
+
const error = provingState.getError();
|
|
634
|
+
if (error) {
|
|
635
|
+
throw new Error(`Block proving failed: ${error}`);
|
|
636
|
+
}
|
|
637
|
+
// Abort if the proving state is not valid due to errors occurred elsewhere.
|
|
638
|
+
if (!provingState.verifyState()) {
|
|
639
|
+
throw new Error(`Invalid proving state when completing block ${blockNumber}.`);
|
|
640
|
+
}
|
|
641
|
+
if (provingState.isAcceptingTxs()) {
|
|
642
|
+
throw new Error(`Block ${blockNumber} is still accepting txs. Call setBlockCompleted after all txs have been added.`);
|
|
643
|
+
}
|
|
644
|
+
// Given we've applied every change from this block, now assemble the block header:
|
|
645
|
+
this.logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
646
|
+
const header = await provingState.buildBlockHeader();
|
|
647
|
+
if (expectedHeader && !header.equals(expectedHeader)) {
|
|
648
|
+
this.logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
649
|
+
throw new Error('Block header mismatch');
|
|
650
|
+
}
|
|
651
|
+
// Get db for this block and remove from map — no other code should use it after this point.
|
|
652
|
+
const db = this.getDbForBlock(provingState.blockNumber);
|
|
653
|
+
this.dbs.delete(provingState.blockNumber);
|
|
654
|
+
// Update the archive tree, capture the snapshot, and close the fork deterministically.
|
|
655
|
+
try {
|
|
656
|
+
this.logger.verbose(`Updating archive tree with block ${provingState.blockNumber} header ${(await header.hash()).toString()}`);
|
|
657
|
+
await db.updateArchive(header);
|
|
658
|
+
provingState.setBuiltArchive(await getTreeSnapshot(MerkleTreeId.ARCHIVE, db));
|
|
659
|
+
} finally{
|
|
660
|
+
await db.close();
|
|
661
|
+
}
|
|
662
|
+
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
663
|
+
return header;
|
|
664
|
+
}
|
|
665
|
+
// ---------------- lifecycle ----------------
|
|
666
|
+
/**
|
|
667
|
+
* Cancels any further proving. If `cancelJobsOnStop` was set, aborts all pending broker jobs
|
|
668
|
+
* (used on reorg). Otherwise jobs remain in the broker queue and can be reused on restart.
|
|
669
|
+
*/ cancel() {
|
|
670
|
+
this.cancelled = true;
|
|
671
|
+
this.resetSchedulerState(this.cancelJobsOnStop);
|
|
672
|
+
// Reject the proving state (and hence subTreeResult) so anyone awaiting the sub-tree result
|
|
673
|
+
// is released rather than hanging — matching TopTreeOrchestrator.cancel().
|
|
674
|
+
this.provingState?.cancel();
|
|
675
|
+
for (const [blockNumber, db] of this.dbs.entries()){
|
|
676
|
+
void db.close().catch((err)=>this.logger.error(`Error closing db for block ${blockNumber}`, err));
|
|
677
|
+
}
|
|
678
|
+
this.dbs.clear();
|
|
679
|
+
}
|
|
680
|
+
cancelInternal() {
|
|
681
|
+
this.cancel();
|
|
682
|
+
}
|
|
683
|
+
// ---------------- private: per-checkpoint init ----------------
|
|
684
|
+
/**
|
|
685
|
+
* Internal driver for the single-checkpoint init. Allocates the world-state fork,
|
|
686
|
+
* inserts L1-to-L2 messages, and creates the per-checkpoint proving state with this
|
|
687
|
+
* sub-tree as its parent. Only called once, from the `start` factory.
|
|
688
|
+
*/ async startCheckpoint(constants, l1ToL2Messages, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint) {
|
|
689
|
+
if (this.provingState) {
|
|
690
|
+
throw new Error('Checkpoint sub-tree already started.');
|
|
691
|
+
}
|
|
692
|
+
// Fork world state at the end of the immediately previous block.
|
|
693
|
+
const lastBlockNumber = headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber;
|
|
694
|
+
const db = await this.dbProvider.fork(lastBlockNumber);
|
|
695
|
+
const firstBlockNumber = BlockNumber(lastBlockNumber + 1);
|
|
696
|
+
this.dbs.set(firstBlockNumber, db);
|
|
697
|
+
// Get archive sibling path before any block in this checkpoint lands.
|
|
698
|
+
const lastArchiveSiblingPath = await getLastSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
699
|
+
// Insert all the l1 to l2 messages into the db. Get the states before and after the insertion.
|
|
700
|
+
const { lastL1ToL2MessageTreeSnapshot, lastL1ToL2MessageSubtreeRootSiblingPath, newL1ToL2MessageTreeSnapshot, newL1ToL2MessageSubtreeRootSiblingPath } = await this.updateL1ToL2MessageTree(l1ToL2Messages, db);
|
|
701
|
+
this.provingState = new CheckpointProvingState(/* index */ 0, constants, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint, lastArchiveSiblingPath, l1ToL2Messages, lastL1ToL2MessageTreeSnapshot, lastL1ToL2MessageSubtreeRootSiblingPath, newL1ToL2MessageTreeSnapshot, newL1ToL2MessageSubtreeRootSiblingPath, Number(this.epochNumber), /* isAlive */ ()=>!this.cancelled, /* onReject */ (reason)=>this.subTreeResult.reject(new Error(reason)));
|
|
702
|
+
}
|
|
703
|
+
// ---------------- private: per-block proof orchestration ----------------
|
|
704
|
+
async updateL1ToL2MessageTree(l1ToL2Messages, db) {
|
|
705
|
+
const lastL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
706
|
+
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);
|
|
707
|
+
// Update the local trees to include the new l1 to l2 messages.
|
|
708
|
+
await appendL1ToL2MessagesToTree(db, l1ToL2Messages);
|
|
709
|
+
const newL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
710
|
+
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);
|
|
711
|
+
return {
|
|
712
|
+
lastL1ToL2MessageTreeSnapshot,
|
|
713
|
+
lastL1ToL2MessageSubtreeRootSiblingPath,
|
|
714
|
+
newL1ToL2MessageTreeSnapshot,
|
|
715
|
+
newL1ToL2MessageSubtreeRootSiblingPath
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
// Updates the merkle trees for a transaction. The first enqueued job for a transaction.
|
|
719
|
+
async prepareBaseRollupInputs(tx, lastArchive, newL1ToL2MessageTreeSnapshot, startSpongeBlob, db) {
|
|
720
|
+
// These hints deliberately carry no recursive proof or verification key — see
|
|
721
|
+
// BaseRollupHintsWithoutProofAndVK. The tx's proof + VK are attached later in
|
|
722
|
+
// TxProvingState.getBaseRollupTypeAndInputs from the proven chonk-verifier / kernel / AVM
|
|
723
|
+
// proofs, which are required there and so cannot be silently omitted.
|
|
724
|
+
const start = performance.now();
|
|
725
|
+
const hints = await insertSideEffectsAndBuildBaseRollupHints(tx, lastArchive, newL1ToL2MessageTreeSnapshot, startSpongeBlob, this.proverId.toField(), db);
|
|
726
|
+
this.metrics.recordBaseRollupInputs(performance.now() - start);
|
|
727
|
+
const promises = [
|
|
728
|
+
MerkleTreeId.NOTE_HASH_TREE,
|
|
729
|
+
MerkleTreeId.NULLIFIER_TREE,
|
|
730
|
+
MerkleTreeId.PUBLIC_DATA_TREE
|
|
731
|
+
].map(async (id)=>{
|
|
732
|
+
return {
|
|
733
|
+
key: id,
|
|
734
|
+
value: await getTreeSnapshot(id, db)
|
|
735
|
+
};
|
|
736
|
+
});
|
|
737
|
+
const treeSnapshots = new Map((await Promise.all(promises)).map((obj)=>[
|
|
738
|
+
obj.key,
|
|
739
|
+
obj.value
|
|
740
|
+
]));
|
|
741
|
+
return [
|
|
742
|
+
hints,
|
|
743
|
+
treeSnapshots
|
|
744
|
+
];
|
|
745
|
+
}
|
|
746
|
+
// Executes the base rollup circuit and stores the output as intermediate state for the parent merge/root circuit.
|
|
747
|
+
// Executes the next level of merge if all inputs are available.
|
|
748
|
+
enqueueBaseRollup(provingState, txIndex) {
|
|
749
|
+
if (!provingState.verifyState()) {
|
|
750
|
+
this.logger.debug('Not running base rollup, state invalid');
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
if (!provingState.tryStartProvingBase(txIndex)) {
|
|
754
|
+
this.logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
758
|
+
const { processedTx } = txProvingState;
|
|
759
|
+
const { rollupType, inputs } = txProvingState.getBaseRollupTypeAndInputs();
|
|
760
|
+
this.logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
761
|
+
this.deferredProving(provingState, this.wrapCircuitCall(inputs instanceof PrivateTxBaseRollupPrivateInputs ? 'getPrivateTxBaseRollupProof' : 'getPublicTxBaseRollupProof', (signal)=>{
|
|
762
|
+
if (inputs instanceof PrivateTxBaseRollupPrivateInputs) {
|
|
763
|
+
return this.prover.getPrivateTxBaseRollupProof(inputs, signal, provingState.epochNumber);
|
|
764
|
+
} else {
|
|
765
|
+
return this.prover.getPublicTxBaseRollupProof(inputs, signal, provingState.epochNumber);
|
|
766
|
+
}
|
|
767
|
+
}, {
|
|
768
|
+
[Attributes.TX_HASH]: processedTx.hash.toString(),
|
|
769
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
770
|
+
}), (result)=>{
|
|
771
|
+
this.logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
772
|
+
validatePartialState(result.inputs.endTreeSnapshots, txProvingState.treeSnapshots);
|
|
773
|
+
const leafLocation = provingState.setBaseRollupProof(txIndex, result);
|
|
774
|
+
if (provingState.totalNumTxs === 1) {
|
|
775
|
+
this.checkAndEnqueueBlockRootRollup(provingState);
|
|
776
|
+
} else {
|
|
777
|
+
this.checkAndEnqueueNextMergeRollup(provingState, leafLocation);
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Route the tx's chonk-verifier dependency through the per-epoch context: read the
|
|
783
|
+
* cached promise (or enqueue if missing), then `.then(handleResult)` to progress to
|
|
784
|
+
* the base rollup once the proof lands.
|
|
785
|
+
*/ getOrEnqueueChonkVerifier(provingState, txIndex) {
|
|
786
|
+
if (!provingState.verifyState()) {
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
790
|
+
const txHash = txProvingState.processedTx.hash.toString();
|
|
791
|
+
const handleResult = (result)=>{
|
|
792
|
+
if (!provingState.verifyState()) {
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
txProvingState.setPublicChonkVerifierProof(result);
|
|
796
|
+
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
797
|
+
};
|
|
798
|
+
const promise = this.chonkCache.getOrCompute(txHash, (signal)=>this.prover.getPublicChonkVerifierProof(txProvingState.getPublicChonkVerifierPrivateInputs(), signal, this.epochNumber));
|
|
799
|
+
void promise.then(handleResult).catch((err)=>{
|
|
800
|
+
// The cache self-cleans on rejection, so a replacement sub-tree for this tx will see the
|
|
801
|
+
// miss and re-enqueue. But if this proving state is still active, the failure must abort
|
|
802
|
+
// it: otherwise the base rollup for this tx is never enqueued and the checkpoint (and
|
|
803
|
+
// epoch) orchestrators hang forever waiting for a proof that will never arrive.
|
|
804
|
+
if (err instanceof AbortError || !provingState.verifyState()) {
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
this.logger.error(`Chonk verifier proof failed for tx ${txHash}`, err);
|
|
808
|
+
provingState.reject(`Chonk verifier proof failed for tx ${txHash}: ${err}`);
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
// Executes the merge rollup circuit. Enqueues the next level of merge if all inputs are available.
|
|
812
|
+
enqueueMergeRollup(provingState, location) {
|
|
813
|
+
if (!provingState.verifyState()) {
|
|
814
|
+
this.logger.debug('Not running merge rollup. State no longer valid.');
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
if (!provingState.tryStartProvingMerge(location)) {
|
|
818
|
+
this.logger.debug('Merge rollup already started.');
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
const inputs = provingState.getMergeRollupInputs(location);
|
|
822
|
+
this.deferredProving(provingState, this.wrapCircuitCall('getTxMergeRollupProof', (signal)=>this.prover.getTxMergeRollupProof(inputs, signal, provingState.epochNumber), {
|
|
823
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-tx-merge'
|
|
824
|
+
}), (result)=>{
|
|
825
|
+
provingState.setMergeRollupProof(location, result);
|
|
826
|
+
this.checkAndEnqueueNextMergeRollup(provingState, location);
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
// Executes the block root rollup circuit.
|
|
830
|
+
enqueueBlockRootRollup(provingState) {
|
|
831
|
+
if (!provingState.verifyState()) {
|
|
832
|
+
this.logger.debug('Not running block root rollup, state no longer valid');
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
if (!provingState.tryStartProvingBlockRoot()) {
|
|
836
|
+
this.logger.debug('Block root rollup already started.');
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs();
|
|
840
|
+
this.logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
841
|
+
this.deferredProving(provingState, this.wrapCircuitCall('getBlockRootRollupProof', (signal)=>{
|
|
842
|
+
if (inputs instanceof BlockRootFirstRollupPrivateInputs) {
|
|
843
|
+
return this.prover.getBlockRootFirstRollupProof(inputs, signal, provingState.epochNumber);
|
|
844
|
+
} else if (inputs instanceof BlockRootSingleTxFirstRollupPrivateInputs) {
|
|
845
|
+
return this.prover.getBlockRootSingleTxFirstRollupProof(inputs, signal, provingState.epochNumber);
|
|
846
|
+
} else if (inputs instanceof BlockRootEmptyTxFirstRollupPrivateInputs) {
|
|
847
|
+
return this.prover.getBlockRootEmptyTxFirstRollupProof(inputs, signal, provingState.epochNumber);
|
|
848
|
+
} else if (inputs instanceof BlockRootSingleTxRollupPrivateInputs) {
|
|
849
|
+
return this.prover.getBlockRootSingleTxRollupProof(inputs, signal, provingState.epochNumber);
|
|
850
|
+
} else {
|
|
851
|
+
return this.prover.getBlockRootRollupProof(inputs, signal, provingState.epochNumber);
|
|
852
|
+
}
|
|
853
|
+
}, {
|
|
854
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
855
|
+
}), async (result)=>{
|
|
856
|
+
this.logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`, {
|
|
857
|
+
blockNumber: provingState.blockNumber,
|
|
858
|
+
checkpointIndex: provingState.parentCheckpoint.index,
|
|
859
|
+
...result.inputs.toInspect()
|
|
860
|
+
});
|
|
861
|
+
const leafLocation = provingState.setBlockRootRollupProof(result);
|
|
862
|
+
const checkpointProvingState = provingState.parentCheckpoint;
|
|
863
|
+
// Verification is called from both here and setBlockCompleted. Whichever runs last
|
|
864
|
+
// will be the first to see all three pieces (header, proof output, archive) and run the checks.
|
|
865
|
+
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
866
|
+
if (checkpointProvingState.totalNumBlocks === 1) {
|
|
867
|
+
this.checkAndEnqueueSubTreeResolution(checkpointProvingState);
|
|
868
|
+
} else {
|
|
869
|
+
this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
870
|
+
}
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
// Executes the base parity circuit. Enqueues the root parity circuit if all inputs are available.
|
|
874
|
+
enqueueBaseParityCircuit(checkpointProvingState, provingState, baseParityIndex) {
|
|
875
|
+
if (!provingState.verifyState()) {
|
|
876
|
+
this.logger.debug('Not running base parity. State no longer valid.');
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
if (!provingState.tryStartProvingBaseParity(baseParityIndex)) {
|
|
880
|
+
this.logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
const inputs = checkpointProvingState.getBaseParityInputs(baseParityIndex);
|
|
884
|
+
this.deferredProving(provingState, this.wrapCircuitCall('getBaseParityProof', (signal)=>this.prover.getBaseParityProof(inputs, signal, provingState.epochNumber), {
|
|
885
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'parity-base'
|
|
886
|
+
}), (provingOutput)=>{
|
|
887
|
+
provingState.setBaseParityProof(baseParityIndex, provingOutput);
|
|
888
|
+
this.checkAndEnqueueRootParityCircuit(provingState);
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
checkAndEnqueueRootParityCircuit(provingState) {
|
|
892
|
+
if (!provingState.isReadyForRootParity()) {
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
this.enqueueRootParityCircuit(provingState);
|
|
896
|
+
}
|
|
897
|
+
// Runs the root parity circuit and stores the outputs.
|
|
898
|
+
// Enqueues the block root rollup if all inputs are available.
|
|
899
|
+
enqueueRootParityCircuit(provingState) {
|
|
900
|
+
if (!provingState.verifyState()) {
|
|
901
|
+
this.logger.debug('Not running root parity. State no longer valid.');
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
if (!provingState.tryStartProvingRootParity()) {
|
|
905
|
+
this.logger.debug('Root parity already started.');
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
const inputs = provingState.getParityRootInputs();
|
|
909
|
+
this.deferredProving(provingState, this.wrapCircuitCall('getRootParityProof', (signal)=>this.prover.getRootParityProof(inputs, signal, provingState.epochNumber), {
|
|
910
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'parity-root'
|
|
911
|
+
}), (result)=>{
|
|
912
|
+
provingState.setRootParityProof(result);
|
|
913
|
+
this.checkAndEnqueueBlockRootRollup(provingState);
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
// Executes the block merge rollup circuit.
|
|
917
|
+
enqueueBlockMergeRollup(provingState, location) {
|
|
918
|
+
if (!provingState.verifyState()) {
|
|
919
|
+
this.logger.debug('Not running block merge rollup. State no longer valid.');
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
if (!provingState.tryStartProvingBlockMerge(location)) {
|
|
923
|
+
this.logger.debug('Block merge rollup already started.');
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
const inputs = provingState.getBlockMergeRollupInputs(location);
|
|
927
|
+
this.deferredProving(provingState, this.wrapCircuitCall('getBlockMergeRollupProof', (signal)=>this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber), {
|
|
928
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-block-merge'
|
|
929
|
+
}), (result)=>{
|
|
930
|
+
this.logger.debug(`Completed block merge rollup proof for checkpoint ${provingState.index}`, {
|
|
931
|
+
checkpointIndex: provingState.index,
|
|
932
|
+
mergeLocation: location,
|
|
933
|
+
...result.inputs.toInspect()
|
|
934
|
+
});
|
|
935
|
+
provingState.setBlockMergeRollupProof(location, result);
|
|
936
|
+
this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
checkAndEnqueueNextMergeRollup(provingState, currentLocation) {
|
|
940
|
+
if (!provingState.isReadyForMergeRollup(currentLocation)) {
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
944
|
+
if (parentLocation.level === 0) {
|
|
945
|
+
this.checkAndEnqueueBlockRootRollup(provingState);
|
|
946
|
+
} else {
|
|
947
|
+
this.enqueueMergeRollup(provingState, parentLocation);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
checkAndEnqueueBlockRootRollup(provingState) {
|
|
951
|
+
if (!provingState.isReadyForBlockRootRollup()) {
|
|
952
|
+
this.logger.debug('Not ready for block root rollup');
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
this.enqueueBlockRootRollup(provingState);
|
|
956
|
+
}
|
|
957
|
+
checkAndEnqueueNextBlockMergeRollup(provingState, currentLocation) {
|
|
958
|
+
if (!provingState.isReadyForBlockMerge(currentLocation)) {
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
962
|
+
if (parentLocation.level === 0) {
|
|
963
|
+
this.checkAndEnqueueSubTreeResolution(provingState);
|
|
964
|
+
} else {
|
|
965
|
+
this.enqueueBlockMergeRollup(provingState, parentLocation);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* Sub-tree analogue of the orchestrator's `checkAndEnqueueCheckpointRootRollup`:
|
|
970
|
+
* resolves the sub-tree promise with the block-level proof outputs once they're all ready,
|
|
971
|
+
* instead of escalating to the checkpoint root rollup.
|
|
972
|
+
*/ checkAndEnqueueSubTreeResolution(provingState) {
|
|
973
|
+
const proofs = provingState.getSubTreeOutputProofs();
|
|
974
|
+
const nonEmpty = proofs.filter((p)=>!!p);
|
|
975
|
+
if (proofs.length !== nonEmpty.length) {
|
|
976
|
+
// Block merge tree not fully resolved yet — retried as more block proofs land.
|
|
977
|
+
return;
|
|
978
|
+
}
|
|
979
|
+
this.subTreeResult.resolve({
|
|
980
|
+
blockProofOutputs: nonEmpty,
|
|
981
|
+
previousArchiveSiblingPath: provingState.getLastArchiveSiblingPath()
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
* Executes the VM circuit for a public function. Enqueues the base rollup once the
|
|
986
|
+
* tx's chonk-verifier + VM proofs are both ready.
|
|
987
|
+
*/ enqueueVM(provingState, txIndex) {
|
|
988
|
+
if (!provingState.verifyState()) {
|
|
989
|
+
this.logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
993
|
+
this.deferredProving(provingState, this.wrapCircuitCall('getAvmProof', async (signal)=>{
|
|
994
|
+
const inputs = txProvingState.getAvmInputs();
|
|
995
|
+
return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
|
|
996
|
+
}, {
|
|
997
|
+
[Attributes.TX_HASH]: txProvingState.processedTx.hash.toString()
|
|
998
|
+
}), (proof)=>{
|
|
999
|
+
this.logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1000
|
+
txProvingState.setAvmProof(proof);
|
|
1001
|
+
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
checkAndEnqueueBaseRollup(provingState, txIndex) {
|
|
1005
|
+
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
1006
|
+
if (!txProvingState.ready()) {
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
// All upstream proofs (chonk verifier and, if required, vm) are ready — proceed to the base rollup.
|
|
1010
|
+
this.logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1011
|
+
this.enqueueBaseRollup(provingState, txIndex);
|
|
1012
|
+
}
|
|
1013
|
+
// Flagged as protected so unit tests can override.
|
|
1014
|
+
async verifyBuiltBlockAgainstSyncedState(provingState) {
|
|
1015
|
+
const builtBlockHeader = provingState.getBuiltBlockHeader();
|
|
1016
|
+
if (!builtBlockHeader) {
|
|
1017
|
+
this.logger.debug('Block header not built yet, skipping header check.');
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
const output = provingState.getBlockRootRollupOutput();
|
|
1021
|
+
if (!output) {
|
|
1022
|
+
this.logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
const newArchive = provingState.getBuiltArchive();
|
|
1026
|
+
if (!newArchive) {
|
|
1027
|
+
this.logger.debug('Archive snapshot not yet captured, skipping header check.');
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
const header = await buildHeaderFromCircuitOutputs(output);
|
|
1031
|
+
if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
|
|
1032
|
+
this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
1033
|
+
provingState.reject(`Block header hash mismatch.`);
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
const blockNumber = provingState.blockNumber;
|
|
1037
|
+
const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
|
|
1038
|
+
if (!syncedArchive.equals(newArchive)) {
|
|
1039
|
+
this.logger.error(`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(syncedArchive)} but built ${inspect(newArchive)}`);
|
|
1040
|
+
provingState.reject(`Archive tree mismatch.`);
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
const circuitArchive = output.newArchive;
|
|
1044
|
+
if (!newArchive.equals(circuitArchive)) {
|
|
1045
|
+
this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
1046
|
+
provingState.reject(`New archive mismatch.`);
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
getDbForBlock(blockNumber) {
|
|
1051
|
+
const db = this.dbs.get(blockNumber);
|
|
1052
|
+
if (!db) {
|
|
1053
|
+
throw new Error(`World state fork for block ${blockNumber} not found.`);
|
|
1054
|
+
}
|
|
1055
|
+
return db;
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Wraps a circuit call with a tracer span and circuit attributes. Replaces the
|
|
1059
|
+
* `ProvingScheduler.wrapCircuitCall` indirection that used to live on the abstract base.
|
|
1060
|
+
*/ wrapCircuitCall(circuitName, fn, attributes = {}) {
|
|
1061
|
+
return wrapCallbackInSpan(this.tracer, `CheckpointSubTreeOrchestrator.prover.${circuitName}`, {
|
|
1062
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
|
|
1063
|
+
...attributes
|
|
1064
|
+
}, fn);
|
|
1065
|
+
}
|
|
1066
|
+
}
|