@aztec/archiver 0.0.1-commit.c7c42ec → 0.0.1-commit.f295ac2
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 +147 -22
- package/dest/archiver.d.ts +135 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +769 -0
- package/dest/{archiver/config.d.ts → config.d.ts} +9 -1
- package/dest/config.d.ts.map +1 -0
- package/dest/{archiver/config.js → config.js} +11 -2
- package/dest/{archiver/errors.d.ts → errors.d.ts} +1 -1
- package/dest/errors.d.ts.map +1 -0
- package/dest/factory.d.ts +5 -6
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +82 -5
- package/dest/index.d.ts +10 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +8 -3
- package/dest/interfaces.d.ts +9 -0
- package/dest/interfaces.d.ts.map +1 -0
- package/dest/interfaces.js +3 -0
- package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.d.ts +1 -1
- package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/calldata_retriever.d.ts +3 -3
- package/dest/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/calldata_retriever.js +2 -2
- package/dest/l1/data_retrieval.d.ts +88 -0
- package/dest/l1/data_retrieval.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/data_retrieval.js +34 -53
- package/dest/{archiver/l1 → l1}/debug_tx.d.ts +1 -1
- package/dest/l1/debug_tx.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/spire_proposer.d.ts +1 -1
- package/dest/l1/spire_proposer.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/trace_tx.d.ts +1 -1
- package/dest/l1/trace_tx.d.ts.map +1 -0
- package/dest/l1/types.d.ts +12 -0
- package/dest/l1/types.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/validate_trace.d.ts +1 -1
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/validate_trace.js +1 -1
- package/dest/modules/data_source_base.d.ts +85 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +291 -0
- package/dest/modules/data_store_updater.d.ts +69 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +304 -0
- package/dest/modules/instrumentation.d.ts +37 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/{archiver → modules}/instrumentation.js +15 -63
- package/dest/modules/l1_synchronizer.d.ts +75 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.js +1113 -0
- package/dest/modules/validation.d.ts +17 -0
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +7 -1
- package/dest/{archiver/kv_archiver_store → store}/block_store.d.ts +27 -6
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/block_store.js +87 -14
- package/dest/store/contract_class_store.d.ts +18 -0
- package/dest/store/contract_class_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +1 -1
- package/dest/store/contract_instance_store.d.ts +24 -0
- package/dest/store/contract_instance_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +1 -1
- package/dest/{archiver/archiver_store.d.ts → store/kv_archiver_store.d.ts} +155 -132
- package/dest/store/kv_archiver_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/kv_archiver_store.js +173 -48
- package/dest/{archiver/kv_archiver_store → store}/log_store.d.ts +1 -1
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/log_store.js +69 -48
- package/dest/{archiver/kv_archiver_store → store}/message_store.d.ts +1 -1
- package/dest/store/message_store.d.ts.map +1 -0
- package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
- package/dest/structs/data_retrieval.d.ts.map +1 -0
- package/dest/structs/inbox_message.d.ts +15 -0
- package/dest/structs/inbox_message.d.ts.map +1 -0
- package/dest/{archiver/structs → structs}/published.d.ts +1 -1
- package/dest/structs/published.d.ts.map +1 -0
- package/dest/test/fake_l1_state.d.ts +190 -0
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/fake_l1_state.js +383 -0
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +1 -0
- package/dest/test/mock_archiver.d.ts +2 -2
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +1 -2
- package/dest/test/mock_l1_to_l2_message_source.d.ts +2 -2
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +12 -3
- package/dest/test/mock_l2_block_source.d.ts +21 -14
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +147 -40
- package/dest/test/mock_structs.d.ts +76 -2
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +133 -2
- package/package.json +15 -17
- package/src/archiver.ts +525 -0
- package/src/{archiver/config.ts → config.ts} +13 -2
- package/src/factory.ts +118 -6
- package/src/index.ts +10 -3
- package/src/interfaces.ts +9 -0
- package/src/{archiver/l1 → l1}/calldata_retriever.ts +3 -3
- package/src/{archiver/l1 → l1}/data_retrieval.ts +54 -71
- package/src/{archiver/l1 → l1}/validate_trace.ts +1 -1
- package/src/modules/data_source_base.ts +414 -0
- package/src/modules/data_store_updater.ts +419 -0
- package/src/{archiver → modules}/instrumentation.ts +14 -63
- package/src/modules/l1_synchronizer.ts +931 -0
- package/src/{archiver → modules}/validation.ts +11 -6
- package/src/{archiver/kv_archiver_store → store}/block_store.ts +116 -19
- package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +1 -1
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +1 -1
- package/src/{archiver/kv_archiver_store → store}/kv_archiver_store.ts +196 -12
- package/src/{archiver/kv_archiver_store → store}/log_store.ts +112 -76
- package/src/test/fake_l1_state.ts +599 -0
- package/src/test/index.ts +1 -0
- package/src/test/mock_archiver.ts +2 -2
- package/src/test/mock_l1_to_l2_message_source.ts +10 -4
- package/src/test/mock_l2_block_source.ts +168 -52
- package/src/test/mock_structs.ts +247 -2
- package/dest/archiver/archiver.d.ts +0 -304
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -1645
- package/dest/archiver/archiver_store.d.ts.map +0 -1
- package/dest/archiver/archiver_store.js +0 -4
- package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
- package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
- package/dest/archiver/archiver_store_test_suite.js +0 -2770
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/index.d.ts +0 -7
- package/dest/archiver/index.d.ts.map +0 -1
- package/dest/archiver/index.js +0 -4
- package/dest/archiver/instrumentation.d.ts +0 -37
- package/dest/archiver/instrumentation.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -158
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
- package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +0 -1
- package/dest/archiver/l1/calldata_retriever.d.ts.map +0 -1
- package/dest/archiver/l1/data_retrieval.d.ts +0 -90
- package/dest/archiver/l1/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/l1/debug_tx.d.ts.map +0 -1
- package/dest/archiver/l1/spire_proposer.d.ts.map +0 -1
- package/dest/archiver/l1/trace_tx.d.ts.map +0 -1
- package/dest/archiver/l1/types.d.ts +0 -12
- package/dest/archiver/l1/types.d.ts.map +0 -1
- package/dest/archiver/l1/validate_trace.d.ts.map +0 -1
- package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/structs/inbox_message.d.ts +0 -15
- package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
- package/dest/archiver/structs/published.d.ts.map +0 -1
- package/dest/archiver/validation.d.ts +0 -17
- package/dest/archiver/validation.d.ts.map +0 -1
- package/dest/rpc/index.d.ts +0 -9
- package/dest/rpc/index.d.ts.map +0 -1
- package/dest/rpc/index.js +0 -15
- package/src/archiver/archiver.ts +0 -2157
- package/src/archiver/archiver_store.ts +0 -372
- package/src/archiver/archiver_store_test_suite.ts +0 -2843
- package/src/archiver/index.ts +0 -6
- package/src/rpc/index.ts +0 -16
- /package/dest/{archiver/errors.js → errors.js} +0 -0
- /package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.js +0 -0
- /package/dest/{archiver/l1 → l1}/debug_tx.js +0 -0
- /package/dest/{archiver/l1 → l1}/spire_proposer.js +0 -0
- /package/dest/{archiver/l1 → l1}/trace_tx.js +0 -0
- /package/dest/{archiver/l1 → l1}/types.js +0 -0
- /package/dest/{archiver/kv_archiver_store → store}/message_store.js +0 -0
- /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
- /package/dest/{archiver/structs → structs}/inbox_message.js +0 -0
- /package/dest/{archiver/structs → structs}/published.js +0 -0
- /package/src/{archiver/errors.ts → errors.ts} +0 -0
- /package/src/{archiver/l1 → l1}/README.md +0 -0
- /package/src/{archiver/l1 → l1}/bin/retrieve-calldata.ts +0 -0
- /package/src/{archiver/l1 → l1}/debug_tx.ts +0 -0
- /package/src/{archiver/l1 → l1}/spire_proposer.ts +0 -0
- /package/src/{archiver/l1 → l1}/trace_tx.ts +0 -0
- /package/src/{archiver/l1 → l1}/types.ts +0 -0
- /package/src/{archiver/kv_archiver_store → store}/message_store.ts +0 -0
- /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
- /package/src/{archiver/structs → structs}/inbox_message.ts +0 -0
- /package/src/{archiver/structs → structs}/published.ts +0 -0
|
@@ -4,15 +4,15 @@ import { compactArray } from '@aztec/foundation/collection';
|
|
|
4
4
|
import type { Logger } from '@aztec/foundation/log';
|
|
5
5
|
import {
|
|
6
6
|
type AttestationInfo,
|
|
7
|
-
type
|
|
8
|
-
type
|
|
7
|
+
type ValidateCheckpointNegativeResult,
|
|
8
|
+
type ValidateCheckpointResult,
|
|
9
9
|
getAttestationInfoFromPayload,
|
|
10
10
|
} from '@aztec/stdlib/block';
|
|
11
11
|
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
12
12
|
import { type L1RollupConstants, getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
13
13
|
import { ConsensusPayload } from '@aztec/stdlib/p2p';
|
|
14
14
|
|
|
15
|
-
export type {
|
|
15
|
+
export type { ValidateCheckpointResult };
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Extracts attestation information from a published checkpoint.
|
|
@@ -35,7 +35,7 @@ export async function validateCheckpointAttestations(
|
|
|
35
35
|
epochCache: EpochCache,
|
|
36
36
|
constants: Pick<L1RollupConstants, 'epochDuration'>,
|
|
37
37
|
logger?: Logger,
|
|
38
|
-
): Promise<
|
|
38
|
+
): Promise<ValidateCheckpointResult> {
|
|
39
39
|
const attestorInfos = getAttestationInfoFromPublishedCheckpoint(publishedCheckpoint);
|
|
40
40
|
const attestors = compactArray(attestorInfos.map(info => ('address' in info ? info.address : undefined)));
|
|
41
41
|
const { checkpoint, attestations } = publishedCheckpoint;
|
|
@@ -61,12 +61,17 @@ export async function validateCheckpointAttestations(
|
|
|
61
61
|
return { valid: true };
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
if (await epochCache.isEscapeHatchOpen(epoch)) {
|
|
65
|
+
logger?.warn(`Escape hatch open for epoch ${epoch} at slot ${slot}, skipping checkpoint validation`);
|
|
66
|
+
return { valid: true };
|
|
67
|
+
}
|
|
68
|
+
|
|
64
69
|
const requiredAttestationCount = Math.floor((committee.length * 2) / 3) + 1;
|
|
65
70
|
|
|
66
|
-
const failedValidationResult = <TReason extends
|
|
71
|
+
const failedValidationResult = <TReason extends ValidateCheckpointNegativeResult['reason']>(reason: TReason) => ({
|
|
67
72
|
valid: false as const,
|
|
68
73
|
reason,
|
|
69
|
-
|
|
74
|
+
checkpoint: checkpoint.toCheckpointInfo(),
|
|
70
75
|
committee,
|
|
71
76
|
seed,
|
|
72
77
|
epoch,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { INITIAL_CHECKPOINT_NUMBER, INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
|
-
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { BlockNumber, CheckpointNumber, IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
4
|
import { toArray } from '@aztec/foundation/iterable';
|
|
5
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
@@ -14,9 +14,9 @@ import {
|
|
|
14
14
|
CommitteeAttestation,
|
|
15
15
|
L2BlockHash,
|
|
16
16
|
L2BlockNew,
|
|
17
|
-
type
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
type ValidateCheckpointResult,
|
|
18
|
+
deserializeValidateCheckpointResult,
|
|
19
|
+
serializeValidateCheckpointResult,
|
|
20
20
|
} from '@aztec/stdlib/block';
|
|
21
21
|
import { L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
22
22
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
@@ -76,7 +76,7 @@ export type CheckpointData = {
|
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
|
-
* LMDB
|
|
79
|
+
* LMDB-based block storage for the archiver.
|
|
80
80
|
*/
|
|
81
81
|
export class BlockStore {
|
|
82
82
|
/** Map block number to block data */
|
|
@@ -350,6 +350,23 @@ export class BlockStore {
|
|
|
350
350
|
await this.#blockArchiveIndex.set(block.archive.root.toString(), block.number);
|
|
351
351
|
}
|
|
352
352
|
|
|
353
|
+
/** Deletes a block and all associated data (tx effects, indices). */
|
|
354
|
+
private async deleteBlock(block: L2BlockNew): Promise<void> {
|
|
355
|
+
// Delete the block from the main blocks map
|
|
356
|
+
await this.#blocks.delete(block.number);
|
|
357
|
+
|
|
358
|
+
// Delete all tx effects for this block
|
|
359
|
+
await Promise.all(block.body.txEffects.map(tx => this.#txEffects.delete(tx.txHash.toString())));
|
|
360
|
+
|
|
361
|
+
// Delete block txs mapping
|
|
362
|
+
const blockHash = (await block.hash()).toString();
|
|
363
|
+
await this.#blockTxs.delete(blockHash);
|
|
364
|
+
|
|
365
|
+
// Clean up indices
|
|
366
|
+
await this.#blockHashIndex.delete(blockHash);
|
|
367
|
+
await this.#blockArchiveIndex.delete(block.archive.root.toString());
|
|
368
|
+
}
|
|
369
|
+
|
|
353
370
|
/**
|
|
354
371
|
* Unwinds checkpoints from the database
|
|
355
372
|
* @param from - The tip of the chain, passed for verification purposes,
|
|
@@ -387,16 +404,11 @@ export class BlockStore {
|
|
|
387
404
|
this.#log.warn(`Cannot remove block ${blockNumber} from the store since we don't have it`);
|
|
388
405
|
continue;
|
|
389
406
|
}
|
|
390
|
-
await this.#blocks.delete(block.number);
|
|
391
|
-
await Promise.all(block.body.txEffects.map(tx => this.#txEffects.delete(tx.txHash.toString())));
|
|
392
|
-
const blockHash = (await block.hash()).toString();
|
|
393
|
-
await this.#blockTxs.delete(blockHash);
|
|
394
|
-
|
|
395
|
-
// Clean up indices
|
|
396
|
-
await this.#blockHashIndex.delete(blockHash);
|
|
397
|
-
await this.#blockArchiveIndex.delete(block.archive.root.toString());
|
|
398
407
|
|
|
399
|
-
this
|
|
408
|
+
await this.deleteBlock(block);
|
|
409
|
+
this.#log.debug(
|
|
410
|
+
`Unwound block ${blockNumber} ${(await block.hash()).toString()} for checkpoint ${checkpointNumber}`,
|
|
411
|
+
);
|
|
400
412
|
}
|
|
401
413
|
}
|
|
402
414
|
|
|
@@ -454,6 +466,61 @@ export class BlockStore {
|
|
|
454
466
|
return converted.filter(isDefined);
|
|
455
467
|
}
|
|
456
468
|
|
|
469
|
+
/**
|
|
470
|
+
* Gets all blocks that have the given slot number.
|
|
471
|
+
* Iterates backwards through blocks for efficiency since we usually query for the last slot.
|
|
472
|
+
* @param slotNumber - The slot number to search for.
|
|
473
|
+
* @returns All blocks with the given slot number, in ascending block number order.
|
|
474
|
+
*/
|
|
475
|
+
async getBlocksForSlot(slotNumber: SlotNumber): Promise<L2BlockNew[]> {
|
|
476
|
+
const blocks: L2BlockNew[] = [];
|
|
477
|
+
|
|
478
|
+
// Iterate backwards through all blocks and filter by slot number
|
|
479
|
+
// This is more efficient since we usually query for the most recent slot
|
|
480
|
+
for await (const [blockNumber, blockStorage] of this.#blocks.entriesAsync({ reverse: true })) {
|
|
481
|
+
const block = await this.getBlockFromBlockStorage(blockNumber, blockStorage);
|
|
482
|
+
const blockSlot = block?.header.globalVariables.slotNumber;
|
|
483
|
+
if (block && blockSlot === slotNumber) {
|
|
484
|
+
blocks.push(block);
|
|
485
|
+
} else if (blockSlot && blockSlot < slotNumber) {
|
|
486
|
+
break; // Blocks are stored in slot ascending order, so we can stop searching
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// Reverse to return blocks in ascending order (block number order)
|
|
491
|
+
return blocks.reverse();
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Removes all blocks with block number > blockNumber.
|
|
496
|
+
* @param blockNumber - The block number to remove after.
|
|
497
|
+
* @returns The removed blocks (for event emission).
|
|
498
|
+
*/
|
|
499
|
+
async unwindBlocksAfter(blockNumber: BlockNumber): Promise<L2BlockNew[]> {
|
|
500
|
+
return await this.db.transactionAsync(async () => {
|
|
501
|
+
const removedBlocks: L2BlockNew[] = [];
|
|
502
|
+
|
|
503
|
+
// Get the latest block number to determine the range
|
|
504
|
+
const latestBlockNumber = await this.getLatestBlockNumber();
|
|
505
|
+
|
|
506
|
+
// Iterate from blockNumber + 1 to latestBlockNumber
|
|
507
|
+
for (let bn = blockNumber + 1; bn <= latestBlockNumber; bn++) {
|
|
508
|
+
const block = await this.getBlock(BlockNumber(bn));
|
|
509
|
+
|
|
510
|
+
if (block === undefined) {
|
|
511
|
+
this.#log.warn(`Cannot remove block ${bn} from the store since we don't have it`);
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
removedBlocks.push(block);
|
|
516
|
+
await this.deleteBlock(block);
|
|
517
|
+
this.#log.debug(`Removed block ${bn} ${(await block.hash()).toString()}`);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
return removedBlocks;
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
|
|
457
524
|
async getProvenBlockNumber(): Promise<BlockNumber> {
|
|
458
525
|
const provenCheckpointNumber = await this.getProvenCheckpointNumber();
|
|
459
526
|
if (provenCheckpointNumber === INITIAL_CHECKPOINT_NUMBER - 1) {
|
|
@@ -503,6 +570,34 @@ export class BlockStore {
|
|
|
503
570
|
);
|
|
504
571
|
}
|
|
505
572
|
|
|
573
|
+
/**
|
|
574
|
+
* Gets up to `limit` amount of Checkpointed L2 blocks starting from `from`.
|
|
575
|
+
* @param start - Number of the first block to return (inclusive).
|
|
576
|
+
* @param limit - The number of blocks to return.
|
|
577
|
+
* @returns The requested L2 blocks
|
|
578
|
+
*/
|
|
579
|
+
async *getCheckpointedBlocks(start: BlockNumber, limit: number): AsyncIterableIterator<CheckpointedL2Block> {
|
|
580
|
+
const checkpointCache = new Map<CheckpointNumber, CheckpointStorage>();
|
|
581
|
+
for await (const [blockNumber, blockStorage] of this.getBlockStorages(start, limit)) {
|
|
582
|
+
const block = await this.getBlockFromBlockStorage(blockNumber, blockStorage);
|
|
583
|
+
if (block) {
|
|
584
|
+
const checkpoint =
|
|
585
|
+
checkpointCache.get(CheckpointNumber(blockStorage.checkpointNumber)) ??
|
|
586
|
+
(await this.#checkpoints.getAsync(blockStorage.checkpointNumber));
|
|
587
|
+
if (checkpoint) {
|
|
588
|
+
checkpointCache.set(CheckpointNumber(blockStorage.checkpointNumber), checkpoint);
|
|
589
|
+
const checkpointedBlock = new CheckpointedL2Block(
|
|
590
|
+
CheckpointNumber(checkpoint.checkpointNumber),
|
|
591
|
+
block,
|
|
592
|
+
L1PublishedData.fromBuffer(checkpoint.l1),
|
|
593
|
+
checkpoint.attestations.map(buf => CommitteeAttestation.fromBuffer(buf)),
|
|
594
|
+
);
|
|
595
|
+
yield checkpointedBlock;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
506
601
|
async getCheckpointedBlockByHash(blockHash: Fr): Promise<CheckpointedL2Block | undefined> {
|
|
507
602
|
const blockNumber = await this.#blockHashIndex.getAsync(blockHash.toString());
|
|
508
603
|
if (blockNumber === undefined) {
|
|
@@ -510,6 +605,7 @@ export class BlockStore {
|
|
|
510
605
|
}
|
|
511
606
|
return this.getCheckpointedBlock(BlockNumber(blockNumber));
|
|
512
607
|
}
|
|
608
|
+
|
|
513
609
|
async getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
|
|
514
610
|
const blockNumber = await this.#blockArchiveIndex.getAsync(archive.toString());
|
|
515
611
|
if (blockNumber === undefined) {
|
|
@@ -644,6 +740,7 @@ export class BlockStore {
|
|
|
644
740
|
const header = BlockHeader.fromBuffer(blockStorage.header);
|
|
645
741
|
const archive = AppendOnlyTreeSnapshot.fromBuffer(blockStorage.archive);
|
|
646
742
|
const blockHash = blockStorage.blockHash;
|
|
743
|
+
header.setHash(Fr.fromBuffer(blockHash));
|
|
647
744
|
const blockHashString = bufferToHex(blockHash);
|
|
648
745
|
const blockTxsBuffer = await this.#blockTxs.getAsync(blockHashString);
|
|
649
746
|
if (blockTxsBuffer === undefined) {
|
|
@@ -668,7 +765,7 @@ export class BlockStore {
|
|
|
668
765
|
header,
|
|
669
766
|
body,
|
|
670
767
|
CheckpointNumber(blockStorage.checkpointNumber!),
|
|
671
|
-
blockStorage.indexWithinCheckpoint,
|
|
768
|
+
IndexWithinCheckpoint(blockStorage.indexWithinCheckpoint),
|
|
672
769
|
);
|
|
673
770
|
|
|
674
771
|
if (block.number !== blockNumber) {
|
|
@@ -799,21 +896,21 @@ export class BlockStore {
|
|
|
799
896
|
* Gets the pending chain validation status.
|
|
800
897
|
* @returns The validation status or undefined if not set.
|
|
801
898
|
*/
|
|
802
|
-
async getPendingChainValidationStatus(): Promise<
|
|
899
|
+
async getPendingChainValidationStatus(): Promise<ValidateCheckpointResult | undefined> {
|
|
803
900
|
const buffer = await this.#pendingChainValidationStatus.getAsync();
|
|
804
901
|
if (!buffer) {
|
|
805
902
|
return undefined;
|
|
806
903
|
}
|
|
807
|
-
return
|
|
904
|
+
return deserializeValidateCheckpointResult(buffer);
|
|
808
905
|
}
|
|
809
906
|
|
|
810
907
|
/**
|
|
811
908
|
* Sets the pending chain validation status.
|
|
812
909
|
* @param status - The validation status to store.
|
|
813
910
|
*/
|
|
814
|
-
async setPendingChainValidationStatus(status:
|
|
911
|
+
async setPendingChainValidationStatus(status: ValidateCheckpointResult | undefined): Promise<void> {
|
|
815
912
|
if (status) {
|
|
816
|
-
const buffer =
|
|
913
|
+
const buffer = serializeValidateCheckpointResult(status);
|
|
817
914
|
await this.#pendingChainValidationStatus.set(buffer);
|
|
818
915
|
} else {
|
|
819
916
|
await this.#pendingChainValidationStatus.delete();
|
|
@@ -12,7 +12,7 @@ import type {
|
|
|
12
12
|
import { Vector } from '@aztec/stdlib/types';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* LMDB
|
|
15
|
+
* LMDB-based contract class storage for the archiver.
|
|
16
16
|
*/
|
|
17
17
|
export class ContractClassStore {
|
|
18
18
|
#contractClasses: AztecAsyncMap<string, Buffer>;
|
|
@@ -12,7 +12,7 @@ import type { UInt64 } from '@aztec/stdlib/types';
|
|
|
12
12
|
type ContractInstanceUpdateKey = [string, string] | [string, string, number];
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* LMDB
|
|
15
|
+
* LMDB-based contract instance storage for the archiver.
|
|
16
16
|
*/
|
|
17
17
|
export class ContractInstanceStore {
|
|
18
18
|
#contractInstances: AztecAsyncMap<string, Buffer>;
|