@aztec/archiver 0.0.1-commit.5476d83 → 0.0.1-commit.5914bae

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 +744 -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 +39 -0
  9. package/dest/errors.d.ts.map +1 -0
  10. package/dest/errors.js +57 -0
  11. package/dest/factory.d.ts +7 -6
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +99 -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 +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 +85 -0
  27. package/dest/l1/data_retrieval.d.ts.map +1 -0
  28. package/dest/{archiver → l1}/data_retrieval.js +75 -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 +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 +88 -0
  48. package/dest/modules/data_store_updater.d.ts.map +1 -0
  49. package/dest/modules/data_store_updater.js +375 -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 +72 -0
  54. package/dest/modules/l1_synchronizer.d.ts.map +1 -0
  55. package/dest/modules/l1_synchronizer.js +1142 -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 +818 -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 +17 -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 +7 -3
  68. package/dest/store/kv_archiver_store.d.ts +362 -0
  69. package/dest/store/kv_archiver_store.d.ts.map +1 -0
  70. package/dest/store/kv_archiver_store.js +475 -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 +494 -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 +16 -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 +209 -0
  88. package/dest/test/fake_l1_state.d.ts.map +1 -0
  89. package/dest/test/fake_l1_state.js +460 -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 +501 -0
  110. package/src/{archiver/config.ts → config.ts} +28 -12
  111. package/src/errors.ts +88 -0
  112. package/src/factory.ts +153 -14
  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 +133 -224
  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 +328 -0
  125. package/src/modules/data_store_updater.ts +503 -0
  126. package/src/{archiver → modules}/instrumentation.ts +43 -66
  127. package/src/modules/l1_synchronizer.ts +963 -0
  128. package/src/{archiver → modules}/validation.ts +11 -6
  129. package/src/store/block_store.ts +1075 -0
  130. package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +17 -9
  131. package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +10 -7
  132. package/src/store/kv_archiver_store.ts +685 -0
  133. package/src/store/l2_tips_cache.ts +89 -0
  134. package/src/store/log_store.ts +691 -0
  135. package/src/{archiver/kv_archiver_store → store}/message_store.ts +22 -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 +703 -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_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,375 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { filterAsync } from '@aztec/foundation/collection';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
