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