@aztec/archiver 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c

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.
Files changed (209) hide show
  1. package/README.md +156 -22
  2. package/dest/archiver.d.ts +139 -0
  3. package/dest/archiver.d.ts.map +1 -0
  4. package/dest/archiver.js +699 -0
  5. package/dest/config.d.ts +30 -0
  6. package/dest/config.d.ts.map +1 -0
  7. package/dest/{archiver/config.js → config.js} +21 -5
  8. package/dest/errors.d.ts +41 -0
  9. package/dest/errors.d.ts.map +1 -0
  10. package/dest/errors.js +62 -0
  11. package/dest/factory.d.ts +9 -7
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +97 -13
  14. package/dest/index.d.ts +11 -4
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +9 -3
  17. package/dest/interfaces.d.ts +9 -0
  18. package/dest/interfaces.d.ts.map +1 -0
  19. package/dest/interfaces.js +3 -0
  20. package/dest/l1/bin/retrieve-calldata.d.ts +3 -0
  21. package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
  22. package/dest/l1/bin/retrieve-calldata.js +148 -0
  23. package/dest/l1/calldata_retriever.d.ts +118 -0
  24. package/dest/l1/calldata_retriever.d.ts.map +1 -0
  25. package/dest/l1/calldata_retriever.js +484 -0
  26. package/dest/l1/data_retrieval.d.ts +89 -0
  27. package/dest/l1/data_retrieval.d.ts.map +1 -0
  28. package/dest/{archiver → l1}/data_retrieval.js +80 -153
  29. package/dest/l1/debug_tx.d.ts +19 -0
  30. package/dest/l1/debug_tx.d.ts.map +1 -0
  31. package/dest/l1/debug_tx.js +73 -0
  32. package/dest/l1/spire_proposer.d.ts +70 -0
  33. package/dest/l1/spire_proposer.d.ts.map +1 -0
  34. package/dest/l1/spire_proposer.js +157 -0
  35. package/dest/l1/trace_tx.d.ts +97 -0
  36. package/dest/l1/trace_tx.d.ts.map +1 -0
  37. package/dest/l1/trace_tx.js +91 -0
  38. package/dest/l1/types.d.ts +12 -0
  39. package/dest/l1/types.d.ts.map +1 -0
  40. package/dest/l1/types.js +3 -0
  41. package/dest/l1/validate_trace.d.ts +32 -0
  42. package/dest/l1/validate_trace.d.ts.map +1 -0
  43. package/dest/l1/validate_trace.js +154 -0
  44. package/dest/modules/data_source_base.d.ts +89 -0
  45. package/dest/modules/data_source_base.d.ts.map +1 -0
  46. package/dest/modules/data_source_base.js +216 -0
  47. package/dest/modules/data_store_updater.d.ts +80 -0
  48. package/dest/modules/data_store_updater.d.ts.map +1 -0
  49. package/dest/modules/data_store_updater.js +323 -0
  50. package/dest/modules/instrumentation.d.ts +39 -0
  51. package/dest/modules/instrumentation.d.ts.map +1 -0
  52. package/dest/{archiver → modules}/instrumentation.js +39 -62
  53. package/dest/modules/l1_synchronizer.d.ts +76 -0
  54. package/dest/modules/l1_synchronizer.d.ts.map +1 -0
  55. package/dest/modules/l1_synchronizer.js +1112 -0
  56. package/dest/modules/validation.d.ts +17 -0
  57. package/dest/modules/validation.d.ts.map +1 -0
  58. package/dest/{archiver → modules}/validation.js +7 -1
  59. package/dest/store/block_store.d.ts +196 -0
  60. package/dest/store/block_store.d.ts.map +1 -0
  61. package/dest/store/block_store.js +773 -0
  62. package/dest/store/contract_class_store.d.ts +18 -0
  63. package/dest/store/contract_class_store.d.ts.map +1 -0
  64. package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +13 -9
  65. package/dest/store/contract_instance_store.d.ts +24 -0
  66. package/dest/store/contract_instance_store.d.ts.map +1 -0
  67. package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +1 -1
  68. package/dest/store/kv_archiver_store.d.ts +354 -0
  69. package/dest/store/kv_archiver_store.d.ts.map +1 -0
  70. package/dest/store/kv_archiver_store.js +464 -0
  71. package/dest/store/l2_tips_cache.d.ts +19 -0
  72. package/dest/store/l2_tips_cache.d.ts.map +1 -0
  73. package/dest/store/l2_tips_cache.js +89 -0
  74. package/dest/store/log_store.d.ts +54 -0
  75. package/dest/store/log_store.d.ts.map +1 -0
  76. package/dest/store/log_store.js +456 -0
  77. package/dest/store/message_store.d.ts +40 -0
  78. package/dest/store/message_store.d.ts.map +1 -0
  79. package/dest/{archiver/kv_archiver_store → store}/message_store.js +15 -14
  80. package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
  81. package/dest/structs/data_retrieval.d.ts.map +1 -0
  82. package/dest/structs/inbox_message.d.ts +15 -0
  83. package/dest/structs/inbox_message.d.ts.map +1 -0
  84. package/dest/{archiver/structs → structs}/inbox_message.js +6 -5
  85. package/dest/structs/published.d.ts +2 -0
  86. package/dest/structs/published.d.ts.map +1 -0
  87. package/dest/test/fake_l1_state.d.ts +193 -0
  88. package/dest/test/fake_l1_state.d.ts.map +1 -0
  89. package/dest/test/fake_l1_state.js +389 -0
  90. package/dest/test/index.d.ts +2 -1
  91. package/dest/test/index.d.ts.map +1 -1
  92. package/dest/test/index.js +4 -1
  93. package/dest/test/mock_archiver.d.ts +16 -8
  94. package/dest/test/mock_archiver.d.ts.map +1 -1
  95. package/dest/test/mock_archiver.js +19 -14
  96. package/dest/test/mock_l1_to_l2_message_source.d.ts +7 -6
  97. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  98. package/dest/test/mock_l1_to_l2_message_source.js +21 -11
  99. package/dest/test/mock_l2_block_source.d.ts +51 -18
  100. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  101. package/dest/test/mock_l2_block_source.js +245 -82
  102. package/dest/test/mock_structs.d.ts +80 -4
  103. package/dest/test/mock_structs.d.ts.map +1 -1
  104. package/dest/test/mock_structs.js +145 -11
  105. package/dest/test/noop_l1_archiver.d.ts +23 -0
  106. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  107. package/dest/test/noop_l1_archiver.js +68 -0
  108. package/package.json +20 -20
  109. package/src/archiver.ts +443 -0
  110. package/src/{archiver/config.ts → config.ts} +28 -12
  111. package/src/errors.ts +102 -0
  112. package/src/factory.ts +143 -13
  113. package/src/index.ts +11 -3
  114. package/src/interfaces.ts +9 -0
  115. package/src/l1/README.md +98 -0
  116. package/src/l1/bin/retrieve-calldata.ts +181 -0
  117. package/src/l1/calldata_retriever.ts +663 -0
  118. package/src/{archiver → l1}/data_retrieval.ts +146 -224
  119. package/src/l1/debug_tx.ts +99 -0
  120. package/src/l1/spire_proposer.ts +160 -0
  121. package/src/l1/trace_tx.ts +128 -0
  122. package/src/l1/types.ts +13 -0
  123. package/src/l1/validate_trace.ts +229 -0
  124. package/src/modules/data_source_base.ts +328 -0
  125. package/src/modules/data_store_updater.ts +448 -0
  126. package/src/{archiver → modules}/instrumentation.ts +43 -66
  127. package/src/modules/l1_synchronizer.ts +932 -0
  128. package/src/{archiver → modules}/validation.ts +11 -6
  129. package/src/store/block_store.ts +1015 -0
  130. package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +13 -9
  131. package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +2 -2
  132. package/src/store/kv_archiver_store.ts +671 -0
  133. package/src/store/l2_tips_cache.ts +89 -0
  134. package/src/store/log_store.ts +637 -0
  135. package/src/{archiver/kv_archiver_store → store}/message_store.ts +21 -18
  136. package/src/{archiver/structs → structs}/inbox_message.ts +8 -8
  137. package/src/{archiver/structs → structs}/published.ts +0 -1
  138. package/src/test/fake_l1_state.ts +607 -0
  139. package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
  140. package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
  141. package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
  142. package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
  143. package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
  144. package/src/test/fixtures/trace_transaction-proxied.json +128 -0
  145. package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
  146. package/src/test/index.ts +4 -0
  147. package/src/test/mock_archiver.ts +23 -16
  148. package/src/test/mock_l1_to_l2_message_source.ts +18 -11
  149. package/src/test/mock_l2_block_source.ts +296 -90
  150. package/src/test/mock_structs.ts +275 -13
  151. package/src/test/noop_l1_archiver.ts +109 -0
  152. package/dest/archiver/archiver.d.ts +0 -287
  153. package/dest/archiver/archiver.d.ts.map +0 -1
  154. package/dest/archiver/archiver.js +0 -1408
  155. package/dest/archiver/archiver_store.d.ts +0 -255
  156. package/dest/archiver/archiver_store.d.ts.map +0 -1
  157. package/dest/archiver/archiver_store.js +0 -4
  158. package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
  159. package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
  160. package/dest/archiver/archiver_store_test_suite.js +0 -1289
  161. package/dest/archiver/config.d.ts +0 -21
  162. package/dest/archiver/config.d.ts.map +0 -1
  163. package/dest/archiver/data_retrieval.d.ts +0 -79
  164. package/dest/archiver/data_retrieval.d.ts.map +0 -1
  165. package/dest/archiver/errors.d.ts +0 -12
  166. package/dest/archiver/errors.d.ts.map +0 -1
  167. package/dest/archiver/errors.js +0 -17
  168. package/dest/archiver/index.d.ts +0 -7
  169. package/dest/archiver/index.d.ts.map +0 -1
  170. package/dest/archiver/index.js +0 -4
  171. package/dest/archiver/instrumentation.d.ts +0 -35
  172. package/dest/archiver/instrumentation.d.ts.map +0 -1
  173. package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -124
  174. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
  175. package/dest/archiver/kv_archiver_store/block_store.js +0 -370
  176. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
  177. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
  178. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
  179. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
  180. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -168
  181. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
  182. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -296
  183. package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -49
  184. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
  185. package/dest/archiver/kv_archiver_store/log_store.js +0 -336
  186. package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -39
  187. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
  188. package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
  189. package/dest/archiver/structs/inbox_message.d.ts +0 -15
  190. package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
  191. package/dest/archiver/structs/published.d.ts +0 -3
  192. package/dest/archiver/structs/published.d.ts.map +0 -1
  193. package/dest/archiver/validation.d.ts +0 -17
  194. package/dest/archiver/validation.d.ts.map +0 -1
  195. package/dest/rpc/index.d.ts +0 -9
  196. package/dest/rpc/index.d.ts.map +0 -1
  197. package/dest/rpc/index.js +0 -15
  198. package/src/archiver/archiver.ts +0 -1858
  199. package/src/archiver/archiver_store.ts +0 -305
  200. package/src/archiver/archiver_store_test_suite.ts +0 -1264
  201. package/src/archiver/errors.ts +0 -26
  202. package/src/archiver/index.ts +0 -6
  203. package/src/archiver/kv_archiver_store/block_store.ts +0 -481
  204. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -422
  205. package/src/archiver/kv_archiver_store/log_store.ts +0 -406
  206. package/src/rpc/index.ts +0 -16
  207. /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
  208. /package/dest/{archiver/structs → structs}/published.js +0 -0
  209. /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
