@aztec/archiver 0.0.1-commit.d431d1c → 0.0.1-commit.d939eb5aa
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 +21 -6
- package/dest/archiver.d.ts +17 -12
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +108 -127
- package/dest/config.d.ts +3 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +3 -2
- package/dest/errors.d.ts +39 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +52 -15
- 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 +191 -259
- package/dest/l1/data_retrieval.d.ts +11 -11
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +38 -37
- 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 +29 -23
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +55 -124
- package/dest/modules/data_store_updater.d.ts +43 -26
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +158 -129
- package/dest/modules/instrumentation.d.ts +19 -4
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +53 -18
- package/dest/modules/l1_synchronizer.d.ts +7 -9
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +186 -145
- package/dest/modules/validation.d.ts +1 -1
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +2 -2
- package/dest/store/block_store.d.ts +86 -34
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +414 -152
- 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 +80 -39
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +86 -35
- 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 +9 -6
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +151 -56
- 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 +24 -4
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +133 -26
- 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_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 +44 -23
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +185 -115
- 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 +71 -0
- package/package.json +14 -13
- package/src/archiver.ts +144 -159
- package/src/config.ts +9 -2
- package/src/errors.ts +82 -26
- 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 +250 -379
- package/src/l1/data_retrieval.ts +35 -41
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_trace.ts +24 -6
- package/src/modules/data_source_base.ts +98 -169
- package/src/modules/data_store_updater.ts +178 -160
- package/src/modules/instrumentation.ts +64 -20
- package/src/modules/l1_synchronizer.ts +212 -182
- package/src/modules/validation.ts +2 -2
- package/src/store/block_store.ts +533 -207
- 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 +141 -59
- package/src/store/l2_tips_cache.ts +134 -0
- package/src/store/log_store.ts +232 -74
- package/src/store/message_store.ts +27 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +180 -32
- package/src/test/index.ts +3 -0
- 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 +247 -130
- package/src/test/mock_structs.ts +45 -15
- package/src/test/noop_l1_archiver.ts +114 -0
|
@@ -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 {
|
|
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
|
|
|
@@ -87,10 +93,14 @@ export abstract class ArchiverDataSourceBase
|
|
|
87
93
|
return this.store.getCheckpointedBlock(number);
|
|
88
94
|
}
|
|
89
95
|
|
|
90
|
-
public
|
|
96
|
+
public getCheckpointedL2BlockNumber(): Promise<BlockNumber> {
|
|
91
97
|
return this.store.getCheckpointedL2BlockNumber();
|
|
92
98
|
}
|
|
93
99
|
|
|
100
|
+
public getFinalizedL2BlockNumber(): Promise<BlockNumber> {
|
|
101
|
+
return this.store.getFinalizedL2BlockNumber();
|
|
102
|
+
}
|
|
103
|
+
|
|
94
104
|
public async getCheckpointHeader(number: CheckpointNumber | 'latest'): Promise<CheckpointHeader | undefined> {
|
|
95
105
|
if (number === 'latest') {
|
|
96
106
|
number = await this.store.getSynchedCheckpointNumber();
|
|
@@ -110,24 +120,14 @@ export abstract class ArchiverDataSourceBase
|
|
|
110
120
|
if (!checkpointData) {
|
|
111
121
|
return undefined;
|
|
112
122
|
}
|
|
113
|
-
return BlockNumber(checkpointData.startBlock + checkpointData.
|
|
123
|
+
return BlockNumber(checkpointData.startBlock + checkpointData.blockCount - 1);
|
|
114
124
|
}
|
|
115
125
|
|
|
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;
|
|
126
|
+
public getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
|
|
127
|
+
return this.store.getCheckpointedBlocks(from, limit);
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
public getBlockHeaderByHash(blockHash:
|
|
130
|
+
public getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
|
|
131
131
|
return this.store.getBlockHeaderByHash(blockHash);
|
|
132
132
|
}
|
|
133
133
|
|
|
@@ -135,7 +135,15 @@ export abstract class ArchiverDataSourceBase
|
|
|
135
135
|
return this.store.getBlockHeaderByArchive(archive);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
public
|
|
138
|
+
public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
139
|
+
return this.store.getBlockData(number);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
143
|
+
return this.store.getBlockDataByArchive(archive);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
public async getL2Block(number: BlockNumber): Promise<L2Block | undefined> {
|
|
139
147
|
// If the number provided is -ve, then return the latest block.
|
|
140
148
|
if (number < 0) {
|
|
141
149
|
number = await this.store.getLatestBlockNumber();
|
|
@@ -152,7 +160,15 @@ export abstract class ArchiverDataSourceBase
|
|
|
152
160
|
}
|
|
153
161
|
|
|
154
162
|
public getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
|
|
155
|
-
return this.store.getSettledTxReceipt(txHash);
|
|
163
|
+
return this.store.getSettledTxReceipt(txHash, this.l1Constants);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public getProposedCheckpoint(): Promise<CommonCheckpointData | undefined> {
|
|
167
|
+
return this.store.getProposedCheckpoint();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public getProposedCheckpointOnly(): Promise<ProposedCheckpointData | undefined> {
|
|
171
|
+
return this.store.getProposedCheckpointOnly();
|
|
156
172
|
}
|
|
157
173
|
|
|
158
174
|
public isPendingChainInvalid(): Promise<boolean> {
|
|
@@ -163,26 +179,21 @@ export abstract class ArchiverDataSourceBase
|
|
|
163
179
|
return (await this.store.getPendingChainValidationStatus()) ?? { valid: true };
|
|
164
180
|
}
|
|
165
181
|
|
|
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);
|
|
182
|
+
public getPrivateLogsByTags(
|
|
183
|
+
tags: SiloedTag[],
|
|
184
|
+
page?: number,
|
|
185
|
+
upToBlockNumber?: BlockNumber,
|
|
186
|
+
): Promise<TxScopedL2Log[][]> {
|
|
187
|
+
return this.store.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
178
188
|
}
|
|
179
189
|
|
|
180
190
|
public getPublicLogsByTagsFromContract(
|
|
181
191
|
contractAddress: AztecAddress,
|
|
182
192
|
tags: Tag[],
|
|
183
193
|
page?: number,
|
|
194
|
+
upToBlockNumber?: BlockNumber,
|
|
184
195
|
): Promise<TxScopedL2Log[][]> {
|
|
185
|
-
return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
196
|
+
return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
186
197
|
}
|
|
187
198
|
|
|
188
199
|
public getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
|
|
@@ -237,147 +248,71 @@ export abstract class ArchiverDataSourceBase
|
|
|
237
248
|
return this.store.getL1ToL2MessageIndex(l1ToL2Message);
|
|
238
249
|
}
|
|
239
250
|
|
|
240
|
-
public async
|
|
241
|
-
checkpointNumber: CheckpointNumber,
|
|
242
|
-
limit: number,
|
|
243
|
-
): Promise<PublishedCheckpoint[]> {
|
|
251
|
+
public async getCheckpoints(checkpointNumber: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
244
252
|
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);
|
|
253
|
+
return Promise.all(checkpoints.map(ch => this.getPublishedCheckpointFromCheckpointData(ch)));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
private async getPublishedCheckpointFromCheckpointData(checkpoint: CheckpointData): Promise<PublishedCheckpoint> {
|
|
257
|
+
const blocksForCheckpoint = await this.store.getBlocksForCheckpoint(checkpoint.checkpointNumber);
|
|
258
|
+
if (!blocksForCheckpoint) {
|
|
259
|
+
throw new Error(`Blocks for checkpoint ${checkpoint.checkpointNumber} not found`);
|
|
265
260
|
}
|
|
266
|
-
|
|
261
|
+
const fullCheckpoint = new Checkpoint(
|
|
262
|
+
checkpoint.archive,
|
|
263
|
+
checkpoint.header,
|
|
264
|
+
blocksForCheckpoint,
|
|
265
|
+
checkpoint.checkpointNumber,
|
|
266
|
+
);
|
|
267
|
+
return new PublishedCheckpoint(fullCheckpoint, checkpoint.l1, checkpoint.attestations);
|
|
267
268
|
}
|
|
268
269
|
|
|
269
|
-
public getBlocksForSlot(slotNumber: SlotNumber): Promise<
|
|
270
|
+
public getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
|
|
270
271
|
return this.store.getBlocksForSlot(slotNumber);
|
|
271
272
|
}
|
|
272
273
|
|
|
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();
|
|
274
|
+
public async getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]> {
|
|
275
|
+
const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
|
|
276
|
+
const blocks = await Promise.all(
|
|
277
|
+
checkpointsData.flatMap(checkpoint =>
|
|
278
|
+
range(checkpoint.blockCount, checkpoint.startBlock).map(blockNumber =>
|
|
279
|
+
this.getCheckpointedBlock(BlockNumber(blockNumber)),
|
|
280
|
+
),
|
|
281
|
+
),
|
|
282
|
+
);
|
|
283
|
+
return blocks.filter(isDefined);
|
|
300
284
|
}
|
|
301
285
|
|
|
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();
|
|
286
|
+
public async getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
287
|
+
const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
|
|
288
|
+
const blocks = await Promise.all(
|
|
289
|
+
checkpointsData.flatMap(checkpoint =>
|
|
290
|
+
range(checkpoint.blockCount, checkpoint.startBlock).map(blockNumber =>
|
|
291
|
+
this.getBlockHeader(BlockNumber(blockNumber)),
|
|
292
|
+
),
|
|
293
|
+
),
|
|
294
|
+
);
|
|
295
|
+
return blocks.filter(isDefined);
|
|
328
296
|
}
|
|
329
297
|
|
|
330
298
|
public async getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
|
|
299
|
+
const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
|
|
300
|
+
return Promise.all(
|
|
301
|
+
checkpointsData.map(data => this.getPublishedCheckpointFromCheckpointData(data).then(p => p.checkpoint)),
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** Returns checkpoint data for all checkpoints whose slot falls within the given epoch. */
|
|
306
|
+
public getCheckpointsDataForEpoch(epochNumber: EpochNumber): Promise<CheckpointData[]> {
|
|
331
307
|
if (!this.l1Constants) {
|
|
332
308
|
throw new Error('L1 constants not set');
|
|
333
309
|
}
|
|
334
310
|
|
|
335
311
|
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;
|
|
312
|
+
return this.store.getCheckpointDataForSlotRange(start, end);
|
|
378
313
|
}
|
|
379
314
|
|
|
380
|
-
public async getBlock(number: BlockNumber): Promise<
|
|
315
|
+
public async getBlock(number: BlockNumber): Promise<L2Block | undefined> {
|
|
381
316
|
// If the number provided is -ve, then return the latest block.
|
|
382
317
|
if (number < 0) {
|
|
383
318
|
number = await this.store.getLatestBlockNumber();
|
|
@@ -388,30 +323,24 @@ export abstract class ArchiverDataSourceBase
|
|
|
388
323
|
return this.store.getBlock(number);
|
|
389
324
|
}
|
|
390
325
|
|
|
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;
|
|
326
|
+
public getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
327
|
+
return this.store.getBlocks(from, limit);
|
|
399
328
|
}
|
|
400
329
|
|
|
401
|
-
public
|
|
330
|
+
public getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
|
|
402
331
|
return this.store.getCheckpointedBlockByHash(blockHash);
|
|
403
332
|
}
|
|
404
333
|
|
|
405
|
-
public
|
|
334
|
+
public getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
|
|
406
335
|
return this.store.getCheckpointedBlockByArchive(archive);
|
|
407
336
|
}
|
|
408
337
|
|
|
409
|
-
public async
|
|
338
|
+
public async getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
410
339
|
const checkpointedBlock = await this.store.getCheckpointedBlockByHash(blockHash);
|
|
411
340
|
return checkpointedBlock?.block;
|
|
412
341
|
}
|
|
413
342
|
|
|
414
|
-
public async
|
|
343
|
+
public async getL2BlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
415
344
|
const checkpointedBlock = await this.store.getCheckpointedBlockByArchive(archive);
|
|
416
345
|
return checkpointedBlock?.block;
|
|
417
346
|
}
|