@aztec/p2p 0.0.1-commit.e558bd1c → 0.0.1-commit.e588bc7e5

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 (431) hide show
  1. package/README.md +129 -3
  2. package/dest/client/factory.d.ts +9 -9
  3. package/dest/client/factory.d.ts.map +1 -1
  4. package/dest/client/factory.js +52 -14
  5. package/dest/client/interface.d.ts +47 -34
  6. package/dest/client/interface.d.ts.map +1 -1
  7. package/dest/client/p2p_client.d.ts +39 -51
  8. package/dest/client/p2p_client.d.ts.map +1 -1
  9. package/dest/client/p2p_client.js +164 -224
  10. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +20 -10
  11. package/dest/config.d.ts +54 -17
  12. package/dest/config.d.ts.map +1 -1
  13. package/dest/config.js +102 -38
  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 +21 -12
  24. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  25. package/dest/mem_pools/attestation_pool/attestation_pool.js +75 -40
  26. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  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 +57 -57
  29. package/dest/mem_pools/attestation_pool/index.d.ts +2 -2
  30. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  31. package/dest/mem_pools/attestation_pool/index.js +1 -1
  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 +2 -2
  36. package/dest/mem_pools/index.d.ts.map +1 -1
  37. package/dest/mem_pools/instrumentation.d.ts +4 -2
  38. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  39. package/dest/mem_pools/instrumentation.js +16 -14
  40. package/dest/mem_pools/interface.d.ts +3 -3
  41. package/dest/mem_pools/interface.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
  43. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  44. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
  45. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  46. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  47. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  48. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  49. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  50. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +7 -3
  51. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  52. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  53. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
  54. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
  55. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  56. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
  57. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +54 -5
  58. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  59. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  60. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +7 -5
  61. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +7 -5
  62. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  63. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  64. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +14 -6
  65. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  66. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  67. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +16 -4
  68. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  69. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  70. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +3 -3
  71. package/dest/mem_pools/tx_pool_v2/index.d.ts +3 -2
  72. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  73. package/dest/mem_pools/tx_pool_v2/index.js +2 -1
  74. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  75. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  76. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  77. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +30 -12
  78. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  79. package/dest/mem_pools/tx_pool_v2/interfaces.js +5 -1
  80. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +78 -15
  81. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  82. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +144 -19
  83. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +12 -3
  84. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  85. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +50 -45
  86. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +12 -5
  87. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  88. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +17 -6
  89. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +14 -5
  90. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  91. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +364 -189
  92. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -1
  93. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  94. package/dest/msg_validators/attestation_validator/attestation_validator.js +5 -4
  95. package/dest/msg_validators/clock_tolerance.d.ts +1 -1
  96. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
  97. package/dest/msg_validators/clock_tolerance.js +4 -3
  98. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +6 -4
  99. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  100. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
  101. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +6 -4
  102. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  103. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
  104. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -8
  105. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  106. package/dest/msg_validators/proposal_validator/proposal_validator.js +53 -41
  107. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
  108. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  109. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  110. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  111. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  112. package/dest/msg_validators/tx_validator/allowed_public_setup.js +24 -20
  113. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  114. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  115. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  116. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
  117. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  118. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  119. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
  120. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
  121. package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
  122. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  123. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  124. package/dest/msg_validators/tx_validator/data_validator.js +35 -2
  125. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
  126. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  127. package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
  128. package/dest/msg_validators/tx_validator/factory.d.ts +133 -6
  129. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  130. package/dest/msg_validators/tx_validator/factory.js +247 -60
  131. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  132. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  133. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  134. package/dest/msg_validators/tx_validator/gas_validator.d.ts +67 -3
  135. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  136. package/dest/msg_validators/tx_validator/gas_validator.js +104 -37
  137. package/dest/msg_validators/tx_validator/index.d.ts +3 -1
  138. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  139. package/dest/msg_validators/tx_validator/index.js +2 -0
  140. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  141. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  142. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  143. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  144. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  145. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  146. package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
  147. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  148. package/dest/msg_validators/tx_validator/phases_validator.js +72 -24
  149. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
  150. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  151. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  152. package/dest/services/dummy_service.d.ts +12 -6
  153. package/dest/services/dummy_service.d.ts.map +1 -1
  154. package/dest/services/dummy_service.js +12 -5
  155. package/dest/services/encoding.d.ts +7 -3
  156. package/dest/services/encoding.d.ts.map +1 -1
  157. package/dest/services/encoding.js +18 -11
  158. package/dest/services/gossipsub/index.d.ts +3 -0
  159. package/dest/services/gossipsub/index.d.ts.map +1 -0
  160. package/dest/services/gossipsub/index.js +2 -0
  161. package/dest/services/gossipsub/scoring.d.ts +21 -3
  162. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  163. package/dest/services/gossipsub/scoring.js +24 -7
  164. package/dest/services/gossipsub/topic_score_params.d.ts +173 -0
  165. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  166. package/dest/services/gossipsub/topic_score_params.js +346 -0
  167. package/dest/services/libp2p/libp2p_service.d.ts +37 -23
  168. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  169. package/dest/services/libp2p/libp2p_service.js +291 -202
  170. package/dest/services/peer-manager/metrics.d.ts +3 -1
  171. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  172. package/dest/services/peer-manager/metrics.js +6 -0
  173. package/dest/services/peer-manager/peer_manager.d.ts +6 -2
  174. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  175. package/dest/services/peer-manager/peer_manager.js +24 -9
  176. package/dest/services/peer-manager/peer_scoring.d.ts +5 -2
  177. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  178. package/dest/services/peer-manager/peer_scoring.js +53 -12
  179. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +12 -8
  180. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  181. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +83 -106
  182. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +4 -7
  183. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  184. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +11 -13
  185. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  186. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +31 -46
  187. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
  188. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  189. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
  190. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
  191. package/dest/services/reqresp/interface.d.ts +10 -1
  192. package/dest/services/reqresp/interface.d.ts.map +1 -1
  193. package/dest/services/reqresp/interface.js +15 -1
  194. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +3 -3
  195. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  196. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +7 -1
  197. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  198. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +15 -0
  199. package/dest/services/reqresp/protocols/tx.d.ts +7 -1
  200. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  201. package/dest/services/reqresp/protocols/tx.js +20 -0
  202. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
  203. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  204. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
  205. package/dest/services/reqresp/reqresp.d.ts +1 -1
  206. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  207. package/dest/services/reqresp/reqresp.js +30 -14
  208. package/dest/services/service.d.ts +26 -4
  209. package/dest/services/service.d.ts.map +1 -1
  210. package/dest/services/tx_collection/config.d.ts +19 -1
  211. package/dest/services/tx_collection/config.d.ts.map +1 -1
  212. package/dest/services/tx_collection/config.js +46 -0
  213. package/dest/services/tx_collection/fast_tx_collection.d.ts +3 -4
  214. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  215. package/dest/services/tx_collection/fast_tx_collection.js +80 -76
  216. package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
  217. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  218. package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
  219. package/dest/services/tx_collection/file_store_tx_source.d.ts +38 -0
  220. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  221. package/dest/services/tx_collection/file_store_tx_source.js +100 -0
  222. package/dest/services/tx_collection/index.d.ts +2 -1
  223. package/dest/services/tx_collection/index.d.ts.map +1 -1
  224. package/dest/services/tx_collection/index.js +1 -0
  225. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  226. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  227. package/dest/services/tx_collection/instrumentation.js +2 -1
  228. package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -7
  229. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  230. package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
  231. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  232. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  233. package/dest/services/tx_collection/request_tracker.js +84 -0
  234. package/dest/services/tx_collection/slow_tx_collection.d.ts +7 -3
  235. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  236. package/dest/services/tx_collection/slow_tx_collection.js +60 -26
  237. package/dest/services/tx_collection/tx_collection.d.ts +23 -13
  238. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  239. package/dest/services/tx_collection/tx_collection.js +75 -3
  240. package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
  241. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  242. package/dest/services/tx_collection/tx_collection_sink.js +26 -29
  243. package/dest/services/tx_collection/tx_source.d.ts +13 -7
  244. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  245. package/dest/services/tx_collection/tx_source.js +26 -7
  246. package/dest/services/tx_file_store/config.d.ts +1 -3
  247. package/dest/services/tx_file_store/config.d.ts.map +1 -1
  248. package/dest/services/tx_file_store/config.js +0 -4
  249. package/dest/services/tx_file_store/tx_file_store.d.ts +4 -3
  250. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  251. package/dest/services/tx_file_store/tx_file_store.js +9 -6
  252. package/dest/services/tx_provider.d.ts +4 -4
  253. package/dest/services/tx_provider.d.ts.map +1 -1
  254. package/dest/services/tx_provider.js +9 -8
  255. package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
  256. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  257. package/dest/test-helpers/make-test-p2p-clients.js +1 -2
  258. package/dest/test-helpers/mock-pubsub.d.ts +30 -4
  259. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  260. package/dest/test-helpers/mock-pubsub.js +105 -4
  261. package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
  262. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  263. package/dest/test-helpers/reqresp-nodes.js +4 -3
  264. package/dest/test-helpers/testbench-utils.d.ts +35 -24
  265. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  266. package/dest/test-helpers/testbench-utils.js +124 -38
  267. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  268. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  269. package/dest/testbench/p2p_client_testbench_worker.js +57 -27
  270. package/dest/testbench/worker_client_manager.d.ts +3 -1
  271. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  272. package/dest/testbench/worker_client_manager.js +6 -3
  273. package/dest/util.d.ts +3 -3
  274. package/dest/util.d.ts.map +1 -1
  275. package/package.json +14 -14
  276. package/src/client/factory.ts +102 -25
  277. package/src/client/interface.ts +52 -34
  278. package/src/client/p2p_client.ts +190 -266
  279. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +33 -14
  280. package/src/config.ts +158 -44
  281. package/src/errors/p2p-service.error.ts +11 -0
  282. package/src/errors/tx-pool.error.ts +12 -0
  283. package/src/index.ts +1 -1
  284. package/src/mem_pools/attestation_pool/attestation_pool.ts +104 -50
  285. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +61 -57
  286. package/src/mem_pools/attestation_pool/index.ts +3 -3
  287. package/src/mem_pools/attestation_pool/mocks.ts +2 -1
  288. package/src/mem_pools/index.ts +1 -1
  289. package/src/mem_pools/instrumentation.ts +17 -13
  290. package/src/mem_pools/interface.ts +2 -2
  291. package/src/mem_pools/tx_pool_v2/README.md +85 -11
  292. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
  293. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  294. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +7 -3
  295. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
  296. package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
  297. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +59 -4
  298. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
  299. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
  300. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -9
  301. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +33 -6
  302. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +4 -3
  303. package/src/mem_pools/tx_pool_v2/index.ts +2 -1
  304. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  305. package/src/mem_pools/tx_pool_v2/interfaces.ts +32 -12
  306. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +209 -27
  307. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +58 -45
  308. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +34 -8
  309. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +410 -187
  310. package/src/msg_validators/attestation_validator/README.md +49 -0
  311. package/src/msg_validators/attestation_validator/attestation_validator.ts +5 -4
  312. package/src/msg_validators/clock_tolerance.ts +4 -3
  313. package/src/msg_validators/proposal_validator/README.md +123 -0
  314. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +14 -4
  315. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +20 -7
  316. package/src/msg_validators/proposal_validator/proposal_validator.ts +69 -45
  317. package/src/msg_validators/tx_validator/README.md +119 -0
  318. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
  319. package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
  320. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  321. package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
  322. package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
  323. package/src/msg_validators/tx_validator/data_validator.ts +42 -1
  324. package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
  325. package/src/msg_validators/tx_validator/factory.ts +394 -78
  326. package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
  327. package/src/msg_validators/tx_validator/gas_validator.ts +123 -27
  328. package/src/msg_validators/tx_validator/index.ts +2 -0
  329. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  330. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  331. package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
  332. package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
  333. package/src/services/dummy_service.ts +18 -7
  334. package/src/services/encoding.ts +18 -10
  335. package/src/services/gossipsub/README.md +641 -0
  336. package/src/services/gossipsub/index.ts +2 -0
  337. package/src/services/gossipsub/scoring.ts +29 -5
  338. package/src/services/gossipsub/topic_score_params.ts +487 -0
  339. package/src/services/libp2p/libp2p_service.ts +307 -229
  340. package/src/services/peer-manager/metrics.ts +7 -0
  341. package/src/services/peer-manager/peer_manager.ts +28 -9
  342. package/src/services/peer-manager/peer_scoring.ts +46 -5
  343. package/src/services/reqresp/README.md +229 -0
  344. package/src/services/reqresp/batch-tx-requester/README.md +46 -7
  345. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +79 -112
  346. package/src/services/reqresp/batch-tx-requester/interface.ts +3 -6
  347. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +30 -71
  348. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
  349. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
  350. package/src/services/reqresp/interface.ts +26 -1
  351. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +2 -2
  352. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +17 -0
  353. package/src/services/reqresp/protocols/tx.ts +22 -0
  354. package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
  355. package/src/services/reqresp/reqresp.ts +35 -15
  356. package/src/services/service.ts +37 -3
  357. package/src/services/tx_collection/config.ts +68 -0
  358. package/src/services/tx_collection/fast_tx_collection.ts +83 -76
  359. package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
  360. package/src/services/tx_collection/file_store_tx_source.ts +129 -0
  361. package/src/services/tx_collection/index.ts +1 -0
  362. package/src/services/tx_collection/instrumentation.ts +7 -1
  363. package/src/services/tx_collection/proposal_tx_collector.ts +9 -13
  364. package/src/services/tx_collection/request_tracker.ts +127 -0
  365. package/src/services/tx_collection/slow_tx_collection.ts +66 -33
  366. package/src/services/tx_collection/tx_collection.ts +114 -19
  367. package/src/services/tx_collection/tx_collection_sink.ts +30 -34
  368. package/src/services/tx_collection/tx_source.ts +28 -8
  369. package/src/services/tx_file_store/config.ts +0 -6
  370. package/src/services/tx_file_store/tx_file_store.ts +10 -8
  371. package/src/services/tx_provider.ts +10 -9
  372. package/src/test-helpers/make-test-p2p-clients.ts +4 -6
  373. package/src/test-helpers/mock-pubsub.ts +146 -9
  374. package/src/test-helpers/reqresp-nodes.ts +5 -7
  375. package/src/test-helpers/testbench-utils.ts +146 -43
  376. package/src/testbench/p2p_client_testbench_worker.ts +63 -30
  377. package/src/testbench/worker_client_manager.ts +13 -6
  378. package/src/util.ts +8 -2
  379. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
  380. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
  381. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
  382. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
  383. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
  384. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
  385. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
  386. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
  387. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
  388. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
  389. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
  390. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
  391. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
  392. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
  393. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
  394. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
  395. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
  396. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
  397. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
  398. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
  399. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
  400. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
  401. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
  402. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
  403. package/dest/mem_pools/tx_pool/index.d.ts +0 -3
  404. package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
  405. package/dest/mem_pools/tx_pool/index.js +0 -2
  406. package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
  407. package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
  408. package/dest/mem_pools/tx_pool/priority.js +0 -15
  409. package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
  410. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
  411. package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
  412. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
  413. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
  414. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
  415. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
  416. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  417. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
  418. package/src/mem_pools/tx_pool/README.md +0 -270
  419. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
  420. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
  421. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
  422. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
  423. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
  424. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
  425. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
  426. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
  427. package/src/mem_pools/tx_pool/index.ts +0 -2
  428. package/src/mem_pools/tx_pool/priority.ts +0 -20
  429. package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
  430. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
  431. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
