@aztec/aztec-node 5.0.0-private.20260319 → 5.0.0-rc.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.
Files changed (47) hide show
  1. package/dest/aztec-node/block_response_helpers.d.ts +25 -0
  2. package/dest/aztec-node/block_response_helpers.d.ts.map +1 -0
  3. package/dest/aztec-node/block_response_helpers.js +112 -0
  4. package/dest/aztec-node/config.d.ts +14 -4
  5. package/dest/aztec-node/config.d.ts.map +1 -1
  6. package/dest/aztec-node/config.js +10 -5
  7. package/dest/aztec-node/public_data_overrides.d.ts +13 -0
  8. package/dest/aztec-node/public_data_overrides.d.ts.map +1 -0
  9. package/dest/aztec-node/public_data_overrides.js +21 -0
  10. package/dest/aztec-node/register_node_rpc_handlers.d.ts +10 -0
  11. package/dest/aztec-node/register_node_rpc_handlers.d.ts.map +1 -0
  12. package/dest/aztec-node/register_node_rpc_handlers.js +31 -0
  13. package/dest/aztec-node/server.d.ts +91 -100
  14. package/dest/aztec-node/server.d.ts.map +1 -1
  15. package/dest/aztec-node/server.js +1073 -492
  16. package/dest/bin/index.js +14 -9
  17. package/dest/index.d.ts +2 -1
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +1 -0
  20. package/dest/sentinel/config.d.ts +3 -2
  21. package/dest/sentinel/config.d.ts.map +1 -1
  22. package/dest/sentinel/config.js +15 -5
  23. package/dest/sentinel/factory.d.ts +4 -2
  24. package/dest/sentinel/factory.d.ts.map +1 -1
  25. package/dest/sentinel/factory.js +4 -4
  26. package/dest/sentinel/sentinel.d.ts +133 -9
  27. package/dest/sentinel/sentinel.d.ts.map +1 -1
  28. package/dest/sentinel/sentinel.js +212 -70
  29. package/dest/sentinel/store.d.ts +8 -8
  30. package/dest/sentinel/store.d.ts.map +1 -1
  31. package/dest/sentinel/store.js +25 -17
  32. package/dest/test/index.d.ts +3 -3
  33. package/dest/test/index.d.ts.map +1 -1
  34. package/package.json +27 -26
  35. package/src/aztec-node/block_response_helpers.ts +161 -0
  36. package/src/aztec-node/config.ts +23 -7
  37. package/src/aztec-node/public_data_overrides.ts +35 -0
  38. package/src/aztec-node/register_node_rpc_handlers.ts +29 -0
  39. package/src/aztec-node/server.ts +1190 -625
  40. package/src/bin/index.ts +13 -11
  41. package/src/index.ts +1 -0
  42. package/src/sentinel/README.md +103 -0
  43. package/src/sentinel/config.ts +18 -6
  44. package/src/sentinel/factory.ts +7 -4
  45. package/src/sentinel/sentinel.ts +267 -82
  46. package/src/sentinel/store.ts +26 -18
  47. package/src/test/index.ts +2 -2
@@ -1,5 +1,6 @@
1
- import { Archiver, createArchiver } from '@aztec/archiver';
2
- import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
1
+ import { Archiver, L1ToL2MessagesNotReadyError, createArchiver } from '@aztec/archiver';
2
+ import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
3
+ import { TestCircuitVerifier } from '@aztec/bb-prover/test';
3
4
  import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
4
5
  import { Blob } from '@aztec/blob-lib';
5
6
  import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
@@ -7,16 +8,25 @@ import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
7
8
  import { createEthereumChain } from '@aztec/ethereum/chain';
8
9
  import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
9
10
  import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
