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

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 +12 -35
  11. package/dest/client/p2p_client.d.ts.map +1 -1
  12. package/dest/client/p2p_client.js +457 -61
  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 +32 -72
  147. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  148. package/dest/services/libp2p/libp2p_service.js +796 -171
  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 +1 -32
  154. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  155. package/dest/services/peer-manager/peer_manager.js +412 -21
  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 +97 -88
  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 +430 -165
  304. package/src/services/peer-manager/metrics.ts +32 -0
  305. package/src/services/peer-manager/peer_manager.ts +24 -14
  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
+ };
6
369
  }
7
- import { randomInt } from '@aztec/foundation/crypto';
370
+ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
371
+ return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
372
+ }
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
387
  import { Attributes, OtelMetricsAdapter, WithTracer, trackSpan } from '@aztec/telemetry-client';
19
- import { ENR } from '@chainsafe/enr';
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,11 @@ import { P2PInstrumentation } from './instrumentation.js';
80
514
  */ blockReceivedCallback;
81
515
  gossipSubEventHandler;
82
516
  instrumentation;
517
+ logger;
83
518
  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 = {};
519
+ 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 = {};
520
+ // Create child logger with fisherman prefix if in fisherman mode
521
+ this.logger = config.fishermanMode ? logger.createChild('[FISHERMAN]') : logger;
85
522
  this.instrumentation = new P2PInstrumentation(telemetry, 'LibP2PService');
86
523
  this.msgIdSeenValidators[TopicType.tx] = new MessageSeenValidator(config.seenMessageCacheSize);
87
524
  this.msgIdSeenValidators[TopicType.block_proposal] = new MessageSeenValidator(config.seenMessageCacheSize);
@@ -92,12 +529,15 @@ import { P2PInstrumentation } from './instrumentation.js';
92
529
  this.topicStrings[TopicType.tx] = createTopicString(TopicType.tx, this.protocolVersion);
93
530
  this.topicStrings[TopicType.block_proposal] = createTopicString(TopicType.block_proposal, this.protocolVersion);
94
531
  this.topicStrings[TopicType.block_attestation] = createTopicString(TopicType.block_attestation, this.protocolVersion);
95
- this.attestationValidator = new AttestationValidator(epochCache);
96
- this.blockProposalValidator = new BlockProposalValidator(epochCache);
532
+ // Use FishermanAttestationValidator in fisherman mode to validate attestation payloads against proposals
533
+ this.attestationValidator = config.fishermanMode ? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry) : new AttestationValidator(epochCache);
534
+ this.blockProposalValidator = new BlockProposalValidator(epochCache, {
535
+ txsPermitted: !config.disableTransactions
536
+ });
97
537
  this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
98
538
  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()
539
+ this.logger.debug(`Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber} from peer.`, {
540
+ p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier()
101
541
  });
102
542
  return undefined;
103
543
  };
@@ -165,7 +605,7 @@ import { P2PInstrumentation } from './instrumentation.js';
165
605
  // 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
606
  // If we hit the limit, the connection will be temporarily accepted and immediately dropped.
167
607
  // Docs: https://nodejs.org/api/net.html#servermaxconnections
168
- maxConnections: Math.ceil(maxPeerCount * 1.5),
608
+ maxConnections: maxPeerCount * 2,
169
609
  // socket option: the maximum length of the queue of pending connections
170
610
  // https://nodejs.org/dist/latest-v22.x/docs/api/net.html#serverlisten
171
611
  // it's not safe if we increase this number
@@ -176,7 +616,7 @@ import { P2PInstrumentation } from './instrumentation.js';
176
616
  // In case closeAbove is reached, the server stops listening altogether
177
617
  // It's important that there is enough difference between closeAbove and listenAbove,
178
618
  // otherwise the server.listener will flap between being closed and open potentially degrading perf even more
179
- closeAbove: maxPeerCount * 2,
619
+ closeAbove: maxPeerCount * 3,
180
620
  listenBelow: Math.floor(maxPeerCount * 0.9)
181
621
  }
182
622
  })
@@ -192,7 +632,9 @@ import { P2PInstrumentation } from './instrumentation.js';
192
632
  ],
193
633
  connectionManager: {
194
634
  minConnections: 0,
195
- maxConnections: maxPeerCount,
635
+ // We set maxConnections above maxPeerCount because if we hit limit of maxPeerCount
636
+ // libp2p will start aggressively rejecting all new connections, preventing network discovery and crawling.
637
+ maxConnections: maxPeerCount * 2,
196
638
  maxParallelDials: 100,
197
639
  dialTimeout: 30_000,
198
640
  maxPeerAddrsToDial: 5,
@@ -273,7 +715,7 @@ import { P2PInstrumentation } from './instrumentation.js';
273
715
  },
