@aztec/archiver 0.0.1-commit.f295ac2 → 0.0.1-commit.f504929

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 (95) hide show
  1. package/README.md +9 -0
  2. package/dest/archiver.d.ts +10 -6
  3. package/dest/archiver.d.ts.map +1 -1
  4. package/dest/archiver.js +50 -111
  5. package/dest/errors.d.ts +6 -1
  6. package/dest/errors.d.ts.map +1 -1
  7. package/dest/errors.js +8 -0
  8. package/dest/factory.d.ts +5 -2
  9. package/dest/factory.d.ts.map +1 -1
  10. package/dest/factory.js +16 -13
  11. package/dest/index.d.ts +2 -1
  12. package/dest/index.d.ts.map +1 -1
  13. package/dest/index.js +1 -0
  14. package/dest/l1/bin/retrieve-calldata.js +35 -32
  15. package/dest/l1/calldata_retriever.d.ts +73 -50
  16. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  17. package/dest/l1/calldata_retriever.js +190 -259
  18. package/dest/l1/data_retrieval.d.ts +9 -9
  19. package/dest/l1/data_retrieval.d.ts.map +1 -1
  20. package/dest/l1/data_retrieval.js +24 -22
  21. package/dest/l1/spire_proposer.d.ts +5 -5
  22. package/dest/l1/spire_proposer.d.ts.map +1 -1
  23. package/dest/l1/spire_proposer.js +9 -17
  24. package/dest/l1/validate_trace.d.ts +6 -3
  25. package/dest/l1/validate_trace.d.ts.map +1 -1
  26. package/dest/l1/validate_trace.js +13 -9
  27. package/dest/modules/data_source_base.d.ts +25 -21
  28. package/dest/modules/data_source_base.d.ts.map +1 -1
  29. package/dest/modules/data_source_base.js +48 -123
  30. package/dest/modules/data_store_updater.d.ts +31 -20
  31. package/dest/modules/data_store_updater.d.ts.map +1 -1
  32. package/dest/modules/data_store_updater.js +79 -60
  33. package/dest/modules/instrumentation.d.ts +17 -4
  34. package/dest/modules/instrumentation.d.ts.map +1 -1
  35. package/dest/modules/instrumentation.js +36 -12
  36. package/dest/modules/l1_synchronizer.d.ts +4 -8
  37. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  38. package/dest/modules/l1_synchronizer.js +23 -19
  39. package/dest/store/block_store.d.ts +50 -32
  40. package/dest/store/block_store.d.ts.map +1 -1
  41. package/dest/store/block_store.js +147 -54
  42. package/dest/store/contract_class_store.d.ts +1 -1
  43. package/dest/store/contract_class_store.d.ts.map +1 -1
  44. package/dest/store/contract_class_store.js +11 -7
  45. package/dest/store/kv_archiver_store.d.ts +52 -29
  46. package/dest/store/kv_archiver_store.d.ts.map +1 -1
  47. package/dest/store/kv_archiver_store.js +49 -23
  48. package/dest/store/l2_tips_cache.d.ts +19 -0
  49. package/dest/store/l2_tips_cache.d.ts.map +1 -0
  50. package/dest/store/l2_tips_cache.js +89 -0
  51. package/dest/store/log_store.d.ts +17 -8
  52. package/dest/store/log_store.d.ts.map +1 -1
  53. package/dest/store/log_store.js +77 -43
  54. package/dest/test/fake_l1_state.d.ts +9 -4
  55. package/dest/test/fake_l1_state.d.ts.map +1 -1
  56. package/dest/test/fake_l1_state.js +56 -18
  57. package/dest/test/index.js +3 -1
  58. package/dest/test/mock_archiver.d.ts +1 -1
  59. package/dest/test/mock_archiver.d.ts.map +1 -1
  60. package/dest/test/mock_archiver.js +3 -2
  61. package/dest/test/mock_l2_block_source.d.ts +36 -21
  62. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  63. package/dest/test/mock_l2_block_source.js +151 -109
  64. package/dest/test/mock_structs.d.ts +3 -2
  65. package/dest/test/mock_structs.d.ts.map +1 -1
  66. package/dest/test/mock_structs.js +11 -9
  67. package/dest/test/noop_l1_archiver.d.ts +23 -0
  68. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  69. package/dest/test/noop_l1_archiver.js +68 -0
  70. package/package.json +14 -13
  71. package/src/archiver.ts +71 -136
  72. package/src/errors.ts +12 -0
  73. package/src/factory.ts +30 -14
  74. package/src/index.ts +1 -0
  75. package/src/l1/README.md +25 -68
  76. package/src/l1/bin/retrieve-calldata.ts +45 -33
  77. package/src/l1/calldata_retriever.ts +249 -379
  78. package/src/l1/data_retrieval.ts +27 -29
  79. package/src/l1/spire_proposer.ts +7 -15
  80. package/src/l1/validate_trace.ts +24 -6
  81. package/src/modules/data_source_base.ts +81 -167
  82. package/src/modules/data_store_updater.ts +92 -63
  83. package/src/modules/instrumentation.ts +46 -14
  84. package/src/modules/l1_synchronizer.ts +26 -24
  85. package/src/store/block_store.ts +188 -92
  86. package/src/store/contract_class_store.ts +11 -7
  87. package/src/store/kv_archiver_store.ts +85 -36
  88. package/src/store/l2_tips_cache.ts +89 -0
  89. package/src/store/log_store.ts +134 -49
  90. package/src/test/fake_l1_state.ts +77 -19
  91. package/src/test/index.ts +3 -0
  92. package/src/test/mock_archiver.ts +3 -2
  93. package/src/test/mock_l2_block_source.ts +196 -126
  94. package/src/test/mock_structs.ts +26 -10
  95. package/src/test/noop_l1_archiver.ts +109 -0
