@aztec/p2p 0.0.1-commit.181e2d196 → 0.0.1-commit.189eedb3

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 (455) hide show
  1. package/README.md +129 -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 +9 -1
  5. package/dest/client/factory.d.ts +5 -4
  6. package/dest/client/factory.d.ts.map +1 -1
  7. package/dest/client/factory.js +33 -15
  8. package/dest/client/interface.d.ts +14 -5
  9. package/dest/client/interface.d.ts.map +1 -1
  10. package/dest/client/p2p_client.d.ts +13 -9
  11. package/dest/client/p2p_client.d.ts.map +1 -1
  12. package/dest/client/p2p_client.js +93 -49
  13. package/dest/config.d.ts +148 -96
  14. package/dest/config.d.ts.map +1 -1
  15. package/dest/config.js +114 -10
  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 +1 -20
  20. package/dest/errors/reqresp.error.d.ts.map +1 -1
  21. package/dest/errors/reqresp.error.js +0 -21
  22. package/dest/index.d.ts +1 -2
  23. package/dest/index.d.ts.map +1 -1
  24. package/dest/index.js +0 -1
  25. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +99 -59
  26. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  27. package/dest/mem_pools/attestation_pool/attestation_pool.js +265 -199
  28. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  29. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  30. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +181 -65
  31. package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -1
  32. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  33. package/dest/mem_pools/attestation_pool/mocks.js +6 -4
  34. package/dest/mem_pools/index.d.ts +1 -2
  35. package/dest/mem_pools/index.d.ts.map +1 -1
  36. package/dest/mem_pools/instrumentation.d.ts +1 -1
  37. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  38. package/dest/mem_pools/instrumentation.js +17 -1
  39. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +1 -5
  40. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -1
  41. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +1 -7
  42. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  43. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  44. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +2 -1
  45. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -1
  46. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  47. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -0
  48. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
  49. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
  50. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +62 -0
  51. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +7 -1
  52. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  53. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +2 -2
  54. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +1 -1
  55. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  56. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +8 -6
  57. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +2 -2
  58. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  59. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
  60. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +12 -5
  61. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  62. package/dest/mem_pools/tx_pool_v2/interfaces.js +2 -1
  63. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +29 -11
  64. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  65. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +46 -16
  66. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +1 -1
  67. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  68. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +26 -43
  69. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +4 -2
  70. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  71. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +3 -0
  72. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +1 -1
  73. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  74. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +94 -88
  75. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +9 -3
  76. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  77. package/dest/msg_validators/attestation_validator/attestation_validator.js +37 -12
  78. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +7 -3
  79. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  80. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +4 -5
  81. package/dest/msg_validators/clock_tolerance.d.ts +12 -1
  82. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
  83. package/dest/msg_validators/clock_tolerance.js +56 -3
  84. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -4
  85. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  86. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
  87. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -4
  88. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  89. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
  90. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +20 -9
  91. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  92. package/dest/msg_validators/proposal_validator/proposal_validator.js +88 -52
  93. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
  94. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  95. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +8 -15
  96. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +1 -1
  97. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  98. package/dest/msg_validators/tx_validator/allowed_public_setup.js +21 -32
  99. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  100. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  101. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  102. package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
  103. package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts +15 -0
  104. package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts.map +1 -0
  105. package/dest/msg_validators/tx_validator/cached_tx_validator.js +19 -0
  106. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
  107. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
  108. package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
  109. package/dest/msg_validators/tx_validator/data_validator.d.ts +2 -1
  110. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  111. package/dest/msg_validators/tx_validator/data_validator.js +36 -2
  112. package/dest/msg_validators/tx_validator/factory.d.ts +27 -7
  113. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  114. package/dest/msg_validators/tx_validator/factory.js +47 -17
  115. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  116. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  117. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  118. package/dest/msg_validators/tx_validator/gas_validator.d.ts +48 -7
  119. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  120. package/dest/msg_validators/tx_validator/gas_validator.js +88 -41
  121. package/dest/msg_validators/tx_validator/index.d.ts +4 -1
  122. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  123. package/dest/msg_validators/tx_validator/index.js +3 -0
  124. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  125. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  126. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  127. package/dest/msg_validators/tx_validator/phases_validator.d.ts +21 -1
  128. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  129. package/dest/msg_validators/tx_validator/phases_validator.js +49 -2
  130. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +2 -1
  131. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  132. package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -0
  133. package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts +48 -0
  134. package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts.map +1 -0
  135. package/dest/msg_validators/tx_validator/tx_validation_cache.js +68 -0
  136. package/dest/services/data_store.d.ts +1 -1
  137. package/dest/services/data_store.d.ts.map +1 -1
  138. package/dest/services/data_store.js +5 -5
  139. package/dest/services/discv5/discV5_service.d.ts +2 -1
  140. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  141. package/dest/services/discv5/discV5_service.js +35 -8
  142. package/dest/services/dummy_service.d.ts +11 -15
  143. package/dest/services/dummy_service.d.ts.map +1 -1
  144. package/dest/services/dummy_service.js +12 -16
  145. package/dest/services/encoding.d.ts +5 -1
  146. package/dest/services/encoding.d.ts.map +1 -1
  147. package/dest/services/encoding.js +7 -1
  148. package/dest/services/gossipsub/topic_score_params.d.ts +13 -2
  149. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
  150. package/dest/services/gossipsub/topic_score_params.js +21 -4
  151. package/dest/services/libp2p/instrumentation.d.ts +3 -1
  152. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  153. package/dest/services/libp2p/instrumentation.js +14 -0
  154. package/dest/services/libp2p/libp2p_service.d.ts +36 -46
  155. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  156. package/dest/services/libp2p/libp2p_service.js +311 -276
  157. package/dest/services/peer-manager/peer_manager.d.ts +6 -2
  158. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  159. package/dest/services/peer-manager/peer_manager.js +38 -10
  160. package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
  161. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  162. package/dest/services/peer-manager/peer_scoring.js +32 -10
  163. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -8
  164. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  165. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +81 -86
  166. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +10 -6
  167. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  168. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +5 -4
  169. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  170. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +13 -7
  171. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +3 -1
  172. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  173. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +3 -0
  174. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +5 -14
  175. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -1
  176. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +6 -20
  177. package/dest/services/reqresp/config.d.ts +3 -3
  178. package/dest/services/reqresp/config.d.ts.map +1 -1
  179. package/dest/services/reqresp/interface.d.ts +16 -18
  180. package/dest/services/reqresp/interface.d.ts.map +1 -1
  181. package/dest/services/reqresp/interface.js +10 -20
  182. package/dest/services/reqresp/metrics.d.ts +1 -1
  183. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  184. package/dest/services/reqresp/metrics.js +0 -1
  185. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +4 -3
  186. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  187. package/dest/services/reqresp/protocols/block_txs/bitvector.js +3 -2
  188. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
  189. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  190. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +31 -28
  191. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +12 -7
  192. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  193. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +42 -24
  194. package/dest/services/reqresp/protocols/index.d.ts +1 -2
  195. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  196. package/dest/services/reqresp/protocols/index.js +0 -1
  197. package/dest/services/reqresp/protocols/tx.d.ts +1 -1
  198. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  199. package/dest/services/reqresp/protocols/tx.js +1 -3
  200. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
  201. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  202. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
  203. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  204. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  205. package/dest/services/reqresp/rate-limiter/rate_limits.js +0 -10
  206. package/dest/services/reqresp/reqresp.d.ts +7 -29
  207. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  208. package/dest/services/reqresp/reqresp.js +41 -214
  209. package/dest/services/service.d.ts +9 -12
  210. package/dest/services/service.d.ts.map +1 -1
  211. package/dest/services/tx_collection/config.d.ts +2 -23
  212. package/dest/services/tx_collection/config.d.ts.map +1 -1
  213. package/dest/services/tx_collection/config.js +2 -55
  214. package/dest/services/tx_collection/file_store_tx_collection.d.ts +12 -28
  215. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
  216. package/dest/services/tx_collection/file_store_tx_collection.js +43 -83
  217. package/dest/services/tx_collection/file_store_tx_source.d.ts +5 -4
  218. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
  219. package/dest/services/tx_collection/file_store_tx_source.js +39 -29
  220. package/dest/services/tx_collection/index.d.ts +2 -3
  221. package/dest/services/tx_collection/index.d.ts.map +1 -1
  222. package/dest/services/tx_collection/index.js +0 -1
  223. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  224. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  225. package/dest/services/tx_collection/instrumentation.js +0 -2
  226. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  227. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  228. package/dest/services/tx_collection/request_tracker.js +84 -0
  229. package/dest/services/tx_collection/tx_collection.d.ts +36 -55
  230. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  231. package/dest/services/tx_collection/tx_collection.js +275 -119
  232. package/dest/services/tx_collection/tx_collection_sink.d.ts +1 -1
  233. package/dest/services/tx_collection/tx_collection_sink.js +2 -2
  234. package/dest/services/tx_collection/tx_source.d.ts +6 -5
  235. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  236. package/dest/services/tx_collection/tx_source.js +9 -7
  237. package/dest/services/tx_file_store/tx_file_store.d.ts +1 -3
  238. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  239. package/dest/services/tx_file_store/tx_file_store.js +4 -14
  240. package/dest/services/tx_provider.d.ts +3 -1
  241. package/dest/services/tx_provider.d.ts.map +1 -1
  242. package/dest/services/tx_provider.js +3 -0
  243. package/dest/test-helpers/make-test-p2p-clients.d.ts +1 -1
  244. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  245. package/dest/test-helpers/make-test-p2p-clients.js +5 -2
  246. package/dest/test-helpers/mock-pubsub.d.ts +23 -9
  247. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  248. package/dest/test-helpers/mock-pubsub.js +44 -44
  249. package/dest/test-helpers/reqresp-nodes.d.ts +4 -5
  250. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  251. package/dest/test-helpers/reqresp-nodes.js +16 -18
  252. package/dest/test-helpers/test_tx_provider.d.ts +3 -1
  253. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -1
  254. package/dest/test-helpers/test_tx_provider.js +3 -0
  255. package/dest/test-helpers/testbench-utils.d.ts +12 -14
  256. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  257. package/dest/test-helpers/testbench-utils.js +40 -15
  258. package/dest/testbench/p2p_client_testbench_worker.d.ts +3 -5
  259. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  260. package/dest/testbench/p2p_client_testbench_worker.js +85 -39
  261. package/dest/testbench/worker_client_manager.d.ts +12 -6
  262. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  263. package/dest/testbench/worker_client_manager.js +57 -11
  264. package/dest/util.d.ts +12 -7
  265. package/dest/util.d.ts.map +1 -1
  266. package/dest/util.js +35 -14
  267. package/dest/versioning.d.ts +3 -6
  268. package/dest/versioning.d.ts.map +1 -1
  269. package/dest/versioning.js +3 -24
  270. package/package.json +15 -14
  271. package/src/bootstrap/bootstrap.ts +9 -1
  272. package/src/client/factory.ts +57 -8
  273. package/src/client/interface.ts +15 -11
  274. package/src/client/p2p_client.ts +106 -70
  275. package/src/client/test/{tx_proposal_collector/README.md → p2p_client.batch_tx_requester.bench.README.md} +23 -53
  276. package/src/config.ts +195 -7
  277. package/src/errors/p2p-service.error.ts +11 -0
  278. package/src/errors/reqresp.error.ts +0 -25
  279. package/src/index.ts +0 -1
  280. package/src/mem_pools/attestation_pool/attestation_pool.ts +316 -241
  281. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +204 -68
  282. package/src/mem_pools/attestation_pool/mocks.ts +13 -8
  283. package/src/mem_pools/index.ts +0 -3
  284. package/src/mem_pools/instrumentation.ts +5 -1
  285. package/src/mem_pools/tx_pool_v2/README.md +9 -1
  286. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +1 -9
  287. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +2 -1
  288. package/src/mem_pools/tx_pool_v2/eviction/index.ts +1 -0
  289. package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +65 -0
  290. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +11 -1
  291. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +3 -3
  292. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +15 -6
  293. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +2 -1
  294. package/src/mem_pools/tx_pool_v2/interfaces.ts +12 -4
  295. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +72 -20
  296. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +29 -43
  297. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +13 -1
  298. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +96 -94
  299. package/src/msg_validators/attestation_validator/README.md +49 -0
  300. package/src/msg_validators/attestation_validator/attestation_validator.ts +41 -9
  301. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +14 -7
  302. package/src/msg_validators/clock_tolerance.ts +73 -3
  303. package/src/msg_validators/proposal_validator/README.md +123 -0
  304. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +24 -4
  305. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +35 -7
  306. package/src/msg_validators/proposal_validator/proposal_validator.ts +109 -56
  307. package/src/msg_validators/tx_validator/README.md +15 -3
  308. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -12
  309. package/src/msg_validators/tx_validator/allowed_public_setup.ts +16 -35
  310. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  311. package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
  312. package/src/msg_validators/tx_validator/cached_tx_validator.ts +31 -0
  313. package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
  314. package/src/msg_validators/tx_validator/data_validator.ts +44 -1
  315. package/src/msg_validators/tx_validator/factory.ts +61 -10
  316. package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
  317. package/src/msg_validators/tx_validator/gas_validator.ts +121 -39
  318. package/src/msg_validators/tx_validator/index.ts +3 -0
  319. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  320. package/src/msg_validators/tx_validator/phases_validator.ts +60 -1
  321. package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -0
  322. package/src/msg_validators/tx_validator/tx_validation_cache.ts +101 -0
  323. package/src/services/data_store.ts +5 -13
  324. package/src/services/discv5/discV5_service.ts +38 -5
  325. package/src/services/dummy_service.ts +14 -39
  326. package/src/services/encoding.ts +9 -1
  327. package/src/services/gossipsub/topic_score_params.ts +36 -4
  328. package/src/services/libp2p/instrumentation.ts +14 -0
  329. package/src/services/libp2p/libp2p_service.ts +339 -313
  330. package/src/services/peer-manager/peer_manager.ts +44 -10
  331. package/src/services/peer-manager/peer_scoring.ts +27 -5
  332. package/src/services/reqresp/README.md +215 -0
  333. package/src/services/reqresp/batch-tx-requester/README.md +46 -7
  334. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +77 -95
  335. package/src/services/reqresp/batch-tx-requester/interface.ts +13 -5
  336. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +13 -6
  337. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +5 -0
  338. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +12 -25
  339. package/src/services/reqresp/config.ts +2 -2
  340. package/src/services/reqresp/interface.ts +21 -47
  341. package/src/services/reqresp/metrics.ts +0 -1
  342. package/src/services/reqresp/protocols/block_txs/bitvector.ts +3 -2
  343. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +34 -30
  344. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +47 -20
  345. package/src/services/reqresp/protocols/index.ts +0 -1
  346. package/src/services/reqresp/protocols/tx.ts +1 -3
  347. package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
  348. package/src/services/reqresp/rate-limiter/rate_limits.ts +0 -10
  349. package/src/services/reqresp/reqresp.ts +45 -260
  350. package/src/services/service.ts +12 -28
  351. package/src/services/tx_collection/config.ts +3 -80
  352. package/src/services/tx_collection/file_store_tx_collection.ts +54 -103
  353. package/src/services/tx_collection/file_store_tx_source.ts +43 -31
  354. package/src/services/tx_collection/index.ts +1 -6
  355. package/src/services/tx_collection/instrumentation.ts +1 -7
  356. package/src/services/tx_collection/request_tracker.ts +127 -0
  357. package/src/services/tx_collection/tx_collection.ts +331 -176
  358. package/src/services/tx_collection/tx_collection_sink.ts +2 -2
  359. package/src/services/tx_collection/tx_source.ts +8 -7
  360. package/src/services/tx_file_store/tx_file_store.ts +5 -17
  361. package/src/services/tx_provider.ts +5 -0
  362. package/src/test-helpers/make-test-p2p-clients.ts +4 -1
  363. package/src/test-helpers/mock-pubsub.ts +46 -60
  364. package/src/test-helpers/reqresp-nodes.ts +13 -23
  365. package/src/test-helpers/test_tx_provider.ts +5 -0
  366. package/src/test-helpers/testbench-utils.ts +51 -28
  367. package/src/testbench/p2p_client_testbench_worker.ts +89 -55
  368. package/src/testbench/worker_client_manager.ts +72 -25
  369. package/src/util.ts +33 -18
  370. package/src/versioning.ts +3 -33
  371. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +0 -2
  372. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +0 -1
  373. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +0 -304
  374. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +0 -73
  375. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +0 -1
  376. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +0 -8
  377. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
  378. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
  379. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
  380. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
  381. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
  382. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
  383. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
  384. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
  385. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
  386. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
  387. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
  388. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
  389. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
  390. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
  391. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
  392. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
  393. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
  394. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
  395. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
  396. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
  397. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
  398. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
  399. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
  400. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
  401. package/dest/mem_pools/tx_pool/index.d.ts +0 -3
  402. package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
  403. package/dest/mem_pools/tx_pool/index.js +0 -2
  404. package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
  405. package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
  406. package/dest/mem_pools/tx_pool/priority.js +0 -15
  407. package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
  408. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
  409. package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
  410. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
  411. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
  412. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
  413. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -24
  414. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  415. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -378
  416. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +0 -64
  417. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +0 -1
  418. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +0 -151
  419. package/dest/services/reqresp/protocols/block.d.ts +0 -9
  420. package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
  421. package/dest/services/reqresp/protocols/block.js +0 -32
  422. package/dest/services/tx_collection/fast_tx_collection.d.ts +0 -54
  423. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
  424. package/dest/services/tx_collection/fast_tx_collection.js +0 -327
  425. package/dest/services/tx_collection/missing_txs_tracker.d.ts +0 -32
  426. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +0 -1
  427. package/dest/services/tx_collection/missing_txs_tracker.js +0 -27
  428. package/dest/services/tx_collection/proposal_tx_collector.d.ts +0 -49
  429. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +0 -1
  430. package/dest/services/tx_collection/proposal_tx_collector.js +0 -50
  431. package/dest/services/tx_collection/slow_tx_collection.d.ts +0 -57
  432. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +0 -1
  433. package/dest/services/tx_collection/slow_tx_collection.js +0 -211
  434. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +0 -345
  435. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +0 -43
  436. package/src/mem_pools/tx_pool/README.md +0 -270
  437. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
  438. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
  439. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
  440. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
  441. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
  442. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
  443. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
  444. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
  445. package/src/mem_pools/tx_pool/index.ts +0 -2
  446. package/src/mem_pools/tx_pool/priority.ts +0 -20
  447. package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
  448. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
  449. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -373
  450. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +0 -161
  451. package/src/services/reqresp/protocols/block.ts +0 -37
  452. package/src/services/tx_collection/fast_tx_collection.ts +0 -387
  453. package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
  454. package/src/services/tx_collection/proposal_tx_collector.ts +0 -113
  455. package/src/services/tx_collection/slow_tx_collection.ts +0 -266
