@aztec/p2p 0.0.1-commit.87a0206 → 0.0.1-commit.88e6f9396

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 (381) 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 +50 -13
  5. package/dest/client/interface.d.ts +39 -33
  6. package/dest/client/interface.d.ts.map +1 -1
  7. package/dest/client/p2p_client.d.ts +37 -50
  8. package/dest/client/p2p_client.d.ts.map +1 -1
  9. package/dest/client/p2p_client.js +150 -223
  10. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +8 -8
  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/tx-pool.error.d.ts +8 -0
  15. package/dest/errors/tx-pool.error.d.ts.map +1 -0
  16. package/dest/errors/tx-pool.error.js +9 -0
  17. package/dest/index.d.ts +2 -1
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +1 -0
  20. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +21 -12
  21. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  22. package/dest/mem_pools/attestation_pool/attestation_pool.js +72 -38
  23. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  24. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  25. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +57 -57
  26. package/dest/mem_pools/attestation_pool/index.d.ts +2 -2
  27. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  28. package/dest/mem_pools/attestation_pool/index.js +1 -1
  29. package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
  30. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  31. package/dest/mem_pools/attestation_pool/mocks.js +2 -2
  32. package/dest/mem_pools/index.d.ts +2 -1
  33. package/dest/mem_pools/index.d.ts.map +1 -1
  34. package/dest/mem_pools/instrumentation.d.ts +4 -2
  35. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  36. package/dest/mem_pools/instrumentation.js +16 -14
  37. package/dest/mem_pools/interface.d.ts +3 -3
  38. package/dest/mem_pools/interface.d.ts.map +1 -1
  39. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  40. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  41. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +2 -1
  42. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +3 -3
  43. package/dest/mem_pools/tx_pool/priority.d.ts +2 -2
  44. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
  45. package/dest/mem_pools/tx_pool/priority.js +4 -4
  46. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  47. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  48. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +3 -1
  49. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
  50. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  51. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
  52. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  53. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  54. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  55. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  56. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  57. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +7 -3
  58. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  59. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  60. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
  61. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
  62. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  63. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
  64. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +54 -5
  65. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  66. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  67. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +7 -5
  68. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +7 -5
  69. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  70. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  71. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +14 -6
  72. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  73. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  74. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +16 -4
  75. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  76. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  77. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +3 -3
  78. package/dest/mem_pools/tx_pool_v2/index.d.ts +3 -2
  79. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  80. package/dest/mem_pools/tx_pool_v2/index.js +2 -1
  81. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  82. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  83. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  84. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +30 -12
  85. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  86. package/dest/mem_pools/tx_pool_v2/interfaces.js +5 -1
  87. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +78 -15
  88. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  89. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +139 -18
  90. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +12 -3
  91. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  92. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +50 -45
  93. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +12 -5
  94. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  95. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +17 -6
  96. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +14 -5
  97. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  98. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +364 -189
  99. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -1
  100. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  101. package/dest/msg_validators/attestation_validator/attestation_validator.js +5 -4
  102. package/dest/msg_validators/clock_tolerance.d.ts +1 -1
  103. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
  104. package/dest/msg_validators/clock_tolerance.js +4 -3
  105. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +6 -4
  106. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  107. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
  108. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +6 -4
  109. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  110. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
  111. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -8
  112. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  113. package/dest/msg_validators/proposal_validator/proposal_validator.js +53 -41
  114. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
  115. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  116. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  117. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  118. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  119. package/dest/msg_validators/tx_validator/allowed_public_setup.js +24 -20
  120. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  121. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  122. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  123. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
  124. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  125. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  126. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
  127. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  128. package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
  129. package/dest/msg_validators/tx_validator/factory.d.ts +133 -6
  130. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  131. package/dest/msg_validators/tx_validator/factory.js +240 -59
  132. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  133. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  134. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  135. package/dest/msg_validators/tx_validator/gas_validator.d.ts +67 -3
  136. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  137. package/dest/msg_validators/tx_validator/gas_validator.js +104 -37
  138. package/dest/msg_validators/tx_validator/index.d.ts +3 -1
  139. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  140. package/dest/msg_validators/tx_validator/index.js +2 -0
  141. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  142. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  143. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  144. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  145. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  146. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  147. package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
  148. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  149. package/dest/msg_validators/tx_validator/phases_validator.js +71 -23
  150. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
  151. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  152. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  153. package/dest/services/dummy_service.d.ts +9 -5
  154. package/dest/services/dummy_service.d.ts.map +1 -1
  155. package/dest/services/dummy_service.js +7 -4
  156. package/dest/services/encoding.d.ts +7 -3
  157. package/dest/services/encoding.d.ts.map +1 -1
  158. package/dest/services/encoding.js +18 -11
  159. package/dest/services/gossipsub/index.d.ts +3 -0
  160. package/dest/services/gossipsub/index.d.ts.map +1 -0
  161. package/dest/services/gossipsub/index.js +2 -0
  162. package/dest/services/gossipsub/scoring.d.ts +21 -3
  163. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  164. package/dest/services/gossipsub/scoring.js +24 -7
  165. package/dest/services/gossipsub/topic_score_params.d.ts +173 -0
  166. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  167. package/dest/services/gossipsub/topic_score_params.js +346 -0
  168. package/dest/services/libp2p/libp2p_service.d.ts +25 -21
  169. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  170. package/dest/services/libp2p/libp2p_service.js +199 -174
  171. package/dest/services/peer-manager/metrics.d.ts +3 -1
  172. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  173. package/dest/services/peer-manager/metrics.js +6 -0
  174. package/dest/services/peer-manager/peer_manager.d.ts +1 -1
  175. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  176. package/dest/services/peer-manager/peer_manager.js +6 -3
  177. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  178. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  179. package/dest/services/peer-manager/peer_scoring.js +25 -2
  180. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +12 -8
  181. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  182. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +80 -106
  183. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +4 -7
  184. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  185. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +11 -13
  186. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  187. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +31 -46
  188. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
  189. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  190. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
  191. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
  192. package/dest/services/reqresp/interface.d.ts +10 -1
  193. package/dest/services/reqresp/interface.d.ts.map +1 -1
  194. package/dest/services/reqresp/interface.js +15 -1
  195. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +3 -3
  196. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  197. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +7 -1
  198. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  199. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +15 -0
  200. package/dest/services/reqresp/protocols/tx.d.ts +7 -1
  201. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  202. package/dest/services/reqresp/protocols/tx.js +20 -0
  203. package/dest/services/reqresp/reqresp.d.ts +1 -1
  204. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  205. package/dest/services/reqresp/reqresp.js +30 -14
  206. package/dest/services/service.d.ts +22 -3
  207. package/dest/services/service.d.ts.map +1 -1
  208. package/dest/services/tx_collection/config.d.ts +19 -1
  209. package/dest/services/tx_collection/config.d.ts.map +1 -1
  210. package/dest/services/tx_collection/config.js +46 -0
  211. package/dest/services/tx_collection/fast_tx_collection.d.ts +3 -4
  212. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  213. package/dest/services/tx_collection/fast_tx_collection.js +80 -76
  214. package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
  215. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  216. package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
  217. package/dest/services/tx_collection/file_store_tx_source.d.ts +37 -0
  218. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  219. package/dest/services/tx_collection/file_store_tx_source.js +90 -0
  220. package/dest/services/tx_collection/index.d.ts +2 -1
  221. package/dest/services/tx_collection/index.d.ts.map +1 -1
  222. package/dest/services/tx_collection/index.js +1 -0
  223. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  224. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  225. package/dest/services/tx_collection/instrumentation.js +2 -1
  226. package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -7
  227. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  228. package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
  229. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  230. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  231. package/dest/services/tx_collection/request_tracker.js +84 -0
  232. package/dest/services/tx_collection/slow_tx_collection.d.ts +7 -3
  233. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  234. package/dest/services/tx_collection/slow_tx_collection.js +60 -26
  235. package/dest/services/tx_collection/tx_collection.d.ts +23 -13
  236. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  237. package/dest/services/tx_collection/tx_collection.js +75 -3
  238. package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
  239. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  240. package/dest/services/tx_collection/tx_collection_sink.js +26 -29
  241. package/dest/services/tx_collection/tx_source.d.ts +8 -3
  242. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  243. package/dest/services/tx_collection/tx_source.js +19 -2
  244. package/dest/services/tx_file_store/config.d.ts +1 -3
  245. package/dest/services/tx_file_store/config.d.ts.map +1 -1
  246. package/dest/services/tx_file_store/config.js +0 -4
  247. package/dest/services/tx_file_store/tx_file_store.d.ts +4 -3
  248. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  249. package/dest/services/tx_file_store/tx_file_store.js +9 -6
  250. package/dest/services/tx_provider.d.ts +4 -4
  251. package/dest/services/tx_provider.d.ts.map +1 -1
  252. package/dest/services/tx_provider.js +9 -8
  253. package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
  254. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  255. package/dest/test-helpers/make-test-p2p-clients.js +1 -2
  256. package/dest/test-helpers/mock-pubsub.d.ts +30 -4
  257. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  258. package/dest/test-helpers/mock-pubsub.js +105 -4
  259. package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
  260. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  261. package/dest/test-helpers/reqresp-nodes.js +4 -3
  262. package/dest/test-helpers/testbench-utils.d.ts +35 -24
  263. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  264. package/dest/test-helpers/testbench-utils.js +124 -38
  265. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  266. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  267. package/dest/testbench/p2p_client_testbench_worker.js +18 -16
  268. package/dest/testbench/worker_client_manager.d.ts +3 -1
  269. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  270. package/dest/testbench/worker_client_manager.js +6 -2
  271. package/dest/util.d.ts +3 -3
  272. package/dest/util.d.ts.map +1 -1
  273. package/package.json +14 -14
  274. package/src/client/factory.ts +96 -24
  275. package/src/client/interface.ts +43 -33
  276. package/src/client/p2p_client.ts +174 -265
  277. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +21 -13
  278. package/src/config.ts +158 -44
  279. package/src/errors/tx-pool.error.ts +12 -0
  280. package/src/index.ts +1 -0
  281. package/src/mem_pools/attestation_pool/attestation_pool.ts +100 -48
  282. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +61 -57
  283. package/src/mem_pools/attestation_pool/index.ts +3 -3
  284. package/src/mem_pools/attestation_pool/mocks.ts +2 -1
  285. package/src/mem_pools/index.ts +3 -0
  286. package/src/mem_pools/instrumentation.ts +17 -13
  287. package/src/mem_pools/interface.ts +2 -2
  288. package/src/mem_pools/tx_pool/README.md +1 -1
  289. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +2 -1
  290. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
  291. package/src/mem_pools/tx_pool/priority.ts +4 -4
  292. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +3 -1
  293. package/src/mem_pools/tx_pool_v2/README.md +85 -11
  294. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
  295. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  296. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +7 -3
  297. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
  298. package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
  299. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +59 -4
  300. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
  301. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
  302. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -9
  303. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +33 -6
  304. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +4 -3
  305. package/src/mem_pools/tx_pool_v2/index.ts +2 -1
  306. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  307. package/src/mem_pools/tx_pool_v2/interfaces.ts +32 -12
  308. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +202 -26
  309. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +58 -45
  310. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +34 -8
  311. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +410 -187
  312. package/src/msg_validators/attestation_validator/README.md +49 -0
  313. package/src/msg_validators/attestation_validator/attestation_validator.ts +5 -4
  314. package/src/msg_validators/clock_tolerance.ts +4 -3
  315. package/src/msg_validators/proposal_validator/README.md +123 -0
  316. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +14 -4
  317. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +20 -7
  318. package/src/msg_validators/proposal_validator/proposal_validator.ts +69 -45
  319. package/src/msg_validators/tx_validator/README.md +119 -0
  320. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
  321. package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
  322. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  323. package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
  324. package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
  325. package/src/msg_validators/tx_validator/factory.ts +387 -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 +81 -26
  332. package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
  333. package/src/services/dummy_service.ts +12 -6
  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 +211 -190
  340. package/src/services/peer-manager/metrics.ts +7 -0
  341. package/src/services/peer-manager/peer_manager.ts +7 -3
  342. package/src/services/peer-manager/peer_scoring.ts +25 -0
  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 +76 -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/reqresp.ts +35 -15
  355. package/src/services/service.ts +31 -2
  356. package/src/services/tx_collection/config.ts +68 -0
  357. package/src/services/tx_collection/fast_tx_collection.ts +83 -76
  358. package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
  359. package/src/services/tx_collection/file_store_tx_source.ts +117 -0
  360. package/src/services/tx_collection/index.ts +1 -0
  361. package/src/services/tx_collection/instrumentation.ts +7 -1
  362. package/src/services/tx_collection/proposal_tx_collector.ts +9 -13
  363. package/src/services/tx_collection/request_tracker.ts +127 -0
  364. package/src/services/tx_collection/slow_tx_collection.ts +66 -33
  365. package/src/services/tx_collection/tx_collection.ts +114 -19
  366. package/src/services/tx_collection/tx_collection_sink.ts +30 -34
  367. package/src/services/tx_collection/tx_source.ts +22 -3
  368. package/src/services/tx_file_store/config.ts +0 -6
  369. package/src/services/tx_file_store/tx_file_store.ts +10 -8
  370. package/src/services/tx_provider.ts +10 -9
  371. package/src/test-helpers/make-test-p2p-clients.ts +4 -6
  372. package/src/test-helpers/mock-pubsub.ts +146 -9
  373. package/src/test-helpers/reqresp-nodes.ts +5 -7
  374. package/src/test-helpers/testbench-utils.ts +146 -43
  375. package/src/testbench/p2p_client_testbench_worker.ts +26 -24
  376. package/src/testbench/worker_client_manager.ts +13 -5
  377. package/src/util.ts +8 -2
  378. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
  379. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  380. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
  381. 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';
