@aztec/archiver 0.0.1-commit.e61ad554 → 0.0.1-commit.ec5f612
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.d.ts +7 -3
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +24 -93
- package/dest/factory.d.ts +3 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +11 -10
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/l1/bin/retrieve-calldata.js +36 -33
- package/dest/l1/calldata_retriever.d.ts +73 -50
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +190 -259
- package/dest/l1/data_retrieval.d.ts +9 -9
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +22 -20
- package/dest/l1/spire_proposer.d.ts +5 -5
- package/dest/l1/spire_proposer.d.ts.map +1 -1
- package/dest/l1/spire_proposer.js +9 -17
- package/dest/l1/validate_trace.d.ts +6 -3
- package/dest/l1/validate_trace.d.ts.map +1 -1
- package/dest/l1/validate_trace.js +13 -9
- package/dest/modules/data_source_base.d.ts +11 -6
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +28 -72
- package/dest/modules/data_store_updater.d.ts +9 -2
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +40 -19
- package/dest/modules/instrumentation.d.ts +15 -2
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +36 -12
- package/dest/modules/l1_synchronizer.d.ts +4 -8
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +16 -12
- package/dest/store/block_store.d.ts +21 -17
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +71 -19
- package/dest/store/contract_class_store.d.ts +1 -1
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +11 -7
- package/dest/store/kv_archiver_store.d.ts +21 -7
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +20 -3
- package/dest/store/l2_tips_cache.d.ts +19 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +89 -0
- package/dest/store/log_store.d.ts +1 -1
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +57 -37
- package/dest/test/fake_l1_state.d.ts +6 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +56 -18
- package/dest/test/index.js +3 -1
- package/dest/test/mock_archiver.d.ts +1 -1
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +3 -2
- package/dest/test/mock_l2_block_source.d.ts +22 -7
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +127 -84
- package/dest/test/mock_structs.d.ts +3 -2
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +7 -5
- package/dest/test/noop_l1_archiver.d.ts +23 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +68 -0
- package/package.json +14 -13
- package/src/archiver.ts +32 -112
- package/src/factory.ts +26 -12
- package/src/index.ts +1 -0
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +46 -39
- package/src/l1/calldata_retriever.ts +249 -379
- package/src/l1/data_retrieval.ts +24 -26
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_trace.ts +24 -6
- package/src/modules/data_source_base.ts +56 -95
- package/src/modules/data_store_updater.ts +43 -18
- package/src/modules/instrumentation.ts +44 -12
- package/src/modules/l1_synchronizer.ts +17 -15
- package/src/store/block_store.ts +90 -41
- package/src/store/contract_class_store.ts +11 -7
- package/src/store/kv_archiver_store.ts +40 -8
- package/src/store/l2_tips_cache.ts +89 -0
- package/src/store/log_store.ts +98 -36
- package/src/test/fake_l1_state.ts +75 -17
- package/src/test/index.ts +3 -0
- package/src/test/mock_archiver.ts +3 -2
- package/src/test/mock_l2_block_source.ts +164 -84
- package/src/test/mock_structs.ts +22 -6
- package/src/test/noop_l1_archiver.ts +109 -0
|
@@ -8,16 +8,19 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
8
8
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
9
9
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
10
|
import {
|
|
11
|
+
type BlockData,
|
|
12
|
+
BlockHash,
|
|
11
13
|
CheckpointedL2Block,
|
|
12
14
|
L2Block,
|
|
13
|
-
L2BlockHash,
|
|
14
15
|
type L2BlockSource,
|
|
15
16
|
type L2Tips,
|
|
16
17
|
type ValidateCheckpointResult,
|
|
17
18
|
} from '@aztec/stdlib/block';
|
|
18
|
-
import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
19
|
+
import { Checkpoint, type CheckpointData, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
19
20
|
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
20
21
|
import { EmptyL1RollupConstants, type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
22
|
+
import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
|
|
23
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
21
24
|
import { type BlockHeader, TxExecutionResult, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
22
25
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
23
26
|
|
|
@@ -26,6 +29,7 @@ import type { UInt64 } from '@aztec/stdlib/types';
|
|
|
26
29
|
*/
|
|
27
30
|
export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
28
31
|
protected l2Blocks: L2Block[] = [];
|
|
32
|
+
protected checkpointList: Checkpoint[] = [];
|
|
29
33
|
|
|
30
34
|
private provenBlockNumber: number = 0;
|
|
31
35
|
private finalizedBlockNumber: number = 0;
|
|
@@ -33,14 +37,30 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
33
37
|
|
|
34
38
|
private log = createLogger('archiver:mock_l2_block_source');
|
|
35
39
|
|
|
40
|
+
/** Creates blocks grouped into single-block checkpoints. */
|
|
36
41
|
public async createBlocks(numBlocks: number) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
await this.createCheckpoints(numBlocks, 1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Creates checkpoints, each containing `blocksPerCheckpoint` blocks. */
|
|
46
|
+
public async createCheckpoints(numCheckpoints: number, blocksPerCheckpoint: number = 1) {
|
|
47
|
+
for (let c = 0; c < numCheckpoints; c++) {
|
|
48
|
+
const checkpointNum = CheckpointNumber(this.checkpointList.length + 1);
|
|
49
|
+
const startBlockNum = this.l2Blocks.length + 1;
|
|
50
|
+
const slotNumber = SlotNumber(Number(checkpointNum));
|
|
51
|
+
const checkpoint = await Checkpoint.random(checkpointNum, {
|
|
52
|
+
numBlocks: blocksPerCheckpoint,
|
|
53
|
+
startBlockNumber: startBlockNum,
|
|
54
|
+
slotNumber,
|
|
55
|
+
checkpointNumber: checkpointNum,
|
|
56
|
+
});
|
|
57
|
+
this.checkpointList.push(checkpoint);
|
|
58
|
+
this.l2Blocks.push(...checkpoint.blocks);
|
|
41
59
|
}
|
|
42
60
|
|
|
43
|
-
this.log.verbose(
|
|
61
|
+
this.log.verbose(
|
|
62
|
+
`Created ${numCheckpoints} checkpoints with ${blocksPerCheckpoint} blocks each in the mock L2 block source`,
|
|
63
|
+
);
|
|
44
64
|
}
|
|
45
65
|
|
|
46
66
|
public addProposedBlocks(blocks: L2Block[]) {
|
|
@@ -50,6 +70,16 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
50
70
|
|
|
51
71
|
public removeBlocks(numBlocks: number) {
|
|
52
72
|
this.l2Blocks = this.l2Blocks.slice(0, -numBlocks);
|
|
73
|
+
const maxBlockNum = this.l2Blocks.length;
|
|
74
|
+
// Remove any checkpoint whose last block is beyond the remaining blocks.
|
|
75
|
+
this.checkpointList = this.checkpointList.filter(c => {
|
|
76
|
+
const lastBlockNum = c.blocks[0].number + c.blocks.length - 1;
|
|
77
|
+
return lastBlockNum <= maxBlockNum;
|
|
78
|
+
});
|
|
79
|
+
// Keep tip numbers consistent with remaining blocks.
|
|
80
|
+
this.checkpointedBlockNumber = Math.min(this.checkpointedBlockNumber, maxBlockNum);
|
|
81
|
+
this.provenBlockNumber = Math.min(this.provenBlockNumber, maxBlockNum);
|
|
82
|
+
this.finalizedBlockNumber = Math.min(this.finalizedBlockNumber, maxBlockNum);
|
|
53
83
|
this.log.verbose(`Removed ${numBlocks} blocks from the mock L2 block source`);
|
|
54
84
|
}
|
|
55
85
|
|
|
@@ -65,7 +95,33 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
65
95
|
}
|
|
66
96
|
|
|
67
97
|
public setCheckpointedBlockNumber(checkpointedBlockNumber: number) {
|
|
98
|
+
const prevCheckpointed = this.checkpointedBlockNumber;
|
|
68
99
|
this.checkpointedBlockNumber = checkpointedBlockNumber;
|
|
100
|
+
// Auto-create single-block checkpoints for newly checkpointed blocks that don't have one yet.
|
|
101
|
+
// This handles blocks added via addProposedBlocks that are now being marked as checkpointed.
|
|
102
|
+
const newCheckpoints: Checkpoint[] = [];
|
|
103
|
+
for (let blockNum = prevCheckpointed + 1; blockNum <= checkpointedBlockNumber; blockNum++) {
|
|
104
|
+
const block = this.l2Blocks[blockNum - 1];
|
|
105
|
+
if (!block) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (this.checkpointList.some(c => c.blocks.some(b => b.number === block.number))) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const checkpointNum = CheckpointNumber(this.checkpointList.length + newCheckpoints.length + 1);
|
|
112
|
+
const checkpoint = new Checkpoint(
|
|
113
|
+
block.archive,
|
|
114
|
+
CheckpointHeader.random({ slotNumber: block.header.globalVariables.slotNumber }),
|
|
115
|
+
[block],
|
|
116
|
+
checkpointNum,
|
|
117
|
+
);
|
|
118
|
+
newCheckpoints.push(checkpoint);
|
|
119
|
+
}
|
|
120
|
+
// Insert new checkpoints in order by number.
|
|
121
|
+
if (newCheckpoints.length > 0) {
|
|
122
|
+
this.checkpointList.push(...newCheckpoints);
|
|
123
|
+
this.checkpointList.sort((a, b) => a.number - b.number);
|
|
124
|
+
}
|
|
69
125
|
}
|
|
70
126
|
|
|
71
127
|
/**
|
|
@@ -112,13 +168,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
112
168
|
if (!block) {
|
|
113
169
|
return Promise.resolve(undefined);
|
|
114
170
|
}
|
|
115
|
-
|
|
116
|
-
CheckpointNumber.fromBlockNumber(number),
|
|
117
|
-
block,
|
|
118
|
-
new L1PublishedData(BigInt(number), BigInt(number), `0x${number.toString(16).padStart(64, '0')}`),
|
|
119
|
-
[],
|
|
120
|
-
);
|
|
121
|
-
return Promise.resolve(checkpointedBlock);
|
|
171
|
+
return Promise.resolve(this.toCheckpointedBlock(block));
|
|
122
172
|
}
|
|
123
173
|
|
|
124
174
|
public async getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
|
|
@@ -167,44 +217,22 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
167
217
|
}
|
|
168
218
|
|
|
169
219
|
public getCheckpoints(from: CheckpointNumber, limit: number) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
blocks.map(async block => {
|
|
174
|
-
// Create a checkpoint from the block - manually construct since L2Block doesn't have toCheckpoint()
|
|
175
|
-
const checkpoint = await Checkpoint.random(block.checkpointNumber, { numBlocks: 1 });
|
|
176
|
-
checkpoint.blocks = [block];
|
|
177
|
-
return new PublishedCheckpoint(
|
|
178
|
-
checkpoint,
|
|
179
|
-
new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
180
|
-
[],
|
|
181
|
-
);
|
|
182
|
-
}),
|
|
220
|
+
const checkpoints = this.checkpointList.slice(from - 1, from - 1 + limit);
|
|
221
|
+
return Promise.resolve(
|
|
222
|
+
checkpoints.map(checkpoint => new PublishedCheckpoint(checkpoint, this.mockL1DataForCheckpoint(checkpoint), [])),
|
|
183
223
|
);
|
|
184
224
|
}
|
|
185
225
|
|
|
186
|
-
public
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (!block) {
|
|
190
|
-
return undefined;
|
|
191
|
-
}
|
|
192
|
-
// Create a checkpoint from the block - manually construct since L2Block doesn't have toCheckpoint()
|
|
193
|
-
const checkpoint = await Checkpoint.random(block.checkpointNumber, { numBlocks: 1 });
|
|
194
|
-
checkpoint.blocks = [block];
|
|
195
|
-
return checkpoint;
|
|
226
|
+
public getCheckpointByArchive(archive: Fr): Promise<Checkpoint | undefined> {
|
|
227
|
+
const checkpoint = this.checkpointList.find(c => c.archive.root.equals(archive));
|
|
228
|
+
return Promise.resolve(checkpoint);
|
|
196
229
|
}
|
|
197
230
|
|
|
198
|
-
public async getCheckpointedBlockByHash(blockHash:
|
|
231
|
+
public async getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
|
|
199
232
|
for (const block of this.l2Blocks) {
|
|
200
233
|
const hash = await block.hash();
|
|
201
234
|
if (hash.equals(blockHash)) {
|
|
202
|
-
return
|
|
203
|
-
checkpointNumber: CheckpointNumber.fromBlockNumber(block.number),
|
|
204
|
-
block,
|
|
205
|
-
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
206
|
-
attestations: [],
|
|
207
|
-
});
|
|
235
|
+
return this.toCheckpointedBlock(block);
|
|
208
236
|
}
|
|
209
237
|
}
|
|
210
238
|
return undefined;
|
|
@@ -215,17 +243,10 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
215
243
|
if (!block) {
|
|
216
244
|
return Promise.resolve(undefined);
|
|
217
245
|
}
|
|
218
|
-
return Promise.resolve(
|
|
219
|
-
CheckpointedL2Block.fromFields({
|
|
220
|
-
checkpointNumber: CheckpointNumber.fromBlockNumber(block.number),
|
|
221
|
-
block,
|
|
222
|
-
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
223
|
-
attestations: [],
|
|
224
|
-
}),
|
|
225
|
-
);
|
|
246
|
+
return Promise.resolve(this.toCheckpointedBlock(block));
|
|
226
247
|
}
|
|
227
248
|
|
|
228
|
-
public async getL2BlockByHash(blockHash:
|
|
249
|
+
public async getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
229
250
|
for (const block of this.l2Blocks) {
|
|
230
251
|
const hash = await block.hash();
|
|
231
252
|
if (hash.equals(blockHash)) {
|
|
@@ -240,7 +261,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
240
261
|
return Promise.resolve(block);
|
|
241
262
|
}
|
|
242
263
|
|
|
243
|
-
public async getBlockHeaderByHash(blockHash:
|
|
264
|
+
public async getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
|
|
244
265
|
for (const block of this.l2Blocks) {
|
|
245
266
|
const hash = await block.hash();
|
|
246
267
|
if (hash.equals(blockHash)) {
|
|
@@ -255,47 +276,69 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
255
276
|
return Promise.resolve(block?.header);
|
|
256
277
|
}
|
|
257
278
|
|
|
279
|
+
public async getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
280
|
+
const block = this.l2Blocks[number - 1];
|
|
281
|
+
if (!block) {
|
|
282
|
+
return undefined;
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
header: block.header,
|
|
286
|
+
archive: block.archive,
|
|
287
|
+
blockHash: await block.hash(),
|
|
288
|
+
checkpointNumber: block.checkpointNumber,
|
|
289
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
public async getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
294
|
+
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
295
|
+
if (!block) {
|
|
296
|
+
return undefined;
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
header: block.header,
|
|
300
|
+
archive: block.archive,
|
|
301
|
+
blockHash: await block.hash(),
|
|
302
|
+
checkpointNumber: block.checkpointNumber,
|
|
303
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
258
307
|
getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
259
308
|
return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.header);
|
|
260
309
|
}
|
|
261
310
|
|
|
262
311
|
getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
|
|
263
|
-
|
|
264
|
-
const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
|
|
265
|
-
const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
|
|
266
|
-
const blocks = this.l2Blocks.filter(b => {
|
|
267
|
-
const slot = b.header.globalVariables.slotNumber;
|
|
268
|
-
return slot >= start && slot <= end;
|
|
269
|
-
});
|
|
270
|
-
// Create checkpoints from blocks - manually construct since L2Block doesn't have toCheckpoint()
|
|
271
|
-
return Promise.all(
|
|
272
|
-
blocks.map(async block => {
|
|
273
|
-
const checkpoint = await Checkpoint.random(block.checkpointNumber, { numBlocks: 1 });
|
|
274
|
-
checkpoint.blocks = [block];
|
|
275
|
-
return checkpoint;
|
|
276
|
-
}),
|
|
277
|
-
);
|
|
312
|
+
return Promise.resolve(this.getCheckpointsInEpoch(epochNumber));
|
|
278
313
|
}
|
|
279
314
|
|
|
280
|
-
|
|
281
|
-
const
|
|
282
|
-
const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
|
|
283
|
-
const blocks = this.l2Blocks.filter(b => {
|
|
284
|
-
const slot = b.header.globalVariables.slotNumber;
|
|
285
|
-
return slot >= start && slot <= end;
|
|
286
|
-
});
|
|
315
|
+
getCheckpointsDataForEpoch(epochNumber: EpochNumber): Promise<CheckpointData[]> {
|
|
316
|
+
const checkpoints = this.getCheckpointsInEpoch(epochNumber);
|
|
287
317
|
return Promise.resolve(
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
checkpointNumber:
|
|
291
|
-
|
|
292
|
-
|
|
318
|
+
checkpoints.map(
|
|
319
|
+
(checkpoint): CheckpointData => ({
|
|
320
|
+
checkpointNumber: checkpoint.number,
|
|
321
|
+
header: checkpoint.header,
|
|
322
|
+
archive: checkpoint.archive,
|
|
323
|
+
checkpointOutHash: computeCheckpointOutHash(
|
|
324
|
+
checkpoint.blocks.map(b => b.body.txEffects.map(tx => tx.l2ToL1Msgs)),
|
|
325
|
+
),
|
|
326
|
+
startBlock: checkpoint.blocks[0].number,
|
|
327
|
+
blockCount: checkpoint.blocks.length,
|
|
293
328
|
attestations: [],
|
|
329
|
+
l1: this.mockL1DataForCheckpoint(checkpoint),
|
|
294
330
|
}),
|
|
295
331
|
),
|
|
296
332
|
);
|
|
297
333
|
}
|
|
298
334
|
|
|
335
|
+
getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]> {
|
|
336
|
+
const checkpoints = this.getCheckpointsInEpoch(epochNumber);
|
|
337
|
+
return Promise.resolve(
|
|
338
|
+
checkpoints.flatMap(checkpoint => checkpoint.blocks.map(block => this.toCheckpointedBlock(block))),
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
|
|
299
342
|
getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
|
|
300
343
|
const blocks = this.l2Blocks.filter(b => b.header.globalVariables.slotNumber === slotNumber);
|
|
301
344
|
return Promise.resolve(blocks);
|
|
@@ -322,7 +365,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
322
365
|
return {
|
|
323
366
|
data: txEffect,
|
|
324
367
|
l2BlockNumber: block.number,
|
|
325
|
-
l2BlockHash:
|
|
368
|
+
l2BlockHash: await block.hash(),
|
|
326
369
|
txIndexInBlock: block.body.txEffects.indexOf(txEffect),
|
|
327
370
|
};
|
|
328
371
|
}
|
|
@@ -343,7 +386,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
343
386
|
TxExecutionResult.SUCCESS,
|
|
344
387
|
undefined,
|
|
345
388
|
txEffect.transactionFee.toBigInt(),
|
|
346
|
-
|
|
389
|
+
await block.hash(),
|
|
347
390
|
block.number,
|
|
348
391
|
);
|
|
349
392
|
}
|
|
@@ -384,7 +427,10 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
384
427
|
|
|
385
428
|
const makeTipId = (blockId: typeof latestBlockId) => ({
|
|
386
429
|
block: blockId,
|
|
387
|
-
checkpoint: {
|
|
430
|
+
checkpoint: {
|
|
431
|
+
number: this.findCheckpointNumberForBlock(blockId.number) ?? CheckpointNumber(0),
|
|
432
|
+
hash: blockId.hash,
|
|
433
|
+
},
|
|
388
434
|
});
|
|
389
435
|
|
|
390
436
|
return {
|
|
@@ -472,4 +518,38 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
472
518
|
getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
|
|
473
519
|
return Promise.resolve({ valid: true });
|
|
474
520
|
}
|
|
521
|
+
|
|
522
|
+
/** Returns checkpoints whose slot falls within the given epoch. */
|
|
523
|
+
private getCheckpointsInEpoch(epochNumber: EpochNumber): Checkpoint[] {
|
|
524
|
+
const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
|
|
525
|
+
const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
|
|
526
|
+
return this.checkpointList.filter(c => c.header.slotNumber >= start && c.header.slotNumber <= end);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** Creates a mock L1PublishedData for a checkpoint. */
|
|
530
|
+
private mockL1DataForCheckpoint(checkpoint: Checkpoint): L1PublishedData {
|
|
531
|
+
return new L1PublishedData(BigInt(checkpoint.number), BigInt(checkpoint.number), Buffer32.random().toString());
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/** Creates a CheckpointedL2Block from a block using stored checkpoint info. */
|
|
535
|
+
private toCheckpointedBlock(block: L2Block): CheckpointedL2Block {
|
|
536
|
+
const checkpoint = this.checkpointList.find(c => c.blocks.some(b => b.number === block.number));
|
|
537
|
+
const checkpointNumber = checkpoint?.number ?? block.checkpointNumber;
|
|
538
|
+
return new CheckpointedL2Block(
|
|
539
|
+
checkpointNumber,
|
|
540
|
+
block,
|
|
541
|
+
new L1PublishedData(
|
|
542
|
+
BigInt(block.number),
|
|
543
|
+
BigInt(block.number),
|
|
544
|
+
`0x${block.number.toString(16).padStart(64, '0')}`,
|
|
545
|
+
),
|
|
546
|
+
[],
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/** Finds the checkpoint number for a block, or undefined if the block is not in any checkpoint. */
|
|
551
|
+
private findCheckpointNumberForBlock(blockNumber: BlockNumber): CheckpointNumber | undefined {
|
|
552
|
+
const checkpoint = this.checkpointList.find(c => c.blocks.some(b => b.number === blockNumber));
|
|
553
|
+
return checkpoint?.number;
|
|
554
|
+
}
|
|
475
555
|
}
|
package/src/test/mock_structs.ts
CHANGED
|
@@ -46,24 +46,40 @@ export function makeInboxMessage(
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export function makeInboxMessages(
|
|
49
|
-
|
|
49
|
+
totalCount: number,
|
|
50
50
|
opts: {
|
|
51
51
|
initialHash?: Buffer16;
|
|
52
52
|
initialCheckpointNumber?: CheckpointNumber;
|
|
53
|
+
messagesPerCheckpoint?: number;
|
|
53
54
|
overrideFn?: (msg: InboxMessage, index: number) => InboxMessage;
|
|
54
55
|
} = {},
|
|
55
56
|
): InboxMessage[] {
|
|
56
|
-
const {
|
|
57
|
+
const {
|
|
58
|
+
initialHash = Buffer16.ZERO,
|
|
59
|
+
overrideFn = msg => msg,
|
|
60
|
+
initialCheckpointNumber = CheckpointNumber(1),
|
|
61
|
+
messagesPerCheckpoint = 1,
|
|
62
|
+
} = opts;
|
|
63
|
+
|
|
57
64
|
const messages: InboxMessage[] = [];
|
|
58
65
|
let rollingHash = initialHash;
|
|
59
|
-
for (let i = 0; i <
|
|
66
|
+
for (let i = 0; i < totalCount; i++) {
|
|
67
|
+
const msgIndex = i % messagesPerCheckpoint;
|
|
68
|
+
const checkpointNumber = CheckpointNumber.fromBigInt(
|
|
69
|
+
BigInt(initialCheckpointNumber) + BigInt(i) / BigInt(messagesPerCheckpoint),
|
|
70
|
+
);
|
|
60
71
|
const leaf = Fr.random();
|
|
61
|
-
const
|
|
62
|
-
|
|
72
|
+
const message = overrideFn(
|
|
73
|
+
makeInboxMessage(rollingHash, {
|
|
74
|
+
leaf,
|
|
75
|
+
checkpointNumber,
|
|
76
|
+
index: InboxLeaf.smallestIndexForCheckpoint(checkpointNumber) + BigInt(msgIndex),
|
|
77
|
+
}),
|
|
78
|
+
i,
|
|
79
|
+
);
|
|
63
80
|
rollingHash = message.rollingHash;
|
|
64
81
|
messages.push(message);
|
|
65
82
|
}
|
|
66
|
-
|
|
67
83
|
return messages;
|
|
68
84
|
}
|
|
69
85
|
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
2
|
+
import type { RollupContract } from '@aztec/ethereum/contracts';
|
|
3
|
+
import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
|
|
4
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
7
|
+
import type { FunctionsOf } from '@aztec/foundation/types';
|
|
8
|
+
import type { ArchiverEmitter } from '@aztec/stdlib/block';
|
|
9
|
+
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
10
|
+
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
11
|
+
|
|
12
|
+
import { mock } from 'jest-mock-extended';
|
|
13
|
+
import { EventEmitter } from 'node:events';
|
|
14
|
+
|
|
15
|
+
import { Archiver } from '../archiver.js';
|
|
16
|
+
import { ArchiverInstrumentation } from '../modules/instrumentation.js';
|
|
17
|
+
import type { ArchiverL1Synchronizer } from '../modules/l1_synchronizer.js';
|
|
18
|
+
import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
|
|
19
|
+
|
|
20
|
+
/** Noop L1 synchronizer for testing without L1 connectivity. */
|
|
21
|
+
class NoopL1Synchronizer implements FunctionsOf<ArchiverL1Synchronizer> {
|
|
22
|
+
public readonly tracer: Tracer;
|
|
23
|
+
|
|
24
|
+
constructor(tracer: Tracer) {
|
|
25
|
+
this.tracer = tracer;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
setConfig(_config: unknown) {}
|
|
29
|
+
getL1BlockNumber(): bigint | undefined {
|
|
30
|
+
return 0n;
|
|
31
|
+
}
|
|
32
|
+
getL1Timestamp(): bigint | undefined {
|
|
33
|
+
return 0n;
|
|
34
|
+
}
|
|
35
|
+
testEthereumNodeSynced(): Promise<void> {
|
|
36
|
+
return Promise.resolve();
|
|
37
|
+
}
|
|
38
|
+
syncFromL1(_initialSyncComplete: boolean): Promise<void> {
|
|
39
|
+
return Promise.resolve();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Archiver with mocked L1 connectivity for testing.
|
|
45
|
+
* Uses mock L1 clients and a noop synchronizer, enabling tests that
|
|
46
|
+
* don't require real Ethereum connectivity.
|
|
47
|
+
*/
|
|
48
|
+
export class NoopL1Archiver extends Archiver {
|
|
49
|
+
constructor(
|
|
50
|
+
dataStore: KVArchiverDataStore,
|
|
51
|
+
l1Constants: L1RollupConstants & { genesisArchiveRoot: Fr },
|
|
52
|
+
instrumentation: ArchiverInstrumentation,
|
|
53
|
+
) {
|
|
54
|
+
// Create mocks for L1 clients
|
|
55
|
+
const publicClient = mock<ViemPublicClient>();
|
|
56
|
+
const debugClient = mock<ViemPublicDebugClient>();
|
|
57
|
+
const rollup = mock<RollupContract>();
|
|
58
|
+
const blobClient = mock<BlobClientInterface>();
|
|
59
|
+
|
|
60
|
+
// Mock methods called during start()
|
|
61
|
+
blobClient.testSources.mockResolvedValue();
|
|
62
|
+
publicClient.getBlockNumber.mockResolvedValue(1n);
|
|
63
|
+
|
|
64
|
+
const events = new EventEmitter() as ArchiverEmitter;
|
|
65
|
+
const synchronizer = new NoopL1Synchronizer(instrumentation.tracer);
|
|
66
|
+
|
|
67
|
+
super(
|
|
68
|
+
publicClient,
|
|
69
|
+
debugClient,
|
|
70
|
+
rollup,
|
|
71
|
+
{
|
|
72
|
+
registryAddress: EthAddress.ZERO,
|
|
73
|
+
governanceProposerAddress: EthAddress.ZERO,
|
|
74
|
+
slashFactoryAddress: EthAddress.ZERO,
|
|
75
|
+
slashingProposerAddress: EthAddress.ZERO,
|
|
76
|
+
},
|
|
77
|
+
dataStore,
|
|
78
|
+
{
|
|
79
|
+
pollingIntervalMs: 1000,
|
|
80
|
+
batchSize: 100,
|
|
81
|
+
skipValidateCheckpointAttestations: true,
|
|
82
|
+
maxAllowedEthClientDriftSeconds: 300,
|
|
83
|
+
ethereumAllowNoDebugHosts: true, // Skip trace validation
|
|
84
|
+
},
|
|
85
|
+
blobClient,
|
|
86
|
+
instrumentation,
|
|
87
|
+
{ ...l1Constants, l1StartBlockHash: Buffer32.random() },
|
|
88
|
+
synchronizer as ArchiverL1Synchronizer,
|
|
89
|
+
events,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Override start to skip L1 validation checks. */
|
|
94
|
+
public override start(_blockUntilSynced?: boolean): Promise<void> {
|
|
95
|
+
// Just start the running promise without L1 checks
|
|
96
|
+
this.runningPromise.start();
|
|
97
|
+
return Promise.resolve();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Creates an archiver with mocked L1 connectivity for testing. */
|
|
102
|
+
export async function createNoopL1Archiver(
|
|
103
|
+
dataStore: KVArchiverDataStore,
|
|
104
|
+
l1Constants: L1RollupConstants & { genesisArchiveRoot: Fr },
|
|
105
|
+
telemetry: TelemetryClient = getTelemetryClient(),
|
|
106
|
+
): Promise<NoopL1Archiver> {
|
|
107
|
+
const instrumentation = await ArchiverInstrumentation.new(telemetry, () => dataStore.estimateSize());
|
|
108
|
+
return new NoopL1Archiver(dataStore, l1Constants, instrumentation);
|
|
109
|
+
}
|