@aztec/archiver 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c

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