@aztec/archiver 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0
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 +164 -22
- package/dest/archiver.d.ts +194 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +949 -0
- package/dest/config.d.ts +34 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/config.js +95 -0
- package/dest/errors.d.ts +87 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/errors.js +129 -0
- package/dest/factory.d.ts +16 -10
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +117 -20
- package/dest/index.d.ts +19 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +17 -3
- package/dest/interfaces.d.ts +9 -0
- package/dest/interfaces.d.ts.map +1 -0
- package/dest/interfaces.js +3 -0
- package/dest/l1/bin/retrieve-calldata.d.ts +3 -0
- package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
- package/dest/l1/bin/retrieve-calldata.js +152 -0
- package/dest/l1/calldata_retriever.d.ts +143 -0
- package/dest/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/l1/calldata_retriever.js +413 -0
- package/dest/l1/data_retrieval.d.ts +102 -0
- package/dest/l1/data_retrieval.d.ts.map +1 -0
- package/dest/{archiver → l1}/data_retrieval.js +85 -165
- package/dest/l1/debug_tx.d.ts +19 -0
- package/dest/l1/debug_tx.d.ts.map +1 -0
- package/dest/l1/debug_tx.js +73 -0
- package/dest/l1/spire_proposer.d.ts +70 -0
- package/dest/l1/spire_proposer.d.ts.map +1 -0
- package/dest/l1/spire_proposer.js +149 -0
- package/dest/l1/trace_tx.d.ts +43 -0
- package/dest/l1/trace_tx.d.ts.map +1 -0
- package/dest/l1/trace_tx.js +91 -0
- package/dest/l1/types.d.ts +12 -0
- package/dest/l1/types.d.ts.map +1 -0
- package/dest/l1/types.js +3 -0
- package/dest/l1/validate_historical_logs.d.ts +23 -0
- package/dest/l1/validate_historical_logs.d.ts.map +1 -0
- package/dest/l1/validate_historical_logs.js +108 -0
- package/dest/l1/validate_trace.d.ts +32 -0
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/l1/validate_trace.js +154 -0
- package/dest/modules/contract_data_source_adapter.d.ts +25 -0
- package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
- package/dest/modules/contract_data_source_adapter.js +32 -0
- package/dest/modules/data_source_base.d.ts +112 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +322 -0
- package/dest/modules/data_store_updater.d.ts +105 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +393 -0
- package/dest/modules/instrumentation.d.ts +63 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/modules/instrumentation.js +166 -0
- package/dest/modules/l1_synchronizer.d.ts +77 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.js +1381 -0
- package/dest/modules/outbox_trees_resolver.d.ts +62 -0
- package/dest/modules/outbox_trees_resolver.d.ts.map +1 -0
- package/dest/modules/outbox_trees_resolver.js +162 -0
- package/dest/modules/validation.d.ts +40 -0
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +41 -17
- package/dest/store/block_store.d.ts +303 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/store/block_store.js +1206 -0
- package/dest/store/contract_class_store.d.ts +31 -0
- package/dest/store/contract_class_store.d.ts.map +1 -0
- package/dest/store/contract_class_store.js +98 -0
- package/dest/store/contract_instance_store.d.ts +51 -0
- package/dest/store/contract_instance_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +55 -3
- package/dest/store/data_stores.d.ts +68 -0
- package/dest/store/data_stores.d.ts.map +1 -0
- package/dest/store/data_stores.js +54 -0
- package/dest/store/function_names_cache.d.ts +17 -0
- package/dest/store/function_names_cache.d.ts.map +1 -0
- package/dest/store/function_names_cache.js +30 -0
- package/dest/store/l2_tips_cache.d.ts +25 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +26 -0
- package/dest/store/log_store.d.ts +59 -0
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/store/log_store.js +310 -0
- package/dest/store/log_store_codec.d.ts +78 -0
- package/dest/store/log_store_codec.d.ts.map +1 -0
- package/dest/store/log_store_codec.js +110 -0
- package/dest/store/message_store.d.ts +50 -0
- package/dest/store/message_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/message_store.js +66 -23
- 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}/inbox_message.js +6 -6
- package/dest/structs/published.d.ts +2 -0
- package/dest/structs/published.d.ts.map +1 -0
- package/dest/test/fake_l1_state.d.ts +214 -0
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/fake_l1_state.js +517 -0
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +4 -1
- package/dest/test/mock_archiver.d.ts +5 -6
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +8 -12
- package/dest/test/mock_l1_to_l2_message_source.d.ts +6 -7
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +19 -14
- package/dest/test/mock_l2_block_source.d.ts +68 -40
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +347 -145
- package/dest/test/mock_structs.d.ts +83 -4
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +157 -12
- package/dest/test/noop_l1_archiver.d.ts +34 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +88 -0
- package/package.json +18 -18
- package/src/archiver.ts +785 -0
- package/src/config.ts +125 -0
- package/src/errors.ts +203 -0
- package/src/factory.ts +185 -22
- package/src/index.ts +27 -3
- package/src/interfaces.ts +9 -0
- package/src/l1/README.md +55 -0
- package/src/l1/bin/retrieve-calldata.ts +194 -0
- package/src/l1/calldata_retriever.ts +529 -0
- package/src/{archiver → l1}/data_retrieval.ts +157 -243
- package/src/l1/debug_tx.ts +99 -0
- package/src/l1/spire_proposer.ts +152 -0
- package/src/l1/trace_tx.ts +128 -0
- package/src/l1/types.ts +13 -0
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/l1/validate_trace.ts +229 -0
- package/src/modules/contract_data_source_adapter.ts +46 -0
- package/src/modules/data_source_base.ts +466 -0
- package/src/modules/data_store_updater.ts +519 -0
- package/src/modules/instrumentation.ts +217 -0
- package/src/modules/l1_synchronizer.ts +1320 -0
- package/src/modules/outbox_trees_resolver.ts +199 -0
- package/src/modules/validation.ts +186 -0
- package/src/store/block_store.ts +1551 -0
- package/src/store/contract_class_store.ts +126 -0
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +70 -7
- package/src/store/data_stores.ts +104 -0
- package/src/store/function_names_cache.ts +37 -0
- package/src/store/l2_tips_cache.ts +35 -0
- package/src/store/log_store.ts +380 -0
- package/src/store/log_store_codec.ts +143 -0
- package/src/{archiver/kv_archiver_store → store}/message_store.ts +81 -28
- package/src/{archiver/structs → structs}/inbox_message.ts +8 -9
- package/src/{archiver/structs → structs}/published.ts +0 -1
- package/src/test/fake_l1_state.ts +770 -0
- package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
- package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
- package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
- package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
- package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
- package/src/test/fixtures/trace_transaction-proxied.json +128 -0
- package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
- package/src/test/index.ts +4 -0
- package/src/test/mock_archiver.ts +10 -14
- package/src/test/mock_l1_to_l2_message_source.ts +16 -15
- package/src/test/mock_l2_block_source.ts +416 -161
- package/src/test/mock_structs.ts +292 -14
- package/src/test/noop_l1_archiver.ts +158 -0
- package/dest/archiver/archiver.d.ts +0 -290
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -1434
- package/dest/archiver/archiver_store.d.ts +0 -256
- 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 -1289
- package/dest/archiver/config.d.ts +0 -21
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/config.js +0 -55
- package/dest/archiver/data_retrieval.d.ts +0 -80
- package/dest/archiver/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts +0 -12
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/errors.js +0 -17
- 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 -35
- package/dest/archiver/instrumentation.d.ts.map +0 -1
- package/dest/archiver/instrumentation.js +0 -140
- package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -125
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.js +0 -371
- 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_class_store.js +0 -120
- 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 -169
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -296
- package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -49
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/log_store.js +0 -337
- package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -39
- package/dest/archiver/kv_archiver_store/message_store.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 +0 -3
- 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 -1880
- package/src/archiver/archiver_store.ts +0 -310
- package/src/archiver/archiver_store_test_suite.ts +0 -1295
- package/src/archiver/config.ts +0 -79
- package/src/archiver/errors.ts +0 -26
- package/src/archiver/index.ts +0 -6
- package/src/archiver/instrumentation.ts +0 -187
- package/src/archiver/kv_archiver_store/block_store.ts +0 -482
- package/src/archiver/kv_archiver_store/contract_class_store.ts +0 -176
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -423
- package/src/archiver/kv_archiver_store/log_store.ts +0 -407
- package/src/archiver/validation.ts +0 -124
- package/src/rpc/index.ts +0 -16
- /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
- /package/dest/{archiver/structs → structs}/published.js +0 -0
- /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
|
@@ -1,24 +1,48 @@
|
|
|
1
1
|
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
2
|
-
import { DefaultL1ContractsConfig } from '@aztec/ethereum';
|
|
3
|
-
import {
|
|
2
|
+
import { DefaultL1ContractsConfig } from '@aztec/ethereum/config';
|
|
3
|
+
import {
|
|
4
|
+
BlockNumber,
|
|
5
|
+
CheckpointNumber,
|
|
6
|
+
EpochNumber,
|
|
7
|
+
IndexWithinCheckpoint,
|
|
8
|
+
SlotNumber,
|
|
9
|
+
} from '@aztec/foundation/branded-types';
|
|
4
10
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
11
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
12
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
7
13
|
import { createLogger } from '@aztec/foundation/log';
|
|
8
14
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
9
15
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
16
|
import {
|
|
17
|
+
type BlockData,
|
|
18
|
+
type BlockHash,
|
|
19
|
+
type BlockQuery,
|
|
20
|
+
type BlockTag,
|
|
21
|
+
type BlocksQuery,
|
|
22
|
+
Body,
|
|
23
|
+
type CheckpointQuery,
|
|
24
|
+
type CheckpointsQuery,
|
|
25
|
+
GENESIS_BLOCK_HEADER_HASH,
|
|
26
|
+
GENESIS_CHECKPOINT_HEADER_HASH,
|
|
11
27
|
L2Block,
|
|
12
|
-
L2BlockHash,
|
|
13
28
|
type L2BlockSource,
|
|
14
29
|
type L2Tips,
|
|
15
|
-
|
|
16
|
-
type
|
|
30
|
+
type ProposedCheckpointQuery,
|
|
31
|
+
type ValidateCheckpointResult,
|
|
17
32
|
} from '@aztec/stdlib/block';
|
|
18
|
-
import
|
|
33
|
+
import {
|
|
34
|
+
Checkpoint,
|
|
35
|
+
type CheckpointData,
|
|
36
|
+
L1PublishedData,
|
|
37
|
+
type ProposedCheckpointData,
|
|
38
|
+
PublishedCheckpoint,
|
|
39
|
+
} from '@aztec/stdlib/checkpoint';
|
|
19
40
|
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
20
41
|
import { EmptyL1RollupConstants, type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
21
|
-
import {
|
|
42
|
+
import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
|
|
43
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
44
|
+
import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
|
|
45
|
+
import { BlockHeader, TxHash } from '@aztec/stdlib/tx';
|
|
22
46
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
23
47
|
|
|
24
48
|
/**
|
|
@@ -26,29 +50,121 @@ import type { UInt64 } from '@aztec/stdlib/types';
|
|
|
26
50
|
*/
|
|
27
51
|
export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
28
52
|
protected l2Blocks: L2Block[] = [];
|
|
53
|
+
protected checkpointList: Checkpoint[] = [];
|
|
29
54
|
|
|
30
55
|
private provenBlockNumber: number = 0;
|
|
31
56
|
private finalizedBlockNumber: number = 0;
|
|
57
|
+
private checkpointedBlockNumber: number = 0;
|
|
58
|
+
|
|
59
|
+
private initialHeader: BlockHeader = BlockHeader.empty();
|
|
60
|
+
private initialHeaderHash: BlockHash = GENESIS_BLOCK_HEADER_HASH;
|
|
61
|
+
private genesisArchiveRoot?: Fr;
|
|
62
|
+
private genesisBlock?: L2Block;
|
|
32
63
|
|
|
33
64
|
private log = createLogger('archiver:mock_l2_block_source');
|
|
34
65
|
|
|
66
|
+
/** Returns the initial header used to synthesize block 0. */
|
|
67
|
+
public getInitialHeader(): BlockHeader {
|
|
68
|
+
return this.initialHeader;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Sets the initial header used to synthesize block 0. Tests that wire up a real
|
|
73
|
+
* world-state should call this with `worldState.getInitialHeader()` so the L2BlockStream
|
|
74
|
+
* agrees on the genesis hash on both sides. Precomputes and caches the header hash so
|
|
75
|
+
* `getGenesisBlockHash()` can return synchronously.
|
|
76
|
+
*/
|
|
77
|
+
public async setInitialHeader(header: BlockHeader): Promise<void> {
|
|
78
|
+
this.initialHeader = header;
|
|
79
|
+
this.initialHeaderHash = await header.hash();
|
|
80
|
+
this.genesisBlock = undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Returns the precomputed hash of the genesis block header. Defaults to the static
|
|
85
|
+
* {@link GENESIS_BLOCK_HEADER_HASH} unless {@link setInitialHeader} has been called with a
|
|
86
|
+
* custom header.
|
|
87
|
+
*/
|
|
88
|
+
public getGenesisBlockHash(): BlockHash {
|
|
89
|
+
return this.initialHeaderHash;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Sets the post-genesis archive root used to synthesize block 0. Mirrors the real archiver,
|
|
94
|
+
* whose synthetic block 0 carries `new AppendOnlyTreeSnapshot(genesisArchiveRoot, 1)` rather
|
|
95
|
+
* than `AppendOnlyTreeSnapshot.empty()`. Tests wiring up a real world-state should set this so
|
|
96
|
+
* archive-based block lookups against the mock match production semantics.
|
|
97
|
+
*/
|
|
98
|
+
public setGenesisArchiveRoot(root: Fr): void {
|
|
99
|
+
this.genesisArchiveRoot = root;
|
|
100
|
+
this.genesisBlock = undefined;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private getGenesisBlock(): L2Block {
|
|
104
|
+
if (this.genesisBlock) {
|
|
105
|
+
return this.genesisBlock;
|
|
106
|
+
}
|
|
107
|
+
const archive = this.genesisArchiveRoot
|
|
108
|
+
? new AppendOnlyTreeSnapshot(this.genesisArchiveRoot, 1)
|
|
109
|
+
: AppendOnlyTreeSnapshot.empty();
|
|
110
|
+
return (this.genesisBlock = new L2Block(
|
|
111
|
+
archive,
|
|
112
|
+
this.initialHeader,
|
|
113
|
+
Body.empty(),
|
|
114
|
+
CheckpointNumber.ZERO,
|
|
115
|
+
IndexWithinCheckpoint(0),
|
|
116
|
+
));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Creates blocks grouped into single-block checkpoints. */
|
|
35
120
|
public async createBlocks(numBlocks: number) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
121
|
+
await this.createCheckpoints(numBlocks, 1);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
125
|
+
return Promise.resolve(
|
|
126
|
+
this.checkpointList.length === 0 ? CheckpointNumber.ZERO : CheckpointNumber(this.checkpointList.length),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Creates checkpoints, each containing `blocksPerCheckpoint` blocks. */
|
|
131
|
+
public async createCheckpoints(numCheckpoints: number, blocksPerCheckpoint: number = 1) {
|
|
132
|
+
for (let c = 0; c < numCheckpoints; c++) {
|
|
133
|
+
const checkpointNum = CheckpointNumber(this.checkpointList.length + 1);
|
|
134
|
+
const startBlockNum = this.l2Blocks.length + 1;
|
|
135
|
+
const slotNumber = SlotNumber(Number(checkpointNum));
|
|
136
|
+
const checkpoint = await Checkpoint.random(checkpointNum, {
|
|
137
|
+
numBlocks: blocksPerCheckpoint,
|
|
138
|
+
startBlockNumber: startBlockNum,
|
|
139
|
+
slotNumber,
|
|
140
|
+
checkpointNumber: checkpointNum,
|
|
141
|
+
});
|
|
142
|
+
this.checkpointList.push(checkpoint);
|
|
143
|
+
this.l2Blocks.push(...checkpoint.blocks);
|
|
40
144
|
}
|
|
41
145
|
|
|
42
|
-
this.log.verbose(
|
|
146
|
+
this.log.verbose(
|
|
147
|
+
`Created ${numCheckpoints} checkpoints with ${blocksPerCheckpoint} blocks each in the mock L2 block source`,
|
|
148
|
+
);
|
|
43
149
|
}
|
|
44
150
|
|
|
45
|
-
public
|
|
151
|
+
public addProposedBlocks(blocks: L2Block[]) {
|
|
46
152
|
this.l2Blocks.push(...blocks);
|
|
47
|
-
this.log.verbose(`Added ${blocks.length} blocks to the mock L2 block source`);
|
|
153
|
+
this.log.verbose(`Added ${blocks.length} proposed blocks to the mock L2 block source`);
|
|
48
154
|
}
|
|
49
155
|
|
|
50
156
|
public removeBlocks(numBlocks: number) {
|
|
51
157
|
this.l2Blocks = this.l2Blocks.slice(0, -numBlocks);
|
|
158
|
+
const maxBlockNum = this.l2Blocks.length;
|
|
159
|
+
// Remove any checkpoint whose last block is beyond the remaining blocks.
|
|
160
|
+
this.checkpointList = this.checkpointList.filter(c => {
|
|
161
|
+
const lastBlockNum = c.blocks[0].number + c.blocks.length - 1;
|
|
162
|
+
return lastBlockNum <= maxBlockNum;
|
|
163
|
+
});
|
|
164
|
+
// Keep tip numbers consistent with remaining blocks.
|
|
165
|
+
this.checkpointedBlockNumber = Math.min(this.checkpointedBlockNumber, maxBlockNum);
|
|
166
|
+
this.provenBlockNumber = Math.min(this.provenBlockNumber, maxBlockNum);
|
|
167
|
+
this.finalizedBlockNumber = Math.min(this.finalizedBlockNumber, maxBlockNum);
|
|
52
168
|
this.log.verbose(`Removed ${numBlocks} blocks from the mock L2 block source`);
|
|
53
169
|
}
|
|
54
170
|
|
|
@@ -63,6 +179,36 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
63
179
|
this.finalizedBlockNumber = finalizedBlockNumber;
|
|
64
180
|
}
|
|
65
181
|
|
|
182
|
+
public setCheckpointedBlockNumber(checkpointedBlockNumber: number) {
|
|
183
|
+
const prevCheckpointed = this.checkpointedBlockNumber;
|
|
184
|
+
this.checkpointedBlockNumber = checkpointedBlockNumber;
|
|
185
|
+
// Auto-create single-block checkpoints for newly checkpointed blocks that don't have one yet.
|
|
186
|
+
// This handles blocks added via addProposedBlocks that are now being marked as checkpointed.
|
|
187
|
+
const newCheckpoints: Checkpoint[] = [];
|
|
188
|
+
for (let blockNum = prevCheckpointed + 1; blockNum <= checkpointedBlockNumber; blockNum++) {
|
|
189
|
+
const block = this.l2Blocks[blockNum - 1];
|
|
190
|
+
if (!block) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (this.checkpointList.some(c => c.blocks.some(b => b.number === block.number))) {
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const checkpointNum = CheckpointNumber(this.checkpointList.length + newCheckpoints.length + 1);
|
|
197
|
+
const checkpoint = new Checkpoint(
|
|
198
|
+
block.archive,
|
|
199
|
+
CheckpointHeader.random({ slotNumber: block.header.globalVariables.slotNumber }),
|
|
200
|
+
[block],
|
|
201
|
+
checkpointNum,
|
|
202
|
+
);
|
|
203
|
+
newCheckpoints.push(checkpoint);
|
|
204
|
+
}
|
|
205
|
+
// Insert new checkpoints in order by number.
|
|
206
|
+
if (newCheckpoints.length > 0) {
|
|
207
|
+
this.checkpointList.push(...newCheckpoints);
|
|
208
|
+
this.checkpointList.sort((a, b) => a.number - b.number);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
66
212
|
/**
|
|
67
213
|
* Method to fetch the rollup contract address at the base-layer.
|
|
68
214
|
* @returns The rollup address.
|
|
@@ -83,137 +229,115 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
83
229
|
* Gets the number of the latest L2 block processed by the block source implementation.
|
|
84
230
|
* @returns In this mock instance, returns the number of L2 blocks that we've mocked.
|
|
85
231
|
*/
|
|
86
|
-
public getBlockNumber()
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
232
|
+
public getBlockNumber(): Promise<BlockNumber>;
|
|
233
|
+
public getBlockNumber(query: BlockQuery): Promise<BlockNumber | undefined>;
|
|
234
|
+
public async getBlockNumber(query?: BlockQuery): Promise<BlockNumber | undefined> {
|
|
235
|
+
if (!query) {
|
|
236
|
+
return BlockNumber(this.l2Blocks.length);
|
|
237
|
+
}
|
|
238
|
+
if ('number' in query) {
|
|
239
|
+
return query.number;
|
|
240
|
+
}
|
|
241
|
+
if ('tag' in query) {
|
|
242
|
+
return BlockNumber(this.resolveBlockTag(query.tag));
|
|
243
|
+
}
|
|
244
|
+
const block = await this.getBlock(query);
|
|
245
|
+
return block ? block.header.globalVariables.blockNumber : undefined;
|
|
92
246
|
}
|
|
93
247
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return Promise.resolve(this.l2Blocks[number - 1]);
|
|
248
|
+
public getCheckpoint(query: CheckpointQuery): Promise<PublishedCheckpoint | undefined> {
|
|
249
|
+
const checkpoint = this.resolveCheckpointQuery(query);
|
|
250
|
+
if (!checkpoint) {
|
|
251
|
+
return Promise.resolve(undefined);
|
|
252
|
+
}
|
|
253
|
+
return Promise.resolve(new PublishedCheckpoint(checkpoint, this.mockL1DataForCheckpoint(checkpoint), []));
|
|
101
254
|
}
|
|
102
255
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
* @param from - Number of the first block to return (inclusive).
|
|
106
|
-
* @param limit - The maximum number of blocks to return.
|
|
107
|
-
* @returns The requested mocked L2 blocks.
|
|
108
|
-
*/
|
|
109
|
-
public getBlocks(from: number, limit: number, proven?: boolean) {
|
|
256
|
+
public getCheckpoints(query: CheckpointsQuery): Promise<PublishedCheckpoint[]> {
|
|
257
|
+
const checkpoints = this.resolveCheckpointsQuery(query);
|
|
110
258
|
return Promise.resolve(
|
|
111
|
-
this.
|
|
112
|
-
.slice(from - 1, from - 1 + limit)
|
|
113
|
-
.filter(b => !proven || this.provenBlockNumber === undefined || b.number <= this.provenBlockNumber),
|
|
259
|
+
checkpoints.map(checkpoint => new PublishedCheckpoint(checkpoint, this.mockL1DataForCheckpoint(checkpoint), [])),
|
|
114
260
|
);
|
|
115
261
|
}
|
|
116
262
|
|
|
117
|
-
public
|
|
118
|
-
|
|
119
|
-
return
|
|
263
|
+
public getCheckpointByArchive(archive: Fr): Promise<Checkpoint | undefined> {
|
|
264
|
+
const checkpoint = this.checkpointList.find(c => c.archive.root.equals(archive));
|
|
265
|
+
return Promise.resolve(checkpoint);
|
|
120
266
|
}
|
|
121
267
|
|
|
122
|
-
public
|
|
123
|
-
|
|
124
|
-
|
|
268
|
+
public getCheckpointData(query: CheckpointQuery): Promise<CheckpointData | undefined> {
|
|
269
|
+
const checkpoint = this.resolveCheckpointQuery(query);
|
|
270
|
+
if (!checkpoint) {
|
|
271
|
+
return Promise.resolve(undefined);
|
|
272
|
+
}
|
|
273
|
+
return Promise.resolve(this.checkpointToData(checkpoint));
|
|
125
274
|
}
|
|
126
275
|
|
|
127
|
-
public
|
|
128
|
-
const
|
|
129
|
-
return
|
|
130
|
-
PublishedL2Block.fromFields({
|
|
131
|
-
block,
|
|
132
|
-
l1: {
|
|
133
|
-
blockNumber: BigInt(block.number),
|
|
134
|
-
blockHash: Buffer32.random().toString(),
|
|
135
|
-
timestamp: BigInt(block.number),
|
|
136
|
-
},
|
|
137
|
-
attestations: [],
|
|
138
|
-
}),
|
|
139
|
-
);
|
|
276
|
+
public getCheckpointsData(query: CheckpointsQuery): Promise<CheckpointData[]> {
|
|
277
|
+
const checkpoints = this.resolveCheckpointsQuery(query);
|
|
278
|
+
return Promise.resolve(checkpoints.map(c => this.checkpointToData(c)));
|
|
140
279
|
}
|
|
141
280
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
return undefined;
|
|
281
|
+
private checkpointToData(checkpoint: Checkpoint): CheckpointData {
|
|
282
|
+
return {
|
|
283
|
+
checkpointNumber: checkpoint.number,
|
|
284
|
+
header: checkpoint.header,
|
|
285
|
+
archive: checkpoint.archive,
|
|
286
|
+
checkpointOutHash: computeCheckpointOutHash(
|
|
287
|
+
checkpoint.blocks.map(b => b.body.txEffects.map(tx => tx.l2ToL1Msgs)),
|
|
288
|
+
),
|
|
289
|
+
startBlock: checkpoint.blocks[0].number,
|
|
290
|
+
blockCount: checkpoint.blocks.length,
|
|
291
|
+
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier,
|
|
292
|
+
attestations: [],
|
|
293
|
+
l1: this.mockL1DataForCheckpoint(checkpoint),
|
|
294
|
+
};
|
|
158
295
|
}
|
|
159
296
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return Promise.resolve(undefined);
|
|
297
|
+
private resolveCheckpointQuery(query: CheckpointQuery): Checkpoint | undefined {
|
|
298
|
+
if ('number' in query) {
|
|
299
|
+
return this.checkpointList[query.number - 1];
|
|
164
300
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
return block.getBlockHeader();
|
|
301
|
+
if ('slot' in query) {
|
|
302
|
+
return this.checkpointList.find(c => c.header.slotNumber === query.slot);
|
|
303
|
+
}
|
|
304
|
+
switch (query.tag) {
|
|
305
|
+
case 'checkpointed':
|
|
306
|
+
return this.checkpointList[this.checkpointList.length - 1];
|
|
307
|
+
case 'proven': {
|
|
308
|
+
const provenCheckpoint = this.checkpointList.filter(c =>
|
|
309
|
+
c.blocks.some(b => b.number <= this.provenBlockNumber),
|
|
310
|
+
);
|
|
311
|
+
return provenCheckpoint.at(-1);
|
|
312
|
+
}
|
|
313
|
+
case 'finalized': {
|
|
314
|
+
const finalizedCheckpoint = this.checkpointList.filter(c =>
|
|
315
|
+
c.blocks.some(b => b.number <= this.finalizedBlockNumber),
|
|
316
|
+
);
|
|
317
|
+
return finalizedCheckpoint.at(-1);
|
|
183
318
|
}
|
|
184
319
|
}
|
|
185
|
-
return undefined;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
public getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
|
|
189
|
-
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
190
|
-
return Promise.resolve(block?.getBlockHeader());
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
194
|
-
return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.getBlockHeader());
|
|
195
320
|
}
|
|
196
321
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
322
|
+
private resolveCheckpointsQuery(query: CheckpointsQuery): Checkpoint[] {
|
|
323
|
+
if ('from' in query) {
|
|
324
|
+
return this.checkpointList.slice(query.from - 1, query.from - 1 + query.limit);
|
|
325
|
+
}
|
|
326
|
+
if ('fromSlot' in query) {
|
|
327
|
+
const matching = this.checkpointList.filter(c =>
|
|
328
|
+
query.reverse ? c.header.slotNumber <= query.fromSlot : c.header.slotNumber >= query.fromSlot,
|
|
329
|
+
);
|
|
330
|
+
const nearestFirst = query.reverse ? matching.reverse() : matching;
|
|
331
|
+
return nearestFirst.slice(0, query.limit);
|
|
332
|
+
}
|
|
333
|
+
return this.getCheckpointsInEpoch(query.epoch);
|
|
200
334
|
}
|
|
201
335
|
|
|
202
|
-
|
|
203
|
-
const
|
|
204
|
-
const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
|
|
205
|
-
const blocks = this.l2Blocks.filter(b => {
|
|
206
|
-
const slot = b.header.globalVariables.slotNumber;
|
|
207
|
-
return slot >= start && slot <= end;
|
|
208
|
-
});
|
|
336
|
+
getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
|
|
337
|
+
const blocks = this.l2Blocks.filter(b => b.header.globalVariables.slotNumber === slotNumber);
|
|
209
338
|
return Promise.resolve(blocks);
|
|
210
339
|
}
|
|
211
340
|
|
|
212
|
-
async getBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
213
|
-
const blocks = await this.getBlocksForEpoch(epochNumber);
|
|
214
|
-
return blocks.map(b => b.getBlockHeader());
|
|
215
|
-
}
|
|
216
|
-
|
|
217
341
|
/**
|
|
218
342
|
* Gets a tx effect.
|
|
219
343
|
* @param txHash - The hash of the tx corresponding to the tx effect.
|
|
@@ -230,66 +354,82 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
230
354
|
return {
|
|
231
355
|
data: txEffect,
|
|
232
356
|
l2BlockNumber: block.number,
|
|
233
|
-
l2BlockHash:
|
|
234
|
-
txIndexInBlock: block.body.txEffects.
|
|
357
|
+
l2BlockHash: await block.hash(),
|
|
358
|
+
txIndexInBlock: block.body.txEffects.findIndex(t => t.txHash.equals(txHash)),
|
|
359
|
+
slotNumber: block.header.globalVariables.slotNumber,
|
|
235
360
|
};
|
|
236
361
|
}
|
|
237
362
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
* @returns The requested tx receipt (or undefined if not found).
|
|
242
|
-
*/
|
|
243
|
-
public async getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
|
|
244
|
-
for (const block of this.l2Blocks) {
|
|
245
|
-
for (const txEffect of block.body.txEffects) {
|
|
246
|
-
if (txEffect.txHash.equals(txHash)) {
|
|
247
|
-
return new TxReceipt(
|
|
248
|
-
txHash,
|
|
249
|
-
TxStatus.SUCCESS,
|
|
250
|
-
'',
|
|
251
|
-
txEffect.transactionFee.toBigInt(),
|
|
252
|
-
L2BlockHash.fromField(await block.hash()),
|
|
253
|
-
block.number,
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
return undefined;
|
|
363
|
+
public getL2ToL1MembershipWitness(): Promise<undefined> {
|
|
364
|
+
// Mock does not back the L2-to-L1 message witness flow.
|
|
365
|
+
return Promise.resolve(undefined);
|
|
259
366
|
}
|
|
260
367
|
|
|
261
368
|
async getL2Tips(): Promise<L2Tips> {
|
|
262
|
-
const [latest, proven, finalized] = [
|
|
369
|
+
const [latest, proven, finalized, checkpointed] = [
|
|
263
370
|
await this.getBlockNumber(),
|
|
264
|
-
|
|
371
|
+
this.provenBlockNumber,
|
|
265
372
|
this.finalizedBlockNumber,
|
|
373
|
+
this.checkpointedBlockNumber,
|
|
266
374
|
] as const;
|
|
267
375
|
|
|
268
376
|
const latestBlock = this.l2Blocks[latest - 1];
|
|
269
377
|
const provenBlock = this.l2Blocks[proven - 1];
|
|
270
378
|
const finalizedBlock = this.l2Blocks[finalized - 1];
|
|
379
|
+
const checkpointedBlock = this.l2Blocks[checkpointed - 1];
|
|
380
|
+
|
|
381
|
+
// For genesis tips (block number 0) report the dynamic initial header hash so consumers
|
|
382
|
+
// running L2BlockStream against this mock agree at block 0 with their local tip store.
|
|
383
|
+
const genesisHash = (await this.initialHeader.hash()).toString();
|
|
384
|
+
const tipHash = async (block: L2Block | undefined, number: number): Promise<string> => {
|
|
385
|
+
if (block) {
|
|
386
|
+
return (await block.hash()).toString();
|
|
387
|
+
}
|
|
388
|
+
return number === 0 ? genesisHash : '';
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
const latestBlockId = {
|
|
392
|
+
number: BlockNumber(latest),
|
|
393
|
+
hash: await tipHash(latestBlock, latest),
|
|
394
|
+
};
|
|
395
|
+
const provenBlockId = {
|
|
396
|
+
number: BlockNumber(proven),
|
|
397
|
+
hash: await tipHash(provenBlock, proven),
|
|
398
|
+
};
|
|
399
|
+
const finalizedBlockId = {
|
|
400
|
+
number: BlockNumber(finalized),
|
|
401
|
+
hash: await tipHash(finalizedBlock, finalized),
|
|
402
|
+
};
|
|
403
|
+
const checkpointedBlockId = {
|
|
404
|
+
number: BlockNumber(checkpointed),
|
|
405
|
+
hash: await tipHash(checkpointedBlock, checkpointed),
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
const makeTipId = (blockId: typeof latestBlockId) => {
|
|
409
|
+
const checkpointNumber = this.findCheckpointNumberForBlock(blockId.number) ?? CheckpointNumber(0);
|
|
410
|
+
// Match production semantics: checkpoint 0 is fully synthetic (no real checkpoint header
|
|
411
|
+
// exists at 0), so its hash stays at the protocol constant `GENESIS_CHECKPOINT_HEADER_HASH`
|
|
412
|
+
// even though the block-0 hash is dynamic. See L2TipsCache for the production path.
|
|
413
|
+
const hash = checkpointNumber === 0 ? GENESIS_CHECKPOINT_HEADER_HASH.toString() : blockId.hash;
|
|
414
|
+
return {
|
|
415
|
+
block: blockId,
|
|
416
|
+
checkpoint: { number: checkpointNumber, hash },
|
|
417
|
+
};
|
|
418
|
+
};
|
|
271
419
|
|
|
272
420
|
return {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
proven: {
|
|
278
|
-
number: BlockNumber(proven),
|
|
279
|
-
hash: (await provenBlock?.hash())?.toString(),
|
|
280
|
-
},
|
|
281
|
-
finalized: {
|
|
282
|
-
number: BlockNumber(finalized),
|
|
283
|
-
hash: (await finalizedBlock?.hash())?.toString(),
|
|
284
|
-
},
|
|
421
|
+
proposed: latestBlockId,
|
|
422
|
+
checkpointed: makeTipId(checkpointedBlockId),
|
|
423
|
+
proven: makeTipId(provenBlockId),
|
|
424
|
+
finalized: makeTipId(finalizedBlockId),
|
|
285
425
|
};
|
|
286
426
|
}
|
|
287
427
|
|
|
288
|
-
|
|
428
|
+
getSyncedL2EpochNumber(): Promise<EpochNumber> {
|
|
289
429
|
throw new Error('Method not implemented.');
|
|
290
430
|
}
|
|
291
431
|
|
|
292
|
-
|
|
432
|
+
getSyncedL2SlotNumber(): Promise<SlotNumber> {
|
|
293
433
|
throw new Error('Method not implemented.');
|
|
294
434
|
}
|
|
295
435
|
|
|
@@ -301,8 +441,12 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
301
441
|
return Promise.resolve(EmptyL1RollupConstants);
|
|
302
442
|
}
|
|
303
443
|
|
|
444
|
+
isPruneDueAtSlot(_slot: SlotNumber): Promise<boolean> {
|
|
445
|
+
return Promise.resolve(false);
|
|
446
|
+
}
|
|
447
|
+
|
|
304
448
|
getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
|
|
305
|
-
return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
|
|
449
|
+
return Promise.resolve({ genesisArchiveRoot: this.genesisArchiveRoot ?? new Fr(GENESIS_ARCHIVE_ROOT) });
|
|
306
450
|
}
|
|
307
451
|
|
|
308
452
|
getL1Timestamp(): Promise<bigint> {
|
|
@@ -355,11 +499,122 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
355
499
|
return Promise.resolve();
|
|
356
500
|
}
|
|
357
501
|
|
|
502
|
+
async getBlock(query: BlockQuery): Promise<L2Block | undefined> {
|
|
503
|
+
if ('number' in query) {
|
|
504
|
+
if (query.number === 0) {
|
|
505
|
+
return this.getGenesisBlock();
|
|
506
|
+
}
|
|
507
|
+
return this.l2Blocks[query.number - 1];
|
|
508
|
+
}
|
|
509
|
+
if ('hash' in query) {
|
|
510
|
+
const genesis = this.getGenesisBlock();
|
|
511
|
+
if ((await genesis.hash()).equals(query.hash)) {
|
|
512
|
+
return genesis;
|
|
513
|
+
}
|
|
514
|
+
for (const b of this.l2Blocks) {
|
|
515
|
+
const hash = await b.hash();
|
|
516
|
+
if (hash.equals(query.hash)) {
|
|
517
|
+
return b;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return undefined;
|
|
521
|
+
}
|
|
522
|
+
if ('archive' in query) {
|
|
523
|
+
const genesis = this.getGenesisBlock();
|
|
524
|
+
if (genesis.archive.root.equals(query.archive)) {
|
|
525
|
+
return genesis;
|
|
526
|
+
}
|
|
527
|
+
return this.l2Blocks.find(b => b.archive.root.equals(query.archive));
|
|
528
|
+
}
|
|
529
|
+
const number = this.resolveBlockTag(query.tag);
|
|
530
|
+
if (number === 0) {
|
|
531
|
+
return this.getGenesisBlock();
|
|
532
|
+
}
|
|
533
|
+
return this.l2Blocks[number - 1];
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
private resolveBlockTag(tag: BlockTag): number {
|
|
537
|
+
switch (tag) {
|
|
538
|
+
case 'latest':
|
|
539
|
+
case 'proposed':
|
|
540
|
+
return this.l2Blocks.length;
|
|
541
|
+
case 'checkpointed':
|
|
542
|
+
return this.checkpointedBlockNumber;
|
|
543
|
+
case 'proven':
|
|
544
|
+
return this.provenBlockNumber;
|
|
545
|
+
case 'finalized':
|
|
546
|
+
return this.finalizedBlockNumber;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
getBlocks(query: BlocksQuery): Promise<L2Block[]> {
|
|
551
|
+
let blocks: L2Block[];
|
|
552
|
+
if ('from' in query) {
|
|
553
|
+
blocks = this.l2Blocks.slice(query.from - 1, query.from - 1 + query.limit);
|
|
554
|
+
} else {
|
|
555
|
+
const epochCheckpoints = this.getCheckpointsInEpoch(query.epoch);
|
|
556
|
+
blocks = epochCheckpoints.flatMap(c => c.blocks);
|
|
557
|
+
}
|
|
558
|
+
if (query.onlyCheckpointed) {
|
|
559
|
+
blocks = blocks.filter(b => b.header.globalVariables.blockNumber <= this.checkpointedBlockNumber);
|
|
560
|
+
}
|
|
561
|
+
return Promise.resolve(blocks);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
async getBlockData(query: BlockQuery): Promise<BlockData | undefined> {
|
|
565
|
+
const block = await this.getBlock(query);
|
|
566
|
+
if (!block) {
|
|
567
|
+
return undefined;
|
|
568
|
+
}
|
|
569
|
+
return {
|
|
570
|
+
header: block.header,
|
|
571
|
+
archive: block.archive,
|
|
572
|
+
blockHash: await block.hash(),
|
|
573
|
+
checkpointNumber: block.checkpointNumber,
|
|
574
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
async getBlocksData(query: BlocksQuery): Promise<BlockData[]> {
|
|
579
|
+
const blocks = await this.getBlocks(query);
|
|
580
|
+
return Promise.all(
|
|
581
|
+
blocks.map(async block => ({
|
|
582
|
+
header: block.header,
|
|
583
|
+
archive: block.archive,
|
|
584
|
+
blockHash: await block.hash(),
|
|
585
|
+
checkpointNumber: block.checkpointNumber,
|
|
586
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
587
|
+
})),
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
|
|
358
591
|
isPendingChainInvalid(): Promise<boolean> {
|
|
359
592
|
return Promise.resolve(false);
|
|
360
593
|
}
|
|
361
594
|
|
|
362
|
-
getPendingChainValidationStatus(): Promise<
|
|
595
|
+
getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
|
|
363
596
|
return Promise.resolve({ valid: true });
|
|
364
597
|
}
|
|
598
|
+
|
|
599
|
+
getProposedCheckpointData(_query?: ProposedCheckpointQuery): Promise<ProposedCheckpointData | undefined> {
|
|
600
|
+
return Promise.resolve(undefined);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/** Returns checkpoints whose slot falls within the given epoch. */
|
|
604
|
+
private getCheckpointsInEpoch(epochNumber: EpochNumber): Checkpoint[] {
|
|
605
|
+
const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
|
|
606
|
+
const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
|
|
607
|
+
return this.checkpointList.filter(c => c.header.slotNumber >= start && c.header.slotNumber <= end);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/** Creates a mock L1PublishedData for a checkpoint. */
|
|
611
|
+
private mockL1DataForCheckpoint(checkpoint: Checkpoint): L1PublishedData {
|
|
612
|
+
return new L1PublishedData(BigInt(checkpoint.number), BigInt(checkpoint.number), Buffer32.random().toString());
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/** Finds the checkpoint number for a block, or undefined if the block is not in any checkpoint. */
|
|
616
|
+
private findCheckpointNumberForBlock(blockNumber: BlockNumber): CheckpointNumber | undefined {
|
|
617
|
+
const checkpoint = this.checkpointList.find(c => c.blocks.some(b => b.number === blockNumber));
|
|
618
|
+
return checkpoint?.number;
|
|
619
|
+
}
|
|
365
620
|
}
|