@aztec/archiver 0.0.1-commit.9372f48 → 0.0.1-commit.949a33fd8
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 +12 -6
- package/dest/archiver.d.ts +22 -11
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +152 -145
- package/dest/config.d.ts +5 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -4
- package/dest/errors.d.ts +61 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +88 -14
- package/dest/factory.d.ts +4 -5
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +33 -27
- package/dest/index.d.ts +4 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -1
- package/dest/l1/bin/retrieve-calldata.js +36 -33
- package/dest/l1/calldata_retriever.d.ts +74 -50
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +197 -260
- package/dest/l1/data_retrieval.d.ts +26 -17
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +42 -47
- 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_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/data_source_base.d.ts +18 -7
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +51 -77
- package/dest/modules/data_store_updater.d.ts +35 -15
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +139 -96
- package/dest/modules/instrumentation.d.ts +21 -3
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +41 -8
- package/dest/modules/l1_synchronizer.d.ts +11 -9
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +304 -151
- package/dest/modules/validation.d.ts +4 -3
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +6 -6
- package/dest/store/block_store.d.ts +98 -28
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +465 -138
- package/dest/store/contract_class_store.d.ts +2 -3
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +7 -67
- package/dest/store/contract_instance_store.d.ts +1 -1
- package/dest/store/contract_instance_store.d.ts.map +1 -1
- package/dest/store/contract_instance_store.js +6 -2
- package/dest/store/kv_archiver_store.d.ts +85 -24
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +106 -27
- package/dest/store/l2_tips_cache.d.ts +20 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +109 -0
- package/dest/store/log_store.d.ts +6 -3
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +150 -55
- package/dest/store/message_store.d.ts +5 -1
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +21 -9
- package/dest/test/fake_l1_state.d.ts +25 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +166 -32
- 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_l1_to_l2_message_source.d.ts +1 -1
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +2 -1
- package/dest/test/mock_l2_block_source.d.ts +35 -5
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +182 -89
- package/dest/test/mock_structs.d.ts +4 -1
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +13 -1
- package/dest/test/noop_l1_archiver.d.ts +4 -1
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +9 -3
- package/package.json +13 -13
- package/src/archiver.ts +187 -164
- package/src/config.ts +23 -2
- package/src/errors.ts +133 -22
- package/src/factory.ts +47 -24
- package/src/index.ts +3 -1
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +46 -39
- package/src/l1/calldata_retriever.ts +261 -379
- package/src/l1/data_retrieval.ts +58 -69
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/modules/data_source_base.ts +95 -98
- package/src/modules/data_store_updater.ts +168 -126
- package/src/modules/instrumentation.ts +56 -9
- package/src/modules/l1_synchronizer.ts +384 -188
- package/src/modules/validation.ts +10 -9
- package/src/store/block_store.ts +569 -174
- package/src/store/contract_class_store.ts +8 -106
- package/src/store/contract_instance_store.ts +8 -5
- package/src/store/kv_archiver_store.ts +167 -41
- package/src/store/l2_tips_cache.ts +134 -0
- package/src/store/log_store.ts +221 -63
- package/src/store/message_store.ts +27 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +213 -42
- package/src/test/mock_archiver.ts +3 -2
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +230 -82
- package/src/test/mock_structs.ts +20 -6
- package/src/test/noop_l1_archiver.ts +10 -2
|
@@ -1,11 +1,18 @@
|
|
|
1
|
+
import { range } from '@aztec/foundation/array';
|
|
1
2
|
import { BlockNumber, CheckpointNumber, type EpochNumber, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
5
|
import { isDefined } from '@aztec/foundation/types';
|
|
5
6
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
6
7
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
|
-
import { type BlockHash, CheckpointedL2Block,
|
|
8
|
-
import {
|
|
8
|
+
import { type BlockData, type BlockHash, CheckpointedL2Block, L2Block, type L2Tips } from '@aztec/stdlib/block';
|
|
9
|
+
import {
|
|
10
|
+
Checkpoint,
|
|
11
|
+
type CheckpointData,
|
|
12
|
+
type CommonCheckpointData,
|
|
13
|
+
type ProposedCheckpointData,
|
|
14
|
+
PublishedCheckpoint,
|
|
15
|
+
} from '@aztec/stdlib/checkpoint';
|
|
9
16
|
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
10
17
|
import { type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
11
18
|
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
@@ -17,7 +24,6 @@ import type { BlockHeader, IndexedTxEffect, TxHash, TxReceipt } from '@aztec/std
|
|
|
17
24
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
18
25
|
|
|
19
26
|
import type { ArchiverDataSource } from '../interfaces.js';
|
|
20
|
-
import type { CheckpointData } from '../store/block_store.js';
|
|
21
27
|
import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
|
|
22
28
|
import type { ValidateCheckpointResult } from './validation.js';
|
|
23
29
|
|
|
@@ -46,9 +52,9 @@ export abstract class ArchiverDataSourceBase
|
|
|
46
52
|
|
|
47
53
|
abstract getL2Tips(): Promise<L2Tips>;
|
|
48
54
|
|
|
49
|
-
abstract
|
|
55
|
+
abstract getSyncedL2SlotNumber(): Promise<SlotNumber | undefined>;
|
|
50
56
|
|
|
51
|
-
abstract
|
|
57
|
+
abstract getSyncedL2EpochNumber(): Promise<EpochNumber | undefined>;
|
|
52
58
|
|
|
53
59
|
abstract isEpochComplete(epochNumber: EpochNumber): Promise<boolean>;
|
|
54
60
|
|
|
@@ -114,13 +120,29 @@ export abstract class ArchiverDataSourceBase
|
|
|
114
120
|
if (!checkpointData) {
|
|
115
121
|
return undefined;
|
|
116
122
|
}
|
|
117
|
-
return BlockNumber(checkpointData.startBlock + checkpointData.
|
|
123
|
+
return BlockNumber(checkpointData.startBlock + checkpointData.blockCount - 1);
|
|
118
124
|
}
|
|
119
125
|
|
|
120
126
|
public getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
|
|
121
127
|
return this.store.getCheckpointedBlocks(from, limit);
|
|
122
128
|
}
|
|
123
129
|
|
|
130
|
+
public getCheckpointData(checkpointNumber: CheckpointNumber): Promise<CheckpointData | undefined> {
|
|
131
|
+
return this.store.getCheckpointData(checkpointNumber);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public getCheckpointDataRange(from: CheckpointNumber, limit: number): Promise<CheckpointData[]> {
|
|
135
|
+
return this.store.getCheckpointDataRange(from, limit);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public getCheckpointNumberBySlot(slot: SlotNumber): Promise<CheckpointNumber | undefined> {
|
|
139
|
+
return this.store.getCheckpointNumberBySlot(slot);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
public getBlockDataWithCheckpointContext(blockNumber: BlockNumber) {
|
|
143
|
+
return this.store.getBlockDataWithCheckpointContext(blockNumber);
|
|
144
|
+
}
|
|
145
|
+
|
|
124
146
|
public getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
|
|
125
147
|
return this.store.getBlockHeaderByHash(blockHash);
|
|
126
148
|
}
|
|
@@ -129,6 +151,14 @@ export abstract class ArchiverDataSourceBase
|
|
|
129
151
|
return this.store.getBlockHeaderByArchive(archive);
|
|
130
152
|
}
|
|
131
153
|
|
|
154
|
+
public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
155
|
+
return this.store.getBlockData(number);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
159
|
+
return this.store.getBlockDataByArchive(archive);
|
|
160
|
+
}
|
|
161
|
+
|
|
132
162
|
public async getL2Block(number: BlockNumber): Promise<L2Block | undefined> {
|
|
133
163
|
// If the number provided is -ve, then return the latest block.
|
|
134
164
|
if (number < 0) {
|
|
@@ -146,7 +176,15 @@ export abstract class ArchiverDataSourceBase
|
|
|
146
176
|
}
|
|
147
177
|
|
|
148
178
|
public getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
|
|
149
|
-
return this.store.getSettledTxReceipt(txHash);
|
|
179
|
+
return this.store.getSettledTxReceipt(txHash, this.l1Constants);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
public getLastCheckpoint(): Promise<CommonCheckpointData | undefined> {
|
|
183
|
+
return this.store.getLastCheckpoint();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
public getLastProposedCheckpoint(): Promise<ProposedCheckpointData | undefined> {
|
|
187
|
+
return this.store.getLastProposedCheckpoint();
|
|
150
188
|
}
|
|
151
189
|
|
|
152
190
|
public isPendingChainInvalid(): Promise<boolean> {
|
|
@@ -157,16 +195,21 @@ export abstract class ArchiverDataSourceBase
|
|
|
157
195
|
return (await this.store.getPendingChainValidationStatus()) ?? { valid: true };
|
|
158
196
|
}
|
|
159
197
|
|
|
160
|
-
public getPrivateLogsByTags(
|
|
161
|
-
|
|
198
|
+
public getPrivateLogsByTags(
|
|
199
|
+
tags: SiloedTag[],
|
|
200
|
+
page?: number,
|
|
201
|
+
upToBlockNumber?: BlockNumber,
|
|
202
|
+
): Promise<TxScopedL2Log[][]> {
|
|
203
|
+
return this.store.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
162
204
|
}
|
|
163
205
|
|
|
164
206
|
public getPublicLogsByTagsFromContract(
|
|
165
207
|
contractAddress: AztecAddress,
|
|
166
208
|
tags: Tag[],
|
|
167
209
|
page?: number,
|
|
210
|
+
upToBlockNumber?: BlockNumber,
|
|
168
211
|
): Promise<TxScopedL2Log[][]> {
|
|
169
|
-
return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
212
|
+
return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
170
213
|
}
|
|
171
214
|
|
|
172
215
|
public getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
|
|
@@ -223,28 +266,22 @@ export abstract class ArchiverDataSourceBase
|
|
|
223
266
|
|
|
224
267
|
public async getCheckpoints(checkpointNumber: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
225
268
|
const checkpoints = await this.store.getRangeOfCheckpoints(checkpointNumber, limit);
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const checkpoint = checkpoints[i];
|
|
234
|
-
const fullCheckpoint = new Checkpoint(
|
|
235
|
-
checkpoint.archive,
|
|
236
|
-
checkpoint.header,
|
|
237
|
-
blocksForCheckpoint,
|
|
238
|
-
checkpoint.checkpointNumber,
|
|
239
|
-
);
|
|
240
|
-
const publishedCheckpoint = new PublishedCheckpoint(
|
|
241
|
-
fullCheckpoint,
|
|
242
|
-
checkpoint.l1,
|
|
243
|
-
checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
|
|
244
|
-
);
|
|
245
|
-
fullCheckpoints.push(publishedCheckpoint);
|
|
269
|
+
return Promise.all(checkpoints.map(ch => this.getPublishedCheckpointFromCheckpointData(ch)));
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
private async getPublishedCheckpointFromCheckpointData(checkpoint: CheckpointData): Promise<PublishedCheckpoint> {
|
|
273
|
+
const blocksForCheckpoint = await this.store.getBlocksForCheckpoint(checkpoint.checkpointNumber);
|
|
274
|
+
if (!blocksForCheckpoint) {
|
|
275
|
+
throw new Error(`Blocks for checkpoint ${checkpoint.checkpointNumber} not found`);
|
|
246
276
|
}
|
|
247
|
-
|
|
277
|
+
const fullCheckpoint = new Checkpoint(
|
|
278
|
+
checkpoint.archive,
|
|
279
|
+
checkpoint.header,
|
|
280
|
+
blocksForCheckpoint,
|
|
281
|
+
checkpoint.checkpointNumber,
|
|
282
|
+
checkpoint.feeAssetPriceModifier,
|
|
283
|
+
);
|
|
284
|
+
return new PublishedCheckpoint(fullCheckpoint, checkpoint.l1, checkpoint.attestations);
|
|
248
285
|
}
|
|
249
286
|
|
|
250
287
|
public getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
|
|
@@ -252,84 +289,44 @@ export abstract class ArchiverDataSourceBase
|
|
|
252
289
|
}
|
|
253
290
|
|
|
254
291
|
public async getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]> {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
let checkpoint = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
|
|
265
|
-
const slot = (b: CheckpointData) => b.header.slotNumber;
|
|
266
|
-
while (checkpoint && slot(checkpoint) >= start) {
|
|
267
|
-
if (slot(checkpoint) <= end) {
|
|
268
|
-
// push the blocks on backwards
|
|
269
|
-
const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
|
|
270
|
-
for (let i = endBlock; i >= checkpoint.startBlock; i--) {
|
|
271
|
-
const checkpointedBlock = await this.getCheckpointedBlock(BlockNumber(i));
|
|
272
|
-
if (checkpointedBlock) {
|
|
273
|
-
blocks.push(checkpointedBlock);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
checkpoint = await this.store.getCheckpointData(CheckpointNumber(checkpoint.checkpointNumber - 1));
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
return blocks.reverse();
|
|
292
|
+
const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
|
|
293
|
+
const blocks = await Promise.all(
|
|
294
|
+
checkpointsData.flatMap(checkpoint =>
|
|
295
|
+
range(checkpoint.blockCount, checkpoint.startBlock).map(blockNumber =>
|
|
296
|
+
this.getCheckpointedBlock(BlockNumber(blockNumber)),
|
|
297
|
+
),
|
|
298
|
+
),
|
|
299
|
+
);
|
|
300
|
+
return blocks.filter(isDefined);
|
|
281
301
|
}
|
|
282
302
|
|
|
283
303
|
public async getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
let checkpoint = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
|
|
294
|
-
const slot = (b: CheckpointData) => b.header.slotNumber;
|
|
295
|
-
while (checkpoint && slot(checkpoint) >= start) {
|
|
296
|
-
if (slot(checkpoint) <= end) {
|
|
297
|
-
// push the blocks on backwards
|
|
298
|
-
const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
|
|
299
|
-
for (let i = endBlock; i >= checkpoint.startBlock; i--) {
|
|
300
|
-
const block = await this.getBlockHeader(BlockNumber(i));
|
|
301
|
-
if (block) {
|
|
302
|
-
blocks.push(block);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
checkpoint = await this.store.getCheckpointData(CheckpointNumber(checkpoint.checkpointNumber - 1));
|
|
307
|
-
}
|
|
308
|
-
return blocks.reverse();
|
|
304
|
+
const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
|
|
305
|
+
const blocks = await Promise.all(
|
|
306
|
+
checkpointsData.flatMap(checkpoint =>
|
|
307
|
+
range(checkpoint.blockCount, checkpoint.startBlock).map(blockNumber =>
|
|
308
|
+
this.getBlockHeader(BlockNumber(blockNumber)),
|
|
309
|
+
),
|
|
310
|
+
),
|
|
311
|
+
);
|
|
312
|
+
return blocks.filter(isDefined);
|
|
309
313
|
}
|
|
310
314
|
|
|
311
315
|
public async getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
|
|
316
|
+
const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
|
|
317
|
+
return Promise.all(
|
|
318
|
+
checkpointsData.map(data => this.getPublishedCheckpointFromCheckpointData(data).then(p => p.checkpoint)),
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** Returns checkpoint data for all checkpoints whose slot falls within the given epoch. */
|
|
323
|
+
public getCheckpointsDataForEpoch(epochNumber: EpochNumber): Promise<CheckpointData[]> {
|
|
312
324
|
if (!this.l1Constants) {
|
|
313
325
|
throw new Error('L1 constants not set');
|
|
314
326
|
}
|
|
315
327
|
|
|
316
328
|
const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
// Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
|
|
320
|
-
// We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
|
|
321
|
-
let checkpointData = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
|
|
322
|
-
const slot = (b: CheckpointData) => b.header.slotNumber;
|
|
323
|
-
while (checkpointData && slot(checkpointData) >= start) {
|
|
324
|
-
if (slot(checkpointData) <= end) {
|
|
325
|
-
// push the checkpoints on backwards
|
|
326
|
-
const [checkpoint] = await this.getCheckpoints(checkpointData.checkpointNumber, 1);
|
|
327
|
-
checkpoints.push(checkpoint.checkpoint);
|
|
328
|
-
}
|
|
329
|
-
checkpointData = await this.store.getCheckpointData(CheckpointNumber(checkpointData.checkpointNumber - 1));
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
return checkpoints.reverse();
|
|
329
|
+
return this.store.getCheckpointDataForSlotRange(start, end);
|
|
333
330
|
}
|
|
334
331
|
|
|
335
332
|
public async getBlock(number: BlockNumber): Promise<L2Block | undefined> {
|