@aztec/aztec-node 5.0.0-private.20260318 → 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 +94 -99
  14. package/dest/aztec-node/server.d.ts.map +1 -1
  15. package/dest/aztec-node/server.js +1082 -479
  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 +1203 -612
  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,27 +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
- import { createWorldStateSynchronizer } from '@aztec/world-state';
169
+ import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
170
+ import { createWorldState, createWorldStateSynchronizer } from '@aztec/world-state';
115
171
 
116
172
  import { createPublicClient } from 'viem';
117
173
 
118
174
  import { createSentinel } from '../sentinel/factory.js';
119
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';
120
183
  import { type AztecNodeConfig, createKeyStoreForValidator } from './config.js';
121
184
  import { NodeMetrics } from './node_metrics.js';
185
+ import { applyPublicDataOverrides } from './public_data_overrides.js';
122
186
 
123
187
  /**
124
188
  * The aztec node.
125
189
  */
126
- export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
190
+ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDebug, Traceable {
127
191
  private metrics: NodeMetrics;
128
- private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
129
-
130
192
  // Prevent two snapshot operations to happen simultaneously
131
193
  private isUploadingSnapshot = false;
194
+ // Saved minTxsPerBlock used by `pauseSequencer` to restore production-sequencer config on resume.
195
+ private sequencerPausedMinTxsPerBlock: number | undefined;
132
196
 
133
197
  public readonly tracer: Tracer;
134
198
 
@@ -144,25 +208,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
144
208
  protected readonly proverNode: ProverNode | undefined,
145
209
  protected readonly slasherClient: SlasherClientInterface | undefined,
146
210
  protected readonly validatorsSentinel: Sentinel | undefined,
147
- protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
211
+ private readonly stopStartedWatchers: () => Promise<void>,
148
212
  protected readonly l1ChainId: number,
149
213
  protected readonly version: number,
150
214
  protected readonly globalVariableBuilder: GlobalVariableBuilderInterface,
215
+ protected readonly feeProvider: FeeProvider,
151
216
  protected readonly epochCache: EpochCacheInterface,
152
217
  protected readonly packageVersion: string,
153
- private proofVerifier: ClientProtocolCircuitVerifier,
218
+ private peerProofVerifier: ClientProtocolCircuitVerifier,
219
+ private rpcProofVerifier: ClientProtocolCircuitVerifier,
154
220
  private telemetry: TelemetryClient = getTelemetryClient(),
155
221
  private log = createLogger('node'),
156
222
  private blobClient?: BlobClientInterface,
157
223
  private validatorClient?: ValidatorClient,
158
224
  private keyStoreManager?: KeystoreManager,
159
225
  private debugLogStore: DebugLogStore = new NullDebugLogStore(),
226
+ private readonly automineSequencer?: AutomineSequencer,
160
227
  ) {
161
228
  this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
162
229
  this.tracer = telemetry.getTracer('AztecNodeService');
163
230
 
164
231
  this.log.info(`Aztec Node version: ${this.packageVersion}`);
165
- 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));
166
233
 
167
234
  // A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
168
235
  // never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
@@ -172,13 +239,264 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
172
239
  }
173
240
  }
174
241
 
242
+ /** @internal Exposed for testing — returns the RPC proof verifier. */
243
+ public getProofVerifier(): ClientProtocolCircuitVerifier {
244
+ return this.rpcProofVerifier;
245
+ }
246
+
175
247
  public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
176
248
  const status = await this.worldStateSynchronizer.status();
177
249
  return status.syncSummary;
178
250
  }
179
251
 
180
- public getL2Tips() {
181
- 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>[];
182
500
  }
183
501
 
