@aztec/stdlib 0.0.1-commit.03f7ef2 → 0.0.1-commit.1142ef1
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/dest/abi/contract_artifact.d.ts +2 -2
- package/dest/abi/contract_artifact.d.ts.map +1 -1
- package/dest/abi/contract_artifact.js +1 -1
- package/dest/abi/selector.js +3 -1
- package/dest/avm/avm_accumulated_data.js +5 -2
- package/dest/avm/avm_circuit_public_inputs.js +3 -1
- package/dest/avm/public_data_update_request.js +3 -1
- package/dest/avm/public_inner_call_request.js +3 -1
- package/dest/avm/revert_code.js +3 -1
- package/dest/aztec-address/index.js +4 -2
- package/dest/block/attestation_info.d.ts +5 -5
- package/dest/block/attestation_info.d.ts.map +1 -1
- package/dest/block/attestation_info.js +4 -4
- package/dest/block/body.js +3 -1
- package/dest/block/l2_block.d.ts +6 -3
- package/dest/block/l2_block.d.ts.map +1 -1
- package/dest/block/l2_block.js +6 -4
- package/dest/block/l2_block_code_to_purge.d.ts +2 -3
- package/dest/block/l2_block_code_to_purge.d.ts.map +1 -1
- package/dest/block/l2_block_code_to_purge.js +2 -8
- package/dest/block/l2_block_header.d.ts +8 -12
- package/dest/block/l2_block_header.d.ts.map +1 -1
- package/dest/block/l2_block_header.js +25 -18
- package/dest/block/l2_block_new.d.ts +1 -2
- package/dest/block/l2_block_new.d.ts.map +1 -1
- package/dest/block/l2_block_new.js +4 -1
- package/dest/block/l2_block_source.d.ts +245 -41
- package/dest/block/l2_block_source.d.ts.map +1 -1
- package/dest/block/l2_block_source.js +23 -5
- package/dest/block/l2_block_stream/index.d.ts +2 -1
- package/dest/block/l2_block_stream/index.d.ts.map +1 -1
- package/dest/block/l2_block_stream/index.js +1 -0
- package/dest/block/l2_block_stream/interfaces.d.ts +12 -5
- package/dest/block/l2_block_stream/interfaces.d.ts.map +1 -1
- package/dest/block/l2_block_stream/l2_block_stream.d.ts +4 -2
- package/dest/block/l2_block_stream/l2_block_stream.d.ts.map +1 -1
- package/dest/block/l2_block_stream/l2_block_stream.js +102 -30
- package/dest/block/l2_block_stream/l2_tips_memory_store.d.ts +24 -16
- package/dest/block/l2_block_stream/l2_tips_memory_store.d.ts.map +1 -1
- package/dest/block/l2_block_stream/l2_tips_memory_store.js +55 -61
- package/dest/block/l2_block_stream/l2_tips_store_base.d.ts +49 -0
- package/dest/block/l2_block_stream/l2_tips_store_base.d.ts.map +1 -0
- package/dest/block/l2_block_stream/l2_tips_store_base.js +179 -0
- package/dest/block/test/l2_tips_store_test_suite.d.ts +1 -1
- package/dest/block/test/l2_tips_store_test_suite.d.ts.map +1 -1
- package/dest/block/test/l2_tips_store_test_suite.js +483 -38
- package/dest/block/validate_block_result.d.ts +24 -24
- package/dest/block/validate_block_result.d.ts.map +1 -1
- package/dest/block/validate_block_result.js +13 -13
- package/dest/checkpoint/checkpoint.d.ts +1 -1
- package/dest/checkpoint/checkpoint.d.ts.map +1 -1
- package/dest/checkpoint/checkpoint.js +1 -0
- package/dest/checkpoint/checkpoint_info.d.ts +32 -3
- package/dest/checkpoint/checkpoint_info.d.ts.map +1 -1
- package/dest/checkpoint/checkpoint_info.js +34 -1
- package/dest/checkpoint/index.d.ts +2 -1
- package/dest/checkpoint/index.d.ts.map +1 -1
- package/dest/checkpoint/index.js +1 -0
- package/dest/database-version/version_manager.js +3 -1
- package/dest/gas/gas.js +3 -1
- package/dest/gas/gas_fees.js +3 -1
- package/dest/interfaces/api_limit.d.ts +2 -1
- package/dest/interfaces/api_limit.d.ts.map +1 -1
- package/dest/interfaces/api_limit.js +1 -0
- package/dest/interfaces/archiver.d.ts +6 -6
- package/dest/interfaces/archiver.d.ts.map +1 -1
- package/dest/interfaces/archiver.js +6 -4
- package/dest/interfaces/aztec-node-admin.d.ts +16 -10
- package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
- package/dest/interfaces/aztec-node-admin.js +3 -3
- package/dest/interfaces/aztec-node.d.ts +11 -10
- package/dest/interfaces/aztec-node.d.ts.map +1 -1
- package/dest/interfaces/aztec-node.js +10 -5
- package/dest/interfaces/configs.d.ts +6 -1
- package/dest/interfaces/configs.d.ts.map +1 -1
- package/dest/interfaces/configs.js +2 -1
- package/dest/interfaces/p2p.d.ts +7 -9
- package/dest/interfaces/p2p.d.ts.map +1 -1
- package/dest/interfaces/p2p.js +3 -4
- package/dest/interfaces/proving-job.d.ts +170 -170
- package/dest/interfaces/proving-job.d.ts.map +1 -1
- package/dest/interfaces/proving-job.js +1 -7
- package/dest/interfaces/server_circuit_prover.d.ts +4 -3
- package/dest/interfaces/server_circuit_prover.d.ts.map +1 -1
- package/dest/interfaces/validator.d.ts +41 -7
- package/dest/interfaces/validator.d.ts.map +1 -1
- package/dest/interfaces/validator.js +3 -1
- package/dest/interfaces/world_state.d.ts +8 -6
- package/dest/interfaces/world_state.d.ts.map +1 -1
- package/dest/kernel/claimed_length_array.js +3 -1
- package/dest/kernel/hints/build_note_hash_read_request_hints.d.ts +6 -5
- package/dest/kernel/hints/build_note_hash_read_request_hints.d.ts.map +1 -1
- package/dest/kernel/hints/build_note_hash_read_request_hints.js +5 -6
- package/dest/kernel/hints/transient_data_squashing_hint.js +3 -1
- package/dest/kernel/log_hash.js +3 -1
- package/dest/kernel/private_log_data.js +5 -2
- package/dest/kernel/private_to_avm_accumulated_data.js +5 -2
- package/dest/kernel/private_to_public_accumulated_data.js +3 -1
- package/dest/kernel/private_to_rollup_accumulated_data.js +3 -1
- package/dest/kernel/private_validation_requests.js +3 -1
- package/dest/kernel/public_call_request.js +5 -2
- package/dest/logs/contract_class_log.js +3 -1
- package/dest/logs/index.d.ts +1 -2
- package/dest/logs/index.d.ts.map +1 -1
- package/dest/logs/index.js +0 -1
- package/dest/logs/private_log.js +3 -1
- package/dest/logs/public_log.js +3 -1
- package/dest/logs/tx_scoped_l2_log.d.ts +18 -39
- package/dest/logs/tx_scoped_l2_log.d.ts.map +1 -1
- package/dest/logs/tx_scoped_l2_log.js +29 -50
- package/dest/messaging/in_hash.d.ts +4 -2
- package/dest/messaging/in_hash.d.ts.map +1 -1
- package/dest/messaging/in_hash.js +3 -1
- package/dest/messaging/l2_to_l1_membership.d.ts +88 -6
- package/dest/messaging/l2_to_l1_membership.d.ts.map +1 -1
- package/dest/messaging/l2_to_l1_membership.js +158 -42
- package/dest/messaging/out_hash.d.ts +2 -1
- package/dest/messaging/out_hash.d.ts.map +1 -1
- package/dest/messaging/out_hash.js +13 -4
- package/dest/p2p/attestation_utils.d.ts +3 -3
- package/dest/p2p/attestation_utils.d.ts.map +1 -1
- package/dest/p2p/attestation_utils.js +1 -1
- package/dest/p2p/block_proposal.d.ts +85 -21
- package/dest/p2p/block_proposal.d.ts.map +1 -1
- package/dest/p2p/block_proposal.js +120 -37
- package/dest/p2p/checkpoint_attestation.d.ts +77 -0
- package/dest/p2p/checkpoint_attestation.d.ts.map +1 -0
- package/dest/p2p/{block_attestation.js → checkpoint_attestation.js} +22 -19
- package/dest/p2p/checkpoint_proposal.d.ts +154 -0
- package/dest/p2p/checkpoint_proposal.d.ts.map +1 -0
- package/dest/p2p/checkpoint_proposal.js +217 -0
- package/dest/p2p/consensus_payload.d.ts +6 -7
- package/dest/p2p/consensus_payload.d.ts.map +1 -1
- package/dest/p2p/consensus_payload.js +3 -2
- package/dest/p2p/gossipable.d.ts +4 -3
- package/dest/p2p/gossipable.d.ts.map +1 -1
- package/dest/p2p/gossipable.js +16 -5
- package/dest/p2p/index.d.ts +4 -2
- package/dest/p2p/index.d.ts.map +1 -1
- package/dest/p2p/index.js +3 -1
- package/dest/p2p/signature_utils.d.ts +5 -3
- package/dest/p2p/signature_utils.d.ts.map +1 -1
- package/dest/p2p/signature_utils.js +3 -1
- package/dest/p2p/signed_txs.d.ts +40 -0
- package/dest/p2p/signed_txs.d.ts.map +1 -0
- package/dest/p2p/signed_txs.js +70 -0
- package/dest/p2p/topic_type.d.ts +3 -2
- package/dest/p2p/topic_type.d.ts.map +1 -1
- package/dest/p2p/topic_type.js +8 -2
- package/dest/rollup/block_rollup_public_inputs.d.ts +4 -9
- package/dest/rollup/block_rollup_public_inputs.d.ts.map +1 -1
- package/dest/rollup/block_rollup_public_inputs.js +6 -10
- package/dest/rollup/checkpoint_constant_data.js +3 -1
- package/dest/rollup/checkpoint_header.d.ts +15 -12
- package/dest/rollup/checkpoint_header.d.ts.map +1 -1
- package/dest/rollup/checkpoint_header.js +33 -19
- package/dest/rollup/checkpoint_rollup_public_inputs.d.ts +6 -1
- package/dest/rollup/checkpoint_rollup_public_inputs.d.ts.map +1 -1
- package/dest/rollup/checkpoint_rollup_public_inputs.js +6 -2
- package/dest/rollup/root_rollup_public_inputs.d.ts +8 -3
- package/dest/rollup/root_rollup_public_inputs.d.ts.map +1 -1
- package/dest/rollup/root_rollup_public_inputs.js +6 -3
- package/dest/tests/factories.d.ts +38 -7
- package/dest/tests/factories.d.ts.map +1 -1
- package/dest/tests/factories.js +77 -13
- package/dest/tests/mocks.d.ts +59 -10
- package/dest/tests/mocks.d.ts.map +1 -1
- package/dest/tests/mocks.js +89 -41
- package/dest/trees/append_only_tree_snapshot.js +3 -1
- package/dest/tx/block_header.js +3 -1
- package/dest/tx/call_context.js +3 -1
- package/dest/tx/global_variable_builder.d.ts +2 -2
- package/dest/tx/global_variable_builder.d.ts.map +1 -1
- package/dest/tx/global_variables.js +3 -1
- package/dest/tx/index.d.ts +1 -2
- package/dest/tx/index.d.ts.map +1 -1
- package/dest/tx/index.js +0 -1
- package/dest/tx/private_execution_result.d.ts +1 -5
- package/dest/tx/private_execution_result.d.ts.map +1 -1
- package/dest/tx/private_execution_result.js +3 -20
- package/dest/tx/public_call_request_with_calldata.js +3 -1
- package/dest/tx/state_reference.js +3 -1
- package/dest/tx/tree_snapshots.js +3 -1
- package/dest/tx/tx.d.ts +10 -3
- package/dest/tx/tx.d.ts.map +1 -1
- package/dest/tx/tx.js +12 -3
- package/dest/tx/tx_effect.d.ts +1 -1
- package/dest/tx/tx_effect.d.ts.map +1 -1
- package/dest/tx/tx_effect.js +6 -2
- package/dest/tx/tx_execution_request.d.ts +1 -1
- package/dest/tx/tx_execution_request.d.ts.map +1 -1
- package/dest/tx/tx_execution_request.js +6 -2
- package/package.json +8 -8
- package/src/abi/contract_artifact.ts +10 -10
- package/src/block/attestation_info.ts +9 -6
- package/src/block/l2_block.ts +6 -5
- package/src/block/l2_block_code_to_purge.ts +3 -11
- package/src/block/l2_block_header.ts +26 -17
- package/src/block/l2_block_new.ts +5 -1
- package/src/block/l2_block_source.ts +66 -16
- package/src/block/l2_block_stream/index.ts +1 -0
- package/src/block/l2_block_stream/interfaces.ts +12 -4
- package/src/block/l2_block_stream/l2_block_stream.ts +121 -38
- package/src/block/l2_block_stream/l2_tips_memory_store.ts +62 -56
- package/src/block/l2_block_stream/l2_tips_store_base.ts +226 -0
- package/src/block/test/l2_tips_store_test_suite.ts +485 -36
- package/src/block/validate_block_result.ts +35 -31
- package/src/checkpoint/checkpoint.ts +1 -0
- package/src/checkpoint/checkpoint_info.ts +45 -2
- package/src/checkpoint/index.ts +1 -0
- package/src/interfaces/api_limit.ts +1 -0
- package/src/interfaces/archiver.ts +14 -6
- package/src/interfaces/aztec-node-admin.ts +7 -4
- package/src/interfaces/aztec-node.ts +43 -13
- package/src/interfaces/configs.ts +5 -0
- package/src/interfaces/p2p.ts +8 -12
- package/src/interfaces/proving-job.ts +2 -11
- package/src/interfaces/server_circuit_prover.ts +3 -2
- package/src/interfaces/validator.ts +57 -7
- package/src/interfaces/world_state.ts +9 -7
- package/src/kernel/hints/build_note_hash_read_request_hints.ts +5 -8
- package/src/logs/index.ts +0 -1
- package/src/logs/tx_scoped_l2_log.ts +37 -53
- package/src/messaging/in_hash.ts +3 -1
- package/src/messaging/l2_to_l1_membership.ts +176 -52
- package/src/messaging/out_hash.ts +17 -7
- package/src/p2p/attestation_utils.ts +3 -3
- package/src/p2p/block_proposal.ts +185 -41
- package/src/p2p/{block_attestation.ts → checkpoint_attestation.ts} +31 -25
- package/src/p2p/checkpoint_proposal.ts +337 -0
- package/src/p2p/consensus_payload.ts +5 -2
- package/src/p2p/gossipable.ts +14 -4
- package/src/p2p/index.ts +3 -1
- package/src/p2p/signature_utils.ts +3 -1
- package/src/p2p/signed_txs.ts +83 -0
- package/src/p2p/topic_type.ts +3 -2
- package/src/rollup/block_rollup_public_inputs.ts +3 -9
- package/src/rollup/checkpoint_header.ts +43 -20
- package/src/rollup/checkpoint_rollup_public_inputs.ts +6 -0
- package/src/rollup/root_rollup_public_inputs.ts +6 -0
- package/src/tests/factories.ts +98 -17
- package/src/tests/mocks.ts +166 -64
- package/src/tx/global_variable_builder.ts +1 -1
- package/src/tx/index.ts +0 -1
- package/src/tx/private_execution_result.ts +0 -15
- package/src/tx/tx.ts +11 -2
- package/src/tx/tx_effect.ts +3 -1
- package/src/tx/tx_execution_request.ts +2 -0
- package/dest/logs/log_with_tx_data.d.ts +0 -19
- package/dest/logs/log_with_tx_data.d.ts.map +0 -1
- package/dest/logs/log_with_tx_data.js +0 -49
- package/dest/p2p/block_attestation.d.ts +0 -80
- package/dest/p2p/block_attestation.d.ts.map +0 -1
- package/dest/tx/content_commitment.d.ts +0 -49
- package/dest/tx/content_commitment.d.ts.map +0 -1
- package/dest/tx/content_commitment.js +0 -90
- package/src/logs/log_with_tx_data.ts +0 -46
- package/src/tx/content_commitment.ts +0 -113
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
BlockNumber,
|
|
3
3
|
BlockNumberSchema,
|
|
4
4
|
CheckpointNumber,
|
|
5
|
+
CheckpointNumberSchema,
|
|
5
6
|
type EpochNumber,
|
|
6
7
|
type SlotNumber,
|
|
7
8
|
} from '@aztec/foundation/branded-types';
|
|
@@ -14,6 +15,7 @@ import { z } from 'zod';
|
|
|
14
15
|
import type { Checkpoint } from '../checkpoint/checkpoint.js';
|
|
15
16
|
import type { PublishedCheckpoint } from '../checkpoint/published_checkpoint.js';
|
|
16
17
|
import type { L1RollupConstants } from '../epoch-helpers/index.js';
|
|
18
|
+
import { CheckpointHeader } from '../rollup/checkpoint_header.js';
|
|
17
19
|
import type { BlockHeader } from '../tx/block_header.js';
|
|
18
20
|
import type { IndexedTxEffect } from '../tx/indexed_tx_effect.js';
|
|
19
21
|
import type { TxHash } from '../tx/tx_hash.js';
|
|
@@ -21,7 +23,7 @@ import type { TxReceipt } from '../tx/tx_receipt.js';
|
|
|
21
23
|
import { type CheckpointedL2Block, PublishedL2Block } from './checkpointed_l2_block.js';
|
|
22
24
|
import type { L2Block } from './l2_block.js';
|
|
23
25
|
import type { L2BlockNew } from './l2_block_new.js';
|
|
24
|
-
import type {
|
|
26
|
+
import type { ValidateCheckpointNegativeResult, ValidateCheckpointResult } from './validate_block_result.js';
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
29
|
* Interface of classes allowing for the retrieval of L2 blocks.
|
|
@@ -66,6 +68,8 @@ export interface L2BlockSource {
|
|
|
66
68
|
*/
|
|
67
69
|
getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined>;
|
|
68
70
|
|
|
71
|
+
getCheckpointedBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<CheckpointedL2Block[]>;
|
|
72
|
+
|
|
69
73
|
/**
|
|
70
74
|
* Retrieves a collection of published checkpoints
|
|
71
75
|
* @param checkpointNumber The first checkpoint to be retrieved
|
|
@@ -161,10 +165,10 @@ export interface L2BlockSource {
|
|
|
161
165
|
isPendingChainInvalid(): Promise<boolean>;
|
|
162
166
|
|
|
163
167
|
/**
|
|
164
|
-
* Returns the status of the pending chain validation. If the chain is invalid, reports the earliest consecutive
|
|
165
|
-
* that is invalid, along with the reason for being invalid, which can be used to trigger an invalidation.
|
|
168
|
+
* Returns the status of the pending chain validation. If the chain is invalid, reports the earliest consecutive
|
|
169
|
+
* checkpoint that is invalid, along with the reason for being invalid, which can be used to trigger an invalidation.
|
|
166
170
|
*/
|
|
167
|
-
getPendingChainValidationStatus(): Promise<
|
|
171
|
+
getPendingChainValidationStatus(): Promise<ValidateCheckpointResult>;
|
|
168
172
|
|
|
169
173
|
/** Force a sync. */
|
|
170
174
|
syncImmediate(): Promise<void>;
|
|
@@ -179,6 +183,10 @@ export interface L2BlockSource {
|
|
|
179
183
|
*/
|
|
180
184
|
getBlock(number: BlockNumber): Promise<L2Block | undefined>;
|
|
181
185
|
|
|
186
|
+
getL2BlockNew(number: BlockNumber): Promise<L2BlockNew | undefined>;
|
|
187
|
+
|
|
188
|
+
getL2BlocksNew(from: BlockNumber, limit: number, proven?: boolean): Promise<L2BlockNew[]>;
|
|
189
|
+
|
|
182
190
|
/**
|
|
183
191
|
* Returns all blocks for a given epoch.
|
|
184
192
|
* @dev Use this method only with recent epochs, since it walks the block list backwards.
|
|
@@ -232,24 +240,44 @@ export interface L2BlockSink {
|
|
|
232
240
|
export type ArchiverEmitter = TypedEventEmitter<{
|
|
233
241
|
[L2BlockSourceEvents.L2PruneDetected]: (args: L2BlockPruneEvent) => void;
|
|
234
242
|
[L2BlockSourceEvents.L2BlockProven]: (args: L2BlockProvenEvent) => void;
|
|
235
|
-
[L2BlockSourceEvents.
|
|
243
|
+
[L2BlockSourceEvents.InvalidAttestationsCheckpointDetected]: (args: InvalidCheckpointDetectedEvent) => void;
|
|
244
|
+
[L2BlockSourceEvents.L2BlocksCheckpointed]: (args: L2CheckpointEvent) => void;
|
|
236
245
|
}>;
|
|
237
246
|
export interface L2BlockSourceEventEmitter extends L2BlockSource, ArchiverEmitter {}
|
|
238
247
|
|
|
239
248
|
/**
|
|
240
249
|
* Identifier for L2 block tags.
|
|
241
|
-
* -
|
|
250
|
+
* - proposed: Latest block proposed on L2.
|
|
251
|
+
* - checkpointed: Checkpointed block on L1.
|
|
242
252
|
* - proven: Proven block on L1.
|
|
243
253
|
* - finalized: Proven block on a finalized L1 block (not implemented, set to proven for now).
|
|
244
254
|
*/
|
|
245
|
-
export type L2BlockTag = '
|
|
255
|
+
export type L2BlockTag = 'proposed' | 'checkpointed' | 'proven' | 'finalized';
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Reason for L2 block prune.
|
|
259
|
+
* - uncheckpointed: L2 blocks were pruned due to a failure to checkpoint.
|
|
260
|
+
* - unproven: L2 blocks were pruned due to a failure to prove.
|
|
261
|
+
*/
|
|
262
|
+
export type L2BlockPruneReason = 'uncheckpointed' | 'unproven';
|
|
246
263
|
|
|
247
264
|
/** Tips of the L2 chain. */
|
|
248
|
-
export type L2Tips =
|
|
265
|
+
export type L2Tips = {
|
|
266
|
+
proposed: L2BlockId;
|
|
267
|
+
checkpointed: L2TipId;
|
|
268
|
+
proven: L2TipId;
|
|
269
|
+
finalized: L2TipId;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
export const GENESIS_CHECKPOINT_HEADER_HASH = CheckpointHeader.empty().hash();
|
|
249
273
|
|
|
250
274
|
/** Identifies a block by number and hash. */
|
|
251
275
|
export type L2BlockId = { number: BlockNumber; hash: string };
|
|
252
276
|
|
|
277
|
+
export type CheckpointId = { number: CheckpointNumber; hash: string };
|
|
278
|
+
|
|
279
|
+
export type L2TipId = { block: L2BlockId; checkpoint: CheckpointId };
|
|
280
|
+
|
|
253
281
|
/** Creates an L2 block id */
|
|
254
282
|
export function makeL2BlockId(number: BlockNumber, hash?: string): L2BlockId {
|
|
255
283
|
if (number !== 0 && !hash) {
|
|
@@ -258,21 +286,38 @@ export function makeL2BlockId(number: BlockNumber, hash?: string): L2BlockId {
|
|
|
258
286
|
return { number, hash: hash! };
|
|
259
287
|
}
|
|
260
288
|
|
|
289
|
+
/** Creates an L2 checkpoint id */
|
|
290
|
+
export function makeL2CheckpointId(number: CheckpointNumber, hash: string): CheckpointId {
|
|
291
|
+
return { number, hash };
|
|
292
|
+
}
|
|
293
|
+
|
|
261
294
|
const L2BlockIdSchema = z.object({
|
|
262
295
|
number: BlockNumberSchema,
|
|
263
296
|
hash: z.string(),
|
|
264
297
|
});
|
|
265
298
|
|
|
299
|
+
const L2CheckpointIdSchema = z.object({
|
|
300
|
+
number: CheckpointNumberSchema,
|
|
301
|
+
hash: z.string(),
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
const L2TipIdSchema = z.object({
|
|
305
|
+
block: L2BlockIdSchema,
|
|
306
|
+
checkpoint: L2CheckpointIdSchema,
|
|
307
|
+
});
|
|
308
|
+
|
|
266
309
|
export const L2TipsSchema = z.object({
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
310
|
+
proposed: L2BlockIdSchema,
|
|
311
|
+
checkpointed: L2TipIdSchema,
|
|
312
|
+
proven: L2TipIdSchema,
|
|
313
|
+
finalized: L2TipIdSchema,
|
|
270
314
|
});
|
|
271
315
|
|
|
272
316
|
export enum L2BlockSourceEvents {
|
|
273
317
|
L2PruneDetected = 'l2PruneDetected',
|
|
274
318
|
L2BlockProven = 'l2BlockProven',
|
|
275
|
-
|
|
319
|
+
L2BlocksCheckpointed = 'l2BlocksCheckpointed',
|
|
320
|
+
InvalidAttestationsCheckpointDetected = 'invalidCheckpointDetected',
|
|
276
321
|
}
|
|
277
322
|
|
|
278
323
|
export type L2BlockProvenEvent = {
|
|
@@ -285,10 +330,15 @@ export type L2BlockProvenEvent = {
|
|
|
285
330
|
export type L2BlockPruneEvent = {
|
|
286
331
|
type: 'l2PruneDetected';
|
|
287
332
|
epochNumber: EpochNumber;
|
|
288
|
-
blocks:
|
|
333
|
+
blocks: L2BlockNew[];
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
export type L2CheckpointEvent = {
|
|
337
|
+
type: 'l2BlocksCheckpointed';
|
|
338
|
+
checkpoint: PublishedCheckpoint;
|
|
289
339
|
};
|
|
290
340
|
|
|
291
|
-
export type
|
|
292
|
-
type: '
|
|
293
|
-
validationResult:
|
|
341
|
+
export type InvalidCheckpointDetectedEvent = {
|
|
342
|
+
type: 'invalidCheckpointDetected';
|
|
343
|
+
validationResult: ValidateCheckpointNegativeResult;
|
|
294
344
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { PublishedCheckpoint } from '../../checkpoint/published_checkpoint.js';
|
|
2
|
+
import type { L2BlockNew } from '../l2_block_new.js';
|
|
3
|
+
import type { CheckpointId, L2BlockId, L2BlockPruneReason, L2Tips } from '../l2_block_source.js';
|
|
3
4
|
|
|
4
5
|
/** Interface to the local view of the chain. Implemented by world-state and l2-tips-store. */
|
|
5
6
|
export interface L2BlockStreamLocalDataProvider {
|
|
@@ -15,11 +16,18 @@ export interface L2BlockStreamEventHandler {
|
|
|
15
16
|
export type L2BlockStreamEvent =
|
|
16
17
|
| /** Emits blocks added to the chain. */ {
|
|
17
18
|
type: 'blocks-added';
|
|
18
|
-
blocks:
|
|
19
|
+
blocks: L2BlockNew[];
|
|
19
20
|
}
|
|
20
|
-
| /**
|
|
21
|
+
| /** Emits checkpoints published to L1. */ {
|
|
22
|
+
type: 'chain-checkpointed';
|
|
23
|
+
checkpoint: PublishedCheckpoint;
|
|
24
|
+
block: L2BlockId;
|
|
25
|
+
}
|
|
26
|
+
| /** Reports last correct block (new tip of the proposed chain). */ {
|
|
21
27
|
type: 'chain-pruned';
|
|
28
|
+
reason: L2BlockPruneReason;
|
|
22
29
|
block: L2BlockId;
|
|
30
|
+
checkpoint: CheckpointId;
|
|
23
31
|
}
|
|
24
32
|
| /** Reports new proven block. */ {
|
|
25
33
|
type: 'chain-proven';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { AbortError } from '@aztec/foundation/error';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import type { PublishedCheckpoint } from '../../checkpoint/published_checkpoint.js';
|
|
7
|
+
import { type L2BlockId, type L2BlockPruneReason, type L2BlockSource, makeL2BlockId } from '../l2_block_source.js';
|
|
7
8
|
import type { L2BlockStreamEvent, L2BlockStreamEventHandler, L2BlockStreamLocalDataProvider } from './interfaces.js';
|
|
8
9
|
|
|
9
10
|
/** Creates a stream of events for new blocks, chain tips updates, and reorgs, out of polling an archiver or a node. */
|
|
@@ -13,7 +14,10 @@ export class L2BlockStream {
|
|
|
13
14
|
private hasStarted = false;
|
|
14
15
|
|
|
15
16
|
constructor(
|
|
16
|
-
private l2BlockSource: Pick<
|
|
17
|
+
private l2BlockSource: Pick<
|
|
18
|
+
L2BlockSource,
|
|
19
|
+
'getL2BlocksNew' | 'getBlockHeader' | 'getL2Tips' | 'getPublishedCheckpoints' | 'getCheckpointedBlocks'
|
|
20
|
+
>,
|
|
17
21
|
private localData: L2BlockStreamLocalDataProvider,
|
|
18
22
|
private handler: L2BlockStreamEventHandler,
|
|
19
23
|
private readonly log = createLogger('types:block_stream'),
|
|
@@ -24,6 +28,8 @@ export class L2BlockStream {
|
|
|
24
28
|
startingBlock?: number;
|
|
25
29
|
/** Instead of downloading all blocks, only fetch the smallest subset that results in reliable reorg detection. */
|
|
26
30
|
skipFinalized?: boolean;
|
|
31
|
+
/** When true, checkpoint events will not be emitted. Blocks are still fetched via checkpoints but only blocks-added events are emitted. */
|
|
32
|
+
ignoreCheckpoints?: boolean;
|
|
27
33
|
} = {},
|
|
28
34
|
) {
|
|
29
35
|
// Note that RunningPromise is in stopped state by default. This promise won't run until someone invokes `start`,
|
|
@@ -61,36 +67,38 @@ export class L2BlockStream {
|
|
|
61
67
|
try {
|
|
62
68
|
const sourceTips = await this.l2BlockSource.getL2Tips();
|
|
63
69
|
const localTips = await this.localData.getL2Tips();
|
|
64
|
-
this.log.trace(`Running L2 block stream`, {
|
|
65
|
-
sourceLatest: sourceTips.latest.number,
|
|
66
|
-
localLatest: localTips.latest.number,
|
|
67
|
-
sourceFinalized: sourceTips.finalized.number,
|
|
68
|
-
localFinalized: localTips.finalized.number,
|
|
69
|
-
sourceProven: sourceTips.proven.number,
|
|
70
|
-
localProven: localTips.proven.number,
|
|
71
|
-
sourceLatestHash: sourceTips.latest.hash,
|
|
72
|
-
localLatestHash: localTips.latest.hash,
|
|
73
|
-
sourceProvenHash: sourceTips.proven.hash,
|
|
74
|
-
localProvenHash: localTips.proven.hash,
|
|
75
|
-
sourceFinalizedHash: sourceTips.finalized.hash,
|
|
76
|
-
localFinalizedHash: localTips.finalized.hash,
|
|
77
|
-
});
|
|
70
|
+
this.log.trace(`Running L2 block stream`, { sourceTips, localTips });
|
|
78
71
|
|
|
79
72
|
// Check if there was a reorg and emit a chain-pruned event if so.
|
|
80
|
-
let latestBlockNumber = localTips.
|
|
81
|
-
const sourceCache = new BlockHashCache([sourceTips.
|
|
73
|
+
let latestBlockNumber = localTips.proposed.number;
|
|
74
|
+
const sourceCache = new BlockHashCache([sourceTips.proposed]);
|
|
82
75
|
while (!(await this.areBlockHashesEqualAt(latestBlockNumber, { sourceCache }))) {
|
|
83
76
|
latestBlockNumber--;
|
|
84
77
|
}
|
|
85
78
|
|
|
86
|
-
if (latestBlockNumber < localTips.
|
|
87
|
-
latestBlockNumber = BlockNumber(Math.min(latestBlockNumber, sourceTips.
|
|
79
|
+
if (latestBlockNumber < localTips.proposed.number) {
|
|
80
|
+
latestBlockNumber = BlockNumber(Math.min(latestBlockNumber, sourceTips.proposed.number)); // see #13471
|
|
88
81
|
const hash = sourceCache.get(latestBlockNumber) ?? (await this.getBlockHashFromSource(latestBlockNumber));
|
|
89
82
|
if (latestBlockNumber !== 0 && !hash) {
|
|
90
83
|
throw new Error(`Block hash not found in block source for block number ${latestBlockNumber}`);
|
|
91
84
|
}
|
|
92
|
-
this.log.verbose(
|
|
93
|
-
|
|
85
|
+
this.log.verbose(
|
|
86
|
+
`Reorg detected. Pruning blocks from ${latestBlockNumber + 1} to ${localTips.proposed.number}.`,
|
|
87
|
+
);
|
|
88
|
+
// This check is not 100% accurate
|
|
89
|
+
// If the local tips are sufficiently behind the source tips, such that we are missing at least one checkpoint
|
|
90
|
+
// that has now been re-orged due to a proof failure then this will indicate a failure to checkpoint rather than a failure to prove
|
|
91
|
+
// TODO: (mbps/PhilWindle): Improve re-org detection accuracy when we come to do re-orgs
|
|
92
|
+
let reason: L2BlockPruneReason = 'unproven';
|
|
93
|
+
if (latestBlockNumber === localTips.checkpointed.block.number && !this.opts.ignoreCheckpoints) {
|
|
94
|
+
reason = 'uncheckpointed';
|
|
95
|
+
}
|
|
96
|
+
await this.emitEvent({
|
|
97
|
+
type: 'chain-pruned',
|
|
98
|
+
block: makeL2BlockId(latestBlockNumber, hash),
|
|
99
|
+
reason,
|
|
100
|
+
checkpoint: sourceTips.checkpointed.checkpoint,
|
|
101
|
+
});
|
|
94
102
|
}
|
|
95
103
|
|
|
96
104
|
// If we are just starting, use the starting block number from the options.
|
|
@@ -105,40 +113,115 @@ export class L2BlockStream {
|
|
|
105
113
|
}
|
|
106
114
|
|
|
107
115
|
let nextBlockNumber = latestBlockNumber + 1;
|
|
116
|
+
let nextCheckpointToEmit = CheckpointNumber(localTips.checkpointed.checkpoint.number + 1);
|
|
108
117
|
if (this.opts.skipFinalized) {
|
|
109
118
|
// When skipping finalized blocks we need to provide reliable reorg detection while fetching as few blocks as
|
|
110
119
|
// possible. Finalized blocks cannot be reorged by definition, so we can skip most of them. We do need the very
|
|
111
120
|
// last finalized block however in order to guarantee that we will eventually find a block in which our local
|
|
112
121
|
// store matches the source.
|
|
113
122
|
// If the last finalized block is behind our local tip, there is nothing to skip.
|
|
114
|
-
nextBlockNumber = Math.max(sourceTips.finalized.number, nextBlockNumber);
|
|
123
|
+
nextBlockNumber = Math.max(sourceTips.finalized.block.number, nextBlockNumber);
|
|
124
|
+
// If the next checkpoint to emit is behind the finalized tip then skip forward
|
|
125
|
+
nextCheckpointToEmit = CheckpointNumber(Math.max(nextCheckpointToEmit, sourceTips.finalized.checkpoint.number));
|
|
115
126
|
}
|
|
116
127
|
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
|
|
128
|
+
// Loop 1: Emit checkpoint events for checkpoints whose blocks are already in local storage.
|
|
129
|
+
// This handles the case where blocks were synced as uncheckpointed and later became checkpointed.
|
|
130
|
+
// The guard `lastBlockInCheckpoint.number > localTips.proposed.number` ensures we don't emit
|
|
131
|
+
// checkpoints for blocks we don't have (e.g., when startingBlock skips earlier blocks).
|
|
132
|
+
// Since only one checkpoint can ever be uncheckpointed, this loop should iterate at most once.
|
|
133
|
+
if (!this.opts.ignoreCheckpoints) {
|
|
134
|
+
let loop1Iterations = 0;
|
|
135
|
+
while (nextCheckpointToEmit <= sourceTips.checkpointed.checkpoint.number) {
|
|
136
|
+
const checkpoints = await this.l2BlockSource.getPublishedCheckpoints(nextCheckpointToEmit, 1);
|
|
137
|
+
if (checkpoints.length === 0) {
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
const lastBlockInCheckpoint = checkpoints[0].checkpoint.blocks.at(-1)!;
|
|
141
|
+
// If this checkpoint has blocks we haven't seen yet, stop - they need to be fetched first
|
|
142
|
+
if (lastBlockInCheckpoint.number > localTips.proposed.number) {
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
loop1Iterations++;
|
|
146
|
+
if (loop1Iterations > 1) {
|
|
147
|
+
this.log.warn(
|
|
148
|
+
`Emitting multiple checkpoints (${loop1Iterations}) for already-local blocks. ` +
|
|
149
|
+
`Next checkpoint: ${nextCheckpointToEmit}, source checkpointed: ${sourceTips.checkpointed.checkpoint.number}`,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
const lastBlockHash = await lastBlockInCheckpoint.hash();
|
|
153
|
+
await this.emitEvent({
|
|
154
|
+
type: 'chain-checkpointed',
|
|
155
|
+
checkpoint: checkpoints[0],
|
|
156
|
+
block: makeL2BlockId(lastBlockInCheckpoint.number, lastBlockHash.toString()),
|
|
157
|
+
});
|
|
158
|
+
nextCheckpointToEmit = CheckpointNumber(nextCheckpointToEmit + 1);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Loop 2: Fetch new checkpointed blocks. For each block, get its checkpoint, emit all blocks
|
|
163
|
+
// from that checkpoint that we need, then emit the checkpoint event.
|
|
164
|
+
// We cache the current checkpoint to avoid redundant fetches when batchSize < checkpoint size.
|
|
165
|
+
let checkpoint: PublishedCheckpoint | undefined;
|
|
166
|
+
while (nextBlockNumber <= sourceTips.checkpointed.block.number) {
|
|
167
|
+
const limit = Math.min(this.opts.batchSize ?? 50, sourceTips.checkpointed.block.number - nextBlockNumber + 1);
|
|
168
|
+
|
|
169
|
+
// Check if we need to fetch a new checkpoint (nextBlockNumber is beyond the cached one)
|
|
170
|
+
if (!checkpoint || nextBlockNumber > checkpoint.checkpoint.blocks.at(-1)!.number) {
|
|
171
|
+
const blocks = await this.l2BlockSource.getCheckpointedBlocks(BlockNumber(nextBlockNumber), 1);
|
|
172
|
+
if (blocks.length === 0) {
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
const checkpoints = await this.l2BlockSource.getPublishedCheckpoints(blocks[0].checkpointNumber, 1);
|
|
176
|
+
if (checkpoints.length === 0) {
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
checkpoint = checkpoints[0];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Get all blocks from this checkpoint that we need, respecting batchSize
|
|
183
|
+
const blocksForCheckpoint = checkpoint.checkpoint.blocks
|
|
184
|
+
.filter(b => b.number >= nextBlockNumber)
|
|
185
|
+
.slice(0, limit);
|
|
186
|
+
if (blocksForCheckpoint.length === 0) {
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
await this.emitEvent({ type: 'blocks-added', blocks: blocksForCheckpoint });
|
|
190
|
+
nextBlockNumber = blocksForCheckpoint.at(-1)!.number + 1;
|
|
191
|
+
|
|
192
|
+
// If we've reached the end of this checkpoint, emit the checkpoint event
|
|
193
|
+
const lastBlockInCheckpoint = checkpoint.checkpoint.blocks.at(-1)!;
|
|
194
|
+
if (!this.opts.ignoreCheckpoints && nextBlockNumber > lastBlockInCheckpoint.number) {
|
|
195
|
+
const lastBlockHash = await lastBlockInCheckpoint.hash();
|
|
196
|
+
await this.emitEvent({
|
|
197
|
+
type: 'chain-checkpointed',
|
|
198
|
+
checkpoint,
|
|
199
|
+
block: makeL2BlockId(lastBlockInCheckpoint.number, lastBlockHash.toString()),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Loop 3: Fetch any remaining uncheckpointed (proposed) blocks.
|
|
205
|
+
while (nextBlockNumber <= sourceTips.proposed.number) {
|
|
206
|
+
const limit = Math.min(this.opts.batchSize ?? 50, sourceTips.proposed.number - nextBlockNumber + 1);
|
|
120
207
|
this.log.trace(`Requesting blocks from ${nextBlockNumber} limit ${limit} proven=${this.opts.proven}`);
|
|
121
|
-
const blocks = await this.l2BlockSource.
|
|
122
|
-
BlockNumber(nextBlockNumber),
|
|
123
|
-
limit,
|
|
124
|
-
this.opts.proven,
|
|
125
|
-
);
|
|
208
|
+
const blocks = await this.l2BlockSource.getL2BlocksNew(BlockNumber(nextBlockNumber), limit, this.opts.proven);
|
|
126
209
|
if (blocks.length === 0) {
|
|
127
210
|
break;
|
|
128
211
|
}
|
|
129
212
|
await this.emitEvent({ type: 'blocks-added', blocks });
|
|
130
|
-
nextBlockNumber = blocks.at(-1)!.
|
|
213
|
+
nextBlockNumber = blocks.at(-1)!.number + 1;
|
|
131
214
|
}
|
|
132
215
|
|
|
133
216
|
// Update the proven and finalized tips.
|
|
134
|
-
if (localTips.proven !== undefined && sourceTips.proven.number !== localTips.proven.number) {
|
|
217
|
+
if (localTips.proven !== undefined && sourceTips.proven.block.number !== localTips.proven.block.number) {
|
|
135
218
|
await this.emitEvent({
|
|
136
219
|
type: 'chain-proven',
|
|
137
|
-
block: sourceTips.proven,
|
|
220
|
+
block: sourceTips.proven.block,
|
|
138
221
|
});
|
|
139
222
|
}
|
|
140
|
-
if (localTips.finalized !== undefined && sourceTips.finalized.number !== localTips.finalized.number) {
|
|
141
|
-
await this.emitEvent({ type: 'chain-finalized', block: sourceTips.finalized });
|
|
223
|
+
if (localTips.finalized !== undefined && sourceTips.finalized.block.number !== localTips.finalized.block.number) {
|
|
224
|
+
await this.emitEvent({ type: 'chain-finalized', block: sourceTips.finalized.block });
|
|
142
225
|
}
|
|
143
226
|
} catch (err: any) {
|
|
144
227
|
if (err.name === 'AbortError') {
|
|
@@ -186,7 +269,7 @@ export class L2BlockStream {
|
|
|
186
269
|
|
|
187
270
|
private async emitEvent(event: L2BlockStreamEvent) {
|
|
188
271
|
this.log.debug(
|
|
189
|
-
`Emitting ${event.type} (${event.type === 'blocks-added' ? event.blocks.length : event.block.number})`,
|
|
272
|
+
`Emitting ${event.type} (${event.type === 'blocks-added' ? event.blocks.length : event.type === 'chain-checkpointed' ? event.checkpoint.checkpoint.number : event.block.number})`,
|
|
190
273
|
);
|
|
191
274
|
await this.handler.handleBlockStreamEvent(event);
|
|
192
275
|
if (!this.isRunning() && !this.isSyncing) {
|
|
@@ -1,78 +1,84 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
3
2
|
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import
|
|
3
|
+
import type { PublishedCheckpoint } from '../../checkpoint/published_checkpoint.js';
|
|
4
|
+
import type { L2BlockTag } from '../l2_block_source.js';
|
|
5
|
+
import { L2TipsStoreBase } from './l2_tips_store_base.js';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @dev
|
|
8
|
+
* In-memory implementation of L2 tips store. Useful for testing and lightweight clients.
|
|
9
|
+
* @dev Tests in kv-store/src/stores/l2_tips_memory_store.test.ts
|
|
11
10
|
*/
|
|
12
|
-
export class L2TipsMemoryStore
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
export class L2TipsMemoryStore extends L2TipsStoreBase {
|
|
12
|
+
private readonly tips = new Map<L2BlockTag, BlockNumber>();
|
|
13
|
+
private readonly blockHashes = new Map<number, string>();
|
|
14
|
+
private readonly blockToCheckpoint = new Map<number, CheckpointNumber>();
|
|
15
|
+
private readonly checkpoints = new Map<number, PublishedCheckpoint>();
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
return Promise.resolve(this.
|
|
17
|
+
protected getTip(tag: L2BlockTag): Promise<BlockNumber | undefined> {
|
|
18
|
+
return Promise.resolve(this.tips.get(tag));
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
finalized: this.getL2Tip('finalized'),
|
|
24
|
-
proven: this.getL2Tip('proven'),
|
|
25
|
-
});
|
|
21
|
+
protected setTip(tag: L2BlockTag, blockNumber: BlockNumber): Promise<void> {
|
|
22
|
+
this.tips.set(tag, blockNumber);
|
|
23
|
+
return Promise.resolve();
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
protected getStoredBlockHash(blockNumber: BlockNumber): Promise<string | undefined> {
|
|
27
|
+
return Promise.resolve(this.blockHashes.get(blockNumber));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected setBlockHash(blockNumber: BlockNumber, hash: string): Promise<void> {
|
|
31
|
+
this.blockHashes.set(blockNumber, hash);
|
|
32
|
+
return Promise.resolve();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
protected deleteBlockHashesBefore(blockNumber: BlockNumber): Promise<void> {
|
|
36
|
+
for (const key of this.blockHashes.keys()) {
|
|
37
|
+
if (key < blockNumber) {
|
|
38
|
+
this.blockHashes.delete(key);
|
|
39
|
+
}
|
|
36
40
|
}
|
|
41
|
+
return Promise.resolve();
|
|
42
|
+
}
|
|
37
43
|
|
|
38
|
-
|
|
44
|
+
protected getCheckpointNumberForBlock(blockNumber: BlockNumber): Promise<CheckpointNumber | undefined> {
|
|
45
|
+
return Promise.resolve(this.blockToCheckpoint.get(blockNumber));
|
|
39
46
|
}
|
|
40
47
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
protected setCheckpointNumberForBlock(blockNumber: BlockNumber, checkpointNumber: CheckpointNumber): Promise<void> {
|
|
49
|
+
this.blockToCheckpoint.set(blockNumber, checkpointNumber);
|
|
50
|
+
return Promise.resolve();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
protected deleteBlockToCheckpointBefore(blockNumber: BlockNumber): Promise<void> {
|
|
54
|
+
for (const key of this.blockToCheckpoint.keys()) {
|
|
55
|
+
if (key < blockNumber) {
|
|
56
|
+
this.blockToCheckpoint.delete(key);
|
|
50
57
|
}
|
|
51
|
-
case 'chain-pruned':
|
|
52
|
-
this.saveTag('latest', event.block);
|
|
53
|
-
break;
|
|
54
|
-
case 'chain-proven':
|
|
55
|
-
this.saveTag('proven', event.block);
|
|
56
|
-
break;
|
|
57
|
-
case 'chain-finalized':
|
|
58
|
-
this.saveTag('finalized', event.block);
|
|
59
|
-
for (const key of this.l2BlockHashesStore.keys()) {
|
|
60
|
-
if (key < event.block.number) {
|
|
61
|
-
this.l2BlockHashesStore.delete(key);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
break;
|
|
65
58
|
}
|
|
59
|
+
return Promise.resolve();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
protected getCheckpoint(checkpointNumber: CheckpointNumber): Promise<PublishedCheckpoint | undefined> {
|
|
63
|
+
return Promise.resolve(this.checkpoints.get(checkpointNumber));
|
|
66
64
|
}
|
|
67
65
|
|
|
68
|
-
protected
|
|
69
|
-
this.
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
protected saveCheckpointData(checkpoint: PublishedCheckpoint): Promise<void> {
|
|
67
|
+
this.checkpoints.set(checkpoint.checkpoint.number, checkpoint);
|
|
68
|
+
return Promise.resolve();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
protected deleteCheckpointsBefore(checkpointNumber: CheckpointNumber): Promise<void> {
|
|
72
|
+
for (const key of this.checkpoints.keys()) {
|
|
73
|
+
if (key < checkpointNumber) {
|
|
74
|
+
this.checkpoints.delete(key);
|
|
75
|
+
}
|
|
72
76
|
}
|
|
77
|
+
return Promise.resolve();
|
|
73
78
|
}
|
|
74
79
|
|
|
75
|
-
protected
|
|
76
|
-
|
|
80
|
+
protected runInTransaction<T>(fn: () => Promise<T>): Promise<T> {
|
|
81
|
+
// Memory store doesn't need transactions - just execute immediately
|
|
82
|
+
return fn();
|
|
77
83
|
}
|
|
78
84
|
}
|