@aztec/p2p 0.0.1-commit.9b94fc1 → 0.0.1-commit.b468ad8

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 (384) 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 +16 -19
  10. package/dest/client/p2p_client.d.ts.map +1 -1
  11. package/dest/client/p2p_client.js +468 -128
  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 +37 -27
  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 +11 -6
  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 +30 -24
  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 +10 -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 +5 -3
  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 +754 -191
  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.d.ts +1 -1
  208. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  209. package/dest/services/reqresp/protocols/block.js +3 -2
  210. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +5 -1
  211. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  212. package/dest/services/reqresp/protocols/block_txs/bitvector.js +12 -0
  213. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
  214. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  215. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +16 -3
  216. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +19 -7
  217. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  218. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +44 -14
  219. package/dest/services/reqresp/protocols/status.d.ts +5 -4
  220. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  221. package/dest/services/reqresp/protocols/status.js +7 -3
  222. package/dest/services/reqresp/protocols/tx.d.ts +2 -3
  223. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  224. package/dest/services/reqresp/reqresp.d.ts +6 -1
  225. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  226. package/dest/services/reqresp/reqresp.js +460 -46
  227. package/dest/services/service.d.ts +19 -3
  228. package/dest/services/service.d.ts.map +1 -1
  229. package/dest/services/tx_collection/config.d.ts +4 -1
  230. package/dest/services/tx_collection/config.d.ts.map +1 -1
  231. package/dest/services/tx_collection/config.js +10 -2
  232. package/dest/services/tx_collection/fast_tx_collection.d.ts +9 -6
  233. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  234. package/dest/services/tx_collection/fast_tx_collection.js +16 -5
  235. package/dest/services/tx_collection/index.d.ts +2 -1
  236. package/dest/services/tx_collection/index.d.ts.map +1 -1
  237. package/dest/services/tx_collection/index.js +1 -0
  238. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  239. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  240. package/dest/services/tx_collection/instrumentation.js +10 -13
  241. package/dest/services/tx_collection/proposal_tx_collector.d.ts +48 -0
  242. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
  243. package/dest/services/tx_collection/proposal_tx_collector.js +50 -0
  244. package/dest/services/tx_collection/slow_tx_collection.d.ts +4 -3
  245. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  246. package/dest/services/tx_collection/tx_collection.d.ts +10 -9
  247. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  248. package/dest/services/tx_collection/tx_collection.js +5 -5
  249. package/dest/services/tx_provider.d.ts +4 -2
  250. package/dest/services/tx_provider.d.ts.map +1 -1
  251. package/dest/services/tx_provider.js +11 -2
  252. package/dest/services/tx_provider_instrumentation.d.ts +5 -2
  253. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  254. package/dest/services/tx_provider_instrumentation.js +14 -14
  255. package/dest/test-helpers/index.d.ts +3 -1
  256. package/dest/test-helpers/index.d.ts.map +1 -1
  257. package/dest/test-helpers/index.js +2 -0
  258. package/dest/test-helpers/mock-tx-helpers.js +1 -1
  259. package/dest/test-helpers/reqresp-nodes.d.ts +2 -2
  260. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  261. package/dest/test-helpers/test_tx_provider.d.ts +40 -0
  262. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
  263. package/dest/test-helpers/test_tx_provider.js +41 -0
  264. package/dest/test-helpers/testbench-utils.d.ts +158 -0
  265. package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
  266. package/dest/test-helpers/testbench-utils.js +297 -0
  267. package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
  268. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  269. package/dest/testbench/p2p_client_testbench_worker.js +218 -123
  270. package/dest/testbench/worker_client_manager.d.ts +51 -6
  271. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  272. package/dest/testbench/worker_client_manager.js +226 -39
  273. package/package.json +18 -18
  274. package/src/bootstrap/bootstrap.ts +7 -4
  275. package/src/client/factory.ts +11 -20
  276. package/src/client/interface.ts +19 -4
  277. package/src/client/p2p_client.ts +109 -155
  278. package/src/client/test/tx_proposal_collector/README.md +227 -0
  279. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +336 -0
  280. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
  281. package/src/config.ts +18 -19
  282. package/src/mem_pools/attestation_pool/attestation_pool.ts +68 -41
  283. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +241 -289
  284. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +163 -141
  285. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +141 -164
  286. package/src/mem_pools/attestation_pool/mocks.ts +21 -15
  287. package/src/mem_pools/instrumentation.ts +39 -14
  288. package/src/mem_pools/interface.ts +2 -4
  289. package/src/mem_pools/tx_pool/README.md +270 -0
  290. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +367 -371
  291. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +132 -0
  292. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +208 -0
  293. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
  294. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
  295. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +93 -0
  296. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
  297. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
  298. package/src/mem_pools/tx_pool/index.ts +0 -1
  299. package/src/mem_pools/tx_pool/priority.ts +8 -1
  300. package/src/mem_pools/tx_pool/tx_pool.ts +11 -5
  301. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +23 -17
  302. package/src/msg_validators/attestation_validator/attestation_validator.ts +37 -22
  303. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +19 -16
  304. package/src/msg_validators/clock_tolerance.ts +51 -0
  305. package/src/msg_validators/index.ts +1 -1
  306. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
  307. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
  308. package/src/msg_validators/proposal_validator/index.ts +3 -0
  309. package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
  310. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -0
  311. package/src/msg_validators/tx_validator/archive_cache.ts +3 -3
  312. package/src/msg_validators/tx_validator/block_header_validator.ts +6 -5
  313. package/src/msg_validators/tx_validator/data_validator.ts +18 -6
  314. package/src/msg_validators/tx_validator/double_spend_validator.ts +4 -3
  315. package/src/msg_validators/tx_validator/factory.ts +67 -25
  316. package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
  317. package/src/msg_validators/tx_validator/gas_validator.ts +17 -28
  318. package/src/msg_validators/tx_validator/index.ts +1 -0
  319. package/src/msg_validators/tx_validator/metadata_validator.ts +19 -8
  320. package/src/msg_validators/tx_validator/phases_validator.ts +5 -3
  321. package/src/msg_validators/tx_validator/size_validator.ts +22 -0
  322. package/src/msg_validators/tx_validator/test_utils.ts +1 -1
  323. package/src/msg_validators/tx_validator/timestamp_validator.ts +11 -5
  324. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
  325. package/src/msg_validators/tx_validator/tx_proof_validator.ts +8 -3
  326. package/src/services/data_store.ts +10 -7
  327. package/src/services/discv5/discV5_service.ts +1 -1
  328. package/src/services/dummy_service.ts +51 -0
  329. package/src/services/encoding.ts +6 -5
  330. package/src/services/libp2p/instrumentation.ts +32 -73
  331. package/src/services/libp2p/libp2p_service.ts +425 -180
  332. package/src/services/peer-manager/metrics.ts +39 -21
  333. package/src/services/peer-manager/peer_manager.ts +5 -4
  334. package/src/services/peer-manager/peer_scoring.ts +3 -4
  335. package/src/services/reqresp/batch-tx-requester/README.md +305 -0
  336. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +706 -0
  337. package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
  338. package/src/services/reqresp/batch-tx-requester/interface.ts +57 -0
  339. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +209 -0
  340. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +205 -0
  341. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
  342. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +65 -4
  343. package/src/services/reqresp/connection-sampler/connection_sampler.ts +19 -1
  344. package/src/services/reqresp/constants.ts +14 -0
  345. package/src/services/reqresp/interface.ts +4 -1
  346. package/src/services/reqresp/metrics.ts +36 -27
  347. package/src/services/reqresp/protocols/auth.ts +2 -2
  348. package/src/services/reqresp/protocols/block.ts +3 -2
  349. package/src/services/reqresp/protocols/block_txs/bitvector.ts +16 -0
  350. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +18 -4
  351. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +52 -10
  352. package/src/services/reqresp/protocols/status.ts +16 -12
  353. package/src/services/reqresp/protocols/tx.ts +1 -2
  354. package/src/services/reqresp/reqresp.ts +66 -19
  355. package/src/services/service.ts +23 -4
  356. package/src/services/tx_collection/config.ts +16 -2
  357. package/src/services/tx_collection/fast_tx_collection.ts +39 -15
  358. package/src/services/tx_collection/index.ts +5 -0
  359. package/src/services/tx_collection/instrumentation.ts +5 -13
  360. package/src/services/tx_collection/proposal_tx_collector.ts +114 -0
  361. package/src/services/tx_collection/slow_tx_collection.ts +3 -3
  362. package/src/services/tx_collection/tx_collection.ts +10 -9
  363. package/src/services/tx_provider.ts +19 -3
  364. package/src/services/tx_provider_instrumentation.ts +24 -14
  365. package/src/test-helpers/index.ts +2 -0
  366. package/src/test-helpers/mock-pubsub.ts +1 -1
  367. package/src/test-helpers/mock-tx-helpers.ts +1 -1
  368. package/src/test-helpers/reqresp-nodes.ts +1 -1
  369. package/src/test-helpers/test_tx_provider.ts +64 -0
  370. package/src/test-helpers/testbench-utils.ts +374 -0
  371. package/src/testbench/p2p_client_testbench_worker.ts +338 -119
  372. package/src/testbench/worker_client_manager.ts +304 -42
  373. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -80
  374. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
  375. package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -238
  376. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
  377. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
  378. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -82
  379. package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
  380. package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
  381. package/dest/msg_validators/block_proposal_validator/index.js +0 -1
  382. package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -283
  383. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -97
  384. 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 { SlotNumber } from '@aztec/foundation/branded-types';