184
502
  /**
@@ -195,16 +513,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
195
513
  dateProvider?: DateProvider;
196
514
  p2pClientDeps?: P2PClientDeps;
197
515
  proverNodeDeps?: Partial<ProverNodeDeps>;
516
+ slashingProtectionDb?: SlashingProtectionDatabase;
198
517
  } = {},
199
518
  options: {
200
- prefilledPublicData?: PublicDataTreeLeaf[];
519
+ genesis?: GenesisData;
201
520
  dontStartSequencer?: boolean;
202
521
  dontStartProverNode?: boolean;
203
522
  } = {},
204
523
  ): Promise<AztecNodeService> {
205
524
  const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
206
525
  const log = deps.logger ?? createLogger('node');
207
- const packageVersion = getPackageVersion() ?? '';
526
+ const packageVersion = getPackageVersion();
208
527
  const telemetry = deps.telemetry ?? getTelemetryClient();
209
528
  const dateProvider = deps.dateProvider ?? new DateProvider();
210
529
  const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
@@ -263,17 +582,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
263
582
 
264
583
  const l1ContractsAddresses = await RegistryContract.collectAddresses(
265
584
  publicClient,
266
- config.l1Contracts.registryAddress,
585
+ config.registryAddress,
267
586
  config.rollupVersion ?? 'canonical',
268
587
  );
269
588
 
270
- // Overwrite the passed in vars.
271
- config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
589
+ Object.assign(config, l1ContractsAddresses);
272
590
 
273
- const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
274
- 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([
275
593
  rollupContract.getL1GenesisTime(),
276
594
  rollupContract.getSlotDuration(),
595
+ rollupContract.getEpochDuration(),
277
596
  rollupContract.getVersion(),
278
597
  rollupContract.getManaLimit().then(Number),
279
598
  ] as const);
@@ -291,300 +610,472 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
291
610
  // attempt snapshot sync if possible
292
611
  await trySnapshotSync(config, log);
293
612
 
294
- const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, { dateProvider });
613
+ const epochCache = await EpochCache.create(config.rollupAddress, config, { dateProvider });
295
614
 
296
- const archiver = await createArchiver(
297
- config,
298
- { blobClient, epochCache, telemetry, dateProvider },
299
- { blockUntilSync: !config.skipArchiverInitialSync },
300
- );
301
-
302
- // now create the merkle trees and the world state synchronizer
303
- const worldStateSynchronizer = await createWorldStateSynchronizer(
304
- config,
305
- archiver,
306
- options.prefilledPublicData,
307
- telemetry,
308
- );
309
- const circuitVerifier =
310
- config.realProofs || config.debugForceTxProofVerification
311
- ? await BBCircuitVerifier.new(config)
312
- : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
313
-
314
- let debugLogStore: DebugLogStore;
315
- if (!config.realProofs) {
316
- log.warn(`Aztec node is accepting fake proofs`);
317
-
318
- debugLogStore = new InMemoryDebugLogStore();
319
- log.info(
320
- 'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
321
- );
322
- } else {
323
- debugLogStore = new NullDebugLogStore();
324
- }
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;
325
619
 
326
- const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
620
+ AztecNodeService.checkConfigMatchesRollup(config, {
621
+ slotDuration: Number(slotDuration),
622
+ epochDuration: Number(epochDuration),
623
+ });
327
624
 
328
- const proverOnly = config.enableProverNode && config.disableValidator;
329
- if (proverOnly) {
330
- log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
331
- }
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);
332
653
 
333
- // create the tx pool and the p2p client, which will need the l2 block source
334
- const p2pClient = await createP2PClient(
335
- config,
336
- archiver,
337
- proofVerifier,
338
- worldStateSynchronizer,
339
- epochCache,
340
- packageVersion,
341
- dateProvider,
342
- telemetry,
343
- deps.p2pClientDeps,
344
- );
654
+ let debugLogStore: DebugLogStore;
655
+ if (!config.realProofs) {
656
+ log.warn(`Aztec node is accepting fake proofs`);
345
657
 
346
- // We'll accumulate sentinel watchers here
347
- 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
+ }
348
665
 
349
- // Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
350
- // Override maxTxsPerCheckpoint with the validator-specific limit if set.
351
- const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
352
- {
353
- ...config,
666
+ const globalVariableBuilderConfig = {
667
+ rollupAddress: config.rollupAddress,
668
+ ethereumSlotDuration: config.ethereumSlotDuration,
669
+ rollupVersion: BigInt(config.rollupVersion),
354
670
  l1GenesisTime,
355
671
  slotDuration: Number(slotDuration),
356
- rollupManaLimit,
357
- maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
358
- },
359
- worldStateSynchronizer,
360
- archiver,
361
- dateProvider,
362
- telemetry,
363
- );
672
+ };
364
673
 
365
- let validatorClient: ValidatorClient | undefined;
674
+ const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, globalVariableBuilderConfig);
675
+ const feeProvider = new FeeProviderImpl(dateProvider, publicClient, globalVariableBuilderConfig);
366
676
 
367
- if (!proverOnly) {
368
- // Create validator client if required
369
- validatorClient = await createValidatorClient(config, {
370
- checkpointsBuilder: validatorCheckpointsBuilder,
371
- worldState: worldStateSynchronizer,
372
- p2pClient,
373
- telemetry,
374
- dateProvider,
375
- epochCache,
376
- blockSource: archiver,
377
- l1ToL2MessageSource: archiver,
378
- keyStoreManager,
379
- blobClient,
380
- });
381
-
382
- // If we have a validator client, register it as a source of offenses for the slasher,
383
- // and have it register callbacks on the p2p client *before* we start it, otherwise messages
384
- // like attestations or auths will fail.
385
- if (validatorClient) {
386
- watchers.push(validatorClient);
387
- if (!options.dontStartSequencer) {
388
- await validatorClient.registerHandlers();
389
- }
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');
390
680
  }
391
- }
392
681
 
393
- // If there's no validator client, create a BlockProposalHandler to handle block proposals
394
- // for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
395
- // while non-reexecution is used for validating the proposals and collecting their txs.
396
- if (!validatorClient) {
397
- const reexecute = !!config.alwaysReexecuteBlockProposals;
398
- log.info(`Setting up block proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
399
- createBlockProposalHandler(config, {
400
- checkpointsBuilder: validatorCheckpointsBuilder,
401
- 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,
402
688
  epochCache,
403
- blockSource: archiver,
404
- l1ToL2MessageSource: archiver,
405
- p2pClient,
689
+ feeProvider,
690
+ packageVersion,
406
691
  dateProvider,
407
692
  telemetry,
408
- }).register(p2pClient, reexecute);
409
- }
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
+ );
410
717
 
411
- // Start world state and wait for it to sync to the archiver.
412
- await worldStateSynchronizer.start();
718
+ let validatorClient: ValidatorClient | undefined;
413
719
 
414
- // Start p2p. Note that it depends on world state to be running.
415
- await p2pClient.start();
720
+ // Tracks successful checkpoint re-execution by a checkpoint proposal handler.
721
+ const reexecutionTracker = new CheckpointReexecutionTracker();
416
722
 
417
- let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
418
- let epochPruneWatcher: EpochPruneWatcher | undefined;
419
- 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
+ }
420
755
 
421
- if (!proverOnly) {
422
- validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
423
- if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
424
- 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);
425
775
  }
426
776
 
427
- if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
428
- 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,
429
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,
430
809
  archiver,
431
810
  epochCache,
432
- p2pClient.getTxProvider(),
433
- validatorCheckpointsBuilder,
434
811
  config,
435
812
  );
436
- watchers.push(epochPruneWatcher);
437
- }
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
+ }
438
826
 
439
- // We assume we want to slash for invalid attestations unless all max penalties are set to 0
440
- if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
441
- 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());
442
831
  watchers.push(attestationsBlockWatcher);
443
832
  }
444
- }
445
833
 
446
- // Start p2p-related services once the archiver has completed sync
447
- void archiver
448
- .waitForInitialSync()
449
- .then(async () => {
450
- await p2pClient.start();
451
- await validatorsSentinel?.start();
452
- await epochPruneWatcher?.start();
453
- await attestationsBlockWatcher?.start();
454
- log.info(`All p2p services started`);
455
- })
456
- .catch(err => log.error('Failed to start p2p services after archiver sync', err));
457
-
458
- // Validator enabled, create/start relevant service
459
- let sequencer: SequencerClient | undefined;
460
- let slasherClient: SlasherClientInterface | undefined;
461
- if (!config.disableValidator && validatorClient) {
462
- // We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
463
- // as they are executed when the node is selected as proposer.
464
- const validatorAddresses = keyStoreManager
465
- ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses()
466
- : [];
467
-
468
- slasherClient = await createSlasher(
469
- config,
470
- config.l1Contracts,
471
- getPublicClient(config),
472
- watchers,
473
- dateProvider,
474
- epochCache,
475
- validatorAddresses,
476
- undefined, // logger
477
- );
478
- 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
+ };
479
848
 
480
- const l1TxUtils = config.sequencerPublisherForwarderAddress
481
- ? await createForwarderL1TxUtilsFromSigners(
482
- publicClient,
483
- keyStoreManager!.createAllValidatorPublisherSigners(),
484
- config.sequencerPublisherForwarderAddress,
485
- { ...config, scope: 'sequencer' },
486
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
487
- )
488
- : 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(
489
906
  publicClient,
490
- keyStoreManager!.createAllValidatorPublisherSigners(),
907
+ [fundingSigner],
491
908
  { ...config, scope: 'sequencer' },
492
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
909
+ { telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
493
910
  );
911
+ funderL1TxUtils = funder;
912
+ }
494
913
 
495
- // Create and start the sequencer client
496
- const checkpointsBuilder = new CheckpointsBuilder(
497
- { ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
498
- worldStateSynchronizer,
499
- archiver,
500
- dateProvider,
501
- telemetry,
502
- debugLogStore,
503
- );
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
+ );
504
923
 
505
- sequencer = await SequencerClient.new(config, {
506
- ...deps,
507
- epochCache,
508
- l1TxUtils,
509
- validatorClient,
510
- p2pClient,
511
- worldStateSynchronizer,
512
- slasherClient,
513
- checkpointsBuilder,
514
- l2BlockSource: archiver,
515
- l1ToL2MessageSource: archiver,
516
- telemetry,
517
- dateProvider,
518
- blobClient,
519
- nodeKeyStore: keyStoreManager!,
520
- });
521
- }
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
+ }
522
974
 
523
- if (!options.dontStartSequencer && sequencer) {
524
- await sequencer.start();
525
- log.verbose(`Sequencer started`);
526
- } else if (sequencer) {
527
- log.warn(`Sequencer created but not started`);
528
- }
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
+ }
529
982
 
530
- // Create prover node subsystem if enabled
531
- let proverNode: ProverNode | undefined;
532
- if (config.enableProverNode) {
533
- proverNode = await createProverNode(config, {
534
- ...deps.proverNodeDeps,
535
- telemetry,
536
- 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,
537
1021
  archiver,
538
1022
  worldStateSynchronizer,
539
- p2pClient,
1023
+ sequencer,
1024
+ proverNode,
1025
+ slasherClient,
1026
+ validatorsSentinel,
1027
+ stopStartedWatchers,
1028
+ ethereumChain.chainInfo.id,
1029
+ config.rollupVersion,
1030
+ globalVariableBuilder,
1031
+ feeProvider,
540
1032
  epochCache,
1033
+ packageVersion,
1034
+ peerProofVerifier,
1035
+ rpcProofVerifier,
1036
+ telemetry,
1037
+ log,
541
1038
  blobClient,
1039
+ validatorClient,
542
1040
  keyStoreManager,
543
- });
1041
+ debugLogStore,
1042
+ automineSequencer,
1043
+ );
544
1044
 
545
- if (!options.dontStartProverNode) {
546
- await proverNode.start();
547
- log.info(`Prover node subsystem started`);
548
- } else {
549
- 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);
550
1050
  }
1051
+ throw err;
551
1052
  }
1053
+ }
552
1054
 
553
- const globalVariableBuilder = new GlobalVariableBuilder({
554
- ...config,
555
- rollupVersion: BigInt(config.rollupVersion),
556
- l1GenesisTime,
557
- slotDuration: Number(slotDuration),
558
- });
559
-
560
- const node = new AztecNodeService(
561
- config,
562
- p2pClient,
563
- archiver,
564
- archiver,
565
- archiver,
566
- archiver,
567
- worldStateSynchronizer,
568
- sequencer,
569
- proverNode,
570
- slasherClient,
571
- validatorsSentinel,
572
- epochPruneWatcher,
573
- ethereumChain.chainInfo.id,
574
- config.rollupVersion,
575
- globalVariableBuilder,
576
- epochCache,
577
- packageVersion,
578
- proofVerifier,
579
- telemetry,
580
- log,
581
- blobClient,
582
- validatorClient,
583
- keyStoreManager,
584
- debugLogStore,
585
- );
586
-
587
- 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
+ }
588
1079
  }
589
1080
 
590
1081
  /**
@@ -595,6 +1086,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
595
1086
  return this.sequencer;
596
1087
  }
597
1088
 
1089
+ /** Test-only: returns the AutomineSequencer when wired via `useAutomineSequencer`. */
1090
+ public getAutomineSequencer(): AutomineSequencer | undefined {
1091
+ return this.automineSequencer;
1092
+ }
1093
+
598
1094
  /** Returns the prover node subsystem, if enabled. */
