Skip to content

Commit f74d768

Browse files
committed
refactor: remove deprecated L2Block and L2BlockHeader
1 parent a238f84 commit f74d768

File tree

65 files changed

+660
-1346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+660
-1346
lines changed

yarn-project/archiver/src/archiver-sync.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ describe('Archiver Sync', () => {
212212
const expectedTotalNumLogs = (name: 'private' | 'public' | 'contractClass') =>
213213
sum(block.body.txEffects.map(txEffect => txEffect[`${name}Logs`].length));
214214

215-
const privateLogs = (await archiver.getBlock(blockNumber))!.toL2Block().getPrivateLogs();
215+
const privateLogs = (await archiver.getBlock(blockNumber))!.getPrivateLogs();
216216
expect(privateLogs.length).toBe(expectedTotalNumLogs('private'));
217217

218218
const publicLogs = (await archiver.getPublicLogs({ fromBlock: blockNumber, toBlock: blockNumber + 1 })).logs;

yarn-project/archiver/src/modules/data_source_base.ts

Lines changed: 31 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
44
import { isDefined } from '@aztec/foundation/types';
55
import type { FunctionSelector } from '@aztec/stdlib/abi';
66
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
7-
import {
8-
type CheckpointedL2Block,
9-
CommitteeAttestation,
10-
L2Block,
11-
type L2BlockNew,
12-
type L2Tips,
13-
PublishedL2Block,
14-
} from '@aztec/stdlib/block';
7+
import { CheckpointedL2Block, CommitteeAttestation, L2BlockNew, type L2Tips } from '@aztec/stdlib/block';
158
import { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
169
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
1710
import { type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
@@ -273,13 +266,13 @@ export abstract class ArchiverDataSourceBase
273266
return this.store.getBlocksForSlot(slotNumber);
274267
}
275268

276-
public async getBlocksForEpoch(epochNumber: EpochNumber): Promise<L2Block[]> {
269+
public async getBlocksForEpoch(epochNumber: EpochNumber): Promise<L2BlockNew[]> {
277270
if (!this.l1Constants) {
278271
throw new Error('L1 constants not set');
279272
}
280273

281274
const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
282-
const blocks: L2Block[] = [];
275+
const blocks: L2BlockNew[] = [];
283276

284277
// Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
285278
// We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
@@ -354,90 +347,68 @@ export abstract class ArchiverDataSourceBase
354347
return checkpoints.reverse();
355348
}
356349

357-
public async getPublishedBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<PublishedL2Block[]> {
350+
public async getPublishedBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<CheckpointedL2Block[]> {
358351
const checkpoints = await this.store.getRangeOfCheckpoints(CheckpointNumber(from), limit);
359352
const provenCheckpointNumber = await this.store.getProvenCheckpointNumber();
360353
const blocks = (
361354
await Promise.all(checkpoints.map(ch => this.store.getBlocksForCheckpoint(ch.checkpointNumber)))
362355
).filter(isDefined);
363356

364-
const olbBlocks: PublishedL2Block[] = [];
357+
const publishedBlocks: CheckpointedL2Block[] = [];
365358
for (let i = 0; i < checkpoints.length; i++) {
366359
const blockForCheckpoint = blocks[i][0];
367360
const checkpoint = checkpoints[i];
368361
if (checkpoint.checkpointNumber > provenCheckpointNumber && proven === true) {
369-
// this checkpointisn't proven and we only want proven
362+
// this checkpoint isn't proven and we only want proven
370363
continue;
371364
}
372-
const oldCheckpoint = new Checkpoint(
373-
blockForCheckpoint.archive,
374-
checkpoint.header,
375-
[blockForCheckpoint],
365+
const publishedBlock = new CheckpointedL2Block(
376366
checkpoint.checkpointNumber,
377-
);
378-
const oldBlock = L2Block.fromCheckpoint(oldCheckpoint);
379-
const publishedBlock = new PublishedL2Block(
380-
oldBlock,
367+
blockForCheckpoint,
381368
checkpoint.l1,
382369
checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
383370
);
384-
olbBlocks.push(publishedBlock);
371+
publishedBlocks.push(publishedBlock);
385372
}
386-
return olbBlocks;
373+
return publishedBlocks;
387374
}
388375

389-
public async getBlock(number: BlockNumber): Promise<L2Block | undefined> {
376+
public async getBlock(number: BlockNumber): Promise<L2BlockNew | undefined> {
390377
// If the number provided is -ve, then return the latest block.
391378
if (number < 0) {
392379
number = await this.store.getLatestBlockNumber();
393380
}
394381
if (number === 0) {
395382
return undefined;
396383
}
397-
const publishedBlocks = await this.getPublishedBlocks(number, 1);
398-
if (publishedBlocks.length === 0) {
399-
return undefined;
384+
return this.store.getBlock(number);
385+
}
386+
387+
public async getBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<L2BlockNew[]> {
388+
const blocks = await this.store.getBlocks(from, limit);
389+
390+
if (proven === true) {
391+
const provenBlockNumber = await this.store.getProvenBlockNumber();
392+
return blocks.filter(b => b.number <= provenBlockNumber);
400393
}
401-
return publishedBlocks[0].block;
394+
return blocks;
402395
}
403396

404-
public async getBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<L2Block[]> {
405-
const publishedBlocks = await this.getPublishedBlocks(from, limit, proven);
406-
return publishedBlocks.map(x => x.block);
397+
public getPublishedBlockByHash(blockHash: Fr): Promise<CheckpointedL2Block | undefined> {
398+
return this.store.getCheckpointedBlockByHash(blockHash);
407399
}
408400

409-
public async getPublishedBlockByHash(blockHash: Fr): Promise<PublishedL2Block | undefined> {
410-
const checkpointedBlock = await this.store.getCheckpointedBlockByHash(blockHash);
411-
return this.buildOldBlockFromCheckpointedBlock(checkpointedBlock);
401+
public getPublishedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
402+
return this.store.getCheckpointedBlockByArchive(archive);
412403
}
413404

414-
public async getPublishedBlockByArchive(archive: Fr): Promise<PublishedL2Block | undefined> {
415-
const checkpointedBlock = await this.store.getCheckpointedBlockByArchive(archive);
416-
return this.buildOldBlockFromCheckpointedBlock(checkpointedBlock);
405+
public async getL2BlockNewByHash(blockHash: Fr): Promise<L2BlockNew | undefined> {
406+
const checkpointedBlock = await this.store.getCheckpointedBlockByHash(blockHash);
407+
return checkpointedBlock?.block;
417408
}
418409

419-
private async buildOldBlockFromCheckpointedBlock(
420-
checkpointedBlock: CheckpointedL2Block | undefined,
421-
): Promise<PublishedL2Block | undefined> {
422-
if (!checkpointedBlock) {
423-
return undefined;
424-
}
425-
const checkpoint = await this.store.getCheckpointData(checkpointedBlock.checkpointNumber);
426-
if (!checkpoint) {
427-
return checkpoint;
428-
}
429-
const fullCheckpoint = new Checkpoint(
430-
checkpointedBlock?.block.archive,
431-
checkpoint?.header,
432-
[checkpointedBlock.block],
433-
checkpoint.checkpointNumber,
434-
);
435-
const oldBlock = L2Block.fromCheckpoint(fullCheckpoint);
436-
const published = new PublishedL2Block(
437-
oldBlock,
438-
checkpoint.l1,
439-
checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
440-
);
441-
return published;
410+
public async getL2BlockNewByArchive(archive: Fr): Promise<L2BlockNew | undefined> {
411+
const checkpointedBlock = await this.store.getCheckpointedBlockByArchive(archive);
412+
return checkpointedBlock?.block;
442413
}
443414
}

yarn-project/archiver/src/test/mock_archiver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { CheckpointNumber } from '@aztec/foundation/branded-types';
22
import type { Fr } from '@aztec/foundation/curves/bn254';
3-
import { L2Block, type L2BlockSource } from '@aztec/stdlib/block';
3+
import type { L2BlockSource } from '@aztec/stdlib/block';
44
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
55
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
66

@@ -57,7 +57,7 @@ export class MockPrefilledArchiver extends MockArchiver {
5757

5858
const fromBlock = this.l2Blocks.length;
5959
// TODO: Add L2 blocks and checkpoints separately once archiver has the apis for that.
60-
this.addBlocks(this.prefilled.slice(fromBlock, fromBlock + numBlocks).map(c => L2Block.fromCheckpoint(c)));
60+
this.addBlocks(this.prefilled.slice(fromBlock, fromBlock + numBlocks).flatMap(c => c.blocks));
6161
return Promise.resolve();
6262
}
6363
}

0 commit comments

Comments
 (0)