@aztec/p2p 0.0.1-commit.d3ec352c → 0.0.1-commit.e310a4c8

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 (379) 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 +2 -2
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +8 -8
  7. package/dest/client/interface.d.ts +18 -5
  8. package/dest/client/interface.d.ts.map +1 -1
  9. package/dest/client/p2p_client.d.ts +11 -14
  10. package/dest/client/p2p_client.d.ts.map +1 -1
  11. package/dest/client/p2p_client.js +464 -125
  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 +11 -8
  19. package/dest/config.d.ts.map +1 -1
  20. package/dest/config.js +12 -13
  21. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +61 -42
  22. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  23. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  24. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  25. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +239 -265
  26. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +21 -18
  27. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  28. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +114 -109
  29. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +17 -16
  30. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  31. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +89 -128
  32. package/dest/mem_pools/attestation_pool/mocks.d.ts +11 -8
  33. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  34. package/dest/mem_pools/attestation_pool/mocks.js +17 -13
  35. package/dest/mem_pools/instrumentation.d.ts +7 -1
  36. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  37. package/dest/mem_pools/instrumentation.js +31 -13
  38. package/dest/mem_pools/interface.d.ts +3 -4
  39. package/dest/mem_pools/interface.d.ts.map +1 -1
  40. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +35 -26
  41. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +314 -335
  43. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +32 -0
  44. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
  45. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +112 -0
  46. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +157 -0
  47. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
  48. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +52 -0
  49. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
  50. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  51. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -0
  52. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
  53. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  54. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
  55. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
  56. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  57. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +78 -0
  58. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
  59. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  60. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
  61. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
  62. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
  63. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
  64. package/dest/mem_pools/tx_pool/index.d.ts +1 -2
  65. package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
  66. package/dest/mem_pools/tx_pool/index.js +0 -1
  67. package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
  68. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
  69. package/dest/mem_pools/tx_pool/priority.js +6 -1
  70. package/dest/mem_pools/tx_pool/tx_pool.d.ts +8 -4
  71. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  72. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  73. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  74. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +25 -20
  75. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -4
  76. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  77. package/dest/msg_validators/attestation_validator/attestation_validator.js +52 -19
  78. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -5
  79. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  80. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +22 -13
  81. package/dest/msg_validators/clock_tolerance.d.ts +21 -0
  82. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
  83. package/dest/msg_validators/clock_tolerance.js +37 -0
  84. package/dest/msg_validators/index.d.ts +2 -2
  85. package/dest/msg_validators/index.d.ts.map +1 -1
  86. package/dest/msg_validators/index.js +1 -1
  87. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
  88. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
  89. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
  90. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
  91. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
  92. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
  93. package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
  94. package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
  95. package/dest/msg_validators/proposal_validator/index.js +3 -0
  96. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
  97. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
  98. package/dest/msg_validators/proposal_validator/proposal_validator.js +104 -0
  99. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
  100. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
  101. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +212 -0
  102. package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
  103. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
  104. package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
  105. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +5 -4
  106. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  107. package/dest/msg_validators/tx_validator/block_header_validator.js +3 -2
  108. package/dest/msg_validators/tx_validator/data_validator.d.ts +3 -1
  109. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  110. package/dest/msg_validators/tx_validator/data_validator.js +4 -1
  111. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +3 -2
  112. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  113. package/dest/msg_validators/tx_validator/double_spend_validator.js +3 -2
  114. package/dest/msg_validators/tx_validator/factory.d.ts +9 -4
  115. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  116. package/dest/msg_validators/tx_validator/factory.js +22 -12
  117. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
  118. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
  119. package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
  120. package/dest/msg_validators/tx_validator/gas_validator.d.ts +3 -2
  121. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  122. package/dest/msg_validators/tx_validator/gas_validator.js +11 -16
  123. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  124. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  125. package/dest/msg_validators/tx_validator/index.js +1 -0
  126. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +4 -3
  127. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  128. package/dest/msg_validators/tx_validator/metadata_validator.js +2 -2
  129. package/dest/msg_validators/tx_validator/phases_validator.d.ts +3 -2
  130. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  131. package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
  132. package/dest/msg_validators/tx_validator/size_validator.d.ts +8 -0
  133. package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
  134. package/dest/msg_validators/tx_validator/size_validator.js +23 -0
  135. package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
  136. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
  137. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +3 -2
  138. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  139. package/dest/msg_validators/tx_validator/timestamp_validator.js +2 -2
  140. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
  141. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
  142. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
  143. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +3 -2
  144. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  145. package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -2
  146. package/dest/services/data_store.d.ts +1 -1
  147. package/dest/services/data_store.d.ts.map +1 -1
  148. package/dest/services/data_store.js +10 -6
  149. package/dest/services/discv5/discV5_service.js +1 -1
  150. package/dest/services/dummy_service.d.ts +18 -2
  151. package/dest/services/dummy_service.d.ts.map +1 -1
  152. package/dest/services/dummy_service.js +42 -0
  153. package/dest/services/encoding.d.ts +1 -1
  154. package/dest/services/encoding.d.ts.map +1 -1
  155. package/dest/services/encoding.js +7 -6
  156. package/dest/services/libp2p/instrumentation.d.ts +1 -1
  157. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  158. package/dest/services/libp2p/instrumentation.js +30 -72
  159. package/dest/services/libp2p/libp2p_service.d.ts +39 -16
  160. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  161. package/dest/services/libp2p/libp2p_service.js +750 -187
  162. package/dest/services/peer-manager/metrics.d.ts +7 -2
  163. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  164. package/dest/services/peer-manager/metrics.js +33 -21
  165. package/dest/services/peer-manager/peer_manager.d.ts +2 -2
  166. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  167. package/dest/services/peer-manager/peer_manager.js +4 -12
  168. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  169. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  170. package/dest/services/peer-manager/peer_scoring.js +7 -4
  171. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +47 -0
  172. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
  173. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +566 -0
  174. package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
  175. package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
  176. package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
  177. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +50 -0
  178. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
  179. package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
  180. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +37 -0
  181. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
  182. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +151 -0
  183. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +54 -0
  184. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
  185. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +139 -0
  186. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +20 -0
  187. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
  188. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
  189. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +22 -3
  190. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  191. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +63 -4
  192. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -1
  193. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  194. package/dest/services/reqresp/connection-sampler/connection_sampler.js +12 -0
  195. package/dest/services/reqresp/constants.d.ts +12 -0
  196. package/dest/services/reqresp/constants.d.ts.map +1 -0
  197. package/dest/services/reqresp/constants.js +7 -0
  198. package/dest/services/reqresp/interface.d.ts +4 -2
  199. package/dest/services/reqresp/interface.d.ts.map +1 -1
  200. package/dest/services/reqresp/interface.js +1 -1
  201. package/dest/services/reqresp/metrics.d.ts +6 -5
  202. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  203. package/dest/services/reqresp/metrics.js +17 -21
  204. package/dest/services/reqresp/protocols/auth.d.ts +2 -2
  205. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
  206. package/dest/services/reqresp/protocols/auth.js +2 -2
  207. package/dest/services/reqresp/protocols/block.js +1 -1
  208. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +5 -1
  209. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  210. package/dest/services/reqresp/protocols/block_txs/bitvector.js +12 -0
  211. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
  212. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  213. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +16 -3
  214. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +19 -7
  215. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  216. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +44 -14
  217. package/dest/services/reqresp/protocols/status.d.ts +1 -1
  218. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  219. package/dest/services/reqresp/protocols/status.js +4 -1
  220. package/dest/services/reqresp/protocols/tx.d.ts +2 -3
  221. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  222. package/dest/services/reqresp/reqresp.d.ts +6 -1
  223. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  224. package/dest/services/reqresp/reqresp.js +460 -46
  225. package/dest/services/service.d.ts +19 -3
  226. package/dest/services/service.d.ts.map +1 -1
  227. package/dest/services/tx_collection/config.d.ts +4 -1
  228. package/dest/services/tx_collection/config.d.ts.map +1 -1
  229. package/dest/services/tx_collection/config.js +10 -2
  230. package/dest/services/tx_collection/fast_tx_collection.d.ts +6 -4
  231. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  232. package/dest/services/tx_collection/fast_tx_collection.js +16 -5
  233. package/dest/services/tx_collection/index.d.ts +2 -1
  234. package/dest/services/tx_collection/index.d.ts.map +1 -1
  235. package/dest/services/tx_collection/index.js +1 -0
  236. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  237. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  238. package/dest/services/tx_collection/instrumentation.js +10 -13
  239. package/dest/services/tx_collection/proposal_tx_collector.d.ts +48 -0
  240. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
  241. package/dest/services/tx_collection/proposal_tx_collector.js +50 -0
  242. package/dest/services/tx_collection/tx_collection.d.ts +6 -6
  243. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  244. package/dest/services/tx_collection/tx_collection.js +6 -6
  245. package/dest/services/tx_provider.d.ts +4 -3
  246. package/dest/services/tx_provider.d.ts.map +1 -1
  247. package/dest/services/tx_provider.js +11 -2
  248. package/dest/services/tx_provider_instrumentation.d.ts +5 -2
  249. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  250. package/dest/services/tx_provider_instrumentation.js +14 -14
  251. package/dest/test-helpers/index.d.ts +3 -1
  252. package/dest/test-helpers/index.d.ts.map +1 -1
  253. package/dest/test-helpers/index.js +2 -0
  254. package/dest/test-helpers/mock-tx-helpers.js +1 -1
  255. package/dest/test-helpers/reqresp-nodes.d.ts +2 -2
  256. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  257. package/dest/test-helpers/test_tx_provider.d.ts +40 -0
  258. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
  259. package/dest/test-helpers/test_tx_provider.js +41 -0
  260. package/dest/test-helpers/testbench-utils.d.ts +158 -0
  261. package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
  262. package/dest/test-helpers/testbench-utils.js +297 -0
  263. package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
  264. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  265. package/dest/testbench/p2p_client_testbench_worker.js +218 -123
  266. package/dest/testbench/worker_client_manager.d.ts +51 -6
  267. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  268. package/dest/testbench/worker_client_manager.js +226 -39
  269. package/package.json +16 -16
  270. package/src/bootstrap/bootstrap.ts +7 -4
  271. package/src/client/factory.ts +11 -20
  272. package/src/client/interface.ts +19 -4
  273. package/src/client/p2p_client.ts +97 -145
  274. package/src/client/test/tx_proposal_collector/README.md +227 -0
  275. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +336 -0
  276. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
  277. package/src/config.ts +18 -19
  278. package/src/mem_pools/attestation_pool/attestation_pool.ts +68 -41
  279. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +241 -289
  280. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +163 -141
  281. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +141 -164
  282. package/src/mem_pools/attestation_pool/mocks.ts +21 -15
  283. package/src/mem_pools/instrumentation.ts +39 -14
  284. package/src/mem_pools/interface.ts +2 -4
  285. package/src/mem_pools/tx_pool/README.md +270 -0
  286. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +362 -367
  287. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +132 -0
  288. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +208 -0
  289. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
  290. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
  291. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +93 -0
  292. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
  293. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
  294. package/src/mem_pools/tx_pool/index.ts +0 -1
  295. package/src/mem_pools/tx_pool/priority.ts +8 -1
  296. package/src/mem_pools/tx_pool/tx_pool.ts +8 -3
  297. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +18 -13
  298. package/src/msg_validators/attestation_validator/attestation_validator.ts +37 -22
  299. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +19 -16
  300. package/src/msg_validators/clock_tolerance.ts +51 -0
  301. package/src/msg_validators/index.ts +1 -1
  302. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
  303. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
  304. package/src/msg_validators/proposal_validator/index.ts +3 -0
  305. package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
  306. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -0
  307. package/src/msg_validators/tx_validator/archive_cache.ts +3 -3
  308. package/src/msg_validators/tx_validator/block_header_validator.ts +6 -5
  309. package/src/msg_validators/tx_validator/data_validator.ts +18 -6
  310. package/src/msg_validators/tx_validator/double_spend_validator.ts +4 -3
  311. package/src/msg_validators/tx_validator/factory.ts +65 -24
  312. package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
  313. package/src/msg_validators/tx_validator/gas_validator.ts +17 -28
  314. package/src/msg_validators/tx_validator/index.ts +1 -0
  315. package/src/msg_validators/tx_validator/metadata_validator.ts +19 -8
  316. package/src/msg_validators/tx_validator/phases_validator.ts +5 -3
  317. package/src/msg_validators/tx_validator/size_validator.ts +22 -0
  318. package/src/msg_validators/tx_validator/test_utils.ts +1 -1
  319. package/src/msg_validators/tx_validator/timestamp_validator.ts +9 -4
  320. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
  321. package/src/msg_validators/tx_validator/tx_proof_validator.ts +8 -3
  322. package/src/services/data_store.ts +10 -7
  323. package/src/services/discv5/discV5_service.ts +1 -1
  324. package/src/services/dummy_service.ts +51 -0
  325. package/src/services/encoding.ts +6 -5
  326. package/src/services/libp2p/instrumentation.ts +32 -73
  327. package/src/services/libp2p/libp2p_service.ts +418 -173
  328. package/src/services/peer-manager/metrics.ts +39 -21
  329. package/src/services/peer-manager/peer_manager.ts +5 -4
  330. package/src/services/peer-manager/peer_scoring.ts +3 -4
  331. package/src/services/reqresp/batch-tx-requester/README.md +305 -0
  332. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +706 -0
  333. package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
  334. package/src/services/reqresp/batch-tx-requester/interface.ts +57 -0
  335. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +209 -0
  336. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +205 -0
  337. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
  338. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +65 -4
  339. package/src/services/reqresp/connection-sampler/connection_sampler.ts +19 -1
  340. package/src/services/reqresp/constants.ts +14 -0
  341. package/src/services/reqresp/interface.ts +4 -1
  342. package/src/services/reqresp/metrics.ts +36 -27
  343. package/src/services/reqresp/protocols/auth.ts +2 -2
  344. package/src/services/reqresp/protocols/block.ts +1 -1
  345. package/src/services/reqresp/protocols/block_txs/bitvector.ts +16 -0
  346. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +18 -4
  347. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +52 -10
  348. package/src/services/reqresp/protocols/status.ts +7 -4
  349. package/src/services/reqresp/protocols/tx.ts +1 -2
  350. package/src/services/reqresp/reqresp.ts +66 -19
  351. package/src/services/service.ts +23 -4
  352. package/src/services/tx_collection/config.ts +16 -2
  353. package/src/services/tx_collection/fast_tx_collection.ts +36 -13
  354. package/src/services/tx_collection/index.ts +5 -0
  355. package/src/services/tx_collection/instrumentation.ts +5 -13
  356. package/src/services/tx_collection/proposal_tx_collector.ts +114 -0
  357. package/src/services/tx_collection/tx_collection.ts +7 -7
  358. package/src/services/tx_provider.ts +19 -4
  359. package/src/services/tx_provider_instrumentation.ts +24 -14
  360. package/src/test-helpers/index.ts +2 -0
  361. package/src/test-helpers/mock-pubsub.ts +1 -1
  362. package/src/test-helpers/mock-tx-helpers.ts +1 -1
  363. package/src/test-helpers/reqresp-nodes.ts +1 -1
  364. package/src/test-helpers/test_tx_provider.ts +64 -0
  365. package/src/test-helpers/testbench-utils.ts +374 -0
  366. package/src/testbench/p2p_client_testbench_worker.ts +338 -119
  367. package/src/testbench/worker_client_manager.ts +304 -42
  368. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -81
  369. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
  370. package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -239
  371. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
  372. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
  373. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -82
  374. package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
  375. package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
  376. package/dest/msg_validators/block_proposal_validator/index.js +0 -1
  377. package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -285
  378. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -97
  379. package/src/msg_validators/block_proposal_validator/index.ts +0 -1
