@aztec/archiver 0.0.1-commit.d3ec352c → 0.0.1-commit.e3c1de76
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 +156 -22
- package/dest/archiver.d.ts +136 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +781 -0
- package/dest/config.d.ts +30 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/{archiver/config.js → config.js} +21 -5
- package/dest/errors.d.ts +41 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/errors.js +62 -0
- package/dest/factory.d.ts +9 -7
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +89 -11
- package/dest/index.d.ts +10 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +8 -3
- package/dest/interfaces.d.ts +9 -0
- package/dest/interfaces.d.ts.map +1 -0
- package/dest/interfaces.js +3 -0
- package/dest/l1/bin/retrieve-calldata.d.ts +3 -0
- package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
- package/dest/l1/bin/retrieve-calldata.js +149 -0
- package/dest/l1/calldata_retriever.d.ts +112 -0
- package/dest/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/l1/calldata_retriever.js +471 -0
- package/dest/l1/data_retrieval.d.ts +88 -0
- package/dest/l1/data_retrieval.d.ts.map +1 -0
- package/dest/{archiver → l1}/data_retrieval.js +75 -150
- package/dest/l1/debug_tx.d.ts +19 -0
- package/dest/l1/debug_tx.d.ts.map +1 -0
- package/dest/l1/debug_tx.js +73 -0
- package/dest/l1/spire_proposer.d.ts +70 -0
- package/dest/l1/spire_proposer.d.ts.map +1 -0
- package/dest/l1/spire_proposer.js +157 -0
- package/dest/l1/trace_tx.d.ts +97 -0
- package/dest/l1/trace_tx.d.ts.map +1 -0
- package/dest/l1/trace_tx.js +91 -0
- package/dest/l1/types.d.ts +12 -0
- package/dest/l1/types.d.ts.map +1 -0
- package/dest/l1/types.js +3 -0
- package/dest/l1/validate_trace.d.ts +32 -0
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/l1/validate_trace.js +154 -0
- package/dest/modules/data_source_base.d.ts +84 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +260 -0
- package/dest/modules/data_store_updater.d.ts +73 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +302 -0
- package/dest/modules/instrumentation.d.ts +37 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/{archiver → modules}/instrumentation.js +30 -60
- package/dest/modules/l1_synchronizer.d.ts +75 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.js +1112 -0
- package/dest/modules/validation.d.ts +17 -0
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +7 -1
- package/dest/store/block_store.d.ts +192 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/store/block_store.js +721 -0
- package/dest/store/contract_class_store.d.ts +18 -0
- package/dest/store/contract_class_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +13 -9
- package/dest/store/contract_instance_store.d.ts +24 -0
- package/dest/store/contract_instance_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +1 -1
- package/dest/store/kv_archiver_store.d.ts +340 -0
- package/dest/store/kv_archiver_store.d.ts.map +1 -0
- package/dest/store/kv_archiver_store.js +446 -0
- package/dest/store/log_store.d.ts +54 -0
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/store/log_store.js +436 -0
- package/dest/store/message_store.d.ts +40 -0
- package/dest/store/message_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/message_store.js +15 -14
- package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
- package/dest/structs/data_retrieval.d.ts.map +1 -0
- package/dest/structs/inbox_message.d.ts +15 -0
- package/dest/structs/inbox_message.d.ts.map +1 -0
- package/dest/{archiver/structs → structs}/inbox_message.js +6 -6
- package/dest/structs/published.d.ts +2 -0
- package/dest/structs/published.d.ts.map +1 -0
- package/dest/test/fake_l1_state.d.ts +190 -0
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/fake_l1_state.js +383 -0
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +4 -1
- package/dest/test/mock_archiver.d.ts +5 -6
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +6 -11
- package/dest/test/mock_l1_to_l2_message_source.d.ts +6 -7
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +19 -14
- package/dest/test/mock_l2_block_source.d.ts +30 -16
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +175 -68
- package/dest/test/mock_structs.d.ts +80 -4
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +145 -12
- package/dest/test/noop_l1_archiver.d.ts +23 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +68 -0
- package/package.json +18 -18
- package/src/archiver.ts +543 -0
- package/src/{archiver/config.ts → config.ts} +28 -12
- package/src/errors.ts +102 -0
- package/src/factory.ts +125 -11
- package/src/index.ts +10 -3
- package/src/interfaces.ts +9 -0
- package/src/l1/README.md +98 -0
- package/src/l1/bin/retrieve-calldata.ts +187 -0
- package/src/l1/calldata_retriever.ts +641 -0
- package/src/{archiver → l1}/data_retrieval.ts +138 -220
- package/src/l1/debug_tx.ts +99 -0
- package/src/l1/spire_proposer.ts +160 -0
- package/src/l1/trace_tx.ts +128 -0
- package/src/l1/types.ts +13 -0
- package/src/l1/validate_trace.ts +229 -0
- package/src/modules/data_source_base.ts +367 -0
- package/src/modules/data_store_updater.ts +423 -0
- package/src/{archiver → modules}/instrumentation.ts +34 -64
- package/src/modules/l1_synchronizer.ts +930 -0
- package/src/{archiver → modules}/validation.ts +11 -6
- package/src/store/block_store.ts +966 -0
- package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +13 -9
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +2 -2
- package/src/store/kv_archiver_store.ts +639 -0
- package/src/store/log_store.ts +575 -0
- package/src/{archiver/kv_archiver_store → store}/message_store.ts +21 -18
- package/src/{archiver/structs → structs}/inbox_message.ts +7 -8
- package/src/{archiver/structs → structs}/published.ts +0 -1
- package/src/test/fake_l1_state.ts +599 -0
- package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
- package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
- package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
- package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
- package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
- package/src/test/fixtures/trace_transaction-proxied.json +128 -0
- package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
- package/src/test/index.ts +4 -0
- package/src/test/mock_archiver.ts +8 -13
- package/src/test/mock_l1_to_l2_message_source.ts +16 -15
- package/src/test/mock_l2_block_source.ts +191 -81
- package/src/test/mock_structs.ts +275 -14
- package/src/test/noop_l1_archiver.ts +109 -0
- package/dest/archiver/archiver.d.ts +0 -290
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -1434
- package/dest/archiver/archiver_store.d.ts +0 -256
- package/dest/archiver/archiver_store.d.ts.map +0 -1
- package/dest/archiver/archiver_store.js +0 -4
- package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
- package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
- package/dest/archiver/archiver_store_test_suite.js +0 -1289
- package/dest/archiver/config.d.ts +0 -21
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/data_retrieval.d.ts +0 -80
- package/dest/archiver/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts +0 -12
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/errors.js +0 -17
- package/dest/archiver/index.d.ts +0 -7
- package/dest/archiver/index.d.ts.map +0 -1
- package/dest/archiver/index.js +0 -4
- package/dest/archiver/instrumentation.d.ts +0 -35
- package/dest/archiver/instrumentation.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -125
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.js +0 -371
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -169
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -296
- package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -49
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/log_store.js +0 -337
- package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -39
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
- package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/structs/inbox_message.d.ts +0 -15
- package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
- package/dest/archiver/structs/published.d.ts +0 -3
- package/dest/archiver/structs/published.d.ts.map +0 -1
- package/dest/archiver/validation.d.ts +0 -17
- package/dest/archiver/validation.d.ts.map +0 -1
- package/dest/rpc/index.d.ts +0 -9
- package/dest/rpc/index.d.ts.map +0 -1
- package/dest/rpc/index.js +0 -15
- package/src/archiver/archiver.ts +0 -1880
- package/src/archiver/archiver_store.ts +0 -310
- package/src/archiver/archiver_store_test_suite.ts +0 -1295
- package/src/archiver/errors.ts +0 -26
- package/src/archiver/index.ts +0 -6
- package/src/archiver/kv_archiver_store/block_store.ts +0 -482
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -423
- package/src/archiver/kv_archiver_store/log_store.ts +0 -407
- package/src/rpc/index.ts +0 -16
- /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
- /package/dest/{archiver/structs → structs}/published.js +0 -0
- /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { ContractClassPublishedEvent, PrivateFunctionBroadcastedEvent, UtilityFunctionBroadcastedEvent } from '@aztec/protocol-contracts/class-registry';
|
|
5
|
+
import { ContractInstancePublishedEvent, ContractInstanceUpdatedEvent } from '@aztec/protocol-contracts/instance-registry';
|
|
6
|
+
import { computePublicBytecodeCommitment, isValidPrivateFunctionMembershipProof, isValidUtilityFunctionMembershipProof } from '@aztec/stdlib/contract';
|
|
7
|
+
import groupBy from 'lodash.groupby';
|
|
8
|
+
/** Operation type for contract data updates. */ var Operation = /*#__PURE__*/ function(Operation) {
|
|
9
|
+
Operation[Operation["Store"] = 0] = "Store";
|
|
10
|
+
Operation[Operation["Delete"] = 1] = "Delete";
|
|
11
|
+
return Operation;
|
|
12
|
+
}(Operation || {});
|
|
13
|
+
/** Archiver helper module to handle updates to the data store. */ export class ArchiverDataStoreUpdater {
|
|
14
|
+
store;
|
|
15
|
+
log;
|
|
16
|
+
constructor(store){
|
|
17
|
+
this.store = store;
|
|
18
|
+
this.log = createLogger('archiver:store_updater');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Adds proposed blocks to the store with contract class/instance extraction from logs.
|
|
22
|
+
* These are uncheckpointed blocks that have been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
23
|
+
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
|
|
24
|
+
* and individually broadcasted functions from the block logs.
|
|
25
|
+
*
|
|
26
|
+
* @param blocks - The proposed L2 blocks to add.
|
|
27
|
+
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
28
|
+
* @returns True if the operation is successful.
|
|
29
|
+
*/ addProposedBlocks(blocks, pendingChainValidationStatus) {
|
|
30
|
+
return this.store.transactionAsync(async ()=>{
|
|
31
|
+
await this.store.addProposedBlocks(blocks);
|
|
32
|
+
const opResults = await Promise.all([
|
|
33
|
+
// Update the pending chain validation status if provided
|
|
34
|
+
pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
|
|
35
|
+
// Add any logs emitted during the retrieved blocks
|
|
36
|
+
this.store.addLogs(blocks),
|
|
37
|
+
// Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
|
|
38
|
+
...blocks.map((block)=>this.addContractDataToDb(block))
|
|
39
|
+
]);
|
|
40
|
+
return opResults.every(Boolean);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Reconciles local blocks with incoming checkpoints from L1.
|
|
45
|
+
* Adds new checkpoints to the store with contract class/instance extraction from logs.
|
|
46
|
+
* Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
|
|
47
|
+
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
|
|
48
|
+
* and individually broadcasted functions from the checkpoint block logs.
|
|
49
|
+
*
|
|
50
|
+
* @param checkpoints - The published checkpoints to add.
|
|
51
|
+
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
52
|
+
* @returns Result with information about any pruned blocks.
|
|
53
|
+
*/ addCheckpoints(checkpoints, pendingChainValidationStatus) {
|
|
54
|
+
return this.store.transactionAsync(async ()=>{
|
|
55
|
+
// Before adding checkpoints, check for conflicts with local blocks if any
|
|
56
|
+
const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
|
|
57
|
+
await this.store.addCheckpoints(checkpoints);
|
|
58
|
+
// Filter out blocks that were already inserted via addProposedBlocks() to avoid duplicating logs/contract data
|
|
59
|
+
const newBlocks = checkpoints.flatMap((ch)=>ch.checkpoint.blocks).filter((b)=>lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
|
|
60
|
+
await Promise.all([
|
|
61
|
+
// Update the pending chain validation status if provided
|
|
62
|
+
pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
|
|
63
|
+
// Add any logs emitted during the retrieved blocks
|
|
64
|
+
this.store.addLogs(newBlocks),
|
|
65
|
+
// Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
|
|
66
|
+
...newBlocks.map((block)=>this.addContractDataToDb(block))
|
|
67
|
+
]);
|
|
68
|
+
return {
|
|
69
|
+
prunedBlocks,
|
|
70
|
+
lastAlreadyInsertedBlockNumber
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Checks for local proposed blocks that do not match the ones to be checkpointed and prunes them.
|
|
76
|
+
* This method handles multiple checkpoints but returns after pruning the first conflict found.
|
|
77
|
+
* This is correct because pruning from the first conflict point removes all subsequent blocks,
|
|
78
|
+
* and when checkpoints are added afterward, they include all the correct blocks.
|
|
79
|
+
*/ async pruneMismatchingLocalBlocks(checkpoints) {
|
|
80
|
+
const [lastCheckpointedBlockNumber, lastBlockNumber] = await Promise.all([
|
|
81
|
+
this.store.getCheckpointedL2BlockNumber(),
|
|
82
|
+
this.store.getLatestBlockNumber()
|
|
83
|
+
]);
|
|
84
|
+
// Exit early if there are no local uncheckpointed blocks
|
|
85
|
+
if (lastBlockNumber === lastCheckpointedBlockNumber) {
|
|
86
|
+
return {
|
|
87
|
+
prunedBlocks: undefined,
|
|
88
|
+
lastAlreadyInsertedBlockNumber: undefined
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// Get all uncheckpointed local blocks
|
|
92
|
+
const uncheckpointedLocalBlocks = await this.store.getBlocks(BlockNumber.add(lastCheckpointedBlockNumber, 1), lastBlockNumber - lastCheckpointedBlockNumber);
|
|
93
|
+
let lastAlreadyInsertedBlockNumber;
|
|
94
|
+
for (const publishedCheckpoint of checkpoints){
|
|
95
|
+
const checkpointBlocks = publishedCheckpoint.checkpoint.blocks;
|
|
96
|
+
const slot = publishedCheckpoint.checkpoint.slot;
|
|
97
|
+
const localBlocksInSlot = uncheckpointedLocalBlocks.filter((b)=>b.slot === slot);
|
|
98
|
+
if (checkpointBlocks.length === 0) {
|
|
99
|
+
this.log.warn(`Checkpoint ${publishedCheckpoint.checkpoint.number} for slot ${slot} has no blocks`);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
// Find the first checkpoint block that conflicts with an existing local block and prune local afterwards
|
|
103
|
+
for (const checkpointBlock of checkpointBlocks){
|
|
104
|
+
const blockNumber = checkpointBlock.number;
|
|
105
|
+
const existingBlock = localBlocksInSlot.find((b)=>b.number === blockNumber);
|
|
106
|
+
const blockInfos = {
|
|
107
|
+
existingBlock: existingBlock?.toBlockInfo(),
|
|
108
|
+
checkpointBlock: checkpointBlock.toBlockInfo()
|
|
109
|
+
};
|
|
110
|
+
if (!existingBlock) {
|
|
111
|
+
this.log.verbose(`No local block found for checkpointed block number ${blockNumber}`, blockInfos);
|
|
112
|
+
} else if (existingBlock.archive.root.equals(checkpointBlock.archive.root)) {
|
|
113
|
+
this.log.verbose(`Block number ${blockNumber} already inserted and matches checkpoint`, blockInfos);
|
|
114
|
+
lastAlreadyInsertedBlockNumber = blockNumber;
|
|
115
|
+
} else {
|
|
116
|
+
this.log.warn(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
|
|
117
|
+
const prunedBlocks = await this.removeBlocksAfter(BlockNumber(blockNumber - 1));
|
|
118
|
+
return {
|
|
119
|
+
prunedBlocks,
|
|
120
|
+
lastAlreadyInsertedBlockNumber
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// If local has more blocks than the checkpoint (e.g., local has [2,3,4] but checkpoint has [2,3]),
|
|
125
|
+
// we need to prune the extra local blocks so they match what was checkpointed
|
|
126
|
+
const lastCheckpointBlockNumber = checkpointBlocks.at(-1).number;
|
|
127
|
+
const lastLocalBlockNumber = localBlocksInSlot.at(-1)?.number;
|
|
128
|
+
if (lastLocalBlockNumber !== undefined && lastLocalBlockNumber > lastCheckpointBlockNumber) {
|
|
129
|
+
this.log.warn(`Local chain for slot ${slot} ends at block ${lastLocalBlockNumber} but checkpoint ends at ${lastCheckpointBlockNumber}. Pruning blocks after block ${lastCheckpointBlockNumber}.`);
|
|
130
|
+
const prunedBlocks = await this.removeBlocksAfter(lastCheckpointBlockNumber);
|
|
131
|
+
return {
|
|
132
|
+
prunedBlocks,
|
|
133
|
+
lastAlreadyInsertedBlockNumber
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
prunedBlocks: undefined,
|
|
139
|
+
lastAlreadyInsertedBlockNumber
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Removes all uncheckpointed blocks strictly after the specified block number and cleans up associated contract data.
|
|
144
|
+
* This handles removal of provisionally added blocks along with their contract classes/instances.
|
|
145
|
+
* Verifies that each block being removed is not part of a stored checkpoint.
|
|
146
|
+
*
|
|
147
|
+
* @param blockNumber - Remove all blocks with number greater than this.
|
|
148
|
+
* @returns The removed blocks.
|
|
149
|
+
* @throws Error if any block to be removed is checkpointed.
|
|
150
|
+
*/ removeUncheckpointedBlocksAfter(blockNumber) {
|
|
151
|
+
return this.store.transactionAsync(async ()=>{
|
|
152
|
+
// Verify we're only removing uncheckpointed blocks
|
|
153
|
+
const lastCheckpointedBlockNumber = await this.store.getCheckpointedL2BlockNumber();
|
|
154
|
+
if (blockNumber < lastCheckpointedBlockNumber) {
|
|
155
|
+
throw new Error(`Cannot remove blocks after ${blockNumber} because checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`);
|
|
156
|
+
}
|
|
157
|
+
return await this.removeBlocksAfter(blockNumber);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Removes all blocks strictly after the given block number along with any logs and contract data.
|
|
162
|
+
* Does not remove their checkpoints.
|
|
163
|
+
*/ async removeBlocksAfter(blockNumber) {
|
|
164
|
+
// First get the blocks to be removed so we can clean up contract data
|
|
165
|
+
const removedBlocks = await this.store.removeBlocksAfter(blockNumber);
|
|
166
|
+
// Clean up contract data and logs for the removed blocks
|
|
167
|
+
await Promise.all([
|
|
168
|
+
this.store.deleteLogs(removedBlocks),
|
|
169
|
+
...removedBlocks.map((block)=>this.removeContractDataFromDb(block))
|
|
170
|
+
]);
|
|
171
|
+
return removedBlocks;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Removes all checkpoints after the given checkpoint number.
|
|
175
|
+
* Deletes ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated data
|
|
176
|
+
* that was stored for the removed checkpoints. Also removes ALL blocks (both checkpointed
|
|
177
|
+
* and uncheckpointed) after the last block of the given checkpoint.
|
|
178
|
+
*
|
|
179
|
+
* @param checkpointNumber - Remove all checkpoints strictly after this one.
|
|
180
|
+
* @returns True if the operation is successful.
|
|
181
|
+
*/ async removeCheckpointsAfter(checkpointNumber) {
|
|
182
|
+
const { blocksRemoved = [] } = await this.store.removeCheckpointsAfter(checkpointNumber);
|
|
183
|
+
const opResults = await Promise.all([
|
|
184
|
+
// Prune rolls back to the last proven block, which is by definition valid
|
|
185
|
+
this.store.setPendingChainValidationStatus({
|
|
186
|
+
valid: true
|
|
187
|
+
}),
|
|
188
|
+
// Remove contract data for all blocks being removed
|
|
189
|
+
...blocksRemoved.map((block)=>this.removeContractDataFromDb(block)),
|
|
190
|
+
this.store.deleteLogs(blocksRemoved)
|
|
191
|
+
]);
|
|
192
|
+
return opResults.every(Boolean);
|
|
193
|
+
}
|
|
194
|
+
/** Extracts and stores contract data from a single block. */ addContractDataToDb(block) {
|
|
195
|
+
return this.updateContractDataOnDb(block, 0);
|
|
196
|
+
}
|
|
197
|
+
/** Removes contract data associated with a block. */ removeContractDataFromDb(block) {
|
|
198
|
+
return this.updateContractDataOnDb(block, 1);
|
|
199
|
+
}
|
|
200
|
+
/** Adds or remove contract data associated with a block. */ async updateContractDataOnDb(block, operation) {
|
|
201
|
+
const contractClassLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.contractClassLogs);
|
|
202
|
+
const privateLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.privateLogs);
|
|
203
|
+
const publicLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.publicLogs);
|
|
204
|
+
return (await Promise.all([
|
|
205
|
+
this.updatePublishedContractClasses(contractClassLogs, block.number, operation),
|
|
206
|
+
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)
|
|
209
|
+
])).every(Boolean);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Extracts and stores contract classes out of ContractClassPublished events emitted by the class registry contract.
|
|
213
|
+
*/ async updatePublishedContractClasses(allLogs, blockNum, operation) {
|
|
214
|
+
const contractClassPublishedEvents = allLogs.filter((log)=>ContractClassPublishedEvent.isContractClassPublishedEvent(log)).map((log)=>ContractClassPublishedEvent.fromLog(log));
|
|
215
|
+
const contractClasses = await Promise.all(contractClassPublishedEvents.map((e)=>e.toContractClassPublic()));
|
|
216
|
+
if (contractClasses.length > 0) {
|
|
217
|
+
contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
218
|
+
if (operation == 0) {
|
|
219
|
+
// TODO: Will probably want to create some worker threads to compute these bytecode commitments as they are expensive
|
|
220
|
+
const commitments = await Promise.all(contractClasses.map((c)=>computePublicBytecodeCommitment(c.packedBytecode)));
|
|
221
|
+
return await this.store.addContractClasses(contractClasses, commitments, blockNum);
|
|
222
|
+
} else if (operation == 1) {
|
|
223
|
+
return await this.store.deleteContractClasses(contractClasses, blockNum);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Extracts and stores contract instances out of ContractInstancePublished events emitted by the canonical deployer contract.
|
|
230
|
+
*/ async updateDeployedContractInstances(allLogs, blockNum, operation) {
|
|
231
|
+
const contractInstances = allLogs.filter((log)=>ContractInstancePublishedEvent.isContractInstancePublishedEvent(log)).map((log)=>ContractInstancePublishedEvent.fromLog(log)).map((e)=>e.toContractInstance());
|
|
232
|
+
if (contractInstances.length > 0) {
|
|
233
|
+
contractInstances.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance at ${c.address.toString()}`));
|
|
234
|
+
if (operation == 0) {
|
|
235
|
+
return await this.store.addContractInstances(contractInstances, blockNum);
|
|
236
|
+
} else if (operation == 1) {
|
|
237
|
+
return await this.store.deleteContractInstances(contractInstances, blockNum);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Extracts and stores contract instance updates out of ContractInstanceUpdated events.
|
|
244
|
+
*/ async updateUpdatedContractInstances(allLogs, timestamp, operation) {
|
|
245
|
+
const contractUpdates = allLogs.filter((log)=>ContractInstanceUpdatedEvent.isContractInstanceUpdatedEvent(log)).map((log)=>ContractInstanceUpdatedEvent.fromLog(log)).map((e)=>e.toContractInstanceUpdate());
|
|
246
|
+
if (contractUpdates.length > 0) {
|
|
247
|
+
contractUpdates.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance update at ${c.address.toString()}`));
|
|
248
|
+
if (operation == 0) {
|
|
249
|
+
return await this.store.addContractInstanceUpdates(contractUpdates, timestamp);
|
|
250
|
+
} else if (operation == 1) {
|
|
251
|
+
return await this.store.deleteContractInstanceUpdates(contractUpdates, timestamp);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Stores the functions that were broadcasted individually.
|
|
258
|
+
*
|
|
259
|
+
* @dev Beware that there is not a delete variant of this, since they are added to contract classes
|
|
260
|
+
* and will be deleted as part of the class if needed.
|
|
261
|
+
*/ async storeBroadcastedIndividualFunctions(allLogs, _blockNum) {
|
|
262
|
+
// Filter out private and utility function broadcast events
|
|
263
|
+
const privateFnEvents = allLogs.filter((log)=>PrivateFunctionBroadcastedEvent.isPrivateFunctionBroadcastedEvent(log)).map((log)=>PrivateFunctionBroadcastedEvent.fromLog(log));
|
|
264
|
+
const utilityFnEvents = allLogs.filter((log)=>UtilityFunctionBroadcastedEvent.isUtilityFunctionBroadcastedEvent(log)).map((log)=>UtilityFunctionBroadcastedEvent.fromLog(log));
|
|
265
|
+
// Group all events by contract class id
|
|
266
|
+
for (const [classIdString, classEvents] of Object.entries(groupBy([
|
|
267
|
+
...privateFnEvents,
|
|
268
|
+
...utilityFnEvents
|
|
269
|
+
], (e)=>e.contractClassId.toString()))){
|
|
270
|
+
const contractClassId = Fr.fromHexString(classIdString);
|
|
271
|
+
const contractClass = await this.store.getContractClass(contractClassId);
|
|
272
|
+
if (!contractClass) {
|
|
273
|
+
this.log.warn(`Skipping broadcasted functions as contract class ${contractClassId.toString()} was not found`);
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
// Split private and utility functions, and filter out invalid ones
|
|
277
|
+
const allFns = classEvents.map((e)=>e.toFunctionWithMembershipProof());
|
|
278
|
+
const privateFns = allFns.filter((fn)=>'utilityFunctionsTreeRoot' in fn);
|
|
279
|
+
const utilityFns = allFns.filter((fn)=>'privateFunctionsArtifactTreeRoot' in fn);
|
|
280
|
+
const privateFunctionsWithValidity = await Promise.all(privateFns.map(async (fn)=>({
|
|
281
|
+
fn,
|
|
282
|
+
valid: await isValidPrivateFunctionMembershipProof(fn, contractClass)
|
|
283
|
+
})));
|
|
284
|
+
const validPrivateFns = privateFunctionsWithValidity.filter(({ valid })=>valid).map(({ fn })=>fn);
|
|
285
|
+
const utilityFunctionsWithValidity = await Promise.all(utilityFns.map(async (fn)=>({
|
|
286
|
+
fn,
|
|
287
|
+
valid: await isValidUtilityFunctionMembershipProof(fn, contractClass)
|
|
288
|
+
})));
|
|
289
|
+
const validUtilityFns = utilityFunctionsWithValidity.filter(({ valid })=>valid).map(({ fn })=>fn);
|
|
290
|
+
const validFnCount = validPrivateFns.length + validUtilityFns.length;
|
|
291
|
+
if (validFnCount !== allFns.length) {
|
|
292
|
+
this.log.warn(`Skipping ${allFns.length - validFnCount} invalid functions`);
|
|
293
|
+
}
|
|
294
|
+
// Store the functions in the contract class in a single operation
|
|
295
|
+
if (validFnCount > 0) {
|
|
296
|
+
this.log.verbose(`Storing ${validFnCount} functions for contract class ${contractClassId.toString()}`);
|
|
297
|
+
}
|
|
298
|
+
return await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
|
|
299
|
+
}
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
2
|
+
import { type LmdbStatsCallback, type TelemetryClient, type Tracer } from '@aztec/telemetry-client';
|
|
3
|
+
export declare class ArchiverInstrumentation {
|
|
4
|
+
private telemetry;
|
|
5
|
+
readonly tracer: Tracer;
|
|
6
|
+
private blockHeight;
|
|
7
|
+
private txCount;
|
|
8
|
+
private l1BlockHeight;
|
|
9
|
+
private proofsSubmittedDelay;
|
|
10
|
+
private proofsSubmittedCount;
|
|
11
|
+
private dbMetrics;
|
|
12
|
+
private pruneDuration;
|
|
13
|
+
private pruneCount;
|
|
14
|
+
private syncDurationPerBlock;
|
|
15
|
+
private syncBlockCount;
|
|
16
|
+
private manaPerBlock;
|
|
17
|
+
private txsPerBlock;
|
|
18
|
+
private syncDurationPerMessage;
|
|
19
|
+
private syncMessageCount;
|
|
20
|
+
private blockProposalTxTargetCount;
|
|
21
|
+
private log;
|
|
22
|
+
private constructor();
|
|
23
|
+
static new(telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback): Promise<ArchiverInstrumentation>;
|
|
24
|
+
isEnabled(): boolean;
|
|
25
|
+
processNewBlocks(syncTimePerBlock: number, blocks: L2Block[]): void;
|
|
26
|
+
processNewMessages(count: number, syncPerMessageMs: number): void;
|
|
27
|
+
processPrune(duration: number): void;
|
|
28
|
+
updateLastProvenBlock(blockNumber: number): void;
|
|
29
|
+
processProofsVerified(logs: {
|
|
30
|
+
proverId: string;
|
|
31
|
+
l2BlockNumber: bigint;
|
|
32
|
+
delay: bigint;
|
|
33
|
+
}[]): void;
|
|
34
|
+
updateL1BlockHeight(blockNumber: bigint): void;
|
|
35
|
+
recordBlockProposalTxTarget(target: string, usedTrace: boolean): void;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5zdHJ1bWVudGF0aW9uLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbW9kdWxlcy9pbnN0cnVtZW50YXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDbkQsT0FBTyxFQUtMLEtBQUssaUJBQWlCLEVBRXRCLEtBQUssZUFBZSxFQUNwQixLQUFLLE1BQU0sRUFHWixNQUFNLHlCQUF5QixDQUFDO0FBRWpDLHFCQUFhLHVCQUF1QjtJQTBCaEMsT0FBTyxDQUFDLFNBQVM7SUF6Qm5CLFNBQWdCLE1BQU0sRUFBRSxNQUFNLENBQUM7SUFFL0Is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Ae,EAAE,SAAS,CAAC,EAAE,iBAAiB,oCAMhF;IAEM,SAAS,IAAI,OAAO,CAE1B;IAEM,gBAAgB,CAAC,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAUlE;IAEM,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,QAMhE;IAEM,YAAY,CAAC,QAAQ,EAAE,MAAM,QAGnC;IAEM,qBAAqB,CAAC,WAAW,EAAE,MAAM,QAE/C;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;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
-
import { Attributes, LmdbMetrics, Metrics,
|
|
2
|
+
import { Attributes, LmdbMetrics, Metrics, createUpDownCounterWithDefault } from '@aztec/telemetry-client';
|
|
3
3
|
export class ArchiverInstrumentation {
|
|
4
4
|
telemetry;
|
|
5
5
|
tracer;
|
|
@@ -17,69 +17,36 @@ export class ArchiverInstrumentation {
|
|
|
17
17
|
txsPerBlock;
|
|
18
18
|
syncDurationPerMessage;
|
|
19
19
|
syncMessageCount;
|
|
20
|
+
blockProposalTxTargetCount;
|
|
20
21
|
log;
|
|
21
22
|
constructor(telemetry, lmdbStats){
|
|
22
23
|
this.telemetry = telemetry;
|
|
23
24
|
this.log = createLogger('archiver:instrumentation');
|
|
24
25
|
this.tracer = telemetry.getTracer('Archiver');
|
|
25
26
|
const meter = telemetry.getMeter('Archiver');
|
|
26
|
-
this.blockHeight = meter.createGauge(Metrics.ARCHIVER_BLOCK_HEIGHT
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
this.blockHeight = meter.createGauge(Metrics.ARCHIVER_BLOCK_HEIGHT);
|
|
28
|
+
this.l1BlockHeight = meter.createGauge(Metrics.ARCHIVER_L1_BLOCK_HEIGHT);
|
|
29
|
+
this.txCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_TOTAL_TXS);
|
|
30
|
+
this.proofsSubmittedCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_ROLLUP_PROOF_COUNT, {
|
|
31
|
+
[Attributes.PROOF_TIMED_OUT]: [
|
|
32
|
+
true,
|
|
33
|
+
false
|
|
34
|
+
]
|
|
29
35
|
});
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
description: 'Time after a block is submitted until its proof is published',
|
|
45
|
-
valueType: ValueType.INT
|
|
46
|
-
});
|
|
47
|
-
this.syncDurationPerBlock = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_BLOCK, {
|
|
48
|
-
unit: 'ms',
|
|
49
|
-
description: 'Duration to sync a block',
|
|
50
|
-
valueType: ValueType.INT
|
|
51
|
-
});
|
|
52
|
-
this.syncBlockCount = meter.createUpDownCounter(Metrics.ARCHIVER_SYNC_BLOCK_COUNT, {
|
|
53
|
-
description: 'Number of blocks synced from L1',
|
|
54
|
-
valueType: ValueType.INT
|
|
55
|
-
});
|
|
56
|
-
this.manaPerBlock = meter.createHistogram(Metrics.ARCHIVER_MANA_PER_BLOCK, {
|
|
57
|
-
description: 'The mana consumed by blocks',
|
|
58
|
-
valueType: ValueType.DOUBLE,
|
|
59
|
-
unit: 'Mmana'
|
|
60
|
-
});
|
|
61
|
-
this.txsPerBlock = meter.createHistogram(Metrics.ARCHIVER_TXS_PER_BLOCK, {
|
|
62
|
-
description: 'The block tx count',
|
|
63
|
-
valueType: ValueType.INT,
|
|
64
|
-
unit: 'tx'
|
|
65
|
-
});
|
|
66
|
-
this.syncDurationPerMessage = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_MESSAGE, {
|
|
67
|
-
unit: 'ms',
|
|
68
|
-
description: 'Duration to sync a message',
|
|
69
|
-
valueType: ValueType.INT
|
|
70
|
-
});
|
|
71
|
-
this.syncMessageCount = meter.createUpDownCounter(Metrics.ARCHIVER_SYNC_MESSAGE_COUNT, {
|
|
72
|
-
description: 'Number of L1 to L2 messages synced',
|
|
73
|
-
valueType: ValueType.INT
|
|
74
|
-
});
|
|
75
|
-
this.pruneDuration = meter.createHistogram(Metrics.ARCHIVER_PRUNE_DURATION, {
|
|
76
|
-
unit: 'ms',
|
|
77
|
-
description: 'Duration to sync a message',
|
|
78
|
-
valueType: ValueType.INT
|
|
79
|
-
});
|
|
80
|
-
this.pruneCount = meter.createUpDownCounter(Metrics.ARCHIVER_PRUNE_COUNT, {
|
|
81
|
-
description: 'Number of prunes detected',
|
|
82
|
-
valueType: ValueType.INT
|
|
36
|
+
this.proofsSubmittedDelay = meter.createHistogram(Metrics.ARCHIVER_ROLLUP_PROOF_DELAY);
|
|
37
|
+
this.syncDurationPerBlock = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_BLOCK);
|
|
38
|
+
this.syncBlockCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_BLOCK_COUNT);
|
|
39
|
+
this.manaPerBlock = meter.createHistogram(Metrics.ARCHIVER_MANA_PER_BLOCK);
|
|
40
|
+
this.txsPerBlock = meter.createHistogram(Metrics.ARCHIVER_TXS_PER_BLOCK);
|
|
41
|
+
this.syncDurationPerMessage = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_MESSAGE);
|
|
42
|
+
this.syncMessageCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_MESSAGE_COUNT);
|
|
43
|
+
this.pruneDuration = meter.createHistogram(Metrics.ARCHIVER_PRUNE_DURATION);
|
|
44
|
+
this.pruneCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_PRUNE_COUNT);
|
|
45
|
+
this.blockProposalTxTargetCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_BLOCK_PROPOSAL_TX_TARGET_COUNT, {
|
|
46
|
+
[Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: [
|
|
47
|
+
true,
|
|
48
|
+
false
|
|
49
|
+
]
|
|
83
50
|
});
|
|
84
51
|
this.dbMetrics = new LmdbMetrics(meter, {
|
|
85
52
|
[Attributes.DB_DATA_TYPE]: 'archiver'
|
|
@@ -87,9 +54,6 @@ export class ArchiverInstrumentation {
|
|
|
87
54
|
}
|
|
88
55
|
static async new(telemetry, lmdbStats) {
|
|
89
56
|
const instance = new ArchiverInstrumentation(telemetry, lmdbStats);
|
|
90
|
-
instance.syncBlockCount.add(0);
|
|
91
|
-
instance.syncMessageCount.add(0);
|
|
92
|
-
instance.pruneCount.add(0);
|
|
93
57
|
await instance.telemetry.flush();
|
|
94
58
|
return instance;
|
|
95
59
|
}
|
|
@@ -137,4 +101,10 @@ export class ArchiverInstrumentation {
|
|
|
137
101
|
updateL1BlockHeight(blockNumber) {
|
|
138
102
|
this.l1BlockHeight.record(Number(blockNumber));
|
|
139
103
|
}
|
|
104
|
+
recordBlockProposalTxTarget(target, usedTrace) {
|
|
105
|
+
this.blockProposalTxTargetCount.add(1, {
|
|
106
|
+
[Attributes.L1_BLOCK_PROPOSAL_TX_TARGET]: target.toLowerCase(),
|
|
107
|
+
[Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: usedTrace
|
|
108
|
+
});
|
|
109
|
+
}
|
|
140
110
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
2
|
+
import { EpochCache } from '@aztec/epoch-cache';
|
|
3
|
+
import { InboxContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
4
|
+
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
5
|
+
import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
|
|
6
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
7
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
8
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
9
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
10
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
11
|
+
import { type ArchiverEmitter } from '@aztec/stdlib/block';
|
|
12
|
+
import { type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
13
|
+
import { type Traceable, type Tracer } from '@aztec/telemetry-client';
|
|
14
|
+
import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
|
|
15
|
+
import type { ArchiverInstrumentation } from './instrumentation.js';
|
|
16
|
+
/**
|
|
17
|
+
* Handles L1 synchronization for the archiver.
|
|
18
|
+
* Responsible for fetching checkpoints, L1→L2 messages, and handling L1 reorgs.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ArchiverL1Synchronizer implements Traceable {
|
|
21
|
+
private readonly publicClient;
|
|
22
|
+
private readonly debugClient;
|
|
23
|
+
private readonly rollup;
|
|
24
|
+
private readonly inbox;
|
|
25
|
+
private readonly l1Addresses;
|
|
26
|
+
private readonly store;
|
|
27
|
+
private config;
|
|
28
|
+
private readonly blobClient;
|
|
29
|
+
private readonly epochCache;
|
|
30
|
+
private readonly dateProvider;
|
|
31
|
+
private readonly instrumentation;
|
|
32
|
+
private readonly l1Constants;
|
|
33
|
+
private readonly events;
|
|
34
|
+
private readonly log;
|
|
35
|
+
private l1BlockNumber;
|
|
36
|
+
private l1BlockHash;
|
|
37
|
+
private l1Timestamp;
|
|
38
|
+
private readonly updater;
|
|
39
|
+
readonly tracer: Tracer;
|
|
40
|
+
constructor(publicClient: ViemPublicClient, debugClient: ViemPublicDebugClient, rollup: RollupContract, inbox: InboxContract, l1Addresses: Pick<L1ContractAddresses, 'registryAddress' | 'governanceProposerAddress' | 'slashFactoryAddress'> & {
|
|
41
|
+
slashingProposerAddress: EthAddress;
|
|
42
|
+
}, store: KVArchiverDataStore, config: {
|
|
43
|
+
batchSize: number;
|
|
44
|
+
skipValidateCheckpointAttestations?: boolean;
|
|
45
|
+
maxAllowedEthClientDriftSeconds: number;
|
|
46
|
+
}, blobClient: BlobClientInterface, epochCache: EpochCache, dateProvider: DateProvider, instrumentation: ArchiverInstrumentation, l1Constants: L1RollupConstants & {
|
|
47
|
+
l1StartBlockHash: Buffer32;
|
|
48
|
+
genesisArchiveRoot: Fr;
|
|
49
|
+
}, events: ArchiverEmitter, tracer: Tracer, log?: Logger);
|
|
50
|
+
/** Sets new config */
|
|
51
|
+
setConfig(newConfig: {
|
|
52
|
+
batchSize: number;
|
|
53
|
+
skipValidateCheckpointAttestations?: boolean;
|
|
54
|
+
maxAllowedEthClientDriftSeconds: number;
|
|
55
|
+
}): void;
|
|
56
|
+
/** Returns the last L1 block number that was synced. */
|
|
57
|
+
getL1BlockNumber(): bigint | undefined;
|
|
58
|
+
/** Returns the last L1 timestamp that was synced. */
|
|
59
|
+
getL1Timestamp(): bigint | undefined;
|
|
60
|
+
/** Checks that the ethereum node we are connected to has a latest timestamp no more than the allowed drift. Throw if not. */
|
|
61
|
+
testEthereumNodeSynced(): Promise<void>;
|
|
62
|
+
syncFromL1(initialSyncComplete: boolean): Promise<void>;
|
|
63
|
+
private pruneUncheckpointedBlocks;
|
|
64
|
+
private canPrune;
|
|
65
|
+
private handleEpochPrune;
|
|
66
|
+
private nextRange;
|
|
67
|
+
private handleL1ToL2Messages;
|
|
68
|
+
private retrieveL1ToL2Message;
|
|
69
|
+
private rollbackL1ToL2Messages;
|
|
70
|
+
private getL1BlockHash;
|
|
71
|
+
private handleCheckpoints;
|
|
72
|
+
private checkForNewCheckpointsBeforeL1SyncPoint;
|
|
73
|
+
private getCheckpointHeader;
|
|
74
|
+
}
|
|
75
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