@aztec/p2p 0.0.1-commit.6d63667d → 0.0.1-commit.71324e566

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 (469) hide show
  1. package/README.md +129 -3
  2. package/dest/client/factory.d.ts +11 -11
  3. package/dest/client/factory.d.ts.map +1 -1
  4. package/dest/client/factory.js +54 -16
  5. package/dest/client/interface.d.ts +54 -34
  6. package/dest/client/interface.d.ts.map +1 -1
  7. package/dest/client/p2p_client.d.ts +41 -52
  8. package/dest/client/p2p_client.d.ts.map +1 -1
  9. package/dest/client/p2p_client.js +179 -226
  10. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +21 -11
  11. package/dest/config.d.ts +133 -92
  12. package/dest/config.d.ts.map +1 -1
  13. package/dest/config.js +108 -39
  14. package/dest/errors/p2p-service.error.d.ts +9 -0
  15. package/dest/errors/p2p-service.error.d.ts.map +1 -0
  16. package/dest/errors/p2p-service.error.js +10 -0
  17. package/dest/errors/tx-pool.error.d.ts +8 -0
  18. package/dest/errors/tx-pool.error.d.ts.map +1 -0
  19. package/dest/errors/tx-pool.error.js +9 -0
  20. package/dest/index.d.ts +2 -2
  21. package/dest/index.d.ts.map +1 -1
  22. package/dest/index.js +1 -1
  23. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +106 -88
  24. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  25. package/dest/mem_pools/attestation_pool/attestation_pool.js +448 -3
  26. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
  27. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  28. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +353 -87
  29. package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
  30. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  31. package/dest/mem_pools/attestation_pool/index.js +1 -2
  32. package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
  33. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  34. package/dest/mem_pools/attestation_pool/mocks.js +2 -2
  35. package/dest/mem_pools/index.d.ts +3 -3
  36. package/dest/mem_pools/index.d.ts.map +1 -1
  37. package/dest/mem_pools/index.js +1 -1
  38. package/dest/mem_pools/instrumentation.d.ts +4 -2
  39. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  40. package/dest/mem_pools/instrumentation.js +16 -14
  41. package/dest/mem_pools/interface.d.ts +5 -5
  42. package/dest/mem_pools/interface.d.ts.map +1 -1
  43. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
  44. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  45. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
  46. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  47. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  48. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  49. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  50. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  51. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +7 -3
  52. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  53. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  54. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
  55. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
  56. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  57. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
  58. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +54 -5
  59. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  60. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  61. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +7 -5
  62. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +9 -7
  63. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  64. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  65. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +14 -6
  66. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  67. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  68. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +16 -4
  69. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  70. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  71. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +3 -3
  72. package/dest/mem_pools/tx_pool_v2/index.d.ts +3 -2
  73. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  74. package/dest/mem_pools/tx_pool_v2/index.js +2 -1
  75. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  76. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  77. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  78. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +30 -12
  79. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  80. package/dest/mem_pools/tx_pool_v2/interfaces.js +5 -1
  81. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +78 -15
  82. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  83. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +144 -19
  84. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +12 -3
  85. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  86. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +50 -45
  87. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +12 -5
  88. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  89. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +17 -6
  90. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +14 -5
  91. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  92. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +364 -189
  93. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +5 -2
  94. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  95. package/dest/msg_validators/attestation_validator/attestation_validator.js +20 -11
  96. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -3
  97. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  98. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +2 -2
  99. package/dest/msg_validators/clock_tolerance.d.ts +12 -1
  100. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
  101. package/dest/msg_validators/clock_tolerance.js +54 -3
  102. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +7 -4
  103. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  104. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
  105. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +7 -4
  106. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  107. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
  108. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +15 -8
  109. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  110. package/dest/msg_validators/proposal_validator/proposal_validator.js +67 -47
  111. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
  112. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  113. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  114. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  115. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  116. package/dest/msg_validators/tx_validator/allowed_public_setup.js +24 -20
  117. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  118. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  119. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  120. package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
  121. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
  122. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  123. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  124. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
  125. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
  126. package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
  127. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  128. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  129. package/dest/msg_validators/tx_validator/data_validator.js +35 -2
  130. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
  131. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  132. package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
  133. package/dest/msg_validators/tx_validator/factory.d.ts +133 -6
  134. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  135. package/dest/msg_validators/tx_validator/factory.js +247 -60
  136. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  137. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  138. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  139. package/dest/msg_validators/tx_validator/gas_validator.d.ts +67 -3
  140. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  141. package/dest/msg_validators/tx_validator/gas_validator.js +112 -43
  142. package/dest/msg_validators/tx_validator/index.d.ts +3 -1
  143. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  144. package/dest/msg_validators/tx_validator/index.js +2 -0
  145. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  146. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  147. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  148. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  149. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  150. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  151. package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
  152. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  153. package/dest/msg_validators/tx_validator/phases_validator.js +72 -24
  154. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
  155. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  156. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  157. package/dest/services/data_store.d.ts +1 -1
  158. package/dest/services/data_store.d.ts.map +1 -1
  159. package/dest/services/data_store.js +5 -5
  160. package/dest/services/dummy_service.d.ts +17 -6
  161. package/dest/services/dummy_service.d.ts.map +1 -1
  162. package/dest/services/dummy_service.js +16 -5
  163. package/dest/services/encoding.d.ts +7 -3
  164. package/dest/services/encoding.d.ts.map +1 -1
  165. package/dest/services/encoding.js +18 -11
  166. package/dest/services/gossipsub/index.d.ts +3 -0
  167. package/dest/services/gossipsub/index.d.ts.map +1 -0
  168. package/dest/services/gossipsub/index.js +2 -0
  169. package/dest/services/gossipsub/scoring.d.ts +21 -3
  170. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  171. package/dest/services/gossipsub/scoring.js +24 -7
  172. package/dest/services/gossipsub/topic_score_params.d.ts +184 -0
  173. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  174. package/dest/services/gossipsub/topic_score_params.js +363 -0
  175. package/dest/services/libp2p/libp2p_service.d.ts +93 -51
  176. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  177. package/dest/services/libp2p/libp2p_service.js +547 -421
  178. package/dest/services/peer-manager/metrics.d.ts +3 -1
  179. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  180. package/dest/services/peer-manager/metrics.js +6 -0
  181. package/dest/services/peer-manager/peer_manager.d.ts +6 -2
  182. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  183. package/dest/services/peer-manager/peer_manager.js +39 -11
  184. package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
  185. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  186. package/dest/services/peer-manager/peer_scoring.js +57 -12
  187. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +12 -8
  188. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  189. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +83 -106
  190. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +4 -7
  191. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  192. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +11 -13
  193. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  194. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +31 -46
  195. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
  196. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  197. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
  198. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
  199. package/dest/services/reqresp/config.d.ts +3 -3
  200. package/dest/services/reqresp/config.d.ts.map +1 -1
  201. package/dest/services/reqresp/interface.d.ts +23 -9
  202. package/dest/services/reqresp/interface.d.ts.map +1 -1
  203. package/dest/services/reqresp/interface.js +23 -10
  204. package/dest/services/reqresp/metrics.d.ts +1 -1
  205. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  206. package/dest/services/reqresp/metrics.js +0 -1
  207. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +4 -3
  208. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  209. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +7 -1
  210. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  211. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +15 -0
  212. package/dest/services/reqresp/protocols/index.d.ts +1 -2
  213. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  214. package/dest/services/reqresp/protocols/index.js +0 -1
  215. package/dest/services/reqresp/protocols/tx.d.ts +7 -1
  216. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  217. package/dest/services/reqresp/protocols/tx.js +21 -3
  218. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
  219. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  220. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
  221. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  222. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  223. package/dest/services/reqresp/rate-limiter/rate_limits.js +0 -10
  224. package/dest/services/reqresp/reqresp.d.ts +4 -2
  225. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  226. package/dest/services/reqresp/reqresp.js +40 -15
  227. package/dest/services/service.d.ts +43 -4
  228. package/dest/services/service.d.ts.map +1 -1
  229. package/dest/services/tx_collection/config.d.ts +19 -1
  230. package/dest/services/tx_collection/config.d.ts.map +1 -1
  231. package/dest/services/tx_collection/config.js +46 -0
  232. package/dest/services/tx_collection/fast_tx_collection.d.ts +3 -4
  233. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  234. package/dest/services/tx_collection/fast_tx_collection.js +80 -76
  235. package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
  236. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  237. package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
  238. package/dest/services/tx_collection/file_store_tx_source.d.ts +38 -0
  239. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  240. package/dest/services/tx_collection/file_store_tx_source.js +100 -0
  241. package/dest/services/tx_collection/index.d.ts +2 -1
  242. package/dest/services/tx_collection/index.d.ts.map +1 -1
  243. package/dest/services/tx_collection/index.js +1 -0
  244. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  245. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  246. package/dest/services/tx_collection/instrumentation.js +2 -1
  247. package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -7
  248. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  249. package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
  250. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  251. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  252. package/dest/services/tx_collection/request_tracker.js +84 -0
  253. package/dest/services/tx_collection/slow_tx_collection.d.ts +7 -3
  254. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  255. package/dest/services/tx_collection/slow_tx_collection.js +60 -26
  256. package/dest/services/tx_collection/tx_collection.d.ts +23 -13
  257. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  258. package/dest/services/tx_collection/tx_collection.js +75 -3
  259. package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
  260. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  261. package/dest/services/tx_collection/tx_collection_sink.js +26 -29
  262. package/dest/services/tx_collection/tx_source.d.ts +13 -7
  263. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  264. package/dest/services/tx_collection/tx_source.js +26 -7
  265. package/dest/services/tx_file_store/config.d.ts +1 -3
  266. package/dest/services/tx_file_store/config.d.ts.map +1 -1
  267. package/dest/services/tx_file_store/config.js +0 -4
  268. package/dest/services/tx_file_store/tx_file_store.d.ts +4 -3
  269. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  270. package/dest/services/tx_file_store/tx_file_store.js +9 -6
  271. package/dest/services/tx_provider.d.ts +4 -4
  272. package/dest/services/tx_provider.d.ts.map +1 -1
  273. package/dest/services/tx_provider.js +9 -8
  274. package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
  275. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  276. package/dest/test-helpers/make-test-p2p-clients.js +1 -2
  277. package/dest/test-helpers/mock-pubsub.d.ts +40 -6
  278. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  279. package/dest/test-helpers/mock-pubsub.js +139 -13
  280. package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
  281. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  282. package/dest/test-helpers/reqresp-nodes.js +5 -5
  283. package/dest/test-helpers/testbench-utils.d.ts +43 -38
  284. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  285. package/dest/test-helpers/testbench-utils.js +150 -61
  286. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  287. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  288. package/dest/testbench/p2p_client_testbench_worker.js +80 -28
  289. package/dest/testbench/worker_client_manager.d.ts +10 -1
  290. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  291. package/dest/testbench/worker_client_manager.js +55 -3
  292. package/dest/util.d.ts +3 -3
  293. package/dest/util.d.ts.map +1 -1
  294. package/package.json +14 -14
  295. package/src/client/factory.ts +105 -29
  296. package/src/client/interface.ts +65 -35
  297. package/src/client/p2p_client.ts +216 -272
  298. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +34 -15
  299. package/src/config.ts +171 -45
  300. package/src/errors/p2p-service.error.ts +11 -0
  301. package/src/errors/tx-pool.error.ts +12 -0
  302. package/src/index.ts +1 -1
  303. package/src/mem_pools/attestation_pool/attestation_pool.ts +501 -91
  304. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +442 -102
  305. package/src/mem_pools/attestation_pool/index.ts +9 -2
  306. package/src/mem_pools/attestation_pool/mocks.ts +2 -1
  307. package/src/mem_pools/index.ts +2 -2
  308. package/src/mem_pools/instrumentation.ts +17 -13
  309. package/src/mem_pools/interface.ts +4 -4
  310. package/src/mem_pools/tx_pool_v2/README.md +85 -11
  311. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
  312. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  313. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +7 -3
  314. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
  315. package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
  316. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +59 -4
  317. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
  318. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +8 -8
  319. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -9
  320. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +33 -6
  321. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +4 -3
  322. package/src/mem_pools/tx_pool_v2/index.ts +2 -1
  323. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  324. package/src/mem_pools/tx_pool_v2/interfaces.ts +32 -12
  325. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +209 -27
  326. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +58 -45
  327. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +34 -8
  328. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +410 -187
  329. package/src/msg_validators/attestation_validator/README.md +49 -0
  330. package/src/msg_validators/attestation_validator/attestation_validator.ts +21 -9
  331. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +6 -3
  332. package/src/msg_validators/clock_tolerance.ts +72 -3
  333. package/src/msg_validators/proposal_validator/README.md +123 -0
  334. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +17 -4
  335. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +23 -7
  336. package/src/msg_validators/proposal_validator/proposal_validator.ts +79 -49
  337. package/src/msg_validators/tx_validator/README.md +119 -0
  338. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
  339. package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
  340. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  341. package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
  342. package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
  343. package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
  344. package/src/msg_validators/tx_validator/data_validator.ts +42 -1
  345. package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
  346. package/src/msg_validators/tx_validator/factory.ts +394 -78
  347. package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
  348. package/src/msg_validators/tx_validator/gas_validator.ts +145 -33
  349. package/src/msg_validators/tx_validator/index.ts +2 -0
  350. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  351. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  352. package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
  353. package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
  354. package/src/services/data_store.ts +5 -13
  355. package/src/services/dummy_service.ts +25 -7
  356. package/src/services/encoding.ts +18 -10
  357. package/src/services/gossipsub/README.md +641 -0
  358. package/src/services/gossipsub/index.ts +2 -0
  359. package/src/services/gossipsub/scoring.ts +29 -5
  360. package/src/services/gossipsub/topic_score_params.ts +519 -0
  361. package/src/services/libp2p/libp2p_service.ts +566 -460
  362. package/src/services/peer-manager/metrics.ts +7 -0
  363. package/src/services/peer-manager/peer_manager.ts +45 -11
  364. package/src/services/peer-manager/peer_scoring.ts +52 -5
  365. package/src/services/reqresp/README.md +229 -0
  366. package/src/services/reqresp/batch-tx-requester/README.md +46 -7
  367. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +79 -112
  368. package/src/services/reqresp/batch-tx-requester/interface.ts +3 -6
  369. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +30 -71
  370. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
  371. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
  372. package/src/services/reqresp/config.ts +2 -2
  373. package/src/services/reqresp/interface.ts +45 -10
  374. package/src/services/reqresp/metrics.ts +0 -1
  375. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +4 -3
  376. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +17 -0
  377. package/src/services/reqresp/protocols/index.ts +0 -1
  378. package/src/services/reqresp/protocols/tx.ts +23 -3
  379. package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
  380. package/src/services/reqresp/rate-limiter/rate_limits.ts +0 -10
  381. package/src/services/reqresp/reqresp.ts +53 -16
  382. package/src/services/service.ts +57 -3
  383. package/src/services/tx_collection/config.ts +68 -0
  384. package/src/services/tx_collection/fast_tx_collection.ts +83 -76
  385. package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
  386. package/src/services/tx_collection/file_store_tx_source.ts +129 -0
  387. package/src/services/tx_collection/index.ts +1 -0
  388. package/src/services/tx_collection/instrumentation.ts +7 -1
  389. package/src/services/tx_collection/proposal_tx_collector.ts +9 -13
  390. package/src/services/tx_collection/request_tracker.ts +127 -0
  391. package/src/services/tx_collection/slow_tx_collection.ts +66 -33
  392. package/src/services/tx_collection/tx_collection.ts +114 -19
  393. package/src/services/tx_collection/tx_collection_sink.ts +30 -34
  394. package/src/services/tx_collection/tx_source.ts +28 -8
  395. package/src/services/tx_file_store/config.ts +0 -6
  396. package/src/services/tx_file_store/tx_file_store.ts +10 -8
  397. package/src/services/tx_provider.ts +10 -9
  398. package/src/test-helpers/make-test-p2p-clients.ts +4 -6
  399. package/src/test-helpers/mock-pubsub.ts +177 -14
  400. package/src/test-helpers/reqresp-nodes.ts +7 -9
  401. package/src/test-helpers/testbench-utils.ts +157 -74
  402. package/src/testbench/p2p_client_testbench_worker.ts +91 -31
  403. package/src/testbench/worker_client_manager.ts +68 -6
  404. package/src/util.ts +8 -2
  405. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
  406. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  407. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
  408. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
  409. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  410. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
  411. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
  412. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
  413. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
  414. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
  415. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
  416. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
  417. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
  418. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
  419. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
  420. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
  421. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
  422. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
  423. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
  424. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
  425. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
  426. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
  427. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
  428. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
  429. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
  430. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
  431. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
  432. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
  433. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
  434. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
  435. package/dest/mem_pools/tx_pool/index.d.ts +0 -3
  436. package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
  437. package/dest/mem_pools/tx_pool/index.js +0 -2
  438. package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
  439. package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
  440. package/dest/mem_pools/tx_pool/priority.js +0 -15
  441. package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
  442. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
  443. package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
  444. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
  445. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
  446. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
  447. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
  448. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  449. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
  450. package/dest/services/reqresp/protocols/block.d.ts +0 -9
  451. package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
  452. package/dest/services/reqresp/protocols/block.js +0 -32
  453. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
  454. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
  455. package/src/mem_pools/tx_pool/README.md +0 -270
  456. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
  457. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
  458. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
  459. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
  460. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
  461. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
  462. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
  463. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
  464. package/src/mem_pools/tx_pool/index.ts +0 -2
  465. package/src/mem_pools/tx_pool/priority.ts +0 -20
  466. package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
  467. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
  468. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
  469. package/src/services/reqresp/protocols/block.ts +0 -37