599
1095
  public getProverNode(): ProverNode | undefined {
600
1096
  return this.proverNode;
@@ -617,7 +1113,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
617
1113
  * @returns - The currently deployed L1 contract addresses.
618
1114
  */
619
1115
  public getL1ContractAddresses(): Promise<L1ContractAddresses> {
620
- return Promise.resolve(this.config.l1Contracts);
1116
+ return Promise.resolve(pickL1ContractAddresses(this.config));
621
1117
  }
622
1118
 
623
1119
  public getEncodedEnr(): Promise<string | undefined> {
@@ -637,14 +1133,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
637
1133
  }
638
1134
 
639
1135
  public async getNodeInfo(): Promise<NodeInfo> {
640
- const [nodeVersion, rollupVersion, chainId, enr, contractAddresses, protocolContractAddresses] = await Promise.all([
641
- this.getNodeVersion(),
642
- this.getVersion(),
643
- this.getChainId(),
644
- this.getEncodedEnr(),
645
- this.getL1ContractAddresses(),
646
- this.getProtocolContractAddresses(),
647
- ]);
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);
648
1152
 
649
1153
  const nodeInfo: NodeInfo = {
650
1154
  nodeVersion,
@@ -654,112 +1158,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
654
1158
  l1ContractAddresses: contractAddresses,
655
1159
  protocolContractAddresses: protocolContractAddresses,
656
1160
  realProofs: !!this.config.realProofs,
1161
+ txsLimits: { gas: { daGas: maxTxGas.daGas, l2Gas: maxTxGas.l2Gas } },
657
1162
  };
658
1163
 
659
1164
  return nodeInfo;
660
1165
  }
