@aztec/archiver 0.0.1-commit.d431d1c → 0.0.1-commit.d6f2b3f94

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 (75) hide show
  1. package/README.md +9 -0
  2. package/dest/archiver.d.ts +6 -5
  3. package/dest/archiver.d.ts.map +1 -1
  4. package/dest/archiver.js +34 -22
  5. package/dest/errors.d.ts +6 -1
  6. package/dest/errors.d.ts.map +1 -1
  7. package/dest/errors.js +8 -0
  8. package/dest/factory.d.ts +5 -2
  9. package/dest/factory.d.ts.map +1 -1
  10. package/dest/factory.js +11 -8
  11. package/dest/l1/bin/retrieve-calldata.js +17 -18
  12. package/dest/l1/data_retrieval.d.ts +1 -1
  13. package/dest/l1/data_retrieval.d.ts.map +1 -1
  14. package/dest/l1/data_retrieval.js +3 -3
  15. package/dest/l1/validate_trace.d.ts +6 -3
  16. package/dest/l1/validate_trace.d.ts.map +1 -1
  17. package/dest/l1/validate_trace.js +13 -9
  18. package/dest/modules/data_source_base.d.ts +17 -18
  19. package/dest/modules/data_source_base.d.ts.map +1 -1
  20. package/dest/modules/data_source_base.js +21 -52
  21. package/dest/modules/data_store_updater.d.ts +23 -19
  22. package/dest/modules/data_store_updater.d.ts.map +1 -1
  23. package/dest/modules/data_store_updater.js +47 -49
  24. package/dest/modules/instrumentation.d.ts +3 -3
  25. package/dest/modules/instrumentation.d.ts.map +1 -1
  26. package/dest/modules/instrumentation.js +17 -10
  27. package/dest/modules/l1_synchronizer.d.ts +1 -1
  28. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  29. package/dest/modules/l1_synchronizer.js +9 -10
  30. package/dest/store/block_store.d.ts +35 -21
  31. package/dest/store/block_store.d.ts.map +1 -1
  32. package/dest/store/block_store.js +81 -40
  33. package/dest/store/contract_class_store.d.ts +1 -1
  34. package/dest/store/contract_class_store.d.ts.map +1 -1
  35. package/dest/store/contract_class_store.js +11 -7
  36. package/dest/store/kv_archiver_store.d.ts +28 -24
  37. package/dest/store/kv_archiver_store.d.ts.map +1 -1
  38. package/dest/store/kv_archiver_store.js +20 -17
  39. package/dest/store/log_store.d.ts +4 -4
  40. package/dest/store/log_store.d.ts.map +1 -1
  41. package/dest/store/log_store.js +57 -37
  42. package/dest/test/fake_l1_state.d.ts +4 -4
  43. package/dest/test/fake_l1_state.d.ts.map +1 -1
  44. package/dest/test/index.js +3 -1
  45. package/dest/test/mock_archiver.js +1 -1
  46. package/dest/test/mock_l2_block_source.d.ts +20 -20
  47. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  48. package/dest/test/mock_l2_block_source.js +40 -41
  49. package/dest/test/mock_structs.d.ts +3 -2
  50. package/dest/test/mock_structs.d.ts.map +1 -1
  51. package/dest/test/mock_structs.js +11 -9
  52. package/dest/test/noop_l1_archiver.d.ts +23 -0
  53. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  54. package/dest/test/noop_l1_archiver.js +68 -0
  55. package/package.json +14 -13
  56. package/src/archiver.ts +46 -28
  57. package/src/errors.ts +12 -0
  58. package/src/factory.ts +23 -13
  59. package/src/l1/bin/retrieve-calldata.ts +16 -17
  60. package/src/l1/data_retrieval.ts +4 -4
  61. package/src/l1/validate_trace.ts +24 -6
  62. package/src/modules/data_source_base.ts +26 -77
  63. package/src/modules/data_store_updater.ts +59 -55
  64. package/src/modules/instrumentation.ts +17 -12
  65. package/src/modules/l1_synchronizer.ts +11 -12
  66. package/src/store/block_store.ts +107 -60
  67. package/src/store/contract_class_store.ts +11 -7
  68. package/src/store/kv_archiver_store.ts +36 -28
  69. package/src/store/log_store.ts +105 -43
  70. package/src/test/fake_l1_state.ts +2 -2
  71. package/src/test/index.ts +3 -0
  72. package/src/test/mock_archiver.ts +1 -1
  73. package/src/test/mock_l2_block_source.ts +54 -64
  74. package/src/test/mock_structs.ts +26 -10
  75. package/src/test/noop_l1_archiver.ts +109 -0
