@aztec/aztec-node 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f
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/aztec-node/block_response_helpers.d.ts +25 -0
- package/dest/aztec-node/block_response_helpers.d.ts.map +1 -0
- package/dest/aztec-node/block_response_helpers.js +112 -0
- package/dest/aztec-node/config.d.ts +14 -8
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +16 -8
- package/dest/aztec-node/node_metrics.d.ts +1 -1
- package/dest/aztec-node/node_metrics.d.ts.map +1 -1
- package/dest/aztec-node/node_metrics.js +9 -16
- package/dest/aztec-node/public_data_overrides.d.ts +13 -0
- package/dest/aztec-node/public_data_overrides.d.ts.map +1 -0
- package/dest/aztec-node/public_data_overrides.js +21 -0
- package/dest/aztec-node/server.d.ts +101 -187
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +1528 -513
- package/dest/sentinel/config.d.ts +3 -2
- package/dest/sentinel/config.d.ts.map +1 -1
- package/dest/sentinel/config.js +15 -5
- package/dest/sentinel/factory.d.ts +5 -3
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +5 -5
- package/dest/sentinel/sentinel.d.ts +137 -12
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +273 -100
- package/dest/sentinel/store.d.ts +8 -8
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +33 -21
- package/dest/test/index.d.ts +3 -3
- package/dest/test/index.d.ts.map +1 -1
- package/package.json +28 -26
- package/src/aztec-node/block_response_helpers.ts +161 -0
- package/src/aztec-node/config.ts +36 -16
- package/src/aztec-node/node_metrics.ts +6 -17
- package/src/aztec-node/public_data_overrides.ts +35 -0
- package/src/aztec-node/server.ts +1282 -663
- package/src/sentinel/README.md +103 -0
- package/src/sentinel/config.ts +18 -6
- package/src/sentinel/factory.ts +9 -11
- package/src/sentinel/sentinel.ts +336 -109
- package/src/sentinel/store.ts +35 -27
- package/src/test/index.ts +2 -2
|
@@ -1,55 +1,499 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
function _ts_add_disposable_resource(env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() {
|
|
16
|
+
try {
|
|
17
|
+
inner.call(this);
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return Promise.reject(e);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
env.stack.push({
|
|
23
|
+
value: value,
|
|
24
|
+
dispose: dispose,
|
|
25
|
+
async: async
|
|
26
|
+
});
|
|
27
|
+
} else if (async) {
|
|
28
|
+
env.stack.push({
|
|
29
|
+
async: true
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
6
33
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
34
|
+
function _ts_dispose_resources(env) {
|
|
35
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
36
|
+
var e = new Error(message);
|
|
37
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
38
|
+
};
|
|
39
|
+
return (_ts_dispose_resources = function _ts_dispose_resources(env) {
|
|
40
|
+
function fail(e) {
|
|
41
|
+
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
42
|
+
env.hasError = true;
|
|
43
|
+
}
|
|
44
|
+
var r, s = 0;
|
|
45
|
+
function next() {
|
|
46
|
+
while(r = env.stack.pop()){
|
|
47
|
+
try {
|
|
48
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
49
|
+
if (r.dispose) {
|
|
50
|
+
var result = r.dispose.call(r.value);
|
|
51
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
52
|
+
fail(e);
|
|
53
|
+
return next();
|
|
54
|
+
});
|
|
55
|
+
} else s |= 1;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
fail(e);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
61
|
+
if (env.hasError) throw env.error;
|
|
62
|
+
}
|
|
63
|
+
return next();
|
|
64
|
+
})(env);
|
|
65
|
+
}
|
|
66
|
+
function applyDecs2203RFactory() {
|
|
67
|
+
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
68
|
+
return function addInitializer(initializer) {
|
|
69
|
+
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
70
|
+
assertCallable(initializer, "An initializer");
|
|
71
|
+
initializers.push(initializer);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
|
|
75
|
+
var kindStr;
|
|
76
|
+
switch(kind){
|
|
77
|
+
case 1:
|
|
78
|
+
kindStr = "accessor";
|
|
79
|
+
break;
|
|
80
|
+
case 2:
|
|
81
|
+
kindStr = "method";
|
|
82
|
+
break;
|
|
83
|
+
case 3:
|
|
84
|
+
kindStr = "getter";
|
|
85
|
+
break;
|
|
86
|
+
case 4:
|
|
87
|
+
kindStr = "setter";
|
|
88
|
+
break;
|
|
89
|
+
default:
|
|
90
|
+
kindStr = "field";
|
|
91
|
+
}
|
|
92
|
+
var ctx = {
|
|
93
|
+
kind: kindStr,
|
|
94
|
+
name: isPrivate ? "#" + name : name,
|
|
95
|
+
static: isStatic,
|
|
96
|
+
private: isPrivate,
|
|
97
|
+
metadata: metadata
|
|
98
|
+
};
|
|
99
|
+
var decoratorFinishedRef = {
|
|
100
|
+
v: false
|
|
101
|
+
};
|
|
102
|
+
ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
|
|
103
|
+
var get, set;
|
|
104
|
+
if (kind === 0) {
|
|
105
|
+
if (isPrivate) {
|
|
106
|
+
get = desc.get;
|
|
107
|
+
set = desc.set;
|
|
108
|
+
} else {
|
|
109
|
+
get = function() {
|
|
110
|
+
return this[name];
|
|
111
|
+
};
|
|
112
|
+
set = function(v) {
|
|
113
|
+
this[name] = v;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
} else if (kind === 2) {
|
|
117
|
+
get = function() {
|
|
118
|
+
return desc.value;
|
|
119
|
+
};
|
|
120
|
+
} else {
|
|
121
|
+
if (kind === 1 || kind === 3) {
|
|
122
|
+
get = function() {
|
|
123
|
+
return desc.get.call(this);
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (kind === 1 || kind === 4) {
|
|
127
|
+
set = function(v) {
|
|
128
|
+
desc.set.call(this, v);
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
ctx.access = get && set ? {
|
|
133
|
+
get: get,
|
|
134
|
+
set: set
|
|
135
|
+
} : get ? {
|
|
136
|
+
get: get
|
|
137
|
+
} : {
|
|
138
|
+
set: set
|
|
139
|
+
};
|
|
140
|
+
try {
|
|
141
|
+
return dec(value, ctx);
|
|
142
|
+
} finally{
|
|
143
|
+
decoratorFinishedRef.v = true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function assertNotFinished(decoratorFinishedRef, fnName) {
|
|
147
|
+
if (decoratorFinishedRef.v) {
|
|
148
|
+
throw new Error("attempted to call " + fnName + " after decoration was finished");
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function assertCallable(fn, hint) {
|
|
152
|
+
if (typeof fn !== "function") {
|
|
153
|
+
throw new TypeError(hint + " must be a function");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function assertValidReturnValue(kind, value) {
|
|
157
|
+
var type = typeof value;
|
|
158
|
+
if (kind === 1) {
|
|
159
|
+
if (type !== "object" || value === null) {
|
|
160
|
+
throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
161
|
+
}
|
|
162
|
+
if (value.get !== undefined) {
|
|
163
|
+
assertCallable(value.get, "accessor.get");
|
|
164
|
+
}
|
|
165
|
+
if (value.set !== undefined) {
|
|
166
|
+
assertCallable(value.set, "accessor.set");
|
|
167
|
+
}
|
|
168
|
+
if (value.init !== undefined) {
|
|
169
|
+
assertCallable(value.init, "accessor.init");
|
|
170
|
+
}
|
|
171
|
+
} else if (type !== "function") {
|
|
172
|
+
var hint;
|
|
173
|
+
if (kind === 0) {
|
|
174
|
+
hint = "field";
|
|
175
|
+
} else if (kind === 10) {
|
|
176
|
+
hint = "class";
|
|
177
|
+
} else {
|
|
178
|
+
hint = "method";
|
|
179
|
+
}
|
|
180
|
+
throw new TypeError(hint + " decorators must return a function or void 0");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
|
|
184
|
+
var decs = decInfo[0];
|
|
185
|
+
var desc, init, value;
|
|
186
|
+
if (isPrivate) {
|
|
187
|
+
if (kind === 0 || kind === 1) {
|
|
188
|
+
desc = {
|
|
189
|
+
get: decInfo[3],
|
|
190
|
+
set: decInfo[4]
|
|
191
|
+
};
|
|
192
|
+
} else if (kind === 3) {
|
|
193
|
+
desc = {
|
|
194
|
+
get: decInfo[3]
|
|
195
|
+
};
|
|
196
|
+
} else if (kind === 4) {
|
|
197
|
+
desc = {
|
|
198
|
+
set: decInfo[3]
|
|
199
|
+
};
|
|
200
|
+
} else {
|
|
201
|
+
desc = {
|
|
202
|
+
value: decInfo[3]
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
} else if (kind !== 0) {
|
|
206
|
+
desc = Object.getOwnPropertyDescriptor(base, name);
|
|
207
|
+
}
|
|
208
|
+
if (kind === 1) {
|
|
209
|
+
value = {
|
|
210
|
+
get: desc.get,
|
|
211
|
+
set: desc.set
|
|
212
|
+
};
|
|
213
|
+
} else if (kind === 2) {
|
|
214
|
+
value = desc.value;
|
|
215
|
+
} else if (kind === 3) {
|
|
216
|
+
value = desc.get;
|
|
217
|
+
} else if (kind === 4) {
|
|
218
|
+
value = desc.set;
|
|
219
|
+
}
|
|
220
|
+
var newValue, get, set;
|
|
221
|
+
if (typeof decs === "function") {
|
|
222
|
+
newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
223
|
+
if (newValue !== void 0) {
|
|
224
|
+
assertValidReturnValue(kind, newValue);
|
|
225
|
+
if (kind === 0) {
|
|
226
|
+
init = newValue;
|
|
227
|
+
} else if (kind === 1) {
|
|
228
|
+
init = newValue.init;
|
|
229
|
+
get = newValue.get || value.get;
|
|
230
|
+
set = newValue.set || value.set;
|
|
231
|
+
value = {
|
|
232
|
+
get: get,
|
|
233
|
+
set: set
|
|
234
|
+
};
|
|
235
|
+
} else {
|
|
236
|
+
value = newValue;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
for(var i = decs.length - 1; i >= 0; i--){
|
|
241
|
+
var dec = decs[i];
|
|
242
|
+
newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
243
|
+
if (newValue !== void 0) {
|
|
244
|
+
assertValidReturnValue(kind, newValue);
|
|
245
|
+
var newInit;
|
|
246
|
+
if (kind === 0) {
|
|
247
|
+
newInit = newValue;
|
|
248
|
+
} else if (kind === 1) {
|
|
249
|
+
newInit = newValue.init;
|
|
250
|
+
get = newValue.get || value.get;
|
|
251
|
+
set = newValue.set || value.set;
|
|
252
|
+
value = {
|
|
253
|
+
get: get,
|
|
254
|
+
set: set
|
|
255
|
+
};
|
|
256
|
+
} else {
|
|
257
|
+
value = newValue;
|
|
258
|
+
}
|
|
259
|
+
if (newInit !== void 0) {
|
|
260
|
+
if (init === void 0) {
|
|
261
|
+
init = newInit;
|
|
262
|
+
} else if (typeof init === "function") {
|
|
263
|
+
init = [
|
|
264
|
+
init,
|
|
265
|
+
newInit
|
|
266
|
+
];
|
|
267
|
+
} else {
|
|
268
|
+
init.push(newInit);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (kind === 0 || kind === 1) {
|
|
275
|
+
if (init === void 0) {
|
|
276
|
+
init = function(instance, init) {
|
|
277
|
+
return init;
|
|
278
|
+
};
|
|
279
|
+
} else if (typeof init !== "function") {
|
|
280
|
+
var ownInitializers = init;
|
|
281
|
+
init = function(instance, init) {
|
|
282
|
+
var value = init;
|
|
283
|
+
for(var i = 0; i < ownInitializers.length; i++){
|
|
284
|
+
value = ownInitializers[i].call(instance, value);
|
|
285
|
+
}
|
|
286
|
+
return value;
|
|
287
|
+
};
|
|
288
|
+
} else {
|
|
289
|
+
var originalInitializer = init;
|
|
290
|
+
init = function(instance, init) {
|
|
291
|
+
return originalInitializer.call(instance, init);
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
ret.push(init);
|
|
295
|
+
}
|
|
296
|
+
if (kind !== 0) {
|
|
297
|
+
if (kind === 1) {
|
|
298
|
+
desc.get = value.get;
|
|
299
|
+
desc.set = value.set;
|
|
300
|
+
} else if (kind === 2) {
|
|
301
|
+
desc.value = value;
|
|
302
|
+
} else if (kind === 3) {
|
|
303
|
+
desc.get = value;
|
|
304
|
+
} else if (kind === 4) {
|
|
305
|
+
desc.set = value;
|
|
306
|
+
}
|
|
307
|
+
if (isPrivate) {
|
|
308
|
+
if (kind === 1) {
|
|
309
|
+
ret.push(function(instance, args) {
|
|
310
|
+
return value.get.call(instance, args);
|
|
311
|
+
});
|
|
312
|
+
ret.push(function(instance, args) {
|
|
313
|
+
return value.set.call(instance, args);
|
|
314
|
+
});
|
|
315
|
+
} else if (kind === 2) {
|
|
316
|
+
ret.push(value);
|
|
317
|
+
} else {
|
|
318
|
+
ret.push(function(instance, args) {
|
|
319
|
+
return value.call(instance, args);
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
} else {
|
|
323
|
+
Object.defineProperty(base, name, desc);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function applyMemberDecs(Class, decInfos, metadata) {
|
|
328
|
+
var ret = [];
|
|
329
|
+
var protoInitializers;
|
|
330
|
+
var staticInitializers;
|
|
331
|
+
var existingProtoNonFields = new Map();
|
|
332
|
+
var existingStaticNonFields = new Map();
|
|
333
|
+
for(var i = 0; i < decInfos.length; i++){
|
|
334
|
+
var decInfo = decInfos[i];
|
|
335
|
+
if (!Array.isArray(decInfo)) continue;
|
|
336
|
+
var kind = decInfo[1];
|
|
337
|
+
var name = decInfo[2];
|
|
338
|
+
var isPrivate = decInfo.length > 3;
|
|
339
|
+
var isStatic = kind >= 5;
|
|
340
|
+
var base;
|
|
341
|
+
var initializers;
|
|
342
|
+
if (isStatic) {
|
|
343
|
+
base = Class;
|
|
344
|
+
kind = kind - 5;
|
|
345
|
+
staticInitializers = staticInitializers || [];
|
|
346
|
+
initializers = staticInitializers;
|
|
347
|
+
} else {
|
|
348
|
+
base = Class.prototype;
|
|
349
|
+
protoInitializers = protoInitializers || [];
|
|
350
|
+
initializers = protoInitializers;
|
|
351
|
+
}
|
|
352
|
+
if (kind !== 0 && !isPrivate) {
|
|
353
|
+
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
|
|
354
|
+
var existingKind = existingNonFields.get(name) || 0;
|
|
355
|
+
if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
|
|
356
|
+
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);
|
|
357
|
+
} else if (!existingKind && kind > 2) {
|
|
358
|
+
existingNonFields.set(name, kind);
|
|
359
|
+
} else {
|
|
360
|
+
existingNonFields.set(name, true);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
|
|
364
|
+
}
|
|
365
|
+
pushInitializers(ret, protoInitializers);
|
|
366
|
+
pushInitializers(ret, staticInitializers);
|
|
367
|
+
return ret;
|
|
368
|
+
}
|
|
369
|
+
function pushInitializers(ret, initializers) {
|
|
370
|
+
if (initializers) {
|
|
371
|
+
ret.push(function(instance) {
|
|
372
|
+
for(var i = 0; i < initializers.length; i++){
|
|
373
|
+
initializers[i].call(instance);
|
|
374
|
+
}
|
|
375
|
+
return instance;
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
function applyClassDecs(targetClass, classDecs, metadata) {
|
|
380
|
+
if (classDecs.length > 0) {
|
|
381
|
+
var initializers = [];
|
|
382
|
+
var newClass = targetClass;
|
|
383
|
+
var name = targetClass.name;
|
|
384
|
+
for(var i = classDecs.length - 1; i >= 0; i--){
|
|
385
|
+
var decoratorFinishedRef = {
|
|
386
|
+
v: false
|
|
387
|
+
};
|
|
388
|
+
try {
|
|
389
|
+
var nextNewClass = classDecs[i](newClass, {
|
|
390
|
+
kind: "class",
|
|
391
|
+
name: name,
|
|
392
|
+
addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
|
|
393
|
+
metadata
|
|
394
|
+
});
|
|
395
|
+
} finally{
|
|
396
|
+
decoratorFinishedRef.v = true;
|
|
397
|
+
}
|
|
398
|
+
if (nextNewClass !== undefined) {
|
|
399
|
+
assertValidReturnValue(10, nextNewClass);
|
|
400
|
+
newClass = nextNewClass;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return [
|
|
404
|
+
defineMetadata(newClass, metadata),
|
|
405
|
+
function() {
|
|
406
|
+
for(var i = 0; i < initializers.length; i++){
|
|
407
|
+
initializers[i].call(newClass);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
];
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function defineMetadata(Class, metadata) {
|
|
414
|
+
return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
|
|
415
|
+
configurable: true,
|
|
416
|
+
enumerable: true,
|
|
417
|
+
value: metadata
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
|
|
421
|
+
if (parentClass !== void 0) {
|
|
422
|
+
var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
423
|
+
}
|
|
424
|
+
var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
|
|
425
|
+
var e = applyMemberDecs(targetClass, memberDecs, metadata);
|
|
426
|
+
if (!classDecs.length) defineMetadata(targetClass, metadata);
|
|
427
|
+
return {
|
|
428
|
+
e: e,
|
|
429
|
+
get c () {
|
|
430
|
+
return applyClassDecs(targetClass, classDecs, metadata);
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
436
|
+
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
437
|
+
}
|
|
438
|
+
var _dec, _initProto;
|
|
439
|
+
import { L1ToL2MessagesNotReadyError, createArchiver } from '@aztec/archiver';
|
|
440
|
+
import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
|
|
441
|
+
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
442
|
+
import { createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
443
|
+
import { Blob } from '@aztec/blob-lib';
|
|
12
444
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
13
445
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
14
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
446
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
15
447
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
448
|
+
import { pickL1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
449
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
450
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
18
451
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
19
452
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
20
453
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
21
454
|
import { createLogger } from '@aztec/foundation/log';
|
|
455
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
22
456
|
import { count } from '@aztec/foundation/string';
|
|
23
457
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
24
458
|
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
459
|
+
import { isErrorClass } from '@aztec/foundation/types';
|
|
25
460
|
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
26
461
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
27
|
-
import {
|
|
28
|
-
import { createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
462
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
463
|
+
import { createP2PClient, createTxValidatorForAcceptingTxsOverRPC, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
29
464
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
465
|
+
import { createProverNode } from '@aztec/prover-node';
|
|
466
|
+
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
467
|
+
import { FeeProviderImpl, GlobalVariableBuilder, SequencerClient, createAutomineSequencer } from '@aztec/sequencer-client';
|
|
468
|
+
import { PublicContractsDB, PublicProcessorFactory } from '@aztec/simulator/server';
|
|
469
|
+
import { AttestationsBlockWatcher, AttestedInvalidProposalWatcher, BroadcastedInvalidCheckpointProposalWatcher, CheckpointEquivocationWatcher, DataWithholdingWatcher, createSlasher } from '@aztec/slasher';
|
|
470
|
+
import { STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS } from '@aztec/standard-contracts/multi-call-entrypoint';
|
|
34
471
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
35
472
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
36
|
-
import {
|
|
473
|
+
import { BlockHash, BlockTag, inspectBlockParameter } from '@aztec/stdlib/block';
|
|
474
|
+
import { CheckpointReexecutionTracker } from '@aztec/stdlib/checkpoint';
|
|
37
475
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
38
476
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
39
477
|
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
40
478
|
import { tryStop } from '@aztec/stdlib/interfaces/server';
|
|
41
|
-
import {
|
|
42
|
-
import {
|
|
479
|
+
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
480
|
+
import { InboxLeaf, appendL1ToL2MessagesToTree } from '@aztec/stdlib/messaging';
|
|
481
|
+
import { MIN_EXECUTION_TIME } from '@aztec/stdlib/timetable';
|
|
43
482
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
44
483
|
import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
45
484
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
46
485
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
47
|
-
import { NodeKeystoreAdapter, ValidatorClient,
|
|
48
|
-
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
49
|
-
import { createPublicClient
|
|
486
|
+
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createProposalHandler, createValidatorClient } from '@aztec/validator-client';
|
|
487
|
+
import { createWorldState, createWorldStateSynchronizer } from '@aztec/world-state';
|
|
488
|
+
import { createPublicClient } from 'viem';
|
|
50
489
|
import { createSentinel } from '../sentinel/factory.js';
|
|
490
|
+
import { blockResponseFromBlockData, blockResponseFromL2Block, checkpointResponseFromCheckpointData, checkpointResponseFromPublishedCheckpoint, projectProposedToCheckpointResponse } from './block_response_helpers.js';
|
|
51
491
|
import { createKeyStoreForValidator } from './config.js';
|
|
52
492
|
import { NodeMetrics } from './node_metrics.js';
|
|
493
|
+
import { applyPublicDataOverrides } from './public_data_overrides.js';
|
|
494
|
+
_dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
495
|
+
[Attributes.TX_HASH]: tx.getTxHash().toString()
|
|
496
|
+
}));
|
|
53
497
|
/**
|
|
54
498
|
* The aztec node.
|
|
55
499
|
*/ export class AztecNodeService {
|
|
@@ -61,22 +505,41 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
61
505
|
l1ToL2MessageSource;
|
|
62
506
|
worldStateSynchronizer;
|
|
63
507
|
sequencer;
|
|
508
|
+
proverNode;
|
|
64
509
|
slasherClient;
|
|
65
510
|
validatorsSentinel;
|
|
66
|
-
|
|
511
|
+
stopStartedWatchers;
|
|
67
512
|
l1ChainId;
|
|
68
513
|
version;
|
|
69
514
|
globalVariableBuilder;
|
|
515
|
+
feeProvider;
|
|
70
516
|
epochCache;
|
|
71
517
|
packageVersion;
|
|
72
|
-
|
|
518
|
+
peerProofVerifier;
|
|
519
|
+
rpcProofVerifier;
|
|
73
520
|
telemetry;
|
|
74
521
|
log;
|
|
522
|
+
blobClient;
|
|
523
|
+
validatorClient;
|
|
524
|
+
keyStoreManager;
|
|
525
|
+
debugLogStore;
|
|
526
|
+
automineSequencer;
|
|
527
|
+
static{
|
|
528
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
529
|
+
[
|
|
530
|
+
_dec,
|
|
531
|
+
2,
|
|
532
|
+
"simulatePublicCalls"
|
|
533
|
+
]
|
|
534
|
+
], []));
|
|
535
|
+
}
|
|
75
536
|
metrics;
|
|
76
537
|
// Prevent two snapshot operations to happen simultaneously
|
|
77
538
|
isUploadingSnapshot;
|
|
539
|
+
// Saved minTxsPerBlock used by `pauseSequencer` to restore production-sequencer config on resume.
|
|
540
|
+
sequencerPausedMinTxsPerBlock;
|
|
78
541
|
tracer;
|
|
79
|
-
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel,
|
|
542
|
+
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, stopStartedWatchers, l1ChainId, version, globalVariableBuilder, feeProvider, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry = getTelemetryClient(), log = createLogger('node'), blobClient, validatorClient, keyStoreManager, debugLogStore = new NullDebugLogStore(), automineSequencer){
|
|
80
543
|
this.config = config;
|
|
81
544
|
this.p2pClient = p2pClient;
|
|
82
545
|
this.blockSource = blockSource;
|
|
@@ -85,29 +548,280 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
85
548
|
this.l1ToL2MessageSource = l1ToL2MessageSource;
|
|
86
549
|
this.worldStateSynchronizer = worldStateSynchronizer;
|
|
87
550
|
this.sequencer = sequencer;
|
|
551
|
+
this.proverNode = proverNode;
|
|
88
552
|
this.slasherClient = slasherClient;
|
|
89
553
|
this.validatorsSentinel = validatorsSentinel;
|
|
90
|
-
this.
|
|
554
|
+
this.stopStartedWatchers = stopStartedWatchers;
|
|
91
555
|
this.l1ChainId = l1ChainId;
|
|
92
556
|
this.version = version;
|
|
93
557
|
this.globalVariableBuilder = globalVariableBuilder;
|
|
558
|
+
this.feeProvider = feeProvider;
|
|
94
559
|
this.epochCache = epochCache;
|
|
95
560
|
this.packageVersion = packageVersion;
|
|
96
|
-
this.
|
|
561
|
+
this.peerProofVerifier = peerProofVerifier;
|
|
562
|
+
this.rpcProofVerifier = rpcProofVerifier;
|
|
97
563
|
this.telemetry = telemetry;
|
|
98
564
|
this.log = log;
|
|
99
|
-
this.
|
|
565
|
+
this.blobClient = blobClient;
|
|
566
|
+
this.validatorClient = validatorClient;
|
|
567
|
+
this.keyStoreManager = keyStoreManager;
|
|
568
|
+
this.debugLogStore = debugLogStore;
|
|
569
|
+
this.automineSequencer = automineSequencer;
|
|
570
|
+
this.isUploadingSnapshot = (_initProto(this), false);
|
|
100
571
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
101
572
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
102
573
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
103
|
-
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config
|
|
574
|
+
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, pickL1ContractAddresses(config));
|
|
575
|
+
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
576
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
577
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
578
|
+
if (debugLogStore.isEnabled && config.realProofs) {
|
|
579
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */ getProofVerifier() {
|
|
583
|
+
return this.rpcProofVerifier;
|
|
104
584
|
}
|
|
105
585
|
async getWorldStateSyncStatus() {
|
|
106
586
|
const status = await this.worldStateSynchronizer.status();
|
|
107
587
|
return status.syncSummary;
|
|
108
588
|
}
|
|
109
|
-
|
|
110
|
-
|
|
589
|
+
async getChainTips() {
|
|
590
|
+
const { proposed, checkpointed, proven, finalized } = await this.blockSource.getL2Tips();
|
|
591
|
+
return {
|
|
592
|
+
proposed,
|
|
593
|
+
checkpointed,
|
|
594
|
+
proven,
|
|
595
|
+
finalized
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
getCheckpointsData(query) {
|
|
599
|
+
return this.blockSource.getCheckpointsData(query);
|
|
600
|
+
}
|
|
601
|
+
async getBlockNumber(tip) {
|
|
602
|
+
if (tip === undefined || tip === 'proposed') {
|
|
603
|
+
return this.blockSource.getBlockNumber();
|
|
604
|
+
}
|
|
605
|
+
return await this.blockSource.getBlockNumber({
|
|
606
|
+
tag: tip
|
|
607
|
+
}) ?? BlockNumber.ZERO;
|
|
608
|
+
}
|
|
609
|
+
async getCheckpointNumber(tip) {
|
|
610
|
+
const tips = await this.blockSource.getL2Tips();
|
|
611
|
+
switch(tip){
|
|
612
|
+
case undefined:
|
|
613
|
+
case 'checkpointed':
|
|
614
|
+
return tips.checkpointed.checkpoint.number;
|
|
615
|
+
case 'proposed':
|
|
616
|
+
return tips.proposedCheckpoint.checkpoint.number;
|
|
617
|
+
case 'proven':
|
|
618
|
+
return tips.proven.checkpoint.number;
|
|
619
|
+
case 'finalized':
|
|
620
|
+
return tips.finalized.checkpoint.number;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
isChainTip(value) {
|
|
624
|
+
return value === 'proposed' || value === 'checkpointed' || value === 'proven' || value === 'finalized';
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Normalizes a {@link BlockParameter} (which may be a bare value) into a
|
|
628
|
+
* {@link NormalizedBlockParameter} object form. Performs no chain-tip resolution — tag
|
|
629
|
+
* lookups are deferred to the underlying block source.
|
|
630
|
+
*/ normalizeBlockParameter(param) {
|
|
631
|
+
if (BlockHash.isBlockHash(param)) {
|
|
632
|
+
return {
|
|
633
|
+
hash: param
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
if (typeof param === 'number') {
|
|
637
|
+
return {
|
|
638
|
+
number: param
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
if (typeof param === 'string') {
|
|
642
|
+
if (this.isBlockTag(param)) {
|
|
643
|
+
return {
|
|
644
|
+
tag: param === 'latest' ? 'proposed' : param
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
throw new BadRequestError(`Invalid BlockParameter tag: ${param}`);
|
|
648
|
+
}
|
|
649
|
+
if (typeof param === 'object' && param !== null) {
|
|
650
|
+
if ('number' in param) {
|
|
651
|
+
return {
|
|
652
|
+
number: param.number
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
if ('hash' in param) {
|
|
656
|
+
return {
|
|
657
|
+
hash: param.hash
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
if ('archive' in param) {
|
|
661
|
+
return {
|
|
662
|
+
archive: param.archive
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
if ('tag' in param) {
|
|
666
|
+
if (this.isBlockTag(param.tag)) {
|
|
667
|
+
return {
|
|
668
|
+
tag: param.tag
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
throw new BadRequestError(`Invalid BlockParameter tag: ${param.tag}`);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
throw new BadRequestError(`Invalid BlockParameter: ${JSON.stringify(param)}`);
|
|
675
|
+
}
|
|
676
|
+
isBlockTag(value) {
|
|
677
|
+
return BlockTag.includes(value);
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Resolves a {@link CheckpointParameter} into a concrete `{ number }` or `{ slot }` query.
|
|
681
|
+
*
|
|
682
|
+
* Tag-based parameters (`'proposed'`, `'checkpointed'`, `'proven'`, `'finalized'`) are
|
|
683
|
+
* translated up-front to the corresponding tip's checkpoint number via {@link L2BlockSource.getL2Tips}.
|
|
684
|
+
* After resolution the unified {@link getCheckpoint} flow can perform a single
|
|
685
|
+
* confirmed→proposed lookup against either store.
|
|
686
|
+
*/ async resolveCheckpointParameter(param) {
|
|
687
|
+
if (typeof param === 'number') {
|
|
688
|
+
return {
|
|
689
|
+
number: param
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
if (this.isChainTip(param)) {
|
|
693
|
+
const tips = await this.blockSource.getL2Tips();
|
|
694
|
+
switch(param){
|
|
695
|
+
case 'proposed':
|
|
696
|
+
return {
|
|
697
|
+
number: tips.proposedCheckpoint.checkpoint.number
|
|
698
|
+
};
|
|
699
|
+
case 'checkpointed':
|
|
700
|
+
return {
|
|
701
|
+
number: tips.checkpointed.checkpoint.number
|
|
702
|
+
};
|
|
703
|
+
case 'proven':
|
|
704
|
+
return {
|
|
705
|
+
number: tips.proven.checkpoint.number
|
|
706
|
+
};
|
|
707
|
+
case 'finalized':
|
|
708
|
+
return {
|
|
709
|
+
number: tips.finalized.checkpoint.number
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
if (typeof param === 'object' && param !== null) {
|
|
714
|
+
if ('number' in param) {
|
|
715
|
+
return {
|
|
716
|
+
number: param.number
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
if ('slot' in param) {
|
|
720
|
+
return {
|
|
721
|
+
slot: param.slot
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
throw new BadRequestError(`Invalid CheckpointParameter: ${JSON.stringify(param)}`);
|
|
726
|
+
}
|
|
727
|
+
/** Fetches checkpoint-level L1 and attestation data for use as block response context. */ async #getCheckpointContext(checkpointNumber) {
|
|
728
|
+
const checkpoint = await this.blockSource.getCheckpointData({
|
|
729
|
+
number: checkpointNumber
|
|
730
|
+
});
|
|
731
|
+
if (!checkpoint) {
|
|
732
|
+
return undefined;
|
|
733
|
+
}
|
|
734
|
+
return {
|
|
735
|
+
l1: checkpoint.l1,
|
|
736
|
+
attestations: checkpoint.attestations
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
async getBlock(param, options = {}) {
|
|
740
|
+
const query = this.normalizeBlockParameter(param);
|
|
741
|
+
const wantTxs = !!options.includeTransactions;
|
|
742
|
+
const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
|
|
743
|
+
if (wantTxs) {
|
|
744
|
+
const block = await this.blockSource.getBlock(query);
|
|
745
|
+
if (!block) {
|
|
746
|
+
return undefined;
|
|
747
|
+
}
|
|
748
|
+
const ctx = wantContext ? await this.#getCheckpointContext(block.checkpointNumber) : undefined;
|
|
749
|
+
return await blockResponseFromL2Block(block, options, ctx);
|
|
750
|
+
}
|
|
751
|
+
const data = await this.blockSource.getBlockData(query);
|
|
752
|
+
if (!data) {
|
|
753
|
+
return undefined;
|
|
754
|
+
}
|
|
755
|
+
const ctx = wantContext ? await this.#getCheckpointContext(data.checkpointNumber) : undefined;
|
|
756
|
+
return blockResponseFromBlockData(data, options, ctx);
|
|
757
|
+
}
|
|
758
|
+
getBlockData(param) {
|
|
759
|
+
const query = this.normalizeBlockParameter(param);
|
|
760
|
+
return this.blockSource.getBlockData(query);
|
|
761
|
+
}
|
|
762
|
+
async getBlocks(from, limit, options = {}) {
|
|
763
|
+
const wantTxs = !!options.includeTransactions;
|
|
764
|
+
const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
|
|
765
|
+
const onlyCheckpointed = !!options.onlyCheckpointed;
|
|
766
|
+
if (wantTxs) {
|
|
767
|
+
const blocks = await this.blockSource.getBlocks({
|
|
768
|
+
from,
|
|
769
|
+
limit,
|
|
770
|
+
onlyCheckpointed
|
|
771
|
+
});
|
|
772
|
+
const ctxByCheckpoint = await this.#getCheckpointContextsForBlocks(wantContext ? blocks : []);
|
|
773
|
+
return await Promise.all(blocks.map((block)=>blockResponseFromL2Block(block, options, ctxByCheckpoint.get(block.checkpointNumber))));
|
|
774
|
+
}
|
|
775
|
+
const dataItems = await this.blockSource.getBlocksData({
|
|
776
|
+
from,
|
|
777
|
+
limit,
|
|
778
|
+
onlyCheckpointed
|
|
779
|
+
});
|
|
780
|
+
const ctxByCheckpoint = await this.#getCheckpointContextsForBlocks(wantContext ? dataItems : []);
|
|
781
|
+
return await Promise.all(dataItems.map((data)=>blockResponseFromBlockData(data, options, ctxByCheckpoint.get(data.checkpointNumber))));
|
|
782
|
+
}
|
|
783
|
+
/** Fetches checkpoint context for a set of blocks, deduplicating shared checkpoints. */ async #getCheckpointContextsForBlocks(blocks) {
|
|
784
|
+
const unique = Array.from(new Set(blocks.map((b)=>b.checkpointNumber)));
|
|
785
|
+
const entries = await Promise.all(unique.map(async (n)=>[
|
|
786
|
+
n,
|
|
787
|
+
await this.#getCheckpointContext(n)
|
|
788
|
+
]));
|
|
789
|
+
return new Map(entries);
|
|
790
|
+
}
|
|
791
|
+
async getCheckpoint(param, options = {}) {
|
|
792
|
+
const query = await this.resolveCheckpointParameter(param);
|
|
793
|
+
// Try the confirmed store first.
|
|
794
|
+
const confirmed = options.includeBlocks ? await this.blockSource.getCheckpoint(query) : await this.blockSource.getCheckpointData(query);
|
|
795
|
+
if (confirmed) {
|
|
796
|
+
return await (options.includeBlocks ? checkpointResponseFromPublishedCheckpoint(confirmed, options) : checkpointResponseFromCheckpointData(confirmed, options));
|
|
797
|
+
}
|
|
798
|
+
// Fall back to the proposed store.
|
|
799
|
+
const proposed = await this.blockSource.getProposedCheckpointData(query);
|
|
800
|
+
if (proposed) {
|
|
801
|
+
if (options.includeAttestations || options.includeL1PublishInfo) {
|
|
802
|
+
throw new BadRequestError(`Options includeL1PublishInfo or includeAttestations cannot be satisfied for a proposed checkpoint`);
|
|
803
|
+
}
|
|
804
|
+
const blocks = options.includeBlocks ? await this.blockSource.getBlocks({
|
|
805
|
+
from: proposed.startBlock,
|
|
806
|
+
limit: proposed.blockCount
|
|
807
|
+
}) : undefined;
|
|
808
|
+
return await projectProposedToCheckpointResponse(proposed, options, blocks);
|
|
809
|
+
}
|
|
810
|
+
return undefined;
|
|
811
|
+
}
|
|
812
|
+
async getCheckpoints(from, limit, options = {}) {
|
|
813
|
+
if (options.includeBlocks) {
|
|
814
|
+
const checkpoints = await this.blockSource.getCheckpoints({
|
|
815
|
+
from,
|
|
816
|
+
limit
|
|
817
|
+
});
|
|
818
|
+
return await Promise.all(checkpoints.map((cp)=>checkpointResponseFromPublishedCheckpoint(cp, options)));
|
|
819
|
+
}
|
|
820
|
+
const datas = await this.blockSource.getCheckpointsData({
|
|
821
|
+
from,
|
|
822
|
+
limit
|
|
823
|
+
});
|
|
824
|
+
return datas.map((d)=>checkpointResponseFromCheckpointData(d, options));
|
|
111
825
|
}
|
|
112
826
|
/**
|
|
113
827
|
* initializes the Aztec Node, wait for component to sync.
|
|
@@ -118,20 +832,31 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
118
832
|
...inputConfig
|
|
119
833
|
}; // Copy the config so we dont mutate the input object
|
|
120
834
|
const log = deps.logger ?? createLogger('node');
|
|
121
|
-
const packageVersion = getPackageVersion()
|
|
835
|
+
const packageVersion = getPackageVersion();
|
|
122
836
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
123
837
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
124
838
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
125
|
-
// Build a key store from file if given or from environment otherwise
|
|
839
|
+
// Build a key store from file if given or from environment otherwise.
|
|
840
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
126
841
|
let keyStoreManager;
|
|
127
842
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
128
843
|
if (keyStoreProvided) {
|
|
129
844
|
const keyStores = loadKeystores(config.keyStoreDirectory);
|
|
130
845
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
131
846
|
} else {
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
847
|
+
const rawKeyStores = [];
|
|
848
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
849
|
+
if (validatorKeyStore) {
|
|
850
|
+
rawKeyStores.push(validatorKeyStore);
|
|
851
|
+
}
|
|
852
|
+
if (config.enableProverNode) {
|
|
853
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
854
|
+
if (proverKeyStore) {
|
|
855
|
+
rawKeyStores.push(proverKeyStore);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
if (rawKeyStores.length > 0) {
|
|
859
|
+
keyStoreManager = new KeystoreManager(rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores));
|
|
135
860
|
}
|
|
136
861
|
}
|
|
137
862
|
await keyStoreManager?.validateSigners();
|
|
@@ -140,8 +865,8 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
140
865
|
if (keyStoreManager === undefined) {
|
|
141
866
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
142
867
|
}
|
|
143
|
-
if (!keyStoreProvided) {
|
|
144
|
-
log.warn(
|
|
868
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
869
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
145
870
|
}
|
|
146
871
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
147
872
|
}
|
|
@@ -151,194 +876,356 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
151
876
|
}
|
|
152
877
|
const publicClient = createPublicClient({
|
|
153
878
|
chain: ethereumChain.chainInfo,
|
|
154
|
-
transport:
|
|
155
|
-
|
|
156
|
-
|
|
879
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, {
|
|
880
|
+
timeout: config.l1HttpTimeoutMS
|
|
881
|
+
}),
|
|
157
882
|
pollingInterval: config.viemPollingIntervalMS
|
|
158
883
|
});
|
|
159
|
-
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
...l1ContractsAddresses
|
|
164
|
-
};
|
|
165
|
-
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
166
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
884
|
+
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.registryAddress, config.rollupVersion ?? 'canonical');
|
|
885
|
+
Object.assign(config, l1ContractsAddresses);
|
|
886
|
+
const rollupContract = new RollupContract(publicClient, config.rollupAddress.toString());
|
|
887
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
167
888
|
rollupContract.getL1GenesisTime(),
|
|
168
889
|
rollupContract.getSlotDuration(),
|
|
169
|
-
rollupContract.getVersion()
|
|
890
|
+
rollupContract.getVersion(),
|
|
891
|
+
rollupContract.getManaLimit().then(Number)
|
|
170
892
|
]);
|
|
171
893
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
172
894
|
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
173
895
|
log.warn(`Registry looked up and returned a rollup with version (${config.rollupVersion}), but this does not match with version detected from the rollup directly: (${rollupVersionFromRollup}).`);
|
|
174
896
|
}
|
|
175
|
-
const
|
|
176
|
-
l1ChainId: config.l1ChainId,
|
|
177
|
-
rollupVersion: config.rollupVersion,
|
|
178
|
-
rollupAddress: config.l1Contracts.rollupAddress.toString()
|
|
179
|
-
};
|
|
180
|
-
const [fileStoreClients, fileStoreUploadClient] = await Promise.all([
|
|
181
|
-
createReadOnlyFileStoreBlobClients(config.blobFileStoreUrls, blobFileStoreMetadata, log),
|
|
182
|
-
createWritableFileStoreBlobClient(config.blobFileStoreUploadUrl, blobFileStoreMetadata, log)
|
|
183
|
-
]);
|
|
184
|
-
const blobClient = deps.blobClient ?? createBlobClient(config, {
|
|
185
|
-
logger: createLogger('node:blob-client:client'),
|
|
186
|
-
fileStoreClients,
|
|
187
|
-
fileStoreUploadClient
|
|
188
|
-
});
|
|
897
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
189
898
|
// attempt snapshot sync if possible
|
|
190
899
|
await trySnapshotSync(config, log);
|
|
191
|
-
const epochCache = await EpochCache.create(config.
|
|
900
|
+
const epochCache = await EpochCache.create(config.rollupAddress, config, {
|
|
192
901
|
dateProvider
|
|
193
902
|
});
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
log.warn(`Aztec node is accepting fake proofs`);
|
|
207
|
-
}
|
|
208
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
209
|
-
// create the tx pool and the p2p client, which will need the l2 block source
|
|
210
|
-
const p2pClient = await createP2PClient(P2PClientType.Full, config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
211
|
-
// We should really not be modifying the config object
|
|
212
|
-
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
|
|
213
|
-
const blockBuilder = new BlockBuilder({
|
|
214
|
-
...config,
|
|
215
|
-
l1GenesisTime,
|
|
216
|
-
slotDuration: Number(slotDuration)
|
|
217
|
-
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
218
|
-
// We'll accumulate sentinel watchers here
|
|
219
|
-
const watchers = [];
|
|
220
|
-
// Create validator client if required
|
|
221
|
-
const validatorClient = createValidatorClient(config, {
|
|
222
|
-
p2pClient,
|
|
223
|
-
telemetry,
|
|
224
|
-
dateProvider,
|
|
225
|
-
epochCache,
|
|
226
|
-
blockBuilder,
|
|
227
|
-
blockSource: archiver,
|
|
228
|
-
l1ToL2MessageSource: archiver,
|
|
229
|
-
keyStoreManager,
|
|
230
|
-
fileStoreBlobUploadClient: fileStoreUploadClient
|
|
231
|
-
});
|
|
232
|
-
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
233
|
-
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
234
|
-
// like attestations or auths will fail.
|
|
235
|
-
if (validatorClient) {
|
|
236
|
-
watchers.push(validatorClient);
|
|
237
|
-
if (!options.dontStartSequencer) {
|
|
238
|
-
await validatorClient.registerHandlers();
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
// If there's no validator client but alwaysReexecuteBlockProposals is enabled,
|
|
242
|
-
// create a BlockProposalHandler to reexecute block proposals for monitoring
|
|
243
|
-
if (!validatorClient && config.alwaysReexecuteBlockProposals) {
|
|
244
|
-
log.info('Setting up block proposal reexecution for monitoring');
|
|
245
|
-
createBlockProposalHandler(config, {
|
|
246
|
-
blockBuilder,
|
|
903
|
+
// Track started resources so we can clean up on partial failure during node creation.
|
|
904
|
+
const started = [];
|
|
905
|
+
try {
|
|
906
|
+
// Default the orphan-prune grace window from the block build duration when unset, so the archiver
|
|
907
|
+
// waits roughly one build slot for a proposed checkpoint to arrive before pruning a block-only tip.
|
|
908
|
+
config.orphanProposedBlockPruneGraceSeconds ??= config.blockDurationMs !== undefined ? Math.ceil(config.blockDurationMs / 1000) : MIN_EXECUTION_TIME;
|
|
909
|
+
// Create world-state first so we can retrieve the initial header before constructing the archiver.
|
|
910
|
+
const nativeWs = await createWorldState(config, options.genesis);
|
|
911
|
+
const initialHeader = nativeWs.getInitialHeader();
|
|
912
|
+
const initialBlockHash = await initialHeader.hash();
|
|
913
|
+
const archiver = await createArchiver(config, {
|
|
914
|
+
blobClient,
|
|
247
915
|
epochCache,
|
|
248
|
-
blockSource: archiver,
|
|
249
|
-
l1ToL2MessageSource: archiver,
|
|
250
|
-
p2pClient,
|
|
251
|
-
dateProvider,
|
|
252
|
-
telemetry
|
|
253
|
-
}).registerForReexecution(p2pClient);
|
|
254
|
-
}
|
|
255
|
-
// Start world state and wait for it to sync to the archiver.
|
|
256
|
-
await worldStateSynchronizer.start();
|
|
257
|
-
// Start p2p. Note that it depends on world state to be running.
|
|
258
|
-
await p2pClient.start();
|
|
259
|
-
const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
260
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
261
|
-
watchers.push(validatorsSentinel);
|
|
262
|
-
}
|
|
263
|
-
let epochPruneWatcher;
|
|
264
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
265
|
-
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), blockBuilder, config);
|
|
266
|
-
watchers.push(epochPruneWatcher);
|
|
267
|
-
}
|
|
268
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
269
|
-
let attestationsBlockWatcher;
|
|
270
|
-
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
271
|
-
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
272
|
-
watchers.push(attestationsBlockWatcher);
|
|
273
|
-
}
|
|
274
|
-
// Start p2p-related services once the archiver has completed sync
|
|
275
|
-
void archiver.waitForInitialSync().then(async ()=>{
|
|
276
|
-
await p2pClient.start();
|
|
277
|
-
await validatorsSentinel?.start();
|
|
278
|
-
await epochPruneWatcher?.start();
|
|
279
|
-
await attestationsBlockWatcher?.start();
|
|
280
|
-
log.info(`All p2p services started`);
|
|
281
|
-
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
282
|
-
// Validator enabled, create/start relevant service
|
|
283
|
-
let sequencer;
|
|
284
|
-
let slasherClient;
|
|
285
|
-
if (!config.disableValidator && validatorClient) {
|
|
286
|
-
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
287
|
-
// as they are executed when the node is selected as proposer.
|
|
288
|
-
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
289
|
-
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
290
|
-
await slasherClient.start();
|
|
291
|
-
const l1TxUtils = config.publisherForwarderAddress ? await createForwarderL1TxUtilsFromEthSigner(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.publisherForwarderAddress, {
|
|
292
|
-
...config,
|
|
293
|
-
scope: 'sequencer'
|
|
294
|
-
}, {
|
|
295
916
|
telemetry,
|
|
296
|
-
logger: log.createChild('l1-tx-utils'),
|
|
297
917
|
dateProvider
|
|
298
|
-
}) : await createL1TxUtilsWithBlobsFromEthSigner(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
299
|
-
...config,
|
|
300
|
-
scope: 'sequencer'
|
|
301
918
|
}, {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
919
|
+
blockUntilSync: !config.skipArchiverInitialSync
|
|
920
|
+
}, initialHeader, initialBlockHash);
|
|
921
|
+
started.push(archiver);
|
|
922
|
+
// The synchronizer takes ownership of the native world-state from here
|
|
923
|
+
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, nativeWs, telemetry);
|
|
924
|
+
started.push(worldStateSynchronizer);
|
|
925
|
+
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
926
|
+
let peerProofVerifier;
|
|
927
|
+
let rpcProofVerifier;
|
|
928
|
+
if (useRealVerifiers) {
|
|
929
|
+
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
930
|
+
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
931
|
+
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
932
|
+
} else {
|
|
933
|
+
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
934
|
+
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
935
|
+
}
|
|
936
|
+
started.push(peerProofVerifier, rpcProofVerifier);
|
|
937
|
+
let debugLogStore;
|
|
938
|
+
if (!config.realProofs) {
|
|
939
|
+
log.warn(`Aztec node is accepting fake proofs`);
|
|
940
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
941
|
+
log.info('Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served');
|
|
942
|
+
} else {
|
|
943
|
+
debugLogStore = new NullDebugLogStore();
|
|
944
|
+
}
|
|
945
|
+
const globalVariableBuilderConfig = {
|
|
946
|
+
rollupAddress: config.rollupAddress,
|
|
947
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
948
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
309
949
|
l1GenesisTime,
|
|
310
950
|
slotDuration: Number(slotDuration)
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
951
|
+
};
|
|
952
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
953
|
+
const feeProvider = new FeeProviderImpl(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
954
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
955
|
+
if (proverOnly) {
|
|
956
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
957
|
+
}
|
|
958
|
+
// create the tx pool and the p2p client, which will need the l2 block source
|
|
959
|
+
const p2pClient = await createP2PClient(config, archiver, peerProofVerifier, worldStateSynchronizer, epochCache, feeProvider, packageVersion, dateProvider, telemetry, deps.p2pClientDeps, initialBlockHash);
|
|
960
|
+
started.push(p2pClient);
|
|
961
|
+
// We'll accumulate sentinel watchers here
|
|
962
|
+
const watchers = [];
|
|
963
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
964
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
965
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
966
|
+
...config,
|
|
967
|
+
l1GenesisTime,
|
|
968
|
+
slotDuration: Number(slotDuration),
|
|
969
|
+
rollupManaLimit,
|
|
970
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
|
|
971
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
972
|
+
let validatorClient;
|
|
973
|
+
// Tracks successful checkpoint re-execution by a checkpoint proposal handler.
|
|
974
|
+
const reexecutionTracker = new CheckpointReexecutionTracker();
|
|
975
|
+
if (!config.disableValidator) {
|
|
976
|
+
// Create validator client if required
|
|
977
|
+
validatorClient = await createValidatorClient(config, {
|
|
978
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
979
|
+
worldState: worldStateSynchronizer,
|
|
980
|
+
p2pClient,
|
|
981
|
+
telemetry,
|
|
982
|
+
dateProvider,
|
|
983
|
+
epochCache,
|
|
984
|
+
blockSource: archiver,
|
|
985
|
+
l1ToL2MessageSource: archiver,
|
|
986
|
+
keyStoreManager,
|
|
987
|
+
blobClient,
|
|
988
|
+
reexecutionTracker,
|
|
989
|
+
slashingProtectionDb: deps.slashingProtectionDb
|
|
990
|
+
});
|
|
991
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
992
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
993
|
+
// like attestations or auths will fail.
|
|
994
|
+
if (validatorClient) {
|
|
995
|
+
watchers.push(validatorClient);
|
|
996
|
+
const vc = validatorClient;
|
|
997
|
+
const getValidatorAddresses = ()=>vc.getValidatorAddresses().map((a)=>a.toString());
|
|
998
|
+
validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
|
|
999
|
+
if (!options.dontStartSequencer) {
|
|
1000
|
+
await validatorClient.registerHandlers();
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
1005
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
1006
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
1007
|
+
// Checkpoint proposals rebuild blobs if the blob client can upload blobs.
|
|
1008
|
+
if (!validatorClient) {
|
|
1009
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
1010
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
1011
|
+
createProposalHandler(config, {
|
|
1012
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
1013
|
+
worldState: worldStateSynchronizer,
|
|
1014
|
+
epochCache,
|
|
1015
|
+
blockSource: archiver,
|
|
1016
|
+
l1ToL2MessageSource: archiver,
|
|
1017
|
+
p2pClient,
|
|
1018
|
+
blobClient,
|
|
1019
|
+
dateProvider,
|
|
1020
|
+
telemetry,
|
|
1021
|
+
reexecutionTracker
|
|
1022
|
+
}).register(p2pClient, reexecute, archiver);
|
|
1023
|
+
}
|
|
1024
|
+
// Start world state and wait for it to sync to the archiver.
|
|
1025
|
+
await worldStateSynchronizer.start();
|
|
1026
|
+
// Start p2p. Note that it depends on world state to be running.
|
|
1027
|
+
await p2pClient.start();
|
|
1028
|
+
let validatorsSentinel;
|
|
1029
|
+
let dataWithholdingWatcher;
|
|
1030
|
+
let attestationsBlockWatcher;
|
|
1031
|
+
let attestedInvalidProposalWatcher;
|
|
1032
|
+
let broadcastedInvalidCheckpointProposalWatcher;
|
|
1033
|
+
let checkpointEquivocationWatcher;
|
|
1034
|
+
if (!proverOnly) {
|
|
1035
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, reexecutionTracker, config);
|
|
1036
|
+
if (validatorsSentinel) {
|
|
1037
|
+
watchers.push(validatorsSentinel);
|
|
1038
|
+
}
|
|
1039
|
+
dataWithholdingWatcher = new DataWithholdingWatcher(epochCache, archiver, p2pClient.getTxProvider(), p2pClient, reexecutionTracker, {
|
|
1040
|
+
chainId: config.l1ChainId,
|
|
1041
|
+
rollupAddress: config.rollupAddress
|
|
1042
|
+
}, config);
|
|
1043
|
+
watchers.push(dataWithholdingWatcher);
|
|
1044
|
+
broadcastedInvalidCheckpointProposalWatcher = new BroadcastedInvalidCheckpointProposalWatcher(p2pClient, archiver, epochCache, config);
|
|
1045
|
+
watchers.push(broadcastedInvalidCheckpointProposalWatcher);
|
|
1046
|
+
if (validatorClient) {
|
|
1047
|
+
attestedInvalidProposalWatcher = new AttestedInvalidProposalWatcher(p2pClient, validatorClient, archiver, epochCache, config, {
|
|
1048
|
+
log: log.createChild('attested-invalid-proposal-watcher')
|
|
1049
|
+
});
|
|
1050
|
+
watchers.push(attestedInvalidProposalWatcher);
|
|
1051
|
+
}
|
|
1052
|
+
checkpointEquivocationWatcher = new CheckpointEquivocationWatcher(archiver, epochCache, config);
|
|
1053
|
+
watchers.push(checkpointEquivocationWatcher);
|
|
1054
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config, log.getBindings());
|
|
1055
|
+
watchers.push(attestationsBlockWatcher);
|
|
1056
|
+
}
|
|
1057
|
+
const watchersToStart = compactArray([
|
|
1058
|
+
validatorsSentinel,
|
|
1059
|
+
dataWithholdingWatcher,
|
|
1060
|
+
attestationsBlockWatcher,
|
|
1061
|
+
broadcastedInvalidCheckpointProposalWatcher,
|
|
1062
|
+
attestedInvalidProposalWatcher,
|
|
1063
|
+
checkpointEquivocationWatcher
|
|
1064
|
+
]);
|
|
1065
|
+
const startedWatchers = [];
|
|
1066
|
+
const stopStartedWatchers = async ()=>{
|
|
1067
|
+
for (const watcher of startedWatchers){
|
|
1068
|
+
await tryStop(watcher);
|
|
1069
|
+
}
|
|
1070
|
+
};
|
|
1071
|
+
// Start p2p-related services once the archiver has completed sync
|
|
1072
|
+
void archiver.waitForInitialSync().then(async ()=>{
|
|
1073
|
+
for (const watcher of watchersToStart){
|
|
1074
|
+
await watcher.start();
|
|
1075
|
+
startedWatchers.push(watcher);
|
|
1076
|
+
}
|
|
1077
|
+
log.info(`All p2p services started`);
|
|
1078
|
+
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
1079
|
+
started.push({
|
|
1080
|
+
stop: stopStartedWatchers
|
|
327
1081
|
});
|
|
1082
|
+
// Validator enabled, create/start relevant service
|
|
1083
|
+
let sequencer;
|
|
1084
|
+
let automineSequencer;
|
|
1085
|
+
let slasherClient;
|
|
1086
|
+
if (!config.disableValidator && validatorClient) {
|
|
1087
|
+
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
1088
|
+
// as they are executed when the node is selected as proposer.
|
|
1089
|
+
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
1090
|
+
slasherClient = await createSlasher(config, pickL1ContractAddresses(config), getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
1091
|
+
await slasherClient.start();
|
|
1092
|
+
started.push(slasherClient);
|
|
1093
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
|
|
1094
|
+
...config,
|
|
1095
|
+
scope: 'sequencer'
|
|
1096
|
+
}, {
|
|
1097
|
+
telemetry,
|
|
1098
|
+
logger: log.createChild('l1-tx-utils'),
|
|
1099
|
+
dateProvider,
|
|
1100
|
+
kzg: Blob.getViemKzgInstance()
|
|
1101
|
+
}) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
1102
|
+
...config,
|
|
1103
|
+
scope: 'sequencer'
|
|
1104
|
+
}, {
|
|
1105
|
+
telemetry,
|
|
1106
|
+
logger: log.createChild('l1-tx-utils'),
|
|
1107
|
+
dateProvider,
|
|
1108
|
+
kzg: Blob.getViemKzgInstance()
|
|
1109
|
+
});
|
|
1110
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
1111
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
1112
|
+
let funderL1TxUtils;
|
|
1113
|
+
if (fundingSigner) {
|
|
1114
|
+
const [funder] = await createL1TxUtilsFromSigners(publicClient, [
|
|
1115
|
+
fundingSigner
|
|
1116
|
+
], {
|
|
1117
|
+
...config,
|
|
1118
|
+
scope: 'sequencer'
|
|
1119
|
+
}, {
|
|
1120
|
+
telemetry,
|
|
1121
|
+
logger: log.createChild('l1-tx-utils:funder'),
|
|
1122
|
+
dateProvider
|
|
1123
|
+
});
|
|
1124
|
+
funderL1TxUtils = funder;
|
|
1125
|
+
}
|
|
1126
|
+
// Create and start the sequencer client
|
|
1127
|
+
const checkpointsBuilder = new CheckpointsBuilder({
|
|
1128
|
+
...config,
|
|
1129
|
+
l1GenesisTime,
|
|
1130
|
+
slotDuration: Number(slotDuration),
|
|
1131
|
+
rollupManaLimit
|
|
1132
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry, debugLogStore);
|
|
1133
|
+
if (config.useAutomineSequencer) {
|
|
1134
|
+
// Test-only path: deterministic, queue-driven sequencer for non-block-building e2e tests.
|
|
1135
|
+
// See `AUTOMINE_E2E_OPTS` in `end-to-end/src/fixtures/fixtures.ts`.
|
|
1136
|
+
automineSequencer = await createAutomineSequencer({
|
|
1137
|
+
config,
|
|
1138
|
+
l1TxUtils,
|
|
1139
|
+
funderL1TxUtils,
|
|
1140
|
+
publicClient,
|
|
1141
|
+
rollupContract,
|
|
1142
|
+
epochCache,
|
|
1143
|
+
blobClient,
|
|
1144
|
+
telemetry,
|
|
1145
|
+
dateProvider,
|
|
1146
|
+
keyStoreManager: keyStoreManager,
|
|
1147
|
+
validatorClient,
|
|
1148
|
+
checkpointsBuilder,
|
|
1149
|
+
globalVariableBuilder,
|
|
1150
|
+
worldStateSynchronizer,
|
|
1151
|
+
archiver,
|
|
1152
|
+
p2pClient,
|
|
1153
|
+
l1Constants: {
|
|
1154
|
+
l1GenesisTime,
|
|
1155
|
+
slotDuration: Number(slotDuration),
|
|
1156
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
1157
|
+
rollupManaLimit
|
|
1158
|
+
},
|
|
1159
|
+
log
|
|
1160
|
+
});
|
|
1161
|
+
} else {
|
|
1162
|
+
sequencer = await SequencerClient.new(config, {
|
|
1163
|
+
...deps,
|
|
1164
|
+
epochCache,
|
|
1165
|
+
l1TxUtils,
|
|
1166
|
+
funderL1TxUtils,
|
|
1167
|
+
validatorClient,
|
|
1168
|
+
p2pClient,
|
|
1169
|
+
worldStateSynchronizer,
|
|
1170
|
+
slasherClient,
|
|
1171
|
+
checkpointsBuilder,
|
|
1172
|
+
l2BlockSource: archiver,
|
|
1173
|
+
l1ToL2MessageSource: archiver,
|
|
1174
|
+
telemetry,
|
|
1175
|
+
dateProvider,
|
|
1176
|
+
blobClient,
|
|
1177
|
+
nodeKeyStore: keyStoreManager,
|
|
1178
|
+
globalVariableBuilder
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
if (!options.dontStartSequencer && sequencer) {
|
|
1183
|
+
await sequencer.start();
|
|
1184
|
+
started.push(sequencer);
|
|
1185
|
+
log.verbose(`Sequencer started`);
|
|
1186
|
+
} else if (sequencer) {
|
|
1187
|
+
log.warn(`Sequencer created but not started`);
|
|
1188
|
+
}
|
|
1189
|
+
if (!options.dontStartSequencer && automineSequencer) {
|
|
1190
|
+
await automineSequencer.start();
|
|
1191
|
+
started.push({
|
|
1192
|
+
stop: ()=>automineSequencer.stop()
|
|
1193
|
+
});
|
|
1194
|
+
log.verbose(`AutomineSequencer started`);
|
|
1195
|
+
} else if (automineSequencer) {
|
|
1196
|
+
log.warn(`AutomineSequencer created but not started`);
|
|
1197
|
+
}
|
|
1198
|
+
// Create prover node subsystem if enabled
|
|
1199
|
+
let proverNode;
|
|
1200
|
+
if (config.enableProverNode) {
|
|
1201
|
+
proverNode = await createProverNode(config, {
|
|
1202
|
+
...deps.proverNodeDeps,
|
|
1203
|
+
telemetry,
|
|
1204
|
+
dateProvider,
|
|
1205
|
+
archiver,
|
|
1206
|
+
worldStateSynchronizer,
|
|
1207
|
+
p2pClient,
|
|
1208
|
+
epochCache,
|
|
1209
|
+
blobClient,
|
|
1210
|
+
keyStoreManager
|
|
1211
|
+
});
|
|
1212
|
+
if (!options.dontStartProverNode) {
|
|
1213
|
+
await proverNode.start();
|
|
1214
|
+
started.push(proverNode);
|
|
1215
|
+
log.info(`Prover node subsystem started`);
|
|
1216
|
+
} else {
|
|
1217
|
+
log.info(`Prover node subsystem created but not started`);
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
const node = new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, stopStartedWatchers, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, feeProvider, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry, log, blobClient, validatorClient, keyStoreManager, debugLogStore, automineSequencer);
|
|
1221
|
+
return node;
|
|
1222
|
+
} catch (err) {
|
|
1223
|
+
log.error('Failed during node creation, stopping started resources', err);
|
|
1224
|
+
for (const resource of started.reverse()){
|
|
1225
|
+
await tryStop(resource);
|
|
1226
|
+
}
|
|
1227
|
+
throw err;
|
|
328
1228
|
}
|
|
329
|
-
if (!options.dontStartSequencer && sequencer) {
|
|
330
|
-
await sequencer.start();
|
|
331
|
-
log.verbose(`Sequencer started`);
|
|
332
|
-
} else if (sequencer) {
|
|
333
|
-
log.warn(`Sequencer created but not started`);
|
|
334
|
-
}
|
|
335
|
-
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
336
|
-
...config,
|
|
337
|
-
rollupVersion: BigInt(config.rollupVersion),
|
|
338
|
-
l1GenesisTime,
|
|
339
|
-
slotDuration: Number(slotDuration)
|
|
340
|
-
});
|
|
341
|
-
return new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry, log);
|
|
342
1229
|
}
|
|
343
1230
|
/**
|
|
344
1231
|
* Returns the sequencer client instance.
|
|
@@ -346,6 +1233,12 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
346
1233
|
*/ getSequencer() {
|
|
347
1234
|
return this.sequencer;
|
|
348
1235
|
}
|
|
1236
|
+
/** Test-only: returns the AutomineSequencer when wired via `useAutomineSequencer`. */ getAutomineSequencer() {
|
|
1237
|
+
return this.automineSequencer;
|
|
1238
|
+
}
|
|
1239
|
+
/** Returns the prover node subsystem, if enabled. */ getProverNode() {
|
|
1240
|
+
return this.proverNode;
|
|
1241
|
+
}
|
|
349
1242
|
getBlockSource() {
|
|
350
1243
|
return this.blockSource;
|
|
351
1244
|
}
|
|
@@ -359,13 +1252,16 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
359
1252
|
* Method to return the currently deployed L1 contract addresses.
|
|
360
1253
|
* @returns - The currently deployed L1 contract addresses.
|
|
361
1254
|
*/ getL1ContractAddresses() {
|
|
362
|
-
return Promise.resolve(this.config
|
|
1255
|
+
return Promise.resolve(pickL1ContractAddresses(this.config));
|
|
363
1256
|
}
|
|
364
1257
|
getEncodedEnr() {
|
|
365
1258
|
return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
|
|
366
1259
|
}
|
|
367
1260
|
async getAllowedPublicSetup() {
|
|
368
|
-
return
|
|
1261
|
+
return [
|
|
1262
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1263
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1264
|
+
];
|
|
369
1265
|
}
|
|
370
1266
|
/**
|
|
371
1267
|
* Method to determine if the node is ready to accept transactions.
|
|
@@ -388,50 +1284,16 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
388
1284
|
rollupVersion,
|
|
389
1285
|
enr,
|
|
390
1286
|
l1ContractAddresses: contractAddresses,
|
|
391
|
-
protocolContractAddresses: protocolContractAddresses
|
|
1287
|
+
protocolContractAddresses: protocolContractAddresses,
|
|
1288
|
+
realProofs: !!this.config.realProofs
|
|
392
1289
|
};
|
|
393
1290
|
return nodeInfo;
|
|
394
1291
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
* @param number - The block number being requested.
|
|
398
|
-
* @returns The requested block.
|
|
399
|
-
*/ async getBlock(number) {
|
|
400
|
-
const blockNumber = number === 'latest' ? await this.getBlockNumber() : number;
|
|
401
|
-
return await this.blockSource.getBlock(blockNumber);
|
|
1292
|
+
async getCurrentMinFees() {
|
|
1293
|
+
return await this.feeProvider.getCurrentMinFees();
|
|
402
1294
|
}
|
|
403
|
-
/**
|
|
404
|
-
|
|
405
|
-
* @param blockHash - The block hash being requested.
|
|
406
|
-
* @returns The requested block.
|
|
407
|
-
*/ async getBlockByHash(blockHash) {
|
|
408
|
-
const publishedBlock = await this.blockSource.getPublishedBlockByHash(blockHash);
|
|
409
|
-
return publishedBlock?.block;
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* Get a block specified by its archive root.
|
|
413
|
-
* @param archive - The archive root being requested.
|
|
414
|
-
* @returns The requested block.
|
|
415
|
-
*/ async getBlockByArchive(archive) {
|
|
416
|
-
const publishedBlock = await this.blockSource.getPublishedBlockByArchive(archive);
|
|
417
|
-
return publishedBlock?.block;
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
|
|
421
|
-
* @param from - The start of the range of blocks to return.
|
|
422
|
-
* @param limit - The maximum number of blocks to obtain.
|
|
423
|
-
* @returns The blocks requested.
|
|
424
|
-
*/ async getBlocks(from, limit) {
|
|
425
|
-
return await this.blockSource.getBlocks(from, limit) ?? [];
|
|
426
|
-
}
|
|
427
|
-
async getPublishedBlocks(from, limit) {
|
|
428
|
-
return await this.blockSource.getPublishedBlocks(from, limit) ?? [];
|
|
429
|
-
}
|
|
430
|
-
/**
|
|
431
|
-
* Method to fetch the current base fees.
|
|
432
|
-
* @returns The current base fees.
|
|
433
|
-
*/ async getCurrentBaseFees() {
|
|
434
|
-
return await this.globalVariableBuilder.getCurrentBaseFees();
|
|
1295
|
+
/** Returns predicted min fees for the current slot and next N slots. */ async getPredictedMinFees(manaUsage) {
|
|
1296
|
+
return await this.feeProvider.getPredictedMinFees(manaUsage);
|
|
435
1297
|
}
|
|
436
1298
|
async getMaxPriorityFees() {
|
|
437
1299
|
for await (const tx of this.p2pClient.iteratePendingTxs()){
|
|
@@ -443,15 +1305,6 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
443
1305
|
});
|
|
444
1306
|
}
|
|
445
1307
|
/**
|
|
446
|
-
* Method to fetch the latest block number synchronized by the node.
|
|
447
|
-
* @returns The block number.
|
|
448
|
-
*/ async getBlockNumber() {
|
|
449
|
-
return await this.blockSource.getBlockNumber();
|
|
450
|
-
}
|
|
451
|
-
async getProvenBlockNumber() {
|
|
452
|
-
return await this.blockSource.getProvenBlockNumber();
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
1308
|
* Method to fetch the version of the package.
|
|
456
1309
|
* @returns The node package version
|
|
457
1310
|
*/ getNodeVersion() {
|
|
@@ -475,25 +1328,11 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
475
1328
|
getContract(address) {
|
|
476
1329
|
return this.contractDataSource.getContract(address);
|
|
477
1330
|
}
|
|
478
|
-
getPrivateLogsByTags(
|
|
479
|
-
return this.logsSource.getPrivateLogsByTags(
|
|
1331
|
+
getPrivateLogsByTags(query) {
|
|
1332
|
+
return this.logsSource.getPrivateLogsByTags(query);
|
|
480
1333
|
}
|
|
481
|
-
|
|
482
|
-
return this.logsSource.
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* Gets public logs based on the provided filter.
|
|
486
|
-
* @param filter - The filter to apply to the logs.
|
|
487
|
-
* @returns The requested logs.
|
|
488
|
-
*/ getPublicLogs(filter) {
|
|
489
|
-
return this.logsSource.getPublicLogs(filter);
|
|
490
|
-
}
|
|
491
|
-
/**
|
|
492
|
-
* Gets contract class logs based on the provided filter.
|
|
493
|
-
* @param filter - The filter to apply to the logs.
|
|
494
|
-
* @returns The requested logs.
|
|
495
|
-
*/ getContractClassLogs(filter) {
|
|
496
|
-
return this.logsSource.getContractClassLogs(filter);
|
|
1334
|
+
getPublicLogsByTags(query) {
|
|
1335
|
+
return this.logsSource.getPublicLogsByTags(query);
|
|
497
1336
|
}
|
|
498
1337
|
/**
|
|
499
1338
|
* Method to submit a transaction to the p2p pool.
|
|
@@ -513,25 +1352,42 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
513
1352
|
});
|
|
514
1353
|
throw new Error(`Invalid tx: ${reason}`);
|
|
515
1354
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
1355
|
+
try {
|
|
1356
|
+
await this.p2pClient.sendTx(tx);
|
|
1357
|
+
} catch (err) {
|
|
1358
|
+
this.metrics.receivedTx(timer.ms(), false);
|
|
1359
|
+
this.log.warn(`Mempool rejected tx ${txHash}: ${err.message}`, {
|
|
1360
|
+
txHash
|
|
1361
|
+
});
|
|
1362
|
+
throw err;
|
|
1363
|
+
}
|
|
1364
|
+
const duration = timer.ms();
|
|
1365
|
+
this.metrics.receivedTx(duration, true);
|
|
1366
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, {
|
|
519
1367
|
txHash
|
|
520
1368
|
});
|
|
521
1369
|
}
|
|
522
1370
|
async getTxReceipt(txHash) {
|
|
523
|
-
|
|
524
|
-
//
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
529
|
-
}
|
|
1371
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
1372
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
1373
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
1374
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
1375
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
530
1376
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
1377
|
+
let receipt;
|
|
531
1378
|
if (settledTxReceipt) {
|
|
532
|
-
|
|
1379
|
+
receipt = settledTxReceipt;
|
|
1380
|
+
} else if (isKnownToPool) {
|
|
1381
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
1382
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
1383
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
1384
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, /*executionResult=*/ undefined, /*error=*/ undefined);
|
|
1385
|
+
} else {
|
|
1386
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
1387
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, /*executionResult=*/ undefined, /*error=*/ 'Tx dropped by P2P node');
|
|
533
1388
|
}
|
|
534
|
-
|
|
1389
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
1390
|
+
return receipt;
|
|
535
1391
|
}
|
|
536
1392
|
getTxEffect(txHash) {
|
|
537
1393
|
return this.blockSource.getTxEffect(txHash);
|
|
@@ -540,18 +1396,29 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
540
1396
|
* Method to stop the aztec node.
|
|
541
1397
|
*/ async stop() {
|
|
542
1398
|
this.log.info(`Stopping Aztec Node`);
|
|
543
|
-
await
|
|
544
|
-
await tryStop(this.epochPruneWatcher);
|
|
1399
|
+
await this.stopStartedWatchers();
|
|
545
1400
|
await tryStop(this.slasherClient);
|
|
546
|
-
await
|
|
1401
|
+
await Promise.all([
|
|
1402
|
+
tryStop(this.peerProofVerifier),
|
|
1403
|
+
tryStop(this.rpcProofVerifier)
|
|
1404
|
+
]);
|
|
547
1405
|
await tryStop(this.sequencer);
|
|
1406
|
+
await tryStop(this.automineSequencer);
|
|
1407
|
+
await tryStop(this.proverNode);
|
|
548
1408
|
await tryStop(this.p2pClient);
|
|
549
1409
|
await tryStop(this.worldStateSynchronizer);
|
|
550
1410
|
await tryStop(this.blockSource);
|
|
1411
|
+
await tryStop(this.blobClient);
|
|
551
1412
|
await tryStop(this.telemetry);
|
|
552
1413
|
this.log.info(`Stopped Aztec Node`);
|
|
553
1414
|
}
|
|
554
1415
|
/**
|
|
1416
|
+
* Returns the blob client used by this node.
|
|
1417
|
+
* @internal - Exposed for testing purposes only.
|
|
1418
|
+
*/ getBlobClient() {
|
|
1419
|
+
return this.blobClient;
|
|
1420
|
+
}
|
|
1421
|
+
/**
|
|
555
1422
|
* Method to retrieve pending txs.
|
|
556
1423
|
* @param limit - The number of items to returns
|
|
557
1424
|
* @param after - The last known pending tx. Used for pagination
|
|
@@ -576,101 +1443,83 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
576
1443
|
*/ async getTxsByHash(txHashes) {
|
|
577
1444
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
578
1445
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
* the leaves were inserted.
|
|
582
|
-
* @param blockNumber - The block number at which to get the data or 'latest' for latest data.
|
|
583
|
-
* @param treeId - The tree to search in.
|
|
584
|
-
* @param leafValues - The values to search for.
|
|
585
|
-
* @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
|
|
586
|
-
*/ async findLeavesIndexes(blockNumber, treeId, leafValues) {
|
|
587
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1446
|
+
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
1447
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
588
1448
|
const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
|
|
589
|
-
//
|
|
590
|
-
const
|
|
591
|
-
// Now we find the block numbers for the indices
|
|
592
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
593
|
-
//
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
1449
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
1450
|
+
const definedIndices = maybeIndices.filter((x)=>x !== undefined);
|
|
1451
|
+
// Now we find the block numbers for the defined indices
|
|
1452
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
1453
|
+
// Build a map from leaf index to block number
|
|
1454
|
+
const indexToBlockNumber = new Map();
|
|
1455
|
+
for(let i = 0; i < definedIndices.length; i++){
|
|
1456
|
+
const blockNumber = blockNumbers[i];
|
|
1457
|
+
if (blockNumber === undefined) {
|
|
1458
|
+
throw new Error(`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`);
|
|
597
1459
|
}
|
|
1460
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
598
1461
|
}
|
|
599
1462
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
600
1463
|
const uniqueBlockNumbers = [
|
|
601
|
-
...new Set(
|
|
1464
|
+
...new Set(indexToBlockNumber.values())
|
|
602
1465
|
];
|
|
603
|
-
// Now we obtain the block hashes from the archive tree
|
|
604
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1466
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
605
1467
|
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
606
1468
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
607
1469
|
}));
|
|
608
|
-
//
|
|
1470
|
+
// Build a map from block number to block hash
|
|
1471
|
+
const blockNumberToHash = new Map();
|
|
609
1472
|
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
610
|
-
|
|
1473
|
+
const blockHash = blockHashes[i];
|
|
1474
|
+
if (blockHash === undefined) {
|
|
611
1475
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
612
1476
|
}
|
|
1477
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
613
1478
|
}
|
|
614
1479
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
615
|
-
return maybeIndices.map((index
|
|
1480
|
+
return maybeIndices.map((index)=>{
|
|
616
1481
|
if (index === undefined) {
|
|
617
1482
|
return undefined;
|
|
618
1483
|
}
|
|
619
|
-
const blockNumber =
|
|
1484
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
620
1485
|
if (blockNumber === undefined) {
|
|
621
|
-
|
|
1486
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
622
1487
|
}
|
|
623
|
-
const
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
return undefined;
|
|
1488
|
+
const l2BlockHash = blockNumberToHash.get(blockNumber);
|
|
1489
|
+
if (l2BlockHash === undefined) {
|
|
1490
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
627
1491
|
}
|
|
628
1492
|
return {
|
|
629
|
-
l2BlockNumber:
|
|
630
|
-
l2BlockHash
|
|
1493
|
+
l2BlockNumber: blockNumber,
|
|
1494
|
+
l2BlockHash,
|
|
631
1495
|
data: index
|
|
632
1496
|
};
|
|
633
1497
|
});
|
|
634
1498
|
}
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
* Returns a sibling path for the given index in the data tree.
|
|
646
|
-
* @param blockNumber - The block number at which to get the data.
|
|
647
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
648
|
-
* @returns The sibling path for the leaf index.
|
|
649
|
-
*/ async getNoteHashSiblingPath(blockNumber, leafIndex) {
|
|
650
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
651
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
652
|
-
}
|
|
653
|
-
async getArchiveMembershipWitness(blockNumber, archive) {
|
|
654
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1499
|
+
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
1500
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1501
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1502
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1503
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1504
|
+
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
1505
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1506
|
+
return undefined;
|
|
1507
|
+
}
|
|
1508
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
655
1509
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
656
|
-
|
|
1510
|
+
blockHash
|
|
657
1511
|
]);
|
|
658
1512
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
659
1513
|
}
|
|
660
|
-
async getNoteHashMembershipWitness(
|
|
661
|
-
const committedDb = await this
|
|
1514
|
+
async getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
1515
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
662
1516
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
663
1517
|
noteHash
|
|
664
1518
|
]);
|
|
665
1519
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
666
1520
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
* @param blockNumber - The block number at which to get the data.
|
|
670
|
-
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
|
|
671
|
-
* @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
|
|
672
|
-
*/ async getL1ToL2MessageMembershipWitness(blockNumber, l1ToL2Message) {
|
|
673
|
-
const db = await this.#getWorldState(blockNumber);
|
|
1521
|
+
async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
1522
|
+
const db = await this.getWorldState(referenceBlock);
|
|
674
1523
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
675
1524
|
l1ToL2Message
|
|
676
1525
|
]);
|
|
@@ -683,51 +1532,24 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
683
1532
|
witness.path
|
|
684
1533
|
];
|
|
685
1534
|
}
|
|
686
|
-
async
|
|
687
|
-
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
688
|
-
return messageIndex ? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex)) : undefined;
|
|
689
|
-
}
|
|
690
|
-
/**
|
|
691
|
-
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
692
|
-
* @param l1ToL2Message - The L1 to L2 message to check.
|
|
693
|
-
* @returns Whether the message is synced and ready to be included in a block.
|
|
694
|
-
*/ async isL1ToL2MessageSynced(l1ToL2Message) {
|
|
1535
|
+
async getL1ToL2MessageCheckpoint(l1ToL2Message) {
|
|
695
1536
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
696
|
-
return messageIndex !== undefined;
|
|
697
|
-
}
|
|
698
|
-
/**
|
|
699
|
-
* Returns all the L2 to L1 messages in a block.
|
|
700
|
-
* @param blockNumber - The block number at which to get the data.
|
|
701
|
-
* @returns The L2 to L1 messages (undefined if the block number is not found).
|
|
702
|
-
*/ async getL2ToL1Messages(blockNumber) {
|
|
703
|
-
const block = await this.blockSource.getBlock(blockNumber === 'latest' ? await this.getBlockNumber() : blockNumber);
|
|
704
|
-
return block?.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs);
|
|
705
|
-
}
|
|
706
|
-
/**
|
|
707
|
-
* Returns a sibling path for a leaf in the committed blocks tree.
|
|
708
|
-
* @param blockNumber - The block number at which to get the data.
|
|
709
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
710
|
-
* @returns The sibling path.
|
|
711
|
-
*/ async getArchiveSiblingPath(blockNumber, leafIndex) {
|
|
712
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
713
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
1537
|
+
return messageIndex !== undefined ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
714
1538
|
}
|
|
715
1539
|
/**
|
|
716
|
-
* Returns
|
|
717
|
-
* @param
|
|
718
|
-
* @
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
1540
|
+
* Returns all the L2 to L1 messages in an epoch.
|
|
1541
|
+
* @param epoch - The epoch at which to get the data.
|
|
1542
|
+
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
1543
|
+
*/ async getL2ToL1Messages(epoch) {
|
|
1544
|
+
const blocks = await this.blockSource.getBlocks({
|
|
1545
|
+
epoch,
|
|
1546
|
+
onlyCheckpointed: true
|
|
1547
|
+
});
|
|
1548
|
+
const blocksInCheckpoints = chunkBy(blocks, (block)=>block.header.globalVariables.slotNumber);
|
|
1549
|
+
return blocksInCheckpoints.map((slotBlocks)=>slotBlocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
723
1550
|
}
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
* @param blockNumber - The block number at which to get the index.
|
|
727
|
-
* @param nullifier - Nullifier we try to find witness for.
|
|
728
|
-
* @returns The nullifier membership witness (if found).
|
|
729
|
-
*/ async getNullifierMembershipWitness(blockNumber, nullifier) {
|
|
730
|
-
const db = await this.#getWorldState(blockNumber);
|
|
1551
|
+
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1552
|
+
const db = await this.getWorldState(referenceBlock);
|
|
731
1553
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
732
1554
|
nullifier.toBuffer()
|
|
733
1555
|
]);
|
|
@@ -741,35 +1563,22 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
741
1563
|
}
|
|
742
1564
|
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
743
1565
|
}
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
* @param blockNumber - The block number at which to get the index.
|
|
747
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
748
|
-
* @returns The low nullifier membership witness (if found).
|
|
749
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
750
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
751
|
-
* we are trying to prove non-inclusion for.
|
|
752
|
-
*
|
|
753
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
754
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
755
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
756
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
757
|
-
*/ async getLowNullifierMembershipWitness(blockNumber, nullifier) {
|
|
758
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1566
|
+
async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1567
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
759
1568
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
760
1569
|
if (!findResult) {
|
|
761
1570
|
return undefined;
|
|
762
1571
|
}
|
|
763
1572
|
const { index, alreadyPresent } = findResult;
|
|
764
1573
|
if (alreadyPresent) {
|
|
765
|
-
|
|
1574
|
+
throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
766
1575
|
}
|
|
767
1576
|
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
768
1577
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
769
1578
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
770
1579
|
}
|
|
771
|
-
async getPublicDataWitness(
|
|
772
|
-
const committedDb = await this
|
|
1580
|
+
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1581
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
773
1582
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
774
1583
|
if (!lowLeafResult) {
|
|
775
1584
|
return undefined;
|
|
@@ -779,18 +1588,8 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
779
1588
|
return new PublicDataWitness(lowLeafResult.index, preimage, path);
|
|
780
1589
|
}
|
|
781
1590
|
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
*
|
|
785
|
-
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
|
|
786
|
-
* Aztec's version of `eth_getStorageAt`.
|
|
787
|
-
*
|
|
788
|
-
* @param contract - Address of the contract to query.
|
|
789
|
-
* @param slot - Slot to query.
|
|
790
|
-
* @param blockNumber - The block number at which to get the data or 'latest'.
|
|
791
|
-
* @returns Storage value at the given contract slot.
|
|
792
|
-
*/ async getPublicStorageAt(blockNumber, contract, slot) {
|
|
793
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1591
|
+
async getPublicStorageAt(referenceBlock, contract, slot) {
|
|
1592
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
794
1593
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
795
1594
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
796
1595
|
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
@@ -800,50 +1599,61 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
800
1599
|
return preimage.leaf.value;
|
|
801
1600
|
}
|
|
802
1601
|
/**
|
|
803
|
-
* Returns the currently committed block header, or the initial header if no blocks have been produced.
|
|
804
|
-
* @returns The current committed block header.
|
|
805
|
-
*/ async getBlockHeader(blockNumber = 'latest') {
|
|
806
|
-
return blockNumber === BlockNumber.ZERO || blockNumber === 'latest' && await this.blockSource.getBlockNumber() === BlockNumber.ZERO ? this.worldStateSynchronizer.getCommitted().getInitialHeader() : this.blockSource.getBlockHeader(blockNumber === 'latest' ? blockNumber : blockNumber);
|
|
807
|
-
}
|
|
808
|
-
/**
|
|
809
|
-
* Get a block header specified by its hash.
|
|
810
|
-
* @param blockHash - The block hash being requested.
|
|
811
|
-
* @returns The requested block header.
|
|
812
|
-
*/ async getBlockHeaderByHash(blockHash) {
|
|
813
|
-
return await this.blockSource.getBlockHeaderByHash(blockHash);
|
|
814
|
-
}
|
|
815
|
-
/**
|
|
816
|
-
* Get a block header specified by its archive root.
|
|
817
|
-
* @param archive - The archive root being requested.
|
|
818
|
-
* @returns The requested block header.
|
|
819
|
-
*/ async getBlockHeaderByArchive(archive) {
|
|
820
|
-
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
821
|
-
}
|
|
822
|
-
/**
|
|
823
1602
|
* Simulates the public part of a transaction with the current state.
|
|
824
1603
|
* @param tx - The transaction to simulate.
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
const
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
}
|
|
833
|
-
const txHash = tx.getTxHash();
|
|
834
|
-
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
835
|
-
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
836
|
-
const coinbase = EthAddress.ZERO;
|
|
837
|
-
const feeRecipient = AztecAddress.ZERO;
|
|
838
|
-
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(blockNumber, coinbase, feeRecipient);
|
|
839
|
-
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry);
|
|
840
|
-
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
841
|
-
globalVariables: newGlobalVariables.toInspect(),
|
|
842
|
-
txHash,
|
|
843
|
-
blockNumber
|
|
844
|
-
});
|
|
845
|
-
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1604
|
+
* @param skipFeeEnforcement - If true, fee enforcement is skipped.
|
|
1605
|
+
* @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
|
|
1606
|
+
**/ async simulatePublicCalls(tx, skipFeeEnforcement = false, overrides) {
|
|
1607
|
+
const env = {
|
|
1608
|
+
stack: [],
|
|
1609
|
+
error: void 0,
|
|
1610
|
+
hasError: false
|
|
1611
|
+
};
|
|
846
1612
|
try {
|
|
1613
|
+
// Check total gas limit for simulation
|
|
1614
|
+
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
1615
|
+
const txGasLimit = gasSettings.gasLimits.l2Gas;
|
|
1616
|
+
const teardownGasLimit = gasSettings.teardownGasLimits.l2Gas;
|
|
1617
|
+
if (txGasLimit + teardownGasLimit > this.config.rpcSimulatePublicMaxGasLimit) {
|
|
1618
|
+
throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
|
|
1619
|
+
}
|
|
1620
|
+
const txHash = tx.getTxHash();
|
|
1621
|
+
const l2Tips = await this.blockSource.getL2Tips();
|
|
1622
|
+
const latestBlockNumber = l2Tips.proposed.number;
|
|
1623
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1624
|
+
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1625
|
+
const coinbase = EthAddress.ZERO;
|
|
1626
|
+
const feeRecipient = AztecAddress.ZERO;
|
|
1627
|
+
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(blockNumber, coinbase, feeRecipient);
|
|
1628
|
+
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry, this.log.getBindings());
|
|
1629
|
+
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
1630
|
+
globalVariables: newGlobalVariables.toInspect(),
|
|
1631
|
+
txHash,
|
|
1632
|
+
blockNumber
|
|
1633
|
+
});
|
|
1634
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1635
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1636
|
+
// If we detect the next block would start a new checkpoint, then insert L1-to-L2 messages into
|
|
1637
|
+
// the world state tree so simulation can take them into account. We detect if the next block would
|
|
1638
|
+
// start a new checkpoint by checking if the proposed checkpoint's block number matches the latest block number,
|
|
1639
|
+
// which means the next block would be the first block of the next checkpoint.
|
|
1640
|
+
const targetCheckpoint = CheckpointNumber((l2Tips.proposedCheckpoint.checkpoint.number ?? CheckpointNumber.ZERO) + 1);
|
|
1641
|
+
const nextCheckpointMessages = l2Tips.proposedCheckpoint.block.number === l2Tips.proposed.number ? await this.l1ToL2MessageSource.getL1ToL2Messages(targetCheckpoint).catch((err)=>{
|
|
1642
|
+
if (isErrorClass(err, L1ToL2MessagesNotReadyError)) {
|
|
1643
|
+
this.log.warn(`L1-to-L2 messages for checkpoint ${targetCheckpoint} are not ready yet (simulating without them)`);
|
|
1644
|
+
} else {
|
|
1645
|
+
this.log.error(`Failed to get L1-to-L2 messages for checkpoint ${targetCheckpoint} (simulating without them)`, err);
|
|
1646
|
+
}
|
|
1647
|
+
return undefined;
|
|
1648
|
+
}) : undefined;
|
|
1649
|
+
const merkleTreeFork = _ts_add_disposable_resource(env, await this.worldStateSynchronizer.fork(latestBlockNumber), true);
|
|
1650
|
+
if (nextCheckpointMessages !== undefined) {
|
|
1651
|
+
this.log.debug(`Appending ${nextCheckpointMessages.length} L1-to-L2 messages to the world state tree for the next checkpoint`, {
|
|
1652
|
+
checkpointNumber: l2Tips.proposedCheckpoint.checkpoint.number + 1
|
|
1653
|
+
});
|
|
1654
|
+
await appendL1ToL2MessagesToTree(merkleTreeFork, nextCheckpointMessages);
|
|
1655
|
+
}
|
|
1656
|
+
await applyPublicDataOverrides(merkleTreeFork, overrides?.publicStorage);
|
|
847
1657
|
const config = PublicSimulatorConfig.from({
|
|
848
1658
|
skipFeeEnforcement,
|
|
849
1659
|
collectDebugLogs: true,
|
|
@@ -854,9 +1664,13 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
854
1664
|
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads
|
|
855
1665
|
})
|
|
856
1666
|
});
|
|
857
|
-
const
|
|
1667
|
+
const contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
|
|
1668
|
+
if (overrides?.contracts) {
|
|
1669
|
+
contractsDB.addContracts(Object.values(overrides.contracts).map(({ instance })=>instance));
|
|
1670
|
+
}
|
|
1671
|
+
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config, contractsDB);
|
|
858
1672
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
859
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
|
|
1673
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([
|
|
860
1674
|
tx
|
|
861
1675
|
]);
|
|
862
1676
|
// REFACTOR: Consider returning the error rather than throwing
|
|
@@ -867,27 +1681,38 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
867
1681
|
throw failedTxs[0].error;
|
|
868
1682
|
}
|
|
869
1683
|
const [processedTx] = processedTxs;
|
|
870
|
-
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed);
|
|
1684
|
+
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed, debugLogs);
|
|
1685
|
+
} catch (e) {
|
|
1686
|
+
env.error = e;
|
|
1687
|
+
env.hasError = true;
|
|
871
1688
|
} finally{
|
|
872
|
-
|
|
1689
|
+
const result = _ts_dispose_resources(env);
|
|
1690
|
+
if (result) await result;
|
|
873
1691
|
}
|
|
874
1692
|
}
|
|
875
1693
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
876
1694
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
877
|
-
const verifier = isSimulation ? undefined : this.
|
|
878
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1695
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1696
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
879
1697
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
880
1698
|
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
881
|
-
const
|
|
1699
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1700
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
|
|
882
1701
|
timestamp: nextSlotTimestamp,
|
|
883
1702
|
blockNumber,
|
|
884
1703
|
l1ChainId: this.l1ChainId,
|
|
885
1704
|
rollupVersion: this.version,
|
|
886
|
-
setupAllowList:
|
|
887
|
-
|
|
1705
|
+
setupAllowList: [
|
|
1706
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1707
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1708
|
+
],
|
|
1709
|
+
gasFees: await this.getCurrentMinFees(),
|
|
888
1710
|
skipFeeEnforcement,
|
|
889
|
-
txsPermitted: !this.config.disableTransactions
|
|
890
|
-
|
|
1711
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1712
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1713
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1714
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
1715
|
+
}, this.log.getBindings());
|
|
891
1716
|
return await validator.validateTx(tx);
|
|
892
1717
|
}
|
|
893
1718
|
getConfig() {
|
|
@@ -900,7 +1725,20 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
900
1725
|
...this.config,
|
|
901
1726
|
...config
|
|
902
1727
|
};
|
|
903
|
-
|
|
1728
|
+
// If the sequencer is currently paused via pauseSequencer(), record the caller's desired
|
|
1729
|
+
// minTxsPerBlock as the restore value (so resumeSequencer applies it) and keep the freeze
|
|
1730
|
+
// (MAX_SAFE_INTEGER) applied to the underlying sequencer. Without this guard, forwarding
|
|
1731
|
+
// the new minTxsPerBlock to the sequencer would silently unpause block production while
|
|
1732
|
+
// pauseSequencer() still considers it paused.
|
|
1733
|
+
const sequencerUpdate = {
|
|
1734
|
+
...config
|
|
1735
|
+
};
|
|
1736
|
+
if (this.sequencerPausedMinTxsPerBlock !== undefined && sequencerUpdate.minTxsPerBlock !== undefined) {
|
|
1737
|
+
this.sequencerPausedMinTxsPerBlock = sequencerUpdate.minTxsPerBlock;
|
|
1738
|
+
delete sequencerUpdate.minTxsPerBlock;
|
|
1739
|
+
}
|
|
1740
|
+
this.sequencer?.updateConfig(sequencerUpdate);
|
|
1741
|
+
this.automineSequencer?.updateConfig(sequencerUpdate);
|
|
904
1742
|
this.slasherClient?.updateConfig(config);
|
|
905
1743
|
this.validatorsSentinel?.updateConfig(config);
|
|
906
1744
|
await this.p2pClient.updateP2PConfig(config);
|
|
@@ -909,7 +1747,18 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
909
1747
|
archiver.updateConfig(config);
|
|
910
1748
|
}
|
|
911
1749
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
912
|
-
|
|
1750
|
+
await Promise.all([
|
|
1751
|
+
tryStop(this.peerProofVerifier),
|
|
1752
|
+
tryStop(this.rpcProofVerifier)
|
|
1753
|
+
]);
|
|
1754
|
+
if (newConfig.realProofs) {
|
|
1755
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1756
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1757
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1758
|
+
} else {
|
|
1759
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1760
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1761
|
+
}
|
|
913
1762
|
}
|
|
914
1763
|
this.config = newConfig;
|
|
915
1764
|
}
|
|
@@ -918,7 +1767,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
918
1767
|
classRegistry: ProtocolContractAddress.ContractClassRegistry,
|
|
919
1768
|
feeJuice: ProtocolContractAddress.FeeJuice,
|
|
920
1769
|
instanceRegistry: ProtocolContractAddress.ContractInstanceRegistry,
|
|
921
|
-
multiCallEntrypoint:
|
|
1770
|
+
multiCallEntrypoint: STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS
|
|
922
1771
|
});
|
|
923
1772
|
}
|
|
924
1773
|
registerContractFunctionSignatures(signatures) {
|
|
@@ -947,7 +1796,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
947
1796
|
throw new Error(`Archiver initial sync not complete. Cannot start snapshot.`);
|
|
948
1797
|
}
|
|
949
1798
|
// And it has an L2 block hash
|
|
950
|
-
const l2BlockHash = await archiver.getL2Tips().then((tips)=>tips.
|
|
1799
|
+
const l2BlockHash = await archiver.getL2Tips().then((tips)=>tips.proposed.hash);
|
|
951
1800
|
if (!l2BlockHash) {
|
|
952
1801
|
this.metrics.recordSnapshotError();
|
|
953
1802
|
throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
|
|
@@ -969,12 +1818,12 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
969
1818
|
});
|
|
970
1819
|
return Promise.resolve();
|
|
971
1820
|
}
|
|
972
|
-
async rollbackTo(targetBlock, force) {
|
|
1821
|
+
async rollbackTo(targetBlock, force, resumeSync = true) {
|
|
973
1822
|
const archiver = this.blockSource;
|
|
974
1823
|
if (!('rollbackTo' in archiver)) {
|
|
975
1824
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
976
1825
|
}
|
|
977
|
-
const finalizedBlock = await archiver.getL2Tips().then((tips)=>tips.finalized.number);
|
|
1826
|
+
const finalizedBlock = await archiver.getL2Tips().then((tips)=>tips.finalized.block.number);
|
|
978
1827
|
if (targetBlock < finalizedBlock) {
|
|
979
1828
|
if (force) {
|
|
980
1829
|
this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
|
|
@@ -997,9 +1846,13 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
997
1846
|
this.log.error(`Error during rollback`, err);
|
|
998
1847
|
throw err;
|
|
999
1848
|
} finally{
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1849
|
+
if (resumeSync) {
|
|
1850
|
+
this.log.info(`Resuming world state and archiver sync.`);
|
|
1851
|
+
this.worldStateSynchronizer.resumeSync();
|
|
1852
|
+
archiver.resume();
|
|
1853
|
+
} else {
|
|
1854
|
+
this.log.info(`Sync left paused after rollback (resumeSync=false).`);
|
|
1855
|
+
}
|
|
1003
1856
|
}
|
|
1004
1857
|
}
|
|
1005
1858
|
async pauseSync() {
|
|
@@ -1013,58 +1866,220 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
1013
1866
|
this.blockSource.resume();
|
|
1014
1867
|
return Promise.resolve();
|
|
1015
1868
|
}
|
|
1016
|
-
|
|
1017
|
-
if (
|
|
1018
|
-
|
|
1869
|
+
pauseSequencer() {
|
|
1870
|
+
if (this.automineSequencer) {
|
|
1871
|
+
this.automineSequencer.pause();
|
|
1872
|
+
return Promise.resolve();
|
|
1019
1873
|
}
|
|
1020
|
-
|
|
1874
|
+
if (this.sequencer) {
|
|
1875
|
+
if (this.sequencerPausedMinTxsPerBlock === undefined) {
|
|
1876
|
+
this.sequencerPausedMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock ?? 0;
|
|
1877
|
+
this.sequencer.updateConfig({
|
|
1878
|
+
minTxsPerBlock: Number.MAX_SAFE_INTEGER
|
|
1879
|
+
});
|
|
1880
|
+
this.log.info(`Sequencer paused (minTxsPerBlock set to MAX_SAFE_INTEGER)`, {
|
|
1881
|
+
previousMinTxsPerBlock: this.sequencerPausedMinTxsPerBlock
|
|
1882
|
+
});
|
|
1883
|
+
}
|
|
1884
|
+
return Promise.resolve();
|
|
1885
|
+
}
|
|
1886
|
+
throw new BadRequestError('Cannot pause sequencer: no sequencer is running');
|
|
1887
|
+
}
|
|
1888
|
+
resumeSequencer() {
|
|
1889
|
+
if (this.automineSequencer) {
|
|
1890
|
+
this.automineSequencer.resume();
|
|
1891
|
+
return Promise.resolve();
|
|
1892
|
+
}
|
|
1893
|
+
if (this.sequencer) {
|
|
1894
|
+
if (this.sequencerPausedMinTxsPerBlock !== undefined) {
|
|
1895
|
+
const restored = this.sequencerPausedMinTxsPerBlock;
|
|
1896
|
+
this.sequencerPausedMinTxsPerBlock = undefined;
|
|
1897
|
+
this.sequencer.updateConfig({
|
|
1898
|
+
minTxsPerBlock: restored
|
|
1899
|
+
});
|
|
1900
|
+
this.log.info(`Sequencer resumed (minTxsPerBlock restored)`, {
|
|
1901
|
+
minTxsPerBlock: restored
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1904
|
+
return Promise.resolve();
|
|
1905
|
+
}
|
|
1906
|
+
throw new BadRequestError('Cannot resume sequencer: no sequencer is running');
|
|
1021
1907
|
}
|
|
1022
1908
|
getSlashOffenses(round) {
|
|
1023
1909
|
if (!this.slasherClient) {
|
|
1024
1910
|
throw new Error(`Slasher client not enabled`);
|
|
1025
1911
|
}
|
|
1026
1912
|
if (round === 'all') {
|
|
1027
|
-
return this.slasherClient.
|
|
1913
|
+
return this.slasherClient.getOffenses();
|
|
1028
1914
|
} else {
|
|
1029
1915
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1030
1916
|
}
|
|
1031
1917
|
}
|
|
1918
|
+
async reloadKeystore() {
|
|
1919
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1920
|
+
throw new BadRequestError('Cannot reload keystore: node is not using a file-based keystore. ' + 'Set KEY_STORE_DIRECTORY to use file-based keystores.');
|
|
1921
|
+
}
|
|
1922
|
+
if (!this.validatorClient) {
|
|
1923
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1924
|
+
}
|
|
1925
|
+
this.log.info('Reloading keystore from disk');
|
|
1926
|
+
// Re-read and validate keystore files
|
|
1927
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1928
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1929
|
+
await newManager.validateSigners();
|
|
1930
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1931
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1932
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1933
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1934
|
+
// would silently fail on every proposer slot.
|
|
1935
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1936
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1937
|
+
const availablePublishers = new Set(oldAdapter.getAttesterAddresses().flatMap((a)=>oldAdapter.getPublisherAddresses(a).map((p)=>p.toString().toLowerCase())));
|
|
1938
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1939
|
+
for (const attester of newAdapter.getAttesterAddresses()){
|
|
1940
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1941
|
+
if (pubs.length > 0 && !pubs.some((p)=>availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1942
|
+
throw new BadRequestError(`Cannot reload keystore: validator ${attester} has publisher keys ` + `[${pubs.map((p)=>p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` + `[${[
|
|
1943
|
+
...availablePublishers
|
|
1944
|
+
].join(', ')}]. Publishers cannot be hot-reloaded — ` + `use an existing publisher key or restart the node.`);
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
// Build adapters for old and new keystores to compute diff
|
|
1949
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1950
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1951
|
+
const oldAddresses = this.keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses() : [];
|
|
1952
|
+
const oldSet = new Set(oldAddresses.map((a)=>a.toString()));
|
|
1953
|
+
const newSet = new Set(newAddresses.map((a)=>a.toString()));
|
|
1954
|
+
const added = newAddresses.filter((a)=>!oldSet.has(a.toString()));
|
|
1955
|
+
const removed = oldAddresses.filter((a)=>!newSet.has(a.toString()));
|
|
1956
|
+
if (added.length > 0) {
|
|
1957
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map((a)=>a.toString()).join(', ')}`);
|
|
1958
|
+
}
|
|
1959
|
+
if (removed.length > 0) {
|
|
1960
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map((a)=>a.toString()).join(', ')}`);
|
|
1961
|
+
}
|
|
1962
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1963
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1964
|
+
}
|
|
1965
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1966
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1967
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1968
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1969
|
+
if (this.sequencer) {
|
|
1970
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1971
|
+
}
|
|
1972
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1973
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1974
|
+
const slashValidatorsNever = unique([
|
|
1975
|
+
...this.config.slashValidatorsNever ?? [],
|
|
1976
|
+
...newAddresses
|
|
1977
|
+
].map((a)=>a.toString())).map(EthAddress.fromString);
|
|
1978
|
+
this.slasherClient.updateConfig({
|
|
1979
|
+
slashValidatorsNever
|
|
1980
|
+
});
|
|
1981
|
+
}
|
|
1982
|
+
this.keyStoreManager = newManager;
|
|
1983
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1984
|
+
}
|
|
1985
|
+
async mineBlock() {
|
|
1986
|
+
if (this.automineSequencer) {
|
|
1987
|
+
await this.automineSequencer.buildEmptyBlock();
|
|
1988
|
+
return;
|
|
1989
|
+
}
|
|
1990
|
+
if (!this.sequencer) {
|
|
1991
|
+
throw new BadRequestError('Cannot mine block: no sequencer is running');
|
|
1992
|
+
}
|
|
1993
|
+
const currentBlockNumber = await this.getBlockNumber();
|
|
1994
|
+
// Use slot duration + 50% buffer as the timeout so this works on running networks too
|
|
1995
|
+
const { slotDuration } = await this.blockSource.getL1Constants();
|
|
1996
|
+
const timeoutSeconds = Math.ceil(slotDuration * 1.5);
|
|
1997
|
+
// Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
|
|
1998
|
+
const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
|
|
1999
|
+
this.sequencer.updateConfig({
|
|
2000
|
+
minTxsPerBlock: 0
|
|
2001
|
+
});
|
|
2002
|
+
try {
|
|
2003
|
+
// Trigger the sequencer to produce a block immediately
|
|
2004
|
+
void this.sequencer.trigger();
|
|
2005
|
+
// Wait for the new L2 block to appear
|
|
2006
|
+
await retryUntil(async ()=>{
|
|
2007
|
+
const newBlockNumber = await this.getBlockNumber();
|
|
2008
|
+
return newBlockNumber > currentBlockNumber ? true : undefined;
|
|
2009
|
+
}, 'mineBlock', timeoutSeconds, 0.1);
|
|
2010
|
+
} finally{
|
|
2011
|
+
this.sequencer.updateConfig({
|
|
2012
|
+
minTxsPerBlock: originalMinTxsPerBlock
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
1032
2016
|
/**
|
|
1033
2017
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1034
|
-
* @param
|
|
2018
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1035
2019
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1036
|
-
*/ async
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
2020
|
+
*/ async getWorldState(block) {
|
|
2021
|
+
const query = this.normalizeBlockParameter(block);
|
|
2022
|
+
// When the request anchors on a specific block hash, resolve it against the archiver up front and
|
|
2023
|
+
// drive the world-state sync to that exact block number and hash. Resolving against the archiver
|
|
2024
|
+
// first fails fast with a clear reorg error if the hash is unknown, and passing the hash to the
|
|
2025
|
+
// synchronizer makes the sync reorg-aware: it barriers until the archive-tree commit for that block
|
|
2026
|
+
// has landed and verifies it matches the requested fork, instead of syncing to bare latest height
|
|
2027
|
+
// and then racing the snapshot read below against an in-flight archive-tree write.
|
|
2028
|
+
const requestedHash = 'hash' in query ? query.hash : undefined;
|
|
2029
|
+
const anchorBlockNumber = requestedHash !== undefined ? await this.resolveBlockNumber(query) : undefined;
|
|
1040
2030
|
let blockSyncedTo = BlockNumber.ZERO;
|
|
1041
2031
|
try {
|
|
1042
2032
|
// Attempt to sync the world state if necessary
|
|
1043
|
-
blockSyncedTo = await this.#syncWorldState();
|
|
2033
|
+
blockSyncedTo = await this.#syncWorldState(anchorBlockNumber, requestedHash);
|
|
1044
2034
|
} catch (err) {
|
|
1045
2035
|
this.log.error(`Error getting world state: ${err}`);
|
|
1046
2036
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
2037
|
+
if ('tag' in query && query.tag === 'proposed') {
|
|
2038
|
+
this.log.debug(`Using committed db for latest block, world state synced upto ${blockSyncedTo}`);
|
|
1050
2039
|
return this.worldStateSynchronizer.getCommitted();
|
|
1051
|
-
} else if (blockNumber <= blockSyncedTo) {
|
|
1052
|
-
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1053
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1054
|
-
} else {
|
|
1055
|
-
throw new Error(`Block ${blockNumber} not yet synced`);
|
|
1056
2040
|
}
|
|
2041
|
+
const blockNumber = anchorBlockNumber ?? await this.resolveBlockNumber(query);
|
|
2042
|
+
// Check it's within world state sync range
|
|
2043
|
+
if (blockNumber > blockSyncedTo) {
|
|
2044
|
+
throw new Error(`Queried block ${inspectBlockParameter(block)} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
2045
|
+
}
|
|
2046
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
2047
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
2048
|
+
// Double-check world-state synced to the same block hash as was requested.
|
|
2049
|
+
// Block 0 is skipped: the snapshot returned by `getSnapshot(0)` is the *pre*-genesis archive
|
|
2050
|
+
// (size 0), so leaf 0 is not yet inserted from that snapshot's view even though block 0's hash
|
|
2051
|
+
// does live at archive index 0 in the committed tree. The genesis hash is already validated by
|
|
2052
|
+
// the archiver when it resolves the hash query to block number 0.
|
|
2053
|
+
if (requestedHash !== undefined && blockNumber !== BlockNumber.ZERO) {
|
|
2054
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
2055
|
+
if (!blockHash || !requestedHash.equals(blockHash)) {
|
|
2056
|
+
throw new Error(`Block hash ${requestedHash.toString()} not found in world state at block number ${blockNumber} (world state has ${blockHash?.toString() ?? 'no hash'} at that index, genesis header hash is ${this.blockSource.getGenesisBlockHash().toString()}). If the node API has been queried with anchor block hash possibly a reorg has occurred.`);
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
return snapshot;
|
|
2060
|
+
}
|
|
2061
|
+
/** Resolves any {@link BlockParameter} variant to a concrete block number. */ async resolveBlockNumber(block) {
|
|
2062
|
+
const query = this.normalizeBlockParameter(block);
|
|
2063
|
+
const blockNumber = await this.blockSource.getBlockNumber(query);
|
|
2064
|
+
if (blockNumber === undefined) {
|
|
2065
|
+
if ('hash' in query) {
|
|
2066
|
+
throw new Error(`Block hash ${query.hash.toString()} not found when querying world state. If the node API has been queried with anchor block hash possibly a reorg has occurred.`);
|
|
2067
|
+
}
|
|
2068
|
+
if ('archive' in query) {
|
|
2069
|
+
throw new Error(`Block with archive ${query.archive.toString()} not found.`);
|
|
2070
|
+
}
|
|
2071
|
+
throw new Error(`Block not found for ${inspectBlockParameter(block)}.`);
|
|
2072
|
+
}
|
|
2073
|
+
return blockNumber;
|
|
1057
2074
|
}
|
|
1058
2075
|
/**
|
|
1059
|
-
* Ensure
|
|
2076
|
+
* Ensure the world state is synced.
|
|
2077
|
+
* @param targetBlockNumber - Block to sync up to. Defaults to the latest block known to the archiver.
|
|
2078
|
+
* @param blockHash - If provided, the synchronizer verifies the block at `targetBlockNumber` matches this
|
|
2079
|
+
* hash, resyncing (and so detecting reorgs) if it does not yet match or has been reorged away.
|
|
1060
2080
|
* @returns A promise that fulfils once the world state is synced
|
|
1061
|
-
*/ async #syncWorldState() {
|
|
1062
|
-
const
|
|
1063
|
-
return await this.worldStateSynchronizer.syncImmediate(
|
|
2081
|
+
*/ async #syncWorldState(targetBlockNumber, blockHash) {
|
|
2082
|
+
const target = targetBlockNumber ?? await this.blockSource.getBlockNumber();
|
|
2083
|
+
return await this.worldStateSynchronizer.syncImmediate(target, blockHash);
|
|
1064
2084
|
}
|
|
1065
2085
|
}
|
|
1066
|
-
_ts_decorate([
|
|
1067
|
-
trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
1068
|
-
[Attributes.TX_HASH]: tx.getTxHash().toString()
|
|
1069
|
-
}))
|
|
1070
|
-
], AztecNodeService.prototype, "simulatePublicCalls", null);
|