@aztec/p2p 0.0.1-commit.c7c42ec → 0.0.1-commit.c80b6263

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 (332) 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 +6 -5
  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 +10 -13
  10. package/dest/client/p2p_client.d.ts.map +1 -1
  11. package/dest/client/p2p_client.js +449 -118
  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 +8 -2
  19. package/dest/config.d.ts.map +1 -1
  20. package/dest/config.js +4 -2
  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/msg_validators/attestation_validator/attestation_validator.d.ts +4 -4
  61. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  62. package/dest/msg_validators/attestation_validator/attestation_validator.js +51 -18
  63. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -5
  64. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  65. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +22 -13
  66. package/dest/msg_validators/clock_tolerance.d.ts +21 -0
  67. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
  68. package/dest/msg_validators/clock_tolerance.js +37 -0
  69. package/dest/msg_validators/index.d.ts +2 -2
  70. package/dest/msg_validators/index.d.ts.map +1 -1
  71. package/dest/msg_validators/index.js +1 -1
  72. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
  73. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
  74. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
  75. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
  76. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
  77. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
  78. package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
  79. package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
  80. package/dest/msg_validators/proposal_validator/index.js +3 -0
  81. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
  82. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
  83. package/dest/msg_validators/proposal_validator/proposal_validator.js +104 -0
  84. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
  85. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
  86. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +212 -0
  87. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +3 -2
  88. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  89. package/dest/msg_validators/tx_validator/block_header_validator.js +4 -3
  90. package/dest/msg_validators/tx_validator/data_validator.d.ts +3 -1
  91. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  92. package/dest/msg_validators/tx_validator/data_validator.js +4 -1
  93. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +3 -2
  94. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  95. package/dest/msg_validators/tx_validator/double_spend_validator.js +3 -2
  96. package/dest/msg_validators/tx_validator/factory.d.ts +8 -3
  97. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  98. package/dest/msg_validators/tx_validator/factory.js +21 -11
  99. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
  100. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
  101. package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
  102. package/dest/msg_validators/tx_validator/gas_validator.d.ts +3 -2
  103. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  104. package/dest/msg_validators/tx_validator/gas_validator.js +11 -16
  105. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  106. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  107. package/dest/msg_validators/tx_validator/index.js +1 -0
  108. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +3 -2
  109. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  110. package/dest/msg_validators/tx_validator/metadata_validator.js +2 -2
  111. package/dest/msg_validators/tx_validator/phases_validator.d.ts +3 -2
  112. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  113. package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
  114. package/dest/msg_validators/tx_validator/size_validator.d.ts +8 -0
  115. package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
  116. package/dest/msg_validators/tx_validator/size_validator.js +23 -0
  117. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +3 -2
  118. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  119. package/dest/msg_validators/tx_validator/timestamp_validator.js +2 -2
  120. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
  121. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
  122. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
  123. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +3 -2
  124. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  125. package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -2
  126. package/dest/services/discv5/discV5_service.js +1 -1
  127. package/dest/services/dummy_service.d.ts +18 -2
  128. package/dest/services/dummy_service.d.ts.map +1 -1
  129. package/dest/services/dummy_service.js +42 -0
  130. package/dest/services/encoding.d.ts +1 -1
  131. package/dest/services/encoding.d.ts.map +1 -1
  132. package/dest/services/encoding.js +6 -5
  133. package/dest/services/libp2p/instrumentation.d.ts +1 -1
  134. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  135. package/dest/services/libp2p/instrumentation.js +30 -72
  136. package/dest/services/libp2p/libp2p_service.d.ts +36 -13
  137. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  138. package/dest/services/libp2p/libp2p_service.js +741 -173
  139. package/dest/services/peer-manager/metrics.d.ts +2 -2
  140. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  141. package/dest/services/peer-manager/metrics.js +21 -26
  142. package/dest/services/peer-manager/peer_manager.d.ts +2 -2
  143. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  144. package/dest/services/peer-manager/peer_manager.js +0 -10
  145. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  146. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  147. package/dest/services/peer-manager/peer_scoring.js +7 -4
  148. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +47 -0
  149. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
  150. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +566 -0
  151. package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
  152. package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
  153. package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
  154. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +50 -0
  155. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
  156. package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
  157. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +37 -0
  158. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
  159. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +151 -0
  160. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +54 -0
  161. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
  162. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +139 -0
  163. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +20 -0
  164. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
  165. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
  166. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +22 -3
  167. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  168. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +63 -4
  169. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -1
  170. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  171. package/dest/services/reqresp/connection-sampler/connection_sampler.js +12 -0
  172. package/dest/services/reqresp/constants.d.ts +12 -0
  173. package/dest/services/reqresp/constants.d.ts.map +1 -0
  174. package/dest/services/reqresp/constants.js +7 -0
  175. package/dest/services/reqresp/interface.d.ts +3 -1
  176. package/dest/services/reqresp/interface.d.ts.map +1 -1
  177. package/dest/services/reqresp/metrics.d.ts +6 -5
  178. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  179. package/dest/services/reqresp/metrics.js +17 -21
  180. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +5 -1
  181. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  182. package/dest/services/reqresp/protocols/block_txs/bitvector.js +12 -0
  183. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
  184. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  185. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +14 -1
  186. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +15 -3
  187. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  188. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +33 -3
  189. package/dest/services/reqresp/protocols/status.d.ts +1 -1
  190. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  191. package/dest/services/reqresp/protocols/status.js +4 -1
  192. package/dest/services/reqresp/reqresp.d.ts +6 -1
  193. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  194. package/dest/services/reqresp/reqresp.js +460 -46
  195. package/dest/services/service.d.ts +19 -3
  196. package/dest/services/service.d.ts.map +1 -1
  197. package/dest/services/tx_collection/config.d.ts +4 -1
  198. package/dest/services/tx_collection/config.d.ts.map +1 -1
  199. package/dest/services/tx_collection/config.js +9 -1
  200. package/dest/services/tx_collection/fast_tx_collection.d.ts +6 -4
  201. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  202. package/dest/services/tx_collection/fast_tx_collection.js +16 -5
  203. package/dest/services/tx_collection/index.d.ts +2 -1
  204. package/dest/services/tx_collection/index.d.ts.map +1 -1
  205. package/dest/services/tx_collection/index.js +1 -0
  206. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  207. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  208. package/dest/services/tx_collection/instrumentation.js +10 -13
  209. package/dest/services/tx_collection/proposal_tx_collector.d.ts +48 -0
  210. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
  211. package/dest/services/tx_collection/proposal_tx_collector.js +50 -0
  212. package/dest/services/tx_collection/slow_tx_collection.d.ts +3 -3
  213. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  214. package/dest/services/tx_collection/tx_collection.d.ts +8 -8
  215. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  216. package/dest/services/tx_collection/tx_collection.js +5 -5
  217. package/dest/services/tx_provider.d.ts +3 -3
  218. package/dest/services/tx_provider.d.ts.map +1 -1
  219. package/dest/services/tx_provider_instrumentation.d.ts +1 -1
  220. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  221. package/dest/services/tx_provider_instrumentation.js +7 -20
  222. package/dest/test-helpers/index.d.ts +3 -1
  223. package/dest/test-helpers/index.d.ts.map +1 -1
  224. package/dest/test-helpers/index.js +2 -0
  225. package/dest/test-helpers/test_tx_provider.d.ts +40 -0
  226. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
  227. package/dest/test-helpers/test_tx_provider.js +41 -0
  228. package/dest/test-helpers/testbench-utils.d.ts +156 -0
  229. package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
  230. package/dest/test-helpers/testbench-utils.js +296 -0
  231. package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
  232. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  233. package/dest/testbench/p2p_client_testbench_worker.js +218 -124
  234. package/dest/testbench/worker_client_manager.d.ts +51 -6
  235. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  236. package/dest/testbench/worker_client_manager.js +226 -39
  237. package/package.json +16 -16
  238. package/src/bootstrap/bootstrap.ts +7 -4
  239. package/src/client/factory.ts +6 -10
  240. package/src/client/interface.ts +19 -4
  241. package/src/client/p2p_client.ts +82 -132
  242. package/src/client/test/tx_proposal_collector/README.md +227 -0
  243. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +336 -0
  244. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
  245. package/src/config.ts +8 -3
  246. package/src/mem_pools/attestation_pool/attestation_pool.ts +68 -41
  247. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +239 -287
  248. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +162 -140
  249. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +141 -164
  250. package/src/mem_pools/attestation_pool/mocks.ts +19 -13
  251. package/src/mem_pools/instrumentation.ts +10 -18
  252. package/src/mem_pools/tx_pool/README.md +28 -13
  253. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +130 -75
  254. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +66 -5
  255. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +119 -4
  256. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
  257. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +4 -2
  258. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
  259. package/src/msg_validators/attestation_validator/attestation_validator.ts +36 -21
  260. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +19 -16
  261. package/src/msg_validators/clock_tolerance.ts +51 -0
  262. package/src/msg_validators/index.ts +1 -1
  263. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
  264. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
  265. package/src/msg_validators/proposal_validator/index.ts +3 -0
  266. package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
  267. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -0
  268. package/src/msg_validators/tx_validator/block_header_validator.ts +7 -4
  269. package/src/msg_validators/tx_validator/data_validator.ts +18 -6
  270. package/src/msg_validators/tx_validator/double_spend_validator.ts +4 -3
  271. package/src/msg_validators/tx_validator/factory.ts +64 -23
  272. package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
  273. package/src/msg_validators/tx_validator/gas_validator.ts +17 -28
  274. package/src/msg_validators/tx_validator/index.ts +1 -0
  275. package/src/msg_validators/tx_validator/metadata_validator.ts +18 -7
  276. package/src/msg_validators/tx_validator/phases_validator.ts +5 -3
  277. package/src/msg_validators/tx_validator/size_validator.ts +22 -0
  278. package/src/msg_validators/tx_validator/timestamp_validator.ts +9 -4
  279. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
  280. package/src/msg_validators/tx_validator/tx_proof_validator.ts +8 -3
  281. package/src/services/discv5/discV5_service.ts +1 -1
  282. package/src/services/dummy_service.ts +51 -0
  283. package/src/services/encoding.ts +5 -4
  284. package/src/services/libp2p/instrumentation.ts +32 -73
  285. package/src/services/libp2p/libp2p_service.ts +404 -154
  286. package/src/services/peer-manager/metrics.ts +22 -26
  287. package/src/services/peer-manager/peer_manager.ts +1 -2
  288. package/src/services/peer-manager/peer_scoring.ts +3 -4
  289. package/src/services/reqresp/batch-tx-requester/README.md +305 -0
  290. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +706 -0
  291. package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
  292. package/src/services/reqresp/batch-tx-requester/interface.ts +57 -0
  293. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +209 -0
  294. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +205 -0
  295. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
  296. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +65 -4
  297. package/src/services/reqresp/connection-sampler/connection_sampler.ts +19 -1
  298. package/src/services/reqresp/constants.ts +14 -0
  299. package/src/services/reqresp/interface.ts +3 -0
  300. package/src/services/reqresp/metrics.ts +36 -27
  301. package/src/services/reqresp/protocols/block_txs/bitvector.ts +16 -0
  302. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +16 -2
  303. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +46 -4
  304. package/src/services/reqresp/protocols/status.ts +7 -4
  305. package/src/services/reqresp/reqresp.ts +66 -19
  306. package/src/services/service.ts +23 -4
  307. package/src/services/tx_collection/config.ts +15 -1
  308. package/src/services/tx_collection/fast_tx_collection.ts +36 -13
  309. package/src/services/tx_collection/index.ts +5 -0
  310. package/src/services/tx_collection/instrumentation.ts +5 -13
  311. package/src/services/tx_collection/proposal_tx_collector.ts +114 -0
  312. package/src/services/tx_collection/slow_tx_collection.ts +2 -2
  313. package/src/services/tx_collection/tx_collection.ts +8 -8
  314. package/src/services/tx_provider.ts +2 -2
  315. package/src/services/tx_provider_instrumentation.ts +13 -20
  316. package/src/test-helpers/index.ts +2 -0
  317. package/src/test-helpers/test_tx_provider.ts +64 -0
  318. package/src/test-helpers/testbench-utils.ts +372 -0
  319. package/src/testbench/p2p_client_testbench_worker.ts +337 -119
  320. package/src/testbench/worker_client_manager.ts +304 -42
  321. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +0 -15
  322. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +0 -1
  323. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +0 -88
  324. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
  325. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
  326. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -82
  327. package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
  328. package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
  329. package/dest/msg_validators/block_proposal_validator/index.js +0 -1
  330. package/src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts +0 -108
  331. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -97
  332. 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,
