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