274
716
  logger: createLibp2pComponentLogger(logger.module)
275
717
  });
276
- const peerScoring = new PeerScoring(config);
718
+ const peerScoring = new PeerScoring(config, telemetry);
277
719
  const reqresp = new ReqResp(config, node, peerScoring, createLogger(`${logger.module}:reqresp`));
278
720
  const peerManager = new PeerManager(node, peerDiscoveryService, config, telemetry, createLogger(`${logger.module}:peer_manager`), peerScoring, reqresp, worldStateSynchronizer, protocolVersion, epochCache);
279
721
  // Update gossipsub score params
@@ -295,8 +737,6 @@ import { P2PInstrumentation } from './instrumentation.js';
295
737
  throw new Error('Announce address not provided.');
296
738
  }
297
739
  const announceTcpMultiaddr = convertToMultiaddr(p2pIp, p2pPort, 'tcp');
298
- // Start job queue, peer discovery service and libp2p node
299
- this.jobQueue.start();
300
740
  await this.peerManager.initializePeers();
301
741
  if (!this.config.p2pDiscoveryDisabled) {
302
742
  await this.peerDiscoveryService.start();
@@ -311,18 +751,13 @@ import { P2PInstrumentation } from './instrumentation.js';
311
751
  const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
312
752
  const blockHandler = reqRespBlockHandler(this.archiver);
313
753
  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
754
  const requestResponseHandlers = {
319
755
  [ReqRespSubProtocol.PING]: pingHandler,
320
756
  [ReqRespSubProtocol.STATUS]: statusHandler.bind(this),
321
757
  [ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this),
322
758
  [ReqRespSubProtocol.BLOCK]: blockHandler.bind(this)
323
759
  };
324
- // Only handle block transactions request if attestation pool is available to the client
325
- if (this.mempools.attestationPool) {
760
+ if (!this.config.disableTransactions) {
326
761
  const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.mempools.txPool);
327
762
  requestResponseHandlers[ReqRespSubProtocol.BLOCK_TXS] = blockTxsHandler.bind(this);
328
763
  }
@@ -331,14 +766,17 @@ import { P2PInstrumentation } from './instrumentation.js';
331
766
  }
332
767
  // add GossipSub listener
333
768
  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);
769
+ // Start running promise for peer discovery and metrics collection
770
+ this.discoveryRunningPromise = new RunningPromise(async ()=>{
771
+ await this.peerManager.heartbeat();
772
+ }, this.logger, this.config.peerCheckIntervalMS);
336
773
  this.discoveryRunningPromise.start();
337
774
  // Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
