@aztec/archiver 0.0.1-commit.fffb133c → 0.0.1-dev
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 +9 -5
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +87 -111
- package/dest/errors.d.ts +7 -9
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +9 -14
- package/dest/factory.d.ts +4 -3
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +32 -26
- 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 +4 -7
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +10 -14
- 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/validate_trace.d.ts +6 -3
- package/dest/l1/validate_trace.d.ts.map +1 -1
- package/dest/l1/validate_trace.js +13 -9
- package/dest/modules/data_source_base.d.ts +13 -8
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +29 -73
- package/dest/modules/data_store_updater.d.ts +22 -7
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +114 -40
- package/dest/modules/instrumentation.d.ts +4 -2
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +26 -12
- 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 +42 -13
- package/dest/store/block_store.d.ts +38 -29
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +294 -85
- 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 +27 -7
- package/dest/store/contract_instance_store.d.ts +1 -1
- package/dest/store/contract_instance_store.d.ts.map +1 -1
- package/dest/store/contract_instance_store.js +17 -2
- package/dest/store/kv_archiver_store.d.ts +40 -18
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +44 -16
- package/dest/store/l2_tips_cache.d.ts +18 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +20 -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 +125 -56
- package/dest/store/message_store.js +1 -1
- package/dest/test/fake_l1_state.d.ts +20 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +97 -20
- package/dest/test/index.js +3 -1
- 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 +25 -9
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +133 -87
- package/dest/test/mock_structs.d.ts +6 -2
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +20 -6
- package/dest/test/noop_l1_archiver.d.ts +26 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +72 -0
- package/package.json +14 -13
- package/src/archiver.ts +110 -132
- package/src/errors.ts +10 -24
- package/src/factory.ts +47 -23
- 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 +7 -17
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_trace.ts +24 -6
- package/src/modules/data_source_base.ts +59 -98
- package/src/modules/data_store_updater.ts +124 -43
- package/src/modules/instrumentation.ts +24 -12
- package/src/modules/l1_synchronizer.ts +49 -17
- package/src/store/block_store.ts +359 -115
- package/src/store/contract_class_store.ts +27 -7
- package/src/store/contract_instance_store.ts +19 -5
- package/src/store/kv_archiver_store.ts +71 -25
- package/src/store/l2_tips_cache.ts +27 -0
- package/src/store/log_store.ts +186 -57
- package/src/store/message_store.ts +1 -1
- package/src/test/fake_l1_state.ts +125 -21
- package/src/test/index.ts +3 -0
- package/src/test/mock_archiver.ts +3 -2
- package/src/test/mock_l2_block_source.ts +179 -87
- package/src/test/mock_structs.ts +42 -12
- package/src/test/noop_l1_archiver.ts +115 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { filterAsync } from '@aztec/foundation/collection';
|
|
2
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
5
|
import {
|
|
@@ -11,11 +12,13 @@ import {
|
|
|
11
12
|
ContractInstanceUpdatedEvent,
|
|
12
13
|
} from '@aztec/protocol-contracts/instance-registry';
|
|
13
14
|
import type { L2Block, ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
14
|
-
import type
|
|
15
|
+
import { type PublishedCheckpoint, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
15
16
|
import {
|
|
17
|
+
type ContractClassPublicWithCommitment,
|
|
16
18
|
type ExecutablePrivateFunctionWithMembershipProof,
|
|
17
19
|
type UtilityFunctionWithMembershipProof,
|
|
18
|
-
|
|
20
|
+
computeContractAddressFromInstance,
|
|
21
|
+
computeContractClassId,
|
|
19
22
|
isValidPrivateFunctionMembershipProof,
|
|
20
23
|
isValidUtilityFunctionMembershipProof,
|
|
21
24
|
} from '@aztec/stdlib/contract';
|
|
@@ -25,6 +28,7 @@ import type { UInt64 } from '@aztec/stdlib/types';
|
|
|
25
28
|
import groupBy from 'lodash.groupby';
|
|
26
29
|
|
|
27
30
|
import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
|
|
31
|
+
import type { L2TipsCache } from '../store/l2_tips_cache.js';
|
|
28
32
|
|
|
29
33
|
/** Operation type for contract data updates. */
|
|
30
34
|
enum Operation {
|
|
@@ -44,36 +48,42 @@ type ReconcileCheckpointsResult = {
|
|
|
44
48
|
export class ArchiverDataStoreUpdater {
|
|
45
49
|
private readonly log = createLogger('archiver:store_updater');
|
|
46
50
|
|
|
47
|
-
constructor(
|
|
51
|
+
constructor(
|
|
52
|
+
private store: KVArchiverDataStore,
|
|
53
|
+
private l2TipsCache?: L2TipsCache,
|
|
54
|
+
private opts: { rollupManaLimit?: number } = {},
|
|
55
|
+
) {}
|
|
48
56
|
|
|
49
57
|
/**
|
|
50
|
-
* Adds proposed
|
|
51
|
-
*
|
|
58
|
+
* Adds a proposed block to the store with contract class/instance extraction from logs.
|
|
59
|
+
* This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
52
60
|
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
|
|
53
61
|
* and individually broadcasted functions from the block logs.
|
|
54
62
|
*
|
|
55
|
-
* @param
|
|
63
|
+
* @param block - The proposed L2 block to add.
|
|
56
64
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
57
65
|
* @returns True if the operation is successful.
|
|
58
66
|
*/
|
|
59
|
-
public
|
|
60
|
-
|
|
67
|
+
public async addProposedBlock(
|
|
68
|
+
block: L2Block,
|
|
61
69
|
pendingChainValidationStatus?: ValidateCheckpointResult,
|
|
62
70
|
): Promise<boolean> {
|
|
63
|
-
|
|
64
|
-
await this.store.
|
|
71
|
+
const result = await this.store.transactionAsync(async () => {
|
|
72
|
+
await this.store.addProposedBlock(block);
|
|
65
73
|
|
|
66
74
|
const opResults = await Promise.all([
|
|
67
75
|
// Update the pending chain validation status if provided
|
|
68
76
|
pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
|
|
69
|
-
// Add any logs emitted during the retrieved
|
|
70
|
-
this.store.addLogs(
|
|
71
|
-
// Unroll all logs emitted during the retrieved
|
|
72
|
-
|
|
77
|
+
// Add any logs emitted during the retrieved block
|
|
78
|
+
this.store.addLogs([block]),
|
|
79
|
+
// Unroll all logs emitted during the retrieved block and extract any contract classes and instances from it
|
|
80
|
+
this.addContractDataToDb(block),
|
|
73
81
|
]);
|
|
74
82
|
|
|
75
83
|
return opResults.every(Boolean);
|
|
76
84
|
});
|
|
85
|
+
await this.l2TipsCache?.refresh();
|
|
86
|
+
return result;
|
|
77
87
|
}
|
|
78
88
|
|
|
79
89
|
/**
|
|
@@ -87,17 +97,21 @@ export class ArchiverDataStoreUpdater {
|
|
|
87
97
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
88
98
|
* @returns Result with information about any pruned blocks.
|
|
89
99
|
*/
|
|
90
|
-
public addCheckpoints(
|
|
100
|
+
public async addCheckpoints(
|
|
91
101
|
checkpoints: PublishedCheckpoint[],
|
|
92
102
|
pendingChainValidationStatus?: ValidateCheckpointResult,
|
|
93
103
|
): Promise<ReconcileCheckpointsResult> {
|
|
94
|
-
|
|
104
|
+
for (const checkpoint of checkpoints) {
|
|
105
|
+
validateCheckpoint(checkpoint.checkpoint, { rollupManaLimit: this.opts?.rollupManaLimit });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const result = await this.store.transactionAsync(async () => {
|
|
95
109
|
// Before adding checkpoints, check for conflicts with local blocks if any
|
|
96
110
|
const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
|
|
97
111
|
|
|
98
112
|
await this.store.addCheckpoints(checkpoints);
|
|
99
113
|
|
|
100
|
-
// Filter out blocks that were already inserted via
|
|
114
|
+
// Filter out blocks that were already inserted via addProposedBlock() to avoid duplicating logs/contract data
|
|
101
115
|
const newBlocks = checkpoints
|
|
102
116
|
.flatMap((ch: PublishedCheckpoint) => ch.checkpoint.blocks)
|
|
103
117
|
.filter(b => lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
|
|
@@ -113,6 +127,8 @@ export class ArchiverDataStoreUpdater {
|
|
|
113
127
|
|
|
114
128
|
return { prunedBlocks, lastAlreadyInsertedBlockNumber };
|
|
115
129
|
});
|
|
130
|
+
await this.l2TipsCache?.refresh();
|
|
131
|
+
return result;
|
|
116
132
|
}
|
|
117
133
|
|
|
118
134
|
/**
|
|
@@ -165,7 +181,7 @@ export class ArchiverDataStoreUpdater {
|
|
|
165
181
|
this.log.verbose(`Block number ${blockNumber} already inserted and matches checkpoint`, blockInfos);
|
|
166
182
|
lastAlreadyInsertedBlockNumber = blockNumber;
|
|
167
183
|
} else {
|
|
168
|
-
this.log.
|
|
184
|
+
this.log.info(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
|
|
169
185
|
const prunedBlocks = await this.removeBlocksAfter(BlockNumber(blockNumber - 1));
|
|
170
186
|
return { prunedBlocks, lastAlreadyInsertedBlockNumber };
|
|
171
187
|
}
|
|
@@ -197,8 +213,8 @@ export class ArchiverDataStoreUpdater {
|
|
|
197
213
|
* @returns The removed blocks.
|
|
198
214
|
* @throws Error if any block to be removed is checkpointed.
|
|
199
215
|
*/
|
|
200
|
-
public removeUncheckpointedBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]> {
|
|
201
|
-
|
|
216
|
+
public async removeUncheckpointedBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]> {
|
|
217
|
+
const result = await this.store.transactionAsync(async () => {
|
|
202
218
|
// Verify we're only removing uncheckpointed blocks
|
|
203
219
|
const lastCheckpointedBlockNumber = await this.store.getCheckpointedL2BlockNumber();
|
|
204
220
|
if (blockNumber < lastCheckpointedBlockNumber) {
|
|
@@ -207,8 +223,11 @@ export class ArchiverDataStoreUpdater {
|
|
|
207
223
|
);
|
|
208
224
|
}
|
|
209
225
|
|
|
210
|
-
|
|
226
|
+
const result = await this.removeBlocksAfter(blockNumber);
|
|
227
|
+
return result;
|
|
211
228
|
});
|
|
229
|
+
await this.l2TipsCache?.refresh();
|
|
230
|
+
return result;
|
|
212
231
|
}
|
|
213
232
|
|
|
214
233
|
/**
|
|
@@ -238,17 +257,43 @@ export class ArchiverDataStoreUpdater {
|
|
|
238
257
|
* @returns True if the operation is successful.
|
|
239
258
|
*/
|
|
240
259
|
public async removeCheckpointsAfter(checkpointNumber: CheckpointNumber): Promise<boolean> {
|
|
241
|
-
const
|
|
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
|
-
]);
|
|
260
|
+
const result = await this.store.transactionAsync(async () => {
|
|
261
|
+
const { blocksRemoved = [] } = await this.store.removeCheckpointsAfter(checkpointNumber);
|
|
250
262
|
|
|
251
|
-
|
|
263
|
+
const opResults = await Promise.all([
|
|
264
|
+
// Prune rolls back to the last proven block, which is by definition valid
|
|
265
|
+
this.store.setPendingChainValidationStatus({ valid: true }),
|
|
266
|
+
// Remove contract data for all blocks being removed
|
|
267
|
+
...blocksRemoved.map(block => this.removeContractDataFromDb(block)),
|
|
268
|
+
this.store.deleteLogs(blocksRemoved),
|
|
269
|
+
]);
|
|
270
|
+
|
|
271
|
+
return opResults.every(Boolean);
|
|
272
|
+
});
|
|
273
|
+
await this.l2TipsCache?.refresh();
|
|
274
|
+
return result;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Updates the proven checkpoint number and refreshes the L2 tips cache.
|
|
279
|
+
* @param checkpointNumber - The checkpoint number to set as proven.
|
|
280
|
+
*/
|
|
281
|
+
public async setProvenCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<void> {
|
|
282
|
+
await this.store.transactionAsync(async () => {
|
|
283
|
+
await this.store.setProvenCheckpointNumber(checkpointNumber);
|
|
284
|
+
});
|
|
285
|
+
await this.l2TipsCache?.refresh();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Updates the finalized checkpoint number and refreshes the L2 tips cache.
|
|
290
|
+
* @param checkpointNumber - The checkpoint number to set as finalized.
|
|
291
|
+
*/
|
|
292
|
+
public async setFinalizedCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<void> {
|
|
293
|
+
await this.store.transactionAsync(async () => {
|
|
294
|
+
await this.store.setFinalizedCheckpointNumber(checkpointNumber);
|
|
295
|
+
});
|
|
296
|
+
await this.l2TipsCache?.refresh();
|
|
252
297
|
}
|
|
253
298
|
|
|
254
299
|
/** Extracts and stores contract data from a single block. */
|
|
@@ -291,18 +336,37 @@ export class ArchiverDataStoreUpdater {
|
|
|
291
336
|
.filter(log => ContractClassPublishedEvent.isContractClassPublishedEvent(log))
|
|
292
337
|
.map(log => ContractClassPublishedEvent.fromLog(log));
|
|
293
338
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
contractClasses.
|
|
297
|
-
|
|
298
|
-
// TODO: Will probably want to create some worker threads to compute these bytecode commitments as they are expensive
|
|
299
|
-
const commitments = await Promise.all(
|
|
300
|
-
contractClasses.map(c => computePublicBytecodeCommitment(c.packedBytecode)),
|
|
301
|
-
);
|
|
302
|
-
return await this.store.addContractClasses(contractClasses, commitments, blockNum);
|
|
303
|
-
} else if (operation == Operation.Delete) {
|
|
339
|
+
if (operation == Operation.Delete) {
|
|
340
|
+
const contractClasses = contractClassPublishedEvents.map(e => e.toContractClassPublic());
|
|
341
|
+
if (contractClasses.length > 0) {
|
|
342
|
+
contractClasses.forEach(c => this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
304
343
|
return await this.store.deleteContractClasses(contractClasses, blockNum);
|
|
305
344
|
}
|
|
345
|
+
return true;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Compute bytecode commitments and validate class IDs in a single pass.
|
|
349
|
+
const contractClasses: ContractClassPublicWithCommitment[] = [];
|
|
350
|
+
for (const event of contractClassPublishedEvents) {
|
|
351
|
+
const contractClass = await event.toContractClassPublicWithBytecodeCommitment();
|
|
352
|
+
const computedClassId = await computeContractClassId({
|
|
353
|
+
artifactHash: contractClass.artifactHash,
|
|
354
|
+
privateFunctionsRoot: contractClass.privateFunctionsRoot,
|
|
355
|
+
publicBytecodeCommitment: contractClass.publicBytecodeCommitment,
|
|
356
|
+
});
|
|
357
|
+
if (!computedClassId.equals(contractClass.id)) {
|
|
358
|
+
this.log.warn(
|
|
359
|
+
`Skipping contract class with mismatched id at block ${blockNum}. Claimed ${contractClass.id}, computed ${computedClassId}`,
|
|
360
|
+
{ blockNum, contractClassId: event.contractClassId.toString() },
|
|
361
|
+
);
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
contractClasses.push(contractClass);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (contractClasses.length > 0) {
|
|
368
|
+
contractClasses.forEach(c => this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
369
|
+
return await this.store.addContractClasses(contractClasses, blockNum);
|
|
306
370
|
}
|
|
307
371
|
return true;
|
|
308
372
|
}
|
|
@@ -315,10 +379,27 @@ export class ArchiverDataStoreUpdater {
|
|
|
315
379
|
blockNum: BlockNumber,
|
|
316
380
|
operation: Operation,
|
|
317
381
|
): Promise<boolean> {
|
|
318
|
-
const
|
|
382
|
+
const allInstances = allLogs
|
|
319
383
|
.filter(log => ContractInstancePublishedEvent.isContractInstancePublishedEvent(log))
|
|
320
384
|
.map(log => ContractInstancePublishedEvent.fromLog(log))
|
|
321
385
|
.map(e => e.toContractInstance());
|
|
386
|
+
|
|
387
|
+
// Verify that each instance's address matches the one derived from its fields if we're adding
|
|
388
|
+
const contractInstances =
|
|
389
|
+
operation === Operation.Delete
|
|
390
|
+
? allInstances
|
|
391
|
+
: await filterAsync(allInstances, async instance => {
|
|
392
|
+
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
393
|
+
if (!computedAddress.equals(instance.address)) {
|
|
394
|
+
this.log.warn(
|
|
395
|
+
`Found contract instance with mismatched address at block ${blockNum}. Claimed ${instance.address} but computed ${computedAddress}.`,
|
|
396
|
+
{ instanceAddress: instance.address.toString(), computedAddress: computedAddress.toString(), blockNum },
|
|
397
|
+
);
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
return true;
|
|
401
|
+
});
|
|
402
|
+
|
|
322
403
|
if (contractInstances.length > 0) {
|
|
323
404
|
contractInstances.forEach(c =>
|
|
324
405
|
this.log.verbose(`${Operation[operation]} contract instance at ${c.address.toString()}`),
|
|
@@ -416,7 +497,7 @@ export class ArchiverDataStoreUpdater {
|
|
|
416
497
|
if (validFnCount > 0) {
|
|
417
498
|
this.log.verbose(`Storing ${validFnCount} functions for contract class ${contractClassId.toString()}`);
|
|
418
499
|
}
|
|
419
|
-
|
|
500
|
+
await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
|
|
420
501
|
}
|
|
421
502
|
return true;
|
|
422
503
|
}
|
|
@@ -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,
|
|
@@ -10,12 +11,14 @@ import {
|
|
|
10
11
|
type TelemetryClient,
|
|
11
12
|
type Tracer,
|
|
12
13
|
type UpDownCounter,
|
|
14
|
+
createUpDownCounterWithDefault,
|
|
13
15
|
} from '@aztec/telemetry-client';
|
|
14
16
|
|
|
15
17
|
export class ArchiverInstrumentation {
|
|
16
18
|
public readonly tracer: Tracer;
|
|
17
19
|
|
|
18
20
|
private blockHeight: Gauge;
|
|
21
|
+
private checkpointHeight: Gauge;
|
|
19
22
|
private txCount: UpDownCounter;
|
|
20
23
|
private l1BlockHeight: Gauge;
|
|
21
24
|
private proofsSubmittedDelay: Histogram;
|
|
@@ -46,17 +49,21 @@ export class ArchiverInstrumentation {
|
|
|
46
49
|
|
|
47
50
|
this.blockHeight = meter.createGauge(Metrics.ARCHIVER_BLOCK_HEIGHT);
|
|
48
51
|
|
|
52
|
+
this.checkpointHeight = meter.createGauge(Metrics.ARCHIVER_CHECKPOINT_HEIGHT);
|
|
53
|
+
|
|
49
54
|
this.l1BlockHeight = meter.createGauge(Metrics.ARCHIVER_L1_BLOCK_HEIGHT);
|
|
50
55
|
|
|
51
|
-
this.txCount = meter
|
|
56
|
+
this.txCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_TOTAL_TXS);
|
|
52
57
|
|
|
53
|
-
this.proofsSubmittedCount = meter
|
|
58
|
+
this.proofsSubmittedCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_ROLLUP_PROOF_COUNT, {
|
|
59
|
+
[Attributes.PROOF_TIMED_OUT]: [true, false],
|
|
60
|
+
});
|
|
54
61
|
|
|
55
62
|
this.proofsSubmittedDelay = meter.createHistogram(Metrics.ARCHIVER_ROLLUP_PROOF_DELAY);
|
|
56
63
|
|
|
57
64
|
this.syncDurationPerBlock = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_BLOCK);
|
|
58
65
|
|
|
59
|
-
this.syncBlockCount = meter
|
|
66
|
+
this.syncBlockCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_BLOCK_COUNT);
|
|
60
67
|
|
|
61
68
|
this.manaPerBlock = meter.createHistogram(Metrics.ARCHIVER_MANA_PER_BLOCK);
|
|
62
69
|
|
|
@@ -64,13 +71,19 @@ export class ArchiverInstrumentation {
|
|
|
64
71
|
|
|
65
72
|
this.syncDurationPerMessage = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_MESSAGE);
|
|
66
73
|
|
|
67
|
-
this.syncMessageCount = meter
|
|
74
|
+
this.syncMessageCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_MESSAGE_COUNT);
|
|
68
75
|
|
|
69
76
|
this.pruneDuration = meter.createHistogram(Metrics.ARCHIVER_PRUNE_DURATION);
|
|
70
77
|
|
|
71
|
-
this.pruneCount = meter
|
|
78
|
+
this.pruneCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_PRUNE_COUNT);
|
|
72
79
|
|
|
73
|
-
this.blockProposalTxTargetCount =
|
|
80
|
+
this.blockProposalTxTargetCount = createUpDownCounterWithDefault(
|
|
81
|
+
meter,
|
|
82
|
+
Metrics.ARCHIVER_BLOCK_PROPOSAL_TX_TARGET_COUNT,
|
|
83
|
+
{
|
|
84
|
+
[Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: [true, false],
|
|
85
|
+
},
|
|
86
|
+
);
|
|
74
87
|
|
|
75
88
|
this.dbMetrics = new LmdbMetrics(
|
|
76
89
|
meter,
|
|
@@ -84,10 +97,6 @@ export class ArchiverInstrumentation {
|
|
|
84
97
|
public static async new(telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback) {
|
|
85
98
|
const instance = new ArchiverInstrumentation(telemetry, lmdbStats);
|
|
86
99
|
|
|
87
|
-
instance.syncBlockCount.add(0);
|
|
88
|
-
instance.syncMessageCount.add(0);
|
|
89
|
-
instance.pruneCount.add(0);
|
|
90
|
-
|
|
91
100
|
await instance.telemetry.flush();
|
|
92
101
|
|
|
93
102
|
return instance;
|
|
@@ -100,6 +109,7 @@ export class ArchiverInstrumentation {
|
|
|
100
109
|
public processNewBlocks(syncTimePerBlock: number, blocks: L2Block[]) {
|
|
101
110
|
this.syncDurationPerBlock.record(Math.ceil(syncTimePerBlock));
|
|
102
111
|
this.blockHeight.record(Math.max(...blocks.map(b => b.number)));
|
|
112
|
+
this.checkpointHeight.record(Math.max(...blocks.map(b => b.checkpointNumber)));
|
|
103
113
|
this.syncBlockCount.add(blocks.length);
|
|
104
114
|
|
|
105
115
|
for (const block of blocks) {
|
|
@@ -122,8 +132,10 @@ export class ArchiverInstrumentation {
|
|
|
122
132
|
this.pruneDuration.record(Math.ceil(duration));
|
|
123
133
|
}
|
|
124
134
|
|
|
125
|
-
public
|
|
126
|
-
|
|
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' });
|
|
127
139
|
}
|
|
128
140
|
|
|
129
141
|
public processProofsVerified(logs: { proverId: string; l2BlockNumber: bigint; delay: bigint }[]) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
2
2
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
3
3
|
import { InboxContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
4
|
-
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
5
4
|
import type { L1BlockId } from '@aztec/ethereum/l1-types';
|
|
6
5
|
import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
|
|
7
6
|
import { maxBigint } from '@aztec/foundation/bigint';
|
|
@@ -9,14 +8,13 @@ import { BlockNumber, CheckpointNumber, EpochNumber } from '@aztec/foundation/br
|
|
|
9
8
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
10
9
|
import { pick } from '@aztec/foundation/collection';
|
|
11
10
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
12
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
13
11
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
14
12
|
import { count } from '@aztec/foundation/string';
|
|
15
13
|
import { DateProvider, Timer, elapsed } from '@aztec/foundation/timer';
|
|
16
14
|
import { isDefined } from '@aztec/foundation/types';
|
|
17
15
|
import { type ArchiverEmitter, L2BlockSourceEvents, type ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
18
16
|
import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
19
|
-
import { type L1RollupConstants, getEpochAtSlot,
|
|
17
|
+
import { type L1RollupConstants, getEpochAtSlot, getSlotAtNextL1Block } from '@aztec/stdlib/epoch-helpers';
|
|
20
18
|
import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
21
19
|
import { type Traceable, type Tracer, execInSpan, trackSpan } from '@aztec/telemetry-client';
|
|
22
20
|
|
|
@@ -28,6 +26,7 @@ import {
|
|
|
28
26
|
retrievedToPublishedCheckpoint,
|
|
29
27
|
} from '../l1/data_retrieval.js';
|
|
30
28
|
import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
|
|
29
|
+
import type { L2TipsCache } from '../store/l2_tips_cache.js';
|
|
31
30
|
import type { InboxMessage } from '../structs/inbox_message.js';
|
|
32
31
|
import { ArchiverDataStoreUpdater } from './data_store_updater.js';
|
|
33
32
|
import type { ArchiverInstrumentation } from './instrumentation.js';
|
|
@@ -60,10 +59,6 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
60
59
|
private readonly debugClient: ViemPublicDebugClient,
|
|
61
60
|
private readonly rollup: RollupContract,
|
|
62
61
|
private readonly inbox: InboxContract,
|
|
63
|
-
private readonly l1Addresses: Pick<
|
|
64
|
-
L1ContractAddresses,
|
|
65
|
-
'registryAddress' | 'governanceProposerAddress' | 'slashFactoryAddress'
|
|
66
|
-
> & { slashingProposerAddress: EthAddress },
|
|
67
62
|
private readonly store: KVArchiverDataStore,
|
|
68
63
|
private config: {
|
|
69
64
|
batchSize: number;
|
|
@@ -74,12 +69,18 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
74
69
|
private readonly epochCache: EpochCache,
|
|
75
70
|
private readonly dateProvider: DateProvider,
|
|
76
71
|
private readonly instrumentation: ArchiverInstrumentation,
|
|
77
|
-
private readonly l1Constants: L1RollupConstants & {
|
|
72
|
+
private readonly l1Constants: L1RollupConstants & {
|
|
73
|
+
l1StartBlockHash: Buffer32;
|
|
74
|
+
genesisArchiveRoot: Fr;
|
|
75
|
+
},
|
|
78
76
|
private readonly events: ArchiverEmitter,
|
|
79
77
|
tracer: Tracer,
|
|
78
|
+
l2TipsCache?: L2TipsCache,
|
|
80
79
|
private readonly log: Logger = createLogger('archiver:l1-sync'),
|
|
81
80
|
) {
|
|
82
|
-
this.updater = new ArchiverDataStoreUpdater(this.store
|
|
81
|
+
this.updater = new ArchiverDataStoreUpdater(this.store, l2TipsCache, {
|
|
82
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
83
|
+
});
|
|
83
84
|
this.tracer = tracer;
|
|
84
85
|
}
|
|
85
86
|
|
|
@@ -215,6 +216,9 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
215
216
|
this.instrumentation.updateL1BlockHeight(currentL1BlockNumber);
|
|
216
217
|
}
|
|
217
218
|
|
|
219
|
+
// Update the finalized L2 checkpoint based on L1 finality.
|
|
220
|
+
await this.updateFinalizedCheckpoint();
|
|
221
|
+
|
|
218
222
|
// After syncing has completed, update the current l1 block number and timestamp,
|
|
219
223
|
// otherwise we risk announcing to the world that we've synced to a given point,
|
|
220
224
|
// but the corresponding blocks have not been processed (see #12631).
|
|
@@ -230,6 +234,36 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
230
234
|
});
|
|
231
235
|
}
|
|
232
236
|
|
|
237
|
+
/** Query L1 for its finalized block and update the finalized checkpoint accordingly. */
|
|
238
|
+
private async updateFinalizedCheckpoint(): Promise<void> {
|
|
239
|
+
try {
|
|
240
|
+
const finalizedL1Block = await this.publicClient.getBlock({ blockTag: 'finalized', includeTransactions: false });
|
|
241
|
+
const finalizedL1BlockNumber = finalizedL1Block.number;
|
|
242
|
+
const finalizedCheckpointNumber = await this.rollup.getProvenCheckpointNumber({
|
|
243
|
+
blockNumber: finalizedL1BlockNumber,
|
|
244
|
+
});
|
|
245
|
+
const localFinalizedCheckpointNumber = await this.store.getFinalizedCheckpointNumber();
|
|
246
|
+
if (localFinalizedCheckpointNumber !== finalizedCheckpointNumber) {
|
|
247
|
+
await this.updater.setFinalizedCheckpointNumber(finalizedCheckpointNumber);
|
|
248
|
+
const finalizedL2BlockNumber = await this.store.getFinalizedL2BlockNumber();
|
|
249
|
+
this.log.info(
|
|
250
|
+
`Updated finalized chain to checkpoint ${finalizedCheckpointNumber} (L2 block ${finalizedL2BlockNumber})`,
|
|
251
|
+
{
|
|
252
|
+
finalizedCheckpointNumber,
|
|
253
|
+
previousFinalizedCheckpointNumber: localFinalizedCheckpointNumber,
|
|
254
|
+
finalizedL2BlockNumber,
|
|
255
|
+
finalizedL1BlockNumber,
|
|
256
|
+
},
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
} catch (err: any) {
|
|
260
|
+
// The rollup contract may not exist at the finalized L1 block right after deployment.
|
|
261
|
+
if (!err?.message?.includes('returned no data')) {
|
|
262
|
+
this.log.warn(`Failed to update finalized checkpoint: ${err}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
233
267
|
/** Prune all proposed local blocks that should have been checkpointed by now. */
|
|
234
268
|
private async pruneUncheckpointedBlocks(currentL1Timestamp: bigint) {
|
|
235
269
|
const [lastCheckpointedBlockNumber, lastProposedBlockNumber] = await Promise.all([
|
|
@@ -249,8 +283,7 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
249
283
|
const firstUncheckpointedBlockSlot = firstUncheckpointedBlockHeader?.getSlot();
|
|
250
284
|
|
|
251
285
|
// What's the slot at the next L1 block? All blocks for slots strictly before this one should've been checkpointed by now.
|
|
252
|
-
const
|
|
253
|
-
const slotAtNextL1Block = getSlotAtTimestamp(nextL1BlockTimestamp, this.l1Constants);
|
|
286
|
+
const slotAtNextL1Block = getSlotAtNextL1Block(currentL1Timestamp, this.l1Constants);
|
|
254
287
|
|
|
255
288
|
// Prune provisional blocks from slots that have ended without being checkpointed
|
|
256
289
|
if (firstUncheckpointedBlockSlot !== undefined && firstUncheckpointedBlockSlot < slotAtNextL1Block) {
|
|
@@ -551,7 +584,7 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
551
584
|
if (provenCheckpointNumber === 0) {
|
|
552
585
|
const localProvenCheckpointNumber = await this.store.getProvenCheckpointNumber();
|
|
553
586
|
if (localProvenCheckpointNumber !== provenCheckpointNumber) {
|
|
554
|
-
await this.
|
|
587
|
+
await this.updater.setProvenCheckpointNumber(provenCheckpointNumber);
|
|
555
588
|
this.log.info(`Rolled back proven chain to checkpoint ${provenCheckpointNumber}`, { provenCheckpointNumber });
|
|
556
589
|
}
|
|
557
590
|
}
|
|
@@ -583,13 +616,13 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
583
616
|
) {
|
|
584
617
|
const localProvenCheckpointNumber = await this.store.getProvenCheckpointNumber();
|
|
585
618
|
if (localProvenCheckpointNumber !== provenCheckpointNumber) {
|
|
586
|
-
await this.
|
|
619
|
+
await this.updater.setProvenCheckpointNumber(provenCheckpointNumber);
|
|
587
620
|
this.log.info(`Updated proven chain to checkpoint ${provenCheckpointNumber}`, { provenCheckpointNumber });
|
|
588
621
|
const provenSlotNumber = localCheckpointForDestinationProvenCheckpointNumber.header.slotNumber;
|
|
589
622
|
const provenEpochNumber: EpochNumber = getEpochAtSlot(provenSlotNumber, this.l1Constants);
|
|
590
623
|
const lastBlockNumberInCheckpoint =
|
|
591
624
|
localCheckpointForDestinationProvenCheckpointNumber.startBlock +
|
|
592
|
-
localCheckpointForDestinationProvenCheckpointNumber.
|
|
625
|
+
localCheckpointForDestinationProvenCheckpointNumber.blockCount -
|
|
593
626
|
1;
|
|
594
627
|
|
|
595
628
|
this.events.emit(L2BlockSourceEvents.L2BlockProven, {
|
|
@@ -598,7 +631,7 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
598
631
|
slotNumber: provenSlotNumber,
|
|
599
632
|
epochNumber: provenEpochNumber,
|
|
600
633
|
});
|
|
601
|
-
this.instrumentation.
|
|
634
|
+
this.instrumentation.updateLastProvenCheckpoint(localCheckpointForDestinationProvenCheckpointNumber);
|
|
602
635
|
} else {
|
|
603
636
|
this.log.trace(`Proven checkpoint ${provenCheckpointNumber} already stored.`);
|
|
604
637
|
}
|
|
@@ -707,7 +740,6 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
707
740
|
this.blobClient,
|
|
708
741
|
searchStartBlock, // TODO(palla/reorg): If the L2 reorg was due to an L1 reorg, we need to start search earlier
|
|
709
742
|
searchEndBlock,
|
|
710
|
-
this.l1Addresses,
|
|
711
743
|
this.instrumentation,
|
|
712
744
|
this.log,
|
|
713
745
|
!initialSyncComplete, // isHistoricalSync
|
|
@@ -820,7 +852,7 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
820
852
|
const prunedCheckpointNumber = result.prunedBlocks[0].checkpointNumber;
|
|
821
853
|
const prunedSlotNumber = result.prunedBlocks[0].header.globalVariables.slotNumber;
|
|
822
854
|
|
|
823
|
-
this.log.
|
|
855
|
+
this.log.info(
|
|
824
856
|
`Pruned ${result.prunedBlocks.length} mismatching blocks for checkpoint ${prunedCheckpointNumber}`,
|
|
825
857
|
{ prunedBlocks: result.prunedBlocks.map(b => b.toBlockInfo()), prunedSlotNumber, prunedCheckpointNumber },
|
|
826
858
|
);
|