@aztec/archiver 0.0.1-commit.e2b2873ed → 0.0.1-commit.e304674f1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -6
- package/dest/archiver.d.ts +11 -8
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +79 -114
- package/dest/config.d.ts +3 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +2 -1
- package/dest/errors.d.ts +34 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +45 -16
- package/dest/factory.d.ts +4 -5
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +29 -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 +32 -28
- 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 +191 -259
- package/dest/l1/data_retrieval.d.ts +11 -11
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +35 -34
- 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 +14 -7
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +39 -77
- package/dest/modules/data_store_updater.d.ts +25 -12
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +125 -94
- 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 +7 -9
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +176 -136
- package/dest/modules/validation.d.ts +1 -1
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +2 -2
- package/dest/store/block_store.d.ts +66 -28
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +356 -135
- package/dest/store/contract_class_store.d.ts +2 -3
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +7 -67
- 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 +6 -2
- package/dest/store/kv_archiver_store.d.ts +61 -24
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +75 -27
- package/dest/store/l2_tips_cache.d.ts +20 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +109 -0
- package/dest/store/log_store.d.ts +6 -3
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +93 -16
- package/dest/store/message_store.d.ts +5 -1
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +21 -9
- package/dest/test/fake_l1_state.d.ts +21 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +133 -26
- 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_l1_to_l2_message_source.d.ts +1 -1
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +2 -1
- package/dest/test/mock_l2_block_source.d.ts +26 -5
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +160 -89
- package/dest/test/mock_structs.d.ts +4 -1
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +13 -1
- package/dest/test/noop_l1_archiver.d.ts +4 -1
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +5 -2
- package/package.json +13 -13
- package/src/archiver.ts +101 -138
- package/src/config.ts +8 -1
- package/src/errors.ts +70 -26
- package/src/factory.ts +30 -16
- package/src/index.ts +1 -0
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +40 -27
- package/src/l1/calldata_retriever.ts +250 -379
- package/src/l1/data_retrieval.ts +31 -37
- package/src/l1/spire_proposer.ts +7 -15
- package/src/modules/data_source_base.ts +78 -98
- package/src/modules/data_store_updater.ts +138 -124
- package/src/modules/instrumentation.ts +29 -2
- package/src/modules/l1_synchronizer.ts +196 -168
- package/src/modules/validation.ts +2 -2
- package/src/store/block_store.ts +451 -172
- package/src/store/contract_class_store.ts +8 -106
- package/src/store/contract_instance_store.ts +8 -5
- package/src/store/kv_archiver_store.ts +115 -41
- package/src/store/l2_tips_cache.ts +128 -0
- package/src/store/log_store.ts +126 -27
- package/src/store/message_store.ts +27 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +178 -30
- package/src/test/mock_archiver.ts +3 -2
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +209 -82
- package/src/test/mock_structs.ts +20 -6
- package/src/test/noop_l1_archiver.ts +7 -2
|
@@ -1,30 +1,23 @@
|
|
|
1
1
|
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import {
|
|
2
|
+
import { filterAsync } from '@aztec/foundation/collection';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import {
|
|
5
|
-
ContractClassPublishedEvent,
|
|
6
|
-
PrivateFunctionBroadcastedEvent,
|
|
7
|
-
UtilityFunctionBroadcastedEvent,
|
|
8
|
-
} from '@aztec/protocol-contracts/class-registry';
|
|
4
|
+
import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
|
|
9
5
|
import {
|
|
10
6
|
ContractInstancePublishedEvent,
|
|
11
7
|
ContractInstanceUpdatedEvent,
|
|
12
8
|
} from '@aztec/protocol-contracts/instance-registry';
|
|
13
9
|
import type { L2Block, ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
14
|
-
import type
|
|
10
|
+
import { type ProposedCheckpointInput, type PublishedCheckpoint, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
15
11
|
import {
|
|
16
|
-
type
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
isValidPrivateFunctionMembershipProof,
|
|
20
|
-
isValidUtilityFunctionMembershipProof,
|
|
12
|
+
type ContractClassPublicWithCommitment,
|
|
13
|
+
computeContractAddressFromInstance,
|
|
14
|
+
computeContractClassId,
|
|
21
15
|
} from '@aztec/stdlib/contract';
|
|
22
16
|
import type { ContractClassLog, PrivateLog, PublicLog } from '@aztec/stdlib/logs';
|
|
23
17
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
24
18
|
|
|
25
|
-
import groupBy from 'lodash.groupby';
|
|
26
|
-
|
|
27
19
|
import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
|
|
20
|
+
import type { L2TipsCache } from '../store/l2_tips_cache.js';
|
|
28
21
|
|
|
29
22
|
/** Operation type for contract data updates. */
|
|
30
23
|
enum Operation {
|
|
@@ -44,60 +37,68 @@ type ReconcileCheckpointsResult = {
|
|
|
44
37
|
export class ArchiverDataStoreUpdater {
|
|
45
38
|
private readonly log = createLogger('archiver:store_updater');
|
|
46
39
|
|
|
47
|
-
constructor(
|
|
40
|
+
constructor(
|
|
41
|
+
private store: KVArchiverDataStore,
|
|
42
|
+
private l2TipsCache?: L2TipsCache,
|
|
43
|
+
private opts: { rollupManaLimit?: number } = {},
|
|
44
|
+
) {}
|
|
48
45
|
|
|
49
46
|
/**
|
|
50
|
-
* Adds proposed
|
|
51
|
-
*
|
|
52
|
-
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events
|
|
53
|
-
* and individually broadcasted functions from the block logs.
|
|
47
|
+
* Adds a proposed block to the store with contract class/instance extraction from logs.
|
|
48
|
+
* This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
49
|
+
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the block logs.
|
|
54
50
|
*
|
|
55
|
-
* @param
|
|
51
|
+
* @param block - The proposed L2 block to add.
|
|
56
52
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
57
53
|
* @returns True if the operation is successful.
|
|
58
54
|
*/
|
|
59
|
-
public
|
|
60
|
-
|
|
55
|
+
public async addProposedBlock(
|
|
56
|
+
block: L2Block,
|
|
61
57
|
pendingChainValidationStatus?: ValidateCheckpointResult,
|
|
62
58
|
): Promise<boolean> {
|
|
63
|
-
|
|
64
|
-
await this.store.
|
|
59
|
+
const result = await this.store.transactionAsync(async () => {
|
|
60
|
+
await this.store.addProposedBlock(block);
|
|
65
61
|
|
|
66
62
|
const opResults = await Promise.all([
|
|
67
63
|
// Update the pending chain validation status if provided
|
|
68
64
|
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
|
-
|
|
65
|
+
// Add any logs emitted during the retrieved block
|
|
66
|
+
this.store.addLogs([block]),
|
|
67
|
+
// Unroll all logs emitted during the retrieved block and extract any contract classes and instances from it
|
|
68
|
+
this.addContractDataToDb(block),
|
|
73
69
|
]);
|
|
74
70
|
|
|
71
|
+
await this.l2TipsCache?.refresh();
|
|
75
72
|
return opResults.every(Boolean);
|
|
76
73
|
});
|
|
74
|
+
return result;
|
|
77
75
|
}
|
|
78
76
|
|
|
79
77
|
/**
|
|
80
78
|
* Reconciles local blocks with incoming checkpoints from L1.
|
|
81
79
|
* Adds new checkpoints to the store with contract class/instance extraction from logs.
|
|
82
80
|
* Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
|
|
83
|
-
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events
|
|
84
|
-
* and individually broadcasted functions from the checkpoint block logs.
|
|
81
|
+
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the checkpoint block logs.
|
|
85
82
|
*
|
|
86
83
|
* @param checkpoints - The published checkpoints to add.
|
|
87
84
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
88
85
|
* @returns Result with information about any pruned blocks.
|
|
89
86
|
*/
|
|
90
|
-
public addCheckpoints(
|
|
87
|
+
public async addCheckpoints(
|
|
91
88
|
checkpoints: PublishedCheckpoint[],
|
|
92
89
|
pendingChainValidationStatus?: ValidateCheckpointResult,
|
|
93
90
|
): Promise<ReconcileCheckpointsResult> {
|
|
94
|
-
|
|
91
|
+
for (const checkpoint of checkpoints) {
|
|
92
|
+
validateCheckpoint(checkpoint.checkpoint, { rollupManaLimit: this.opts?.rollupManaLimit });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const result = await this.store.transactionAsync(async () => {
|
|
95
96
|
// Before adding checkpoints, check for conflicts with local blocks if any
|
|
96
97
|
const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
|
|
97
98
|
|
|
98
99
|
await this.store.addCheckpoints(checkpoints);
|
|
99
100
|
|
|
100
|
-
// Filter out blocks that were already inserted via
|
|
101
|
+
// Filter out blocks that were already inserted via addProposedBlock() to avoid duplicating logs/contract data
|
|
101
102
|
const newBlocks = checkpoints
|
|
102
103
|
.flatMap((ch: PublishedCheckpoint) => ch.checkpoint.blocks)
|
|
103
104
|
.filter(b => lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
|
|
@@ -111,8 +112,19 @@ export class ArchiverDataStoreUpdater {
|
|
|
111
112
|
...newBlocks.map(block => this.addContractDataToDb(block)),
|
|
112
113
|
]);
|
|
113
114
|
|
|
115
|
+
await this.l2TipsCache?.refresh();
|
|
114
116
|
return { prunedBlocks, lastAlreadyInsertedBlockNumber };
|
|
115
117
|
});
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public async setProposedCheckpoint(proposedCheckpoint: ProposedCheckpointInput) {
|
|
122
|
+
const result = await this.store.transactionAsync(async () => {
|
|
123
|
+
await this.store.setProposedCheckpoint(proposedCheckpoint);
|
|
124
|
+
await this.l2TipsCache?.refresh();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
return result;
|
|
116
128
|
}
|
|
117
129
|
|
|
118
130
|
/**
|
|
@@ -165,7 +177,7 @@ export class ArchiverDataStoreUpdater {
|
|
|
165
177
|
this.log.verbose(`Block number ${blockNumber} already inserted and matches checkpoint`, blockInfos);
|
|
166
178
|
lastAlreadyInsertedBlockNumber = blockNumber;
|
|
167
179
|
} else {
|
|
168
|
-
this.log.
|
|
180
|
+
this.log.info(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
|
|
169
181
|
const prunedBlocks = await this.removeBlocksAfter(BlockNumber(blockNumber - 1));
|
|
170
182
|
return { prunedBlocks, lastAlreadyInsertedBlockNumber };
|
|
171
183
|
}
|
|
@@ -197,8 +209,8 @@ export class ArchiverDataStoreUpdater {
|
|
|
197
209
|
* @returns The removed blocks.
|
|
198
210
|
* @throws Error if any block to be removed is checkpointed.
|
|
199
211
|
*/
|
|
200
|
-
public removeUncheckpointedBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]> {
|
|
201
|
-
|
|
212
|
+
public async removeUncheckpointedBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]> {
|
|
213
|
+
const result = await this.store.transactionAsync(async () => {
|
|
202
214
|
// Verify we're only removing uncheckpointed blocks
|
|
203
215
|
const lastCheckpointedBlockNumber = await this.store.getCheckpointedL2BlockNumber();
|
|
204
216
|
if (blockNumber < lastCheckpointedBlockNumber) {
|
|
@@ -207,8 +219,15 @@ export class ArchiverDataStoreUpdater {
|
|
|
207
219
|
);
|
|
208
220
|
}
|
|
209
221
|
|
|
210
|
-
|
|
222
|
+
const result = await this.removeBlocksAfter(blockNumber);
|
|
223
|
+
|
|
224
|
+
// Clear the proposed checkpoint if it exists, since its blocks have been pruned
|
|
225
|
+
await this.store.deleteProposedCheckpoint();
|
|
226
|
+
|
|
227
|
+
await this.l2TipsCache?.refresh();
|
|
228
|
+
return result;
|
|
211
229
|
});
|
|
230
|
+
return result;
|
|
212
231
|
}
|
|
213
232
|
|
|
214
233
|
/**
|
|
@@ -238,17 +257,42 @@ export class ArchiverDataStoreUpdater {
|
|
|
238
257
|
* @returns True if the operation is successful.
|
|
239
258
|
*/
|
|
240
259
|
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
|
-
]);
|
|
260
|
+
return 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
|
+
await this.l2TipsCache?.refresh();
|
|
272
|
+
return opResults.every(Boolean);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Updates the proven checkpoint number and refreshes the L2 tips cache.
|
|
278
|
+
* @param checkpointNumber - The checkpoint number to set as proven.
|
|
279
|
+
*/
|
|
280
|
+
public async setProvenCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<void> {
|
|
281
|
+
await this.store.transactionAsync(async () => {
|
|
282
|
+
await this.store.setProvenCheckpointNumber(checkpointNumber);
|
|
283
|
+
await this.l2TipsCache?.refresh();
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Updates the finalized checkpoint number and refreshes the L2 tips cache.
|
|
289
|
+
* @param checkpointNumber - The checkpoint number to set as finalized.
|
|
290
|
+
*/
|
|
291
|
+
public async setFinalizedCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<void> {
|
|
292
|
+
await this.store.transactionAsync(async () => {
|
|
293
|
+
await this.store.setFinalizedCheckpointNumber(checkpointNumber);
|
|
294
|
+
await this.l2TipsCache?.refresh();
|
|
295
|
+
});
|
|
252
296
|
}
|
|
253
297
|
|
|
254
298
|
/** Extracts and stores contract data from a single block. */
|
|
@@ -272,9 +316,6 @@ export class ArchiverDataStoreUpdater {
|
|
|
272
316
|
this.updatePublishedContractClasses(contractClassLogs, block.number, operation),
|
|
273
317
|
this.updateDeployedContractInstances(privateLogs, block.number, operation),
|
|
274
318
|
this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation),
|
|
275
|
-
operation === Operation.Store
|
|
276
|
-
? this.storeBroadcastedIndividualFunctions(contractClassLogs, block.number)
|
|
277
|
-
: Promise.resolve(true),
|
|
278
319
|
])
|
|
279
320
|
).every(Boolean);
|
|
280
321
|
}
|
|
@@ -291,18 +332,37 @@ export class ArchiverDataStoreUpdater {
|
|
|
291
332
|
.filter(log => ContractClassPublishedEvent.isContractClassPublishedEvent(log))
|
|
292
333
|
.map(log => ContractClassPublishedEvent.fromLog(log));
|
|
293
334
|
|
|
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) {
|
|
335
|
+
if (operation == Operation.Delete) {
|
|
336
|
+
const contractClasses = contractClassPublishedEvents.map(e => e.toContractClassPublic());
|
|
337
|
+
if (contractClasses.length > 0) {
|
|
338
|
+
contractClasses.forEach(c => this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
304
339
|
return await this.store.deleteContractClasses(contractClasses, blockNum);
|
|
305
340
|
}
|
|
341
|
+
return true;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Compute bytecode commitments and validate class IDs in a single pass.
|
|
345
|
+
const contractClasses: ContractClassPublicWithCommitment[] = [];
|
|
346
|
+
for (const event of contractClassPublishedEvents) {
|
|
347
|
+
const contractClass = await event.toContractClassPublicWithBytecodeCommitment();
|
|
348
|
+
const computedClassId = await computeContractClassId({
|
|
349
|
+
artifactHash: contractClass.artifactHash,
|
|
350
|
+
privateFunctionsRoot: contractClass.privateFunctionsRoot,
|
|
351
|
+
publicBytecodeCommitment: contractClass.publicBytecodeCommitment,
|
|
352
|
+
});
|
|
353
|
+
if (!computedClassId.equals(contractClass.id)) {
|
|
354
|
+
this.log.warn(
|
|
355
|
+
`Skipping contract class with mismatched id at block ${blockNum}. Claimed ${contractClass.id}, computed ${computedClassId}`,
|
|
356
|
+
{ blockNum, contractClassId: event.contractClassId.toString() },
|
|
357
|
+
);
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
contractClasses.push(contractClass);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (contractClasses.length > 0) {
|
|
364
|
+
contractClasses.forEach(c => this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
365
|
+
return await this.store.addContractClasses(contractClasses, blockNum);
|
|
306
366
|
}
|
|
307
367
|
return true;
|
|
308
368
|
}
|
|
@@ -315,10 +375,27 @@ export class ArchiverDataStoreUpdater {
|
|
|
315
375
|
blockNum: BlockNumber,
|
|
316
376
|
operation: Operation,
|
|
317
377
|
): Promise<boolean> {
|
|
318
|
-
const
|
|
378
|
+
const allInstances = allLogs
|
|
319
379
|
.filter(log => ContractInstancePublishedEvent.isContractInstancePublishedEvent(log))
|
|
320
380
|
.map(log => ContractInstancePublishedEvent.fromLog(log))
|
|
321
381
|
.map(e => e.toContractInstance());
|
|
382
|
+
|
|
383
|
+
// Verify that each instance's address matches the one derived from its fields if we're adding
|
|
384
|
+
const contractInstances =
|
|
385
|
+
operation === Operation.Delete
|
|
386
|
+
? allInstances
|
|
387
|
+
: await filterAsync(allInstances, async instance => {
|
|
388
|
+
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
389
|
+
if (!computedAddress.equals(instance.address)) {
|
|
390
|
+
this.log.warn(
|
|
391
|
+
`Found contract instance with mismatched address at block ${blockNum}. Claimed ${instance.address} but computed ${computedAddress}.`,
|
|
392
|
+
{ instanceAddress: instance.address.toString(), computedAddress: computedAddress.toString(), blockNum },
|
|
393
|
+
);
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
return true;
|
|
397
|
+
});
|
|
398
|
+
|
|
322
399
|
if (contractInstances.length > 0) {
|
|
323
400
|
contractInstances.forEach(c =>
|
|
324
401
|
this.log.verbose(`${Operation[operation]} contract instance at ${c.address.toString()}`),
|
|
@@ -357,67 +434,4 @@ export class ArchiverDataStoreUpdater {
|
|
|
357
434
|
}
|
|
358
435
|
return true;
|
|
359
436
|
}
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* Stores the functions that were broadcasted individually.
|
|
363
|
-
*
|
|
364
|
-
* @dev Beware that there is not a delete variant of this, since they are added to contract classes
|
|
365
|
-
* and will be deleted as part of the class if needed.
|
|
366
|
-
*/
|
|
367
|
-
private async storeBroadcastedIndividualFunctions(
|
|
368
|
-
allLogs: ContractClassLog[],
|
|
369
|
-
_blockNum: BlockNumber,
|
|
370
|
-
): Promise<boolean> {
|
|
371
|
-
// Filter out private and utility function broadcast events
|
|
372
|
-
const privateFnEvents = allLogs
|
|
373
|
-
.filter(log => PrivateFunctionBroadcastedEvent.isPrivateFunctionBroadcastedEvent(log))
|
|
374
|
-
.map(log => PrivateFunctionBroadcastedEvent.fromLog(log));
|
|
375
|
-
const utilityFnEvents = allLogs
|
|
376
|
-
.filter(log => UtilityFunctionBroadcastedEvent.isUtilityFunctionBroadcastedEvent(log))
|
|
377
|
-
.map(log => UtilityFunctionBroadcastedEvent.fromLog(log));
|
|
378
|
-
|
|
379
|
-
// Group all events by contract class id
|
|
380
|
-
for (const [classIdString, classEvents] of Object.entries(
|
|
381
|
-
groupBy([...privateFnEvents, ...utilityFnEvents], e => e.contractClassId.toString()),
|
|
382
|
-
)) {
|
|
383
|
-
const contractClassId = Fr.fromHexString(classIdString);
|
|
384
|
-
const contractClass = await this.store.getContractClass(contractClassId);
|
|
385
|
-
if (!contractClass) {
|
|
386
|
-
this.log.warn(`Skipping broadcasted functions as contract class ${contractClassId.toString()} was not found`);
|
|
387
|
-
continue;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
// Split private and utility functions, and filter out invalid ones
|
|
391
|
-
const allFns = classEvents.map(e => e.toFunctionWithMembershipProof());
|
|
392
|
-
const privateFns = allFns.filter(
|
|
393
|
-
(fn): fn is ExecutablePrivateFunctionWithMembershipProof => 'utilityFunctionsTreeRoot' in fn,
|
|
394
|
-
);
|
|
395
|
-
const utilityFns = allFns.filter(
|
|
396
|
-
(fn): fn is UtilityFunctionWithMembershipProof => 'privateFunctionsArtifactTreeRoot' in fn,
|
|
397
|
-
);
|
|
398
|
-
|
|
399
|
-
const privateFunctionsWithValidity = await Promise.all(
|
|
400
|
-
privateFns.map(async fn => ({ fn, valid: await isValidPrivateFunctionMembershipProof(fn, contractClass) })),
|
|
401
|
-
);
|
|
402
|
-
const validPrivateFns = privateFunctionsWithValidity.filter(({ valid }) => valid).map(({ fn }) => fn);
|
|
403
|
-
const utilityFunctionsWithValidity = await Promise.all(
|
|
404
|
-
utilityFns.map(async fn => ({
|
|
405
|
-
fn,
|
|
406
|
-
valid: await isValidUtilityFunctionMembershipProof(fn, contractClass),
|
|
407
|
-
})),
|
|
408
|
-
);
|
|
409
|
-
const validUtilityFns = utilityFunctionsWithValidity.filter(({ valid }) => valid).map(({ fn }) => fn);
|
|
410
|
-
const validFnCount = validPrivateFns.length + validUtilityFns.length;
|
|
411
|
-
if (validFnCount !== allFns.length) {
|
|
412
|
-
this.log.warn(`Skipping ${allFns.length - validFnCount} invalid functions`);
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
// Store the functions in the contract class in a single operation
|
|
416
|
-
if (validFnCount > 0) {
|
|
417
|
-
this.log.verbose(`Storing ${validFnCount} functions for contract class ${contractClassId.toString()}`);
|
|
418
|
-
}
|
|
419
|
-
return await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
|
|
420
|
-
}
|
|
421
|
-
return true;
|
|
422
|
-
}
|
|
423
437
|
}
|
|
@@ -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
|
}
|