@aztec/p2p 0.0.1-commit.2ed92850 → 0.0.1-commit.43597cc1

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 (361) 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 +3 -3
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +11 -8
  7. package/dest/client/interface.d.ts +9 -2
  8. package/dest/client/interface.d.ts.map +1 -1
  9. package/dest/client/p2p_client.d.ts +7 -4
  10. package/dest/client/p2p_client.d.ts.map +1 -1
  11. package/dest/client/p2p_client.js +24 -7
  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 +16 -3
  19. package/dest/config.d.ts.map +1 -1
  20. package/dest/config.js +7 -2
  21. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +94 -87
  22. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  23. package/dest/mem_pools/attestation_pool/attestation_pool.js +411 -3
  24. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
  25. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  26. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +351 -85
  27. package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
  28. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  29. package/dest/mem_pools/attestation_pool/index.js +1 -2
  30. package/dest/mem_pools/index.d.ts +2 -2
  31. package/dest/mem_pools/index.d.ts.map +1 -1
  32. package/dest/mem_pools/index.js +1 -1
  33. package/dest/mem_pools/instrumentation.d.ts +1 -1
  34. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  35. package/dest/mem_pools/instrumentation.js +2 -2
  36. package/dest/mem_pools/interface.d.ts +3 -3
  37. package/dest/mem_pools/interface.d.ts.map +1 -1
  38. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
  39. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
  40. package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
  41. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +43 -0
  42. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
  43. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +103 -0
  44. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
  45. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
  46. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +119 -0
  47. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
  48. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  49. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +90 -0
  50. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
  51. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
  52. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +89 -0
  53. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +10 -0
  54. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
  55. package/dest/mem_pools/tx_pool_v2/eviction/index.js +11 -0
  56. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +131 -0
  57. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
  58. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +17 -0
  59. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
  60. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  61. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +63 -0
  62. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
  63. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  64. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +91 -0
  65. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
  66. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  67. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +70 -0
  68. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
  69. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
  70. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +63 -0
  71. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
  72. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
  73. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
  74. package/dest/mem_pools/tx_pool_v2/index.d.ts +5 -0
  75. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
  76. package/dest/mem_pools/tx_pool_v2/index.js +4 -0
  77. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +197 -0
  78. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
  79. package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -0
  80. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +71 -0
  81. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
  82. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +95 -0
  83. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
  84. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
  85. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
  86. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +99 -0
  87. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
  88. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +332 -0
  89. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +55 -0
  90. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
  91. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +156 -0
  92. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +69 -0
  93. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
  94. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +748 -0
  95. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
  96. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  97. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +7 -2
  98. package/dest/msg_validators/proposal_validator/proposal_validator.js +5 -5
  99. package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
  100. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
  101. package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
  102. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +5 -4
  103. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  104. package/dest/msg_validators/tx_validator/block_header_validator.js +4 -3
  105. package/dest/msg_validators/tx_validator/data_validator.d.ts +3 -1
  106. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  107. package/dest/msg_validators/tx_validator/data_validator.js +4 -1
  108. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +3 -2
  109. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  110. package/dest/msg_validators/tx_validator/double_spend_validator.js +3 -2
  111. package/dest/msg_validators/tx_validator/factory.d.ts +8 -3
  112. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  113. package/dest/msg_validators/tx_validator/factory.js +21 -11
  114. package/dest/msg_validators/tx_validator/gas_validator.d.ts +3 -2
  115. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  116. package/dest/msg_validators/tx_validator/gas_validator.js +3 -2
  117. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +3 -2
  118. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  119. package/dest/msg_validators/tx_validator/metadata_validator.js +2 -2
  120. package/dest/msg_validators/tx_validator/phases_validator.d.ts +3 -2
  121. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  122. package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
  123. package/dest/msg_validators/tx_validator/size_validator.d.ts +3 -1
  124. package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -1
  125. package/dest/msg_validators/tx_validator/size_validator.js +4 -1
  126. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +3 -2
  127. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  128. package/dest/msg_validators/tx_validator/timestamp_validator.js +2 -2
  129. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
  130. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
  131. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
  132. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +3 -2
  133. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  134. package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -2
  135. package/dest/services/data_store.d.ts +1 -1
  136. package/dest/services/data_store.d.ts.map +1 -1
  137. package/dest/services/data_store.js +10 -6
  138. package/dest/services/discv5/discV5_service.js +1 -1
  139. package/dest/services/dummy_service.d.ts +18 -2
  140. package/dest/services/dummy_service.d.ts.map +1 -1
  141. package/dest/services/dummy_service.js +42 -0
  142. package/dest/services/gossipsub/index.d.ts +3 -0
  143. package/dest/services/gossipsub/index.d.ts.map +1 -0
  144. package/dest/services/gossipsub/index.js +2 -0
  145. package/dest/services/gossipsub/scoring.d.ts +21 -3
  146. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  147. package/dest/services/gossipsub/scoring.js +24 -7
  148. package/dest/services/gossipsub/topic_score_params.d.ts +161 -0
  149. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  150. package/dest/services/gossipsub/topic_score_params.js +324 -0
  151. package/dest/services/index.d.ts +2 -1
  152. package/dest/services/index.d.ts.map +1 -1
  153. package/dest/services/index.js +1 -0
  154. package/dest/services/libp2p/instrumentation.d.ts +1 -1
  155. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  156. package/dest/services/libp2p/instrumentation.js +14 -3
  157. package/dest/services/libp2p/libp2p_service.d.ts +80 -33
  158. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  159. package/dest/services/libp2p/libp2p_service.js +352 -284
  160. package/dest/services/peer-manager/metrics.d.ts +2 -2
  161. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  162. package/dest/services/peer-manager/metrics.js +20 -5
  163. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  164. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  165. package/dest/services/peer-manager/peer_scoring.js +33 -4
  166. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +47 -0
  167. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
  168. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +566 -0
  169. package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
  170. package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
  171. package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
  172. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +50 -0
  173. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
  174. package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
  175. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +37 -0
  176. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
  177. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +151 -0
  178. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +54 -0
  179. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
  180. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +139 -0
  181. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +20 -0
  182. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
  183. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
  184. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +22 -3
  185. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  186. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +63 -4
  187. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -1
  188. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  189. package/dest/services/reqresp/connection-sampler/connection_sampler.js +12 -0
  190. package/dest/services/reqresp/interface.d.ts +3 -1
  191. package/dest/services/reqresp/interface.d.ts.map +1 -1
  192. package/dest/services/reqresp/metrics.d.ts +6 -5
  193. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  194. package/dest/services/reqresp/metrics.js +17 -5
  195. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +5 -1
  196. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  197. package/dest/services/reqresp/protocols/block_txs/bitvector.js +5 -0
  198. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +6 -4
  199. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  200. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +27 -9
  201. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +23 -6
  202. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  203. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +44 -13
  204. package/dest/services/reqresp/reqresp.d.ts +6 -1
  205. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  206. package/dest/services/reqresp/reqresp.js +58 -22
  207. package/dest/services/service.d.ts +21 -1
  208. package/dest/services/service.d.ts.map +1 -1
  209. package/dest/services/tx_collection/config.d.ts +4 -1
  210. package/dest/services/tx_collection/config.d.ts.map +1 -1
  211. package/dest/services/tx_collection/config.js +9 -1
  212. package/dest/services/tx_collection/fast_tx_collection.d.ts +5 -4
  213. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  214. package/dest/services/tx_collection/fast_tx_collection.js +17 -10
  215. package/dest/services/tx_collection/index.d.ts +2 -1
  216. package/dest/services/tx_collection/index.d.ts.map +1 -1
  217. package/dest/services/tx_collection/index.js +1 -0
  218. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  219. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  220. package/dest/services/tx_collection/instrumentation.js +9 -2
  221. package/dest/services/tx_collection/proposal_tx_collector.d.ts +48 -0
  222. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
  223. package/dest/services/tx_collection/proposal_tx_collector.js +49 -0
  224. package/dest/services/tx_collection/tx_collection.d.ts +4 -4
  225. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  226. package/dest/services/tx_collection/tx_collection.js +5 -5
  227. package/dest/services/tx_file_store/config.d.ts +18 -0
  228. package/dest/services/tx_file_store/config.d.ts.map +1 -0
  229. package/dest/services/tx_file_store/config.js +26 -0
  230. package/dest/services/tx_file_store/index.d.ts +4 -0
  231. package/dest/services/tx_file_store/index.d.ts.map +1 -0
  232. package/dest/services/tx_file_store/index.js +3 -0
  233. package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
  234. package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
  235. package/dest/services/tx_file_store/instrumentation.js +29 -0
  236. package/dest/services/tx_file_store/tx_file_store.d.ts +47 -0
  237. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
  238. package/dest/services/tx_file_store/tx_file_store.js +149 -0
  239. package/dest/services/tx_provider_instrumentation.d.ts +1 -1
  240. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  241. package/dest/services/tx_provider_instrumentation.js +5 -5
  242. package/dest/test-helpers/index.d.ts +3 -1
  243. package/dest/test-helpers/index.d.ts.map +1 -1
  244. package/dest/test-helpers/index.js +2 -0
  245. package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
  246. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  247. package/dest/test-helpers/reqresp-nodes.js +2 -1
  248. package/dest/test-helpers/test_tx_provider.d.ts +40 -0
  249. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
  250. package/dest/test-helpers/test_tx_provider.js +41 -0
  251. package/dest/test-helpers/testbench-utils.d.ts +152 -0
  252. package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
  253. package/dest/test-helpers/testbench-utils.js +308 -0
  254. package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
  255. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  256. package/dest/testbench/p2p_client_testbench_worker.js +212 -131
  257. package/dest/testbench/worker_client_manager.d.ts +51 -6
  258. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  259. package/dest/testbench/worker_client_manager.js +226 -44
  260. package/package.json +14 -14
  261. package/src/bootstrap/bootstrap.ts +7 -4
  262. package/src/client/factory.ts +13 -14
  263. package/src/client/interface.ts +13 -1
  264. package/src/client/p2p_client.ts +32 -8
  265. package/src/client/test/tx_proposal_collector/README.md +227 -0
  266. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +336 -0
  267. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
  268. package/src/config.ts +22 -2
  269. package/src/mem_pools/attestation_pool/attestation_pool.ts +444 -90
  270. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +436 -100
  271. package/src/mem_pools/attestation_pool/index.ts +9 -2
  272. package/src/mem_pools/index.ts +1 -1
  273. package/src/mem_pools/instrumentation.ts +2 -1
  274. package/src/mem_pools/interface.ts +2 -2
  275. package/src/mem_pools/tx_pool_v2/README.md +209 -0
  276. package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
  277. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -0
  278. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +147 -0
  279. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +118 -0
  280. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +111 -0
  281. package/src/mem_pools/tx_pool_v2/eviction/index.ts +23 -0
  282. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +164 -0
  283. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
  284. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
  285. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +86 -0
  286. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +72 -0
  287. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +31 -0
  288. package/src/mem_pools/tx_pool_v2/index.ts +11 -0
  289. package/src/mem_pools/tx_pool_v2/interfaces.ts +227 -0
  290. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +161 -0
  291. package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
  292. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +417 -0
  293. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +212 -0
  294. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +882 -0
  295. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +10 -4
  296. package/src/msg_validators/proposal_validator/proposal_validator.ts +5 -5
  297. package/src/msg_validators/tx_validator/archive_cache.ts +3 -3
  298. package/src/msg_validators/tx_validator/block_header_validator.ts +7 -8
  299. package/src/msg_validators/tx_validator/data_validator.ts +6 -2
  300. package/src/msg_validators/tx_validator/double_spend_validator.ts +4 -3
  301. package/src/msg_validators/tx_validator/factory.ts +64 -23
  302. package/src/msg_validators/tx_validator/gas_validator.ts +9 -3
  303. package/src/msg_validators/tx_validator/metadata_validator.ts +6 -3
  304. package/src/msg_validators/tx_validator/phases_validator.ts +5 -3
  305. package/src/msg_validators/tx_validator/size_validator.ts +6 -2
  306. package/src/msg_validators/tx_validator/timestamp_validator.ts +6 -3
  307. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
  308. package/src/msg_validators/tx_validator/tx_proof_validator.ts +8 -3
  309. package/src/services/data_store.ts +10 -7
  310. package/src/services/discv5/discV5_service.ts +1 -1
  311. package/src/services/dummy_service.ts +51 -0
  312. package/src/services/gossipsub/README.md +626 -0
  313. package/src/services/gossipsub/index.ts +2 -0
  314. package/src/services/gossipsub/scoring.ts +29 -5
  315. package/src/services/gossipsub/topic_score_params.ts +451 -0
  316. package/src/services/index.ts +1 -0
  317. package/src/services/libp2p/instrumentation.ts +15 -2
  318. package/src/services/libp2p/libp2p_service.ts +381 -305
  319. package/src/services/peer-manager/metrics.ts +21 -4
  320. package/src/services/peer-manager/peer_scoring.ts +29 -1
  321. package/src/services/reqresp/batch-tx-requester/README.md +305 -0
  322. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +706 -0
  323. package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
  324. package/src/services/reqresp/batch-tx-requester/interface.ts +57 -0
  325. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +209 -0
  326. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +205 -0
  327. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
  328. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +65 -4
  329. package/src/services/reqresp/connection-sampler/connection_sampler.ts +16 -0
  330. package/src/services/reqresp/interface.ts +3 -0
  331. package/src/services/reqresp/metrics.ts +34 -9
  332. package/src/services/reqresp/protocols/block_txs/bitvector.ts +7 -0
  333. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +34 -11
  334. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +57 -9
  335. package/src/services/reqresp/reqresp.ts +66 -19
  336. package/src/services/service.ts +24 -0
  337. package/src/services/tx_collection/config.ts +15 -1
  338. package/src/services/tx_collection/fast_tx_collection.ts +30 -17
  339. package/src/services/tx_collection/index.ts +5 -0
  340. package/src/services/tx_collection/instrumentation.ts +11 -2
  341. package/src/services/tx_collection/proposal_tx_collector.ts +112 -0
  342. package/src/services/tx_collection/tx_collection.ts +4 -4
  343. package/src/services/tx_file_store/config.ts +43 -0
  344. package/src/services/tx_file_store/index.ts +3 -0
  345. package/src/services/tx_file_store/instrumentation.ts +36 -0
  346. package/src/services/tx_file_store/tx_file_store.ts +173 -0
  347. package/src/services/tx_provider_instrumentation.ts +11 -5
  348. package/src/test-helpers/index.ts +2 -0
  349. package/src/test-helpers/reqresp-nodes.ts +2 -1
  350. package/src/test-helpers/test_tx_provider.ts +64 -0
  351. package/src/test-helpers/testbench-utils.ts +362 -0
  352. package/src/testbench/p2p_client_testbench_worker.ts +321 -122
  353. package/src/testbench/worker_client_manager.ts +304 -47
  354. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
  355. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  356. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
  357. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
  358. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  359. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
  360. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
  361. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
