Skip to content

Commit c5680d4

Browse files
authored
feat: Provisional blocks can be added to archiver (#18949)
This PR makes a number of changes to the archiver. 1. Blocks are now stored separately from checkpoints within the archiver store. 2. Blocks can be added directly to the archiver as well as being synced via checkpoints from L1. 3. Blocks added independently are then deemed to be 'checkpointed' once their checkpoint is received from L1. 4. The archiver now supports multiple blocks per checkpoint. Some APIs are now considered legacy and will be removed as part of further work. Previously we had `L2Block` and `PublishedL2Block`. We now have `L2BlockNew` and `CheckpointedL2Block`. There are currently APIs for each and this will be updated. Some operations such manually rolling back blocks still assume 1 block per checkpoint. This will be fixed when we tackle re-orgs of the provisional chain more generally.
2 parents 25cd2bc + e4f6f05 commit c5680d4

Some content is hidden

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

43 files changed

+3709
-782
lines changed

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

Lines changed: 680 additions & 42 deletions
Large diffs are not rendered by default.

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

Lines changed: 463 additions & 222 deletions
Large diffs are not rendered by default.

yarn-project/archiver/src/archiver/archiver_store.ts

Lines changed: 88 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import type { Fr } from '@aztec/foundation/curves/bn254';
44
import type { CustomRange } from '@aztec/kv-store';
55
import type { FunctionSelector } from '@aztec/stdlib/abi';
66
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
7-
import type { L2Block, ValidateBlockResult } from '@aztec/stdlib/block';
7+
import type { CheckpointedL2Block, L2BlockNew, ValidateBlockResult } from '@aztec/stdlib/block';
8+
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
89
import type {
910
ContractClassPublic,
1011
ContractInstanceUpdateWithAddress,
@@ -17,14 +18,14 @@ import type { LogFilter, TxScopedL2Log } from '@aztec/stdlib/logs';
1718
import { BlockHeader, type IndexedTxEffect, type TxHash, type TxReceipt } from '@aztec/stdlib/tx';
1819
import type { UInt64 } from '@aztec/stdlib/types';
1920

21+
import type { CheckpointData } from './kv_archiver_store/block_store.js';
2022
import type { InboxMessage } from './structs/inbox_message.js';
21-
import type { PublishedL2Block } from './structs/published.js';
2223

2324
/**
2425
* Represents the latest L1 block processed by the archiver for various objects in L2.
2526
*/
2627
export type ArchiverL1SynchPoint = {
27-
/** Number of the last L1 block that added a new L2 block metadata. */
28+
/** Number of the last L1 block that added a new L2 checkpoint metadata. */
2829
blocksSynchedTo?: bigint;
2930
/** Last L1 block checked for L1 to L2 messages. */
3031
messagesSynchedTo?: L1BlockId;
@@ -45,42 +46,95 @@ export interface ArchiverDataStore {
4546
* @param opts.force - If true, the blocks will be added even if they have gaps.
4647
* @returns True if the operation is successful.
4748
*/
48-
addBlocks(blocks: PublishedL2Block[], opts?: { force?: boolean }): Promise<boolean>;
49+
addBlocks(blocks: L2BlockNew[], opts?: { force?: boolean }): Promise<boolean>;
4950

5051
/**
51-
* Unwinds blocks from the database
52+
* Appends new checkpoints, and their blocks to the store's collection
53+
* @param checkpoints The collectionn of checkpoints to be added
54+
* @returns True if the operation is successful
55+
*/
56+
addCheckpoints(checkpoints: PublishedCheckpoint[]): Promise<boolean>;
57+
58+
/**
59+
* Retrieves all blocks for the requested chackpoint
60+
* @param checkpointNumber Retreieves all blocks for the given checkpoint
61+
* @returns The collection of blocks for the requested checkpoint if available (undefined otherwise)
62+
*/
63+
getBlocksForCheckpoint(checkpointNumber: CheckpointNumber): Promise<L2BlockNew[] | undefined>;
64+
65+
/**
66+
* Returns an array of checkpoint objects
67+
* @param from The first checkpoint number to be retrieved
68+
* @param limit The maximum number of chackpoints to retrieve
69+
* @returns The array of requested checkpoint data objects
70+
*/
71+
getRangeOfCheckpoints(from: CheckpointNumber, limit: number): Promise<CheckpointData[]>;
72+
73+
/**
74+
* Unwinds checkpoints from the database
5275
* @param from - The tip of the chain, passed for verification purposes,
5376
* ensuring that we don't end up deleting something we did not intend
54-
* @param blocksToUnwind - The number of blocks we are to unwind
77+
* @param checkpointsToUnwind - The number of checkpoints we are to unwind
5578
* @returns True if the operation is successful
5679
*/
57-
unwindBlocks(from: BlockNumber, blocksToUnwind: number): Promise<boolean>;
80+
unwindCheckpoints(from: CheckpointNumber, checkpointsToUnwind: number): Promise<boolean>;
5881

5982
/**
6083
* Returns the block for the given number, or undefined if not exists.
6184
* @param number - The block number to return.
6285
*/
63-
getPublishedBlock(number: BlockNumber): Promise<PublishedL2Block | undefined>;
86+
getCheckpointedBlock(number: number): Promise<CheckpointedL2Block | undefined>;
6487

6588
/**
6689
* Returns the block for the given hash, or undefined if not exists.
6790
* @param blockHash - The block hash to return.
6891
*/
69-
getPublishedBlockByHash(blockHash: Fr): Promise<PublishedL2Block | undefined>;
92+
getCheckpointedBlockByHash(blockHash: Fr): Promise<CheckpointedL2Block | undefined>;
7093

7194
/**
7295
* Returns the block for the given archive root, or undefined if not exists.
7396
* @param archive - The archive root to return.
7497
*/
75-
getPublishedBlockByArchive(archive: Fr): Promise<PublishedL2Block | undefined>;
98+
getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined>;
99+
100+
/**
101+
* Returns checkpoint data for the requested checkpoint number
102+
* @param checkpointNumber - The checkpoint requested
103+
* @returns The checkpoint data or undefined if not found
104+
*/
105+
getCheckpointData(checkpointNumber: CheckpointNumber): Promise<CheckpointData | undefined>;
106+
107+
/**
108+
* Returns the number of the latest block
109+
* @returns The number of the latest block
110+
*/
111+
getLatestBlockNumber(): Promise<BlockNumber>;
112+
113+
/**
114+
* Returns the block for the given number, or undefined if not exists.
115+
* @param number - The block number to return.
116+
*/
117+
getBlock(number: number): Promise<L2BlockNew | undefined>;
118+
119+
/**
120+
* Returns the block for the given hash, or undefined if not exists.
121+
* @param blockHash - The block hash to return.
122+
*/
123+
getBlockByHash(blockHash: Fr): Promise<L2BlockNew | undefined>;
124+
125+
/**
126+
* Returns the block for the given archive root, or undefined if not exists.
127+
* @param archive - The archive root to return.
128+
*/
129+
getBlockByArchive(archive: Fr): Promise<L2BlockNew | undefined>;
76130

77131
/**
78132
* Gets up to `limit` amount of published L2 blocks starting from `from`.
79133
* @param from - Number of the first block to return (inclusive).
80134
* @param limit - The number of blocks to return.
81135
* @returns The requested L2 blocks.
82136
*/
83-
getPublishedBlocks(from: BlockNumber, limit: number): Promise<PublishedL2Block[]>;
137+
getBlocks(from: number, limit: number): Promise<L2BlockNew[]>;
84138

85139
/**
86140
* Gets up to `limit` amount of L2 block headers starting from `from`.
@@ -121,8 +175,8 @@ export interface ArchiverDataStore {
121175
* @param blocks - The blocks for which to add the logs.
122176
* @returns True if the operation is successful.
123177
*/
124-
addLogs(blocks: L2Block[]): Promise<boolean>;
125-
deleteLogs(blocks: L2Block[]): Promise<boolean>;
178+
addLogs(blocks: L2BlockNew[]): Promise<boolean>;
179+
deleteLogs(blocks: L2BlockNew[]): Promise<boolean>;
126180

127181
/**
128182
* Append L1 to L2 messages to the store.
@@ -178,25 +232,37 @@ export interface ArchiverDataStore {
178232
* Gets the number of the latest L2 block processed.
179233
* @returns The number of the latest L2 block processed.
180234
*/
181-
getSynchedL2BlockNumber(): Promise<BlockNumber>;
235+
getCheckpointedL2BlockNumber(): Promise<BlockNumber>;
236+
237+
/**
238+
* Gets the number of the latest published checkpoint processed.
239+
* @returns The number of the latest published checkpoint processed
240+
*/
241+
getSynchedCheckpointNumber(): Promise<CheckpointNumber>;
242+
243+
/**
244+
* Gets the number of the latest proven checkpoint processed.
245+
* @returns The number of the latest proven checkpoint processed.
246+
*/
247+
getProvenCheckpointNumber(): Promise<CheckpointNumber>;
182248

183249
/**
184-
* Gets the number of the latest proven L2 block processed.
185-
* @returns The number of the latest proven L2 block processed.
250+
* Returns the number of the most recent proven block
251+
* @returns The number of the most recent proven block
186252
*/
187-
getProvenL2BlockNumber(): Promise<BlockNumber>;
253+
getProvenBlockNumber(): Promise<BlockNumber>;
188254

189255
/**
190-
* Stores the number of the latest proven L2 block processed.
191-
* @param l2BlockNumber - The number of the latest proven L2 block processed.
256+
* Stores the number of the latest proven checkpoint processed.
257+
* @param checkpointNumber - The number of the latest proven checkpoint processed.
192258
*/
193-
setProvenL2BlockNumber(l2BlockNumber: BlockNumber): Promise<void>;
259+
setProvenCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<void>;
194260

195261
/**
196-
* Stores the l1 block number that blocks have been synched until
262+
* Stores the l1 block number that checkpoints have been synched until
197263
* @param l1BlockNumber - The l1 block number
198264
*/
199-
setBlockSynchedL1BlockNumber(l1BlockNumber: bigint): Promise<void>;
265+
setCheckpointSynchedL1BlockNumber(l1BlockNumber: bigint): Promise<void>;
200266

201267
/**
202268
* Stores the l1 block that messages have been synched until

0 commit comments

Comments
 (0)