@@ -370,21 +370,21 @@ 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, _initProto;
374
374
  import { BlockNumber } from '@aztec/foundation/branded-types';
375
- import { randomInt } from '@aztec/foundation/crypto/random';
375
+ import { maxBy } from '@aztec/foundation/collection';
376
376
  import { createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
377
377
  import { RunningPromise } from '@aztec/foundation/running-promise';
378
378
  import { Timer } from '@aztec/foundation/timer';
379
379
  import { protocolContractsHash } from '@aztec/protocol-contracts';
380
380
  import { GasFees } from '@aztec/stdlib/gas';
381
- import { BlockProposal, CheckpointAttestation, CheckpointProposal, P2PClientType, P2PMessage, PeerErrorSeverity, TopicType, createTopicString, getTopicsForClientAndConfig, metricsTopicStrToLabels } from '@aztec/stdlib/p2p';
381
+ import { BlockProposal, CheckpointAttestation, CheckpointProposal, P2PMessage, PeerErrorSeverity, PeerErrorSeverityByHarshness, TopicType, createTopicString, getTopicsForConfig, metricsTopicStrToLabels } from '@aztec/stdlib/p2p';
382
382
  import { MerkleTreeId } from '@aztec/stdlib/trees';
383
383
  import { Tx } from '@aztec/stdlib/tx';
384
384
  import { compressComponentVersions } from '@aztec/stdlib/versioning';
385
385
  import { Attributes, OtelMetricsAdapter, SpanStatusCode, WithTracer, trackSpan } from '@aztec/telemetry-client';
386
386
  import { gossipsub } from '@chainsafe/libp2p-gossipsub';
387
- import { createPeerScoreParams, createTopicScoreParams } from '@chainsafe/libp2p-gossipsub/score';
387
+ import { createPeerScoreParams } from '@chainsafe/libp2p-gossipsub/score';
388
388
  import { SignaturePolicy } from '@chainsafe/libp2p-gossipsub/types';
389
389
  import { noise } from '@chainsafe/libp2p-noise';
390
390
  import { yamux } from '@chainsafe/libp2p-yamux';
@@ -395,52 +395,46 @@ import { mplex } from '@libp2p/mplex';
395
395
  import { tcp } from '@libp2p/tcp';
396
396
  import { ENR } from '@nethermindeth/enr';
397
397
  import { createLibp2p } from 'libp2p';
398
- import { ProposalSlotCapExceededError } from '../../errors/attestation-pool.error.js';
398
+ import { CheckpointProposalReceivedCallbackNotRegisteredError } from '../../errors/p2p-service.error.js';
399
399
  import { BlockProposalValidator, CheckpointAttestationValidator, CheckpointProposalValidator, DoubleSpendTxValidator, FishermanAttestationValidator, getDefaultAllowedSetupFunctions } from '../../msg_validators/index.js';
400
400
  import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
401
- import { createTxMessageValidators, createTxReqRespValidator } from '../../msg_validators/tx_validator/factory.js';
401
+ import { createFirstStageTxValidationsForGossipedTransactions, createSecondStageTxValidationsForGossipedTransactions, createTxValidatorForBlockProposalReceivedTxs, createTxValidatorForReqResponseReceivedTxs } from '../../msg_validators/tx_validator/factory.js';
402
402
  import { GossipSubEvent } from '../../types/index.js';
403
403
  import { convertToMultiaddr } from '../../util.js';
404
404
  import { getVersions } from '../../versioning.js';
405
405
  import { AztecDatastore } from '../data_store.js';
406
406
  import { DiscV5Service } from '../discv5/discV5_service.js';
407
407
  import { SnappyTransform, fastMsgIdFn, getMsgIdFn, msgIdToStrFn } from '../encoding.js';
408
- import { gossipScoreThresholds } from '../gossipsub/scoring.js';
408
+ import { APP_SPECIFIC_WEIGHT, gossipScoreThresholds } from '../gossipsub/scoring.js';
409
+ import { createAllTopicScoreParams } from '../gossipsub/topic_score_params.js';
409
410
  import { PeerManager } from '../peer-manager/peer_manager.js';
410
411
  import { PeerScoring } from '../peer-manager/peer_scoring.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';
412
+ import { DEFAULT_SUB_PROTOCOL_VALIDATORS, ReqRespSubProtocol, ValidationError, pingHandler, reqGoodbyeHandler, reqRespBlockTxsHandler, reqRespStatusHandler, reqRespTxHandler } from '../reqresp/index.js';
413
413
  import { ReqResp } from '../reqresp/reqresp.js';
414
414
  import { P2PInstrumentation } from './instrumentation.js';
415
- _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)=>({
416
421
  [Attributes.SLOT_NUMBER]: block.slotNumber,
417
422
  [Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
418
423
  [Attributes.P2P_ID]: await block.p2pMessageLoggingIdentifier().then((i)=>i.toString())
419
- })), _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)=>({
420
427
  [Attributes.SLOT_NUMBER]: checkpoint.slotNumber,
421
428
  [Attributes.BLOCK_ARCHIVE]: checkpoint.archive.toString(),
422
429
  [Attributes.P2P_ID]: await checkpoint.p2pMessageLoggingIdentifier().then((i)=>i.toString())
423
- })), _dec2 = trackSpan('Libp2pService.validateRequestedBlockTxs', (request)=>({
430
+ })), _dec5 = trackSpan('Libp2pService.validateRequestedBlockTxs', (request)=>({
424
431
  [Attributes.BLOCK_ARCHIVE]: request.archiveRoot.toString()
425
- })), _dec3 = trackSpan('Libp2pService.validateRequestedTx', (requestedTxHash, _responseTx)=>({
432
+ })), _dec6 = trackSpan('Libp2pService.validateRequestedTx', (requestedTxHash, _responseTx)=>({
426
433
  [Attributes.TX_HASH]: requestedTxHash.toString()
427
- })), _dec4 = trackSpan('Libp2pService.validateRequestedBlock', (requestedBlockNumber, _responseBlock)=>({
428
- [Attributes.BLOCK_NUMBER]: requestedBlockNumber.toString()
429
- })), _dec5 = trackSpan('Libp2pService.validatePropagatedTx', (tx)=>({
430
- [Attributes.TX_HASH]: tx.getTxHash().toString()
431
- })), _dec6 = trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation)=>({
432
- [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
433
- [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
434
- [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then((i)=>i.toString())
435
- })), _dec7 = trackSpan('Libp2pService.validateBlockProposal', (_peerId, block)=>({
436
- [Attributes.SLOT_NUMBER]: block.slotNumber.toString()
437
- })), _dec8 = trackSpan('Libp2pService.validateCheckpointProposal', (_peerId, checkpoint)=>({
438
- [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString()
439
434
  }));
440
435
  /**
441
436
  * Lib P2P implementation of the P2PService interface.
442
437
  */ export class LibP2PService extends WithTracer {
443
- clientType;
444
438
  config;
445
439
  node;
446
440
  peerDiscoveryService;
@@ -456,47 +450,37 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
456
450
  [
457
451
  _dec,
458
452
  2,
459
- "processValidBlockProposal"
453
+ "validateAndStoreCheckpointAttestation"
460
454
  ],
461
455
  [
462
456
  _dec1,
463
457
  2,
464
- "processValidCheckpointProposal"
458
+ "validateAndStoreBlockProposal"
465
459
  ],
466
460
  [
467
461
  _dec2,
468
462
  2,
469
- "validateRequestedBlockTxs"
463
+ "processValidBlockProposal"
470
464
  ],
471
465
  [
472
466
  _dec3,
473
467
  2,
474
- "validateRequestedTxs"
468
+ "validateAndStoreCheckpointProposal"
475
469
  ],
476
470
  [
477
471
  _dec4,
478
472
  2,
479
- "validateRequestedBlock"
473
+ "processValidCheckpointProposal"
480
474
  ],
481
475
  [
482
476
  _dec5,
483
477
  2,
484
- "validatePropagatedTx"
478
+ "validateRequestedBlockTxs"
485
479
  ],
486
480
  [
487
481
  _dec6,
488
482
  2,
489
- "validateCheckpointAttestation"
490
- ],
491
- [
492
- _dec7,
493
- 2,
494
- "validateBlockProposal"
495
- ],
496
- [
497
- _dec8,
498
- 2,
499
- "validateCheckpointProposal"
483
+ "validateRequestedTxs"
500
484
  ]
501
485
  ], []));
502
486
  }
