@aztec/archiver 0.0.1-commit.d431d1c → 0.0.1-commit.d939eb5aa
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 +21 -6
- package/dest/archiver.d.ts +17 -12
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +108 -127
- package/dest/config.d.ts +3 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +3 -2
- package/dest/errors.d.ts +39 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +52 -15
- package/dest/factory.d.ts +4 -2
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +29 -23
- 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 +35 -32
- 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 +38 -37
- 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 +29 -23
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +55 -124
- package/dest/modules/data_store_updater.d.ts +43 -26
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +158 -129
- package/dest/modules/instrumentation.d.ts +19 -4
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +53 -18
- 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 +186 -145
- 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 +86 -34
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +414 -152
- 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 +16 -72
- 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 +80 -39
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +86 -35
- 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 +9 -6
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +151 -56
- 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 +24 -4
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +133 -26
- 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_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 +44 -23
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +185 -115
- 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 +24 -10
- 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 +71 -0
- package/package.json +14 -13
- package/src/archiver.ts +144 -159
- package/src/config.ts +9 -2
- package/src/errors.ts +82 -26
- package/src/factory.ts +46 -22
- package/src/index.ts +1 -0
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +45 -33
- package/src/l1/calldata_retriever.ts +250 -379
- package/src/l1/data_retrieval.ts +35 -41
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_trace.ts +24 -6
- package/src/modules/data_source_base.ts +98 -169
- package/src/modules/data_store_updater.ts +178 -160
- package/src/modules/instrumentation.ts +64 -20
- package/src/modules/l1_synchronizer.ts +212 -182
- package/src/modules/validation.ts +2 -2
- package/src/store/block_store.ts +533 -207
- package/src/store/contract_class_store.ts +16 -110
- package/src/store/contract_instance_store.ts +8 -5
- package/src/store/kv_archiver_store.ts +141 -59
- package/src/store/l2_tips_cache.ts +134 -0
- package/src/store/log_store.ts +232 -74
- package/src/store/message_store.ts +27 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +180 -32
- package/src/test/index.ts +3 -0
- 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 +247 -130
- package/src/test/mock_structs.ts +45 -15
- package/src/test/noop_l1_archiver.ts +114 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import {
|
|
2
|
+
import { filterAsync } from '@aztec/foundation/collection';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import { ContractClassPublishedEvent
|
|
4
|
+
import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
|
|
5
5
|
import { ContractInstancePublishedEvent, ContractInstanceUpdatedEvent } from '@aztec/protocol-contracts/instance-registry';
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
6
|
+
import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
7
|
+
import { computeContractAddressFromInstance, computeContractClassId } from '@aztec/stdlib/contract';
|
|
8
8
|
/** Operation type for contract data updates. */ var Operation = /*#__PURE__*/ function(Operation) {
|
|
9
9
|
Operation[Operation["Store"] = 0] = "Store";
|
|
10
10
|
Operation[Operation["Delete"] = 1] = "Delete";
|
|
@@ -12,49 +12,61 @@ import groupBy from 'lodash.groupby';
|
|
|
12
12
|
}(Operation || {});
|
|
13
13
|
/** Archiver helper module to handle updates to the data store. */ export class ArchiverDataStoreUpdater {
|
|
14
14
|
store;
|
|
15
|
+
l2TipsCache;
|
|
16
|
+
opts;
|
|
15
17
|
log;
|
|
16
|
-
constructor(store){
|
|
18
|
+
constructor(store, l2TipsCache, opts = {}){
|
|
17
19
|
this.store = store;
|
|
20
|
+
this.l2TipsCache = l2TipsCache;
|
|
21
|
+
this.opts = opts;
|
|
18
22
|
this.log = createLogger('archiver:store_updater');
|
|
19
23
|
}
|
|
20
24
|
/**
|
|
21
|
-
* Adds
|
|
22
|
-
*
|
|
23
|
-
*
|
|
25
|
+
* Adds a proposed block to the store with contract class/instance extraction from logs.
|
|
26
|
+
* This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
27
|
+
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the block logs.
|
|
24
28
|
*
|
|
25
|
-
* @param
|
|
29
|
+
* @param block - The proposed L2 block to add.
|
|
26
30
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
27
31
|
* @returns True if the operation is successful.
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
await this.store.
|
|
32
|
+
*/ async addProposedBlock(block, pendingChainValidationStatus) {
|
|
33
|
+
const result = await this.store.transactionAsync(async ()=>{
|
|
34
|
+
await this.store.addProposedBlock(block);
|
|
31
35
|
const opResults = await Promise.all([
|
|
32
36
|
// Update the pending chain validation status if provided
|
|
33
37
|
pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
|
|
34
|
-
// Add any logs emitted during the retrieved
|
|
35
|
-
this.store.addLogs(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
// Add any logs emitted during the retrieved block
|
|
39
|
+
this.store.addLogs([
|
|
40
|
+
block
|
|
41
|
+
]),
|
|
42
|
+
// Unroll all logs emitted during the retrieved block and extract any contract classes and instances from it
|
|
43
|
+
this.addContractDataToDb(block)
|
|
38
44
|
]);
|
|
45
|
+
await this.l2TipsCache?.refresh();
|
|
39
46
|
return opResults.every(Boolean);
|
|
40
47
|
});
|
|
48
|
+
return result;
|
|
41
49
|
}
|
|
42
50
|
/**
|
|
43
51
|
* Reconciles local blocks with incoming checkpoints from L1.
|
|
44
|
-
* Adds checkpoints to the store with contract class/instance extraction from logs.
|
|
52
|
+
* Adds new checkpoints to the store with contract class/instance extraction from logs.
|
|
45
53
|
* Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
|
|
46
|
-
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events
|
|
47
|
-
* and individually broadcasted functions from the checkpoint block logs.
|
|
54
|
+
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the checkpoint block logs.
|
|
48
55
|
*
|
|
49
56
|
* @param checkpoints - The published checkpoints to add.
|
|
50
57
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
51
58
|
* @returns Result with information about any pruned blocks.
|
|
52
|
-
*/
|
|
53
|
-
|
|
59
|
+
*/ async addCheckpoints(checkpoints, pendingChainValidationStatus) {
|
|
60
|
+
for (const checkpoint of checkpoints){
|
|
61
|
+
validateCheckpoint(checkpoint.checkpoint, {
|
|
62
|
+
rollupManaLimit: this.opts?.rollupManaLimit
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const result = await this.store.transactionAsync(async ()=>{
|
|
54
66
|
// Before adding checkpoints, check for conflicts with local blocks if any
|
|
55
67
|
const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
|
|
56
68
|
await this.store.addCheckpoints(checkpoints);
|
|
57
|
-
// Filter out blocks that were already inserted via
|
|
69
|
+
// Filter out blocks that were already inserted via addProposedBlock() to avoid duplicating logs/contract data
|
|
58
70
|
const newBlocks = checkpoints.flatMap((ch)=>ch.checkpoint.blocks).filter((b)=>lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
|
|
59
71
|
await Promise.all([
|
|
60
72
|
// Update the pending chain validation status if provided
|
|
@@ -62,13 +74,22 @@ import groupBy from 'lodash.groupby';
|
|
|
62
74
|
// Add any logs emitted during the retrieved blocks
|
|
63
75
|
this.store.addLogs(newBlocks),
|
|
64
76
|
// Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
|
|
65
|
-
...newBlocks.map((block)=>this.
|
|
77
|
+
...newBlocks.map((block)=>this.addContractDataToDb(block))
|
|
66
78
|
]);
|
|
79
|
+
await this.l2TipsCache?.refresh();
|
|
67
80
|
return {
|
|
68
81
|
prunedBlocks,
|
|
69
82
|
lastAlreadyInsertedBlockNumber
|
|
70
83
|
};
|
|
71
84
|
});
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
async setProposedCheckpoint(proposedCheckpoint) {
|
|
88
|
+
const result = await this.store.transactionAsync(async ()=>{
|
|
89
|
+
await this.store.setProposedCheckpoint(proposedCheckpoint);
|
|
90
|
+
await this.l2TipsCache?.refresh();
|
|
91
|
+
});
|
|
92
|
+
return result;
|
|
72
93
|
}
|
|
73
94
|
/**
|
|
74
95
|
* Checks for local proposed blocks that do not match the ones to be checkpointed and prunes them.
|
|
@@ -112,7 +133,7 @@ import groupBy from 'lodash.groupby';
|
|
|
112
133
|
this.log.verbose(`Block number ${blockNumber} already inserted and matches checkpoint`, blockInfos);
|
|
113
134
|
lastAlreadyInsertedBlockNumber = blockNumber;
|
|
114
135
|
} else {
|
|
115
|
-
this.log.
|
|
136
|
+
this.log.info(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
|
|
116
137
|
const prunedBlocks = await this.removeBlocksAfter(BlockNumber(blockNumber - 1));
|
|
117
138
|
return {
|
|
118
139
|
prunedBlocks,
|
|
@@ -139,98 +160,152 @@ import groupBy from 'lodash.groupby';
|
|
|
139
160
|
};
|
|
140
161
|
}
|
|
141
162
|
/**
|
|
142
|
-
* Removes all blocks strictly after the specified block number and cleans up associated contract data.
|
|
163
|
+
* Removes all uncheckpointed blocks strictly after the specified block number and cleans up associated contract data.
|
|
143
164
|
* This handles removal of provisionally added blocks along with their contract classes/instances.
|
|
165
|
+
* Verifies that each block being removed is not part of a stored checkpoint.
|
|
144
166
|
*
|
|
145
167
|
* @param blockNumber - Remove all blocks with number greater than this.
|
|
146
168
|
* @returns The removed blocks.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
169
|
+
* @throws Error if any block to be removed is checkpointed.
|
|
170
|
+
*/ async removeUncheckpointedBlocksAfter(blockNumber) {
|
|
171
|
+
const result = await this.store.transactionAsync(async ()=>{
|
|
172
|
+
// Verify we're only removing uncheckpointed blocks
|
|
173
|
+
const lastCheckpointedBlockNumber = await this.store.getCheckpointedL2BlockNumber();
|
|
174
|
+
if (blockNumber < lastCheckpointedBlockNumber) {
|
|
175
|
+
throw new Error(`Cannot remove blocks after ${blockNumber} because checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`);
|
|
176
|
+
}
|
|
177
|
+
const result = await this.removeBlocksAfter(blockNumber);
|
|
178
|
+
// Clear the proposed checkpoint if it exists, since its blocks have been pruned
|
|
179
|
+
await this.store.deleteProposedCheckpoint();
|
|
180
|
+
await this.l2TipsCache?.refresh();
|
|
181
|
+
return result;
|
|
157
182
|
});
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Removes all blocks strictly after the given block number along with any logs and contract data.
|
|
187
|
+
* Does not remove their checkpoints.
|
|
188
|
+
*/ async removeBlocksAfter(blockNumber) {
|
|
189
|
+
// First get the blocks to be removed so we can clean up contract data
|
|
190
|
+
const removedBlocks = await this.store.removeBlocksAfter(blockNumber);
|
|
191
|
+
// Clean up contract data and logs for the removed blocks
|
|
192
|
+
await Promise.all([
|
|
193
|
+
this.store.deleteLogs(removedBlocks),
|
|
194
|
+
...removedBlocks.map((block)=>this.removeContractDataFromDb(block))
|
|
195
|
+
]);
|
|
196
|
+
return removedBlocks;
|
|
158
197
|
}
|
|
159
198
|
/**
|
|
160
|
-
*
|
|
199
|
+
* Removes all checkpoints after the given checkpoint number.
|
|
161
200
|
* Deletes ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated data
|
|
162
|
-
* that was stored for the
|
|
201
|
+
* that was stored for the removed checkpoints. Also removes ALL blocks (both checkpointed
|
|
202
|
+
* and uncheckpointed) after the last block of the given checkpoint.
|
|
163
203
|
*
|
|
164
|
-
* @param
|
|
165
|
-
* @param checkpointsToUnwind - The number of checkpoints to unwind.
|
|
204
|
+
* @param checkpointNumber - Remove all checkpoints strictly after this one.
|
|
166
205
|
* @returns True if the operation is successful.
|
|
167
|
-
*/ async
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
this.store.deleteLogs(blocks),
|
|
192
|
-
this.store.unwindCheckpoints(from, checkpointsToUnwind)
|
|
193
|
-
]);
|
|
194
|
-
return opResults.every(Boolean);
|
|
206
|
+
*/ async removeCheckpointsAfter(checkpointNumber) {
|
|
207
|
+
return await this.store.transactionAsync(async ()=>{
|
|
208
|
+
const { blocksRemoved = [] } = await this.store.removeCheckpointsAfter(checkpointNumber);
|
|
209
|
+
const opResults = await Promise.all([
|
|
210
|
+
// Prune rolls back to the last proven block, which is by definition valid
|
|
211
|
+
this.store.setPendingChainValidationStatus({
|
|
212
|
+
valid: true
|
|
213
|
+
}),
|
|
214
|
+
// Remove contract data for all blocks being removed
|
|
215
|
+
...blocksRemoved.map((block)=>this.removeContractDataFromDb(block)),
|
|
216
|
+
this.store.deleteLogs(blocksRemoved)
|
|
217
|
+
]);
|
|
218
|
+
await this.l2TipsCache?.refresh();
|
|
219
|
+
return opResults.every(Boolean);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Updates the proven checkpoint number and refreshes the L2 tips cache.
|
|
224
|
+
* @param checkpointNumber - The checkpoint number to set as proven.
|
|
225
|
+
*/ async setProvenCheckpointNumber(checkpointNumber) {
|
|
226
|
+
await this.store.transactionAsync(async ()=>{
|
|
227
|
+
await this.store.setProvenCheckpointNumber(checkpointNumber);
|
|
228
|
+
await this.l2TipsCache?.refresh();
|
|
229
|
+
});
|
|
195
230
|
}
|
|
196
|
-
/**
|
|
197
|
-
|
|
231
|
+
/**
|
|
232
|
+
* Updates the finalized checkpoint number and refreshes the L2 tips cache.
|
|
233
|
+
* @param checkpointNumber - The checkpoint number to set as finalized.
|
|
234
|
+
*/ async setFinalizedCheckpointNumber(checkpointNumber) {
|
|
235
|
+
await this.store.transactionAsync(async ()=>{
|
|
236
|
+
await this.store.setFinalizedCheckpointNumber(checkpointNumber);
|
|
237
|
+
await this.l2TipsCache?.refresh();
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
/** Extracts and stores contract data from a single block. */ addContractDataToDb(block) {
|
|
241
|
+
return this.updateContractDataOnDb(block, 0);
|
|
198
242
|
}
|
|
199
|
-
/** Removes contract data associated with a block. */
|
|
200
|
-
return this.
|
|
243
|
+
/** Removes contract data associated with a block. */ removeContractDataFromDb(block) {
|
|
244
|
+
return this.updateContractDataOnDb(block, 1);
|
|
201
245
|
}
|
|
202
|
-
/** Adds or remove contract data associated with a block. */ async
|
|
246
|
+
/** Adds or remove contract data associated with a block. */ async updateContractDataOnDb(block, operation) {
|
|
203
247
|
const contractClassLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.contractClassLogs);
|
|
204
248
|
const privateLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.privateLogs);
|
|
205
249
|
const publicLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.publicLogs);
|
|
206
250
|
return (await Promise.all([
|
|
207
251
|
this.updatePublishedContractClasses(contractClassLogs, block.number, operation),
|
|
208
252
|
this.updateDeployedContractInstances(privateLogs, block.number, operation),
|
|
209
|
-
this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation)
|
|
210
|
-
operation === 0 ? this.storeBroadcastedIndividualFunctions(contractClassLogs, block.number) : Promise.resolve(true)
|
|
253
|
+
this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation)
|
|
211
254
|
])).every(Boolean);
|
|
212
255
|
}
|
|
213
256
|
/**
|
|
214
257
|
* Extracts and stores contract classes out of ContractClassPublished events emitted by the class registry contract.
|
|
215
258
|
*/ async updatePublishedContractClasses(allLogs, blockNum, operation) {
|
|
216
259
|
const contractClassPublishedEvents = allLogs.filter((log)=>ContractClassPublishedEvent.isContractClassPublishedEvent(log)).map((log)=>ContractClassPublishedEvent.fromLog(log));
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
contractClasses.
|
|
220
|
-
|
|
221
|
-
// TODO: Will probably want to create some worker threads to compute these bytecode commitments as they are expensive
|
|
222
|
-
const commitments = await Promise.all(contractClasses.map((c)=>computePublicBytecodeCommitment(c.packedBytecode)));
|
|
223
|
-
return await this.store.addContractClasses(contractClasses, commitments, blockNum);
|
|
224
|
-
} else if (operation == 1) {
|
|
260
|
+
if (operation == 1) {
|
|
261
|
+
const contractClasses = contractClassPublishedEvents.map((e)=>e.toContractClassPublic());
|
|
262
|
+
if (contractClasses.length > 0) {
|
|
263
|
+
contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
225
264
|
return await this.store.deleteContractClasses(contractClasses, blockNum);
|
|
226
265
|
}
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
// Compute bytecode commitments and validate class IDs in a single pass.
|
|
269
|
+
const contractClasses = [];
|
|
270
|
+
for (const event of contractClassPublishedEvents){
|
|
271
|
+
const contractClass = await event.toContractClassPublicWithBytecodeCommitment();
|
|
272
|
+
const computedClassId = await computeContractClassId({
|
|
273
|
+
artifactHash: contractClass.artifactHash,
|
|
274
|
+
privateFunctionsRoot: contractClass.privateFunctionsRoot,
|
|
275
|
+
publicBytecodeCommitment: contractClass.publicBytecodeCommitment
|
|
276
|
+
});
|
|
277
|
+
if (!computedClassId.equals(contractClass.id)) {
|
|
278
|
+
this.log.warn(`Skipping contract class with mismatched id at block ${blockNum}. Claimed ${contractClass.id}, computed ${computedClassId}`, {
|
|
279
|
+
blockNum,
|
|
280
|
+
contractClassId: event.contractClassId.toString()
|
|
281
|
+
});
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
contractClasses.push(contractClass);
|
|
285
|
+
}
|
|
286
|
+
if (contractClasses.length > 0) {
|
|
287
|
+
contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
288
|
+
return await this.store.addContractClasses(contractClasses, blockNum);
|
|
227
289
|
}
|
|
228
290
|
return true;
|
|
229
291
|
}
|
|
230
292
|
/**
|
|
231
293
|
* Extracts and stores contract instances out of ContractInstancePublished events emitted by the canonical deployer contract.
|
|
232
294
|
*/ async updateDeployedContractInstances(allLogs, blockNum, operation) {
|
|
233
|
-
const
|
|
295
|
+
const allInstances = allLogs.filter((log)=>ContractInstancePublishedEvent.isContractInstancePublishedEvent(log)).map((log)=>ContractInstancePublishedEvent.fromLog(log)).map((e)=>e.toContractInstance());
|
|
296
|
+
// Verify that each instance's address matches the one derived from its fields if we're adding
|
|
297
|
+
const contractInstances = operation === 1 ? allInstances : await filterAsync(allInstances, async (instance)=>{
|
|
298
|
+
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
299
|
+
if (!computedAddress.equals(instance.address)) {
|
|
300
|
+
this.log.warn(`Found contract instance with mismatched address at block ${blockNum}. Claimed ${instance.address} but computed ${computedAddress}.`, {
|
|
301
|
+
instanceAddress: instance.address.toString(),
|
|
302
|
+
computedAddress: computedAddress.toString(),
|
|
303
|
+
blockNum
|
|
304
|
+
});
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
return true;
|
|
308
|
+
});
|
|
234
309
|
if (contractInstances.length > 0) {
|
|
235
310
|
contractInstances.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance at ${c.address.toString()}`));
|
|
236
311
|
if (operation == 0) {
|
|
@@ -255,50 +330,4 @@ import groupBy from 'lodash.groupby';
|
|
|
255
330
|
}
|
|
256
331
|
return true;
|
|
257
332
|
}
|
|
258
|
-
/**
|
|
259
|
-
* Stores the functions that were broadcasted individually.
|
|
260
|
-
*
|
|
261
|
-
* @dev Beware that there is not a delete variant of this, since they are added to contract classes
|
|
262
|
-
* and will be deleted as part of the class if needed.
|
|
263
|
-
*/ async storeBroadcastedIndividualFunctions(allLogs, _blockNum) {
|
|
264
|
-
// Filter out private and utility function broadcast events
|
|
265
|
-
const privateFnEvents = allLogs.filter((log)=>PrivateFunctionBroadcastedEvent.isPrivateFunctionBroadcastedEvent(log)).map((log)=>PrivateFunctionBroadcastedEvent.fromLog(log));
|
|
266
|
-
const utilityFnEvents = allLogs.filter((log)=>UtilityFunctionBroadcastedEvent.isUtilityFunctionBroadcastedEvent(log)).map((log)=>UtilityFunctionBroadcastedEvent.fromLog(log));
|
|
267
|
-
// Group all events by contract class id
|
|
268
|
-
for (const [classIdString, classEvents] of Object.entries(groupBy([
|
|
269
|
-
...privateFnEvents,
|
|
270
|
-
...utilityFnEvents
|
|
271
|
-
], (e)=>e.contractClassId.toString()))){
|
|
272
|
-
const contractClassId = Fr.fromHexString(classIdString);
|
|
273
|
-
const contractClass = await this.store.getContractClass(contractClassId);
|
|
274
|
-
if (!contractClass) {
|
|
275
|
-
this.log.warn(`Skipping broadcasted functions as contract class ${contractClassId.toString()} was not found`);
|
|
276
|
-
continue;
|
|
277
|
-
}
|
|
278
|
-
// Split private and utility functions, and filter out invalid ones
|
|
279
|
-
const allFns = classEvents.map((e)=>e.toFunctionWithMembershipProof());
|
|
280
|
-
const privateFns = allFns.filter((fn)=>'utilityFunctionsTreeRoot' in fn);
|
|
281
|
-
const utilityFns = allFns.filter((fn)=>'privateFunctionsArtifactTreeRoot' in fn);
|
|
282
|
-
const privateFunctionsWithValidity = await Promise.all(privateFns.map(async (fn)=>({
|
|
283
|
-
fn,
|
|
284
|
-
valid: await isValidPrivateFunctionMembershipProof(fn, contractClass)
|
|
285
|
-
})));
|
|
286
|
-
const validPrivateFns = privateFunctionsWithValidity.filter(({ valid })=>valid).map(({ fn })=>fn);
|
|
287
|
-
const utilityFunctionsWithValidity = await Promise.all(utilityFns.map(async (fn)=>({
|
|
288
|
-
fn,
|
|
289
|
-
valid: await isValidUtilityFunctionMembershipProof(fn, contractClass)
|
|
290
|
-
})));
|
|
291
|
-
const validUtilityFns = utilityFunctionsWithValidity.filter(({ valid })=>valid).map(({ fn })=>fn);
|
|
292
|
-
const validFnCount = validPrivateFns.length + validUtilityFns.length;
|
|
293
|
-
if (validFnCount !== allFns.length) {
|
|
294
|
-
this.log.warn(`Skipping ${allFns.length - validFnCount} invalid functions`);
|
|
295
|
-
}
|
|
296
|
-
// Store the functions in the contract class in a single operation
|
|
297
|
-
if (validFnCount > 0) {
|
|
298
|
-
this.log.verbose(`Storing ${validFnCount} functions for contract class ${contractClassId.toString()}`);
|
|
299
|
-
}
|
|
300
|
-
return await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
|
|
301
|
-
}
|
|
302
|
-
return true;
|
|
303
|
-
}
|
|
304
333
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
3
|
+
import type { CheckpointData } from '@aztec/stdlib/checkpoint';
|
|
4
|
+
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
2
5
|
import { type LmdbStatsCallback, type TelemetryClient, type Tracer } from '@aztec/telemetry-client';
|
|
3
6
|
export declare class ArchiverInstrumentation {
|
|
4
7
|
private telemetry;
|
|
5
8
|
readonly tracer: Tracer;
|
|
6
9
|
private blockHeight;
|
|
10
|
+
private checkpointHeight;
|
|
7
11
|
private txCount;
|
|
8
12
|
private l1BlockHeight;
|
|
9
13
|
private proofsSubmittedDelay;
|
|
@@ -12,20 +16,23 @@ export declare class ArchiverInstrumentation {
|
|
|
12
16
|
private pruneDuration;
|
|
13
17
|
private pruneCount;
|
|
14
18
|
private syncDurationPerBlock;
|
|
19
|
+
private syncDurationPerCheckpoint;
|
|
15
20
|
private syncBlockCount;
|
|
16
21
|
private manaPerBlock;
|
|
17
22
|
private txsPerBlock;
|
|
18
23
|
private syncDurationPerMessage;
|
|
19
24
|
private syncMessageCount;
|
|
20
25
|
private blockProposalTxTargetCount;
|
|
26
|
+
private checkpointL1InclusionDelay;
|
|
21
27
|
private log;
|
|
22
28
|
private constructor();
|
|
23
29
|
static new(telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback): Promise<ArchiverInstrumentation>;
|
|
24
30
|
isEnabled(): boolean;
|
|
25
|
-
|
|
31
|
+
processNewProposedBlock(syncTimePerBlock: number, block: L2Block): void;
|
|
32
|
+
processNewCheckpointedBlocks(syncTimePerCheckpoint: number, blocks: L2Block[]): void;
|
|
26
33
|
processNewMessages(count: number, syncPerMessageMs: number): void;
|
|
27
34
|
processPrune(duration: number): void;
|
|
28
|
-
|
|
35
|
+
updateLastProvenCheckpoint(checkpoint: CheckpointData): void;
|
|
29
36
|
processProofsVerified(logs: {
|
|
30
37
|
proverId: string;
|
|
31
38
|
l2BlockNumber: bigint;
|
|
@@ -33,5 +40,13 @@ export declare class ArchiverInstrumentation {
|
|
|
33
40
|
}[]): void;
|
|
34
41
|
updateL1BlockHeight(blockNumber: bigint): void;
|
|
35
42
|
recordBlockProposalTxTarget(target: string, usedTrace: boolean): void;
|
|
43
|
+
/**
|
|
44
|
+
* Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
|
|
45
|
+
*/
|
|
46
|
+
processCheckpointL1Timing(data: {
|
|
47
|
+
slotNumber: SlotNumber;
|
|
48
|
+
l1Timestamp: bigint;
|
|
49
|
+
l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>;
|
|
50
|
+
}): void;
|
|
36
51
|
}
|
|
37
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
52
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5zdHJ1bWVudGF0aW9uLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbW9kdWxlcy9pbnN0cnVtZW50YXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFFbEUsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDbkQsT0FBTyxLQUFLLEVBQUUsY0FBYyxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDL0QsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUVyRSxPQUFPLEVBS0wsS0FBSyxpQkFBaUIsRUFFdEIsS0FBSyxlQUFlLEVBQ3BCLEtBQUssTUFBTSxFQUdaLE1BQU0seUJBQXlCLENBQUM7QUFFakMscUJBQWEsdUJBQXVCO0lBOEJoQyxPQUFPLENBQUMsU0FBUztJQTdCbkIsU0FBZ0IsTUFBTSxFQUFFLE1BQU0sQ0FBQztJQUUvQixPQUFPLENBQUMsV0FBVyxDQUFRO0lBQzNCLE9BQU8sQ0FBQyxnQkFBZ0IsQ0FBUTtJQUNoQyxPQUFPLENBQUMsT0FBTyxDQUFnQjtJQUMvQixPQUFPLENBQUMsYUFBYSxDQUFRO0lBQzdCLE9BQU8sQ0FBQyxvQkFBb0IsQ0FBWTtJQUN4QyxPQUFPLENBQUMsb0JBQW9CLENBQWdCO0lBQzVDLE9BQU8sQ0FBQyxTQUFTLENBQWM7SUFFL0IsT0FBTyxDQUFDLGFBQWEsQ0FBWTtJQUNqQyxPQUFPLENBQUMsVUFBVSxDQUFnQjtJQUVsQyxPQUFPLENBQUMsb0JBQW9CLENBQVk7SUFDeEMsT0FBTyxDQUFDLHlCQUF5QixDQUFZO0lBQzdDLE9BQU8sQ0FBQyxjQUFjLENBQWdCO0lBQ3RDLE9BQU8sQ0FBQyxZQUFZLENBQVk7SUFDaEMsT0FBTyxDQUFDLFdBQVcsQ0FBWTtJQUUvQixPQUFPLENBQUMsc0JBQXNCLENBQVk7SUFDMUMsT0FBTyxDQUFDLGdCQUFnQixDQUFnQjtJQUV4QyxPQUFPLENBQUMsMEJBQTBCLENBQWdCO0lBRWxELE9BQU8sQ0FBQywwQkFBMEIsQ0FBWTtJQUU5QyxPQUFPLENBQUMsR0FBRyxDQUE0QztJQUV2RCxPQUFPLGVBd0ROO0lBRUQsT0FBb0IsR0FBRyxDQUFDLFNBQVMsRUFBRSxlQUFlLEVBQUUsU0FBUyxDQUFDLEVBQUUsaUJBQWlCLG9DQU1oRjtJQUVNLFNBQVMsSUFBSSxPQUFPLENBRTFCO0lBRU0sdUJBQXVCLENBQUMsZ0JBQWdCLEVBQUUsTUFBTSxFQUFFLEtBQUssRUFBRSxPQUFPLFFBU3RFO0lBRU0sNEJBQTRCLENBQUMscUJBQXFCLEVBQUUsTUFBTSxFQUFFLE1BQU0sRUFBRSxPQUFPLEVBQUUsUUFTbkY7SUFFTSxrQkFBa0IsQ0FBQyxLQUFLLEVBQUUsTUFBTSxFQUFFLGdCQUFnQixFQUFFLE1BQU0sUUFNaEU7SUFFTSxZQUFZLENBQUMsUUFBUSxFQUFFLE1BQU0sUUFHbkM7SUFFTSwwQkFBMEIsQ0FBQyxVQUFVLEVBQUUsY0FBYyxRQUkzRDtJQUVNLHFCQUFxQixDQUFDLElBQUksRUFBRTtRQUFFLFFBQVEsRUFBRSxNQUFNLENBQUM7UUFBQyxhQUFhLEVBQUUsTUFBTSxDQUFDO1FBQUMsS0FBSyxFQUFFLE1BQU0sQ0FBQTtLQUFFLEVBQUUsUUFXOUY7SUFFTSxtQkFBbUIsQ0FBQyxXQUFXLEVBQUUsTUFBTSxRQUU3QztJQUVNLDJCQUEyQixDQUFDLE1BQU0sRUFBRSxNQUFNLEVBQUUsU0FBUyxFQUFFLE9BQU8sUUFLcEU7SUFFRDs7T0FFRztJQUNJLHlCQUF5QixDQUFDLElBQUksRUFBRTtRQUNyQyxVQUFVLEVBQUUsVUFBVSxDQUFDO1FBQ3ZCLFdBQVcsRUFBRSxNQUFNLENBQUM7UUFDcEIsV0FBVyxFQUFFLElBQUksQ0FBQyxpQkFBaUIsRUFBRSxlQUFlLEdBQUcsY0FBYyxDQUFDLENBQUM7S0FDeEUsR0FBRyxJQUFJLENBSVA7Q0FDRiJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../src/modules/instrumentation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../src/modules/instrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAElE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,EAKL,KAAK,iBAAiB,EAEtB,KAAK,eAAe,EACpB,KAAK,MAAM,EAGZ,MAAM,yBAAyB,CAAC;AAEjC,qBAAa,uBAAuB;IA8BhC,OAAO,CAAC,SAAS;IA7BnB,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,gBAAgB,CAAQ;IAChC,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,aAAa,CAAQ;IAC7B,OAAO,CAAC,oBAAoB,CAAY;IACxC,OAAO,CAAC,oBAAoB,CAAgB;IAC5C,OAAO,CAAC,SAAS,CAAc;IAE/B,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,UAAU,CAAgB;IAElC,OAAO,CAAC,oBAAoB,CAAY;IACxC,OAAO,CAAC,yBAAyB,CAAY;IAC7C,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,YAAY,CAAY;IAChC,OAAO,CAAC,WAAW,CAAY;IAE/B,OAAO,CAAC,sBAAsB,CAAY;IAC1C,OAAO,CAAC,gBAAgB,CAAgB;IAExC,OAAO,CAAC,0BAA0B,CAAgB;IAElD,OAAO,CAAC,0BAA0B,CAAY;IAE9C,OAAO,CAAC,GAAG,CAA4C;IAEvD,OAAO,eAwDN;IAED,OAAoB,GAAG,CAAC,SAAS,EAAE,eAAe,EAAE,SAAS,CAAC,EAAE,iBAAiB,oCAMhF;IAEM,SAAS,IAAI,OAAO,CAE1B;IAEM,uBAAuB,CAAC,gBAAgB,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,QAStE;IAEM,4BAA4B,CAAC,qBAAqB,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QASnF;IAEM,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,QAMhE;IAEM,YAAY,CAAC,QAAQ,EAAE,MAAM,QAGnC;IAEM,0BAA0B,CAAC,UAAU,EAAE,cAAc,QAI3D;IAEM,qBAAqB,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,QAW9F;IAEM,mBAAmB,CAAC,WAAW,EAAE,MAAM,QAE7C;IAEM,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,QAKpE;IAED;;OAEG;IACI,yBAAyB,CAAC,IAAI,EAAE;QACrC,UAAU,EAAE,UAAU,CAAC;QACvB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,GAAG,cAAc,CAAC,CAAC;KACxE,GAAG,IAAI,CAIP;CACF"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
-
import {
|
|
2
|
+
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
3
|
+
import { Attributes, LmdbMetrics, Metrics, createUpDownCounterWithDefault } from '@aztec/telemetry-client';
|
|
3
4
|
export class ArchiverInstrumentation {
|
|
4
5
|
telemetry;
|
|
5
6
|
tracer;
|
|
6
7
|
blockHeight;
|
|
8
|
+
checkpointHeight;
|
|
7
9
|
txCount;
|
|
8
10
|
l1BlockHeight;
|
|
9
11
|
proofsSubmittedDelay;
|
|
@@ -12,12 +14,14 @@ export class ArchiverInstrumentation {
|
|
|
12
14
|
pruneDuration;
|
|
13
15
|
pruneCount;
|
|
14
16
|
syncDurationPerBlock;
|
|
17
|
+
syncDurationPerCheckpoint;
|
|
15
18
|
syncBlockCount;
|
|
16
19
|
manaPerBlock;
|
|
17
20
|
txsPerBlock;
|
|
18
21
|
syncDurationPerMessage;
|
|
19
22
|
syncMessageCount;
|
|
20
23
|
blockProposalTxTargetCount;
|
|
24
|
+
checkpointL1InclusionDelay;
|
|
21
25
|
log;
|
|
22
26
|
constructor(telemetry, lmdbStats){
|
|
23
27
|
this.telemetry = telemetry;
|
|
@@ -25,43 +29,63 @@ export class ArchiverInstrumentation {
|
|
|
25
29
|
this.tracer = telemetry.getTracer('Archiver');
|
|
26
30
|
const meter = telemetry.getMeter('Archiver');
|
|
27
31
|
this.blockHeight = meter.createGauge(Metrics.ARCHIVER_BLOCK_HEIGHT);
|
|
32
|
+
this.checkpointHeight = meter.createGauge(Metrics.ARCHIVER_CHECKPOINT_HEIGHT);
|
|
28
33
|
this.l1BlockHeight = meter.createGauge(Metrics.ARCHIVER_L1_BLOCK_HEIGHT);
|
|
29
|
-
this.txCount = meter
|
|
30
|
-
this.proofsSubmittedCount = meter
|
|
34
|
+
this.txCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_TOTAL_TXS);
|
|
35
|
+
this.proofsSubmittedCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_ROLLUP_PROOF_COUNT, {
|
|
36
|
+
[Attributes.PROOF_TIMED_OUT]: [
|
|
37
|
+
true,
|
|
38
|
+
false
|
|
39
|
+
]
|
|
40
|
+
});
|
|
31
41
|
this.proofsSubmittedDelay = meter.createHistogram(Metrics.ARCHIVER_ROLLUP_PROOF_DELAY);
|
|
32
42
|
this.syncDurationPerBlock = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_BLOCK);
|
|
33
|
-
this.
|
|
43
|
+
this.syncDurationPerCheckpoint = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_CHECKPOINT);
|
|
44
|
+
this.syncBlockCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_BLOCK_COUNT);
|
|
34
45
|
this.manaPerBlock = meter.createHistogram(Metrics.ARCHIVER_MANA_PER_BLOCK);
|
|
35
46
|
this.txsPerBlock = meter.createHistogram(Metrics.ARCHIVER_TXS_PER_BLOCK);
|
|
36
47
|
this.syncDurationPerMessage = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_MESSAGE);
|
|
37
|
-
this.syncMessageCount = meter
|
|
48
|
+
this.syncMessageCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_MESSAGE_COUNT);
|
|
38
49
|
this.pruneDuration = meter.createHistogram(Metrics.ARCHIVER_PRUNE_DURATION);
|
|
39
|
-
this.pruneCount = meter
|
|
40
|
-
this.blockProposalTxTargetCount = meter
|
|
50
|
+
this.pruneCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_PRUNE_COUNT);
|
|
51
|
+
this.blockProposalTxTargetCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_BLOCK_PROPOSAL_TX_TARGET_COUNT, {
|
|
52
|
+
[Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: [
|
|
53
|
+
true,
|
|
54
|
+
false
|
|
55
|
+
]
|
|
56
|
+
});
|
|
57
|
+
this.checkpointL1InclusionDelay = meter.createHistogram(Metrics.ARCHIVER_CHECKPOINT_L1_INCLUSION_DELAY);
|
|
41
58
|
this.dbMetrics = new LmdbMetrics(meter, {
|
|
42
59
|
[Attributes.DB_DATA_TYPE]: 'archiver'
|
|
43
60
|
}, lmdbStats);
|
|
44
61
|
}
|
|
45
62
|
static async new(telemetry, lmdbStats) {
|
|
46
63
|
const instance = new ArchiverInstrumentation(telemetry, lmdbStats);
|
|
47
|
-
instance.syncBlockCount.add(0);
|
|
48
|
-
instance.syncMessageCount.add(0);
|
|
49
|
-
instance.pruneCount.add(0);
|
|
50
64
|
await instance.telemetry.flush();
|
|
51
65
|
return instance;
|
|
52
66
|
}
|
|
53
67
|
isEnabled() {
|
|
54
68
|
return this.telemetry.isEnabled();
|
|
55
69
|
}
|
|
56
|
-
|
|
70
|
+
processNewProposedBlock(syncTimePerBlock, block) {
|
|
71
|
+
const attrs = {
|
|
72
|
+
[Attributes.STATUS]: 'proposed'
|
|
73
|
+
};
|
|
74
|
+
this.blockHeight.record(block.number, attrs);
|
|
57
75
|
this.syncDurationPerBlock.record(Math.ceil(syncTimePerBlock));
|
|
76
|
+
// Per block metrics
|
|
77
|
+
this.txCount.add(block.body.txEffects.length);
|
|
78
|
+
this.txsPerBlock.record(block.body.txEffects.length);
|
|
79
|
+
this.manaPerBlock.record(block.header.totalManaUsed.toNumber() / 1e6);
|
|
80
|
+
}
|
|
81
|
+
processNewCheckpointedBlocks(syncTimePerCheckpoint, blocks) {
|
|
82
|
+
if (blocks.length === 0) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
this.syncDurationPerCheckpoint.record(Math.ceil(syncTimePerCheckpoint));
|
|
58
86
|
this.blockHeight.record(Math.max(...blocks.map((b)=>b.number)));
|
|
87
|
+
this.checkpointHeight.record(Math.max(...blocks.map((b)=>b.checkpointNumber)));
|
|
59
88
|
this.syncBlockCount.add(blocks.length);
|
|
60
|
-
for (const block of blocks){
|
|
61
|
-
this.txCount.add(block.body.txEffects.length);
|
|
62
|
-
this.txsPerBlock.record(block.body.txEffects.length);
|
|
63
|
-
this.manaPerBlock.record(block.header.totalManaUsed.toNumber() / 1e6);
|
|
64
|
-
}
|
|
65
89
|
}
|
|
66
90
|
processNewMessages(count, syncPerMessageMs) {
|
|
67
91
|
if (count === 0) {
|
|
@@ -74,8 +98,12 @@ export class ArchiverInstrumentation {
|
|
|
74
98
|
this.pruneCount.add(1);
|
|
75
99
|
this.pruneDuration.record(Math.ceil(duration));
|
|
76
100
|
}
|
|
77
|
-
|
|
78
|
-
|
|
101
|
+
updateLastProvenCheckpoint(checkpoint) {
|
|
102
|
+
const lastBlockNumberInCheckpoint = checkpoint.startBlock + checkpoint.blockCount - 1;
|
|
103
|
+
this.blockHeight.record(lastBlockNumberInCheckpoint, {
|
|
104
|
+
[Attributes.STATUS]: 'proven'
|
|
105
|
+
});
|
|
106
|
+
this.checkpointHeight.record(checkpoint.checkpointNumber, {
|
|
79
107
|
[Attributes.STATUS]: 'proven'
|
|
80
108
|
});
|
|
81
109
|
}
|
|
@@ -100,4 +128,11 @@ export class ArchiverInstrumentation {
|
|
|
100
128
|
[Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: usedTrace
|
|
101
129
|
});
|
|
102
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
|
|
133
|
+
*/ processCheckpointL1Timing(data) {
|
|
134
|
+
const slotStartTs = getTimestampForSlot(data.slotNumber, data.l1Constants);
|
|
135
|
+
const inclusionDelaySeconds = Number(data.l1Timestamp - slotStartTs);
|
|
136
|
+
this.checkpointL1InclusionDelay.record(inclusionDelaySeconds);
|
|
137
|
+
}
|
|
103
138
|
}
|