@aztec/aztec-node 0.0.1-commit.03f7ef2 → 0.0.1-commit.04852196a

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.
@@ -1,20 +1,386 @@
1
- function _ts_decorate(decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
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 { createBlobClient } from '@aztec/blob-client/client';
10
- import { createReadOnlyFileStoreBlobClients, createWritableFileStoreBlobClient } from '@aztec/blob-client/filestore';
11
- import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
376
+ import { createBlobClientWithFileStores } from '@aztec/blob-client/client';
377
+ import { Blob } from '@aztec/blob-lib';
12
378
  import { EpochCache } from '@aztec/epoch-cache';
13
379
  import { createEthereumChain } from '@aztec/ethereum/chain';
14
380
  import { getPublicClient } from '@aztec/ethereum/client';
15
381
  import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
16
- import { BlockNumber } from '@aztec/foundation/branded-types';
17
- import { compactArray, pick } from '@aztec/foundation/collection';
382
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
383
+ import { compactArray, pick, unique } from '@aztec/foundation/collection';
18
384
  import { Fr } from '@aztec/foundation/curves/bn254';
19
385
  import { EthAddress } from '@aztec/foundation/eth-address';
20
386
  import { BadRequestError } from '@aztec/foundation/json-rpc';
@@ -24,32 +390,36 @@ import { DateProvider, Timer } from '@aztec/foundation/timer';
24
390
  import { MembershipWitness } from '@aztec/foundation/trees';
25
391
  import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
26
392
  import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
27
- import { createForwarderL1TxUtilsFromEthSigner, createL1TxUtilsWithBlobsFromEthSigner } from '@aztec/node-lib/factories';
28
- import { createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
393
+ import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
394
+ import { createP2PClient, createTxValidatorForAcceptingTxsOverRPC, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
29
395
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
30
- import { BlockBuilder, GlobalVariableBuilder, SequencerClient, createValidatorForAcceptingTxs } from '@aztec/sequencer-client';
31
- import { CheckpointsBuilder } from '@aztec/sequencer-client';
396
+ import { createProverNode } from '@aztec/prover-node';
397
+ import { createKeyStoreForProver } from '@aztec/prover-node/config';
398
+ import { GlobalVariableBuilder, SequencerClient } from '@aztec/sequencer-client';
32
399
  import { PublicProcessorFactory } from '@aztec/simulator/server';
33
400
  import { AttestationsBlockWatcher, EpochPruneWatcher, createSlasher } from '@aztec/slasher';
34
401
  import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
35
402
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
36
- import { L2BlockHash } from '@aztec/stdlib/block';
403
+ import { BlockHash, L2Block } from '@aztec/stdlib/block';
37
404
  import { GasFees } from '@aztec/stdlib/gas';
38
405
  import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
39
406
  import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
40
407
  import { tryStop } from '@aztec/stdlib/interfaces/server';
408
+ import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
41
409
  import { InboxLeaf } from '@aztec/stdlib/messaging';
42
- import { P2PClientType } from '@aztec/stdlib/p2p';
43
410
  import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
44
411
  import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
45
412
  import { getPackageVersion } from '@aztec/stdlib/update-checker';
46
413
  import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
47
- import { NodeKeystoreAdapter, ValidatorClient, createBlockProposalHandler, createValidatorClient } from '@aztec/validator-client';
414
+ import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createBlockProposalHandler, createValidatorClient } from '@aztec/validator-client';
48
415
  import { createWorldStateSynchronizer } from '@aztec/world-state';
49
416
  import { createPublicClient, fallback, http } from 'viem';
50
417
  import { createSentinel } from '../sentinel/factory.js';
51
418
  import { createKeyStoreForValidator } from './config.js';
52
419
  import { NodeMetrics } from './node_metrics.js';
420
+ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
421
+ [Attributes.TX_HASH]: tx.getTxHash().toString()
422
+ }));
53
423
  /**
54
424
  * The aztec node.
55
425
  */ export class AztecNodeService {
@@ -61,6 +431,7 @@ import { NodeMetrics } from './node_metrics.js';
61
431
  l1ToL2MessageSource;
62
432
  worldStateSynchronizer;
63
433
  sequencer;
434
+ proverNode;
64
435
  slasherClient;
65
436
  validatorsSentinel;
66
437
  epochPruneWatcher;
@@ -72,11 +443,25 @@ import { NodeMetrics } from './node_metrics.js';
72
443
  proofVerifier;
73
444
  telemetry;
74
445
  log;
446
+ blobClient;
447
+ validatorClient;
448
+ keyStoreManager;
449
+ debugLogStore;
450
+ static{
451
+ ({ e: [_initProto] } = _apply_decs_2203_r(this, [
452
+ [
453
+ _dec,
454
+ 2,
455
+ "simulatePublicCalls"
456
+ ]
457
+ ], []));
458
+ }
75
459
  metrics;
460
+ initialHeaderHashPromise;
76
461
  // Prevent two snapshot operations to happen simultaneously
77
462
  isUploadingSnapshot;
78
463
  tracer;
79
- constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry = getTelemetryClient(), log = createLogger('node')){
464
+ 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()){
80
465
  this.config = config;
81
466
  this.p2pClient = p2pClient;
82
467
  this.blockSource = blockSource;
@@ -85,6 +470,7 @@ import { NodeMetrics } from './node_metrics.js';
85
470
  this.l1ToL2MessageSource = l1ToL2MessageSource;
86
471
  this.worldStateSynchronizer = worldStateSynchronizer;
87
472
  this.sequencer = sequencer;
473
+ this.proverNode = proverNode;
88
474
  this.slasherClient = slasherClient;
89
475
  this.validatorsSentinel = validatorsSentinel;
90
476
  this.epochPruneWatcher = epochPruneWatcher;
@@ -96,11 +482,22 @@ import { NodeMetrics } from './node_metrics.js';
96
482
  this.proofVerifier = proofVerifier;
97
483
  this.telemetry = telemetry;
98
484
  this.log = log;
485
+ this.blobClient = blobClient;
486
+ this.validatorClient = validatorClient;
487
+ this.keyStoreManager = keyStoreManager;
488
+ this.debugLogStore = debugLogStore;
489
+ this.initialHeaderHashPromise = (_initProto(this), undefined);
99
490
  this.isUploadingSnapshot = false;
100
491
  this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
101
492
  this.tracer = telemetry.getTracer('AztecNodeService');
102
493
  this.log.info(`Aztec Node version: ${this.packageVersion}`);
103
494
  this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
495
+ // A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
496
+ // never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
497
+ // memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
498
+ if (debugLogStore.isEnabled && config.realProofs) {
499
+ throw new Error('debugLogStore should never be enabled when realProofs are set');
500
+ }
104
501
  }
