@aztec/archiver 0.0.1-commit.96bb3f7 → 0.0.1-commit.993d240

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 (232) hide show
  1. package/README.md +164 -22
  2. package/dest/archiver.d.ts +158 -0
  3. package/dest/archiver.d.ts.map +1 -0
  4. package/dest/archiver.js +881 -0
  5. package/dest/config.d.ts +33 -0
  6. package/dest/config.d.ts.map +1 -0
  7. package/dest/{archiver/config.js → config.js} +31 -14
  8. package/dest/errors.d.ts +87 -0
  9. package/dest/errors.d.ts.map +1 -0
  10. package/dest/errors.js +129 -0
  11. package/dest/factory.d.ts +16 -10
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +112 -20
  14. package/dest/index.d.ts +19 -4
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +17 -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/{archiver/l1 → l1}/bin/retrieve-calldata.d.ts +1 -1
  21. package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
  22. package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.js +35 -32
  23. package/dest/l1/calldata_retriever.d.ts +136 -0
  24. package/dest/l1/calldata_retriever.d.ts.map +1 -0
  25. package/dest/l1/calldata_retriever.js +412 -0
  26. package/dest/l1/data_retrieval.d.ts +97 -0
  27. package/dest/l1/data_retrieval.d.ts.map +1 -0
  28. package/dest/{archiver/l1 → l1}/data_retrieval.js +65 -89
  29. package/dest/{archiver/l1 → l1}/debug_tx.d.ts +1 -1
  30. package/dest/l1/debug_tx.d.ts.map +1 -0
  31. package/dest/{archiver/l1 → l1}/spire_proposer.d.ts +5 -5
  32. package/dest/l1/spire_proposer.d.ts.map +1 -0
  33. package/dest/{archiver/l1 → l1}/spire_proposer.js +9 -17
  34. package/dest/l1/trace_tx.d.ts +43 -0
  35. package/dest/l1/trace_tx.d.ts.map +1 -0
  36. package/dest/l1/types.d.ts +12 -0
  37. package/dest/l1/types.d.ts.map +1 -0
  38. package/dest/l1/validate_historical_logs.d.ts +23 -0
  39. package/dest/l1/validate_historical_logs.d.ts.map +1 -0
  40. package/dest/l1/validate_historical_logs.js +108 -0
  41. package/dest/{archiver/l1 → l1}/validate_trace.d.ts +6 -3
  42. package/dest/l1/validate_trace.d.ts.map +1 -0
  43. package/dest/{archiver/l1 → l1}/validate_trace.js +13 -9
  44. package/dest/modules/contract_data_source_adapter.d.ts +25 -0
  45. package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
  46. package/dest/modules/contract_data_source_adapter.js +40 -0
  47. package/dest/modules/data_source_base.d.ts +113 -0
  48. package/dest/modules/data_source_base.d.ts.map +1 -0
  49. package/dest/modules/data_source_base.js +351 -0
  50. package/dest/modules/data_store_updater.d.ts +105 -0
  51. package/dest/modules/data_store_updater.d.ts.map +1 -0
  52. package/dest/modules/data_store_updater.js +392 -0
  53. package/dest/modules/instrumentation.d.ts +55 -0
  54. package/dest/modules/instrumentation.d.ts.map +1 -0
  55. package/dest/{archiver → modules}/instrumentation.js +61 -19
  56. package/dest/modules/l1_synchronizer.d.ts +77 -0
  57. package/dest/modules/l1_synchronizer.d.ts.map +1 -0
  58. package/dest/modules/l1_synchronizer.js +1344 -0
  59. package/dest/modules/validation.d.ts +18 -0
  60. package/dest/modules/validation.d.ts.map +1 -0
  61. package/dest/{archiver → modules}/validation.js +12 -6
  62. package/dest/store/block_store.d.ts +300 -0
  63. package/dest/store/block_store.d.ts.map +1 -0
  64. package/dest/store/block_store.js +1219 -0
  65. package/dest/store/contract_class_store.d.ts +31 -0
  66. package/dest/store/contract_class_store.d.ts.map +1 -0
  67. package/dest/store/contract_class_store.js +80 -0
  68. package/dest/store/contract_instance_store.d.ts +51 -0
  69. package/dest/store/contract_instance_store.d.ts.map +1 -0
  70. package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +38 -3
  71. package/dest/store/data_stores.d.ts +68 -0
  72. package/dest/store/data_stores.d.ts.map +1 -0
  73. package/dest/store/data_stores.js +54 -0
  74. package/dest/store/function_names_cache.d.ts +17 -0
  75. package/dest/store/function_names_cache.d.ts.map +1 -0
  76. package/dest/store/function_names_cache.js +30 -0
  77. package/dest/store/l2_tips_cache.d.ts +25 -0
  78. package/dest/store/l2_tips_cache.d.ts.map +1 -0
  79. package/dest/store/l2_tips_cache.js +26 -0
  80. package/dest/store/log_store.d.ts +59 -0
  81. package/dest/store/log_store.d.ts.map +1 -0
  82. package/dest/store/log_store.js +310 -0
  83. package/dest/store/log_store_codec.d.ts +70 -0
  84. package/dest/store/log_store_codec.d.ts.map +1 -0
  85. package/dest/store/log_store_codec.js +101 -0
  86. package/dest/store/message_store.d.ts +50 -0
  87. package/dest/store/message_store.d.ts.map +1 -0
  88. package/dest/{archiver/kv_archiver_store → store}/message_store.js +51 -9
  89. package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
  90. package/dest/structs/data_retrieval.d.ts.map +1 -0
  91. package/dest/structs/inbox_message.d.ts +15 -0
  92. package/dest/structs/inbox_message.d.ts.map +1 -0
  93. package/dest/{archiver/structs → structs}/published.d.ts +1 -1
  94. package/dest/structs/published.d.ts.map +1 -0
  95. package/dest/test/fake_l1_state.d.ts +214 -0
  96. package/dest/test/fake_l1_state.d.ts.map +1 -0
  97. package/dest/test/fake_l1_state.js +517 -0
  98. package/dest/test/index.d.ts +2 -1
  99. package/dest/test/index.d.ts.map +1 -1
  100. package/dest/test/index.js +4 -1
  101. package/dest/test/mock_archiver.d.ts +2 -2
  102. package/dest/test/mock_archiver.d.ts.map +1 -1
  103. package/dest/test/mock_archiver.js +3 -3
  104. package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
  105. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  106. package/dest/test/mock_l1_to_l2_message_source.js +2 -1
  107. package/dest/test/mock_l2_block_source.d.ts +65 -41
  108. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  109. package/dest/test/mock_l2_block_source.js +330 -151
  110. package/dest/test/mock_structs.d.ts +81 -3
  111. package/dest/test/mock_structs.d.ts.map +1 -1
  112. package/dest/test/mock_structs.js +152 -7
  113. package/dest/test/noop_l1_archiver.d.ts +29 -0
  114. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  115. package/dest/test/noop_l1_archiver.js +85 -0
  116. package/package.json +17 -18
  117. package/src/archiver.ts +681 -0
  118. package/src/{archiver/config.ts → config.ts} +43 -12
  119. package/src/errors.ts +203 -0
  120. package/src/factory.ts +175 -22
  121. package/src/index.ts +27 -3
  122. package/src/interfaces.ts +9 -0
  123. package/src/l1/README.md +55 -0
  124. package/src/{archiver/l1 → l1}/bin/retrieve-calldata.ts +45 -33
  125. package/src/l1/calldata_retriever.ts +522 -0
  126. package/src/{archiver/l1 → l1}/data_retrieval.ts +106 -134
  127. package/src/{archiver/l1 → l1}/spire_proposer.ts +7 -15
  128. package/src/l1/validate_historical_logs.ts +140 -0
  129. package/src/{archiver/l1 → l1}/validate_trace.ts +24 -6
  130. package/src/modules/contract_data_source_adapter.ts +55 -0
  131. package/src/modules/data_source_base.ts +493 -0
  132. package/src/modules/data_store_updater.ts +518 -0
  133. package/src/{archiver → modules}/instrumentation.ts +72 -20
  134. package/src/modules/l1_synchronizer.ts +1257 -0
  135. package/src/{archiver → modules}/validation.ts +15 -9
  136. package/src/store/block_store.ts +1590 -0
  137. package/src/store/contract_class_store.ts +108 -0
  138. package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +52 -6
  139. package/src/store/data_stores.ts +104 -0
  140. package/src/store/function_names_cache.ts +37 -0
  141. package/src/store/l2_tips_cache.ts +35 -0
  142. package/src/store/log_store.ts +379 -0
  143. package/src/store/log_store_codec.ts +132 -0
  144. package/src/{archiver/kv_archiver_store → store}/message_store.ts +60 -10
  145. package/src/{archiver/structs → structs}/inbox_message.ts +1 -1
  146. package/src/test/fake_l1_state.ts +770 -0
  147. package/src/test/index.ts +4 -0
  148. package/src/test/mock_archiver.ts +4 -3
  149. package/src/test/mock_l1_to_l2_message_source.ts +1 -0
  150. package/src/test/mock_l2_block_source.ts +403 -171
  151. package/src/test/mock_structs.ts +283 -8
  152. package/src/test/noop_l1_archiver.ts +139 -0
  153. package/dest/archiver/archiver.d.ts +0 -307
  154. package/dest/archiver/archiver.d.ts.map +0 -1
  155. package/dest/archiver/archiver.js +0 -2102
  156. package/dest/archiver/archiver_store.d.ts +0 -315
  157. package/dest/archiver/archiver_store.d.ts.map +0 -1
  158. package/dest/archiver/archiver_store.js +0 -4
  159. package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
  160. package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
  161. package/dest/archiver/archiver_store_test_suite.js +0 -2770
  162. package/dest/archiver/config.d.ts +0 -22
  163. package/dest/archiver/config.d.ts.map +0 -1
  164. package/dest/archiver/errors.d.ts +0 -36
  165. package/dest/archiver/errors.d.ts.map +0 -1
  166. package/dest/archiver/errors.js +0 -54
  167. package/dest/archiver/index.d.ts +0 -7
  168. package/dest/archiver/index.d.ts.map +0 -1
  169. package/dest/archiver/index.js +0 -4
  170. package/dest/archiver/instrumentation.d.ts +0 -37
  171. package/dest/archiver/instrumentation.d.ts.map +0 -1
  172. package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -164
  173. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
  174. package/dest/archiver/kv_archiver_store/block_store.js +0 -626
  175. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
  176. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
  177. package/dest/archiver/kv_archiver_store/contract_class_store.js +0 -120
  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 -159
  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 -316
  183. package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -45
  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 -401
  186. package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -40
  187. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
  188. package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +0 -1
  189. package/dest/archiver/l1/calldata_retriever.d.ts +0 -112
  190. package/dest/archiver/l1/calldata_retriever.d.ts.map +0 -1
  191. package/dest/archiver/l1/calldata_retriever.js +0 -471
  192. package/dest/archiver/l1/data_retrieval.d.ts +0 -90
  193. package/dest/archiver/l1/data_retrieval.d.ts.map +0 -1
  194. package/dest/archiver/l1/debug_tx.d.ts.map +0 -1
  195. package/dest/archiver/l1/spire_proposer.d.ts.map +0 -1
  196. package/dest/archiver/l1/trace_tx.d.ts +0 -97
  197. package/dest/archiver/l1/trace_tx.d.ts.map +0 -1
  198. package/dest/archiver/l1/types.d.ts +0 -12
  199. package/dest/archiver/l1/types.d.ts.map +0 -1
  200. package/dest/archiver/l1/validate_trace.d.ts.map +0 -1
  201. package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
  202. package/dest/archiver/structs/inbox_message.d.ts +0 -15
  203. package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
  204. package/dest/archiver/structs/published.d.ts.map +0 -1
  205. package/dest/archiver/validation.d.ts +0 -17
  206. package/dest/archiver/validation.d.ts.map +0 -1
  207. package/dest/rpc/index.d.ts +0 -9
  208. package/dest/rpc/index.d.ts.map +0 -1
  209. package/dest/rpc/index.js +0 -15
  210. package/src/archiver/archiver.ts +0 -2265
  211. package/src/archiver/archiver_store.ts +0 -380
  212. package/src/archiver/archiver_store_test_suite.ts +0 -2842
  213. package/src/archiver/errors.ts +0 -90
  214. package/src/archiver/index.ts +0 -6
  215. package/src/archiver/kv_archiver_store/block_store.ts +0 -850
  216. package/src/archiver/kv_archiver_store/contract_class_store.ts +0 -176
  217. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -442
  218. package/src/archiver/kv_archiver_store/log_store.ts +0 -516
  219. package/src/archiver/l1/README.md +0 -98
  220. package/src/archiver/l1/calldata_retriever.ts +0 -641
  221. package/src/rpc/index.ts +0 -16
  222. /package/dest/{archiver/l1 → l1}/debug_tx.js +0 -0
  223. /package/dest/{archiver/l1 → l1}/trace_tx.js +0 -0
  224. /package/dest/{archiver/l1 → l1}/types.js +0 -0
  225. /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
  226. /package/dest/{archiver/structs → structs}/inbox_message.js +0 -0
  227. /package/dest/{archiver/structs → structs}/published.js +0 -0
  228. /package/src/{archiver/l1 → l1}/debug_tx.ts +0 -0
  229. /package/src/{archiver/l1 → l1}/trace_tx.ts +0 -0
  230. /package/src/{archiver/l1 → l1}/types.ts +0 -0
  231. /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
  232. /package/src/{archiver/structs → structs}/published.ts +0 -0
