@aztec/archiver 0.0.1-commit.4d3c002 → 0.0.1-commit.4d9804df

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 (124) hide show
  1. package/README.md +7 -5
  2. package/dest/archiver.d.ts +70 -15
  3. package/dest/archiver.d.ts.map +1 -1
  4. package/dest/archiver.js +274 -71
  5. package/dest/config.d.ts +7 -3
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +39 -16
  8. package/dest/errors.d.ts +35 -13
  9. package/dest/errors.d.ts.map +1 -1
  10. package/dest/errors.js +54 -16
  11. package/dest/factory.d.ts +11 -6
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +35 -21
  14. package/dest/index.d.ts +11 -3
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +10 -2
  17. package/dest/l1/calldata_retriever.d.ts +9 -1
  18. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  19. package/dest/l1/calldata_retriever.js +20 -10
  20. package/dest/l1/data_retrieval.d.ts +24 -10
  21. package/dest/l1/data_retrieval.d.ts.map +1 -1
  22. package/dest/l1/data_retrieval.js +13 -19
  23. package/dest/l1/trace_tx.d.ts +12 -66
  24. package/dest/l1/trace_tx.d.ts.map +1 -1
  25. package/dest/l1/validate_historical_logs.d.ts +23 -0
  26. package/dest/l1/validate_historical_logs.d.ts.map +1 -0
  27. package/dest/l1/validate_historical_logs.js +108 -0
  28. package/dest/modules/contract_data_source_adapter.d.ts +25 -0
  29. package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
  30. package/dest/modules/contract_data_source_adapter.js +32 -0
  31. package/dest/modules/data_source_base.d.ts +71 -50
  32. package/dest/modules/data_source_base.d.ts.map +1 -1
  33. package/dest/modules/data_source_base.js +250 -150
  34. package/dest/modules/data_store_updater.d.ts +28 -9
  35. package/dest/modules/data_store_updater.d.ts.map +1 -1
  36. package/dest/modules/data_store_updater.js +121 -61
  37. package/dest/modules/instrumentation.d.ts +15 -2
  38. package/dest/modules/instrumentation.d.ts.map +1 -1
  39. package/dest/modules/instrumentation.js +48 -9
  40. package/dest/modules/l1_synchronizer.d.ts +11 -7
  41. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  42. package/dest/modules/l1_synchronizer.js +347 -118
  43. package/dest/modules/outbox_trees_resolver.d.ts +62 -0
  44. package/dest/modules/outbox_trees_resolver.d.ts.map +1 -0
  45. package/dest/modules/outbox_trees_resolver.js +162 -0
  46. package/dest/modules/validation.d.ts +30 -7
  47. package/dest/modules/validation.d.ts.map +1 -1
  48. package/dest/modules/validation.js +33 -15
  49. package/dest/store/block_store.d.ts +167 -94
  50. package/dest/store/block_store.d.ts.map +1 -1
  51. package/dest/store/block_store.js +524 -260
  52. package/dest/store/contract_class_store.d.ts +17 -3
  53. package/dest/store/contract_class_store.d.ts.map +1 -1
  54. package/dest/store/contract_class_store.js +36 -2
  55. package/dest/store/contract_instance_store.d.ts +28 -1
  56. package/dest/store/contract_instance_store.d.ts.map +1 -1
  57. package/dest/store/contract_instance_store.js +49 -1
  58. package/dest/store/data_stores.d.ts +68 -0
  59. package/dest/store/data_stores.d.ts.map +1 -0
  60. package/dest/store/data_stores.js +54 -0
  61. package/dest/store/function_names_cache.d.ts +17 -0
  62. package/dest/store/function_names_cache.d.ts.map +1 -0
  63. package/dest/store/function_names_cache.js +30 -0
  64. package/dest/store/l2_tips_cache.d.ts +13 -8
  65. package/dest/store/l2_tips_cache.d.ts.map +1 -1
  66. package/dest/store/l2_tips_cache.js +13 -96
  67. package/dest/store/log_store.d.ts +42 -40
  68. package/dest/store/log_store.d.ts.map +1 -1
  69. package/dest/store/log_store.js +257 -480
  70. package/dest/store/log_store_codec.d.ts +78 -0
  71. package/dest/store/log_store_codec.d.ts.map +1 -0
  72. package/dest/store/log_store_codec.js +110 -0
  73. package/dest/store/message_store.d.ts +9 -3
  74. package/dest/store/message_store.d.ts.map +1 -1
  75. package/dest/store/message_store.js +31 -1
  76. package/dest/test/fake_l1_state.d.ts +7 -3
  77. package/dest/test/fake_l1_state.d.ts.map +1 -1
  78. package/dest/test/fake_l1_state.js +45 -18
  79. package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
  80. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  81. package/dest/test/mock_l1_to_l2_message_source.js +1 -2
  82. package/dest/test/mock_l2_block_source.d.ts +47 -54
  83. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  84. package/dest/test/mock_l2_block_source.js +229 -205
  85. package/dest/test/mock_structs.d.ts +1 -1
  86. package/dest/test/mock_structs.d.ts.map +1 -1
  87. package/dest/test/mock_structs.js +2 -2
  88. package/dest/test/noop_l1_archiver.d.ts +14 -6
  89. package/dest/test/noop_l1_archiver.d.ts.map +1 -1
  90. package/dest/test/noop_l1_archiver.js +26 -10
  91. package/package.json +14 -14
  92. package/src/archiver.ts +355 -77
  93. package/src/config.ts +43 -20
  94. package/src/errors.ts +80 -23
  95. package/src/factory.ts +46 -19
  96. package/src/index.ts +18 -2
  97. package/src/l1/calldata_retriever.ts +27 -10
  98. package/src/l1/data_retrieval.ts +38 -36
  99. package/src/l1/validate_historical_logs.ts +140 -0
  100. package/src/modules/contract_data_source_adapter.ts +46 -0
  101. package/src/modules/data_source_base.ts +319 -200
  102. package/src/modules/data_store_updater.ts +146 -64
  103. package/src/modules/instrumentation.ts +43 -10
  104. package/src/modules/l1_synchronizer.ts +499 -136
  105. package/src/modules/outbox_trees_resolver.ts +199 -0
  106. package/src/modules/validation.ts +78 -21
  107. package/src/store/block_store.ts +627 -321
  108. package/src/store/contract_class_store.ts +47 -3
  109. package/src/store/contract_instance_store.ts +61 -1
  110. package/src/store/data_stores.ts +104 -0
  111. package/src/store/function_names_cache.ts +37 -0
  112. package/src/store/l2_tips_cache.ts +16 -109
  113. package/src/store/log_store.ts +296 -652
  114. package/src/store/log_store_codec.ts +143 -0
  115. package/src/store/message_store.ts +35 -2
  116. package/src/test/fake_l1_state.ts +50 -27
  117. package/src/test/mock_l1_to_l2_message_source.ts +0 -1
  118. package/src/test/mock_l2_block_source.ts +276 -258
  119. package/src/test/mock_structs.ts +5 -2
  120. package/src/test/noop_l1_archiver.ts +54 -11
  121. package/dest/store/kv_archiver_store.d.ts +0 -377
  122. package/dest/store/kv_archiver_store.d.ts.map +0 -1
  123. package/dest/store/kv_archiver_store.js +0 -494
  124. package/src/store/kv_archiver_store.ts +0 -713
