@aztec/p2p 0.0.1-commit.f295ac2 → 0.0.1-commit.f8ca9b2f3

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 (443) hide show
  1. package/dest/bootstrap/bootstrap.d.ts +4 -3
  2. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  3. package/dest/bootstrap/bootstrap.js +4 -4
  4. package/dest/client/factory.d.ts +5 -5
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +47 -13
  7. package/dest/client/interface.d.ts +33 -15
  8. package/dest/client/interface.d.ts.map +1 -1
  9. package/dest/client/p2p_client.d.ts +35 -36
  10. package/dest/client/p2p_client.d.ts.map +1 -1
  11. package/dest/client/p2p_client.js +115 -139
  12. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +2 -0
  13. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +1 -0
  14. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +305 -0
  15. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +73 -0
  16. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +1 -0
  17. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +8 -0
  18. package/dest/config.d.ts +24 -3
  19. package/dest/config.d.ts.map +1 -1
  20. package/dest/config.js +16 -2
  21. package/dest/index.d.ts +2 -1
  22. package/dest/index.d.ts.map +1 -1
  23. package/dest/index.js +1 -0
  24. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +102 -88
  25. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  26. package/dest/mem_pools/attestation_pool/attestation_pool.js +436 -3
  27. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
  28. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  29. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +353 -87
  30. package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
  31. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  32. package/dest/mem_pools/attestation_pool/index.js +1 -2
  33. package/dest/mem_pools/index.d.ts +3 -2
  34. package/dest/mem_pools/index.d.ts.map +1 -1
  35. package/dest/mem_pools/index.js +1 -1
  36. package/dest/mem_pools/instrumentation.d.ts +1 -1
  37. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  38. package/dest/mem_pools/instrumentation.js +2 -2
  39. package/dest/mem_pools/interface.d.ts +5 -5
  40. package/dest/mem_pools/interface.d.ts.map +1 -1
  41. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +3 -3
  42. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  43. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +3 -2
  44. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -1
  45. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +3 -2
  46. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -1
  47. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +3 -3
  48. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +8 -1
  50. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +3 -3
  51. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
  52. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +2 -0
  53. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
  54. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
  55. package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
  56. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +43 -0
  57. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
  58. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +103 -0
  59. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +87 -0
  60. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  61. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +180 -0
  62. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
  63. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
  64. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +119 -0
  65. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
  66. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  67. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +90 -0
  68. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
  69. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
  70. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +89 -0
  71. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +10 -0
  72. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
  73. package/dest/mem_pools/tx_pool_v2/eviction/index.js +11 -0
  74. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +131 -0
  75. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
  76. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +17 -0
  77. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
  78. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  79. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +63 -0
  80. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
  81. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  82. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +91 -0
  83. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
  84. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  85. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +70 -0
  86. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
  87. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
  88. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +63 -0
  89. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
  90. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
  91. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
  92. package/dest/mem_pools/tx_pool_v2/index.d.ts +6 -0
  93. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
  94. package/dest/mem_pools/tx_pool_v2/index.js +5 -0
  95. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +197 -0
  96. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
  97. package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -0
  98. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +93 -0
  99. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
  100. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +127 -0
  101. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
  102. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
  103. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
  104. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +99 -0
  105. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
  106. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +332 -0
  107. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +55 -0
  108. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
  109. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +156 -0
  110. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +69 -0
  111. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
  112. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +751 -0
  113. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +3 -3
  114. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  115. package/dest/msg_validators/attestation_validator/attestation_validator.js +41 -10
  116. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -5
  117. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  118. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +18 -6
  119. package/dest/msg_validators/clock_tolerance.d.ts +21 -0
  120. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
  121. package/dest/msg_validators/clock_tolerance.js +37 -0
  122. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +3 -3
  123. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  124. package/dest/msg_validators/proposal_validator/proposal_validator.js +55 -31
  125. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +3 -3
  126. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -1
  127. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +93 -64
  128. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +3 -3
  129. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  130. package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
  131. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
  132. package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
  133. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +20 -6
  134. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  135. package/dest/msg_validators/tx_validator/block_header_validator.js +4 -3
  136. package/dest/msg_validators/tx_validator/data_validator.d.ts +3 -1
  137. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  138. package/dest/msg_validators/tx_validator/data_validator.js +4 -1
  139. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +15 -4
  140. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  141. package/dest/msg_validators/tx_validator/double_spend_validator.js +7 -6
  142. package/dest/msg_validators/tx_validator/factory.d.ts +8 -3
  143. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  144. package/dest/msg_validators/tx_validator/factory.js +21 -11
  145. package/dest/msg_validators/tx_validator/gas_validator.d.ts +3 -2
  146. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  147. package/dest/msg_validators/tx_validator/gas_validator.js +3 -2
  148. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  149. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  150. package/dest/msg_validators/tx_validator/index.js +1 -0
  151. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +3 -2
  152. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  153. package/dest/msg_validators/tx_validator/metadata_validator.js +2 -2
  154. package/dest/msg_validators/tx_validator/phases_validator.d.ts +3 -2
  155. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  156. package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
  157. package/dest/msg_validators/tx_validator/size_validator.d.ts +8 -0
  158. package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
  159. package/dest/msg_validators/tx_validator/size_validator.js +23 -0
  160. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +22 -5
  161. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  162. package/dest/msg_validators/tx_validator/timestamp_validator.js +4 -4
  163. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
  164. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
  165. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
  166. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +3 -2
  167. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  168. package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -2
  169. package/dest/services/data_store.d.ts +1 -1
  170. package/dest/services/data_store.d.ts.map +1 -1
  171. package/dest/services/data_store.js +10 -6
  172. package/dest/services/discv5/discV5_service.js +1 -1
  173. package/dest/services/dummy_service.d.ts +22 -2
  174. package/dest/services/dummy_service.d.ts.map +1 -1
  175. package/dest/services/dummy_service.js +45 -0
  176. package/dest/services/encoding.d.ts +2 -2
  177. package/dest/services/encoding.d.ts.map +1 -1
  178. package/dest/services/encoding.js +4 -5
  179. package/dest/services/gossipsub/index.d.ts +3 -0
  180. package/dest/services/gossipsub/index.d.ts.map +1 -0
  181. package/dest/services/gossipsub/index.js +2 -0
  182. package/dest/services/gossipsub/scoring.d.ts +21 -3
  183. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  184. package/dest/services/gossipsub/scoring.js +24 -7
  185. package/dest/services/gossipsub/topic_score_params.d.ts +161 -0
  186. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  187. package/dest/services/gossipsub/topic_score_params.js +324 -0
  188. package/dest/services/index.d.ts +2 -1
  189. package/dest/services/index.d.ts.map +1 -1
  190. package/dest/services/index.js +1 -0
  191. package/dest/services/libp2p/instrumentation.d.ts +1 -1
  192. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  193. package/dest/services/libp2p/instrumentation.js +14 -3
  194. package/dest/services/libp2p/libp2p_service.d.ts +91 -36
  195. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  196. package/dest/services/libp2p/libp2p_service.js +407 -303
  197. package/dest/services/peer-manager/metrics.d.ts +2 -2
  198. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  199. package/dest/services/peer-manager/metrics.js +20 -5
  200. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  201. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  202. package/dest/services/peer-manager/peer_scoring.js +33 -4
  203. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +47 -0
  204. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
  205. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +566 -0
  206. package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
  207. package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
  208. package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
  209. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +50 -0
  210. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
  211. package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
  212. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +37 -0
  213. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
  214. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +151 -0
  215. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +54 -0
  216. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
  217. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +139 -0
  218. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +20 -0
  219. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
  220. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
  221. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +22 -3
  222. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  223. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +63 -4
  224. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -1
  225. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  226. package/dest/services/reqresp/connection-sampler/connection_sampler.js +12 -0
  227. package/dest/services/reqresp/interface.d.ts +14 -3
  228. package/dest/services/reqresp/interface.d.ts.map +1 -1
  229. package/dest/services/reqresp/interface.js +17 -3
  230. package/dest/services/reqresp/metrics.d.ts +6 -5
  231. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  232. package/dest/services/reqresp/metrics.js +17 -5
  233. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +5 -1
  234. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  235. package/dest/services/reqresp/protocols/block_txs/bitvector.js +5 -0
  236. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +7 -5
  237. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  238. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +27 -9
  239. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +29 -6
  240. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  241. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +59 -13
  242. package/dest/services/reqresp/protocols/tx.d.ts +7 -1
  243. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  244. package/dest/services/reqresp/protocols/tx.js +20 -0
  245. package/dest/services/reqresp/reqresp.d.ts +6 -1
  246. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  247. package/dest/services/reqresp/reqresp.js +69 -26
  248. package/dest/services/service.d.ts +38 -1
  249. package/dest/services/service.d.ts.map +1 -1
  250. package/dest/services/tx_collection/config.d.ts +10 -1
  251. package/dest/services/tx_collection/config.d.ts.map +1 -1
  252. package/dest/services/tx_collection/config.js +25 -1
  253. package/dest/services/tx_collection/fast_tx_collection.d.ts +7 -4
  254. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  255. package/dest/services/tx_collection/fast_tx_collection.js +34 -13
  256. package/dest/services/tx_collection/file_store_tx_collection.d.ts +44 -0
  257. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  258. package/dest/services/tx_collection/file_store_tx_collection.js +118 -0
  259. package/dest/services/tx_collection/file_store_tx_source.d.ts +27 -0
  260. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  261. package/dest/services/tx_collection/file_store_tx_source.js +57 -0
  262. package/dest/services/tx_collection/index.d.ts +3 -1
  263. package/dest/services/tx_collection/index.d.ts.map +1 -1
  264. package/dest/services/tx_collection/index.js +2 -0
  265. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  266. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  267. package/dest/services/tx_collection/instrumentation.js +9 -2
  268. package/dest/services/tx_collection/proposal_tx_collector.d.ts +48 -0
  269. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
  270. package/dest/services/tx_collection/proposal_tx_collector.js +49 -0
  271. package/dest/services/tx_collection/slow_tx_collection.d.ts +5 -3
  272. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  273. package/dest/services/tx_collection/slow_tx_collection.js +48 -19
  274. package/dest/services/tx_collection/tx_collection.d.ts +23 -13
  275. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  276. package/dest/services/tx_collection/tx_collection.js +62 -6
  277. package/dest/services/tx_collection/tx_collection_sink.d.ts +15 -6
  278. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  279. package/dest/services/tx_collection/tx_collection_sink.js +13 -7
  280. package/dest/services/tx_file_store/config.d.ts +16 -0
  281. package/dest/services/tx_file_store/config.d.ts.map +1 -0
  282. package/dest/services/tx_file_store/config.js +22 -0
  283. package/dest/services/tx_file_store/index.d.ts +4 -0
  284. package/dest/services/tx_file_store/index.d.ts.map +1 -0
  285. package/dest/services/tx_file_store/index.js +3 -0
  286. package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
  287. package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
  288. package/dest/services/tx_file_store/instrumentation.js +29 -0
  289. package/dest/services/tx_file_store/tx_file_store.d.ts +47 -0
  290. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
  291. package/dest/services/tx_file_store/tx_file_store.js +149 -0
  292. package/dest/services/tx_provider.d.ts +5 -5
  293. package/dest/services/tx_provider.d.ts.map +1 -1
  294. package/dest/services/tx_provider.js +5 -4
  295. package/dest/services/tx_provider_instrumentation.d.ts +1 -1
  296. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  297. package/dest/services/tx_provider_instrumentation.js +5 -5
  298. package/dest/test-helpers/index.d.ts +3 -1
  299. package/dest/test-helpers/index.d.ts.map +1 -1
  300. package/dest/test-helpers/index.js +2 -0
  301. package/dest/test-helpers/make-test-p2p-clients.d.ts +3 -3
  302. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  303. package/dest/test-helpers/mock-pubsub.d.ts +27 -1
  304. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  305. package/dest/test-helpers/mock-pubsub.js +97 -2
  306. package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
  307. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  308. package/dest/test-helpers/reqresp-nodes.js +2 -1
  309. package/dest/test-helpers/test_tx_provider.d.ts +40 -0
  310. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
  311. package/dest/test-helpers/test_tx_provider.js +41 -0
  312. package/dest/test-helpers/testbench-utils.d.ts +158 -0
  313. package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
  314. package/dest/test-helpers/testbench-utils.js +360 -0
  315. package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
  316. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  317. package/dest/testbench/p2p_client_testbench_worker.js +213 -134
  318. package/dest/testbench/worker_client_manager.d.ts +51 -6
  319. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  320. package/dest/testbench/worker_client_manager.js +226 -44
  321. package/package.json +14 -14
  322. package/src/bootstrap/bootstrap.ts +7 -4
  323. package/src/client/factory.ts +78 -22
  324. package/src/client/interface.ts +39 -14
  325. package/src/client/p2p_client.ts +155 -166
  326. package/src/client/test/tx_proposal_collector/README.md +227 -0
  327. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +336 -0
  328. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
  329. package/src/config.ts +38 -2
  330. package/src/index.ts +1 -0
  331. package/src/mem_pools/attestation_pool/attestation_pool.ts +488 -91
  332. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +442 -102
  333. package/src/mem_pools/attestation_pool/index.ts +9 -2
  334. package/src/mem_pools/index.ts +4 -1
  335. package/src/mem_pools/instrumentation.ts +2 -1
  336. package/src/mem_pools/interface.ts +4 -4
  337. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +2 -2
  338. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +2 -1
  339. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +2 -1
  340. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +10 -7
  341. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +4 -2
  342. package/src/mem_pools/tx_pool_v2/README.md +259 -0
  343. package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
  344. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -0
  345. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +234 -0
  346. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +147 -0
  347. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +118 -0
  348. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +111 -0
  349. package/src/mem_pools/tx_pool_v2/eviction/index.ts +23 -0
  350. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +164 -0
  351. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
  352. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
  353. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +86 -0
  354. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +72 -0
  355. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +31 -0
  356. package/src/mem_pools/tx_pool_v2/index.ts +12 -0
  357. package/src/mem_pools/tx_pool_v2/interfaces.ts +227 -0
  358. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +207 -0
  359. package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
  360. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +417 -0
  361. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +212 -0
  362. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +895 -0
  363. package/src/msg_validators/attestation_validator/attestation_validator.ts +26 -14
  364. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +16 -10
  365. package/src/msg_validators/clock_tolerance.ts +51 -0
  366. package/src/msg_validators/proposal_validator/proposal_validator.ts +31 -31
  367. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +91 -67
  368. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +2 -2
  369. package/src/msg_validators/tx_validator/archive_cache.ts +3 -3
  370. package/src/msg_validators/tx_validator/block_header_validator.ts +21 -8
  371. package/src/msg_validators/tx_validator/data_validator.ts +6 -2
  372. package/src/msg_validators/tx_validator/double_spend_validator.ts +15 -9
  373. package/src/msg_validators/tx_validator/factory.ts +64 -23
  374. package/src/msg_validators/tx_validator/gas_validator.ts +9 -3
  375. package/src/msg_validators/tx_validator/index.ts +1 -0
  376. package/src/msg_validators/tx_validator/metadata_validator.ts +6 -3
  377. package/src/msg_validators/tx_validator/phases_validator.ts +5 -3
  378. package/src/msg_validators/tx_validator/size_validator.ts +22 -0
  379. package/src/msg_validators/tx_validator/timestamp_validator.ts +25 -17
  380. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
  381. package/src/msg_validators/tx_validator/tx_proof_validator.ts +8 -3
  382. package/src/services/data_store.ts +10 -7
  383. package/src/services/discv5/discV5_service.ts +1 -1
  384. package/src/services/dummy_service.ts +57 -0
  385. package/src/services/encoding.ts +4 -5
  386. package/src/services/gossipsub/README.md +626 -0
  387. package/src/services/gossipsub/index.ts +2 -0
  388. package/src/services/gossipsub/scoring.ts +29 -5
  389. package/src/services/gossipsub/topic_score_params.ts +451 -0
  390. package/src/services/index.ts +1 -0
  391. package/src/services/libp2p/instrumentation.ts +15 -2
  392. package/src/services/libp2p/libp2p_service.ts +437 -316
  393. package/src/services/peer-manager/metrics.ts +21 -4
  394. package/src/services/peer-manager/peer_scoring.ts +29 -1
  395. package/src/services/reqresp/batch-tx-requester/README.md +305 -0
  396. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +706 -0
  397. package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
  398. package/src/services/reqresp/batch-tx-requester/interface.ts +57 -0
  399. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +209 -0
  400. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +205 -0
  401. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
  402. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +65 -4
  403. package/src/services/reqresp/connection-sampler/connection_sampler.ts +16 -0
  404. package/src/services/reqresp/interface.ts +31 -3
  405. package/src/services/reqresp/metrics.ts +34 -9
  406. package/src/services/reqresp/protocols/block_txs/bitvector.ts +7 -0
  407. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +35 -12
  408. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +74 -9
  409. package/src/services/reqresp/protocols/tx.ts +22 -0
  410. package/src/services/reqresp/reqresp.ts +79 -22
  411. package/src/services/service.ts +44 -0
  412. package/src/services/tx_collection/config.ts +41 -1
  413. package/src/services/tx_collection/fast_tx_collection.ts +44 -19
  414. package/src/services/tx_collection/file_store_tx_collection.ts +152 -0
  415. package/src/services/tx_collection/file_store_tx_source.ts +70 -0
  416. package/src/services/tx_collection/index.ts +6 -0
  417. package/src/services/tx_collection/instrumentation.ts +11 -2
  418. package/src/services/tx_collection/proposal_tx_collector.ts +112 -0
  419. package/src/services/tx_collection/slow_tx_collection.ts +57 -28
  420. package/src/services/tx_collection/tx_collection.ts +86 -20
  421. package/src/services/tx_collection/tx_collection_sink.ts +17 -7
  422. package/src/services/tx_file_store/config.ts +37 -0
  423. package/src/services/tx_file_store/index.ts +3 -0
  424. package/src/services/tx_file_store/instrumentation.ts +36 -0
  425. package/src/services/tx_file_store/tx_file_store.ts +173 -0
  426. package/src/services/tx_provider.ts +10 -9
  427. package/src/services/tx_provider_instrumentation.ts +11 -5
  428. package/src/test-helpers/index.ts +2 -0
  429. package/src/test-helpers/make-test-p2p-clients.ts +3 -3
  430. package/src/test-helpers/mock-pubsub.ts +133 -3
  431. package/src/test-helpers/reqresp-nodes.ts +2 -1
  432. package/src/test-helpers/test_tx_provider.ts +64 -0
  433. package/src/test-helpers/testbench-utils.ts +422 -0
  434. package/src/testbench/p2p_client_testbench_worker.ts +322 -127
  435. package/src/testbench/worker_client_manager.ts +304 -47
  436. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
  437. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  438. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
  439. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
  440. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  441. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
  442. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
  443. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