105
502
  async getWorldStateSyncStatus() {
106
503
  const status = await this.worldStateSynchronizer.status();
@@ -122,16 +519,27 @@ import { NodeMetrics } from './node_metrics.js';
122
519
  const telemetry = deps.telemetry ?? getTelemetryClient();
123
520
  const dateProvider = deps.dateProvider ?? new DateProvider();
124
521
  const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
125
- // Build a key store from file if given or from environment otherwise
522
+ // Build a key store from file if given or from environment otherwise.
523
+ // We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
126
524
  let keyStoreManager;
127
525
  const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
128
526
  if (keyStoreProvided) {
129
527
  const keyStores = loadKeystores(config.keyStoreDirectory);
130
528
  keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
131
529
  } else {
132
- const keyStore = createKeyStoreForValidator(config);
133
- if (keyStore) {
134
- keyStoreManager = new KeystoreManager(keyStore);
530
+ const rawKeyStores = [];
531
+ const validatorKeyStore = createKeyStoreForValidator(config);
532
+ if (validatorKeyStore) {
533
+ rawKeyStores.push(validatorKeyStore);
534
+ }
535
+ if (config.enableProverNode) {
536
+ const proverKeyStore = createKeyStoreForProver(config);
537
+ if (proverKeyStore) {
538
+ rawKeyStores.push(proverKeyStore);
539
+ }
540
+ }
541
+ if (rawKeyStores.length > 0) {
542
+ keyStoreManager = new KeystoreManager(rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores));
135
543
  }
136
544
  }
137
545
  await keyStoreManager?.validateSigners();
@@ -140,8 +548,8 @@ import { NodeMetrics } from './node_metrics.js';
140
548
  if (keyStoreManager === undefined) {
141
549
  throw new Error('Failed to create key store, a requirement for running a validator');
142
550
  }
143
- if (!keyStoreProvided) {
144
- log.warn('KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS');
551
+ if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
552
+ log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
145
553
  }
146
554
  ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
147
555
  }
@@ -163,29 +571,17 @@ import { NodeMetrics } from './node_metrics.js';
163
571
  ...l1ContractsAddresses
164
572
  };
165
573
  const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
166
- const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
574
+ const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
167
575
  rollupContract.getL1GenesisTime(),
168
576
  rollupContract.getSlotDuration(),
169
- rollupContract.getVersion()
577
+ rollupContract.getVersion(),
578
+ rollupContract.getManaLimit().then(Number)
170
579
  ]);
171
580
  config.rollupVersion ??= Number(rollupVersionFromRollup);
172
581
  if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
173
582
  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}).`);
174
583
  }
175
- const blobFileStoreMetadata = {
176
- l1ChainId: config.l1ChainId,
177
- rollupVersion: config.rollupVersion,
178
- rollupAddress: config.l1Contracts.rollupAddress.toString()
179
- };
180
- const [fileStoreClients, fileStoreUploadClient] = await Promise.all([
181
- createReadOnlyFileStoreBlobClients(config.blobFileStoreUrls, blobFileStoreMetadata, log),
182
- createWritableFileStoreBlobClient(config.blobFileStoreUploadUrl, blobFileStoreMetadata, log)
183
- ]);
184
- const blobClient = deps.blobClient ?? createBlobClient(config, {
185
- logger: createLogger('node:blob-client:client'),
186
- fileStoreClients,
187
- fileStoreUploadClient
188
- });
584
+ const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
189
585
  // attempt snapshot sync if possible
190
586
  await trySnapshotSync(config, log);
191
587
  const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, {
@@ -202,74 +598,95 @@ import { NodeMetrics } from './node_metrics.js';
202
598
  // now create the merkle trees and the world state synchronizer
203
599
  const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.prefilledPublicData, telemetry);
204
600
  const circuitVerifier = config.realProofs || config.debugForceTxProofVerification ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
601
+ let debugLogStore;
205
602
  if (!config.realProofs) {
206
603
  log.warn(`Aztec node is accepting fake proofs`);
604
+ debugLogStore = new InMemoryDebugLogStore();
605
+ log.info('Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served');
606
+ } else {
607
+ debugLogStore = new NullDebugLogStore();
207
608
  }
208
609
  const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
610
+ const proverOnly = config.enableProverNode && config.disableValidator;
611
+ if (proverOnly) {
612
+ log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
613
+ }
209
614
  // create the tx pool and the p2p client, which will need the l2 block source
210
- const p2pClient = await createP2PClient(P2PClientType.Full, config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
211
- // We should really not be modifying the config object
212
- config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
213
- const blockBuilder = new BlockBuilder({
615
+ const p2pClient = await createP2PClient(config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
616
+ // We'll accumulate sentinel watchers here
617
+ const watchers = [];
618
+ // Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
619
+ // Override maxTxsPerCheckpoint with the validator-specific limit if set.
620
+ const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
214
621
  ...config,
215
622
  l1GenesisTime,
216
- slotDuration: Number(slotDuration)
623
+ slotDuration: Number(slotDuration),
624
+ rollupManaLimit,
625
+ maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
217
626
  }, worldStateSynchronizer, archiver, dateProvider, telemetry);
218
- // We'll accumulate sentinel watchers here
219
- const watchers = [];
220
- // Create validator client if required
221
- const validatorClient = createValidatorClient(config, {
222
- p2pClient,
223
- telemetry,
224
- dateProvider,
225
- epochCache,
226
- blockBuilder,
227
- blockSource: archiver,
228
- l1ToL2MessageSource: archiver,
229
- keyStoreManager,
230
- fileStoreBlobUploadClient: fileStoreUploadClient
231
- });
232
- // If we have a validator client, register it as a source of offenses for the slasher,
233
- // and have it register callbacks on the p2p client *before* we start it, otherwise messages
234
- // like attestations or auths will fail.
235
- if (validatorClient) {
236
- watchers.push(validatorClient);
237
- if (!options.dontStartSequencer) {
238
- await validatorClient.registerHandlers();
627
+ let validatorClient;
628
+ if (!proverOnly) {
629
+ // Create validator client if required
630
+ validatorClient = await createValidatorClient(config, {
631
+ checkpointsBuilder: validatorCheckpointsBuilder,
632
+ worldState: worldStateSynchronizer,
633
+ p2pClient,
634
+ telemetry,
635
+ dateProvider,
636
+ epochCache,
637
+ blockSource: archiver,
638
+ l1ToL2MessageSource: archiver,
639
+ keyStoreManager,
640
+ blobClient
641
+ });
642
+ // If we have a validator client, register it as a source of offenses for the slasher,
643
+ // and have it register callbacks on the p2p client *before* we start it, otherwise messages
644
+ // like attestations or auths will fail.
645
+ if (validatorClient) {
646
+ watchers.push(validatorClient);
647
+ if (!options.dontStartSequencer) {
648
+ await validatorClient.registerHandlers();
649
+ }
239
650
  }
240
651
  }
241
- // If there's no validator client but alwaysReexecuteBlockProposals is enabled,
242
- // create a BlockProposalHandler to reexecute block proposals for monitoring
243
- if (!validatorClient && config.alwaysReexecuteBlockProposals) {
244
- log.info('Setting up block proposal reexecution for monitoring');
652
+ // If there's no validator client, create a BlockProposalHandler to handle block proposals
653
+ // for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
654
+ // while non-reexecution is used for validating the proposals and collecting their txs.
655
+ if (!validatorClient) {
656
+ const reexecute = !!config.alwaysReexecuteBlockProposals;
657
+ log.info(`Setting up block proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
245
658
  createBlockProposalHandler(config, {
246
- blockBuilder,
659
+ checkpointsBuilder: validatorCheckpointsBuilder,
660
+ worldState: worldStateSynchronizer,
247
661
  epochCache,
248
662
  blockSource: archiver,
249
663
  l1ToL2MessageSource: archiver,
250
664
  p2pClient,
251
665
  dateProvider,
252
666
  telemetry
253
- }).registerForReexecution(p2pClient);
667
+ }).register(p2pClient, reexecute);
254
668
  }