@@ -12,6 +12,8 @@ import type {
12
12
  InboxContract,
13
13
  MessageSentLog,
14
14
  RollupContract,
15
+ ViemCommitteeAttestations,
16
+ ViemHeader,
15
17
  } from '@aztec/ethereum/contracts';
16
18
  import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
17
19
  import { asyncPool } from '@aztec/foundation/async-pool';
@@ -35,18 +37,33 @@ import type { DataRetrieval } from '../structs/data_retrieval.js';
35
37
  import type { InboxMessage } from '../structs/inbox_message.js';
36
38
  import { CalldataRetriever } from './calldata_retriever.js';
37
39
 
38
- export type RetrievedCheckpoint = {
40
+ type RetrievedCheckpointBase = {
39
41
  checkpointNumber: CheckpointNumber;
40
42
  archiveRoot: Fr;
41
43
  feeAssetPriceModifier: bigint;
42
44
  header: CheckpointHeader;
43
- checkpointBlobData: CheckpointBlobData;
44
45
  l1: L1PublishedData;
45
46
  chainId: Fr;
46
47
  version: Fr;
47
48
  attestations: CommitteeAttestation[];
48
49
  };
49
50
 
51
+ /** Checkpoint data as retrieved from L1 calldata and blob data. */
52
+ export type RetrievedCheckpoint = RetrievedCheckpointBase & { checkpointBlobData: CheckpointBlobData };
53
+
54
+ /** Checkpoint data retrieved from L1 calldata only, without blob data. */
55
+ export type RetrievedCheckpointFromCalldata = RetrievedCheckpointBase & {
56
+ /** Versioned blob hashes from the checkpoint proposed event. */
57
+ blobHashes: Buffer[];
58
+ /** Parent beacon block root from the L1 block, used for blob fetching. */
59
+ parentBeaconBlockRoot: string | undefined;
60
+ /**
61
+ * The exact packed `CommitteeAttestations` tuple from the propose calldata, carried verbatim so that
62
+ * attestation validation can attach byte-faithful invalidation evidence to a negative result.
63
+ */
64
+ verbatimAttestations: ViemCommitteeAttestations;
65
+ };
66
+
50
67
  export async function retrievedToPublishedCheckpoint({
51
68
  checkpointNumber,
52
69
  archiveRoot,
@@ -137,31 +154,27 @@ export async function retrievedToPublishedCheckpoint({
137
154
  }
138
155
 
139
156
  /**
140
- * Fetches new checkpoints.
157
+ * Fetches checkpoint calldata from the rollup contract without fetching blob data.
158
+ * Returns RetrievedCheckpointFromCalldata objects that preserve the information needed for deferred blob fetching.
141
159
  * @param rollup - The rollup contract wrapper.
142
160
  * @param publicClient - The viem public client to use for transaction retrieval.
143
161
  * @param debugClient - The viem debug client to use for trace/debug RPC methods (optional).
144
- * @param blobClient - The blob client client for fetching blob data.
145
162
  * @param searchStartBlock - The block number to use for starting the search.
146
163
  * @param searchEndBlock - The highest block number that we should search up to.
147
- * @param contractAddresses - The contract addresses (governanceProposerAddress, slashFactoryAddress, slashingProposerAddress).
148
164
  * @param instrumentation - The archiver instrumentation instance.
149
165
  * @param logger - The logger instance.
150
- * @param isHistoricalSync - Whether this is a historical sync.
151
- * @returns An array of retrieved checkpoints.
166
+ * @returns An array of calldata-only checkpoints.
152
167
  */
153
- export async function retrieveCheckpointsFromRollup(
168
+ export async function retrieveCheckpointCalldataFromRollup(
154
169
  rollup: RollupContract,
155
170
  publicClient: ViemPublicClient,
156
171
  debugClient: ViemPublicDebugClient,
157
- blobClient: BlobClientInterface,
158
172
  searchStartBlock: bigint,
159
173
  searchEndBlock: bigint,
160
174
  instrumentation: ArchiverInstrumentation,
161
175
  logger: Logger = createLogger('archiver'),
162
- isHistoricalSync: boolean = false,
163
- ): Promise<RetrievedCheckpoint[]> {
164
- const retrievedCheckpoints: RetrievedCheckpoint[] = [];
176
+ ): Promise<RetrievedCheckpointFromCalldata[]> {
177
+ const retrievedCheckpoints: RetrievedCheckpointFromCalldata[] = [];
165
178
 
166
179
  let rollupConstants: { chainId: Fr; version: Fr; targetCommitteeSize: number } | undefined;
167
180
 
@@ -197,46 +210,39 @@ export async function retrieveCheckpointsFromRollup(
197
210
  rollup,
198
211
  publicClient,
199
212
  debugClient,
200
- blobClient,
201
213
  checkpointProposedLogs,
202
214
  rollupConstants,
203
215
  instrumentation,
204
216
  logger,
205
- isHistoricalSync,
206
217
  );
207
218
  retrievedCheckpoints.push(...newCheckpoints);
208
219
  searchStartBlock = lastLog.l1BlockNumber + 1n;
209
220
  } while (searchStartBlock <= searchEndBlock);
210
221
 
211
- // The asyncPool from processCheckpointProposedLogs will not necessarily return the checkpoints in order, so we sort them before returning.
212
222
  return retrievedCheckpoints.sort((a, b) => Number(a.l1.blockNumber - b.l1.blockNumber));
213
223
  }
214
224
 
215
225
  /**
216
- * Processes newly received CheckpointProposed logs.
226
+ * Processes CheckpointProposed logs, fetching only calldata (no blobs).
217
227
  * @param rollup - The rollup contract wrapper.
218
228
  * @param publicClient - The viem public client to use for transaction retrieval.
219
229
  * @param debugClient - The viem debug client to use for trace/debug RPC methods (optional).
220
- * @param blobClient - The blob client client for fetching blob data.
221
230
  * @param logs - CheckpointProposed logs.
222
231
  * @param rollupConstants - The rollup constants (chainId, version, targetCommitteeSize).
223
232
  * @param instrumentation - The archiver instrumentation instance.
224
233
  * @param logger - The logger instance.
225
- * @param isHistoricalSync - Whether this is a historical sync.
226
- * @returns An array of retrieved checkpoints.
234
+ * @returns An array of calldata-only checkpoints.
227
235
  */
228
236
  async function processCheckpointProposedLogs(
229
237
  rollup: RollupContract,
230
238
  publicClient: ViemPublicClient,
231
239
  debugClient: ViemPublicDebugClient,
232
- blobClient: BlobClientInterface,
233
240
  logs: CheckpointProposedLog[],
234
241
  { chainId, version, targetCommitteeSize }: { chainId: Fr; version: Fr; targetCommitteeSize: number },
235
242
  instrumentation: ArchiverInstrumentation,
236
243
  logger: Logger,
237
- isHistoricalSync: boolean,
238
- ): Promise<RetrievedCheckpoint[]> {
239
- const retrievedCheckpoints: RetrievedCheckpoint[] = [];
244
+ ): Promise<RetrievedCheckpointFromCalldata[]> {
245
+ const retrievedCheckpoints: RetrievedCheckpointFromCalldata[] = [];
240
246
  const calldataRetriever = new CalldataRetriever(
241
247
  publicClient,
242
248
  debugClient,
@@ -252,7 +258,6 @@ async function processCheckpointProposedLogs(
252
258
  const archiveFromChain = await rollup.archiveAt(checkpointNumber);
253
259
  const blobHashes = log.args.versionedBlobHashes;
254
260
 
255
- // The value from the event and contract will match only if the checkpoint is in the chain.
256
261
  if (archive.equals(archiveFromChain)) {
257
262
  const expectedHashes = {
258
263
  attestationsHash: log.args.attestationsHash.toString() as Hex,
@@ -268,19 +273,16 @@ async function processCheckpointProposedLogs(
268
273
  const { timestamp, parentBeaconBlockRoot } = await getL1Block(publicClient, log.l1BlockNumber);
269
274
  const l1 = new L1PublishedData(log.l1BlockNumber, timestamp, log.l1BlockHash.toString());
270
275
 
271
- const checkpointBlobData = await getCheckpointBlobDataFromBlobs(
272
- blobClient,
273
- checkpoint.blockHash,
276
+ retrievedCheckpoints.push({
277
+ ...checkpoint,
278
+ l1,
279
+ chainId,
280
+ version,
274
281
  blobHashes,
275
- checkpointNumber,
276
- logger,
277
- isHistoricalSync,
278
282
  parentBeaconBlockRoot,
279
- timestamp,
280
- );
283
+ });
281
284
 
282
- retrievedCheckpoints.push({ ...checkpoint, checkpointBlobData, l1, chainId, version });
283
- logger.trace(`Retrieved checkpoint ${checkpointNumber} from L1 tx ${log.l1TransactionHash}`, {
285
+ logger.trace(`Retrieved checkpoint calldata ${checkpointNumber} from L1 tx ${log.l1TransactionHash}`, {
284
286
  l1BlockNumber: log.l1BlockNumber,
285
287
  checkpointNumber,
286
288
  archive: archive.toString(),
@@ -346,7 +348,7 @@ export async function retrieveL1ToL2Message(
346
348
  inbox: InboxContract,
347
349
  message: InboxMessage,
348
350
  ): Promise<InboxMessage | undefined> {
349
- const log = await inbox.getMessageSentEventByHash(message.leaf.toString(), message.l1BlockHash.toString());
351
+ const log = await inbox.getMessageSentEventByHash(message.leaf.toString(), message.l1BlockNumber);
350
352
  return log && mapLogInboxMessage(log);
351
353
  }
352
354
 
@@ -465,7 +467,7 @@ export async function getProofFromSubmitProofTx(
465
467
  start: bigint;
466
468
  end: bigint;
467
469
  args: EpochProofPublicInputArgs;
468
- fees: readonly Hex[];
470
+ headers: readonly ViemHeader[];
469
471
  proof: Hex;
470
472
  },
471
473
  ];
@@ -0,0 +1,140 @@
1
+ import { getPublicClient, getRpcUrlsFromClient } from '@aztec/ethereum/client';
2
+ import { RollupContract } from '@aztec/ethereum/contracts';
3
+ import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
4
+ import type { ViemPublicClient } from '@aztec/ethereum/types';
5
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
6
+
7
+ /** Subset of L1 contract addresses whose historical logs the Aztec node relies on. */
8
+ export type HistoricalLogsContractAddresses = Pick<
9
+ L1ContractAddresses,
10
+ 'rollupAddress' | 'inboxAddress' | 'registryAddress' | 'governanceProposerAddress'
11
+ >;
12
+
13
+ /** Result of probing a single RPC URL. */
14
+ type ProbeResult = { ok: true } | { ok: false; reason: string; clientVersion: string | undefined };
15
+
16
+ /**
17
+ * Validates that every configured L1 RPC URL returns historical logs for the Rollup contract.
18
+ *
19
+ * Some RPC providers prune old logs, which would cause L1 syncing to silently fail. To detect this,
20
+ * we query for the `OwnershipTransferred` event which every Rollup emits in its constructor (via
21
+ * Ownable) on the block it was deployed (`l1StartBlock`). The `client` is typically a viem fallback
22
+ * transport over several user-configured RPC URLs — checking only the first URL would miss a bad
23
+ * secondary, so we probe each URL independently. The first URL that fails aborts startup, unless
24
+ * the operator has explicitly opted out.
25
+ *
26
+ * @param client - The L1 public client built from the user-configured RPC URLs.
27
+ * @param addresses - The subset of L1 contract addresses we rely on for historical log retrieval.
28
+ * @param skipCheck - If true, log warnings instead of throwing.
29
+ * @param bindings - Optional logger bindings for context.
30
+ * @throws Error if any URL fails the probe and skipCheck is false.
31
+ */
32
+ export async function validateAndLogHistoricalLogsAvailability(
33
+ client: ViemPublicClient,
34
+ addresses: HistoricalLogsContractAddresses,
35
+ skipCheck: boolean,
36
+ bindings?: LoggerBindings,
37
+ ): Promise<void> {
38
+ const logger = createLogger('archiver:validate_historical_logs', bindings);
39
+ logger.debug('Validating historical log availability on L1 RPCs');
40
+
41
+ const urls = getRpcUrlsFromClient(client);
42
+ if (urls.length === 0) {
43
+ logger.warn('Could not determine L1 RPC URLs from the public client; skipping historical logs check.');
44
+ return;
45
+ }
46
+
47
+ const chainId = client.chain?.id;
48
+ if (chainId === undefined) {
49
+ logger.warn('Could not determine L1 chain ID from the public client; skipping historical logs check.');
50
+ return;
51
+ }
52
+
53
+ for (const url of urls) {
54
+ const probeClient = getPublicClient({ l1RpcUrls: [url], l1ChainId: chainId });
55
+ const rollup = new RollupContract(probeClient, addresses.rollupAddress.toString());
56
+ const result = await probeRpcUrl(rollup, probeClient, logger);
57
+
58
+ if (result.ok) {
59
+ logger.debug(`L1 RPC ${url} returned historical OwnershipTransferred log for the Rollup contract.`);
60
+ continue;
61
+ }
62
+
63
+ const errorMessage = buildErrorMessage(url, result, addresses);
64
+ if (skipCheck) {
65
+ logger.warn(`${errorMessage}\nContinuing because ARCHIVER_SKIP_HISTORICAL_LOGS_CHECK is true.`);
66
+ continue;
67
+ }
68
+
69
+ logger.error(errorMessage);
70
+ throw new Error(errorMessage);
71
+ }
72
+ }
73
+
74
+ /** Runs the OwnershipTransferred probe against a single RPC and queries its client version. */
75
+ async function probeRpcUrl(rollup: RollupContract, client: ViemPublicClient, logger: Logger): Promise<ProbeResult> {
76
+ let queryError: unknown;
77
+ try {
78
+ const logs = await rollup.getOwnershipTransferredEventsAtDeploy();
79
+ if (logs.length > 0) {
80
+ return { ok: true };
81
+ }
82
+ } catch (err) {
83
+ queryError = err;
84
+ }
85
+
86
+ const clientVersion = await getClientVersion(client, logger);
87
+
88
+ let reason: string;
89
+ if (queryError instanceof Error) {
90
+ reason = `Query for historical logs failed: ${queryError.message}`;
91
+ } else if (queryError !== undefined) {
92
+ reason = 'Query for historical logs failed with a non-Error value.';
93
+ } else {
94
+ reason = 'No OwnershipTransferred event was returned by the L1 RPC for the Rollup deploy block.';
95
+ }
96
+ return { ok: false, reason, clientVersion };
97
+ }
98
+
99
+ /** Builds the operator-facing error message for a failing RPC URL. */
100
+ function buildErrorMessage(
101
+ url: string,
102
+ result: Extract<ProbeResult, { ok: false }>,
103
+ addresses: HistoricalLogsContractAddresses,
104
+ ): string {
105
+ return [
106
+ `L1 RPC at ${url} does not return historical logs for the Rollup contract. ${result.reason}`,
107
+ `This likely means this Ethereum RPC node prunes old logs, which would cause the archiver ` +
108
+ `to silently miss data during L1 sync.`,
109
+ result.clientVersion
110
+ ? `Detected L1 client version for ${url}: ${result.clientVersion}.`
111
+ : `Could not determine L1 client version for ${url}.`,
112
+ `The following L1 contract addresses must have their historical logs retained by the RPC node:`,
113
+ ` - Rollup: ${addresses.rollupAddress.toString()}`,
114
+ ` - Inbox: ${addresses.inboxAddress.toString()}`,
115
+ ` - Registry: ${addresses.registryAddress.toString()}`,
116
+ ` - GovernanceProposer: ${addresses.governanceProposerAddress.toString()}`,
117
+ isReth(result.clientVersion)
118
+ ? `To retain logs for these contracts, configure reth with a ` +
119
+ `prune.segments.receipts_log_filter entry for each address above ` +
120
+ `so reth does not prune their receipts/logs. See https://reth.rs/run/pruning.html for details.`
121
+ : `Point this RPC endpoint at a node that retains full log history for the addresses above.`,
122
+ `Set ARCHIVER_SKIP_HISTORICAL_LOGS_CHECK=true to bypass this check at your own risk.`,
123
+ ].join('\n');
124
+ }
125
+
126
+ /** Queries `web3_clientVersion` on the L1 RPC. Returns undefined if the call fails or returns a non-string. */
127
+ async function getClientVersion(client: ViemPublicClient, logger: Logger): Promise<string | undefined> {
128
+ try {
129
+ const result = await client.request({ method: 'web3_clientVersion' });
130
+ return typeof result === 'string' ? result : undefined;
131
+ } catch (err) {
132
+ logger.debug(`Failed to query web3_clientVersion: ${err instanceof Error ? err.message : err}`);
133
+ return undefined;
134
+ }
135
+ }
136
+
137
+ /** Heuristic check for reth based on the web3_clientVersion string (reth returns e.g. "reth/v1.0.0-..."). */
138
+ function isReth(clientVersion: string | undefined): boolean {
139
+ return !!clientVersion && /reth/i.test(clientVersion);
140
+ }
@@ -0,0 +1,46 @@
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import type { Fr } from '@aztec/foundation/curves/bn254';
3
+ import type { FunctionSelector } from '@aztec/stdlib/abi';
4
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
+ import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
6
+ import type { UInt64 } from '@aztec/stdlib/types';
7
+
8
+ import type { ArchiverDataStores } from '../store/data_stores.js';
9
+
10
+ /**
11
+ * Thin {@link ContractDataSource} adapter over {@link ArchiverDataStores}.
12
+ *
13
+ * Used by contexts (e.g. offline epoch re-prover tools) that need a ContractDataSource
14
+ * but do not need a full archiver instance.
15
+ */
16
+ export class ArchiverContractDataSourceAdapter implements ContractDataSource {
17
+ constructor(private readonly stores: ArchiverDataStores) {}
18
+
19
+ public getBlockNumber(): Promise<BlockNumber> {
20
+ return this.stores.blocks.getLatestL2BlockNumber();
21
+ }
22
+
23
+ public getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
24
+ return this.stores.contractClasses.getContractClass(id);
25
+ }
26
+
27
+ public getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
28
+ return this.stores.contractClasses.getBytecodeCommitment(id);
29
+ }
30
+
31
+ public getContract(address: AztecAddress, timestamp: UInt64): Promise<ContractInstanceWithAddress | undefined> {
32
+ return this.stores.contractInstances.getContractInstance(address, timestamp);
33
+ }
34
+
35
+ public getContractClassIds(): Promise<Fr[]> {
36
+ return this.stores.contractClasses.getContractClassIds();
37
+ }
38
+
39
+ public getDebugFunctionName(_address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
40
+ return Promise.resolve(this.stores.functionNames.get(selector));
41
+ }
42
+
43
+ public registerContractFunctionSignatures(signatures: string[]): Promise<void> {
44
+ return this.stores.functionNames.register(signatures);
45
+ }
46
+ }