@aztec/archiver 0.0.1-commit.ffe5b04ea → 0.0.1-commit.fff30aa

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 (65) hide show
  1. package/dest/archiver.d.ts +3 -5
  2. package/dest/archiver.d.ts.map +1 -1
  3. package/dest/archiver.js +51 -17
  4. package/dest/errors.d.ts +7 -9
  5. package/dest/errors.d.ts.map +1 -1
  6. package/dest/errors.js +9 -14
  7. package/dest/factory.d.ts +4 -5
  8. package/dest/factory.d.ts.map +1 -1
  9. package/dest/factory.js +19 -16
  10. package/dest/l1/data_retrieval.d.ts +3 -6
  11. package/dest/l1/data_retrieval.d.ts.map +1 -1
  12. package/dest/l1/data_retrieval.js +6 -12
  13. package/dest/modules/data_source_base.d.ts +3 -3
  14. package/dest/modules/data_source_base.d.ts.map +1 -1
  15. package/dest/modules/data_source_base.js +1 -1
  16. package/dest/modules/data_store_updater.d.ts +10 -5
  17. package/dest/modules/data_store_updater.d.ts.map +1 -1
  18. package/dest/modules/data_store_updater.js +66 -22
  19. package/dest/modules/instrumentation.d.ts +1 -12
  20. package/dest/modules/instrumentation.d.ts.map +1 -1
  21. package/dest/modules/instrumentation.js +0 -10
  22. package/dest/modules/l1_synchronizer.d.ts +2 -2
  23. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  24. package/dest/modules/l1_synchronizer.js +31 -8
  25. package/dest/store/block_store.d.ts +13 -13
  26. package/dest/store/block_store.d.ts.map +1 -1
  27. package/dest/store/block_store.js +111 -66
  28. package/dest/store/contract_class_store.d.ts +1 -1
  29. package/dest/store/contract_class_store.d.ts.map +1 -1
  30. package/dest/store/contract_class_store.js +6 -2
  31. package/dest/store/contract_instance_store.d.ts +1 -1
  32. package/dest/store/contract_instance_store.d.ts.map +1 -1
  33. package/dest/store/contract_instance_store.js +6 -2
  34. package/dest/store/kv_archiver_store.d.ts +20 -12
  35. package/dest/store/kv_archiver_store.d.ts.map +1 -1
  36. package/dest/store/kv_archiver_store.js +24 -13
  37. package/dest/store/log_store.d.ts +1 -1
  38. package/dest/store/log_store.d.ts.map +1 -1
  39. package/dest/store/log_store.js +48 -10
  40. package/dest/test/fake_l1_state.d.ts +15 -1
  41. package/dest/test/fake_l1_state.d.ts.map +1 -1
  42. package/dest/test/fake_l1_state.js +41 -2
  43. package/dest/test/mock_l2_block_source.d.ts +3 -3
  44. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  45. package/dest/test/mock_l2_block_source.js +4 -4
  46. package/dest/test/noop_l1_archiver.d.ts +4 -1
  47. package/dest/test/noop_l1_archiver.d.ts.map +1 -1
  48. package/dest/test/noop_l1_archiver.js +5 -1
  49. package/package.json +13 -13
  50. package/src/archiver.ts +53 -18
  51. package/src/errors.ts +10 -24
  52. package/src/factory.ts +20 -13
  53. package/src/l1/data_retrieval.ts +9 -17
  54. package/src/modules/data_source_base.ts +3 -3
  55. package/src/modules/data_store_updater.ts +75 -25
  56. package/src/modules/instrumentation.ts +0 -20
  57. package/src/modules/l1_synchronizer.ts +34 -10
  58. package/src/store/block_store.ts +134 -74
  59. package/src/store/contract_class_store.ts +7 -3
  60. package/src/store/contract_instance_store.ts +8 -5
  61. package/src/store/kv_archiver_store.ts +31 -17
  62. package/src/store/log_store.ts +66 -12
  63. package/src/test/fake_l1_state.ts +50 -4
  64. package/src/test/mock_l2_block_source.ts +9 -3
  65. package/src/test/noop_l1_archiver.ts +7 -1
