@aztec/archiver 0.0.1-commit.7d4e6cd → 0.0.1-commit.87a0206

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 (191) hide show
  1. package/README.md +156 -22
  2. package/dest/archiver.d.ts +136 -0
  3. package/dest/archiver.d.ts.map +1 -0
  4. package/dest/archiver.js +781 -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} +9 -0
  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 +89 -11
  14. package/dest/index.d.ts +10 -4
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +8 -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 +2 -2
  24. package/dest/l1/calldata_retriever.d.ts.map +1 -0
  25. package/dest/l1/data_retrieval.d.ts +88 -0
  26. package/dest/l1/data_retrieval.d.ts.map +1 -0
  27. package/dest/{archiver/l1 → l1}/data_retrieval.js +36 -55
  28. package/dest/{archiver/l1 → l1}/debug_tx.d.ts +1 -1
  29. package/dest/l1/debug_tx.d.ts.map +1 -0
  30. package/dest/{archiver/l1 → l1}/spire_proposer.d.ts +1 -1
  31. package/dest/l1/spire_proposer.d.ts.map +1 -0
  32. package/dest/{archiver/l1 → l1}/trace_tx.d.ts +1 -1
  33. package/dest/l1/trace_tx.d.ts.map +1 -0
  34. package/dest/l1/types.d.ts +12 -0
  35. package/dest/l1/types.d.ts.map +1 -0
  36. package/dest/{archiver/l1 → l1}/validate_trace.d.ts +6 -3
  37. package/dest/l1/validate_trace.d.ts.map +1 -0
  38. package/dest/{archiver/l1 → l1}/validate_trace.js +13 -9
  39. package/dest/modules/data_source_base.d.ts +84 -0
  40. package/dest/modules/data_source_base.d.ts.map +1 -0
  41. package/dest/modules/data_source_base.js +260 -0
  42. package/dest/modules/data_store_updater.d.ts +73 -0
  43. package/dest/modules/data_store_updater.d.ts.map +1 -0
  44. package/dest/modules/data_store_updater.js +302 -0
  45. package/dest/modules/instrumentation.d.ts +37 -0
  46. package/dest/modules/instrumentation.d.ts.map +1 -0
  47. package/dest/{archiver → modules}/instrumentation.js +17 -10
  48. package/dest/modules/l1_synchronizer.d.ts +75 -0
  49. package/dest/modules/l1_synchronizer.d.ts.map +1 -0
  50. package/dest/modules/l1_synchronizer.js +1112 -0
  51. package/dest/{archiver → modules}/validation.d.ts +1 -1
  52. package/dest/modules/validation.d.ts.map +1 -0
  53. package/dest/{archiver → modules}/validation.js +6 -0
  54. package/dest/store/block_store.d.ts +192 -0
  55. package/dest/store/block_store.d.ts.map +1 -0
  56. package/dest/{archiver/kv_archiver_store → store}/block_store.js +142 -47
  57. package/dest/store/contract_class_store.d.ts +18 -0
  58. package/dest/store/contract_class_store.d.ts.map +1 -0
  59. package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +12 -8
  60. package/dest/store/contract_instance_store.d.ts +24 -0
  61. package/dest/store/contract_instance_store.d.ts.map +1 -0
  62. package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +1 -1
  63. package/dest/store/kv_archiver_store.d.ts +340 -0
  64. package/dest/store/kv_archiver_store.d.ts.map +1 -0
  65. package/dest/store/kv_archiver_store.js +446 -0
  66. package/dest/store/log_store.d.ts +54 -0
  67. package/dest/store/log_store.d.ts.map +1 -0
  68. package/dest/{archiver/kv_archiver_store → store}/log_store.js +146 -91
  69. package/dest/{archiver/kv_archiver_store → store}/message_store.d.ts +1 -1
  70. package/dest/store/message_store.d.ts.map +1 -0
  71. package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
  72. package/dest/structs/data_retrieval.d.ts.map +1 -0
  73. package/dest/structs/inbox_message.d.ts +15 -0
  74. package/dest/structs/inbox_message.d.ts.map +1 -0
  75. package/dest/{archiver/structs → structs}/published.d.ts +1 -1
  76. package/dest/structs/published.d.ts.map +1 -0
  77. package/dest/test/fake_l1_state.d.ts +190 -0
  78. package/dest/test/fake_l1_state.d.ts.map +1 -0
  79. package/dest/test/fake_l1_state.js +383 -0
  80. package/dest/test/index.d.ts +2 -1
  81. package/dest/test/index.d.ts.map +1 -1
  82. package/dest/test/index.js +4 -1
  83. package/dest/test/mock_archiver.d.ts +2 -2
  84. package/dest/test/mock_archiver.d.ts.map +1 -1
  85. package/dest/test/mock_archiver.js +1 -2
  86. package/dest/test/mock_l2_block_source.d.ts +20 -17
  87. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  88. package/dest/test/mock_l2_block_source.js +108 -48
  89. package/dest/test/mock_structs.d.ts +78 -3
  90. package/dest/test/mock_structs.d.ts.map +1 -1
  91. package/dest/test/mock_structs.js +140 -7
  92. package/dest/test/noop_l1_archiver.d.ts +23 -0
  93. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  94. package/dest/test/noop_l1_archiver.js +68 -0
  95. package/package.json +16 -17
  96. package/src/archiver.ts +543 -0
  97. package/src/{archiver/config.ts → config.ts} +11 -0
  98. package/src/{archiver/errors.ts → errors.ts} +12 -0
  99. package/src/factory.ts +125 -11
  100. package/src/index.ts +10 -3
  101. package/src/interfaces.ts +9 -0
  102. package/src/{archiver/l1 → l1}/bin/retrieve-calldata.ts +16 -17
  103. package/src/{archiver/l1 → l1}/calldata_retriever.ts +1 -1
  104. package/src/{archiver/l1 → l1}/data_retrieval.ts +57 -74
  105. package/src/{archiver/l1 → l1}/validate_trace.ts +24 -6
  106. package/src/modules/data_source_base.ts +367 -0
  107. package/src/modules/data_store_updater.ts +423 -0
  108. package/src/{archiver → modules}/instrumentation.ts +17 -12
  109. package/src/modules/l1_synchronizer.ts +930 -0
  110. package/src/{archiver → modules}/validation.ts +5 -0
  111. package/src/{archiver/kv_archiver_store → store}/block_store.ts +179 -63
  112. package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +12 -8
  113. package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +1 -1
  114. package/src/{archiver/kv_archiver_store → store}/kv_archiver_store.ts +234 -37
  115. package/src/{archiver/kv_archiver_store → store}/log_store.ts +242 -121
  116. package/src/test/fake_l1_state.ts +599 -0
  117. package/src/test/index.ts +4 -0
  118. package/src/test/mock_archiver.ts +2 -2
  119. package/src/test/mock_l2_block_source.ts +114 -66
  120. package/src/test/mock_structs.ts +269 -8
  121. package/src/test/noop_l1_archiver.ts +109 -0
  122. package/dest/archiver/archiver.d.ts +0 -307
  123. package/dest/archiver/archiver.d.ts.map +0 -1
  124. package/dest/archiver/archiver.js +0 -2102
  125. package/dest/archiver/archiver_store.d.ts +0 -315
  126. package/dest/archiver/archiver_store.d.ts.map +0 -1
  127. package/dest/archiver/archiver_store.js +0 -4
  128. package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
  129. package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
  130. package/dest/archiver/archiver_store_test_suite.js +0 -2770
  131. package/dest/archiver/config.d.ts.map +0 -1
  132. package/dest/archiver/errors.d.ts +0 -36
  133. package/dest/archiver/errors.d.ts.map +0 -1
  134. package/dest/archiver/index.d.ts +0 -7
  135. package/dest/archiver/index.d.ts.map +0 -1
  136. package/dest/archiver/index.js +0 -4
  137. package/dest/archiver/instrumentation.d.ts +0 -37
  138. package/dest/archiver/instrumentation.d.ts.map +0 -1
  139. package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -164
  140. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
  141. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
  142. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
  143. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
  144. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
  145. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -159
  146. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
  147. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -316
  148. package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -45
  149. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
  150. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
  151. package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +0 -1
  152. package/dest/archiver/l1/calldata_retriever.d.ts.map +0 -1
  153. package/dest/archiver/l1/data_retrieval.d.ts +0 -90
  154. package/dest/archiver/l1/data_retrieval.d.ts.map +0 -1
  155. package/dest/archiver/l1/debug_tx.d.ts.map +0 -1
  156. package/dest/archiver/l1/spire_proposer.d.ts.map +0 -1
  157. package/dest/archiver/l1/trace_tx.d.ts.map +0 -1
  158. package/dest/archiver/l1/types.d.ts +0 -12
  159. package/dest/archiver/l1/types.d.ts.map +0 -1
  160. package/dest/archiver/l1/validate_trace.d.ts.map +0 -1
  161. package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
  162. package/dest/archiver/structs/inbox_message.d.ts +0 -15
  163. package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
  164. package/dest/archiver/structs/published.d.ts.map +0 -1
  165. package/dest/archiver/validation.d.ts.map +0 -1
  166. package/dest/rpc/index.d.ts +0 -9
  167. package/dest/rpc/index.d.ts.map +0 -1
  168. package/dest/rpc/index.js +0 -15
  169. package/src/archiver/archiver.ts +0 -2265
  170. package/src/archiver/archiver_store.ts +0 -380
  171. package/src/archiver/archiver_store_test_suite.ts +0 -2842
  172. package/src/archiver/index.ts +0 -6
  173. package/src/rpc/index.ts +0 -16
  174. /package/dest/{archiver/l1 → l1}/calldata_retriever.js +0 -0
  175. /package/dest/{archiver/l1 → l1}/debug_tx.js +0 -0
  176. /package/dest/{archiver/l1 → l1}/spire_proposer.js +0 -0
  177. /package/dest/{archiver/l1 → l1}/trace_tx.js +0 -0
  178. /package/dest/{archiver/l1 → l1}/types.js +0 -0
  179. /package/dest/{archiver/kv_archiver_store → store}/message_store.js +0 -0
  180. /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
  181. /package/dest/{archiver/structs → structs}/inbox_message.js +0 -0
  182. /package/dest/{archiver/structs → structs}/published.js +0 -0
  183. /package/src/{archiver/l1 → l1}/README.md +0 -0
  184. /package/src/{archiver/l1 → l1}/debug_tx.ts +0 -0
  185. /package/src/{archiver/l1 → l1}/spire_proposer.ts +0 -0
  186. /package/src/{archiver/l1 → l1}/trace_tx.ts +0 -0
  187. /package/src/{archiver/l1 → l1}/types.ts +0 -0
  188. /package/src/{archiver/kv_archiver_store → store}/message_store.ts +0 -0
  189. /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
  190. /package/src/{archiver/structs → structs}/inbox_message.ts +0 -0
  191. /package/src/{archiver/structs → structs}/published.ts +0 -0