@@ -1,14 +1,14 @@
1
1
  import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
2
  import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
3
- import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import { maxBy, merge } from '@aztec/foundation/collection';
4
4
  import { type Logger, createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
5
5
  import { RunningPromise } from '@aztec/foundation/running-promise';
6
6
  import { Timer } from '@aztec/foundation/timer';
7
7
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
8
8
  import { protocolContractsHash } from '@aztec/protocol-contracts';
9
- import type { EthAddress, L2Block, L2BlockSource } from '@aztec/stdlib/block';
9
+ import type { EthAddress, L2BlockSource } from '@aztec/stdlib/block';
10
10
  import type { ContractDataSource } from '@aztec/stdlib/contract';
11
- import { GasFees } from '@aztec/stdlib/gas';
11
+ import { type BlockMinFeesProvider, GasFees } from '@aztec/stdlib/gas';
12
12
  import type { ClientProtocolCircuitVerifier, PeerInfo, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
13
13
  import {
14
14
  BlockProposal,
@@ -17,15 +17,15 @@ import {
17
17
  type CheckpointProposalCore,
18
18
  type Gossipable,
19
19
  P2PMessage,
20
- type ValidationResult as P2PValidationResult,
21
20
  PeerErrorSeverity,
21
+ PeerErrorSeverityByHarshness,
22
22
  TopicType,
23
23
  createTopicString,
24
24
  getTopicsForConfig,
25
25
  metricsTopicStrToLabels,
26
26
  } from '@aztec/stdlib/p2p';
27
27
  import { MerkleTreeId } from '@aztec/stdlib/trees';
28
- import { Tx, type TxHash, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
28
+ import { Tx, type TxValidationResult } from '@aztec/stdlib/tx';
29
29
  import type { UInt64 } from '@aztec/stdlib/types';
30
30
  import { compressComponentVersions } from '@aztec/stdlib/versioning';
31
31
  import {
@@ -50,13 +50,15 @@ import { yamux } from '@chainsafe/libp2p-yamux';
50
50
  import { bootstrap } from '@libp2p/bootstrap';
51
51
  import { identify } from '@libp2p/identify';
52
52
  import { type Message, type MultiaddrConnection, type PeerId, TopicValidatorResult } from '@libp2p/interface';
53
- import type { ConnectionManager } from '@libp2p/interface-internal';
53
+ import type { AddressManager, ConnectionManager } from '@libp2p/interface-internal';
54
54
  import { mplex } from '@libp2p/mplex';
55
55
  import { tcp } from '@libp2p/tcp';
56
+ import { multiaddr } from '@multiformats/multiaddr';
56
57
  import { ENR } from '@nethermindeth/enr';
57
58
  import { createLibp2p } from 'libp2p';
58
59
 
59
60
  import type { P2PConfig } from '../../config.js';
61
+ import { CheckpointProposalReceivedCallbackNotRegisteredError } from '../../errors/p2p-service.error.js';
60
62
  import type { MemPools } from '../../mem_pools/interface.js';
61
63
  import {
62
64
  BlockProposalValidator,
@@ -72,8 +74,8 @@ import {
72
74
  createFirstStageTxValidationsForGossipedTransactions,
73
75
  createSecondStageTxValidationsForGossipedTransactions,
74
76
  createTxValidatorForBlockProposalReceivedTxs,
75
- createTxValidatorForReqResponseReceivedTxs,
76
77
  } from '../../msg_validators/tx_validator/factory.js';
78
+ import { TxValidationCache } from '../../msg_validators/tx_validator/tx_validation_cache.js';
77
79
  import { GossipSubEvent } from '../../types/index.js';
78
80
  import { type PubSubLibp2p, convertToMultiaddr } from '../../util.js';
79
81
  import { getVersions } from '../../versioning.js';
@@ -91,19 +93,15 @@ import {
91
93
  AuthRequest,
92
94
  BlockTxsRequest,
93
95
  BlockTxsResponse,
94
- DEFAULT_SUB_PROTOCOL_VALIDATORS,
95
96
  type ReqRespInterface,
96
97
  type ReqRespResponse,
97
98
  ReqRespSubProtocol,
98
99
  type ReqRespSubProtocolHandler,
99
100
  type ReqRespSubProtocolHandlers,
100
- type ReqRespSubProtocolValidators,
101
101
  StatusMessage,
102
- type SubProtocolMap,
103
102
  ValidationError,
104
103
  pingHandler,
105
104
  reqGoodbyeHandler,
106
- reqRespBlockHandler,
107
105
  reqRespBlockTxsHandler,
108
106
  reqRespStatusHandler,
109
107
  reqRespTxHandler,
@@ -111,6 +109,7 @@ import {
111
109
  import { ReqResp } from '../reqresp/reqresp.js';
112
110
  import type {
113
111
  P2PBlockReceivedCallback,
112
+ P2PCheckpointAttestationCallback,
114
113
  P2PCheckpointReceivedCallback,
115
114
  P2PDuplicateAttestationCallback,
116
115
  P2PService,
@@ -129,7 +128,7 @@ type ValidationOutcome = { allPassed: true } | { allPassed: false; failure: Vali
129
128
  // REFACTOR: Unify with the type above
130
129
  type ReceivedMessageValidationResult<T, M = undefined> =
131
130
  | { obj: T; result: Exclude<TopicValidatorResult, TopicValidatorResult.Reject>; metadata?: M }
132
- | { obj?: T; result: TopicValidatorResult.Reject; metadata?: M };
131
+ | { obj?: T; result: TopicValidatorResult.Reject; metadata?: M; severity: PeerErrorSeverity };
133
132
 
134
133
  /**
135
134
  * Lib P2P implementation of the P2PService interface.
@@ -146,8 +145,6 @@ export class LibP2PService extends WithTracer implements P2PService {
146
145
  private protocolVersion = '';
147
146
  private topicStrings: Record<TopicType, string> = {} as Record<TopicType, string>;
148
147
 
149
- private feesCache: { blockNumber: BlockNumber; gasFees: GasFees } | undefined;
150
-
151
148
  /** Callback invoked when a duplicate proposal is detected (triggers slashing). */
152
149
  private duplicateProposalCallback?: (info: {
153
150
  slot: SlotNumber;
@@ -158,6 +155,9 @@ export class LibP2PService extends WithTracer implements P2PService {
158
155
  /** Callback invoked when a duplicate attestation is detected (triggers slashing). */
159
156
  private duplicateAttestationCallback?: P2PDuplicateAttestationCallback;
160
157
 
158
+ /** Callback invoked when a valid checkpoint attestation is accepted into the pool. */
159
+ private checkpointAttestationCallback?: P2PCheckpointAttestationCallback;
160
+
161
161
  /**
162
162
  * Callback for when a block is received from a peer.
163
163
  * @param block - The block received from the peer.
@@ -170,10 +170,19 @@ export class LibP2PService extends WithTracer implements P2PService {
170
170
  * @param checkpoint - The checkpoint proposal received from the peer.
171
171
  * @returns The attestations for the checkpoint, if any.
172
172
  */
173
- private checkpointReceivedCallback: P2PCheckpointReceivedCallback;
173
+ private allNodesCheckpointReceivedCallback: P2PCheckpointReceivedCallback;
174
+ /**
175
+ * Callback for when a checkpoint proposal is received - specifically for validators - from a peer.
176
+ * @param checkpoint - The checkpoint proposal received from the peer.
177
+ * @returns The attestations for the checkpoint, if any.
178
+ */
179
+ private validatorCheckpointReceivedCallback: P2PCheckpointReceivedCallback;
174
180
 
175
181
  private gossipSubEventHandler: (e: CustomEvent<GossipsubMessage>) => void;
176
182
 
183
+ private ipChangedHandler?: (ip: string) => void;
184
+ private discoveredP2pIp?: string;
185
+
177
186
  private instrumentation: P2PInstrumentation;
178
187
 
179
188
  private telemetry: TelemetryClient;
@@ -191,8 +200,10 @@ export class LibP2PService extends WithTracer implements P2PService {
191
200
  private epochCache: EpochCacheInterface,
192
201
  private proofVerifier: ClientProtocolCircuitVerifier,
193
202
  private worldStateSynchronizer: WorldStateSynchronizer,
203
+ private blockMinFeesProvider: BlockMinFeesProvider,
194
204
  telemetry: TelemetryClient,
195
205
  logger: Logger = createLogger('p2p:libp2p_service'),
206
+ private txValidationCache?: TxValidationCache,
196
207
  ) {
197
208
  super(telemetry, 'LibP2PService');
198
209
  this.telemetry = telemetry;
@@ -222,40 +233,55 @@ export class LibP2PService extends WithTracer implements P2PService {
222
233
  this.protocolVersion,
223
234
  );
224
235
 
225
- this.blockProposalValidator = new BlockProposalValidator(epochCache, {
226
- txsPermitted: !config.disableTransactions,
227
- maxTxsPerBlock: config.maxTxsPerBlock,
228
- });
229
- this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, {
236
+ const p2pPropagationTime = config.attestationPropagationTime;
237
+ const proposalValidatorOpts = {
230
238
  txsPermitted: !config.disableTransactions,
231
- maxTxsPerBlock: config.maxTxsPerBlock,
232
- });
239
+ maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
240
+ maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
241
+ p2pPropagationTime,
242
+ skipSlotValidation: config.skipProposalSlotValidation,
243
+ signatureContext: {
244
+ chainId: config.l1ChainId,
245
+ rollupAddress: config.rollupAddress,
246
+ },
247
+ };
248
+ this.blockProposalValidator = new BlockProposalValidator(epochCache, proposalValidatorOpts);
249
+ this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, proposalValidatorOpts);
250
+ const attestationValidatorOpts = {
251
+ l1PublishingTime: config.l1PublishingTime,
252
+ p2pPropagationTime,
253
+ signatureContext: proposalValidatorOpts.signatureContext,
254
+ };
233
255
  this.checkpointAttestationValidator = config.fishermanMode
234
- ? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry)
235
- : new CheckpointAttestationValidator(epochCache);
256
+ ? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry, attestationValidatorOpts)
257
+ : new CheckpointAttestationValidator(epochCache, attestationValidatorOpts);
236
258
 
237
259
  this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
238
260
 
239
261
  this.blockReceivedCallback = async (block: BlockProposal): Promise<boolean> => {
240
- this.logger.debug(
241
- `Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber} from peer.`,
262
+ this.logger.warn(
263
+ `Handler for block received not yet registered on P2P service. Received block ${block.blockNumber} for slot ${block.slotNumber} from peer.`,
242
264
  { p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier() },
243
265
  );
244
- return false;
266
+ return true;
245
267
  };
246
268
 
247
- this.checkpointReceivedCallback = (
248
- checkpoint: CheckpointProposalCore,
269
+ this.allNodesCheckpointReceivedCallback = (
270
+ _checkpoint: CheckpointProposalCore,
271
+ ): Promise<CheckpointAttestation[] | undefined> => {
272
+ throw new CheckpointProposalReceivedCallbackNotRegisteredError();
273
+ };
274
+
275
+ this.validatorCheckpointReceivedCallback = (
276
+ _checkpoint: CheckpointProposalCore,
249
277
  ): Promise<CheckpointAttestation[] | undefined> => {
250
- this.logger.debug(
251
- `Handler not yet registered: Checkpoint received callback not set. Received checkpoint for slot ${checkpoint.slotNumber} from peer.`,
252
- );
253
278
  return Promise.resolve(undefined);
254
279
  };
255
280
  }
256
281
 
257
- public updateConfig(config: Partial<P2PReqRespConfig>) {
282
+ public updateConfig(config: Partial<P2PReqRespConfig & Pick<P2PConfig, 'skipIncomingProposals'>>) {
258
283
  this.reqresp.updateConfig(config);
284
+ this.config = merge(this.config, config);
259
285
  }
260
286
 
261
287
  /**
@@ -274,9 +300,11 @@ export class LibP2PService extends WithTracer implements P2PService {
274
300
  proofVerifier: ClientProtocolCircuitVerifier;
275
301
  worldStateSynchronizer: WorldStateSynchronizer;
276
302
  peerStore: AztecAsyncKVStore;
303
+ blockMinFeesProvider: BlockMinFeesProvider;
277
304
  telemetry: TelemetryClient;
278
305
  logger: Logger;
279
306
  packageVersion: string;
307
+ txValidationCache?: TxValidationCache;
280
308
  },
281
309
  ) {
282
310
  const {
@@ -286,9 +314,11 @@ export class LibP2PService extends WithTracer implements P2PService {
286
314
  mempools,
287
315
  proofVerifier,
288
316
  peerStore,
317
+ blockMinFeesProvider,
289
318
  telemetry,
290
319
  logger,
291
320
  packageVersion,
321
+ txValidationCache,
292
322
  } = deps;
293
323
  const { p2pPort, maxPeerCount, listenAddress } = config;
294
324
  const bindAddrTcp = convertToMultiaddr(listenAddress, p2pPort, 'tcp');
@@ -339,9 +369,12 @@ export class LibP2PService extends WithTracer implements P2PService {
339
369
  const l1Constants = epochCache.getL1Constants();
340
370
  const topicScoreParams = createAllTopicScoreParams(protocolVersion, {
341
371
  slotDurationMs: l1Constants.slotDuration * 1000,
372
+ ethereumSlotDuration: l1Constants.ethereumSlotDuration,
342
373
  heartbeatIntervalMs: config.gossipsubInterval,
343
374
  targetCommitteeSize: l1Constants.targetCommitteeSize,
344
375
  blockDurationMs: config.blockDurationMs,
376
+ l1PublishingTime: config.l1PublishingTime,
377
+ p2pPropagationTime: config.attestationPropagationTime,
345
378
  expectedBlockProposalsPerSlot: config.expectedBlockProposalsPerSlot,
346
379
  });
347
380
 
@@ -443,8 +476,9 @@ export class LibP2PService extends WithTracer implements P2PService {
443
476
  topics: topicScoreParams,
444
477
  }),
445
478
  }) as (components: GossipSubComponents) => GossipSub,
446
- components: (components: { connectionManager: ConnectionManager }) => ({
479
+ components: (components: { connectionManager: ConnectionManager; addressManager: AddressManager }) => ({
447
480
  connectionManager: components.connectionManager,
481
+ addressManager: components.addressManager,
448
482
  }),
449
483
  },
450
484
  logger: createLibp2pComponentLogger(logger.module, logger.getBindings()),
@@ -466,6 +500,9 @@ export class LibP2PService extends WithTracer implements P2PService {
466
500
  epochCache,
467
501
  );
468
502
 
503
+ // Gate req/resp data protocols for unauthenticated peers when p2pAllowOnlyValidators is enabled
504
+ reqresp.setShouldRejectPeer(peerId => peerManager.shouldDisableP2PGossip(peerId));
505
+
469
506
  // Configure application-specific scoring for gossipsub.
470
507
  // The weight scales app score to align with gossipsub thresholds:
471
508
  // - Disconnect (-50) × 10 = -500 = gossipThreshold (stops receiving gossip)
@@ -486,8 +523,10 @@ export class LibP2PService extends WithTracer implements P2PService {
486
523
  epochCache,
487
524
  proofVerifier,
488
525
  worldStateSynchronizer,
526
+ blockMinFeesProvider,
489
527
  telemetry,
490
528
  logger,
529
+ txValidationCache,
491
530
  );
492
531
  }
493
532
 
@@ -501,24 +540,21 @@ export class LibP2PService extends WithTracer implements P2PService {
501
540
  throw new Error('P2P service already started');
502
541
  }
503
542
 
504
- // Get listen & announce addresses for logging
505
543
  const { p2pIp, p2pPort } = this.config;
506
- if (!p2pIp) {
507
- throw new Error('Announce address not provided.');
544
+ if (!p2pIp && !this.config.queryForIp) {
545
+ throw new Error('Announce address not provided and queryForIp is not enabled.');
508
546
  }
509
- const announceTcpMultiaddr = convertToMultiaddr(p2pIp, p2pPort, 'tcp');
547
+ const announceTcpMultiaddr = p2pIp ? convertToMultiaddr(p2pIp, p2pPort, 'tcp') : undefined;
510
548
 
511
549
  // Create request response protocol handlers
512
550
  const txHandler = reqRespTxHandler(this.mempools);
513
551
  const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
514
- const blockHandler = reqRespBlockHandler(this.archiver);
515
552
  const statusHandler = reqRespStatusHandler(this.protocolVersion, this.worldStateSynchronizer, this.logger);
516
553
 
517
554
  const requestResponseHandlers: Partial<ReqRespSubProtocolHandlers> = {
518
555
  [ReqRespSubProtocol.PING]: pingHandler,
519
556
  [ReqRespSubProtocol.STATUS]: statusHandler.bind(this),
520
557
  [ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this),
521
- [ReqRespSubProtocol.BLOCK]: blockHandler.bind(this),
522
558
  };
523
559
 
524
560
  if (!this.config.disableTransactions) {
@@ -534,17 +570,9 @@ export class LibP2PService extends WithTracer implements P2PService {
534
570
  requestResponseHandlers[ReqRespSubProtocol.TX] = txHandler.bind(this);
535
571
  }
536
572
 
537
- // Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
538
- const reqrespSubProtocolValidators = {
539
- ...DEFAULT_SUB_PROTOCOL_VALIDATORS,
540
- [ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
541
- [ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
542
- [ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this),
543
- };
544
-
545
573
  await this.peerManager.initializePeers();
546
574
 
547
- await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
575
+ await this.reqresp.start(requestResponseHandlers);
548
576
 
549
577
  await this.node.start();
550
578
 
@@ -560,6 +588,38 @@ export class LibP2PService extends WithTracer implements P2PService {
560
588
  if (!this.config.p2pDiscoveryDisabled) {
561
589
  await this.peerDiscoveryService.start();
562
590
  }
591
+
592
+ // Bridge discv5 IP changes to libp2p's AddressManager so peers see the updated address
593
+ if (this.config.queryForIp) {
594
+ this.discoveredP2pIp = this.config.p2pIp;
595
+ this.logger.info('IP change tracking enabled, bridging discv5 IP updates to libp2p AddressManager');
596
+ this.ipChangedHandler = (ip: string) => {
597
+ const addressManager = this.node.services.components.addressManager;
598
+ const newAddr = multiaddr(convertToMultiaddr(ip, this.config.p2pPort, 'tcp'));
599
+ const previousIp = this.discoveredP2pIp;
600
+
601
+ if (previousIp) {
602
+ const oldAddr = multiaddr(convertToMultiaddr(previousIp, this.config.p2pPort, 'tcp'));
603
+ addressManager.removeObservedAddr(oldAddr);
604
+ this.logger.info('Libp2p announce address updated due to IP change', {
605
+ previousIp,
606
+ newIp: ip,
607
+ newMultiaddr: newAddr.toString(),
608
+ });
609
+ } else {
610
+ this.logger.info('Libp2p announce address set from initial discv5 IP discovery', {
611
+ ip,
612
+ multiaddr: newAddr.toString(),
613
+ });
614
+ }
615
+
616
+ addressManager.addObservedAddr(newAddr);
617
+ addressManager.confirmObservedAddr(newAddr);
618
+ this.discoveredP2pIp = ip;
619
+ };
620
+ this.peerDiscoveryService.on('ip:changed', this.ipChangedHandler);
621
+ }
622
+
563
623
  this.discoveryRunningPromise = new RunningPromise(
564
624
  async () => {
565
625
  await this.peerManager.heartbeat();
@@ -585,6 +645,11 @@ export class LibP2PService extends WithTracer implements P2PService {
585
645
  // Remove gossip sub listener
586
646
  this.node.services.pubsub.removeEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
587
647
 
648
+ if (this.ipChangedHandler) {
649
+ this.peerDiscoveryService.removeListener('ip:changed', this.ipChangedHandler);
650
+ this.ipChangedHandler = undefined;
651
+ }
652
+
588
653
  // Stop peer manager
589
654
  this.logger.debug('Stopping peer manager...');
590
655
  await this.peerManager.stop();
@@ -599,12 +664,8 @@ export class LibP2PService extends WithTracer implements P2PService {
599
664
  this.logger.info('LibP2P service stopped');
600
665
  }
601
666
 
602
- addReqRespSubProtocol(
603
- subProtocol: ReqRespSubProtocol,
604
- handler: ReqRespSubProtocolHandler,
605
- validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
606
- ): Promise<void> {
607
- return this.reqresp.addSubProtocol(subProtocol, handler, validator);
667
+ addReqRespSubProtocol(subProtocol: ReqRespSubProtocol, handler: ReqRespSubProtocolHandler): Promise<void> {
668
+ return this.reqresp.addSubProtocol(subProtocol, handler);
608
669
  }
609
670
 
610
671
  public registerThisValidatorAddresses(address: EthAddress[]): void {
@@ -632,20 +693,6 @@ export class LibP2PService extends WithTracer implements P2PService {
632
693
  setImmediate(() => void safeJob());
633
694
  }
634
695
 
635
- /**
636
- * Send a batch of requests to peers, and return the responses
637
- * @param protocol - The request response protocol to use
638
- * @param requests - The requests to send to the peers
639
- * @returns The responses to the requests
640
- */
641
- sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(
642
- protocol: SubProtocol,
643
- requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[],
644
- pinnedPeerId: PeerId | undefined,
645
- ): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]> {
646
- return this.reqresp.sendBatchRequest(protocol, requests, pinnedPeerId);
647
- }
648
-
649
696
  public sendRequestToPeer(
650
697
  peerId: PeerId,
651
698
  subProtocol: ReqRespSubProtocol,
@@ -667,8 +714,12 @@ export class LibP2PService extends WithTracer implements P2PService {
667
714
  this.blockReceivedCallback = callback;
668
715
  }
669
716
 
670
- public registerCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
671
- this.checkpointReceivedCallback = callback;
717
+ public registerValidatorCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
718
+ this.validatorCheckpointReceivedCallback = callback;
719
+ }
720
+
721
+ public registerAllNodesCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
722
+ this.allNodesCheckpointReceivedCallback = callback;
672
723
  }
673
724
 
674
725
  /**
@@ -690,6 +741,10 @@ export class LibP2PService extends WithTracer implements P2PService {
690
741
  this.duplicateAttestationCallback = callback;
691
742
  }
692
743
 
744
+ public registerCheckpointAttestationCallback(callback: P2PCheckpointAttestationCallback): void {
745
+ this.checkpointAttestationCallback = callback;
746
+ }
747
+
693
748
  /**
694
749
  * Subscribes to a topic.
695
750
  * @param topic - The topic to subscribe to.
@@ -754,6 +809,9 @@ export class LibP2PService extends WithTracer implements P2PService {
754
809
  if (!validator || !validator.addMessage(msgId)) {
755
810
  this.instrumentation.incMessagePrevalidationStatus(false, topicType);
756
811
  this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
812
+ if (topicType === TopicType.tx) {
813
+ this.logger.verbose(`Ignoring already-seen tx gossip message`, { msgId, source: source.toString() });
814
+ }
757
815
  return { result: false, topicType };
758
816
  }
759
817
 
@@ -815,6 +873,15 @@ export class LibP2PService extends WithTracer implements P2PService {
815
873
 
816
874
  // Process the message, optionally within a linked span for trace propagation
817
875
  const processMessage = async () => {
876
+ if (
877
+ this.config.skipIncomingProposals &&
878
+ (msg.topic === this.topicStrings[TopicType.block_proposal] ||
879
+ msg.topic === this.topicStrings[TopicType.checkpoint_proposal])
880
+ ) {
881
+ this.logger.warn(`Ignoring incoming proposal (skipIncomingProposals is set)`, { topic: msg.topic });
882
+ this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
883
+ return;
884
+ }
818
885
  if (msg.topic === this.topicStrings[TopicType.tx]) {
819
886
  await this.handleGossipedTx(p2pMessage.payload, msgId, source);
820
887
  } else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
@@ -880,30 +947,67 @@ export class LibP2PService extends WithTracer implements P2PService {
880
947
  source: PeerId,
881
948
  topicType: TopicType,
882
949
  ): Promise<ReceivedMessageValidationResult<T, M>> {
883
- let resultAndObj: ReceivedMessageValidationResult<T, M> = { result: TopicValidatorResult.Reject };
950
+ // Default to reject result with a penalty if validation function throws an error
951
+ let resultAndObj: ReceivedMessageValidationResult<T, M> = {
952
+ result: TopicValidatorResult.Reject,
953
+ severity: PeerErrorSeverity.MidToleranceError,
954
+ };
884
955
  const timer = new Timer();
885
956
  try {
886
957
  resultAndObj = await validationFunc();
887
958
  } catch (err) {
888
- this.peerManager.penalizePeer(source, PeerErrorSeverity.LowToleranceError);
889
- this.logger.error(`Error deserializing and validating gossipsub message`, err, {
890
- msgId,
891
- source: source.toString(),
892
- topicType,
893
- });
959
+ this.logger.error(`Error validating gossipsub message`, err, { msgId, source: source.toString(), topicType });
960
+ }
961
+
962
+ const validationTimeMs = timer.ms();
963
+ const mcacheWindowMs = this.config.gossipsubMcacheLength * this.config.gossipsubInterval;
964
+ if (validationTimeMs > mcacheWindowMs * 0.75) {
965
+ this.instrumentation.incSlowValidation(topicType);
966
+ this.logger.warn(
967
+ `Gossip validation for ${topicType} took ${validationTimeMs}ms, approaching mcache eviction window of ${mcacheWindowMs}ms. ` +
968
+ `Message forwarding may be skipped if validation exceeds the window.`,
969
+ { msgId, source: source.toString(), topicType, validationTimeMs, mcacheWindowMs },
970
+ );
894
971
  }
895
972
 
896
973
  if (resultAndObj.result === TopicValidatorResult.Accept) {
974
+ this.logger.debug(`Message ${topicType} accepted by validator`, { msgId, source: source.toString(), topicType });
897
975
  this.instrumentation.recordMessageValidation(topicType, timer);
976
+ } else if (resultAndObj.result === TopicValidatorResult.Reject) {
977
+ this.logger.warn(`Message ${topicType} rejected by validator with severity ${resultAndObj.severity}`, {
978
+ msgId,
979
+ source: source.toString(),
980
+ topicType,
981
+ severity: resultAndObj.severity,
982
+ });
983
+ this.peerManager.penalizePeer(source, resultAndObj.severity);
984
+ } else {
985
+ this.logger.trace(`Message ${topicType} ignored by validator`, { msgId, source: source.toString(), topicType });
898
986
  }
899
987
 
900
988
  this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result);
901
989
  return resultAndObj;
902
990
  }
903
991
 
992
+ private tryDeserialize<T>(deserializeFunc: () => T, msgId: string, source: PeerId): T | undefined {
993
+ try {
994
+ return deserializeFunc();
995
+ } catch (err) {
996
+ this.logger.warn(`Failed to deserialize gossipsub message from buffer`, {
997
+ err,
998
+ msgId,
999
+ source: source.toString(),
1000
+ });
1001
+ return undefined;
1002
+ }
1003
+ }
1004
+
904
1005
  protected async handleGossipedTx(payloadData: Buffer, msgId: string, source: PeerId) {
905
1006
  const validationFunc: () => Promise<ReceivedMessageValidationResult<Tx>> = async () => {
906
- const tx = Tx.fromBuffer(payloadData);
1007
+ const tx = this.tryDeserialize(() => Tx.fromBuffer(payloadData), msgId, source);
1008
+ if (!tx) {
1009
+ return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.LowToleranceError };
1010
+ }
907
1011
 
908
1012
  const currentBlockNumber = await this.archiver.getBlockNumber();
909
1013
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
@@ -923,13 +1027,20 @@ export class LibP2PService extends WithTracer implements P2PService {
923
1027
  severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
924
1028
  }
925
1029
 
926
- this.peerManager.penalizePeer(source, severity);
927
- return { result: TopicValidatorResult.Reject };
1030
+ this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 1 validation failed`, {
1031
+ validator: name,
1032
+ severity,
1033
+ source: source.toString(),
1034
+ });
1035
+ return { result: TopicValidatorResult.Reject, severity };
928
1036
  }
929
1037
 
930
1038
  // Pool pre-check: see if the pool would accept this tx before doing expensive proof verification
931
1039
  const canAdd = await this.mempools.txPool.canAddPendingTx(tx);
932
1040
  if (canAdd === 'ignored') {
1041
+ this.logger.verbose(`Ignoring gossiped tx ${tx.getTxHash().toString()}: pool pre-check returned ignored`, {
1042
+ source: source.toString(),
1043
+ });
933
1044
  return { result: TopicValidatorResult.Ignore, obj: tx };
934
1045
  }
935
1046
 
@@ -937,9 +1048,13 @@ export class LibP2PService extends WithTracer implements P2PService {
937
1048
  const secondStageValidators = this.createSecondStageMessageValidators();
938
1049
  const secondStageOutcome = await this.runValidations(tx, secondStageValidators);
939
1050
  if (!secondStageOutcome.allPassed) {
940
- const { severity } = secondStageOutcome.failure;
941
- this.peerManager.penalizePeer(source, severity);
942
- return { result: TopicValidatorResult.Reject };
1051
+ const { severity, name } = secondStageOutcome.failure;
1052
+ this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 2 validation failed`, {
1053
+ validator: name,
1054
+ severity,
1055
+ source: source.toString(),
1056
+ });
1057
+ return { result: TopicValidatorResult.Reject, severity };
943
1058
  }
944
1059
 
945
1060
  // Pool add: persist the tx
@@ -949,7 +1064,7 @@ export class LibP2PService extends WithTracer implements P2PService {
949
1064
  const wasAccepted = addResult.accepted.some(h => h.equals(txHash));
950
1065
  const wasIgnored = addResult.ignored.some(h => h.equals(txHash));
951
1066
 
952
- this.logger.trace(`Validate propagated tx`, {
1067
+ this.logger.verbose(`Validate propagated tx ${txHash.toString()}`, {
953
1068
  wasAccepted,
954
1069
  wasIgnored,
955
1070
  [Attributes.P2P_ID]: source.toString(),
@@ -960,7 +1075,11 @@ export class LibP2PService extends WithTracer implements P2PService {
960
1075
  } else if (wasIgnored) {
961
1076
  return { result: TopicValidatorResult.Ignore, obj: tx };
962
1077
  } else {
963
- return { result: TopicValidatorResult.Reject };
1078
+ this.logger.warn(`Gossiped tx ${txHash.toString()} unexpectedly rejected by pool`, {
1079
+ source: source.toString(),
1080
+ txHash: txHash.toString(),
1081
+ });
1082
+ return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.HighToleranceError };
964
1083
  }
965
1084
  };
966
1085
 
@@ -990,7 +1109,16 @@ export class LibP2PService extends WithTracer implements P2PService {
990
1109
  source: PeerId,
991
1110
  ): Promise<void> {
992
1111
  const { result, obj: attestation } = await this.validateReceivedMessage<CheckpointAttestation>(
993
- () => this.validateAndStoreCheckpointAttestation(source, CheckpointAttestation.fromBuffer(payloadData)),
1112
+ () => {
1113
+ const attestation = this.tryDeserialize(() => CheckpointAttestation.fromBuffer(payloadData), msgId, source);
1114
+ if (!attestation) {
1115
+ return Promise.resolve({
1116
+ result: TopicValidatorResult.Reject,
1117
+ severity: PeerErrorSeverity.LowToleranceError,
1118
+ });
1119
+ }
1120
+ return this.validateAndStoreCheckpointAttestation(source, attestation);
1121
+ },
994
1122
  msgId,
995
1123
  source,
996
1124
  TopicType.checkpoint_attestation,
@@ -1023,8 +1151,7 @@ export class LibP2PService extends WithTracer implements P2PService {
1023
1151
 
1024
1152
  if (validationResult.result === 'reject') {
1025
1153
  this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
1026
- this.peerManager.penalizePeer(peerId, validationResult.severity);
1027
- return { result: TopicValidatorResult.Reject };
1154
+ return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
1028
1155
  }
1029
1156
 
1030
1157
  if (validationResult.result === 'ignore') {
@@ -1050,16 +1177,16 @@ export class LibP2PService extends WithTracer implements P2PService {
1050
1177
  return { result: TopicValidatorResult.Ignore, obj: attestation };
1051
1178
  }
1052
1179
 
1053
- // Could not add (cap reached for signer), no need to re-broadcast
1180
+ // Could not add (cap reached for signer), penalize and do not re-broadcast
1054
1181
  if (!added) {
1055
- this.logger.warn(`Dropping checkpoint attestation due to cap`, {
1182
+ this.logger.warn(`Rejecting checkpoint attestation due to cap`, {
1056
1183
  slot: slot.toString(),
1057
1184
  archive: attestation.archive.toString(),
1058
1185
  source: peerId.toString(),
1059
1186
  attester: attestation.getSender()?.toString(),
1060
1187
  count,
1061
1188
  });
1062
- return { result: TopicValidatorResult.Ignore, obj: attestation };
1189
+ return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.HighToleranceError };
1063
1190
  }
1064
1191
 
1065
1192
  // Check if this is a duplicate attestation (signer attested to a different proposal at the same slot)
@@ -1078,6 +1205,7 @@ export class LibP2PService extends WithTracer implements P2PService {
1078
1205
  }
1079
1206
 
1080
1207
  // Attestation was added successfully - accept it so other nodes can also detect the equivocation
1208
+ this.checkpointAttestationCallback?.(attestation);
1081
1209
  return { result: TopicValidatorResult.Accept, obj: attestation };
1082
1210
  }
1083
1211
 
@@ -1114,8 +1242,7 @@ export class LibP2PService extends WithTracer implements P2PService {
1114
1242
 
1115
1243
  if (validationResult.result === 'reject') {
1116
1244
  this.logger.warn(`Penalizing peer ${peerId} for block proposal validation failure`);
1117
- this.peerManager.penalizePeer(peerId, validationResult.severity);
1118
- return { result: TopicValidatorResult.Reject };
1245
+ return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
1119
1246
  }
1120
1247
 
1121
1248
  if (validationResult.result === 'ignore') {
@@ -1139,7 +1266,6 @@ export class LibP2PService extends WithTracer implements P2PService {
1139
1266
 
1140
1267
  // Too many blocks received for this slot and index, penalize peer and do not re-broadcast
1141
1268
  if (!added) {
1142
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
1143
1269
  this.logger.warn(`Penalizing peer for block proposal exceeding per-position cap`, {
1144
1270
  ...block.toBlockInfo(),
1145
1271
  indexWithinCheckpoint: block.indexWithinCheckpoint,
@@ -1147,7 +1273,11 @@ export class LibP2PService extends WithTracer implements P2PService {
1147
1273
  proposer: block.getSender()?.toString(),
1148
1274
  source: peerId.toString(),
1149
1275
  });
1150
- return { result: TopicValidatorResult.Reject, metadata: { isEquivocated } };
1276
+ return {
1277
+ result: TopicValidatorResult.Reject,
1278
+ metadata: { isEquivocated },
1279
+ severity: PeerErrorSeverity.HighToleranceError,
1280
+ };
1151
1281
  }
1152
1282
 
1153
1283
  // If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
@@ -1192,7 +1322,7 @@ export class LibP2PService extends WithTracer implements P2PService {
1192
1322
  // Note: Validators do NOT attest to individual blocks, only to checkpoint proposals.
1193
1323
  const isValid = await this.blockReceivedCallback(block, sender);
1194
1324
  if (!isValid) {
1195
- this.logger.warn(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
1325
+ this.logger.info(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
1196
1326
  }
1197
1327
  }
1198
1328
 
@@ -1212,17 +1342,33 @@ export class LibP2PService extends WithTracer implements P2PService {
1212
1342
  TopicType.checkpoint_proposal,
1213
1343
  );
1214
1344
 
1345
+ // Process checkpoint proposal if valid and not equivocated.
1346
+ const processCheckpointFn = () =>
1347
+ result === TopicValidatorResult.Accept && checkpoint && !isEquivocated
1348
+ ? this.processValidCheckpointProposal(checkpoint.toCore(), source)
1349
+ : Promise.resolve();
1350
+
1215
1351
  // If the checkpoint contained a valid last block, we process it even if the checkpoint itself is to be rejected
1216
1352
  // TODO(palla/mbps): Is this ok? Should we be considering a block from a checkpoint that was equivocated?
1217
- if (processBlock && checkpoint?.getBlockProposal()) {
1218
- await this.processValidBlockProposal(checkpoint.getBlockProposal()!, source);
1219
- }
1220
-
1221
- if (result !== TopicValidatorResult.Accept || !checkpoint || isEquivocated) {
1353
+ const processBlockFn = () =>
1354
+ processBlock && checkpoint && checkpoint.getBlockProposal()
1355
+ ? this.processValidBlockProposal(checkpoint.getBlockProposal()!, source)
1356
+ : Promise.resolve();
1357
+
1358
+ // A node that skips checkpoint validation attests without re-executing the embedded last block, so run
1359
+ // the checkpoint callback first: this creates and broadcasts the attestation before the block is
1360
+ // processed. Otherwise the block's re-execution — which can stall until the re-execution deadline
1361
+ // waiting for a parent that may never arrive — would delay the attestation past the slot's attestation
1362
+ // window, after which peers reject it as stale.
1363
+ if (this.config.skipCheckpointProposalValidation) {
1364
+ await processCheckpointFn();
1365
+ await processBlockFn();
1222
1366
  return;
1223
1367
  }
1224
1368
 
1225
- await this.processValidCheckpointProposal(checkpoint.toCore(), source);
1369
+ // Process the block first, since it's required for the checkpoint proposal validation.
1370
+ await processBlockFn();
1371
+ await processCheckpointFn();
1226
1372
  }
1227
1373
 
1228
1374
  /**
@@ -1240,8 +1386,7 @@ export class LibP2PService extends WithTracer implements P2PService {
1240
1386
 
1241
1387
  if (validationResult.result === 'reject') {
1242
1388
  this.logger.warn(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
1243
- this.peerManager.penalizePeer(peerId, validationResult.severity);
1244
- return { result: TopicValidatorResult.Reject };
1389
+ return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
1245
1390
  }
1246
1391
 
1247
1392
  if (validationResult.result === 'ignore') {
@@ -1256,20 +1401,21 @@ export class LibP2PService extends WithTracer implements P2PService {
1256
1401
  [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
1257
1402
  [Attributes.P2P_ID]: peerId.toString(),
1258
1403
  });
1259
- const {
1260
- result,
1261
- obj,
1262
- metadata: { isEquivocated } = {},
1263
- } = await this.validateAndStoreBlockProposal(peerId, blockProposal);
1264
- if (result === TopicValidatorResult.Reject || !obj || isEquivocated) {
1404
+ const blockProposalResult = await this.validateAndStoreBlockProposal(peerId, blockProposal);
1405
+ const { obj, metadata: { isEquivocated } = {} } = blockProposalResult;
1406
+ if (blockProposalResult.result === TopicValidatorResult.Reject || !obj || isEquivocated) {
1265
1407
  this.logger.debug(`Rejecting checkpoint due to invalid last block proposal`, {
1266
1408
  [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
1267
1409
  [Attributes.P2P_ID]: peerId.toString(),
1268
1410
  isEquivocated,
1269
- result,
1411
+ result: blockProposalResult.result,
1270
1412
  });
1271
- return { result: TopicValidatorResult.Reject };
1272
- } else if (result === TopicValidatorResult.Accept && obj && !isEquivocated) {
1413
+ return {
1414
+ result: TopicValidatorResult.Reject,
1415
+ severity:
1416
+ 'severity' in blockProposalResult ? blockProposalResult.severity : PeerErrorSeverity.MidToleranceError,
1417
+ };
1418
+ } else if (blockProposalResult.result === TopicValidatorResult.Accept && obj && !isEquivocated) {
1273
1419
  processBlock = true;
1274
1420
  }
1275
1421
  }
@@ -1296,13 +1442,17 @@ export class LibP2PService extends WithTracer implements P2PService {
1296
1442
  // Too many checkpoint proposals received for this slot, penalize peer and do not re-broadcast
1297
1443
  // Note: We still return the checkpoint obj so the lastBlock can be processed if valid
1298
1444
  if (!added) {
1299
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
1300
1445
  this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
1301
1446
  ...checkpoint.toCheckpointInfo(),
1302
1447
  count,
1303
1448
  source: peerId.toString(),
1304
1449
  });
1305
- return { result: TopicValidatorResult.Reject, obj: checkpoint, metadata: { isEquivocated, processBlock } };
1450
+ return {
1451
+ result: TopicValidatorResult.Reject,
1452
+ obj: checkpoint,
1453
+ metadata: { isEquivocated, processBlock },
1454
+ severity: PeerErrorSeverity.HighToleranceError,
1455
+ };
1306
1456
  }
1307
1457
 
1308
1458
  // If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
@@ -1347,9 +1497,11 @@ export class LibP2PService extends WithTracer implements P2PService {
1347
1497
  source: sender.toString(),
1348
1498
  });
1349
1499
 
1500
+ await this.allNodesCheckpointReceivedCallback(checkpoint, sender);
1501
+
1350
1502
  // Call the checkpoint received callback with the core version (without lastBlock)
1351
1503
  // to validate and potentially generate attestations
1352
- const attestations = await this.checkpointReceivedCallback(checkpoint, sender);
1504
+ const attestations = await this.validatorCheckpointReceivedCallback(checkpoint, sender);
1353
1505
  if (attestations && attestations.length > 0) {
1354
1506
  // If the callback returned attestations, add them to the pool and propagate them
1355
1507
  await this.mempools.attestationPool.addOwnCheckpointAttestations(attestations);
@@ -1372,82 +1524,87 @@ export class LibP2PService extends WithTracer implements P2PService {
1372
1524
  }
1373
1525
 
1374
1526
  /**
1375
- * Validate the requested block transactions. Allow partial returns.
1527
+ * Validate the requested block transactions request-response consistency.
1528
+ * It does NOT validate the transactions themselves.
1376
1529
  * @param request - The block transactions request.
1377
1530
  * @param response - The block transactions response.
1378
1531
  * @param peerId - The ID of the peer that made the request.
1379
- * @returns True if the requested block transactions are valid, false otherwise.
1532
+ * @returns True if the request-response is consistent, false otherwise.
1380
1533
  */
1381
- @trackSpan('Libp2pService.validateRequestedBlockTxs', request => ({
1534
+ @trackSpan('Libp2pService.validateRequestedBlockTxsConsistency', request => ({
1382
1535
  [Attributes.BLOCK_ARCHIVE]: request.archiveRoot.toString(),
1383
1536
  }))
1384
- protected async validateRequestedBlockTxs(
1537
+ protected async validateRequestedBlockTxsConsistency(
1385
1538
  request: BlockTxsRequest,
1386
1539
  response: BlockTxsResponse,
1387
1540
  peerId: PeerId,
1388
1541
  ): Promise<boolean> {
1389
- const requestedTxValidator = this.createRequestedTxValidator();
1390
-
1391
1542
  try {
1392
- if (!response.archiveRoot.equals(request.archiveRoot)) {
1543
+ // Check for duplicates txs (or hashes) in the response.
1544
+ const returnedHashes = response.txs.map(tx => tx.getTxHash().toString());
1545
+ const uniqueReturned = new Set(returnedHashes.map(h => h.toString()));
1546
+ if (uniqueReturned.size !== returnedHashes.length) {
1393
1547
  this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1394
- throw new ValidationError(
1395
- `Received block txs for unexpected archive root: expected ${request.archiveRoot.toString()}, got ${response.archiveRoot.toString()}`,
1548
+ throw new ValidationError(`Received duplicate txs in block txs response`);
1549
+ }
1550
+
1551
+ // We get the block tx hashes from the proposal or the archiver.
1552
+ const proposal = await this.mempools.attestationPool.getBlockProposalByArchive(request.archiveRoot.toString());
1553
+ const blockTxHashes =
1554
+ proposal?.txHashes ??
1555
+ (await this.archiver.getBlock({ archive: request.archiveRoot }))?.body.txEffects.map(e => e.txHash);
1556
+
1557
+ // If we don't have the block, we can't verify membership/order of the returned txs.
1558
+ if (!blockTxHashes) {
1559
+ // This shouldn't happen, since we asked for the block (proposal).
1560
+ // Neither a local proposal nor an archived block: we cannot verify membership/order of the
1561
+ // returned txs. This is a local-state gap, not a peer fault, so we do not penalize.
1562
+ this.logger.warn(
1563
+ `Block ${request.archiveRoot.toString()} not found in attestation pool or archiver; cannot validate membership/order of returned txs`,
1396
1564
  );
1565
+ // NOTE: We mark the response as invalid, given the limitations of a true/false return value.
1566
+ return false;
1397
1567
  }
1398
1568
 
1399
- if (response.txIndices.getLength() !== request.txIndices.getLength()) {
1400
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1569
+ // Verify that the returned tx hashes are a subset of (tx hashes by index) U (explicitly requested tx hashes).
1570
+ const uniqueRequestedHashes = new Set([
1571
+ // tx hashes requested by index.
1572
+ ...request.txIndices.getTrueIndices().map(i => blockTxHashes[i].toString()),
1573
+ // explicitly requested tx hashes.
1574
+ ...request.txHashes.map(h => h.toString()),
1575
+ ]);
1576
+ if (!returnedHashes.every(h => uniqueRequestedHashes.has(h))) {
1577
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
1401
1578
  throw new ValidationError(
1402
- `Received block txs with mismatched bitvector length: expected ${request.txIndices.getLength()}, got ${response.txIndices.getLength()}`,
1579
+ 'Returned txs should be a subset of (tx hashes by index) U (explicitly requested tx hashes)',
1403
1580
  );
1404
1581
  }
1405
1582
 
1406
- // Check no duplicates and not exceeding returnable count
1407
- const requestedIndices = new Set(request.txIndices.getTrueIndices());
1408
- const availableIndices = new Set(response.txIndices.getTrueIndices());
1409
- const maxReturnable = [...requestedIndices].filter(i => availableIndices.has(i)).length;
1410
-
1411
- const returnedHashes = await Promise.all(response.txs.map(tx => tx.getTxHash().toString()));
1412
- const uniqueReturned = new Set(returnedHashes.map(h => h.toString()));
1413
- if (uniqueReturned.size !== returnedHashes.length) {
1414
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1415
- throw new ValidationError(`Received duplicate txs in block txs response`);
1583
+ // Tx indices information is optional, but if present, we need to verify a few things.
1584
+ if (!response.peerHasBlock()) {
1585
+ this.logger.debug(`Peer ${peerId.toString()} signalled missing block`);
1586
+ return true;
1416
1587
  }
1417
- if (response.txs.length > maxReturnable) {
1588
+
1589
+ // If the response has a non-empty bitvector, it needs to be consistent with the number of txs in the block.
1590
+ if (response.txIndices.getLength() !== blockTxHashes.length) {
1418
1591
  this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1419
1592
  throw new ValidationError(
1420
- `Received more txs (${response.txs.length}) than requested-and-available (${maxReturnable})`,
1593
+ `Received block txs with mismatched bitvector length: expected ${blockTxHashes.length}, got ${response.txIndices.getLength()}`,
1421
1594
  );
1422
1595
  }
1423
1596
 
1424
- // Given proposal (should have locally), ensure returned txs are valid subset and match request indices
1425
- const proposal = await this.mempools.attestationPool.getBlockProposal(request.archiveRoot.toString());
1426
- if (proposal) {
1427
- // Build intersected indices
1428
- const intersectIdx = request.txIndices.getTrueIndices().filter(i => response.txIndices.isSet(i));
1429
-
1430
- // Enforce subset membership and preserve increasing order by index.
1431
- const hashToIndexInProposal = new Map<string, number>(
1432
- proposal.txHashes.map((h, i) => [h.toString(), i] as [string, number]),
1433
- );
1434
- const allowedIndexSet = new Set(intersectIdx);
1435
- const indices = returnedHashes.map(h => hashToIndexInProposal.get(h));
1436
- const allAllowed = indices.every(idx => idx !== undefined && allowedIndexSet.has(idx));
1437
- const strictlyIncreasing = indices.every((idx, i) => (i === 0 ? idx !== undefined : idx! > indices[i - 1]!));
1438
- if (!allAllowed || !strictlyIncreasing) {
1439
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
1440
- throw new ValidationError('Returned txs do not match expected subset/order for requested indices');
1441
- }
1442
- } else {
1443
- // No local proposal, cannot check the membership/order of the returned txs
1444
- this.logger.warn(
1445
- `Block proposal not found for archive root ${request.archiveRoot.toString()}; cannot validate membership/order of returned txs`,
1446
- );
1447
- return false;
1597
+ // For every index we requested that the peer claims to have (per its bitvector), the
1598
+ // corresponding tx must be present in the response. A peer advertising availability but
1599
+ // withholding the tx is inconsistent.
1600
+ const returnedHashSet = new Set(returnedHashes);
1601
+ const expectedIndices = request.txIndices.getTrueIndices().filter(i => response.txIndices.isSet(i));
1602
+ const missingExpected = expectedIndices.some(i => !returnedHashSet.has(blockTxHashes[i].toString()));
1603
+ if (missingExpected) {
1604
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
1605
+ throw new ValidationError('Peer advertised requested txs via indices but did not return them');
1448
1606
  }
1449
1607
 
1450
- await Promise.all(response.txs.map(tx => this.validateRequestedTx(tx, peerId, requestedTxValidator)));
1451
1608
  return true;
1452
1609
  } catch (e: any) {
1453
1610
  if (e instanceof ValidationError) {
@@ -1460,125 +1617,8 @@ export class LibP2PService extends WithTracer implements P2PService {
1460
1617
  }
1461
1618
  }
1462
1619
 
1463
- /**
1464
- * Validate a collection of txs that has been requested from a peer.
1465
- *
1466
- * The core component of this validator is that each tx hash MUST match the requested tx hash,
1467
- * In order to perform this check, the tx proof must be verified.
1468
- *
1469
- * Note: This function is called from within `ReqResp.sendRequest` as part of the
1470
- * ReqRespSubProtocol.TX subprotocol validation.
1471
- *
1472
- * @param requestedTxHash - The collection of the txs that was requested.
1473
- * @param responseTx - The collection of txs that was received as a response to the request.
1474
- * @param peerId - The peer ID of the peer that sent the tx.
1475
- * @returns True if the whole collection of txs is valid, false otherwise.
1476
- */
1477
- @trackSpan('Libp2pService.validateRequestedTx', (requestedTxHash, _responseTx) => ({
1478
- [Attributes.TX_HASH]: requestedTxHash.toString(),
1479
- }))
1480
- private async validateRequestedTxs(requestedTxHash: TxHash[], responseTx: Tx[], peerId: PeerId): Promise<boolean> {
1481
- const requested = new Set(requestedTxHash.map(h => h.toString()));
1482
- const requestedTxValidator = this.createRequestedTxValidator();
1483
-
1484
- //TODO: (mralj) - this is somewhat naive implementation, if single tx is invalid we consider the whole response invalid.
1485
- // I think we should still extract the valid txs and return them, so that we can still use the response.
1486
- try {
1487
- await Promise.all(responseTx.map(tx => this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
1488
- return true;
1489
- } catch (e: any) {
1490
- if (e instanceof ValidationError) {
1491
- this.logger.warn(`Failed to validate requested txs from peer ${peerId.toString()}, reason ${e.message}`);
1492
- } else {
1493
- this.logger.error(`Error during validation of requested txs`, e);
1494
- }
1495
-
1496
- return false;
1497
- }
1498
- }
1499
-
1500
- /**
1501
- * Validates a BLOCK response.
1502
- *
1503
- * If a local copy exists, enforces hash equality. If missing, rejects (no penalty) since the hash cannot be verified.
1504
- * Penalizes on block number mismatch or hash mismatch.
1505
- *
1506
- * @param requestedBlockNumber - The requested block number.
1507
- * @param responseBlock - The block returned by the peer.
1508
- * @param peerId - The peer that returned the block.
1509
- * @returns True if the response is valid, false otherwise.
1510
- */
1511
- @trackSpan('Libp2pService.validateRequestedBlock', (requestedBlockNumber, _responseBlock) => ({
1512
- [Attributes.BLOCK_NUMBER]: requestedBlockNumber.toString(),
1513
- }))
1514
- protected async validateRequestedBlock(
1515
- requestedBlockNumber: Fr,
1516
- responseBlock: L2Block,
1517
- peerId: PeerId,
1518
- ): Promise<boolean> {
1519
- try {
1520
- const reqNum = Number(requestedBlockNumber.toString());
1521
- if (responseBlock.number !== reqNum) {
1522
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
1523
- return false;
1524
- }
1525
-
1526
- const local = await this.archiver.getBlock(BlockNumber(reqNum));
1527
- if (!local) {
1528
- // We are missing the local block; we cannot verify the hash yet. Reject without penalizing.
1529
- // TODO: Consider extending this validator to accept an expected hash or
1530
- // performing quorum-based checks when using P2P syncing prior to L1 sync.
1531
- this.logger.warn(`Local block ${reqNum} not found; rejecting BLOCK response without hash verification`);
1532
- return false;
1533
- }
1534
- const [localHash, respHash] = await Promise.all([local.hash(), responseBlock.hash()]);
1535
- if (!localHash.equals(respHash)) {
1536
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1537
- return false;
1538
- }
1539
-
1540
- return true;
1541
- } catch (e) {
1542
- this.logger.warn(`Error validating requested block`, e);
1543
- return false;
1544
- }
1545
- }
1546
-
1547
- protected async validateRequestedTx(
1548
- tx: Tx,
1549
- peerId: PeerId,
1550
- txValidator: TxValidator,
1551
- requested?: Set<`0x${string}`>,
1552
- ) {
1553
- const penalize = (severity: PeerErrorSeverity) => this.peerManager.penalizePeer(peerId, severity);
1554
- if (requested && !requested.has(tx.getTxHash().toString())) {
1555
- penalize(PeerErrorSeverity.MidToleranceError);
1556
- throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
1557
- }
1558
-
1559
- const { result } = await txValidator.validateTx(tx);
1560
- if (result === 'invalid') {
1561
- penalize(PeerErrorSeverity.LowToleranceError);
1562
- throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that is invalid.`);
1563
- }
1564
- }
1565
-
1566
- protected createRequestedTxValidator(): TxValidator {
1567
- return createTxValidatorForReqResponseReceivedTxs(this.proofVerifier, {
1568
- l1ChainId: this.config.l1ChainId,
1569
- rollupVersion: this.config.rollupVersion,
1570
- });
1571
- }
1572
-
1573
- private async getGasFees(blockNumber: BlockNumber): Promise<GasFees> {
1574
- if (blockNumber === this.feesCache?.blockNumber) {
1575
- return this.feesCache.gasFees;
1576
- }
1577
-
1578
- const header = await this.archiver.getBlockHeader(blockNumber);
1579
- const gasFees = header?.globalVariables.gasFees ?? GasFees.empty();
1580
- this.feesCache = { blockNumber, gasFees };
1581
- return gasFees;
1620
+ private getGasFees(): Promise<GasFees> {
1621
+ return this.blockMinFeesProvider.getCurrentMinFees();
1582
1622
  }
1583
1623
 
1584
1624
  /**
@@ -1592,8 +1632,10 @@ export class LibP2PService extends WithTracer implements P2PService {
1592
1632
  l1ChainId: this.config.l1ChainId,
1593
1633
  rollupVersion: this.config.rollupVersion,
1594
1634
  proofVerifier: this.proofVerifier,
1635
+ txValidationCache: this.txValidationCache,
1595
1636
  },
1596
1637
  peerScoring: this.peerManager,
1638
+ validateRequestedBlockTxsConsistency: this.validateRequestedBlockTxsConsistency.bind(this),
1597
1639
  };
1598
1640
  }
1599
1641
 
@@ -1602,6 +1644,7 @@ export class LibP2PService extends WithTracer implements P2PService {
1602
1644
  this.proofVerifier,
1603
1645
  { l1ChainId: this.config.l1ChainId, rollupVersion: this.config.rollupVersion },
1604
1646
  this.logger.getBindings(),
1647
+ this.txValidationCache,
1605
1648
  );
1606
1649
 
1607
1650
  const results = await Promise.all(
@@ -1620,12 +1663,13 @@ export class LibP2PService extends WithTracer implements P2PService {
1620
1663
  currentBlockNumber: BlockNumber,
1621
1664
  nextSlotTimestamp: UInt64,
1622
1665
  ): Promise<Record<string, TransactionValidator>> {
1623
- const gasFees = await this.getGasFees(currentBlockNumber);
1666
+ const gasFees = await this.getGasFees();
1624
1667
  const allowedInSetup = [
1625
1668
  ...(await getDefaultAllowedSetupFunctions()),
1626
1669
  ...(this.config.txPublicSetupAllowListExtend ?? []),
1627
1670
  ];
1628
1671
  const blockNumber = BlockNumber(currentBlockNumber + 1);
1672
+ const l1Constants = await this.archiver.getL1Constants();
1629
1673
 
1630
1674
  return createFirstStageTxValidationsForGossipedTransactions(
1631
1675
  nextSlotTimestamp,
@@ -1639,6 +1683,11 @@ export class LibP2PService extends WithTracer implements P2PService {
1639
1683
  !this.config.disableTransactions,
1640
1684
  allowedInSetup,
1641
1685
  this.logger.getBindings(),
1686
+ {
1687
+ rollupManaLimit: l1Constants.rollupManaLimit,
1688
+ maxBlockL2Gas: this.config.validateMaxL2BlockGas,
1689
+ maxBlockDAGas: this.config.validateMaxDABlockGas,
1690
+ },
1642
1691
  );
1643
1692
  }
1644
1693
 
@@ -1664,8 +1713,10 @@ export class LibP2PService extends WithTracer implements P2PService {
1664
1713
 
1665
1714
  // A promise that resolves when all validations have been run
1666
1715
  const allValidations = await Promise.all(validationPromises);
1667
- const failed = allValidations.find(x => !x.isValid);
1668
- if (failed) {
1716
+ const failures = allValidations.filter(x => !x.isValid);
1717
+ if (failures.length > 0) {
1718
+ // Pick the most severe failure (lowest tolerance = harshest penalty)
1719
+ const failed = maxBy(failures, f => PeerErrorSeverityByHarshness.indexOf(f.severity))!;
1669
1720
  return {
1670
1721
  allPassed: false,
1671
1722
  failure: {
@@ -1718,31 +1769,6 @@ export class LibP2PService extends WithTracer implements P2PService {
1718
1769
  return PeerErrorSeverity.HighToleranceError;
1719
1770
  }
1720
1771
 
1721
- /**
1722
- * Validate a checkpoint attestation.
1723
- *
1724
- * @param attestation - The checkpoint attestation to validate.
1725
- * @returns True if the checkpoint attestation is valid, false otherwise.
1726
- */
1727
- @trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation) => ({
1728
- [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
1729
- [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
1730
- [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
1731
- }))
1732
- public async validateCheckpointAttestation(
1733
- peerId: PeerId,
1734
- attestation: CheckpointAttestation,
1735
- ): Promise<P2PValidationResult> {
1736
- const result = await this.checkpointAttestationValidator.validate(attestation);
1737
-
1738
- if (result.result === 'reject') {
1739
- this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
1740
- this.peerManager.penalizePeer(peerId, result.severity);
1741
- }
1742
-
1743
- return result;
1744
- }
1745
-
1746
1772
  public getPeerScore(peerId: PeerId): number {
1747
1773
  return this.node.services.pubsub.score.score(peerId.toString());
1748
1774
  }