338
775
  const reqrespSubProtocolValidators = {
339
776
  ...DEFAULT_SUB_PROTOCOL_VALIDATORS,
340
- // TODO(#11336): A request validator for blocks
341
- [ReqRespSubProtocol.TX]: this.validateRequestedTx.bind(this)
777
+ [ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
778
+ [ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
779
+ [ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this)
342
780
  };
343
781
  await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
344
782
  this.logger.info(`Started P2P service`, {
@@ -357,8 +795,6 @@ import { P2PInstrumentation } from './instrumentation.js';
357
795
  // Stop peer manager
358
796
  this.logger.debug('Stopping peer manager...');
359
797
  await this.peerManager.stop();
360
- this.logger.debug('Stopping job queue...');
361
- await this.jobQueue.end();
362
798
  this.logger.debug('Stopping running promise...');
363
799
  await this.discoveryRunningPromise?.stop();
364
800
  this.logger.debug('Stopping peer discovery service...');
@@ -424,15 +860,15 @@ import { P2PInstrumentation } from './instrumentation.js';
424
860
  if (!this.node.services.pubsub) {
425
861
  throw new Error('Pubsub service not available.');
426
862
  }
427
- const p2pMessage = await P2PMessage.fromGossipable(message);
428
- this.logger.debug(`Publishing message`, {
429
- topic,
430
- messageId: p2pMessage.id
431
- });
863
+ const p2pMessage = P2PMessage.fromGossipable(message, this.config.debugP2PInstrumentMessages);
432
864
  const result = await this.node.services.pubsub.publish(topic, p2pMessage.toMessageData());
433
865
  return result.recipients.length;
434
866
  }
435
- preValidateReceivedMessage(msg, msgId, source) {
867
+ /**
868
+ * Checks if this message has already been seen, based on its msgId computed from hashing the message data.
869
+ * Note that we do not rely on the seenCache from gossipsub since we want to keep a longer history of seen
870
+ * messages to avoid tx echoes across the network.
871
+ */ preValidateReceivedMessage(msg, msgId, source) {
436
872
  let topicType;
437
873
  switch(msg.topic){
438
874
  case this.topicStrings[TopicType.tx]:
@@ -464,66 +900,108 @@ import { P2PInstrumentation } from './instrumentation.js';
464
900
  };
465
901
  }
466
902
  /**
903
+ * Safely deserializes a P2PMessage from raw message data.
904
+ * @param msgId - The message ID.
905
+ * @param source - The peer ID of the message source.
906
+ * @param data - The raw message data.
907
+ * @returns The deserialized P2PMessage or undefined if deserialization fails.
908
+ */ safelyDeserializeP2PMessage(msgId, source, data) {
909
+ try {
910
+ return P2PMessage.fromMessageData(Buffer.from(data), this.config.debugP2PInstrumentMessages);
911
+ } catch (err) {
912
+ this.logger.error(`Error deserializing P2PMessage`, err, {
913
+ msgId,
914
+ source: source.toString()
915
+ });
916
+ this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Reject);
917
+ this.peerManager.penalizePeer(source, PeerErrorSeverity.LowToleranceError);
918
+ return undefined;
919
+ }
920
+ }
921
+ /**
467
922
  * Handles a new gossip message that was received by the client.
468
923
  * @param topic - The message's topic.
469
924
  * @param data - The message data
470
925
  */ 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
- });
926
+ const msgReceivedTime = Date.now();
927
+ let topicType;
928
+ const p2pMessage = this.safelyDeserializeP2PMessage(msgId, source, msg.data);
929
+ if (!p2pMessage) {
930
+ return;
931
+ }
479
932
  const preValidationResult = this.preValidateReceivedMessage(msg, msgId, source);
480
933
  if (!preValidationResult.result) {
481
934
  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
935
  }
488
936
  if (msg.topic === this.topicStrings[TopicType.tx]) {
937
+ topicType = TopicType.tx;
489
938
  await this.handleGossipedTx(p2pMessage.payload, msgId, source);
490
939
  }
491
- if (msg.topic === this.topicStrings[TopicType.block_attestation] && this.clientType === P2PClientType.Full) {
492
- await this.processAttestationFromPeer(p2pMessage.payload, msgId, source);
940
+ if (msg.topic === this.topicStrings[TopicType.block_attestation]) {
941
+ topicType = TopicType.block_attestation;
942
+ if (this.clientType === P2PClientType.Full) {
943
+ await this.processAttestationFromPeer(p2pMessage.payload, msgId, source);
944
+ }
493
945
  }
494
946
  if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
947
+ topicType = TopicType.block_proposal;
495
948
  await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
496
949
  }
950
+ if (p2pMessage.timestamp !== undefined && topicType !== undefined) {
951
+ const latency = msgReceivedTime - p2pMessage.timestamp.getTime();
952
+ this.instrumentation.recordMessageLatency(topicType, latency);
953
+ }
497
954
  return;
498
955
  }
499
956
  async validateReceivedMessage(validationFunc, msgId, source, topicType) {
500
957
  let resultAndObj = {
501
- result: false,
502
- obj: undefined
958
+ result: TopicValidatorResult.Reject
503
959
  };
504
960
  const timer = new Timer();
505
961
  try {
506
962
  resultAndObj = await validationFunc();
507
963
  } catch (err) {
508
- this.logger.error(`Error deserializing and validating message `, err);
964
+ this.peerManager.penalizePeer(source, PeerErrorSeverity.LowToleranceError);
965
+ this.logger.error(`Error deserializing and validating gossipsub message`, err, {
966
+ msgId,
967
+ source: source.toString(),
968
+ topicType
969
+ });
509
970
  }
510
- if (resultAndObj.result) {
971
+ if (resultAndObj.result === TopicValidatorResult.Accept) {
511
972
  this.instrumentation.recordMessageValidation(topicType, timer);
512
973
  }
513
- this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result && resultAndObj.obj ? TopicValidatorResult.Accept : TopicValidatorResult.Reject);
974
+ this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result);
514
975
  return resultAndObj;
515
976
  }
