@aztec/archiver 5.0.0-private.20260319 → 5.0.0-rc.2
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 +19 -13
- package/dest/archiver.d.ts +71 -15
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +268 -74
- package/dest/config.d.ts +7 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +39 -16
- package/dest/errors.d.ts +44 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +66 -12
- package/dest/factory.d.ts +12 -7
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +40 -25
- package/dest/index.d.ts +11 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +10 -2
- 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 +15 -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/trace_tx.d.ts +12 -66
- package/dest/l1/trace_tx.d.ts.map +1 -1
- 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 +32 -0
- package/dest/modules/data_source_base.d.ts +72 -48
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +266 -143
- package/dest/modules/data_store_updater.d.ts +30 -13
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +172 -117
- package/dest/modules/instrumentation.d.ts +7 -2
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +25 -7
- package/dest/modules/l1_synchronizer.d.ts +11 -6
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +437 -217
- package/dest/modules/outbox_trees_resolver.d.ts +62 -0
- package/dest/modules/outbox_trees_resolver.d.ts.map +1 -0
- package/dest/modules/outbox_trees_resolver.js +162 -0
- package/dest/modules/validation.d.ts +24 -5
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +40 -15
- package/dest/store/block_store.d.ts +164 -66
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +638 -233
- 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 +36 -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 +48 -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 +54 -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 +13 -7
- package/dest/store/l2_tips_cache.d.ts.map +1 -1
- package/dest/store/l2_tips_cache.js +13 -76
- package/dest/store/log_store.d.ts +42 -40
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +257 -480
- package/dest/store/log_store_codec.d.ts +78 -0
- package/dest/store/log_store_codec.d.ts.map +1 -0
- package/dest/store/log_store_codec.js +110 -0
- package/dest/store/message_store.d.ts +9 -3
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +39 -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_l2_block_source.d.ts +48 -50
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +223 -179
- package/dest/test/mock_structs.d.ts +1 -1
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +2 -2
- package/dest/test/noop_l1_archiver.d.ts +14 -6
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +25 -9
- package/package.json +14 -14
- package/src/archiver.ts +353 -80
- package/src/config.ts +43 -20
- package/src/errors.ts +103 -18
- package/src/factory.ts +56 -24
- package/src/index.ts +18 -2
- package/src/l1/calldata_retriever.ts +16 -5
- package/src/l1/data_retrieval.ts +38 -46
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/modules/contract_data_source_adapter.ts +46 -0
- package/src/modules/data_source_base.ts +340 -189
- package/src/modules/data_store_updater.ts +211 -148
- package/src/modules/instrumentation.ts +28 -8
- package/src/modules/l1_synchronizer.ts +583 -255
- package/src/modules/outbox_trees_resolver.ts +199 -0
- package/src/modules/validation.ts +81 -21
- package/src/store/block_store.ts +792 -285
- package/src/store/contract_class_store.ts +43 -103
- package/src/store/contract_instance_store.ts +62 -5
- package/src/store/data_stores.ts +104 -0
- package/src/store/function_names_cache.ts +37 -0
- package/src/store/l2_tips_cache.ts +16 -70
- package/src/store/log_store.ts +296 -652
- package/src/store/log_store_codec.ts +143 -0
- package/src/store/message_store.ts +43 -12
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +99 -27
- package/src/test/mock_l2_block_source.ts +279 -233
- package/src/test/mock_structs.ts +5 -2
- package/src/test/noop_l1_archiver.ts +52 -9
- package/dest/store/kv_archiver_store.d.ts +0 -367
- package/dest/store/kv_archiver_store.d.ts.map +0 -1
- package/dest/store/kv_archiver_store.js +0 -481
- package/src/store/kv_archiver_store.ts +0 -697
|
@@ -1,23 +1,23 @@
|
|
|
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
6
|
import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
7
|
+
import { computeContractAddressFromInstance, computeContractClassId } from '@aztec/stdlib/contract';
|
|
8
|
+
import { MAX_CAPACITY_BLOCKS_PER_CHECKPOINT } from '@aztec/stdlib/deserialization';
|
|
9
9
|
/** Operation type for contract data updates. */ var Operation = /*#__PURE__*/ function(Operation) {
|
|
10
10
|
Operation[Operation["Store"] = 0] = "Store";
|
|
11
11
|
Operation[Operation["Delete"] = 1] = "Delete";
|
|
12
12
|
return Operation;
|
|
13
13
|
}(Operation || {});
|
|
14
14
|
/** Archiver helper module to handle updates to the data store. */ export class ArchiverDataStoreUpdater {
|
|
15
|
-
|
|
15
|
+
stores;
|
|
16
16
|
l2TipsCache;
|
|
17
17
|
opts;
|
|
18
18
|
log;
|
|
19
|
-
constructor(
|
|
20
|
-
this.
|
|
19
|
+
constructor(stores, l2TipsCache, opts = {}){
|
|
20
|
+
this.stores = stores;
|
|
21
21
|
this.l2TipsCache = l2TipsCache;
|
|
22
22
|
this.opts = opts;
|
|
23
23
|
this.log = createLogger('archiver:store_updater');
|
|
@@ -25,77 +25,106 @@ import groupBy from 'lodash.groupby';
|
|
|
25
25
|
/**
|
|
26
26
|
* Adds a proposed block to the store with contract class/instance extraction from logs.
|
|
27
27
|
* This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
28
|
-
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events
|
|
29
|
-
* and individually broadcasted functions from the block logs.
|
|
28
|
+
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the block logs.
|
|
30
29
|
*
|
|
31
30
|
* @param block - The proposed L2 block to add.
|
|
32
31
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
33
32
|
* @returns True if the operation is successful.
|
|
34
33
|
*/ async addProposedBlock(block, pendingChainValidationStatus) {
|
|
35
|
-
const result = await this.
|
|
36
|
-
await this.
|
|
34
|
+
const result = await this.stores.db.transactionAsync(async ()=>{
|
|
35
|
+
await this.stores.blocks.addProposedBlock(block);
|
|
37
36
|
const opResults = await Promise.all([
|
|
38
37
|
// Update the pending chain validation status if provided
|
|
39
|
-
pendingChainValidationStatus && this.
|
|
38
|
+
pendingChainValidationStatus && this.stores.blocks.setPendingChainValidationStatus(pendingChainValidationStatus),
|
|
40
39
|
// Add any logs emitted during the retrieved block
|
|
41
|
-
this.
|
|
40
|
+
this.stores.logs.addLogs([
|
|
42
41
|
block
|
|
43
42
|
]),
|
|
44
43
|
// Unroll all logs emitted during the retrieved block and extract any contract classes and instances from it
|
|
45
44
|
this.addContractDataToDb(block)
|
|
46
45
|
]);
|
|
47
|
-
await this.l2TipsCache?.refresh();
|
|
48
46
|
return opResults.every(Boolean);
|
|
49
47
|
});
|
|
48
|
+
await this.l2TipsCache?.refresh();
|
|
50
49
|
return result;
|
|
51
50
|
}
|
|
52
51
|
/**
|
|
53
52
|
* Reconciles local blocks with incoming checkpoints from L1.
|
|
54
53
|
* Adds new checkpoints to the store with contract class/instance extraction from logs.
|
|
55
54
|
* Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
|
|
56
|
-
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events
|
|
57
|
-
*
|
|
55
|
+
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the checkpoint block logs.
|
|
56
|
+
* If `promoteProposed` is supplied, the proposed-checkpoint promotion runs inside the same transaction
|
|
57
|
+
* as the added checkpoints so both updates are applied atomically.
|
|
58
58
|
*
|
|
59
|
-
* @param checkpoints - The published checkpoints to add.
|
|
59
|
+
* @param checkpoints - The published checkpoints to add (excluding any being promoted from proposed).
|
|
60
60
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
61
|
+
* @param promoteProposed - Optional promotion of the current proposed checkpoint (fast path when blocks are already local).
|
|
61
62
|
* @returns Result with information about any pruned blocks.
|
|
62
|
-
*/ async addCheckpoints(checkpoints, pendingChainValidationStatus) {
|
|
63
|
+
*/ async addCheckpoints(checkpoints, pendingChainValidationStatus, promoteProposed, evictProposedFrom) {
|
|
64
|
+
// Checkpoints here are already accepted by L1, so tolerate up to the physical blob-capacity
|
|
65
|
+
// ceiling rather than the conservative attestable limit used when building/attesting.
|
|
63
66
|
for (const checkpoint of checkpoints){
|
|
64
67
|
validateCheckpoint(checkpoint.checkpoint, {
|
|
65
|
-
rollupManaLimit: this.opts?.rollupManaLimit
|
|
68
|
+
rollupManaLimit: this.opts?.rollupManaLimit,
|
|
69
|
+
maxBlocksPerCheckpoint: MAX_CAPACITY_BLOCKS_PER_CHECKPOINT
|
|
66
70
|
});
|
|
67
71
|
}
|
|
68
|
-
|
|
72
|
+
if (promoteProposed) {
|
|
73
|
+
validateCheckpoint(promoteProposed.checkpoint.checkpoint, {
|
|
74
|
+
rollupManaLimit: this.opts?.rollupManaLimit,
|
|
75
|
+
maxBlocksPerCheckpoint: MAX_CAPACITY_BLOCKS_PER_CHECKPOINT
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const result = await this.stores.db.transactionAsync(async ()=>{
|
|
69
79
|
// Before adding checkpoints, check for conflicts with local blocks if any
|
|
70
80
|
const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
|
|
71
|
-
await this.
|
|
81
|
+
await this.stores.blocks.addCheckpoints(checkpoints);
|
|
72
82
|
// Filter out blocks that were already inserted via addProposedBlock() to avoid duplicating logs/contract data
|
|
73
83
|
const newBlocks = checkpoints.flatMap((ch)=>ch.checkpoint.blocks).filter((b)=>lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
|
|
74
84
|
await Promise.all([
|
|
75
85
|
// Update the pending chain validation status if provided
|
|
76
|
-
pendingChainValidationStatus && this.
|
|
86
|
+
pendingChainValidationStatus && this.stores.blocks.setPendingChainValidationStatus(pendingChainValidationStatus),
|
|
77
87
|
// Add any logs emitted during the retrieved blocks
|
|
78
|
-
this.
|
|
88
|
+
this.stores.logs.addLogs(newBlocks),
|
|
79
89
|
// Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
|
|
80
|
-
...newBlocks.map((block)=>this.addContractDataToDb(block))
|
|
90
|
+
...newBlocks.map((block)=>this.addContractDataToDb(block)),
|
|
91
|
+
// Promote the proposed checkpoint if requested (uses explicit checkpoint number)
|
|
92
|
+
promoteProposed ? this.stores.blocks.promoteProposedToCheckpointed(promoteProposed.checkpoint.checkpoint.number, promoteProposed.l1, promoteProposed.attestations, promoteProposed.checkpoint.checkpoint.archive.root) : undefined,
|
|
93
|
+
// Evict pending checkpoints that diverged from what L1 mined
|
|
94
|
+
evictProposedFrom !== undefined ? this.stores.blocks.evictProposedCheckpointsFrom(evictProposedFrom) : undefined
|
|
81
95
|
]);
|
|
82
|
-
await this.l2TipsCache?.refresh();
|
|
83
96
|
return {
|
|
84
97
|
prunedBlocks,
|
|
85
98
|
lastAlreadyInsertedBlockNumber
|
|
86
99
|
};
|
|
87
100
|
});
|
|
101
|
+
await this.l2TipsCache?.refresh();
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
async addProposedCheckpoint(proposedCheckpoint) {
|
|
105
|
+
const result = await this.stores.db.transactionAsync(async ()=>{
|
|
106
|
+
await this.stores.blocks.addProposedCheckpoint(proposedCheckpoint);
|
|
107
|
+
});
|
|
108
|
+
await this.l2TipsCache?.refresh();
|
|
88
109
|
return result;
|
|
89
110
|
}
|
|
90
111
|
/**
|
|
91
112
|
* Checks for local proposed blocks that do not match the ones to be checkpointed and prunes them.
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
113
|
+
* Conflict detection is keyed on `blockNumber`: when a local proposed block and an L1
|
|
114
|
+
* checkpointed block share a block number but live at different slots (e.g. a different proposer
|
|
115
|
+
* mined the same block number one slot earlier), we still treat them as a conflict and prune.
|
|
116
|
+
* The trailing per-checkpoint prune that handles "local has extra trailing blocks within the
|
|
117
|
+
* same slot as the published checkpoint" remains scoped by slot to preserve pipelining: local
|
|
118
|
+
* blocks that live at a later slot than the checkpoint being processed represent speculation
|
|
119
|
+
* atop the just-confirmed tip (and may be referenced by a pending proposed checkpoint), so we
|
|
120
|
+
* leave them in place. This method handles multiple checkpoints but returns after pruning the
|
|
121
|
+
* first conflict found. This is correct because pruning from the first conflict point removes
|
|
122
|
+
* all subsequent blocks, and when checkpoints are added afterward, they include all the correct
|
|
123
|
+
* blocks.
|
|
95
124
|
*/ async pruneMismatchingLocalBlocks(checkpoints) {
|
|
96
125
|
const [lastCheckpointedBlockNumber, lastBlockNumber] = await Promise.all([
|
|
97
|
-
this.
|
|
98
|
-
this.
|
|
126
|
+
this.stores.blocks.getCheckpointedL2BlockNumber(),
|
|
127
|
+
this.stores.blocks.getLatestL2BlockNumber()
|
|
99
128
|
]);
|
|
100
129
|
// Exit early if there are no local uncheckpointed blocks
|
|
101
130
|
if (lastBlockNumber === lastCheckpointedBlockNumber) {
|
|
@@ -105,22 +134,25 @@ import groupBy from 'lodash.groupby';
|
|
|
105
134
|
};
|
|
106
135
|
}
|
|
107
136
|
// Get all uncheckpointed local blocks
|
|
108
|
-
const uncheckpointedLocalBlocks = await this.
|
|
137
|
+
const uncheckpointedLocalBlocks = await this.stores.blocks.getBlocksData({
|
|
138
|
+
from: BlockNumber.add(lastCheckpointedBlockNumber, 1),
|
|
139
|
+
limit: lastBlockNumber - lastCheckpointedBlockNumber
|
|
140
|
+
});
|
|
109
141
|
let lastAlreadyInsertedBlockNumber;
|
|
110
142
|
for (const publishedCheckpoint of checkpoints){
|
|
111
143
|
const checkpointBlocks = publishedCheckpoint.checkpoint.blocks;
|
|
112
144
|
const slot = publishedCheckpoint.checkpoint.slot;
|
|
113
|
-
const localBlocksInSlot = uncheckpointedLocalBlocks.filter((b)=>b.slot === slot);
|
|
114
145
|
if (checkpointBlocks.length === 0) {
|
|
115
146
|
this.log.warn(`Checkpoint ${publishedCheckpoint.checkpoint.number} for slot ${slot} has no blocks`);
|
|
116
147
|
continue;
|
|
117
148
|
}
|
|
118
|
-
// Find the first checkpoint block that conflicts with an existing local block and prune local afterwards
|
|
149
|
+
// Find the first checkpoint block that conflicts with an existing local block and prune local afterwards.
|
|
150
|
+
// Conflict detection joins on block number only — same block number at a different slot is still a conflict.
|
|
119
151
|
for (const checkpointBlock of checkpointBlocks){
|
|
120
152
|
const blockNumber = checkpointBlock.number;
|
|
121
|
-
const existingBlock =
|
|
153
|
+
const existingBlock = uncheckpointedLocalBlocks.find((b)=>b.header.getBlockNumber() === blockNumber);
|
|
122
154
|
const blockInfos = {
|
|
123
|
-
existingBlock: existingBlock?.
|
|
155
|
+
existingBlock: existingBlock?.header.toInspect(),
|
|
124
156
|
checkpointBlock: checkpointBlock.toBlockInfo()
|
|
125
157
|
};
|
|
126
158
|
if (!existingBlock) {
|
|
@@ -131,19 +163,23 @@ import groupBy from 'lodash.groupby';
|
|
|
131
163
|
} else {
|
|
132
164
|
this.log.info(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
|
|
133
165
|
const prunedBlocks = await this.removeBlocksAfter(BlockNumber(blockNumber - 1));
|
|
166
|
+
await this.evictProposedCheckpointsForPrunedBlocks(prunedBlocks);
|
|
134
167
|
return {
|
|
135
168
|
prunedBlocks,
|
|
136
169
|
lastAlreadyInsertedBlockNumber
|
|
137
170
|
};
|
|
138
171
|
}
|
|
139
172
|
}
|
|
140
|
-
// If
|
|
141
|
-
//
|
|
173
|
+
// If the sequencer locally proposed extra blocks within this checkpoint's slot (e.g. local has
|
|
174
|
+
// [N, N+1] but L1 confirmed just [N]), prune the extras. Scoped to the checkpoint's slot so we
|
|
175
|
+
// do not throw away speculative blocks at later slots that belong to a pending proposed checkpoint.
|
|
142
176
|
const lastCheckpointBlockNumber = checkpointBlocks.at(-1).number;
|
|
143
|
-
const
|
|
177
|
+
const localBlocksInSlot = uncheckpointedLocalBlocks.filter((b)=>b.header.getSlot() === slot);
|
|
178
|
+
const lastLocalBlockNumber = localBlocksInSlot.at(-1)?.header.getBlockNumber();
|
|
144
179
|
if (lastLocalBlockNumber !== undefined && lastLocalBlockNumber > lastCheckpointBlockNumber) {
|
|
145
180
|
this.log.warn(`Local chain for slot ${slot} ends at block ${lastLocalBlockNumber} but checkpoint ends at ${lastCheckpointBlockNumber}. Pruning blocks after block ${lastCheckpointBlockNumber}.`);
|
|
146
181
|
const prunedBlocks = await this.removeBlocksAfter(lastCheckpointBlockNumber);
|
|
182
|
+
await this.evictProposedCheckpointsForPrunedBlocks(prunedBlocks);
|
|
147
183
|
return {
|
|
148
184
|
prunedBlocks,
|
|
149
185
|
lastAlreadyInsertedBlockNumber
|
|
@@ -164,27 +200,60 @@ import groupBy from 'lodash.groupby';
|
|
|
164
200
|
* @returns The removed blocks.
|
|
165
201
|
* @throws Error if any block to be removed is checkpointed.
|
|
166
202
|
*/ async removeUncheckpointedBlocksAfter(blockNumber) {
|
|
167
|
-
const result = await this.
|
|
203
|
+
const result = await this.stores.db.transactionAsync(async ()=>{
|
|
168
204
|
// Verify we're only removing uncheckpointed blocks
|
|
169
|
-
const lastCheckpointedBlockNumber = await this.
|
|
205
|
+
const lastCheckpointedBlockNumber = await this.stores.blocks.getCheckpointedL2BlockNumber();
|
|
170
206
|
if (blockNumber < lastCheckpointedBlockNumber) {
|
|
171
207
|
throw new Error(`Cannot remove blocks after ${blockNumber} because checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`);
|
|
172
208
|
}
|
|
173
|
-
const
|
|
174
|
-
await this.
|
|
175
|
-
return
|
|
209
|
+
const prunedBlocks = await this.removeBlocksAfter(blockNumber);
|
|
210
|
+
await this.evictProposedCheckpointsForPrunedBlocks(prunedBlocks);
|
|
211
|
+
return prunedBlocks;
|
|
176
212
|
});
|
|
213
|
+
await this.l2TipsCache?.refresh();
|
|
177
214
|
return result;
|
|
178
215
|
}
|
|
179
216
|
/**
|
|
217
|
+
* Removes all blocks without a proposed checkpoint strictly after the specified block number and cleans up associated contract data.
|
|
218
|
+
* This handles removal of provisionally added blocks along with their contract classes/instances.
|
|
219
|
+
* Verifies that each block being removed is not part of a stored checkpoint (proposed or not).
|
|
220
|
+
* This differs from `removeUncheckpointedBlocksAfter` in that it also checks proposed checkpoints.
|
|
221
|
+
*
|
|
222
|
+
* @param blockNumber - Remove all blocks with number greater than this.
|
|
223
|
+
* @returns The removed blocks.
|
|
224
|
+
* @throws Error if any block to be removed is checkpointed.
|
|
225
|
+
*/ async removeBlocksWithoutProposedCheckpointAfter(blockNumber) {
|
|
226
|
+
const result = await this.stores.db.transactionAsync(async ()=>{
|
|
227
|
+
// Verify we're only removing uncheckpointed blocks
|
|
228
|
+
const lastCheckpointedBlockNumber = await this.stores.blocks.getProposedCheckpointL2BlockNumber();
|
|
229
|
+
if (blockNumber < lastCheckpointedBlockNumber) {
|
|
230
|
+
throw new Error(`Cannot remove blocks after ${blockNumber} because proposed checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`);
|
|
231
|
+
}
|
|
232
|
+
return await this.removeBlocksAfter(blockNumber);
|
|
233
|
+
});
|
|
234
|
+
await this.l2TipsCache?.refresh();
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Evicts pending proposed checkpoints that referenced any of the just-pruned blocks. Pruned
|
|
239
|
+
* blocks invalidate all proposed checkpoints from the lowest pruned block's checkpoint number
|
|
240
|
+
* onwards: those checkpoints either reference the pruned blocks directly or chain off them.
|
|
241
|
+
*/ async evictProposedCheckpointsForPrunedBlocks(prunedBlocks) {
|
|
242
|
+
if (prunedBlocks.length === 0) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const fromCheckpointNumber = prunedBlocks[0].checkpointNumber;
|
|
246
|
+
await this.stores.blocks.evictProposedCheckpointsFrom(fromCheckpointNumber);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
180
249
|
* Removes all blocks strictly after the given block number along with any logs and contract data.
|
|
181
250
|
* Does not remove their checkpoints.
|
|
182
251
|
*/ async removeBlocksAfter(blockNumber) {
|
|
183
252
|
// First get the blocks to be removed so we can clean up contract data
|
|
184
|
-
const removedBlocks = await this.
|
|
253
|
+
const removedBlocks = await this.stores.blocks.removeBlocksAfter(blockNumber);
|
|
185
254
|
// Clean up contract data and logs for the removed blocks
|
|
186
255
|
await Promise.all([
|
|
187
|
-
this.
|
|
256
|
+
this.stores.logs.deleteLogs(removedBlocks),
|
|
188
257
|
...removedBlocks.map((block)=>this.removeContractDataFromDb(block))
|
|
189
258
|
]);
|
|
190
259
|
return removedBlocks;
|
|
@@ -198,38 +267,39 @@ import groupBy from 'lodash.groupby';
|
|
|
198
267
|
* @param checkpointNumber - Remove all checkpoints strictly after this one.
|
|
199
268
|
* @returns True if the operation is successful.
|
|
200
269
|
*/ async removeCheckpointsAfter(checkpointNumber) {
|
|
201
|
-
|
|
202
|
-
const { blocksRemoved = [] } = await this.
|
|
270
|
+
const result = await this.stores.db.transactionAsync(async ()=>{
|
|
271
|
+
const { blocksRemoved = [] } = await this.stores.blocks.removeCheckpointsAfter(checkpointNumber);
|
|
203
272
|
const opResults = await Promise.all([
|
|
204
273
|
// Prune rolls back to the last proven block, which is by definition valid
|
|
205
|
-
this.
|
|
274
|
+
this.stores.blocks.setPendingChainValidationStatus({
|
|
206
275
|
valid: true
|
|
207
276
|
}),
|
|
208
277
|
// Remove contract data for all blocks being removed
|
|
209
278
|
...blocksRemoved.map((block)=>this.removeContractDataFromDb(block)),
|
|
210
|
-
this.
|
|
279
|
+
this.stores.logs.deleteLogs(blocksRemoved)
|
|
211
280
|
]);
|
|
212
|
-
await this.l2TipsCache?.refresh();
|
|
213
281
|
return opResults.every(Boolean);
|
|
214
282
|
});
|
|
283
|
+
await this.l2TipsCache?.refresh();
|
|
284
|
+
return result;
|
|
215
285
|
}
|
|
216
286
|
/**
|
|
217
287
|
* Updates the proven checkpoint number and refreshes the L2 tips cache.
|
|
218
288
|
* @param checkpointNumber - The checkpoint number to set as proven.
|
|
219
289
|
*/ async setProvenCheckpointNumber(checkpointNumber) {
|
|
220
|
-
await this.
|
|
221
|
-
await this.
|
|
222
|
-
await this.l2TipsCache?.refresh();
|
|
290
|
+
await this.stores.db.transactionAsync(async ()=>{
|
|
291
|
+
await this.stores.blocks.setProvenCheckpointNumber(checkpointNumber);
|
|
223
292
|
});
|
|
293
|
+
await this.l2TipsCache?.refresh();
|
|
224
294
|
}
|
|
225
295
|
/**
|
|
226
296
|
* Updates the finalized checkpoint number and refreshes the L2 tips cache.
|
|
227
297
|
* @param checkpointNumber - The checkpoint number to set as finalized.
|
|
228
298
|
*/ async setFinalizedCheckpointNumber(checkpointNumber) {
|
|
229
|
-
await this.
|
|
230
|
-
await this.
|
|
231
|
-
await this.l2TipsCache?.refresh();
|
|
299
|
+
await this.stores.db.transactionAsync(async ()=>{
|
|
300
|
+
await this.stores.blocks.setFinalizedCheckpointNumber(checkpointNumber);
|
|
232
301
|
});
|
|
302
|
+
await this.l2TipsCache?.refresh();
|
|
233
303
|
}
|
|
234
304
|
/** Extracts and stores contract data from a single block. */ addContractDataToDb(block) {
|
|
235
305
|
return this.updateContractDataOnDb(block, 0);
|
|
@@ -244,37 +314,68 @@ import groupBy from 'lodash.groupby';
|
|
|
244
314
|
return (await Promise.all([
|
|
245
315
|
this.updatePublishedContractClasses(contractClassLogs, block.number, operation),
|
|
246
316
|
this.updateDeployedContractInstances(privateLogs, block.number, operation),
|
|
247
|
-
this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation)
|
|
248
|
-
operation === 0 ? this.storeBroadcastedIndividualFunctions(contractClassLogs, block.number) : Promise.resolve(true)
|
|
317
|
+
this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation)
|
|
249
318
|
])).every(Boolean);
|
|
250
319
|
}
|
|
251
320
|
/**
|
|
252
321
|
* Extracts and stores contract classes out of ContractClassPublished events emitted by the class registry contract.
|
|
253
322
|
*/ async updatePublishedContractClasses(allLogs, blockNum, operation) {
|
|
254
323
|
const contractClassPublishedEvents = allLogs.filter((log)=>ContractClassPublishedEvent.isContractClassPublishedEvent(log)).map((log)=>ContractClassPublishedEvent.fromLog(log));
|
|
255
|
-
|
|
324
|
+
if (operation == 1) {
|
|
325
|
+
const contractClasses = contractClassPublishedEvents.map((e)=>e.toContractClassPublic());
|
|
326
|
+
if (contractClasses.length > 0) {
|
|
327
|
+
contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
328
|
+
return await this.stores.contractClasses.deleteContractClasses(contractClasses, blockNum);
|
|
329
|
+
}
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
// Compute bytecode commitments and validate class IDs in a single pass.
|
|
333
|
+
const contractClasses = [];
|
|
334
|
+
for (const event of contractClassPublishedEvents){
|
|
335
|
+
const contractClass = await event.toContractClassPublicWithBytecodeCommitment();
|
|
336
|
+
const computedClassId = await computeContractClassId({
|
|
337
|
+
artifactHash: contractClass.artifactHash,
|
|
338
|
+
privateFunctionsRoot: contractClass.privateFunctionsRoot,
|
|
339
|
+
publicBytecodeCommitment: contractClass.publicBytecodeCommitment
|
|
340
|
+
});
|
|
341
|
+
if (!computedClassId.equals(contractClass.id)) {
|
|
342
|
+
this.log.warn(`Skipping contract class with mismatched id at block ${blockNum}. Claimed ${contractClass.id}, computed ${computedClassId}`, {
|
|
343
|
+
blockNum,
|
|
344
|
+
contractClassId: event.contractClassId.toString()
|
|
345
|
+
});
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
contractClasses.push(contractClass);
|
|
349
|
+
}
|
|
256
350
|
if (contractClasses.length > 0) {
|
|
257
351
|
contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
258
|
-
|
|
259
|
-
// TODO: Will probably want to create some worker threads to compute these bytecode commitments as they are expensive
|
|
260
|
-
const commitments = await Promise.all(contractClasses.map((c)=>computePublicBytecodeCommitment(c.packedBytecode)));
|
|
261
|
-
return await this.store.addContractClasses(contractClasses, commitments, blockNum);
|
|
262
|
-
} else if (operation == 1) {
|
|
263
|
-
return await this.store.deleteContractClasses(contractClasses, blockNum);
|
|
264
|
-
}
|
|
352
|
+
return await this.stores.contractClasses.addContractClasses(contractClasses, blockNum);
|
|
265
353
|
}
|
|
266
354
|
return true;
|
|
267
355
|
}
|
|
268
356
|
/**
|
|
269
357
|
* Extracts and stores contract instances out of ContractInstancePublished events emitted by the canonical deployer contract.
|
|
270
358
|
*/ async updateDeployedContractInstances(allLogs, blockNum, operation) {
|
|
271
|
-
const
|
|
359
|
+
const allInstances = allLogs.filter((log)=>ContractInstancePublishedEvent.isContractInstancePublishedEvent(log)).map((log)=>ContractInstancePublishedEvent.fromLog(log)).map((e)=>e.toContractInstance());
|
|
360
|
+
// Verify that each instance's address matches the one derived from its fields if we're adding
|
|
361
|
+
const contractInstances = operation === 1 ? allInstances : await filterAsync(allInstances, async (instance)=>{
|
|
362
|
+
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
363
|
+
if (!computedAddress.equals(instance.address)) {
|
|
364
|
+
this.log.warn(`Found contract instance with mismatched address at block ${blockNum}. Claimed ${instance.address} but computed ${computedAddress}.`, {
|
|
365
|
+
instanceAddress: instance.address.toString(),
|
|
366
|
+
computedAddress: computedAddress.toString(),
|
|
367
|
+
blockNum
|
|
368
|
+
});
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
return true;
|
|
372
|
+
});
|
|
272
373
|
if (contractInstances.length > 0) {
|
|
273
374
|
contractInstances.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance at ${c.address.toString()}`));
|
|
274
375
|
if (operation == 0) {
|
|
275
|
-
return await this.
|
|
376
|
+
return await this.stores.contractInstances.addContractInstances(contractInstances, blockNum);
|
|
276
377
|
} else if (operation == 1) {
|
|
277
|
-
return await this.
|
|
378
|
+
return await this.stores.contractInstances.deleteContractInstances(contractInstances);
|
|
278
379
|
}
|
|
279
380
|
}
|
|
280
381
|
return true;
|
|
@@ -286,56 +387,10 @@ import groupBy from 'lodash.groupby';
|
|
|
286
387
|
if (contractUpdates.length > 0) {
|
|
287
388
|
contractUpdates.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance update at ${c.address.toString()}`));
|
|
288
389
|
if (operation == 0) {
|
|
289
|
-
return await this.
|
|
390
|
+
return await this.stores.contractInstances.addContractInstanceUpdates(contractUpdates, timestamp);
|
|
290
391
|
} else if (operation == 1) {
|
|
291
|
-
return await this.
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
return true;
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Stores the functions that were broadcasted individually.
|
|
298
|
-
*
|
|
299
|
-
* @dev Beware that there is not a delete variant of this, since they are added to contract classes
|
|
300
|
-
* and will be deleted as part of the class if needed.
|
|
301
|
-
*/ async storeBroadcastedIndividualFunctions(allLogs, _blockNum) {
|
|
302
|
-
// Filter out private and utility function broadcast events
|
|
303
|
-
const privateFnEvents = allLogs.filter((log)=>PrivateFunctionBroadcastedEvent.isPrivateFunctionBroadcastedEvent(log)).map((log)=>PrivateFunctionBroadcastedEvent.fromLog(log));
|
|
304
|
-
const utilityFnEvents = allLogs.filter((log)=>UtilityFunctionBroadcastedEvent.isUtilityFunctionBroadcastedEvent(log)).map((log)=>UtilityFunctionBroadcastedEvent.fromLog(log));
|
|
305
|
-
// Group all events by contract class id
|
|
306
|
-
for (const [classIdString, classEvents] of Object.entries(groupBy([
|
|
307
|
-
...privateFnEvents,
|
|
308
|
-
...utilityFnEvents
|
|
309
|
-
], (e)=>e.contractClassId.toString()))){
|
|
310
|
-
const contractClassId = Fr.fromHexString(classIdString);
|
|
311
|
-
const contractClass = await this.store.getContractClass(contractClassId);
|
|
312
|
-
if (!contractClass) {
|
|
313
|
-
this.log.warn(`Skipping broadcasted functions as contract class ${contractClassId.toString()} was not found`);
|
|
314
|
-
continue;
|
|
315
|
-
}
|
|
316
|
-
// Split private and utility functions, and filter out invalid ones
|
|
317
|
-
const allFns = classEvents.map((e)=>e.toFunctionWithMembershipProof());
|
|
318
|
-
const privateFns = allFns.filter((fn)=>'utilityFunctionsTreeRoot' in fn);
|
|
319
|
-
const utilityFns = allFns.filter((fn)=>'privateFunctionsArtifactTreeRoot' in fn);
|
|
320
|
-
const privateFunctionsWithValidity = await Promise.all(privateFns.map(async (fn)=>({
|
|
321
|
-
fn,
|
|
322
|
-
valid: await isValidPrivateFunctionMembershipProof(fn, contractClass)
|
|
323
|
-
})));
|
|
324
|
-
const validPrivateFns = privateFunctionsWithValidity.filter(({ valid })=>valid).map(({ fn })=>fn);
|
|
325
|
-
const utilityFunctionsWithValidity = await Promise.all(utilityFns.map(async (fn)=>({
|
|
326
|
-
fn,
|
|
327
|
-
valid: await isValidUtilityFunctionMembershipProof(fn, contractClass)
|
|
328
|
-
})));
|
|
329
|
-
const validUtilityFns = utilityFunctionsWithValidity.filter(({ valid })=>valid).map(({ fn })=>fn);
|
|
330
|
-
const validFnCount = validPrivateFns.length + validUtilityFns.length;
|
|
331
|
-
if (validFnCount !== allFns.length) {
|
|
332
|
-
this.log.warn(`Skipping ${allFns.length - validFnCount} invalid functions`);
|
|
333
|
-
}
|
|
334
|
-
// Store the functions in the contract class in a single operation
|
|
335
|
-
if (validFnCount > 0) {
|
|
336
|
-
this.log.verbose(`Storing ${validFnCount} functions for contract class ${contractClassId.toString()}`);
|
|
392
|
+
return await this.stores.contractInstances.deleteContractInstanceUpdates(contractUpdates, timestamp);
|
|
337
393
|
}
|
|
338
|
-
await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
|
|
339
394
|
}
|
|
340
395
|
return true;
|
|
341
396
|
}
|
|
@@ -16,6 +16,7 @@ export declare class ArchiverInstrumentation {
|
|
|
16
16
|
private pruneDuration;
|
|
17
17
|
private pruneCount;
|
|
18
18
|
private syncDurationPerBlock;
|
|
19
|
+
private syncDurationPerCheckpoint;
|
|
19
20
|
private syncBlockCount;
|
|
20
21
|
private manaPerBlock;
|
|
21
22
|
private txsPerBlock;
|
|
@@ -23,11 +24,13 @@ export declare class ArchiverInstrumentation {
|
|
|
23
24
|
private syncMessageCount;
|
|
24
25
|
private blockProposalTxTargetCount;
|
|
25
26
|
private checkpointL1InclusionDelay;
|
|
27
|
+
private checkpointPromotedCount;
|
|
26
28
|
private log;
|
|
27
29
|
private constructor();
|
|
28
30
|
static new(telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback): Promise<ArchiverInstrumentation>;
|
|
29
31
|
isEnabled(): boolean;
|
|
30
|
-
|
|
32
|
+
processNewProposedBlock(syncTimePerBlock: number, block: L2Block): void;
|
|
33
|
+
processNewCheckpointedBlocks(syncTimePerCheckpoint: number, blocks: L2Block[]): void;
|
|
31
34
|
processNewMessages(count: number, syncPerMessageMs: number): void;
|
|
32
35
|
processPrune(duration: number): void;
|
|
33
36
|
updateLastProvenCheckpoint(checkpoint: CheckpointData): void;
|
|
@@ -38,6 +41,8 @@ export declare class ArchiverInstrumentation {
|
|
|
38
41
|
}[]): void;
|
|
39
42
|
updateL1BlockHeight(blockNumber: bigint): void;
|
|
40
43
|
recordBlockProposalTxTarget(target: string, usedTrace: boolean): void;
|
|
44
|
+
/** Records a checkpoint promoted from proposed (blob fetch skipped). */
|
|
45
|
+
processCheckpointPromoted(): void;
|
|
41
46
|
/**
|
|
42
47
|
* Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
|
|
43
48
|
*/
|
|
@@ -47,4 +52,4 @@ export declare class ArchiverInstrumentation {
|
|
|
47
52
|
l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>;
|
|
48
53
|
}): void;
|
|
49
54
|
}
|
|
50
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
55
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QUFNLFFBRTdDO0lBRU0sMkJBQTJCLENBQUMsTUFBTSxFQUFFLE1BQU0sRUFBRSxTQUFTLEVBQUUsT0FBTyxRQUtwRTtJQUVELHdFQUF3RTtJQUNqRSx5QkFBeUIsU0FFL0I7SUFFRDs7T0FFRztJQUNJLHlCQUF5QixDQUFDLElBQUksRUFBRTtRQUNyQyxVQUFVLEVBQUUsVUFBVSxDQUFDO1FBQ3ZCLFdBQVcsRUFBRSxNQUFNLENBQUM7UUFDcEIsV0FBVyxFQUFFLElBQUksQ0FBQyxpQkFBaUIsRUFBRSxlQUFlLEdBQUcsY0FBYyxDQUFDLENBQUM7S0FDeEUsR0FBRyxJQUFJLENBSVA7Q0FDRiJ9
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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,EA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AA0B,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"}
|
|
@@ -14,6 +14,7 @@ export class ArchiverInstrumentation {
|
|
|
14
14
|
pruneDuration;
|
|
15
15
|
pruneCount;
|
|
16
16
|
syncDurationPerBlock;
|
|
17
|
+
syncDurationPerCheckpoint;
|
|
17
18
|
syncBlockCount;
|
|
18
19
|
manaPerBlock;
|
|
19
20
|
txsPerBlock;
|
|
@@ -21,6 +22,7 @@ export class ArchiverInstrumentation {
|
|
|
21
22
|
syncMessageCount;
|
|
22
23
|
blockProposalTxTargetCount;
|
|
23
24
|
checkpointL1InclusionDelay;
|
|
25
|
+
checkpointPromotedCount;
|
|
24
26
|
log;
|
|
25
27
|
constructor(telemetry, lmdbStats){
|
|
26
28
|
this.telemetry = telemetry;
|
|
@@ -39,6 +41,7 @@ export class ArchiverInstrumentation {
|
|
|
39
41
|
});
|
|
40
42
|
this.proofsSubmittedDelay = meter.createHistogram(Metrics.ARCHIVER_ROLLUP_PROOF_DELAY);
|
|
41
43
|
this.syncDurationPerBlock = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_BLOCK);
|
|
44
|
+
this.syncDurationPerCheckpoint = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_CHECKPOINT);
|
|
42
45
|
this.syncBlockCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_BLOCK_COUNT);
|
|
43
46
|
this.manaPerBlock = meter.createHistogram(Metrics.ARCHIVER_MANA_PER_BLOCK);
|
|
44
47
|
this.txsPerBlock = meter.createHistogram(Metrics.ARCHIVER_TXS_PER_BLOCK);
|
|
@@ -53,6 +56,7 @@ export class ArchiverInstrumentation {
|
|
|
53
56
|
]
|
|
54
57
|
});
|
|
55
58
|
this.checkpointL1InclusionDelay = meter.createHistogram(Metrics.ARCHIVER_CHECKPOINT_L1_INCLUSION_DELAY);
|
|
59
|
+
this.checkpointPromotedCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_CHECKPOINT_PROMOTED_COUNT);
|
|
56
60
|
this.dbMetrics = new LmdbMetrics(meter, {
|
|
57
61
|
[Attributes.DB_DATA_TYPE]: 'archiver'
|
|
58
62
|
}, lmdbStats);
|
|
@@ -65,16 +69,27 @@ export class ArchiverInstrumentation {
|
|
|
65
69
|
isEnabled() {
|
|
66
70
|
return this.telemetry.isEnabled();
|
|
67
71
|
}
|
|
68
|
-
|
|
72
|
+
processNewProposedBlock(syncTimePerBlock, block) {
|
|
73
|
+
const attrs = {
|
|
74
|
+
[Attributes.STATUS]: 'proposed'
|
|
75
|
+
};
|
|
76
|
+
this.blockHeight.record(block.number, attrs);
|
|
69
77
|
this.syncDurationPerBlock.record(Math.ceil(syncTimePerBlock));
|
|
70
|
-
|
|
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));
|
|
88
|
+
this.blockHeight.record(Math.max(...blocks.map((b)=>b.number)), {
|
|
89
|
+
[Attributes.STATUS]: 'checkpointed'
|
|
90
|
+
});
|
|
71
91
|
this.checkpointHeight.record(Math.max(...blocks.map((b)=>b.checkpointNumber)));
|
|
72
92
|
this.syncBlockCount.add(blocks.length);
|
|
73
|
-
for (const block of blocks){
|
|
74
|
-
this.txCount.add(block.body.txEffects.length);
|
|
75
|
-
this.txsPerBlock.record(block.body.txEffects.length);
|
|
76
|
-
this.manaPerBlock.record(block.header.totalManaUsed.toNumber() / 1e6);
|
|
77
|
-
}
|
|
78
93
|
}
|
|
79
94
|
processNewMessages(count, syncPerMessageMs) {
|
|
80
95
|
if (count === 0) {
|
|
@@ -117,6 +132,9 @@ export class ArchiverInstrumentation {
|
|
|
117
132
|
[Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: usedTrace
|
|
118
133
|
});
|
|
119
134
|
}
|
|
135
|
+
/** Records a checkpoint promoted from proposed (blob fetch skipped). */ processCheckpointPromoted() {
|
|
136
|
+
this.checkpointPromotedCount.add(1);
|
|
137
|
+
}
|
|
120
138
|
/**
|
|
121
139
|
* Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
|
|
122
140
|
*/ processCheckpointL1Timing(data) {
|