@@ -1,6 +1,6 @@
1
1
  import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
2
  import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
3
- import { randomInt } from '@aztec/foundation/crypto/random';
3
+ import { maxBy } from '@aztec/foundation/collection';
4
4
  import { Fr } from '@aztec/foundation/curves/bn254';
5
5
  import { type Logger, createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
6
6
  import { RunningPromise } from '@aztec/foundation/running-promise';
@@ -17,13 +17,12 @@ import {
17
17
  CheckpointProposal,
18
18
  type CheckpointProposalCore,
19
19
  type Gossipable,
20
- P2PClientType,
21
20
  P2PMessage,
22
- type ValidationResult as P2PValidationResult,
23
21
  PeerErrorSeverity,
22
+ PeerErrorSeverityByHarshness,
24
23
  TopicType,
25
24
  createTopicString,
26
- getTopicsForClientAndConfig,
25
+ getTopicsForConfig,
27
26
  metricsTopicStrToLabels,
28
27
  } from '@aztec/stdlib/p2p';
29
28
  import { MerkleTreeId } from '@aztec/stdlib/trees';
@@ -45,7 +44,7 @@ import {
45
44
  type GossipsubMessage,
46
45
  gossipsub,
47
46
  } from '@chainsafe/libp2p-gossipsub';
48
- import { createPeerScoreParams, createTopicScoreParams } from '@chainsafe/libp2p-gossipsub/score';
47
+ import { createPeerScoreParams } from '@chainsafe/libp2p-gossipsub/score';
49
48
  import { SignaturePolicy } from '@chainsafe/libp2p-gossipsub/types';
50
49
  import { noise } from '@chainsafe/libp2p-noise';
51
50
  import { yamux } from '@chainsafe/libp2p-yamux';
@@ -59,6 +58,7 @@ import { ENR } from '@nethermindeth/enr';
59
58
  import { createLibp2p } from 'libp2p';
60
59
 
61
60
  import type { P2PConfig } from '../../config.js';
61
+ import { CheckpointProposalReceivedCallbackNotRegisteredError } from '../../errors/p2p-service.error.js';
62
62
  import type { MemPools } from '../../mem_pools/interface.js';
63
63
  import {
64
64
  BlockProposalValidator,
@@ -70,9 +70,11 @@ import {
70
70
  } from '../../msg_validators/index.js';
71
71
  import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
72
72
  import {
73
- type MessageValidator,
74
- createTxMessageValidators,
75
- createTxReqRespValidator,
73
+ type TransactionValidator,
74
+ createFirstStageTxValidationsForGossipedTransactions,
75
+ createSecondStageTxValidationsForGossipedTransactions,
76
+ createTxValidatorForBlockProposalReceivedTxs,
77
+ createTxValidatorForReqResponseReceivedTxs,
76
78
  } from '../../msg_validators/tx_validator/factory.js';
77
79
  import { GossipSubEvent } from '../../types/index.js';
78
80
  import { type PubSubLibp2p, convertToMultiaddr } from '../../util.js';
@@ -80,13 +82,17 @@ import { getVersions } from '../../versioning.js';
80
82
  import { AztecDatastore } from '../data_store.js';
81
83
  import { DiscV5Service } from '../discv5/discV5_service.js';
82
84
  import { SnappyTransform, fastMsgIdFn, getMsgIdFn, msgIdToStrFn } from '../encoding.js';
83
- import { gossipScoreThresholds } from '../gossipsub/scoring.js';
85
+ import { APP_SPECIFIC_WEIGHT, gossipScoreThresholds } from '../gossipsub/scoring.js';
86
+ import { createAllTopicScoreParams } from '../gossipsub/topic_score_params.js';
84
87
  import type { PeerManagerInterface } from '../peer-manager/interface.js';
85
88
  import { PeerManager } from '../peer-manager/peer_manager.js';
86
89
  import { PeerScoring } from '../peer-manager/peer_scoring.js';
87
90
  import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
88
91
  import type { P2PReqRespConfig } from '../reqresp/config.js';
89
92
  import {
93
+ AuthRequest,
94
+ BlockTxsRequest,
95
+ BlockTxsResponse,
90
96
  DEFAULT_SUB_PROTOCOL_VALIDATORS,
91
97
  type ReqRespInterface,
92
98
  type ReqRespResponse,
@@ -94,14 +100,9 @@ import {
94
100
  type ReqRespSubProtocolHandler,
95
101
  type ReqRespSubProtocolHandlers,
96
102
  type ReqRespSubProtocolValidators,
103
+ StatusMessage,
97
104
  type SubProtocolMap,
98
105
  ValidationError,
99
- } from '../reqresp/index.js';
100
- import {
101
- AuthRequest,
102
- BlockTxsRequest,
103
- BlockTxsResponse,
104
- StatusMessage,
105
106
  pingHandler,
106
107
  reqGoodbyeHandler,
107
108
  reqRespBlockHandler,
@@ -113,6 +114,7 @@ import { ReqResp } from '../reqresp/reqresp.js';
113
114
  import type {
114
115
  P2PBlockReceivedCallback,
115
116
  P2PCheckpointReceivedCallback,
117
+ P2PDuplicateAttestationCallback,
116
118
  P2PService,
117
119
  PeerDiscoveryService,
118
120
  } from '../service.js';
@@ -129,12 +131,12 @@ type ValidationOutcome = { allPassed: true } | { allPassed: false; failure: Vali
129
131
  // REFACTOR: Unify with the type above
130
132
  type ReceivedMessageValidationResult<T, M = undefined> =
131
133
  | { obj: T; result: Exclude<TopicValidatorResult, TopicValidatorResult.Reject>; metadata?: M }
132
- | { obj?: T; result: TopicValidatorResult.Reject; metadata?: M };
134
+ | { obj?: T; result: TopicValidatorResult.Reject; metadata?: M; severity: PeerErrorSeverity };
133
135
 
134
136
  /**
135
137
  * Lib P2P implementation of the P2PService interface.
136
138
  */
137
- export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends WithTracer implements P2PService {
139
+ export class LibP2PService extends WithTracer implements P2PService {
138
140
  private discoveryRunningPromise?: RunningPromise;
139
141
  private msgIdSeenValidators: Record<TopicType, MessageSeenValidator> = {} as Record<TopicType, MessageSeenValidator>;
140
142
 
@@ -155,6 +157,9 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
155
157
  type: 'checkpoint' | 'block';
156
158
  }) => void;
157
159
 
160
+ /** Callback invoked when a duplicate attestation is detected (triggers slashing). */
161
+ private duplicateAttestationCallback?: P2PDuplicateAttestationCallback;
162
+
158
163
  /**
159
164
  * Callback for when a block is received from a peer.
160
165
  * @param block - The block received from the peer.
@@ -167,7 +172,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
167
172
  * @param checkpoint - The checkpoint proposal received from the peer.
168
173
  * @returns The attestations for the checkpoint, if any.
169
174
  */
170
- private checkpointReceivedCallback: P2PCheckpointReceivedCallback;
175
+ private allNodesCheckpointReceivedCallback: P2PCheckpointReceivedCallback;
176
+ /**
177
+ * Callback for when a checkpoint proposal is received - specifically for validators - from a peer.
178
+ * @param checkpoint - The checkpoint proposal received from the peer.
179
+ * @returns The attestations for the checkpoint, if any.
180
+ */
181
+ private validatorCheckpointReceivedCallback: P2PCheckpointReceivedCallback;
171
182
 
172
183
  private gossipSubEventHandler: (e: CustomEvent<GossipsubMessage>) => void;
173
184
 
@@ -178,7 +189,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
178
189
  protected logger: Logger;
179
190
 
180
191
  constructor(
181
- private clientType: T,
182
192
  private config: P2PConfig,
183
193
  protected node: PubSubLibp2p,
184
194
  private peerDiscoveryService: PeerDiscoveryService,
@@ -220,10 +230,12 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
220
230
  this.protocolVersion,
221
231
  );
222
232
 
223
- this.blockProposalValidator = new BlockProposalValidator(epochCache, { txsPermitted: !config.disableTransactions });
224
- this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, {
233
+ const proposalValidatorOpts = {
225
234
  txsPermitted: !config.disableTransactions,
226
- });
235
+ maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
236
+ };
237
+ this.blockProposalValidator = new BlockProposalValidator(epochCache, proposalValidatorOpts);
238
+ this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, proposalValidatorOpts);
227
239
  this.checkpointAttestationValidator = config.fishermanMode
228
240
  ? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry)
229
241
  : new CheckpointAttestationValidator(epochCache);
@@ -231,19 +243,22 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
231
243
  this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
232
244
 
233
245
  this.blockReceivedCallback = async (block: BlockProposal): Promise<boolean> => {
234
- this.logger.debug(
235
- `Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber} from peer.`,
246
+ this.logger.warn(
247
+ `Handler for block received not yet registered on P2P service. Received block ${block.blockNumber} for slot ${block.slotNumber} from peer.`,
236
248
  { p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier() },
237
249
  );
238
- return false;
250
+ return true;
239
251
  };
240
252
 
241
- this.checkpointReceivedCallback = (
242
- checkpoint: CheckpointProposalCore,
253
+ this.allNodesCheckpointReceivedCallback = (
254
+ _checkpoint: CheckpointProposalCore,
255
+ ): Promise<CheckpointAttestation[] | undefined> => {
256
+ throw new CheckpointProposalReceivedCallbackNotRegisteredError();
257
+ };
258
+
259
+ this.validatorCheckpointReceivedCallback = (
260
+ _checkpoint: CheckpointProposalCore,
243
261
  ): Promise<CheckpointAttestation[] | undefined> => {
244
- this.logger.debug(
245
- `Handler not yet registered: Checkpoint received callback not set. Received checkpoint for slot ${checkpoint.slotNumber} from peer.`,
246
- );
247
262
  return Promise.resolve(undefined);
248
263
  };
249
264
  }
@@ -258,8 +273,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
258
273
  * @param txPool - The transaction pool to be accessed by the service.
259
274
  * @returns The new service.
260
275
  */
261
- public static async new<T extends P2PClientType>(
262
- clientType: T,
276
+ public static async new(
263
277
  config: P2PConfig,
264
278
  peerId: PeerId,
265
279
  deps: {
@@ -311,11 +325,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
311
325
  const versions = getVersions(config);
312
326
  const protocolVersion = compressComponentVersions(versions);
313
327
 
314
- const txTopic = createTopicString(TopicType.tx, protocolVersion);
315
- const blockProposalTopic = createTopicString(TopicType.block_proposal, protocolVersion);
316
- const checkpointProposalTopic = createTopicString(TopicType.checkpoint_proposal, protocolVersion);
317
- const checkpointAttestationTopic = createTopicString(TopicType.checkpoint_attestation, protocolVersion);
318
-
319
328
  const preferredPeersEnrs: ENR[] = config.preferredPeers.map(enr => ENR.decodeTxt(enr));
320
329
  const directPeers = (
321
330
  await Promise.all(
@@ -335,6 +344,16 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
335
344
 
336
345
  const announceTcpMultiaddr = config.p2pIp ? [convertToMultiaddr(config.p2pIp, p2pPort, 'tcp')] : [];
337
346
 
347
+ // Create dynamic topic score params based on network configuration
348
+ const l1Constants = epochCache.getL1Constants();
349
+ const topicScoreParams = createAllTopicScoreParams(protocolVersion, {
350
+ slotDurationMs: l1Constants.slotDuration * 1000,
351
+ heartbeatIntervalMs: config.gossipsubInterval,
352
+ targetCommitteeSize: l1Constants.targetCommitteeSize,
353
+ blockDurationMs: config.blockDurationMs,
354
+ expectedBlockProposalsPerSlot: config.expectedBlockProposalsPerSlot,
355
+ });
356
+
338
357
  const node = await createLibp2p({
339
358
  start: false,
340
359
  peerId,
@@ -430,28 +449,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
430
449
  scoreParams: createPeerScoreParams({
431
450
  // IPColocation factor can be disabled for local testing - default to -5
432
451
  IPColocationFactorWeight: config.debugDisableColocationPenalty ? 0 : -5.0,
433
- topics: {
434
- [txTopic]: createTopicScoreParams({
435
- topicWeight: 1,
436
- invalidMessageDeliveriesWeight: -20,
437
- invalidMessageDeliveriesDecay: 0.5,
438
- }),
439
- [blockProposalTopic]: createTopicScoreParams({
440
- topicWeight: 1,
441
- invalidMessageDeliveriesWeight: -20,
442
- invalidMessageDeliveriesDecay: 0.5,
443
- }),
444
- [checkpointProposalTopic]: createTopicScoreParams({
445
- topicWeight: 1,
446
- invalidMessageDeliveriesWeight: -20,
447
- invalidMessageDeliveriesDecay: 0.5,
448
- }),
449
- [checkpointAttestationTopic]: createTopicScoreParams({
450
- topicWeight: 1,
451
- invalidMessageDeliveriesWeight: -20,
452
- invalidMessageDeliveriesDecay: 0.5,
453
- }),
454
- },
452
+ topics: topicScoreParams,
455
453
  }),
456
454
  }) as (components: GossipSubComponents) => GossipSub,
457
455
  components: (components: { connectionManager: ConnectionManager }) => ({
@@ -477,13 +475,16 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
477
475
  epochCache,
478
476
  );
479
477
 
480
- // Update gossipsub score params
481
- node.services.pubsub.score.params.appSpecificWeight = 10;
478
+ // Configure application-specific scoring for gossipsub.
479
+ // The weight scales app score to align with gossipsub thresholds:
480
+ // - Disconnect (-50) × 10 = -500 = gossipThreshold (stops receiving gossip)
481
+ // - Ban (-100) × 10 = -1000 = publishThreshold (cannot publish)
482
+ // Note: positive topic scores can offset penalties, so alignment is best-effort.
483
+ node.services.pubsub.score.params.appSpecificWeight = APP_SPECIFIC_WEIGHT;
482
484
  node.services.pubsub.score.params.appSpecificScore = (peerId: string) =>
483
485
  peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
484
486
 
485
487
  return new LibP2PService(
486
- clientType,
487
488
  config,
488
489
  node,
489
490
  peerDiscoveryService,
@@ -557,7 +558,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
557
558
  await this.node.start();
558
559
 
559
560
  // Subscribe to standard GossipSub topics by default
560
- for (const topic of getTopicsForClientAndConfig(this.clientType, this.config.disableTransactions)) {
561
+ for (const topic of getTopicsForConfig(this.config.disableTransactions)) {
561
562
  this.subscribeToTopic(this.topicStrings[topic]);
562
563
  }
563
564
 
@@ -623,6 +624,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
623
624
  return this.peerManager.getPeers(includePending);
624
625
  }
625
626
 
627
+ public getGossipMeshPeerCount(topicType: TopicType): number {
628
+ return this.node.services.pubsub.getMeshPeers(this.topicStrings[topicType]).length;
629
+ }
630
+
626
631
  private handleGossipSubEvent(e: CustomEvent<GossipsubMessage>) {
627
632
  this.logger.trace(`Received PUBSUB message.`);
628
633
 
@@ -671,8 +676,16 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
671
676
  this.blockReceivedCallback = callback;
672
677
  }
673
678
 
674
- public registerCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
675
- this.checkpointReceivedCallback = callback;
679
+ public registerValidatorCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
680
+ this.validatorCheckpointReceivedCallback = callback;
681
+ }
682
+
683
+ public registerAllNodesCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
684
+ this.allNodesCheckpointReceivedCallback = callback;
685
+ }
686
+
687
+ public async notifyOwnCheckpointProposal(checkpoint: CheckpointProposalCore): Promise<void> {
688
+ await this.allNodesCheckpointReceivedCallback(checkpoint, this.node.peerId);
676
689
  }
677
690
 
678
691
  /**
@@ -685,6 +698,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
685
698
  this.duplicateProposalCallback = callback;
686
699
  }
687
700
 
701
+ /**
702
+ * Registers a callback to be invoked when a duplicate attestation is detected.
703
+ * A validator signing attestations for different proposals at the same slot.
704
+ * This callback is triggered on the first duplicate (when count goes from 1 to 2).
705
+ */
706
+ public registerDuplicateAttestationCallback(callback: P2PDuplicateAttestationCallback): void {
707
+ this.duplicateAttestationCallback = callback;
708
+ }
709
+
688
710
  /**
689
711
  * Subscribes to a topic.
690
712
  * @param topic - The topic to subscribe to.
@@ -749,6 +771,9 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
749
771
  if (!validator || !validator.addMessage(msgId)) {
750
772
  this.instrumentation.incMessagePrevalidationStatus(false, topicType);
751
773
  this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
774
+ if (topicType === TopicType.tx) {
775
+ this.logger.verbose(`Ignoring already-seen tx gossip message`, { msgId, source: source.toString() });
776
+ }
752
777
  return { result: false, topicType };
753
778
  }
754
779
 
@@ -813,9 +838,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
813
838
  if (msg.topic === this.topicStrings[TopicType.tx]) {
814
839
  await this.handleGossipedTx(p2pMessage.payload, msgId, source);
815
840
  } else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
816
- if (this.clientType === P2PClientType.Full) {
817
- await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
818
- }
841
+ await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
819
842
  } else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
820
843
  await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
821
844
  } else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
@@ -877,45 +900,128 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
877
900
  source: PeerId,
878
901
  topicType: TopicType,
879
902
  ): Promise<ReceivedMessageValidationResult<T, M>> {
880
- let resultAndObj: ReceivedMessageValidationResult<T, M> = { result: TopicValidatorResult.Reject };
903
+ // Default to reject result with a penalty if validation function throws an error
904
+ let resultAndObj: ReceivedMessageValidationResult<T, M> = {
905
+ result: TopicValidatorResult.Reject,
906
+ severity: PeerErrorSeverity.MidToleranceError,
907
+ };
881
908
  const timer = new Timer();
882
909
  try {
883
910
  resultAndObj = await validationFunc();
884
911
  } catch (err) {
885
- this.peerManager.penalizePeer(source, PeerErrorSeverity.LowToleranceError);
886
- this.logger.error(`Error deserializing and validating gossipsub message`, err, {
887
- msgId,
888
- source: source.toString(),
889
- topicType,
890
- });
912
+ this.logger.error(`Error validating gossipsub message`, err, { msgId, source: source.toString(), topicType });
891
913
  }
892
914
 
893
915
  if (resultAndObj.result === TopicValidatorResult.Accept) {
916
+ this.logger.debug(`Message ${topicType} accepted by validator`, { msgId, source: source.toString(), topicType });
894
917
  this.instrumentation.recordMessageValidation(topicType, timer);
918
+ } else if (resultAndObj.result === TopicValidatorResult.Reject) {
919
+ this.logger.warn(`Message ${topicType} rejected by validator with severity ${resultAndObj.severity}`, {
920
+ msgId,
921
+ source: source.toString(),
922
+ topicType,
923
+ severity: resultAndObj.severity,
924
+ });
925
+ this.peerManager.penalizePeer(source, resultAndObj.severity);
926
+ } else {
927
+ this.logger.trace(`Message ${topicType} ignored by validator`, { msgId, source: source.toString(), topicType });
895
928
  }
896
929
 
897
930
  this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result);
898
931
  return resultAndObj;
899
932
  }
900
933
 
934
+ private tryDeserialize<T>(deserializeFunc: () => T, msgId: string, source: PeerId): T | undefined {
935
+ try {
936
+ return deserializeFunc();
937
+ } catch (err) {
938
+ this.logger.warn(`Failed to deserialize gossipsub message from buffer`, {
939
+ err,
940
+ msgId,
941
+ source: source.toString(),
942
+ });
943
+ return undefined;
944
+ }
945
+ }
946
+
901
947
  protected async handleGossipedTx(payloadData: Buffer, msgId: string, source: PeerId) {
902
948
  const validationFunc: () => Promise<ReceivedMessageValidationResult<Tx>> = async () => {
903
- const tx = Tx.fromBuffer(payloadData);
904
- const isValid = await this.validatePropagatedTx(tx, source);
905
- const exists = isValid && (await this.mempools.txPool.hasTx(tx.getTxHash()));
949
+ const tx = this.tryDeserialize(() => Tx.fromBuffer(payloadData), msgId, source);
950
+ if (!tx) {
951
+ return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.LowToleranceError };
952
+ }
953
+
954
+ const currentBlockNumber = await this.archiver.getBlockNumber();
955
+ const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
956
+
957
+ // Stage 1: fast validators (metadata, data, timestamps, double-spend, gas, phases, block header)
958
+ const firstStageValidators = await this.createFirstStageMessageValidators(currentBlockNumber, nextSlotTimestamp);
959
+ const firstStageOutcome = await this.runValidations(tx, firstStageValidators);
960
+ if (!firstStageOutcome.allPassed) {
961
+ const { name } = firstStageOutcome.failure;
962
+ let { severity } = firstStageOutcome.failure;
963
+
964
+ // Double spend validator has a special case handler. We perform more detailed examination
965
+ // as to how recently the nullifier was entered into the tree and if the transaction should
966
+ // have 'known' the nullifier existed. This determines the severity of the penalty applied to the peer.
967
+ if (name === 'doubleSpendValidator') {
968
+ const txBlockNumber = BlockNumber(currentBlockNumber + 1);
969
+ severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
970
+ }
971
+
972
+ this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 1 validation failed`, {
973
+ validator: name,
974
+ severity,
975
+ source: source.toString(),
976
+ });
977
+ return { result: TopicValidatorResult.Reject, severity };
978
+ }
979
+
980
+ // Pool pre-check: see if the pool would accept this tx before doing expensive proof verification
981
+ const canAdd = await this.mempools.txPool.canAddPendingTx(tx);
982
+ if (canAdd === 'ignored') {
983
+ this.logger.verbose(`Ignoring gossiped tx ${tx.getTxHash().toString()}: pool pre-check returned ignored`, {
984
+ source: source.toString(),
985
+ });
986
+ return { result: TopicValidatorResult.Ignore, obj: tx };
987
+ }
988
+
989
+ // Stage 2: expensive proof verification
990
+ const secondStageValidators = this.createSecondStageMessageValidators();
991
+ const secondStageOutcome = await this.runValidations(tx, secondStageValidators);
992
+ if (!secondStageOutcome.allPassed) {
993
+ const { severity, name } = secondStageOutcome.failure;
994
+ this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 2 validation failed`, {
995
+ validator: name,
996
+ severity,
997
+ source: source.toString(),
998
+ });
999
+ return { result: TopicValidatorResult.Reject, severity };
1000
+ }
1001
+
1002
+ // Pool add: persist the tx
1003
+ const txHash = tx.getTxHash();
1004
+ const addResult = await this.mempools.txPool.addPendingTxs([tx], { source: 'gossip' });
906
1005
 
907
- this.logger.trace(`Validate propagated tx`, {
908
- isValid,
909
- exists,
1006
+ const wasAccepted = addResult.accepted.some(h => h.equals(txHash));
1007
+ const wasIgnored = addResult.ignored.some(h => h.equals(txHash));
1008
+
1009
+ this.logger.verbose(`Validate propagated tx ${txHash.toString()}`, {
1010
+ wasAccepted,
1011
+ wasIgnored,
910
1012
  [Attributes.P2P_ID]: source.toString(),
911
1013
  });
912
1014
 
913
- if (!isValid) {
914
- return { result: TopicValidatorResult.Reject };
915
- } else if (exists) {
1015
+ if (wasAccepted) {
1016
+ return { result: TopicValidatorResult.Accept, obj: tx };
1017
+ } else if (wasIgnored) {
916
1018
  return { result: TopicValidatorResult.Ignore, obj: tx };
917
1019
  } else {
918
- return { result: TopicValidatorResult.Accept, obj: tx };
1020
+ this.logger.warn(`Gossiped tx ${txHash.toString()} unexpectedly rejected by pool`, {
1021
+ source: source.toString(),
1022
+ txHash: txHash.toString(),
1023
+ });
1024
+ return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.HighToleranceError };
919
1025
  }
920
1026
  };
921
1027
 
@@ -924,6 +1030,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
924
1030
  return;
925
1031
  }
926
1032
 
1033
+ // Tx was accepted into pool and will be propagated - just log and record metrics
927
1034
  const txHash = tx.getTxHash();
928
1035
  const txHashString = txHash.toString();
929
1036
  this.logger.verbose(`Received tx ${txHashString} from external peer ${source.toString()} via gossip`, {
@@ -931,13 +1038,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
931
1038
  txHash: txHashString,
932
1039
  });
933
1040
 
934
- if (this.config.dropTransactions && randomInt(1000) < this.config.dropTransactionsProbability * 1000) {
935
- this.logger.warn(`Intentionally dropping tx ${txHashString} (probability rule)`);
936
- return;
937
- }
938
-
939
1041
  this.instrumentation.incrementTxReceived(1);
940
- await this.mempools.txPool.addTxs([tx]);
941
1042
  }
942
1043
 
943
1044
  /**
@@ -950,7 +1051,16 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
950
1051
  source: PeerId,
951
1052
  ): Promise<void> {
952
1053
  const { result, obj: attestation } = await this.validateReceivedMessage<CheckpointAttestation>(
953
- () => this.validateAndStoreCheckpointAttestation(source, CheckpointAttestation.fromBuffer(payloadData)),
1054
+ () => {
1055
+ const attestation = this.tryDeserialize(() => CheckpointAttestation.fromBuffer(payloadData), msgId, source);
1056
+ if (!attestation) {
1057
+ return Promise.resolve({
1058
+ result: TopicValidatorResult.Reject,
1059
+ severity: PeerErrorSeverity.LowToleranceError,
1060
+ });
1061
+ }
1062
+ return this.validateAndStoreCheckpointAttestation(source, attestation);
1063
+ },
954
1064
  msgId,
955
1065
  source,
956
1066
  TopicType.checkpoint_attestation,
@@ -983,48 +1093,60 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
983
1093
 
984
1094
  if (validationResult.result === 'reject') {
985
1095
  this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
986
- this.peerManager.penalizePeer(peerId, validationResult.severity);
987
- return { result: TopicValidatorResult.Reject };
1096
+ return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
988
1097
  }
989
1098
 
990
1099
  if (validationResult.result === 'ignore') {
991
1100
  return { result: TopicValidatorResult.Ignore, obj: attestation };
992
1101
  }
993
1102
 
994
- // Get committee size for the attestation's slot
995
- const slot = attestation.payload.header.slotNumber;
996
- const { committee } = await this.epochCache.getCommittee(slot);
997
- const committeeSize = committee?.length ?? 0;
998
-
999
1103
  // Try to add the attestation: this handles existence check, cap check, and adding in one call
1000
- const { added, alreadyExists } = await this.mempools.attestationPool.tryAddCheckpointAttestation(
1001
- attestation,
1002
- committeeSize,
1003
- );
1104
+ // count is the number of attestations by this signer for this slot (for duplicate detection)
1105
+ const slot = attestation.payload.header.slotNumber;
1106
+ const { added, alreadyExists, count } =
1107
+ await this.mempools.attestationPool.tryAddCheckpointAttestation(attestation);
1004
1108
 
1005
1109
  this.logger.trace(`Validate propagated checkpoint attestation`, {
1006
1110
  added,
1007
1111
  alreadyExists,
1112
+ count,
1008
1113
  [Attributes.SLOT_NUMBER]: slot.toString(),
1009
1114
  [Attributes.P2P_ID]: peerId.toString(),
1010
1115
  });
1011
1116
 
1012
- // Duplicate attestation received, no need to re-broadcast
1117
+ // Exact same attestation received, no need to re-broadcast
1013
1118
  if (alreadyExists) {
1014
1119
  return { result: TopicValidatorResult.Ignore, obj: attestation };
1015
1120
  }
1016
1121
 
1017
- // Could not add (cap reached), no need to re-broadcast
1122
+ // Could not add (cap reached for signer), penalize and do not re-broadcast
1018
1123
  if (!added) {
1019
- this.logger.warn(`Dropping checkpoint attestation due to per-(slot, proposalId) attestation cap`, {
1124
+ this.logger.warn(`Rejecting checkpoint attestation due to cap`, {
1020
1125
  slot: slot.toString(),
1021
1126
  archive: attestation.archive.toString(),
1022
1127
  source: peerId.toString(),
1128
+ attester: attestation.getSender()?.toString(),
1129
+ count,
1023
1130
  });
1024
- return { result: TopicValidatorResult.Ignore, obj: attestation };
1131
+ return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.HighToleranceError };
1025
1132
  }
1026
1133
 
1027
- // Attestation was added successfully
1134
+ // Check if this is a duplicate attestation (signer attested to a different proposal at the same slot)
1135
+ // count is the number of attestations by this signer for this slot
1136
+ if (count === 2) {
1137
+ const attester = attestation.getSender();
1138
+ if (attester) {
1139
+ this.logger.warn(`Detected duplicate attestation (equivocation) at slot ${slot}`, {
1140
+ slot: slot.toString(),
1141
+ archive: attestation.archive.toString(),
1142
+ source: peerId.toString(),
1143
+ attester: attester.toString(),
1144
+ });
1145
+ this.duplicateAttestationCallback?.({ slot, attester });
1146
+ }
1147
+ }
1148
+
1149
+ // Attestation was added successfully - accept it so other nodes can also detect the equivocation
1028
1150
  return { result: TopicValidatorResult.Accept, obj: attestation };
1029
1151
  }
1030
1152
 
@@ -1061,8 +1183,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1061
1183
 
1062
1184
  if (validationResult.result === 'reject') {
1063
1185
  this.logger.warn(`Penalizing peer ${peerId} for block proposal validation failure`);
1064
- this.peerManager.penalizePeer(peerId, validationResult.severity);
1065
- return { result: TopicValidatorResult.Reject };
1186
+ return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
1066
1187
  }
1067
1188
 
1068
1189
  if (validationResult.result === 'ignore') {
@@ -1070,8 +1191,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1070
1191
  }
1071
1192
 
1072
1193
  // Try to add the proposal: this handles existence check, cap check, and adding in one call
1073
- const { added, alreadyExists, totalForPosition } = await this.mempools.attestationPool.tryAddBlockProposal(block);
1074
- const isEquivocated = totalForPosition !== undefined && totalForPosition > 1;
1194
+ const { added, alreadyExists, count } = await this.mempools.attestationPool.tryAddBlockProposal(block);
1195
+ const isEquivocated = count !== undefined && count > 1;
1075
1196
 
1076
1197
  // Duplicate proposal received, no need to re-broadcast
1077
1198
  if (alreadyExists) {
@@ -1086,15 +1207,18 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1086
1207
 
1087
1208
  // Too many blocks received for this slot and index, penalize peer and do not re-broadcast
1088
1209
  if (!added) {
1089
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
1090
1210
  this.logger.warn(`Penalizing peer for block proposal exceeding per-position cap`, {
1091
1211
  ...block.toBlockInfo(),
1092
1212
  indexWithinCheckpoint: block.indexWithinCheckpoint,
1093
- totalForPosition,
1213
+ count,
1094
1214
  proposer: block.getSender()?.toString(),
1095
1215
  source: peerId.toString(),
1096
1216
  });
1097
- return { result: TopicValidatorResult.Reject, metadata: { isEquivocated } };
1217
+ return {
1218
+ result: TopicValidatorResult.Reject,
1219
+ metadata: { isEquivocated },
1220
+ severity: PeerErrorSeverity.HighToleranceError,
1221
+ };
1098
1222
  }
1099
1223
 
1100
1224
  // If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
@@ -1107,7 +1231,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1107
1231
  proposer: proposer?.toString(),
1108
1232
  });
1109
1233
  // Invoke the duplicate callback on the first duplicate spotted only
1110
- if (proposer && totalForPosition === 2) {
1234
+ if (proposer && count === 2) {
1111
1235
  this.duplicateProposalCallback?.({ slot: block.slotNumber, proposer, type: 'block' });
1112
1236
  }
1113
1237
  return { result: TopicValidatorResult.Accept, obj: block, metadata: { isEquivocated } };
@@ -1132,14 +1256,14 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1132
1256
  ...block.toBlockInfo(),
1133
1257
  });
1134
1258
 
1135
- // Mark the txs in this proposal as non-evictable
1136
- await this.mempools.txPool.markTxsAsNonEvictable(block.txHashes);
1259
+ // Mark the txs in this proposal as protected
1260
+ await this.mempools.txPool.protectTxs(block.txHashes, block.blockHeader);
1137
1261
 
1138
1262
  // Call the block received callback to validate the proposal.
1139
1263
  // Note: Validators do NOT attest to individual blocks, only to checkpoint proposals.
1140
1264
  const isValid = await this.blockReceivedCallback(block, sender);
1141
1265
  if (!isValid) {
1142
- this.logger.warn(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
1266
+ this.logger.info(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
1143
1267
  }
1144
1268
  }
1145
1269
 
@@ -1187,8 +1311,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1187
1311
 
1188
1312
  if (validationResult.result === 'reject') {
1189
1313
  this.logger.warn(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
1190
- this.peerManager.penalizePeer(peerId, validationResult.severity);
1191
- return { result: TopicValidatorResult.Reject };
1314
+ return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
1192
1315
  }
1193
1316
 
1194
1317
  if (validationResult.result === 'ignore') {
@@ -1203,20 +1326,21 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1203
1326
  [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
1204
1327
  [Attributes.P2P_ID]: peerId.toString(),
1205
1328
  });
1206
- const {
1207
- result,
1208
- obj,
1209
- metadata: { isEquivocated } = {},
1210
- } = await this.validateAndStoreBlockProposal(peerId, blockProposal);
1211
- if (result === TopicValidatorResult.Reject || !obj || isEquivocated) {
1329
+ const blockProposalResult = await this.validateAndStoreBlockProposal(peerId, blockProposal);
1330
+ const { obj, metadata: { isEquivocated } = {} } = blockProposalResult;
1331
+ if (blockProposalResult.result === TopicValidatorResult.Reject || !obj || isEquivocated) {
1212
1332
  this.logger.debug(`Rejecting checkpoint due to invalid last block proposal`, {
1213
1333
  [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
1214
1334
  [Attributes.P2P_ID]: peerId.toString(),
1215
1335
  isEquivocated,
1216
- result,
1336
+ result: blockProposalResult.result,
1217
1337
  });
1218
- return { result: TopicValidatorResult.Reject };
1219
- } else if (result === TopicValidatorResult.Accept && obj && !isEquivocated) {
1338
+ return {
1339
+ result: TopicValidatorResult.Reject,
1340
+ severity:
1341
+ 'severity' in blockProposalResult ? blockProposalResult.severity : PeerErrorSeverity.MidToleranceError,
1342
+ };
1343
+ } else if (blockProposalResult.result === TopicValidatorResult.Accept && obj && !isEquivocated) {
1220
1344
  processBlock = true;
1221
1345
  }
1222
1346
  }
@@ -1224,8 +1348,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1224
1348
  // Try to add the checkpoint proposal core: this handles existence check, cap check, and adding in one call
1225
1349
  const checkpointCore = checkpoint.toCore();
1226
1350
  const tryAddResult = await this.mempools.attestationPool.tryAddCheckpointProposal(checkpointCore);
1227
- const { added, alreadyExists, totalForPosition } = tryAddResult;
1228
- const isEquivocated = totalForPosition !== undefined && totalForPosition > 1;
1351
+ const { added, alreadyExists, count } = tryAddResult;
1352
+ const isEquivocated = count !== undefined && count > 1;
1229
1353
 
1230
1354
  // Duplicate proposal received, do not re-broadcast
1231
1355
  if (alreadyExists) {
@@ -1243,13 +1367,17 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1243
1367
  // Too many checkpoint proposals received for this slot, penalize peer and do not re-broadcast
1244
1368
  // Note: We still return the checkpoint obj so the lastBlock can be processed if valid
1245
1369
  if (!added) {
1246
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
1247
1370
  this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
1248
1371
  ...checkpoint.toCheckpointInfo(),
1249
- totalForPosition,
1372
+ count,
1250
1373
  source: peerId.toString(),
1251
1374
  });
1252
- return { result: TopicValidatorResult.Reject, obj: checkpoint, metadata: { isEquivocated, processBlock } };
1375
+ return {
1376
+ result: TopicValidatorResult.Reject,
1377
+ obj: checkpoint,
1378
+ metadata: { isEquivocated, processBlock },
1379
+ severity: PeerErrorSeverity.HighToleranceError,
1380
+ };
1253
1381
  }
1254
1382
 
1255
1383
  // If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
@@ -1262,7 +1390,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1262
1390
  proposer: proposer?.toString(),
1263
1391
  });
1264
1392
  // Invoke the duplicate callback on the first duplicate spotted only
1265
- if (proposer && totalForPosition === 2) {
1393
+ if (proposer && count === 2) {
1266
1394
  this.duplicateProposalCallback?.({ slot: checkpoint.slotNumber, proposer, type: 'checkpoint' });
1267
1395
  }
1268
1396
  return {
@@ -1294,9 +1422,11 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1294
1422
  source: sender.toString(),
1295
1423
  });
1296
1424
 
1425
+ await this.allNodesCheckpointReceivedCallback(checkpoint, sender);
1426
+
1297
1427
  // Call the checkpoint received callback with the core version (without lastBlock)
1298
1428
  // to validate and potentially generate attestations
1299
- const attestations = await this.checkpointReceivedCallback(checkpoint, sender);
1429
+ const attestations = await this.validatorCheckpointReceivedCallback(checkpoint, sender);
1300
1430
  if (attestations && attestations.length > 0) {
1301
1431
  // If the callback returned attestations, add them to the pool and propagate them
1302
1432
  await this.mempools.attestationPool.addOwnCheckpointAttestations(attestations);
@@ -1511,43 +1641,12 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1511
1641
  }
1512
1642
 
1513
1643
  protected createRequestedTxValidator(): TxValidator {
1514
- return createTxReqRespValidator(this.proofVerifier, {
1644
+ return createTxValidatorForReqResponseReceivedTxs(this.proofVerifier, {
1515
1645
  l1ChainId: this.config.l1ChainId,
1516
1646
  rollupVersion: this.config.rollupVersion,
1517
1647
  });
1518
1648
  }
1519
1649
 
1520
- @trackSpan('Libp2pService.validatePropagatedTx', tx => ({
1521
- [Attributes.TX_HASH]: tx.getTxHash().toString(),
1522
- }))
1523
- private async validatePropagatedTx(tx: Tx, peerId: PeerId): Promise<boolean> {
1524
- const currentBlockNumber = await this.archiver.getBlockNumber();
1525
-
1526
- // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
1527
- const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1528
- const messageValidators = await this.createMessageValidators(currentBlockNumber, nextSlotTimestamp);
1529
-
1530
- for (const validator of messageValidators) {
1531
- const outcome = await this.runValidations(tx, validator);
1532
-
1533
- if (outcome.allPassed) {
1534
- continue;
1535
- }
1536
- const { name } = outcome.failure;
1537
- let { severity } = outcome.failure;
1538
-
1539
- // Double spend validator has a special case handler
1540
- if (name === 'doubleSpendValidator') {
1541
- const txBlockNumber = BlockNumber(currentBlockNumber + 1); // tx is expected to be in the next block
1542
- severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
1543
- }
1544
-
1545
- this.peerManager.penalizePeer(peerId, severity);
1546
- return false;
1547
- }
1548
- return true;
1549
- }
1550
-
1551
1650
  private async getGasFees(blockNumber: BlockNumber): Promise<GasFees> {
1552
1651
  if (blockNumber === this.feesCache?.blockNumber) {
1553
1652
  return this.feesCache.gasFees;
@@ -1575,60 +1674,62 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1575
1674
  };
1576
1675
  }
1577
1676
 
1578
- public async validate(txs: Tx[]): Promise<void> {
1579
- const currentBlockNumber = await this.archiver.getBlockNumber();
1580
-
1581
- // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
1582
- const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1583
- const messageValidators = await this.createMessageValidators(currentBlockNumber, nextSlotTimestamp);
1677
+ public async validateTxsReceivedInBlockProposal(txs: Tx[]): Promise<void> {
1678
+ const validator = createTxValidatorForBlockProposalReceivedTxs(
1679
+ this.proofVerifier,
1680
+ { l1ChainId: this.config.l1ChainId, rollupVersion: this.config.rollupVersion },
1681
+ this.logger.getBindings(),
1682
+ );
1584
1683
 
1585
- await Promise.all(
1684
+ const results = await Promise.all(
1586
1685
  txs.map(async tx => {
1587
- for (const validator of messageValidators) {
1588
- const outcome = await this.runValidations(tx, validator);
1589
- if (!outcome.allPassed) {
1590
- throw new Error('Invalid tx detected', { cause: { outcome } });
1591
- }
1592
- }
1686
+ const result = await validator.validateTx(tx);
1687
+ return result.result !== 'invalid';
1593
1688
  }),
1594
1689
  );
1690
+ if (results.some(value => value === false)) {
1691
+ throw new Error('Invalid tx detected');
1692
+ }
1595
1693
  }
1596
1694
 
1597
- /**
1598
- * Create message validators for the given block number and timestamp.
1599
- *
1600
- * Each validator is a pair of a validator and a severity.
1601
- * If a validator fails, the peer is penalized with the severity of the validator.
1602
- *
1603
- * @param currentBlockNumber - The current synced block number.
1604
- * @param nextSlotTimestamp - The timestamp of the next slot (used to validate txs are not expired).
1605
- * @returns The message validators.
1606
- */
1607
- private async createMessageValidators(
1695
+ /** Creates the first stage (fast) validators for gossiped transactions. */
1696
+ protected async createFirstStageMessageValidators(
1608
1697
  currentBlockNumber: BlockNumber,
1609
1698
  nextSlotTimestamp: UInt64,
1610
- ): Promise<Record<string, MessageValidator>[]> {
1699
+ ): Promise<Record<string, TransactionValidator>> {
1611
1700
  const gasFees = await this.getGasFees(currentBlockNumber);
1612
- const allowedInSetup = this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
1613
-
1614
- const blockNumberInWhichTheTxIsConsideredToBeIncluded = BlockNumber(currentBlockNumber + 1);
1615
-
1616
- return createTxMessageValidators(
1701
+ const allowedInSetup = [
1702
+ ...(await getDefaultAllowedSetupFunctions()),
1703
+ ...(this.config.txPublicSetupAllowListExtend ?? []),
1704
+ ];
1705
+ const blockNumber = BlockNumber(currentBlockNumber + 1);
1706
+ const l1Constants = await this.archiver.getL1Constants();
1707
+
1708
+ return createFirstStageTxValidationsForGossipedTransactions(
1617
1709
  nextSlotTimestamp,
1618
- blockNumberInWhichTheTxIsConsideredToBeIncluded,
1710
+ blockNumber,
1619
1711
  this.worldStateSynchronizer,
1620
1712
  gasFees,
1621
1713
  this.config.l1ChainId,
1622
1714
  this.config.rollupVersion,
1623
1715
  protocolContractsHash,
1624
1716
  this.archiver,
1625
- this.proofVerifier,
1626
1717
  !this.config.disableTransactions,
1627
1718
  allowedInSetup,
1628
1719
  this.logger.getBindings(),
1720
+ {
1721
+ rollupManaLimit: l1Constants.rollupManaLimit,
1722
+ maxBlockL2Gas: this.config.validateMaxL2BlockGas,
1723
+ maxBlockDAGas: this.config.validateMaxDABlockGas,
1724
+ },
1629
1725
  );
1630
1726
  }
1631
1727
 
1728
+ /** Creates the second stage (expensive proof verification) validators for gossiped transactions. */
1729
+ protected createSecondStageMessageValidators(): Record<string, TransactionValidator> {
1730
+ return createSecondStageTxValidationsForGossipedTransactions(this.proofVerifier, this.logger.getBindings());
1731
+ }
1732
+
1632
1733
  /**
1633
1734
  * Run validations on a tx.
1634
1735
  * @param tx - The tx to validate.
@@ -1637,7 +1738,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1637
1738
  */
1638
1739
  private async runValidations(
1639
1740
  tx: Tx,
1640
- messageValidators: Record<string, MessageValidator>,
1741
+ messageValidators: Record<string, TransactionValidator>,
1641
1742
  ): Promise<ValidationOutcome> {
1642
1743
  const validationPromises = Object.entries(messageValidators).map(async ([name, { validator, severity }]) => {
1643
1744
  const { result } = await validator.validateTx(tx);
@@ -1646,8 +1747,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1646
1747
 
1647
1748
  // A promise that resolves when all validations have been run
1648
1749
  const allValidations = await Promise.all(validationPromises);
1649
- const failed = allValidations.find(x => !x.isValid);
1650
- if (failed) {
1750
+ const failures = allValidations.filter(x => !x.isValid);
1751
+ if (failures.length > 0) {
1752
+ // Pick the most severe failure (lowest tolerance = harshest penalty)
1753
+ const failed = maxBy(failures, f => PeerErrorSeverityByHarshness.indexOf(f.severity))!;
1651
1754
  return {
1652
1755
  allPassed: false,
1653
1756
  failure: {
@@ -1700,31 +1803,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1700
1803
  return PeerErrorSeverity.HighToleranceError;
1701
1804
  }
1702
1805
 
1703
- /**
1704
- * Validate a checkpoint attestation.
1705
- *
1706
- * @param attestation - The checkpoint attestation to validate.
1707
- * @returns True if the checkpoint attestation is valid, false otherwise.
1708
- */
1709
- @trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation) => ({
1710
- [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
1711
- [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
1712
- [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
1713
- }))
1714
- public async validateCheckpointAttestation(
1715
- peerId: PeerId,
1716
- attestation: CheckpointAttestation,
1717
- ): Promise<P2PValidationResult> {
1718
- const result = await this.checkpointAttestationValidator.validate(attestation);
1719
-
1720
- if (result.result === 'reject') {
1721
- this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
1722
- this.peerManager.penalizePeer(peerId, result.severity);
1723
- }
1724
-
1725
- return result;
1726
- }
1727
-
1728
1806
  public getPeerScore(peerId: PeerId): number {
1729
1807
  return this.node.services.pubsub.score.score(peerId.toString());
1730
1808
  }