@@ -1,31 +1,29 @@
1
- import { GENESIS_BLOCK_HEADER_HASH, INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
1
+ import { GENESIS_BLOCK_HEADER_HASH } from '@aztec/constants';
2
2
  import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import { DateProvider } from '@aztec/foundation/timer';
5
- import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncSingleton } from '@aztec/kv-store';
6
- import type {
7
- EthAddress,
8
- L2Block,
9
- L2BlockId,
10
- L2BlockSource,
5
+ import type { AztecAsyncKVStore, AztecAsyncSingleton } from '@aztec/kv-store';
6
+ import { L2TipsKVStore } from '@aztec/kv-store/stores';
7
+ import {
8
+ type EthAddress,
9
+ type L2Block,
10
+ type L2BlockSource,
11
11
  L2BlockStream,
12
- L2BlockStreamEvent,
13
- L2Tips,
14
- PublishedL2Block,
12
+ type L2BlockStreamEvent,
13
+ type L2Tips,
14
+ type L2TipsStore,
15
15
  } from '@aztec/stdlib/block';
16
16
  import type { ContractDataSource } from '@aztec/stdlib/contract';
17
17
  import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
18
18
  import { type PeerInfo, tryStop } from '@aztec/stdlib/interfaces/server';
19
- import { BlockAttestation, type BlockProposal, type P2PClientType } from '@aztec/stdlib/p2p';
20
- import type { Tx, TxHash } from '@aztec/stdlib/tx';
21
19
  import {
22
- Attributes,
23
- type TelemetryClient,
24
- TraceableL2BlockStream,
25
- WithTracer,
26
- getTelemetryClient,
27
- trackSpan,
28
- } from '@aztec/telemetry-client';
20
+ type BlockProposal,
21
+ CheckpointAttestation,
22
+ type CheckpointProposal,
23
+ type P2PClientType,
24
+ } from '@aztec/stdlib/p2p';
25
+ import type { Tx, TxHash } from '@aztec/stdlib/tx';
26
+ import { Attributes, type TelemetryClient, WithTracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
29
27
 
30
28
  import type { PeerId } from '@libp2p/interface';
31
29
  import type { ENR } from '@nethermindeth/enr';
@@ -41,7 +39,7 @@ import {
41
39
  type ReqRespSubProtocolValidators,
42
40
  } from '../services/reqresp/interface.js';
43
41
  import { chunkTxHashesRequest } from '../services/reqresp/protocols/tx.js';
44
- import type { P2PBlockReceivedCallback, P2PService } from '../services/service.js';
42
+ import type { P2PBlockReceivedCallback, P2PCheckpointReceivedCallback, P2PService } from '../services/service.js';
45
43
  import { TxCollection } from '../services/tx_collection/tx_collection.js';
46
44
  import { TxProvider } from '../services/tx_provider.js';
47
45
  import { type P2P, P2PClientState, type P2PSyncState } from './interface.js';
@@ -63,14 +61,11 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
63
61
  private provenBlockNumberAtStart = -1;
64
62
  private finalizedBlockNumberAtStart = -1;
65
63
 
66
- private synchedBlockHashes: AztecAsyncMap<BlockNumber, string>;
67
- private synchedLatestBlockNumber: AztecAsyncSingleton<BlockNumber>;
68
- private synchedProvenBlockNumber: AztecAsyncSingleton<BlockNumber>;
69
- private synchedFinalizedBlockNumber: AztecAsyncSingleton<BlockNumber>;
64
+ private l2Tips: L2TipsStore;
70
65
  private synchedLatestSlot: AztecAsyncSingleton<bigint>;
71
66
 
72
67
  private txPool: TxPool;
73
- private attestationPool: T extends P2PClientType.Full ? AttestationPool : undefined;
68
+ private attestationPool: AttestationPool;
74
69
 
75
70
  private config: P2PConfig;
76
71
 
@@ -92,7 +87,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
92
87
  _clientType: T,
93
88
  private store: AztecAsyncKVStore,
94
89
  private l2BlockSource: L2BlockSource & ContractDataSource,
95
- mempools: MemPools<T>,
90
+ mempools: MemPools,
96
91
  private p2pService: P2PService,
97
92
  private txCollection: TxCollection,
98
93
  config: Partial<P2PConfig> = {},
@@ -104,7 +99,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
104
99
 
105
100
  this.config = { ...getP2PDefaultConfig(), ...config };
106
101
  this.txPool = mempools.txPool;
107
- this.attestationPool = mempools.attestationPool!;
102
+ this.attestationPool = mempools.attestationPool;
108
103
 
109
104
  this.txProvider = new TxProvider(
110
105
  this.txCollection,
@@ -115,7 +110,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
115
110
  );
116
111
 
117
112
  // Default to collecting all txs when we see a valid proposal
118
- // This can be overridden by the validator client to attest, and it will call getTxsForBlockProposal on its own
113
+ // This can be overridden by the validator client to validate, and it will call getTxsForBlockProposal on its own
114
+ // Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
119
115
  // TODO(palla/txs): We should not trigger a request for txs on a proposal before fully validating it. We need to bring
120
116
  // validator-client code into here so we can validate a proposal is reasonable.
121
117
  this.registerBlockProposalHandler(async (block, sender) => {
@@ -124,21 +120,17 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
124
120
  const constants = this.txCollection.getConstants();
125
121
  const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(block.slotNumber + 1), constants));
126
122
  const deadline = new Date(nextSlotTimestampSeconds * 1000);
127
- const parentBlock = await this.l2BlockSource.getBlockHeaderByArchive(block.payload.header.lastArchiveRoot);
123
+ const parentBlock = await this.l2BlockSource.getBlockHeaderByArchive(block.blockHeader.lastArchive.root);
128
124
  if (!parentBlock) {
129
125
  this.log.debug(`Cannot collect txs for proposal as parent block not found`);
130
- return;
126
+ return false;
131
127
  }
132
128
  const blockNumber = BlockNumber(parentBlock.getBlockNumber() + 1);
133
129
  await this.txProvider.getTxsForBlockProposal(block, blockNumber, { pinnedPeer: sender, deadline });
134
- return undefined;
130
+ return true;
135
131
  });