661
1166
 
662
- /**
663
- * Get a block specified by its block number, block hash, or 'latest'.
664
- * @param block - The block parameter (block number, block hash, or 'latest').
665
- * @returns The requested block.
666
- */
667
- public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
668
- if (BlockHash.isBlockHash(block)) {
669
- return this.getBlockByHash(block);
670
- }
671
- const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
672
- if (blockNumber === BlockNumber.ZERO) {
673
- return this.buildInitialBlock();
674
- }
675
- return await this.blockSource.getL2Block(blockNumber);
676
- }
677
-
678
- /**
679
- * Get a block specified by its hash.
680
- * @param blockHash - The block hash being requested.
681
- * @returns The requested block.
682
- */
683
- public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
684
- const initialBlockHash = await this.#getInitialHeaderHash();
685
- if (blockHash.equals(initialBlockHash)) {
686
- return this.buildInitialBlock();
687
- }
688
- return await this.blockSource.getL2BlockByHash(blockHash);
689
- }
690
-
691
- private buildInitialBlock(): L2Block {
692
- const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
693
- return L2Block.empty(initialHeader);
694
- }
695
-
696
- /**
697
- * Get a block specified by its archive root.
698
- * @param archive - The archive root being requested.
699
- * @returns The requested block.
700
- */
701
- public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
702
- return await this.blockSource.getL2BlockByArchive(archive);
703
- }
704
-
705
- /**
706
- * Method to request blocks. Will attempt to return all requested blocks but will return only those available.
707
- * @param from - The start of the range of blocks to return.
708
- * @param limit - The maximum number of blocks to obtain.
709
- * @returns The blocks requested.
710
- */
711
- public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
712
- return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
713
- }
714
-
715
- public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
716
- return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
717
- }
718
-
719
- public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
720
- return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
721
- }
722
-
723
- public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
724
- return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
1167
+ public async getCurrentMinFees(): Promise<GasFees> {
1168
+ return await this.feeProvider.getCurrentMinFees();
725
1169
  }
726
1170
 
727
- /**
728
- * Method to fetch the current min L2 fees.
729
- * @returns The current min L2 fees.
730
- */
731
- public async getCurrentMinFees(): Promise<GasFees> {
732
- 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);
733
1174
  }
734
1175
 
