@aztec/archiver 0.0.1-commit.3469e52 → 0.0.1-commit.381b1a9
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 +9 -0
- package/dest/archiver.d.ts +12 -8
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +81 -120
- package/dest/errors.d.ts +6 -1
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +8 -0
- package/dest/factory.d.ts +3 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +14 -11
- 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 +35 -32
- 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 +4 -7
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +12 -16
- 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 +25 -21
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +45 -120
- package/dest/modules/data_store_updater.d.ts +40 -21
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +114 -64
- package/dest/modules/instrumentation.d.ts +6 -4
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +26 -12
- package/dest/modules/l1_synchronizer.d.ts +5 -8
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +46 -20
- package/dest/store/block_store.d.ts +49 -32
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +165 -54
- 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 +53 -25
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +50 -17
- 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 +4 -4
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +105 -47
- package/dest/store/message_store.js +1 -1
- package/dest/test/fake_l1_state.d.ts +16 -4
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +84 -20
- 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 +39 -23
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +157 -112
- package/dest/test/mock_structs.d.ts +6 -2
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +24 -10
- package/dest/test/noop_l1_archiver.d.ts +26 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +72 -0
- package/package.json +14 -13
- package/src/archiver.ts +106 -149
- package/src/errors.ts +12 -0
- package/src/factory.ts +29 -12
- package/src/index.ts +1 -0
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +45 -33
- package/src/l1/calldata_retriever.ts +249 -379
- package/src/l1/data_retrieval.ts +10 -20
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_trace.ts +24 -6
- package/src/modules/data_source_base.ts +76 -166
- package/src/modules/data_store_updater.ts +130 -66
- package/src/modules/instrumentation.ts +26 -14
- package/src/modules/l1_synchronizer.ts +55 -26
- package/src/store/block_store.ts +216 -92
- package/src/store/contract_class_store.ts +11 -7
- package/src/store/kv_archiver_store.ts +88 -30
- package/src/store/l2_tips_cache.ts +89 -0
- package/src/store/log_store.ts +171 -55
- package/src/store/message_store.ts +1 -1
- package/src/test/fake_l1_state.ts +112 -23
- package/src/test/index.ts +3 -0
- package/src/test/mock_archiver.ts +3 -2
- package/src/test/mock_l2_block_source.ts +211 -129
- package/src/test/mock_structs.ts +45 -15
- package/src/test/noop_l1_archiver.ts +115 -0
|
@@ -8,24 +8,33 @@ 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
|
-
|
|
13
|
-
L2BlockNew,
|
|
14
|
+
L2Block,
|
|
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
|
-
import {
|
|
21
|
-
|
|
21
|
+
import {
|
|
22
|
+
EmptyL1RollupConstants,
|
|
23
|
+
type L1RollupConstants,
|
|
24
|
+
getEpochAtSlot,
|
|
25
|
+
getSlotRangeForEpoch,
|
|
26
|
+
} from '@aztec/stdlib/epoch-helpers';
|
|
27
|
+
import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
|
|
28
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
29
|
+
import { type BlockHeader, TxExecutionResult, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
22
30
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
23
31
|
|
|
24
32
|
/**
|
|
25
33
|
* A mocked implementation of L2BlockSource to be used in tests.
|
|
26
34
|
*/
|
|
27
35
|
export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
28
|
-
protected l2Blocks:
|
|
36
|
+
protected l2Blocks: L2Block[] = [];
|
|
37
|
+
protected checkpointList: Checkpoint[] = [];
|
|
29
38
|
|
|
30
39
|
private provenBlockNumber: number = 0;
|
|
31
40
|
private finalizedBlockNumber: number = 0;
|
|
@@ -33,23 +42,55 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
33
42
|
|
|
34
43
|
private log = createLogger('archiver:mock_l2_block_source');
|
|
35
44
|
|
|
45
|
+
/** Creates blocks grouped into single-block checkpoints. */
|
|
36
46
|
public async createBlocks(numBlocks: number) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
47
|
+
await this.createCheckpoints(numBlocks, 1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
51
|
+
return Promise.resolve(
|
|
52
|
+
this.checkpointList.length === 0 ? CheckpointNumber.ZERO : CheckpointNumber(this.checkpointList.length),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Creates checkpoints, each containing `blocksPerCheckpoint` blocks. */
|
|
57
|
+
public async createCheckpoints(numCheckpoints: number, blocksPerCheckpoint: number = 1) {
|
|
58
|
+
for (let c = 0; c < numCheckpoints; c++) {
|
|
59
|
+
const checkpointNum = CheckpointNumber(this.checkpointList.length + 1);
|
|
60
|
+
const startBlockNum = this.l2Blocks.length + 1;
|
|
61
|
+
const slotNumber = SlotNumber(Number(checkpointNum));
|
|
62
|
+
const checkpoint = await Checkpoint.random(checkpointNum, {
|
|
63
|
+
numBlocks: blocksPerCheckpoint,
|
|
64
|
+
startBlockNumber: startBlockNum,
|
|
65
|
+
slotNumber,
|
|
66
|
+
checkpointNumber: checkpointNum,
|
|
67
|
+
});
|
|
68
|
+
this.checkpointList.push(checkpoint);
|
|
69
|
+
this.l2Blocks.push(...checkpoint.blocks);
|
|
41
70
|
}
|
|
42
71
|
|
|
43
|
-
this.log.verbose(
|
|
72
|
+
this.log.verbose(
|
|
73
|
+
`Created ${numCheckpoints} checkpoints with ${blocksPerCheckpoint} blocks each in the mock L2 block source`,
|
|
74
|
+
);
|
|
44
75
|
}
|
|
45
76
|
|
|
46
|
-
public
|
|
77
|
+
public addProposedBlocks(blocks: L2Block[]) {
|
|
47
78
|
this.l2Blocks.push(...blocks);
|
|
48
|
-
this.log.verbose(`Added ${blocks.length} blocks to the mock L2 block source`);
|
|
79
|
+
this.log.verbose(`Added ${blocks.length} proposed blocks to the mock L2 block source`);
|
|
49
80
|
}
|
|
50
81
|
|
|
51
82
|
public removeBlocks(numBlocks: number) {
|
|
52
83
|
this.l2Blocks = this.l2Blocks.slice(0, -numBlocks);
|
|
84
|
+
const maxBlockNum = this.l2Blocks.length;
|
|
85
|
+
// Remove any checkpoint whose last block is beyond the remaining blocks.
|
|
86
|
+
this.checkpointList = this.checkpointList.filter(c => {
|
|
87
|
+
const lastBlockNum = c.blocks[0].number + c.blocks.length - 1;
|
|
88
|
+
return lastBlockNum <= maxBlockNum;
|
|
89
|
+
});
|
|
90
|
+
// Keep tip numbers consistent with remaining blocks.
|
|
91
|
+
this.checkpointedBlockNumber = Math.min(this.checkpointedBlockNumber, maxBlockNum);
|
|
92
|
+
this.provenBlockNumber = Math.min(this.provenBlockNumber, maxBlockNum);
|
|
93
|
+
this.finalizedBlockNumber = Math.min(this.finalizedBlockNumber, maxBlockNum);
|
|
53
94
|
this.log.verbose(`Removed ${numBlocks} blocks from the mock L2 block source`);
|
|
54
95
|
}
|
|
55
96
|
|
|
@@ -65,7 +106,33 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
65
106
|
}
|
|
66
107
|
|
|
67
108
|
public setCheckpointedBlockNumber(checkpointedBlockNumber: number) {
|
|
109
|
+
const prevCheckpointed = this.checkpointedBlockNumber;
|
|
68
110
|
this.checkpointedBlockNumber = checkpointedBlockNumber;
|
|
111
|
+
// Auto-create single-block checkpoints for newly checkpointed blocks that don't have one yet.
|
|
112
|
+
// This handles blocks added via addProposedBlocks that are now being marked as checkpointed.
|
|
113
|
+
const newCheckpoints: Checkpoint[] = [];
|
|
114
|
+
for (let blockNum = prevCheckpointed + 1; blockNum <= checkpointedBlockNumber; blockNum++) {
|
|
115
|
+
const block = this.l2Blocks[blockNum - 1];
|
|
116
|
+
if (!block) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (this.checkpointList.some(c => c.blocks.some(b => b.number === block.number))) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const checkpointNum = CheckpointNumber(this.checkpointList.length + newCheckpoints.length + 1);
|
|
123
|
+
const checkpoint = new Checkpoint(
|
|
124
|
+
block.archive,
|
|
125
|
+
CheckpointHeader.random({ slotNumber: block.header.globalVariables.slotNumber }),
|
|
126
|
+
[block],
|
|
127
|
+
checkpointNum,
|
|
128
|
+
);
|
|
129
|
+
newCheckpoints.push(checkpoint);
|
|
130
|
+
}
|
|
131
|
+
// Insert new checkpoints in order by number.
|
|
132
|
+
if (newCheckpoints.length > 0) {
|
|
133
|
+
this.checkpointList.push(...newCheckpoints);
|
|
134
|
+
this.checkpointList.sort((a, b) => a.number - b.number);
|
|
135
|
+
}
|
|
69
136
|
}
|
|
70
137
|
|
|
71
138
|
/**
|
|
@@ -96,6 +163,14 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
96
163
|
return Promise.resolve(BlockNumber(this.provenBlockNumber));
|
|
97
164
|
}
|
|
98
165
|
|
|
166
|
+
public getCheckpointedL2BlockNumber() {
|
|
167
|
+
return Promise.resolve(BlockNumber(this.checkpointedBlockNumber));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public getFinalizedL2BlockNumber() {
|
|
171
|
+
return Promise.resolve(BlockNumber(this.finalizedBlockNumber));
|
|
172
|
+
}
|
|
173
|
+
|
|
99
174
|
public getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined> {
|
|
100
175
|
if (number > this.checkpointedBlockNumber) {
|
|
101
176
|
return Promise.resolve(undefined);
|
|
@@ -104,20 +179,10 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
104
179
|
if (!block) {
|
|
105
180
|
return Promise.resolve(undefined);
|
|
106
181
|
}
|
|
107
|
-
|
|
108
|
-
CheckpointNumber(number),
|
|
109
|
-
block,
|
|
110
|
-
new L1PublishedData(BigInt(number), BigInt(number), `0x${number.toString(16).padStart(64, '0')}`),
|
|
111
|
-
[],
|
|
112
|
-
);
|
|
113
|
-
return Promise.resolve(checkpointedBlock);
|
|
182
|
+
return Promise.resolve(this.toCheckpointedBlock(block));
|
|
114
183
|
}
|
|
115
184
|
|
|
116
|
-
public async getCheckpointedBlocks(
|
|
117
|
-
from: BlockNumber,
|
|
118
|
-
limit: number,
|
|
119
|
-
_proven?: boolean,
|
|
120
|
-
): Promise<CheckpointedL2Block[]> {
|
|
185
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
|
|
121
186
|
const result: CheckpointedL2Block[] = [];
|
|
122
187
|
for (let i = 0; i < limit; i++) {
|
|
123
188
|
const blockNum = from + i;
|
|
@@ -137,7 +202,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
137
202
|
* @param number - The block number to return (inclusive).
|
|
138
203
|
* @returns The requested L2 block.
|
|
139
204
|
*/
|
|
140
|
-
public getBlock(number: number): Promise<
|
|
205
|
+
public getBlock(number: number): Promise<L2Block | undefined> {
|
|
141
206
|
const block = this.l2Blocks[number - 1];
|
|
142
207
|
return Promise.resolve(block);
|
|
143
208
|
}
|
|
@@ -147,7 +212,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
147
212
|
* @param number - The block number to return.
|
|
148
213
|
* @returns The requested L2 block.
|
|
149
214
|
*/
|
|
150
|
-
public
|
|
215
|
+
public getL2Block(number: BlockNumber): Promise<L2Block | undefined> {
|
|
151
216
|
const block = this.l2Blocks[number - 1];
|
|
152
217
|
return Promise.resolve(block);
|
|
153
218
|
}
|
|
@@ -158,95 +223,41 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
158
223
|
* @param limit - The maximum number of blocks to return.
|
|
159
224
|
* @returns The requested mocked L2 blocks.
|
|
160
225
|
*/
|
|
161
|
-
public getBlocks(from: number, limit: number
|
|
162
|
-
return Promise.resolve(
|
|
163
|
-
this.l2Blocks
|
|
164
|
-
.slice(from - 1, from - 1 + limit)
|
|
165
|
-
.filter(b => !proven || this.provenBlockNumber === undefined || b.number <= this.provenBlockNumber),
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
public getPublishedCheckpoints(from: CheckpointNumber, limit: number) {
|
|
170
|
-
// TODO(mbps): Implement this properly. This only works when we have one block per checkpoint.
|
|
171
|
-
const blocks = this.l2Blocks.slice(from - 1, from - 1 + limit);
|
|
172
|
-
return Promise.all(
|
|
173
|
-
blocks.map(async block => {
|
|
174
|
-
// Create a checkpoint from the block - manually construct since L2BlockNew 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
|
-
}),
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
public async getCheckpointByArchive(archive: Fr): Promise<Checkpoint | undefined> {
|
|
187
|
-
// TODO(mbps): Implement this properly. This only works when we have one block per checkpoint.
|
|
188
|
-
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
189
|
-
if (!block) {
|
|
190
|
-
return undefined;
|
|
191
|
-
}
|
|
192
|
-
// Create a checkpoint from the block - manually construct since L2BlockNew doesn't have toCheckpoint()
|
|
193
|
-
const checkpoint = await Checkpoint.random(block.checkpointNumber, { numBlocks: 1 });
|
|
194
|
-
checkpoint.blocks = [block];
|
|
195
|
-
return checkpoint;
|
|
226
|
+
public getBlocks(from: number, limit: number): Promise<L2Block[]> {
|
|
227
|
+
return Promise.resolve(this.l2Blocks.slice(from - 1, from - 1 + limit));
|
|
196
228
|
}
|
|
197
229
|
|
|
198
|
-
public
|
|
199
|
-
const
|
|
200
|
-
.slice(from - 1, from - 1 + limit)
|
|
201
|
-
.filter(b => !proven || this.provenBlockNumber === undefined || b.number <= this.provenBlockNumber);
|
|
230
|
+
public getCheckpoints(from: CheckpointNumber, limit: number) {
|
|
231
|
+
const checkpoints = this.checkpointList.slice(from - 1, from - 1 + limit);
|
|
202
232
|
return Promise.resolve(
|
|
203
|
-
|
|
204
|
-
CheckpointedL2Block.fromFields({
|
|
205
|
-
checkpointNumber: CheckpointNumber(block.number),
|
|
206
|
-
block,
|
|
207
|
-
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
208
|
-
attestations: [],
|
|
209
|
-
}),
|
|
210
|
-
),
|
|
233
|
+
checkpoints.map(checkpoint => new PublishedCheckpoint(checkpoint, this.mockL1DataForCheckpoint(checkpoint), [])),
|
|
211
234
|
);
|
|
212
235
|
}
|
|
213
236
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return
|
|
237
|
+
public getCheckpointByArchive(archive: Fr): Promise<Checkpoint | undefined> {
|
|
238
|
+
const checkpoint = this.checkpointList.find(c => c.archive.root.equals(archive));
|
|
239
|
+
return Promise.resolve(checkpoint);
|
|
217
240
|
}
|
|
218
241
|
|
|
219
|
-
public async
|
|
242
|
+
public async getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
|
|
220
243
|
for (const block of this.l2Blocks) {
|
|
221
244
|
const hash = await block.hash();
|
|
222
245
|
if (hash.equals(blockHash)) {
|
|
223
|
-
return
|
|
224
|
-
checkpointNumber: CheckpointNumber(block.number),
|
|
225
|
-
block,
|
|
226
|
-
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
227
|
-
attestations: [],
|
|
228
|
-
});
|
|
246
|
+
return this.toCheckpointedBlock(block);
|
|
229
247
|
}
|
|
230
248
|
}
|
|
231
249
|
return undefined;
|
|
232
250
|
}
|
|
233
251
|
|
|
234
|
-
public
|
|
252
|
+
public getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
|
|
235
253
|
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
236
254
|
if (!block) {
|
|
237
255
|
return Promise.resolve(undefined);
|
|
238
256
|
}
|
|
239
|
-
return Promise.resolve(
|
|
240
|
-
CheckpointedL2Block.fromFields({
|
|
241
|
-
checkpointNumber: CheckpointNumber(block.number),
|
|
242
|
-
block,
|
|
243
|
-
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
244
|
-
attestations: [],
|
|
245
|
-
}),
|
|
246
|
-
);
|
|
257
|
+
return Promise.resolve(this.toCheckpointedBlock(block));
|
|
247
258
|
}
|
|
248
259
|
|
|
249
|
-
public async
|
|
260
|
+
public async getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
250
261
|
for (const block of this.l2Blocks) {
|
|
251
262
|
const hash = await block.hash();
|
|
252
263
|
if (hash.equals(blockHash)) {
|
|
@@ -256,12 +267,12 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
256
267
|
return undefined;
|
|
257
268
|
}
|
|
258
269
|
|
|
259
|
-
public
|
|
270
|
+
public getL2BlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
260
271
|
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
261
272
|
return Promise.resolve(block);
|
|
262
273
|
}
|
|
263
274
|
|
|
264
|
-
public async getBlockHeaderByHash(blockHash:
|
|
275
|
+
public async getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
|
|
265
276
|
for (const block of this.l2Blocks) {
|
|
266
277
|
const hash = await block.hash();
|
|
267
278
|
if (hash.equals(blockHash)) {
|
|
@@ -276,46 +287,77 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
276
287
|
return Promise.resolve(block?.header);
|
|
277
288
|
}
|
|
278
289
|
|
|
290
|
+
public async getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
291
|
+
const block = this.l2Blocks[number - 1];
|
|
292
|
+
if (!block) {
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
header: block.header,
|
|
297
|
+
archive: block.archive,
|
|
298
|
+
blockHash: await block.hash(),
|
|
299
|
+
checkpointNumber: block.checkpointNumber,
|
|
300
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
public async getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
305
|
+
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
306
|
+
if (!block) {
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
header: block.header,
|
|
311
|
+
archive: block.archive,
|
|
312
|
+
blockHash: await block.hash(),
|
|
313
|
+
checkpointNumber: block.checkpointNumber,
|
|
314
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
|
|
279
318
|
getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
280
319
|
return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.header);
|
|
281
320
|
}
|
|
282
321
|
|
|
283
322
|
getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
323
|
+
return Promise.resolve(this.getCheckpointsInEpoch(epochNumber));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
getCheckpointsDataForEpoch(epochNumber: EpochNumber): Promise<CheckpointData[]> {
|
|
327
|
+
const checkpoints = this.getCheckpointsInEpoch(epochNumber);
|
|
328
|
+
return Promise.resolve(
|
|
329
|
+
checkpoints.map(
|
|
330
|
+
(checkpoint): CheckpointData => ({
|
|
331
|
+
checkpointNumber: checkpoint.number,
|
|
332
|
+
header: checkpoint.header,
|
|
333
|
+
archive: checkpoint.archive,
|
|
334
|
+
checkpointOutHash: computeCheckpointOutHash(
|
|
335
|
+
checkpoint.blocks.map(b => b.body.txEffects.map(tx => tx.l2ToL1Msgs)),
|
|
336
|
+
),
|
|
337
|
+
startBlock: checkpoint.blocks[0].number,
|
|
338
|
+
blockCount: checkpoint.blocks.length,
|
|
339
|
+
attestations: [],
|
|
340
|
+
l1: this.mockL1DataForCheckpoint(checkpoint),
|
|
341
|
+
}),
|
|
342
|
+
),
|
|
298
343
|
);
|
|
299
344
|
}
|
|
300
345
|
|
|
301
|
-
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
return slot >= start && slot <= end;
|
|
307
|
-
});
|
|
308
|
-
return Promise.resolve(blocks);
|
|
346
|
+
getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]> {
|
|
347
|
+
const checkpoints = this.getCheckpointsInEpoch(epochNumber);
|
|
348
|
+
return Promise.resolve(
|
|
349
|
+
checkpoints.flatMap(checkpoint => checkpoint.blocks.map(block => this.toCheckpointedBlock(block))),
|
|
350
|
+
);
|
|
309
351
|
}
|
|
310
352
|
|
|
311
|
-
getBlocksForSlot(slotNumber: SlotNumber): Promise<
|
|
353
|
+
getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
|
|
312
354
|
const blocks = this.l2Blocks.filter(b => b.header.globalVariables.slotNumber === slotNumber);
|
|
313
355
|
return Promise.resolve(blocks);
|
|
314
356
|
}
|
|
315
357
|
|
|
316
|
-
async
|
|
317
|
-
const
|
|
318
|
-
return
|
|
358
|
+
async getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
359
|
+
const checkpointedBlocks = await this.getCheckpointedBlocksForEpoch(epochNumber);
|
|
360
|
+
return checkpointedBlocks.map(b => b.block.header);
|
|
319
361
|
}
|
|
320
362
|
|
|
321
363
|
/**
|
|
@@ -334,7 +376,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
334
376
|
return {
|
|
335
377
|
data: txEffect,
|
|
336
378
|
l2BlockNumber: block.number,
|
|
337
|
-
l2BlockHash:
|
|
379
|
+
l2BlockHash: await block.hash(),
|
|
338
380
|
txIndexInBlock: block.body.txEffects.indexOf(txEffect),
|
|
339
381
|
};
|
|
340
382
|
}
|
|
@@ -348,13 +390,16 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
348
390
|
for (const block of this.l2Blocks) {
|
|
349
391
|
for (const txEffect of block.body.txEffects) {
|
|
350
392
|
if (txEffect.txHash.equals(txHash)) {
|
|
393
|
+
// In mock, assume all txs are checkpointed with successful execution
|
|
351
394
|
return new TxReceipt(
|
|
352
395
|
txHash,
|
|
353
|
-
TxStatus.
|
|
354
|
-
|
|
396
|
+
TxStatus.CHECKPOINTED,
|
|
397
|
+
TxExecutionResult.SUCCESS,
|
|
398
|
+
undefined,
|
|
355
399
|
txEffect.transactionFee.toBigInt(),
|
|
356
|
-
|
|
400
|
+
await block.hash(),
|
|
357
401
|
block.number,
|
|
402
|
+
getEpochAtSlot(block.slot, EmptyL1RollupConstants),
|
|
358
403
|
);
|
|
359
404
|
}
|
|
360
405
|
}
|
|
@@ -394,7 +439,10 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
394
439
|
|
|
395
440
|
const makeTipId = (blockId: typeof latestBlockId) => ({
|
|
396
441
|
block: blockId,
|
|
397
|
-
checkpoint: {
|
|
442
|
+
checkpoint: {
|
|
443
|
+
number: this.findCheckpointNumberForBlock(blockId.number) ?? CheckpointNumber(0),
|
|
444
|
+
hash: blockId.hash,
|
|
445
|
+
},
|
|
398
446
|
});
|
|
399
447
|
|
|
400
448
|
return {
|
|
@@ -405,11 +453,11 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
405
453
|
};
|
|
406
454
|
}
|
|
407
455
|
|
|
408
|
-
|
|
456
|
+
getSyncedL2EpochNumber(): Promise<EpochNumber> {
|
|
409
457
|
throw new Error('Method not implemented.');
|
|
410
458
|
}
|
|
411
459
|
|
|
412
|
-
|
|
460
|
+
getSyncedL2SlotNumber(): Promise<SlotNumber> {
|
|
413
461
|
throw new Error('Method not implemented.');
|
|
414
462
|
}
|
|
415
463
|
|
|
@@ -482,4 +530,38 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
482
530
|
getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
|
|
483
531
|
return Promise.resolve({ valid: true });
|
|
484
532
|
}
|
|
533
|
+
|
|
534
|
+
/** Returns checkpoints whose slot falls within the given epoch. */
|
|
535
|
+
private getCheckpointsInEpoch(epochNumber: EpochNumber): Checkpoint[] {
|
|
536
|
+
const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
|
|
537
|
+
const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
|
|
538
|
+
return this.checkpointList.filter(c => c.header.slotNumber >= start && c.header.slotNumber <= end);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/** Creates a mock L1PublishedData for a checkpoint. */
|
|
542
|
+
private mockL1DataForCheckpoint(checkpoint: Checkpoint): L1PublishedData {
|
|
543
|
+
return new L1PublishedData(BigInt(checkpoint.number), BigInt(checkpoint.number), Buffer32.random().toString());
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/** Creates a CheckpointedL2Block from a block using stored checkpoint info. */
|
|
547
|
+
private toCheckpointedBlock(block: L2Block): CheckpointedL2Block {
|
|
548
|
+
const checkpoint = this.checkpointList.find(c => c.blocks.some(b => b.number === block.number));
|
|
549
|
+
const checkpointNumber = checkpoint?.number ?? block.checkpointNumber;
|
|
550
|
+
return new CheckpointedL2Block(
|
|
551
|
+
checkpointNumber,
|
|
552
|
+
block,
|
|
553
|
+
new L1PublishedData(
|
|
554
|
+
BigInt(block.number),
|
|
555
|
+
BigInt(block.number),
|
|
556
|
+
`0x${block.number.toString(16).padStart(64, '0')}`,
|
|
557
|
+
),
|
|
558
|
+
[],
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/** Finds the checkpoint number for a block, or undefined if the block is not in any checkpoint. */
|
|
563
|
+
private findCheckpointNumberForBlock(blockNumber: BlockNumber): CheckpointNumber | undefined {
|
|
564
|
+
const checkpoint = this.checkpointList.find(c => c.blocks.some(b => b.number === blockNumber));
|
|
565
|
+
return checkpoint?.number;
|
|
566
|
+
}
|
|
485
567
|
}
|
package/src/test/mock_structs.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer'
|
|
|
12
12
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
13
13
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
14
14
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
|
-
import { CommitteeAttestation,
|
|
15
|
+
import { CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
|
|
16
16
|
import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
17
17
|
import { PrivateLog, PublicLog, SiloedTag, Tag } from '@aztec/stdlib/logs';
|
|
18
18
|
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
@@ -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
|
|
|
@@ -111,6 +127,25 @@ export function makeL1PublishedData(l1BlockNumber: number): L1PublishedData {
|
|
|
111
127
|
return new L1PublishedData(BigInt(l1BlockNumber), BigInt(l1BlockNumber * 1000), makeBlockHash(l1BlockNumber));
|
|
112
128
|
}
|
|
113
129
|
|
|
130
|
+
/** Creates a Checkpoint from a list of blocks with a header that matches the blocks' structure. */
|
|
131
|
+
export function makeCheckpoint(blocks: L2Block[], checkpointNumber = CheckpointNumber(1)): Checkpoint {
|
|
132
|
+
const firstBlock = blocks[0];
|
|
133
|
+
const { slotNumber, timestamp, coinbase, feeRecipient, gasFees } = firstBlock.header.globalVariables;
|
|
134
|
+
return new Checkpoint(
|
|
135
|
+
blocks.at(-1)!.archive,
|
|
136
|
+
CheckpointHeader.random({
|
|
137
|
+
lastArchiveRoot: firstBlock.header.lastArchive.root,
|
|
138
|
+
slotNumber,
|
|
139
|
+
timestamp,
|
|
140
|
+
coinbase,
|
|
141
|
+
feeRecipient,
|
|
142
|
+
gasFees,
|
|
143
|
+
}),
|
|
144
|
+
blocks,
|
|
145
|
+
checkpointNumber,
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
114
149
|
/** Wraps a Checkpoint with L1 published data and random attestations. */
|
|
115
150
|
export function makePublishedCheckpoint(
|
|
116
151
|
checkpoint: Checkpoint,
|
|
@@ -268,8 +303,8 @@ export async function makeCheckpointWithLogs(
|
|
|
268
303
|
): Promise<PublishedCheckpoint> {
|
|
269
304
|
const { previousArchive, numTxsPerBlock = 4, privateLogs, publicLogs } = options;
|
|
270
305
|
|
|
271
|
-
const block = await
|
|
272
|
-
checkpointNumber: CheckpointNumber(blockNumber),
|
|
306
|
+
const block = await L2Block.random(BlockNumber(blockNumber), {
|
|
307
|
+
checkpointNumber: CheckpointNumber.fromBlockNumber(BlockNumber(blockNumber)),
|
|
273
308
|
indexWithinCheckpoint: IndexWithinCheckpoint(0),
|
|
274
309
|
state: makeStateForBlock(blockNumber, numTxsPerBlock),
|
|
275
310
|
...(previousArchive ? { lastArchive: previousArchive } : {}),
|
|
@@ -285,11 +320,6 @@ export async function makeCheckpointWithLogs(
|
|
|
285
320
|
return txEffect;
|
|
286
321
|
});
|
|
287
322
|
|
|
288
|
-
const checkpoint =
|
|
289
|
-
AppendOnlyTreeSnapshot.random(),
|
|
290
|
-
CheckpointHeader.random(),
|
|
291
|
-
[block],
|
|
292
|
-
CheckpointNumber(blockNumber),
|
|
293
|
-
);
|
|
323
|
+
const checkpoint = makeCheckpoint([block], CheckpointNumber.fromBlockNumber(BlockNumber(blockNumber)));
|
|
294
324
|
return makePublishedCheckpoint(checkpoint, blockNumber);
|
|
295
325
|
}
|