@aztec/archiver 0.0.1-commit.5914bae → 0.0.1-commit.59a0419c6

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 (95) hide show
  1. package/README.md +12 -6
  2. package/dest/archiver.d.ts +7 -5
  3. package/dest/archiver.d.ts.map +1 -1
  4. package/dest/archiver.js +18 -5
  5. package/dest/config.d.ts +5 -3
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +15 -3
  8. package/dest/errors.d.ts +44 -2
  9. package/dest/errors.d.ts.map +1 -1
  10. package/dest/errors.js +58 -2
  11. package/dest/factory.d.ts +2 -2
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +3 -4
  14. package/dest/index.d.ts +3 -2
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +2 -1
  17. package/dest/l1/calldata_retriever.d.ts +1 -1
  18. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  19. package/dest/l1/calldata_retriever.js +2 -1
  20. package/dest/l1/data_retrieval.d.ts +24 -12
  21. package/dest/l1/data_retrieval.d.ts.map +1 -1
  22. package/dest/l1/data_retrieval.js +36 -37
  23. package/dest/l1/validate_historical_logs.d.ts +23 -0
  24. package/dest/l1/validate_historical_logs.d.ts.map +1 -0
  25. package/dest/l1/validate_historical_logs.js +108 -0
  26. package/dest/modules/data_source_base.d.ts +6 -4
  27. package/dest/modules/data_source_base.d.ts.map +1 -1
  28. package/dest/modules/data_source_base.js +10 -4
  29. package/dest/modules/data_store_updater.d.ts +15 -10
  30. package/dest/modules/data_store_updater.d.ts.map +1 -1
  31. package/dest/modules/data_store_updater.js +27 -59
  32. package/dest/modules/instrumentation.d.ts +18 -2
  33. package/dest/modules/instrumentation.d.ts.map +1 -1
  34. package/dest/modules/instrumentation.js +32 -6
  35. package/dest/modules/l1_synchronizer.d.ts +6 -2
  36. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  37. package/dest/modules/l1_synchronizer.js +248 -149
  38. package/dest/modules/validation.d.ts +1 -1
  39. package/dest/modules/validation.d.ts.map +1 -1
  40. package/dest/modules/validation.js +2 -2
  41. package/dest/store/block_store.d.ts +46 -5
  42. package/dest/store/block_store.d.ts.map +1 -1
  43. package/dest/store/block_store.js +225 -63
  44. package/dest/store/contract_class_store.d.ts +2 -3
  45. package/dest/store/contract_class_store.d.ts.map +1 -1
  46. package/dest/store/contract_class_store.js +1 -65
  47. package/dest/store/kv_archiver_store.d.ts +35 -14
  48. package/dest/store/kv_archiver_store.d.ts.map +1 -1
  49. package/dest/store/kv_archiver_store.js +40 -14
  50. package/dest/store/l2_tips_cache.d.ts +2 -1
  51. package/dest/store/l2_tips_cache.d.ts.map +1 -1
  52. package/dest/store/l2_tips_cache.js +27 -7
  53. package/dest/store/log_store.d.ts +6 -3
  54. package/dest/store/log_store.d.ts.map +1 -1
  55. package/dest/store/log_store.js +47 -10
  56. package/dest/store/message_store.d.ts +5 -1
  57. package/dest/store/message_store.d.ts.map +1 -1
  58. package/dest/store/message_store.js +20 -8
  59. package/dest/test/fake_l1_state.d.ts +7 -3
  60. package/dest/test/fake_l1_state.d.ts.map +1 -1
  61. package/dest/test/fake_l1_state.js +50 -10
  62. package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
  63. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  64. package/dest/test/mock_l1_to_l2_message_source.js +2 -1
  65. package/dest/test/mock_l2_block_source.d.ts +7 -2
  66. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  67. package/dest/test/mock_l2_block_source.js +28 -3
  68. package/dest/test/noop_l1_archiver.d.ts +1 -1
  69. package/dest/test/noop_l1_archiver.d.ts.map +1 -1
  70. package/dest/test/noop_l1_archiver.js +4 -2
  71. package/package.json +13 -13
  72. package/src/archiver.ts +33 -8
  73. package/src/config.ts +22 -2
  74. package/src/errors.ts +94 -2
  75. package/src/factory.ts +2 -3
  76. package/src/index.ts +2 -1
  77. package/src/l1/calldata_retriever.ts +2 -1
  78. package/src/l1/data_retrieval.ts +52 -53
  79. package/src/l1/validate_historical_logs.ts +140 -0
  80. package/src/modules/data_source_base.ts +23 -4
  81. package/src/modules/data_store_updater.ts +43 -85
  82. package/src/modules/instrumentation.ts +47 -7
  83. package/src/modules/l1_synchronizer.ts +321 -185
  84. package/src/modules/validation.ts +2 -2
  85. package/src/store/block_store.ts +295 -73
  86. package/src/store/contract_class_store.ts +1 -103
  87. package/src/store/kv_archiver_store.ts +67 -24
  88. package/src/store/l2_tips_cache.ts +58 -13
  89. package/src/store/log_store.ts +62 -20
  90. package/src/store/message_store.ts +26 -9
  91. package/src/structs/inbox_message.ts +1 -1
  92. package/src/test/fake_l1_state.ts +72 -15
  93. package/src/test/mock_l1_to_l2_message_source.ts +1 -0
  94. package/src/test/mock_l2_block_source.ts +37 -2
  95. package/src/test/noop_l1_archiver.ts +3 -1
