@aztec/archiver 0.0.1-commit.e558bd1c → 0.0.1-commit.e5a3663dd
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 +26 -15
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +161 -153
- package/dest/config.d.ts +5 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -4
- package/dest/errors.d.ts +61 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +88 -14
- package/dest/factory.d.ts +6 -7
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +40 -32
- package/dest/index.d.ts +11 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +10 -2
- package/dest/l1/bin/retrieve-calldata.js +32 -28
- package/dest/l1/calldata_retriever.d.ts +74 -50
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +197 -260
- package/dest/l1/data_retrieval.d.ts +26 -17
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +42 -47
- 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_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/contract_data_source_adapter.d.ts +25 -0
- package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
- package/dest/modules/contract_data_source_adapter.js +42 -0
- package/dest/modules/data_source_base.d.ts +27 -14
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +98 -125
- package/dest/modules/data_store_updater.d.ts +37 -17
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +155 -112
- package/dest/modules/instrumentation.d.ts +21 -3
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +41 -8
- package/dest/modules/l1_synchronizer.d.ts +13 -11
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +355 -182
- 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 +107 -31
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +477 -141
- package/dest/store/contract_class_store.d.ts +17 -4
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +24 -68
- package/dest/store/contract_instance_store.d.ts +28 -1
- package/dest/store/contract_instance_store.d.ts.map +1 -1
- package/dest/store/contract_instance_store.js +37 -2
- package/dest/store/data_stores.d.ts +68 -0
- package/dest/store/data_stores.d.ts.map +1 -0
- package/dest/store/data_stores.js +50 -0
- package/dest/store/function_names_cache.d.ts +17 -0
- package/dest/store/function_names_cache.d.ts.map +1 -0
- package/dest/store/function_names_cache.js +30 -0
- 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 +95 -20
- package/dest/store/message_store.d.ts +11 -1
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +51 -9
- package/dest/test/fake_l1_state.d.ts +25 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +166 -32
- 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 +35 -5
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +182 -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 +7 -4
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +14 -8
- package/package.json +13 -13
- package/src/archiver.ts +199 -174
- package/src/config.ts +23 -2
- package/src/errors.ts +133 -22
- package/src/factory.ts +53 -30
- package/src/index.ts +18 -2
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +40 -27
- package/src/l1/calldata_retriever.ts +261 -379
- package/src/l1/data_retrieval.ts +58 -69
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/modules/contract_data_source_adapter.ts +59 -0
- package/src/modules/data_source_base.ts +142 -144
- package/src/modules/data_store_updater.ts +187 -141
- package/src/modules/instrumentation.ts +56 -9
- package/src/modules/l1_synchronizer.ts +463 -218
- package/src/modules/validation.ts +10 -9
- package/src/store/block_store.ts +587 -177
- package/src/store/contract_class_store.ts +31 -103
- package/src/store/contract_instance_store.ts +51 -5
- package/src/store/data_stores.ts +108 -0
- package/src/store/function_names_cache.ts +37 -0
- package/src/store/l2_tips_cache.ts +134 -0
- package/src/store/log_store.ts +128 -32
- package/src/store/message_store.ts +60 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +213 -42
- 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 +230 -82
- package/src/test/mock_structs.ts +20 -6
- package/src/test/noop_l1_archiver.ts +16 -8
- package/dest/store/kv_archiver_store.d.ts +0 -340
- package/dest/store/kv_archiver_store.d.ts.map +0 -1
- package/dest/store/kv_archiver_store.js +0 -446
- package/src/store/kv_archiver_store.ts +0 -639
|
@@ -1,75 +1,107 @@
|
|
|
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";
|
|
11
11
|
return Operation;
|
|
12
12
|
}(Operation || {});
|
|
13
13
|
/** Archiver helper module to handle updates to the data store. */ export class ArchiverDataStoreUpdater {
|
|
14
|
-
|
|
14
|
+
stores;
|
|
15
|
+
l2TipsCache;
|
|
16
|
+
opts;
|
|
15
17
|
log;
|
|
16
|
-
constructor(
|
|
17
|
-
this.
|
|
18
|
+
constructor(stores, l2TipsCache, opts = {}){
|
|
19
|
+
this.stores = stores;
|
|
20
|
+
this.l2TipsCache = l2TipsCache;
|
|
21
|
+
this.opts = opts;
|
|
18
22
|
this.log = createLogger('archiver:store_updater');
|
|
19
23
|
}
|
|
20
24
|
/**
|
|
21
|
-
* Adds proposed
|
|
22
|
-
*
|
|
23
|
-
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events
|
|
24
|
-
* and individually broadcasted functions from the block logs.
|
|
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.
|
|
25
28
|
*
|
|
26
|
-
* @param
|
|
29
|
+
* @param block - The proposed L2 block to add.
|
|
27
30
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
28
31
|
* @returns True if the operation is successful.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
await this.
|
|
32
|
+
*/ async addProposedBlock(block, pendingChainValidationStatus) {
|
|
33
|
+
const result = await this.stores.db.transactionAsync(async ()=>{
|
|
34
|
+
await this.stores.blocks.addProposedBlock(block);
|
|
32
35
|
const opResults = await Promise.all([
|
|
33
36
|
// Update the pending chain validation status if provided
|
|
34
|
-
pendingChainValidationStatus && this.
|
|
35
|
-
// Add any logs emitted during the retrieved
|
|
36
|
-
this.
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
pendingChainValidationStatus && this.stores.blocks.setPendingChainValidationStatus(pendingChainValidationStatus),
|
|
38
|
+
// Add any logs emitted during the retrieved block
|
|
39
|
+
this.stores.logs.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)
|
|
39
44
|
]);
|
|
45
|
+
await this.l2TipsCache?.refresh();
|
|
40
46
|
return opResults.every(Boolean);
|
|
41
47
|
});
|
|
48
|
+
return result;
|
|
42
49
|
}
|
|
43
50
|
/**
|
|
44
51
|
* Reconciles local blocks with incoming checkpoints from L1.
|
|
45
52
|
* Adds new checkpoints to the store with contract class/instance extraction from logs.
|
|
46
53
|
* Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
|
|
47
|
-
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events
|
|
48
|
-
*
|
|
54
|
+
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the checkpoint block logs.
|
|
55
|
+
* If `promoteProposed` is supplied, the proposed-checkpoint promotion runs inside the same transaction
|
|
56
|
+
* as the added checkpoints so both updates are applied atomically.
|
|
49
57
|
*
|
|
50
|
-
* @param checkpoints - The published checkpoints to add.
|
|
58
|
+
* @param checkpoints - The published checkpoints to add (excluding any being promoted from proposed).
|
|
51
59
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
60
|
+
* @param promoteProposed - Optional promotion of the current proposed checkpoint (fast path when blocks are already local).
|
|
52
61
|
* @returns Result with information about any pruned blocks.
|
|
53
|
-
*/ addCheckpoints(checkpoints, pendingChainValidationStatus) {
|
|
54
|
-
|
|
62
|
+
*/ async addCheckpoints(checkpoints, pendingChainValidationStatus, promoteProposed, evictProposedFrom) {
|
|
63
|
+
for (const checkpoint of checkpoints){
|
|
64
|
+
validateCheckpoint(checkpoint.checkpoint, {
|
|
65
|
+
rollupManaLimit: this.opts?.rollupManaLimit
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (promoteProposed) {
|
|
69
|
+
validateCheckpoint(promoteProposed.checkpoint.checkpoint, {
|
|
70
|
+
rollupManaLimit: this.opts?.rollupManaLimit
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const result = await this.stores.db.transactionAsync(async ()=>{
|
|
55
74
|
// Before adding checkpoints, check for conflicts with local blocks if any
|
|
56
75
|
const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
|
|
57
|
-
await this.
|
|
58
|
-
// Filter out blocks that were already inserted via
|
|
76
|
+
await this.stores.blocks.addCheckpoints(checkpoints);
|
|
77
|
+
// Filter out blocks that were already inserted via addProposedBlock() to avoid duplicating logs/contract data
|
|
59
78
|
const newBlocks = checkpoints.flatMap((ch)=>ch.checkpoint.blocks).filter((b)=>lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
|
|
60
79
|
await Promise.all([
|
|
61
80
|
// Update the pending chain validation status if provided
|
|
62
|
-
pendingChainValidationStatus && this.
|
|
81
|
+
pendingChainValidationStatus && this.stores.blocks.setPendingChainValidationStatus(pendingChainValidationStatus),
|
|
63
82
|
// Add any logs emitted during the retrieved blocks
|
|
64
|
-
this.
|
|
83
|
+
this.stores.logs.addLogs(newBlocks),
|
|
65
84
|
// Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
|
|
66
|
-
...newBlocks.map((block)=>this.addContractDataToDb(block))
|
|
85
|
+
...newBlocks.map((block)=>this.addContractDataToDb(block)),
|
|
86
|
+
// Promote the proposed checkpoint if requested (uses explicit checkpoint number)
|
|
87
|
+
promoteProposed ? this.stores.blocks.promoteProposedToCheckpointed(promoteProposed.checkpoint.checkpoint.number, promoteProposed.l1, promoteProposed.attestations, promoteProposed.checkpoint.checkpoint.archive.root) : undefined,
|
|
88
|
+
// Evict pending checkpoints that diverged from what L1 mined
|
|
89
|
+
evictProposedFrom !== undefined ? this.stores.blocks.evictProposedCheckpointsFrom(evictProposedFrom) : undefined
|
|
67
90
|
]);
|
|
91
|
+
await this.l2TipsCache?.refresh();
|
|
68
92
|
return {
|
|
69
93
|
prunedBlocks,
|
|
70
94
|
lastAlreadyInsertedBlockNumber
|
|
71
95
|
};
|
|
72
96
|
});
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
async addProposedCheckpoint(proposedCheckpoint) {
|
|
100
|
+
const result = await this.stores.db.transactionAsync(async ()=>{
|
|
101
|
+
await this.stores.blocks.addProposedCheckpoint(proposedCheckpoint);
|
|
102
|
+
await this.l2TipsCache?.refresh();
|
|
103
|
+
});
|
|
104
|
+
return result;
|
|
73
105
|
}
|
|
74
106
|
/**
|
|
75
107
|
* Checks for local proposed blocks that do not match the ones to be checkpointed and prunes them.
|
|
@@ -78,8 +110,8 @@ import groupBy from 'lodash.groupby';
|
|
|
78
110
|
* and when checkpoints are added afterward, they include all the correct blocks.
|
|
79
111
|
*/ async pruneMismatchingLocalBlocks(checkpoints) {
|
|
80
112
|
const [lastCheckpointedBlockNumber, lastBlockNumber] = await Promise.all([
|
|
81
|
-
this.
|
|
82
|
-
this.
|
|
113
|
+
this.stores.blocks.getCheckpointedL2BlockNumber(),
|
|
114
|
+
this.stores.blocks.getLatestL2BlockNumber()
|
|
83
115
|
]);
|
|
84
116
|
// Exit early if there are no local uncheckpointed blocks
|
|
85
117
|
if (lastBlockNumber === lastCheckpointedBlockNumber) {
|
|
@@ -89,7 +121,7 @@ import groupBy from 'lodash.groupby';
|
|
|
89
121
|
};
|
|
90
122
|
}
|
|
91
123
|
// Get all uncheckpointed local blocks
|
|
92
|
-
const uncheckpointedLocalBlocks = await this.
|
|
124
|
+
const uncheckpointedLocalBlocks = await this.stores.blocks.getBlocks(BlockNumber.add(lastCheckpointedBlockNumber, 1), lastBlockNumber - lastCheckpointedBlockNumber);
|
|
93
125
|
let lastAlreadyInsertedBlockNumber;
|
|
94
126
|
for (const publishedCheckpoint of checkpoints){
|
|
95
127
|
const checkpointBlocks = publishedCheckpoint.checkpoint.blocks;
|
|
@@ -113,7 +145,7 @@ import groupBy from 'lodash.groupby';
|
|
|
113
145
|
this.log.verbose(`Block number ${blockNumber} already inserted and matches checkpoint`, blockInfos);
|
|
114
146
|
lastAlreadyInsertedBlockNumber = blockNumber;
|
|
115
147
|
} else {
|
|
116
|
-
this.log.
|
|
148
|
+
this.log.info(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
|
|
117
149
|
const prunedBlocks = await this.removeBlocksAfter(BlockNumber(blockNumber - 1));
|
|
118
150
|
return {
|
|
119
151
|
prunedBlocks,
|
|
@@ -147,25 +179,30 @@ import groupBy from 'lodash.groupby';
|
|
|
147
179
|
* @param blockNumber - Remove all blocks with number greater than this.
|
|
148
180
|
* @returns The removed blocks.
|
|
149
181
|
* @throws Error if any block to be removed is checkpointed.
|
|
150
|
-
*/ removeUncheckpointedBlocksAfter(blockNumber) {
|
|
151
|
-
|
|
182
|
+
*/ async removeUncheckpointedBlocksAfter(blockNumber) {
|
|
183
|
+
const result = await this.stores.db.transactionAsync(async ()=>{
|
|
152
184
|
// Verify we're only removing uncheckpointed blocks
|
|
153
|
-
const lastCheckpointedBlockNumber = await this.
|
|
185
|
+
const lastCheckpointedBlockNumber = await this.stores.blocks.getCheckpointedL2BlockNumber();
|
|
154
186
|
if (blockNumber < lastCheckpointedBlockNumber) {
|
|
155
187
|
throw new Error(`Cannot remove blocks after ${blockNumber} because checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`);
|
|
156
188
|
}
|
|
157
|
-
|
|
189
|
+
const result = await this.removeBlocksAfter(blockNumber);
|
|
190
|
+
// Clear all pending proposed checkpoints since their blocks have been pruned
|
|
191
|
+
await this.stores.blocks.deleteProposedCheckpoints();
|
|
192
|
+
await this.l2TipsCache?.refresh();
|
|
193
|
+
return result;
|
|
158
194
|
});
|
|
195
|
+
return result;
|
|
159
196
|
}
|
|
160
197
|
/**
|
|
161
198
|
* Removes all blocks strictly after the given block number along with any logs and contract data.
|
|
162
199
|
* Does not remove their checkpoints.
|
|
163
200
|
*/ async removeBlocksAfter(blockNumber) {
|
|
164
201
|
// First get the blocks to be removed so we can clean up contract data
|
|
165
|
-
const removedBlocks = await this.
|
|
202
|
+
const removedBlocks = await this.stores.blocks.removeBlocksAfter(blockNumber);
|
|
166
203
|
// Clean up contract data and logs for the removed blocks
|
|
167
204
|
await Promise.all([
|
|
168
|
-
this.
|
|
205
|
+
this.stores.logs.deleteLogs(removedBlocks),
|
|
169
206
|
...removedBlocks.map((block)=>this.removeContractDataFromDb(block))
|
|
170
207
|
]);
|
|
171
208
|
return removedBlocks;
|
|
@@ -179,17 +216,38 @@ import groupBy from 'lodash.groupby';
|
|
|
179
216
|
* @param checkpointNumber - Remove all checkpoints strictly after this one.
|
|
180
217
|
* @returns True if the operation is successful.
|
|
181
218
|
*/ async removeCheckpointsAfter(checkpointNumber) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
219
|
+
return await this.stores.db.transactionAsync(async ()=>{
|
|
220
|
+
const { blocksRemoved = [] } = await this.stores.blocks.removeCheckpointsAfter(checkpointNumber);
|
|
221
|
+
const opResults = await Promise.all([
|
|
222
|
+
// Prune rolls back to the last proven block, which is by definition valid
|
|
223
|
+
this.stores.blocks.setPendingChainValidationStatus({
|
|
224
|
+
valid: true
|
|
225
|
+
}),
|
|
226
|
+
// Remove contract data for all blocks being removed
|
|
227
|
+
...blocksRemoved.map((block)=>this.removeContractDataFromDb(block)),
|
|
228
|
+
this.stores.logs.deleteLogs(blocksRemoved)
|
|
229
|
+
]);
|
|
230
|
+
await this.l2TipsCache?.refresh();
|
|
231
|
+
return opResults.every(Boolean);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Updates the proven checkpoint number and refreshes the L2 tips cache.
|
|
236
|
+
* @param checkpointNumber - The checkpoint number to set as proven.
|
|
237
|
+
*/ async setProvenCheckpointNumber(checkpointNumber) {
|
|
238
|
+
await this.stores.db.transactionAsync(async ()=>{
|
|
239
|
+
await this.stores.blocks.setProvenCheckpointNumber(checkpointNumber);
|
|
240
|
+
await this.l2TipsCache?.refresh();
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Updates the finalized checkpoint number and refreshes the L2 tips cache.
|
|
245
|
+
* @param checkpointNumber - The checkpoint number to set as finalized.
|
|
246
|
+
*/ async setFinalizedCheckpointNumber(checkpointNumber) {
|
|
247
|
+
await this.stores.db.transactionAsync(async ()=>{
|
|
248
|
+
await this.stores.blocks.setFinalizedCheckpointNumber(checkpointNumber);
|
|
249
|
+
await this.l2TipsCache?.refresh();
|
|
250
|
+
});
|
|
193
251
|
}
|
|
194
252
|
/** Extracts and stores contract data from a single block. */ addContractDataToDb(block) {
|
|
195
253
|
return this.updateContractDataOnDb(block, 0);
|
|
@@ -204,37 +262,68 @@ import groupBy from 'lodash.groupby';
|
|
|
204
262
|
return (await Promise.all([
|
|
205
263
|
this.updatePublishedContractClasses(contractClassLogs, block.number, operation),
|
|
206
264
|
this.updateDeployedContractInstances(privateLogs, block.number, operation),
|
|
207
|
-
this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation)
|
|
208
|
-
operation === 0 ? this.storeBroadcastedIndividualFunctions(contractClassLogs, block.number) : Promise.resolve(true)
|
|
265
|
+
this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation)
|
|
209
266
|
])).every(Boolean);
|
|
210
267
|
}
|
|
211
268
|
/**
|
|
212
269
|
* Extracts and stores contract classes out of ContractClassPublished events emitted by the class registry contract.
|
|
213
270
|
*/ async updatePublishedContractClasses(allLogs, blockNum, operation) {
|
|
214
271
|
const contractClassPublishedEvents = allLogs.filter((log)=>ContractClassPublishedEvent.isContractClassPublishedEvent(log)).map((log)=>ContractClassPublishedEvent.fromLog(log));
|
|
215
|
-
|
|
272
|
+
if (operation == 1) {
|
|
273
|
+
const contractClasses = contractClassPublishedEvents.map((e)=>e.toContractClassPublic());
|
|
274
|
+
if (contractClasses.length > 0) {
|
|
275
|
+
contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
276
|
+
return await this.stores.contractClasses.deleteContractClasses(contractClasses, blockNum);
|
|
277
|
+
}
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
280
|
+
// Compute bytecode commitments and validate class IDs in a single pass.
|
|
281
|
+
const contractClasses = [];
|
|
282
|
+
for (const event of contractClassPublishedEvents){
|
|
283
|
+
const contractClass = await event.toContractClassPublicWithBytecodeCommitment();
|
|
284
|
+
const computedClassId = await computeContractClassId({
|
|
285
|
+
artifactHash: contractClass.artifactHash,
|
|
286
|
+
privateFunctionsRoot: contractClass.privateFunctionsRoot,
|
|
287
|
+
publicBytecodeCommitment: contractClass.publicBytecodeCommitment
|
|
288
|
+
});
|
|
289
|
+
if (!computedClassId.equals(contractClass.id)) {
|
|
290
|
+
this.log.warn(`Skipping contract class with mismatched id at block ${blockNum}. Claimed ${contractClass.id}, computed ${computedClassId}`, {
|
|
291
|
+
blockNum,
|
|
292
|
+
contractClassId: event.contractClassId.toString()
|
|
293
|
+
});
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
contractClasses.push(contractClass);
|
|
297
|
+
}
|
|
216
298
|
if (contractClasses.length > 0) {
|
|
217
299
|
contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
218
|
-
|
|
219
|
-
// TODO: Will probably want to create some worker threads to compute these bytecode commitments as they are expensive
|
|
220
|
-
const commitments = await Promise.all(contractClasses.map((c)=>computePublicBytecodeCommitment(c.packedBytecode)));
|
|
221
|
-
return await this.store.addContractClasses(contractClasses, commitments, blockNum);
|
|
222
|
-
} else if (operation == 1) {
|
|
223
|
-
return await this.store.deleteContractClasses(contractClasses, blockNum);
|
|
224
|
-
}
|
|
300
|
+
return await this.stores.contractClasses.addContractClasses(contractClasses, blockNum);
|
|
225
301
|
}
|
|
226
302
|
return true;
|
|
227
303
|
}
|
|
228
304
|
/**
|
|
229
305
|
* Extracts and stores contract instances out of ContractInstancePublished events emitted by the canonical deployer contract.
|
|
230
306
|
*/ async updateDeployedContractInstances(allLogs, blockNum, operation) {
|
|
231
|
-
const
|
|
307
|
+
const allInstances = allLogs.filter((log)=>ContractInstancePublishedEvent.isContractInstancePublishedEvent(log)).map((log)=>ContractInstancePublishedEvent.fromLog(log)).map((e)=>e.toContractInstance());
|
|
308
|
+
// Verify that each instance's address matches the one derived from its fields if we're adding
|
|
309
|
+
const contractInstances = operation === 1 ? allInstances : await filterAsync(allInstances, async (instance)=>{
|
|
310
|
+
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
311
|
+
if (!computedAddress.equals(instance.address)) {
|
|
312
|
+
this.log.warn(`Found contract instance with mismatched address at block ${blockNum}. Claimed ${instance.address} but computed ${computedAddress}.`, {
|
|
313
|
+
instanceAddress: instance.address.toString(),
|
|
314
|
+
computedAddress: computedAddress.toString(),
|
|
315
|
+
blockNum
|
|
316
|
+
});
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
return true;
|
|
320
|
+
});
|
|
232
321
|
if (contractInstances.length > 0) {
|
|
233
322
|
contractInstances.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance at ${c.address.toString()}`));
|
|
234
323
|
if (operation == 0) {
|
|
235
|
-
return await this.
|
|
324
|
+
return await this.stores.contractInstances.addContractInstances(contractInstances, blockNum);
|
|
236
325
|
} else if (operation == 1) {
|
|
237
|
-
return await this.
|
|
326
|
+
return await this.stores.contractInstances.deleteContractInstances(contractInstances);
|
|
238
327
|
}
|
|
239
328
|
}
|
|
240
329
|
return true;
|
|
@@ -246,56 +335,10 @@ import groupBy from 'lodash.groupby';
|
|
|
246
335
|
if (contractUpdates.length > 0) {
|
|
247
336
|
contractUpdates.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance update at ${c.address.toString()}`));
|
|
248
337
|
if (operation == 0) {
|
|
249
|
-
return await this.
|
|
338
|
+
return await this.stores.contractInstances.addContractInstanceUpdates(contractUpdates, timestamp);
|
|
250
339
|
} else if (operation == 1) {
|
|
251
|
-
return await this.
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return true;
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Stores the functions that were broadcasted individually.
|
|
258
|
-
*
|
|
259
|
-
* @dev Beware that there is not a delete variant of this, since they are added to contract classes
|
|
260
|
-
* and will be deleted as part of the class if needed.
|
|
261
|
-
*/ async storeBroadcastedIndividualFunctions(allLogs, _blockNum) {
|
|
262
|
-
// Filter out private and utility function broadcast events
|
|
263
|
-
const privateFnEvents = allLogs.filter((log)=>PrivateFunctionBroadcastedEvent.isPrivateFunctionBroadcastedEvent(log)).map((log)=>PrivateFunctionBroadcastedEvent.fromLog(log));
|
|
264
|
-
const utilityFnEvents = allLogs.filter((log)=>UtilityFunctionBroadcastedEvent.isUtilityFunctionBroadcastedEvent(log)).map((log)=>UtilityFunctionBroadcastedEvent.fromLog(log));
|
|
265
|
-
// Group all events by contract class id
|
|
266
|
-
for (const [classIdString, classEvents] of Object.entries(groupBy([
|
|
267
|
-
...privateFnEvents,
|
|
268
|
-
...utilityFnEvents
|
|
269
|
-
], (e)=>e.contractClassId.toString()))){
|
|
270
|
-
const contractClassId = Fr.fromHexString(classIdString);
|
|
271
|
-
const contractClass = await this.store.getContractClass(contractClassId);
|
|
272
|
-
if (!contractClass) {
|
|
273
|
-
this.log.warn(`Skipping broadcasted functions as contract class ${contractClassId.toString()} was not found`);
|
|
274
|
-
continue;
|
|
275
|
-
}
|
|
276
|
-
// Split private and utility functions, and filter out invalid ones
|
|
277
|
-
const allFns = classEvents.map((e)=>e.toFunctionWithMembershipProof());
|
|
278
|
-
const privateFns = allFns.filter((fn)=>'utilityFunctionsTreeRoot' in fn);
|
|
279
|
-
const utilityFns = allFns.filter((fn)=>'privateFunctionsArtifactTreeRoot' in fn);
|
|
280
|
-
const privateFunctionsWithValidity = await Promise.all(privateFns.map(async (fn)=>({
|
|
281
|
-
fn,
|
|
282
|
-
valid: await isValidPrivateFunctionMembershipProof(fn, contractClass)
|
|
283
|
-
})));
|
|
284
|
-
const validPrivateFns = privateFunctionsWithValidity.filter(({ valid })=>valid).map(({ fn })=>fn);
|
|
285
|
-
const utilityFunctionsWithValidity = await Promise.all(utilityFns.map(async (fn)=>({
|
|
286
|
-
fn,
|
|
287
|
-
valid: await isValidUtilityFunctionMembershipProof(fn, contractClass)
|
|
288
|
-
})));
|
|
289
|
-
const validUtilityFns = utilityFunctionsWithValidity.filter(({ valid })=>valid).map(({ fn })=>fn);
|
|
290
|
-
const validFnCount = validPrivateFns.length + validUtilityFns.length;
|
|
291
|
-
if (validFnCount !== allFns.length) {
|
|
292
|
-
this.log.warn(`Skipping ${allFns.length - validFnCount} invalid functions`);
|
|
293
|
-
}
|
|
294
|
-
// Store the functions in the contract class in a single operation
|
|
295
|
-
if (validFnCount > 0) {
|
|
296
|
-
this.log.verbose(`Storing ${validFnCount} functions for contract class ${contractClassId.toString()}`);
|
|
340
|
+
return await this.stores.contractInstances.deleteContractInstanceUpdates(contractUpdates, timestamp);
|
|
297
341
|
}
|
|
298
|
-
return await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
|
|
299
342
|
}
|
|
300
343
|
return true;
|
|
301
344
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
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,24 @@ 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;
|
|
27
|
+
private checkpointPromotedCount;
|
|
21
28
|
private log;
|
|
22
29
|
private constructor();
|
|
23
30
|
static new(telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback): Promise<ArchiverInstrumentation>;
|
|
24
31
|
isEnabled(): boolean;
|
|
25
|
-
|
|
32
|
+
processNewProposedBlock(syncTimePerBlock: number, block: L2Block): void;
|
|
33
|
+
processNewCheckpointedBlocks(syncTimePerCheckpoint: number, blocks: L2Block[]): void;
|
|
26
34
|
processNewMessages(count: number, syncPerMessageMs: number): void;
|
|
27
35
|
processPrune(duration: number): void;
|
|
28
|
-
|
|
36
|
+
updateLastProvenCheckpoint(checkpoint: CheckpointData): void;
|
|
29
37
|
processProofsVerified(logs: {
|
|
30
38
|
proverId: string;
|
|
31
39
|
l2BlockNumber: bigint;
|
|
@@ -33,5 +41,15 @@ export declare class ArchiverInstrumentation {
|
|
|
33
41
|
}[]): void;
|
|
34
42
|
updateL1BlockHeight(blockNumber: bigint): void;
|
|
35
43
|
recordBlockProposalTxTarget(target: string, usedTrace: boolean): void;
|
|
44
|
+
/** Records a checkpoint promoted from proposed (blob fetch skipped). */
|
|
45
|
+
processCheckpointPromoted(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
|
|
48
|
+
*/
|
|
49
|
+
processCheckpointL1Timing(data: {
|
|
50
|
+
slotNumber: SlotNumber;
|
|
51
|
+
l1Timestamp: bigint;
|
|
52
|
+
l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>;
|
|
53
|
+
}): void;
|
|
36
54
|
}
|
|
37
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
55
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5zdHJ1bWVudGF0aW9uLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbW9kdWxlcy9pbnN0cnVtZW50YXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFFbEUsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDbkQsT0FBTyxLQUFLLEVBQUUsY0FBYyxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDL0QsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUVyRSxPQUFPLEVBS0wsS0FBSyxpQkFBaUIsRUFFdEIsS0FBSyxlQUFlLEVBQ3BCLEtBQUssTUFBTSxFQUdaLE1BQU0seUJBQXlCLENBQUM7QUFFakMscUJBQWEsdUJBQXVCO0lBK0JoQyxPQUFPLENBQUMsU0FBUztJQTlCbkIsU0FBZ0IsTUFBTSxFQUFFLE1BQU0sQ0FBQztJQUUvQixPQUFPLENBQUMsV0FBVyxDQUFRO0lBQzNCLE9BQU8sQ0FBQyxnQkFBZ0IsQ0FBUTtJQUNoQyxPQUFPLENBQUMsT0FBTyxDQUFnQjtJQUMvQixPQUFPLENBQUMsYUFBYSxDQUFRO0lBQzdCLE9BQU8sQ0FBQyxvQkFBb0IsQ0FBWTtJQUN4QyxPQUFPLENBQUMsb0JBQW9CLENBQWdCO0lBQzVDLE9BQU8sQ0FBQyxTQUFTLENBQWM7SUFFL0IsT0FBTyxDQUFDLGFBQWEsQ0FBWTtJQUNqQyxPQUFPLENBQUMsVUFBVSxDQUFnQjtJQUVsQyxPQUFPLENBQUMsb0JBQW9CLENBQVk7SUFDeEMsT0FBTyxDQUFDLHlCQUF5QixDQUFZO0lBQzdDLE9BQU8sQ0FBQyxjQUFjLENBQWdCO0lBQ3RDLE9BQU8sQ0FBQyxZQUFZLENBQVk7SUFDaEMsT0FBTyxDQUFDLFdBQVcsQ0FBWTtJQUUvQixPQUFPLENBQUMsc0JBQXNCLENBQVk7SUFDMUMsT0FBTyxDQUFDLGdCQUFnQixDQUFnQjtJQUV4QyxPQUFPLENBQUMsMEJBQTBCLENBQWdCO0lBRWxELE9BQU8sQ0FBQywwQkFBMEIsQ0FBWTtJQUM5QyxPQUFPLENBQUMsdUJBQXVCLENBQWdCO0lBRS9DLE9BQU8sQ0FBQyxHQUFHLENBQTRDO0lBRXZELE9BQU8sZUEwRE47SUFFRCxPQUFvQixHQUFHLENBQUMsU0FBUyxFQUFFLGVBQWUsRUFBRSxTQUFTLENBQUMsRUFBRSxpQkFBaUIsb0NBTWhGO0lBRU0sU0FBUyxJQUFJLE9BQU8sQ0FFMUI7SUFFTSx1QkFBdUIsQ0FBQyxnQkFBZ0IsRUFBRSxNQUFNLEVBQUUsS0FBSyxFQUFFLE9BQU8sUUFTdEU7SUFFTSw0QkFBNEIsQ0FBQyxxQkFBcUIsRUFBRSxNQUFNLEVBQUUsTUFBTSxFQUFFLE9BQU8sRUFBRSxRQVNuRjtJQUVNLGtCQUFrQixDQUFDLEtBQUssRUFBRSxNQUFNLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxRQU1oRTtJQUVNLFlBQVksQ0FBQyxRQUFRLEVBQUUsTUFBTSxRQUduQztJQUVNLDBCQUEwQixDQUFDLFVBQVUsRUFBRSxjQUFjLFFBSTNEO0lBRU0scUJBQXFCLENBQUMsSUFBSSxFQUFFO1FBQUUsUUFBUSxFQUFFLE1BQU0sQ0FBQztRQUFDLGFBQWEsRUFBRSxNQUFNLENBQUM7UUFBQyxLQUFLLEVBQUUsTUFBTSxDQUFBO0tBQUUsRUFBRSxRQVc5RjtJQUVNLG1CQUFtQixDQUFDLFdBQVcsRUFBRSxNQUFNLFFBRTdDO0lBRU0sMkJBQTJCLENBQUMsTUFBTSxFQUFFLE1BQU0sRUFBRSxTQUFTLEVBQUUsT0FBTyxRQUtwRTtJQUVELHdFQUF3RTtJQUNqRSx5QkFBeUIsU0FFL0I7SUFFRDs7T0FFRztJQUNJLHlCQUF5QixDQUFDLElBQUksRUFBRTtRQUNyQyxVQUFVLEVBQUUsVUFBVSxDQUFDO1FBQ3ZCLFdBQVcsRUFBRSxNQUFNLENBQUM7UUFDcEIsV0FBVyxFQUFFLElBQUksQ0FBQyxpQkFBaUIsRUFBRSxlQUFlLEdBQUcsY0FBYyxDQUFDLENBQUM7S0FDeEUsR0FBRyxJQUFJLENBSVA7Q0FDRiJ9
|
|
@@ -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;IA+BhC,OAAO,CAAC,SAAS;IA9BnB,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;IAC9C,OAAO,CAAC,uBAAuB,CAAgB;IAE/C,OAAO,CAAC,GAAG,CAA4C;IAEvD,OAAO,eA0DN;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,wEAAwE;IACjE,yBAAyB,SAE/B;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 { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
2
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,15 @@ 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;
|
|
25
|
+
checkpointPromotedCount;
|
|
21
26
|
log;
|
|
22
27
|
constructor(telemetry, lmdbStats){
|
|
23
28
|
this.telemetry = telemetry;
|
|
@@ -25,6 +30,7 @@ export class ArchiverInstrumentation {
|
|
|
25
30
|
this.tracer = telemetry.getTracer('Archiver');
|
|
26
31
|
const meter = telemetry.getMeter('Archiver');
|
|
27
32
|
this.blockHeight = meter.createGauge(Metrics.ARCHIVER_BLOCK_HEIGHT);
|
|
33
|
+
this.checkpointHeight = meter.createGauge(Metrics.ARCHIVER_CHECKPOINT_HEIGHT);
|
|
28
34
|
this.l1BlockHeight = meter.createGauge(Metrics.ARCHIVER_L1_BLOCK_HEIGHT);
|
|
29
35
|
this.txCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_TOTAL_TXS);
|
|
30
36
|
this.proofsSubmittedCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_ROLLUP_PROOF_COUNT, {
|
|
@@ -35,6 +41,7 @@ export class ArchiverInstrumentation {
|
|
|
35
41
|
});
|
|
36
42
|
this.proofsSubmittedDelay = meter.createHistogram(Metrics.ARCHIVER_ROLLUP_PROOF_DELAY);
|
|
37
43
|
this.syncDurationPerBlock = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_BLOCK);
|
|
44
|
+
this.syncDurationPerCheckpoint = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_CHECKPOINT);
|
|
38
45
|
this.syncBlockCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_BLOCK_COUNT);
|
|
39
46
|
this.manaPerBlock = meter.createHistogram(Metrics.ARCHIVER_MANA_PER_BLOCK);
|
|
40
47
|
this.txsPerBlock = meter.createHistogram(Metrics.ARCHIVER_TXS_PER_BLOCK);
|
|
@@ -48,6 +55,8 @@ export class ArchiverInstrumentation {
|
|
|
48
55
|
false
|
|
49
56
|
]
|
|
50
57
|
});
|
|
58
|
+
this.checkpointL1InclusionDelay = meter.createHistogram(Metrics.ARCHIVER_CHECKPOINT_L1_INCLUSION_DELAY);
|
|
59
|
+
this.checkpointPromotedCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_CHECKPOINT_PROMOTED_COUNT);
|
|
51
60
|
this.dbMetrics = new LmdbMetrics(meter, {
|
|
52
61
|
[Attributes.DB_DATA_TYPE]: 'archiver'
|
|
53
62
|
}, lmdbStats);
|
|
@@ -60,15 +69,25 @@ export class ArchiverInstrumentation {
|
|
|
60
69
|
isEnabled() {
|
|
61
70
|
return this.telemetry.isEnabled();
|
|
62
71
|
}
|
|
63
|
-
|
|
72
|
+
processNewProposedBlock(syncTimePerBlock, block) {
|
|
73
|
+
const attrs = {
|
|
74
|
+
[Attributes.STATUS]: 'proposed'
|
|
75
|
+
};
|
|
76
|
+
this.blockHeight.record(block.number, attrs);
|
|
64
77
|
this.syncDurationPerBlock.record(Math.ceil(syncTimePerBlock));
|
|
78
|
+
// Per block metrics
|
|
79
|
+
this.txCount.add(block.body.txEffects.length);
|
|
80
|
+
this.txsPerBlock.record(block.body.txEffects.length);
|
|
81
|
+
this.manaPerBlock.record(block.header.totalManaUsed.toNumber() / 1e6);
|
|
82
|
+
}
|
|
83
|
+
processNewCheckpointedBlocks(syncTimePerCheckpoint, blocks) {
|
|
84
|
+
if (blocks.length === 0) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
this.syncDurationPerCheckpoint.record(Math.ceil(syncTimePerCheckpoint));
|
|
65
88
|
this.blockHeight.record(Math.max(...blocks.map((b)=>b.number)));
|
|
89
|
+
this.checkpointHeight.record(Math.max(...blocks.map((b)=>b.checkpointNumber)));
|
|
66
90
|
this.syncBlockCount.add(blocks.length);
|
|
67
|
-
for (const block of blocks){
|
|
68
|
-
this.txCount.add(block.body.txEffects.length);
|
|
69
|
-
this.txsPerBlock.record(block.body.txEffects.length);
|
|
70
|
-
this.manaPerBlock.record(block.header.totalManaUsed.toNumber() / 1e6);
|
|
71
|
-
}
|
|
72
91
|
}
|
|
73
92
|
processNewMessages(count, syncPerMessageMs) {
|
|
74
93
|
if (count === 0) {
|
|
@@ -81,8 +100,12 @@ export class ArchiverInstrumentation {
|
|
|
81
100
|
this.pruneCount.add(1);
|
|
82
101
|
this.pruneDuration.record(Math.ceil(duration));
|
|
83
102
|
}
|
|
84
|
-
|
|
85
|
-
|
|
103
|
+
updateLastProvenCheckpoint(checkpoint) {
|
|
104
|
+
const lastBlockNumberInCheckpoint = checkpoint.startBlock + checkpoint.blockCount - 1;
|
|
105
|
+
this.blockHeight.record(lastBlockNumberInCheckpoint, {
|
|
106
|
+
[Attributes.STATUS]: 'proven'
|
|
107
|
+
});
|
|
108
|
+
this.checkpointHeight.record(checkpoint.checkpointNumber, {
|
|
86
109
|
[Attributes.STATUS]: 'proven'
|
|
87
110
|
});
|
|
88
111
|
}
|
|
@@ -107,4 +130,14 @@ export class ArchiverInstrumentation {
|
|
|
107
130
|
[Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: usedTrace
|
|
108
131
|
});
|
|
109
132
|
}
|
|
133
|
+
/** Records a checkpoint promoted from proposed (blob fetch skipped). */ processCheckpointPromoted() {
|
|
134
|
+
this.checkpointPromotedCount.add(1);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
|
|
138
|
+
*/ processCheckpointL1Timing(data) {
|
|
139
|
+
const slotStartTs = getTimestampForSlot(data.slotNumber, data.l1Constants);
|
|
140
|
+
const inclusionDelaySeconds = Number(data.l1Timestamp - slotStartTs);
|
|
141
|
+
this.checkpointL1InclusionDelay.record(inclusionDelaySeconds);
|
|
142
|
+
}
|
|
110
143
|
}
|