@aztec/archiver 0.0.1-commit.5de5ca79e → 0.0.1-commit.6201a7b05
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 +16 -7
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +104 -48
- package/dest/config.d.ts +3 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +14 -3
- package/dest/errors.d.ts +41 -2
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +62 -1
- package/dest/factory.d.ts +2 -2
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +9 -7
- package/dest/index.d.ts +3 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -1
- package/dest/l1/calldata_retriever.d.ts +2 -1
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +11 -5
- package/dest/l1/data_retrieval.d.ts +19 -10
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +25 -32
- package/dest/l1/validate_historical_logs.d.ts +23 -0
- package/dest/l1/validate_historical_logs.d.ts.map +1 -0
- package/dest/l1/validate_historical_logs.js +108 -0
- package/dest/modules/data_source_base.d.ts +8 -2
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +19 -1
- package/dest/modules/data_store_updater.d.ts +15 -10
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +71 -68
- package/dest/modules/instrumentation.d.ts +7 -2
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +22 -6
- package/dest/modules/l1_synchronizer.d.ts +7 -2
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +261 -143
- package/dest/modules/validation.d.ts +4 -3
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +6 -6
- package/dest/store/block_store.d.ts +72 -5
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +341 -66
- 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 +51 -17
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +60 -16
- package/dest/store/l2_tips_cache.d.ts +2 -1
- package/dest/store/l2_tips_cache.d.ts.map +1 -1
- package/dest/store/l2_tips_cache.js +27 -7
- 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 +2 -4
- package/dest/store/message_store.d.ts +3 -3
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +9 -10
- package/dest/test/fake_l1_state.d.ts +15 -3
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +80 -18
- 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 +16 -2
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +50 -3
- package/dest/test/noop_l1_archiver.d.ts +1 -1
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +4 -2
- package/package.json +13 -13
- package/src/archiver.ts +126 -46
- package/src/config.ts +15 -1
- package/src/errors.ts +97 -2
- package/src/factory.ts +13 -7
- package/src/index.ts +2 -1
- package/src/l1/calldata_retriever.ts +17 -5
- package/src/l1/data_retrieval.ts +36 -45
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/modules/data_source_base.ts +32 -1
- package/src/modules/data_store_updater.ts +98 -97
- package/src/modules/instrumentation.ts +27 -7
- package/src/modules/l1_synchronizer.ts +328 -169
- package/src/modules/validation.ts +10 -9
- package/src/store/block_store.ts +419 -76
- 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 +100 -32
- package/src/store/l2_tips_cache.ts +58 -13
- package/src/store/log_store.ts +2 -5
- package/src/store/message_store.ts +10 -12
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +99 -27
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +58 -2
- package/src/test/noop_l1_archiver.ts +3 -1
|
@@ -1,29 +1,26 @@
|
|
|
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
|
-
import type { L2Block, ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
14
|
-
import {
|
|
9
|
+
import type { CommitteeAttestation, L2Block, ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
10
|
+
import {
|
|
11
|
+
type L1PublishedData,
|
|
12
|
+
type ProposedCheckpointInput,
|
|
13
|
+
type PublishedCheckpoint,
|
|
14
|
+
validateCheckpoint,
|
|
15
|
+
} from '@aztec/stdlib/checkpoint';
|
|
15
16
|
import {
|
|
16
|
-
type
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
isValidPrivateFunctionMembershipProof,
|
|
20
|
-
isValidUtilityFunctionMembershipProof,
|
|
17
|
+
type ContractClassPublicWithCommitment,
|
|
18
|
+
computeContractAddressFromInstance,
|
|
19
|
+
computeContractClassId,
|
|
21
20
|
} from '@aztec/stdlib/contract';
|
|
22
21
|
import type { ContractClassLog, PrivateLog, PublicLog } from '@aztec/stdlib/logs';
|
|
23
22
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
24
23
|
|
|
25
|
-
import groupBy from 'lodash.groupby';
|
|
26
|
-
|
|
27
24
|
import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
|
|
28
25
|
import type { L2TipsCache } from '../store/l2_tips_cache.js';
|
|
29
26
|
|
|
@@ -54,8 +51,7 @@ export class ArchiverDataStoreUpdater {
|
|
|
54
51
|
/**
|
|
55
52
|
* Adds a proposed block to the store with contract class/instance extraction from logs.
|
|
56
53
|
* This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
57
|
-
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events
|
|
58
|
-
* and individually broadcasted functions from the block logs.
|
|
54
|
+
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the block logs.
|
|
59
55
|
*
|
|
60
56
|
* @param block - The proposed L2 block to add.
|
|
61
57
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
@@ -87,20 +83,31 @@ export class ArchiverDataStoreUpdater {
|
|
|
87
83
|
* Reconciles local blocks with incoming checkpoints from L1.
|
|
88
84
|
* Adds new checkpoints to the store with contract class/instance extraction from logs.
|
|
89
85
|
* Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
|
|
90
|
-
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events
|
|
91
|
-
*
|
|
86
|
+
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the checkpoint block logs.
|
|
87
|
+
* If `promoteProposed` is supplied, the proposed-checkpoint promotion runs inside the same transaction
|
|
88
|
+
* as the added checkpoints so both updates are applied atomically.
|
|
92
89
|
*
|
|
93
|
-
* @param checkpoints - The published checkpoints to add.
|
|
90
|
+
* @param checkpoints - The published checkpoints to add (excluding any being promoted from proposed).
|
|
94
91
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
92
|
+
* @param promoteProposed - Optional promotion of the current proposed checkpoint (fast path when blocks are already local).
|
|
95
93
|
* @returns Result with information about any pruned blocks.
|
|
96
94
|
*/
|
|
97
95
|
public async addCheckpoints(
|
|
98
96
|
checkpoints: PublishedCheckpoint[],
|
|
99
97
|
pendingChainValidationStatus?: ValidateCheckpointResult,
|
|
98
|
+
promoteProposed?: {
|
|
99
|
+
l1: L1PublishedData;
|
|
100
|
+
attestations: CommitteeAttestation[];
|
|
101
|
+
checkpoint: PublishedCheckpoint;
|
|
102
|
+
},
|
|
103
|
+
evictProposedFrom?: CheckpointNumber,
|
|
100
104
|
): Promise<ReconcileCheckpointsResult> {
|
|
101
105
|
for (const checkpoint of checkpoints) {
|
|
102
106
|
validateCheckpoint(checkpoint.checkpoint, { rollupManaLimit: this.opts?.rollupManaLimit });
|
|
103
107
|
}
|
|
108
|
+
if (promoteProposed) {
|
|
109
|
+
validateCheckpoint(promoteProposed.checkpoint.checkpoint, { rollupManaLimit: this.opts?.rollupManaLimit });
|
|
110
|
+
}
|
|
104
111
|
|
|
105
112
|
const result = await this.store.transactionAsync(async () => {
|
|
106
113
|
// Before adding checkpoints, check for conflicts with local blocks if any
|
|
@@ -120,6 +127,17 @@ export class ArchiverDataStoreUpdater {
|
|
|
120
127
|
this.store.addLogs(newBlocks),
|
|
121
128
|
// Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
|
|
122
129
|
...newBlocks.map(block => this.addContractDataToDb(block)),
|
|
130
|
+
// Promote the proposed checkpoint if requested (uses explicit checkpoint number)
|
|
131
|
+
promoteProposed
|
|
132
|
+
? this.store.promoteProposedToCheckpointed(
|
|
133
|
+
promoteProposed.checkpoint.checkpoint.number,
|
|
134
|
+
promoteProposed.l1,
|
|
135
|
+
promoteProposed.attestations,
|
|
136
|
+
promoteProposed.checkpoint.checkpoint.archive.root,
|
|
137
|
+
)
|
|
138
|
+
: undefined,
|
|
139
|
+
// Evict pending checkpoints that diverged from what L1 mined
|
|
140
|
+
evictProposedFrom !== undefined ? this.store.evictProposedCheckpointsFrom(evictProposedFrom) : undefined,
|
|
123
141
|
]);
|
|
124
142
|
|
|
125
143
|
await this.l2TipsCache?.refresh();
|
|
@@ -128,6 +146,15 @@ export class ArchiverDataStoreUpdater {
|
|
|
128
146
|
return result;
|
|
129
147
|
}
|
|
130
148
|
|
|
149
|
+
public async addProposedCheckpoint(proposedCheckpoint: ProposedCheckpointInput) {
|
|
150
|
+
const result = await this.store.transactionAsync(async () => {
|
|
151
|
+
await this.store.addProposedCheckpoint(proposedCheckpoint);
|
|
152
|
+
await this.l2TipsCache?.refresh();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
|
|
131
158
|
/**
|
|
132
159
|
* Checks for local proposed blocks that do not match the ones to be checkpointed and prunes them.
|
|
133
160
|
* This method handles multiple checkpoints but returns after pruning the first conflict found.
|
|
@@ -221,6 +248,10 @@ export class ArchiverDataStoreUpdater {
|
|
|
221
248
|
}
|
|
222
249
|
|
|
223
250
|
const result = await this.removeBlocksAfter(blockNumber);
|
|
251
|
+
|
|
252
|
+
// Clear all pending proposed checkpoints since their blocks have been pruned
|
|
253
|
+
await this.store.deleteProposedCheckpoints();
|
|
254
|
+
|
|
224
255
|
await this.l2TipsCache?.refresh();
|
|
225
256
|
return result;
|
|
226
257
|
});
|
|
@@ -313,9 +344,6 @@ export class ArchiverDataStoreUpdater {
|
|
|
313
344
|
this.updatePublishedContractClasses(contractClassLogs, block.number, operation),
|
|
314
345
|
this.updateDeployedContractInstances(privateLogs, block.number, operation),
|
|
315
346
|
this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation),
|
|
316
|
-
operation === Operation.Store
|
|
317
|
-
? this.storeBroadcastedIndividualFunctions(contractClassLogs, block.number)
|
|
318
|
-
: Promise.resolve(true),
|
|
319
347
|
])
|
|
320
348
|
).every(Boolean);
|
|
321
349
|
}
|
|
@@ -332,18 +360,37 @@ export class ArchiverDataStoreUpdater {
|
|
|
332
360
|
.filter(log => ContractClassPublishedEvent.isContractClassPublishedEvent(log))
|
|
333
361
|
.map(log => ContractClassPublishedEvent.fromLog(log));
|
|
334
362
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
contractClasses.
|
|
338
|
-
|
|
339
|
-
// TODO: Will probably want to create some worker threads to compute these bytecode commitments as they are expensive
|
|
340
|
-
const commitments = await Promise.all(
|
|
341
|
-
contractClasses.map(c => computePublicBytecodeCommitment(c.packedBytecode)),
|
|
342
|
-
);
|
|
343
|
-
return await this.store.addContractClasses(contractClasses, commitments, blockNum);
|
|
344
|
-
} else if (operation == Operation.Delete) {
|
|
363
|
+
if (operation == Operation.Delete) {
|
|
364
|
+
const contractClasses = contractClassPublishedEvents.map(e => e.toContractClassPublic());
|
|
365
|
+
if (contractClasses.length > 0) {
|
|
366
|
+
contractClasses.forEach(c => this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
345
367
|
return await this.store.deleteContractClasses(contractClasses, blockNum);
|
|
346
368
|
}
|
|
369
|
+
return true;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Compute bytecode commitments and validate class IDs in a single pass.
|
|
373
|
+
const contractClasses: ContractClassPublicWithCommitment[] = [];
|
|
374
|
+
for (const event of contractClassPublishedEvents) {
|
|
375
|
+
const contractClass = await event.toContractClassPublicWithBytecodeCommitment();
|
|
376
|
+
const computedClassId = await computeContractClassId({
|
|
377
|
+
artifactHash: contractClass.artifactHash,
|
|
378
|
+
privateFunctionsRoot: contractClass.privateFunctionsRoot,
|
|
379
|
+
publicBytecodeCommitment: contractClass.publicBytecodeCommitment,
|
|
380
|
+
});
|
|
381
|
+
if (!computedClassId.equals(contractClass.id)) {
|
|
382
|
+
this.log.warn(
|
|
383
|
+
`Skipping contract class with mismatched id at block ${blockNum}. Claimed ${contractClass.id}, computed ${computedClassId}`,
|
|
384
|
+
{ blockNum, contractClassId: event.contractClassId.toString() },
|
|
385
|
+
);
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
contractClasses.push(contractClass);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
if (contractClasses.length > 0) {
|
|
392
|
+
contractClasses.forEach(c => this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
393
|
+
return await this.store.addContractClasses(contractClasses, blockNum);
|
|
347
394
|
}
|
|
348
395
|
return true;
|
|
349
396
|
}
|
|
@@ -356,10 +403,27 @@ export class ArchiverDataStoreUpdater {
|
|
|
356
403
|
blockNum: BlockNumber,
|
|
357
404
|
operation: Operation,
|
|
358
405
|
): Promise<boolean> {
|
|
359
|
-
const
|
|
406
|
+
const allInstances = allLogs
|
|
360
407
|
.filter(log => ContractInstancePublishedEvent.isContractInstancePublishedEvent(log))
|
|
361
408
|
.map(log => ContractInstancePublishedEvent.fromLog(log))
|
|
362
409
|
.map(e => e.toContractInstance());
|
|
410
|
+
|
|
411
|
+
// Verify that each instance's address matches the one derived from its fields if we're adding
|
|
412
|
+
const contractInstances =
|
|
413
|
+
operation === Operation.Delete
|
|
414
|
+
? allInstances
|
|
415
|
+
: await filterAsync(allInstances, async instance => {
|
|
416
|
+
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
417
|
+
if (!computedAddress.equals(instance.address)) {
|
|
418
|
+
this.log.warn(
|
|
419
|
+
`Found contract instance with mismatched address at block ${blockNum}. Claimed ${instance.address} but computed ${computedAddress}.`,
|
|
420
|
+
{ instanceAddress: instance.address.toString(), computedAddress: computedAddress.toString(), blockNum },
|
|
421
|
+
);
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
return true;
|
|
425
|
+
});
|
|
426
|
+
|
|
363
427
|
if (contractInstances.length > 0) {
|
|
364
428
|
contractInstances.forEach(c =>
|
|
365
429
|
this.log.verbose(`${Operation[operation]} contract instance at ${c.address.toString()}`),
|
|
@@ -398,67 +462,4 @@ export class ArchiverDataStoreUpdater {
|
|
|
398
462
|
}
|
|
399
463
|
return true;
|
|
400
464
|
}
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
* Stores the functions that were broadcasted individually.
|
|
404
|
-
*
|
|
405
|
-
* @dev Beware that there is not a delete variant of this, since they are added to contract classes
|
|
406
|
-
* and will be deleted as part of the class if needed.
|
|
407
|
-
*/
|
|
408
|
-
private async storeBroadcastedIndividualFunctions(
|
|
409
|
-
allLogs: ContractClassLog[],
|
|
410
|
-
_blockNum: BlockNumber,
|
|
411
|
-
): Promise<boolean> {
|
|
412
|
-
// Filter out private and utility function broadcast events
|
|
413
|
-
const privateFnEvents = allLogs
|
|
414
|
-
.filter(log => PrivateFunctionBroadcastedEvent.isPrivateFunctionBroadcastedEvent(log))
|
|
415
|
-
.map(log => PrivateFunctionBroadcastedEvent.fromLog(log));
|
|
416
|
-
const utilityFnEvents = allLogs
|
|
417
|
-
.filter(log => UtilityFunctionBroadcastedEvent.isUtilityFunctionBroadcastedEvent(log))
|
|
418
|
-
.map(log => UtilityFunctionBroadcastedEvent.fromLog(log));
|
|
419
|
-
|
|
420
|
-
// Group all events by contract class id
|
|
421
|
-
for (const [classIdString, classEvents] of Object.entries(
|
|
422
|
-
groupBy([...privateFnEvents, ...utilityFnEvents], e => e.contractClassId.toString()),
|
|
423
|
-
)) {
|
|
424
|
-
const contractClassId = Fr.fromHexString(classIdString);
|
|
425
|
-
const contractClass = await this.store.getContractClass(contractClassId);
|
|
426
|
-
if (!contractClass) {
|
|
427
|
-
this.log.warn(`Skipping broadcasted functions as contract class ${contractClassId.toString()} was not found`);
|
|
428
|
-
continue;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
// Split private and utility functions, and filter out invalid ones
|
|
432
|
-
const allFns = classEvents.map(e => e.toFunctionWithMembershipProof());
|
|
433
|
-
const privateFns = allFns.filter(
|
|
434
|
-
(fn): fn is ExecutablePrivateFunctionWithMembershipProof => 'utilityFunctionsTreeRoot' in fn,
|
|
435
|
-
);
|
|
436
|
-
const utilityFns = allFns.filter(
|
|
437
|
-
(fn): fn is UtilityFunctionWithMembershipProof => 'privateFunctionsArtifactTreeRoot' in fn,
|
|
438
|
-
);
|
|
439
|
-
|
|
440
|
-
const privateFunctionsWithValidity = await Promise.all(
|
|
441
|
-
privateFns.map(async fn => ({ fn, valid: await isValidPrivateFunctionMembershipProof(fn, contractClass) })),
|
|
442
|
-
);
|
|
443
|
-
const validPrivateFns = privateFunctionsWithValidity.filter(({ valid }) => valid).map(({ fn }) => fn);
|
|
444
|
-
const utilityFunctionsWithValidity = await Promise.all(
|
|
445
|
-
utilityFns.map(async fn => ({
|
|
446
|
-
fn,
|
|
447
|
-
valid: await isValidUtilityFunctionMembershipProof(fn, contractClass),
|
|
448
|
-
})),
|
|
449
|
-
);
|
|
450
|
-
const validUtilityFns = utilityFunctionsWithValidity.filter(({ valid }) => valid).map(({ fn }) => fn);
|
|
451
|
-
const validFnCount = validPrivateFns.length + validUtilityFns.length;
|
|
452
|
-
if (validFnCount !== allFns.length) {
|
|
453
|
-
this.log.warn(`Skipping ${allFns.length - validFnCount} invalid functions`);
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
// Store the functions in the contract class in a single operation
|
|
457
|
-
if (validFnCount > 0) {
|
|
458
|
-
this.log.verbose(`Storing ${validFnCount} functions for contract class ${contractClassId.toString()}`);
|
|
459
|
-
}
|
|
460
|
-
await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
|
|
461
|
-
}
|
|
462
|
-
return true;
|
|
463
|
-
}
|
|
464
465
|
}
|
|
@@ -32,6 +32,7 @@ export class ArchiverInstrumentation {
|
|
|
32
32
|
private pruneCount: UpDownCounter;
|
|
33
33
|
|
|
34
34
|
private syncDurationPerBlock: Histogram;
|
|
35
|
+
private syncDurationPerCheckpoint: Histogram;
|
|
35
36
|
private syncBlockCount: UpDownCounter;
|
|
36
37
|
private manaPerBlock: Histogram;
|
|
37
38
|
private txsPerBlock: Histogram;
|
|
@@ -42,6 +43,7 @@ export class ArchiverInstrumentation {
|
|
|
42
43
|
private blockProposalTxTargetCount: UpDownCounter;
|
|
43
44
|
|
|
44
45
|
private checkpointL1InclusionDelay: Histogram;
|
|
46
|
+
private checkpointPromotedCount: UpDownCounter;
|
|
45
47
|
|
|
46
48
|
private log = createLogger('archiver:instrumentation');
|
|
47
49
|
|
|
@@ -68,6 +70,8 @@ export class ArchiverInstrumentation {
|
|
|
68
70
|
|
|
69
71
|
this.syncDurationPerBlock = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_BLOCK);
|
|
70
72
|
|
|
73
|
+
this.syncDurationPerCheckpoint = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_CHECKPOINT);
|
|
74
|
+
|
|
71
75
|
this.syncBlockCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_BLOCK_COUNT);
|
|
72
76
|
|
|
73
77
|
this.manaPerBlock = meter.createHistogram(Metrics.ARCHIVER_MANA_PER_BLOCK);
|
|
@@ -92,6 +96,8 @@ export class ArchiverInstrumentation {
|
|
|
92
96
|
|
|
93
97
|
this.checkpointL1InclusionDelay = meter.createHistogram(Metrics.ARCHIVER_CHECKPOINT_L1_INCLUSION_DELAY);
|
|
94
98
|
|
|
99
|
+
this.checkpointPromotedCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_CHECKPOINT_PROMOTED_COUNT);
|
|
100
|
+
|
|
95
101
|
this.dbMetrics = new LmdbMetrics(
|
|
96
102
|
meter,
|
|
97
103
|
{
|
|
@@ -113,17 +119,26 @@ export class ArchiverInstrumentation {
|
|
|
113
119
|
return this.telemetry.isEnabled();
|
|
114
120
|
}
|
|
115
121
|
|
|
116
|
-
public
|
|
122
|
+
public processNewProposedBlock(syncTimePerBlock: number, block: L2Block) {
|
|
123
|
+
const attrs = { [Attributes.STATUS]: 'proposed' };
|
|
124
|
+
this.blockHeight.record(block.number, attrs);
|
|
117
125
|
this.syncDurationPerBlock.record(Math.ceil(syncTimePerBlock));
|
|
126
|
+
|
|
127
|
+
// Per block metrics
|
|
128
|
+
this.txCount.add(block.body.txEffects.length);
|
|
129
|
+
this.txsPerBlock.record(block.body.txEffects.length);
|
|
130
|
+
this.manaPerBlock.record(block.header.totalManaUsed.toNumber() / 1e6);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public processNewCheckpointedBlocks(syncTimePerCheckpoint: number, blocks: L2Block[]) {
|
|
134
|
+
if (blocks.length === 0) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
this.syncDurationPerCheckpoint.record(Math.ceil(syncTimePerCheckpoint));
|
|
118
139
|
this.blockHeight.record(Math.max(...blocks.map(b => b.number)));
|
|
119
140
|
this.checkpointHeight.record(Math.max(...blocks.map(b => b.checkpointNumber)));
|
|
120
141
|
this.syncBlockCount.add(blocks.length);
|
|
121
|
-
|
|
122
|
-
for (const block of blocks) {
|
|
123
|
-
this.txCount.add(block.body.txEffects.length);
|
|
124
|
-
this.txsPerBlock.record(block.body.txEffects.length);
|
|
125
|
-
this.manaPerBlock.record(block.header.totalManaUsed.toNumber() / 1e6);
|
|
126
|
-
}
|
|
127
142
|
}
|
|
128
143
|
|
|
129
144
|
public processNewMessages(count: number, syncPerMessageMs: number) {
|
|
@@ -169,6 +184,11 @@ export class ArchiverInstrumentation {
|
|
|
169
184
|
});
|
|
170
185
|
}
|
|
171
186
|
|
|
187
|
+
/** Records a checkpoint promoted from proposed (blob fetch skipped). */
|
|
188
|
+
public processCheckpointPromoted() {
|
|
189
|
+
this.checkpointPromotedCount.add(1);
|
|
190
|
+
}
|
|
191
|
+
|
|
172
192
|
/**
|
|
173
193
|
* Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
|
|
174
194
|
*/
|