@aztec/archiver 4.0.0-devnet.2-patch.4 → 4.0.0-devnet.3-patch.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/dest/archiver.d.ts +3 -3
  2. package/dest/archiver.d.ts.map +1 -1
  3. package/dest/archiver.js +67 -22
  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 +3 -4
  8. package/dest/factory.d.ts.map +1 -1
  9. package/dest/factory.js +25 -23
  10. package/dest/l1/bin/retrieve-calldata.js +32 -28
  11. package/dest/l1/calldata_retriever.d.ts +70 -53
  12. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  13. package/dest/l1/calldata_retriever.js +178 -260
  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 +3 -3
  21. package/dest/modules/data_source_base.d.ts.map +1 -1
  22. package/dest/modules/data_source_base.js +1 -1
  23. package/dest/modules/data_store_updater.d.ts +15 -7
  24. package/dest/modules/data_store_updater.d.ts.map +1 -1
  25. package/dest/modules/data_store_updater.js +75 -23
  26. package/dest/modules/l1_synchronizer.d.ts +3 -7
  27. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  28. package/dest/modules/l1_synchronizer.js +36 -6
  29. package/dest/store/block_store.d.ts +13 -13
  30. package/dest/store/block_store.d.ts.map +1 -1
  31. package/dest/store/block_store.js +111 -66
  32. package/dest/store/contract_class_store.d.ts +1 -1
  33. package/dest/store/contract_class_store.d.ts.map +1 -1
  34. package/dest/store/contract_class_store.js +6 -2
  35. package/dest/store/contract_instance_store.d.ts +1 -1
  36. package/dest/store/contract_instance_store.d.ts.map +1 -1
  37. package/dest/store/contract_instance_store.js +6 -2
  38. package/dest/store/kv_archiver_store.d.ts +20 -12
  39. package/dest/store/kv_archiver_store.d.ts.map +1 -1
  40. package/dest/store/kv_archiver_store.js +24 -13
  41. package/dest/store/log_store.d.ts +1 -1
  42. package/dest/store/log_store.d.ts.map +1 -1
  43. package/dest/store/log_store.js +48 -10
  44. package/dest/store/message_store.js +1 -1
  45. package/dest/test/fake_l1_state.d.ts +17 -1
  46. package/dest/test/fake_l1_state.d.ts.map +1 -1
  47. package/dest/test/fake_l1_state.js +83 -12
  48. package/dest/test/mock_l2_block_source.d.ts +4 -3
  49. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  50. package/dest/test/mock_l2_block_source.js +7 -4
  51. package/dest/test/mock_structs.d.ts +4 -1
  52. package/dest/test/mock_structs.d.ts.map +1 -1
  53. package/dest/test/mock_structs.js +13 -1
  54. package/dest/test/noop_l1_archiver.d.ts +4 -1
  55. package/dest/test/noop_l1_archiver.d.ts.map +1 -1
  56. package/dest/test/noop_l1_archiver.js +5 -1
  57. package/package.json +13 -13
  58. package/src/archiver.ts +80 -22
  59. package/src/errors.ts +10 -24
  60. package/src/factory.ts +22 -13
  61. package/src/l1/README.md +25 -68
  62. package/src/l1/bin/retrieve-calldata.ts +40 -27
  63. package/src/l1/calldata_retriever.ts +231 -383
  64. package/src/l1/data_retrieval.ts +3 -16
  65. package/src/l1/spire_proposer.ts +7 -15
  66. package/src/modules/data_source_base.ts +3 -3
  67. package/src/modules/data_store_updater.ts +81 -26
  68. package/src/modules/l1_synchronizer.ts +41 -10
  69. package/src/store/block_store.ts +134 -74
  70. package/src/store/contract_class_store.ts +7 -3
  71. package/src/store/contract_instance_store.ts +8 -5
  72. package/src/store/kv_archiver_store.ts +31 -17
  73. package/src/store/log_store.ts +66 -12
  74. package/src/store/message_store.ts +1 -1
  75. package/src/test/fake_l1_state.ts +110 -14
  76. package/src/test/mock_l2_block_source.ts +15 -3
  77. package/src/test/mock_structs.ts +20 -6
  78. package/src/test/noop_l1_archiver.ts +7 -1
