@aztec/archiver 0.29.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/archiver/archiver.d.ts +2 -2
- package/dest/archiver/archiver.d.ts.map +1 -1
- package/dest/archiver/archiver.js +25 -26
- package/dest/archiver/archiver_store.d.ts +7 -7
- 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 +42 -39
- package/dest/archiver/config.d.ts.map +1 -1
- package/dest/archiver/config.js +6 -2
- package/dest/archiver/data_retrieval.d.ts +5 -6
- package/dest/archiver/data_retrieval.d.ts.map +1 -1
- package/dest/archiver/data_retrieval.js +5 -5
- package/dest/archiver/eth_log_handlers.d.ts +2 -2
- package/dest/archiver/eth_log_handlers.d.ts.map +1 -1
- package/dest/archiver/eth_log_handlers.js +3 -3
- package/dest/archiver/kv_archiver_store/block_store.d.ts +3 -2
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/block_store.js +10 -13
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +7 -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 +6 -7
- package/dest/archiver/kv_archiver_store/message_store.d.ts +5 -5
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/message_store.js +7 -11
- package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts +2 -2
- 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 +3 -3
- package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +9 -8
- package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +1 -1
- package/dest/archiver/memory_archiver_store/memory_archiver_store.js +15 -16
- package/package.json +9 -9
- package/src/archiver/archiver.ts +41 -45
- package/src/archiver/archiver_store.ts +8 -7
- package/src/archiver/archiver_store_test_suite.ts +60 -42
- package/src/archiver/config.ts +6 -0
- package/src/archiver/data_retrieval.ts +9 -9
- package/src/archiver/eth_log_handlers.ts +4 -4
- package/src/archiver/kv_archiver_store/block_store.ts +11 -12
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +8 -8
- package/src/archiver/kv_archiver_store/message_store.ts +9 -11
- package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +3 -3
- package/src/archiver/memory_archiver_store/memory_archiver_store.ts +17 -18
|
@@ -28,14 +28,14 @@ export function processLeafInsertedLogs(
|
|
|
28
28
|
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
29
29
|
* @param expectedL2BlockNumber - The next expected L2 block number.
|
|
30
30
|
* @param logs - L2BlockProcessed logs.
|
|
31
|
-
* @returns - An array of tuples representing block metadata including the header, archive tree snapshot
|
|
31
|
+
* @returns - An array of tuples representing block metadata including the header, archive tree snapshot.
|
|
32
32
|
*/
|
|
33
33
|
export async function processL2BlockProcessedLogs(
|
|
34
34
|
publicClient: PublicClient,
|
|
35
35
|
expectedL2BlockNumber: bigint,
|
|
36
36
|
logs: Log<bigint, number, false, undefined, true, typeof RollupAbi, 'L2BlockProcessed'>[],
|
|
37
|
-
): Promise<[Header, AppendOnlyTreeSnapshot
|
|
38
|
-
const retrievedBlockMetadata: [Header, AppendOnlyTreeSnapshot
|
|
37
|
+
): Promise<[Header, AppendOnlyTreeSnapshot][]> {
|
|
38
|
+
const retrievedBlockMetadata: [Header, AppendOnlyTreeSnapshot][] = [];
|
|
39
39
|
for (const log of logs) {
|
|
40
40
|
const blockNum = log.args.blockNumber;
|
|
41
41
|
if (blockNum !== expectedL2BlockNumber) {
|
|
@@ -48,7 +48,7 @@ export async function processL2BlockProcessedLogs(
|
|
|
48
48
|
log.args.blockNumber,
|
|
49
49
|
);
|
|
50
50
|
|
|
51
|
-
retrievedBlockMetadata.push([header, archive
|
|
51
|
+
retrievedBlockMetadata.push([header, archive]);
|
|
52
52
|
expectedL2BlockNumber++;
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { L2Block, TxEffect, TxHash, TxReceipt, TxStatus } from '@aztec/circuit-types';
|
|
2
2
|
import { AppendOnlyTreeSnapshot, AztecAddress, Header, INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js';
|
|
3
3
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
4
|
-
import { AztecKVStore, AztecMap, Range } from '@aztec/kv-store';
|
|
4
|
+
import { AztecKVStore, AztecMap, AztecSingleton, Range } from '@aztec/kv-store';
|
|
5
5
|
|
|
6
|
+
import { DataRetrieval } from '../data_retrieval.js';
|
|
6
7
|
import { BlockBodyStore } from './block_body_store.js';
|
|
7
8
|
|
|
8
9
|
type BlockIndexValue = [blockNumber: number, index: number];
|
|
9
10
|
|
|
10
11
|
type BlockStorage = {
|
|
11
|
-
l1BlockNumber: bigint;
|
|
12
12
|
header: Buffer;
|
|
13
13
|
archive: Buffer;
|
|
14
14
|
};
|
|
@@ -19,6 +19,8 @@ type BlockStorage = {
|
|
|
19
19
|
export class BlockStore {
|
|
20
20
|
/** Map block number to block data */
|
|
21
21
|
#blocks: AztecMap<number, BlockStorage>;
|
|
22
|
+
/** Stores L1 block number in which the last processed L2 block was included */
|
|
23
|
+
#lastSynchedL1Block: AztecSingleton<bigint>;
|
|
22
24
|
|
|
23
25
|
/** Index mapping transaction hash (as a string) to its location in a block */
|
|
24
26
|
#txIndex: AztecMap<string, BlockIndexValue>;
|
|
@@ -36,20 +38,20 @@ export class BlockStore {
|
|
|
36
38
|
this.#blocks = db.openMap('archiver_blocks');
|
|
37
39
|
this.#txIndex = db.openMap('archiver_tx_index');
|
|
38
40
|
this.#contractIndex = db.openMap('archiver_contract_index');
|
|
41
|
+
this.#lastSynchedL1Block = db.openSingleton('archiver_last_synched_l1_block');
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
/**
|
|
42
45
|
* Append new blocks to the store's list.
|
|
43
|
-
* @param blocks - The L2 blocks to be added to the store.
|
|
46
|
+
* @param blocks - The L2 blocks to be added to the store and the last processed L1 block.
|
|
44
47
|
* @returns True if the operation is successful.
|
|
45
48
|
*/
|
|
46
|
-
addBlocks(blocks: L2Block
|
|
49
|
+
addBlocks(blocks: DataRetrieval<L2Block>): Promise<boolean> {
|
|
47
50
|
return this.db.transaction(() => {
|
|
48
|
-
for (const block of blocks) {
|
|
51
|
+
for (const block of blocks.retrievedData) {
|
|
49
52
|
void this.#blocks.set(block.number, {
|
|
50
53
|
header: block.header.toBuffer(),
|
|
51
54
|
archive: block.archive.toBuffer(),
|
|
52
|
-
l1BlockNumber: block.getL1BlockNumber(),
|
|
53
55
|
});
|
|
54
56
|
|
|
55
57
|
block.getTxs().forEach((tx, i) => {
|
|
@@ -57,6 +59,8 @@ export class BlockStore {
|
|
|
57
59
|
});
|
|
58
60
|
}
|
|
59
61
|
|
|
62
|
+
void this.#lastSynchedL1Block.set(blocks.lastProcessedL1BlockNumber);
|
|
63
|
+
|
|
60
64
|
return true;
|
|
61
65
|
});
|
|
62
66
|
}
|
|
@@ -165,12 +169,7 @@ export class BlockStore {
|
|
|
165
169
|
* @returns The L1 block that published the latest L2 block
|
|
166
170
|
*/
|
|
167
171
|
getSynchedL1BlockNumber(): bigint {
|
|
168
|
-
|
|
169
|
-
if (!lastBlock) {
|
|
170
|
-
return 0n;
|
|
171
|
-
} else {
|
|
172
|
-
return lastBlock.l1BlockNumber;
|
|
173
|
-
}
|
|
172
|
+
return this.#lastSynchedL1Block.get() ?? 0n;
|
|
174
173
|
}
|
|
175
174
|
|
|
176
175
|
#computeBlockRange(start: number, limit: number): Required<Pick<Range<number>, 'start' | 'end'>> {
|
|
@@ -17,6 +17,7 @@ import { AztecKVStore } from '@aztec/kv-store';
|
|
|
17
17
|
import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts';
|
|
18
18
|
|
|
19
19
|
import { ArchiverDataStore, ArchiverL1SynchPoint } from '../archiver_store.js';
|
|
20
|
+
import { DataRetrieval } from '../data_retrieval.js';
|
|
20
21
|
import { BlockBodyStore } from './block_body_store.js';
|
|
21
22
|
import { BlockStore } from './block_store.js';
|
|
22
23
|
import { ContractClassStore } from './contract_class_store.js';
|
|
@@ -87,10 +88,10 @@ export class KVArchiverDataStore implements ArchiverDataStore {
|
|
|
87
88
|
|
|
88
89
|
/**
|
|
89
90
|
* Append new blocks to the store's list.
|
|
90
|
-
* @param blocks - The L2 blocks to be added to the store.
|
|
91
|
+
* @param blocks - The L2 blocks to be added to the store and the last processed L1 block.
|
|
91
92
|
* @returns True if the operation is successful.
|
|
92
93
|
*/
|
|
93
|
-
addBlocks(blocks: L2Block
|
|
94
|
+
addBlocks(blocks: DataRetrieval<L2Block>): Promise<boolean> {
|
|
94
95
|
return this.#blockStore.addBlocks(blocks);
|
|
95
96
|
}
|
|
96
97
|
|
|
@@ -145,20 +146,19 @@ export class KVArchiverDataStore implements ArchiverDataStore {
|
|
|
145
146
|
|
|
146
147
|
/**
|
|
147
148
|
* Append L1 to L2 messages to the store.
|
|
148
|
-
* @param messages - The L1 to L2 messages to be added to the store.
|
|
149
|
-
* @param lastMessageL1BlockNumber - The L1 block number in which the last message was emitted.
|
|
149
|
+
* @param messages - The L1 to L2 messages to be added to the store and the last processed L1 block.
|
|
150
150
|
* @returns True if the operation is successful.
|
|
151
151
|
*/
|
|
152
|
-
addL1ToL2Messages(messages: InboxLeaf
|
|
153
|
-
return Promise.resolve(this.#messageStore.addL1ToL2Messages(messages
|
|
152
|
+
addL1ToL2Messages(messages: DataRetrieval<InboxLeaf>): Promise<boolean> {
|
|
153
|
+
return Promise.resolve(this.#messageStore.addL1ToL2Messages(messages));
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
/**
|
|
157
157
|
* Gets the L1 to L2 message index in the L1 to L2 message tree.
|
|
158
158
|
* @param l1ToL2Message - The L1 to L2 message.
|
|
159
|
-
* @returns The index of the L1 to L2 message in the L1 to L2 message tree.
|
|
159
|
+
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
|
|
160
160
|
*/
|
|
161
|
-
public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint> {
|
|
161
|
+
public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined> {
|
|
162
162
|
return Promise.resolve(this.#messageStore.getL1ToL2MessageIndex(l1ToL2Message));
|
|
163
163
|
}
|
|
164
164
|
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
9
9
|
import { AztecKVStore, AztecMap, AztecSingleton } from '@aztec/kv-store';
|
|
10
10
|
|
|
11
|
+
import { DataRetrieval } from '../data_retrieval.js';
|
|
12
|
+
|
|
11
13
|
/**
|
|
12
14
|
* LMDB implementation of the ArchiverDataStore interface.
|
|
13
15
|
*/
|
|
@@ -36,20 +38,19 @@ export class MessageStore {
|
|
|
36
38
|
|
|
37
39
|
/**
|
|
38
40
|
* Append L1 to L2 messages to the store.
|
|
39
|
-
* @param messages - The L1 to L2 messages to be added to the store.
|
|
40
|
-
* @param lastMessageL1BlockNumber - The L1 block number in which the last message was emitted.
|
|
41
|
+
* @param messages - The L1 to L2 messages to be added to the store and the last processed L1 block.
|
|
41
42
|
* @returns True if the operation is successful.
|
|
42
43
|
*/
|
|
43
|
-
addL1ToL2Messages(messages: InboxLeaf
|
|
44
|
+
addL1ToL2Messages(messages: DataRetrieval<InboxLeaf>): Promise<boolean> {
|
|
44
45
|
return this.db.transaction(() => {
|
|
45
46
|
const lastL1BlockNumber = this.#lastL1BlockMessages.get() ?? 0n;
|
|
46
|
-
if (lastL1BlockNumber >=
|
|
47
|
+
if (lastL1BlockNumber >= messages.lastProcessedL1BlockNumber) {
|
|
47
48
|
return false;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
void this.#lastL1BlockMessages.set(
|
|
51
|
+
void this.#lastL1BlockMessages.set(messages.lastProcessedL1BlockNumber);
|
|
51
52
|
|
|
52
|
-
for (const message of messages) {
|
|
53
|
+
for (const message of messages.retrievedData) {
|
|
53
54
|
if (message.index >= this.#l1ToL2MessagesSubtreeSize) {
|
|
54
55
|
throw new Error(`Message index ${message.index} out of subtree range`);
|
|
55
56
|
}
|
|
@@ -69,13 +70,10 @@ export class MessageStore {
|
|
|
69
70
|
/**
|
|
70
71
|
* Gets the L1 to L2 message index in the L1 to L2 message tree.
|
|
71
72
|
* @param l1ToL2Message - The L1 to L2 message.
|
|
72
|
-
* @returns The index of the L1 to L2 message in the L1 to L2 message tree.
|
|
73
|
+
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
|
|
73
74
|
*/
|
|
74
|
-
public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint> {
|
|
75
|
+
public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined> {
|
|
75
76
|
const index = this.#l1ToL2MessageIndices.get(l1ToL2Message.toString());
|
|
76
|
-
if (index === undefined) {
|
|
77
|
-
throw new Error(`L1 to L2 message index not found in the store for message ${l1ToL2Message.toString()}`);
|
|
78
|
-
}
|
|
79
77
|
return Promise.resolve(index);
|
|
80
78
|
}
|
|
81
79
|
|
|
@@ -52,9 +52,9 @@ export class L1ToL2MessageStore {
|
|
|
52
52
|
/**
|
|
53
53
|
* Gets the L1 to L2 message index in the L1 to L2 message tree.
|
|
54
54
|
* @param l1ToL2Message - The L1 to L2 message.
|
|
55
|
-
* @returns The index of the L1 to L2 message in the L1 to L2 message tree.
|
|
55
|
+
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
|
|
56
56
|
*/
|
|
57
|
-
getMessageIndex(l1ToL2Message: Fr): bigint {
|
|
57
|
+
getMessageIndex(l1ToL2Message: Fr): bigint | undefined {
|
|
58
58
|
for (const [key, message] of this.store.entries()) {
|
|
59
59
|
if (message.equals(l1ToL2Message)) {
|
|
60
60
|
const [blockNumber, messageIndex] = key.split('-');
|
|
@@ -64,6 +64,6 @@ export class L1ToL2MessageStore {
|
|
|
64
64
|
return indexInTheWholeTree;
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
|
|
67
|
+
return undefined;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -20,6 +20,7 @@ import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
|
20
20
|
import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts';
|
|
21
21
|
|
|
22
22
|
import { ArchiverDataStore, ArchiverL1SynchPoint } from '../archiver_store.js';
|
|
23
|
+
import { DataRetrieval } from '../data_retrieval.js';
|
|
23
24
|
import { L1ToL2MessageStore } from './l1_to_l2_message_store.js';
|
|
24
25
|
|
|
25
26
|
/**
|
|
@@ -62,6 +63,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
62
63
|
|
|
63
64
|
private contractInstances: Map<string, ContractInstanceWithAddress> = new Map();
|
|
64
65
|
|
|
66
|
+
private lastL1BlockNewBlocks: bigint = 0n;
|
|
65
67
|
private lastL1BlockNewMessages: bigint = 0n;
|
|
66
68
|
|
|
67
69
|
constructor(
|
|
@@ -97,12 +99,13 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
97
99
|
|
|
98
100
|
/**
|
|
99
101
|
* Append new blocks to the store's list.
|
|
100
|
-
* @param blocks - The L2 blocks to be added to the store.
|
|
101
|
-
* @returns True if the operation is successful
|
|
102
|
+
* @param blocks - The L2 blocks to be added to the store and the last processed L1 block.
|
|
103
|
+
* @returns True if the operation is successful.
|
|
102
104
|
*/
|
|
103
|
-
public addBlocks(blocks: L2Block
|
|
104
|
-
this.
|
|
105
|
-
this.
|
|
105
|
+
public addBlocks(blocks: DataRetrieval<L2Block>): Promise<boolean> {
|
|
106
|
+
this.lastL1BlockNewBlocks = blocks.lastProcessedL1BlockNumber;
|
|
107
|
+
this.l2BlockContexts.push(...blocks.retrievedData.map(block => new L2BlockContext(block)));
|
|
108
|
+
this.txEffects.push(...blocks.retrievedData.flatMap(b => b.getTxs()));
|
|
106
109
|
return Promise.resolve(true);
|
|
107
110
|
}
|
|
108
111
|
|
|
@@ -156,17 +159,16 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
156
159
|
|
|
157
160
|
/**
|
|
158
161
|
* Append L1 to L2 messages to the store.
|
|
159
|
-
* @param messages - The L1 to L2 messages to be added to the store.
|
|
160
|
-
* @param lastMessageL1BlockNumber - The L1 block number in which the last message was emitted.
|
|
162
|
+
* @param messages - The L1 to L2 messages to be added to the store and the last processed L1 block.
|
|
161
163
|
* @returns True if the operation is successful.
|
|
162
164
|
*/
|
|
163
|
-
public addL1ToL2Messages(messages: InboxLeaf
|
|
164
|
-
if (
|
|
165
|
+
public addL1ToL2Messages(messages: DataRetrieval<InboxLeaf>): Promise<boolean> {
|
|
166
|
+
if (messages.lastProcessedL1BlockNumber <= this.lastL1BlockNewMessages) {
|
|
165
167
|
return Promise.resolve(false);
|
|
166
168
|
}
|
|
167
169
|
|
|
168
|
-
this.lastL1BlockNewMessages =
|
|
169
|
-
for (const message of messages) {
|
|
170
|
+
this.lastL1BlockNewMessages = messages.lastProcessedL1BlockNumber;
|
|
171
|
+
for (const message of messages.retrievedData) {
|
|
170
172
|
this.l1ToL2Messages.addMessage(message);
|
|
171
173
|
}
|
|
172
174
|
return Promise.resolve(true);
|
|
@@ -175,9 +177,9 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
175
177
|
/**
|
|
176
178
|
* Gets the L1 to L2 message index in the L1 to L2 message tree.
|
|
177
179
|
* @param l1ToL2Message - The L1 to L2 message.
|
|
178
|
-
* @returns The index of the L1 to L2 message in the L1 to L2 message tree.
|
|
180
|
+
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
|
|
179
181
|
*/
|
|
180
|
-
public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint> {
|
|
182
|
+
public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined> {
|
|
181
183
|
return Promise.resolve(this.l1ToL2Messages.getMessageIndex(l1ToL2Message));
|
|
182
184
|
}
|
|
183
185
|
|
|
@@ -356,12 +358,9 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
356
358
|
}
|
|
357
359
|
|
|
358
360
|
public getSynchedL1BlockNumbers(): Promise<ArchiverL1SynchPoint> {
|
|
359
|
-
const blocks = this.l2BlockContexts[this.l2BlockContexts.length - 1]?.block?.getL1BlockNumber() ?? 0n;
|
|
360
|
-
const messages = this.lastL1BlockNewMessages;
|
|
361
|
-
|
|
362
361
|
return Promise.resolve({
|
|
363
|
-
blocks,
|
|
364
|
-
messages,
|
|
362
|
+
blocks: this.lastL1BlockNewBlocks,
|
|
363
|
+
messages: this.lastL1BlockNewMessages,
|
|
365
364
|
});
|
|
366
365
|
}
|
|
367
366
|
}
|