@@ -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,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);
@@ -495,10 +532,32 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
495
532
  requestResponseHandlers[ReqRespSubProtocol.TX] = txHandler.bind(this);
496
533
  }
497
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
+
498
554
  // add GossipSub listener
499
555
  this.node.services.pubsub.addEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
500
556
 
501
557
  // Start running promise for peer discovery and metrics collection
558
+ if (!this.config.p2pDiscoveryDisabled) {
559
+ await this.peerDiscoveryService.start();
560
+ }
502
561
  this.discoveryRunningPromise = new RunningPromise(
503
562
  async () => {
504
563
  await this.peerManager.heartbeat();
@@ -508,14 +567,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
508
567
  );
509
568
  this.discoveryRunningPromise.start();
510
569
 
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
570
  this.logger.info(`Started P2P service`, {
520
571
  listen: this.config.listenAddress,
521
572
  port: this.config.p2pPort,
@@ -589,6 +640,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
589
640
  return this.reqresp.sendBatchRequest(protocol, requests, pinnedPeerId);
590
641
  }
591
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
+
592
652
  /**
593
653
  * Get the ENR of the node
594
654
  * @returns The ENR of the node
@@ -601,6 +661,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
601
661
  this.blockReceivedCallback = callback;
602
662
  }
603
663
 
664
+ public registerCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
665
+ this.checkpointReceivedCallback = callback;
666
+ }
667
+
604
668
  /**
605
669
  * Subscribes to a topic.
606
670
  * @param topic - The topic to subscribe to.
@@ -622,7 +686,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
622
686
  if (!this.node.services.pubsub) {
623
687
  throw new Error('Pubsub service not available.');
624
688
  }
625
- 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);
626
693
  const result = await this.node.services.pubsub.publish(topic, p2pMessage.toMessageData());
627
694
  return result.recipients.length;
628
695
  }
@@ -643,12 +710,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
643
710
  case this.topicStrings[TopicType.tx]:
644
711
  topicType = TopicType.tx;
645
712
  break;
646
- case this.topicStrings[TopicType.block_attestation]:
647
- topicType = TopicType.block_attestation;
648
- break;
649
713
  case this.topicStrings[TopicType.block_proposal]:
650
714
  topicType = TopicType.block_proposal;
651
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;
652
722
  default:
653
723
  this.logger.error(`Received message on unknown topic: ${msg.topic}`);
654
724
  break;
@@ -707,23 +777,74 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
707
777
  return;
708
778
  }
709
779
 
780
+ // Determine topic type for attributes
710
781
  if (msg.topic === this.topicStrings[TopicType.tx]) {
711
782
  topicType = TopicType.tx;
712
- 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;
713
789
  }
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);
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}`);
718
805
  }
719
- }
720
- if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
721
- topicType = TopicType.block_proposal;
722
- 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();
723
845
  }
724
846
 
725
- if (p2pMessage.timestamp !== undefined && topicType !== undefined) {
726
- const latency = msgReceivedTime - p2pMessage.timestamp.getTime();
847
+ if (latency !== undefined && topicType !== undefined) {
727
848
  this.instrumentation.recordMessageLatency(topicType, latency);
728
849
  }
729
850
 
@@ -800,27 +921,30 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
800
921
  }
801
922
 
802
923
  /**
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.
924
+ * Process a checkpoint attestation from a peer.
925
+ * Validates the attestation and adds it to the pool.
807
926
  */
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);
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);
811
934
  const pool = this.mempools.attestationPool;