10
- import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
11
- import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
11
+ import { type L1ContractAddresses, pickL1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
12
+ import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
13
+ import {
14
+ BlockNumber,
15
+ CheckpointNumber,
16
+ type CheckpointProposalHash,
17
+ EpochNumber,
18
+ SlotNumber,
19
+ } from '@aztec/foundation/branded-types';
12
20
  import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
13
21
  import { Fr } from '@aztec/foundation/curves/bn254';
14
22
  import { EthAddress } from '@aztec/foundation/eth-address';
15
23
  import { BadRequestError } from '@aztec/foundation/json-rpc';
16
24
  import { type Logger, createLogger } from '@aztec/foundation/log';
25
+ import { retryUntil } from '@aztec/foundation/retry';
17
26
  import { count } from '@aztec/foundation/string';
18
27
  import { DateProvider, Timer } from '@aztec/foundation/timer';
19
28
  import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
29
+ import { isErrorClass } from '@aztec/foundation/types';
20
30
  import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
21
31
  import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
22
32
  import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
@@ -30,26 +40,46 @@ import {
30
40
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
31
41
  import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
32
42
  import { createKeyStoreForProver } from '@aztec/prover-node/config';
33
- import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
34
- import { PublicProcessorFactory } from '@aztec/simulator/server';
43
+ import {
44
+ FeeProviderImpl,
45
+ GlobalVariableBuilder,
46
+ SequencerClient,
47
+ type SequencerPublisher,
48
+ } from '@aztec/sequencer-client';
49
+ import { AutomineSequencer, createAutomineSequencer } from '@aztec/sequencer-client/automine';
50
+ import { PublicContractsDB, PublicProcessorFactory } from '@aztec/simulator/server';
35
51
  import {
36
52
  AttestationsBlockWatcher,
37
- EpochPruneWatcher,
53
+ AttestedInvalidProposalWatcher,
54
+ BroadcastedInvalidCheckpointProposalWatcher,
55
+ CheckpointEquivocationWatcher,
56
+ DataWithholdingWatcher,
38
57
  type SlasherClientInterface,
39
58
  type Watcher,
40
59
  createSlasher,
41
60
  } from '@aztec/slasher';
61
+ import { STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS } from '@aztec/standard-contracts/multi-call-entrypoint';
42
62
  import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
43
63
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
44
64
  import {
45
65
  type BlockData,
46
66
  BlockHash,
47
67
  type BlockParameter,
68
+ BlockTag,
69
+ type CheckpointsQuery,
70
+ type CommitteeAttestation,
48
71
  type DataInBlock,
49
- L2Block,
50
72
  type L2BlockSource,
73
+ type L2Tips,
74
+ type NormalizedBlockParameter,
75
+ inspectBlockParameter,
51
76
  } from '@aztec/stdlib/block';
52
- import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
77
+ import {
78
+ type CheckpointData,
79
+ CheckpointReexecutionTracker,
80
+ L1PublishedData,
81
+ type PublishedCheckpoint,
82
+ } from '@aztec/stdlib/checkpoint';
53
83
  import type {
54
84
  ContractClassPublic,
55
85
  ContractDataSource,
@@ -57,16 +87,27 @@ import type {
57
87
  NodeInfo,
58
88
  ProtocolContractAddresses,
59
89
  } from '@aztec/stdlib/contract';
60
- import { GasFees } from '@aztec/stdlib/gas';
90
+ import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
91
+ import { GasFees, type ManaUsageEstimate, getNetworkTxGasLimits } from '@aztec/stdlib/gas';
61
92
  import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
62
- import {
63
- type AztecNode,
64
- type AztecNodeAdmin,
65
- type AztecNodeAdminConfig,
66
- AztecNodeAdminConfigSchema,
67
- type GetContractClassLogsResponse,
68
- type GetPublicLogsResponse,
93
+ import type {
94
+ AztecNode,
95
+ AztecNodeAdmin,
96
+ AztecNodeAdminConfig,
97
+ AztecNodeDebug,
98
+ BlockIncludeOptions,
99
+ BlockResponse,
100
+ BlocksIncludeOptions,
101
+ ChainTip,
102
+ ChainTips,
103
+ CheckpointIncludeOptions,
104
+ CheckpointParameter,
105
+ CheckpointResponse,
106
+ GetTxByHashOptions,
107
+ PeerInfo,
108
+ ProposalsForSlot,
69
109
  } from '@aztec/stdlib/interfaces/client';
110
+ import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
70
111
  import {
71
112
  type AllowedElement,
72
113
  type ClientProtocolCircuitVerifier,
@@ -76,25 +117,39 @@ import {
76
117
  type WorldStateSynchronizer,
77
118
  tryStop,
78
119
  } from '@aztec/stdlib/interfaces/server';
79
- import type { DebugLogStore, LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
120
+ import type { DebugLogStore, LogResult, PrivateLogsQuery, PublicLogsQuery } from '@aztec/stdlib/logs';
80
121
  import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
81
- import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
82
- import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
83
- import type { NullifierLeafPreimage, PublicDataTreeLeaf, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
122
+ import {
123
+ InboxLeaf,
124
+ type L1ToL2MessageSource,
125
+ type L2ToL1MembershipWitness,
126
+ appendL1ToL2MessagesToTree,
127
+ } from '@aztec/stdlib/messaging';
128
+ import type { CheckpointAttestation } from '@aztec/stdlib/p2p';
129
+ import type { Offense } from '@aztec/stdlib/slashing';
130
+ import type { NullifierLeafPreimage, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
84
131
  import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
85
132
  import {
86
- type BlockHeader,
133
+ DroppedTxReceipt,
134
+ type FeeProvider,
135
+ type GetTxReceiptOptions,
87
136
  type GlobalVariableBuilder as GlobalVariableBuilderInterface,
137
+ GlobalVariables,
88
138
  type IndexedTxEffect,
139
+ MinedTxReceipt,
140
+ type MinedTxStatus,
141
+ PendingTxReceipt,
89
142
  PublicSimulationOutput,
143
+ type SimulationOverrides,
90
144
  Tx,
91
145
  type TxHash,
92
- TxReceipt,
146
+ type TxReceipt,
93
147
  TxStatus,
94
148
  type TxValidationResult,
95
149
  } from '@aztec/stdlib/tx';
96
150
  import { getPackageVersion } from '@aztec/stdlib/update-checker';
97
151
  import type { SingleValidatorStats, ValidatorsStats } from '@aztec/stdlib/validators';
152
+ import type { GenesisData } from '@aztec/stdlib/world-state';
98
153
  import {
99
154
  Attributes,
100
155
  type TelemetryClient,
@@ -108,28 +163,36 @@ import {
108
163
  FullNodeCheckpointsBuilder,
109
164
  NodeKeystoreAdapter,
110
165
  ValidatorClient,
111
- createBlockProposalHandler,
166
+ createProposalHandler,
112
167
  createValidatorClient,
113
168
  } from '@aztec/validator-client';
114
169
  import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
115
- import { createWorldStateSynchronizer } from '@aztec/world-state';
170
+ import { createWorldState, createWorldStateSynchronizer } from '@aztec/world-state';
116
171
 
117
172
  import { createPublicClient } from 'viem';
118
173
 
119
174
  import { createSentinel } from '../sentinel/factory.js';
120
175
  import { Sentinel } from '../sentinel/sentinel.js';
176
+ import {
177
+ blockResponseFromBlockData,
178
+ blockResponseFromL2Block,
179
+ checkpointResponseFromCheckpointData,
180
+ checkpointResponseFromPublishedCheckpoint,
181
+ projectProposedToCheckpointResponse,
182
+ } from './block_response_helpers.js';
121
183
  import { type AztecNodeConfig, createKeyStoreForValidator } from './config.js';
122
184
  import { NodeMetrics } from './node_metrics.js';
185
+ import { applyPublicDataOverrides } from './public_data_overrides.js';
123
186
 
124
187
  /**
125
188
  * The aztec node.
126
189
  */
127
- export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
190
+ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDebug, Traceable {
128
191
  private metrics: NodeMetrics;
129
- private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
130
-
131
192
  // Prevent two snapshot operations to happen simultaneously
132
193
  private isUploadingSnapshot = false;
194
+ // Saved minTxsPerBlock used by `pauseSequencer` to restore production-sequencer config on resume.
195
+ private sequencerPausedMinTxsPerBlock: number | undefined;
133
196
 
134
197
  public readonly tracer: Tracer;
135
198
 
@@ -145,25 +208,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
145
208
  protected readonly proverNode: ProverNode | undefined,
146
209
  protected readonly slasherClient: SlasherClientInterface | undefined,
147
210
  protected readonly validatorsSentinel: Sentinel | undefined,
148
- protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
211
+ private readonly stopStartedWatchers: () => Promise<void>,
149
212
  protected readonly l1ChainId: number,
150
213
  protected readonly version: number,
151
214
  protected readonly globalVariableBuilder: GlobalVariableBuilderInterface,
215
+ protected readonly feeProvider: FeeProvider,
152
216
  protected readonly epochCache: EpochCacheInterface,
153
217
  protected readonly packageVersion: string,
154
- private proofVerifier: ClientProtocolCircuitVerifier,
218
+ private peerProofVerifier: ClientProtocolCircuitVerifier,
219
+ private rpcProofVerifier: ClientProtocolCircuitVerifier,
155
220
  private telemetry: TelemetryClient = getTelemetryClient(),
156
221
  private log = createLogger('node'),
157
222
  private blobClient?: BlobClientInterface,
158
223
  private validatorClient?: ValidatorClient,
159
224
  private keyStoreManager?: KeystoreManager,
160
225
  private debugLogStore: DebugLogStore = new NullDebugLogStore(),
226
+ private readonly automineSequencer?: AutomineSequencer,
161
227
  ) {
162
228
  this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
163
229
  this.tracer = telemetry.getTracer('AztecNodeService');
164
230
 
165
231
  this.log.info(`Aztec Node version: ${this.packageVersion}`);
166
- this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
232
+ this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, pickL1ContractAddresses(config));
167
233
 
168
234
  // A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
169
235
  // never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
@@ -173,13 +239,264 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
173
239
  }
174
240
  }
175
241
 
242
+ /** @internal Exposed for testing — returns the RPC proof verifier. */
243
+ public getProofVerifier(): ClientProtocolCircuitVerifier {
244
+ return this.rpcProofVerifier;
245
+ }
246
+
176
247
  public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
177
248
  const status = await this.worldStateSynchronizer.status();
178
249
  return status.syncSummary;
179
250
  }
180
251
 
181
- public getL2Tips() {
182
- return this.blockSource.getL2Tips();
252
+ public async getChainTips(): Promise<ChainTips> {
253
+ const { proposed, checkpointed, proven, finalized } = await this.blockSource.getL2Tips();
254
+ return { proposed, checkpointed, proven, finalized };
255
+ }
256
+
257
+ public getL1Constants() {
258
+ return this.blockSource.getL1Constants();
259
+ }
260
+
261
+ public getSyncedL2SlotNumber() {
262
+ return this.blockSource.getSyncedL2SlotNumber();
263
+ }
264
+
265
+ public getSyncedL2EpochNumber() {
266
+ return this.blockSource.getSyncedL2EpochNumber();
267
+ }
268
+
269
+ public getSyncedL1Timestamp() {
270
+ return this.blockSource.getL1Timestamp();
271
+ }
272
+
273
+ public getCheckpointsData(query: CheckpointsQuery) {
274
+ return this.blockSource.getCheckpointsData(query);
275
+ }
276
+
277
+ public async getBlockNumber(tip?: ChainTip): Promise<BlockNumber> {
278
+ if (tip === undefined || tip === 'proposed') {
279
+ return this.blockSource.getBlockNumber();
280
+ }
281
+ return (await this.blockSource.getBlockNumber({ tag: tip })) ?? BlockNumber.ZERO;
282
+ }
283
+
284
+ public async getCheckpointNumber(tip?: ChainTip): Promise<CheckpointNumber> {
285
+ const tips = await this.blockSource.getL2Tips();
286
+ switch (tip) {
287
+ case undefined:
288
+ case 'checkpointed':
289
+ return tips.checkpointed.checkpoint.number;
290
+ case 'proposed':
291
+ return tips.proposedCheckpoint.checkpoint.number;
292
+ case 'proven':
293
+ return tips.proven.checkpoint.number;
294
+ case 'finalized':
295
+ return tips.finalized.checkpoint.number;
296
+ }
297
+ }
298
+
299
+ private isChainTip(value: unknown): value is ChainTip {
300
+ return value === 'proposed' || value === 'checkpointed' || value === 'proven' || value === 'finalized';
301
+ }
302
+
303
+ /**
304
+ * Normalizes a {@link BlockParameter} (which may be a bare value) into a
305
+ * {@link NormalizedBlockParameter} object form. Performs no chain-tip resolution — tag
306
+ * lookups are deferred to the underlying block source.
307
+ */
308
+ private normalizeBlockParameter(param: BlockParameter): NormalizedBlockParameter {
309
+ if (BlockHash.isBlockHash(param)) {
310
+ return { hash: param };
311
+ }
312
+ if (typeof param === 'number') {
313
+ return { number: param as BlockNumber };
314
+ }
315
+ if (typeof param === 'string') {
316
+ if (this.isBlockTag(param)) {
317
+ return { tag: param === 'latest' ? 'proposed' : param };
318
+ }
319
+ throw new BadRequestError(`Invalid BlockParameter tag: ${param}`);
320
+ }
321
+ if (typeof param === 'object' && param !== null) {
322
+ if ('number' in param) {
323
+ return { number: param.number };
324
+ }
325
+ if ('hash' in param) {
326
+ return { hash: param.hash };
327
+ }
328
+ if ('archive' in param) {
329
+ return { archive: param.archive };
330
+ }
331
+ if ('tag' in param) {
332
+ if (this.isBlockTag(param.tag)) {
333
+ return { tag: param.tag };
334
+ }
335
+ throw new BadRequestError(`Invalid BlockParameter tag: ${param.tag}`);
336
+ }
337
+ }
338
+ throw new BadRequestError(`Invalid BlockParameter: ${JSON.stringify(param)}`);
339
+ }
340
+
341
+ private isBlockTag(value: string): value is BlockTag {
342
+ return BlockTag.includes(value as BlockTag);
343
+ }
344
+
345
+ /**
346
+ * Resolves a {@link CheckpointParameter} into a concrete `{ number }` or `{ slot }` query.
347
+ *
348
+ * Tag-based parameters (`'proposed'`, `'checkpointed'`, `'proven'`, `'finalized'`) are
349
+ * translated up-front to the corresponding tip's checkpoint number via {@link L2BlockSource.getL2Tips}.
350
+ * After resolution the unified {@link getCheckpoint} flow can perform a single
351
+ * confirmed→proposed lookup against either store.
352
+ */
353
+ private async resolveCheckpointParameter(
354
+ param: CheckpointParameter,
355
+ ): Promise<{ number: CheckpointNumber } | { slot: SlotNumber }> {
356
+ if (typeof param === 'number') {
357
+ return { number: param as CheckpointNumber };
358
+ }
359
+ if (this.isChainTip(param)) {
360
+ const tips = await this.blockSource.getL2Tips();
361
+ switch (param) {
362
+ case 'proposed':
363
+ return { number: tips.proposedCheckpoint.checkpoint.number };
364
+ case 'checkpointed':
365
+ return { number: tips.checkpointed.checkpoint.number };
366
+ case 'proven':
367
+ return { number: tips.proven.checkpoint.number };
368
+ case 'finalized':
369
+ return { number: tips.finalized.checkpoint.number };
370
+ }
371
+ }
372
+ if (typeof param === 'object' && param !== null) {
373
+ if ('number' in param) {
374
+ return { number: param.number };
375
+ }
376
+ if ('slot' in param) {
377
+ return { slot: param.slot };
378
+ }
379
+ }
380
+ throw new BadRequestError(`Invalid CheckpointParameter: ${JSON.stringify(param)}`);
381
+ }
382
+
383
+ /** Fetches checkpoint-level L1 and attestation data for use as block response context. */
384
+ async #getCheckpointContext(
385
+ checkpointNumber: CheckpointNumber,
386
+ ): Promise<{ l1?: L1PublishedData; attestations?: CommitteeAttestation[] } | undefined> {
387
+ const checkpoint = await this.blockSource.getCheckpointData({ number: checkpointNumber });
388
+ if (!checkpoint) {
389
+ return undefined;
390
+ }
391
+ return { l1: checkpoint.l1, attestations: checkpoint.attestations };
392
+ }
393
+
394
+ public async getBlock<Opts extends BlockIncludeOptions = {}>(
395
+ param: BlockParameter,
396
+ options: Opts = {} as Opts,
397
+ ): Promise<BlockResponse<Opts> | undefined> {
398
+ const query = this.normalizeBlockParameter(param);
399
+ const wantTxs = !!options.includeTransactions;
400
+ const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
401
+
402
+ if (wantTxs) {
403
+ const block = await this.blockSource.getBlock(query);
404
+ if (!block) {
405
+ return undefined;
406
+ }
407
+ const ctx = wantContext ? await this.#getCheckpointContext(block.checkpointNumber) : undefined;
408
+ return (await blockResponseFromL2Block(block, options, ctx)) as BlockResponse<Opts>;
409
+ }
410
+ const data = await this.blockSource.getBlockData(query);
411
+ if (!data) {
412
+ return undefined;
413
+ }
414
+ const ctx = wantContext ? await this.#getCheckpointContext(data.checkpointNumber) : undefined;
415
+ return blockResponseFromBlockData(data, options, ctx) as BlockResponse<Opts>;
416
+ }
417
+
418
+ public getBlockData(param: BlockParameter): Promise<BlockData | undefined> {
419
+ const query = this.normalizeBlockParameter(param);
420
+ return this.blockSource.getBlockData(query);
421
+ }
422
+
423
+ public async getBlocks<Opts extends BlocksIncludeOptions = {}>(
424
+ from: BlockNumber,
425
+ limit: number,
426
+ options: Opts = {} as Opts,
427
+ ): Promise<BlockResponse<Opts>[]> {
428
+ const wantTxs = !!options.includeTransactions;
429
+ const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
430
+ const onlyCheckpointed = !!options.onlyCheckpointed;
431
+ if (wantTxs) {
432
+ const blocks = await this.blockSource.getBlocks({ from, limit, onlyCheckpointed });
433
+ const ctxByCheckpoint = await this.#getCheckpointContextsForBlocks(wantContext ? blocks : []);
434
+ return (await Promise.all(
435
+ blocks.map(block => blockResponseFromL2Block(block, options, ctxByCheckpoint.get(block.checkpointNumber))),
436
+ )) as BlockResponse<Opts>[];
437
+ }
438
+ const dataItems = await this.blockSource.getBlocksData({ from, limit, onlyCheckpointed });
439
+ const ctxByCheckpoint = await this.#getCheckpointContextsForBlocks(wantContext ? dataItems : []);
440
+ return (await Promise.all(
441
+ dataItems.map(data => blockResponseFromBlockData(data, options, ctxByCheckpoint.get(data.checkpointNumber))),
442
+ )) as BlockResponse<Opts>[];
443
+ }
444
+
445
+ /** Fetches checkpoint context for a set of blocks, deduplicating shared checkpoints. */
446
+ async #getCheckpointContextsForBlocks(
447
+ blocks: { checkpointNumber: CheckpointNumber }[],
448
+ ): Promise<Map<CheckpointNumber, { l1?: L1PublishedData; attestations?: CommitteeAttestation[] } | undefined>> {
449
+ const unique = Array.from(new Set(blocks.map(b => b.checkpointNumber)));
450
+ const entries = await Promise.all(unique.map(async n => [n, await this.#getCheckpointContext(n)] as const));
451
+ return new Map(entries);
452
+ }
453
+
454
+ public async getCheckpoint<Opts extends CheckpointIncludeOptions = {}>(
455
+ param: CheckpointParameter,
456
+ options: Opts = {} as Opts,
457
+ ): Promise<CheckpointResponse<Opts> | undefined> {
458
+ const query = await this.resolveCheckpointParameter(param);
459
+
460
+ // Try the confirmed store first.
461
+ const confirmed = options.includeBlocks
462
+ ? await this.blockSource.getCheckpoint(query)
463
+ : await this.blockSource.getCheckpointData(query);
464
+ if (confirmed) {
465
+ return (await (options.includeBlocks
466
+ ? checkpointResponseFromPublishedCheckpoint(confirmed as PublishedCheckpoint, options)
467
+ : checkpointResponseFromCheckpointData(confirmed as CheckpointData, options))) as CheckpointResponse<Opts>;
468
+ }
469
+
470
+ // Fall back to the proposed store.
471
+ const proposed = await this.blockSource.getProposedCheckpointData(query);
472
+ if (proposed) {
473
+ if (options.includeAttestations || options.includeL1PublishInfo) {
474
+ throw new BadRequestError(
475
+ `Options includeL1PublishInfo or includeAttestations cannot be satisfied for a proposed checkpoint`,
476
+ );
477
+ }
478
+ const blocks = options.includeBlocks
479
+ ? await this.blockSource.getBlocks({ from: proposed.startBlock, limit: proposed.blockCount })
480
+ : undefined;
481
+ return (await projectProposedToCheckpointResponse(proposed, options, blocks)) as CheckpointResponse<Opts>;
482
+ }
483
+
484
+ return undefined;
485
+ }
486
+
487
+ public async getCheckpoints<Opts extends CheckpointIncludeOptions = {}>(
488
+ from: CheckpointNumber,
489
+ limit: number,
490
+ options: Opts = {} as Opts,
491
+ ): Promise<CheckpointResponse<Opts>[]> {
492
+ if (options.includeBlocks) {
493
+ const checkpoints = await this.blockSource.getCheckpoints({ from, limit });
494
+ return (await Promise.all(
495
+ checkpoints.map(cp => checkpointResponseFromPublishedCheckpoint(cp, options)),
496
+ )) as CheckpointResponse<Opts>[];
497
+ }
498
+ const datas = await this.blockSource.getCheckpointsData({ from, limit });
499
+ return datas.map(d => checkpointResponseFromCheckpointData(d, options)) as CheckpointResponse<Opts>[];
183
500
  }
184
501
 
185
502
  /**
@@ -199,14 +516,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
199
516
  slashingProtectionDb?: SlashingProtectionDatabase;
200
517
  } = {},
201
518
  options: {
202
- prefilledPublicData?: PublicDataTreeLeaf[];
519
+ genesis?: GenesisData;
203
520
  dontStartSequencer?: boolean;
204
521
  dontStartProverNode?: boolean;
205
522
  } = {},
206
523
  ): Promise<AztecNodeService> {
207
524
  const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
208
525
  const log = deps.logger ?? createLogger('node');
209
- const packageVersion = getPackageVersion() ?? '';
526
+ const packageVersion = getPackageVersion();
210
527
  const telemetry = deps.telemetry ?? getTelemetryClient();
211
528
  const dateProvider = deps.dateProvider ?? new DateProvider();
212
529
  const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
@@ -265,17 +582,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
265
582
 
266
583
  const l1ContractsAddresses = await RegistryContract.collectAddresses(
267
584
  publicClient,
268
- config.l1Contracts.registryAddress,
585
+ config.registryAddress,
269
586
  config.rollupVersion ?? 'canonical',
270
587
  );
271
588
 
272
- // Overwrite the passed in vars.
273
- config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
589
+ Object.assign(config, l1ContractsAddresses);
274
590
 
275
- const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
276
- const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
591
+ const rollupContract = new RollupContract(publicClient, config.rollupAddress.toString());
592
+ const [l1GenesisTime, slotDuration, epochDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
277
593
  rollupContract.getL1GenesisTime(),
278
594
  rollupContract.getSlotDuration(),
595
+ rollupContract.getEpochDuration(),
279
596
  rollupContract.getVersion(),
280
597
  rollupContract.getManaLimit().then(Number),
281
598
  ] as const);
@@ -293,301 +610,472 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
293
610
  // attempt snapshot sync if possible
294
611
  await trySnapshotSync(config, log);
295
612
 
296
- const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, { dateProvider });
297
-
298
- const archiver = await createArchiver(
299
- config,
300
- { blobClient, epochCache, telemetry, dateProvider },
301
- { blockUntilSync: !config.skipArchiverInitialSync },
302
- );
613
+ const epochCache = await EpochCache.create(config.rollupAddress, config, { dateProvider });
303
614
 
304
- // now create the merkle trees and the world state synchronizer
305
- const worldStateSynchronizer = await createWorldStateSynchronizer(
306
- config,
307
- archiver,
308
- options.prefilledPublicData,
309
- telemetry,
310
- );
311
- const circuitVerifier =
312
- config.realProofs || config.debugForceTxProofVerification
313
- ? await BBCircuitVerifier.new(config)
314
- : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
315
-
316
- let debugLogStore: DebugLogStore;
317
- if (!config.realProofs) {
318
- log.warn(`Aztec node is accepting fake proofs`);
319
-
320
- debugLogStore = new InMemoryDebugLogStore();
321
- log.info(
322
- 'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
323
- );
324
- } else {
325
- debugLogStore = new NullDebugLogStore();
326
- }
615
+ // Track started resources so we can clean up on partial failure during node creation.
616
+ const started: { stop?(): Promise<void> | void }[] = [];
617
+ try {
618
+ config.skipOrphanProposedBlockPruning ||= !!config.useAutomineSequencer;
327
619
 
328
- const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
620
+ AztecNodeService.checkConfigMatchesRollup(config, {
621
+ slotDuration: Number(slotDuration),
622
+ epochDuration: Number(epochDuration),
623
+ });
329
624
 
330
- const proverOnly = config.enableProverNode && config.disableValidator;
331
- if (proverOnly) {
332
- log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
333
- }
625
+ // Create world-state first so we can retrieve the initial header before constructing the archiver.
626
+ const nativeWs = await createWorldState(config, options.genesis);
627
+ const initialHeader = nativeWs.getInitialHeader();
628
+ const initialBlockHash = await initialHeader.hash();
629
+ const archiver = await createArchiver(
630
+ config,
631
+ { blobClient, epochCache, telemetry, dateProvider },
632
+ { blockUntilSync: !config.skipArchiverInitialSync },
633
+ initialHeader,
634
+ initialBlockHash,
635
+ );
636
+ started.push(archiver);
637
+
638
+ // The synchronizer takes ownership of the native world-state from here
639
+ const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, nativeWs, telemetry);
640
+ started.push(worldStateSynchronizer);
641
+ const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
642
+ let peerProofVerifier: ClientProtocolCircuitVerifier;
643
+ let rpcProofVerifier: ClientProtocolCircuitVerifier;
644
+ if (useRealVerifiers) {
645
+ peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
646
+ const rpcVerifier = await BBCircuitVerifier.new(config);
647
+ rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
648
+ } else {
649
+ peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
650
+ rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
651
+ }
652
+ started.push(peerProofVerifier, rpcProofVerifier);
334
653
 
335
- // create the tx pool and the p2p client, which will need the l2 block source
336
- const p2pClient = await createP2PClient(
337
- config,
338
- archiver,
339
- proofVerifier,
340
- worldStateSynchronizer,
341
- epochCache,
342
- packageVersion,
343
- dateProvider,
344
- telemetry,
345
- deps.p2pClientDeps,
346
- );
654
+ let debugLogStore: DebugLogStore;
655
+ if (!config.realProofs) {
656
+ log.warn(`Aztec node is accepting fake proofs`);
347
657
 
348
- // We'll accumulate sentinel watchers here
349
- const watchers: Watcher[] = [];
658
+ debugLogStore = new InMemoryDebugLogStore();
659
+ log.info(
660
+ 'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
661
+ );
662
+ } else {
663
+ debugLogStore = new NullDebugLogStore();
664
+ }
350
665
 
351
- // Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
352
- // Override maxTxsPerCheckpoint with the validator-specific limit if set.
353
- const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
354
- {
355
- ...config,
666
+ const globalVariableBuilderConfig = {
667
+ rollupAddress: config.rollupAddress,
668
+ ethereumSlotDuration: config.ethereumSlotDuration,
669
+ rollupVersion: BigInt(config.rollupVersion),
356
670
  l1GenesisTime,
357
671
  slotDuration: Number(slotDuration),
358
- rollupManaLimit,
359
- maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
360
- },
361
- worldStateSynchronizer,
362
- archiver,
363
- dateProvider,
364
- telemetry,
365
- );
366
-
367
- let validatorClient: ValidatorClient | undefined;
672
+ };
368
673
 
369
- if (!proverOnly) {
370
- // Create validator client if required
371
- validatorClient = await createValidatorClient(config, {
372
- checkpointsBuilder: validatorCheckpointsBuilder,
373
- worldState: worldStateSynchronizer,
374
- p2pClient,
375
- telemetry,
376
- dateProvider,
377
- epochCache,
378
- blockSource: archiver,
379
- l1ToL2MessageSource: archiver,
380
- keyStoreManager,
381
- blobClient,
382
- slashingProtectionDb: deps.slashingProtectionDb,
383
- });
674
+ const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, globalVariableBuilderConfig);
675
+ const feeProvider = new FeeProviderImpl(dateProvider, publicClient, globalVariableBuilderConfig);
384
676
 
385
- // If we have a validator client, register it as a source of offenses for the slasher,
386
- // and have it register callbacks on the p2p client *before* we start it, otherwise messages
387
- // like attestations or auths will fail.
388
- if (validatorClient) {
389
- watchers.push(validatorClient);
390
- if (!options.dontStartSequencer) {
391
- await validatorClient.registerHandlers();
392
- }
677
+ const proverOnly = config.enableProverNode && config.disableValidator;
678
+ if (proverOnly) {
679
+ log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
393
680
  }
394
- }
395
681
 
396
- // If there's no validator client, create a BlockProposalHandler to handle block proposals
397
- // for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
398
- // while non-reexecution is used for validating the proposals and collecting their txs.
399
- if (!validatorClient) {
400
- const reexecute = !!config.alwaysReexecuteBlockProposals;
401
- log.info(`Setting up block proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
402
- createBlockProposalHandler(config, {
403
- checkpointsBuilder: validatorCheckpointsBuilder,
404
- worldState: worldStateSynchronizer,
682
+ // create the tx pool and the p2p client, which will need the l2 block source
683
+ const p2pClient = await createP2PClient(
684
+ config,
685
+ archiver,
686
+ peerProofVerifier,
687
+ worldStateSynchronizer,
405
688
  epochCache,
406
- blockSource: archiver,
407
- l1ToL2MessageSource: archiver,
408
- p2pClient,
689
+ feeProvider,
690
+ packageVersion,
409
691
  dateProvider,
410
692
  telemetry,
411
- }).register(p2pClient, reexecute);
412
- }
693
+ deps.p2pClientDeps,
694
+ initialBlockHash,
695
+ );
696
+ started.push(p2pClient);
697
+ archiver.setCheckpointProposalPresence(p2pClient);
698
+
699
+ // We'll accumulate sentinel watchers here
700
+ const watchers: Watcher[] = [];
701
+
702
+ // Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
703
+ // Override maxTxsPerCheckpoint with the validator-specific limit if set.
704
+ const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
705
+ {
706
+ ...config,
707
+ l1GenesisTime,
708
+ slotDuration: Number(slotDuration),
709
+ rollupManaLimit,
710
+ maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
711
+ },
712
+ worldStateSynchronizer,
713
+ archiver,
714
+ dateProvider,
715
+ telemetry,
716
+ );
413
717
 
414
- // Start world state and wait for it to sync to the archiver.
415
- await worldStateSynchronizer.start();
718
+ let validatorClient: ValidatorClient | undefined;
416
719
 
417
- // Start p2p. Note that it depends on world state to be running.
418
- await p2pClient.start();
720
+ // Tracks successful checkpoint re-execution by a checkpoint proposal handler.
721
+ const reexecutionTracker = new CheckpointReexecutionTracker();
419
722
 
420
- let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
421
- let epochPruneWatcher: EpochPruneWatcher | undefined;
422
- let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
723
+ if (!config.disableValidator) {
724
+ // Create validator client if required
725
+ validatorClient = await createValidatorClient(config, {
726
+ checkpointsBuilder: validatorCheckpointsBuilder,
727
+ worldState: worldStateSynchronizer,
728
+ p2pClient,
729
+ telemetry,
730
+ dateProvider,
731
+ epochCache,
732
+ blockSource: archiver,
733
+ l1ToL2MessageSource: archiver,
734
+ keyStoreManager,
735
+ blobClient,
736
+ reexecutionTracker,
737
+ slashingProtectionDb: deps.slashingProtectionDb,
738
+ });
739
+
740
+ // If we have a validator client, register it as a source of offenses for the slasher,
741
+ // and have it register callbacks on the p2p client *before* we start it, otherwise messages
742
+ // like attestations or auths will fail.
743
+ if (validatorClient) {
744
+ watchers.push(validatorClient);
745
+
746
+ const vc = validatorClient;
747
+ const getValidatorAddresses = () => vc.getValidatorAddresses().map(a => a.toString());
748
+ validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
749
+
750
+ if (!options.dontStartSequencer) {
751
+ await validatorClient.registerHandlers();
752
+ }
753
+ }
754
+ }
423
755
 
424
- if (!proverOnly) {
425
- validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
426
- if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
427
- watchers.push(validatorsSentinel);
756
+ // If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
757
+ // for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
758
+ // while non-reexecution is used for validating the proposals and collecting their txs.
759
+ // Checkpoint proposals rebuild blobs if the blob client can upload blobs.
760
+ if (!validatorClient) {
761
+ const reexecute = !!config.alwaysReexecuteBlockProposals;
762
+ log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
763
+ createProposalHandler(config, {
764
+ checkpointsBuilder: validatorCheckpointsBuilder,
765
+ worldState: worldStateSynchronizer,
766
+ epochCache,
767
+ blockSource: archiver,
768
+ l1ToL2MessageSource: archiver,
769
+ p2pClient,
770
+ blobClient,
771
+ dateProvider,
772
+ telemetry,
773
+ reexecutionTracker,
774
+ }).register(p2pClient, reexecute, archiver);
428
775
  }
429
776
 
430
- if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
431
- epochPruneWatcher = new EpochPruneWatcher(
777
+ // Start world state and wait for it to sync to the archiver.
778
+ await worldStateSynchronizer.start();
779
+
780
+ // Start p2p. Note that it depends on world state to be running.
781
+ await p2pClient.start();
782
+
783
+ let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
784
+ let dataWithholdingWatcher: DataWithholdingWatcher | undefined;
785
+ let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
786
+ let attestedInvalidProposalWatcher: AttestedInvalidProposalWatcher | undefined;
787
+ let broadcastedInvalidCheckpointProposalWatcher: BroadcastedInvalidCheckpointProposalWatcher | undefined;
788
+ let checkpointEquivocationWatcher: CheckpointEquivocationWatcher | undefined;
789
+
790
+ if (!proverOnly) {
791
+ validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, reexecutionTracker, config);
792
+ if (validatorsSentinel) {
793
+ watchers.push(validatorsSentinel);
794
+ }
795
+
796
+ dataWithholdingWatcher = new DataWithholdingWatcher(
797
+ epochCache,
432
798
  archiver,
799
+ p2pClient.getTxProvider(),
800
+ p2pClient,
801
+ reexecutionTracker,
802
+ { chainId: config.l1ChainId, rollupAddress: config.rollupAddress },
803
+ config,
804
+ );
805
+ watchers.push(dataWithholdingWatcher);
806
+
807
+ broadcastedInvalidCheckpointProposalWatcher = new BroadcastedInvalidCheckpointProposalWatcher(
808
+ p2pClient,
433
809
  archiver,
434
810
  epochCache,
435
- p2pClient.getTxProvider(),
436
- validatorCheckpointsBuilder,
437
811
  config,
438
812
  );
439
- watchers.push(epochPruneWatcher);
440
- }
813
+ watchers.push(broadcastedInvalidCheckpointProposalWatcher);
814
+
815
+ if (validatorClient) {
816
+ attestedInvalidProposalWatcher = new AttestedInvalidProposalWatcher(
817
+ p2pClient,
818
+ validatorClient,
819
+ archiver,
820
+ epochCache,
821
+ config,
822
+ { log: log.createChild('attested-invalid-proposal-watcher') },
823
+ );
824
+ watchers.push(attestedInvalidProposalWatcher);
825
+ }
441
826
 
442
- // We assume we want to slash for invalid attestations unless all max penalties are set to 0
443
- if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
444
- attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
827
+ checkpointEquivocationWatcher = new CheckpointEquivocationWatcher(archiver, epochCache, config);
828
+ watchers.push(checkpointEquivocationWatcher);
829
+
830
+ attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config, log.getBindings());
445
831
  watchers.push(attestationsBlockWatcher);
446
832
  }
447
- }
448
833
 
449
- // Start p2p-related services once the archiver has completed sync
450
- void archiver
451
- .waitForInitialSync()
452
- .then(async () => {
453
- await p2pClient.start();
454
- await validatorsSentinel?.start();
455
- await epochPruneWatcher?.start();
456
- await attestationsBlockWatcher?.start();
457
- log.info(`All p2p services started`);
458
- })
459
- .catch(err => log.error('Failed to start p2p services after archiver sync', err));
460
-
461
- // Validator enabled, create/start relevant service
462
- let sequencer: SequencerClient | undefined;
463
- let slasherClient: SlasherClientInterface | undefined;
464
- if (!config.disableValidator && validatorClient) {
465
- // We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
466
- // as they are executed when the node is selected as proposer.
467
- const validatorAddresses = keyStoreManager
468
- ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses()
469
- : [];
470
-
471
- slasherClient = await createSlasher(
472
- config,
473
- config.l1Contracts,
474
- getPublicClient(config),
475
- watchers,
476
- dateProvider,
477
- epochCache,
478
- validatorAddresses,
479
- undefined, // logger
480
- );
481
- await slasherClient.start();
834
+ const watchersToStart = compactArray([
835
+ validatorsSentinel,
836
+ dataWithholdingWatcher,
837
+ attestationsBlockWatcher,
838
+ broadcastedInvalidCheckpointProposalWatcher,
839
+ attestedInvalidProposalWatcher,
840
+ checkpointEquivocationWatcher,
841
+ ]);
842
+ const startedWatchers: Watcher[] = [];
843
+ const stopStartedWatchers = async () => {
844
+ for (const watcher of startedWatchers) {
845
+ await tryStop(watcher);
846
+ }
847
+ };
482
848
 
483
- const l1TxUtils = config.sequencerPublisherForwarderAddress
484
- ? await createForwarderL1TxUtilsFromSigners(
485
- publicClient,
486
- keyStoreManager!.createAllValidatorPublisherSigners(),
487
- config.sequencerPublisherForwarderAddress,
488
- { ...config, scope: 'sequencer' },
489
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
490
- )
491
- : await createL1TxUtilsFromSigners(
849
+ // Start p2p-related services once the archiver has completed sync
850
+ void archiver
851
+ .waitForInitialSync()
852
+ .then(async () => {
853
+ for (const watcher of watchersToStart) {
854
+ await watcher.start();
855
+ startedWatchers.push(watcher);
856
+ }
857
+ log.info(`All p2p services started`);
858
+ })
859
+ .catch(err => log.error('Failed to start p2p services after archiver sync', err));
860
+ started.push({ stop: stopStartedWatchers });
861
+
862
+ // Validator enabled, create/start relevant service
863
+ let sequencer: SequencerClient | undefined;
864
+ let automineSequencer: AutomineSequencer | undefined;
865
+ let slasherClient: SlasherClientInterface | undefined;
866
+ if (!config.disableValidator && validatorClient) {
867
+ // We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
868
+ // as they are executed when the node is selected as proposer.
869
+ const validatorAddresses = keyStoreManager
870
+ ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses()
871
+ : [];
872
+
873
+ slasherClient = await createSlasher(
874
+ config,
875
+ pickL1ContractAddresses(config),
876
+ getPublicClient(config),
877
+ watchers,
878
+ dateProvider,
879
+ epochCache,
880
+ validatorAddresses,
881
+ undefined, // logger
882
+ );
883
+ await slasherClient.start();
884
+ started.push(slasherClient);
885
+
886
+ const l1TxUtils = config.sequencerPublisherForwarderAddress
887
+ ? await createForwarderL1TxUtilsFromSigners(
888
+ publicClient,
889
+ keyStoreManager!.createAllValidatorPublisherSigners(),
890
+ config.sequencerPublisherForwarderAddress,
891
+ { ...config, scope: 'sequencer' },
892
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
893
+ )
894
+ : await createL1TxUtilsFromSigners(
895
+ publicClient,
896
+ keyStoreManager!.createAllValidatorPublisherSigners(),
897
+ { ...config, scope: 'sequencer' },
898
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
899
+ );
900
+
901
+ // Create a funder L1TxUtils from the keystore funding account (if configured)
902
+ const fundingSigner = keyStoreManager?.createFundingSigner();
903
+ let funderL1TxUtils: L1TxUtils | undefined;
904
+ if (fundingSigner) {
905
+ const [funder] = await createL1TxUtilsFromSigners(
492
906
  publicClient,
493
- keyStoreManager!.createAllValidatorPublisherSigners(),
907
+ [fundingSigner],
494
908
  { ...config, scope: 'sequencer' },
495
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
909
+ { telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
496
910
  );
911
+ funderL1TxUtils = funder;
912
+ }
497
913
 
498
- // Create and start the sequencer client
499
- const checkpointsBuilder = new CheckpointsBuilder(
500
- { ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
501
- worldStateSynchronizer,
502
- archiver,
503
- dateProvider,
504
- telemetry,
505
- debugLogStore,
506
- );
914
+ // Create and start the sequencer client
915
+ const checkpointsBuilder = new CheckpointsBuilder(
916
+ { ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
917
+ worldStateSynchronizer,
918
+ archiver,
919
+ dateProvider,
920
+ telemetry,
921
+ debugLogStore,
922
+ );
507
923
 
508
- sequencer = await SequencerClient.new(config, {
509
- ...deps,
510
- epochCache,
511
- l1TxUtils,
512
- validatorClient,
513
- p2pClient,
514
- worldStateSynchronizer,
515
- slasherClient,
516
- checkpointsBuilder,
517
- l2BlockSource: archiver,
518
- l1ToL2MessageSource: archiver,
519
- telemetry,
520
- dateProvider,
521
- blobClient,
522
- nodeKeyStore: keyStoreManager!,
523
- });
524
- }
924
+ if (config.useAutomineSequencer) {
925
+ // Test-only path: deterministic, queue-driven sequencer for non-block-building e2e tests.
926
+ // See `AUTOMINE_E2E_OPTS` in `end-to-end/src/fixtures/fixtures.ts`.
927
+ automineSequencer = await createAutomineSequencer({
928
+ config,
929
+ l1TxUtils,
930
+ funderL1TxUtils,
931
+ publicClient,
932
+ rollupContract,
933
+ epochCache,
934
+ blobClient,
935
+ telemetry,
936
+ dateProvider,
937
+ keyStoreManager: keyStoreManager!,
938
+ validatorClient,
939
+ checkpointsBuilder,
940
+ globalVariableBuilder,
941
+ worldStateSynchronizer,
942
+ archiver,
943
+ p2pClient,
944
+ l1Constants: {
945
+ l1GenesisTime,
946
+ slotDuration: Number(slotDuration),
947
+ ethereumSlotDuration: config.ethereumSlotDuration,
948
+ rollupManaLimit,
949
+ },
950
+ autoSettle: config.automineEnableProveEpoch,
951
+ log,
952
+ });
953
+ } else {
954
+ sequencer = await SequencerClient.new(config, {
955
+ ...deps,
956
+ epochCache,
957
+ l1TxUtils,
958
+ funderL1TxUtils,
959
+ validatorClient,
960
+ p2pClient,
961
+ worldStateSynchronizer,
962
+ slasherClient,
963
+ checkpointsBuilder,
964
+ l2BlockSource: archiver,
965
+ l1ToL2MessageSource: archiver,
966
+ telemetry,
967
+ dateProvider,
968
+ blobClient,
969
+ nodeKeyStore: keyStoreManager!,
970
+ globalVariableBuilder,
971
+ });
972
+ }
973
+ }
525
974
 
526
- if (!options.dontStartSequencer && sequencer) {
527
- await sequencer.start();
528
- log.verbose(`Sequencer started`);
529
- } else if (sequencer) {
530
- log.warn(`Sequencer created but not started`);
531
- }
975
+ if (!options.dontStartSequencer && sequencer) {
976
+ await sequencer.start();
977
+ started.push(sequencer);
978
+ log.verbose(`Sequencer started`);
979
+ } else if (sequencer) {
980
+ log.warn(`Sequencer created but not started`);
981
+ }
532
982
 
533
- // Create prover node subsystem if enabled
534
- let proverNode: ProverNode | undefined;
535
- if (config.enableProverNode) {
536
- proverNode = await createProverNode(config, {
537
- ...deps.proverNodeDeps,
538
- telemetry,
539
- dateProvider,
983
+ if (!options.dontStartSequencer && automineSequencer) {
984
+ await automineSequencer.start();
985
+ started.push({ stop: () => automineSequencer!.stop() });
986
+ log.verbose(`AutomineSequencer started`);
987
+ } else if (automineSequencer) {
988
+ log.warn(`AutomineSequencer created but not started`);
989
+ }
990
+
991
+ // Create prover node subsystem if enabled
992
+ let proverNode: ProverNode | undefined;
993
+ if (config.enableProverNode) {
994
+ proverNode = await createProverNode(config, {
995
+ ...deps.proverNodeDeps,
996
+ telemetry,
997
+ dateProvider,
998
+ archiver,
999
+ worldStateSynchronizer,
1000
+ p2pClient,
1001
+ epochCache,
1002
+ blobClient,
1003
+ keyStoreManager,
1004
+ });
1005
+
1006
+ if (!options.dontStartProverNode) {
1007
+ await proverNode.start();
1008
+ started.push(proverNode);
1009
+ log.info(`Prover node subsystem started`);
1010
+ } else {
1011
+ log.info(`Prover node subsystem created but not started`);
1012
+ }
1013
+ }
1014
+
1015
+ const node = new AztecNodeService(
1016
+ config,
1017
+ p2pClient,
1018
+ archiver,
1019
+ archiver,
1020
+ archiver,
540
1021
  archiver,
541
1022
  worldStateSynchronizer,
542
- p2pClient,
1023
+ sequencer,
1024
+ proverNode,
1025
+ slasherClient,
1026
+ validatorsSentinel,
1027
+ stopStartedWatchers,
1028
+ ethereumChain.chainInfo.id,
1029
+ config.rollupVersion,
1030
+ globalVariableBuilder,
1031
+ feeProvider,
543
1032
  epochCache,
1033
+ packageVersion,
1034
+ peerProofVerifier,
1035
+ rpcProofVerifier,
1036
+ telemetry,
1037
+ log,
544
1038
  blobClient,
1039
+ validatorClient,
545
1040
  keyStoreManager,
546
- });
1041
+ debugLogStore,
1042
+ automineSequencer,
1043
+ );
547
1044
 
548
- if (!options.dontStartProverNode) {
549
- await proverNode.start();
550
- log.info(`Prover node subsystem started`);
551
- } else {
552
- log.info(`Prover node subsystem created but not started`);
1045
+ return node;
1046
+ } catch (err) {
1047
+ log.error('Failed during node creation, stopping started resources', err);
1048
+ for (const resource of started.reverse()) {
1049
+ await tryStop(resource);
553
1050
  }
1051
+ throw err;
554
1052
  }
1053
+ }
555
1054
 
556
- const globalVariableBuilder = new GlobalVariableBuilder({
557
- ...config,
558
- rollupVersion: BigInt(config.rollupVersion),
559
- l1GenesisTime,
560
- slotDuration: Number(slotDuration),
561
- });
562
-
563
- const node = new AztecNodeService(
564
- config,
565
- p2pClient,
566
- archiver,
567
- archiver,
568
- archiver,
569
- archiver,
570
- worldStateSynchronizer,
571
- sequencer,
572
- proverNode,
573
- slasherClient,
574
- validatorsSentinel,
575
- epochPruneWatcher,
576
- ethereumChain.chainInfo.id,
577
- config.rollupVersion,
578
- globalVariableBuilder,
579
- epochCache,
580
- packageVersion,
581
- proofVerifier,
582
- telemetry,
583
- log,
584
- blobClient,
585
- validatorClient,
586
- keyStoreManager,
587
- debugLogStore,
588
- );
589
-
590
- return node;
1055
+ /**
1056
+ * Verifies the node's configured L1 timing matches the rollup contract it is pointed at, for the fields the
1057
+ * node's own config carries. Each comparison is guarded against an undefined config value, so a config that
1058
+ * does not carry a field is not checked. Throws a single error listing every mismatch. Runs in the shared
1059
+ * startup path for every node role.
1060
+ */
1061
+ private static checkConfigMatchesRollup(
1062
+ config: AztecNodeConfig,
1063
+ rollup: { slotDuration: number; epochDuration: number },
1064
+ ): void {
1065
+ const mismatches: string[] = [];
1066
+ if (config.aztecSlotDuration !== undefined && config.aztecSlotDuration !== rollup.slotDuration) {
1067
+ mismatches.push(`aztecSlotDuration is ${config.aztecSlotDuration} but the rollup reports ${rollup.slotDuration}`);
1068
+ }
1069
+ if (config.aztecEpochDuration !== undefined && config.aztecEpochDuration !== rollup.epochDuration) {
1070
+ mismatches.push(
1071
+ `aztecEpochDuration is ${config.aztecEpochDuration} but the rollup reports ${rollup.epochDuration}`,
1072
+ );
1073
+ }
1074
+ if (mismatches.length > 0) {
1075
+ throw new Error(
1076
+ `The node's configured L1 timing does not match the rollup contract it is pointed at: ${mismatches.join('; ')}`,
1077
+ );
1078
+ }
591
1079
  }
592
1080
 
593
1081
  /**
@@ -598,6 +1086,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
598
1086
  return this.sequencer;
599
1087
  }
600
1088
 
1089
+ /** Test-only: returns the AutomineSequencer when wired via `useAutomineSequencer`. */
1090
+ public getAutomineSequencer(): AutomineSequencer | undefined {
1091
+ return this.automineSequencer;
1092
+ }
1093
+
601
1094
  /** Returns the prover node subsystem, if enabled. */
602
1095
  public getProverNode(): ProverNode | undefined {
603
1096
  return this.proverNode;
@@ -620,7 +1113,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
620
1113
  * @returns - The currently deployed L1 contract addresses.
621
1114
  */
622
1115
  public getL1ContractAddresses(): Promise<L1ContractAddresses> {
623
- return Promise.resolve(this.config.l1Contracts);
1116
+ return Promise.resolve(pickL1ContractAddresses(this.config));
624
1117
  }
625
1118
 
626
1119
  public getEncodedEnr(): Promise<string | undefined> {
@@ -640,14 +1133,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
640
1133
  }
641
1134
 
642
1135
  public async getNodeInfo(): Promise<NodeInfo> {
643
- const [nodeVersion, rollupVersion, chainId, enr, contractAddresses, protocolContractAddresses] = await Promise.all([
644
- this.getNodeVersion(),
645
- this.getVersion(),
646
- this.getChainId(),
647
- this.getEncodedEnr(),
648
- this.getL1ContractAddresses(),
649
- this.getProtocolContractAddresses(),
650
- ]);
1136
+ const [nodeVersion, rollupVersion, chainId, enr, contractAddresses, protocolContractAddresses, l1Constants] =
1137
+ await Promise.all([
1138
+ this.getNodeVersion(),
1139
+ this.getVersion(),
1140
+ this.getChainId(),
1141
+ this.getEncodedEnr(),
1142
+ this.getL1ContractAddresses(),
1143
+ this.getProtocolContractAddresses(),
1144
+ this.blockSource.getL1Constants(),
1145
+ ]);
1146
+
1147
+ // Gas limits a single tx may declare on this network, derived from network-wide constants only (the
1148
+ // timetable's blocks-per-checkpoint and the network-minimum per-block multipliers) — never this node's
1149
+ // local caps or configured multipliers, which can make the node stricter at block-building time but
1150
+ // cannot define what the network accepts for relay. Clients read txsLimits to set fallback gas limits.
1151
+ const maxTxGas = getNetworkTxGasLimits(this.config, l1Constants);
651
1152
 
652
1153
  const nodeInfo: NodeInfo = {
653
1154
  nodeVersion,
@@ -657,112 +1158,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
657
1158
  l1ContractAddresses: contractAddresses,
658
1159
  protocolContractAddresses: protocolContractAddresses,
659
1160
  realProofs: !!this.config.realProofs,
1161
+ txsLimits: { gas: { daGas: maxTxGas.daGas, l2Gas: maxTxGas.l2Gas } },
660
1162
  };
661
1163
 
662
1164
  return nodeInfo;
663
1165
  }
664
1166
 
665
- /**
666
- * Get a block specified by its block number, block hash, or 'latest'.
667
- * @param block - The block parameter (block number, block hash, or 'latest').
668
- * @returns The requested block.
669
- */
670
- public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
671
- if (BlockHash.isBlockHash(block)) {
672
- return this.getBlockByHash(block);
673
- }
674
- const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
675
- if (blockNumber === BlockNumber.ZERO) {
676
- return this.buildInitialBlock();
677
- }
678
- return await this.blockSource.getL2Block(blockNumber);
679
- }
680
-
681
- /**
682
- * Get a block specified by its hash.
683
- * @param blockHash - The block hash being requested.
684
- * @returns The requested block.
685
- */
686
- public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
687
- const initialBlockHash = await this.#getInitialHeaderHash();
688
- if (blockHash.equals(initialBlockHash)) {
689
- return this.buildInitialBlock();
690
- }
691
- return await this.blockSource.getL2BlockByHash(blockHash);
692
- }
693
-
694
- private buildInitialBlock(): L2Block {
695
- const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
696
- return L2Block.empty(initialHeader);
697
- }
698
-
699
- /**
700
- * Get a block specified by its archive root.
701
- * @param archive - The archive root being requested.
702
- * @returns The requested block.
703
- */
704
- public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
705
- return await this.blockSource.getL2BlockByArchive(archive);
706
- }
707
-
708
- /**
709
- * Method to request blocks. Will attempt to return all requested blocks but will return only those available.
710
- * @param from - The start of the range of blocks to return.
711
- * @param limit - The maximum number of blocks to obtain.
712
- * @returns The blocks requested.
713
- */
714
- public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
715
- return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
716
- }
717
-
718
- public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
719
- return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
720
- }
721
-
722
- public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
723
- return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
724
- }
725
-
726
- public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
727
- return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
1167
+ public async getCurrentMinFees(): Promise<GasFees> {
1168
+ return await this.feeProvider.getCurrentMinFees();
728
1169
  }
729
1170
 
730
- /**
731
- * Method to fetch the current min L2 fees.
732
- * @returns The current min L2 fees.
733
- */
734
- public async getCurrentMinFees(): Promise<GasFees> {
735
- return await this.globalVariableBuilder.getCurrentMinFees();
1171
+ /** Returns predicted min fees for the current slot and next N slots. */
1172
+ public async getPredictedMinFees(manaUsage?: ManaUsageEstimate): Promise<GasFees[]> {
1173
+ return await this.feeProvider.getPredictedMinFees(manaUsage);
736
1174
  }
737
1175
 
738
1176
  public async getMaxPriorityFees(): Promise<GasFees> {
739
- for await (const tx of this.p2pClient.iteratePendingTxs()) {
1177
+ for await (const tx of this.p2pClient.iteratePendingTxs({ includeProof: false })) {
740
1178
  return tx.getGasSettings().maxPriorityFeesPerGas;
741
1179
  }
742
1180
 
743
1181
  return GasFees.from({ feePerDaGas: 0n, feePerL2Gas: 0n });
744
1182
  }
745
1183
 
746
- /**
747
- * Method to fetch the latest block number synchronized by the node.
748
- * @returns The block number.
749
- */
750
- public async getBlockNumber(): Promise<BlockNumber> {
751
- return await this.blockSource.getBlockNumber();
752
- }
753
-
754
- public async getProvenBlockNumber(): Promise<BlockNumber> {
755
- return await this.blockSource.getProvenBlockNumber();
756
- }
757
-
758
- public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
759
- return await this.blockSource.getCheckpointedL2BlockNumber();
760
- }
761
-
762
- public getCheckpointNumber(): Promise<CheckpointNumber> {
763
- return this.blockSource.getCheckpointNumber();
764
- }
765
-
766
1184
  /**
767
1185
  * Method to fetch the version of the package.
768
1186
  * @returns The node package version
@@ -795,69 +1213,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
795
1213
  return this.contractDataSource.getContract(address);
796
1214
  }
797
1215
 
798
- public async getPrivateLogsByTags(
799
- tags: SiloedTag[],
800
- page?: number,
801
- referenceBlock?: BlockHash,
802
- ): Promise<TxScopedL2Log[][]> {
803
- let upToBlockNumber: BlockNumber | undefined;
804
- if (referenceBlock) {
805
- const initialBlockHash = await this.#getInitialHeaderHash();
806
- if (referenceBlock.equals(initialBlockHash)) {
807
- upToBlockNumber = BlockNumber(0);
808
- } else {
809
- const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
810
- if (!header) {
811
- throw new Error(
812
- `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
813
- );
814
- }
815
- upToBlockNumber = header.globalVariables.blockNumber;
816
- }
817
- }
818
- return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
819
- }
820
-
821
- public async getPublicLogsByTagsFromContract(
822
- contractAddress: AztecAddress,
823
- tags: Tag[],
824
- page?: number,
825
- referenceBlock?: BlockHash,
826
- ): Promise<TxScopedL2Log[][]> {
827
- let upToBlockNumber: BlockNumber | undefined;
828
- if (referenceBlock) {
829
- const initialBlockHash = await this.#getInitialHeaderHash();
830
- if (referenceBlock.equals(initialBlockHash)) {
831
- upToBlockNumber = BlockNumber(0);
832
- } else {
833
- const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
834
- if (!header) {
835
- throw new Error(
836
- `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
837
- );
838
- }
839
- upToBlockNumber = header.globalVariables.blockNumber;
840
- }
841
- }
842
- return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
843
- }
844
-
845
- /**
846
- * Gets public logs based on the provided filter.
847
- * @param filter - The filter to apply to the logs.
848
- * @returns The requested logs.
849
- */
850
- getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
851
- return this.logsSource.getPublicLogs(filter);
1216
+ public getPrivateLogsByTags(query: PrivateLogsQuery): Promise<LogResult[][]> {
1217
+ return this.logsSource.getPrivateLogsByTags(query);
852
1218
  }
853
1219
 
854
- /**
855
- * Gets contract class logs based on the provided filter.
856
- * @param filter - The filter to apply to the logs.
857
- * @returns The requested logs.
858
- */
859
- getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse> {
860
- return this.logsSource.getContractClassLogs(filter);
1220
+ public getPublicLogsByTags(query: PublicLogsQuery): Promise<LogResult[][]> {
1221
+ return this.logsSource.getPublicLogsByTags(query);
861
1222
  }
862
1223
 
863
1224
  /**
@@ -880,32 +1241,47 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
880
1241
  throw new Error(`Invalid tx: ${reason}`);
881
1242
  }
882
1243
 
883
- await this.p2pClient!.sendTx(tx);
1244
+ try {
1245
+ await this.p2pClient!.sendTx(tx);
1246
+ } catch (err) {
1247
+ this.metrics.receivedTx(timer.ms(), false);
1248
+ this.log.warn(`Mempool rejected tx ${txHash}: ${(err as Error).message}`, { txHash });
1249
+ throw err;
1250
+ }
884
1251
  const duration = timer.ms();
885
1252
  this.metrics.receivedTx(duration, true);
886
1253
  this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
887
1254
  }
888
1255
 
889
- public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
1256
+ public async getTxReceipt<TGetTxReceiptOptions extends GetTxReceiptOptions = {}>(
1257
+ txHash: TxHash,
1258
+ options?: TGetTxReceiptOptions,
1259
+ ): Promise<TxReceipt<TGetTxReceiptOptions>> {
890
1260
  // Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
891
- // as a fallback if we don't find a settled receipt in the archiver.
1261
+ // as a fallback if we don't find a mined tx effect in the archiver.
892
1262
  const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
893
1263
  const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
894
1264
 
895
- // Then get the actual tx from the archiver, which tracks every tx in a mined block.
896
- const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
1265
+ // Then get the raw tx effect from the archiver, which tracks every tx in a mined block.
1266
+ const indexed = await this.blockSource.getTxEffect(txHash);
897
1267
 
898
1268
  let receipt: TxReceipt;
899
- if (settledTxReceipt) {
900
- receipt = settledTxReceipt;
1269
+ if (indexed) {
1270
+ receipt = await this.#assembleMinedReceipt(indexed, options);
901
1271
  } else if (isKnownToPool) {
902
1272
  // If the tx is in the pool but not in the archiver, it's pending.
903
1273
  // This handles race conditions between archiver and p2p, where the archiver
904
1274
  // has pruned the block in which a tx was mined, but p2p has not caught up yet.
905
- receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
1275
+ let tx: Tx | undefined;
1276
+ if (options?.includePendingTx) {
1277
+ // The tx may have left the pool since we checked its status (mined or dropped); in that case we
1278
+ // leave `tx` unset and still return a pending receipt.
1279
+ tx = await this.p2pClient.getTxByHashFromPool(txHash, { includeProof: !!options.includeProof });
1280
+ }
1281
+ receipt = new PendingTxReceipt(txHash, tx);
906
1282
  } else {
907
1283
  // Otherwise, if we don't know the tx, we consider it dropped.
908
- receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
1284
+ receipt = new DroppedTxReceipt(txHash, 'Tx dropped by P2P node');
909
1285
  }
910
1286
 
911
1287
  this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
@@ -913,6 +1289,44 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
913
1289
  return receipt;
914
1290
  }
915
1291
 
1292
+ /**
1293
+ * Assembles a {@link MinedTxReceipt} from a raw {@link IndexedTxEffect}, deriving the finalization status from the
1294
+ * cached L2 tips and the epoch from the block's slot number.
1295
+ */
1296
+ async #assembleMinedReceipt(indexed: IndexedTxEffect, options?: GetTxReceiptOptions): Promise<MinedTxReceipt> {
1297
+ const blockNumber = indexed.l2BlockNumber;
1298
+ const [tips, l1Constants] = await Promise.all([this.blockSource.getL2Tips(), this.blockSource.getL1Constants()]);
1299
+
1300
+ const status = this.#deriveMinedStatus(blockNumber, tips);
1301
+ const epochNumber = getEpochAtSlot(indexed.slotNumber, l1Constants);
1302
+
1303
+ return new MinedTxReceipt(
1304
+ indexed.data.txHash,
1305
+ status,
1306
+ MinedTxReceipt.executionResultFromRevertCode(indexed.data.revertCode),
1307
+ indexed.data.transactionFee.toBigInt(),
1308
+ indexed.l2BlockHash,
1309
+ blockNumber,
1310
+ indexed.slotNumber,
1311
+ indexed.txIndexInBlock,
1312
+ epochNumber,
1313
+ options?.includeTxEffect ? indexed.data : undefined,
1314
+ /*debugLogs=*/ undefined,
1315
+ );
1316
+ }
1317
+
1318
+ #deriveMinedStatus(blockNumber: BlockNumber, tips: L2Tips): MinedTxStatus {
1319
+ if (blockNumber <= tips.finalized.block.number) {
1320
+ return TxStatus.FINALIZED;
1321
+ } else if (blockNumber <= tips.proven.block.number) {
1322
+ return TxStatus.PROVEN;
1323
+ } else if (blockNumber <= tips.checkpointed.block.number) {
1324
+ return TxStatus.CHECKPOINTED;
1325
+ } else {
1326
+ return TxStatus.PROPOSED;
1327
+ }
1328
+ }
1329
+
916
1330
  public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
917
1331
  return this.blockSource.getTxEffect(txHash);
918
1332
  }
@@ -922,11 +1336,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
922
1336
  */
923
1337
  public async stop() {
924
1338
  this.log.info(`Stopping Aztec Node`);
925
- await tryStop(this.validatorsSentinel);
926
- await tryStop(this.epochPruneWatcher);
1339
+ await this.stopStartedWatchers();
927
1340
  await tryStop(this.slasherClient);
928
- await tryStop(this.proofVerifier);
1341
+ await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
929
1342
  await tryStop(this.sequencer);
1343
+ await tryStop(this.automineSequencer);
930
1344
  await tryStop(this.proverNode);
931
1345
  await tryStop(this.p2pClient);
932
1346
  await tryStop(this.worldStateSynchronizer);
@@ -950,30 +1364,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
950
1364
  * @param after - The last known pending tx. Used for pagination
951
1365
  * @returns - The pending txs.
952
1366
  */
953
- public getPendingTxs(limit?: number, after?: TxHash): Promise<Tx[]> {
954
- return this.p2pClient!.getPendingTxs(limit, after);
1367
+ public getPendingTxs(limit?: number, after?: TxHash, options?: GetTxByHashOptions): Promise<Tx[]> {
1368
+ return this.p2pClient!.getPendingTxs(limit, after, options);
955
1369
  }
956
1370
 
957
1371
  public getPendingTxCount(): Promise<number> {
958
1372
  return this.p2pClient!.getPendingTxCount();
959
1373
  }
960
1374
 
1375
+ public getPeers(includePending?: boolean): Promise<PeerInfo[]> {
1376
+ return this.p2pClient!.getPeers(includePending);
1377
+ }
1378
+
1379
+ public getCheckpointAttestationsForSlot(
1380
+ slot: SlotNumber,
1381
+ proposalPayloadHash?: CheckpointProposalHash,
1382
+ ): Promise<CheckpointAttestation[]> {
1383
+ return this.p2pClient!.getCheckpointAttestationsForSlot(slot, proposalPayloadHash);
1384
+ }
1385
+
1386
+ public getProposalsForSlot(slot: SlotNumber): Promise<ProposalsForSlot> {
1387
+ return this.p2pClient!.getProposalsForSlot(slot);
1388
+ }
1389
+
961
1390
  /**
962
- * Method to retrieve a single tx from the mempool or unfinalized chain.
1391
+ * Method to retrieve a single tx from the mempool or unfinalized chain. The tx's proof is only loaded and returned
1392
+ * when `includeProof` is set.
963
1393
  * @param txHash - The transaction hash to return.
1394
+ * @param options - Options for the returned tx (eg whether to include its proof).
964
1395
  * @returns - The tx if it exists.
965
1396
  */
966
- public getTxByHash(txHash: TxHash): Promise<Tx | undefined> {
967
- return Promise.resolve(this.p2pClient!.getTxByHashFromPool(txHash));
1397
+ public getTxByHash(txHash: TxHash, options?: GetTxByHashOptions): Promise<Tx | undefined> {
1398
+ return this.p2pClient!.getTxByHashFromPool(txHash, { includeProof: !!options?.includeProof });
968
1399
  }
969
1400
 
970
1401
  /**
971
- * Method to retrieve txs from the mempool or unfinalized chain.
1402
+ * Method to retrieve txs from the mempool or unfinalized chain. The txs' proofs are only loaded and returned when
1403
+ * `includeProof` is set.
972
1404
  * @param txHash - The transaction hash to return.
1405
+ * @param options - Options for the returned txs (eg whether to include their proofs).
973
1406
  * @returns - The txs if it exists.
974
1407
  */
975
- public async getTxsByHash(txHashes: TxHash[]): Promise<Tx[]> {
976
- return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
1408
+ public async getTxsByHash(txHashes: TxHash[], options?: GetTxByHashOptions): Promise<Tx[]> {
1409
+ const txs = await this.p2pClient!.getTxsByHashFromPool(txHashes, { includeProof: !!options?.includeProof });
1410
+ return compactArray(txs);
977
1411
  }
978
1412
 
979
1413
  public async findLeavesIndexes(
@@ -1015,7 +1449,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1015
1449
  );
1016
1450
 
1017
1451
  // Build a map from block number to block hash
1018
- const blockNumberToHash = new Map<BlockNumber, Fr>();
1452
+ const blockNumberToHash = new Map<BlockNumber, BlockHash>();
1019
1453
  for (let i = 0; i < uniqueBlockNumbers.length; i++) {
1020
1454
  const blockHash = blockHashes[i];
1021
1455
  if (blockHash === undefined) {
@@ -1033,13 +1467,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1033
1467
  if (blockNumber === undefined) {
1034
1468
  throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
1035
1469
  }
1036
- const blockHash = blockNumberToHash.get(blockNumber);
1037
- if (blockHash === undefined) {
1470
+ const l2BlockHash = blockNumberToHash.get(blockNumber);
1471
+ if (l2BlockHash === undefined) {
1038
1472
  throw new Error(`Block hash not found for block number ${blockNumber}`);
1039
1473
  }
1040
1474
  return {
1041
1475
  l2BlockNumber: blockNumber,
1042
- l2BlockHash: new BlockHash(blockHash),
1476
+ l2BlockHash,
1043
1477
  data: index,
1044
1478
  };
1045
1479
  });
@@ -1053,6 +1487,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1053
1487
  // which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
1054
1488
  // So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
1055
1489
  const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
1490
+ if (referenceBlockNumber === BlockNumber.ZERO) {
1491
+ // Block 0 (the initial block) has an empty archive, so no membership witness can exist.
1492
+ return undefined;
1493
+ }
1056
1494
  const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
1057
1495
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
1058
1496
  return pathAndIndex === undefined
@@ -1090,35 +1528,37 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1090
1528
 
1091
1529
  public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
1092
1530
  const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
1093
- return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
1094
- }
1095
-
1096
- /**
1097
- * Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
1098
- * @param l1ToL2Message - The L1 to L2 message to check.
1099
- * @returns Whether the message is synced and ready to be included in a block.
1100
- */
1101
- public async isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean> {
1102
- const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
1103
- return messageIndex !== undefined;
1531
+ return messageIndex !== undefined ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
1104
1532
  }
1105
1533
 
1106
1534
  /**
1107
1535
  * Returns all the L2 to L1 messages in an epoch.
1536
+ *
1537
+ * @deprecated Use {@link getL2ToL1MembershipWitness} to get an L2-to-L1 message witness directly.
1538
+ *
1108
1539
  * @param epoch - The epoch at which to get the data.
1109
1540
  * @returns The L2 to L1 messages (empty array if the epoch is not found).
1110
1541
  */
1111
1542
  public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
1112
- // Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
1113
- const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
1114
- const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
1115
- group => group.map(cb => cb.block),
1116
- );
1117
- return blocksInCheckpoints.map(blocks =>
1118
- blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
1543
+ const blocks = await this.blockSource.getBlocks({ epoch, onlyCheckpointed: true });
1544
+ const blocksInCheckpoints = chunkBy(blocks, block => block.header.globalVariables.slotNumber);
1545
+ return blocksInCheckpoints.map(slotBlocks =>
1546
+ slotBlocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
1119
1547
  );
1120
1548
  }
1121
1549
 
1550
+ /**
1551
+ * Returns the L2-to-L1 membership witness for a message in `txHash`. Passthrough to the
1552
+ * archiver's locally-cached resolver — see {@link Archiver.getL2ToL1MembershipWitness}.
1553
+ */
1554
+ public getL2ToL1MembershipWitness(
1555
+ txHash: TxHash,
1556
+ message: Fr,
1557
+ messageIndexInTx?: number,
1558
+ ): Promise<L2ToL1MembershipWitness | undefined> {
1559
+ return this.blockSource.getL2ToL1MembershipWitness(txHash, message, messageIndexInTx);
1560
+ }
1561
+
1122
1562
  public async getNullifierMembershipWitness(
1123
1563
  referenceBlock: BlockParameter,
1124
1564
  nullifier: Fr,
@@ -1189,49 +1629,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1189
1629
  return preimage.leaf.value;
1190
1630
  }
1191
1631
 
1192
- public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
1193
- if (BlockHash.isBlockHash(block)) {
1194
- const initialBlockHash = await this.#getInitialHeaderHash();
1195
- if (block.equals(initialBlockHash)) {
1196
- // Block source doesn't handle initial header so we need to handle the case separately.
1197
- return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1198
- }
1199
- return this.blockSource.getBlockHeaderByHash(block);
1200
- } else {
1201
- // Block source doesn't handle initial header so we need to handle the case separately.
1202
- const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
1203
- if (blockNumber === BlockNumber.ZERO) {
1204
- return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1205
- }
1206
- return this.blockSource.getBlockHeader(block);
1207
- }
1208
- }
1209
-
1210
- /**
1211
- * Get a block header specified by its archive root.
1212
- * @param archive - The archive root being requested.
1213
- * @returns The requested block header.
1214
- */
1215
- public async getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
1216
- return await this.blockSource.getBlockHeaderByArchive(archive);
1217
- }
1218
-
1219
- public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
1220
- return this.blockSource.getBlockData(number);
1221
- }
1222
-
1223
- public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
1224
- return this.blockSource.getBlockDataByArchive(archive);
1225
- }
1226
-
1227
1632
  /**
1228
1633
  * Simulates the public part of a transaction with the current state.
1229
1634
  * @param tx - The transaction to simulate.
1635
+ * @param skipFeeEnforcement - If true, fee enforcement is skipped.
1636
+ * @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
1230
1637
  **/
1231
1638
  @trackSpan('AztecNodeService.simulatePublicCalls', (tx: Tx) => ({
1232
1639
  [Attributes.TX_HASH]: tx.getTxHash().toString(),
1233
1640
  }))
1234
- public async simulatePublicCalls(tx: Tx, skipFeeEnforcement = false): Promise<PublicSimulationOutput> {
1641
+ public async simulatePublicCalls(
1642
+ tx: Tx,
1643
+ skipFeeEnforcement = false,
1644
+ overrides?: SimulationOverrides,
1645
+ ): Promise<PublicSimulationOutput> {
1235
1646
  // Check total gas limit for simulation
1236
1647
  const gasSettings = tx.data.constants.txContext.gasSettings;
1237
1648
  const txGasLimit = gasSettings.gasLimits.l2Gas;
@@ -1247,18 +1658,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1247
1658
  }
1248
1659
 
1249
1660
  const txHash = tx.getTxHash();
1250
- const latestBlockNumber = await this.blockSource.getBlockNumber();
1661
+ const l2Tips = await this.blockSource.getL2Tips();
1662
+ const latestBlockNumber = l2Tips.proposed.number;
1251
1663
  const blockNumber = BlockNumber.add(latestBlockNumber, 1);
1252
1664
 
1253
1665
  // If sequencer is not initialized, we just set these values to zero for simulation.
1254
1666
  const coinbase = EthAddress.ZERO;
1255
1667
  const feeRecipient = AztecAddress.ZERO;
1256
1668
 
1257
- const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(
1258
- blockNumber,
1669
+ // Define the slot for simulation as the max of the next L1 timestamp slot, the slot after the proposed
1670
+ // checkpoint, and the latest proposed block's slot.
1671
+ const proposedCheckpointBlockData = await this.blockSource.getBlockData({
1672
+ number: l2Tips.proposedCheckpoint.block.number,
1673
+ });
1674
+ const proposedCheckpointSlot = proposedCheckpointBlockData?.header.getSlot();
1675
+ let slotAfterProposedCheckpoint: SlotNumber | undefined;
1676
+ if (proposedCheckpointSlot !== undefined) {
1677
+ slotAfterProposedCheckpoint = SlotNumber.fromBigInt(BigInt(proposedCheckpointSlot) + 1n);
1678
+ }
1679
+
1680
+ let latestProposedBlockSlot: SlotNumber | undefined;
1681
+ if (l2Tips.proposed.number > l2Tips.proposedCheckpoint.block.number) {
1682
+ latestProposedBlockSlot = (
1683
+ await this.blockSource.getBlockData({ number: l2Tips.proposed.number })
1684
+ )?.header.getSlot();
1685
+ }
1686
+ const slotFromNextL1Timestamp = this.epochCache.getEpochAndSlotInNextL1Slot().slot;
1687
+ const targetSlot = SlotNumber(
1688
+ Math.max(...compactArray([slotFromNextL1Timestamp, slotAfterProposedCheckpoint, latestProposedBlockSlot])),
1689
+ );
1690
+
1691
+ const checkpointGlobalVariables = await this.globalVariableBuilder.buildCheckpointGlobalVariables(
1259
1692
  coinbase,
1260
1693
  feeRecipient,
1694
+ targetSlot,
1261
1695
  );
1696
+ const newGlobalVariables = GlobalVariables.from({ blockNumber, ...checkpointGlobalVariables });
1697
+
1262
1698
  const publicProcessorFactory = new PublicProcessorFactory(
1263
1699
  this.contractDataSource,
1264
1700
  new DateProvider(),
@@ -1274,40 +1710,77 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1274
1710
 
1275
1711
  // Ensure world-state has caught up with the latest block we loaded from the archiver
1276
1712
  await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
1277
- const merkleTreeFork = await this.worldStateSynchronizer.fork();
1278
- try {
1279
- const config = PublicSimulatorConfig.from({
1280
- skipFeeEnforcement,
1281
- collectDebugLogs: true,
1282
- collectHints: false,
1283
- collectCallMetadata: true,
1284
- collectStatistics: false,
1285
- collectionLimits: CollectionLimitsConfig.from({
1286
- maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
1287
- }),
1288
- });
1289
- const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
1290
-
1291
- // REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
1292
- const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
1293
- // REFACTOR: Consider returning the error rather than throwing
1294
- if (failedTxs.length) {
1295
- this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
1296
- throw failedTxs[0].error;
1297
- }
1298
1713
 
1299
- const [processedTx] = processedTxs;
1300
- return new PublicSimulationOutput(
1301
- processedTx.revertReason,
1302
- processedTx.globalVariables,
1303
- processedTx.txEffect,
1304
- returns,
1305
- processedTx.gasUsed,
1306
- debugLogs,
1714
+ // If we detect the next block would start a new checkpoint, then insert L1-to-L2 messages into
1715
+ // the world state tree so simulation can take them into account. We detect if the next block would
1716
+ // start a new checkpoint by checking if the proposed checkpoint's block number matches the latest block number,
1717
+ // which means the next block would be the first block of the next checkpoint.
1718
+ const targetCheckpoint = CheckpointNumber(
1719
+ (l2Tips.proposedCheckpoint.checkpoint.number ?? CheckpointNumber.ZERO) + 1,
1720
+ );
1721
+ const nextCheckpointMessages: Fr[] | undefined =
1722
+ l2Tips.proposedCheckpoint.block.number === l2Tips.proposed.number
1723
+ ? await this.l1ToL2MessageSource.getL1ToL2Messages(targetCheckpoint).catch(err => {
1724
+ if (isErrorClass(err, L1ToL2MessagesNotReadyError)) {
1725
+ this.log.warn(
1726
+ `L1-to-L2 messages for checkpoint ${targetCheckpoint} are not ready yet (simulating without them)`,
1727
+ );
1728
+ } else {
1729
+ this.log.error(
1730
+ `Failed to get L1-to-L2 messages for checkpoint ${targetCheckpoint} (simulating without them)`,
1731
+ err,
1732
+ );
1733
+ }
1734
+ return undefined;
1735
+ })
1736
+ : undefined;
1737
+
1738
+ // Request a new fork of the world state at the latest block number, and apply any overrides and next checkpoint messages to it before simulation
1739
+ await using merkleTreeFork = await this.worldStateSynchronizer.fork(latestBlockNumber);
1740
+
1741
+ if (nextCheckpointMessages !== undefined) {
1742
+ this.log.debug(
1743
+ `Appending ${nextCheckpointMessages.length} L1-to-L2 messages to the world state tree for the next checkpoint`,
1744
+ { checkpointNumber: l2Tips.proposedCheckpoint.checkpoint.number + 1 },
1307
1745
  );
1308
- } finally {
1309
- await merkleTreeFork.close();
1746
+ await appendL1ToL2MessagesToTree(merkleTreeFork, nextCheckpointMessages);
1747
+ }
1748
+ await applyPublicDataOverrides(merkleTreeFork, overrides?.publicStorage);
1749
+
1750
+ const config = PublicSimulatorConfig.from({
1751
+ skipFeeEnforcement,
1752
+ collectDebugLogs: true,
1753
+ collectHints: false,
1754
+ collectCallMetadata: true,
1755
+ collectStatistics: false,
1756
+ collectionLimits: CollectionLimitsConfig.from({
1757
+ maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
1758
+ }),
1759
+ });
1760
+
1761
+ const contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
1762
+ if (overrides?.contracts) {
1763
+ contractsDB.addContracts(Object.values(overrides.contracts).map(({ instance }) => instance));
1764
+ }
1765
+ const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config, contractsDB);
1766
+
1767
+ // REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
1768
+ const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
1769
+ // REFACTOR: Consider returning the error rather than throwing
1770
+ if (failedTxs.length) {
1771
+ this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
1772
+ throw failedTxs[0].error;
1310
1773
  }
1774
+
1775
+ const [processedTx] = processedTxs;
1776
+ return new PublicSimulationOutput(
1777
+ processedTx.revertReason,
1778
+ processedTx.globalVariables,
1779
+ processedTx.txEffect,
1780
+ returns,
1781
+ processedTx.gasUsed,
1782
+ debugLogs,
1783
+ );
1311
1784
  }
1312
1785
 
1313
1786
  public async isValidTx(
@@ -1315,12 +1788,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1315
1788
  { isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
1316
1789
  ): Promise<TxValidationResult> {
1317
1790
  const db = this.worldStateSynchronizer.getCommitted();
1318
- const verifier = isSimulation ? undefined : this.proofVerifier;
1791
+ const verifier = isSimulation ? undefined : this.rpcProofVerifier;
1319
1792
 
1320
1793
  // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1321
1794
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1322
1795
  const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1323
1796
  const l1Constants = await this.blockSource.getL1Constants();
1797
+ // Enforce the same network admission limit the node advertises in getNodeInfo (network-wide, not this
1798
+ // node's local caps), so a tx the wallet sized against txsLimits is not rejected here.
1799
+ const networkTxGasLimits = getNetworkTxGasLimits(this.config, l1Constants);
1324
1800
  const validator = createTxValidatorForAcceptingTxsOverRPC(
1325
1801
  db,
1326
1802
  this.contractDataSource,
@@ -1336,10 +1812,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1336
1812
  ],
1337
1813
  gasFees: await this.getCurrentMinFees(),
1338
1814
  skipFeeEnforcement,
1815
+ isSimulation,
1339
1816
  txsPermitted: !this.config.disableTransactions,
1340
- rollupManaLimit: l1Constants.rollupManaLimit,
1341
- maxBlockL2Gas: this.config.validateMaxL2BlockGas,
1342
- maxBlockDAGas: this.config.validateMaxDABlockGas,
1817
+ maxTxL2Gas: networkTxGasLimits.l2Gas,
1818
+ maxTxDAGas: networkTxGasLimits.daGas,
1343
1819
  },
1344
1820
  this.log.getBindings(),
1345
1821
  );
@@ -1355,7 +1831,18 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1355
1831
 
1356
1832
  public async setConfig(config: Partial<AztecNodeAdminConfig>): Promise<void> {
1357
1833
  const newConfig = { ...this.config, ...config };
1358
- this.sequencer?.updateConfig(config);
1834
+ // If the sequencer is currently paused via pauseSequencer(), record the caller's desired
1835
+ // minTxsPerBlock as the restore value (so resumeSequencer applies it) and keep the freeze
1836
+ // (MAX_SAFE_INTEGER) applied to the underlying sequencer. Without this guard, forwarding
1837
+ // the new minTxsPerBlock to the sequencer would silently unpause block production while
1838
+ // pauseSequencer() still considers it paused.
1839
+ const sequencerUpdate = { ...config };
1840
+ if (this.sequencerPausedMinTxsPerBlock !== undefined && sequencerUpdate.minTxsPerBlock !== undefined) {
1841
+ this.sequencerPausedMinTxsPerBlock = sequencerUpdate.minTxsPerBlock;
1842
+ delete sequencerUpdate.minTxsPerBlock;
1843
+ }
1844
+ this.sequencer?.updateConfig(sequencerUpdate);
1845
+ this.automineSequencer?.updateConfig(sequencerUpdate);
1359
1846
  this.slasherClient?.updateConfig(config);
1360
1847
  this.validatorsSentinel?.updateConfig(config);
1361
1848
  await this.p2pClient.updateP2PConfig(config);
@@ -1364,7 +1851,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1364
1851
  archiver.updateConfig(config);
1365
1852
  }
1366
1853
  if (newConfig.realProofs !== this.config.realProofs) {
1367
- this.proofVerifier = config.realProofs ? await BBCircuitVerifier.new(newConfig) : new TestCircuitVerifier();
1854
+ await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
1855
+ if (newConfig.realProofs) {
1856
+ this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
1857
+ const rpcVerifier = await BBCircuitVerifier.new(newConfig);
1858
+ this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
1859
+ } else {
1860
+ this.peerProofVerifier = new TestCircuitVerifier();
1861
+ this.rpcProofVerifier = new TestCircuitVerifier();
1862
+ }
1368
1863
  }
1369
1864
 
1370
1865
  this.config = newConfig;
@@ -1375,7 +1870,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1375
1870
  classRegistry: ProtocolContractAddress.ContractClassRegistry,
1376
1871
  feeJuice: ProtocolContractAddress.FeeJuice,
1377
1872
  instanceRegistry: ProtocolContractAddress.ContractInstanceRegistry,
1378
- multiCallEntrypoint: ProtocolContractAddress.MultiCallEntrypoint,
1873
+ multiCallEntrypoint: STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS,
1379
1874
  });
1380
1875
  }
1381
1876
 
@@ -1439,7 +1934,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1439
1934
  return Promise.resolve();
1440
1935
  }