3
- import { randomInt } from '@aztec/foundation/crypto';
4
- import { Fr } from '@aztec/foundation/fields';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
+ import { randomInt } from '@aztec/foundation/crypto/random';
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,
@@ -53,20 +62,19 @@ import type { P2PConfig } from '../../config.js';
53
62
  import { ProposalSlotCapExceededError } from '../../errors/attestation-pool.error.js';
54
63
  import type { MemPools } from '../../mem_pools/interface.js';
55
64
  import {
56
- AttestationValidator,
57
65
  BlockProposalValidator,
66
+ CheckpointAttestationValidator,
67
+ CheckpointProposalValidator,
58
68
  FishermanAttestationValidator,
59
69
  } from '../../msg_validators/index.js';
60
70
  import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
61
71
  import { getDefaultAllowedSetupFunctions } from '../../msg_validators/tx_validator/allowed_public_setup.js';
62
- import { type MessageValidator, createTxMessageValidators } from '../../msg_validators/tx_validator/factory.js';
63
72
  import {
64
- AggregateTxValidator,
65
- DataTxValidator,
66
- DoubleSpendTxValidator,
67
- MetadataTxValidator,
68
- TxProofValidator,
69
- } from '../../msg_validators/tx_validator/index.js';
73
+ type MessageValidator,
74
+ createTxMessageValidators,
75
+ createTxReqRespValidator,
76
+ } from '../../msg_validators/tx_validator/factory.js';
77
+ import { DoubleSpendTxValidator } from '../../msg_validators/tx_validator/index.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,10 +85,12 @@ 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,
@@ -101,7 +111,12 @@ import {
101
111
  reqRespTxHandler,
102
112
  } from '../reqresp/protocols/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,13 +140,14 @@ 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>;
133
149
 
134
- private feesCache: { blockNumber: number; gasFees: GasFees } | undefined;
150
+ private feesCache: { blockNumber: BlockNumber; gasFees: GasFees } | undefined;
135
151
 
