@aztec/aztec-node 0.0.1-commit.9b94fc1 → 0.0.1-commit.9ee6fcc6

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