@@ -0,0 +1,68 @@
1
+ import { Buffer32 } from '@aztec/foundation/buffer';
2
+ import { EthAddress } from '@aztec/foundation/eth-address';
3
+ import { getTelemetryClient } from '@aztec/telemetry-client';
4
+ import { mock } from 'jest-mock-extended';
5
+ import { EventEmitter } from 'node:events';
6
+ import { Archiver } from '../archiver.js';
7
+ import { ArchiverInstrumentation } from '../modules/instrumentation.js';
8
+ /** Noop L1 synchronizer for testing without L1 connectivity. */ class NoopL1Synchronizer {
9
+ tracer;
10
+ constructor(tracer){
11
+ this.tracer = tracer;
12
+ }
13
+ setConfig(_config) {}
14
+ getL1BlockNumber() {
15
+ return 0n;
16
+ }
17
+ getL1Timestamp() {
18
+ return 0n;
19
+ }
20
+ testEthereumNodeSynced() {
21
+ return Promise.resolve();
22
+ }
23
+ syncFromL1(_initialSyncComplete) {
24
+ return Promise.resolve();
25
+ }
26
+ }
27
+ /**
28
+ * Archiver with mocked L1 connectivity for testing.
29
+ * Uses mock L1 clients and a noop synchronizer, enabling tests that
30
+ * don't require real Ethereum connectivity.
31
+ */ export class NoopL1Archiver extends Archiver {
32
+ constructor(dataStore, l1Constants, instrumentation){
33
+ // Create mocks for L1 clients
34
+ const publicClient = mock();
35
+ const debugClient = mock();
36
+ const rollup = mock();
37
+ const blobClient = mock();
38
+ // Mock methods called during start()
39
+ blobClient.testSources.mockResolvedValue();
40
+ publicClient.getBlockNumber.mockResolvedValue(1n);
41
+ const events = new EventEmitter();
42
+ const synchronizer = new NoopL1Synchronizer(instrumentation.tracer);
43
+ super(publicClient, debugClient, rollup, {
44
+ registryAddress: EthAddress.ZERO,
45
+ governanceProposerAddress: EthAddress.ZERO,
46
+ slashFactoryAddress: EthAddress.ZERO,
47
+ slashingProposerAddress: EthAddress.ZERO
48
+ }, dataStore, {
49
+ pollingIntervalMs: 1000,
50
+ batchSize: 100,
51
+ skipValidateCheckpointAttestations: true,
52
+ maxAllowedEthClientDriftSeconds: 300,
53
+ ethereumAllowNoDebugHosts: true
54
+ }, blobClient, instrumentation, {
55
+ ...l1Constants,
56
+ l1StartBlockHash: Buffer32.random()
57
+ }, synchronizer, events);
58
+ }
59
+ /** Override start to skip L1 validation checks. */ start(_blockUntilSynced) {
60
+ // Just start the running promise without L1 checks
61
+ this.runningPromise.start();
62
+ return Promise.resolve();
63
+ }
64
+ }
65
+ /** Creates an archiver with mocked L1 connectivity for testing. */ export async function createNoopL1Archiver(dataStore, l1Constants, telemetry = getTelemetryClient()) {
66
+ const instrumentation = await ArchiverInstrumentation.new(telemetry, ()=>dataStore.estimateSize());
67
+ return new NoopL1Archiver(dataStore, l1Constants, instrumentation);
68
+ }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@aztec/archiver",
3
- "version": "0.0.1-commit.d431d1c",
3
+ "version": "0.0.1-commit.d6f2b3f94",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
7
7
  "./test": "./dest/test/index.js",
8
+ "./test/noop-l1": "./dest/test/noop_l1_archiver.js",
8
9
  "./config": "./dest/config.js"
9
10
  },
10
11
  "typedocOptions": {
@@ -64,18 +65,18 @@
64
65
  ]
65
66
  },
