@aztec/archiver 0.0.1-commit.fffb133c → 0.0.1-dev

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 (100) hide show
  1. package/dest/archiver.d.ts +9 -5
  2. package/dest/archiver.d.ts.map +1 -1
  3. package/dest/archiver.js +87 -111
  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 -3
  8. package/dest/factory.d.ts.map +1 -1
  9. package/dest/factory.js +32 -26
  10. package/dest/index.d.ts +2 -1
  11. package/dest/index.d.ts.map +1 -1
  12. package/dest/index.js +1 -0
  13. package/dest/l1/bin/retrieve-calldata.js +36 -33
  14. package/dest/l1/calldata_retriever.d.ts +73 -50
  15. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  16. package/dest/l1/calldata_retriever.js +190 -259
  17. package/dest/l1/data_retrieval.d.ts +4 -7
  18. package/dest/l1/data_retrieval.d.ts.map +1 -1
  19. package/dest/l1/data_retrieval.js +10 -14
  20. package/dest/l1/spire_proposer.d.ts +5 -5
  21. package/dest/l1/spire_proposer.d.ts.map +1 -1
  22. package/dest/l1/spire_proposer.js +9 -17
  23. package/dest/l1/validate_trace.d.ts +6 -3
  24. package/dest/l1/validate_trace.d.ts.map +1 -1
  25. package/dest/l1/validate_trace.js +13 -9
  26. package/dest/modules/data_source_base.d.ts +13 -8
  27. package/dest/modules/data_source_base.d.ts.map +1 -1
  28. package/dest/modules/data_source_base.js +29 -73
  29. package/dest/modules/data_store_updater.d.ts +22 -7
  30. package/dest/modules/data_store_updater.d.ts.map +1 -1
  31. package/dest/modules/data_store_updater.js +114 -40
  32. package/dest/modules/instrumentation.d.ts +4 -2
  33. package/dest/modules/instrumentation.d.ts.map +1 -1
  34. package/dest/modules/instrumentation.js +26 -12
  35. package/dest/modules/l1_synchronizer.d.ts +5 -8
  36. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  37. package/dest/modules/l1_synchronizer.js +42 -13
  38. package/dest/store/block_store.d.ts +38 -29
  39. package/dest/store/block_store.d.ts.map +1 -1
  40. package/dest/store/block_store.js +294 -85
  41. package/dest/store/contract_class_store.d.ts +1 -1
  42. package/dest/store/contract_class_store.d.ts.map +1 -1
  43. package/dest/store/contract_class_store.js +27 -7
  44. package/dest/store/contract_instance_store.d.ts +1 -1
  45. package/dest/store/contract_instance_store.d.ts.map +1 -1
  46. package/dest/store/contract_instance_store.js +17 -2
  47. package/dest/store/kv_archiver_store.d.ts +40 -18
  48. package/dest/store/kv_archiver_store.d.ts.map +1 -1
  49. package/dest/store/kv_archiver_store.js +44 -16
  50. package/dest/store/l2_tips_cache.d.ts +18 -0
  51. package/dest/store/l2_tips_cache.d.ts.map +1 -0
  52. package/dest/store/l2_tips_cache.js +20 -0
  53. package/dest/store/log_store.d.ts +1 -1
  54. package/dest/store/log_store.d.ts.map +1 -1
  55. package/dest/store/log_store.js +125 -56
  56. package/dest/store/message_store.js +1 -1
  57. package/dest/test/fake_l1_state.d.ts +20 -1
  58. package/dest/test/fake_l1_state.d.ts.map +1 -1
  59. package/dest/test/fake_l1_state.js +97 -20
  60. package/dest/test/index.js +3 -1
  61. package/dest/test/mock_archiver.d.ts +1 -1
  62. package/dest/test/mock_archiver.d.ts.map +1 -1
  63. package/dest/test/mock_archiver.js +3 -2
  64. package/dest/test/mock_l2_block_source.d.ts +25 -9
  65. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  66. package/dest/test/mock_l2_block_source.js +133 -87
  67. package/dest/test/mock_structs.d.ts +6 -2
  68. package/dest/test/mock_structs.d.ts.map +1 -1
  69. package/dest/test/mock_structs.js +20 -6
  70. package/dest/test/noop_l1_archiver.d.ts +26 -0
  71. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  72. package/dest/test/noop_l1_archiver.js +72 -0
  73. package/package.json +14 -13
  74. package/src/archiver.ts +110 -132
  75. package/src/errors.ts +10 -24
  76. package/src/factory.ts +47 -23
  77. package/src/index.ts +1 -0
  78. package/src/l1/README.md +25 -68
  79. package/src/l1/bin/retrieve-calldata.ts +46 -39
  80. package/src/l1/calldata_retriever.ts +249 -379
  81. package/src/l1/data_retrieval.ts +7 -17
  82. package/src/l1/spire_proposer.ts +7 -15
  83. package/src/l1/validate_trace.ts +24 -6
  84. package/src/modules/data_source_base.ts +59 -98
  85. package/src/modules/data_store_updater.ts +124 -43
  86. package/src/modules/instrumentation.ts +24 -12
  87. package/src/modules/l1_synchronizer.ts +49 -17
  88. package/src/store/block_store.ts +359 -115
  89. package/src/store/contract_class_store.ts +27 -7
  90. package/src/store/contract_instance_store.ts +19 -5
  91. package/src/store/kv_archiver_store.ts +71 -25
  92. package/src/store/l2_tips_cache.ts +27 -0
  93. package/src/store/log_store.ts +186 -57
  94. package/src/store/message_store.ts +1 -1
  95. package/src/test/fake_l1_state.ts +125 -21
  96. package/src/test/index.ts +3 -0
  97. package/src/test/mock_archiver.ts +3 -2
  98. package/src/test/mock_l2_block_source.ts +179 -87
  99. package/src/test/mock_structs.ts +42 -12
  100. package/src/test/noop_l1_archiver.ts +115 -0
