@aztec/aztec-node 0.0.1-commit.5daedc8 → 0.0.1-commit.6201a7b05
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 +21 -0
- package/dest/aztec-node/block_response_helpers.d.ts.map +1 -0
- package/dest/aztec-node/block_response_helpers.js +88 -0
- package/dest/aztec-node/config.d.ts +12 -6
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +18 -4
- package/dest/aztec-node/node_metrics.d.ts +1 -1
- package/dest/aztec-node/node_metrics.d.ts.map +1 -1
- package/dest/aztec-node/node_metrics.js +9 -16
- package/dest/aztec-node/server.d.ts +87 -178
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +1338 -431
- package/dest/sentinel/factory.d.ts +4 -3
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +1 -1
- package/dest/sentinel/sentinel.d.ts +11 -7
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +97 -60
- package/dest/sentinel/store.d.ts +2 -2
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +11 -7
- package/package.json +29 -28
- package/src/aztec-node/block_response_helpers.ts +131 -0
- package/src/aztec-node/config.ts +35 -15
- package/src/aztec-node/node_metrics.ts +6 -17
- package/src/aztec-node/server.ts +1153 -566
- package/src/sentinel/factory.ts +4 -8
- package/src/sentinel/sentinel.ts +119 -65
- package/src/sentinel/store.ts +12 -12
|
@@ -1,50 +1,428 @@
|
|
|
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,
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
375
|
+
import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
|
|
376
|
+
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
377
|
+
import { createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
378
|
+
import { Blob } from '@aztec/blob-lib';
|
|
11
379
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
380
|
+
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
381
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
382
|
+
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
383
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
384
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
385
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
14
386
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
15
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
16
387
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
17
388
|
import { createLogger } from '@aztec/foundation/log';
|
|
389
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
18
390
|
import { count } from '@aztec/foundation/string';
|
|
19
391
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
20
392
|
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
21
393
|
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
22
394
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
23
|
-
import {
|
|
24
|
-
import { createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
395
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
396
|
+
import { createP2PClient, createTxValidatorForAcceptingTxsOverRPC, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
25
397
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
26
|
-
import {
|
|
398
|
+
import { createProverNode } from '@aztec/prover-node';
|
|
399
|
+
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
400
|
+
import { FeeProviderImpl, GlobalVariableBuilder, SequencerClient } from '@aztec/sequencer-client';
|
|
27
401
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
28
402
|
import { AttestationsBlockWatcher, EpochPruneWatcher, createSlasher } from '@aztec/slasher';
|
|
29
|
-
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
403
|
+
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
30
404
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
31
|
-
import {
|
|
405
|
+
import { BlockHash, L2Block, inspectBlockParameter } from '@aztec/stdlib/block';
|
|
32
406
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
33
407
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
34
408
|
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
35
409
|
import { tryStop } from '@aztec/stdlib/interfaces/server';
|
|
410
|
+
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
36
411
|
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
37
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
38
412
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
39
413
|
import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
40
414
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
41
415
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
42
|
-
import { NodeKeystoreAdapter, ValidatorClient,
|
|
416
|
+
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createProposalHandler, createValidatorClient } from '@aztec/validator-client';
|
|
43
417
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
44
|
-
import { createPublicClient
|
|
418
|
+
import { createPublicClient } from 'viem';
|
|
45
419
|
import { createSentinel } from '../sentinel/factory.js';
|
|
420
|
+
import { blockResponseFromBlockData, blockResponseFromL2Block, checkpointResponseFromCheckpointData, checkpointResponseFromPublishedCheckpoint } from './block_response_helpers.js';
|
|
46
421
|
import { createKeyStoreForValidator } from './config.js';
|
|
47
422
|
import { NodeMetrics } from './node_metrics.js';
|
|
423
|
+
_dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
424
|
+
[Attributes.TX_HASH]: tx.getTxHash().toString()
|
|
425
|
+
}));
|
|
48
426
|
/**
|
|
49
427
|
* The aztec node.
|
|
50
428
|
*/ export class AztecNodeService {
|
|
@@ -56,22 +434,40 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
56
434
|
l1ToL2MessageSource;
|
|
57
435
|
worldStateSynchronizer;
|
|
58
436
|
sequencer;
|
|
437
|
+
proverNode;
|
|
59
438
|
slasherClient;
|
|
60
439
|
validatorsSentinel;
|
|
61
440
|
epochPruneWatcher;
|
|
441
|
+
attestationsBlockWatcher;
|
|
62
442
|
l1ChainId;
|
|
63
443
|
version;
|
|
64
444
|
globalVariableBuilder;
|
|
445
|
+
feeProvider;
|
|
65
446
|
epochCache;
|
|
66
447
|
packageVersion;
|
|
67
|
-
|
|
448
|
+
peerProofVerifier;
|
|
449
|
+
rpcProofVerifier;
|
|
68
450
|
telemetry;
|
|
69
451
|
log;
|
|
452
|
+
blobClient;
|
|
453
|
+
validatorClient;
|
|
454
|
+
keyStoreManager;
|
|
455
|
+
debugLogStore;
|
|
456
|
+
static{
|
|
457
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
458
|
+
[
|
|
459
|
+
_dec,
|
|
460
|
+
2,
|
|
461
|
+
"simulatePublicCalls"
|
|
462
|
+
]
|
|
463
|
+
], []));
|
|
464
|
+
}
|
|
70
465
|
metrics;
|
|
466
|
+
initialHeaderHashPromise;
|
|
71
467
|
// Prevent two snapshot operations to happen simultaneously
|
|
72
468
|
isUploadingSnapshot;
|
|
73
469
|
tracer;
|
|
74
|
-
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion,
|
|
470
|
+
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, attestationsBlockWatcher, l1ChainId, version, globalVariableBuilder, feeProvider, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry = getTelemetryClient(), log = createLogger('node'), blobClient, validatorClient, keyStoreManager, debugLogStore = new NullDebugLogStore()){
|
|
75
471
|
this.config = config;
|
|
76
472
|
this.p2pClient = p2pClient;
|
|
77
473
|
this.blockSource = blockSource;
|
|
@@ -80,30 +476,312 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
80
476
|
this.l1ToL2MessageSource = l1ToL2MessageSource;
|
|
81
477
|
this.worldStateSynchronizer = worldStateSynchronizer;
|
|
82
478
|
this.sequencer = sequencer;
|
|
479
|
+
this.proverNode = proverNode;
|
|
83
480
|
this.slasherClient = slasherClient;
|
|
84
481
|
this.validatorsSentinel = validatorsSentinel;
|
|
85
482
|
this.epochPruneWatcher = epochPruneWatcher;
|
|
483
|
+
this.attestationsBlockWatcher = attestationsBlockWatcher;
|
|
86
484
|
this.l1ChainId = l1ChainId;
|
|
87
485
|
this.version = version;
|
|
88
486
|
this.globalVariableBuilder = globalVariableBuilder;
|
|
487
|
+
this.feeProvider = feeProvider;
|
|
89
488
|
this.epochCache = epochCache;
|
|
90
489
|
this.packageVersion = packageVersion;
|
|
91
|
-
this.
|
|
490
|
+
this.peerProofVerifier = peerProofVerifier;
|
|
491
|
+
this.rpcProofVerifier = rpcProofVerifier;
|
|
92
492
|
this.telemetry = telemetry;
|
|
93
493
|
this.log = log;
|
|
494
|
+
this.blobClient = blobClient;
|
|
495
|
+
this.validatorClient = validatorClient;
|
|
496
|
+
this.keyStoreManager = keyStoreManager;
|
|
497
|
+
this.debugLogStore = debugLogStore;
|
|
498
|
+
this.initialHeaderHashPromise = (_initProto(this), undefined);
|
|
94
499
|
this.isUploadingSnapshot = false;
|
|
95
500
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
96
501
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
97
502
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
98
503
|
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
|
|
504
|
+
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
505
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
506
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
507
|
+
if (debugLogStore.isEnabled && config.realProofs) {
|
|
508
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */ getProofVerifier() {
|
|
512
|
+
return this.rpcProofVerifier;
|
|
99
513
|
}
|
|
100
514
|
async getWorldStateSyncStatus() {
|
|
101
515
|
const status = await this.worldStateSynchronizer.status();
|
|
102
516
|
return status.syncSummary;
|
|
103
517
|
}
|
|
518
|
+
async getChainTips() {
|
|
519
|
+
const { proposed, checkpointed, proven, finalized } = await this.blockSource.getL2Tips();
|
|
520
|
+
return {
|
|
521
|
+
proposed,
|
|
522
|
+
checkpointed,
|
|
523
|
+
proven,
|
|
524
|
+
finalized
|
|
525
|
+
};
|
|
526
|
+
}
|
|
104
527
|
getL2Tips() {
|
|
105
528
|
return this.blockSource.getL2Tips();
|
|
106
529
|
}
|
|
530
|
+
async getBlockHeader(number) {
|
|
531
|
+
const resolvedNumber = number === 'latest' ? await this.blockSource.getBlockNumber() : number;
|
|
532
|
+
if (resolvedNumber === BlockNumber.ZERO) {
|
|
533
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
534
|
+
}
|
|
535
|
+
return this.blockSource.getBlockHeader(resolvedNumber);
|
|
536
|
+
}
|
|
537
|
+
async getCheckpointedBlocks(from, limit) {
|
|
538
|
+
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
539
|
+
}
|
|
540
|
+
getCheckpointsDataForEpoch(epoch) {
|
|
541
|
+
return this.blockSource.getCheckpointsDataForEpoch(epoch);
|
|
542
|
+
}
|
|
543
|
+
getBlockNumber(tip) {
|
|
544
|
+
switch(tip){
|
|
545
|
+
case undefined:
|
|
546
|
+
case 'proposed':
|
|
547
|
+
return this.blockSource.getBlockNumber();
|
|
548
|
+
case 'checkpointed':
|
|
549
|
+
return this.blockSource.getCheckpointedL2BlockNumber();
|
|
550
|
+
case 'proven':
|
|
551
|
+
return this.blockSource.getProvenBlockNumber();
|
|
552
|
+
case 'finalized':
|
|
553
|
+
return this.blockSource.getFinalizedL2BlockNumber();
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
async getCheckpointNumber(tip) {
|
|
557
|
+
switch(tip){
|
|
558
|
+
case undefined:
|
|
559
|
+
case 'proposed':
|
|
560
|
+
case 'checkpointed':
|
|
561
|
+
return await this.blockSource.getCheckpointNumber();
|
|
562
|
+
case 'proven':
|
|
563
|
+
case 'finalized':
|
|
564
|
+
{
|
|
565
|
+
const tips = await this.blockSource.getL2Tips();
|
|
566
|
+
return tip === 'proven' ? tips.proven.checkpoint.number : tips.finalized.checkpoint.number;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
isChainTip(value) {
|
|
571
|
+
return value === 'proposed' || value === 'checkpointed' || value === 'proven' || value === 'finalized';
|
|
572
|
+
}
|
|
573
|
+
async resolveBlockParameter(param) {
|
|
574
|
+
if (BlockHash.isBlockHash(param)) {
|
|
575
|
+
return {
|
|
576
|
+
hash: param
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
if (typeof param === 'number') {
|
|
580
|
+
return {
|
|
581
|
+
number: param
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
if (param === 'latest') {
|
|
585
|
+
return {
|
|
586
|
+
number: await this.blockSource.getBlockNumber()
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
if (this.isChainTip(param)) {
|
|
590
|
+
return {
|
|
591
|
+
number: await this.getBlockNumber(param)
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
if (typeof param === 'object' && param !== null) {
|
|
595
|
+
if ('number' in param) {
|
|
596
|
+
return {
|
|
597
|
+
number: param.number
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
if ('hash' in param) {
|
|
601
|
+
return {
|
|
602
|
+
hash: param.hash
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
if ('archive' in param) {
|
|
606
|
+
return {
|
|
607
|
+
archive: param.archive
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
throw new BadRequestError(`Invalid BlockParameter: ${JSON.stringify(param)}`);
|
|
612
|
+
}
|
|
613
|
+
async resolveCheckpointParameter(param) {
|
|
614
|
+
if (typeof param === 'number') {
|
|
615
|
+
return {
|
|
616
|
+
number: param
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
if (param === 'latest') {
|
|
620
|
+
return {
|
|
621
|
+
number: await this.blockSource.getCheckpointNumber()
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
if (this.isChainTip(param)) {
|
|
625
|
+
return {
|
|
626
|
+
number: await this.getCheckpointNumber(param)
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
if (typeof param === 'object' && param !== null) {
|
|
630
|
+
if ('number' in param) {
|
|
631
|
+
return {
|
|
632
|
+
number: param.number
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
if ('slot' in param) {
|
|
636
|
+
return {
|
|
637
|
+
slot: param.slot
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
throw new BadRequestError(`Invalid CheckpointParameter: ${JSON.stringify(param)}`);
|
|
642
|
+
}
|
|
643
|
+
async getBlock(param, options = {}) {
|
|
644
|
+
const resolved = await this.resolveBlockParameter(param);
|
|
645
|
+
const wantTxs = !!options.includeTransactions;
|
|
646
|
+
const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
|
|
647
|
+
if (resolved.hash !== undefined) {
|
|
648
|
+
const initial = await this.#getInitialHeaderHash();
|
|
649
|
+
if (resolved.hash.equals(initial)) {
|
|
650
|
+
return await this.buildGenesisBlockResponse(options);
|
|
651
|
+
}
|
|
652
|
+
if (wantTxs) {
|
|
653
|
+
const block = await this.blockSource.getL2BlockByHash(resolved.hash);
|
|
654
|
+
if (!block) {
|
|
655
|
+
return undefined;
|
|
656
|
+
}
|
|
657
|
+
const ctx = wantContext ? await this.blockSource.getBlockDataWithCheckpointContext(block.number) : undefined;
|
|
658
|
+
return await blockResponseFromL2Block(block, options, ctx);
|
|
659
|
+
}
|
|
660
|
+
const data = await this.blockSource.getBlockHeaderByHash(resolved.hash);
|
|
661
|
+
if (!data) {
|
|
662
|
+
return undefined;
|
|
663
|
+
}
|
|
664
|
+
const blockNumber = data.globalVariables.blockNumber;
|
|
665
|
+
const ctx = wantContext ? await this.blockSource.getBlockDataWithCheckpointContext(blockNumber) : undefined;
|
|
666
|
+
if (ctx) {
|
|
667
|
+
return blockResponseFromBlockData(ctx.data, blockNumber, options, ctx);
|
|
668
|
+
}
|
|
669
|
+
const blockData = await this.blockSource.getBlockData(blockNumber);
|
|
670
|
+
if (!blockData) {
|
|
671
|
+
return undefined;
|
|
672
|
+
}
|
|
673
|
+
return blockResponseFromBlockData(blockData, blockNumber, options);
|
|
674
|
+
}
|
|
675
|
+
if (resolved.archive !== undefined) {
|
|
676
|
+
if (wantTxs) {
|
|
677
|
+
const block = await this.blockSource.getL2BlockByArchive(resolved.archive);
|
|
678
|
+
if (!block) {
|
|
679
|
+
return undefined;
|
|
680
|
+
}
|
|
681
|
+
const ctx = wantContext ? await this.blockSource.getBlockDataWithCheckpointContext(block.number) : undefined;
|
|
682
|
+
return await blockResponseFromL2Block(block, options, ctx);
|
|
683
|
+
}
|
|
684
|
+
const data = await this.blockSource.getBlockDataByArchive(resolved.archive);
|
|
685
|
+
if (!data) {
|
|
686
|
+
return undefined;
|
|
687
|
+
}
|
|
688
|
+
const blockNumber = data.header.globalVariables.blockNumber;
|
|
689
|
+
const ctx = wantContext ? await this.blockSource.getBlockDataWithCheckpointContext(blockNumber) : undefined;
|
|
690
|
+
return blockResponseFromBlockData(data, blockNumber, options, ctx);
|
|
691
|
+
}
|
|
692
|
+
const blockNumber = resolved.number;
|
|
693
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
694
|
+
return await this.buildGenesisBlockResponse(options);
|
|
695
|
+
}
|
|
696
|
+
if (wantTxs) {
|
|
697
|
+
const block = await this.blockSource.getL2Block(blockNumber);
|
|
698
|
+
if (!block) {
|
|
699
|
+
return undefined;
|
|
700
|
+
}
|
|
701
|
+
const ctx = wantContext ? await this.blockSource.getBlockDataWithCheckpointContext(blockNumber) : undefined;
|
|
702
|
+
return await blockResponseFromL2Block(block, options, ctx);
|
|
703
|
+
}
|
|
704
|
+
const ctx = await this.blockSource.getBlockDataWithCheckpointContext(blockNumber);
|
|
705
|
+
if (!ctx) {
|
|
706
|
+
return undefined;
|
|
707
|
+
}
|
|
708
|
+
return blockResponseFromBlockData(ctx.data, blockNumber, options, ctx);
|
|
709
|
+
}
|
|
710
|
+
async getBlocks(from, limit, options = {}) {
|
|
711
|
+
const wantTxs = !!options.includeTransactions;
|
|
712
|
+
const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
|
|
713
|
+
if (wantTxs) {
|
|
714
|
+
const blocks = await this.blockSource.getBlocks(from, limit);
|
|
715
|
+
return await Promise.all(blocks.map(async (block)=>{
|
|
716
|
+
const ctx = wantContext ? await this.blockSource.getBlockDataWithCheckpointContext(block.number) : undefined;
|
|
717
|
+
return blockResponseFromL2Block(block, options, ctx);
|
|
718
|
+
}));
|
|
719
|
+
}
|
|
720
|
+
const results = [];
|
|
721
|
+
for(let i = 0; i < limit; i++){
|
|
722
|
+
const blockNumber = BlockNumber(from + i);
|
|
723
|
+
const ctx = await this.blockSource.getBlockDataWithCheckpointContext(blockNumber);
|
|
724
|
+
if (!ctx) {
|
|
725
|
+
break;
|
|
726
|
+
}
|
|
727
|
+
results.push(blockResponseFromBlockData(ctx.data, blockNumber, options, ctx));
|
|
728
|
+
}
|
|
729
|
+
return results;
|
|
730
|
+
}
|
|
731
|
+
async getCheckpoint(param, options = {}) {
|
|
732
|
+
const resolved = await this.resolveCheckpointParameter(param);
|
|
733
|
+
let checkpointNumber = resolved.number;
|
|
734
|
+
if (checkpointNumber === undefined && resolved.slot !== undefined) {
|
|
735
|
+
checkpointNumber = await this.blockSource.getCheckpointNumberBySlot(resolved.slot);
|
|
736
|
+
}
|
|
737
|
+
if (checkpointNumber === undefined) {
|
|
738
|
+
return undefined;
|
|
739
|
+
}
|
|
740
|
+
if (options.includeBlocks) {
|
|
741
|
+
const [checkpoint] = await this.blockSource.getCheckpoints(checkpointNumber, 1);
|
|
742
|
+
if (!checkpoint) {
|
|
743
|
+
return undefined;
|
|
744
|
+
}
|
|
745
|
+
return await checkpointResponseFromPublishedCheckpoint(checkpoint, options);
|
|
746
|
+
}
|
|
747
|
+
const data = await this.blockSource.getCheckpointData(checkpointNumber);
|
|
748
|
+
if (!data) {
|
|
749
|
+
return undefined;
|
|
750
|
+
}
|
|
751
|
+
return checkpointResponseFromCheckpointData(data, options);
|
|
752
|
+
}
|
|
753
|
+
async getCheckpoints(from, limit, options = {}) {
|
|
754
|
+
if (options.includeBlocks) {
|
|
755
|
+
const checkpoints = await this.blockSource.getCheckpoints(from, limit);
|
|
756
|
+
return await Promise.all(checkpoints.map((cp)=>checkpointResponseFromPublishedCheckpoint(cp, options)));
|
|
757
|
+
}
|
|
758
|
+
const datas = await this.blockSource.getCheckpointDataRange(from, limit);
|
|
759
|
+
return datas.map((d)=>checkpointResponseFromCheckpointData(d, options));
|
|
760
|
+
}
|
|
761
|
+
async buildGenesisBlockResponse(options) {
|
|
762
|
+
const initial = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
763
|
+
const empty = L2Block.empty(initial);
|
|
764
|
+
const response = {
|
|
765
|
+
header: empty.header,
|
|
766
|
+
archive: empty.archive,
|
|
767
|
+
hash: await this.#getInitialHeaderHash(),
|
|
768
|
+
checkpointNumber: empty.checkpointNumber,
|
|
769
|
+
indexWithinCheckpoint: empty.indexWithinCheckpoint,
|
|
770
|
+
number: empty.number
|
|
771
|
+
};
|
|
772
|
+
if (options.includeTransactions) {
|
|
773
|
+
response.body = empty.body;
|
|
774
|
+
}
|
|
775
|
+
if (options.includeL1PublishInfo) {
|
|
776
|
+
response.l1 = {
|
|
777
|
+
published: false
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
if (options.includeAttestations) {
|
|
781
|
+
response.attestations = [];
|
|
782
|
+
}
|
|
783
|
+
return response;
|
|
784
|
+
}
|
|
107
785
|
/**
|
|
108
786
|
* initializes the Aztec Node, wait for component to sync.
|
|
109
787
|
* @param config - The configuration to be used by the aztec node.
|
|
@@ -116,20 +794,28 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
116
794
|
const packageVersion = getPackageVersion() ?? '';
|
|
117
795
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
118
796
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
119
|
-
const blobSinkClient = deps.blobSinkClient ?? createBlobSinkClient(config, {
|
|
120
|
-
logger: createLogger('node:blob-sink:client')
|
|
121
|
-
});
|
|
122
797
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
123
|
-
// Build a key store from file if given or from environment otherwise
|
|
798
|
+
// Build a key store from file if given or from environment otherwise.
|
|
799
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
124
800
|
let keyStoreManager;
|
|
125
801
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
126
802
|
if (keyStoreProvided) {
|
|
127
803
|
const keyStores = loadKeystores(config.keyStoreDirectory);
|
|
128
804
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
129
805
|
} else {
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
806
|
+
const rawKeyStores = [];
|
|
807
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
808
|
+
if (validatorKeyStore) {
|
|
809
|
+
rawKeyStores.push(validatorKeyStore);
|
|
810
|
+
}
|
|
811
|
+
if (config.enableProverNode) {
|
|
812
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
813
|
+
if (proverKeyStore) {
|
|
814
|
+
rawKeyStores.push(proverKeyStore);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
if (rawKeyStores.length > 0) {
|
|
818
|
+
keyStoreManager = new KeystoreManager(rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores));
|
|
133
819
|
}
|
|
134
820
|
}
|
|
135
821
|
await keyStoreManager?.validateSigners();
|
|
@@ -138,8 +824,8 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
138
824
|
if (keyStoreManager === undefined) {
|
|
139
825
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
140
826
|
}
|
|
141
|
-
if (!keyStoreProvided) {
|
|
142
|
-
log.warn(
|
|
827
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
828
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
143
829
|
}
|
|
144
830
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
145
831
|
}
|
|
@@ -149,7 +835,9 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
149
835
|
}
|
|
150
836
|
const publicClient = createPublicClient({
|
|
151
837
|
chain: ethereumChain.chainInfo,
|
|
152
|
-
transport:
|
|
838
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, {
|
|
839
|
+
timeout: config.l1HttpTimeoutMS
|
|
840
|
+
}),
|
|
153
841
|
pollingInterval: config.viemPollingIntervalMS
|
|
154
842
|
});
|
|
155
843
|
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.l1Contracts.registryAddress, config.rollupVersion ?? 'canonical');
|
|
@@ -159,149 +847,277 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
159
847
|
...l1ContractsAddresses
|
|
160
848
|
};
|
|
161
849
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
162
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
850
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
163
851
|
rollupContract.getL1GenesisTime(),
|
|
164
852
|
rollupContract.getSlotDuration(),
|
|
165
|
-
rollupContract.getVersion()
|
|
853
|
+
rollupContract.getVersion(),
|
|
854
|
+
rollupContract.getManaLimit().then(Number)
|
|
166
855
|
]);
|
|
167
856
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
168
857
|
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
169
858
|
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}).`);
|
|
170
859
|
}
|
|
860
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
171
861
|
// attempt snapshot sync if possible
|
|
172
862
|
await trySnapshotSync(config, log);
|
|
173
863
|
const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, {
|
|
174
864
|
dateProvider
|
|
175
865
|
});
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}, {
|
|
182
|
-
blockUntilSync: !config.skipArchiverInitialSync
|
|
183
|
-
});
|
|
184
|
-
// now create the merkle trees and the world state synchronizer
|
|
185
|
-
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.prefilledPublicData, telemetry);
|
|
186
|
-
const circuitVerifier = config.realProofs ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
187
|
-
if (!config.realProofs) {
|
|
188
|
-
log.warn(`Aztec node is accepting fake proofs`);
|
|
189
|
-
}
|
|
190
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
191
|
-
// create the tx pool and the p2p client, which will need the l2 block source
|
|
192
|
-
const p2pClient = await createP2PClient(P2PClientType.Full, config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
193
|
-
// We should really not be modifying the config object
|
|
194
|
-
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
|
|
195
|
-
const blockBuilder = new BlockBuilder({
|
|
196
|
-
...config,
|
|
197
|
-
l1GenesisTime,
|
|
198
|
-
slotDuration: Number(slotDuration)
|
|
199
|
-
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
200
|
-
// We'll accumulate sentinel watchers here
|
|
201
|
-
const watchers = [];
|
|
202
|
-
// Create validator client if required
|
|
203
|
-
const validatorClient = createValidatorClient(config, {
|
|
204
|
-
p2pClient,
|
|
205
|
-
telemetry,
|
|
206
|
-
dateProvider,
|
|
207
|
-
epochCache,
|
|
208
|
-
blockBuilder,
|
|
209
|
-
blockSource: archiver,
|
|
210
|
-
l1ToL2MessageSource: archiver,
|
|
211
|
-
keyStoreManager
|
|
212
|
-
});
|
|
213
|
-
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
214
|
-
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
215
|
-
// like attestations or auths will fail.
|
|
216
|
-
if (validatorClient) {
|
|
217
|
-
watchers.push(validatorClient);
|
|
218
|
-
if (!options.dontStartSequencer) {
|
|
219
|
-
await validatorClient.registerHandlers();
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
// If there's no validator client but alwaysReexecuteBlockProposals is enabled,
|
|
223
|
-
// create a BlockProposalHandler to reexecute block proposals for monitoring
|
|
224
|
-
if (!validatorClient && config.alwaysReexecuteBlockProposals) {
|
|
225
|
-
log.info('Setting up block proposal reexecution for monitoring');
|
|
226
|
-
createBlockProposalHandler(config, {
|
|
227
|
-
blockBuilder,
|
|
866
|
+
// Track started resources so we can clean up on partial failure during node creation.
|
|
867
|
+
const started = [];
|
|
868
|
+
try {
|
|
869
|
+
const archiver = await createArchiver(config, {
|
|
870
|
+
blobClient,
|
|
228
871
|
epochCache,
|
|
229
|
-
blockSource: archiver,
|
|
230
|
-
l1ToL2MessageSource: archiver,
|
|
231
|
-
p2pClient,
|
|
232
|
-
dateProvider,
|
|
233
|
-
telemetry
|
|
234
|
-
}).registerForReexecution(p2pClient);
|
|
235
|
-
}
|
|
236
|
-
// Start world state and wait for it to sync to the archiver.
|
|
237
|
-
await worldStateSynchronizer.start();
|
|
238
|
-
// Start p2p. Note that it depends on world state to be running.
|
|
239
|
-
await p2pClient.start();
|
|
240
|
-
const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
241
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
242
|
-
watchers.push(validatorsSentinel);
|
|
243
|
-
}
|
|
244
|
-
let epochPruneWatcher;
|
|
245
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
246
|
-
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), blockBuilder, config);
|
|
247
|
-
watchers.push(epochPruneWatcher);
|
|
248
|
-
}
|
|
249
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
250
|
-
let attestationsBlockWatcher;
|
|
251
|
-
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
252
|
-
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
253
|
-
watchers.push(attestationsBlockWatcher);
|
|
254
|
-
}
|
|
255
|
-
// Start p2p-related services once the archiver has completed sync
|
|
256
|
-
void archiver.waitForInitialSync().then(async ()=>{
|
|
257
|
-
await p2pClient.start();
|
|
258
|
-
await validatorsSentinel?.start();
|
|
259
|
-
await epochPruneWatcher?.start();
|
|
260
|
-
await attestationsBlockWatcher?.start();
|
|
261
|
-
log.info(`All p2p services started`);
|
|
262
|
-
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
263
|
-
// Validator enabled, create/start relevant service
|
|
264
|
-
let sequencer;
|
|
265
|
-
let slasherClient;
|
|
266
|
-
if (!config.disableValidator) {
|
|
267
|
-
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
268
|
-
// as they are executed when the node is selected as proposer.
|
|
269
|
-
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
270
|
-
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
271
|
-
await slasherClient.start();
|
|
272
|
-
const l1TxUtils = await createL1TxUtilsWithBlobsFromEthSigner(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
273
|
-
...config,
|
|
274
|
-
scope: 'sequencer'
|
|
275
|
-
}, {
|
|
276
872
|
telemetry,
|
|
277
|
-
logger: log.createChild('l1-tx-utils'),
|
|
278
873
|
dateProvider
|
|
874
|
+
}, {
|
|
875
|
+
blockUntilSync: !config.skipArchiverInitialSync
|
|
279
876
|
});
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
877
|
+
started.push(archiver);
|
|
878
|
+
// now create the merkle trees and the world state synchronizer
|
|
879
|
+
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.genesis, telemetry);
|
|
880
|
+
started.push(worldStateSynchronizer);
|
|
881
|
+
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
882
|
+
let peerProofVerifier;
|
|
883
|
+
let rpcProofVerifier;
|
|
884
|
+
if (useRealVerifiers) {
|
|
885
|
+
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
886
|
+
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
887
|
+
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
888
|
+
} else {
|
|
889
|
+
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
890
|
+
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
891
|
+
}
|
|
892
|
+
started.push(peerProofVerifier, rpcProofVerifier);
|
|
893
|
+
let debugLogStore;
|
|
894
|
+
if (!config.realProofs) {
|
|
895
|
+
log.warn(`Aztec node is accepting fake proofs`);
|
|
896
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
897
|
+
log.info('Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served');
|
|
898
|
+
} else {
|
|
899
|
+
debugLogStore = new NullDebugLogStore();
|
|
900
|
+
}
|
|
901
|
+
const globalVariableBuilderConfig = {
|
|
902
|
+
l1Contracts: config.l1Contracts,
|
|
903
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
904
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
905
|
+
l1GenesisTime,
|
|
906
|
+
slotDuration: Number(slotDuration)
|
|
907
|
+
};
|
|
908
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
909
|
+
const feeProvider = new FeeProviderImpl(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
910
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
911
|
+
if (proverOnly) {
|
|
912
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
913
|
+
}
|
|
914
|
+
// create the tx pool and the p2p client, which will need the l2 block source
|
|
915
|
+
const p2pClient = await createP2PClient(config, archiver, peerProofVerifier, worldStateSynchronizer, epochCache, feeProvider, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
916
|
+
started.push(p2pClient);
|
|
917
|
+
// We'll accumulate sentinel watchers here
|
|
918
|
+
const watchers = [];
|
|
919
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
920
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
921
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
922
|
+
...config,
|
|
923
|
+
l1GenesisTime,
|
|
924
|
+
slotDuration: Number(slotDuration),
|
|
925
|
+
rollupManaLimit,
|
|
926
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
|
|
927
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
928
|
+
let validatorClient;
|
|
929
|
+
if (!config.disableValidator) {
|
|
930
|
+
// Create validator client if required
|
|
931
|
+
validatorClient = await createValidatorClient(config, {
|
|
932
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
933
|
+
worldState: worldStateSynchronizer,
|
|
934
|
+
p2pClient,
|
|
935
|
+
telemetry,
|
|
936
|
+
dateProvider,
|
|
937
|
+
epochCache,
|
|
938
|
+
blockSource: archiver,
|
|
939
|
+
l1ToL2MessageSource: archiver,
|
|
940
|
+
keyStoreManager,
|
|
941
|
+
blobClient,
|
|
942
|
+
slashingProtectionDb: deps.slashingProtectionDb
|
|
943
|
+
});
|
|
944
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
945
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
946
|
+
// like attestations or auths will fail.
|
|
947
|
+
if (validatorClient) {
|
|
948
|
+
watchers.push(validatorClient);
|
|
949
|
+
const vc = validatorClient;
|
|
950
|
+
const getValidatorAddresses = ()=>vc.getValidatorAddresses().map((a)=>a.toString());
|
|
951
|
+
validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
|
|
952
|
+
if (!options.dontStartSequencer) {
|
|
953
|
+
await validatorClient.registerHandlers();
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
958
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
959
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
960
|
+
// Checkpoint proposals rebuild blobs if the blob client can upload blobs.
|
|
961
|
+
if (!validatorClient) {
|
|
962
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
963
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
964
|
+
createProposalHandler(config, {
|
|
965
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
966
|
+
worldState: worldStateSynchronizer,
|
|
967
|
+
epochCache,
|
|
968
|
+
blockSource: archiver,
|
|
969
|
+
l1ToL2MessageSource: archiver,
|
|
970
|
+
p2pClient,
|
|
971
|
+
blobClient,
|
|
972
|
+
dateProvider,
|
|
973
|
+
telemetry
|
|
974
|
+
}).register(p2pClient, reexecute, archiver);
|
|
975
|
+
}
|
|
976
|
+
// Start world state and wait for it to sync to the archiver.
|
|
977
|
+
await worldStateSynchronizer.start();
|
|
978
|
+
// Start p2p. Note that it depends on world state to be running.
|
|
979
|
+
await p2pClient.start();
|
|
980
|
+
let validatorsSentinel;
|
|
981
|
+
let epochPruneWatcher;
|
|
982
|
+
let attestationsBlockWatcher;
|
|
983
|
+
if (!proverOnly) {
|
|
984
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
985
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
986
|
+
watchers.push(validatorsSentinel);
|
|
987
|
+
}
|
|
988
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
989
|
+
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
|
|
990
|
+
watchers.push(epochPruneWatcher);
|
|
991
|
+
}
|
|
992
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
993
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
994
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
995
|
+
watchers.push(attestationsBlockWatcher);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
// Start p2p-related services once the archiver has completed sync
|
|
999
|
+
void archiver.waitForInitialSync().then(async ()=>{
|
|
1000
|
+
if (validatorsSentinel) {
|
|
1001
|
+
await validatorsSentinel.start();
|
|
1002
|
+
started.push(validatorsSentinel);
|
|
1003
|
+
}
|
|
1004
|
+
if (epochPruneWatcher) {
|
|
1005
|
+
await epochPruneWatcher.start();
|
|
1006
|
+
started.push(epochPruneWatcher);
|
|
1007
|
+
}
|
|
1008
|
+
if (attestationsBlockWatcher) {
|
|
1009
|
+
await attestationsBlockWatcher.start();
|
|
1010
|
+
started.push(attestationsBlockWatcher);
|
|
1011
|
+
}
|
|
1012
|
+
log.info(`All p2p services started`);
|
|
1013
|
+
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
1014
|
+
// Validator enabled, create/start relevant service
|
|
1015
|
+
let sequencer;
|
|
1016
|
+
let slasherClient;
|
|
1017
|
+
if (!config.disableValidator && validatorClient) {
|
|
1018
|
+
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
1019
|
+
// as they are executed when the node is selected as proposer.
|
|
1020
|
+
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
1021
|
+
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
1022
|
+
await slasherClient.start();
|
|
1023
|
+
started.push(slasherClient);
|
|
1024
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
|
|
1025
|
+
...config,
|
|
1026
|
+
scope: 'sequencer'
|
|
1027
|
+
}, {
|
|
1028
|
+
telemetry,
|
|
1029
|
+
logger: log.createChild('l1-tx-utils'),
|
|
1030
|
+
dateProvider,
|
|
1031
|
+
kzg: Blob.getViemKzgInstance()
|
|
1032
|
+
}) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
1033
|
+
...config,
|
|
1034
|
+
scope: 'sequencer'
|
|
1035
|
+
}, {
|
|
1036
|
+
telemetry,
|
|
1037
|
+
logger: log.createChild('l1-tx-utils'),
|
|
1038
|
+
dateProvider,
|
|
1039
|
+
kzg: Blob.getViemKzgInstance()
|
|
1040
|
+
});
|
|
1041
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
1042
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
1043
|
+
let funderL1TxUtils;
|
|
1044
|
+
if (fundingSigner) {
|
|
1045
|
+
const [funder] = await createL1TxUtilsFromSigners(publicClient, [
|
|
1046
|
+
fundingSigner
|
|
1047
|
+
], {
|
|
1048
|
+
...config,
|
|
1049
|
+
scope: 'sequencer'
|
|
1050
|
+
}, {
|
|
1051
|
+
telemetry,
|
|
1052
|
+
logger: log.createChild('l1-tx-utils:funder'),
|
|
1053
|
+
dateProvider
|
|
1054
|
+
});
|
|
1055
|
+
funderL1TxUtils = funder;
|
|
1056
|
+
}
|
|
1057
|
+
// Create and start the sequencer client
|
|
1058
|
+
const checkpointsBuilder = new CheckpointsBuilder({
|
|
1059
|
+
...config,
|
|
1060
|
+
l1GenesisTime,
|
|
1061
|
+
slotDuration: Number(slotDuration),
|
|
1062
|
+
rollupManaLimit
|
|
1063
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry, debugLogStore);
|
|
1064
|
+
sequencer = await SequencerClient.new(config, {
|
|
1065
|
+
...deps,
|
|
1066
|
+
epochCache,
|
|
1067
|
+
l1TxUtils,
|
|
1068
|
+
funderL1TxUtils,
|
|
1069
|
+
validatorClient,
|
|
1070
|
+
p2pClient,
|
|
1071
|
+
worldStateSynchronizer,
|
|
1072
|
+
slasherClient,
|
|
1073
|
+
checkpointsBuilder,
|
|
1074
|
+
l2BlockSource: archiver,
|
|
1075
|
+
l1ToL2MessageSource: archiver,
|
|
1076
|
+
telemetry,
|
|
1077
|
+
dateProvider,
|
|
1078
|
+
blobClient,
|
|
1079
|
+
nodeKeyStore: keyStoreManager,
|
|
1080
|
+
globalVariableBuilder
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
if (!options.dontStartSequencer && sequencer) {
|
|
1084
|
+
await sequencer.start();
|
|
1085
|
+
started.push(sequencer);
|
|
1086
|
+
log.verbose(`Sequencer started`);
|
|
1087
|
+
} else if (sequencer) {
|
|
1088
|
+
log.warn(`Sequencer created but not started`);
|
|
1089
|
+
}
|
|
1090
|
+
// Create prover node subsystem if enabled
|
|
1091
|
+
let proverNode;
|
|
1092
|
+
if (config.enableProverNode) {
|
|
1093
|
+
proverNode = await createProverNode(config, {
|
|
1094
|
+
...deps.proverNodeDeps,
|
|
1095
|
+
telemetry,
|
|
1096
|
+
dateProvider,
|
|
1097
|
+
archiver,
|
|
1098
|
+
worldStateSynchronizer,
|
|
1099
|
+
p2pClient,
|
|
1100
|
+
epochCache,
|
|
1101
|
+
blobClient,
|
|
1102
|
+
keyStoreManager
|
|
1103
|
+
});
|
|
1104
|
+
if (!options.dontStartProverNode) {
|
|
1105
|
+
await proverNode.start();
|
|
1106
|
+
started.push(proverNode);
|
|
1107
|
+
log.info(`Prover node subsystem started`);
|
|
1108
|
+
} else {
|
|
1109
|
+
log.info(`Prover node subsystem created but not started`);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
const node = new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, attestationsBlockWatcher, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, feeProvider, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry, log, blobClient, validatorClient, keyStoreManager, debugLogStore);
|
|
1113
|
+
return node;
|
|
1114
|
+
} catch (err) {
|
|
1115
|
+
log.error('Failed during node creation, stopping started resources', err);
|
|
1116
|
+
for (const resource of started.reverse()){
|
|
1117
|
+
await tryStop(resource);
|
|
1118
|
+
}
|
|
1119
|
+
throw err;
|
|
303
1120
|
}
|
|
304
|
-
return new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, ethereumChain.chainInfo.id, config.rollupVersion, new GlobalVariableBuilder(config), epochCache, packageVersion, proofVerifier, telemetry, log);
|
|
305
1121
|
}
|
|
306
1122
|
/**
|
|
307
1123
|
* Returns the sequencer client instance.
|
|
@@ -309,6 +1125,9 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
309
1125
|
*/ getSequencer() {
|
|
310
1126
|
return this.sequencer;
|
|
311
1127
|
}
|
|
1128
|
+
/** Returns the prover node subsystem, if enabled. */ getProverNode() {
|
|
1129
|
+
return this.proverNode;
|
|
1130
|
+
}
|
|
312
1131
|
getBlockSource() {
|
|
313
1132
|
return this.blockSource;
|
|
314
1133
|
}
|
|
@@ -328,7 +1147,10 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
328
1147
|
return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
|
|
329
1148
|
}
|
|
330
1149
|
async getAllowedPublicSetup() {
|
|
331
|
-
return
|
|
1150
|
+
return [
|
|
1151
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1152
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1153
|
+
];
|
|
332
1154
|
}
|
|
333
1155
|
/**
|
|
334
1156
|
* Method to determine if the node is ready to accept transactions.
|
|
@@ -351,50 +1173,16 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
351
1173
|
rollupVersion,
|
|
352
1174
|
enr,
|
|
353
1175
|
l1ContractAddresses: contractAddresses,
|
|
354
|
-
protocolContractAddresses: protocolContractAddresses
|
|
1176
|
+
protocolContractAddresses: protocolContractAddresses,
|
|
1177
|
+
realProofs: !!this.config.realProofs
|
|
355
1178
|
};
|
|
356
1179
|
return nodeInfo;
|
|
357
1180
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
* @param number - The block number being requested.
|
|
361
|
-
* @returns The requested block.
|
|
362
|
-
*/ async getBlock(number) {
|
|
363
|
-
const blockNumber = number === 'latest' ? await this.getBlockNumber() : number;
|
|
364
|
-
return await this.blockSource.getBlock(blockNumber);
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Get a block specified by its hash.
|
|
368
|
-
* @param blockHash - The block hash being requested.
|
|
369
|
-
* @returns The requested block.
|
|
370
|
-
*/ async getBlockByHash(blockHash) {
|
|
371
|
-
const publishedBlock = await this.blockSource.getPublishedBlockByHash(blockHash);
|
|
372
|
-
return publishedBlock?.block;
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* Get a block specified by its archive root.
|
|
376
|
-
* @param archive - The archive root being requested.
|
|
377
|
-
* @returns The requested block.
|
|
378
|
-
*/ async getBlockByArchive(archive) {
|
|
379
|
-
const publishedBlock = await this.blockSource.getPublishedBlockByArchive(archive);
|
|
380
|
-
return publishedBlock?.block;
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
|
|
384
|
-
* @param from - The start of the range of blocks to return.
|
|
385
|
-
* @param limit - The maximum number of blocks to obtain.
|
|
386
|
-
* @returns The blocks requested.
|
|
387
|
-
*/ async getBlocks(from, limit) {
|
|
388
|
-
return await this.blockSource.getBlocks(from, limit) ?? [];
|
|
389
|
-
}
|
|
390
|
-
async getPublishedBlocks(from, limit) {
|
|
391
|
-
return await this.blockSource.getPublishedBlocks(from, limit) ?? [];
|
|
1181
|
+
async getCurrentMinFees() {
|
|
1182
|
+
return await this.feeProvider.getCurrentMinFees();
|
|
392
1183
|
}
|
|
393
|
-
/**
|
|
394
|
-
|
|
395
|
-
* @returns The current base fees.
|
|
396
|
-
*/ async getCurrentBaseFees() {
|
|
397
|
-
return await this.globalVariableBuilder.getCurrentBaseFees();
|
|
1184
|
+
/** Returns predicted min fees for the current slot and next N slots. */ async getPredictedMinFees(manaUsage) {
|
|
1185
|
+
return await this.feeProvider.getPredictedMinFees(manaUsage);
|
|
398
1186
|
}
|
|
399
1187
|
async getMaxPriorityFees() {
|
|
400
1188
|
for await (const tx of this.p2pClient.iteratePendingTxs()){
|
|
@@ -406,15 +1194,6 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
406
1194
|
});
|
|
407
1195
|
}
|
|
408
1196
|
/**
|
|
409
|
-
* Method to fetch the latest block number synchronized by the node.
|
|
410
|
-
* @returns The block number.
|
|
411
|
-
*/ async getBlockNumber() {
|
|
412
|
-
return await this.blockSource.getBlockNumber();
|
|
413
|
-
}
|
|
414
|
-
async getProvenBlockNumber() {
|
|
415
|
-
return await this.blockSource.getProvenBlockNumber();
|
|
416
|
-
}
|
|
417
|
-
/**
|
|
418
1197
|
* Method to fetch the version of the package.
|
|
419
1198
|
* @returns The node package version
|
|
420
1199
|
*/ getNodeVersion() {
|
|
@@ -438,22 +1217,37 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
438
1217
|
getContract(address) {
|
|
439
1218
|
return this.contractDataSource.getContract(address);
|
|
440
1219
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
1220
|
+
async getPrivateLogsByTags(tags, page, referenceBlock) {
|
|
1221
|
+
let upToBlockNumber;
|
|
1222
|
+
if (referenceBlock) {
|
|
1223
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1224
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1225
|
+
upToBlockNumber = BlockNumber(0);
|
|
1226
|
+
} else {
|
|
1227
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
1228
|
+
if (!header) {
|
|
1229
|
+
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
1230
|
+
}
|
|
1231
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
1235
|
+
}
|
|
1236
|
+
async getPublicLogsByTagsFromContract(contractAddress, tags, page, referenceBlock) {
|
|
1237
|
+
let upToBlockNumber;
|
|
1238
|
+
if (referenceBlock) {
|
|
1239
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1240
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1241
|
+
upToBlockNumber = BlockNumber(0);
|
|
1242
|
+
} else {
|
|
1243
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
1244
|
+
if (!header) {
|
|
1245
|
+
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
1246
|
+
}
|
|
1247
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
457
1251
|
}
|
|
458
1252
|
/**
|
|
459
1253
|
* Gets public logs based on the provided filter.
|
|
@@ -487,25 +1281,42 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
487
1281
|
});
|
|
488
1282
|
throw new Error(`Invalid tx: ${reason}`);
|
|
489
1283
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
1284
|
+
try {
|
|
1285
|
+
await this.p2pClient.sendTx(tx);
|
|
1286
|
+
} catch (err) {
|
|
1287
|
+
this.metrics.receivedTx(timer.ms(), false);
|
|
1288
|
+
this.log.warn(`Mempool rejected tx ${txHash}: ${err.message}`, {
|
|
1289
|
+
txHash
|
|
1290
|
+
});
|
|
1291
|
+
throw err;
|
|
1292
|
+
}
|
|
1293
|
+
const duration = timer.ms();
|
|
1294
|
+
this.metrics.receivedTx(duration, true);
|
|
1295
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, {
|
|
493
1296
|
txHash
|
|
494
1297
|
});
|
|
495
1298
|
}
|
|
496
1299
|
async getTxReceipt(txHash) {
|
|
497
|
-
|
|
498
|
-
//
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
503
|
-
}
|
|
1300
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
1301
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
1302
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
1303
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
1304
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
504
1305
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
1306
|
+
let receipt;
|
|
505
1307
|
if (settledTxReceipt) {
|
|
506
|
-
|
|
1308
|
+
receipt = settledTxReceipt;
|
|
1309
|
+
} else if (isKnownToPool) {
|
|
1310
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
1311
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
1312
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
1313
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, /*executionResult=*/ undefined, /*error=*/ undefined);
|
|
1314
|
+
} else {
|
|
1315
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
1316
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, /*executionResult=*/ undefined, /*error=*/ 'Tx dropped by P2P node');
|
|
507
1317
|
}
|
|
508
|
-
|
|
1318
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
1319
|
+
return receipt;
|
|
509
1320
|
}
|
|
510
1321
|
getTxEffect(txHash) {
|
|
511
1322
|
return this.blockSource.getTxEffect(txHash);
|
|
@@ -514,18 +1325,30 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
514
1325
|
* Method to stop the aztec node.
|
|
515
1326
|
*/ async stop() {
|
|
516
1327
|
this.log.info(`Stopping Aztec Node`);
|
|
1328
|
+
await tryStop(this.attestationsBlockWatcher);
|
|
517
1329
|
await tryStop(this.validatorsSentinel);
|
|
518
1330
|
await tryStop(this.epochPruneWatcher);
|
|
519
1331
|
await tryStop(this.slasherClient);
|
|
520
|
-
await
|
|
1332
|
+
await Promise.all([
|
|
1333
|
+
tryStop(this.peerProofVerifier),
|
|
1334
|
+
tryStop(this.rpcProofVerifier)
|
|
1335
|
+
]);
|
|
521
1336
|
await tryStop(this.sequencer);
|
|
1337
|
+
await tryStop(this.proverNode);
|
|
522
1338
|
await tryStop(this.p2pClient);
|
|
523
1339
|
await tryStop(this.worldStateSynchronizer);
|
|
524
1340
|
await tryStop(this.blockSource);
|
|
1341
|
+
await tryStop(this.blobClient);
|
|
525
1342
|
await tryStop(this.telemetry);
|
|
526
1343
|
this.log.info(`Stopped Aztec Node`);
|
|
527
1344
|
}
|
|
528
1345
|
/**
|
|
1346
|
+
* Returns the blob client used by this node.
|
|
1347
|
+
* @internal - Exposed for testing purposes only.
|
|
1348
|
+
*/ getBlobClient() {
|
|
1349
|
+
return this.blobClient;
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
529
1352
|
* Method to retrieve pending txs.
|
|
530
1353
|
* @param limit - The number of items to returns
|
|
531
1354
|
* @param after - The last known pending tx. Used for pagination
|
|
@@ -550,101 +1373,83 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
550
1373
|
*/ async getTxsByHash(txHashes) {
|
|
551
1374
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
552
1375
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
* the leaves were inserted.
|
|
556
|
-
* @param blockNumber - The block number at which to get the data or 'latest' for latest data.
|
|
557
|
-
* @param treeId - The tree to search in.
|
|
558
|
-
* @param leafValues - The values to search for.
|
|
559
|
-
* @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
|
|
560
|
-
*/ async findLeavesIndexes(blockNumber, treeId, leafValues) {
|
|
561
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1376
|
+
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
1377
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
562
1378
|
const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
|
|
563
|
-
//
|
|
564
|
-
const
|
|
565
|
-
// Now we find the block numbers for the indices
|
|
566
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
567
|
-
//
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
1379
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
1380
|
+
const definedIndices = maybeIndices.filter((x)=>x !== undefined);
|
|
1381
|
+
// Now we find the block numbers for the defined indices
|
|
1382
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
1383
|
+
// Build a map from leaf index to block number
|
|
1384
|
+
const indexToBlockNumber = new Map();
|
|
1385
|
+
for(let i = 0; i < definedIndices.length; i++){
|
|
1386
|
+
const blockNumber = blockNumbers[i];
|
|
1387
|
+
if (blockNumber === undefined) {
|
|
1388
|
+
throw new Error(`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`);
|
|
571
1389
|
}
|
|
1390
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
572
1391
|
}
|
|
573
1392
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
574
1393
|
const uniqueBlockNumbers = [
|
|
575
|
-
...new Set(
|
|
1394
|
+
...new Set(indexToBlockNumber.values())
|
|
576
1395
|
];
|
|
577
|
-
// Now we obtain the block hashes from the archive tree
|
|
578
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1396
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
579
1397
|
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
580
|
-
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, blockNumber);
|
|
1398
|
+
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
581
1399
|
}));
|
|
582
|
-
//
|
|
1400
|
+
// Build a map from block number to block hash
|
|
1401
|
+
const blockNumberToHash = new Map();
|
|
583
1402
|
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
584
|
-
|
|
1403
|
+
const blockHash = blockHashes[i];
|
|
1404
|
+
if (blockHash === undefined) {
|
|
585
1405
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
586
1406
|
}
|
|
1407
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
587
1408
|
}
|
|
588
|
-
// Create
|
|
589
|
-
return maybeIndices.map((index
|
|
1409
|
+
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1410
|
+
return maybeIndices.map((index)=>{
|
|
590
1411
|
if (index === undefined) {
|
|
591
1412
|
return undefined;
|
|
592
1413
|
}
|
|
593
|
-
const blockNumber =
|
|
1414
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
594
1415
|
if (blockNumber === undefined) {
|
|
595
|
-
|
|
1416
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
596
1417
|
}
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
return undefined;
|
|
1418
|
+
const l2BlockHash = blockNumberToHash.get(blockNumber);
|
|
1419
|
+
if (l2BlockHash === undefined) {
|
|
1420
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
601
1421
|
}
|
|
602
1422
|
return {
|
|
603
|
-
l2BlockNumber:
|
|
604
|
-
l2BlockHash
|
|
1423
|
+
l2BlockNumber: blockNumber,
|
|
1424
|
+
l2BlockHash,
|
|
605
1425
|
data: index
|
|
606
1426
|
};
|
|
607
1427
|
});
|
|
608
1428
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
* Returns a sibling path for the given index in the data tree.
|
|
620
|
-
* @param blockNumber - The block number at which to get the data.
|
|
621
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
622
|
-
* @returns The sibling path for the leaf index.
|
|
623
|
-
*/ async getNoteHashSiblingPath(blockNumber, leafIndex) {
|
|
624
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
625
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
626
|
-
}
|
|
627
|
-
async getArchiveMembershipWitness(blockNumber, archive) {
|
|
628
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1429
|
+
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
1430
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1431
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1432
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1433
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1434
|
+
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
1435
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1436
|
+
return undefined;
|
|
1437
|
+
}
|
|
1438
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
629
1439
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
630
|
-
|
|
1440
|
+
blockHash
|
|
631
1441
|
]);
|
|
632
1442
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
633
1443
|
}
|
|
634
|
-
async getNoteHashMembershipWitness(
|
|
635
|
-
const committedDb = await this
|
|
1444
|
+
async getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
1445
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
636
1446
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
637
1447
|
noteHash
|
|
638
1448
|
]);
|
|
639
1449
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
640
1450
|
}
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
* @param blockNumber - The block number at which to get the data.
|
|
644
|
-
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
|
|
645
|
-
* @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
|
|
646
|
-
*/ async getL1ToL2MessageMembershipWitness(blockNumber, l1ToL2Message) {
|
|
647
|
-
const db = await this.#getWorldState(blockNumber);
|
|
1451
|
+
async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
1452
|
+
const db = await this.getWorldState(referenceBlock);
|
|
648
1453
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
649
1454
|
l1ToL2Message
|
|
650
1455
|
]);
|
|
@@ -657,9 +1462,9 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
657
1462
|
witness.path
|
|
658
1463
|
];
|
|
659
1464
|
}
|
|
660
|
-
async
|
|
1465
|
+
async getL1ToL2MessageCheckpoint(l1ToL2Message) {
|
|
661
1466
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
662
|
-
return messageIndex ? InboxLeaf.
|
|
1467
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
663
1468
|
}
|
|
664
1469
|
/**
|
|
665
1470
|
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
@@ -670,38 +1475,17 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
670
1475
|
return messageIndex !== undefined;
|
|
671
1476
|
}
|
|
672
1477
|
/**
|
|
673
|
-
* Returns all the L2 to L1 messages in
|
|
674
|
-
* @param
|
|
675
|
-
* @returns The L2 to L1 messages (
|
|
676
|
-
*/ async getL2ToL1Messages(
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
* @returns The sibling path.
|
|
685
|
-
*/ async getArchiveSiblingPath(blockNumber, leafIndex) {
|
|
686
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
687
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
688
|
-
}
|
|
689
|
-
/**
|
|
690
|
-
* Returns a sibling path for a leaf in the committed public data tree.
|
|
691
|
-
* @param blockNumber - The block number at which to get the data.
|
|
692
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
693
|
-
* @returns The sibling path.
|
|
694
|
-
*/ async getPublicDataSiblingPath(blockNumber, leafIndex) {
|
|
695
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
696
|
-
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
697
|
-
}
|
|
698
|
-
/**
|
|
699
|
-
* Returns a nullifier membership witness for a given nullifier at a given block.
|
|
700
|
-
* @param blockNumber - The block number at which to get the index.
|
|
701
|
-
* @param nullifier - Nullifier we try to find witness for.
|
|
702
|
-
* @returns The nullifier membership witness (if found).
|
|
703
|
-
*/ async getNullifierMembershipWitness(blockNumber, nullifier) {
|
|
704
|
-
const db = await this.#getWorldState(blockNumber);
|
|
1478
|
+
* Returns all the L2 to L1 messages in an epoch.
|
|
1479
|
+
* @param epoch - The epoch at which to get the data.
|
|
1480
|
+
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
1481
|
+
*/ async getL2ToL1Messages(epoch) {
|
|
1482
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1483
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1484
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, (cb)=>cb.block.header.globalVariables.slotNumber).map((group)=>group.map((cb)=>cb.block));
|
|
1485
|
+
return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
1486
|
+
}
|
|
1487
|
+
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1488
|
+
const db = await this.getWorldState(referenceBlock);
|
|
705
1489
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
706
1490
|
nullifier.toBuffer()
|
|
707
1491
|
]);
|
|
@@ -715,35 +1499,22 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
715
1499
|
}
|
|
716
1500
|
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
717
1501
|
}
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
* @param blockNumber - The block number at which to get the index.
|
|
721
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
722
|
-
* @returns The low nullifier membership witness (if found).
|
|
723
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
724
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
725
|
-
* we are trying to prove non-inclusion for.
|
|
726
|
-
*
|
|
727
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
728
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
729
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
730
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
731
|
-
*/ async getLowNullifierMembershipWitness(blockNumber, nullifier) {
|
|
732
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1502
|
+
async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1503
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
733
1504
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
734
1505
|
if (!findResult) {
|
|
735
1506
|
return undefined;
|
|
736
1507
|
}
|
|
737
1508
|
const { index, alreadyPresent } = findResult;
|
|
738
1509
|
if (alreadyPresent) {
|
|
739
|
-
|
|
1510
|
+
throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
740
1511
|
}
|
|
741
1512
|
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
742
1513
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
743
1514
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
744
1515
|
}
|
|
745
|
-
async getPublicDataWitness(
|
|
746
|
-
const committedDb = await this
|
|
1516
|
+
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1517
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
747
1518
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
748
1519
|
if (!lowLeafResult) {
|
|
749
1520
|
return undefined;
|
|
@@ -753,18 +1524,8 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
753
1524
|
return new PublicDataWitness(lowLeafResult.index, preimage, path);
|
|
754
1525
|
}
|
|
755
1526
|
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
*
|
|
759
|
-
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
|
|
760
|
-
* Aztec's version of `eth_getStorageAt`.
|
|
761
|
-
*
|
|
762
|
-
* @param contract - Address of the contract to query.
|
|
763
|
-
* @param slot - Slot to query.
|
|
764
|
-
* @param blockNumber - The block number at which to get the data or 'latest'.
|
|
765
|
-
* @returns Storage value at the given contract slot.
|
|
766
|
-
*/ async getPublicStorageAt(blockNumber, contract, slot) {
|
|
767
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1527
|
+
async getPublicStorageAt(referenceBlock, contract, slot) {
|
|
1528
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
768
1529
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
769
1530
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
770
1531
|
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
@@ -774,26 +1535,6 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
774
1535
|
return preimage.leaf.value;
|
|
775
1536
|
}
|
|
776
1537
|
/**
|
|
777
|
-
* Returns the currently committed block header, or the initial header if no blocks have been produced.
|
|
778
|
-
* @returns The current committed block header.
|
|
779
|
-
*/ async getBlockHeader(blockNumber = 'latest') {
|
|
780
|
-
return blockNumber === 0 || blockNumber === 'latest' && await this.blockSource.getBlockNumber() === 0 ? this.worldStateSynchronizer.getCommitted().getInitialHeader() : this.blockSource.getBlockHeader(blockNumber);
|
|
781
|
-
}
|
|
782
|
-
/**
|
|
783
|
-
* Get a block header specified by its hash.
|
|
784
|
-
* @param blockHash - The block hash being requested.
|
|
785
|
-
* @returns The requested block header.
|
|
786
|
-
*/ async getBlockHeaderByHash(blockHash) {
|
|
787
|
-
return await this.blockSource.getBlockHeaderByHash(blockHash);
|
|
788
|
-
}
|
|
789
|
-
/**
|
|
790
|
-
* Get a block header specified by its archive root.
|
|
791
|
-
* @param archive - The archive root being requested.
|
|
792
|
-
* @returns The requested block header.
|
|
793
|
-
*/ async getBlockHeaderByArchive(archive) {
|
|
794
|
-
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
795
|
-
}
|
|
796
|
-
/**
|
|
797
1538
|
* Simulates the public part of a transaction with the current state.
|
|
798
1539
|
* @param tx - The transaction to simulate.
|
|
799
1540
|
**/ async simulatePublicCalls(tx, skipFeeEnforcement = false) {
|
|
@@ -805,17 +1546,20 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
805
1546
|
throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
|
|
806
1547
|
}
|
|
807
1548
|
const txHash = tx.getTxHash();
|
|
808
|
-
const
|
|
1549
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1550
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
809
1551
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
810
1552
|
const coinbase = EthAddress.ZERO;
|
|
811
1553
|
const feeRecipient = AztecAddress.ZERO;
|
|
812
1554
|
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(blockNumber, coinbase, feeRecipient);
|
|
813
|
-
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry);
|
|
1555
|
+
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry, this.log.getBindings());
|
|
814
1556
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
815
1557
|
globalVariables: newGlobalVariables.toInspect(),
|
|
816
1558
|
txHash,
|
|
817
1559
|
blockNumber
|
|
818
1560
|
});
|
|
1561
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1562
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
819
1563
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
820
1564
|
try {
|
|
821
1565
|
const config = PublicSimulatorConfig.from({
|
|
@@ -823,12 +1567,14 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
823
1567
|
collectDebugLogs: true,
|
|
824
1568
|
collectHints: false,
|
|
825
1569
|
collectCallMetadata: true,
|
|
826
|
-
|
|
827
|
-
|
|
1570
|
+
collectStatistics: false,
|
|
1571
|
+
collectionLimits: CollectionLimitsConfig.from({
|
|
1572
|
+
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads
|
|
1573
|
+
})
|
|
828
1574
|
});
|
|
829
1575
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
830
1576
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
831
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
|
|
1577
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([
|
|
832
1578
|
tx
|
|
833
1579
|
]);
|
|
834
1580
|
// REFACTOR: Consider returning the error rather than throwing
|
|
@@ -839,27 +1585,34 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
839
1585
|
throw failedTxs[0].error;
|
|
840
1586
|
}
|
|
841
1587
|
const [processedTx] = processedTxs;
|
|
842
|
-
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed);
|
|
1588
|
+
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed, debugLogs);
|
|
843
1589
|
} finally{
|
|
844
1590
|
await merkleTreeFork.close();
|
|
845
1591
|
}
|
|
846
1592
|
}
|
|
847
1593
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
848
1594
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
849
|
-
const verifier = isSimulation ? undefined : this.
|
|
850
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1595
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1596
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
851
1597
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
852
|
-
const blockNumber = await this.blockSource.getBlockNumber() + 1;
|
|
853
|
-
const
|
|
1598
|
+
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1599
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1600
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
|
|
854
1601
|
timestamp: nextSlotTimestamp,
|
|
855
1602
|
blockNumber,
|
|
856
1603
|
l1ChainId: this.l1ChainId,
|
|
857
1604
|
rollupVersion: this.version,
|
|
858
|
-
setupAllowList:
|
|
859
|
-
|
|
1605
|
+
setupAllowList: [
|
|
1606
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1607
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1608
|
+
],
|
|
1609
|
+
gasFees: await this.getCurrentMinFees(),
|
|
860
1610
|
skipFeeEnforcement,
|
|
861
|
-
txsPermitted: !this.config.disableTransactions
|
|
862
|
-
|
|
1611
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1612
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1613
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1614
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
1615
|
+
}, this.log.getBindings());
|
|
863
1616
|
return await validator.validateTx(tx);
|
|
864
1617
|
}
|
|
865
1618
|
getConfig() {
|
|
@@ -881,7 +1634,18 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
881
1634
|
archiver.updateConfig(config);
|
|
882
1635
|
}
|
|
883
1636
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
884
|
-
|
|
1637
|
+
await Promise.all([
|
|
1638
|
+
tryStop(this.peerProofVerifier),
|
|
1639
|
+
tryStop(this.rpcProofVerifier)
|
|
1640
|
+
]);
|
|
1641
|
+
if (newConfig.realProofs) {
|
|
1642
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1643
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1644
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1645
|
+
} else {
|
|
1646
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1647
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1648
|
+
}
|
|
885
1649
|
}
|
|
886
1650
|
this.config = newConfig;
|
|
887
1651
|
}
|
|
@@ -919,7 +1683,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
919
1683
|
throw new Error(`Archiver initial sync not complete. Cannot start snapshot.`);
|
|
920
1684
|
}
|
|
921
1685
|
// And it has an L2 block hash
|
|
922
|
-
const l2BlockHash = await archiver.getL2Tips().then((tips)=>tips.
|
|
1686
|
+
const l2BlockHash = await archiver.getL2Tips().then((tips)=>tips.proposed.hash);
|
|
923
1687
|
if (!l2BlockHash) {
|
|
924
1688
|
this.metrics.recordSnapshotError();
|
|
925
1689
|
throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
|
|
@@ -941,12 +1705,12 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
941
1705
|
});
|
|
942
1706
|
return Promise.resolve();
|
|
943
1707
|
}
|
|
944
|
-
async rollbackTo(targetBlock, force) {
|
|
1708
|
+
async rollbackTo(targetBlock, force, resumeSync = true) {
|
|
945
1709
|
const archiver = this.blockSource;
|
|
946
1710
|
if (!('rollbackTo' in archiver)) {
|
|
947
1711
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
948
1712
|
}
|
|
949
|
-
const finalizedBlock = await archiver.getL2Tips().then((tips)=>tips.finalized.number);
|
|
1713
|
+
const finalizedBlock = await archiver.getL2Tips().then((tips)=>tips.finalized.block.number);
|
|
950
1714
|
if (targetBlock < finalizedBlock) {
|
|
951
1715
|
if (force) {
|
|
952
1716
|
this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
|
|
@@ -969,9 +1733,13 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
969
1733
|
this.log.error(`Error during rollback`, err);
|
|
970
1734
|
throw err;
|
|
971
1735
|
} finally{
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
1736
|
+
if (resumeSync) {
|
|
1737
|
+
this.log.info(`Resuming world state and archiver sync.`);
|
|
1738
|
+
this.worldStateSynchronizer.resumeSync();
|
|
1739
|
+
archiver.resume();
|
|
1740
|
+
} else {
|
|
1741
|
+
this.log.info(`Sync left paused after rollback (resumeSync=false).`);
|
|
1742
|
+
}
|
|
975
1743
|
}
|
|
976
1744
|
}
|
|
977
1745
|
async pauseSync() {
|
|
@@ -985,58 +1753,197 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
985
1753
|
this.blockSource.resume();
|
|
986
1754
|
return Promise.resolve();
|
|
987
1755
|
}
|
|
988
|
-
getSlashPayloads() {
|
|
989
|
-
if (!this.slasherClient) {
|
|
990
|
-
throw new Error(`Slasher client not enabled`);
|
|
991
|
-
}
|
|
992
|
-
return this.slasherClient.getSlashPayloads();
|
|
993
|
-
}
|
|
994
1756
|
getSlashOffenses(round) {
|
|
995
1757
|
if (!this.slasherClient) {
|
|
996
1758
|
throw new Error(`Slasher client not enabled`);
|
|
997
1759
|
}
|
|
998
1760
|
if (round === 'all') {
|
|
999
|
-
return this.slasherClient.
|
|
1761
|
+
return this.slasherClient.getOffenses();
|
|
1000
1762
|
} else {
|
|
1001
1763
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1002
1764
|
}
|
|
1003
1765
|
}
|
|
1766
|
+
async reloadKeystore() {
|
|
1767
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1768
|
+
throw new BadRequestError('Cannot reload keystore: node is not using a file-based keystore. ' + 'Set KEY_STORE_DIRECTORY to use file-based keystores.');
|
|
1769
|
+
}
|
|
1770
|
+
if (!this.validatorClient) {
|
|
1771
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1772
|
+
}
|
|
1773
|
+
this.log.info('Reloading keystore from disk');
|
|
1774
|
+
// Re-read and validate keystore files
|
|
1775
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1776
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1777
|
+
await newManager.validateSigners();
|
|
1778
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1779
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1780
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1781
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1782
|
+
// would silently fail on every proposer slot.
|
|
1783
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1784
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1785
|
+
const availablePublishers = new Set(oldAdapter.getAttesterAddresses().flatMap((a)=>oldAdapter.getPublisherAddresses(a).map((p)=>p.toString().toLowerCase())));
|
|
1786
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1787
|
+
for (const attester of newAdapter.getAttesterAddresses()){
|
|
1788
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1789
|
+
if (pubs.length > 0 && !pubs.some((p)=>availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1790
|
+
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 ` + `[${[
|
|
1791
|
+
...availablePublishers
|
|
1792
|
+
].join(', ')}]. Publishers cannot be hot-reloaded — ` + `use an existing publisher key or restart the node.`);
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
// Build adapters for old and new keystores to compute diff
|
|
1797
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1798
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1799
|
+
const oldAddresses = this.keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses() : [];
|
|
1800
|
+
const oldSet = new Set(oldAddresses.map((a)=>a.toString()));
|
|
1801
|
+
const newSet = new Set(newAddresses.map((a)=>a.toString()));
|
|
1802
|
+
const added = newAddresses.filter((a)=>!oldSet.has(a.toString()));
|
|
1803
|
+
const removed = oldAddresses.filter((a)=>!newSet.has(a.toString()));
|
|
1804
|
+
if (added.length > 0) {
|
|
1805
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map((a)=>a.toString()).join(', ')}`);
|
|
1806
|
+
}
|
|
1807
|
+
if (removed.length > 0) {
|
|
1808
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map((a)=>a.toString()).join(', ')}`);
|
|
1809
|
+
}
|
|
1810
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1811
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1812
|
+
}
|
|
1813
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1814
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1815
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1816
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1817
|
+
if (this.sequencer) {
|
|
1818
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1819
|
+
}
|
|
1820
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1821
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1822
|
+
const slashValidatorsNever = unique([
|
|
1823
|
+
...this.config.slashValidatorsNever ?? [],
|
|
1824
|
+
...newAddresses
|
|
1825
|
+
].map((a)=>a.toString())).map(EthAddress.fromString);
|
|
1826
|
+
this.slasherClient.updateConfig({
|
|
1827
|
+
slashValidatorsNever
|
|
1828
|
+
});
|
|
1829
|
+
}
|
|
1830
|
+
this.keyStoreManager = newManager;
|
|
1831
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1832
|
+
}
|
|
1833
|
+
async mineBlock() {
|
|
1834
|
+
if (!this.sequencer) {
|
|
1835
|
+
throw new BadRequestError('Cannot mine block: no sequencer is running');
|
|
1836
|
+
}
|
|
1837
|
+
const currentBlockNumber = await this.getBlockNumber();
|
|
1838
|
+
// Use slot duration + 50% buffer as the timeout so this works on running networks too
|
|
1839
|
+
const { slotDuration } = await this.blockSource.getL1Constants();
|
|
1840
|
+
const timeoutSeconds = Math.ceil(slotDuration * 1.5);
|
|
1841
|
+
// Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
|
|
1842
|
+
const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
|
|
1843
|
+
this.sequencer.updateConfig({
|
|
1844
|
+
minTxsPerBlock: 0
|
|
1845
|
+
});
|
|
1846
|
+
try {
|
|
1847
|
+
// Trigger the sequencer to produce a block immediately
|
|
1848
|
+
void this.sequencer.trigger();
|
|
1849
|
+
// Wait for the new L2 block to appear
|
|
1850
|
+
await retryUntil(async ()=>{
|
|
1851
|
+
const newBlockNumber = await this.getBlockNumber();
|
|
1852
|
+
return newBlockNumber > currentBlockNumber ? true : undefined;
|
|
1853
|
+
}, 'mineBlock', timeoutSeconds, 0.1);
|
|
1854
|
+
} finally{
|
|
1855
|
+
this.sequencer.updateConfig({
|
|
1856
|
+
minTxsPerBlock: originalMinTxsPerBlock
|
|
1857
|
+
});
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
#getInitialHeaderHash() {
|
|
1861
|
+
if (!this.initialHeaderHashPromise) {
|
|
1862
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1863
|
+
}
|
|
1864
|
+
return this.initialHeaderHashPromise;
|
|
1865
|
+
}
|
|
1004
1866
|
/**
|
|
1005
1867
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1006
|
-
* @param
|
|
1868
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1007
1869
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1008
|
-
*/ async
|
|
1009
|
-
|
|
1010
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
1011
|
-
}
|
|
1012
|
-
let blockSyncedTo = 0;
|
|
1870
|
+
*/ async getWorldState(block) {
|
|
1871
|
+
let blockSyncedTo = BlockNumber.ZERO;
|
|
1013
1872
|
try {
|
|
1014
1873
|
// Attempt to sync the world state if necessary
|
|
1015
1874
|
blockSyncedTo = await this.#syncWorldState();
|
|
1016
1875
|
} catch (err) {
|
|
1017
1876
|
this.log.error(`Error getting world state: ${err}`);
|
|
1018
1877
|
}
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1878
|
+
if (block === 'latest') {
|
|
1879
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1022
1880
|
return this.worldStateSynchronizer.getCommitted();
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
|
|
1881
|
+
}
|
|
1882
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1883
|
+
let blockNumber;
|
|
1884
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1885
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1886
|
+
if (block.equals(initialBlockHash)) {
|
|
1887
|
+
// Block 0 is a first-class historical block: its state lives in the trees' persisted
|
|
1888
|
+
// block-0 payload. Resolving the genesis hash to block number 0 lets the snapshot path
|
|
1889
|
+
// pin reads to genesis state even after the node has advanced past it.
|
|
1890
|
+
blockNumber = BlockNumber.ZERO;
|
|
1891
|
+
} else {
|
|
1892
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1893
|
+
if (!header) {
|
|
1894
|
+
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.`);
|
|
1895
|
+
}
|
|
1896
|
+
blockNumber = header.getBlockNumber();
|
|
1897
|
+
}
|
|
1026
1898
|
} else {
|
|
1027
|
-
|
|
1899
|
+
blockNumber = block;
|
|
1900
|
+
}
|
|
1901
|
+
// Check it's within world state sync range
|
|
1902
|
+
if (blockNumber > blockSyncedTo) {
|
|
1903
|
+
throw new Error(`Queried block ${inspectBlockParameter(block)} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1904
|
+
}
|
|
1905
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1906
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1907
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1908
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1909
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1910
|
+
if (!blockHash || !block.equals(blockHash)) {
|
|
1911
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1912
|
+
throw new Error(`Block hash ${block.toString()} not found in world state at block number ${blockNumber} (world state has ${blockHash?.toString() ?? 'no hash'} at that index, genesis header hash is ${initialBlockHash.toString()}). If the node API has been queried with anchor block hash possibly a reorg has occurred.`);
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
return snapshot;
|
|
1916
|
+
}
|
|
1917
|
+
/** Resolves any {@link BlockParameter} variant to a concrete block number. */ async resolveBlockNumber(block) {
|
|
1918
|
+
const resolved = await this.resolveBlockParameter(block);
|
|
1919
|
+
if (resolved.number !== undefined) {
|
|
1920
|
+
return resolved.number;
|
|
1921
|
+
}
|
|
1922
|
+
if (resolved.hash !== undefined) {
|
|
1923
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1924
|
+
if (resolved.hash.equals(initialBlockHash)) {
|
|
1925
|
+
return BlockNumber.ZERO;
|
|
1926
|
+
}
|
|
1927
|
+
const header = await this.blockSource.getBlockHeaderByHash(resolved.hash);
|
|
1928
|
+
if (!header) {
|
|
1929
|
+
throw new Error(`Block hash ${resolved.hash.toString()} not found.`);
|
|
1930
|
+
}
|
|
1931
|
+
return header.getBlockNumber();
|
|
1932
|
+
}
|
|
1933
|
+
if (resolved.archive !== undefined) {
|
|
1934
|
+
const header = await this.blockSource.getBlockHeaderByArchive(resolved.archive);
|
|
1935
|
+
if (!header) {
|
|
1936
|
+
throw new Error(`Block with archive ${resolved.archive.toString()} not found.`);
|
|
1937
|
+
}
|
|
1938
|
+
return header.getBlockNumber();
|
|
1028
1939
|
}
|
|
1940
|
+
throw new BadRequestError(`Invalid BlockParameter: ${JSON.stringify(block)}`);
|
|
1029
1941
|
}
|
|
1030
1942
|
/**
|
|
1031
1943
|
* Ensure we fully sync the world state
|
|
1032
1944
|
* @returns A promise that fulfils once the world state is synced
|
|
1033
1945
|
*/ async #syncWorldState() {
|
|
1034
1946
|
const blockSourceHeight = await this.blockSource.getBlockNumber();
|
|
1035
|
-
return this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1947
|
+
return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1036
1948
|
}
|
|
1037
1949
|
}
|
|
1038
|
-
_ts_decorate([
|
|
1039
|
-
trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
1040
|
-
[Attributes.TX_HASH]: tx.getTxHash().toString()
|
|
1041
|
-
}))
|
|
1042
|
-
], AztecNodeService.prototype, "simulatePublicCalls", null);
|