@aztec/p2p 0.0.1-commit.6c91f13 → 0.0.1-commit.6d63667d

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 (437) 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 +1 -1
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +9 -6
  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 +13 -14
  10. package/dest/client/p2p_client.d.ts.map +1 -1
  11. package/dest/client/p2p_client.js +462 -120
  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 +14 -2
  19. package/dest/config.d.ts.map +1 -1
  20. package/dest/config.js +7 -3
  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 +237 -263
  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 +113 -108
  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 +9 -6
  33. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  34. package/dest/mem_pools/attestation_pool/mocks.js +16 -12
  35. package/dest/mem_pools/instrumentation.d.ts +1 -1
  36. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  37. package/dest/mem_pools/instrumentation.js +5 -14
  38. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +15 -10
  39. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  40. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +91 -50
  41. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +19 -5
  42. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -1
  43. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +59 -3
  44. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +79 -5
  45. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -1
  46. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +47 -0
  47. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
  48. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  49. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -0
  50. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +2 -2
  51. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -1
  52. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +4 -4
  53. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
  54. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +2 -0
  55. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +2 -2
  56. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  57. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
  58. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
  59. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
  60. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
  61. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
  62. package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
  63. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +43 -0
  64. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
  65. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +103 -0
  66. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
  67. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
  68. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +119 -0
  69. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
  70. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  71. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +90 -0
  72. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
  73. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
  74. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +89 -0
  75. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +10 -0
  76. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
  77. package/dest/mem_pools/tx_pool_v2/eviction/index.js +11 -0
  78. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +131 -0
  79. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
  80. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +17 -0
  81. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
  82. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  83. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +63 -0
  84. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
  85. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  86. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +91 -0
  87. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
  88. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  89. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +70 -0
  90. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
  91. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
  92. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +63 -0
  93. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
  94. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
  95. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
  96. package/dest/mem_pools/tx_pool_v2/index.d.ts +5 -0
  97. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
  98. package/dest/mem_pools/tx_pool_v2/index.js +4 -0
  99. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +197 -0
  100. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
  101. package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -0
  102. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +71 -0
  103. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
  104. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +95 -0
  105. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
  106. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
  107. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
  108. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +99 -0
  109. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
  110. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +332 -0
  111. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +55 -0
  112. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
  113. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +156 -0
  114. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +69 -0
  115. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
  116. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +748 -0
  117. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -4
  118. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  119. package/dest/msg_validators/attestation_validator/attestation_validator.js +51 -18
  120. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -5
  121. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  122. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +22 -13
  123. package/dest/msg_validators/clock_tolerance.d.ts +21 -0
  124. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
  125. package/dest/msg_validators/clock_tolerance.js +37 -0
  126. package/dest/msg_validators/index.d.ts +2 -2
  127. package/dest/msg_validators/index.d.ts.map +1 -1
  128. package/dest/msg_validators/index.js +1 -1
  129. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
  130. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
  131. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
  132. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
  133. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
  134. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
  135. package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
  136. package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
  137. package/dest/msg_validators/proposal_validator/index.js +3 -0
  138. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
  139. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
  140. package/dest/msg_validators/proposal_validator/proposal_validator.js +104 -0
  141. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
  142. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
  143. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +212 -0
  144. package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
  145. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
  146. package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
  147. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +5 -4
  148. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  149. package/dest/msg_validators/tx_validator/block_header_validator.js +3 -2
  150. package/dest/msg_validators/tx_validator/data_validator.d.ts +3 -1
  151. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  152. package/dest/msg_validators/tx_validator/data_validator.js +4 -1
  153. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +3 -2
  154. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  155. package/dest/msg_validators/tx_validator/double_spend_validator.js +3 -2
  156. package/dest/msg_validators/tx_validator/factory.d.ts +8 -3
  157. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  158. package/dest/msg_validators/tx_validator/factory.js +21 -11
  159. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
  160. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
  161. package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
  162. package/dest/msg_validators/tx_validator/gas_validator.d.ts +3 -2
  163. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  164. package/dest/msg_validators/tx_validator/gas_validator.js +11 -16
  165. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  166. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  167. package/dest/msg_validators/tx_validator/index.js +1 -0
  168. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +3 -2
  169. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  170. package/dest/msg_validators/tx_validator/metadata_validator.js +2 -2
  171. package/dest/msg_validators/tx_validator/phases_validator.d.ts +3 -2
  172. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  173. package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
  174. package/dest/msg_validators/tx_validator/size_validator.d.ts +8 -0
  175. package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
  176. package/dest/msg_validators/tx_validator/size_validator.js +23 -0
  177. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +3 -2
  178. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  179. package/dest/msg_validators/tx_validator/timestamp_validator.js +2 -2
  180. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
  181. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
  182. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
  183. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +3 -2
  184. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  185. package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -2
  186. package/dest/services/data_store.d.ts +1 -1
  187. package/dest/services/data_store.d.ts.map +1 -1
  188. package/dest/services/data_store.js +10 -6
  189. package/dest/services/discv5/discV5_service.js +1 -1
  190. package/dest/services/dummy_service.d.ts +18 -2
  191. package/dest/services/dummy_service.d.ts.map +1 -1
  192. package/dest/services/dummy_service.js +42 -0
  193. package/dest/services/encoding.d.ts +1 -1
  194. package/dest/services/encoding.d.ts.map +1 -1
  195. package/dest/services/encoding.js +6 -5
  196. package/dest/services/index.d.ts +2 -1
  197. package/dest/services/index.d.ts.map +1 -1
  198. package/dest/services/index.js +1 -0
  199. package/dest/services/libp2p/instrumentation.d.ts +1 -1
  200. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  201. package/dest/services/libp2p/instrumentation.js +30 -72
  202. package/dest/services/libp2p/libp2p_service.d.ts +38 -15
  203. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  204. package/dest/services/libp2p/libp2p_service.js +747 -183
  205. package/dest/services/peer-manager/metrics.d.ts +2 -2
  206. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  207. package/dest/services/peer-manager/metrics.js +21 -26
  208. package/dest/services/peer-manager/peer_manager.d.ts +2 -2
  209. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  210. package/dest/services/peer-manager/peer_manager.js +0 -10
  211. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  212. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  213. package/dest/services/peer-manager/peer_scoring.js +7 -4
  214. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +47 -0
  215. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
  216. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +566 -0
  217. package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
  218. package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
  219. package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
  220. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +50 -0
  221. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
  222. package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
  223. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +37 -0
  224. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
  225. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +151 -0
  226. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +54 -0
  227. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
  228. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +139 -0
  229. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +20 -0
  230. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
  231. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
  232. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +22 -3
  233. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  234. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +63 -4
  235. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -1
  236. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  237. package/dest/services/reqresp/connection-sampler/connection_sampler.js +12 -0
  238. package/dest/services/reqresp/constants.d.ts +12 -0
  239. package/dest/services/reqresp/constants.d.ts.map +1 -0
  240. package/dest/services/reqresp/constants.js +7 -0
  241. package/dest/services/reqresp/interface.d.ts +3 -1
  242. package/dest/services/reqresp/interface.d.ts.map +1 -1
  243. package/dest/services/reqresp/metrics.d.ts +6 -5
  244. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  245. package/dest/services/reqresp/metrics.js +17 -21
  246. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +5 -1
  247. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  248. package/dest/services/reqresp/protocols/block_txs/bitvector.js +12 -0
  249. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +6 -5
  250. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  251. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +27 -9
  252. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +23 -6
  253. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  254. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +44 -13
  255. package/dest/services/reqresp/protocols/status.d.ts +1 -1
  256. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  257. package/dest/services/reqresp/protocols/status.js +4 -1
  258. package/dest/services/reqresp/reqresp.d.ts +6 -1
  259. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  260. package/dest/services/reqresp/reqresp.js +460 -46
  261. package/dest/services/service.d.ts +19 -3
  262. package/dest/services/service.d.ts.map +1 -1
  263. package/dest/services/tx_collection/config.d.ts +4 -1
  264. package/dest/services/tx_collection/config.d.ts.map +1 -1
  265. package/dest/services/tx_collection/config.js +9 -1
  266. package/dest/services/tx_collection/fast_tx_collection.d.ts +5 -4
  267. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  268. package/dest/services/tx_collection/fast_tx_collection.js +17 -10
  269. package/dest/services/tx_collection/index.d.ts +2 -1
  270. package/dest/services/tx_collection/index.d.ts.map +1 -1
  271. package/dest/services/tx_collection/index.js +1 -0
  272. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  273. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  274. package/dest/services/tx_collection/instrumentation.js +10 -13
  275. package/dest/services/tx_collection/proposal_tx_collector.d.ts +48 -0
  276. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
  277. package/dest/services/tx_collection/proposal_tx_collector.js +49 -0
  278. package/dest/services/tx_collection/slow_tx_collection.d.ts +3 -3
  279. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  280. package/dest/services/tx_collection/tx_collection.d.ts +8 -8
  281. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  282. package/dest/services/tx_collection/tx_collection.js +5 -5
  283. package/dest/services/tx_file_store/config.d.ts +18 -0
  284. package/dest/services/tx_file_store/config.d.ts.map +1 -0
  285. package/dest/services/tx_file_store/config.js +26 -0
  286. package/dest/services/tx_file_store/index.d.ts +4 -0
  287. package/dest/services/tx_file_store/index.d.ts.map +1 -0
  288. package/dest/services/tx_file_store/index.js +3 -0
  289. package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
  290. package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
  291. package/dest/services/tx_file_store/instrumentation.js +29 -0
  292. package/dest/services/tx_file_store/tx_file_store.d.ts +47 -0
  293. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
  294. package/dest/services/tx_file_store/tx_file_store.js +149 -0
  295. package/dest/services/tx_provider.d.ts +3 -3
  296. package/dest/services/tx_provider.d.ts.map +1 -1
  297. package/dest/services/tx_provider_instrumentation.d.ts +1 -1
  298. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  299. package/dest/services/tx_provider_instrumentation.js +7 -20
  300. package/dest/test-helpers/index.d.ts +3 -1
  301. package/dest/test-helpers/index.d.ts.map +1 -1
  302. package/dest/test-helpers/index.js +2 -0
  303. package/dest/test-helpers/test_tx_provider.d.ts +40 -0
  304. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
  305. package/dest/test-helpers/test_tx_provider.js +41 -0
  306. package/dest/test-helpers/testbench-utils.d.ts +158 -0
  307. package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
  308. package/dest/test-helpers/testbench-utils.js +297 -0
  309. package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
  310. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  311. package/dest/testbench/p2p_client_testbench_worker.js +218 -124
  312. package/dest/testbench/worker_client_manager.d.ts +51 -6
  313. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  314. package/dest/testbench/worker_client_manager.js +226 -39
  315. package/package.json +16 -16
  316. package/src/bootstrap/bootstrap.ts +7 -4
  317. package/src/client/factory.ts +10 -10
  318. package/src/client/interface.ts +19 -4
  319. package/src/client/p2p_client.ts +95 -133
  320. package/src/client/test/tx_proposal_collector/README.md +227 -0
  321. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +336 -0
  322. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
  323. package/src/config.ts +15 -3
  324. package/src/mem_pools/attestation_pool/attestation_pool.ts +68 -41
  325. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +239 -287
  326. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +162 -140
  327. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +141 -164
  328. package/src/mem_pools/attestation_pool/mocks.ts +19 -13
  329. package/src/mem_pools/instrumentation.ts +10 -18
  330. package/src/mem_pools/tx_pool/README.md +28 -13
  331. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +130 -75
  332. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +66 -5
  333. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +119 -4
  334. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
  335. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +4 -2
  336. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
  337. package/src/mem_pools/tx_pool_v2/README.md +209 -0
  338. package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
  339. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -0
  340. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +147 -0
  341. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +118 -0
  342. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +111 -0
  343. package/src/mem_pools/tx_pool_v2/eviction/index.ts +23 -0
  344. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +164 -0
  345. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
  346. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
  347. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +86 -0
  348. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +72 -0
  349. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +31 -0
  350. package/src/mem_pools/tx_pool_v2/index.ts +11 -0
  351. package/src/mem_pools/tx_pool_v2/interfaces.ts +227 -0
  352. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +161 -0
  353. package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
  354. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +417 -0
  355. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +212 -0
  356. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +882 -0
  357. package/src/msg_validators/attestation_validator/attestation_validator.ts +36 -21
  358. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +19 -16
  359. package/src/msg_validators/clock_tolerance.ts +51 -0
  360. package/src/msg_validators/index.ts +1 -1
  361. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
  362. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
  363. package/src/msg_validators/proposal_validator/index.ts +3 -0
  364. package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
  365. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -0
  366. package/src/msg_validators/tx_validator/archive_cache.ts +3 -3
  367. package/src/msg_validators/tx_validator/block_header_validator.ts +6 -5
  368. package/src/msg_validators/tx_validator/data_validator.ts +18 -6
  369. package/src/msg_validators/tx_validator/double_spend_validator.ts +4 -3
  370. package/src/msg_validators/tx_validator/factory.ts +64 -23
  371. package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
  372. package/src/msg_validators/tx_validator/gas_validator.ts +17 -28
  373. package/src/msg_validators/tx_validator/index.ts +1 -0
  374. package/src/msg_validators/tx_validator/metadata_validator.ts +18 -7
  375. package/src/msg_validators/tx_validator/phases_validator.ts +5 -3
  376. package/src/msg_validators/tx_validator/size_validator.ts +22 -0
  377. package/src/msg_validators/tx_validator/timestamp_validator.ts +9 -4
  378. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
  379. package/src/msg_validators/tx_validator/tx_proof_validator.ts +8 -3
  380. package/src/services/data_store.ts +10 -7
  381. package/src/services/discv5/discV5_service.ts +1 -1
  382. package/src/services/dummy_service.ts +51 -0
  383. package/src/services/encoding.ts +5 -4
  384. package/src/services/index.ts +1 -0
  385. package/src/services/libp2p/instrumentation.ts +32 -73
  386. package/src/services/libp2p/libp2p_service.ts +420 -166
  387. package/src/services/peer-manager/metrics.ts +22 -26
  388. package/src/services/peer-manager/peer_manager.ts +1 -2
  389. package/src/services/peer-manager/peer_scoring.ts +3 -4
  390. package/src/services/reqresp/batch-tx-requester/README.md +305 -0
  391. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +706 -0
  392. package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
  393. package/src/services/reqresp/batch-tx-requester/interface.ts +57 -0
  394. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +209 -0
  395. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +205 -0
  396. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
  397. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +65 -4
  398. package/src/services/reqresp/connection-sampler/connection_sampler.ts +19 -1
  399. package/src/services/reqresp/constants.ts +14 -0
  400. package/src/services/reqresp/interface.ts +3 -0
  401. package/src/services/reqresp/metrics.ts +36 -27
  402. package/src/services/reqresp/protocols/block_txs/bitvector.ts +16 -0
  403. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +34 -12
  404. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +57 -9
  405. package/src/services/reqresp/protocols/status.ts +7 -4
  406. package/src/services/reqresp/reqresp.ts +66 -19
  407. package/src/services/service.ts +23 -4
  408. package/src/services/tx_collection/config.ts +15 -1
  409. package/src/services/tx_collection/fast_tx_collection.ts +30 -17
  410. package/src/services/tx_collection/index.ts +5 -0
  411. package/src/services/tx_collection/instrumentation.ts +5 -13
  412. package/src/services/tx_collection/proposal_tx_collector.ts +112 -0
  413. package/src/services/tx_collection/slow_tx_collection.ts +2 -2
  414. package/src/services/tx_collection/tx_collection.ts +8 -8
  415. package/src/services/tx_file_store/config.ts +43 -0
  416. package/src/services/tx_file_store/index.ts +3 -0
  417. package/src/services/tx_file_store/instrumentation.ts +36 -0
  418. package/src/services/tx_file_store/tx_file_store.ts +173 -0
  419. package/src/services/tx_provider.ts +2 -2
  420. package/src/services/tx_provider_instrumentation.ts +13 -20
  421. package/src/test-helpers/index.ts +2 -0
  422. package/src/test-helpers/test_tx_provider.ts +64 -0
  423. package/src/test-helpers/testbench-utils.ts +374 -0
  424. package/src/testbench/p2p_client_testbench_worker.ts +337 -119
  425. package/src/testbench/worker_client_manager.ts +304 -42
  426. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +0 -15
  427. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +0 -1
  428. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +0 -88
  429. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
  430. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
  431. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -82
  432. package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
  433. package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
  434. package/dest/msg_validators/block_proposal_validator/index.js +0 -1
  435. package/src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts +0 -108
  436. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -97
  437. package/src/msg_validators/block_proposal_validator/index.ts +0 -1
