@aztec/aztec-node 0.0.1-commit.9b94fc1 → 0.0.1-commit.9badcec54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/aztec-node/config.d.ts +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 +89 -147
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +1024 -323
- package/dest/sentinel/factory.d.ts +2 -2
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +1 -1
- package/dest/sentinel/sentinel.d.ts +6 -5
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +91 -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/config.ts +35 -15
- package/src/aztec-node/node_metrics.ts +6 -17
- package/src/aztec-node/server.ts +785 -406
- package/src/sentinel/factory.ts +2 -7
- package/src/sentinel/sentinel.ts +103 -61
- package/src/sentinel/store.ts +12 -12
|
@@ -1,49 +1,427 @@
|
|
|
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
|
+
};
|
|
369
|
+
}
|
|
370
|
+
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
371
|
+
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
6
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 } from '@aztec/stdlib/block';
|
|
406
|
+
import { GasFees } from '@aztec/stdlib/gas';
|
|
32
407
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
33
408
|
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
34
409
|
import { tryStop } from '@aztec/stdlib/interfaces/server';
|
|
410
|
+
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
35
411
|
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
36
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
37
412
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
38
413
|
import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
39
414
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
40
415
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
41
|
-
import { NodeKeystoreAdapter, ValidatorClient,
|
|
416
|
+
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createProposalHandler, createValidatorClient } from '@aztec/validator-client';
|
|
42
417
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
43
|
-
import { createPublicClient
|
|
418
|
+
import { createPublicClient } from 'viem';
|
|
44
419
|
import { createSentinel } from '../sentinel/factory.js';
|
|
45
420
|
import { createKeyStoreForValidator } from './config.js';
|
|
46
421
|
import { NodeMetrics } from './node_metrics.js';
|
|
422
|
+
_dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
423
|
+
[Attributes.TX_HASH]: tx.getTxHash().toString()
|
|
424
|
+
}));
|
|
47
425
|
/**
|
|
48
426
|
* The aztec node.
|
|
49
427
|
*/ export class AztecNodeService {
|
|
@@ -55,22 +433,39 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
55
433
|
l1ToL2MessageSource;
|
|
56
434
|
worldStateSynchronizer;
|
|
57
435
|
sequencer;
|
|
436
|
+
proverNode;
|
|
58
437
|
slasherClient;
|
|
59
438
|
validatorsSentinel;
|
|
60
439
|
epochPruneWatcher;
|
|
61
440
|
l1ChainId;
|
|
62
441
|
version;
|
|
63
442
|
globalVariableBuilder;
|
|
443
|
+
feeProvider;
|
|
64
444
|
epochCache;
|
|
65
445
|
packageVersion;
|
|
66
|
-
|
|
446
|
+
peerProofVerifier;
|
|
447
|
+
rpcProofVerifier;
|
|
67
448
|
telemetry;
|
|
68
449
|
log;
|
|
450
|
+
blobClient;
|
|
451
|
+
validatorClient;
|
|
452
|
+
keyStoreManager;
|
|
453
|
+
debugLogStore;
|
|
454
|
+
static{
|
|
455
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
456
|
+
[
|
|
457
|
+
_dec,
|
|
458
|
+
2,
|
|
459
|
+
"simulatePublicCalls"
|
|
460
|
+
]
|
|
461
|
+
], []));
|
|
462
|
+
}
|
|
69
463
|
metrics;
|
|
464
|
+
initialHeaderHashPromise;
|
|
70
465
|
// Prevent two snapshot operations to happen simultaneously
|
|
71
466
|
isUploadingSnapshot;
|
|
72
467
|
tracer;
|
|
73
|
-
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion,
|
|
468
|
+
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, feeProvider, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry = getTelemetryClient(), log = createLogger('node'), blobClient, validatorClient, keyStoreManager, debugLogStore = new NullDebugLogStore()){
|
|
74
469
|
this.config = config;
|
|
75
470
|
this.p2pClient = p2pClient;
|
|
76
471
|
this.blockSource = blockSource;
|
|
@@ -79,22 +474,39 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
79
474
|
this.l1ToL2MessageSource = l1ToL2MessageSource;
|
|
80
475
|
this.worldStateSynchronizer = worldStateSynchronizer;
|
|
81
476
|
this.sequencer = sequencer;
|
|
477
|
+
this.proverNode = proverNode;
|
|
82
478
|
this.slasherClient = slasherClient;
|
|
83
479
|
this.validatorsSentinel = validatorsSentinel;
|
|
84
480
|
this.epochPruneWatcher = epochPruneWatcher;
|
|
85
481
|
this.l1ChainId = l1ChainId;
|
|
86
482
|
this.version = version;
|
|
87
483
|
this.globalVariableBuilder = globalVariableBuilder;
|
|
484
|
+
this.feeProvider = feeProvider;
|
|
88
485
|
this.epochCache = epochCache;
|
|
89
486
|
this.packageVersion = packageVersion;
|
|
90
|
-
this.
|
|
487
|
+
this.peerProofVerifier = peerProofVerifier;
|
|
488
|
+
this.rpcProofVerifier = rpcProofVerifier;
|
|
91
489
|
this.telemetry = telemetry;
|
|
92
490
|
this.log = log;
|
|
491
|
+
this.blobClient = blobClient;
|
|
492
|
+
this.validatorClient = validatorClient;
|
|
493
|
+
this.keyStoreManager = keyStoreManager;
|
|
494
|
+
this.debugLogStore = debugLogStore;
|
|
495
|
+
this.initialHeaderHashPromise = (_initProto(this), undefined);
|
|
93
496
|
this.isUploadingSnapshot = false;
|
|
94
497
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
95
498
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
96
499
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
97
500
|
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
|
|
501
|
+
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
502
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
503
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
504
|
+
if (debugLogStore.isEnabled && config.realProofs) {
|
|
505
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */ getProofVerifier() {
|
|
509
|
+
return this.rpcProofVerifier;
|
|
98
510
|
}
|
|
99
511
|
async getWorldStateSyncStatus() {
|
|
100
512
|
const status = await this.worldStateSynchronizer.status();
|
|
@@ -115,20 +527,28 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
115
527
|
const packageVersion = getPackageVersion() ?? '';
|
|
116
528
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
117
529
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
118
|
-
const blobSinkClient = deps.blobSinkClient ?? createBlobSinkClient(config, {
|
|
119
|
-
logger: createLogger('node:blob-sink:client')
|
|
120
|
-
});
|
|
121
530
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
122
|
-
// Build a key store from file if given or from environment otherwise
|
|
531
|
+
// Build a key store from file if given or from environment otherwise.
|
|
532
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
123
533
|
let keyStoreManager;
|
|
124
534
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
125
535
|
if (keyStoreProvided) {
|
|
126
536
|
const keyStores = loadKeystores(config.keyStoreDirectory);
|
|
127
537
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
128
538
|
} else {
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
539
|
+
const rawKeyStores = [];
|
|
540
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
541
|
+
if (validatorKeyStore) {
|
|
542
|
+
rawKeyStores.push(validatorKeyStore);
|
|
543
|
+
}
|
|
544
|
+
if (config.enableProverNode) {
|
|
545
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
546
|
+
if (proverKeyStore) {
|
|
547
|
+
rawKeyStores.push(proverKeyStore);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
if (rawKeyStores.length > 0) {
|
|
551
|
+
keyStoreManager = new KeystoreManager(rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores));
|
|
132
552
|
}
|
|
133
553
|
}
|
|
134
554
|
await keyStoreManager?.validateSigners();
|
|
@@ -137,8 +557,8 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
137
557
|
if (keyStoreManager === undefined) {
|
|
138
558
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
139
559
|
}
|
|
140
|
-
if (!keyStoreProvided) {
|
|
141
|
-
log.warn(
|
|
560
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
561
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
142
562
|
}
|
|
143
563
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
144
564
|
}
|
|
@@ -148,7 +568,9 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
148
568
|
}
|
|
149
569
|
const publicClient = createPublicClient({
|
|
150
570
|
chain: ethereumChain.chainInfo,
|
|
151
|
-
transport:
|
|
571
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, {
|
|
572
|
+
timeout: config.l1HttpTimeoutMS
|
|
573
|
+
}),
|
|
152
574
|
pollingInterval: config.viemPollingIntervalMS
|
|
153
575
|
});
|
|
154
576
|
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.l1Contracts.registryAddress, config.rollupVersion ?? 'canonical');
|
|
@@ -158,22 +580,24 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
158
580
|
...l1ContractsAddresses
|
|
159
581
|
};
|
|
160
582
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
161
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
583
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
162
584
|
rollupContract.getL1GenesisTime(),
|
|
163
585
|
rollupContract.getSlotDuration(),
|
|
164
|
-
rollupContract.getVersion()
|
|
586
|
+
rollupContract.getVersion(),
|
|
587
|
+
rollupContract.getManaLimit().then(Number)
|
|
165
588
|
]);
|
|
166
589
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
167
590
|
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
168
591
|
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}).`);
|
|
169
592
|
}
|
|
593
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
170
594
|
// attempt snapshot sync if possible
|
|
171
595
|
await trySnapshotSync(config, log);
|
|
172
596
|
const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, {
|
|
173
597
|
dateProvider
|
|
174
598
|
});
|
|
175
599
|
const archiver = await createArchiver(config, {
|
|
176
|
-
|
|
600
|
+
blobClient,
|
|
177
601
|
epochCache,
|
|
178
602
|
telemetry,
|
|
179
603
|
dateProvider
|
|
@@ -181,117 +605,195 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
181
605
|
blockUntilSync: !config.skipArchiverInitialSync
|
|
182
606
|
});
|
|
183
607
|
// now create the merkle trees and the world state synchronizer
|
|
184
|
-
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.
|
|
185
|
-
const
|
|
608
|
+
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.genesis, telemetry);
|
|
609
|
+
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
610
|
+
let peerProofVerifier;
|
|
611
|
+
let rpcProofVerifier;
|
|
612
|
+
if (useRealVerifiers) {
|
|
613
|
+
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
614
|
+
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
615
|
+
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
616
|
+
} else {
|
|
617
|
+
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
618
|
+
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
619
|
+
}
|
|
620
|
+
let debugLogStore;
|
|
186
621
|
if (!config.realProofs) {
|
|
187
622
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
623
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
624
|
+
log.info('Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served');
|
|
625
|
+
} else {
|
|
626
|
+
debugLogStore = new NullDebugLogStore();
|
|
627
|
+
}
|
|
628
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
629
|
+
if (proverOnly) {
|
|
630
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
188
631
|
}
|
|
189
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
190
632
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
191
|
-
const p2pClient = await createP2PClient(
|
|
192
|
-
// We
|
|
193
|
-
|
|
194
|
-
|
|
633
|
+
const p2pClient = await createP2PClient(config, archiver, peerProofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
634
|
+
// We'll accumulate sentinel watchers here
|
|
635
|
+
const watchers = [];
|
|
636
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
637
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
638
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
195
639
|
...config,
|
|
196
640
|
l1GenesisTime,
|
|
197
|
-
slotDuration: Number(slotDuration)
|
|
641
|
+
slotDuration: Number(slotDuration),
|
|
642
|
+
rollupManaLimit,
|
|
643
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
|
|
198
644
|
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
645
|
+
let validatorClient;
|
|
646
|
+
if (!proverOnly) {
|
|
647
|
+
// Create validator client if required
|
|
648
|
+
validatorClient = await createValidatorClient(config, {
|
|
649
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
650
|
+
worldState: worldStateSynchronizer,
|
|
651
|
+
p2pClient,
|
|
652
|
+
telemetry,
|
|
653
|
+
dateProvider,
|
|
654
|
+
epochCache,
|
|
655
|
+
blockSource: archiver,
|
|
656
|
+
l1ToL2MessageSource: archiver,
|
|
657
|
+
keyStoreManager,
|
|
658
|
+
blobClient,
|
|
659
|
+
slashingProtectionDb: deps.slashingProtectionDb
|
|
660
|
+
});
|
|
661
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
662
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
663
|
+
// like attestations or auths will fail.
|
|
664
|
+
if (validatorClient) {
|
|
665
|
+
watchers.push(validatorClient);
|
|
666
|
+
const vc = validatorClient;
|
|
667
|
+
const getValidatorAddresses = ()=>vc.getValidatorAddresses().map((a)=>a.toString());
|
|
668
|
+
validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
|
|
669
|
+
if (!options.dontStartSequencer) {
|
|
670
|
+
await validatorClient.registerHandlers();
|
|
671
|
+
}
|
|
219
672
|
}
|
|
220
673
|
}
|
|
221
|
-
// If there's no validator client
|
|
222
|
-
//
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
674
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
675
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
676
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
677
|
+
// Checkpoint proposals rebuild blobs if the blob client can upload blobs.
|
|
678
|
+
if (!validatorClient) {
|
|
679
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
680
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
681
|
+
createProposalHandler(config, {
|
|
682
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
683
|
+
worldState: worldStateSynchronizer,
|
|
227
684
|
epochCache,
|
|
228
685
|
blockSource: archiver,
|
|
229
686
|
l1ToL2MessageSource: archiver,
|
|
230
687
|
p2pClient,
|
|
688
|
+
blobClient,
|
|
231
689
|
dateProvider,
|
|
232
690
|
telemetry
|
|
233
|
-
}).
|
|
691
|
+
}).register(p2pClient, reexecute, archiver);
|
|
234
692
|
}
|
|
235
693
|
// Start world state and wait for it to sync to the archiver.
|
|
236
694
|
await worldStateSynchronizer.start();
|
|
237
695
|
// Start p2p. Note that it depends on world state to be running.
|
|
238
696
|
await p2pClient.start();
|
|
239
|
-
|
|
240
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
241
|
-
watchers.push(validatorsSentinel);
|
|
242
|
-
}
|
|
697
|
+
let validatorsSentinel;
|
|
243
698
|
let epochPruneWatcher;
|
|
244
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
245
|
-
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), blockBuilder, config);
|
|
246
|
-
watchers.push(epochPruneWatcher);
|
|
247
|
-
}
|
|
248
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
249
699
|
let attestationsBlockWatcher;
|
|
250
|
-
if (
|
|
251
|
-
|
|
252
|
-
|
|
700
|
+
if (!proverOnly) {
|
|
701
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
702
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
703
|
+
watchers.push(validatorsSentinel);
|
|
704
|
+
}
|
|
705
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
706
|
+
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
|
|
707
|
+
watchers.push(epochPruneWatcher);
|
|
708
|
+
}
|
|
709
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
710
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
711
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
712
|
+
watchers.push(attestationsBlockWatcher);
|
|
713
|
+
}
|
|
253
714
|
}
|
|
254
715
|
// Start p2p-related services once the archiver has completed sync
|
|
255
716
|
void archiver.waitForInitialSync().then(async ()=>{
|
|
256
|
-
await p2pClient.start();
|
|
257
717
|
await validatorsSentinel?.start();
|
|
258
718
|
await epochPruneWatcher?.start();
|
|
259
719
|
await attestationsBlockWatcher?.start();
|
|
260
720
|
log.info(`All p2p services started`);
|
|
261
721
|
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
722
|
+
const globalVariableBuilderConfig = {
|
|
723
|
+
l1Contracts: config.l1Contracts,
|
|
724
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
725
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
726
|
+
l1GenesisTime,
|
|
727
|
+
slotDuration: Number(slotDuration)
|
|
728
|
+
};
|
|
729
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
730
|
+
const feeProvider = new FeeProviderImpl(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
262
731
|
// Validator enabled, create/start relevant service
|
|
263
732
|
let sequencer;
|
|
264
733
|
let slasherClient;
|
|
265
|
-
if (!config.disableValidator) {
|
|
734
|
+
if (!config.disableValidator && validatorClient) {
|
|
266
735
|
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
267
736
|
// as they are executed when the node is selected as proposer.
|
|
268
737
|
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
269
738
|
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
270
739
|
await slasherClient.start();
|
|
271
|
-
const l1TxUtils = await
|
|
740
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
|
|
272
741
|
...config,
|
|
273
742
|
scope: 'sequencer'
|
|
274
743
|
}, {
|
|
275
744
|
telemetry,
|
|
276
745
|
logger: log.createChild('l1-tx-utils'),
|
|
277
|
-
dateProvider
|
|
746
|
+
dateProvider,
|
|
747
|
+
kzg: Blob.getViemKzgInstance()
|
|
748
|
+
}) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
749
|
+
...config,
|
|
750
|
+
scope: 'sequencer'
|
|
751
|
+
}, {
|
|
752
|
+
telemetry,
|
|
753
|
+
logger: log.createChild('l1-tx-utils'),
|
|
754
|
+
dateProvider,
|
|
755
|
+
kzg: Blob.getViemKzgInstance()
|
|
278
756
|
});
|
|
757
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
758
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
759
|
+
let funderL1TxUtils;
|
|
760
|
+
if (fundingSigner) {
|
|
761
|
+
const [funder] = await createL1TxUtilsFromSigners(publicClient, [
|
|
762
|
+
fundingSigner
|
|
763
|
+
], {
|
|
764
|
+
...config,
|
|
765
|
+
scope: 'sequencer'
|
|
766
|
+
}, {
|
|
767
|
+
telemetry,
|
|
768
|
+
logger: log.createChild('l1-tx-utils:funder'),
|
|
769
|
+
dateProvider
|
|
770
|
+
});
|
|
771
|
+
funderL1TxUtils = funder;
|
|
772
|
+
}
|
|
279
773
|
// Create and start the sequencer client
|
|
774
|
+
const checkpointsBuilder = new CheckpointsBuilder({
|
|
775
|
+
...config,
|
|
776
|
+
l1GenesisTime,
|
|
777
|
+
slotDuration: Number(slotDuration),
|
|
778
|
+
rollupManaLimit
|
|
779
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry, debugLogStore);
|
|
280
780
|
sequencer = await SequencerClient.new(config, {
|
|
281
781
|
...deps,
|
|
282
782
|
epochCache,
|
|
283
783
|
l1TxUtils,
|
|
784
|
+
funderL1TxUtils,
|
|
284
785
|
validatorClient,
|
|
285
786
|
p2pClient,
|
|
286
787
|
worldStateSynchronizer,
|
|
287
788
|
slasherClient,
|
|
288
|
-
|
|
789
|
+
checkpointsBuilder,
|
|
289
790
|
l2BlockSource: archiver,
|
|
290
791
|
l1ToL2MessageSource: archiver,
|
|
291
792
|
telemetry,
|
|
292
793
|
dateProvider,
|
|
293
|
-
|
|
294
|
-
nodeKeyStore: keyStoreManager
|
|
794
|
+
blobClient,
|
|
795
|
+
nodeKeyStore: keyStoreManager,
|
|
796
|
+
globalVariableBuilder
|
|
295
797
|
});
|
|
296
798
|
}
|
|
297
799
|
if (!options.dontStartSequencer && sequencer) {
|
|
@@ -300,7 +802,29 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
300
802
|
} else if (sequencer) {
|
|
301
803
|
log.warn(`Sequencer created but not started`);
|
|
302
804
|
}
|
|
303
|
-
|
|
805
|
+
// Create prover node subsystem if enabled
|
|
806
|
+
let proverNode;
|
|
807
|
+
if (config.enableProverNode) {
|
|
808
|
+
proverNode = await createProverNode(config, {
|
|
809
|
+
...deps.proverNodeDeps,
|
|
810
|
+
telemetry,
|
|
811
|
+
dateProvider,
|
|
812
|
+
archiver,
|
|
813
|
+
worldStateSynchronizer,
|
|
814
|
+
p2pClient,
|
|
815
|
+
epochCache,
|
|
816
|
+
blobClient,
|
|
817
|
+
keyStoreManager
|
|
818
|
+
});
|
|
819
|
+
if (!options.dontStartProverNode) {
|
|
820
|
+
await proverNode.start();
|
|
821
|
+
log.info(`Prover node subsystem started`);
|
|
822
|
+
} else {
|
|
823
|
+
log.info(`Prover node subsystem created but not started`);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
const node = new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, feeProvider, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry, log, blobClient, validatorClient, keyStoreManager, debugLogStore);
|
|
827
|
+
return node;
|
|
304
828
|
}
|
|
305
829
|
/**
|
|
306
830
|
* Returns the sequencer client instance.
|
|
@@ -308,6 +832,9 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
308
832
|
*/ getSequencer() {
|
|
309
833
|
return this.sequencer;
|
|
310
834
|
}
|
|
835
|
+
/** Returns the prover node subsystem, if enabled. */ getProverNode() {
|
|
836
|
+
return this.proverNode;
|
|
837
|
+
}
|
|
311
838
|
getBlockSource() {
|
|
312
839
|
return this.blockSource;
|
|
313
840
|
}
|
|
@@ -327,7 +854,10 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
327
854
|
return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
|
|
328
855
|
}
|
|
329
856
|
async getAllowedPublicSetup() {
|
|
330
|
-
return
|
|
857
|
+
return [
|
|
858
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
859
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
860
|
+
];
|
|
331
861
|
}
|
|
332
862
|
/**
|
|
333
863
|
* Method to determine if the node is ready to accept transactions.
|
|
@@ -350,33 +880,46 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
350
880
|
rollupVersion,
|
|
351
881
|
enr,
|
|
352
882
|
l1ContractAddresses: contractAddresses,
|
|
353
|
-
protocolContractAddresses: protocolContractAddresses
|
|
883
|
+
protocolContractAddresses: protocolContractAddresses,
|
|
884
|
+
realProofs: !!this.config.realProofs
|
|
354
885
|
};
|
|
355
886
|
return nodeInfo;
|
|
356
887
|
}
|
|
357
888
|
/**
|
|
358
|
-
* Get a block specified by its number.
|
|
359
|
-
* @param
|
|
889
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
890
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
360
891
|
* @returns The requested block.
|
|
361
|
-
*/ async getBlock(
|
|
362
|
-
|
|
363
|
-
|
|
892
|
+
*/ async getBlock(block) {
|
|
893
|
+
if (BlockHash.isBlockHash(block)) {
|
|
894
|
+
return this.getBlockByHash(block);
|
|
895
|
+
}
|
|
896
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
897
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
898
|
+
return this.buildInitialBlock();
|
|
899
|
+
}
|
|
900
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
364
901
|
}
|
|
365
902
|
/**
|
|
366
903
|
* Get a block specified by its hash.
|
|
367
904
|
* @param blockHash - The block hash being requested.
|
|
368
905
|
* @returns The requested block.
|
|
369
906
|
*/ async getBlockByHash(blockHash) {
|
|
370
|
-
const
|
|
371
|
-
|
|
907
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
908
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
909
|
+
return this.buildInitialBlock();
|
|
910
|
+
}
|
|
911
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
912
|
+
}
|
|
913
|
+
buildInitialBlock() {
|
|
914
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
915
|
+
return L2Block.empty(initialHeader);
|
|
372
916
|
}
|
|
373
917
|
/**
|
|
374
918
|
* Get a block specified by its archive root.
|
|
375
919
|
* @param archive - The archive root being requested.
|
|
376
920
|
* @returns The requested block.
|
|
377
921
|
*/ async getBlockByArchive(archive) {
|
|
378
|
-
|
|
379
|
-
return publishedBlock?.block;
|
|
922
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
380
923
|
}
|
|
381
924
|
/**
|
|
382
925
|
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
|
|
@@ -384,16 +927,31 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
384
927
|
* @param limit - The maximum number of blocks to obtain.
|
|
385
928
|
* @returns The blocks requested.
|
|
386
929
|
*/ async getBlocks(from, limit) {
|
|
387
|
-
return await this.blockSource.getBlocks(from, limit) ?? [];
|
|
930
|
+
return await this.blockSource.getBlocks(from, BlockNumber(limit)) ?? [];
|
|
388
931
|
}
|
|
389
|
-
async
|
|
390
|
-
return await this.blockSource.
|
|
932
|
+
async getCheckpoints(from, limit) {
|
|
933
|
+
return await this.blockSource.getCheckpoints(from, limit) ?? [];
|
|
391
934
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
return
|
|
935
|
+
async getCheckpointedBlocks(from, limit) {
|
|
936
|
+
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
937
|
+
}
|
|
938
|
+
getCheckpointsDataForEpoch(epochNumber) {
|
|
939
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
940
|
+
}
|
|
941
|
+
async getCurrentMinFees() {
|
|
942
|
+
return await this.feeProvider.getCurrentMinFees();
|
|
943
|
+
}
|
|
944
|
+
/** Returns predicted min fees for the current slot and next N slots. */ async getPredictedMinFees(manaUsage) {
|
|
945
|
+
return await this.feeProvider.getPredictedMinFees(manaUsage);
|
|
946
|
+
}
|
|
947
|
+
async getMaxPriorityFees() {
|
|
948
|
+
for await (const tx of this.p2pClient.iteratePendingTxs()){
|
|
949
|
+
return tx.getGasSettings().maxPriorityFeesPerGas;
|
|
950
|
+
}
|
|
951
|
+
return GasFees.from({
|
|
952
|
+
feePerDaGas: 0n,
|
|
953
|
+
feePerL2Gas: 0n
|
|
954
|
+
});
|
|
397
955
|
}
|
|
398
956
|
/**
|
|
399
957
|
* Method to fetch the latest block number synchronized by the node.
|
|
@@ -404,6 +962,12 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
404
962
|
async getProvenBlockNumber() {
|
|
405
963
|
return await this.blockSource.getProvenBlockNumber();
|
|
406
964
|
}
|
|
965
|
+
async getCheckpointedBlockNumber() {
|
|
966
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
967
|
+
}
|
|
968
|
+
getCheckpointNumber() {
|
|
969
|
+
return this.blockSource.getCheckpointNumber();
|
|
970
|
+
}
|
|
407
971
|
/**
|
|
408
972
|
* Method to fetch the version of the package.
|
|
409
973
|
* @returns The node package version
|
|
@@ -428,22 +992,37 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
428
992
|
getContract(address) {
|
|
429
993
|
return this.contractDataSource.getContract(address);
|
|
430
994
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
995
|
+
async getPrivateLogsByTags(tags, page, referenceBlock) {
|
|
996
|
+
let upToBlockNumber;
|
|
997
|
+
if (referenceBlock) {
|
|
998
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
999
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1000
|
+
upToBlockNumber = BlockNumber(0);
|
|
1001
|
+
} else {
|
|
1002
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
1003
|
+
if (!header) {
|
|
1004
|
+
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
1005
|
+
}
|
|
1006
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
1010
|
+
}
|
|
1011
|
+
async getPublicLogsByTagsFromContract(contractAddress, tags, page, referenceBlock) {
|
|
1012
|
+
let upToBlockNumber;
|
|
1013
|
+
if (referenceBlock) {
|
|
1014
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1015
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1016
|
+
upToBlockNumber = BlockNumber(0);
|
|
1017
|
+
} else {
|
|
1018
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
1019
|
+
if (!header) {
|
|
1020
|
+
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
1021
|
+
}
|
|
1022
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
447
1026
|
}
|
|
448
1027
|
/**
|
|
449
1028
|
* Gets public logs based on the provided filter.
|
|
@@ -478,24 +1057,33 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
478
1057
|
throw new Error(`Invalid tx: ${reason}`);
|
|
479
1058
|
}
|
|
480
1059
|
await this.p2pClient.sendTx(tx);
|
|
481
|
-
|
|
482
|
-
this.
|
|
1060
|
+
const duration = timer.ms();
|
|
1061
|
+
this.metrics.receivedTx(duration, true);
|
|
1062
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, {
|
|
483
1063
|
txHash
|
|
484
1064
|
});
|
|
485
1065
|
}
|
|
486
1066
|
async getTxReceipt(txHash) {
|
|
487
|
-
|
|
488
|
-
//
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
493
|
-
}
|
|
1067
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
1068
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
1069
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
1070
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
1071
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
494
1072
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
1073
|
+
let receipt;
|
|
495
1074
|
if (settledTxReceipt) {
|
|
496
|
-
|
|
1075
|
+
receipt = settledTxReceipt;
|
|
1076
|
+
} else if (isKnownToPool) {
|
|
1077
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
1078
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
1079
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
1080
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
1081
|
+
} else {
|
|
1082
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
1083
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
497
1084
|
}
|
|
498
|
-
|
|
1085
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
1086
|
+
return receipt;
|
|
499
1087
|
}
|
|
500
1088
|
getTxEffect(txHash) {
|
|
501
1089
|
return this.blockSource.getTxEffect(txHash);
|
|
@@ -507,15 +1095,26 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
507
1095
|
await tryStop(this.validatorsSentinel);
|
|
508
1096
|
await tryStop(this.epochPruneWatcher);
|
|
509
1097
|
await tryStop(this.slasherClient);
|
|
510
|
-
await
|
|
1098
|
+
await Promise.all([
|
|
1099
|
+
tryStop(this.peerProofVerifier),
|
|
1100
|
+
tryStop(this.rpcProofVerifier)
|
|
1101
|
+
]);
|
|
511
1102
|
await tryStop(this.sequencer);
|
|
1103
|
+
await tryStop(this.proverNode);
|
|
512
1104
|
await tryStop(this.p2pClient);
|
|
513
1105
|
await tryStop(this.worldStateSynchronizer);
|
|
514
1106
|
await tryStop(this.blockSource);
|
|
1107
|
+
await tryStop(this.blobClient);
|
|
515
1108
|
await tryStop(this.telemetry);
|
|
516
1109
|
this.log.info(`Stopped Aztec Node`);
|
|
517
1110
|
}
|
|
518
1111
|
/**
|
|
1112
|
+
* Returns the blob client used by this node.
|
|
1113
|
+
* @internal - Exposed for testing purposes only.
|
|
1114
|
+
*/ getBlobClient() {
|
|
1115
|
+
return this.blobClient;
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
519
1118
|
* Method to retrieve pending txs.
|
|
520
1119
|
* @param limit - The number of items to returns
|
|
521
1120
|
* @param after - The last known pending tx. Used for pagination
|
|
@@ -540,101 +1139,83 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
540
1139
|
*/ async getTxsByHash(txHashes) {
|
|
541
1140
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
542
1141
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
* the leaves were inserted.
|
|
546
|
-
* @param blockNumber - The block number at which to get the data or 'latest' for latest data.
|
|
547
|
-
* @param treeId - The tree to search in.
|
|
548
|
-
* @param leafValues - The values to search for.
|
|
549
|
-
* @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
|
|
550
|
-
*/ async findLeavesIndexes(blockNumber, treeId, leafValues) {
|
|
551
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1142
|
+
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
1143
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
552
1144
|
const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
|
|
553
|
-
//
|
|
554
|
-
const
|
|
555
|
-
// Now we find the block numbers for the indices
|
|
556
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
557
|
-
//
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
1145
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
1146
|
+
const definedIndices = maybeIndices.filter((x)=>x !== undefined);
|
|
1147
|
+
// Now we find the block numbers for the defined indices
|
|
1148
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
1149
|
+
// Build a map from leaf index to block number
|
|
1150
|
+
const indexToBlockNumber = new Map();
|
|
1151
|
+
for(let i = 0; i < definedIndices.length; i++){
|
|
1152
|
+
const blockNumber = blockNumbers[i];
|
|
1153
|
+
if (blockNumber === undefined) {
|
|
1154
|
+
throw new Error(`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`);
|
|
561
1155
|
}
|
|
1156
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
562
1157
|
}
|
|
563
1158
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
564
1159
|
const uniqueBlockNumbers = [
|
|
565
|
-
...new Set(
|
|
1160
|
+
...new Set(indexToBlockNumber.values())
|
|
566
1161
|
];
|
|
567
|
-
// Now we obtain the block hashes from the archive tree
|
|
568
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1162
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
569
1163
|
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
570
|
-
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, blockNumber);
|
|
1164
|
+
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
571
1165
|
}));
|
|
572
|
-
//
|
|
1166
|
+
// Build a map from block number to block hash
|
|
1167
|
+
const blockNumberToHash = new Map();
|
|
573
1168
|
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
574
|
-
|
|
1169
|
+
const blockHash = blockHashes[i];
|
|
1170
|
+
if (blockHash === undefined) {
|
|
575
1171
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
576
1172
|
}
|
|
1173
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
577
1174
|
}
|
|
578
|
-
// Create
|
|
579
|
-
return maybeIndices.map((index
|
|
1175
|
+
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1176
|
+
return maybeIndices.map((index)=>{
|
|
580
1177
|
if (index === undefined) {
|
|
581
1178
|
return undefined;
|
|
582
1179
|
}
|
|
583
|
-
const blockNumber =
|
|
1180
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
584
1181
|
if (blockNumber === undefined) {
|
|
585
|
-
|
|
1182
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
586
1183
|
}
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
return undefined;
|
|
1184
|
+
const l2BlockHash = blockNumberToHash.get(blockNumber);
|
|
1185
|
+
if (l2BlockHash === undefined) {
|
|
1186
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
591
1187
|
}
|
|
592
1188
|
return {
|
|
593
|
-
l2BlockNumber:
|
|
594
|
-
l2BlockHash
|
|
1189
|
+
l2BlockNumber: blockNumber,
|
|
1190
|
+
l2BlockHash,
|
|
595
1191
|
data: index
|
|
596
1192
|
};
|
|
597
1193
|
});
|
|
598
1194
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
* Returns a sibling path for the given index in the data tree.
|
|
610
|
-
* @param blockNumber - The block number at which to get the data.
|
|
611
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
612
|
-
* @returns The sibling path for the leaf index.
|
|
613
|
-
*/ async getNoteHashSiblingPath(blockNumber, leafIndex) {
|
|
614
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
615
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
616
|
-
}
|
|
617
|
-
async getArchiveMembershipWitness(blockNumber, archive) {
|
|
618
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1195
|
+
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
1196
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1197
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1198
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1199
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1200
|
+
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
1201
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1202
|
+
return undefined;
|
|
1203
|
+
}
|
|
1204
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
619
1205
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
620
|
-
|
|
1206
|
+
blockHash
|
|
621
1207
|
]);
|
|
622
1208
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
623
1209
|
}
|
|
624
|
-
async getNoteHashMembershipWitness(
|
|
625
|
-
const committedDb = await this
|
|
1210
|
+
async getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
1211
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
626
1212
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
627
1213
|
noteHash
|
|
628
1214
|
]);
|
|
629
1215
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
630
1216
|
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
* @param blockNumber - The block number at which to get the data.
|
|
634
|
-
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
|
|
635
|
-
* @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
|
|
636
|
-
*/ async getL1ToL2MessageMembershipWitness(blockNumber, l1ToL2Message) {
|
|
637
|
-
const db = await this.#getWorldState(blockNumber);
|
|
1217
|
+
async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
1218
|
+
const db = await this.getWorldState(referenceBlock);
|
|
638
1219
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
639
1220
|
l1ToL2Message
|
|
640
1221
|
]);
|
|
@@ -647,9 +1228,9 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
647
1228
|
witness.path
|
|
648
1229
|
];
|
|
649
1230
|
}
|
|
650
|
-
async
|
|
1231
|
+
async getL1ToL2MessageCheckpoint(l1ToL2Message) {
|
|
651
1232
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
652
|
-
return messageIndex ? InboxLeaf.
|
|
1233
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
653
1234
|
}
|
|
654
1235
|
/**
|
|
655
1236
|
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
@@ -660,38 +1241,17 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
660
1241
|
return messageIndex !== undefined;
|
|
661
1242
|
}
|
|
662
1243
|
/**
|
|
663
|
-
* Returns all the L2 to L1 messages in
|
|
664
|
-
* @param
|
|
665
|
-
* @returns The L2 to L1 messages (
|
|
666
|
-
*/ async getL2ToL1Messages(
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
* @returns The sibling path.
|
|
675
|
-
*/ async getArchiveSiblingPath(blockNumber, leafIndex) {
|
|
676
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
677
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
678
|
-
}
|
|
679
|
-
/**
|
|
680
|
-
* Returns a sibling path for a leaf in the committed public data tree.
|
|
681
|
-
* @param blockNumber - The block number at which to get the data.
|
|
682
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
683
|
-
* @returns The sibling path.
|
|
684
|
-
*/ async getPublicDataSiblingPath(blockNumber, leafIndex) {
|
|
685
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
686
|
-
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
687
|
-
}
|
|
688
|
-
/**
|
|
689
|
-
* Returns a nullifier membership witness for a given nullifier at a given block.
|
|
690
|
-
* @param blockNumber - The block number at which to get the index.
|
|
691
|
-
* @param nullifier - Nullifier we try to find witness for.
|
|
692
|
-
* @returns The nullifier membership witness (if found).
|
|
693
|
-
*/ async getNullifierMembershipWitness(blockNumber, nullifier) {
|
|
694
|
-
const db = await this.#getWorldState(blockNumber);
|
|
1244
|
+
* Returns all the L2 to L1 messages in an epoch.
|
|
1245
|
+
* @param epoch - The epoch at which to get the data.
|
|
1246
|
+
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
1247
|
+
*/ async getL2ToL1Messages(epoch) {
|
|
1248
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1249
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1250
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, (cb)=>cb.block.header.globalVariables.slotNumber).map((group)=>group.map((cb)=>cb.block));
|
|
1251
|
+
return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
1252
|
+
}
|
|
1253
|
+
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1254
|
+
const db = await this.getWorldState(referenceBlock);
|
|
695
1255
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
696
1256
|
nullifier.toBuffer()
|
|
697
1257
|
]);
|
|
@@ -705,35 +1265,22 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
705
1265
|
}
|
|
706
1266
|
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
707
1267
|
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
* @param blockNumber - The block number at which to get the index.
|
|
711
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
712
|
-
* @returns The low nullifier membership witness (if found).
|
|
713
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
714
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
715
|
-
* we are trying to prove non-inclusion for.
|
|
716
|
-
*
|
|
717
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
718
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
719
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
720
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
721
|
-
*/ async getLowNullifierMembershipWitness(blockNumber, nullifier) {
|
|
722
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1268
|
+
async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1269
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
723
1270
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
724
1271
|
if (!findResult) {
|
|
725
1272
|
return undefined;
|
|
726
1273
|
}
|
|
727
1274
|
const { index, alreadyPresent } = findResult;
|
|
728
1275
|
if (alreadyPresent) {
|
|
729
|
-
|
|
1276
|
+
throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
730
1277
|
}
|
|
731
1278
|
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
732
1279
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
733
1280
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
734
1281
|
}
|
|
735
|
-
async getPublicDataWitness(
|
|
736
|
-
const committedDb = await this
|
|
1282
|
+
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1283
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
737
1284
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
738
1285
|
if (!lowLeafResult) {
|
|
739
1286
|
return undefined;
|
|
@@ -743,18 +1290,8 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
743
1290
|
return new PublicDataWitness(lowLeafResult.index, preimage, path);
|
|
744
1291
|
}
|
|
745
1292
|
}
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
*
|
|
749
|
-
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
|
|
750
|
-
* Aztec's version of `eth_getStorageAt`.
|
|
751
|
-
*
|
|
752
|
-
* @param contract - Address of the contract to query.
|
|
753
|
-
* @param slot - Slot to query.
|
|
754
|
-
* @param blockNumber - The block number at which to get the data or 'latest'.
|
|
755
|
-
* @returns Storage value at the given contract slot.
|
|
756
|
-
*/ async getPublicStorageAt(blockNumber, contract, slot) {
|
|
757
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1293
|
+
async getPublicStorageAt(referenceBlock, contract, slot) {
|
|
1294
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
758
1295
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
759
1296
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
760
1297
|
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
@@ -763,18 +1300,22 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
763
1300
|
const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
764
1301
|
return preimage.leaf.value;
|
|
765
1302
|
}
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
1303
|
+
async getBlockHeader(block = 'latest') {
|
|
1304
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1305
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1306
|
+
if (block.equals(initialBlockHash)) {
|
|
1307
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1308
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1309
|
+
}
|
|
1310
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1311
|
+
} else {
|
|
1312
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1313
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
1314
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1315
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1316
|
+
}
|
|
1317
|
+
return this.blockSource.getBlockHeader(block);
|
|
1318
|
+
}
|
|
778
1319
|
}
|
|
779
1320
|
/**
|
|
780
1321
|
* Get a block header specified by its archive root.
|
|
@@ -783,6 +1324,12 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
783
1324
|
*/ async getBlockHeaderByArchive(archive) {
|
|
784
1325
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
785
1326
|
}
|
|
1327
|
+
getBlockData(number) {
|
|
1328
|
+
return this.blockSource.getBlockData(number);
|
|
1329
|
+
}
|
|
1330
|
+
getBlockDataByArchive(archive) {
|
|
1331
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1332
|
+
}
|
|
786
1333
|
/**
|
|
787
1334
|
* Simulates the public part of a transaction with the current state.
|
|
788
1335
|
* @param tx - The transaction to simulate.
|
|
@@ -795,17 +1342,20 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
795
1342
|
throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
|
|
796
1343
|
}
|
|
797
1344
|
const txHash = tx.getTxHash();
|
|
798
|
-
const
|
|
1345
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1346
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
799
1347
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
800
1348
|
const coinbase = EthAddress.ZERO;
|
|
801
1349
|
const feeRecipient = AztecAddress.ZERO;
|
|
802
1350
|
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(blockNumber, coinbase, feeRecipient);
|
|
803
|
-
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry);
|
|
1351
|
+
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry, this.log.getBindings());
|
|
804
1352
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
805
1353
|
globalVariables: newGlobalVariables.toInspect(),
|
|
806
1354
|
txHash,
|
|
807
1355
|
blockNumber
|
|
808
1356
|
});
|
|
1357
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1358
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
809
1359
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
810
1360
|
try {
|
|
811
1361
|
const config = PublicSimulatorConfig.from({
|
|
@@ -813,12 +1363,14 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
813
1363
|
collectDebugLogs: true,
|
|
814
1364
|
collectHints: false,
|
|
815
1365
|
collectCallMetadata: true,
|
|
816
|
-
|
|
817
|
-
|
|
1366
|
+
collectStatistics: false,
|
|
1367
|
+
collectionLimits: CollectionLimitsConfig.from({
|
|
1368
|
+
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads
|
|
1369
|
+
})
|
|
818
1370
|
});
|
|
819
1371
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
820
1372
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
821
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
|
|
1373
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([
|
|
822
1374
|
tx
|
|
823
1375
|
]);
|
|
824
1376
|
// REFACTOR: Consider returning the error rather than throwing
|
|
@@ -829,27 +1381,34 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
829
1381
|
throw failedTxs[0].error;
|
|
830
1382
|
}
|
|
831
1383
|
const [processedTx] = processedTxs;
|
|
832
|
-
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed);
|
|
1384
|
+
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed, debugLogs);
|
|
833
1385
|
} finally{
|
|
834
1386
|
await merkleTreeFork.close();
|
|
835
1387
|
}
|
|
836
1388
|
}
|
|
837
1389
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
838
1390
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
839
|
-
const verifier = isSimulation ? undefined : this.
|
|
840
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1391
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1392
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
841
1393
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
842
|
-
const blockNumber = await this.blockSource.getBlockNumber() + 1;
|
|
843
|
-
const
|
|
1394
|
+
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1395
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1396
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
|
|
844
1397
|
timestamp: nextSlotTimestamp,
|
|
845
1398
|
blockNumber,
|
|
846
1399
|
l1ChainId: this.l1ChainId,
|
|
847
1400
|
rollupVersion: this.version,
|
|
848
|
-
setupAllowList:
|
|
849
|
-
|
|
1401
|
+
setupAllowList: [
|
|
1402
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1403
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1404
|
+
],
|
|
1405
|
+
gasFees: await this.getCurrentMinFees(),
|
|
850
1406
|
skipFeeEnforcement,
|
|
851
|
-
txsPermitted: !this.config.disableTransactions
|
|
852
|
-
|
|
1407
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1408
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1409
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1410
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
1411
|
+
}, this.log.getBindings());
|
|
853
1412
|
return await validator.validateTx(tx);
|
|
854
1413
|
}
|
|
855
1414
|
getConfig() {
|
|
@@ -871,7 +1430,18 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
871
1430
|
archiver.updateConfig(config);
|
|
872
1431
|
}
|
|
873
1432
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
874
|
-
|
|
1433
|
+
await Promise.all([
|
|
1434
|
+
tryStop(this.peerProofVerifier),
|
|
1435
|
+
tryStop(this.rpcProofVerifier)
|
|
1436
|
+
]);
|
|
1437
|
+
if (newConfig.realProofs) {
|
|
1438
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1439
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1440
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1441
|
+
} else {
|
|
1442
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1443
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1444
|
+
}
|
|
875
1445
|
}
|
|
876
1446
|
this.config = newConfig;
|
|
877
1447
|
}
|
|
@@ -909,7 +1479,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
909
1479
|
throw new Error(`Archiver initial sync not complete. Cannot start snapshot.`);
|
|
910
1480
|
}
|
|
911
1481
|
// And it has an L2 block hash
|
|
912
|
-
const l2BlockHash = await archiver.getL2Tips().then((tips)=>tips.
|
|
1482
|
+
const l2BlockHash = await archiver.getL2Tips().then((tips)=>tips.proposed.hash);
|
|
913
1483
|
if (!l2BlockHash) {
|
|
914
1484
|
this.metrics.recordSnapshotError();
|
|
915
1485
|
throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
|
|
@@ -931,12 +1501,12 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
931
1501
|
});
|
|
932
1502
|
return Promise.resolve();
|
|
933
1503
|
}
|
|
934
|
-
async rollbackTo(targetBlock, force) {
|
|
1504
|
+
async rollbackTo(targetBlock, force, resumeSync = true) {
|
|
935
1505
|
const archiver = this.blockSource;
|
|
936
1506
|
if (!('rollbackTo' in archiver)) {
|
|
937
1507
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
938
1508
|
}
|
|
939
|
-
const finalizedBlock = await archiver.getL2Tips().then((tips)=>tips.finalized.number);
|
|
1509
|
+
const finalizedBlock = await archiver.getL2Tips().then((tips)=>tips.finalized.block.number);
|
|
940
1510
|
if (targetBlock < finalizedBlock) {
|
|
941
1511
|
if (force) {
|
|
942
1512
|
this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
|
|
@@ -959,9 +1529,13 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
959
1529
|
this.log.error(`Error during rollback`, err);
|
|
960
1530
|
throw err;
|
|
961
1531
|
} finally{
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
1532
|
+
if (resumeSync) {
|
|
1533
|
+
this.log.info(`Resuming world state and archiver sync.`);
|
|
1534
|
+
this.worldStateSynchronizer.resumeSync();
|
|
1535
|
+
archiver.resume();
|
|
1536
|
+
} else {
|
|
1537
|
+
this.log.info(`Sync left paused after rollback (resumeSync=false).`);
|
|
1538
|
+
}
|
|
965
1539
|
}
|
|
966
1540
|
}
|
|
967
1541
|
async pauseSync() {
|
|
@@ -975,58 +1549,185 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
975
1549
|
this.blockSource.resume();
|
|
976
1550
|
return Promise.resolve();
|
|
977
1551
|
}
|
|
978
|
-
getSlashPayloads() {
|
|
979
|
-
if (!this.slasherClient) {
|
|
980
|
-
throw new Error(`Slasher client not enabled`);
|
|
981
|
-
}
|
|
982
|
-
return this.slasherClient.getSlashPayloads();
|
|
983
|
-
}
|
|
984
1552
|
getSlashOffenses(round) {
|
|
985
1553
|
if (!this.slasherClient) {
|
|
986
1554
|
throw new Error(`Slasher client not enabled`);
|
|
987
1555
|
}
|
|
988
1556
|
if (round === 'all') {
|
|
989
|
-
return this.slasherClient.
|
|
1557
|
+
return this.slasherClient.getOffenses();
|
|
990
1558
|
} else {
|
|
991
1559
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
992
1560
|
}
|
|
993
1561
|
}
|
|
1562
|
+
async reloadKeystore() {
|
|
1563
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1564
|
+
throw new BadRequestError('Cannot reload keystore: node is not using a file-based keystore. ' + 'Set KEY_STORE_DIRECTORY to use file-based keystores.');
|
|
1565
|
+
}
|
|
1566
|
+
if (!this.validatorClient) {
|
|
1567
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1568
|
+
}
|
|
1569
|
+
this.log.info('Reloading keystore from disk');
|
|
1570
|
+
// Re-read and validate keystore files
|
|
1571
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1572
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1573
|
+
await newManager.validateSigners();
|
|
1574
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1575
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1576
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1577
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1578
|
+
// would silently fail on every proposer slot.
|
|
1579
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1580
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1581
|
+
const availablePublishers = new Set(oldAdapter.getAttesterAddresses().flatMap((a)=>oldAdapter.getPublisherAddresses(a).map((p)=>p.toString().toLowerCase())));
|
|
1582
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1583
|
+
for (const attester of newAdapter.getAttesterAddresses()){
|
|
1584
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1585
|
+
if (pubs.length > 0 && !pubs.some((p)=>availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1586
|
+
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 ` + `[${[
|
|
1587
|
+
...availablePublishers
|
|
1588
|
+
].join(', ')}]. Publishers cannot be hot-reloaded — ` + `use an existing publisher key or restart the node.`);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
// Build adapters for old and new keystores to compute diff
|
|
1593
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1594
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1595
|
+
const oldAddresses = this.keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses() : [];
|
|
1596
|
+
const oldSet = new Set(oldAddresses.map((a)=>a.toString()));
|
|
1597
|
+
const newSet = new Set(newAddresses.map((a)=>a.toString()));
|
|
1598
|
+
const added = newAddresses.filter((a)=>!oldSet.has(a.toString()));
|
|
1599
|
+
const removed = oldAddresses.filter((a)=>!newSet.has(a.toString()));
|
|
1600
|
+
if (added.length > 0) {
|
|
1601
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map((a)=>a.toString()).join(', ')}`);
|
|
1602
|
+
}
|
|
1603
|
+
if (removed.length > 0) {
|
|
1604
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map((a)=>a.toString()).join(', ')}`);
|
|
1605
|
+
}
|
|
1606
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1607
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1608
|
+
}
|
|
1609
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1610
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1611
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1612
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1613
|
+
if (this.sequencer) {
|
|
1614
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1615
|
+
}
|
|
1616
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1617
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1618
|
+
const slashValidatorsNever = unique([
|
|
1619
|
+
...this.config.slashValidatorsNever ?? [],
|
|
1620
|
+
...newAddresses
|
|
1621
|
+
].map((a)=>a.toString())).map(EthAddress.fromString);
|
|
1622
|
+
this.slasherClient.updateConfig({
|
|
1623
|
+
slashValidatorsNever
|
|
1624
|
+
});
|
|
1625
|
+
}
|
|
1626
|
+
this.keyStoreManager = newManager;
|
|
1627
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1628
|
+
}
|
|
1629
|
+
async mineBlock() {
|
|
1630
|
+
if (!this.sequencer) {
|
|
1631
|
+
throw new BadRequestError('Cannot mine block: no sequencer is running');
|
|
1632
|
+
}
|
|
1633
|
+
const currentBlockNumber = await this.getBlockNumber();
|
|
1634
|
+
// Use slot duration + 50% buffer as the timeout so this works on running networks too
|
|
1635
|
+
const { slotDuration } = await this.blockSource.getL1Constants();
|
|
1636
|
+
const timeoutSeconds = Math.ceil(slotDuration * 1.5);
|
|
1637
|
+
// Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
|
|
1638
|
+
const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
|
|
1639
|
+
this.sequencer.updateConfig({
|
|
1640
|
+
minTxsPerBlock: 0
|
|
1641
|
+
});
|
|
1642
|
+
try {
|
|
1643
|
+
// Trigger the sequencer to produce a block immediately
|
|
1644
|
+
void this.sequencer.trigger();
|
|
1645
|
+
// Wait for the new L2 block to appear
|
|
1646
|
+
await retryUntil(async ()=>{
|
|
1647
|
+
const newBlockNumber = await this.getBlockNumber();
|
|
1648
|
+
return newBlockNumber > currentBlockNumber ? true : undefined;
|
|
1649
|
+
}, 'mineBlock', timeoutSeconds, 0.1);
|
|
1650
|
+
} finally{
|
|
1651
|
+
this.sequencer.updateConfig({
|
|
1652
|
+
minTxsPerBlock: originalMinTxsPerBlock
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
#getInitialHeaderHash() {
|
|
1657
|
+
if (!this.initialHeaderHashPromise) {
|
|
1658
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1659
|
+
}
|
|
1660
|
+
return this.initialHeaderHashPromise;
|
|
1661
|
+
}
|
|
994
1662
|
/**
|
|
995
1663
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
996
|
-
* @param
|
|
1664
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
997
1665
|
* @returns An instance of a committed MerkleTreeOperations
|
|
998
|
-
*/ async
|
|
999
|
-
|
|
1000
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
1001
|
-
}
|
|
1002
|
-
let blockSyncedTo = 0;
|
|
1666
|
+
*/ async getWorldState(block) {
|
|
1667
|
+
let blockSyncedTo = BlockNumber.ZERO;
|
|
1003
1668
|
try {
|
|
1004
1669
|
// Attempt to sync the world state if necessary
|
|
1005
1670
|
blockSyncedTo = await this.#syncWorldState();
|
|
1006
1671
|
} catch (err) {
|
|
1007
1672
|
this.log.error(`Error getting world state: ${err}`);
|
|
1008
1673
|
}
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1674
|
+
if (block === 'latest') {
|
|
1675
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1012
1676
|
return this.worldStateSynchronizer.getCommitted();
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
|
|
1677
|
+
}
|
|
1678
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1679
|
+
let blockNumber;
|
|
1680
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1681
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1682
|
+
if (block.equals(initialBlockHash)) {
|
|
1683
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1684
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1685
|
+
}
|
|
1686
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1687
|
+
if (!header) {
|
|
1688
|
+
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.`);
|
|
1689
|
+
}
|
|
1690
|
+
blockNumber = header.getBlockNumber();
|
|
1016
1691
|
} else {
|
|
1017
|
-
|
|
1692
|
+
blockNumber = block;
|
|
1693
|
+
}
|
|
1694
|
+
// Check it's within world state sync range
|
|
1695
|
+
if (blockNumber > blockSyncedTo) {
|
|
1696
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1697
|
+
}
|
|
1698
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1699
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1700
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1701
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1702
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1703
|
+
if (!blockHash || !block.equals(blockHash)) {
|
|
1704
|
+
throw new Error(`Block hash ${block.toString()} not found in world state at block number ${blockNumber}. If the node API has been queried with anchor block hash possibly a reorg has occurred.`);
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
return snapshot;
|
|
1708
|
+
}
|
|
1709
|
+
/** Resolves a block parameter to a block number. */ async resolveBlockNumber(block) {
|
|
1710
|
+
if (block === 'latest') {
|
|
1711
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1712
|
+
}
|
|
1713
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1714
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1715
|
+
if (block.equals(initialBlockHash)) {
|
|
1716
|
+
return BlockNumber.ZERO;
|
|
1717
|
+
}
|
|
1718
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1719
|
+
if (!header) {
|
|
1720
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1721
|
+
}
|
|
1722
|
+
return header.getBlockNumber();
|
|
1018
1723
|
}
|
|
1724
|
+
return block;
|
|
1019
1725
|
}
|
|
1020
1726
|
/**
|
|
1021
1727
|
* Ensure we fully sync the world state
|
|
1022
1728
|
* @returns A promise that fulfils once the world state is synced
|
|
1023
1729
|
*/ async #syncWorldState() {
|
|
1024
1730
|
const blockSourceHeight = await this.blockSource.getBlockNumber();
|
|
1025
|
-
return this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1731
|
+
return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1026
1732
|
}
|
|
1027
1733
|
}
|
|
1028
|
-
_ts_decorate([
|
|
1029
|
-
trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
1030
|
-
[Attributes.TX_HASH]: tx.getTxHash().toString()
|
|
1031
|
-
}))
|
|
1032
|
-
], AztecNodeService.prototype, "simulatePublicCalls", null);
|