@@ -1,5 +1,5 @@
1
1
  import type { ViemPublicDebugClient } from '@aztec/ethereum/types';
2
- import { createLogger } from '@aztec/foundation/log';
2
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
3
3
 
4
4
  import type { Hex } from 'viem';
5
5
  import type { ZodSchema } from 'zod';
@@ -7,8 +7,6 @@ import type { ZodSchema } from 'zod';
7
7
  import { callTraceSchema } from './debug_tx.js';
8
8
  import { traceTransactionResponseSchema } from './trace_tx.js';
9
9
 
10
- const logger = createLogger('aztec:archiver:validate_trace');
11
-
12
10
  /**
13
11
  * Helper function to test a trace method with validation
14
12
  *
@@ -17,6 +15,7 @@ const logger = createLogger('aztec:archiver:validate_trace');
17
15
  * @param schema - Zod schema to validate the response
18
16
  * @param method - Name of the RPC method ('debug_traceTransaction' or 'trace_transaction')
19
17
  * @param blockType - Type of block being tested ('recent' or 'old')
18
+ * @param logger - Logger instance
20
19
  * @returns true if the method works and validation passes, false otherwise
21
20
  */
22
21
  async function testTraceMethod(
@@ -25,6 +24,7 @@ async function testTraceMethod(
25
24
  schema: ZodSchema,
26
25
  method: 'debug_traceTransaction' | 'trace_transaction',
27
26
  blockType: string,
27
+ logger: Logger,
28
28
  ): Promise<boolean> {
29
29
  try {
30
30
  // Make request with appropriate params based on method name
@@ -59,9 +59,14 @@ export interface TraceAvailability {
59
59
  * Validates the availability of debug/trace methods on the Ethereum client.
60
60
  *
61
61
  * @param client - The Viem public debug client
62
+ * @param bindings - Optional logger bindings for context
62
63
  * @returns Object indicating which trace methods are available for recent and old blocks
63
64
  */
64
- export async function validateTraceAvailability(client: ViemPublicDebugClient): Promise<TraceAvailability> {
65
+ export async function validateTraceAvailability(
66
+ client: ViemPublicDebugClient,
67
+ bindings?: LoggerBindings,
68
+ ): Promise<TraceAvailability> {
69
+ const logger = createLogger('archiver:validate_trace', bindings);
65
70
  const result: TraceAvailability = {
66
71
  debugTraceRecent: false,
67
72
  traceTransactionRecent: false,
@@ -95,6 +100,7 @@ export async function validateTraceAvailability(client: ViemPublicDebugClient):
95
100
  callTraceSchema,
96
101
  'debug_traceTransaction',
97
102
  'recent',
103
+ logger,
98
104
  );
99
105
 
100
106
  // Test trace_transaction with recent block
@@ -104,6 +110,7 @@ export async function validateTraceAvailability(client: ViemPublicDebugClient):
104
110
  traceTransactionResponseSchema,
105
111
  'trace_transaction',
106
112
  'recent',
113
+ logger,
107
114
  );
108
115
 
109
116
  // Get a block from 512 blocks ago
@@ -132,7 +139,14 @@ export async function validateTraceAvailability(client: ViemPublicDebugClient):
132
139
  const oldTxHash = oldBlock.transactions[0] as Hex;
133
140
 
134
141
  // Test debug_traceTransaction with old block
135
- result.debugTraceOld = await testTraceMethod(client, oldTxHash, callTraceSchema, 'debug_traceTransaction', 'old');
142
+ result.debugTraceOld = await testTraceMethod(
143
+ client,
144
+ oldTxHash,
145
+ callTraceSchema,
146
+ 'debug_traceTransaction',
147
+ 'old',
148
+ logger,
149
+ );
136
150
 
137
151
  // Test trace_transaction with old block
138
152
  result.traceTransactionOld = await testTraceMethod(
@@ -141,6 +155,7 @@ export async function validateTraceAvailability(client: ViemPublicDebugClient):
141
155
  traceTransactionResponseSchema,
142
156
  'trace_transaction',
143
157
  'old',
158
+ logger,
144
159
  );
145
160
  } catch (error) {
146
161
  logger.warn(`Error validating debug_traceTransaction and trace_transaction availability: ${error}`);
@@ -159,15 +174,18 @@ function hasTxs(block: { transactions?: Hex[] }): boolean {
159
174
  *
160
175
  * @param client - The Viem public debug client
161
176
  * @param ethereumAllowNoDebugHosts - If false, throws an error when no trace methods are available
177
+ * @param bindings - Optional logger bindings for context
162
178
  * @throws Error if ethereumAllowNoDebugHosts is false and no trace methods are available
163
179
  */
164
180
  export async function validateAndLogTraceAvailability(
165
181
  client: ViemPublicDebugClient,
166
182
  ethereumAllowNoDebugHosts: boolean,
183
+ bindings?: LoggerBindings,
167
184
  ): Promise<void> {
185
+ const logger = createLogger('archiver:validate_trace', bindings);
168
186
  logger.debug('Validating trace/debug method availability...');
169
187
 
170
- const availability = await validateTraceAvailability(client);
188
+ const availability = await validateTraceAvailability(client, bindings);
171
189
 
172
190
  // Check if we have support for old blocks (either debug or trace)
173
191
  const hasOldBlockSupport = availability.debugTraceOld || availability.traceTransactionOld;
@@ -0,0 +1,367 @@
1
+ import { BlockNumber, CheckpointNumber, type EpochNumber, type SlotNumber } from '@aztec/foundation/branded-types';
2
+ import type { Fr } from '@aztec/foundation/curves/bn254';
3
+ import type { EthAddress } from '@aztec/foundation/eth-address';
4
+ import { isDefined } from '@aztec/foundation/types';
5
+ import type { FunctionSelector } from '@aztec/stdlib/abi';
6
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
7
+ import { type BlockHash, CheckpointedL2Block, CommitteeAttestation, L2Block, type L2Tips } from '@aztec/stdlib/block';
8
+ import { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
9
+ import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
10
+ import { type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
11
+ import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
12
+ import type { L2LogsSource } from '@aztec/stdlib/interfaces/server';
13
+ import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
14
+ import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
15
+ import type { CheckpointHeader } from '@aztec/stdlib/rollup';
16
+ import type { BlockHeader, IndexedTxEffect, TxHash, TxReceipt } from '@aztec/stdlib/tx';
17
+ import type { UInt64 } from '@aztec/stdlib/types';
18
+
19
+ import type { ArchiverDataSource } from '../interfaces.js';
20
+ import type { CheckpointData } from '../store/block_store.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.numBlocks - 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 async getL2Block(number: BlockNumber): Promise<L2Block | undefined> {
133
+ // If the number provided is -ve, then return the latest block.
134
+ if (number < 0) {
135
+ number = await this.store.getLatestBlockNumber();
136
+ }
137
+ if (number === 0) {
138
+ return undefined;
139
+ }
140
+ const publishedBlock = await this.store.getBlock(number);
141
+ return publishedBlock;
142
+ }
143
+
144
+ public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
145
+ return this.store.getTxEffect(txHash);
146
+ }
147
+
148
+ public getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
149
+ return this.store.getSettledTxReceipt(txHash);
150
+ }
151
+
152
+ public isPendingChainInvalid(): Promise<boolean> {
153
+ return this.getPendingChainValidationStatus().then(status => !status.valid);
154
+ }
155
+
156
+ public async getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
157
+ return (await this.store.getPendingChainValidationStatus()) ?? { valid: true };
158
+ }
159
+
160
+ public getPrivateLogsByTags(tags: SiloedTag[], page?: number): Promise<TxScopedL2Log[][]> {
161
+ return this.store.getPrivateLogsByTags(tags, page);
162
+ }
163
+
164
+ public getPublicLogsByTagsFromContract(
165
+ contractAddress: AztecAddress,
166
+ tags: Tag[],
167
+ page?: number,
168
+ ): Promise<TxScopedL2Log[][]> {
169
+ return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, page);
170
+ }
171
+
172
+ public getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
173
+ return this.store.getPublicLogs(filter);
174
+ }
175
+
176
+ public getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse> {
177
+ return this.store.getContractClassLogs(filter);
178
+ }
179
+
180
+ public getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
181
+ return this.store.getContractClass(id);
182
+ }
183
+
184
+ public getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
185
+ return this.store.getBytecodeCommitment(id);
186
+ }
187
+
188
+ public async getContract(
189
+ address: AztecAddress,
190
+ maybeTimestamp?: UInt64,
191
+ ): Promise<ContractInstanceWithAddress | undefined> {
192
+ let timestamp;
193
+ if (maybeTimestamp === undefined) {
194
+ const latestBlockHeader = await this.getBlockHeader('latest');
195
+ // If we get undefined block header, it means that the archiver has not yet synced any block so we default to 0.
196
+ timestamp = latestBlockHeader ? latestBlockHeader.globalVariables.timestamp : 0n;
197
+ } else {
198
+ timestamp = maybeTimestamp;
199
+ }
200
+
201
+ return this.store.getContractInstance(address, timestamp);
202
+ }
203
+
204
+ public getContractClassIds(): Promise<Fr[]> {
205
+ return this.store.getContractClassIds();
206
+ }
207
+
208
+ public getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
209
+ return this.store.getDebugFunctionName(address, selector);
210
+ }
211
+
212
+ public registerContractFunctionSignatures(signatures: string[]): Promise<void> {
213
+ return this.store.registerContractFunctionSignatures(signatures);
214
+ }
215
+
216
+ public getL1ToL2Messages(checkpointNumber: CheckpointNumber): Promise<Fr[]> {
217
+ return this.store.getL1ToL2Messages(checkpointNumber);
218
+ }
219
+
220
+ public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined> {
221
+ return this.store.getL1ToL2MessageIndex(l1ToL2Message);
222
+ }
223
+
224
+ public async getCheckpoints(checkpointNumber: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
225
+ const checkpoints = await this.store.getRangeOfCheckpoints(checkpointNumber, limit);
226
+ const blocks = (
227
+ await Promise.all(checkpoints.map(ch => this.store.getBlocksForCheckpoint(ch.checkpointNumber)))
228
+ ).filter(isDefined);
229
+
230
+ const fullCheckpoints: PublishedCheckpoint[] = [];
231
+ for (let i = 0; i < checkpoints.length; i++) {
232
+ const blocksForCheckpoint = blocks[i];
233
+ const checkpoint = checkpoints[i];
234
+ const fullCheckpoint = new Checkpoint(
235
+ checkpoint.archive,
236
+ checkpoint.header,
237
+ blocksForCheckpoint,
238
+ checkpoint.checkpointNumber,
239
+ );
240
+ const publishedCheckpoint = new PublishedCheckpoint(
241
+ fullCheckpoint,
242
+ checkpoint.l1,
243
+ checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
244
+ );
245
+ fullCheckpoints.push(publishedCheckpoint);
246
+ }
247
+ return fullCheckpoints;
248
+ }
249
+
250
+ public getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
251
+ return this.store.getBlocksForSlot(slotNumber);
252
+ }
253
+
254
+ public async getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]> {
255
+ if (!this.l1Constants) {
256
+ throw new Error('L1 constants not set');
257
+ }
258
+
259
+ const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
260
+ const blocks: CheckpointedL2Block[] = [];
261
+
262
+ // Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
263
+ // We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
264
+ let checkpoint = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
265
+ const slot = (b: CheckpointData) => b.header.slotNumber;
266
+ while (checkpoint && slot(checkpoint) >= start) {
267
+ if (slot(checkpoint) <= end) {
268
+ // push the blocks on backwards
269
+ const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
270
+ for (let i = endBlock; i >= checkpoint.startBlock; i--) {
271
+ const checkpointedBlock = await this.getCheckpointedBlock(BlockNumber(i));
272
+ if (checkpointedBlock) {
273
+ blocks.push(checkpointedBlock);
274
+ }
275
+ }
276
+ }
277
+ checkpoint = await this.store.getCheckpointData(CheckpointNumber(checkpoint.checkpointNumber - 1));
278
+ }
279
+
280
+ return blocks.reverse();
281
+ }
282
+
283
+ public async getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
284
+ if (!this.l1Constants) {
285
+ throw new Error('L1 constants not set');
286
+ }
287
+
288
+ const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
289
+ const blocks: BlockHeader[] = [];
290
+
291
+ // Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
292
+ // We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
293
+ let checkpoint = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
294
+ const slot = (b: CheckpointData) => b.header.slotNumber;
295
+ while (checkpoint && slot(checkpoint) >= start) {
296
+ if (slot(checkpoint) <= end) {
297
+ // push the blocks on backwards
298
+ const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
299
+ for (let i = endBlock; i >= checkpoint.startBlock; i--) {
300
+ const block = await this.getBlockHeader(BlockNumber(i));
301
+ if (block) {
302
+ blocks.push(block);
303
+ }
304
+ }
305
+ }
306
+ checkpoint = await this.store.getCheckpointData(CheckpointNumber(checkpoint.checkpointNumber - 1));
307
+ }
308
+ return blocks.reverse();
309
+ }
310
+
311
+ public async getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
312
+ if (!this.l1Constants) {
313
+ throw new Error('L1 constants not set');
314
+ }
315
+
316
+ const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
317
+ const checkpoints: Checkpoint[] = [];
318
+
319
+ // Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
320
+ // We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
321
+ let checkpointData = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
322
+ const slot = (b: CheckpointData) => b.header.slotNumber;
323
+ while (checkpointData && slot(checkpointData) >= start) {
324
+ if (slot(checkpointData) <= end) {
325
+ // push the checkpoints on backwards
326
+ const [checkpoint] = await this.getCheckpoints(checkpointData.checkpointNumber, 1);
327
+ checkpoints.push(checkpoint.checkpoint);
328
+ }
329
+ checkpointData = await this.store.getCheckpointData(CheckpointNumber(checkpointData.checkpointNumber - 1));
330
+ }
331
+
332
+ return checkpoints.reverse();
333
+ }
334
+
335
+ public async getBlock(number: BlockNumber): Promise<L2Block | undefined> {
336
+ // If the number provided is -ve, then return the latest block.
337
+ if (number < 0) {
338
+ number = await this.store.getLatestBlockNumber();
339
+ }
340
+ if (number === 0) {
341
+ return undefined;
342
+ }
343
+ return this.store.getBlock(number);
344
+ }
345
+
346
+ public getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
347
+ return this.store.getBlocks(from, limit);
348
+ }
349
+
350
+ public getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
351
+ return this.store.getCheckpointedBlockByHash(blockHash);
352
+ }
353
+
354
+ public getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
355
+ return this.store.getCheckpointedBlockByArchive(archive);
356
+ }
357
+
358
+ public async getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
359
+ const checkpointedBlock = await this.store.getCheckpointedBlockByHash(blockHash);
360
+ return checkpointedBlock?.block;
361
+ }
362
+
363
+ public async getL2BlockByArchive(archive: Fr): Promise<L2Block | undefined> {
364
+ const checkpointedBlock = await this.store.getCheckpointedBlockByArchive(archive);
365
+ return checkpointedBlock?.block;
366
+ }
367
+ }