@aztec/aztec-node 0.0.1-commit.5476d83 → 0.0.1-commit.5914bae
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 +11 -5
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +17 -3
- 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 +78 -138
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +941 -302
- package/dest/sentinel/factory.d.ts +1 -1
- 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 +85 -54
- 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 +30 -28
- package/src/aztec-node/config.ts +34 -14
- package/src/aztec-node/node_metrics.ts +6 -17
- package/src/aztec-node/server.ts +703 -379
- package/src/sentinel/factory.ts +1 -6
- package/src/sentinel/sentinel.ts +97 -55
- package/src/sentinel/store.ts +12 -12
|
@@ -1,50 +1,426 @@
|
|
|
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
375
|
import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
376
|
+
import { createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
377
|
+
import { Blob } from '@aztec/blob-lib';
|
|
11
378
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
379
|
+
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
380
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
381
|
+
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
382
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
383
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
384
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
14
385
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
15
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
16
386
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
17
387
|
import { createLogger } from '@aztec/foundation/log';
|
|
388
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
18
389
|
import { count } from '@aztec/foundation/string';
|
|
19
390
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
20
391
|
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
21
392
|
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
22
393
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
23
|
-
import {
|
|
24
|
-
import { createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
394
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
395
|
+
import { createP2PClient, createTxValidatorForAcceptingTxsOverRPC, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
25
396
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
26
|
-
import {
|
|
397
|
+
import { createProverNode } from '@aztec/prover-node';
|
|
398
|
+
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
399
|
+
import { GlobalVariableBuilder, SequencerClient } from '@aztec/sequencer-client';
|
|
27
400
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
28
401
|
import { AttestationsBlockWatcher, EpochPruneWatcher, createSlasher } from '@aztec/slasher';
|
|
29
|
-
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
402
|
+
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
30
403
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
31
|
-
import {
|
|
404
|
+
import { BlockHash, L2Block } from '@aztec/stdlib/block';
|
|
32
405
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
33
406
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
34
407
|
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
35
408
|
import { tryStop } from '@aztec/stdlib/interfaces/server';
|
|
409
|
+
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
36
410
|
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
37
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
38
411
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
39
412
|
import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
40
413
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
41
414
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
42
|
-
import { NodeKeystoreAdapter, ValidatorClient,
|
|
415
|
+
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createProposalHandler, createValidatorClient } from '@aztec/validator-client';
|
|
43
416
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
44
|
-
import { createPublicClient
|
|
417
|
+
import { createPublicClient } from 'viem';
|
|
45
418
|
import { createSentinel } from '../sentinel/factory.js';
|
|
46
419
|
import { createKeyStoreForValidator } from './config.js';
|
|
47
420
|
import { NodeMetrics } from './node_metrics.js';
|
|
421
|
+
_dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
422
|
+
[Attributes.TX_HASH]: tx.getTxHash().toString()
|
|
423
|
+
}));
|
|
48
424
|
/**
|
|
49
425
|
* The aztec node.
|
|
50
426
|
*/ export class AztecNodeService {
|
|
@@ -56,6 +432,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
56
432
|
l1ToL2MessageSource;
|
|
57
433
|
worldStateSynchronizer;
|
|
58
434
|
sequencer;
|
|
435
|
+
proverNode;
|
|
59
436
|
slasherClient;
|
|
60
437
|
validatorsSentinel;
|
|
61
438
|
epochPruneWatcher;
|
|
@@ -67,11 +444,25 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
67
444
|
proofVerifier;
|
|
68
445
|
telemetry;
|
|
69
446
|
log;
|
|
447
|
+
blobClient;
|
|
448
|
+
validatorClient;
|
|
449
|
+
keyStoreManager;
|
|
450
|
+
debugLogStore;
|
|
451
|
+
static{
|
|
452
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
453
|
+
[
|
|
454
|
+
_dec,
|
|
455
|
+
2,
|
|
456
|
+
"simulatePublicCalls"
|
|
457
|
+
]
|
|
458
|
+
], []));
|
|
459
|
+
}
|
|
70
460
|
metrics;
|
|
461
|
+
initialHeaderHashPromise;
|
|
71
462
|
// Prevent two snapshot operations to happen simultaneously
|
|
72
463
|
isUploadingSnapshot;
|
|
73
464
|
tracer;
|
|
74
|
-
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry = getTelemetryClient(), log = createLogger('node')){
|
|
465
|
+
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry = getTelemetryClient(), log = createLogger('node'), blobClient, validatorClient, keyStoreManager, debugLogStore = new NullDebugLogStore()){
|
|
75
466
|
this.config = config;
|
|
76
467
|
this.p2pClient = p2pClient;
|
|
77
468
|
this.blockSource = blockSource;
|
|
@@ -80,6 +471,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
80
471
|
this.l1ToL2MessageSource = l1ToL2MessageSource;
|
|
81
472
|
this.worldStateSynchronizer = worldStateSynchronizer;
|
|
82
473
|
this.sequencer = sequencer;
|
|
474
|
+
this.proverNode = proverNode;
|
|
83
475
|
this.slasherClient = slasherClient;
|
|
84
476
|
this.validatorsSentinel = validatorsSentinel;
|
|
85
477
|
this.epochPruneWatcher = epochPruneWatcher;
|
|
@@ -91,11 +483,22 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
91
483
|
this.proofVerifier = proofVerifier;
|
|
92
484
|
this.telemetry = telemetry;
|
|
93
485
|
this.log = log;
|
|
486
|
+
this.blobClient = blobClient;
|
|
487
|
+
this.validatorClient = validatorClient;
|
|
488
|
+
this.keyStoreManager = keyStoreManager;
|
|
489
|
+
this.debugLogStore = debugLogStore;
|
|
490
|
+
this.initialHeaderHashPromise = (_initProto(this), undefined);
|
|
94
491
|
this.isUploadingSnapshot = false;
|
|
95
492
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
96
493
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
97
494
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
98
495
|
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
|
|
496
|
+
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
497
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
498
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
499
|
+
if (debugLogStore.isEnabled && config.realProofs) {
|
|
500
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
501
|
+
}
|
|
99
502
|
}
|
|
100
503
|
async getWorldStateSyncStatus() {
|
|
101
504
|
const status = await this.worldStateSynchronizer.status();
|
|
@@ -116,20 +519,28 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
116
519
|
const packageVersion = getPackageVersion() ?? '';
|
|
117
520
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
118
521
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
119
|
-
const blobSinkClient = deps.blobSinkClient ?? createBlobSinkClient(config, {
|
|
120
|
-
logger: createLogger('node:blob-sink:client')
|
|
121
|
-
});
|
|
122
522
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
123
|
-
// Build a key store from file if given or from environment otherwise
|
|
523
|
+
// Build a key store from file if given or from environment otherwise.
|
|
524
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
124
525
|
let keyStoreManager;
|
|
125
526
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
126
527
|
if (keyStoreProvided) {
|
|
127
528
|
const keyStores = loadKeystores(config.keyStoreDirectory);
|
|
128
529
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
129
530
|
} else {
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
531
|
+
const rawKeyStores = [];
|
|
532
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
533
|
+
if (validatorKeyStore) {
|
|
534
|
+
rawKeyStores.push(validatorKeyStore);
|
|
535
|
+
}
|
|
536
|
+
if (config.enableProverNode) {
|
|
537
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
538
|
+
if (proverKeyStore) {
|
|
539
|
+
rawKeyStores.push(proverKeyStore);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
if (rawKeyStores.length > 0) {
|
|
543
|
+
keyStoreManager = new KeystoreManager(rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores));
|
|
133
544
|
}
|
|
134
545
|
}
|
|
135
546
|
await keyStoreManager?.validateSigners();
|
|
@@ -138,8 +549,8 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
138
549
|
if (keyStoreManager === undefined) {
|
|
139
550
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
140
551
|
}
|
|
141
|
-
if (!keyStoreProvided) {
|
|
142
|
-
log.warn(
|
|
552
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
553
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
143
554
|
}
|
|
144
555
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
145
556
|
}
|
|
@@ -149,7 +560,9 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
149
560
|
}
|
|
150
561
|
const publicClient = createPublicClient({
|
|
151
562
|
chain: ethereumChain.chainInfo,
|
|
152
|
-
transport:
|
|
563
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, {
|
|
564
|
+
timeout: config.l1HttpTimeoutMS
|
|
565
|
+
}),
|
|
153
566
|
pollingInterval: config.viemPollingIntervalMS
|
|
154
567
|
});
|
|
155
568
|
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.l1Contracts.registryAddress, config.rollupVersion ?? 'canonical');
|
|
@@ -159,22 +572,24 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
159
572
|
...l1ContractsAddresses
|
|
160
573
|
};
|
|
161
574
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
162
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
575
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
163
576
|
rollupContract.getL1GenesisTime(),
|
|
164
577
|
rollupContract.getSlotDuration(),
|
|
165
|
-
rollupContract.getVersion()
|
|
578
|
+
rollupContract.getVersion(),
|
|
579
|
+
rollupContract.getManaLimit().then(Number)
|
|
166
580
|
]);
|
|
167
581
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
168
582
|
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
169
583
|
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
584
|
}
|
|
585
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
171
586
|
// attempt snapshot sync if possible
|
|
172
587
|
await trySnapshotSync(config, log);
|
|
173
588
|
const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, {
|
|
174
589
|
dateProvider
|
|
175
590
|
});
|
|
176
591
|
const archiver = await createArchiver(config, {
|
|
177
|
-
|
|
592
|
+
blobClient,
|
|
178
593
|
epochCache,
|
|
179
594
|
telemetry,
|
|
180
595
|
dateProvider
|
|
@@ -183,74 +598,99 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
183
598
|
});
|
|
184
599
|
// now create the merkle trees and the world state synchronizer
|
|
185
600
|
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.prefilledPublicData, telemetry);
|
|
186
|
-
const circuitVerifier = config.realProofs ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
601
|
+
const circuitVerifier = config.realProofs || config.debugForceTxProofVerification ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
602
|
+
let debugLogStore;
|
|
187
603
|
if (!config.realProofs) {
|
|
188
604
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
605
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
606
|
+
log.info('Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served');
|
|
607
|
+
} else {
|
|
608
|
+
debugLogStore = new NullDebugLogStore();
|
|
189
609
|
}
|
|
190
610
|
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
611
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
612
|
+
if (proverOnly) {
|
|
613
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
614
|
+
}
|
|
191
615
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
192
|
-
const p2pClient = await createP2PClient(
|
|
193
|
-
// We
|
|
194
|
-
|
|
195
|
-
|
|
616
|
+
const p2pClient = await createP2PClient(config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
617
|
+
// We'll accumulate sentinel watchers here
|
|
618
|
+
const watchers = [];
|
|
619
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
620
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
621
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
196
622
|
...config,
|
|
197
623
|
l1GenesisTime,
|
|
198
|
-
slotDuration: Number(slotDuration)
|
|
624
|
+
slotDuration: Number(slotDuration),
|
|
625
|
+
rollupManaLimit,
|
|
626
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
|
|
199
627
|
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
628
|
+
let validatorClient;
|
|
629
|
+
if (!proverOnly) {
|
|
630
|
+
// Create validator client if required
|
|
631
|
+
validatorClient = await createValidatorClient(config, {
|
|
632
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
633
|
+
worldState: worldStateSynchronizer,
|
|
634
|
+
p2pClient,
|
|
635
|
+
telemetry,
|
|
636
|
+
dateProvider,
|
|
637
|
+
epochCache,
|
|
638
|
+
blockSource: archiver,
|
|
639
|
+
l1ToL2MessageSource: archiver,
|
|
640
|
+
keyStoreManager,
|
|
641
|
+
blobClient,
|
|
642
|
+
slashingProtectionDb: deps.slashingProtectionDb
|
|
643
|
+
});
|
|
644
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
645
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
646
|
+
// like attestations or auths will fail.
|
|
647
|
+
if (validatorClient) {
|
|
648
|
+
watchers.push(validatorClient);
|
|
649
|
+
if (!options.dontStartSequencer) {
|
|
650
|
+
await validatorClient.registerHandlers();
|
|
651
|
+
}
|
|
220
652
|
}
|
|
221
653
|
}
|
|
222
|
-
// If there's no validator client
|
|
223
|
-
//
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
654
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
655
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
656
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
657
|
+
// Checkpoint proposals are handled if the blob client can upload blobs.
|
|
658
|
+
if (!validatorClient) {
|
|
659
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
660
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
661
|
+
createProposalHandler(config, {
|
|
662
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
663
|
+
worldState: worldStateSynchronizer,
|
|
228
664
|
epochCache,
|
|
229
665
|
blockSource: archiver,
|
|
230
666
|
l1ToL2MessageSource: archiver,
|
|
231
667
|
p2pClient,
|
|
668
|
+
blobClient,
|
|
232
669
|
dateProvider,
|
|
233
670
|
telemetry
|
|
234
|
-
}).
|
|
671
|
+
}).register(p2pClient, reexecute);
|
|
235
672
|
}
|
|
236
673
|
// Start world state and wait for it to sync to the archiver.
|
|
237
674
|
await worldStateSynchronizer.start();
|
|
238
675
|
// Start p2p. Note that it depends on world state to be running.
|
|
239
676
|
await p2pClient.start();
|
|
240
|
-
|
|
241
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
242
|
-
watchers.push(validatorsSentinel);
|
|
243
|
-
}
|
|
677
|
+
let validatorsSentinel;
|
|
244
678
|
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
679
|
let attestationsBlockWatcher;
|
|
251
|
-
if (
|
|
252
|
-
|
|
253
|
-
|
|
680
|
+
if (!proverOnly) {
|
|
681
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
682
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
683
|
+
watchers.push(validatorsSentinel);
|
|
684
|
+
}
|
|
685
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
686
|
+
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
|
|
687
|
+
watchers.push(epochPruneWatcher);
|
|
688
|
+
}
|
|
689
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
690
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
691
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
692
|
+
watchers.push(attestationsBlockWatcher);
|
|
693
|
+
}
|
|
254
694
|
}
|
|
255
695
|
// Start p2p-related services once the archiver has completed sync
|
|
256
696
|
void archiver.waitForInitialSync().then(async ()=>{
|
|
@@ -260,24 +700,46 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
260
700
|
await attestationsBlockWatcher?.start();
|
|
261
701
|
log.info(`All p2p services started`);
|
|
262
702
|
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
703
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, {
|
|
704
|
+
l1Contracts: config.l1Contracts,
|
|
705
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
706
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
707
|
+
l1GenesisTime,
|
|
708
|
+
slotDuration: Number(slotDuration)
|
|
709
|
+
});
|
|
263
710
|
// Validator enabled, create/start relevant service
|
|
264
711
|
let sequencer;
|
|
265
712
|
let slasherClient;
|
|
266
|
-
if (!config.disableValidator) {
|
|
713
|
+
if (!config.disableValidator && validatorClient) {
|
|
267
714
|
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
268
715
|
// as they are executed when the node is selected as proposer.
|
|
269
716
|
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
270
717
|
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
271
718
|
await slasherClient.start();
|
|
272
|
-
const l1TxUtils = await
|
|
719
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
|
|
720
|
+
...config,
|
|
721
|
+
scope: 'sequencer'
|
|
722
|
+
}, {
|
|
723
|
+
telemetry,
|
|
724
|
+
logger: log.createChild('l1-tx-utils'),
|
|
725
|
+
dateProvider,
|
|
726
|
+
kzg: Blob.getViemKzgInstance()
|
|
727
|
+
}) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
273
728
|
...config,
|
|
274
729
|
scope: 'sequencer'
|
|
275
730
|
}, {
|
|
276
731
|
telemetry,
|
|
277
732
|
logger: log.createChild('l1-tx-utils'),
|
|
278
|
-
dateProvider
|
|
733
|
+
dateProvider,
|
|
734
|
+
kzg: Blob.getViemKzgInstance()
|
|
279
735
|
});
|
|
280
736
|
// Create and start the sequencer client
|
|
737
|
+
const checkpointsBuilder = new CheckpointsBuilder({
|
|
738
|
+
...config,
|
|
739
|
+
l1GenesisTime,
|
|
740
|
+
slotDuration: Number(slotDuration),
|
|
741
|
+
rollupManaLimit
|
|
742
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry, debugLogStore);
|
|
281
743
|
sequencer = await SequencerClient.new(config, {
|
|
282
744
|
...deps,
|
|
283
745
|
epochCache,
|
|
@@ -286,13 +748,14 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
286
748
|
p2pClient,
|
|
287
749
|
worldStateSynchronizer,
|
|
288
750
|
slasherClient,
|
|
289
|
-
|
|
751
|
+
checkpointsBuilder,
|
|
290
752
|
l2BlockSource: archiver,
|
|
291
753
|
l1ToL2MessageSource: archiver,
|
|
292
754
|
telemetry,
|
|
293
755
|
dateProvider,
|
|
294
|
-
|
|
295
|
-
nodeKeyStore: keyStoreManager
|
|
756
|
+
blobClient,
|
|
757
|
+
nodeKeyStore: keyStoreManager,
|
|
758
|
+
globalVariableBuilder
|
|
296
759
|
});
|
|
297
760
|
}
|
|
298
761
|
if (!options.dontStartSequencer && sequencer) {
|
|
@@ -301,7 +764,29 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
301
764
|
} else if (sequencer) {
|
|
302
765
|
log.warn(`Sequencer created but not started`);
|
|
303
766
|
}
|
|
304
|
-
|
|
767
|
+
// Create prover node subsystem if enabled
|
|
768
|
+
let proverNode;
|
|
769
|
+
if (config.enableProverNode) {
|
|
770
|
+
proverNode = await createProverNode(config, {
|
|
771
|
+
...deps.proverNodeDeps,
|
|
772
|
+
telemetry,
|
|
773
|
+
dateProvider,
|
|
774
|
+
archiver,
|
|
775
|
+
worldStateSynchronizer,
|
|
776
|
+
p2pClient,
|
|
777
|
+
epochCache,
|
|
778
|
+
blobClient,
|
|
779
|
+
keyStoreManager
|
|
780
|
+
});
|
|
781
|
+
if (!options.dontStartProverNode) {
|
|
782
|
+
await proverNode.start();
|
|
783
|
+
log.info(`Prover node subsystem started`);
|
|
784
|
+
} else {
|
|
785
|
+
log.info(`Prover node subsystem created but not started`);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
const node = new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry, log, blobClient, validatorClient, keyStoreManager, debugLogStore);
|
|
789
|
+
return node;
|
|
305
790
|
}
|
|
306
791
|
/**
|
|
307
792
|
* Returns the sequencer client instance.
|
|
@@ -309,6 +794,9 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
309
794
|
*/ getSequencer() {
|
|
310
795
|
return this.sequencer;
|
|
311
796
|
}
|
|
797
|
+
/** Returns the prover node subsystem, if enabled. */ getProverNode() {
|
|
798
|
+
return this.proverNode;
|
|
799
|
+
}
|
|
312
800
|
getBlockSource() {
|
|
313
801
|
return this.blockSource;
|
|
314
802
|
}
|
|
@@ -328,7 +816,10 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
328
816
|
return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
|
|
329
817
|
}
|
|
330
818
|
async getAllowedPublicSetup() {
|
|
331
|
-
return
|
|
819
|
+
return [
|
|
820
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
821
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
822
|
+
];
|
|
332
823
|
}
|
|
333
824
|
/**
|
|
334
825
|
* Method to determine if the node is ready to accept transactions.
|
|
@@ -351,33 +842,46 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
351
842
|
rollupVersion,
|
|
352
843
|
enr,
|
|
353
844
|
l1ContractAddresses: contractAddresses,
|
|
354
|
-
protocolContractAddresses: protocolContractAddresses
|
|
845
|
+
protocolContractAddresses: protocolContractAddresses,
|
|
846
|
+
realProofs: !!this.config.realProofs
|
|
355
847
|
};
|
|
356
848
|
return nodeInfo;
|
|
357
849
|
}
|
|
358
850
|
/**
|
|
359
|
-
* Get a block specified by its number.
|
|
360
|
-
* @param
|
|
851
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
852
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
361
853
|
* @returns The requested block.
|
|
362
|
-
*/ async getBlock(
|
|
363
|
-
|
|
364
|
-
|
|
854
|
+
*/ async getBlock(block) {
|
|
855
|
+
if (BlockHash.isBlockHash(block)) {
|
|
856
|
+
return this.getBlockByHash(block);
|
|
857
|
+
}
|
|
858
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
859
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
860
|
+
return this.buildInitialBlock();
|
|
861
|
+
}
|
|
862
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
365
863
|
}
|
|
366
864
|
/**
|
|
367
865
|
* Get a block specified by its hash.
|
|
368
866
|
* @param blockHash - The block hash being requested.
|
|
369
867
|
* @returns The requested block.
|
|
370
868
|
*/ async getBlockByHash(blockHash) {
|
|
371
|
-
const
|
|
372
|
-
|
|
869
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
870
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
871
|
+
return this.buildInitialBlock();
|
|
872
|
+
}
|
|
873
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
874
|
+
}
|
|
875
|
+
buildInitialBlock() {
|
|
876
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
877
|
+
return L2Block.empty(initialHeader);
|
|
373
878
|
}
|
|
374
879
|
/**
|
|
375
880
|
* Get a block specified by its archive root.
|
|
376
881
|
* @param archive - The archive root being requested.
|
|
377
882
|
* @returns The requested block.
|
|
378
883
|
*/ async getBlockByArchive(archive) {
|
|
379
|
-
|
|
380
|
-
return publishedBlock?.block;
|
|
884
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
381
885
|
}
|
|
382
886
|
/**
|
|
383
887
|
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
|
|
@@ -385,16 +889,22 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
385
889
|
* @param limit - The maximum number of blocks to obtain.
|
|
386
890
|
* @returns The blocks requested.
|
|
387
891
|
*/ async getBlocks(from, limit) {
|
|
388
|
-
return await this.blockSource.getBlocks(from, limit) ?? [];
|
|
892
|
+
return await this.blockSource.getBlocks(from, BlockNumber(limit)) ?? [];
|
|
893
|
+
}
|
|
894
|
+
async getCheckpoints(from, limit) {
|
|
895
|
+
return await this.blockSource.getCheckpoints(from, limit) ?? [];
|
|
896
|
+
}
|
|
897
|
+
async getCheckpointedBlocks(from, limit) {
|
|
898
|
+
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
389
899
|
}
|
|
390
|
-
|
|
391
|
-
return
|
|
900
|
+
getCheckpointsDataForEpoch(epochNumber) {
|
|
901
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
392
902
|
}
|
|
393
903
|
/**
|
|
394
|
-
* Method to fetch the current
|
|
395
|
-
* @returns The current
|
|
396
|
-
*/ async
|
|
397
|
-
return await this.globalVariableBuilder.
|
|
904
|
+
* Method to fetch the current min L2 fees.
|
|
905
|
+
* @returns The current min L2 fees.
|
|
906
|
+
*/ async getCurrentMinFees() {
|
|
907
|
+
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
398
908
|
}
|
|
399
909
|
async getMaxPriorityFees() {
|
|
400
910
|
for await (const tx of this.p2pClient.iteratePendingTxs()){
|
|
@@ -414,6 +924,12 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
414
924
|
async getProvenBlockNumber() {
|
|
415
925
|
return await this.blockSource.getProvenBlockNumber();
|
|
416
926
|
}
|
|
927
|
+
async getCheckpointedBlockNumber() {
|
|
928
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
929
|
+
}
|
|
930
|
+
getCheckpointNumber() {
|
|
931
|
+
return this.blockSource.getCheckpointNumber();
|
|
932
|
+
}
|
|
417
933
|
/**
|
|
418
934
|
* Method to fetch the version of the package.
|
|
419
935
|
* @returns The node package version
|
|
@@ -438,22 +954,29 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
438
954
|
getContract(address) {
|
|
439
955
|
return this.contractDataSource.getContract(address);
|
|
440
956
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
957
|
+
async getPrivateLogsByTags(tags, page, referenceBlock) {
|
|
958
|
+
if (referenceBlock) {
|
|
959
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
960
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
961
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
962
|
+
if (!header) {
|
|
963
|
+
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
968
|
+
}
|
|
969
|
+
async getPublicLogsByTagsFromContract(contractAddress, tags, page, referenceBlock) {
|
|
970
|
+
if (referenceBlock) {
|
|
971
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
972
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
973
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
974
|
+
if (!header) {
|
|
975
|
+
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
457
980
|
}
|
|
458
981
|
/**
|
|
459
982
|
* Gets public logs based on the provided filter.
|
|
@@ -488,24 +1011,33 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
488
1011
|
throw new Error(`Invalid tx: ${reason}`);
|
|
489
1012
|
}
|
|
490
1013
|
await this.p2pClient.sendTx(tx);
|
|
491
|
-
|
|
492
|
-
this.
|
|
1014
|
+
const duration = timer.ms();
|
|
1015
|
+
this.metrics.receivedTx(duration, true);
|
|
1016
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, {
|
|
493
1017
|
txHash
|
|
494
1018
|
});
|
|
495
1019
|
}
|
|
496
1020
|
async getTxReceipt(txHash) {
|
|
497
|
-
|
|
498
|
-
//
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
503
|
-
}
|
|
1021
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
1022
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
1023
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
1024
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
1025
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
504
1026
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
1027
|
+
let receipt;
|
|
505
1028
|
if (settledTxReceipt) {
|
|
506
|
-
|
|
1029
|
+
receipt = settledTxReceipt;
|
|
1030
|
+
} else if (isKnownToPool) {
|
|
1031
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
1032
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
1033
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
1034
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
1035
|
+
} else {
|
|
1036
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
1037
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
507
1038
|
}
|
|
508
|
-
|
|
1039
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
1040
|
+
return receipt;
|
|
509
1041
|
}
|
|
510
1042
|
getTxEffect(txHash) {
|
|
511
1043
|
return this.blockSource.getTxEffect(txHash);
|
|
@@ -519,13 +1051,21 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
519
1051
|
await tryStop(this.slasherClient);
|
|
520
1052
|
await tryStop(this.proofVerifier);
|
|
521
1053
|
await tryStop(this.sequencer);
|
|
1054
|
+
await tryStop(this.proverNode);
|
|
522
1055
|
await tryStop(this.p2pClient);
|
|
523
1056
|
await tryStop(this.worldStateSynchronizer);
|
|
524
1057
|
await tryStop(this.blockSource);
|
|
1058
|
+
await tryStop(this.blobClient);
|
|
525
1059
|
await tryStop(this.telemetry);
|
|
526
1060
|
this.log.info(`Stopped Aztec Node`);
|
|
527
1061
|
}
|
|
528
1062
|
/**
|
|
1063
|
+
* Returns the blob client used by this node.
|
|
1064
|
+
* @internal - Exposed for testing purposes only.
|
|
1065
|
+
*/ getBlobClient() {
|
|
1066
|
+
return this.blobClient;
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
529
1069
|
* Method to retrieve pending txs.
|
|
530
1070
|
* @param limit - The number of items to returns
|
|
531
1071
|
* @param after - The last known pending tx. Used for pagination
|
|
@@ -550,101 +1090,89 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
550
1090
|
*/ async getTxsByHash(txHashes) {
|
|
551
1091
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
552
1092
|
}
|
|
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);
|
|
1093
|
+
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
1094
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
562
1095
|
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
|
-
|
|
1096
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
1097
|
+
const definedIndices = maybeIndices.filter((x)=>x !== undefined);
|
|
1098
|
+
// Now we find the block numbers for the defined indices
|
|
1099
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
1100
|
+
// Build a map from leaf index to block number
|
|
1101
|
+
const indexToBlockNumber = new Map();
|
|
1102
|
+
for(let i = 0; i < definedIndices.length; i++){
|
|
1103
|
+
const blockNumber = blockNumbers[i];
|
|
1104
|
+
if (blockNumber === undefined) {
|
|
1105
|
+
throw new Error(`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`);
|
|
571
1106
|
}
|
|
1107
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
572
1108
|
}
|
|
573
1109
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
574
1110
|
const uniqueBlockNumbers = [
|
|
575
|
-
...new Set(
|
|
1111
|
+
...new Set(indexToBlockNumber.values())
|
|
576
1112
|
];
|
|
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).
|
|
1113
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
579
1114
|
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
580
|
-
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, blockNumber);
|
|
1115
|
+
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
581
1116
|
}));
|
|
582
|
-
//
|
|
1117
|
+
// Build a map from block number to block hash
|
|
1118
|
+
const blockNumberToHash = new Map();
|
|
583
1119
|
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
584
|
-
|
|
1120
|
+
const blockHash = blockHashes[i];
|
|
1121
|
+
if (blockHash === undefined) {
|
|
585
1122
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
586
1123
|
}
|
|
1124
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
587
1125
|
}
|
|
588
|
-
// Create
|
|
589
|
-
return maybeIndices.map((index
|
|
1126
|
+
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1127
|
+
return maybeIndices.map((index)=>{
|
|
590
1128
|
if (index === undefined) {
|
|
591
1129
|
return undefined;
|
|
592
1130
|
}
|
|
593
|
-
const blockNumber =
|
|
1131
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
594
1132
|
if (blockNumber === undefined) {
|
|
595
|
-
|
|
1133
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
596
1134
|
}
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
return undefined;
|
|
1135
|
+
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1136
|
+
if (blockHash === undefined) {
|
|
1137
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
601
1138
|
}
|
|
602
1139
|
return {
|
|
603
|
-
l2BlockNumber:
|
|
604
|
-
l2BlockHash:
|
|
1140
|
+
l2BlockNumber: blockNumber,
|
|
1141
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
605
1142
|
data: index
|
|
606
1143
|
};
|
|
607
1144
|
});
|
|
608
1145
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
const committedDb = await this
|
|
625
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
626
|
-
}
|
|
627
|
-
async getArchiveMembershipWitness(blockNumber, archive) {
|
|
628
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1146
|
+
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
1147
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1148
|
+
if (referenceBlock === BlockNumber.ZERO) {
|
|
1149
|
+
return undefined;
|
|
1150
|
+
}
|
|
1151
|
+
if (BlockHash.isBlockHash(referenceBlock)) {
|
|
1152
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1153
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1154
|
+
return undefined;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1158
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1159
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1160
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1161
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
629
1162
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
630
|
-
|
|
1163
|
+
blockHash
|
|
631
1164
|
]);
|
|
632
1165
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
633
1166
|
}
|
|
634
|
-
async getNoteHashMembershipWitness(
|
|
635
|
-
const committedDb = await this
|
|
1167
|
+
async getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
1168
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
636
1169
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
637
1170
|
noteHash
|
|
638
1171
|
]);
|
|
639
1172
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
640
1173
|
}
|
|
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);
|
|
1174
|
+
async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
1175
|
+
const db = await this.getWorldState(referenceBlock);
|
|
648
1176
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
649
1177
|
l1ToL2Message
|
|
650
1178
|
]);
|
|
@@ -657,9 +1185,9 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
657
1185
|
witness.path
|
|
658
1186
|
];
|
|
659
1187
|
}
|
|
660
|
-
async
|
|
1188
|
+
async getL1ToL2MessageCheckpoint(l1ToL2Message) {
|
|
661
1189
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
662
|
-
return messageIndex ? InboxLeaf.
|
|
1190
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
663
1191
|
}
|
|
664
1192
|
/**
|
|
665
1193
|
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
@@ -670,38 +1198,17 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
670
1198
|
return messageIndex !== undefined;
|
|
671
1199
|
}
|
|
672
1200
|
/**
|
|
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);
|
|
1201
|
+
* Returns all the L2 to L1 messages in an epoch.
|
|
1202
|
+
* @param epoch - The epoch at which to get the data.
|
|
1203
|
+
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
1204
|
+
*/ async getL2ToL1Messages(epoch) {
|
|
1205
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1206
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1207
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, (cb)=>cb.block.header.globalVariables.slotNumber).map((group)=>group.map((cb)=>cb.block));
|
|
1208
|
+
return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
1209
|
+
}
|
|
1210
|
+
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1211
|
+
const db = await this.getWorldState(referenceBlock);
|
|
705
1212
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
706
1213
|
nullifier.toBuffer()
|
|
707
1214
|
]);
|
|
@@ -715,35 +1222,22 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
715
1222
|
}
|
|
716
1223
|
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
717
1224
|
}
|
|
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);
|
|
1225
|
+
async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1226
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
733
1227
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
734
1228
|
if (!findResult) {
|
|
735
1229
|
return undefined;
|
|
736
1230
|
}
|
|
737
1231
|
const { index, alreadyPresent } = findResult;
|
|
738
1232
|
if (alreadyPresent) {
|
|
739
|
-
|
|
1233
|
+
throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
740
1234
|
}
|
|
741
1235
|
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
742
1236
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
743
1237
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
744
1238
|
}
|
|
745
|
-
async getPublicDataWitness(
|
|
746
|
-
const committedDb = await this
|
|
1239
|
+
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1240
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
747
1241
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
748
1242
|
if (!lowLeafResult) {
|
|
749
1243
|
return undefined;
|
|
@@ -753,18 +1247,8 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
753
1247
|
return new PublicDataWitness(lowLeafResult.index, preimage, path);
|
|
754
1248
|
}
|
|
755
1249
|
}
|
|
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);
|
|
1250
|
+
async getPublicStorageAt(referenceBlock, contract, slot) {
|
|
1251
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
768
1252
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
769
1253
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
770
1254
|
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
@@ -773,18 +1257,22 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
773
1257
|
const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
774
1258
|
return preimage.leaf.value;
|
|
775
1259
|
}
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
1260
|
+
async getBlockHeader(block = 'latest') {
|
|
1261
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1262
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1263
|
+
if (block.equals(initialBlockHash)) {
|
|
1264
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1265
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1266
|
+
}
|
|
1267
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1268
|
+
} else {
|
|
1269
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1270
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
1271
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1272
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1273
|
+
}
|
|
1274
|
+
return this.blockSource.getBlockHeader(block);
|
|
1275
|
+
}
|
|
788
1276
|
}
|
|
789
1277
|
/**
|
|
790
1278
|
* Get a block header specified by its archive root.
|
|
@@ -793,6 +1281,12 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
793
1281
|
*/ async getBlockHeaderByArchive(archive) {
|
|
794
1282
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
795
1283
|
}
|
|
1284
|
+
getBlockData(number) {
|
|
1285
|
+
return this.blockSource.getBlockData(number);
|
|
1286
|
+
}
|
|
1287
|
+
getBlockDataByArchive(archive) {
|
|
1288
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1289
|
+
}
|
|
796
1290
|
/**
|
|
797
1291
|
* Simulates the public part of a transaction with the current state.
|
|
798
1292
|
* @param tx - The transaction to simulate.
|
|
@@ -805,17 +1299,20 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
805
1299
|
throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
|
|
806
1300
|
}
|
|
807
1301
|
const txHash = tx.getTxHash();
|
|
808
|
-
const
|
|
1302
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1303
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
809
1304
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
810
1305
|
const coinbase = EthAddress.ZERO;
|
|
811
1306
|
const feeRecipient = AztecAddress.ZERO;
|
|
812
1307
|
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(blockNumber, coinbase, feeRecipient);
|
|
813
|
-
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry);
|
|
1308
|
+
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry, this.log.getBindings());
|
|
814
1309
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
815
1310
|
globalVariables: newGlobalVariables.toInspect(),
|
|
816
1311
|
txHash,
|
|
817
1312
|
blockNumber
|
|
818
1313
|
});
|
|
1314
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1315
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
819
1316
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
820
1317
|
try {
|
|
821
1318
|
const config = PublicSimulatorConfig.from({
|
|
@@ -823,12 +1320,14 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
823
1320
|
collectDebugLogs: true,
|
|
824
1321
|
collectHints: false,
|
|
825
1322
|
collectCallMetadata: true,
|
|
826
|
-
|
|
827
|
-
|
|
1323
|
+
collectStatistics: false,
|
|
1324
|
+
collectionLimits: CollectionLimitsConfig.from({
|
|
1325
|
+
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads
|
|
1326
|
+
})
|
|
828
1327
|
});
|
|
829
1328
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
830
1329
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
831
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
|
|
1330
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([
|
|
832
1331
|
tx
|
|
833
1332
|
]);
|
|
834
1333
|
// REFACTOR: Consider returning the error rather than throwing
|
|
@@ -839,7 +1338,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
839
1338
|
throw failedTxs[0].error;
|
|
840
1339
|
}
|
|
841
1340
|
const [processedTx] = processedTxs;
|
|
842
|
-
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed);
|
|
1341
|
+
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed, debugLogs);
|
|
843
1342
|
} finally{
|
|
844
1343
|
await merkleTreeFork.close();
|
|
845
1344
|
}
|
|
@@ -847,19 +1346,26 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
847
1346
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
848
1347
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
849
1348
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
850
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1349
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
851
1350
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
852
|
-
const blockNumber = await this.blockSource.getBlockNumber() + 1;
|
|
853
|
-
const
|
|
1351
|
+
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1352
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1353
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
|
|
854
1354
|
timestamp: nextSlotTimestamp,
|
|
855
1355
|
blockNumber,
|
|
856
1356
|
l1ChainId: this.l1ChainId,
|
|
857
1357
|
rollupVersion: this.version,
|
|
858
|
-
setupAllowList:
|
|
859
|
-
|
|
1358
|
+
setupAllowList: [
|
|
1359
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1360
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1361
|
+
],
|
|
1362
|
+
gasFees: await this.getCurrentMinFees(),
|
|
860
1363
|
skipFeeEnforcement,
|
|
861
|
-
txsPermitted: !this.config.disableTransactions
|
|
862
|
-
|
|
1364
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1365
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1366
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1367
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
1368
|
+
}, this.log.getBindings());
|
|
863
1369
|
return await validator.validateTx(tx);
|
|
864
1370
|
}
|
|
865
1371
|
getConfig() {
|
|
@@ -919,7 +1425,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
919
1425
|
throw new Error(`Archiver initial sync not complete. Cannot start snapshot.`);
|
|
920
1426
|
}
|
|
921
1427
|
// And it has an L2 block hash
|
|
922
|
-
const l2BlockHash = await archiver.getL2Tips().then((tips)=>tips.
|
|
1428
|
+
const l2BlockHash = await archiver.getL2Tips().then((tips)=>tips.proposed.hash);
|
|
923
1429
|
if (!l2BlockHash) {
|
|
924
1430
|
this.metrics.recordSnapshotError();
|
|
925
1431
|
throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
|
|
@@ -946,7 +1452,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
946
1452
|
if (!('rollbackTo' in archiver)) {
|
|
947
1453
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
948
1454
|
}
|
|
949
|
-
const finalizedBlock = await archiver.getL2Tips().then((tips)=>tips.finalized.number);
|
|
1455
|
+
const finalizedBlock = await archiver.getL2Tips().then((tips)=>tips.finalized.block.number);
|
|
950
1456
|
if (targetBlock < finalizedBlock) {
|
|
951
1457
|
if (force) {
|
|
952
1458
|
this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
|
|
@@ -1001,42 +1507,175 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
1001
1507
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1002
1508
|
}
|
|
1003
1509
|
}
|
|
1510
|
+
async reloadKeystore() {
|
|
1511
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1512
|
+
throw new BadRequestError('Cannot reload keystore: node is not using a file-based keystore. ' + 'Set KEY_STORE_DIRECTORY to use file-based keystores.');
|
|
1513
|
+
}
|
|
1514
|
+
if (!this.validatorClient) {
|
|
1515
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1516
|
+
}
|
|
1517
|
+
this.log.info('Reloading keystore from disk');
|
|
1518
|
+
// Re-read and validate keystore files
|
|
1519
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1520
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1521
|
+
await newManager.validateSigners();
|
|
1522
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1523
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1524
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1525
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1526
|
+
// would silently fail on every proposer slot.
|
|
1527
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1528
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1529
|
+
const availablePublishers = new Set(oldAdapter.getAttesterAddresses().flatMap((a)=>oldAdapter.getPublisherAddresses(a).map((p)=>p.toString().toLowerCase())));
|
|
1530
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1531
|
+
for (const attester of newAdapter.getAttesterAddresses()){
|
|
1532
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1533
|
+
if (pubs.length > 0 && !pubs.some((p)=>availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1534
|
+
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 ` + `[${[
|
|
1535
|
+
...availablePublishers
|
|
1536
|
+
].join(', ')}]. Publishers cannot be hot-reloaded — ` + `use an existing publisher key or restart the node.`);
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
// Build adapters for old and new keystores to compute diff
|
|
1541
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1542
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1543
|
+
const oldAddresses = this.keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses() : [];
|
|
1544
|
+
const oldSet = new Set(oldAddresses.map((a)=>a.toString()));
|
|
1545
|
+
const newSet = new Set(newAddresses.map((a)=>a.toString()));
|
|
1546
|
+
const added = newAddresses.filter((a)=>!oldSet.has(a.toString()));
|
|
1547
|
+
const removed = oldAddresses.filter((a)=>!newSet.has(a.toString()));
|
|
1548
|
+
if (added.length > 0) {
|
|
1549
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map((a)=>a.toString()).join(', ')}`);
|
|
1550
|
+
}
|
|
1551
|
+
if (removed.length > 0) {
|
|
1552
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map((a)=>a.toString()).join(', ')}`);
|
|
1553
|
+
}
|
|
1554
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1555
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1556
|
+
}
|
|
1557
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1558
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1559
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1560
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1561
|
+
if (this.sequencer) {
|
|
1562
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1563
|
+
}
|
|
1564
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1565
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1566
|
+
const slashValidatorsNever = unique([
|
|
1567
|
+
...this.config.slashValidatorsNever ?? [],
|
|
1568
|
+
...newAddresses
|
|
1569
|
+
].map((a)=>a.toString())).map(EthAddress.fromString);
|
|
1570
|
+
this.slasherClient.updateConfig({
|
|
1571
|
+
slashValidatorsNever
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
this.keyStoreManager = newManager;
|
|
1575
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1576
|
+
}
|
|
1577
|
+
async mineBlock() {
|
|
1578
|
+
if (!this.sequencer) {
|
|
1579
|
+
throw new BadRequestError('Cannot mine block: no sequencer is running');
|
|
1580
|
+
}
|
|
1581
|
+
const currentBlockNumber = await this.getBlockNumber();
|
|
1582
|
+
// Use slot duration + 50% buffer as the timeout so this works on running networks too
|
|
1583
|
+
const { slotDuration } = await this.blockSource.getL1Constants();
|
|
1584
|
+
const timeoutSeconds = Math.ceil(slotDuration * 1.5);
|
|
1585
|
+
// Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
|
|
1586
|
+
const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
|
|
1587
|
+
this.sequencer.updateConfig({
|
|
1588
|
+
minTxsPerBlock: 0
|
|
1589
|
+
});
|
|
1590
|
+
try {
|
|
1591
|
+
// Trigger the sequencer to produce a block immediately
|
|
1592
|
+
void this.sequencer.trigger();
|
|
1593
|
+
// Wait for the new L2 block to appear
|
|
1594
|
+
await retryUntil(async ()=>{
|
|
1595
|
+
const newBlockNumber = await this.getBlockNumber();
|
|
1596
|
+
return newBlockNumber > currentBlockNumber ? true : undefined;
|
|
1597
|
+
}, 'mineBlock', timeoutSeconds, 0.1);
|
|
1598
|
+
} finally{
|
|
1599
|
+
this.sequencer.updateConfig({
|
|
1600
|
+
minTxsPerBlock: originalMinTxsPerBlock
|
|
1601
|
+
});
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
#getInitialHeaderHash() {
|
|
1605
|
+
if (!this.initialHeaderHashPromise) {
|
|
1606
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1607
|
+
}
|
|
1608
|
+
return this.initialHeaderHashPromise;
|
|
1609
|
+
}
|
|
1004
1610
|
/**
|
|
1005
1611
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1006
|
-
* @param
|
|
1612
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1007
1613
|
* @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;
|
|
1614
|
+
*/ async getWorldState(block) {
|
|
1615
|
+
let blockSyncedTo = BlockNumber.ZERO;
|
|
1013
1616
|
try {
|
|
1014
1617
|
// Attempt to sync the world state if necessary
|
|
1015
1618
|
blockSyncedTo = await this.#syncWorldState();
|
|
1016
1619
|
} catch (err) {
|
|
1017
1620
|
this.log.error(`Error getting world state: ${err}`);
|
|
1018
1621
|
}
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1622
|
+
if (block === 'latest') {
|
|
1623
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1022
1624
|
return this.worldStateSynchronizer.getCommitted();
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
|
|
1625
|
+
}
|
|
1626
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1627
|
+
let blockNumber;
|
|
1628
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1629
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1630
|
+
if (block.equals(initialBlockHash)) {
|
|
1631
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1632
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1633
|
+
}
|
|
1634
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1635
|
+
if (!header) {
|
|
1636
|
+
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.`);
|
|
1637
|
+
}
|
|
1638
|
+
blockNumber = header.getBlockNumber();
|
|
1026
1639
|
} else {
|
|
1027
|
-
|
|
1640
|
+
blockNumber = block;
|
|
1641
|
+
}
|
|
1642
|
+
// Check it's within world state sync range
|
|
1643
|
+
if (blockNumber > blockSyncedTo) {
|
|
1644
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1645
|
+
}
|
|
1646
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1647
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1648
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1649
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1650
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1651
|
+
if (!blockHash || !new BlockHash(blockHash).equals(block)) {
|
|
1652
|
+
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.`);
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
return snapshot;
|
|
1656
|
+
}
|
|
1657
|
+
/** Resolves a block parameter to a block number. */ async resolveBlockNumber(block) {
|
|
1658
|
+
if (block === 'latest') {
|
|
1659
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1660
|
+
}
|
|
1661
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1662
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1663
|
+
if (block.equals(initialBlockHash)) {
|
|
1664
|
+
return BlockNumber.ZERO;
|
|
1665
|
+
}
|
|
1666
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1667
|
+
if (!header) {
|
|
1668
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1669
|
+
}
|
|
1670
|
+
return header.getBlockNumber();
|
|
1028
1671
|
}
|
|
1672
|
+
return block;
|
|
1029
1673
|
}
|
|
1030
1674
|
/**
|
|
1031
1675
|
* Ensure we fully sync the world state
|
|
1032
1676
|
* @returns A promise that fulfils once the world state is synced
|
|
1033
1677
|
*/ async #syncWorldState() {
|
|
1034
1678
|
const blockSourceHeight = await this.blockSource.getBlockNumber();
|
|
1035
|
-
return this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1679
|
+
return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1036
1680
|
}
|
|
1037
1681
|
}
|
|
1038
|
-
_ts_decorate([
|
|
1039
|
-
trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
1040
|
-
[Attributes.TX_HASH]: tx.getTxHash().toString()
|
|
1041
|
-
}))
|
|
1042
|
-
], AztecNodeService.prototype, "simulatePublicCalls", null);
|