@aztec/p2p 0.0.1-commit.f295ac2 → 0.0.1-commit.f2ce05ee

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 (407) 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/aztec_kv_tx_pool.d.ts +3 -3
  39. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  40. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +3 -2
  41. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +3 -2
  43. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -1
  44. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +3 -3
  45. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  46. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +8 -1
  47. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +3 -3
  48. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +2 -0
  50. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
  51. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
  52. package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
  53. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +43 -0
  54. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
  55. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +103 -0
  56. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
  57. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
  58. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +119 -0
  59. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
  60. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  61. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +90 -0
  62. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
  63. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
  64. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +89 -0
  65. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +10 -0
  66. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
  67. package/dest/mem_pools/tx_pool_v2/eviction/index.js +11 -0
  68. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +131 -0
  69. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
  70. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +17 -0
  71. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
  72. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  73. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +63 -0
  74. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
  75. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  76. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +91 -0
  77. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
  78. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  79. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +70 -0
  80. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
  81. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
  82. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +63 -0
  83. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
  84. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
  85. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
  86. package/dest/mem_pools/tx_pool_v2/index.d.ts +5 -0
  87. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
  88. package/dest/mem_pools/tx_pool_v2/index.js +4 -0
  89. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +197 -0
  90. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
  91. package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -0
  92. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +71 -0
  93. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
  94. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +95 -0
  95. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
  96. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
  97. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
  98. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +99 -0
  99. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
  100. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +332 -0
  101. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +55 -0
  102. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
  103. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +156 -0
  104. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +69 -0
  105. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
  106. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +748 -0
  107. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +3 -3
  108. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  109. package/dest/msg_validators/attestation_validator/attestation_validator.js +41 -10
  110. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -5
  111. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  112. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +18 -6
  113. package/dest/msg_validators/clock_tolerance.d.ts +21 -0
  114. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
  115. package/dest/msg_validators/clock_tolerance.js +37 -0
  116. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +3 -3
  117. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  118. package/dest/msg_validators/proposal_validator/proposal_validator.js +55 -31
  119. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +3 -3
  120. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -1
  121. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +93 -64
  122. package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
  123. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
  124. package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
  125. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +5 -4
  126. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  127. package/dest/msg_validators/tx_validator/block_header_validator.js +3 -2
  128. package/dest/msg_validators/tx_validator/data_validator.d.ts +3 -1
  129. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  130. package/dest/msg_validators/tx_validator/data_validator.js +4 -1
  131. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +3 -2
  132. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  133. package/dest/msg_validators/tx_validator/double_spend_validator.js +3 -2
  134. package/dest/msg_validators/tx_validator/factory.d.ts +8 -3
  135. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  136. package/dest/msg_validators/tx_validator/factory.js +21 -11
  137. package/dest/msg_validators/tx_validator/gas_validator.d.ts +3 -2
  138. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  139. package/dest/msg_validators/tx_validator/gas_validator.js +3 -2
  140. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  141. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  142. package/dest/msg_validators/tx_validator/index.js +1 -0
  143. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +3 -2
  144. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  145. package/dest/msg_validators/tx_validator/metadata_validator.js +2 -2
  146. package/dest/msg_validators/tx_validator/phases_validator.d.ts +3 -2
  147. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  148. package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
  149. package/dest/msg_validators/tx_validator/size_validator.d.ts +8 -0
  150. package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
  151. package/dest/msg_validators/tx_validator/size_validator.js +23 -0
  152. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +3 -2
  153. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  154. package/dest/msg_validators/tx_validator/timestamp_validator.js +2 -2
  155. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
  156. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
  157. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
  158. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +3 -2
  159. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  160. package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -2
  161. package/dest/services/data_store.d.ts +1 -1
  162. package/dest/services/data_store.d.ts.map +1 -1
  163. package/dest/services/data_store.js +10 -6
  164. package/dest/services/discv5/discV5_service.js +1 -1
  165. package/dest/services/dummy_service.d.ts +18 -2
  166. package/dest/services/dummy_service.d.ts.map +1 -1
  167. package/dest/services/dummy_service.js +42 -0
  168. package/dest/services/encoding.d.ts +1 -1
  169. package/dest/services/encoding.d.ts.map +1 -1
  170. package/dest/services/encoding.js +2 -3
  171. package/dest/services/gossipsub/index.d.ts +3 -0
  172. package/dest/services/gossipsub/index.d.ts.map +1 -0
  173. package/dest/services/gossipsub/index.js +2 -0
  174. package/dest/services/gossipsub/scoring.d.ts +21 -3
  175. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  176. package/dest/services/gossipsub/scoring.js +24 -7
  177. package/dest/services/gossipsub/topic_score_params.d.ts +161 -0
  178. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  179. package/dest/services/gossipsub/topic_score_params.js +324 -0
  180. package/dest/services/index.d.ts +2 -1
  181. package/dest/services/index.d.ts.map +1 -1
  182. package/dest/services/index.js +1 -0
  183. package/dest/services/libp2p/instrumentation.d.ts +1 -1
  184. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  185. package/dest/services/libp2p/instrumentation.js +14 -3
  186. package/dest/services/libp2p/libp2p_service.d.ts +81 -34
  187. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  188. package/dest/services/libp2p/libp2p_service.js +356 -288
  189. package/dest/services/peer-manager/metrics.d.ts +2 -2
  190. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  191. package/dest/services/peer-manager/metrics.js +20 -5
  192. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  193. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  194. package/dest/services/peer-manager/peer_scoring.js +33 -4
  195. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +47 -0
  196. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
  197. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +566 -0
  198. package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
  199. package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
  200. package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
  201. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +50 -0
  202. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
  203. package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
  204. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +37 -0
  205. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
  206. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +151 -0
  207. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +54 -0
  208. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
  209. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +139 -0
  210. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +20 -0
  211. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
  212. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
  213. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +22 -3
  214. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  215. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +63 -4
  216. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -1
  217. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  218. package/dest/services/reqresp/connection-sampler/connection_sampler.js +12 -0
  219. package/dest/services/reqresp/interface.d.ts +5 -3
  220. package/dest/services/reqresp/interface.d.ts.map +1 -1
  221. package/dest/services/reqresp/interface.js +2 -2
  222. package/dest/services/reqresp/metrics.d.ts +6 -5
  223. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  224. package/dest/services/reqresp/metrics.js +17 -5
  225. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +5 -1
  226. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  227. package/dest/services/reqresp/protocols/block_txs/bitvector.js +5 -0
  228. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +6 -4
  229. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  230. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +27 -9
  231. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +23 -6
  232. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  233. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +44 -13
  234. package/dest/services/reqresp/reqresp.d.ts +6 -1
  235. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  236. package/dest/services/reqresp/reqresp.js +58 -22
  237. package/dest/services/service.d.ts +21 -1
  238. package/dest/services/service.d.ts.map +1 -1
  239. package/dest/services/tx_collection/config.d.ts +4 -1
  240. package/dest/services/tx_collection/config.d.ts.map +1 -1
  241. package/dest/services/tx_collection/config.js +9 -1
  242. package/dest/services/tx_collection/fast_tx_collection.d.ts +5 -4
  243. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  244. package/dest/services/tx_collection/fast_tx_collection.js +17 -10
  245. package/dest/services/tx_collection/index.d.ts +2 -1
  246. package/dest/services/tx_collection/index.d.ts.map +1 -1
  247. package/dest/services/tx_collection/index.js +1 -0
  248. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  249. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  250. package/dest/services/tx_collection/instrumentation.js +9 -2
  251. package/dest/services/tx_collection/proposal_tx_collector.d.ts +48 -0
  252. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
  253. package/dest/services/tx_collection/proposal_tx_collector.js +49 -0
  254. package/dest/services/tx_collection/slow_tx_collection.d.ts +3 -3
  255. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  256. package/dest/services/tx_collection/tx_collection.d.ts +8 -8
  257. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  258. package/dest/services/tx_collection/tx_collection.js +5 -5
  259. package/dest/services/tx_file_store/config.d.ts +18 -0
  260. package/dest/services/tx_file_store/config.d.ts.map +1 -0
  261. package/dest/services/tx_file_store/config.js +26 -0
  262. package/dest/services/tx_file_store/index.d.ts +4 -0
  263. package/dest/services/tx_file_store/index.d.ts.map +1 -0
  264. package/dest/services/tx_file_store/index.js +3 -0
  265. package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
  266. package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
  267. package/dest/services/tx_file_store/instrumentation.js +29 -0
  268. package/dest/services/tx_file_store/tx_file_store.d.ts +47 -0
  269. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
  270. package/dest/services/tx_file_store/tx_file_store.js +149 -0
  271. package/dest/services/tx_provider.d.ts +3 -3
  272. package/dest/services/tx_provider.d.ts.map +1 -1
  273. package/dest/services/tx_provider_instrumentation.d.ts +1 -1
  274. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  275. package/dest/services/tx_provider_instrumentation.js +5 -5
  276. package/dest/test-helpers/index.d.ts +3 -1
  277. package/dest/test-helpers/index.d.ts.map +1 -1
  278. package/dest/test-helpers/index.js +2 -0
  279. package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
  280. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  281. package/dest/test-helpers/reqresp-nodes.js +2 -1
  282. package/dest/test-helpers/test_tx_provider.d.ts +40 -0
  283. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
  284. package/dest/test-helpers/test_tx_provider.js +41 -0
  285. package/dest/test-helpers/testbench-utils.d.ts +152 -0
  286. package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
  287. package/dest/test-helpers/testbench-utils.js +308 -0
  288. package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
  289. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  290. package/dest/testbench/p2p_client_testbench_worker.js +212 -133
  291. package/dest/testbench/worker_client_manager.d.ts +51 -6
  292. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  293. package/dest/testbench/worker_client_manager.js +226 -44
  294. package/package.json +14 -14
  295. package/src/bootstrap/bootstrap.ts +7 -4
  296. package/src/client/factory.ts +13 -14
  297. package/src/client/interface.ts +13 -1
  298. package/src/client/p2p_client.ts +37 -13
  299. package/src/client/test/tx_proposal_collector/README.md +227 -0
  300. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +336 -0
  301. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
  302. package/src/config.ts +22 -2
  303. package/src/mem_pools/attestation_pool/attestation_pool.ts +444 -90
  304. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +436 -100
  305. package/src/mem_pools/attestation_pool/index.ts +9 -2
  306. package/src/mem_pools/index.ts +1 -1
  307. package/src/mem_pools/instrumentation.ts +2 -1
  308. package/src/mem_pools/interface.ts +2 -2
  309. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +2 -2
  310. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +2 -1
  311. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +2 -1
  312. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +10 -7
  313. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +4 -2
  314. package/src/mem_pools/tx_pool_v2/README.md +209 -0
  315. package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
  316. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -0
  317. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +147 -0
  318. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +118 -0
  319. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +111 -0
  320. package/src/mem_pools/tx_pool_v2/eviction/index.ts +23 -0
  321. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +164 -0
  322. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
  323. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
  324. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +86 -0
  325. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +72 -0
  326. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +31 -0
  327. package/src/mem_pools/tx_pool_v2/index.ts +11 -0
  328. package/src/mem_pools/tx_pool_v2/interfaces.ts +227 -0
  329. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +161 -0
  330. package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
  331. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +417 -0
  332. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +212 -0
  333. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +882 -0
  334. package/src/msg_validators/attestation_validator/attestation_validator.ts +26 -14
  335. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +16 -10
  336. package/src/msg_validators/clock_tolerance.ts +51 -0
  337. package/src/msg_validators/proposal_validator/proposal_validator.ts +31 -31
  338. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +91 -67
  339. package/src/msg_validators/tx_validator/archive_cache.ts +3 -3
  340. package/src/msg_validators/tx_validator/block_header_validator.ts +6 -5
  341. package/src/msg_validators/tx_validator/data_validator.ts +6 -2
  342. package/src/msg_validators/tx_validator/double_spend_validator.ts +4 -3
  343. package/src/msg_validators/tx_validator/factory.ts +64 -23
  344. package/src/msg_validators/tx_validator/gas_validator.ts +9 -3
  345. package/src/msg_validators/tx_validator/index.ts +1 -0
  346. package/src/msg_validators/tx_validator/metadata_validator.ts +6 -3
  347. package/src/msg_validators/tx_validator/phases_validator.ts +5 -3
  348. package/src/msg_validators/tx_validator/size_validator.ts +22 -0
  349. package/src/msg_validators/tx_validator/timestamp_validator.ts +6 -3
  350. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
  351. package/src/msg_validators/tx_validator/tx_proof_validator.ts +8 -3
  352. package/src/services/data_store.ts +10 -7
  353. package/src/services/discv5/discV5_service.ts +1 -1
  354. package/src/services/dummy_service.ts +51 -0
  355. package/src/services/encoding.ts +2 -3
  356. package/src/services/gossipsub/README.md +626 -0
  357. package/src/services/gossipsub/index.ts +2 -0
  358. package/src/services/gossipsub/scoring.ts +29 -5
  359. package/src/services/gossipsub/topic_score_params.ts +451 -0
  360. package/src/services/index.ts +1 -0
  361. package/src/services/libp2p/instrumentation.ts +15 -2
  362. package/src/services/libp2p/libp2p_service.ts +390 -302
  363. package/src/services/peer-manager/metrics.ts +21 -4
  364. package/src/services/peer-manager/peer_scoring.ts +29 -1
  365. package/src/services/reqresp/batch-tx-requester/README.md +305 -0
  366. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +706 -0
  367. package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
  368. package/src/services/reqresp/batch-tx-requester/interface.ts +57 -0
  369. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +209 -0
  370. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +205 -0
  371. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
  372. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +65 -4
  373. package/src/services/reqresp/connection-sampler/connection_sampler.ts +16 -0
  374. package/src/services/reqresp/interface.ts +5 -2
  375. package/src/services/reqresp/metrics.ts +34 -9
  376. package/src/services/reqresp/protocols/block_txs/bitvector.ts +7 -0
  377. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +34 -11
  378. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +57 -9
  379. package/src/services/reqresp/reqresp.ts +66 -19
  380. package/src/services/service.ts +24 -0
  381. package/src/services/tx_collection/config.ts +15 -1
  382. package/src/services/tx_collection/fast_tx_collection.ts +30 -17
  383. package/src/services/tx_collection/index.ts +5 -0
  384. package/src/services/tx_collection/instrumentation.ts +11 -2
  385. package/src/services/tx_collection/proposal_tx_collector.ts +112 -0
  386. package/src/services/tx_collection/slow_tx_collection.ts +2 -2
  387. package/src/services/tx_collection/tx_collection.ts +8 -8
  388. package/src/services/tx_file_store/config.ts +43 -0
  389. package/src/services/tx_file_store/index.ts +3 -0
  390. package/src/services/tx_file_store/instrumentation.ts +36 -0
  391. package/src/services/tx_file_store/tx_file_store.ts +173 -0
  392. package/src/services/tx_provider.ts +2 -2
  393. package/src/services/tx_provider_instrumentation.ts +11 -5
  394. package/src/test-helpers/index.ts +2 -0
  395. package/src/test-helpers/reqresp-nodes.ts +2 -1
  396. package/src/test-helpers/test_tx_provider.ts +64 -0
  397. package/src/test-helpers/testbench-utils.ts +362 -0
  398. package/src/testbench/p2p_client_testbench_worker.ts +321 -126
  399. package/src/testbench/worker_client_manager.ts +304 -47
  400. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
  401. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  402. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
  403. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
  404. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  405. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
  406. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
  407. 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 } 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,112 +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 isValid = await this.validateCheckpointAttestation(source, attestation);