1441
1936
 
1442
- public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
1937
+ public async rollbackTo(targetBlock: BlockNumber, force?: boolean, resumeSync = true): Promise<void> {
1443
1938
  const archiver = this.blockSource as Archiver;
1444
1939
  if (!('rollbackTo' in archiver)) {
1445
1940
  throw new Error('Archiver implementation does not support rollbacks.');
@@ -1469,9 +1964,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1469
1964
  this.log.error(`Error during rollback`, err);
1470
1965
  throw err;
1471
1966
  } finally {
1472
- this.log.info(`Resuming world state and archiver sync.`);
1473
- this.worldStateSynchronizer.resumeSync();
1474
- archiver.resume();
1967
+ if (resumeSync) {
1968
+ this.log.info(`Resuming world state and archiver sync.`);
1969
+ this.worldStateSynchronizer.resumeSync();
1970
+ archiver.resume();
1971
+ } else {
1972
+ this.log.info(`Sync left paused after rollback (resumeSync=false).`);
1973
+ }
1475
1974
  }
1476
1975
  }
1477
1976
 
@@ -1488,11 +1987,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1488
1987
  return Promise.resolve();
1489
1988
  }
1490
1989
 
1491
- public getSlashPayloads(): Promise<SlashPayloadRound[]> {
1492
- if (!this.slasherClient) {
1493
- throw new Error(`Slasher client not enabled`);
1990
+ public pauseSequencer(): Promise<void> {
1991
+ if (this.automineSequencer) {
1992
+ this.automineSequencer.pause();
1993
+ return Promise.resolve();
1494
1994
  }
1495
- return this.slasherClient.getSlashPayloads();
1995
+ if (this.sequencer) {
1996
+ if (this.sequencerPausedMinTxsPerBlock === undefined) {
1997
+ this.sequencerPausedMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock ?? 0;
1998
+ this.sequencer.updateConfig({ minTxsPerBlock: Number.MAX_SAFE_INTEGER });
1999
+ this.log.info(`Sequencer paused (minTxsPerBlock set to MAX_SAFE_INTEGER)`, {
2000
+ previousMinTxsPerBlock: this.sequencerPausedMinTxsPerBlock,
2001
+ });
2002
+ }
2003
+ return Promise.resolve();
2004
+ }
2005
+ throw new BadRequestError('Cannot pause sequencer: no sequencer is running');
2006
+ }
2007
+
2008
+ public resumeSequencer(): Promise<void> {
2009
+ if (this.automineSequencer) {
2010
+ this.automineSequencer.resume();
2011
+ return Promise.resolve();
2012
+ }
2013
+ if (this.sequencer) {
2014
+ if (this.sequencerPausedMinTxsPerBlock !== undefined) {
2015
+ const restored = this.sequencerPausedMinTxsPerBlock;
2016
+ this.sequencerPausedMinTxsPerBlock = undefined;
2017
+ this.sequencer.updateConfig({ minTxsPerBlock: restored });
2018
+ this.log.info(`Sequencer resumed (minTxsPerBlock restored)`, { minTxsPerBlock: restored });
2019
+ }
2020
+ return Promise.resolve();
2021
+ }
2022
+ throw new BadRequestError('Cannot resume sequencer: no sequencer is running');
1496
2023
  }
1497
2024
 
1498
2025
  public getSlashOffenses(round: bigint | 'all' | 'current'): Promise<Offense[]> {
@@ -1500,7 +2027,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1500
2027
  throw new Error(`Slasher client not enabled`);
1501
2028
  }
1502
2029
  if (round === 'all') {
1503
- return this.slasherClient.getPendingOffenses();
2030
+ return this.slasherClient.getOffenses();
1504
2031
  } else {
1505
2032
  return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
1506
2033
  }
@@ -1594,11 +2121,49 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1594
2121
  this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
1595
2122
  }
1596
2123
 
1597
- #getInitialHeaderHash(): Promise<BlockHash> {
1598
- if (!this.initialHeaderHashPromise) {
1599
- this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
2124
+ public async mineBlock(): Promise<void> {
2125
+ if (this.automineSequencer) {
2126
+ await this.automineSequencer.buildEmptyBlock();
2127
+ return;
2128
+ }
2129
+ if (!this.sequencer) {
2130
+ throw new BadRequestError('Cannot mine block: no sequencer is running');
2131
+ }
2132
+
2133
+ const currentBlockNumber = await this.getBlockNumber();
2134
+
2135
+ // Use slot duration + 50% buffer as the timeout so this works on running networks too
2136
+ const { slotDuration } = await this.blockSource.getL1Constants();
2137
+ const timeoutSeconds = Math.ceil(slotDuration * 1.5);
2138
+
2139
+ // Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
2140
+ const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
2141
+ this.sequencer.updateConfig({ minTxsPerBlock: 0 });
2142
+
2143
+ try {
2144
+ // Trigger the sequencer to produce a block immediately
2145
+ void this.sequencer.trigger();
2146
+
2147
+ // Wait for the new L2 block to appear
2148
+ await retryUntil(
2149
+ async () => {
2150
+ const newBlockNumber = await this.getBlockNumber();
2151
+ return newBlockNumber > currentBlockNumber ? true : undefined;
2152
+ },
2153
+ 'mineBlock',
2154
+ timeoutSeconds,
2155
+ 0.1,
2156
+ );
2157
+ } finally {
2158
+ this.sequencer.updateConfig({ minTxsPerBlock: originalMinTxsPerBlock });
2159
+ }
2160
+ }
2161
+
2162
+ public async prove(upToCheckpoint?: CheckpointNumber): Promise<CheckpointNumber> {
2163
+ if (!this.automineSequencer) {
2164
+ throw new BadRequestError('Cannot prove checkpoint: no automine sequencer is running');
1600
2165
  }
1601
- return this.initialHeaderHashPromise;
2166
+ return await this.automineSequencer.prove(upToCheckpoint);
1602
2167
  }
1603
2168
 
1604
2169
  /**
@@ -1607,54 +2172,52 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1607
2172
  * @returns An instance of a committed MerkleTreeOperations
1608
2173
  */
1609
2174
  protected async getWorldState(block: BlockParameter) {
2175
+ const query = this.normalizeBlockParameter(block);
2176
+
2177
+ // When the request anchors on a specific block hash, resolve it against the archiver up front and
2178
+ // drive the world-state sync to that exact block number and hash. Resolving against the archiver
2179
+ // first fails fast with a clear reorg error if the hash is unknown, and passing the hash to the
2180
+ // synchronizer makes the sync reorg-aware: it barriers until the archive-tree commit for that block
2181
+ // has landed and verifies it matches the requested fork, instead of syncing to bare latest height
2182
+ // and then racing the snapshot read below against an in-flight archive-tree write.
2183
+ const requestedHash = 'hash' in query ? query.hash : undefined;
2184
+ const anchorBlockNumber = requestedHash !== undefined ? await this.resolveBlockNumber(query) : undefined;
2185
+
1610
2186
  let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
1611
2187
  try {
1612
2188
  // Attempt to sync the world state if necessary
1613
- blockSyncedTo = await this.#syncWorldState();
2189
+ blockSyncedTo = await this.#syncWorldState(anchorBlockNumber, requestedHash);
1614
2190
  } catch (err) {
1615
2191
  this.log.error(`Error getting world state: ${err}`);
1616
2192
  }
1617
2193
 
1618
- if (block === 'latest') {
1619
- this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
2194
+ if ('tag' in query && query.tag === 'proposed') {
2195
+ this.log.debug(`Using committed db for latest block, world state synced upto ${blockSyncedTo}`);
1620
2196
  return this.worldStateSynchronizer.getCommitted();
1621
2197
  }
1622
2198
 
1623
- // Get the block number, either directly from the parameter or by quering the archiver with the block hash
1624
- let blockNumber: BlockNumber;
1625
- if (BlockHash.isBlockHash(block)) {
1626
- const initialBlockHash = await this.#getInitialHeaderHash();
1627
- if (block.equals(initialBlockHash)) {
1628
- // Block source doesn't handle initial header so we need to handle the case separately.
1629
- return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
1630
- }
1631
-
1632
- const header = await this.blockSource.getBlockHeaderByHash(block);
1633
- if (!header) {
1634
- throw new Error(
1635
- `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.`,
1636
- );
1637
- }
1638
-
1639
- blockNumber = header.getBlockNumber();
1640
- } else {
1641
- blockNumber = block as BlockNumber;
1642
- }
2199
+ const blockNumber = anchorBlockNumber ?? (await this.resolveBlockNumber(query));
1643
2200
 
1644
2201
  // Check it's within world state sync range
1645
2202
  if (blockNumber > blockSyncedTo) {
1646
- throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
2203
+ throw new Error(
2204
+ `Queried block ${inspectBlockParameter(block)} not yet synced by the node (node is synced upto ${blockSyncedTo}).`,
2205
+ );
1647
2206
  }
1648
2207
  this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1649
2208
 
1650
2209
  const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
1651
2210
 
1652
- // Double-check world-state synced to the same block hash as was requested
1653
- if (BlockHash.isBlockHash(block)) {
2211
+ // Double-check world-state synced to the same block hash as was requested.
2212
+ // Block 0 is skipped: the snapshot returned by `getSnapshot(0)` is the *pre*-genesis archive
2213
+ // (size 0), so leaf 0 is not yet inserted from that snapshot's view even though block 0's hash
2214
+ // does live at archive index 0 in the committed tree. The genesis hash is already validated by
2215
+ // the archiver when it resolves the hash query to block number 0.
2216
+ if (requestedHash !== undefined && blockNumber !== BlockNumber.ZERO) {
1654
2217
  const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
1655
- if (!blockHash || !new BlockHash(blockHash).equals(block)) {
2218
+ if (!blockHash || !requestedHash.equals(blockHash)) {
1656
2219
  throw new Error(
1657
- `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.`,
2220
+ `Block hash ${requestedHash.toString()} not found in world state at block number ${blockNumber} (world state has ${blockHash?.toString() ?? 'no hash'} at that index, genesis header hash is ${this.blockSource.getGenesisBlockHash().toString()}). If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
1658
2221
  );
1659
2222
  }
1660
2223
  }
@@ -1662,31 +2225,33 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1662
2225
  return snapshot;
1663
2226
  }
1664
2227
 
1665
- /** Resolves a block parameter to a block number. */
2228
+ /** Resolves any {@link BlockParameter} variant to a concrete block number. */
1666
2229
  protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
1667
- if (block === 'latest') {
1668
- return BlockNumber(await this.blockSource.getBlockNumber());
1669
- }
1670
- if (BlockHash.isBlockHash(block)) {
1671
- const initialBlockHash = await this.#getInitialHeaderHash();
1672
- if (block.equals(initialBlockHash)) {
1673
- return BlockNumber.ZERO;
2230
+ const query = this.normalizeBlockParameter(block);
2231
+ const blockNumber = await this.blockSource.getBlockNumber(query);
2232
+ if (blockNumber === undefined) {
2233
+ if ('hash' in query) {
2234
+ throw new Error(
2235
+ `Block hash ${query.hash.toString()} not found when querying world state. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
2236
+ );
1674
2237
  }
1675
- const header = await this.blockSource.getBlockHeaderByHash(block);
1676
- if (!header) {
1677
- throw new Error(`Block hash ${block.toString()} not found.`);
2238
+ if ('archive' in query) {
2239
+ throw new Error(`Block with archive ${query.archive.toString()} not found.`);
1678
2240
  }
1679
- return header.getBlockNumber();
2241
+ throw new Error(`Block not found for ${inspectBlockParameter(block)}.`);
1680
2242
  }
1681
- return block as BlockNumber;
2243
+ return blockNumber;
1682
2244
  }
1683
2245
 
1684
2246
  /**
1685
- * Ensure we fully sync the world state
2247
+ * Ensure the world state is synced.
2248
+ * @param targetBlockNumber - Block to sync up to. Defaults to the latest block known to the archiver.
2249
+ * @param blockHash - If provided, the synchronizer verifies the block at `targetBlockNumber` matches this
2250
+ * hash, resyncing (and so detecting reorgs) if it does not yet match or has been reorged away.
1686
2251
  * @returns A promise that fulfils once the world state is synced
1687
2252
  */
1688
- async #syncWorldState(): Promise<BlockNumber> {
1689
- const blockSourceHeight = await this.blockSource.getBlockNumber();
1690
- return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
2253
+ async #syncWorldState(targetBlockNumber?: BlockNumber, blockHash?: BlockHash): Promise<BlockNumber> {
2254
+ const target = targetBlockNumber ?? (await this.blockSource.getBlockNumber());
2255
+ return await this.worldStateSynchronizer.syncImmediate(target, blockHash);
1691
2256
  }
1692
2257
  }