@aztec/archiver 0.0.1-commit.9b94fc1 → 0.0.1-commit.9ee6fcc6

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.
Files changed (211) hide show
  1. package/README.md +156 -22
  2. package/dest/archiver.d.ts +138 -0
  3. package/dest/archiver.d.ts.map +1 -0
  4. package/dest/archiver.js +743 -0
  5. package/dest/config.d.ts +30 -0
  6. package/dest/config.d.ts.map +1 -0
  7. package/dest/{archiver/config.js → config.js} +23 -6
  8. package/dest/errors.d.ts +53 -0
  9. package/dest/errors.d.ts.map +1 -0
  10. package/dest/errors.js +75 -0
  11. package/dest/factory.d.ts +8 -7
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +99 -15
  14. package/dest/index.d.ts +11 -4
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +9 -3
  17. package/dest/interfaces.d.ts +9 -0
  18. package/dest/interfaces.d.ts.map +1 -0
  19. package/dest/interfaces.js +3 -0
  20. package/dest/l1/bin/retrieve-calldata.d.ts +3 -0
  21. package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
  22. package/dest/l1/bin/retrieve-calldata.js +152 -0
  23. package/dest/l1/calldata_retriever.d.ts +135 -0
  24. package/dest/l1/calldata_retriever.d.ts.map +1 -0
  25. package/dest/l1/calldata_retriever.js +402 -0
  26. package/dest/l1/data_retrieval.d.ts +88 -0
  27. package/dest/l1/data_retrieval.d.ts.map +1 -0
  28. package/dest/{archiver → l1}/data_retrieval.js +83 -155
  29. package/dest/l1/debug_tx.d.ts +19 -0
  30. package/dest/l1/debug_tx.d.ts.map +1 -0
  31. package/dest/l1/debug_tx.js +73 -0
  32. package/dest/l1/spire_proposer.d.ts +70 -0
  33. package/dest/l1/spire_proposer.d.ts.map +1 -0
  34. package/dest/l1/spire_proposer.js +149 -0
  35. package/dest/l1/trace_tx.d.ts +97 -0
  36. package/dest/l1/trace_tx.d.ts.map +1 -0
  37. package/dest/l1/trace_tx.js +91 -0
  38. package/dest/l1/types.d.ts +12 -0
  39. package/dest/l1/types.d.ts.map +1 -0
  40. package/dest/l1/types.js +3 -0
  41. package/dest/l1/validate_trace.d.ts +32 -0
  42. package/dest/l1/validate_trace.d.ts.map +1 -0
  43. package/dest/l1/validate_trace.js +154 -0
  44. package/dest/modules/data_source_base.d.ts +89 -0
  45. package/dest/modules/data_source_base.d.ts.map +1 -0
  46. package/dest/modules/data_source_base.js +216 -0
  47. package/dest/modules/data_store_updater.d.ts +85 -0
  48. package/dest/modules/data_store_updater.d.ts.map +1 -0
  49. package/dest/modules/data_store_updater.js +324 -0
  50. package/dest/modules/instrumentation.d.ts +50 -0
  51. package/dest/modules/instrumentation.d.ts.map +1 -0
  52. package/dest/{archiver → modules}/instrumentation.js +49 -62
  53. package/dest/modules/l1_synchronizer.d.ts +72 -0
  54. package/dest/modules/l1_synchronizer.d.ts.map +1 -0
  55. package/dest/modules/l1_synchronizer.js +1147 -0
  56. package/dest/modules/validation.d.ts +17 -0
  57. package/dest/modules/validation.d.ts.map +1 -0
  58. package/dest/{archiver → modules}/validation.js +7 -1
  59. package/dest/store/block_store.d.ts +195 -0
  60. package/dest/store/block_store.d.ts.map +1 -0
  61. package/dest/store/block_store.js +773 -0
  62. package/dest/store/contract_class_store.d.ts +17 -0
  63. package/dest/store/contract_class_store.d.ts.map +1 -0
  64. package/dest/store/contract_class_store.js +64 -0
  65. package/dest/store/contract_instance_store.d.ts +24 -0
  66. package/dest/store/contract_instance_store.d.ts.map +1 -0
  67. package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +7 -3
  68. package/dest/store/kv_archiver_store.d.ts +364 -0
  69. package/dest/store/kv_archiver_store.d.ts.map +1 -0
  70. package/dest/store/kv_archiver_store.js +477 -0
  71. package/dest/store/l2_tips_cache.d.ts +19 -0
  72. package/dest/store/l2_tips_cache.d.ts.map +1 -0
  73. package/dest/store/l2_tips_cache.js +89 -0
  74. package/dest/store/log_store.d.ts +57 -0
  75. package/dest/store/log_store.d.ts.map +1 -0
  76. package/dest/store/log_store.js +533 -0
  77. package/dest/store/message_store.d.ts +44 -0
  78. package/dest/store/message_store.d.ts.map +1 -0
  79. package/dest/{archiver/kv_archiver_store → store}/message_store.js +29 -15
  80. package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
  81. package/dest/structs/data_retrieval.d.ts.map +1 -0
  82. package/dest/structs/inbox_message.d.ts +15 -0
  83. package/dest/structs/inbox_message.d.ts.map +1 -0
  84. package/dest/{archiver/structs → structs}/inbox_message.js +6 -5
  85. package/dest/structs/published.d.ts +2 -0
  86. package/dest/structs/published.d.ts.map +1 -0
  87. package/dest/test/fake_l1_state.d.ts +202 -0
  88. package/dest/test/fake_l1_state.d.ts.map +1 -0
  89. package/dest/test/fake_l1_state.js +455 -0
  90. package/dest/test/index.d.ts +2 -1
  91. package/dest/test/index.d.ts.map +1 -1
  92. package/dest/test/index.js +4 -1
  93. package/dest/test/mock_archiver.d.ts +16 -8
  94. package/dest/test/mock_archiver.d.ts.map +1 -1
  95. package/dest/test/mock_archiver.js +19 -14
  96. package/dest/test/mock_l1_to_l2_message_source.d.ts +7 -6
  97. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  98. package/dest/test/mock_l1_to_l2_message_source.js +21 -11
  99. package/dest/test/mock_l2_block_source.d.ts +54 -20
  100. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  101. package/dest/test/mock_l2_block_source.js +251 -85
  102. package/dest/test/mock_structs.d.ts +83 -4
  103. package/dest/test/mock_structs.d.ts.map +1 -1
  104. package/dest/test/mock_structs.js +157 -11
  105. package/dest/test/noop_l1_archiver.d.ts +26 -0
  106. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  107. package/dest/test/noop_l1_archiver.js +72 -0
  108. package/package.json +20 -20
  109. package/src/archiver.ts +500 -0
  110. package/src/{archiver/config.ts → config.ts} +36 -13
  111. package/src/errors.ts +118 -0
  112. package/src/factory.ts +154 -17
  113. package/src/index.ts +11 -3
  114. package/src/interfaces.ts +9 -0
  115. package/src/l1/README.md +55 -0
  116. package/src/l1/bin/retrieve-calldata.ts +194 -0
  117. package/src/l1/calldata_retriever.ts +511 -0
  118. package/src/{archiver → l1}/data_retrieval.ts +143 -226
  119. package/src/l1/debug_tx.ts +99 -0
  120. package/src/l1/spire_proposer.ts +152 -0
  121. package/src/l1/trace_tx.ts +128 -0
  122. package/src/l1/types.ts +13 -0
  123. package/src/l1/validate_trace.ts +229 -0
  124. package/src/modules/data_source_base.ts +333 -0
  125. package/src/modules/data_store_updater.ts +424 -0
  126. package/src/{archiver → modules}/instrumentation.ts +63 -66
  127. package/src/modules/l1_synchronizer.ts +967 -0
  128. package/src/{archiver → modules}/validation.ts +11 -6
  129. package/src/store/block_store.ts +1018 -0
  130. package/src/store/contract_class_store.ts +82 -0
  131. package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +10 -7
  132. package/src/store/kv_archiver_store.ts +682 -0
  133. package/src/store/l2_tips_cache.ts +89 -0
  134. package/src/store/log_store.ts +736 -0
  135. package/src/{archiver/kv_archiver_store → store}/message_store.ts +41 -19
  136. package/src/{archiver/structs → structs}/inbox_message.ts +8 -8
  137. package/src/{archiver/structs → structs}/published.ts +0 -1
  138. package/src/test/fake_l1_state.ts +698 -0
  139. package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
  140. package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
  141. package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
  142. package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
  143. package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
  144. package/src/test/fixtures/trace_transaction-proxied.json +128 -0
  145. package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
  146. package/src/test/index.ts +4 -0
  147. package/src/test/mock_archiver.ts +23 -16
  148. package/src/test/mock_l1_to_l2_message_source.ts +18 -11
  149. package/src/test/mock_l2_block_source.ts +311 -93
  150. package/src/test/mock_structs.ts +289 -13
  151. package/src/test/noop_l1_archiver.ts +115 -0
  152. package/dest/archiver/archiver.d.ts +0 -287
  153. package/dest/archiver/archiver.d.ts.map +0 -1
  154. package/dest/archiver/archiver.js +0 -1408
  155. package/dest/archiver/archiver_store.d.ts +0 -255
  156. package/dest/archiver/archiver_store.d.ts.map +0 -1
  157. package/dest/archiver/archiver_store.js +0 -4
  158. package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
  159. package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
  160. package/dest/archiver/archiver_store_test_suite.js +0 -1289
  161. package/dest/archiver/config.d.ts +0 -21
  162. package/dest/archiver/config.d.ts.map +0 -1
  163. package/dest/archiver/data_retrieval.d.ts +0 -79
  164. package/dest/archiver/data_retrieval.d.ts.map +0 -1
  165. package/dest/archiver/errors.d.ts +0 -12
  166. package/dest/archiver/errors.d.ts.map +0 -1
  167. package/dest/archiver/errors.js +0 -17
  168. package/dest/archiver/index.d.ts +0 -7
  169. package/dest/archiver/index.d.ts.map +0 -1
  170. package/dest/archiver/index.js +0 -4
  171. package/dest/archiver/instrumentation.d.ts +0 -35
  172. package/dest/archiver/instrumentation.d.ts.map +0 -1
  173. package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -124
  174. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
  175. package/dest/archiver/kv_archiver_store/block_store.js +0 -370
  176. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
  177. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
  178. package/dest/archiver/kv_archiver_store/contract_class_store.js +0 -120
  179. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
  180. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
  181. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -168
  182. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
  183. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -296
  184. package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -49
  185. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
  186. package/dest/archiver/kv_archiver_store/log_store.js +0 -336
  187. package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -39
  188. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
  189. package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
  190. package/dest/archiver/structs/inbox_message.d.ts +0 -15
  191. package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
  192. package/dest/archiver/structs/published.d.ts +0 -3
  193. package/dest/archiver/structs/published.d.ts.map +0 -1
  194. package/dest/archiver/validation.d.ts +0 -17
  195. package/dest/archiver/validation.d.ts.map +0 -1
  196. package/dest/rpc/index.d.ts +0 -9
  197. package/dest/rpc/index.d.ts.map +0 -1
  198. package/dest/rpc/index.js +0 -15
  199. package/src/archiver/archiver.ts +0 -1858
  200. package/src/archiver/archiver_store.ts +0 -305
  201. package/src/archiver/archiver_store_test_suite.ts +0 -1264
  202. package/src/archiver/errors.ts +0 -26
  203. package/src/archiver/index.ts +0 -6
  204. package/src/archiver/kv_archiver_store/block_store.ts +0 -481
  205. package/src/archiver/kv_archiver_store/contract_class_store.ts +0 -176
  206. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -422
  207. package/src/archiver/kv_archiver_store/log_store.ts +0 -406
  208. package/src/rpc/index.ts +0 -16
  209. /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
  210. /package/dest/{archiver/structs → structs}/published.js +0 -0
  211. /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
