@aztec/archiver 4.0.0-nightly.20260119 → 4.0.0-nightly.20260121

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.
@@ -9,15 +9,13 @@ import type { FunctionSelector } from '@aztec/stdlib/abi';
9
9
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
10
10
  import {
11
11
  CheckpointedL2Block,
12
- L2Block,
13
12
  L2BlockHash,
14
13
  L2BlockNew,
15
14
  type L2BlockSource,
16
15
  type L2Tips,
17
- PublishedL2Block,
18
16
  type ValidateCheckpointResult,
19
17
  } from '@aztec/stdlib/block';
20
- import { type Checkpoint, L1PublishedData } from '@aztec/stdlib/checkpoint';
18
+ import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
21
19
  import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
22
20
  import { EmptyL1RollupConstants, type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
23
21
  import { type BlockHeader, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
@@ -27,7 +25,7 @@ import type { UInt64 } from '@aztec/stdlib/types';
27
25
  * A mocked implementation of L2BlockSource to be used in tests.
28
26
  */
29
27
  export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
30
- protected l2Blocks: L2Block[] = [];
28
+ protected l2Blocks: L2BlockNew[] = [];
31
29
 
32
30
  private provenBlockNumber: number = 0;
33
31
  private finalizedBlockNumber: number = 0;
@@ -38,14 +36,14 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
38
36
  public async createBlocks(numBlocks: number) {
39
37
  for (let i = 0; i < numBlocks; i++) {
40
38
  const blockNum = this.l2Blocks.length + 1;
41
- const block = await L2Block.random(BlockNumber(blockNum));
39
+ const block = await L2BlockNew.random(BlockNumber(blockNum), { slotNumber: SlotNumber(blockNum) });
42
40
  this.l2Blocks.push(block);
43
41
  }
44
42
 
45
43
  this.log.verbose(`Created ${numBlocks} blocks in the mock L2 block source`);
46
44
  }
47
45
 
48
- public addBlocks(blocks: L2Block[]) {
46
+ public addBlocks(blocks: L2BlockNew[]) {
49
47
  this.l2Blocks.push(...blocks);
50
48
  this.log.verbose(`Added ${blocks.length} blocks to the mock L2 block source`);
51
49
  }
@@ -108,7 +106,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
108
106
  }
109
107
  const checkpointedBlock = new CheckpointedL2Block(
110
108
  CheckpointNumber(number),
111
- block.toL2Block(),
109
+ block,
112
110
  new L1PublishedData(BigInt(number), BigInt(number), `0x${number.toString(16).padStart(64, '0')}`),
113
111
  [],
114
112
  );
@@ -139,8 +137,9 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
139
137
  * @param number - The block number to return (inclusive).
140
138
  * @returns The requested L2 block.
141
139
  */
142
- public getBlock(number: number) {
143
- return Promise.resolve(this.l2Blocks[number - 1]);
140
+ public getBlock(number: number): Promise<L2BlockNew | undefined> {
141
+ const block = this.l2Blocks[number - 1];
142
+ return Promise.resolve(block);
144
143
  }
145
144
 
146
145
  /**
@@ -150,7 +149,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
150
149
  */
151
150
  public getL2BlockNew(number: BlockNumber): Promise<L2BlockNew | undefined> {
152
151
  const block = this.l2Blocks[number - 1];
153
- return Promise.resolve(block?.toL2Block());
152
+ return Promise.resolve(block);
154
153
  }
155
154
 
156
155
  /**
@@ -159,7 +158,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
159
158
  * @param limit - The maximum number of blocks to return.
160
159
  * @returns The requested mocked L2 blocks.
161
160
  */
162
- public getBlocks(from: number, limit: number, proven?: boolean) {
161
+ public getBlocks(from: number, limit: number, proven?: boolean): Promise<L2BlockNew[]> {
163
162
  return Promise.resolve(
164
163
  this.l2Blocks
165
164
  .slice(from - 1, from - 1 + limit)
@@ -167,37 +166,62 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
167
166
  );
168
167
  }
169
168
 
170
- public async getPublishedCheckpoints(from: CheckpointNumber, limit: number) {
171
- // TODO: Implement this properly. This only works when we have one block per checkpoint.
172
- return (await this.getPublishedBlocks(from, limit)).map(block => block.toPublishedCheckpoint());
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
+ );
173
184
  }
174
185
 
175
186
  public async getCheckpointByArchive(archive: Fr): Promise<Checkpoint | undefined> {
176
- // TODO: Implement this properly. This only works when we have one block per checkpoint.
177
- return (await this.getPublishedBlockByArchive(archive))?.block.toCheckpoint();
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;
178
196
  }
179
197
 
180
- public async getPublishedBlocks(from: number, limit: number, proven?: boolean) {
181
- const blocks = await this.getBlocks(from, limit, proven);
182
- return blocks.map(block =>
183
- PublishedL2Block.fromFields({
184
- block,
185
- l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
186
- attestations: [],
187
- }),
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);
202
+ 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
+ ),
188
211
  );
189
212
  }
190
213
 
191
- async getL2BlocksNew(from: BlockNumber, limit: number, proven?: boolean): Promise<L2BlockNew[]> {
192
- const blocks = await this.getBlocks(from, limit, proven);
193
- return blocks.map(x => x.toL2Block());
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);
194
217
  }
