@aztec/archiver 0.1.0-alpha23 → 0.1.0-alpha40
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.
- package/.tsbuildinfo +1 -1
- package/dest/archiver/archiver.d.ts +27 -21
- package/dest/archiver/archiver.d.ts.map +1 -1
- package/dest/archiver/archiver.js +50 -35
- package/dest/archiver/archiver.test.js +9 -10
- package/dest/archiver/archiver_store.d.ts +41 -37
- package/dest/archiver/archiver_store.d.ts.map +1 -1
- package/dest/archiver/archiver_store.js +48 -42
- package/dest/archiver/archiver_store.test.d.ts +2 -0
- package/dest/archiver/archiver_store.test.d.ts.map +1 -0
- package/dest/archiver/archiver_store.test.js +61 -0
- package/dest/archiver/config.d.ts +11 -1
- package/dest/archiver/config.d.ts.map +1 -1
- package/dest/archiver/config.js +4 -3
- package/dest/archiver/data_retrieval.d.ts +4 -4
- package/dest/archiver/data_retrieval.d.ts.map +1 -1
- package/dest/archiver/data_retrieval.js +3 -3
- package/dest/archiver/eth_log_handlers.d.ts +6 -6
- package/dest/archiver/eth_log_handlers.d.ts.map +1 -1
- package/dest/archiver/eth_log_handlers.js +13 -13
- package/dest/archiver/l1_to_l2_message_store.d.ts +1 -1
- package/dest/archiver/l1_to_l2_message_store.d.ts.map +1 -1
- package/dest/archiver/l1_to_l2_message_store.js +6 -6
- package/dest/archiver/l1_to_l2_message_store.test.js +4 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +5 -5
- package/package.json +7 -6
- package/src/archiver/archiver.test.ts +11 -10
- package/src/archiver/archiver.ts +61 -38
- package/src/archiver/archiver_store.test.ts +74 -0
- package/src/archiver/archiver_store.ts +72 -63
- package/src/archiver/config.ts +17 -3
- package/src/archiver/data_retrieval.ts +10 -8
- package/src/archiver/eth_log_handlers.ts +18 -17
- package/src/archiver/l1_to_l2_message_store.test.ts +4 -3
- package/src/archiver/l1_to_l2_message_store.ts +5 -5
- package/src/index.ts +6 -4
- package/tsconfig.json +3 -0
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import { Fr, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/circuits.js';
|
|
2
|
+
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
1
3
|
import {
|
|
2
|
-
ContractPublicData,
|
|
3
|
-
L2Block,
|
|
4
|
-
INITIAL_L2_BLOCK_NUM,
|
|
5
4
|
ContractData,
|
|
5
|
+
ContractDataAndBytecode,
|
|
6
|
+
INITIAL_L2_BLOCK_NUM,
|
|
6
7
|
L1ToL2Message,
|
|
8
|
+
L2Block,
|
|
7
9
|
L2BlockL2Logs,
|
|
8
10
|
LogType,
|
|
9
11
|
} from '@aztec/types';
|
|
10
|
-
|
|
11
|
-
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
12
|
+
|
|
12
13
|
import { L1ToL2MessageStore, PendingL1ToL2MessageStore } from './l1_to_l2_message_store.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Interface describing a data store to be used by the archiver to store all its relevant data
|
|
16
|
-
* (blocks, encrypted logs, aztec contract
|
|
17
|
+
* (blocks, encrypted logs, aztec contract data and bytecode).
|
|
17
18
|
*/
|
|
18
19
|
export interface ArchiverDataStore {
|
|
19
20
|
/**
|
|
@@ -24,12 +25,12 @@ export interface ArchiverDataStore {
|
|
|
24
25
|
addL2Blocks(blocks: L2Block[]): Promise<boolean>;
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
|
-
* Gets
|
|
28
|
+
* Gets up to `limit` amount of L2 blocks starting from `from`.
|
|
28
29
|
* @param from - Number of the first block to return (inclusive).
|
|
29
|
-
* @param
|
|
30
|
+
* @param limit - The number of blocks to return.
|
|
30
31
|
* @returns The requested L2 blocks.
|
|
31
32
|
*/
|
|
32
|
-
getL2Blocks(from: number,
|
|
33
|
+
getL2Blocks(from: number, limit: number): Promise<L2Block[]>;
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* Append new logs to the store's list.
|
|
@@ -62,11 +63,11 @@ export interface ArchiverDataStore {
|
|
|
62
63
|
confirmL1ToL2Messages(messageKeys: Fr[]): Promise<boolean>;
|
|
63
64
|
|
|
64
65
|
/**
|
|
65
|
-
* Gets
|
|
66
|
-
* @param
|
|
66
|
+
* Gets up to `limit` amount of pending L1 to L2 messages, sorted by fee
|
|
67
|
+
* @param limit - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).
|
|
67
68
|
* @returns The requested L1 to L2 message keys.
|
|
68
69
|
*/
|
|
69
|
-
getPendingL1ToL2MessageKeys(
|
|
70
|
+
getPendingL1ToL2MessageKeys(limit: number): Promise<Fr[]>;
|
|
70
71
|
|
|
71
72
|
/**
|
|
72
73
|
* Gets the confirmed L1 to L2 message corresponding to the given message key.
|
|
@@ -76,35 +77,35 @@ export interface ArchiverDataStore {
|
|
|
76
77
|
getConfirmedL1ToL2Message(messageKey: Fr): Promise<L1ToL2Message>;
|
|
77
78
|
|
|
78
79
|
/**
|
|
79
|
-
* Gets
|
|
80
|
+
* Gets up to `limit` amount of logs starting from `from`.
|
|
80
81
|
* @param from - Number of the L2 block to which corresponds the first logs to be returned.
|
|
81
|
-
* @param
|
|
82
|
+
* @param limit - The number of logs to return.
|
|
82
83
|
* @param logType - Specifies whether to return encrypted or unencrypted logs.
|
|
83
84
|
* @returns The requested logs.
|
|
84
85
|
*/
|
|
85
|
-
getLogs(from: number,
|
|
86
|
+
getLogs(from: number, limit: number, logType: LogType): Promise<L2BlockL2Logs[]>;
|
|
86
87
|
|
|
87
88
|
/**
|
|
88
|
-
* Store new Contract
|
|
89
|
+
* Store new Contract data and bytecode from an L2 block to the store's list.
|
|
89
90
|
* @param data - List of contracts' data to be added.
|
|
90
91
|
* @param blockNum - Number of the L2 block the contract data was deployed in.
|
|
91
92
|
* @returns True if the operation is successful.
|
|
92
93
|
*/
|
|
93
|
-
|
|
94
|
+
addContractDataAndBytecode(data: ContractDataAndBytecode[], blockNum: number): Promise<boolean>;
|
|
94
95
|
|
|
95
96
|
/**
|
|
96
97
|
* Lookup the L2 contract data for a contract address.
|
|
97
98
|
* @param contractAddress - The contract data address.
|
|
98
99
|
* @returns The contract's public data.
|
|
99
100
|
*/
|
|
100
|
-
|
|
101
|
+
getContractDataAndBytecode(contractAddress: AztecAddress): Promise<ContractDataAndBytecode | undefined>;
|
|
101
102
|
|
|
102
103
|
/**
|
|
103
|
-
* Lookup all contract data in an L2 block.
|
|
104
|
+
* Lookup all contract data and bytecode in an L2 block.
|
|
104
105
|
* @param blockNum - The block number to get all contract data from.
|
|
105
|
-
* @returns All contract
|
|
106
|
+
* @returns All contract data and bytecode in the block (if found).
|
|
106
107
|
*/
|
|
107
|
-
|
|
108
|
+
getContractDataAndBytecodeInBlock(blockNum: number): Promise<ContractDataAndBytecode[]>;
|
|
108
109
|
|
|
109
110
|
/**
|
|
110
111
|
* Get basic info for an L2 contract.
|
|
@@ -112,7 +113,7 @@ export interface ArchiverDataStore {
|
|
|
112
113
|
* @param contractAddress - The contract data address.
|
|
113
114
|
* @returns ContractData with the portal address (if we didn't throw an error).
|
|
114
115
|
*/
|
|
115
|
-
|
|
116
|
+
getContractData(contractAddress: AztecAddress): Promise<ContractData | undefined>;
|
|
116
117
|
|
|
117
118
|
/**
|
|
118
119
|
* Get basic info for an all L2 contracts deployed in a block.
|
|
@@ -120,7 +121,7 @@ export interface ArchiverDataStore {
|
|
|
120
121
|
* @param l2BlockNum - Number of the L2 block where contracts were deployed.
|
|
121
122
|
* @returns ContractData with the portal address (if we didn't throw an error).
|
|
122
123
|
*/
|
|
123
|
-
|
|
124
|
+
getContractDataInBlock(l2BlockNum: number): Promise<ContractData[] | undefined>;
|
|
124
125
|
|
|
125
126
|
/**
|
|
126
127
|
* Gets the number of the latest L2 block processed.
|
|
@@ -157,9 +158,14 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
157
158
|
private unencryptedLogs: L2BlockL2Logs[] = [];
|
|
158
159
|
|
|
159
160
|
/**
|
|
160
|
-
* A sparse array containing all the contract data that have been fetched so far.
|
|
161
|
+
* A sparse array containing all the contract data and bytecode that have been fetched so far.
|
|
161
162
|
*/
|
|
162
|
-
private
|
|
163
|
+
private contractDataAndBytecodeByBlock: (ContractDataAndBytecode[] | undefined)[] = [];
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* A mapping of contract address to contract data and bytecode.
|
|
167
|
+
*/
|
|
168
|
+
private contractDataAndBytecode: Map<string, ContractDataAndBytecode> = new Map();
|
|
163
169
|
|
|
164
170
|
/**
|
|
165
171
|
* Contains all the confirmed L1 to L2 messages (i.e. messages that were consumed in an L2 block)
|
|
@@ -234,45 +240,53 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
234
240
|
}
|
|
235
241
|
|
|
236
242
|
/**
|
|
237
|
-
* Store new Contract
|
|
243
|
+
* Store new Contract data and bytecode from an L2 block to the store's list.
|
|
238
244
|
* @param data - List of contracts' data to be added.
|
|
239
245
|
* @param blockNum - Number of the L2 block the contract data was deployed in.
|
|
240
246
|
* @returns True if the operation is successful (always in this implementation).
|
|
241
247
|
*/
|
|
242
|
-
public
|
|
243
|
-
|
|
244
|
-
|
|
248
|
+
public addContractDataAndBytecode(data: ContractDataAndBytecode[], blockNum: number): Promise<boolean> {
|
|
249
|
+
// Add to the contracts mapping
|
|
250
|
+
for (const contractData of data) {
|
|
251
|
+
const key = contractData.contractData.contractAddress.toString();
|
|
252
|
+
this.contractDataAndBytecode.set(key, contractData);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Add the index per block
|
|
256
|
+
if (this.contractDataAndBytecodeByBlock[blockNum]?.length) {
|
|
257
|
+
this.contractDataAndBytecodeByBlock[blockNum]?.push(...data);
|
|
245
258
|
} else {
|
|
246
|
-
this.
|
|
259
|
+
this.contractDataAndBytecodeByBlock[blockNum] = [...data];
|
|
247
260
|
}
|
|
248
261
|
return Promise.resolve(true);
|
|
249
262
|
}
|
|
250
263
|
|
|
251
264
|
/**
|
|
252
|
-
* Gets
|
|
265
|
+
* Gets up to `limit` amount of L2 blocks starting from `from`.
|
|
253
266
|
* @param from - Number of the first block to return (inclusive).
|
|
254
|
-
* @param
|
|
267
|
+
* @param limit - The number of blocks to return.
|
|
255
268
|
* @returns The requested L2 blocks.
|
|
256
269
|
*/
|
|
257
|
-
public getL2Blocks(from: number,
|
|
258
|
-
if
|
|
259
|
-
|
|
270
|
+
public getL2Blocks(from: number, limit: number): Promise<L2Block[]> {
|
|
271
|
+
// Return an empty array if we are outside of range
|
|
272
|
+
if (limit < 1) {
|
|
273
|
+
throw new Error(`Invalid block range from: ${from}, limit: ${limit}`);
|
|
260
274
|
}
|
|
261
|
-
if (from > this.l2Blocks.length) {
|
|
275
|
+
if (from < INITIAL_L2_BLOCK_NUM || from > this.l2Blocks.length) {
|
|
262
276
|
return Promise.resolve([]);
|
|
263
277
|
}
|
|
264
278
|
const startIndex = from - INITIAL_L2_BLOCK_NUM;
|
|
265
|
-
const endIndex =
|
|
279
|
+
const endIndex = startIndex + limit;
|
|
266
280
|
return Promise.resolve(this.l2Blocks.slice(startIndex, endIndex));
|
|
267
281
|
}
|
|
268
282
|
|
|
269
283
|
/**
|
|
270
|
-
* Gets
|
|
271
|
-
* @param
|
|
284
|
+
* Gets up to `limit` amount of pending L1 to L2 messages, sorted by fee
|
|
285
|
+
* @param limit - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).
|
|
272
286
|
* @returns The requested L1 to L2 message keys.
|
|
273
287
|
*/
|
|
274
|
-
public getPendingL1ToL2MessageKeys(
|
|
275
|
-
return Promise.resolve(this.pendingL1ToL2Messages.getMessageKeys(
|
|
288
|
+
public getPendingL1ToL2MessageKeys(limit: number = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP): Promise<Fr[]> {
|
|
289
|
+
return Promise.resolve(this.pendingL1ToL2Messages.getMessageKeys(limit));
|
|
276
290
|
}
|
|
277
291
|
|
|
278
292
|
/**
|
|
@@ -283,28 +297,28 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
283
297
|
public getConfirmedL1ToL2Message(messageKey: Fr): Promise<L1ToL2Message> {
|
|
284
298
|
const message = this.confirmedL1ToL2Messages.getMessage(messageKey);
|
|
285
299
|
if (!message) {
|
|
286
|
-
throw new Error(`Message with key ${messageKey.toString()} not found`);
|
|
300
|
+
throw new Error(`L1 to L2 Message with key ${messageKey.toString()} not found in the confirmed messages store`);
|
|
287
301
|
}
|
|
288
302
|
return Promise.resolve(message);
|
|
289
303
|
}
|
|
290
304
|
|
|
291
305
|
/**
|
|
292
|
-
* Gets
|
|
306
|
+
* Gets up to `limit` amount of logs starting from `from`.
|
|
293
307
|
* @param from - Number of the L2 block to which corresponds the first logs to be returned.
|
|
294
|
-
* @param
|
|
308
|
+
* @param limit - The number of logs to return.
|
|
295
309
|
* @param logType - Specifies whether to return encrypted or unencrypted logs.
|
|
296
310
|
* @returns The requested logs.
|
|
297
311
|
*/
|
|
298
|
-
getLogs(from: number,
|
|
299
|
-
if (from < INITIAL_L2_BLOCK_NUM) {
|
|
300
|
-
throw new Error(`Invalid block range ${from}`);
|
|
312
|
+
getLogs(from: number, limit: number, logType: LogType): Promise<L2BlockL2Logs[]> {
|
|
313
|
+
if (from < INITIAL_L2_BLOCK_NUM || limit < 1) {
|
|
314
|
+
throw new Error(`Invalid block range from: ${from}, limit: ${limit}`);
|
|
301
315
|
}
|
|
302
316
|
const logs = logType === LogType.ENCRYPTED ? this.encryptedLogs : this.unencryptedLogs;
|
|
303
317
|
if (from > logs.length) {
|
|
304
318
|
return Promise.resolve([]);
|
|
305
319
|
}
|
|
306
320
|
const startIndex = from - INITIAL_L2_BLOCK_NUM;
|
|
307
|
-
const endIndex =
|
|
321
|
+
const endIndex = startIndex + limit;
|
|
308
322
|
return Promise.resolve(logs.slice(startIndex, endIndex));
|
|
309
323
|
}
|
|
310
324
|
|
|
@@ -313,29 +327,21 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
313
327
|
* @param contractAddress - The contract data address.
|
|
314
328
|
* @returns The contract's public data.
|
|
315
329
|
*/
|
|
316
|
-
public
|
|
317
|
-
|
|
318
|
-
for (let i = INITIAL_L2_BLOCK_NUM; i < this.contractPublicData.length; i++) {
|
|
319
|
-
const contracts = this.contractPublicData[i];
|
|
320
|
-
const contract = contracts?.find(c => c.contractData.contractAddress.equals(contractAddress));
|
|
321
|
-
if (contract) {
|
|
322
|
-
result = contract;
|
|
323
|
-
break;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
330
|
+
public getContractDataAndBytecode(contractAddress: AztecAddress): Promise<ContractDataAndBytecode | undefined> {
|
|
331
|
+
const result = this.contractDataAndBytecode.get(contractAddress.toString());
|
|
326
332
|
return Promise.resolve(result);
|
|
327
333
|
}
|
|
328
334
|
|
|
329
335
|
/**
|
|
330
336
|
* Lookup all contract data in an L2 block.
|
|
331
337
|
* @param blockNum - The block number to get all contract data from.
|
|
332
|
-
* @returns All contract
|
|
338
|
+
* @returns All contract data and bytecode in the block (if found).
|
|
333
339
|
*/
|
|
334
|
-
public
|
|
340
|
+
public getContractDataAndBytecodeInBlock(blockNum: number): Promise<ContractDataAndBytecode[]> {
|
|
335
341
|
if (blockNum > this.l2Blocks.length) {
|
|
336
342
|
return Promise.resolve([]);
|
|
337
343
|
}
|
|
338
|
-
return Promise.resolve(this.
|
|
344
|
+
return Promise.resolve(this.contractDataAndBytecodeByBlock[blockNum] || []);
|
|
339
345
|
}
|
|
340
346
|
|
|
341
347
|
/**
|
|
@@ -344,7 +350,10 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
344
350
|
* @param contractAddress - The contract data address.
|
|
345
351
|
* @returns ContractData with the portal address (if we didn't throw an error).
|
|
346
352
|
*/
|
|
347
|
-
public
|
|
353
|
+
public getContractData(contractAddress: AztecAddress): Promise<ContractData | undefined> {
|
|
354
|
+
if (contractAddress.isZero()) {
|
|
355
|
+
return Promise.resolve(undefined);
|
|
356
|
+
}
|
|
348
357
|
for (const block of this.l2Blocks) {
|
|
349
358
|
for (const contractData of block.newContractData) {
|
|
350
359
|
if (contractData.contractAddress.equals(contractAddress)) {
|
|
@@ -361,7 +370,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
361
370
|
* @param l2BlockNum - Number of the L2 block where contracts were deployed.
|
|
362
371
|
* @returns ContractData with the portal address (if we didn't throw an error).
|
|
363
372
|
*/
|
|
364
|
-
public
|
|
373
|
+
public getContractDataInBlock(l2BlockNum: number): Promise<ContractData[] | undefined> {
|
|
365
374
|
if (l2BlockNum > this.l2Blocks.length) {
|
|
366
375
|
return Promise.resolve([]);
|
|
367
376
|
}
|
package/src/archiver/config.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
2
|
import { L1Addresses } from '@aztec/types';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* There are 2 polling intervals used in this configuration. The first is the archiver polling interval, archiverPollingIntervalMS.
|
|
6
|
+
* This is the interval between successive calls to eth_blockNumber via viem.
|
|
7
|
+
* Results of calls to eth_blockNumber are cached by viem with this cache being updated periodically at the interval specified by viemPollingIntervalMS.
|
|
8
|
+
* As a result the maximum observed polling time for new blocks will be viemPollingIntervalMS + archiverPollingIntervalMS.
|
|
9
|
+
*/
|
|
10
|
+
|
|
4
11
|
/**
|
|
5
12
|
* The archiver configuration.
|
|
6
13
|
*/
|
|
@@ -18,7 +25,12 @@ export interface ArchiverConfig extends L1Addresses {
|
|
|
18
25
|
/**
|
|
19
26
|
* The polling interval in ms for retrieving new L2 blocks and encrypted logs.
|
|
20
27
|
*/
|
|
21
|
-
|
|
28
|
+
archiverPollingIntervalMS?: number;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The polling interval viem uses in ms
|
|
32
|
+
*/
|
|
33
|
+
viemPollingIntervalMS?: number;
|
|
22
34
|
|
|
23
35
|
/**
|
|
24
36
|
* Eth block from which we start scanning for L2Blocks.
|
|
@@ -34,7 +46,8 @@ export interface ArchiverConfig extends L1Addresses {
|
|
|
34
46
|
export function getConfigEnvVars(): ArchiverConfig {
|
|
35
47
|
const {
|
|
36
48
|
ETHEREUM_HOST,
|
|
37
|
-
|
|
49
|
+
ARCHIVER_POLLING_INTERVAL_MS,
|
|
50
|
+
ARCHIVER_VIEM_POLLING_INTERVAL_MS,
|
|
38
51
|
ROLLUP_CONTRACT_ADDRESS,
|
|
39
52
|
CONTRACT_DEPLOYMENT_EMITTER_ADDRESS,
|
|
40
53
|
SEARCH_START_BLOCK,
|
|
@@ -43,7 +56,8 @@ export function getConfigEnvVars(): ArchiverConfig {
|
|
|
43
56
|
} = process.env;
|
|
44
57
|
return {
|
|
45
58
|
rpcUrl: ETHEREUM_HOST || 'http://127.0.0.1:8545/',
|
|
46
|
-
|
|
59
|
+
archiverPollingIntervalMS: ARCHIVER_POLLING_INTERVAL_MS ? +ARCHIVER_POLLING_INTERVAL_MS : 1_000,
|
|
60
|
+
viemPollingIntervalMS: ARCHIVER_VIEM_POLLING_INTERVAL_MS ? +ARCHIVER_VIEM_POLLING_INTERVAL_MS : 1_000,
|
|
47
61
|
rollupContract: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO,
|
|
48
62
|
inboxContract: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO,
|
|
49
63
|
contractDeploymentEmitterContract: CONTRACT_DEPLOYMENT_EMITTER_ADDRESS
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import { ContractDataAndBytecode, L1ToL2Message, L2Block } from '@aztec/types';
|
|
4
|
+
|
|
1
5
|
import { PublicClient } from 'viem';
|
|
6
|
+
|
|
2
7
|
import {
|
|
3
8
|
getContractDeploymentLogs,
|
|
9
|
+
getL1ToL2MessageCancelledLogs,
|
|
4
10
|
getL2BlockProcessedLogs,
|
|
5
11
|
getPendingL1ToL2MessageLogs,
|
|
6
|
-
getL1ToL2MessageCancelledLogs,
|
|
7
12
|
processBlockLogs,
|
|
13
|
+
processCancelledL1ToL2MessagesLogs,
|
|
8
14
|
processContractDeploymentLogs,
|
|
9
15
|
processPendingL1ToL2MessageAddedLogs,
|
|
10
|
-
processCancelledL1ToL2MessagesLogs,
|
|
11
16
|
} from './eth_log_handlers.js';
|
|
12
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
13
|
-
import { ContractPublicData, L1ToL2Message, L2Block } from '@aztec/types';
|
|
14
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* Data retrieved from logs
|
|
@@ -71,7 +73,7 @@ export async function retrieveBlocks(
|
|
|
71
73
|
* @param currentBlockNumber - Latest available block number in the ETH node.
|
|
72
74
|
* @param searchStartBlock - The block number to use for starting the search.
|
|
73
75
|
* @param blockHashMapping - A mapping from block number to relevant block hash.
|
|
74
|
-
* @returns An array of
|
|
76
|
+
* @returns An array of ContractDataAndBytecode and their equivalent L2 Block number along with the next eth block to search from..
|
|
75
77
|
*/
|
|
76
78
|
export async function retrieveNewContractData(
|
|
77
79
|
publicClient: PublicClient,
|
|
@@ -80,8 +82,8 @@ export async function retrieveNewContractData(
|
|
|
80
82
|
currentBlockNumber: bigint,
|
|
81
83
|
searchStartBlock: bigint,
|
|
82
84
|
blockHashMapping: { [key: number]: Buffer | undefined },
|
|
83
|
-
): Promise<DataRetrieval<[
|
|
84
|
-
let retrievedNewContracts: [
|
|
85
|
+
): Promise<DataRetrieval<[ContractDataAndBytecode[], number]>> {
|
|
86
|
+
let retrievedNewContracts: [ContractDataAndBytecode[], number][] = [];
|
|
85
87
|
do {
|
|
86
88
|
if (searchStartBlock > currentBlockNumber) {
|
|
87
89
|
break;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
|
+
import { ContractDeploymentEmitterAbi, InboxAbi, RollupAbi } from '@aztec/l1-artifacts';
|
|
4
5
|
import {
|
|
5
|
-
L1ToL2Message,
|
|
6
|
-
L1Actor,
|
|
7
|
-
L2Actor,
|
|
8
|
-
L2Block,
|
|
9
|
-
ContractPublicData,
|
|
10
6
|
BufferReader,
|
|
11
7
|
ContractData,
|
|
8
|
+
ContractDataAndBytecode,
|
|
12
9
|
EncodedContractFunction,
|
|
10
|
+
L1Actor,
|
|
11
|
+
L1ToL2Message,
|
|
12
|
+
L2Actor,
|
|
13
|
+
L2Block,
|
|
13
14
|
} from '@aztec/types';
|
|
14
|
-
|
|
15
|
-
import {
|
|
15
|
+
|
|
16
|
+
import { Hex, Log, PublicClient, decodeFunctionData, getAbiItem, getAddress, hexToBytes } from 'viem';
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Processes newly received MessageAdded (L1 to L2) logs.
|
|
@@ -162,13 +163,13 @@ export async function getContractDeploymentLogs(
|
|
|
162
163
|
* Processes newly received ContractDeployment logs.
|
|
163
164
|
* @param blockHashMapping - A mapping from block number to relevant block hash.
|
|
164
165
|
* @param logs - ContractDeployment logs.
|
|
165
|
-
* @returns The set of retrieved contract
|
|
166
|
+
* @returns The set of retrieved contract data and bytecode items.
|
|
166
167
|
*/
|
|
167
168
|
export function processContractDeploymentLogs(
|
|
168
169
|
blockHashMapping: { [key: number]: Buffer | undefined },
|
|
169
170
|
logs: Log<bigint, number, undefined, true, typeof ContractDeploymentEmitterAbi, 'ContractDeployment'>[],
|
|
170
|
-
): [
|
|
171
|
-
const
|
|
171
|
+
): [ContractDataAndBytecode[], number][] {
|
|
172
|
+
const contractDataAndBytecode: [ContractDataAndBytecode[], number][] = [];
|
|
172
173
|
for (let i = 0; i < logs.length; i++) {
|
|
173
174
|
const log = logs[i];
|
|
174
175
|
const l2BlockNum = Number(log.args.l2BlockNum);
|
|
@@ -178,17 +179,17 @@ export function processContractDeploymentLogs(
|
|
|
178
179
|
continue;
|
|
179
180
|
}
|
|
180
181
|
const publicFnsReader = BufferReader.asReader(Buffer.from(log.args.acir.slice(2), 'hex'));
|
|
181
|
-
const contractData = new
|
|
182
|
+
const contractData = new ContractDataAndBytecode(
|
|
182
183
|
new ContractData(AztecAddress.fromString(log.args.aztecAddress), EthAddress.fromString(log.args.portalAddress)),
|
|
183
184
|
publicFnsReader.readVector(EncodedContractFunction),
|
|
184
185
|
);
|
|
185
|
-
if (
|
|
186
|
-
|
|
186
|
+
if (contractDataAndBytecode[i]) {
|
|
187
|
+
contractDataAndBytecode[i][0].push(contractData);
|
|
187
188
|
} else {
|
|
188
|
-
|
|
189
|
+
contractDataAndBytecode[i] = [[contractData], l2BlockNum];
|
|
189
190
|
}
|
|
190
191
|
}
|
|
191
|
-
return
|
|
192
|
+
return contractDataAndBytecode;
|
|
192
193
|
}
|
|
193
194
|
|
|
194
195
|
/**
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { L1ToL2MessageStore, PendingL1ToL2MessageStore } from './l1_to_l2_message_store.js';
|
|
3
2
|
import { L1Actor, L1ToL2Message, L2Actor } from '@aztec/types';
|
|
4
3
|
|
|
4
|
+
import { L1ToL2MessageStore, PendingL1ToL2MessageStore } from './l1_to_l2_message_store.js';
|
|
5
|
+
|
|
5
6
|
describe('l1_to_l2_message_store', () => {
|
|
6
7
|
let store: L1ToL2MessageStore;
|
|
7
8
|
let entryKey: Fr;
|
|
@@ -62,12 +63,12 @@ describe('pending_l1_to_l2_message_store', () => {
|
|
|
62
63
|
expect(store.getMessageKeys(10)).toEqual([]);
|
|
63
64
|
});
|
|
64
65
|
|
|
65
|
-
it('getMessageKeys returns an empty array if
|
|
66
|
+
it('getMessageKeys returns an empty array if limit is 0', () => {
|
|
66
67
|
store.addMessage(entryKey, msg);
|
|
67
68
|
expect(store.getMessageKeys(0)).toEqual([]);
|
|
68
69
|
});
|
|
69
70
|
|
|
70
|
-
it('get messages for a non-empty store when
|
|
71
|
+
it('get messages for a non-empty store when limit > number of messages in store', () => {
|
|
71
72
|
const entryKeys = [1, 2, 3, 4, 5].map(x => new Fr(x));
|
|
72
73
|
entryKeys.forEach(entryKey => {
|
|
73
74
|
store.addMessage(entryKey, L1ToL2Message.random());
|
|
@@ -38,18 +38,18 @@ export class L1ToL2MessageStore {
|
|
|
38
38
|
* for removing messages or fetching multiple messages.
|
|
39
39
|
*/
|
|
40
40
|
export class PendingL1ToL2MessageStore extends L1ToL2MessageStore {
|
|
41
|
-
getMessageKeys(
|
|
42
|
-
if (
|
|
41
|
+
getMessageKeys(limit: number): Fr[] {
|
|
42
|
+
if (limit < 1) {
|
|
43
43
|
return [];
|
|
44
44
|
}
|
|
45
|
-
// fetch `
|
|
45
|
+
// fetch `limit` number of messages from the store with the highest fee.
|
|
46
46
|
// Note the store has multiple of the same message. So if a message has count 2, include both of them in the result:
|
|
47
47
|
const messages: Fr[] = [];
|
|
48
48
|
const sortedMessages = Array.from(this.store.values()).sort((a, b) => b.message.fee - a.message.fee);
|
|
49
49
|
for (const messageAndCount of sortedMessages) {
|
|
50
50
|
for (let i = 0; i < messageAndCount.count; i++) {
|
|
51
51
|
messages.push(messageAndCount.message.entryKey!);
|
|
52
|
-
if (messages.length ===
|
|
52
|
+
if (messages.length === limit) {
|
|
53
53
|
return messages;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
@@ -63,7 +63,7 @@ export class PendingL1ToL2MessageStore extends L1ToL2MessageStore {
|
|
|
63
63
|
const messageKeyBigInt = messageKey.value;
|
|
64
64
|
const msgAndCount = this.store.get(messageKeyBigInt);
|
|
65
65
|
if (!msgAndCount) {
|
|
66
|
-
throw new Error(`Message with key ${messageKeyBigInt} not found in store`);
|
|
66
|
+
throw new Error(`Unable to remove message: L1 to L2 Message with key ${messageKeyBigInt} not found in store`);
|
|
67
67
|
}
|
|
68
68
|
if (msgAndCount.count > 1) {
|
|
69
69
|
msgAndCount.count--;
|
package/src/index.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import { createDebugLogger } from '@aztec/foundation/log';
|
|
2
|
+
|
|
1
3
|
import { fileURLToPath } from 'url';
|
|
2
4
|
import { createPublicClient, http } from 'viem';
|
|
3
5
|
import { localhost } from 'viem/chains';
|
|
4
|
-
|
|
6
|
+
|
|
5
7
|
import { MemoryArchiverStore } from './archiver/archiver_store.js';
|
|
6
|
-
import {
|
|
8
|
+
import { Archiver, getConfigEnvVars } from './archiver/index.js';
|
|
7
9
|
|
|
8
10
|
export * from './archiver/index.js';
|
|
9
11
|
|
|
10
|
-
const log =
|
|
12
|
+
const log = createDebugLogger('aztec:archiver');
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* A function which instantiates and starts Archiver.
|
|
@@ -45,7 +47,7 @@ async function main() {
|
|
|
45
47
|
if (process.argv[1] === fileURLToPath(import.meta.url).replace(/\/index\.js$/, '')) {
|
|
46
48
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
47
49
|
main().catch(err => {
|
|
48
|
-
log(err);
|
|
50
|
+
log.fatal(err);
|
|
49
51
|
process.exit(1);
|
|
50
52
|
});
|
|
51
53
|
}
|