@@ -20,7 +20,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
20
20
  import { EthAddress } from '@aztec/foundation/eth-address';
21
21
  import { type Logger, createLogger } from '@aztec/foundation/log';
22
22
  import { RollupAbi } from '@aztec/l1-artifacts';
23
- import { Body, CommitteeAttestation, L2BlockNew } from '@aztec/stdlib/block';
23
+ import { Body, CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
24
24
  import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
25
25
  import { Proof } from '@aztec/stdlib/proofs';
26
26
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
@@ -38,6 +38,7 @@ import { CalldataRetriever } from './calldata_retriever.js';
38
38
  export type RetrievedCheckpoint = {
39
39
  checkpointNumber: CheckpointNumber;
40
40
  archiveRoot: Fr;
41
+ feeAssetPriceModifier: bigint;
41
42
  header: CheckpointHeader;
42
43
  checkpointBlobData: CheckpointBlobData;
43
44
  l1: L1PublishedData;
@@ -49,6 +50,7 @@ export type RetrievedCheckpoint = {
49
50
  export async function retrievedToPublishedCheckpoint({
50
51
  checkpointNumber,
51
52
  archiveRoot,
53
+ feeAssetPriceModifier,
52
54
  header: checkpointHeader,
53
55
  checkpointBlobData,
54
56
  l1,
@@ -69,7 +71,7 @@ export async function retrievedToPublishedCheckpoint({
69
71
  const l1toL2MessageTreeRoot = blocksBlobData[0].l1ToL2MessageRoot!;
70
72
 
71
73
  const spongeBlob = SpongeBlob.init();
72
- const l2Blocks: L2BlockNew[] = [];
74
+ const l2Blocks: L2Block[] = [];
73
75
  for (let i = 0; i < blocksBlobData.length; i++) {
74
76
  const blockBlobData = blocksBlobData[i];
75
77
  const { blockEndMarker, blockEndStateField, lastArchiveRoot, noteHashRoot, nullifierRoot, publicDataRoot } =
@@ -100,7 +102,7 @@ export async function retrievedToPublishedCheckpoint({
100
102
  }),
101
103
  });
102
104
 
103
- const body = Body.fromTxBlobData(checkpointBlobData.blocks[0].txs);
105
+ const body = Body.fromTxBlobData(blockBlobData.txs);
104
106
 
105
107
  const blobFields = encodeBlockBlobData(blockBlobData);
106
108
  await spongeBlob.absorb(blobFields);
@@ -119,7 +121,7 @@ export async function retrievedToPublishedCheckpoint({
119
121
 
120
122
  const newArchive = new AppendOnlyTreeSnapshot(newArchiveRoots[i], l2BlockNumber + 1);
121
123
 
122
- l2Blocks.push(new L2BlockNew(newArchive, header, body, checkpointNumber, IndexWithinCheckpoint(i)));
124
+ l2Blocks.push(new L2Block(newArchive, header, body, checkpointNumber, IndexWithinCheckpoint(i)));
123
125
  }
124
126
 
125
127
  const lastBlock = l2Blocks.at(-1)!;
@@ -128,6 +130,7 @@ export async function retrievedToPublishedCheckpoint({
128
130
  header: checkpointHeader,
129
131
  blocks: l2Blocks,
130
132
  number: checkpointNumber,
133
+ feeAssetPriceModifier: feeAssetPriceModifier,
131
134
  });
132
135
 
133
136
  return PublishedCheckpoint.from({ checkpoint, l1, attestations });
@@ -154,11 +157,6 @@ export async function retrieveCheckpointsFromRollup(
154
157
  blobClient: BlobClientInterface,
155
158
  searchStartBlock: bigint,
156
159
  searchEndBlock: bigint,
157
- contractAddresses: {
158
- governanceProposerAddress: EthAddress;
159
- slashFactoryAddress?: EthAddress;
160
- slashingProposerAddress: EthAddress;
161
- },
162
160
  instrumentation: ArchiverInstrumentation,
163
161
  logger: Logger = createLogger('archiver'),
164
162
  isHistoricalSync: boolean = false,
@@ -202,7 +200,6 @@ export async function retrieveCheckpointsFromRollup(
202
200
  blobClient,
203
201
  checkpointProposedLogs,
204
202
  rollupConstants,
205
- contractAddresses,
206
203
  instrumentation,
207
204
  logger,
208
205
  isHistoricalSync,
@@ -223,7 +220,6 @@ export async function retrieveCheckpointsFromRollup(
223
220
  * @param blobClient - The blob client client for fetching blob data.
224
221
  * @param logs - CheckpointProposed logs.
225
222
  * @param rollupConstants - The rollup constants (chainId, version, targetCommitteeSize).
226
- * @param contractAddresses - The contract addresses (governanceProposerAddress, slashFactoryAddress, slashingProposerAddress).
227
223
  * @param instrumentation - The archiver instrumentation instance.
228
224
  * @param logger - The logger instance.
229
225
  * @param isHistoricalSync - Whether this is a historical sync.
@@ -236,11 +232,6 @@ async function processCheckpointProposedLogs(
236
232
  blobClient: BlobClientInterface,
237
233
  logs: CheckpointProposedLog[],
238
234
  { chainId, version, targetCommitteeSize }: { chainId: Fr; version: Fr; targetCommitteeSize: number },
239
- contractAddresses: {
240
- governanceProposerAddress: EthAddress;
241
- slashFactoryAddress?: EthAddress;
242
- slashingProposerAddress: EthAddress;
243
- },
244
235
  instrumentation: ArchiverInstrumentation,
245
236
  logger: Logger,
246
237
  isHistoricalSync: boolean,
@@ -252,7 +243,7 @@ async function processCheckpointProposedLogs(
252
243
  targetCommitteeSize,
253
244
  instrumentation,
254
245
  logger,
255
- { ...contractAddresses, rollupAddress: EthAddress.fromString(rollup.address) },
246
+ EthAddress.fromString(rollup.address),
256
247
  );
257
248
 
258
249
  await asyncPool(10, logs, async log => {
@@ -263,10 +254,9 @@ async function processCheckpointProposedLogs(
263
254
 
264
255
  // The value from the event and contract will match only if the checkpoint is in the chain.
265
256
  if (archive.equals(archiveFromChain)) {
266
- // Build expected hashes object (fields may be undefined for backwards compatibility with older events)
267
257
  const expectedHashes = {
268
- attestationsHash: log.args.attestationsHash?.toString(),
269
- payloadDigest: log.args.payloadDigest?.toString(),
258
+ attestationsHash: log.args.attestationsHash.toString() as Hex,
259
+ payloadDigest: log.args.payloadDigest.toString() as Hex,
270
260
  };
271
261
 
272
262
  const checkpoint = await calldataRetriever.getCheckpointFromRollupTx(
@@ -275,6 +265,9 @@ async function processCheckpointProposedLogs(
275
265
  checkpointNumber,
276
266
  expectedHashes,
277
267
  );
268
+ const { timestamp, parentBeaconBlockRoot } = await getL1Block(publicClient, log.l1BlockNumber);
269
+ const l1 = new L1PublishedData(log.l1BlockNumber, timestamp, log.l1BlockHash.toString());
270
+
278
271
  const checkpointBlobData = await getCheckpointBlobDataFromBlobs(
279
272
  blobClient,
280
273
  checkpoint.blockHash,
@@ -282,12 +275,8 @@ async function processCheckpointProposedLogs(
282
275
  checkpointNumber,
283
276
  logger,
284
277
  isHistoricalSync,
285
- );
286
-
287
- const l1 = new L1PublishedData(
288
- log.l1BlockNumber,
289
- await getL1BlockTime(publicClient, log.l1BlockNumber),
290
- log.l1BlockHash.toString(),
278
+ parentBeaconBlockRoot,
279
+ timestamp,
291
280
  );
292
281
 
293
282
  retrievedCheckpoints.push({ ...checkpoint, checkpointBlobData, l1, chainId, version });
@@ -308,9 +297,12 @@ async function processCheckpointProposedLogs(
308
297
  return retrievedCheckpoints;
309
298
  }
310
299
 
311
- export async function getL1BlockTime(publicClient: ViemPublicClient, blockNumber: bigint): Promise<bigint> {
300
+ export async function getL1Block(
301
+ publicClient: ViemPublicClient,
302
+ blockNumber: bigint,
303
+ ): Promise<{ timestamp: bigint; parentBeaconBlockRoot: string | undefined }> {
312
304
  const block = await publicClient.getBlock({ blockNumber, includeTransactions: false });
313
- return block.timestamp;
305
+ return { timestamp: block.timestamp, parentBeaconBlockRoot: block.parentBeaconBlockRoot };
314
306
  }
315
307
 
316
308
  export async function getCheckpointBlobDataFromBlobs(
@@ -320,8 +312,14 @@ export async function getCheckpointBlobDataFromBlobs(
320
312
  checkpointNumber: CheckpointNumber,
321
313
  logger: Logger,
322
314
  isHistoricalSync: boolean,
315
+ parentBeaconBlockRoot?: string,
316
+ l1BlockTimestamp?: bigint,
323
317
  ): Promise<CheckpointBlobData> {
324
- const blobBodies = await blobClient.getBlobSidecar(blockHash, blobHashes, { isHistoricalSync });
318
+ const blobBodies = await blobClient.getBlobSidecar(blockHash, blobHashes, {
319
+ isHistoricalSync,
320
+ parentBeaconBlockRoot,
321
+ l1BlockTimestamp,
322
+ });
325
323
  if (blobBodies.length === 0) {
326
324
  throw new NoBlobBodiesFoundError(checkpointNumber);
327
325
  }
@@ -87,17 +87,17 @@ export async function verifyProxyImplementation(
87
87
  /**
88
88
  * Attempts to decode transaction as a Spire Proposer Multicall.
89
89
  * Spire Proposer is a proxy contract that wraps multiple calls.
90
- * Returns the target address and calldata of the wrapped call if validation succeeds and there is a single call.
90
+ * Returns all wrapped calls if validation succeeds (caller handles hash matching to find the propose call).
91
91
  * @param tx - The transaction to decode
92
92
  * @param publicClient - The viem public client for proxy verification
93
93
  * @param logger - Logger instance
94
- * @returns Object with 'to' and 'data' of the wrapped call, or undefined if validation fails
94
+ * @returns Array of wrapped calls with 'to' and 'data', or undefined if not a valid Spire Proposer tx
95
95
  */
96
- export async function getCallFromSpireProposer(
96
+ export async function getCallsFromSpireProposer(
97
97
  tx: Transaction,
98
98
  publicClient: { getStorageAt: (params: { address: Hex; slot: Hex }) => Promise<Hex | undefined> },
99
99
  logger: Logger,
100
- ): Promise<{ to: Hex; data: Hex } | undefined> {
100
+ ): Promise<{ to: Hex; data: Hex }[] | undefined> {
101
101
  const txHash = tx.hash;
102
102
 
103
103
  try {
@@ -141,17 +141,9 @@ export async function getCallFromSpireProposer(
141
141
 
142
142
  const [calls] = spireArgs;
143
143
 
144
- // Validate exactly ONE call (see ./README.md for rationale)
145
- if (calls.length !== 1) {
146
- logger.warn(`Spire Proposer multicall must contain exactly one call (got ${calls.length})`, { txHash });
147
- return undefined;
148
- }
149
-
150
- const call = calls[0];
151
-
152
- // Successfully extracted the single wrapped call
153
- logger.trace(`Decoded Spire Proposer with single call to ${call.target}`, { txHash });
154
- return { to: call.target, data: call.data };
144
+ // Return all wrapped calls (hash matching in the caller determines which is the propose call)
145
+ logger.trace(`Decoded Spire Proposer with ${calls.length} call(s)`, { txHash });
146
+ return calls.map(call => ({ to: call.target, data: call.data }));
155
147
  } catch (err) {
156
148
  // Any decoding error triggers fallback to trace
157
149
  logger.warn(`Failed to decode Spire Proposer: ${err}`, { txHash });
@@ -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;
@@ -1,11 +1,12 @@
1
+ import { range } from '@aztec/foundation/array';
1
2
  import { BlockNumber, CheckpointNumber, type EpochNumber, type SlotNumber } from '@aztec/foundation/branded-types';
2
3
  import type { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import type { EthAddress } from '@aztec/foundation/eth-address';
4
5
  import { isDefined } from '@aztec/foundation/types';
5
6
  import type { FunctionSelector } from '@aztec/stdlib/abi';
6
7
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
7
- import { CheckpointedL2Block, CommitteeAttestation, L2BlockNew, type L2Tips } from '@aztec/stdlib/block';
8
- import { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
8
+ import { type BlockData, type BlockHash, CheckpointedL2Block, L2Block, type L2Tips } from '@aztec/stdlib/block';
9
+ import { Checkpoint, type CheckpointData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
9
10
  import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
10
11
  import { type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
11
12
  import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
@@ -17,7 +18,6 @@ import type { BlockHeader, IndexedTxEffect, TxHash, TxReceipt } from '@aztec/std
17
18
  import type { UInt64 } from '@aztec/stdlib/types';
18
19
 
19
20
  import type { ArchiverDataSource } from '../interfaces.js';
20
- import type { CheckpointData } from '../store/block_store.js';
21
21
  import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
22
22
  import type { ValidateCheckpointResult } from './validation.js';
23
23
 
@@ -87,10 +87,14 @@ export abstract class ArchiverDataSourceBase
87
87
  return this.store.getCheckpointedBlock(number);
88
88
  }
89
89
 
90
- public getCheckpointedBlockNumber(): Promise<BlockNumber> {
90
+ public getCheckpointedL2BlockNumber(): Promise<BlockNumber> {
91
91
  return this.store.getCheckpointedL2BlockNumber();
92
92
  }
93
93
 
94
+ public getFinalizedL2BlockNumber(): Promise<BlockNumber> {
95
+ return this.store.getFinalizedL2BlockNumber();
96
+ }
97
+
94
98
  public async getCheckpointHeader(number: CheckpointNumber | 'latest'): Promise<CheckpointHeader | undefined> {
95
99
  if (number === 'latest') {
96
100
  number = await this.store.getSynchedCheckpointNumber();
@@ -110,24 +114,14 @@ export abstract class ArchiverDataSourceBase
110
114
  if (!checkpointData) {
111
115
  return undefined;
112
116
  }
113
- return BlockNumber(checkpointData.startBlock + checkpointData.numBlocks - 1);
117
+ return BlockNumber(checkpointData.startBlock + checkpointData.blockCount - 1);
114
118
  }
115
119
 
116
- public async getCheckpointedBlocks(
117
- from: BlockNumber,
118
- limit: number,
119
- proven?: boolean,
120
- ): Promise<CheckpointedL2Block[]> {
121
- const blocks = await this.store.getCheckpointedBlocks(from, limit);
122
-
123
- if (proven === true) {
124
- const provenBlockNumber = await this.store.getProvenBlockNumber();
125
- return blocks.filter(b => b.block.number <= provenBlockNumber);
126
- }
127
- return blocks;
120
+ public getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
121
+ return this.store.getCheckpointedBlocks(from, limit);
128
122
  }
129
123
 
130
- public getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
124
+ public getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
131
125
  return this.store.getBlockHeaderByHash(blockHash);
132
126
  }
133
127
 
@@ -135,7 +129,15 @@ export abstract class ArchiverDataSourceBase
135
129
  return this.store.getBlockHeaderByArchive(archive);
136
130
  }
137
131
 
138
- public async getL2BlockNew(number: BlockNumber): Promise<L2BlockNew | undefined> {
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> {
139
141
  // If the number provided is -ve, then return the latest block.
140
142
  if (number < 0) {
141
143
  number = await this.store.getLatestBlockNumber();
@@ -163,22 +165,16 @@ export abstract class ArchiverDataSourceBase
163
165
  return (await this.store.getPendingChainValidationStatus()) ?? { valid: true };
164
166
  }
165
167
 
166
- public async getL2BlocksNew(from: BlockNumber, limit: number, proven?: boolean): Promise<L2BlockNew[]> {
167
- const blocks = await this.store.getBlocks(from, limit);
168
-
169
- if (proven === true) {
170
- const provenBlockNumber = await this.store.getProvenBlockNumber();
171
- return blocks.filter(b => b.number <= provenBlockNumber);
172
- }
173
- return blocks;
174
- }
175
-
176
- public getPrivateLogsByTags(tags: SiloedTag[]): Promise<TxScopedL2Log[][]> {
177
- return this.store.getPrivateLogsByTags(tags);
168
+ public getPrivateLogsByTags(tags: SiloedTag[], page?: number): Promise<TxScopedL2Log[][]> {
169
+ return this.store.getPrivateLogsByTags(tags, page);
178
170
  }
179
171
 
180
- public getPublicLogsByTagsFromContract(contractAddress: AztecAddress, tags: Tag[]): Promise<TxScopedL2Log[][]> {
181
- return this.store.getPublicLogsByTagsFromContract(contractAddress, tags);
172
+ public getPublicLogsByTagsFromContract(
173
+ contractAddress: AztecAddress,
174
+ tags: Tag[],
175
+ page?: number,
176
+ ): Promise<TxScopedL2Log[][]> {
177
+ return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, page);
182
178
  }
183
179
 
184
180
  public getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
@@ -233,147 +229,71 @@ export abstract class ArchiverDataSourceBase
233
229
  return this.store.getL1ToL2MessageIndex(l1ToL2Message);
234
230
  }
235
231
 
236
- public async getPublishedCheckpoints(
237
- checkpointNumber: CheckpointNumber,
238
- limit: number,
239
- ): Promise<PublishedCheckpoint[]> {
232
+ public async getCheckpoints(checkpointNumber: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
240
233
  const checkpoints = await this.store.getRangeOfCheckpoints(checkpointNumber, limit);
241
- const blocks = (
242
- await Promise.all(checkpoints.map(ch => this.store.getBlocksForCheckpoint(ch.checkpointNumber)))
243
- ).filter(isDefined);
244
-
245
- const fullCheckpoints: PublishedCheckpoint[] = [];
246
- for (let i = 0; i < checkpoints.length; i++) {
247
- const blocksForCheckpoint = blocks[i];
248
- const checkpoint = checkpoints[i];
249
- const fullCheckpoint = new Checkpoint(
250
- checkpoint.archive,
251
- checkpoint.header,
252
- blocksForCheckpoint,
253
- checkpoint.checkpointNumber,
254
- );
255
- const publishedCheckpoint = new PublishedCheckpoint(
256
- fullCheckpoint,
257
- checkpoint.l1,
258
- checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
259
- );
260
- fullCheckpoints.push(publishedCheckpoint);
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`);
261
241
  }
262
- return fullCheckpoints;
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);
263
249
  }
264
250
 
265
- public getBlocksForSlot(slotNumber: SlotNumber): Promise<L2BlockNew[]> {
251
+ public getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
266
252
  return this.store.getBlocksForSlot(slotNumber);
267
253
  }
268
254
 
269
- public async getBlocksForEpoch(epochNumber: EpochNumber): Promise<L2BlockNew[]> {
270
- if (!this.l1Constants) {
271
- throw new Error('L1 constants not set');
272
- }
273
-
274
- const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
275
- const blocks: L2BlockNew[] = [];
276
-
277
- // Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
278
- // We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
279
- let checkpoint = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
280
- const slot = (b: CheckpointData) => b.header.slotNumber;
281
- while (checkpoint && slot(checkpoint) >= start) {
282
- if (slot(checkpoint) <= end) {
283
- // push the blocks on backwards
284
- const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
285
- for (let i = endBlock; i >= checkpoint.startBlock; i--) {
286
- const block = await this.getBlock(BlockNumber(i));
287
- if (block) {
288
- blocks.push(block);
289
- }
290
- }
291
- }
292
- checkpoint = await this.store.getCheckpointData(CheckpointNumber(checkpoint.checkpointNumber - 1));
293
- }
294
-
295
- return blocks.reverse();
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);
296
265
  }
297
266
 
298
- public async getBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
299
- if (!this.l1Constants) {
300
- throw new Error('L1 constants not set');
301
- }
302
-
303
- const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
304
- const blocks: BlockHeader[] = [];
305
-
306
- // Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
307
- // We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
308
- let checkpoint = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
309
- const slot = (b: CheckpointData) => b.header.slotNumber;
310
- while (checkpoint && slot(checkpoint) >= start) {
311
- if (slot(checkpoint) <= end) {
312
- // push the blocks on backwards
313
- const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
314
- for (let i = endBlock; i >= checkpoint.startBlock; i--) {
315
- const block = await this.getBlockHeader(BlockNumber(i));
316
- if (block) {
317
- blocks.push(block);
318
- }
319
- }
320
- }
321
- checkpoint = await this.store.getCheckpointData(CheckpointNumber(checkpoint.checkpointNumber - 1));
322
- }
323
- return blocks.reverse();
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);
324
277
  }
325
278
 
326
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[]> {
327
288
  if (!this.l1Constants) {
328
289
  throw new Error('L1 constants not set');
329
290
  }
330
291
 
331
292
  const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
332
- const checkpoints: Checkpoint[] = [];
333
-
334
- // Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
335
- // We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
336
- let checkpointData = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
337
- const slot = (b: CheckpointData) => b.header.slotNumber;
338
- while (checkpointData && slot(checkpointData) >= start) {
339
- if (slot(checkpointData) <= end) {
340
- // push the checkpoints on backwards
341
- const [checkpoint] = await this.getPublishedCheckpoints(checkpointData.checkpointNumber, 1);
342
- checkpoints.push(checkpoint.checkpoint);
343
- }
344
- checkpointData = await this.store.getCheckpointData(CheckpointNumber(checkpointData.checkpointNumber - 1));
345
- }
346
-
347
- return checkpoints.reverse();
348
- }
349
-
350
- public async getPublishedBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<CheckpointedL2Block[]> {
351
- const checkpoints = await this.store.getRangeOfCheckpoints(CheckpointNumber(from), limit);
352
- const provenCheckpointNumber = await this.store.getProvenCheckpointNumber();
353
- const blocks = (
354
- await Promise.all(checkpoints.map(ch => this.store.getBlocksForCheckpoint(ch.checkpointNumber)))
355
- ).filter(isDefined);
356
-
357
- const publishedBlocks: CheckpointedL2Block[] = [];
358
- for (let i = 0; i < checkpoints.length; i++) {
359
- const blockForCheckpoint = blocks[i][0];
360
- const checkpoint = checkpoints[i];
361
- if (checkpoint.checkpointNumber > provenCheckpointNumber && proven === true) {
362
- // this checkpoint isn't proven and we only want proven
363
- continue;
364
- }
365
- const publishedBlock = new CheckpointedL2Block(
366
- checkpoint.checkpointNumber,
367
- blockForCheckpoint,
368
- checkpoint.l1,
369
- checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
370
- );
371
- publishedBlocks.push(publishedBlock);
372
- }
373
- return publishedBlocks;
293
+ return this.store.getCheckpointDataForSlotRange(start, end);
374
294
  }
375
295
 
376
- public async getBlock(number: BlockNumber): Promise<L2BlockNew | undefined> {
296
+ public async getBlock(number: BlockNumber): Promise<L2Block | undefined> {
377
297
  // If the number provided is -ve, then return the latest block.
378
298
  if (number < 0) {
379
299
  number = await this.store.getLatestBlockNumber();
@@ -384,30 +304,24 @@ export abstract class ArchiverDataSourceBase
384
304
  return this.store.getBlock(number);
385
305
  }
386
306
 
387
- public async getBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<L2BlockNew[]> {
388
- const blocks = await this.store.getBlocks(from, limit);
389
-
390
- if (proven === true) {
391
- const provenBlockNumber = await this.store.getProvenBlockNumber();
392
- return blocks.filter(b => b.number <= provenBlockNumber);
393
- }
394
- return blocks;
307
+ public getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
308
+ return this.store.getBlocks(from, limit);
395
309
  }
396
310
 
397
- public getPublishedBlockByHash(blockHash: Fr): Promise<CheckpointedL2Block | undefined> {
311
+ public getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
398
312
  return this.store.getCheckpointedBlockByHash(blockHash);
399
313
  }
400
314
 
401
- public getPublishedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
315
+ public getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
402
316
  return this.store.getCheckpointedBlockByArchive(archive);
403
317
  }
404
318
 
405
- public async getL2BlockNewByHash(blockHash: Fr): Promise<L2BlockNew | undefined> {
319
+ public async getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
406
320
  const checkpointedBlock = await this.store.getCheckpointedBlockByHash(blockHash);
407
321
  return checkpointedBlock?.block;
408
322
  }
409
323
 
410
- public async getL2BlockNewByArchive(archive: Fr): Promise<L2BlockNew | undefined> {
324
+ public async getL2BlockByArchive(archive: Fr): Promise<L2Block | undefined> {
411
325
  const checkpointedBlock = await this.store.getCheckpointedBlockByArchive(archive);
412
326
  return checkpointedBlock?.block;
413
327
  }