@aztec/archiver 0.0.1-commit.fcb71a6 → 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 (200) 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/{archiver/config.d.ts → config.d.ts} +9 -1
  6. package/dest/config.d.ts.map +1 -0
  7. package/dest/{archiver/config.js → config.js} +11 -2
  8. package/dest/errors.d.ts +41 -0
  9. package/dest/errors.d.ts.map +1 -0
  10. package/dest/{archiver/errors.js → errors.js} +8 -0
  11. package/dest/factory.d.ts +9 -7
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +94 -11
  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/{archiver/l1 → l1}/bin/retrieve-calldata.d.ts +1 -1
  21. package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
  22. package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.js +17 -18
  23. package/dest/{archiver/l1 → l1}/calldata_retriever.d.ts +9 -3
  24. package/dest/l1/calldata_retriever.d.ts.map +1 -0
  25. package/dest/{archiver/l1 → l1}/calldata_retriever.js +19 -6
  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 → l1}/data_retrieval.js +39 -57
  29. package/dest/{archiver/l1 → l1}/debug_tx.d.ts +1 -1
  30. package/dest/l1/debug_tx.d.ts.map +1 -0
  31. package/dest/{archiver/l1 → l1}/spire_proposer.d.ts +1 -1
  32. package/dest/l1/spire_proposer.d.ts.map +1 -0
  33. package/dest/{archiver/l1 → l1}/trace_tx.d.ts +1 -1
  34. package/dest/l1/trace_tx.d.ts.map +1 -0
  35. package/dest/l1/types.d.ts +12 -0
  36. package/dest/l1/types.d.ts.map +1 -0
  37. package/dest/{archiver/l1 → l1}/validate_trace.d.ts +6 -3
  38. package/dest/l1/validate_trace.d.ts.map +1 -0
  39. package/dest/{archiver/l1 → l1}/validate_trace.js +14 -10
  40. package/dest/modules/data_source_base.d.ts +89 -0
  41. package/dest/modules/data_source_base.d.ts.map +1 -0
  42. package/dest/modules/data_source_base.js +216 -0
  43. package/dest/modules/data_store_updater.d.ts +80 -0
  44. package/dest/modules/data_store_updater.d.ts.map +1 -0
  45. package/dest/modules/data_store_updater.js +323 -0
  46. package/dest/modules/instrumentation.d.ts +39 -0
  47. package/dest/modules/instrumentation.d.ts.map +1 -0
  48. package/dest/{archiver → modules}/instrumentation.js +33 -67
  49. package/dest/modules/l1_synchronizer.d.ts +76 -0
  50. package/dest/modules/l1_synchronizer.d.ts.map +1 -0
  51. package/dest/modules/l1_synchronizer.js +1112 -0
  52. package/dest/modules/validation.d.ts +17 -0
  53. package/dest/modules/validation.d.ts.map +1 -0
  54. package/dest/{archiver → modules}/validation.js +7 -1
  55. package/dest/store/block_store.d.ts +196 -0
  56. package/dest/store/block_store.d.ts.map +1 -0
  57. package/dest/{archiver/kv_archiver_store → store}/block_store.js +228 -62
  58. package/dest/store/contract_class_store.d.ts +18 -0
  59. package/dest/store/contract_class_store.d.ts.map +1 -0
  60. package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +12 -8
  61. package/dest/store/contract_instance_store.d.ts +24 -0
  62. package/dest/store/contract_instance_store.d.ts.map +1 -0
  63. package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +1 -1
  64. package/dest/store/kv_archiver_store.d.ts +354 -0
  65. package/dest/store/kv_archiver_store.d.ts.map +1 -0
  66. package/dest/store/kv_archiver_store.js +464 -0
  67. package/dest/store/l2_tips_cache.d.ts +19 -0
  68. package/dest/store/l2_tips_cache.d.ts.map +1 -0
  69. package/dest/store/l2_tips_cache.js +89 -0
  70. package/dest/store/log_store.d.ts +54 -0
  71. package/dest/store/log_store.d.ts.map +1 -0
  72. package/dest/{archiver/kv_archiver_store → store}/log_store.js +146 -91
  73. package/dest/{archiver/kv_archiver_store → store}/message_store.d.ts +1 -1
  74. package/dest/store/message_store.d.ts.map +1 -0
  75. package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
  76. package/dest/structs/data_retrieval.d.ts.map +1 -0
  77. package/dest/structs/inbox_message.d.ts +15 -0
  78. package/dest/structs/inbox_message.d.ts.map +1 -0
  79. package/dest/{archiver/structs → structs}/published.d.ts +1 -1
  80. package/dest/structs/published.d.ts.map +1 -0
  81. package/dest/test/fake_l1_state.d.ts +193 -0
  82. package/dest/test/fake_l1_state.d.ts.map +1 -0
  83. package/dest/test/fake_l1_state.js +389 -0
  84. package/dest/test/index.d.ts +2 -1
  85. package/dest/test/index.d.ts.map +1 -1
  86. package/dest/test/index.js +4 -1
  87. package/dest/test/mock_archiver.d.ts +2 -2
  88. package/dest/test/mock_archiver.d.ts.map +1 -1
  89. package/dest/test/mock_archiver.js +3 -3
  90. package/dest/test/mock_l1_to_l2_message_source.d.ts +2 -2
  91. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  92. package/dest/test/mock_l1_to_l2_message_source.js +12 -3
  93. package/dest/test/mock_l2_block_source.d.ts +39 -17
  94. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  95. package/dest/test/mock_l2_block_source.js +232 -83
  96. package/dest/test/mock_structs.d.ts +78 -3
  97. package/dest/test/mock_structs.d.ts.map +1 -1
  98. package/dest/test/mock_structs.js +140 -7
  99. package/dest/test/noop_l1_archiver.d.ts +23 -0
  100. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  101. package/dest/test/noop_l1_archiver.js +68 -0
  102. package/package.json +16 -17
  103. package/src/archiver.ts +443 -0
  104. package/src/{archiver/config.ts → config.ts} +13 -2
  105. package/src/{archiver/errors.ts → errors.ts} +12 -0
  106. package/src/factory.ts +140 -11
  107. package/src/index.ts +11 -3
  108. package/src/interfaces.ts +9 -0
  109. package/src/{archiver/l1 → l1}/bin/retrieve-calldata.ts +16 -17
  110. package/src/{archiver/l1 → l1}/calldata_retriever.ts +28 -6
  111. package/src/{archiver/l1 → l1}/data_retrieval.ts +60 -74
  112. package/src/{archiver/l1 → l1}/validate_trace.ts +25 -7
  113. package/src/modules/data_source_base.ts +328 -0
  114. package/src/modules/data_store_updater.ts +448 -0
  115. package/src/{archiver → modules}/instrumentation.ts +33 -70
  116. package/src/modules/l1_synchronizer.ts +932 -0
  117. package/src/{archiver → modules}/validation.ts +11 -6
  118. package/src/{archiver/kv_archiver_store → store}/block_store.ts +293 -100
  119. package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +12 -8
  120. package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +1 -1
  121. package/src/{archiver/kv_archiver_store → store}/kv_archiver_store.ts +273 -40
  122. package/src/store/l2_tips_cache.ts +89 -0
  123. package/src/{archiver/kv_archiver_store → store}/log_store.ts +242 -121
  124. package/src/test/fake_l1_state.ts +607 -0
  125. package/src/test/index.ts +4 -0
  126. package/src/test/mock_archiver.ts +4 -3
  127. package/src/test/mock_l1_to_l2_message_source.ts +10 -4
  128. package/src/test/mock_l2_block_source.ts +276 -90
  129. package/src/test/mock_structs.ts +269 -8
  130. package/src/test/noop_l1_archiver.ts +109 -0
  131. package/dest/archiver/archiver.d.ts +0 -304
  132. package/dest/archiver/archiver.d.ts.map +0 -1
  133. package/dest/archiver/archiver.js +0 -1645
  134. package/dest/archiver/archiver_store.d.ts +0 -308
  135. package/dest/archiver/archiver_store.d.ts.map +0 -1
  136. package/dest/archiver/archiver_store.js +0 -4
  137. package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
  138. package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
  139. package/dest/archiver/archiver_store_test_suite.js +0 -2770
  140. package/dest/archiver/config.d.ts.map +0 -1
  141. package/dest/archiver/errors.d.ts +0 -36
  142. package/dest/archiver/errors.d.ts.map +0 -1
  143. package/dest/archiver/index.d.ts +0 -7
  144. package/dest/archiver/index.d.ts.map +0 -1
  145. package/dest/archiver/index.js +0 -4
  146. package/dest/archiver/instrumentation.d.ts +0 -37
  147. package/dest/archiver/instrumentation.d.ts.map +0 -1
  148. package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -157
  149. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
  150. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
  151. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
  152. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
  153. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
  154. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -158
  155. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
  156. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -313
  157. package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -45
  158. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
  159. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
  160. package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +0 -1
  161. package/dest/archiver/l1/calldata_retriever.d.ts.map +0 -1
  162. package/dest/archiver/l1/data_retrieval.d.ts +0 -90
  163. package/dest/archiver/l1/data_retrieval.d.ts.map +0 -1
  164. package/dest/archiver/l1/debug_tx.d.ts.map +0 -1
  165. package/dest/archiver/l1/spire_proposer.d.ts.map +0 -1
  166. package/dest/archiver/l1/trace_tx.d.ts.map +0 -1
  167. package/dest/archiver/l1/types.d.ts +0 -12
  168. package/dest/archiver/l1/types.d.ts.map +0 -1
  169. package/dest/archiver/l1/validate_trace.d.ts.map +0 -1
  170. package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
  171. package/dest/archiver/structs/inbox_message.d.ts +0 -15
  172. package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
  173. package/dest/archiver/structs/published.d.ts.map +0 -1
  174. package/dest/archiver/validation.d.ts +0 -17
  175. package/dest/archiver/validation.d.ts.map +0 -1
  176. package/dest/rpc/index.d.ts +0 -9
  177. package/dest/rpc/index.d.ts.map +0 -1
  178. package/dest/rpc/index.js +0 -15
  179. package/src/archiver/archiver.ts +0 -2157
  180. package/src/archiver/archiver_store.ts +0 -372
  181. package/src/archiver/archiver_store_test_suite.ts +0 -2843
  182. package/src/archiver/index.ts +0 -6
  183. package/src/rpc/index.ts +0 -16
  184. /package/dest/{archiver/l1 → l1}/debug_tx.js +0 -0
  185. /package/dest/{archiver/l1 → l1}/spire_proposer.js +0 -0
  186. /package/dest/{archiver/l1 → l1}/trace_tx.js +0 -0
  187. /package/dest/{archiver/l1 → l1}/types.js +0 -0
  188. /package/dest/{archiver/kv_archiver_store → store}/message_store.js +0 -0
  189. /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
  190. /package/dest/{archiver/structs → structs}/inbox_message.js +0 -0
  191. /package/dest/{archiver/structs → structs}/published.js +0 -0
  192. /package/src/{archiver/l1 → l1}/README.md +0 -0
  193. /package/src/{archiver/l1 → l1}/debug_tx.ts +0 -0
  194. /package/src/{archiver/l1 → l1}/spire_proposer.ts +0 -0
  195. /package/src/{archiver/l1 → l1}/trace_tx.ts +0 -0
  196. /package/src/{archiver/l1 → l1}/types.ts +0 -0
  197. /package/src/{archiver/kv_archiver_store → store}/message_store.ts +0 -0
  198. /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
  199. /package/src/{archiver/structs → structs}/inbox_message.ts +0 -0
  200. /package/src/{archiver/structs → structs}/published.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
+ }