+ import { createLogger } from '@aztec/foundation/log';
5
+ import { ContractClassPublishedEvent, PrivateFunctionBroadcastedEvent, UtilityFunctionBroadcastedEvent } from '@aztec/protocol-contracts/class-registry';
6
+ import { ContractInstancePublishedEvent, ContractInstanceUpdatedEvent } from '@aztec/protocol-contracts/instance-registry';
7
+ import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
8
+ import { computeContractAddressFromInstance, computeContractClassId, isValidPrivateFunctionMembershipProof, isValidUtilityFunctionMembershipProof } from '@aztec/stdlib/contract';
9
+ import groupBy from 'lodash.groupby';
10
+ /** Operation type for contract data updates. */ var Operation = /*#__PURE__*/ function(Operation) {
11
+ Operation[Operation["Store"] = 0] = "Store";
12
+ Operation[Operation["Delete"] = 1] = "Delete";
13
+ return Operation;
14
+ }(Operation || {});
15
+ /** Archiver helper module to handle updates to the data store. */ export class ArchiverDataStoreUpdater {
16
+ store;
17
+ l2TipsCache;
18
+ opts;
19
+ log;
20
+ constructor(store, l2TipsCache, opts = {}){
21
+ this.store = store;
22
+ this.l2TipsCache = l2TipsCache;
23
+ this.opts = opts;
24
+ this.log = createLogger('archiver:store_updater');
25
+ }
26
+ /**
27
+ * Adds a proposed block to the store with contract class/instance extraction from logs.
28
+ * This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
29
+ * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
30
+ * and individually broadcasted functions from the block logs.
31
+ *
32
+ * @param block - The proposed L2 block to add.
33
+ * @param pendingChainValidationStatus - Optional validation status to set.
34
+ * @returns True if the operation is successful.
35
+ */ async addProposedBlock(block, pendingChainValidationStatus) {
36
+ const result = await this.store.transactionAsync(async ()=>{
37
+ await this.store.addProposedBlock(block);
38
+ const opResults = await Promise.all([
39
+ // Update the pending chain validation status if provided
40
+ pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
41
+ // Add any logs emitted during the retrieved block
42
+ this.store.addLogs([
43
+ block
44
+ ]),
45
+ // Unroll all logs emitted during the retrieved block and extract any contract classes and instances from it
46
+ this.addContractDataToDb(block)
47
+ ]);
48
+ await this.l2TipsCache?.refresh();
49
+ return opResults.every(Boolean);
50
+ });
51
+ return result;
52
+ }
53
+ /**
54
+ * Reconciles local blocks with incoming checkpoints from L1.
55
+ * Adds new checkpoints to the store with contract class/instance extraction from logs.
56
+ * Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
57
+ * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
58
+ * and individually broadcasted functions from the checkpoint block logs.
59
+ *
60
+ * @param checkpoints - The published checkpoints to add.
61
+ * @param pendingChainValidationStatus - Optional validation status to set.
62
+ * @returns Result with information about any pruned blocks.
63
+ */ async addCheckpoints(checkpoints, pendingChainValidationStatus) {
64
+ for (const checkpoint of checkpoints){
65
+ validateCheckpoint(checkpoint.checkpoint, {
66
+ rollupManaLimit: this.opts?.rollupManaLimit
67
+ });
68
+ }
69
+ const result = await this.store.transactionAsync(async ()=>{
70
+ // Before adding checkpoints, check for conflicts with local blocks if any
71
+ const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
72
+ await this.store.addCheckpoints(checkpoints);
73
+ // Filter out blocks that were already inserted via addProposedBlock() to avoid duplicating logs/contract data
74
+ const newBlocks = checkpoints.flatMap((ch)=>ch.checkpoint.blocks).filter((b)=>lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
75
+ await Promise.all([
76
+ // Update the pending chain validation status if provided
77
+ pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
78
+ // Add any logs emitted during the retrieved blocks
79
+ this.store.addLogs(newBlocks),
80
+ // Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
81
+ ...newBlocks.map((block)=>this.addContractDataToDb(block))
82
+ ]);
83
+ await this.l2TipsCache?.refresh();
84
+ return {
85
+ prunedBlocks,
86
+ lastAlreadyInsertedBlockNumber
87
+ };
88
+ });
89
+ return result;
90
+ }
91
+ /**
92
+ * Checks for local proposed blocks that do not match the ones to be checkpointed and prunes them.
93
+ * This method handles multiple checkpoints but returns after pruning the first conflict found.
94
+ * This is correct because pruning from the first conflict point removes all subsequent blocks,
95
+ * and when checkpoints are added afterward, they include all the correct blocks.
96
+ */ async pruneMismatchingLocalBlocks(checkpoints) {
97
+ const [lastCheckpointedBlockNumber, lastBlockNumber] = await Promise.all([
98
+ this.store.getCheckpointedL2BlockNumber(),
99
+ this.store.getLatestBlockNumber()
100
+ ]);
101
+ // Exit early if there are no local uncheckpointed blocks
102
+ if (lastBlockNumber === lastCheckpointedBlockNumber) {
103
+ return {
104
+ prunedBlocks: undefined,
105
+ lastAlreadyInsertedBlockNumber: undefined
106
+ };
107
+ }
108
+ // Get all uncheckpointed local blocks
109
+ const uncheckpointedLocalBlocks = await this.store.getBlocks(BlockNumber.add(lastCheckpointedBlockNumber, 1), lastBlockNumber - lastCheckpointedBlockNumber);
110
+ let lastAlreadyInsertedBlockNumber;
111
+ for (const publishedCheckpoint of checkpoints){
112
+ const checkpointBlocks = publishedCheckpoint.checkpoint.blocks;
113
+ const slot = publishedCheckpoint.checkpoint.slot;
114
+ const localBlocksInSlot = uncheckpointedLocalBlocks.filter((b)=>b.slot === slot);
115
+ if (checkpointBlocks.length === 0) {
116
+ this.log.warn(`Checkpoint ${publishedCheckpoint.checkpoint.number} for slot ${slot} has no blocks`);
117
+ continue;
118
+ }
119
+ // Find the first checkpoint block that conflicts with an existing local block and prune local afterwards
120
+ for (const checkpointBlock of checkpointBlocks){
121
+ const blockNumber = checkpointBlock.number;
122
+ const existingBlock = localBlocksInSlot.find((b)=>b.number === blockNumber);
123
+ const blockInfos = {
124
+ existingBlock: existingBlock?.toBlockInfo(),
125
+ checkpointBlock: checkpointBlock.toBlockInfo()
126
+ };
127
+ if (!existingBlock) {
128
+ this.log.verbose(`No local block found for checkpointed block number ${blockNumber}`, blockInfos);
129
+ } else if (existingBlock.archive.root.equals(checkpointBlock.archive.root)) {
130
+ this.log.verbose(`Block number ${blockNumber} already inserted and matches checkpoint`, blockInfos);
131
+ lastAlreadyInsertedBlockNumber = blockNumber;
132
+ } else {
133
+ this.log.info(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
134
+ const prunedBlocks = await this.removeBlocksAfter(BlockNumber(blockNumber - 1));
135
+ return {
136
+ prunedBlocks,
137
+ lastAlreadyInsertedBlockNumber
138
+ };
139
+ }
140
+ }
141
+ // If local has more blocks than the checkpoint (e.g., local has [2,3,4] but checkpoint has [2,3]),
142
+ // we need to prune the extra local blocks so they match what was checkpointed
143
+ const lastCheckpointBlockNumber = checkpointBlocks.at(-1).number;
144
+ const lastLocalBlockNumber = localBlocksInSlot.at(-1)?.number;
145
+ if (lastLocalBlockNumber !== undefined && lastLocalBlockNumber > lastCheckpointBlockNumber) {
146
+ this.log.warn(`Local chain for slot ${slot} ends at block ${lastLocalBlockNumber} but checkpoint ends at ${lastCheckpointBlockNumber}. Pruning blocks after block ${lastCheckpointBlockNumber}.`);
147
+ const prunedBlocks = await this.removeBlocksAfter(lastCheckpointBlockNumber);
148
+ return {
149
+ prunedBlocks,
150
+ lastAlreadyInsertedBlockNumber
151
+ };
152
+ }
153
+ }
154
+ return {
155
+ prunedBlocks: undefined,
156
+ lastAlreadyInsertedBlockNumber
157
+ };
158
+ }
159
+ /**
160
+ * Removes all uncheckpointed blocks strictly after the specified block number and cleans up associated contract data.
161
+ * This handles removal of provisionally added blocks along with their contract classes/instances.
162
+ * Verifies that each block being removed is not part of a stored checkpoint.
163
+ *
164
+ * @param blockNumber - Remove all blocks with number greater than this.
165
+ * @returns The removed blocks.
166
+ * @throws Error if any block to be removed is checkpointed.
167
+ */ async removeUncheckpointedBlocksAfter(blockNumber) {
168
+ const result = await this.store.transactionAsync(async ()=>{
169
+ // Verify we're only removing uncheckpointed blocks
170
+ const lastCheckpointedBlockNumber = await this.store.getCheckpointedL2BlockNumber();
171
+ if (blockNumber < lastCheckpointedBlockNumber) {
172
+ throw new Error(`Cannot remove blocks after ${blockNumber} because checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`);
173
+ }
174
+ const result = await this.removeBlocksAfter(blockNumber);
175
+ await this.l2TipsCache?.refresh();
176
+ return result;
177
+ });
178
+ return result;
179
+ }
180
+ /**
181
+ * Removes all blocks strictly after the given block number along with any logs and contract data.
182
+ * Does not remove their checkpoints.
183
+ */ async removeBlocksAfter(blockNumber) {
184
+ // First get the blocks to be removed so we can clean up contract data
185
+ const removedBlocks = await this.store.removeBlocksAfter(blockNumber);
186
+ // Clean up contract data and logs for the removed blocks
187
+ await Promise.all([
188
+ this.store.deleteLogs(removedBlocks),
189
+ ...removedBlocks.map((block)=>this.removeContractDataFromDb(block))
190
+ ]);
191
+ return removedBlocks;
192
+ }
193
+ /**
194
+ * Removes all checkpoints after the given checkpoint number.
195
+ * Deletes ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated data
196
+ * that was stored for the removed checkpoints. Also removes ALL blocks (both checkpointed
197
+ * and uncheckpointed) after the last block of the given checkpoint.
198
+ *
199
+ * @param checkpointNumber - Remove all checkpoints strictly after this one.
200
+ * @returns True if the operation is successful.
201
+ */ async removeCheckpointsAfter(checkpointNumber) {
202
+ return await this.store.transactionAsync(async ()=>{
203
+ const { blocksRemoved = [] } = await this.store.removeCheckpointsAfter(checkpointNumber);
204
+ const opResults = await Promise.all([
205
+ // Prune rolls back to the last proven block, which is by definition valid
206
+ this.store.setPendingChainValidationStatus({
207
+ valid: true
208
+ }),
209
+ // Remove contract data for all blocks being removed
210
+ ...blocksRemoved.map((block)=>this.removeContractDataFromDb(block)),
211
+ this.store.deleteLogs(blocksRemoved)
212
+ ]);
213
+ await this.l2TipsCache?.refresh();
214
+ return opResults.every(Boolean);
215
+ });
216
+ }
217
+ /**
218
+ * Updates the proven checkpoint number and refreshes the L2 tips cache.
219
+ * @param checkpointNumber - The checkpoint number to set as proven.
220
+ */ async setProvenCheckpointNumber(checkpointNumber) {
221
+ await this.store.transactionAsync(async ()=>{
222
+ await this.store.setProvenCheckpointNumber(checkpointNumber);
223
+ await this.l2TipsCache?.refresh();
224
+ });
225
+ }
226
+ /**
227
+ * Updates the finalized checkpoint number and refreshes the L2 tips cache.
228
+ * @param checkpointNumber - The checkpoint number to set as finalized.
229
+ */ async setFinalizedCheckpointNumber(checkpointNumber) {
230
+ await this.store.transactionAsync(async ()=>{
231
+ await this.store.setFinalizedCheckpointNumber(checkpointNumber);
232
+ await this.l2TipsCache?.refresh();
233
+ });
234
+ }
235
+ /** Extracts and stores contract data from a single block. */ addContractDataToDb(block) {
236
+ return this.updateContractDataOnDb(block, 0);
237
+ }
238
+ /** Removes contract data associated with a block. */ removeContractDataFromDb(block) {
239
+ return this.updateContractDataOnDb(block, 1);
240
+ }
241
+ /** Adds or remove contract data associated with a block. */ async updateContractDataOnDb(block, operation) {
242
+ const contractClassLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.contractClassLogs);
243
+ const privateLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.privateLogs);
244
+ const publicLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.publicLogs);
245
+ return (await Promise.all([
246
+ this.updatePublishedContractClasses(contractClassLogs, block.number, operation),
247
+ this.updateDeployedContractInstances(privateLogs, block.number, operation),
248
+ this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation),
249
+ operation === 0 ? this.storeBroadcastedIndividualFunctions(contractClassLogs, block.number) : Promise.resolve(true)
250
+ ])).every(Boolean);
251
+ }
252
+ /**
253
+ * Extracts and stores contract classes out of ContractClassPublished events emitted by the class registry contract.
254
+ */ async updatePublishedContractClasses(allLogs, blockNum, operation) {
255
+ const contractClassPublishedEvents = allLogs.filter((log)=>ContractClassPublishedEvent.isContractClassPublishedEvent(log)).map((log)=>ContractClassPublishedEvent.fromLog(log));
256
+ if (operation == 1) {
257
+ const contractClasses = contractClassPublishedEvents.map((e)=>e.toContractClassPublic());
258
+ if (contractClasses.length > 0) {
259
+ contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
260
+ return await this.store.deleteContractClasses(contractClasses, blockNum);
261
+ }
262
+ return true;
263
+ }
264
+ // Compute bytecode commitments and validate class IDs in a single pass.
265
+ const contractClasses = [];
266
+ for (const event of contractClassPublishedEvents){
267
+ const contractClass = await event.toContractClassPublicWithBytecodeCommitment();
268
+ const computedClassId = await computeContractClassId({
269
+ artifactHash: contractClass.artifactHash,
270
+ privateFunctionsRoot: contractClass.privateFunctionsRoot,
271
+ publicBytecodeCommitment: contractClass.publicBytecodeCommitment
272
+ });
273
+ if (!computedClassId.equals(contractClass.id)) {
274
+ this.log.warn(`Skipping contract class with mismatched id at block ${blockNum}. Claimed ${contractClass.id}, computed ${computedClassId}`, {
275
+ blockNum,
276
+ contractClassId: event.contractClassId.toString()
277
+ });
278
+ continue;
279
+ }
280
+ contractClasses.push(contractClass);
281
+ }
282
+ if (contractClasses.length > 0) {
283
+ contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
284
+ return await this.store.addContractClasses(contractClasses, blockNum);
285
+ }
286
+ return true;
287
+ }
288
+ /**
289
+ * Extracts and stores contract instances out of ContractInstancePublished events emitted by the canonical deployer contract.
290
+ */ async updateDeployedContractInstances(allLogs, blockNum, operation) {
291
+ const allInstances = allLogs.filter((log)=>ContractInstancePublishedEvent.isContractInstancePublishedEvent(log)).map((log)=>ContractInstancePublishedEvent.fromLog(log)).map((e)=>e.toContractInstance());
292
+ // Verify that each instance's address matches the one derived from its fields if we're adding
293
+ const contractInstances = operation === 1 ? allInstances : await filterAsync(allInstances, async (instance)=>{
294
+ const computedAddress = await computeContractAddressFromInstance(instance);
295
+ if (!computedAddress.equals(instance.address)) {
296
+ this.log.warn(`Found contract instance with mismatched address at block ${blockNum}. Claimed ${instance.address} but computed ${computedAddress}.`, {
297
+ instanceAddress: instance.address.toString(),
298
+ computedAddress: computedAddress.toString(),
299
+ blockNum
300
+ });
301
+ return false;
302
+ }
303
+ return true;
304
+ });
305
+ if (contractInstances.length > 0) {
306
+ contractInstances.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance at ${c.address.toString()}`));
307
+ if (operation == 0) {
308
+ return await this.store.addContractInstances(contractInstances, blockNum);
309
+ } else if (operation == 1) {
310
+ return await this.store.deleteContractInstances(contractInstances, blockNum);
311
+ }
312
+ }
313
+ return true;
314
+ }
315
+ /**
316
+ * Extracts and stores contract instance updates out of ContractInstanceUpdated events.
317
+ */ async updateUpdatedContractInstances(allLogs, timestamp, operation) {
318
+ const contractUpdates = allLogs.filter((log)=>ContractInstanceUpdatedEvent.isContractInstanceUpdatedEvent(log)).map((log)=>ContractInstanceUpdatedEvent.fromLog(log)).map((e)=>e.toContractInstanceUpdate());
319
+ if (contractUpdates.length > 0) {
320
+ contractUpdates.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance update at ${c.address.toString()}`));
321
+ if (operation == 0) {
322
+ return await this.store.addContractInstanceUpdates(contractUpdates, timestamp);
323
+ } else if (operation == 1) {
324
+ return await this.store.deleteContractInstanceUpdates(contractUpdates, timestamp);
325
+ }
326
+ }
327
+ return true;
328
+ }
329
+ /**
330
+ * Stores the functions that were broadcasted individually.
331
+ *
332
+ * @dev Beware that there is not a delete variant of this, since they are added to contract classes
333
+ * and will be deleted as part of the class if needed.
334
+ */ async storeBroadcastedIndividualFunctions(allLogs, _blockNum) {
335
+ // Filter out private and utility function broadcast events
336
+ const privateFnEvents = allLogs.filter((log)=>PrivateFunctionBroadcastedEvent.isPrivateFunctionBroadcastedEvent(log)).map((log)=>PrivateFunctionBroadcastedEvent.fromLog(log));
337
+ const utilityFnEvents = allLogs.filter((log)=>UtilityFunctionBroadcastedEvent.isUtilityFunctionBroadcastedEvent(log)).map((log)=>UtilityFunctionBroadcastedEvent.fromLog(log));
338
+ // Group all events by contract class id
339
+ for (const [classIdString, classEvents] of Object.entries(groupBy([
340
+ ...privateFnEvents,
341
+ ...utilityFnEvents
342
+ ], (e)=>e.contractClassId.toString()))){
343
+ const contractClassId = Fr.fromHexString(classIdString);
344
+ const contractClass = await this.store.getContractClass(contractClassId);
345
+ if (!contractClass) {
346
+ this.log.warn(`Skipping broadcasted functions as contract class ${contractClassId.toString()} was not found`);
347
+ continue;
348
+ }
349
+ // Split private and utility functions, and filter out invalid ones
350
+ const allFns = classEvents.map((e)=>e.toFunctionWithMembershipProof());
351
+ const privateFns = allFns.filter((fn)=>'utilityFunctionsTreeRoot' in fn);
352
+ const utilityFns = allFns.filter((fn)=>'privateFunctionsArtifactTreeRoot' in fn);
353
+ const privateFunctionsWithValidity = await Promise.all(privateFns.map(async (fn)=>({
354
+ fn,
355
+ valid: await isValidPrivateFunctionMembershipProof(fn, contractClass)
356
+ })));
357
+ const validPrivateFns = privateFunctionsWithValidity.filter(({ valid })=>valid).map(({ fn })=>fn);
358
+ const utilityFunctionsWithValidity = await Promise.all(utilityFns.map(async (fn)=>({
359
+ fn,
360
+ valid: await isValidUtilityFunctionMembershipProof(fn, contractClass)
361
+ })));
362
+ const validUtilityFns = utilityFunctionsWithValidity.filter(({ valid })=>valid).map(({ fn })=>fn);
363
+ const validFnCount = validPrivateFns.length + validUtilityFns.length;
364
+ if (validFnCount !== allFns.length) {
365
+ this.log.warn(`Skipping ${allFns.length - validFnCount} invalid functions`);
366
+ }
367
+ // Store the functions in the contract class in a single operation
368
+ if (validFnCount > 0) {
369
+ this.log.verbose(`Storing ${validFnCount} functions for contract class ${contractClassId.toString()}`);
370
+ }
371
+ await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
372
+ }
373
+ return true;
374
+ }
375
+ }
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5zdHJ1bWVudGF0aW9uLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbW9kdWxlcy9pbnN0cnVtZW50YXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDbkQsT0FBTyxLQUFLLEVBQUUsY0FBYyxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDL0QsT0FBTyxFQUtMLEtBQUssaUJBQWlCLEVBRXRCLEtBQUssZUFBZSxFQUNwQixLQUFLLE1BQU0sRUFHWixNQUFNLHlCQUF5QixDQUFDO0FBRWpDLHFCQUFhLHVCQUF1QjtJQTJCaEMsT0FBTyxDQUFDLFNBQVM7SUExQm5CLFNBQWdCLE1BQU0sRUFBRSxNQUFNLENBQUM7SUFFL0IsT0FBTyxDQUFDLFdBQVcsQ0FBUTtJQUMzQixPQ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AA4C;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,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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDFfc3luY2hyb25pemVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbW9kdWxlcy9sMV9zeW5jaHJvbml6ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsbUJB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