@aztec/archiver 0.0.0-test.1 → 0.0.1-commit.5476d83
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/README.md +27 -6
- package/dest/archiver/archiver.d.ts +147 -57
- package/dest/archiver/archiver.d.ts.map +1 -1
- package/dest/archiver/archiver.js +841 -333
- package/dest/archiver/archiver_store.d.ts +85 -50
- 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 +708 -213
- package/dest/archiver/config.d.ts +5 -21
- package/dest/archiver/config.d.ts.map +1 -1
- package/dest/archiver/config.js +21 -12
- package/dest/archiver/data_retrieval.d.ts +32 -27
- package/dest/archiver/data_retrieval.d.ts.map +1 -1
- package/dest/archiver/data_retrieval.js +197 -94
- package/dest/archiver/errors.d.ts +9 -1
- package/dest/archiver/errors.d.ts.map +1 -1
- package/dest/archiver/errors.js +12 -0
- package/dest/archiver/index.d.ts +3 -4
- package/dest/archiver/index.d.ts.map +1 -1
- package/dest/archiver/index.js +1 -2
- package/dest/archiver/instrumentation.d.ts +12 -6
- package/dest/archiver/instrumentation.d.ts.map +1 -1
- package/dest/archiver/instrumentation.js +58 -17
- package/dest/archiver/kv_archiver_store/block_store.d.ts +48 -11
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/block_store.js +216 -63
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +3 -3
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/contract_class_store.js +12 -18
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +11 -8
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.js +30 -16
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +50 -35
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +88 -46
- package/dest/archiver/kv_archiver_store/log_store.d.ts +2 -2
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/log_store.js +18 -46
- package/dest/archiver/kv_archiver_store/message_store.d.ts +23 -17
- 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/data_retrieval.d.ts +1 -1
- package/dest/archiver/structs/inbox_message.d.ts +15 -0
- package/dest/archiver/structs/inbox_message.d.ts.map +1 -0
- package/dest/archiver/structs/inbox_message.js +38 -0
- package/dest/archiver/structs/published.d.ts +3 -11
- package/dest/archiver/structs/published.d.ts.map +1 -1
- package/dest/archiver/structs/published.js +1 -1
- package/dest/archiver/validation.d.ts +17 -0
- package/dest/archiver/validation.d.ts.map +1 -0
- package/dest/archiver/validation.js +98 -0
- package/dest/factory.d.ts +8 -13
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +18 -49
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/rpc/index.d.ts +2 -3
- package/dest/rpc/index.d.ts.map +1 -1
- package/dest/rpc/index.js +1 -4
- package/dest/test/index.d.ts +1 -1
- package/dest/test/mock_archiver.d.ts +2 -2
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.d.ts +5 -3
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +14 -1
- package/dest/test/mock_l2_block_source.d.ts +38 -10
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +119 -8
- 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 +28 -30
- package/src/archiver/archiver.ts +1087 -410
- package/src/archiver/archiver_store.ts +97 -55
- package/src/archiver/archiver_store_test_suite.ts +664 -210
- package/src/archiver/config.ts +28 -41
- package/src/archiver/data_retrieval.ts +279 -125
- package/src/archiver/errors.ts +21 -0
- package/src/archiver/index.ts +2 -3
- package/src/archiver/instrumentation.ts +77 -22
- package/src/archiver/kv_archiver_store/block_store.ts +270 -72
- package/src/archiver/kv_archiver_store/contract_class_store.ts +13 -23
- package/src/archiver/kv_archiver_store/contract_instance_store.ts +35 -27
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +127 -63
- package/src/archiver/kv_archiver_store/log_store.ts +24 -62
- package/src/archiver/kv_archiver_store/message_store.ts +209 -53
- package/src/archiver/structs/inbox_message.ts +41 -0
- package/src/archiver/structs/published.ts +2 -11
- package/src/archiver/validation.ts +124 -0
- package/src/factory.ts +24 -66
- package/src/index.ts +1 -1
- package/src/rpc/index.ts +1 -5
- package/src/test/mock_archiver.ts +1 -1
- package/src/test/mock_l1_to_l2_message_source.ts +14 -3
- package/src/test/mock_l2_block_source.ts +158 -13
- package/src/test/mock_structs.ts +49 -0
- package/dest/archiver/kv_archiver_store/nullifier_store.d.ts +0 -12
- package/dest/archiver/kv_archiver_store/nullifier_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/nullifier_store.js +0 -73
- 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/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +0 -175
- package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +0 -1
- package/dest/archiver/memory_archiver_store/memory_archiver_store.js +0 -636
- package/src/archiver/kv_archiver_store/nullifier_store.ts +0 -97
- package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +0 -61
- package/src/archiver/memory_archiver_store/memory_archiver_store.ts +0 -801
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import type { L2Tips } from '@aztec/stdlib/block';
|
|
2
3
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -17,8 +18,8 @@ export class MockL1ToL2MessageSource implements L1ToL2MessageSource {
|
|
|
17
18
|
this.blockNumber = blockNumber;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
getL1ToL2Messages(blockNumber:
|
|
21
|
-
return Promise.resolve(this.messagesPerBlock.get(
|
|
21
|
+
getL1ToL2Messages(blockNumber: number): Promise<Fr[]> {
|
|
22
|
+
return Promise.resolve(this.messagesPerBlock.get(blockNumber) ?? []);
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
getL1ToL2MessageIndex(_l1ToL2Message: Fr): Promise<bigint | undefined> {
|
|
@@ -28,4 +29,14 @@ export class MockL1ToL2MessageSource implements L1ToL2MessageSource {
|
|
|
28
29
|
getBlockNumber(): Promise<number> {
|
|
29
30
|
return Promise.resolve(this.blockNumber);
|
|
30
31
|
}
|
|
32
|
+
|
|
33
|
+
getL2Tips(): Promise<L2Tips> {
|
|
34
|
+
const number = this.blockNumber;
|
|
35
|
+
const tip = { number, hash: new Fr(number).toString() };
|
|
36
|
+
return Promise.resolve({
|
|
37
|
+
latest: tip,
|
|
38
|
+
proven: tip,
|
|
39
|
+
finalized: tip,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
31
42
|
}
|
|
@@ -1,17 +1,33 @@
|
|
|
1
|
+
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
1
2
|
import { DefaultL1ContractsConfig } from '@aztec/ethereum';
|
|
3
|
+
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
3
7
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
8
|
+
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
9
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
|
+
import {
|
|
11
|
+
L2Block,
|
|
12
|
+
L2BlockHash,
|
|
13
|
+
type L2BlockSource,
|
|
14
|
+
type L2Tips,
|
|
15
|
+
PublishedL2Block,
|
|
16
|
+
type ValidateBlockResult,
|
|
17
|
+
} from '@aztec/stdlib/block';
|
|
18
|
+
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
19
|
+
import { EmptyL1RollupConstants, type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
6
20
|
import { type BlockHeader, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
21
|
+
import type { UInt64 } from '@aztec/stdlib/types';
|
|
7
22
|
|
|
8
23
|
/**
|
|
9
24
|
* A mocked implementation of L2BlockSource to be used in tests.
|
|
10
25
|
*/
|
|
11
|
-
export class MockL2BlockSource implements L2BlockSource {
|
|
26
|
+
export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
12
27
|
protected l2Blocks: L2Block[] = [];
|
|
13
28
|
|
|
14
29
|
private provenBlockNumber: number = 0;
|
|
30
|
+
private finalizedBlockNumber: number = 0;
|
|
15
31
|
|
|
16
32
|
private log = createLogger('archiver:mock_l2_block_source');
|
|
17
33
|
|
|
@@ -39,6 +55,13 @@ export class MockL2BlockSource implements L2BlockSource {
|
|
|
39
55
|
this.provenBlockNumber = provenBlockNumber;
|
|
40
56
|
}
|
|
41
57
|
|
|
58
|
+
public setFinalizedBlockNumber(finalizedBlockNumber: number) {
|
|
59
|
+
if (finalizedBlockNumber > this.provenBlockNumber) {
|
|
60
|
+
this.provenBlockNumber = finalizedBlockNumber;
|
|
61
|
+
}
|
|
62
|
+
this.finalizedBlockNumber = finalizedBlockNumber;
|
|
63
|
+
}
|
|
64
|
+
|
|
42
65
|
/**
|
|
43
66
|
* Method to fetch the rollup contract address at the base-layer.
|
|
44
67
|
* @returns The rollup address.
|
|
@@ -90,24 +113,95 @@ export class MockL2BlockSource implements L2BlockSource {
|
|
|
90
113
|
);
|
|
91
114
|
}
|
|
92
115
|
|
|
116
|
+
public async getPublishedBlocks(from: number, limit: number, proven?: boolean) {
|
|
117
|
+
const blocks = await this.getBlocks(from, limit, proven);
|
|
118
|
+
return blocks.map(block =>
|
|
119
|
+
PublishedL2Block.fromFields({
|
|
120
|
+
block,
|
|
121
|
+
l1: {
|
|
122
|
+
blockNumber: BigInt(block.number),
|
|
123
|
+
blockHash: Buffer32.random().toString(),
|
|
124
|
+
timestamp: BigInt(block.number),
|
|
125
|
+
},
|
|
126
|
+
attestations: [],
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public async getPublishedBlockByHash(blockHash: Fr): Promise<PublishedL2Block | undefined> {
|
|
132
|
+
for (const block of this.l2Blocks) {
|
|
133
|
+
const hash = await block.hash();
|
|
134
|
+
if (hash.equals(blockHash)) {
|
|
135
|
+
return PublishedL2Block.fromFields({
|
|
136
|
+
block,
|
|
137
|
+
l1: {
|
|
138
|
+
blockNumber: BigInt(block.number),
|
|
139
|
+
blockHash: Buffer32.random().toString(),
|
|
140
|
+
timestamp: BigInt(block.number),
|
|
141
|
+
},
|
|
142
|
+
attestations: [],
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public getPublishedBlockByArchive(archive: Fr): Promise<PublishedL2Block | undefined> {
|
|
150
|
+
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
151
|
+
if (!block) {
|
|
152
|
+
return Promise.resolve(undefined);
|
|
153
|
+
}
|
|
154
|
+
return Promise.resolve(
|
|
155
|
+
PublishedL2Block.fromFields({
|
|
156
|
+
block,
|
|
157
|
+
l1: {
|
|
158
|
+
blockNumber: BigInt(block.number),
|
|
159
|
+
blockHash: Buffer32.random().toString(),
|
|
160
|
+
timestamp: BigInt(block.number),
|
|
161
|
+
},
|
|
162
|
+
attestations: [],
|
|
163
|
+
}),
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public async getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
|
|
168
|
+
for (const block of this.l2Blocks) {
|
|
169
|
+
const hash = await block.hash();
|
|
170
|
+
if (hash.equals(blockHash)) {
|
|
171
|
+
return block.getBlockHeader();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
public getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
|
|
178
|
+
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
179
|
+
return Promise.resolve(block?.getBlockHeader());
|
|
180
|
+
}
|
|
181
|
+
|
|
93
182
|
getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
94
|
-
return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.
|
|
183
|
+
return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.getBlockHeader());
|
|
95
184
|
}
|
|
96
185
|
|
|
97
|
-
getBlocksForEpoch(epochNumber:
|
|
186
|
+
getBlocksForEpoch(epochNumber: EpochNumber): Promise<L2Block[]> {
|
|
98
187
|
const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
|
|
99
188
|
const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
|
|
100
189
|
const blocks = this.l2Blocks.filter(b => {
|
|
101
|
-
const slot = b.header.globalVariables.slotNumber
|
|
190
|
+
const slot = b.header.globalVariables.slotNumber;
|
|
102
191
|
return slot >= start && slot <= end;
|
|
103
192
|
});
|
|
104
193
|
return Promise.resolve(blocks);
|
|
105
194
|
}
|
|
106
195
|
|
|
196
|
+
async getBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
197
|
+
const blocks = await this.getBlocksForEpoch(epochNumber);
|
|
198
|
+
return blocks.map(b => b.getBlockHeader());
|
|
199
|
+
}
|
|
200
|
+
|
|
107
201
|
/**
|
|
108
202
|
* Gets a tx effect.
|
|
109
|
-
* @param txHash - The hash of
|
|
110
|
-
* @returns The requested tx effect.
|
|
203
|
+
* @param txHash - The hash of the tx corresponding to the tx effect.
|
|
204
|
+
* @returns The requested tx effect with block info (or undefined if not found).
|
|
111
205
|
*/
|
|
112
206
|
public async getTxEffect(txHash: TxHash) {
|
|
113
207
|
const match = this.l2Blocks
|
|
@@ -117,7 +211,12 @@ export class MockL2BlockSource implements L2BlockSource {
|
|
|
117
211
|
return Promise.resolve(undefined);
|
|
118
212
|
}
|
|
119
213
|
const [txEffect, block] = match;
|
|
120
|
-
return {
|
|
214
|
+
return {
|
|
215
|
+
data: txEffect,
|
|
216
|
+
l2BlockNumber: block.number,
|
|
217
|
+
l2BlockHash: L2BlockHash.fromField(await block.hash()),
|
|
218
|
+
txIndexInBlock: block.body.txEffects.indexOf(txEffect),
|
|
219
|
+
};
|
|
121
220
|
}
|
|
122
221
|
|
|
123
222
|
/**
|
|
@@ -147,7 +246,7 @@ export class MockL2BlockSource implements L2BlockSource {
|
|
|
147
246
|
const [latest, proven, finalized] = [
|
|
148
247
|
await this.getBlockNumber(),
|
|
149
248
|
await this.getProvenBlockNumber(),
|
|
150
|
-
|
|
249
|
+
this.finalizedBlockNumber,
|
|
151
250
|
] as const;
|
|
152
251
|
|
|
153
252
|
const latestBlock = this.l2Blocks[latest - 1];
|
|
@@ -170,19 +269,27 @@ export class MockL2BlockSource implements L2BlockSource {
|
|
|
170
269
|
};
|
|
171
270
|
}
|
|
172
271
|
|
|
173
|
-
getL2EpochNumber(): Promise<
|
|
272
|
+
getL2EpochNumber(): Promise<EpochNumber> {
|
|
174
273
|
throw new Error('Method not implemented.');
|
|
175
274
|
}
|
|
176
275
|
|
|
177
|
-
getL2SlotNumber(): Promise<
|
|
276
|
+
getL2SlotNumber(): Promise<SlotNumber> {
|
|
178
277
|
throw new Error('Method not implemented.');
|
|
179
278
|
}
|
|
180
279
|
|
|
181
|
-
isEpochComplete(_epochNumber:
|
|
280
|
+
isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
|
|
182
281
|
throw new Error('Method not implemented.');
|
|
183
282
|
}
|
|
184
283
|
|
|
185
284
|
getL1Constants(): Promise<L1RollupConstants> {
|
|
285
|
+
return Promise.resolve(EmptyL1RollupConstants);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
|
|
289
|
+
return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
getL1Timestamp(): Promise<bigint> {
|
|
186
293
|
throw new Error('Method not implemented.');
|
|
187
294
|
}
|
|
188
295
|
|
|
@@ -191,6 +298,7 @@ export class MockL2BlockSource implements L2BlockSource {
|
|
|
191
298
|
* @returns A promise that signals the initialization of the l2 block source on completion.
|
|
192
299
|
*/
|
|
193
300
|
public start(): Promise<void> {
|
|
301
|
+
this.log.verbose('Starting mock L2 block source');
|
|
194
302
|
return Promise.resolve();
|
|
195
303
|
}
|
|
196
304
|
|
|
@@ -199,6 +307,43 @@ export class MockL2BlockSource implements L2BlockSource {
|
|
|
199
307
|
* @returns A promise that signals the l2 block source is now stopped.
|
|
200
308
|
*/
|
|
201
309
|
public stop(): Promise<void> {
|
|
310
|
+
this.log.verbose('Stopping mock L2 block source');
|
|
202
311
|
return Promise.resolve();
|
|
203
312
|
}
|
|
313
|
+
|
|
314
|
+
getContractClass(_id: Fr): Promise<ContractClassPublic | undefined> {
|
|
315
|
+
return Promise.resolve(undefined);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
getBytecodeCommitment(_id: Fr): Promise<Fr | undefined> {
|
|
319
|
+
return Promise.resolve(undefined);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
getContract(_address: AztecAddress, _timestamp?: UInt64): Promise<ContractInstanceWithAddress | undefined> {
|
|
323
|
+
return Promise.resolve(undefined);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
getContractClassIds(): Promise<Fr[]> {
|
|
327
|
+
return Promise.resolve([]);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
getDebugFunctionName(_address: AztecAddress, _selector: FunctionSelector): Promise<string | undefined> {
|
|
331
|
+
return Promise.resolve(undefined);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
registerContractFunctionSignatures(_signatures: string[]): Promise<void> {
|
|
335
|
+
return Promise.resolve();
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
syncImmediate(): Promise<void> {
|
|
339
|
+
return Promise.resolve();
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
isPendingChainInvalid(): Promise<boolean> {
|
|
343
|
+
return Promise.resolve(false);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
getPendingChainValidationStatus(): Promise<ValidateBlockResult> {
|
|
347
|
+
return Promise.resolve({ valid: true });
|
|
348
|
+
}
|
|
204
349
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
+
import { randomBigInt, randomInt } from '@aztec/foundation/crypto';
|
|
3
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
4
|
+
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
5
|
+
|
|
6
|
+
import { type InboxMessage, updateRollingHash } from '../archiver/structs/inbox_message.js';
|
|
7
|
+
|
|
8
|
+
export function makeInboxMessage(
|
|
9
|
+
previousRollingHash = Buffer16.ZERO,
|
|
10
|
+
overrides: Partial<InboxMessage> = {},
|
|
11
|
+
): InboxMessage {
|
|
12
|
+
const { l2BlockNumber = randomInt(100) + 1 } = overrides;
|
|
13
|
+
const { l1BlockNumber = randomBigInt(100n) + 1n } = overrides;
|
|
14
|
+
const { l1BlockHash = Buffer32.random() } = overrides;
|
|
15
|
+
const { leaf = Fr.random() } = overrides;
|
|
16
|
+
const { rollingHash = updateRollingHash(previousRollingHash, leaf) } = overrides;
|
|
17
|
+
const { index = InboxLeaf.smallestIndexFromL2Block(l2BlockNumber) } = overrides;
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
index,
|
|
21
|
+
leaf,
|
|
22
|
+
l2BlockNumber,
|
|
23
|
+
l1BlockNumber,
|
|
24
|
+
l1BlockHash,
|
|
25
|
+
rollingHash,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function makeInboxMessages(
|
|
30
|
+
count: number,
|
|
31
|
+
opts: {
|
|
32
|
+
initialHash?: Buffer16;
|
|
33
|
+
initialL2BlockNumber?: number;
|
|
34
|
+
overrideFn?: (msg: InboxMessage, index: number) => InboxMessage;
|
|
35
|
+
} = {},
|
|
36
|
+
): InboxMessage[] {
|
|
37
|
+
const { initialHash = Buffer16.ZERO, overrideFn = msg => msg, initialL2BlockNumber = 1 } = opts;
|
|
38
|
+
const messages: InboxMessage[] = [];
|
|
39
|
+
let rollingHash = initialHash;
|
|
40
|
+
for (let i = 0; i < count; i++) {
|
|
41
|
+
const leaf = Fr.random();
|
|
42
|
+
const l2BlockNumber = i + initialL2BlockNumber;
|
|
43
|
+
const message = overrideFn(makeInboxMessage(rollingHash, { leaf, l2BlockNumber }), i);
|
|
44
|
+
rollingHash = message.rollingHash;
|
|
45
|
+
messages.push(message);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return messages;
|
|
49
|
+
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
3
|
-
import type { InBlock, L2Block } from '@aztec/stdlib/block';
|
|
4
|
-
export declare class NullifierStore {
|
|
5
|
-
#private;
|
|
6
|
-
private db;
|
|
7
|
-
constructor(db: AztecAsyncKVStore);
|
|
8
|
-
addNullifiers(blocks: L2Block[]): Promise<boolean>;
|
|
9
|
-
deleteNullifiers(blocks: L2Block[]): Promise<boolean>;
|
|
10
|
-
findNullifiersIndexesWithBlock(blockNumber: number, nullifiers: Fr[]): Promise<(InBlock<bigint> | undefined)[]>;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=nullifier_store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nullifier_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/kv_archiver_store/nullifier_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE5D,qBAAa,cAAc;;IAMb,OAAO,CAAC,EAAE;gBAAF,EAAE,EAAE,iBAAiB;IAMnC,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IA0BlD,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAerD,8BAA8B,CAClC,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,EAAE,EAAE,GACf,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC;CAkC5C"}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { MAX_NULLIFIERS_PER_TX } from '@aztec/constants';
|
|
2
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
export class NullifierStore {
|
|
4
|
-
db;
|
|
5
|
-
#nullifiersToBlockNumber;
|
|
6
|
-
#nullifiersToBlockHash;
|
|
7
|
-
#nullifiersToIndex;
|
|
8
|
-
#log;
|
|
9
|
-
constructor(db){
|
|
10
|
-
this.db = db;
|
|
11
|
-
this.#log = createLogger('archiver:log_store');
|
|
12
|
-
this.#nullifiersToBlockNumber = db.openMap('archiver_nullifiers_to_block_number');
|
|
13
|
-
this.#nullifiersToBlockHash = db.openMap('archiver_nullifiers_to_block_hash');
|
|
14
|
-
this.#nullifiersToIndex = db.openMap('archiver_nullifiers_to_index');
|
|
15
|
-
}
|
|
16
|
-
async addNullifiers(blocks) {
|
|
17
|
-
const blockHashes = await Promise.all(blocks.map((block)=>block.hash()));
|
|
18
|
-
await this.db.transactionAsync(async ()=>{
|
|
19
|
-
await Promise.all(blocks.map((block, i)=>{
|
|
20
|
-
const dataStartIndexForBlock = block.header.state.partial.nullifierTree.nextAvailableLeafIndex - block.body.txEffects.length * MAX_NULLIFIERS_PER_TX;
|
|
21
|
-
return Promise.all(block.body.txEffects.map((txEffects, txIndex)=>{
|
|
22
|
-
const dataStartIndexForTx = dataStartIndexForBlock + txIndex * MAX_NULLIFIERS_PER_TX;
|
|
23
|
-
return Promise.all(txEffects.nullifiers.map(async (nullifier, nullifierIndex)=>{
|
|
24
|
-
await this.#nullifiersToBlockNumber.set(nullifier.toString(), block.number);
|
|
25
|
-
await this.#nullifiersToBlockHash.set(nullifier.toString(), blockHashes[i].toString());
|
|
26
|
-
await this.#nullifiersToIndex.set(nullifier.toString(), dataStartIndexForTx + nullifierIndex);
|
|
27
|
-
}));
|
|
28
|
-
}));
|
|
29
|
-
}));
|
|
30
|
-
});
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
async deleteNullifiers(blocks) {
|
|
34
|
-
await this.db.transactionAsync(async ()=>{
|
|
35
|
-
for (const block of blocks){
|
|
36
|
-
for (const nullifier of block.body.txEffects.flatMap((tx)=>tx.nullifiers)){
|
|
37
|
-
await Promise.all([
|
|
38
|
-
this.#nullifiersToBlockNumber.delete(nullifier.toString()),
|
|
39
|
-
this.#nullifiersToBlockHash.delete(nullifier.toString()),
|
|
40
|
-
this.#nullifiersToIndex.delete(nullifier.toString())
|
|
41
|
-
]);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
async findNullifiersIndexesWithBlock(blockNumber, nullifiers) {
|
|
48
|
-
const asStrings = nullifiers.map((x)=>x.toString());
|
|
49
|
-
const maybeNullifiers = await Promise.all(asStrings.map(async (nullifier)=>{
|
|
50
|
-
const [data, l2BlockNumber, l2BlockHash] = await Promise.all([
|
|
51
|
-
this.#nullifiersToIndex.getAsync(nullifier),
|
|
52
|
-
this.#nullifiersToBlockNumber.getAsync(nullifier),
|
|
53
|
-
this.#nullifiersToBlockHash.getAsync(nullifier)
|
|
54
|
-
]);
|
|
55
|
-
return {
|
|
56
|
-
data,
|
|
57
|
-
l2BlockNumber,
|
|
58
|
-
l2BlockHash
|
|
59
|
-
};
|
|
60
|
-
}));
|
|
61
|
-
return maybeNullifiers.map(({ data, l2BlockNumber, l2BlockHash })=>{
|
|
62
|
-
if (data === undefined || l2BlockNumber === undefined || l2BlockHash === undefined || l2BlockNumber > blockNumber) {
|
|
63
|
-
return undefined;
|
|
64
|
-
} else {
|
|
65
|
-
return {
|
|
66
|
-
data: BigInt(data),
|
|
67
|
-
l2BlockNumber,
|
|
68
|
-
l2BlockHash
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
3
|
-
/**
|
|
4
|
-
* A simple in-memory implementation of an L1 to L2 message store.
|
|
5
|
-
*/
|
|
6
|
-
export declare class L1ToL2MessageStore {
|
|
7
|
-
#private;
|
|
8
|
-
/**
|
|
9
|
-
* A map pointing from a key in a "messageIndex" format to the corresponding L1 to L2 message hash.
|
|
10
|
-
*/
|
|
11
|
-
protected store: Map<string, Fr>;
|
|
12
|
-
constructor();
|
|
13
|
-
getTotalL1ToL2MessageCount(): bigint;
|
|
14
|
-
addMessage(message: InboxLeaf): void;
|
|
15
|
-
getMessages(blockNumber: bigint): Fr[];
|
|
16
|
-
/**
|
|
17
|
-
* Gets the L1 to L2 message index in the L1 to L2 message tree.
|
|
18
|
-
* @param l1ToL2Message - The L1 to L2 message.
|
|
19
|
-
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
|
|
20
|
-
*/
|
|
21
|
-
getMessageIndex(l1ToL2Message: Fr): bigint | undefined;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=l1_to_l2_message_store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"l1_to_l2_message_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/memory_archiver_store/l1_to_l2_message_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD;;GAEG;AACH,qBAAa,kBAAkB;;IAC7B;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,CAAa;;IAM7C,0BAA0B,IAAI,MAAM;IAIpC,UAAU,CAAC,OAAO,EAAE,SAAS;IAI7B,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,EAAE,EAAE;IAsBtC;;;;OAIG;IACH,eAAe,CAAC,aAAa,EAAE,EAAE,GAAG,MAAM,GAAG,SAAS;CAQvD"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { L1_TO_L2_MSG_SUBTREE_HEIGHT } from '@aztec/constants';
|
|
2
|
-
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
3
|
-
/**
|
|
4
|
-
* A simple in-memory implementation of an L1 to L2 message store.
|
|
5
|
-
*/ export class L1ToL2MessageStore {
|
|
6
|
-
/**
|
|
7
|
-
* A map pointing from a key in a "messageIndex" format to the corresponding L1 to L2 message hash.
|
|
8
|
-
*/ store = new Map();
|
|
9
|
-
#l1ToL2MessagesSubtreeSize = 2 ** L1_TO_L2_MSG_SUBTREE_HEIGHT;
|
|
10
|
-
constructor(){}
|
|
11
|
-
getTotalL1ToL2MessageCount() {
|
|
12
|
-
return BigInt(this.store.size);
|
|
13
|
-
}
|
|
14
|
-
addMessage(message) {
|
|
15
|
-
this.store.set(`${message.index}`, message.leaf);
|
|
16
|
-
}
|
|
17
|
-
getMessages(blockNumber) {
|
|
18
|
-
const messages = [];
|
|
19
|
-
let undefinedMessageFound = false;
|
|
20
|
-
const startIndex = Number(InboxLeaf.smallestIndexFromL2Block(blockNumber));
|
|
21
|
-
for(let i = startIndex; i < startIndex + this.#l1ToL2MessagesSubtreeSize; i++){
|
|
22
|
-
// This is inefficient but probably fine for now.
|
|
23
|
-
const message = this.store.get(`${i}`);
|
|
24
|
-
if (message) {
|
|
25
|
-
if (undefinedMessageFound) {
|
|
26
|
-
throw new Error(`L1 to L2 message gap found in block ${blockNumber}`);
|
|
27
|
-
}
|
|
28
|
-
messages.push(message);
|
|
29
|
-
} else {
|
|
30
|
-
undefinedMessageFound = true;
|
|
31
|
-
// We continue iterating over messages here to verify that there are no more messages after the undefined one.
|
|
32
|
-
// --> If this was the case this would imply there is some issue with log fetching.
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return messages;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Gets the L1 to L2 message index in the L1 to L2 message tree.
|
|
39
|
-
* @param l1ToL2Message - The L1 to L2 message.
|
|
40
|
-
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
|
|
41
|
-
*/ getMessageIndex(l1ToL2Message) {
|
|
42
|
-
for (const [key, message] of this.store.entries()){
|
|
43
|
-
if (message.equals(l1ToL2Message)) {
|
|
44
|
-
return BigInt(key);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
}
|