@aztec/archiver 0.0.1-commit.8f9871590 → 0.0.1-commit.934299a21

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 (68) hide show
  1. package/dest/archiver.d.ts +5 -2
  2. package/dest/archiver.d.ts.map +1 -1
  3. package/dest/archiver.js +9 -91
  4. package/dest/factory.d.ts +1 -1
  5. package/dest/factory.d.ts.map +1 -1
  6. package/dest/factory.js +5 -5
  7. package/dest/index.d.ts +2 -1
  8. package/dest/index.d.ts.map +1 -1
  9. package/dest/index.js +1 -0
  10. package/dest/l1/bin/retrieve-calldata.js +32 -28
  11. package/dest/l1/calldata_retriever.d.ts +73 -52
  12. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  13. package/dest/l1/calldata_retriever.js +190 -261
  14. package/dest/l1/data_retrieval.d.ts +2 -6
  15. package/dest/l1/data_retrieval.d.ts.map +1 -1
  16. package/dest/l1/data_retrieval.js +6 -11
  17. package/dest/l1/spire_proposer.d.ts +5 -5
  18. package/dest/l1/spire_proposer.d.ts.map +1 -1
  19. package/dest/l1/spire_proposer.js +9 -17
  20. package/dest/modules/data_source_base.d.ts +8 -3
  21. package/dest/modules/data_source_base.d.ts.map +1 -1
  22. package/dest/modules/data_source_base.js +28 -72
  23. package/dest/modules/data_store_updater.d.ts +9 -2
  24. package/dest/modules/data_store_updater.d.ts.map +1 -1
  25. package/dest/modules/data_store_updater.js +40 -19
  26. package/dest/modules/instrumentation.d.ts +15 -2
  27. package/dest/modules/instrumentation.d.ts.map +1 -1
  28. package/dest/modules/instrumentation.js +19 -2
  29. package/dest/modules/l1_synchronizer.d.ts +4 -8
  30. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  31. package/dest/modules/l1_synchronizer.js +14 -9
  32. package/dest/store/block_store.d.ts +18 -14
  33. package/dest/store/block_store.d.ts.map +1 -1
  34. package/dest/store/block_store.js +69 -17
  35. package/dest/store/kv_archiver_store.d.ts +18 -4
  36. package/dest/store/kv_archiver_store.d.ts.map +1 -1
  37. package/dest/store/kv_archiver_store.js +18 -0
  38. package/dest/store/l2_tips_cache.d.ts +19 -0
  39. package/dest/store/l2_tips_cache.d.ts.map +1 -0
  40. package/dest/store/l2_tips_cache.js +89 -0
  41. package/dest/test/fake_l1_state.d.ts +6 -1
  42. package/dest/test/fake_l1_state.d.ts.map +1 -1
  43. package/dest/test/fake_l1_state.js +56 -18
  44. package/dest/test/mock_archiver.d.ts +1 -1
  45. package/dest/test/mock_archiver.d.ts.map +1 -1
  46. package/dest/test/mock_archiver.js +3 -2
  47. package/dest/test/mock_l2_block_source.d.ts +18 -3
  48. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  49. package/dest/test/mock_l2_block_source.js +125 -82
  50. package/package.json +13 -13
  51. package/src/archiver.ts +10 -110
  52. package/src/factory.ts +7 -1
  53. package/src/index.ts +1 -0
  54. package/src/l1/README.md +25 -68
  55. package/src/l1/bin/retrieve-calldata.ts +40 -27
  56. package/src/l1/calldata_retriever.ts +249 -383
  57. package/src/l1/data_retrieval.ts +3 -16
  58. package/src/l1/spire_proposer.ts +7 -15
  59. package/src/modules/data_source_base.ts +53 -92
  60. package/src/modules/data_store_updater.ts +43 -18
  61. package/src/modules/instrumentation.ts +29 -2
  62. package/src/modules/l1_synchronizer.ts +15 -12
  63. package/src/store/block_store.ts +85 -36
  64. package/src/store/kv_archiver_store.ts +35 -3
  65. package/src/store/l2_tips_cache.ts +89 -0
  66. package/src/test/fake_l1_state.ts +75 -17
  67. package/src/test/mock_archiver.ts +3 -2
  68. package/src/test/mock_l2_block_source.ts +158 -78