@@ -509,6 +493,8 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
509
493
  protocolVersion;
510
494
  topicStrings;
511
495
  feesCache;
496
+ /** Callback invoked when a duplicate proposal is detected (triggers slashing). */ duplicateProposalCallback;
497
+ /** Callback invoked when a duplicate attestation is detected (triggers slashing). */ duplicateAttestationCallback;
512
498
  /**
513
499
  * Callback for when a block is received from a peer.
514
500
  * @param block - The block received from the peer.
@@ -518,13 +504,18 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
518
504
  * Callback for when a checkpoint proposal is received from a peer.
519
505
  * @param checkpoint - The checkpoint proposal received from the peer.
520
506
  * @returns The attestations for the checkpoint, if any.
521
- */ checkpointReceivedCallback;
507
+ */ allNodesCheckpointReceivedCallback;
508
+ /**
509
+ * Callback for when a checkpoint proposal is received - specifically for validators - from a peer.
510
+ * @param checkpoint - The checkpoint proposal received from the peer.
511
+ * @returns The attestations for the checkpoint, if any.
512
+ */ validatorCheckpointReceivedCallback;
522
513
  gossipSubEventHandler;
523
514
  instrumentation;
524
515
  telemetry;
525
516
  logger;
526
- constructor(clientType, config, node, peerDiscoveryService, reqresp, peerManager, mempools, archiver, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger = createLogger('p2p:libp2p_service')){
527
- super(telemetry, 'LibP2PService'), this.clientType = clientType, this.config = config, this.node = node, this.peerDiscoveryService = peerDiscoveryService, this.reqresp = reqresp, this.peerManager = peerManager, this.mempools = mempools, this.archiver = archiver, this.epochCache = epochCache, this.proofVerifier = proofVerifier, this.worldStateSynchronizer = worldStateSynchronizer, this.msgIdSeenValidators = (_initProto(this), {}), this.protocolVersion = '', this.topicStrings = {};
517
+ constructor(config, node, peerDiscoveryService, reqresp, peerManager, mempools, archiver, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger = createLogger('p2p:libp2p_service')){
518
+ super(telemetry, 'LibP2PService'), this.config = config, this.node = node, this.peerDiscoveryService = peerDiscoveryService, this.reqresp = reqresp, this.peerManager = peerManager, this.mempools = mempools, this.archiver = archiver, this.epochCache = epochCache, this.proofVerifier = proofVerifier, this.worldStateSynchronizer = worldStateSynchronizer, this.msgIdSeenValidators = (_initProto(this), {}), this.protocolVersion = '', this.topicStrings = {};
528
519
  this.telemetry = telemetry;
529
520
  // Create child logger with fisherman prefix if in fisherman mode
530
521
  this.logger = config.fishermanMode ? logger.createChild('[FISHERMAN]') : logger;
@@ -540,22 +531,30 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
540
531
  this.topicStrings[TopicType.block_proposal] = createTopicString(TopicType.block_proposal, this.protocolVersion);
541
532
  this.topicStrings[TopicType.checkpoint_proposal] = createTopicString(TopicType.checkpoint_proposal, this.protocolVersion);
542
533
  this.topicStrings[TopicType.checkpoint_attestation] = createTopicString(TopicType.checkpoint_attestation, this.protocolVersion);
543
- this.blockProposalValidator = new BlockProposalValidator(epochCache, {
544
- txsPermitted: !config.disableTransactions
545
- });
546
- this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, {
547
- txsPermitted: !config.disableTransactions
534
+ const p2pPropagationTime = config.attestationPropagationTime;
535
+ const proposalValidatorOpts = {
536
+ txsPermitted: !config.disableTransactions,
537
+ maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
538
+ p2pPropagationTime
539
+ };
540
+ this.blockProposalValidator = new BlockProposalValidator(epochCache, proposalValidatorOpts);
541
+ this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, proposalValidatorOpts);
542
+ this.checkpointAttestationValidator = config.fishermanMode ? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry, {
543
+ l1PublishingTime: config.l1PublishingTime
544
+ }) : new CheckpointAttestationValidator(epochCache, {
545
+ l1PublishingTime: config.l1PublishingTime
548
546
  });
549
- this.checkpointAttestationValidator = config.fishermanMode ? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry) : new CheckpointAttestationValidator(epochCache);
550
547
  this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
