@aztec/p2p 0.0.1-commit.e6bd8901 → 0.0.1-commit.ec5f612

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