@@ -157,11 +157,6 @@ export async function retrieveCheckpointsFromRollup(
157
157
  blobClient: BlobClientInterface,
158
158
  searchStartBlock: bigint,
159
159
  searchEndBlock: bigint,
160
- contractAddresses: {
161
- governanceProposerAddress: EthAddress;
162
- slashFactoryAddress?: EthAddress;
163
- slashingProposerAddress: EthAddress;
164
- },
165
160
  instrumentation: ArchiverInstrumentation,
166
161
  logger: Logger = createLogger('archiver'),
167
162
  isHistoricalSync: boolean = false,
@@ -205,7 +200,6 @@ export async function retrieveCheckpointsFromRollup(
205
200
  blobClient,
206
201
  checkpointProposedLogs,
207
202
  rollupConstants,
208
- contractAddresses,
209
203
  instrumentation,
210
204
  logger,
211
205
  isHistoricalSync,
@@ -226,7 +220,6 @@ export async function retrieveCheckpointsFromRollup(
226
220
  * @param blobClient - The blob client client for fetching blob data.
227
221
  * @param logs - CheckpointProposed logs.
228
222
  * @param rollupConstants - The rollup constants (chainId, version, targetCommitteeSize).
229
- * @param contractAddresses - The contract addresses (governanceProposerAddress, slashFactoryAddress, slashingProposerAddress).
230
223
  * @param instrumentation - The archiver instrumentation instance.
231
224
  * @param logger - The logger instance.
232
225
  * @param isHistoricalSync - Whether this is a historical sync.
@@ -239,11 +232,6 @@ async function processCheckpointProposedLogs(
239
232
  blobClient: BlobClientInterface,
240
233
  logs: CheckpointProposedLog[],
241
234
  { chainId, version, targetCommitteeSize }: { chainId: Fr; version: Fr; targetCommitteeSize: number },
242
- contractAddresses: {
243
- governanceProposerAddress: EthAddress;
244
- slashFactoryAddress?: EthAddress;
245
- slashingProposerAddress: EthAddress;
246
- },
247
235
  instrumentation: ArchiverInstrumentation,
248
236
  logger: Logger,
249
237
  isHistoricalSync: boolean,
@@ -255,7 +243,7 @@ async function processCheckpointProposedLogs(
255
243
  targetCommitteeSize,
256
244
  instrumentation,
257
245
  logger,
258
- { ...contractAddresses, rollupAddress: EthAddress.fromString(rollup.address) },
246
+ EthAddress.fromString(rollup.address),
259
247
  );
260
248
 
261
249
  await asyncPool(10, logs, async log => {
@@ -266,10 +254,9 @@ async function processCheckpointProposedLogs(
266
254
 
267
255
  // The value from the event and contract will match only if the checkpoint is in the chain.
268
256
  if (archive.equals(archiveFromChain)) {
269
- // Build expected hashes object (fields may be undefined for backwards compatibility with older events)
270
257
  const expectedHashes = {
271
- attestationsHash: log.args.attestationsHash?.toString(),
272
- payloadDigest: log.args.payloadDigest?.toString(),
258
+ attestationsHash: log.args.attestationsHash.toString() as Hex,
259
+ payloadDigest: log.args.payloadDigest.toString() as Hex,
273
260
  };
274
261
 
275
262
  const checkpoint = await calldataRetriever.getCheckpointFromRollupTx(
@@ -87,17 +87,17 @@ export async function verifyProxyImplementation(
87
87
  /**
88
88
  * Attempts to decode transaction as a Spire Proposer Multicall.
89
89
  * Spire Proposer is a proxy contract that wraps multiple calls.
90
- * Returns the target address and calldata of the wrapped call if validation succeeds and there is a single call.
90
+ * Returns all wrapped calls if validation succeeds (caller handles hash matching to find the propose call).
91
91
  * @param tx - The transaction to decode
92
92
  * @param publicClient - The viem public client for proxy verification
93
93
  * @param logger - Logger instance
94
- * @returns Object with 'to' and 'data' of the wrapped call, or undefined if validation fails
94
+ * @returns Array of wrapped calls with 'to' and 'data', or undefined if not a valid Spire Proposer tx
95
95
  */
96
- export async function getCallFromSpireProposer(
96
+ export async function getCallsFromSpireProposer(
97
97
  tx: Transaction,
98
98
  publicClient: { getStorageAt: (params: { address: Hex; slot: Hex }) => Promise<Hex | undefined> },
99
99
  logger: Logger,
100
- ): Promise<{ to: Hex; data: Hex } | undefined> {
100
+ ): Promise<{ to: Hex; data: Hex }[] | undefined> {
101
101
  const txHash = tx.hash;
102
102
 
103
103
  try {
@@ -141,17 +141,9 @@ export async function getCallFromSpireProposer(
141
141
 
142
142
  const [calls] = spireArgs;
143
143
 
144
- // Validate exactly ONE call (see ./README.md for rationale)
145
- if (calls.length !== 1) {
146
- logger.warn(`Spire Proposer multicall must contain exactly one call (got ${calls.length})`, { txHash });
147
- return undefined;
148
- }
149
-
150
- const call = calls[0];
151
-
152
- // Successfully extracted the single wrapped call
153
- logger.trace(`Decoded Spire Proposer with single call to ${call.target}`, { txHash });
154
- return { to: call.target, data: call.data };
144
+ // Return all wrapped calls (hash matching in the caller determines which is the propose call)
145
+ logger.trace(`Decoded Spire Proposer with ${calls.length} call(s)`, { txHash });
146
+ return calls.map(call => ({ to: call.target, data: call.data }));
155
147
  } catch (err) {
156
148
  // Any decoding error triggers fallback to trace
157
149
  logger.warn(`Failed to decode Spire Proposer: ${err}`, { txHash });
@@ -1,11 +1,12 @@
1
+ import { range } from '@aztec/foundation/array';
1
2
  import { BlockNumber, CheckpointNumber, type EpochNumber, type SlotNumber } from '@aztec/foundation/branded-types';
2
3
  import type { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import type { EthAddress } from '@aztec/foundation/eth-address';
4
5
  import { isDefined } from '@aztec/foundation/types';
5
6
  import type { FunctionSelector } from '@aztec/stdlib/abi';
6
7
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
7
- import { type BlockHash, CheckpointedL2Block, CommitteeAttestation, L2Block, type L2Tips } from '@aztec/stdlib/block';
8
- import { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
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
10
  import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
10
11
  import { type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
11
12
  import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
@@ -17,7 +18,6 @@ import type { BlockHeader, IndexedTxEffect, TxHash, TxReceipt } from '@aztec/std
17
18
  import type { UInt64 } from '@aztec/stdlib/types';
18
19
 
19
20
  import type { ArchiverDataSource } from '../interfaces.js';
20
- import type { CheckpointData } from '../store/block_store.js';
21
21
  import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
22
22
  import type { ValidateCheckpointResult } from './validation.js';
23
23
 
@@ -114,7 +114,7 @@ export abstract class ArchiverDataSourceBase
114
114
  if (!checkpointData) {
115
115
  return undefined;
116
116
  }
117
- return BlockNumber(checkpointData.startBlock + checkpointData.numBlocks - 1);
117
+ return BlockNumber(checkpointData.startBlock + checkpointData.blockCount - 1);
118
118
  }
119
119
 
120
120
  public getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
@@ -129,6 +129,14 @@ export abstract class ArchiverDataSourceBase
129
129
  return this.store.getBlockHeaderByArchive(archive);
130
130
  }
131
131
 
132
+ public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
133
+ return this.store.getBlockData(number);
134
+ }
135
+
136
+ public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
137
+ return this.store.getBlockDataByArchive(archive);
138
+ }
139
+
132
140
  public async getL2Block(number: BlockNumber): Promise<L2Block | undefined> {
133
141
  // If the number provided is -ve, then return the latest block.
134
142
  if (number < 0) {
@@ -223,28 +231,21 @@ export abstract class ArchiverDataSourceBase
223
231
 
224
232
  public async getCheckpoints(checkpointNumber: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
225
233
  const checkpoints = await this.store.getRangeOfCheckpoints(checkpointNumber, limit);
226
- const blocks = (
227
- await Promise.all(checkpoints.map(ch => this.store.getBlocksForCheckpoint(ch.checkpointNumber)))
228
- ).filter(isDefined);
229
-
230
- const fullCheckpoints: PublishedCheckpoint[] = [];
231
- for (let i = 0; i < checkpoints.length; i++) {
232
- const blocksForCheckpoint = blocks[i];
233
- const checkpoint = checkpoints[i];
234
- const fullCheckpoint = new Checkpoint(
235
- checkpoint.archive,
236
- checkpoint.header,
237
- blocksForCheckpoint,
238
- checkpoint.checkpointNumber,
239
- );
240
- const publishedCheckpoint = new PublishedCheckpoint(
241
- fullCheckpoint,
242
- checkpoint.l1,
243
- checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
244
- );
245
- fullCheckpoints.push(publishedCheckpoint);
234
+ return Promise.all(checkpoints.map(ch => this.getPublishedCheckpointFromCheckpointData(ch)));
235
+ }
236
+
237
+ private async getPublishedCheckpointFromCheckpointData(checkpoint: CheckpointData): Promise<PublishedCheckpoint> {
238
+ const blocksForCheckpoint = await this.store.getBlocksForCheckpoint(checkpoint.checkpointNumber);
239
+ if (!blocksForCheckpoint) {
240
+ throw new Error(`Blocks for checkpoint ${checkpoint.checkpointNumber} not found`);
246
241
  }
247
- return fullCheckpoints;
242
+ const fullCheckpoint = new Checkpoint(
243
+ checkpoint.archive,
244
+ checkpoint.header,
245
+ blocksForCheckpoint,
246
+ checkpoint.checkpointNumber,
247
+ );
248
+ return new PublishedCheckpoint(fullCheckpoint, checkpoint.l1, checkpoint.attestations);
248
249
  }
249
250
 
250
251
  public getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
@@ -252,84 +253,44 @@ export abstract class ArchiverDataSourceBase
252
253
  }
253
254
 
254
255
  public async getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]> {
255
- if (!this.l1Constants) {
256
- throw new Error('L1 constants not set');
257
- }
258
-
259
- const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
260
- const blocks: CheckpointedL2Block[] = [];
261
-
262
- // Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
263
- // We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
264
- let checkpoint = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
265
- const slot = (b: CheckpointData) => b.header.slotNumber;
266
- while (checkpoint && slot(checkpoint) >= start) {
267
- if (slot(checkpoint) <= end) {
268
- // push the blocks on backwards
269
- const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
270
- for (let i = endBlock; i >= checkpoint.startBlock; i--) {
271
- const checkpointedBlock = await this.getCheckpointedBlock(BlockNumber(i));
272
- if (checkpointedBlock) {
273
- blocks.push(checkpointedBlock);
274
- }
275
- }
276
- }
277
- checkpoint = await this.store.getCheckpointData(CheckpointNumber(checkpoint.checkpointNumber - 1));
278
- }
279
-
280
- return blocks.reverse();
256
+ const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
257
+ const blocks = await Promise.all(
258
+ checkpointsData.flatMap(checkpoint =>
259
+ range(checkpoint.blockCount, checkpoint.startBlock).map(blockNumber =>
260
+ this.getCheckpointedBlock(BlockNumber(blockNumber)),
261
+ ),
262
+ ),
263
+ );
264
+ return blocks.filter(isDefined);
281
265
  }
282
266
 
283
267
  public async getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
284
- if (!this.l1Constants) {
285
- throw new Error('L1 constants not set');
286
- }
287
-
288
- const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
289
- const blocks: BlockHeader[] = [];
290
-
291
- // Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
292
- // We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
293
- let checkpoint = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
294
- const slot = (b: CheckpointData) => b.header.slotNumber;
295
- while (checkpoint && slot(checkpoint) >= start) {
296
- if (slot(checkpoint) <= end) {
297
- // push the blocks on backwards
298
- const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
299
- for (let i = endBlock; i >= checkpoint.startBlock; i--) {
300
- const block = await this.getBlockHeader(BlockNumber(i));
301
- if (block) {
302
- blocks.push(block);
303
- }
304
- }
305
- }
306
- checkpoint = await this.store.getCheckpointData(CheckpointNumber(checkpoint.checkpointNumber - 1));
307
- }
308
- return blocks.reverse();
268
+ const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
269
+ const blocks = await Promise.all(
270
+ checkpointsData.flatMap(checkpoint =>
271
+ range(checkpoint.blockCount, checkpoint.startBlock).map(blockNumber =>
272
+ this.getBlockHeader(BlockNumber(blockNumber)),
273
+ ),
274
+ ),
275
+ );
276
+ return blocks.filter(isDefined);
309
277
  }
310
278
 
311
279
  public async getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
280
+ const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
281
+ return Promise.all(
282
+ checkpointsData.map(data => this.getPublishedCheckpointFromCheckpointData(data).then(p => p.checkpoint)),
283
+ );
284
+ }
285
+
286
+ /** Returns checkpoint data for all checkpoints whose slot falls within the given epoch. */
287
+ public getCheckpointsDataForEpoch(epochNumber: EpochNumber): Promise<CheckpointData[]> {
312
288
  if (!this.l1Constants) {
313
289
  throw new Error('L1 constants not set');
314
290
  }
315
291
 
316
292
  const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
317
- const checkpoints: Checkpoint[] = [];
318
-
319
- // Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
320
- // We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
321
- let checkpointData = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
322
- const slot = (b: CheckpointData) => b.header.slotNumber;
323
- while (checkpointData && slot(checkpointData) >= start) {
324
- if (slot(checkpointData) <= end) {
325
- // push the checkpoints on backwards
326
- const [checkpoint] = await this.getCheckpoints(checkpointData.checkpointNumber, 1);
327
- checkpoints.push(checkpoint.checkpoint);
328
- }
329
- checkpointData = await this.store.getCheckpointData(CheckpointNumber(checkpointData.checkpointNumber - 1));
330
- }
331
-
332
- return checkpoints.reverse();
293
+ return this.store.getCheckpointDataForSlotRange(start, end);
333
294
  }
334
295
 
335
296
  public async getBlock(number: BlockNumber): Promise<L2Block | undefined> {
@@ -25,6 +25,7 @@ import type { UInt64 } from '@aztec/stdlib/types';
25
25
  import groupBy from 'lodash.groupby';
26
26
 
27
27
  import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
28
+ import type { L2TipsCache } from '../store/l2_tips_cache.js';
28
29
 
29
30
  /** Operation type for contract data updates. */
30
31
  enum Operation {
@@ -44,7 +45,10 @@ type ReconcileCheckpointsResult = {
44
45
  export class ArchiverDataStoreUpdater {
45
46
  private readonly log = createLogger('archiver:store_updater');
46
47
 
47
- constructor(private store: KVArchiverDataStore) {}
48
+ constructor(
49
+ private store: KVArchiverDataStore,
50
+ private l2TipsCache?: L2TipsCache,
51
+ ) {}
48
52
 
49
53
  /**
50
54
  * Adds proposed blocks to the store with contract class/instance extraction from logs.
@@ -56,11 +60,11 @@ export class ArchiverDataStoreUpdater {
56
60
  * @param pendingChainValidationStatus - Optional validation status to set.
57
61
  * @returns True if the operation is successful.
58
62
  */
59
- public addProposedBlocks(
63
+ public async addProposedBlocks(
60
64
  blocks: L2Block[],
61
65
  pendingChainValidationStatus?: ValidateCheckpointResult,
62
66
  ): Promise<boolean> {
63
- return this.store.transactionAsync(async () => {
67
+ const result = await this.store.transactionAsync(async () => {
64
68
  await this.store.addProposedBlocks(blocks);
65
69
 
66
70
  const opResults = await Promise.all([
@@ -72,8 +76,10 @@ export class ArchiverDataStoreUpdater {
72
76
  ...blocks.map(block => this.addContractDataToDb(block)),
73
77
  ]);
74
78
 
79
+ await this.l2TipsCache?.refresh();
75
80
  return opResults.every(Boolean);
76
81
  });
82
+ return result;
77
83
  }
78
84
 
79
85
  /**
@@ -87,11 +93,11 @@ export class ArchiverDataStoreUpdater {
87
93
  * @param pendingChainValidationStatus - Optional validation status to set.
88
94
  * @returns Result with information about any pruned blocks.
89
95
  */
90
- public addCheckpoints(
96
+ public async addCheckpoints(
91
97
  checkpoints: PublishedCheckpoint[],
92
98
  pendingChainValidationStatus?: ValidateCheckpointResult,
93
99
  ): Promise<ReconcileCheckpointsResult> {
94
- return this.store.transactionAsync(async () => {
100
+ const result = await this.store.transactionAsync(async () => {
95
101
  // Before adding checkpoints, check for conflicts with local blocks if any
96
102
  const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
97
103
 
@@ -111,8 +117,10 @@ export class ArchiverDataStoreUpdater {
111
117
  ...newBlocks.map(block => this.addContractDataToDb(block)),
112
118
  ]);
113
119
 
120
+ await this.l2TipsCache?.refresh();
114
121
  return { prunedBlocks, lastAlreadyInsertedBlockNumber };
115
122
  });
123
+ return result;
116
124
  }
117
125
 
118
126
  /**
@@ -197,8 +205,8 @@ export class ArchiverDataStoreUpdater {
197
205
  * @returns The removed blocks.
198
206
  * @throws Error if any block to be removed is checkpointed.
199
207
  */
200
- public removeUncheckpointedBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]> {
201
- return this.store.transactionAsync(async () => {
208
+ public async removeUncheckpointedBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]> {
209
+ const result = await this.store.transactionAsync(async () => {
202
210
  // Verify we're only removing uncheckpointed blocks
203
211
  const lastCheckpointedBlockNumber = await this.store.getCheckpointedL2BlockNumber();
204
212
  if (blockNumber < lastCheckpointedBlockNumber) {
@@ -207,8 +215,11 @@ export class ArchiverDataStoreUpdater {
207
215
  );
208
216
  }
209
217
 
210
- return await this.removeBlocksAfter(blockNumber);
218
+ const result = await this.removeBlocksAfter(blockNumber);
219
+ await this.l2TipsCache?.refresh();
220
+ return result;
211
221
  });
222
+ return result;
212
223
  }
213
224
 
214
225
  /**
@@ -238,17 +249,31 @@ export class ArchiverDataStoreUpdater {
238
249
  * @returns True if the operation is successful.
239
250
  */
240
251
  public async removeCheckpointsAfter(checkpointNumber: CheckpointNumber): Promise<boolean> {
241
- const { blocksRemoved = [] } = await this.store.removeCheckpointsAfter(checkpointNumber);
242
-
243
- const opResults = await Promise.all([
244
- // Prune rolls back to the last proven block, which is by definition valid
245
- this.store.setPendingChainValidationStatus({ valid: true }),
246
- // Remove contract data for all blocks being removed
247
- ...blocksRemoved.map(block => this.removeContractDataFromDb(block)),
248
- this.store.deleteLogs(blocksRemoved),
249
- ]);
252
+ return await this.store.transactionAsync(async () => {
253
+ const { blocksRemoved = [] } = await this.store.removeCheckpointsAfter(checkpointNumber);
254
+
255
+ const opResults = await Promise.all([
256
+ // Prune rolls back to the last proven block, which is by definition valid
257
+ this.store.setPendingChainValidationStatus({ valid: true }),
258
+ // Remove contract data for all blocks being removed
259
+ ...blocksRemoved.map(block => this.removeContractDataFromDb(block)),
260
+ this.store.deleteLogs(blocksRemoved),
261
+ ]);
250
262
 
251
- return opResults.every(Boolean);
263
+ await this.l2TipsCache?.refresh();
264
+ return opResults.every(Boolean);
265
+ });
266
+ }
267
+
268
+ /**
269
+ * Updates the proven checkpoint number and refreshes the L2 tips cache.
270
+ * @param checkpointNumber - The checkpoint number to set as proven.
271
+ */
272
+ public async setProvenCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<void> {
273
+ await this.store.transactionAsync(async () => {
274
+ await this.store.setProvenCheckpointNumber(checkpointNumber);
275
+ await this.l2TipsCache?.refresh();
276
+ });
252
277
  }
253
278
 
254
279
  /** Extracts and stores contract data from a single block. */
@@ -1,5 +1,9 @@
1
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
1
2
  import { createLogger } from '@aztec/foundation/log';
2
3
  import type { L2Block } from '@aztec/stdlib/block';
4
+ import type { CheckpointData } from '@aztec/stdlib/checkpoint';
5
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
6
+ import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
3
7
  import {
4
8
  Attributes,
5
9
  type Gauge,
@@ -17,6 +21,7 @@ export class ArchiverInstrumentation {
17
21
  public readonly tracer: Tracer;
18
22
 
19
23
  private blockHeight: Gauge;
24
+ private checkpointHeight: Gauge;
20
25
  private txCount: UpDownCounter;
21
26
  private l1BlockHeight: Gauge;
22
27
  private proofsSubmittedDelay: Histogram;
@@ -36,6 +41,8 @@ export class ArchiverInstrumentation {
36
41
 
37
42
  private blockProposalTxTargetCount: UpDownCounter;
38
43
 
44
+ private checkpointL1InclusionDelay: Histogram;
45
+
39
46
  private log = createLogger('archiver:instrumentation');
40
47
 
41
48
  private constructor(
@@ -47,6 +54,8 @@ export class ArchiverInstrumentation {
47
54
 
48
55
  this.blockHeight = meter.createGauge(Metrics.ARCHIVER_BLOCK_HEIGHT);
49
56
 
57
+ this.checkpointHeight = meter.createGauge(Metrics.ARCHIVER_CHECKPOINT_HEIGHT);
58
+
50
59
  this.l1BlockHeight = meter.createGauge(Metrics.ARCHIVER_L1_BLOCK_HEIGHT);
51
60
 
52
61
  this.txCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_TOTAL_TXS);
@@ -81,6 +90,8 @@ export class ArchiverInstrumentation {
81
90
  },
82
91
  );
83
92
 
93
+ this.checkpointL1InclusionDelay = meter.createHistogram(Metrics.ARCHIVER_CHECKPOINT_L1_INCLUSION_DELAY);
94
+
84
95
  this.dbMetrics = new LmdbMetrics(
85
96
  meter,
86
97
  {
@@ -105,6 +116,7 @@ export class ArchiverInstrumentation {
105
116
  public processNewBlocks(syncTimePerBlock: number, blocks: L2Block[]) {
106
117
  this.syncDurationPerBlock.record(Math.ceil(syncTimePerBlock));
107
118
  this.blockHeight.record(Math.max(...blocks.map(b => b.number)));
119
+ this.checkpointHeight.record(Math.max(...blocks.map(b => b.checkpointNumber)));
108
120
  this.syncBlockCount.add(blocks.length);
109
121
 
110
122
  for (const block of blocks) {
@@ -127,8 +139,10 @@ export class ArchiverInstrumentation {
127
139
  this.pruneDuration.record(Math.ceil(duration));
128
140
  }
129
141
 
130
- public updateLastProvenBlock(blockNumber: number) {
131
- this.blockHeight.record(blockNumber, { [Attributes.STATUS]: 'proven' });
142
+ public updateLastProvenCheckpoint(checkpoint: CheckpointData) {
143
+ const lastBlockNumberInCheckpoint = checkpoint.startBlock + checkpoint.blockCount - 1;
144
+ this.blockHeight.record(lastBlockNumberInCheckpoint, { [Attributes.STATUS]: 'proven' });
145
+ this.checkpointHeight.record(checkpoint.checkpointNumber, { [Attributes.STATUS]: 'proven' });
132
146
  }
133
147
 
134
148
  public processProofsVerified(logs: { proverId: string; l2BlockNumber: bigint; delay: bigint }[]) {
@@ -154,4 +168,17 @@ export class ArchiverInstrumentation {
154
168
  [Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: usedTrace,
155
169
  });
156
170
  }
171
+
172
+ /**
173
+ * Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
174
+ */
175
+ public processCheckpointL1Timing(data: {
176
+ slotNumber: SlotNumber;
177
+ l1Timestamp: bigint;
178
+ l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>;
179
+ }): void {
180
+ const slotStartTs = getTimestampForSlot(data.slotNumber, data.l1Constants);
181
+ const inclusionDelaySeconds = Number(data.l1Timestamp - slotStartTs);
182
+ this.checkpointL1InclusionDelay.record(inclusionDelaySeconds);
183
+ }
157
184
  }
@@ -1,7 +1,6 @@
1
1
  import type { BlobClientInterface } from '@aztec/blob-client/client';
2
2
  import { EpochCache } from '@aztec/epoch-cache';
3
3
  import { InboxContract, RollupContract } from '@aztec/ethereum/contracts';
4
- import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
5
4
  import type { L1BlockId } from '@aztec/ethereum/l1-types';
6
5
  import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
7
6
  import { maxBigint } from '@aztec/foundation/bigint';
@@ -9,7 +8,6 @@ import { BlockNumber, CheckpointNumber, EpochNumber } from '@aztec/foundation/br
9
8
  import { Buffer32 } from '@aztec/foundation/buffer';
10
9
  import { pick } from '@aztec/foundation/collection';
11
10
  import { Fr } from '@aztec/foundation/curves/bn254';
12
- import { EthAddress } from '@aztec/foundation/eth-address';
13
11
  import { type Logger, createLogger } from '@aztec/foundation/log';
14
12
  import { count } from '@aztec/foundation/string';
15
13
  import { DateProvider, Timer, elapsed } from '@aztec/foundation/timer';
@@ -28,6 +26,7 @@ import {
28
26
  retrievedToPublishedCheckpoint,
29
27
  } from '../l1/data_retrieval.js';
30
28
  import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
29
+ import type { L2TipsCache } from '../store/l2_tips_cache.js';
31
30
  import type { InboxMessage } from '../structs/inbox_message.js';
32
31
  import { ArchiverDataStoreUpdater } from './data_store_updater.js';
33
32
  import type { ArchiverInstrumentation } from './instrumentation.js';
@@ -60,10 +59,6 @@ export class ArchiverL1Synchronizer implements Traceable {
60
59
  private readonly debugClient: ViemPublicDebugClient,
61
60
  private readonly rollup: RollupContract,
62
61
  private readonly inbox: InboxContract,
63
- private readonly l1Addresses: Pick<
64
- L1ContractAddresses,
65
- 'registryAddress' | 'governanceProposerAddress' | 'slashFactoryAddress'
66
- > & { slashingProposerAddress: EthAddress },
67
62
  private readonly store: KVArchiverDataStore,
68
63
  private config: {
69
64
  batchSize: number;
@@ -77,9 +72,10 @@ export class ArchiverL1Synchronizer implements Traceable {
77
72
  private readonly l1Constants: L1RollupConstants & { l1StartBlockHash: Buffer32; genesisArchiveRoot: Fr },
78
73
  private readonly events: ArchiverEmitter,
79
74
  tracer: Tracer,
75
+ l2TipsCache?: L2TipsCache,
80
76
  private readonly log: Logger = createLogger('archiver:l1-sync'),
81
77
  ) {
82
- this.updater = new ArchiverDataStoreUpdater(this.store);
78
+ this.updater = new ArchiverDataStoreUpdater(this.store, l2TipsCache);
83
79
  this.tracer = tracer;
84
80
  }
85
81
 
@@ -550,7 +546,7 @@ export class ArchiverL1Synchronizer implements Traceable {
550
546
  if (provenCheckpointNumber === 0) {
551
547
  const localProvenCheckpointNumber = await this.store.getProvenCheckpointNumber();
552
548
  if (localProvenCheckpointNumber !== provenCheckpointNumber) {
553
- await this.store.setProvenCheckpointNumber(provenCheckpointNumber);
549
+ await this.updater.setProvenCheckpointNumber(provenCheckpointNumber);
554
550
  this.log.info(`Rolled back proven chain to checkpoint ${provenCheckpointNumber}`, { provenCheckpointNumber });
555
551
  }
556
552
  }
@@ -582,13 +578,13 @@ export class ArchiverL1Synchronizer implements Traceable {
582
578
  ) {
583
579
  const localProvenCheckpointNumber = await this.store.getProvenCheckpointNumber();
584
580
  if (localProvenCheckpointNumber !== provenCheckpointNumber) {
585
- await this.store.setProvenCheckpointNumber(provenCheckpointNumber);
581
+ await this.updater.setProvenCheckpointNumber(provenCheckpointNumber);
586
582
  this.log.info(`Updated proven chain to checkpoint ${provenCheckpointNumber}`, { provenCheckpointNumber });
587
583
  const provenSlotNumber = localCheckpointForDestinationProvenCheckpointNumber.header.slotNumber;
588
584
  const provenEpochNumber: EpochNumber = getEpochAtSlot(provenSlotNumber, this.l1Constants);
589
585
  const lastBlockNumberInCheckpoint =
590
586
  localCheckpointForDestinationProvenCheckpointNumber.startBlock +
591
- localCheckpointForDestinationProvenCheckpointNumber.numBlocks -
587
+ localCheckpointForDestinationProvenCheckpointNumber.blockCount -
592
588
  1;
593
589
 
594
590
  this.events.emit(L2BlockSourceEvents.L2BlockProven, {
@@ -597,7 +593,7 @@ export class ArchiverL1Synchronizer implements Traceable {
597
593
  slotNumber: provenSlotNumber,
598
594
  epochNumber: provenEpochNumber,
599
595
  });
600
- this.instrumentation.updateLastProvenBlock(lastBlockNumberInCheckpoint);
596
+ this.instrumentation.updateLastProvenCheckpoint(localCheckpointForDestinationProvenCheckpointNumber);
601
597
  } else {
602
598
  this.log.trace(`Proven checkpoint ${provenCheckpointNumber} already stored.`);
603
599
  }
@@ -706,7 +702,6 @@ export class ArchiverL1Synchronizer implements Traceable {
706
702
  this.blobClient,
707
703
  searchStartBlock, // TODO(palla/reorg): If the L2 reorg was due to an L1 reorg, we need to start search earlier
708
704
  searchEndBlock,
709
- this.l1Addresses,
710
705
  this.instrumentation,
711
706
  this.log,
712
707
  !initialSyncComplete, // isHistoricalSync
@@ -801,6 +796,14 @@ export class ArchiverL1Synchronizer implements Traceable {
801
796
  );
802
797
  }
803
798
 
799
+ for (const published of validCheckpoints) {
800
+ this.instrumentation.processCheckpointL1Timing({
801
+ slotNumber: published.checkpoint.header.slotNumber,
802
+ l1Timestamp: published.l1.timestamp,
803
+ l1Constants: this.l1Constants,
804
+ });
805
+ }
806
+
804
807
  try {
805
808
  const updatedValidationResult =
806
809
  rollupStatus.validationResult === initialValidationResult ? undefined : rollupStatus.validationResult;