@aztec-labs/aztec-node 6.1.0-nightly.20261113 → 6.1.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.
@@ -0,0 +1,63 @@
1
+ import { LruMap } from '@aztec-labs/foundation/collection';
2
+ import type { SnapshotUploadStatus } from '@aztec-labs/stdlib/interfaces/client';
3
+
4
+ /** In-memory upload outcomes and mutual exclusion for a single node process. */
5
+ export class SnapshotUploads {
6
+ private readonly operations = new LruMap<string, SnapshotUploadStatus>(100);
7
+ private runningId: string | undefined;
8
+
9
+ /** Returns unknown for operations whose outcome is no longer available. */
10
+ public get(operationId: string): SnapshotUploadStatus {
11
+ const status = this.operations.get(operationId);
12
+ return status ? { ...status } : { state: 'unknown' };
13
+ }
14
+
15
+ /**
16
+ * Returns true when the ID already identifies an operation at this location, false when the node does not know it.
17
+ * @throws If the ID already identifies an operation at a different location.
18
+ */
19
+ public checkExisting(operationId: string, location: string): boolean {
20
+ const status = this.operations.get(operationId);
21
+ if (!status || status.state === 'unknown') {
22
+ return false;
23
+ }
24
+ if (status.location !== location) {
25
+ throw new Error('Snapshot upload operation ID already used for a different location.');
26
+ }
27
+ return true;
28
+ }
29
+
30
+ /** Marks a running operation's local capture complete, after syncing has resumed. */
31
+ public markUploading(operationId: string): void {
32
+ const status = this.operations.get(operationId);
33
+ if (status?.state !== 'capturing') {
34
+ throw new Error('Snapshot upload operation is not capturing.');
35
+ }
36
+ this.operations.set(operationId, { state: 'uploading', location: status.location });
37
+ }
38
+
39
+ /** Starts work without awaiting completion, or accepts an idempotent retry of a retained operation. */
40
+ public start(operationId: string, location: string, upload: () => Promise<void>): void {
41
+ if (this.checkExisting(operationId, location)) {
42
+ return;
43
+ }
44
+ if (this.runningId !== undefined) {
45
+ throw new Error('Snapshot upload already in progress. Cannot start another one until complete.');
46
+ }
47
+ this.runningId = operationId;
48
+ this.operations.set(operationId, { state: 'capturing', location });
49
+ void this.run(operationId, location, upload);
50
+ }
51
+
52
+ private async run(operationId: string, location: string, upload: () => Promise<void>) {
53
+ try {
54
+ await upload();
55
+ this.operations.set(operationId, { state: 'succeeded', location });
56
+ } catch (err) {
57
+ const error = err instanceof Error ? err.message : String(err);
58
+ this.operations.set(operationId, { state: 'failed', location, error });
59
+ } finally {
60
+ this.runningId = undefined;
61
+ }
62
+ }
63
+ }
package/src/factory.ts CHANGED
@@ -5,10 +5,11 @@ import { createBlobClientWithFileStores } from '@aztec-labs/blob-client/client';
5
5
  import { Blob, getKzg } from '@aztec-labs/blob-lib';
6
6
  import { EpochCache } from '@aztec-labs/epoch-cache';
7
7
  import { createEthereumChain } from '@aztec-labs/ethereum/chain';
8
- import { getPublicClient, makeL1HttpTransport } from '@aztec-labs/ethereum/client';
8
+ import { makeL1HttpTransport } from '@aztec-labs/ethereum/client';
9
9
  import { InboxContract, RegistryContract, RollupContract } from '@aztec-labs/ethereum/contracts';
10
10
  import { pickL1ContractAddresses } from '@aztec-labs/ethereum/l1-contract-addresses';
11
11
  import type { L1TxUtils } from '@aztec-labs/ethereum/l1-tx-utils';
12
+ import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec-labs/ethereum/types';
12
13
  import { compactArray } from '@aztec-labs/foundation/collection';
13
14
  import { getEnv } from '@aztec-labs/foundation/config/env';
14
15
  import { type Logger, createLogger } from '@aztec-labs/foundation/log';
@@ -59,7 +60,11 @@ import type { SlashingProtectionDatabase } from '@aztec-labs/validator-ha-signer
59
60
  import { createWorldState, createWorldStateSynchronizer } from '@aztec-labs/world-state';
60
61
  import { createPublicClient } from 'viem';
61
62
 
