@aztec/archiver 0.0.1-commit.5de5ca79e → 0.0.1-commit.6201a7b05

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 (99) hide show
  1. package/README.md +12 -6
  2. package/dest/archiver.d.ts +16 -7
  3. package/dest/archiver.d.ts.map +1 -1
  4. package/dest/archiver.js +104 -48
  5. package/dest/config.d.ts +3 -1
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +14 -3
  8. package/dest/errors.d.ts +41 -2
  9. package/dest/errors.d.ts.map +1 -1
  10. package/dest/errors.js +62 -1
  11. package/dest/factory.d.ts +2 -2
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +9 -7
  14. package/dest/index.d.ts +3 -2
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +2 -1
  17. package/dest/l1/calldata_retriever.d.ts +2 -1
  18. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  19. package/dest/l1/calldata_retriever.js +11 -5
  20. package/dest/l1/data_retrieval.d.ts +19 -10
  21. package/dest/l1/data_retrieval.d.ts.map +1 -1
  22. package/dest/l1/data_retrieval.js +25 -32
  23. package/dest/l1/validate_historical_logs.d.ts +23 -0
  24. package/dest/l1/validate_historical_logs.d.ts.map +1 -0
  25. package/dest/l1/validate_historical_logs.js +108 -0
  26. package/dest/modules/data_source_base.d.ts +8 -2
  27. package/dest/modules/data_source_base.d.ts.map +1 -1
  28. package/dest/modules/data_source_base.js +19 -1
  29. package/dest/modules/data_store_updater.d.ts +15 -10
  30. package/dest/modules/data_store_updater.d.ts.map +1 -1
  31. package/dest/modules/data_store_updater.js +71 -68
  32. package/dest/modules/instrumentation.d.ts +7 -2
  33. package/dest/modules/instrumentation.d.ts.map +1 -1
  34. package/dest/modules/instrumentation.js +22 -6
  35. package/dest/modules/l1_synchronizer.d.ts +7 -2
  36. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  37. package/dest/modules/l1_synchronizer.js +261 -143
  38. package/dest/modules/validation.d.ts +4 -3
  39. package/dest/modules/validation.d.ts.map +1 -1
  40. package/dest/modules/validation.js +6 -6
  41. package/dest/store/block_store.d.ts +72 -5
  42. package/dest/store/block_store.d.ts.map +1 -1
  43. package/dest/store/block_store.js +341 -66
  44. package/dest/store/contract_class_store.d.ts +2 -3
  45. package/dest/store/contract_class_store.d.ts.map +1 -1
  46. package/dest/store/contract_class_store.js +7 -67
  47. package/dest/store/contract_instance_store.d.ts +1 -1
  48. package/dest/store/contract_instance_store.d.ts.map +1 -1
  49. package/dest/store/contract_instance_store.js +6 -2
  50. package/dest/store/kv_archiver_store.d.ts +51 -17
  51. package/dest/store/kv_archiver_store.d.ts.map +1 -1
  52. package/dest/store/kv_archiver_store.js +60 -16
  53. package/dest/store/l2_tips_cache.d.ts +2 -1
  54. package/dest/store/l2_tips_cache.d.ts.map +1 -1
  55. package/dest/store/l2_tips_cache.js +27 -7
  56. package/dest/store/log_store.d.ts +1 -1
  57. package/dest/store/log_store.d.ts.map +1 -1
  58. package/dest/store/log_store.js +2 -4
  59. package/dest/store/message_store.d.ts +3 -3
  60. package/dest/store/message_store.d.ts.map +1 -1
  61. package/dest/store/message_store.js +9 -10
  62. package/dest/test/fake_l1_state.d.ts +15 -3
  63. package/dest/test/fake_l1_state.d.ts.map +1 -1
  64. package/dest/test/fake_l1_state.js +80 -18
  65. package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
  66. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  67. package/dest/test/mock_l1_to_l2_message_source.js +2 -1
  68. package/dest/test/mock_l2_block_source.d.ts +16 -2
  69. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  70. package/dest/test/mock_l2_block_source.js +50 -3
  71. package/dest/test/noop_l1_archiver.d.ts +1 -1
  72. package/dest/test/noop_l1_archiver.d.ts.map +1 -1
  73. package/dest/test/noop_l1_archiver.js +4 -2
  74. package/package.json +13 -13
  75. package/src/archiver.ts +126 -46
  76. package/src/config.ts +15 -1
  77. package/src/errors.ts +97 -2
  78. package/src/factory.ts +13 -7
  79. package/src/index.ts +2 -1
  80. package/src/l1/calldata_retriever.ts +17 -5
  81. package/src/l1/data_retrieval.ts +36 -45
  82. package/src/l1/validate_historical_logs.ts +140 -0
  83. package/src/modules/data_source_base.ts +32 -1
  84. package/src/modules/data_store_updater.ts +98 -97
  85. package/src/modules/instrumentation.ts +27 -7
  86. package/src/modules/l1_synchronizer.ts +328 -169
  87. package/src/modules/validation.ts +10 -9
  88. package/src/store/block_store.ts +419 -76
  89. package/src/store/contract_class_store.ts +8 -106
  90. package/src/store/contract_instance_store.ts +8 -5
  91. package/src/store/kv_archiver_store.ts +100 -32
  92. package/src/store/l2_tips_cache.ts +58 -13
  93. package/src/store/log_store.ts +2 -5
  94. package/src/store/message_store.ts +10 -12
  95. package/src/structs/inbox_message.ts +1 -1
  96. package/src/test/fake_l1_state.ts +99 -27
  97. package/src/test/mock_l1_to_l2_message_source.ts +1 -0
  98. package/src/test/mock_l2_block_source.ts +58 -2
  99. package/src/test/noop_l1_archiver.ts +3 -1
