@aztec/archiver 0.28.1 → 0.30.0

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 (55) hide show
  1. package/dest/archiver/archiver.d.ts +13 -53
  2. package/dest/archiver/archiver.d.ts.map +1 -1
  3. package/dest/archiver/archiver.js +60 -199
  4. package/dest/archiver/archiver_store.d.ts +21 -67
  5. package/dest/archiver/archiver_store.d.ts.map +1 -1
  6. package/dest/archiver/archiver_store_test_suite.d.ts.map +1 -1
  7. package/dest/archiver/archiver_store_test_suite.js +60 -199
  8. package/dest/archiver/config.d.ts.map +1 -1
  9. package/dest/archiver/config.js +6 -2
  10. package/dest/archiver/data_retrieval.d.ts +10 -32
  11. package/dest/archiver/data_retrieval.d.ts.map +1 -1
  12. package/dest/archiver/data_retrieval.js +13 -67
  13. package/dest/archiver/eth_log_handlers.d.ts +7 -38
  14. package/dest/archiver/eth_log_handlers.d.ts.map +1 -1
  15. package/dest/archiver/eth_log_handlers.js +9 -77
  16. package/dest/archiver/kv_archiver_store/block_store.d.ts +5 -4
  17. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
  18. package/dest/archiver/kv_archiver_store/block_store.js +12 -15
  19. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +15 -56
  20. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
  21. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +23 -87
  22. package/dest/archiver/kv_archiver_store/message_store.d.ts +12 -43
  23. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +1 -1
  24. package/dest/archiver/kv_archiver_store/message_store.js +32 -141
  25. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts +8 -41
  26. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts.map +1 -1
  27. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.js +22 -79
  28. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +20 -81
  29. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +1 -1
  30. package/dest/archiver/memory_archiver_store/memory_archiver_store.js +30 -143
  31. package/dest/index.d.ts.map +1 -1
  32. package/dest/index.js +3 -15
  33. package/dest/rpc/archiver_client.d.ts.map +1 -1
  34. package/dest/rpc/archiver_client.js +2 -6
  35. package/dest/rpc/archiver_server.d.ts.map +1 -1
  36. package/dest/rpc/archiver_server.js +2 -6
  37. package/package.json +9 -9
  38. package/src/archiver/archiver.ts +80 -267
  39. package/src/archiver/archiver_store.ts +22 -76
  40. package/src/archiver/archiver_store_test_suite.ts +78 -243
  41. package/src/archiver/config.ts +6 -0
  42. package/src/archiver/data_retrieval.ts +19 -101
  43. package/src/archiver/eth_log_handlers.ts +14 -108
  44. package/src/archiver/kv_archiver_store/block_store.ts +13 -14
  45. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +23 -93
  46. package/src/archiver/kv_archiver_store/message_store.ts +38 -169
  47. package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +21 -90
  48. package/src/archiver/memory_archiver_store/memory_archiver_store.ts +33 -161
  49. package/src/index.ts +1 -15
  50. package/src/rpc/archiver_client.ts +0 -8
  51. package/src/rpc/archiver_server.ts +0 -8
  52. package/dest/archiver/kv_archiver_store/contract_store.d.ts +0 -26
  53. package/dest/archiver/kv_archiver_store/contract_store.d.ts.map +0 -1
  54. package/dest/archiver/kv_archiver_store/contract_store.js +0 -49
  55. package/src/archiver/kv_archiver_store/contract_store.ts +0 -55
@@ -1,30 +1,26 @@
1
- import { Body, L1ToL2Message, NewInboxLeaf } from '@aztec/circuit-types';
2
- import { AppendOnlyTreeSnapshot, Fr, Header } from '@aztec/circuits.js';
1
+ import { Body, InboxLeaf } from '@aztec/circuit-types';
2
+ import { AppendOnlyTreeSnapshot, Header } from '@aztec/circuits.js';
3
3
  import { EthAddress } from '@aztec/foundation/eth-address';
4
4
 
5
5
  import { PublicClient } from 'viem';
6
6
 
7
7
  import {
8
- getL1ToL2MessageCancelledLogs,
9
8
  getL2BlockProcessedLogs,
10
9
  getLeafInsertedLogs,
11
- getPendingL1ToL2MessageLogs,
12
10
  getTxsPublishedLogs,
13
- processCancelledL1ToL2MessagesLogs,
14
11
  processL2BlockProcessedLogs,
15
12
  processLeafInsertedLogs,
16
- processPendingL1ToL2MessageAddedLogs,
17
13
  processTxsPublishedLogs,
18
14
  } from './eth_log_handlers.js';
19
15
 
20
16
  /**
21
17
  * Data retrieved from logs
22
18
  */
