@@ -4,14 +4,7 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
44import { isDefined } from '@aztec/foundation/types' ;
55import type { FunctionSelector } from '@aztec/stdlib/abi' ;
66import 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' ;
158import { Checkpoint , PublishedCheckpoint } from '@aztec/stdlib/checkpoint' ;
169import type { ContractClassPublic , ContractDataSource , ContractInstanceWithAddress } from '@aztec/stdlib/contract' ;
1710import { 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}
0 commit comments