735
1176
  public async getMaxPriorityFees(): Promise<GasFees> {
736
- for await (const tx of this.p2pClient.iteratePendingTxs()) {
1177
+ for await (const tx of this.p2pClient.iteratePendingTxs({ includeProof: false })) {
737
1178
  return tx.getGasSettings().maxPriorityFeesPerGas;
738
1179
  }
739
1180
 
740
1181
  return GasFees.from({ feePerDaGas: 0n, feePerL2Gas: 0n });
741
1182
  }
742
1183
 
743
- /**
744
- * Method to fetch the latest block number synchronized by the node.
745
- * @returns The block number.
746
- */
747
- public async getBlockNumber(): Promise<BlockNumber> {
748
- return await this.blockSource.getBlockNumber();
749
- }
750
-
751
- public async getProvenBlockNumber(): Promise<BlockNumber> {
752
- return await this.blockSource.getProvenBlockNumber();
753
- }
754
-
755
- public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
756
- return await this.blockSource.getCheckpointedL2BlockNumber();
757
- }
758
-
759
- public getCheckpointNumber(): Promise<CheckpointNumber> {
760
- return this.blockSource.getCheckpointNumber();
761
- }
762
-
763
1184
  /**
764
1185
  * Method to fetch the version of the package.
765
1186
  * @returns The node package version
@@ -792,69 +1213,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
792
1213
  return this.contractDataSource.getContract(address);
793
1214
  }
794
1215
 
795
- public async getPrivateLogsByTags(
796
- tags: SiloedTag[],
797
- page?: number,
798
- referenceBlock?: BlockHash,
799
- ): Promise<TxScopedL2Log[][]> {
800
- let upToBlockNumber: BlockNumber | undefined;
801
- if (referenceBlock) {
802
- const initialBlockHash = await this.#getInitialHeaderHash();
803
- if (referenceBlock.equals(initialBlockHash)) {
804
- upToBlockNumber = BlockNumber(0);
805
- } else {
806
- const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
807
- if (!header) {
808
- throw new Error(
809
- `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
810
- );
811
- }
812
- upToBlockNumber = header.globalVariables.blockNumber;
813
- }
814
- }
815
- return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
816
- }
817
-
818
- public async getPublicLogsByTagsFromContract(
819
- contractAddress: AztecAddress,
820
- tags: Tag[],
821
- page?: number,
822
- referenceBlock?: BlockHash,
823
- ): Promise<TxScopedL2Log[][]> {
824
- let upToBlockNumber: BlockNumber | undefined;
825
- if (referenceBlock) {
826
- const initialBlockHash = await this.#getInitialHeaderHash();
827
- if (referenceBlock.equals(initialBlockHash)) {
828
- upToBlockNumber = BlockNumber(0);
829
- } else {
830
- const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
831
- if (!header) {
832
- throw new Error(
833
- `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
834
- );
835
- }
836
- upToBlockNumber = header.globalVariables.blockNumber;
837
- }
838
- }
839
- return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
840
- }
841
-
842
- /**
843
- * Gets public logs based on the provided filter.
844
- * @param filter - The filter to apply to the logs.
845
- * @returns The requested logs.
846
- */
847
- getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
848
- return this.logsSource.getPublicLogs(filter);
1216
+ public getPrivateLogsByTags(query: PrivateLogsQuery): Promise<LogResult[][]> {
1217
+ return this.logsSource.getPrivateLogsByTags(query);
849
1218
  }
850
1219
 
851
- /**
852
- * Gets contract class logs based on the provided filter.
853
- * @param filter - The filter to apply to the logs.
854
- * @returns The requested logs.
855
- */
856
- getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse> {
857
- return this.logsSource.getContractClassLogs(filter);
1220
+ public getPublicLogsByTags(query: PublicLogsQuery): Promise<LogResult[][]> {
1221
+ return this.logsSource.getPublicLogsByTags(query);
858
1222
  }
859
1223
 
860
1224
  /**
@@ -877,32 +1241,47 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
877
1241
  throw new Error(`Invalid tx: ${reason}`);
878
1242
  }
879
1243
 
880
- 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
+ }
881
1251
  const duration = timer.ms();
882
1252
  this.metrics.receivedTx(duration, true);
883
1253
  this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
884
1254
  }
885
1255
 
886
- public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
1256
+ public async getTxReceipt<TGetTxReceiptOptions extends GetTxReceiptOptions = {}>(
1257
+ txHash: TxHash,
1258
+ options?: TGetTxReceiptOptions,
1259
+ ): Promise<TxReceipt<TGetTxReceiptOptions>> {
887
1260
  // Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
888
- // 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.
889
1262
  const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
890
1263
  const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
891
1264
 
892
- // Then get the actual tx from the archiver, which tracks every tx in a mined block.
893
- 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);
894
1267
 
895
1268
  let receipt: TxReceipt;
896
- if (settledTxReceipt) {
897
- receipt = settledTxReceipt;
1269
+ if (indexed) {
1270
+ receipt = await this.#assembleMinedReceipt(indexed, options);
898
1271
  } else if (isKnownToPool) {
899
1272
  // If the tx is in the pool but not in the archiver, it's pending.
900
1273
  // This handles race conditions between archiver and p2p, where the archiver
901
1274
  // has pruned the block in which a tx was mined, but p2p has not caught up yet.
902
- 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);
903
1282
  } else {
904
1283
  // Otherwise, if we don't know the tx, we consider it dropped.
905
- receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
1284
+ receipt = new DroppedTxReceipt(txHash, 'Tx dropped by P2P node');
906
1285
  }
907
1286
 
908
1287
  this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
@@ -910,6 +1289,44 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
910
1289
  return receipt;
911
1290
  }
912
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
+
913
1330
  public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
914
1331
  return this.blockSource.getTxEffect(txHash);
915
1332
  }
@@ -919,11 +1336,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
919
1336
  */
920
1337
  public async stop() {
921
1338
  this.log.info(`Stopping Aztec Node`);
922
- await tryStop(this.validatorsSentinel);
923
- await tryStop(this.epochPruneWatcher);
1339
+ await this.stopStartedWatchers();
924
1340
  await tryStop(this.slasherClient);
925
- await tryStop(this.proofVerifier);
1341
+ await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
926
1342
  await tryStop(this.sequencer);
1343
+ await tryStop(this.automineSequencer);
927
1344
  await tryStop(this.proverNode);
928
1345
  await tryStop(this.p2pClient);
929
1346
  await tryStop(this.worldStateSynchronizer);
@@ -947,30 +1364,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
947
1364
  * @param after - The last known pending tx. Used for pagination
948
1365
  * @returns - The pending txs.
949
1366
  */
950
- public getPendingTxs(limit?: number, after?: TxHash): Promise<Tx[]> {
951
- 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);
952
1369
  }
953
1370
 
954
1371
  public getPendingTxCount(): Promise<number> {
955
1372
  return this.p2pClient!.getPendingTxCount();
956
1373
  }
957
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
+
958
1390
  /**
959
- * 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.
960
1393
  * @param txHash - The transaction hash to return.
1394
+ * @param options - Options for the returned tx (eg whether to include its proof).
961
1395
  * @returns - The tx if it exists.
962
1396
  */
963
- public getTxByHash(txHash: TxHash): Promise<Tx | undefined> {
964
- 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 });
965
1399
  }