62
- import { type AztecNodeConfig, createKeyStoreForValidator } from './aztec-node/config.js';
63
+ import {
64
+ type AztecNodeConfig,
65
+ createKeyStoreForValidator,
66
+ resolveNodeWorldStateHistoryRetention,
67
+ } from './aztec-node/config.js';
63
68
  import { AdmissionMinFeesProvider, NextBlockFeeCache, NextBlockPredictor } from './aztec-node/next_block/index.js';
64
69
  import { AztecNodeService } from './aztec-node/server.js';
65
70
  import { createSentinel } from './sentinel/factory.js';
@@ -168,49 +173,85 @@ export async function createAztecNodeService(
168
173
  );
169
174
  }
170
175
 
171
- const publicClient = createPublicClient({
172
- chain: ethereumChain.chainInfo,
173
- transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
174
- pollingInterval: config.viemPollingIntervalMS,
175
- });
176
-
177
- const l1ContractsAddresses = await RegistryContract.collectAddresses(
178
- publicClient,
179
- config.registryAddress,
180
- config.rollupVersion ?? 'canonical',
181
- );
182
-
183
- Object.assign(config, l1ContractsAddresses);
184
-
185
- const rollupContract = new RollupContract(publicClient, config.rollupAddress.toString());
186
- // Read-only Inbox handle: proposal validation confirms a checkpoint's final message position against the live
187
- // bucket ring before accepting it, so every node needs one, validator or not.
188
- const inboxContract = new InboxContract(publicClient, config.inboxAddress);
189
- const [l1GenesisTime, slotDuration, epochDuration, rollupVersionFromRollup] = await Promise.all([
190
- rollupContract.getL1GenesisTime(),
191
- rollupContract.getSlotDuration(),
192
- rollupContract.getEpochDuration(),
193
- rollupContract.getVersion(),
194
- ] as const);
195
-
196
- config.rollupVersion ??= Number(rollupVersionFromRollup);
197
-
198
- if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
199
- log.warn(
200
- `Registry looked up and returned a rollup with version (${config.rollupVersion}), but this does not match with version detected from the rollup directly: (${rollupVersionFromRollup}).`,
176
+ // Track started resources so we can clean up on partial failure during node creation. Each L1 RPC grader goes in as
177
+ // soon as its transport starts it, so a failure building the next one does not leave it running.
178
+ const started: { stop?(): Promise<void> | void }[] = [];
179
+ const l1RpcGraders: { stop(): Promise<void> }[] = [];
180
+ const makeL1Client = (urls: string[], graderName: string): ViemPublicClient => {
181
+ const transport = makeL1HttpTransport(urls, {
182
+ timeout: config.l1HttpTimeoutMS,
183
+ grader: { config, chainId: config.l1ChainId, logger: log.createChild(graderName) },
184
+ });
185
+ if (transport.grader) {
186
+ l1RpcGraders.push(transport.grader);
187
+ started.push(transport.grader);
188
+ }
189
+ return createPublicClient({
190
+ chain: ethereumChain.chainInfo,
191
+ transport,
192
+ pollingInterval: config.viemPollingIntervalMS,
193
+ });
194
+ };
195
+
196
+ try {
197
+ // The one L1 public client of this process. Every module the node builds below reads from and sends to L1 through
198
+ // it, rather than building its own from the L1 RPC URLs.
199
+ const publicClient = makeL1Client(config.l1RpcUrls, 'l1-rpc-grader');
200
+ // The archiver traces L1 txs over the debug RPC URLs when there are any, since the regular ones may not serve debug
201
+ // or trace calls.
202
+ const debugClient = (
203
+ config.l1DebugRpcUrls.length > 0 ? makeL1Client(config.l1DebugRpcUrls, 'l1-debug-rpc-grader') : publicClient
204
+ ) as ViemPublicDebugClient;
205
+
206
+ const l1ContractsAddresses = await RegistryContract.collectAddresses(
207
+ publicClient,
208
+ config.registryAddress,
209
+ config.rollupVersion ?? 'canonical',
201
210
  );
202
- }
203
211
 
204
- const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
212
+ Object.assign(config, l1ContractsAddresses);
205
213
 
206
- // attempt snapshot sync if possible
207
- await trySnapshotSync(config, log, options.genesis);
214
+ const rollupContract = new RollupContract(publicClient, config.rollupAddress.toString());
215
+ // Read-only Inbox handle: proposal validation confirms a checkpoint's final message position against the live
216
+ // bucket ring before accepting it, so every node needs one, validator or not.
217
+ const inboxContract = new InboxContract(publicClient, config.inboxAddress);
218
+ const [l1GenesisTime, slotDuration, epochDuration, rollupVersionFromRollup] = await Promise.all([
219
+ rollupContract.getL1GenesisTime(),
220
+ rollupContract.getSlotDuration(),
221
+ rollupContract.getEpochDuration(),
222
+ rollupContract.getVersion(),
223
+ ] as const);
208
224
 
209
- const epochCache = await EpochCache.create(config.rollupAddress, config, { dateProvider });
225
+ config.rollupVersion ??= Number(rollupVersionFromRollup);
226
+
227
+ if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
228
+ log.warn(
229
+ `Registry looked up and returned a rollup with version (${config.rollupVersion}), but this does not match with version detected from the rollup directly: (${rollupVersionFromRollup}).`,
230
+ );
231
+ }
232
+
233
+ const proofSubmissionEpochs = config.enableProverNode ? await rollupContract.getProofSubmissionEpochs() : undefined;
234
+ // Snapshot sync and world-state creation below read the resolved policy, so this must run before either.
235
+ const configuredHistoryRetention = config.worldStateHistoryRetention;
236
+ config.worldStateHistoryRetention = resolveNodeWorldStateHistoryRetention(
237
+ configuredHistoryRetention,
238
+ proofSubmissionEpochs === undefined ? undefined : { proofSubmissionEpochs, epochDuration: Number(epochDuration) },
239
+ );
240
+ if (configuredHistoryRetention === undefined && proofSubmissionEpochs !== undefined) {
241
+ log.info('Derived world-state history retention from the proof submission window', {
242
+ historyRetention: config.worldStateHistoryRetention,
243
+ proofSubmissionEpochs,
244
+ epochDuration: Number(epochDuration),
245
+ });
246
+ }
247
+
248
+ const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
249
+
250
+ // attempt snapshot sync if possible
251
+ await trySnapshotSync(config, publicClient, log, options.genesis);
252
+
253
+ const epochCache = await EpochCache.create(rollupContract, config, { dateProvider });
210
254
 