195
218
 
196
- public async getPublishedBlockByHash(blockHash: Fr): Promise<PublishedL2Block | undefined> {
219
+ public async getPublishedBlockByHash(blockHash: Fr): Promise<CheckpointedL2Block | undefined> {
197
220
  for (const block of this.l2Blocks) {
198
221
  const hash = await block.hash();
199
222
  if (hash.equals(blockHash)) {
200
- return PublishedL2Block.fromFields({
223
+ return CheckpointedL2Block.fromFields({
224
+ checkpointNumber: CheckpointNumber(block.number),
201
225
  block,
202
226
  l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
203
227
  attestations: [],
@@ -207,13 +231,14 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
207
231
  return undefined;
208
232
  }
209
233
 
210
- public getPublishedBlockByArchive(archive: Fr): Promise<PublishedL2Block | undefined> {
234
+ public getPublishedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
211
235
  const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
212
236
  if (!block) {
213
237
  return Promise.resolve(undefined);
214
238
  }
215
239
  return Promise.resolve(
216
- PublishedL2Block.fromFields({
240
+ CheckpointedL2Block.fromFields({
241
+ checkpointNumber: CheckpointNumber(block.number),
217
242
  block,
218
243
  l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
219
244
  attestations: [],
@@ -221,11 +246,26 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
221
246
  );
222
247
  }
223
248
 
249
+ public async getL2BlockNewByHash(blockHash: Fr): Promise<L2BlockNew | undefined> {
250
+ for (const block of this.l2Blocks) {
251
+ const hash = await block.hash();
252
+ if (hash.equals(blockHash)) {
253
+ return block;
254
+ }
255
+ }
256
+ return undefined;
257
+ }
258
+
259
+ public getL2BlockNewByArchive(archive: Fr): Promise<L2BlockNew | undefined> {
260
+ const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
261
+ return Promise.resolve(block);
262
+ }
263
+
224
264
  public async getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
225
265
  for (const block of this.l2Blocks) {
226
266
  const hash = await block.hash();
227
267
  if (hash.equals(blockHash)) {
228
- return block.getBlockHeader();
268
+ return block.header;
229
269
  }
230
270
  }
231
271
  return undefined;
@@ -233,19 +273,32 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
233
273
 
234
274
  public getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
235
275
  const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
236
- return Promise.resolve(block?.getBlockHeader());
276
+ return Promise.resolve(block?.header);
237
277
  }
238
278
 
239
279
  getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
240
- return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.getBlockHeader());
280
+ return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.header);
241
281
  }
242
282
 
243
283
  getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
244
- // TODO: Implement this properly. This only works when we have one block per checkpoint.
245
- return this.getBlocksForEpoch(epochNumber).then(blocks => blocks.map(b => b.toCheckpoint()));
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
+ }),
298
+ );
246
299
  }
247
300
 
248
- getBlocksForEpoch(epochNumber: EpochNumber): Promise<L2Block[]> {
301
+ getBlocksForEpoch(epochNumber: EpochNumber): Promise<L2BlockNew[]> {
249
302
  const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
250
303
  const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
251
304
  const blocks = this.l2Blocks.filter(b => {
@@ -257,12 +310,12 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
257
310
 
258
311
  getBlocksForSlot(slotNumber: SlotNumber): Promise<L2BlockNew[]> {
259
312
  const blocks = this.l2Blocks.filter(b => b.header.globalVariables.slotNumber === slotNumber);
260
- return Promise.resolve(blocks.map(b => b.toL2Block()));
313
+ return Promise.resolve(blocks);
261
314
  }
262
315
 
263
316
  async getBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
264
317
  const blocks = await this.getBlocksForEpoch(epochNumber);
265
- return blocks.map(b => b.getBlockHeader());
318
+ return blocks.map(b => b.header);
266
319
  }
267
320
 
268
321
  /**
@@ -4,7 +4,7 @@ import {
4
4
  PRIVATE_LOG_SIZE_IN_FIELDS,
5
5
  } from '@aztec/constants';
6
6
  import { makeTuple } from '@aztec/foundation/array';
7
- import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
7
+ import { BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
8
8
  import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
9
9
  import { times, timesParallel } from '@aztec/foundation/collection';
10
10
  import { randomBigInt, randomInt } from '@aztec/foundation/crypto/random';
@@ -270,7 +270,7 @@ export async function makeCheckpointWithLogs(
270
270
 
271
271
  const block = await L2BlockNew.random(BlockNumber(blockNumber), {
272
272
  checkpointNumber: CheckpointNumber(blockNumber),
273
- indexWithinCheckpoint: 0,
273
+ indexWithinCheckpoint: IndexWithinCheckpoint(0),
274
274
  state: makeStateForBlock(blockNumber, numTxsPerBlock),
275
275
  ...(previousArchive ? { lastArchive: previousArchive } : {}),
276
276
  });