255
669
  // Start world state and wait for it to sync to the archiver.
256
670
  await worldStateSynchronizer.start();
257
671
  // Start p2p. Note that it depends on world state to be running.
258
672
  await p2pClient.start();
259
- const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
260
- if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
261
- watchers.push(validatorsSentinel);
262
- }
673
+ let validatorsSentinel;
263
674
  let epochPruneWatcher;
264
- if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
265
- epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), blockBuilder, config);
266
- watchers.push(epochPruneWatcher);
267
- }
268
- // We assume we want to slash for invalid attestations unless all max penalties are set to 0
269
675
  let attestationsBlockWatcher;
270
- if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
271
- attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
272
- watchers.push(attestationsBlockWatcher);
676
+ if (!proverOnly) {
677
+ validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
678
+ if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
679
+ watchers.push(validatorsSentinel);
680
+ }
681
+ if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
682
+ epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
683
+ watchers.push(epochPruneWatcher);
684
+ }
685
+ // We assume we want to slash for invalid attestations unless all max penalties are set to 0
686
+ if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
687
+ attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
688
+ watchers.push(attestationsBlockWatcher);
689
+ }
273
690
  }
274
691
  // Start p2p-related services once the archiver has completed sync
275
692
  void archiver.waitForInitialSync().then(async ()=>{
@@ -288,27 +705,30 @@ import { NodeMetrics } from './node_metrics.js';
288
705
  const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
289
706
  slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
290
707
  await slasherClient.start();
291
- const l1TxUtils = config.publisherForwarderAddress ? await createForwarderL1TxUtilsFromEthSigner(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.publisherForwarderAddress, {
708
+ const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
292
709
  ...config,
293
710
  scope: 'sequencer'
294
711
  }, {
295
712
  telemetry,
296
713
  logger: log.createChild('l1-tx-utils'),
297
- dateProvider
298
- }) : await createL1TxUtilsWithBlobsFromEthSigner(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
714
+ dateProvider,
715
+ kzg: Blob.getViemKzgInstance()
716
+ }) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
299
717
  ...config,
300
718
  scope: 'sequencer'
301
719
  }, {
302
720
  telemetry,
303
721
  logger: log.createChild('l1-tx-utils'),
304
- dateProvider
722
+ dateProvider,
723
+ kzg: Blob.getViemKzgInstance()
305
724
  });
306
725
  // Create and start the sequencer client
307
726
  const checkpointsBuilder = new CheckpointsBuilder({
308
727
  ...config,
309
728
  l1GenesisTime,
310
- slotDuration: Number(slotDuration)
311
- }, archiver, dateProvider, telemetry);
729
+ slotDuration: Number(slotDuration),
730
+ rollupManaLimit
731
+ }, worldStateSynchronizer, archiver, dateProvider, telemetry, debugLogStore);
312
732
  sequencer = await SequencerClient.new(config, {
313
733
  ...deps,
314
734
  epochCache,
@@ -332,13 +752,35 @@ import { NodeMetrics } from './node_metrics.js';
332
752
  } else if (sequencer) {
333
753
  log.warn(`Sequencer created but not started`);
334
754
  }
755
+ // Create prover node subsystem if enabled
756
+ let proverNode;
757
+ if (config.enableProverNode) {
758
+ proverNode = await createProverNode(config, {
759
+ ...deps.proverNodeDeps,
760
+ telemetry,
761
+ dateProvider,
762
+ archiver,
763
+ worldStateSynchronizer,
764
+ p2pClient,
765
+ epochCache,
766
+ blobClient,
767
+ keyStoreManager
768
+ });
769
+ if (!options.dontStartProverNode) {
770
+ await proverNode.start();
771
+ log.info(`Prover node subsystem started`);
772
+ } else {
773
+ log.info(`Prover node subsystem created but not started`);
774
+ }
775
+ }
335
776
  const globalVariableBuilder = new GlobalVariableBuilder({
336
777
  ...config,
337
778
  rollupVersion: BigInt(config.rollupVersion),
338
779
  l1GenesisTime,
339
780
  slotDuration: Number(slotDuration)
340
781
  });
341
- return new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry, log);
782
+ 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);
783
+ return node;
342
784
  }
343
785
  /**
344
786
  * Returns the sequencer client instance.
@@ -346,6 +788,9 @@ import { NodeMetrics } from './node_metrics.js';
346
788
  */ getSequencer() {
347
789
  return this.sequencer;
348
790
  }
791
+ /** Returns the prover node subsystem, if enabled. */ getProverNode() {
792
+ return this.proverNode;
793
+ }
349
794
  getBlockSource() {
350
795
  return this.blockSource;
351
796
  }
@@ -365,7 +810,10 @@ import { NodeMetrics } from './node_metrics.js';
365
810
  return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
366
811
  }
367
812
  async getAllowedPublicSetup() {
368
- return this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
813
+ return [
814
+ ...await getDefaultAllowedSetupFunctions(),
815
+ ...this.config.txPublicSetupAllowListExtend ?? []
816
+ ];
369
817
  }
