@aztec/archiver 0.0.1-commit.ee80a48 → 0.0.1-commit.ef17749e1
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 +7 -2
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +25 -96
- package/dest/factory.d.ts +2 -2
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +12 -8
- 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 +36 -33
- package/dest/l1/calldata_retriever.d.ts +73 -50
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +190 -259
- package/dest/l1/data_retrieval.d.ts +9 -9
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +21 -19
- 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/modules/data_source_base.d.ts +8 -3
- 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 +13 -3
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +48 -19
- package/dest/modules/instrumentation.d.ts +15 -2
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +19 -2
- package/dest/modules/l1_synchronizer.d.ts +5 -8
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +16 -9
- package/dest/store/block_store.d.ts +18 -14
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +69 -17
- package/dest/store/kv_archiver_store.d.ts +18 -4
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +18 -0
- 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 +55 -35
- package/dest/store/message_store.js +1 -1
- package/dest/test/fake_l1_state.d.ts +6 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +56 -18
- 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 +19 -3
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +128 -82
- 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/package.json +13 -13
- package/src/archiver.ts +39 -116
- package/src/factory.ts +27 -10
- package/src/index.ts +1 -0
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +46 -39
- package/src/l1/calldata_retriever.ts +249 -379
- package/src/l1/data_retrieval.ts +23 -25
- package/src/l1/spire_proposer.ts +7 -15
- package/src/modules/data_source_base.ts +53 -92
- package/src/modules/data_store_updater.ts +49 -19
- package/src/modules/instrumentation.ts +29 -2
- package/src/modules/l1_synchronizer.ts +22 -13
- package/src/store/block_store.ts +85 -36
- package/src/store/kv_archiver_store.ts +35 -3
- package/src/store/l2_tips_cache.ts +89 -0
- package/src/store/log_store.ts +93 -31
- package/src/store/message_store.ts +1 -1
- package/src/test/fake_l1_state.ts +75 -17
- package/src/test/mock_archiver.ts +3 -2
- package/src/test/mock_l2_block_source.ts +164 -78
- package/src/test/mock_structs.ts +20 -6
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,
|
|
@@ -128,6 +130,7 @@ export async function retrievedToPublishedCheckpoint({
|
|
|
128
130
|
header: checkpointHeader,
|
|
129
131
|
blocks: l2Blocks,
|
|
130
132
|
number: checkpointNumber,
|
|
133
|
+
feeAssetPriceModifier: feeAssetPriceModifier,
|
|
131
134
|
});
|
|
132
135
|
|
|
133
136
|
return PublishedCheckpoint.from({ checkpoint, l1, attestations });
|
|
@@ -154,11 +157,6 @@ export async function retrieveCheckpointsFromRollup(
|
|
|
154
157
|
blobClient: BlobClientInterface,
|
|
155
158
|
searchStartBlock: bigint,
|
|
156
159
|
searchEndBlock: bigint,
|
|
157
|
-
contractAddresses: {
|
|
158
|
-
governanceProposerAddress: EthAddress;
|
|
159
|
-
slashFactoryAddress?: EthAddress;
|
|
160
|
-
slashingProposerAddress: EthAddress;
|
|
161
|
-
},
|
|
162
160
|
instrumentation: ArchiverInstrumentation,
|
|
163
161
|
logger: Logger = createLogger('archiver'),
|
|
164
162
|
isHistoricalSync: boolean = false,
|
|
@@ -202,7 +200,6 @@ export async function retrieveCheckpointsFromRollup(
|
|
|
202
200
|
blobClient,
|
|
203
201
|
checkpointProposedLogs,
|
|
204
202
|
rollupConstants,
|
|
205
|
-
contractAddresses,
|
|
206
203
|
instrumentation,
|
|
207
204
|
logger,
|
|
208
205
|
isHistoricalSync,
|
|
@@ -223,7 +220,6 @@ export async function retrieveCheckpointsFromRollup(
|
|
|
223
220
|
* @param blobClient - The blob client client for fetching blob data.
|
|
224
221
|
* @param logs - CheckpointProposed logs.
|
|
225
222
|
* @param rollupConstants - The rollup constants (chainId, version, targetCommitteeSize).
|
|
226
|
-
* @param contractAddresses - The contract addresses (governanceProposerAddress, slashFactoryAddress, slashingProposerAddress).
|
|
227
223
|
* @param instrumentation - The archiver instrumentation instance.
|
|
228
224
|
* @param logger - The logger instance.
|
|
229
225
|
* @param isHistoricalSync - Whether this is a historical sync.
|
|
@@ -236,11 +232,6 @@ async function processCheckpointProposedLogs(
|
|
|
236
232
|
blobClient: BlobClientInterface,
|
|
237
233
|
logs: CheckpointProposedLog[],
|
|
238
234
|
{ chainId, version, targetCommitteeSize }: { chainId: Fr; version: Fr; targetCommitteeSize: number },
|
|
239
|
-
contractAddresses: {
|
|
240
|
-
governanceProposerAddress: EthAddress;
|
|
241
|
-
slashFactoryAddress?: EthAddress;
|
|
242
|
-
slashingProposerAddress: EthAddress;
|
|
243
|
-
},
|
|
244
235
|
instrumentation: ArchiverInstrumentation,
|
|
245
236
|
logger: Logger,
|
|
246
237
|
isHistoricalSync: boolean,
|
|
@@ -252,7 +243,7 @@ async function processCheckpointProposedLogs(
|
|
|
252
243
|
targetCommitteeSize,
|
|
253
244
|
instrumentation,
|
|
254
245
|
logger,
|
|
255
|
-
|
|
246
|
+
EthAddress.fromString(rollup.address),
|
|
256
247
|
);
|
|
257
248
|
|
|
258
249
|
await asyncPool(10, logs, async log => {
|
|
@@ -263,10 +254,9 @@ async function processCheckpointProposedLogs(
|
|
|
263
254
|
|
|
264
255
|
// The value from the event and contract will match only if the checkpoint is in the chain.
|
|
265
256
|
if (archive.equals(archiveFromChain)) {
|
|
266
|
-
// Build expected hashes object (fields may be undefined for backwards compatibility with older events)
|
|
267
257
|
const expectedHashes = {
|
|
268
|
-
attestationsHash: log.args.attestationsHash
|
|
269
|
-
payloadDigest: log.args.payloadDigest
|
|
258
|
+
attestationsHash: log.args.attestationsHash.toString() as Hex,
|
|
259
|
+
payloadDigest: log.args.payloadDigest.toString() as Hex,
|
|
270
260
|
};
|
|
271
261
|
|
|
272
262
|
const checkpoint = await calldataRetriever.getCheckpointFromRollupTx(
|
|
@@ -275,6 +265,9 @@ async function processCheckpointProposedLogs(
|
|
|
275
265
|
checkpointNumber,
|
|
276
266
|
expectedHashes,
|
|
277
267
|
);
|
|
268
|
+
const { timestamp, parentBeaconBlockRoot } = await getL1Block(publicClient, log.l1BlockNumber);
|
|
269
|
+
const l1 = new L1PublishedData(log.l1BlockNumber, timestamp, log.l1BlockHash.toString());
|
|
270
|
+
|
|
278
271
|
const checkpointBlobData = await getCheckpointBlobDataFromBlobs(
|
|
279
272
|
blobClient,
|
|
280
273
|
checkpoint.blockHash,
|
|
@@ -282,12 +275,8 @@ async function processCheckpointProposedLogs(
|
|
|
282
275
|
checkpointNumber,
|
|
283
276
|
logger,
|
|
284
277
|
isHistoricalSync,
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const l1 = new L1PublishedData(
|
|
288
|
-
log.l1BlockNumber,
|
|
289
|
-
await getL1BlockTime(publicClient, log.l1BlockNumber),
|
|
290
|
-
log.l1BlockHash.toString(),
|
|
278
|
+
parentBeaconBlockRoot,
|
|
279
|
+
timestamp,
|
|
291
280
|
);
|
|
292
281
|
|
|
293
282
|
retrievedCheckpoints.push({ ...checkpoint, checkpointBlobData, l1, chainId, version });
|
|
@@ -308,9 +297,12 @@ async function processCheckpointProposedLogs(
|
|
|
308
297
|
return retrievedCheckpoints;
|
|
309
298
|
}
|
|
310
299
|
|
|
311
|
-
export async function
|
|
300
|
+
export async function getL1Block(
|
|
301
|
+
publicClient: ViemPublicClient,
|
|
302
|
+
blockNumber: bigint,
|
|
303
|
+
): Promise<{ timestamp: bigint; parentBeaconBlockRoot: string | undefined }> {
|
|
312
304
|
const block = await publicClient.getBlock({ blockNumber, includeTransactions: false });
|
|
313
|
-
return block.timestamp;
|
|
305
|
+
return { timestamp: block.timestamp, parentBeaconBlockRoot: block.parentBeaconBlockRoot };
|
|
314
306
|
}
|
|
315
307
|
|
|
316
308
|
export async function getCheckpointBlobDataFromBlobs(
|
|
@@ -320,8 +312,14 @@ export async function getCheckpointBlobDataFromBlobs(
|
|
|
320
312
|
checkpointNumber: CheckpointNumber,
|
|
321
313
|
logger: Logger,
|
|
322
314
|
isHistoricalSync: boolean,
|
|
315
|
+
parentBeaconBlockRoot?: string,
|
|
316
|
+
l1BlockTimestamp?: bigint,
|
|
323
317
|
): Promise<CheckpointBlobData> {
|
|
324
|
-
const blobBodies = await blobClient.getBlobSidecar(blockHash, blobHashes, {
|
|
318
|
+
const blobBodies = await blobClient.getBlobSidecar(blockHash, blobHashes, {
|
|
319
|
+
isHistoricalSync,
|
|
320
|
+
parentBeaconBlockRoot,
|
|
321
|
+
l1BlockTimestamp,
|
|
322
|
+
});
|
|
325
323
|
if (blobBodies.length === 0) {
|
|
326
324
|
throw new NoBlobBodiesFoundError(checkpointNumber);
|
|
327
325
|
}
|
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 });
|
|
@@ -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 { type BlockHash, CheckpointedL2Block,
|
|
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,7 +114,7 @@ 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[]> {
|
|
@@ -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> {
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
ContractInstanceUpdatedEvent,
|
|
12
12
|
} from '@aztec/protocol-contracts/instance-registry';
|
|
13
13
|
import type { L2Block, ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
14
|
-
import type
|
|
14
|
+
import { type PublishedCheckpoint, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
15
15
|
import {
|
|
16
16
|
type ExecutablePrivateFunctionWithMembershipProof,
|
|
17
17
|
type UtilityFunctionWithMembershipProof,
|
|
@@ -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,11 @@ 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
|
+
private opts: { rollupManaLimit?: number } = {},
|
|
52
|
+
) {}
|
|
48
53
|
|
|
49
54
|
/**
|
|
50
55
|
* Adds proposed blocks to the store with contract class/instance extraction from logs.
|
|
@@ -56,11 +61,11 @@ export class ArchiverDataStoreUpdater {
|
|
|
56
61
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
57
62
|
* @returns True if the operation is successful.
|
|
58
63
|
*/
|
|
59
|
-
public addProposedBlocks(
|
|
64
|
+
public async addProposedBlocks(
|
|
60
65
|
blocks: L2Block[],
|
|
61
66
|
pendingChainValidationStatus?: ValidateCheckpointResult,
|
|
62
67
|
): Promise<boolean> {
|
|
63
|
-
|
|
68
|
+
const result = await this.store.transactionAsync(async () => {
|
|
64
69
|
await this.store.addProposedBlocks(blocks);
|
|
65
70
|
|
|
66
71
|
const opResults = await Promise.all([
|
|
@@ -72,8 +77,10 @@ export class ArchiverDataStoreUpdater {
|
|
|
72
77
|
...blocks.map(block => this.addContractDataToDb(block)),
|
|
73
78
|
]);
|
|
74
79
|
|
|
80
|
+
await this.l2TipsCache?.refresh();
|
|
75
81
|
return opResults.every(Boolean);
|
|
76
82
|
});
|
|
83
|
+
return result;
|
|
77
84
|
}
|
|
78
85
|
|
|
79
86
|
/**
|
|
@@ -87,11 +94,15 @@ export class ArchiverDataStoreUpdater {
|
|
|
87
94
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
88
95
|
* @returns Result with information about any pruned blocks.
|
|
89
96
|
*/
|
|
90
|
-
public addCheckpoints(
|
|
97
|
+
public async addCheckpoints(
|
|
91
98
|
checkpoints: PublishedCheckpoint[],
|
|
92
99
|
pendingChainValidationStatus?: ValidateCheckpointResult,
|
|
93
100
|
): Promise<ReconcileCheckpointsResult> {
|
|
94
|
-
|
|
101
|
+
for (const checkpoint of checkpoints) {
|
|
102
|
+
validateCheckpoint(checkpoint.checkpoint, { rollupManaLimit: this.opts?.rollupManaLimit });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const result = await this.store.transactionAsync(async () => {
|
|
95
106
|
// Before adding checkpoints, check for conflicts with local blocks if any
|
|
96
107
|
const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
|
|
97
108
|
|
|
@@ -111,8 +122,10 @@ export class ArchiverDataStoreUpdater {
|
|
|
111
122
|
...newBlocks.map(block => this.addContractDataToDb(block)),
|
|
112
123
|
]);
|
|
113
124
|
|
|
125
|
+
await this.l2TipsCache?.refresh();
|
|
114
126
|
return { prunedBlocks, lastAlreadyInsertedBlockNumber };
|
|
115
127
|
});
|
|
128
|
+
return result;
|
|
116
129
|
}
|
|
117
130
|
|
|
118
131
|
/**
|
|
@@ -197,8 +210,8 @@ export class ArchiverDataStoreUpdater {
|
|
|
197
210
|
* @returns The removed blocks.
|
|
198
211
|
* @throws Error if any block to be removed is checkpointed.
|
|
199
212
|
*/
|
|
200
|
-
public removeUncheckpointedBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]> {
|
|
201
|
-
|
|
213
|
+
public async removeUncheckpointedBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]> {
|
|
214
|
+
const result = await this.store.transactionAsync(async () => {
|
|
202
215
|
// Verify we're only removing uncheckpointed blocks
|
|
203
216
|
const lastCheckpointedBlockNumber = await this.store.getCheckpointedL2BlockNumber();
|
|
204
217
|
if (blockNumber < lastCheckpointedBlockNumber) {
|
|
@@ -207,8 +220,11 @@ export class ArchiverDataStoreUpdater {
|
|
|
207
220
|
);
|
|
208
221
|
}
|
|
209
222
|
|
|
210
|
-
|
|
223
|
+
const result = await this.removeBlocksAfter(blockNumber);
|
|
224
|
+
await this.l2TipsCache?.refresh();
|
|
225
|
+
return result;
|
|
211
226
|
});
|
|
227
|
+
return result;
|
|
212
228
|
}
|
|
213
229
|
|
|
214
230
|
/**
|
|
@@ -238,17 +254,31 @@ export class ArchiverDataStoreUpdater {
|
|
|
238
254
|
* @returns True if the operation is successful.
|
|
239
255
|
*/
|
|
240
256
|
public async removeCheckpointsAfter(checkpointNumber: CheckpointNumber): Promise<boolean> {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const opResults = await Promise.all([
|
|
244
|
-
// Prune rolls back to the last proven block, which is by definition valid
|
|
245
|
-
this.store.setPendingChainValidationStatus({ valid: true }),
|
|
246
|
-
// Remove contract data for all blocks being removed
|
|
247
|
-
...blocksRemoved.map(block => this.removeContractDataFromDb(block)),
|
|
248
|
-
this.store.deleteLogs(blocksRemoved),
|
|
249
|
-
]);
|
|
257
|
+
return await this.store.transactionAsync(async () => {
|
|
258
|
+
const { blocksRemoved = [] } = await this.store.removeCheckpointsAfter(checkpointNumber);
|
|
250
259
|
|
|
251
|
-
|
|
260
|
+
const opResults = await Promise.all([
|
|
261
|
+
// Prune rolls back to the last proven block, which is by definition valid
|
|
262
|
+
this.store.setPendingChainValidationStatus({ valid: true }),
|
|
263
|
+
// Remove contract data for all blocks being removed
|
|
264
|
+
...blocksRemoved.map(block => this.removeContractDataFromDb(block)),
|
|
265
|
+
this.store.deleteLogs(blocksRemoved),
|
|
266
|
+
]);
|
|
267
|
+
|
|
268
|
+
await this.l2TipsCache?.refresh();
|
|
269
|
+
return opResults.every(Boolean);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Updates the proven checkpoint number and refreshes the L2 tips cache.
|
|
275
|
+
* @param checkpointNumber - The checkpoint number to set as proven.
|
|
276
|
+
*/
|
|
277
|
+
public async setProvenCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<void> {
|
|
278
|
+
await this.store.transactionAsync(async () => {
|
|
279
|
+
await this.store.setProvenCheckpointNumber(checkpointNumber);
|
|
280
|
+
await this.l2TipsCache?.refresh();
|
|
281
|
+
});
|
|
252
282
|
}
|
|
253
283
|
|
|
254
284
|
/** Extracts and stores contract data from a single block. */
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
3
|
import type { L2Block } from '@aztec/stdlib/block';
|
|
4
|
+
import type { CheckpointData } from '@aztec/stdlib/checkpoint';
|
|
5
|
+
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
6
|
+
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
3
7
|
import {
|
|
4
8
|
Attributes,
|
|
5
9
|
type Gauge,
|
|
@@ -17,6 +21,7 @@ export class ArchiverInstrumentation {
|
|
|
17
21
|
public readonly tracer: Tracer;
|
|
18
22
|
|
|
19
23
|
private blockHeight: Gauge;
|
|
24
|
+
private checkpointHeight: Gauge;
|
|
20
25
|
private txCount: UpDownCounter;
|
|
21
26
|
private l1BlockHeight: Gauge;
|
|
22
27
|
private proofsSubmittedDelay: Histogram;
|
|
@@ -36,6 +41,8 @@ export class ArchiverInstrumentation {
|
|
|
36
41
|
|
|
37
42
|
private blockProposalTxTargetCount: UpDownCounter;
|
|
38
43
|
|
|
44
|
+
private checkpointL1InclusionDelay: Histogram;
|
|
45
|
+
|
|
39
46
|
private log = createLogger('archiver:instrumentation');
|
|
40
47
|
|
|
41
48
|
private constructor(
|
|
@@ -47,6 +54,8 @@ export class ArchiverInstrumentation {
|
|
|
47
54
|
|
|
48
55
|
this.blockHeight = meter.createGauge(Metrics.ARCHIVER_BLOCK_HEIGHT);
|
|
49
56
|
|
|
57
|
+
this.checkpointHeight = meter.createGauge(Metrics.ARCHIVER_CHECKPOINT_HEIGHT);
|
|
58
|
+
|
|
50
59
|
this.l1BlockHeight = meter.createGauge(Metrics.ARCHIVER_L1_BLOCK_HEIGHT);
|
|
51
60
|
|
|
52
61
|
this.txCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_TOTAL_TXS);
|
|
@@ -81,6 +90,8 @@ export class ArchiverInstrumentation {
|
|
|
81
90
|
},
|
|
82
91
|
);
|
|
83
92
|
|
|
93
|
+
this.checkpointL1InclusionDelay = meter.createHistogram(Metrics.ARCHIVER_CHECKPOINT_L1_INCLUSION_DELAY);
|
|
94
|
+
|
|
84
95
|
this.dbMetrics = new LmdbMetrics(
|
|
85
96
|
meter,
|
|
86
97
|
{
|
|
@@ -105,6 +116,7 @@ export class ArchiverInstrumentation {
|
|
|
105
116
|
public processNewBlocks(syncTimePerBlock: number, blocks: L2Block[]) {
|
|
106
117
|
this.syncDurationPerBlock.record(Math.ceil(syncTimePerBlock));
|
|
107
118
|
this.blockHeight.record(Math.max(...blocks.map(b => b.number)));
|
|
119
|
+
this.checkpointHeight.record(Math.max(...blocks.map(b => b.checkpointNumber)));
|
|
108
120
|
this.syncBlockCount.add(blocks.length);
|
|
109
121
|
|
|
110
122
|
for (const block of blocks) {
|
|
@@ -127,8 +139,10 @@ export class ArchiverInstrumentation {
|
|
|
127
139
|
this.pruneDuration.record(Math.ceil(duration));
|
|
128
140
|
}
|
|
129
141
|
|
|
130
|
-
public
|
|
131
|
-
|
|
142
|
+
public updateLastProvenCheckpoint(checkpoint: CheckpointData) {
|
|
143
|
+
const lastBlockNumberInCheckpoint = checkpoint.startBlock + checkpoint.blockCount - 1;
|
|
144
|
+
this.blockHeight.record(lastBlockNumberInCheckpoint, { [Attributes.STATUS]: 'proven' });
|
|
145
|
+
this.checkpointHeight.record(checkpoint.checkpointNumber, { [Attributes.STATUS]: 'proven' });
|
|
132
146
|
}
|
|
133
147
|
|
|
134
148
|
public processProofsVerified(logs: { proverId: string; l2BlockNumber: bigint; delay: bigint }[]) {
|
|
@@ -154,4 +168,17 @@ export class ArchiverInstrumentation {
|
|
|
154
168
|
[Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: usedTrace,
|
|
155
169
|
});
|
|
156
170
|
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
|
|
174
|
+
*/
|
|
175
|
+
public processCheckpointL1Timing(data: {
|
|
176
|
+
slotNumber: SlotNumber;
|
|
177
|
+
l1Timestamp: bigint;
|
|
178
|
+
l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>;
|
|
179
|
+
}): void {
|
|
180
|
+
const slotStartTs = getTimestampForSlot(data.slotNumber, data.l1Constants);
|
|
181
|
+
const inclusionDelaySeconds = Number(data.l1Timestamp - slotStartTs);
|
|
182
|
+
this.checkpointL1InclusionDelay.record(inclusionDelaySeconds);
|
|
183
|
+
}
|
|
157
184
|
}
|