@aztec/archiver 0.1.0-alpha11

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 (45) hide show
  1. package/.eslintrc.cjs +1 -0
  2. package/.tsbuildinfo +1 -0
  3. package/README.md +17 -0
  4. package/dest/archiver/archiver.d.ts +147 -0
  5. package/dest/archiver/archiver.d.ts.map +1 -0
  6. package/dest/archiver/archiver.js +260 -0
  7. package/dest/archiver/archiver.test.d.ts +2 -0
  8. package/dest/archiver/archiver.test.d.ts.map +1 -0
  9. package/dest/archiver/archiver.test.js +188 -0
  10. package/dest/archiver/archiver_store.d.ts +269 -0
  11. package/dest/archiver/archiver_store.d.ts.map +1 -0
  12. package/dest/archiver/archiver_store.js +259 -0
  13. package/dest/archiver/config.d.ts +29 -0
  14. package/dest/archiver/config.d.ts.map +1 -0
  15. package/dest/archiver/config.js +21 -0
  16. package/dest/archiver/data_retrieval.d.ts +64 -0
  17. package/dest/archiver/data_retrieval.d.ts.map +1 -0
  18. package/dest/archiver/data_retrieval.js +102 -0
  19. package/dest/archiver/eth_log_handlers.d.ts +77 -0
  20. package/dest/archiver/eth_log_handlers.d.ts.map +1 -0
  21. package/dest/archiver/eth_log_handlers.js +178 -0
  22. package/dest/archiver/index.d.ts +3 -0
  23. package/dest/archiver/index.d.ts.map +1 -0
  24. package/dest/archiver/index.js +3 -0
  25. package/dest/archiver/l1_to_l2_message_store.d.ts +40 -0
  26. package/dest/archiver/l1_to_l2_message_store.d.ts.map +1 -0
  27. package/dest/archiver/l1_to_l2_message_store.js +71 -0
  28. package/dest/archiver/l1_to_l2_message_store.test.d.ts +2 -0
  29. package/dest/archiver/l1_to_l2_message_store.test.d.ts.map +1 -0
  30. package/dest/archiver/l1_to_l2_message_store.test.js +77 -0
  31. package/dest/index.d.ts +2 -0
  32. package/dest/index.d.ts.map +1 -0
  33. package/dest/index.js +37 -0
  34. package/package.json +19 -0
  35. package/src/archiver/archiver.test.ts +225 -0
  36. package/src/archiver/archiver.ts +363 -0
  37. package/src/archiver/archiver_store.ts +425 -0
  38. package/src/archiver/config.ts +55 -0
  39. package/src/archiver/data_retrieval.ts +167 -0
  40. package/src/archiver/eth_log_handlers.ts +238 -0
  41. package/src/archiver/index.ts +2 -0
  42. package/src/archiver/l1_to_l2_message_store.test.ts +97 -0
  43. package/src/archiver/l1_to_l2_message_store.ts +88 -0
  44. package/src/index.ts +51 -0
  45. package/tsconfig.json +23 -0
