@aztec/p2p 0.0.1-commit.c31f2472 → 0.0.1-commit.c52d6e7

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 (559) hide show
  1. package/README.md +130 -3
  2. package/dest/bootstrap/bootstrap.d.ts +1 -1
  3. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  4. package/dest/bootstrap/bootstrap.js +22 -6
  5. package/dest/client/factory.d.ts +13 -12
  6. package/dest/client/factory.d.ts.map +1 -1
  7. package/dest/client/factory.js +67 -18
  8. package/dest/client/interface.d.ts +93 -40
  9. package/dest/client/interface.d.ts.map +1 -1
  10. package/dest/client/p2p_client.d.ts +69 -64
  11. package/dest/client/p2p_client.d.ts.map +1 -1
  12. package/dest/client/p2p_client.js +247 -244
  13. package/dest/config.d.ts +168 -89
  14. package/dest/config.d.ts.map +1 -1
  15. package/dest/config.js +157 -45
  16. package/dest/errors/p2p-service.error.d.ts +9 -0
  17. package/dest/errors/p2p-service.error.d.ts.map +1 -0
  18. package/dest/errors/p2p-service.error.js +10 -0
  19. package/dest/errors/reqresp.error.d.ts +9 -16
  20. package/dest/errors/reqresp.error.d.ts.map +1 -1
  21. package/dest/errors/reqresp.error.js +10 -17
  22. package/dest/errors/tx-pool.error.d.ts +8 -0
  23. package/dest/errors/tx-pool.error.d.ts.map +1 -0
  24. package/dest/errors/tx-pool.error.js +9 -0
  25. package/dest/index.d.ts +2 -2
  26. package/dest/index.d.ts.map +1 -1
  27. package/dest/index.js +1 -1
  28. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +164 -106
  29. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  30. package/dest/mem_pools/attestation_pool/attestation_pool.js +518 -3
  31. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
  32. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  33. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +550 -125
  34. package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
  35. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  36. package/dest/mem_pools/attestation_pool/index.js +1 -2
  37. package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
  38. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  39. package/dest/mem_pools/attestation_pool/mocks.js +7 -5
  40. package/dest/mem_pools/index.d.ts +3 -3
  41. package/dest/mem_pools/index.d.ts.map +1 -1
  42. package/dest/mem_pools/index.js +1 -1
  43. package/dest/mem_pools/instrumentation.d.ts +12 -5
  44. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  45. package/dest/mem_pools/instrumentation.js +38 -17
  46. package/dest/mem_pools/interface.d.ts +5 -5
  47. package/dest/mem_pools/interface.d.ts.map +1 -1
  48. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
  49. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
  50. package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
  51. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +39 -0
  52. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
  53. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +97 -0
  54. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
  55. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  56. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
  57. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
  58. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
  59. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +128 -0
  60. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
  61. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  62. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +94 -0
  63. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
  64. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
  65. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +99 -0
  66. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +11 -0
  67. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
  68. package/dest/mem_pools/tx_pool_v2/eviction/index.js +12 -0
  69. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
  70. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
  71. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +64 -0
  72. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +180 -0
  73. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
  74. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +25 -0
  75. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
  76. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  77. package/dest/mem_pools/{tx_pool → tx_pool_v2}/eviction/invalid_txs_after_mining_rule.js +15 -35
  78. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
  79. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  80. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +92 -0
  81. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
  82. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  83. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +79 -0
  84. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
  85. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
  86. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +75 -0
  87. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
  88. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
  89. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
  90. package/dest/mem_pools/tx_pool_v2/index.d.ts +6 -0
  91. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
  92. package/dest/mem_pools/tx_pool_v2/index.js +5 -0
  93. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  94. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  95. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  96. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +243 -0
  97. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
  98. package/dest/mem_pools/tx_pool_v2/interfaces.js +11 -0
  99. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +137 -0
  100. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
  101. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +223 -0
  102. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
  103. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
  104. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
  105. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +122 -0
  106. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
  107. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +368 -0
  108. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +68 -0
  109. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
  110. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +178 -0
  111. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +91 -0
  112. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
  113. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +1013 -0
  114. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +10 -3
  115. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  116. package/dest/msg_validators/attestation_validator/attestation_validator.js +38 -15
  117. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +8 -4
  118. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  119. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +4 -5
  120. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +12 -5
  121. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  122. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +11 -3
  123. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +12 -5
  124. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  125. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +23 -3
  126. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +36 -9
  127. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  128. package/dest/msg_validators/proposal_validator/proposal_validator.js +130 -48
  129. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
  130. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  131. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +11 -18
  132. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  133. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  134. package/dest/msg_validators/tx_validator/allowed_public_setup.js +25 -21
  135. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  136. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  137. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  138. package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
  139. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
  140. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +18 -5
  141. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  142. package/dest/msg_validators/tx_validator/block_header_validator.js +2 -2
  143. package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts +15 -0
  144. package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts.map +1 -0
  145. package/dest/msg_validators/tx_validator/cached_tx_validator.js +19 -0
  146. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
  147. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
  148. package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
  149. package/dest/msg_validators/tx_validator/data_validator.d.ts +2 -1
  150. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  151. package/dest/msg_validators/tx_validator/data_validator.js +36 -2
  152. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
  153. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  154. package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
  155. package/dest/msg_validators/tx_validator/factory.d.ts +133 -7
  156. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  157. package/dest/msg_validators/tx_validator/factory.js +261 -61
  158. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  159. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  160. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  161. package/dest/msg_validators/tx_validator/gas_validator.d.ts +104 -3
  162. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  163. package/dest/msg_validators/tx_validator/gas_validator.js +137 -53
  164. package/dest/msg_validators/tx_validator/index.d.ts +5 -1
  165. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  166. package/dest/msg_validators/tx_validator/index.js +4 -0
  167. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  168. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  169. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  170. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  171. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  172. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  173. package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
  174. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  175. package/dest/msg_validators/tx_validator/phases_validator.js +72 -24
  176. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
  177. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  178. package/dest/msg_validators/tx_validator/timestamp_validator.js +7 -7
  179. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +2 -1
  180. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  181. package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -0
  182. package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts +48 -0
  183. package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts.map +1 -0
  184. package/dest/msg_validators/tx_validator/tx_validation_cache.js +68 -0
  185. package/dest/services/data_store.d.ts +1 -1
  186. package/dest/services/data_store.d.ts.map +1 -1
  187. package/dest/services/data_store.js +14 -10
  188. package/dest/services/discv5/discV5_service.d.ts +13 -2
  189. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  190. package/dest/services/discv5/discV5_service.js +119 -23
  191. package/dest/services/discv5/persisted_enr_store.d.ts +38 -0
  192. package/dest/services/discv5/persisted_enr_store.d.ts.map +1 -0
  193. package/dest/services/discv5/persisted_enr_store.js +145 -0
  194. package/dest/services/dummy_service.d.ts +26 -18
  195. package/dest/services/dummy_service.d.ts.map +1 -1
  196. package/dest/services/dummy_service.js +25 -20
  197. package/dest/services/encoding.d.ts +24 -7
  198. package/dest/services/encoding.d.ts.map +1 -1
  199. package/dest/services/encoding.js +43 -26
  200. package/dest/services/gossipsub/index.d.ts +3 -0
  201. package/dest/services/gossipsub/index.d.ts.map +1 -0
  202. package/dest/services/gossipsub/index.js +2 -0
  203. package/dest/services/gossipsub/scoring.d.ts +21 -3
  204. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  205. package/dest/services/gossipsub/scoring.js +24 -7
  206. package/dest/services/gossipsub/topic_score_params.d.ts +167 -0
  207. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  208. package/dest/services/gossipsub/topic_score_params.js +336 -0
  209. package/dest/services/index.d.ts +2 -1
  210. package/dest/services/index.d.ts.map +1 -1
  211. package/dest/services/index.js +1 -0
  212. package/dest/services/libp2p/instrumentation.d.ts +3 -1
  213. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  214. package/dest/services/libp2p/instrumentation.js +14 -0
  215. package/dest/services/libp2p/libp2p_service.d.ts +112 -61
  216. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  217. package/dest/services/libp2p/libp2p_service.js +808 -583
  218. package/dest/services/peer-manager/metrics.d.ts +3 -1
  219. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  220. package/dest/services/peer-manager/metrics.js +6 -0
  221. package/dest/services/peer-manager/peer_manager.d.ts +20 -3
  222. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  223. package/dest/services/peer-manager/peer_manager.js +83 -26
  224. package/dest/services/peer-manager/peer_scoring.d.ts +34 -2
  225. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  226. package/dest/services/peer-manager/peer_scoring.js +127 -15
  227. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +7 -10
  228. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  229. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +100 -132
  230. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +11 -11
  231. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  232. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +11 -13
  233. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  234. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +31 -46
  235. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
  236. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  237. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
  238. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +5 -14
  239. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -1
  240. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +6 -20
  241. package/dest/services/reqresp/config.d.ts +15 -3
  242. package/dest/services/reqresp/config.d.ts.map +1 -1
  243. package/dest/services/reqresp/config.js +11 -0
  244. package/dest/services/reqresp/interface.d.ts +25 -18
  245. package/dest/services/reqresp/interface.d.ts.map +1 -1
  246. package/dest/services/reqresp/interface.js +23 -19
  247. package/dest/services/reqresp/metrics.d.ts +1 -1
  248. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  249. package/dest/services/reqresp/metrics.js +0 -1
  250. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +4 -3
  251. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  252. package/dest/services/reqresp/protocols/block_txs/bitvector.js +3 -2
  253. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +7 -5
  254. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  255. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +34 -26
  256. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +33 -17
  257. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  258. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +72 -38
  259. package/dest/services/reqresp/protocols/index.d.ts +1 -2
  260. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  261. package/dest/services/reqresp/protocols/index.js +0 -1
  262. package/dest/services/reqresp/protocols/tx.d.ts +7 -1
  263. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  264. package/dest/services/reqresp/protocols/tx.js +21 -3
  265. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
  266. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  267. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
  268. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  269. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  270. package/dest/services/reqresp/rate-limiter/rate_limits.js +3 -13
  271. package/dest/services/reqresp/reqresp.d.ts +7 -29
  272. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  273. package/dest/services/reqresp/reqresp.js +85 -219
  274. package/dest/services/service.d.ts +66 -13
  275. package/dest/services/service.d.ts.map +1 -1
  276. package/dest/services/tx_collection/config.d.ts +11 -14
  277. package/dest/services/tx_collection/config.d.ts.map +1 -1
  278. package/dest/services/tx_collection/config.js +26 -33
  279. package/dest/services/tx_collection/file_store_tx_collection.d.ts +37 -0
  280. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  281. package/dest/services/tx_collection/file_store_tx_collection.js +127 -0
  282. package/dest/services/tx_collection/file_store_tx_source.d.ts +38 -0
  283. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  284. package/dest/services/tx_collection/file_store_tx_source.js +100 -0
  285. package/dest/services/tx_collection/index.d.ts +3 -3
  286. package/dest/services/tx_collection/index.d.ts.map +1 -1
  287. package/dest/services/tx_collection/index.js +1 -1
  288. package/dest/services/tx_collection/instrumentation.js +1 -2
  289. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  290. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  291. package/dest/services/tx_collection/request_tracker.js +84 -0
  292. package/dest/services/tx_collection/tx_collection.d.ts +45 -51
  293. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  294. package/dest/services/tx_collection/tx_collection.js +296 -68
  295. package/dest/services/tx_collection/tx_collection_sink.d.ts +19 -9
  296. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  297. package/dest/services/tx_collection/tx_collection_sink.js +28 -31
  298. package/dest/services/tx_collection/tx_source.d.ts +13 -7
  299. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  300. package/dest/services/tx_collection/tx_source.js +29 -7
  301. package/dest/services/tx_file_store/config.d.ts +16 -0
  302. package/dest/services/tx_file_store/config.d.ts.map +1 -0
  303. package/dest/services/tx_file_store/config.js +22 -0
  304. package/dest/services/tx_file_store/index.d.ts +4 -0
  305. package/dest/services/tx_file_store/index.d.ts.map +1 -0
  306. package/dest/services/tx_file_store/index.js +3 -0
  307. package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
  308. package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
  309. package/dest/services/tx_file_store/instrumentation.js +29 -0
  310. package/dest/services/tx_file_store/tx_file_store.d.ts +46 -0
  311. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
  312. package/dest/services/tx_file_store/tx_file_store.js +142 -0
  313. package/dest/services/tx_provider.d.ts +6 -4
  314. package/dest/services/tx_provider.d.ts.map +1 -1
  315. package/dest/services/tx_provider.js +12 -8
  316. package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
  317. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  318. package/dest/test-helpers/make-test-p2p-clients.js +5 -3
  319. package/dest/test-helpers/mock-pubsub.d.ts +46 -6
  320. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  321. package/dest/test-helpers/mock-pubsub.js +115 -14
  322. package/dest/test-helpers/reqresp-nodes.d.ts +5 -7
  323. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  324. package/dest/test-helpers/reqresp-nodes.js +19 -20
  325. package/dest/test-helpers/test_tx_provider.d.ts +3 -1
  326. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -1
  327. package/dest/test-helpers/test_tx_provider.js +3 -0
  328. package/dest/test-helpers/testbench-utils.d.ts +58 -50
  329. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  330. package/dest/test-helpers/testbench-utils.js +181 -76
  331. package/dest/testbench/p2p_client_testbench_worker.d.ts +3 -5
  332. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  333. package/dest/testbench/p2p_client_testbench_worker.js +114 -51
  334. package/dest/testbench/worker_client_manager.d.ts +12 -6
  335. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  336. package/dest/testbench/worker_client_manager.js +57 -11
  337. package/dest/util.d.ts +13 -8
  338. package/dest/util.d.ts.map +1 -1
  339. package/dest/util.js +35 -14
  340. package/dest/versioning.d.ts +3 -6
  341. package/dest/versioning.d.ts.map +1 -1
  342. package/dest/versioning.js +3 -24
  343. package/package.json +15 -16
  344. package/src/bootstrap/bootstrap.ts +17 -3
  345. package/src/client/factory.ts +135 -31
  346. package/src/client/interface.ts +100 -48
  347. package/src/client/p2p_client.ts +289 -310
  348. package/src/client/test/{tx_proposal_collector/README.md → p2p_client.batch_tx_requester.bench.README.md} +23 -53
  349. package/src/config.ts +282 -49
  350. package/src/errors/p2p-service.error.ts +11 -0
  351. package/src/errors/reqresp.error.ts +13 -19
  352. package/src/errors/tx-pool.error.ts +12 -0
  353. package/src/index.ts +1 -1
  354. package/src/mem_pools/attestation_pool/attestation_pool.ts +585 -94
  355. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +656 -141
  356. package/src/mem_pools/attestation_pool/index.ts +9 -2
  357. package/src/mem_pools/attestation_pool/mocks.ts +14 -8
  358. package/src/mem_pools/index.ts +2 -2
  359. package/src/mem_pools/instrumentation.ts +27 -17
  360. package/src/mem_pools/interface.ts +4 -4
  361. package/src/mem_pools/tx_pool_v2/README.md +283 -0
  362. package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
  363. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +112 -0
  364. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
  365. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +160 -0
  366. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +120 -0
  367. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +126 -0
  368. package/src/mem_pools/tx_pool_v2/eviction/index.ts +28 -0
  369. package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +67 -0
  370. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +219 -0
  371. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +72 -0
  372. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +99 -0
  373. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +90 -0
  374. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +99 -0
  375. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +32 -0
  376. package/src/mem_pools/tx_pool_v2/index.ts +12 -0
  377. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  378. package/src/mem_pools/tx_pool_v2/interfaces.ts +274 -0
  379. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +349 -0
  380. package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
  381. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +465 -0
  382. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +252 -0
  383. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +1215 -0
  384. package/src/msg_validators/attestation_validator/README.md +49 -0
  385. package/src/msg_validators/attestation_validator/attestation_validator.ts +46 -14
  386. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +17 -9
  387. package/src/msg_validators/proposal_validator/README.md +123 -0
  388. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +26 -4
  389. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +43 -7
  390. package/src/msg_validators/proposal_validator/proposal_validator.ts +155 -49
  391. package/src/msg_validators/tx_validator/README.md +129 -0
  392. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +8 -17
  393. package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
  394. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  395. package/src/msg_validators/tx_validator/archive_cache.ts +2 -2
  396. package/src/msg_validators/tx_validator/block_header_validator.ts +18 -8
  397. package/src/msg_validators/tx_validator/cached_tx_validator.ts +31 -0
  398. package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
  399. package/src/msg_validators/tx_validator/data_validator.ts +44 -1
  400. package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
  401. package/src/msg_validators/tx_validator/factory.ts +413 -80
  402. package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
  403. package/src/msg_validators/tx_validator/gas_validator.ts +195 -54
  404. package/src/msg_validators/tx_validator/index.ts +4 -0
  405. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  406. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  407. package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
  408. package/src/msg_validators/tx_validator/timestamp_validator.ts +24 -19
  409. package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -0
  410. package/src/msg_validators/tx_validator/tx_validation_cache.ts +101 -0
  411. package/src/services/data_store.ts +14 -19
  412. package/src/services/discv5/discV5_service.ts +126 -14
  413. package/src/services/discv5/persisted_enr_store.ts +158 -0
  414. package/src/services/dummy_service.ts +38 -45
  415. package/src/services/encoding.ts +42 -26
  416. package/src/services/gossipsub/README.md +663 -0
  417. package/src/services/gossipsub/index.ts +2 -0
  418. package/src/services/gossipsub/scoring.ts +29 -5
  419. package/src/services/gossipsub/topic_score_params.ts +478 -0
  420. package/src/services/index.ts +1 -0
  421. package/src/services/libp2p/instrumentation.ts +14 -0
  422. package/src/services/libp2p/libp2p_service.ts +880 -641
  423. package/src/services/peer-manager/metrics.ts +7 -0
  424. package/src/services/peer-manager/peer_manager.ts +91 -25
  425. package/src/services/peer-manager/peer_scoring.ts +127 -8
  426. package/src/services/reqresp/README.md +194 -0
  427. package/src/services/reqresp/batch-tx-requester/README.md +60 -21
  428. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +101 -147
  429. package/src/services/reqresp/batch-tx-requester/interface.ts +14 -10
  430. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +30 -71
  431. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
  432. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +12 -25
  433. package/src/services/reqresp/config.ts +19 -2
  434. package/src/services/reqresp/interface.ts +45 -46
  435. package/src/services/reqresp/metrics.ts +0 -1
  436. package/src/services/reqresp/protocols/block_txs/bitvector.ts +3 -2
  437. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +43 -30
  438. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +86 -36
  439. package/src/services/reqresp/protocols/index.ts +0 -1
  440. package/src/services/reqresp/protocols/tx.ts +23 -3
  441. package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
  442. package/src/services/reqresp/rate-limiter/rate_limits.ts +3 -13
  443. package/src/services/reqresp/reqresp.ts +100 -263
  444. package/src/services/service.ts +85 -29
  445. package/src/services/tx_collection/config.ts +40 -49
  446. package/src/services/tx_collection/file_store_tx_collection.ts +153 -0
  447. package/src/services/tx_collection/file_store_tx_source.ts +129 -0
  448. package/src/services/tx_collection/index.ts +2 -6
  449. package/src/services/tx_collection/instrumentation.ts +1 -1
  450. package/src/services/tx_collection/request_tracker.ts +127 -0
  451. package/src/services/tx_collection/tx_collection.ts +362 -110
  452. package/src/services/tx_collection/tx_collection_sink.ts +32 -36
  453. package/src/services/tx_collection/tx_source.ts +29 -8
  454. package/src/services/tx_file_store/config.ts +37 -0
  455. package/src/services/tx_file_store/index.ts +3 -0
  456. package/src/services/tx_file_store/instrumentation.ts +36 -0
  457. package/src/services/tx_file_store/tx_file_store.ts +163 -0
  458. package/src/services/tx_provider.ts +15 -9
  459. package/src/test-helpers/make-test-p2p-clients.ts +7 -6
  460. package/src/test-helpers/mock-pubsub.ts +137 -14
  461. package/src/test-helpers/reqresp-nodes.ts +17 -29
  462. package/src/test-helpers/test_tx_provider.ts +5 -0
  463. package/src/test-helpers/testbench-utils.ts +188 -94
  464. package/src/testbench/p2p_client_testbench_worker.ts +123 -66
  465. package/src/testbench/worker_client_manager.ts +72 -25
  466. package/src/util.ts +40 -19
  467. package/src/versioning.ts +3 -33
  468. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +0 -2
  469. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +0 -1
  470. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +0 -305
  471. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +0 -73
  472. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +0 -1
  473. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +0 -8
  474. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
  475. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  476. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
  477. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
  478. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  479. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
  480. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
  481. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
  482. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
  483. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
  484. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
  485. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
  486. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
  487. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
  488. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
  489. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
  490. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
  491. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
  492. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
  493. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
  494. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
  495. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
  496. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
  497. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
  498. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
  499. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
  500. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
  501. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
  502. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
  503. package/dest/mem_pools/tx_pool/index.d.ts +0 -3
  504. package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
  505. package/dest/mem_pools/tx_pool/index.js +0 -2
  506. package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
  507. package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
  508. package/dest/mem_pools/tx_pool/priority.js +0 -15
  509. package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
  510. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
  511. package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
  512. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
  513. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
  514. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
  515. package/dest/msg_validators/clock_tolerance.d.ts +0 -21
  516. package/dest/msg_validators/clock_tolerance.d.ts.map +0 -1
  517. package/dest/msg_validators/clock_tolerance.js +0 -37
  518. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
  519. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  520. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
  521. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +0 -64
  522. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +0 -1
  523. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +0 -151
  524. package/dest/services/reqresp/protocols/block.d.ts +0 -9
  525. package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
  526. package/dest/services/reqresp/protocols/block.js +0 -32
  527. package/dest/services/tx_collection/fast_tx_collection.d.ts +0 -53
  528. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
  529. package/dest/services/tx_collection/fast_tx_collection.js +0 -311
  530. package/dest/services/tx_collection/proposal_tx_collector.d.ts +0 -48
  531. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +0 -1
  532. package/dest/services/tx_collection/proposal_tx_collector.js +0 -50
  533. package/dest/services/tx_collection/slow_tx_collection.d.ts +0 -53
  534. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +0 -1
  535. package/dest/services/tx_collection/slow_tx_collection.js +0 -177
  536. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +0 -336
  537. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +0 -43
  538. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
  539. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
  540. package/src/mem_pools/tx_pool/README.md +0 -270
  541. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
  542. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
  543. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
  544. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
  545. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
  546. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
  547. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
  548. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
  549. package/src/mem_pools/tx_pool/index.ts +0 -2
  550. package/src/mem_pools/tx_pool/priority.ts +0 -20
  551. package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
  552. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
  553. package/src/msg_validators/clock_tolerance.ts +0 -51
  554. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
  555. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +0 -161
  556. package/src/services/reqresp/protocols/block.ts +0 -37
  557. package/src/services/tx_collection/fast_tx_collection.ts +0 -364
  558. package/src/services/tx_collection/proposal_tx_collector.ts +0 -114
  559. package/src/services/tx_collection/slow_tx_collection.ts +0 -233