@@ -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 });
@@ -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 {
@@ -11,11 +12,13 @@ import {
11
12
  ContractInstanceUpdatedEvent,
12
13
  } from '@aztec/protocol-contracts/instance-registry';
13
14
  import type { L2Block, ValidateCheckpointResult } from '@aztec/stdlib/block';
14
- import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
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';
@@ -48,32 +51,33 @@ export class ArchiverDataStoreUpdater {
48
51
  constructor(
49
52
  private store: KVArchiverDataStore,
50
53
  private l2TipsCache?: L2TipsCache,
54
+ private opts: { rollupManaLimit?: number } = {},
51
55
  ) {}
52
56
 
53
57
  /**
54
- * Adds proposed blocks to the store with contract class/instance extraction from logs.
55
- * 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.
56
60
  * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
57
61
  * and individually broadcasted functions from the block logs.
58
62
  *
59
- * @param blocks - The proposed L2 blocks to add.
63
+ * @param block - The proposed L2 block to add.
60
64
  * @param pendingChainValidationStatus - Optional validation status to set.
61
65
  * @returns True if the operation is successful.
62
66
  */
63
- public async addProposedBlocks(
64
- blocks: L2Block[],
67
+ public async addProposedBlock(
68
+ block: L2Block,
65
69
  pendingChainValidationStatus?: ValidateCheckpointResult,
66
70
  ): Promise<boolean> {
67
71
  const result = await this.store.transactionAsync(async () => {
68
- await this.store.addProposedBlocks(blocks);
72
+ await this.store.addProposedBlock(block);
69
73
 
70
74
  const opResults = await Promise.all([
71
75
  // Update the pending chain validation status if provided
72
76
  pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
73
- // Add any logs emitted during the retrieved blocks
74
- this.store.addLogs(blocks),
75
- // Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
76
- ...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),
77
81
  ]);
78
82
 
79
83
  await this.l2TipsCache?.refresh();
@@ -97,13 +101,17 @@ export class ArchiverDataStoreUpdater {
97
101
  checkpoints: PublishedCheckpoint[],
98
102
  pendingChainValidationStatus?: ValidateCheckpointResult,
99
103
  ): Promise<ReconcileCheckpointsResult> {
104
+ for (const checkpoint of checkpoints) {
105
+ validateCheckpoint(checkpoint.checkpoint, { rollupManaLimit: this.opts?.rollupManaLimit });
106
+ }
107
+
100
108
  const result = await this.store.transactionAsync(async () => {
101
109
  // Before adding checkpoints, check for conflicts with local blocks if any
102
110
  const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
103
111
 
104
112
  await this.store.addCheckpoints(checkpoints);
105
113
 
106
- // 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
107
115
  const newBlocks = checkpoints
108
116
  .flatMap((ch: PublishedCheckpoint) => ch.checkpoint.blocks)
109
117
  .filter(b => lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
@@ -173,7 +181,7 @@ export class ArchiverDataStoreUpdater {
173
181
  this.log.verbose(`Block number ${blockNumber} already inserted and matches checkpoint`, blockInfos);
174
182
  lastAlreadyInsertedBlockNumber = blockNumber;
175
183
  } else {
176
- 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);
177
185
  const prunedBlocks = await this.removeBlocksAfter(BlockNumber(blockNumber - 1));
178
186
  return { prunedBlocks, lastAlreadyInsertedBlockNumber };
179
187
  }
@@ -276,6 +284,17 @@ export class ArchiverDataStoreUpdater {
276
284
  });
277
285
  }
278
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
+
279
298
  /** Extracts and stores contract data from a single block. */
280
299
  private addContractDataToDb(block: L2Block): Promise<boolean> {
281
300
  return this.updateContractDataOnDb(block, Operation.Store);
@@ -316,18 +335,37 @@ export class ArchiverDataStoreUpdater {
316
335
  .filter(log => ContractClassPublishedEvent.isContractClassPublishedEvent(log))
317
336
  .map(log => ContractClassPublishedEvent.fromLog(log));
318
337
 
319
- const contractClasses = await Promise.all(contractClassPublishedEvents.map(e => e.toContractClassPublic()));
320
- if (contractClasses.length > 0) {
321
- contractClasses.forEach(c => this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
322
- if (operation == Operation.Store) {
323
- // TODO: Will probably want to create some worker threads to compute these bytecode commitments as they are expensive
324
- const commitments = await Promise.all(
325
- contractClasses.map(c => computePublicBytecodeCommitment(c.packedBytecode)),
326
- );
327
- return await this.store.addContractClasses(contractClasses, commitments, blockNum);
328
- } 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()}`));
329
342
  return await this.store.deleteContractClasses(contractClasses, blockNum);
330
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);
331
369
  }
332
370
  return true;
333
371
  }
@@ -340,10 +378,27 @@ export class ArchiverDataStoreUpdater {
340
378
  blockNum: BlockNumber,
341
379
  operation: Operation,
342
380
  ): Promise<boolean> {
343
- const contractInstances = allLogs
381
+ const allInstances = allLogs
344
382
  .filter(log => ContractInstancePublishedEvent.isContractInstancePublishedEvent(log))
345
383
  .map(log => ContractInstancePublishedEvent.fromLog(log))
346
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
+
347
402
  if (contractInstances.length > 0) {
348
403
  contractInstances.forEach(c =>
349
404
  this.log.verbose(`${Operation[operation]} contract instance at ${c.address.toString()}`),
@@ -441,7 +496,7 @@ export class ArchiverDataStoreUpdater {
441
496
  if (validFnCount > 0) {
442
497
  this.log.verbose(`Storing ${validFnCount} functions for contract class ${contractClassId.toString()}`);
443
498
  }
444
- return await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
499
+ await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
445
500
  }
446
501
  return true;
447
502
  }
@@ -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';
@@ -61,10 +59,6 @@ export class ArchiverL1Synchronizer implements Traceable {
61
59
  private readonly debugClient: ViemPublicDebugClient,
62
60
  private readonly rollup: RollupContract,
63
61
  private readonly inbox: InboxContract,
64
- private readonly l1Addresses: Pick<
65
- L1ContractAddresses,
66
- 'registryAddress' | 'governanceProposerAddress' | 'slashFactoryAddress'
67
- > & { slashingProposerAddress: EthAddress },
68
62
  private readonly store: KVArchiverDataStore,
69
63
  private config: {
70
64
  batchSize: number;
@@ -75,13 +69,18 @@ export class ArchiverL1Synchronizer implements Traceable {
75
69
  private readonly epochCache: EpochCache,
76
70
  private readonly dateProvider: DateProvider,
77
71
  private readonly instrumentation: ArchiverInstrumentation,
78
- private readonly l1Constants: L1RollupConstants & { l1StartBlockHash: Buffer32; genesisArchiveRoot: Fr },
72
+ private readonly l1Constants: L1RollupConstants & {
73
+ l1StartBlockHash: Buffer32;
74
+ genesisArchiveRoot: Fr;
75
+ },
79
76
  private readonly events: ArchiverEmitter,
80
77
  tracer: Tracer,
81
78
  l2TipsCache?: L2TipsCache,
82
79
  private readonly log: Logger = createLogger('archiver:l1-sync'),
83
80
  ) {
84
- this.updater = new ArchiverDataStoreUpdater(this.store, l2TipsCache);
81
+ this.updater = new ArchiverDataStoreUpdater(this.store, l2TipsCache, {
82
+ rollupManaLimit: l1Constants.rollupManaLimit,
83
+ });
85
84
  this.tracer = tracer;
86
85
  }
87
86
 
@@ -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([
@@ -708,7 +740,6 @@ export class ArchiverL1Synchronizer implements Traceable {
708
740
  this.blobClient,
709
741
  searchStartBlock, // TODO(palla/reorg): If the L2 reorg was due to an L1 reorg, we need to start search earlier
710
742
  searchEndBlock,
711
- this.l1Addresses,
712
743
  this.instrumentation,
713
744
  this.log,
714
745
  !initialSyncComplete, // isHistoricalSync
@@ -821,7 +852,7 @@ export class ArchiverL1Synchronizer implements Traceable {
821
852
  const prunedCheckpointNumber = result.prunedBlocks[0].checkpointNumber;
822
853
  const prunedSlotNumber = result.prunedBlocks[0].header.globalVariables.slotNumber;
823
854
 
824
- this.log.warn(
855
+ this.log.info(
825
856
  `Pruned ${result.prunedBlocks.length} mismatching blocks for checkpoint ${prunedCheckpointNumber}`,
826
857
  { prunedBlocks: result.prunedBlocks.map(b => b.toBlockInfo()), prunedSlotNumber, prunedCheckpointNumber },
827
858
  );