966
1400
 
967
1401
  /**
968
- * 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.
969
1404
  * @param txHash - The transaction hash to return.
1405
+ * @param options - Options for the returned txs (eg whether to include their proofs).
970
1406
  * @returns - The txs if it exists.
971
1407
  */
972
- public async getTxsByHash(txHashes: TxHash[]): Promise<Tx[]> {
973
- 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);
974
1411
  }
975
1412
 
976
1413
  public async findLeavesIndexes(
@@ -1012,7 +1449,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1012
1449
  );
1013
1450
 
1014
1451
  // Build a map from block number to block hash
1015
- const blockNumberToHash = new Map<BlockNumber, Fr>();
1452
+ const blockNumberToHash = new Map<BlockNumber, BlockHash>();
1016
1453
  for (let i = 0; i < uniqueBlockNumbers.length; i++) {
1017
1454
  const blockHash = blockHashes[i];
1018
1455
  if (blockHash === undefined) {
@@ -1030,13 +1467,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1030
1467
  if (blockNumber === undefined) {
1031
1468
  throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
1032
1469
  }
1033
- const blockHash = blockNumberToHash.get(blockNumber);
1034
- if (blockHash === undefined) {
1470
+ const l2BlockHash = blockNumberToHash.get(blockNumber);
1471
+ if (l2BlockHash === undefined) {
1035
1472
  throw new Error(`Block hash not found for block number ${blockNumber}`);
1036
1473
  }
1037
1474
  return {
1038
1475
  l2BlockNumber: blockNumber,
1039
- l2BlockHash: new BlockHash(blockHash),
1476
+ l2BlockHash,
1040
1477
  data: index,
1041
1478
  };
1042
1479
  });
@@ -1046,7 +1483,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1046
1483
  referenceBlock: BlockParameter,
1047
1484
  blockHash: BlockHash,
1048
1485
  ): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
1049
- const committedDb = await this.getWorldState(referenceBlock);
1486
+ // The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
1487
+ // which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
1488
+ // So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
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
+ }
1494
+ const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
1050
1495
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
1051
1496
  return pathAndIndex === undefined
1052
1497
  ? undefined
@@ -1083,35 +1528,37 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1083
1528
 
1084
1529
  public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
1085
1530
  const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
1086
- return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
1087
- }
1088
-
1089
- /**
1090
- * Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
1091
- * @param l1ToL2Message - The L1 to L2 message to check.
1092
- * @returns Whether the message is synced and ready to be included in a block.
1093
- */
1094
- public async isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean> {
1095
- const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
1096
- return messageIndex !== undefined;
1531
+ return messageIndex !== undefined ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
1097
1532
  }
1098
1533
 
1099
1534
  /**
1100
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
+ *
1101
1539
  * @param epoch - The epoch at which to get the data.
1102
1540
  * @returns The L2 to L1 messages (empty array if the epoch is not found).
1103
1541
  */
1104
1542
  public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
1105
- // Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
1106
- const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
1107
- const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
1108
- group => group.map(cb => cb.block),
1109
- );
1110
- return blocksInCheckpoints.map(blocks =>
1111
- 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)),
1112
1547
  );
1113
1548
  }
1114
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
+
1115
1562
  public async getNullifierMembershipWitness(
1116
1563
  referenceBlock: BlockParameter,
1117
1564
  nullifier: Fr,
@@ -1182,49 +1629,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1182
1629
  return preimage.leaf.value;
1183
1630
  }
1184
1631
 
1185
- public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
1186
- if (BlockHash.isBlockHash(block)) {
1187
- const initialBlockHash = await this.#getInitialHeaderHash();
1188
- if (block.equals(initialBlockHash)) {
1189
- // Block source doesn't handle initial header so we need to handle the case separately.
1190
- return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1191
- }
1192
- return this.blockSource.getBlockHeaderByHash(block);
1193
- } else {
1194
- // Block source doesn't handle initial header so we need to handle the case separately.
1195
- const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
1196
- if (blockNumber === BlockNumber.ZERO) {
1197
- return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1198
- }
1199
- return this.blockSource.getBlockHeader(block);
1200
- }
1201
- }
1202
-
1203
- /**
1204
- * Get a block header specified by its archive root.
1205
- * @param archive - The archive root being requested.
1206
- * @returns The requested block header.
1207
- */
1208
- public async getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
1209
- return await this.blockSource.getBlockHeaderByArchive(archive);
1210
- }
1211
-
1212
- public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
1213
- return this.blockSource.getBlockData(number);
1214
- }
1215
-
1216
- public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
1217
- return this.blockSource.getBlockDataByArchive(archive);
1218
- }
1219
-
1220
1632
  /**
1221
1633
  * Simulates the public part of a transaction with the current state.
1222
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.
1223
1637
  **/
1224
1638
  @trackSpan('AztecNodeService.simulatePublicCalls', (tx: Tx) => ({
1225
1639
  [Attributes.TX_HASH]: tx.getTxHash().toString(),
1226
1640
  }))
