@aztec/archiver 0.0.1-commit.42ee6df9b → 0.0.1-commit.431c48d
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 +7 -7
- package/dest/archiver.d.ts +70 -15
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +273 -71
- package/dest/config.d.ts +7 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +44 -16
- package/dest/errors.d.ts +35 -13
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +54 -16
- package/dest/factory.d.ts +18 -6
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +66 -21
- 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 +9 -1
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +20 -10
- package/dest/l1/data_retrieval.d.ts +24 -10
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +13 -19
- 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 +71 -50
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +250 -150
- package/dest/modules/data_store_updater.d.ts +28 -9
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +129 -64
- package/dest/modules/instrumentation.d.ts +15 -2
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +48 -9
- package/dest/modules/l1_synchronizer.d.ts +11 -7
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +347 -118
- package/dest/modules/outbox_trees_resolver.d.ts +64 -0
- package/dest/modules/outbox_trees_resolver.d.ts.map +1 -0
- package/dest/modules/outbox_trees_resolver.js +184 -0
- package/dest/modules/validation.d.ts +30 -7
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +33 -15
- package/dest/store/block_store.d.ts +169 -94
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +618 -270
- package/dest/store/contract_class_store.d.ts +17 -3
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +36 -2
- 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 +53 -5
- 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 -8
- package/dest/store/l2_tips_cache.d.ts.map +1 -1
- package/dest/store/l2_tips_cache.js +13 -96
- 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 +31 -1
- package/dest/test/fake_l1_state.d.ts +14 -3
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +58 -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 +1 -2
- package/dest/test/mock_l2_block_source.d.ts +47 -54
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +229 -205
- 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 +26 -10
- package/package.json +15 -14
- package/src/archiver.ts +355 -77
- package/src/config.ts +51 -20
- package/src/errors.ts +80 -23
- package/src/factory.ts +80 -19
- package/src/index.ts +18 -2
- package/src/l1/calldata_retriever.ts +27 -10
- package/src/l1/data_retrieval.ts +38 -36
- 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 +319 -200
- package/src/modules/data_store_updater.ts +156 -65
- package/src/modules/instrumentation.ts +43 -10
- package/src/modules/l1_synchronizer.ts +499 -136
- package/src/modules/outbox_trees_resolver.ts +220 -0
- package/src/modules/validation.ts +78 -21
- package/src/store/block_store.ts +741 -333
- package/src/store/contract_class_store.ts +47 -3
- package/src/store/contract_instance_store.ts +67 -7
- 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 -109
- package/src/store/log_store.ts +296 -652
- package/src/store/log_store_codec.ts +143 -0
- package/src/store/message_store.ts +35 -2
- package/src/test/fake_l1_state.ts +65 -27
- package/src/test/mock_l1_to_l2_message_source.ts +0 -1
- package/src/test/mock_l2_block_source.ts +276 -258
- package/src/test/mock_structs.ts +5 -2
- package/src/test/noop_l1_archiver.ts +54 -11
- package/dest/store/kv_archiver_store.d.ts +0 -377
- package/dest/store/kv_archiver_store.d.ts.map +0 -1
- package/dest/store/kv_archiver_store.js +0 -494
- package/src/store/kv_archiver_store.ts +0 -713
|
@@ -5,18 +5,19 @@ import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-reg
|
|
|
5
5
|
import { ContractInstancePublishedEvent, ContractInstanceUpdatedEvent } from '@aztec/protocol-contracts/instance-registry';
|
|
6
6
|
import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
7
7
|
import { computeContractAddressFromInstance, computeContractClassId } from '@aztec/stdlib/contract';
|
|
8
|
+
import { MAX_CAPACITY_BLOCKS_PER_CHECKPOINT } from '@aztec/stdlib/deserialization';
|
|
8
9
|
/** Operation type for contract data updates. */ var Operation = /*#__PURE__*/ function(Operation) {
|
|
9
10
|
Operation[Operation["Store"] = 0] = "Store";
|
|
10
11
|
Operation[Operation["Delete"] = 1] = "Delete";
|
|
11
12
|
return Operation;
|
|
12
13
|
}(Operation || {});
|
|
13
14
|
/** Archiver helper module to handle updates to the data store. */ export class ArchiverDataStoreUpdater {
|
|
14
|
-
|
|
15
|
+
stores;
|
|
15
16
|
l2TipsCache;
|
|
16
17
|
opts;
|
|
17
18
|
log;
|
|
18
|
-
constructor(
|
|
19
|
-
this.
|
|
19
|
+
constructor(stores, l2TipsCache, opts = {}){
|
|
20
|
+
this.stores = stores;
|
|
20
21
|
this.l2TipsCache = l2TipsCache;
|
|
21
22
|
this.opts = opts;
|
|
22
23
|
this.log = createLogger('archiver:store_updater');
|
|
@@ -30,21 +31,21 @@ import { computeContractAddressFromInstance, computeContractClassId } from '@azt
|
|
|
30
31
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
31
32
|
* @returns True if the operation is successful.
|
|
32
33
|
*/ async addProposedBlock(block, pendingChainValidationStatus) {
|
|
33
|
-
const result = await this.
|
|
34
|
-
await this.
|
|
34
|
+
const result = await this.stores.db.transactionAsync(async ()=>{
|
|
35
|
+
await this.stores.blocks.addProposedBlock(block);
|
|
35
36
|
const opResults = await Promise.all([
|
|
36
37
|
// Update the pending chain validation status if provided
|
|
37
|
-
pendingChainValidationStatus && this.
|
|
38
|
+
pendingChainValidationStatus && this.stores.blocks.setPendingChainValidationStatus(pendingChainValidationStatus),
|
|
38
39
|
// Add any logs emitted during the retrieved block
|
|
39
|
-
this.
|
|
40
|
+
this.stores.logs.addLogs([
|
|
40
41
|
block
|
|
41
42
|
]),
|
|
42
43
|
// Unroll all logs emitted during the retrieved block and extract any contract classes and instances from it
|
|
43
44
|
this.addContractDataToDb(block)
|
|
44
45
|
]);
|
|
45
|
-
await this.l2TipsCache?.refresh();
|
|
46
46
|
return opResults.every(Boolean);
|
|
47
47
|
});
|
|
48
|
+
await this.l2TipsCache?.refresh();
|
|
48
49
|
return result;
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
@@ -52,54 +53,79 @@ import { computeContractAddressFromInstance, computeContractClassId } from '@azt
|
|
|
52
53
|
* Adds new checkpoints to the store with contract class/instance extraction from logs.
|
|
53
54
|
* Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
|
|
54
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.
|
|
55
58
|
*
|
|
56
|
-
* @param checkpoints - The published checkpoints to add.
|
|
59
|
+
* @param checkpoints - The published checkpoints to add (excluding any being promoted from proposed).
|
|
57
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).
|
|
58
62
|
* @returns Result with information about any pruned blocks.
|
|
59
|
-
*/ async addCheckpoints(checkpoints, pendingChainValidationStatus) {
|
|
63
|
+
*/ async addCheckpoints(checkpoints, pendingChainValidationStatus, promoteProposed, evictProposedFrom) {
|
|
64
|
+
// These checkpoints are already on L1, so ingest validates against the physical blob capacity rather than
|
|
65
|
+
// the conservative build/attest policy, and tolerates an empty non-first block. Both rules are enforced by
|
|
66
|
+
// proposers and attesters; rejecting an ingest would stall sync rather than undo the checkpoint.
|
|
67
|
+
const validateOpts = {
|
|
68
|
+
rollupManaLimit: this.opts?.rollupManaLimit,
|
|
69
|
+
maxBlocksPerCheckpoint: MAX_CAPACITY_BLOCKS_PER_CHECKPOINT,
|
|
70
|
+
allowEmptyNonFirstBlocks: true
|
|
71
|
+
};
|
|
60
72
|
for (const checkpoint of checkpoints){
|
|
61
|
-
validateCheckpoint(checkpoint.checkpoint,
|
|
62
|
-
|
|
63
|
-
|
|
73
|
+
validateCheckpoint(checkpoint.checkpoint, validateOpts);
|
|
74
|
+
}
|
|
75
|
+
if (promoteProposed) {
|
|
76
|
+
validateCheckpoint(promoteProposed.checkpoint.checkpoint, validateOpts);
|
|
64
77
|
}
|
|
65
|
-
const result = await this.
|
|
78
|
+
const result = await this.stores.db.transactionAsync(async ()=>{
|
|
66
79
|
// Before adding checkpoints, check for conflicts with local blocks if any
|
|
67
80
|
const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
|
|
68
|
-
await this.
|
|
69
|
-
//
|
|
70
|
-
|
|
81
|
+
const insertedCheckpoints = await this.stores.blocks.addCheckpoints(checkpoints);
|
|
82
|
+
// Skip blocks already inserted via addProposedBlock() and blocks of already-stored checkpoints
|
|
83
|
+
// re-included by an L1 reorg: their logs/contract data were extracted when first inserted.
|
|
84
|
+
const newBlocks = insertedCheckpoints.flatMap((ch)=>ch.checkpoint.blocks).filter((b)=>lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
|
|
71
85
|
await Promise.all([
|
|
72
86
|
// Update the pending chain validation status if provided
|
|
73
|
-
pendingChainValidationStatus && this.
|
|
87
|
+
pendingChainValidationStatus && this.stores.blocks.setPendingChainValidationStatus(pendingChainValidationStatus),
|
|
74
88
|
// Add any logs emitted during the retrieved blocks
|
|
75
|
-
this.
|
|
89
|
+
this.stores.logs.addLogs(newBlocks),
|
|
76
90
|
// Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
|
|
77
|
-
...newBlocks.map((block)=>this.addContractDataToDb(block))
|
|
91
|
+
...newBlocks.map((block)=>this.addContractDataToDb(block)),
|
|
92
|
+
// Promote the proposed checkpoint if requested (uses explicit checkpoint number)
|
|
93
|
+
promoteProposed ? this.stores.blocks.promoteProposedToCheckpointed(promoteProposed.checkpoint.checkpoint.number, promoteProposed.l1, promoteProposed.attestations, promoteProposed.checkpoint.checkpoint.archive.root) : undefined,
|
|
94
|
+
// Evict pending checkpoints that diverged from what L1 mined
|
|
95
|
+
evictProposedFrom !== undefined ? this.stores.blocks.evictProposedCheckpointsFrom(evictProposedFrom) : undefined
|
|
78
96
|
]);
|
|
79
|
-
await this.l2TipsCache?.refresh();
|
|
80
97
|
return {
|
|
81
98
|
prunedBlocks,
|
|
82
99
|
lastAlreadyInsertedBlockNumber
|
|
83
100
|
};
|
|
84
101
|
});
|
|
102
|
+
await this.l2TipsCache?.refresh();
|
|
85
103
|
return result;
|
|
86
104
|
}
|
|
87
|
-
async
|
|
88
|
-
const result = await this.
|
|
89
|
-
await this.
|
|
90
|
-
await this.l2TipsCache?.refresh();
|
|
105
|
+
async addProposedCheckpoint(proposedCheckpoint) {
|
|
106
|
+
const result = await this.stores.db.transactionAsync(async ()=>{
|
|
107
|
+
await this.stores.blocks.addProposedCheckpoint(proposedCheckpoint);
|
|
91
108
|
});
|
|
109
|
+
await this.l2TipsCache?.refresh();
|
|
92
110
|
return result;
|
|
93
111
|
}
|
|
94
112
|
/**
|
|
95
113
|
* Checks for local proposed blocks that do not match the ones to be checkpointed and prunes them.
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
114
|
+
* Conflict detection is keyed on `blockNumber`: when a local proposed block and an L1
|
|
115
|
+
* checkpointed block share a block number but live at different slots (e.g. a different proposer
|
|
116
|
+
* mined the same block number one slot earlier), we still treat them as a conflict and prune.
|
|
117
|
+
* The trailing per-checkpoint prune that handles "local has extra trailing blocks within the
|
|
118
|
+
* same slot as the published checkpoint" remains scoped by slot to preserve pipelining: local
|
|
119
|
+
* blocks that live at a later slot than the checkpoint being processed represent speculation
|
|
120
|
+
* atop the just-confirmed tip (and may be referenced by a pending proposed checkpoint), so we
|
|
121
|
+
* leave them in place. This method handles multiple checkpoints but returns after pruning the
|
|
122
|
+
* first conflict found. This is correct because pruning from the first conflict point removes
|
|
123
|
+
* all subsequent blocks, and when checkpoints are added afterward, they include all the correct
|
|
124
|
+
* blocks.
|
|
99
125
|
*/ async pruneMismatchingLocalBlocks(checkpoints) {
|
|
100
126
|
const [lastCheckpointedBlockNumber, lastBlockNumber] = await Promise.all([
|
|
101
|
-
this.
|
|
102
|
-
this.
|
|
127
|
+
this.stores.blocks.getCheckpointedL2BlockNumber(),
|
|
128
|
+
this.stores.blocks.getLatestL2BlockNumber()
|
|
103
129
|
]);
|
|
104
130
|
// Exit early if there are no local uncheckpointed blocks
|
|
105
131
|
if (lastBlockNumber === lastCheckpointedBlockNumber) {
|
|
@@ -109,22 +135,25 @@ import { computeContractAddressFromInstance, computeContractClassId } from '@azt
|
|
|
109
135
|
};
|
|
110
136
|
}
|
|
111
137
|
// Get all uncheckpointed local blocks
|
|
112
|
-
const uncheckpointedLocalBlocks = await this.
|
|
138
|
+
const uncheckpointedLocalBlocks = await this.stores.blocks.getBlocksData({
|
|
139
|
+
from: BlockNumber.add(lastCheckpointedBlockNumber, 1),
|
|
140
|
+
limit: lastBlockNumber - lastCheckpointedBlockNumber
|
|
141
|
+
});
|
|
113
142
|
let lastAlreadyInsertedBlockNumber;
|
|
114
143
|
for (const publishedCheckpoint of checkpoints){
|
|
115
144
|
const checkpointBlocks = publishedCheckpoint.checkpoint.blocks;
|
|
116
145
|
const slot = publishedCheckpoint.checkpoint.slot;
|
|
117
|
-
const localBlocksInSlot = uncheckpointedLocalBlocks.filter((b)=>b.slot === slot);
|
|
118
146
|
if (checkpointBlocks.length === 0) {
|
|
119
147
|
this.log.warn(`Checkpoint ${publishedCheckpoint.checkpoint.number} for slot ${slot} has no blocks`);
|
|
120
148
|
continue;
|
|
121
149
|
}
|
|
122
|
-
// Find the first checkpoint block that conflicts with an existing local block and prune local afterwards
|
|
150
|
+
// Find the first checkpoint block that conflicts with an existing local block and prune local afterwards.
|
|
151
|
+
// Conflict detection joins on block number only — same block number at a different slot is still a conflict.
|
|
123
152
|
for (const checkpointBlock of checkpointBlocks){
|
|
124
153
|
const blockNumber = checkpointBlock.number;
|
|
125
|
-
const existingBlock =
|
|
154
|
+
const existingBlock = uncheckpointedLocalBlocks.find((b)=>b.header.getBlockNumber() === blockNumber);
|
|
126
155
|
const blockInfos = {
|
|
127
|
-
existingBlock: existingBlock?.
|
|
156
|
+
existingBlock: existingBlock?.header.toInspect(),
|
|
128
157
|
checkpointBlock: checkpointBlock.toBlockInfo()
|
|
129
158
|
};
|
|
130
159
|
if (!existingBlock) {
|
|
@@ -135,19 +164,23 @@ import { computeContractAddressFromInstance, computeContractClassId } from '@azt
|
|
|
135
164
|
} else {
|
|
136
165
|
this.log.info(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
|
|
137
166
|
const prunedBlocks = await this.removeBlocksAfter(BlockNumber(blockNumber - 1));
|
|
167
|
+
await this.evictProposedCheckpointsForPrunedBlocks(prunedBlocks);
|
|
138
168
|
return {
|
|
139
169
|
prunedBlocks,
|
|
140
170
|
lastAlreadyInsertedBlockNumber
|
|
141
171
|
};
|
|
142
172
|
}
|
|
143
173
|
}
|
|
144
|
-
// If
|
|
145
|
-
//
|
|
174
|
+
// If the sequencer locally proposed extra blocks within this checkpoint's slot (e.g. local has
|
|
175
|
+
// [N, N+1] but L1 confirmed just [N]), prune the extras. Scoped to the checkpoint's slot so we
|
|
176
|
+
// do not throw away speculative blocks at later slots that belong to a pending proposed checkpoint.
|
|
146
177
|
const lastCheckpointBlockNumber = checkpointBlocks.at(-1).number;
|
|
147
|
-
const
|
|
178
|
+
const localBlocksInSlot = uncheckpointedLocalBlocks.filter((b)=>b.header.getSlot() === slot);
|
|
179
|
+
const lastLocalBlockNumber = localBlocksInSlot.at(-1)?.header.getBlockNumber();
|
|
148
180
|
if (lastLocalBlockNumber !== undefined && lastLocalBlockNumber > lastCheckpointBlockNumber) {
|
|
149
181
|
this.log.warn(`Local chain for slot ${slot} ends at block ${lastLocalBlockNumber} but checkpoint ends at ${lastCheckpointBlockNumber}. Pruning blocks after block ${lastCheckpointBlockNumber}.`);
|
|
150
182
|
const prunedBlocks = await this.removeBlocksAfter(lastCheckpointBlockNumber);
|
|
183
|
+
await this.evictProposedCheckpointsForPrunedBlocks(prunedBlocks);
|
|
151
184
|
return {
|
|
152
185
|
prunedBlocks,
|
|
153
186
|
lastAlreadyInsertedBlockNumber
|
|
@@ -168,29 +201,60 @@ import { computeContractAddressFromInstance, computeContractClassId } from '@azt
|
|
|
168
201
|
* @returns The removed blocks.
|
|
169
202
|
* @throws Error if any block to be removed is checkpointed.
|
|
170
203
|
*/ async removeUncheckpointedBlocksAfter(blockNumber) {
|
|
171
|
-
const result = await this.
|
|
204
|
+
const result = await this.stores.db.transactionAsync(async ()=>{
|
|
172
205
|
// Verify we're only removing uncheckpointed blocks
|
|
173
|
-
const lastCheckpointedBlockNumber = await this.
|
|
206
|
+
const lastCheckpointedBlockNumber = await this.stores.blocks.getCheckpointedL2BlockNumber();
|
|
174
207
|
if (blockNumber < lastCheckpointedBlockNumber) {
|
|
175
208
|
throw new Error(`Cannot remove blocks after ${blockNumber} because checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`);
|
|
176
209
|
}
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
210
|
+
const prunedBlocks = await this.removeBlocksAfter(blockNumber);
|
|
211
|
+
await this.evictProposedCheckpointsForPrunedBlocks(prunedBlocks);
|
|
212
|
+
return prunedBlocks;
|
|
213
|
+
});
|
|
214
|
+
await this.l2TipsCache?.refresh();
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Removes all blocks without a proposed checkpoint strictly after the specified block number and cleans up associated contract data.
|
|
219
|
+
* This handles removal of provisionally added blocks along with their contract classes/instances.
|
|
220
|
+
* Verifies that each block being removed is not part of a stored checkpoint (proposed or not).
|
|
221
|
+
* This differs from `removeUncheckpointedBlocksAfter` in that it also checks proposed checkpoints.
|
|
222
|
+
*
|
|
223
|
+
* @param blockNumber - Remove all blocks with number greater than this.
|
|
224
|
+
* @returns The removed blocks.
|
|
225
|
+
* @throws Error if any block to be removed is checkpointed.
|
|
226
|
+
*/ async removeBlocksWithoutProposedCheckpointAfter(blockNumber) {
|
|
227
|
+
const result = await this.stores.db.transactionAsync(async ()=>{
|
|
228
|
+
// Verify we're only removing uncheckpointed blocks
|
|
229
|
+
const lastCheckpointedBlockNumber = await this.stores.blocks.getProposedCheckpointL2BlockNumber();
|
|
230
|
+
if (blockNumber < lastCheckpointedBlockNumber) {
|
|
231
|
+
throw new Error(`Cannot remove blocks after ${blockNumber} because proposed checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`);
|
|
232
|
+
}
|
|
233
|
+
return await this.removeBlocksAfter(blockNumber);
|
|
182
234
|
});
|
|
235
|
+
await this.l2TipsCache?.refresh();
|
|
183
236
|
return result;
|
|
184
237
|
}
|
|
185
238
|
/**
|
|
239
|
+
* Evicts pending proposed checkpoints that referenced any of the just-pruned blocks. Pruned
|
|
240
|
+
* blocks invalidate all proposed checkpoints from the lowest pruned block's checkpoint number
|
|
241
|
+
* onwards: those checkpoints either reference the pruned blocks directly or chain off them.
|
|
242
|
+
*/ async evictProposedCheckpointsForPrunedBlocks(prunedBlocks) {
|
|
243
|
+
if (prunedBlocks.length === 0) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const fromCheckpointNumber = prunedBlocks[0].checkpointNumber;
|
|
247
|
+
await this.stores.blocks.evictProposedCheckpointsFrom(fromCheckpointNumber);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
186
250
|
* Removes all blocks strictly after the given block number along with any logs and contract data.
|
|
187
251
|
* Does not remove their checkpoints.
|
|
188
252
|
*/ async removeBlocksAfter(blockNumber) {
|
|
189
253
|
// First get the blocks to be removed so we can clean up contract data
|
|
190
|
-
const removedBlocks = await this.
|
|
254
|
+
const removedBlocks = await this.stores.blocks.removeBlocksAfter(blockNumber);
|
|
191
255
|
// Clean up contract data and logs for the removed blocks
|
|
192
256
|
await Promise.all([
|
|
193
|
-
this.
|
|
257
|
+
this.stores.logs.deleteLogs(removedBlocks),
|
|
194
258
|
...removedBlocks.map((block)=>this.removeContractDataFromDb(block))
|
|
195
259
|
]);
|
|
196
260
|
return removedBlocks;
|
|
@@ -204,38 +268,39 @@ import { computeContractAddressFromInstance, computeContractClassId } from '@azt
|
|
|
204
268
|
* @param checkpointNumber - Remove all checkpoints strictly after this one.
|
|
205
269
|
* @returns True if the operation is successful.
|
|
206
270
|
*/ async removeCheckpointsAfter(checkpointNumber) {
|
|
207
|
-
|
|
208
|
-
const { blocksRemoved = [] } = await this.
|
|
271
|
+
const result = await this.stores.db.transactionAsync(async ()=>{
|
|
272
|
+
const { blocksRemoved = [] } = await this.stores.blocks.removeCheckpointsAfter(checkpointNumber);
|
|
209
273
|
const opResults = await Promise.all([
|
|
210
274
|
// Prune rolls back to the last proven block, which is by definition valid
|
|
211
|
-
this.
|
|
275
|
+
this.stores.blocks.setPendingChainValidationStatus({
|
|
212
276
|
valid: true
|
|
213
277
|
}),
|
|
214
278
|
// Remove contract data for all blocks being removed
|
|
215
279
|
...blocksRemoved.map((block)=>this.removeContractDataFromDb(block)),
|
|
216
|
-
this.
|
|
280
|
+
this.stores.logs.deleteLogs(blocksRemoved)
|
|
217
281
|
]);
|
|
218
|
-
await this.l2TipsCache?.refresh();
|
|
219
282
|
return opResults.every(Boolean);
|
|
220
283
|
});
|
|
284
|
+
await this.l2TipsCache?.refresh();
|
|
285
|
+
return result;
|
|
221
286
|
}
|
|
222
287
|
/**
|
|
223
288
|
* Updates the proven checkpoint number and refreshes the L2 tips cache.
|
|
224
289
|
* @param checkpointNumber - The checkpoint number to set as proven.
|
|
225
290
|
*/ async setProvenCheckpointNumber(checkpointNumber) {
|
|
226
|
-
await this.
|
|
227
|
-
await this.
|
|
228
|
-
await this.l2TipsCache?.refresh();
|
|
291
|
+
await this.stores.db.transactionAsync(async ()=>{
|
|
292
|
+
await this.stores.blocks.setProvenCheckpointNumber(checkpointNumber);
|
|
229
293
|
});
|
|
294
|
+
await this.l2TipsCache?.refresh();
|
|
230
295
|
}
|
|
231
296
|
/**
|
|
232
297
|
* Updates the finalized checkpoint number and refreshes the L2 tips cache.
|
|
233
298
|
* @param checkpointNumber - The checkpoint number to set as finalized.
|
|
234
299
|
*/ async setFinalizedCheckpointNumber(checkpointNumber) {
|
|
235
|
-
await this.
|
|
236
|
-
await this.
|
|
237
|
-
await this.l2TipsCache?.refresh();
|
|
300
|
+
await this.stores.db.transactionAsync(async ()=>{
|
|
301
|
+
await this.stores.blocks.setFinalizedCheckpointNumber(checkpointNumber);
|
|
238
302
|
});
|
|
303
|
+
await this.l2TipsCache?.refresh();
|
|
239
304
|
}
|
|
240
305
|
/** Extracts and stores contract data from a single block. */ addContractDataToDb(block) {
|
|
241
306
|
return this.updateContractDataOnDb(block, 0);
|
|
@@ -261,7 +326,7 @@ import { computeContractAddressFromInstance, computeContractClassId } from '@azt
|
|
|
261
326
|
const contractClasses = contractClassPublishedEvents.map((e)=>e.toContractClassPublic());
|
|
262
327
|
if (contractClasses.length > 0) {
|
|
263
328
|
contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
264
|
-
return await this.
|
|
329
|
+
return await this.stores.contractClasses.deleteContractClasses(contractClasses, blockNum);
|
|
265
330
|
}
|
|
266
331
|
return true;
|
|
267
332
|
}
|
|
@@ -285,7 +350,7 @@ import { computeContractAddressFromInstance, computeContractClassId } from '@azt
|
|
|
285
350
|
}
|
|
286
351
|
if (contractClasses.length > 0) {
|
|
287
352
|
contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
288
|
-
return await this.
|
|
353
|
+
return await this.stores.contractClasses.addContractClasses(contractClasses, blockNum);
|
|
289
354
|
}
|
|
290
355
|
return true;
|
|
291
356
|
}
|
|
@@ -309,9 +374,9 @@ import { computeContractAddressFromInstance, computeContractClassId } from '@azt
|
|
|
309
374
|
if (contractInstances.length > 0) {
|
|
310
375
|
contractInstances.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance at ${c.address.toString()}`));
|
|
311
376
|
if (operation == 0) {
|
|
312
|
-
return await this.
|
|
377
|
+
return await this.stores.contractInstances.addContractInstances(contractInstances, blockNum);
|
|
313
378
|
} else if (operation == 1) {
|
|
314
|
-
return await this.
|
|
379
|
+
return await this.stores.contractInstances.deleteContractInstances(contractInstances);
|
|
315
380
|
}
|
|
316
381
|
}
|
|
317
382
|
return true;
|
|
@@ -323,9 +388,9 @@ import { computeContractAddressFromInstance, computeContractClassId } from '@azt
|
|
|
323
388
|
if (contractUpdates.length > 0) {
|
|
324
389
|
contractUpdates.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance update at ${c.address.toString()}`));
|
|
325
390
|
if (operation == 0) {
|
|
326
|
-
return await this.
|
|
391
|
+
return await this.stores.contractInstances.addContractInstanceUpdates(contractUpdates, timestamp);
|
|
327
392
|
} else if (operation == 1) {
|
|
328
|
-
return await this.
|
|
393
|
+
return await this.stores.contractInstances.deleteContractInstanceUpdates(contractUpdates, timestamp);
|
|
329
394
|
}
|
|
330
395
|
}
|
|
331
396
|
return true;
|
|
@@ -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,13 +24,23 @@ 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;
|
|
36
|
+
/**
|
|
37
|
+
* Records a pending-chain reorg, where the archiver dropped proposed blocks (and world-state follows by pruning). The
|
|
38
|
+
* type distinguishes the cause: 'uncheckpointed' (slot ended without a checkpoint), 'l1_conflict' (proposed blocks
|
|
39
|
+
* conflicting with an L1 checkpoint), 'orphan' (no matching proposed checkpoint arrived before the deadline), or
|
|
40
|
+
* 'l1_mismatch' (the local checkpointed tip diverged from L1 — an L1 reorg or a pruned/missed-proof checkpoint — so
|
|
41
|
+
* already-checkpointed blocks were rewound).
|
|
42
|
+
*/
|
|
43
|
+
recordPrune(pruneType: 'uncheckpointed' | 'l1_conflict' | 'orphan' | 'l1_mismatch'): void;
|
|
33
44
|
updateLastProvenCheckpoint(checkpoint: CheckpointData): void;
|
|
34
45
|
processProofsVerified(logs: {
|
|
35
46
|
proverId: string;
|
|
@@ -38,6 +49,8 @@ export declare class ArchiverInstrumentation {
|
|
|
38
49
|
}[]): void;
|
|
39
50
|
updateL1BlockHeight(blockNumber: bigint): void;
|
|
40
51
|
recordBlockProposalTxTarget(target: string, usedTrace: boolean): void;
|
|
52
|
+
/** Records a checkpoint promoted from proposed (blob fetch skipped). */
|
|
53
|
+
processCheckpointPromoted(): void;
|
|
41
54
|
/**
|
|
42
55
|
* Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
|
|
43
56
|
*/
|
|
@@ -47,4 +60,4 @@ export declare class ArchiverInstrumentation {
|
|
|
47
60
|
l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>;
|
|
48
61
|
}): void;
|
|
49
62
|
}
|
|
50
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
63
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5zdHJ1bWVudGF0aW9uLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbW9kdWxlcy9pbnN0cnVtZW50YXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFFbEUsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDbkQsT0FBTyxLQUFLLEVBQUUsY0FBYyxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDL0QsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUVyRSxPQUFPLEVBS0wsS0FBSyxpQkFBaUIsRUFFdEIsS0FBSyxlQUFlLEVBQ3BCLEtBQUssTUFBTSxFQUdaLE1BQU0seUJBQXlCLENBQUM7QUFFakMscUJBQWEsdUJBQXVCO0lBK0JoQyxPQUFPLENBQUMsU0FBUztJQTlCbkIsU0FBZ0IsTUFBTSxFQUFFLE1BQU0sQ0FBQztJQUUvQixPQUFPLENBQUMsV0FBVyxDQUFRO0lBQzNCLE9BQU8sQ0FBQyxnQkFBZ0IsQ0FBUTtJQUNoQyxPQUFPLENBQUMsT0FBTyxDQUFnQjtJQUMvQixPQUFPLENBQUMsYUFBYSxDQUFRO0lBQzdCLE9BQU8sQ0FBQyxvQkFBb0IsQ0FBWTtJQUN4QyxPQUFPLENBQUM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AAE,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;IAED;;;;;;OAMG;IACI,WAAW,CAAC,SAAS,EAAE,gBAAgB,GAAG,aAAa,GAAG,QAAQ,GAAG,aAAa,QAExF;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"}
|
|
@@ -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,13 +41,22 @@ 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);
|
|
45
48
|
this.syncDurationPerMessage = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_MESSAGE);
|
|
46
49
|
this.syncMessageCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_MESSAGE_COUNT);
|
|
47
50
|
this.pruneDuration = meter.createHistogram(Metrics.ARCHIVER_PRUNE_DURATION);
|
|
48
|
-
this.pruneCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_PRUNE_COUNT
|
|
51
|
+
this.pruneCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_PRUNE_COUNT, {
|
|
52
|
+
[Attributes.PRUNE_TYPE]: [
|
|
53
|
+
'unproven',
|
|
54
|
+
'uncheckpointed',
|
|
55
|
+
'l1_conflict',
|
|
56
|
+
'orphan',
|
|
57
|
+
'l1_mismatch'
|
|
58
|
+
]
|
|
59
|
+
});
|
|
49
60
|
this.blockProposalTxTargetCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_BLOCK_PROPOSAL_TX_TARGET_COUNT, {
|
|
50
61
|
[Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: [
|
|
51
62
|
true,
|
|
@@ -53,6 +64,7 @@ export class ArchiverInstrumentation {
|
|
|
53
64
|
]
|
|
54
65
|
});
|
|
55
66
|
this.checkpointL1InclusionDelay = meter.createHistogram(Metrics.ARCHIVER_CHECKPOINT_L1_INCLUSION_DELAY);
|
|
67
|
+
this.checkpointPromotedCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_CHECKPOINT_PROMOTED_COUNT);
|
|
56
68
|
this.dbMetrics = new LmdbMetrics(meter, {
|
|
57
69
|
[Attributes.DB_DATA_TYPE]: 'archiver'
|
|
58
70
|
}, lmdbStats);
|
|
@@ -65,16 +77,27 @@ export class ArchiverInstrumentation {
|
|
|
65
77
|
isEnabled() {
|
|
66
78
|
return this.telemetry.isEnabled();
|
|
67
79
|
}
|
|
68
|
-
|
|
80
|
+
processNewProposedBlock(syncTimePerBlock, block) {
|
|
81
|
+
const attrs = {
|
|
82
|
+
[Attributes.STATUS]: 'proposed'
|
|
83
|
+
};
|
|
84
|
+
this.blockHeight.record(block.number, attrs);
|
|
69
85
|
this.syncDurationPerBlock.record(Math.ceil(syncTimePerBlock));
|
|
70
|
-
|
|
86
|
+
// Per block metrics
|
|
87
|
+
this.txCount.add(block.body.txEffects.length);
|
|
88
|
+
this.txsPerBlock.record(block.body.txEffects.length);
|
|
89
|
+
this.manaPerBlock.record(block.header.totalManaUsed.toNumber() / 1e6);
|
|
90
|
+
}
|
|
91
|
+
processNewCheckpointedBlocks(syncTimePerCheckpoint, blocks) {
|
|
92
|
+
if (blocks.length === 0) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this.syncDurationPerCheckpoint.record(Math.ceil(syncTimePerCheckpoint));
|
|
96
|
+
this.blockHeight.record(Math.max(...blocks.map((b)=>b.number)), {
|
|
97
|
+
[Attributes.STATUS]: 'checkpointed'
|
|
98
|
+
});
|
|
71
99
|
this.checkpointHeight.record(Math.max(...blocks.map((b)=>b.checkpointNumber)));
|
|
72
100
|
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
101
|
}
|
|
79
102
|
processNewMessages(count, syncPerMessageMs) {
|
|
80
103
|
if (count === 0) {
|
|
@@ -84,9 +107,22 @@ export class ArchiverInstrumentation {
|
|
|
84
107
|
this.syncDurationPerMessage.record(Math.ceil(syncPerMessageMs));
|
|
85
108
|
}
|
|
86
109
|
processPrune(duration) {
|
|
87
|
-
this.pruneCount.add(1
|
|
110
|
+
this.pruneCount.add(1, {
|
|
111
|
+
[Attributes.PRUNE_TYPE]: 'unproven'
|
|
112
|
+
});
|
|
88
113
|
this.pruneDuration.record(Math.ceil(duration));
|
|
89
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Records a pending-chain reorg, where the archiver dropped proposed blocks (and world-state follows by pruning). The
|
|
117
|
+
* type distinguishes the cause: 'uncheckpointed' (slot ended without a checkpoint), 'l1_conflict' (proposed blocks
|
|
118
|
+
* conflicting with an L1 checkpoint), 'orphan' (no matching proposed checkpoint arrived before the deadline), or
|
|
119
|
+
* 'l1_mismatch' (the local checkpointed tip diverged from L1 — an L1 reorg or a pruned/missed-proof checkpoint — so
|
|
120
|
+
* already-checkpointed blocks were rewound).
|
|
121
|
+
*/ recordPrune(pruneType) {
|
|
122
|
+
this.pruneCount.add(1, {
|
|
123
|
+
[Attributes.PRUNE_TYPE]: pruneType
|
|
124
|
+
});
|
|
125
|
+
}
|
|
90
126
|
updateLastProvenCheckpoint(checkpoint) {
|
|
91
127
|
const lastBlockNumberInCheckpoint = checkpoint.startBlock + checkpoint.blockCount - 1;
|
|
92
128
|
this.blockHeight.record(lastBlockNumberInCheckpoint, {
|
|
@@ -117,6 +153,9 @@ export class ArchiverInstrumentation {
|
|
|
117
153
|
[Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: usedTrace
|
|
118
154
|
});
|
|
119
155
|
}
|
|
156
|
+
/** Records a checkpoint promoted from proposed (blob fetch skipped). */ processCheckpointPromoted() {
|
|
157
|
+
this.checkpointPromotedCount.add(1);
|
|
158
|
+
}
|
|
120
159
|
/**
|
|
121
160
|
* Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
|
|
122
161
|
*/ processCheckpointL1Timing(data) {
|
|
@@ -6,22 +6,22 @@ import { Buffer32 } from '@aztec/foundation/buffer';
|
|
|
6
6
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
7
7
|
import { type Logger } from '@aztec/foundation/log';
|
|
8
8
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
9
|
-
import { type ArchiverEmitter } from '@aztec/stdlib/block';
|
|
9
|
+
import { type ArchiverEmitter, type L2Block } from '@aztec/stdlib/block';
|
|
10
10
|
import { type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
11
11
|
import { type Traceable, type Tracer } from '@aztec/telemetry-client';
|
|
12
|
-
import type
|
|
12
|
+
import { type ArchiverDataStores } from '../store/data_stores.js';
|
|
13
13
|
import type { L2TipsCache } from '../store/l2_tips_cache.js';
|
|
14
14
|
import type { ArchiverInstrumentation } from './instrumentation.js';
|
|
15
15
|
/**
|
|
16
16
|
* Handles L1 synchronization for the archiver.
|
|
17
|
-
* Responsible for fetching checkpoints, L1
|
|
17
|
+
* Responsible for fetching checkpoints, L1 to L2 messages, and handling L1 reorgs.
|
|
18
18
|
*/
|
|
19
19
|
export declare class ArchiverL1Synchronizer implements Traceable {
|
|
20
20
|
private readonly publicClient;
|
|
21
21
|
private readonly debugClient;
|
|
22
22
|
private readonly rollup;
|
|
23
23
|
private readonly inbox;
|
|
24
|
-
private readonly
|
|
24
|
+
private readonly stores;
|
|
25
25
|
private config;
|
|
26
26
|
private readonly blobClient;
|
|
27
27
|
private readonly epochCache;
|
|
@@ -35,9 +35,10 @@ export declare class ArchiverL1Synchronizer implements Traceable {
|
|
|
35
35
|
private l1Timestamp;
|
|
36
36
|
private readonly updater;
|
|
37
37
|
readonly tracer: Tracer;
|
|
38
|
-
constructor(publicClient: ViemPublicClient, debugClient: ViemPublicDebugClient, rollup: RollupContract, inbox: InboxContract,
|
|
38
|
+
constructor(publicClient: ViemPublicClient, debugClient: ViemPublicDebugClient, rollup: RollupContract, inbox: InboxContract, stores: ArchiverDataStores, config: {
|
|
39
39
|
batchSize: number;
|
|
40
40
|
skipValidateCheckpointAttestations?: boolean;
|
|
41
|
+
skipPromoteProposedCheckpointDuringL1Sync?: boolean;
|
|
41
42
|
maxAllowedEthClientDriftSeconds: number;
|
|
42
43
|
}, blobClient: BlobClientInterface, epochCache: EpochCache, dateProvider: DateProvider, instrumentation: ArchiverInstrumentation, l1Constants: L1RollupConstants & {
|
|
43
44
|
l1StartBlockHash: Buffer32;
|
|
@@ -47,15 +48,17 @@ export declare class ArchiverL1Synchronizer implements Traceable {
|
|
|
47
48
|
setConfig(newConfig: {
|
|
48
49
|
batchSize: number;
|
|
49
50
|
skipValidateCheckpointAttestations?: boolean;
|
|
51
|
+
skipPromoteProposedCheckpointDuringL1Sync?: boolean;
|
|
50
52
|
maxAllowedEthClientDriftSeconds: number;
|
|
51
53
|
}): void;
|
|
52
54
|
/** Returns the last L1 block number that was synced. */
|
|
53
55
|
getL1BlockNumber(): bigint | undefined;
|
|
54
56
|
/** Returns the last L1 timestamp that was synced. */
|
|
55
57
|
getL1Timestamp(): bigint | undefined;
|
|
58
|
+
private getSignatureContext;
|
|
56
59
|
/** Checks that the ethereum node we are connected to has a latest timestamp no more than the allowed drift. Throw if not. */
|
|
57
60
|
testEthereumNodeSynced(): Promise<void>;
|
|
58
|
-
syncFromL1(initialSyncComplete: boolean): Promise<
|
|
61
|
+
syncFromL1(initialSyncComplete: boolean): Promise<L2Block[]>;
|
|
59
62
|
private updateFinalizedCheckpoint;
|
|
60
63
|
private pruneUncheckpointedBlocks;
|
|
61
64
|
private canPrune;
|
|
@@ -67,7 +70,8 @@ export declare class ArchiverL1Synchronizer implements Traceable {
|
|
|
67
70
|
private rollbackL1ToL2Messages;
|
|
68
71
|
private getL1BlockHash;
|
|
69
72
|
private handleCheckpoints;
|
|
73
|
+
private tryBuildPublishedCheckpointFromProposed;
|
|
70
74
|
private checkForNewCheckpointsBeforeL1SyncPoint;
|
|
71
75
|
private getCheckpointHeader;
|
|
72
76
|
}
|
|
73
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
77
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDFfc3luY2hyb25pemVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbW9kdWxlcy9sMV9zeW5jaHJvbml6ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQUNyRSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDaEQsT0FBTyxFQUFFLGFBQWEsRUFBMkIsY0FBYyxFQUFFLE1BQU0sMkJBQTJCLENBQUM7QUFHbkcsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUscUJBQXFCLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUlyRixPQUFPLEVBQVksUUFBUSxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFFOUQsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sRUFBRSxLQUFLLE1BQU0sRUFBZ0IsTUFBTSx1Q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