@aztec/pxe 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 (408) hide show
  1. package/dest/access_scopes.d.ts +9 -0
  2. package/dest/access_scopes.d.ts.map +1 -0
  3. package/dest/access_scopes.js +6 -0
  4. package/dest/bin/check_oracle_version.js +105 -15
  5. package/dest/block_synchronizer/block_synchronizer.d.ts +45 -0
  6. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
  7. package/dest/block_synchronizer/block_synchronizer.js +153 -0
  8. package/dest/block_synchronizer/index.d.ts +2 -0
  9. package/dest/block_synchronizer/index.d.ts.map +1 -0
  10. package/dest/block_synchronizer/index.js +1 -0
  11. package/dest/config/index.d.ts +6 -4
  12. package/dest/config/index.d.ts.map +1 -1
  13. package/dest/config/index.js +17 -0
  14. package/dest/config/package_info.js +1 -1
  15. package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
  16. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
  17. package/dest/contract_function_simulator/benchmarked_node.js +77 -0
  18. package/dest/contract_function_simulator/contract_function_simulator.d.ts +76 -24
  19. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/contract_function_simulator.js +218 -73
  21. package/dest/contract_function_simulator/execution_note_cache.d.ts +21 -11
  22. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/execution_note_cache.js +49 -31
  24. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +1 -1
  25. package/dest/contract_function_simulator/execution_tagging_index_cache.js +1 -1
  26. package/dest/contract_function_simulator/hashed_values_cache.d.ts +2 -2
  27. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/index.d.ts +2 -2
  29. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  30. package/dest/contract_function_simulator/index.js +1 -1
  31. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +5 -4
  32. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +7 -4
  34. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +5 -4
  35. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +7 -6
  37. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +2 -2
  38. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  39. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -1
  40. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +6 -5
  41. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  42. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +7 -4
  43. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  44. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  45. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  46. package/dest/contract_function_simulator/oracle/interfaces.d.ts +27 -20
  47. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  48. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +4 -2
  49. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  50. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -1
  51. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +11 -7
  52. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  53. package/dest/contract_function_simulator/oracle/note_packing_utils.js +14 -10
  54. package/dest/contract_function_simulator/oracle/oracle.d.ts +13 -11
  55. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  56. package/dest/contract_function_simulator/oracle/oracle.js +86 -51
  57. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -27
  58. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  59. package/dest/contract_function_simulator/oracle/private_execution.js +2 -38
  60. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +54 -45
  61. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  62. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +105 -62
  63. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +114 -38
  64. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  65. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +214 -86
  66. package/dest/contract_function_simulator/pick_notes.d.ts +2 -2
  67. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  68. package/dest/contract_function_simulator/pick_notes.js +1 -1
  69. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +4 -4
  70. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  71. package/dest/contract_function_simulator/proxied_contract_data_source.js +23 -5
  72. package/dest/contract_logging.d.ts +22 -0
  73. package/dest/contract_logging.d.ts.map +1 -0
  74. package/dest/contract_logging.js +23 -0
  75. package/dest/contract_sync/contract_sync_service.d.ts +43 -0
  76. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  77. package/dest/contract_sync/contract_sync_service.js +97 -0
  78. package/dest/contract_sync/helpers.d.ts +29 -0
  79. package/dest/contract_sync/helpers.d.ts.map +1 -0
  80. package/dest/contract_sync/helpers.js +55 -0
  81. package/dest/debug/pxe_debug_utils.d.ts +45 -0
  82. package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
  83. package/dest/debug/pxe_debug_utils.js +48 -0
  84. package/dest/entrypoints/client/bundle/index.d.ts +4 -2
  85. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  86. package/dest/entrypoints/client/bundle/index.js +3 -1
  87. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  88. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  89. package/dest/entrypoints/client/bundle/utils.js +32 -9
  90. package/dest/entrypoints/client/lazy/index.d.ts +4 -2
  91. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  92. package/dest/entrypoints/client/lazy/index.js +3 -1
  93. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  94. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  95. package/dest/entrypoints/client/lazy/utils.js +33 -10
  96. package/dest/entrypoints/pxe_creation_options.d.ts +7 -3
  97. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  98. package/dest/entrypoints/server/index.d.ts +6 -2
  99. package/dest/entrypoints/server/index.d.ts.map +1 -1
  100. package/dest/entrypoints/server/index.js +5 -1
  101. package/dest/entrypoints/server/utils.d.ts +1 -1
  102. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  103. package/dest/entrypoints/server/utils.js +39 -16
  104. package/dest/error_enriching.d.ts +4 -4
  105. package/dest/error_enriching.d.ts.map +1 -1
  106. package/dest/error_enriching.js +6 -6
  107. package/dest/events/event_service.d.ts +15 -0
  108. package/dest/events/event_service.d.ts.map +1 -0
  109. package/dest/events/event_service.js +44 -0
  110. package/dest/events/index.d.ts +2 -0
  111. package/dest/events/index.d.ts.map +1 -0
  112. package/dest/events/index.js +1 -0
  113. package/dest/events/private_event_filter_validator.d.ts +9 -0
  114. package/dest/events/private_event_filter_validator.d.ts.map +1 -0
  115. package/dest/events/private_event_filter_validator.js +38 -0
  116. package/dest/job_coordinator/job_coordinator.d.ts +75 -0
  117. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
  118. package/dest/job_coordinator/job_coordinator.js +94 -0
  119. package/dest/logs/log_service.d.ts +29 -0
  120. package/dest/logs/log_service.d.ts.map +1 -0
  121. package/dest/logs/log_service.js +118 -0
  122. package/dest/notes/index.d.ts +2 -0
  123. package/dest/notes/index.d.ts.map +1 -0
  124. package/dest/notes/index.js +1 -0
  125. package/dest/notes/note_service.d.ts +49 -0
  126. package/dest/notes/note_service.d.ts.map +1 -0
  127. package/dest/notes/note_service.js +148 -0
  128. package/dest/notes_filter.d.ts +25 -0
  129. package/dest/notes_filter.d.ts.map +1 -0
  130. package/dest/notes_filter.js +4 -0
  131. package/dest/oracle_version.d.ts +3 -3
  132. package/dest/oracle_version.d.ts.map +1 -1
  133. package/dest/oracle_version.js +4 -3
  134. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  135. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  136. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  137. package/dest/private_kernel/hints/index.d.ts +3 -3
  138. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  139. package/dest/private_kernel/hints/index.js +2 -2
  140. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
  141. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  142. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +16 -10
  143. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  144. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  145. package/dest/private_kernel/private_kernel_execution_prover.js +16 -17
  146. package/dest/private_kernel/private_kernel_oracle.d.ts +26 -25
  147. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  148. package/dest/private_kernel/private_kernel_oracle.js +94 -2
  149. package/dest/pxe.d.ts +112 -102
  150. package/dest/pxe.d.ts.map +1 -1
  151. package/dest/pxe.js +255 -252
  152. package/dest/storage/address_store/address_store.d.ts +11 -0
  153. package/dest/storage/address_store/address_store.d.ts.map +1 -0
  154. package/dest/storage/{address_data_provider/address_data_provider.js → address_store/address_store.js} +13 -12
  155. package/dest/storage/address_store/index.d.ts +2 -0
  156. package/dest/storage/address_store/index.d.ts.map +1 -0
  157. package/dest/storage/address_store/index.js +1 -0
  158. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +17 -0
  159. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
  160. package/dest/storage/{sync_data_provider/sync_data_provider.js → anchor_block_store/anchor_block_store.js} +10 -10
  161. package/dest/storage/{sync_data_provider → anchor_block_store}/index.d.ts +2 -2
  162. package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
  163. package/dest/storage/anchor_block_store/index.js +1 -0
  164. package/dest/storage/capsule_store/capsule_store.d.ts +72 -0
  165. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
  166. package/dest/storage/capsule_store/capsule_store.js +253 -0
  167. package/dest/storage/capsule_store/index.d.ts +2 -0
  168. package/dest/storage/capsule_store/index.d.ts.map +1 -0
  169. package/dest/storage/capsule_store/index.js +1 -0
  170. package/dest/storage/contract_store/contract_store.d.ts +93 -0
  171. package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
  172. package/dest/storage/contract_store/contract_store.js +309 -0
  173. package/dest/storage/contract_store/index.d.ts +2 -0
  174. package/dest/storage/contract_store/index.d.ts.map +1 -0
  175. package/dest/storage/contract_store/index.js +1 -0
  176. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.d.ts +1 -1
  177. package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
  178. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.js +1 -1
  179. package/dest/storage/index.d.ts +8 -8
  180. package/dest/storage/index.d.ts.map +1 -1
  181. package/dest/storage/index.js +7 -7
  182. package/dest/storage/metadata.d.ts +1 -1
  183. package/dest/storage/metadata.js +1 -1
  184. package/dest/storage/note_store/index.d.ts +3 -0
  185. package/dest/storage/note_store/index.d.ts.map +1 -0
  186. package/dest/storage/note_store/index.js +2 -0
  187. package/dest/storage/note_store/note_store.d.ts +83 -0
  188. package/dest/storage/note_store/note_store.d.ts.map +1 -0
  189. package/dest/storage/note_store/note_store.js +343 -0
  190. package/dest/storage/note_store/stored_note.d.ts +16 -0
  191. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  192. package/dest/storage/note_store/stored_note.js +43 -0
  193. package/dest/storage/private_event_store/private_event_store.d.ts +91 -0
  194. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
  195. package/dest/storage/private_event_store/private_event_store.js +273 -0
  196. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  197. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  198. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  199. package/dest/storage/tagging_store/index.d.ts +4 -0
  200. package/dest/storage/tagging_store/index.d.ts.map +1 -0
  201. package/dest/storage/tagging_store/index.js +3 -0
  202. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +28 -0
  203. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
  204. package/dest/storage/tagging_store/recipient_tagging_store.js +111 -0
  205. package/dest/storage/tagging_store/sender_address_book_store.d.ts +14 -0
  206. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -0
  207. package/dest/storage/tagging_store/sender_address_book_store.js +36 -0
  208. package/dest/storage/tagging_store/sender_tagging_store.d.ts +77 -0
  209. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
  210. package/dest/storage/tagging_store/sender_tagging_store.js +348 -0
  211. package/dest/tagging/constants.d.ts +2 -2
  212. package/dest/tagging/constants.d.ts.map +1 -1
  213. package/dest/tagging/constants.js +10 -2
  214. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  215. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  216. package/dest/tagging/get_all_logs_by_tags.js +60 -0
  217. package/dest/tagging/index.d.ts +16 -6
  218. package/dest/tagging/index.d.ts.map +1 -1
  219. package/dest/tagging/index.js +15 -5
  220. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +15 -0
  221. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -0
  222. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +99 -0
  223. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
  224. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
  225. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
  226. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +15 -0
  227. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -0
  228. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +32 -0
  229. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +21 -0
  230. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
  231. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +74 -0
  232. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +11 -0
  233. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
  234. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +29 -0
  235. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +21 -0
  236. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
  237. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +60 -0
  238. package/package.json +28 -19
  239. package/src/access_scopes.ts +9 -0
  240. package/src/bin/check_oracle_version.ts +131 -20
  241. package/src/block_synchronizer/block_synchronizer.ts +178 -0
  242. package/src/block_synchronizer/index.ts +1 -0
  243. package/src/config/index.ts +17 -3
  244. package/src/config/package_info.ts +1 -1
  245. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  246. package/src/contract_function_simulator/contract_function_simulator.ts +380 -104
  247. package/src/contract_function_simulator/execution_note_cache.ts +51 -28
  248. package/src/contract_function_simulator/execution_tagging_index_cache.ts +1 -1
  249. package/src/contract_function_simulator/hashed_values_cache.ts +1 -1
  250. package/src/contract_function_simulator/index.ts +1 -1
  251. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +7 -3
  252. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +6 -5
  253. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -1
  254. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +6 -3
  255. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  256. package/src/contract_function_simulator/oracle/interfaces.ts +32 -17
  257. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +1 -1
  258. package/src/contract_function_simulator/oracle/note_packing_utils.ts +27 -13
  259. package/src/contract_function_simulator/oracle/oracle.ts +101 -47
  260. package/src/contract_function_simulator/oracle/private_execution.ts +2 -68
  261. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +154 -97
  262. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +350 -91
  263. package/src/contract_function_simulator/pick_notes.ts +1 -1
  264. package/src/contract_function_simulator/proxied_contract_data_source.ts +24 -7
  265. package/src/contract_logging.ts +39 -0
  266. package/src/contract_sync/contract_sync_service.ts +152 -0
  267. package/src/contract_sync/helpers.ts +98 -0
  268. package/src/debug/pxe_debug_utils.ts +93 -0
  269. package/src/entrypoints/client/bundle/index.ts +3 -1
  270. package/src/entrypoints/client/bundle/utils.ts +24 -17
  271. package/src/entrypoints/client/lazy/index.ts +3 -1
  272. package/src/entrypoints/client/lazy/utils.ts +25 -18
  273. package/src/entrypoints/pxe_creation_options.ts +6 -2
  274. package/src/entrypoints/server/index.ts +5 -1
  275. package/src/entrypoints/server/utils.ts +33 -41
  276. package/src/error_enriching.ts +7 -15
  277. package/src/events/event_service.ts +71 -0
  278. package/src/events/index.ts +1 -0
  279. package/src/events/private_event_filter_validator.ts +46 -0
  280. package/src/job_coordinator/job_coordinator.ts +150 -0
  281. package/src/logs/log_service.ts +208 -0
  282. package/src/notes/index.ts +1 -0
  283. package/src/notes/note_service.ts +196 -0
  284. package/src/notes_filter.ts +26 -0
  285. package/src/oracle_version.ts +4 -3
  286. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  287. package/src/private_kernel/hints/index.ts +2 -2
  288. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +40 -29
  289. package/src/private_kernel/private_kernel_execution_prover.ts +20 -18
  290. package/src/private_kernel/private_kernel_oracle.ts +118 -37
  291. package/src/pxe.ts +395 -343
  292. package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +16 -16
  293. package/src/storage/address_store/index.ts +1 -0
  294. package/src/storage/{sync_data_provider/sync_data_provider.ts → anchor_block_store/anchor_block_store.ts} +10 -11
  295. package/src/storage/anchor_block_store/index.ts +1 -0
  296. package/src/storage/capsule_store/capsule_store.ts +315 -0
  297. package/src/storage/capsule_store/index.ts +1 -0
  298. package/src/storage/contract_store/contract_store.ts +429 -0
  299. package/src/storage/contract_store/index.ts +1 -0
  300. package/src/storage/{contract_data_provider → contract_store}/private_functions_tree.ts +1 -1
  301. package/src/storage/index.ts +7 -7
  302. package/src/storage/metadata.ts +1 -1
  303. package/src/storage/note_store/index.ts +2 -0
  304. package/src/storage/note_store/note_store.ts +418 -0
  305. package/src/storage/note_store/stored_note.ts +48 -0
  306. package/src/storage/private_event_store/private_event_store.ts +384 -0
  307. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  308. package/src/storage/tagging_store/index.ts +3 -0
  309. package/src/storage/tagging_store/recipient_tagging_store.ts +139 -0
  310. package/src/storage/tagging_store/sender_address_book_store.ts +48 -0
  311. package/src/storage/tagging_store/sender_tagging_store.ts +429 -0
  312. package/src/tagging/constants.ts +10 -2
  313. package/src/tagging/get_all_logs_by_tags.ts +92 -0
  314. package/src/tagging/index.ts +18 -5
  315. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +143 -0
  316. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
  317. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +49 -0
  318. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +99 -0
  319. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +36 -0
  320. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +84 -0
  321. package/dest/contract_function_simulator/execution_data_provider.d.ts +0 -265
  322. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +0 -1
  323. package/dest/contract_function_simulator/execution_data_provider.js +0 -14
  324. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  325. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  326. package/dest/contract_function_simulator/proxied_node.js +0 -27
  327. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +0 -122
  328. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +0 -1
  329. package/dest/contract_function_simulator/pxe_oracle_interface.js +0 -694
  330. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  331. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  332. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  333. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
  334. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -45
  335. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  336. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
  337. package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -11
  338. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +0 -1
  339. package/dest/storage/address_data_provider/index.d.ts +0 -2
  340. package/dest/storage/address_data_provider/index.d.ts.map +0 -1
  341. package/dest/storage/address_data_provider/index.js +0 -1
  342. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -25
  343. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
  344. package/dest/storage/capsule_data_provider/capsule_data_provider.js +0 -118
  345. package/dest/storage/capsule_data_provider/index.d.ts +0 -2
  346. package/dest/storage/capsule_data_provider/index.d.ts.map +0 -1
  347. package/dest/storage/capsule_data_provider/index.js +0 -1
  348. package/dest/storage/contract_data_provider/contract_data_provider.d.ts +0 -64
  349. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +0 -1
  350. package/dest/storage/contract_data_provider/contract_data_provider.js +0 -193
  351. package/dest/storage/contract_data_provider/index.d.ts +0 -2
  352. package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
  353. package/dest/storage/contract_data_provider/index.js +0 -1
  354. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
  355. package/dest/storage/note_data_provider/index.d.ts +0 -3
  356. package/dest/storage/note_data_provider/index.d.ts.map +0 -1
  357. package/dest/storage/note_data_provider/index.js +0 -2
  358. package/dest/storage/note_data_provider/note_data_provider.d.ts +0 -83
  359. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +0 -1
  360. package/dest/storage/note_data_provider/note_data_provider.js +0 -311
  361. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +0 -37
  362. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +0 -1
  363. package/dest/storage/private_event_data_provider/private_event_data_provider.js +0 -105
  364. package/dest/storage/sync_data_provider/index.d.ts.map +0 -1
  365. package/dest/storage/sync_data_provider/index.js +0 -1
  366. package/dest/storage/sync_data_provider/sync_data_provider.d.ts +0 -10
  367. package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +0 -1
  368. package/dest/storage/tagging_data_provider/index.d.ts +0 -2
  369. package/dest/storage/tagging_data_provider/index.d.ts.map +0 -1
  370. package/dest/storage/tagging_data_provider/index.js +0 -1
  371. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +0 -40
  372. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +0 -1
  373. package/dest/storage/tagging_data_provider/tagging_data_provider.js +0 -89
  374. package/dest/synchronizer/index.d.ts +0 -2
  375. package/dest/synchronizer/index.d.ts.map +0 -1
  376. package/dest/synchronizer/index.js +0 -1
  377. package/dest/synchronizer/synchronizer.d.ts +0 -35
  378. package/dest/synchronizer/synchronizer.d.ts.map +0 -1
  379. package/dest/synchronizer/synchronizer.js +0 -101
  380. package/dest/tagging/siloed_tag.d.ts +0 -14
  381. package/dest/tagging/siloed_tag.d.ts.map +0 -1
  382. package/dest/tagging/siloed_tag.js +0 -20
  383. package/dest/tagging/tag.d.ts +0 -12
  384. package/dest/tagging/tag.d.ts.map +0 -1
  385. package/dest/tagging/tag.js +0 -17
  386. package/dest/tagging/utils.d.ts +0 -18
  387. package/dest/tagging/utils.d.ts.map +0 -1
  388. package/dest/tagging/utils.js +0 -24
  389. package/src/contract_function_simulator/execution_data_provider.ts +0 -333
  390. package/src/contract_function_simulator/proxied_node.ts +0 -33
  391. package/src/contract_function_simulator/pxe_oracle_interface.ts +0 -1008
  392. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -132
  393. package/src/storage/address_data_provider/index.ts +0 -1
  394. package/src/storage/capsule_data_provider/capsule_data_provider.ts +0 -147
  395. package/src/storage/capsule_data_provider/index.ts +0 -1
  396. package/src/storage/contract_data_provider/contract_data_provider.ts +0 -277
  397. package/src/storage/contract_data_provider/index.ts +0 -1
  398. package/src/storage/note_data_provider/index.ts +0 -2
  399. package/src/storage/note_data_provider/note_data_provider.ts +0 -399
  400. package/src/storage/private_event_data_provider/private_event_data_provider.ts +0 -143
  401. package/src/storage/sync_data_provider/index.ts +0 -1
  402. package/src/storage/tagging_data_provider/index.ts +0 -1
  403. package/src/storage/tagging_data_provider/tagging_data_provider.ts +0 -120
  404. package/src/synchronizer/index.ts +0 -1
  405. package/src/synchronizer/synchronizer.ts +0 -120
  406. package/src/tagging/siloed_tag.ts +0 -22
  407. package/src/tagging/tag.ts +0 -16
  408. package/src/tagging/utils.ts +0 -31