package/src/index.ts CHANGED
@@ -7,5 +7,6 @@ export * from './enr/index.js';
7
7
  export * from './config.js';
8
8
  export * from './mem_pools/attestation_pool/index.js';
9
9
  export * from './mem_pools/tx_pool/index.js';
10
+ export * from './mem_pools/tx_pool_v2/index.js';
10
11
  export * from './msg_validators/index.js';
11
12
  export * from './services/index.js';
@@ -1,52 +1,311 @@
1
- import type { SlotNumber } from '@aztec/foundation/branded-types';
2
- import type {
1
+ import { IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import { toArray } from '@aztec/foundation/iterable';
4
+ import { createLogger } from '@aztec/foundation/log';
5
+ import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec/kv-store';
6
+ import {
3
7
  BlockProposal,
4
8
  CheckpointAttestation,
5
9
  CheckpointProposal,
6
- CheckpointProposalCore,
10
+ type CheckpointProposalCore,
7
11
  } from '@aztec/stdlib/p2p';
12
+ import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
13
+
14
+ import { PoolInstrumentation, PoolName, type PoolStatsCallback } from '../instrumentation.js';
15
+
16
+ /** Result of trying to add an item (proposal or attestation) to the pool */
17
+ export type TryAddResult = {
18
+ /** Whether the item was added */
19
+ added: boolean;
20
+ /** Whether the exact item already existed */
21
+ alreadyExists: boolean;
22
+ /** Count of items for the position. Meaning varies by method:
23
+ * - tryAddBlockProposal: proposals at (slot, indexWithinCheckpoint)
24
+ * - tryAddCheckpointProposal: proposals at slot
25
+ * - tryAddCheckpointAttestation: attestations by this signer for this slot */
26
+ count: number;
27
+ };
28
+
29
+ export const MAX_CHECKPOINT_PROPOSALS_PER_SLOT = 5;
30
+ export const MAX_BLOCK_PROPOSALS_PER_POSITION = 3;
31
+ /** Maximum attestations a single signer can make per slot before being rejected. */
32
+ export const MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER = 3;
33
+
34
+ /** Public API interface for attestation pools. Used for typing mocks and test implementations. */
35
+ export type AttestationPoolApi = Pick<
36
+ AttestationPool,
37
+ | 'tryAddBlockProposal'
38
+ | 'getBlockProposal'
39
+ | 'tryAddCheckpointProposal'
40
+ | 'getCheckpointProposal'
41
+ | 'addOwnCheckpointAttestations'
42
+ | 'tryAddCheckpointAttestation'
43
+ | 'deleteOlderThan'
44
+ | 'getCheckpointAttestationsForSlot'
45
+ | 'getCheckpointAttestationsForSlotAndProposal'
46
+ | 'isEmpty'
47
+ >;
8
48
 
9
49
  /**
10
- * An Attestation Pool contains attestations collected by a validator
50
+ * Pool for storing attestations and proposals collected by a validator.
11
51
  *
12
- * Attestations that are observed via the p2p network are stored for requests
52
+ * Attestations and proposals observed via the p2p network are stored for requests
13
53
  * from the validator to produce a block, or to serve to other peers.
14
54
  */
15
- export interface AttestationPool {
16
- /**
17
- * Adds new block proposal to the pool
18
- */
19
- addBlockProposal(blockProposal: BlockProposal): Promise<void>;
55
+ export class AttestationPool {
56
+ private metrics: PoolInstrumentation<CheckpointAttestation>;
57
+
58
+ // Checkpoint attestations from attestation key (slot-proposalId-signer) to serialized CheckpointAttestation
59
+ // Keys are lexicographically sortable allowing range queries by slot or by (slot, proposalId)
60
+ private checkpointAttestations: AztecAsyncMap<string, Buffer>;
61
+
62
+ // Checkpoint proposals from proposal archive to serialized CheckpointProposal
63
+ private checkpointProposals: AztecAsyncMap<string, Buffer>;
64
+
65
+ // Checkpoint proposals indexed by slot for querying all proposals in a slot
66
+ // Key: slot number, Value: proposal archive strings
67
+ private checkpointProposalsForSlot: AztecAsyncMultiMap<number, string>;
68
+
69
+ // Block proposals from proposal archive to serialized BlockProposal
70
+ private blockProposals: AztecAsyncMap<string, Buffer>;
71
+
72
+ // Block proposals indexed by slot and index-within-checkpoint for duplicate detection
73
+ // Key: (slot << 10) | indexWithinCheckpoint, Value: archive string
74
+ private blockProposalsForSlotAndIndex: AztecAsyncMultiMap<number, string>;
75
+
76
+ // Checkpoint attestations indexed by (slot, signer) for tracking attestations per (slot, signer) for duplicate detection
77
+ // Key: `${Fr(slot).toString()}-${signerAddress}` string (padded for lexicographic ordering), Value: `proposalId` strings
78
+ private checkpointAttestationsPerSlotAndSigner: AztecAsyncMultiMap<string, string>;
79
+
80
+ constructor(
81
+ private store: AztecAsyncKVStore,
82
+ telemetry: TelemetryClient = getTelemetryClient(),
83
+ private log = createLogger('aztec:attestation_pool'),
84
+ ) {
85
+ // Initialize block proposal storage
86
+ this.blockProposals = store.openMap('proposals');
87
+ this.blockProposalsForSlotAndIndex = store.openMultiMap('block_proposals_for_slot_and_index');
88
+
89
+ // Initialize checkpoint attestations storage
90
+ this.checkpointAttestations = store.openMap('checkpoint_attestations');
91
+ this.checkpointAttestationsPerSlotAndSigner = store.openMultiMap('checkpoint_attestations_per_slot_and_signer');
92
+
93
+ // Initialize checkpoint proposal storage
94
+ this.checkpointProposals = store.openMap('checkpoint_proposals');
95
+ this.checkpointProposalsForSlot = store.openMultiMap('checkpoint_proposals_for_slot');
96
+
97
+ this.metrics = new PoolInstrumentation(telemetry, PoolName.ATTESTATION_POOL, this.poolStats);
98
+ }
99
+
100
+ private poolStats: PoolStatsCallback = async () => {
101
+ return {
102
+ itemCount: await this.checkpointAttestations.sizeAsync(),
103
+ };
104
+ };
105
+
106
+ /** Returns whether the pool is empty. */
107
+ public async isEmpty(): Promise<boolean> {
108
+ for await (const _ of this.checkpointAttestations.entriesAsync()) {
109
+ return false;
110
+ }
111
+ for await (const _ of this.blockProposals.entriesAsync()) {
112
+ return false;
113
+ }
114
+ return true;
115
+ }
116
+
117
+ private getProposalKey(slot: number | bigint | Fr | string, proposalId: Fr | string | Buffer): string {
118
+ const slotStr = typeof slot === 'string' ? slot : new Fr(slot).toString();
119
+ const proposalIdStr =
120
+ typeof proposalId === 'string'
121
+ ? proposalId
122
+ : Buffer.isBuffer(proposalId)
123
+ ? Fr.fromBuffer(proposalId).toString()
124
+ : proposalId.toString();
125
+
126
+ return `${slotStr}-${proposalIdStr}`;
127
+ }
128
+
129
+ private getAttestationKey(slot: number | bigint | Fr | string, proposalId: Fr | string, address: string): string {
130
+ return `${this.getProposalKey(slot, proposalId)}-${address}`;
131
+ }
132
+
133
+ /** Returns range bounds for querying all attestations for a given slot. */
134
+ private getAttestationKeyRangeForSlot(slot: SlotNumber): { start: string; end: string } {
135
+ const slotStr = new Fr(slot).toString();
136
+ return { start: `${slotStr}-`, end: `${slotStr}-Z` }; // 'Z' sorts after any hex character
137
+ }
138
+
139
+ /** Returns range bounds for querying all attestations for a given (slot, proposalId). */
140
+ private getAttestationKeyRangeForProposal(slot: SlotNumber, proposalId: string): { start: string; end: string } {
141
+ const proposalKey = this.getProposalKey(slot, proposalId);
142
+ return { start: `${proposalKey}-`, end: `${proposalKey}-Z` };
143
+ }
144
+
145
+ /** Creates a key for the per-signer-per-slot attestation index. Uses padded slot for lexicographic ordering. */
146
+ private getSlotSignerKey(slot: SlotNumber, signerAddress: string): string {
147
+ const slotStr = new Fr(slot).toString();
148
+ return `${slotStr}-${signerAddress}`;
149
+ }
150
+
151
+ /** Number of bits reserved for indexWithinCheckpoint in position keys. */
152
+ private static readonly INDEX_BITS = 10;
153
+ /** Maximum indexWithinCheckpoint value (2^10 - 1 = 1023). */
154
+ private static readonly MAX_INDEX = (1 << AttestationPool.INDEX_BITS) - 1;
155
+
156
+ /** Creates a position key for block proposals: (slot << 10) | indexWithinCheckpoint. */
157
+ private getBlockPositionKey(slot: number, indexWithinCheckpoint: number): number {
158
+ if (indexWithinCheckpoint > AttestationPool.MAX_INDEX) {
159
+ throw new Error(
160
+ `Value for indexWithinCheckpoint ${indexWithinCheckpoint} exceeds maximum ${AttestationPool.MAX_INDEX}`,
161
+ );
162
+ }
163
+ return (slot << AttestationPool.INDEX_BITS) | indexWithinCheckpoint;
164
+ }
20
165
 
21
166
  /**
22
- * Get block proposal by it's ID
167
+ * Attempts to add a block proposal to the pool.
23
168
  *
24
- * @param id - The ID of the block proposal to retrieve. The ID is proposal.payload.archive
169
+ * This method performs validation and addition in a single call:
170
+ * - Checks if the proposal already exists (returns alreadyExists: true if so)
171
+ * - Checks if the position has reached the proposal cap (returns added: false if so)
172
+ * - Adds the proposal if validation passes
25
173
  *
26
- * @return The block proposal if it exists, otherwise undefined.
174
+ * @param blockProposal - The block proposal to add
175
+ * @returns Result indicating whether the proposal was added and duplicate detection info
27
176
  */
28
- getBlockProposal(id: string): Promise<BlockProposal | undefined>;
177
+ public async tryAddBlockProposal(blockProposal: BlockProposal): Promise<TryAddResult> {
178
+ return await this.store.transactionAsync(async () => {
179
+ const proposalId = blockProposal.archive.toString();
180
+
181
+ // Check if already exists
182
+ const alreadyExists = await this.blockProposals.hasAsync(proposalId);
183
+ if (alreadyExists) {
184
+ const count = await this.getBlockProposalCountForPosition(
185
+ blockProposal.slotNumber,
186
+ blockProposal.indexWithinCheckpoint,
187
+ );
188
+ return { added: false, alreadyExists: true, count };
189
+ }
190
+
191
+ // Get current count for position and check cap, do not add if exceeded
192
+ const count = await this.getBlockProposalCountForPosition(
193
+ blockProposal.slotNumber,
194
+ blockProposal.indexWithinCheckpoint,
195
+ );
196
+
197
+ if (count >= MAX_BLOCK_PROPOSALS_PER_POSITION) {
198
+ return { added: false, alreadyExists: false, count };
199
+ }
200
+
201
+ // Add the proposal
202
+ await this.addBlockProposal(blockProposal);
203
+
204
+ this.log.debug(
205
+ `Added block proposal for slot ${blockProposal.slotNumber} and index ${blockProposal.indexWithinCheckpoint}`,
206
+ {
207
+ proposalId,
208
+ slotNumber: blockProposal.slotNumber,
209
+ indexWithinCheckpoint: blockProposal.indexWithinCheckpoint,
210
+ },
211
+ );
212
+
213
+ return { added: true, alreadyExists: false, count: count + 1 };
214
+ });
215
+ }
216
+
217
+ /** Gets the count of block proposals for a given position (slot, indexWithinCheckpoint). */
218
+ private getBlockProposalCountForPosition(
219
+ slot: SlotNumber,
220
+ indexWithinCheckpoint: IndexWithinCheckpoint,
221
+ ): Promise<number> {
222
+ const positionKey = this.getBlockPositionKey(slot, indexWithinCheckpoint);
223
+ return this.blockProposalsForSlotAndIndex.getValueCountAsync(positionKey);
224
+ }
225
+
226
+ /** Internal method - must be called within a transaction. */
227
+ private async addBlockProposal(blockProposal: BlockProposal): Promise<void> {
228
+ const proposalId = blockProposal.archive.toString();
229
+ // Strip signedTxs before storing to avoid persisting full tx data
230
+ await this.blockProposals.set(proposalId, blockProposal.withoutSignedTxs().toBuffer());
231
+
232
+ // Index by slot and position for duplicate detection
233
+ const positionKey = this.getBlockPositionKey(blockProposal.slotNumber, blockProposal.indexWithinCheckpoint);
234
+ await this.blockProposalsForSlotAndIndex.set(positionKey, proposalId);
235
+ }
29
236
 
30
237
  /**
31
- * Check if a block proposal exists in the pool
238
+ * Get block proposal by its ID.
32
239
  *
33
- * @param idOrProposal - The ID of the block proposal or the block proposal itself to check. The ID is proposal.payload.archive
240
+ * @param id - The ID of the block proposal to retrieve. The ID is proposal.payload.archive
34
241
  *
35
- * @return True if the block proposal exists, false otherwise.
242
+ * @return The block proposal if it exists, otherwise undefined.
36
243
  */
37
- hasBlockProposal(idOrProposal: string | BlockProposal): Promise<boolean>;
244
+ public async getBlockProposal(id: string): Promise<BlockProposal | undefined> {
245
+ const buffer = await this.blockProposals.getAsync(id);
246
+ try {
247
+ if (buffer && buffer.length > 0) {
248
+ return BlockProposal.fromBuffer(buffer);
249
+ }
250
+ } catch {
251
+ return undefined;
252
+ }
253
+
254
+ return undefined;
255
+ }
38
256
 
39
257
  /**
40
- * Adds a checkpoint proposal to the pool.
258
+ * Attempts to add a checkpoint proposal to the pool.
259
+ *
260
+ * This method performs validation and addition in a single call:
261
+ * - Checks if the proposal already exists (returns alreadyExists: true if so)
262
+ * - Checks if the slot has reached the proposal cap (returns added: false if so)
263
+ * - Adds the proposal if validation passes
41
264
  *
42
- * If the proposal contains a lastBlock, the BlockProposal is automatically extracted
43
- * and stored separately via addBlockProposal. The checkpoint proposal is then stored
44
- * without the lastBlock info (as CheckpointProposalCore).
265
+ * Note: This method only handles the CheckpointProposalCore. If the original
266
+ * CheckpointProposal contains a lastBlock, the caller should extract it via
267
+ * getBlockProposal() and add it separately via tryAddBlockProposal().
45
268
  *
46
- * @param proposal - The checkpoint proposal to add
47
- * @throws ProposalSlotCapExceededError if the slot has reached the maximum number of proposals
269
+ * @param proposal - The checkpoint proposal core to add
270
+ * @returns Result indicating whether the proposal was added and duplicate detection info
48
271
  */
49
- addCheckpointProposal(proposal: CheckpointProposal): Promise<void>;
272
+ public async tryAddCheckpointProposal(proposal: CheckpointProposalCore): Promise<TryAddResult> {
273
+ return await this.store.transactionAsync(async () => {
274
+ const proposalId = proposal.archive.toString();
275
+
276
+ // Check if already exists
277
+ const alreadyExists = await this.checkpointProposals.hasAsync(proposalId);
278
+ if (alreadyExists) {
279
+ const count = await this.checkpointProposalsForSlot.getValueCountAsync(proposal.slotNumber);
280
+ return { added: false, alreadyExists: true, count };
281
+ }
282
+
283
+ // Get current count for slot and check cap
284
+ const count = await this.checkpointProposalsForSlot.getValueCountAsync(proposal.slotNumber);
285
+ if (count >= MAX_CHECKPOINT_PROPOSALS_PER_SLOT) {
286
+ return { added: false, alreadyExists: false, count };
287
+ }
288
+
289
+ // Add the proposal if cap not exceeded
290
+ await this.addCheckpointProposal(proposal);
291
+
292
+ this.log.debug(`Added checkpoint proposal for slot ${proposal.slotNumber}`, {
293
+ proposalId,
294
+ slotNumber: proposal.slotNumber,
295
+ });
296
+
297
+ return { added: true, alreadyExists: false, count: count + 1 };
298
+ });
299
+ }
300
+
301
+ /** Internal method - must be called within a transaction. */
302
+ private async addCheckpointProposal(proposal: CheckpointProposalCore): Promise<void> {
303
+ const slotKey = proposal.slotNumber;
304
+ const proposalId = proposal.archive.toString();
305
+
306
+ await this.checkpointProposalsForSlot.set(slotKey, proposalId);
307
+ await this.checkpointProposals.set(proposalId, proposal.toBuffer());
308
+ }
50
309
 
51
310
  /**
52
311
  * Get checkpoint proposal by its ID.
@@ -57,101 +316,239 @@ export interface AttestationPool {
57
316
  * @param id - The ID of the checkpoint proposal to retrieve (proposal.archive)
58
317
  * @return The checkpoint proposal core if it exists, otherwise undefined.
59
318
  */
60
- getCheckpointProposal(id: string): Promise<CheckpointProposalCore | undefined>;
319
+ public async getCheckpointProposal(id: string): Promise<CheckpointProposalCore | undefined> {
320
+ const buffer = await this.checkpointProposals.getAsync(id);
321
+ try {
322
+ if (buffer && buffer.length > 0) {
323
+ return CheckpointProposal.fromBuffer(buffer);
324
+ }
325
+ } catch {
326
+ return undefined;
327
+ }
61
328
 
62
- /**
63
- * Check if a checkpoint proposal exists in the pool
64
- *
65
- * @param idOrProposal - The ID of the checkpoint proposal or the proposal itself
66
- * @return True if the proposal exists, false otherwise.
67
- */
68
- hasCheckpointProposal(idOrProposal: string | CheckpointProposal): Promise<boolean>;
329
+ return undefined;
330
+ }
69
331
 
70
332
  /**
71
- * Add checkpoint attestations to the pool
72
- *
73
- * @param attestations - Checkpoint attestations to add into the pool
333
+ * Adds own checkpoint attestations to the pool.
334
+ * Skips validations on number of checkpoint attestations stored for the given slot.
74
335
  */
75
- addCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void>;
336
+ public async addOwnCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void> {
337
+ await this.store.transactionAsync(async () => {
338
+ for (const attestation of attestations) {
339
+ const slotNumber = attestation.payload.header.slotNumber;
340
+ const proposalId = attestation.archive;
341
+ const sender = attestation.getSender();
76
342
 
77
- /**
78
- * Delete checkpoint attestations older than the given slot
79
- *
80
- * @param slot - The oldest slot to keep.
81
- */
82
- deleteCheckpointAttestationsOlderThan(slot: SlotNumber): Promise<void>;
343
+ // Skip attestations with invalid signatures
344
+ if (!sender) {
345
+ this.log.warn(`Skipping own checkpoint attestation with invalid signature for slot ${slotNumber}`, {
346
+ signature: attestation.signature.toString(),
347
+ slotNumber,
348
+ proposalId,
349
+ });
350
+ continue;
351
+ }
352
+
353
+ const address = sender.toString();
354
+
355
+ await this.checkpointAttestations.set(
356
+ this.getAttestationKey(slotNumber, proposalId, address),
357
+ attestation.toBuffer(),
358
+ );
359
+
360
+ this.log.debug(`Added own checkpoint attestation for slot ${slotNumber} from ${address}`, {
361
+ signature: attestation.signature.toString(),
362
+ slotNumber,
363
+ address,
364
+ proposalId,
365
+ });
366
+ }
367
+ });
368
+ }
83
369
 
84
370
  /**
85
- * Get all checkpoint attestations for a given slot
371
+ * Get all checkpoint attestations for a given slot.
86
372
  *
87
373
  * @param slot - The slot to query
88
374
  * @return CheckpointAttestations
89
375
  */
90
- getCheckpointAttestationsForSlot(slot: SlotNumber): Promise<CheckpointAttestation[]>;
376
+ public async getCheckpointAttestationsForSlot(slot: SlotNumber): Promise<CheckpointAttestation[]> {
377
+ const range = this.getAttestationKeyRangeForSlot(slot);
378
+ const attestations: CheckpointAttestation[] = [];
379
+
380
+ for await (const [_, buf] of this.checkpointAttestations.entriesAsync(range)) {
381
+ attestations.push(CheckpointAttestation.fromBuffer(buf));
382
+ }
383
+
384
+ return attestations;
385
+ }
91
386
 
92
387
  /**
93
- * Get checkpoint attestations for slot and given proposal
388
+ * Get checkpoint attestations for slot and given proposal.
94
389
  *
95
390
  * @param slot - The slot to query
96
391
  * @param proposalId - The proposal to query
97
392
  * @return CheckpointAttestations
98
393
  */
99
- getCheckpointAttestationsForSlotAndProposal(slot: SlotNumber, proposalId: string): Promise<CheckpointAttestation[]>;
394
+ public async getCheckpointAttestationsForSlotAndProposal(
395
+ slot: SlotNumber,
396
+ proposalId: string,
397
+ ): Promise<CheckpointAttestation[]> {
398
+ const range = this.getAttestationKeyRangeForProposal(slot, proposalId);
399
+ const attestations: CheckpointAttestation[] = [];
100
400
 
101
- /**
102
- * Check if a specific checkpoint attestation exists in the pool
103
- *
104
- * @param attestation - The attestation to check
105
- * @return True if the attestation exists, false otherwise
106
- */
107
- hasCheckpointAttestation(attestation: CheckpointAttestation): Promise<boolean>;
401
+ for await (const [_, buf] of this.checkpointAttestations.entriesAsync(range)) {
402
+ attestations.push(CheckpointAttestation.fromBuffer(buf));
403
+ }
108
404
 
109
- /**
110
- * Returns whether adding this proposal is permitted at current capacity:
111
- * - True if the proposal already exists, allow overwrite to keep parity with tests.
112
- * - True if the slot is below the proposal cap.
113
- * - False if the slot is at/above cap and this would be a new unique proposal.
114
- *
115
- * @param block - The block proposal to check
116
- * @returns True if the proposal can be added (or already exists), false otherwise.
117
- */
118
- canAddProposal(block: BlockProposal): Promise<boolean>;
405
+ return attestations;
406
+ }
119
407
 
120
408
  /**
121
- * Returns whether adding this checkpoint proposal is permitted at current capacity.
409
+ * Delete all pool data (attestations, proposals) older than the given slot.
122
410
  *
123
- * @param proposal - The checkpoint proposal to check
124
- * @returns True if the proposal can be added, false otherwise.
411
+ * @param oldestSlot - The oldest slot to keep.
125
412
  */
126
- canAddCheckpointProposal(proposal: CheckpointProposal): Promise<boolean>;
413
+ public async deleteOlderThan(oldestSlot: SlotNumber): Promise<void> {
414
+ let numberOfAttestations = 0;
415
+ let numberOfCheckpointProposals = 0;
416
+ let numberOfBlockProposals = 0;
127
417
 
128
- /**
129
- * Returns whether a checkpoint attestation would be accepted for (slot, proposalId).
130
- *
131
- * @param attestation - The attestation to check
132
- * @param committeeSize - Committee size for the attestation's slot
133
- * @returns True if the attestation can be added, false otherwise.
134
- */
135
- canAddCheckpointAttestation(attestation: CheckpointAttestation, committeeSize: number): Promise<boolean>;
418
+ await this.store.transactionAsync(async () => {
419
+ // Delete checkpoint attestations with slot < oldestSlot
420
+ // Attestation keys start with Fr(slot).toString(), so we use end bound of Fr(oldestSlot).toString()
421
+ const attestationEndKey = new Fr(oldestSlot).toString();
422
+ for await (const key of this.checkpointAttestations.keysAsync({ end: attestationEndKey })) {
423
+ await this.checkpointAttestations.delete(key);
424
+ numberOfAttestations++;
425
+ }
136
426
 
137
- /**
138
- * Returns whether the checkpoint proposal cap for the given slot has been reached.
139
- *
140
- * @param slot - The slot to check
141
- * @returns True if the cap has been reached, false otherwise.
142
- */
143
- hasReachedCheckpointProposalCap(slot: SlotNumber): Promise<boolean>;
427
+ // Clean up per-signer-per-slot index. Keys are formatted as `${Fr(slot).toString()}-${signerAddress}`.
428
+ // Since Fr pads to fixed-width hex, Fr(oldestSlot) is lexicographically greater than any key with
429
+ // a smaller slot (even with the signer suffix), so using it as the exclusive end bound is correct.
430
+ const slotSignerEndKey = new Fr(oldestSlot).toString();
431
+ for await (const key of this.checkpointAttestationsPerSlotAndSigner.keysAsync({ end: slotSignerEndKey })) {
432
+ await this.checkpointAttestationsPerSlotAndSigner.delete(key);
433
+ }
434
+
435
+ // Delete checkpoint proposals for slots < oldestSlot, using checkpointProposalsForSlot as index
436
+ for await (const slot of this.checkpointProposalsForSlot.keysAsync({ end: oldestSlot })) {
437
+ const proposalIds = await toArray(this.checkpointProposalsForSlot.getValuesAsync(slot));
438
+ for (const proposalId of proposalIds) {
439
+ await this.checkpointProposals.delete(proposalId);
440
+ numberOfCheckpointProposals++;
441
+ }
442
+ await this.checkpointProposalsForSlot.delete(slot);
443
+ }
444
+
445
+ // Delete block proposals for slots < oldestSlot, using blockProposalsForSlotAndIndex as index
446
+ // Key format: (slot << INDEX_BITS) | indexWithinCheckpoint
447
+ const blockPositionEndKey = oldestSlot << AttestationPool.INDEX_BITS;
448
+ for await (const positionKey of this.blockProposalsForSlotAndIndex.keysAsync({ end: blockPositionEndKey })) {
449
+ const proposalIds = await toArray(this.blockProposalsForSlotAndIndex.getValuesAsync(positionKey));
450
+ for (const proposalId of proposalIds) {
451
+ await this.blockProposals.delete(proposalId);
452
+ numberOfBlockProposals++;
453
+ }
454
+ await this.blockProposalsForSlotAndIndex.delete(positionKey);
455
+ }
456
+ });
457
+
458
+ this.log.verbose(`Deleted old pool data`, {
459
+ oldestSlot,
460
+ numberOfAttestations,
461
+ numberOfCheckpointProposals,
462
+ numberOfBlockProposals,
463
+ });
464
+ }
144
465
 
145
466
  /**
146
- * Returns whether the checkpoint attestation cap for the given slot and proposal has been reached.
467
+ * Attempts to add a checkpoint attestation to the pool.
468
+ *
469
+ * This method performs validation and addition in a single call:
470
+ * - Checks if the attestation already exists (returns alreadyExists: true if so)
471
+ * - Checks if this signer has reached the per-signer attestation cap for this slot
472
+ * - Adds the attestation if validation passes
147
473
  *
148
- * @param slot - The slot to check
149
- * @param proposalId - The proposal to check
150
- * @param committeeSize - Committee size for the slot
151
- * @returns True if the cap has been reached, false otherwise.
474
+ * @param attestation - The checkpoint attestation to add
475
+ * @returns Result indicating whether the attestation was added, existence info, and count of
476
+ * attestations by this signer for this slot (for equivocation detection)
152
477
  */
153
- hasReachedCheckpointAttestationCap(slot: SlotNumber, proposalId: string, committeeSize: number): Promise<boolean>;
478
+ public async tryAddCheckpointAttestation(attestation: CheckpointAttestation): Promise<TryAddResult> {
479
+ const slotNumber = attestation.payload.header.slotNumber;
480
+ const proposalId = attestation.archive.toString();
481
+ const sender = attestation.getSender();
154
482
 
155
- /** Returns whether the pool is empty. */
156
- isEmpty(): Promise<boolean>;
483
+ if (!sender) {
484
+ return { added: false, alreadyExists: false, count: 0 };
485
+ }
486
+
487
+ const signerAddress = sender.toString();
488
+
489
+ return await this.store.transactionAsync(async () => {
490
+ const key = this.getAttestationKey(slotNumber, proposalId, signerAddress);
491
+ const alreadyExists = await this.checkpointAttestations.hasAsync(key);
492
+
493
+ // Get count of attestations by this signer for this slot (for duplicate detection)
494
+ const signerAttestationCount = await this.getSignerAttestationCountForSlot(slotNumber, signerAddress);
495
+
496
+ if (alreadyExists) {
497
+ return {
498
+ added: false,
499
+ alreadyExists: true,
500
+ count: signerAttestationCount,
501
+ };
502
+ }
503
+
504
+ // Check if this signer has exceeded the per-signer cap for this slot
505
+ if (signerAttestationCount >= MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER) {
506
+ this.log.debug(`Rejecting attestation: signer ${signerAddress} exceeded per-slot cap for slot ${slotNumber}`, {
507
+ slotNumber,
508
+ signerAddress,
509
+ proposalId,
510
+ signerAttestationCount,
511
+ });
512
+ return {
513
+ added: false,
514
+ alreadyExists: false,
515
+ count: signerAttestationCount,
516
+ };
517
+ }
518
+
519
+ // Add the attestation
520
+ await this.checkpointAttestations.set(key, attestation.toBuffer());
521
+
522
+ // Track this attestation in the per-signer-per-slot index for duplicate detection
523
+ const slotSignerKey = this.getSlotSignerKey(slotNumber, signerAddress);
524
+ await this.checkpointAttestationsPerSlotAndSigner.set(slotSignerKey, proposalId);
525
+
526
+ this.log.debug(`Added checkpoint attestation for slot ${slotNumber} from ${signerAddress}`, {
527
+ signature: attestation.signature.toString(),
528
+ slotNumber,
529
+ address: signerAddress,
530
+ proposalId,
531
+ });
532
+
533
+ // Return the new count
534
+ return {
535
+ added: true,
536
+ alreadyExists: false,
537
+ count: signerAttestationCount + 1,
538
+ };
539
+ });
540
+ }
541
+
542
+ /** Gets the count of attestations by a specific signer for a given slot. */
543
+ private async getSignerAttestationCountForSlot(slot: SlotNumber, signerAddress: string): Promise<number> {
544
+ const slotSignerKey = this.getSlotSignerKey(slot, signerAddress);
545
+ return await this.checkpointAttestationsPerSlotAndSigner.getValueCountAsync(slotSignerKey);
546
+ }
547
+ }
548
+
549
+ /** Creates an AttestationPool backed by a temporary store for testing. */
550
+ export async function createTestAttestationPool(telemetry?: TelemetryClient): Promise<AttestationPool> {
551
+ const { openTmpStore } = await import('@aztec/kv-store/lmdb-v2');
552
+ const store = await openTmpStore('test-attestation-pool');
553
+ return new AttestationPool(store, telemetry);
157
554
  }