@@ -0,0 +1,328 @@
1
+ import { range } from '@aztec/foundation/array';
2
+ import { BlockNumber, CheckpointNumber, type EpochNumber, type SlotNumber } from '@aztec/foundation/branded-types';
3
+ import type { Fr } from '@aztec/foundation/curves/bn254';
4
+ import type { EthAddress } from '@aztec/foundation/eth-address';
5
+ import { isDefined } from '@aztec/foundation/types';
6
+ import type { FunctionSelector } from '@aztec/stdlib/abi';
7
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
8
+ import { type BlockData, type BlockHash, CheckpointedL2Block, L2Block, type L2Tips } from '@aztec/stdlib/block';
9
+ import { Checkpoint, type CheckpointData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
10
+ import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
11
+ import { type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
12
+ import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
13
+ import type { L2LogsSource } from '@aztec/stdlib/interfaces/server';
14
+ import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
15
+ import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
16
+ import type { CheckpointHeader } from '@aztec/stdlib/rollup';
17
+ import type { BlockHeader, IndexedTxEffect, TxHash, TxReceipt } from '@aztec/stdlib/tx';
18
+ import type { UInt64 } from '@aztec/stdlib/types';
19
+
20
+ import type { ArchiverDataSource } from '../interfaces.js';
21
+ import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
22
+ import type { ValidateCheckpointResult } from './validation.js';
23
+
24
+ /**
25
+ * Abstract base class implementing ArchiverDataSource using a KVArchiverDataStore.
26
+ * Provides implementations for all store-delegating methods and declares abstract methods
27
+ * for L1-dependent functionality that subclasses must implement.
28
+ */
29
+ export abstract class ArchiverDataSourceBase
30
+ implements ArchiverDataSource, L2LogsSource, ContractDataSource, L1ToL2MessageSource
31
+ {
32
+ constructor(
33
+ protected readonly store: KVArchiverDataStore,
34
+ protected readonly l1Constants?: L1RollupConstants,
35
+ ) {}
36
+
37
+ abstract getRollupAddress(): Promise<EthAddress>;
38
+
39
+ abstract getRegistryAddress(): Promise<EthAddress>;
40
+
41
+ abstract getL1Constants(): Promise<L1RollupConstants>;
42
+
43
+ abstract getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }>;
44
+
45
+ abstract getL1Timestamp(): Promise<bigint | undefined>;
46
+
47
+ abstract getL2Tips(): Promise<L2Tips>;
48
+
49
+ abstract getL2SlotNumber(): Promise<SlotNumber | undefined>;
50
+
51
+ abstract getL2EpochNumber(): Promise<EpochNumber | undefined>;
52
+
53
+ abstract isEpochComplete(epochNumber: EpochNumber): Promise<boolean>;
54
+
55
+ abstract syncImmediate(): Promise<void>;
56
+
57
+ public getCheckpointNumber(): Promise<CheckpointNumber> {
58
+ return this.store.getSynchedCheckpointNumber();
59
+ }
60
+
61
+ public getSynchedCheckpointNumber(): Promise<CheckpointNumber> {
62
+ return this.store.getSynchedCheckpointNumber();
63
+ }
64
+
65
+ public getProvenCheckpointNumber(): Promise<CheckpointNumber> {
66
+ return this.store.getProvenCheckpointNumber();
67
+ }
68
+
69
+ public getBlockNumber(): Promise<BlockNumber> {
70
+ return this.store.getLatestBlockNumber();
71
+ }
72
+
73
+ public getProvenBlockNumber(): Promise<BlockNumber> {
74
+ return this.store.getProvenBlockNumber();
75
+ }
76
+
77
+ public async getBlockHeader(number: BlockNumber | 'latest'): Promise<BlockHeader | undefined> {
78
+ const blockNumber = number === 'latest' ? await this.store.getLatestBlockNumber() : number;
79
+ if (blockNumber === 0) {
80
+ return undefined;
81
+ }
82
+ const headers = await this.store.getBlockHeaders(blockNumber, 1);
83
+ return headers.length === 0 ? undefined : headers[0];
84
+ }
85
+
86
+ public getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined> {
87
+ return this.store.getCheckpointedBlock(number);
88
+ }
89
+
90
+ public getCheckpointedL2BlockNumber(): Promise<BlockNumber> {
91
+ return this.store.getCheckpointedL2BlockNumber();
92
+ }
93
+
94
+ public getFinalizedL2BlockNumber(): Promise<BlockNumber> {
95
+ return this.store.getFinalizedL2BlockNumber();
96
+ }
97
+
98
+ public async getCheckpointHeader(number: CheckpointNumber | 'latest'): Promise<CheckpointHeader | undefined> {
99
+ if (number === 'latest') {
100
+ number = await this.store.getSynchedCheckpointNumber();
101
+ }
102
+ if (number === 0) {
103
+ return undefined;
104
+ }
105
+ const checkpoint = await this.store.getCheckpointData(number);
106
+ if (!checkpoint) {
107
+ return undefined;
108
+ }
109
+ return checkpoint.header;
110
+ }
111
+
112
+ public async getLastBlockNumberInCheckpoint(checkpointNumber: CheckpointNumber): Promise<BlockNumber | undefined> {
113
+ const checkpointData = await this.store.getCheckpointData(checkpointNumber);
114
+ if (!checkpointData) {
115
+ return undefined;
116
+ }
117
+ return BlockNumber(checkpointData.startBlock + checkpointData.blockCount - 1);
118
+ }
119
+
120
+ public getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
121
+ return this.store.getCheckpointedBlocks(from, limit);
122
+ }
123
+
124
+ public getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
125
+ return this.store.getBlockHeaderByHash(blockHash);
126
+ }
127
+
128
+ public getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
129
+ return this.store.getBlockHeaderByArchive(archive);
130
+ }
131
+
132
+ public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
133
+ return this.store.getBlockData(number);
134
+ }
135
+
136
+ public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
137
+ return this.store.getBlockDataByArchive(archive);
138
+ }
139
+
140
+ public async getL2Block(number: BlockNumber): Promise<L2Block | undefined> {
141
+ // If the number provided is -ve, then return the latest block.
142
+ if (number < 0) {
143
+ number = await this.store.getLatestBlockNumber();
144
+ }
145
+ if (number === 0) {
146
+ return undefined;
147
+ }
148
+ const publishedBlock = await this.store.getBlock(number);
149
+ return publishedBlock;
150
+ }
151
+
152
+ public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
153
+ return this.store.getTxEffect(txHash);
154
+ }
155
+
156
+ public getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
157
+ return this.store.getSettledTxReceipt(txHash);
158
+ }
159
+
160
+ public isPendingChainInvalid(): Promise<boolean> {
161
+ return this.getPendingChainValidationStatus().then(status => !status.valid);
162
+ }
163
+
164
+ public async getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
165
+ return (await this.store.getPendingChainValidationStatus()) ?? { valid: true };
166
+ }
167
+
168
+ public getPrivateLogsByTags(tags: SiloedTag[], page?: number): Promise<TxScopedL2Log[][]> {
169
+ return this.store.getPrivateLogsByTags(tags, page);
170
+ }
171
+
172
+ public getPublicLogsByTagsFromContract(
173
+ contractAddress: AztecAddress,
174
+ tags: Tag[],
175
+ page?: number,
176
+ ): Promise<TxScopedL2Log[][]> {
177
+ return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, page);
178
+ }
179
+
180
+ public getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
181
+ return this.store.getPublicLogs(filter);
182
+ }
183
+
184
+ public getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse> {
185
+ return this.store.getContractClassLogs(filter);
186
+ }
187
+
188
+ public getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
189
+ return this.store.getContractClass(id);
190
+ }
191
+
192
+ public getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
193
+ return this.store.getBytecodeCommitment(id);
194
+ }
195
+
196
+ public async getContract(
197
+ address: AztecAddress,
198
+ maybeTimestamp?: UInt64,
199
+ ): Promise<ContractInstanceWithAddress | undefined> {
200
+ let timestamp;
201
+ if (maybeTimestamp === undefined) {
202
+ const latestBlockHeader = await this.getBlockHeader('latest');
203
+ // If we get undefined block header, it means that the archiver has not yet synced any block so we default to 0.
204
+ timestamp = latestBlockHeader ? latestBlockHeader.globalVariables.timestamp : 0n;
205
+ } else {
206
+ timestamp = maybeTimestamp;
207
+ }
208
+
209
+ return this.store.getContractInstance(address, timestamp);
210
+ }
211
+
212
+ public getContractClassIds(): Promise<Fr[]> {
213
+ return this.store.getContractClassIds();
214
+ }
215
+
216
+ public getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
217
+ return this.store.getDebugFunctionName(address, selector);
218
+ }
219
+
220
+ public registerContractFunctionSignatures(signatures: string[]): Promise<void> {
221
+ return this.store.registerContractFunctionSignatures(signatures);
222
+ }
223
+
224
+ public getL1ToL2Messages(checkpointNumber: CheckpointNumber): Promise<Fr[]> {
225
+ return this.store.getL1ToL2Messages(checkpointNumber);
226
+ }
227
+
228
+ public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined> {
229
+ return this.store.getL1ToL2MessageIndex(l1ToL2Message);
230
+ }
231
+
232
+ public async getCheckpoints(checkpointNumber: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
233
+ const checkpoints = await this.store.getRangeOfCheckpoints(checkpointNumber, limit);
234
+ return Promise.all(checkpoints.map(ch => this.getPublishedCheckpointFromCheckpointData(ch)));
235
+ }
236
+
237
+ private async getPublishedCheckpointFromCheckpointData(checkpoint: CheckpointData): Promise<PublishedCheckpoint> {
238
+ const blocksForCheckpoint = await this.store.getBlocksForCheckpoint(checkpoint.checkpointNumber);
239
+ if (!blocksForCheckpoint) {
240
+ throw new Error(`Blocks for checkpoint ${checkpoint.checkpointNumber} not found`);
241
+ }
242
+ const fullCheckpoint = new Checkpoint(
243
+ checkpoint.archive,
244
+ checkpoint.header,
245
+ blocksForCheckpoint,
246
+ checkpoint.checkpointNumber,
247
+ );
248
+ return new PublishedCheckpoint(fullCheckpoint, checkpoint.l1, checkpoint.attestations);
249
+ }
250
+
251
+ public getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
252
+ return this.store.getBlocksForSlot(slotNumber);
253
+ }
254
+
255
+ public async getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]> {
256
+ const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
257
+ const blocks = await Promise.all(
258
+ checkpointsData.flatMap(checkpoint =>
259
+ range(checkpoint.blockCount, checkpoint.startBlock).map(blockNumber =>
260
+ this.getCheckpointedBlock(BlockNumber(blockNumber)),
261
+ ),
262
+ ),
263
+ );
264
+ return blocks.filter(isDefined);
265
+ }
266
+
267
+ public async getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
268
+ const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
269
+ const blocks = await Promise.all(
270
+ checkpointsData.flatMap(checkpoint =>
271
+ range(checkpoint.blockCount, checkpoint.startBlock).map(blockNumber =>
272
+ this.getBlockHeader(BlockNumber(blockNumber)),
273
+ ),
274
+ ),
275
+ );
276
+ return blocks.filter(isDefined);
277
+ }
278
+
279
+ public async getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
280
+ const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
281
+ return Promise.all(
282
+ checkpointsData.map(data => this.getPublishedCheckpointFromCheckpointData(data).then(p => p.checkpoint)),
283
+ );
284
+ }
285
+
286
+ /** Returns checkpoint data for all checkpoints whose slot falls within the given epoch. */
287
+ public getCheckpointsDataForEpoch(epochNumber: EpochNumber): Promise<CheckpointData[]> {
288
+ if (!this.l1Constants) {
289
+ throw new Error('L1 constants not set');
290
+ }
291
+
292
+ const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
293
+ return this.store.getCheckpointDataForSlotRange(start, end);
294
+ }
295
+
296
+ public async getBlock(number: BlockNumber): Promise<L2Block | undefined> {
297
+ // If the number provided is -ve, then return the latest block.
298
+ if (number < 0) {
299
+ number = await this.store.getLatestBlockNumber();
300
+ }
301
+ if (number === 0) {
302
+ return undefined;
303
+ }
304
+ return this.store.getBlock(number);
305
+ }
306
+
307
+ public getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
308
+ return this.store.getBlocks(from, limit);
309
+ }
310
+
311
+ public getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
312
+ return this.store.getCheckpointedBlockByHash(blockHash);
313
+ }
314
+
315
+ public getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
316
+ return this.store.getCheckpointedBlockByArchive(archive);
317
+ }
318
+
319
+ public async getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
320
+ const checkpointedBlock = await this.store.getCheckpointedBlockByHash(blockHash);
321
+ return checkpointedBlock?.block;
322
+ }
323
+
324
+ public async getL2BlockByArchive(archive: Fr): Promise<L2Block | undefined> {
325
+ const checkpointedBlock = await this.store.getCheckpointedBlockByArchive(archive);
326
+ return checkpointedBlock?.block;
327
+ }
328
+ }