@aztec/archiver 0.86.0 → 0.87.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 +62 -5
- package/dest/archiver/archiver.d.ts.map +1 -1
- package/dest/archiver/archiver.js +362 -91
- package/dest/archiver/archiver_store.d.ts +33 -17
- 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 +364 -62
- package/dest/archiver/data_retrieval.d.ts +23 -14
- package/dest/archiver/data_retrieval.d.ts.map +1 -1
- package/dest/archiver/data_retrieval.js +86 -38
- package/dest/archiver/errors.d.ts +8 -0
- package/dest/archiver/errors.d.ts.map +1 -1
- package/dest/archiver/errors.js +12 -0
- package/dest/archiver/instrumentation.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/block_store.d.ts +4 -1
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/block_store.js +43 -6
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +3 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.js +17 -3
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +24 -14
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +37 -11
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/log_store.js +1 -1
- package/dest/archiver/kv_archiver_store/message_store.d.ts +21 -15
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/message_store.js +150 -48
- package/dest/archiver/structs/inbox_message.d.ts +14 -0
- package/dest/archiver/structs/inbox_message.d.ts.map +1 -0
- package/dest/archiver/structs/inbox_message.js +38 -0
- package/dest/rpc/index.d.ts +1 -1
- package/dest/test/mock_l2_block_source.d.ts +2 -0
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +8 -1
- package/dest/test/mock_structs.d.ts +9 -0
- package/dest/test/mock_structs.d.ts.map +1 -0
- package/dest/test/mock_structs.js +37 -0
- package/package.json +15 -15
- package/src/archiver/archiver.ts +431 -108
- package/src/archiver/archiver_store.ts +37 -18
- package/src/archiver/archiver_store_test_suite.ts +307 -52
- package/src/archiver/data_retrieval.ts +130 -53
- package/src/archiver/errors.ts +21 -0
- package/src/archiver/instrumentation.ts +4 -1
- package/src/archiver/kv_archiver_store/block_store.ts +46 -8
- package/src/archiver/kv_archiver_store/contract_instance_store.ts +20 -7
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +61 -17
- package/src/archiver/kv_archiver_store/log_store.ts +6 -2
- package/src/archiver/kv_archiver_store/message_store.ts +209 -53
- package/src/archiver/structs/inbox_message.ts +40 -0
- package/src/test/mock_l2_block_source.ts +9 -1
- package/src/test/mock_structs.ts +49 -0
- package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts +0 -23
- package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts.map +0 -1
- package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.js +0 -49
- package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +0 -61
|
@@ -7,7 +7,7 @@ import { ContractClassStore } from './contract_class_store.js';
|
|
|
7
7
|
import { ContractInstanceStore } from './contract_instance_store.js';
|
|
8
8
|
import { LogStore } from './log_store.js';
|
|
9
9
|
import { MessageStore } from './message_store.js';
|
|
10
|
-
export const ARCHIVER_DB_VERSION =
|
|
10
|
+
export const ARCHIVER_DB_VERSION = 2;
|
|
11
11
|
/**
|
|
12
12
|
* LMDB implementation of the ArchiverDataStore interface.
|
|
13
13
|
*/ export class KVArchiverDataStore {
|
|
@@ -30,6 +30,15 @@ export const ARCHIVER_DB_VERSION = 1;
|
|
|
30
30
|
this.#contractClassStore = new ContractClassStore(db);
|
|
31
31
|
this.#contractInstanceStore = new ContractInstanceStore(db);
|
|
32
32
|
}
|
|
33
|
+
transactionAsync(callback) {
|
|
34
|
+
return this.db.transactionAsync(callback);
|
|
35
|
+
}
|
|
36
|
+
getBlockNumber() {
|
|
37
|
+
return this.getSynchedL2BlockNumber();
|
|
38
|
+
}
|
|
39
|
+
async getContract(address, blockNumber) {
|
|
40
|
+
return this.getContractInstance(address, blockNumber ?? await this.getBlockNumber());
|
|
41
|
+
}
|
|
33
42
|
async backupTo(path, compress = true) {
|
|
34
43
|
await this.db.backupTo(path, compress);
|
|
35
44
|
return join(path, 'data.mdb');
|
|
@@ -62,6 +71,9 @@ export const ARCHIVER_DB_VERSION = 1;
|
|
|
62
71
|
getContractInstance(address, blockNumber) {
|
|
63
72
|
return this.#contractInstanceStore.getContractInstance(address, blockNumber);
|
|
64
73
|
}
|
|
74
|
+
getContractInstanceDeploymentBlockNumber(address) {
|
|
75
|
+
return this.#contractInstanceStore.getContractInstanceDeploymentBlockNumber(address);
|
|
76
|
+
}
|
|
65
77
|
async addContractClasses(data, bytecodeCommitments, blockNumber) {
|
|
66
78
|
return (await Promise.all(data.map((c, i)=>this.#contractClassStore.addContractClass(c, bytecodeCommitments[i], blockNumber)))).every(Boolean);
|
|
67
79
|
}
|
|
@@ -74,8 +86,8 @@ export const ARCHIVER_DB_VERSION = 1;
|
|
|
74
86
|
addFunctions(contractClassId, privateFunctions, utilityFunctions) {
|
|
75
87
|
return this.#contractClassStore.addFunctions(contractClassId, privateFunctions, utilityFunctions);
|
|
76
88
|
}
|
|
77
|
-
async addContractInstances(data,
|
|
78
|
-
return (await Promise.all(data.map((c)=>this.#contractInstanceStore.addContractInstance(c)))).every(Boolean);
|
|
89
|
+
async addContractInstances(data, blockNumber) {
|
|
90
|
+
return (await Promise.all(data.map((c)=>this.#contractInstanceStore.addContractInstance(c, blockNumber)))).every(Boolean);
|
|
79
91
|
}
|
|
80
92
|
async deleteContractInstances(data, _blockNumber) {
|
|
81
93
|
return (await Promise.all(data.map((c)=>this.#contractInstanceStore.deleteContractInstance(c)))).every(Boolean);
|
|
@@ -90,8 +102,8 @@ export const ARCHIVER_DB_VERSION = 1;
|
|
|
90
102
|
* Append new blocks to the store's list.
|
|
91
103
|
* @param blocks - The L2 blocks to be added to the store and the last processed L1 block.
|
|
92
104
|
* @returns True if the operation is successful.
|
|
93
|
-
*/ addBlocks(blocks) {
|
|
94
|
-
return this.#blockStore.addBlocks(blocks);
|
|
105
|
+
*/ addBlocks(blocks, opts = {}) {
|
|
106
|
+
return this.#blockStore.addBlocks(blocks, opts);
|
|
95
107
|
}
|
|
96
108
|
/**
|
|
97
109
|
* Unwinds blocks from the database
|
|
@@ -102,13 +114,16 @@ export const ARCHIVER_DB_VERSION = 1;
|
|
|
102
114
|
*/ unwindBlocks(from, blocksToUnwind) {
|
|
103
115
|
return this.#blockStore.unwindBlocks(from, blocksToUnwind);
|
|
104
116
|
}
|
|
117
|
+
getPublishedBlock(number) {
|
|
118
|
+
return this.#blockStore.getBlock(number);
|
|
119
|
+
}
|
|
105
120
|
/**
|
|
106
121
|
* Gets up to `limit` amount of L2 blocks starting from `from`.
|
|
107
122
|
*
|
|
108
123
|
* @param start - Number of the first block to return (inclusive).
|
|
109
124
|
* @param limit - The number of blocks to return.
|
|
110
125
|
* @returns The requested L2 blocks
|
|
111
|
-
*/
|
|
126
|
+
*/ getPublishedBlocks(start, limit) {
|
|
112
127
|
return toArray(this.#blockStore.getBlocks(start, limit));
|
|
113
128
|
}
|
|
114
129
|
/**
|
|
@@ -147,10 +162,12 @@ export const ARCHIVER_DB_VERSION = 1;
|
|
|
147
162
|
getTotalL1ToL2MessageCount() {
|
|
148
163
|
return this.#messageStore.getTotalL1ToL2MessageCount();
|
|
149
164
|
}
|
|
165
|
+
getLastL1ToL2Message() {
|
|
166
|
+
return this.#messageStore.getLastMessage();
|
|
167
|
+
}
|
|
150
168
|
/**
|
|
151
169
|
* Append L1 to L2 messages to the store.
|
|
152
|
-
* @param messages - The L1 to L2 messages to be added to the store
|
|
153
|
-
* @returns True if the operation is successful.
|
|
170
|
+
* @param messages - The L1 to L2 messages to be added to the store.
|
|
154
171
|
*/ addL1ToL2Messages(messages) {
|
|
155
172
|
return this.#messageStore.addL1ToL2Messages(messages);
|
|
156
173
|
}
|
|
@@ -225,15 +242,15 @@ export const ARCHIVER_DB_VERSION = 1;
|
|
|
225
242
|
async setBlockSynchedL1BlockNumber(l1BlockNumber) {
|
|
226
243
|
await this.#blockStore.setSynchedL1BlockNumber(l1BlockNumber);
|
|
227
244
|
}
|
|
228
|
-
async
|
|
229
|
-
await this.#messageStore.
|
|
245
|
+
async setMessageSynchedL1Block(l1Block) {
|
|
246
|
+
await this.#messageStore.setSynchedL1Block(l1Block);
|
|
230
247
|
}
|
|
231
248
|
/**
|
|
232
249
|
* Gets the last L1 block number processed by the archiver
|
|
233
250
|
*/ async getSynchPoint() {
|
|
234
251
|
const [blocksSynchedTo, messagesSynchedTo] = await Promise.all([
|
|
235
252
|
this.#blockStore.getSynchedL1BlockNumber(),
|
|
236
|
-
this.#messageStore.
|
|
253
|
+
this.#messageStore.getSynchedL1Block()
|
|
237
254
|
]);
|
|
238
255
|
return {
|
|
239
256
|
blocksSynchedTo,
|
|
@@ -243,4 +260,13 @@ export const ARCHIVER_DB_VERSION = 1;
|
|
|
243
260
|
estimateSize() {
|
|
244
261
|
return this.db.estimateSize();
|
|
245
262
|
}
|
|
263
|
+
rollbackL1ToL2MessagesToL2Block(targetBlockNumber) {
|
|
264
|
+
return this.#messageStore.rollbackL1ToL2MessagesToL2Block(BigInt(targetBlockNumber));
|
|
265
|
+
}
|
|
266
|
+
iterateL1ToL2Messages(range = {}) {
|
|
267
|
+
return this.#messageStore.iterateL1ToL2Messages(range);
|
|
268
|
+
}
|
|
269
|
+
removeL1ToL2Messages(startIndex) {
|
|
270
|
+
return this.#messageStore.removeL1ToL2Messages(startIndex);
|
|
271
|
+
}
|
|
246
272
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/kv_archiver_store/log_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAGnD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC3G,OAAO,EAIL,KAAK,SAAS,EAEd,UAAU,EAEV,aAAa,EACd,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;GAEG;AACH,qBAAa,QAAQ;;
|
|
1
|
+
{"version":3,"file":"log_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/kv_archiver_store/log_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAGnD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC3G,OAAO,EAIL,KAAK,SAAS,EAEd,UAAU,EAEV,aAAa,EACd,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;GAEG;AACH,qBAAa,QAAQ;;IAUjB,OAAO,CAAC,EAAE;IACV,OAAO,CAAC,UAAU;gBADV,EAAE,EAAE,iBAAiB,EACrB,UAAU,EAAE,UAAU,EAC9B,eAAe,GAAE,MAAa;IAyChC;;;;OAIG;IACH,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAkE5C,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IA2B/C;;;;;OAKG;IACG,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAWzE;;;;;OAKG;IACG,aAAa,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;IAK3D;;;;OAIG;IACH,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,qBAAqB,CAAC;IA+EhE;;;;OAIG;IACH,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,4BAA4B,CAAC;CA6G/E"}
|
|
@@ -39,7 +39,7 @@ import { ContractClassLog, ExtendedContractClassLog, ExtendedPublicLog, LogId, P
|
|
|
39
39
|
taggedLogs.set(tag.toString(), currentLogs);
|
|
40
40
|
});
|
|
41
41
|
txEffect.publicLogs.forEach((log, logIndex)=>{
|
|
42
|
-
const tag = log.
|
|
42
|
+
const tag = log.fields[0];
|
|
43
43
|
this.#log.debug(`Found public log with tag ${tag.toString()} in block ${block.number}`);
|
|
44
44
|
const currentLogs = taggedLogs.get(tag.toString()) ?? [];
|
|
45
45
|
currentLogs.push(new TxScopedL2Log(txHash, dataStartIndexForTx, logIndex, block.number, log).toBuffer());
|
|
@@ -1,33 +1,39 @@
|
|
|
1
|
+
import type { L1BlockId } from '@aztec/ethereum';
|
|
1
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import type
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import { type AztecAsyncKVStore, type CustomRange } from '@aztec/kv-store';
|
|
4
|
+
import { type InboxMessage } from '../structs/inbox_message.js';
|
|
5
|
+
export declare class MessageStoreError extends Error {
|
|
6
|
+
readonly inboxMessage: InboxMessage;
|
|
7
|
+
constructor(message: string, inboxMessage: InboxMessage);
|
|
8
|
+
}
|
|
8
9
|
export declare class MessageStore {
|
|
9
10
|
#private;
|
|
10
11
|
private db;
|
|
11
12
|
constructor(db: AztecAsyncKVStore);
|
|
12
13
|
getTotalL1ToL2MessageCount(): Promise<bigint>;
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
getSynchedL1BlockNumber(): Promise<bigint | undefined>;
|
|
18
|
-
setSynchedL1BlockNumber(l1BlockNumber: bigint): Promise<void>;
|
|
14
|
+
/** Gets the last L1 block synced. */
|
|
15
|
+
getSynchedL1Block(): Promise<L1BlockId | undefined>;
|
|
16
|
+
/** Sets the last L1 block synced */
|
|
17
|
+
setSynchedL1Block(l1Block: L1BlockId): Promise<void>;
|
|
19
18
|
/**
|
|
20
19
|
* Append L1 to L2 messages to the store.
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* Requires new messages to be in order and strictly after the last message added.
|
|
21
|
+
* Throws if out of order messages are added or if the rolling hash is invalid.
|
|
23
22
|
*/
|
|
24
|
-
addL1ToL2Messages(messages:
|
|
23
|
+
addL1ToL2Messages(messages: InboxMessage[]): Promise<void>;
|
|
25
24
|
/**
|
|
26
25
|
* Gets the L1 to L2 message index in the L1 to L2 message tree.
|
|
27
26
|
* @param l1ToL2Message - The L1 to L2 message.
|
|
28
27
|
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
|
|
29
28
|
*/
|
|
30
29
|
getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined>;
|
|
30
|
+
getLastMessage(): Promise<InboxMessage | undefined>;
|
|
31
31
|
getL1ToL2Messages(blockNumber: bigint): Promise<Fr[]>;
|
|
32
|
+
iterateL1ToL2Messages(range?: CustomRange<bigint>): AsyncIterableIterator<InboxMessage>;
|
|
33
|
+
removeL1ToL2Messages(startIndex: bigint): Promise<void>;
|
|
34
|
+
rollbackL1ToL2MessagesToL2Block(targetBlockNumber: bigint): Promise<void>;
|
|
35
|
+
private indexToKey;
|
|
36
|
+
private leafToIndexKey;
|
|
37
|
+
private increaseTotalMessageCount;
|
|
32
38
|
}
|
|
33
39
|
//# sourceMappingURL=message_store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/kv_archiver_store/message_store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"message_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/kv_archiver_store/message_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAI9C,OAAO,EACL,KAAK,iBAAiB,EAGtB,KAAK,WAAW,EAEjB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,KAAK,YAAY,EAIlB,MAAM,6BAA6B,CAAC;AAErC,qBAAa,iBAAkB,SAAQ,KAAK;aAGxB,YAAY,EAAE,YAAY;gBAD1C,OAAO,EAAE,MAAM,EACC,YAAY,EAAE,YAAY;CAK7C;AAED,qBAAa,YAAY;;IAYX,OAAO,CAAC,EAAE;gBAAF,EAAE,EAAE,iBAAiB;IAO5B,0BAA0B,IAAI,OAAO,CAAC,MAAM,CAAC;IAI1D,qCAAqC;IACxB,iBAAiB,IAAI,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAUhE,oCAAoC;IACvB,iBAAiB,CAAC,OAAO,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAKjE;;;;OAIG;IACI,iBAAiB,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA+FjE;;;;OAIG;IACI,qBAAqB,CAAC,aAAa,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAI/D,cAAc,IAAI,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;IAKnD,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,EAAE,CAAC;IAuBpD,qBAAqB,CAAC,KAAK,GAAE,WAAW,CAAC,MAAM,CAAM,GAAG,qBAAqB,CAAC,YAAY,CAAC;IAOlG,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBvD,+BAA+B,CAAC,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMhF,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,cAAc;YAIR,yBAAyB;CASxC"}
|
|
@@ -1,57 +1,112 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
+
import { toArray } from '@aztec/foundation/iterable';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
5
|
+
import { mapRange } from '@aztec/kv-store';
|
|
4
6
|
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
import { deserializeInboxMessage, serializeInboxMessage, updateRollingHash } from '../structs/inbox_message.js';
|
|
8
|
+
export class MessageStoreError extends Error {
|
|
9
|
+
inboxMessage;
|
|
10
|
+
constructor(message, inboxMessage){
|
|
11
|
+
super(message), this.inboxMessage = inboxMessage;
|
|
12
|
+
this.name = 'MessageStoreError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class MessageStore {
|
|
8
16
|
db;
|
|
9
|
-
#l1ToL2Messages;
|
|
10
|
-
#l1ToL2MessageIndices;
|
|
11
|
-
#lastSynchedL1Block;
|
|
12
|
-
#totalMessageCount;
|
|
17
|
+
/** Maps from message index to serialized InboxMessage */ #l1ToL2Messages;
|
|
18
|
+
/** Maps from hex-stringified message leaf to its index */ #l1ToL2MessageIndices;
|
|
19
|
+
/** Stores L1 block number and hash of the L1 synchpoint */ #lastSynchedL1Block;
|
|
20
|
+
/** Stores total messages stored */ #totalMessageCount;
|
|
13
21
|
#log;
|
|
14
|
-
#l1ToL2MessagesSubtreeSize;
|
|
15
22
|
constructor(db){
|
|
16
23
|
this.db = db;
|
|
17
24
|
this.#log = createLogger('archiver:message_store');
|
|
18
|
-
this.#l1ToL2MessagesSubtreeSize = 2 ** L1_TO_L2_MSG_SUBTREE_HEIGHT;
|
|
19
25
|
this.#l1ToL2Messages = db.openMap('archiver_l1_to_l2_messages');
|
|
20
26
|
this.#l1ToL2MessageIndices = db.openMap('archiver_l1_to_l2_message_indices');
|
|
21
|
-
this.#lastSynchedL1Block = db.openSingleton('
|
|
27
|
+
this.#lastSynchedL1Block = db.openSingleton('archiver_last_l1_block_id');
|
|
22
28
|
this.#totalMessageCount = db.openSingleton('archiver_l1_to_l2_message_count');
|
|
23
29
|
}
|
|
24
30
|
async getTotalL1ToL2MessageCount() {
|
|
25
31
|
return await this.#totalMessageCount.getAsync() ?? 0n;
|
|
26
32
|
}
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
/** Gets the last L1 block synced. */ async getSynchedL1Block() {
|
|
34
|
+
const buffer = await this.#lastSynchedL1Block.getAsync();
|
|
35
|
+
if (!buffer) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const reader = BufferReader.asReader(buffer);
|
|
39
|
+
return {
|
|
40
|
+
l1BlockNumber: reader.readUInt256(),
|
|
41
|
+
l1BlockHash: Buffer32.fromBuffer(reader.readBytes(Buffer32.SIZE))
|
|
42
|
+
};
|
|
32
43
|
}
|
|
33
|
-
async
|
|
34
|
-
|
|
44
|
+
/** Sets the last L1 block synced */ async setSynchedL1Block(l1Block) {
|
|
45
|
+
const buffer = serializeToBuffer([
|
|
46
|
+
l1Block.l1BlockNumber,
|
|
47
|
+
l1Block.l1BlockHash
|
|
48
|
+
]);
|
|
49
|
+
await this.#lastSynchedL1Block.set(buffer);
|
|
35
50
|
}
|
|
36
51
|
/**
|
|
37
52
|
* Append L1 to L2 messages to the store.
|
|
38
|
-
*
|
|
39
|
-
*
|
|
53
|
+
* Requires new messages to be in order and strictly after the last message added.
|
|
54
|
+
* Throws if out of order messages are added or if the rolling hash is invalid.
|
|
40
55
|
*/ addL1ToL2Messages(messages) {
|
|
56
|
+
if (messages.length === 0) {
|
|
57
|
+
return Promise.resolve();
|
|
58
|
+
}
|
|
41
59
|
return this.db.transactionAsync(async ()=>{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
let lastMessage = await this.getLastMessage();
|
|
61
|
+
let messageCount = 0;
|
|
62
|
+
for (const message of messages){
|
|
63
|
+
// Check messages are inserted in increasing order, but allow reinserting messages.
|
|
64
|
+
if (lastMessage && message.index <= lastMessage.index) {
|
|
65
|
+
const existing = await this.#l1ToL2Messages.getAsync(this.indexToKey(message.index));
|
|
66
|
+
if (existing && deserializeInboxMessage(existing).rollingHash.equals(message.rollingHash)) {
|
|
67
|
+
// We reinsert instead of skipping in case the message was re-orged and got added in a different L1 block.
|
|
68
|
+
this.#log.trace(`Reinserting message with index ${message.index} in the store`);
|
|
69
|
+
await this.#l1ToL2Messages.set(this.indexToKey(message.index), serializeInboxMessage(message));
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
throw new MessageStoreError(`Cannot insert L1 to L2 message with index ${message.index} before last message with index ${lastMessage.index}`, message);
|
|
73
|
+
}
|
|
74
|
+
// Check rolling hash is valid.
|
|
75
|
+
const previousRollingHash = lastMessage?.rollingHash ?? Buffer16.ZERO;
|
|
76
|
+
const expectedRollingHash = updateRollingHash(previousRollingHash, message.leaf);
|
|
77
|
+
if (!expectedRollingHash.equals(message.rollingHash)) {
|
|
78
|
+
throw new MessageStoreError(`Invalid rolling hash for incoming L1 to L2 message ${message.leaf.toString()} ` + `with index ${message.index} ` + `(expected ${expectedRollingHash.toString()} from previous hash ${previousRollingHash} but got ${message.rollingHash.toString()})`, message);
|
|
79
|
+
}
|
|
80
|
+
// Check index corresponds to the L2 block number.
|
|
81
|
+
const [expectedStart, expectedEnd] = InboxLeaf.indexRangeFromL2Block(message.l2BlockNumber);
|
|
82
|
+
if (message.index < expectedStart || message.index >= expectedEnd) {
|
|
83
|
+
throw new MessageStoreError(`Invalid index ${message.index} for incoming L1 to L2 message ${message.leaf.toString()} ` + `at block ${message.l2BlockNumber} (expected value in range [${expectedStart}, ${expectedEnd}))`, message);
|
|
84
|
+
}
|
|
85
|
+
// Check there are no gaps in the indices within the same block.
|
|
86
|
+
if (lastMessage && message.l2BlockNumber === lastMessage.l2BlockNumber && message.index !== lastMessage.index + 1n) {
|
|
87
|
+
throw new MessageStoreError(`Missing prior message for incoming L1 to L2 message ${message.leaf.toString()} ` + `with index ${message.index}`, message);
|
|
88
|
+
}
|
|
89
|
+
// Check the first message in a block has the correct index.
|
|
90
|
+
if ((!lastMessage || message.l2BlockNumber > lastMessage.l2BlockNumber) && message.index !== InboxLeaf.smallestIndexFromL2Block(message.l2BlockNumber)) {
|
|
91
|
+
throw new MessageStoreError(`Message ${message.leaf.toString()} for L2 block ${message.l2BlockNumber} has wrong index ` + `${message.index} (expected ${InboxLeaf.smallestIndexFromL2Block(message.l2BlockNumber)})`, message);
|
|
92
|
+
}
|
|
93
|
+
// Perform the insertions.
|
|
94
|
+
await this.#l1ToL2Messages.set(this.indexToKey(message.index), serializeInboxMessage(message));
|
|
95
|
+
await this.#l1ToL2MessageIndices.set(this.leafToIndexKey(message.leaf), message.index);
|
|
96
|
+
messageCount++;
|
|
97
|
+
this.#log.trace(`Inserted L1 to L2 message ${message.leaf} with index ${message.index} into the store`);
|
|
98
|
+
lastMessage = message;
|
|
45
99
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
await this
|
|
50
|
-
|
|
100
|
+
// Update the L1 sync point to that of the last message added.
|
|
101
|
+
const currentSyncPoint = await this.getSynchedL1Block();
|
|
102
|
+
if (!currentSyncPoint || currentSyncPoint.l1BlockNumber < lastMessage.l1BlockNumber) {
|
|
103
|
+
await this.setSynchedL1Block({
|
|
104
|
+
l1BlockNumber: lastMessage.l1BlockNumber,
|
|
105
|
+
l1BlockHash: lastMessage.l1BlockHash
|
|
106
|
+
});
|
|
51
107
|
}
|
|
52
|
-
|
|
53
|
-
await this
|
|
54
|
-
return true;
|
|
108
|
+
// Update total message count with the number of inserted messages.
|
|
109
|
+
await this.increaseTotalMessageCount(messageCount);
|
|
55
110
|
});
|
|
56
111
|
}
|
|
57
112
|
/**
|
|
@@ -59,27 +114,74 @@ import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
|
59
114
|
* @param l1ToL2Message - The L1 to L2 message.
|
|
60
115
|
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
|
|
61
116
|
*/ getL1ToL2MessageIndex(l1ToL2Message) {
|
|
62
|
-
return this.#l1ToL2MessageIndices.getAsync(
|
|
117
|
+
return this.#l1ToL2MessageIndices.getAsync(this.leafToIndexKey(l1ToL2Message));
|
|
118
|
+
}
|
|
119
|
+
async getLastMessage() {
|
|
120
|
+
const [msg] = await toArray(this.#l1ToL2Messages.valuesAsync({
|
|
121
|
+
reverse: true,
|
|
122
|
+
limit: 1
|
|
123
|
+
}));
|
|
124
|
+
return msg ? deserializeInboxMessage(msg) : undefined;
|
|
63
125
|
}
|
|
64
126
|
async getL1ToL2Messages(blockNumber) {
|
|
65
127
|
const messages = [];
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
for
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
} else {
|
|
78
|
-
undefinedMessageFound = true;
|
|
79
|
-
// We continue iterating over messages here to verify that there are no more messages after the undefined one.
|
|
80
|
-
// --> If this was the case this would imply there is some issue with log fetching.
|
|
128
|
+
const [startIndex, endIndex] = InboxLeaf.indexRangeFromL2Block(blockNumber);
|
|
129
|
+
let lastIndex = startIndex - 1n;
|
|
130
|
+
for await (const msgBuffer of this.#l1ToL2Messages.valuesAsync({
|
|
131
|
+
start: this.indexToKey(startIndex),
|
|
132
|
+
end: this.indexToKey(endIndex)
|
|
133
|
+
})){
|
|
134
|
+
const msg = deserializeInboxMessage(msgBuffer);
|
|
135
|
+
if (msg.l2BlockNumber !== blockNumber) {
|
|
136
|
+
throw new Error(`L1 to L2 message with index ${msg.index} has invalid block number ${msg.l2BlockNumber}`);
|
|
137
|
+
} else if (msg.index !== lastIndex + 1n) {
|
|
138
|
+
throw new Error(`Expected L1 to L2 message with index ${lastIndex + 1n} but got ${msg.index}`);
|
|
81
139
|
}
|
|
140
|
+
lastIndex = msg.index;
|
|
141
|
+
messages.push(msg.leaf);
|
|
82
142
|
}
|
|
83
143
|
return messages;
|
|
84
144
|
}
|
|
145
|
+
async *iterateL1ToL2Messages(range = {}) {
|
|
146
|
+
const entriesRange = mapRange(range, this.indexToKey);
|
|
147
|
+
for await (const msgBuffer of this.#l1ToL2Messages.valuesAsync(entriesRange)){
|
|
148
|
+
yield deserializeInboxMessage(msgBuffer);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
removeL1ToL2Messages(startIndex) {
|
|
152
|
+
this.#log.debug(`Deleting L1 to L2 messages from index ${startIndex}`);
|
|
153
|
+
let deleteCount = 0;
|
|
154
|
+
return this.db.transactionAsync(async ()=>{
|
|
155
|
+
for await (const [key, msgBuffer] of this.#l1ToL2Messages.entriesAsync({
|
|
156
|
+
start: this.indexToKey(startIndex)
|
|
157
|
+
})){
|
|
158
|
+
this.#log.trace(`Deleting L1 to L2 message with index ${key - 1} from the store`);
|
|
159
|
+
await this.#l1ToL2Messages.delete(key);
|
|
160
|
+
await this.#l1ToL2MessageIndices.delete(this.leafToIndexKey(deserializeInboxMessage(msgBuffer).leaf));
|
|
161
|
+
deleteCount++;
|
|
162
|
+
}
|
|
163
|
+
await this.increaseTotalMessageCount(-deleteCount);
|
|
164
|
+
this.#log.warn(`Deleted ${deleteCount} L1 to L2 messages from index ${startIndex} from the store`);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
rollbackL1ToL2MessagesToL2Block(targetBlockNumber) {
|
|
168
|
+
this.#log.debug(`Deleting L1 to L2 messages up to target L2 block ${targetBlockNumber}`);
|
|
169
|
+
const startIndex = InboxLeaf.smallestIndexFromL2Block(targetBlockNumber + 1n);
|
|
170
|
+
return this.removeL1ToL2Messages(startIndex);
|
|
171
|
+
}
|
|
172
|
+
indexToKey(index) {
|
|
173
|
+
return Number(index);
|
|
174
|
+
}
|
|
175
|
+
leafToIndexKey(leaf) {
|
|
176
|
+
return leaf.toString();
|
|
177
|
+
}
|
|
178
|
+
async increaseTotalMessageCount(count) {
|
|
179
|
+
if (count === 0) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
return await this.db.transactionAsync(async ()=>{
|
|
183
|
+
const lastTotalMessageCount = await this.getTotalL1ToL2MessageCount();
|
|
184
|
+
await this.#totalMessageCount.set(lastTotalMessageCount + BigInt(count));
|
|
185
|
+
});
|
|
186
|
+
}
|
|
85
187
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
export type InboxMessage = {
|
|
4
|
+
index: bigint;
|
|
5
|
+
leaf: Fr;
|
|
6
|
+
l2BlockNumber: bigint;
|
|
7
|
+
l1BlockNumber: bigint;
|
|
8
|
+
l1BlockHash: Buffer32;
|
|
9
|
+
rollingHash: Buffer16;
|
|
10
|
+
};
|
|
11
|
+
export declare function updateRollingHash(currentRollingHash: Buffer16, leaf: Fr): Buffer16;
|
|
12
|
+
export declare function serializeInboxMessage(message: InboxMessage): Buffer;
|
|
13
|
+
export declare function deserializeInboxMessage(buffer: Buffer): InboxMessage;
|
|
14
|
+
//# sourceMappingURL=inbox_message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inbox_message.d.ts","sourceRoot":"","sources":["../../../src/archiver/structs/inbox_message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAG9C,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,EAAE,CAAC;IACT,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,QAAQ,CAAC;IACtB,WAAW,EAAE,QAAQ,CAAC;CACvB,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,kBAAkB,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,GAAG,QAAQ,CAGlF;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CASnE;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CASpE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
+
import { keccak256 } from '@aztec/foundation/crypto';
|
|
3
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
4
|
+
import { BufferReader, bigintToUInt64BE, numToUInt32BE, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
5
|
+
export function updateRollingHash(currentRollingHash, leaf) {
|
|
6
|
+
const input = Buffer.concat([
|
|
7
|
+
currentRollingHash.toBuffer(),
|
|
8
|
+
leaf.toBuffer()
|
|
9
|
+
]);
|
|
10
|
+
return Buffer16.fromBuffer(keccak256(input));
|
|
11
|
+
}
|
|
12
|
+
export function serializeInboxMessage(message) {
|
|
13
|
+
return serializeToBuffer([
|
|
14
|
+
bigintToUInt64BE(message.index),
|
|
15
|
+
message.leaf,
|
|
16
|
+
message.l1BlockHash,
|
|
17
|
+
numToUInt32BE(Number(message.l1BlockNumber)),
|
|
18
|
+
numToUInt32BE(Number(message.l2BlockNumber)),
|
|
19
|
+
message.rollingHash
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
22
|
+
export function deserializeInboxMessage(buffer) {
|
|
23
|
+
const reader = BufferReader.asReader(buffer);
|
|
24
|
+
const index = reader.readUInt64();
|
|
25
|
+
const leaf = reader.readObject(Fr);
|
|
26
|
+
const l1BlockHash = reader.readObject(Buffer32);
|
|
27
|
+
const l1BlockNumber = BigInt(reader.readNumber());
|
|
28
|
+
const l2BlockNumber = BigInt(reader.readNumber());
|
|
29
|
+
const rollingHash = reader.readObject(Buffer16);
|
|
30
|
+
return {
|
|
31
|
+
index,
|
|
32
|
+
leaf,
|
|
33
|
+
l1BlockHash,
|
|
34
|
+
l1BlockNumber,
|
|
35
|
+
l2BlockNumber,
|
|
36
|
+
rollingHash
|
|
37
|
+
};
|
|
38
|
+
}
|
package/dest/rpc/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ArchiverApi } from '@aztec/stdlib/interfaces/server';
|
|
2
2
|
import { type ComponentsVersions } from '@aztec/stdlib/versioning';
|
|
3
|
-
export declare function createArchiverClient(url: string, versions: Partial<ComponentsVersions>, fetch?: (host: string,
|
|
3
|
+
export declare function createArchiverClient(url: string, versions: Partial<ComponentsVersions>, fetch?: (host: string, body: unknown, extraHeaders?: Record<string, string>, noRetry?: boolean) => Promise<{
|
|
4
4
|
response: any;
|
|
5
5
|
headers: {
|
|
6
6
|
get: (header: string) => string | null | undefined;
|
|
@@ -12,11 +12,13 @@ import { type BlockHeader, TxHash, TxReceipt } from '@aztec/stdlib/tx';
|
|
|
12
12
|
export declare class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
13
13
|
protected l2Blocks: L2Block[];
|
|
14
14
|
private provenBlockNumber;
|
|
15
|
+
private finalizedBlockNumber;
|
|
15
16
|
private log;
|
|
16
17
|
createBlocks(numBlocks: number): Promise<void>;
|
|
17
18
|
addBlocks(blocks: L2Block[]): void;
|
|
18
19
|
removeBlocks(numBlocks: number): void;
|
|
19
20
|
setProvenBlockNumber(provenBlockNumber: number): void;
|
|
21
|
+
setFinalizedBlockNumber(finalizedBlockNumber: number): void;
|
|
20
22
|
/**
|
|
21
23
|
* Method to fetch the rollup contract address at the base-layer.
|
|
22
24
|
* @returns The rollup address.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock_l2_block_source.d.ts","sourceRoot":"","sources":["../../src/test/mock_l2_block_source.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAe,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC5F,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AACnH,OAAO,EAAE,KAAK,iBAAiB,EAAwB,MAAM,6BAA6B,CAAC;AAC3F,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,EAAE,SAAS,EAAY,MAAM,kBAAkB,CAAC;AAEjF;;GAEG;AACH,qBAAa,iBAAkB,YAAW,aAAa,EAAE,kBAAkB;IACzE,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAM;IAEnC,OAAO,CAAC,iBAAiB,CAAa;
|
|
1
|
+
{"version":3,"file":"mock_l2_block_source.d.ts","sourceRoot":"","sources":["../../src/test/mock_l2_block_source.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAe,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC5F,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AACnH,OAAO,EAAE,KAAK,iBAAiB,EAAwB,MAAM,6BAA6B,CAAC;AAC3F,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,EAAE,SAAS,EAAY,MAAM,kBAAkB,CAAC;AAEjF;;GAEG;AACH,qBAAa,iBAAkB,YAAW,aAAa,EAAE,kBAAkB;IACzE,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAM;IAEnC,OAAO,CAAC,iBAAiB,CAAa;IACtC,OAAO,CAAC,oBAAoB,CAAa;IAEzC,OAAO,CAAC,GAAG,CAAiD;IAE/C,YAAY,CAAC,SAAS,EAAE,MAAM;IAUpC,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE;IAK3B,YAAY,CAAC,SAAS,EAAE,MAAM;IAK9B,oBAAoB,CAAC,iBAAiB,EAAE,MAAM;IAI9C,uBAAuB,CAAC,oBAAoB,EAAE,MAAM;IAO3D;;;OAGG;IACH,gBAAgB,IAAI,OAAO,CAAC,UAAU,CAAC;IAIvC;;;OAGG;IACH,kBAAkB,IAAI,OAAO,CAAC,UAAU,CAAC;IAIzC;;;OAGG;IACI,cAAc;IAId,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI9C;;;;OAIG;IACI,QAAQ,CAAC,MAAM,EAAE,MAAM;IAI9B;;;;;OAKG;IACI,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO;IAQjD,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO;;;;;;;;;IAa7E,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAI3E,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAU1D,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAIpE;;;;OAIG;IACU,WAAW,CAAC,MAAM,EAAE,MAAM;;;;;;IAgBvC;;;;OAIG;IACU,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAkB1E,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IA2BlC,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAInC,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IAIlC,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIvD,cAAc,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAI5C;;;OAGG;IACI,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAK7B;;;OAGG;IACI,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAK5B,gBAAgB,CAAC,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;IAInE,qBAAqB,CAAC,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;IAIvD,WAAW,CAAC,QAAQ,EAAE,YAAY,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC;IAI5G,mBAAmB,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;IAIpC,oBAAoB,CAAC,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAItG,kCAAkC,CAAC,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B"}
|
|
@@ -10,6 +10,7 @@ import { TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
|
10
10
|
*/ export class MockL2BlockSource {
|
|
11
11
|
l2Blocks = [];
|
|
12
12
|
provenBlockNumber = 0;
|
|
13
|
+
finalizedBlockNumber = 0;
|
|
13
14
|
log = createLogger('archiver:mock_l2_block_source');
|
|
14
15
|
async createBlocks(numBlocks) {
|
|
15
16
|
for(let i = 0; i < numBlocks; i++){
|
|
@@ -30,6 +31,12 @@ import { TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
|
30
31
|
setProvenBlockNumber(provenBlockNumber) {
|
|
31
32
|
this.provenBlockNumber = provenBlockNumber;
|
|
32
33
|
}
|
|
34
|
+
setFinalizedBlockNumber(finalizedBlockNumber) {
|
|
35
|
+
if (finalizedBlockNumber > this.provenBlockNumber) {
|
|
36
|
+
this.provenBlockNumber = finalizedBlockNumber;
|
|
37
|
+
}
|
|
38
|
+
this.finalizedBlockNumber = finalizedBlockNumber;
|
|
39
|
+
}
|
|
33
40
|
/**
|
|
34
41
|
* Method to fetch the rollup contract address at the base-layer.
|
|
35
42
|
* @returns The rollup address.
|
|
@@ -133,7 +140,7 @@ import { TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
|
133
140
|
const [latest, proven, finalized] = [
|
|
134
141
|
await this.getBlockNumber(),
|
|
135
142
|
await this.getProvenBlockNumber(),
|
|
136
|
-
|
|
143
|
+
this.finalizedBlockNumber
|
|
137
144
|
];
|
|
138
145
|
const latestBlock = this.l2Blocks[latest - 1];
|
|
139
146
|
const provenBlock = this.l2Blocks[proven - 1];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Buffer16 } from '@aztec/foundation/buffer';
|
|
2
|
+
import { type InboxMessage } from '../archiver/structs/inbox_message.js';
|
|
3
|
+
export declare function makeInboxMessage(previousRollingHash?: Buffer16, overrides?: Partial<InboxMessage>): InboxMessage;
|
|
4
|
+
export declare function makeInboxMessages(count: number, opts?: {
|
|
5
|
+
initialHash?: Buffer16;
|
|
6
|
+
initialL2BlockNumber?: bigint;
|
|
7
|
+
overrideFn?: (msg: InboxMessage, index: number) => InboxMessage;
|
|
8
|
+
}): InboxMessage[];
|
|
9
|
+
//# sourceMappingURL=mock_structs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock_structs.d.ts","sourceRoot":"","sources":["../../src/test/mock_structs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAY,MAAM,0BAA0B,CAAC;AAK9D,OAAO,EAAE,KAAK,YAAY,EAAqB,MAAM,sCAAsC,CAAC;AAE5F,wBAAgB,gBAAgB,CAC9B,mBAAmB,WAAgB,EACnC,SAAS,GAAE,OAAO,CAAC,YAAY,CAAM,GACpC,YAAY,CAgBd;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,IAAI,GAAE;IACJ,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,KAAK,YAAY,CAAC;CAC5D,GACL,YAAY,EAAE,CAahB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
+
import { randomBigInt } from '@aztec/foundation/crypto';
|
|
3
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
4
|
+
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
5
|
+
import { updateRollingHash } from '../archiver/structs/inbox_message.js';
|
|
6
|
+
export function makeInboxMessage(previousRollingHash = Buffer16.ZERO, overrides = {}) {
|
|
7
|
+
const { l2BlockNumber = randomBigInt(100n) + 1n } = overrides;
|
|
8
|
+
const { l1BlockNumber = l2BlockNumber } = overrides;
|
|
9
|
+
const { l1BlockHash = Buffer32.random() } = overrides;
|
|
10
|
+
const { leaf = Fr.random() } = overrides;
|
|
11
|
+
const { rollingHash = updateRollingHash(previousRollingHash, leaf) } = overrides;
|
|
12
|
+
const { index = InboxLeaf.smallestIndexFromL2Block(l2BlockNumber) } = overrides;
|
|
13
|
+
return {
|
|
14
|
+
index,
|
|
15
|
+
leaf,
|
|
16
|
+
l2BlockNumber,
|
|
17
|
+
l1BlockNumber,
|
|
18
|
+
l1BlockHash,
|
|
19
|
+
rollingHash
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function makeInboxMessages(count, opts = {}) {
|
|
23
|
+
const { initialHash = Buffer16.ZERO, overrideFn = (msg)=>msg, initialL2BlockNumber = 1n } = opts;
|
|
24
|
+
const messages = [];
|
|
25
|
+
let rollingHash = initialHash;
|
|
26
|
+
for(let i = 0; i < count; i++){
|
|
27
|
+
const leaf = Fr.random();
|
|
28
|
+
const l2BlockNumber = BigInt(i) + initialL2BlockNumber;
|
|
29
|
+
const message = overrideFn(makeInboxMessage(rollingHash, {
|
|
30
|
+
leaf,
|
|
31
|
+
l2BlockNumber
|
|
32
|
+
}), i);
|
|
33
|
+
rollingHash = message.rollingHash;
|
|
34
|
+
messages.push(message);
|
|
35
|
+
}
|
|
36
|
+
return messages;
|
|
37
|
+
}
|