@@ -370,21 +370,24 @@ function applyDecs2203RFactory() {
370
370
  function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
371
371
  return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
372
372
  }
373
- var _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _initProto;
373
+ var _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _initProto;
374
374
  import { BlockNumber } from '@aztec/foundation/branded-types';
375
- import { randomInt } from '@aztec/foundation/crypto/random';
375
+ import { compactArray, maxBy, merge } from '@aztec/foundation/collection';
376
376
  import { createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
377
377
  import { RunningPromise } from '@aztec/foundation/running-promise';
378
378
  import { Timer } from '@aztec/foundation/timer';
379
379
  import { protocolContractsHash } from '@aztec/protocol-contracts';
380
- import { GasFees } from '@aztec/stdlib/gas';
381
- import { BlockProposal, CheckpointAttestation, CheckpointProposal, P2PClientType, P2PMessage, PeerErrorSeverity, TopicType, createTopicString, getTopicsForClientAndConfig, metricsTopicStrToLabels } from '@aztec/stdlib/p2p';
380
+ import { DEFAULT_MAX_BLOCKS_PER_CHECKPOINT } from '@aztec/stdlib/config';
381
+ import { getNetworkTxGasLimits } from '@aztec/stdlib/gas';
382
+ import { BlockProposal, CheckpointAttestation, CheckpointProposal, P2PMessage, PeerErrorSeverity, PeerErrorSeverityByHarshness, TopicType, createTopicString, getTopicsForConfig, metricsTopicStrToLabels } from '@aztec/stdlib/p2p';
383
+ import { ConsensusTimetable, getDefaultCheckpointProposalSyncGrace } from '@aztec/stdlib/timetable';
382
384
  import { MerkleTreeId } from '@aztec/stdlib/trees';
383
385
  import { Tx } from '@aztec/stdlib/tx';
386
+ import { InvalidBlockProposalTxsError } from '@aztec/stdlib/validators';
384
387
  import { compressComponentVersions } from '@aztec/stdlib/versioning';
385
388
  import { Attributes, OtelMetricsAdapter, SpanStatusCode, WithTracer, trackSpan } from '@aztec/telemetry-client';
386
389
  import { gossipsub } from '@chainsafe/libp2p-gossipsub';
387
- import { createPeerScoreParams, createTopicScoreParams } from '@chainsafe/libp2p-gossipsub/score';
390
+ import { createPeerScoreParams } from '@chainsafe/libp2p-gossipsub/score';
388
391
  import { SignaturePolicy } from '@chainsafe/libp2p-gossipsub/types';
389
392
  import { noise } from '@chainsafe/libp2p-noise';
390
393
  import { yamux } from '@chainsafe/libp2p-yamux';
@@ -393,58 +396,60 @@ import { identify } from '@libp2p/identify';
393
396
  import { TopicValidatorResult } from '@libp2p/interface';
394
397
  import { mplex } from '@libp2p/mplex';
395
398
  import { tcp } from '@libp2p/tcp';
399
+ import { multiaddr } from '@multiformats/multiaddr';
396
400
  import { ENR } from '@nethermindeth/enr';
397
401
  import { createLibp2p } from 'libp2p';
398
- import { ProposalSlotCapExceededError } from '../../errors/attestation-pool.error.js';
399
- import { BlockProposalValidator, CheckpointAttestationValidator, CheckpointProposalValidator, FishermanAttestationValidator } from '../../msg_validators/index.js';
402
+ import { CheckpointProposalReceivedCallbackNotRegisteredError } from '../../errors/p2p-service.error.js';
403
+ import { BlockProposalValidator, CheckpointAttestationValidator, CheckpointProposalValidator, DoubleSpendTxValidator, FishermanAttestationValidator, getDefaultAllowedSetupFunctions } from '../../msg_validators/index.js';
400
404
  import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
401
- import { getDefaultAllowedSetupFunctions } from '../../msg_validators/tx_validator/allowed_public_setup.js';
402
- import { createTxMessageValidators, createTxReqRespValidator } from '../../msg_validators/tx_validator/factory.js';
403
- import { DoubleSpendTxValidator } from '../../msg_validators/tx_validator/index.js';
405
+ import { createFirstStageTxValidationsForGossipedTransactions, createSecondStageTxValidationsForGossipedTransactions, createTxValidatorForBlockProposalReceivedTxs } from '../../msg_validators/tx_validator/factory.js';
404
406
  import { GossipSubEvent } from '../../types/index.js';
405
407
  import { convertToMultiaddr } from '../../util.js';
406
408
  import { getVersions } from '../../versioning.js';
407
409
  import { AztecDatastore } from '../data_store.js';
408
410
  import { DiscV5Service } from '../discv5/discV5_service.js';
409
- import { SnappyTransform, fastMsgIdFn, getMsgIdFn, msgIdToStrFn } from '../encoding.js';
410
- import { gossipScoreThresholds } from '../gossipsub/scoring.js';
411
+ import { SnappyTransform, getMsgIdFn, msgIdToStrFn } from '../encoding.js';
412
+ import { APP_SPECIFIC_WEIGHT, gossipScoreThresholds } from '../gossipsub/scoring.js';
413
+ import { createAllTopicScoreParams } from '../gossipsub/topic_score_params.js';
411
414
  import { PeerManager } from '../peer-manager/peer_manager.js';
412
415
  import { PeerScoring } from '../peer-manager/peer_scoring.js';
413
- import { DEFAULT_SUB_PROTOCOL_VALIDATORS, ReqRespSubProtocol, ValidationError } from '../reqresp/interface.js';
414
- import { reqRespBlockTxsHandler } from '../reqresp/protocols/block_txs/block_txs_handler.js';
415
- import { reqGoodbyeHandler } from '../reqresp/protocols/goodbye.js';
416
- import { pingHandler, reqRespBlockHandler, reqRespStatusHandler, reqRespTxHandler } from '../reqresp/protocols/index.js';
416
+ import { YAMUX_MAX_MESSAGE_SIZE_BYTES } from '../reqresp/config.js';
417
+ import { ReqRespSubProtocol, ValidationError, pingHandler, reqGoodbyeHandler, reqRespBlockTxsHandler, reqRespStatusHandler, reqRespTxHandler } from '../reqresp/index.js';
417
418
  import { ReqResp } from '../reqresp/reqresp.js';
418
419
  import { P2PInstrumentation } from './instrumentation.js';
419
- _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
420
+ /**
421
+ * Builds the {@link ConsensusTimetable} shared by the gossip validators for proposal/attestation receive-window
422
+ * bounds. Derived purely from protocol slot-timing constants plus the block sub-slot duration and the consensus
423
+ * materialization grace, so every node agrees on these bounds without depending on proposer operational budgets.
424
+ */ function buildConsensusTimetable(config, l1Constants) {
425
+ const blockDuration = config.blockDurationMs / 1000;
426
+ return new ConsensusTimetable({
427
+ l1Constants,
428
+ blockDuration,
429
+ checkpointProposalSyncGrace: config.checkpointProposalSyncGraceSeconds ?? getDefaultCheckpointProposalSyncGrace(blockDuration)
430
+ });
431
+ }
432
+ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId, attestation)=>({
433
+ [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toString()
434
+ })), _dec1 = trackSpan('Libp2pService.validateAndStoreBlockProposal', (_peerId, block)=>({
435
+ [Attributes.BLOCK_NUMBER]: block.blockNumber.toString(),
436
+ [Attributes.SLOT_NUMBER]: block.slotNumber.toString()
437
+ })), _dec2 = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
420
438
  [Attributes.SLOT_NUMBER]: block.slotNumber,