516
977
  async handleGossipedTx(payloadData, msgId, source) {
517
978
  const validationFunc = async ()=>{
518
979
  const tx = Tx.fromBuffer(payloadData);
519
- const result = await this.validatePropagatedTx(tx, source);
520
- return {
521
- result,
522
- obj: tx
523
- };
980
+ const isValid = await this.validatePropagatedTx(tx, source);
981
+ const exists = isValid && await this.mempools.txPool.hasTx(tx.getTxHash());
982
+ this.logger.trace(`Validate propagated tx`, {
983
+ isValid,
984
+ exists,
985
+ [Attributes.P2P_ID]: source.toString()
986
+ });
987
+ if (!isValid) {
988
+ return {
989
+ result: TopicValidatorResult.Reject
990
+ };
991
+ } else if (exists) {
992
+ return {
993
+ result: TopicValidatorResult.Ignore,
994
+ obj: tx
995
+ };
996
+ } else {
997
+ return {
998
+ result: TopicValidatorResult.Accept,
999
+ obj: tx
1000
+ };
1001
+ }
524
1002
  };
525
1003
  const { result, obj: tx } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.tx);
526
- if (!result || !tx) {
1004
+ if (result !== TopicValidatorResult.Accept || !tx) {
527
1005
  return;
528
1006
  }
529
1007
  const txHash = tx.getTxHash();
@@ -533,9 +1011,10 @@ import { P2PInstrumentation } from './instrumentation.js';
533
1011
  txHash: txHashString
534
1012
  });
535
1013
  if (this.config.dropTransactions && randomInt(1000) < this.config.dropTransactionsProbability * 1000) {
536
- this.logger.debug(`Intentionally dropping tx ${txHashString} (probability rule)`);
1014
+ this.logger.warn(`Intentionally dropping tx ${txHashString} (probability rule)`);
537
1015
  return;
538
1016
  }
1017
+ this.instrumentation.incrementTxReceived(1);
539
1018
  await this.mempools.txPool.addTxs([
540
1019
  tx
541
1020
  ]);