1227
- 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> {
1228
1646
  // Check total gas limit for simulation
1229
1647
  const gasSettings = tx.data.constants.txContext.gasSettings;
1230
1648
  const txGasLimit = gasSettings.gasLimits.l2Gas;
@@ -1240,18 +1658,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1240
1658
  }
1241
1659
 
1242
1660
  const txHash = tx.getTxHash();
1243
- const latestBlockNumber = await this.blockSource.getBlockNumber();
1661
+ const l2Tips = await this.blockSource.getL2Tips();
1662
+ const latestBlockNumber = l2Tips.proposed.number;
1244
1663
  const blockNumber = BlockNumber.add(latestBlockNumber, 1);
1245
1664
 
1246
1665
  // If sequencer is not initialized, we just set these values to zero for simulation.
1247
1666
  const coinbase = EthAddress.ZERO;
1248
1667
  const feeRecipient = AztecAddress.ZERO;
1249
1668
 
1250
- const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(
1251
- 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(
1252
1692
  coinbase,
1253
1693
  feeRecipient,
1694
+ targetSlot,
1254
1695
  );
1696
+ const newGlobalVariables = GlobalVariables.from({ blockNumber, ...checkpointGlobalVariables });
1697
+
1255
1698
  const publicProcessorFactory = new PublicProcessorFactory(
1256
1699
  this.contractDataSource,
1257
1700
  new DateProvider(),
@@ -1267,40 +1710,77 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1267
1710
 
1268
1711
  // Ensure world-state has caught up with the latest block we loaded from the archiver
1269
1712
  await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
1270
- const merkleTreeFork = await this.worldStateSynchronizer.fork();
1271
- try {
1272
- const config = PublicSimulatorConfig.from({
1273
- skipFeeEnforcement,
1274
- collectDebugLogs: true,
1275
- collectHints: false,
1276
- collectCallMetadata: true,
1277
- collectStatistics: false,
1278
- collectionLimits: CollectionLimitsConfig.from({
1279
- maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
1280
- }),
1281
- });
1282
- const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
1283
-
1284
- // REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
1285
- const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
1286
- // REFACTOR: Consider returning the error rather than throwing
1287
- if (failedTxs.length) {
1288
- this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
1289
- throw failedTxs[0].error;
1290
- }
1291
1713
 
1292
- const [processedTx] = processedTxs;
1293
- return new PublicSimulationOutput(
1294
- processedTx.revertReason,
1295
- processedTx.globalVariables,
1296
- processedTx.txEffect,
1297
- returns,
1298
- processedTx.gasUsed,
1299
- 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 },
1300
1745
  );
1301
- } finally {
1302
- await merkleTreeFork.close();
1746
+ await appendL1ToL2MessagesToTree(merkleTreeFork, nextCheckpointMessages);
1303
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;
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
+ );
1304
1784
  }
1305
1785
 
1306
1786
  public async isValidTx(
@@ -1308,12 +1788,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1308
1788
  { isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
1309
1789
  ): Promise<TxValidationResult> {
1310
1790
  const db = this.worldStateSynchronizer.getCommitted();
1311
- const verifier = isSimulation ? undefined : this.proofVerifier;
1791
+ const verifier = isSimulation ? undefined : this.rpcProofVerifier;
1312
1792
 
1313
1793
  // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1314
1794
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1315
1795
  const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1316
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);
1317
1800
  const validator = createTxValidatorForAcceptingTxsOverRPC(
1318
1801
  db,
1319
1802
  this.contractDataSource,
@@ -1329,10 +1812,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1329
1812
  ],
1330
1813
  gasFees: await this.getCurrentMinFees(),
1331
1814
  skipFeeEnforcement,
1815
+ isSimulation,
1332
1816
  txsPermitted: !this.config.disableTransactions,
1333
- rollupManaLimit: l1Constants.rollupManaLimit,
1334
- maxBlockL2Gas: this.config.validateMaxL2BlockGas,
1335
- maxBlockDAGas: this.config.validateMaxDABlockGas,
1817
+ maxTxL2Gas: networkTxGasLimits.l2Gas,
1818
+ maxTxDAGas: networkTxGasLimits.daGas,
1336
1819
  },
1337
1820
  this.log.getBindings(),
1338
1821
  );
@@ -1348,7 +1831,18 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1348
1831
 
1349
1832
  public async setConfig(config: Partial<AztecNodeAdminConfig>): Promise<void> {
1350
1833
  const newConfig = { ...this.config, ...config };
1351
- 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);
1352
1846
  this.slasherClient?.updateConfig(config);
1353
1847
  this.validatorsSentinel?.updateConfig(config);
1354
1848
  await this.p2pClient.updateP2PConfig(config);
@@ -1357,7 +1851,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1357
1851
  archiver.updateConfig(config);
1358
1852
  }
1359
1853
  if (newConfig.realProofs !== this.config.realProofs) {
1360
- 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
+ }
1361
1863
  }
1362
1864
 
1363
1865
  this.config = newConfig;
@@ -1368,7 +1870,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1368
1870
  classRegistry: ProtocolContractAddress.ContractClassRegistry,
1369
1871
  feeJuice: ProtocolContractAddress.FeeJuice,
1370
1872
  instanceRegistry: ProtocolContractAddress.ContractInstanceRegistry,
1371
- multiCallEntrypoint: ProtocolContractAddress.MultiCallEntrypoint,
1873
+ multiCallEntrypoint: STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS,
1372
1874
  });
1373
1875
  }
1374
1876
 
@@ -1432,7 +1934,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1432
1934
  return Promise.resolve();
1433
1935
  }
1434
1936
 
