@aztec/aztec-node 3.0.3 → 4.0.0-devnet.1-patch.1

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,384 @@
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
+ };
6
369
  }
370
+ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
371
+ return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
372
+ }
373
+ var _dec, _initProto;
7
374
  import { createArchiver } from '@aztec/archiver';
8
375
  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';
376
+ import { createBlobClientWithFileStores } from '@aztec/blob-client/client';
11
377
  import { EpochCache } from '@aztec/epoch-cache';
12
378
  import { createEthereumChain } from '@aztec/ethereum/chain';
13
379
  import { getPublicClient } from '@aztec/ethereum/client';
14
380
  import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
15
- import { BlockNumber } from '@aztec/foundation/branded-types';
381
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
16
382
  import { compactArray, pick } from '@aztec/foundation/collection';
17
383
  import { Fr } from '@aztec/foundation/curves/bn254';
18
384
  import { EthAddress } from '@aztec/foundation/eth-address';
@@ -26,12 +392,12 @@ import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
26
392
  import { createForwarderL1TxUtilsFromEthSigner, createL1TxUtilsWithBlobsFromEthSigner } from '@aztec/node-lib/factories';
27
393
  import { createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
28
394
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
29
- import { BlockBuilder, GlobalVariableBuilder, SequencerClient, createValidatorForAcceptingTxs } from '@aztec/sequencer-client';
395
+ import { GlobalVariableBuilder, SequencerClient } from '@aztec/sequencer-client';
30
396
  import { PublicProcessorFactory } from '@aztec/simulator/server';
31
397
  import { AttestationsBlockWatcher, EpochPruneWatcher, createSlasher } from '@aztec/slasher';
32
398
  import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
33
399
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
34
- import { L2BlockHash } from '@aztec/stdlib/block';
400
+ import { BlockHash, L2Block } from '@aztec/stdlib/block';
35
401
  import { GasFees } from '@aztec/stdlib/gas';
36
402
  import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
37
403
  import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
@@ -42,12 +408,15 @@ import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@az
42
408
  import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
43
409
  import { getPackageVersion } from '@aztec/stdlib/update-checker';
44
410
  import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
45
- import { NodeKeystoreAdapter, ValidatorClient, createBlockProposalHandler, createValidatorClient } from '@aztec/validator-client';
411
+ import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createBlockProposalHandler, createValidatorClient, createValidatorForAcceptingTxs } from '@aztec/validator-client';
46
412
  import { createWorldStateSynchronizer } from '@aztec/world-state';
47
413
  import { createPublicClient, fallback, http } from 'viem';
48
414
  import { createSentinel } from '../sentinel/factory.js';
49
415
  import { createKeyStoreForValidator } from './config.js';
50
416
  import { NodeMetrics } from './node_metrics.js';
417
+ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
418
+ [Attributes.TX_HASH]: tx.getTxHash().toString()
419
+ }));
51
420
  /**
52
421
  * The aztec node.
53
422
  */ export class AztecNodeService {
@@ -70,11 +439,22 @@ import { NodeMetrics } from './node_metrics.js';
70
439
  proofVerifier;
71
440
  telemetry;
72
441
  log;
442
+ blobClient;
443
+ static{
444
+ ({ e: [_initProto] } = _apply_decs_2203_r(this, [
445
+ [
446
+ _dec,
447
+ 2,
448
+ "simulatePublicCalls"
449
+ ]
450
+ ], []));
451
+ }
73
452
  metrics;
453
+ initialHeaderHashPromise;
74
454
  // Prevent two snapshot operations to happen simultaneously
75
455
  isUploadingSnapshot;
76
456
  tracer;
77
- constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry = getTelemetryClient(), log = createLogger('node')){
457
+ constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry = getTelemetryClient(), log = createLogger('node'), blobClient){
78
458
  this.config = config;
79
459
  this.p2pClient = p2pClient;
80
460
  this.blockSource = blockSource;
@@ -94,6 +474,8 @@ import { NodeMetrics } from './node_metrics.js';
94
474
  this.proofVerifier = proofVerifier;
95
475
  this.telemetry = telemetry;
96
476
  this.log = log;
477
+ this.blobClient = blobClient;
478
+ this.initialHeaderHashPromise = (_initProto(this), undefined);
97
479
  this.isUploadingSnapshot = false;
98
480
  this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
99
481
  this.tracer = telemetry.getTracer('AztecNodeService');
@@ -119,9 +501,6 @@ import { NodeMetrics } from './node_metrics.js';
119
501
  const packageVersion = getPackageVersion() ?? '';
120
502
  const telemetry = deps.telemetry ?? getTelemetryClient();
121
503
  const dateProvider = deps.dateProvider ?? new DateProvider();
122
- const blobSinkClient = deps.blobSinkClient ?? createBlobSinkClient(config, {
123
- logger: createLogger('node:blob-sink:client')
124
- });
125
504
  const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
126
505
  // Build a key store from file if given or from environment otherwise
127
506
  let keyStoreManager;
@@ -152,7 +531,9 @@ import { NodeMetrics } from './node_metrics.js';
152
531
  }