370
818
  /**
371
819
  * Method to determine if the node is ready to accept transactions.
@@ -388,33 +836,46 @@ import { NodeMetrics } from './node_metrics.js';
388
836
  rollupVersion,
389
837
  enr,
390
838
  l1ContractAddresses: contractAddresses,
391
- protocolContractAddresses: protocolContractAddresses
839
+ protocolContractAddresses: protocolContractAddresses,
840
+ realProofs: !!this.config.realProofs
392
841
  };
393
842
  return nodeInfo;
394
843
  }
395
844
  /**
396
- * Get a block specified by its number.
397
- * @param number - The block number being requested.
845
+ * Get a block specified by its block number, block hash, or 'latest'.
846
+ * @param block - The block parameter (block number, block hash, or 'latest').
398
847
  * @returns The requested block.
399
- */ async getBlock(number) {
400
- const blockNumber = number === 'latest' ? await this.getBlockNumber() : number;
401
- return await this.blockSource.getBlock(blockNumber);
848
+ */ async getBlock(block) {
849
+ if (BlockHash.isBlockHash(block)) {
850
+ return this.getBlockByHash(block);
851
+ }
852
+ const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
853
+ if (blockNumber === BlockNumber.ZERO) {
854
+ return this.buildInitialBlock();
855
+ }
856
+ return await this.blockSource.getL2Block(blockNumber);
402
857
  }
403
858
  /**
404
859
  * Get a block specified by its hash.
405
860
  * @param blockHash - The block hash being requested.
406
861
  * @returns The requested block.
407
862
  */ async getBlockByHash(blockHash) {
408
- const publishedBlock = await this.blockSource.getPublishedBlockByHash(blockHash);
409
- return publishedBlock?.block;
863
+ const initialBlockHash = await this.#getInitialHeaderHash();
864
+ if (blockHash.equals(initialBlockHash)) {
865
+ return this.buildInitialBlock();
866
+ }
867
+ return await this.blockSource.getL2BlockByHash(blockHash);
868
+ }
869
+ buildInitialBlock() {
870
+ const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
871
+ return L2Block.empty(initialHeader);
410
872
  }
411
873
  /**
412
874
  * Get a block specified by its archive root.
413
875
  * @param archive - The archive root being requested.
414
876
  * @returns The requested block.
415
877
  */ async getBlockByArchive(archive) {
416
- const publishedBlock = await this.blockSource.getPublishedBlockByArchive(archive);
417
- return publishedBlock?.block;
878
+ return await this.blockSource.getL2BlockByArchive(archive);
418
879
  }
419
880
  /**
420
881
  * Method to request blocks. Will attempt to return all requested blocks but will return only those available.
@@ -422,16 +883,19 @@ import { NodeMetrics } from './node_metrics.js';
422
883
  * @param limit - The maximum number of blocks to obtain.
423
884
  * @returns The blocks requested.
424
885
  */ async getBlocks(from, limit) {
425
- return await this.blockSource.getBlocks(from, limit) ?? [];
886
+ return await this.blockSource.getBlocks(from, BlockNumber(limit)) ?? [];
887
+ }
888
+ async getCheckpoints(from, limit) {
889
+ return await this.blockSource.getCheckpoints(from, limit) ?? [];
426
890
  }
427
- async getPublishedBlocks(from, limit) {
428
- return await this.blockSource.getPublishedBlocks(from, limit) ?? [];
891
+ async getCheckpointedBlocks(from, limit) {
892
+ return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
429
893
  }
430
894
  /**
431
- * Method to fetch the current base fees.
432
- * @returns The current base fees.
433
- */ async getCurrentBaseFees() {
434
- return await this.globalVariableBuilder.getCurrentBaseFees();
895
+ * Method to fetch the current min L2 fees.
896
+ * @returns The current min L2 fees.
897
+ */ async getCurrentMinFees() {
898
+ return await this.globalVariableBuilder.getCurrentMinFees();
435
899
  }
436
900
  async getMaxPriorityFees() {
437
901
  for await (const tx of this.p2pClient.iteratePendingTxs()){
@@ -451,6 +915,12 @@ import { NodeMetrics } from './node_metrics.js';
451
915
  async getProvenBlockNumber() {
452
916
  return await this.blockSource.getProvenBlockNumber();
453
917
  }
918
+ async getCheckpointedBlockNumber() {
919
+ return await this.blockSource.getCheckpointedL2BlockNumber();
920
+ }
921
+ getCheckpointNumber() {
922
+ return this.blockSource.getCheckpointNumber();
923
+ }
454
924
  /**
455
925
  * Method to fetch the version of the package.
456
926
  * @returns The node package version
@@ -475,11 +945,29 @@ import { NodeMetrics } from './node_metrics.js';
475
945
  getContract(address) {
476
946
  return this.contractDataSource.getContract(address);
477
947
  }
478
- getPrivateLogsByTags(tags) {
479
- return this.logsSource.getPrivateLogsByTags(tags);
480
- }
481
- getPublicLogsByTagsFromContract(contractAddress, tags) {
482
- return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags);
948
+ async getPrivateLogsByTags(tags, page, referenceBlock) {
949
+ if (referenceBlock) {
950
+ const initialBlockHash = await this.#getInitialHeaderHash();
951
+ if (!referenceBlock.equals(initialBlockHash)) {
952
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
953
+ if (!header) {
954
+ throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
955
+ }
956
+ }
957
+ }
958
+ return this.logsSource.getPrivateLogsByTags(tags, page);
959
+ }
960
+ async getPublicLogsByTagsFromContract(contractAddress, tags, page, referenceBlock) {
961
+ if (referenceBlock) {
962
+ const initialBlockHash = await this.#getInitialHeaderHash();
963
+ if (!referenceBlock.equals(initialBlockHash)) {
964
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
965
+ if (!header) {
966
+ throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
967
+ }
968
+ }
969
+ }
970
+ return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
483
971
  }
484
972
  /**
485
973
  * Gets public logs based on the provided filter.
@@ -514,24 +1002,33 @@ import { NodeMetrics } from './node_metrics.js';
514
1002
  throw new Error(`Invalid tx: ${reason}`);
515
1003
  }
516
1004
  await this.p2pClient.sendTx(tx);
517
- this.metrics.receivedTx(timer.ms(), true);
518
- this.log.info(`Received tx ${txHash}`, {
1005
+ const duration = timer.ms();
1006
+ this.metrics.receivedTx(duration, true);
1007
+ this.log.info(`Received tx ${txHash} in ${duration}ms`, {
519
1008
  txHash
520
1009
  });
521
1010
  }
522
1011
  async getTxReceipt(txHash) {
523
- let txReceipt = new TxReceipt(txHash, TxStatus.DROPPED, 'Tx dropped by P2P node.');
524
- // We first check if the tx is in pending (instead of first checking if it is mined) because if we first check
525
- // for mined and then for pending there could be a race condition where the tx is mined between the two checks
526
- // and we would incorrectly return a TxReceipt with status DROPPED
527
- if (await this.p2pClient.getTxStatus(txHash) === 'pending') {
528
- txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
529
- }
1012
+ // Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
1013
+ // as a fallback if we don't find a settled receipt in the archiver.
1014
+ const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
1015
+ const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
1016
+ // Then get the actual tx from the archiver, which tracks every tx in a mined block.
530
1017
  const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
1018
+ let receipt;
531
1019
  if (settledTxReceipt) {
532
- txReceipt = settledTxReceipt;
1020
+ receipt = settledTxReceipt;
1021
+ } else if (isKnownToPool) {
1022
+ // If the tx is in the pool but not in the archiver, it's pending.
1023
+ // This handles race conditions between archiver and p2p, where the archiver
1024
+ // has pruned the block in which a tx was mined, but p2p has not caught up yet.
1025
+ receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
1026
+ } else {
1027
+ // Otherwise, if we don't know the tx, we consider it dropped.
1028
+ receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
533
1029
  }
534
- return txReceipt;
1030
+ this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
1031
+ return receipt;
535
1032
  }
536
1033
  getTxEffect(txHash) {
537
1034
  return this.blockSource.getTxEffect(txHash);
@@ -545,13 +1042,21 @@ import { NodeMetrics } from './node_metrics.js';
545
1042
  await tryStop(this.slasherClient);
546
1043
  await tryStop(this.proofVerifier);
547
1044
  await tryStop(this.sequencer);
1045
+ await tryStop(this.proverNode);
548
1046
  await tryStop(this.p2pClient);
549
1047
  await tryStop(this.worldStateSynchronizer);
550
1048
  await tryStop(this.blockSource);
1049
+ await tryStop(this.blobClient);
551
1050
  await tryStop(this.telemetry);
552
1051
  this.log.info(`Stopped Aztec Node`);
553
1052
  }
554
1053
  /**
1054
+ * Returns the blob client used by this node.
1055
+ * @internal - Exposed for testing purposes only.
1056
+ */ getBlobClient() {
1057
+ return this.blobClient;
1058
+ }
1059
+ /**
555
1060
  * Method to retrieve pending txs.
556
1061
  * @param limit - The number of items to returns
557
1062
  * @param after - The last known pending tx. Used for pagination
@@ -576,15 +1081,8 @@ import { NodeMetrics } from './node_metrics.js';
576
1081
  */ async getTxsByHash(txHashes) {
577
1082
  return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
578
1083
  }
579
- /**
580
- * Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
581
- * the leaves were inserted.
582
- * @param blockNumber - The block number at which to get the data or 'latest' for latest data.
583
- * @param treeId - The tree to search in.
584
- * @param leafValues - The values to search for.
585
- * @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
586
- */ async findLeavesIndexes(blockNumber, treeId, leafValues) {
587
- const committedDb = await this.#getWorldState(blockNumber);
1084
+ async findLeavesIndexes(referenceBlock, treeId, leafValues) {
1085
+ const committedDb = await this.#getWorldState(referenceBlock);
588
1086
  const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
589
1087
  // We filter out undefined values
590
1088
  const indices = maybeIndices.filter((x)=>x !== undefined);
@@ -627,50 +1125,27 @@ import { NodeMetrics } from './node_metrics.js';
627
1125
  }
628
1126
  return {
629
1127
  l2BlockNumber: BlockNumber(Number(blockNumber)),
630
- l2BlockHash: L2BlockHash.fromField(blockHash),
1128
+ l2BlockHash: new BlockHash(blockHash),
631
1129
  data: index
632
1130
  };
633
1131
  });
634
1132
  }
635
- /**
636
- * Returns a sibling path for the given index in the nullifier tree.
637
- * @param blockNumber - The block number at which to get the data.
638
- * @param leafIndex - The index of the leaf for which the sibling path is required.
639
- * @returns The sibling path for the leaf index.
640
- */ async getNullifierSiblingPath(blockNumber, leafIndex) {
641
- const committedDb = await this.#getWorldState(blockNumber);
642
- return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
643
- }
644
- /**
645
- * Returns a sibling path for the given index in the data tree.
646
- * @param blockNumber - The block number at which to get the data.
647
- * @param leafIndex - The index of the leaf for which the sibling path is required.
648
- * @returns The sibling path for the leaf index.
649
- */ async getNoteHashSiblingPath(blockNumber, leafIndex) {
650
- const committedDb = await this.#getWorldState(blockNumber);
651
- return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
652
- }
653
- async getArchiveMembershipWitness(blockNumber, archive) {
654
- const committedDb = await this.#getWorldState(blockNumber);
1133
+ async getBlockHashMembershipWitness(referenceBlock, blockHash) {
1134
+ const committedDb = await this.#getWorldState(referenceBlock);
655
1135
  const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
656
- archive
1136
+ blockHash
657
1137
  ]);
658
1138
  return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
659
1139
  }
660
- async getNoteHashMembershipWitness(blockNumber, noteHash) {
661
- const committedDb = await this.#getWorldState(blockNumber);
1140
+ async getNoteHashMembershipWitness(referenceBlock, noteHash) {
1141
+ const committedDb = await this.#getWorldState(referenceBlock);
662
1142
  const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
663
1143
  noteHash
664
1144
  ]);
665
1145
  return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
666
1146
  }
667
- /**
668
- * Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
669
- * @param blockNumber - The block number at which to get the data.
670
- * @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
671
- * @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
672
- */ async getL1ToL2MessageMembershipWitness(blockNumber, l1ToL2Message) {
673
- const db = await this.#getWorldState(blockNumber);
1147
+ async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
1148
+ const db = await this.#getWorldState(referenceBlock);
674
1149
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
675
1150
  l1ToL2Message
676
1151
  ]);