@@ -0,0 +1,324 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { filterAsync } from '@aztec/foundation/collection';
3
+ import { createLogger } from '@aztec/foundation/log';
4
+ import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
5
+ import { ContractInstancePublishedEvent, ContractInstanceUpdatedEvent } from '@aztec/protocol-contracts/instance-registry';
6
+ import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
7
+ import { computeContractAddressFromInstance, computeContractClassId } from '@aztec/stdlib/contract';
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
+ l2TipsCache;
16
+ opts;
17
+ log;
18
+ constructor(store, l2TipsCache, opts = {}){
19
+ this.store = store;
20
+ this.l2TipsCache = l2TipsCache;
21
+ this.opts = opts;
22
+ this.log = createLogger('archiver:store_updater');
23
+ }
24
+ /**
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.
28
+ *
29
+ * @param block - The proposed L2 block to add.
30
+ * @param pendingChainValidationStatus - Optional validation status to set.
31
+ * @returns True if the operation is successful.
32
+ */ async addProposedBlock(block, pendingChainValidationStatus) {
33
+ const result = await this.store.transactionAsync(async ()=>{
34
+ await this.store.addProposedBlock(block);
35
+ const opResults = await Promise.all([
36
+ // Update the pending chain validation status if provided
37
+ pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
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)
44
+ ]);
45
+ await this.l2TipsCache?.refresh();
46
+ return opResults.every(Boolean);
47
+ });
48
+ return result;
49
+ }
50
+ /**
51
+ * Reconciles local blocks with incoming checkpoints from L1.
52
+ * Adds new checkpoints to the store with contract class/instance extraction from logs.
53
+ * Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
54
+ * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the checkpoint block logs.
55
+ *
56
+ * @param checkpoints - The published checkpoints to add.
57
+ * @param pendingChainValidationStatus - Optional validation status to set.
58
+ * @returns Result with information about any pruned blocks.
59
+ */ async addCheckpoints(checkpoints, pendingChainValidationStatus) {
60
+ for (const checkpoint of checkpoints){
61
+ validateCheckpoint(checkpoint.checkpoint, {
62
+ rollupManaLimit: this.opts?.rollupManaLimit
63
+ });
64
+ }
65
+ const result = await this.store.transactionAsync(async ()=>{
66
+ // Before adding checkpoints, check for conflicts with local blocks if any
67
+ const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
68
+ await this.store.addCheckpoints(checkpoints);
69
+ // Filter out blocks that were already inserted via addProposedBlock() to avoid duplicating logs/contract data
70
+ const newBlocks = checkpoints.flatMap((ch)=>ch.checkpoint.blocks).filter((b)=>lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
71
+ await Promise.all([
72
+ // Update the pending chain validation status if provided
73
+ pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
74
+ // Add any logs emitted during the retrieved blocks
75
+ this.store.addLogs(newBlocks),
76
+ // Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
77
+ ...newBlocks.map((block)=>this.addContractDataToDb(block))
78
+ ]);
79
+ await this.l2TipsCache?.refresh();
80
+ return {
81
+ prunedBlocks,
82
+ lastAlreadyInsertedBlockNumber
83
+ };
84
+ });
85
+ return result;
86
+ }
87
+ /**
88
+ * Checks for local proposed blocks that do not match the ones to be checkpointed and prunes them.
89
+ * This method handles multiple checkpoints but returns after pruning the first conflict found.
90
+ * This is correct because pruning from the first conflict point removes all subsequent blocks,
91
+ * and when checkpoints are added afterward, they include all the correct blocks.
92
+ */ async pruneMismatchingLocalBlocks(checkpoints) {
93
+ const [lastCheckpointedBlockNumber, lastBlockNumber] = await Promise.all([
94
+ this.store.getCheckpointedL2BlockNumber(),
95
+ this.store.getLatestBlockNumber()
96
+ ]);
97
+ // Exit early if there are no local uncheckpointed blocks
98
+ if (lastBlockNumber === lastCheckpointedBlockNumber) {
99
+ return {
100
+ prunedBlocks: undefined,
101
+ lastAlreadyInsertedBlockNumber: undefined
102
+ };
103
+ }
104
+ // Get all uncheckpointed local blocks
105
+ const uncheckpointedLocalBlocks = await this.store.getBlocks(BlockNumber.add(lastCheckpointedBlockNumber, 1), lastBlockNumber - lastCheckpointedBlockNumber);
106
+ let lastAlreadyInsertedBlockNumber;
107
+ for (const publishedCheckpoint of checkpoints){
108
+ const checkpointBlocks = publishedCheckpoint.checkpoint.blocks;
109
+ const slot = publishedCheckpoint.checkpoint.slot;
110
+ const localBlocksInSlot = uncheckpointedLocalBlocks.filter((b)=>b.slot === slot);
111
+ if (checkpointBlocks.length === 0) {
112
+ this.log.warn(`Checkpoint ${publishedCheckpoint.checkpoint.number} for slot ${slot} has no blocks`);
113
+ continue;
114
+ }
115
+ // Find the first checkpoint block that conflicts with an existing local block and prune local afterwards
116
+ for (const checkpointBlock of checkpointBlocks){
117
+ const blockNumber = checkpointBlock.number;
118
+ const existingBlock = localBlocksInSlot.find((b)=>b.number === blockNumber);
119
+ const blockInfos = {
120
+ existingBlock: existingBlock?.toBlockInfo(),
121
+ checkpointBlock: checkpointBlock.toBlockInfo()
122
+ };
123
+ if (!existingBlock) {
124
+ this.log.verbose(`No local block found for checkpointed block number ${blockNumber}`, blockInfos);
125
+ } else if (existingBlock.archive.root.equals(checkpointBlock.archive.root)) {
126
+ this.log.verbose(`Block number ${blockNumber} already inserted and matches checkpoint`, blockInfos);
127
+ lastAlreadyInsertedBlockNumber = blockNumber;
128
+ } else {
129
+ this.log.info(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
130
+ const prunedBlocks = await this.removeBlocksAfter(BlockNumber(blockNumber - 1));
131
+ return {
132
+ prunedBlocks,
133
+ lastAlreadyInsertedBlockNumber
134
+ };
135
+ }
136
+ }
137
+ // If local has more blocks than the checkpoint (e.g., local has [2,3,4] but checkpoint has [2,3]),
138
+ // we need to prune the extra local blocks so they match what was checkpointed
139
+ const lastCheckpointBlockNumber = checkpointBlocks.at(-1).number;
140
+ const lastLocalBlockNumber = localBlocksInSlot.at(-1)?.number;
141
+ if (lastLocalBlockNumber !== undefined && lastLocalBlockNumber > lastCheckpointBlockNumber) {
142
+ this.log.warn(`Local chain for slot ${slot} ends at block ${lastLocalBlockNumber} but checkpoint ends at ${lastCheckpointBlockNumber}. Pruning blocks after block ${lastCheckpointBlockNumber}.`);
143
+ const prunedBlocks = await this.removeBlocksAfter(lastCheckpointBlockNumber);
144
+ return {
145
+ prunedBlocks,
146
+ lastAlreadyInsertedBlockNumber
147
+ };
148
+ }
149
+ }
150
+ return {
151
+ prunedBlocks: undefined,
152
+ lastAlreadyInsertedBlockNumber
153
+ };
154
+ }
155
+ /**
156
+ * Removes all uncheckpointed blocks strictly after the specified block number and cleans up associated contract data.
157
+ * This handles removal of provisionally added blocks along with their contract classes/instances.
158
+ * Verifies that each block being removed is not part of a stored checkpoint.
159
+ *
160
+ * @param blockNumber - Remove all blocks with number greater than this.
161
+ * @returns The removed blocks.
162
+ * @throws Error if any block to be removed is checkpointed.
163
+ */ async removeUncheckpointedBlocksAfter(blockNumber) {
164
+ const result = await this.store.transactionAsync(async ()=>{
165
+ // Verify we're only removing uncheckpointed blocks
166
+ const lastCheckpointedBlockNumber = await this.store.getCheckpointedL2BlockNumber();
167
+ if (blockNumber < lastCheckpointedBlockNumber) {
168
+ throw new Error(`Cannot remove blocks after ${blockNumber} because checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`);
169
+ }
170
+ const result = await this.removeBlocksAfter(blockNumber);
171
+ await this.l2TipsCache?.refresh();
172
+ return result;
173
+ });
174
+ return result;
175
+ }
176
+ /**
177
+ * Removes all blocks strictly after the given block number along with any logs and contract data.
178
+ * Does not remove their checkpoints.
179
+ */ async removeBlocksAfter(blockNumber) {
180
+ // First get the blocks to be removed so we can clean up contract data
181
+ const removedBlocks = await this.store.removeBlocksAfter(blockNumber);
182
+ // Clean up contract data and logs for the removed blocks
183
+ await Promise.all([
184
+ this.store.deleteLogs(removedBlocks),
185
+ ...removedBlocks.map((block)=>this.removeContractDataFromDb(block))
186
+ ]);
187
+ return removedBlocks;
188
+ }
189
+ /**
190
+ * Removes all checkpoints after the given checkpoint number.
191
+ * Deletes ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated data
192
+ * that was stored for the removed checkpoints. Also removes ALL blocks (both checkpointed
193
+ * and uncheckpointed) after the last block of the given checkpoint.
194
+ *
195
+ * @param checkpointNumber - Remove all checkpoints strictly after this one.
196
+ * @returns True if the operation is successful.
197
+ */ async removeCheckpointsAfter(checkpointNumber) {
198
+ return await this.store.transactionAsync(async ()=>{
199
+ const { blocksRemoved = [] } = await this.store.removeCheckpointsAfter(checkpointNumber);
200
+ const opResults = await Promise.all([
201
+ // Prune rolls back to the last proven block, which is by definition valid
202
+ this.store.setPendingChainValidationStatus({
203
+ valid: true
204
+ }),
205
+ // Remove contract data for all blocks being removed
206
+ ...blocksRemoved.map((block)=>this.removeContractDataFromDb(block)),
207
+ this.store.deleteLogs(blocksRemoved)
208
+ ]);
209
+ await this.l2TipsCache?.refresh();
210
+ return opResults.every(Boolean);
211
+ });
212
+ }
213
+ /**
214
+ * Updates the proven checkpoint number and refreshes the L2 tips cache.
215
+ * @param checkpointNumber - The checkpoint number to set as proven.
216
+ */ async setProvenCheckpointNumber(checkpointNumber) {
217
+ await this.store.transactionAsync(async ()=>{
218
+ await this.store.setProvenCheckpointNumber(checkpointNumber);
219
+ await this.l2TipsCache?.refresh();
220
+ });
221
+ }
222
+ /**
223
+ * Updates the finalized checkpoint number and refreshes the L2 tips cache.
224
+ * @param checkpointNumber - The checkpoint number to set as finalized.
225
+ */ async setFinalizedCheckpointNumber(checkpointNumber) {
226
+ await this.store.transactionAsync(async ()=>{
227
+ await this.store.setFinalizedCheckpointNumber(checkpointNumber);
228
+ await this.l2TipsCache?.refresh();
229
+ });
230
+ }
231
+ /** Extracts and stores contract data from a single block. */ addContractDataToDb(block) {
232
+ return this.updateContractDataOnDb(block, 0);
233
+ }
234
+ /** Removes contract data associated with a block. */ removeContractDataFromDb(block) {
235
+ return this.updateContractDataOnDb(block, 1);
236
+ }
237
+ /** Adds or remove contract data associated with a block. */ async updateContractDataOnDb(block, operation) {
238
+ const contractClassLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.contractClassLogs);
239
+ const privateLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.privateLogs);
240
+ const publicLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.publicLogs);
241
+ return (await Promise.all([
242
+ this.updatePublishedContractClasses(contractClassLogs, block.number, operation),
243
+ this.updateDeployedContractInstances(privateLogs, block.number, operation),
244
+ this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation)
245
+ ])).every(Boolean);
246
+ }
247
+ /**
248
+ * Extracts and stores contract classes out of ContractClassPublished events emitted by the class registry contract.
249
+ */ async updatePublishedContractClasses(allLogs, blockNum, operation) {
250
+ const contractClassPublishedEvents = allLogs.filter((log)=>ContractClassPublishedEvent.isContractClassPublishedEvent(log)).map((log)=>ContractClassPublishedEvent.fromLog(log));
251
+ if (operation == 1) {
252
+ const contractClasses = contractClassPublishedEvents.map((e)=>e.toContractClassPublic());
253
+ if (contractClasses.length > 0) {
254
+ contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
255
+ return await this.store.deleteContractClasses(contractClasses, blockNum);
256
+ }
257
+ return true;
258
+ }
259
+ // Compute bytecode commitments and validate class IDs in a single pass.
260
+ const contractClasses = [];
261
+ for (const event of contractClassPublishedEvents){
262
+ const contractClass = await event.toContractClassPublicWithBytecodeCommitment();
263
+ const computedClassId = await computeContractClassId({
264
+ artifactHash: contractClass.artifactHash,
265
+ privateFunctionsRoot: contractClass.privateFunctionsRoot,
266
+ publicBytecodeCommitment: contractClass.publicBytecodeCommitment
267
+ });
268
+ if (!computedClassId.equals(contractClass.id)) {
269
+ this.log.warn(`Skipping contract class with mismatched id at block ${blockNum}. Claimed ${contractClass.id}, computed ${computedClassId}`, {
270
+ blockNum,
271
+ contractClassId: event.contractClassId.toString()
272
+ });
273
+ continue;
274
+ }
275
+ contractClasses.push(contractClass);
276
+ }
277
+ if (contractClasses.length > 0) {
278
+ contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
279
+ return await this.store.addContractClasses(contractClasses, blockNum);
280
+ }
281
+ return true;
282
+ }
283
+ /**
284
+ * Extracts and stores contract instances out of ContractInstancePublished events emitted by the canonical deployer contract.
285
+ */ async updateDeployedContractInstances(allLogs, blockNum, operation) {
286
+ const allInstances = allLogs.filter((log)=>ContractInstancePublishedEvent.isContractInstancePublishedEvent(log)).map((log)=>ContractInstancePublishedEvent.fromLog(log)).map((e)=>e.toContractInstance());
287
+ // Verify that each instance's address matches the one derived from its fields if we're adding
288
+ const contractInstances = operation === 1 ? allInstances : await filterAsync(allInstances, async (instance)=>{
289
+ const computedAddress = await computeContractAddressFromInstance(instance);
290
+ if (!computedAddress.equals(instance.address)) {
291
+ this.log.warn(`Found contract instance with mismatched address at block ${blockNum}. Claimed ${instance.address} but computed ${computedAddress}.`, {
292
+ instanceAddress: instance.address.toString(),
293
+ computedAddress: computedAddress.toString(),
294
+ blockNum
295
+ });
296
+ return false;
297
+ }
298
+ return true;
299
+ });
300
+ if (contractInstances.length > 0) {
301
+ contractInstances.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance at ${c.address.toString()}`));
302
+ if (operation == 0) {
303
+ return await this.store.addContractInstances(contractInstances, blockNum);
304
+ } else if (operation == 1) {
305
+ return await this.store.deleteContractInstances(contractInstances, blockNum);
306
+ }
307
+ }
308
+ return true;
309
+ }
310
+ /**
311
+ * Extracts and stores contract instance updates out of ContractInstanceUpdated events.
312
+ */ async updateUpdatedContractInstances(allLogs, timestamp, operation) {
313
+ const contractUpdates = allLogs.filter((log)=>ContractInstanceUpdatedEvent.isContractInstanceUpdatedEvent(log)).map((log)=>ContractInstanceUpdatedEvent.fromLog(log)).map((e)=>e.toContractInstanceUpdate());
314
+ if (contractUpdates.length > 0) {
315
+ contractUpdates.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance update at ${c.address.toString()}`));
316
+ if (operation == 0) {
317
+ return await this.store.addContractInstanceUpdates(contractUpdates, timestamp);
318
+ } else if (operation == 1) {
319
+ return await this.store.deleteContractInstanceUpdates(contractUpdates, timestamp);
320
+ }
321
+ }
322
+ return true;
323
+ }
324
+ }
@@ -0,0 +1,50 @@
1
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
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';
5
+ import { type LmdbStatsCallback, type TelemetryClient, type Tracer } from '@aztec/telemetry-client';
6
+ export declare class ArchiverInstrumentation {
7
+ private telemetry;
8
+ readonly tracer: Tracer;
9
+ private blockHeight;
10
+ private checkpointHeight;
11
+ private txCount;
12
+ private l1BlockHeight;
13
+ private proofsSubmittedDelay;
14
+ private proofsSubmittedCount;
15
+ private dbMetrics;
16
+ private pruneDuration;
17
+ private pruneCount;
18
+ private syncDurationPerBlock;
19
+ private syncBlockCount;
20
+ private manaPerBlock;
21
+ private txsPerBlock;
22
+ private syncDurationPerMessage;
23
+ private syncMessageCount;
24
+ private blockProposalTxTargetCount;
25
+ private checkpointL1InclusionDelay;
26
+ private log;
27
+ private constructor();
28
+ static new(telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback): Promise<ArchiverInstrumentation>;
29
+ isEnabled(): boolean;
30
+ processNewBlocks(syncTimePerBlock: number, blocks: L2Block[]): void;
31
+ processNewMessages(count: number, syncPerMessageMs: number): void;
32
+ processPrune(duration: number): void;
33
+ updateLastProvenCheckpoint(checkpoint: CheckpointData): void;
34
+ processProofsVerified(logs: {
35
+ proverId: string;
36
+ l2BlockNumber: bigint;
37
+ delay: bigint;
38
+ }[]): void;
39
+ updateL1BlockHeight(blockNumber: bigint): void;
40
+ recordBlockProposalTxTarget(target: string, usedTrace: boolean): void;
41
+ /**
42
+ * Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
43
+ */
44
+ processCheckpointL1Timing(data: {
45
+ slotNumber: SlotNumber;
46
+ l1Timestamp: bigint;
47
+ l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>;
48
+ }): void;
49
+ }
50
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5zdHJ1bWVudGF0aW9uLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbW9kdWxlcy9pbnN0cnVtZW50YXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFFbEUsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDbkQsT0FBTyxLQUFLLEVBQUUsY0FBYyxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDL0QsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUVyRSxPQUFPLEVBS0wsS0FBSyxpQkFBaUIsRUFFdEIsS0FBSyxlQUFlLEVBQ3BCLEtBQUssTUFBTSxFQUdaLE1BQU0seUJBQXlCLENBQUM7QUFFakMscUJBQWEsdUJBQXVCO0lBNkJoQyxPQUFPLENBQUMsU0FBUztJQTVCbkIsU0FBZ0IsTUFBTSxFQUFFLE1BQU0sQ0FBQztJQUUvQixPQUFPLENBQUMsV0FBVyxDQUFRO0lBQzNCLE9BQU8sQ0FBQyxnQ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,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 { Attributes, LmdbMetrics, Metrics, ValueType } from '@aztec/telemetry-client';
2
+ import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
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;
@@ -17,79 +19,46 @@ export class ArchiverInstrumentation {
17
19
  txsPerBlock;
18
20
  syncDurationPerMessage;
19
21
  syncMessageCount;
22
+ blockProposalTxTargetCount;
23
+ checkpointL1InclusionDelay;
20
24
  log;
21
25
  constructor(telemetry, lmdbStats){
22
26
  this.telemetry = telemetry;
23
27
  this.log = createLogger('archiver:instrumentation');
24
28
  this.tracer = telemetry.getTracer('Archiver');
25
29
  const meter = telemetry.getMeter('Archiver');
26
- this.blockHeight = meter.createGauge(Metrics.ARCHIVER_BLOCK_HEIGHT, {
27
- description: 'The height of the latest block processed by the archiver',
28
- valueType: ValueType.INT
30
+ this.blockHeight = meter.createGauge(Metrics.ARCHIVER_BLOCK_HEIGHT);
31
+ this.checkpointHeight = meter.createGauge(Metrics.ARCHIVER_CHECKPOINT_HEIGHT);
32
+ this.l1BlockHeight = meter.createGauge(Metrics.ARCHIVER_L1_BLOCK_HEIGHT);
33
+ this.txCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_TOTAL_TXS);
34
+ this.proofsSubmittedCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_ROLLUP_PROOF_COUNT, {
35
+ [Attributes.PROOF_TIMED_OUT]: [
36
+ true,
37
+ false
38
+ ]
29
39
  });
30
- this.l1BlockHeight = meter.createGauge(Metrics.ARCHIVER_L1_BLOCK_HEIGHT, {
31
- description: 'The height of the latest L1 block processed by the archiver',
32
- valueType: ValueType.INT
33
- });
34
- this.txCount = meter.createUpDownCounter(Metrics.ARCHIVER_TOTAL_TXS, {
35
- description: 'The total number of transactions',
36
- valueType: ValueType.INT
37
- });
38
- this.proofsSubmittedCount = meter.createUpDownCounter(Metrics.ARCHIVER_ROLLUP_PROOF_COUNT, {
39
- description: 'Number of proofs submitted',
40
- valueType: ValueType.INT
41
- });
42
- this.proofsSubmittedDelay = meter.createHistogram(Metrics.ARCHIVER_ROLLUP_PROOF_DELAY, {
43
- unit: 'ms',
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
40
+ this.proofsSubmittedDelay = meter.createHistogram(Metrics.ARCHIVER_ROLLUP_PROOF_DELAY);
41
+ this.syncDurationPerBlock = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_BLOCK);
42
+ this.syncBlockCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_BLOCK_COUNT);
43
+ this.manaPerBlock = meter.createHistogram(Metrics.ARCHIVER_MANA_PER_BLOCK);
44
+ this.txsPerBlock = meter.createHistogram(Metrics.ARCHIVER_TXS_PER_BLOCK);
45
+ this.syncDurationPerMessage = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_MESSAGE);
46
+ this.syncMessageCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_MESSAGE_COUNT);
47
+ this.pruneDuration = meter.createHistogram(Metrics.ARCHIVER_PRUNE_DURATION);
48
+ this.pruneCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_PRUNE_COUNT);
49
+ this.blockProposalTxTargetCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_BLOCK_PROPOSAL_TX_TARGET_COUNT, {
50
+ [Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: [
51
+ true,
52
+ false
53
+ ]
83
54
  });