@@ -70,9 +69,11 @@ import {
70
69
  } from '../../msg_validators/index.js';
71
70
  import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
72
71
  import {
73
- type MessageValidator,
74
- createTxMessageValidators,
75
- createTxReqRespValidator,
72
+ type TransactionValidator,
73
+ createFirstStageTxValidationsForGossipedTransactions,
74
+ createSecondStageTxValidationsForGossipedTransactions,
75
+ createTxValidatorForBlockProposalReceivedTxs,
76
+ createTxValidatorForReqResponseReceivedTxs,
76
77
  } from '../../msg_validators/tx_validator/factory.js';
77
78
  import { GossipSubEvent } from '../../types/index.js';
78
79
  import { type PubSubLibp2p, convertToMultiaddr } from '../../util.js';
@@ -80,13 +81,17 @@ import { getVersions } from '../../versioning.js';
80
81
  import { AztecDatastore } from '../data_store.js';
81
82
  import { DiscV5Service } from '../discv5/discV5_service.js';
82
83
  import { SnappyTransform, fastMsgIdFn, getMsgIdFn, msgIdToStrFn } from '../encoding.js';
83
- import { gossipScoreThresholds } from '../gossipsub/scoring.js';
84
+ import { APP_SPECIFIC_WEIGHT, gossipScoreThresholds } from '../gossipsub/scoring.js';
85
+ import { createAllTopicScoreParams } from '../gossipsub/topic_score_params.js';
84
86
  import type { PeerManagerInterface } from '../peer-manager/interface.js';