@@ -683,9 +1158,9 @@ import { NodeMetrics } from './node_metrics.js';
683
1158
  witness.path
684
1159
  ];
685
1160
  }
686
- async getL1ToL2MessageBlock(l1ToL2Message) {
1161
+ async getL1ToL2MessageCheckpoint(l1ToL2Message) {
687
1162
  const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
688
- return messageIndex ? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex)) : undefined;
1163
+ return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
689
1164
  }
690
1165
  /**
691
1166
  * Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
@@ -696,38 +1171,29 @@ import { NodeMetrics } from './node_metrics.js';
696
1171
  return messageIndex !== undefined;
697
1172
  }
698
1173
  /**
699
- * Returns all the L2 to L1 messages in a block.
700
- * @param blockNumber - The block number at which to get the data.
701
- * @returns The L2 to L1 messages (undefined if the block number is not found).
702
- */ async getL2ToL1Messages(blockNumber) {
703
- const block = await this.blockSource.getBlock(blockNumber === 'latest' ? await this.getBlockNumber() : blockNumber);
704
- return block?.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs);
705
- }
706
- /**
707
- * Returns a sibling path for a leaf in the committed blocks tree.
708
- * @param blockNumber - The block number at which to get the data.
709
- * @param leafIndex - Index of the leaf in the tree.
710
- * @returns The sibling path.
711
- */ async getArchiveSiblingPath(blockNumber, leafIndex) {
712
- const committedDb = await this.#getWorldState(blockNumber);
713
- return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
714
- }
715
- /**
716
- * Returns a sibling path for a leaf in the committed public data tree.
717
- * @param blockNumber - The block number at which to get the data.
718
- * @param leafIndex - Index of the leaf in the tree.
719
- * @returns The sibling path.
720
- */ async getPublicDataSiblingPath(blockNumber, leafIndex) {
721
- const committedDb = await this.#getWorldState(blockNumber);
722
- return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
1174
+ * Returns all the L2 to L1 messages in an epoch.
1175
+ * @param epoch - The epoch at which to get the data.
1176
+ * @returns The L2 to L1 messages (empty array if the epoch is not found).
1177
+ */ async getL2ToL1Messages(epoch) {
1178
+ // Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
1179
+ const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
1180
+ const blocksInCheckpoints = [];
1181
+ let previousSlotNumber = SlotNumber.ZERO;
1182
+ let checkpointIndex = -1;
1183
+ for (const checkpointedBlock of checkpointedBlocks){
1184
+ const block = checkpointedBlock.block;
1185
+ const slotNumber = block.header.globalVariables.slotNumber;
1186
+ if (slotNumber !== previousSlotNumber) {
1187
+ checkpointIndex++;
1188
+ blocksInCheckpoints.push([]);
1189
+ previousSlotNumber = slotNumber;
1190
+ }
1191
+ blocksInCheckpoints[checkpointIndex].push(block);
1192
+ }
1193
+ return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
723
1194
  }
724
- /**
725
- * Returns a nullifier membership witness for a given nullifier at a given block.
726
- * @param blockNumber - The block number at which to get the index.
727
- * @param nullifier - Nullifier we try to find witness for.
728
- * @returns The nullifier membership witness (if found).
729
- */ async getNullifierMembershipWitness(blockNumber, nullifier) {
730
- const db = await this.#getWorldState(blockNumber);
1195
+ async getNullifierMembershipWitness(referenceBlock, nullifier) {
1196
+ const db = await this.#getWorldState(referenceBlock);
731
1197
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
732
1198
  nullifier.toBuffer()
733
1199
  ]);
@@ -743,7 +1209,8 @@ import { NodeMetrics } from './node_metrics.js';
743
1209
  }
