@aztec/archiver 0.0.1-commit.3469e52 → 0.0.1-commit.35158ae7e
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 -9
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +98 -124
- package/dest/config.d.ts +3 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +2 -1
- package/dest/errors.d.ts +26 -9
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +34 -13
- package/dest/factory.d.ts +4 -2
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +29 -23
- 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 +9 -9
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +24 -22
- 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 +27 -23
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +49 -124
- package/dest/modules/data_store_updater.d.ts +42 -26
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +149 -129
- package/dest/modules/instrumentation.d.ts +17 -4
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +36 -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 +59 -25
- 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 +188 -95
- 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 +16 -72
- 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 +64 -36
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +63 -29
- 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 +9 -6
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +150 -53
- 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 +14 -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 +95 -23
- 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 +126 -151
- package/src/config.ts +8 -1
- package/src/errors.ts +52 -24
- package/src/factory.ts +46 -22
- 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 +27 -29
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_trace.ts +24 -6
- package/src/modules/data_source_base.ts +84 -169
- package/src/modules/data_store_updater.ts +166 -161
- package/src/modules/instrumentation.ts +46 -14
- package/src/modules/l1_synchronizer.ts +72 -36
- package/src/store/block_store.ts +239 -140
- package/src/store/contract_class_store.ts +16 -110
- package/src/store/contract_instance_store.ts +8 -5
- package/src/store/kv_archiver_store.ts +104 -53
- package/src/store/l2_tips_cache.ts +89 -0
- package/src/store/log_store.ts +231 -70
- package/src/store/message_store.ts +20 -1
- package/src/test/fake_l1_state.ts +127 -28
- 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
|
@@ -1,11 +1,12 @@
|
|
|
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 {
|
|
8
|
-
import { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
8
|
+
import { type BlockData, type BlockHash, CheckpointedL2Block, L2Block, type L2Tips } from '@aztec/stdlib/block';
|
|
9
|
+
import { Checkpoint, type CheckpointData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
9
10
|
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
10
11
|
import { type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
11
12
|
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
@@ -17,7 +18,6 @@ import type { BlockHeader, IndexedTxEffect, TxHash, TxReceipt } from '@aztec/std
|
|
|
17
18
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
18
19
|
|
|
19
20
|
import type { ArchiverDataSource } from '../interfaces.js';
|
|
20
|
-
import type { CheckpointData } from '../store/block_store.js';
|
|
21
21
|
import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
|
|
22
22
|
import type { ValidateCheckpointResult } from './validation.js';
|
|
23
23
|
|
|
@@ -46,9 +46,9 @@ export abstract class ArchiverDataSourceBase
|
|
|
46
46
|
|
|
47
47
|
abstract getL2Tips(): Promise<L2Tips>;
|
|
48
48
|
|
|
49
|
-
abstract
|
|
49
|
+
abstract getSyncedL2SlotNumber(): Promise<SlotNumber | undefined>;
|
|
50
50
|
|
|
51
|
-
abstract
|
|
51
|
+
abstract getSyncedL2EpochNumber(): Promise<EpochNumber | undefined>;
|
|
52
52
|
|
|
53
53
|
abstract isEpochComplete(epochNumber: EpochNumber): Promise<boolean>;
|
|
54
54
|
|
|
@@ -87,10 +87,14 @@ export abstract class ArchiverDataSourceBase
|
|
|
87
87
|
return this.store.getCheckpointedBlock(number);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
public
|
|
90
|
+
public getCheckpointedL2BlockNumber(): Promise<BlockNumber> {
|
|
91
91
|
return this.store.getCheckpointedL2BlockNumber();
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
public getFinalizedL2BlockNumber(): Promise<BlockNumber> {
|
|
95
|
+
return this.store.getFinalizedL2BlockNumber();
|
|
96
|
+
}
|
|
97
|
+
|
|
94
98
|
public async getCheckpointHeader(number: CheckpointNumber | 'latest'): Promise<CheckpointHeader | undefined> {
|
|
95
99
|
if (number === 'latest') {
|
|
96
100
|
number = await this.store.getSynchedCheckpointNumber();
|
|
@@ -110,24 +114,14 @@ export abstract class ArchiverDataSourceBase
|
|
|
110
114
|
if (!checkpointData) {
|
|
111
115
|
return undefined;
|
|
112
116
|
}
|
|
113
|
-
return BlockNumber(checkpointData.startBlock + checkpointData.
|
|
117
|
+
return BlockNumber(checkpointData.startBlock + checkpointData.blockCount - 1);
|
|
114
118
|
}
|
|
115
119
|
|
|
116
|
-
public
|
|
117
|
-
from
|
|
118
|
-
limit: number,
|
|
119
|
-
proven?: boolean,
|
|
120
|
-
): Promise<CheckpointedL2Block[]> {
|
|
121
|
-
const blocks = await this.store.getCheckpointedBlocks(from, limit);
|
|
122
|
-
|
|
123
|
-
if (proven === true) {
|
|
124
|
-
const provenBlockNumber = await this.store.getProvenBlockNumber();
|
|
125
|
-
return blocks.filter(b => b.block.number <= provenBlockNumber);
|
|
126
|
-
}
|
|
127
|
-
return blocks;
|
|
120
|
+
public getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
|
|
121
|
+
return this.store.getCheckpointedBlocks(from, limit);
|
|
128
122
|
}
|
|
129
123
|
|
|
130
|
-
public getBlockHeaderByHash(blockHash:
|
|
124
|
+
public getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
|
|
131
125
|
return this.store.getBlockHeaderByHash(blockHash);
|
|
132
126
|
}
|
|
133
127
|
|
|
@@ -135,7 +129,15 @@ export abstract class ArchiverDataSourceBase
|
|
|
135
129
|
return this.store.getBlockHeaderByArchive(archive);
|
|
136
130
|
}
|
|
137
131
|
|
|
138
|
-
public
|
|
132
|
+
public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
133
|
+
return this.store.getBlockData(number);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
137
|
+
return this.store.getBlockDataByArchive(archive);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
public async getL2Block(number: BlockNumber): Promise<L2Block | undefined> {
|
|
139
141
|
// If the number provided is -ve, then return the latest block.
|
|
140
142
|
if (number < 0) {
|
|
141
143
|
number = await this.store.getLatestBlockNumber();
|
|
@@ -152,7 +154,7 @@ export abstract class ArchiverDataSourceBase
|
|
|
152
154
|
}
|
|
153
155
|
|
|
154
156
|
public getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
|
|
155
|
-
return this.store.getSettledTxReceipt(txHash);
|
|
157
|
+
return this.store.getSettledTxReceipt(txHash, this.l1Constants);
|
|
156
158
|
}
|
|
157
159
|
|
|
158
160
|
public isPendingChainInvalid(): Promise<boolean> {
|
|
@@ -163,26 +165,21 @@ export abstract class ArchiverDataSourceBase
|
|
|
163
165
|
return (await this.store.getPendingChainValidationStatus()) ?? { valid: true };
|
|
164
166
|
}
|
|
165
167
|
|
|
166
|
-
public
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
return blocks;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
public getPrivateLogsByTags(tags: SiloedTag[], page?: number): Promise<TxScopedL2Log[][]> {
|
|
177
|
-
return this.store.getPrivateLogsByTags(tags, page);
|
|
168
|
+
public getPrivateLogsByTags(
|
|
169
|
+
tags: SiloedTag[],
|
|
170
|
+
page?: number,
|
|
171
|
+
upToBlockNumber?: BlockNumber,
|
|
172
|
+
): Promise<TxScopedL2Log[][]> {
|
|
173
|
+
return this.store.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
178
174
|
}
|
|
179
175
|
|
|
180
176
|
public getPublicLogsByTagsFromContract(
|
|
181
177
|
contractAddress: AztecAddress,
|
|
182
178
|
tags: Tag[],
|
|
183
179
|
page?: number,
|
|
180
|
+
upToBlockNumber?: BlockNumber,
|
|
184
181
|
): Promise<TxScopedL2Log[][]> {
|
|
185
|
-
return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
182
|
+
return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
186
183
|
}
|
|
187
184
|
|
|
188
185
|
public getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
|
|
@@ -237,147 +234,71 @@ export abstract class ArchiverDataSourceBase
|
|
|
237
234
|
return this.store.getL1ToL2MessageIndex(l1ToL2Message);
|
|
238
235
|
}
|
|
239
236
|
|
|
240
|
-
public async
|
|
241
|
-
checkpointNumber: CheckpointNumber,
|
|
242
|
-
limit: number,
|
|
243
|
-
): Promise<PublishedCheckpoint[]> {
|
|
237
|
+
public async getCheckpoints(checkpointNumber: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
244
238
|
const checkpoints = await this.store.getRangeOfCheckpoints(checkpointNumber, limit);
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const checkpoint = checkpoints[i];
|
|
253
|
-
const fullCheckpoint = new Checkpoint(
|
|
254
|
-
checkpoint.archive,
|
|
255
|
-
checkpoint.header,
|
|
256
|
-
blocksForCheckpoint,
|
|
257
|
-
checkpoint.checkpointNumber,
|
|
258
|
-
);
|
|
259
|
-
const publishedCheckpoint = new PublishedCheckpoint(
|
|
260
|
-
fullCheckpoint,
|
|
261
|
-
checkpoint.l1,
|
|
262
|
-
checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
|
|
263
|
-
);
|
|
264
|
-
fullCheckpoints.push(publishedCheckpoint);
|
|
239
|
+
return Promise.all(checkpoints.map(ch => this.getPublishedCheckpointFromCheckpointData(ch)));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
private async getPublishedCheckpointFromCheckpointData(checkpoint: CheckpointData): Promise<PublishedCheckpoint> {
|
|
243
|
+
const blocksForCheckpoint = await this.store.getBlocksForCheckpoint(checkpoint.checkpointNumber);
|
|
244
|
+
if (!blocksForCheckpoint) {
|
|
245
|
+
throw new Error(`Blocks for checkpoint ${checkpoint.checkpointNumber} not found`);
|
|
265
246
|
}
|
|
266
|
-
|
|
247
|
+
const fullCheckpoint = new Checkpoint(
|
|
248
|
+
checkpoint.archive,
|
|
249
|
+
checkpoint.header,
|
|
250
|
+
blocksForCheckpoint,
|
|
251
|
+
checkpoint.checkpointNumber,
|
|
252
|
+
);
|
|
253
|
+
return new PublishedCheckpoint(fullCheckpoint, checkpoint.l1, checkpoint.attestations);
|
|
267
254
|
}
|
|
268
255
|
|
|
269
|
-
public getBlocksForSlot(slotNumber: SlotNumber): Promise<
|
|
256
|
+
public getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
|
|
270
257
|
return this.store.getBlocksForSlot(slotNumber);
|
|
271
258
|
}
|
|
272
259
|
|
|
273
|
-
public async
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
let checkpoint = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
|
|
284
|
-
const slot = (b: CheckpointData) => b.header.slotNumber;
|
|
285
|
-
while (checkpoint && slot(checkpoint) >= start) {
|
|
286
|
-
if (slot(checkpoint) <= end) {
|
|
287
|
-
// push the blocks on backwards
|
|
288
|
-
const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
|
|
289
|
-
for (let i = endBlock; i >= checkpoint.startBlock; i--) {
|
|
290
|
-
const block = await this.getBlock(BlockNumber(i));
|
|
291
|
-
if (block) {
|
|
292
|
-
blocks.push(block);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
checkpoint = await this.store.getCheckpointData(CheckpointNumber(checkpoint.checkpointNumber - 1));
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
return blocks.reverse();
|
|
260
|
+
public async getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]> {
|
|
261
|
+
const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
|
|
262
|
+
const blocks = await Promise.all(
|
|
263
|
+
checkpointsData.flatMap(checkpoint =>
|
|
264
|
+
range(checkpoint.blockCount, checkpoint.startBlock).map(blockNumber =>
|
|
265
|
+
this.getCheckpointedBlock(BlockNumber(blockNumber)),
|
|
266
|
+
),
|
|
267
|
+
),
|
|
268
|
+
);
|
|
269
|
+
return blocks.filter(isDefined);
|
|
300
270
|
}
|
|
301
271
|
|
|
302
|
-
public async
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
let checkpoint = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
|
|
313
|
-
const slot = (b: CheckpointData) => b.header.slotNumber;
|
|
314
|
-
while (checkpoint && slot(checkpoint) >= start) {
|
|
315
|
-
if (slot(checkpoint) <= end) {
|
|
316
|
-
// push the blocks on backwards
|
|
317
|
-
const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
|
|
318
|
-
for (let i = endBlock; i >= checkpoint.startBlock; i--) {
|
|
319
|
-
const block = await this.getBlockHeader(BlockNumber(i));
|
|
320
|
-
if (block) {
|
|
321
|
-
blocks.push(block);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
checkpoint = await this.store.getCheckpointData(CheckpointNumber(checkpoint.checkpointNumber - 1));
|
|
326
|
-
}
|
|
327
|
-
return blocks.reverse();
|
|
272
|
+
public async getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
273
|
+
const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
|
|
274
|
+
const blocks = await Promise.all(
|
|
275
|
+
checkpointsData.flatMap(checkpoint =>
|
|
276
|
+
range(checkpoint.blockCount, checkpoint.startBlock).map(blockNumber =>
|
|
277
|
+
this.getBlockHeader(BlockNumber(blockNumber)),
|
|
278
|
+
),
|
|
279
|
+
),
|
|
280
|
+
);
|
|
281
|
+
return blocks.filter(isDefined);
|
|
328
282
|
}
|
|
329
283
|
|
|
330
284
|
public async getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
|
|
285
|
+
const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
|
|
286
|
+
return Promise.all(
|
|
287
|
+
checkpointsData.map(data => this.getPublishedCheckpointFromCheckpointData(data).then(p => p.checkpoint)),
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Returns checkpoint data for all checkpoints whose slot falls within the given epoch. */
|
|
292
|
+
public getCheckpointsDataForEpoch(epochNumber: EpochNumber): Promise<CheckpointData[]> {
|
|
331
293
|
if (!this.l1Constants) {
|
|
332
294
|
throw new Error('L1 constants not set');
|
|
333
295
|
}
|
|
334
296
|
|
|
335
297
|
const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
// Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
|
|
339
|
-
// We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
|
|
340
|
-
let checkpointData = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
|
|
341
|
-
const slot = (b: CheckpointData) => b.header.slotNumber;
|
|
342
|
-
while (checkpointData && slot(checkpointData) >= start) {
|
|
343
|
-
if (slot(checkpointData) <= end) {
|
|
344
|
-
// push the checkpoints on backwards
|
|
345
|
-
const [checkpoint] = await this.getPublishedCheckpoints(checkpointData.checkpointNumber, 1);
|
|
346
|
-
checkpoints.push(checkpoint.checkpoint);
|
|
347
|
-
}
|
|
348
|
-
checkpointData = await this.store.getCheckpointData(CheckpointNumber(checkpointData.checkpointNumber - 1));
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
return checkpoints.reverse();
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
public async getPublishedBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<CheckpointedL2Block[]> {
|
|
355
|
-
const checkpoints = await this.store.getRangeOfCheckpoints(CheckpointNumber(from), limit);
|
|
356
|
-
const provenCheckpointNumber = await this.store.getProvenCheckpointNumber();
|
|
357
|
-
const blocks = (
|
|
358
|
-
await Promise.all(checkpoints.map(ch => this.store.getBlocksForCheckpoint(ch.checkpointNumber)))
|
|
359
|
-
).filter(isDefined);
|
|
360
|
-
|
|
361
|
-
const publishedBlocks: CheckpointedL2Block[] = [];
|
|
362
|
-
for (let i = 0; i < checkpoints.length; i++) {
|
|
363
|
-
const blockForCheckpoint = blocks[i][0];
|
|
364
|
-
const checkpoint = checkpoints[i];
|
|
365
|
-
if (checkpoint.checkpointNumber > provenCheckpointNumber && proven === true) {
|
|
366
|
-
// this checkpoint isn't proven and we only want proven
|
|
367
|
-
continue;
|
|
368
|
-
}
|
|
369
|
-
const publishedBlock = new CheckpointedL2Block(
|
|
370
|
-
checkpoint.checkpointNumber,
|
|
371
|
-
blockForCheckpoint,
|
|
372
|
-
checkpoint.l1,
|
|
373
|
-
checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
|
|
374
|
-
);
|
|
375
|
-
publishedBlocks.push(publishedBlock);
|
|
376
|
-
}
|
|
377
|
-
return publishedBlocks;
|
|
298
|
+
return this.store.getCheckpointDataForSlotRange(start, end);
|
|
378
299
|
}
|
|
379
300
|
|
|
380
|
-
public async getBlock(number: BlockNumber): Promise<
|
|
301
|
+
public async getBlock(number: BlockNumber): Promise<L2Block | undefined> {
|
|
381
302
|
// If the number provided is -ve, then return the latest block.
|
|
382
303
|
if (number < 0) {
|
|
383
304
|
number = await this.store.getLatestBlockNumber();
|
|
@@ -388,30 +309,24 @@ export abstract class ArchiverDataSourceBase
|
|
|
388
309
|
return this.store.getBlock(number);
|
|
389
310
|
}
|
|
390
311
|
|
|
391
|
-
public
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
if (proven === true) {
|
|
395
|
-
const provenBlockNumber = await this.store.getProvenBlockNumber();
|
|
396
|
-
return blocks.filter(b => b.number <= provenBlockNumber);
|
|
397
|
-
}
|
|
398
|
-
return blocks;
|
|
312
|
+
public getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
313
|
+
return this.store.getBlocks(from, limit);
|
|
399
314
|
}
|
|
400
315
|
|
|
401
|
-
public
|
|
316
|
+
public getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
|
|
402
317
|
return this.store.getCheckpointedBlockByHash(blockHash);
|
|
403
318
|
}
|
|
404
319
|
|
|
405
|
-
public
|
|
320
|
+
public getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
|
|
406
321
|
return this.store.getCheckpointedBlockByArchive(archive);
|
|
407
322
|
}
|
|
408
323
|
|
|
409
|
-
public async
|
|
324
|
+
public async getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
410
325
|
const checkpointedBlock = await this.store.getCheckpointedBlockByHash(blockHash);
|
|
411
326
|
return checkpointedBlock?.block;
|
|
412
327
|
}
|
|
413
328
|
|
|
414
|
-
public async
|
|
329
|
+
public async getL2BlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
415
330
|
const checkpointedBlock = await this.store.getCheckpointedBlockByArchive(archive);
|
|
416
331
|
return checkpointedBlock?.block;
|
|
417
332
|
}
|