421
439
  [Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
422
440
  [Attributes.P2P_ID]: await block.p2pMessageLoggingIdentifier().then((i)=>i.toString())
423
- })), _dec1 = trackSpan('Libp2pService.processValidCheckpointProposal', async (checkpoint)=>({
441
+ })), _dec3 = trackSpan('Libp2pService.validateAndStoreCheckpointProposal', (_peerId, checkpoint)=>({
442
+ [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString()
443
+ })), _dec4 = trackSpan('Libp2pService.processValidCheckpointProposal', async (checkpoint)=>({
424
444
  [Attributes.SLOT_NUMBER]: checkpoint.slotNumber,
425
445
  [Attributes.BLOCK_ARCHIVE]: checkpoint.archive.toString(),
426
446
  [Attributes.P2P_ID]: await checkpoint.p2pMessageLoggingIdentifier().then((i)=>i.toString())
427
- })), _dec2 = trackSpan('Libp2pService.validateRequestedBlockTxs', (request)=>({
428
- [Attributes.BLOCK_HASH]: request.blockHash.toString()
429
- })), _dec3 = trackSpan('Libp2pService.validateRequestedTx', (requestedTxHash, _responseTx)=>({
430
- [Attributes.TX_HASH]: requestedTxHash.toString()
431
- })), _dec4 = trackSpan('Libp2pService.validateRequestedBlock', (requestedBlockNumber, _responseBlock)=>({
432
- [Attributes.BLOCK_NUMBER]: requestedBlockNumber.toString()
433
- })), _dec5 = trackSpan('Libp2pService.validatePropagatedTx', (tx)=>({
434
- [Attributes.TX_HASH]: tx.getTxHash().toString()
435
- })), _dec6 = trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation)=>({
436
- [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
437
- [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
438
- [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then((i)=>i.toString())
439
- })), _dec7 = trackSpan('Libp2pService.validateBlockProposal', (_peerId, block)=>({
440
- [Attributes.SLOT_NUMBER]: block.slotNumber.toString()
441
- })), _dec8 = trackSpan('Libp2pService.validateCheckpointProposal', (_peerId, checkpoint)=>({
442
- [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString()
447
+ })), _dec5 = trackSpan('Libp2pService.validateRequestedBlockTxsConsistency', (request)=>({
448
+ [Attributes.BLOCK_ARCHIVE]: request.archiveRoot.toString()
443
449
  }));
444
450
  /**
445
451
  * Lib P2P implementation of the P2PService interface.
446
452
  */ export class LibP2PService extends WithTracer {
447
- clientType;
448
453
  config;
449
454
  node;
450
455
  peerDiscoveryService;
@@ -455,52 +460,39 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
455
460
  epochCache;
456
461
  proofVerifier;
457
462
  worldStateSynchronizer;
463
+ blockMinFeesProvider;
464
+ txValidationCache;
458
465
  static{
459
466
  ({ e: [_initProto] } = _apply_decs_2203_r(this, [
460
467
  [
461
468
  _dec,
462
469
  2,
463
- "processValidBlockProposal"
470
+ "validateAndStoreCheckpointAttestation"
464
471
  ],
465
472
  [
466
473
  _dec1,
467
474
  2,
468
- "processValidCheckpointProposal"
475
+ "validateAndStoreBlockProposal"
469
476
  ],
470
477
  [
471
478
  _dec2,
472
479
  2,
473
- "validateRequestedBlockTxs"
480
+ "processValidBlockProposal"
474
481
  ],
475
482
  [
476
483
  _dec3,
477
484
  2,
478
- "validateRequestedTxs"
485
+ "validateAndStoreCheckpointProposal"
479
486
  ],
480
487
  [
481
488
  _dec4,
482
489
  2,
483
- "validateRequestedBlock"
490
+ "processValidCheckpointProposal"
484
491
  ],
485
492
  [
486
493
  _dec5,
487
494
  2,
488
- "validatePropagatedTx"
489
- ],
490
- [
491
- _dec6,
492
- 2,
493
- "validateCheckpointAttestation"
494
- ],
495
- [
496
- _dec7,
497
- 2,
498
- "validateBlockProposal"
499
- ],
500
- [
501
- _dec8,
502
- 2,
503
- "validateCheckpointProposal"
495
+ "validateRequestedBlockTxsConsistency"
504
496
  ]
505
497
  ], []));
506
498
  }
@@ -512,7 +504,10 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
512
504
  checkpointAttestationValidator;
513
505
  protocolVersion;
514
506
  topicStrings;
515
- feesCache;
507
+ /** Callback invoked when a duplicate proposal is detected (triggers slashing). */ duplicateProposalCallback;
508
+ /** Callback invoked when an oversized block proposal is stored as slashing evidence (triggers slashing). */ oversizedProposalCallback;
509
+ /** Callback invoked when a duplicate attestation is detected (triggers slashing). */ duplicateAttestationCallback;
510
+ /** Callback invoked when a valid checkpoint attestation is accepted into the pool. */ checkpointAttestationCallback;
516
511
  /**
517
512
  * Callback for when a block is received from a peer.
518
513
  * @param block - The block received from the peer.
@@ -522,13 +517,20 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
522
517
  * Callback for when a checkpoint proposal is received from a peer.
523
518
  * @param checkpoint - The checkpoint proposal received from the peer.
524
519
  * @returns The attestations for the checkpoint, if any.
525
- */ checkpointReceivedCallback;
520
+ */ allNodesCheckpointReceivedCallback;
521
+ /**
522
+ * Callback for when a checkpoint proposal is received - specifically for validators - from a peer.
523
+ * @param checkpoint - The checkpoint proposal received from the peer.
524
+ * @returns The attestations for the checkpoint, if any.
525
+ */ validatorCheckpointReceivedCallback;
526
526
  gossipSubEventHandler;
527
+ ipChangedHandler;
528
+ discoveredP2pIp;
527
529
  instrumentation;
528
530
  telemetry;
529
531
  logger;
530
- constructor(clientType, config, node, peerDiscoveryService, reqresp, peerManager, mempools, archiver, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger = createLogger('p2p:libp2p_service')){
531
- super(telemetry, 'LibP2PService'), this.clientType = clientType, this.config = config, this.node = node, this.peerDiscoveryService = peerDiscoveryService, this.reqresp = reqresp, this.peerManager = peerManager, this.mempools = mempools, this.archiver = archiver, this.epochCache = epochCache, this.proofVerifier = proofVerifier, this.worldStateSynchronizer = worldStateSynchronizer, this.msgIdSeenValidators = (_initProto(this), {}), this.protocolVersion = '', this.topicStrings = {};
532
+ constructor(config, node, peerDiscoveryService, reqresp, peerManager, mempools, archiver, epochCache, proofVerifier, worldStateSynchronizer, blockMinFeesProvider, telemetry, logger = createLogger('p2p:libp2p_service'), txValidationCache){
533
+ super(telemetry, 'LibP2PService'), this.config = config, this.node = node, this.peerDiscoveryService = peerDiscoveryService, this.reqresp = reqresp, this.peerManager = peerManager, this.mempools = mempools, this.archiver = archiver, this.epochCache = epochCache, this.proofVerifier = proofVerifier, this.worldStateSynchronizer = worldStateSynchronizer, this.blockMinFeesProvider = blockMinFeesProvider, this.txValidationCache = txValidationCache, this.msgIdSeenValidators = (_initProto(this), {}), this.protocolVersion = '', this.topicStrings = {};
532
534
  this.telemetry = telemetry;
533
535
  // Create child logger with fisherman prefix if in fisherman mode
534
536
  this.logger = config.fishermanMode ? logger.createChild('[FISHERMAN]') : logger;
@@ -544,40 +546,57 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
544
546
  this.topicStrings[TopicType.block_proposal] = createTopicString(TopicType.block_proposal, this.protocolVersion);
545
547
  this.topicStrings[TopicType.checkpoint_proposal] = createTopicString(TopicType.checkpoint_proposal, this.protocolVersion);
546
548
  this.topicStrings[TopicType.checkpoint_attestation] = createTopicString(TopicType.checkpoint_attestation, this.protocolVersion);
547
- this.blockProposalValidator = new BlockProposalValidator(epochCache, {
548
- txsPermitted: !config.disableTransactions
549
- });
550
- this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, {
551
- txsPermitted: !config.disableTransactions
552
- });
553
- this.checkpointAttestationValidator = config.fishermanMode ? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry) : new CheckpointAttestationValidator(epochCache);
549
+ // Build the consensus timetable once from protocol slot-timing constants and inject it into every
550
+ // validator so they share one set of receive-window bounds, independent of proposer operational budgets.
551
+ const consensusTimetable = buildConsensusTimetable(config, epochCache.getL1Constants());
552
+ const proposalValidatorOpts = {
553
+ txsPermitted: !config.disableTransactions,
554
+ maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
555
+ maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
556
+ skipSlotValidation: config.skipProposalSlotValidation,
557
+ signatureContext: {
558
+ chainId: config.l1ChainId,
559
+ rollupAddress: config.rollupAddress
560
+ },
561
+ clockDisparityMs: config.maxGossipClockDisparityMs
562
+ };
563
+ this.blockProposalValidator = new BlockProposalValidator(epochCache, consensusTimetable, proposalValidatorOpts);
564
+ this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, consensusTimetable, proposalValidatorOpts);
565
+ const attestationValidatorOpts = {
566
+ signatureContext: proposalValidatorOpts.signatureContext,
567
+ clockDisparityMs: config.maxGossipClockDisparityMs
568
+ };
569
+ this.checkpointAttestationValidator = config.fishermanMode ? new FishermanAttestationValidator(epochCache, consensusTimetable, mempools.attestationPool, telemetry, attestationValidatorOpts) : new CheckpointAttestationValidator(epochCache, consensusTimetable, attestationValidatorOpts);
554
570
  this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
555
571
  this.blockReceivedCallback = async (block)=>{
556
- this.logger.debug(`Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber} from peer.`, {
572
+ this.logger.warn(`Handler for block received not yet registered on P2P service. Received block ${block.blockNumber} for slot ${block.slotNumber} from peer.`, {
557
573
  p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier()
558
574
  });
559
- return false;
575
+ return true;
576
+ };
577
+ this.allNodesCheckpointReceivedCallback = (_checkpoint)=>{
578
+ throw new CheckpointProposalReceivedCallbackNotRegisteredError();
560
579
  };
561
- this.checkpointReceivedCallback = (checkpoint)=>{
562
- this.logger.debug(`Handler not yet registered: Checkpoint received callback not set. Received checkpoint for slot ${checkpoint.slotNumber} from peer.`);
580
+ this.validatorCheckpointReceivedCallback = (_checkpoint)=>{
563
581
  return Promise.resolve(undefined);
564
582
  };
565
583
  }
566
584
  updateConfig(config) {
567
585
  this.reqresp.updateConfig(config);
586
+ this.config = merge(this.config, config);
568
587
  }
569
588
  /**
570
589
  * Creates an instance of the LibP2P service.
571
590
  * @param config - The configuration to use when creating the service.
572
591
  * @param txPool - The transaction pool to be accessed by the service.
573
592
  * @returns The new service.
574
- */ static async new(clientType, config, peerId, deps) {
575
- const { worldStateSynchronizer, epochCache, l2BlockSource, mempools, proofVerifier, peerStore, telemetry, logger, packageVersion } = deps;
593
+ */ static async new(config, peerId, deps) {
594
+ const { worldStateSynchronizer, epochCache, l2BlockSource, mempools, proofVerifier, peerStore, blockMinFeesProvider, telemetry, logger, packageVersion, txValidationCache } = deps;
576
595
  const { p2pPort, maxPeerCount, listenAddress } = config;
577
596
  const bindAddrTcp = convertToMultiaddr(listenAddress, p2pPort, 'tcp');
578
597
  const datastore = new AztecDatastore(peerStore);
579
598
  const otelMetricsAdapter = new OtelMetricsAdapter(telemetry, logger.getBindings());
580
- const peerDiscoveryService = new DiscV5Service(peerId, config, packageVersion, telemetry, createLogger(`${logger.module}:discv5_service`, logger.getBindings()));
599
+ const peerDiscoveryService = new DiscV5Service(peerId, config, packageVersion, telemetry, createLogger(`${logger.module}:discv5_service`, logger.getBindings()), peerStore);
581
600
  // Seed libp2p's bootstrap discovery with private and trusted peers
582
601
  const bootstrapNodes = [
583
602
  ...config.privatePeers,
@@ -591,27 +610,46 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
591
610
  }
592
611
  const versions = getVersions(config);
593
612
  const protocolVersion = compressComponentVersions(versions);
594
- const txTopic = createTopicString(TopicType.tx, protocolVersion);
595
- const blockProposalTopic = createTopicString(TopicType.block_proposal, protocolVersion);
596
- const checkpointProposalTopic = createTopicString(TopicType.checkpoint_proposal, protocolVersion);
597
- const checkpointAttestationTopic = createTopicString(TopicType.checkpoint_attestation, protocolVersion);
598
613
  const preferredPeersEnrs = config.preferredPeers.map((enr)=>ENR.decodeTxt(enr));
599
- const directPeers = (await Promise.all(preferredPeersEnrs.map(async (enr)=>{
600
- const peerId = await enr.peerId();
601
- const address = enr.getLocationMultiaddr('tcp');
602
- if (address === undefined) {
603
- throw new Error(`Direct peer ${peerId.toString()} has no TCP address, ENR: ${enr.encodeTxt()}`);
614
+ const directPeers = compactArray(await Promise.all(preferredPeersEnrs.map(async (enr)=>{
615
+ try {
616
+ const peerId = await enr.peerId();
617
+ const address = enr.getLocationMultiaddr('tcp');
618
+ if (address === undefined) {
619
+ throw new Error(`Direct peer ${peerId.toString()} has no TCP address, ENR: ${enr.encodeTxt()}`);
620
+ }
621
+ return {
622
+ id: peerId,
623
+ addrs: [
624
+ address
625
+ ]
626
+ };
627
+ } catch (err) {
628
+ // A malformed configured ENR shouldn't abort node setup — skip it and log.
629
+ logger.warn(`Skipping preferred peer with invalid ENR`, {
630
+ err
631
+ });
632
+ return undefined;
604
633
  }
605
- return {
606
- id: peerId,
607
- addrs: [
608
- address
609
- ]
610
- };
611
- }))).filter((peer)=>peer !== undefined);
634
+ })));
612
635
  const announceTcpMultiaddr = config.p2pIp ? [
613
636
  convertToMultiaddr(config.p2pIp, p2pPort, 'tcp')
614
637
  ] : [];
638
+ // Create dynamic topic score params based on network configuration. Scoring uses the network-wide
639
+ // max-blocks-per-checkpoint config value directly to size expected per-slot message rates; these are
640
+ // peer-rate thresholds, not consensus deadlines, so they need no proposer operational budgets.
641
+ const l1Constants = epochCache.getL1Constants();
642
+ const topicScoreParams = createAllTopicScoreParams(protocolVersion, {
643
+ slotDurationMs: l1Constants.slotDuration * 1000,
644
+ heartbeatIntervalMs: config.gossipsubInterval,
645
+ targetCommitteeSize: l1Constants.targetCommitteeSize,
646
+ maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint ?? DEFAULT_MAX_BLOCKS_PER_CHECKPOINT,
647
+ expectedBlockProposalsPerSlot: config.expectedBlockProposalsPerSlot
648
+ });
649
+ // Restrict gossipsub to exactly the topics we subscribe to. Without this, an arbitrary-topic
650
+ // message is transformed, msg-id'd and inserted into the seenCache before the subscription check,
651
+ // so a crafted topic colliding on msg id can suppress a real message as a duplicate.
652
+ const allowedTopics = getTopicsForConfig(config.disableTransactions).map((topic)=>createTopicString(topic, protocolVersion));
615
653
  const node = await createLibp2p({
616
654
  start: false,
617
655
  peerId,
@@ -645,8 +683,11 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
645
683
  ],
646
684
  datastore,
647
685
  peerDiscovery,
686
+ // Pin the yamux frame size: MAX_REQRESP_REQUEST_SIZE_BYTES relies on a reqresp request fitting in one frame.
648
687
  streamMuxers: [
649
- yamux(),
688
+ yamux({
689
+ maxMessageSize: YAMUX_MAX_MESSAGE_SIZE_BYTES
690
+ }),
650
691
  mplex()
651
692
  ],
652
693
  connectionEncryption: [
@@ -664,7 +705,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
664
705
  },
665
706
  connectionGater: {
666
707
  denyInboundConnection: (maConn)=>{
667
- const allowed = peerManager.isNodeAllowedToConnect(maConn.remoteAddr.nodeAddress().address);
708
+ const allowed = peerManager.isAddressAllowedToConnect(maConn.remoteAddr.nodeAddress().address);
668
709
  if (allowed) {
669
710
  return false;
670
711
  }
@@ -674,7 +715,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
674
715
  denyInboundEncryptedConnection: (peerId, _maConn)=>{
675
716
  //NOTE: it is not necessary to check address here because this was already done by
676
717
  // denyInboundConnection
677
- const allowed = peerManager.isNodeAllowedToConnect(peerId);
718
+ const allowed = peerManager.isPeerAllowedToConnect(peerId);
678
719
  if (allowed) {
679
720
  return false;
680
721
  }
@@ -701,9 +742,13 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
701
742
  mcacheLength: config.gossipsubMcacheLength,
702
743
  mcacheGossip: config.gossipsubMcacheGossip,
703
744
  seenTTL: config.gossipsubSeenTTL,
745
+ allowedTopics,
746
+ // No fastMsgIdFn: the fast-path dedup cache keys on a non-cryptographic 64-bit hash of the
747
+ // raw data only (no topic), so a collision — accidental or engineered via a weak seed — drops
748
+ // a different message with no fallback to the full id. Dedup instead rests solely on the
749
+ // cryptographic, topic-framed msgIdFn below.
704
750
  msgIdFn: getMsgIdFn,
705
751
  msgIdToStrFn: msgIdToStrFn,
706
- fastMsgIdFn: fastMsgIdFn,
707
752
  dataTransform: new SnappyTransform(),
708
753
  metricsRegister: otelMetricsAdapter,
709
754
  metricsTopicStrToLabel: metricsTopicStrToLabels(protocolVersion),
@@ -712,32 +757,12 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
712
757
  scoreParams: createPeerScoreParams({
713
758
  // IPColocation factor can be disabled for local testing - default to -5
714
759
  IPColocationFactorWeight: config.debugDisableColocationPenalty ? 0 : -5.0,
715
- topics: {
716
- [txTopic]: createTopicScoreParams({
717
- topicWeight: 1,
718
- invalidMessageDeliveriesWeight: -20,
719
- invalidMessageDeliveriesDecay: 0.5
720
- }),
721
- [blockProposalTopic]: createTopicScoreParams({
722
- topicWeight: 1,
723
- invalidMessageDeliveriesWeight: -20,
724
- invalidMessageDeliveriesDecay: 0.5
725
- }),
726
- [checkpointProposalTopic]: createTopicScoreParams({
727
- topicWeight: 1,
728
- invalidMessageDeliveriesWeight: -20,
729
- invalidMessageDeliveriesDecay: 0.5
730
- }),
731
- [checkpointAttestationTopic]: createTopicScoreParams({
732
- topicWeight: 1,
733
- invalidMessageDeliveriesWeight: -20,
734
- invalidMessageDeliveriesDecay: 0.5
735
- })
736
- }
760
+ topics: topicScoreParams
737
761
  })
738
762
  }),
739
763
  components: (components)=>({
740
- connectionManager: components.connectionManager
764
+ connectionManager: components.connectionManager,
765
+ addressManager: components.addressManager
741
766
  })
742
767
  },
743
768
  logger: createLibp2pComponentLogger(logger.module, logger.getBindings())
@@ -745,10 +770,16 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
745
770
  const peerScoring = new PeerScoring(config, telemetry);
746
771
  const reqresp = new ReqResp(config, node, peerScoring, createLogger(`${logger.module}:reqresp`));
747
772
  const peerManager = new PeerManager(node, peerDiscoveryService, config, telemetry, createLogger(`${logger.module}:peer_manager`), peerScoring, reqresp, worldStateSynchronizer, protocolVersion, epochCache);
748
- // Update gossipsub score params
749
- node.services.pubsub.score.params.appSpecificWeight = 10;
773
+ // Gate req/resp data protocols for unauthenticated peers when p2pAllowOnlyValidators is enabled
774
+ reqresp.setShouldRejectPeer((peerId)=>peerManager.shouldDisableP2PGossip(peerId));
775
+ // Configure application-specific scoring for gossipsub.
776
+ // The weight scales app score to align with gossipsub thresholds:
777
+ // - Disconnect (-50) × 10 = -500 = gossipThreshold (stops receiving gossip)
778
+ // - Ban (-100) × 10 = -1000 = publishThreshold (cannot publish)
779
+ // Note: positive topic scores can offset penalties, so alignment is best-effort.
780
+ node.services.pubsub.score.params.appSpecificWeight = APP_SPECIFIC_WEIGHT;
750
781
  node.services.pubsub.score.params.appSpecificScore = (peerId)=>peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
751
- return new LibP2PService(clientType, config, node, peerDiscoveryService, reqresp, peerManager, mempools, l2BlockSource, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger);
782
+ return new LibP2PService(config, node, peerDiscoveryService, reqresp, peerManager, mempools, l2BlockSource, epochCache, proofVerifier, worldStateSynchronizer, blockMinFeesProvider, telemetry, logger, txValidationCache);
752
783
  }
753
784
  /**
754
785
  * Starts the LibP2P service.
@@ -758,42 +789,32 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
758
789
  if (this.node.status === 'started') {
759
790
  throw new Error('P2P service already started');
760
791
  }
761
- // Get listen & announce addresses for logging
762
792
  const { p2pIp, p2pPort } = this.config;
763
- if (!p2pIp) {
764
- throw new Error('Announce address not provided.');
793
+ if (!p2pIp && !this.config.queryForIp) {
794
+ throw new Error('Announce address not provided and queryForIp is not enabled.');
765
795
  }
766
- const announceTcpMultiaddr = convertToMultiaddr(p2pIp, p2pPort, 'tcp');
796
+ const announceTcpMultiaddr = p2pIp ? convertToMultiaddr(p2pIp, p2pPort, 'tcp') : undefined;
767
797
  // Create request response protocol handlers
768
798
  const txHandler = reqRespTxHandler(this.mempools);
769
799
  const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
770
- const blockHandler = reqRespBlockHandler(this.archiver);
771
800
  const statusHandler = reqRespStatusHandler(this.protocolVersion, this.worldStateSynchronizer, this.logger);
772
801
  const requestResponseHandlers = {
773
802
  [ReqRespSubProtocol.PING]: pingHandler,
774
803
  [ReqRespSubProtocol.STATUS]: statusHandler.bind(this),
775
- [ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this),
776
- [ReqRespSubProtocol.BLOCK]: blockHandler.bind(this)
804
+ [ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this)
777
805
  };
778
806
  if (!this.config.disableTransactions) {
779
- const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.mempools.txPool);
807
+ const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.archiver, this.mempools.txPool);
780
808
  requestResponseHandlers[ReqRespSubProtocol.BLOCK_TXS] = blockTxsHandler.bind(this);
781
809
  }
782
810
  if (!this.config.disableTransactions) {
783
811
  requestResponseHandlers[ReqRespSubProtocol.TX] = txHandler.bind(this);
784
812
  }
785
- // Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
786
- const reqrespSubProtocolValidators = {
787
- ...DEFAULT_SUB_PROTOCOL_VALIDATORS,
788
- [ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
789
- [ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
790
- [ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this)
791
- };
792
813
  await this.peerManager.initializePeers();
793
- await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
814
+ await this.reqresp.start(requestResponseHandlers);
794
815
  await this.node.start();
795
816
  // Subscribe to standard GossipSub topics by default
796
- for (const topic of getTopicsForClientAndConfig(this.clientType, this.config.disableTransactions)){
817
+ for (const topic of getTopicsForConfig(this.config.disableTransactions)){
797
818
  this.subscribeToTopic(this.topicStrings[topic]);
798
819
  }
799
820
  // add GossipSub listener
@@ -802,6 +823,34 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
802
823
  if (!this.config.p2pDiscoveryDisabled) {
803
824
  await this.peerDiscoveryService.start();
804
825
  }
826
+ // Bridge discv5 IP changes to libp2p's AddressManager so peers see the updated address
827
+ if (this.config.queryForIp) {
828
+ this.discoveredP2pIp = this.config.p2pIp;
829
+ this.logger.info('IP change tracking enabled, bridging discv5 IP updates to libp2p AddressManager');
830
+ this.ipChangedHandler = (ip)=>{
831
+ const addressManager = this.node.services.components.addressManager;
832
+ const newAddr = multiaddr(convertToMultiaddr(ip, this.config.p2pPort, 'tcp'));
833
+ const previousIp = this.discoveredP2pIp;
834
+ if (previousIp) {
835
+ const oldAddr = multiaddr(convertToMultiaddr(previousIp, this.config.p2pPort, 'tcp'));
836
+ addressManager.removeObservedAddr(oldAddr);
837
+ this.logger.info('Libp2p announce address updated due to IP change', {
838
+ previousIp,
839
+ newIp: ip,
840
+ newMultiaddr: newAddr.toString()
841
+ });
842
+ } else {
843
+ this.logger.info('Libp2p announce address set from initial discv5 IP discovery', {
844
+ ip,
845
+ multiaddr: newAddr.toString()
846
+ });
847
+ }
848
+ addressManager.addObservedAddr(newAddr);
849
+ addressManager.confirmObservedAddr(newAddr);
850
+ this.discoveredP2pIp = ip;
851
+ };
852
+ this.peerDiscoveryService.on('ip:changed', this.ipChangedHandler);
853
+ }
805
854
  this.discoveryRunningPromise = new RunningPromise(async ()=>{
806
855
  await this.peerManager.heartbeat();
807
856
  }, this.logger, this.config.peerCheckIntervalMS);
@@ -819,6 +868,10 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
819
868
  */ async stop() {
820
869
  // Remove gossip sub listener
821
870
  this.node.services.pubsub.removeEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
871
+ if (this.ipChangedHandler) {
872
+ this.peerDiscoveryService.removeListener('ip:changed', this.ipChangedHandler);
873
+ this.ipChangedHandler = undefined;
874
+ }
822
875
  // Stop peer manager
823
876
  this.logger.debug('Stopping peer manager...');
824
877
  await this.peerManager.stop();
@@ -832,8 +885,8 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
832
885
  await this.stopLibP2P();
833
886
  this.logger.info('LibP2P service stopped');
834
887
  }
835
- addReqRespSubProtocol(subProtocol, handler, validator) {
836
- return this.reqresp.addSubProtocol(subProtocol, handler, validator);
888
+ addReqRespSubProtocol(subProtocol, handler) {
889
+ return this.reqresp.addSubProtocol(subProtocol, handler);
837
890
  }
838
891
  registerThisValidatorAddresses(address) {
839
892
  this.peerManager.registerThisValidatorAddresses(address);
@@ -841,6 +894,9 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
841
894
  getPeers(includePending) {
842
895
  return this.peerManager.getPeers(includePending);
843
896
  }
897
+ getGossipMeshPeerCount(topicType) {
898
+ return this.node.services.pubsub.getMeshPeers(this.topicStrings[topicType]).length;
899
+ }
844
900
  handleGossipSubEvent(e) {
845
901
  this.logger.trace(`Received PUBSUB message.`);
846
902
  const safeJob = async ()=>{
@@ -852,14 +908,6 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
852
908
  };
853
909
  setImmediate(()=>void safeJob());
854
910
  }
855
- /**
856
- * Send a batch of requests to peers, and return the responses
857
- * @param protocol - The request response protocol to use
858
- * @param requests - The requests to send to the peers
859
- * @returns The responses to the requests
860
- */ sendBatchRequest(protocol, requests, pinnedPeerId) {
861
- return this.reqresp.sendBatchRequest(protocol, requests, pinnedPeerId);
862
- }
863
911
  sendRequestToPeer(peerId, subProtocol, payload, dialTimeout) {
864
912
  return this.reqresp.sendRequestToPeer(peerId, subProtocol, payload, dialTimeout);
865
913
  }
@@ -872,8 +920,32 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
872
920
  registerBlockReceivedCallback(callback) {
873
921
  this.blockReceivedCallback = callback;
874
922
  }
875
- registerCheckpointReceivedCallback(callback) {
876
- this.checkpointReceivedCallback = callback;
923
+ registerValidatorCheckpointReceivedCallback(callback) {
924
+ this.validatorCheckpointReceivedCallback = callback;
925
+ }
926
+ registerAllNodesCheckpointReceivedCallback(callback) {
927
+ this.allNodesCheckpointReceivedCallback = callback;
928
+ }
929
+ /**
930
+ * Registers a callback to be invoked when a duplicate proposal is detected.
931
+ * This callback is triggered on the first duplicate (when count goes from 1 to 2).
932
+ */ registerDuplicateProposalCallback(callback) {
933
+ this.duplicateProposalCallback = callback;
934
+ }
935
+ /**
936
+ * Registers a callback to be invoked when an oversized block proposal is stored as slashing evidence.
937
+ */ registerOversizedProposalCallback(callback) {
938
+ this.oversizedProposalCallback = callback;
939
+ }
940
+ /**
941
+ * Registers a callback to be invoked when a duplicate attestation is detected.
942
+ * A validator signing attestations for different proposals at the same slot.
943
+ * This callback is triggered on the first duplicate (when count goes from 1 to 2).
944
+ */ registerDuplicateAttestationCallback(callback) {
945
+ this.duplicateAttestationCallback = callback;
946
+ }
947
+ registerCheckpointAttestationCallback(callback) {
948
+ this.checkpointAttestationCallback = callback;
877
949
  }
878
950
  /**
879
951
  * Subscribes to a topic.
@@ -926,6 +998,12 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
926
998
  if (!validator || !validator.addMessage(msgId)) {
927
999
  this.instrumentation.incMessagePrevalidationStatus(false, topicType);
928
1000
  this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
1001
+ if (topicType === TopicType.tx) {
1002
+ this.logger.verbose(`Ignoring already-seen tx gossip message`, {
1003
+ msgId,
1004
+ source: source.toString()
1005
+ });
1006
+ }
929
1007
  return {
930
1008
  result: false,
931
1009
  topicType
@@ -983,12 +1061,17 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
983
1061
  }
984
1062
  // Process the message, optionally within a linked span for trace propagation
985
1063
  const processMessage = async ()=>{
1064
+ if (this.config.skipIncomingProposals && (msg.topic === this.topicStrings[TopicType.block_proposal] || msg.topic === this.topicStrings[TopicType.checkpoint_proposal])) {
1065
+ this.logger.warn(`Ignoring incoming proposal (skipIncomingProposals is set)`, {
1066
+ topic: msg.topic
1067
+ });
1068
+ this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
1069
+ return;
1070
+ }
986
1071
  if (msg.topic === this.topicStrings[TopicType.tx]) {
987
1072
  await this.handleGossipedTx(p2pMessage.payload, msgId, source);
988
1073
  } else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
989
- if (this.clientType === P2PClientType.Full) {
990
- await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
991
- }
1074
+ await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
992
1075
  } else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
993
1076
  await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
994
1077
  } else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
@@ -1033,49 +1116,162 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1033
1116
  return;
1034
1117
  }
1035
1118
  async validateReceivedMessage(validationFunc, msgId, source, topicType) {
1119
+ // Default to reject result with a penalty if validation function throws an error
1036
1120
  let resultAndObj = {
1037
- result: TopicValidatorResult.Reject
1121
+ result: TopicValidatorResult.Reject,
1122
+ severity: PeerErrorSeverity.MidToleranceError
1038
1123
  };
1039
1124
  const timer = new Timer();
1040
1125
  try {
1041
1126
  resultAndObj = await validationFunc();
1042
1127
  } catch (err) {
1043
- this.peerManager.penalizePeer(source, PeerErrorSeverity.LowToleranceError);
1044
- this.logger.error(`Error deserializing and validating gossipsub message`, err, {
1128
+ this.logger.error(`Error validating gossipsub message`, err, {
1045
1129
  msgId,
1046
1130
  source: source.toString(),
1047
1131
  topicType
1048
1132
  });
1049
1133
  }
1134
+ const validationTimeMs = timer.ms();
1135
+ const mcacheWindowMs = this.config.gossipsubMcacheLength * this.config.gossipsubInterval;
1136
+ if (validationTimeMs > mcacheWindowMs * 0.75) {
1137
+ this.instrumentation.incSlowValidation(topicType);
1138
+ this.logger.warn(`Gossip validation for ${topicType} took ${validationTimeMs}ms, approaching mcache eviction window of ${mcacheWindowMs}ms. ` + `Message forwarding may be skipped if validation exceeds the window.`, {
1139
+ msgId,
1140
+ source: source.toString(),
1141
+ topicType,
1142
+ validationTimeMs,
1143
+ mcacheWindowMs
1144
+ });
1145
+ }
1050
1146
  if (resultAndObj.result === TopicValidatorResult.Accept) {
1147
+ this.logger.debug(`Message ${topicType} accepted by validator`, {
1148
+ msgId,
1149
+ source: source.toString(),
1150
+ topicType
1151
+ });
1051
1152
  this.instrumentation.recordMessageValidation(topicType, timer);
1153
+ } else if (resultAndObj.result === TopicValidatorResult.Reject) {
1154
+ this.logger.warn(`Message ${topicType} rejected by validator with severity ${resultAndObj.severity}`, {
1155
+ msgId,
1156
+ source: source.toString(),
1157
+ topicType,
1158
+ severity: resultAndObj.severity
1159
+ });
1160
+ this.peerManager.penalizePeer(source, resultAndObj.severity);
1161
+ } else {
1162
+ this.logger.trace(`Message ${topicType} ignored by validator`, {
1163
+ msgId,
1164
+ source: source.toString(),
1165
+ topicType
1166
+ });
1052
1167
  }
1053
1168
  this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result);
1054
1169
  return resultAndObj;
1055
1170
  }
1171
+ tryDeserialize(deserializeFunc, msgId, source) {
1172
+ try {
1173
+ return deserializeFunc();
1174
+ } catch (err) {
1175
+ this.logger.warn(`Failed to deserialize gossipsub message from buffer`, {
1176
+ err,
1177
+ msgId,
1178
+ source: source.toString()
1179
+ });
1180
+ return undefined;
1181
+ }
1182
+ }
1056
1183
  async handleGossipedTx(payloadData, msgId, source) {
1057
1184
  const validationFunc = async ()=>{
1058
- const tx = Tx.fromBuffer(payloadData);
1059
- const isValid = await this.validatePropagatedTx(tx, source);
1060
- const exists = isValid && await this.mempools.txPool.hasTx(tx.getTxHash());
1061
- this.logger.trace(`Validate propagated tx`, {
1062
- isValid,
1063
- exists,
1185
+ const tx = this.tryDeserialize(()=>Tx.fromBuffer(payloadData), msgId, source);
1186
+ if (!tx) {
1187
+ return {
1188
+ result: TopicValidatorResult.Reject,
1189
+ severity: PeerErrorSeverity.LowToleranceError
1190
+ };
1191
+ }
1192
+ const currentBlockNumber = await this.archiver.getBlockNumber();
1193
+ const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1194
+ // Stage 1: fast validators (metadata, data, timestamps, double-spend, gas, phases, block header)
1195
+ const firstStageValidators = await this.createFirstStageMessageValidators(currentBlockNumber, nextSlotTimestamp);
1196
+ const firstStageOutcome = await this.runValidations(tx, firstStageValidators);
1197
+ if (!firstStageOutcome.allPassed) {
1198
+ const { name } = firstStageOutcome.failure;
1199
+ let { severity } = firstStageOutcome.failure;
1200
+ // Double spend validator has a special case handler. We perform more detailed examination
1201
+ // as to how recently the nullifier was entered into the tree and if the transaction should
1202
+ // have 'known' the nullifier existed. This determines the severity of the penalty applied to the peer.
1203
+ if (name === 'doubleSpendValidator') {
1204
+ const txBlockNumber = BlockNumber(currentBlockNumber + 1);
1205
+ severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
1206
+ }
1207
+ this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 1 validation failed`, {
1208
+ validator: name,
1209
+ severity,
1210
+ source: source.toString()
1211
+ });
1212
+ return {
1213
+ result: TopicValidatorResult.Reject,
1214
+ severity
1215
+ };
1216
+ }
1217
+ // Pool pre-check: see if the pool would accept this tx before doing expensive proof verification
1218
+ const canAdd = await this.mempools.txPool.canAddPendingTx(tx);
1219
+ if (canAdd === 'ignored') {
1220
+ this.logger.verbose(`Ignoring gossiped tx ${tx.getTxHash().toString()}: pool pre-check returned ignored`, {
1221
+ source: source.toString()
1222
+ });
1223
+ return {
1224
+ result: TopicValidatorResult.Ignore,
1225
+ obj: tx
1226
+ };
1227
+ }
1228
+ // Stage 2: expensive proof verification
1229
+ const secondStageValidators = this.createSecondStageMessageValidators();
1230
+ const secondStageOutcome = await this.runValidations(tx, secondStageValidators);
1231
+ if (!secondStageOutcome.allPassed) {
1232
+ const { severity, name } = secondStageOutcome.failure;
1233
+ this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 2 validation failed`, {
1234
+ validator: name,
1235
+ severity,
1236
+ source: source.toString()
1237
+ });
1238
+ return {
1239
+ result: TopicValidatorResult.Reject,
1240
+ severity
1241
+ };
1242
+ }
1243
+ // Pool add: persist the tx
1244
+ const txHash = tx.getTxHash();
1245
+ const addResult = await this.mempools.txPool.addPendingTxs([
1246
+ tx
1247
+ ], {
1248
+ source: 'gossip'
1249
+ });
1250
+ const wasAccepted = addResult.accepted.some((h)=>h.equals(txHash));
1251
+ const wasIgnored = addResult.ignored.some((h)=>h.equals(txHash));
1252
+ this.logger.verbose(`Validate propagated tx ${txHash.toString()}`, {
1253
+ wasAccepted,
1254
+ wasIgnored,
1064
1255
  [Attributes.P2P_ID]: source.toString()
1065
1256
  });
1066
- if (!isValid) {
1257
+ if (wasAccepted) {
1067
1258
  return {
1068
- result: TopicValidatorResult.Reject
1259
+ result: TopicValidatorResult.Accept,
1260
+ obj: tx
1069
1261
  };
1070
- } else if (exists) {
1262
+ } else if (wasIgnored) {
1071
1263
  return {
1072
1264
  result: TopicValidatorResult.Ignore,
1073
1265
  obj: tx
1074
1266
  };
1075
1267
  } else {
1268
+ this.logger.warn(`Gossiped tx ${txHash.toString()} unexpectedly rejected by pool`, {
1269
+ source: source.toString(),
1270
+ txHash: txHash.toString()
1271
+ });
1076
1272
  return {
1077
- result: TopicValidatorResult.Accept,
1078
- obj: tx
1273
+ result: TopicValidatorResult.Reject,
1274
+ severity: PeerErrorSeverity.HighToleranceError
1079
1275
  };
1080
1276
  }
1081
1277
  };
@@ -1083,133 +1279,230 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1083
1279
  if (result !== TopicValidatorResult.Accept || !tx) {
1084
1280
  return;
1085
1281
  }
1282
+ // Tx was accepted into pool and will be propagated - just log and record metrics
1086
1283
  const txHash = tx.getTxHash();
1087
1284
  const txHashString = txHash.toString();
1088
1285
  this.logger.verbose(`Received tx ${txHashString} from external peer ${source.toString()} via gossip`, {
1089
1286
  source: source.toString(),
1090
1287
  txHash: txHashString
1091
1288
  });
1092
- if (this.config.dropTransactions && randomInt(1000) < this.config.dropTransactionsProbability * 1000) {
1093
- this.logger.warn(`Intentionally dropping tx ${txHashString} (probability rule)`);
1094
- return;
1095
- }
1096
1289
  this.instrumentation.incrementTxReceived(1);
1097
- await this.mempools.txPool.addTxs([
1098
- tx
1099
- ]);
1100
1290
  }
1101
1291
  /**
1102
1292
  * Process a checkpoint attestation from a peer.
1103
1293
  * Validates the attestation and adds it to the pool.
1104
1294
  */ async processCheckpointAttestationFromPeer(payloadData, msgId, source) {
1105
- const validationFunc = async ()=>{
1106
- const attestation = CheckpointAttestation.fromBuffer(payloadData);
1107
- const pool = this.mempools.attestationPool;
1108
- const validationResult = await this.validateCheckpointAttestation(source, attestation);
1109
- const isValid = validationResult.result === 'accept';
1110
- const exists = isValid && await pool.hasCheckpointAttestation(attestation);
1111
- let canAdd = true;
1112
- if (isValid && !exists) {
1113
- const slot = attestation.payload.header.slotNumber;
1114
- const { committee } = await this.epochCache.getCommittee(slot);
1115
- const committeeSize = committee?.length ?? 0;
1116
- canAdd = await pool.canAddCheckpointAttestation(attestation, committeeSize);
1117
- }
1118
- this.logger.trace(`Validate propagated checkpoint attestation`, {
1119
- isValid,
1120
- exists,
1121
- canAdd,
1122
- [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toString(),
1123
- [Attributes.P2P_ID]: source.toString()
1124
- });
1125
- if (validationResult.result === 'reject') {
1126
- return {
1127
- result: TopicValidatorResult.Reject
1128
- };
1129
- } else if (validationResult.result === 'ignore' || exists) {
1130
- return {
1131
- result: TopicValidatorResult.Ignore,
1132
- obj: attestation
1133
- };
1134
- } else if (!canAdd) {
1135
- this.logger.warn(`Dropping checkpoint attestation due to per-(slot, proposalId) attestation cap`, {
1136
- slot: attestation.payload.header.slotNumber.toString(),
1137
- archive: attestation.archive.toString(),
1138
- source: source.toString()
1295
+ const { result, obj: attestation } = await this.validateReceivedMessage(()=>{
1296
+ const attestation = this.tryDeserialize(()=>CheckpointAttestation.fromBuffer(payloadData), msgId, source);
1297
+ if (!attestation) {
1298
+ return Promise.resolve({
1299
+ result: TopicValidatorResult.Reject,
1300
+ severity: PeerErrorSeverity.LowToleranceError
1139
1301
  });
1140
- return {
1141
- result: TopicValidatorResult.Ignore,
1142
- obj: attestation
1143
- };
1144
- } else {
1145
- return {
1146
- result: TopicValidatorResult.Accept,
1147
- obj: attestation
1148
- };
1149
1302
  }
1150
- };
1151
- const { result, obj: attestation } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.checkpoint_attestation);
1303
+ return this.validateAndStoreCheckpointAttestation(source, attestation);
1304
+ }, msgId, source, TopicType.checkpoint_attestation);
1152
1305
  if (result !== TopicValidatorResult.Accept || !attestation) {
1153
1306
  return;
1154
1307
  }
1155
- this.logger.debug(`Received checkpoint attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`, {
1308
+ this.logger.verbose(`Received valid checkpoint attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`, {
1156
1309
  p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
1157
1310
  slot: attestation.slotNumber,
1158
1311
  archive: attestation.archive.toString(),
1159
1312
  source: source.toString()
1160
1313
  });
1161
- await this.mempools.attestationPool.addCheckpointAttestations([
1162
- attestation
1163
- ]);
1164
1314
  }
1165
- async processBlockFromPeer(payloadData, msgId, source) {
1166
- const validationFunc = async ()=>{
1167
- const block = BlockProposal.fromBuffer(payloadData);
1168
- const validationResult = await this.validateBlockProposal(source, block);
1169
- const isValid = validationResult.result === 'accept';
1170
- const pool = this.mempools.attestationPool;
1171
- const exists = isValid && await pool.hasBlockProposal(block);
1172
- const canAdd = isValid && await pool.canAddProposal(block);
1173
- this.logger.trace(`Validate propagated block proposal`, {
1174
- isValid,
1175
- exists,
1176
- canAdd,
1177
- [Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
1178
- [Attributes.P2P_ID]: source.toString()
1315
+ /** Validates a checkpoint attestation and adds it to the pool. Penalizes the peer if validation fails. */ async validateAndStoreCheckpointAttestation(peerId, attestation) {
1316
+ const validationResult = await this.checkpointAttestationValidator.validate(attestation);
1317
+ if (validationResult.result === 'reject') {
1318
+ this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
1319
+ return {
1320
+ result: TopicValidatorResult.Reject,
1321
+ severity: validationResult.severity
1322
+ };
1323
+ }
1324
+ if (validationResult.result === 'ignore') {
1325
+ return {
1326
+ result: TopicValidatorResult.Ignore,
1327
+ obj: attestation
1328
+ };
1329
+ }
1330
+ // Try to add the attestation: this handles existence check, cap check, and adding in one call
1331
+ // count is the number of attestations by this signer for this slot (for duplicate detection)
1332
+ const slot = attestation.payload.header.slotNumber;
1333
+ const { added, alreadyExists, count } = await this.mempools.attestationPool.tryAddCheckpointAttestation(attestation);
1334
+ this.logger.trace(`Validate propagated checkpoint attestation`, {
1335
+ added,
1336
+ alreadyExists,
1337
+ count,
1338
+ [Attributes.SLOT_NUMBER]: slot.toString(),
1339
+ [Attributes.P2P_ID]: peerId.toString()
1340
+ });
1341
+ // Exact same attestation received, no need to re-broadcast
1342
+ if (alreadyExists) {
1343
+ return {
1344
+ result: TopicValidatorResult.Ignore,
1345
+ obj: attestation
1346
+ };
1347
+ }
1348
+ // Could not add (cap reached for signer), penalize and do not re-broadcast
1349
+ if (!added) {
1350
+ this.logger.warn(`Rejecting checkpoint attestation due to cap`, {
1351
+ slot: slot.toString(),
1352
+ archive: attestation.archive.toString(),
1353
+ source: peerId.toString(),
1354
+ attester: attestation.getSender()?.toString(),
1355
+ count
1179
1356
  });
1180
- if (validationResult.result === 'reject') {
1181
- return {
1182
- result: TopicValidatorResult.Reject
1183
- };
1184
- } else if (validationResult.result === 'ignore' || exists) {
1185
- return {
1186
- result: TopicValidatorResult.Ignore,
1187
- obj: block
1188
- };
1189
- } else if (!canAdd) {
1190
- this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
1191
- this.logger.warn(`Penalizing peer for block proposal exceeding per-slot cap`, {
1192
- slot: block.slotNumber.toString(),
1193
- archive: block.archive.toString(),
1194
- source: source.toString()
1357
+ return {
1358
+ result: TopicValidatorResult.Reject,
1359
+ severity: PeerErrorSeverity.HighToleranceError
1360
+ };
1361
+ }
1362
+ // Check if this is a duplicate attestation (signer attested to a different proposal at the same slot)
1363
+ // count is the number of attestations by this signer for this slot
1364
+ if (count === 2) {
1365
+ const attester = attestation.getSender();
1366
+ if (attester) {
1367
+ this.logger.warn(`Detected duplicate attestation (equivocation) at slot ${slot}`, {
1368
+ slot: slot.toString(),
1369
+ archive: attestation.archive.toString(),
1370
+ source: peerId.toString(),
1371
+ attester: attester.toString()
1372
+ });
1373
+ this.duplicateAttestationCallback?.({
1374
+ slot,
1375
+ attester
1195
1376
  });
1196
- return {
1197
- result: TopicValidatorResult.Reject
1198
- };
1199
- } else {
1200
- return {
1201
- result: TopicValidatorResult.Accept,
1202
- obj: block
1203
- };
1204
1377
  }
1378
+ }
1379
+ // Attestation was added successfully - accept it so other nodes can also detect the equivocation
1380
+ this.checkpointAttestationCallback?.(attestation);
1381
+ return {
1382
+ result: TopicValidatorResult.Accept,
1383
+ obj: attestation
1205
1384
  };
1206
- const { result, obj: block } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.block_proposal);
1207
- if (!result || !block) {
1385
+ }
1386
+ async processBlockFromPeer(payloadData, msgId, source) {
1387
+ const { result, obj: block, metadata: { isEquivocated, isOversized } = {} } = await this.validateReceivedMessage(()=>this.validateAndStoreBlockProposal(source, BlockProposal.fromBuffer(payloadData)), msgId, source, TopicType.block_proposal);
1388
+ // If not accepted, equivocated, or oversized, return. Oversized proposals are re-broadcast as
1389
+ // slashing evidence but never attested or processed.
1390
+ if (result !== TopicValidatorResult.Accept || !block || isEquivocated || isOversized) {
1208
1391
  return;
1209
1392
  }
1210
1393
  await this.processValidBlockProposal(block, source);
1211
1394
  }
1212
- // REVIEW: callback pattern https://github.com/AztecProtocol/aztec-packages/issues/7963
1395
+ /** Validates a block proposal. Triggers a penalization to the peer that sent it if invalid. Adds to the mempool if valid. */ async validateAndStoreBlockProposal(peerId, block) {
1396
+ const validationResult = await this.blockProposalValidator.validate(block);
1397
+ if (validationResult.result === 'reject') {
1398
+ this.logger.warn(`Penalizing peer ${peerId} for block proposal validation failure`);
1399
+ return {
1400
+ result: TopicValidatorResult.Reject,
1401
+ severity: validationResult.severity
1402
+ };
1403
+ }
1404
+ if (validationResult.result === 'ignore') {
1405
+ return {
1406
+ result: TopicValidatorResult.Ignore,
1407
+ obj: block
1408
+ };
1409
+ }
1410
+ // Try to add the proposal: this handles existence check, cap check, and adding in one call
1411
+ const { added, alreadyExists, count } = await this.mempools.attestationPool.tryAddBlockProposal(block);
1412
+ const isEquivocated = count !== undefined && count > 1;
1413
+ // An oversized proposal (index at or beyond the consensus per-checkpoint limit) is structurally valid
1414
+ // proposer misbehavior: it is stored and re-broadcast as slashing evidence but never processed or
1415
+ // attested to. No-ops when maxBlocksPerCheckpoint is unset (local/test).
1416
+ const isOversized = this.config.maxBlocksPerCheckpoint !== undefined && block.indexWithinCheckpoint >= this.config.maxBlocksPerCheckpoint;
1417
+ // Duplicate proposal received, no need to re-broadcast
1418
+ if (alreadyExists) {
1419
+ this.logger.debug(`Ignoring duplicate block proposal received`, {
1420
+ ...block.toBlockInfo(),
1421
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
1422
+ proposer: block.getSender()?.toString(),
1423
+ source: peerId.toString()
1424
+ });
1425
+ return {
1426
+ result: TopicValidatorResult.Ignore,
1427
+ obj: block,
1428
+ metadata: {
1429
+ isEquivocated,
1430
+ isOversized
1431
+ }
1432
+ };
1433
+ }
1434
+ // Too many blocks received for this slot and index, penalize peer and do not re-broadcast
1435
+ if (!added) {
1436
+ this.logger.warn(`Penalizing peer for block proposal exceeding per-position cap`, {
1437
+ ...block.toBlockInfo(),
1438
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
1439
+ count,
1440
+ proposer: block.getSender()?.toString(),
1441
+ source: peerId.toString()
1442
+ });
1443
+ return {
1444
+ result: TopicValidatorResult.Reject,
1445
+ metadata: {
1446
+ isEquivocated,
1447
+ isOversized
1448
+ },
1449
+ severity: PeerErrorSeverity.HighToleranceError
1450
+ };
1451
+ }
1452
+ // The proposal was stored: if oversized, invoke the oversized callback so the proposer can be
1453
+ // slashed. Fired alongside (not instead of) equivocation detection below.
1454
+ if (isOversized) {
1455
+ const proposer = block.getSender();
1456
+ if (proposer) {
1457
+ this.logger.warn(`Detected oversized block proposal at slot ${block.slotNumber}`, {
1458
+ ...block.toBlockInfo(),
1459
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
1460
+ maxBlocksPerCheckpoint: this.config.maxBlocksPerCheckpoint,
1461
+ source: peerId.toString(),
1462
+ proposer: proposer.toString()
1463
+ });
1464
+ this.oversizedProposalCallback?.({
1465
+ slot: block.slotNumber,
1466
+ proposer
1467
+ });
1468
+ }
1469
+ }
1470
+ // If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
1471
+ // and do re-broadcast it so other nodes in the network know to slash the proposer
1472
+ if (isEquivocated) {
1473
+ const proposer = block.getSender();
1474
+ this.logger.warn(`Detected duplicate block proposal (equivocation) at slot ${block.slotNumber}`, {
1475
+ ...block.toBlockInfo(),
1476
+ source: peerId.toString(),
1477
+ proposer: proposer?.toString()
1478
+ });
1479
+ // Invoke the duplicate callback on the first duplicate spotted only
1480
+ if (proposer && count === 2) {
1481
+ this.duplicateProposalCallback?.({
1482
+ slot: block.slotNumber,
1483
+ proposer,
1484
+ type: 'block'
1485
+ });
1486
+ }
1487
+ return {
1488
+ result: TopicValidatorResult.Accept,
1489
+ obj: block,
1490
+ metadata: {
1491
+ isEquivocated,
1492
+ isOversized
1493
+ }
1494
+ };
1495
+ }
1496
+ // Otherwise, we're good to go!
1497
+ return {
1498
+ result: TopicValidatorResult.Accept,
1499
+ obj: block,
1500
+ metadata: {
1501
+ isEquivocated: false,
1502
+ isOversized
1503
+ }
1504
+ };
1505
+ }
1213
1506
  // REFACTOR(palla): This method should be moved to the p2p_client or to a separate component,
1214
1507
  // should not be here as it does not deal with p2p networking.
1215
1508
  async processValidBlockProposal(block, sender) {
@@ -1219,85 +1512,183 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1219
1512
  source: sender.toString(),
1220
1513
  ...block.toBlockInfo()
1221
1514
  });
1222
- // Attempt to add proposal
1515
+ // Mark the txs in this proposal as protected
1516
+ await this.mempools.txPool.protectTxs(block.txHashes, block.blockHeader);
1517
+ if (!await this.tryBlockReceivedCallback(block, sender)) {
1518
+ // Release the protections this proposal created so its txs return to pending. Only entries still
1519
+ // keyed to this slot are cleared, so a tx referenced by a live proposal at another slot stays protected.
1520
+ await this.mempools.txPool.unprotectTxs(block.txHashes, slot);
1521
+ }
1522
+ }
1523
+ /**
1524
+ * Runs the block received callback to validate a proposal, and returns whether it was accepted.
1525
+ * A callback that throws is reported as a rejection: the proposal is no more usable than one explicitly
1526
+ * rejected, and letting the error escape would leave the proposal's tx protections in place.
1527
+ * Note: Validators do NOT attest to individual blocks, only to checkpoint proposals.
1528
+ */ async tryBlockReceivedCallback(block, sender) {
1223
1529
  try {
1224
- await this.mempools.attestationPool.addBlockProposal(block);
1225
- } catch (err) {
1226
- // Drop proposals if we hit per-slot cap in the attestation pool; rethrow unknown errors
1227
- if (err instanceof ProposalSlotCapExceededError) {
1228
- this.logger.warn(`Dropping block proposal due to per-slot proposal cap`, {
1229
- slot: String(slot),
1230
- archive: block.archive.toString(),
1231
- error: err.message
1232
- });
1233
- return;
1530
+ const isValid = await this.blockReceivedCallback(block, sender);
1531
+ if (!isValid) {
1532
+ this.logger.info(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
1234
1533
  }
1235
- throw err;
1236
- }
1237
- // Mark the txs in this proposal as non-evictable
1238
- await this.mempools.txPool.markTxsAsNonEvictable(block.txHashes);
1239
- // Call the block received callback to validate the proposal.
1240
- // Note: Validators do NOT attest to individual blocks, only to checkpoint proposals.
1241
- const isValid = await this.blockReceivedCallback(block, sender);
1242
- if (!isValid) {
1243
- this.logger.warn(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
1534
+ return isValid;
1535
+ } catch (err) {
1536
+ this.logger.error(`Error validating block proposal for block ${block.blockNumber}`, err, block.toBlockInfo());
1537
+ return false;
1244
1538
  }
1245
1539
  }
1246
1540
  /**
1247
1541
  * Handle a gossiped checkpoint proposal.
1248
1542
  * Validates and processes the checkpoint proposal, then triggers the callback for attestation.
1249
1543
  */ async handleGossipedCheckpointProposal(payloadData, msgId, source) {
1250
- // TODO(palla/mbps): This pattern is repeated across multiple message handlers, consider abstracting it.
1251
- const validationFunc = async ()=>{
1252
- const checkpoint = CheckpointProposal.fromBuffer(payloadData);
1253
- const validationResult = await this.validateCheckpointProposal(source, checkpoint);
1254
- const isValid = validationResult.result === 'accept';
1255
- const pool = this.mempools.attestationPool;
1256
- const exists = isValid && await pool.hasCheckpointProposal(checkpoint);
1257
- const canAdd = isValid && await pool.canAddCheckpointProposal(checkpoint);
1258
- this.logger.trace(`Validate propagated checkpoint proposal`, {
1259
- isValid,
1260
- exists,
1261
- canAdd,
1544
+ const { result, obj: checkpoint, metadata: { isEquivocated, processBlock, isOversized } = {} } = await this.validateReceivedMessage(()=>this.validateAndStoreCheckpointProposal(source, CheckpointProposal.fromBuffer(payloadData)), msgId, source, TopicType.checkpoint_proposal);
1545
+ // An oversized checkpoint is re-broadcast as slashing evidence but never attested or processed.
1546
+ // Process checkpoint proposal if valid and neither equivocated nor oversized.
1547
+ const processCheckpointFn = ()=>result === TopicValidatorResult.Accept && checkpoint && !isEquivocated && !isOversized ? this.processValidCheckpointProposal(checkpoint.toCore(), source) : Promise.resolve();
1548
+ // If the checkpoint contained a valid last block, we process it even if the checkpoint itself is to be rejected
1549
+ // TODO(palla/mbps): Is this ok? Should we be considering a block from a checkpoint that was equivocated?
1550
+ const processBlockFn = ()=>processBlock && checkpoint && checkpoint.getBlockProposal() ? this.processValidBlockProposal(checkpoint.getBlockProposal(), source) : Promise.resolve();
1551
+ // A node that skips checkpoint validation attests without re-executing the embedded last block, so run
1552
+ // the checkpoint callback first: this creates and broadcasts the attestation before the block is
1553
+ // processed. Otherwise the block's re-execution — which can stall until the re-execution deadline
1554
+ // waiting for a parent that may never arrive — would delay the attestation past the slot's attestation
1555
+ // window, after which peers reject it as stale.
1556
+ if (this.config.skipCheckpointProposalValidation) {
1557
+ await processCheckpointFn();
1558
+ await processBlockFn();
1559
+ return;
1560
+ }
1561
+ // Process the block first, since it's required for the checkpoint proposal validation.
1562
+ await processBlockFn();
1563
+ await processCheckpointFn();
1564
+ }
1565
+ /**
1566
+ * Validates a checkpoint proposal. Penalizes peer if validation fails. Adds the checkpoint and
1567
+ * its last block (if present) to the mempool if valid. Triggers equivocation detection on both.
1568
+ */ async validateAndStoreCheckpointProposal(peerId, checkpoint) {
1569
+ const validationResult = await this.checkpointProposalValidator.validate(checkpoint);
1570
+ if (validationResult.result === 'reject') {
1571
+ this.logger.warn(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
1572
+ return {
1573
+ result: TopicValidatorResult.Reject,
1574
+ severity: validationResult.severity
1575
+ };
1576
+ }
1577
+ if (validationResult.result === 'ignore') {
1578
+ return {
1579
+ result: TopicValidatorResult.Ignore,
1580
+ obj: checkpoint
1581
+ };
1582
+ }
1583
+ // Extract and try to add the block proposal first if present
1584
+ const blockProposal = checkpoint.getBlockProposal();
1585
+ let processBlock = false;
1586
+ let isOversized = false;
1587
+ if (blockProposal) {
1588
+ this.logger.debug(`Validating block proposal from propagated checkpoint`, {
1262
1589
  [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
1263
- [Attributes.P2P_ID]: source.toString()
1590
+ [Attributes.P2P_ID]: peerId.toString()
1264
1591
  });
1265
- if (validationResult.result === 'reject') {
1266
- return {
1267
- result: TopicValidatorResult.Reject
1268
- };
1269
- } else if (validationResult.result === 'ignore' || exists) {
1270
- return {
1271
- result: TopicValidatorResult.Ignore,
1272
- obj: checkpoint
1273
- };
1274
- } else if (!canAdd) {
1275
- this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
1276
- this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
1277
- slot: checkpoint.slotNumber.toString(),
1278
- archive: checkpoint.archive.toString(),
1279
- source: source.toString()
1592
+ const blockProposalResult = await this.validateAndStoreBlockProposal(peerId, blockProposal);
1593
+ const { obj, metadata: { isEquivocated, isOversized: blockIsOversized } = {} } = blockProposalResult;
1594
+ isOversized = blockIsOversized ?? false;
1595
+ if (blockProposalResult.result === TopicValidatorResult.Reject || !obj || isEquivocated) {
1596
+ this.logger.debug(`Rejecting checkpoint due to invalid last block proposal`, {
1597
+ [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
1598
+ [Attributes.P2P_ID]: peerId.toString(),
1599
+ isEquivocated,
1600
+ result: blockProposalResult.result
1280
1601
  });
1281
1602
  return {
1282
- result: TopicValidatorResult.Reject
1283
- };
1284
- } else {
1285
- return {
1286
- result: TopicValidatorResult.Accept,
1287
- obj: checkpoint
1603
+ result: TopicValidatorResult.Reject,
1604
+ severity: 'severity' in blockProposalResult ? blockProposalResult.severity : PeerErrorSeverity.MidToleranceError
1288
1605
  };
1606
+ } else if (blockProposalResult.result === TopicValidatorResult.Accept && obj && !isEquivocated && !isOversized) {
1607
+ // An oversized terminal block is re-broadcast as slashing evidence but never processed.
1608
+ processBlock = true;
1289
1609
  }
1290
- };
1291
- const { result, obj: checkpoint } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.checkpoint_proposal);
1292
- if (result !== TopicValidatorResult.Accept || !checkpoint) {
1293
- return;
1294
1610
  }
1295
- await this.processValidCheckpointProposal(checkpoint, source);
1611
+ // Try to add the checkpoint proposal core: this handles existence check, cap check, and adding in one call
1612
+ const checkpointCore = checkpoint.toCore();
1613
+ const tryAddResult = await this.mempools.attestationPool.tryAddCheckpointProposal(checkpointCore);
1614
+ const { added, alreadyExists, count } = tryAddResult;
1615
+ const isEquivocated = count !== undefined && count > 1;
1616
+ // Duplicate proposal received, do not re-broadcast
1617
+ if (alreadyExists) {
1618
+ this.logger.debug(`Ignoring duplicate checkpoint proposal received`, {
1619
+ ...checkpoint.toCheckpointInfo(),
1620
+ source: peerId.toString()
1621
+ });
1622
+ return {
1623
+ result: TopicValidatorResult.Ignore,
1624
+ obj: checkpoint,
1625
+ metadata: {
1626
+ isEquivocated,
1627
+ processBlock,
1628
+ isOversized
1629
+ }
1630
+ };
1631
+ }
1632
+ // Too many checkpoint proposals received for this slot, penalize peer and do not re-broadcast.
1633
+ // Note: We still return the checkpoint obj so the lastBlock can be processed if valid
1634
+ if (!added) {
1635
+ this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
1636
+ ...checkpoint.toCheckpointInfo(),
1637
+ count,
1638
+ source: peerId.toString()
1639
+ });
1640
+ return {
1641
+ result: TopicValidatorResult.Reject,
1642
+ obj: checkpoint,
1643
+ metadata: {
1644
+ isEquivocated,
1645
+ processBlock,
1646
+ isOversized
1647
+ },
1648
+ severity: PeerErrorSeverity.HighToleranceError
1649
+ };
1650
+ }
1651
+ // If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
1652
+ // and do re-broadcast it so other nodes in the network know to slash the proposer
1653
+ if (isEquivocated) {
1654
+ const proposer = checkpoint.getSender();
1655
+ this.logger.warn(`Detected duplicate checkpoint proposal (equivocation) at slot ${checkpoint.slotNumber}`, {
1656
+ ...checkpoint.toCheckpointInfo(),
1657
+ source: peerId.toString(),
1658
+ proposer: proposer?.toString()
1659
+ });
1660
+ // Invoke the duplicate callback on the first duplicate spotted only
1661
+ if (proposer && count === 2) {
1662
+ this.duplicateProposalCallback?.({
1663
+ slot: checkpoint.slotNumber,
1664
+ proposer,
1665
+ type: 'checkpoint'
1666
+ });
1667
+ }
1668
+ return {
1669
+ result: TopicValidatorResult.Accept,
1670
+ obj: checkpoint,
1671
+ metadata: {
1672
+ isEquivocated,
1673
+ processBlock,
1674
+ isOversized
1675
+ }
1676
+ };
1677
+ }
1678
+ // Otherwise, we're good to go!
1679
+ return {
1680
+ result: TopicValidatorResult.Accept,
1681
+ obj: checkpoint,
1682
+ metadata: {
1683
+ processBlock,
1684
+ isEquivocated,
1685
+ isOversized
1686
+ }
1687
+ };
1296
1688
  }
1297
1689
  /**
1298
1690
  * Process a validated checkpoint proposal.
1299
- * Extracts and processes the last block proposal (if present) first, then processes the checkpoint.
1300
- * The block callback is invoked before the checkpoint callback.
1691
+ * Note: The proposal was already added to the pool by tryAddCheckpointProposal in handleGossipedCheckpointProposal.
1301
1692
  */ async processValidCheckpointProposal(checkpoint, sender) {
1302
1693
  const slot = checkpoint.slotNumber;
1303
1694
  this.logger.verbose(`Received checkpoint proposal for slot ${slot} from external peer ${sender.toString()}.`, {
@@ -1306,33 +1697,13 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1306
1697
  archive: checkpoint.archive.toString(),
1307
1698
  source: sender.toString()
1308
1699
  });
1309
- // Extract block proposal before adding to pool (pool stores them separately)
1310
- const blockProposal = checkpoint.getBlockProposal();
1311
- // Add proposal to the pool (this extracts and stores block proposal separately)
1312
- await this.mempools.attestationPool.addCheckpointProposal(checkpoint);
1313
- // Mark txs as non-evictable if present (from the last block)
1314
- if (checkpoint.txHashes.length > 0) {
1315
- await this.mempools.txPool.markTxsAsNonEvictable(checkpoint.txHashes);
1316
- }
1317
- // If there was a last block proposal, invoke the block callback first for validation.
1318
- // Note: The block proposal is already stored in the pool by addCheckpointProposal.
1319
- if (blockProposal) {
1320
- const isValid = await this.blockReceivedCallback(blockProposal, sender);
1321
- if (!isValid) {
1322
- this.logger.warn(`Block proposal from checkpoint failed validation`, {
1323
- slot: slot.toString(),
1324
- archive: checkpoint.archive.toString(),
1325
- blockNumber: blockProposal.blockNumber.toString()
1326
- });
1327
- return;
1328
- }
1329
- }
1700
+ await this.allNodesCheckpointReceivedCallback(checkpoint, sender);
1330
1701
  // Call the checkpoint received callback with the core version (without lastBlock)
1331
1702
  // to validate and potentially generate attestations
1332
- const attestations = await this.checkpointReceivedCallback(checkpoint.toCore(), sender);
1703
+ const attestations = await this.validatorCheckpointReceivedCallback(checkpoint, sender);
1333
1704
  if (attestations && attestations.length > 0) {
1334
1705
  // If the callback returned attestations, add them to the pool and propagate them
1335
- await this.mempools.attestationPool.addCheckpointAttestations(attestations);
1706
+ await this.mempools.attestationPool.addOwnCheckpointAttestations(attestations);
1336
1707
  for (const attestation of attestations){
1337
1708
  await this.propagate(attestation);
1338
1709
  }
@@ -1353,192 +1724,78 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1353
1724
  });
1354
1725
  }
1355
1726
  /**
1356
- * Validate the requested block transactions. Allow partial returns.
1727
+ * Validate the requested block transactions request-response consistency.
1728
+ * It does NOT validate the transactions themselves.
1357
1729
  * @param request - The block transactions request.
1358
1730
  * @param response - The block transactions response.
1359
1731
  * @param peerId - The ID of the peer that made the request.
1360
- * @returns True if the requested block transactions are valid, false otherwise.
1361
- */ async validateRequestedBlockTxs(request, response, peerId) {
1362
- const requestedTxValidator = this.createRequestedTxValidator();
1732
+ * @returns True if the request-response is consistent, false otherwise.
1733
+ */ async validateRequestedBlockTxsConsistency(request, response, peerId) {
1363
1734
  try {
1364
- if (!response.blockHash.equals(request.blockHash)) {
1365
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1366
- throw new ValidationError(`Received block txs for unexpected block: expected ${request.blockHash.toString()}, got ${response.blockHash.toString()}`);
1367
- }
1368
- if (response.txIndices.getLength() !== request.txIndices.getLength()) {
1369
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1370
- throw new ValidationError(`Received block txs with mismatched bitvector length: expected ${request.txIndices.getLength()}, got ${response.txIndices.getLength()}`);
1371
- }
1372
- // Check no duplicates and not exceeding returnable count
1373
- const requestedIndices = new Set(request.txIndices.getTrueIndices());
1374
- const availableIndices = new Set(response.txIndices.getTrueIndices());
1375
- const maxReturnable = [
1376
- ...requestedIndices
1377
- ].filter((i)=>availableIndices.has(i)).length;
1378
- const returnedHashes = await Promise.all(response.txs.map((tx)=>tx.getTxHash().toString()));
1735
+ // Check for duplicates txs (or hashes) in the response.
1736
+ const returnedHashes = response.txs.map((tx)=>tx.getTxHash().toString());
1379
1737
  const uniqueReturned = new Set(returnedHashes.map((h)=>h.toString()));
1380
1738
  if (uniqueReturned.size !== returnedHashes.length) {
1381
1739
  this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1382
1740
  throw new ValidationError(`Received duplicate txs in block txs response`);
1383
1741
  }
1384
- if (response.txs.length > maxReturnable) {
1385
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1386
- throw new ValidationError(`Received more txs (${response.txs.length}) than requested-and-available (${maxReturnable})`);
1387
- }
1388
- // Given proposal (should have locally), ensure returned txs are valid subset and match request indices
1389
- const proposal = await this.mempools.attestationPool.getBlockProposal(request.blockHash.toString());
1390
- if (proposal) {
1391
- // Build intersected indices
1392
- const intersectIdx = request.txIndices.getTrueIndices().filter((i)=>response.txIndices.isSet(i));
1393
- // Enforce subset membership and preserve increasing order by index.
1394
- const hashToIndexInProposal = new Map(proposal.txHashes.map((h, i)=>[
1395
- h.toString(),
1396
- i
1397
- ]));
1398
- const allowedIndexSet = new Set(intersectIdx);
1399
- const indices = returnedHashes.map((h)=>hashToIndexInProposal.get(h));
1400
- const allAllowed = indices.every((idx)=>idx !== undefined && allowedIndexSet.has(idx));
1401
- const strictlyIncreasing = indices.every((idx, i)=>i === 0 ? idx !== undefined : idx > indices[i - 1]);
1402
- if (!allAllowed || !strictlyIncreasing) {
1403
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
1404
- throw new ValidationError('Returned txs do not match expected subset/order for requested indices');
1405
- }
1406
- } else {
1407
- // No local proposal, cannot check the membership/order of the returned txs
1408
- this.logger.warn(`Block proposal not found for block hash ${request.blockHash.toString()}; cannot validate membership/order of returned txs`);
1742
+ // We get the block tx hashes from the proposal or the archiver.
1743
+ const proposal = await this.mempools.attestationPool.getBlockProposalByArchive(request.archiveRoot.toString());
1744
+ const blockTxHashes = proposal?.txHashes ?? (await this.archiver.getBlock({
1745
+ archive: request.archiveRoot
1746
+ }))?.body.txEffects.map((e)=>e.txHash);
1747
+ // If we don't have the block, we can't verify membership/order of the returned txs.
1748
+ if (!blockTxHashes) {
1749
+ // This shouldn't happen, since we asked for the block (proposal).
1750
+ // Neither a local proposal nor an archived block: we cannot verify membership/order of the
1751
+ // returned txs. This is a local-state gap, not a peer fault, so we do not penalize.
1752
+ this.logger.warn(`Block ${request.archiveRoot.toString()} not found in attestation pool or archiver; cannot validate membership/order of returned txs`);
1753
+ // NOTE: We mark the response as invalid, given the limitations of a true/false return value.
1409
1754
  return false;
1410
1755
  }
1411
- await Promise.all(response.txs.map((tx)=>this.validateRequestedTx(tx, peerId, requestedTxValidator)));
1412
- return true;
1413
- } catch (e) {
1414
- if (e instanceof ValidationError) {
1415
- this.logger.warn(`Failed validation for requested block txs from peer ${peerId.toString()}`);
1416
- } else {
1417
- this.logger.error(`Error during validation of requested block txs`, e);
1418
- }
1419
- return false;
1420
- }
1421
- }
1422
- /**
1423
- * Validate a collection of txs that has been requested from a peer.
1424
- *
1425
- * The core component of this validator is that each tx hash MUST match the requested tx hash,
1426
- * In order to perform this check, the tx proof must be verified.
1427
- *
1428
- * Note: This function is called from within `ReqResp.sendRequest` as part of the
1429
- * ReqRespSubProtocol.TX subprotocol validation.
1430
- *
1431
- * @param requestedTxHash - The collection of the txs that was requested.
1432
- * @param responseTx - The collection of txs that was received as a response to the request.
1433
- * @param peerId - The peer ID of the peer that sent the tx.
1434
- * @returns True if the whole collection of txs is valid, false otherwise.
1435
- */ async validateRequestedTxs(requestedTxHash, responseTx, peerId) {
1436
- const requested = new Set(requestedTxHash.map((h)=>h.toString()));
1437
- const requestedTxValidator = this.createRequestedTxValidator();
1438
- //TODO: (mralj) - this is somewhat naive implementation, if single tx is invalid we consider the whole response invalid.
1439
- // I think we should still extract the valid txs and return them, so that we can still use the response.
1440
- try {
1441
- await Promise.all(responseTx.map((tx)=>this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
1442
- return true;
1443
- } catch (e) {
1444
- if (e instanceof ValidationError) {
1445
- this.logger.warn(`Failed to validate requested txs from peer ${peerId.toString()}, reason ${e.message}`);
1446
- } else {
1447
- this.logger.error(`Error during validation of requested txs`, e);
1448
- }
1449
- return false;
1450
- }
1451
- }
1452
- /**
1453
- * Validates a BLOCK response.
1454
- *
1455
- * If a local copy exists, enforces hash equality. If missing, rejects (no penalty) since the hash cannot be verified.
1456
- * Penalizes on block number mismatch or hash mismatch.
1457
- *
1458
- * @param requestedBlockNumber - The requested block number.
1459
- * @param responseBlock - The block returned by the peer.
1460
- * @param peerId - The peer that returned the block.
1461
- * @returns True if the response is valid, false otherwise.
1462
- */ async validateRequestedBlock(requestedBlockNumber, responseBlock, peerId) {
1463
- try {
1464
- const reqNum = Number(requestedBlockNumber.toString());
1465
- if (responseBlock.number !== reqNum) {
1756
+ // Verify that the returned tx hashes are a subset of (tx hashes by index) U (explicitly requested tx hashes).
1757
+ const uniqueRequestedHashes = new Set([
1758
+ // tx hashes requested by index.
1759
+ ...request.txIndices.getTrueIndices().map((i)=>blockTxHashes[i].toString()),
1760
+ // explicitly requested tx hashes.
1761
+ ...request.txHashes.map((h)=>h.toString())
1762
+ ]);
1763
+ if (!returnedHashes.every((h)=>uniqueRequestedHashes.has(h))) {
1466
1764
  this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
1467
- return false;
1765
+ throw new ValidationError('Returned txs should be a subset of (tx hashes by index) U (explicitly requested tx hashes)');
1468
1766
  }
1469
- const local = await this.archiver.getBlock(BlockNumber(reqNum));
1470
- if (!local) {
1471
- // We are missing the local block; we cannot verify the hash yet. Reject without penalizing.
1472
- // TODO: Consider extending this validator to accept an expected hash or
1473
- // performing quorum-based checks when using P2P syncing prior to L1 sync.
1474
- this.logger.warn(`Local block ${reqNum} not found; rejecting BLOCK response without hash verification`);
1475
- return false;
1767
+ // Tx indices information is optional, but if present, we need to verify a few things.
1768
+ if (!response.peerHasBlock()) {
1769
+ this.logger.debug(`Peer ${peerId.toString()} signalled missing block`);
1770
+ return true;
1476
1771
  }
1477
- const [localHash, respHash] = await Promise.all([
1478
- local.hash(),
1479
- responseBlock.hash()
1480
- ]);
1481
- if (!localHash.equals(respHash)) {
1772
+ // If the response has a non-empty bitvector, it needs to be consistent with the number of txs in the block.
1773
+ if (response.txIndices.getLength() !== blockTxHashes.length) {
1482
1774
  this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1483
- return false;
1775
+ throw new ValidationError(`Received block txs with mismatched bitvector length: expected ${blockTxHashes.length}, got ${response.txIndices.getLength()}`);
1776
+ }
1777
+ // For every index we requested that the peer claims to have (per its bitvector), the
1778
+ // corresponding tx must be present in the response. A peer advertising availability but
1779
+ // withholding the tx is inconsistent.
1780
+ const returnedHashSet = new Set(returnedHashes);
1781
+ const expectedIndices = request.txIndices.getTrueIndices().filter((i)=>response.txIndices.isSet(i));
1782
+ const missingExpected = expectedIndices.some((i)=>!returnedHashSet.has(blockTxHashes[i].toString()));
1783
+ if (missingExpected) {
1784
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
1785
+ throw new ValidationError('Peer advertised requested txs via indices but did not return them');
1484
1786
  }
1485
1787
  return true;
1486
1788
  } catch (e) {
1487
- this.logger.warn(`Error validating requested block`, e);
1488
- return false;
1489
- }
1490
- }
1491
- async validateRequestedTx(tx, peerId, txValidator, requested) {
1492
- const penalize = (severity)=>this.peerManager.penalizePeer(peerId, severity);
1493
- if (requested && !requested.has(tx.getTxHash().toString())) {
1494
- penalize(PeerErrorSeverity.MidToleranceError);
1495
- throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
1496
- }
1497
- const { result } = await txValidator.validateTx(tx);
1498
- if (result === 'invalid') {
1499
- penalize(PeerErrorSeverity.LowToleranceError);
1500
- throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that is invalid.`);
1501
- }
1502
- }
1503
- createRequestedTxValidator() {
1504
- return createTxReqRespValidator(this.proofVerifier, {
1505
- l1ChainId: this.config.l1ChainId,
1506
- rollupVersion: this.config.rollupVersion
1507
- });
1508
- }
1509
- async validatePropagatedTx(tx, peerId) {
1510
- const currentBlockNumber = await this.archiver.getBlockNumber();
1511
- // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
1512
- const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1513
- const messageValidators = await this.createMessageValidators(currentBlockNumber, nextSlotTimestamp);
1514
- for (const validator of messageValidators){
1515
- const outcome = await this.runValidations(tx, validator);
1516
- if (outcome.allPassed) {
1517
- continue;
1518
- }
1519
- const { name } = outcome.failure;
1520
- let { severity } = outcome.failure;
1521
- // Double spend validator has a special case handler
1522
- if (name === 'doubleSpendValidator') {
1523
- const txBlockNumber = BlockNumber(currentBlockNumber + 1); // tx is expected to be in the next block
1524
- severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
1789
+ if (e instanceof ValidationError) {
1790
+ this.logger.warn(`Failed validation for requested block txs from peer ${peerId.toString()}`);
1791
+ } else {
1792
+ this.logger.error(`Error during validation of requested block txs`, e);
1525
1793
  }
1526
- this.peerManager.penalizePeer(peerId, severity);
1527
1794
  return false;
1528
1795
  }
1529
- return true;
1530
1796
  }
1531
- async getGasFees(blockNumber) {
1532
- if (blockNumber === this.feesCache?.blockNumber) {
1533
- return this.feesCache.gasFees;
1534
- }
1535
- const header = await this.archiver.getBlockHeader(blockNumber);
1536
- const gasFees = header?.globalVariables.gasFees ?? GasFees.empty();
1537
- this.feesCache = {
1538
- blockNumber,
1539
- gasFees
1540
- };
1541
- return gasFees;
1797
+ getGasFees() {
1798
+ return this.blockMinFeesProvider.getCurrentMinFees();
1542
1799
  }
1543
1800
  /**
1544
1801
  * Get the BatchTxRequesterLibP2PService dependencies for creating BatchTxRequester instances
@@ -1549,43 +1806,48 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1549
1806
  txValidatorConfig: {
1550
1807
  l1ChainId: this.config.l1ChainId,
1551
1808
  rollupVersion: this.config.rollupVersion,
1552
- proofVerifier: this.proofVerifier
1809
+ proofVerifier: this.proofVerifier,
1810
+ txValidationCache: this.txValidationCache
1553
1811
  },
1554
- peerScoring: this.peerManager
1812
+ peerScoring: this.peerManager,
1813
+ validateRequestedBlockTxsConsistency: this.validateRequestedBlockTxsConsistency.bind(this)
1555
1814
  };
1556
1815
  }
1557
- async validate(txs) {
1558
- const currentBlockNumber = await this.archiver.getBlockNumber();
1559
- // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
1560
- const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1561
- const messageValidators = await this.createMessageValidators(currentBlockNumber, nextSlotTimestamp);
1562
- await Promise.all(txs.map(async (tx)=>{
1563
- for (const validator of messageValidators){
1564
- const outcome = await this.runValidations(tx, validator);
1565
- if (!outcome.allPassed) {
1566
- throw new Error('Invalid tx detected', {
1567
- cause: {
1568
- outcome
1569
- }
1570
- });
1816
+ async validateTxsReceivedInBlockProposal(txs) {
1817
+ const validator = createTxValidatorForBlockProposalReceivedTxs(this.proofVerifier, {
1818
+ l1ChainId: this.config.l1ChainId,
1819
+ rollupVersion: this.config.rollupVersion
1820
+ }, this.logger.getBindings(), this.txValidationCache);
1821
+ const results = await Promise.all(txs.map(async (tx)=>({
1822
+ txHash: tx.getTxHash(),
1823
+ result: await validator.validateTx(tx)
1824
+ })));
1825
+ const invalidTxs = results.flatMap(({ txHash, result })=>result.result === 'invalid' ? [
1826
+ {
1827
+ txHash,
1828
+ reasons: result.reason
1571
1829
  }
1572
- }
1573
- }));
1830
+ ] : []);
1831
+ if (invalidTxs.length > 0) {
1832
+ throw new InvalidBlockProposalTxsError(invalidTxs);
1833
+ }
1574
1834
  }
1575
- /**
1576
- * Create message validators for the given block number and timestamp.
1577
- *
1578
- * Each validator is a pair of a validator and a severity.
1579
- * If a validator fails, the peer is penalized with the severity of the validator.
1580
- *
1581
- * @param currentBlockNumber - The current synced block number.
1582
- * @param nextSlotTimestamp - The timestamp of the next slot (used to validate txs are not expired).
1583
- * @returns The message validators.
1584
- */ async createMessageValidators(currentBlockNumber, nextSlotTimestamp) {
1585
- const gasFees = await this.getGasFees(currentBlockNumber);
1586
- const allowedInSetup = this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
1587
- const blockNumberInWhichTheTxIsConsideredToBeIncluded = BlockNumber(currentBlockNumber + 1);
1588
- return createTxMessageValidators(nextSlotTimestamp, blockNumberInWhichTheTxIsConsideredToBeIncluded, this.worldStateSynchronizer, gasFees, this.config.l1ChainId, this.config.rollupVersion, protocolContractsHash, this.archiver, this.proofVerifier, !this.config.disableTransactions, allowedInSetup, this.logger.getBindings());
1835
+ /** Creates the first stage (fast) validators for gossiped transactions. */ async createFirstStageMessageValidators(currentBlockNumber, nextSlotTimestamp) {
1836
+ const gasFees = await this.getGasFees();
1837
+ const allowedInSetup = [
1838
+ ...await getDefaultAllowedSetupFunctions(),
1839
+ ...this.config.txPublicSetupAllowListExtend ?? []
1840
+ ];
1841
+ const blockNumber = BlockNumber(currentBlockNumber + 1);
1842
+ const l1Constants = await this.archiver.getL1Constants();
1843
+ const networkTxGasLimits = getNetworkTxGasLimits(this.config, l1Constants);
1844
+ return createFirstStageTxValidationsForGossipedTransactions(nextSlotTimestamp, blockNumber, this.worldStateSynchronizer, gasFees, this.config.l1ChainId, this.config.rollupVersion, protocolContractsHash, this.archiver, !this.config.disableTransactions, allowedInSetup, this.logger.getBindings(), {
1845
+ maxTxL2Gas: networkTxGasLimits.l2Gas,
1846
+ maxTxDAGas: networkTxGasLimits.daGas
1847
+ });
1848
+ }
1849
+ /** Creates the second stage (expensive proof verification) validators for gossiped transactions. */ createSecondStageMessageValidators() {
1850
+ return createSecondStageTxValidationsForGossipedTransactions(this.proofVerifier, this.logger.getBindings());
1589
1851
  }
1590
1852
  /**
1591
1853
  * Run validations on a tx.
@@ -1603,8 +1865,10 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1603
1865
  });
1604
1866
  // A promise that resolves when all validations have been run
1605
1867
  const allValidations = await Promise.all(validationPromises);
1606
- const failed = allValidations.find((x)=>!x.isValid);
1607
- if (failed) {
1868
+ const failures = allValidations.filter((x)=>!x.isValid);
1869
+ if (failures.length > 0) {
1870
+ // Pick the most severe failure (lowest tolerance = harshest penalty)
1871
+ const failed = maxBy(failures, (f)=>PeerErrorSeverityByHarshness.indexOf(f.severity));
1608
1872
  return {
1609
1873
  allPassed: false,
1610
1874
  failure: {
@@ -1651,45 +1915,6 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
1651
1915
  }
1652
1916
  return PeerErrorSeverity.HighToleranceError;
1653
1917
  }
1654
- /**
1655
- * Validate a checkpoint attestation.
1656
- *
1657
- * @param attestation - The checkpoint attestation to validate.
1658
- * @returns True if the checkpoint attestation is valid, false otherwise.
1659
- */ async validateCheckpointAttestation(peerId, attestation) {
1660
- const result = await this.checkpointAttestationValidator.validate(attestation);
1661
- if (result.result === 'reject') {
1662
- this.logger.debug(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
1663
- this.peerManager.penalizePeer(peerId, result.severity);
1664
- }
1665
- return result;
1666
- }
1667
- /**
1668
- * Validate a block proposal.
1669
- *
1670
- * @param block - The block proposal to validate.
1671
- * @returns True if the block proposal is valid, false otherwise.
1672
- */ async validateBlockProposal(peerId, block) {
1673
- const result = await this.blockProposalValidator.validate(block);
1674
- if (result.result === 'reject') {
1675
- this.logger.debug(`Penalizing peer ${peerId} for block proposal validation failure`);
1676
- this.peerManager.penalizePeer(peerId, result.severity);
1677
- }
1678
- return result;
1679
- }
1680
- /**
1681
- * Validate a checkpoint proposal.
1682
- *
1683
- * @param checkpoint - The checkpoint proposal to validate.
1684
- * @returns True if the checkpoint proposal is valid, false otherwise.
1685
- */ async validateCheckpointProposal(peerId, checkpoint) {
1686
- const result = await this.checkpointProposalValidator.validate(checkpoint);
1687
- if (result.result === 'reject') {
1688
- this.logger.debug(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
1689
- this.peerManager.penalizePeer(peerId, result.severity);
1690
- }
1691
- return result;
1692
- }
1693
1918
  getPeerScore(peerId) {
1694
1919
  return this.node.services.pubsub.score.score(peerId.toString());
1695
1920
  }