1108
- const exists = isValid && await pool.hasCheckpointAttestation(attestation);
1109
- let canAdd = true;
1110
- if (isValid && !exists) {
1111
- const slot = attestation.payload.header.slotNumber;
1112
- const { committee } = await this.epochCache.getCommittee(slot);
1113
- const committeeSize = committee?.length ?? 0;
1114
- canAdd = await pool.canAddCheckpointAttestation(attestation, committeeSize);
1115
- }
1116
- this.logger.trace(`Validate propagated checkpoint attestation`, {
1117
- isValid,
1118
- exists,
1119
- canAdd,
1120
- [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toString(),
1121
- [Attributes.P2P_ID]: source.toString()
1122
- });
1123
- if (!isValid) {
1124
- return {
1125
- result: TopicValidatorResult.Reject
1126
- };
1127
- } else if (exists) {
1128
- return {
1129
- result: TopicValidatorResult.Ignore,
1130
- obj: attestation
1131
- };
1132
- } else if (!canAdd) {
1133
- this.logger.warn(`Dropping checkpoint attestation due to per-(slot, proposalId) attestation cap`, {
1134
- slot: attestation.payload.header.slotNumber.toString(),
1135
- archive: attestation.archive.toString(),
1136
- source: source.toString()
1137
- });
1138
- return {
1139
- result: TopicValidatorResult.Ignore,
1140
- obj: attestation
1141
- };
1142
- } else {
1143
- return {
1144
- result: TopicValidatorResult.Accept,
1145
- obj: attestation
1146
- };
1147
- }
1148
- };
1149
- 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);
1150
1104
  if (result !== TopicValidatorResult.Accept || !attestation) {
1151
1105
  return;
1152
1106
  }