55
+ this.checkpointL1InclusionDelay = meter.createHistogram(Metrics.ARCHIVER_CHECKPOINT_L1_INCLUSION_DELAY);
84
56
  this.dbMetrics = new LmdbMetrics(meter, {
85
57
  [Attributes.DB_DATA_TYPE]: 'archiver'
86
58
  }, lmdbStats);
87
59
  }
88
60
  static async new(telemetry, lmdbStats) {
89
61
  const instance = new ArchiverInstrumentation(telemetry, lmdbStats);
90
- instance.syncBlockCount.add(0);
91
- instance.syncMessageCount.add(0);
92
- instance.pruneCount.add(0);
93
62
  await instance.telemetry.flush();
94
63
  return instance;
95
64
  }
@@ -99,6 +68,7 @@ export class ArchiverInstrumentation {
99
68
  processNewBlocks(syncTimePerBlock, blocks) {
100
69
  this.syncDurationPerBlock.record(Math.ceil(syncTimePerBlock));
101
70
  this.blockHeight.record(Math.max(...blocks.map((b)=>b.number)));
71
+ this.checkpointHeight.record(Math.max(...blocks.map((b)=>b.checkpointNumber)));
102
72
  this.syncBlockCount.add(blocks.length);
103
73
  for (const block of blocks){
104
74
  this.txCount.add(block.body.txEffects.length);
@@ -117,8 +87,12 @@ export class ArchiverInstrumentation {
117
87
  this.pruneCount.add(1);
118
88
  this.pruneDuration.record(Math.ceil(duration));
119
89
  }
120
- updateLastProvenBlock(blockNumber) {
121
- this.blockHeight.record(blockNumber, {
90
+ updateLastProvenCheckpoint(checkpoint) {
91
+ const lastBlockNumberInCheckpoint = checkpoint.startBlock + checkpoint.blockCount - 1;
92
+ this.blockHeight.record(lastBlockNumberInCheckpoint, {
93
+ [Attributes.STATUS]: 'proven'
94
+ });
95
+ this.checkpointHeight.record(checkpoint.checkpointNumber, {
122
96
  [Attributes.STATUS]: 'proven'
123
97
  });
124
98
  }
@@ -137,4 +111,17 @@ export class ArchiverInstrumentation {
137
111
  updateL1BlockHeight(blockNumber) {
138
112
  this.l1BlockHeight.record(Number(blockNumber));
139
113
  }
114
+ recordBlockProposalTxTarget(target, usedTrace) {
115
+ this.blockProposalTxTargetCount.add(1, {
116
+ [Attributes.L1_BLOCK_PROPOSAL_TX_TARGET]: target.toLowerCase(),
117
+ [Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: usedTrace
118
+ });
119
+ }
120
+ /**
121
+ * Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
122
+ */ processCheckpointL1Timing(data) {
123
+ const slotStartTs = getTimestampForSlot(data.slotNumber, data.l1Constants);
124
+ const inclusionDelaySeconds = Number(data.l1Timestamp - slotStartTs);
125
+ this.checkpointL1InclusionDelay.record(inclusionDelaySeconds);
126
+ }
140
127
  }
@@ -0,0 +1,72 @@
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 { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
5
+ import { Buffer32 } from '@aztec/foundation/buffer';
6
+ import { Fr } from '@aztec/foundation/curves/bn254';
7
+ import { type Logger } from '@aztec/foundation/log';
8
+ import { DateProvider } from '@aztec/foundation/timer';
9
+ import { type ArchiverEmitter } from '@aztec/stdlib/block';
10
+ import { type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
11
+ import { type Traceable, type Tracer } from '@aztec/telemetry-client';
12
+ import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
13
+ import type { L2TipsCache } from '../store/l2_tips_cache.js';
14
+ import type { ArchiverInstrumentation } from './instrumentation.js';
15
+ /**
16
+ * Handles L1 synchronization for the archiver.
17
+ * Responsible for fetching checkpoints, L1→L2 messages, and handling L1 reorgs.
18
+ */
19
+ export declare class ArchiverL1Synchronizer implements Traceable {
20
+ private readonly publicClient;
21
+ private readonly debugClient;
22
+ private readonly rollup;
23
+ private readonly inbox;
24
+ private readonly store;
25
+ private config;
26
+ private readonly blobClient;
27
+ private readonly epochCache;
28
+ private readonly dateProvider;
29
+ private readonly instrumentation;
30
+ private readonly l1Constants;
31
+ private readonly events;
32
+ private readonly log;
33
+ private l1BlockNumber;
34
+ private l1BlockHash;
35
+ private l1Timestamp;
36
+ private readonly updater;
37
+ readonly tracer: Tracer;
38
+ constructor(publicClient: ViemPublicClient, debugClient: ViemPublicDebugClient, rollup: RollupContract, inbox: InboxContract, store: KVArchiverDataStore, config: {
39
+ batchSize: number;
40
+ skipValidateCheckpointAttestations?: boolean;
41
+ maxAllowedEthClientDriftSeconds: number;
42
+ }, blobClient: BlobClientInterface, epochCache: EpochCache, dateProvider: DateProvider, instrumentation: ArchiverInstrumentation, l1Constants: L1RollupConstants & {
43
+ l1StartBlockHash: Buffer32;
44
+ genesisArchiveRoot: Fr;
45
+ }, events: ArchiverEmitter, tracer: Tracer, l2TipsCache?: L2TipsCache, log?: Logger);
46
+ /** Sets new config */
47
+ setConfig(newConfig: {
48
+ batchSize: number;
49
+ skipValidateCheckpointAttestations?: boolean;
50
+ maxAllowedEthClientDriftSeconds: number;
51
+ }): void;
52
+ /** Returns the last L1 block number that was synced. */
53
+ getL1BlockNumber(): bigint | undefined;
54
+ /** Returns the last L1 timestamp that was synced. */
55
+ getL1Timestamp(): bigint | undefined;
56
+ /** Checks that the ethereum node we are connected to has a latest timestamp no more than the allowed drift. Throw if not. */
57
+ testEthereumNodeSynced(): Promise<void>;
58
+ syncFromL1(initialSyncComplete: boolean): Promise<void>;
59
+ private updateFinalizedCheckpoint;
60
+ private pruneUncheckpointedBlocks;
61
+ private canPrune;
62
+ private handleEpochPrune;
63
+ private nextRange;
64
+ private handleL1ToL2Messages;
65
+ private retrieveL1ToL2Message;
66
+ private rollbackL1ToL2Messages;
67
+ private getL1BlockHash;
68
+ private handleCheckpoints;
69
+ private checkForNewCheckpointsBeforeL1SyncPoint;
70
+ private getCheckpointHeader;
71
+ }
72
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDFfc3luY2hyb25pemVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbW9kdWxlcy9sMV9zeW5jaHJvbml6ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQUNyRSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDaEQsT0FBTyxFQUFFLGFBQWEsRUFBRSxjQUFjLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQUUxRSxPQUFPLEt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