@aztec/p2p 4.0.0-nightly.20250907 → 4.0.0-nightly.20260108

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 (334) hide show
  1. package/dest/bootstrap/bootstrap.d.ts +1 -1
  2. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  3. package/dest/bootstrap/bootstrap.js +14 -4
  4. package/dest/client/factory.d.ts +3 -2
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +9 -5
  7. package/dest/client/index.d.ts +1 -1
  8. package/dest/client/interface.d.ts +8 -6
  9. package/dest/client/interface.d.ts.map +1 -1
  10. package/dest/client/p2p_client.d.ts +13 -36
  11. package/dest/client/p2p_client.d.ts.map +1 -1
  12. package/dest/client/p2p_client.js +460 -63
  13. package/dest/config.d.ts +67 -61
  14. package/dest/config.d.ts.map +1 -1
  15. package/dest/config.js +28 -15
  16. package/dest/enr/generate-enr.d.ts +2 -2
  17. package/dest/enr/generate-enr.d.ts.map +1 -1
  18. package/dest/enr/generate-enr.js +1 -1
  19. package/dest/enr/index.d.ts +1 -1
  20. package/dest/errors/attestation-pool.error.d.ts +7 -0
  21. package/dest/errors/attestation-pool.error.d.ts.map +1 -0
  22. package/dest/errors/attestation-pool.error.js +12 -0
  23. package/dest/errors/reqresp.error.d.ts +1 -1
  24. package/dest/errors/reqresp.error.d.ts.map +1 -1
  25. package/dest/index.d.ts +1 -1
  26. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +43 -6
  27. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  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 +72 -46
  31. package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
  32. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +15 -6
  33. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  34. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +73 -18
  35. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +13 -6
  36. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  37. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +69 -11
  38. package/dest/mem_pools/attestation_pool/mocks.d.ts +226 -5
  39. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  40. package/dest/mem_pools/attestation_pool/mocks.js +9 -7
  41. package/dest/mem_pools/index.d.ts +1 -1
  42. package/dest/mem_pools/instrumentation.d.ts +9 -1
  43. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  44. package/dest/mem_pools/instrumentation.js +38 -2
  45. package/dest/mem_pools/interface.d.ts +3 -4
  46. package/dest/mem_pools/interface.d.ts.map +1 -1
  47. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +39 -58
  48. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +314 -317
  50. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +18 -0
  51. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
  52. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +56 -0
  53. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +83 -0
  54. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
  55. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +5 -0
  56. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +15 -0
  57. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +1 -0
  58. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +88 -0
  59. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
  60. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  61. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
  62. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
  63. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  64. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +76 -0
  65. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
  66. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  67. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
  68. package/dest/mem_pools/tx_pool/index.d.ts +1 -2
  69. package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
  70. package/dest/mem_pools/tx_pool/index.js +0 -1
  71. package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
  72. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
  73. package/dest/mem_pools/tx_pool/priority.js +6 -1
  74. package/dest/mem_pools/tx_pool/tx_pool.d.ts +28 -9
  75. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  76. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  77. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  78. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +155 -25
  79. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -2
  80. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  81. package/dest/msg_validators/attestation_validator/attestation_validator.js +32 -5
  82. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
  83. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
  84. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +67 -0
  85. package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
  86. package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
  87. package/dest/msg_validators/attestation_validator/index.js +1 -0
  88. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +5 -2
  89. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
  90. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +44 -12
  91. package/dest/msg_validators/block_proposal_validator/index.d.ts +1 -1
  92. package/dest/msg_validators/index.d.ts +1 -1
  93. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +1 -1
  94. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -1
  95. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
  96. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  97. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +1 -1
  98. package/dest/msg_validators/tx_validator/archive_cache.d.ts +2 -2
  99. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
  100. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +2 -2
  101. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  102. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  103. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  104. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  105. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +1 -1
  106. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  107. package/dest/msg_validators/tx_validator/double_spend_validator.js +1 -1
  108. package/dest/msg_validators/tx_validator/factory.d.ts +4 -3
  109. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  110. package/dest/msg_validators/tx_validator/factory.js +11 -5
  111. package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
  112. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  113. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  114. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  115. package/dest/msg_validators/tx_validator/index.js +1 -0
  116. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +3 -6
  117. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  118. package/dest/msg_validators/tx_validator/metadata_validator.js +6 -24
  119. package/dest/msg_validators/tx_validator/phases_validator.d.ts +1 -1
  120. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  121. package/dest/msg_validators/tx_validator/phases_validator.js +3 -1
  122. package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
  123. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
  124. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +13 -0
  125. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
  126. package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
  127. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +1 -1
  128. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
  129. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +1 -1
  130. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  131. package/dest/services/data_store.d.ts +1 -1
  132. package/dest/services/data_store.d.ts.map +1 -1
  133. package/dest/services/discv5/discV5_service.d.ts +3 -3
  134. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  135. package/dest/services/discv5/discV5_service.js +2 -2
  136. package/dest/services/dummy_service.d.ts +2 -2
  137. package/dest/services/dummy_service.d.ts.map +1 -1
  138. package/dest/services/encoding.d.ts +25 -4
  139. package/dest/services/encoding.d.ts.map +1 -1
  140. package/dest/services/encoding.js +74 -6
  141. package/dest/services/gossipsub/scoring.d.ts +1 -1
  142. package/dest/services/index.d.ts +1 -1
  143. package/dest/services/libp2p/instrumentation.d.ts +3 -1
  144. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  145. package/dest/services/libp2p/instrumentation.js +9 -2
  146. package/dest/services/libp2p/libp2p_service.d.ts +33 -72
  147. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  148. package/dest/services/libp2p/libp2p_service.js +841 -175
  149. package/dest/services/peer-manager/interface.d.ts +1 -1
  150. package/dest/services/peer-manager/metrics.d.ts +8 -1
  151. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  152. package/dest/services/peer-manager/metrics.js +28 -0
  153. package/dest/services/peer-manager/peer_manager.d.ts +2 -33
  154. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  155. package/dest/services/peer-manager/peer_manager.js +29 -22
  156. package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
  157. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  158. package/dest/services/peer-manager/peer_scoring.js +40 -2
  159. package/dest/services/reqresp/config.d.ts +1 -1
  160. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +1 -1
  161. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  162. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -4
  163. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  164. package/dest/services/reqresp/index.d.ts +1 -1
  165. package/dest/services/reqresp/interface.d.ts +2 -11
  166. package/dest/services/reqresp/interface.d.ts.map +1 -1
  167. package/dest/services/reqresp/interface.js +1 -18
  168. package/dest/services/reqresp/metrics.d.ts +1 -1
  169. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  170. package/dest/services/reqresp/protocols/auth.d.ts +2 -2
  171. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
  172. package/dest/services/reqresp/protocols/auth.js +2 -2
  173. package/dest/services/reqresp/protocols/block.d.ts +1 -1
  174. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  175. package/dest/services/reqresp/protocols/block.js +3 -2
  176. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +1 -1
  177. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  178. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
  179. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +4 -6
  180. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  181. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +1 -1
  182. package/dest/services/reqresp/protocols/block_txs/index.d.ts +1 -1
  183. package/dest/services/reqresp/protocols/goodbye.d.ts +1 -1
  184. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
  185. package/dest/services/reqresp/protocols/index.d.ts +1 -1
  186. package/dest/services/reqresp/protocols/ping.d.ts +1 -1
  187. package/dest/services/reqresp/protocols/status.d.ts +6 -5
  188. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  189. package/dest/services/reqresp/protocols/status.js +4 -3
  190. package/dest/services/reqresp/protocols/tx.d.ts +2 -3
  191. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  192. package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
  193. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +2 -2
  194. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  195. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  196. package/dest/services/reqresp/reqresp.d.ts +1 -41
  197. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  198. package/dest/services/reqresp/reqresp.js +416 -34
  199. package/dest/services/reqresp/status.d.ts +2 -2
  200. package/dest/services/reqresp/status.d.ts.map +1 -1
  201. package/dest/services/service.d.ts +2 -2
  202. package/dest/services/service.d.ts.map +1 -1
  203. package/dest/services/tx_collection/config.d.ts +1 -1
  204. package/dest/services/tx_collection/config.js +1 -1
  205. package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -9
  206. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  207. package/dest/services/tx_collection/fast_tx_collection.js +6 -1
  208. package/dest/services/tx_collection/index.d.ts +1 -1
  209. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  210. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  211. package/dest/services/tx_collection/slow_tx_collection.d.ts +6 -7
  212. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  213. package/dest/services/tx_collection/slow_tx_collection.js +2 -1
  214. package/dest/services/tx_collection/tx_collection.d.ts +12 -11
  215. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  216. package/dest/services/tx_collection/tx_collection.js +3 -2
  217. package/dest/services/tx_collection/tx_collection_sink.d.ts +3 -3
  218. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  219. package/dest/services/tx_collection/tx_collection_sink.js +34 -4
  220. package/dest/services/tx_collection/tx_source.d.ts +1 -1
  221. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  222. package/dest/services/tx_collection/tx_source.js +2 -2
  223. package/dest/services/tx_provider.d.ts +6 -4
  224. package/dest/services/tx_provider.d.ts.map +1 -1
  225. package/dest/services/tx_provider.js +19 -6
  226. package/dest/services/tx_provider_instrumentation.d.ts +5 -2
  227. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  228. package/dest/services/tx_provider_instrumentation.js +14 -1
  229. package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
  230. package/dest/test-helpers/get-ports.d.ts +1 -1
  231. package/dest/test-helpers/get-ports.d.ts.map +1 -1
  232. package/dest/test-helpers/index.d.ts +1 -1
  233. package/dest/test-helpers/make-enrs.d.ts +1 -1
  234. package/dest/test-helpers/make-enrs.js +1 -1
  235. package/dest/test-helpers/make-test-p2p-clients.d.ts +2 -2
  236. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  237. package/dest/test-helpers/mock-pubsub.d.ts +4 -4
  238. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  239. package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
  240. package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
  241. package/dest/test-helpers/mock-tx-helpers.js +19 -0
  242. package/dest/test-helpers/reqresp-nodes.d.ts +3 -3
  243. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  244. package/dest/test-helpers/reqresp-nodes.js +4 -3
  245. package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
  246. package/dest/testbench/p2p_client_testbench_worker.js +17 -9
  247. package/dest/testbench/parse_log_file.d.ts +1 -1
  248. package/dest/testbench/testbench.d.ts +1 -1
  249. package/dest/testbench/testbench.js +2 -2
  250. package/dest/testbench/worker_client_manager.d.ts +1 -1
  251. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  252. package/dest/types/index.d.ts +1 -1
  253. package/dest/util.d.ts +2 -1
  254. package/dest/util.d.ts.map +1 -1
  255. package/dest/util.js +11 -2
  256. package/dest/versioning.d.ts +2 -2
  257. package/dest/versioning.d.ts.map +1 -1
  258. package/dest/versioning.js +2 -2
  259. package/package.json +21 -21
  260. package/src/bootstrap/bootstrap.ts +15 -4
  261. package/src/client/factory.ts +21 -12
  262. package/src/client/interface.ts +8 -5
  263. package/src/client/p2p_client.ts +106 -106
  264. package/src/config.ts +42 -21
  265. package/src/enr/generate-enr.ts +1 -1
  266. package/src/errors/attestation-pool.error.ts +13 -0
  267. package/src/mem_pools/attestation_pool/attestation_pool.ts +46 -5
  268. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +89 -48
  269. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +107 -24
  270. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +98 -19
  271. package/src/mem_pools/attestation_pool/mocks.ts +11 -8
  272. package/src/mem_pools/instrumentation.ts +46 -0
  273. package/src/mem_pools/interface.ts +2 -4
  274. package/src/mem_pools/tx_pool/README.md +255 -0
  275. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +368 -360
  276. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +71 -0
  277. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +93 -0
  278. package/src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts +108 -0
  279. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
  280. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +91 -0
  281. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
  282. package/src/mem_pools/tx_pool/index.ts +0 -1
  283. package/src/mem_pools/tx_pool/priority.ts +8 -1
  284. package/src/mem_pools/tx_pool/tx_pool.ts +28 -8
  285. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +131 -18
  286. package/src/msg_validators/attestation_validator/attestation_validator.ts +41 -6
  287. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +91 -0
  288. package/src/msg_validators/attestation_validator/index.ts +1 -0
  289. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +53 -12
  290. package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
  291. package/src/msg_validators/tx_validator/block_header_validator.ts +2 -2
  292. package/src/msg_validators/tx_validator/double_spend_validator.ts +1 -1
  293. package/src/msg_validators/tx_validator/factory.ts +13 -6
  294. package/src/msg_validators/tx_validator/index.ts +1 -0
  295. package/src/msg_validators/tx_validator/metadata_validator.ts +8 -42
  296. package/src/msg_validators/tx_validator/phases_validator.ts +3 -1
  297. package/src/msg_validators/tx_validator/test_utils.ts +1 -1
  298. package/src/msg_validators/tx_validator/timestamp_validator.ts +47 -0
  299. package/src/services/discv5/discV5_service.ts +2 -2
  300. package/src/services/dummy_service.ts +1 -1
  301. package/src/services/encoding.ts +81 -6
  302. package/src/services/libp2p/instrumentation.ts +10 -1
  303. package/src/services/libp2p/libp2p_service.ts +494 -169
  304. package/src/services/peer-manager/metrics.ts +32 -0
  305. package/src/services/peer-manager/peer_manager.ts +25 -16
  306. package/src/services/peer-manager/peer_scoring.ts +46 -3
  307. package/src/services/reqresp/interface.ts +1 -22
  308. package/src/services/reqresp/protocols/auth.ts +2 -2
  309. package/src/services/reqresp/protocols/block.ts +3 -2
  310. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +1 -1
  311. package/src/services/reqresp/protocols/status.ts +9 -8
  312. package/src/services/reqresp/protocols/tx.ts +1 -2
  313. package/src/services/reqresp/reqresp.ts +15 -11
  314. package/src/services/service.ts +1 -1
  315. package/src/services/tx_collection/config.ts +1 -1
  316. package/src/services/tx_collection/fast_tx_collection.ts +8 -5
  317. package/src/services/tx_collection/slow_tx_collection.ts +7 -6
  318. package/src/services/tx_collection/tx_collection.ts +12 -10
  319. package/src/services/tx_collection/tx_collection_sink.ts +34 -3
  320. package/src/services/tx_collection/tx_source.ts +2 -2
  321. package/src/services/tx_provider.ts +26 -9
  322. package/src/services/tx_provider_instrumentation.ts +19 -2
  323. package/src/test-helpers/make-enrs.ts +1 -1
  324. package/src/test-helpers/mock-pubsub.ts +1 -1
  325. package/src/test-helpers/mock-tx-helpers.ts +24 -0
  326. package/src/test-helpers/reqresp-nodes.ts +4 -3
  327. package/src/testbench/p2p_client_testbench_worker.ts +14 -6
  328. package/src/testbench/testbench.ts +2 -2
  329. package/src/util.ts +12 -2
  330. package/src/versioning.ts +3 -3
  331. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -68
  332. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
  333. package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -160
  334. package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -199
