@aztec/archiver 0.0.1-commit.c2eed6949 → 0.0.1-commit.c52d6e7
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 +19 -11
- package/dest/archiver.d.ts +71 -15
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +276 -70
- package/dest/config.d.ts +7 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +44 -16
- package/dest/errors.d.ts +44 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +66 -12
- package/dest/factory.d.ts +18 -6
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +66 -21
- package/dest/index.d.ts +11 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +10 -2
- package/dest/l1/calldata_retriever.d.ts +9 -1
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +22 -11
- package/dest/l1/data_retrieval.d.ts +25 -11
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +25 -32
- package/dest/l1/trace_tx.d.ts +12 -66
- package/dest/l1/trace_tx.d.ts.map +1 -1
- package/dest/l1/validate_historical_logs.d.ts +23 -0
- package/dest/l1/validate_historical_logs.d.ts.map +1 -0
- package/dest/l1/validate_historical_logs.js +108 -0
- package/dest/modules/contract_data_source_adapter.d.ts +25 -0
- package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
- package/dest/modules/contract_data_source_adapter.js +32 -0
- package/dest/modules/data_source_base.d.ts +71 -48
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +250 -144
- package/dest/modules/data_store_updater.d.ts +28 -8
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +124 -55
- package/dest/modules/instrumentation.d.ts +15 -2
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +48 -9
- package/dest/modules/l1_synchronizer.d.ts +13 -8
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +453 -219
- package/dest/modules/outbox_trees_resolver.d.ts +64 -0
- package/dest/modules/outbox_trees_resolver.d.ts.map +1 -0
- package/dest/modules/outbox_trees_resolver.js +184 -0
- package/dest/modules/validation.d.ts +30 -7
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +35 -17
- package/dest/store/block_store.d.ts +177 -68
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +719 -246
- package/dest/store/contract_class_store.d.ts +17 -3
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +36 -2
- package/dest/store/contract_instance_store.d.ts +28 -1
- package/dest/store/contract_instance_store.d.ts.map +1 -1
- package/dest/store/contract_instance_store.js +49 -1
- package/dest/store/data_stores.d.ts +68 -0
- package/dest/store/data_stores.d.ts.map +1 -0
- package/dest/store/data_stores.js +54 -0
- package/dest/store/function_names_cache.d.ts +17 -0
- package/dest/store/function_names_cache.d.ts.map +1 -0
- package/dest/store/function_names_cache.js +30 -0
- package/dest/store/l2_tips_cache.d.ts +13 -7
- package/dest/store/l2_tips_cache.d.ts.map +1 -1
- package/dest/store/l2_tips_cache.js +13 -76
- package/dest/store/log_store.d.ts +42 -40
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +257 -480
- package/dest/store/log_store_codec.d.ts +78 -0
- package/dest/store/log_store_codec.d.ts.map +1 -0
- package/dest/store/log_store_codec.js +110 -0
- package/dest/store/message_store.d.ts +9 -3
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +39 -10
- package/dest/test/fake_l1_state.d.ts +15 -3
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +83 -21
- package/dest/test/mock_l2_block_source.d.ts +48 -50
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +228 -179
- package/dest/test/mock_structs.d.ts +1 -1
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +2 -2
- package/dest/test/noop_l1_archiver.d.ts +14 -6
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +26 -10
- package/package.json +14 -14
- package/src/archiver.ts +362 -76
- package/src/config.ts +51 -20
- package/src/errors.ts +103 -18
- package/src/factory.ts +80 -19
- package/src/index.ts +18 -2
- package/src/l1/calldata_retriever.ts +29 -11
- package/src/l1/data_retrieval.ts +44 -46
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/modules/contract_data_source_adapter.ts +46 -0
- package/src/modules/data_source_base.ts +325 -192
- package/src/modules/data_store_updater.ts +152 -57
- package/src/modules/instrumentation.ts +43 -10
- package/src/modules/l1_synchronizer.ts +612 -259
- package/src/modules/outbox_trees_resolver.ts +220 -0
- package/src/modules/validation.ts +80 -23
- package/src/store/block_store.ts +879 -300
- package/src/store/contract_class_store.ts +47 -3
- package/src/store/contract_instance_store.ts +61 -1
- package/src/store/data_stores.ts +104 -0
- package/src/store/function_names_cache.ts +37 -0
- package/src/store/l2_tips_cache.ts +16 -70
- package/src/store/log_store.ts +296 -652
- package/src/store/log_store_codec.ts +143 -0
- package/src/store/message_store.ts +43 -12
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +102 -30
- package/src/test/mock_l2_block_source.ts +285 -232
- package/src/test/mock_structs.ts +5 -2
- package/src/test/noop_l1_archiver.ts +54 -11
- package/dest/store/kv_archiver_store.d.ts +0 -364
- package/dest/store/kv_archiver_store.d.ts.map +0 -1
- package/dest/store/kv_archiver_store.js +0 -477
- package/src/store/kv_archiver_store.ts +0 -682
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
2
2
|
import { DefaultL1ContractsConfig } from '@aztec/ethereum/config';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
BlockNumber,
|
|
5
|
+
CheckpointNumber,
|
|
6
|
+
EpochNumber,
|
|
7
|
+
IndexWithinCheckpoint,
|
|
8
|
+
SlotNumber,
|
|
9
|
+
} from '@aztec/foundation/branded-types';
|
|
4
10
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
5
11
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
12
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
@@ -9,24 +15,34 @@ import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
|
9
15
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
16
|
import {
|
|
11
17
|
type BlockData,
|
|
12
|
-
BlockHash,
|
|
13
|
-
|
|
18
|
+
type BlockHash,
|
|
19
|
+
type BlockQuery,
|
|
20
|
+
type BlockTag,
|
|
21
|
+
type BlocksQuery,
|
|
22
|
+
Body,
|
|
23
|
+
type CheckpointQuery,
|
|
24
|
+
type CheckpointsQuery,
|
|
25
|
+
GENESIS_BLOCK_HEADER_HASH,
|
|
26
|
+
GENESIS_CHECKPOINT_HEADER_HASH,
|
|
14
27
|
L2Block,
|
|
15
28
|
type L2BlockSource,
|
|
16
29
|
type L2Tips,
|
|
30
|
+
type ProposedCheckpointQuery,
|
|
17
31
|
type ValidateCheckpointResult,
|
|
18
32
|
} from '@aztec/stdlib/block';
|
|
19
|
-
import { Checkpoint, type CheckpointData, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
20
|
-
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
21
33
|
import {
|
|
22
|
-
|
|
23
|
-
type
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
Checkpoint,
|
|
35
|
+
type CheckpointData,
|
|
36
|
+
L1PublishedData,
|
|
37
|
+
type ProposedCheckpointData,
|
|
38
|
+
PublishedCheckpoint,
|
|
39
|
+
} from '@aztec/stdlib/checkpoint';
|
|
40
|
+
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
41
|
+
import { EmptyL1RollupConstants, type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
27
42
|
import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
|
|
28
43
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
29
|
-
import {
|
|
44
|
+
import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
|
|
45
|
+
import { BlockHeader, TxHash } from '@aztec/stdlib/tx';
|
|
30
46
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
31
47
|
|
|
32
48
|
/**
|
|
@@ -40,8 +56,66 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
40
56
|
private finalizedBlockNumber: number = 0;
|
|
41
57
|
private checkpointedBlockNumber: number = 0;
|
|
42
58
|
|
|
59
|
+
private initialHeader: BlockHeader = BlockHeader.empty();
|
|
60
|
+
private initialHeaderHash: BlockHash = GENESIS_BLOCK_HEADER_HASH;
|
|
61
|
+
private genesisArchiveRoot?: Fr;
|
|
62
|
+
private genesisBlock?: L2Block;
|
|
63
|
+
|
|
43
64
|
private log = createLogger('archiver:mock_l2_block_source');
|
|
44
65
|
|
|
66
|
+
/** Returns the initial header used to synthesize block 0. */
|
|
67
|
+
public getInitialHeader(): BlockHeader {
|
|
68
|
+
return this.initialHeader;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Sets the initial header used to synthesize block 0. Tests that wire up a real
|
|
73
|
+
* world-state should call this with `worldState.getInitialHeader()` so the L2BlockStream
|
|
74
|
+
* agrees on the genesis hash on both sides. Precomputes and caches the header hash so
|
|
75
|
+
* `getGenesisBlockHash()` can return synchronously.
|
|
76
|
+
*/
|
|
77
|
+
public async setInitialHeader(header: BlockHeader): Promise<void> {
|
|
78
|
+
this.initialHeader = header;
|
|
79
|
+
this.initialHeaderHash = await header.hash();
|
|
80
|
+
this.genesisBlock = undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Returns the precomputed hash of the genesis block header. Defaults to the static
|
|
85
|
+
* {@link GENESIS_BLOCK_HEADER_HASH} unless {@link setInitialHeader} has been called with a
|
|
86
|
+
* custom header.
|
|
87
|
+
*/
|
|
88
|
+
public getGenesisBlockHash(): BlockHash {
|
|
89
|
+
return this.initialHeaderHash;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Sets the post-genesis archive root used to synthesize block 0. Mirrors the real archiver,
|
|
94
|
+
* whose synthetic block 0 carries `new AppendOnlyTreeSnapshot(genesisArchiveRoot, 1)` rather
|
|
95
|
+
* than `AppendOnlyTreeSnapshot.empty()`. Tests wiring up a real world-state should set this so
|
|
96
|
+
* archive-based block lookups against the mock match production semantics.
|
|
97
|
+
*/
|
|
98
|
+
public setGenesisArchiveRoot(root: Fr): void {
|
|
99
|
+
this.genesisArchiveRoot = root;
|
|
100
|
+
this.genesisBlock = undefined;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private getGenesisBlock(): L2Block {
|
|
104
|
+
if (this.genesisBlock) {
|
|
105
|
+
return this.genesisBlock;
|
|
106
|
+
}
|
|
107
|
+
const archive = this.genesisArchiveRoot
|
|
108
|
+
? new AppendOnlyTreeSnapshot(this.genesisArchiveRoot, 1)
|
|
109
|
+
: AppendOnlyTreeSnapshot.empty();
|
|
110
|
+
return (this.genesisBlock = new L2Block(
|
|
111
|
+
archive,
|
|
112
|
+
this.initialHeader,
|
|
113
|
+
Body.empty(),
|
|
114
|
+
CheckpointNumber.ZERO,
|
|
115
|
+
IndexWithinCheckpoint(0),
|
|
116
|
+
));
|
|
117
|
+
}
|
|
118
|
+
|
|
45
119
|
/** Creates blocks grouped into single-block checkpoints. */
|
|
46
120
|
public async createBlocks(numBlocks: number) {
|
|
47
121
|
await this.createCheckpoints(numBlocks, 1);
|
|
@@ -155,80 +229,32 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
155
229
|
* Gets the number of the latest L2 block processed by the block source implementation.
|
|
156
230
|
* @returns In this mock instance, returns the number of L2 blocks that we've mocked.
|
|
157
231
|
*/
|
|
158
|
-
public getBlockNumber()
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return Promise.resolve(BlockNumber(this.provenBlockNumber));
|
|
164
|
-
}
|
|
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
|
-
|
|
174
|
-
public getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined> {
|
|
175
|
-
if (number > this.checkpointedBlockNumber) {
|
|
176
|
-
return Promise.resolve(undefined);
|
|
232
|
+
public getBlockNumber(): Promise<BlockNumber>;
|
|
233
|
+
public getBlockNumber(query: BlockQuery): Promise<BlockNumber | undefined>;
|
|
234
|
+
public async getBlockNumber(query?: BlockQuery): Promise<BlockNumber | undefined> {
|
|
235
|
+
if (!query) {
|
|
236
|
+
return BlockNumber(this.l2Blocks.length);
|
|
177
237
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return Promise.resolve(undefined);
|
|
238
|
+
if ('number' in query) {
|
|
239
|
+
return query.number;
|
|
181
240
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
public async getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
|
|
186
|
-
const result: CheckpointedL2Block[] = [];
|
|
187
|
-
for (let i = 0; i < limit; i++) {
|
|
188
|
-
const blockNum = from + i;
|
|
189
|
-
if (blockNum > this.checkpointedBlockNumber) {
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
192
|
-
const block = await this.getCheckpointedBlock(BlockNumber(blockNum));
|
|
193
|
-
if (block) {
|
|
194
|
-
result.push(block);
|
|
195
|
-
}
|
|
241
|
+
if ('tag' in query) {
|
|
242
|
+
return BlockNumber(this.resolveBlockTag(query.tag));
|
|
196
243
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Gets an l2 block.
|
|
202
|
-
* @param number - The block number to return (inclusive).
|
|
203
|
-
* @returns The requested L2 block.
|
|
204
|
-
*/
|
|
205
|
-
public getBlock(number: number): Promise<L2Block | undefined> {
|
|
206
|
-
const block = this.l2Blocks[number - 1];
|
|
207
|
-
return Promise.resolve(block);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Gets an L2 block (new format).
|
|
212
|
-
* @param number - The block number to return.
|
|
213
|
-
* @returns The requested L2 block.
|
|
214
|
-
*/
|
|
215
|
-
public getL2Block(number: BlockNumber): Promise<L2Block | undefined> {
|
|
216
|
-
const block = this.l2Blocks[number - 1];
|
|
217
|
-
return Promise.resolve(block);
|
|
244
|
+
const block = await this.getBlock(query);
|
|
245
|
+
return block ? block.header.globalVariables.blockNumber : undefined;
|
|
218
246
|
}
|
|
219
247
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
public getBlocks(from: number, limit: number): Promise<L2Block[]> {
|
|
227
|
-
return Promise.resolve(this.l2Blocks.slice(from - 1, from - 1 + limit));
|
|
248
|
+
public getCheckpoint(query: CheckpointQuery): Promise<PublishedCheckpoint | undefined> {
|
|
249
|
+
const checkpoint = this.resolveCheckpointQuery(query);
|
|
250
|
+
if (!checkpoint) {
|
|
251
|
+
return Promise.resolve(undefined);
|
|
252
|
+
}
|
|
253
|
+
return Promise.resolve(new PublishedCheckpoint(checkpoint, this.mockL1DataForCheckpoint(checkpoint), []));
|
|
228
254
|
}
|
|
229
255
|
|
|
230
|
-
public getCheckpoints(
|
|
231
|
-
const checkpoints = this.
|
|
256
|
+
public getCheckpoints(query: CheckpointsQuery): Promise<PublishedCheckpoint[]> {
|
|
257
|
+
const checkpoints = this.resolveCheckpointsQuery(query);
|
|
232
258
|
return Promise.resolve(
|
|
233
259
|
checkpoints.map(checkpoint => new PublishedCheckpoint(checkpoint, this.mockL1DataForCheckpoint(checkpoint), [])),
|
|
234
260
|
);
|
|
@@ -239,115 +265,72 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
239
265
|
return Promise.resolve(checkpoint);
|
|
240
266
|
}
|
|
241
267
|
|
|
242
|
-
public
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
if (hash.equals(blockHash)) {
|
|
246
|
-
return this.toCheckpointedBlock(block);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
return undefined;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
public getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
|
|
253
|
-
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
254
|
-
if (!block) {
|
|
268
|
+
public getCheckpointData(query: CheckpointQuery): Promise<CheckpointData | undefined> {
|
|
269
|
+
const checkpoint = this.resolveCheckpointQuery(query);
|
|
270
|
+
if (!checkpoint) {
|
|
255
271
|
return Promise.resolve(undefined);
|
|
256
272
|
}
|
|
257
|
-
return Promise.resolve(this.
|
|
273
|
+
return Promise.resolve(this.checkpointToData(checkpoint));
|
|
258
274
|
}
|
|
259
275
|
|
|
260
|
-
public
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
if (hash.equals(blockHash)) {
|
|
264
|
-
return block;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return undefined;
|
|
276
|
+
public getCheckpointsData(query: CheckpointsQuery): Promise<CheckpointData[]> {
|
|
277
|
+
const checkpoints = this.resolveCheckpointsQuery(query);
|
|
278
|
+
return Promise.resolve(checkpoints.map(c => this.checkpointToData(c)));
|
|
268
279
|
}
|
|
269
280
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
281
|
+
private checkpointToData(checkpoint: Checkpoint): CheckpointData {
|
|
282
|
+
return {
|
|
283
|
+
checkpointNumber: checkpoint.number,
|
|
284
|
+
header: checkpoint.header,
|
|
285
|
+
archive: checkpoint.archive,
|
|
286
|
+
checkpointOutHash: computeCheckpointOutHash(
|
|
287
|
+
checkpoint.blocks.map(b => b.body.txEffects.map(tx => tx.l2ToL1Msgs)),
|
|
288
|
+
),
|
|
289
|
+
startBlock: checkpoint.blocks[0].number,
|
|
290
|
+
blockCount: checkpoint.blocks.length,
|
|
291
|
+
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier,
|
|
292
|
+
attestations: [],
|
|
293
|
+
l1: this.mockL1DataForCheckpoint(checkpoint),
|
|
294
|
+
};
|
|
273
295
|
}
|
|
274
296
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
297
|
+
private resolveCheckpointQuery(query: CheckpointQuery): Checkpoint | undefined {
|
|
298
|
+
if ('number' in query) {
|
|
299
|
+
return this.checkpointList[query.number - 1];
|
|
300
|
+
}
|
|
301
|
+
if ('slot' in query) {
|
|
302
|
+
return this.checkpointList.find(c => c.header.slotNumber === query.slot);
|
|
303
|
+
}
|
|
304
|
+
switch (query.tag) {
|
|
305
|
+
case 'checkpointed':
|
|
306
|
+
return this.checkpointList[this.checkpointList.length - 1];
|
|
307
|
+
case 'proven': {
|
|
308
|
+
const provenCheckpoint = this.checkpointList.filter(c =>
|
|
309
|
+
c.blocks.some(b => b.number <= this.provenBlockNumber),
|
|
310
|
+
);
|
|
311
|
+
return provenCheckpoint.at(-1);
|
|
312
|
+
}
|
|
313
|
+
case 'finalized': {
|
|
314
|
+
const finalizedCheckpoint = this.checkpointList.filter(c =>
|
|
315
|
+
c.blocks.some(b => b.number <= this.finalizedBlockNumber),
|
|
316
|
+
);
|
|
317
|
+
return finalizedCheckpoint.at(-1);
|
|
280
318
|
}
|
|
281
319
|
}
|
|
282
|
-
return undefined;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
public getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
|
|
286
|
-
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
287
|
-
return Promise.resolve(block?.header);
|
|
288
320
|
}
|
|
289
321
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
return undefined;
|
|
322
|
+
private resolveCheckpointsQuery(query: CheckpointsQuery): Checkpoint[] {
|
|
323
|
+
if ('from' in query) {
|
|
324
|
+
return this.checkpointList.slice(query.from - 1, query.from - 1 + query.limit);
|
|
294
325
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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;
|
|
326
|
+
if ('fromSlot' in query) {
|
|
327
|
+
const matching = this.checkpointList.filter(c =>
|
|
328
|
+
query.reverse ? c.header.slotNumber <= query.fromSlot : c.header.slotNumber >= query.fromSlot,
|
|
329
|
+
);
|
|
330
|
+
const nearestFirst = query.reverse ? matching.reverse() : matching;
|
|
331
|
+
return nearestFirst.slice(0, query.limit);
|
|
308
332
|
}
|
|
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
|
-
|
|
318
|
-
getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
319
|
-
return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.header);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
|
|
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
|
-
),
|
|
343
|
-
);
|
|
344
|
-
}
|
|
345
|
-
|
|
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
|
-
);
|
|
333
|
+
return this.getCheckpointsInEpoch(query.epoch);
|
|
351
334
|
}
|
|
352
335
|
|
|
353
336
|
getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
|
|
@@ -355,11 +338,6 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
355
338
|
return Promise.resolve(blocks);
|
|
356
339
|
}
|
|
357
340
|
|
|
358
|
-
async getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
359
|
-
const checkpointedBlocks = await this.getCheckpointedBlocksForEpoch(epochNumber);
|
|
360
|
-
return checkpointedBlocks.map(b => b.block.header);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
341
|
/**
|
|
364
342
|
* Gets a tx effect.
|
|
365
343
|
* @param txHash - The hash of the tx corresponding to the tx effect.
|
|
@@ -377,40 +355,20 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
377
355
|
data: txEffect,
|
|
378
356
|
l2BlockNumber: block.number,
|
|
379
357
|
l2BlockHash: await block.hash(),
|
|
380
|
-
txIndexInBlock: block.body.txEffects.
|
|
358
|
+
txIndexInBlock: block.body.txEffects.findIndex(t => t.txHash.equals(txHash)),
|
|
359
|
+
slotNumber: block.header.globalVariables.slotNumber,
|
|
381
360
|
};
|
|
382
361
|
}
|
|
383
362
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
* @returns The requested tx receipt (or undefined if not found).
|
|
388
|
-
*/
|
|
389
|
-
public async getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
|
|
390
|
-
for (const block of this.l2Blocks) {
|
|
391
|
-
for (const txEffect of block.body.txEffects) {
|
|
392
|
-
if (txEffect.txHash.equals(txHash)) {
|
|
393
|
-
// In mock, assume all txs are checkpointed with successful execution
|
|
394
|
-
return new TxReceipt(
|
|
395
|
-
txHash,
|
|
396
|
-
TxStatus.CHECKPOINTED,
|
|
397
|
-
TxExecutionResult.SUCCESS,
|
|
398
|
-
undefined,
|
|
399
|
-
txEffect.transactionFee.toBigInt(),
|
|
400
|
-
await block.hash(),
|
|
401
|
-
block.number,
|
|
402
|
-
getEpochAtSlot(block.slot, EmptyL1RollupConstants),
|
|
403
|
-
);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
return undefined;
|
|
363
|
+
public getL2ToL1MembershipWitness(): Promise<undefined> {
|
|
364
|
+
// Mock does not back the L2-to-L1 message witness flow.
|
|
365
|
+
return Promise.resolve(undefined);
|
|
408
366
|
}
|
|
409
367
|
|
|
410
368
|
async getL2Tips(): Promise<L2Tips> {
|
|
411
369
|
const [latest, proven, finalized, checkpointed] = [
|
|
412
370
|
await this.getBlockNumber(),
|
|
413
|
-
|
|
371
|
+
this.provenBlockNumber,
|
|
414
372
|
this.finalizedBlockNumber,
|
|
415
373
|
this.checkpointedBlockNumber,
|
|
416
374
|
] as const;
|
|
@@ -420,30 +378,44 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
420
378
|
const finalizedBlock = this.l2Blocks[finalized - 1];
|
|
421
379
|
const checkpointedBlock = this.l2Blocks[checkpointed - 1];
|
|
422
380
|
|
|
381
|
+
// For genesis tips (block number 0) report the dynamic initial header hash so consumers
|
|
382
|
+
// running L2BlockStream against this mock agree at block 0 with their local tip store.
|
|
383
|
+
const genesisHash = (await this.initialHeader.hash()).toString();
|
|
384
|
+
const tipHash = async (block: L2Block | undefined, number: number): Promise<string> => {
|
|
385
|
+
if (block) {
|
|
386
|
+
return (await block.hash()).toString();
|
|
387
|
+
}
|
|
388
|
+
return number === 0 ? genesisHash : '';
|
|
389
|
+
};
|
|
390
|
+
|
|
423
391
|
const latestBlockId = {
|
|
424
392
|
number: BlockNumber(latest),
|
|
425
|
-
hash:
|
|
393
|
+
hash: await tipHash(latestBlock, latest),
|
|
426
394
|
};
|
|
427
395
|
const provenBlockId = {
|
|
428
396
|
number: BlockNumber(proven),
|
|
429
|
-
hash:
|
|
397
|
+
hash: await tipHash(provenBlock, proven),
|
|
430
398
|
};
|
|
431
399
|
const finalizedBlockId = {
|
|
432
400
|
number: BlockNumber(finalized),
|
|
433
|
-
hash:
|
|
401
|
+
hash: await tipHash(finalizedBlock, finalized),
|
|
434
402
|
};
|
|
435
403
|
const checkpointedBlockId = {
|
|
436
404
|
number: BlockNumber(checkpointed),
|
|
437
|
-
hash:
|
|
405
|
+
hash: await tipHash(checkpointedBlock, checkpointed),
|
|
438
406
|
};
|
|
439
407
|
|
|
440
|
-
const makeTipId = (blockId: typeof latestBlockId) =>
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
408
|
+
const makeTipId = (blockId: typeof latestBlockId) => {
|
|
409
|
+
const checkpointNumber = this.findCheckpointNumberForBlock(blockId.number) ?? CheckpointNumber(0);
|
|
410
|
+
// Match production semantics: checkpoint 0 is fully synthetic (no real checkpoint header
|
|
411
|
+
// exists at 0), so its hash stays at the protocol constant `GENESIS_CHECKPOINT_HEADER_HASH`
|
|
412
|
+
// even though the block-0 hash is dynamic. See L2TipsCache for the production path.
|
|
413
|
+
const hash = checkpointNumber === 0 ? GENESIS_CHECKPOINT_HEADER_HASH.toString() : blockId.hash;
|
|
414
|
+
return {
|
|
415
|
+
block: blockId,
|
|
416
|
+
checkpoint: { number: checkpointNumber, hash },
|
|
417
|
+
};
|
|
418
|
+
};
|
|
447
419
|
|
|
448
420
|
return {
|
|
449
421
|
proposed: latestBlockId,
|
|
@@ -469,8 +441,12 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
469
441
|
return Promise.resolve(EmptyL1RollupConstants);
|
|
470
442
|
}
|
|
471
443
|
|
|
444
|
+
isPruneDueAtSlot(_slot: SlotNumber): Promise<boolean> {
|
|
445
|
+
return Promise.resolve(false);
|
|
446
|
+
}
|
|
447
|
+
|
|
472
448
|
getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
|
|
473
|
-
return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
|
|
449
|
+
return Promise.resolve({ genesisArchiveRoot: this.genesisArchiveRoot ?? new Fr(GENESIS_ARCHIVE_ROOT) });
|
|
474
450
|
}
|
|
475
451
|
|
|
476
452
|
getL1Timestamp(): Promise<bigint> {
|
|
@@ -523,6 +499,95 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
523
499
|
return Promise.resolve();
|
|
524
500
|
}
|
|
525
501
|
|
|
502
|
+
async getBlock(query: BlockQuery): Promise<L2Block | undefined> {
|
|
503
|
+
if ('number' in query) {
|
|
504
|
+
if (query.number === 0) {
|
|
505
|
+
return this.getGenesisBlock();
|
|
506
|
+
}
|
|
507
|
+
return this.l2Blocks[query.number - 1];
|
|
508
|
+
}
|
|
509
|
+
if ('hash' in query) {
|
|
510
|
+
const genesis = this.getGenesisBlock();
|
|
511
|
+
if ((await genesis.hash()).equals(query.hash)) {
|
|
512
|
+
return genesis;
|
|
513
|
+
}
|
|
514
|
+
for (const b of this.l2Blocks) {
|
|
515
|
+
const hash = await b.hash();
|
|
516
|
+
if (hash.equals(query.hash)) {
|
|
517
|
+
return b;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return undefined;
|
|
521
|
+
}
|
|
522
|
+
if ('archive' in query) {
|
|
523
|
+
const genesis = this.getGenesisBlock();
|
|
524
|
+
if (genesis.archive.root.equals(query.archive)) {
|
|
525
|
+
return genesis;
|
|
526
|
+
}
|
|
527
|
+
return this.l2Blocks.find(b => b.archive.root.equals(query.archive));
|
|
528
|
+
}
|
|
529
|
+
const number = this.resolveBlockTag(query.tag);
|
|
530
|
+
if (number === 0) {
|
|
531
|
+
return this.getGenesisBlock();
|
|
532
|
+
}
|
|
533
|
+
return this.l2Blocks[number - 1];
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
private resolveBlockTag(tag: BlockTag): number {
|
|
537
|
+
switch (tag) {
|
|
538
|
+
case 'latest':
|
|
539
|
+
case 'proposed':
|
|
540
|
+
return this.l2Blocks.length;
|
|
541
|
+
case 'checkpointed':
|
|
542
|
+
return this.checkpointedBlockNumber;
|
|
543
|
+
case 'proven':
|
|
544
|
+
return this.provenBlockNumber;
|
|
545
|
+
case 'finalized':
|
|
546
|
+
return this.finalizedBlockNumber;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
getBlocks(query: BlocksQuery): Promise<L2Block[]> {
|
|
551
|
+
let blocks: L2Block[];
|
|
552
|
+
if ('from' in query) {
|
|
553
|
+
blocks = this.l2Blocks.slice(query.from - 1, query.from - 1 + query.limit);
|
|
554
|
+
} else {
|
|
555
|
+
const epochCheckpoints = this.getCheckpointsInEpoch(query.epoch);
|
|
556
|
+
blocks = epochCheckpoints.flatMap(c => c.blocks);
|
|
557
|
+
}
|
|
558
|
+
if (query.onlyCheckpointed) {
|
|
559
|
+
blocks = blocks.filter(b => b.header.globalVariables.blockNumber <= this.checkpointedBlockNumber);
|
|
560
|
+
}
|
|
561
|
+
return Promise.resolve(blocks);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
async getBlockData(query: BlockQuery): Promise<BlockData | undefined> {
|
|
565
|
+
const block = await this.getBlock(query);
|
|
566
|
+
if (!block) {
|
|
567
|
+
return undefined;
|
|
568
|
+
}
|
|
569
|
+
return {
|
|
570
|
+
header: block.header,
|
|
571
|
+
archive: block.archive,
|
|
572
|
+
blockHash: await block.hash(),
|
|
573
|
+
checkpointNumber: block.checkpointNumber,
|
|
574
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
async getBlocksData(query: BlocksQuery): Promise<BlockData[]> {
|
|
579
|
+
const blocks = await this.getBlocks(query);
|
|
580
|
+
return Promise.all(
|
|
581
|
+
blocks.map(async block => ({
|
|
582
|
+
header: block.header,
|
|
583
|
+
archive: block.archive,
|
|
584
|
+
blockHash: await block.hash(),
|
|
585
|
+
checkpointNumber: block.checkpointNumber,
|
|
586
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
587
|
+
})),
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
|
|
526
591
|
isPendingChainInvalid(): Promise<boolean> {
|
|
527
592
|
return Promise.resolve(false);
|
|
528
593
|
}
|
|
@@ -531,6 +596,10 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
531
596
|
return Promise.resolve({ valid: true });
|
|
532
597
|
}
|
|
533
598
|
|
|
599
|
+
getProposedCheckpointData(_query?: ProposedCheckpointQuery): Promise<ProposedCheckpointData | undefined> {
|
|
600
|
+
return Promise.resolve(undefined);
|
|
601
|
+
}
|
|
602
|
+
|
|
534
603
|
/** Returns checkpoints whose slot falls within the given epoch. */
|
|
535
604
|
private getCheckpointsInEpoch(epochNumber: EpochNumber): Checkpoint[] {
|
|
536
605
|
const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
|
|
@@ -543,22 +612,6 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
543
612
|
return new L1PublishedData(BigInt(checkpoint.number), BigInt(checkpoint.number), Buffer32.random().toString());
|
|
544
613
|
}
|
|
545
614
|
|
|
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
615
|
/** Finds the checkpoint number for a block, or undefined if the block is not in any checkpoint. */
|
|
563
616
|
private findCheckpointNumberForBlock(blockNumber: BlockNumber): CheckpointNumber | undefined {
|
|
564
617
|
const checkpoint = this.checkpointList.find(c => c.blocks.some(b => b.number === blockNumber));
|
package/src/test/mock_structs.ts
CHANGED
|
@@ -269,7 +269,10 @@ export function makePublicLogTag(blockNumber: number, txIndex: number, logIndex:
|
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
/** Creates a PublicLog with fields derived from the tag. */
|
|
272
|
-
export function makePublicLog(
|
|
272
|
+
export function makePublicLog(
|
|
273
|
+
tag: Tag,
|
|
274
|
+
contractAddress: AztecAddress = AztecAddress.fromNumberUnsafe(543254),
|
|
275
|
+
): PublicLog {
|
|
273
276
|
return PublicLog.from({
|
|
274
277
|
contractAddress,
|
|
275
278
|
fields: new Array(10).fill(null).map((_, i) => (!i ? tag.value : new Fr(tag.value.toBigInt() + BigInt(i)))),
|
|
@@ -281,7 +284,7 @@ export function makePublicLogs(
|
|
|
281
284
|
blockNumber: number,
|
|
282
285
|
txIndex: number,
|
|
283
286
|
numLogsPerTx: number,
|
|
284
|
-
contractAddress: AztecAddress = AztecAddress.
|
|
287
|
+
contractAddress: AztecAddress = AztecAddress.fromNumberUnsafe(543254),
|
|
285
288
|
): PublicLog[] {
|
|
286
289
|
return times(numLogsPerTx, logIndex => {
|
|
287
290
|
const tag = makePublicLogTag(blockNumber, txIndex, logIndex);
|