@aztec/aztec-node 0.0.0-test.1 → 0.0.1-commit.0b941701
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/config.d.ts +18 -10
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +81 -14
- 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 +17 -7
- package/dest/aztec-node/server.d.ts +114 -141
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +1093 -339
- 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 +8 -0
- package/dest/sentinel/config.d.ts.map +1 -0
- package/dest/sentinel/config.js +29 -0
- package/dest/sentinel/factory.d.ts +9 -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 +93 -0
- package/dest/sentinel/sentinel.d.ts.map +1 -0
- package/dest/sentinel/sentinel.js +403 -0
- package/dest/sentinel/store.d.ts +35 -0
- package/dest/sentinel/store.d.ts.map +1 -0
- package/dest/sentinel/store.js +170 -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 +46 -35
- package/src/aztec-node/config.ts +132 -25
- package/src/aztec-node/node_metrics.ts +24 -14
- package/src/aztec-node/server.ts +902 -418
- package/src/bin/index.ts +4 -2
- package/src/index.ts +0 -1
- package/src/sentinel/config.ts +37 -0
- package/src/sentinel/factory.ts +36 -0
- package/src/sentinel/index.ts +8 -0
- package/src/sentinel/sentinel.ts +510 -0
- package/src/sentinel/store.ts +185 -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,422 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
function applyDecs2203RFactory() {
|
|
2
|
+
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
3
|
+
return function addInitializer(initializer) {
|
|
4
|
+
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
5
|
+
assertCallable(initializer, "An initializer");
|
|
6
|
+
initializers.push(initializer);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
|
|
10
|
+
var kindStr;
|
|
11
|
+
switch(kind){
|
|
12
|
+
case 1:
|
|
13
|
+
kindStr = "accessor";
|
|
14
|
+
break;
|
|
15
|
+
case 2:
|
|
16
|
+
kindStr = "method";
|
|
17
|
+
break;
|
|
18
|
+
case 3:
|
|
19
|
+
kindStr = "getter";
|
|
20
|
+
break;
|
|
21
|
+
case 4:
|
|
22
|
+
kindStr = "setter";
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
kindStr = "field";
|
|
26
|
+
}
|
|
27
|
+
var ctx = {
|
|
28
|
+
kind: kindStr,
|
|
29
|
+
name: isPrivate ? "#" + name : name,
|
|
30
|
+
static: isStatic,
|
|
31
|
+
private: isPrivate,
|
|
32
|
+
metadata: metadata
|
|
33
|
+
};
|
|
34
|
+
var decoratorFinishedRef = {
|
|
35
|
+
v: false
|
|
36
|
+
};
|
|
37
|
+
ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
|
|
38
|
+
var get, set;
|
|
39
|
+
if (kind === 0) {
|
|
40
|
+
if (isPrivate) {
|
|
41
|
+
get = desc.get;
|
|
42
|
+
set = desc.set;
|
|
43
|
+
} else {
|
|
44
|
+
get = function() {
|
|
45
|
+
return this[name];
|
|
46
|
+
};
|
|
47
|
+
set = function(v) {
|
|
48
|
+
this[name] = v;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
} else if (kind === 2) {
|
|
52
|
+
get = function() {
|
|
53
|
+
return desc.value;
|
|
54
|
+
};
|
|
55
|
+
} else {
|
|
56
|
+
if (kind === 1 || kind === 3) {
|
|
57
|
+
get = function() {
|
|
58
|
+
return desc.get.call(this);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (kind === 1 || kind === 4) {
|
|
62
|
+
set = function(v) {
|
|
63
|
+
desc.set.call(this, v);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
ctx.access = get && set ? {
|
|
68
|
+
get: get,
|
|
69
|
+
set: set
|
|
70
|
+
} : get ? {
|
|
71
|
+
get: get
|
|
72
|
+
} : {
|
|
73
|
+
set: set
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
return dec(value, ctx);
|
|
77
|
+
} finally{
|
|
78
|
+
decoratorFinishedRef.v = true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function assertNotFinished(decoratorFinishedRef, fnName) {
|
|
82
|
+
if (decoratorFinishedRef.v) {
|
|
83
|
+
throw new Error("attempted to call " + fnName + " after decoration was finished");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function assertCallable(fn, hint) {
|
|
87
|
+
if (typeof fn !== "function") {
|
|
88
|
+
throw new TypeError(hint + " must be a function");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function assertValidReturnValue(kind, value) {
|
|
92
|
+
var type = typeof value;
|
|
93
|
+
if (kind === 1) {
|
|
94
|
+
if (type !== "object" || value === null) {
|
|
95
|
+
throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
96
|
+
}
|
|
97
|
+
if (value.get !== undefined) {
|
|
98
|
+
assertCallable(value.get, "accessor.get");
|
|
99
|
+
}
|
|
100
|
+
if (value.set !== undefined) {
|
|
101
|
+
assertCallable(value.set, "accessor.set");
|
|
102
|
+
}
|
|
103
|
+
if (value.init !== undefined) {
|
|
104
|
+
assertCallable(value.init, "accessor.init");
|
|
105
|
+
}
|
|
106
|
+
} else if (type !== "function") {
|
|
107
|
+
var hint;
|
|
108
|
+
if (kind === 0) {
|
|
109
|
+
hint = "field";
|
|
110
|
+
} else if (kind === 10) {
|
|
111
|
+
hint = "class";
|
|
112
|
+
} else {
|
|
113
|
+
hint = "method";
|
|
114
|
+
}
|
|
115
|
+
throw new TypeError(hint + " decorators must return a function or void 0");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
|
|
119
|
+
var decs = decInfo[0];
|
|
120
|
+
var desc, init, value;
|
|
121
|
+
if (isPrivate) {
|
|
122
|
+
if (kind === 0 || kind === 1) {
|
|
123
|
+
desc = {
|
|
124
|
+
get: decInfo[3],
|
|
125
|
+
set: decInfo[4]
|
|
126
|
+
};
|
|
127
|
+
} else if (kind === 3) {
|
|
128
|
+
desc = {
|
|
129
|
+
get: decInfo[3]
|
|
130
|
+
};
|
|
131
|
+
} else if (kind === 4) {
|
|
132
|
+
desc = {
|
|
133
|
+
set: decInfo[3]
|
|
134
|
+
};
|
|
135
|
+
} else {
|
|
136
|
+
desc = {
|
|
137
|
+
value: decInfo[3]
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
} else if (kind !== 0) {
|
|
141
|
+
desc = Object.getOwnPropertyDescriptor(base, name);
|
|
142
|
+
}
|
|
143
|
+
if (kind === 1) {
|
|
144
|
+
value = {
|
|
145
|
+
get: desc.get,
|
|
146
|
+
set: desc.set
|
|
147
|
+
};
|
|
148
|
+
} else if (kind === 2) {
|
|
149
|
+
value = desc.value;
|
|
150
|
+
} else if (kind === 3) {
|
|
151
|
+
value = desc.get;
|
|
152
|
+
} else if (kind === 4) {
|
|
153
|
+
value = desc.set;
|
|
154
|
+
}
|
|
155
|
+
var newValue, get, set;
|
|
156
|
+
if (typeof decs === "function") {
|
|
157
|
+
newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
158
|
+
if (newValue !== void 0) {
|
|
159
|
+
assertValidReturnValue(kind, newValue);
|
|
160
|
+
if (kind === 0) {
|
|
161
|
+
init = newValue;
|
|
162
|
+
} else if (kind === 1) {
|
|
163
|
+
init = newValue.init;
|
|
164
|
+
get = newValue.get || value.get;
|
|
165
|
+
set = newValue.set || value.set;
|
|
166
|
+
value = {
|
|
167
|
+
get: get,
|
|
168
|
+
set: set
|
|
169
|
+
};
|
|
170
|
+
} else {
|
|
171
|
+
value = newValue;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
for(var i = decs.length - 1; i >= 0; i--){
|
|
176
|
+
var dec = decs[i];
|
|
177
|
+
newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
178
|
+
if (newValue !== void 0) {
|
|
179
|
+
assertValidReturnValue(kind, newValue);
|
|
180
|
+
var newInit;
|
|
181
|
+
if (kind === 0) {
|
|
182
|
+
newInit = newValue;
|
|
183
|
+
} else if (kind === 1) {
|
|
184
|
+
newInit = newValue.init;
|
|
185
|
+
get = newValue.get || value.get;
|
|
186
|
+
set = newValue.set || value.set;
|
|
187
|
+
value = {
|
|
188
|
+
get: get,
|
|
189
|
+
set: set
|
|
190
|
+
};
|
|
191
|
+
} else {
|
|
192
|
+
value = newValue;
|
|
193
|
+
}
|
|
194
|
+
if (newInit !== void 0) {
|
|
195
|
+
if (init === void 0) {
|
|
196
|
+
init = newInit;
|
|
197
|
+
} else if (typeof init === "function") {
|
|
198
|
+
init = [
|
|
199
|
+
init,
|
|
200
|
+
newInit
|
|
201
|
+
];
|
|
202
|
+
} else {
|
|
203
|
+
init.push(newInit);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (kind === 0 || kind === 1) {
|
|
210
|
+
if (init === void 0) {
|
|
211
|
+
init = function(instance, init) {
|
|
212
|
+
return init;
|
|
213
|
+
};
|
|
214
|
+
} else if (typeof init !== "function") {
|
|
215
|
+
var ownInitializers = init;
|
|
216
|
+
init = function(instance, init) {
|
|
217
|
+
var value = init;
|
|
218
|
+
for(var i = 0; i < ownInitializers.length; i++){
|
|
219
|
+
value = ownInitializers[i].call(instance, value);
|
|
220
|
+
}
|
|
221
|
+
return value;
|
|
222
|
+
};
|
|
223
|
+
} else {
|
|
224
|
+
var originalInitializer = init;
|
|
225
|
+
init = function(instance, init) {
|
|
226
|
+
return originalInitializer.call(instance, init);
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
ret.push(init);
|
|
230
|
+
}
|
|
231
|
+
if (kind !== 0) {
|
|
232
|
+
if (kind === 1) {
|
|
233
|
+
desc.get = value.get;
|
|
234
|
+
desc.set = value.set;
|
|
235
|
+
} else if (kind === 2) {
|
|
236
|
+
desc.value = value;
|
|
237
|
+
} else if (kind === 3) {
|
|
238
|
+
desc.get = value;
|
|
239
|
+
} else if (kind === 4) {
|
|
240
|
+
desc.set = value;
|
|
241
|
+
}
|
|
242
|
+
if (isPrivate) {
|
|
243
|
+
if (kind === 1) {
|
|
244
|
+
ret.push(function(instance, args) {
|
|
245
|
+
return value.get.call(instance, args);
|
|
246
|
+
});
|
|
247
|
+
ret.push(function(instance, args) {
|
|
248
|
+
return value.set.call(instance, args);
|
|
249
|
+
});
|
|
250
|
+
} else if (kind === 2) {
|
|
251
|
+
ret.push(value);
|
|
252
|
+
} else {
|
|
253
|
+
ret.push(function(instance, args) {
|
|
254
|
+
return value.call(instance, args);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
} else {
|
|
258
|
+
Object.defineProperty(base, name, desc);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function applyMemberDecs(Class, decInfos, metadata) {
|
|
263
|
+
var ret = [];
|
|
264
|
+
var protoInitializers;
|
|
265
|
+
var staticInitializers;
|
|
266
|
+
var existingProtoNonFields = new Map();
|
|
267
|
+
var existingStaticNonFields = new Map();
|
|
268
|
+
for(var i = 0; i < decInfos.length; i++){
|
|
269
|
+
var decInfo = decInfos[i];
|
|
270
|
+
if (!Array.isArray(decInfo)) continue;
|
|
271
|
+
var kind = decInfo[1];
|
|
272
|
+
var name = decInfo[2];
|
|
273
|
+
var isPrivate = decInfo.length > 3;
|
|
274
|
+
var isStatic = kind >= 5;
|
|
275
|
+
var base;
|
|
276
|
+
var initializers;
|
|
277
|
+
if (isStatic) {
|
|
278
|
+
base = Class;
|
|
279
|
+
kind = kind - 5;
|
|
280
|
+
staticInitializers = staticInitializers || [];
|
|
281
|
+
initializers = staticInitializers;
|
|
282
|
+
} else {
|
|
283
|
+
base = Class.prototype;
|
|
284
|
+
protoInitializers = protoInitializers || [];
|
|
285
|
+
initializers = protoInitializers;
|
|
286
|
+
}
|
|
287
|
+
if (kind !== 0 && !isPrivate) {
|
|
288
|
+
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
|
|
289
|
+
var existingKind = existingNonFields.get(name) || 0;
|
|
290
|
+
if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
|
|
291
|
+
throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
|
|
292
|
+
} else if (!existingKind && kind > 2) {
|
|
293
|
+
existingNonFields.set(name, kind);
|
|
294
|
+
} else {
|
|
295
|
+
existingNonFields.set(name, true);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
|
|
299
|
+
}
|
|
300
|
+
pushInitializers(ret, protoInitializers);
|
|
301
|
+
pushInitializers(ret, staticInitializers);
|
|
302
|
+
return ret;
|
|
303
|
+
}
|
|
304
|
+
function pushInitializers(ret, initializers) {
|
|
305
|
+
if (initializers) {
|
|
306
|
+
ret.push(function(instance) {
|
|
307
|
+
for(var i = 0; i < initializers.length; i++){
|
|
308
|
+
initializers[i].call(instance);
|
|
309
|
+
}
|
|
310
|
+
return instance;
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function applyClassDecs(targetClass, classDecs, metadata) {
|
|
315
|
+
if (classDecs.length > 0) {
|
|
316
|
+
var initializers = [];
|
|
317
|
+
var newClass = targetClass;
|
|
318
|
+
var name = targetClass.name;
|
|
319
|
+
for(var i = classDecs.length - 1; i >= 0; i--){
|
|
320
|
+
var decoratorFinishedRef = {
|
|
321
|
+
v: false
|
|
322
|
+
};
|
|
323
|
+
try {
|
|
324
|
+
var nextNewClass = classDecs[i](newClass, {
|
|
325
|
+
kind: "class",
|
|
326
|
+
name: name,
|
|
327
|
+
addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
|
|
328
|
+
metadata
|
|
329
|
+
});
|
|
330
|
+
} finally{
|
|
331
|
+
decoratorFinishedRef.v = true;
|
|
332
|
+
}
|
|
333
|
+
if (nextNewClass !== undefined) {
|
|
334
|
+
assertValidReturnValue(10, nextNewClass);
|
|
335
|
+
newClass = nextNewClass;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return [
|
|
339
|
+
defineMetadata(newClass, metadata),
|
|
340
|
+
function() {
|
|
341
|
+
for(var i = 0; i < initializers.length; i++){
|
|
342
|
+
initializers[i].call(newClass);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
];
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
function defineMetadata(Class, metadata) {
|
|
349
|
+
return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
|
|
350
|
+
configurable: true,
|
|
351
|
+
enumerable: true,
|
|
352
|
+
value: metadata
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
|
|
356
|
+
if (parentClass !== void 0) {
|
|
357
|
+
var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
358
|
+
}
|
|
359
|
+
var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
|
|
360
|
+
var e = applyMemberDecs(targetClass, memberDecs, metadata);
|
|
361
|
+
if (!classDecs.length) defineMetadata(targetClass, metadata);
|
|
362
|
+
return {
|
|
363
|
+
e: e,
|
|
364
|
+
get c () {
|
|
365
|
+
return applyClassDecs(targetClass, classDecs, metadata);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
};
|
|
6
369
|
}
|
|
370
|
+
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
371
|
+
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
372
|
+
}
|
|
373
|
+
var _dec, _initProto;
|
|
7
374
|
import { createArchiver } from '@aztec/archiver';
|
|
8
|
-
import { BBCircuitVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
|
|
9
|
-
import {
|
|
10
|
-
import { INITIAL_L2_BLOCK_NUM, REGISTERER_CONTRACT_ADDRESS } from '@aztec/constants';
|
|
375
|
+
import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
|
|
376
|
+
import { createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
11
377
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
12
|
-
import { createEthereumChain } from '@aztec/ethereum';
|
|
13
|
-
import {
|
|
378
|
+
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
379
|
+
import { getPublicClient } from '@aztec/ethereum/client';
|
|
380
|
+
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
381
|
+
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
382
|
+
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
383
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
14
384
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
15
|
-
import {
|
|
385
|
+
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
16
386
|
import { createLogger } from '@aztec/foundation/log';
|
|
387
|
+
import { count } from '@aztec/foundation/string';
|
|
17
388
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
389
|
+
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
390
|
+
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
391
|
+
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
392
|
+
import { createForwarderL1TxUtilsFromEthSigner, createL1TxUtilsWithBlobsFromEthSigner } from '@aztec/node-lib/factories';
|
|
393
|
+
import { createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
22
394
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
23
|
-
import { GlobalVariableBuilder, SequencerClient
|
|
395
|
+
import { GlobalVariableBuilder, SequencerClient } from '@aztec/sequencer-client';
|
|
24
396
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
397
|
+
import { AttestationsBlockWatcher, EpochPruneWatcher, createSlasher } from '@aztec/slasher';
|
|
398
|
+
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
25
399
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
26
|
-
import {
|
|
400
|
+
import { L2Block, L2BlockHash } from '@aztec/stdlib/block';
|
|
401
|
+
import { GasFees } from '@aztec/stdlib/gas';
|
|
402
|
+
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
403
|
+
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
27
404
|
import { tryStop } from '@aztec/stdlib/interfaces/server';
|
|
405
|
+
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
28
406
|
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
29
407
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
30
408
|
import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
409
|
+
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
31
410
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
32
|
-
import { createValidatorClient } from '@aztec/validator-client';
|
|
411
|
+
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createBlockProposalHandler, createValidatorClient, createValidatorForAcceptingTxs } from '@aztec/validator-client';
|
|
33
412
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
34
|
-
import {
|
|
413
|
+
import { createPublicClient, fallback, http } from 'viem';
|
|
414
|
+
import { createSentinel } from '../sentinel/factory.js';
|
|
415
|
+
import { createKeyStoreForValidator } from './config.js';
|
|
35
416
|
import { NodeMetrics } from './node_metrics.js';
|
|
417
|
+
_dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
418
|
+
[Attributes.TX_HASH]: tx.getTxHash().toString()
|
|
419
|
+
}));
|
|
36
420
|
/**
|
|
37
421
|
* The aztec node.
|
|
38
422
|
*/ export class AztecNodeService {
|
|
@@ -42,35 +426,57 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
42
426
|
logsSource;
|
|
43
427
|
contractDataSource;
|
|
44
428
|
l1ToL2MessageSource;
|
|
45
|
-
nullifierSource;
|
|
46
429
|
worldStateSynchronizer;
|
|
47
430
|
sequencer;
|
|
431
|
+
slasherClient;
|
|
432
|
+
validatorsSentinel;
|
|
433
|
+
epochPruneWatcher;
|
|
48
434
|
l1ChainId;
|
|
49
435
|
version;
|
|
50
436
|
globalVariableBuilder;
|
|
437
|
+
epochCache;
|
|
438
|
+
packageVersion;
|
|
51
439
|
proofVerifier;
|
|
52
440
|
telemetry;
|
|
53
441
|
log;
|
|
54
|
-
|
|
442
|
+
blobClient;
|
|
443
|
+
static{
|
|
444
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
445
|
+
[
|
|
446
|
+
_dec,
|
|
447
|
+
2,
|
|
448
|
+
"simulatePublicCalls"
|
|
449
|
+
]
|
|
450
|
+
], []));
|
|
451
|
+
}
|
|
55
452
|
metrics;
|
|
453
|
+
initialHeaderHashPromise;
|
|
454
|
+
// Prevent two snapshot operations to happen simultaneously
|
|
455
|
+
isUploadingSnapshot;
|
|
56
456
|
tracer;
|
|
57
|
-
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource,
|
|
457
|
+
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry = getTelemetryClient(), log = createLogger('node'), blobClient){
|
|
58
458
|
this.config = config;
|
|
59
459
|
this.p2pClient = p2pClient;
|
|
60
460
|
this.blockSource = blockSource;
|
|
61
461
|
this.logsSource = logsSource;
|
|
62
462
|
this.contractDataSource = contractDataSource;
|
|
63
463
|
this.l1ToL2MessageSource = l1ToL2MessageSource;
|
|
64
|
-
this.nullifierSource = nullifierSource;
|
|
65
464
|
this.worldStateSynchronizer = worldStateSynchronizer;
|
|
66
465
|
this.sequencer = sequencer;
|
|
466
|
+
this.slasherClient = slasherClient;
|
|
467
|
+
this.validatorsSentinel = validatorsSentinel;
|
|
468
|
+
this.epochPruneWatcher = epochPruneWatcher;
|
|
67
469
|
this.l1ChainId = l1ChainId;
|
|
68
470
|
this.version = version;
|
|
69
471
|
this.globalVariableBuilder = globalVariableBuilder;
|
|
472
|
+
this.epochCache = epochCache;
|
|
473
|
+
this.packageVersion = packageVersion;
|
|
70
474
|
this.proofVerifier = proofVerifier;
|
|
71
475
|
this.telemetry = telemetry;
|
|
72
476
|
this.log = log;
|
|
73
|
-
this.
|
|
477
|
+
this.blobClient = blobClient;
|
|
478
|
+
this.initialHeaderHashPromise = (_initProto(this), undefined);
|
|
479
|
+
this.isUploadingSnapshot = false;
|
|
74
480
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
75
481
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
76
482
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
@@ -87,59 +493,222 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
87
493
|
* initializes the Aztec Node, wait for component to sync.
|
|
88
494
|
* @param config - The configuration to be used by the aztec node.
|
|
89
495
|
* @returns - A fully synced Aztec Node for use in development/testing.
|
|
90
|
-
*/ static async createAndSync(
|
|
91
|
-
const
|
|
496
|
+
*/ static async createAndSync(inputConfig, deps = {}, options = {}) {
|
|
497
|
+
const config = {
|
|
498
|
+
...inputConfig
|
|
499
|
+
}; // Copy the config so we dont mutate the input object
|
|
92
500
|
const log = deps.logger ?? createLogger('node');
|
|
501
|
+
const packageVersion = getPackageVersion() ?? '';
|
|
502
|
+
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
93
503
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
94
|
-
const blobSinkClient = deps.blobSinkClient ?? createBlobSinkClient(config);
|
|
95
504
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
96
|
-
//
|
|
505
|
+
// Build a key store from file if given or from environment otherwise
|
|
506
|
+
let keyStoreManager;
|
|
507
|
+
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
508
|
+
if (keyStoreProvided) {
|
|
509
|
+
const keyStores = loadKeystores(config.keyStoreDirectory);
|
|
510
|
+
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
511
|
+
} else {
|
|
512
|
+
const keyStore = createKeyStoreForValidator(config);
|
|
513
|
+
if (keyStore) {
|
|
514
|
+
keyStoreManager = new KeystoreManager(keyStore);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
await keyStoreManager?.validateSigners();
|
|
518
|
+
// If we are a validator, verify our configuration before doing too much more.
|
|
519
|
+
if (!config.disableValidator) {
|
|
520
|
+
if (keyStoreManager === undefined) {
|
|
521
|
+
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
522
|
+
}
|
|
523
|
+
if (!keyStoreProvided) {
|
|
524
|
+
log.warn('KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS');
|
|
525
|
+
}
|
|
526
|
+
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
527
|
+
}
|
|
528
|
+
// validate that the actual chain id matches that specified in configuration
|
|
97
529
|
if (config.l1ChainId !== ethereumChain.chainInfo.id) {
|
|
98
530
|
throw new Error(`RPC URL configured for chain id ${ethereumChain.chainInfo.id} but expected id ${config.l1ChainId}`);
|
|
99
531
|
}
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
532
|
+
const publicClient = createPublicClient({
|
|
533
|
+
chain: ethereumChain.chainInfo,
|
|
534
|
+
transport: fallback(config.l1RpcUrls.map((url)=>http(url, {
|
|
535
|
+
batch: false
|
|
536
|
+
}))),
|
|
537
|
+
pollingInterval: config.viemPollingIntervalMS
|
|
538
|
+
});
|
|
539
|
+
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.l1Contracts.registryAddress, config.rollupVersion ?? 'canonical');
|
|
540
|
+
// Overwrite the passed in vars.
|
|
541
|
+
config.l1Contracts = {
|
|
542
|
+
...config.l1Contracts,
|
|
543
|
+
...l1ContractsAddresses
|
|
544
|
+
};
|
|
545
|
+
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
546
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
547
|
+
rollupContract.getL1GenesisTime(),
|
|
548
|
+
rollupContract.getSlotDuration(),
|
|
549
|
+
rollupContract.getVersion()
|
|
550
|
+
]);
|
|
551
|
+
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
552
|
+
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
553
|
+
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}).`);
|
|
554
|
+
}
|
|
555
|
+
const blobClient = await createBlobClientWithFileStores(config, createLogger('node:blob-client:client'));
|
|
556
|
+
// attempt snapshot sync if possible
|
|
557
|
+
await trySnapshotSync(config, log);
|
|
558
|
+
const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, {
|
|
559
|
+
dateProvider
|
|
560
|
+
});
|
|
561
|
+
const archiver = await createArchiver(config, {
|
|
562
|
+
blobClient,
|
|
563
|
+
epochCache,
|
|
564
|
+
telemetry,
|
|
565
|
+
dateProvider
|
|
566
|
+
}, {
|
|
567
|
+
blockUntilSync: !config.skipArchiverInitialSync
|
|
568
|
+
});
|
|
103
569
|
// now create the merkle trees and the world state synchronizer
|
|
104
570
|
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.prefilledPublicData, telemetry);
|
|
105
|
-
const
|
|
571
|
+
const circuitVerifier = config.realProofs || config.debugForceTxProofVerification ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
106
572
|
if (!config.realProofs) {
|
|
107
573
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
108
574
|
}
|
|
109
|
-
const
|
|
110
|
-
dateProvider
|
|
111
|
-
});
|
|
575
|
+
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
112
576
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
113
|
-
const p2pClient = await createP2PClient(P2PClientType.Full, config, archiver, proofVerifier, worldStateSynchronizer, epochCache, telemetry);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
577
|
+
const p2pClient = await createP2PClient(P2PClientType.Full, config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
578
|
+
// We should really not be modifying the config object
|
|
579
|
+
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
|
|
580
|
+
// Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
|
|
581
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
582
|
+
...config,
|
|
583
|
+
l1GenesisTime,
|
|
584
|
+
slotDuration: Number(slotDuration)
|
|
585
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
586
|
+
// We'll accumulate sentinel watchers here
|
|
587
|
+
const watchers = [];
|
|
588
|
+
// Create validator client if required
|
|
589
|
+
const validatorClient = await createValidatorClient(config, {
|
|
590
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
591
|
+
worldState: worldStateSynchronizer,
|
|
123
592
|
p2pClient,
|
|
124
593
|
telemetry,
|
|
125
594
|
dateProvider,
|
|
126
|
-
epochCache
|
|
127
|
-
|
|
128
|
-
// now create the sequencer
|
|
129
|
-
const sequencer = config.disableValidator ? undefined : await SequencerClient.new(config, {
|
|
130
|
-
...deps,
|
|
131
|
-
validatorClient,
|
|
132
|
-
p2pClient,
|
|
133
|
-
worldStateSynchronizer,
|
|
134
|
-
slasherClient,
|
|
135
|
-
contractDataSource: archiver,
|
|
136
|
-
l2BlockSource: archiver,
|
|
595
|
+
epochCache,
|
|
596
|
+
blockSource: archiver,
|
|
137
597
|
l1ToL2MessageSource: archiver,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
blobSinkClient
|
|
598
|
+
keyStoreManager,
|
|
599
|
+
blobClient
|
|
141
600
|
});
|
|
142
|
-
|
|
601
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
602
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
603
|
+
// like attestations or auths will fail.
|
|
604
|
+
if (validatorClient) {
|
|
605
|
+
watchers.push(validatorClient);
|
|
606
|
+
if (!options.dontStartSequencer) {
|
|
607
|
+
await validatorClient.registerHandlers();
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
// If there's no validator client but alwaysReexecuteBlockProposals is enabled,
|
|
611
|
+
// create a BlockProposalHandler to reexecute block proposals for monitoring
|
|
612
|
+
if (!validatorClient && config.alwaysReexecuteBlockProposals) {
|
|
613
|
+
log.info('Setting up block proposal reexecution for monitoring');
|
|
614
|
+
createBlockProposalHandler(config, {
|
|
615
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
616
|
+
worldState: worldStateSynchronizer,
|
|
617
|
+
epochCache,
|
|
618
|
+
blockSource: archiver,
|
|
619
|
+
l1ToL2MessageSource: archiver,
|
|
620
|
+
p2pClient,
|
|
621
|
+
dateProvider,
|
|
622
|
+
telemetry
|
|
623
|
+
}).registerForReexecution(p2pClient);
|
|
624
|
+
}
|
|
625
|
+
// Start world state and wait for it to sync to the archiver.
|
|
626
|
+
await worldStateSynchronizer.start();
|
|
627
|
+
// Start p2p. Note that it depends on world state to be running.
|
|
628
|
+
await p2pClient.start();
|
|
629
|
+
const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
630
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
631
|
+
watchers.push(validatorsSentinel);
|
|
632
|
+
}
|
|
633
|
+
let epochPruneWatcher;
|
|
634
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
635
|
+
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
|
|
636
|
+
watchers.push(epochPruneWatcher);
|
|
637
|
+
}
|
|
638
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
639
|
+
let attestationsBlockWatcher;
|
|
640
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
641
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
642
|
+
watchers.push(attestationsBlockWatcher);
|
|
643
|
+
}
|
|
644
|
+
// Start p2p-related services once the archiver has completed sync
|
|
645
|
+
void archiver.waitForInitialSync().then(async ()=>{
|
|
646
|
+
await p2pClient.start();
|
|
647
|
+
await validatorsSentinel?.start();
|
|
648
|
+
await epochPruneWatcher?.start();
|
|
649
|
+
await attestationsBlockWatcher?.start();
|
|
650
|
+
log.info(`All p2p services started`);
|
|
651
|
+
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
652
|
+
// Validator enabled, create/start relevant service
|
|
653
|
+
let sequencer;
|
|
654
|
+
let slasherClient;
|
|
655
|
+
if (!config.disableValidator && validatorClient) {
|
|
656
|
+
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
657
|
+
// as they are executed when the node is selected as proposer.
|
|
658
|
+
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
659
|
+
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
660
|
+
await slasherClient.start();
|
|
661
|
+
const l1TxUtils = config.publisherForwarderAddress ? await createForwarderL1TxUtilsFromEthSigner(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.publisherForwarderAddress, {
|
|
662
|
+
...config,
|
|
663
|
+
scope: 'sequencer'
|
|
664
|
+
}, {
|
|
665
|
+
telemetry,
|
|
666
|
+
logger: log.createChild('l1-tx-utils'),
|
|
667
|
+
dateProvider
|
|
668
|
+
}) : await createL1TxUtilsWithBlobsFromEthSigner(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
669
|
+
...config,
|
|
670
|
+
scope: 'sequencer'
|
|
671
|
+
}, {
|
|
672
|
+
telemetry,
|
|
673
|
+
logger: log.createChild('l1-tx-utils'),
|
|
674
|
+
dateProvider
|
|
675
|
+
});
|
|
676
|
+
// Create and start the sequencer client
|
|
677
|
+
const checkpointsBuilder = new CheckpointsBuilder({
|
|
678
|
+
...config,
|
|
679
|
+
l1GenesisTime,
|
|
680
|
+
slotDuration: Number(slotDuration)
|
|
681
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
682
|
+
sequencer = await SequencerClient.new(config, {
|
|
683
|
+
...deps,
|
|
684
|
+
epochCache,
|
|
685
|
+
l1TxUtils,
|
|
686
|
+
validatorClient,
|
|
687
|
+
p2pClient,
|
|
688
|
+
worldStateSynchronizer,
|
|
689
|
+
slasherClient,
|
|
690
|
+
checkpointsBuilder,
|
|
691
|
+
l2BlockSource: archiver,
|
|
692
|
+
l1ToL2MessageSource: archiver,
|
|
693
|
+
telemetry,
|
|
694
|
+
dateProvider,
|
|
695
|
+
blobClient,
|
|
696
|
+
nodeKeyStore: keyStoreManager
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
if (!options.dontStartSequencer && sequencer) {
|
|
700
|
+
await sequencer.start();
|
|
701
|
+
log.verbose(`Sequencer started`);
|
|
702
|
+
} else if (sequencer) {
|
|
703
|
+
log.warn(`Sequencer created but not started`);
|
|
704
|
+
}
|
|
705
|
+
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
706
|
+
...config,
|
|
707
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
708
|
+
l1GenesisTime,
|
|
709
|
+
slotDuration: Number(slotDuration)
|
|
710
|
+
});
|
|
711
|
+
return new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry, log, blobClient);
|
|
143
712
|
}
|
|
144
713
|
/**
|
|
145
714
|
* Returns the sequencer client instance.
|
|
@@ -165,6 +734,9 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
165
734
|
getEncodedEnr() {
|
|
166
735
|
return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
|
|
167
736
|
}
|
|
737
|
+
async getAllowedPublicSetup() {
|
|
738
|
+
return this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
|
|
739
|
+
}
|
|
168
740
|
/**
|
|
169
741
|
* Method to determine if the node is ready to accept transactions.
|
|
170
742
|
* @returns - Flag indicating the readiness for tx submission.
|
|
@@ -172,7 +744,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
172
744
|
return Promise.resolve(this.p2pClient.isReady() ?? false);
|
|
173
745
|
}
|
|
174
746
|
async getNodeInfo() {
|
|
175
|
-
const [nodeVersion,
|
|
747
|
+
const [nodeVersion, rollupVersion, chainId, enr, contractAddresses, protocolContractAddresses] = await Promise.all([
|
|
176
748
|
this.getNodeVersion(),
|
|
177
749
|
this.getVersion(),
|
|
178
750
|
this.getChainId(),
|
|
@@ -183,7 +755,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
183
755
|
const nodeInfo = {
|
|
184
756
|
nodeVersion,
|
|
185
757
|
l1ChainId: chainId,
|
|
186
|
-
|
|
758
|
+
rollupVersion,
|
|
187
759
|
enr,
|
|
188
760
|
l1ContractAddresses: contractAddresses,
|
|
189
761
|
protocolContractAddresses: protocolContractAddresses
|
|
@@ -191,11 +763,40 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
191
763
|
return nodeInfo;
|
|
192
764
|
}
|
|
193
765
|
/**
|
|
194
|
-
* Get a block specified by its number.
|
|
195
|
-
* @param
|
|
766
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
767
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
768
|
+
* @returns The requested block.
|
|
769
|
+
*/ async getBlock(block) {
|
|
770
|
+
if (L2BlockHash.isL2BlockHash(block)) {
|
|
771
|
+
return this.getBlockByHash(Fr.fromBuffer(block.toBuffer()));
|
|
772
|
+
}
|
|
773
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
774
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
775
|
+
return this.buildInitialBlock();
|
|
776
|
+
}
|
|
777
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Get a block specified by its hash.
|
|
781
|
+
* @param blockHash - The block hash being requested.
|
|
782
|
+
* @returns The requested block.
|
|
783
|
+
*/ async getBlockByHash(blockHash) {
|
|
784
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
785
|
+
if (blockHash.equals(Fr.fromBuffer(initialBlockHash.toBuffer()))) {
|
|
786
|
+
return this.buildInitialBlock();
|
|
787
|
+
}
|
|
788
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
789
|
+
}
|
|
790
|
+
buildInitialBlock() {
|
|
791
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
792
|
+
return L2Block.empty(initialHeader);
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Get a block specified by its archive root.
|
|
796
|
+
* @param archive - The archive root being requested.
|
|
196
797
|
* @returns The requested block.
|
|
197
|
-
*/ async
|
|
198
|
-
return await this.blockSource.
|
|
798
|
+
*/ async getBlockByArchive(archive) {
|
|
799
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
199
800
|
}
|
|
200
801
|
/**
|
|
201
802
|
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
|
|
@@ -203,16 +804,31 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
203
804
|
* @param limit - The maximum number of blocks to obtain.
|
|
204
805
|
* @returns The blocks requested.
|
|
205
806
|
*/ async getBlocks(from, limit) {
|
|
206
|
-
return await this.blockSource.getBlocks(from, limit) ?? [];
|
|
807
|
+
return await this.blockSource.getBlocks(from, BlockNumber(limit)) ?? [];
|
|
808
|
+
}
|
|
809
|
+
async getCheckpoints(from, limit) {
|
|
810
|
+
return await this.blockSource.getCheckpoints(from, limit) ?? [];
|
|
811
|
+
}
|
|
812
|
+
async getCheckpointedBlocks(from, limit) {
|
|
813
|
+
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
207
814
|
}
|
|
208
815
|
/**
|
|
209
|
-
* Method to fetch the current
|
|
210
|
-
* @returns The current
|
|
211
|
-
*/ async
|
|
212
|
-
return await this.globalVariableBuilder.
|
|
816
|
+
* Method to fetch the current min L2 fees.
|
|
817
|
+
* @returns The current min L2 fees.
|
|
818
|
+
*/ async getCurrentMinFees() {
|
|
819
|
+
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
820
|
+
}
|
|
821
|
+
async getMaxPriorityFees() {
|
|
822
|
+
for await (const tx of this.p2pClient.iteratePendingTxs()){
|
|
823
|
+
return tx.getGasSettings().maxPriorityFeesPerGas;
|
|
824
|
+
}
|
|
825
|
+
return GasFees.from({
|
|
826
|
+
feePerDaGas: 0n,
|
|
827
|
+
feePerL2Gas: 0n
|
|
828
|
+
});
|
|
213
829
|
}
|
|
214
830
|
/**
|
|
215
|
-
* Method to fetch the
|
|
831
|
+
* Method to fetch the latest block number synchronized by the node.
|
|
216
832
|
* @returns The block number.
|
|
217
833
|
*/ async getBlockNumber() {
|
|
218
834
|
return await this.blockSource.getBlockNumber();
|
|
@@ -220,6 +836,9 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
220
836
|
async getProvenBlockNumber() {
|
|
221
837
|
return await this.blockSource.getProvenBlockNumber();
|
|
222
838
|
}
|
|
839
|
+
async getCheckpointedBlockNumber() {
|
|
840
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
841
|
+
}
|
|
223
842
|
/**
|
|
224
843
|
* Method to fetch the version of the package.
|
|
225
844
|
* @returns The node package version
|
|
@@ -238,44 +857,37 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
238
857
|
*/ getChainId() {
|
|
239
858
|
return Promise.resolve(this.l1ChainId);
|
|
240
859
|
}
|
|
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;
|
|
860
|
+
getContractClass(id) {
|
|
861
|
+
return this.contractDataSource.getContractClass(id);
|
|
260
862
|
}
|
|
261
863
|
getContract(address) {
|
|
262
864
|
return this.contractDataSource.getContract(address);
|
|
263
865
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
866
|
+
async getPrivateLogsByTags(tags, page, referenceBlock) {
|
|
867
|
+
if (referenceBlock) {
|
|
868
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
869
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
870
|
+
const blockHashFr = Fr.fromBuffer(referenceBlock.toBuffer());
|
|
871
|
+
const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
872
|
+
if (!header) {
|
|
873
|
+
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
271
878
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
879
|
+
async getPublicLogsByTagsFromContract(contractAddress, tags, page, referenceBlock) {
|
|
880
|
+
if (referenceBlock) {
|
|
881
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
882
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
883
|
+
const blockHashFr = Fr.fromBuffer(referenceBlock.toBuffer());
|
|
884
|
+
const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
885
|
+
if (!header) {
|
|
886
|
+
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
279
891
|
}
|
|
280
892
|
/**
|
|
281
893
|
* Gets public logs based on the provided filter.
|
|
@@ -295,18 +907,19 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
295
907
|
* Method to submit a transaction to the p2p pool.
|
|
296
908
|
* @param tx - The transaction to be submitted.
|
|
297
909
|
*/ async sendTx(tx) {
|
|
910
|
+
await this.#sendTx(tx);
|
|
911
|
+
}
|
|
912
|
+
async #sendTx(tx) {
|
|
298
913
|
const timer = new Timer();
|
|
299
|
-
const txHash =
|
|
914
|
+
const txHash = tx.getTxHash().toString();
|
|
300
915
|
const valid = await this.isValidTx(tx);
|
|
301
916
|
if (valid.result !== 'valid') {
|
|
302
917
|
const reason = valid.reason.join(', ');
|
|
303
918
|
this.metrics.receivedTx(timer.ms(), false);
|
|
304
|
-
this.log.warn(`
|
|
919
|
+
this.log.warn(`Received invalid tx ${txHash}: ${reason}`, {
|
|
305
920
|
txHash
|
|
306
921
|
});
|
|
307
|
-
|
|
308
|
-
// throw new Error(`Invalid tx: ${reason}`);
|
|
309
|
-
return;
|
|
922
|
+
throw new Error(`Invalid tx: ${reason}`);
|
|
310
923
|
}
|
|
311
924
|
await this.p2pClient.sendTx(tx);
|
|
312
925
|
this.metrics.receivedTx(timer.ms(), true);
|
|
@@ -315,18 +928,24 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
315
928
|
});
|
|
316
929
|
}
|
|
317
930
|
async getTxReceipt(txHash) {
|
|
318
|
-
|
|
319
|
-
//
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
324
|
-
}
|
|
931
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
932
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
933
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
934
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
935
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
325
936
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
326
937
|
if (settledTxReceipt) {
|
|
327
|
-
|
|
938
|
+
// If the archiver has the receipt then return it.
|
|
939
|
+
return settledTxReceipt;
|
|
940
|
+
} else if (isKnownToPool) {
|
|
941
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
942
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
943
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
944
|
+
return new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
945
|
+
} else {
|
|
946
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
947
|
+
return new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
328
948
|
}
|
|
329
|
-
return txReceipt;
|
|
330
949
|
}
|
|
331
950
|
getTxEffect(txHash) {
|
|
332
951
|
return this.blockSource.getTxEffect(txHash);
|
|
@@ -334,212 +953,195 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
334
953
|
/**
|
|
335
954
|
* Method to stop the aztec node.
|
|
336
955
|
*/ async stop() {
|
|
337
|
-
this.log.info(`Stopping`);
|
|
338
|
-
await this.
|
|
339
|
-
await this.
|
|
340
|
-
await this.
|
|
956
|
+
this.log.info(`Stopping Aztec Node`);
|
|
957
|
+
await tryStop(this.validatorsSentinel);
|
|
958
|
+
await tryStop(this.epochPruneWatcher);
|
|
959
|
+
await tryStop(this.slasherClient);
|
|
960
|
+
await tryStop(this.proofVerifier);
|
|
961
|
+
await tryStop(this.sequencer);
|
|
962
|
+
await tryStop(this.p2pClient);
|
|
963
|
+
await tryStop(this.worldStateSynchronizer);
|
|
341
964
|
await tryStop(this.blockSource);
|
|
342
|
-
await this.
|
|
343
|
-
this.
|
|
965
|
+
await tryStop(this.blobClient);
|
|
966
|
+
await tryStop(this.telemetry);
|
|
967
|
+
this.log.info(`Stopped Aztec Node`);
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Returns the blob client used by this node.
|
|
971
|
+
* @internal - Exposed for testing purposes only.
|
|
972
|
+
*/ getBlobClient() {
|
|
973
|
+
return this.blobClient;
|
|
344
974
|
}
|
|
345
975
|
/**
|
|
346
976
|
* Method to retrieve pending txs.
|
|
977
|
+
* @param limit - The number of items to returns
|
|
978
|
+
* @param after - The last known pending tx. Used for pagination
|
|
347
979
|
* @returns - The pending txs.
|
|
348
|
-
*/ getPendingTxs() {
|
|
349
|
-
return this.p2pClient.getPendingTxs();
|
|
980
|
+
*/ getPendingTxs(limit, after) {
|
|
981
|
+
return this.p2pClient.getPendingTxs(limit, after);
|
|
350
982
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
return pendingTxs.length;
|
|
983
|
+
getPendingTxCount() {
|
|
984
|
+
return this.p2pClient.getPendingTxCount();
|
|
354
985
|
}
|
|
355
986
|
/**
|
|
356
|
-
* Method to retrieve a single tx from the mempool or
|
|
987
|
+
* Method to retrieve a single tx from the mempool or unfinalized chain.
|
|
357
988
|
* @param txHash - The transaction hash to return.
|
|
358
989
|
* @returns - The tx if it exists.
|
|
359
990
|
*/ getTxByHash(txHash) {
|
|
360
991
|
return Promise.resolve(this.p2pClient.getTxByHashFromPool(txHash));
|
|
361
992
|
}
|
|
362
993
|
/**
|
|
363
|
-
* Method to retrieve txs from the mempool or
|
|
994
|
+
* Method to retrieve txs from the mempool or unfinalized chain.
|
|
364
995
|
* @param txHash - The transaction hash to return.
|
|
365
996
|
* @returns - The txs if it exists.
|
|
366
997
|
*/ async getTxsByHash(txHashes) {
|
|
367
998
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
368
999
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
* @param blockNumber - The block number at which to get the data or 'latest' for latest data
|
|
382
|
-
* @param treeId - The tree to search in.
|
|
383
|
-
* @param leafIndices - The values to search for
|
|
384
|
-
* @returns The indexes of the given leaves in the given tree or undefined if not found.
|
|
385
|
-
*/ async findBlockNumbersForIndexes(blockNumber, treeId, leafIndices) {
|
|
386
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
387
|
-
return await committedDb.getBlockNumbersForLeafIndices(treeId, leafIndices);
|
|
388
|
-
}
|
|
389
|
-
async findNullifiersIndexesWithBlock(blockNumber, nullifiers) {
|
|
390
|
-
if (blockNumber === 'latest') {
|
|
391
|
-
blockNumber = await this.getBlockNumber();
|
|
1000
|
+
async findLeavesIndexes(block, treeId, leafValues) {
|
|
1001
|
+
const committedDb = await this.#getWorldState(block);
|
|
1002
|
+
const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
|
|
1003
|
+
// We filter out undefined values
|
|
1004
|
+
const indices = maybeIndices.filter((x)=>x !== undefined);
|
|
1005
|
+
// Now we find the block numbers for the indices
|
|
1006
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, indices);
|
|
1007
|
+
// If any of the block numbers are undefined, we throw an error.
|
|
1008
|
+
for(let i = 0; i < indices.length; i++){
|
|
1009
|
+
if (blockNumbers[i] === undefined) {
|
|
1010
|
+
throw new Error(`Block number is undefined for leaf index ${indices[i]} in tree ${MerkleTreeId[treeId]}`);
|
|
1011
|
+
}
|
|
392
1012
|
}
|
|
393
|
-
|
|
1013
|
+
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
1014
|
+
const uniqueBlockNumbers = [
|
|
1015
|
+
...new Set(blockNumbers.filter((x)=>x !== undefined))
|
|
1016
|
+
];
|
|
1017
|
+
// Now we obtain the block hashes from the archive tree by calling await `committedDb.getLeafValue(treeId, index)`
|
|
1018
|
+
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1019
|
+
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
1020
|
+
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1021
|
+
}));
|
|
1022
|
+
// If any of the block hashes are undefined, we throw an error.
|
|
1023
|
+
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
1024
|
+
if (blockHashes[i] === undefined) {
|
|
1025
|
+
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1029
|
+
return maybeIndices.map((index, i)=>{
|
|
1030
|
+
if (index === undefined) {
|
|
1031
|
+
return undefined;
|
|
1032
|
+
}
|
|
1033
|
+
const blockNumber = blockNumbers[i];
|
|
1034
|
+
if (blockNumber === undefined) {
|
|
1035
|
+
return undefined;
|
|
1036
|
+
}
|
|
1037
|
+
const blockHashIndex = uniqueBlockNumbers.indexOf(blockNumber);
|
|
1038
|
+
const blockHash = blockHashes[blockHashIndex];
|
|
1039
|
+
if (!blockHash) {
|
|
1040
|
+
return undefined;
|
|
1041
|
+
}
|
|
1042
|
+
return {
|
|
1043
|
+
l2BlockNumber: BlockNumber(Number(blockNumber)),
|
|
1044
|
+
l2BlockHash: L2BlockHash.fromField(blockHash),
|
|
1045
|
+
data: index
|
|
1046
|
+
};
|
|
1047
|
+
});
|
|
394
1048
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
* @param blockNumber - The block number at which to get the data.
|
|
398
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
399
|
-
* @returns The sibling path for the leaf index.
|
|
400
|
-
*/ async getNullifierSiblingPath(blockNumber, leafIndex) {
|
|
401
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1049
|
+
async getNullifierSiblingPath(block, leafIndex) {
|
|
1050
|
+
const committedDb = await this.#getWorldState(block);
|
|
402
1051
|
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
403
1052
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
* @param blockNumber - The block number at which to get the data.
|
|
407
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
408
|
-
* @returns The sibling path for the leaf index.
|
|
409
|
-
*/ async getNoteHashSiblingPath(blockNumber, leafIndex) {
|
|
410
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1053
|
+
async getNoteHashSiblingPath(block, leafIndex) {
|
|
1054
|
+
const committedDb = await this.#getWorldState(block);
|
|
411
1055
|
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
412
1056
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
1057
|
+
async getArchiveMembershipWitness(block, archive) {
|
|
1058
|
+
const committedDb = await this.#getWorldState(block);
|
|
1059
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
1060
|
+
archive
|
|
1061
|
+
]);
|
|
1062
|
+
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1063
|
+
}
|
|
1064
|
+
async getNoteHashMembershipWitness(block, noteHash) {
|
|
1065
|
+
const committedDb = await this.#getWorldState(block);
|
|
1066
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
1067
|
+
noteHash
|
|
1068
|
+
]);
|
|
1069
|
+
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1070
|
+
}
|
|
1071
|
+
async getL1ToL2MessageMembershipWitness(block, l1ToL2Message) {
|
|
1072
|
+
const db = await this.#getWorldState(block);
|
|
1073
|
+
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
1074
|
+
l1ToL2Message
|
|
1075
|
+
]);
|
|
1076
|
+
if (!witness) {
|
|
421
1077
|
return undefined;
|
|
422
1078
|
}
|
|
423
|
-
|
|
424
|
-
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, index);
|
|
1079
|
+
// REFACTOR: Return a MembershipWitness object
|
|
425
1080
|
return [
|
|
426
|
-
index,
|
|
427
|
-
|
|
1081
|
+
witness.index,
|
|
1082
|
+
witness.path
|
|
428
1083
|
];
|
|
429
1084
|
}
|
|
1085
|
+
async getL1ToL2MessageBlock(l1ToL2Message) {
|
|
1086
|
+
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
1087
|
+
return messageIndex ? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex)) : undefined;
|
|
1088
|
+
}
|
|
430
1089
|
/**
|
|
431
1090
|
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
432
1091
|
* @param l1ToL2Message - The L1 to L2 message to check.
|
|
433
1092
|
* @returns Whether the message is synced and ready to be included in a block.
|
|
434
1093
|
*/ async isL1ToL2MessageSynced(l1ToL2Message) {
|
|
435
|
-
|
|
1094
|
+
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
1095
|
+
return messageIndex !== undefined;
|
|
436
1096
|
}
|
|
437
1097
|
/**
|
|
438
|
-
* Returns the
|
|
439
|
-
* @
|
|
440
|
-
*
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
indexOfMsgInSubtree = Math.max(indexOfMsgInSubtree, idx);
|
|
457
|
-
return idx !== -1;
|
|
458
|
-
});
|
|
459
|
-
if (indexOfMsgTx === -1) {
|
|
460
|
-
throw new Error('The L2ToL1Message you are trying to prove inclusion of does not exist');
|
|
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
|
-
];
|
|
1098
|
+
* Returns all the L2 to L1 messages in an epoch.
|
|
1099
|
+
* @param epoch - The epoch at which to get the data.
|
|
1100
|
+
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
1101
|
+
*/ async getL2ToL1Messages(epoch) {
|
|
1102
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1103
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1104
|
+
const blocksInCheckpoints = [];
|
|
1105
|
+
let previousSlotNumber = SlotNumber.ZERO;
|
|
1106
|
+
let checkpointIndex = -1;
|
|
1107
|
+
for (const checkpointedBlock of checkpointedBlocks){
|
|
1108
|
+
const block = checkpointedBlock.block;
|
|
1109
|
+
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1110
|
+
if (slotNumber !== previousSlotNumber) {
|
|
1111
|
+
checkpointIndex++;
|
|
1112
|
+
blocksInCheckpoints.push([]);
|
|
1113
|
+
previousSlotNumber = slotNumber;
|
|
1114
|
+
}
|
|
1115
|
+
blocksInCheckpoints[checkpointIndex].push(block);
|
|
480
1116
|
}
|
|
481
|
-
|
|
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
|
-
];
|
|
1117
|
+
return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
497
1118
|
}
|
|
498
|
-
|
|
499
|
-
|
|
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);
|
|
1119
|
+
async getArchiveSiblingPath(block, leafIndex) {
|
|
1120
|
+
const committedDb = await this.#getWorldState(block);
|
|
505
1121
|
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
506
1122
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
* @param blockNumber - The block number at which to get the data.
|
|
510
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
511
|
-
* @returns The sibling path.
|
|
512
|
-
*/ async getPublicDataSiblingPath(blockNumber, leafIndex) {
|
|
513
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1123
|
+
async getPublicDataSiblingPath(block, leafIndex) {
|
|
1124
|
+
const committedDb = await this.#getWorldState(block);
|
|
514
1125
|
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
515
1126
|
}
|
|
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, [
|
|
1127
|
+
async getNullifierMembershipWitness(block, nullifier) {
|
|
1128
|
+
const db = await this.#getWorldState(block);
|
|
1129
|
+
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
524
1130
|
nullifier.toBuffer()
|
|
525
|
-
])
|
|
526
|
-
if (!
|
|
1131
|
+
]);
|
|
1132
|
+
if (!witness) {
|
|
527
1133
|
return undefined;
|
|
528
1134
|
}
|
|
529
|
-
const
|
|
530
|
-
const
|
|
531
|
-
const [leafPreimage, siblingPath] = await Promise.all([
|
|
532
|
-
leafPreimagePromise,
|
|
533
|
-
siblingPathPromise
|
|
534
|
-
]);
|
|
1135
|
+
const { index, path } = witness;
|
|
1136
|
+
const leafPreimage = await db.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
535
1137
|
if (!leafPreimage) {
|
|
536
1138
|
return undefined;
|
|
537
1139
|
}
|
|
538
|
-
return new NullifierMembershipWitness(
|
|
1140
|
+
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
539
1141
|
}
|
|
540
1142
|
/**
|
|
541
1143
|
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
542
|
-
* @param
|
|
1144
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
543
1145
|
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
544
1146
|
* @returns The low nullifier membership witness (if found).
|
|
545
1147
|
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
@@ -550,8 +1152,8 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
550
1152
|
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
551
1153
|
* index of the nullifier itself when it already exists in the tree.
|
|
552
1154
|
* TODO: This is a confusing behavior and we should eventually address that.
|
|
553
|
-
*/ async getLowNullifierMembershipWitness(
|
|
554
|
-
const committedDb = await this.#getWorldState(
|
|
1155
|
+
*/ async getLowNullifierMembershipWitness(block, nullifier) {
|
|
1156
|
+
const committedDb = await this.#getWorldState(block);
|
|
555
1157
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
556
1158
|
if (!findResult) {
|
|
557
1159
|
return undefined;
|
|
@@ -564,8 +1166,8 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
564
1166
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
565
1167
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
566
1168
|
}
|
|
567
|
-
async
|
|
568
|
-
const committedDb = await this.#getWorldState(
|
|
1169
|
+
async getPublicDataWitness(block, leafSlot) {
|
|
1170
|
+
const committedDb = await this.#getWorldState(block);
|
|
569
1171
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
570
1172
|
if (!lowLeafResult) {
|
|
571
1173
|
return undefined;
|
|
@@ -575,53 +1177,79 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
575
1177
|
return new PublicDataWitness(lowLeafResult.index, preimage, path);
|
|
576
1178
|
}
|
|
577
1179
|
}
|
|
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);
|
|
1180
|
+
async getPublicStorageAt(block, contract, slot) {
|
|
1181
|
+
const committedDb = await this.#getWorldState(block);
|
|
590
1182
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
591
1183
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
592
1184
|
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
593
1185
|
return Fr.ZERO;
|
|
594
1186
|
}
|
|
595
1187
|
const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
596
|
-
return preimage.value;
|
|
1188
|
+
return preimage.leaf.value;
|
|
1189
|
+
}
|
|
1190
|
+
async getBlockHeader(block = 'latest') {
|
|
1191
|
+
if (L2BlockHash.isL2BlockHash(block)) {
|
|
1192
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1193
|
+
if (block.equals(initialBlockHash)) {
|
|
1194
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1195
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1196
|
+
}
|
|
1197
|
+
const blockHashFr = Fr.fromBuffer(block.toBuffer());
|
|
1198
|
+
return this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
1199
|
+
} else {
|
|
1200
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1201
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
1202
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1203
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1204
|
+
}
|
|
1205
|
+
return this.blockSource.getBlockHeader(block);
|
|
1206
|
+
}
|
|
597
1207
|
}
|
|
598
1208
|
/**
|
|
599
|
-
*
|
|
600
|
-
* @
|
|
601
|
-
|
|
602
|
-
|
|
1209
|
+
* Get a block header specified by its archive root.
|
|
1210
|
+
* @param archive - The archive root being requested.
|
|
1211
|
+
* @returns The requested block header.
|
|
1212
|
+
*/ async getBlockHeaderByArchive(archive) {
|
|
1213
|
+
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
603
1214
|
}
|
|
604
1215
|
/**
|
|
605
1216
|
* Simulates the public part of a transaction with the current state.
|
|
606
1217
|
* @param tx - The transaction to simulate.
|
|
607
1218
|
**/ async simulatePublicCalls(tx, skipFeeEnforcement = false) {
|
|
608
|
-
|
|
609
|
-
const
|
|
1219
|
+
// Check total gas limit for simulation
|
|
1220
|
+
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
1221
|
+
const txGasLimit = gasSettings.gasLimits.l2Gas;
|
|
1222
|
+
const teardownGasLimit = gasSettings.teardownGasLimits.l2Gas;
|
|
1223
|
+
if (txGasLimit + teardownGasLimit > this.config.rpcSimulatePublicMaxGasLimit) {
|
|
1224
|
+
throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
|
|
1225
|
+
}
|
|
1226
|
+
const txHash = tx.getTxHash();
|
|
1227
|
+
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
610
1228
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
611
|
-
const coinbase =
|
|
612
|
-
const feeRecipient =
|
|
613
|
-
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(
|
|
1229
|
+
const coinbase = EthAddress.ZERO;
|
|
1230
|
+
const feeRecipient = AztecAddress.ZERO;
|
|
1231
|
+
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(blockNumber, coinbase, feeRecipient);
|
|
614
1232
|
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry);
|
|
615
|
-
const fork = await this.worldStateSynchronizer.fork();
|
|
616
1233
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
617
1234
|
globalVariables: newGlobalVariables.toInspect(),
|
|
618
1235
|
txHash,
|
|
619
1236
|
blockNumber
|
|
620
1237
|
});
|
|
1238
|
+
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
621
1239
|
try {
|
|
622
|
-
const
|
|
1240
|
+
const config = PublicSimulatorConfig.from({
|
|
1241
|
+
skipFeeEnforcement,
|
|
1242
|
+
collectDebugLogs: true,
|
|
1243
|
+
collectHints: false,
|
|
1244
|
+
collectCallMetadata: true,
|
|
1245
|
+
collectStatistics: false,
|
|
1246
|
+
collectionLimits: CollectionLimitsConfig.from({
|
|
1247
|
+
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads
|
|
1248
|
+
})
|
|
1249
|
+
});
|
|
1250
|
+
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
623
1251
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
624
|
-
const [processedTxs, failedTxs, returns] = await processor.process([
|
|
1252
|
+
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
|
|
625
1253
|
tx
|
|
626
1254
|
]);
|
|
627
1255
|
// REFACTOR: Consider returning the error rather than throwing
|
|
@@ -632,30 +1260,47 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
632
1260
|
throw failedTxs[0].error;
|
|
633
1261
|
}
|
|
634
1262
|
const [processedTx] = processedTxs;
|
|
635
|
-
return new PublicSimulationOutput(processedTx.revertReason, processedTx.
|
|
1263
|
+
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed);
|
|
636
1264
|
} finally{
|
|
637
|
-
await
|
|
1265
|
+
await merkleTreeFork.close();
|
|
638
1266
|
}
|
|
639
1267
|
}
|
|
640
1268
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
641
|
-
const blockNumber = await this.blockSource.getBlockNumber() + 1;
|
|
642
1269
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
643
1270
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
1271
|
+
// We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
|
|
1272
|
+
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1273
|
+
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
644
1274
|
const validator = createValidatorForAcceptingTxs(db, this.contractDataSource, verifier, {
|
|
1275
|
+
timestamp: nextSlotTimestamp,
|
|
645
1276
|
blockNumber,
|
|
646
1277
|
l1ChainId: this.l1ChainId,
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
1278
|
+
rollupVersion: this.version,
|
|
1279
|
+
setupAllowList: this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions(),
|
|
1280
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1281
|
+
skipFeeEnforcement,
|
|
1282
|
+
txsPermitted: !this.config.disableTransactions
|
|
650
1283
|
});
|
|
651
1284
|
return await validator.validateTx(tx);
|
|
652
1285
|
}
|
|
1286
|
+
getConfig() {
|
|
1287
|
+
const schema = AztecNodeAdminConfigSchema;
|
|
1288
|
+
const keys = schema.keyof().options;
|
|
1289
|
+
return Promise.resolve(pick(this.config, ...keys));
|
|
1290
|
+
}
|
|
653
1291
|
async setConfig(config) {
|
|
654
1292
|
const newConfig = {
|
|
655
1293
|
...this.config,
|
|
656
1294
|
...config
|
|
657
1295
|
};
|
|
658
|
-
|
|
1296
|
+
this.sequencer?.updateConfig(config);
|
|
1297
|
+
this.slasherClient?.updateConfig(config);
|
|
1298
|
+
this.validatorsSentinel?.updateConfig(config);
|
|
1299
|
+
await this.p2pClient.updateP2PConfig(config);
|
|
1300
|
+
const archiver = this.blockSource;
|
|
1301
|
+
if ('updateConfig' in archiver) {
|
|
1302
|
+
archiver.updateConfig(config);
|
|
1303
|
+
}
|
|
659
1304
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
660
1305
|
this.proofVerifier = config.realProofs ? await BBCircuitVerifier.new(newConfig) : new TestCircuitVerifier();
|
|
661
1306
|
}
|
|
@@ -663,51 +1308,165 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
663
1308
|
}
|
|
664
1309
|
getProtocolContractAddresses() {
|
|
665
1310
|
return Promise.resolve({
|
|
666
|
-
|
|
1311
|
+
classRegistry: ProtocolContractAddress.ContractClassRegistry,
|
|
667
1312
|
feeJuice: ProtocolContractAddress.FeeJuice,
|
|
668
|
-
|
|
1313
|
+
instanceRegistry: ProtocolContractAddress.ContractInstanceRegistry,
|
|
669
1314
|
multiCallEntrypoint: ProtocolContractAddress.MultiCallEntrypoint
|
|
670
1315
|
});
|
|
671
1316
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
this.log.info(`Adding contract class via API ${contractClass.id}`);
|
|
675
|
-
return this.contractDataSource.addContractClass(contractClass);
|
|
1317
|
+
registerContractFunctionSignatures(signatures) {
|
|
1318
|
+
return this.contractDataSource.registerContractFunctionSignatures(signatures);
|
|
676
1319
|
}
|
|
677
|
-
|
|
678
|
-
return this.
|
|
1320
|
+
getValidatorsStats() {
|
|
1321
|
+
return this.validatorsSentinel?.computeStats() ?? Promise.resolve({
|
|
1322
|
+
stats: {},
|
|
1323
|
+
slotWindow: 0
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
getValidatorStats(validatorAddress, fromSlot, toSlot) {
|
|
1327
|
+
return this.validatorsSentinel?.getValidatorStats(validatorAddress, fromSlot, toSlot) ?? Promise.resolve(undefined);
|
|
679
1328
|
}
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
1329
|
+
async startSnapshotUpload(location) {
|
|
1330
|
+
// Note that we are forcefully casting the blocksource as an archiver
|
|
1331
|
+
// We break support for archiver running remotely to the node
|
|
1332
|
+
const archiver = this.blockSource;
|
|
1333
|
+
if (!('backupTo' in archiver)) {
|
|
1334
|
+
this.metrics.recordSnapshotError();
|
|
1335
|
+
throw new Error('Archiver implementation does not support backups. Cannot generate snapshot.');
|
|
1336
|
+
}
|
|
1337
|
+
// Test that the archiver has done an initial sync.
|
|
1338
|
+
if (!archiver.isInitialSyncComplete()) {
|
|
1339
|
+
this.metrics.recordSnapshotError();
|
|
1340
|
+
throw new Error(`Archiver initial sync not complete. Cannot start snapshot.`);
|
|
683
1341
|
}
|
|
684
|
-
|
|
1342
|
+
// And it has an L2 block hash
|
|
1343
|
+
const l2BlockHash = await archiver.getL2Tips().then((tips)=>tips.proposed.hash);
|
|
1344
|
+
if (!l2BlockHash) {
|
|
1345
|
+
this.metrics.recordSnapshotError();
|
|
1346
|
+
throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
|
|
1347
|
+
}
|
|
1348
|
+
if (this.isUploadingSnapshot) {
|
|
1349
|
+
this.metrics.recordSnapshotError();
|
|
1350
|
+
throw new Error(`Snapshot upload already in progress. Cannot start another one until complete.`);
|
|
1351
|
+
}
|
|
1352
|
+
// Do not wait for the upload to be complete to return to the caller, but flag that an operation is in progress
|
|
1353
|
+
this.isUploadingSnapshot = true;
|
|
1354
|
+
const timer = new Timer();
|
|
1355
|
+
void uploadSnapshot(location, this.blockSource, this.worldStateSynchronizer, this.config, this.log).then(()=>{
|
|
1356
|
+
this.isUploadingSnapshot = false;
|
|
1357
|
+
this.metrics.recordSnapshot(timer.ms());
|
|
1358
|
+
}).catch((err)=>{
|
|
1359
|
+
this.isUploadingSnapshot = false;
|
|
1360
|
+
this.metrics.recordSnapshotError();
|
|
1361
|
+
this.log.error(`Error uploading snapshot: ${err}`);
|
|
1362
|
+
});
|
|
685
1363
|
return Promise.resolve();
|
|
686
1364
|
}
|
|
1365
|
+
async rollbackTo(targetBlock, force) {
|
|
1366
|
+
const archiver = this.blockSource;
|
|
1367
|
+
if (!('rollbackTo' in archiver)) {
|
|
1368
|
+
throw new Error('Archiver implementation does not support rollbacks.');
|
|
1369
|
+
}
|
|
1370
|
+
const finalizedBlock = await archiver.getL2Tips().then((tips)=>tips.finalized.block.number);
|
|
1371
|
+
if (targetBlock < finalizedBlock) {
|
|
1372
|
+
if (force) {
|
|
1373
|
+
this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
|
|
1374
|
+
await this.worldStateSynchronizer.clear();
|
|
1375
|
+
await this.p2pClient.clear();
|
|
1376
|
+
} else {
|
|
1377
|
+
throw new Error(`Cannot rollback to block ${targetBlock} as it is before finalized ${finalizedBlock}`);
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
try {
|
|
1381
|
+
this.log.info(`Pausing archiver and world state sync to start rollback`);
|
|
1382
|
+
await archiver.stop();
|
|
1383
|
+
await this.worldStateSynchronizer.stopSync();
|
|
1384
|
+
const currentBlock = await archiver.getBlockNumber();
|
|
1385
|
+
const blocksToUnwind = currentBlock - targetBlock;
|
|
1386
|
+
this.log.info(`Unwinding ${count(blocksToUnwind, 'block')} from L2 block ${currentBlock} to ${targetBlock}`);
|
|
1387
|
+
await archiver.rollbackTo(targetBlock);
|
|
1388
|
+
this.log.info(`Unwinding complete.`);
|
|
1389
|
+
} catch (err) {
|
|
1390
|
+
this.log.error(`Error during rollback`, err);
|
|
1391
|
+
throw err;
|
|
1392
|
+
} finally{
|
|
1393
|
+
this.log.info(`Resuming world state and archiver sync.`);
|
|
1394
|
+
this.worldStateSynchronizer.resumeSync();
|
|
1395
|
+
archiver.resume();
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
async pauseSync() {
|
|
1399
|
+
this.log.info(`Pausing archiver and world state sync`);
|
|
1400
|
+
await this.blockSource.stop();
|
|
1401
|
+
await this.worldStateSynchronizer.stopSync();
|
|
1402
|
+
}
|
|
1403
|
+
resumeSync() {
|
|
1404
|
+
this.log.info(`Resuming world state and archiver sync.`);
|
|
1405
|
+
this.worldStateSynchronizer.resumeSync();
|
|
1406
|
+
this.blockSource.resume();
|
|
1407
|
+
return Promise.resolve();
|
|
1408
|
+
}
|
|
1409
|
+
getSlashPayloads() {
|
|
1410
|
+
if (!this.slasherClient) {
|
|
1411
|
+
throw new Error(`Slasher client not enabled`);
|
|
1412
|
+
}
|
|
1413
|
+
return this.slasherClient.getSlashPayloads();
|
|
1414
|
+
}
|
|
1415
|
+
getSlashOffenses(round) {
|
|
1416
|
+
if (!this.slasherClient) {
|
|
1417
|
+
throw new Error(`Slasher client not enabled`);
|
|
1418
|
+
}
|
|
1419
|
+
if (round === 'all') {
|
|
1420
|
+
return this.slasherClient.getPendingOffenses();
|
|
1421
|
+
} else {
|
|
1422
|
+
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
#getInitialHeaderHash() {
|
|
1426
|
+
if (!this.initialHeaderHashPromise) {
|
|
1427
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1428
|
+
}
|
|
1429
|
+
return this.initialHeaderHashPromise;
|
|
1430
|
+
}
|
|
687
1431
|
/**
|
|
688
1432
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
689
|
-
* @param
|
|
1433
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
690
1434
|
* @returns An instance of a committed MerkleTreeOperations
|
|
691
|
-
*/ async #getWorldState(
|
|
692
|
-
|
|
693
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
694
|
-
}
|
|
695
|
-
let blockSyncedTo = 0;
|
|
1435
|
+
*/ async #getWorldState(block) {
|
|
1436
|
+
let blockSyncedTo = BlockNumber.ZERO;
|
|
696
1437
|
try {
|
|
697
1438
|
// Attempt to sync the world state if necessary
|
|
698
1439
|
blockSyncedTo = await this.#syncWorldState();
|
|
699
1440
|
} catch (err) {
|
|
700
1441
|
this.log.error(`Error getting world state: ${err}`);
|
|
701
1442
|
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1443
|
+
if (block === 'latest') {
|
|
1444
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
705
1445
|
return this.worldStateSynchronizer.getCommitted();
|
|
706
|
-
}
|
|
1446
|
+
}
|
|
1447
|
+
if (L2BlockHash.isL2BlockHash(block)) {
|
|
1448
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1449
|
+
if (block.equals(initialBlockHash)) {
|
|
1450
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1451
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1452
|
+
}
|
|
1453
|
+
const blockHashFr = Fr.fromBuffer(block.toBuffer());
|
|
1454
|
+
const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
1455
|
+
if (!header) {
|
|
1456
|
+
throw new Error(`Block hash ${block.toString()} not found when querying world state. If the node API has been queried with anchor block hash possibly a reorg has occurred.`);
|
|
1457
|
+
}
|
|
1458
|
+
const blockNumber = header.getBlockNumber();
|
|
1459
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1460
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1461
|
+
}
|
|
1462
|
+
// Block number provided
|
|
1463
|
+
{
|
|
1464
|
+
const blockNumber = block;
|
|
1465
|
+
if (blockNumber > blockSyncedTo) {
|
|
1466
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1467
|
+
}
|
|
707
1468
|
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
708
1469
|
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
709
|
-
} else {
|
|
710
|
-
throw new Error(`Block ${blockNumber} not yet synced`);
|
|
711
1470
|
}
|
|
712
1471
|
}
|
|
713
1472
|
/**
|
|
@@ -715,11 +1474,6 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
715
1474
|
* @returns A promise that fulfils once the world state is synced
|
|
716
1475
|
*/ async #syncWorldState() {
|
|
717
1476
|
const blockSourceHeight = await this.blockSource.getBlockNumber();
|
|
718
|
-
return this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1477
|
+
return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
719
1478
|
}
|
|
720
1479
|
}
|
|
721
|
-
_ts_decorate([
|
|
722
|
-
trackSpan('AztecNodeService.simulatePublicCalls', async (tx)=>({
|
|
723
|
-
[Attributes.TX_HASH]: (await tx.getTxHash()).toString()
|
|
724
|
-
}))
|
|
725
|
-
], AztecNodeService.prototype, "simulatePublicCalls", null);
|