@aztec/archiver 0.72.1 → 0.74.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 +2 -2
- package/dest/archiver/archiver.d.ts.map +1 -1
- package/dest/archiver/archiver.js +31 -16
- package/dest/archiver/archiver_store.d.ts +2 -2
- package/dest/archiver/archiver_store.d.ts.map +1 -1
- package/dest/archiver/archiver_store_test_suite.d.ts +1 -1
- package/dest/archiver/archiver_store_test_suite.d.ts.map +1 -1
- package/dest/archiver/archiver_store_test_suite.js +14 -14
- package/dest/archiver/config.d.ts +1 -1
- package/dest/archiver/config.d.ts.map +1 -1
- package/dest/archiver/config.js +4 -4
- package/dest/archiver/data_retrieval.d.ts +3 -2
- package/dest/archiver/data_retrieval.d.ts.map +1 -1
- package/dest/archiver/data_retrieval.js +83 -16
- package/dest/archiver/errors.d.ts +4 -0
- package/dest/archiver/errors.d.ts.map +1 -0
- package/dest/archiver/errors.js +6 -0
- package/dest/archiver/kv_archiver_store/block_store.d.ts +16 -16
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/block_store.js +53 -53
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +5 -5
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/contract_class_store.js +13 -12
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +3 -3
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.js +3 -3
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +3 -7
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +39 -61
- package/dest/archiver/kv_archiver_store/log_store.d.ts +5 -5
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/log_store.js +54 -53
- package/dest/archiver/kv_archiver_store/message_store.d.ts +6 -6
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/message_store.js +16 -16
- package/dest/archiver/kv_archiver_store/nullifier_store.d.ts +2 -2
- package/dest/archiver/kv_archiver_store/nullifier_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/nullifier_store.js +31 -22
- package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +2 -2
- package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +1 -1
- package/dest/archiver/memory_archiver_store/memory_archiver_store.js +24 -22
- package/dest/factory.js +7 -7
- package/dest/test/mock_l2_block_source.d.ts +2 -2
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +12 -9
- package/package.json +12 -12
- package/src/archiver/archiver.ts +38 -18
- package/src/archiver/archiver_store.ts +1 -1
- package/src/archiver/archiver_store_test_suite.ts +17 -14
- package/src/archiver/config.ts +4 -4
- package/src/archiver/data_retrieval.ts +108 -12
- package/src/archiver/errors.ts +5 -0
- package/src/archiver/kv_archiver_store/block_store.ts +66 -67
- package/src/archiver/kv_archiver_store/contract_class_store.ts +17 -15
- package/src/archiver/kv_archiver_store/contract_instance_store.ts +5 -5
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +43 -62
- package/src/archiver/kv_archiver_store/log_store.ts +79 -71
- package/src/archiver/kv_archiver_store/message_store.ts +22 -22
- package/src/archiver/kv_archiver_store/nullifier_store.ts +48 -30
- package/src/archiver/memory_archiver_store/memory_archiver_store.ts +44 -43
- package/src/factory.ts +10 -8
- package/src/test/mock_l2_block_source.ts +18 -16
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { InboxLeaf } from '@aztec/circuit-types';
|
|
2
2
|
import { Fr, L1_TO_L2_MSG_SUBTREE_HEIGHT } from '@aztec/circuits.js';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import {
|
|
4
|
+
import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncSingleton } from '@aztec/kv-store';
|
|
5
5
|
|
|
6
6
|
import { type DataRetrieval } from '../structs/data_retrieval.js';
|
|
7
7
|
|
|
@@ -9,36 +9,36 @@ import { type DataRetrieval } from '../structs/data_retrieval.js';
|
|
|
9
9
|
* LMDB implementation of the ArchiverDataStore interface.
|
|
10
10
|
*/
|
|
11
11
|
export class MessageStore {
|
|
12
|
-
#l1ToL2Messages:
|
|
13
|
-
#l1ToL2MessageIndices:
|
|
14
|
-
#lastSynchedL1Block:
|
|
15
|
-
#totalMessageCount:
|
|
12
|
+
#l1ToL2Messages: AztecAsyncMap<string, Buffer>;
|
|
13
|
+
#l1ToL2MessageIndices: AztecAsyncMap<string, bigint>;
|
|
14
|
+
#lastSynchedL1Block: AztecAsyncSingleton<bigint>;
|
|
15
|
+
#totalMessageCount: AztecAsyncSingleton<bigint>;
|
|
16
16
|
|
|
17
17
|
#log = createLogger('archiver:message_store');
|
|
18
18
|
|
|
19
19
|
#l1ToL2MessagesSubtreeSize = 2 ** L1_TO_L2_MSG_SUBTREE_HEIGHT;
|
|
20
20
|
|
|
21
|
-
constructor(private db:
|
|
21
|
+
constructor(private db: AztecAsyncKVStore) {
|
|
22
22
|
this.#l1ToL2Messages = db.openMap('archiver_l1_to_l2_messages');
|
|
23
23
|
this.#l1ToL2MessageIndices = db.openMap('archiver_l1_to_l2_message_indices');
|
|
24
24
|
this.#lastSynchedL1Block = db.openSingleton('archiver_last_l1_block_new_messages');
|
|
25
25
|
this.#totalMessageCount = db.openSingleton('archiver_l1_to_l2_message_count');
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
getTotalL1ToL2MessageCount(): bigint {
|
|
29
|
-
return this.#totalMessageCount.
|
|
28
|
+
async getTotalL1ToL2MessageCount(): Promise<bigint> {
|
|
29
|
+
return (await this.#totalMessageCount.getAsync()) ?? 0n;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Gets the last L1 block number that emitted new messages.
|
|
34
34
|
* @returns The last L1 block number processed
|
|
35
35
|
*/
|
|
36
|
-
getSynchedL1BlockNumber(): bigint | undefined {
|
|
37
|
-
return this.#lastSynchedL1Block.
|
|
36
|
+
getSynchedL1BlockNumber(): Promise<bigint | undefined> {
|
|
37
|
+
return this.#lastSynchedL1Block.getAsync();
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
setSynchedL1BlockNumber(l1BlockNumber: bigint) {
|
|
41
|
-
|
|
40
|
+
async setSynchedL1BlockNumber(l1BlockNumber: bigint): Promise<void> {
|
|
41
|
+
await this.#lastSynchedL1Block.set(l1BlockNumber);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
@@ -47,22 +47,22 @@ export class MessageStore {
|
|
|
47
47
|
* @returns True if the operation is successful.
|
|
48
48
|
*/
|
|
49
49
|
addL1ToL2Messages(messages: DataRetrieval<InboxLeaf>): Promise<boolean> {
|
|
50
|
-
return this.db.
|
|
51
|
-
const lastL1BlockNumber = this.#lastSynchedL1Block.
|
|
50
|
+
return this.db.transactionAsync(async () => {
|
|
51
|
+
const lastL1BlockNumber = (await this.#lastSynchedL1Block.getAsync()) ?? 0n;
|
|
52
52
|
if (lastL1BlockNumber >= messages.lastProcessedL1BlockNumber) {
|
|
53
53
|
return false;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
await this.#lastSynchedL1Block.set(messages.lastProcessedL1BlockNumber);
|
|
57
57
|
|
|
58
58
|
for (const message of messages.retrievedData) {
|
|
59
59
|
const key = `${message.index}`;
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
await this.#l1ToL2Messages.set(key, message.leaf.toBuffer());
|
|
61
|
+
await this.#l1ToL2MessageIndices.set(message.leaf.toString(), message.index);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
const lastTotalMessageCount = this.getTotalL1ToL2MessageCount();
|
|
65
|
-
|
|
64
|
+
const lastTotalMessageCount = await this.getTotalL1ToL2MessageCount();
|
|
65
|
+
await this.#totalMessageCount.set(lastTotalMessageCount + BigInt(messages.retrievedData.length));
|
|
66
66
|
|
|
67
67
|
return true;
|
|
68
68
|
});
|
|
@@ -74,17 +74,17 @@ export class MessageStore {
|
|
|
74
74
|
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
|
|
75
75
|
*/
|
|
76
76
|
getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined> {
|
|
77
|
-
return
|
|
77
|
+
return this.#l1ToL2MessageIndices.getAsync(l1ToL2Message.toString());
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
getL1ToL2Messages(blockNumber: bigint): Fr[] {
|
|
80
|
+
async getL1ToL2Messages(blockNumber: bigint): Promise<Fr[]> {
|
|
81
81
|
const messages: Fr[] = [];
|
|
82
82
|
let undefinedMessageFound = false;
|
|
83
83
|
const startIndex = Number(InboxLeaf.smallestIndexFromL2Block(blockNumber));
|
|
84
84
|
for (let i = startIndex; i < startIndex + this.#l1ToL2MessagesSubtreeSize; i++) {
|
|
85
85
|
// This is inefficient but probably fine for now.
|
|
86
86
|
const key = `${i}`;
|
|
87
|
-
const message = this.#l1ToL2Messages.
|
|
87
|
+
const message = await this.#l1ToL2Messages.getAsync(key);
|
|
88
88
|
if (message) {
|
|
89
89
|
if (undefinedMessageFound) {
|
|
90
90
|
throw new Error(`L1 to L2 message gap found in block ${blockNumber}`);
|
|
@@ -1,46 +1,55 @@
|
|
|
1
1
|
import { type InBlock, type L2Block } from '@aztec/circuit-types';
|
|
2
2
|
import { type Fr, MAX_NULLIFIERS_PER_TX } from '@aztec/circuits.js';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import {
|
|
4
|
+
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
5
5
|
|
|
6
6
|
export class NullifierStore {
|
|
7
|
-
#nullifiersToBlockNumber:
|
|
8
|
-
#nullifiersToBlockHash:
|
|
9
|
-
#nullifiersToIndex:
|
|
7
|
+
#nullifiersToBlockNumber: AztecAsyncMap<string, number>;
|
|
8
|
+
#nullifiersToBlockHash: AztecAsyncMap<string, string>;
|
|
9
|
+
#nullifiersToIndex: AztecAsyncMap<string, number>;
|
|
10
10
|
#log = createLogger('archiver:log_store');
|
|
11
11
|
|
|
12
|
-
constructor(private db:
|
|
12
|
+
constructor(private db: AztecAsyncKVStore) {
|
|
13
13
|
this.#nullifiersToBlockNumber = db.openMap('archiver_nullifiers_to_block_number');
|
|
14
14
|
this.#nullifiersToBlockHash = db.openMap('archiver_nullifiers_to_block_hash');
|
|
15
15
|
this.#nullifiersToIndex = db.openMap('archiver_nullifiers_to_index');
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
async addNullifiers(blocks: L2Block[]): Promise<boolean> {
|
|
19
|
-
await
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
19
|
+
const blockHashes = await Promise.all(blocks.map(block => block.hash()));
|
|
20
|
+
await this.db.transactionAsync(async () => {
|
|
21
|
+
await Promise.all(
|
|
22
|
+
blocks.map((block, i) => {
|
|
23
|
+
const dataStartIndexForBlock =
|
|
24
|
+
block.header.state.partial.nullifierTree.nextAvailableLeafIndex -
|
|
25
|
+
block.body.txEffects.length * MAX_NULLIFIERS_PER_TX;
|
|
26
|
+
return Promise.all(
|
|
27
|
+
block.body.txEffects.map((txEffects, txIndex) => {
|
|
28
|
+
const dataStartIndexForTx = dataStartIndexForBlock + txIndex * MAX_NULLIFIERS_PER_TX;
|
|
29
|
+
return Promise.all(
|
|
30
|
+
txEffects.nullifiers.map(async (nullifier, nullifierIndex) => {
|
|
31
|
+
await this.#nullifiersToBlockNumber.set(nullifier.toString(), block.number);
|
|
32
|
+
await this.#nullifiersToBlockHash.set(nullifier.toString(), blockHashes[i].toString());
|
|
33
|
+
await this.#nullifiersToIndex.set(nullifier.toString(), dataStartIndexForTx + nullifierIndex);
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
}),
|
|
39
|
+
);
|
|
33
40
|
});
|
|
34
41
|
return true;
|
|
35
42
|
}
|
|
36
43
|
|
|
37
44
|
async deleteNullifiers(blocks: L2Block[]): Promise<boolean> {
|
|
38
|
-
await this.db.
|
|
45
|
+
await this.db.transactionAsync(async () => {
|
|
39
46
|
for (const block of blocks) {
|
|
40
47
|
for (const nullifier of block.body.txEffects.flatMap(tx => tx.nullifiers)) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
await Promise.all([
|
|
49
|
+
this.#nullifiersToBlockNumber.delete(nullifier.toString()),
|
|
50
|
+
this.#nullifiersToBlockHash.delete(nullifier.toString()),
|
|
51
|
+
this.#nullifiersToIndex.delete(nullifier.toString()),
|
|
52
|
+
]);
|
|
44
53
|
}
|
|
45
54
|
}
|
|
46
55
|
});
|
|
@@ -51,13 +60,22 @@ export class NullifierStore {
|
|
|
51
60
|
blockNumber: number,
|
|
52
61
|
nullifiers: Fr[],
|
|
53
62
|
): Promise<(InBlock<bigint> | undefined)[]> {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
l2BlockHash
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
const asStrings = nullifiers.map(x => x.toString());
|
|
64
|
+
|
|
65
|
+
const maybeNullifiers = await Promise.all(
|
|
66
|
+
asStrings.map(async nullifier => {
|
|
67
|
+
const [data, l2BlockNumber, l2BlockHash] = await Promise.all([
|
|
68
|
+
this.#nullifiersToIndex.getAsync(nullifier),
|
|
69
|
+
this.#nullifiersToBlockNumber.getAsync(nullifier),
|
|
70
|
+
this.#nullifiersToBlockHash.getAsync(nullifier),
|
|
71
|
+
]);
|
|
72
|
+
return {
|
|
73
|
+
data,
|
|
74
|
+
l2BlockNumber,
|
|
75
|
+
l2BlockHash,
|
|
76
|
+
};
|
|
77
|
+
}),
|
|
78
|
+
);
|
|
61
79
|
return maybeNullifiers.map(({ data, l2BlockNumber, l2BlockHash }) => {
|
|
62
80
|
if (
|
|
63
81
|
data === undefined ||
|
|
@@ -191,14 +191,18 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
191
191
|
* @param blocks - The L2 blocks to be added to the store and the last processed L1 block.
|
|
192
192
|
* @returns True if the operation is successful.
|
|
193
193
|
*/
|
|
194
|
-
public addBlocks(blocks: L1Published<L2Block>[]): Promise<boolean> {
|
|
194
|
+
public async addBlocks(blocks: L1Published<L2Block>[]): Promise<boolean> {
|
|
195
195
|
if (blocks.length === 0) {
|
|
196
196
|
return Promise.resolve(true);
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
this.lastL1BlockNewBlocks = blocks[blocks.length - 1].l1.blockNumber;
|
|
200
200
|
this.l2Blocks.push(...blocks);
|
|
201
|
-
|
|
201
|
+
const flatTxEffects = blocks.flatMap(b => b.data.body.txEffects.map(txEffect => ({ block: b, txEffect })));
|
|
202
|
+
const wrappedTxEffects = await Promise.all(
|
|
203
|
+
flatTxEffects.map(flatTxEffect => wrapInBlock(flatTxEffect.txEffect, flatTxEffect.block.data)),
|
|
204
|
+
);
|
|
205
|
+
this.txEffects.push(...wrappedTxEffects);
|
|
202
206
|
|
|
203
207
|
return Promise.resolve(true);
|
|
204
208
|
}
|
|
@@ -257,20 +261,18 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
257
261
|
const dataStartIndexForTx = dataStartIndexForBlock + txIndex * MAX_NOTE_HASHES_PER_TX;
|
|
258
262
|
txEffect.publicLogs.forEach(log => {
|
|
259
263
|
// Check that each log stores 3 lengths in its first field. If not, it's not a tagged log:
|
|
264
|
+
// See macros/note/mod/ and see how finalization_log[0] is constructed, to understand this monstrosity. (It wasn't me).
|
|
265
|
+
// Search the codebase for "disgusting encoding" to see other hardcoded instances of this encoding, that you might need to change if you ever find yourself here.
|
|
260
266
|
const firstFieldBuf = log.log[0].toBuffer();
|
|
261
|
-
if (
|
|
262
|
-
!firstFieldBuf.subarray(0, 24).equals(Buffer.alloc(24)) ||
|
|
263
|
-
firstFieldBuf[26] !== 0 ||
|
|
264
|
-
firstFieldBuf[29] !== 0
|
|
265
|
-
) {
|
|
267
|
+
if (!firstFieldBuf.subarray(0, 27).equals(Buffer.alloc(27)) || firstFieldBuf[29] !== 0) {
|
|
266
268
|
// See parseLogFromPublic - the first field of a tagged log is 8 bytes structured:
|
|
267
|
-
// [ publicLen[0], publicLen[1], 0, privateLen[0], privateLen[1]
|
|
269
|
+
// [ publicLen[0], publicLen[1], 0, privateLen[0], privateLen[1]]
|
|
268
270
|
this.#log.warn(`Skipping public log with invalid first field: ${log.log[0]}`);
|
|
269
271
|
return;
|
|
270
272
|
}
|
|
271
273
|
// Check that the length values line up with the log contents
|
|
272
|
-
const publicValuesLength = firstFieldBuf.subarray(-
|
|
273
|
-
const privateValuesLength = firstFieldBuf.subarray(-
|
|
274
|
+
const publicValuesLength = firstFieldBuf.subarray(-5).readUint16BE();
|
|
275
|
+
const privateValuesLength = firstFieldBuf.subarray(-5).readUint16BE(3);
|
|
274
276
|
// Add 1 for the first field holding lengths
|
|
275
277
|
const totalLogLength = 1 + publicValuesLength + privateValuesLength;
|
|
276
278
|
// Note that zeroes can be valid log values, so we can only assert that we do not go over the given length
|
|
@@ -300,8 +302,8 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
300
302
|
*/
|
|
301
303
|
addLogs(blocks: L2Block[]): Promise<boolean> {
|
|
302
304
|
blocks.forEach(block => {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
+
this.#storeTaggedLogsFromPrivate(block);
|
|
306
|
+
this.#storeTaggedLogsFromPublic(block);
|
|
305
307
|
this.privateLogsPerBlock.set(block.number, block.body.txEffects.map(txEffect => txEffect.privateLogs).flat());
|
|
306
308
|
this.publicLogsPerBlock.set(block.number, block.body.txEffects.map(txEffect => txEffect.publicLogs).flat());
|
|
307
309
|
this.contractClassLogsPerBlock.set(block.number, block.body.contractClassLogs);
|
|
@@ -327,22 +329,25 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
327
329
|
return Promise.resolve(true);
|
|
328
330
|
}
|
|
329
331
|
|
|
330
|
-
addNullifiers(blocks: L2Block[]): Promise<boolean> {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
const
|
|
337
|
-
txEffects.
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
332
|
+
async addNullifiers(blocks: L2Block[]): Promise<boolean> {
|
|
333
|
+
await Promise.all(
|
|
334
|
+
blocks.map(async block => {
|
|
335
|
+
const dataStartIndexForBlock =
|
|
336
|
+
block.header.state.partial.nullifierTree.nextAvailableLeafIndex -
|
|
337
|
+
block.body.txEffects.length * MAX_NULLIFIERS_PER_TX;
|
|
338
|
+
const blockHash = await block.hash();
|
|
339
|
+
block.body.txEffects.forEach((txEffects, txIndex) => {
|
|
340
|
+
const dataStartIndexForTx = dataStartIndexForBlock + txIndex * MAX_NULLIFIERS_PER_TX;
|
|
341
|
+
txEffects.nullifiers.forEach((nullifier, nullifierIndex) => {
|
|
342
|
+
this.blockScopedNullifiers.set(nullifier.toString(), {
|
|
343
|
+
index: BigInt(dataStartIndexForTx + nullifierIndex),
|
|
344
|
+
blockNumber: block.number,
|
|
345
|
+
blockHash: blockHash.toString(),
|
|
346
|
+
});
|
|
342
347
|
});
|
|
343
348
|
});
|
|
344
|
-
})
|
|
345
|
-
|
|
349
|
+
}),
|
|
350
|
+
);
|
|
346
351
|
return Promise.resolve(true);
|
|
347
352
|
}
|
|
348
353
|
|
|
@@ -450,24 +455,22 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
450
455
|
* @param txHash - The hash of a tx we try to get the receipt for.
|
|
451
456
|
* @returns The requested tx receipt (or undefined if not found).
|
|
452
457
|
*/
|
|
453
|
-
public getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
|
|
458
|
+
public async getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
|
|
454
459
|
for (const block of this.l2Blocks) {
|
|
455
460
|
for (const txEffect of block.data.body.txEffects) {
|
|
456
461
|
if (txEffect.txHash.equals(txHash)) {
|
|
457
|
-
return
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
block.data.number,
|
|
465
|
-
),
|
|
462
|
+
return new TxReceipt(
|
|
463
|
+
txHash,
|
|
464
|
+
TxReceipt.statusFromRevertCode(txEffect.revertCode),
|
|
465
|
+
'',
|
|
466
|
+
txEffect.transactionFee.toBigInt(),
|
|
467
|
+
L2BlockHash.fromField(await block.data.hash()),
|
|
468
|
+
block.data.number,
|
|
466
469
|
);
|
|
467
470
|
}
|
|
468
471
|
}
|
|
469
472
|
}
|
|
470
|
-
return
|
|
473
|
+
return undefined;
|
|
471
474
|
}
|
|
472
475
|
|
|
473
476
|
/**
|
|
@@ -737,20 +740,18 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
737
740
|
return Promise.resolve(this.functionNames.get(selector.toString()));
|
|
738
741
|
}
|
|
739
742
|
|
|
740
|
-
public registerContractFunctionSignatures(_address: AztecAddress, signatures: string[]): Promise<void> {
|
|
743
|
+
public async registerContractFunctionSignatures(_address: AztecAddress, signatures: string[]): Promise<void> {
|
|
741
744
|
for (const sig of signatures) {
|
|
742
745
|
try {
|
|
743
|
-
const selector = FunctionSelector.fromSignature(sig);
|
|
746
|
+
const selector = await FunctionSelector.fromSignature(sig);
|
|
744
747
|
this.functionNames.set(selector.toString(), sig.slice(0, sig.indexOf('(')));
|
|
745
748
|
} catch {
|
|
746
749
|
this.#log.warn(`Failed to parse signature: ${sig}. Ignoring`);
|
|
747
750
|
}
|
|
748
751
|
}
|
|
749
|
-
|
|
750
|
-
return Promise.resolve();
|
|
751
752
|
}
|
|
752
753
|
|
|
753
|
-
public estimateSize(): { mappingSize: number; actualSize: number; numItems: number } {
|
|
754
|
-
return { mappingSize: 0, actualSize: 0, numItems: 0 };
|
|
754
|
+
public estimateSize(): Promise<{ mappingSize: number; actualSize: number; numItems: number }> {
|
|
755
|
+
return Promise.resolve({ mappingSize: 0, actualSize: 0, numItems: 0 });
|
|
755
756
|
}
|
|
756
757
|
}
|
package/src/factory.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { FunctionType, decodeFunctionSignature } from '@aztec/foundation/abi';
|
|
|
9
9
|
import { createLogger } from '@aztec/foundation/log';
|
|
10
10
|
import { type Maybe } from '@aztec/foundation/types';
|
|
11
11
|
import { type DataStoreConfig } from '@aztec/kv-store/config';
|
|
12
|
-
import { createStore } from '@aztec/kv-store/lmdb';
|
|
12
|
+
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
13
13
|
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
|
|
14
14
|
import { TokenBridgeContractArtifact } from '@aztec/noir-contracts.js/TokenBridge';
|
|
15
15
|
import { protocolContractNames } from '@aztec/protocol-contracts';
|
|
@@ -53,7 +53,7 @@ async function registerProtocolContracts(store: KVArchiverDataStore) {
|
|
|
53
53
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
54
54
|
|
|
55
55
|
await store.registerContractFunctionSignatures(contract.address, publicFunctionSignatures);
|
|
56
|
-
const bytecodeCommitment = computePublicBytecodeCommitment(contractClassPublic.packedBytecode);
|
|
56
|
+
const bytecodeCommitment = await computePublicBytecodeCommitment(contractClassPublic.packedBytecode);
|
|
57
57
|
await store.addContractClasses([contractClassPublic], [bytecodeCommitment], blockNumber);
|
|
58
58
|
await store.addContractInstances([contract.instance], blockNumber);
|
|
59
59
|
}
|
|
@@ -67,11 +67,13 @@ async function registerProtocolContracts(store: KVArchiverDataStore) {
|
|
|
67
67
|
async function registerCommonContracts(store: KVArchiverDataStore) {
|
|
68
68
|
const blockNumber = 0;
|
|
69
69
|
const artifacts = [TokenBridgeContractArtifact, TokenContractArtifact];
|
|
70
|
-
const classes =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
const classes = await Promise.all(
|
|
71
|
+
artifacts.map(async artifact => ({
|
|
72
|
+
...(await getContractClassFromArtifact(artifact)),
|
|
73
|
+
privateFunctions: [],
|
|
74
|
+
unconstrainedFunctions: [],
|
|
75
|
+
})),
|
|
76
|
+
);
|
|
77
|
+
const bytecodeCommitments = await Promise.all(classes.map(x => computePublicBytecodeCommitment(x.packedBytecode)));
|
|
76
78
|
await store.addContractClasses(classes, bytecodeCommitments, blockNumber);
|
|
77
79
|
}
|
|
@@ -126,7 +126,7 @@ export class MockL2BlockSource implements L2BlockSource {
|
|
|
126
126
|
* @param txHash - The hash of a transaction which resulted in the returned tx effect.
|
|
127
127
|
* @returns The requested tx effect.
|
|
128
128
|
*/
|
|
129
|
-
public getTxEffect(txHash: TxHash) {
|
|
129
|
+
public async getTxEffect(txHash: TxHash) {
|
|
130
130
|
const match = this.l2Blocks
|
|
131
131
|
.flatMap(b => b.body.txEffects.map(tx => [tx, b] as const))
|
|
132
132
|
.find(([tx]) => tx.txHash.equals(txHash));
|
|
@@ -134,7 +134,7 @@ export class MockL2BlockSource implements L2BlockSource {
|
|
|
134
134
|
return Promise.resolve(undefined);
|
|
135
135
|
}
|
|
136
136
|
const [txEffect, block] = match;
|
|
137
|
-
return
|
|
137
|
+
return { data: txEffect, l2BlockNumber: block.number, l2BlockHash: (await block.hash()).toString() };
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
/**
|
|
@@ -142,24 +142,22 @@ export class MockL2BlockSource implements L2BlockSource {
|
|
|
142
142
|
* @param txHash - The hash of a tx we try to get the receipt for.
|
|
143
143
|
* @returns The requested tx receipt (or undefined if not found).
|
|
144
144
|
*/
|
|
145
|
-
public getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
|
|
145
|
+
public async getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
|
|
146
146
|
for (const block of this.l2Blocks) {
|
|
147
147
|
for (const txEffect of block.body.txEffects) {
|
|
148
148
|
if (txEffect.txHash.equals(txHash)) {
|
|
149
|
-
return
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
block.number,
|
|
157
|
-
),
|
|
149
|
+
return new TxReceipt(
|
|
150
|
+
txHash,
|
|
151
|
+
TxStatus.SUCCESS,
|
|
152
|
+
'',
|
|
153
|
+
txEffect.transactionFee.toBigInt(),
|
|
154
|
+
L2BlockHash.fromField(await block.hash()),
|
|
155
|
+
block.number,
|
|
158
156
|
);
|
|
159
157
|
}
|
|
160
158
|
}
|
|
161
159
|
}
|
|
162
|
-
return
|
|
160
|
+
return undefined;
|
|
163
161
|
}
|
|
164
162
|
|
|
165
163
|
async getL2Tips(): Promise<L2Tips> {
|
|
@@ -169,10 +167,14 @@ export class MockL2BlockSource implements L2BlockSource {
|
|
|
169
167
|
await this.getProvenBlockNumber(),
|
|
170
168
|
] as const;
|
|
171
169
|
|
|
170
|
+
const latestBlock = this.l2Blocks[latest - 1];
|
|
171
|
+
const provenBlock = this.l2Blocks[proven - 1];
|
|
172
|
+
const finalizedBlock = this.l2Blocks[finalized - 1];
|
|
173
|
+
|
|
172
174
|
return {
|
|
173
|
-
latest: { number: latest, hash:
|
|
174
|
-
proven: { number: proven, hash:
|
|
175
|
-
finalized: { number: finalized, hash:
|
|
175
|
+
latest: { number: latest, hash: (await latestBlock?.hash())?.toString() },
|
|
176
|
+
proven: { number: proven, hash: (await provenBlock?.hash())?.toString() },
|
|
177
|
+
finalized: { number: finalized, hash: (await finalizedBlock?.hash())?.toString() },
|
|
176
178
|
};
|
|
177
179
|
}
|
|
178
180
|
|