@@ -0,0 +1,105 @@
1
+ import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
2
+ import type { CommitteeAttestation, L2Block, ValidateCheckpointResult } from '@aztec/stdlib/block';
3
+ import { type L1PublishedData, type ProposedCheckpointInput, type PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
4
+ import type { ArchiverDataStores } from '../store/data_stores.js';
5
+ import type { L2TipsCache } from '../store/l2_tips_cache.js';
6
+ /** Result of adding checkpoints with information about any pruned blocks. */
7
+ type ReconcileCheckpointsResult = {
8
+ /** Blocks that were pruned due to conflict with L1 checkpoints. */
9
+ prunedBlocks: L2Block[] | undefined;
10
+ /** Last block number that was already inserted locally, or undefined if none. */
11
+ lastAlreadyInsertedBlockNumber: BlockNumber | undefined;
12
+ };
13
+ /** Archiver helper module to handle updates to the data store. */
14
+ export declare class ArchiverDataStoreUpdater {
15
+ private stores;
16
+ private l2TipsCache?;
17
+ private opts;
18
+ private readonly log;
19
+ constructor(stores: ArchiverDataStores, l2TipsCache?: L2TipsCache | undefined, opts?: {
20
+ rollupManaLimit?: number;
21
+ });
22
+ /**
23
+ * Adds a proposed block to the store with contract class/instance extraction from logs.
24
+ * This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
25
+ * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the block logs.
26
+ *
27
+ * @param block - The proposed L2 block to add.
28
+ * @param pendingChainValidationStatus - Optional validation status to set.
29
+ * @returns True if the operation is successful.
30
+ */
31
+ addProposedBlock(block: L2Block, pendingChainValidationStatus?: ValidateCheckpointResult): Promise<boolean>;
32
+ /**
33
+ * Reconciles local blocks with incoming checkpoints from L1.
34
+ * Adds new checkpoints to the store with contract class/instance extraction from logs.
35
+ * Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
36
+ * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the checkpoint block logs.
37
+ * If `promoteProposed` is supplied, the proposed-checkpoint promotion runs inside the same transaction
38
+ * as the added checkpoints so both updates are applied atomically.
39
+ *
40
+ * @param checkpoints - The published checkpoints to add (excluding any being promoted from proposed).
41
+ * @param pendingChainValidationStatus - Optional validation status to set.
42
+ * @param promoteProposed - Optional promotion of the current proposed checkpoint (fast path when blocks are already local).
43
+ * @returns Result with information about any pruned blocks.
44
+ */
45
+ addCheckpoints(checkpoints: PublishedCheckpoint[], pendingChainValidationStatus?: ValidateCheckpointResult, promoteProposed?: {
46
+ l1: L1PublishedData;
47
+ attestations: CommitteeAttestation[];
48
+ checkpoint: PublishedCheckpoint;
49
+ }, evictProposedFrom?: CheckpointNumber): Promise<ReconcileCheckpointsResult>;
50
+ addProposedCheckpoint(proposedCheckpoint: ProposedCheckpointInput): Promise<void>;
51
+ private pruneMismatchingLocalBlocks;
52
+ /**
53
+ * Removes all uncheckpointed blocks strictly after the specified block number and cleans up associated contract data.
54
+ * This handles removal of provisionally added blocks along with their contract classes/instances.
55
+ * Verifies that each block being removed is not part of a stored checkpoint.
56
+ *
57
+ * @param blockNumber - Remove all blocks with number greater than this.
58
+ * @returns The removed blocks.
59
+ * @throws Error if any block to be removed is checkpointed.
60
+ */
61
+ removeUncheckpointedBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]>;
62
+ /**
63
+ * Removes all blocks without a proposed checkpoint strictly after the specified block number and cleans up associated contract data.
64
+ * This handles removal of provisionally added blocks along with their contract classes/instances.
65
+ * Verifies that each block being removed is not part of a stored checkpoint (proposed or not).
66
+ * This differs from `removeUncheckpointedBlocksAfter` in that it also checks proposed checkpoints.
67
+ *
68
+ * @param blockNumber - Remove all blocks with number greater than this.
69
+ * @returns The removed blocks.
70
+ * @throws Error if any block to be removed is checkpointed.
71
+ */
72
+ removeBlocksWithoutProposedCheckpointAfter(blockNumber: BlockNumber): Promise<L2Block[]>;
73
+ private evictProposedCheckpointsForPrunedBlocks;
74
+ private removeBlocksAfter;
75
+ /**
76
+ * Removes all checkpoints after the given checkpoint number.
77
+ * Deletes ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated data
78
+ * that was stored for the removed checkpoints. Also removes ALL blocks (both checkpointed
79
+ * and uncheckpointed) after the last block of the given checkpoint.
80
+ *
81
+ * @param checkpointNumber - Remove all checkpoints strictly after this one.
82
+ * @returns True if the operation is successful.
83
+ */
84
+ removeCheckpointsAfter(checkpointNumber: CheckpointNumber): Promise<boolean>;
85
+ /**
86
+ * Updates the proven checkpoint number and refreshes the L2 tips cache.
87
+ * @param checkpointNumber - The checkpoint number to set as proven.
88
+ */
89
+ setProvenCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<void>;
90
+ /**
91
+ * Updates the finalized checkpoint number and refreshes the L2 tips cache.
92
+ * @param checkpointNumber - The checkpoint number to set as finalized.
93
+ */
94
+ setFinalizedCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<void>;
95
+ /** Extracts and stores contract data from a single block. */
96
+ private addContractDataToDb;
97
+ /** Removes contract data associated with a block. */
98
+ private removeContractDataFromDb;
99
+ private updateContractDataOnDb;
100
+ private updatePublishedContractClasses;
101
+ private updateDeployedContractInstances;
102
+ private updateUpdatedContractInstances;
103
+ }
104
+ export {};
105
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGF0YV9zdG9yZV91cGRhdGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbW9kdWxlcy9kYXRhX3N0b3JlX3VwZGF0ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFdBQVcsRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBUWhGLE9BQU8sS0FBSyxFQUFFLG9CQUFvQixFQUFFLE9BQU8sRUFBRSx3QkFBd0IsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBQ25HLE9BQU8sRUFDTCxLQUFLLGVBQWUsRUFDcEIsS0FBSyx1QkFBdUIsRUFDNUIsS0FBSyxtQkFBbUIsRUFFekIsTUFBTSwwQkFBMEIsQ0FBQztBQVNsQyxPQUFPLEtBQUssRUFBRSxrQkFBa0IsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBQ2xFLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBUTdELDZFQUE2RTtBQUM3RSxLQUFLLDBCQUEwQixHQUFHO0lBQ2hDLG1FQUFtRTtJQUNuRSxZQUFZLEVBQUUsT0FBTyxFQUFFLEdBQUcsU0FBUyxDQUFDO0lBQ3BDLGlGQUFpRjtJQUNqRiw4QkFBOEIsRUFBRSxXQUFXLEdBQUcsU0FBUyxDQUFDO0NBQ3pELENBQUM7QUFFRixrRUFBa0U7QUFDbEUscUJBQWEsd0JBQXdCO0lBSWpDLE9BQU8sQ0FBQyxNQUFNO0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;IACU,yBAAyB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAKxF;IAED;;;OAGG;IACU,4BAA4B,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAK3F;IAED,6DAA6D;IAC7D,OAAO,CAAC,mBAAmB;IAI3B,qDAAqD;IACrD,OAAO,CAAC,wBAAwB;YAKlB,sBAAsB;YAiBtB,8BAA8B;YA+C9B,+BAA+B;YA0C/B,8BAA8B;CAsB7C"}
@@ -0,0 +1,392 @@
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
+ stores;
15
+ l2TipsCache;
16
+ opts;
17
+ log;
18
+ constructor(stores, l2TipsCache, opts = {}){
19
+ this.stores = stores;
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.stores.db.transactionAsync(async ()=>{
34
+ await this.stores.blocks.addProposedBlock(block);
35
+ const opResults = await Promise.all([
36
+ // Update the pending chain validation status if provided
37
+ pendingChainValidationStatus && this.stores.blocks.setPendingChainValidationStatus(pendingChainValidationStatus),
38
+ // Add any logs emitted during the retrieved block
39
+ this.stores.logs.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
+ return opResults.every(Boolean);
46
+ });
47
+ await this.l2TipsCache?.refresh();
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
+ * If `promoteProposed` is supplied, the proposed-checkpoint promotion runs inside the same transaction
56
+ * as the added checkpoints so both updates are applied atomically.
57
+ *
58
+ * @param checkpoints - The published checkpoints to add (excluding any being promoted from proposed).
59
+ * @param pendingChainValidationStatus - Optional validation status to set.
60
+ * @param promoteProposed - Optional promotion of the current proposed checkpoint (fast path when blocks are already local).
61
+ * @returns Result with information about any pruned blocks.
62
+ */ async addCheckpoints(checkpoints, pendingChainValidationStatus, promoteProposed, evictProposedFrom) {
63
+ for (const checkpoint of checkpoints){
64
+ validateCheckpoint(checkpoint.checkpoint, {
65
+ rollupManaLimit: this.opts?.rollupManaLimit
66
+ });
67
+ }
68
+ if (promoteProposed) {
69
+ validateCheckpoint(promoteProposed.checkpoint.checkpoint, {
70
+ rollupManaLimit: this.opts?.rollupManaLimit
71
+ });
72
+ }
73
+ const result = await this.stores.db.transactionAsync(async ()=>{
74
+ // Before adding checkpoints, check for conflicts with local blocks if any
75
+ const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
76
+ await this.stores.blocks.addCheckpoints(checkpoints);
77
+ // Filter out blocks that were already inserted via addProposedBlock() to avoid duplicating logs/contract data
78
+ const newBlocks = checkpoints.flatMap((ch)=>ch.checkpoint.blocks).filter((b)=>lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
79
+ await Promise.all([
80
+ // Update the pending chain validation status if provided
81
+ pendingChainValidationStatus && this.stores.blocks.setPendingChainValidationStatus(pendingChainValidationStatus),
82
+ // Add any logs emitted during the retrieved blocks
83
+ this.stores.logs.addLogs(newBlocks),
84
+ // Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
85
+ ...newBlocks.map((block)=>this.addContractDataToDb(block)),
86
+ // Promote the proposed checkpoint if requested (uses explicit checkpoint number)
87
+ promoteProposed ? this.stores.blocks.promoteProposedToCheckpointed(promoteProposed.checkpoint.checkpoint.number, promoteProposed.l1, promoteProposed.attestations, promoteProposed.checkpoint.checkpoint.archive.root) : undefined,
88
+ // Evict pending checkpoints that diverged from what L1 mined
89
+ evictProposedFrom !== undefined ? this.stores.blocks.evictProposedCheckpointsFrom(evictProposedFrom) : undefined
90
+ ]);
91
+ return {
92
+ prunedBlocks,
93
+ lastAlreadyInsertedBlockNumber
94
+ };
95
+ });
96
+ await this.l2TipsCache?.refresh();
97
+ return result;
98
+ }
99
+ async addProposedCheckpoint(proposedCheckpoint) {
100
+ const result = await this.stores.db.transactionAsync(async ()=>{
101
+ await this.stores.blocks.addProposedCheckpoint(proposedCheckpoint);
102
+ });
103
+ await this.l2TipsCache?.refresh();
104
+ return result;
105
+ }
106
+ /**
107
+ * Checks for local proposed blocks that do not match the ones to be checkpointed and prunes them.
108
+ * Conflict detection is keyed on `blockNumber`: when a local proposed block and an L1
109
+ * checkpointed block share a block number but live at different slots (e.g. a different proposer
110
+ * mined the same block number one slot earlier), we still treat them as a conflict and prune.
111
+ * The trailing per-checkpoint prune that handles "local has extra trailing blocks within the
112
+ * same slot as the published checkpoint" remains scoped by slot to preserve pipelining: local
113
+ * blocks that live at a later slot than the checkpoint being processed represent speculation
114
+ * atop the just-confirmed tip (and may be referenced by a pending proposed checkpoint), so we
115
+ * leave them in place. This method handles multiple checkpoints but returns after pruning the
116
+ * first conflict found. This is correct because pruning from the first conflict point removes
117
+ * all subsequent blocks, and when checkpoints are added afterward, they include all the correct
118
+ * blocks.
119
+ */ async pruneMismatchingLocalBlocks(checkpoints) {
120
+ const [lastCheckpointedBlockNumber, lastBlockNumber] = await Promise.all([
121
+ this.stores.blocks.getCheckpointedL2BlockNumber(),
122
+ this.stores.blocks.getLatestL2BlockNumber()
123
+ ]);
124
+ // Exit early if there are no local uncheckpointed blocks
125
+ if (lastBlockNumber === lastCheckpointedBlockNumber) {
126
+ return {
127
+ prunedBlocks: undefined,
128
+ lastAlreadyInsertedBlockNumber: undefined
129
+ };
130
+ }
131
+ // Get all uncheckpointed local blocks
132
+ const uncheckpointedLocalBlocks = await this.stores.blocks.getBlocksData({
133
+ from: BlockNumber.add(lastCheckpointedBlockNumber, 1),
134
+ limit: lastBlockNumber - lastCheckpointedBlockNumber
135
+ });
136
+ let lastAlreadyInsertedBlockNumber;
137
+ for (const publishedCheckpoint of checkpoints){
138
+ const checkpointBlocks = publishedCheckpoint.checkpoint.blocks;
139
+ const slot = publishedCheckpoint.checkpoint.slot;
140
+ if (checkpointBlocks.length === 0) {
141
+ this.log.warn(`Checkpoint ${publishedCheckpoint.checkpoint.number} for slot ${slot} has no blocks`);
142
+ continue;
143
+ }
144
+ // Find the first checkpoint block that conflicts with an existing local block and prune local afterwards.
145
+ // Conflict detection joins on block number only — same block number at a different slot is still a conflict.
146
+ for (const checkpointBlock of checkpointBlocks){
147
+ const blockNumber = checkpointBlock.number;
148
+ const existingBlock = uncheckpointedLocalBlocks.find((b)=>b.header.getBlockNumber() === blockNumber);
149
+ const blockInfos = {
150
+ existingBlock: existingBlock?.header.toInspect(),
151
+ checkpointBlock: checkpointBlock.toBlockInfo()
152
+ };
153
+ if (!existingBlock) {
154
+ this.log.verbose(`No local block found for checkpointed block number ${blockNumber}`, blockInfos);
155
+ } else if (existingBlock.archive.root.equals(checkpointBlock.archive.root)) {
156
+ this.log.verbose(`Block number ${blockNumber} already inserted and matches checkpoint`, blockInfos);
157
+ lastAlreadyInsertedBlockNumber = blockNumber;
158
+ } else {
159
+ this.log.info(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
160
+ const prunedBlocks = await this.removeBlocksAfter(BlockNumber(blockNumber - 1));
161
+ await this.evictProposedCheckpointsForPrunedBlocks(prunedBlocks);
162
+ return {
163
+ prunedBlocks,
164
+ lastAlreadyInsertedBlockNumber
165
+ };
166
+ }
167
+ }
168
+ // If the sequencer locally proposed extra blocks within this checkpoint's slot (e.g. local has
169
+ // [N, N+1] but L1 confirmed just [N]), prune the extras. Scoped to the checkpoint's slot so we
170
+ // do not throw away speculative blocks at later slots that belong to a pending proposed checkpoint.
171
+ const lastCheckpointBlockNumber = checkpointBlocks.at(-1).number;
172
+ const localBlocksInSlot = uncheckpointedLocalBlocks.filter((b)=>b.header.getSlot() === slot);
173
+ const lastLocalBlockNumber = localBlocksInSlot.at(-1)?.header.getBlockNumber();
174
+ if (lastLocalBlockNumber !== undefined && lastLocalBlockNumber > lastCheckpointBlockNumber) {
175
+ this.log.warn(`Local chain for slot ${slot} ends at block ${lastLocalBlockNumber} but checkpoint ends at ${lastCheckpointBlockNumber}. Pruning blocks after block ${lastCheckpointBlockNumber}.`);
176
+ const prunedBlocks = await this.removeBlocksAfter(lastCheckpointBlockNumber);
177
+ await this.evictProposedCheckpointsForPrunedBlocks(prunedBlocks);
178
+ return {
179
+ prunedBlocks,
180
+ lastAlreadyInsertedBlockNumber
181
+ };
182
+ }
183
+ }
184
+ return {
185
+ prunedBlocks: undefined,
186
+ lastAlreadyInsertedBlockNumber
187
+ };
188
+ }
189
+ /**
190
+ * Removes all uncheckpointed blocks strictly after the specified block number and cleans up associated contract data.
191
+ * This handles removal of provisionally added blocks along with their contract classes/instances.
192
+ * Verifies that each block being removed is not part of a stored checkpoint.
193
+ *
194
+ * @param blockNumber - Remove all blocks with number greater than this.
195
+ * @returns The removed blocks.
196
+ * @throws Error if any block to be removed is checkpointed.
197
+ */ async removeUncheckpointedBlocksAfter(blockNumber) {
198
+ const result = await this.stores.db.transactionAsync(async ()=>{
199
+ // Verify we're only removing uncheckpointed blocks
200
+ const lastCheckpointedBlockNumber = await this.stores.blocks.getCheckpointedL2BlockNumber();
201
+ if (blockNumber < lastCheckpointedBlockNumber) {
202
+ throw new Error(`Cannot remove blocks after ${blockNumber} because checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`);
203
+ }
204
+ const prunedBlocks = await this.removeBlocksAfter(blockNumber);
205
+ await this.evictProposedCheckpointsForPrunedBlocks(prunedBlocks);
206
+ return prunedBlocks;
207
+ });
208
+ await this.l2TipsCache?.refresh();
209
+ return result;
210
+ }
211
+ /**
212
+ * Removes all blocks without a proposed checkpoint strictly after the specified block number and cleans up associated contract data.
213
+ * This handles removal of provisionally added blocks along with their contract classes/instances.
214
+ * Verifies that each block being removed is not part of a stored checkpoint (proposed or not).
215
+ * This differs from `removeUncheckpointedBlocksAfter` in that it also checks proposed checkpoints.
216
+ *
217
+ * @param blockNumber - Remove all blocks with number greater than this.
218
+ * @returns The removed blocks.
219
+ * @throws Error if any block to be removed is checkpointed.
220
+ */ async removeBlocksWithoutProposedCheckpointAfter(blockNumber) {
221
+ const result = await this.stores.db.transactionAsync(async ()=>{
222
+ // Verify we're only removing uncheckpointed blocks
223
+ const lastCheckpointedBlockNumber = await this.stores.blocks.getProposedCheckpointL2BlockNumber();
224
+ if (blockNumber < lastCheckpointedBlockNumber) {
225
+ throw new Error(`Cannot remove blocks after ${blockNumber} because proposed checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`);
226
+ }
227
+ return await this.removeBlocksAfter(blockNumber);
228
+ });
229
+ await this.l2TipsCache?.refresh();
230
+ return result;
231
+ }
232
+ /**
233
+ * Evicts pending proposed checkpoints that referenced any of the just-pruned blocks. Pruned
234
+ * blocks invalidate all proposed checkpoints from the lowest pruned block's checkpoint number
235
+ * onwards: those checkpoints either reference the pruned blocks directly or chain off them.
236
+ */ async evictProposedCheckpointsForPrunedBlocks(prunedBlocks) {
237
+ if (prunedBlocks.length === 0) {
238
+ return;
239
+ }
240
+ const fromCheckpointNumber = prunedBlocks[0].checkpointNumber;
241
+ await this.stores.blocks.evictProposedCheckpointsFrom(fromCheckpointNumber);
242
+ }
243
+ /**
244
+ * Removes all blocks strictly after the given block number along with any logs and contract data.
245
+ * Does not remove their checkpoints.
246
+ */ async removeBlocksAfter(blockNumber) {
247
+ // First get the blocks to be removed so we can clean up contract data
248
+ const removedBlocks = await this.stores.blocks.removeBlocksAfter(blockNumber);
249
+ // Clean up contract data and logs for the removed blocks
250
+ await Promise.all([
251
+ this.stores.logs.deleteLogs(removedBlocks),
252
+ ...removedBlocks.map((block)=>this.removeContractDataFromDb(block))
253
+ ]);
254
+ return removedBlocks;
255
+ }
256
+ /**
257
+ * Removes all checkpoints after the given checkpoint number.
258
+ * Deletes ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated data
259
+ * that was stored for the removed checkpoints. Also removes ALL blocks (both checkpointed
260
+ * and uncheckpointed) after the last block of the given checkpoint.
261
+ *
262
+ * @param checkpointNumber - Remove all checkpoints strictly after this one.
263
+ * @returns True if the operation is successful.
264
+ */ async removeCheckpointsAfter(checkpointNumber) {
265
+ const result = await this.stores.db.transactionAsync(async ()=>{
266
+ const { blocksRemoved = [] } = await this.stores.blocks.removeCheckpointsAfter(checkpointNumber);
267
+ const opResults = await Promise.all([
268
+ // Prune rolls back to the last proven block, which is by definition valid
269
+ this.stores.blocks.setPendingChainValidationStatus({
270
+ valid: true
271
+ }),
272
+ // Remove contract data for all blocks being removed
273
+ ...blocksRemoved.map((block)=>this.removeContractDataFromDb(block)),
274
+ this.stores.logs.deleteLogs(blocksRemoved)
275
+ ]);
276
+ return opResults.every(Boolean);
277
+ });
278
+ await this.l2TipsCache?.refresh();
279
+ return result;
280
+ }
281
+ /**
282
+ * Updates the proven checkpoint number and refreshes the L2 tips cache.
283
+ * @param checkpointNumber - The checkpoint number to set as proven.
284
+ */ async setProvenCheckpointNumber(checkpointNumber) {
285
+ await this.stores.db.transactionAsync(async ()=>{
286
+ await this.stores.blocks.setProvenCheckpointNumber(checkpointNumber);
287
+ });
288
+ await this.l2TipsCache?.refresh();
289
+ }
290
+ /**
291
+ * Updates the finalized checkpoint number and refreshes the L2 tips cache.
292
+ * @param checkpointNumber - The checkpoint number to set as finalized.
293
+ */ async setFinalizedCheckpointNumber(checkpointNumber) {
294
+ await this.stores.db.transactionAsync(async ()=>{
295
+ await this.stores.blocks.setFinalizedCheckpointNumber(checkpointNumber);
296
+ });
297
+ await this.l2TipsCache?.refresh();
298
+ }
299
+ /** Extracts and stores contract data from a single block. */ addContractDataToDb(block) {
300
+ return this.updateContractDataOnDb(block, 0);
301
+ }
302
+ /** Removes contract data associated with a block. */ removeContractDataFromDb(block) {
303
+ return this.updateContractDataOnDb(block, 1);
304
+ }
305
+ /** Adds or remove contract data associated with a block. */ async updateContractDataOnDb(block, operation) {
306
+ const contractClassLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.contractClassLogs);
307
+ const privateLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.privateLogs);
308
+ const publicLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.publicLogs);
309
+ return (await Promise.all([
310
+ this.updatePublishedContractClasses(contractClassLogs, block.number, operation),
311
+ this.updateDeployedContractInstances(privateLogs, block.number, operation),
312
+ this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation)
313
+ ])).every(Boolean);
314
+ }
315
+ /**
316
+ * Extracts and stores contract classes out of ContractClassPublished events emitted by the class registry contract.
317
+ */ async updatePublishedContractClasses(allLogs, blockNum, operation) {
318
+ const contractClassPublishedEvents = allLogs.filter((log)=>ContractClassPublishedEvent.isContractClassPublishedEvent(log)).map((log)=>ContractClassPublishedEvent.fromLog(log));
319
+ if (operation == 1) {
320
+ const contractClasses = contractClassPublishedEvents.map((e)=>e.toContractClassPublic());
321
+ if (contractClasses.length > 0) {
322
+ contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
323
+ return await this.stores.contractClasses.deleteContractClasses(contractClasses, blockNum);
324
+ }
325
+ return true;
326
+ }
327
+ // Compute bytecode commitments and validate class IDs in a single pass.
328
+ const contractClasses = [];
329
+ for (const event of contractClassPublishedEvents){
330
+ const contractClass = await event.toContractClassPublicWithBytecodeCommitment();
331
+ const computedClassId = await computeContractClassId({
332
+ artifactHash: contractClass.artifactHash,
333
+ privateFunctionsRoot: contractClass.privateFunctionsRoot,
334
+ publicBytecodeCommitment: contractClass.publicBytecodeCommitment
335
+ });
336
+ if (!computedClassId.equals(contractClass.id)) {
337
+ this.log.warn(`Skipping contract class with mismatched id at block ${blockNum}. Claimed ${contractClass.id}, computed ${computedClassId}`, {
338
+ blockNum,
339
+ contractClassId: event.contractClassId.toString()
340
+ });
341
+ continue;
342
+ }
343
+ contractClasses.push(contractClass);
344
+ }
345
+ if (contractClasses.length > 0) {
346
+ contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
347
+ return await this.stores.contractClasses.addContractClasses(contractClasses, blockNum);
348
+ }
349
+ return true;
350
+ }
351
+ /**
352
+ * Extracts and stores contract instances out of ContractInstancePublished events emitted by the canonical deployer contract.
353
+ */ async updateDeployedContractInstances(allLogs, blockNum, operation) {
354
+ const allInstances = allLogs.filter((log)=>ContractInstancePublishedEvent.isContractInstancePublishedEvent(log)).map((log)=>ContractInstancePublishedEvent.fromLog(log)).map((e)=>e.toContractInstance());
355
+ // Verify that each instance's address matches the one derived from its fields if we're adding
356
+ const contractInstances = operation === 1 ? allInstances : await filterAsync(allInstances, async (instance)=>{
357
+ const computedAddress = await computeContractAddressFromInstance(instance);
358
+ if (!computedAddress.equals(instance.address)) {
359
+ this.log.warn(`Found contract instance with mismatched address at block ${blockNum}. Claimed ${instance.address} but computed ${computedAddress}.`, {
360
+ instanceAddress: instance.address.toString(),
361
+ computedAddress: computedAddress.toString(),
362
+ blockNum
363
+ });
364
+ return false;
365
+ }
366
+ return true;
367
+ });
368
+ if (contractInstances.length > 0) {
369
+ contractInstances.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance at ${c.address.toString()}`));
370
+ if (operation == 0) {
371
+ return await this.stores.contractInstances.addContractInstances(contractInstances, blockNum);
372
+ } else if (operation == 1) {
373
+ return await this.stores.contractInstances.deleteContractInstances(contractInstances);
374
+ }
375
+ }
376
+ return true;
377
+ }
378
+ /**
379
+ * Extracts and stores contract instance updates out of ContractInstanceUpdated events.
380
+ */ async updateUpdatedContractInstances(allLogs, timestamp, operation) {
381
+ const contractUpdates = allLogs.filter((log)=>ContractInstanceUpdatedEvent.isContractInstanceUpdatedEvent(log)).map((log)=>ContractInstanceUpdatedEvent.fromLog(log)).map((e)=>e.toContractInstanceUpdate());
382
+ if (contractUpdates.length > 0) {
383
+ contractUpdates.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance update at ${c.address.toString()}`));
384
+ if (operation == 0) {
385
+ return await this.stores.contractInstances.addContractInstanceUpdates(contractUpdates, timestamp);
386
+ } else if (operation == 1) {
387
+ return await this.stores.contractInstances.deleteContractInstanceUpdates(contractUpdates, timestamp);
388
+ }
389
+ }
390
+ return true;
391
+ }
392
+ }
@@ -0,0 +1,55 @@
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 syncDurationPerCheckpoint;
20
+ private syncBlockCount;
21
+ private manaPerBlock;
22
+ private txsPerBlock;
23
+ private syncDurationPerMessage;
24
+ private syncMessageCount;
25
+ private blockProposalTxTargetCount;
26
+ private checkpointL1InclusionDelay;
27
+ private checkpointPromotedCount;
28
+ private log;
29
+ private constructor();
30
+ static new(telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback): Promise<ArchiverInstrumentation>;
31
+ isEnabled(): boolean;
32
+ processNewProposedBlock(syncTimePerBlock: number, block: L2Block): void;
33
+ processNewCheckpointedBlocks(syncTimePerCheckpoint: number, blocks: L2Block[]): void;
34
+ processNewMessages(count: number, syncPerMessageMs: number): void;
35
+ processPrune(duration: number): void;
36
+ updateLastProvenCheckpoint(checkpoint: CheckpointData): void;
37
+ processProofsVerified(logs: {
38
+ proverId: string;
39
+ l2BlockNumber: bigint;
40
+ delay: bigint;
41
+ }[]): void;
42
+ updateL1BlockHeight(blockNumber: bigint): void;
43
+ recordBlockProposalTxTarget(target: string, usedTrace: boolean): void;
44
+ /** Records a checkpoint promoted from proposed (blob fetch skipped). */
45
+ processCheckpointPromoted(): void;
46
+ /**
47
+ * Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
48
+ */
49
+ processCheckpointL1Timing(data: {
50
+ slotNumber: SlotNumber;
51
+ l1Timestamp: bigint;
52
+ l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>;
53
+ }): void;
54
+ }
55
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5zdHJ1bWVudGF0aW9uLmQudHMiLCJzb3VyY2VSb290Ijoi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