@aztec/archiver 0.28.0 → 0.29.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.
- package/dest/archiver/archiver.d.ts +13 -53
- package/dest/archiver/archiver.d.ts.map +1 -1
- package/dest/archiver/archiver.js +42 -180
- package/dest/archiver/archiver_store.d.ts +17 -63
- package/dest/archiver/archiver_store.d.ts.map +1 -1
- package/dest/archiver/archiver_store_test_suite.d.ts.map +1 -1
- package/dest/archiver/archiver_store_test_suite.js +26 -168
- package/dest/archiver/data_retrieval.d.ts +5 -26
- package/dest/archiver/data_retrieval.d.ts.map +1 -1
- package/dest/archiver/data_retrieval.js +10 -64
- package/dest/archiver/eth_log_handlers.d.ts +5 -36
- package/dest/archiver/eth_log_handlers.d.ts.map +1 -1
- package/dest/archiver/eth_log_handlers.js +7 -75
- package/dest/archiver/kv_archiver_store/block_store.d.ts +2 -2
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/block_store.js +3 -3
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +11 -52
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +21 -84
- package/dest/archiver/kv_archiver_store/message_store.d.ts +10 -41
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/message_store.js +31 -136
- package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts +8 -41
- package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts.map +1 -1
- package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.js +22 -79
- package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +14 -76
- package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +1 -1
- package/dest/archiver/memory_archiver_store/memory_archiver_store.js +22 -134
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -15
- package/dest/rpc/archiver_client.d.ts.map +1 -1
- package/dest/rpc/archiver_client.js +2 -6
- package/dest/rpc/archiver_server.d.ts.map +1 -1
- package/dest/rpc/archiver_server.js +2 -6
- package/package.json +9 -9
- package/src/archiver/archiver.ts +47 -230
- package/src/archiver/archiver_store.ts +17 -72
- package/src/archiver/archiver_store_test_suite.ts +25 -208
- package/src/archiver/data_retrieval.ts +11 -93
- package/src/archiver/eth_log_handlers.ts +10 -104
- package/src/archiver/kv_archiver_store/block_store.ts +2 -2
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +19 -89
- package/src/archiver/kv_archiver_store/message_store.ts +36 -165
- package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +21 -90
- package/src/archiver/memory_archiver_store/memory_archiver_store.ts +23 -150
- package/src/index.ts +1 -15
- package/src/rpc/archiver_client.ts +0 -8
- package/src/rpc/archiver_server.ts +0 -8
- package/dest/archiver/kv_archiver_store/contract_store.d.ts +0 -26
- package/dest/archiver/kv_archiver_store/contract_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_store.js +0 -49
- package/src/archiver/kv_archiver_store/contract_store.ts +0 -55
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Body,
|
|
3
|
-
ExtendedContractData,
|
|
4
3
|
ExtendedUnencryptedL2Log,
|
|
5
4
|
GetUnencryptedLogsResponse,
|
|
6
|
-
|
|
5
|
+
InboxLeaf,
|
|
7
6
|
L2Block,
|
|
8
7
|
L2BlockContext,
|
|
9
8
|
L2BlockL2Logs,
|
|
10
9
|
LogFilter,
|
|
11
10
|
LogId,
|
|
12
11
|
LogType,
|
|
13
|
-
NewInboxLeaf,
|
|
14
12
|
TxEffect,
|
|
15
13
|
TxHash,
|
|
16
14
|
TxReceipt,
|
|
17
15
|
TxStatus,
|
|
18
16
|
UnencryptedL2Log,
|
|
19
17
|
} from '@aztec/circuit-types';
|
|
20
|
-
import { Fr, INITIAL_L2_BLOCK_NUM
|
|
18
|
+
import { Fr, INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js';
|
|
21
19
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
22
20
|
import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts';
|
|
23
21
|
|
|
24
|
-
import { ArchiverDataStore } from '../archiver_store.js';
|
|
25
|
-
import { L1ToL2MessageStore
|
|
22
|
+
import { ArchiverDataStore, ArchiverL1SynchPoint } from '../archiver_store.js';
|
|
23
|
+
import { L1ToL2MessageStore } from './l1_to_l2_message_store.js';
|
|
26
24
|
|
|
27
25
|
/**
|
|
28
26
|
* Simple, in-memory implementation of an archiver data store.
|
|
@@ -56,36 +54,15 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
56
54
|
private unencryptedLogsPerBlock: L2BlockL2Logs[] = [];
|
|
57
55
|
|
|
58
56
|
/**
|
|
59
|
-
*
|
|
57
|
+
* Contains all L1 to L2 messages.
|
|
60
58
|
*/
|
|
61
|
-
private
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* A mapping of contract address to extended contract data.
|
|
65
|
-
*/
|
|
66
|
-
private extendedContractData: Map<string, ExtendedContractData> = new Map();
|
|
67
|
-
|
|
68
|
-
// TODO(#4492): Nuke the other message stores
|
|
69
|
-
private newL1ToL2Messages = new NewL1ToL2MessageStore();
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Contains all the confirmed L1 to L2 messages (i.e. messages that were consumed in an L2 block)
|
|
73
|
-
* It is a map of entryKey to the corresponding L1 to L2 message and the number of times it has appeared
|
|
74
|
-
*/
|
|
75
|
-
private confirmedL1ToL2Messages: L1ToL2MessageStore = new L1ToL2MessageStore();
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Contains all the pending L1 to L2 messages (accounts for duplication of messages)
|
|
79
|
-
*/
|
|
80
|
-
private pendingL1ToL2Messages: PendingL1ToL2MessageStore = new PendingL1ToL2MessageStore();
|
|
59
|
+
private l1ToL2Messages = new L1ToL2MessageStore();
|
|
81
60
|
|
|
82
61
|
private contractClasses: Map<string, ContractClassPublic> = new Map();
|
|
83
62
|
|
|
84
63
|
private contractInstances: Map<string, ContractInstanceWithAddress> = new Map();
|
|
85
64
|
|
|
86
65
|
private lastL1BlockNewMessages: bigint = 0n;
|
|
87
|
-
private lastL1BlockAddedMessages: bigint = 0n;
|
|
88
|
-
private lastL1BlockCancelledMessages: bigint = 0n;
|
|
89
66
|
|
|
90
67
|
constructor(
|
|
91
68
|
/** The max number of logs that can be obtained in 1 "getUnencryptedLogs" call. */
|
|
@@ -178,97 +155,30 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
178
155
|
}
|
|
179
156
|
|
|
180
157
|
/**
|
|
181
|
-
* Append
|
|
158
|
+
* Append L1 to L2 messages to the store.
|
|
182
159
|
* @param messages - The L1 to L2 messages to be added to the store.
|
|
183
160
|
* @param lastMessageL1BlockNumber - The L1 block number in which the last message was emitted.
|
|
184
161
|
* @returns True if the operation is successful.
|
|
185
162
|
*/
|
|
186
|
-
public
|
|
163
|
+
public addL1ToL2Messages(messages: InboxLeaf[], lastMessageL1BlockNumber: bigint): Promise<boolean> {
|
|
187
164
|
if (lastMessageL1BlockNumber <= this.lastL1BlockNewMessages) {
|
|
188
165
|
return Promise.resolve(false);
|
|
189
166
|
}
|
|
190
167
|
|
|
191
168
|
this.lastL1BlockNewMessages = lastMessageL1BlockNumber;
|
|
192
169
|
for (const message of messages) {
|
|
193
|
-
this.
|
|
194
|
-
}
|
|
195
|
-
return Promise.resolve(true);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Append new pending L1 to L2 messages to the store.
|
|
200
|
-
* @param messages - The L1 to L2 messages to be added to the store.
|
|
201
|
-
* @param l1BlockNumber - The L1 block number for which to add the messages.
|
|
202
|
-
* @returns True if the operation is successful (always in this implementation).
|
|
203
|
-
*/
|
|
204
|
-
public addPendingL1ToL2Messages(messages: L1ToL2Message[], l1BlockNumber: bigint): Promise<boolean> {
|
|
205
|
-
if (l1BlockNumber <= this.lastL1BlockAddedMessages) {
|
|
206
|
-
return Promise.resolve(false);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
this.lastL1BlockAddedMessages = l1BlockNumber;
|
|
210
|
-
for (const message of messages) {
|
|
211
|
-
this.pendingL1ToL2Messages.addMessage(message.entryKey!, message);
|
|
212
|
-
}
|
|
213
|
-
return Promise.resolve(true);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Remove pending L1 to L2 messages from the store (if they were cancelled).
|
|
218
|
-
* @param messages - The entry keys to be removed from the store.
|
|
219
|
-
* @param l1BlockNumber - The L1 block number for which to remove the messages.
|
|
220
|
-
* @returns True if the operation is successful (always in this implementation).
|
|
221
|
-
*/
|
|
222
|
-
public cancelPendingL1ToL2EntryKeys(messages: Fr[], l1BlockNumber: bigint): Promise<boolean> {
|
|
223
|
-
if (l1BlockNumber <= this.lastL1BlockCancelledMessages) {
|
|
224
|
-
return Promise.resolve(false);
|
|
170
|
+
this.l1ToL2Messages.addMessage(message);
|
|
225
171
|
}
|
|
226
|
-
|
|
227
|
-
this.lastL1BlockCancelledMessages = l1BlockNumber;
|
|
228
|
-
messages.forEach(entryKey => {
|
|
229
|
-
this.pendingL1ToL2Messages.removeMessage(entryKey);
|
|
230
|
-
});
|
|
231
172
|
return Promise.resolve(true);
|
|
232
173
|
}
|
|
233
174
|
|
|
234
175
|
/**
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
* @
|
|
238
|
-
* @returns True if the operation is successful (always in this implementation).
|
|
176
|
+
* Gets the L1 to L2 message index in the L1 to L2 message tree.
|
|
177
|
+
* @param l1ToL2Message - The L1 to L2 message.
|
|
178
|
+
* @returns The index of the L1 to L2 message in the L1 to L2 message tree.
|
|
239
179
|
*/
|
|
240
|
-
public
|
|
241
|
-
|
|
242
|
-
if (entryKey.equals(Fr.ZERO)) {
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
this.confirmedL1ToL2Messages.addMessage(entryKey, this.pendingL1ToL2Messages.getMessage(entryKey)!);
|
|
247
|
-
this.pendingL1ToL2Messages.removeMessage(entryKey);
|
|
248
|
-
});
|
|
249
|
-
return Promise.resolve(true);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Store new extended contract data from an L2 block to the store's list.
|
|
254
|
-
* @param data - List of contracts' data to be added.
|
|
255
|
-
* @param blockNum - Number of the L2 block the contract data was deployed in.
|
|
256
|
-
* @returns True if the operation is successful (always in this implementation).
|
|
257
|
-
*/
|
|
258
|
-
public addExtendedContractData(data: ExtendedContractData[], blockNum: number): Promise<boolean> {
|
|
259
|
-
// Add to the contracts mapping
|
|
260
|
-
for (const contractData of data) {
|
|
261
|
-
const key = contractData.contractData.contractAddress.toString();
|
|
262
|
-
this.extendedContractData.set(key, contractData);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// Add the index per block
|
|
266
|
-
if (this.extendedContractDataByBlock[blockNum]?.length) {
|
|
267
|
-
this.extendedContractDataByBlock[blockNum]?.push(...data);
|
|
268
|
-
} else {
|
|
269
|
-
this.extendedContractDataByBlock[blockNum] = [...data];
|
|
270
|
-
}
|
|
271
|
-
return Promise.resolve(true);
|
|
180
|
+
public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint> {
|
|
181
|
+
return Promise.resolve(this.l1ToL2Messages.getMessageIndex(l1ToL2Message));
|
|
272
182
|
}
|
|
273
183
|
|
|
274
184
|
/**
|
|
@@ -322,34 +232,12 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
322
232
|
}
|
|
323
233
|
|
|
324
234
|
/**
|
|
325
|
-
* Gets
|
|
326
|
-
* @param limit - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).
|
|
327
|
-
* @returns The requested L1 to L2 entry keys.
|
|
328
|
-
*/
|
|
329
|
-
public getPendingL1ToL2EntryKeys(limit: number = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP): Promise<Fr[]> {
|
|
330
|
-
return Promise.resolve(this.pendingL1ToL2Messages.getEntryKeys(limit));
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Gets the confirmed L1 to L2 message corresponding to the given entry key.
|
|
335
|
-
* @param entryKey - The entry key to look up.
|
|
336
|
-
* @returns The requested L1 to L2 message or throws if not found.
|
|
337
|
-
*/
|
|
338
|
-
public getConfirmedL1ToL2Message(entryKey: Fr): Promise<L1ToL2Message> {
|
|
339
|
-
const message = this.confirmedL1ToL2Messages.getMessage(entryKey);
|
|
340
|
-
if (!message) {
|
|
341
|
-
throw new Error(`L1 to L2 Message with key ${entryKey.toString()} not found in the confirmed messages store`);
|
|
342
|
-
}
|
|
343
|
-
return Promise.resolve(message);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Gets new L1 to L2 message (to be) included in a given block.
|
|
235
|
+
* Gets L1 to L2 message (to be) included in a given block.
|
|
348
236
|
* @param blockNumber - L2 block number to get messages for.
|
|
349
237
|
* @returns The L1 to L2 messages/leaves of the messages subtree (throws if not found).
|
|
350
238
|
*/
|
|
351
|
-
|
|
352
|
-
return Promise.resolve(this.
|
|
239
|
+
getL1ToL2Messages(blockNumber: bigint): Promise<Fr[]> {
|
|
240
|
+
return Promise.resolve(this.l1ToL2Messages.getMessages(blockNumber));
|
|
353
241
|
}
|
|
354
242
|
|
|
355
243
|
/**
|
|
@@ -456,39 +344,24 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
456
344
|
});
|
|
457
345
|
}
|
|
458
346
|
|
|
459
|
-
/**
|
|
460
|
-
* Get the extended contract data for this contract.
|
|
461
|
-
* TODO(palla/purge-old-contract-deploy): Delete me?
|
|
462
|
-
* @param contractAddress - The contract data address.
|
|
463
|
-
* @returns The extended contract data or undefined if not found.
|
|
464
|
-
*/
|
|
465
|
-
getExtendedContractData(contractAddress: AztecAddress): Promise<ExtendedContractData | undefined> {
|
|
466
|
-
const result = this.extendedContractData.get(contractAddress.toString());
|
|
467
|
-
return Promise.resolve(result);
|
|
468
|
-
}
|
|
469
|
-
|
|
470
347
|
/**
|
|
471
348
|
* Gets the number of the latest L2 block processed.
|
|
472
349
|
* @returns The number of the latest L2 block processed.
|
|
473
350
|
*/
|
|
474
|
-
public
|
|
351
|
+
public getSynchedL2BlockNumber(): Promise<number> {
|
|
475
352
|
if (this.l2BlockContexts.length === 0) {
|
|
476
353
|
return Promise.resolve(INITIAL_L2_BLOCK_NUM - 1);
|
|
477
354
|
}
|
|
478
355
|
return Promise.resolve(this.l2BlockContexts[this.l2BlockContexts.length - 1].block.number);
|
|
479
356
|
}
|
|
480
357
|
|
|
481
|
-
public
|
|
482
|
-
const
|
|
483
|
-
const
|
|
484
|
-
const addedMessages = this.lastL1BlockAddedMessages;
|
|
485
|
-
const cancelledMessages = this.lastL1BlockCancelledMessages;
|
|
358
|
+
public getSynchedL1BlockNumbers(): Promise<ArchiverL1SynchPoint> {
|
|
359
|
+
const blocks = this.l2BlockContexts[this.l2BlockContexts.length - 1]?.block?.getL1BlockNumber() ?? 0n;
|
|
360
|
+
const messages = this.lastL1BlockNewMessages;
|
|
486
361
|
|
|
487
362
|
return Promise.resolve({
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
addedMessages,
|
|
491
|
-
cancelledMessages,
|
|
363
|
+
blocks,
|
|
364
|
+
messages,
|
|
492
365
|
});
|
|
493
366
|
}
|
|
494
367
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
1
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
3
2
|
import { fileURLToPath } from '@aztec/foundation/url';
|
|
4
|
-
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
5
3
|
|
|
6
|
-
import { createPublicClient,
|
|
4
|
+
import { createPublicClient, http } from 'viem';
|
|
7
5
|
import { localhost } from 'viem/chains';
|
|
8
6
|
|
|
9
7
|
import { Archiver, getConfigEnvVars } from './archiver/index.js';
|
|
@@ -29,23 +27,11 @@ async function main() {
|
|
|
29
27
|
|
|
30
28
|
const archiverStore = new MemoryArchiverStore(1000);
|
|
31
29
|
|
|
32
|
-
// TODO(#4492): Nuke this once the old inbox is purged
|
|
33
|
-
let newInboxAddress!: EthAddress;
|
|
34
|
-
{
|
|
35
|
-
const rollup = getContract({
|
|
36
|
-
address: getAddress(l1Contracts.rollupAddress.toString()),
|
|
37
|
-
abi: RollupAbi,
|
|
38
|
-
client: publicClient,
|
|
39
|
-
});
|
|
40
|
-
newInboxAddress = EthAddress.fromString(await rollup.read.NEW_INBOX());
|
|
41
|
-
}
|
|
42
|
-
|
|
43
30
|
const archiver = new Archiver(
|
|
44
31
|
publicClient,
|
|
45
32
|
l1Contracts.rollupAddress,
|
|
46
33
|
l1Contracts.availabilityOracleAddress,
|
|
47
34
|
l1Contracts.inboxAddress,
|
|
48
|
-
newInboxAddress,
|
|
49
35
|
l1Contracts.registryAddress,
|
|
50
36
|
archiverStore,
|
|
51
37
|
);
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ContractData,
|
|
3
|
-
EncodedContractFunction,
|
|
4
|
-
ExtendedContractData,
|
|
5
2
|
ExtendedUnencryptedL2Log,
|
|
6
|
-
L1ToL2Message,
|
|
7
3
|
L2Block,
|
|
8
4
|
L2BlockL2Logs,
|
|
9
5
|
NullifierMembershipWitness,
|
|
@@ -18,13 +14,9 @@ export const createArchiverClient = (url: string, fetch = makeFetch([1, 2, 3], t
|
|
|
18
14
|
createJsonRpcClient<ArchiveSource>(
|
|
19
15
|
url,
|
|
20
16
|
{
|
|
21
|
-
ContractData,
|
|
22
|
-
EncodedContractFunction,
|
|
23
17
|
EthAddress,
|
|
24
|
-
ExtendedContractData,
|
|
25
18
|
ExtendedUnencryptedL2Log,
|
|
26
19
|
Fr,
|
|
27
|
-
L1ToL2Message,
|
|
28
20
|
L2Block,
|
|
29
21
|
L2BlockL2Logs,
|
|
30
22
|
},
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ContractData,
|
|
3
|
-
EncodedContractFunction,
|
|
4
|
-
ExtendedContractData,
|
|
5
2
|
ExtendedUnencryptedL2Log,
|
|
6
|
-
L1ToL2Message,
|
|
7
3
|
L2Block,
|
|
8
4
|
L2BlockL2Logs,
|
|
9
5
|
NullifierMembershipWitness,
|
|
@@ -24,13 +20,9 @@ export function createArchiverRpcServer(archiverService: Archiver): JsonRpcServe
|
|
|
24
20
|
return new JsonRpcServer(
|
|
25
21
|
archiverService,
|
|
26
22
|
{
|
|
27
|
-
ContractData,
|
|
28
|
-
EncodedContractFunction,
|
|
29
23
|
EthAddress,
|
|
30
|
-
ExtendedContractData,
|
|
31
24
|
ExtendedUnencryptedL2Log,
|
|
32
25
|
Fr,
|
|
33
|
-
L1ToL2Message,
|
|
34
26
|
L2Block,
|
|
35
27
|
L2BlockL2Logs,
|
|
36
28
|
TxEffect,
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ExtendedContractData } from '@aztec/circuit-types';
|
|
2
|
-
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
3
|
-
import { AztecKVStore } from '@aztec/kv-store';
|
|
4
|
-
import { BlockStore } from './block_store.js';
|
|
5
|
-
/**
|
|
6
|
-
* LMDB implementation of the ArchiverDataStore interface.
|
|
7
|
-
*/
|
|
8
|
-
export declare class ContractStore {
|
|
9
|
-
#private;
|
|
10
|
-
private db;
|
|
11
|
-
constructor(db: AztecKVStore, blockStore: BlockStore);
|
|
12
|
-
/**
|
|
13
|
-
* Add new extended contract data from an L2 block to the store's list.
|
|
14
|
-
* @param data - List of contracts' data to be added.
|
|
15
|
-
* @param blockNum - Number of the L2 block the contract data was deployed in.
|
|
16
|
-
* @returns True if the operation is successful.
|
|
17
|
-
*/
|
|
18
|
-
addExtendedContractData(data: ExtendedContractData[], blockNum: number): Promise<boolean>;
|
|
19
|
-
/**
|
|
20
|
-
* Get the extended contract data for this contract.
|
|
21
|
-
* @param contractAddress - The contract data address.
|
|
22
|
-
* @returns The extended contract data or undefined if not found.
|
|
23
|
-
*/
|
|
24
|
-
getExtendedContractData(contractAddress: AztecAddress): ExtendedContractData | undefined;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=contract_store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contract_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/kv_archiver_store/contract_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAY,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;GAEG;AACH,qBAAa,aAAa;;IAKZ,OAAO,CAAC,EAAE;gBAAF,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU;IAK5D;;;;;OAKG;IACH,uBAAuB,CAAC,IAAI,EAAE,oBAAoB,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOzF;;;;OAIG;IACH,uBAAuB,CAAC,eAAe,EAAE,YAAY,GAAG,oBAAoB,GAAG,SAAS;CAgBzF"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
var _ContractStore_blockStore, _ContractStore_extendedContractData, _ContractStore_log;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
-
import { ExtendedContractData } from '@aztec/circuit-types';
|
|
4
|
-
import { createDebugLogger } from '@aztec/foundation/log';
|
|
5
|
-
/**
|
|
6
|
-
* LMDB implementation of the ArchiverDataStore interface.
|
|
7
|
-
*/
|
|
8
|
-
export class ContractStore {
|
|
9
|
-
constructor(db, blockStore) {
|
|
10
|
-
this.db = db;
|
|
11
|
-
_ContractStore_blockStore.set(this, void 0);
|
|
12
|
-
_ContractStore_extendedContractData.set(this, void 0);
|
|
13
|
-
_ContractStore_log.set(this, createDebugLogger('aztec:archiver:contract_store'));
|
|
14
|
-
__classPrivateFieldSet(this, _ContractStore_extendedContractData, db.openMap('archiver_extended_contract_data'), "f");
|
|
15
|
-
__classPrivateFieldSet(this, _ContractStore_blockStore, blockStore, "f");
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Add new extended contract data from an L2 block to the store's list.
|
|
19
|
-
* @param data - List of contracts' data to be added.
|
|
20
|
-
* @param blockNum - Number of the L2 block the contract data was deployed in.
|
|
21
|
-
* @returns True if the operation is successful.
|
|
22
|
-
*/
|
|
23
|
-
addExtendedContractData(data, blockNum) {
|
|
24
|
-
return __classPrivateFieldGet(this, _ContractStore_extendedContractData, "f").swap(blockNum, (existingData = []) => {
|
|
25
|
-
existingData.push(...data.map(d => d.toBuffer()));
|
|
26
|
-
return existingData;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Get the extended contract data for this contract.
|
|
31
|
-
* @param contractAddress - The contract data address.
|
|
32
|
-
* @returns The extended contract data or undefined if not found.
|
|
33
|
-
*/
|
|
34
|
-
getExtendedContractData(contractAddress) {
|
|
35
|
-
const [blockNumber, _] = __classPrivateFieldGet(this, _ContractStore_blockStore, "f").getContractLocation(contractAddress) ?? [];
|
|
36
|
-
if (typeof blockNumber !== 'number') {
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
for (const contract of __classPrivateFieldGet(this, _ContractStore_extendedContractData, "f").get(blockNumber) ?? []) {
|
|
40
|
-
const extendedContractData = ExtendedContractData.fromBuffer(contract);
|
|
41
|
-
if (extendedContractData.contractData.contractAddress.equals(contractAddress)) {
|
|
42
|
-
return extendedContractData;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
_ContractStore_blockStore = new WeakMap(), _ContractStore_extendedContractData = new WeakMap(), _ContractStore_log = new WeakMap();
|
|
49
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJhY3Rfc3RvcmUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXJjaGl2ZXIva3ZfYXJjaGl2ZXJfc3RvcmUvY29udHJhY3Rfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxPQUFPLEVBQUUsb0JBQW9CLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUU1RCxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUsxRDs7R0FFRztBQUNILE1BQU0sT0FBTyxhQUFhO0lBS3hCLFlBQW9CLEVBQWdCLEVBQUUsVUFBc0I7UUFBeEMsT0FBRSxHQUFGLEVBQUUsQ0FBYztRQUpwQyw0Q0FBd0I7UUFDeEIsc0RBQWtEO1FBQ2xELDZCQUFPLGlCQUFpQixDQUFDLCtCQUErQixDQUFDLEVBQUM7UUFHeEQsdUJBQUEsSUFBSSx1Q0FBeUIsRUFBRSxDQUFDLE9BQU8sQ0FBQyxpQ0FBaUMsQ0FBQyxNQUFBLENBQUM7UUFDM0UsdUJBQUEsSUFBSSw2QkFBZSxVQUFVLE1BQUEsQ0FBQztJQUNoQyxDQUFDO0lBRUQ7Ozs7O09BS0c7SUFDSCx1QkFBdUIsQ0FBQyxJQUE0QixFQUFFLFFBQWdCO1FBQ3BFLE9BQU8sdUJBQUEsSUFBSSwyQ0FBc0IsQ0FBQyxJQUFJLENBQUMsUUFBUSxFQUFFLENBQUMsWUFBWSxHQUFHLEVBQUUsRUFBRSxFQUFFO1lBQ3JFLFlBQVksQ0FBQyxJQUFJLENBQUMsR0FBRyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxFQUFFLENBQUMsQ0FBQyxDQUFDLFFBQVEsRUFBRSxDQUFDLENBQUMsQ0FBQztZQUNsRCxPQUFPLFlBQVksQ0FBQztRQUN0QixDQUFDLENBQUMsQ0FBQztJQUNMLENBQUM7SUFFRDs7OztPQUlHO0lBQ0gsdUJBQXVCLENBQUMsZUFBNkI7UUFDbkQsTUFBTSxDQUFDLFdBQVcsRUFBRSxDQUFDLENBQUMsR0FBRyx1QkFBQSxJQUFJLGlDQUFZLENBQUMsbUJBQW1CLENBQUMsZUFBZSxDQUFDLElBQUksRUFBRSxDQUFDO1FBRXJGLElBQUksT0FBTyxXQUFXLEtBQUssUUFBUSxFQUFFLENBQUM7WUFDcEMsT0FBTyxTQUFTLENBQUM7UUFDbkIsQ0FBQztRQUVELEtBQUssTUFBTSxRQUFRLElBQUksdUJBQUEsSUFBSSwyQ0FBc0IsQ0FBQyxHQUFHLENBQUMsV0FBVyxDQUFDLElBQUksRUFBRSxFQUFFLENBQUM7WUFDekUsTUFBTSxvQkFBb0IsR0FBRyxvQkFBb0IsQ0FBQyxVQUFVLENBQUMsUUFBUSxDQUFDLENBQUM7WUFDdkUsSUFBSSxvQkFBb0IsQ0FBQyxZQUFZLENBQUMsZUFBZSxDQUFDLE1BQU0sQ0FBQyxlQUFlLENBQUMsRUFBRSxDQUFDO2dCQUM5RSxPQUFPLG9CQUFvQixDQUFDO1lBQzlCLENBQUM7UUFDSCxDQUFDO1FBRUQsT0FBTyxTQUFTLENBQUM7SUFDbkIsQ0FBQztDQUNGIn0=
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { ExtendedContractData } from '@aztec/circuit-types';
|
|
2
|
-
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
3
|
-
import { createDebugLogger } from '@aztec/foundation/log';
|
|
4
|
-
import { AztecKVStore, AztecMap } from '@aztec/kv-store';
|
|
5
|
-
|
|
6
|
-
import { BlockStore } from './block_store.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* LMDB implementation of the ArchiverDataStore interface.
|
|
10
|
-
*/
|
|
11
|
-
export class ContractStore {
|
|
12
|
-
#blockStore: BlockStore;
|
|
13
|
-
#extendedContractData: AztecMap<number, Buffer[]>;
|
|
14
|
-
#log = createDebugLogger('aztec:archiver:contract_store');
|
|
15
|
-
|
|
16
|
-
constructor(private db: AztecKVStore, blockStore: BlockStore) {
|
|
17
|
-
this.#extendedContractData = db.openMap('archiver_extended_contract_data');
|
|
18
|
-
this.#blockStore = blockStore;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Add new extended contract data from an L2 block to the store's list.
|
|
23
|
-
* @param data - List of contracts' data to be added.
|
|
24
|
-
* @param blockNum - Number of the L2 block the contract data was deployed in.
|
|
25
|
-
* @returns True if the operation is successful.
|
|
26
|
-
*/
|
|
27
|
-
addExtendedContractData(data: ExtendedContractData[], blockNum: number): Promise<boolean> {
|
|
28
|
-
return this.#extendedContractData.swap(blockNum, (existingData = []) => {
|
|
29
|
-
existingData.push(...data.map(d => d.toBuffer()));
|
|
30
|
-
return existingData;
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Get the extended contract data for this contract.
|
|
36
|
-
* @param contractAddress - The contract data address.
|
|
37
|
-
* @returns The extended contract data or undefined if not found.
|
|
38
|
-
*/
|
|
39
|
-
getExtendedContractData(contractAddress: AztecAddress): ExtendedContractData | undefined {
|
|
40
|
-
const [blockNumber, _] = this.#blockStore.getContractLocation(contractAddress) ?? [];
|
|
41
|
-
|
|
42
|
-
if (typeof blockNumber !== 'number') {
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
for (const contract of this.#extendedContractData.get(blockNumber) ?? []) {
|
|
47
|
-
const extendedContractData = ExtendedContractData.fromBuffer(contract);
|
|
48
|
-
if (extendedContractData.contractData.contractAddress.equals(contractAddress)) {
|
|
49
|
-
return extendedContractData;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
}
|