@@ -1,22 +1,390 @@
1
- function _ts_decorate(decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1
+ function applyDecs2203RFactory() {
2
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
3
+ return function addInitializer(initializer) {
4
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
5
+ assertCallable(initializer, "An initializer");
6
+ initializers.push(initializer);
7
+ };
8
+ }
9
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
10
+ var kindStr;
11
+ switch(kind){
12
+ case 1:
13
+ kindStr = "accessor";
14
+ break;
15
+ case 2:
16
+ kindStr = "method";
17
+ break;
18
+ case 3:
19
+ kindStr = "getter";
20
+ break;
21
+ case 4:
22
+ kindStr = "setter";
23
+ break;
24
+ default:
25
+ kindStr = "field";
26
+ }
27
+ var ctx = {
28
+ kind: kindStr,
29
+ name: isPrivate ? "#" + name : name,
30
+ static: isStatic,
31
+ private: isPrivate,
32
+ metadata: metadata
33
+ };
34
+ var decoratorFinishedRef = {
35
+ v: false
36
+ };
37
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
38
+ var get, set;
39
+ if (kind === 0) {
40
+ if (isPrivate) {
41
+ get = desc.get;
42
+ set = desc.set;
43
+ } else {
44
+ get = function() {
45
+ return this[name];
46
+ };
47
+ set = function(v) {
48
+ this[name] = v;
49
+ };
50
+ }
51
+ } else if (kind === 2) {
52
+ get = function() {
53
+ return desc.value;
54
+ };
55
+ } else {
56
+ if (kind === 1 || kind === 3) {
57
+ get = function() {
58
+ return desc.get.call(this);
59
+ };
60
+ }
61
+ if (kind === 1 || kind === 4) {
62
+ set = function(v) {
63
+ desc.set.call(this, v);
64
+ };
65
+ }
66
+ }
67
+ ctx.access = get && set ? {
68
+ get: get,
69
+ set: set
70
+ } : get ? {
71
+ get: get
72
+ } : {
73
+ set: set
74
+ };
75
+ try {
76
+ return dec(value, ctx);
77
+ } finally{
78
+ decoratorFinishedRef.v = true;
79
+ }
80
+ }
81
+ function assertNotFinished(decoratorFinishedRef, fnName) {
82
+ if (decoratorFinishedRef.v) {
83
+ throw new Error("attempted to call " + fnName + " after decoration was finished");
84
+ }
85
+ }
86
+ function assertCallable(fn, hint) {
87
+ if (typeof fn !== "function") {
88
+ throw new TypeError(hint + " must be a function");
89
+ }
90
+ }
91
+ function assertValidReturnValue(kind, value) {
92
+ var type = typeof value;
93
+ if (kind === 1) {
94
+ if (type !== "object" || value === null) {
95
+ throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
96
+ }
97
+ if (value.get !== undefined) {
98
+ assertCallable(value.get, "accessor.get");
99
+ }
100
+ if (value.set !== undefined) {
101
+ assertCallable(value.set, "accessor.set");
102
+ }
103
+ if (value.init !== undefined) {
104
+ assertCallable(value.init, "accessor.init");
105
+ }
106
+ } else if (type !== "function") {
107
+ var hint;
108
+ if (kind === 0) {
109
+ hint = "field";
110
+ } else if (kind === 10) {
111
+ hint = "class";
112
+ } else {
113
+ hint = "method";
114
+ }
115
+ throw new TypeError(hint + " decorators must return a function or void 0");
116
+ }
117
+ }
118
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
119
+ var decs = decInfo[0];
120
+ var desc, init, value;
121
+ if (isPrivate) {
122
+ if (kind === 0 || kind === 1) {
123
+ desc = {
124
+ get: decInfo[3],
125
+ set: decInfo[4]
126
+ };
127
+ } else if (kind === 3) {
128
+ desc = {
129
+ get: decInfo[3]
130
+ };
131
+ } else if (kind === 4) {
132
+ desc = {
133
+ set: decInfo[3]
134
+ };
135
+ } else {
136
+ desc = {
137
+ value: decInfo[3]
138
+ };
139
+ }
140
+ } else if (kind !== 0) {
141
+ desc = Object.getOwnPropertyDescriptor(base, name);
142
+ }
143
+ if (kind === 1) {
144
+ value = {
145
+ get: desc.get,
146
+ set: desc.set
147
+ };
148
+ } else if (kind === 2) {
149
+ value = desc.value;
150
+ } else if (kind === 3) {
151
+ value = desc.get;
152
+ } else if (kind === 4) {
153
+ value = desc.set;
154
+ }
155
+ var newValue, get, set;
156
+ if (typeof decs === "function") {
157
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
158
+ if (newValue !== void 0) {
159
+ assertValidReturnValue(kind, newValue);
160
+ if (kind === 0) {
161
+ init = newValue;
162
+ } else if (kind === 1) {
163
+ init = newValue.init;
164
+ get = newValue.get || value.get;
165
+ set = newValue.set || value.set;
166
+ value = {
167
+ get: get,
168
+ set: set
169
+ };
170
+ } else {
171
+ value = newValue;
172
+ }
173
+ }
174
+ } else {
175
+ for(var i = decs.length - 1; i >= 0; i--){
176
+ var dec = decs[i];
177
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
178
+ if (newValue !== void 0) {
179
+ assertValidReturnValue(kind, newValue);
180
+ var newInit;
181
+ if (kind === 0) {
182
+ newInit = newValue;
183
+ } else if (kind === 1) {
184
+ newInit = newValue.init;
185
+ get = newValue.get || value.get;
186
+ set = newValue.set || value.set;
187
+ value = {
188
+ get: get,
189
+ set: set
190
+ };
191
+ } else {
192
+ value = newValue;
193
+ }
194
+ if (newInit !== void 0) {
195
+ if (init === void 0) {
196
+ init = newInit;
197
+ } else if (typeof init === "function") {
198
+ init = [
199
+ init,
200
+ newInit
201
+ ];
202
+ } else {
203
+ init.push(newInit);
204
+ }
205
+ }
206
+ }
207
+ }
208
+ }
209
+ if (kind === 0 || kind === 1) {
210
+ if (init === void 0) {
211
+ init = function(instance, init) {
212
+ return init;
213
+ };
214
+ } else if (typeof init !== "function") {
215
+ var ownInitializers = init;
216
+ init = function(instance, init) {
217
+ var value = init;
218
+ for(var i = 0; i < ownInitializers.length; i++){
219
+ value = ownInitializers[i].call(instance, value);
220
+ }
221
+ return value;
222
+ };
223
+ } else {
224
+ var originalInitializer = init;
225
+ init = function(instance, init) {
226
+ return originalInitializer.call(instance, init);
227
+ };
228
+ }
229
+ ret.push(init);
230
+ }
231
+ if (kind !== 0) {
232
+ if (kind === 1) {
233
+ desc.get = value.get;
234
+ desc.set = value.set;
235
+ } else if (kind === 2) {
236
+ desc.value = value;
237
+ } else if (kind === 3) {
238
+ desc.get = value;
239
+ } else if (kind === 4) {
240
+ desc.set = value;
241
+ }
242
+ if (isPrivate) {
243
+ if (kind === 1) {
244
+ ret.push(function(instance, args) {
245
+ return value.get.call(instance, args);
246
+ });
247
+ ret.push(function(instance, args) {
248
+ return value.set.call(instance, args);
249
+ });
250
+ } else if (kind === 2) {
251
+ ret.push(value);
252
+ } else {
253
+ ret.push(function(instance, args) {
254
+ return value.call(instance, args);
255
+ });
256
+ }
257
+ } else {
258
+ Object.defineProperty(base, name, desc);
259
+ }
260
+ }
261
+ }
262
+ function applyMemberDecs(Class, decInfos, metadata) {
263
+ var ret = [];
264
+ var protoInitializers;
265
+ var staticInitializers;
266
+ var existingProtoNonFields = new Map();
267
+ var existingStaticNonFields = new Map();
268
+ for(var i = 0; i < decInfos.length; i++){
269
+ var decInfo = decInfos[i];
270
+ if (!Array.isArray(decInfo)) continue;
271
+ var kind = decInfo[1];
272
+ var name = decInfo[2];
273
+ var isPrivate = decInfo.length > 3;
274
+ var isStatic = kind >= 5;
275
+ var base;
276
+ var initializers;
277
+ if (isStatic) {
278
+ base = Class;
279
+ kind = kind - 5;
280
+ staticInitializers = staticInitializers || [];
281
+ initializers = staticInitializers;
282
+ } else {
283
+ base = Class.prototype;
284
+ protoInitializers = protoInitializers || [];
285
+ initializers = protoInitializers;
286
+ }
287
+ if (kind !== 0 && !isPrivate) {
288
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
289
+ var existingKind = existingNonFields.get(name) || 0;
290
+ if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
291
+ throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
292
+ } else if (!existingKind && kind > 2) {
293
+ existingNonFields.set(name, kind);
294
+ } else {
295
+ existingNonFields.set(name, true);
296
+ }
297
+ }
298
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
299
+ }
300
+ pushInitializers(ret, protoInitializers);
301
+ pushInitializers(ret, staticInitializers);
302
+ return ret;
303
+ }
304
+ function pushInitializers(ret, initializers) {
305
+ if (initializers) {
306
+ ret.push(function(instance) {
307
+ for(var i = 0; i < initializers.length; i++){
308
+ initializers[i].call(instance);
309
+ }
310
+ return instance;
311
+ });
312
+ }
313
+ }
314
+ function applyClassDecs(targetClass, classDecs, metadata) {
315
+ if (classDecs.length > 0) {
316
+ var initializers = [];
317
+ var newClass = targetClass;
318
+ var name = targetClass.name;
319
+ for(var i = classDecs.length - 1; i >= 0; i--){
320
+ var decoratorFinishedRef = {
321
+ v: false
322
+ };
323
+ try {
324
+ var nextNewClass = classDecs[i](newClass, {
325
+ kind: "class",
326
+ name: name,
327
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
328
+ metadata
329
+ });
330
+ } finally{
331
+ decoratorFinishedRef.v = true;
332
+ }
333
+ if (nextNewClass !== undefined) {
334
+ assertValidReturnValue(10, nextNewClass);
335
+ newClass = nextNewClass;
336
+ }
337
+ }
338
+ return [
339
+ defineMetadata(newClass, metadata),
340
+ function() {
341
+ for(var i = 0; i < initializers.length; i++){
342
+ initializers[i].call(newClass);
343
+ }
344
+ }
345
+ ];
346
+ }
347
+ }
348
+ function defineMetadata(Class, metadata) {
349
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
350
+ configurable: true,
351
+ enumerable: true,
352
+ value: metadata
353
+ });
354
+ }
355
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
356
+ if (parentClass !== void 0) {
357
+ var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
358
+ }
359
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
360
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
361
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
362
+ return {
363
+ e: e,
364
+ get c () {
365
+ return applyClassDecs(targetClass, classDecs, metadata);
366
+ }
367
+ };
368
+ };
369
+ }
370
+ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
371
+ return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
6
372
  }