@@ -8,16 +8,24 @@ import { createLogger } from '@aztec/foundation/log';
8
8
  import type { FunctionSelector } from '@aztec/stdlib/abi';
9
9
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
10
10
  import {
11
+ type BlockData,
12
+ BlockHash,
11
13
  CheckpointedL2Block,
12
14
  L2Block,
13
- L2BlockHash,
14
15
  type L2BlockSource,
15
16
  type L2Tips,
16
17
  type ValidateCheckpointResult,
17
18
  } from '@aztec/stdlib/block';
18
- import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
19
+ import { Checkpoint, type CheckpointData, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
19
20
  import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
20
- import { EmptyL1RollupConstants, type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
21
+ import {
22
+ EmptyL1RollupConstants,
23
+ type L1RollupConstants,
24
+ getEpochAtSlot,
25
+ getSlotRangeForEpoch,
26
+ } from '@aztec/stdlib/epoch-helpers';
27
+ import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
28
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
21
29
  import { type BlockHeader, TxExecutionResult, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
22
30
  import type { UInt64 } from '@aztec/stdlib/types';
23
31
 
@@ -26,6 +34,7 @@ import type { UInt64 } from '@aztec/stdlib/types';
26
34
  */
27
35
  export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
28
36
  protected l2Blocks: L2Block[] = [];
37
+ protected checkpointList: Checkpoint[] = [];
29
38
 
30
39
  private provenBlockNumber: number = 0;
31
40
  private finalizedBlockNumber: number = 0;
@@ -33,14 +42,36 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
33
42
 
34
43
  private log = createLogger('archiver:mock_l2_block_source');
35
44
 
45
+ /** Creates blocks grouped into single-block checkpoints. */
36
46
  public async createBlocks(numBlocks: number) {
37
- for (let i = 0; i < numBlocks; i++) {
38
- const blockNum = this.l2Blocks.length + 1;
39
- const block = await L2Block.random(BlockNumber(blockNum), { slotNumber: SlotNumber(blockNum) });
40
- this.l2Blocks.push(block);
47
+ await this.createCheckpoints(numBlocks, 1);
48
+ }
49
+
50
+ public getCheckpointNumber(): Promise<CheckpointNumber> {
51
+ return Promise.resolve(
52
+ this.checkpointList.length === 0 ? CheckpointNumber.ZERO : CheckpointNumber(this.checkpointList.length),
53
+ );
54
+ }
55
+
56
+ /** Creates checkpoints, each containing `blocksPerCheckpoint` blocks. */
57
+ public async createCheckpoints(numCheckpoints: number, blocksPerCheckpoint: number = 1) {
58
+ for (let c = 0; c < numCheckpoints; c++) {
59
+ const checkpointNum = CheckpointNumber(this.checkpointList.length + 1);
60
+ const startBlockNum = this.l2Blocks.length + 1;
61
+ const slotNumber = SlotNumber(Number(checkpointNum));
62
+ const checkpoint = await Checkpoint.random(checkpointNum, {
63
+ numBlocks: blocksPerCheckpoint,
64
+ startBlockNumber: startBlockNum,
65
+ slotNumber,
66
+ checkpointNumber: checkpointNum,
67
+ });
68
+ this.checkpointList.push(checkpoint);
69
+ this.l2Blocks.push(...checkpoint.blocks);
41
70
  }
42
71
 
43
- this.log.verbose(`Created ${numBlocks} blocks in the mock L2 block source`);
72
+ this.log.verbose(
73
+ `Created ${numCheckpoints} checkpoints with ${blocksPerCheckpoint} blocks each in the mock L2 block source`,
74
+ );
44
75
  }
45
76
 
46
77
  public addProposedBlocks(blocks: L2Block[]) {
@@ -50,6 +81,16 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
50
81
 
51
82
  public removeBlocks(numBlocks: number) {
52
83
  this.l2Blocks = this.l2Blocks.slice(0, -numBlocks);
84
+ const maxBlockNum = this.l2Blocks.length;
85
+ // Remove any checkpoint whose last block is beyond the remaining blocks.
86
+ this.checkpointList = this.checkpointList.filter(c => {
87
+ const lastBlockNum = c.blocks[0].number + c.blocks.length - 1;
88
+ return lastBlockNum <= maxBlockNum;
89
+ });
90
+ // Keep tip numbers consistent with remaining blocks.
91
+ this.checkpointedBlockNumber = Math.min(this.checkpointedBlockNumber, maxBlockNum);
92
+ this.provenBlockNumber = Math.min(this.provenBlockNumber, maxBlockNum);
93
+ this.finalizedBlockNumber = Math.min(this.finalizedBlockNumber, maxBlockNum);
53
94
  this.log.verbose(`Removed ${numBlocks} blocks from the mock L2 block source`);
54
95
  }
55
96
 
@@ -65,7 +106,33 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
65
106
  }
66
107
 
67
108
  public setCheckpointedBlockNumber(checkpointedBlockNumber: number) {
109
+ const prevCheckpointed = this.checkpointedBlockNumber;
68
110
  this.checkpointedBlockNumber = checkpointedBlockNumber;
111
+ // Auto-create single-block checkpoints for newly checkpointed blocks that don't have one yet.
112
+ // This handles blocks added via addProposedBlocks that are now being marked as checkpointed.
113
+ const newCheckpoints: Checkpoint[] = [];
114
+ for (let blockNum = prevCheckpointed + 1; blockNum <= checkpointedBlockNumber; blockNum++) {
115
+ const block = this.l2Blocks[blockNum - 1];
116
+ if (!block) {
117
+ continue;
118
+ }
119
+ if (this.checkpointList.some(c => c.blocks.some(b => b.number === block.number))) {
120
+ continue;
121
+ }
122
+ const checkpointNum = CheckpointNumber(this.checkpointList.length + newCheckpoints.length + 1);
123
+ const checkpoint = new Checkpoint(
124
+ block.archive,
125
+ CheckpointHeader.random({ slotNumber: block.header.globalVariables.slotNumber }),
126
+ [block],
127
+ checkpointNum,
128
+ );
129
+ newCheckpoints.push(checkpoint);
130
+ }
131
+ // Insert new checkpoints in order by number.
132
+ if (newCheckpoints.length > 0) {
133
+ this.checkpointList.push(...newCheckpoints);
134
+ this.checkpointList.sort((a, b) => a.number - b.number);
135
+ }
69
136
  }
70
137
 
71
138
  /**
@@ -112,13 +179,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
112
179
  if (!block) {
113
180
  return Promise.resolve(undefined);
114
181
  }
115
- const checkpointedBlock = new CheckpointedL2Block(
116
- CheckpointNumber.fromBlockNumber(number),
117
- block,
118
- new L1PublishedData(BigInt(number), BigInt(number), `0x${number.toString(16).padStart(64, '0')}`),
119
- [],
120
- );
121
- return Promise.resolve(checkpointedBlock);
182
+ return Promise.resolve(this.toCheckpointedBlock(block));
122
183
  }
123
184
 
124
185
  public async getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
@@ -167,44 +228,22 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
167
228
  }
168
229
 
169
230
  public getCheckpoints(from: CheckpointNumber, limit: number) {
170
- // TODO(mbps): Implement this properly. This only works when we have one block per checkpoint.
171
- const blocks = this.l2Blocks.slice(from - 1, from - 1 + limit);
172
- return Promise.all(
173
- blocks.map(async block => {
174
- // Create a checkpoint from the block - manually construct since L2Block doesn't have toCheckpoint()
175
- const checkpoint = await Checkpoint.random(block.checkpointNumber, { numBlocks: 1 });
176
- checkpoint.blocks = [block];
177
- return new PublishedCheckpoint(
178
- checkpoint,
179
- new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
180
- [],
181
- );
182
- }),
231
+ const checkpoints = this.checkpointList.slice(from - 1, from - 1 + limit);
232
+ return Promise.resolve(
233
+ checkpoints.map(checkpoint => new PublishedCheckpoint(checkpoint, this.mockL1DataForCheckpoint(checkpoint), [])),
183
234
  );
184
235
  }
185
236
 
186
- public async getCheckpointByArchive(archive: Fr): Promise<Checkpoint | undefined> {
187
- // TODO(mbps): Implement this properly. This only works when we have one block per checkpoint.
188
- const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
189
- if (!block) {
190
- return undefined;
191
- }
192
- // Create a checkpoint from the block - manually construct since L2Block doesn't have toCheckpoint()
193
- const checkpoint = await Checkpoint.random(block.checkpointNumber, { numBlocks: 1 });
194
- checkpoint.blocks = [block];
195
- return checkpoint;
237
+ public getCheckpointByArchive(archive: Fr): Promise<Checkpoint | undefined> {
238
+ const checkpoint = this.checkpointList.find(c => c.archive.root.equals(archive));
239
+ return Promise.resolve(checkpoint);
196
240
  }
197
241
 
198
- public async getCheckpointedBlockByHash(blockHash: Fr): Promise<CheckpointedL2Block | undefined> {
242
+ public async getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
199
243
  for (const block of this.l2Blocks) {
200
244
  const hash = await block.hash();
201
245
  if (hash.equals(blockHash)) {
202
- return CheckpointedL2Block.fromFields({
203
- checkpointNumber: CheckpointNumber.fromBlockNumber(block.number),
204
- block,
205
- l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
206
- attestations: [],
207
- });
246
+ return this.toCheckpointedBlock(block);
208
247
  }
209
248
  }
210
249
  return undefined;
@@ -215,17 +254,10 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
215
254
  if (!block) {
216
255
  return Promise.resolve(undefined);
217
256
  }
218
- return Promise.resolve(
219
- CheckpointedL2Block.fromFields({
220
- checkpointNumber: CheckpointNumber.fromBlockNumber(block.number),
221
- block,
222
- l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
223
- attestations: [],
224
- }),
225
- );
257
+ return Promise.resolve(this.toCheckpointedBlock(block));
226
258
  }
227
259
 
228
- public async getL2BlockByHash(blockHash: Fr): Promise<L2Block | undefined> {
260
+ public async getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
229
261
  for (const block of this.l2Blocks) {
230
262
  const hash = await block.hash();
231
263
  if (hash.equals(blockHash)) {
@@ -240,7 +272,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
240
272
  return Promise.resolve(block);
241
273
  }
242
274
 
243
- public async getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
275
+ public async getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
244
276
  for (const block of this.l2Blocks) {
245
277
  const hash = await block.hash();
246
278
  if (hash.equals(blockHash)) {
@@ -255,47 +287,69 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
255
287
  return Promise.resolve(block?.header);
256
288
  }
257
289
 
290
+ public async getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
291
+ const block = this.l2Blocks[number - 1];
292
+ if (!block) {
293
+ return undefined;
294
+ }
295
+ return {
296
+ header: block.header,
297
+ archive: block.archive,
298
+ blockHash: await block.hash(),
299
+ checkpointNumber: block.checkpointNumber,
300
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
301
+ };
302
+ }
303
+
304
+ public async getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
305
+ const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
306
+ if (!block) {
307
+ return undefined;
308
+ }
309
+ return {
310
+ header: block.header,
311
+ archive: block.archive,
312
+ blockHash: await block.hash(),
313
+ checkpointNumber: block.checkpointNumber,
314
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
315
+ };
316
+ }
317
+
258
318
  getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
259
319
  return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.header);
260
320
  }
261
321
 
262
322
  getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
263
- // TODO(mbps): Implement this properly. This only works when we have one block per checkpoint.
264
- const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
265
- const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
266
- const blocks = this.l2Blocks.filter(b => {
267
- const slot = b.header.globalVariables.slotNumber;
268
- return slot >= start && slot <= end;
269
- });
270
- // Create checkpoints from blocks - manually construct since L2Block doesn't have toCheckpoint()
271
- return Promise.all(
272
- blocks.map(async block => {
273
- const checkpoint = await Checkpoint.random(block.checkpointNumber, { numBlocks: 1 });
274
- checkpoint.blocks = [block];
275
- return checkpoint;
276
- }),
277
- );
323
+ return Promise.resolve(this.getCheckpointsInEpoch(epochNumber));
278
324
  }
279
325
 
280
- getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]> {
281
- const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
282
- const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
283
- const blocks = this.l2Blocks.filter(b => {
284
- const slot = b.header.globalVariables.slotNumber;
285
- return slot >= start && slot <= end;
286
- });
326
+ getCheckpointsDataForEpoch(epochNumber: EpochNumber): Promise<CheckpointData[]> {
327
+ const checkpoints = this.getCheckpointsInEpoch(epochNumber);
287
328
  return Promise.resolve(
288
- blocks.map(block =>
289
- CheckpointedL2Block.fromFields({
290
- checkpointNumber: CheckpointNumber.fromBlockNumber(block.number),
291
- block,
292
- l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
329
+ checkpoints.map(
330
+ (checkpoint): CheckpointData => ({
331
+ checkpointNumber: checkpoint.number,
332
+ header: checkpoint.header,
333
+ archive: checkpoint.archive,
334
+ checkpointOutHash: computeCheckpointOutHash(
335
+ checkpoint.blocks.map(b => b.body.txEffects.map(tx => tx.l2ToL1Msgs)),
336
+ ),
337
+ startBlock: checkpoint.blocks[0].number,
338
+ blockCount: checkpoint.blocks.length,
293
339
  attestations: [],
340
+ l1: this.mockL1DataForCheckpoint(checkpoint),
294
341
  }),
295
342
  ),
296
343
  );
297
344
  }
298
345
 
346
+ getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]> {
347
+ const checkpoints = this.getCheckpointsInEpoch(epochNumber);
348
+ return Promise.resolve(
349
+ checkpoints.flatMap(checkpoint => checkpoint.blocks.map(block => this.toCheckpointedBlock(block))),
350
+ );
351
+ }
352
+
299
353
  getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
300
354
  const blocks = this.l2Blocks.filter(b => b.header.globalVariables.slotNumber === slotNumber);
301
355
  return Promise.resolve(blocks);
@@ -322,7 +376,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
322
376
  return {
323
377
  data: txEffect,
324
378
  l2BlockNumber: block.number,
325
- l2BlockHash: L2BlockHash.fromField(await block.hash()),
379
+ l2BlockHash: await block.hash(),
326
380
  txIndexInBlock: block.body.txEffects.indexOf(txEffect),
327
381
  };
328
382
  }
@@ -343,8 +397,9 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
343
397
  TxExecutionResult.SUCCESS,
344
398
  undefined,
345
399
  txEffect.transactionFee.toBigInt(),
346
- L2BlockHash.fromField(await block.hash()),
400
+ await block.hash(),
347
401
  block.number,
402
+ getEpochAtSlot(block.slot, EmptyL1RollupConstants),
348
403
  );
349
404
  }
350
405
  }
@@ -384,7 +439,10 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
384
439
 
385
440
  const makeTipId = (blockId: typeof latestBlockId) => ({
386
441
  block: blockId,
387
- checkpoint: { number: CheckpointNumber.fromBlockNumber(blockId.number), hash: blockId.hash },
442
+ checkpoint: {
443
+ number: this.findCheckpointNumberForBlock(blockId.number) ?? CheckpointNumber(0),
444
+ hash: blockId.hash,
445
+ },
388
446
  });
389
447
 
390
448
  return {
@@ -395,11 +453,11 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
395
453
  };
396
454
  }
397
455
 
398
- getL2EpochNumber(): Promise<EpochNumber> {
456
+ getSyncedL2EpochNumber(): Promise<EpochNumber> {
399
457
  throw new Error('Method not implemented.');
400
458
  }
401
459
 
402
- getL2SlotNumber(): Promise<SlotNumber> {
460
+ getSyncedL2SlotNumber(): Promise<SlotNumber> {
403
461
  throw new Error('Method not implemented.');
404
462
  }
405
463
 
@@ -472,4 +530,38 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
472
530
  getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
473
531
  return Promise.resolve({ valid: true });
474
532
  }
533
+
534
+ /** Returns checkpoints whose slot falls within the given epoch. */
535
+ private getCheckpointsInEpoch(epochNumber: EpochNumber): Checkpoint[] {
536
+ const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
537
+ const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
538
+ return this.checkpointList.filter(c => c.header.slotNumber >= start && c.header.slotNumber <= end);
539
+ }
540
+
541
+ /** Creates a mock L1PublishedData for a checkpoint. */
542
+ private mockL1DataForCheckpoint(checkpoint: Checkpoint): L1PublishedData {
543
+ return new L1PublishedData(BigInt(checkpoint.number), BigInt(checkpoint.number), Buffer32.random().toString());
544
+ }
545
+
546
+ /** Creates a CheckpointedL2Block from a block using stored checkpoint info. */
547
+ private toCheckpointedBlock(block: L2Block): CheckpointedL2Block {
548
+ const checkpoint = this.checkpointList.find(c => c.blocks.some(b => b.number === block.number));
549
+ const checkpointNumber = checkpoint?.number ?? block.checkpointNumber;
550
+ return new CheckpointedL2Block(
551
+ checkpointNumber,
552
+ block,
553
+ new L1PublishedData(
554
+ BigInt(block.number),
555
+ BigInt(block.number),
556
+ `0x${block.number.toString(16).padStart(64, '0')}`,
557
+ ),
558
+ [],
559
+ );
560
+ }
561
+
562
+ /** Finds the checkpoint number for a block, or undefined if the block is not in any checkpoint. */
563
+ private findCheckpointNumberForBlock(blockNumber: BlockNumber): CheckpointNumber | undefined {
564
+ const checkpoint = this.checkpointList.find(c => c.blocks.some(b => b.number === blockNumber));
565
+ return checkpoint?.number;
566
+ }
475
567
  }
@@ -46,24 +46,40 @@ export function makeInboxMessage(
46
46
  }
47
47
 
48
48
  export function makeInboxMessages(
49
- count: number,
49
+ totalCount: number,
50
50
  opts: {
51
51
  initialHash?: Buffer16;
52
52
  initialCheckpointNumber?: CheckpointNumber;
53
+ messagesPerCheckpoint?: number;
53
54
  overrideFn?: (msg: InboxMessage, index: number) => InboxMessage;
54
55
  } = {},
55
56
  ): InboxMessage[] {
56
- const { initialHash = Buffer16.ZERO, overrideFn = msg => msg, initialCheckpointNumber = 1 } = opts;
57
+ const {
58
+ initialHash = Buffer16.ZERO,
59
+ overrideFn = msg => msg,
60
+ initialCheckpointNumber = CheckpointNumber(1),
61
+ messagesPerCheckpoint = 1,
62
+ } = opts;
63
+
57
64
  const messages: InboxMessage[] = [];
58
65
  let rollingHash = initialHash;
59
- for (let i = 0; i < count; i++) {
66
+ for (let i = 0; i < totalCount; i++) {
67
+ const msgIndex = i % messagesPerCheckpoint;
68
+ const checkpointNumber = CheckpointNumber.fromBigInt(
69
+ BigInt(initialCheckpointNumber) + BigInt(i) / BigInt(messagesPerCheckpoint),
70
+ );
60
71
  const leaf = Fr.random();
61
- const checkpointNumber = CheckpointNumber(i + initialCheckpointNumber);
62
- const message = overrideFn(makeInboxMessage(rollingHash, { leaf, checkpointNumber }), i);
72
+ const message = overrideFn(
73
+ makeInboxMessage(rollingHash, {
74
+ leaf,
75
+ checkpointNumber,
76
+ index: InboxLeaf.smallestIndexForCheckpoint(checkpointNumber) + BigInt(msgIndex),
77
+ }),
78
+ i,
79
+ );
63
80
  rollingHash = message.rollingHash;
64
81
  messages.push(message);
65
82
  }
66
-
67
83
  return messages;
68
84
  }
69
85
 
@@ -111,6 +127,25 @@ export function makeL1PublishedData(l1BlockNumber: number): L1PublishedData {
111
127
  return new L1PublishedData(BigInt(l1BlockNumber), BigInt(l1BlockNumber * 1000), makeBlockHash(l1BlockNumber));
112
128
  }
113
129
 
130
+ /** Creates a Checkpoint from a list of blocks with a header that matches the blocks' structure. */
131
+ export function makeCheckpoint(blocks: L2Block[], checkpointNumber = CheckpointNumber(1)): Checkpoint {
132
+ const firstBlock = blocks[0];
133
+ const { slotNumber, timestamp, coinbase, feeRecipient, gasFees } = firstBlock.header.globalVariables;
134
+ return new Checkpoint(
135
+ blocks.at(-1)!.archive,
136
+ CheckpointHeader.random({
137
+ lastArchiveRoot: firstBlock.header.lastArchive.root,
138
+ slotNumber,
139
+ timestamp,
140
+ coinbase,
141
+ feeRecipient,
142
+ gasFees,
143
+ }),
144
+ blocks,
145
+ checkpointNumber,
146
+ );
147
+ }
148
+
114
149
  /** Wraps a Checkpoint with L1 published data and random attestations. */
115
150
  export function makePublishedCheckpoint(
116
151
  checkpoint: Checkpoint,
@@ -285,11 +320,6 @@ export async function makeCheckpointWithLogs(
285
320
  return txEffect;
286
321
  });
287
322
 
288
- const checkpoint = new Checkpoint(
289
- AppendOnlyTreeSnapshot.random(),
290
- CheckpointHeader.random(),
291
- [block],
292
- CheckpointNumber.fromBlockNumber(BlockNumber(blockNumber)),
293
- );
323
+ const checkpoint = makeCheckpoint([block], CheckpointNumber.fromBlockNumber(BlockNumber(blockNumber)));
294
324
  return makePublishedCheckpoint(checkpoint, blockNumber);
295
325
  }
@@ -0,0 +1,115 @@
1
+ import type { BlobClientInterface } from '@aztec/blob-client/client';
2
+ import type { RollupContract } from '@aztec/ethereum/contracts';
3
+ import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
4
+ import { SlotNumber } from '@aztec/foundation/branded-types';
5
+ import { Buffer32 } from '@aztec/foundation/buffer';
6
+ import { Fr } from '@aztec/foundation/curves/bn254';
7
+ import { EthAddress } from '@aztec/foundation/eth-address';
8
+ import type { FunctionsOf } from '@aztec/foundation/types';
9
+ import type { ArchiverEmitter } from '@aztec/stdlib/block';
10
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
11
+ import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
12
+
13
+ import { mock } from 'jest-mock-extended';
14
+ import { EventEmitter } from 'node:events';
15
+
16
+ import { Archiver } from '../archiver.js';
17
+ import { ArchiverInstrumentation } from '../modules/instrumentation.js';
18
+ import type { ArchiverL1Synchronizer } from '../modules/l1_synchronizer.js';
19
+ import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
20
+
21
+ /** Noop L1 synchronizer for testing without L1 connectivity. */
22
+ class NoopL1Synchronizer implements FunctionsOf<ArchiverL1Synchronizer> {
23
+ public readonly tracer: Tracer;
24
+
25
+ constructor(tracer: Tracer) {
26
+ this.tracer = tracer;
27
+ }
28
+
29
+ setConfig(_config: unknown) {}
30
+ getL1BlockNumber(): bigint | undefined {
31
+ return 0n;
32
+ }
33
+ getL1Timestamp(): bigint | undefined {
34
+ return undefined;
35
+ }
36
+ testEthereumNodeSynced(): Promise<void> {
37
+ return Promise.resolve();
38
+ }
39
+ syncFromL1(_initialSyncComplete: boolean): Promise<void> {
40
+ return Promise.resolve();
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Archiver with mocked L1 connectivity for testing.
46
+ * Uses mock L1 clients and a noop synchronizer, enabling tests that
47
+ * don't require real Ethereum connectivity.
48
+ */
49
+ export class NoopL1Archiver extends Archiver {
50
+ constructor(
51
+ dataStore: KVArchiverDataStore,
52
+ l1Constants: L1RollupConstants & { genesisArchiveRoot: Fr },
53
+ instrumentation: ArchiverInstrumentation,
54
+ ) {
55
+ // Create mocks for L1 clients
56
+ const publicClient = mock<ViemPublicClient>();
57
+ const debugClient = mock<ViemPublicDebugClient>();
58
+ const rollup = mock<RollupContract>();
59
+ const blobClient = mock<BlobClientInterface>();
60
+
61
+ // Mock methods called during start()
62
+ blobClient.testSources.mockResolvedValue();
63
+ publicClient.getBlockNumber.mockResolvedValue(1n);
64
+
65
+ const events = new EventEmitter() as ArchiverEmitter;
66
+ const synchronizer = new NoopL1Synchronizer(instrumentation.tracer);
67
+
68
+ super(
69
+ publicClient,
70
+ debugClient,
71
+ rollup,
72
+ {
73
+ registryAddress: EthAddress.ZERO,
74
+ governanceProposerAddress: EthAddress.ZERO,
75
+ slashFactoryAddress: EthAddress.ZERO,
76
+ slashingProposerAddress: EthAddress.ZERO,
77
+ },
78
+ dataStore,
79
+ {
80
+ pollingIntervalMs: 1000,
81
+ batchSize: 100,
82
+ skipValidateCheckpointAttestations: true,
83
+ maxAllowedEthClientDriftSeconds: 300,
84
+ ethereumAllowNoDebugHosts: true, // Skip trace validation
85
+ },
86
+ blobClient,
87
+ instrumentation,
88
+ { ...l1Constants, l1StartBlockHash: Buffer32.random() },
89
+ synchronizer as ArchiverL1Synchronizer,
90
+ events,
91
+ );
92
+ }
93
+
94
+ /** Override start to skip L1 validation checks. */
95
+ public override start(_blockUntilSynced?: boolean): Promise<void> {
96
+ // Just start the running promise without L1 checks
97
+ this.runningPromise.start();
98
+ return Promise.resolve();
99
+ }
100
+
101
+ /** Always reports as fully synced since there is no real L1 to sync from. */
102
+ public override getSyncedL2SlotNumber(): Promise<SlotNumber | undefined> {
103
+ return Promise.resolve(SlotNumber(Number.MAX_SAFE_INTEGER));
104
+ }
105
+ }
106
+
107
+ /** Creates an archiver with mocked L1 connectivity for testing. */
108
+ export async function createNoopL1Archiver(
109
+ dataStore: KVArchiverDataStore,
110
+ l1Constants: L1RollupConstants & { genesisArchiveRoot: Fr },
111
+ telemetry: TelemetryClient = getTelemetryClient(),
112
+ ): Promise<NoopL1Archiver> {
113
+ const instrumentation = await ArchiverInstrumentation.new(telemetry, () => dataStore.estimateSize());
114
+ return new NoopL1Archiver(dataStore, l1Constants, instrumentation);
115
+ }