136
132
 
137
- // REFACTOR: Try replacing these with an L2TipsStore
138
- this.synchedBlockHashes = store.openMap('p2p_pool_block_hashes');
139
- this.synchedLatestBlockNumber = store.openSingleton('p2p_pool_last_l2_block');
140
- this.synchedProvenBlockNumber = store.openSingleton('p2p_pool_last_proven_l2_block');
141
- this.synchedFinalizedBlockNumber = store.openSingleton('p2p_pool_last_finalized_l2_block');
133
+ this.l2Tips = new L2TipsKVStore(store, 'p2p_client');
142
134
  this.synchedLatestSlot = store.openSingleton('p2p_pool_last_l2_slot');
143
135
  }
144
136
 
@@ -164,7 +156,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
164
156
  }
165
157
 
166
158
  public getL2BlockHash(number: BlockNumber): Promise<string | undefined> {
167
- return this.synchedBlockHashes.getAsync(number);
159
+ return this.l2Tips.getL2BlockHash(number);
168
160
  }
169
161
 
170
162
  public updateP2PConfig(config: Partial<P2PConfig>): Promise<void> {
@@ -173,84 +165,45 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
173
165
  return Promise.resolve();
174
166
  }
175
167
 
176
- public async getL2Tips(): Promise<L2Tips> {
177
- const latestBlockNumber = await this.getSyncedLatestBlockNum();
178
- let latestBlockHash: string | undefined;
179
-
180
- const provenBlockNumber = await this.getSyncedProvenBlockNum();
181
- let provenBlockHash: string | undefined;
182
-
183
- const finalizedBlockNumber = await this.getSyncedFinalizedBlockNum();
184
- let finalizedBlockHash: string | undefined;
185
-
186
- if (latestBlockNumber > 0) {
187
- latestBlockHash = await this.synchedBlockHashes.getAsync(latestBlockNumber);
188
- if (typeof latestBlockHash === 'undefined') {
189
- throw new Error(`Block hash for latest block ${latestBlockNumber} not found in p2p client`);
190
- }
191
- }
192
-
193
- if (provenBlockNumber > 0) {
194
- provenBlockHash = await this.synchedBlockHashes.getAsync(provenBlockNumber);
195
- if (typeof provenBlockHash === 'undefined') {
196
- throw new Error(`Block hash for proven block ${provenBlockNumber} not found in p2p client`);
197
- }
198
- }
199
-
200
- if (finalizedBlockNumber > 0) {
201
- finalizedBlockHash = await this.synchedBlockHashes.getAsync(finalizedBlockNumber);
202
- if (typeof finalizedBlockHash === 'undefined') {
203
- throw new Error(`Block hash for finalized block ${finalizedBlockNumber} not found in p2p client`);
204
- }
205
- }
206
-
207
- const genesisHash = GENESIS_BLOCK_HEADER_HASH.toString();
208
-
209
- return {
210
- latest: { hash: latestBlockHash ?? genesisHash, number: latestBlockNumber },
211
- proven: { hash: provenBlockHash ?? genesisHash, number: provenBlockNumber },
212
- finalized: { hash: finalizedBlockHash ?? genesisHash, number: finalizedBlockNumber },
213
- };
168
+ public getL2Tips(): Promise<L2Tips> {
169
+ return this.l2Tips.getL2Tips();
214
170
  }
215
171
 
216
172
  public async handleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void> {
217
173
  this.log.debug(`Handling block stream event ${event.type}`);
174
+
218
175
  switch (event.type) {
219
176
  case 'blocks-added':
220
177
  await this.handleLatestL2Blocks(event.blocks);
221
178
  break;
222
179
  case 'chain-finalized': {
223
- // TODO (alexg): I think we can prune the block hashes map here
224
- await this.setBlockHash(event.block);
225
- const from = BlockNumber((await this.getSyncedFinalizedBlockNum()) + 1);
180
+ const oldFinalizedBlockNum = await this.getSyncedFinalizedBlockNum();
181
+ const from = BlockNumber(oldFinalizedBlockNum + 1);
226
182
  const limit = event.block.number - from + 1;
227
183
  if (limit > 0) {
228
- await this.handleFinalizedL2Blocks(await this.l2BlockSource.getBlocks(from, limit));
184
+ const oldBlocks = await this.l2BlockSource.getBlocks(from, limit);
185
+ await this.handleFinalizedL2Blocks(oldBlocks);
229
186
  }
230
187
  break;
231
188
  }
232
- case 'chain-proven': {
233
- await this.setBlockHash(event.block);
189
+ case 'chain-proven':
234
190
  this.txCollection.stopCollectingForBlocksUpTo(event.block.number);
235
- await this.synchedProvenBlockNumber.set(event.block.number);
236
191
  break;
237
- }
238
192
  case 'chain-pruned':
239
- await this.setBlockHash(event.block);
240
193
  this.txCollection.stopCollectingForBlocksAfter(event.block.number);
241
194
  await this.handlePruneL2Blocks(event.block.number);
242
195
  break;
196
+ case 'chain-checkpointed':
197
+ break;
243
198
  default: {
244
199
  const _: never = event;
245
200
  break;
246
201
  }
247
202
  }
248
- }
249
203
 
250
- private async setBlockHash(block: L2BlockId): Promise<void> {
251
- if (block.hash !== undefined) {
252
- await this.synchedBlockHashes.set(block.number, block.hash.toString());
253
- }
204
+ // Pass the event through to our l2 tips store
205
+ await this.l2Tips.handleBlockStreamEvent(event);
206
+ await this.startServiceIfSynched();
254
207
  }
255
208
 
256
209
  #assertIsReady() {
@@ -274,18 +227,15 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
274
227
 
275
228
  // get the current latest block numbers
276
229
  const latestBlockNumbers = await this.l2BlockSource.getL2Tips();
277
- this.latestBlockNumberAtStart = latestBlockNumbers.latest.number;
278
- this.provenBlockNumberAtStart = latestBlockNumbers.proven.number;
279
- this.finalizedBlockNumberAtStart = latestBlockNumbers.finalized.number;
230
+ this.latestBlockNumberAtStart = latestBlockNumbers.proposed.number;
231
+ this.provenBlockNumberAtStart = latestBlockNumbers.proven.block.number;
232
+ this.finalizedBlockNumberAtStart = latestBlockNumbers.finalized.block.number;
280
233
 
281
234
  const syncedLatestBlock = (await this.getSyncedLatestBlockNum()) + 1;
282
235
  const syncedProvenBlock = (await this.getSyncedProvenBlockNum()) + 1;
283
236
  const syncedFinalizedBlock = (await this.getSyncedFinalizedBlockNum()) + 1;
284
237
 
285
- if (
286
- (await this.txPool.isEmpty()) &&
287
- (this.attestationPool === undefined || (await this.attestationPool?.isEmpty()))
288
- ) {
238
+ if ((await this.txPool.isEmpty()) && (await this.attestationPool.isEmpty())) {
289
239
  // if mempools are empty, we don't care about syncing prior blocks
290
240
  this.initBlockStream(BlockNumber(this.latestBlockNumberAtStart));
291
241
  this.setCurrentState(P2PClientState.RUNNING);
@@ -338,12 +288,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
338
288
  private initBlockStream(startingBlock?: BlockNumber) {
339
289
  if (!this.blockStream) {
340
290
  const { blockRequestBatchSize: batchSize, blockCheckIntervalMS: pollIntervalMS } = this.config;
341
- this.blockStream = new TraceableL2BlockStream(
291
+ this.blockStream = new L2BlockStream(
342
292
  this.l2BlockSource,
343
293
  this,
344
294
  this,
345
- this.telemetry.getTracer('P2PL2BlockStream'),
346
- 'P2PL2BlockStream',
347
295
  createLogger(`${this.log.module}:l2-block-stream`),
348
296
  { batchSize, pollIntervalMS, startingBlock },
349
297
  );
@@ -378,30 +326,44 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
378
326
  [Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
379
327
  [Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString(),
380
328
  }))
381
- public broadcastProposal(proposal: BlockProposal): Promise<void> {
329
+ public async broadcastProposal(proposal: BlockProposal): Promise<void> {
382
330
  this.log.verbose(`Broadcasting proposal for slot ${proposal.slotNumber} to peers`);
331
+ // Store our own proposal so we can respond to req/resp requests for it
332
+ await this.attestationPool.addBlockProposal(proposal);
383
333
  return this.p2pService.propagate(proposal);
384
334
  }
385
335
 
386
- public async broadcastAttestations(attestations: BlockAttestation[]): Promise<void> {
387
- this.log.verbose(`Broadcasting ${attestations.length} attestations to peers`);
388
- await Promise.all(attestations.map(att => this.p2pService.propagate(att)));
336
+ @trackSpan('p2pClient.broadcastCheckpointProposal', async proposal => ({
337
+ [Attributes.SLOT_NUMBER]: proposal.slotNumber,
338
+ [Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
339
+ [Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString(),
340
+ }))
341
+ public async broadcastCheckpointProposal(proposal: CheckpointProposal): Promise<void> {
342
+ this.log.verbose(`Broadcasting checkpoint proposal for slot ${proposal.slotNumber} to peers`);
343
+ const blockProposal = proposal.getBlockProposal();
344
+ if (blockProposal) {
345
+ // Store our own last-block proposal so we can respond to req/resp requests for it.
346
+ await this.attestationPool.addBlockProposal(blockProposal);
347
+ }
348
+ return this.p2pService.propagate(proposal);
389
349
  }
390
350
 
391
- public async getAttestationsForSlot(slot: SlotNumber, proposalId?: string): Promise<BlockAttestation[]> {
392
- return (
393
- (await (proposalId
394
- ? this.attestationPool?.getAttestationsForSlotAndProposal(slot, proposalId)
395
- : this.attestationPool?.getAttestationsForSlot(slot))) ?? []
396
- );
351
+ public async broadcastCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void> {
352
+ this.log.verbose(`Broadcasting ${attestations.length} checkpoint attestations to peers`);
353
+ await Promise.all(attestations.map(att => this.p2pService.propagate(att)));
397
354
  }
398
355
 
399
- public addAttestations(attestations: BlockAttestation[]): Promise<void> {
400
- return this.attestationPool?.addAttestations(attestations) ?? Promise.resolve();
356
+ public async getCheckpointAttestationsForSlot(
357
+ slot: SlotNumber,
358
+ proposalId?: string,
359
+ ): Promise<CheckpointAttestation[]> {
360
+ return await (proposalId
361
+ ? this.attestationPool.getCheckpointAttestationsForSlotAndProposal(slot, proposalId)
362
+ : this.attestationPool.getCheckpointAttestationsForSlot(slot));
401
363
  }
402
364
 
403
- public deleteAttestation(attestation: BlockAttestation): Promise<void> {
404
- return this.attestationPool?.deleteAttestations([attestation]) ?? Promise.resolve();
365
+ public addCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void> {
366
+ return this.attestationPool.addCheckpointAttestations(attestations);
405
367
  }
406
368
 
407
369
  // REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
@@ -410,6 +372,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
410
372
  this.p2pService.registerBlockReceivedCallback(handler);
411
373
  }
412
374
 
375
+ public registerCheckpointProposalHandler(handler: P2PCheckpointReceivedCallback): void {
376
+ this.p2pService.registerCheckpointReceivedCallback(handler);
377
+ }
378
+
413
379
  /**
414
380
  * Uses the batched Request Response protocol to request a set of transactions from the network.
415
381
  */
@@ -652,7 +618,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
652
618
  * @returns Block number of latest L2 Block we've synced with.
653
619
  */
654
620
  public async getSyncedLatestBlockNum(): Promise<BlockNumber> {
655
- return (await this.synchedLatestBlockNumber.getAsync()) ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
621
+ const tips = await this.l2Tips.getL2Tips();
622
+ return tips.proposed.number;
656
623
  }
657
624
 
658
625
  /**
@@ -660,11 +627,13 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
660
627
  * @returns Block number of latest proven L2 Block we've synced with.
661
628
  */
662
629
  public async getSyncedProvenBlockNum(): Promise<BlockNumber> {
663
- return (await this.synchedProvenBlockNumber.getAsync()) ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
630
+ const tips = await this.l2Tips.getL2Tips();
631
+ return tips.proven.block.number;
664
632
  }
665
633
 
666
634
  public async getSyncedFinalizedBlockNum(): Promise<BlockNumber> {
667
- return (await this.synchedFinalizedBlockNumber.getAsync()) ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
635
+ const tips = await this.l2Tips.getL2Tips();
636
+ return tips.finalized.block.number;
668
637
  }
669
638
 
670
639
  /** Returns latest L2 slot for which we have seen an L2 block. */
@@ -700,7 +669,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
700
669
  private async markTxsAsMinedFromBlocks(blocks: L2Block[]): Promise<void> {
701
670
  for (const block of blocks) {
702
671
  const txHashes = block.body.txEffects.map(txEffect => txEffect.txHash);
703
- await this.txPool.markAsMined(txHashes, block.getBlockHeader());
672
+ await this.txPool.markAsMined(txHashes, block.header);
704
673
  }
705
674
  }
706
675
 
@@ -709,29 +678,18 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
709
678
  * @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
710
679
  * @returns Empty promise.
711
680
  */
712
- private async handleLatestL2Blocks(blocks: PublishedL2Block[]): Promise<void> {
681
+ private async handleLatestL2Blocks(blocks: L2Block[]): Promise<void> {
713
682
  if (!blocks.length) {
714
683
  return Promise.resolve();
715
684
  }
716
685
 
717
- await this.markTxsAsMinedFromBlocks(blocks.map(b => b.block));
718
- await this.startCollectingMissingTxs(blocks.map(b => b.block));
719
-
720
- const lastBlock = blocks.at(-1)!.block;
686
+ await this.markTxsAsMinedFromBlocks(blocks);
687
+ await this.txPool.clearNonEvictableTxs();
688
+ await this.startCollectingMissingTxs(blocks);
721
689
 
722
- await Promise.all(
723
- blocks.map(async block =>
724
- this.setBlockHash({
725
- number: block.block.number,
726
- hash: await block.block.hash().then(h => h.toString()),
727
- }),
728
- ),
729
- );
730
-
731
- await this.synchedLatestBlockNumber.set(lastBlock.number);
690
+ const lastBlock = blocks.at(-1)!;
732
691
  await this.synchedLatestSlot.set(BigInt(lastBlock.header.getSlot()));
733
692
  this.log.verbose(`Synched to latest block ${lastBlock.number}`);
734
- await this.startServiceIfSynched();
735
693
  }
736
694
 
737
695
  /** Request txs for unproven blocks so the prover node has more chances to get them. */
@@ -782,12 +740,9 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
782
740
  await this.txPool.deleteTxs(txHashes, { permanently: true });
783
741
  await this.txPool.cleanupDeletedMinedTxs(lastBlockNum);
784
742
 
785
- await this.attestationPool?.deleteAttestationsOlderThan(lastBlockSlot);
743
+ await this.attestationPool.deleteCheckpointAttestationsOlderThan(lastBlockSlot);
786
744
 
787
- await this.synchedFinalizedBlockNumber.set(lastBlockNum);
788
745
  this.log.debug(`Synched to finalized block ${lastBlockNum} at slot ${lastBlockSlot}`);
789
-
790
- await this.startServiceIfSynched();
791
746
  }
792
747
 
793
748
  /**
@@ -833,21 +788,18 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
833
788
  this.log.info(`Deleting ${minedTxsFromReorg.length} mined txs from reorg`);
834
789
  await this.txPool.deleteTxs(minedTxsFromReorg);
835
790
  } else {
836
- this.log.info(`Moving ${minedTxsFromReorg.length} mined txs from reorg back to pending`);
837
- await this.txPool.markMinedAsPending(minedTxsFromReorg);
791
+ await this.txPool.markMinedAsPending(minedTxsFromReorg, latestBlock);
838
792
  }
839
-
840
- await this.synchedLatestBlockNumber.set(latestBlock);
841
- // no need to update block hashes, as they will be updated as new blocks are added
842
793
  }
843
794
 
844
795
  private async startServiceIfSynched() {
845
796
  if (this.currentState !== P2PClientState.SYNCHING) {
846
797
  return;
847
798
  }
848
- const syncedFinalizedBlock = await this.getSyncedFinalizedBlockNum();
849
- const syncedProvenBlock = await this.getSyncedProvenBlockNum();
850
- const syncedLatestBlock = await this.getSyncedLatestBlockNum();
799
+ const tips = await this.l2Tips.getL2Tips();
800
+ const syncedFinalizedBlock = tips.finalized.block.number;
801
+ const syncedProvenBlock = tips.proven.block.number;
802
+ const syncedLatestBlock = tips.proposed.number;
851
803
 
852
804
  if (
853
805
  syncedLatestBlock >= this.latestBlockNumberAtStart &&
@@ -0,0 +1,227 @@
1
+ # ProposalTxCollector Benchmarks
2
+
3
+ This benchmark suite measures **how quickly a proposer node can fetch missing transactions from P2P peers** when building a block proposal. It compares two alternative transaction-collection implementations under several controlled "who-has-which-txs" distributions.
4
+
5
+ ## Purpose
6
+
7
+ When proposing a block, the node may have a block proposal containing a list of `txHashes`, but may be **missing the full `Tx` objects** locally. The node must fetch those missing txs from peers via the P2P req/resp layer.
8
+
9
+ This benchmark answers:
10
+
11
+ - How long does it take to fetch **N missing txs** (N ∈ **{10, 50, 100, 500}**)?
12
+ - How do different **peer availability patterns** affect performance?
13
+ - Which collector strategy performs better under each pattern?
14
+
15
+ The suite compares two collectors:
16
+
17
+ - **`BatchTxRequesterCollector`** (collector type: `batch-requester`)
18
+ - **`SendBatchRequestCollector`** (collector type: `send-batch-request`)
19
+
20
+ ## Architecture
21
+
22
+ The benchmark runs a small simulated network on localhost:
23
+
24
+ ```
25
+ ┌─────────────────────────────────────────────────────────────────────┐
26
+ │ Test Process (Driver) │
27
+ │ p2p_client.proposal_tx_collector.bench.test.ts │
28
+ │ ┌─────────────────────────────────────────────────────────────┐ │
29
+ │ │ WorkerClientManager │ │
30
+ │ │ (src/testbench/worker_client_manager.ts) │ │
31
+ │ └─────────────────────────────────────────────────────────────┘ │
32
+ │ │ IPC │
33
+ │ ┌────────────────────┼────────────────────┐ │
34
+ │ ▼ ▼ ▼ │
35
+ │ ┌───────────┐ ┌───────────┐ ┌───────────┐ │
36
+ │ │ Worker 0 │◄──────►│ Worker 1 │◄──────►│ Worker N-1│ │
37
+ │ │ (Collector│ P2P │(Responder)│ P2P │(Responder)│ │
38
+ │ │ Node) │ │ │ │ │ │
39
+ │ │ TxPool:[] │ │ TxPool: │ │ TxPool: │ │
40
+ │ │ │ │ [txs...] │ │ [txs...] │ │
41
+ │ └───────────┘ └───────────┘ └───────────┘ │
42
+ └─────────────────────────────────────────────────────────────────────┘
43
+ ```
44
+
45
+ - **N worker processes** are spawned using Node's **`child_process.fork()`**
46
+ - Each worker runs a "light" **`P2PClient.Full`** node (enough to exercise the real P2P req/resp machinery)
47
+ - Workers communicate with the test process via **IPC messages** defined in `p2p_client_testbench_worker.ts`
48
+
49
+ ### Why multiple processes?
50
+
51
+ Using separate OS processes makes the setup closer to real networking behavior (independent event loops, scheduling, IPC boundaries), and avoids many artifacts you'd get by running everything in one process.
52
+
53
+ ### Worker roles
54
+
55
+ The network is intentionally asymmetric:
56
+
57
+ - **Worker 0 is the collector/proposer node**
58
+ - Starts with an **empty tx pool** (`[]`)
59
+ - Is the only worker instructed to run the collector for each `BENCH_REQRESP` command
60
+ - **Workers 1..N-1 are responder peers**
61
+ - Locally generate and filter txs according to the distribution pattern
62
+ - Respond to req/resp queries made by Worker 0's collector
63
+
64
+ This models a proposer that has only `txHashes` in a proposal and must fetch the full tx bodies from the network.
65
+
66
+ ## Transaction Distribution Patterns
67
+
68
+ Each benchmark case generates `missingTxCount` mock txs and assigns them to peers using one of these patterns:
69
+
70
+ ### `uniform`
71
+
72
+ **Every responder peer has every transaction.**
73
+
74
+ - Simulates the best-case: high replication / high gossip success
75
+ - Expectation: collector should quickly succeed; differences mostly reflect collector overhead and batching strategy
76
+
77
+ ### `sparse`
78
+
79
+ **Each transaction exists on only a small subset of peers.**
80
+
81
+ Each responder is bucketed and holds txs whose index falls into its bucket or the "next" bucket (striped by tx index).
82
+
83
+ - Simulates partial propagation, churn, or uneven mempool convergence
84
+ - Expectation: collector must query multiple peers and cope with "misses"
85
+
86
+ ### `pinned-only`
87
+
88
+ **Only a single "pinned" peer has the transactions; all other peers have none.**
89
+
90
+ - Simulates "I know exactly who has the txs" (or a topology where one peer is the source of truth)
91
+ - Useful to test whether "pinned peer" fast-paths work as intended
92
+
93
+ > **Guardrail:** the pinned peer index must be within `(0, numberOfPeers)` (Worker 0 cannot be pinned).
94
+
95
+ ## Collectors Under Test
96
+
97
+ ### `BatchTxRequesterCollector` (`batch-requester`)
98
+
99
+ ```typescript
100
+ new BatchTxRequesterCollector(p2pService, logger, new DateProvider())
101
+ ```
102
+
103
+ Uses the P2P service plus internal logic to fetch missing txs, coordinating requests in a batched or staged way.
104
+
105
+ ### `SendBatchRequestCollector` (`send-batch-request`)
106
+
107
+ ```typescript
108
+ const maxPeers = 10;
109
+ const maxRetryAttempts = Math.max(peerIds.length, 3);
110
+ new SendBatchRequestCollector(p2pService, maxPeers, maxRetryAttempts)
111
+ ```
112
+
113
+ Explicitly caps the number of peers it will involve (`maxPeers`) and uses a retry budget derived from peer count.
114
+
115
+ ## Test Parameters
116
+
117
+ | Parameter | Value | Description |
118
+ |-----------|-------|-------------|
119
+ | `PEERS_PER_RUN` | 30 | Number of worker processes spawned |
120
+ | `MISSING_TX_COUNTS` | 10, 50, 100, 500 | Number of missing transactions to fetch |
121
+ | `TIMEOUT_MS` | 30,000 ms | Collector timeout per case |
122
+ | `TEST_TIMEOUT_MS` | 600,000 ms | Overall Jest timeout (10 minutes) |
123
+
124
+ ## Running
125
+
126
+ From the p2p package:
127
+
128
+ ```bash
129
+ cd yarn-project/p2p
130
+ yarn test src/client/test/tx_proposal_collector/p2p_client.proposal_tx_collector.bench.test.ts
131
+ ```
132
+
133
+ Or from repo root:
134
+
135
+ ```bash
136
+ yarn test p2p_client.proposal_tx_collector.bench.test.ts
137
+ ```
138
+
139
+ The benchmark is intentionally long due to spawning many processes and running multiple cases.
140
+
141
+ ## Output Formats
142
+
143
+ ### Default: Markdown table to stdout
144
+
145
+ If no env vars are set, the suite prints a table:
146
+
147
+ ```
148
+ | Collector | Distribution | Missing | Duration (ms) | Fetched | Success |
149
+ |---------------------|--------------|---------|---------------|---------|---------|
150
+ | batch-requester | pinned-only | 10 | 123 | 10 | Yes |
151
+ | send-batch-request | pinned-only | 10 | 145 | 10 | Yes |
152
+ ```
153
+
154
+ Plus a comparison summary stating which collector was faster per `(distribution, missing)` pair.
155
+
156
+ ### JSON metrics (for CI/dashboards)
157
+
158
+ ```bash
159
+ BENCH_OUTPUT=/path/results.json yarn test ...
160
+ ```
161
+
162
+ Writes JSON metrics like:
163
+ - `ProposalTxCollector/<collector>/<distribution>/missing_<N>/duration` (ms)
164
+ - `ProposalTxCollector/<collector>/<distribution>/missing_<N>/fetched` (txs)
165
+
166
+ ### Markdown file output
167
+
168
+ ```bash
169
+ BENCH_OUTPUT_MD=/path/results.md yarn test ...
170
+ ```
171
+
172
+ Writes the pretty table + summary to disk.
173
+
174
+ ## Interpreting Results
175
+
176
+ For each case the benchmark records:
177
+
178
+ - `durationMs`: wall-clock time spent inside the collector call
179
+ - `fetchedCount`: how many txs were returned by the collector
180
+ - `success`: `fetchedCount === missingTxCount`
181
+
182
+ **Guidelines:**
183
+
184
+ - **Always check `Success` first.** A faster run that fetched fewer txs is not a win.
185
+ - Compare collectors **within the same distribution + missing count** only.
186
+ - Expect `pinned-only` to highlight pinned-peer behavior (fast if pinned peer is used effectively; slow if the algorithm wastes time sampling other peers).
187
+ - Expect `sparse` to be the most "network-like" stress case, since many peers won't have each requested tx.
188
+
189
+ ## Determinism / Noise Reduction
190
+
191
+ Inside each worker, the benchmark intentionally reduces variability:
192
+
193
+ - **Unlimited rate limits** are installed so the req/resp rate limiter doesn't dominate results
194
+ - **Deterministic tx generation** ensures all workers see the same tx set without large IPC payloads
195
+
196
+ This makes the benchmark better for *comparing collectors* (A vs B), but it is **not** a perfect model of production networking conditions.
197
+
198
+ ## Limitations
199
+
200
+ This benchmark does **not** measure:
201
+
202
+ - Real internet latency, NAT traversal, or adversarial peers (everything runs on localhost)
203
+ - End-to-end proposer behavior beyond tx fetching (block construction, proving, etc.)
204
+ - Gossip-based mempool convergence—tx availability is injected directly into each worker's in-memory tx pool
205
+
206
+ ## Files
207
+
208
+ | File | Purpose |
209
+ |------|---------|
210
+ | `p2p_client.proposal_tx_collector.bench.test.ts` | Test suite (cases, distributions, output formatting) |
211
+ | `proposal_tx_collector_worker.ts` | Collector-specific worker implementation |
212
+ | `proposal_tx_collector_worker_protocol.ts` | IPC message types and serialization |
213
+ | `src/testbench/worker_client_manager.ts` | Worker process manager (forking, IPC, orchestration) |
214
+ | `src/testbench/p2p_client_testbench_worker.ts` | General testbench worker implementation |
215
+ | `src/test-helpers/testbench-utils.ts` | Shared mocks and utilities (InMemoryTxPool, InMemoryAttestationPool, etc.) |
216
+
217
+ ## Implementation Notes
218
+
219
+ - Workers run TypeScript via `ts-node/esm` unless a compiled JS worker exists at `dest/testbench/p2p_client_testbench_worker.js`
220
+ - Request/response rate limits are overridden so the benchmark is not throttled
221
+ - Workers generate txs locally from a shared seed to avoid sending large tx payloads over IPC
222
+
223
+ ## Practical Tips
224
+
225
+ - Run on an otherwise idle machine; CPU scheduling noise matters when spawning 30 node processes
226
+ - If you see intermittent failures, increase `TIMEOUT_MS` or reduce `PEERS_PER_RUN` for local iteration
227
+ - Use `BENCH_OUTPUT` in CI to track performance regressions over time