85
87
  import { PeerManager } from '../peer-manager/peer_manager.js';
86
88
  import { PeerScoring } from '../peer-manager/peer_scoring.js';
87
89
  import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
88
90
  import type { P2PReqRespConfig } from '../reqresp/config.js';
89
91
  import {
92
+ AuthRequest,
93
+ BlockTxsRequest,
94
+ BlockTxsResponse,
90
95
  DEFAULT_SUB_PROTOCOL_VALIDATORS,
91
96
  type ReqRespInterface,
92
97
  type ReqRespResponse,
@@ -94,14 +99,9 @@ import {
94
99
  type ReqRespSubProtocolHandler,
95
100
  type ReqRespSubProtocolHandlers,
96
101
  type ReqRespSubProtocolValidators,
102
+ StatusMessage,
97
103
  type SubProtocolMap,
98
104
  ValidationError,
99
- } from '../reqresp/index.js';
100
- import {
101
- AuthRequest,
102
- BlockTxsRequest,
103
- BlockTxsResponse,
104
- StatusMessage,
105
105
  pingHandler,
106
106
  reqGoodbyeHandler,
107
107
  reqRespBlockHandler,
@@ -113,6 +113,7 @@ import { ReqResp } from '../reqresp/reqresp.js';
113
113
  import type {
114
114
  P2PBlockReceivedCallback,
115
115
  P2PCheckpointReceivedCallback,
116
+ P2PDuplicateAttestationCallback,
116
117
  P2PService,
117
118
  PeerDiscoveryService,
118
119
  } from '../service.js';
@@ -134,7 +135,7 @@ type ReceivedMessageValidationResult<T, M = undefined> =
134
135
  /**
135
136
  * Lib P2P implementation of the P2PService interface.
136
137
  */
137
- export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends WithTracer implements P2PService {
138
+ export class LibP2PService extends WithTracer implements P2PService {
138
139
  private discoveryRunningPromise?: RunningPromise;
139
140
  private msgIdSeenValidators: Record<TopicType, MessageSeenValidator> = {} as Record<TopicType, MessageSeenValidator>;
140
141
 
@@ -155,6 +156,9 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
155
156
  type: 'checkpoint' | 'block';
156
157
  }) => void;
157
158
 
159
+ /** Callback invoked when a duplicate attestation is detected (triggers slashing). */
160
+ private duplicateAttestationCallback?: P2PDuplicateAttestationCallback;
161
+
158
162
  /**
159
163
  * Callback for when a block is received from a peer.
160
164
  * @param block - The block received from the peer.
@@ -178,7 +182,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
178
182
  protected logger: Logger;
179
183
 
180
184
  constructor(
181
- private clientType: T,
182
185
  private config: P2PConfig,
183
186
  protected node: PubSubLibp2p,
184
187
  private peerDiscoveryService: PeerDiscoveryService,
@@ -220,10 +223,12 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
220
223
  this.protocolVersion,
221
224
  );
222
225
 
223
- this.blockProposalValidator = new BlockProposalValidator(epochCache, { txsPermitted: !config.disableTransactions });
224
- this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, {
226
+ const proposalValidatorOpts = {
225
227
  txsPermitted: !config.disableTransactions,
226
- });
228
+ maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
229
+ };
230
+ this.blockProposalValidator = new BlockProposalValidator(epochCache, proposalValidatorOpts);
231
+ this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, proposalValidatorOpts);
227
232
  this.checkpointAttestationValidator = config.fishermanMode
228
233
  ? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry)
229
234
  : new CheckpointAttestationValidator(epochCache);
@@ -231,11 +236,11 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
231
236
  this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
232
237
 
233
238
  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.`,
239
+ this.logger.warn(
240
+ `Handler for block received not yet registered on P2P service. Received block ${block.blockNumber} for slot ${block.slotNumber} from peer.`,
236
241
  { p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier() },
237
242
  );
238
- return false;
243
+ return true;
239
244
  };
240
245
 
241
246
  this.checkpointReceivedCallback = (
@@ -258,8 +263,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
258
263
  * @param txPool - The transaction pool to be accessed by the service.
259
264
  * @returns The new service.
260
265
  */
261
- public static async new<T extends P2PClientType>(
262
- clientType: T,
266
+ public static async new(
263
267
  config: P2PConfig,
264
268
  peerId: PeerId,
265
269
  deps: {
@@ -311,11 +315,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
311
315
  const versions = getVersions(config);
312
316
  const protocolVersion = compressComponentVersions(versions);
313
317
 
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
318
  const preferredPeersEnrs: ENR[] = config.preferredPeers.map(enr => ENR.decodeTxt(enr));
320
319
  const directPeers = (
321
320
  await Promise.all(
@@ -335,6 +334,16 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
335
334
 
336
335
  const announceTcpMultiaddr = config.p2pIp ? [convertToMultiaddr(config.p2pIp, p2pPort, 'tcp')] : [];
337
336
 
337
+ // Create dynamic topic score params based on network configuration
338
+ const l1Constants = epochCache.getL1Constants();
339
+ const topicScoreParams = createAllTopicScoreParams(protocolVersion, {
340
+ slotDurationMs: l1Constants.slotDuration * 1000,
341
+ heartbeatIntervalMs: config.gossipsubInterval,
342
+ targetCommitteeSize: l1Constants.targetCommitteeSize,
343
+ blockDurationMs: config.blockDurationMs,
344
+ expectedBlockProposalsPerSlot: config.expectedBlockProposalsPerSlot,
345
+ });
346
+
338
347
  const node = await createLibp2p({
339
348
  start: false,
340
349
  peerId,
@@ -430,28 +439,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
430
439
  scoreParams: createPeerScoreParams({
431
440
  // IPColocation factor can be disabled for local testing - default to -5
432
441
  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
- },
442
+ topics: topicScoreParams,
455
443
  }),
456
444
  }) as (components: GossipSubComponents) => GossipSub,
457
445
  components: (components: { connectionManager: ConnectionManager }) => ({
@@ -477,13 +465,16 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
477
465
  epochCache,
478
466
  );
479
467
 
480
- // Update gossipsub score params
481
- node.services.pubsub.score.params.appSpecificWeight = 10;
468
+ // Configure application-specific scoring for gossipsub.
469
+ // The weight scales app score to align with gossipsub thresholds:
470
+ // - Disconnect (-50) × 10 = -500 = gossipThreshold (stops receiving gossip)
471
+ // - Ban (-100) × 10 = -1000 = publishThreshold (cannot publish)
472
+ // Note: positive topic scores can offset penalties, so alignment is best-effort.
473
+ node.services.pubsub.score.params.appSpecificWeight = APP_SPECIFIC_WEIGHT;
482
474
  node.services.pubsub.score.params.appSpecificScore = (peerId: string) =>
483
475
  peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
484
476
 
485
477
  return new LibP2PService(
486
- clientType,
487
478
  config,
488
479
  node,
489
480
  peerDiscoveryService,
@@ -557,7 +548,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
557
548
  await this.node.start();
558
549
 
559
550
  // Subscribe to standard GossipSub topics by default
560
- for (const topic of getTopicsForClientAndConfig(this.clientType, this.config.disableTransactions)) {
551
+ for (const topic of getTopicsForConfig(this.config.disableTransactions)) {
561
552
  this.subscribeToTopic(this.topicStrings[topic]);
562
553
  }
563
554
 
@@ -623,6 +614,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
623
614
  return this.peerManager.getPeers(includePending);
624
615
  }
625
616
 
617
+ public getGossipMeshPeerCount(topicType: TopicType): number {
618
+ return this.node.services.pubsub.getMeshPeers(this.topicStrings[topicType]).length;
619
+ }
620
+
626
621
  private handleGossipSubEvent(e: CustomEvent<GossipsubMessage>) {
627
622
  this.logger.trace(`Received PUBSUB message.`);
628
623
 
@@ -685,6 +680,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
685
680
  this.duplicateProposalCallback = callback;
686
681
  }
687
682
 
683
+ /**
684
+ * Registers a callback to be invoked when a duplicate attestation is detected.
685
+ * A validator signing attestations for different proposals at the same slot.
686
+ * This callback is triggered on the first duplicate (when count goes from 1 to 2).
687
+ */
688
+ public registerDuplicateAttestationCallback(callback: P2PDuplicateAttestationCallback): void {
689
+ this.duplicateAttestationCallback = callback;
690
+ }
691
+
688
692
  /**
689
693
  * Subscribes to a topic.
690
694
  * @param topic - The topic to subscribe to.
@@ -749,6 +753,9 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
749
753
  if (!validator || !validator.addMessage(msgId)) {
750
754
  this.instrumentation.incMessagePrevalidationStatus(false, topicType);
751
755
  this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
756
+ if (topicType === TopicType.tx) {
757
+ this.logger.verbose(`Ignoring already-seen tx gossip message`, { msgId, source: source.toString() });
758
+ }
752
759
  return { result: false, topicType };
753
760
  }
754
761
 
@@ -813,9 +820,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
813
820
  if (msg.topic === this.topicStrings[TopicType.tx]) {
814
821
  await this.handleGossipedTx(p2pMessage.payload, msgId, source);
815
822
  } else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
816
- if (this.clientType === P2PClientType.Full) {
817
- await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
818
- }
823
+ await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
819
824
  } else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
820
825
  await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
821
826
  } else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
@@ -901,21 +906,81 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
901
906
  protected async handleGossipedTx(payloadData: Buffer, msgId: string, source: PeerId) {
902
907
  const validationFunc: () => Promise<ReceivedMessageValidationResult<Tx>> = async () => {
903
908
  const tx = Tx.fromBuffer(payloadData);
904
- const isValid = await this.validatePropagatedTx(tx, source);
905
- const exists = isValid && (await this.mempools.txPool.hasTx(tx.getTxHash()));
906
909
 
907
- this.logger.trace(`Validate propagated tx`, {
908
- isValid,
909
- exists,
910
+ const currentBlockNumber = await this.archiver.getBlockNumber();
911
+ const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
912
+
913
+ // Stage 1: fast validators (metadata, data, timestamps, double-spend, gas, phases, block header)
914
+ const firstStageValidators = await this.createFirstStageMessageValidators(currentBlockNumber, nextSlotTimestamp);
915
+ const firstStageOutcome = await this.runValidations(tx, firstStageValidators);
916
+ if (!firstStageOutcome.allPassed) {
917
+ const { name } = firstStageOutcome.failure;
918
+ let { severity } = firstStageOutcome.failure;
919
+
920
+ // Double spend validator has a special case handler. We perform more detailed examination
921
+ // as to how recently the nullifier was entered into the tree and if the transaction should
922
+ // have 'known' the nullifier existed. This determines the severity of the penalty applied to the peer.
923
+ if (name === 'doubleSpendValidator') {
924
+ const txBlockNumber = BlockNumber(currentBlockNumber + 1);
925
+ severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
926
+ }
927
+
928
+ this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 1 validation failed`, {
929
+ validator: name,
930
+ severity,
931
+ source: source.toString(),
932
+ });
933
+ this.peerManager.penalizePeer(source, severity);
934
+ return { result: TopicValidatorResult.Reject };
935
+ }
936
+
937
+ // Pool pre-check: see if the pool would accept this tx before doing expensive proof verification
938
+ const canAdd = await this.mempools.txPool.canAddPendingTx(tx);
939
+ if (canAdd === 'ignored') {
940
+ this.logger.verbose(`Ignoring gossiped tx ${tx.getTxHash().toString()}: pool pre-check returned ignored`, {
941
+ source: source.toString(),
942
+ });
943
+ return { result: TopicValidatorResult.Ignore, obj: tx };
944
+ }
945
+
946
+ // Stage 2: expensive proof verification
947
+ const secondStageValidators = this.createSecondStageMessageValidators();
948
+ const secondStageOutcome = await this.runValidations(tx, secondStageValidators);
949
+ if (!secondStageOutcome.allPassed) {
950
+ const { severity, name } = secondStageOutcome.failure;
951
+ this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 2 validation failed`, {
952
+ validator: name,
953
+ severity,
954
+ source: source.toString(),
955
+ });
956
+ this.peerManager.penalizePeer(source, severity);
957
+ return { result: TopicValidatorResult.Reject };
958
+ }
959
+
960
+ // Pool add: persist the tx
961
+ const txHash = tx.getTxHash();
962
+ const addResult = await this.mempools.txPool.addPendingTxs([tx], { source: 'gossip' });
963
+
964
+ const wasAccepted = addResult.accepted.some(h => h.equals(txHash));
965
+ const wasIgnored = addResult.ignored.some(h => h.equals(txHash));
966
+
967
+ this.logger.verbose(`Validate propagated tx ${txHash.toString()}`, {
968
+ wasAccepted,
969
+ wasIgnored,
910
970
  [Attributes.P2P_ID]: source.toString(),
911
971
  });
912
972
 
913
- if (!isValid) {
914
- return { result: TopicValidatorResult.Reject };
915
- } else if (exists) {
973
+ if (wasAccepted) {
974
+ return { result: TopicValidatorResult.Accept, obj: tx };
975
+ } else if (wasIgnored) {
916
976
  return { result: TopicValidatorResult.Ignore, obj: tx };
917
977
  } else {
918
- return { result: TopicValidatorResult.Accept, obj: tx };
978
+ this.logger.warn(`Gossiped tx ${txHash.toString()} unexpectedly rejected by pool`, {
979
+ source: source.toString(),
980
+ txHash: txHash.toString(),
981
+ });
982
+ this.peerManager.penalizePeer(source, PeerErrorSeverity.HighToleranceError);
983
+ return { result: TopicValidatorResult.Reject };
919
984
  }
920
985
  };
921
986
 
@@ -924,6 +989,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
924
989
  return;
925
990
  }
926
991
 
992
+ // Tx was accepted into pool and will be propagated - just log and record metrics
927
993
  const txHash = tx.getTxHash();
928
994
  const txHashString = txHash.toString();
929
995
  this.logger.verbose(`Received tx ${txHashString} from external peer ${source.toString()} via gossip`, {
@@ -931,13 +997,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
931
997
  txHash: txHashString,
932
998
  });
933
999
 
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
1000
  this.instrumentation.incrementTxReceived(1);
940
- await this.mempools.txPool.addTxs([tx]);
941
1001
  }
942
1002
 
943
1003
  /**
@@ -991,40 +1051,53 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
991
1051
  return { result: TopicValidatorResult.Ignore, obj: attestation };
992
1052
  }
993
1053
 
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
1054
  // 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
- );
1055
+ // count is the number of attestations by this signer for this slot (for duplicate detection)
1056
+ const slot = attestation.payload.header.slotNumber;
1057
+ const { added, alreadyExists, count } =
1058
+ await this.mempools.attestationPool.tryAddCheckpointAttestation(attestation);
1004
1059
 
1005
1060
  this.logger.trace(`Validate propagated checkpoint attestation`, {
1006
1061
  added,
1007
1062
  alreadyExists,
1063
+ count,
1008
1064
  [Attributes.SLOT_NUMBER]: slot.toString(),
1009
1065
  [Attributes.P2P_ID]: peerId.toString(),
1010
1066
  });
1011
1067
 
1012
- // Duplicate attestation received, no need to re-broadcast
1068
+ // Exact same attestation received, no need to re-broadcast
1013
1069
  if (alreadyExists) {
1014
1070
  return { result: TopicValidatorResult.Ignore, obj: attestation };
1015
1071
  }
1016
1072
 
1017
- // Could not add (cap reached), no need to re-broadcast
1073
+ // Could not add (cap reached for signer), no need to re-broadcast
1018
1074
  if (!added) {
1019
- this.logger.warn(`Dropping checkpoint attestation due to per-(slot, proposalId) attestation cap`, {
1075
+ this.logger.warn(`Dropping checkpoint attestation due to cap`, {
1020
1076
  slot: slot.toString(),
1021
1077
  archive: attestation.archive.toString(),
1022
1078
  source: peerId.toString(),
1079
+ attester: attestation.getSender()?.toString(),
1080
+ count,
1023
1081
  });
1024
1082
  return { result: TopicValidatorResult.Ignore, obj: attestation };
1025
1083
  }
1026
1084
 
1027
- // Attestation was added successfully
1085
+ // Check if this is a duplicate attestation (signer attested to a different proposal at the same slot)
1086
+ // count is the number of attestations by this signer for this slot
1087
+ if (count === 2) {
1088
+ const attester = attestation.getSender();
1089
+ if (attester) {
1090
+ this.logger.warn(`Detected duplicate attestation (equivocation) at slot ${slot}`, {
1091
+ slot: slot.toString(),
1092
+ archive: attestation.archive.toString(),
1093
+ source: peerId.toString(),
1094
+ attester: attester.toString(),
1095
+ });
1096
+ this.duplicateAttestationCallback?.({ slot, attester });
1097
+ }
1098
+ }
1099
+
1100
+ // Attestation was added successfully - accept it so other nodes can also detect the equivocation
1028
1101
  return { result: TopicValidatorResult.Accept, obj: attestation };
1029
1102
  }
1030
1103
 
@@ -1070,8 +1143,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1070
1143
  }
1071
1144
 
1072
1145
  // 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;
1146
+ const { added, alreadyExists, count } = await this.mempools.attestationPool.tryAddBlockProposal(block);
1147
+ const isEquivocated = count !== undefined && count > 1;
1075
1148
 
1076
1149
  // Duplicate proposal received, no need to re-broadcast
1077
1150
  if (alreadyExists) {
@@ -1090,7 +1163,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1090
1163
  this.logger.warn(`Penalizing peer for block proposal exceeding per-position cap`, {
1091
1164
  ...block.toBlockInfo(),
1092
1165
  indexWithinCheckpoint: block.indexWithinCheckpoint,
1093
- totalForPosition,
1166
+ count,
1094
1167
  proposer: block.getSender()?.toString(),
1095
1168
  source: peerId.toString(),
1096
1169
  });
@@ -1107,7 +1180,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1107
1180
  proposer: proposer?.toString(),
1108
1181
  });
1109
1182
  // Invoke the duplicate callback on the first duplicate spotted only
1110
- if (proposer && totalForPosition === 2) {
1183
+ if (proposer && count === 2) {
1111
1184
  this.duplicateProposalCallback?.({ slot: block.slotNumber, proposer, type: 'block' });
1112
1185
  }
1113
1186
  return { result: TopicValidatorResult.Accept, obj: block, metadata: { isEquivocated } };
@@ -1132,14 +1205,14 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1132
1205
  ...block.toBlockInfo(),
1133
1206
  });
1134
1207
 
1135
- // Mark the txs in this proposal as non-evictable
1136
- await this.mempools.txPool.markTxsAsNonEvictable(block.txHashes);
1208
+ // Mark the txs in this proposal as protected
1209
+ await this.mempools.txPool.protectTxs(block.txHashes, block.blockHeader);
1137
1210
 
1138
1211
  // Call the block received callback to validate the proposal.
1139
1212
  // Note: Validators do NOT attest to individual blocks, only to checkpoint proposals.
1140
1213
  const isValid = await this.blockReceivedCallback(block, sender);
1141
1214
  if (!isValid) {
1142
- this.logger.warn(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
1215
+ this.logger.info(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
1143
1216
  }
1144
1217
  }
1145
1218
 
@@ -1224,8 +1297,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1224
1297
  // Try to add the checkpoint proposal core: this handles existence check, cap check, and adding in one call
1225
1298
  const checkpointCore = checkpoint.toCore();
1226
1299
  const tryAddResult = await this.mempools.attestationPool.tryAddCheckpointProposal(checkpointCore);
1227
- const { added, alreadyExists, totalForPosition } = tryAddResult;
1228
- const isEquivocated = totalForPosition !== undefined && totalForPosition > 1;
1300
+ const { added, alreadyExists, count } = tryAddResult;
1301
+ const isEquivocated = count !== undefined && count > 1;
1229
1302
 
1230
1303
  // Duplicate proposal received, do not re-broadcast
1231
1304
  if (alreadyExists) {
@@ -1246,7 +1319,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1246
1319
  this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
1247
1320
  this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
1248
1321
  ...checkpoint.toCheckpointInfo(),
1249
- totalForPosition,
1322
+ count,
1250
1323
  source: peerId.toString(),
1251
1324
  });
1252
1325
  return { result: TopicValidatorResult.Reject, obj: checkpoint, metadata: { isEquivocated, processBlock } };
@@ -1262,7 +1335,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1262
1335
  proposer: proposer?.toString(),
1263
1336
  });
1264
1337
  // Invoke the duplicate callback on the first duplicate spotted only
1265
- if (proposer && totalForPosition === 2) {
1338
+ if (proposer && count === 2) {
1266
1339
  this.duplicateProposalCallback?.({ slot: checkpoint.slotNumber, proposer, type: 'checkpoint' });
1267
1340
  }
1268
1341
  return {
@@ -1511,43 +1584,12 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1511
1584
  }
1512
1585
 
1513
1586
  protected createRequestedTxValidator(): TxValidator {
1514
- return createTxReqRespValidator(this.proofVerifier, {
1587
+ return createTxValidatorForReqResponseReceivedTxs(this.proofVerifier, {
1515
1588
  l1ChainId: this.config.l1ChainId,
1516
1589
  rollupVersion: this.config.rollupVersion,
1517
1590
  });
1518
1591
  }
1519
1592
 
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
1593
  private async getGasFees(blockNumber: BlockNumber): Promise<GasFees> {
1552
1594
  if (blockNumber === this.feesCache?.blockNumber) {
1553
1595
  return this.feesCache.gasFees;
@@ -1575,60 +1617,62 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1575
1617
  };
1576
1618
  }
1577
1619
 
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);
1620
+ public async validateTxsReceivedInBlockProposal(txs: Tx[]): Promise<void> {
1621
+ const validator = createTxValidatorForBlockProposalReceivedTxs(
1622
+ this.proofVerifier,
1623
+ { l1ChainId: this.config.l1ChainId, rollupVersion: this.config.rollupVersion },
1624
+ this.logger.getBindings(),
1625
+ );
1584
1626
 
1585
- await Promise.all(
1627
+ const results = await Promise.all(
1586
1628
  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
- }
1629
+ const result = await validator.validateTx(tx);
1630
+ return result.result !== 'invalid';
1593
1631
  }),
1594
1632
  );
1633
+ if (results.some(value => value === false)) {
1634
+ throw new Error('Invalid tx detected');
1635
+ }
1595
1636
  }
1596
1637
 
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(
1638
+ /** Creates the first stage (fast) validators for gossiped transactions. */
1639
+ protected async createFirstStageMessageValidators(
1608
1640
  currentBlockNumber: BlockNumber,
1609
1641
  nextSlotTimestamp: UInt64,
1610
- ): Promise<Record<string, MessageValidator>[]> {
1642
+ ): Promise<Record<string, TransactionValidator>> {
1611
1643
  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(
1644
+ const allowedInSetup = [
1645
+ ...(await getDefaultAllowedSetupFunctions()),
1646
+ ...(this.config.txPublicSetupAllowListExtend ?? []),
1647
+ ];
1648
+ const blockNumber = BlockNumber(currentBlockNumber + 1);
1649
+ const l1Constants = await this.archiver.getL1Constants();
1650
+
1651
+ return createFirstStageTxValidationsForGossipedTransactions(
1617
1652
  nextSlotTimestamp,
1618
- blockNumberInWhichTheTxIsConsideredToBeIncluded,
1653
+ blockNumber,
1619
1654
  this.worldStateSynchronizer,
1620
1655
  gasFees,
1621
1656
  this.config.l1ChainId,
1622
1657
  this.config.rollupVersion,
1623
1658
  protocolContractsHash,
1624
1659
  this.archiver,
1625
- this.proofVerifier,
1626
1660
  !this.config.disableTransactions,
1627
1661
  allowedInSetup,
1628
1662
  this.logger.getBindings(),
1663
+ {
1664
+ rollupManaLimit: l1Constants.rollupManaLimit,
1665
+ maxBlockL2Gas: this.config.validateMaxL2BlockGas,
1666
+ maxBlockDAGas: this.config.validateMaxDABlockGas,
1667
+ },
1629
1668
  );
1630
1669
  }
1631
1670
 
1671
+ /** Creates the second stage (expensive proof verification) validators for gossiped transactions. */
1672
+ protected createSecondStageMessageValidators(): Record<string, TransactionValidator> {
1673
+ return createSecondStageTxValidationsForGossipedTransactions(this.proofVerifier, this.logger.getBindings());
1674
+ }
1675
+
1632
1676
  /**
1633
1677
  * Run validations on a tx.
1634
1678
  * @param tx - The tx to validate.
@@ -1637,7 +1681,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1637
1681
  */
1638
1682
  private async runValidations(
1639
1683
  tx: Tx,
1640
- messageValidators: Record<string, MessageValidator>,
1684
+ messageValidators: Record<string, TransactionValidator>,
1641
1685
  ): Promise<ValidationOutcome> {
1642
1686
  const validationPromises = Object.entries(messageValidators).map(async ([name, { validator, severity }]) => {
1643
1687
  const { result } = await validator.validateTx(tx);
@@ -1646,8 +1690,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1646
1690
 
1647
1691
  // A promise that resolves when all validations have been run
1648
1692
  const allValidations = await Promise.all(validationPromises);
1649
- const failed = allValidations.find(x => !x.isValid);
1650
- if (failed) {
1693
+ const failures = allValidations.filter(x => !x.isValid);
1694
+ if (failures.length > 0) {
1695
+ // Pick the most severe failure (lowest tolerance = harshest penalty)
1696
+ const failed = maxBy(failures, f => PeerErrorSeverityByHarshness.indexOf(f.severity))!;
1651
1697
  return {
1652
1698
  allPassed: false,
1653
1699
  failure: {
@@ -1700,31 +1746,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1700
1746
  return PeerErrorSeverity.HighToleranceError;
1701
1747
  }
1702
1748
 
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
1749
  public getPeerScore(peerId: PeerId): number {
1729
1750
  return this.node.services.pubsub.score.score(peerId.toString());
1730
1751
  }