@aztec/archiver 0.0.1-commit.c80b6263 → 0.0.1-commit.cf93bcc56
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/dest/archiver.d.ts +5 -2
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +9 -91
- package/dest/factory.d.ts +1 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +9 -4
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/l1/bin/retrieve-calldata.js +18 -19
- package/dest/l1/calldata_retriever.d.ts +7 -1
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +17 -4
- package/dest/l1/data_retrieval.d.ts +3 -2
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +4 -3
- package/dest/modules/data_source_base.d.ts +11 -6
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +28 -72
- package/dest/modules/data_store_updater.d.ts +9 -2
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +40 -19
- package/dest/modules/instrumentation.d.ts +4 -2
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +9 -2
- package/dest/modules/l1_synchronizer.d.ts +3 -2
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +6 -6
- package/dest/store/block_store.d.ts +19 -15
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +71 -19
- package/dest/store/contract_class_store.d.ts +1 -1
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +11 -7
- package/dest/store/kv_archiver_store.d.ts +21 -7
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +20 -3
- package/dest/store/l2_tips_cache.d.ts +19 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +89 -0
- package/dest/store/log_store.d.ts +1 -1
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +56 -36
- package/dest/test/fake_l1_state.d.ts +4 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +15 -9
- package/dest/test/mock_archiver.d.ts +1 -1
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +3 -2
- package/dest/test/mock_l2_block_source.d.ts +21 -6
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +127 -84
- package/package.json +13 -13
- package/src/archiver.ts +10 -110
- package/src/factory.ts +23 -8
- package/src/index.ts +1 -0
- package/src/l1/bin/retrieve-calldata.ts +17 -23
- package/src/l1/calldata_retriever.ts +25 -3
- package/src/l1/data_retrieval.ts +4 -1
- package/src/modules/data_source_base.ts +56 -95
- package/src/modules/data_store_updater.ts +43 -18
- package/src/modules/instrumentation.ts +9 -2
- package/src/modules/l1_synchronizer.ts +7 -5
- package/src/store/block_store.ts +87 -38
- package/src/store/contract_class_store.ts +11 -7
- package/src/store/kv_archiver_store.ts +40 -8
- package/src/store/l2_tips_cache.ts +89 -0
- package/src/store/log_store.ts +95 -33
- package/src/test/fake_l1_state.ts +17 -9
- package/src/test/mock_archiver.ts +3 -2
- package/src/test/mock_l2_block_source.ts +163 -83
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
|
|
3
|
-
import {
|
|
3
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
4
4
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
+
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
6
7
|
|
|
7
|
-
import { type Hex, createPublicClient, http } from 'viem';
|
|
8
|
+
import { type Hex, createPublicClient, getAbiItem, http, toEventSelector } from 'viem';
|
|
8
9
|
import { mainnet } from 'viem/chains';
|
|
9
10
|
|
|
10
11
|
import { CalldataRetriever } from '../calldata_retriever.js';
|
|
@@ -111,43 +112,36 @@ async function main() {
|
|
|
111
112
|
},
|
|
112
113
|
);
|
|
113
114
|
|
|
114
|
-
// Extract
|
|
115
|
-
logger.info('Decoding transaction to extract
|
|
115
|
+
// Extract checkpoint number from transaction logs
|
|
116
|
+
logger.info('Decoding transaction to extract checkpoint number...');
|
|
116
117
|
const receipt = await publicClient.getTransactionReceipt({ hash: txHash });
|
|
117
|
-
|
|
118
|
+
|
|
119
|
+
// Look for CheckpointProposed event (emitted when a checkpoint is proposed to the rollup)
|
|
120
|
+
// Event signature: CheckpointProposed(uint256 indexed checkpointNumber, bytes32 indexed archive, bytes32[], bytes32, bytes32)
|
|
121
|
+
// Hash: keccak256("CheckpointProposed(uint256,bytes32,bytes32[],bytes32,bytes32)")
|
|
122
|
+
const checkpointProposedEvent = receipt.logs.find(log => {
|
|
118
123
|
try {
|
|
119
|
-
// Try to match the L2BlockProposed event
|
|
120
124
|
return (
|
|
121
125
|
log.address.toLowerCase() === rollupAddress.toString().toLowerCase() &&
|
|
122
|
-
log.topics[0] ===
|
|
126
|
+
log.topics[0] === toEventSelector(getAbiItem({ abi: RollupAbi, name: 'CheckpointProposed' }))
|
|
123
127
|
);
|
|
124
128
|
} catch {
|
|
125
129
|
return false;
|
|
126
130
|
}
|
|
127
131
|
});
|
|
128
132
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
// L2 block number is typically the first indexed parameter
|
|
132
|
-
l2BlockNumber = Number(BigInt(l2BlockProposedEvent.topics[1]));
|
|
133
|
-
logger.info(`L2 Block Number (from event): ${l2BlockNumber}`);
|
|
134
|
-
} else {
|
|
135
|
-
// Fallback: try to extract from transaction data or use a default
|
|
136
|
-
logger.warn('Could not extract L2 block number from event, using block number as fallback');
|
|
137
|
-
l2BlockNumber = Number(tx.blockNumber);
|
|
133
|
+
if (!checkpointProposedEvent || checkpointProposedEvent.topics[1] === undefined) {
|
|
134
|
+
throw new Error(`Checkpoint proposed event not found`);
|
|
138
135
|
}
|
|
139
136
|
|
|
137
|
+
const checkpointNumber = CheckpointNumber.fromBigInt(BigInt(checkpointProposedEvent.topics[1]));
|
|
138
|
+
|
|
140
139
|
logger.info('');
|
|
141
|
-
logger.info('Retrieving
|
|
140
|
+
logger.info('Retrieving checkpoint from rollup transaction...');
|
|
142
141
|
logger.info('');
|
|
143
142
|
|
|
144
143
|
// For this script, we don't have blob hashes or expected hashes, so pass empty arrays/objects
|
|
145
|
-
const result = await retriever.getCheckpointFromRollupTx(
|
|
146
|
-
txHash,
|
|
147
|
-
[],
|
|
148
|
-
CheckpointNumber.fromBlockNumber(BlockNumber(l2BlockNumber)),
|
|
149
|
-
{},
|
|
150
|
-
);
|
|
144
|
+
const result = await retriever.getCheckpointFromRollupTx(txHash, [], checkpointNumber, {});
|
|
151
145
|
|
|
152
146
|
logger.info(' Successfully retrieved block header!');
|
|
153
147
|
logger.info('');
|
|
@@ -39,6 +39,14 @@ import type { CallInfo } from './types.js';
|
|
|
39
39
|
* in order to reconstruct an L2 block header.
|
|
40
40
|
*/
|
|
41
41
|
export class CalldataRetriever {
|
|
42
|
+
/** Tx hashes we've already logged for trace+debug failure (log once per tx per process). */
|
|
43
|
+
private static readonly traceFailureWarnedTxHashes = new Set<string>();
|
|
44
|
+
|
|
45
|
+
/** Clears the trace-failure warned set. For testing only. */
|
|
46
|
+
static resetTraceFailureWarnedForTesting(): void {
|
|
47
|
+
CalldataRetriever.traceFailureWarnedTxHashes.clear();
|
|
48
|
+
}
|
|
49
|
+
|
|
42
50
|
/** Pre-computed valid contract calls for validation */
|
|
43
51
|
private readonly validContractCalls: ValidContractCall[];
|
|
44
52
|
|
|
@@ -84,6 +92,7 @@ export class CalldataRetriever {
|
|
|
84
92
|
header: CheckpointHeader;
|
|
85
93
|
attestations: CommitteeAttestation[];
|
|
86
94
|
blockHash: string;
|
|
95
|
+
feeAssetPriceModifier: bigint;
|
|
87
96
|
}> {
|
|
88
97
|
this.logger.trace(`Fetching checkpoint ${checkpointNumber} from rollup tx ${txHash}`, {
|
|
89
98
|
willValidateHashes: !!expectedHashes.attestationsHash || !!expectedHashes.payloadDigest,
|
|
@@ -313,7 +322,8 @@ export class CalldataRetriever {
|
|
|
313
322
|
this.logger.debug(`Successfully traced using trace_transaction, found ${calls.length} calls`);
|
|
314
323
|
} catch (err) {
|
|
315
324
|
const traceError = err instanceof Error ? err : new Error(String(err));
|
|
316
|
-
this.logger.verbose(`Failed trace_transaction for ${txHash}
|
|
325
|
+
this.logger.verbose(`Failed trace_transaction for ${txHash}: ${traceError.message}`);
|
|
326
|
+
this.logger.debug(`Trace failure details for ${txHash}`, { traceError });
|
|
317
327
|
|
|
318
328
|
try {
|
|
319
329
|
// Fall back to debug_traceTransaction (Geth RPC)
|
|
@@ -322,7 +332,16 @@ export class CalldataRetriever {
|
|
|
322
332
|
this.logger.debug(`Successfully traced using debug_traceTransaction, found ${calls.length} calls`);
|
|
323
333
|
} catch (debugErr) {
|
|
324
334
|
const debugError = debugErr instanceof Error ? debugErr : new Error(String(debugErr));
|
|
325
|
-
|
|
335
|
+
// Log once per tx so we don't spam on every sync cycle when sync point doesn't advance
|
|
336
|
+
if (!CalldataRetriever.traceFailureWarnedTxHashes.has(txHash)) {
|
|
337
|
+
CalldataRetriever.traceFailureWarnedTxHashes.add(txHash);
|
|
338
|
+
this.logger.warn(
|
|
339
|
+
`Cannot decode L1 tx ${txHash}: trace and debug RPC failed or unavailable. ` +
|
|
340
|
+
`trace_transaction: ${traceError.message}; debug_traceTransaction: ${debugError.message}`,
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
// Full error objects can be very long; keep at debug only
|
|
344
|
+
this.logger.debug(`Trace/debug failure details for tx ${txHash}`, {
|
|
326
345
|
traceError,
|
|
327
346
|
debugError,
|
|
328
347
|
txHash,
|
|
@@ -403,6 +422,7 @@ export class CalldataRetriever {
|
|
|
403
422
|
header: CheckpointHeader;
|
|
404
423
|
attestations: CommitteeAttestation[];
|
|
405
424
|
blockHash: string;
|
|
425
|
+
feeAssetPriceModifier: bigint;
|
|
406
426
|
} {
|
|
407
427
|
const { functionName: rollupFunctionName, args: rollupArgs } = decodeFunctionData({
|
|
408
428
|
abi: RollupAbi,
|
|
@@ -458,7 +478,8 @@ export class CalldataRetriever {
|
|
|
458
478
|
if (expectedHashes.payloadDigest) {
|
|
459
479
|
// Use ConsensusPayload to compute the digest - this ensures we match the exact logic
|
|
460
480
|
// used by the network for signing and verification
|
|
461
|
-
const
|
|
481
|
+
const feeAssetPriceModifier = decodedArgs.oracleInput.feeAssetPriceModifier;
|
|
482
|
+
const consensusPayload = new ConsensusPayload(header, archiveRoot, feeAssetPriceModifier);
|
|
462
483
|
const payloadToSign = consensusPayload.getPayloadToSign(SignatureDomainSeparator.checkpointAttestation);
|
|
463
484
|
const computedPayloadDigest = keccak256(payloadToSign);
|
|
464
485
|
|
|
@@ -495,6 +516,7 @@ export class CalldataRetriever {
|
|
|
495
516
|
header,
|
|
496
517
|
attestations,
|
|
497
518
|
blockHash,
|
|
519
|
+
feeAssetPriceModifier: decodedArgs.oracleInput.feeAssetPriceModifier,
|
|
498
520
|
};
|
|
499
521
|
}
|
|
500
522
|
}
|
package/src/l1/data_retrieval.ts
CHANGED
|
@@ -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,
|
|
@@ -100,7 +102,7 @@ export async function retrievedToPublishedCheckpoint({
|
|
|
100
102
|
}),
|
|
101
103
|
});
|
|
102
104
|
|
|
103
|
-
const body = Body.fromTxBlobData(
|
|
105
|
+
const body = Body.fromTxBlobData(blockBlobData.txs);
|
|
104
106
|
|
|
105
107
|
const blobFields = encodeBlockBlobData(blockBlobData);
|
|
106
108
|
await spongeBlob.absorb(blobFields);
|
|
@@ -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 });
|
|
@@ -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 {
|
|
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
|
|
|
@@ -114,14 +114,14 @@ export abstract class ArchiverDataSourceBase
|
|
|
114
114
|
if (!checkpointData) {
|
|
115
115
|
return undefined;
|
|
116
116
|
}
|
|
117
|
-
return BlockNumber(checkpointData.startBlock + checkpointData.
|
|
117
|
+
return BlockNumber(checkpointData.startBlock + checkpointData.blockCount - 1);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
public getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
|
|
121
121
|
return this.store.getCheckpointedBlocks(from, limit);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
public getBlockHeaderByHash(blockHash:
|
|
124
|
+
public getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
|
|
125
125
|
return this.store.getBlockHeaderByHash(blockHash);
|
|
126
126
|
}
|
|
127
127
|
|
|
@@ -129,6 +129,14 @@ export abstract class ArchiverDataSourceBase
|
|
|
129
129
|
return this.store.getBlockHeaderByArchive(archive);
|
|
130
130
|
}
|
|
131
131
|
|
|
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
|
+
|
|
132
140
|
public async getL2Block(number: BlockNumber): Promise<L2Block | undefined> {
|
|
133
141
|
// If the number provided is -ve, then return the latest block.
|
|
134
142
|
if (number < 0) {
|
|
@@ -223,28 +231,21 @@ export abstract class ArchiverDataSourceBase
|
|
|
223
231
|
|
|
224
232
|
public async getCheckpoints(checkpointNumber: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
225
233
|
const checkpoints = await this.store.getRangeOfCheckpoints(checkpointNumber, limit);
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const checkpoint = checkpoints[i];
|
|
234
|
-
const fullCheckpoint = new Checkpoint(
|
|
235
|
-
checkpoint.archive,
|
|
236
|
-
checkpoint.header,
|
|
237
|
-
blocksForCheckpoint,
|
|
238
|
-
checkpoint.checkpointNumber,
|
|
239
|
-
);
|
|
240
|
-
const publishedCheckpoint = new PublishedCheckpoint(
|
|
241
|
-
fullCheckpoint,
|
|
242
|
-
checkpoint.l1,
|
|
243
|
-
checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
|
|
244
|
-
);
|
|
245
|
-
fullCheckpoints.push(publishedCheckpoint);
|
|
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`);
|
|
246
241
|
}
|
|
247
|
-
|
|
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);
|
|
248
249
|
}
|
|
249
250
|
|
|
250
251
|
public getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
|
|
@@ -252,84 +253,44 @@ export abstract class ArchiverDataSourceBase
|
|
|
252
253
|
}
|
|
253
254
|
|
|
254
255
|
public async getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]> {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
let checkpoint = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
|
|
265
|
-
const slot = (b: CheckpointData) => b.header.slotNumber;
|
|
266
|
-
while (checkpoint && slot(checkpoint) >= start) {
|
|
267
|
-
if (slot(checkpoint) <= end) {
|
|
268
|
-
// push the blocks on backwards
|
|
269
|
-
const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
|
|
270
|
-
for (let i = endBlock; i >= checkpoint.startBlock; i--) {
|
|
271
|
-
const checkpointedBlock = await this.getCheckpointedBlock(BlockNumber(i));
|
|
272
|
-
if (checkpointedBlock) {
|
|
273
|
-
blocks.push(checkpointedBlock);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
checkpoint = await this.store.getCheckpointData(CheckpointNumber(checkpoint.checkpointNumber - 1));
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
return blocks.reverse();
|
|
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);
|
|
281
265
|
}
|
|
282
266
|
|
|
283
267
|
public async getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
let checkpoint = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
|
|
294
|
-
const slot = (b: CheckpointData) => b.header.slotNumber;
|
|
295
|
-
while (checkpoint && slot(checkpoint) >= start) {
|
|
296
|
-
if (slot(checkpoint) <= end) {
|
|
297
|
-
// push the blocks on backwards
|
|
298
|
-
const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
|
|
299
|
-
for (let i = endBlock; i >= checkpoint.startBlock; i--) {
|
|
300
|
-
const block = await this.getBlockHeader(BlockNumber(i));
|
|
301
|
-
if (block) {
|
|
302
|
-
blocks.push(block);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
checkpoint = await this.store.getCheckpointData(CheckpointNumber(checkpoint.checkpointNumber - 1));
|
|
307
|
-
}
|
|
308
|
-
return blocks.reverse();
|
|
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);
|
|
309
277
|
}
|
|
310
278
|
|
|
311
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[]> {
|
|
312
288
|
if (!this.l1Constants) {
|
|
313
289
|
throw new Error('L1 constants not set');
|
|
314
290
|
}
|
|
315
291
|
|
|
316
292
|
const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
// Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
|
|
320
|
-
// We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
|
|
321
|
-
let checkpointData = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
|
|
322
|
-
const slot = (b: CheckpointData) => b.header.slotNumber;
|
|
323
|
-
while (checkpointData && slot(checkpointData) >= start) {
|
|
324
|
-
if (slot(checkpointData) <= end) {
|
|
325
|
-
// push the checkpoints on backwards
|
|
326
|
-
const [checkpoint] = await this.getCheckpoints(checkpointData.checkpointNumber, 1);
|
|
327
|
-
checkpoints.push(checkpoint.checkpoint);
|
|
328
|
-
}
|
|
329
|
-
checkpointData = await this.store.getCheckpointData(CheckpointNumber(checkpointData.checkpointNumber - 1));
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
return checkpoints.reverse();
|
|
293
|
+
return this.store.getCheckpointDataForSlotRange(start, end);
|
|
333
294
|
}
|
|
334
295
|
|
|
335
296
|
public async getBlock(number: BlockNumber): Promise<L2Block | undefined> {
|
|
@@ -347,7 +308,7 @@ export abstract class ArchiverDataSourceBase
|
|
|
347
308
|
return this.store.getBlocks(from, limit);
|
|
348
309
|
}
|
|
349
310
|
|
|
350
|
-
public getCheckpointedBlockByHash(blockHash:
|
|
311
|
+
public getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
|
|
351
312
|
return this.store.getCheckpointedBlockByHash(blockHash);
|
|
352
313
|
}
|
|
353
314
|
|
|
@@ -355,7 +316,7 @@ export abstract class ArchiverDataSourceBase
|
|
|
355
316
|
return this.store.getCheckpointedBlockByArchive(archive);
|
|
356
317
|
}
|
|
357
318
|
|
|
358
|
-
public async getL2BlockByHash(blockHash:
|
|
319
|
+
public async getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
359
320
|
const checkpointedBlock = await this.store.getCheckpointedBlockByHash(blockHash);
|
|
360
321
|
return checkpointedBlock?.block;
|
|
361
322
|
}
|
|
@@ -25,6 +25,7 @@ import type { UInt64 } from '@aztec/stdlib/types';
|
|
|
25
25
|
import groupBy from 'lodash.groupby';
|
|
26
26
|
|
|
27
27
|
import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
|
|
28
|
+
import type { L2TipsCache } from '../store/l2_tips_cache.js';
|
|
28
29
|
|
|
29
30
|
/** Operation type for contract data updates. */
|
|
30
31
|
enum Operation {
|
|
@@ -44,7 +45,10 @@ type ReconcileCheckpointsResult = {
|
|
|
44
45
|
export class ArchiverDataStoreUpdater {
|
|
45
46
|
private readonly log = createLogger('archiver:store_updater');
|
|
46
47
|
|
|
47
|
-
constructor(
|
|
48
|
+
constructor(
|
|
49
|
+
private store: KVArchiverDataStore,
|
|
50
|
+
private l2TipsCache?: L2TipsCache,
|
|
51
|
+
) {}
|
|
48
52
|
|
|
49
53
|
/**
|
|
50
54
|
* Adds proposed blocks to the store with contract class/instance extraction from logs.
|
|
@@ -56,11 +60,11 @@ export class ArchiverDataStoreUpdater {
|
|
|
56
60
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
57
61
|
* @returns True if the operation is successful.
|
|
58
62
|
*/
|
|
59
|
-
public addProposedBlocks(
|
|
63
|
+
public async addProposedBlocks(
|
|
60
64
|
blocks: L2Block[],
|
|
61
65
|
pendingChainValidationStatus?: ValidateCheckpointResult,
|
|
62
66
|
): Promise<boolean> {
|
|
63
|
-
|
|
67
|
+
const result = await this.store.transactionAsync(async () => {
|
|
64
68
|
await this.store.addProposedBlocks(blocks);
|
|
65
69
|
|
|
66
70
|
const opResults = await Promise.all([
|
|
@@ -72,8 +76,10 @@ export class ArchiverDataStoreUpdater {
|
|
|
72
76
|
...blocks.map(block => this.addContractDataToDb(block)),
|
|
73
77
|
]);
|
|
74
78
|
|
|
79
|
+
await this.l2TipsCache?.refresh();
|
|
75
80
|
return opResults.every(Boolean);
|
|
76
81
|
});
|
|
82
|
+
return result;
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
/**
|
|
@@ -87,11 +93,11 @@ export class ArchiverDataStoreUpdater {
|
|
|
87
93
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
88
94
|
* @returns Result with information about any pruned blocks.
|
|
89
95
|
*/
|
|
90
|
-
public addCheckpoints(
|
|
96
|
+
public async addCheckpoints(
|
|
91
97
|
checkpoints: PublishedCheckpoint[],
|
|
92
98
|
pendingChainValidationStatus?: ValidateCheckpointResult,
|
|
93
99
|
): Promise<ReconcileCheckpointsResult> {
|
|
94
|
-
|
|
100
|
+
const result = await this.store.transactionAsync(async () => {
|
|
95
101
|
// Before adding checkpoints, check for conflicts with local blocks if any
|
|
96
102
|
const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
|
|
97
103
|
|
|
@@ -111,8 +117,10 @@ export class ArchiverDataStoreUpdater {
|
|
|
111
117
|
...newBlocks.map(block => this.addContractDataToDb(block)),
|
|
112
118
|
]);
|
|
113
119
|
|
|
120
|
+
await this.l2TipsCache?.refresh();
|
|
114
121
|
return { prunedBlocks, lastAlreadyInsertedBlockNumber };
|
|
115
122
|
});
|
|
123
|
+
return result;
|
|
116
124
|
}
|
|
117
125
|
|
|
118
126
|
/**
|
|
@@ -197,8 +205,8 @@ export class ArchiverDataStoreUpdater {
|
|
|
197
205
|
* @returns The removed blocks.
|
|
198
206
|
* @throws Error if any block to be removed is checkpointed.
|
|
199
207
|
*/
|
|
200
|
-
public removeUncheckpointedBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]> {
|
|
201
|
-
|
|
208
|
+
public async removeUncheckpointedBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]> {
|
|
209
|
+
const result = await this.store.transactionAsync(async () => {
|
|
202
210
|
// Verify we're only removing uncheckpointed blocks
|
|
203
211
|
const lastCheckpointedBlockNumber = await this.store.getCheckpointedL2BlockNumber();
|
|
204
212
|
if (blockNumber < lastCheckpointedBlockNumber) {
|
|
@@ -207,8 +215,11 @@ export class ArchiverDataStoreUpdater {
|
|
|
207
215
|
);
|
|
208
216
|
}
|
|
209
217
|
|
|
210
|
-
|
|
218
|
+
const result = await this.removeBlocksAfter(blockNumber);
|
|
219
|
+
await this.l2TipsCache?.refresh();
|
|
220
|
+
return result;
|
|
211
221
|
});
|
|
222
|
+
return result;
|
|
212
223
|
}
|
|
213
224
|
|
|
214
225
|
/**
|
|
@@ -238,17 +249,31 @@ export class ArchiverDataStoreUpdater {
|
|
|
238
249
|
* @returns True if the operation is successful.
|
|
239
250
|
*/
|
|
240
251
|
public async removeCheckpointsAfter(checkpointNumber: CheckpointNumber): Promise<boolean> {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
252
|
+
return await this.store.transactionAsync(async () => {
|
|
253
|
+
const { blocksRemoved = [] } = await this.store.removeCheckpointsAfter(checkpointNumber);
|
|
254
|
+
|
|
255
|
+
const opResults = await Promise.all([
|
|
256
|
+
// Prune rolls back to the last proven block, which is by definition valid
|
|
257
|
+
this.store.setPendingChainValidationStatus({ valid: true }),
|
|
258
|
+
// Remove contract data for all blocks being removed
|
|
259
|
+
...blocksRemoved.map(block => this.removeContractDataFromDb(block)),
|
|
260
|
+
this.store.deleteLogs(blocksRemoved),
|
|
261
|
+
]);
|
|
250
262
|
|
|
251
|
-
|
|
263
|
+
await this.l2TipsCache?.refresh();
|
|
264
|
+
return opResults.every(Boolean);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Updates the proven checkpoint number and refreshes the L2 tips cache.
|
|
270
|
+
* @param checkpointNumber - The checkpoint number to set as proven.
|
|
271
|
+
*/
|
|
272
|
+
public async setProvenCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<void> {
|
|
273
|
+
await this.store.transactionAsync(async () => {
|
|
274
|
+
await this.store.setProvenCheckpointNumber(checkpointNumber);
|
|
275
|
+
await this.l2TipsCache?.refresh();
|
|
276
|
+
});
|
|
252
277
|
}
|
|
253
278
|
|
|
254
279
|
/** Extracts and stores contract data from a single block. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import type { L2Block } from '@aztec/stdlib/block';
|
|
3
|
+
import type { CheckpointData } from '@aztec/stdlib/checkpoint';
|
|
3
4
|
import {
|
|
4
5
|
Attributes,
|
|
5
6
|
type Gauge,
|
|
@@ -17,6 +18,7 @@ export class ArchiverInstrumentation {
|
|
|
17
18
|
public readonly tracer: Tracer;
|
|
18
19
|
|
|
19
20
|
private blockHeight: Gauge;
|
|
21
|
+
private checkpointHeight: Gauge;
|
|
20
22
|
private txCount: UpDownCounter;
|
|
21
23
|
private l1BlockHeight: Gauge;
|
|
22
24
|
private proofsSubmittedDelay: Histogram;
|
|
@@ -47,6 +49,8 @@ export class ArchiverInstrumentation {
|
|
|
47
49
|
|
|
48
50
|
this.blockHeight = meter.createGauge(Metrics.ARCHIVER_BLOCK_HEIGHT);
|
|
49
51
|
|
|
52
|
+
this.checkpointHeight = meter.createGauge(Metrics.ARCHIVER_CHECKPOINT_HEIGHT);
|
|
53
|
+
|
|
50
54
|
this.l1BlockHeight = meter.createGauge(Metrics.ARCHIVER_L1_BLOCK_HEIGHT);
|
|
51
55
|
|
|
52
56
|
this.txCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_TOTAL_TXS);
|
|
@@ -105,6 +109,7 @@ export class ArchiverInstrumentation {
|
|
|
105
109
|
public processNewBlocks(syncTimePerBlock: number, blocks: L2Block[]) {
|
|
106
110
|
this.syncDurationPerBlock.record(Math.ceil(syncTimePerBlock));
|
|
107
111
|
this.blockHeight.record(Math.max(...blocks.map(b => b.number)));
|
|
112
|
+
this.checkpointHeight.record(Math.max(...blocks.map(b => b.checkpointNumber)));
|
|
108
113
|
this.syncBlockCount.add(blocks.length);
|
|
109
114
|
|
|
110
115
|
for (const block of blocks) {
|
|
@@ -127,8 +132,10 @@ export class ArchiverInstrumentation {
|
|
|
127
132
|
this.pruneDuration.record(Math.ceil(duration));
|
|
128
133
|
}
|
|
129
134
|
|
|
130
|
-
public
|
|
131
|
-
|
|
135
|
+
public updateLastProvenCheckpoint(checkpoint: CheckpointData) {
|
|
136
|
+
const lastBlockNumberInCheckpoint = checkpoint.startBlock + checkpoint.blockCount - 1;
|
|
137
|
+
this.blockHeight.record(lastBlockNumberInCheckpoint, { [Attributes.STATUS]: 'proven' });
|
|
138
|
+
this.checkpointHeight.record(checkpoint.checkpointNumber, { [Attributes.STATUS]: 'proven' });
|
|
132
139
|
}
|
|
133
140
|
|
|
134
141
|
public processProofsVerified(logs: { proverId: string; l2BlockNumber: bigint; delay: bigint }[]) {
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
retrievedToPublishedCheckpoint,
|
|
29
29
|
} from '../l1/data_retrieval.js';
|
|
30
30
|
import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
|
|
31
|
+
import type { L2TipsCache } from '../store/l2_tips_cache.js';
|
|
31
32
|
import type { InboxMessage } from '../structs/inbox_message.js';
|
|
32
33
|
import { ArchiverDataStoreUpdater } from './data_store_updater.js';
|
|
33
34
|
import type { ArchiverInstrumentation } from './instrumentation.js';
|
|
@@ -77,9 +78,10 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
77
78
|
private readonly l1Constants: L1RollupConstants & { l1StartBlockHash: Buffer32; genesisArchiveRoot: Fr },
|
|
78
79
|
private readonly events: ArchiverEmitter,
|
|
79
80
|
tracer: Tracer,
|
|
81
|
+
l2TipsCache?: L2TipsCache,
|
|
80
82
|
private readonly log: Logger = createLogger('archiver:l1-sync'),
|
|
81
83
|
) {
|
|
82
|
-
this.updater = new ArchiverDataStoreUpdater(this.store);
|
|
84
|
+
this.updater = new ArchiverDataStoreUpdater(this.store, l2TipsCache);
|
|
83
85
|
this.tracer = tracer;
|
|
84
86
|
}
|
|
85
87
|
|
|
@@ -550,7 +552,7 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
550
552
|
if (provenCheckpointNumber === 0) {
|
|
551
553
|
const localProvenCheckpointNumber = await this.store.getProvenCheckpointNumber();
|
|
552
554
|
if (localProvenCheckpointNumber !== provenCheckpointNumber) {
|
|
553
|
-
await this.
|
|
555
|
+
await this.updater.setProvenCheckpointNumber(provenCheckpointNumber);
|
|
554
556
|
this.log.info(`Rolled back proven chain to checkpoint ${provenCheckpointNumber}`, { provenCheckpointNumber });
|
|
555
557
|
}
|
|
556
558
|
}
|
|
@@ -582,13 +584,13 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
582
584
|
) {
|
|
583
585
|
const localProvenCheckpointNumber = await this.store.getProvenCheckpointNumber();
|
|
584
586
|
if (localProvenCheckpointNumber !== provenCheckpointNumber) {
|
|
585
|
-
await this.
|
|
587
|
+
await this.updater.setProvenCheckpointNumber(provenCheckpointNumber);
|
|
586
588
|
this.log.info(`Updated proven chain to checkpoint ${provenCheckpointNumber}`, { provenCheckpointNumber });
|
|
587
589
|
const provenSlotNumber = localCheckpointForDestinationProvenCheckpointNumber.header.slotNumber;
|
|
588
590
|
const provenEpochNumber: EpochNumber = getEpochAtSlot(provenSlotNumber, this.l1Constants);
|
|
589
591
|
const lastBlockNumberInCheckpoint =
|
|
590
592
|
localCheckpointForDestinationProvenCheckpointNumber.startBlock +
|
|
591
|
-
localCheckpointForDestinationProvenCheckpointNumber.
|
|
593
|
+
localCheckpointForDestinationProvenCheckpointNumber.blockCount -
|
|
592
594
|
1;
|
|
593
595
|
|
|
594
596
|
this.events.emit(L2BlockSourceEvents.L2BlockProven, {
|
|
@@ -597,7 +599,7 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
597
599
|
slotNumber: provenSlotNumber,
|
|
598
600
|
epochNumber: provenEpochNumber,
|
|
599
601
|
});
|
|
600
|
-
this.instrumentation.
|
|
602
|
+
this.instrumentation.updateLastProvenCheckpoint(localCheckpointForDestinationProvenCheckpointNumber);
|
|
601
603
|
} else {
|
|
602
604
|
this.log.trace(`Proven checkpoint ${provenCheckpointNumber} already stored.`);
|
|
603
605
|
}
|