136
152
  /**
137
153
  * Callback for when a block is received from a peer.
@@ -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(
@@ -153,7 +178,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
153
178
  private peerDiscoveryService: PeerDiscoveryService,
154
179
  private reqresp: ReqRespInterface,
155
180
  private peerManager: PeerManagerInterface,
156
- protected mempools: MemPools<T>,
181
+ protected mempools: MemPools,
157
182
  private archiver: L2BlockSource & ContractDataSource,
158
183
  private epochCache: EpochCacheInterface,
159
184
  private proofVerifier: ClientProtocolCircuitVerifier,
@@ -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
 
@@ -215,7 +257,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
215
257
  config: P2PConfig,
216
258
  peerId: PeerId,
217
259
  deps: {
218
- mempools: MemPools<T>;
260
+ mempools: MemPools;
219
261
  l2BlockSource: L2BlockSource & ContractDataSource;
220
262
  epochCache: EpochCacheInterface;
221
263
  proofVerifier: ClientProtocolCircuitVerifier;
@@ -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);
@@ -486,8 +523,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
486
523
  [ReqRespSubProtocol.BLOCK]: blockHandler.bind(this),
487
524
  };
488
525
 
489
- // Only handle block transactions request if attestation pool is available to the client
490
- if (this.mempools.attestationPool && !this.config.disableTransactions) {
526
+ if (!this.config.disableTransactions) {
491
527
  const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.mempools.txPool);
492
528
  requestResponseHandlers[ReqRespSubProtocol.BLOCK_TXS] = blockTxsHandler.bind(this);
493
529
  }
@@ -496,10 +532,32 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
496
532
  requestResponseHandlers[ReqRespSubProtocol.TX] = txHandler.bind(this);
497
533
  }
498
534
 
535
+ // Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
536
+ const reqrespSubProtocolValidators = {
537
+ ...DEFAULT_SUB_PROTOCOL_VALIDATORS,
538
+ [ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
539
+ [ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
540
+ [ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this),
541
+ };
542
+
543
+ await this.peerManager.initializePeers();
544
+
545
+ await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
546
+
547
+ await this.node.start();
548
+
549
+ // Subscribe to standard GossipSub topics by default
550
+ for (const topic of getTopicsForClientAndConfig(this.clientType, this.config.disableTransactions)) {
551
+ this.subscribeToTopic(this.topicStrings[topic]);
552
+ }
553
+
499
554
  // add GossipSub listener
500
555
  this.node.services.pubsub.addEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
501
556
 
502
557
  // Start running promise for peer discovery and metrics collection
558
+ if (!this.config.p2pDiscoveryDisabled) {
559
+ await this.peerDiscoveryService.start();
560
+ }
503
561
  this.discoveryRunningPromise = new RunningPromise(
504
562
  async () => {
505
563
  await this.peerManager.heartbeat();
@@ -509,14 +567,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
509
567
  );
510
568
  this.discoveryRunningPromise.start();
511
569
 
512
- // Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
513
- const reqrespSubProtocolValidators = {
514
- ...DEFAULT_SUB_PROTOCOL_VALIDATORS,
515
- [ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
516
- [ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
517
- [ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this),
518
- };
519
- await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
520
570
  this.logger.info(`Started P2P service`, {
521
571
  listen: this.config.listenAddress,
522
572
  port: this.config.p2pPort,
@@ -590,6 +640,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
590
640
  return this.reqresp.sendBatchRequest(protocol, requests, pinnedPeerId);
591
641
  }
592
642
 
643
+ public sendRequestToPeer(
644
+ peerId: PeerId,
645
+ subProtocol: ReqRespSubProtocol,
646
+ payload: Buffer,
647
+ dialTimeout?: number,
648
+ ): Promise<ReqRespResponse> {
649
+ return this.reqresp.sendRequestToPeer(peerId, subProtocol, payload, dialTimeout);
650
+ }
651
+
593
652
  /**
594
653
  * Get the ENR of the node
595
654
  * @returns The ENR of the node
@@ -602,6 +661,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
602
661
  this.blockReceivedCallback = callback;
603
662
  }
604
663
 
664
+ public registerCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
665
+ this.checkpointReceivedCallback = callback;
666
+ }
667
+
605
668
  /**
606
669
  * Subscribes to a topic.
607
670
  * @param topic - The topic to subscribe to.
@@ -623,7 +686,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
623
686
  if (!this.node.services.pubsub) {
624
687
  throw new Error('Pubsub service not available.');
625
688
  }
626
- const p2pMessage = P2PMessage.fromGossipable(message, this.config.debugP2PInstrumentMessages);
689
+ const isBlockProposal = topic === this.topicStrings[TopicType.block_proposal];
690
+ const traceContext =
691
+ this.config.debugP2PInstrumentMessages && isBlockProposal ? this.telemetry.getTraceContext() : undefined;
692
+ const p2pMessage = P2PMessage.fromGossipable(message, this.config.debugP2PInstrumentMessages, traceContext);
627
693
  const result = await this.node.services.pubsub.publish(topic, p2pMessage.toMessageData());
628
694
  return result.recipients.length;
629
695
  }
@@ -644,12 +710,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
644
710
  case this.topicStrings[TopicType.tx]:
645
711
  topicType = TopicType.tx;
646
712
  break;
647
- case this.topicStrings[TopicType.block_attestation]:
648
- topicType = TopicType.block_attestation;
649
- break;
650
713
  case this.topicStrings[TopicType.block_proposal]:
651
714
  topicType = TopicType.block_proposal;
652
715
  break;
716
+ case this.topicStrings[TopicType.checkpoint_proposal]:
717
+ topicType = TopicType.checkpoint_proposal;
718
+ break;
719
+ case this.topicStrings[TopicType.checkpoint_attestation]:
720
+ topicType = TopicType.checkpoint_attestation;
721
+ break;
653
722
  default:
654
723
  this.logger.error(`Received message on unknown topic: ${msg.topic}`);
655
724
  break;
@@ -708,23 +777,74 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
708
777
  return;
709
778
  }
710
779
 
780
+ // Determine topic type for attributes
711
781
  if (msg.topic === this.topicStrings[TopicType.tx]) {
712
782
  topicType = TopicType.tx;
713
- await this.handleGossipedTx(p2pMessage.payload, msgId, source);
783
+ } else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
784
+ topicType = TopicType.checkpoint_attestation;
785
+ } else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
786
+ topicType = TopicType.block_proposal;
787
+ } else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
788
+ topicType = TopicType.checkpoint_proposal;
714
789
  }
715
- if (msg.topic === this.topicStrings[TopicType.block_attestation]) {
716
- topicType = TopicType.block_attestation;
717
- if (this.clientType === P2PClientType.Full) {
718
- await this.processAttestationFromPeer(p2pMessage.payload, msgId, source);
790
+
791
+ // Process the message, optionally within a linked span for trace propagation
792
+ const processMessage = async () => {
793
+ if (msg.topic === this.topicStrings[TopicType.tx]) {
794
+ await this.handleGossipedTx(p2pMessage.payload, msgId, source);
795
+ } else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
796
+ if (this.clientType === P2PClientType.Full) {
797
+ await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
798
+ }
799
+ } else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
800
+ await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
801
+ } else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
802
+ await this.handleGossipedCheckpointProposal(p2pMessage.payload, msgId, source);
803
+ } else {
804
+ this.logger.error(`Received message on unknown topic: ${msg.topic}`);
719
805
  }
720
- }
721
- if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
722
- topicType = TopicType.block_proposal;
723
- await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
806
+ };
807
+
808
+ const latency = p2pMessage.timestamp !== undefined ? msgReceivedTime - p2pMessage.timestamp.getTime() : undefined;
809
+ const propagatedContext = p2pMessage.traceContext
810
+ ? this.telemetry.extractPropagatedContext(p2pMessage.traceContext)
811
+ : undefined;
812
+
813
+ if (propagatedContext) {
814
+ await this.tracer.startActiveSpan(
815
+ 'LibP2PService.processMessage',
816
+ {
817
+ attributes: {
818
+ [Attributes.TOPIC_NAME]: topicType!,
819
+ [Attributes.PEER_ID]: source.toString(),
820
+ },
821
+ },
822
+ propagatedContext,
823
+ async span => {
824
+ try {
825
+ await processMessage();
826
+ span.setStatus({
827
+ code: SpanStatusCode.OK,
828
+ });
829
+ } catch (err) {
830
+ span.setStatus({
831
+ code: SpanStatusCode.ERROR,
832
+ message: String(err),
833
+ });
834
+ if (typeof err === 'string' || (err && err instanceof Error)) {
835
+ span.recordException(err);
836
+ }
837
+ throw err;
838
+ } finally {
839
+ span.end();
840
+ }
841
+ },
842
+ );
843
+ } else {
844
+ await processMessage();
724
845
  }
725
846
 
726
- if (p2pMessage.timestamp !== undefined && topicType !== undefined) {
727
- const latency = msgReceivedTime - p2pMessage.timestamp.getTime();
847
+ if (latency !== undefined && topicType !== undefined) {
728
848
  this.instrumentation.recordMessageLatency(topicType, latency);
729
849
  }
730
850
 
@@ -801,27 +921,30 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
801
921
  }
802
922
 
803
923
  /**
804
- * Process Attestation From Peer
805
- * When a proposal is received from a peer, we add it to the attestation pool, so it can be accessed by other services.
806
- *
807
- * @param attestation - The attestation to process.
924
+ * Process a checkpoint attestation from a peer.
925
+ * Validates the attestation and adds it to the pool.
808
926
  */