@@ -0,0 +1,269 @@
1
+ import { ContractPublicData, L2Block, ContractData, L1ToL2Message, L2BlockL2Logs } from '@aztec/types';
2
+ import { Fr } from '@aztec/circuits.js';
3
+ import { AztecAddress } from '@aztec/foundation/aztec-address';
4
+ /**
5
+ * Interface describing a data store to be used by the archiver to store all its relevant data
6
+ * (blocks, encrypted logs, aztec contract public data).
7
+ */
8
+ export interface ArchiverDataStore {
9
+ /**
10
+ * Append new blocks to the store's list.
11
+ * @param blocks - The L2 blocks to be added to the store.
12
+ * @returns True if the operation is successful.
13
+ */
14
+ addL2Blocks(blocks: L2Block[]): Promise<boolean>;
15
+ /**
16
+ * Gets the `take` amount of L2 blocks starting from `from`.
17
+ * @param from - Number of the first block to return (inclusive).
18
+ * @param take - The number of blocks to return.
19
+ * @returns The requested L2 blocks.
20
+ */
21
+ getL2Blocks(from: number, take: number): Promise<L2Block[]>;
22
+ /**
23
+ * Append new encrypted logs to the store's list.
24
+ * @param data - The encrypted logs to be added to the store.
25
+ * @returns True if the operation is successful.
26
+ */
27
+ addEncryptedLogs(data: L2BlockL2Logs[]): Promise<boolean>;
28
+ /**
29
+ * Append new unencrypted logs to the store's list.
30
+ * @param data - The unencrypted logs to be added to the store.
31
+ * @returns True if the operation is successful.
32
+ */
33
+ addUnencryptedLogs(data: L2BlockL2Logs[]): Promise<boolean>;
34
+ /**
35
+ * Append new pending L1 to L2 messages to the store.
36
+ * @param messages - The L1 to L2 messages to be added to the store.
37
+ * @returns True if the operation is successful.
38
+ */
39
+ addPendingL1ToL2Messages(messages: L1ToL2Message[]): Promise<boolean>;
40
+ /**
41
+ * Remove pending L1 to L2 messages from the store (if they were cancelled).
42
+ * @param messageKeys - The message keys to be removed from the store.
43
+ * @returns True if the operation is successful.
44
+ */
45
+ cancelPendingL1ToL2Messages(messageKeys: Fr[]): Promise<boolean>;
46
+ /**
47
+ * Messages that have been published in an L2 block are confirmed.
48
+ * Add them to the confirmed store, also remove them from the pending store.
49
+ * @param messageKeys - The message keys to be removed from the store.
50
+ * @returns True if the operation is successful.
51
+ */
52
+ confirmL1ToL2Messages(messageKeys: Fr[]): Promise<boolean>;
53
+ /**
54
+ * Gets the `take` amount of pending L1 to L2 messages, sorted by fee
55
+ * @param take - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).
56
+ * @returns The requested L1 to L2 message keys.
57
+ */
58
+ getPendingL1ToL2MessageKeys(take: number): Promise<Fr[]>;
59
+ /**
60
+ * Gets the confirmed L1 to L2 message corresponding to the given message key.
61
+ * @param messageKey - The message key to look up.
62
+ * @returns The requested L1 to L2 message or throws if not found.
63
+ */
64
+ getConfirmedL1ToL2Message(messageKey: Fr): Promise<L1ToL2Message>;
65
+ /**
66
+ * Gets the `take` amount of encrypted logs starting from `from`.
67
+ * @param from - Number of the L2 block to which corresponds the first `encryptedLogs` to be returned.
68
+ * @param take - The number of encrypted logs to return.
69
+ * @returns The requested encrypted logs.
70
+ */
71
+ getEncryptedLogs(from: number, take: number): Promise<L2BlockL2Logs[]>;
72
+ /**
73
+ * Gets the `take` amount of unencrypted logs starting from `from`.
74
+ * @param from - Number of the L2 block to which corresponds the first `unencryptedLogs` to be returned.
75
+ * @param take - The number of unencrypted logs to return.
76
+ * @returns The requested unencrypted logs.
77
+ */
78
+ getUnencryptedLogs(from: number, take: number): Promise<L2BlockL2Logs[]>;
79
+ /**
80
+ * Store new Contract Public Data from an L2 block to the store's list.
81
+ * @param data - List of contracts' data to be added.
82
+ * @param blockNum - Number of the L2 block the contract data was deployed in.
83
+ * @returns True if the operation is successful.
84
+ */
85
+ addL2ContractPublicData(data: ContractPublicData[], blockNum: number): Promise<boolean>;
86
+ /**
87
+ * Lookup the L2 contract data for a contract address.
88
+ * @param contractAddress - The contract data address.
89
+ * @returns The contract's public data.
90
+ */
91
+ getL2ContractPublicData(contractAddress: AztecAddress): Promise<ContractPublicData | undefined>;
92
+ /**
93
+ * Lookup all contract data in an L2 block.
94
+ * @param blockNum - The block number to get all contract data from.
95
+ * @returns All contract public data in the block (if found).
96
+ */
97
+ getL2ContractPublicDataInBlock(blockNum: number): Promise<ContractPublicData[]>;
98
+ /**
99
+ * Get basic info for an L2 contract.
100
+ * Contains contract address & the ethereum portal address.
101
+ * @param contractAddress - The contract data address.
102
+ * @returns ContractData with the portal address (if we didn't throw an error).
103
+ */
104
+ getL2ContractInfo(contractAddress: AztecAddress): Promise<ContractData | undefined>;
105
+ /**
106
+ * Get basic info for an all L2 contracts deployed in a block.
107
+ * Contains contract address & the ethereum portal address.
108
+ * @param l2BlockNum - Number of the L2 block where contracts were deployed.
109
+ * @returns ContractData with the portal address (if we didn't throw an error).
110
+ */
111
+ getL2ContractInfoInBlock(l2BlockNum: number): Promise<ContractData[] | undefined>;
112
+ /**
113
+ * Gets the number of the latest L2 block processed.
114
+ * @returns The number of the latest L2 block processed.
115
+ */
116
+ getBlockHeight(): Promise<number>;
117
+ /**
118
+ * Gets the length of L2 blocks in store.
119
+ * @returns The length of L2 Blocks stored.
120
+ */
121
+ getBlocksLength(): number;
122
+ }
123
+ /**
124
+ * Simple, in-memory implementation of an archiver data store.
125
+ */
126
+ export declare class MemoryArchiverStore implements ArchiverDataStore {
127
+ /**
128
+ * An array containing all the L2 blocks that have been fetched so far.
129
+ */
130
+ private l2Blocks;
131
+ /**
132
+ * An array containing all the encrypted logs that have been fetched so far.
133
+ * Note: Index in the "outer" array equals to (corresponding L2 block's number - INITIAL_L2_BLOCK_NUM).
134
+ */
135
+ private encryptedLogs;
136
+ /**
137
+ * An array containing all the unencrypted logs that have been fetched so far.
138
+ * Note: Index in the "outer" array equals to (corresponding L2 block's number - INITIAL_L2_BLOCK_NUM).
139
+ */
140
+ private unencryptedLogs;
141
+ /**
142
+ * A sparse array containing all the contract data that have been fetched so far.
143
+ */
144
+ private contractPublicData;
145
+ /**
146
+ * Contains all the confirmed L1 to L2 messages (i.e. messages that were consumed in an L2 block)
147
+ * It is a map of entryKey to the corresponding L1 to L2 message and the number of times it has appeared
148
+ */
149
+ private confirmedL1ToL2Messages;
150
+ /**
151
+ * Contains all the pending L1 to L2 messages (accounts for duplication of messages)
152
+ */
153
+ private pendingL1ToL2Messages;
154
+ constructor();
155
+ /**
156
+ * Append new blocks to the store's list.
157
+ * @param blocks - The L2 blocks to be added to the store.
158
+ * @returns True if the operation is successful (always in this implementation).
159
+ */
160
+ addL2Blocks(blocks: L2Block[]): Promise<boolean>;
161
+ /**
162
+ * Append new encrypted logs data to the store's list.
163
+ * @param data - The encrypted logs to be added to the store.
164
+ * @returns True if the operation is successful (always in this implementation).
165
+ */
166
+ addEncryptedLogs(data: L2BlockL2Logs[]): Promise<boolean>;
167
+ /**
168
+ * Append new unencrypted logs data to the store's list.
169
+ * @param data - The unencrypted logs to be added to the store.
170
+ * @returns True if the operation is successful (always in this implementation).
171
+ */
172
+ addUnencryptedLogs(data: L2BlockL2Logs[]): Promise<boolean>;
173
+ /**
174
+ * Append new pending L1 to L2 messages to the store.
175
+ * @param messages - The L1 to L2 messages to be added to the store.
176
+ * @returns True if the operation is successful (always in this implementation).
177
+ */
178
+ addPendingL1ToL2Messages(messages: L1ToL2Message[]): Promise<boolean>;
179
+ /**
180
+ * Remove pending L1 to L2 messages from the store (if they were cancelled).
181
+ * @param messageKeys - The message keys to be removed from the store.
182
+ * @returns True if the operation is successful (always in this implementation).
183
+ */
184
+ cancelPendingL1ToL2Messages(messageKeys: Fr[]): Promise<boolean>;
185
+ /**
186
+ * Messages that have been published in an L2 block are confirmed.
187
+ * Add them to the confirmed store, also remove them from the pending store.
188
+ * @param messageKeys - The message keys to be removed from the store.
189
+ * @returns True if the operation is successful (always in this implementation).
190
+ */
191
+ confirmL1ToL2Messages(messageKeys: Fr[]): Promise<boolean>;
192
+ /**
193
+ * Store new Contract Public Data from an L2 block to the store's list.
194
+ * @param data - List of contracts' data to be added.
195
+ * @param blockNum - Number of the L2 block the contract data was deployed in.
196
+ * @returns True if the operation is successful (always in this implementation).
197
+ */
198
+ addL2ContractPublicData(data: ContractPublicData[], blockNum: number): Promise<boolean>;
199
+ /**
200
+ * Gets the `take` amount of L2 blocks starting from `from`.
201
+ * @param from - Number of the first block to return (inclusive).
202
+ * @param take - The number of blocks to return.
203
+ * @returns The requested L2 blocks.
204
+ */
205
+ getL2Blocks(from: number, take: number): Promise<L2Block[]>;
206
+ /**
207
+ * Gets the `take` amount of pending L1 to L2 messages, sorted by fee
208
+ * @param take - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).
209
+ * @returns The requested L1 to L2 message keys.
210
+ */
211
+ getPendingL1ToL2MessageKeys(take?: number): Promise<Fr[]>;
212
+ /**
213
+ * Gets the confirmed L1 to L2 message corresponding to the given message key.
214
+ * @param messageKey - The message key to look up.
215
+ * @returns The requested L1 to L2 message or throws if not found.
216
+ */
217
+ getConfirmedL1ToL2Message(messageKey: Fr): Promise<L1ToL2Message>;
218
+ /**
219
+ * Gets the `take` amount of encrypted logs starting from `from`.
220
+ * @param from - Number of the L2 block to which corresponds the first encrypted logs to be returned.
221
+ * @param take - The number of encrypted logs to return.
222
+ * @returns The requested encrypted logs.
223
+ */
224
+ getEncryptedLogs(from: number, take: number): Promise<L2BlockL2Logs[]>;
225
+ /**
226
+ * Gets the 'take' amount of unencrypted logs starting from 'from'.
227
+ * @param from - Number of the L2 block to which corresponds the first unencrypted logs to be returned.
228
+ * @param take - The number of unencrypted logs to return.
229
+ * @returns The requested unencrypted logs.
230
+ */
231
+ getUnencryptedLogs(from: number, take: number): Promise<L2BlockL2Logs[]>;
232
+ /**
233
+ * Lookup the L2 contract data for a contract address.
234
+ * @param contractAddress - The contract data address.
235
+ * @returns The contract's public data.
236
+ */
237
+ getL2ContractPublicData(contractAddress: AztecAddress): Promise<ContractPublicData | undefined>;
238
+ /**
239
+ * Lookup all contract data in an L2 block.
240
+ * @param blockNum - The block number to get all contract data from.
241
+ * @returns All contract public data in the block (if found).
242
+ */
243
+ getL2ContractPublicDataInBlock(blockNum: number): Promise<ContractPublicData[]>;
244
+ /**
245
+ * Get basic info for an L2 contract.
246
+ * Contains contract address & the ethereum portal address.
247
+ * @param contractAddress - The contract data address.
248
+ * @returns ContractData with the portal address (if we didn't throw an error).
249
+ */
250
+ getL2ContractInfo(contractAddress: AztecAddress): Promise<ContractData | undefined>;
251
+ /**
252
+ * Get basic info for an all L2 contracts deployed in a block.
253
+ * Contains contract address & the ethereum portal address.
254
+ * @param l2BlockNum - Number of the L2 block where contracts were deployed.
255
+ * @returns ContractData with the portal address (if we didn't throw an error).
256
+ */
257
+ getL2ContractInfoInBlock(l2BlockNum: number): Promise<ContractData[] | undefined>;
258
+ /**
259
+ * Gets the number of the latest L2 block processed.
260
+ * @returns The number of the latest L2 block processed.
261
+ */
262
+ getBlockHeight(): Promise<number>;
263
+ /**
264
+ * Gets the length of L2 blocks in store.
265
+ * @returns The length of L2 Blocks array.
266
+ */
267
+ getBlocksLength(): number;
268
+ }
269
+ //# sourceMappingURL=archiver_store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"archiver_store.d.ts","sourceRoot":"","sources":["../../src/archiver/archiver_store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,OAAO,EAEP,YAAY,EACZ,aAAa,EACb,aAAa,EACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,EAAE,EAAuC,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAG/D;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;O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I,OAAO,CAAC,MAAM,CAAC;IAKxC;;;OAGG;IACI,eAAe,IAAI,MAAM;CAGjC"}
@@ -0,0 +1,259 @@
1
+ import { INITIAL_L2_BLOCK_NUM, } from '@aztec/types';
2
+ import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/circuits.js';
3
+ import { L1ToL2MessageStore, PendingL1ToL2MessageStore } from './l1_to_l2_message_store.js';
4
+ /**
5
+ * Simple, in-memory implementation of an archiver data store.
6
+ */
7
+ export class MemoryArchiverStore {
8
+ constructor() {
9
+ /**
10
+ * An array containing all the L2 blocks that have been fetched so far.
11
+ */
12
+ this.l2Blocks = [];
13
+ /**
14
+ * An array containing all the encrypted logs that have been fetched so far.
15
+ * Note: Index in the "outer" array equals to (corresponding L2 block's number - INITIAL_L2_BLOCK_NUM).
16
+ */
17
+ this.encryptedLogs = [];
18
+ /**
19
+ * An array containing all the unencrypted logs that have been fetched so far.
20
+ * Note: Index in the "outer" array equals to (corresponding L2 block's number - INITIAL_L2_BLOCK_NUM).
21
+ */
22
+ this.unencryptedLogs = [];
23
+ /**
24
+ * A sparse array containing all the contract data that have been fetched so far.
25
+ */
26
+ this.contractPublicData = [];
27
+ /**
28
+ * Contains all the confirmed L1 to L2 messages (i.e. messages that were consumed in an L2 block)
29
+ * It is a map of entryKey to the corresponding L1 to L2 message and the number of times it has appeared
30
+ */
31
+ this.confirmedL1ToL2Messages = new L1ToL2MessageStore();
32
+ /**
33
+ * Contains all the pending L1 to L2 messages (accounts for duplication of messages)
34
+ */
35
+ this.pendingL1ToL2Messages = new PendingL1ToL2MessageStore();
36
+ }
37
+ /**
38
+ * Append new blocks to the store's list.
39
+ * @param blocks - The L2 blocks to be added to the store.
40
+ * @returns True if the operation is successful (always in this implementation).
41
+ */
42
+ addL2Blocks(blocks) {
43
+ this.l2Blocks.push(...blocks);
44
+ return Promise.resolve(true);
45
+ }
46
+ /**
47
+ * Append new encrypted logs data to the store's list.
48
+ * @param data - The encrypted logs to be added to the store.
49
+ * @returns True if the operation is successful (always in this implementation).
50
+ */
51
+ addEncryptedLogs(data) {
52
+ this.encryptedLogs.push(...data);
53
+ return Promise.resolve(true);
54
+ }
55
+ /**
56
+ * Append new unencrypted logs data to the store's list.
57
+ * @param data - The unencrypted logs to be added to the store.
58
+ * @returns True if the operation is successful (always in this implementation).
59
+ */
60
+ addUnencryptedLogs(data) {
61
+ this.unencryptedLogs.push(...data);
62
+ return Promise.resolve(true);
63
+ }
64
+ /**
65
+ * Append new pending L1 to L2 messages to the store.
66
+ * @param messages - The L1 to L2 messages to be added to the store.
67
+ * @returns True if the operation is successful (always in this implementation).
68
+ */
69
+ addPendingL1ToL2Messages(messages) {
70
+ for (const msg of messages) {
71
+ this.pendingL1ToL2Messages.addMessage(msg.entryKey, msg);
72
+ }
73
+ return Promise.resolve(true);
74
+ }
75
+ /**
76
+ * Remove pending L1 to L2 messages from the store (if they were cancelled).
77
+ * @param messageKeys - The message keys to be removed from the store.
78
+ * @returns True if the operation is successful (always in this implementation).
79
+ */
80
+ cancelPendingL1ToL2Messages(messageKeys) {
81
+ messageKeys.forEach(messageKey => {
82
+ this.pendingL1ToL2Messages.removeMessage(messageKey);
83
+ });
84
+ return Promise.resolve(true);
85
+ }
86
+ /**
87
+ * Messages that have been published in an L2 block are confirmed.
88
+ * Add them to the confirmed store, also remove them from the pending store.
89
+ * @param messageKeys - The message keys to be removed from the store.
90
+ * @returns True if the operation is successful (always in this implementation).
91
+ */
92
+ confirmL1ToL2Messages(messageKeys) {
93
+ messageKeys.forEach(messageKey => {
94
+ this.confirmedL1ToL2Messages.addMessage(messageKey, this.pendingL1ToL2Messages.getMessage(messageKey));
95
+ this.pendingL1ToL2Messages.removeMessage(messageKey);
96
+ });
97
+ return Promise.resolve(true);
98
+ }
99
+ /**
100
+ * Store new Contract Public Data from an L2 block to the store's list.
101
+ * @param data - List of contracts' data to be added.
102
+ * @param blockNum - Number of the L2 block the contract data was deployed in.
103
+ * @returns True if the operation is successful (always in this implementation).
104
+ */
105
+ addL2ContractPublicData(data, blockNum) {
106
+ if (this.contractPublicData[blockNum]?.length) {
107
+ this.contractPublicData[blockNum]?.push(...data);
108
+ }
109
+ else {
110
+ this.contractPublicData[blockNum] = [...data];
111
+ }
112
+ return Promise.resolve(true);
113
+ }
114
+ /**
115
+ * Gets the `take` amount of L2 blocks starting from `from`.
116
+ * @param from - Number of the first block to return (inclusive).
117
+ * @param take - The number of blocks to return.
118
+ * @returns The requested L2 blocks.
119
+ */
120
+ getL2Blocks(from, take) {
121
+ if (from < INITIAL_L2_BLOCK_NUM) {
122
+ throw new Error(`Invalid block range ${from}`);
123
+ }
124
+ if (from > this.l2Blocks.length) {
125
+ return Promise.resolve([]);
126
+ }
127
+ const startIndex = from - INITIAL_L2_BLOCK_NUM;
128
+ const endIndex = from + take;
129
+ return Promise.resolve(this.l2Blocks.slice(startIndex, endIndex));
130
+ }
131
+ /**
132
+ * Gets the `take` amount of pending L1 to L2 messages, sorted by fee
133
+ * @param take - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).
134
+ * @returns The requested L1 to L2 message keys.
135
+ */
136
+ getPendingL1ToL2MessageKeys(take = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP) {
137
+ return Promise.resolve(this.pendingL1ToL2Messages.getMessageKeys(take));
138
+ }
139
+ /**
140
+ * Gets the confirmed L1 to L2 message corresponding to the given message key.
141
+ * @param messageKey - The message key to look up.
142
+ * @returns The requested L1 to L2 message or throws if not found.
143
+ */
144
+ getConfirmedL1ToL2Message(messageKey) {
145
+ const message = this.confirmedL1ToL2Messages.getMessage(messageKey);
146
+ if (!message) {
147
+ throw new Error(`Message with key ${messageKey.toString()} not found`);
148
+ }
149
+ return Promise.resolve(message);
150
+ }
151
+ /**
152
+ * Gets the `take` amount of encrypted logs starting from `from`.
153
+ * @param from - Number of the L2 block to which corresponds the first encrypted logs to be returned.
154
+ * @param take - The number of encrypted logs to return.
155
+ * @returns The requested encrypted logs.
156
+ */
157
+ getEncryptedLogs(from, take) {
158
+ if (from < INITIAL_L2_BLOCK_NUM) {
159
+ throw new Error(`Invalid block range ${from}`);
160
+ }
161
+ if (from > this.encryptedLogs.length) {
162
+ return Promise.resolve([]);
163
+ }
164
+ const startIndex = from - INITIAL_L2_BLOCK_NUM;
165
+ const endIndex = from + take;
166
+ return Promise.resolve(this.encryptedLogs.slice(startIndex, endIndex));
167
+ }
168
+ /**
169
+ * Gets the 'take' amount of unencrypted logs starting from 'from'.
170
+ * @param from - Number of the L2 block to which corresponds the first unencrypted logs to be returned.
171
+ * @param take - The number of unencrypted logs to return.
172
+ * @returns The requested unencrypted logs.
173
+ */
174
+ getUnencryptedLogs(from, take) {
175
+ if (from < INITIAL_L2_BLOCK_NUM) {
176
+ throw new Error(`Invalid block range ${from}`);
177
+ }
178
+ if (from > this.unencryptedLogs.length) {
179
+ return Promise.resolve([]);
180
+ }
181
+ const startIndex = from - INITIAL_L2_BLOCK_NUM;
182
+ const endIndex = from + take;
183
+ return Promise.resolve(this.unencryptedLogs.slice(startIndex, endIndex));
184
+ }
185
+ /**
186
+ * Lookup the L2 contract data for a contract address.
187
+ * @param contractAddress - The contract data address.
188
+ * @returns The contract's public data.
189
+ */
190
+ getL2ContractPublicData(contractAddress) {
191
+ let result;
192
+ for (let i = INITIAL_L2_BLOCK_NUM; i < this.contractPublicData.length; i++) {
193
+ const contracts = this.contractPublicData[i];
194
+ const contract = contracts?.find(c => c.contractData.contractAddress.equals(contractAddress));
195
+ if (contract) {
196
+ result = contract;
197
+ break;
198
+ }
199
+ }
200
+ return Promise.resolve(result);
201
+ }
202
+ /**
203
+ * Lookup all contract data in an L2 block.
204
+ * @param blockNum - The block number to get all contract data from.
205
+ * @returns All contract public data in the block (if found).
206
+ */
207
+ getL2ContractPublicDataInBlock(blockNum) {
208
+ if (blockNum > this.l2Blocks.length) {
209
+ return Promise.resolve([]);
210
+ }
211
+ return Promise.resolve(this.contractPublicData[blockNum] || []);
212
+ }
213
+ /**
214
+ * Get basic info for an L2 contract.
215
+ * Contains contract address & the ethereum portal address.
216
+ * @param contractAddress - The contract data address.
217
+ * @returns ContractData with the portal address (if we didn't throw an error).
218
+ */
219
+ getL2ContractInfo(contractAddress) {
220
+ for (const block of this.l2Blocks) {
221
+ for (const contractData of block.newContractData) {
222
+ if (contractData.contractAddress.equals(contractAddress)) {
223
+ return Promise.resolve(contractData);
224
+ }
225
+ }
226
+ }
227
+ return Promise.resolve(undefined);
228
+ }
229
+ /**
230
+ * Get basic info for an all L2 contracts deployed in a block.
231
+ * Contains contract address & the ethereum portal address.
232
+ * @param l2BlockNum - Number of the L2 block where contracts were deployed.
233
+ * @returns ContractData with the portal address (if we didn't throw an error).
234
+ */
235
+ getL2ContractInfoInBlock(l2BlockNum) {
236
+ if (l2BlockNum > this.l2Blocks.length) {
237
+ return Promise.resolve([]);
238
+ }
239
+ const block = this.l2Blocks[l2BlockNum];
240
+ return Promise.resolve(block.newContractData);
241
+ }
242
+ /**
243
+ * Gets the number of the latest L2 block processed.
244
+ * @returns The number of the latest L2 block processed.
245
+ */
246
+ getBlockHeight() {
247
+ if (this.l2Blocks.length === 0)
248
+ return Promise.resolve(INITIAL_L2_BLOCK_NUM - 1);
249
+ return Promise.resolve(this.l2Blocks[this.l2Blocks.length - 1].number);
250
+ }
251
+ /**
252
+ * Gets the length of L2 blocks in store.
253
+ * @returns The length of L2 Blocks array.
254
+ */
255
+ getBlocksLength() {
256
+ return this.l2Blocks.length;
257
+ }
258
+ }
259
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXJjaGl2ZXJfc3RvcmUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYXJjaGl2ZXIvYXJjaGl2ZXJfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUdMLG9CQUFvQixHQUlyQixNQUFNLGNBQWMsQ0FBQztBQ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QUMsQ0FBQztTQUM1QjtRQUNELE1BQU0sS0FBSyxHQUFHLElBQUksQ0FBQyxRQUFRLENBQUMsVUFBVSxDQUFDLENBQUM7UUFDeEMsT0FBTyxPQUFPLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxlQUFlLENBQUMsQ0FBQztJQUNoRCxDQUFDO0lBRUQ7OztPQUdHO0lBQ0ksY0FBYztRQUNuQixJQUFJLElBQUksQ0FBQyxRQUFRLENBQUMsTUFBTSxLQUFLLENBQUM7WUFBRSxPQUFPLE9BQU8sQ0FBQyxPQUFPLENBQUMsb0JBQW9CLEdBQUcsQ0FBQyxDQUFDLENBQUM7UUFDakYsT0FBTyxPQUFPLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxRQUFRLENBQUMsSUFBSSxDQUFDLFFBQVEsQ0FBQyxNQUFNLEdBQUcsQ0FBQyxDQUFDLENBQUMsTUFBTSxDQUFDLENBQUM7SUFDekUsQ0FBQztJQUVEOzs7T0FHRztJQUNJLGVBQWU7UUFDcEIsT0FBTyxJQUFJLENBQUMsUUFBUSxDQUFDLE1BQU0sQ0FBQztJQUM5QixDQUFDO0NBQ0YifQ==
@@ -0,0 +1,29 @@
1
+ import { L1Addresses } from '@aztec/types';
2
+ /**
3
+ * The archiver configuration.
4
+ */
5
+ export interface ArchiverConfig extends L1Addresses {
6
+ /**
7
+ * The url of the Ethereum RPC node.
8
+ */
9
+ rpcUrl: string;
10
+ /**
11
+ * The key for the ethereum node.
12
+ */
13
+ apiKey?: string;
14
+ /**
15
+ * The polling interval in ms for retrieving new L2 blocks and encrypted logs.
16
+ */
17
+ archiverPollingInterval?: number;
18
+ /**
19
+ * Eth block from which we start scanning for L2Blocks.
20
+ */
21
+ searchStartBlock: number;
22
+ }
23
+ /**
24
+ * Returns the archiver configuration from the environment variables.
25
+ * Note: If an environment variable is not set, the default value is used.
26
+ * @returns The archiver configuration.
27
+ */
28
+ export declare function getConfigEnvVars(): ArchiverConfig;
29
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/archiver/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,uBAAuB,CAAC,EAAE,MAAM,CAAC;IAEjC;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,cAAc,CAqBjD"}
@@ -0,0 +1,21 @@
1
+ import { EthAddress } from '@aztec/foundation/eth-address';
2
+ /**
3
+ * Returns the archiver configuration from the environment variables.
4
+ * Note: If an environment variable is not set, the default value is used.
5
+ * @returns The archiver configuration.
6
+ */
7
+ export function getConfigEnvVars() {
8
+ const { ETHEREUM_HOST, ARCHIVER_POLLING_INTERVAL, ROLLUP_CONTRACT_ADDRESS, CONTRACT_DEPLOYMENT_EMITTER_ADDRESS, SEARCH_START_BLOCK, API_KEY, INBOX_CONTRACT_ADDRESS, } = process.env;
9
+ return {
10
+ rpcUrl: ETHEREUM_HOST || 'http://127.0.0.1:8545/',
11
+ archiverPollingInterval: ARCHIVER_POLLING_INTERVAL ? +ARCHIVER_POLLING_INTERVAL : 1000,
12
+ rollupContract: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO,
13
+ inboxContract: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO,
14
+ contractDeploymentEmitterContract: CONTRACT_DEPLOYMENT_EMITTER_ADDRESS
15
+ ? EthAddress.fromString(CONTRACT_DEPLOYMENT_EMITTER_ADDRESS)
16
+ : EthAddress.ZERO,
17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0FBQztZQUM1RCxDQUFDLENBQUMsVUFBVSxDQUFDLElBQUk7UUFDbkIsZ0JBQWdCLEVBQUUsa0JBQWtCLENBQUMsQ0FBQyxDQUFDLENBQUMsa0JBQWtCLENBQUMsQ0FBQyxDQUFDLENBQUM7UUFDOUQsTUFBTSxFQUFFLE9BQU87S0FDaEIsQ0FBQztBQUNKLENBQUMifQ==
@@ -0,0 +1,64 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import { PublicClient } from 'viem';
3
+ import { EthAddress } from '@aztec/foundation/eth-address';
4
+ import { ContractPublicData, L1ToL2Message, L2Block } from '@aztec/types';
5
+ import { Fr } from '@aztec/foundation/fields';
6
+ /**
7
+ * Data retrieved from logs
8
+ */
9
+ type DataRetrieval<T> = {
10
+ /**
11
+ * The next block number.
12
+ */
13
+ nextEthBlockNumber: bigint;
14
+ /**
15
+ * The data returned.
16
+ */
17
+ retrievedData: T[];
18
+ };
19
+ /**
20
+ * Fetches new L2 Blocks.
21
+ * @param publicClient - The viem public client to use for transaction retrieval.
22
+ * @param rollupAddress - The address of the rollup contract.
23
+ * @param blockUntilSynced - If true, blocks until the archiver has fully synced.
24
+ * @param currentL1BlockNum - Latest available block number in the ETH node.
25
+ * @param searchStartBlock - The block number to use for starting the search.
26
+ * @param expectedNextL2BlockNum - The next L2 block number that we expect to find.
27
+ * @returns An array of L2 Blocks and the next eth block to search from
28
+ */
29
+ export declare function retrieveBlocks(publicClient: PublicClient, rollupAddress: EthAddress, blockUntilSynced: boolean, currentL1BlockNum: bigint, searchStartBlock: bigint, expectedNextL2BlockNum: bigint): Promise<DataRetrieval<L2Block>>;
30
+ /**
31
+ * Fetches new contract data.
32
+ * @param publicClient - The viem public client to use for transaction retrieval.
33
+ * @param contractDeploymentEmitterAddress - The address of the contract deployment emitter contract.
34
+ * @param blockUntilSynced - If true, blocks until the archiver has fully synced.
35
+ * @param currentBlockNumber - Latest available block number in the ETH node.
36
+ * @param searchStartBlock - The block number to use for starting the search.
37
+ * @param blockHashMapping - A mapping from block number to relevant block hash.
38
+ * @returns An array of ContractPublicData and their equivalent L2 Block number along with the next eth block to search from..
39
+ */
40
+ export declare function retrieveNewContractData(publicClient: PublicClient, contractDeploymentEmitterAddress: EthAddress, blockUntilSynced: boolean, currentBlockNumber: bigint, searchStartBlock: bigint, blockHashMapping: {
41
+ [key: number]: Buffer | undefined;
42
+ }): Promise<DataRetrieval<[ContractPublicData[], number]>>;
43
+ /**
44
+ * Fetch new pending L1 to L2 messages.
45
+ * @param publicClient - The viem public client to use for transaction retrieval.
46
+ * @param inboxAddress - The address of the inbox contract to fetch messages from.
47
+ * @param blockUntilSynced - If true, blocks until the archiver has fully synced.
48
+ * @param currentBlockNumber - Latest available block number in the ETH node.
49
+ * @param searchStartBlock - The block number to use for starting the search.
50
+ * @returns An array of L1ToL2Message and next eth block to search from.
51
+ */
52
+ export declare function retrieveNewPendingL1ToL2Messages(publicClient: PublicClient, inboxAddress: EthAddress, blockUntilSynced: boolean, currentBlockNumber: bigint, searchStartBlock: bigint): Promise<DataRetrieval<L1ToL2Message>>;
53
+ /**
54
+ * Fetch newly cancelled L1 to L2 messages.
55
+ * @param publicClient - The viem public client to use for transaction retrieval.
56
+ * @param inboxAddress - The address of the inbox contract to fetch messages from.
57
+ * @param blockUntilSynced - If true, blocks until the archiver has fully synced.
58
+ * @param currentBlockNumber - Latest available block number in the ETH node.
59
+ * @param searchStartBlock - The block number to use for starting the search.
60
+ * @returns An array of message keys that were cancelled and next eth block to search from.
61
+ */
62
+ export declare function retrieveNewCancelledL1ToL2Messages(publicClient: PublicClient, inboxAddress: EthAddress, blockUntilSynced: boolean, currentBlockNumber: bigint, searchStartBlock: bigint): Promise<DataRetrieval<Fr>>;
63
+ export {};
64
+ //# sourceMappingURL=data_retrieval.d.ts.map