@@ -370,14 +370,12 @@ function applyDecs2203RFactory() {
370
370
  function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
371
371
  return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
372
372
  }
373
- var _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _initProto;
373
+ var _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _initProto;
374
374
  import { BlockNumber } from '@aztec/foundation/branded-types';
375
375
  import { randomInt } from '@aztec/foundation/crypto/random';
376
- import { Fr } from '@aztec/foundation/curves/bn254';
377
376
  import { createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
378
377
  import { RunningPromise } from '@aztec/foundation/running-promise';
379
378
  import { Timer } from '@aztec/foundation/timer';
380
- import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
381
379
  import { protocolContractsHash } from '@aztec/protocol-contracts';
382
380
  import { GasFees } from '@aztec/stdlib/gas';
383
381
  import { BlockProposal, CheckpointAttestation, CheckpointProposal, P2PClientType, P2PMessage, PeerErrorSeverity, TopicType, createTopicString, getTopicsForClientAndConfig, metricsTopicStrToLabels } from '@aztec/stdlib/p2p';
@@ -386,7 +384,7 @@ import { Tx } from '@aztec/stdlib/tx';
386
384
  import { compressComponentVersions } from '@aztec/stdlib/versioning';
387
385
  import { Attributes, OtelMetricsAdapter, SpanStatusCode, WithTracer, trackSpan } from '@aztec/telemetry-client';
388
386
  import { gossipsub } from '@chainsafe/libp2p-gossipsub';
389
- import { createPeerScoreParams, createTopicScoreParams } from '@chainsafe/libp2p-gossipsub/score';
387
+ import { createPeerScoreParams } from '@chainsafe/libp2p-gossipsub/score';
390
388
  import { SignaturePolicy } from '@chainsafe/libp2p-gossipsub/types';
391
389
  import { noise } from '@chainsafe/libp2p-noise';
392
390
  import { yamux } from '@chainsafe/libp2p-yamux';
@@ -397,51 +395,50 @@ import { mplex } from '@libp2p/mplex';
397
395
  import { tcp } from '@libp2p/tcp';
398
396
  import { ENR } from '@nethermindeth/enr';
399
397
  import { createLibp2p } from 'libp2p';
400
- import { ProposalSlotCapExceededError } from '../../errors/attestation-pool.error.js';
401
- import { BlockProposalValidator, CheckpointAttestationValidator, CheckpointProposalValidator, FishermanAttestationValidator, SizeTxValidator } from '../../msg_validators/index.js';
398
+ import { BlockProposalValidator, CheckpointAttestationValidator, CheckpointProposalValidator, DoubleSpendTxValidator, FishermanAttestationValidator, getDefaultAllowedSetupFunctions } from '../../msg_validators/index.js';
402
399
  import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
403
- import { getDefaultAllowedSetupFunctions } from '../../msg_validators/tx_validator/allowed_public_setup.js';
404
- import { createTxMessageValidators } from '../../msg_validators/tx_validator/factory.js';
405
- import { AggregateTxValidator, DataTxValidator, DoubleSpendTxValidator, MetadataTxValidator, TxProofValidator } from '../../msg_validators/tx_validator/index.js';
400
+ import { createTxMessageValidators, createTxReqRespValidator } from '../../msg_validators/tx_validator/factory.js';
406
401
  import { GossipSubEvent } from '../../types/index.js';
407
402
  import { convertToMultiaddr } from '../../util.js';
408
403
  import { getVersions } from '../../versioning.js';
409
404
  import { AztecDatastore } from '../data_store.js';
410
405
  import { DiscV5Service } from '../discv5/discV5_service.js';
411
406
  import { SnappyTransform, fastMsgIdFn, getMsgIdFn, msgIdToStrFn } from '../encoding.js';
412
- import { gossipScoreThresholds } from '../gossipsub/scoring.js';
407
+ import { APP_SPECIFIC_WEIGHT, gossipScoreThresholds } from '../gossipsub/scoring.js';
408
+ import { createAllTopicScoreParams } from '../gossipsub/topic_score_params.js';
413
409
  import { PeerManager } from '../peer-manager/peer_manager.js';
414
410
  import { PeerScoring } from '../peer-manager/peer_scoring.js';
415
- import { DEFAULT_SUB_PROTOCOL_VALIDATORS, ReqRespSubProtocol, ValidationError } from '../reqresp/interface.js';
416
- import { reqRespBlockTxsHandler } from '../reqresp/protocols/block_txs/block_txs_handler.js';
417
- import { reqGoodbyeHandler } from '../reqresp/protocols/goodbye.js';
418
- import { pingHandler, reqRespBlockHandler, reqRespStatusHandler, reqRespTxHandler } from '../reqresp/protocols/index.js';
411
+ import { DEFAULT_SUB_PROTOCOL_VALIDATORS, ReqRespSubProtocol, ValidationError } from '../reqresp/index.js';
412
+ import { pingHandler, reqGoodbyeHandler, reqRespBlockHandler, reqRespBlockTxsHandler, reqRespStatusHandler, reqRespTxHandler } from '../reqresp/index.js';
419
413
  import { ReqResp } from '../reqresp/reqresp.js';
420
414
  import { P2PInstrumentation } from './instrumentation.js';
421
- _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
415
+ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId, attestation)=>({
416
+ [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toString()
417
+ })), _dec1 = trackSpan('Libp2pService.validateAndStoreBlockProposal', (_peerId, block)=>({
418
+ [Attributes.BLOCK_NUMBER]: block.blockNumber.toString(),
419
+ [Attributes.SLOT_NUMBER]: block.slotNumber.toString()
420
+ })), _dec2 = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
422
421
  [Attributes.SLOT_NUMBER]: block.slotNumber,