package/src/errors.ts CHANGED
@@ -1,14 +1,17 @@
1
+ import type { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
1
2
  import type { Fr } from '@aztec/foundation/schemas';
2
3
 
3
4
  export class NoBlobBodiesFoundError extends Error {
4
5
  constructor(l2BlockNum: number) {
5
6
  super(`No blob bodies found for block ${l2BlockNum}`);
7
+ this.name = 'NoBlobBodiesFoundError';
6
8
  }
7
9
  }
8
10
 
9
11
  export class BlockNumberNotSequentialError extends Error {
10
12
  constructor(newBlockNumber: number, previous: number | undefined) {
11
13
  super(`Cannot insert new block ${newBlockNumber} given previous block number is ${previous ?? 'undefined'}`);
14
+ this.name = 'BlockNumberNotSequentialError';
12
15
  }
13
16
  }
14
17
 
@@ -22,14 +25,29 @@ export class InitialCheckpointNumberNotSequentialError extends Error {
22
25
  previousCheckpointNumber ?? 'undefined'
23
26
  }`,
24
27
  );
28
+ this.name = 'InitialCheckpointNumberNotSequentialError';
29
+ }
30
+ }
31
+
32
+ export class BlockCheckpointNumberNotSequentialError extends Error {
33
+ constructor(
34
+ blockNumber: BlockNumber,
35
+ blockCheckpointNumber: CheckpointNumber,
36
+ previous: CheckpointNumber | undefined,
37
+ ) {
38
+ super(
39
+ `Cannot insert new block ${blockNumber} for checkpoint ${blockCheckpointNumber} given previous checkpoint number is ${previous ?? 'undefined'}`,
40
+ );
41
+ this.name = 'BlockCheckpointNumberNotSequentialError';
25
42
  }
26
43
  }
27
44
 
28
45
  export class CheckpointNumberNotSequentialError extends Error {
29
- constructor(newCheckpointNumber: number, previous: number | undefined) {
46
+ constructor(newCheckpointNumber: CheckpointNumber, previous: CheckpointNumber | undefined) {
30
47
  super(
31
- `Cannot insert new checkpoint ${newCheckpointNumber} given previous checkpoint number in batch is ${previous ?? 'undefined'}`,
48
+ `Cannot insert new checkpoint ${newCheckpointNumber} given previous checkpoint number is ${previous ?? 'undefined'}`,
32
49
  );
50
+ this.name = 'CheckpointNumberNotSequentialError';
33
51
  }
34
52
  }
35
53
 
@@ -38,6 +56,7 @@ export class BlockIndexNotSequentialError extends Error {
38
56
  super(
39
57
  `Cannot insert new block at checkpoint index ${newBlockIndex} given previous block index is ${previousBlockIndex ?? 'undefined'}`,
40
58
  );
59
+ this.name = 'BlockIndexNotSequentialError';
41
60
  }
42
61
  }
43
62
 
@@ -51,18 +70,21 @@ export class BlockArchiveNotConsistentError extends Error {
51
70
  super(
52
71
  `Cannot insert new block number ${newBlockNumber} with archive ${newBlockArchive.toString()} previous block number is ${previousBlockNumber ?? 'undefined'}, previous archive is ${previousBlockArchive?.toString() ?? 'undefined'}`,
53
72
  );
73
+ this.name = 'BlockArchiveNotConsistentError';
54
74
  }
55
75
  }
56
76
 
57
77
  export class CheckpointNotFoundError extends Error {
58
78
  constructor(checkpointNumber: number) {
59
79
  super(`Failed to find expected checkpoint number ${checkpointNumber}`);
80
+ this.name = 'CheckpointNotFoundError';
60
81
  }
61
82
  }
62
83
 
63
84
  export class BlockNotFoundError extends Error {
64
85
  constructor(blockNumber: number) {
65
86
  super(`Failed to find expected block number ${blockNumber}`);
87
+ this.name = 'BlockNotFoundError';
66
88
  }
67
89
  }
68
90
 
@@ -104,6 +126,79 @@ export class L1ToL2MessagesNotReadyError extends Error {
104
126
  }
105
127
  }
106
128
 
129
+ /** Thrown when a proposed checkpoint number is stale (already processed). */
130
+ export class ProposedCheckpointStaleError extends Error {
131
+ constructor(
132
+ public readonly proposedCheckpointNumber: number,
133
+ public readonly currentProposedNumber: number,
134
+ ) {
135
+ super(`Stale proposed checkpoint ${proposedCheckpointNumber}: current proposed is ${currentProposedNumber}`);
136
+ this.name = 'ProposedCheckpointStaleError';
137
+ }
138
+ }
139
+
140
+ /** Thrown when a proposed checkpoint number is not the expected latestTip + 1. */
141
+ export class ProposedCheckpointNotSequentialError extends Error {
142
+ constructor(
143
+ public readonly proposedCheckpointNumber: number,
144
+ public readonly latestTipNumber: number,
145
+ ) {
146
+ super(
147
+ `Proposed checkpoint ${proposedCheckpointNumber} is not sequential: expected ${latestTipNumber + 1} (latest tip + 1, where tip is highest of confirmed or pending)`,
148
+ );
149
+ this.name = 'ProposedCheckpointNotSequentialError';
150
+ }
151
+ }
152
+
153
+ /** Thrown when a proposed checkpoint or block L2 slot has already expired on L1. */
154
+ export class BlockOrCheckpointSlotExpiredError extends Error {
155
+ constructor(
156
+ public readonly slot: number,
157
+ public readonly nextSlotStart: bigint,
158
+ public readonly l1TimestampSynced: bigint | undefined,
159
+ ) {
160
+ super(
161
+ `Checkpoint or block for slot ${slot} is expired: L1 synced to ${l1TimestampSynced} which is past the next slot start ${nextSlotStart}. ` +
162
+ `If the checkpoint still lands via a late L1 tx, the archiver will pick it up via normal L1-sync (not the pending-queue shortcut).`,
163
+ );
164
+ this.name = 'BlockOrCheckpointSlotExpiredError';
165
+ }
166
+ }
167
+
168
+ /** Thrown when attempting to promote a proposed checkpoint but no proposed checkpoint exists in the store. */
169
+ export class NoProposedCheckpointToPromoteError extends Error {
170
+ constructor() {
171
+ super('Cannot promote proposed checkpoint: no proposed checkpoint exists');
172
+ this.name = 'NoProposedCheckpointToPromoteError';
173
+ }
174
+ }
175
+
176
+ /** Thrown when the archive root of the proposed checkpoint does not match the expected one. */
177
+ export class ProposedCheckpointArchiveRootMismatchError extends Error {
178
+ constructor(
179
+ public readonly expectedArchiveRoot: Fr,
180
+ public readonly actualArchiveRoot: Fr,
181
+ ) {
182
+ super(
183
+ `Cannot promote proposed checkpoint: archive root mismatch (expected ${expectedArchiveRoot}, got ${actualArchiveRoot})`,
184
+ );
185
+ this.name = 'ProposedCheckpointArchiveRootMismatchError';
186
+ }
187
+ }
188
+
189
+ /** Thrown when the proposed checkpoint does not directly follow the latest confirmed checkpoint. */
190
+ export class ProposedCheckpointPromotionNotSequentialError extends Error {
191
+ constructor(
192
+ public readonly proposedCheckpointNumber: number,
193
+ public readonly latestCheckpointNumber: number,
194
+ ) {
195
+ super(
196
+ `Cannot promote proposed checkpoint: not sequential (latest ${latestCheckpointNumber}, proposed ${proposedCheckpointNumber})`,
197
+ );
198
+ this.name = 'ProposedCheckpointPromotionNotSequentialError';
199
+ }
200
+ }
201
+
107
202
  /** Thrown when a proposed block conflicts with an already checkpointed block (different content). */
108
203
  export class CannotOverwriteCheckpointedBlockError extends Error {
109
204
  constructor(
package/src/factory.ts CHANGED
@@ -13,7 +13,7 @@ import { protocolContractNames } from '@aztec/protocol-contracts';
13
13
  import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
14
14
  import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
15
15
  import type { ArchiverEmitter } from '@aztec/stdlib/block';
16
- import { type ContractClassPublic, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
16
+ import { type ContractClassPublicWithCommitment, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
17
17
  import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
18
18
  import { getTelemetryClient } from '@aztec/telemetry-client';
19
19
 
@@ -121,6 +121,7 @@ export async function createArchiver(
121
121
  batchSize: 100,
122
122
  maxAllowedEthClientDriftSeconds: 300,
123
123
  ethereumAllowNoDebugHosts: false,
124
+ skipHistoricalLogsCheck: false,
124
125
  },
125
126
  mapArchiverConfig(config),
126
127
  );
@@ -173,16 +174,22 @@ export async function createArchiver(
173
174
  return archiver;
174
175
  }
175
176
 
176
- /** Registers protocol contracts in the archiver store. */
177
+ /** Registers protocol contracts in the archiver store. Idempotent — skips contracts that already exist (e.g. on node restart). */
177
178
  export async function registerProtocolContracts(store: KVArchiverDataStore) {
178
179
  const blockNumber = 0;
179
180
  for (const name of protocolContractNames) {
180
181
  const provider = new BundledProtocolContractsProvider();
181
182
  const contract = await provider.getProtocolContractArtifact(name);
182
- const contractClassPublic: ContractClassPublic = {
183
+
184
+ // Skip if already registered (happens on node restart with a persisted store).
185
+ if (await store.getContractClass(contract.contractClass.id)) {
186
+ continue;
187
+ }
188
+
189
+ const publicBytecodeCommitment = await computePublicBytecodeCommitment(contract.contractClass.packedBytecode);
190
+ const contractClassPublic: ContractClassPublicWithCommitment = {
183
191
  ...contract.contractClass,
184
- privateFunctions: [],
185
- utilityFunctions: [],
192
+ publicBytecodeCommitment,
186
193
  };
187
194
 
188
195
  const publicFunctionSignatures = contract.artifact.functions
@@ -190,8 +197,7 @@ export async function registerProtocolContracts(store: KVArchiverDataStore) {
190
197
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
191
198
 
192
199
  await store.registerContractFunctionSignatures(publicFunctionSignatures);
193
- const bytecodeCommitment = await computePublicBytecodeCommitment(contractClassPublic.packedBytecode);
194
- await store.addContractClasses([contractClassPublic], [bytecodeCommitment], BlockNumber(blockNumber));
200
+ await store.addContractClasses([contractClassPublic], BlockNumber(blockNumber));
195
201
  await store.addContractInstances([contract.instance], BlockNumber(blockNumber));
196
202
  }
197
203
  }
package/src/index.ts CHANGED
@@ -10,4 +10,5 @@ export { KVArchiverDataStore, ARCHIVER_DB_VERSION } from './store/kv_archiver_st
10
10
  export { ContractInstanceStore } from './store/contract_instance_store.js';
11
11
  export { L2TipsCache } from './store/l2_tips_cache.js';
12
12
 
13
- export { retrieveCheckpointsFromRollup, retrieveL2ProofVerifiedEvents } from './l1/data_retrieval.js';
13
+ export { retrieveL2ProofVerifiedEvents } from './l1/data_retrieval.js';
14
+ export { CalldataRetriever } from './l1/calldata_retriever.js';
@@ -1,12 +1,13 @@
1
1
  import { MULTI_CALL_3_ADDRESS, type ViemCommitteeAttestations, type ViemHeader } from '@aztec/ethereum/contracts';
2
2
  import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
3
3
  import { CheckpointNumber } from '@aztec/foundation/branded-types';
4
+ import { LruSet } from '@aztec/foundation/collection';
4
5
  import { Fr } from '@aztec/foundation/curves/bn254';
5
6
  import { EthAddress } from '@aztec/foundation/eth-address';
6
7
  import type { Logger } from '@aztec/foundation/log';
7
8
  import { RollupAbi } from '@aztec/l1-artifacts';
8
9
  import { CommitteeAttestation } from '@aztec/stdlib/block';
9
- import { ConsensusPayload, SignatureDomainSeparator } from '@aztec/stdlib/p2p';
10
+ import { ConsensusPayload, getHashedSignaturePayloadTypedData } from '@aztec/stdlib/p2p';
10
11
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
11
12
 
12
13
  import {
@@ -44,7 +45,7 @@ type CheckpointData = {
44
45
  */
45
46
  export class CalldataRetriever {
46
47
  /** Tx hashes we've already logged for trace+debug failure (log once per tx per process). */
47
- private static readonly traceFailureWarnedTxHashes = new Set<string>();
48
+ private static readonly traceFailureWarnedTxHashes = new LruSet<string>(1000);
48
49
 
49
50
  /** Clears the trace-failure warned set. For testing only. */
50
51
  static resetTraceFailureWarnedForTesting(): void {
@@ -60,6 +61,13 @@ export class CalldataRetriever {
60
61
  private readonly rollupAddress: EthAddress,
61
62
  ) {}
62
63
 
64
+ private getSignatureContext() {
65
+ return {
66
+ chainId: this.publicClient.chain.id,
67
+ rollupAddress: this.rollupAddress,
68
+ };
69
+ }
70
+
63
71
  /**
64
72
  * Gets checkpoint header and metadata from the calldata of an L1 transaction.
65
73
  * Tries multicall3 decoding, falls back to trace-based extraction.
@@ -465,9 +473,13 @@ export class CalldataRetriever {
465
473
 
466
474
  /** Computes the keccak256 payload digest from the checkpoint header, archive root, and fee asset price modifier. */
467
475
  private computePayloadDigest(header: CheckpointHeader, archiveRoot: Fr, feeAssetPriceModifier: bigint): Hex {
468
- const consensusPayload = new ConsensusPayload(header, archiveRoot, feeAssetPriceModifier);
469
- const payloadToSign = consensusPayload.getPayloadToSign(SignatureDomainSeparator.checkpointAttestation);
470
- return keccak256(payloadToSign);
476
+ const consensusPayload = new ConsensusPayload(
477
+ header,
478
+ archiveRoot,
479
+ feeAssetPriceModifier,
480
+ this.getSignatureContext(),
481
+ );
482
+ return getHashedSignaturePayloadTypedData(consensusPayload).toString();
471
483
  }
472
484
 
473
485
  /**
@@ -35,18 +35,28 @@ import type { DataRetrieval } from '../structs/data_retrieval.js';
35
35
  import type { InboxMessage } from '../structs/inbox_message.js';
36
36
  import { CalldataRetriever } from './calldata_retriever.js';
37
37
 
38
- export type RetrievedCheckpoint = {
38
+ type RetrievedCheckpointBase = {
39
39
  checkpointNumber: CheckpointNumber;
40
40
  archiveRoot: Fr;
41
41
  feeAssetPriceModifier: bigint;
42
42
  header: CheckpointHeader;
43
- checkpointBlobData: CheckpointBlobData;
44
43
  l1: L1PublishedData;
45
44
  chainId: Fr;
46
45
  version: Fr;
47
46
  attestations: CommitteeAttestation[];
48
47
  };
49
48
 
49
+ /** Checkpoint data as retrieved from L1 calldata and blob data. */
50
+ export type RetrievedCheckpoint = RetrievedCheckpointBase & { checkpointBlobData: CheckpointBlobData };
51
+
52
+ /** Checkpoint data retrieved from L1 calldata only, without blob data. */
53
+ export type RetrievedCheckpointFromCalldata = RetrievedCheckpointBase & {
54
+ /** Versioned blob hashes from the checkpoint proposed event. */
55
+ blobHashes: Buffer[];
56
+ /** Parent beacon block root from the L1 block, used for blob fetching. */
57
+ parentBeaconBlockRoot: string | undefined;
58
+ };
59
+
50
60
  export async function retrievedToPublishedCheckpoint({
51
61
  checkpointNumber,
52
62
  archiveRoot,
@@ -137,31 +147,27 @@ export async function retrievedToPublishedCheckpoint({
137
147
  }
138
148
 
139
149
  /**
140
- * Fetches new checkpoints.
150
+ * Fetches checkpoint calldata from the rollup contract without fetching blob data.
151
+ * Returns RetrievedCheckpointFromCalldata objects that preserve the information needed for deferred blob fetching.
141
152
  * @param rollup - The rollup contract wrapper.
142
153
  * @param publicClient - The viem public client to use for transaction retrieval.
143
154
  * @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
155
  * @param searchStartBlock - The block number to use for starting the search.
146
156
  * @param searchEndBlock - The highest block number that we should search up to.
147
- * @param contractAddresses - The contract addresses (governanceProposerAddress, slashFactoryAddress, slashingProposerAddress).
148
157
  * @param instrumentation - The archiver instrumentation instance.
149
158
  * @param logger - The logger instance.
150
- * @param isHistoricalSync - Whether this is a historical sync.
151
- * @returns An array of retrieved checkpoints.
159
+ * @returns An array of calldata-only checkpoints.
152
160
  */
153
- export async function retrieveCheckpointsFromRollup(
161
+ export async function retrieveCheckpointCalldataFromRollup(
154
162
  rollup: RollupContract,
155
163
  publicClient: ViemPublicClient,
156
164
  debugClient: ViemPublicDebugClient,
157
- blobClient: BlobClientInterface,
158
165
  searchStartBlock: bigint,
159
166
  searchEndBlock: bigint,
160
167
  instrumentation: ArchiverInstrumentation,
161
168
  logger: Logger = createLogger('archiver'),
162
- isHistoricalSync: boolean = false,
163
- ): Promise<RetrievedCheckpoint[]> {
164
- const retrievedCheckpoints: RetrievedCheckpoint[] = [];
169
+ ): Promise<RetrievedCheckpointFromCalldata[]> {
170
+ const retrievedCheckpoints: RetrievedCheckpointFromCalldata[] = [];
165
171
 
166
172
  let rollupConstants: { chainId: Fr; version: Fr; targetCommitteeSize: number } | undefined;
167
173
 
@@ -197,46 +203,39 @@ export async function retrieveCheckpointsFromRollup(
197
203
  rollup,
198
204
  publicClient,
199
205
  debugClient,
200
- blobClient,
201
206
  checkpointProposedLogs,
202
207
  rollupConstants,
203
208
  instrumentation,
204
209
  logger,
205
- isHistoricalSync,
206
210
  );
207
211
  retrievedCheckpoints.push(...newCheckpoints);
208
212
  searchStartBlock = lastLog.l1BlockNumber + 1n;
209
213
  } while (searchStartBlock <= searchEndBlock);
210
214
 
211
- // The asyncPool from processCheckpointProposedLogs will not necessarily return the checkpoints in order, so we sort them before returning.
212
215
  return retrievedCheckpoints.sort((a, b) => Number(a.l1.blockNumber - b.l1.blockNumber));
213
216
  }
214
217
 
215
218
  /**
216
- * Processes newly received CheckpointProposed logs.
219
+ * Processes CheckpointProposed logs, fetching only calldata (no blobs).
217
220
  * @param rollup - The rollup contract wrapper.
218
221
  * @param publicClient - The viem public client to use for transaction retrieval.
219
222
  * @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
223
  * @param logs - CheckpointProposed logs.
222
224
  * @param rollupConstants - The rollup constants (chainId, version, targetCommitteeSize).
223
225
  * @param instrumentation - The archiver instrumentation instance.
224
226
  * @param logger - The logger instance.
225
- * @param isHistoricalSync - Whether this is a historical sync.
226
- * @returns An array of retrieved checkpoints.
227
+ * @returns An array of calldata-only checkpoints.
227
228
  */
228
229
  async function processCheckpointProposedLogs(
229
230
  rollup: RollupContract,
230
231
  publicClient: ViemPublicClient,
231
232
  debugClient: ViemPublicDebugClient,
232
- blobClient: BlobClientInterface,
233
233
  logs: CheckpointProposedLog[],
234
234
  { chainId, version, targetCommitteeSize }: { chainId: Fr; version: Fr; targetCommitteeSize: number },
235
235
  instrumentation: ArchiverInstrumentation,
236
236
  logger: Logger,
237
- isHistoricalSync: boolean,
238
- ): Promise<RetrievedCheckpoint[]> {
239
- const retrievedCheckpoints: RetrievedCheckpoint[] = [];
237
+ ): Promise<RetrievedCheckpointFromCalldata[]> {
238
+ const retrievedCheckpoints: RetrievedCheckpointFromCalldata[] = [];
240
239
  const calldataRetriever = new CalldataRetriever(
241
240
  publicClient,
242
241
  debugClient,
@@ -252,7 +251,6 @@ async function processCheckpointProposedLogs(
252
251
  const archiveFromChain = await rollup.archiveAt(checkpointNumber);
253
252
  const blobHashes = log.args.versionedBlobHashes;
254
253
 
255
- // The value from the event and contract will match only if the checkpoint is in the chain.
256
254
  if (archive.equals(archiveFromChain)) {
257
255
  const expectedHashes = {
258
256
  attestationsHash: log.args.attestationsHash.toString() as Hex,
@@ -268,19 +266,16 @@ async function processCheckpointProposedLogs(
268
266
  const { timestamp, parentBeaconBlockRoot } = await getL1Block(publicClient, log.l1BlockNumber);
269
267
  const l1 = new L1PublishedData(log.l1BlockNumber, timestamp, log.l1BlockHash.toString());
270
268
 
271
- const checkpointBlobData = await getCheckpointBlobDataFromBlobs(
272
- blobClient,
273
- checkpoint.blockHash,
269
+ retrievedCheckpoints.push({
270
+ ...checkpoint,
271
+ l1,
272
+ chainId,
273
+ version,
274
274
  blobHashes,
275
- checkpointNumber,
276
- logger,
277
- isHistoricalSync,
278
275
  parentBeaconBlockRoot,
279
- timestamp,
280
- );
276
+ });
281
277
 
282
- retrievedCheckpoints.push({ ...checkpoint, checkpointBlobData, l1, chainId, version });
283
- logger.trace(`Retrieved checkpoint ${checkpointNumber} from L1 tx ${log.l1TransactionHash}`, {
278
+ logger.trace(`Retrieved checkpoint calldata ${checkpointNumber} from L1 tx ${log.l1TransactionHash}`, {
284
279
  l1BlockNumber: log.l1BlockNumber,
285
280
  checkpointNumber,
286
281
  archive: archive.toString(),
@@ -344,14 +339,10 @@ export async function getCheckpointBlobDataFromBlobs(
344
339
  /** Given an L1 to L2 message, retrieves its corresponding event from the Inbox within a specific block range. */
345
340
  export async function retrieveL1ToL2Message(
346
341
  inbox: InboxContract,
347
- leaf: Fr,
348
- fromBlock: bigint,
349
- toBlock: bigint,
342
+ message: InboxMessage,
350
343
  ): Promise<InboxMessage | undefined> {
351
- const logs = await inbox.getMessageSentEventByHash(leaf.toString(), fromBlock, toBlock);
352
-
353
- const messages = mapLogsInboxMessage(logs);
354
- return messages.length > 0 ? messages[0] : undefined;
344
+ const log = await inbox.getMessageSentEventByHash(message.leaf.toString(), message.l1BlockNumber);
345
+ return log && mapLogInboxMessage(log);
355
346
  }
356
347
 
357
348
  /**
@@ -374,22 +365,22 @@ export async function retrieveL1ToL2Messages(
374
365
  break;
375
366
  }
376
367
 
377
- retrievedL1ToL2Messages.push(...mapLogsInboxMessage(messageSentLogs));
368
+ retrievedL1ToL2Messages.push(...messageSentLogs.map(mapLogInboxMessage));
378
369
  searchStartBlock = messageSentLogs.at(-1)!.l1BlockNumber + 1n;
379
370
  }
380
371
 
381
372
  return retrievedL1ToL2Messages;
382
373
  }
383
374
 
384
- function mapLogsInboxMessage(logs: MessageSentLog[]): InboxMessage[] {
385
- return logs.map(log => ({
375
+ function mapLogInboxMessage(log: MessageSentLog): InboxMessage {
376
+ return {
386
377
  index: log.args.index,
387
378
  leaf: log.args.leaf,
388
379
  l1BlockNumber: log.l1BlockNumber,
389
380
  l1BlockHash: log.l1BlockHash,
390
381
  checkpointNumber: log.args.checkpointNumber,
391
382
  rollingHash: log.args.rollingHash,
392
- }));
383
+ };
393
384
  }
394
385
 
395
386
  /** Retrieves L2ProofVerified events from the rollup contract. */
@@ -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
+ }
@@ -6,7 +6,13 @@ import { isDefined } from '@aztec/foundation/types';
6
6
  import type { FunctionSelector } from '@aztec/stdlib/abi';
7
7
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
8
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
+ import {
10
+ Checkpoint,
11
+ type CheckpointData,
12
+ type CommonCheckpointData,
13
+ type ProposedCheckpointData,
14
+ PublishedCheckpoint,
15
+ } from '@aztec/stdlib/checkpoint';
10
16
  import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
11
17
  import { type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
12
18
  import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
@@ -121,6 +127,22 @@ export abstract class ArchiverDataSourceBase
121
127
  return this.store.getCheckpointedBlocks(from, limit);
122
128
  }
123
129
 
130
+ public getCheckpointData(checkpointNumber: CheckpointNumber): Promise<CheckpointData | undefined> {
131
+ return this.store.getCheckpointData(checkpointNumber);
132
+ }
133
+
134
+ public getCheckpointDataRange(from: CheckpointNumber, limit: number): Promise<CheckpointData[]> {
135
+ return this.store.getCheckpointDataRange(from, limit);
136
+ }
137
+
138
+ public getCheckpointNumberBySlot(slot: SlotNumber): Promise<CheckpointNumber | undefined> {
139
+ return this.store.getCheckpointNumberBySlot(slot);
140
+ }
141
+
142
+ public getBlockDataWithCheckpointContext(blockNumber: BlockNumber) {
143
+ return this.store.getBlockDataWithCheckpointContext(blockNumber);
144
+ }
145
+
124
146
  public getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
125
147
  return this.store.getBlockHeaderByHash(blockHash);
126
148
  }
@@ -157,6 +179,14 @@ export abstract class ArchiverDataSourceBase
157
179
  return this.store.getSettledTxReceipt(txHash, this.l1Constants);
158
180
  }
159
181
 
182
+ public getLastCheckpoint(): Promise<CommonCheckpointData | undefined> {
183
+ return this.store.getLastCheckpoint();
184
+ }
185
+
186
+ public getLastProposedCheckpoint(): Promise<ProposedCheckpointData | undefined> {
187
+ return this.store.getLastProposedCheckpoint();
188
+ }
189
+
160
190
  public isPendingChainInvalid(): Promise<boolean> {
161
191
  return this.getPendingChainValidationStatus().then(status => !status.valid);
162
192
  }
@@ -249,6 +279,7 @@ export abstract class ArchiverDataSourceBase
249
279
  checkpoint.header,
250
280
  blocksForCheckpoint,
251
281
  checkpoint.checkpointNumber,
282
+ checkpoint.feeAssetPriceModifier,
252
283
  );
253
284
  return new PublishedCheckpoint(fullCheckpoint, checkpoint.l1, checkpoint.attestations);
254
285
  }