812
- const isValid = await this.validateAttestation(source, attestation);
813
- const exists = isValid && (await pool.hasAttestation(attestation));
935
+ const validationResult = await this.validateCheckpointAttestation(source, attestation);
936
+ const isValid = validationResult.result === 'accept';
937
+ const exists = isValid && (await pool.hasCheckpointAttestation(attestation));
814
938
 
815
939
  let canAdd = true;
816
940
  if (isValid && !exists) {
817
941
  const slot = attestation.payload.header.slotNumber;
818
942
  const { committee } = await this.epochCache.getCommittee(slot);
819
943
  const committeeSize = committee?.length ?? 0;
820
- canAdd = await pool.canAddAttestation(attestation, committeeSize);
944
+ canAdd = await pool.canAddCheckpointAttestation(attestation, committeeSize);
821
945
  }
822
946
 
823
- this.logger.trace(`Validate propagated block attestation`, {
947
+ this.logger.trace(`Validate propagated checkpoint attestation`, {
824
948
  isValid,
825
949
  exists,
826
950
  canAdd,
@@ -828,12 +952,12 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
828
952
  [Attributes.P2P_ID]: source.toString(),
829
953
  });
830
954
 
831
- if (!isValid) {
955
+ if (validationResult.result === 'reject') {
832
956
  return { result: TopicValidatorResult.Reject };
833
- } else if (exists) {
957
+ } else if (validationResult.result === 'ignore' || exists) {
834
958
  return { result: TopicValidatorResult.Ignore, obj: attestation };
835
959
  } else if (!canAdd) {
836
- 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`, {
837
961
  slot: attestation.payload.header.slotNumber.toString(),
838
962
  archive: attestation.archive.toString(),
839
963
  source: source.toString(),
@@ -844,11 +968,11 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
844
968
  }
845
969
  };
846
970
 
847
- const { result, obj: attestation } = await this.validateReceivedMessage<BlockAttestation>(
971
+ const { result, obj: attestation } = await this.validateReceivedMessage<CheckpointAttestation>(
848
972
  validationFunc,
849
973
  msgId,
850
974
  source,
851
- TopicType.block_attestation,
975
+ TopicType.checkpoint_attestation,
852
976
  );
853
977
 
854
978
  if (result !== TopicValidatorResult.Accept || !attestation) {
@@ -856,7 +980,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
856
980
  }
857
981
 
858
982
  this.logger.debug(
859
- `Received attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`,
983
+ `Received checkpoint attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`,
860
984
  {
861
985
  p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
862
986
  slot: attestation.slotNumber,
@@ -865,13 +989,14 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
865
989
  },
866
990
  );
867
991
 
868
- await this.mempools.attestationPool.addAttestations([attestation]);
992
+ await this.mempools.attestationPool.addCheckpointAttestations([attestation]);
869
993
  }
870
994
 
871
995
  private async processBlockFromPeer(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
872
996
  const validationFunc: () => Promise<ReceivedMessageValidationResult<BlockProposal>> = async () => {
873
997
  const block = BlockProposal.fromBuffer(payloadData);
874
- const isValid = await this.validateBlockProposal(source, block);
998
+ const validationResult = await this.validateBlockProposal(source, block);
999
+ const isValid = validationResult.result === 'accept';
875
1000
  const pool = this.mempools.attestationPool;
876
1001
 
877
1002
  const exists = isValid && (await pool.hasBlockProposal(block));
@@ -881,13 +1006,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
881
1006
  isValid,
882
1007
  exists,
883
1008
  canAdd,
884
- [Attributes.SLOT_NUMBER]: block.payload.header.slotNumber.toString(),
1009
+ [Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
885
1010
  [Attributes.P2P_ID]: source.toString(),
886
1011
  });
887
1012
 
888
- if (!isValid) {
1013
+ if (validationResult.result === 'reject') {
889
1014
  return { result: TopicValidatorResult.Reject };
890
- } else if (exists) {
1015
+ } else if (validationResult.result === 'ignore' || exists) {
891
1016
  return { result: TopicValidatorResult.Ignore, obj: block };
892
1017
  } else if (!canAdd) {
893
1018
  this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
@@ -917,6 +1042,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
917
1042
  }
918
1043
 
919
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.
920
1047
  @trackSpan('Libp2pService.processValidBlockProposal', async block => ({
921
1048
  [Attributes.SLOT_NUMBER]: block.slotNumber,
922
1049
  [Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
@@ -924,17 +1051,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
924
1051
  }))
925
1052
  private async processValidBlockProposal(block: BlockProposal, sender: PeerId) {
926
1053
  const slot = block.slotNumber;
927
- const previousSlot = SlotNumber(slot - 1);
928
1054
  this.logger.verbose(`Received block proposal for slot ${slot} from external peer ${sender.toString()}.`, {
929
1055
  p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier(),
930
- slot: block.slotNumber,
931
- archive: block.archive.toString(),
932
1056
  source: sender.toString(),
1057
+ ...block.toBlockInfo(),
933
1058
  });
934
- const attestationsForPreviousSlot = await this.mempools.attestationPool.getAttestationsForSlot(previousSlot);
935
- this.logger.verbose(`Received ${attestationsForPreviousSlot.length} attestations for slot ${previousSlot}`);
936
1059
 
937
- // Attempt to add proposal, then mark the txs in this proposal as non-evictable
1060
+ // Attempt to add proposal
938
1061
  try {
939
1062
  await this.mempools.attestationPool.addBlockProposal(block);
940
1063
  } catch (err: unknown) {
@@ -949,34 +1072,126 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
949
1072
  }
950
1073
  throw err;
951
1074
  }
1075
+
1076
+ // Mark the txs in this proposal as non-evictable
952
1077
  await this.mempools.txPool.markTxsAsNonEvictable(block.txHashes);
953
- const attestations = await this.blockReceivedCallback(block, sender);
954
1078
 
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(),
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(),
963
1120
  });
964
- await this.broadcastAttestation(attestation);
1121
+ return { result: TopicValidatorResult.Reject };
1122
+ } else {
1123
+ return { result: TopicValidatorResult.Accept, obj: checkpoint };
965
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;
966
1136
  }
1137
+
1138
+ await this.processValidCheckpointProposal(checkpoint, source);
967
1139
  }
968
1140
 
969
1141
  /**
970
- * Broadcast an attestation to all peers.
971
- * @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.
972
1145
  */
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()),
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()),
977
1150
  }))
978
- private async broadcastAttestation(attestation: BlockAttestation) {
979
- 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
+ }
980
1195
  }
981
1196
 
982
1197
  /**
@@ -1101,7 +1316,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1101
1316
  const requested = new Set(requestedTxHash.map(h => h.toString()));
1102
1317
  const requestedTxValidator = this.createRequestedTxValidator();
1103
1318
 
1104
- //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.
1105
1320
  // I think we should still extract the valid txs and return them, so that we can still use the response.
1106
1321
  try {
1107
1322
  await Promise.all(responseTx.map(tx => this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
@@ -1164,27 +1379,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1164
1379
  }
1165
1380
  }
1166
1381
 
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
1382
  private async validateRequestedTx(tx: Tx, peerId: PeerId, txValidator: TxValidator, requested?: Set<`0x${string}`>) {
1181
1383
  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
1384
  if (requested && !requested.has(tx.getTxHash().toString())) {
1189
1385
  penalize(PeerErrorSeverity.MidToleranceError);
1190
1386
  throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
@@ -1197,6 +1393,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1197
1393
  }
1198
1394
  }
1199
1395
 
1396
+ private createRequestedTxValidator(): TxValidator {
1397
+ return createTxReqRespValidator(this.proofVerifier, {
1398
+ l1ChainId: this.config.l1ChainId,
1399
+ rollupVersion: this.config.rollupVersion,
1400
+ });
1401
+ }
1402
+
1200
1403
  @trackSpan('Libp2pService.validatePropagatedTx', tx => ({
1201
1404
  [Attributes.TX_HASH]: tx.getTxHash().toString(),
1202
1405
  }))
@@ -1239,6 +1442,22 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1239
1442
  return gasFees;
1240
1443
  }
1241
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
+
1242
1461
  public async validate(txs: Tx[]): Promise<void> {
1243
1462
  const currentBlockNumber = await this.archiver.getBlockNumber();
1244
1463
 
@@ -1289,6 +1508,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1289
1508
  this.proofVerifier,
1290
1509
  !this.config.disableTransactions,
1291
1510
  allowedInSetup,
1511
+ this.logger.getBindings(),
1292
1512
  );
1293
1513
  }
1294
1514
 
@@ -1342,15 +1562,18 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1342
1562
  return PeerErrorSeverity.HighToleranceError;
1343
1563
  }
1344
1564
 
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);
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
+ },
1352
1574
  },
1353
- });
1575
+ this.logger.getBindings(),
1576
+ );
1354
1577
 
1355
1578
  const validSnapshot = await snapshotValidator.validateTx(tx);
1356
1579
  if (validSnapshot.result !== 'valid') {
@@ -1361,24 +1584,28 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1361
1584
  }
1362
1585
 
1363
1586
  /**
1364
- * Validate an attestation.
1587
+ * Validate a checkpoint attestation.
1365
1588
  *
1366
- * @param attestation - The attestation to validate.
1367
- * @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.
1368
1591
  */
1369
- @trackSpan('Libp2pService.validateAttestation', async (_, attestation) => ({
1592
+ @trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation) => ({
1370
1593
  [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
1371
1594
  [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
1372
1595
  [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
1373
1596
  }))
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;
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);
1379
1606
  }
1380
1607
 
1381
- return true;
1608
+ return result;
1382
1609
  }
1383
1610
 
1384
1611
  /**
@@ -1388,17 +1615,40 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1388
1615
  * @returns True if the block proposal is valid, false otherwise.
1389
1616
  */
1390
1617
  @trackSpan('Libp2pService.validateBlockProposal', (_peerId, block) => ({
1391
- [Attributes.SLOT_NUMBER]: block.payload.header.slotNumber.toString(),
1618
+ [Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
1392
1619
  }))
1393
- public async validateBlockProposal(peerId: PeerId, block: BlockProposal): Promise<boolean> {
1394
- const severity = await this.blockProposalValidator.validate(block);
1395
- 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') {
1396
1624
  this.logger.debug(`Penalizing peer ${peerId} for block proposal validation failure`);
1397
- this.peerManager.penalizePeer(peerId, severity);
1398
- return false;
1625
+ this.peerManager.penalizePeer(peerId, result.severity);
1399
1626
  }
1400
1627
 
1401
- 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;
1402
1652
  }
1403
1653
 
1404
1654
  public getPeerScore(peerId: PeerId): number {