1153
- 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()}`, {
1154
1108
  p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
1155
1109
  slot: attestation.slotNumber,
1156
1110
  archive: attestation.archive.toString(),
1157
1111
  source: source.toString()
1158
1112
  });
1159
- await this.mempools.attestationPool.addCheckpointAttestations([
1160
- attestation
1161
- ]);
1162
1113
  }
1163
- async processBlockFromPeer(payloadData, msgId, source) {
1164
- const validationFunc = async ()=>{
1165
- const block = BlockProposal.fromBuffer(payloadData);
1166
- const isValid = await this.validateBlockProposal(source, block);
1167
- const pool = this.mempools.attestationPool;
1168
- const exists = isValid && await pool.hasBlockProposal(block);
1169
- const canAdd = isValid && await pool.canAddProposal(block);
1170
- this.logger.trace(`Validate propagated block proposal`, {
1171
- isValid,
1172
- exists,
1173
- canAdd,
1174
- [Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
1175
- [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()
1176
1154
  });
1177
- if (!isValid) {
1178
- return {
1179
- result: TopicValidatorResult.Reject
1180
- };
1181
- } else if (exists) {
1182
- return {
1183
- result: TopicValidatorResult.Ignore,
1184
- obj: block
1185
- };
1186
- } else if (!canAdd) {
1187
- this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
1188
- this.logger.warn(`Penalizing peer for block proposal exceeding per-slot cap`, {
1189
- slot: block.slotNumber.toString(),
1190
- archive: block.archive.toString(),
1191
- source: source.toString()
1192
- });
1193
- return {
1194
- result: TopicValidatorResult.Reject
1195
- };
1196
- } else {
1197
- return {
1198
- result: TopicValidatorResult.Accept,
1199
- obj: block
1200
- };
1201
- }
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
1202
1164
  };
1203
- const { result, obj: block } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.block_proposal);
1204
- 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) {
1205
1170
  return;
1206
1171
  }
1207
1172
  await this.processValidBlockProposal(block, source);
1208
1173
  }
1209
- // 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
+ }
1210
1256
  // REFACTOR(palla): This method should be moved to the p2p_client or to a separate component,
1211
1257
  // should not be here as it does not deal with p2p networking.
1212
1258
  async processValidBlockProposal(block, sender) {
@@ -1216,21 +1262,6 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1216
1262
  source: sender.toString(),
1217
1263
  ...block.toBlockInfo()
1218
1264
  });
1219
- // Attempt to add proposal
1220
- try {
1221
- await this.mempools.attestationPool.addBlockProposal(block);
1222
- } catch (err) {
1223
- // Drop proposals if we hit per-slot cap in the attestation pool; rethrow unknown errors
1224
- if (err instanceof ProposalSlotCapExceededError) {
1225
- this.logger.warn(`Dropping block proposal due to per-slot proposal cap`, {
1226
- slot: String(slot),
1227
- archive: block.archive.toString(),
1228
- error: err.message
1229
- });
1230
- return;
1231
- }
1232
- throw err;
1233
- }
1234
1265
  // Mark the txs in this proposal as non-evictable
1235
1266
  await this.mempools.txPool.markTxsAsNonEvictable(block.txHashes);
1236
1267
  // Call the block received callback to validate the proposal.
@@ -1244,56 +1275,135 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1244
1275
  * Handle a gossiped checkpoint proposal.
1245
1276
  * Validates and processes the checkpoint proposal, then triggers the callback for attestation.
1246
1277
  */ async handleGossipedCheckpointProposal(payloadData, msgId, source) {
1247
- // TODO(palla/mbps): This pattern is repeated across multiple message handlers, consider abstracting it.
1248
- const validationFunc = async ()=>{
1249
- const checkpoint = CheckpointProposal.fromBuffer(payloadData);
1250
- const isValid = await this.validateCheckpointProposal(source, checkpoint);
1251
- const pool = this.mempools.attestationPool;
1252
- const exists = isValid && await pool.hasCheckpointProposal(checkpoint);
1253
- const canAdd = isValid && await pool.canAddCheckpointProposal(checkpoint);
1254
- this.logger.trace(`Validate propagated checkpoint proposal`, {
1255
- isValid,
1256
- exists,
1257
- 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`, {
1258
1312
  [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
1259
- [Attributes.P2P_ID]: source.toString()
1313
+ [Attributes.P2P_ID]: peerId.toString()
1260
1314
  });