@@ -35,18 +35,28 @@ import type { DataRetrieval } from '../structs/data_retrieval.js';
35
35
  import type { InboxMessage } from '../structs/inbox_message.js';
36
36
  import { CalldataRetriever } from './calldata_retriever.js';
37
37
 
38
- export type RetrievedCheckpoint = {
38
+ type RetrievedCheckpointBase = {
39
39
  checkpointNumber: CheckpointNumber;
40
40
  archiveRoot: Fr;
41
41
  feeAssetPriceModifier: bigint;
42
42
  header: CheckpointHeader;
43
- checkpointBlobData: CheckpointBlobData;
44
43
  l1: L1PublishedData;
45
44
  chainId: Fr;
46
45
  version: Fr;
47
46
  attestations: CommitteeAttestation[];
48
47
  };
49
48
 
49
+ /** Checkpoint data as retrieved from L1 calldata and blob data. */
50
+ export type RetrievedCheckpoint = RetrievedCheckpointBase & { checkpointBlobData: CheckpointBlobData };
51
+
52
+ /** Checkpoint data retrieved from L1 calldata only, without blob data. */
53
+ export type RetrievedCheckpointFromCalldata = RetrievedCheckpointBase & {
54
+ /** Versioned blob hashes from the checkpoint proposed event. */
55
+ blobHashes: Buffer[];
56
+ /** Parent beacon block root from the L1 block, used for blob fetching. */
57
+ parentBeaconBlockRoot: string | undefined;
58
+ };
59
+
50
60
  export async function retrievedToPublishedCheckpoint({
51
61
  checkpointNumber,
52
62
  archiveRoot,
@@ -137,31 +147,27 @@ export async function retrievedToPublishedCheckpoint({
137
147
  }
138
148
 
139
149
  /**
140
- * Fetches new checkpoints.
150
+ * Fetches checkpoint calldata from the rollup contract without fetching blob data.
151
+ * Returns RetrievedCheckpointFromCalldata objects that preserve the information needed for deferred blob fetching.
141
152
  * @param rollup - The rollup contract wrapper.
142
153
  * @param publicClient - The viem public client to use for transaction retrieval.
143
154
  * @param debugClient - The viem debug client to use for trace/debug RPC methods (optional).
144
- * @param blobClient - The blob client client for fetching blob data.
145
155
  * @param searchStartBlock - The block number to use for starting the search.
146
156
  * @param searchEndBlock - The highest block number that we should search up to.
147
- * @param contractAddresses - The contract addresses (governanceProposerAddress, slashFactoryAddress, slashingProposerAddress).
148
157
  * @param instrumentation - The archiver instrumentation instance.
149
158
  * @param logger - The logger instance.
150
- * @param isHistoricalSync - Whether this is a historical sync.
151
- * @returns An array of retrieved checkpoints.
159
+ * @returns An array of calldata-only checkpoints.
152
160
  */
153
- export async function retrieveCheckpointsFromRollup(
161
+ export async function retrieveCheckpointCalldataFromRollup(
154
162
  rollup: RollupContract,
155
163
  publicClient: ViemPublicClient,
156
164
  debugClient: ViemPublicDebugClient,
157
- blobClient: BlobClientInterface,
158
165
  searchStartBlock: bigint,
159
166
  searchEndBlock: bigint,
160
167
  instrumentation: ArchiverInstrumentation,
161
168
  logger: Logger = createLogger('archiver'),
162
- isHistoricalSync: boolean = false,
163
- ): Promise<RetrievedCheckpoint[]> {
164
- const retrievedCheckpoints: RetrievedCheckpoint[] = [];
169
+ ): Promise<RetrievedCheckpointFromCalldata[]> {
170
+ const retrievedCheckpoints: RetrievedCheckpointFromCalldata[] = [];
165
171
 
166
172
  let rollupConstants: { chainId: Fr; version: Fr; targetCommitteeSize: number } | undefined;
167
173
 
@@ -197,46 +203,39 @@ export async function retrieveCheckpointsFromRollup(
197
203
  rollup,
198
204
  publicClient,
199
205
  debugClient,
200
- blobClient,
201
206
  checkpointProposedLogs,
202
207
  rollupConstants,
203
208
  instrumentation,
204
209
  logger,
205
- isHistoricalSync,
206
210
  );
207
211
  retrievedCheckpoints.push(...newCheckpoints);
208
212
  searchStartBlock = lastLog.l1BlockNumber + 1n;
209
213
  } while (searchStartBlock <= searchEndBlock);
210
214
 
211
- // The asyncPool from processCheckpointProposedLogs will not necessarily return the checkpoints in order, so we sort them before returning.
212
215
  return retrievedCheckpoints.sort((a, b) => Number(a.l1.blockNumber - b.l1.blockNumber));
213
216
  }
214
217
 
215
218
  /**
216
- * Processes newly received CheckpointProposed logs.
219
+ * Processes CheckpointProposed logs, fetching only calldata (no blobs).
217
220
  * @param rollup - The rollup contract wrapper.
218
221
  * @param publicClient - The viem public client to use for transaction retrieval.
219
222
  * @param debugClient - The viem debug client to use for trace/debug RPC methods (optional).
220
- * @param blobClient - The blob client client for fetching blob data.
221
223
  * @param logs - CheckpointProposed logs.
222
224
  * @param rollupConstants - The rollup constants (chainId, version, targetCommitteeSize).
223
225
  * @param instrumentation - The archiver instrumentation instance.
224
226
  * @param logger - The logger instance.
225
- * @param isHistoricalSync - Whether this is a historical sync.
226
- * @returns An array of retrieved checkpoints.
227
+ * @returns An array of calldata-only checkpoints.
227
228
  */
228
229
  async function processCheckpointProposedLogs(
229
230
  rollup: RollupContract,
230
231
  publicClient: ViemPublicClient,
231
232
  debugClient: ViemPublicDebugClient,
232
- blobClient: BlobClientInterface,
233
233
  logs: CheckpointProposedLog[],
234
234
  { chainId, version, targetCommitteeSize }: { chainId: Fr; version: Fr; targetCommitteeSize: number },
235
235
  instrumentation: ArchiverInstrumentation,
236
236
  logger: Logger,
237
- isHistoricalSync: boolean,
238
- ): Promise<RetrievedCheckpoint[]> {
239
- const retrievedCheckpoints: RetrievedCheckpoint[] = [];
237
+ ): Promise<RetrievedCheckpointFromCalldata[]> {
238
+ const retrievedCheckpoints: RetrievedCheckpointFromCalldata[] = [];
240
239
  const calldataRetriever = new CalldataRetriever(
241
240
  publicClient,
242
241
  debugClient,
@@ -252,7 +251,6 @@ async function processCheckpointProposedLogs(
252
251
  const archiveFromChain = await rollup.archiveAt(checkpointNumber);
253
252
  const blobHashes = log.args.versionedBlobHashes;
254
253
 
255
- // The value from the event and contract will match only if the checkpoint is in the chain.
256
254
  if (archive.equals(archiveFromChain)) {
257
255
  const expectedHashes = {
258
256
  attestationsHash: log.args.attestationsHash.toString() as Hex,
@@ -265,23 +263,19 @@ async function processCheckpointProposedLogs(
265
263
  checkpointNumber,
266
264
  expectedHashes,
267
265
  );
268
- const checkpointBlobData = await getCheckpointBlobDataFromBlobs(
269
- blobClient,
270
- checkpoint.blockHash,
266
+ const { timestamp, parentBeaconBlockRoot } = await getL1Block(publicClient, log.l1BlockNumber);
267
+ const l1 = new L1PublishedData(log.l1BlockNumber, timestamp, log.l1BlockHash.toString());
268
+
269
+ retrievedCheckpoints.push({
270
+ ...checkpoint,
271
+ l1,
272
+ chainId,
273
+ version,
271
274
  blobHashes,
272
- checkpointNumber,
273
- logger,
274
- isHistoricalSync,
275
- );
276
-
277
- const l1 = new L1PublishedData(
278
- log.l1BlockNumber,
279
- await getL1BlockTime(publicClient, log.l1BlockNumber),
280
- log.l1BlockHash.toString(),
281
- );
275
+ parentBeaconBlockRoot,
276
+ });
282
277
 
283
- retrievedCheckpoints.push({ ...checkpoint, checkpointBlobData, l1, chainId, version });
284
- logger.trace(`Retrieved checkpoint ${checkpointNumber} from L1 tx ${log.l1TransactionHash}`, {
278
+ logger.trace(`Retrieved checkpoint calldata ${checkpointNumber} from L1 tx ${log.l1TransactionHash}`, {
285
279
  l1BlockNumber: log.l1BlockNumber,
286
280
  checkpointNumber,
287
281
  archive: archive.toString(),
@@ -298,9 +292,12 @@ async function processCheckpointProposedLogs(
298
292
  return retrievedCheckpoints;
299
293
  }
300
294
 
301
- export async function getL1BlockTime(publicClient: ViemPublicClient, blockNumber: bigint): Promise<bigint> {
295
+ export async function getL1Block(
296
+ publicClient: ViemPublicClient,
297
+ blockNumber: bigint,
298
+ ): Promise<{ timestamp: bigint; parentBeaconBlockRoot: string | undefined }> {
302
299
  const block = await publicClient.getBlock({ blockNumber, includeTransactions: false });
303
- return block.timestamp;
300
+ return { timestamp: block.timestamp, parentBeaconBlockRoot: block.parentBeaconBlockRoot };
304
301
  }
305
302
 
306
303
  export async function getCheckpointBlobDataFromBlobs(
@@ -310,8 +307,14 @@ export async function getCheckpointBlobDataFromBlobs(
310
307
  checkpointNumber: CheckpointNumber,
311
308
  logger: Logger,
312
309
  isHistoricalSync: boolean,
310
+ parentBeaconBlockRoot?: string,
311
+ l1BlockTimestamp?: bigint,
313
312
  ): Promise<CheckpointBlobData> {
314
- const blobBodies = await blobClient.getBlobSidecar(blockHash, blobHashes, { isHistoricalSync });
313
+ const blobBodies = await blobClient.getBlobSidecar(blockHash, blobHashes, {
314
+ isHistoricalSync,
315
+ parentBeaconBlockRoot,
316
+ l1BlockTimestamp,
317
+ });
315
318
  if (blobBodies.length === 0) {
316
319
  throw new NoBlobBodiesFoundError(checkpointNumber);
317
320
  }
@@ -336,14 +339,10 @@ export async function getCheckpointBlobDataFromBlobs(
336
339
  /** Given an L1 to L2 message, retrieves its corresponding event from the Inbox within a specific block range. */
337
340
  export async function retrieveL1ToL2Message(
338
341
  inbox: InboxContract,
339
- leaf: Fr,
340
- fromBlock: bigint,
341
- toBlock: bigint,
342
+ message: InboxMessage,
342
343
  ): Promise<InboxMessage | undefined> {
343
- const logs = await inbox.getMessageSentEventByHash(leaf.toString(), fromBlock, toBlock);
344
-
345
- const messages = mapLogsInboxMessage(logs);
346
- return messages.length > 0 ? messages[0] : undefined;
344
+ const log = await inbox.getMessageSentEventByHash(message.leaf.toString(), message.l1BlockNumber);
345
+ return log && mapLogInboxMessage(log);
347
346
  }
348
347
 
349
348
  /**
@@ -366,22 +365,22 @@ export async function retrieveL1ToL2Messages(
366
365
  break;
367
366
  }
368
367
 
369
- retrievedL1ToL2Messages.push(...mapLogsInboxMessage(messageSentLogs));
368
+ retrievedL1ToL2Messages.push(...messageSentLogs.map(mapLogInboxMessage));
370
369
  searchStartBlock = messageSentLogs.at(-1)!.l1BlockNumber + 1n;
371
370
  }
372
371
 
373
372
  return retrievedL1ToL2Messages;
374
373
  }
375
374
 
376
- function mapLogsInboxMessage(logs: MessageSentLog[]): InboxMessage[] {
377
- return logs.map(log => ({
375
+ function mapLogInboxMessage(log: MessageSentLog): InboxMessage {
376
+ return {
378
377
  index: log.args.index,
379
378
  leaf: log.args.leaf,
380
379
  l1BlockNumber: log.l1BlockNumber,
381
380
  l1BlockHash: log.l1BlockHash,
382
381
  checkpointNumber: log.args.checkpointNumber,
383
382
  rollingHash: log.args.rollingHash,
384
- }));
383
+ };
385
384
  }
386
385
 
387
386
  /** Retrieves L2ProofVerified events from the rollup contract. */
@@ -0,0 +1,140 @@
1
+ import { getPublicClient, getRpcUrlsFromClient } from '@aztec/ethereum/client';
2
+ import { RollupContract } from '@aztec/ethereum/contracts';
3
+ import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
4
+ import type { ViemPublicClient } from '@aztec/ethereum/types';
5
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
6
+
7
+ /** Subset of L1 contract addresses whose historical logs the Aztec node relies on. */
8
+ export type HistoricalLogsContractAddresses = Pick<
9
+ L1ContractAddresses,
10
+ 'rollupAddress' | 'inboxAddress' | 'registryAddress' | 'governanceProposerAddress'
11
+ >;
12
+
13
+ /** Result of probing a single RPC URL. */
14
+ type ProbeResult = { ok: true } | { ok: false; reason: string; clientVersion: string | undefined };
15
+
16
+ /**
17
+ * Validates that every configured L1 RPC URL returns historical logs for the Rollup contract.
18
+ *
19
+ * Some RPC providers prune old logs, which would cause L1 syncing to silently fail. To detect this,
20
+ * we query for the `OwnershipTransferred` event which every Rollup emits in its constructor (via
21
+ * Ownable) on the block it was deployed (`l1StartBlock`). The `client` is typically a viem fallback
22
+ * transport over several user-configured RPC URLs — checking only the first URL would miss a bad
23
+ * secondary, so we probe each URL independently. The first URL that fails aborts startup, unless
24
+ * the operator has explicitly opted out.
25
+ *
26
+ * @param client - The L1 public client built from the user-configured RPC URLs.
27
+ * @param addresses - The subset of L1 contract addresses we rely on for historical log retrieval.
28
+ * @param skipCheck - If true, log warnings instead of throwing.
29
+ * @param bindings - Optional logger bindings for context.
30
+ * @throws Error if any URL fails the probe and skipCheck is false.
31
+ */
32
+ export async function validateAndLogHistoricalLogsAvailability(
33
+ client: ViemPublicClient,
34
+ addresses: HistoricalLogsContractAddresses,
35
+ skipCheck: boolean,
36
+ bindings?: LoggerBindings,
37
+ ): Promise<void> {
38
+ const logger = createLogger('archiver:validate_historical_logs', bindings);
39
+ logger.debug('Validating historical log availability on L1 RPCs');
40
+
41
+ const urls = getRpcUrlsFromClient(client);
42
+ if (urls.length === 0) {
43
+ logger.warn('Could not determine L1 RPC URLs from the public client; skipping historical logs check.');
44
+ return;
45
+ }
46
+
47
+ const chainId = client.chain?.id;
48
+ if (chainId === undefined) {
49
+ logger.warn('Could not determine L1 chain ID from the public client; skipping historical logs check.');
50
+ return;
51
+ }
52
+
53
+ for (const url of urls) {
54
+ const probeClient = getPublicClient({ l1RpcUrls: [url], l1ChainId: chainId });
55
+ const rollup = new RollupContract(probeClient, addresses.rollupAddress.toString());
56
+ const result = await probeRpcUrl(rollup, probeClient, logger);
57
+
58
+ if (result.ok) {
59
+ logger.debug(`L1 RPC ${url} returned historical OwnershipTransferred log for the Rollup contract.`);
60
+ continue;
61
+ }
62
+
63
+ const errorMessage = buildErrorMessage(url, result, addresses);
64
+ if (skipCheck) {
65
+ logger.warn(`${errorMessage}\nContinuing because ARCHIVER_SKIP_HISTORICAL_LOGS_CHECK is true.`);
66
+ continue;
67
+ }
68
+
69
+ logger.error(errorMessage);
70
+ throw new Error(errorMessage);
71
+ }
72
+ }
73
+
74
+ /** Runs the OwnershipTransferred probe against a single RPC and queries its client version. */
75
+ async function probeRpcUrl(rollup: RollupContract, client: ViemPublicClient, logger: Logger): Promise<ProbeResult> {
76
+ let queryError: unknown;
77
+ try {
78
+ const logs = await rollup.getOwnershipTransferredEventsAtDeploy();
79
+ if (logs.length > 0) {
80
+ return { ok: true };
81
+ }
82
+ } catch (err) {
83
+ queryError = err;
84
+ }
85
+
86
+ const clientVersion = await getClientVersion(client, logger);
87
+
88
+ let reason: string;
89
+ if (queryError instanceof Error) {
90
+ reason = `Query for historical logs failed: ${queryError.message}`;
91
+ } else if (queryError !== undefined) {
92
+ reason = 'Query for historical logs failed with a non-Error value.';
93
+ } else {
94
+ reason = 'No OwnershipTransferred event was returned by the L1 RPC for the Rollup deploy block.';
95
+ }
96
+ return { ok: false, reason, clientVersion };
97
+ }
98
+
99
+ /** Builds the operator-facing error message for a failing RPC URL. */
100
+ function buildErrorMessage(
101
+ url: string,
102
+ result: Extract<ProbeResult, { ok: false }>,
103
+ addresses: HistoricalLogsContractAddresses,
104
+ ): string {
105
+ return [
106
+ `L1 RPC at ${url} does not return historical logs for the Rollup contract. ${result.reason}`,
107
+ `This likely means this Ethereum RPC node prunes old logs, which would cause the archiver ` +
108
+ `to silently miss data during L1 sync.`,
109
+ result.clientVersion
110
+ ? `Detected L1 client version for ${url}: ${result.clientVersion}.`
111
+ : `Could not determine L1 client version for ${url}.`,
112
+ `The following L1 contract addresses must have their historical logs retained by the RPC node:`,
113
+ ` - Rollup: ${addresses.rollupAddress.toString()}`,
114
+ ` - Inbox: ${addresses.inboxAddress.toString()}`,
115
+ ` - Registry: ${addresses.registryAddress.toString()}`,
116
+ ` - GovernanceProposer: ${addresses.governanceProposerAddress.toString()}`,
117
+ isReth(result.clientVersion)
118
+ ? `To retain logs for these contracts, configure reth with a ` +
119
+ `prune.segments.receipts_log_filter entry for each address above ` +
120
+ `so reth does not prune their receipts/logs. See https://reth.rs/run/pruning.html for details.`
121
+ : `Point this RPC endpoint at a node that retains full log history for the addresses above.`,
122
+ `Set ARCHIVER_SKIP_HISTORICAL_LOGS_CHECK=true to bypass this check at your own risk.`,
123
+ ].join('\n');
124
+ }
125
+
126
+ /** Queries `web3_clientVersion` on the L1 RPC. Returns undefined if the call fails or returns a non-string. */
127
+ async function getClientVersion(client: ViemPublicClient, logger: Logger): Promise<string | undefined> {
128
+ try {
129
+ const result = await client.request({ method: 'web3_clientVersion' });
130
+ return typeof result === 'string' ? result : undefined;
131
+ } catch (err) {
132
+ logger.debug(`Failed to query web3_clientVersion: ${err instanceof Error ? err.message : err}`);
133
+ return undefined;
134
+ }
135
+ }
136
+
137
+ /** Heuristic check for reth based on the web3_clientVersion string (reth returns e.g. "reth/v1.0.0-..."). */
138
+ function isReth(clientVersion: string | undefined): boolean {
139
+ return !!clientVersion && /reth/i.test(clientVersion);
140
+ }
@@ -6,7 +6,13 @@ import { isDefined } from '@aztec/foundation/types';
6
6
  import type { FunctionSelector } from '@aztec/stdlib/abi';
7
7
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
8
8
  import { type BlockData, type BlockHash, CheckpointedL2Block, L2Block, type L2Tips } from '@aztec/stdlib/block';
9
- import { Checkpoint, type CheckpointData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
9
+ import {
10
+ Checkpoint,
11
+ type CheckpointData,
12
+ type CommonCheckpointData,
13
+ type ProposedCheckpointData,
14
+ PublishedCheckpoint,
15
+ } from '@aztec/stdlib/checkpoint';
10
16
  import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
11
17
  import { type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
12
18
  import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
@@ -157,6 +163,14 @@ export abstract class ArchiverDataSourceBase
157
163
  return this.store.getSettledTxReceipt(txHash, this.l1Constants);
158
164
  }
159
165
 
166
+ public getProposedCheckpoint(): Promise<CommonCheckpointData | undefined> {
167
+ return this.store.getProposedCheckpoint();
168
+ }
169
+
170
+ public getProposedCheckpointOnly(): Promise<ProposedCheckpointData | undefined> {
171
+ return this.store.getProposedCheckpointOnly();
172
+ }
173
+
160
174
  public isPendingChainInvalid(): Promise<boolean> {
161
175
  return this.getPendingChainValidationStatus().then(status => !status.valid);
162
176
  }
@@ -165,16 +179,21 @@ export abstract class ArchiverDataSourceBase
165
179
  return (await this.store.getPendingChainValidationStatus()) ?? { valid: true };
166
180
  }
167
181
 
168
- public getPrivateLogsByTags(tags: SiloedTag[], page?: number): Promise<TxScopedL2Log[][]> {
169
- return this.store.getPrivateLogsByTags(tags, page);
182
+ public getPrivateLogsByTags(
183
+ tags: SiloedTag[],
184
+ page?: number,
185
+ upToBlockNumber?: BlockNumber,
186
+ ): Promise<TxScopedL2Log[][]> {
187
+ return this.store.getPrivateLogsByTags(tags, page, upToBlockNumber);
170
188
  }
171
189
 
172
190
  public getPublicLogsByTagsFromContract(
173
191
  contractAddress: AztecAddress,
174
192
  tags: Tag[],
175
193
  page?: number,
194
+ upToBlockNumber?: BlockNumber,
176
195
  ): Promise<TxScopedL2Log[][]> {
177
- return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, page);
196
+ return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
178
197
  }
179
198
 
180
199
  public getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
@@ -1,32 +1,26 @@
1
1
  import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
2
2
  import { filterAsync } from '@aztec/foundation/collection';
3
- import { Fr } from '@aztec/foundation/curves/bn254';
4
3
  import { createLogger } from '@aztec/foundation/log';
5
- import {
6
- ContractClassPublishedEvent,
7
- PrivateFunctionBroadcastedEvent,
8
- UtilityFunctionBroadcastedEvent,
9
- } from '@aztec/protocol-contracts/class-registry';
4
+ import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
10
5
  import {
11
6
  ContractInstancePublishedEvent,
12
7
  ContractInstanceUpdatedEvent,
13
8
  } from '@aztec/protocol-contracts/instance-registry';
14
- import type { L2Block, ValidateCheckpointResult } from '@aztec/stdlib/block';
15
- import { type PublishedCheckpoint, validateCheckpoint } from '@aztec/stdlib/checkpoint';
9
+ import type { CommitteeAttestation, L2Block, ValidateCheckpointResult } from '@aztec/stdlib/block';
10
+ import {
11
+ type L1PublishedData,
12
+ type ProposedCheckpointInput,
13
+ type PublishedCheckpoint,
14
+ validateCheckpoint,
15
+ } from '@aztec/stdlib/checkpoint';
16
16
  import {
17
17
  type ContractClassPublicWithCommitment,
18
- type ExecutablePrivateFunctionWithMembershipProof,
19
- type UtilityFunctionWithMembershipProof,
20
18
  computeContractAddressFromInstance,
21
19
  computeContractClassId,
22
- isValidPrivateFunctionMembershipProof,
23
- isValidUtilityFunctionMembershipProof,
24
20
  } from '@aztec/stdlib/contract';
25
21
  import type { ContractClassLog, PrivateLog, PublicLog } from '@aztec/stdlib/logs';
26
22
  import type { UInt64 } from '@aztec/stdlib/types';
27
23
 
28
- import groupBy from 'lodash.groupby';
29
-
30
24
  import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
31
25
  import type { L2TipsCache } from '../store/l2_tips_cache.js';
32
26
 
@@ -57,8 +51,7 @@ export class ArchiverDataStoreUpdater {
57
51
  /**
58
52
  * Adds a proposed block to the store with contract class/instance extraction from logs.
59
53
  * This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
60
- * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
61
- * and individually broadcasted functions from the block logs.
54
+ * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the block logs.
62
55
  *
63
56
  * @param block - The proposed L2 block to add.
64
57
  * @param pendingChainValidationStatus - Optional validation status to set.
@@ -90,20 +83,30 @@ export class ArchiverDataStoreUpdater {
90
83
  * Reconciles local blocks with incoming checkpoints from L1.
91
84
  * Adds new checkpoints to the store with contract class/instance extraction from logs.
92
85
  * Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
93
- * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
94
- * and individually broadcasted functions from the checkpoint block logs.
86
+ * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the checkpoint block logs.
87
+ * If `promoteProposed` is supplied, the proposed-checkpoint promotion runs inside the same transaction
88
+ * as the added checkpoints so both updates are applied atomically.
95
89
  *
96
- * @param checkpoints - The published checkpoints to add.
90
+ * @param checkpoints - The published checkpoints to add (excluding any being promoted from proposed).
97
91
  * @param pendingChainValidationStatus - Optional validation status to set.
92
+ * @param promoteProposed - Optional promotion of the current proposed checkpoint (fast path when blocks are already local).
98
93
  * @returns Result with information about any pruned blocks.
99
94
  */
100
95
  public async addCheckpoints(
101
96
  checkpoints: PublishedCheckpoint[],
102
97
  pendingChainValidationStatus?: ValidateCheckpointResult,
98
+ promoteProposed?: {
99
+ l1: L1PublishedData;
100
+ attestations: CommitteeAttestation[];
101
+ checkpoint: PublishedCheckpoint;
102
+ },
103
103
  ): Promise<ReconcileCheckpointsResult> {
104
104
  for (const checkpoint of checkpoints) {
105
105
  validateCheckpoint(checkpoint.checkpoint, { rollupManaLimit: this.opts?.rollupManaLimit });
106
106
  }
107
+ if (promoteProposed) {
108
+ validateCheckpoint(promoteProposed.checkpoint.checkpoint, { rollupManaLimit: this.opts?.rollupManaLimit });
109
+ }
107
110
 
108
111
  const result = await this.store.transactionAsync(async () => {
109
112
  // Before adding checkpoints, check for conflicts with local blocks if any
@@ -123,6 +126,14 @@ export class ArchiverDataStoreUpdater {
123
126
  this.store.addLogs(newBlocks),
124
127
  // Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
125
128
  ...newBlocks.map(block => this.addContractDataToDb(block)),
129
+ // Promote the proposed checkpoint if requested
130
+ promoteProposed
131
+ ? this.store.promoteProposedToCheckpointed(
132
+ promoteProposed.l1,
133
+ promoteProposed.attestations,
134
+ promoteProposed.checkpoint.checkpoint.archive.root,
135
+ )
136
+ : undefined,
126
137
  ]);
127
138
 
128
139
  await this.l2TipsCache?.refresh();
@@ -131,6 +142,15 @@ export class ArchiverDataStoreUpdater {
131
142
  return result;
132
143
  }
133
144
 
145
+ public async setProposedCheckpoint(proposedCheckpoint: ProposedCheckpointInput) {
146
+ const result = await this.store.transactionAsync(async () => {
147
+ await this.store.setProposedCheckpoint(proposedCheckpoint);
148
+ await this.l2TipsCache?.refresh();
149
+ });
150
+
151
+ return result;
152
+ }
153
+
134
154
  /**
135
155
  * Checks for local proposed blocks that do not match the ones to be checkpointed and prunes them.
136
156
  * This method handles multiple checkpoints but returns after pruning the first conflict found.
@@ -224,6 +244,10 @@ export class ArchiverDataStoreUpdater {
224
244
  }
225
245
 
226
246
  const result = await this.removeBlocksAfter(blockNumber);
247
+
248
+ // Clear the proposed checkpoint if it exists, since its blocks have been pruned
249
+ await this.store.deleteProposedCheckpoint();
250
+
227
251
  await this.l2TipsCache?.refresh();
228
252
  return result;
229
253
  });
@@ -316,9 +340,6 @@ export class ArchiverDataStoreUpdater {
316
340
  this.updatePublishedContractClasses(contractClassLogs, block.number, operation),
317
341
  this.updateDeployedContractInstances(privateLogs, block.number, operation),
318
342
  this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation),
319
- operation === Operation.Store
320
- ? this.storeBroadcastedIndividualFunctions(contractClassLogs, block.number)
321
- : Promise.resolve(true),
322
343
  ])
323
344
  ).every(Boolean);
324
345
  }
@@ -437,67 +458,4 @@ export class ArchiverDataStoreUpdater {
437
458
  }
438
459
  return true;
439
460
  }
440
-
441
- /**
442
- * Stores the functions that were broadcasted individually.
443
- *
444
- * @dev Beware that there is not a delete variant of this, since they are added to contract classes
445
- * and will be deleted as part of the class if needed.
446
- */
447
- private async storeBroadcastedIndividualFunctions(
448
- allLogs: ContractClassLog[],
449
- _blockNum: BlockNumber,
450
- ): Promise<boolean> {
451
- // Filter out private and utility function broadcast events
452
- const privateFnEvents = allLogs
453
- .filter(log => PrivateFunctionBroadcastedEvent.isPrivateFunctionBroadcastedEvent(log))
454
- .map(log => PrivateFunctionBroadcastedEvent.fromLog(log));
455
- const utilityFnEvents = allLogs
456
- .filter(log => UtilityFunctionBroadcastedEvent.isUtilityFunctionBroadcastedEvent(log))
457
- .map(log => UtilityFunctionBroadcastedEvent.fromLog(log));
458
-
459
- // Group all events by contract class id
460
- for (const [classIdString, classEvents] of Object.entries(
461
- groupBy([...privateFnEvents, ...utilityFnEvents], e => e.contractClassId.toString()),
462
- )) {
463
- const contractClassId = Fr.fromHexString(classIdString);
464
- const contractClass = await this.store.getContractClass(contractClassId);
465
- if (!contractClass) {
466
- this.log.warn(`Skipping broadcasted functions as contract class ${contractClassId.toString()} was not found`);
467
- continue;
468
- }
469
-
470
- // Split private and utility functions, and filter out invalid ones
471
- const allFns = classEvents.map(e => e.toFunctionWithMembershipProof());
472
- const privateFns = allFns.filter(
473
- (fn): fn is ExecutablePrivateFunctionWithMembershipProof => 'utilityFunctionsTreeRoot' in fn,
474
- );
475
- const utilityFns = allFns.filter(
476
- (fn): fn is UtilityFunctionWithMembershipProof => 'privateFunctionsArtifactTreeRoot' in fn,
477
- );
478
-
479
- const privateFunctionsWithValidity = await Promise.all(
480
- privateFns.map(async fn => ({ fn, valid: await isValidPrivateFunctionMembershipProof(fn, contractClass) })),
481
- );
482
- const validPrivateFns = privateFunctionsWithValidity.filter(({ valid }) => valid).map(({ fn }) => fn);
483
- const utilityFunctionsWithValidity = await Promise.all(
484
- utilityFns.map(async fn => ({
485
- fn,
486
- valid: await isValidUtilityFunctionMembershipProof(fn, contractClass),
487
- })),
488
- );
489
- const validUtilityFns = utilityFunctionsWithValidity.filter(({ valid }) => valid).map(({ fn }) => fn);
490
- const validFnCount = validPrivateFns.length + validUtilityFns.length;
491
- if (validFnCount !== allFns.length) {
492
- this.log.warn(`Skipping ${allFns.length - validFnCount} invalid functions`);
493
- }
494
-
495
- // Store the functions in the contract class in a single operation
496
- if (validFnCount > 0) {
497
- this.log.verbose(`Storing ${validFnCount} functions for contract class ${contractClassId.toString()}`);
498
- }
499
- await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
500
- }
501
- return true;
502
- }
503
461
  }