@@ -1,23 +1,25 @@
1
1
  import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
- import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
3
  import { randomInt } from '@aztec/foundation/crypto/random';
4
4
  import { Fr } from '@aztec/foundation/curves/bn254';
5
5
  import { type Logger, createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
6
6
  import { RunningPromise } from '@aztec/foundation/running-promise';
7
7
  import { Timer } from '@aztec/foundation/timer';
8
8
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
9
- import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
10
9
  import { protocolContractsHash } from '@aztec/protocol-contracts';
11
10
  import type { EthAddress, L2Block, L2BlockSource } from '@aztec/stdlib/block';
12
11
  import type { ContractDataSource } from '@aztec/stdlib/contract';
13
12
  import { GasFees } from '@aztec/stdlib/gas';
14
13
  import type { ClientProtocolCircuitVerifier, PeerInfo, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
15
14
  import {
16
- BlockAttestation,
17
15
  BlockProposal,
16
+ CheckpointAttestation,
17
+ CheckpointProposal,
18
+ type CheckpointProposalCore,
18
19
  type Gossipable,
19
20
  P2PClientType,
20
21
  P2PMessage,
22
+ type ValidationResult as P2PValidationResult,
21
23
  PeerErrorSeverity,
22
24
  TopicType,
23
25
  createTopicString,
@@ -28,7 +30,14 @@ import { MerkleTreeId } from '@aztec/stdlib/trees';
28
30
  import { Tx, type TxHash, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
29
31
  import type { UInt64 } from '@aztec/stdlib/types';
30
32
  import { compressComponentVersions } from '@aztec/stdlib/versioning';
31
- import { Attributes, OtelMetricsAdapter, type TelemetryClient, WithTracer, trackSpan } from '@aztec/telemetry-client';
33
+ import {
34
+ Attributes,
35
+ OtelMetricsAdapter,
36
+ SpanStatusCode,
37
+ type TelemetryClient,
38
+ WithTracer,
39
+ trackSpan,
40
+ } from '@aztec/telemetry-client';
32
41
 
33
42
  import {
34
43
  type GossipSub,
@@ -51,22 +60,21 @@ import { createLibp2p } from 'libp2p';
51
60
 
52
61
  import type { P2PConfig } from '../../config.js';
53
62
  import { ProposalSlotCapExceededError } from '../../errors/attestation-pool.error.js';
54
- import type { MemPools } from '../../mem_pools/interface.js';
63
+ import type { MemPools } from '../../mem_pools/index.js';
55
64
  import {
56
- AttestationValidator,
57
65
  BlockProposalValidator,
66
+ CheckpointAttestationValidator,
67
+ CheckpointProposalValidator,
68
+ DoubleSpendTxValidator,
58
69
  FishermanAttestationValidator,
70
+ getDefaultAllowedSetupFunctions,
59
71
  } from '../../msg_validators/index.js';
60
72
  import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
61
- import { getDefaultAllowedSetupFunctions } from '../../msg_validators/tx_validator/allowed_public_setup.js';
62
- import { type MessageValidator, createTxMessageValidators } from '../../msg_validators/tx_validator/factory.js';
63
73
  import {
64
- AggregateTxValidator,
65
- DataTxValidator,
66
- DoubleSpendTxValidator,
67
- MetadataTxValidator,
68
- TxProofValidator,
69
- } from '../../msg_validators/tx_validator/index.js';
74
+ type MessageValidator,
75
+ createTxMessageValidators,
76
+ createTxReqRespValidator,
77
+ } from '../../msg_validators/tx_validator/factory.js';
70
78
  import { GossipSubEvent } from '../../types/index.js';
71
79
  import { type PubSubLibp2p, convertToMultiaddr } from '../../util.js';
72
80
  import { getVersions } from '../../versioning.js';
@@ -77,31 +85,38 @@ import { gossipScoreThresholds } from '../gossipsub/scoring.js';
77
85
  import type { PeerManagerInterface } from '../peer-manager/interface.js';
78
86
  import { PeerManager } from '../peer-manager/peer_manager.js';
79
87
  import { PeerScoring } from '../peer-manager/peer_scoring.js';
88
+ import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
80
89
  import type { P2PReqRespConfig } from '../reqresp/config.js';
81
90
  import {
82
91
  DEFAULT_SUB_PROTOCOL_VALIDATORS,
83
92
  type ReqRespInterface,
93
+ type ReqRespResponse,
84
94
  ReqRespSubProtocol,
85
95
  type ReqRespSubProtocolHandler,
86
96
  type ReqRespSubProtocolHandlers,
87
97
  type ReqRespSubProtocolValidators,
88
98
  type SubProtocolMap,
89
99
  ValidationError,
90
- } from '../reqresp/interface.js';
91
- import { reqRespBlockTxsHandler } from '../reqresp/protocols/block_txs/block_txs_handler.js';
92
- import { reqGoodbyeHandler } from '../reqresp/protocols/goodbye.js';
100
+ } from '../reqresp/index.js';
93
101
  import {
94
102
  AuthRequest,
95
103
  BlockTxsRequest,
96
104
  BlockTxsResponse,
97
105
  StatusMessage,
98
106
  pingHandler,
107
+ reqGoodbyeHandler,
99
108
  reqRespBlockHandler,
109
+ reqRespBlockTxsHandler,
100
110
  reqRespStatusHandler,
101
111
  reqRespTxHandler,
102
- } from '../reqresp/protocols/index.js';
112
+ } from '../reqresp/index.js';
103
113
  import { ReqResp } from '../reqresp/reqresp.js';
104
- import type { P2PBlockReceivedCallback, P2PService, PeerDiscoveryService } from '../service.js';
114
+ import type {
115
+ P2PBlockReceivedCallback,
116
+ P2PCheckpointReceivedCallback,
117
+ P2PService,
118
+ PeerDiscoveryService,
119
+ } from '../service.js';
105
120
  import { P2PInstrumentation } from './instrumentation.js';
106
121
 
107
122
  interface ValidationResult {
@@ -125,8 +140,9 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
125
140
  private msgIdSeenValidators: Record<TopicType, MessageSeenValidator> = {} as Record<TopicType, MessageSeenValidator>;
126
141
 
127
142
  // Message validators
128
- private attestationValidator: AttestationValidator;
129
143
  private blockProposalValidator: BlockProposalValidator;
144
+ private checkpointProposalValidator: CheckpointProposalValidator;
145
+ private checkpointAttestationValidator: CheckpointAttestationValidator;
130
146
 
131
147
  private protocolVersion = '';
132
148
  private topicStrings: Record<TopicType, string> = {} as Record<TopicType, string>;
@@ -140,10 +156,19 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
140
156
  */
141
157
  private blockReceivedCallback: P2PBlockReceivedCallback;
142
158
 
159
+ /**
160
+ * Callback for when a checkpoint proposal is received from a peer.
161
+ * @param checkpoint - The checkpoint proposal received from the peer.
162
+ * @returns The attestations for the checkpoint, if any.
163
+ */
164
+ private checkpointReceivedCallback: P2PCheckpointReceivedCallback;
165
+
143
166
  private gossipSubEventHandler: (e: CustomEvent<GossipsubMessage>) => void;
144
167
 
145
168
  private instrumentation: P2PInstrumentation;
146
169
 
170
+ private telemetry: TelemetryClient;
171
+
147
172
  protected logger: Logger;
148
173
 
149
174
  constructor(
@@ -162,6 +187,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
162
187
  logger: Logger = createLogger('p2p:libp2p_service'),
163
188
  ) {
164
189
  super(telemetry, 'LibP2PService');
190
+ this.telemetry = telemetry;
165
191
 
166
192
  // Create child logger with fisherman prefix if in fisherman mode
167
193
  this.logger = config.fishermanMode ? logger.createChild('[FISHERMAN]') : logger;
@@ -170,7 +196,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
170
196
 
171
197
  this.msgIdSeenValidators[TopicType.tx] = new MessageSeenValidator(config.seenMessageCacheSize);
172
198
  this.msgIdSeenValidators[TopicType.block_proposal] = new MessageSeenValidator(config.seenMessageCacheSize);
173
- this.msgIdSeenValidators[TopicType.block_attestation] = new MessageSeenValidator(config.seenMessageCacheSize);
199
+ this.msgIdSeenValidators[TopicType.checkpoint_proposal] = new MessageSeenValidator(config.seenMessageCacheSize);
200
+ this.msgIdSeenValidators[TopicType.checkpoint_attestation] = new MessageSeenValidator(config.seenMessageCacheSize);
174
201
 
175
202
  const versions = getVersions(config);
176
203
  this.protocolVersion = compressComponentVersions(versions);
@@ -178,25 +205,40 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
178
205
 
179
206
  this.topicStrings[TopicType.tx] = createTopicString(TopicType.tx, this.protocolVersion);
180
207
  this.topicStrings[TopicType.block_proposal] = createTopicString(TopicType.block_proposal, this.protocolVersion);
181
- this.topicStrings[TopicType.block_attestation] = createTopicString(
182
- TopicType.block_attestation,
208
+ this.topicStrings[TopicType.checkpoint_proposal] = createTopicString(
209
+ TopicType.checkpoint_proposal,
210
+ this.protocolVersion,
211
+ );
212
+ this.topicStrings[TopicType.checkpoint_attestation] = createTopicString(
213
+ TopicType.checkpoint_attestation,
183
214
  this.protocolVersion,
184
215
  );
185
216
 
186
- // Use FishermanAttestationValidator in fisherman mode to validate attestation payloads against proposals
187
- this.attestationValidator = config.fishermanMode
188
- ? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry)
189
- : new AttestationValidator(epochCache);
190
217
  this.blockProposalValidator = new BlockProposalValidator(epochCache, { txsPermitted: !config.disableTransactions });
218
+ this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, {
219
+ txsPermitted: !config.disableTransactions,
220
+ });
221
+ this.checkpointAttestationValidator = config.fishermanMode
222
+ ? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry)
223
+ : new CheckpointAttestationValidator(epochCache);
191
224
 
192
225
  this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
193
226
 
194
- this.blockReceivedCallback = async (block: BlockProposal): Promise<BlockAttestation[] | undefined> => {
227
+ this.blockReceivedCallback = async (block: BlockProposal): Promise<boolean> => {
195
228
  this.logger.debug(
196
229
  `Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber} from peer.`,
197
230
  { p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier() },
198
231
  );
199
- return undefined;
232
+ return false;
233
+ };
234
+
235
+ this.checkpointReceivedCallback = (
236
+ checkpoint: CheckpointProposalCore,
237
+ ): Promise<CheckpointAttestation[] | undefined> => {
238
+ this.logger.debug(
239
+ `Handler not yet registered: Checkpoint received callback not set. Received checkpoint for slot ${checkpoint.slotNumber} from peer.`,
240
+ );
241
+ return Promise.resolve(undefined);
200
242
  };
201
243
  }
202
244
 
@@ -242,14 +284,14 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
242
284
 
243
285
  const datastore = new AztecDatastore(peerStore);
244
286
 
245
- const otelMetricsAdapter = new OtelMetricsAdapter(telemetry);
287
+ const otelMetricsAdapter = new OtelMetricsAdapter(telemetry, logger.getBindings());
246
288
 
247
289
  const peerDiscoveryService = new DiscV5Service(
248
290
  peerId,
249
291
  config,
250
292
  packageVersion,
251
293
  telemetry,
252
- createLogger(`${logger.module}:discv5_service`),
294
+ createLogger(`${logger.module}:discv5_service`, logger.getBindings()),
253
295
  );
254
296
 
255
297
  // Seed libp2p's bootstrap discovery with private and trusted peers
@@ -265,7 +307,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
265
307
 
266
308
  const txTopic = createTopicString(TopicType.tx, protocolVersion);
267
309
  const blockProposalTopic = createTopicString(TopicType.block_proposal, protocolVersion);
268
- const blockAttestationTopic = createTopicString(TopicType.block_attestation, protocolVersion);
310
+ const checkpointProposalTopic = createTopicString(TopicType.checkpoint_proposal, protocolVersion);
311
+ const checkpointAttestationTopic = createTopicString(TopicType.checkpoint_attestation, protocolVersion);
269
312
 
270
313
  const preferredPeersEnrs: ENR[] = config.preferredPeers.map(enr => ENR.decodeTxt(enr));
271
314
  const directPeers = (
@@ -387,12 +430,17 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
387
430
  invalidMessageDeliveriesWeight: -20,
388
431
  invalidMessageDeliveriesDecay: 0.5,
389
432
  }),
390
- [blockAttestationTopic]: createTopicScoreParams({
433
+ [blockProposalTopic]: createTopicScoreParams({
391
434
  topicWeight: 1,
392
435
  invalidMessageDeliveriesWeight: -20,
393
436
  invalidMessageDeliveriesDecay: 0.5,
394
437
  }),
395
- [blockProposalTopic]: createTopicScoreParams({
438
+ [checkpointProposalTopic]: createTopicScoreParams({
439
+ topicWeight: 1,
440
+ invalidMessageDeliveriesWeight: -20,
441
+ invalidMessageDeliveriesDecay: 0.5,
442
+ }),
443
+ [checkpointAttestationTopic]: createTopicScoreParams({
396
444
  topicWeight: 1,
397
445
  invalidMessageDeliveriesWeight: -20,
398
446
  invalidMessageDeliveriesDecay: 0.5,
@@ -404,7 +452,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
404
452
  connectionManager: components.connectionManager,
405
453
  }),
406
454
  },
407
- logger: createLibp2pComponentLogger(logger.module),
455
+ logger: createLibp2pComponentLogger(logger.module, logger.getBindings()),
408
456
  });
409
457
 
410
458
  const peerScoring = new PeerScoring(config, telemetry);
@@ -462,17 +510,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
462
510
  }
463
511
  const announceTcpMultiaddr = convertToMultiaddr(p2pIp, p2pPort, 'tcp');
464
512
 
465
- await this.peerManager.initializePeers();
466
- if (!this.config.p2pDiscoveryDisabled) {
467
- await this.peerDiscoveryService.start();
468
- }
469
- await this.node.start();
470
-
471
- // Subscribe to standard GossipSub topics by default
472
- for (const topic of getTopicsForClientAndConfig(this.clientType, this.config.disableTransactions)) {
473
- this.subscribeToTopic(this.topicStrings[topic]);
474
- }
475
-
476
513
  // Create request response protocol handlers
477
514
  const txHandler = reqRespTxHandler(this.mempools);
478
515
  const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
@@ -487,7 +524,11 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
487
524
  };