153
532
  const publicClient = createPublicClient({
154
533
  chain: ethereumChain.chainInfo,
155
- transport: fallback(config.l1RpcUrls.map((url)=>http(url))),
534
+ transport: fallback(config.l1RpcUrls.map((url)=>http(url, {
535
+ batch: false
536
+ }))),
156
537
  pollingInterval: config.viemPollingIntervalMS
157
538
  });
158
539
  const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.l1Contracts.registryAddress, config.rollupVersion ?? 'canonical');
@@ -171,13 +552,14 @@ import { NodeMetrics } from './node_metrics.js';
171
552
  if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
172
553
  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}).`);
173
554
  }
555
+ const blobClient = await createBlobClientWithFileStores(config, createLogger('node:blob-client:client'));
174
556
  // attempt snapshot sync if possible
175
557
  await trySnapshotSync(config, log);
176
558
  const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, {
177
559
  dateProvider
178
560
  });
179
561
  const archiver = await createArchiver(config, {
180
- blobSinkClient,
562
+ blobClient,
181
563
  epochCache,
182
564
  telemetry,
183
565
  dateProvider
@@ -195,7 +577,8 @@ import { NodeMetrics } from './node_metrics.js';
195
577
  const p2pClient = await createP2PClient(P2PClientType.Full, config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
196
578
  // We should really not be modifying the config object
197
579
  config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
198
- const blockBuilder = new BlockBuilder({
580
+ // Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
581
+ const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
199
582
  ...config,
200
583
  l1GenesisTime,
201
584
  slotDuration: Number(slotDuration)
@@ -203,15 +586,17 @@ import { NodeMetrics } from './node_metrics.js';
203
586
  // We'll accumulate sentinel watchers here
204
587
  const watchers = [];
205
588
  // Create validator client if required
206
- const validatorClient = createValidatorClient(config, {
589
+ const validatorClient = await createValidatorClient(config, {
590
+ checkpointsBuilder: validatorCheckpointsBuilder,
591
+ worldState: worldStateSynchronizer,
207
592
  p2pClient,
208
593
  telemetry,
209
594
  dateProvider,
210
595
  epochCache,
211
- blockBuilder,
212
596
  blockSource: archiver,
213
597
  l1ToL2MessageSource: archiver,
214
- keyStoreManager
598
+ keyStoreManager,
599
+ blobClient
215
600
  });
216
601
  // If we have a validator client, register it as a source of offenses for the slasher,
217
602
  // and have it register callbacks on the p2p client *before* we start it, otherwise messages
@@ -227,7 +612,8 @@ import { NodeMetrics } from './node_metrics.js';
227
612
  if (!validatorClient && config.alwaysReexecuteBlockProposals) {
228
613
  log.info('Setting up block proposal reexecution for monitoring');
229
614
  createBlockProposalHandler(config, {
230
- blockBuilder,
615
+ checkpointsBuilder: validatorCheckpointsBuilder,
616
+ worldState: worldStateSynchronizer,
231
617
  epochCache,
232
618
  blockSource: archiver,
233
619
  l1ToL2MessageSource: archiver,
@@ -246,7 +632,7 @@ import { NodeMetrics } from './node_metrics.js';
246
632
  }
247
633
  let epochPruneWatcher;
248
634
  if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
249
- epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), blockBuilder, config);
635
+ epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
250
636
  watchers.push(epochPruneWatcher);
251
637
  }
252
638
  // We assume we want to slash for invalid attestations unless all max penalties are set to 0
@@ -266,7 +652,7 @@ import { NodeMetrics } from './node_metrics.js';
266
652
  // Validator enabled, create/start relevant service
267
653
  let sequencer;
268
654
  let slasherClient;
269
- if (!config.disableValidator) {
655
+ if (!config.disableValidator && validatorClient) {
270
656
  // We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
271
657
  // as they are executed when the node is selected as proposer.
272
658
  const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
@@ -288,6 +674,11 @@ import { NodeMetrics } from './node_metrics.js';
288
674
  dateProvider
289
675
  });
290
676
  // Create and start the sequencer client
677
+ const checkpointsBuilder = new CheckpointsBuilder({
678
+ ...config,
679
+ l1GenesisTime,
680
+ slotDuration: Number(slotDuration)
681
+ }, worldStateSynchronizer, archiver, dateProvider, telemetry);
291
682
  sequencer = await SequencerClient.new(config, {
292
683
  ...deps,
293
684
  epochCache,
@@ -296,12 +687,12 @@ import { NodeMetrics } from './node_metrics.js';
296
687
  p2pClient,
297
688
  worldStateSynchronizer,
298
689
  slasherClient,
299
- blockBuilder,
690
+ checkpointsBuilder,
300
691
  l2BlockSource: archiver,
301
692
  l1ToL2MessageSource: archiver,
302
693
  telemetry,
303
694
  dateProvider,
304
- blobSinkClient,
695
+ blobClient,
305
696
  nodeKeyStore: keyStoreManager
306
697
  });
307
698
  }
@@ -311,7 +702,13 @@ import { NodeMetrics } from './node_metrics.js';
311
702
  } else if (sequencer) {
312
703
  log.warn(`Sequencer created but not started`);
313
704
  }
314
- 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);
705
+ const globalVariableBuilder = new GlobalVariableBuilder({
706
+ ...config,
707
+ rollupVersion: BigInt(config.rollupVersion),
708
+ l1GenesisTime,
709
+ slotDuration: Number(slotDuration)
710
+ });
711
+ 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, blobClient);
315
712
  }
316
713
  /**
317
714
  * Returns the sequencer client instance.
@@ -361,33 +758,46 @@ import { NodeMetrics } from './node_metrics.js';
361
758
  rollupVersion,
362
759
  enr,
363
760
  l1ContractAddresses: contractAddresses,
364
- protocolContractAddresses: protocolContractAddresses
761
+ protocolContractAddresses: protocolContractAddresses,
762
+ realProofs: !!this.config.realProofs
365
763
  };
366
764
  return nodeInfo;
367
765
  }
368
766
  /**
369
- * Get a block specified by its number.
370
- * @param number - The block number being requested.
767
+ * Get a block specified by its block number, block hash, or 'latest'.
768
+ * @param block - The block parameter (block number, block hash, or 'latest').
371
769
  * @returns The requested block.
372
- */ async getBlock(number) {
373
- const blockNumber = number === 'latest' ? await this.getBlockNumber() : number;
374
- return await this.blockSource.getBlock(blockNumber);
770
+ */ async getBlock(block) {
771
+ if (BlockHash.isBlockHash(block)) {
772
+ return this.getBlockByHash(block);
773
+ }
774
+ const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
775
+ if (blockNumber === BlockNumber.ZERO) {
776
+ return this.buildInitialBlock();
777
+ }
778
+ return await this.blockSource.getL2Block(blockNumber);
375
779
  }
376
780
  /**
377
781
  * Get a block specified by its hash.
378
782
  * @param blockHash - The block hash being requested.
379
783
  * @returns The requested block.
380
784
  */ async getBlockByHash(blockHash) {
381
- const publishedBlock = await this.blockSource.getPublishedBlockByHash(blockHash);
382
- return publishedBlock?.block;
785
+ const initialBlockHash = await this.#getInitialHeaderHash();
786
+ if (blockHash.equals(initialBlockHash)) {
787
+ return this.buildInitialBlock();
788
+ }
789
+ return await this.blockSource.getL2BlockByHash(blockHash);
790
+ }
791
+ buildInitialBlock() {
792
+ const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
793
+ return L2Block.empty(initialHeader);
383
794
  }
384
795
  /**
385
796
  * Get a block specified by its archive root.
386
797
  * @param archive - The archive root being requested.
387
798
  * @returns The requested block.
388
799
  */ async getBlockByArchive(archive) {
389
- const publishedBlock = await this.blockSource.getPublishedBlockByArchive(archive);
390
- return publishedBlock?.block;
800
+ return await this.blockSource.getL2BlockByArchive(archive);
391
801
  }
392
802
  /**
393
803
  * Method to request blocks. Will attempt to return all requested blocks but will return only those available.
@@ -395,16 +805,19 @@ import { NodeMetrics } from './node_metrics.js';
395
805
  * @param limit - The maximum number of blocks to obtain.
396
806
  * @returns The blocks requested.
397
807
  */ async getBlocks(from, limit) {
398
- return await this.blockSource.getBlocks(from, limit) ?? [];
808
+ return await this.blockSource.getBlocks(from, BlockNumber(limit)) ?? [];
809
+ }
810
+ async getCheckpoints(from, limit) {
811
+ return await this.blockSource.getCheckpoints(from, limit) ?? [];
399
812
  }
400
- async getPublishedBlocks(from, limit) {
401
- return await this.blockSource.getPublishedBlocks(from, limit) ?? [];
813
+ async getCheckpointedBlocks(from, limit) {
814
+ return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
402
815
  }
403
816
  /**
404
- * Method to fetch the current base fees.
405
- * @returns The current base fees.
406
- */ async getCurrentBaseFees() {
407
- return await this.globalVariableBuilder.getCurrentBaseFees();
817
+ * Method to fetch the current min L2 fees.
818
+ * @returns The current min L2 fees.
819
+ */ async getCurrentMinFees() {
820
+ return await this.globalVariableBuilder.getCurrentMinFees();
408
821
  }
409
822
  async getMaxPriorityFees() {
410
823
  for await (const tx of this.p2pClient.iteratePendingTxs()){
@@ -424,6 +837,9 @@ import { NodeMetrics } from './node_metrics.js';
424
837
  async getProvenBlockNumber() {
425
838
  return await this.blockSource.getProvenBlockNumber();
426
839
  }
840
+ async getCheckpointedBlockNumber() {
841
+ return await this.blockSource.getCheckpointedL2BlockNumber();
842
+ }
427
843
  /**
428
844
  * Method to fetch the version of the package.
429
845
  * @returns The node package version
@@ -448,14 +864,29 @@ import { NodeMetrics } from './node_metrics.js';
448
864
  getContract(address) {
449
865
  return this.contractDataSource.getContract(address);
450
866
  }
451
- /**
452
- * Gets all logs that match any of the received tags (i.e. logs with their first field equal to a tag).
453
- * @param tags - The tags to filter the logs by.
454
- * @param logsPerTag - The maximum number of logs to return for each tag. By default no limit is set
455
- * @returns For each received tag, an array of matching logs is returned. An empty array implies no logs match
456
- * that tag.
457
- */ getLogsByTags(tags, logsPerTag) {
458
- return this.logsSource.getLogsByTags(tags, logsPerTag);
867
+ async getPrivateLogsByTags(tags, page, referenceBlock) {
868
+ if (referenceBlock) {
869
+ const initialBlockHash = await this.#getInitialHeaderHash();
870
+ if (!referenceBlock.equals(initialBlockHash)) {
871
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
872
+ if (!header) {
873
+ throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
874
+ }
875
+ }
876
+ }
877
+ return this.logsSource.getPrivateLogsByTags(tags, page);
878
+ }
879
+ async getPublicLogsByTagsFromContract(contractAddress, tags, page, referenceBlock) {
880
+ if (referenceBlock) {
881
+ const initialBlockHash = await this.#getInitialHeaderHash();
882
+ if (!referenceBlock.equals(initialBlockHash)) {
883
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
884
+ if (!header) {
885
+ throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
886
+ }
887
+ }
888
+ }
889
+ return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
459
890
  }
460
891
  /**
461
892
  * Gets public logs based on the provided filter.
@@ -496,18 +927,24 @@ import { NodeMetrics } from './node_metrics.js';
496
927
  });
497
928
  }
498
929
  async getTxReceipt(txHash) {
499
- let txReceipt = new TxReceipt(txHash, TxStatus.DROPPED, 'Tx dropped by P2P node.');
500
- // We first check if the tx is in pending (instead of first checking if it is mined) because if we first check
501
- // for mined and then for pending there could be a race condition where the tx is mined between the two checks
502
- // and we would incorrectly return a TxReceipt with status DROPPED
503
- if (await this.p2pClient.getTxStatus(txHash) === 'pending') {
504
- txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
505
- }
930
+ // Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
931
+ // as a fallback if we don't find a settled receipt in the archiver.
932
+ const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
933
+ const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
934
+ // Then get the actual tx from the archiver, which tracks every tx in a mined block.
506
935
  const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
507
936
  if (settledTxReceipt) {
508
- txReceipt = settledTxReceipt;
937
+ // If the archiver has the receipt then return it.
938
+ return settledTxReceipt;
939
+ } else if (isKnownToPool) {
940
+ // If the tx is in the pool but not in the archiver, it's pending.
941
+ // This handles race conditions between archiver and p2p, where the archiver
942
+ // has pruned the block in which a tx was mined, but p2p has not caught up yet.
943
+ return new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
944
+ } else {
945
+ // Otherwise, if we don't know the tx, we consider it dropped.
946
+ return new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
509
947
  }
510
- return txReceipt;
511
948
  }
512
949
  getTxEffect(txHash) {
513
950
  return this.blockSource.getTxEffect(txHash);
@@ -524,10 +961,17 @@ import { NodeMetrics } from './node_metrics.js';
524
961
  await tryStop(this.p2pClient);
525
962
  await tryStop(this.worldStateSynchronizer);
526
963
  await tryStop(this.blockSource);
964
+ await tryStop(this.blobClient);
527
965
  await tryStop(this.telemetry);
528
966
  this.log.info(`Stopped Aztec Node`);
529
967
  }
530
968
  /**
969
+ * Returns the blob client used by this node.
970
+ * @internal - Exposed for testing purposes only.
971
+ */ getBlobClient() {
972
+ return this.blobClient;
973
+ }
974
+ /**
531
975
  * Method to retrieve pending txs.
532
976
  * @param limit - The number of items to returns
533
977
  * @param after - The last known pending tx. Used for pagination
@@ -552,15 +996,8 @@ import { NodeMetrics } from './node_metrics.js';
552
996
  */ async getTxsByHash(txHashes) {
553
997
  return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
554
998
  }
555
- /**
556
- * Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
557
- * the leaves were inserted.
558
- * @param blockNumber - The block number at which to get the data or 'latest' for latest data.
559
- * @param treeId - The tree to search in.
560
- * @param leafValues - The values to search for.
561
- * @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
562
- */ async findLeavesIndexes(blockNumber, treeId, leafValues) {
563
- const committedDb = await this.#getWorldState(blockNumber);
999
+ async findLeavesIndexes(referenceBlock, treeId, leafValues) {
1000
+ const committedDb = await this.#getWorldState(referenceBlock);
564
1001
  const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
565
1002
  // We filter out undefined values
566
1003
  const indices = maybeIndices.filter((x)=>x !== undefined);
@@ -603,50 +1040,27 @@ import { NodeMetrics } from './node_metrics.js';
603
1040
  }
604
1041
  return {
605
1042
  l2BlockNumber: BlockNumber(Number(blockNumber)),
606
- l2BlockHash: L2BlockHash.fromField(blockHash),
1043
+ l2BlockHash: new BlockHash(blockHash),
607
1044
  data: index
608
1045
  };
609
1046
  });
610
1047
  }
611
- /**
612
- * Returns a sibling path for the given index in the nullifier tree.
613
- * @param blockNumber - The block number at which to get the data.
614
- * @param leafIndex - The index of the leaf for which the sibling path is required.
615
- * @returns The sibling path for the leaf index.
616
- */ async getNullifierSiblingPath(blockNumber, leafIndex) {
617
- const committedDb = await this.#getWorldState(blockNumber);
618
- return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
619
- }
620
- /**
621
- * Returns a sibling path for the given index in the data tree.
622
- * @param blockNumber - The block number at which to get the data.
623
- * @param leafIndex - The index of the leaf for which the sibling path is required.
624
- * @returns The sibling path for the leaf index.
625
- */ async getNoteHashSiblingPath(blockNumber, leafIndex) {
626
- const committedDb = await this.#getWorldState(blockNumber);
627
- return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
628
- }
629
- async getArchiveMembershipWitness(blockNumber, archive) {
630
- const committedDb = await this.#getWorldState(blockNumber);
1048
+ async getBlockHashMembershipWitness(referenceBlock, blockHash) {
1049
+ const committedDb = await this.#getWorldState(referenceBlock);
631
1050
  const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
632
- archive
1051
+ blockHash
633
1052
  ]);
634
1053
  return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
635
1054
  }
636
- async getNoteHashMembershipWitness(blockNumber, noteHash) {
637
- const committedDb = await this.#getWorldState(blockNumber);
1055
+ async getNoteHashMembershipWitness(referenceBlock, noteHash) {
1056
+ const committedDb = await this.#getWorldState(referenceBlock);
638
1057
  const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
639
1058
  noteHash
640
1059
  ]);
641
1060
  return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
642
1061
  }
643
- /**
644
- * Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
645
- * @param blockNumber - The block number at which to get the data.
646
- * @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
647
- * @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
648
- */ async getL1ToL2MessageMembershipWitness(blockNumber, l1ToL2Message) {
649
- const db = await this.#getWorldState(blockNumber);
1062
+ async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
1063
+ const db = await this.#getWorldState(referenceBlock);
650
1064
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
651
1065
  l1ToL2Message
652
1066
  ]);
@@ -672,38 +1086,29 @@ import { NodeMetrics } from './node_metrics.js';
672
1086
  return messageIndex !== undefined;
673
1087
  }
674
1088
  /**
675
- * Returns all the L2 to L1 messages in a block.
676
- * @param blockNumber - The block number at which to get the data.
677
- * @returns The L2 to L1 messages (undefined if the block number is not found).
678
- */ async getL2ToL1Messages(blockNumber) {
679
- const block = await this.blockSource.getBlock(blockNumber === 'latest' ? await this.getBlockNumber() : blockNumber);
680
- return block?.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs);
681
- }
682
- /**
683
- * Returns a sibling path for a leaf in the committed blocks tree.
684
- * @param blockNumber - The block number at which to get the data.
685
- * @param leafIndex - Index of the leaf in the tree.
686
- * @returns The sibling path.
687
- */ async getArchiveSiblingPath(blockNumber, leafIndex) {
688
- const committedDb = await this.#getWorldState(blockNumber);
689
- return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
690
- }
691
- /**
692
- * Returns a sibling path for a leaf in the committed public data tree.
693
- * @param blockNumber - The block number at which to get the data.
694
- * @param leafIndex - Index of the leaf in the tree.
695
- * @returns The sibling path.
696
- */ async getPublicDataSiblingPath(blockNumber, leafIndex) {
697
- const committedDb = await this.#getWorldState(blockNumber);
698
- return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
1089
+ * Returns all the L2 to L1 messages in an epoch.
1090
+ * @param epoch - The epoch at which to get the data.
1091
+ * @returns The L2 to L1 messages (empty array if the epoch is not found).
1092
+ */ async getL2ToL1Messages(epoch) {
1093
+ // Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
1094
+ const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
1095
+ const blocksInCheckpoints = [];
1096
+ let previousSlotNumber = SlotNumber.ZERO;
1097
+ let checkpointIndex = -1;
1098
+ for (const checkpointedBlock of checkpointedBlocks){
1099
+ const block = checkpointedBlock.block;
1100
+ const slotNumber = block.header.globalVariables.slotNumber;
1101
+ if (slotNumber !== previousSlotNumber) {
1102
+ checkpointIndex++;
1103
+ blocksInCheckpoints.push([]);
1104
+ previousSlotNumber = slotNumber;
1105
+ }
1106
+ blocksInCheckpoints[checkpointIndex].push(block);
1107
+ }
1108
+ return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
699
1109
  }
700
- /**
701
- * Returns a nullifier membership witness for a given nullifier at a given block.
702
- * @param blockNumber - The block number at which to get the index.
703
- * @param nullifier - Nullifier we try to find witness for.
704
- * @returns The nullifier membership witness (if found).
705
- */ async getNullifierMembershipWitness(blockNumber, nullifier) {
706
- const db = await this.#getWorldState(blockNumber);
1110
+ async getNullifierMembershipWitness(referenceBlock, nullifier) {
1111
+ const db = await this.#getWorldState(referenceBlock);
707
1112
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
708
1113
  nullifier.toBuffer()
709
1114
  ]);
@@ -719,7 +1124,8 @@ import { NodeMetrics } from './node_metrics.js';
719
1124
  }
720
1125
  /**
721
1126
  * Returns a low nullifier membership witness for a given nullifier at a given block.
722
- * @param blockNumber - The block number at which to get the index.
1127
+ * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
1128
+ * (which contains the root of the nullifier tree in which we are searching for the nullifier).
723
1129
  * @param nullifier - Nullifier we try to find the low nullifier witness for.
724
1130
  * @returns The low nullifier membership witness (if found).
725
1131
  * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
@@ -730,8 +1136,8 @@ import { NodeMetrics } from './node_metrics.js';
730
1136
  * the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
731
1137
  * index of the nullifier itself when it already exists in the tree.
732
1138
  * TODO: This is a confusing behavior and we should eventually address that.
733
- */ async getLowNullifierMembershipWitness(blockNumber, nullifier) {
734
- const committedDb = await this.#getWorldState(blockNumber);
1139
+ */ async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
1140
+ const committedDb = await this.#getWorldState(referenceBlock);
735
1141
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
736
1142
  if (!findResult) {
737
1143
  return undefined;
@@ -744,8 +1150,8 @@ import { NodeMetrics } from './node_metrics.js';
744
1150
  const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
745
1151
  return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
746
1152
  }
747
- async getPublicDataWitness(blockNumber, leafSlot) {
748
- const committedDb = await this.#getWorldState(blockNumber);
1153
+ async getPublicDataWitness(referenceBlock, leafSlot) {
1154
+ const committedDb = await this.#getWorldState(referenceBlock);
749
1155
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
750
1156
  if (!lowLeafResult) {
751
1157
  return undefined;
@@ -755,18 +1161,8 @@ import { NodeMetrics } from './node_metrics.js';
755
1161
  return new PublicDataWitness(lowLeafResult.index, preimage, path);
756
1162
  }
757
1163
  }
758
- /**
759
- * Gets the storage value at the given contract storage slot.
760
- *
761
- * @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
762
- * Aztec's version of `eth_getStorageAt`.
763
- *
764
- * @param contract - Address of the contract to query.
765
- * @param slot - Slot to query.
766
- * @param blockNumber - The block number at which to get the data or 'latest'.
767
- * @returns Storage value at the given contract slot.
768
- */ async getPublicStorageAt(blockNumber, contract, slot) {
769
- const committedDb = await this.#getWorldState(blockNumber);
1164
+ async getPublicStorageAt(referenceBlock, contract, slot) {
1165
+ const committedDb = await this.#getWorldState(referenceBlock);
770
1166
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
771
1167
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
772
1168
  if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
@@ -775,18 +1171,22 @@ import { NodeMetrics } from './node_metrics.js';
775
1171
  const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
776
1172
  return preimage.leaf.value;
777
1173
  }
778
- /**
779
- * Returns the currently committed block header, or the initial header if no blocks have been produced.
780
- * @returns The current committed block header.
781
- */ async getBlockHeader(blockNumber = 'latest') {
782
- return blockNumber === BlockNumber.ZERO || blockNumber === 'latest' && await this.blockSource.getBlockNumber() === BlockNumber.ZERO ? this.worldStateSynchronizer.getCommitted().getInitialHeader() : this.blockSource.getBlockHeader(blockNumber === 'latest' ? blockNumber : blockNumber);
783
- }
784
- /**
785
- * Get a block header specified by its hash.
786
- * @param blockHash - The block hash being requested.
787
- * @returns The requested block header.
788
- */ async getBlockHeaderByHash(blockHash) {
789
- return await this.blockSource.getBlockHeaderByHash(blockHash);
1174
+ async getBlockHeader(block = 'latest') {
1175
+ if (BlockHash.isBlockHash(block)) {
1176
+ const initialBlockHash = await this.#getInitialHeaderHash();
1177
+ if (block.equals(initialBlockHash)) {
1178
+ // Block source doesn't handle initial header so we need to handle the case separately.
1179
+ return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1180
+ }
1181
+ return this.blockSource.getBlockHeaderByHash(block);
1182
+ } else {
1183
+ // Block source doesn't handle initial header so we need to handle the case separately.
1184
+ const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
1185
+ if (blockNumber === BlockNumber.ZERO) {
1186
+ return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1187
+ }
1188
+ return this.blockSource.getBlockHeader(block);
1189
+ }
790
1190
  }
791
1191
  /**
792
1192
  * Get a block header specified by its archive root.
@@ -812,7 +1212,7 @@ import { NodeMetrics } from './node_metrics.js';
812
1212
  const coinbase = EthAddress.ZERO;
813
1213
  const feeRecipient = AztecAddress.ZERO;
814
1214
  const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(blockNumber, coinbase, feeRecipient);
815
- const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry);
1215
+ const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry, this.log.getBindings());
816
1216
  this.log.verbose(`Simulating public calls for tx ${txHash}`, {
817
1217
  globalVariables: newGlobalVariables.toInspect(),
818
1218
  txHash,
@@ -860,10 +1260,10 @@ import { NodeMetrics } from './node_metrics.js';
860
1260
  l1ChainId: this.l1ChainId,
861
1261
  rollupVersion: this.version,
862
1262
  setupAllowList: this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions(),
863
- gasFees: await this.getCurrentBaseFees(),
1263
+ gasFees: await this.getCurrentMinFees(),
864
1264
  skipFeeEnforcement,
865
1265
  txsPermitted: !this.config.disableTransactions
866
- });
1266
+ }, this.log.getBindings());
867
1267
  return await validator.validateTx(tx);
868
1268
  }
869
1269
  getConfig() {
@@ -923,7 +1323,7 @@ import { NodeMetrics } from './node_metrics.js';
923
1323
  throw new Error(`Archiver initial sync not complete. Cannot start snapshot.`);
924
1324
  }
925
1325
  // And it has an L2 block hash
926
- const l2BlockHash = await archiver.getL2Tips().then((tips)=>tips.latest.hash);
1326
+ const l2BlockHash = await archiver.getL2Tips().then((tips)=>tips.proposed.hash);
927
1327
  if (!l2BlockHash) {
928
1328
  this.metrics.recordSnapshotError();
929
1329
  throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
@@ -950,7 +1350,7 @@ import { NodeMetrics } from './node_metrics.js';
950
1350
  if (!('rollbackTo' in archiver)) {
951
1351
  throw new Error('Archiver implementation does not support rollbacks.');
952
1352
  }
953
- const finalizedBlock = await archiver.getL2Tips().then((tips)=>tips.finalized.number);
1353
+ const finalizedBlock = await archiver.getL2Tips().then((tips)=>tips.finalized.block.number);
954
1354
  if (targetBlock < finalizedBlock) {
955
1355
  if (force) {
956
1356
  this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
@@ -1005,14 +1405,17 @@ import { NodeMetrics } from './node_metrics.js';
1005
1405
  return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
1006
1406
  }
1007
1407
  }
1408
+ #getInitialHeaderHash() {
1409
+ if (!this.initialHeaderHashPromise) {
1410
+ this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
1411
+ }
1412
+ return this.initialHeaderHashPromise;
1413
+ }
1008
1414
  /**
1009
1415
  * Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
1010
- * @param blockNumber - The block number at which to get the data.
1416
+ * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1011
1417
  * @returns An instance of a committed MerkleTreeOperations
1012
- */ async #getWorldState(blockNumber) {
1013
- if (typeof blockNumber === 'number' && blockNumber < INITIAL_L2_BLOCK_NUM - 1) {
1014
- throw new Error('Invalid block number to get world state for: ' + blockNumber);
1015
- }
1418
+ */ async #getWorldState(block) {
1016
1419
  let blockSyncedTo = BlockNumber.ZERO;
1017
1420
  try {
1018
1421
  // Attempt to sync the world state if necessary
@@ -1020,15 +1423,32 @@ import { NodeMetrics } from './node_metrics.js';
1020
1423
  } catch (err) {
1021
1424
  this.log.error(`Error getting world state: ${err}`);
1022
1425
  }
1023
- // using a snapshot could be less efficient than using the committed db
1024
- if (blockNumber === 'latest' /*|| blockNumber === blockSyncedTo*/ ) {
1025
- this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1426
+ if (block === 'latest') {
1427
+ this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
1026
1428
  return this.worldStateSynchronizer.getCommitted();
1027
- } else if (blockNumber <= blockSyncedTo) {
1429
+ }
1430
+ if (BlockHash.isBlockHash(block)) {
1431
+ const initialBlockHash = await this.#getInitialHeaderHash();
1432
+ if (block.equals(initialBlockHash)) {
1433
+ // Block source doesn't handle initial header so we need to handle the case separately.
1434
+ return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
1435
+ }
1436
+ const header = await this.blockSource.getBlockHeaderByHash(block);
1437
+ if (!header) {
1438
+ 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.`);
1439
+ }
1440
+ const blockNumber = header.getBlockNumber();
1441
+ this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1442
+ return this.worldStateSynchronizer.getSnapshot(blockNumber);
1443
+ }
1444
+ // Block number provided
1445
+ {
1446
+ const blockNumber = block;
1447
+ if (blockNumber > blockSyncedTo) {
1448
+ throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
1449
+ }
1028
1450
  this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1029
1451
  return this.worldStateSynchronizer.getSnapshot(blockNumber);
1030
- } else {
1031
- throw new Error(`Block ${blockNumber} not yet synced`);
1032
1452
  }
1033
1453
  }
1034
1454
  /**
@@ -1039,8 +1459,3 @@ import { NodeMetrics } from './node_metrics.js';
1039
1459
  return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
1040
1460
  }
1041
1461
  }
1042
- _ts_decorate([
1043
- trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1044
- [Attributes.TX_HASH]: tx.getTxHash().toString()
1045
- }))
1046
- ], AztecNodeService.prototype, "simulatePublicCalls", null);