23
- type DataRetrieval<T> = {
19
+ export type DataRetrieval<T> = {
24
20
  /**
25
- * The next block number.
21
+ * Blocknumber of the last L1 block from which we obtained data.
26
22
  */
27
- nextEthBlockNumber: bigint;
23
+ lastProcessedL1BlockNumber: bigint;
28
24
  /**
29
25
  * The data returned.
30
26
  */
@@ -39,7 +35,7 @@ type DataRetrieval<T> = {
39
35
  * @param searchStartBlock - The block number to use for starting the search.
40
36
  * @param searchEndBlock - The highest block number that we should search up to.
41
37
  * @param expectedNextL2BlockNum - The next L2 block number that we expect to find.
42
- * @returns An array of tuples representing block metadata including the header, archive tree snapshot, and associated l1 block number; as well as the next eth block to search from.
38
+ * @returns An array of tuples representing block metadata including the header, archive tree snapshot; as well as the next eth block to search from.
43
39
  */
44
40
  export async function retrieveBlockMetadataFromRollup(
45
41
  publicClient: PublicClient,
@@ -48,8 +44,8 @@ export async function retrieveBlockMetadataFromRollup(
48
44
  searchStartBlock: bigint,
49
45
  searchEndBlock: bigint,
50
46
  expectedNextL2BlockNum: bigint,
51
- ): Promise<DataRetrieval<[Header, AppendOnlyTreeSnapshot, bigint]>> {
52
- const retrievedBlockMetadata: [Header, AppendOnlyTreeSnapshot, bigint][] = [];
47
+ ): Promise<DataRetrieval<[Header, AppendOnlyTreeSnapshot]>> {
48
+ const retrievedBlockMetadata: [Header, AppendOnlyTreeSnapshot][] = [];
53
49
  do {
54
50
  if (searchStartBlock > searchEndBlock) {
55
51
  break;
@@ -73,7 +69,7 @@ export async function retrieveBlockMetadataFromRollup(
73
69
  searchStartBlock = l2BlockProcessedLogs[l2BlockProcessedLogs.length - 1].blockNumber! + 1n;
74
70
  expectedNextL2BlockNum += BigInt(newBlockMetadata.length);
75
71
  } while (blockUntilSynced && searchStartBlock <= searchEndBlock);
76
- return { nextEthBlockNumber: searchStartBlock, retrievedData: retrievedBlockMetadata };
72
+ return { lastProcessedL1BlockNumber: searchStartBlock - 1n, retrievedData: retrievedBlockMetadata };
77
73
  }
78
74
 
79
75
  /**
@@ -112,116 +108,38 @@ export async function retrieveBlockBodiesFromAvailabilityOracle(
112
108
  retrievedBlockBodies.push(...newBlockBodies);
113
109
  searchStartBlock = l2TxsPublishedLogs[l2TxsPublishedLogs.length - 1].blockNumber! + 1n;
114
110
  } while (blockUntilSynced && searchStartBlock <= searchEndBlock);
115
- return { nextEthBlockNumber: searchStartBlock, retrievedData: retrievedBlockBodies };
111
+ return { lastProcessedL1BlockNumber: searchStartBlock - 1n, retrievedData: retrievedBlockBodies };
116
112
  }
117
113
 
118
114
  /**
119
- * Fetch new pending L1 to L2 messages.
115
+ * Fetch L1 to L2 messages.
120
116
  * @param publicClient - The viem public client to use for transaction retrieval.
121
117
  * @param inboxAddress - The address of the inbox contract to fetch messages from.
122
118
  * @param blockUntilSynced - If true, blocks until the archiver has fully synced.
123
119
  * @param searchStartBlock - The block number to use for starting the search.
124
120
  * @param searchEndBlock - The highest block number that we should search up to.
125
- * @returns An array of L1ToL2Message and next eth block to search from.
121
+ * @returns An array of InboxLeaf and next eth block to search from.
126
122
  */
127
- export async function retrieveNewPendingL1ToL2Messages(
123
+ export async function retrieveL1ToL2Messages(
128
124
  publicClient: PublicClient,
129
125
  inboxAddress: EthAddress,
130
126
  blockUntilSynced: boolean,
131
127
  searchStartBlock: bigint,
132
128
  searchEndBlock: bigint,
133
- ): Promise<DataRetrieval<[L1ToL2Message, bigint]>> {
134
- const retrievedNewL1ToL2Messages: [L1ToL2Message, bigint][] = [];
129
+ ): Promise<DataRetrieval<InboxLeaf>> {
130
+ const retrievedL1ToL2Messages: InboxLeaf[] = [];
135
131
  do {
136
132
  if (searchStartBlock > searchEndBlock) {
137
133
  break;
138
134
  }
139
- const newL1ToL2MessageLogs = await getPendingL1ToL2MessageLogs(
140
- publicClient,
141
- inboxAddress,
142
- searchStartBlock,
143
- searchEndBlock,
144
- );
145
- if (newL1ToL2MessageLogs.length === 0) {
146
- break;
147
- }
148
- const newL1ToL2Messages = processPendingL1ToL2MessageAddedLogs(newL1ToL2MessageLogs);
149
- retrievedNewL1ToL2Messages.push(...newL1ToL2Messages);
150
- // handles the case when there are no new messages:
151
- searchStartBlock = (newL1ToL2MessageLogs.findLast(msgLog => !!msgLog)?.blockNumber || searchStartBlock) + 1n;
152
- } while (blockUntilSynced && searchStartBlock <= searchEndBlock);
153
- return { nextEthBlockNumber: searchStartBlock, retrievedData: retrievedNewL1ToL2Messages };
154
- }
155
-
156
- /**
157
- * Fetch new L1 to L2 messages.
158
- * @param publicClient - The viem public client to use for transaction retrieval.
159
- * @param newInboxAddress - The address of the inbox contract to fetch messages from.
160
- * @param blockUntilSynced - If true, blocks until the archiver has fully synced.
161
- * @param searchStartBlock - The block number to use for starting the search.
162
- * @param searchEndBlock - The highest block number that we should search up to.
163
- * @returns An array of NewInboxLeaf and next eth block to search from.
164
- */
165
- export async function retrieveNewL1ToL2Messages(
166
- publicClient: PublicClient,
167
- newInboxAddress: EthAddress,
168
- blockUntilSynced: boolean,
169
- searchStartBlock: bigint,
170
- searchEndBlock: bigint,
171
- ): Promise<DataRetrieval<NewInboxLeaf>> {
172
- const retrievedNewL1ToL2Messages: NewInboxLeaf[] = [];
173
- do {
174
- if (searchStartBlock > searchEndBlock) {
175
- break;
176
- }
177
- const leafInsertedLogs = await getLeafInsertedLogs(publicClient, newInboxAddress, searchStartBlock, searchEndBlock);
135
+ const leafInsertedLogs = await getLeafInsertedLogs(publicClient, inboxAddress, searchStartBlock, searchEndBlock);
178
136
  if (leafInsertedLogs.length === 0) {
179
137
  break;
180
138
  }
181
- const newL1ToL2Messages = processLeafInsertedLogs(leafInsertedLogs);
182
- retrievedNewL1ToL2Messages.push(...newL1ToL2Messages);
139
+ const l1ToL2Messages = processLeafInsertedLogs(leafInsertedLogs);
140
+ retrievedL1ToL2Messages.push(...l1ToL2Messages);
183
141
  // handles the case when there are no new messages:
184
142
  searchStartBlock = (leafInsertedLogs.findLast(msgLog => !!msgLog)?.blockNumber || searchStartBlock) + 1n;
185
143
  } while (blockUntilSynced && searchStartBlock <= searchEndBlock);
186
- return { nextEthBlockNumber: searchStartBlock, retrievedData: retrievedNewL1ToL2Messages };
187
- }
188
-
189
- /**
190
- * Fetch newly cancelled L1 to L2 messages.
191
- * @param publicClient - The viem public client to use for transaction retrieval.
192
- * @param inboxAddress - The address of the inbox contract to fetch messages from.
193
- * @param blockUntilSynced - If true, blocks until the archiver has fully synced.
194
- * @param searchStartBlock - The block number to use for starting the search.
195
- * @param searchEndBlock - The highest block number that we should search up to.
196
- * @returns An array of entry keys that were cancelled and next eth block to search from.
197
- * TODO(#4492): Nuke the following when purging the old inbox
198
- */
199
- export async function retrieveNewCancelledL1ToL2Messages(
200
- publicClient: PublicClient,
201
- inboxAddress: EthAddress,
202
- blockUntilSynced: boolean,
203
- searchStartBlock: bigint,
204
- searchEndBlock: bigint,
205
- ): Promise<DataRetrieval<[Fr, bigint]>> {
206
- const retrievedNewCancelledL1ToL2Messages: [Fr, bigint][] = [];
207
- do {
208
- if (searchStartBlock > searchEndBlock) {
209
- break;
210
- }
211
- const newL1ToL2MessageCancelledLogs = await getL1ToL2MessageCancelledLogs(
212
- publicClient,
213
- inboxAddress,
214
- searchStartBlock,
215
- searchEndBlock,
216
- );
217
- if (newL1ToL2MessageCancelledLogs.length === 0) {
218
- break;
219
- }
220
- const newCancelledL1ToL2Messages = processCancelledL1ToL2MessagesLogs(newL1ToL2MessageCancelledLogs);
221
- retrievedNewCancelledL1ToL2Messages.push(...newCancelledL1ToL2Messages);
222
- // handles the case when there are no new messages:
223
- searchStartBlock =
224
- (newL1ToL2MessageCancelledLogs.findLast(msgLog => !!msgLog)?.blockNumber || searchStartBlock) + 1n;
225
- } while (blockUntilSynced && searchStartBlock <= searchEndBlock);
226
- return { nextEthBlockNumber: searchStartBlock, retrievedData: retrievedNewCancelledL1ToL2Messages };
144
+ return { lastProcessedL1BlockNumber: searchStartBlock - 1n, retrievedData: retrievedL1ToL2Messages };
227
145
  }
@@ -1,10 +1,9 @@
1
- import { Body, L1Actor, L1ToL2Message, L2Actor, NewInboxLeaf } from '@aztec/circuit-types';
1
+ import { Body, InboxLeaf } from '@aztec/circuit-types';
2
2
  import { AppendOnlyTreeSnapshot, Header } from '@aztec/circuits.js';
3
- import { AztecAddress } from '@aztec/foundation/aztec-address';
4
3
  import { EthAddress } from '@aztec/foundation/eth-address';
5
4
  import { Fr } from '@aztec/foundation/fields';
6
5
  import { numToUInt32BE } from '@aztec/foundation/serialize';
7
- import { AvailabilityOracleAbi, InboxAbi, NewInboxAbi, RollupAbi } from '@aztec/l1-artifacts';
6
+ import { AvailabilityOracleAbi, InboxAbi, RollupAbi } from '@aztec/l1-artifacts';
8
7
 
9
8
  import { Hex, Log, PublicClient, decodeFunctionData, getAbiItem, getAddress, hexToBytes } from 'viem';
10
9
 
@@ -14,72 +13,29 @@ import { Hex, Log, PublicClient, decodeFunctionData, getAbiItem, getAddress, hex
14
13
  * @returns Array of all processed LeafInserted logs
15
14
  */
16
15
  export function processLeafInsertedLogs(
17
- logs: Log<bigint, number, false, undefined, true, typeof NewInboxAbi, 'LeafInserted'>[],
18
- ): NewInboxLeaf[] {
19
- const leaves: NewInboxLeaf[] = [];
16
+ logs: Log<bigint, number, false, undefined, true, typeof InboxAbi, 'LeafInserted'>[],
17
+ ): InboxLeaf[] {
18
+ const leaves: InboxLeaf[] = [];
20
19
  for (const log of logs) {
21
20
  const { blockNumber, index, value } = log.args;
22
- leaves.push(new NewInboxLeaf(blockNumber, index, Fr.fromString(value)));
21
+ leaves.push(new InboxLeaf(blockNumber, index, Fr.fromString(value)));
23
22
  }
24
23
  return leaves;
25
24
  }
26
25
 
27
- /**
28
- * Processes newly received MessageAdded (L1 to L2) logs.
29
- * @param logs - MessageAdded logs.
30
- * @returns Array of all Pending L1 to L2 messages that were processed
31
- */
32
- export function processPendingL1ToL2MessageAddedLogs(
33
- logs: Log<bigint, number, false, undefined, true, typeof InboxAbi, 'MessageAdded'>[],
34
- ): [L1ToL2Message, bigint][] {
35
- const l1ToL2Messages: [L1ToL2Message, bigint][] = [];
36
- for (const log of logs) {
37
- const { sender, senderChainId, recipient, recipientVersion, content, secretHash, deadline, fee, entryKey } =
38
- log.args;
39
- l1ToL2Messages.push([
40
- new L1ToL2Message(
41
- new L1Actor(EthAddress.fromString(sender), Number(senderChainId)),
42
- new L2Actor(AztecAddress.fromString(recipient), Number(recipientVersion)),
43
- Fr.fromString(content),
44
- Fr.fromString(secretHash),
45
- deadline,
46
- Number(fee),
47
- Fr.fromString(entryKey),
48
- ),
49
- log.blockNumber!,
50
- ]);
51
- }
52
- return l1ToL2Messages;
53
- }
54
-
55
- /**
56
- * Process newly received L1ToL2MessageCancelled logs.
57
- * @param logs - L1ToL2MessageCancelled logs.
58
- * @returns Array of entry keys of the L1 to L2 messages that were cancelled
59
- */
60
- export function processCancelledL1ToL2MessagesLogs(
61
- logs: Log<bigint, number, false, undefined, true, typeof InboxAbi, 'L1ToL2MessageCancelled'>[],
62
- ): [Fr, bigint][] {
63
- const cancelledL1ToL2Messages: [Fr, bigint][] = [];
64
- for (const log of logs) {
65
- cancelledL1ToL2Messages.push([Fr.fromString(log.args.entryKey), log.blockNumber!]);
66
- }
67
- return cancelledL1ToL2Messages;
68
- }
69
-
70
26
  /**
71
27
  * Processes newly received L2BlockProcessed logs.
72
28
  * @param publicClient - The viem public client to use for transaction retrieval.
73
29
  * @param expectedL2BlockNumber - The next expected L2 block number.
74
30
  * @param logs - L2BlockProcessed logs.
75
- * @returns - An array of tuples representing block metadata including the header, archive tree snapshot, and associated l1 block number.
31
+ * @returns - An array of tuples representing block metadata including the header, archive tree snapshot.
76
32
  */
77
33
  export async function processL2BlockProcessedLogs(
78
34
  publicClient: PublicClient,
79
35
  expectedL2BlockNumber: bigint,
80
36
  logs: Log<bigint, number, false, undefined, true, typeof RollupAbi, 'L2BlockProcessed'>[],
81
- ): Promise<[Header, AppendOnlyTreeSnapshot, bigint][]> {
82
- const retrievedBlockMetadata: [Header, AppendOnlyTreeSnapshot, bigint][] = [];
37
+ ): Promise<[Header, AppendOnlyTreeSnapshot][]> {
38
+ const retrievedBlockMetadata: [Header, AppendOnlyTreeSnapshot][] = [];
83
39
  for (const log of logs) {
84
40
  const blockNum = log.args.blockNumber;
85
41
  if (blockNum !== expectedL2BlockNumber) {
@@ -92,7 +48,7 @@ export async function processL2BlockProcessedLogs(
92
48
  log.args.blockNumber,
93
49
  );
94
50
 
95
- retrievedBlockMetadata.push([header, archive, log.blockNumber!]);
51
+ retrievedBlockMetadata.push([header, archive]);
96
52
  expectedL2BlockNumber++;
97
53
  }
98
54
 
@@ -235,73 +191,23 @@ export function getTxsPublishedLogs(
235
191
  }
236
192
 
237
193
  /**
238
- * Get relevant `MessageAdded` logs emitted by Inbox on chain.
239
- * @param publicClient - The viem public client to use for transaction retrieval.
240
- * @param inboxAddress - The address of the inbox contract.
241
- * @param fromBlock - First block to get logs from (inclusive).
242
- * @param toBlock - Last block to get logs from (inclusive).
243
- * @returns An array of `MessageAdded` logs.
244
- */
245
- export function getPendingL1ToL2MessageLogs(
246
- publicClient: PublicClient,
247
- inboxAddress: EthAddress,
248
- fromBlock: bigint,
249
- toBlock: bigint,
250
- ): Promise<Log<bigint, number, false, undefined, true, typeof InboxAbi, 'MessageAdded'>[]> {
251
- return publicClient.getLogs({
252
- address: getAddress(inboxAddress.toString()),
253
- event: getAbiItem({
254
- abi: InboxAbi,
255
- name: 'MessageAdded',
256
- }),
257
- fromBlock,
258
- toBlock: toBlock + 1n, // the toBlock argument in getLogs is exclusive
259
- });
260
- }
261
-
262
- /**
263
- * Get relevant `L1ToL2MessageCancelled` logs emitted by Inbox on chain when pending messages are cancelled
194
+ * Get relevant `LeafInserted` logs emitted by Inbox on chain.
264
195
  * @param publicClient - The viem public client to use for transaction retrieval.
265
196
  * @param inboxAddress - The address of the inbox contract.
266
197
  * @param fromBlock - First block to get logs from (inclusive).
267
198
  * @param toBlock - Last block to get logs from (inclusive).
268
- * @returns An array of `L1ToL2MessageCancelled` logs.
199
+ * @returns An array of `LeafInserted` logs.
269
200
  */
270
- export function getL1ToL2MessageCancelledLogs(
201
+ export function getLeafInsertedLogs(
271
202
  publicClient: PublicClient,
272
203
  inboxAddress: EthAddress,
273
204
  fromBlock: bigint,
274
205
  toBlock: bigint,
275
- ): Promise<Log<bigint, number, false, undefined, true, typeof InboxAbi, 'L1ToL2MessageCancelled'>[]> {
206
+ ): Promise<Log<bigint, number, false, undefined, true, typeof InboxAbi, 'LeafInserted'>[]> {
276
207
  return publicClient.getLogs({
277
208
  address: getAddress(inboxAddress.toString()),
278
209
  event: getAbiItem({
279
210
  abi: InboxAbi,
280
- name: 'L1ToL2MessageCancelled',
281
- }),
282
- fromBlock,
283
- toBlock: toBlock + 1n, // the toBlock argument in getLogs is exclusive
284
- });
285
- }
286
-
287
- /**
288
- * Get relevant `LeafInserted` logs emitted by NewInbox on chain.
289
- * @param publicClient - The viem public client to use for transaction retrieval.
290
- * @param newInboxAddress - The address of the new inbox contract.
291
- * @param fromBlock - First block to get logs from (inclusive).
292
- * @param toBlock - Last block to get logs from (inclusive).
293
- * @returns An array of `LeafInserted` logs.
294
- */
295
- export function getLeafInsertedLogs(
296
- publicClient: PublicClient,
297
- newInboxAddress: EthAddress,
298
- fromBlock: bigint,
299
- toBlock: bigint,
300
- ): Promise<Log<bigint, number, false, undefined, true, typeof NewInboxAbi, 'LeafInserted'>[]> {
301
- return publicClient.getLogs({
302
- address: getAddress(newInboxAddress.toString()),
303
- event: getAbiItem({
304
- abi: NewInboxAbi,
305
211
  name: 'LeafInserted',
306
212
  }),
307
213
  fromBlock,
@@ -1,14 +1,14 @@
1
1
  import { L2Block, TxEffect, TxHash, TxReceipt, TxStatus } from '@aztec/circuit-types';
2
2
  import { AppendOnlyTreeSnapshot, AztecAddress, Header, INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js';
3
3
  import { createDebugLogger } from '@aztec/foundation/log';
4
- import { AztecKVStore, AztecMap, Range } from '@aztec/kv-store';
4
+ import { AztecKVStore, AztecMap, AztecSingleton, Range } from '@aztec/kv-store';
5
5
 
6
+ import { DataRetrieval } from '../data_retrieval.js';
6
7
  import { BlockBodyStore } from './block_body_store.js';
7
8
 
8
9
  type BlockIndexValue = [blockNumber: number, index: number];
9
10
 
10
11
  type BlockStorage = {
11
- l1BlockNumber: bigint;
12
12
  header: Buffer;
13
13
  archive: Buffer;
14
14
  };
@@ -19,6 +19,8 @@ type BlockStorage = {
19
19
  export class BlockStore {
20
20
  /** Map block number to block data */
21
21
  #blocks: AztecMap<number, BlockStorage>;
22
+ /** Stores L1 block number in which the last processed L2 block was included */
23
+ #lastSynchedL1Block: AztecSingleton<bigint>;
22
24
 
23
25
  /** Index mapping transaction hash (as a string) to its location in a block */
24
26
  #txIndex: AztecMap<string, BlockIndexValue>;
@@ -36,20 +38,20 @@ export class BlockStore {
36
38
  this.#blocks = db.openMap('archiver_blocks');
37
39
  this.#txIndex = db.openMap('archiver_tx_index');
38
40
  this.#contractIndex = db.openMap('archiver_contract_index');
41
+ this.#lastSynchedL1Block = db.openSingleton('archiver_last_synched_l1_block');
39
42
  }
40
43
 
41
44
  /**
42
45
  * Append new blocks to the store's list.
43
- * @param blocks - The L2 blocks to be added to the store.
46
+ * @param blocks - The L2 blocks to be added to the store and the last processed L1 block.
44
47
  * @returns True if the operation is successful.
45
48
  */
46
- addBlocks(blocks: L2Block[]): Promise<boolean> {
49
+ addBlocks(blocks: DataRetrieval<L2Block>): Promise<boolean> {
47
50
  return this.db.transaction(() => {
48
- for (const block of blocks) {
51
+ for (const block of blocks.retrievedData) {
49
52
  void this.#blocks.set(block.number, {
50
53
  header: block.header.toBuffer(),
51
54
  archive: block.archive.toBuffer(),
52
- l1BlockNumber: block.getL1BlockNumber(),
53
55
  });
54
56
 
55
57
  block.getTxs().forEach((tx, i) => {
@@ -57,6 +59,8 @@ export class BlockStore {
57
59
  });
58
60
  }
59
61
 
62
+ void this.#lastSynchedL1Block.set(blocks.lastProcessedL1BlockNumber);
63
+
60
64
  return true;
61
65
  });
62
66
  }
@@ -155,7 +159,7 @@ export class BlockStore {
155
159
  * Gets the number of the latest L2 block processed.
156
160
  * @returns The number of the latest L2 block processed.
157
161
  */
158
- getBlockNumber(): number {
162
+ getSynchedL2BlockNumber(): number {
159
163
  const [lastBlockNumber] = this.#blocks.keys({ reverse: true, limit: 1 });
160
164
  return typeof lastBlockNumber === 'number' ? lastBlockNumber : INITIAL_L2_BLOCK_NUM - 1;
161
165
  }
@@ -164,13 +168,8 @@ export class BlockStore {
164
168
  * Gets the most recent L1 block processed.
165
169
  * @returns The L1 block that published the latest L2 block
166
170
  */
167
- getL1BlockNumber(): bigint {
168
- const [lastBlock] = this.#blocks.values({ reverse: true, limit: 1 });
169
- if (!lastBlock) {
170
- return 0n;
171
- } else {
172
- return lastBlock.l1BlockNumber;
173
- }
171
+ getSynchedL1BlockNumber(): bigint {
172
+ return this.#lastSynchedL1Block.get() ?? 0n;
174
173
  }
175
174
 
176
175
  #computeBlockRange(start: number, limit: number): Required<Pick<Range<number>, 'start' | 'end'>> {
@@ -1,13 +1,11 @@
1
1
  import {
2
2
  Body,
3
- ExtendedContractData,
4
3
  GetUnencryptedLogsResponse,
5
- L1ToL2Message,
4
+ InboxLeaf,
6
5
  L2Block,
7
6
  L2BlockL2Logs,
8
7
  LogFilter,
9
8
  LogType,
10
- NewInboxLeaf,
11
9
  TxEffect,
12
10
  TxHash,
13
11
  TxReceipt,
@@ -19,11 +17,11 @@ import { AztecKVStore } from '@aztec/kv-store';
19
17
  import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts';
20
18
 
21
19
  import { ArchiverDataStore, ArchiverL1SynchPoint } from '../archiver_store.js';
20
+ import { DataRetrieval } from '../data_retrieval.js';
22
21
  import { BlockBodyStore } from './block_body_store.js';
23
22
  import { BlockStore } from './block_store.js';
24
23
  import { ContractClassStore } from './contract_class_store.js';
25
24
  import { ContractInstanceStore } from './contract_instance_store.js';
26
- import { ContractStore } from './contract_store.js';
27
25
  import { LogStore } from './log_store.js';
28
26
  import { MessageStore } from './message_store.js';
29
27
 
@@ -34,7 +32,6 @@ export class KVArchiverDataStore implements ArchiverDataStore {
34
32
  #blockStore: BlockStore;
35
33
  #blockBodyStore: BlockBodyStore;
36
34
  #logStore: LogStore;
37
- #contractStore: ContractStore;
38
35
  #messageStore: MessageStore;
39
36
  #contractClassStore: ContractClassStore;
40
37
  #contractInstanceStore: ContractInstanceStore;
@@ -45,7 +42,6 @@ export class KVArchiverDataStore implements ArchiverDataStore {
45
42
  this.#blockBodyStore = new BlockBodyStore(db);
46
43
  this.#blockStore = new BlockStore(db, this.#blockBodyStore);
47
44
  this.#logStore = new LogStore(db, this.#blockStore, logsMaxPageSize);
48
- this.#contractStore = new ContractStore(db, this.#blockStore);
49
45
  this.#messageStore = new MessageStore(db);
50
46
  this.#contractClassStore = new ContractClassStore(db);
51
47
  this.#contractInstanceStore = new ContractInstanceStore(db);
@@ -92,10 +88,10 @@ export class KVArchiverDataStore implements ArchiverDataStore {
92
88
 
93
89
  /**
94
90
  * Append new blocks to the store's list.
95
- * @param blocks - The L2 blocks to be added to the store.
91
+ * @param blocks - The L2 blocks to be added to the store and the last processed L1 block.
96
92
  * @returns True if the operation is successful.
97
93
  */
98
- addBlocks(blocks: L2Block[]): Promise<boolean> {
94
+ addBlocks(blocks: DataRetrieval<L2Block>): Promise<boolean> {
99
95
  return this.#blockStore.addBlocks(blocks);
100
96
  }
101
97
 
@@ -149,76 +145,31 @@ export class KVArchiverDataStore implements ArchiverDataStore {
149
145
  }
150
146
 
151
147
  /**
152
- * Append new L1 to L2 messages to the store.
153
- * @param messages - The L1 to L2 messages to be added to the store.
154
- * @param lastMessageL1BlockNumber - The L1 block number in which the last message was emitted.
148
+ * Append L1 to L2 messages to the store.
149
+ * @param messages - The L1 to L2 messages to be added to the store and the last processed L1 block.
155
150
  * @returns True if the operation is successful.
156
151
  */
157
- addNewL1ToL2Messages(messages: NewInboxLeaf[], lastMessageL1BlockNumber: bigint): Promise<boolean> {
158
- return Promise.resolve(this.#messageStore.addNewL1ToL2Messages(messages, lastMessageL1BlockNumber));
152
+ addL1ToL2Messages(messages: DataRetrieval<InboxLeaf>): Promise<boolean> {
153
+ return Promise.resolve(this.#messageStore.addL1ToL2Messages(messages));
159
154
  }
160
155
 
161
156
  /**
162
- * Append new pending L1 to L2 messages to the store.
163
- * @param messages - The L1 to L2 messages to be added to the store.
164
- * @param l1BlockNumber - The L1 block number for which to add the messages.
165
- * @returns True if the operation is successful.
166
- */
167
- addPendingL1ToL2Messages(messages: L1ToL2Message[], l1BlockNumber: bigint): Promise<boolean> {
168
- return Promise.resolve(this.#messageStore.addPendingMessages(messages, l1BlockNumber));
169
- }
170
-
171
- /**
172
- * Remove pending L1 to L2 messages from the store (if they were cancelled).
173
- * @param messages - The entry keys to be removed from the store.
174
- * @param l1BlockNumber - The L1 block number for which to remove the messages.
175
- * @returns True if the operation is successful.
176
- */
177
- cancelPendingL1ToL2EntryKeys(messages: Fr[], l1BlockNumber: bigint): Promise<boolean> {
178
- return Promise.resolve(this.#messageStore.cancelPendingMessages(messages, l1BlockNumber));
179
- }
180
-
181
- /**
182
- * Messages that have been published in an L2 block are confirmed.
183
- * Add them to the confirmed store, also remove them from the pending store.
184
- * @param entryKeys - The entry keys to be removed from the store.
185
- * @param blockNumber - The block for which to add the messages.
186
- * @returns True if the operation is successful.
187
- */
188
- confirmL1ToL2EntryKeys(entryKeys: Fr[]): Promise<boolean> {
189
- return this.#messageStore.confirmPendingMessages(entryKeys);
190
- }
191
-
192
- /**
193
- * Gets up to `limit` amount of pending L1 to L2 messages, sorted by fee
194
- * @param limit - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).
195
- * @returns The requested L1 to L2 entry keys.
196
- */
197
- getPendingL1ToL2EntryKeys(limit: number): Promise<Fr[]> {
198
- return Promise.resolve(this.#messageStore.getPendingEntryKeysByFee(limit));
199
- }
200
-
201
- /**
202
- * Gets the confirmed L1 to L2 message corresponding to the given entry key.
203
- * @param entryKey - The entry key to look up.
204
- * @returns The requested L1 to L2 message or throws if not found.
157
+ * Gets the L1 to L2 message index in the L1 to L2 message tree.
158
+ * @param l1ToL2Message - The L1 to L2 message.
159
+ * @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
205
160
  */
206
- getConfirmedL1ToL2Message(entryKey: Fr): Promise<L1ToL2Message> {
207
- try {
208
- return Promise.resolve(this.#messageStore.getConfirmedMessage(entryKey));
209
- } catch (err) {
210
- return Promise.reject(err);
211
- }
161
+ public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined> {
162
+ return Promise.resolve(this.#messageStore.getL1ToL2MessageIndex(l1ToL2Message));
212
163
  }
213
164
 
214
165
  /**
215
- * Gets new L1 to L2 message (to be) included in a given block.
166
+ * Gets L1 to L2 message (to be) included in a given block.
216
167
  * @param blockNumber - L2 block number to get messages for.
217
168
  * @returns The L1 to L2 messages/leaves of the messages subtree (throws if not found).
218
169
  */
219
- getNewL1ToL2Messages(blockNumber: bigint): Promise<Fr[]> {
170
+ getL1ToL2Messages(blockNumber: bigint): Promise<Fr[]> {
220
171
  try {
221
- return Promise.resolve(this.#messageStore.getNewL1ToL2Messages(blockNumber));
172
+ return Promise.resolve(this.#messageStore.getL1ToL2Messages(blockNumber));
222
173
  } catch (err) {
223
174
  return Promise.reject(err);
224
175
  }
@@ -252,44 +203,23 @@ export class KVArchiverDataStore implements ArchiverDataStore {
252
203
  }
253
204
  }
254
205
 
255
- /**
256
- * Add new extended contract data from an L2 block to the store's list.
257
- * @param data - List of contracts' data to be added.
258
- * @param blockNum - Number of the L2 block the contract data was deployed in.
259
- * @returns True if the operation is successful.
260
- */
261
- addExtendedContractData(data: ExtendedContractData[], blockNum: number): Promise<boolean> {
262
- return this.#contractStore.addExtendedContractData(data, blockNum);
263
- }
264
-
265
- /**
266
- * Get the extended contract data for this contract.
267
- * @param contractAddress - The contract data address.
268
- * @returns The extended contract data or undefined if not found.
269
- */
270
- getExtendedContractData(contractAddress: AztecAddress): Promise<ExtendedContractData | undefined> {
271
- return Promise.resolve(this.#contractStore.getExtendedContractData(contractAddress));
272
- }
273
-
274
206
  /**
275
207
  * Gets the number of the latest L2 block processed.
276
208
  * @returns The number of the latest L2 block processed.
277
209
  */
278
- getBlockNumber(): Promise<number> {
279
- return Promise.resolve(this.#blockStore.getBlockNumber());
210
+ getSynchedL2BlockNumber(): Promise<number> {
211
+ return Promise.resolve(this.#blockStore.getSynchedL2BlockNumber());
280
212
  }
281
213
 
282
214
  /**
283
215
  * Gets the last L1 block number processed by the archiver
284
216
  */
285
- getL1BlockNumber(): Promise<ArchiverL1SynchPoint> {
286
- const addedBlock = this.#blockStore.getL1BlockNumber();
287
- const { addedMessages, cancelledMessages, newMessages } = this.#messageStore.getL1BlockNumber();
217
+ getSynchedL1BlockNumbers(): Promise<ArchiverL1SynchPoint> {
218
+ const blocks = this.#blockStore.getSynchedL1BlockNumber();
219
+ const messages = this.#messageStore.getSynchedL1BlockNumber();
288
220
  return Promise.resolve({
289
- addedBlock,
290
- addedMessages,
291
- newMessages,
292
- cancelledMessages,
221
+ blocks,
222
+ messages,
293
223
  });
294
224
  }
295
225
  }