1261
- if (!isValid) {
1262
- return {
1263
- result: TopicValidatorResult.Reject
1264
- };
1265
- } else if (exists) {
1266
- return {
1267
- result: TopicValidatorResult.Ignore,
1268
- obj: checkpoint
1269
- };
1270
- } else if (!canAdd) {
1271
- this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
1272
- this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
1273
- slot: checkpoint.slotNumber.toString(),
1274
- archive: checkpoint.archive.toString(),
1275
- 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
1276
1322
  });
1277
1323
  return {
1278
1324
  result: TopicValidatorResult.Reject
1279
1325
  };
1280
- } else {
1281
- return {
1282
- result: TopicValidatorResult.Accept,
1283
- obj: checkpoint
1284
- };
1326
+ } else if (result === TopicValidatorResult.Accept && obj && !isEquivocated) {
1327
+ processBlock = true;
1285
1328
  }
1286
- };
1287
- const { result, obj: checkpoint } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.checkpoint_proposal);
1288
- if (result !== TopicValidatorResult.Accept || !checkpoint) {
1289
- return;
1290
1329
  }
1291
- 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
+ };
1292
1403
  }
1293
1404
  /**
1294
1405
  * Process a validated checkpoint proposal.
1295
- * Extracts and processes the last block proposal (if present) first, then processes the checkpoint.
1296
- * The block callback is invoked before the checkpoint callback.
1406
+ * Note: The proposal was already added to the pool by tryAddCheckpointProposal in handleGossipedCheckpointProposal.
1297
1407
  */ async processValidCheckpointProposal(checkpoint, sender) {
1298
1408
  const slot = checkpoint.slotNumber;
1299
1409
  this.logger.verbose(`Received checkpoint proposal for slot ${slot} from external peer ${sender.toString()}.`, {
@@ -1302,33 +1412,12 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1302
1412
  archive: checkpoint.archive.toString(),
1303
1413
  source: sender.toString()
1304
1414
  });
1305
- // Extract block proposal before adding to pool (pool stores them separately)
1306
- const blockProposal = checkpoint.getBlockProposal();
1307
- // Add proposal to the pool (this extracts and stores block proposal separately)
1308
- await this.mempools.attestationPool.addCheckpointProposal(checkpoint);
1309
- // Mark txs as non-evictable if present (from the last block)
1310
- if (checkpoint.txHashes.length > 0) {
1311
- await this.mempools.txPool.markTxsAsNonEvictable(checkpoint.txHashes);
1312
- }
1313
- // If there was a last block proposal, invoke the block callback first for validation.
1314
- // Note: The block proposal is already stored in the pool by addCheckpointProposal.
1315
- if (blockProposal) {
1316
- const isValid = await this.blockReceivedCallback(blockProposal, sender);
1317
- if (!isValid) {
1318
- this.logger.warn(`Block proposal from checkpoint failed validation`, {
1319
- slot: slot.toString(),
1320
- archive: checkpoint.archive.toString(),
1321
- blockNumber: blockProposal.blockNumber.toString()
1322
- });
1323
- return;
1324
- }
1325
- }
1326
1415
  // Call the checkpoint received callback with the core version (without lastBlock)
1327
1416
  // to validate and potentially generate attestations
1328
- const attestations = await this.checkpointReceivedCallback(checkpoint.toCore(), sender);
1417
+ const attestations = await this.checkpointReceivedCallback(checkpoint, sender);
1329
1418
  if (attestations && attestations.length > 0) {
1330
1419
  // If the callback returned attestations, add them to the pool and propagate them
1331
- await this.mempools.attestationPool.addCheckpointAttestations(attestations);
1420
+ await this.mempools.attestationPool.addOwnCheckpointAttestations(attestations);
1332
1421
  for (const attestation of attestations){
1333
1422
  await this.propagate(attestation);
1334
1423
  }
@@ -1357,9 +1446,9 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1357
1446
  */ async validateRequestedBlockTxs(request, response, peerId) {
1358
1447
  const requestedTxValidator = this.createRequestedTxValidator();
1359
1448
  try {
1360
- if (!response.blockHash.equals(request.blockHash)) {
1449
+ if (!response.archiveRoot.equals(request.archiveRoot)) {
1361
1450
  this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1362
- 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()}`);
1363
1452
  }
1364
1453
  if (response.txIndices.getLength() !== request.txIndices.getLength()) {
1365
1454
  this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
@@ -1382,7 +1471,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1382
1471
  throw new ValidationError(`Received more txs (${response.txs.length}) than requested-and-available (${maxReturnable})`);
1383
1472
  }
1384
1473
  // Given proposal (should have locally), ensure returned txs are valid subset and match request indices
1385
- const proposal = await this.mempools.attestationPool.getBlockProposal(request.blockHash.toString());
1474
+ const proposal = await this.mempools.attestationPool.getBlockProposal(request.archiveRoot.toString());
1386
1475
  if (proposal) {
1387
1476
  // Build intersected indices
1388
1477
  const intersectIdx = request.txIndices.getTrueIndices().filter((i)=>response.txIndices.isSet(i));
@@ -1401,7 +1490,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1401
1490
  }
1402
1491
  } else {
1403
1492
  // No local proposal, cannot check the membership/order of the returned txs
1404
- 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`);
1405
1494
  return false;
1406
1495
  }
1407
1496
  await Promise.all(response.txs.map((tx)=>this.validateRequestedTx(tx, peerId, requestedTxValidator)));
@@ -1431,7 +1520,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1431
1520
  */ async validateRequestedTxs(requestedTxHash, responseTx, peerId) {
1432
1521
  const requested = new Set(requestedTxHash.map((h)=>h.toString()));
1433
1522
  const requestedTxValidator = this.createRequestedTxValidator();
1434
- //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.
1435
1524
  // I think we should still extract the valid txs and return them, so that we can still use the response.
1436
1525
  try {
1437
1526
  await Promise.all(responseTx.map((tx)=>this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
@@ -1484,20 +1573,8 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1484
1573
  return false;
1485
1574
  }
1486
1575
  }
1487
- createRequestedTxValidator() {
1488
- return new AggregateTxValidator(new DataTxValidator(), new MetadataTxValidator({
1489
- l1ChainId: new Fr(this.config.l1ChainId),
1490
- rollupVersion: new Fr(this.config.rollupVersion),
1491
- protocolContractsHash,
1492
- vkTreeRoot: getVKTreeRoot()
1493
- }), new TxProofValidator(this.proofVerifier));
1494
- }
1495
1576
  async validateRequestedTx(tx, peerId, txValidator, requested) {
1496
1577
  const penalize = (severity)=>this.peerManager.penalizePeer(peerId, severity);
1497
- if (!await tx.validateTxHash()) {
1498
- penalize(PeerErrorSeverity.MidToleranceError);
1499
- throw new ValidationError(`Received tx with invalid hash ${tx.getTxHash().toString()}.`);
1500
- }
1501
1578
  if (requested && !requested.has(tx.getTxHash().toString())) {
1502
1579
  penalize(PeerErrorSeverity.MidToleranceError);
1503
1580
  throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
@@ -1508,6 +1585,12 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1508
1585
  throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that is invalid.`);
1509
1586
  }
1510
1587
  }
1588
+ createRequestedTxValidator() {
1589
+ return createTxReqRespValidator(this.proofVerifier, {
1590
+ l1ChainId: this.config.l1ChainId,
1591
+ rollupVersion: this.config.rollupVersion
1592
+ });
1593
+ }
1511
1594
  async validatePropagatedTx(tx, peerId) {
1512
1595
  const currentBlockNumber = await this.archiver.getBlockNumber();
1513
1596
  // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
@@ -1542,6 +1625,20 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1542
1625
  };
1543
1626
  return gasFees;
1544
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
+ }
1545
1642
  async validate(txs) {
1546
1643
  const currentBlockNumber = await this.archiver.getBlockNumber();
1547
1644
  // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
@@ -1573,7 +1670,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1573
1670
  const gasFees = await this.getGasFees(currentBlockNumber);
1574
1671
  const allowedInSetup = this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
1575
1672
  const blockNumberInWhichTheTxIsConsideredToBeIncluded = BlockNumber(currentBlockNumber + 1);
1576
- 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());
1577
1674
  }
1578
1675
  /**
1579
1676
  * Run validations on a tx.
@@ -1632,7 +1729,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1632
1729
  const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
1633
1730
  return indices.map((index)=>index !== undefined);
1634
1731
  }
1635
- });
1732
+ }, this.logger.getBindings());
1636
1733
  const validSnapshot = await snapshotValidator.validateTx(tx);
1637
1734
  if (validSnapshot.result !== 'valid') {
1638
1735
  return PeerErrorSeverity.LowToleranceError;
@@ -1645,41 +1742,12 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1645
1742
  * @param attestation - The checkpoint attestation to validate.
1646
1743
  * @returns True if the checkpoint attestation is valid, false otherwise.
1647
1744
  */ async validateCheckpointAttestation(peerId, attestation) {
1648
- const severity = await this.checkpointAttestationValidator.validate(attestation);
1649
- if (severity) {
1650
- this.logger.debug(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
1651
- this.peerManager.penalizePeer(peerId, severity);
1652
- return false;
1745
+ const result = await this.checkpointAttestationValidator.validate(attestation);
1746
+ if (result.result === 'reject') {
1747
+ this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
1748
+ this.peerManager.penalizePeer(peerId, result.severity);
1653
1749
  }
1654
- return true;
1655
- }
1656
- /**
1657
- * Validate a block proposal.
1658
- *
1659
- * @param block - The block proposal to validate.
1660
- * @returns True if the block proposal is valid, false otherwise.
1661
- */ async validateBlockProposal(peerId, block) {
1662
- const severity = await this.blockProposalValidator.validate(block);
1663
- if (severity) {
1664
- this.logger.debug(`Penalizing peer ${peerId} for block proposal validation failure`);
1665
- this.peerManager.penalizePeer(peerId, severity);
1666
- return false;
1667
- }
1668
- return true;
1669
- }
1670
- /**
1671
- * Validate a checkpoint proposal.
1672
- *
1673
- * @param checkpoint - The checkpoint proposal to validate.
1674
- * @returns True if the checkpoint proposal is valid, false otherwise.
1675
- */ async validateCheckpointProposal(peerId, checkpoint) {
1676
- const severity = await this.checkpointProposalValidator.validate(checkpoint);
1677
- if (severity) {
1678
- this.logger.debug(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
1679
- this.peerManager.penalizePeer(peerId, severity);
1680
- return false;
1681
- }
1682
- return true;
1750
+ return result;
1683
1751
  }
1684
1752
  getPeerScore(peerId) {
1685
1753
  return this.node.services.pubsub.score.score(peerId.toString());