744
1210
  /**
745
1211
  * Returns a low nullifier membership witness for a given nullifier at a given block.
746
- * @param blockNumber - The block number at which to get the index.
1212
+ * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
1213
+ * (which contains the root of the nullifier tree in which we are searching for the nullifier).
747
1214
  * @param nullifier - Nullifier we try to find the low nullifier witness for.
748
1215
  * @returns The low nullifier membership witness (if found).
749
1216
  * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
@@ -754,8 +1221,8 @@ import { NodeMetrics } from './node_metrics.js';
754
1221
  * the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
755
1222
  * index of the nullifier itself when it already exists in the tree.
756
1223
  * TODO: This is a confusing behavior and we should eventually address that.
757
- */ async getLowNullifierMembershipWitness(blockNumber, nullifier) {
758
- const committedDb = await this.#getWorldState(blockNumber);
1224
+ */ async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
1225
+ const committedDb = await this.#getWorldState(referenceBlock);
759
1226
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
760
1227
  if (!findResult) {
761
1228
  return undefined;
@@ -768,8 +1235,8 @@ import { NodeMetrics } from './node_metrics.js';
768
1235
  const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
769
1236
  return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
770
1237
  }
771
- async getPublicDataWitness(blockNumber, leafSlot) {
772
- const committedDb = await this.#getWorldState(blockNumber);
1238
+ async getPublicDataWitness(referenceBlock, leafSlot) {
1239
+ const committedDb = await this.#getWorldState(referenceBlock);
773
1240
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
774
1241
  if (!lowLeafResult) {
775
1242
  return undefined;
@@ -779,18 +1246,8 @@ import { NodeMetrics } from './node_metrics.js';
779
1246
  return new PublicDataWitness(lowLeafResult.index, preimage, path);
780
1247
  }
781
1248
  }
782
- /**
783
- * Gets the storage value at the given contract storage slot.
784
- *
785
- * @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
786
- * Aztec's version of `eth_getStorageAt`.
787
- *
788
- * @param contract - Address of the contract to query.
789
- * @param slot - Slot to query.
790
- * @param blockNumber - The block number at which to get the data or 'latest'.
791
- * @returns Storage value at the given contract slot.
792
- */ async getPublicStorageAt(blockNumber, contract, slot) {
793
- const committedDb = await this.#getWorldState(blockNumber);
1249
+ async getPublicStorageAt(referenceBlock, contract, slot) {
1250
+ const committedDb = await this.#getWorldState(referenceBlock);
794
1251
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
795
1252
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
796
1253
  if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
@@ -799,18 +1256,22 @@ import { NodeMetrics } from './node_metrics.js';
799
1256
  const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
800
1257
  return preimage.leaf.value;
801
1258
  }
802
- /**
803
- * Returns the currently committed block header, or the initial header if no blocks have been produced.
804
- * @returns The current committed block header.
805
- */ async getBlockHeader(blockNumber = 'latest') {
806
- return blockNumber === BlockNumber.ZERO || blockNumber === 'latest' && await this.blockSource.getBlockNumber() === BlockNumber.ZERO ? this.worldStateSynchronizer.getCommitted().getInitialHeader() : this.blockSource.getBlockHeader(blockNumber === 'latest' ? blockNumber : blockNumber);
807
- }
808
- /**
809
- * Get a block header specified by its hash.
810
- * @param blockHash - The block hash being requested.
811
- * @returns The requested block header.
812
- */ async getBlockHeaderByHash(blockHash) {
813
- return await this.blockSource.getBlockHeaderByHash(blockHash);
1259
+ async getBlockHeader(block = 'latest') {
1260
+ if (BlockHash.isBlockHash(block)) {
1261
+ const initialBlockHash = await this.#getInitialHeaderHash();
1262
+ if (block.equals(initialBlockHash)) {
1263
+ // Block source doesn't handle initial header so we need to handle the case separately.
1264
+ return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1265
+ }
1266
+ return this.blockSource.getBlockHeaderByHash(block);
1267
+ } else {
1268
+ // Block source doesn't handle initial header so we need to handle the case separately.
1269
+ const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
1270
+ if (blockNumber === BlockNumber.ZERO) {
1271
+ return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1272
+ }
1273
+ return this.blockSource.getBlockHeader(block);
1274
+ }
814
1275
  }
815
1276
  /**
816
1277
  * Get a block header specified by its archive root.
@@ -819,6 +1280,12 @@ import { NodeMetrics } from './node_metrics.js';
819
1280
  */ async getBlockHeaderByArchive(archive) {
820
1281
  return await this.blockSource.getBlockHeaderByArchive(archive);
821
1282
  }
1283
+ getBlockData(number) {
1284
+ return this.blockSource.getBlockData(number);
1285
+ }
1286
+ getBlockDataByArchive(archive) {
1287
+ return this.blockSource.getBlockDataByArchive(archive);
1288
+ }
822
1289
  /**
823
1290
  * Simulates the public part of a transaction with the current state.
824
1291
  * @param tx - The transaction to simulate.
@@ -831,17 +1298,20 @@ import { NodeMetrics } from './node_metrics.js';
831
1298
  throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
832
1299
  }
833
1300
  const txHash = tx.getTxHash();
834
- const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
1301
+ const latestBlockNumber = await this.blockSource.getBlockNumber();
1302
+ const blockNumber = BlockNumber.add(latestBlockNumber, 1);
835
1303
  // If sequencer is not initialized, we just set these values to zero for simulation.
836
1304
  const coinbase = EthAddress.ZERO;
837
1305
  const feeRecipient = AztecAddress.ZERO;
838
1306
  const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(blockNumber, coinbase, feeRecipient);
839
- const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry);
1307
+ const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry, this.log.getBindings());
840
1308
  this.log.verbose(`Simulating public calls for tx ${txHash}`, {
841
1309
  globalVariables: newGlobalVariables.toInspect(),
842
1310
  txHash,
843
1311
  blockNumber
844
1312
  });
1313
+ // Ensure world-state has caught up with the latest block we loaded from the archiver
1314
+ await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
845
1315
  const merkleTreeFork = await this.worldStateSynchronizer.fork();
846
1316
  try {
847
1317
  const config = PublicSimulatorConfig.from({
@@ -856,7 +1326,7 @@ import { NodeMetrics } from './node_metrics.js';
856
1326
  });
857
1327
  const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
858
1328
  // REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
859
- const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
1329
+ const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([
860
1330
  tx
861
1331
  ]);
862
1332
  // REFACTOR: Consider returning the error rather than throwing
@@ -867,7 +1337,7 @@ import { NodeMetrics } from './node_metrics.js';
867
1337
  throw failedTxs[0].error;
868
1338
  }
869
1339
  const [processedTx] = processedTxs;
870
- return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed);
1340
+ return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed, debugLogs);
871
1341
  } finally{
872
1342
  await merkleTreeFork.close();
873
1343
  }
@@ -875,19 +1345,22 @@ import { NodeMetrics } from './node_metrics.js';
875
1345
  async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
876
1346
  const db = this.worldStateSynchronizer.getCommitted();
877
1347
  const verifier = isSimulation ? undefined : this.proofVerifier;
878
- // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
1348
+ // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
879
1349
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
880
1350
  const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
881
- const validator = createValidatorForAcceptingTxs(db, this.contractDataSource, verifier, {
1351
+ const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
882
1352
  timestamp: nextSlotTimestamp,
883
1353
  blockNumber,
884
1354
  l1ChainId: this.l1ChainId,
885
1355
  rollupVersion: this.version,
886
- setupAllowList: this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions(),
887
- gasFees: await this.getCurrentBaseFees(),
1356
+ setupAllowList: [
1357
+ ...await getDefaultAllowedSetupFunctions(),
1358
+ ...this.config.txPublicSetupAllowListExtend ?? []
1359
+ ],
1360
+ gasFees: await this.getCurrentMinFees(),
888
1361
  skipFeeEnforcement,
889
1362
  txsPermitted: !this.config.disableTransactions
890
- });
1363
+ }, this.log.getBindings());
891
1364
  return await validator.validateTx(tx);
892
1365
  }
893
1366
  getConfig() {
@@ -947,7 +1420,7 @@ import { NodeMetrics } from './node_metrics.js';
947
1420
  throw new Error(`Archiver initial sync not complete. Cannot start snapshot.`);
948
1421
  }
949
1422
  // And it has an L2 block hash
950
- const l2BlockHash = await archiver.getL2Tips().then((tips)=>tips.latest.hash);
1423
+ const l2BlockHash = await archiver.getL2Tips().then((tips)=>tips.proposed.hash);
951
1424
  if (!l2BlockHash) {
952
1425
  this.metrics.recordSnapshotError();
953
1426
  throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
@@ -974,7 +1447,7 @@ import { NodeMetrics } from './node_metrics.js';
974
1447
  if (!('rollbackTo' in archiver)) {
975
1448
  throw new Error('Archiver implementation does not support rollbacks.');
976
1449
  }
977
- const finalizedBlock = await archiver.getL2Tips().then((tips)=>tips.finalized.number);
1450
+ const finalizedBlock = await archiver.getL2Tips().then((tips)=>tips.finalized.block.number);
978
1451
  if (targetBlock < finalizedBlock) {
979
1452
  if (force) {
980
1453
  this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
@@ -1029,14 +1502,84 @@ import { NodeMetrics } from './node_metrics.js';
1029
1502
  return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
1030
1503
  }
1031
1504
  }
1505
+ async reloadKeystore() {
1506
+ if (!this.config.keyStoreDirectory?.length) {
1507
+ throw new BadRequestError('Cannot reload keystore: node is not using a file-based keystore. ' + 'Set KEY_STORE_DIRECTORY to use file-based keystores.');
1508
+ }
1509
+ if (!this.validatorClient) {
1510
+ throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
1511
+ }
1512
+ this.log.info('Reloading keystore from disk');
1513
+ // Re-read and validate keystore files
1514
+ const keyStores = loadKeystores(this.config.keyStoreDirectory);
1515
+ const newManager = new KeystoreManager(mergeKeystores(keyStores));
1516
+ await newManager.validateSigners();
1517
+ ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
1518
+ // Validate that every validator's publisher keys overlap with the L1 signers
1519
+ // that were initialized at startup. Publishers cannot be hot-reloaded, so a
1520
+ // validator with a publisher key that doesn't match any existing L1 signer
1521
+ // would silently fail on every proposer slot.
1522
+ if (this.keyStoreManager && this.sequencer) {
1523
+ const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
1524
+ const availablePublishers = new Set(oldAdapter.getAttesterAddresses().flatMap((a)=>oldAdapter.getPublisherAddresses(a).map((p)=>p.toString().toLowerCase())));
1525
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1526
+ for (const attester of newAdapter.getAttesterAddresses()){
1527
+ const pubs = newAdapter.getPublisherAddresses(attester);
1528
+ if (pubs.length > 0 && !pubs.some((p)=>availablePublishers.has(p.toString().toLowerCase()))) {
1529
+ 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 ` + `[${[
1530
+ ...availablePublishers
1531
+ ].join(', ')}]. Publishers cannot be hot-reloaded — ` + `use an existing publisher key or restart the node.`);
1532
+ }
1533
+ }
1534
+ }
1535
+ // Build adapters for old and new keystores to compute diff
1536
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1537
+ const newAddresses = newAdapter.getAttesterAddresses();
1538
+ const oldAddresses = this.keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses() : [];
1539
+ const oldSet = new Set(oldAddresses.map((a)=>a.toString()));
1540
+ const newSet = new Set(newAddresses.map((a)=>a.toString()));
1541
+ const added = newAddresses.filter((a)=>!oldSet.has(a.toString()));
1542
+ const removed = oldAddresses.filter((a)=>!newSet.has(a.toString()));
1543
+ if (added.length > 0) {
1544
+ this.log.info(`Keystore reload: adding attester keys: ${added.map((a)=>a.toString()).join(', ')}`);
1545
+ }
1546
+ if (removed.length > 0) {
1547
+ this.log.info(`Keystore reload: removing attester keys: ${removed.map((a)=>a.toString()).join(', ')}`);
1548
+ }
1549
+ if (added.length === 0 && removed.length === 0) {
1550
+ this.log.info('Keystore reload: attester keys unchanged');
1551
+ }
1552
+ // Update the validator client (coinbase, feeRecipient, attester keys)
1553
+ this.validatorClient.reloadKeystore(newManager);
1554
+ // Update the publisher factory's keystore so newly-added validators
1555
+ // can be matched to existing publisher keys when proposing blocks.
1556
+ if (this.sequencer) {
1557
+ this.sequencer.updatePublisherNodeKeyStore(newAdapter);
1558
+ }
1559
+ // Update slasher's "don't-slash-self" list with new validator addresses
1560
+ if (this.slasherClient && !this.config.slashSelfAllowed) {
1561
+ const slashValidatorsNever = unique([
1562
+ ...this.config.slashValidatorsNever ?? [],
1563
+ ...newAddresses
1564
+ ].map((a)=>a.toString())).map(EthAddress.fromString);
1565
+ this.slasherClient.updateConfig({
1566
+ slashValidatorsNever
1567
+ });
1568
+ }
1569
+ this.keyStoreManager = newManager;
1570
+ this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
1571
+ }
1572
+ #getInitialHeaderHash() {
1573
+ if (!this.initialHeaderHashPromise) {
1574
+ this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
1575
+ }
1576
+ return this.initialHeaderHashPromise;
1577
+ }
1032
1578
  /**
1033
1579
  * Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
1034
- * @param blockNumber - The block number at which to get the data.
1580
+ * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1035
1581
  * @returns An instance of a committed MerkleTreeOperations
1036
- */ async #getWorldState(blockNumber) {
1037
- if (typeof blockNumber === 'number' && blockNumber < INITIAL_L2_BLOCK_NUM - 1) {
1038
- throw new Error('Invalid block number to get world state for: ' + blockNumber);
1039
- }
1582
+ */ async #getWorldState(block) {
1040
1583
  let blockSyncedTo = BlockNumber.ZERO;
1041
1584
  try {
1042
1585
  // Attempt to sync the world state if necessary
@@ -1044,15 +1587,32 @@ import { NodeMetrics } from './node_metrics.js';
1044
1587
  } catch (err) {
1045
1588
  this.log.error(`Error getting world state: ${err}`);
1046
1589
  }
1047
- // using a snapshot could be less efficient than using the committed db
1048
- if (blockNumber === 'latest' /*|| blockNumber === blockSyncedTo*/ ) {
1049
- this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1590
+ if (block === 'latest') {
1591
+ this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
1050
1592
  return this.worldStateSynchronizer.getCommitted();
1051
- } else if (blockNumber <= blockSyncedTo) {
1593
+ }
1594
+ if (BlockHash.isBlockHash(block)) {
1595
+ const initialBlockHash = await this.#getInitialHeaderHash();
1596
+ if (block.equals(initialBlockHash)) {
1597
+ // Block source doesn't handle initial header so we need to handle the case separately.
1598
+ return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
1599
+ }
1600
+ const header = await this.blockSource.getBlockHeaderByHash(block);
1601
+ if (!header) {
1602
+ 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.`);
1603
+ }
1604
+ const blockNumber = header.getBlockNumber();
1605
+ this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1606
+ return this.worldStateSynchronizer.getSnapshot(blockNumber);
1607
+ }
1608
+ // Block number provided
1609
+ {
1610
+ const blockNumber = block;
1611
+ if (blockNumber > blockSyncedTo) {
1612
+ throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
1613
+ }
1052
1614
  this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1053
1615
  return this.worldStateSynchronizer.getSnapshot(blockNumber);
1054
- } else {
1055
- throw new Error(`Block ${blockNumber} not yet synced`);
1056
1616
  }
1057
1617
  }
1058
1618
  /**
@@ -1063,8 +1623,3 @@ import { NodeMetrics } from './node_metrics.js';
1063
1623
  return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
1064
1624
  }
1065
1625
  }
1066
- _ts_decorate([
1067
- trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1068
- [Attributes.TX_HASH]: tx.getTxHash().toString()
1069
- }))
1070
- ], AztecNodeService.prototype, "simulatePublicCalls", null);