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