211
- // Track started resources so we can clean up on partial failure during node creation.
212
- const started: { stop?(): Promise<void> | void }[] = [];
213
- try {
214
255
  // Governance can change the rollup's fee settings (the mana target and limit among them) at any time, so every
215
256
  // component that needs them reads them from this tracker rather than from a copy taken at startup.
216
257
  const feeConfigTracker = await RollupFeeConfigTracker.create(rollupContract, {
@@ -242,7 +283,15 @@ export async function createAztecNodeService(
242
283
  started.push({ stop: () => avmSimulator[Symbol.asyncDispose]() });
243
284
  const archiver = await createArchiver(
244
285
  config,
245
- { blobClient, epochCache, telemetry, dateProvider, feeConfigProvider: feeConfigTracker },
286
+ {
287
+ l1Client: publicClient,
288
+ l1DebugClient: debugClient,
289
+ blobClient,
290
+ epochCache,
291
+ telemetry,
292
+ dateProvider,
293
+ feeConfigProvider: feeConfigTracker,
294
+ },
246
295
  { blockUntilSync: !config.skipArchiverInitialSync },
247
296
  initialHeader,
248
297
  initialBlockHash,
@@ -317,8 +366,7 @@ export async function createAztecNodeService(
317
366
  // submission window spans (proofSubmissionEpochs + 1) epochs, so its tx pool must keep finalized txs
318
367
  // for at least that long to re-fetch them for proving and failure upload. Operators may configure a
319
368
  // larger margin but not a smaller one.
320
- if (config.enableProverNode) {
321
- const proofSubmissionEpochs = await rollupContract.getProofSubmissionEpochs();
369
+ if (proofSubmissionEpochs !== undefined) {
322
370
  const proverRetentionFloorSlots = (proofSubmissionEpochs + 1) * Number(epochDuration);
323
371
  const configuredSlots = config.keepFinalizedTxsForSlots ?? 0;
324
372
  if (proverRetentionFloorSlots > configuredSlots) {
@@ -541,7 +589,7 @@ export async function createAztecNodeService(
541
589
  slasherClient = await createSlasher(
542
590
  config,
543
591
  pickL1ContractAddresses(config),
544
- getPublicClient(config),
592
+ publicClient,
545
593
  watchers,
546
594
  dateProvider,
547
595
  epochCache,
@@ -624,6 +672,7 @@ export async function createAztecNodeService(
624
672
  } else {
625
673
  sequencer = await SequencerClient.new(config, {
626
674
  ...deps,
675
+ l1Client: publicClient,
627
676
  epochCache,
628
677
  l1TxUtils,
629
678
  funderL1TxUtils,
@@ -665,6 +714,7 @@ export async function createAztecNodeService(
665
714
  if (config.enableProverNode) {
666
715
  proverNode = await createProverNode(config, {
667
716
  ...deps.proverNodeDeps,
717
+ l1Client: publicClient,
668
718
  telemetry,
669
719
  dateProvider,
670
720
  archiver,
@@ -698,6 +748,7 @@ export async function createAztecNodeService(
698
748
  slasherClient,
699
749
  validatorsSentinel,
700
750
  stopStartedWatchers,
751
+ l1RpcGraders,
701
752
  l1ChainId: ethereumChain.chainInfo.id,
702
753
  version: config.rollupVersion,
703
754
  globalVariableBuilder,
@@ -1,4 +1,5 @@
1
1
  import type { BlockNumber, CheckpointNumber } from '@aztec-labs/foundation/branded-types';
2
+ import { unique } from '@aztec-labs/foundation/collection';
2
3
  import { BadRequestError } from '@aztec-labs/foundation/json-rpc';
3
4
  import type { BlockData, BlockParameter, CommitteeAttestation, L2BlockSource } from '@aztec-labs/stdlib/block';
4
5
  import type { CheckpointData, L1PublishedData, PublishedCheckpoint } from '@aztec-labs/stdlib/checkpoint';
@@ -146,8 +147,10 @@ export class NodeBlockProvider {
146
147
  async #getCheckpointContextsForBlocks(
147
148
  blocks: { checkpointNumber: CheckpointNumber }[],
148
149
  ): Promise<Map<CheckpointNumber, { l1?: L1PublishedData; attestations?: CommitteeAttestation[] } | undefined>> {
149
- const unique = Array.from(new Set(blocks.map(b => b.checkpointNumber)));
150
- const entries = await Promise.all(unique.map(async n => [n, await this.#getCheckpointContext(n)] as const));
150
+ const checkpointNumbers = unique(blocks.map(b => b.checkpointNumber));
151
+ const entries = await Promise.all(
152
+ checkpointNumbers.map(async n => [n, await this.#getCheckpointContext(n)] as const),
153
+ );
151
154
  return new Map(entries);
152
155
  }
153
156
  }
@@ -1,6 +1,6 @@
1
1
  import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec-labs/constants';
2
2
  import { BlockNumber, type EpochNumber } from '@aztec-labs/foundation/branded-types';
3
- import { chunkBy } from '@aztec-labs/foundation/collection';
3
+ import { chunkBy, compactArray } from '@aztec-labs/foundation/collection';
4
4
  import { Fr } from '@aztec-labs/foundation/curves/bn254';
5
5
  import { type Logger, createLogger } from '@aztec-labs/foundation/log';
6
6
  import { sleep } from '@aztec-labs/foundation/sleep';
@@ -77,7 +77,7 @@ export class NodeWorldStateQueries {
77
77
  leafValues.map(x => x.toBuffer()),
78
78
  );
79
79
  // Filter out undefined values to query block numbers only for found leaves
80
- const definedIndices = maybeIndices.filter(x => x !== undefined);
80
+ const definedIndices = compactArray(maybeIndices);
81
81
 
82
82
  // Now we find the block numbers for the defined indices
83
83
  const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
@@ -6,7 +6,14 @@ import {
6
6
  EpochNumber,
7
7
  SlotNumber,
8
8
  } from '@aztec-labs/foundation/branded-types';
9
- import { countWhile, filterAsync, fromEntries, getEntries, mapValues } from '@aztec-labs/foundation/collection';
9
+ import {
10
+ compactArray,
11
+ countWhile,
12
+ filterAsync,
13
+ fromEntries,
14
+ getEntries,
15
+ mapValues,
16
+ } from '@aztec-labs/foundation/collection';
10
17
  import { EthAddress } from '@aztec-labs/foundation/eth-address';
11
18
  import { createLogger } from '@aztec-labs/foundation/log';
12
19
  import { RunningPromise } from '@aztec-labs/foundation/running-promise';
@@ -589,7 +596,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
589
596
  // Used regardless of which case applies.
590
597
  const checkpoint = await this.getCheckpointForSlot(slot);
591
598
  const p2pAttested = await this.p2p.getCheckpointAttestationsForSlot(slot, checkpoint?.proposalPayloadHash);
592
- const p2pAttestors = p2pAttested.map(a => a.getSender()).filter((s): s is EthAddress => s !== undefined);
599
+ const p2pAttestors = compactArray(p2pAttested.map(a => a.getSender()));
593
600
  const attestors = new Set(
594
601
  [...p2pAttestors.map(a => a.toString()), ...(checkpoint?.attestors.map(a => a.toString()) ?? [])].filter(
595
602
  addr => proposer.toString() !== addr,