423
422
  [Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
424
423
  [Attributes.P2P_ID]: await block.p2pMessageLoggingIdentifier().then((i)=>i.toString())
425
- })), _dec1 = trackSpan('Libp2pService.processValidCheckpointProposal', async (checkpoint)=>({
424
+ })), _dec3 = trackSpan('Libp2pService.validateAndStoreCheckpointProposal', (_peerId, checkpoint)=>({
425
+ [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString()
426
+ })), _dec4 = trackSpan('Libp2pService.processValidCheckpointProposal', async (checkpoint)=>({
426
427
  [Attributes.SLOT_NUMBER]: checkpoint.slotNumber,
427
428
  [Attributes.BLOCK_ARCHIVE]: checkpoint.archive.toString(),
428
429
  [Attributes.P2P_ID]: await checkpoint.p2pMessageLoggingIdentifier().then((i)=>i.toString())
429
- })), _dec2 = trackSpan('Libp2pService.validateRequestedBlockTxs', (request)=>({
430
- [Attributes.BLOCK_HASH]: request.blockHash.toString()
431
- })), _dec3 = trackSpan('Libp2pService.validateRequestedTx', (requestedTxHash, _responseTx)=>({
430
+ })), _dec5 = trackSpan('Libp2pService.validateRequestedBlockTxs', (request)=>({
431
+ [Attributes.BLOCK_ARCHIVE]: request.archiveRoot.toString()
432
+ })), _dec6 = trackSpan('Libp2pService.validateRequestedTx', (requestedTxHash, _responseTx)=>({
432
433
  [Attributes.TX_HASH]: requestedTxHash.toString()
433
- })), _dec4 = trackSpan('Libp2pService.validateRequestedBlock', (requestedBlockNumber, _responseBlock)=>({
434
+ })), _dec7 = trackSpan('Libp2pService.validateRequestedBlock', (requestedBlockNumber, _responseBlock)=>({
434
435
  [Attributes.BLOCK_NUMBER]: requestedBlockNumber.toString()
435
- })), _dec5 = trackSpan('Libp2pService.validatePropagatedTx', (tx)=>({
436
+ })), _dec8 = trackSpan('Libp2pService.validatePropagatedTx', (tx)=>({
436
437
  [Attributes.TX_HASH]: tx.getTxHash().toString()
437
- })), _dec6 = trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation)=>({
438
+ })), _dec9 = trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation)=>({
438
439
  [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
439
440
  [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
440
441
  [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then((i)=>i.toString())
441
- })), _dec7 = trackSpan('Libp2pService.validateBlockProposal', (_peerId, block)=>({
442
- [Attributes.SLOT_NUMBER]: block.slotNumber.toString()
443
- })), _dec8 = trackSpan('Libp2pService.validateCheckpointProposal', (_peerId, checkpoint)=>({
444
- [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString()
445
442
  }));
446
443
  /**
447
444
  * Lib P2P implementation of the P2PService interface.
@@ -462,47 +459,52 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
462
459
  [
463
460
  _dec,
464
461
  2,
465
- "processValidBlockProposal"
462
+ "validateAndStoreCheckpointAttestation"
466
463
  ],
467
464
  [
468
465
  _dec1,
469
466
  2,
470
- "processValidCheckpointProposal"
467
+ "validateAndStoreBlockProposal"
471
468
  ],
472
469
  [
473
470
  _dec2,
474
471
  2,
475
- "validateRequestedBlockTxs"
472
+ "processValidBlockProposal"
476
473
  ],
477
474
  [
478
475
  _dec3,
479
476
  2,
480
- "validateRequestedTxs"
477
+ "validateAndStoreCheckpointProposal"
481
478
  ],
482
479
  [
483
480
  _dec4,
484
481
  2,
485
- "validateRequestedBlock"
482
+ "processValidCheckpointProposal"
486
483
  ],
487
484
  [
488
485
  _dec5,
489
486
  2,
490
- "validatePropagatedTx"
487
+ "validateRequestedBlockTxs"
491
488
  ],
492
489
  [
493
490
  _dec6,
494
491
  2,
495
- "validateCheckpointAttestation"
492
+ "validateRequestedTxs"
496
493
  ],
497
494
  [
498
495
  _dec7,
499
496
  2,
500
- "validateBlockProposal"
497
+ "validateRequestedBlock"
501
498
  ],
502
499
  [
503
500
  _dec8,
504
501
  2,
505
- "validateCheckpointProposal"
502
+ "validatePropagatedTx"
503
+ ],
504
+ [
505
+ _dec9,
506
+ 2,
507
+ "validateCheckpointAttestation"
506
508
  ]
507
509
  ], []));
508
510
  }
@@ -515,6 +517,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
515
517
  protocolVersion;
516
518
  topicStrings;
517
519
  feesCache;
520
+ /** Callback invoked when a duplicate proposal is detected (triggers slashing). */ duplicateProposalCallback;
518
521
  /**
519
522
  * Callback for when a block is received from a peer.
520
523
  * @param block - The block received from the peer.
@@ -578,8 +581,8 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
578
581
  const { p2pPort, maxPeerCount, listenAddress } = config;
579
582
  const bindAddrTcp = convertToMultiaddr(listenAddress, p2pPort, 'tcp');
580
583
  const datastore = new AztecDatastore(peerStore);
581
- const otelMetricsAdapter = new OtelMetricsAdapter(telemetry);
582
- const peerDiscoveryService = new DiscV5Service(peerId, config, packageVersion, telemetry, createLogger(`${logger.module}:discv5_service`));
584
+ const otelMetricsAdapter = new OtelMetricsAdapter(telemetry, logger.getBindings());
585
+ const peerDiscoveryService = new DiscV5Service(peerId, config, packageVersion, telemetry, createLogger(`${logger.module}:discv5_service`, logger.getBindings()));
583
586
  // Seed libp2p's bootstrap discovery with private and trusted peers
584
587
  const bootstrapNodes = [
585
588
  ...config.privatePeers,
@@ -593,10 +596,6 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
593
596
  }
594
597
  const versions = getVersions(config);
595
598
  const protocolVersion = compressComponentVersions(versions);
596
- const txTopic = createTopicString(TopicType.tx, protocolVersion);
597
- const blockProposalTopic = createTopicString(TopicType.block_proposal, protocolVersion);
598
- const checkpointProposalTopic = createTopicString(TopicType.checkpoint_proposal, protocolVersion);
599
- const checkpointAttestationTopic = createTopicString(TopicType.checkpoint_attestation, protocolVersion);
600
599
  const preferredPeersEnrs = config.preferredPeers.map((enr)=>ENR.decodeTxt(enr));
601
600
  const directPeers = (await Promise.all(preferredPeersEnrs.map(async (enr)=>{
602
601
  const peerId = await enr.peerId();
@@ -614,6 +613,14 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
614
613
  const announceTcpMultiaddr = config.p2pIp ? [
615
614
  convertToMultiaddr(config.p2pIp, p2pPort, 'tcp')
616
615
  ] : [];
616
+ // Create dynamic topic score params based on network configuration
617
+ const l1Constants = epochCache.getL1Constants();
618
+ const topicScoreParams = createAllTopicScoreParams(protocolVersion, {
619
+ slotDurationMs: l1Constants.slotDuration * 1000,
620
+ heartbeatIntervalMs: config.gossipsubInterval,
621
+ targetCommitteeSize: l1Constants.targetCommitteeSize,
622
+ blockDurationMs: config.blockDurationMs
623
+ });
617
624
  const node = await createLibp2p({
618
625
  start: false,
619
626
  peerId,
@@ -714,41 +721,24 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
714
721
  scoreParams: createPeerScoreParams({
715
722
  // IPColocation factor can be disabled for local testing - default to -5
716
723
  IPColocationFactorWeight: config.debugDisableColocationPenalty ? 0 : -5.0,
717
- topics: {
718
- [txTopic]: createTopicScoreParams({
719
- topicWeight: 1,
720
- invalidMessageDeliveriesWeight: -20,
721
- invalidMessageDeliveriesDecay: 0.5
722
- }),
723
- [blockProposalTopic]: createTopicScoreParams({
724
- topicWeight: 1,
725
- invalidMessageDeliveriesWeight: -20,
726
- invalidMessageDeliveriesDecay: 0.5
727
- }),
728
- [checkpointProposalTopic]: createTopicScoreParams({
729
- topicWeight: 1,
730
- invalidMessageDeliveriesWeight: -20,
731
- invalidMessageDeliveriesDecay: 0.5
732
- }),
733
- [checkpointAttestationTopic]: createTopicScoreParams({
734
- topicWeight: 1,
735
- invalidMessageDeliveriesWeight: -20,
736
- invalidMessageDeliveriesDecay: 0.5
737
- })
738
- }
724
+ topics: topicScoreParams
739
725
  })
740
726
  }),
741
727
  components: (components)=>({
742
728
  connectionManager: components.connectionManager
743
729
  })
744
730
  },
745
- logger: createLibp2pComponentLogger(logger.module)
731
+ logger: createLibp2pComponentLogger(logger.module, logger.getBindings())
746
732
  });
747
733
  const peerScoring = new PeerScoring(config, telemetry);
748
734
  const reqresp = new ReqResp(config, node, peerScoring, createLogger(`${logger.module}:reqresp`));
749
735
  const peerManager = new PeerManager(node, peerDiscoveryService, config, telemetry, createLogger(`${logger.module}:peer_manager`), peerScoring, reqresp, worldStateSynchronizer, protocolVersion, epochCache);
750
- // Update gossipsub score params
751
- node.services.pubsub.score.params.appSpecificWeight = 10;
736
+ // Configure application-specific scoring for gossipsub.
737
+ // The weight scales app score to align with gossipsub thresholds:
738
+ // - Disconnect (-50) × 10 = -500 = gossipThreshold (stops receiving gossip)
739
+ // - Ban (-100) × 10 = -1000 = publishThreshold (cannot publish)
740
+ // Note: positive topic scores can offset penalties, so alignment is best-effort.
741
+ node.services.pubsub.score.params.appSpecificWeight = APP_SPECIFIC_WEIGHT;
752
742
  node.services.pubsub.score.params.appSpecificScore = (peerId)=>peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
753
743
  return new LibP2PService(clientType, config, node, peerDiscoveryService, reqresp, peerManager, mempools, l2BlockSource, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger);
754
744
  }
@@ -778,7 +768,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
778
768
  [ReqRespSubProtocol.BLOCK]: blockHandler.bind(this)
779
769
  };
780
770
  if (!this.config.disableTransactions) {
781
- const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.mempools.txPool);
771
+ const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.archiver, this.mempools.txPool);
782
772
  requestResponseHandlers[ReqRespSubProtocol.BLOCK_TXS] = blockTxsHandler.bind(this);
783
773
  }
784
774
  if (!this.config.disableTransactions) {
@@ -862,6 +852,9 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
862
852
  */ sendBatchRequest(protocol, requests, pinnedPeerId) {
863
853
  return this.reqresp.sendBatchRequest(protocol, requests, pinnedPeerId);
864
854
  }
855
+ sendRequestToPeer(peerId, subProtocol, payload, dialTimeout) {
856
+ return this.reqresp.sendRequestToPeer(peerId, subProtocol, payload, dialTimeout);
857
+ }
865
858
  /**
866
859
  * Get the ENR of the node
867
860
  * @returns The ENR of the node
@@ -875,6 +868,12 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
875
868
  this.checkpointReceivedCallback = callback;
876
869
  }
877
870
  /**
871
+ * Registers a callback to be invoked when a duplicate proposal is detected.
872
+ * This callback is triggered on the first duplicate (when count goes from 1 to 2).
873
+ */ registerDuplicateProposalCallback(callback) {
874
+ this.duplicateProposalCallback = callback;
875
+ }
876
+ /**
878
877
  * Subscribes to a topic.
879
878
  * @param topic - The topic to subscribe to.
880
879
  */ subscribeToTopic(topic) {
@@ -1101,114 +1100,159 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1101
1100
  * Process a checkpoint attestation from a peer.
1102
1101
  * Validates the attestation and adds it to the pool.
1103
1102
  */ async processCheckpointAttestationFromPeer(payloadData, msgId, source) {
1104
- const validationFunc = async ()=>{
1105
- const attestation = CheckpointAttestation.fromBuffer(payloadData);
1106
- const pool = this.mempools.attestationPool;
1107
- const validationResult = await this.validateCheckpointAttestation(source, attestation);
1108
- const isValid = validationResult.result === 'accept';
1109
- const exists = isValid && await pool.hasCheckpointAttestation(attestation);
1110
- let canAdd = true;
1111
- if (isValid && !exists) {
1112
- const slot = attestation.payload.header.slotNumber;
1113
- const { committee } = await this.epochCache.getCommittee(slot);
1114
- const committeeSize = committee?.length ?? 0;
1115
- canAdd = await pool.canAddCheckpointAttestation(attestation, committeeSize);
1116
- }
1117
- this.logger.trace(`Validate propagated checkpoint attestation`, {
1118
- isValid,
1119
- exists,
1120
- canAdd,
1121
- [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toString(),
1122
- [Attributes.P2P_ID]: source.toString()
1123
- });
1124
- if (validationResult.result === 'reject') {
1125
- return {
1126
- result: TopicValidatorResult.Reject
1127
- };
1128
- } else if (validationResult.result === 'ignore' || exists) {
1129
- return {
1130
- result: TopicValidatorResult.Ignore,
1131
- obj: attestation
1132
- };
1133
- } else if (!canAdd) {
1134
- this.logger.warn(`Dropping checkpoint attestation due to per-(slot, proposalId) attestation cap`, {
1135
- slot: attestation.payload.header.slotNumber.toString(),
1136
- archive: attestation.archive.toString(),
1137
- source: source.toString()
1138
- });
1139
- return {
1140
- result: TopicValidatorResult.Ignore,
1141
- obj: attestation
1142
- };
1143
- } else {
1144
- return {
1145
- result: TopicValidatorResult.Accept,
1146
- obj: attestation
1147
- };
1148
- }
1149
- };
1150
- const { result, obj: attestation } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.checkpoint_attestation);
1103
+ const { result, obj: attestation } = await this.validateReceivedMessage(()=>this.validateAndStoreCheckpointAttestation(source, CheckpointAttestation.fromBuffer(payloadData)), msgId, source, TopicType.checkpoint_attestation);
1151
1104
  if (result !== TopicValidatorResult.Accept || !attestation) {
1152
1105
  return;
1153
1106
  }
1154
- this.logger.debug(`Received checkpoint attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`, {
1107
+ this.logger.verbose(`Received valid checkpoint attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`, {
1155
1108
  p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
1156
1109
  slot: attestation.slotNumber,
1157
1110
  archive: attestation.archive.toString(),
1158
1111
  source: source.toString()
1159
1112
  });
1160
- await this.mempools.attestationPool.addCheckpointAttestations([
1161
- attestation
1162
- ]);
1163
1113
  }
1164
- async processBlockFromPeer(payloadData, msgId, source) {
1165
- const validationFunc = async ()=>{
1166
- const block = BlockProposal.fromBuffer(payloadData);
1167
- const validationResult = await this.validateBlockProposal(source, block);
1168
- const isValid = validationResult.result === 'accept';
1169
- const pool = this.mempools.attestationPool;
1170
- const exists = isValid && await pool.hasBlockProposal(block);
1171
- const canAdd = isValid && await pool.canAddProposal(block);
1172
- this.logger.trace(`Validate propagated block proposal`, {
1173
- isValid,
1174
- exists,
1175
- canAdd,
1176
- [Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
1177
- [Attributes.P2P_ID]: source.toString()
1114
+ /** Validates a checkpoint attestation and adds it to the pool. Penalizes the peer if validation fails. */ async validateAndStoreCheckpointAttestation(peerId, attestation) {
1115
+ const validationResult = await this.checkpointAttestationValidator.validate(attestation);
1116
+ if (validationResult.result === 'reject') {
1117
+ this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
1118
+ this.peerManager.penalizePeer(peerId, validationResult.severity);
1119
+ return {
1120
+ result: TopicValidatorResult.Reject
1121
+ };
1122
+ }
1123
+ if (validationResult.result === 'ignore') {
1124
+ return {
1125
+ result: TopicValidatorResult.Ignore,
1126
+ obj: attestation
1127
+ };
1128
+ }
1129
+ // Get committee size for the attestation's slot
1130
+ const slot = attestation.payload.header.slotNumber;
1131
+ const { committee } = await this.epochCache.getCommittee(slot);
1132
+ const committeeSize = committee?.length ?? 0;
1133
+ // Try to add the attestation: this handles existence check, cap check, and adding in one call
1134
+ const { added, alreadyExists } = await this.mempools.attestationPool.tryAddCheckpointAttestation(attestation, committeeSize);
1135
+ this.logger.trace(`Validate propagated checkpoint attestation`, {
1136
+ added,
1137
+ alreadyExists,
1138
+ [Attributes.SLOT_NUMBER]: slot.toString(),
1139
+ [Attributes.P2P_ID]: peerId.toString()
1140
+ });
1141
+ // Duplicate attestation received, no need to re-broadcast
1142
+ if (alreadyExists) {
1143
+ return {
1144
+ result: TopicValidatorResult.Ignore,
1145
+ obj: attestation
1146
+ };
1147
+ }
1148
+ // Could not add (cap reached), no need to re-broadcast
1149
+ if (!added) {
1150
+ this.logger.warn(`Dropping checkpoint attestation due to per-(slot, proposalId) attestation cap`, {
1151
+ slot: slot.toString(),
1152
+ archive: attestation.archive.toString(),
1153
+ source: peerId.toString()
1178
1154
  });
1179
- if (validationResult.result === 'reject') {
1180
- return {
1181
- result: TopicValidatorResult.Reject
1182
- };
1183
- } else if (validationResult.result === 'ignore' || exists) {
1184
- return {
1185
- result: TopicValidatorResult.Ignore,
1186
- obj: block
1187
- };
1188
- } else if (!canAdd) {
1189
- this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
1190
- this.logger.warn(`Penalizing peer for block proposal exceeding per-slot cap`, {
1191
- slot: block.slotNumber.toString(),
1192
- archive: block.archive.toString(),
1193
- source: source.toString()
1194
- });
1195
- return {
1196
- result: TopicValidatorResult.Reject
1197
- };
1198
- } else {
1199
- return {
1200
- result: TopicValidatorResult.Accept,
1201
- obj: block
1202
- };
1203
- }
1155
+ return {
1156
+ result: TopicValidatorResult.Ignore,
1157
+ obj: attestation
1158
+ };
1159
+ }
1160
+ // Attestation was added successfully
1161
+ return {
1162
+ result: TopicValidatorResult.Accept,
1163
+ obj: attestation
1204
1164
  };
1205
- const { result, obj: block } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.block_proposal);
1206
- if (!result || !block) {
1165
+ }
1166
+ async processBlockFromPeer(payloadData, msgId, source) {
1167
+ const { result, obj: block, metadata: { isEquivocated } = {} } = await this.validateReceivedMessage(()=>this.validateAndStoreBlockProposal(source, BlockProposal.fromBuffer(payloadData)), msgId, source, TopicType.block_proposal);
1168
+ // If not accepted or equivocated, return
1169
+ if (result !== TopicValidatorResult.Accept || !block || isEquivocated) {
1207
1170
  return;
1208
1171
  }
1209
1172
  await this.processValidBlockProposal(block, source);
1210
1173
  }
1211
- // REVIEW: callback pattern https://github.com/AztecProtocol/aztec-packages/issues/7963
1174
+ /** Validates a block proposal. Triggers a penalization to the peer that sent it if invalid. Adds to the mempool if valid. */ async validateAndStoreBlockProposal(peerId, block) {
1175
+ const validationResult = await this.blockProposalValidator.validate(block);
1176
+ if (validationResult.result === 'reject') {
1177
+ this.logger.warn(`Penalizing peer ${peerId} for block proposal validation failure`);
1178
+ this.peerManager.penalizePeer(peerId, validationResult.severity);
1179
+ return {
1180
+ result: TopicValidatorResult.Reject
1181
+ };
1182
+ }
1183
+ if (validationResult.result === 'ignore') {
1184
+ return {
1185
+ result: TopicValidatorResult.Ignore,
1186
+ obj: block
1187
+ };
1188
+ }
1189
+ // Try to add the proposal: this handles existence check, cap check, and adding in one call
1190
+ const { added, alreadyExists, totalForPosition } = await this.mempools.attestationPool.tryAddBlockProposal(block);
1191
+ const isEquivocated = totalForPosition !== undefined && totalForPosition > 1;
1192
+ // Duplicate proposal received, no need to re-broadcast
1193
+ if (alreadyExists) {
1194
+ this.logger.debug(`Ignoring duplicate block proposal received`, {
1195
+ ...block.toBlockInfo(),
1196
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
1197
+ proposer: block.getSender()?.toString(),
1198
+ source: peerId.toString()
1199
+ });
1200
+ return {
1201
+ result: TopicValidatorResult.Ignore,
1202
+ obj: block,
1203
+ metadata: {
1204
+ isEquivocated
1205
+ }
1206
+ };
1207
+ }
1208
+ // Too many blocks received for this slot and index, penalize peer and do not re-broadcast
1209
+ if (!added) {
1210
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
1211
+ this.logger.warn(`Penalizing peer for block proposal exceeding per-position cap`, {
1212
+ ...block.toBlockInfo(),
1213
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
1214
+ totalForPosition,
1215
+ proposer: block.getSender()?.toString(),
1216
+ source: peerId.toString()
1217
+ });
1218
+ return {
1219
+ result: TopicValidatorResult.Reject,
1220
+ metadata: {
1221
+ isEquivocated
1222
+ }
1223
+ };
1224
+ }
1225
+ // If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
1226
+ // and do re-broadcast it so other nodes in the network know to slash the proposer
1227
+ if (isEquivocated) {
1228
+ const proposer = block.getSender();
1229
+ this.logger.warn(`Detected duplicate block proposal (equivocation) at slot ${block.slotNumber}`, {
1230
+ ...block.toBlockInfo(),
1231
+ source: peerId.toString(),
1232
+ proposer: proposer?.toString()
1233
+ });
1234
+ // Invoke the duplicate callback on the first duplicate spotted only
1235
+ if (proposer && totalForPosition === 2) {
1236
+ this.duplicateProposalCallback?.({
1237
+ slot: block.slotNumber,
1238
+ proposer,
1239
+ type: 'block'
1240
+ });
1241
+ }
1242
+ return {
1243
+ result: TopicValidatorResult.Accept,
1244
+ obj: block,
1245
+ metadata: {
1246
+ isEquivocated
1247
+ }
1248
+ };
1249
+ }
1250
+ // Otherwise, we're good to go!
1251
+ return {
1252
+ result: TopicValidatorResult.Accept,
1253
+ obj: block
1254
+ };
1255
+ }
1212
1256
  // REFACTOR(palla): This method should be moved to the p2p_client or to a separate component,
1213
1257
  // should not be here as it does not deal with p2p networking.
1214
1258
  async processValidBlockProposal(block, sender) {
@@ -1218,21 +1262,6 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1218
1262
  source: sender.toString(),
1219
1263
  ...block.toBlockInfo()
1220
1264
  });
1221
- // Attempt to add proposal
1222
- try {
1223
- await this.mempools.attestationPool.addBlockProposal(block);
1224
- } catch (err) {
1225
- // Drop proposals if we hit per-slot cap in the attestation pool; rethrow unknown errors
1226
- if (err instanceof ProposalSlotCapExceededError) {
1227
- this.logger.warn(`Dropping block proposal due to per-slot proposal cap`, {
1228
- slot: String(slot),
1229
- archive: block.archive.toString(),
1230
- error: err.message
1231
- });
1232
- return;
1233
- }
1234
- throw err;
1235
- }
1236
1265
  // Mark the txs in this proposal as non-evictable
1237
1266
  await this.mempools.txPool.markTxsAsNonEvictable(block.txHashes);
1238
1267
  // Call the block received callback to validate the proposal.
@@ -1246,57 +1275,135 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1246
1275
  * Handle a gossiped checkpoint proposal.
1247
1276
  * Validates and processes the checkpoint proposal, then triggers the callback for attestation.
1248
1277
  */ async handleGossipedCheckpointProposal(payloadData, msgId, source) {
1249
- // TODO(palla/mbps): This pattern is repeated across multiple message handlers, consider abstracting it.
1250
- const validationFunc = async ()=>{
1251
- const checkpoint = CheckpointProposal.fromBuffer(payloadData);
1252
- const validationResult = await this.validateCheckpointProposal(source, checkpoint);
1253
- const isValid = validationResult.result === 'accept';
1254
- const pool = this.mempools.attestationPool;
1255
- const exists = isValid && await pool.hasCheckpointProposal(checkpoint);
1256
- const canAdd = isValid && await pool.canAddCheckpointProposal(checkpoint);
1257
- this.logger.trace(`Validate propagated checkpoint proposal`, {
1258
- isValid,
1259
- exists,
1260
- canAdd,
1278
+ const { result, obj: checkpoint, metadata: { isEquivocated, processBlock } = {} } = await this.validateReceivedMessage(()=>this.validateAndStoreCheckpointProposal(source, CheckpointProposal.fromBuffer(payloadData)), msgId, source, TopicType.checkpoint_proposal);
1279
+ // If the checkpoint contained a valid last block, we process it even if the checkpoint itself is to be rejected
1280
+ // TODO(palla/mbps): Is this ok? Should we be considering a block from a checkpoint that was equivocated?
1281
+ if (processBlock && checkpoint?.getBlockProposal()) {
1282
+ await this.processValidBlockProposal(checkpoint.getBlockProposal(), source);
1283
+ }
1284
+ if (result !== TopicValidatorResult.Accept || !checkpoint || isEquivocated) {
1285
+ return;
1286
+ }
1287
+ await this.processValidCheckpointProposal(checkpoint.toCore(), source);
1288
+ }
1289
+ /**
1290
+ * Validates a checkpoint proposal. Penalizes peer if validation fails. Adds the checkpoint and
1291
+ * its last block (if present) to the mempool if valid. Triggers equivocation detection on both.
1292
+ */ async validateAndStoreCheckpointProposal(peerId, checkpoint) {
1293
+ const validationResult = await this.checkpointProposalValidator.validate(checkpoint);
1294
+ if (validationResult.result === 'reject') {
1295
+ this.logger.warn(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
1296
+ this.peerManager.penalizePeer(peerId, validationResult.severity);
1297
+ return {
1298
+ result: TopicValidatorResult.Reject
1299
+ };
1300
+ }
1301
+ if (validationResult.result === 'ignore') {
1302
+ return {
1303
+ result: TopicValidatorResult.Ignore,
1304
+ obj: checkpoint
1305
+ };
1306
+ }
1307
+ // Extract and try to add the block proposal first if present
1308
+ const blockProposal = checkpoint.getBlockProposal();
1309
+ let processBlock = false;
1310
+ if (blockProposal) {
1311
+ this.logger.debug(`Validating block proposal from propagated checkpoint`, {
1261
1312
  [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
1262
- [Attributes.P2P_ID]: source.toString()
1313
+ [Attributes.P2P_ID]: peerId.toString()
1263
1314
  });
1264
- if (validationResult.result === 'reject') {
1265
- return {
1266
- result: TopicValidatorResult.Reject
1267
- };
1268
- } else if (validationResult.result === 'ignore' || exists) {
1269
- return {
1270
- result: TopicValidatorResult.Ignore,
1271
- obj: checkpoint
1272
- };
1273
- } else if (!canAdd) {
1274
- this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
1275
- this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
1276
- slot: checkpoint.slotNumber.toString(),
1277
- archive: checkpoint.archive.toString(),
1278
- source: source.toString()
1315
+ const { result, obj, metadata: { isEquivocated } = {} } = await this.validateAndStoreBlockProposal(peerId, blockProposal);
1316
+ if (result === TopicValidatorResult.Reject || !obj || isEquivocated) {
1317
+ this.logger.debug(`Rejecting checkpoint due to invalid last block proposal`, {
1318
+ [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
1319
+ [Attributes.P2P_ID]: peerId.toString(),
1320
+ isEquivocated,
1321
+ result
1279
1322
  });
1280
1323
  return {
1281
1324
  result: TopicValidatorResult.Reject
1282
1325
  };
1283
- } else {
1284
- return {
1285
- result: TopicValidatorResult.Accept,
1286
- obj: checkpoint
1287
- };
1326
+ } else if (result === TopicValidatorResult.Accept && obj && !isEquivocated) {
1327
+ processBlock = true;
1288
1328
  }
1289
- };
1290
- const { result, obj: checkpoint } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.checkpoint_proposal);
1291
- if (result !== TopicValidatorResult.Accept || !checkpoint) {
1292
- return;
1293
1329
  }
1294
- await this.processValidCheckpointProposal(checkpoint, source);
1330
+ // Try to add the checkpoint proposal core: this handles existence check, cap check, and adding in one call
1331
+ const checkpointCore = checkpoint.toCore();
1332
+ const tryAddResult = await this.mempools.attestationPool.tryAddCheckpointProposal(checkpointCore);
1333
+ const { added, alreadyExists, totalForPosition } = tryAddResult;
1334
+ const isEquivocated = totalForPosition !== undefined && totalForPosition > 1;
1335
+ // Duplicate proposal received, do not re-broadcast
1336
+ if (alreadyExists) {
1337
+ this.logger.debug(`Ignoring duplicate checkpoint proposal received`, {
1338
+ ...checkpoint.toCheckpointInfo(),
1339
+ source: peerId.toString()
1340
+ });
1341
+ return {
1342
+ result: TopicValidatorResult.Ignore,
1343
+ obj: checkpoint,
1344
+ metadata: {
1345
+ isEquivocated,
1346
+ processBlock
1347
+ }
1348
+ };
1349
+ }
1350
+ // Too many checkpoint proposals received for this slot, penalize peer and do not re-broadcast
1351
+ // Note: We still return the checkpoint obj so the lastBlock can be processed if valid
1352
+ if (!added) {
1353
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
1354
+ this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
1355
+ ...checkpoint.toCheckpointInfo(),
1356
+ totalForPosition,
1357
+ source: peerId.toString()
1358
+ });
1359
+ return {
1360
+ result: TopicValidatorResult.Reject,
1361
+ obj: checkpoint,
1362
+ metadata: {
1363
+ isEquivocated,
1364
+ processBlock
1365
+ }
1366
+ };
1367
+ }
1368
+ // If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
1369
+ // and do re-broadcast it so other nodes in the network know to slash the proposer
1370
+ if (isEquivocated) {
1371
+ const proposer = checkpoint.getSender();
1372
+ this.logger.warn(`Detected duplicate checkpoint proposal (equivocation) at slot ${checkpoint.slotNumber}`, {
1373
+ ...checkpoint.toCheckpointInfo(),
1374
+ source: peerId.toString(),
1375
+ proposer: proposer?.toString()
1376
+ });
1377
+ // Invoke the duplicate callback on the first duplicate spotted only
1378
+ if (proposer && totalForPosition === 2) {
1379
+ this.duplicateProposalCallback?.({
1380
+ slot: checkpoint.slotNumber,
1381
+ proposer,
1382
+ type: 'checkpoint'
1383
+ });
1384
+ }
1385
+ return {
1386
+ result: TopicValidatorResult.Accept,
1387
+ obj: checkpoint,
1388
+ metadata: {
1389
+ isEquivocated,
1390
+ processBlock
1391
+ }
1392
+ };
1393
+ }
1394
+ // Otherwise, we're good to go!
1395
+ return {
1396
+ result: TopicValidatorResult.Accept,
1397
+ obj: checkpoint,
1398
+ metadata: {
1399
+ processBlock,
1400
+ isEquivocated
1401
+ }
1402
+ };
1295
1403
  }
1296
1404
  /**
1297
1405
  * Process a validated checkpoint proposal.
1298
- * Extracts and processes the last block proposal (if present) first, then processes the checkpoint.
1299
- * The block callback is invoked before the checkpoint callback.
1406
+ * Note: The proposal was already added to the pool by tryAddCheckpointProposal in handleGossipedCheckpointProposal.
1300
1407
  */ async processValidCheckpointProposal(checkpoint, sender) {
1301
1408
  const slot = checkpoint.slotNumber;
1302
1409
  this.logger.verbose(`Received checkpoint proposal for slot ${slot} from external peer ${sender.toString()}.`, {
@@ -1305,33 +1412,12 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1305
1412
  archive: checkpoint.archive.toString(),
1306
1413
  source: sender.toString()
1307
1414
  });
1308
- // Extract block proposal before adding to pool (pool stores them separately)
1309
- const blockProposal = checkpoint.getBlockProposal();
1310
- // Add proposal to the pool (this extracts and stores block proposal separately)
1311
- await this.mempools.attestationPool.addCheckpointProposal(checkpoint);
1312
- // Mark txs as non-evictable if present (from the last block)
1313
- if (checkpoint.txHashes.length > 0) {
1314
- await this.mempools.txPool.markTxsAsNonEvictable(checkpoint.txHashes);
1315
- }
1316
- // If there was a last block proposal, invoke the block callback first for validation.
1317
- // Note: The block proposal is already stored in the pool by addCheckpointProposal.
1318
- if (blockProposal) {
1319
- const isValid = await this.blockReceivedCallback(blockProposal, sender);
1320
- if (!isValid) {
1321
- this.logger.warn(`Block proposal from checkpoint failed validation`, {
1322
- slot: slot.toString(),
1323
- archive: checkpoint.archive.toString(),
1324
- blockNumber: blockProposal.blockNumber.toString()
1325
- });
1326
- return;
1327
- }
1328
- }
1329
1415
  // Call the checkpoint received callback with the core version (without lastBlock)
1330
1416
  // to validate and potentially generate attestations
1331
- const attestations = await this.checkpointReceivedCallback(checkpoint.toCore(), sender);
1417
+ const attestations = await this.checkpointReceivedCallback(checkpoint, sender);
1332
1418
  if (attestations && attestations.length > 0) {
1333
1419
  // If the callback returned attestations, add them to the pool and propagate them
1334
- await this.mempools.attestationPool.addCheckpointAttestations(attestations);
1420
+ await this.mempools.attestationPool.addOwnCheckpointAttestations(attestations);
1335
1421
  for (const attestation of attestations){
1336
1422
  await this.propagate(attestation);
1337
1423
  }
@@ -1360,9 +1446,9 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1360
1446
  */ async validateRequestedBlockTxs(request, response, peerId) {
1361
1447
  const requestedTxValidator = this.createRequestedTxValidator();
1362
1448
  try {
1363
- if (!response.blockHash.equals(request.blockHash)) {
1449
+ if (!response.archiveRoot.equals(request.archiveRoot)) {
1364
1450
  this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1365
- throw new ValidationError(`Received block txs for unexpected block: expected ${request.blockHash.toString()}, got ${response.blockHash.toString()}`);
1451
+ throw new ValidationError(`Received block txs for unexpected archive root: expected ${request.archiveRoot.toString()}, got ${response.archiveRoot.toString()}`);
1366
1452
  }
1367
1453
  if (response.txIndices.getLength() !== request.txIndices.getLength()) {
1368
1454
  this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
@@ -1385,7 +1471,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1385
1471
  throw new ValidationError(`Received more txs (${response.txs.length}) than requested-and-available (${maxReturnable})`);
1386
1472
  }
1387
1473
  // Given proposal (should have locally), ensure returned txs are valid subset and match request indices
1388
- const proposal = await this.mempools.attestationPool.getBlockProposal(request.blockHash.toString());
1474
+ const proposal = await this.mempools.attestationPool.getBlockProposal(request.archiveRoot.toString());
1389
1475
  if (proposal) {
1390
1476
  // Build intersected indices
1391
1477
  const intersectIdx = request.txIndices.getTrueIndices().filter((i)=>response.txIndices.isSet(i));
@@ -1404,7 +1490,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1404
1490
  }
1405
1491
  } else {
1406
1492
  // No local proposal, cannot check the membership/order of the returned txs
1407
- this.logger.warn(`Block proposal not found for block hash ${request.blockHash.toString()}; cannot validate membership/order of returned txs`);
1493
+ this.logger.warn(`Block proposal not found for archive root ${request.archiveRoot.toString()}; cannot validate membership/order of returned txs`);
1408
1494
  return false;
1409
1495
  }
1410
1496
  await Promise.all(response.txs.map((tx)=>this.validateRequestedTx(tx, peerId, requestedTxValidator)));
@@ -1434,7 +1520,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1434
1520
  */ async validateRequestedTxs(requestedTxHash, responseTx, peerId) {
1435
1521
  const requested = new Set(requestedTxHash.map((h)=>h.toString()));
1436
1522
  const requestedTxValidator = this.createRequestedTxValidator();
1437
- //TODO: (mralj) - this is somewhat naive implementation, if single tx is invlid we consider the whole response invalid.
1523
+ //TODO: (mralj) - this is somewhat naive implementation, if single tx is invalid we consider the whole response invalid.
1438
1524
  // I think we should still extract the valid txs and return them, so that we can still use the response.
1439
1525
  try {
1440
1526
  await Promise.all(responseTx.map((tx)=>this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
@@ -1487,20 +1573,8 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1487
1573
  return false;
1488
1574
  }
1489
1575
  }
1490
- createRequestedTxValidator() {
1491
- return new AggregateTxValidator(new DataTxValidator(), new SizeTxValidator(), new MetadataTxValidator({
1492
- l1ChainId: new Fr(this.config.l1ChainId),
1493
- rollupVersion: new Fr(this.config.rollupVersion),
1494
- protocolContractsHash,
1495
- vkTreeRoot: getVKTreeRoot()
1496
- }), new TxProofValidator(this.proofVerifier));
1497
- }
1498
1576
  async validateRequestedTx(tx, peerId, txValidator, requested) {
1499
1577
  const penalize = (severity)=>this.peerManager.penalizePeer(peerId, severity);
1500
- if (!await tx.validateTxHash()) {
1501
- penalize(PeerErrorSeverity.MidToleranceError);
1502
- throw new ValidationError(`Received tx with invalid hash ${tx.getTxHash().toString()}.`);
1503
- }
1504
1578
  if (requested && !requested.has(tx.getTxHash().toString())) {
1505
1579
  penalize(PeerErrorSeverity.MidToleranceError);
1506
1580
  throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
@@ -1511,6 +1585,12 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1511
1585
  throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that is invalid.`);
1512
1586
  }
1513
1587
  }
1588
+ createRequestedTxValidator() {
1589
+ return createTxReqRespValidator(this.proofVerifier, {
1590
+ l1ChainId: this.config.l1ChainId,
1591
+ rollupVersion: this.config.rollupVersion
1592
+ });
1593
+ }
1514
1594
  async validatePropagatedTx(tx, peerId) {
1515
1595
  const currentBlockNumber = await this.archiver.getBlockNumber();
1516
1596
  // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
@@ -1545,6 +1625,20 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1545
1625
  };
1546
1626
  return gasFees;
1547
1627
  }
1628
+ /**
1629
+ * Get the BatchTxRequesterLibP2PService dependencies for creating BatchTxRequester instances
1630
+ */ getBatchTxRequesterService() {
1631
+ return {
1632
+ reqResp: this.reqresp,
1633
+ connectionSampler: this.reqresp.getConnectionSampler(),
1634
+ txValidatorConfig: {
1635
+ l1ChainId: this.config.l1ChainId,
1636
+ rollupVersion: this.config.rollupVersion,
1637
+ proofVerifier: this.proofVerifier
1638
+ },
1639
+ peerScoring: this.peerManager
1640
+ };
1641
+ }
1548
1642
  async validate(txs) {
1549
1643
  const currentBlockNumber = await this.archiver.getBlockNumber();
1550
1644
  // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
@@ -1576,7 +1670,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1576
1670
  const gasFees = await this.getGasFees(currentBlockNumber);
1577
1671
  const allowedInSetup = this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
1578
1672
  const blockNumberInWhichTheTxIsConsideredToBeIncluded = BlockNumber(currentBlockNumber + 1);
1579
- return createTxMessageValidators(nextSlotTimestamp, blockNumberInWhichTheTxIsConsideredToBeIncluded, this.worldStateSynchronizer, gasFees, this.config.l1ChainId, this.config.rollupVersion, protocolContractsHash, this.archiver, this.proofVerifier, !this.config.disableTransactions, allowedInSetup);
1673
+ return createTxMessageValidators(nextSlotTimestamp, blockNumberInWhichTheTxIsConsideredToBeIncluded, this.worldStateSynchronizer, gasFees, this.config.l1ChainId, this.config.rollupVersion, protocolContractsHash, this.archiver, this.proofVerifier, !this.config.disableTransactions, allowedInSetup, this.logger.getBindings());
1580
1674
  }
1581
1675
  /**
1582
1676
  * Run validations on a tx.
@@ -1635,7 +1729,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1635
1729
  const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
1636
1730
  return indices.map((index)=>index !== undefined);
1637
1731
  }
1638
- });
1732
+ }, this.logger.getBindings());
1639
1733
  const validSnapshot = await snapshotValidator.validateTx(tx);
1640
1734
  if (validSnapshot.result !== 'valid') {
1641
1735
  return PeerErrorSeverity.LowToleranceError;
@@ -1650,33 +1744,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1650
1744
  */ async validateCheckpointAttestation(peerId, attestation) {
1651
1745
  const result = await this.checkpointAttestationValidator.validate(attestation);
1652
1746
  if (result.result === 'reject') {
1653
- this.logger.debug(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
1654
- this.peerManager.penalizePeer(peerId, result.severity);
1655
- }
1656
- return result;
1657
- }
1658
- /**
1659
- * Validate a block proposal.
1660
- *
1661
- * @param block - The block proposal to validate.
1662
- * @returns True if the block proposal is valid, false otherwise.
1663
- */ async validateBlockProposal(peerId, block) {
1664
- const result = await this.blockProposalValidator.validate(block);
1665
- if (result.result === 'reject') {
1666
- this.logger.debug(`Penalizing peer ${peerId} for block proposal validation failure`);
1667
- this.peerManager.penalizePeer(peerId, result.severity);
1668
- }
1669
- return result;
1670
- }
1671
- /**
1672
- * Validate a checkpoint proposal.
1673
- *
1674
- * @param checkpoint - The checkpoint proposal to validate.
1675
- * @returns True if the checkpoint proposal is valid, false otherwise.
1676
- */ async validateCheckpointProposal(peerId, checkpoint) {
1677
- const result = await this.checkpointProposalValidator.validate(checkpoint);
1678
- if (result.result === 'reject') {
1679
- this.logger.debug(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
1747
+ this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
1680
1748
  this.peerManager.penalizePeer(peerId, result.severity);
1681
1749
  }
1682
1750
  return result;