551
548
  this.blockReceivedCallback = async (block)=>{
552
- this.logger.debug(`Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber} from peer.`, {
549
+ this.logger.warn(`Handler for block received not yet registered on P2P service. Received block ${block.blockNumber} for slot ${block.slotNumber} from peer.`, {
553
550
  p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier()
554
551
  });
555
- return false;
552
+ return true;
553
+ };
554
+ this.allNodesCheckpointReceivedCallback = (_checkpoint)=>{
555
+ throw new CheckpointProposalReceivedCallbackNotRegisteredError();
556
556
  };
557
- this.checkpointReceivedCallback = (checkpoint)=>{
558
- this.logger.debug(`Handler not yet registered: Checkpoint received callback not set. Received checkpoint for slot ${checkpoint.slotNumber} from peer.`);
557
+ this.validatorCheckpointReceivedCallback = (_checkpoint)=>{
559
558
  return Promise.resolve(undefined);
560
559
  };
561
560
  }
@@ -567,7 +566,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
567
566
  * @param config - The configuration to use when creating the service.
568
567
  * @param txPool - The transaction pool to be accessed by the service.
569
568
  * @returns The new service.
570
- */ static async new(clientType, config, peerId, deps) {
569
+ */ static async new(config, peerId, deps) {
571
570
  const { worldStateSynchronizer, epochCache, l2BlockSource, mempools, proofVerifier, peerStore, telemetry, logger, packageVersion } = deps;
572
571
  const { p2pPort, maxPeerCount, listenAddress } = config;
573
572
  const bindAddrTcp = convertToMultiaddr(listenAddress, p2pPort, 'tcp');
@@ -587,10 +586,6 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
587
586
  }
588
587
  const versions = getVersions(config);
589
588
  const protocolVersion = compressComponentVersions(versions);
590
- const txTopic = createTopicString(TopicType.tx, protocolVersion);
591
- const blockProposalTopic = createTopicString(TopicType.block_proposal, protocolVersion);
592
- const checkpointProposalTopic = createTopicString(TopicType.checkpoint_proposal, protocolVersion);
593
- const checkpointAttestationTopic = createTopicString(TopicType.checkpoint_attestation, protocolVersion);
594
589
  const preferredPeersEnrs = config.preferredPeers.map((enr)=>ENR.decodeTxt(enr));
595
590
  const directPeers = (await Promise.all(preferredPeersEnrs.map(async (enr)=>{
596
591
  const peerId = await enr.peerId();
@@ -608,6 +603,18 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
608
603
  const announceTcpMultiaddr = config.p2pIp ? [
609
604
  convertToMultiaddr(config.p2pIp, p2pPort, 'tcp')
610
605
  ] : [];
606
+ // Create dynamic topic score params based on network configuration
607
+ const l1Constants = epochCache.getL1Constants();
608
+ const topicScoreParams = createAllTopicScoreParams(protocolVersion, {
609
+ slotDurationMs: l1Constants.slotDuration * 1000,
610
+ ethereumSlotDuration: l1Constants.ethereumSlotDuration,
611
+ heartbeatIntervalMs: config.gossipsubInterval,
612
+ targetCommitteeSize: l1Constants.targetCommitteeSize,
613
+ blockDurationMs: config.blockDurationMs,
614
+ l1PublishingTime: config.l1PublishingTime,
615
+ p2pPropagationTime: config.attestationPropagationTime,
616
+ expectedBlockProposalsPerSlot: config.expectedBlockProposalsPerSlot
617
+ });
611
618
  const node = await createLibp2p({
612
619
  start: false,
613
620
  peerId,
@@ -708,28 +715,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
708
715
  scoreParams: createPeerScoreParams({
709
716
  // IPColocation factor can be disabled for local testing - default to -5
710
717
  IPColocationFactorWeight: config.debugDisableColocationPenalty ? 0 : -5.0,
711
- topics: {
712
- [txTopic]: createTopicScoreParams({
713
- topicWeight: 1,
714
- invalidMessageDeliveriesWeight: -20,
715
- invalidMessageDeliveriesDecay: 0.5
716
- }),
717
- [blockProposalTopic]: createTopicScoreParams({
718
- topicWeight: 1,
719
- invalidMessageDeliveriesWeight: -20,
720
- invalidMessageDeliveriesDecay: 0.5
721
- }),
722
- [checkpointProposalTopic]: createTopicScoreParams({
723
- topicWeight: 1,
724
- invalidMessageDeliveriesWeight: -20,
725
- invalidMessageDeliveriesDecay: 0.5
726
- }),
727
- [checkpointAttestationTopic]: createTopicScoreParams({
728
- topicWeight: 1,
729
- invalidMessageDeliveriesWeight: -20,
730
- invalidMessageDeliveriesDecay: 0.5
731
- })
732
- }
718
+ topics: topicScoreParams
733
719
  })
734
720
  }),
735
721
  components: (components)=>({
@@ -741,10 +727,16 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
741
727
  const peerScoring = new PeerScoring(config, telemetry);
742
728
  const reqresp = new ReqResp(config, node, peerScoring, createLogger(`${logger.module}:reqresp`));
743
729
  const peerManager = new PeerManager(node, peerDiscoveryService, config, telemetry, createLogger(`${logger.module}:peer_manager`), peerScoring, reqresp, worldStateSynchronizer, protocolVersion, epochCache);
744
- // Update gossipsub score params
745
- node.services.pubsub.score.params.appSpecificWeight = 10;
730
+ // Gate req/resp data protocols for unauthenticated peers when p2pAllowOnlyValidators is enabled
731
+ reqresp.setShouldRejectPeer((peerId)=>peerManager.shouldDisableP2PGossip(peerId));
732
+ // Configure application-specific scoring for gossipsub.
733
+ // The weight scales app score to align with gossipsub thresholds:
734
+ // - Disconnect (-50) × 10 = -500 = gossipThreshold (stops receiving gossip)
735
+ // - Ban (-100) × 10 = -1000 = publishThreshold (cannot publish)
736
+ // Note: positive topic scores can offset penalties, so alignment is best-effort.
737
+ node.services.pubsub.score.params.appSpecificWeight = APP_SPECIFIC_WEIGHT;
746
738
  node.services.pubsub.score.params.appSpecificScore = (peerId)=>peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
747
- return new LibP2PService(clientType, config, node, peerDiscoveryService, reqresp, peerManager, mempools, l2BlockSource, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger);
739
+ return new LibP2PService(config, node, peerDiscoveryService, reqresp, peerManager, mempools, l2BlockSource, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger);
748
740
  }
749
741
  /**
750
742
  * Starts the LibP2P service.
@@ -763,13 +755,11 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
763
755
  // Create request response protocol handlers
764
756
  const txHandler = reqRespTxHandler(this.mempools);
765
757
  const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
766
- const blockHandler = reqRespBlockHandler(this.archiver);
767
758
  const statusHandler = reqRespStatusHandler(this.protocolVersion, this.worldStateSynchronizer, this.logger);
768
759
  const requestResponseHandlers = {
769
760
  [ReqRespSubProtocol.PING]: pingHandler,
770
761
  [ReqRespSubProtocol.STATUS]: statusHandler.bind(this),
771
- [ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this),
772
- [ReqRespSubProtocol.BLOCK]: blockHandler.bind(this)
762
+ [ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this)
773
763
  };
774
764
  if (!this.config.disableTransactions) {
775
765
  const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.archiver, this.mempools.txPool);
@@ -782,14 +772,13 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
782
772
  const reqrespSubProtocolValidators = {
783
773
  ...DEFAULT_SUB_PROTOCOL_VALIDATORS,
784
774
  [ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
785
- [ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
786
- [ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this)
775
+ [ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this)
787
776
  };
788
777
  await this.peerManager.initializePeers();
789
778
  await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
790
779
  await this.node.start();
791
780
  // Subscribe to standard GossipSub topics by default
792
- for (const topic of getTopicsForClientAndConfig(this.clientType, this.config.disableTransactions)){
781
+ for (const topic of getTopicsForConfig(this.config.disableTransactions)){
793
782
  this.subscribeToTopic(this.topicStrings[topic]);
794
783
  }
795
784
  // add GossipSub listener
@@ -837,6 +826,9 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
837
826
  getPeers(includePending) {
838
827
  return this.peerManager.getPeers(includePending);
839
828
  }
829
+ getGossipMeshPeerCount(topicType) {
830
+ return this.node.services.pubsub.getMeshPeers(this.topicStrings[topicType]).length;
831
+ }
840
832
  handleGossipSubEvent(e) {
841
833
  this.logger.trace(`Received PUBSUB message.`);
842
834
  const safeJob = async ()=>{
@@ -868,8 +860,27 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
868
860
  registerBlockReceivedCallback(callback) {
869
861
  this.blockReceivedCallback = callback;
870
862
  }
871
- registerCheckpointReceivedCallback(callback) {
872
- this.checkpointReceivedCallback = callback;
863
+ registerValidatorCheckpointReceivedCallback(callback) {
864
+ this.validatorCheckpointReceivedCallback = callback;
865
+ }
866
+ registerAllNodesCheckpointReceivedCallback(callback) {
867
+ this.allNodesCheckpointReceivedCallback = callback;
868
+ }
869
+ async notifyOwnCheckpointProposal(checkpoint) {
870
+ await this.allNodesCheckpointReceivedCallback(checkpoint, this.node.peerId);
871
+ }
872
+ /**
873
+ * Registers a callback to be invoked when a duplicate proposal is detected.
874
+ * This callback is triggered on the first duplicate (when count goes from 1 to 2).
875
+ */ registerDuplicateProposalCallback(callback) {
876
+ this.duplicateProposalCallback = callback;
877
+ }
878
+ /**
879
+ * Registers a callback to be invoked when a duplicate attestation is detected.
880
+ * A validator signing attestations for different proposals at the same slot.
881
+ * This callback is triggered on the first duplicate (when count goes from 1 to 2).
882
+ */ registerDuplicateAttestationCallback(callback) {
883
+ this.duplicateAttestationCallback = callback;
873
884
  }
874
885
  /**
875
886
  * Subscribes to a topic.
@@ -922,6 +933,12 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
922
933
  if (!validator || !validator.addMessage(msgId)) {
923
934
  this.instrumentation.incMessagePrevalidationStatus(false, topicType);
924
935
  this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
936
+ if (topicType === TopicType.tx) {
937
+ this.logger.verbose(`Ignoring already-seen tx gossip message`, {
938
+ msgId,
939
+ source: source.toString()
940
+ });
941
+ }
925
942
  return {
926
943
  result: false,
927
944
  topicType
@@ -982,9 +999,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
982
999
  if (msg.topic === this.topicStrings[TopicType.tx]) {
983
1000
  await this.handleGossipedTx(p2pMessage.payload, msgId, source);
984
1001
  } else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
985
- if (this.clientType === P2PClientType.Full) {
986
- await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
987
- }
1002
+ await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
988
1003
  } else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
989
1004
  await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
990
1005
  } else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
@@ -1029,49 +1044,150 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1029
1044
  return;
1030
1045
  }
1031
1046
  async validateReceivedMessage(validationFunc, msgId, source, topicType) {
1047
+ // Default to reject result with a penalty if validation function throws an error
1032
1048
  let resultAndObj = {
1033
- result: TopicValidatorResult.Reject
1049
+ result: TopicValidatorResult.Reject,
1050
+ severity: PeerErrorSeverity.MidToleranceError
1034
1051
  };
1035
1052
  const timer = new Timer();
1036
1053
  try {
1037
1054
  resultAndObj = await validationFunc();
1038
1055
  } catch (err) {
1039
- this.peerManager.penalizePeer(source, PeerErrorSeverity.LowToleranceError);
1040
- this.logger.error(`Error deserializing and validating gossipsub message`, err, {
1056
+ this.logger.error(`Error validating gossipsub message`, err, {
1041
1057
  msgId,
1042
1058
  source: source.toString(),
1043
1059
  topicType
1044
1060
  });
1045
1061
  }
1046
1062
  if (resultAndObj.result === TopicValidatorResult.Accept) {
1063
+ this.logger.debug(`Message ${topicType} accepted by validator`, {
1064
+ msgId,
1065
+ source: source.toString(),
1066
+ topicType
1067
+ });
1047
1068
  this.instrumentation.recordMessageValidation(topicType, timer);
1069
+ } else if (resultAndObj.result === TopicValidatorResult.Reject) {
1070
+ this.logger.warn(`Message ${topicType} rejected by validator with severity ${resultAndObj.severity}`, {
1071
+ msgId,
1072
+ source: source.toString(),
1073
+ topicType,
1074
+ severity: resultAndObj.severity
1075
+ });
1076
+ this.peerManager.penalizePeer(source, resultAndObj.severity);
1077
+ } else {
1078
+ this.logger.trace(`Message ${topicType} ignored by validator`, {
1079
+ msgId,
1080
+ source: source.toString(),
1081
+ topicType
1082
+ });
1048
1083
  }
1049
1084
  this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result);
1050
1085
  return resultAndObj;
1051
1086
  }
1087
+ tryDeserialize(deserializeFunc, msgId, source) {
1088
+ try {
1089
+ return deserializeFunc();
1090
+ } catch (err) {
1091
+ this.logger.warn(`Failed to deserialize gossipsub message from buffer`, {
1092
+ err,
1093
+ msgId,
1094
+ source: source.toString()
1095
+ });
1096
+ return undefined;
1097
+ }
1098
+ }
1052
1099
  async handleGossipedTx(payloadData, msgId, source) {
1053
1100
  const validationFunc = async ()=>{
1054
- const tx = Tx.fromBuffer(payloadData);
1055
- const isValid = await this.validatePropagatedTx(tx, source);
1056
- const exists = isValid && await this.mempools.txPool.hasTx(tx.getTxHash());
1057
- this.logger.trace(`Validate propagated tx`, {
1058
- isValid,
1059
- exists,
1101
+ const tx = this.tryDeserialize(()=>Tx.fromBuffer(payloadData), msgId, source);
1102
+ if (!tx) {
1103
+ return {
1104
+ result: TopicValidatorResult.Reject,
1105
+ severity: PeerErrorSeverity.LowToleranceError
1106
+ };
1107
+ }
1108
+ const currentBlockNumber = await this.archiver.getBlockNumber();
1109
+ const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1110
+ // Stage 1: fast validators (metadata, data, timestamps, double-spend, gas, phases, block header)
1111
+ const firstStageValidators = await this.createFirstStageMessageValidators(currentBlockNumber, nextSlotTimestamp);
1112
+ const firstStageOutcome = await this.runValidations(tx, firstStageValidators);
1113
+ if (!firstStageOutcome.allPassed) {
1114
+ const { name } = firstStageOutcome.failure;
1115
+ let { severity } = firstStageOutcome.failure;
1116
+ // Double spend validator has a special case handler. We perform more detailed examination
1117
+ // as to how recently the nullifier was entered into the tree and if the transaction should
1118
+ // have 'known' the nullifier existed. This determines the severity of the penalty applied to the peer.
1119
+ if (name === 'doubleSpendValidator') {
1120
+ const txBlockNumber = BlockNumber(currentBlockNumber + 1);
1121
+ severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
1122
+ }
1123
+ this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 1 validation failed`, {
1124
+ validator: name,
1125
+ severity,
1126
+ source: source.toString()
1127
+ });
1128
+ return {
1129
+ result: TopicValidatorResult.Reject,
1130
+ severity
1131
+ };
1132
+ }
1133
+ // Pool pre-check: see if the pool would accept this tx before doing expensive proof verification
1134
+ const canAdd = await this.mempools.txPool.canAddPendingTx(tx);
1135
+ if (canAdd === 'ignored') {
1136
+ this.logger.verbose(`Ignoring gossiped tx ${tx.getTxHash().toString()}: pool pre-check returned ignored`, {
1137
+ source: source.toString()
1138
+ });
1139
+ return {
1140
+ result: TopicValidatorResult.Ignore,
1141
+ obj: tx
1142
+ };
1143
+ }
1144
+ // Stage 2: expensive proof verification
1145
+ const secondStageValidators = this.createSecondStageMessageValidators();
1146
+ const secondStageOutcome = await this.runValidations(tx, secondStageValidators);
1147
+ if (!secondStageOutcome.allPassed) {
1148
+ const { severity, name } = secondStageOutcome.failure;
1149
+ this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 2 validation failed`, {
1150
+ validator: name,
1151
+ severity,
1152
+ source: source.toString()
1153
+ });
1154
+ return {
1155
+ result: TopicValidatorResult.Reject,
1156
+ severity
1157
+ };
1158
+ }
1159
+ // Pool add: persist the tx
1160
+ const txHash = tx.getTxHash();
1161
+ const addResult = await this.mempools.txPool.addPendingTxs([
1162
+ tx
1163
+ ], {
1164
+ source: 'gossip'
1165
+ });
1166
+ const wasAccepted = addResult.accepted.some((h)=>h.equals(txHash));
1167
+ const wasIgnored = addResult.ignored.some((h)=>h.equals(txHash));
1168
+ this.logger.verbose(`Validate propagated tx ${txHash.toString()}`, {
1169
+ wasAccepted,
1170
+ wasIgnored,
1060
1171
  [Attributes.P2P_ID]: source.toString()
1061
1172
  });
1062
- if (!isValid) {
1173
+ if (wasAccepted) {
1063
1174
  return {
1064
- result: TopicValidatorResult.Reject
1175
+ result: TopicValidatorResult.Accept,
1176
+ obj: tx
1065
1177
  };
1066
- } else if (exists) {
1178
+ } else if (wasIgnored) {
1067
1179
  return {
1068
1180
  result: TopicValidatorResult.Ignore,
1069
1181
  obj: tx
1070
1182
  };
1071
1183
  } else {
1184
+ this.logger.warn(`Gossiped tx ${txHash.toString()} unexpectedly rejected by pool`, {
1185
+ source: source.toString(),
1186
+ txHash: txHash.toString()
1187
+ });
1072
1188
  return {
1073
- result: TopicValidatorResult.Accept,
1074
- obj: tx
1189
+ result: TopicValidatorResult.Reject,
1190
+ severity: PeerErrorSeverity.HighToleranceError
1075
1191
  };
1076
1192
  }
1077
1193
  };
@@ -1079,133 +1195,199 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1079
1195
  if (result !== TopicValidatorResult.Accept || !tx) {
1080
1196
  return;
1081
1197
  }
1198
+ // Tx was accepted into pool and will be propagated - just log and record metrics
1082
1199
  const txHash = tx.getTxHash();
1083
1200
  const txHashString = txHash.toString();
1084
1201
  this.logger.verbose(`Received tx ${txHashString} from external peer ${source.toString()} via gossip`, {
1085
1202
  source: source.toString(),
1086
1203
  txHash: txHashString
1087
1204
  });
1088
- if (this.config.dropTransactions && randomInt(1000) < this.config.dropTransactionsProbability * 1000) {
1089
- this.logger.warn(`Intentionally dropping tx ${txHashString} (probability rule)`);
1090
- return;
1091
- }
1092
1205
  this.instrumentation.incrementTxReceived(1);
1093
- await this.mempools.txPool.addTxs([
1094
- tx
1095
- ]);
1096
1206
  }
1097
1207
  /**
1098
1208
  * Process a checkpoint attestation from a peer.
1099
1209
  * Validates the attestation and adds it to the pool.
1100
1210
  */ async processCheckpointAttestationFromPeer(payloadData, msgId, source) {
1101
- const validationFunc = async ()=>{
1102
- const attestation = CheckpointAttestation.fromBuffer(payloadData);
1103
- const pool = this.mempools.attestationPool;
1104
- const validationResult = await this.validateCheckpointAttestation(source, attestation);
1105
- const isValid = validationResult.result === 'accept';
1106
- const exists = isValid && await pool.hasCheckpointAttestation(attestation);
1107
- let canAdd = true;
1108
- if (isValid && !exists) {
1109
- const slot = attestation.payload.header.slotNumber;
1110
- const { committee } = await this.epochCache.getCommittee(slot);
1111
- const committeeSize = committee?.length ?? 0;
1112
- canAdd = await pool.canAddCheckpointAttestation(attestation, committeeSize);
1113
- }
1114
- this.logger.trace(`Validate propagated checkpoint attestation`, {
1115
- isValid,
1116
- exists,
1117
- canAdd,
1118
- [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toString(),
1119
- [Attributes.P2P_ID]: source.toString()
1120
- });
1121
- if (validationResult.result === 'reject') {
1122
- return {
1123
- result: TopicValidatorResult.Reject
1124
- };
1125
- } else if (validationResult.result === 'ignore' || exists) {
1126
- return {
1127
- result: TopicValidatorResult.Ignore,
1128
- obj: attestation
1129
- };
1130
- } else if (!canAdd) {
1131
- this.logger.warn(`Dropping checkpoint attestation due to per-(slot, proposalId) attestation cap`, {
1132
- slot: attestation.payload.header.slotNumber.toString(),
1133
- archive: attestation.archive.toString(),
1134
- source: source.toString()
1211
+ const { result, obj: attestation } = await this.validateReceivedMessage(()=>{
1212
+ const attestation = this.tryDeserialize(()=>CheckpointAttestation.fromBuffer(payloadData), msgId, source);
1213
+ if (!attestation) {
1214
+ return Promise.resolve({
1215
+ result: TopicValidatorResult.Reject,
1216
+ severity: PeerErrorSeverity.LowToleranceError
1135
1217
  });
1136
- return {
1137
- result: TopicValidatorResult.Ignore,
1138
- obj: attestation
1139
- };
1140
- } else {
1141
- return {
1142
- result: TopicValidatorResult.Accept,
1143
- obj: attestation
1144
- };
1145
1218
  }
1146
- };
1147
- const { result, obj: attestation } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.checkpoint_attestation);
1219
+ return this.validateAndStoreCheckpointAttestation(source, attestation);
1220
+ }, msgId, source, TopicType.checkpoint_attestation);
1148
1221
  if (result !== TopicValidatorResult.Accept || !attestation) {
1149
1222
  return;
1150
1223
  }
1151
- this.logger.debug(`Received checkpoint attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`, {
1224
+ this.logger.verbose(`Received valid checkpoint attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`, {
1152
1225
  p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
1153
1226
  slot: attestation.slotNumber,
1154
1227
  archive: attestation.archive.toString(),
1155
1228
  source: source.toString()
1156
1229
  });
1157
- await this.mempools.attestationPool.addCheckpointAttestations([
1158
- attestation
1159
- ]);
1160
1230
  }
1161
- async processBlockFromPeer(payloadData, msgId, source) {
1162
- const validationFunc = async ()=>{
1163
- const block = BlockProposal.fromBuffer(payloadData);
1164
- const validationResult = await this.validateBlockProposal(source, block);
1165
- const isValid = validationResult.result === 'accept';
1166
- const pool = this.mempools.attestationPool;
1167
- const exists = isValid && await pool.hasBlockProposal(block);
1168
- const canAdd = isValid && await pool.canAddProposal(block);
1169
- this.logger.trace(`Validate propagated block proposal`, {
1170
- isValid,
1171
- exists,
1172
- canAdd,
1173
- [Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
1174
- [Attributes.P2P_ID]: source.toString()
1231
+ /** Validates a checkpoint attestation and adds it to the pool. Penalizes the peer if validation fails. */ async validateAndStoreCheckpointAttestation(peerId, attestation) {
1232
+ const validationResult = await this.checkpointAttestationValidator.validate(attestation);
1233
+ if (validationResult.result === 'reject') {
1234
+ this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
1235
+ return {
1236
+ result: TopicValidatorResult.Reject,
1237
+ severity: validationResult.severity
1238
+ };
1239
+ }
1240
+ if (validationResult.result === 'ignore') {
1241
+ return {
1242
+ result: TopicValidatorResult.Ignore,
1243
+ obj: attestation
1244
+ };
1245
+ }
1246
+ // Try to add the attestation: this handles existence check, cap check, and adding in one call
1247
+ // count is the number of attestations by this signer for this slot (for duplicate detection)
1248
+ const slot = attestation.payload.header.slotNumber;
1249
+ const { added, alreadyExists, count } = await this.mempools.attestationPool.tryAddCheckpointAttestation(attestation);
1250
+ this.logger.trace(`Validate propagated checkpoint attestation`, {
1251
+ added,
1252
+ alreadyExists,
1253
+ count,
1254
+ [Attributes.SLOT_NUMBER]: slot.toString(),
1255
+ [Attributes.P2P_ID]: peerId.toString()
1256
+ });
1257
+ // Exact same attestation received, no need to re-broadcast
1258
+ if (alreadyExists) {
1259
+ return {
1260
+ result: TopicValidatorResult.Ignore,
1261
+ obj: attestation
1262
+ };
1263
+ }
1264
+ // Could not add (cap reached for signer), penalize and do not re-broadcast
1265
+ if (!added) {
1266
+ this.logger.warn(`Rejecting checkpoint attestation due to cap`, {
1267
+ slot: slot.toString(),
1268
+ archive: attestation.archive.toString(),
1269
+ source: peerId.toString(),
1270
+ attester: attestation.getSender()?.toString(),
1271
+ count
1175
1272
  });
1176
- if (validationResult.result === 'reject') {
1177
- return {
1178
- result: TopicValidatorResult.Reject
1179
- };
1180
- } else if (validationResult.result === 'ignore' || exists) {
1181
- return {
1182
- result: TopicValidatorResult.Ignore,
1183
- obj: block
1184
- };
1185
- } else if (!canAdd) {
1186
- this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
1187
- this.logger.warn(`Penalizing peer for block proposal exceeding per-slot cap`, {
1188
- slot: block.slotNumber.toString(),
1189
- archive: block.archive.toString(),
1190
- source: source.toString()
1273
+ return {
1274
+ result: TopicValidatorResult.Reject,
1275
+ severity: PeerErrorSeverity.HighToleranceError
1276
+ };
1277
+ }
1278
+ // Check if this is a duplicate attestation (signer attested to a different proposal at the same slot)
1279
+ // count is the number of attestations by this signer for this slot
1280
+ if (count === 2) {
1281
+ const attester = attestation.getSender();
1282
+ if (attester) {
1283
+ this.logger.warn(`Detected duplicate attestation (equivocation) at slot ${slot}`, {
1284
+ slot: slot.toString(),
1285
+ archive: attestation.archive.toString(),
1286
+ source: peerId.toString(),
1287
+ attester: attester.toString()
1288
+ });
1289
+ this.duplicateAttestationCallback?.({
1290
+ slot,
1291
+ attester
1191
1292
  });
1192
- return {
1193
- result: TopicValidatorResult.Reject
1194
- };
1195
- } else {
1196
- return {
1197
- result: TopicValidatorResult.Accept,
1198
- obj: block
1199
- };
1200
1293
  }
1294
+ }
1295
+ // Attestation was added successfully - accept it so other nodes can also detect the equivocation
1296
+ return {
1297
+ result: TopicValidatorResult.Accept,
1298
+ obj: attestation
1201
1299
  };
1202
- const { result, obj: block } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.block_proposal);
1203
- if (!result || !block) {
1300
+ }
1301
+ async processBlockFromPeer(payloadData, msgId, source) {
1302
+ const { result, obj: block, metadata: { isEquivocated } = {} } = await this.validateReceivedMessage(()=>this.validateAndStoreBlockProposal(source, BlockProposal.fromBuffer(payloadData)), msgId, source, TopicType.block_proposal);
1303
+ // If not accepted or equivocated, return
1304
+ if (result !== TopicValidatorResult.Accept || !block || isEquivocated) {
1204
1305
  return;
1205
1306
  }
1206
1307
  await this.processValidBlockProposal(block, source);
1207
1308
  }
1208
- // REVIEW: callback pattern https://github.com/AztecProtocol/aztec-packages/issues/7963
1309
+ /** 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) {
1310
+ const validationResult = await this.blockProposalValidator.validate(block);
1311
+ if (validationResult.result === 'reject') {
1312
+ this.logger.warn(`Penalizing peer ${peerId} for block proposal validation failure`);
1313
+ return {
1314
+ result: TopicValidatorResult.Reject,
1315
+ severity: validationResult.severity
1316
+ };
1317
+ }
1318
+ if (validationResult.result === 'ignore') {
1319
+ return {
1320
+ result: TopicValidatorResult.Ignore,
1321
+ obj: block
1322
+ };
1323
+ }
1324
+ // Try to add the proposal: this handles existence check, cap check, and adding in one call
1325
+ const { added, alreadyExists, count } = await this.mempools.attestationPool.tryAddBlockProposal(block);
1326
+ const isEquivocated = count !== undefined && count > 1;
1327
+ // Duplicate proposal received, no need to re-broadcast
1328
+ if (alreadyExists) {
1329
+ this.logger.debug(`Ignoring duplicate block proposal received`, {
1330
+ ...block.toBlockInfo(),
1331
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
1332
+ proposer: block.getSender()?.toString(),
1333
+ source: peerId.toString()
1334
+ });
1335
+ return {
1336
+ result: TopicValidatorResult.Ignore,
1337
+ obj: block,
1338
+ metadata: {
1339
+ isEquivocated
1340
+ }
1341
+ };
1342
+ }
1343
+ // Too many blocks received for this slot and index, penalize peer and do not re-broadcast
1344
+ if (!added) {
1345
+ this.logger.warn(`Penalizing peer for block proposal exceeding per-position cap`, {
1346
+ ...block.toBlockInfo(),
1347
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
1348
+ count,
1349
+ proposer: block.getSender()?.toString(),
1350
+ source: peerId.toString()
1351
+ });
1352
+ return {
1353
+ result: TopicValidatorResult.Reject,
1354
+ metadata: {
1355
+ isEquivocated
1356
+ },
1357
+ severity: PeerErrorSeverity.HighToleranceError
1358
+ };
1359
+ }
1360
+ // If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
1361
+ // and do re-broadcast it so other nodes in the network know to slash the proposer
1362
+ if (isEquivocated) {
1363
+ const proposer = block.getSender();
1364
+ this.logger.warn(`Detected duplicate block proposal (equivocation) at slot ${block.slotNumber}`, {
1365
+ ...block.toBlockInfo(),
1366
+ source: peerId.toString(),
1367
+ proposer: proposer?.toString()
1368
+ });
1369
+ // Invoke the duplicate callback on the first duplicate spotted only
1370
+ if (proposer && count === 2) {
1371
+ this.duplicateProposalCallback?.({
1372
+ slot: block.slotNumber,
1373
+ proposer,
1374
+ type: 'block'
1375
+ });
1376
+ }
1377
+ return {
1378
+ result: TopicValidatorResult.Accept,
1379
+ obj: block,
1380
+ metadata: {
1381
+ isEquivocated
1382
+ }
1383
+ };
1384
+ }
1385
+ // Otherwise, we're good to go!
1386
+ return {
1387
+ result: TopicValidatorResult.Accept,
1388
+ obj: block
1389
+ };
1390
+ }
1209
1391
  // REFACTOR(palla): This method should be moved to the p2p_client or to a separate component,
1210
1392
  // should not be here as it does not deal with p2p networking.
1211
1393
  async processValidBlockProposal(block, sender) {
@@ -1215,85 +1397,150 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1215
1397
  source: sender.toString(),
1216
1398
  ...block.toBlockInfo()
1217
1399
  });
1218
- // Attempt to add proposal
1219
- try {
1220
- await this.mempools.attestationPool.addBlockProposal(block);
1221
- } catch (err) {
1222
- // Drop proposals if we hit per-slot cap in the attestation pool; rethrow unknown errors
1223
- if (err instanceof ProposalSlotCapExceededError) {
1224
- this.logger.warn(`Dropping block proposal due to per-slot proposal cap`, {
1225
- slot: String(slot),
1226
- archive: block.archive.toString(),
1227
- error: err.message
1228
- });
1229
- return;
1230
- }
1231
- throw err;
1232
- }
1233
- // Mark the txs in this proposal as non-evictable
1234
- await this.mempools.txPool.markTxsAsNonEvictable(block.txHashes);
1400
+ // Mark the txs in this proposal as protected
1401
+ await this.mempools.txPool.protectTxs(block.txHashes, block.blockHeader);
1235
1402
  // Call the block received callback to validate the proposal.
1236
1403
  // Note: Validators do NOT attest to individual blocks, only to checkpoint proposals.
1237
1404
  const isValid = await this.blockReceivedCallback(block, sender);
1238
1405
  if (!isValid) {
1239
- this.logger.warn(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
1406
+ this.logger.info(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
1240
1407
  }
1241
1408
  }
1242
1409
  /**
1243
1410
  * Handle a gossiped checkpoint proposal.
1244
1411
  * Validates and processes the checkpoint proposal, then triggers the callback for attestation.
1245
1412
  */ async handleGossipedCheckpointProposal(payloadData, msgId, source) {
1246
- // TODO(palla/mbps): This pattern is repeated across multiple message handlers, consider abstracting it.
1247
- const validationFunc = async ()=>{
1248
- const checkpoint = CheckpointProposal.fromBuffer(payloadData);
1249
- const validationResult = await this.validateCheckpointProposal(source, checkpoint);
1250
- const isValid = validationResult.result === 'accept';
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,
1413
+ const { result, obj: checkpoint, metadata: { isEquivocated, processBlock } = {} } = await this.validateReceivedMessage(()=>this.validateAndStoreCheckpointProposal(source, CheckpointProposal.fromBuffer(payloadData)), msgId, source, TopicType.checkpoint_proposal);
1414
+ // If the checkpoint contained a valid last block, we process it even if the checkpoint itself is to be rejected
1415
+ // TODO(palla/mbps): Is this ok? Should we be considering a block from a checkpoint that was equivocated?
1416
+ if (processBlock && checkpoint?.getBlockProposal()) {
1417
+ await this.processValidBlockProposal(checkpoint.getBlockProposal(), source);
1418
+ }
1419
+ if (result !== TopicValidatorResult.Accept || !checkpoint || isEquivocated) {
1420
+ return;
1421
+ }
1422
+ await this.processValidCheckpointProposal(checkpoint.toCore(), source);
1423
+ }
1424
+ /**
1425
+ * Validates a checkpoint proposal. Penalizes peer if validation fails. Adds the checkpoint and
1426
+ * its last block (if present) to the mempool if valid. Triggers equivocation detection on both.
1427
+ */ async validateAndStoreCheckpointProposal(peerId, checkpoint) {
1428
+ const validationResult = await this.checkpointProposalValidator.validate(checkpoint);
1429
+ if (validationResult.result === 'reject') {
1430
+ this.logger.warn(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
1431
+ return {
1432
+ result: TopicValidatorResult.Reject,
1433
+ severity: validationResult.severity
1434
+ };
1435
+ }
1436
+ if (validationResult.result === 'ignore') {
1437
+ return {
1438
+ result: TopicValidatorResult.Ignore,
1439
+ obj: checkpoint
1440
+ };
1441
+ }
1442
+ // Extract and try to add the block proposal first if present
1443
+ const blockProposal = checkpoint.getBlockProposal();
1444
+ let processBlock = false;
1445
+ if (blockProposal) {
1446
+ this.logger.debug(`Validating block proposal from propagated checkpoint`, {
1258
1447
  [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
1259
- [Attributes.P2P_ID]: source.toString()
1448
+ [Attributes.P2P_ID]: peerId.toString()
1260
1449
  });
1261
- if (validationResult.result === 'reject') {
1262
- return {
1263
- result: TopicValidatorResult.Reject
1264
- };
1265
- } else if (validationResult.result === 'ignore' || 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()
1450
+ const blockProposalResult = await this.validateAndStoreBlockProposal(peerId, blockProposal);
1451
+ const { obj, metadata: { isEquivocated } = {} } = blockProposalResult;
1452
+ if (blockProposalResult.result === TopicValidatorResult.Reject || !obj || isEquivocated) {
1453
+ this.logger.debug(`Rejecting checkpoint due to invalid last block proposal`, {
1454
+ [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
1455
+ [Attributes.P2P_ID]: peerId.toString(),
1456
+ isEquivocated,
1457
+ result: blockProposalResult.result
1276
1458
  });
1277
1459
  return {
1278
- result: TopicValidatorResult.Reject
1279
- };
1280
- } else {
1281
- return {
1282
- result: TopicValidatorResult.Accept,
1283
- obj: checkpoint
1460
+ result: TopicValidatorResult.Reject,
1461
+ severity: 'severity' in blockProposalResult ? blockProposalResult.severity : PeerErrorSeverity.MidToleranceError
1284
1462
  };
1463
+ } else if (blockProposalResult.result === TopicValidatorResult.Accept && obj && !isEquivocated) {
1464
+ processBlock = true;
1285
1465
  }
1286
- };
1287
- const { result, obj: checkpoint } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.checkpoint_proposal);
1288
- if (result !== TopicValidatorResult.Accept || !checkpoint) {
1289
- return;
1290
1466
  }
1291
- await this.processValidCheckpointProposal(checkpoint, source);
1467
+ // Try to add the checkpoint proposal core: this handles existence check, cap check, and adding in one call
1468
+ const checkpointCore = checkpoint.toCore();
1469
+ const tryAddResult = await this.mempools.attestationPool.tryAddCheckpointProposal(checkpointCore);
1470
+ const { added, alreadyExists, count } = tryAddResult;
1471
+ const isEquivocated = count !== undefined && count > 1;
1472
+ // Duplicate proposal received, do not re-broadcast
1473
+ if (alreadyExists) {
1474
+ this.logger.debug(`Ignoring duplicate checkpoint proposal received`, {
1475
+ ...checkpoint.toCheckpointInfo(),
1476
+ source: peerId.toString()
1477
+ });
1478
+ return {
1479
+ result: TopicValidatorResult.Ignore,
1480
+ obj: checkpoint,
1481
+ metadata: {
1482
+ isEquivocated,
1483
+ processBlock
1484
+ }
1485
+ };
1486
+ }
1487
+ // Too many checkpoint proposals received for this slot, penalize peer and do not re-broadcast
1488
+ // Note: We still return the checkpoint obj so the lastBlock can be processed if valid
1489
+ if (!added) {
1490
+ this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
1491
+ ...checkpoint.toCheckpointInfo(),
1492
+ count,
1493
+ source: peerId.toString()
1494
+ });
1495
+ return {
1496
+ result: TopicValidatorResult.Reject,
1497
+ obj: checkpoint,
1498
+ metadata: {
1499
+ isEquivocated,
1500
+ processBlock
1501
+ },
1502
+ severity: PeerErrorSeverity.HighToleranceError
1503
+ };
1504
+ }
1505
+ // If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
1506
+ // and do re-broadcast it so other nodes in the network know to slash the proposer
1507
+ if (isEquivocated) {
1508
+ const proposer = checkpoint.getSender();
1509
+ this.logger.warn(`Detected duplicate checkpoint proposal (equivocation) at slot ${checkpoint.slotNumber}`, {
1510
+ ...checkpoint.toCheckpointInfo(),
1511
+ source: peerId.toString(),
1512
+ proposer: proposer?.toString()
1513
+ });
1514
+ // Invoke the duplicate callback on the first duplicate spotted only
1515
+ if (proposer && count === 2) {
1516
+ this.duplicateProposalCallback?.({
1517
+ slot: checkpoint.slotNumber,
1518
+ proposer,
1519
+ type: 'checkpoint'
1520
+ });
1521
+ }
1522
+ return {
1523
+ result: TopicValidatorResult.Accept,
1524
+ obj: checkpoint,
1525
+ metadata: {
1526
+ isEquivocated,
1527
+ processBlock
1528
+ }
1529
+ };
1530
+ }
1531
+ // Otherwise, we're good to go!
1532
+ return {
1533
+ result: TopicValidatorResult.Accept,
1534
+ obj: checkpoint,
1535
+ metadata: {
1536
+ processBlock,
1537
+ isEquivocated
1538
+ }
1539
+ };
1292
1540
  }
1293
1541
  /**
1294
1542
  * 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.
1543
+ * Note: The proposal was already added to the pool by tryAddCheckpointProposal in handleGossipedCheckpointProposal.
1297
1544
  */ async processValidCheckpointProposal(checkpoint, sender) {
1298
1545
  const slot = checkpoint.slotNumber;
1299
1546
  this.logger.verbose(`Received checkpoint proposal for slot ${slot} from external peer ${sender.toString()}.`, {
@@ -1302,33 +1549,13 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1302
1549
  archive: checkpoint.archive.toString(),
1303
1550
  source: sender.toString()
1304
1551
  });
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
- }
1552
+ await this.allNodesCheckpointReceivedCallback(checkpoint, sender);
1326
1553
  // Call the checkpoint received callback with the core version (without lastBlock)
1327
1554
  // to validate and potentially generate attestations
1328
- const attestations = await this.checkpointReceivedCallback(checkpoint.toCore(), sender);
1555
+ const attestations = await this.validatorCheckpointReceivedCallback(checkpoint, sender);
1329
1556
  if (attestations && attestations.length > 0) {
1330
1557
  // If the callback returned attestations, add them to the pool and propagate them
1331
- await this.mempools.attestationPool.addCheckpointAttestations(attestations);
1558
+ await this.mempools.attestationPool.addOwnCheckpointAttestations(attestations);
1332
1559
  for (const attestation of attestations){
1333
1560
  await this.propagate(attestation);
1334
1561
  }
@@ -1445,45 +1672,6 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1445
1672
  return false;
1446
1673
  }
1447
1674
  }
1448
- /**
1449
- * Validates a BLOCK response.
1450
- *
1451
- * If a local copy exists, enforces hash equality. If missing, rejects (no penalty) since the hash cannot be verified.
1452
- * Penalizes on block number mismatch or hash mismatch.
1453
- *
1454
- * @param requestedBlockNumber - The requested block number.
1455
- * @param responseBlock - The block returned by the peer.
1456
- * @param peerId - The peer that returned the block.
1457
- * @returns True if the response is valid, false otherwise.
1458
- */ async validateRequestedBlock(requestedBlockNumber, responseBlock, peerId) {
1459
- try {
1460
- const reqNum = Number(requestedBlockNumber.toString());
1461
- if (responseBlock.number !== reqNum) {
1462
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
1463
- return false;
1464
- }
1465
- const local = await this.archiver.getBlock(BlockNumber(reqNum));
1466
- if (!local) {
1467
- // We are missing the local block; we cannot verify the hash yet. Reject without penalizing.
1468
- // TODO: Consider extending this validator to accept an expected hash or
1469
- // performing quorum-based checks when using P2P syncing prior to L1 sync.
1470
- this.logger.warn(`Local block ${reqNum} not found; rejecting BLOCK response without hash verification`);
1471
- return false;
1472
- }
1473
- const [localHash, respHash] = await Promise.all([
1474
- local.hash(),
1475
- responseBlock.hash()
1476
- ]);
1477
- if (!localHash.equals(respHash)) {
1478
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1479
- return false;
1480
- }
1481
- return true;
1482
- } catch (e) {
1483
- this.logger.warn(`Error validating requested block`, e);
1484
- return false;
1485
- }
1486
- }
1487
1675
  async validateRequestedTx(tx, peerId, txValidator, requested) {
1488
1676
  const penalize = (severity)=>this.peerManager.penalizePeer(peerId, severity);
1489
1677
  if (requested && !requested.has(tx.getTxHash().toString())) {
@@ -1497,33 +1685,11 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1497
1685
  }
1498
1686
  }
1499
1687
  createRequestedTxValidator() {
1500
- return createTxReqRespValidator(this.proofVerifier, {
1688
+ return createTxValidatorForReqResponseReceivedTxs(this.proofVerifier, {
1501
1689
  l1ChainId: this.config.l1ChainId,
1502
1690
  rollupVersion: this.config.rollupVersion
1503
1691
  });
1504
1692
  }
1505
- async validatePropagatedTx(tx, peerId) {
1506
- const currentBlockNumber = await this.archiver.getBlockNumber();
1507
- // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
1508
- const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1509
- const messageValidators = await this.createMessageValidators(currentBlockNumber, nextSlotTimestamp);
1510
- for (const validator of messageValidators){
1511
- const outcome = await this.runValidations(tx, validator);
1512
- if (outcome.allPassed) {
1513
- continue;
1514
- }
1515
- const { name } = outcome.failure;
1516
- let { severity } = outcome.failure;
1517
- // Double spend validator has a special case handler
1518
- if (name === 'doubleSpendValidator') {
1519
- const txBlockNumber = BlockNumber(currentBlockNumber + 1); // tx is expected to be in the next block
1520
- severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
1521
- }
1522
- this.peerManager.penalizePeer(peerId, severity);
1523
- return false;
1524
- }
1525
- return true;
1526
- }
1527
1693
  async getGasFees(blockNumber) {
1528
1694
  if (blockNumber === this.feesCache?.blockNumber) {
1529
1695
  return this.feesCache.gasFees;
@@ -1550,38 +1716,35 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1550
1716
  peerScoring: this.peerManager
1551
1717
  };
1552
1718
  }
1553
- async validate(txs) {
1554
- const currentBlockNumber = await this.archiver.getBlockNumber();
1555
- // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
1556
- const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1557
- const messageValidators = await this.createMessageValidators(currentBlockNumber, nextSlotTimestamp);
1558
- await Promise.all(txs.map(async (tx)=>{
1559
- for (const validator of messageValidators){
1560
- const outcome = await this.runValidations(tx, validator);
1561
- if (!outcome.allPassed) {
1562
- throw new Error('Invalid tx detected', {
1563
- cause: {
1564
- outcome
1565
- }
1566
- });
1567
- }
1568
- }
1719
+ async validateTxsReceivedInBlockProposal(txs) {
1720
+ const validator = createTxValidatorForBlockProposalReceivedTxs(this.proofVerifier, {
1721
+ l1ChainId: this.config.l1ChainId,
1722
+ rollupVersion: this.config.rollupVersion
1723
+ }, this.logger.getBindings());
1724
+ const results = await Promise.all(txs.map(async (tx)=>{
1725
+ const result = await validator.validateTx(tx);
1726
+ return result.result !== 'invalid';
1569
1727
  }));
1728
+ if (results.some((value)=>value === false)) {
1729
+ throw new Error('Invalid tx detected');
1730
+ }
1570
1731
  }
1571
- /**
1572
- * Create message validators for the given block number and timestamp.
1573
- *
1574
- * Each validator is a pair of a validator and a severity.
1575
- * If a validator fails, the peer is penalized with the severity of the validator.
1576
- *
1577
- * @param currentBlockNumber - The current synced block number.
1578
- * @param nextSlotTimestamp - The timestamp of the next slot (used to validate txs are not expired).
1579
- * @returns The message validators.
1580
- */ async createMessageValidators(currentBlockNumber, nextSlotTimestamp) {
1732
+ /** Creates the first stage (fast) validators for gossiped transactions. */ async createFirstStageMessageValidators(currentBlockNumber, nextSlotTimestamp) {
1581
1733
  const gasFees = await this.getGasFees(currentBlockNumber);
1582
- const allowedInSetup = this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
1583
- const blockNumberInWhichTheTxIsConsideredToBeIncluded = BlockNumber(currentBlockNumber + 1);
1584
- 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());
1734
+ const allowedInSetup = [
1735
+ ...await getDefaultAllowedSetupFunctions(),
1736
+ ...this.config.txPublicSetupAllowListExtend ?? []
1737
+ ];
1738
+ const blockNumber = BlockNumber(currentBlockNumber + 1);
1739
+ const l1Constants = await this.archiver.getL1Constants();
1740
+ return createFirstStageTxValidationsForGossipedTransactions(nextSlotTimestamp, blockNumber, this.worldStateSynchronizer, gasFees, this.config.l1ChainId, this.config.rollupVersion, protocolContractsHash, this.archiver, !this.config.disableTransactions, allowedInSetup, this.logger.getBindings(), {
1741
+ rollupManaLimit: l1Constants.rollupManaLimit,
1742
+ maxBlockL2Gas: this.config.validateMaxL2BlockGas,
1743
+ maxBlockDAGas: this.config.validateMaxDABlockGas
1744
+ });
1745
+ }
1746
+ /** Creates the second stage (expensive proof verification) validators for gossiped transactions. */ createSecondStageMessageValidators() {
1747
+ return createSecondStageTxValidationsForGossipedTransactions(this.proofVerifier, this.logger.getBindings());
1585
1748
  }
1586
1749
  /**
1587
1750
  * Run validations on a tx.
@@ -1599,8 +1762,10 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1599
1762
  });
1600
1763
  // A promise that resolves when all validations have been run
1601
1764
  const allValidations = await Promise.all(validationPromises);
1602
- const failed = allValidations.find((x)=>!x.isValid);
1603
- if (failed) {
1765
+ const failures = allValidations.filter((x)=>!x.isValid);
1766
+ if (failures.length > 0) {
1767
+ // Pick the most severe failure (lowest tolerance = harshest penalty)
1768
+ const failed = maxBy(failures, (f)=>PeerErrorSeverityByHarshness.indexOf(f.severity));
1604
1769
  return {
1605
1770
  allPassed: false,
1606
1771
  failure: {
@@ -1647,45 +1812,6 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1647
1812
  }
1648
1813
  return PeerErrorSeverity.HighToleranceError;
1649
1814
  }
1650
- /**
1651
- * Validate a checkpoint attestation.
1652
- *
1653
- * @param attestation - The checkpoint attestation to validate.
1654
- * @returns True if the checkpoint attestation is valid, false otherwise.
1655
- */ async validateCheckpointAttestation(peerId, attestation) {
1656
- const result = await this.checkpointAttestationValidator.validate(attestation);
1657
- if (result.result === 'reject') {
1658
- this.logger.debug(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
1659
- this.peerManager.penalizePeer(peerId, result.severity);
1660
- }
1661
- return result;
1662
- }
1663
- /**
1664
- * Validate a block proposal.
1665
- *
1666
- * @param block - The block proposal to validate.
1667
- * @returns True if the block proposal is valid, false otherwise.
1668
- */ async validateBlockProposal(peerId, block) {
1669
- const result = await this.blockProposalValidator.validate(block);
1670
- if (result.result === 'reject') {
1671
- this.logger.debug(`Penalizing peer ${peerId} for block proposal validation failure`);
1672
- this.peerManager.penalizePeer(peerId, result.severity);
1673
- }
1674
- return result;
1675
- }
1676
- /**
1677
- * Validate a checkpoint proposal.
1678
- *
1679
- * @param checkpoint - The checkpoint proposal to validate.
1680
- * @returns True if the checkpoint proposal is valid, false otherwise.
1681
- */ async validateCheckpointProposal(peerId, checkpoint) {
1682
- const result = await this.checkpointProposalValidator.validate(checkpoint);
1683
- if (result.result === 'reject') {
1684
- this.logger.debug(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
1685
- this.peerManager.penalizePeer(peerId, result.severity);
1686
- }
1687
- return result;
1688
- }
1689
1815
  getPeerScore(peerId) {
1690
1816
  return this.node.services.pubsub.score.score(peerId.toString());
1691
1817
  }