66
67
  "dependencies": {
67
- "@aztec/blob-client": "0.0.1-commit.d431d1c",
68
- "@aztec/blob-lib": "0.0.1-commit.d431d1c",
69
- "@aztec/constants": "0.0.1-commit.d431d1c",
70
- "@aztec/epoch-cache": "0.0.1-commit.d431d1c",
71
- "@aztec/ethereum": "0.0.1-commit.d431d1c",
72
- "@aztec/foundation": "0.0.1-commit.d431d1c",
73
- "@aztec/kv-store": "0.0.1-commit.d431d1c",
74
- "@aztec/l1-artifacts": "0.0.1-commit.d431d1c",
75
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.d431d1c",
76
- "@aztec/protocol-contracts": "0.0.1-commit.d431d1c",
77
- "@aztec/stdlib": "0.0.1-commit.d431d1c",
78
- "@aztec/telemetry-client": "0.0.1-commit.d431d1c",
68
+ "@aztec/blob-client": "0.0.1-commit.d6f2b3f94",
69
+ "@aztec/blob-lib": "0.0.1-commit.d6f2b3f94",
70
+ "@aztec/constants": "0.0.1-commit.d6f2b3f94",
71
+ "@aztec/epoch-cache": "0.0.1-commit.d6f2b3f94",
72
+ "@aztec/ethereum": "0.0.1-commit.d6f2b3f94",
73
+ "@aztec/foundation": "0.0.1-commit.d6f2b3f94",
74
+ "@aztec/kv-store": "0.0.1-commit.d6f2b3f94",
75
+ "@aztec/l1-artifacts": "0.0.1-commit.d6f2b3f94",
76
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.d6f2b3f94",
77
+ "@aztec/protocol-contracts": "0.0.1-commit.d6f2b3f94",
78
+ "@aztec/stdlib": "0.0.1-commit.d6f2b3f94",
79
+ "@aztec/telemetry-client": "0.0.1-commit.d6f2b3f94",
79
80
  "lodash.groupby": "^4.6.0",
80
81
  "lodash.omit": "^4.5.0",
81
82
  "tslib": "^2.5.0",
package/src/archiver.ts CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  type ArchiverEmitter,
18
18
  type CheckpointId,
19
19
  GENESIS_CHECKPOINT_HEADER_HASH,
20
- L2BlockNew,
20
+ L2Block,
21
21
  type L2BlockSink,
22
22
  type L2Tips,
23
23
  type ValidateCheckpointResult,
@@ -26,6 +26,7 @@ import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
26
26
  import {
27
27
  type L1RollupConstants,
28
28
  getEpochNumberAtTimestamp,
29
+ getSlotAtNextL1Block,
29
30
  getSlotAtTimestamp,
30
31
  getSlotRangeForEpoch,
31
32
  getTimestampRangeForEpoch,
@@ -46,7 +47,7 @@ export type { ArchiverEmitter };
46
47
 
47
48
  /** Request to add a block to the archiver, queued for processing by the sync loop. */
48
49
  type AddBlockRequest = {
49
- block: L2BlockNew;
50
+ block: L2Block;
50
51
  resolve: () => void;
51
52
  reject: (err: Error) => void;
52
53
  };
@@ -68,7 +69,7 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
68
69
  public readonly events: ArchiverEmitter;
69
70
 
70
71
  /** A loop in which we will be continually fetching new checkpoints. */
71
- private runningPromise: RunningPromise;
72
+ protected runningPromise: RunningPromise;
72
73
 
73
74
  /** L1 synchronizer that handles fetching checkpoints and messages from L1. */
74
75
  private readonly synchronizer: ArchiverL1Synchronizer;
@@ -158,7 +159,11 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
158
159
 
159
160
  await this.blobClient.testSources();
160
161
  await this.synchronizer.testEthereumNodeSynced();
161
- await validateAndLogTraceAvailability(this.debugClient, this.config.ethereumAllowNoDebugHosts ?? false);
162
+ await validateAndLogTraceAvailability(
163
+ this.debugClient,
164
+ this.config.ethereumAllowNoDebugHosts ?? false,
165
+ this.log.getBindings(),
166
+ );
162
167
 
163
168
  // Log initial state for the archiver
164
169
  const { l1StartBlock } = this.l1Constants;
@@ -187,7 +192,7 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
187
192
  * @param block - The L2 block to add.
188
193
  * @returns A promise that resolves when the block has been added to the store, or rejects on error.
189
194
  */
190
- public addBlock(block: L2BlockNew): Promise<void> {
195
+ public addBlock(block: L2Block): Promise<void> {
191
196
  return new Promise<void>((resolve, reject) => {
192
197
  this.blockQueue.push({ block, resolve, reject });
193
198
  this.log.debug(`Queued block ${block.number} for processing`);
@@ -212,10 +217,25 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
212
217
  const queuedItems = this.blockQueue.splice(0, this.blockQueue.length);
213
218
  this.log.debug(`Processing ${queuedItems.length} queued block(s)`);
214
219
 
220
+ // Calculate slot threshold for validation
221
+ const l1Timestamp = this.synchronizer.getL1Timestamp();
222
+ const slotAtNextL1Block =
223
+ l1Timestamp === undefined ? undefined : getSlotAtNextL1Block(l1Timestamp, this.l1Constants);
224
+
215
225
  // Process each block individually to properly resolve/reject each promise
216
226
  for (const { block, resolve, reject } of queuedItems) {
227
+ const blockSlot = block.header.globalVariables.slotNumber;
228
+ if (slotAtNextL1Block !== undefined && blockSlot < slotAtNextL1Block) {
229
+ this.log.warn(
230
+ `Rejecting proposed block ${block.number} for past slot ${blockSlot} (current is ${slotAtNextL1Block})`,
231
+ { block: block.toBlockInfo(), l1Timestamp, slotAtNextL1Block },
232
+ );
233
+ reject(new Error(`Block ${block.number} is for past slot ${blockSlot} (current is ${slotAtNextL1Block})`));
234
+ continue;
235
+ }
236
+
217
237
  try {
218
- await this.updater.addBlocks([block]);
238
+ await this.updater.addProposedBlocks([block]);
219
239
  this.log.debug(`Added block ${block.number} to store`);
220
240
  resolve();
221
241
  } catch (err: any) {
@@ -323,8 +343,11 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
323
343
  }
324
344
 
325
345
  public async isEpochComplete(epochNumber: EpochNumber): Promise<boolean> {
326
- // The epoch is complete if the current L2 block is the last one in the epoch (or later)
327
- const header = await this.getBlockHeader('latest');
346
+ // The epoch is complete if the current checkpointed L2 block is the last one in the epoch (or later).
347
+ // We use the checkpointed block number (synced from L1) instead of 'latest' to avoid returning true
348
+ // prematurely when proposed blocks have been pushed to the archiver but not yet checkpointed on L1.
349
+ const checkpointedBlockNumber = await this.getCheckpointedL2BlockNumber();
350
+ const header = checkpointedBlockNumber > 0 ? await this.getBlockHeader(checkpointedBlockNumber) : undefined;
328
351
  const slot = header ? header.globalVariables.slotNumber : undefined;
329
352
  const [_startSlot, endSlot] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
330
353
  if (slot && slot >= endSlot) {
@@ -355,8 +378,8 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
355
378
  return this.initialSyncComplete;
356
379
  }
357
380
 
358
- public unwindCheckpoints(from: CheckpointNumber, checkpointsToUnwind: number): Promise<boolean> {
359
- return this.updater.unwindCheckpoints(from, checkpointsToUnwind);
381
+ public removeCheckpointsAfter(checkpointNumber: CheckpointNumber): Promise<boolean> {
382
+ return this.updater.removeCheckpointsAfter(checkpointNumber);
360
383
  }
361
384
 
362
385
  /** Used by TXE to add checkpoints directly without syncing from L1. */
@@ -364,22 +387,18 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
364
387
  checkpoints: PublishedCheckpoint[],
365
388
  pendingChainValidationStatus?: ValidateCheckpointResult,
366
389
  ): Promise<boolean> {
367
- await this.updater.setNewCheckpointData(checkpoints, pendingChainValidationStatus);
390
+ await this.updater.addCheckpoints(checkpoints, pendingChainValidationStatus);
368
391
  return true;
369
392
  }
370
393
 
371
394
  public async getL2Tips(): Promise<L2Tips> {
372
- const [latestBlockNumber, provenBlockNumber, checkpointedBlockNumber] = await Promise.all([
395
+ const [latestBlockNumber, provenBlockNumber, checkpointedBlockNumber, finalizedBlockNumber] = await Promise.all([
373
396
  this.getBlockNumber(),
374
397
  this.getProvenBlockNumber(),
375
- this.getCheckpointedBlockNumber(),
398
+ this.getCheckpointedL2BlockNumber(),
399
+ this.getFinalizedL2BlockNumber(),
376
400
  ] as const);
377
401
 
378
- // TODO(#13569): Compute proper finalized block number based on L1 finalized block.
379
- // We just force it 2 epochs worth of proven data for now.
380
- // NOTE: update end-to-end/src/e2e_epochs/epochs_empty_blocks.test.ts as that uses finalized blocks in computations
381
- const finalizedBlockNumber = BlockNumber(Math.max(provenBlockNumber - this.l1Constants.epochDuration * 2, 0));
382
-
383
402
  const beforeInitialblockNumber = BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
384
403
 
385
404
  // Get the latest block header and checkpointed blocks for proven, finalised and checkpointed blocks
@@ -425,14 +444,12 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
425
444
  // Now attempt to retrieve checkpoints for proven, finalised and checkpointed blocks
426
445
  const [[provenBlockCheckpoint], [finalizedBlockCheckpoint], [checkpointedBlockCheckpoint]] = await Promise.all([
427
446
  provenCheckpointedBlock !== undefined
428
- ? await this.getPublishedCheckpoints(provenCheckpointedBlock?.checkpointNumber, 1)
447
+ ? await this.getCheckpoints(provenCheckpointedBlock?.checkpointNumber, 1)
429
448
  : [undefined],
430
449
  finalizedCheckpointedBlock !== undefined
431
- ? await this.getPublishedCheckpoints(finalizedCheckpointedBlock?.checkpointNumber, 1)
432
- : [undefined],
433
- checkpointedBlock !== undefined
434
- ? await this.getPublishedCheckpoints(checkpointedBlock?.checkpointNumber, 1)
450
+ ? await this.getCheckpoints(finalizedCheckpointedBlock?.checkpointNumber, 1)
435
451
  : [undefined],
452
+ checkpointedBlock !== undefined ? await this.getCheckpoints(checkpointedBlock?.checkpointNumber, 1) : [undefined],
436
453
  ]);
437
454
 
438
455
  const initialcheckpointId: CheckpointId = {
@@ -490,13 +507,12 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
490
507
  if (targetL2BlockNumber >= currentL2Block) {
491
508
  throw new Error(`Target L2 block ${targetL2BlockNumber} must be less than current L2 block ${currentL2Block}`);
492
509
  }
493
- const blocksToUnwind = currentL2Block - targetL2BlockNumber;
494
510
  const targetL2Block = await this.store.getCheckpointedBlock(targetL2BlockNumber);
495
511
  if (!targetL2Block) {
496
512
  throw new Error(`Target L2 block ${targetL2BlockNumber} not found`);
497
513
  }
498
514
  const targetL1BlockNumber = targetL2Block.l1.blockNumber;
499
- const targetCheckpointNumber = CheckpointNumber.fromBlockNumber(targetL2BlockNumber);
515
+ const targetCheckpointNumber = targetL2Block.checkpointNumber;
500
516
  const targetL1Block = await this.publicClient.getBlock({
501
517
  blockNumber: targetL1BlockNumber,
502
518
  includeTransactions: false,
@@ -505,9 +521,11 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
505
521
  throw new Error(`Missing L1 block ${targetL1BlockNumber}`);
506
522
  }
507
523
  const targetL1BlockHash = Buffer32.fromString(targetL1Block.hash);
508
- this.log.info(`Unwinding ${blocksToUnwind} checkpoints from L2 block ${currentL2Block}`);
509
- await this.updater.unwindCheckpoints(CheckpointNumber(currentL2Block), blocksToUnwind);
510
- this.log.info(`Unwinding L1 to L2 messages to checkpoint ${targetCheckpointNumber}`);
524
+ this.log.info(
525
+ `Removing checkpoints after checkpoint ${targetCheckpointNumber} (target block ${targetL2BlockNumber})`,
526
+ );
527
+ await this.updater.removeCheckpointsAfter(targetCheckpointNumber);
528
+ this.log.info(`Rolling back L1 to L2 messages to checkpoint ${targetCheckpointNumber}`);
511
529
  await this.store.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
512
530
  this.log.info(`Setting L1 syncpoints to ${targetL1BlockNumber}`);
513
531
  await this.store.setCheckpointSynchedL1BlockNumber(targetL1BlockNumber);
package/src/errors.ts CHANGED
@@ -88,3 +88,15 @@ export class BlockNotFoundError extends Error {
88
88
  super(`Failed to find expected block number ${blockNumber}`);
89
89
  }
90
90
  }
91
+
92
+ export class CannotOverwriteCheckpointedBlockError extends Error {
93
+ constructor(
94
+ public readonly blockNumber: number,
95
+ public readonly lastCheckpointedBlock: number,
96
+ ) {
97
+ super(
98
+ `Cannot add block ${blockNumber}: would overwrite checkpointed data (checkpointed up to block ${lastCheckpointedBlock})`,
99
+ );
100
+ this.name = 'CannotOverwriteCheckpointedBlockError';
101
+ }
102
+ }
package/src/factory.ts CHANGED
@@ -6,7 +6,6 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
6
6
  import { Buffer32 } from '@aztec/foundation/buffer';
7
7
  import { merge } from '@aztec/foundation/collection';
8
8
  import { Fr } from '@aztec/foundation/curves/bn254';
9
- import { createLogger } from '@aztec/foundation/log';
10
9
  import { DateProvider } from '@aztec/foundation/timer';
11
10
  import type { DataStoreConfig } from '@aztec/kv-store/config';
12
11
  import { createStore } from '@aztec/kv-store/lmdb-v2';
@@ -15,6 +14,7 @@ import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/prov
15
14
  import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
16
15
  import type { ArchiverEmitter } from '@aztec/stdlib/block';
17
16
  import { type ContractClassPublic, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
17
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
18
18
  import { getTelemetryClient } from '@aztec/telemetry-client';
19
19
 
20
20
  import { EventEmitter } from 'events';
@@ -31,13 +31,14 @@ export const ARCHIVER_STORE_NAME = 'archiver';
31
31
  /** Creates an archiver store. */
32
32
  export async function createArchiverStore(
33
33
  userConfig: Pick<ArchiverConfig, 'archiverStoreMapSizeKb' | 'maxLogs'> & DataStoreConfig,
34
+ l1Constants: Pick<L1RollupConstants, 'epochDuration'>,
34
35
  ) {
35
36
  const config = {
36
37
  ...userConfig,
37
38
  dataStoreMapSizeKb: userConfig.archiverStoreMapSizeKb ?? userConfig.dataStoreMapSizeKb,
38
39
  };
39
- const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config, createLogger('archiver:lmdb'));
40
- return new KVArchiverDataStore(store, config.maxLogs);
40
+ const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config);
41
+ return new KVArchiverDataStore(store, config.maxLogs, l1Constants);
41
42
  }
42
43
 
43
44
  /**
@@ -52,7 +53,7 @@ export async function createArchiver(
52
53
  deps: ArchiverDeps,
53
54
  opts: { blockUntilSync: boolean } = { blockUntilSync: true },
54
55
  ): Promise<Archiver> {
55
- const archiverStore = await createArchiverStore(config);
56
+ const archiverStore = await createArchiverStore(config, { epochDuration: config.aztecEpochDuration });
56
57
  await registerProtocolContracts(archiverStore);
57
58
 
58
59
  // Create Ethereum clients
@@ -76,14 +77,21 @@ export async function createArchiver(
76
77
  const inbox = new InboxContract(publicClient, config.l1Contracts.inboxAddress);
77
78
 
78
79
  // Fetch L1 constants from rollup contract
79
- const [l1StartBlock, l1GenesisTime, proofSubmissionEpochs, genesisArchiveRoot, slashingProposerAddress] =
80
- await Promise.all([
81
- rollup.getL1StartBlock(),
82
- rollup.getL1GenesisTime(),
83
- rollup.getProofSubmissionEpochs(),
84
- rollup.getGenesisArchiveTreeRoot(),
85
- rollup.getSlashingProposerAddress(),
86
- ] as const);
80
+ const [
81
+ l1StartBlock,
82
+ l1GenesisTime,
83
+ proofSubmissionEpochs,
84
+ genesisArchiveRoot,
85
+ slashingProposerAddress,
86
+ targetCommitteeSize,
87
+ ] = await Promise.all([
88
+ rollup.getL1StartBlock(),
89
+ rollup.getL1GenesisTime(),
90
+ rollup.getProofSubmissionEpochs(),
91
+ rollup.getGenesisArchiveTreeRoot(),
92
+ rollup.getSlashingProposerAddress(),
93
+ rollup.getTargetCommitteeSize(),
94
+ ] as const);
87
95
 
88
96
  const l1StartBlockHash = await publicClient
89
97
  .getBlock({ blockNumber: l1StartBlock, includeTransactions: false })
@@ -99,6 +107,7 @@ export async function createArchiver(
99
107
  slotDuration,
100
108
  ethereumSlotDuration,
101
109
  proofSubmissionEpochs: Number(proofSubmissionEpochs),
110
+ targetCommitteeSize,
102
111
  genesisArchiveRoot: Fr.fromString(genesisArchiveRoot.toString()),
103
112
  };
104
113
 
@@ -155,7 +164,8 @@ export async function createArchiver(
155
164
  return archiver;
156
165
  }
157
166
 
158
- async function registerProtocolContracts(store: KVArchiverDataStore) {
167
+ /** Registers protocol contracts in the archiver store. */
168
+ export async function registerProtocolContracts(store: KVArchiverDataStore) {
159
169
  const blockNumber = 0;
160
170
  for (const name of protocolContractNames) {
161
171
  const provider = new BundledProtocolContractsProvider();
@@ -3,8 +3,9 @@ import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/ty
3
3
  import { CheckpointNumber } from '@aztec/foundation/branded-types';
4
4
  import { EthAddress } from '@aztec/foundation/eth-address';
5
5
  import { createLogger } from '@aztec/foundation/log';
6
+ import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
6
7
 
7
- import { type Hex, createPublicClient, http } from 'viem';
8
+ import { type Hex, createPublicClient, getAbiItem, http, toEventSelector } from 'viem';
8
9
  import { mainnet } from 'viem/chains';
9
10
 
10
11
  import { CalldataRetriever } from '../calldata_retriever.js';
@@ -111,38 +112,36 @@ async function main() {
111
112
  },
112
113
  );
113
114
 
114
- // Extract L2 block number from transaction logs
115
- logger.info('Decoding transaction to extract L2 block number...');
115
+ // Extract checkpoint number from transaction logs
116
+ logger.info('Decoding transaction to extract checkpoint number...');
116
117
  const receipt = await publicClient.getTransactionReceipt({ hash: txHash });
117
- const l2BlockProposedEvent = receipt.logs.find(log => {
118
+
119
+ // Look for CheckpointProposed event (emitted when a checkpoint is proposed to the rollup)
120
+ // Event signature: CheckpointProposed(uint256 indexed checkpointNumber, bytes32 indexed archive, bytes32[], bytes32, bytes32)
121
+ // Hash: keccak256("CheckpointProposed(uint256,bytes32,bytes32[],bytes32,bytes32)")
122
+ const checkpointProposedEvent = receipt.logs.find(log => {
118
123
  try {
119
- // Try to match the L2BlockProposed event
120
124
  return (
121
125
  log.address.toLowerCase() === rollupAddress.toString().toLowerCase() &&
122
- log.topics[0] === '0x2f1d0e696fa5186494a2f2f89a0e0bcbb15d607f6c5eac4637e07e1e5e7d3c00' // L2BlockProposed event signature
126
+ log.topics[0] === toEventSelector(getAbiItem({ abi: RollupAbi, name: 'CheckpointProposed' }))
123
127
  );
124
128
  } catch {
125
129
  return false;
126
130
  }
127
131
  });
128
132
 
129
- let l2BlockNumber: number;
130
- if (l2BlockProposedEvent && l2BlockProposedEvent.topics[1]) {
131
- // L2 block number is typically the first indexed parameter
132
- l2BlockNumber = Number(BigInt(l2BlockProposedEvent.topics[1]));
133
- logger.info(`L2 Block Number (from event): ${l2BlockNumber}`);
134
- } else {
135
- // Fallback: try to extract from transaction data or use a default
136
- logger.warn('Could not extract L2 block number from event, using block number as fallback');
137
- l2BlockNumber = Number(tx.blockNumber);
133
+ if (!checkpointProposedEvent || checkpointProposedEvent.topics[1] === undefined) {
134
+ throw new Error(`Checkpoint proposed event not found`);
138
135
  }
139
136
 
137
+ const checkpointNumber = CheckpointNumber.fromBigInt(BigInt(checkpointProposedEvent.topics[1]));
138
+
140
139
  logger.info('');
141
- logger.info('Retrieving block header from rollup transaction...');
140
+ logger.info('Retrieving checkpoint from rollup transaction...');
142
141
  logger.info('');
143
142
 
144
143
  // For this script, we don't have blob hashes or expected hashes, so pass empty arrays/objects
145
- const result = await retriever.getCheckpointFromRollupTx(txHash, [], CheckpointNumber(l2BlockNumber), {});
144
+ const result = await retriever.getCheckpointFromRollupTx(txHash, [], checkpointNumber, {});
146
145
 
147
146
  logger.info(' Successfully retrieved block header!');
148
147
  logger.info('');
@@ -20,7 +20,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
20
20
  import { EthAddress } from '@aztec/foundation/eth-address';
21
21
  import { type Logger, createLogger } from '@aztec/foundation/log';
22
22
  import { RollupAbi } from '@aztec/l1-artifacts';
23
- import { Body, CommitteeAttestation, L2BlockNew } from '@aztec/stdlib/block';
23
+ import { Body, CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
24
24
  import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
25
25
  import { Proof } from '@aztec/stdlib/proofs';
26
26
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
@@ -69,7 +69,7 @@ export async function retrievedToPublishedCheckpoint({
69
69
  const l1toL2MessageTreeRoot = blocksBlobData[0].l1ToL2MessageRoot!;
70
70
 
71
71
  const spongeBlob = SpongeBlob.init();
72
- const l2Blocks: L2BlockNew[] = [];
72
+ const l2Blocks: L2Block[] = [];
73
73
  for (let i = 0; i < blocksBlobData.length; i++) {
74
74
  const blockBlobData = blocksBlobData[i];
75
75
  const { blockEndMarker, blockEndStateField, lastArchiveRoot, noteHashRoot, nullifierRoot, publicDataRoot } =
@@ -100,7 +100,7 @@ export async function retrievedToPublishedCheckpoint({
100
100
  }),
101
101
  });
102
102
 
103
- const body = Body.fromTxBlobData(checkpointBlobData.blocks[0].txs);
103
+ const body = Body.fromTxBlobData(blockBlobData.txs);
104
104
 
105
105
  const blobFields = encodeBlockBlobData(blockBlobData);
106
106
  await spongeBlob.absorb(blobFields);
@@ -119,7 +119,7 @@ export async function retrievedToPublishedCheckpoint({
119
119
 
120
120
  const newArchive = new AppendOnlyTreeSnapshot(newArchiveRoots[i], l2BlockNumber + 1);
121
121
 
122
- l2Blocks.push(new L2BlockNew(newArchive, header, body, checkpointNumber, IndexWithinCheckpoint(i)));
122
+ l2Blocks.push(new L2Block(newArchive, header, body, checkpointNumber, IndexWithinCheckpoint(i)));
123
123
  }
124
124
 
125
125
  const lastBlock = l2Blocks.at(-1)!;
@@ -1,5 +1,5 @@
1
1
  import type { ViemPublicDebugClient } from '@aztec/ethereum/types';
2
- import { createLogger } from '@aztec/foundation/log';
2
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
3
3
 
4
4
  import type { Hex } from 'viem';
5
5
  import type { ZodSchema } from 'zod';
@@ -7,8 +7,6 @@ import type { ZodSchema } from 'zod';
7
7
  import { callTraceSchema } from './debug_tx.js';
8
8
  import { traceTransactionResponseSchema } from './trace_tx.js';
9
9
 
10
- const logger = createLogger('aztec:archiver:validate_trace');
11
-
12
10
  /**
13
11
  * Helper function to test a trace method with validation
14
12
  *
@@ -17,6 +15,7 @@ const logger = createLogger('aztec:archiver:validate_trace');
17
15
  * @param schema - Zod schema to validate the response
18
16
  * @param method - Name of the RPC method ('debug_traceTransaction' or 'trace_transaction')
19
17
  * @param blockType - Type of block being tested ('recent' or 'old')
18
+ * @param logger - Logger instance
20
19
  * @returns true if the method works and validation passes, false otherwise
21
20
  */
22
21
  async function testTraceMethod(
@@ -25,6 +24,7 @@ async function testTraceMethod(
25
24
  schema: ZodSchema,
26
25
  method: 'debug_traceTransaction' | 'trace_transaction',
27
26
  blockType: string,
27
+ logger: Logger,
28
28
  ): Promise<boolean> {
29
29
  try {
30
30
  // Make request with appropriate params based on method name
@@ -59,9 +59,14 @@ export interface TraceAvailability {
59
59
  * Validates the availability of debug/trace methods on the Ethereum client.
60
60
  *
61
61
  * @param client - The Viem public debug client
62
+ * @param bindings - Optional logger bindings for context
62
63
  * @returns Object indicating which trace methods are available for recent and old blocks
63
64
  */
64
- export async function validateTraceAvailability(client: ViemPublicDebugClient): Promise<TraceAvailability> {
65
+ export async function validateTraceAvailability(
66
+ client: ViemPublicDebugClient,
67
+ bindings?: LoggerBindings,
68
+ ): Promise<TraceAvailability> {
69
+ const logger = createLogger('archiver:validate_trace', bindings);
65
70
  const result: TraceAvailability = {
66
71
  debugTraceRecent: false,
67
72
  traceTransactionRecent: false,
@@ -95,6 +100,7 @@ export async function validateTraceAvailability(client: ViemPublicDebugClient):
95
100
  callTraceSchema,
96
101
  'debug_traceTransaction',
97
102
  'recent',
103
+ logger,
98
104
  );
99
105
 
100
106
  // Test trace_transaction with recent block
@@ -104,6 +110,7 @@ export async function validateTraceAvailability(client: ViemPublicDebugClient):
104
110
  traceTransactionResponseSchema,
105
111
  'trace_transaction',
106
112
  'recent',
113
+ logger,
107
114
  );
108
115
 
109
116
  // Get a block from 512 blocks ago
@@ -132,7 +139,14 @@ export async function validateTraceAvailability(client: ViemPublicDebugClient):
132
139
  const oldTxHash = oldBlock.transactions[0] as Hex;
133
140
 
134
141
  // Test debug_traceTransaction with old block
135
- result.debugTraceOld = await testTraceMethod(client, oldTxHash, callTraceSchema, 'debug_traceTransaction', 'old');
142
+ result.debugTraceOld = await testTraceMethod(
143
+ client,
144
+ oldTxHash,
145
+ callTraceSchema,
146
+ 'debug_traceTransaction',
147
+ 'old',
148
+ logger,
149
+ );
136
150
 
137
151
  // Test trace_transaction with old block
138
152
  result.traceTransactionOld = await testTraceMethod(
@@ -141,6 +155,7 @@ export async function validateTraceAvailability(client: ViemPublicDebugClient):
141
155
  traceTransactionResponseSchema,
142
156
  'trace_transaction',
143
157
  'old',
158
+ logger,
144
159
  );
145
160
  } catch (error) {
146
161
  logger.warn(`Error validating debug_traceTransaction and trace_transaction availability: ${error}`);
@@ -159,15 +174,18 @@ function hasTxs(block: { transactions?: Hex[] }): boolean {
159
174
  *
160
175
  * @param client - The Viem public debug client
161
176
  * @param ethereumAllowNoDebugHosts - If false, throws an error when no trace methods are available
177
+ * @param bindings - Optional logger bindings for context
162
178
  * @throws Error if ethereumAllowNoDebugHosts is false and no trace methods are available
163
179
  */
164
180
  export async function validateAndLogTraceAvailability(
165
181
  client: ViemPublicDebugClient,
166
182
  ethereumAllowNoDebugHosts: boolean,
183
+ bindings?: LoggerBindings,
167
184
  ): Promise<void> {
185
+ const logger = createLogger('archiver:validate_trace', bindings);
168
186
  logger.debug('Validating trace/debug method availability...');
169
187
 
170
- const availability = await validateTraceAvailability(client);
188
+ const availability = await validateTraceAvailability(client, bindings);
171
189
 
172
190
  // Check if we have support for old blocks (either debug or trace)
173
191
  const hasOldBlockSupport = availability.debugTraceOld || availability.traceTransactionOld;