package/src/errors.ts CHANGED
@@ -6,24 +6,9 @@ export class NoBlobBodiesFoundError extends Error {
6
6
  }
7
7
  }
8
8
 
9
- export class InitialBlockNumberNotSequentialError extends Error {
10
- constructor(
11
- public readonly newBlockNumber: number,
12
- public readonly previousBlockNumber: number | undefined,
13
- ) {
14
- super(
15
- `Cannot insert new block ${newBlockNumber} given previous block number in store is ${
16
- previousBlockNumber ?? 'undefined'
17
- }`,
18
- );
19
- }
20
- }
21
-
22
9
  export class BlockNumberNotSequentialError extends Error {
23
10
  constructor(newBlockNumber: number, previous: number | undefined) {
24
- super(
25
- `Cannot insert new block ${newBlockNumber} given previous block number in batch is ${previous ?? 'undefined'}`,
26
- );
11
+ super(`Cannot insert new block ${newBlockNumber} given previous block number is ${previous ?? 'undefined'}`);
27
12
  }
28
13
  }
29
14
 
@@ -48,14 +33,6 @@ export class CheckpointNumberNotSequentialError extends Error {
48
33
  }
49
34
  }
50
35
 
51
- export class CheckpointNumberNotConsistentError extends Error {
52
- constructor(newCheckpointNumber: number, previous: number | undefined) {
53
- super(
54
- `Cannot insert block for new checkpoint ${newCheckpointNumber} given previous block was checkpoint ${previous ?? 'undefined'}`,
55
- );
56
- }
57
- }
58
-
59
36
  export class BlockIndexNotSequentialError extends Error {
60
37
  constructor(newBlockIndex: number, previousBlockIndex: number | undefined) {
61
38
  super(
@@ -89,6 +66,15 @@ export class BlockNotFoundError extends Error {
89
66
  }
90
67
  }
91
68
 
69
+ /** Thrown when a proposed block matches a block that was already checkpointed. This is expected for late proposals. */
70
+ export class BlockAlreadyCheckpointedError extends Error {
71
+ constructor(public readonly blockNumber: number) {
72
+ super(`Block ${blockNumber} has already been checkpointed with the same content`);
73
+ this.name = 'BlockAlreadyCheckpointedError';
74
+ }
75
+ }
76
+
77
+ /** Thrown when a proposed block conflicts with an already checkpointed block (different content). */
92
78
  export class CannotOverwriteCheckpointedBlockError extends Error {
93
79
  constructor(
94
80
  public readonly blockNumber: number,
package/src/factory.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { EpochCache } from '@aztec/epoch-cache';
2
2
  import { createEthereumChain } from '@aztec/ethereum/chain';
3
+ import { makeL1HttpTransport } from '@aztec/ethereum/client';
3
4
  import { InboxContract, RollupContract } from '@aztec/ethereum/contracts';
4
5
  import type { ViemPublicDebugClient } from '@aztec/ethereum/types';
5
6
  import { BlockNumber } from '@aztec/foundation/branded-types';
@@ -7,18 +8,17 @@ import { Buffer32 } from '@aztec/foundation/buffer';
7
8
  import { merge } from '@aztec/foundation/collection';
8
9
  import { Fr } from '@aztec/foundation/curves/bn254';
9
10
  import { DateProvider } from '@aztec/foundation/timer';
11
+ import type { DataStoreConfig } from '@aztec/kv-store/config';
10
12
  import { createStore } from '@aztec/kv-store/lmdb-v2';
11
13
  import { protocolContractNames } from '@aztec/protocol-contracts';
12
14
  import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
13
15
  import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
14
16
  import type { ArchiverEmitter } from '@aztec/stdlib/block';
15
- import { type ContractClassPublic, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
16
- import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
17
- import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
17
+ import { type ContractClassPublicWithCommitment, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
18
18
  import { getTelemetryClient } from '@aztec/telemetry-client';
19
19
 
20
20
  import { EventEmitter } from 'events';
21
- import { createPublicClient, fallback, http } from 'viem';
21
+ import { createPublicClient } from 'viem';
22
22
 
23
23
  import { Archiver, type ArchiverDeps } from './archiver.js';
24
24
  import { type ArchiverConfig, mapArchiverConfig } from './config.js';
@@ -32,14 +32,13 @@ export const ARCHIVER_STORE_NAME = 'archiver';
32
32
  /** Creates an archiver store. */
33
33
  export async function createArchiverStore(
34
34
  userConfig: Pick<ArchiverConfig, 'archiverStoreMapSizeKb' | 'maxLogs'> & DataStoreConfig,
35
- l1Constants: Pick<L1RollupConstants, 'epochDuration'>,
36
35
  ) {
37
36
  const config = {
38
37
  ...userConfig,
39
38
  dataStoreMapSizeKb: userConfig.archiverStoreMapSizeKb ?? userConfig.dataStoreMapSizeKb,
40
39
  };
41
40
  const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config);
42
- return new KVArchiverDataStore(store, config.maxLogs, l1Constants);
41
+ return new KVArchiverDataStore(store, config.maxLogs);
43
42
  }
44
43
 
45
44
  /**
@@ -54,14 +53,15 @@ export async function createArchiver(
54
53
  deps: ArchiverDeps,
55
54
  opts: { blockUntilSync: boolean } = { blockUntilSync: true },
56
55
  ): Promise<Archiver> {
57
- const archiverStore = await createArchiverStore(config, { epochDuration: config.aztecEpochDuration });
56
+ const archiverStore = await createArchiverStore(config);
58
57
  await registerProtocolContracts(archiverStore);
59
58
 
60
59
  // Create Ethereum clients
61
60
  const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
61
+ const httpTimeout = config.l1HttpTimeoutMS;
62
62
  const publicClient = createPublicClient({
63
63
  chain: chain.chainInfo,
64
- transport: fallback(config.l1RpcUrls.map(url => http(url, { batch: false }))),
64
+ transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: httpTimeout }),
65
65
  pollingInterval: config.viemPollingIntervalMS,
66
66
  });
67
67
 
@@ -69,7 +69,7 @@ export async function createArchiver(
69
69
  const debugRpcUrls = config.l1DebugRpcUrls.length > 0 ? config.l1DebugRpcUrls : config.l1RpcUrls;
70
70
  const debugClient = createPublicClient({
71
71
  chain: chain.chainInfo,
72
- transport: fallback(debugRpcUrls.map(url => http(url, { batch: false }))),
72
+ transport: makeL1HttpTransport(debugRpcUrls, { timeout: httpTimeout }),
73
73
  pollingInterval: config.viemPollingIntervalMS,
74
74
  }) as ViemPublicDebugClient;
75
75
 
@@ -173,14 +173,22 @@ export async function createArchiver(
173
173
  return archiver;
174
174
  }
175
175
 
176
- /** Registers protocol contracts in the archiver store. */
176
+ /** Registers protocol contracts in the archiver store. Idempotent — skips contracts that already exist (e.g. on node restart). */
177
177
  export async function registerProtocolContracts(store: KVArchiverDataStore) {
178
178
  const blockNumber = 0;
179
179
  for (const name of protocolContractNames) {
180
180
  const provider = new BundledProtocolContractsProvider();
181
181
  const contract = await provider.getProtocolContractArtifact(name);
182
- const contractClassPublic: ContractClassPublic = {
182
+
183
+ // Skip if already registered (happens on node restart with a persisted store).
184
+ if (await store.getContractClass(contract.contractClass.id)) {
185
+ continue;
186
+ }
187
+
188
+ const publicBytecodeCommitment = await computePublicBytecodeCommitment(contract.contractClass.packedBytecode);
189
+ const contractClassPublic: ContractClassPublicWithCommitment = {
183
190
  ...contract.contractClass,
191
+ publicBytecodeCommitment,
184
192
  privateFunctions: [],
185
193
  utilityFunctions: [],
186
194
  };
@@ -190,8 +198,7 @@ export async function registerProtocolContracts(store: KVArchiverDataStore) {
190
198
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
191
199
 
192
200
  await store.registerContractFunctionSignatures(publicFunctionSignatures);
193
- const bytecodeCommitment = await computePublicBytecodeCommitment(contractClassPublic.packedBytecode);
194
- await store.addContractClasses([contractClassPublic], [bytecodeCommitment], BlockNumber(blockNumber));
201
+ await store.addContractClasses([contractClassPublic], BlockNumber(blockNumber));
195
202
  await store.addContractInstances([contract.instance], BlockNumber(blockNumber));
196
203
  }
197
204
  }
@@ -265,9 +265,6 @@ async function processCheckpointProposedLogs(
265
265
  checkpointNumber,
266
266
  expectedHashes,
267
267
  );
268
- const { timestamp, parentBeaconBlockRoot } = await getL1Block(publicClient, log.l1BlockNumber);
269
- const l1 = new L1PublishedData(log.l1BlockNumber, timestamp, log.l1BlockHash.toString());
270
-
271
268
  const checkpointBlobData = await getCheckpointBlobDataFromBlobs(
272
269
  blobClient,
273
270
  checkpoint.blockHash,
@@ -275,8 +272,12 @@ async function processCheckpointProposedLogs(
275
272
  checkpointNumber,
276
273
  logger,
277
274
  isHistoricalSync,
278
- parentBeaconBlockRoot,
279
- timestamp,
275
+ );
276
+
277
+ const l1 = new L1PublishedData(
278
+ log.l1BlockNumber,
279
+ await getL1BlockTime(publicClient, log.l1BlockNumber),
280
+ log.l1BlockHash.toString(),
280
281
  );
281
282
 
282
283
  retrievedCheckpoints.push({ ...checkpoint, checkpointBlobData, l1, chainId, version });
@@ -297,12 +298,9 @@ async function processCheckpointProposedLogs(
297
298
  return retrievedCheckpoints;
298
299
  }
299
300
 
300
- export async function getL1Block(
301
- publicClient: ViemPublicClient,
302
- blockNumber: bigint,
303
- ): Promise<{ timestamp: bigint; parentBeaconBlockRoot: string | undefined }> {
301
+ export async function getL1BlockTime(publicClient: ViemPublicClient, blockNumber: bigint): Promise<bigint> {
304
302
  const block = await publicClient.getBlock({ blockNumber, includeTransactions: false });
305
- return { timestamp: block.timestamp, parentBeaconBlockRoot: block.parentBeaconBlockRoot };
303
+ return block.timestamp;
306
304
  }
307
305
 
308
306
  export async function getCheckpointBlobDataFromBlobs(
@@ -312,14 +310,8 @@ export async function getCheckpointBlobDataFromBlobs(
312
310
  checkpointNumber: CheckpointNumber,
313
311
  logger: Logger,
314
312
  isHistoricalSync: boolean,
315
- parentBeaconBlockRoot?: string,
316
- l1BlockTimestamp?: bigint,
317
313
  ): Promise<CheckpointBlobData> {
318
- const blobBodies = await blobClient.getBlobSidecar(blockHash, blobHashes, {
319
- isHistoricalSync,
320
- parentBeaconBlockRoot,
321
- l1BlockTimestamp,
322
- });
314
+ const blobBodies = await blobClient.getBlobSidecar(blockHash, blobHashes, { isHistoricalSync });
323
315
  if (blobBodies.length === 0) {
324
316
  throw new NoBlobBodiesFoundError(checkpointNumber);
325
317
  }
@@ -46,9 +46,9 @@ export abstract class ArchiverDataSourceBase
46
46
 
47
47
  abstract getL2Tips(): Promise<L2Tips>;
48
48
 
49
- abstract getL2SlotNumber(): Promise<SlotNumber | undefined>;
49
+ abstract getSyncedL2SlotNumber(): Promise<SlotNumber | undefined>;
50
50
 
51
- abstract getL2EpochNumber(): Promise<EpochNumber | undefined>;
51
+ abstract getSyncedL2EpochNumber(): Promise<EpochNumber | undefined>;
52
52
 
53
53
  abstract isEpochComplete(epochNumber: EpochNumber): Promise<boolean>;
54
54
 
@@ -154,7 +154,7 @@ export abstract class ArchiverDataSourceBase
154
154
  }
155
155
 
156
156
  public getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
157
- return this.store.getSettledTxReceipt(txHash);
157
+ return this.store.getSettledTxReceipt(txHash, this.l1Constants);
158
158
  }
159
159
 
160
160
  public isPendingChainInvalid(): Promise<boolean> {
@@ -1,4 +1,5 @@
1
1
  import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
2
+ import { filterAsync } from '@aztec/foundation/collection';
2
3
  import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import { createLogger } from '@aztec/foundation/log';
4
5
  import {
@@ -13,9 +14,11 @@ import {
13
14
  import type { L2Block, ValidateCheckpointResult } from '@aztec/stdlib/block';
14
15
  import { type PublishedCheckpoint, validateCheckpoint } from '@aztec/stdlib/checkpoint';
15
16
  import {
17
+ type ContractClassPublicWithCommitment,
16
18
  type ExecutablePrivateFunctionWithMembershipProof,
17
19
  type UtilityFunctionWithMembershipProof,
18
- computePublicBytecodeCommitment,
20
+ computeContractAddressFromInstance,
21
+ computeContractClassId,
19
22
  isValidPrivateFunctionMembershipProof,
20
23
  isValidUtilityFunctionMembershipProof,
21
24
  } from '@aztec/stdlib/contract';
@@ -52,29 +55,29 @@ export class ArchiverDataStoreUpdater {
52
55
  ) {}
53
56
 
54
57
  /**
55
- * Adds proposed blocks to the store with contract class/instance extraction from logs.
56
- * These are uncheckpointed blocks that have been proposed by the sequencer but not yet included in a checkpoint on L1.
58
+ * Adds a proposed block to the store with contract class/instance extraction from logs.
59
+ * This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
57
60
  * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
58
61
  * and individually broadcasted functions from the block logs.
59
62
  *
60
- * @param blocks - The proposed L2 blocks to add.
63
+ * @param block - The proposed L2 block to add.
61
64
  * @param pendingChainValidationStatus - Optional validation status to set.
62
65
  * @returns True if the operation is successful.
63
66
  */
64
- public async addProposedBlocks(
65
- blocks: L2Block[],
67
+ public async addProposedBlock(
68
+ block: L2Block,
66
69
  pendingChainValidationStatus?: ValidateCheckpointResult,
67
70
  ): Promise<boolean> {
68
71
  const result = await this.store.transactionAsync(async () => {
69
- await this.store.addProposedBlocks(blocks);
72
+ await this.store.addProposedBlock(block);
70
73
 
71
74
  const opResults = await Promise.all([
72
75
  // Update the pending chain validation status if provided
73
76
  pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
74
- // Add any logs emitted during the retrieved blocks
75
- this.store.addLogs(blocks),
76
- // Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
77
- ...blocks.map(block => this.addContractDataToDb(block)),
77
+ // Add any logs emitted during the retrieved block
78
+ this.store.addLogs([block]),
79
+ // Unroll all logs emitted during the retrieved block and extract any contract classes and instances from it
80
+ this.addContractDataToDb(block),
78
81
  ]);
79
82
 
80
83
  await this.l2TipsCache?.refresh();
@@ -108,7 +111,7 @@ export class ArchiverDataStoreUpdater {
108
111
 
109
112
  await this.store.addCheckpoints(checkpoints);
110
113
 
111
- // Filter out blocks that were already inserted via addProposedBlocks() to avoid duplicating logs/contract data
114
+ // Filter out blocks that were already inserted via addProposedBlock() to avoid duplicating logs/contract data
112
115
  const newBlocks = checkpoints
113
116
  .flatMap((ch: PublishedCheckpoint) => ch.checkpoint.blocks)
114
117
  .filter(b => lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
@@ -178,7 +181,7 @@ export class ArchiverDataStoreUpdater {
178
181
  this.log.verbose(`Block number ${blockNumber} already inserted and matches checkpoint`, blockInfos);
179
182
  lastAlreadyInsertedBlockNumber = blockNumber;
180
183
  } else {
181
- this.log.warn(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
184
+ this.log.info(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
182
185
  const prunedBlocks = await this.removeBlocksAfter(BlockNumber(blockNumber - 1));
183
186
  return { prunedBlocks, lastAlreadyInsertedBlockNumber };
184
187
  }
@@ -281,6 +284,17 @@ export class ArchiverDataStoreUpdater {
281
284
  });
282
285
  }
283
286
 
287
+ /**
288
+ * Updates the finalized checkpoint number and refreshes the L2 tips cache.
289
+ * @param checkpointNumber - The checkpoint number to set as finalized.
290
+ */
291
+ public async setFinalizedCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<void> {
292
+ await this.store.transactionAsync(async () => {
293
+ await this.store.setFinalizedCheckpointNumber(checkpointNumber);
294
+ await this.l2TipsCache?.refresh();
295
+ });
296
+ }
297
+
284
298
  /** Extracts and stores contract data from a single block. */
285
299
  private addContractDataToDb(block: L2Block): Promise<boolean> {
286
300
  return this.updateContractDataOnDb(block, Operation.Store);
@@ -321,18 +335,37 @@ export class ArchiverDataStoreUpdater {
321
335
  .filter(log => ContractClassPublishedEvent.isContractClassPublishedEvent(log))
322
336
  .map(log => ContractClassPublishedEvent.fromLog(log));
323
337
 
324
- const contractClasses = await Promise.all(contractClassPublishedEvents.map(e => e.toContractClassPublic()));
325
- if (contractClasses.length > 0) {
326
- contractClasses.forEach(c => this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
327
- if (operation == Operation.Store) {
328
- // TODO: Will probably want to create some worker threads to compute these bytecode commitments as they are expensive
329
- const commitments = await Promise.all(
330
- contractClasses.map(c => computePublicBytecodeCommitment(c.packedBytecode)),
331
- );
332
- return await this.store.addContractClasses(contractClasses, commitments, blockNum);
333
- } else if (operation == Operation.Delete) {
338
+ if (operation == Operation.Delete) {
339
+ const contractClasses = contractClassPublishedEvents.map(e => e.toContractClassPublic());
340
+ if (contractClasses.length > 0) {
341
+ contractClasses.forEach(c => this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
334
342
  return await this.store.deleteContractClasses(contractClasses, blockNum);
335
343
  }
344
+ return true;
345
+ }
346
+
347
+ // Compute bytecode commitments and validate class IDs in a single pass.
348
+ const contractClasses: ContractClassPublicWithCommitment[] = [];
349
+ for (const event of contractClassPublishedEvents) {
350
+ const contractClass = await event.toContractClassPublicWithBytecodeCommitment();
351
+ const computedClassId = await computeContractClassId({
352
+ artifactHash: contractClass.artifactHash,
353
+ privateFunctionsRoot: contractClass.privateFunctionsRoot,
354
+ publicBytecodeCommitment: contractClass.publicBytecodeCommitment,
355
+ });
356
+ if (!computedClassId.equals(contractClass.id)) {
357
+ this.log.warn(
358
+ `Skipping contract class with mismatched id at block ${blockNum}. Claimed ${contractClass.id}, computed ${computedClassId}`,
359
+ { blockNum, contractClassId: event.contractClassId.toString() },
360
+ );
361
+ continue;
362
+ }
363
+ contractClasses.push(contractClass);
364
+ }
365
+
366
+ if (contractClasses.length > 0) {
367
+ contractClasses.forEach(c => this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
368
+ return await this.store.addContractClasses(contractClasses, blockNum);
336
369
  }
337
370
  return true;
338
371
  }
@@ -345,10 +378,27 @@ export class ArchiverDataStoreUpdater {
345
378
  blockNum: BlockNumber,
346
379
  operation: Operation,
347
380
  ): Promise<boolean> {
348
- const contractInstances = allLogs
381
+ const allInstances = allLogs
349
382
  .filter(log => ContractInstancePublishedEvent.isContractInstancePublishedEvent(log))
350
383
  .map(log => ContractInstancePublishedEvent.fromLog(log))
351
384
  .map(e => e.toContractInstance());
385
+
386
+ // Verify that each instance's address matches the one derived from its fields if we're adding
387
+ const contractInstances =
388
+ operation === Operation.Delete
389
+ ? allInstances
390
+ : await filterAsync(allInstances, async instance => {
391
+ const computedAddress = await computeContractAddressFromInstance(instance);
392
+ if (!computedAddress.equals(instance.address)) {
393
+ this.log.warn(
394
+ `Found contract instance with mismatched address at block ${blockNum}. Claimed ${instance.address} but computed ${computedAddress}.`,
395
+ { instanceAddress: instance.address.toString(), computedAddress: computedAddress.toString(), blockNum },
396
+ );
397
+ return false;
398
+ }
399
+ return true;
400
+ });
401
+
352
402
  if (contractInstances.length > 0) {
353
403
  contractInstances.forEach(c =>
354
404
  this.log.verbose(`${Operation[operation]} contract instance at ${c.address.toString()}`),
@@ -446,7 +496,7 @@ export class ArchiverDataStoreUpdater {
446
496
  if (validFnCount > 0) {
447
497
  this.log.verbose(`Storing ${validFnCount} functions for contract class ${contractClassId.toString()}`);
448
498
  }
449
- return await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
499
+ await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
450
500
  }
451
501
  return true;
452
502
  }
@@ -1,9 +1,6 @@
1
- import type { SlotNumber } from '@aztec/foundation/branded-types';
2
1
  import { createLogger } from '@aztec/foundation/log';
3
2
  import type { L2Block } from '@aztec/stdlib/block';
4
3
  import type { CheckpointData } from '@aztec/stdlib/checkpoint';
5
- import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
6
- import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
7
4
  import {
8
5
  Attributes,
9
6
  type Gauge,
@@ -41,8 +38,6 @@ export class ArchiverInstrumentation {
41
38
 
42
39
  private blockProposalTxTargetCount: UpDownCounter;
43
40
 
44
- private checkpointL1InclusionDelay: Histogram;
45
-
46
41
  private log = createLogger('archiver:instrumentation');
47
42
 
48
43
  private constructor(
@@ -90,8 +85,6 @@ export class ArchiverInstrumentation {
90
85
  },
91
86
  );
92
87
 
93
- this.checkpointL1InclusionDelay = meter.createHistogram(Metrics.ARCHIVER_CHECKPOINT_L1_INCLUSION_DELAY);
94
-
95
88
  this.dbMetrics = new LmdbMetrics(
96
89
  meter,
97
90
  {
@@ -168,17 +161,4 @@ export class ArchiverInstrumentation {
168
161
  [Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: usedTrace,
169
162
  });
170
163
  }
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
- }
184
164
  }
@@ -72,7 +72,6 @@ export class ArchiverL1Synchronizer implements Traceable {
72
72
  private readonly l1Constants: L1RollupConstants & {
73
73
  l1StartBlockHash: Buffer32;
74
74
  genesisArchiveRoot: Fr;
75
- rollupManaLimit?: number;
76
75
  },
77
76
  private readonly events: ArchiverEmitter,
78
77
  tracer: Tracer,
@@ -217,6 +216,9 @@ export class ArchiverL1Synchronizer implements Traceable {
217
216
  this.instrumentation.updateL1BlockHeight(currentL1BlockNumber);
218
217
  }
219
218
 
219
+ // Update the finalized L2 checkpoint based on L1 finality.
220
+ await this.updateFinalizedCheckpoint();
221
+
220
222
  // After syncing has completed, update the current l1 block number and timestamp,
221
223
  // otherwise we risk announcing to the world that we've synced to a given point,
222
224
  // but the corresponding blocks have not been processed (see #12631).
@@ -232,6 +234,36 @@ export class ArchiverL1Synchronizer implements Traceable {
232
234
  });
233
235
  }
234
236
 
237
+ /** Query L1 for its finalized block and update the finalized checkpoint accordingly. */
238
+ private async updateFinalizedCheckpoint(): Promise<void> {
239
+ try {
240
+ const finalizedL1Block = await this.publicClient.getBlock({ blockTag: 'finalized', includeTransactions: false });
241
+ const finalizedL1BlockNumber = finalizedL1Block.number;
242
+ const finalizedCheckpointNumber = await this.rollup.getProvenCheckpointNumber({
243
+ blockNumber: finalizedL1BlockNumber,
244
+ });
245
+ const localFinalizedCheckpointNumber = await this.store.getFinalizedCheckpointNumber();
246
+ if (localFinalizedCheckpointNumber !== finalizedCheckpointNumber) {
247
+ await this.updater.setFinalizedCheckpointNumber(finalizedCheckpointNumber);
248
+ const finalizedL2BlockNumber = await this.store.getFinalizedL2BlockNumber();
249
+ this.log.info(
250
+ `Updated finalized chain to checkpoint ${finalizedCheckpointNumber} (L2 block ${finalizedL2BlockNumber})`,
251
+ {
252
+ finalizedCheckpointNumber,
253
+ previousFinalizedCheckpointNumber: localFinalizedCheckpointNumber,
254
+ finalizedL2BlockNumber,
255
+ finalizedL1BlockNumber,
256
+ },
257
+ );
258
+ }
259
+ } catch (err: any) {
260
+ // The rollup contract may not exist at the finalized L1 block right after deployment.
261
+ if (!err?.message?.includes('returned no data')) {
262
+ this.log.warn(`Failed to update finalized checkpoint: ${err}`);
263
+ }
264
+ }
265
+ }
266
+
235
267
  /** Prune all proposed local blocks that should have been checkpointed by now. */
236
268
  private async pruneUncheckpointedBlocks(currentL1Timestamp: bigint) {
237
269
  const [lastCheckpointedBlockNumber, lastProposedBlockNumber] = await Promise.all([
@@ -802,14 +834,6 @@ export class ArchiverL1Synchronizer implements Traceable {
802
834
  );
803
835
  }
804
836
 
805
- for (const published of validCheckpoints) {
806
- this.instrumentation.processCheckpointL1Timing({
807
- slotNumber: published.checkpoint.header.slotNumber,
808
- l1Timestamp: published.l1.timestamp,
809
- l1Constants: this.l1Constants,
810
- });
811
- }
812
-
813
837
  try {
814
838
  const updatedValidationResult =
815
839
  rollupStatus.validationResult === initialValidationResult ? undefined : rollupStatus.validationResult;
@@ -828,7 +852,7 @@ export class ArchiverL1Synchronizer implements Traceable {
828
852
  const prunedCheckpointNumber = result.prunedBlocks[0].checkpointNumber;
829
853
  const prunedSlotNumber = result.prunedBlocks[0].header.globalVariables.slotNumber;
830
854
 
831
- this.log.warn(
855
+ this.log.info(
832
856
  `Pruned ${result.prunedBlocks.length} mismatching blocks for checkpoint ${prunedCheckpointNumber}`,
833
857
  { prunedBlocks: result.prunedBlocks.map(b => b.toBlockInfo()), prunedSlotNumber, prunedCheckpointNumber },
834
858
  );