488
525
 
489
526
  if (!this.config.disableTransactions) {
490
- const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.mempools.txPool);
527
+ const blockTxsHandler = reqRespBlockTxsHandler(
528
+ this.mempools.attestationPool,
529
+ this.archiver,
530
+ this.mempools.txPool,
531
+ );
491
532
  requestResponseHandlers[ReqRespSubProtocol.BLOCK_TXS] = blockTxsHandler.bind(this);
492
533
  }
493
534
 
@@ -495,10 +536,32 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
495
536
  requestResponseHandlers[ReqRespSubProtocol.TX] = txHandler.bind(this);
496
537
  }
497
538
 
539
+ // Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
540
+ const reqrespSubProtocolValidators = {
541
+ ...DEFAULT_SUB_PROTOCOL_VALIDATORS,
542
+ [ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
543
+ [ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
544
+ [ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this),
545
+ };
546
+
547
+ await this.peerManager.initializePeers();
548
+
549
+ await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
550
+
551
+ await this.node.start();
552
+
553
+ // Subscribe to standard GossipSub topics by default
554
+ for (const topic of getTopicsForClientAndConfig(this.clientType, this.config.disableTransactions)) {
555
+ this.subscribeToTopic(this.topicStrings[topic]);
556
+ }
557
+
498
558
  // add GossipSub listener
499
559
  this.node.services.pubsub.addEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
500
560
 
501
561
  // Start running promise for peer discovery and metrics collection
562
+ if (!this.config.p2pDiscoveryDisabled) {
563
+ await this.peerDiscoveryService.start();
564
+ }
502
565
  this.discoveryRunningPromise = new RunningPromise(
503
566
  async () => {
504
567
  await this.peerManager.heartbeat();
@@ -508,14 +571,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
508
571
  );
509
572
  this.discoveryRunningPromise.start();
510
573
 
511
- // Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
512
- const reqrespSubProtocolValidators = {
513
- ...DEFAULT_SUB_PROTOCOL_VALIDATORS,
514
- [ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
515
- [ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
516
- [ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this),
517
- };
518
- await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
519
574
  this.logger.info(`Started P2P service`, {
520
575
  listen: this.config.listenAddress,
521
576
  port: this.config.p2pPort,
@@ -589,6 +644,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
589
644
  return this.reqresp.sendBatchRequest(protocol, requests, pinnedPeerId);
590
645
  }
591
646
 
647
+ public sendRequestToPeer(
648
+ peerId: PeerId,
649
+ subProtocol: ReqRespSubProtocol,
650
+ payload: Buffer,
651
+ dialTimeout?: number,
652
+ ): Promise<ReqRespResponse> {
653
+ return this.reqresp.sendRequestToPeer(peerId, subProtocol, payload, dialTimeout);
654
+ }
655
+
592
656
  /**
593
657
  * Get the ENR of the node
594
658
  * @returns The ENR of the node
@@ -601,6 +665,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
601
665
  this.blockReceivedCallback = callback;
602
666
  }
603
667
 
668
+ public registerCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
669
+ this.checkpointReceivedCallback = callback;
670
+ }
671
+
604
672
  /**
605
673
  * Subscribes to a topic.
606
674
  * @param topic - The topic to subscribe to.
@@ -622,7 +690,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
622
690
  if (!this.node.services.pubsub) {
623
691
  throw new Error('Pubsub service not available.');
624
692
  }
625
- const p2pMessage = P2PMessage.fromGossipable(message, this.config.debugP2PInstrumentMessages);
693
+ const isBlockProposal = topic === this.topicStrings[TopicType.block_proposal];
694
+ const traceContext =
695
+ this.config.debugP2PInstrumentMessages && isBlockProposal ? this.telemetry.getTraceContext() : undefined;
696
+ const p2pMessage = P2PMessage.fromGossipable(message, this.config.debugP2PInstrumentMessages, traceContext);
626
697
  const result = await this.node.services.pubsub.publish(topic, p2pMessage.toMessageData());
627
698
  return result.recipients.length;
628
699
  }
@@ -643,12 +714,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
643
714
  case this.topicStrings[TopicType.tx]:
644
715
  topicType = TopicType.tx;
645
716
  break;
646
- case this.topicStrings[TopicType.block_attestation]:
647
- topicType = TopicType.block_attestation;
648
- break;
649
717
  case this.topicStrings[TopicType.block_proposal]:
650
718
  topicType = TopicType.block_proposal;
651
719
  break;
720
+ case this.topicStrings[TopicType.checkpoint_proposal]:
721
+ topicType = TopicType.checkpoint_proposal;
722
+ break;
723
+ case this.topicStrings[TopicType.checkpoint_attestation]:
724
+ topicType = TopicType.checkpoint_attestation;
725
+ break;
652
726
  default:
653
727
  this.logger.error(`Received message on unknown topic: ${msg.topic}`);
654
728
  break;
@@ -707,23 +781,74 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
707
781
  return;
708
782
  }
709
783
 
784
+ // Determine topic type for attributes
710
785
  if (msg.topic === this.topicStrings[TopicType.tx]) {
711
786
  topicType = TopicType.tx;
712
- await this.handleGossipedTx(p2pMessage.payload, msgId, source);
787
+ } else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
788
+ topicType = TopicType.checkpoint_attestation;
789
+ } else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
790
+ topicType = TopicType.block_proposal;
791
+ } else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
792
+ topicType = TopicType.checkpoint_proposal;
713
793
  }
714
- if (msg.topic === this.topicStrings[TopicType.block_attestation]) {
715
- topicType = TopicType.block_attestation;
716
- if (this.clientType === P2PClientType.Full) {
717
- await this.processAttestationFromPeer(p2pMessage.payload, msgId, source);
794
+
795
+ // Process the message, optionally within a linked span for trace propagation
796
+ const processMessage = async () => {
797
+ if (msg.topic === this.topicStrings[TopicType.tx]) {
798
+ await this.handleGossipedTx(p2pMessage.payload, msgId, source);
799
+ } else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
800
+ if (this.clientType === P2PClientType.Full) {
801
+ await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
802
+ }
803
+ } else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
804
+ await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
805
+ } else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
806
+ await this.handleGossipedCheckpointProposal(p2pMessage.payload, msgId, source);
807
+ } else {
808
+ this.logger.error(`Received message on unknown topic: ${msg.topic}`);
718
809
  }
719
- }
720
- if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
721
- topicType = TopicType.block_proposal;
722
- await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
810
+ };
811
+
812
+ const latency = p2pMessage.timestamp !== undefined ? msgReceivedTime - p2pMessage.timestamp.getTime() : undefined;
813
+ const propagatedContext = p2pMessage.traceContext
814
+ ? this.telemetry.extractPropagatedContext(p2pMessage.traceContext)
815
+ : undefined;
816
+
817
+ if (propagatedContext) {
818
+ await this.tracer.startActiveSpan(
819
+ 'LibP2PService.processMessage',
820
+ {
821
+ attributes: {
822
+ [Attributes.TOPIC_NAME]: topicType!,
823
+ [Attributes.PEER_ID]: source.toString(),
824
+ },
825
+ },
826
+ propagatedContext,
827
+ async span => {
828
+ try {
829
+ await processMessage();
830
+ span.setStatus({
831
+ code: SpanStatusCode.OK,
832
+ });
833
+ } catch (err) {
834
+ span.setStatus({
835
+ code: SpanStatusCode.ERROR,
836
+ message: String(err),
837
+ });
838
+ if (typeof err === 'string' || (err && err instanceof Error)) {
839
+ span.recordException(err);
840
+ }
841
+ throw err;
842
+ } finally {
843
+ span.end();
844
+ }
845
+ },
846
+ );
847
+ } else {
848
+ await processMessage();
723
849
  }
724
850
 
725
- if (p2pMessage.timestamp !== undefined && topicType !== undefined) {
726
- const latency = msgReceivedTime - p2pMessage.timestamp.getTime();
851
+ if (latency !== undefined && topicType !== undefined) {
727
852
  this.instrumentation.recordMessageLatency(topicType, latency);
728
853
  }
729
854
 
@@ -800,27 +925,30 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
800
925
  }
801
926
 
802
927
  /**
803
- * Process Attestation From Peer
804
- * When a proposal is received from a peer, we add it to the attestation pool, so it can be accessed by other services.
805
- *
806
- * @param attestation - The attestation to process.
928
+ * Process a checkpoint attestation from a peer.
929
+ * Validates the attestation and adds it to the pool.
807
930
  */
808
- private async processAttestationFromPeer(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
809
- const validationFunc: () => Promise<ReceivedMessageValidationResult<BlockAttestation>> = async () => {
810
- const attestation = BlockAttestation.fromBuffer(payloadData);
931
+ private async processCheckpointAttestationFromPeer(
932
+ payloadData: Buffer,
933
+ msgId: string,
934
+ source: PeerId,
935
+ ): Promise<void> {
936
+ const validationFunc: () => Promise<ReceivedMessageValidationResult<CheckpointAttestation>> = async () => {
937
+ const attestation = CheckpointAttestation.fromBuffer(payloadData);
811
938
  const pool = this.mempools.attestationPool;
812
- const isValid = await this.validateAttestation(source, attestation);
813
- const exists = isValid && (await pool.hasAttestation(attestation));
939
+ const validationResult = await this.validateCheckpointAttestation(source, attestation);
940
+ const isValid = validationResult.result === 'accept';
941
+ const exists = isValid && (await pool.hasCheckpointAttestation(attestation));
814
942
 
815
943
  let canAdd = true;
816
944
  if (isValid && !exists) {
817
945
  const slot = attestation.payload.header.slotNumber;
818
946
  const { committee } = await this.epochCache.getCommittee(slot);
819
947
  const committeeSize = committee?.length ?? 0;
820
- canAdd = await pool.canAddAttestation(attestation, committeeSize);
948
+ canAdd = await pool.canAddCheckpointAttestation(attestation, committeeSize);
821
949
  }
822
950
 
823
- this.logger.trace(`Validate propagated block attestation`, {
951
+ this.logger.trace(`Validate propagated checkpoint attestation`, {
824
952
  isValid,
825
953
  exists,
826
954
  canAdd,
@@ -828,12 +956,12 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
828
956
  [Attributes.P2P_ID]: source.toString(),
829
957
  });
830
958
 
831
- if (!isValid) {
959
+ if (validationResult.result === 'reject') {
832
960
  return { result: TopicValidatorResult.Reject };
833
- } else if (exists) {
961
+ } else if (validationResult.result === 'ignore' || exists) {
834
962
  return { result: TopicValidatorResult.Ignore, obj: attestation };
835
963
  } else if (!canAdd) {
836
- this.logger.warn(`Dropping block attestation due to per-(slot, proposalId) attestation cap`, {
964
+ this.logger.warn(`Dropping checkpoint attestation due to per-(slot, proposalId) attestation cap`, {
837
965
  slot: attestation.payload.header.slotNumber.toString(),
838
966
  archive: attestation.archive.toString(),
839
967
  source: source.toString(),
@@ -844,11 +972,11 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
844
972
  }
845
973
  };
846
974
 
847
- const { result, obj: attestation } = await this.validateReceivedMessage<BlockAttestation>(
975
+ const { result, obj: attestation } = await this.validateReceivedMessage<CheckpointAttestation>(
848
976
  validationFunc,
849
977
  msgId,
850
978
  source,
851
- TopicType.block_attestation,
979
+ TopicType.checkpoint_attestation,
852
980
  );
853
981
 
854
982
  if (result !== TopicValidatorResult.Accept || !attestation) {
@@ -856,7 +984,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
856
984
  }
857
985
 
858
986
  this.logger.debug(
859
- `Received attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`,
987
+ `Received checkpoint attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`,
860
988
  {
861
989
  p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
862
990
  slot: attestation.slotNumber,
@@ -865,13 +993,14 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
865
993
  },
866
994
  );
867
995
 
868
- await this.mempools.attestationPool.addAttestations([attestation]);
996
+ await this.mempools.attestationPool.addCheckpointAttestations([attestation]);
869
997
  }
870
998
 
871
999
  private async processBlockFromPeer(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
872
1000
  const validationFunc: () => Promise<ReceivedMessageValidationResult<BlockProposal>> = async () => {
873
1001
  const block = BlockProposal.fromBuffer(payloadData);
874
- const isValid = await this.validateBlockProposal(source, block);
1002
+ const validationResult = await this.validateBlockProposal(source, block);
1003
+ const isValid = validationResult.result === 'accept';
875
1004
  const pool = this.mempools.attestationPool;
876
1005
 
877
1006
  const exists = isValid && (await pool.hasBlockProposal(block));
@@ -881,13 +1010,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
881
1010
  isValid,
882
1011
  exists,
883
1012
  canAdd,
884
- [Attributes.SLOT_NUMBER]: block.payload.header.slotNumber.toString(),
1013
+ [Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
885
1014
  [Attributes.P2P_ID]: source.toString(),
886
1015
  });
887
1016
 
888
- if (!isValid) {
1017
+ if (validationResult.result === 'reject') {
889
1018
  return { result: TopicValidatorResult.Reject };
890
- } else if (exists) {
1019
+ } else if (validationResult.result === 'ignore' || exists) {
891
1020
  return { result: TopicValidatorResult.Ignore, obj: block };
892
1021
  } else if (!canAdd) {
893
1022
  this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
@@ -917,6 +1046,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
917
1046
  }
918
1047
 
919
1048
  // REVIEW: callback pattern https://github.com/AztecProtocol/aztec-packages/issues/7963
1049
+ // REFACTOR(palla): This method should be moved to the p2p_client or to a separate component,
1050
+ // should not be here as it does not deal with p2p networking.
920
1051
  @trackSpan('Libp2pService.processValidBlockProposal', async block => ({
921
1052
  [Attributes.SLOT_NUMBER]: block.slotNumber,
922
1053
  [Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
@@ -924,17 +1055,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
924
1055
  }))
925
1056
  private async processValidBlockProposal(block: BlockProposal, sender: PeerId) {
926
1057
  const slot = block.slotNumber;
927
- const previousSlot = SlotNumber(slot - 1);
928
1058
  this.logger.verbose(`Received block proposal for slot ${slot} from external peer ${sender.toString()}.`, {
929
1059
  p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier(),
930
- slot: block.slotNumber,
931
- archive: block.archive.toString(),
932
1060
  source: sender.toString(),
1061
+ ...block.toBlockInfo(),
933
1062
  });
934
- const attestationsForPreviousSlot = await this.mempools.attestationPool.getAttestationsForSlot(previousSlot);
935
- this.logger.verbose(`Received ${attestationsForPreviousSlot.length} attestations for slot ${previousSlot}`);
936
1063
 
937
- // Attempt to add proposal, then mark the txs in this proposal as non-evictable
1064
+ // Attempt to add proposal
938
1065
  try {
939
1066
  await this.mempools.attestationPool.addBlockProposal(block);
940
1067
  } catch (err: unknown) {
@@ -949,34 +1076,126 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
949
1076
  }
950
1077
  throw err;
951
1078
  }
1079
+
1080
+ // Mark the txs in this proposal as non-evictable
952
1081
  await this.mempools.txPool.markTxsAsNonEvictable(block.txHashes);
953
- const attestations = await this.blockReceivedCallback(block, sender);
954
1082
 
955
- // TODO: fix up this pattern - the abstraction is not nice
956
- // The attestation can be undefined if no handler is registered / the validator deems the block invalid / in fisherman mode
957
- if (attestations?.length) {
958
- for (const attestation of attestations) {
959
- this.logger.verbose(`Broadcasting attestation for slot ${attestation.slotNumber}`, {
960
- p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
961
- slot: attestation.slotNumber,
962
- archive: attestation.archive.toString(),
1083
+ // Call the block received callback to validate the proposal.
1084
+ // Note: Validators do NOT attest to individual blocks, only to checkpoint proposals.
1085
+ const isValid = await this.blockReceivedCallback(block, sender);
1086
+ if (!isValid) {
1087
+ this.logger.warn(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
1088
+ }
1089
+ }
1090
+
1091
+ /**
1092
+ * Handle a gossiped checkpoint proposal.
1093
+ * Validates and processes the checkpoint proposal, then triggers the callback for attestation.
1094
+ */
1095
+ private async handleGossipedCheckpointProposal(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
1096
+ // TODO(palla/mbps): This pattern is repeated across multiple message handlers, consider abstracting it.
1097
+ const validationFunc: () => Promise<ReceivedMessageValidationResult<CheckpointProposal>> = async () => {
1098
+ const checkpoint = CheckpointProposal.fromBuffer(payloadData);
1099
+ const validationResult = await this.validateCheckpointProposal(source, checkpoint);
1100
+ const isValid = validationResult.result === 'accept';
1101
+ const pool = this.mempools.attestationPool;
1102
+
1103
+ const exists = isValid && (await pool.hasCheckpointProposal(checkpoint));
1104
+ const canAdd = isValid && (await pool.canAddCheckpointProposal(checkpoint));
1105
+
1106
+ this.logger.trace(`Validate propagated checkpoint proposal`, {
1107
+ isValid,
1108
+ exists,
1109
+ canAdd,
1110
+ [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
1111
+ [Attributes.P2P_ID]: source.toString(),
1112
+ });
1113
+
1114
+ if (validationResult.result === 'reject') {
1115
+ return { result: TopicValidatorResult.Reject };
1116
+ } else if (validationResult.result === 'ignore' || exists) {
1117
+ return { result: TopicValidatorResult.Ignore, obj: checkpoint };
1118
+ } else if (!canAdd) {
1119
+ this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
1120
+ this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
1121
+ slot: checkpoint.slotNumber.toString(),
1122
+ archive: checkpoint.archive.toString(),
1123
+ source: source.toString(),
963
1124
  });
964
- await this.broadcastAttestation(attestation);
1125
+ return { result: TopicValidatorResult.Reject };
1126
+ } else {
1127
+ return { result: TopicValidatorResult.Accept, obj: checkpoint };
965
1128
  }
1129
+ };
1130
+
1131
+ const { result, obj: checkpoint } = await this.validateReceivedMessage<CheckpointProposal>(
1132
+ validationFunc,
1133
+ msgId,
1134
+ source,
1135
+ TopicType.checkpoint_proposal,
1136
+ );
1137
+
1138
+ if (result !== TopicValidatorResult.Accept || !checkpoint) {
1139
+ return;
966
1140
  }
1141
+
1142
+ await this.processValidCheckpointProposal(checkpoint, source);
967
1143
  }
968
1144
 
969
1145
  /**
970
- * Broadcast an attestation to all peers.
971
- * @param attestation - The attestation to broadcast.
1146
+ * Process a validated checkpoint proposal.
1147
+ * Extracts and processes the last block proposal (if present) first, then processes the checkpoint.
1148
+ * The block callback is invoked before the checkpoint callback.
972
1149
  */
973
- @trackSpan('Libp2pService.broadcastAttestation', async attestation => ({
974
- [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
975
- [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
976
- [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
1150
+ @trackSpan('Libp2pService.processValidCheckpointProposal', async checkpoint => ({
1151
+ [Attributes.SLOT_NUMBER]: checkpoint.slotNumber,
1152
+ [Attributes.BLOCK_ARCHIVE]: checkpoint.archive.toString(),
1153
+ [Attributes.P2P_ID]: await checkpoint.p2pMessageLoggingIdentifier().then(i => i.toString()),
977
1154
  }))
978
- private async broadcastAttestation(attestation: BlockAttestation) {
979
- await this.propagate(attestation);
1155
+ private async processValidCheckpointProposal(checkpoint: CheckpointProposal, sender: PeerId) {
1156
+ const slot = checkpoint.slotNumber;
1157
+ this.logger.verbose(`Received checkpoint proposal for slot ${slot} from external peer ${sender.toString()}.`, {
1158
+ p2pMessageIdentifier: await checkpoint.p2pMessageLoggingIdentifier(),
1159
+ slot: checkpoint.slotNumber,
1160
+ archive: checkpoint.archive.toString(),
1161
+ source: sender.toString(),
1162
+ });
1163
+
1164
+ // Extract block proposal before adding to pool (pool stores them separately)
1165
+ const blockProposal = checkpoint.getBlockProposal();
1166
+
1167
+ // Add proposal to the pool (this extracts and stores block proposal separately)
1168
+ await this.mempools.attestationPool.addCheckpointProposal(checkpoint);
1169
+
1170
+ // Mark txs as non-evictable if present (from the last block)
1171
+ if (checkpoint.txHashes.length > 0) {
1172
+ await this.mempools.txPool.markTxsAsNonEvictable(checkpoint.txHashes);
1173
+ }
1174
+
1175
+ // If there was a last block proposal, invoke the block callback first for validation.
1176
+ // Note: The block proposal is already stored in the pool by addCheckpointProposal.
1177
+ if (blockProposal) {
1178
+ const isValid = await this.blockReceivedCallback(blockProposal, sender);
1179
+ if (!isValid) {
1180
+ this.logger.warn(`Block proposal from checkpoint failed validation`, {
1181
+ slot: slot.toString(),
1182
+ archive: checkpoint.archive.toString(),
1183
+ blockNumber: blockProposal.blockNumber.toString(),
1184
+ });
1185
+ return;
1186
+ }
1187
+ }
1188
+
1189
+ // Call the checkpoint received callback with the core version (without lastBlock)
1190
+ // to validate and potentially generate attestations
1191
+ const attestations = await this.checkpointReceivedCallback(checkpoint.toCore(), sender);
1192
+ if (attestations && attestations.length > 0) {
1193
+ // If the callback returned attestations, add them to the pool and propagate them
1194
+ await this.mempools.attestationPool.addCheckpointAttestations(attestations);
1195
+ for (const attestation of attestations) {
1196
+ await this.propagate(attestation);
1197
+ }
1198
+ }
980
1199
  }
981
1200
 
982
1201
  /**
@@ -999,7 +1218,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
999
1218
  * @returns True if the requested block transactions are valid, false otherwise.
1000
1219
  */
1001
1220
  @trackSpan('Libp2pService.validateRequestedBlockTxs', request => ({
1002
- [Attributes.BLOCK_HASH]: request.blockHash.toString(),
1221
+ [Attributes.BLOCK_ARCHIVE]: request.archiveRoot.toString(),
1003
1222
  }))
1004
1223
  private async validateRequestedBlockTxs(
1005
1224
  request: BlockTxsRequest,
@@ -1009,10 +1228,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1009
1228
  const requestedTxValidator = this.createRequestedTxValidator();
1010
1229
 
1011
1230
  try {
1012
- if (!response.blockHash.equals(request.blockHash)) {
1231
+ if (!response.archiveRoot.equals(request.archiveRoot)) {
1013
1232
  this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1014
1233
  throw new ValidationError(
1015
- `Received block txs for unexpected block: expected ${request.blockHash.toString()}, got ${response.blockHash.toString()}`,
1234
+ `Received block txs for unexpected archive root: expected ${request.archiveRoot.toString()}, got ${response.archiveRoot.toString()}`,
1016
1235
  );
1017
1236
  }
1018
1237
 
@@ -1042,7 +1261,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1042
1261
  }
1043
1262
 
1044
1263
  // Given proposal (should have locally), ensure returned txs are valid subset and match request indices
1045
- const proposal = await this.mempools.attestationPool.getBlockProposal(request.blockHash.toString());
1264
+ const proposal = await this.mempools.attestationPool.getBlockProposal(request.archiveRoot.toString());
1046
1265
  if (proposal) {
1047
1266
  // Build intersected indices
1048
1267
  const intersectIdx = request.txIndices.getTrueIndices().filter(i => response.txIndices.isSet(i));
@@ -1062,7 +1281,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1062
1281
  } else {
1063
1282
  // No local proposal, cannot check the membership/order of the returned txs
1064
1283
  this.logger.warn(
1065
- `Block proposal not found for block hash ${request.blockHash.toString()}; cannot validate membership/order of returned txs`,
1284
+ `Block proposal not found for archive root ${request.archiveRoot.toString()}; cannot validate membership/order of returned txs`,
1066
1285
  );
1067
1286
  return false;
1068
1287
  }
@@ -1101,7 +1320,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1101
1320
  const requested = new Set(requestedTxHash.map(h => h.toString()));
1102
1321
  const requestedTxValidator = this.createRequestedTxValidator();
1103
1322
 
1104
- //TODO: (mralj) - this is somewhat naive implementation, if single tx is invlid we consider the whole response invalid.
1323
+ //TODO: (mralj) - this is somewhat naive implementation, if single tx is invalid we consider the whole response invalid.
1105
1324
  // I think we should still extract the valid txs and return them, so that we can still use the response.
1106
1325
  try {
1107
1326
  await Promise.all(responseTx.map(tx => this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
@@ -1164,27 +1383,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1164
1383
  }
1165
1384
  }
1166
1385
 
1167
- private createRequestedTxValidator(): TxValidator {
1168
- return new AggregateTxValidator(
1169
- new DataTxValidator(),
1170
- new MetadataTxValidator({
1171
- l1ChainId: new Fr(this.config.l1ChainId),
1172
- rollupVersion: new Fr(this.config.rollupVersion),
1173
- protocolContractsHash,
1174
- vkTreeRoot: getVKTreeRoot(),
1175
- }),
1176
- new TxProofValidator(this.proofVerifier),
1177
- );
1178
- }
1179
-
1180
1386
  private async validateRequestedTx(tx: Tx, peerId: PeerId, txValidator: TxValidator, requested?: Set<`0x${string}`>) {
1181
1387
  const penalize = (severity: PeerErrorSeverity) => this.peerManager.penalizePeer(peerId, severity);
1182
-
1183
- if (!(await tx.validateTxHash())) {
1184
- penalize(PeerErrorSeverity.MidToleranceError);
1185
- throw new ValidationError(`Received tx with invalid hash ${tx.getTxHash().toString()}.`);
1186
- }
1187
-
1188
1388
  if (requested && !requested.has(tx.getTxHash().toString())) {
1189
1389
  penalize(PeerErrorSeverity.MidToleranceError);
1190
1390
  throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
@@ -1197,6 +1397,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1197
1397
  }
1198
1398
  }
1199
1399
 
1400
+ private createRequestedTxValidator(): TxValidator {
1401
+ return createTxReqRespValidator(this.proofVerifier, {
1402
+ l1ChainId: this.config.l1ChainId,
1403
+ rollupVersion: this.config.rollupVersion,
1404
+ });
1405
+ }
1406
+
1200
1407
  @trackSpan('Libp2pService.validatePropagatedTx', tx => ({
1201
1408
  [Attributes.TX_HASH]: tx.getTxHash().toString(),
1202
1409
  }))
@@ -1239,6 +1446,22 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1239
1446
  return gasFees;
1240
1447
  }
1241
1448
 
1449
+ /**
1450
+ * Get the BatchTxRequesterLibP2PService dependencies for creating BatchTxRequester instances
1451
+ */
1452
+ public getBatchTxRequesterService(): BatchTxRequesterLibP2PService {
1453
+ return {
1454
+ reqResp: this.reqresp,
1455
+ connectionSampler: this.reqresp.getConnectionSampler(),
1456
+ txValidatorConfig: {
1457
+ l1ChainId: this.config.l1ChainId,
1458
+ rollupVersion: this.config.rollupVersion,
1459
+ proofVerifier: this.proofVerifier,
1460
+ },
1461
+ peerScoring: this.peerManager,
1462
+ };
1463
+ }
1464
+
1242
1465
  public async validate(txs: Tx[]): Promise<void> {
1243
1466
  const currentBlockNumber = await this.archiver.getBlockNumber();
1244
1467
 
@@ -1289,6 +1512,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1289
1512
  this.proofVerifier,
1290
1513
  !this.config.disableTransactions,
1291
1514
  allowedInSetup,
1515
+ this.logger.getBindings(),
1292
1516
  );
1293
1517
  }
1294
1518
 
@@ -1342,15 +1566,18 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1342
1566
  return PeerErrorSeverity.HighToleranceError;
1343
1567
  }
1344
1568
 
1345
- const snapshotValidator = new DoubleSpendTxValidator({
1346
- nullifiersExist: async (nullifiers: Buffer[]) => {
1347
- const merkleTree = this.worldStateSynchronizer.getSnapshot(
1348
- BlockNumber(blockNumber - this.config.doubleSpendSeverePeerPenaltyWindow),
1349
- );
1350
- const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
1351
- return indices.map(index => index !== undefined);
1569
+ const snapshotValidator = new DoubleSpendTxValidator(
1570
+ {
1571
+ nullifiersExist: async (nullifiers: Buffer[]) => {
1572
+ const merkleTree = this.worldStateSynchronizer.getSnapshot(
1573
+ BlockNumber(blockNumber - this.config.doubleSpendSeverePeerPenaltyWindow),
1574
+ );
1575
+ const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
1576
+ return indices.map(index => index !== undefined);
1577
+ },
1352
1578
  },
1353
- });
1579
+ this.logger.getBindings(),
1580
+ );
1354
1581
 
1355
1582
  const validSnapshot = await snapshotValidator.validateTx(tx);
1356
1583
  if (validSnapshot.result !== 'valid') {
@@ -1361,24 +1588,28 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1361
1588
  }
1362
1589
 
1363
1590
  /**
1364
- * Validate an attestation.
1591
+ * Validate a checkpoint attestation.
1365
1592
  *
1366
- * @param attestation - The attestation to validate.
1367
- * @returns True if the attestation is valid, false otherwise.
1593
+ * @param attestation - The checkpoint attestation to validate.
1594
+ * @returns True if the checkpoint attestation is valid, false otherwise.
1368
1595
  */
1369
- @trackSpan('Libp2pService.validateAttestation', async (_, attestation) => ({
1596
+ @trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation) => ({
1370
1597
  [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
1371
1598
  [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
1372
1599
  [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
1373
1600
  }))
1374
- public async validateAttestation(peerId: PeerId, attestation: BlockAttestation): Promise<boolean> {
1375
- const severity = await this.attestationValidator.validate(attestation);
1376
- if (severity) {
1377
- this.peerManager.penalizePeer(peerId, severity);
1378
- return false;
1601
+ public async validateCheckpointAttestation(
1602
+ peerId: PeerId,
1603
+ attestation: CheckpointAttestation,
1604
+ ): Promise<P2PValidationResult> {
1605
+ const result = await this.checkpointAttestationValidator.validate(attestation);
1606
+
1607
+ if (result.result === 'reject') {
1608
+ this.logger.debug(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
1609
+ this.peerManager.penalizePeer(peerId, result.severity);
1379
1610
  }
1380
1611
 
1381
- return true;
1612
+ return result;
1382
1613
  }
1383
1614
 
1384
1615
  /**
@@ -1388,17 +1619,40 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1388
1619
  * @returns True if the block proposal is valid, false otherwise.
1389
1620
  */
1390
1621
  @trackSpan('Libp2pService.validateBlockProposal', (_peerId, block) => ({
1391
- [Attributes.SLOT_NUMBER]: block.payload.header.slotNumber.toString(),
1622
+ [Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
1392
1623
  }))
1393
- public async validateBlockProposal(peerId: PeerId, block: BlockProposal): Promise<boolean> {
1394
- const severity = await this.blockProposalValidator.validate(block);
1395
- if (severity) {
1624
+ public async validateBlockProposal(peerId: PeerId, block: BlockProposal): Promise<P2PValidationResult> {
1625
+ const result = await this.blockProposalValidator.validate(block);
1626
+
1627
+ if (result.result === 'reject') {
1396
1628
  this.logger.debug(`Penalizing peer ${peerId} for block proposal validation failure`);
1397
- this.peerManager.penalizePeer(peerId, severity);
1398
- return false;
1629
+ this.peerManager.penalizePeer(peerId, result.severity);
1399
1630
  }
1400
1631
 
1401
- return true;
1632
+ return result;
1633
+ }
1634
+
1635
+ /**
1636
+ * Validate a checkpoint proposal.
1637
+ *
1638
+ * @param checkpoint - The checkpoint proposal to validate.
1639
+ * @returns True if the checkpoint proposal is valid, false otherwise.
1640
+ */
1641
+ @trackSpan('Libp2pService.validateCheckpointProposal', (_peerId, checkpoint) => ({
1642
+ [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
1643
+ }))
1644
+ public async validateCheckpointProposal(
1645
+ peerId: PeerId,
1646
+ checkpoint: CheckpointProposal,
1647
+ ): Promise<P2PValidationResult> {
1648
+ const result = await this.checkpointProposalValidator.validate(checkpoint);
1649
+
1650
+ if (result.result === 'reject') {
1651
+ this.logger.debug(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
1652
+ this.peerManager.penalizePeer(peerId, result.severity);
1653
+ }
1654
+
1655
+ return result;
1402
1656
  }
1403
1657
 
1404
1658
  public getPeerScore(peerId: PeerId): number {