@@ -548,25 +1027,57 @@ import { P2PInstrumentation } from './instrumentation.js';
548
1027
  */ async processAttestationFromPeer(payloadData, msgId, source) {
549
1028
  const validationFunc = async ()=>{
550
1029
  const attestation = BlockAttestation.fromBuffer(payloadData);
551
- const result = await this.validateAttestation(source, attestation);
552
- this.logger.trace(`validatePropagatedAttestation: ${result}`, {
1030
+ const pool = this.mempools.attestationPool;
1031
+ const isValid = await this.validateAttestation(source, attestation);
1032
+ const exists = isValid && await pool.hasAttestation(attestation);
1033
+ let canAdd = true;
1034
+ if (isValid && !exists) {
1035
+ const slot = attestation.payload.header.slotNumber;
1036
+ const { committee } = await this.epochCache.getCommittee(slot);
1037
+ const committeeSize = committee?.length ?? 0;
1038
+ canAdd = await pool.canAddAttestation(attestation, committeeSize);
1039
+ }
1040
+ this.logger.trace(`Validate propagated block attestation`, {
1041
+ isValid,
1042
+ exists,
1043
+ canAdd,
553
1044
  [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toString(),
554
1045
  [Attributes.P2P_ID]: source.toString()
555
1046
  });
556
- return {
557
- result,
558
- obj: attestation
559
- };
1047
+ if (!isValid) {
1048
+ return {
1049
+ result: TopicValidatorResult.Reject
1050
+ };
1051
+ } else if (exists) {
1052
+ return {
1053
+ result: TopicValidatorResult.Ignore,
1054
+ obj: attestation
1055
+ };
1056
+ } else if (!canAdd) {
1057
+ this.logger.warn(`Dropping block attestation due to per-(slot, proposalId) attestation cap`, {
1058
+ slot: attestation.payload.header.slotNumber.toString(),
1059
+ archive: attestation.archive.toString(),
1060
+ source: source.toString()
1061
+ });
1062
+ return {
1063
+ result: TopicValidatorResult.Ignore,
1064
+ obj: attestation
1065
+ };
1066
+ } else {
1067
+ return {
1068
+ result: TopicValidatorResult.Accept,
1069
+ obj: attestation
1070
+ };
1071
+ }
560
1072
  };
561
1073
  const { result, obj: attestation } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.block_attestation);
562
- if (!result || !attestation) {
1074
+ if (result !== TopicValidatorResult.Accept || !attestation) {
563
1075
  return;
564
1076
  }
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(),
1077
+ this.logger.debug(`Received attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`, {
1078
+ p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
1079
+ slot: attestation.slotNumber,
568
1080
  archive: attestation.archive.toString(),
569
- block: attestation.blockNumber,
570
1081
  source: source.toString()
571
1082
  });
572
1083
  await this.mempools.attestationPool.addAttestations([
@@ -576,15 +1087,42 @@ import { P2PInstrumentation } from './instrumentation.js';
576
1087
  async processBlockFromPeer(payloadData, msgId, source) {
577
1088
  const validationFunc = async ()=>{
578
1089
  const block = BlockProposal.fromBuffer(payloadData);
579
- const result = await this.validateBlockProposal(source, block);
580
- this.logger.trace(`validatePropagatedBlock: ${result}`, {
1090
+ const isValid = await this.validateBlockProposal(source, block);
1091
+ const pool = this.mempools.attestationPool;
1092
+ const exists = isValid && await pool.hasBlockProposal(block);
1093
+ const canAdd = isValid && await pool.canAddProposal(block);
1094
+ this.logger.trace(`Validate propagated block proposal`, {
1095
+ isValid,
1096
+ exists,
1097
+ canAdd,
581
1098
  [Attributes.SLOT_NUMBER]: block.payload.header.slotNumber.toString(),
582
1099
  [Attributes.P2P_ID]: source.toString()
583
1100
  });
584
- return {
585
- result,
586
- obj: block
587
- };
1101
+ if (!isValid) {
1102
+ return {
1103
+ result: TopicValidatorResult.Reject
1104
+ };
1105
+ } else if (exists) {
1106
+ return {
1107
+ result: TopicValidatorResult.Ignore,
1108
+ obj: block
1109
+ };
1110
+ } else if (!canAdd) {
1111
+ this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
1112
+ this.logger.warn(`Penalizing peer for block proposal exceeding per-slot cap`, {
1113
+ slot: block.slotNumber.toString(),
1114
+ archive: block.archive.toString(),
1115
+ source: source.toString()
1116
+ });
1117
+ return {
1118
+ result: TopicValidatorResult.Reject
1119
+ };
1120
+ } else {
1121
+ return {
1122
+ result: TopicValidatorResult.Accept,
1123
+ obj: block
1124
+ };
1125
+ }
588
1126
  };
589
1127
  const { result, obj: block } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.block_proposal);
590
1128
  if (!result || !block) {
@@ -594,33 +1132,41 @@ import { P2PInstrumentation } from './instrumentation.js';
594
1132
  }
595
1133
  // REVIEW: callback pattern https://github.com/AztecProtocol/aztec-packages/issues/7963
596
1134
  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(),
1135
+ const slot = block.slotNumber;
1136
+ const previousSlot = SlotNumber(slot - 1);
1137
+ this.logger.verbose(`Received block proposal for slot ${slot} from external peer ${sender.toString()}.`, {
1138
+ p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier(),
1139
+ slot: block.slotNumber,
603
1140
  archive: block.archive.toString(),
604
- block: block.blockNumber,
605
1141
  source: sender.toString()
606
1142
  });
607
- const attestationsForPreviousSlot = await this.mempools.attestationPool?.getAttestationsForSlot(previousSlot);
608
- if (attestationsForPreviousSlot !== undefined) {
609
- this.logger.verbose(`Received ${attestationsForPreviousSlot.length} attestations for slot ${previousSlot}`);
1143
+ const attestationsForPreviousSlot = await this.mempools.attestationPool.getAttestationsForSlot(previousSlot);
1144
+ this.logger.verbose(`Received ${attestationsForPreviousSlot.length} attestations for slot ${previousSlot}`);
1145
+ // Attempt to add proposal, then mark the txs in this proposal as non-evictable
1146
+ try {
1147
+ await this.mempools.attestationPool.addBlockProposal(block);
1148
+ } catch (err) {
1149
+ // Drop proposals if we hit per-slot cap in the attestation pool; rethrow unknown errors
1150
+ if (err instanceof ProposalSlotCapExceededError) {
1151
+ this.logger.warn(`Dropping block proposal due to per-slot proposal cap`, {
1152
+ slot: String(slot),
1153
+ archive: block.archive.toString(),
1154
+ error: err.message
1155
+ });
1156
+ return;
1157
+ }
1158
+ throw err;
610
1159
  }
611
- // Mark the txs in this proposal as non-evictable
612
1160
  await this.mempools.txPool.markTxsAsNonEvictable(block.txHashes);
613
- await this.mempools.attestationPool?.addBlockProposal(block);
614
1161
  const attestations = await this.blockReceivedCallback(block, sender);
615
1162
  // 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
1163
+ // The attestation can be undefined if no handler is registered / the validator deems the block invalid / in fisherman mode
617
1164
  if (attestations?.length) {
618
1165
  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
1166
+ this.logger.verbose(`Broadcasting attestation for slot ${attestation.slotNumber}`, {
1167
+ p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
1168
+ slot: attestation.slotNumber,
1169
+ archive: attestation.archive.toString()
624
1170
  });
625
1171
  await this.broadcastAttestation(attestation);
626
1172
  }
@@ -636,19 +1182,84 @@ import { P2PInstrumentation } from './instrumentation.js';
636
1182
  * Propagates provided message to peers.
637
1183
  * @param message - The message to propagate.
638
1184
  */ async propagate(message) {
639
- const p2pMessageIdentifier = await message.p2pMessageIdentifier();
1185
+ const p2pMessageIdentifier = await message.p2pMessageLoggingIdentifier();
640
1186
  this.logger.trace(`Message ${p2pMessageIdentifier} queued`, {
641
1187
  p2pMessageIdentifier
642
1188
  });
643
- void this.jobQueue.put(async ()=>{
644
- await this.sendToPeers(message);
645
- }).catch((error)=>{
1189
+ void this.sendToPeers(message).catch((error)=>{
646
1190
  this.logger.error(`Error propagating message ${p2pMessageIdentifier}`, {
647
1191
  error
648
1192
  });
649
1193
  });
650
1194
  }
651
1195
  /**
1196
+ * Validate the requested block transactions. Allow partial returns.
1197
+ * @param request - The block transactions request.
1198
+ * @param response - The block transactions response.
1199
+ * @param peerId - The ID of the peer that made the request.
1200
+ * @returns True if the requested block transactions are valid, false otherwise.
1201
+ */ async validateRequestedBlockTxs(request, response, peerId) {
1202
+ const requestedTxValidator = this.createRequestedTxValidator();
1203
+ try {
1204
+ if (!response.blockHash.equals(request.blockHash)) {
1205
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1206
+ throw new ValidationError(`Received block txs for unexpected block: expected ${request.blockHash.toString()}, got ${response.blockHash.toString()}`);
1207
+ }
1208
+ if (response.txIndices.getLength() !== request.txIndices.getLength()) {
1209
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1210
+ throw new ValidationError(`Received block txs with mismatched bitvector length: expected ${request.txIndices.getLength()}, got ${response.txIndices.getLength()}`);
1211
+ }
1212
+ // Check no duplicates and not exceeding returnable count
1213
+ const requestedIndices = new Set(request.txIndices.getTrueIndices());
1214
+ const availableIndices = new Set(response.txIndices.getTrueIndices());
1215
+ const maxReturnable = [
1216
+ ...requestedIndices
1217
+ ].filter((i)=>availableIndices.has(i)).length;
1218
+ const returnedHashes = await Promise.all(response.txs.map((tx)=>tx.getTxHash().toString()));
1219
+ const uniqueReturned = new Set(returnedHashes.map((h)=>h.toString()));
1220
+ if (uniqueReturned.size !== returnedHashes.length) {
1221
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1222
+ throw new ValidationError(`Received duplicate txs in block txs response`);
1223
+ }
1224
+ if (response.txs.length > maxReturnable) {
1225
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1226
+ throw new ValidationError(`Received more txs (${response.txs.length}) than requested-and-available (${maxReturnable})`);
1227
+ }
1228
+ // Given proposal (should have locally), ensure returned txs are valid subset and match request indices
1229
+ const proposal = await this.mempools.attestationPool.getBlockProposal(request.blockHash.toString());
1230
+ if (proposal) {
1231
+ // Build intersected indices
1232
+ const intersectIdx = request.txIndices.getTrueIndices().filter((i)=>response.txIndices.isSet(i));
1233
+ // Enforce subset membership and preserve increasing order by index.
1234
+ const hashToIndexInProposal = new Map(proposal.txHashes.map((h, i)=>[
1235
+ h.toString(),
1236
+ i
1237
+ ]));
1238
+ const allowedIndexSet = new Set(intersectIdx);
1239
+ const indices = returnedHashes.map((h)=>hashToIndexInProposal.get(h));
1240
+ const allAllowed = indices.every((idx)=>idx !== undefined && allowedIndexSet.has(idx));
1241
+ const strictlyIncreasing = indices.every((idx, i)=>i === 0 ? idx !== undefined : idx > indices[i - 1]);
1242
+ if (!allAllowed || !strictlyIncreasing) {
1243
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
1244
+ throw new ValidationError('Returned txs do not match expected subset/order for requested indices');
1245
+ }
1246
+ } else {
1247
+ // No local proposal, cannot check the membership/order of the returned txs
1248
+ this.logger.warn(`Block proposal not found for block hash ${request.blockHash.toString()}; cannot validate membership/order of returned txs`);
1249
+ return false;
1250
+ }
1251
+ await Promise.all(response.txs.map((tx)=>this.validateRequestedTx(tx, peerId, requestedTxValidator)));
1252
+ return true;
1253
+ } catch (e) {
1254
+ if (e instanceof ValidationError) {
1255
+ this.logger.warn(`Failed validation for requested block txs from peer ${peerId.toString()}`);
1256
+ } else {
1257
+ this.logger.error(`Error during validation of requested block txs`, e);
1258
+ }
1259
+ return false;
1260
+ }
1261
+ }
1262
+ /**
652
1263
  * Validate a collection of txs that has been requested from a peer.
653
1264
  *
654
1265
  * The core component of this validator is that each tx hash MUST match the requested tx hash,
@@ -658,36 +1269,89 @@ import { P2PInstrumentation } from './instrumentation.js';
658
1269
  * ReqRespSubProtocol.TX subprotocol validation.
659
1270
  *
660
1271
  * @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.
1272
+ * @param responseTx - The collection of txs that was received as a response to the request.
662
1273
  * @param peerId - The peer ID of the peer that sent the tx.
663
1274
  * @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) {
1275
+ */ async validateRequestedTxs(requestedTxHash, responseTx, peerId) {
667
1276
  const requested = new Set(requestedTxHash.map((h)=>h.toString()));
668
- const proofValidator = new TxProofValidator(this.proofVerifier);
1277
+ const requestedTxValidator = this.createRequestedTxValidator();
1278
+ //TODO: (mralj) - this is somewhat naive implementation, if single tx is invlid we consider the whole response invalid.
1279
+ // I think we should still extract the valid txs and return them, so that we can still use the response.
669
1280
  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
- }));
1281
+ await Promise.all(responseTx.map((tx)=>this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
681
1282
  return true;
682
1283
  } catch (e) {
683
1284
  if (e instanceof ValidationError) {
684
- this.logger.debug(`Failed to validate requested txs from peer ${peerId.toString()}, reason ${e.message}`);
1285
+ this.logger.warn(`Failed to validate requested txs from peer ${peerId.toString()}, reason ${e.message}`);
685
1286
  } else {
686
- this.logger.warn(`Error during validation of requested txs`, e);
1287
+ this.logger.error(`Error during validation of requested txs`, e);
1288
+ }
1289
+ return false;
1290
+ }
1291
+ }
1292
+ /**
1293
+ * Validates a BLOCK response.
1294
+ *
1295
+ * If a local copy exists, enforces hash equality. If missing, rejects (no penalty) since the hash cannot be verified.
1296
+ * Penalizes on block number mismatch or hash mismatch.
1297
+ *
1298
+ * @param requestedBlockNumber - The requested block number.
1299
+ * @param responseBlock - The block returned by the peer.
1300
+ * @param peerId - The peer that returned the block.
1301
+ * @returns True if the response is valid, false otherwise.
1302
+ */ async validateRequestedBlock(requestedBlockNumber, responseBlock, peerId) {
1303
+ try {
1304
+ const reqNum = Number(requestedBlockNumber.toString());
1305
+ if (responseBlock.number !== reqNum) {
1306
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
1307
+ return false;
1308
+ }
1309
+ const local = await this.archiver.getBlock(BlockNumber(reqNum));
1310
+ if (!local) {
1311
+ // We are missing the local block; we cannot verify the hash yet. Reject without penalizing.
1312
+ // TODO: Consider extending this validator to accept an expected hash or
1313
+ // performing quorum-based checks when using P2P syncing prior to L1 sync.
1314
+ this.logger.warn(`Local block ${reqNum} not found; rejecting BLOCK response without hash verification`);
1315
+ return false;
1316
+ }
1317
+ const [localHash, respHash] = await Promise.all([
1318
+ local.hash(),
1319
+ responseBlock.hash()
1320
+ ]);
1321
+ if (!localHash.equals(respHash)) {
1322
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
1323
+ return false;
687
1324
  }
1325
+ return true;
1326
+ } catch (e) {
1327
+ this.logger.warn(`Error validating requested block`, e);
688
1328
  return false;
689
1329
  }
690
1330
  }
1331
+ createRequestedTxValidator() {
1332
+ return new AggregateTxValidator(new DataTxValidator(), new MetadataTxValidator({
1333
+ l1ChainId: new Fr(this.config.l1ChainId),
1334
+ rollupVersion: new Fr(this.config.rollupVersion),
1335
+ protocolContractsHash,
1336
+ vkTreeRoot: getVKTreeRoot()
1337
+ }), new TxProofValidator(this.proofVerifier));
1338
+ }
1339
+ async validateRequestedTx(tx, peerId, txValidator, requested) {
1340
+ const penalize = (severity)=>this.peerManager.penalizePeer(peerId, severity);
1341
+ if (!await tx.validateTxHash()) {
1342
+ penalize(PeerErrorSeverity.MidToleranceError);
1343
+ throw new ValidationError(`Received tx with invalid hash ${tx.getTxHash().toString()}.`);
1344
+ }
1345
+ if (requested && !requested.has(tx.getTxHash().toString())) {
1346
+ penalize(PeerErrorSeverity.MidToleranceError);
1347
+ throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
1348
+ }
1349
+ const { result } = await txValidator.validateTx(tx);
1350
+ if (result === 'invalid') {
1351
+ penalize(PeerErrorSeverity.LowToleranceError);
1352
+ throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that is invalid.`);
1353
+ }
1354
+ }
691
1355
  async validatePropagatedTx(tx, peerId) {
692
1356
  const currentBlockNumber = await this.archiver.getBlockNumber();
693
1357
  // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
@@ -702,7 +1366,7 @@ import { P2PInstrumentation } from './instrumentation.js';
702
1366
  let { severity } = outcome.failure;
703
1367
  // Double spend validator has a special case handler
704
1368
  if (name === 'doubleSpendValidator') {
705
- const txBlockNumber = currentBlockNumber + 1; // tx is expected to be in the next block
1369
+ const txBlockNumber = BlockNumber(currentBlockNumber + 1); // tx is expected to be in the next block
706
1370
  severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
707
1371
  }
708
1372
  this.peerManager.penalizePeer(peerId, severity);
@@ -752,8 +1416,8 @@ import { P2PInstrumentation } from './instrumentation.js';
752
1416
  */ async createMessageValidators(currentBlockNumber, nextSlotTimestamp) {
753
1417
  const gasFees = await this.getGasFees(currentBlockNumber);
754
1418
  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);
1419
+ const blockNumberInWhichTheTxIsConsideredToBeIncluded = BlockNumber(currentBlockNumber + 1);
1420
+ return createTxMessageValidators(nextSlotTimestamp, blockNumberInWhichTheTxIsConsideredToBeIncluded, this.worldStateSynchronizer, gasFees, this.config.l1ChainId, this.config.rollupVersion, protocolContractsHash, this.archiver, this.proofVerifier, !this.config.disableTransactions, allowedInSetup);
757
1421
  }
758
1422
  /**
759
1423
  * Run validations on a tx.
@@ -808,7 +1472,7 @@ import { P2PInstrumentation } from './instrumentation.js';
808
1472
  }
809
1473
  const snapshotValidator = new DoubleSpendTxValidator({
810
1474
  nullifiersExist: async (nullifiers)=>{
811
- const merkleTree = this.worldStateSynchronizer.getSnapshot(blockNumber - this.config.doubleSpendSeverePeerPenaltyWindow);
1475
+ const merkleTree = this.worldStateSynchronizer.getSnapshot(BlockNumber(blockNumber - this.config.doubleSpendSeverePeerPenaltyWindow));
812
1476
  const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
813
1477
  return indices.map((index)=>index !== undefined);
814
1478
  }
@@ -854,7 +1518,7 @@ import { P2PInstrumentation } from './instrumentation.js';
854
1518
  }
855
1519
  async sendToPeers(message) {
856
1520
  const parent = message.constructor;
857
- const identifier = await message.p2pMessageIdentifier().then((i)=>i.toString());
1521
+ const identifier = await message.p2pMessageLoggingIdentifier().then((i)=>i.toString());
858
1522
  this.logger.trace(`Sending message ${identifier}`, {
859
1523
  p2pMessageIdentifier: identifier
860
1524
  });
@@ -881,42 +1545,3 @@ import { P2PInstrumentation } from './instrumentation.js';
881
1545
  }
882
1546
  }
883
1547
  }
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);