1435
- public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
1937
+ public async rollbackTo(targetBlock: BlockNumber, force?: boolean, resumeSync = true): Promise<void> {
1436
1938
  const archiver = this.blockSource as Archiver;
1437
1939
  if (!('rollbackTo' in archiver)) {
1438
1940
  throw new Error('Archiver implementation does not support rollbacks.');
@@ -1462,9 +1964,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1462
1964
  this.log.error(`Error during rollback`, err);
1463
1965
  throw err;
1464
1966
  } finally {
1465
- this.log.info(`Resuming world state and archiver sync.`);
1466
- this.worldStateSynchronizer.resumeSync();
1467
- 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
+ }
1468
1974
  }
1469
1975
  }
1470
1976
 
@@ -1481,11 +1987,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1481
1987
  return Promise.resolve();
1482
1988
  }
1483
1989
 
1484
- public getSlashPayloads(): Promise<SlashPayloadRound[]> {
1485
- if (!this.slasherClient) {
1486
- throw new Error(`Slasher client not enabled`);
1990
+ public pauseSequencer(): Promise<void> {
1991
+ if (this.automineSequencer) {
1992
+ this.automineSequencer.pause();
1993
+ return Promise.resolve();
1994
+ }
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();
1487
2021
  }
1488
- return this.slasherClient.getSlashPayloads();
2022
+ throw new BadRequestError('Cannot resume sequencer: no sequencer is running');
1489
2023
  }
1490
2024
 
1491
2025
  public getSlashOffenses(round: bigint | 'all' | 'current'): Promise<Offense[]> {
@@ -1493,7 +2027,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1493
2027
  throw new Error(`Slasher client not enabled`);
1494
2028
  }
1495
2029
  if (round === 'all') {
1496
- return this.slasherClient.getPendingOffenses();
2030
+ return this.slasherClient.getOffenses();
1497
2031
  } else {
1498
2032
  return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
1499
2033
  }
@@ -1587,11 +2121,49 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1587
2121
  this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
1588
2122
  }
1589
2123
 
1590
- #getInitialHeaderHash(): Promise<BlockHash> {
1591
- if (!this.initialHeaderHashPromise) {
1592
- 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');
1593
2165
  }
1594
- return this.initialHeaderHashPromise;
2166
+ return await this.automineSequencer.prove(upToCheckpoint);
1595
2167
  }
1596
2168
 
1597
2169
  /**
@@ -1600,54 +2172,52 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1600
2172
  * @returns An instance of a committed MerkleTreeOperations
1601
2173
  */
1602
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
+
1603
2186
  let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
1604
2187
  try {
1605
2188
  // Attempt to sync the world state if necessary
1606
- blockSyncedTo = await this.#syncWorldState();
2189
+ blockSyncedTo = await this.#syncWorldState(anchorBlockNumber, requestedHash);
1607
2190
  } catch (err) {
1608
2191
  this.log.error(`Error getting world state: ${err}`);
1609
2192
  }
1610
2193
 
1611
- if (block === 'latest') {
1612
- 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}`);
1613
2196
  return this.worldStateSynchronizer.getCommitted();
1614
2197
  }
1615
2198
 
1616
- // Get the block number, either directly from the parameter or by quering the archiver with the block hash
1617
- let blockNumber: BlockNumber;
1618
- if (BlockHash.isBlockHash(block)) {
1619
- const initialBlockHash = await this.#getInitialHeaderHash();
1620
- if (block.equals(initialBlockHash)) {
1621
- // Block source doesn't handle initial header so we need to handle the case separately.
1622
- return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
1623
- }
1624
-
1625
- const header = await this.blockSource.getBlockHeaderByHash(block);
1626
- if (!header) {
1627
- throw new Error(
1628
- `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.`,
1629
- );
1630
- }
1631
-
1632
- blockNumber = header.getBlockNumber();
1633
- } else {
1634
- blockNumber = block as BlockNumber;
1635
- }
2199
+ const blockNumber = anchorBlockNumber ?? (await this.resolveBlockNumber(query));
1636
2200
 
1637
2201
  // Check it's within world state sync range
1638
2202
  if (blockNumber > blockSyncedTo) {
1639
- 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
+ );
1640
2206
  }
1641
2207
  this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1642
2208
 
1643
2209
  const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
1644
2210
 
1645
- // Double-check world-state synced to the same block hash as was requested
1646
- 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) {
1647
2217
  const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
1648
- if (!blockHash || !new BlockHash(blockHash).equals(block)) {
2218
+ if (!blockHash || !requestedHash.equals(blockHash)) {
1649
2219
  throw new Error(
1650
- `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.`,
1651
2221
  );
1652
2222
  }
1653
2223
  }
@@ -1655,12 +2225,33 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1655
2225
  return snapshot;
1656
2226
  }
1657
2227
 
2228
+ /** Resolves any {@link BlockParameter} variant to a concrete block number. */
2229
+ protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
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
+ );
2237
+ }
2238
+ if ('archive' in query) {
2239
+ throw new Error(`Block with archive ${query.archive.toString()} not found.`);
2240
+ }
2241
+ throw new Error(`Block not found for ${inspectBlockParameter(block)}.`);
2242
+ }
2243
+ return blockNumber;
2244
+ }
2245
+
1658
2246
  /**
1659
- * 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.
1660
2251
  * @returns A promise that fulfils once the world state is synced
1661
2252
  */
1662
- async #syncWorldState(): Promise<BlockNumber> {
1663
- const blockSourceHeight = await this.blockSource.getBlockNumber();
1664
- 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);
1665
2256
  }
1666
2257
  }