@aztec/archiver 0.0.1-commit.7b97ef96e → 0.0.1-commit.7cbc774
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.
- package/README.md +19 -11
- package/dest/archiver.d.ts +36 -17
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +257 -75
- package/dest/config.d.ts +6 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +23 -15
- package/dest/errors.d.ts +55 -9
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +81 -14
- package/dest/factory.d.ts +13 -9
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +48 -39
- package/dest/index.d.ts +11 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +10 -2
- package/dest/l1/bin/retrieve-calldata.js +32 -28
- package/dest/l1/calldata_retriever.d.ts +71 -53
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +190 -262
- package/dest/l1/data_retrieval.d.ts +24 -16
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +39 -45
- package/dest/l1/spire_proposer.d.ts +5 -5
- package/dest/l1/spire_proposer.d.ts.map +1 -1
- package/dest/l1/spire_proposer.js +9 -17
- package/dest/l1/trace_tx.d.ts +12 -66
- package/dest/l1/trace_tx.d.ts.map +1 -1
- package/dest/l1/validate_historical_logs.d.ts +23 -0
- package/dest/l1/validate_historical_logs.d.ts.map +1 -0
- package/dest/l1/validate_historical_logs.js +108 -0
- package/dest/modules/contract_data_source_adapter.d.ts +25 -0
- package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
- package/dest/modules/contract_data_source_adapter.js +40 -0
- package/dest/modules/data_source_base.d.ts +70 -46
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +270 -135
- package/dest/modules/data_store_updater.d.ts +42 -17
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +191 -122
- package/dest/modules/instrumentation.d.ts +18 -2
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +35 -7
- package/dest/modules/l1_synchronizer.d.ts +12 -11
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +439 -207
- package/dest/modules/validation.d.ts +4 -3
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +6 -6
- package/dest/store/block_store.d.ts +174 -70
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +696 -250
- package/dest/store/contract_class_store.d.ts +17 -4
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +24 -68
- package/dest/store/contract_instance_store.d.ts +28 -1
- package/dest/store/contract_instance_store.d.ts.map +1 -1
- package/dest/store/contract_instance_store.js +37 -2
- package/dest/store/data_stores.d.ts +68 -0
- package/dest/store/data_stores.d.ts.map +1 -0
- package/dest/store/data_stores.js +54 -0
- package/dest/store/function_names_cache.d.ts +17 -0
- package/dest/store/function_names_cache.d.ts.map +1 -0
- package/dest/store/function_names_cache.js +30 -0
- package/dest/store/l2_tips_cache.d.ts +13 -7
- package/dest/store/l2_tips_cache.d.ts.map +1 -1
- package/dest/store/l2_tips_cache.js +13 -76
- package/dest/store/log_store.d.ts +42 -37
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +262 -408
- package/dest/store/log_store_codec.d.ts +70 -0
- package/dest/store/log_store_codec.d.ts.map +1 -0
- package/dest/store/log_store_codec.js +101 -0
- package/dest/store/message_store.d.ts +11 -1
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +51 -9
- package/dest/test/fake_l1_state.d.ts +22 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +152 -24
- package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +2 -1
- package/dest/test/mock_l2_block_source.d.ts +52 -46
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +246 -170
- package/dest/test/mock_structs.d.ts +4 -1
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +13 -1
- package/dest/test/noop_l1_archiver.d.ts +12 -6
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +26 -9
- package/package.json +14 -14
- package/src/archiver.ts +313 -75
- package/src/config.ts +32 -12
- package/src/errors.ts +122 -21
- package/src/factory.ts +54 -30
- package/src/index.ts +18 -2
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +40 -27
- package/src/l1/calldata_retriever.ts +243 -384
- package/src/l1/data_retrieval.ts +55 -69
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/modules/contract_data_source_adapter.ts +55 -0
- package/src/modules/data_source_base.ts +336 -171
- package/src/modules/data_store_updater.ts +224 -154
- package/src/modules/instrumentation.ts +48 -8
- package/src/modules/l1_synchronizer.ts +579 -254
- package/src/modules/validation.ts +10 -9
- package/src/store/block_store.ts +865 -290
- package/src/store/contract_class_store.ts +31 -103
- package/src/store/contract_instance_store.ts +51 -5
- package/src/store/data_stores.ts +104 -0
- package/src/store/function_names_cache.ts +37 -0
- package/src/store/l2_tips_cache.ts +16 -70
- package/src/store/log_store.ts +301 -559
- package/src/store/log_store_codec.ts +132 -0
- package/src/store/message_store.ts +60 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +198 -35
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +309 -205
- package/src/test/mock_structs.ts +20 -6
- package/src/test/noop_l1_archiver.ts +39 -9
- package/dest/store/kv_archiver_store.d.ts +0 -354
- package/dest/store/kv_archiver_store.d.ts.map +0 -1
- package/dest/store/kv_archiver_store.js +0 -464
- package/src/store/kv_archiver_store.ts +0 -671
package/src/l1/data_retrieval.ts
CHANGED
|
@@ -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
|
-
|
|
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,36 +147,27 @@ export async function retrievedToPublishedCheckpoint({
|
|
|
137
147
|
}
|
|
138
148
|
|
|
139
149
|
/**
|
|
140
|
-
* Fetches
|
|
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
|
-
* @
|
|
151
|
-
* @returns An array of retrieved checkpoints.
|
|
159
|
+
* @returns An array of calldata-only checkpoints.
|
|
152
160
|
*/
|
|
153
|
-
export async function
|
|
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
|
-
contractAddresses: {
|
|
161
|
-
governanceProposerAddress: EthAddress;
|
|
162
|
-
slashFactoryAddress?: EthAddress;
|
|
163
|
-
slashingProposerAddress: EthAddress;
|
|
164
|
-
},
|
|
165
167
|
instrumentation: ArchiverInstrumentation,
|
|
166
168
|
logger: Logger = createLogger('archiver'),
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const retrievedCheckpoints: RetrievedCheckpoint[] = [];
|
|
169
|
+
): Promise<RetrievedCheckpointFromCalldata[]> {
|
|
170
|
+
const retrievedCheckpoints: RetrievedCheckpointFromCalldata[] = [];
|
|
170
171
|
|
|
171
172
|
let rollupConstants: { chainId: Fr; version: Fr; targetCommitteeSize: number } | undefined;
|
|
172
173
|
|
|
@@ -202,60 +203,46 @@ export async function retrieveCheckpointsFromRollup(
|
|
|
202
203
|
rollup,
|
|
203
204
|
publicClient,
|
|
204
205
|
debugClient,
|
|
205
|
-
blobClient,
|
|
206
206
|
checkpointProposedLogs,
|
|
207
207
|
rollupConstants,
|
|
208
|
-
contractAddresses,
|
|
209
208
|
instrumentation,
|
|
210
209
|
logger,
|
|
211
|
-
isHistoricalSync,
|
|
212
210
|
);
|
|
213
211
|
retrievedCheckpoints.push(...newCheckpoints);
|
|
214
212
|
searchStartBlock = lastLog.l1BlockNumber + 1n;
|
|
215
213
|
} while (searchStartBlock <= searchEndBlock);
|
|
216
214
|
|
|
217
|
-
// The asyncPool from processCheckpointProposedLogs will not necessarily return the checkpoints in order, so we sort them before returning.
|
|
218
215
|
return retrievedCheckpoints.sort((a, b) => Number(a.l1.blockNumber - b.l1.blockNumber));
|
|
219
216
|
}
|
|
220
217
|
|
|
221
218
|
/**
|
|
222
|
-
* Processes
|
|
219
|
+
* Processes CheckpointProposed logs, fetching only calldata (no blobs).
|
|
223
220
|
* @param rollup - The rollup contract wrapper.
|
|
224
221
|
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
225
222
|
* @param debugClient - The viem debug client to use for trace/debug RPC methods (optional).
|
|
226
|
-
* @param blobClient - The blob client client for fetching blob data.
|
|
227
223
|
* @param logs - CheckpointProposed logs.
|
|
228
224
|
* @param rollupConstants - The rollup constants (chainId, version, targetCommitteeSize).
|
|
229
|
-
* @param contractAddresses - The contract addresses (governanceProposerAddress, slashFactoryAddress, slashingProposerAddress).
|
|
230
225
|
* @param instrumentation - The archiver instrumentation instance.
|
|
231
226
|
* @param logger - The logger instance.
|
|
232
|
-
* @
|
|
233
|
-
* @returns An array of retrieved checkpoints.
|
|
227
|
+
* @returns An array of calldata-only checkpoints.
|
|
234
228
|
*/
|
|
235
229
|
async function processCheckpointProposedLogs(
|
|
236
230
|
rollup: RollupContract,
|
|
237
231
|
publicClient: ViemPublicClient,
|
|
238
232
|
debugClient: ViemPublicDebugClient,
|
|
239
|
-
blobClient: BlobClientInterface,
|
|
240
233
|
logs: CheckpointProposedLog[],
|
|
241
234
|
{ chainId, version, targetCommitteeSize }: { chainId: Fr; version: Fr; targetCommitteeSize: number },
|
|
242
|
-
contractAddresses: {
|
|
243
|
-
governanceProposerAddress: EthAddress;
|
|
244
|
-
slashFactoryAddress?: EthAddress;
|
|
245
|
-
slashingProposerAddress: EthAddress;
|
|
246
|
-
},
|
|
247
235
|
instrumentation: ArchiverInstrumentation,
|
|
248
236
|
logger: Logger,
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
const retrievedCheckpoints: RetrievedCheckpoint[] = [];
|
|
237
|
+
): Promise<RetrievedCheckpointFromCalldata[]> {
|
|
238
|
+
const retrievedCheckpoints: RetrievedCheckpointFromCalldata[] = [];
|
|
252
239
|
const calldataRetriever = new CalldataRetriever(
|
|
253
240
|
publicClient,
|
|
254
241
|
debugClient,
|
|
255
242
|
targetCommitteeSize,
|
|
256
243
|
instrumentation,
|
|
257
244
|
logger,
|
|
258
|
-
|
|
245
|
+
EthAddress.fromString(rollup.address),
|
|
259
246
|
);
|
|
260
247
|
|
|
261
248
|
await asyncPool(10, logs, async log => {
|
|
@@ -264,12 +251,10 @@ async function processCheckpointProposedLogs(
|
|
|
264
251
|
const archiveFromChain = await rollup.archiveAt(checkpointNumber);
|
|
265
252
|
const blobHashes = log.args.versionedBlobHashes;
|
|
266
253
|
|
|
267
|
-
// The value from the event and contract will match only if the checkpoint is in the chain.
|
|
268
254
|
if (archive.equals(archiveFromChain)) {
|
|
269
|
-
// Build expected hashes object (fields may be undefined for backwards compatibility with older events)
|
|
270
255
|
const expectedHashes = {
|
|
271
|
-
attestationsHash: log.args.attestationsHash
|
|
272
|
-
payloadDigest: log.args.payloadDigest
|
|
256
|
+
attestationsHash: log.args.attestationsHash.toString() as Hex,
|
|
257
|
+
payloadDigest: log.args.payloadDigest.toString() as Hex,
|
|
273
258
|
};
|
|
274
259
|
|
|
275
260
|
const checkpoint = await calldataRetriever.getCheckpointFromRollupTx(
|
|
@@ -278,23 +263,19 @@ async function processCheckpointProposedLogs(
|
|
|
278
263
|
checkpointNumber,
|
|
279
264
|
expectedHashes,
|
|
280
265
|
);
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
266
|
+
const { timestamp, parentBeaconBlockRoot } = await getL1Block(publicClient, log.l1BlockNumber);
|
|
267
|
+
const l1 = new L1PublishedData(log.l1BlockNumber, timestamp, log.l1BlockHash.toString());
|
|
268
|
+
|
|
269
|
+
retrievedCheckpoints.push({
|
|
270
|
+
...checkpoint,
|
|
271
|
+
l1,
|
|
272
|
+
chainId,
|
|
273
|
+
version,
|
|
284
274
|
blobHashes,
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
isHistoricalSync,
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
const l1 = new L1PublishedData(
|
|
291
|
-
log.l1BlockNumber,
|
|
292
|
-
await getL1BlockTime(publicClient, log.l1BlockNumber),
|
|
293
|
-
log.l1BlockHash.toString(),
|
|
294
|
-
);
|
|
275
|
+
parentBeaconBlockRoot,
|
|
276
|
+
});
|
|
295
277
|
|
|
296
|
-
|
|
297
|
-
logger.trace(`Retrieved checkpoint ${checkpointNumber} from L1 tx ${log.l1TransactionHash}`, {
|
|
278
|
+
logger.trace(`Retrieved checkpoint calldata ${checkpointNumber} from L1 tx ${log.l1TransactionHash}`, {
|
|
298
279
|
l1BlockNumber: log.l1BlockNumber,
|
|
299
280
|
checkpointNumber,
|
|
300
281
|
archive: archive.toString(),
|
|
@@ -311,9 +292,12 @@ async function processCheckpointProposedLogs(
|
|
|
311
292
|
return retrievedCheckpoints;
|
|
312
293
|
}
|
|
313
294
|
|
|
314
|
-
export async function
|
|
295
|
+
export async function getL1Block(
|
|
296
|
+
publicClient: ViemPublicClient,
|
|
297
|
+
blockNumber: bigint,
|
|
298
|
+
): Promise<{ timestamp: bigint; parentBeaconBlockRoot: string | undefined }> {
|
|
315
299
|
const block = await publicClient.getBlock({ blockNumber, includeTransactions: false });
|
|
316
|
-
return block.timestamp;
|
|
300
|
+
return { timestamp: block.timestamp, parentBeaconBlockRoot: block.parentBeaconBlockRoot };
|
|
317
301
|
}
|
|
318
302
|
|
|
319
303
|
export async function getCheckpointBlobDataFromBlobs(
|
|
@@ -323,8 +307,14 @@ export async function getCheckpointBlobDataFromBlobs(
|
|
|
323
307
|
checkpointNumber: CheckpointNumber,
|
|
324
308
|
logger: Logger,
|
|
325
309
|
isHistoricalSync: boolean,
|
|
310
|
+
parentBeaconBlockRoot?: string,
|
|
311
|
+
l1BlockTimestamp?: bigint,
|
|
326
312
|
): Promise<CheckpointBlobData> {
|
|
327
|
-
const blobBodies = await blobClient.getBlobSidecar(blockHash, blobHashes, {
|
|
313
|
+
const blobBodies = await blobClient.getBlobSidecar(blockHash, blobHashes, {
|
|
314
|
+
isHistoricalSync,
|
|
315
|
+
parentBeaconBlockRoot,
|
|
316
|
+
l1BlockTimestamp,
|
|
317
|
+
});
|
|
328
318
|
if (blobBodies.length === 0) {
|
|
329
319
|
throw new NoBlobBodiesFoundError(checkpointNumber);
|
|
330
320
|
}
|
|
@@ -349,14 +339,10 @@ export async function getCheckpointBlobDataFromBlobs(
|
|
|
349
339
|
/** Given an L1 to L2 message, retrieves its corresponding event from the Inbox within a specific block range. */
|
|
350
340
|
export async function retrieveL1ToL2Message(
|
|
351
341
|
inbox: InboxContract,
|
|
352
|
-
|
|
353
|
-
fromBlock: bigint,
|
|
354
|
-
toBlock: bigint,
|
|
342
|
+
message: InboxMessage,
|
|
355
343
|
): Promise<InboxMessage | undefined> {
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
const messages = mapLogsInboxMessage(logs);
|
|
359
|
-
return messages.length > 0 ? messages[0] : undefined;
|
|
344
|
+
const log = await inbox.getMessageSentEventByHash(message.leaf.toString(), message.l1BlockNumber);
|
|
345
|
+
return log && mapLogInboxMessage(log);
|
|
360
346
|
}
|
|
361
347
|
|
|
362
348
|
/**
|
|
@@ -379,22 +365,22 @@ export async function retrieveL1ToL2Messages(
|
|
|
379
365
|
break;
|
|
380
366
|
}
|
|
381
367
|
|
|
382
|
-
retrievedL1ToL2Messages.push(...
|
|
368
|
+
retrievedL1ToL2Messages.push(...messageSentLogs.map(mapLogInboxMessage));
|
|
383
369
|
searchStartBlock = messageSentLogs.at(-1)!.l1BlockNumber + 1n;
|
|
384
370
|
}
|
|
385
371
|
|
|
386
372
|
return retrievedL1ToL2Messages;
|
|
387
373
|
}
|
|
388
374
|
|
|
389
|
-
function
|
|
390
|
-
return
|
|
375
|
+
function mapLogInboxMessage(log: MessageSentLog): InboxMessage {
|
|
376
|
+
return {
|
|
391
377
|
index: log.args.index,
|
|
392
378
|
leaf: log.args.leaf,
|
|
393
379
|
l1BlockNumber: log.l1BlockNumber,
|
|
394
380
|
l1BlockHash: log.l1BlockHash,
|
|
395
381
|
checkpointNumber: log.args.checkpointNumber,
|
|
396
382
|
rollingHash: log.args.rollingHash,
|
|
397
|
-
}
|
|
383
|
+
};
|
|
398
384
|
}
|
|
399
385
|
|
|
400
386
|
/** Retrieves L2ProofVerified events from the rollup contract. */
|
package/src/l1/spire_proposer.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
-
//
|
|
145
|
-
|
|
146
|
-
|
|
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 });
|
|
@@ -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,55 @@
|
|
|
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 async getContract(
|
|
32
|
+
address: AztecAddress,
|
|
33
|
+
maybeTimestamp?: UInt64,
|
|
34
|
+
): Promise<ContractInstanceWithAddress | undefined> {
|
|
35
|
+
let timestamp = maybeTimestamp;
|
|
36
|
+
if (timestamp === undefined) {
|
|
37
|
+
const latest = await this.stores.blocks.getLatestL2BlockNumber();
|
|
38
|
+
const blockData = latest > 0 ? await this.stores.blocks.getBlockData({ number: latest }) : undefined;
|
|
39
|
+
timestamp = blockData ? blockData.header.globalVariables.timestamp : 0n;
|
|
40
|
+
}
|
|
41
|
+
return this.stores.contractInstances.getContractInstance(address, timestamp);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public getContractClassIds(): Promise<Fr[]> {
|
|
45
|
+
return this.stores.contractClasses.getContractClassIds();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public getDebugFunctionName(_address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
|
|
49
|
+
return Promise.resolve(this.stores.functionNames.get(selector));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public registerContractFunctionSignatures(signatures: string[]): Promise<void> {
|
|
53
|
+
return this.stores.functionNames.register(signatures);
|
|
54
|
+
}
|
|
55
|
+
}
|