809
- private async processAttestationFromPeer(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
810
- const validationFunc: () => Promise<ReceivedMessageValidationResult<BlockAttestation>> = async () => {
811
- const attestation = BlockAttestation.fromBuffer(payloadData);
812
- const pool = this.mempools.attestationPool!;
813
- const isValid = await this.validateAttestation(source, attestation);
814
- const exists = isValid && (await pool.hasAttestation(attestation));
927
+ private async processCheckpointAttestationFromPeer(
928
+ payloadData: Buffer,
929
+ msgId: string,
930
+ source: PeerId,
931
+ ): Promise<void> {
932
+ const validationFunc: () => Promise<ReceivedMessageValidationResult<CheckpointAttestation>> = async () => {
933
+ const attestation = CheckpointAttestation.fromBuffer(payloadData);
934
+ const pool = this.mempools.attestationPool;
935
+ const validationResult = await this.validateCheckpointAttestation(source, attestation);
936
+ const isValid = validationResult.result === 'accept';
937
+ const exists = isValid && (await pool.hasCheckpointAttestation(attestation));
815
938
 
816
939
  let canAdd = true;
817
940
  if (isValid && !exists) {
818
941
  const slot = attestation.payload.header.slotNumber;
819
942
  const { committee } = await this.epochCache.getCommittee(slot);
820
943
  const committeeSize = committee?.length ?? 0;
821
- canAdd = await pool.canAddAttestation(attestation, committeeSize);
944
+ canAdd = await pool.canAddCheckpointAttestation(attestation, committeeSize);
822
945
  }
823
946
 
824
- this.logger.trace(`Validate propagated block attestation`, {
947
+ this.logger.trace(`Validate propagated checkpoint attestation`, {
825
948
  isValid,
826
949
  exists,
827
950
  canAdd,
@@ -829,12 +952,12 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
829
952
  [Attributes.P2P_ID]: source.toString(),
830
953
  });
831
954
 
832
- if (!isValid) {
955
+ if (validationResult.result === 'reject') {
833
956
  return { result: TopicValidatorResult.Reject };
834
- } else if (exists) {
957
+ } else if (validationResult.result === 'ignore' || exists) {
835
958
  return { result: TopicValidatorResult.Ignore, obj: attestation };
836
959
  } else if (!canAdd) {
837
- this.logger.warn(`Dropping block attestation due to per-(slot, proposalId) attestation cap`, {
960
+ this.logger.warn(`Dropping checkpoint attestation due to per-(slot, proposalId) attestation cap`, {
838
961
  slot: attestation.payload.header.slotNumber.toString(),
839
962
  archive: attestation.archive.toString(),
840
963
  source: source.toString(),
@@ -845,11 +968,11 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
845
968
  }
846
969
  };
847
970
 
848
- const { result, obj: attestation } = await this.validateReceivedMessage<BlockAttestation>(
971
+ const { result, obj: attestation } = await this.validateReceivedMessage<CheckpointAttestation>(
849
972
  validationFunc,
850
973
  msgId,
851
974
  source,
852
- TopicType.block_attestation,
975
+ TopicType.checkpoint_attestation,
853
976
  );
854
977
 
855
978
  if (result !== TopicValidatorResult.Accept || !attestation) {
@@ -857,7 +980,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
857
980
  }
858
981
 
859
982
  this.logger.debug(
860
- `Received attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`,
983
+ `Received checkpoint attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`,
861
984
  {
862
985
  p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
863
986
  slot: attestation.slotNumber,
@@ -866,31 +989,30 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
866
989
  },
867
990
  );
868
991
 
869
- await this.mempools.attestationPool!.addAttestations([attestation]);
992
+ await this.mempools.attestationPool.addCheckpointAttestations([attestation]);
870
993
  }
871
994
 
872
995
  private async processBlockFromPeer(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
873
996
  const validationFunc: () => Promise<ReceivedMessageValidationResult<BlockProposal>> = async () => {
874
997
  const block = BlockProposal.fromBuffer(payloadData);
875
- const isValid = await this.validateBlockProposal(source, block);
998
+ const validationResult = await this.validateBlockProposal(source, block);
999
+ const isValid = validationResult.result === 'accept';
876
1000
  const pool = this.mempools.attestationPool;
877
1001
 
878
- // Note that we dont have an attestation pool if we're a prover node, but we still
879
- // subscribe to block proposal topics in order to prevent their txs from being cleared.
880
- const exists = isValid && (await pool?.hasBlockProposal(block));
881
- const canAdd = isValid && (await pool?.canAddProposal(block));
1002
+ const exists = isValid && (await pool.hasBlockProposal(block));
1003
+ const canAdd = isValid && (await pool.canAddProposal(block));
882
1004
 
883
1005
  this.logger.trace(`Validate propagated block proposal`, {
884
1006
  isValid,
885
1007
  exists,
886
1008
  canAdd,
887
- [Attributes.SLOT_NUMBER]: block.payload.header.slotNumber.toString(),
1009
+ [Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
888
1010
  [Attributes.P2P_ID]: source.toString(),
889
1011
  });
890
1012
 
891
- if (!isValid) {
1013
+ if (validationResult.result === 'reject') {
892
1014
  return { result: TopicValidatorResult.Reject };
893
- } else if (exists) {
1015
+ } else if (validationResult.result === 'ignore' || exists) {
894
1016
  return { result: TopicValidatorResult.Ignore, obj: block };
895
1017
  } else if (!canAdd) {
896
1018
  this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
@@ -920,6 +1042,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
920
1042
  }
921
1043
 
922
1044
  // REVIEW: callback pattern https://github.com/AztecProtocol/aztec-packages/issues/7963
1045
+ // REFACTOR(palla): This method should be moved to the p2p_client or to a separate component,
1046
+ // should not be here as it does not deal with p2p networking.
923
1047
  @trackSpan('Libp2pService.processValidBlockProposal', async block => ({
924
1048
  [Attributes.SLOT_NUMBER]: block.slotNumber,
925
1049
  [Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
@@ -927,21 +1051,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
927
1051
  }))
928
1052
  private async processValidBlockProposal(block: BlockProposal, sender: PeerId) {
929
1053
  const slot = block.slotNumber;
930
- const previousSlot = SlotNumber(slot - 1);
931
1054
  this.logger.verbose(`Received block proposal for slot ${slot} from external peer ${sender.toString()}.`, {
932
1055
  p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier(),
933
- slot: block.slotNumber,
934
- archive: block.archive.toString(),
935
1056
  source: sender.toString(),
1057
+ ...block.toBlockInfo(),
936
1058
  });
937
- const attestationsForPreviousSlot = await this.mempools.attestationPool?.getAttestationsForSlot(previousSlot);
938
- if (attestationsForPreviousSlot !== undefined) {
939
- this.logger.verbose(`Received ${attestationsForPreviousSlot.length} attestations for slot ${previousSlot}`);
940
- }
941
1059
 
942
- // Attempt to add proposal, then mark the txs in this proposal as non-evictable
1060
+ // Attempt to add proposal
943
1061
  try {
944
- await this.mempools.attestationPool?.addBlockProposal(block);
1062
+ await this.mempools.attestationPool.addBlockProposal(block);
945
1063
  } catch (err: unknown) {
946
1064
  // Drop proposals if we hit per-slot cap in the attestation pool; rethrow unknown errors
947
1065
  if (err instanceof ProposalSlotCapExceededError) {
@@ -954,34 +1072,126 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
954
1072
  }
955
1073
  throw err;
956
1074
  }
1075
+
1076
+ // Mark the txs in this proposal as non-evictable
957
1077
  await this.mempools.txPool.markTxsAsNonEvictable(block.txHashes);
958
- const attestations = await this.blockReceivedCallback(block, sender);
959
1078
 
960
- // TODO: fix up this pattern - the abstraction is not nice
961
- // The attestation can be undefined if no handler is registered / the validator deems the block invalid / in fisherman mode
962
- if (attestations?.length) {
963
- for (const attestation of attestations) {
964
- this.logger.verbose(`Broadcasting attestation for slot ${attestation.slotNumber}`, {
965
- p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
966
- slot: attestation.slotNumber,
967
- archive: attestation.archive.toString(),
1079
+ // Call the block received callback to validate the proposal.
1080
+ // Note: Validators do NOT attest to individual blocks, only to checkpoint proposals.
1081
+ const isValid = await this.blockReceivedCallback(block, sender);
1082
+ if (!isValid) {
1083
+ this.logger.warn(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
1084
+ }
1085
+ }
1086
+
1087
+ /**
1088
+ * Handle a gossiped checkpoint proposal.
1089
+ * Validates and processes the checkpoint proposal, then triggers the callback for attestation.
1090
+ */
1091
+ private async handleGossipedCheckpointProposal(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
1092
+ // TODO(palla/mbps): This pattern is repeated across multiple message handlers, consider abstracting it.
1093
+ const validationFunc: () => Promise<ReceivedMessageValidationResult<CheckpointProposal>> = async () => {
1094
+ const checkpoint = CheckpointProposal.fromBuffer(payloadData);
1095
+ const validationResult = await this.validateCheckpointProposal(source, checkpoint);
1096
+ const isValid = validationResult.result === 'accept';
1097
+ const pool = this.mempools.attestationPool;
1098
+
1099
+ const exists = isValid && (await pool.hasCheckpointProposal(checkpoint));
1100
+ const canAdd = isValid && (await pool.canAddCheckpointProposal(checkpoint));
1101
+
1102
+ this.logger.trace(`Validate propagated checkpoint proposal`, {
1103
+ isValid,
1104
+ exists,
1105
+ canAdd,
1106
+ [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
1107
+ [Attributes.P2P_ID]: source.toString(),
1108
+ });
1109
+
1110
+ if (validationResult.result === 'reject') {
1111
+ return { result: TopicValidatorResult.Reject };
1112
+ } else if (validationResult.result === 'ignore' || exists) {
1113
+ return { result: TopicValidatorResult.Ignore, obj: checkpoint };
1114
+ } else if (!canAdd) {
1115
+ this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
1116
+ this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
1117
+ slot: checkpoint.slotNumber.toString(),
1118
+ archive: checkpoint.archive.toString(),
1119
+ source: source.toString(),
968
1120
  });
969
- await this.broadcastAttestation(attestation);
1121
+ return { result: TopicValidatorResult.Reject };
1122
+ } else {
1123
+ return { result: TopicValidatorResult.Accept, obj: checkpoint };
970
1124
  }
1125
+ };
1126
+
1127
+ const { result, obj: checkpoint } = await this.validateReceivedMessage<CheckpointProposal>(
1128
+ validationFunc,
1129
+ msgId,
1130
+ source,
1131
+ TopicType.checkpoint_proposal,
1132
+ );
1133
+
1134
+ if (result !== TopicValidatorResult.Accept || !checkpoint) {
1135
+ return;
971
1136
  }
1137
+
1138
+ await this.processValidCheckpointProposal(checkpoint, source);
972
1139
  }
973
1140
 
974
1141
  /**
975
- * Broadcast an attestation to all peers.
976
- * @param attestation - The attestation to broadcast.
1142
+ * Process a validated checkpoint proposal.
1143
+ * Extracts and processes the last block proposal (if present) first, then processes the checkpoint.
1144
+ * The block callback is invoked before the checkpoint callback.
977
1145
  */
978
- @trackSpan('Libp2pService.broadcastAttestation', async attestation => ({
979
- [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
980
- [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
981
- [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
1146
+ @trackSpan('Libp2pService.processValidCheckpointProposal', async checkpoint => ({
1147
+ [Attributes.SLOT_NUMBER]: checkpoint.slotNumber,
1148
+ [Attributes.BLOCK_ARCHIVE]: checkpoint.archive.toString(),
1149
+ [Attributes.P2P_ID]: await checkpoint.p2pMessageLoggingIdentifier().then(i => i.toString()),
982
1150
  }))
983
- private async broadcastAttestation(attestation: BlockAttestation) {
984
- await this.propagate(attestation);
1151
+ private async processValidCheckpointProposal(checkpoint: CheckpointProposal, sender: PeerId) {
1152
+ const slot = checkpoint.slotNumber;
1153
+ this.logger.verbose(`Received checkpoint proposal for slot ${slot} from external peer ${sender.toString()}.`, {
1154
+ p2pMessageIdentifier: await checkpoint.p2pMessageLoggingIdentifier(),
1155
+ slot: checkpoint.slotNumber,
1156
+ archive: checkpoint.archive.toString(),
1157
+ source: sender.toString(),
1158
+ });
1159
+
1160
+ // Extract block proposal before adding to pool (pool stores them separately)
1161
+ const blockProposal = checkpoint.getBlockProposal();
1162
+
1163
+ // Add proposal to the pool (this extracts and stores block proposal separately)
1164
+ await this.mempools.attestationPool.addCheckpointProposal(checkpoint);
1165
+
1166
+ // Mark txs as non-evictable if present (from the last block)
1167
+ if (checkpoint.txHashes.length > 0) {
1168
+ await this.mempools.txPool.markTxsAsNonEvictable(checkpoint.txHashes);
1169
+ }
1170
+
1171
+ // If there was a last block proposal, invoke the block callback first for validation.
1172
+ // Note: The block proposal is already stored in the pool by addCheckpointProposal.
1173
+ if (blockProposal) {
1174
+ const isValid = await this.blockReceivedCallback(blockProposal, sender);
1175
+ if (!isValid) {
1176
+ this.logger.warn(`Block proposal from checkpoint failed validation`, {
1177
+ slot: slot.toString(),
1178
+ archive: checkpoint.archive.toString(),
1179
+ blockNumber: blockProposal.blockNumber.toString(),
1180
+ });
1181
+ return;
1182
+ }
1183
+ }
1184
+
1185
+ // Call the checkpoint received callback with the core version (without lastBlock)
1186
+ // to validate and potentially generate attestations
1187
+ const attestations = await this.checkpointReceivedCallback(checkpoint.toCore(), sender);
1188
+ if (attestations && attestations.length > 0) {
1189
+ // If the callback returned attestations, add them to the pool and propagate them
1190
+ await this.mempools.attestationPool.addCheckpointAttestations(attestations);
1191
+ for (const attestation of attestations) {
1192
+ await this.propagate(attestation);
1193
+ }
1194
+ }
985
1195
  }
986
1196
 
987
1197
  /**
@@ -1004,7 +1214,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1004
1214
  * @returns True if the requested block transactions are valid, false otherwise.
1005
1215
  */
1006
1216
  @trackSpan('Libp2pService.validateRequestedBlockTxs', request => ({
1007
- [Attributes.BLOCK_HASH]: request.blockHash.toString(),
1217
+ [Attributes.BLOCK_ARCHIVE]: request.archiveRoot.toString(),
1008
1218
  }))
1009
1219
  private async validateRequestedBlockTxs(
1010
1220
  request: BlockTxsRequest,
@@ -1014,10 +1224,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1014
1224
  const requestedTxValidator = this.createRequestedTxValidator();
1015
1225
 
1016
1226
  try {
1017
- if (!response.blockHash.equals(request.blockHash)) {
1227
+ if (!response.archiveRoot.equals(request.archiveRoot)) {
1018
1228
  this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1019
1229
  throw new ValidationError(
1020
- `Received block txs for unexpected block: expected ${request.blockHash.toString()}, got ${response.blockHash.toString()}`,
1230
+ `Received block txs for unexpected archive root: expected ${request.archiveRoot.toString()}, got ${response.archiveRoot.toString()}`,
1021
1231
  );
1022
1232
  }
1023
1233
 
@@ -1047,7 +1257,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1047
1257
  }
1048
1258
 
1049
1259
  // Given proposal (should have locally), ensure returned txs are valid subset and match request indices
1050
- const proposal = await this.mempools.attestationPool?.getBlockProposal(request.blockHash.toString());
1260
+ const proposal = await this.mempools.attestationPool.getBlockProposal(request.archiveRoot.toString());
1051
1261
  if (proposal) {
1052
1262
  // Build intersected indices
1053
1263
  const intersectIdx = request.txIndices.getTrueIndices().filter(i => response.txIndices.isSet(i));
@@ -1067,7 +1277,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1067
1277
  } else {
1068
1278
  // No local proposal, cannot check the membership/order of the returned txs
1069
1279
  this.logger.warn(
1070
- `Block proposal not found for block hash ${request.blockHash.toString()}; cannot validate membership/order of returned txs`,
1280
+ `Block proposal not found for archive root ${request.archiveRoot.toString()}; cannot validate membership/order of returned txs`,
1071
1281
  );
1072
1282
  return false;
1073
1283
  }
@@ -1106,7 +1316,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1106
1316
  const requested = new Set(requestedTxHash.map(h => h.toString()));
1107
1317
  const requestedTxValidator = this.createRequestedTxValidator();
1108
1318
 
1109
- //TODO: (mralj) - this is somewhat naive implementation, if single tx is invlid we consider the whole response invalid.
1319
+ //TODO: (mralj) - this is somewhat naive implementation, if single tx is invalid we consider the whole response invalid.
1110
1320
  // I think we should still extract the valid txs and return them, so that we can still use the response.
1111
1321
  try {
1112
1322
  await Promise.all(responseTx.map(tx => this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
@@ -1148,7 +1358,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1148
1358
  return false;
1149
1359
  }
1150
1360
 
1151
- const local = await this.archiver.getBlock(reqNum);
1361
+ const local = await this.archiver.getBlock(BlockNumber(reqNum));
1152
1362
  if (!local) {
1153
1363
  // We are missing the local block; we cannot verify the hash yet. Reject without penalizing.
1154
1364
  // TODO: Consider extending this validator to accept an expected hash or
@@ -1169,27 +1379,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1169
1379
  }
1170
1380
  }
1171
1381
 
1172
- private createRequestedTxValidator(): TxValidator {
1173
- return new AggregateTxValidator(
1174
- new DataTxValidator(),
1175
- new MetadataTxValidator({
1176
- l1ChainId: new Fr(this.config.l1ChainId),
1177
- rollupVersion: new Fr(this.config.rollupVersion),
1178
- protocolContractsHash,
1179
- vkTreeRoot: getVKTreeRoot(),
1180
- }),
1181
- new TxProofValidator(this.proofVerifier),
1182
- );
1183
- }
1184
-
1185
1382
  private async validateRequestedTx(tx: Tx, peerId: PeerId, txValidator: TxValidator, requested?: Set<`0x${string}`>) {
1186
1383
  const penalize = (severity: PeerErrorSeverity) => this.peerManager.penalizePeer(peerId, severity);
1187
-
1188
- if (!(await tx.validateTxHash())) {
1189
- penalize(PeerErrorSeverity.MidToleranceError);
1190
- throw new ValidationError(`Received tx with invalid hash ${tx.getTxHash().toString()}.`);
1191
- }
1192
-
1193
1384
  if (requested && !requested.has(tx.getTxHash().toString())) {
1194
1385
  penalize(PeerErrorSeverity.MidToleranceError);
1195
1386
  throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
@@ -1202,6 +1393,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1202
1393
  }
1203
1394
  }
1204
1395
 
1396
+ private createRequestedTxValidator(): TxValidator {
1397
+ return createTxReqRespValidator(this.proofVerifier, {
1398
+ l1ChainId: this.config.l1ChainId,
1399
+ rollupVersion: this.config.rollupVersion,
1400
+ });
1401
+ }
1402
+
1205
1403
  @trackSpan('Libp2pService.validatePropagatedTx', tx => ({
1206
1404
  [Attributes.TX_HASH]: tx.getTxHash().toString(),
1207
1405
  }))
@@ -1223,7 +1421,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1223
1421
 
1224
1422
  // Double spend validator has a special case handler
1225
1423
  if (name === 'doubleSpendValidator') {
1226
- const txBlockNumber = currentBlockNumber + 1; // tx is expected to be in the next block
1424
+ const txBlockNumber = BlockNumber(currentBlockNumber + 1); // tx is expected to be in the next block
1227
1425
  severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
1228
1426
  }
1229
1427
 
@@ -1233,7 +1431,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1233
1431
  return true;
1234
1432
  }
1235
1433
 
1236
- private async getGasFees(blockNumber: number): Promise<GasFees> {
1434
+ private async getGasFees(blockNumber: BlockNumber): Promise<GasFees> {
1237
1435
  if (blockNumber === this.feesCache?.blockNumber) {
1238
1436
  return this.feesCache.gasFees;
1239
1437
  }
@@ -1244,6 +1442,22 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1244
1442
  return gasFees;
1245
1443
  }
1246
1444
 
1445
+ /**
1446
+ * Get the BatchTxRequesterLibP2PService dependencies for creating BatchTxRequester instances
1447
+ */
1448
+ public getBatchTxRequesterService(): BatchTxRequesterLibP2PService {
1449
+ return {
1450
+ reqResp: this.reqresp,
1451
+ connectionSampler: this.reqresp.getConnectionSampler(),
1452
+ txValidatorConfig: {
1453
+ l1ChainId: this.config.l1ChainId,
1454
+ rollupVersion: this.config.rollupVersion,
1455
+ proofVerifier: this.proofVerifier,
1456
+ },
1457
+ peerScoring: this.peerManager,
1458
+ };
1459
+ }
1460
+
1247
1461
  public async validate(txs: Tx[]): Promise<void> {
1248
1462
  const currentBlockNumber = await this.archiver.getBlockNumber();
1249
1463
 
@@ -1274,13 +1488,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1274
1488
  * @returns The message validators.
1275
1489
  */
1276
1490
  private async createMessageValidators(
1277
- currentBlockNumber: number,
1491
+ currentBlockNumber: BlockNumber,
1278
1492
  nextSlotTimestamp: UInt64,
1279
1493
  ): Promise<Record<string, MessageValidator>[]> {
1280
1494
  const gasFees = await this.getGasFees(currentBlockNumber);
1281
1495
  const allowedInSetup = this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
1282
1496
 
1283
- const blockNumberInWhichTheTxIsConsideredToBeIncluded = currentBlockNumber + 1;
1497
+ const blockNumberInWhichTheTxIsConsideredToBeIncluded = BlockNumber(currentBlockNumber + 1);
1284
1498
 
1285
1499
  return createTxMessageValidators(
1286
1500
  nextSlotTimestamp,
@@ -1294,6 +1508,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1294
1508
  this.proofVerifier,
1295
1509
  !this.config.disableTransactions,
1296
1510
  allowedInSetup,
1511
+ this.logger.getBindings(),
1297
1512
  );
1298
1513
  }
1299
1514
 
@@ -1342,20 +1557,23 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1342
1557
  * @param peerId - The peer ID of the peer that sent the tx.
1343
1558
  * @returns Severity
1344
1559
  */
1345
- private async handleDoubleSpendFailure(tx: Tx, blockNumber: number): Promise<PeerErrorSeverity> {
1560
+ private async handleDoubleSpendFailure(tx: Tx, blockNumber: BlockNumber): Promise<PeerErrorSeverity> {
1346
1561
  if (blockNumber <= this.config.doubleSpendSeverePeerPenaltyWindow) {
1347
1562
  return PeerErrorSeverity.HighToleranceError;
1348
1563
  }
1349
1564
 
1350
- const snapshotValidator = new DoubleSpendTxValidator({
1351
- nullifiersExist: async (nullifiers: Buffer[]) => {
1352
- const merkleTree = this.worldStateSynchronizer.getSnapshot(
1353
- blockNumber - this.config.doubleSpendSeverePeerPenaltyWindow,
1354
- );
1355
- const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
1356
- return indices.map(index => index !== undefined);
1565
+ const snapshotValidator = new DoubleSpendTxValidator(
1566
+ {
1567
+ nullifiersExist: async (nullifiers: Buffer[]) => {
1568
+ const merkleTree = this.worldStateSynchronizer.getSnapshot(
1569
+ BlockNumber(blockNumber - this.config.doubleSpendSeverePeerPenaltyWindow),
1570
+ );
1571
+ const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
1572
+ return indices.map(index => index !== undefined);
1573
+ },
1357
1574
  },
1358
- });
1575
+ this.logger.getBindings(),
1576
+ );
1359
1577
 
1360
1578
  const validSnapshot = await snapshotValidator.validateTx(tx);
1361
1579
  if (validSnapshot.result !== 'valid') {
@@ -1366,24 +1584,28 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1366
1584
  }
1367
1585
 
1368
1586
  /**
1369
- * Validate an attestation.
1587
+ * Validate a checkpoint attestation.
1370
1588
  *
1371
- * @param attestation - The attestation to validate.
1372
- * @returns True if the attestation is valid, false otherwise.
1589
+ * @param attestation - The checkpoint attestation to validate.
1590
+ * @returns True if the checkpoint attestation is valid, false otherwise.
1373
1591
  */
1374
- @trackSpan('Libp2pService.validateAttestation', async (_, attestation) => ({
1592
+ @trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation) => ({
1375
1593
  [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
1376
1594
  [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
1377
1595
  [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
1378
1596
  }))
1379
- public async validateAttestation(peerId: PeerId, attestation: BlockAttestation): Promise<boolean> {
1380
- const severity = await this.attestationValidator.validate(attestation);
1381
- if (severity) {
1382
- this.peerManager.penalizePeer(peerId, severity);
1383
- return false;
1597
+ public async validateCheckpointAttestation(
1598
+ peerId: PeerId,
1599
+ attestation: CheckpointAttestation,
1600
+ ): Promise<P2PValidationResult> {
1601
+ const result = await this.checkpointAttestationValidator.validate(attestation);
1602
+
1603
+ if (result.result === 'reject') {
1604
+ this.logger.debug(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
1605
+ this.peerManager.penalizePeer(peerId, result.severity);
1384
1606
  }
1385
1607
 
1386
- return true;
1608
+ return result;
1387
1609
  }
1388
1610
 
1389
1611
  /**
@@ -1393,17 +1615,40 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1393
1615
  * @returns True if the block proposal is valid, false otherwise.
1394
1616
  */
1395
1617
  @trackSpan('Libp2pService.validateBlockProposal', (_peerId, block) => ({
1396
- [Attributes.SLOT_NUMBER]: block.payload.header.slotNumber.toString(),
1618
+ [Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
1397
1619
  }))
1398
- public async validateBlockProposal(peerId: PeerId, block: BlockProposal): Promise<boolean> {
1399
- const severity = await this.blockProposalValidator.validate(block);
1400
- if (severity) {
1620
+ public async validateBlockProposal(peerId: PeerId, block: BlockProposal): Promise<P2PValidationResult> {
1621
+ const result = await this.blockProposalValidator.validate(block);
1622
+
1623
+ if (result.result === 'reject') {
1401
1624
  this.logger.debug(`Penalizing peer ${peerId} for block proposal validation failure`);
1402
- this.peerManager.penalizePeer(peerId, severity);
1403
- return false;
1625
+ this.peerManager.penalizePeer(peerId, result.severity);
1404
1626
  }
1405
1627
 
1406
- return true;
1628
+ return result;
1629
+ }
1630
+
1631
+ /**
1632
+ * Validate a checkpoint proposal.
1633
+ *
1634
+ * @param checkpoint - The checkpoint proposal to validate.
1635
+ * @returns True if the checkpoint proposal is valid, false otherwise.
1636
+ */
1637
+ @trackSpan('Libp2pService.validateCheckpointProposal', (_peerId, checkpoint) => ({
1638
+ [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
1639
+ }))
1640
+ public async validateCheckpointProposal(
1641
+ peerId: PeerId,
1642
+ checkpoint: CheckpointProposal,
1643
+ ): Promise<P2PValidationResult> {
1644
+ const result = await this.checkpointProposalValidator.validate(checkpoint);
1645
+
1646
+ if (result.result === 'reject') {
1647
+ this.logger.debug(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
1648
+ this.peerManager.penalizePeer(peerId, result.severity);
1649
+ }
1650
+
1651
+ return result;
1407
1652
  }
1408
1653
 
1409
1654
  public getPeerScore(peerId: PeerId): number {