@@ -0,0 +1,429 @@
1
+ import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
2
+ import type { DirectionalAppTaggingSecret, PreTag } from '@aztec/stdlib/logs';
3
+ import { TxHash } from '@aztec/stdlib/tx';
4
+
5
+ import type { StagedStore } from '../../job_coordinator/job_coordinator.js';
6
+ import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../../tagging/constants.js';
7
+
8
+ /**
9
+ * Data provider of tagging data used when syncing the sender tagging indexes. The recipient counterpart of this class
10
+ * is called RecipientTaggingStore. We have the data stores separate for sender and recipient because
11
+ * the algorithms are completely disjoint and there is not data reuse between the two.
12
+ */
13
+ export class SenderTaggingStore implements StagedStore {
14
+ readonly storeName = 'sender_tagging';
15
+
16
+ #store: AztecAsyncKVStore;
17
+
18
+ // Stores the pending indexes for each directional app tagging secret. Pending here means that the tx that contained
19
+ // the private logs with tags corresponding to these indexes has not been finalized yet.
20
+ //
21
+ // We don't store just the highest index because if their transaction is dropped we'd then need the information about
22
+ // the lower pending indexes. For each secret-tx pair however we only store the largest index used in that tx, since
23
+ // the smaller ones are irrelevant due to tx atomicity.
24
+ //
25
+ // TODO(#17615): This assumes no logs are used in the non-revertible phase.
26
+ //
27
+ // directional app tagging secret => { pending index, txHash }[]
28
+ #pendingIndexes: AztecAsyncMap<string, { index: number; txHash: string }[]>;
29
+
30
+ // jobId => directional app tagging secret => { pending index, txHash }[]
31
+ #pendingIndexesForJob: Map<string, Map<string, { index: number; txHash: string }[]>>;
32
+
33
+ // Stores the last (highest) finalized index for each directional app tagging secret. We care only about the last
34
+ // index because unlike the pending indexes, it will never happen that a finalized index would be removed and hence
35
+ // we don't need to store the history.
36
+ //
37
+ // directional app tagging secret => highest finalized index
38
+ #lastFinalizedIndexes: AztecAsyncMap<string, number>;
39
+
40
+ // jobId => directional app tagging secret => highest finalized index
41
+ #lastFinalizedIndexesForJob: Map<string, Map<string, number>>;
42
+
43
+ constructor(store: AztecAsyncKVStore) {
44
+ this.#store = store;
45
+
46
+ this.#pendingIndexes = this.#store.openMap('pending_indexes');
47
+ this.#lastFinalizedIndexes = this.#store.openMap('last_finalized_indexes');
48
+
49
+ this.#pendingIndexesForJob = new Map();
50
+ this.#lastFinalizedIndexesForJob = new Map();
51
+ }
52
+
53
+ #getPendingIndexesForJob(jobId: string): Map<string, { index: number; txHash: string }[]> {
54
+ let pendingIndexesForJob = this.#pendingIndexesForJob.get(jobId);
55
+ if (!pendingIndexesForJob) {
56
+ pendingIndexesForJob = new Map();
57
+ this.#pendingIndexesForJob.set(jobId, pendingIndexesForJob);
58
+ }
59
+ return pendingIndexesForJob;
60
+ }
61
+
62
+ #getLastFinalizedIndexesForJob(jobId: string): Map<string, number> {
63
+ let jobStagedLastFinalizedIndexes = this.#lastFinalizedIndexesForJob.get(jobId);
64
+ if (!jobStagedLastFinalizedIndexes) {
65
+ jobStagedLastFinalizedIndexes = new Map();
66
+ this.#lastFinalizedIndexesForJob.set(jobId, jobStagedLastFinalizedIndexes);
67
+ }
68
+ return jobStagedLastFinalizedIndexes;
69
+ }
70
+
71
+ async #readPendingIndexes(jobId: string, secret: string): Promise<{ index: number; txHash: string }[]> {
72
+ // Always issue DB read to keep IndexedDB transaction alive (they auto-commit when a new micro-task starts and there
73
+ // are no pending read requests). The staged value still takes precedence if it exists.
74
+ const dbValue = await this.#pendingIndexes.getAsync(secret);
75
+ const staged = this.#getPendingIndexesForJob(jobId).get(secret);
76
+ return staged !== undefined ? staged : (dbValue ?? []);
77
+ }
78
+
79
+ #writePendingIndexes(jobId: string, secret: string, pendingIndexes: { index: number; txHash: string }[]) {
80
+ this.#getPendingIndexesForJob(jobId).set(secret, pendingIndexes);
81
+ }
82
+
83
+ async #readLastFinalizedIndex(jobId: string, secret: string): Promise<number | undefined> {
84
+ // Always issue DB read to keep IndexedDB transaction alive (they auto-commit when a new micro-task starts and there
85
+ // are no pending read requests). The staged value still takes precedence if it exists.
86
+ const dbValue = await this.#lastFinalizedIndexes.getAsync(secret);
87
+ const staged = this.#getLastFinalizedIndexesForJob(jobId).get(secret);
88
+ return staged ?? dbValue;
89
+ }
90
+
91
+ #writeLastFinalizedIndex(jobId: string, secret: string, lastFinalizedIndex: number) {
92
+ this.#getLastFinalizedIndexesForJob(jobId).set(secret, lastFinalizedIndex);
93
+ }
94
+
95
+ /**
96
+ * Writes all job-specific in-memory data to persistent storage.
97
+ *
98
+ * @remark This method must run in a DB transaction context. It's designed to be called from JobCoordinator#commitJob.
99
+ */
100
+ async commit(jobId: string): Promise<void> {
101
+ const pendingIndexesForJob = this.#pendingIndexesForJob.get(jobId);
102
+ if (pendingIndexesForJob) {
103
+ for (const [secret, pendingIndexes] of pendingIndexesForJob.entries()) {
104
+ if (pendingIndexes.length === 0) {
105
+ await this.#pendingIndexes.delete(secret);
106
+ } else {
107
+ await this.#pendingIndexes.set(secret, pendingIndexes);
108
+ }
109
+ }
110
+ }
111
+
112
+ const lastFinalizedIndexesForJob = this.#lastFinalizedIndexesForJob.get(jobId);
113
+ if (lastFinalizedIndexesForJob) {
114
+ for (const [secret, lastFinalizedIndex] of lastFinalizedIndexesForJob.entries()) {
115
+ await this.#lastFinalizedIndexes.set(secret, lastFinalizedIndex);
116
+ }
117
+ }
118
+
119
+ return this.discardStaged(jobId);
120
+ }
121
+
122
+ discardStaged(jobId: string): Promise<void> {
123
+ this.#pendingIndexesForJob.delete(jobId);
124
+ this.#lastFinalizedIndexesForJob.delete(jobId);
125
+ return Promise.resolve();
126
+ }
127
+
128
+ /**
129
+ * Stores pending indexes.
130
+ * @remarks Ignores the index if the same preTag + txHash combination already exists in the db with the same index.
131
+ * This is expected to happen because whenever we start sync we start from the last finalized index and we can have
132
+ * pending indexes already stored from previous syncs.
133
+ * @param preTags - The pre-tags containing the directional app tagging secrets and the indexes that are to be
134
+ * stored in the db.
135
+ * @param txHash - The tx in which the pretags were used in private logs.
136
+ * @param jobId - job context for staged writes to this store. See `JobCoordinator` for more details.
137
+ * @throws If any two pre-tags contain the same directional app tagging secret. This is enforced because we care
138
+ * only about the highest index for a given secret that was used in the tx. Hence this check is a good way to catch
139
+ * bugs.
140
+ * @throws If the newly stored pending index is further than window length from the highest finalized index for the
141
+ * same secret. This is enforced in order to give a guarantee to a recipient that he doesn't need to look further than
142
+ * window length ahead of the highest finalized index.
143
+ * @throws If a secret + txHash pair already exists in the db with a different index value. It should never happen
144
+ * that we would attempt to store a different index for a given secret-txHash pair because we always store just the
145
+ * highest index for a given secret-txHash pair. Hence this is a good way to catch bugs.
146
+ * @throws If the newly stored pending index is lower than or equal to the last finalized index for the same secret.
147
+ * This is enforced because this should never happen if the syncing is done correctly as we look for logs from higher
148
+ * indexes than finalized ones.
149
+ */
150
+ storePendingIndexes(preTags: PreTag[], txHash: TxHash, jobId: string): Promise<void> {
151
+ if (preTags.length === 0) {
152
+ return Promise.resolve();
153
+ }
154
+
155
+ // The secrets in pre-tags should be unique because we always store just the highest index per given secret-txHash
156
+ // pair. Below we check that this is the case.
157
+ const secretsSet = new Set(preTags.map(preTag => preTag.secret.toString()));
158
+ if (secretsSet.size !== preTags.length) {
159
+ return Promise.reject(new Error(`Duplicate secrets found when storing pending indexes`));
160
+ }
161
+
162
+ const txHashStr = txHash.toString();
163
+
164
+ return this.#store.transactionAsync(async () => {
165
+ // Prefetch all data, start reads during iteration to keep IndexedDB transaction alive
166
+ const preTagReadPromises = preTags.map(({ secret, index }) => {
167
+ const secretStr = secret.toString();
168
+ return {
169
+ secret,
170
+ secretStr,
171
+ index,
172
+ pending: this.#readPendingIndexes(jobId, secretStr),
173
+ finalized: this.#readLastFinalizedIndex(jobId, secretStr),
174
+ };
175
+ });
176
+
177
+ // Await all reads together
178
+ const preTagData = await Promise.all(
179
+ preTagReadPromises.map(async item => ({
180
+ ...item,
181
+ pendingData: await item.pending,
182
+ finalizedIndex: await item.finalized,
183
+ })),
184
+ );
185
+
186
+ // Process in memory and validate
187
+ for (const { secretStr, index, pendingData, finalizedIndex } of preTagData) {
188
+ // First we check that for any secret the highest used index in tx is not further than window length from
189
+ // the highest finalized index.
190
+ if (index > (finalizedIndex ?? 0) + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN) {
191
+ throw new Error(
192
+ `Highest used index ${index} is further than window length from the highest finalized index ${finalizedIndex ?? 0}.
193
+ Tagging window length ${UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN} is configured too low. Contact the Aztec team
194
+ to increase it!`,
195
+ );
196
+ }
197
+
198
+ // Throw if the new pending index is lower than or equal to the last finalized index
199
+ if (finalizedIndex !== undefined && index <= finalizedIndex) {
200
+ throw new Error(
201
+ `Cannot store pending index ${index} for secret ${secretStr}: ` +
202
+ `it is lower than or equal to the last finalized index ${finalizedIndex}`,
203
+ );
204
+ }
205
+
206
+ // Check if this secret + txHash combination already exists
207
+ const existingForSecretAndTx = pendingData.find(entry => entry.txHash === txHashStr);
208
+
209
+ if (existingForSecretAndTx) {
210
+ // If it exists with a different index, throw an error
211
+ if (existingForSecretAndTx.index !== index) {
212
+ throw new Error(
213
+ `Cannot store index ${index} for secret ${secretStr} and txHash ${txHashStr}: ` +
214
+ `a different index ${existingForSecretAndTx.index} already exists for this secret-txHash pair`,
215
+ );
216
+ }
217
+ // If it exists with the same index, ignore the update (no-op)
218
+ } else {
219
+ // If it doesn't exist, add it
220
+ this.#writePendingIndexes(jobId, secretStr, [...pendingData, { index, txHash: txHashStr }]);
221
+ }
222
+ }
223
+ });
224
+ }
225
+
226
+ /**
227
+ * Returns the transaction hashes of all pending transactions that contain indexes within a specified range
228
+ * for a given directional app tagging secret.
229
+ * @param secret - The directional app tagging secret to query pending indexes for.
230
+ * @param startIndex - The lower bound of the index range (inclusive).
231
+ * @param endIndex - The upper bound of the index range (exclusive).
232
+ * @returns An array of unique transaction hashes for pending transactions that contain indexes in the range
233
+ * [startIndex, endIndex). Returns an empty array if no pending indexes exist in the range.
234
+ */
235
+ getTxHashesOfPendingIndexes(
236
+ secret: DirectionalAppTaggingSecret,
237
+ startIndex: number,
238
+ endIndex: number,
239
+ jobId: string,
240
+ ): Promise<TxHash[]> {
241
+ return this.#store.transactionAsync(async () => {
242
+ const existing = await this.#readPendingIndexes(jobId, secret.toString());
243
+ const txHashes = existing
244
+ .filter(entry => entry.index >= startIndex && entry.index < endIndex)
245
+ .map(entry => entry.txHash);
246
+ return Array.from(new Set(txHashes)).map(TxHash.fromString);
247
+ });
248
+ }
249
+
250
+ /**
251
+ * Returns the last (highest) finalized index for a given secret.
252
+ * @param secret - The secret to get the last finalized index for.
253
+ * @returns The last (highest) finalized index for the given secret.
254
+ */
255
+ getLastFinalizedIndex(secret: DirectionalAppTaggingSecret, jobId: string): Promise<number | undefined> {
256
+ return this.#store.transactionAsync(() => this.#readLastFinalizedIndex(jobId, secret.toString()));
257
+ }
258
+
259
+ /**
260
+ * Returns the last used index for a given directional app tagging secret, considering both finalized and pending
261
+ * indexes.
262
+ * @param secret - The directional app tagging secret to query the last used index for.
263
+ * @returns The last used index.
264
+ */
265
+ getLastUsedIndex(secret: DirectionalAppTaggingSecret, jobId: string): Promise<number | undefined> {
266
+ const secretStr = secret.toString();
267
+
268
+ return this.#store.transactionAsync(async () => {
269
+ const pendingPromise = this.#readPendingIndexes(jobId, secretStr);
270
+ const finalizedPromise = this.#readLastFinalizedIndex(jobId, secretStr);
271
+
272
+ const [pendingTxScopedIndexes, lastFinalized] = await Promise.all([pendingPromise, finalizedPromise]);
273
+ const pendingIndexes = pendingTxScopedIndexes.map(entry => entry.index);
274
+
275
+ if (pendingTxScopedIndexes.length === 0) {
276
+ return lastFinalized;
277
+ }
278
+
279
+ // As the last used index we return the highest one from the pending indexes. Note that this value will be always
280
+ // higher than the last finalized index because we prune lower pending indexes when a tx is finalized.
281
+ return Math.max(...pendingIndexes);
282
+ });
283
+ }
284
+
285
+ /**
286
+ * Drops all pending indexes corresponding to the given transaction hashes.
287
+ */
288
+ dropPendingIndexes(txHashes: TxHash[], jobId: string): Promise<void> {
289
+ if (txHashes.length === 0) {
290
+ return Promise.resolve();
291
+ }
292
+
293
+ const txHashStrings = new Set<string>(txHashes.map(txHash => txHash.toString()));
294
+
295
+ return this.#store.transactionAsync(async () => {
296
+ // Prefetch all data, start reads during iteration to keep IndexedDB transaction alive
297
+ const secretReadPromises: Map<string, Promise<{ index: number; txHash: string }[]>> = new Map();
298
+
299
+ for await (const secret of this.#pendingIndexes.keysAsync()) {
300
+ secretReadPromises.set(secret, this.#readPendingIndexes(jobId, secret));
301
+ }
302
+
303
+ // Add staged-only secrets (sync, no DB)
304
+ for (const secret of this.#getPendingIndexesForJob(jobId).keys()) {
305
+ if (!secretReadPromises.has(secret)) {
306
+ secretReadPromises.set(secret, Promise.resolve(this.#getPendingIndexesForJob(jobId).get(secret) ?? []));
307
+ }
308
+ }
309
+
310
+ // Await all reads together
311
+ const secrets = [...secretReadPromises.keys()];
312
+ const pendingDataResults = await Promise.all(secretReadPromises.values());
313
+
314
+ // Process in memory
315
+ for (let i = 0; i < secrets.length; i++) {
316
+ const secret = secrets[i];
317
+ const pendingData = pendingDataResults[i];
318
+
319
+ if (pendingData && pendingData.length > 0) {
320
+ const filtered = pendingData.filter(item => !txHashStrings.has(item.txHash));
321
+ if (filtered.length === 0) {
322
+ this.#writePendingIndexes(jobId, secret, []);
323
+ } else if (filtered.length !== pendingData.length) {
324
+ // Some items were filtered out, so update the pending data
325
+ this.#writePendingIndexes(jobId, secret, filtered);
326
+ }
327
+ // else: No items were filtered out (txHashes not found for this secret) --> no-op
328
+ }
329
+ }
330
+ });
331
+ }
332
+
333
+ /**
334
+ * Updates pending indexes corresponding to the given transaction hashes to be finalized and prunes any lower pending
335
+ * indexes.
336
+ */
337
+ finalizePendingIndexes(txHashes: TxHash[], jobId: string): Promise<void> {
338
+ if (txHashes.length === 0) {
339
+ return Promise.resolve();
340
+ }
341
+
342
+ const txHashStrings = new Set(txHashes.map(tx => tx.toString()));
343
+
344
+ return this.#store.transactionAsync(async () => {
345
+ // Prefetch all data, start reads during iteration to keep IndexedDB transaction alive
346
+ const secretDataPromises: Map<
347
+ string,
348
+ { pending: Promise<{ index: number; txHash: string }[]>; finalized: Promise<number | undefined> }
349
+ > = new Map();
350
+
351
+ for await (const secret of this.#pendingIndexes.keysAsync()) {
352
+ secretDataPromises.set(secret, {
353
+ pending: this.#readPendingIndexes(jobId, secret),
354
+ finalized: this.#readLastFinalizedIndex(jobId, secret),
355
+ });
356
+ }
357
+
358
+ // Add staged-only secrets (sync, no DB)
359
+ for (const secret of this.#getPendingIndexesForJob(jobId).keys()) {
360
+ if (!secretDataPromises.has(secret)) {
361
+ secretDataPromises.set(secret, {
362
+ pending: Promise.resolve(this.#getPendingIndexesForJob(jobId).get(secret) ?? []),
363
+ finalized: Promise.resolve(this.#getLastFinalizedIndexesForJob(jobId).get(secret)),
364
+ });
365
+ }
366
+ }
367
+
368
+ // Await all reads together
369
+ const secrets = [...secretDataPromises.keys()];
370
+ const dataResults = await Promise.all(
371
+ secrets.map(async secret => ({
372
+ secret,
373
+ pendingData: await secretDataPromises.get(secret)!.pending,
374
+ lastFinalized: await secretDataPromises.get(secret)!.finalized,
375
+ })),
376
+ );
377
+
378
+ // Process all txHashes for each secret in memory
379
+ for (const { secret, pendingData, lastFinalized } of dataResults) {
380
+ if (!pendingData || pendingData.length === 0) {
381
+ continue;
382
+ }
383
+
384
+ let currentPending = pendingData;
385
+ let currentFinalized = lastFinalized;
386
+
387
+ // Process all txHashes for this secret
388
+ for (const txHashStr of txHashStrings) {
389
+ const matchingIndexes = currentPending.filter(item => item.txHash === txHashStr).map(item => item.index);
390
+ if (matchingIndexes.length === 0) {
391
+ continue;
392
+ }
393
+
394
+ if (matchingIndexes.length > 1) {
395
+ // We should always just store the highest pending index for a given tx hash and secret because the lower
396
+ // values are irrelevant.
397
+ throw new Error(`Multiple pending indexes found for tx hash ${txHashStr} and secret ${secret}`);
398
+ }
399
+
400
+ const newFinalized = matchingIndexes[0];
401
+
402
+ if (newFinalized < (currentFinalized ?? 0)) {
403
+ // This should never happen because when last finalized index was finalized we should have pruned the lower
404
+ // pending indexes.
405
+ throw new Error(
406
+ `New finalized index ${newFinalized} is smaller than the current last finalized index ${currentFinalized}`,
407
+ );
408
+ }
409
+
410
+ currentFinalized = newFinalized;
411
+
412
+ // When we add pending indexes, we ensure they are higher than the last finalized index. However, because we
413
+ // cannot control the order in which transactions are finalized, there may be pending indexes that are now
414
+ // obsolete because they are lower than the most recently finalized index. For this reason, we prune these
415
+ // outdated pending indexes.
416
+ currentPending = currentPending.filter(item => item.index > currentFinalized!);
417
+ }
418
+
419
+ // Write final state if changed
420
+ if (currentFinalized !== lastFinalized) {
421
+ this.#writeLastFinalizedIndex(jobId, secret, currentFinalized!);
422
+ }
423
+ if (currentPending !== pendingData) {
424
+ this.#writePendingIndexes(jobId, secret, currentPending);
425
+ }
426
+ }
427
+ });
428
+ }
429
+ }
@@ -1,2 +1,10 @@
1
- // Half the size of the window we slide over the tagging indexes.
2
- export const WINDOW_HALF_SIZE = 10;
1
+ // This window has to be as large as the largest expected number of logs emitted in a tx for a given directional app
2
+ // tagging secret. If we get more tag indexes consumed than this window, an error is thrown in `PXE::proveTx` function.
3
+ // This is set to a larger value than MAX_PRIVATE_LOGS_PER_TX (currently 64) because there could be more than
4
+ // MAX_PRIVATE_LOGS_PER_TX indexes consumed in case the logs are squashed. This happens when the log contains a note
5
+ // and the note is nullified in the same tx.
6
+ //
7
+ // Having a large window significantly slowed down `e2e_l1_with_wall_time` test as there we perform sync for more than
8
+ // 1000 secrets. For this reason we set it to a relatively low value of 20. 20 should be sufficient for all the use
9
+ // cases.
10
+ export const UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN = 20;
@@ -0,0 +1,92 @@
1
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2
+ import type { BlockHash } from '@aztec/stdlib/block';
3
+ import { MAX_LOGS_PER_TAG, MAX_RPC_LEN } from '@aztec/stdlib/interfaces/api-limit';
4
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
5
+ import type { SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
6
+
7
+ /**
8
+ * Generic pagination helper that fetches all pages of results.
9
+ * @param numTags - The number of tags being queried (determines result array size).
10
+ * @param fetchPage - Function that fetches a single page of results given a page number.
11
+ * @returns An array of arrays, one per tag, containing all results across all pages.
12
+ */
13
+ async function getAllPages<T>(numTags: number, fetchPage: (page: number) => Promise<T[][]>): Promise<T[][]> {
14
+ const allResultsPerTag: T[][] = Array.from({ length: numTags }, () => []);
15
+ let page = 0;
16
+ let hasMore = true;
17
+
18
+ while (hasMore) {
19
+ const resultsPage = await fetchPage(page);
20
+ hasMore = false;
21
+
22
+ for (let i = 0; i < resultsPage.length; i++) {
23
+ allResultsPerTag[i].push(...resultsPage[i]);
24
+ if (resultsPage[i].length === MAX_LOGS_PER_TAG) {
25
+ hasMore = true;
26
+ }
27
+ }
28
+ page++;
29
+ }
30
+
31
+ return allResultsPerTag;
32
+ }
33
+
34
+ /**
35
+ * Splits tags into chunks of MAX_RPC_LEN, fetches logs for each chunk using getAllPages, then stitches the results
36
+ * back into a single array preserving the original tag order.
37
+ */
38
+ async function getAllPagesInBatches<Tag, T>(
39
+ tags: Tag[],
40
+ fetchAllPagesForBatch: (batch: Tag[]) => Promise<T[][]>,
41
+ ): Promise<T[][]> {
42
+ if (tags.length <= MAX_RPC_LEN) {
43
+ return fetchAllPagesForBatch(tags);
44
+ }
45
+
46
+ const batches: Tag[][] = [];
47
+ for (let i = 0; i < tags.length; i += MAX_RPC_LEN) {
48
+ batches.push(tags.slice(i, i + MAX_RPC_LEN));
49
+ }
50
+ const batchResults = await Promise.all(batches.map(fetchAllPagesForBatch));
51
+ return batchResults.flat();
52
+ }
53
+
54
+ /**
55
+ * Fetches all private logs for the given tags, automatically paginating through all pages.
56
+ * @param aztecNode - The Aztec node to query.
57
+ * @param tags - The siloed tags to search for.
58
+ * @param anchorBlockHash - reference block for the Aztec node query, throws if block is not found there (typically
59
+ * because of reorgs).
60
+ * @returns An array of log arrays, one per tag, containing all logs across all pages.
61
+ */
62
+ export function getAllPrivateLogsByTags(
63
+ aztecNode: AztecNode,
64
+ tags: SiloedTag[],
65
+ anchorBlockHash: BlockHash,
66
+ ): Promise<TxScopedL2Log[][]> {
67
+ return getAllPagesInBatches(tags, batch =>
68
+ getAllPages(batch.length, page => aztecNode.getPrivateLogsByTags(batch, page, anchorBlockHash)),
69
+ );
70
+ }
71
+
72
+ /**
73
+ * Fetches all public logs for the given tags from a contract, automatically paginating through all pages.
74
+ * @param aztecNode - The Aztec node to query.
75
+ * @param contractAddress - The contract address to search logs for.
76
+ * @param tags - The tags to search for.
77
+ * @param anchorBlockHash - reference block for the Aztec node query, throws if block is not found there (typically
78
+ * because of reorgs).
79
+ * @returns An array of log arrays, one per tag, containing all logs across all pages.
80
+ */
81
+ export function getAllPublicLogsByTagsFromContract(
82
+ aztecNode: AztecNode,
83
+ contractAddress: AztecAddress,
84
+ tags: Tag[],
85
+ anchorBlockHash: BlockHash,
86
+ ): Promise<TxScopedL2Log[][]> {
87
+ return getAllPagesInBatches(tags, batch =>
88
+ getAllPages(batch.length, page =>
89
+ aztecNode.getPublicLogsByTagsFromContract(contractAddress, batch, page, anchorBlockHash),
90
+ ),
91
+ );
92
+ }
@@ -1,6 +1,19 @@
1
- export * from './tag.js';
2
- export * from './constants.js';
3
- export * from './siloed_tag.js';
4
- export * from './utils.js';
5
- export { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
1
+ /**
2
+ * This directory contains the sender and recipient synchronization algorithms that use tagging.
3
+ *
4
+ * The objective of the sender sync algorithm is to determine which tags have already been used by a sender, thereby
5
+ * deciding which tag should be used next.
6
+ *
7
+ * The objective of the recipient sync algorithm is to load and process the corresponding logs.
8
+ *
9
+ * @module tagging
10
+ */
11
+
12
+ export { loadPrivateLogsForSenderRecipientPair } from './recipient_sync/load_private_logs_for_sender_recipient_pair.js';
13
+ export { syncSenderTaggingIndexes } from './sender_sync/sync_sender_tagging_indexes.js';
14
+ export { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from './constants.js';
15
+ export { getAllPrivateLogsByTags, getAllPublicLogsByTagsFromContract } from './get_all_logs_by_tags.js';
16
+
17
+ // Re-export tagging-related types from stdlib
18
+ export { DirectionalAppTaggingSecret, Tag, SiloedTag } from '@aztec/stdlib/logs';
6
19
  export { type PreTag } from '@aztec/stdlib/logs';