@aztec/archiver 0.0.1-commit.3469e52 → 0.0.1-commit.3895657bc

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 (97) hide show
  1. package/README.md +9 -0
  2. package/dest/archiver.d.ts +12 -6
  3. package/dest/archiver.d.ts.map +1 -1
  4. package/dest/archiver.js +52 -111
  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 +6 -3
  9. package/dest/factory.d.ts.map +1 -1
  10. package/dest/factory.js +19 -14
  11. package/dest/index.d.ts +2 -1
  12. package/dest/index.d.ts.map +1 -1
  13. package/dest/index.js +1 -0
  14. package/dest/l1/bin/retrieve-calldata.js +35 -32
  15. package/dest/l1/calldata_retriever.d.ts +73 -50
  16. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  17. package/dest/l1/calldata_retriever.js +190 -259
  18. package/dest/l1/data_retrieval.d.ts +9 -9
  19. package/dest/l1/data_retrieval.d.ts.map +1 -1
  20. package/dest/l1/data_retrieval.js +24 -22
  21. package/dest/l1/spire_proposer.d.ts +5 -5
  22. package/dest/l1/spire_proposer.d.ts.map +1 -1
  23. package/dest/l1/spire_proposer.js +9 -17
  24. package/dest/l1/validate_trace.d.ts +6 -3
  25. package/dest/l1/validate_trace.d.ts.map +1 -1
  26. package/dest/l1/validate_trace.js +13 -9
  27. package/dest/modules/data_source_base.d.ts +23 -19
  28. package/dest/modules/data_source_base.d.ts.map +1 -1
  29. package/dest/modules/data_source_base.js +44 -119
  30. package/dest/modules/data_store_updater.d.ts +35 -21
  31. package/dest/modules/data_store_updater.d.ts.map +1 -1
  32. package/dest/modules/data_store_updater.js +87 -60
  33. package/dest/modules/instrumentation.d.ts +17 -4
  34. package/dest/modules/instrumentation.d.ts.map +1 -1
  35. package/dest/modules/instrumentation.js +36 -12
  36. package/dest/modules/l1_synchronizer.d.ts +5 -8
  37. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  38. package/dest/modules/l1_synchronizer.js +25 -19
  39. package/dest/store/block_store.d.ts +50 -32
  40. package/dest/store/block_store.d.ts.map +1 -1
  41. package/dest/store/block_store.js +147 -54
  42. package/dest/store/contract_class_store.d.ts +1 -1
  43. package/dest/store/contract_class_store.d.ts.map +1 -1
  44. package/dest/store/contract_class_store.js +11 -7
  45. package/dest/store/kv_archiver_store.d.ts +43 -25
  46. package/dest/store/kv_archiver_store.d.ts.map +1 -1
  47. package/dest/store/kv_archiver_store.js +38 -17
  48. package/dest/store/l2_tips_cache.d.ts +19 -0
  49. package/dest/store/l2_tips_cache.d.ts.map +1 -0
  50. package/dest/store/l2_tips_cache.js +89 -0
  51. package/dest/store/log_store.d.ts +4 -4
  52. package/dest/store/log_store.d.ts.map +1 -1
  53. package/dest/store/log_store.js +57 -37
  54. package/dest/store/message_store.js +1 -1
  55. package/dest/test/fake_l1_state.d.ts +9 -4
  56. package/dest/test/fake_l1_state.d.ts.map +1 -1
  57. package/dest/test/fake_l1_state.js +56 -18
  58. package/dest/test/index.js +3 -1
  59. package/dest/test/mock_archiver.d.ts +1 -1
  60. package/dest/test/mock_archiver.d.ts.map +1 -1
  61. package/dest/test/mock_archiver.js +3 -2
  62. package/dest/test/mock_l2_block_source.d.ts +37 -21
  63. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  64. package/dest/test/mock_l2_block_source.js +154 -109
  65. package/dest/test/mock_structs.d.ts +6 -2
  66. package/dest/test/mock_structs.d.ts.map +1 -1
  67. package/dest/test/mock_structs.js +24 -10
  68. package/dest/test/noop_l1_archiver.d.ts +23 -0
  69. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  70. package/dest/test/noop_l1_archiver.js +68 -0
  71. package/package.json +14 -13
  72. package/src/archiver.ts +78 -137
  73. package/src/errors.ts +12 -0
  74. package/src/factory.ts +34 -15
  75. package/src/index.ts +1 -0
  76. package/src/l1/README.md +25 -68
  77. package/src/l1/bin/retrieve-calldata.ts +45 -33
  78. package/src/l1/calldata_retriever.ts +249 -379
  79. package/src/l1/data_retrieval.ts +27 -29
  80. package/src/l1/spire_proposer.ts +7 -15
  81. package/src/l1/validate_trace.ts +24 -6
  82. package/src/modules/data_source_base.ts +73 -163
  83. package/src/modules/data_store_updater.ts +98 -64
  84. package/src/modules/instrumentation.ts +46 -14
  85. package/src/modules/l1_synchronizer.ts +33 -25
  86. package/src/store/block_store.ts +188 -92
  87. package/src/store/contract_class_store.ts +11 -7
  88. package/src/store/kv_archiver_store.ts +69 -29
  89. package/src/store/l2_tips_cache.ts +89 -0
  90. package/src/store/log_store.ts +105 -43
  91. package/src/store/message_store.ts +1 -1
  92. package/src/test/fake_l1_state.ts +77 -19
  93. package/src/test/index.ts +3 -0
  94. package/src/test/mock_archiver.ts +3 -2
  95. package/src/test/mock_l2_block_source.ts +202 -126
  96. package/src/test/mock_structs.ts +45 -15
  97. package/src/test/noop_l1_archiver.ts +109 -0