7
- import { randomInt } from '@aztec/foundation/crypto';
373
+ var _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _initProto;
374
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
375
+ import { randomInt } from '@aztec/foundation/crypto/random';
376
+ import { Fr } from '@aztec/foundation/curves/bn254';
8
377
  import { createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
9
- import { SerialQueue } from '@aztec/foundation/queue';
10
378
  import { RunningPromise } from '@aztec/foundation/running-promise';
11
379
  import { Timer } from '@aztec/foundation/timer';
12
- import { protocolContractTreeRoot } from '@aztec/protocol-contracts';
380
+ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
381
+ import { protocolContractsHash } from '@aztec/protocol-contracts';
13
382
  import { GasFees } from '@aztec/stdlib/gas';
14
383
  import { BlockAttestation, BlockProposal, P2PClientType, P2PMessage, PeerErrorSeverity, TopicType, createTopicString, getTopicsForClientAndConfig, metricsTopicStrToLabels } from '@aztec/stdlib/p2p';
15
384
  import { MerkleTreeId } from '@aztec/stdlib/trees';
16
385
  import { Tx } from '@aztec/stdlib/tx';
17
386
  import { compressComponentVersions } from '@aztec/stdlib/versioning';
18
- import { Attributes, OtelMetricsAdapter, WithTracer, trackSpan } from '@aztec/telemetry-client';
19
- import { ENR } from '@chainsafe/enr';
387
+ import { Attributes, OtelMetricsAdapter, SpanStatusCode, WithTracer, trackSpan } from '@aztec/telemetry-client';
20
388
  import { gossipsub } from '@chainsafe/libp2p-gossipsub';
21
389
  import { createPeerScoreParams, createTopicScoreParams } from '@chainsafe/libp2p-gossipsub/score';
22
390
  import { SignaturePolicy } from '@chainsafe/libp2p-gossipsub/types';
@@ -25,15 +393,16 @@ import { yamux } from '@chainsafe/libp2p-yamux';
25
393
  import { bootstrap } from '@libp2p/bootstrap';
26
394
  import { identify } from '@libp2p/identify';
27
395
  import { TopicValidatorResult } from '@libp2p/interface';
28
- import '@libp2p/kad-dht';
29
396
  import { mplex } from '@libp2p/mplex';
30
397
  import { tcp } from '@libp2p/tcp';
398
+ import { ENR } from '@nethermindeth/enr';
31
399
  import { createLibp2p } from 'libp2p';
32
- import { AttestationValidator, BlockProposalValidator } from '../../msg_validators/index.js';
400
+ import { ProposalSlotCapExceededError } from '../../errors/attestation-pool.error.js';
401
+ import { AttestationValidator, BlockProposalValidator, FishermanAttestationValidator } from '../../msg_validators/index.js';
33
402
  import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
34
403
  import { getDefaultAllowedSetupFunctions } from '../../msg_validators/tx_validator/allowed_public_setup.js';
35
404
  import { createTxMessageValidators } from '../../msg_validators/tx_validator/factory.js';
36
- import { DoubleSpendTxValidator, TxProofValidator } from '../../msg_validators/tx_validator/index.js';
405
+ import { AggregateTxValidator, DataTxValidator, DoubleSpendTxValidator, MetadataTxValidator, TxProofValidator } from '../../msg_validators/tx_validator/index.js';
37
406
  import { GossipSubEvent } from '../../types/index.js';
38
407
  import { convertToMultiaddr } from '../../util.js';
39
408
  import { getVersions } from '../../versioning.js';
@@ -49,6 +418,29 @@ import { reqGoodbyeHandler } from '../reqresp/protocols/goodbye.js';
49
418
  import { pingHandler, reqRespBlockHandler, reqRespStatusHandler, reqRespTxHandler } from '../reqresp/protocols/index.js';
50
419
  import { ReqResp } from '../reqresp/reqresp.js';
51
420
  import { P2PInstrumentation } from './instrumentation.js';
421
+ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
422
+ [Attributes.SLOT_NUMBER]: block.slotNumber,
423
+ [Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
424
+ [Attributes.P2P_ID]: await block.p2pMessageLoggingIdentifier().then((i)=>i.toString())
425
+ })), _dec1 = trackSpan('Libp2pService.broadcastAttestation', async (attestation)=>({
426
+ [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
427
+ [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
428
+ [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then((i)=>i.toString())
429
+ })), _dec2 = trackSpan('Libp2pService.validateRequestedBlockTxs', (request)=>({
430
+ [Attributes.BLOCK_HASH]: request.blockHash.toString()
431
+ })), _dec3 = trackSpan('Libp2pService.validateRequestedTx', (requestedTxHash, _responseTx)=>({
432
+ [Attributes.TX_HASH]: requestedTxHash.toString()
433
+ })), _dec4 = trackSpan('Libp2pService.validateRequestedBlock', (requestedBlockNumber, _responseBlock)=>({
434
+ [Attributes.BLOCK_NUMBER]: requestedBlockNumber.toString()
435
+ })), _dec5 = trackSpan('Libp2pService.validatePropagatedTx', (tx)=>({
436
+ [Attributes.TX_HASH]: tx.getTxHash().toString()
437
+ })), _dec6 = trackSpan('Libp2pService.validateAttestation', async (_, attestation)=>({
438
+ [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
439
+ [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
440
+ [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then((i)=>i.toString())
441
+ })), _dec7 = trackSpan('Libp2pService.validateBlockProposal', (_peerId, block)=>({
442
+ [Attributes.SLOT_NUMBER]: block.payload.header.slotNumber.toString()
443
+ }));
52
444
  /**
53
445
  * Lib P2P implementation of the P2PService interface.
54
446
  */ export class LibP2PService extends WithTracer {
@@ -63,8 +455,50 @@ import { P2PInstrumentation } from './instrumentation.js';
63
455
  epochCache;
64
456
  proofVerifier;
65
457
  worldStateSynchronizer;
66
- logger;
67
- jobQueue;
458
+ static{
459
+ ({ e: [_initProto] } = _apply_decs_2203_r(this, [
460
+ [
461
+ _dec,
462
+ 2,
463
+ "processValidBlockProposal"
464
+ ],
465
+ [
466
+ _dec1,
467
+ 2,
468
+ "broadcastAttestation"
469
+ ],
470
+ [
471
+ _dec2,
472
+ 2,
473
+ "validateRequestedBlockTxs"
474
+ ],
475
+ [
476
+ _dec3,
477
+ 2,
478
+ "validateRequestedTxs"
479
+ ],
480
+ [
481
+ _dec4,
482
+ 2,
483
+ "validateRequestedBlock"
484
+ ],
485
+ [
486
+ _dec5,
487
+ 2,
488
+ "validatePropagatedTx"
489
+ ],
490
+ [
491
+ _dec6,
492
+ 2,
493
+ "validateAttestation"
494
+ ],
495
+ [
496
+ _dec7,
497
+ 2,
498
+ "validateBlockProposal"
499
+ ]
500
+ ], []));
501
+ }
68
502
  discoveryRunningPromise;
69
503
  msgIdSeenValidators;
70
504
  // Message validators
@@ -80,8 +514,13 @@ import { P2PInstrumentation } from './instrumentation.js';
80
514
  */ blockReceivedCallback;
81
515
  gossipSubEventHandler;
82
516
  instrumentation;
517
+ telemetry;
518
+ logger;
83
519
  constructor(clientType, config, node, peerDiscoveryService, reqresp, peerManager, mempools, archiver, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger = createLogger('p2p:libp2p_service')){
84
- 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.logger = logger, this.jobQueue = new SerialQueue(), this.msgIdSeenValidators = {}, this.protocolVersion = '', this.topicStrings = {};
520
+ 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 = {};
521
+ this.telemetry = telemetry;
522
+ // Create child logger with fisherman prefix if in fisherman mode
523
+ this.logger = config.fishermanMode ? logger.createChild('[FISHERMAN]') : logger;
85
524
  this.instrumentation = new P2PInstrumentation(telemetry, 'LibP2PService');
86
525
  this.msgIdSeenValidators[TopicType.tx] = new MessageSeenValidator(config.seenMessageCacheSize);
87
526
  this.msgIdSeenValidators[TopicType.block_proposal] = new MessageSeenValidator(config.seenMessageCacheSize);
@@ -92,12 +531,15 @@ import { P2PInstrumentation } from './instrumentation.js';
92
531
  this.topicStrings[TopicType.tx] = createTopicString(TopicType.tx, this.protocolVersion);
93
532
  this.topicStrings[TopicType.block_proposal] = createTopicString(TopicType.block_proposal, this.protocolVersion);
94
533
  this.topicStrings[TopicType.block_attestation] = createTopicString(TopicType.block_attestation, this.protocolVersion);
95
- this.attestationValidator = new AttestationValidator(epochCache);
96
- this.blockProposalValidator = new BlockProposalValidator(epochCache);
534
+ // Use FishermanAttestationValidator in fisherman mode to validate attestation payloads against proposals
535
+ this.attestationValidator = config.fishermanMode ? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry) : new AttestationValidator(epochCache);
536
+ this.blockProposalValidator = new BlockProposalValidator(epochCache, {
537
+ txsPermitted: !config.disableTransactions
538
+ });
97
539
  this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
98
540
  this.blockReceivedCallback = async (block)=>{
99
- this.logger.debug(`Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber.toNumber()} from peer.`, {
100
- p2pMessageIdentifier: await block.p2pMessageIdentifier()
541
+ this.logger.debug(`Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber} from peer.`, {
542
+ p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier()
101
543
  });
102
544
  return undefined;
103
545
  };
@@ -165,7 +607,7 @@ import { P2PInstrumentation } from './instrumentation.js';
165
607
  // The connection attempts to the node on TCP layer are not necessarily valid Aztec peers so we want to have a bit of leeway here
166
608
  // If we hit the limit, the connection will be temporarily accepted and immediately dropped.
167
609
  // Docs: https://nodejs.org/api/net.html#servermaxconnections
168
- maxConnections: Math.ceil(maxPeerCount * 1.5),
610
+ maxConnections: maxPeerCount * 2,
169
611
  // socket option: the maximum length of the queue of pending connections
170
612
  // https://nodejs.org/dist/latest-v22.x/docs/api/net.html#serverlisten
171
613
  // it's not safe if we increase this number
@@ -176,7 +618,7 @@ import { P2PInstrumentation } from './instrumentation.js';
176
618
  // In case closeAbove is reached, the server stops listening altogether
177
619
  // It's important that there is enough difference between closeAbove and listenAbove,
178
620
  // otherwise the server.listener will flap between being closed and open potentially degrading perf even more
179
- closeAbove: maxPeerCount * 2,
621
+ closeAbove: maxPeerCount * 3,
180
622
  listenBelow: Math.floor(maxPeerCount * 0.9)
181
623
  }
182
624
  })
@@ -192,7 +634,9 @@ import { P2PInstrumentation } from './instrumentation.js';
192
634
  ],
193
635
  connectionManager: {
194
636
  minConnections: 0,
195
- maxConnections: maxPeerCount,
637
+ // We set maxConnections above maxPeerCount because if we hit limit of maxPeerCount
638
+ // libp2p will start aggressively rejecting all new connections, preventing network discovery and crawling.
639
+ maxConnections: maxPeerCount * 2,
196
640
  maxParallelDials: 100,
197
641
  dialTimeout: 30_000,
198
642
  maxPeerAddrsToDial: 5,
@@ -273,7 +717,7 @@ import { P2PInstrumentation } from './instrumentation.js';
273
717
  },
274
718
  logger: createLibp2pComponentLogger(logger.module)
275
719
  });
276
- const peerScoring = new PeerScoring(config);
720
+ const peerScoring = new PeerScoring(config, telemetry);
277
721
  const reqresp = new ReqResp(config, node, peerScoring, createLogger(`${logger.module}:reqresp`));
278
722
  const peerManager = new PeerManager(node, peerDiscoveryService, config, telemetry, createLogger(`${logger.module}:peer_manager`), peerScoring, reqresp, worldStateSynchronizer, protocolVersion, epochCache);
279
723
  // Update gossipsub score params
@@ -295,8 +739,6 @@ import { P2PInstrumentation } from './instrumentation.js';
295
739
  throw new Error('Announce address not provided.');
296
740
  }
297
741
  const announceTcpMultiaddr = convertToMultiaddr(p2pIp, p2pPort, 'tcp');
298
- // Start job queue, peer discovery service and libp2p node
299
- this.jobQueue.start();
300
742
  await this.peerManager.initializePeers();
301
743
  if (!this.config.p2pDiscoveryDisabled) {
302
744
  await this.peerDiscoveryService.start();
@@ -311,18 +753,13 @@ import { P2PInstrumentation } from './instrumentation.js';
311
753
  const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
312
754
  const blockHandler = reqRespBlockHandler(this.archiver);
313
755
  const statusHandler = reqRespStatusHandler(this.protocolVersion, this.worldStateSynchronizer, this.logger);
314
- // In case P2P client doesnt'have attestation pool,
315
- // const blockTxsHandler = this.mempools.attestationPool
316
- // ? reqRespBlockTxsHandler(this.mempools.attestationPool, this.mempools.txPool)
317
- // : def;
318
756
  const requestResponseHandlers = {
319
757
  [ReqRespSubProtocol.PING]: pingHandler,
320
758
  [ReqRespSubProtocol.STATUS]: statusHandler.bind(this),
321
759
  [ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this),
322
760
  [ReqRespSubProtocol.BLOCK]: blockHandler.bind(this)
323
761
  };
324
- // Only handle block transactions request if attestation pool is available to the client
325
- if (this.mempools.attestationPool) {
762
+ if (!this.config.disableTransactions) {
326
763
  const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.mempools.txPool);
327
764
  requestResponseHandlers[ReqRespSubProtocol.BLOCK_TXS] = blockTxsHandler.bind(this);
328
765
  }
@@ -331,14 +768,17 @@ import { P2PInstrumentation } from './instrumentation.js';
331
768
  }
332
769
  // add GossipSub listener
333
770
  this.node.services.pubsub.addEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
334
- // Start running promise for peer discovery
335
- this.discoveryRunningPromise = new RunningPromise(()=>this.peerManager.heartbeat(), this.logger, this.config.peerCheckIntervalMS);
771
+ // Start running promise for peer discovery and metrics collection
772
+ this.discoveryRunningPromise = new RunningPromise(async ()=>{
773
+ await this.peerManager.heartbeat();
774
+ }, this.logger, this.config.peerCheckIntervalMS);
336
775
  this.discoveryRunningPromise.start();
337
776
  // Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
338
777
  const reqrespSubProtocolValidators = {
339
778
  ...DEFAULT_SUB_PROTOCOL_VALIDATORS,
340
- // TODO(#11336): A request validator for blocks
341
- [ReqRespSubProtocol.TX]: this.validateRequestedTx.bind(this)
779
+ [ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
780
+ [ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
781
+ [ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this)
342
782
  };
343
783
  await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
344
784
  this.logger.info(`Started P2P service`, {
@@ -357,8 +797,6 @@ import { P2PInstrumentation } from './instrumentation.js';
357
797
  // Stop peer manager
358
798
  this.logger.debug('Stopping peer manager...');
359
799
  await this.peerManager.stop();
360
- this.logger.debug('Stopping job queue...');
361
- await this.jobQueue.end();
362
800
  this.logger.debug('Stopping running promise...');
363
801
  await this.discoveryRunningPromise?.stop();
364
802
  this.logger.debug('Stopping peer discovery service...');
@@ -424,15 +862,17 @@ import { P2PInstrumentation } from './instrumentation.js';
424
862
  if (!this.node.services.pubsub) {
425
863
  throw new Error('Pubsub service not available.');
426
864
  }
427
- const p2pMessage = await P2PMessage.fromGossipable(message);
428
- this.logger.debug(`Publishing message`, {
429
- topic,
430
- messageId: p2pMessage.id
431
- });
865
+ const isBlockProposal = topic === this.topicStrings[TopicType.block_proposal];
866
+ const traceContext = this.config.debugP2PInstrumentMessages && isBlockProposal ? this.telemetry.getTraceContext() : undefined;
867
+ const p2pMessage = P2PMessage.fromGossipable(message, this.config.debugP2PInstrumentMessages, traceContext);
432
868
  const result = await this.node.services.pubsub.publish(topic, p2pMessage.toMessageData());
433
869
  return result.recipients.length;
434
870
  }
435
- preValidateReceivedMessage(msg, msgId, source) {
871
+ /**
872
+ * Checks if this message has already been seen, based on its msgId computed from hashing the message data.
873
+ * Note that we do not rely on the seenCache from gossipsub since we want to keep a longer history of seen
874
+ * messages to avoid tx echoes across the network.
875
+ */ preValidateReceivedMessage(msg, msgId, source) {
436
876
  let topicType;
437
877
  switch(msg.topic){
438
878
  case this.topicStrings[TopicType.tx]:
@@ -464,66 +904,145 @@ import { P2PInstrumentation } from './instrumentation.js';
464
904
  };
465
905
  }
466
906
  /**
907
+ * Safely deserializes a P2PMessage from raw message data.
908
+ * @param msgId - The message ID.
909
+ * @param source - The peer ID of the message source.
910
+ * @param data - The raw message data.
911
+ * @returns The deserialized P2PMessage or undefined if deserialization fails.
912
+ */ safelyDeserializeP2PMessage(msgId, source, data) {
913
+ try {
914
+ return P2PMessage.fromMessageData(Buffer.from(data), this.config.debugP2PInstrumentMessages);
915
+ } catch (err) {
916
+ this.logger.error(`Error deserializing P2PMessage`, err, {
917
+ msgId,
918
+ source: source.toString()
919
+ });
920
+ this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Reject);
921
+ this.peerManager.penalizePeer(source, PeerErrorSeverity.LowToleranceError);
922
+ return undefined;
923
+ }
924
+ }
925
+ /**
467
926
  * Handles a new gossip message that was received by the client.
468
927
  * @param topic - The message's topic.
469
928
  * @param data - The message data
470
929
  */ async handleNewGossipMessage(msg, msgId, source) {
471
- const p2pMessage = P2PMessage.fromMessageData(Buffer.from(msg.data));
472
- const currentTime = new Date();
473
- const messageLatency = currentTime.getTime() - p2pMessage.publishTime.getTime();
474
- this.logger.debug(`Received message`, {
475
- topic: msg.topic,
476
- messageId: p2pMessage.id,
477
- messageLatency
478
- });
930
+ const msgReceivedTime = Date.now();
931
+ let topicType;
932
+ const p2pMessage = this.safelyDeserializeP2PMessage(msgId, source, msg.data);
933
+ if (!p2pMessage) {
934
+ return;
935
+ }
479
936
  const preValidationResult = this.preValidateReceivedMessage(msg, msgId, source);
480
937
  if (!preValidationResult.result) {
481
938
  return;
482
- } else if (preValidationResult.topicType !== undefined) {
483
- // guard against clock skew & DST
484
- if (messageLatency > 0) {
485
- this.instrumentation.recordMessageLatency(preValidationResult.topicType, messageLatency);
486
- }
487
939
  }
940
+ // Determine topic type for attributes
488
941
  if (msg.topic === this.topicStrings[TopicType.tx]) {
489
- await this.handleGossipedTx(p2pMessage.payload, msgId, source);
942
+ topicType = TopicType.tx;
943
+ } else if (msg.topic === this.topicStrings[TopicType.block_attestation]) {
944
+ topicType = TopicType.block_attestation;
945
+ } else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
946
+ topicType = TopicType.block_proposal;
490
947
  }
491
- if (msg.topic === this.topicStrings[TopicType.block_attestation] && this.clientType === P2PClientType.Full) {
492
- await this.processAttestationFromPeer(p2pMessage.payload, msgId, source);
948
+ // Process the message, optionally within a linked span for trace propagation
949
+ const processMessage = async ()=>{
950
+ if (msg.topic === this.topicStrings[TopicType.tx]) {
951
+ await this.handleGossipedTx(p2pMessage.payload, msgId, source);
952
+ }
953
+ if (msg.topic === this.topicStrings[TopicType.block_attestation]) {
954
+ if (this.clientType === P2PClientType.Full) {
955
+ await this.processAttestationFromPeer(p2pMessage.payload, msgId, source);
956
+ }
957
+ }
958
+ if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
959
+ await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
960
+ }
961
+ };
962
+ const latency = p2pMessage.timestamp !== undefined ? msgReceivedTime - p2pMessage.timestamp.getTime() : undefined;
963
+ const propagatedContext = p2pMessage.traceContext ? this.telemetry.extractPropagatedContext(p2pMessage.traceContext) : undefined;
964
+ if (propagatedContext) {
965
+ await this.tracer.startActiveSpan('LibP2PService.processMessage', {
966
+ attributes: {
967
+ [Attributes.TOPIC_NAME]: topicType,
968
+ [Attributes.PEER_ID]: source.toString()
969
+ }
970
+ }, propagatedContext, async (span)=>{
971
+ try {
972
+ await processMessage();
973
+ span.setStatus({
974
+ code: SpanStatusCode.OK
975
+ });
976
+ } catch (err) {
977
+ span.setStatus({
978
+ code: SpanStatusCode.ERROR,
979
+ message: String(err)
980
+ });
981
+ if (typeof err === 'string' || err && err instanceof Error) {
982
+ span.recordException(err);
983
+ }
984
+ throw err;
985
+ } finally{
986
+ span.end();
987
+ }
988
+ });
989
+ } else {
990
+ await processMessage();
493
991
  }
494
- if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
495
- await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
992
+ if (latency !== undefined && topicType !== undefined) {
993
+ this.instrumentation.recordMessageLatency(topicType, latency);
496
994
  }
497
995
  return;
498
996
  }
499
997
  async validateReceivedMessage(validationFunc, msgId, source, topicType) {
500
998
  let resultAndObj = {
501
- result: false,
502
- obj: undefined
999
+ result: TopicValidatorResult.Reject
503
1000
  };
504
1001
  const timer = new Timer();
505
1002
  try {
506
1003
  resultAndObj = await validationFunc();
507
1004
  } catch (err) {
508
- this.logger.error(`Error deserializing and validating message `, err);
1005
+ this.peerManager.penalizePeer(source, PeerErrorSeverity.LowToleranceError);
1006
+ this.logger.error(`Error deserializing and validating gossipsub message`, err, {
1007
+ msgId,
1008
+ source: source.toString(),
1009
+ topicType
1010
+ });
509
1011
  }
510
- if (resultAndObj.result) {
1012
+ if (resultAndObj.result === TopicValidatorResult.Accept) {
511
1013
  this.instrumentation.recordMessageValidation(topicType, timer);
512
1014
  }
513
- this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result && resultAndObj.obj ? TopicValidatorResult.Accept : TopicValidatorResult.Reject);
1015
+ this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result);
514
1016
  return resultAndObj;
515
1017
  }
516
1018
  async handleGossipedTx(payloadData, msgId, source) {
517
1019
  const validationFunc = async ()=>{
518
1020
  const tx = Tx.fromBuffer(payloadData);
519
- const result = await this.validatePropagatedTx(tx, source);
520
- return {
521
- result,
522
- obj: tx
523
- };
1021
+ const isValid = await this.validatePropagatedTx(tx, source);
1022
+ const exists = isValid && await this.mempools.txPool.hasTx(tx.getTxHash());
1023
+ this.logger.trace(`Validate propagated tx`, {
1024
+ isValid,
1025
+ exists,
1026
+ [Attributes.P2P_ID]: source.toString()
1027
+ });
1028
+ if (!isValid) {
1029
+ return {
1030
+ result: TopicValidatorResult.Reject
1031
+ };
1032
+ } else if (exists) {
1033
+ return {
1034
+ result: TopicValidatorResult.Ignore,
1035
+ obj: tx
1036
+ };
1037
+ } else {
1038
+ return {
1039
+ result: TopicValidatorResult.Accept,
1040
+ obj: tx
1041
+ };
1042
+ }
524
1043
  };
525
1044
  const { result, obj: tx } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.tx);
526
- if (!result || !tx) {
1045
+ if (result !== TopicValidatorResult.Accept || !tx) {
527
1046
  return;
528
1047
  }
529
1048
  const txHash = tx.getTxHash();
@@ -533,9 +1052,10 @@ import { P2PInstrumentation } from './instrumentation.js';
533
1052
  txHash: txHashString
534
1053
  });
535
1054
  if (this.config.dropTransactions && randomInt(1000) < this.config.dropTransactionsProbability * 1000) {
536
- this.logger.debug(`Intentionally dropping tx ${txHashString} (probability rule)`);
1055
+ this.logger.warn(`Intentionally dropping tx ${txHashString} (probability rule)`);
537
1056
  return;
538
1057
  }
1058
+ this.instrumentation.incrementTxReceived(1);
539
1059
  await this.mempools.txPool.addTxs([
540
1060
  tx
541
1061
  ]);
@@ -548,25 +1068,57 @@ import { P2PInstrumentation } from './instrumentation.js';
548
1068
  */ async processAttestationFromPeer(payloadData, msgId, source) {
549
1069
  const validationFunc = async ()=>{
550
1070
  const attestation = BlockAttestation.fromBuffer(payloadData);
551
- const result = await this.validateAttestation(source, attestation);
552
- this.logger.trace(`validatePropagatedAttestation: ${result}`, {
1071
+ const pool = this.mempools.attestationPool;
1072
+ const isValid = await this.validateAttestation(source, attestation);
1073
+ const exists = isValid && await pool.hasAttestation(attestation);
1074
+ let canAdd = true;
1075
+ if (isValid && !exists) {
1076
+ const slot = attestation.payload.header.slotNumber;
1077
+ const { committee } = await this.epochCache.getCommittee(slot);
1078
+ const committeeSize = committee?.length ?? 0;
1079
+ canAdd = await pool.canAddAttestation(attestation, committeeSize);
1080
+ }
1081
+ this.logger.trace(`Validate propagated block attestation`, {
1082
+ isValid,
1083
+ exists,
1084
+ canAdd,
553
1085
  [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toString(),
554
1086
  [Attributes.P2P_ID]: source.toString()
555
1087
  });
556
- return {
557
- result,
558
- obj: attestation
559
- };
1088
+ if (!isValid) {
1089
+ return {
1090
+ result: TopicValidatorResult.Reject
1091
+ };
1092
+ } else if (exists) {
1093
+ return {
1094
+ result: TopicValidatorResult.Ignore,
1095
+ obj: attestation
1096
+ };
1097
+ } else if (!canAdd) {
1098
+ this.logger.warn(`Dropping block attestation due to per-(slot, proposalId) attestation cap`, {
1099
+ slot: attestation.payload.header.slotNumber.toString(),
1100
+ archive: attestation.archive.toString(),
1101
+ source: source.toString()
1102
+ });
1103
+ return {
1104
+ result: TopicValidatorResult.Ignore,
1105
+ obj: attestation
1106
+ };
1107
+ } else {
1108
+ return {
1109
+ result: TopicValidatorResult.Accept,
1110
+ obj: attestation
1111
+ };
1112
+ }
560
1113
  };
561
1114
  const { result, obj: attestation } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.block_attestation);
562
- if (!result || !attestation) {
1115
+ if (result !== TopicValidatorResult.Accept || !attestation) {
563
1116
  return;
564
1117
  }
565
- this.logger.debug(`Received attestation for block ${attestation.blockNumber} slot ${attestation.slotNumber.toNumber()} from external peer ${source.toString()}`, {
566
- p2pMessageIdentifier: await attestation.p2pMessageIdentifier(),
567
- slot: attestation.slotNumber.toNumber(),
1118
+ this.logger.debug(`Received attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`, {
1119
+ p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
1120
+ slot: attestation.slotNumber,
568
1121
  archive: attestation.archive.toString(),
569
- block: attestation.blockNumber,
570
1122
  source: source.toString()
571
1123
  });
572
1124
  await this.mempools.attestationPool.addAttestations([
@@ -576,15 +1128,42 @@ import { P2PInstrumentation } from './instrumentation.js';
576
1128
  async processBlockFromPeer(payloadData, msgId, source) {
577
1129
  const validationFunc = async ()=>{
578
1130
  const block = BlockProposal.fromBuffer(payloadData);
579
- const result = await this.validateBlockProposal(source, block);
580
- this.logger.trace(`validatePropagatedBlock: ${result}`, {
1131
+ const isValid = await this.validateBlockProposal(source, block);
1132
+ const pool = this.mempools.attestationPool;
1133
+ const exists = isValid && await pool.hasBlockProposal(block);
1134
+ const canAdd = isValid && await pool.canAddProposal(block);
1135
+ this.logger.trace(`Validate propagated block proposal`, {
1136
+ isValid,
1137
+ exists,
1138
+ canAdd,
581
1139
  [Attributes.SLOT_NUMBER]: block.payload.header.slotNumber.toString(),
582
1140
  [Attributes.P2P_ID]: source.toString()
583
1141
  });
584
- return {
585
- result,
586
- obj: block
587
- };
1142
+ if (!isValid) {
1143
+ return {
1144
+ result: TopicValidatorResult.Reject
1145
+ };
1146
+ } else if (exists) {
1147
+ return {
1148
+ result: TopicValidatorResult.Ignore,
1149
+ obj: block
1150
+ };
1151
+ } else if (!canAdd) {
1152
+ this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
1153
+ this.logger.warn(`Penalizing peer for block proposal exceeding per-slot cap`, {
1154
+ slot: block.slotNumber.toString(),
1155
+ archive: block.archive.toString(),
1156
+ source: source.toString()
1157
+ });
1158
+ return {
1159
+ result: TopicValidatorResult.Reject
1160
+ };
1161
+ } else {
1162
+ return {
1163
+ result: TopicValidatorResult.Accept,
1164
+ obj: block
1165
+ };
1166
+ }
588
1167
  };
589
1168
  const { result, obj: block } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.block_proposal);
590
1169
  if (!result || !block) {
@@ -594,33 +1173,41 @@ import { P2PInstrumentation } from './instrumentation.js';
594
1173
  }
595
1174
  // REVIEW: callback pattern https://github.com/AztecProtocol/aztec-packages/issues/7963
596
1175
  async processValidBlockProposal(block, sender) {
597
- const slot = block.slotNumber.toBigInt();
598
- const previousSlot = slot - 1n;
599
- const epoch = slot / 32n;
600
- this.logger.verbose(`Received block ${block.blockNumber} for slot ${slot} epoch ${epoch} from external peer ${sender.toString()}.`, {
601
- p2pMessageIdentifier: await block.p2pMessageIdentifier(),
602
- slot: block.slotNumber.toNumber(),
1176
+ const slot = block.slotNumber;
1177
+ const previousSlot = SlotNumber(slot - 1);
1178
+ this.logger.verbose(`Received block proposal for slot ${slot} from external peer ${sender.toString()}.`, {
1179
+ p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier(),
1180
+ slot: block.slotNumber,
603
1181
  archive: block.archive.toString(),
604
- block: block.blockNumber,
605
1182
  source: sender.toString()
606
1183
  });
607
- const attestationsForPreviousSlot = await this.mempools.attestationPool?.getAttestationsForSlot(previousSlot);
608
- if (attestationsForPreviousSlot !== undefined) {
609
- this.logger.verbose(`Received ${attestationsForPreviousSlot.length} attestations for slot ${previousSlot}`);
1184
+ const attestationsForPreviousSlot = await this.mempools.attestationPool.getAttestationsForSlot(previousSlot);
1185
+ this.logger.verbose(`Received ${attestationsForPreviousSlot.length} attestations for slot ${previousSlot}`);
1186
+ // Attempt to add proposal, then mark the txs in this proposal as non-evictable
1187
+ try {
1188
+ await this.mempools.attestationPool.addBlockProposal(block);
1189
+ } catch (err) {
1190
+ // Drop proposals if we hit per-slot cap in the attestation pool; rethrow unknown errors
1191
+ if (err instanceof ProposalSlotCapExceededError) {
1192
+ this.logger.warn(`Dropping block proposal due to per-slot proposal cap`, {
1193
+ slot: String(slot),
1194
+ archive: block.archive.toString(),
1195
+ error: err.message
1196
+ });
1197
+ return;
1198
+ }
1199
+ throw err;
610
1200
  }
611
- // Mark the txs in this proposal as non-evictable
612
1201
  await this.mempools.txPool.markTxsAsNonEvictable(block.txHashes);
613
- await this.mempools.attestationPool?.addBlockProposal(block);
614
1202
  const attestations = await this.blockReceivedCallback(block, sender);
615
1203
  // TODO: fix up this pattern - the abstraction is not nice
616
- // The attestation can be undefined if no handler is registered / the validator deems the block invalid
1204
+ // The attestation can be undefined if no handler is registered / the validator deems the block invalid / in fisherman mode
617
1205
  if (attestations?.length) {
618
1206
  for (const attestation of attestations){
619
- this.logger.verbose(`Broadcasting attestation for block ${attestation.blockNumber} slot ${attestation.slotNumber.toNumber()}`, {
620
- p2pMessageIdentifier: await attestation.p2pMessageIdentifier(),
621
- slot: attestation.slotNumber.toNumber(),
622
- archive: attestation.archive.toString(),
623
- block: attestation.blockNumber
1207
+ this.logger.verbose(`Broadcasting attestation for slot ${attestation.slotNumber}`, {
1208
+ p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
1209
+ slot: attestation.slotNumber,
1210
+ archive: attestation.archive.toString()
624
1211
  });
625
1212
  await this.broadcastAttestation(attestation);
626
1213
  }
@@ -636,19 +1223,84 @@ import { P2PInstrumentation } from './instrumentation.js';
636
1223
  * Propagates provided message to peers.
637
1224
  * @param message - The message to propagate.
638
1225
  */ async propagate(message) {
639
- const p2pMessageIdentifier = await message.p2pMessageIdentifier();
1226
+ const p2pMessageIdentifier = await message.p2pMessageLoggingIdentifier();
640
1227
  this.logger.trace(`Message ${p2pMessageIdentifier} queued`, {
641
1228
  p2pMessageIdentifier
642
1229
  });
643
- void this.jobQueue.put(async ()=>{
644
- await this.sendToPeers(message);
645
- }).catch((error)=>{
1230
+ void this.sendToPeers(message).catch((error)=>{
646
1231
  this.logger.error(`Error propagating message ${p2pMessageIdentifier}`, {
647
1232
  error
648
1233
  });
649
1234
  });
650
1235
  }
651
1236
  /**
1237
+ * Validate the requested block transactions. Allow partial returns.
1238
+ * @param request - The block transactions request.
1239
+ * @param response - The block transactions response.
1240
+ * @param peerId - The ID of the peer that made the request.
1241
+ * @returns True if the requested block transactions are valid, false otherwise.
1242
+ */ async validateRequestedBlockTxs(request, response, peerId) {
1243
+ const requestedTxValidator = this.createRequestedTxValidator();
1244
+ try {
1245
+ if (!response.blockHash.equals(request.blockHash)) {
1246
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1247
+ throw new ValidationError(`Received block txs for unexpected block: expected ${request.blockHash.toString()}, got ${response.blockHash.toString()}`);
1248
+ }
1249
+ if (response.txIndices.getLength() !== request.txIndices.getLength()) {
1250
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1251
+ throw new ValidationError(`Received block txs with mismatched bitvector length: expected ${request.txIndices.getLength()}, got ${response.txIndices.getLength()}`);
1252
+ }
1253
+ // Check no duplicates and not exceeding returnable count
1254
+ const requestedIndices = new Set(request.txIndices.getTrueIndices());
1255
+ const availableIndices = new Set(response.txIndices.getTrueIndices());
1256
+ const maxReturnable = [
1257
+ ...requestedIndices
1258
+ ].filter((i)=>availableIndices.has(i)).length;
1259
+ const returnedHashes = await Promise.all(response.txs.map((tx)=>tx.getTxHash().toString()));
1260
+ const uniqueReturned = new Set(returnedHashes.map((h)=>h.toString()));
1261
+ if (uniqueReturned.size !== returnedHashes.length) {
1262
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1263
+ throw new ValidationError(`Received duplicate txs in block txs response`);
1264
+ }
1265
+ if (response.txs.length > maxReturnable) {
1266
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1267
+ throw new ValidationError(`Received more txs (${response.txs.length}) than requested-and-available (${maxReturnable})`);
1268
+ }
1269
+ // Given proposal (should have locally), ensure returned txs are valid subset and match request indices
1270
+ const proposal = await this.mempools.attestationPool.getBlockProposal(request.blockHash.toString());
1271
+ if (proposal) {
1272
+ // Build intersected indices
1273
+ const intersectIdx = request.txIndices.getTrueIndices().filter((i)=>response.txIndices.isSet(i));
1274
+ // Enforce subset membership and preserve increasing order by index.
1275
+ const hashToIndexInProposal = new Map(proposal.txHashes.map((h, i)=>[
1276
+ h.toString(),
1277
+ i
1278
+ ]));
1279
+ const allowedIndexSet = new Set(intersectIdx);
1280
+ const indices = returnedHashes.map((h)=>hashToIndexInProposal.get(h));
1281
+ const allAllowed = indices.every((idx)=>idx !== undefined && allowedIndexSet.has(idx));
1282
+ const strictlyIncreasing = indices.every((idx, i)=>i === 0 ? idx !== undefined : idx > indices[i - 1]);
1283
+ if (!allAllowed || !strictlyIncreasing) {
1284
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
1285
+ throw new ValidationError('Returned txs do not match expected subset/order for requested indices');
1286
+ }
1287
+ } else {
1288
+ // No local proposal, cannot check the membership/order of the returned txs
1289
+ this.logger.warn(`Block proposal not found for block hash ${request.blockHash.toString()}; cannot validate membership/order of returned txs`);
1290
+ return false;
1291
+ }
1292
+ await Promise.all(response.txs.map((tx)=>this.validateRequestedTx(tx, peerId, requestedTxValidator)));
1293
+ return true;
1294
+ } catch (e) {
1295
+ if (e instanceof ValidationError) {
1296
+ this.logger.warn(`Failed validation for requested block txs from peer ${peerId.toString()}`);
1297
+ } else {
1298
+ this.logger.error(`Error during validation of requested block txs`, e);
1299
+ }
1300
+ return false;
1301
+ }
1302
+ }
1303
+ /**
652
1304
  * Validate a collection of txs that has been requested from a peer.
653
1305
  *
654
1306
  * The core component of this validator is that each tx hash MUST match the requested tx hash,
@@ -658,36 +1310,89 @@ import { P2PInstrumentation } from './instrumentation.js';
658
1310
  * ReqRespSubProtocol.TX subprotocol validation.
659
1311
  *
660
1312
  * @param requestedTxHash - The collection of the txs that was requested.
661
- * @param responseTx - The collectin of txs that was received as a response to the request.
1313
+ * @param responseTx - The collection of txs that was received as a response to the request.
662
1314
  * @param peerId - The peer ID of the peer that sent the tx.
663
1315
  * @returns True if the whole collection of txs is valid, false otherwise.
664
- */ //TODO: (mralj) - this is somewhat naive implementation, if single tx is invlid we consider the whole response invalid.
665
- // I think we should still extract the valid txs and return them, so that we can still use the response.
666
- async validateRequestedTx(requestedTxHash, responseTx, peerId) {
1316
+ */ async validateRequestedTxs(requestedTxHash, responseTx, peerId) {
667
1317
  const requested = new Set(requestedTxHash.map((h)=>h.toString()));
668
- const proofValidator = new TxProofValidator(this.proofVerifier);
1318
+ const requestedTxValidator = this.createRequestedTxValidator();
1319
+ //TODO: (mralj) - this is somewhat naive implementation, if single tx is invlid we consider the whole response invalid.
1320
+ // I think we should still extract the valid txs and return them, so that we can still use the response.
669
1321
  try {
670
- await Promise.all(responseTx.map(async (tx)=>{
671
- if (!requested.has(tx.getTxHash().toString())) {
672
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
673
- throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
674
- }
675
- const { result } = await proofValidator.validateTx(tx);
676
- if (result === 'invalid') {
677
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
678
- throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that is invalid.`);
679
- }
680
- }));
1322
+ await Promise.all(responseTx.map((tx)=>this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
681
1323
  return true;
682
1324
  } catch (e) {
683
1325
  if (e instanceof ValidationError) {
684
- this.logger.debug(`Failed to validate requested txs from peer ${peerId.toString()}, reason ${e.message}`);
1326
+ this.logger.warn(`Failed to validate requested txs from peer ${peerId.toString()}, reason ${e.message}`);
685
1327
  } else {
686
- this.logger.warn(`Error during validation of requested txs`, e);
1328
+ this.logger.error(`Error during validation of requested txs`, e);
687
1329
  }
688
1330
  return false;
689
1331
  }
690
1332
  }
1333
+ /**
1334
+ * Validates a BLOCK response.
1335
+ *
1336
+ * If a local copy exists, enforces hash equality. If missing, rejects (no penalty) since the hash cannot be verified.
1337
+ * Penalizes on block number mismatch or hash mismatch.
1338
+ *
1339
+ * @param requestedBlockNumber - The requested block number.
1340
+ * @param responseBlock - The block returned by the peer.
1341
+ * @param peerId - The peer that returned the block.
1342
+ * @returns True if the response is valid, false otherwise.
1343
+ */ async validateRequestedBlock(requestedBlockNumber, responseBlock, peerId) {
1344
+ try {
1345
+ const reqNum = Number(requestedBlockNumber.toString());
1346
+ if (responseBlock.number !== reqNum) {
1347
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
1348
+ return false;
1349
+ }
1350
+ const local = await this.archiver.getBlock(BlockNumber(reqNum));
1351
+ if (!local) {
1352
+ // We are missing the local block; we cannot verify the hash yet. Reject without penalizing.
1353
+ // TODO: Consider extending this validator to accept an expected hash or
1354
+ // performing quorum-based checks when using P2P syncing prior to L1 sync.
1355
+ this.logger.warn(`Local block ${reqNum} not found; rejecting BLOCK response without hash verification`);
1356
+ return false;
1357
+ }
1358
+ const [localHash, respHash] = await Promise.all([
1359
+ local.hash(),
1360
+ responseBlock.hash()
1361
+ ]);
1362
+ if (!localHash.equals(respHash)) {
1363
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1364
+ return false;
1365
+ }
1366
+ return true;
1367
+ } catch (e) {
1368
+ this.logger.warn(`Error validating requested block`, e);
1369
+ return false;
1370
+ }
1371
+ }
1372
+ createRequestedTxValidator() {
1373
+ return new AggregateTxValidator(new DataTxValidator(), new MetadataTxValidator({
1374
+ l1ChainId: new Fr(this.config.l1ChainId),
1375
+ rollupVersion: new Fr(this.config.rollupVersion),
1376
+ protocolContractsHash,
1377
+ vkTreeRoot: getVKTreeRoot()
1378
+ }), new TxProofValidator(this.proofVerifier));
1379
+ }
1380
+ async validateRequestedTx(tx, peerId, txValidator, requested) {
1381
+ const penalize = (severity)=>this.peerManager.penalizePeer(peerId, severity);
1382
+ if (!await tx.validateTxHash()) {
1383
+ penalize(PeerErrorSeverity.MidToleranceError);
1384
+ throw new ValidationError(`Received tx with invalid hash ${tx.getTxHash().toString()}.`);
1385
+ }
1386
+ if (requested && !requested.has(tx.getTxHash().toString())) {
1387
+ penalize(PeerErrorSeverity.MidToleranceError);
1388
+ throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
1389
+ }
1390
+ const { result } = await txValidator.validateTx(tx);
1391
+ if (result === 'invalid') {
1392
+ penalize(PeerErrorSeverity.LowToleranceError);
1393
+ throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that is invalid.`);
1394
+ }
1395
+ }
691
1396
  async validatePropagatedTx(tx, peerId) {
692
1397
  const currentBlockNumber = await this.archiver.getBlockNumber();
693
1398
  // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
@@ -702,7 +1407,7 @@ import { P2PInstrumentation } from './instrumentation.js';
702
1407
  let { severity } = outcome.failure;
703
1408
  // Double spend validator has a special case handler
704
1409
  if (name === 'doubleSpendValidator') {
705
- const txBlockNumber = currentBlockNumber + 1; // tx is expected to be in the next block
1410
+ const txBlockNumber = BlockNumber(currentBlockNumber + 1); // tx is expected to be in the next block
706
1411
  severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
707
1412
  }
708
1413
  this.peerManager.penalizePeer(peerId, severity);
@@ -752,8 +1457,8 @@ import { P2PInstrumentation } from './instrumentation.js';
752
1457
  */ async createMessageValidators(currentBlockNumber, nextSlotTimestamp) {
753
1458
  const gasFees = await this.getGasFees(currentBlockNumber);
754
1459
  const allowedInSetup = this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
755
- const blockNumberInWhichTheTxIsConsideredToBeIncluded = currentBlockNumber + 1;
756
- return createTxMessageValidators(nextSlotTimestamp, blockNumberInWhichTheTxIsConsideredToBeIncluded, this.worldStateSynchronizer, gasFees, this.config.l1ChainId, this.config.rollupVersion, protocolContractTreeRoot, this.archiver, this.proofVerifier, !this.config.disableTransactions, allowedInSetup);
1460
+ const blockNumberInWhichTheTxIsConsideredToBeIncluded = BlockNumber(currentBlockNumber + 1);
1461
+ return createTxMessageValidators(nextSlotTimestamp, blockNumberInWhichTheTxIsConsideredToBeIncluded, this.worldStateSynchronizer, gasFees, this.config.l1ChainId, this.config.rollupVersion, protocolContractsHash, this.archiver, this.proofVerifier, !this.config.disableTransactions, allowedInSetup);
757
1462
  }
758
1463
  /**
759
1464
  * Run validations on a tx.
@@ -808,7 +1513,7 @@ import { P2PInstrumentation } from './instrumentation.js';
808
1513
  }
809
1514
  const snapshotValidator = new DoubleSpendTxValidator({
810
1515
  nullifiersExist: async (nullifiers)=>{
811
- const merkleTree = this.worldStateSynchronizer.getSnapshot(blockNumber - this.config.doubleSpendSeverePeerPenaltyWindow);
1516
+ const merkleTree = this.worldStateSynchronizer.getSnapshot(BlockNumber(blockNumber - this.config.doubleSpendSeverePeerPenaltyWindow));
812
1517
  const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
813
1518
  return indices.map((index)=>index !== undefined);
814
1519
  }
@@ -854,7 +1559,7 @@ import { P2PInstrumentation } from './instrumentation.js';
854
1559
  }
855
1560
  async sendToPeers(message) {
856
1561
  const parent = message.constructor;
857
- const identifier = await message.p2pMessageIdentifier().then((i)=>i.toString());
1562
+ const identifier = await message.p2pMessageLoggingIdentifier().then((i)=>i.toString());
858
1563
  this.logger.trace(`Sending message ${identifier}`, {
859
1564
  p2pMessageIdentifier: identifier
860
1565
  });
@@ -881,42 +1586,3 @@ import { P2PInstrumentation } from './instrumentation.js';
881
1586
  }
882
1587
  }
883
1588
  }
884
- _ts_decorate([
885
- trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
886
- [Attributes.BLOCK_NUMBER]: block.blockNumber,
887
- [Attributes.SLOT_NUMBER]: block.slotNumber.toNumber(),
888
- [Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
889
- [Attributes.P2P_ID]: await block.p2pMessageIdentifier().then((i)=>i.toString())
890
- }))
891
- ], LibP2PService.prototype, "processValidBlockProposal", null);
892
- _ts_decorate([
893
- trackSpan('Libp2pService.broadcastAttestation', async (attestation)=>({
894
- [Attributes.BLOCK_NUMBER]: attestation.blockNumber,
895
- [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toNumber(),
896
- [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
897
- [Attributes.P2P_ID]: await attestation.p2pMessageIdentifier().then((i)=>i.toString())
898
- }))
899
- ], LibP2PService.prototype, "broadcastAttestation", null);
900
- _ts_decorate([
901
- trackSpan('Libp2pService.validateRequestedTx', (requestedTxHash, _responseTx)=>({
902
- [Attributes.TX_HASH]: requestedTxHash.toString()
903
- }))
904
- ], LibP2PService.prototype, "validateRequestedTx", null);
905
- _ts_decorate([
906
- trackSpan('Libp2pService.validatePropagatedTx', (tx)=>({
907
- [Attributes.TX_HASH]: tx.getTxHash().toString()
908
- }))
909
- ], LibP2PService.prototype, "validatePropagatedTx", null);
910
- _ts_decorate([
911
- trackSpan('Libp2pService.validateAttestation', async (_, attestation)=>({
912
- [Attributes.BLOCK_NUMBER]: attestation.blockNumber,
913
- [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toNumber(),
914
- [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
915
- [Attributes.P2P_ID]: await attestation.p2pMessageIdentifier().then((i)=>i.toString())
916
- }))
917
- ], LibP2PService.prototype, "validateAttestation", null);
918
- _ts_decorate([
919
- trackSpan('Libp2pService.validateBlockProposal', (_peerId, block)=>({
920
- [Attributes.SLOT_NUMBER]: block.payload.header.slotNumber.toString()
921
- }))
922
- ], LibP2PService.prototype, "validateBlockProposal", null);