@@ -8,24 +8,28 @@ 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
- L2BlockHash,
13
- L2BlockNew,
14
+ L2Block,
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
21
  import { EmptyL1RollupConstants, type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
21
- import { type BlockHeader, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
22
+ import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
23
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
24
+ import { type BlockHeader, TxExecutionResult, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
22
25
  import type { UInt64 } from '@aztec/stdlib/types';
23
26
 
24
27
  /**
25
28
  * A mocked implementation of L2BlockSource to be used in tests.
26
29
  */
27
30
  export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
28
- protected l2Blocks: L2BlockNew[] = [];
31
+ protected l2Blocks: L2Block[] = [];
32
+ protected checkpointList: Checkpoint[] = [];
29
33
 
30
34
  private provenBlockNumber: number = 0;
31
35
  private finalizedBlockNumber: number = 0;
@@ -33,23 +37,55 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
33
37
 
34
38
  private log = createLogger('archiver:mock_l2_block_source');
35
39
 
40
+ /** Creates blocks grouped into single-block checkpoints. */
36
41
  public async createBlocks(numBlocks: number) {
37
- for (let i = 0; i < numBlocks; i++) {
38
- const blockNum = this.l2Blocks.length + 1;
39
- const block = await L2BlockNew.random(BlockNumber(blockNum), { slotNumber: SlotNumber(blockNum) });
40
- this.l2Blocks.push(block);
42
+ await this.createCheckpoints(numBlocks, 1);
43
+ }
44
+
45
+ public getCheckpointNumber(): Promise<CheckpointNumber> {
46
+ return Promise.resolve(
47
+ this.checkpointList.length === 0 ? CheckpointNumber.ZERO : CheckpointNumber(this.checkpointList.length),
48
+ );
49
+ }
50
+
51
+ /** Creates checkpoints, each containing `blocksPerCheckpoint` blocks. */
52
+ public async createCheckpoints(numCheckpoints: number, blocksPerCheckpoint: number = 1) {
53
+ for (let c = 0; c < numCheckpoints; c++) {
54
+ const checkpointNum = CheckpointNumber(this.checkpointList.length + 1);
55
+ const startBlockNum = this.l2Blocks.length + 1;
56
+ const slotNumber = SlotNumber(Number(checkpointNum));
57
+ const checkpoint = await Checkpoint.random(checkpointNum, {
58
+ numBlocks: blocksPerCheckpoint,
59
+ startBlockNumber: startBlockNum,
60
+ slotNumber,
61
+ checkpointNumber: checkpointNum,
62
+ });
63
+ this.checkpointList.push(checkpoint);
64
+ this.l2Blocks.push(...checkpoint.blocks);
41
65
  }
42
66
 
43
- this.log.verbose(`Created ${numBlocks} blocks in the mock L2 block source`);
67
+ this.log.verbose(
68
+ `Created ${numCheckpoints} checkpoints with ${blocksPerCheckpoint} blocks each in the mock L2 block source`,
69
+ );
44
70
  }
45
71
 
46
- public addBlocks(blocks: L2BlockNew[]) {
72
+ public addProposedBlocks(blocks: L2Block[]) {
47
73
  this.l2Blocks.push(...blocks);
48
- this.log.verbose(`Added ${blocks.length} blocks to the mock L2 block source`);
74
+ this.log.verbose(`Added ${blocks.length} proposed blocks to the mock L2 block source`);
49
75
  }
50
76
 
51
77
  public removeBlocks(numBlocks: number) {
52
78
  this.l2Blocks = this.l2Blocks.slice(0, -numBlocks);
79
+ const maxBlockNum = this.l2Blocks.length;
80
+ // Remove any checkpoint whose last block is beyond the remaining blocks.
81
+ this.checkpointList = this.checkpointList.filter(c => {
82
+ const lastBlockNum = c.blocks[0].number + c.blocks.length - 1;
83
+ return lastBlockNum <= maxBlockNum;
84
+ });
85
+ // Keep tip numbers consistent with remaining blocks.
86
+ this.checkpointedBlockNumber = Math.min(this.checkpointedBlockNumber, maxBlockNum);
87
+ this.provenBlockNumber = Math.min(this.provenBlockNumber, maxBlockNum);
88
+ this.finalizedBlockNumber = Math.min(this.finalizedBlockNumber, maxBlockNum);
53
89
  this.log.verbose(`Removed ${numBlocks} blocks from the mock L2 block source`);
54
90
  }
55
91
 
@@ -65,7 +101,33 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
65
101
  }
66
102
 
67
103
  public setCheckpointedBlockNumber(checkpointedBlockNumber: number) {
104
+ const prevCheckpointed = this.checkpointedBlockNumber;
68
105
  this.checkpointedBlockNumber = checkpointedBlockNumber;
106
+ // Auto-create single-block checkpoints for newly checkpointed blocks that don't have one yet.
107
+ // This handles blocks added via addProposedBlocks that are now being marked as checkpointed.
108
+ const newCheckpoints: Checkpoint[] = [];
109
+ for (let blockNum = prevCheckpointed + 1; blockNum <= checkpointedBlockNumber; blockNum++) {
110
+ const block = this.l2Blocks[blockNum - 1];
111
+ if (!block) {
112
+ continue;
113
+ }
114
+ if (this.checkpointList.some(c => c.blocks.some(b => b.number === block.number))) {
115
+ continue;
116
+ }
117
+ const checkpointNum = CheckpointNumber(this.checkpointList.length + newCheckpoints.length + 1);
118
+ const checkpoint = new Checkpoint(
119
+ block.archive,
120
+ CheckpointHeader.random({ slotNumber: block.header.globalVariables.slotNumber }),
121
+ [block],
122
+ checkpointNum,
123
+ );
124
+ newCheckpoints.push(checkpoint);
125
+ }
126
+ // Insert new checkpoints in order by number.
127
+ if (newCheckpoints.length > 0) {
128
+ this.checkpointList.push(...newCheckpoints);
129
+ this.checkpointList.sort((a, b) => a.number - b.number);
130
+ }
69
131
  }
70
132
 
71
133
  /**
@@ -96,6 +158,14 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
96
158
  return Promise.resolve(BlockNumber(this.provenBlockNumber));
97
159
  }
98
160
 
161
+ public getCheckpointedL2BlockNumber() {
162
+ return Promise.resolve(BlockNumber(this.checkpointedBlockNumber));
163
+ }
164
+
165
+ public getFinalizedL2BlockNumber() {
166
+ return Promise.resolve(BlockNumber(this.finalizedBlockNumber));
167
+ }
168
+
99
169
  public getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined> {
100
170
  if (number > this.checkpointedBlockNumber) {
101
171
  return Promise.resolve(undefined);
@@ -104,20 +174,10 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
104
174
  if (!block) {
105
175
  return Promise.resolve(undefined);
106
176
  }
107
- const checkpointedBlock = new CheckpointedL2Block(
108
- CheckpointNumber(number),
109
- block,
110
- new L1PublishedData(BigInt(number), BigInt(number), `0x${number.toString(16).padStart(64, '0')}`),
111
- [],
112
- );
113
- return Promise.resolve(checkpointedBlock);
177
+ return Promise.resolve(this.toCheckpointedBlock(block));
114
178
  }
115
179
 
116
- public async getCheckpointedBlocks(
117
- from: BlockNumber,
118
- limit: number,
119
- _proven?: boolean,
120
- ): Promise<CheckpointedL2Block[]> {
180
+ public async getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
121
181
  const result: CheckpointedL2Block[] = [];
122
182
  for (let i = 0; i < limit; i++) {
123
183
  const blockNum = from + i;
@@ -137,7 +197,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
137
197
  * @param number - The block number to return (inclusive).
138
198
  * @returns The requested L2 block.
139
199
  */
140
- public getBlock(number: number): Promise<L2BlockNew | undefined> {
200
+ public getBlock(number: number): Promise<L2Block | undefined> {
141
201
  const block = this.l2Blocks[number - 1];
142
202
  return Promise.resolve(block);
143
203
  }
@@ -147,7 +207,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
147
207
  * @param number - The block number to return.
148
208
  * @returns The requested L2 block.
149
209
  */
150
- public getL2BlockNew(number: BlockNumber): Promise<L2BlockNew | undefined> {
210
+ public getL2Block(number: BlockNumber): Promise<L2Block | undefined> {
151
211
  const block = this.l2Blocks[number - 1];
152
212
  return Promise.resolve(block);
153
213
  }
@@ -158,95 +218,41 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
158
218
  * @param limit - The maximum number of blocks to return.
159
219
  * @returns The requested mocked L2 blocks.
160
220
  */
161
- public getBlocks(from: number, limit: number, proven?: boolean): Promise<L2BlockNew[]> {
162
- return Promise.resolve(
163
- this.l2Blocks
164
- .slice(from - 1, from - 1 + limit)
165
- .filter(b => !proven || this.provenBlockNumber === undefined || b.number <= this.provenBlockNumber),
166
- );
221
+ public getBlocks(from: number, limit: number): Promise<L2Block[]> {
222
+ return Promise.resolve(this.l2Blocks.slice(from - 1, from - 1 + limit));
167
223
  }
168
224
 
169
- public getPublishedCheckpoints(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 L2BlockNew 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
- }),
183
- );
184
- }
185
-
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 L2BlockNew doesn't have toCheckpoint()
193
- const checkpoint = await Checkpoint.random(block.checkpointNumber, { numBlocks: 1 });
194
- checkpoint.blocks = [block];
195
- return checkpoint;
196
- }
197
-
198
- public getPublishedBlocks(from: number, limit: number, proven?: boolean): Promise<CheckpointedL2Block[]> {
199
- const blocks = this.l2Blocks
200
- .slice(from - 1, from - 1 + limit)
201
- .filter(b => !proven || this.provenBlockNumber === undefined || b.number <= this.provenBlockNumber);
225
+ public getCheckpoints(from: CheckpointNumber, limit: number) {
226
+ const checkpoints = this.checkpointList.slice(from - 1, from - 1 + limit);
202
227
  return Promise.resolve(
203
- blocks.map(block =>
204
- CheckpointedL2Block.fromFields({
205
- checkpointNumber: CheckpointNumber(block.number),
206
- block,
207
- l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
208
- attestations: [],
209
- }),
210
- ),
228
+ checkpoints.map(checkpoint => new PublishedCheckpoint(checkpoint, this.mockL1DataForCheckpoint(checkpoint), [])),
211
229
  );
212
230
  }
213
231
 
214
- getL2BlocksNew(from: BlockNumber, limit: number, proven?: boolean): Promise<L2BlockNew[]> {
215
- // getBlocks already returns L2BlockNew[], so just return directly
216
- return this.getBlocks(from, limit, proven);
232
+ public getCheckpointByArchive(archive: Fr): Promise<Checkpoint | undefined> {
233
+ const checkpoint = this.checkpointList.find(c => c.archive.root.equals(archive));
234
+ return Promise.resolve(checkpoint);
217
235
  }
218
236
 
219
- public async getPublishedBlockByHash(blockHash: Fr): Promise<CheckpointedL2Block | undefined> {
237
+ public async getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
220
238
  for (const block of this.l2Blocks) {
221
239
  const hash = await block.hash();
222
240
  if (hash.equals(blockHash)) {
223
- return CheckpointedL2Block.fromFields({
224
- checkpointNumber: CheckpointNumber(block.number),
225
- block,
226
- l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
227
- attestations: [],
228
- });
241
+ return this.toCheckpointedBlock(block);
229
242
  }
230
243
  }
231
244
  return undefined;
232
245
  }
233
246
 
234
- public getPublishedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
247
+ public getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
235
248
  const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
236
249
  if (!block) {
237
250
  return Promise.resolve(undefined);
238
251
  }
239
- return Promise.resolve(
240
- CheckpointedL2Block.fromFields({
241
- checkpointNumber: CheckpointNumber(block.number),
242
- block,
243
- l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
244
- attestations: [],
245
- }),
246
- );
252
+ return Promise.resolve(this.toCheckpointedBlock(block));
247
253
  }
248
254
 
249
- public async getL2BlockNewByHash(blockHash: Fr): Promise<L2BlockNew | undefined> {
255
+ public async getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
250
256
  for (const block of this.l2Blocks) {
251
257
  const hash = await block.hash();
252
258
  if (hash.equals(blockHash)) {
@@ -256,12 +262,12 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
256
262
  return undefined;
257
263
  }
258
264
 
259
- public getL2BlockNewByArchive(archive: Fr): Promise<L2BlockNew | undefined> {
265
+ public getL2BlockByArchive(archive: Fr): Promise<L2Block | undefined> {
260
266
  const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
261
267
  return Promise.resolve(block);
262
268
  }
263
269
 
264
- public async getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
270
+ public async getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
265
271
  for (const block of this.l2Blocks) {
266
272
  const hash = await block.hash();
267
273
  if (hash.equals(blockHash)) {
@@ -276,46 +282,77 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
276
282
  return Promise.resolve(block?.header);
277
283
  }
278
284
 
285
+ public async getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
286
+ const block = this.l2Blocks[number - 1];
287
+ if (!block) {
288
+ return undefined;
289
+ }
290
+ return {
291
+ header: block.header,
292
+ archive: block.archive,
293
+ blockHash: await block.hash(),
294
+ checkpointNumber: block.checkpointNumber,
295
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
296
+ };
297
+ }
298
+
299
+ public async getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
300
+ const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
301
+ if (!block) {
302
+ return undefined;
303
+ }
304
+ return {
305
+ header: block.header,
306
+ archive: block.archive,
307
+ blockHash: await block.hash(),
308
+ checkpointNumber: block.checkpointNumber,
309
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
310
+ };
311
+ }
312
+
279
313
  getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
280
314
  return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.header);
281
315
  }
282
316
 
283
317
  getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
284
- // TODO(mbps): Implement this properly. This only works when we have one block per checkpoint.
285
- const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
286
- const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
287
- const blocks = this.l2Blocks.filter(b => {
288
- const slot = b.header.globalVariables.slotNumber;
289
- return slot >= start && slot <= end;
290
- });
291
- // Create checkpoints from blocks - manually construct since L2BlockNew doesn't have toCheckpoint()
292
- return Promise.all(
293
- blocks.map(async block => {
294
- const checkpoint = await Checkpoint.random(block.checkpointNumber, { numBlocks: 1 });
295
- checkpoint.blocks = [block];
296
- return checkpoint;
297
- }),
318
+ return Promise.resolve(this.getCheckpointsInEpoch(epochNumber));
319
+ }
320
+
321
+ getCheckpointsDataForEpoch(epochNumber: EpochNumber): Promise<CheckpointData[]> {
322
+ const checkpoints = this.getCheckpointsInEpoch(epochNumber);
323
+ return Promise.resolve(
324
+ checkpoints.map(
325
+ (checkpoint): CheckpointData => ({
326
+ checkpointNumber: checkpoint.number,
327
+ header: checkpoint.header,
328
+ archive: checkpoint.archive,
329
+ checkpointOutHash: computeCheckpointOutHash(
330
+ checkpoint.blocks.map(b => b.body.txEffects.map(tx => tx.l2ToL1Msgs)),
331
+ ),
332
+ startBlock: checkpoint.blocks[0].number,
333
+ blockCount: checkpoint.blocks.length,
334
+ attestations: [],
335
+ l1: this.mockL1DataForCheckpoint(checkpoint),
336
+ }),
337
+ ),
298
338
  );
299
339
  }
300
340
 
301
- getBlocksForEpoch(epochNumber: EpochNumber): Promise<L2BlockNew[]> {
302
- const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
303
- const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
304
- const blocks = this.l2Blocks.filter(b => {
305
- const slot = b.header.globalVariables.slotNumber;
306
- return slot >= start && slot <= end;
307
- });
308
- return Promise.resolve(blocks);
341
+ getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]> {
342
+ const checkpoints = this.getCheckpointsInEpoch(epochNumber);
343
+ return Promise.resolve(
344
+ checkpoints.flatMap(checkpoint => checkpoint.blocks.map(block => this.toCheckpointedBlock(block))),
345
+ );
309
346
  }
310
347
 
311
- getBlocksForSlot(slotNumber: SlotNumber): Promise<L2BlockNew[]> {
348
+ getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
312
349
  const blocks = this.l2Blocks.filter(b => b.header.globalVariables.slotNumber === slotNumber);
313
350
  return Promise.resolve(blocks);
314
351
  }
315
352
 
316
- async getBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
317
- const blocks = await this.getBlocksForEpoch(epochNumber);
318
- return blocks.map(b => b.header);
353
+ async getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
354
+ const checkpointedBlocks = await this.getCheckpointedBlocksForEpoch(epochNumber);
355
+ return checkpointedBlocks.map(b => b.block.header);
319
356
  }
320
357
 
321
358
  /**
@@ -334,7 +371,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
334
371
  return {
335
372
  data: txEffect,
336
373
  l2BlockNumber: block.number,
337
- l2BlockHash: L2BlockHash.fromField(await block.hash()),
374
+ l2BlockHash: await block.hash(),
338
375
  txIndexInBlock: block.body.txEffects.indexOf(txEffect),
339
376
  };
340
377
  }
@@ -348,12 +385,14 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
348
385
  for (const block of this.l2Blocks) {
349
386
  for (const txEffect of block.body.txEffects) {
350
387
  if (txEffect.txHash.equals(txHash)) {
388
+ // In mock, assume all txs are checkpointed with successful execution
351
389
  return new TxReceipt(
352
390
  txHash,
353
- TxStatus.SUCCESS,
354
- '',
391
+ TxStatus.CHECKPOINTED,
392
+ TxExecutionResult.SUCCESS,
393
+ undefined,
355
394
  txEffect.transactionFee.toBigInt(),
356
- L2BlockHash.fromField(await block.hash()),
395
+ await block.hash(),
357
396
  block.number,
358
397
  );
359
398
  }
@@ -394,7 +433,10 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
394
433
 
395
434
  const makeTipId = (blockId: typeof latestBlockId) => ({
396
435
  block: blockId,
397
- checkpoint: { number: CheckpointNumber(blockId.number), hash: blockId.hash },
436
+ checkpoint: {
437
+ number: this.findCheckpointNumberForBlock(blockId.number) ?? CheckpointNumber(0),
438
+ hash: blockId.hash,
439
+ },
398
440
  });
399
441
 
400
442
  return {
@@ -482,4 +524,38 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
482
524
  getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
483
525
  return Promise.resolve({ valid: true });
484
526
  }
527
+
528
+ /** Returns checkpoints whose slot falls within the given epoch. */
529
+ private getCheckpointsInEpoch(epochNumber: EpochNumber): Checkpoint[] {
530
+ const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
531
+ const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
532
+ return this.checkpointList.filter(c => c.header.slotNumber >= start && c.header.slotNumber <= end);
533
+ }
534
+
535
+ /** Creates a mock L1PublishedData for a checkpoint. */
536
+ private mockL1DataForCheckpoint(checkpoint: Checkpoint): L1PublishedData {
537
+ return new L1PublishedData(BigInt(checkpoint.number), BigInt(checkpoint.number), Buffer32.random().toString());
538
+ }
539
+
540
+ /** Creates a CheckpointedL2Block from a block using stored checkpoint info. */
541
+ private toCheckpointedBlock(block: L2Block): CheckpointedL2Block {
542
+ const checkpoint = this.checkpointList.find(c => c.blocks.some(b => b.number === block.number));
543
+ const checkpointNumber = checkpoint?.number ?? block.checkpointNumber;
544
+ return new CheckpointedL2Block(
545
+ checkpointNumber,
546
+ block,
547
+ new L1PublishedData(
548
+ BigInt(block.number),
549
+ BigInt(block.number),
550
+ `0x${block.number.toString(16).padStart(64, '0')}`,
551
+ ),
552
+ [],
553
+ );
554
+ }
555
+
556
+ /** Finds the checkpoint number for a block, or undefined if the block is not in any checkpoint. */
557
+ private findCheckpointNumberForBlock(blockNumber: BlockNumber): CheckpointNumber | undefined {
558
+ const checkpoint = this.checkpointList.find(c => c.blocks.some(b => b.number === blockNumber));
559
+ return checkpoint?.number;
560
+ }
485
561
  }
@@ -12,7 +12,7 @@ import type { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer'
12
12
  import { Fr } from '@aztec/foundation/curves/bn254';
13
13
  import { EthAddress } from '@aztec/foundation/eth-address';
14
14
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
15
- import { CommitteeAttestation, L2BlockNew } from '@aztec/stdlib/block';
15
+ import { CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
16
16
  import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
17
17
  import { PrivateLog, PublicLog, SiloedTag, Tag } from '@aztec/stdlib/logs';
18
18
  import { InboxLeaf } from '@aztec/stdlib/messaging';
@@ -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,
@@ -268,8 +303,8 @@ export async function makeCheckpointWithLogs(
268
303
  ): Promise<PublishedCheckpoint> {
269
304
  const { previousArchive, numTxsPerBlock = 4, privateLogs, publicLogs } = options;
270
305
 
271
- const block = await L2BlockNew.random(BlockNumber(blockNumber), {
272
- checkpointNumber: CheckpointNumber(blockNumber),
306
+ const block = await L2Block.random(BlockNumber(blockNumber), {
307
+ checkpointNumber: CheckpointNumber.fromBlockNumber(BlockNumber(blockNumber)),
273
308
  indexWithinCheckpoint: IndexWithinCheckpoint(0),
274
309
  state: makeStateForBlock(blockNumber, numTxsPerBlock),
275
310
  ...(previousArchive ? { lastArchive: previousArchive } : {}),
@@ -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(blockNumber),
293
- );
323
+ const checkpoint = makeCheckpoint([block], CheckpointNumber.fromBlockNumber(BlockNumber(blockNumber)));
294
324
  return makePublishedCheckpoint(checkpoint, blockNumber);
295
325
  }