@aztec/p2p 0.0.0-test.1 → 0.0.1-commit.5476d83

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 (385) 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 +22 -9
  4. package/dest/client/factory.d.ts +14 -4
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +60 -24
  7. package/dest/client/index.d.ts +2 -1
  8. package/dest/client/index.d.ts.map +1 -1
  9. package/dest/client/index.js +1 -0
  10. package/dest/client/interface.d.ts +157 -0
  11. package/dest/client/interface.d.ts.map +1 -0
  12. package/dest/client/interface.js +9 -0
  13. package/dest/client/p2p_client.d.ts +72 -187
  14. package/dest/client/p2p_client.d.ts.map +1 -1
  15. package/dest/client/p2p_client.js +373 -177
  16. package/dest/config.d.ts +151 -125
  17. package/dest/config.d.ts.map +1 -1
  18. package/dest/config.js +183 -34
  19. package/dest/enr/generate-enr.d.ts +11 -3
  20. package/dest/enr/generate-enr.d.ts.map +1 -1
  21. package/dest/enr/generate-enr.js +27 -5
  22. package/dest/enr/index.d.ts +1 -1
  23. package/dest/errors/attestation-pool.error.d.ts +7 -0
  24. package/dest/errors/attestation-pool.error.d.ts.map +1 -0
  25. package/dest/errors/attestation-pool.error.js +12 -0
  26. package/dest/errors/reqresp.error.d.ts +1 -1
  27. package/dest/errors/reqresp.error.d.ts.map +1 -1
  28. package/dest/index.d.ts +4 -1
  29. package/dest/index.d.ts.map +1 -1
  30. package/dest/index.js +2 -0
  31. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +68 -8
  32. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  33. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  34. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  35. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +214 -63
  36. package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
  37. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +21 -6
  38. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  39. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +126 -25
  40. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +19 -6
  41. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  42. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +111 -21
  43. package/dest/mem_pools/attestation_pool/mocks.d.ts +225 -5
  44. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  45. package/dest/mem_pools/attestation_pool/mocks.js +9 -15
  46. package/dest/mem_pools/index.d.ts +1 -1
  47. package/dest/mem_pools/instrumentation.d.ts +10 -12
  48. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  49. package/dest/mem_pools/instrumentation.js +35 -38
  50. package/dest/mem_pools/interface.d.ts +1 -1
  51. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +62 -13
  52. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  53. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +469 -97
  54. package/dest/mem_pools/tx_pool/index.d.ts +1 -1
  55. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +34 -10
  56. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
  57. package/dest/mem_pools/tx_pool/memory_tx_pool.js +133 -36
  58. package/dest/mem_pools/tx_pool/priority.d.ts +1 -1
  59. package/dest/mem_pools/tx_pool/priority.js +1 -1
  60. package/dest/mem_pools/tx_pool/tx_pool.d.ts +65 -9
  61. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  62. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  63. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  64. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +264 -39
  65. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -2
  66. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  67. package/dest/msg_validators/attestation_validator/attestation_validator.js +45 -9
  68. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
  69. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
  70. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +67 -0
  71. package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
  72. package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
  73. package/dest/msg_validators/attestation_validator/index.js +1 -0
  74. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +6 -2
  75. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
  76. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +73 -12
  77. package/dest/msg_validators/block_proposal_validator/index.d.ts +1 -1
  78. package/dest/msg_validators/index.d.ts +1 -1
  79. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +10 -0
  80. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
  81. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
  82. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
  83. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  84. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +3 -0
  85. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
  86. package/dest/msg_validators/tx_validator/allowed_public_setup.js +27 -0
  87. package/dest/msg_validators/tx_validator/archive_cache.d.ts +14 -0
  88. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -0
  89. package/dest/msg_validators/tx_validator/archive_cache.js +22 -0
  90. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +1 -1
  91. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  92. package/dest/msg_validators/tx_validator/block_header_validator.js +4 -4
  93. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  94. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  95. package/dest/msg_validators/tx_validator/data_validator.js +56 -86
  96. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +1 -3
  97. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  98. package/dest/msg_validators/tx_validator/double_spend_validator.js +21 -27
  99. package/dest/msg_validators/tx_validator/factory.d.ts +15 -0
  100. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
  101. package/dest/msg_validators/tx_validator/factory.js +74 -0
  102. package/dest/msg_validators/tx_validator/gas_validator.d.ts +11 -0
  103. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
  104. package/dest/msg_validators/tx_validator/gas_validator.js +115 -0
  105. package/dest/msg_validators/tx_validator/index.d.ts +8 -1
  106. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  107. package/dest/msg_validators/tx_validator/index.js +7 -0
  108. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +8 -4
  109. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  110. package/dest/msg_validators/tx_validator/metadata_validator.js +39 -20
  111. package/dest/msg_validators/tx_validator/phases_validator.d.ts +14 -0
  112. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
  113. package/dest/msg_validators/tx_validator/phases_validator.js +93 -0
  114. package/dest/msg_validators/tx_validator/test_utils.d.ts +17 -0
  115. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
  116. package/dest/msg_validators/tx_validator/test_utils.js +22 -0
  117. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +12 -0
  118. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
  119. package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
  120. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +8 -0
  121. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -0
  122. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +24 -0
  123. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +1 -1
  124. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  125. package/dest/msg_validators/tx_validator/tx_proof_validator.js +6 -5
  126. package/dest/services/data_store.d.ts +1 -1
  127. package/dest/services/data_store.d.ts.map +1 -1
  128. package/dest/services/discv5/discV5_service.d.ts +10 -9
  129. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  130. package/dest/services/discv5/discV5_service.js +63 -36
  131. package/dest/services/dummy_service.d.ts +50 -11
  132. package/dest/services/dummy_service.d.ts.map +1 -1
  133. package/dest/services/dummy_service.js +88 -5
  134. package/dest/services/encoding.d.ts +26 -7
  135. package/dest/services/encoding.d.ts.map +1 -1
  136. package/dest/services/encoding.js +73 -5
  137. package/dest/services/gossipsub/scoring.d.ts +1 -1
  138. package/dest/services/index.d.ts +5 -1
  139. package/dest/services/index.d.ts.map +1 -1
  140. package/dest/services/index.js +4 -0
  141. package/dest/services/libp2p/instrumentation.d.ts +20 -0
  142. package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
  143. package/dest/services/libp2p/instrumentation.js +164 -0
  144. package/dest/services/libp2p/libp2p_service.d.ts +78 -89
  145. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  146. package/dest/services/libp2p/libp2p_service.js +698 -246
  147. package/dest/services/peer-manager/interface.d.ts +23 -0
  148. package/dest/services/peer-manager/interface.d.ts.map +1 -0
  149. package/dest/services/peer-manager/interface.js +1 -0
  150. package/dest/services/peer-manager/metrics.d.ts +6 -2
  151. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  152. package/dest/services/peer-manager/metrics.js +22 -2
  153. package/dest/services/peer-manager/peer_manager.d.ts +102 -22
  154. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  155. package/dest/services/peer-manager/peer_manager.js +549 -72
  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 +11 -9
  160. package/dest/services/reqresp/config.d.ts.map +1 -1
  161. package/dest/services/reqresp/config.js +18 -4
  162. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +2 -2
  163. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  164. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +10 -6
  165. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +31 -17
  166. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  167. package/dest/services/reqresp/connection-sampler/connection_sampler.js +142 -84
  168. package/dest/services/reqresp/index.d.ts +3 -2
  169. package/dest/services/reqresp/index.d.ts.map +1 -1
  170. package/dest/services/reqresp/index.js +2 -1
  171. package/dest/services/reqresp/interface.d.ts +73 -24
  172. package/dest/services/reqresp/interface.d.ts.map +1 -1
  173. package/dest/services/reqresp/interface.js +45 -26
  174. package/dest/services/reqresp/metrics.d.ts +1 -1
  175. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  176. package/dest/services/reqresp/protocols/auth.d.ts +43 -0
  177. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
  178. package/dest/services/reqresp/protocols/auth.js +71 -0
  179. package/dest/services/reqresp/protocols/block.d.ts +6 -1
  180. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  181. package/dest/services/reqresp/protocols/block.js +28 -5
  182. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +30 -0
  183. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
  184. package/dest/services/reqresp/protocols/block_txs/bitvector.js +75 -0
  185. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
  186. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
  187. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +39 -0
  188. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +47 -0
  189. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
  190. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
  191. package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
  192. package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
  193. package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
  194. package/dest/services/reqresp/protocols/goodbye.d.ts +3 -5
  195. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
  196. package/dest/services/reqresp/protocols/goodbye.js +7 -7
  197. package/dest/services/reqresp/protocols/index.d.ts +3 -1
  198. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  199. package/dest/services/reqresp/protocols/index.js +2 -0
  200. package/dest/services/reqresp/protocols/ping.d.ts +1 -3
  201. package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
  202. package/dest/services/reqresp/protocols/status.d.ts +39 -7
  203. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  204. package/dest/services/reqresp/protocols/status.js +72 -5
  205. package/dest/services/reqresp/protocols/tx.d.ts +13 -2
  206. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  207. package/dest/services/reqresp/protocols/tx.js +34 -6
  208. package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
  209. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +6 -4
  210. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  211. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
  212. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  213. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  214. package/dest/services/reqresp/rate-limiter/rate_limits.js +21 -1
  215. package/dest/services/reqresp/reqresp.d.ts +24 -66
  216. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  217. package/dest/services/reqresp/reqresp.js +298 -207
  218. package/dest/services/reqresp/status.d.ts +10 -4
  219. package/dest/services/reqresp/status.d.ts.map +1 -1
  220. package/dest/services/reqresp/status.js +9 -2
  221. package/dest/services/service.d.ts +23 -19
  222. package/dest/services/service.d.ts.map +1 -1
  223. package/dest/services/tx_collection/config.d.ts +25 -0
  224. package/dest/services/tx_collection/config.d.ts.map +1 -0
  225. package/dest/services/tx_collection/config.js +58 -0
  226. package/dest/services/tx_collection/fast_tx_collection.d.ts +50 -0
  227. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
  228. package/dest/services/tx_collection/fast_tx_collection.js +300 -0
  229. package/dest/services/tx_collection/index.d.ts +3 -0
  230. package/dest/services/tx_collection/index.d.ts.map +1 -0
  231. package/dest/services/tx_collection/index.js +2 -0
  232. package/dest/services/tx_collection/instrumentation.d.ts +10 -0
  233. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
  234. package/dest/services/tx_collection/instrumentation.js +34 -0
  235. package/dest/services/tx_collection/slow_tx_collection.d.ts +52 -0
  236. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
  237. package/dest/services/tx_collection/slow_tx_collection.js +177 -0
  238. package/dest/services/tx_collection/tx_collection.d.ts +109 -0
  239. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
  240. package/dest/services/tx_collection/tx_collection.js +128 -0
  241. package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
  242. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
  243. package/dest/services/tx_collection/tx_collection_sink.js +111 -0
  244. package/dest/services/tx_collection/tx_source.d.ts +18 -0
  245. package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
  246. package/dest/services/tx_collection/tx_source.js +31 -0
  247. package/dest/services/tx_provider.d.ts +49 -0
  248. package/dest/services/tx_provider.d.ts.map +1 -0
  249. package/dest/services/tx_provider.js +210 -0
  250. package/dest/services/tx_provider_instrumentation.d.ts +13 -0
  251. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
  252. package/dest/services/tx_provider_instrumentation.js +34 -0
  253. package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
  254. package/dest/test-helpers/get-ports.d.ts +1 -1
  255. package/dest/test-helpers/get-ports.d.ts.map +1 -1
  256. package/dest/test-helpers/index.d.ts +2 -1
  257. package/dest/test-helpers/index.d.ts.map +1 -1
  258. package/dest/test-helpers/index.js +1 -0
  259. package/dest/test-helpers/make-enrs.d.ts +1 -1
  260. package/dest/test-helpers/make-enrs.d.ts.map +1 -1
  261. package/dest/test-helpers/make-enrs.js +4 -5
  262. package/dest/test-helpers/make-test-p2p-clients.d.ts +33 -5
  263. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  264. package/dest/test-helpers/make-test-p2p-clients.js +86 -16
  265. package/dest/test-helpers/mock-pubsub.d.ts +59 -0
  266. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
  267. package/dest/test-helpers/mock-pubsub.js +130 -0
  268. package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
  269. package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
  270. package/dest/test-helpers/mock-tx-helpers.js +19 -0
  271. package/dest/test-helpers/reqresp-nodes.d.ts +15 -11
  272. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  273. package/dest/test-helpers/reqresp-nodes.js +62 -28
  274. package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
  275. package/dest/testbench/p2p_client_testbench_worker.js +103 -29
  276. package/dest/testbench/parse_log_file.d.ts +1 -1
  277. package/dest/testbench/parse_log_file.js +4 -4
  278. package/dest/testbench/testbench.d.ts +1 -1
  279. package/dest/testbench/testbench.js +4 -4
  280. package/dest/testbench/worker_client_manager.d.ts +1 -6
  281. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  282. package/dest/testbench/worker_client_manager.js +11 -19
  283. package/dest/types/index.d.ts +4 -2
  284. package/dest/types/index.d.ts.map +1 -1
  285. package/dest/types/index.js +2 -0
  286. package/dest/util.d.ts +24 -16
  287. package/dest/util.d.ts.map +1 -1
  288. package/dest/util.js +75 -69
  289. package/dest/versioning.d.ts +4 -4
  290. package/dest/versioning.d.ts.map +1 -1
  291. package/dest/versioning.js +8 -3
  292. package/package.json +32 -27
  293. package/src/bootstrap/bootstrap.ts +27 -11
  294. package/src/client/factory.ts +136 -45
  295. package/src/client/index.ts +1 -0
  296. package/src/client/interface.ts +198 -0
  297. package/src/client/p2p_client.ts +469 -330
  298. package/src/config.ts +305 -134
  299. package/src/enr/generate-enr.ts +39 -6
  300. package/src/errors/attestation-pool.error.ts +13 -0
  301. package/src/index.ts +4 -0
  302. package/src/mem_pools/attestation_pool/attestation_pool.ts +75 -7
  303. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +264 -65
  304. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +173 -34
  305. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +156 -30
  306. package/src/mem_pools/attestation_pool/mocks.ts +11 -10
  307. package/src/mem_pools/instrumentation.ts +43 -44
  308. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +549 -108
  309. package/src/mem_pools/tx_pool/memory_tx_pool.ts +153 -44
  310. package/src/mem_pools/tx_pool/priority.ts +1 -1
  311. package/src/mem_pools/tx_pool/tx_pool.ts +67 -8
  312. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +217 -34
  313. package/src/msg_validators/attestation_validator/attestation_validator.ts +54 -11
  314. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +91 -0
  315. package/src/msg_validators/attestation_validator/index.ts +1 -0
  316. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +82 -14
  317. package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
  318. package/src/msg_validators/tx_validator/allowed_public_setup.ts +35 -0
  319. package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
  320. package/src/msg_validators/tx_validator/block_header_validator.ts +4 -4
  321. package/src/msg_validators/tx_validator/data_validator.ts +81 -69
  322. package/src/msg_validators/tx_validator/double_spend_validator.ts +19 -17
  323. package/src/msg_validators/tx_validator/factory.ts +109 -0
  324. package/src/msg_validators/tx_validator/gas_validator.ts +134 -0
  325. package/src/msg_validators/tx_validator/index.ts +7 -0
  326. package/src/msg_validators/tx_validator/metadata_validator.ts +58 -21
  327. package/src/msg_validators/tx_validator/phases_validator.ts +116 -0
  328. package/src/msg_validators/tx_validator/test_utils.ts +43 -0
  329. package/src/msg_validators/tx_validator/timestamp_validator.ts +46 -0
  330. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +17 -0
  331. package/src/msg_validators/tx_validator/tx_proof_validator.ts +6 -5
  332. package/src/services/discv5/discV5_service.ts +84 -38
  333. package/src/services/dummy_service.ts +147 -9
  334. package/src/services/encoding.ts +80 -5
  335. package/src/services/index.ts +4 -0
  336. package/src/services/libp2p/instrumentation.ts +167 -0
  337. package/src/services/libp2p/libp2p_service.ts +866 -294
  338. package/src/services/peer-manager/interface.ts +29 -0
  339. package/src/services/peer-manager/metrics.ts +26 -1
  340. package/src/services/peer-manager/peer_manager.ts +654 -78
  341. package/src/services/peer-manager/peer_scoring.ts +46 -3
  342. package/src/services/reqresp/config.ts +26 -9
  343. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +12 -6
  344. package/src/services/reqresp/connection-sampler/connection_sampler.ts +148 -95
  345. package/src/services/reqresp/index.ts +2 -0
  346. package/src/services/reqresp/interface.ts +91 -36
  347. package/src/services/reqresp/metrics.ts +4 -1
  348. package/src/services/reqresp/protocols/auth.ts +83 -0
  349. package/src/services/reqresp/protocols/block.ts +24 -3
  350. package/src/services/reqresp/protocols/block_txs/bitvector.ts +90 -0
  351. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +53 -0
  352. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +79 -0
  353. package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
  354. package/src/services/reqresp/protocols/goodbye.ts +9 -7
  355. package/src/services/reqresp/protocols/index.ts +2 -0
  356. package/src/services/reqresp/protocols/status.ts +117 -5
  357. package/src/services/reqresp/protocols/tx.ts +35 -6
  358. package/src/services/reqresp/rate-limiter/rate_limiter.ts +12 -3
  359. package/src/services/reqresp/rate-limiter/rate_limits.ts +21 -1
  360. package/src/services/reqresp/reqresp.ts +387 -256
  361. package/src/services/reqresp/status.ts +12 -3
  362. package/src/services/service.ts +45 -21
  363. package/src/services/tx_collection/config.ts +84 -0
  364. package/src/services/tx_collection/fast_tx_collection.ts +340 -0
  365. package/src/services/tx_collection/index.ts +2 -0
  366. package/src/services/tx_collection/instrumentation.ts +43 -0
  367. package/src/services/tx_collection/slow_tx_collection.ts +233 -0
  368. package/src/services/tx_collection/tx_collection.ts +215 -0
  369. package/src/services/tx_collection/tx_collection_sink.ts +129 -0
  370. package/src/services/tx_collection/tx_source.ts +37 -0
  371. package/src/services/tx_provider.ts +216 -0
  372. package/src/services/tx_provider_instrumentation.ts +44 -0
  373. package/src/test-helpers/index.ts +1 -0
  374. package/src/test-helpers/make-enrs.ts +4 -5
  375. package/src/test-helpers/make-test-p2p-clients.ts +111 -21
  376. package/src/test-helpers/mock-pubsub.ts +188 -0
  377. package/src/test-helpers/mock-tx-helpers.ts +24 -0
  378. package/src/test-helpers/reqresp-nodes.ts +86 -35
  379. package/src/testbench/p2p_client_testbench_worker.ts +151 -25
  380. package/src/testbench/parse_log_file.ts +4 -4
  381. package/src/testbench/testbench.ts +4 -4
  382. package/src/testbench/worker_client_manager.ts +17 -23
  383. package/src/types/index.ts +2 -0
  384. package/src/util.ts +105 -91
  385. package/src/versioning.ts +11 -4
@@ -4,13 +4,19 @@ function _ts_decorate(decorators, target, key, desc) {
4
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
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  }
7
+ import { SlotNumber } from '@aztec/foundation/branded-types';
8
+ import { randomInt } from '@aztec/foundation/crypto';
7
9
  import { Fr } from '@aztec/foundation/fields';
8
10
  import { createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
9
- import { SerialQueue } from '@aztec/foundation/queue';
10
11
  import { RunningPromise } from '@aztec/foundation/running-promise';
11
- import { BlockAttestation, BlockProposal, P2PClientType, PeerErrorSeverity, TopicTypeMap, getTopicTypeForClientType, metricsTopicStrToLabels } from '@aztec/stdlib/p2p';
12
+ import { Timer } from '@aztec/foundation/timer';
13
+ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
14
+ import { protocolContractsHash } from '@aztec/protocol-contracts';
15
+ import { GasFees } from '@aztec/stdlib/gas';
16
+ import { BlockAttestation, BlockProposal, P2PClientType, P2PMessage, PeerErrorSeverity, TopicType, createTopicString, getTopicsForClientAndConfig, metricsTopicStrToLabels } from '@aztec/stdlib/p2p';
12
17
  import { MerkleTreeId } from '@aztec/stdlib/trees';
13
18
  import { Tx } from '@aztec/stdlib/tx';
19
+ import { compressComponentVersions } from '@aztec/stdlib/versioning';
14
20
  import { Attributes, OtelMetricsAdapter, WithTracer, trackSpan } from '@aztec/telemetry-client';
15
21
  import { gossipsub } from '@chainsafe/libp2p-gossipsub';
16
22
  import { createPeerScoreParams, createTopicScoreParams } from '@chainsafe/libp2p-gossipsub/score';
@@ -20,23 +26,31 @@ import { yamux } from '@chainsafe/libp2p-yamux';
20
26
  import { bootstrap } from '@libp2p/bootstrap';
21
27
  import { identify } from '@libp2p/identify';
22
28
  import { TopicValidatorResult } from '@libp2p/interface';
23
- import '@libp2p/kad-dht';
24
29
  import { mplex } from '@libp2p/mplex';
25
30
  import { tcp } from '@libp2p/tcp';
31
+ import { ENR } from '@nethermindeth/enr';
26
32
  import { createLibp2p } from 'libp2p';
27
- import { AttestationValidator, BlockProposalValidator } from '../../msg_validators/index.js';
28
- import { DataTxValidator, DoubleSpendTxValidator, MetadataTxValidator, TxProofValidator } from '../../msg_validators/tx_validator/index.js';
33
+ import { ProposalSlotCapExceededError } from '../../errors/attestation-pool.error.js';
34
+ import { AttestationValidator, BlockProposalValidator, FishermanAttestationValidator } from '../../msg_validators/index.js';
35
+ import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
36
+ import { getDefaultAllowedSetupFunctions } from '../../msg_validators/tx_validator/allowed_public_setup.js';
37
+ import { createTxMessageValidators } from '../../msg_validators/tx_validator/factory.js';
38
+ import { AggregateTxValidator, DataTxValidator, DoubleSpendTxValidator, MetadataTxValidator, TxProofValidator } from '../../msg_validators/tx_validator/index.js';
29
39
  import { GossipSubEvent } from '../../types/index.js';
30
40
  import { convertToMultiaddr } from '../../util.js';
41
+ import { getVersions } from '../../versioning.js';
31
42
  import { AztecDatastore } from '../data_store.js';
43
+ import { DiscV5Service } from '../discv5/discV5_service.js';
32
44
  import { SnappyTransform, fastMsgIdFn, getMsgIdFn, msgIdToStrFn } from '../encoding.js';
33
45
  import { gossipScoreThresholds } from '../gossipsub/scoring.js';
34
46
  import { PeerManager } from '../peer-manager/peer_manager.js';
35
47
  import { PeerScoring } from '../peer-manager/peer_scoring.js';
36
- import { DEFAULT_SUB_PROTOCOL_VALIDATORS, ReqRespSubProtocol } from '../reqresp/interface.js';
48
+ import { DEFAULT_SUB_PROTOCOL_VALIDATORS, ReqRespSubProtocol, ValidationError } from '../reqresp/interface.js';
49
+ import { reqRespBlockTxsHandler } from '../reqresp/protocols/block_txs/block_txs_handler.js';
37
50
  import { reqGoodbyeHandler } from '../reqresp/protocols/goodbye.js';
38
- import { pingHandler, reqRespBlockHandler, reqRespTxHandler, statusHandler } from '../reqresp/protocols/index.js';
51
+ import { pingHandler, reqRespBlockHandler, reqRespStatusHandler, reqRespTxHandler } from '../reqresp/protocols/index.js';
39
52
  import { ReqResp } from '../reqresp/reqresp.js';
53
+ import { P2PInstrumentation } from './instrumentation.js';
40
54
  /**
41
55
  * Lib P2P implementation of the P2PService interface.
42
56
  */ export class LibP2PService extends WithTracer {
@@ -44,62 +58,104 @@ import { ReqResp } from '../reqresp/reqresp.js';
44
58
  config;
45
59
  node;
46
60
  peerDiscoveryService;
61
+ reqresp;
62
+ peerManager;
47
63
  mempools;
48
- l2BlockSource;
64
+ archiver;
65
+ epochCache;
49
66
  proofVerifier;
50
67
  worldStateSynchronizer;
51
- logger;
52
- jobQueue;
53
- peerManager;
54
68
  discoveryRunningPromise;
69
+ msgIdSeenValidators;
55
70
  // Message validators
56
71
  attestationValidator;
57
72
  blockProposalValidator;
58
- // Request and response sub service
59
- reqresp;
73
+ protocolVersion;
74
+ topicStrings;
75
+ feesCache;
60
76
  /**
61
77
  * Callback for when a block is received from a peer.
62
78
  * @param block - The block received from the peer.
63
79
  * @returns The attestation for the block, if any.
64
80
  */ blockReceivedCallback;
65
- constructor(clientType, config, node, peerDiscoveryService, mempools, l2BlockSource, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger = createLogger('p2p:libp2p_service')){
66
- super(telemetry, 'LibP2PService'), this.clientType = clientType, this.config = config, this.node = node, this.peerDiscoveryService = peerDiscoveryService, this.mempools = mempools, this.l2BlockSource = l2BlockSource, this.proofVerifier = proofVerifier, this.worldStateSynchronizer = worldStateSynchronizer, this.logger = logger, this.jobQueue = new SerialQueue();
67
- const peerScoring = new PeerScoring(config);
68
- this.reqresp = new ReqResp(config, node, peerScoring);
69
- this.peerManager = new PeerManager(node, peerDiscoveryService, config, telemetry, createLogger(`${logger.module}:peer_manager`), peerScoring, this.reqresp);
70
- // Update gossipsub score params
71
- this.node.services.pubsub.score.params.appSpecificScore = (peerId)=>{
72
- return this.peerManager.getPeerScore(peerId);
73
- };
74
- this.node.services.pubsub.score.params.appSpecificWeight = 10;
75
- this.attestationValidator = new AttestationValidator(epochCache);
76
- this.blockProposalValidator = new BlockProposalValidator(epochCache);
81
+ gossipSubEventHandler;
82
+ instrumentation;
83
+ logger;
84
+ constructor(clientType, config, node, peerDiscoveryService, reqresp, peerManager, mempools, archiver, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger = createLogger('p2p:libp2p_service')){
85
+ 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 = {}, this.protocolVersion = '', this.topicStrings = {};
86
+ // Create child logger with fisherman prefix if in fisherman mode
87
+ this.logger = config.fishermanMode ? logger.createChild('[FISHERMAN]') : logger;
88
+ this.instrumentation = new P2PInstrumentation(telemetry, 'LibP2PService');
89
+ this.msgIdSeenValidators[TopicType.tx] = new MessageSeenValidator(config.seenMessageCacheSize);
90
+ this.msgIdSeenValidators[TopicType.block_proposal] = new MessageSeenValidator(config.seenMessageCacheSize);
91
+ this.msgIdSeenValidators[TopicType.block_attestation] = new MessageSeenValidator(config.seenMessageCacheSize);
92
+ const versions = getVersions(config);
93
+ this.protocolVersion = compressComponentVersions(versions);
94
+ logger.info(`Started libp2p service with protocol version ${this.protocolVersion}`);
95
+ this.topicStrings[TopicType.tx] = createTopicString(TopicType.tx, this.protocolVersion);
96
+ this.topicStrings[TopicType.block_proposal] = createTopicString(TopicType.block_proposal, this.protocolVersion);
97
+ this.topicStrings[TopicType.block_attestation] = createTopicString(TopicType.block_attestation, this.protocolVersion);
98
+ // Use FishermanAttestationValidator in fisherman mode to validate attestation payloads against proposals
99
+ this.attestationValidator = config.fishermanMode ? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry) : new AttestationValidator(epochCache);
100
+ this.blockProposalValidator = new BlockProposalValidator(epochCache, {
101
+ txsPermitted: !config.disableTransactions
102
+ });
103
+ this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
77
104
  this.blockReceivedCallback = async (block)=>{
78
- this.logger.debug(`Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber.toNumber()} from peer.`, {
79
- p2pMessageIdentifier: await block.p2pMessageIdentifier()
105
+ this.logger.debug(`Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber} from peer.`, {
106
+ p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier()
80
107
  });
81
108
  return undefined;
82
109
  };
83
110
  }
111
+ updateConfig(config) {
112
+ this.reqresp.updateConfig(config);
113
+ }
84
114
  /**
85
115
  * Creates an instance of the LibP2P service.
86
116
  * @param config - The configuration to use when creating the service.
87
117
  * @param txPool - The transaction pool to be accessed by the service.
88
118
  * @returns The new service.
89
- */ static async new(clientType, config, peerDiscoveryService, peerId, mempools, l2BlockSource, epochCache, proofVerifier, worldStateSynchronizer, store, telemetry, logger = createLogger('p2p:libp2p_service')) {
90
- const { tcpListenAddress, tcpAnnounceAddress, maxPeerCount } = config;
91
- const bindAddrTcp = convertToMultiaddr(tcpListenAddress, 'tcp');
92
- // We know tcpAnnounceAddress cannot be null here because we set it or throw when setting up the service.
93
- const announceAddrTcp = convertToMultiaddr(tcpAnnounceAddress, 'tcp');
94
- const datastore = new AztecDatastore(store);
119
+ */ static async new(clientType, config, peerId, deps) {
120
+ const { worldStateSynchronizer, epochCache, l2BlockSource, mempools, proofVerifier, peerStore, telemetry, logger, packageVersion } = deps;
121
+ const { p2pPort, maxPeerCount, listenAddress } = config;
122
+ const bindAddrTcp = convertToMultiaddr(listenAddress, p2pPort, 'tcp');
123
+ const datastore = new AztecDatastore(peerStore);
95
124
  const otelMetricsAdapter = new OtelMetricsAdapter(telemetry);
96
- // If bootstrap nodes are provided, also provide them to the p2p service
125
+ const peerDiscoveryService = new DiscV5Service(peerId, config, packageVersion, telemetry, createLogger(`${logger.module}:discv5_service`));
126
+ // Seed libp2p's bootstrap discovery with private and trusted peers
127
+ const bootstrapNodes = [
128
+ ...config.privatePeers,
129
+ ...config.trustedPeers
130
+ ];
97
131
  const peerDiscovery = [];
98
- if (peerDiscoveryService.bootstrapNodes.length > 0) {
132
+ if (bootstrapNodes.length > 0) {
99
133
  peerDiscovery.push(bootstrap({
100
- list: peerDiscoveryService.bootstrapNodes
134
+ list: bootstrapNodes
101
135
  }));
102
136
  }
137
+ const versions = getVersions(config);
138
+ const protocolVersion = compressComponentVersions(versions);
139
+ const txTopic = createTopicString(TopicType.tx, protocolVersion);
140
+ const blockProposalTopic = createTopicString(TopicType.block_proposal, protocolVersion);
141
+ const blockAttestationTopic = createTopicString(TopicType.block_attestation, protocolVersion);
142
+ const preferredPeersEnrs = config.preferredPeers.map((enr)=>ENR.decodeTxt(enr));
143
+ const directPeers = (await Promise.all(preferredPeersEnrs.map(async (enr)=>{
144
+ const peerId = await enr.peerId();
145
+ const address = enr.getLocationMultiaddr('tcp');
146
+ if (address === undefined) {
147
+ throw new Error(`Direct peer ${peerId.toString()} has no TCP address, ENR: ${enr.encodeTxt()}`);
148
+ }
149
+ return {
150
+ id: peerId,
151
+ addrs: [
152
+ address
153
+ ]
154
+ };
155
+ }))).filter((peer)=>peer !== undefined);
156
+ const announceTcpMultiaddr = config.p2pIp ? [
157
+ convertToMultiaddr(config.p2pIp, p2pPort, 'tcp')
158
+ ] : [];
103
159
  const node = await createLibp2p({
104
160
  start: false,
105
161
  peerId,
@@ -107,44 +163,76 @@ import { ReqResp } from '../reqresp/reqresp.js';
107
163
  listen: [
108
164
  bindAddrTcp
109
165
  ],
110
- announce: [
111
- announceAddrTcp
112
- ]
166
+ announce: announceTcpMultiaddr
113
167
  },
114
168
  transports: [
115
169
  tcp({
116
- maxConnections: config.maxPeerCount,
170
+ // It's better to have this number a bit higher than our maxPeerCount because it's sets the limit on transport (TCP) layer
171
+ // 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
172
+ // If we hit the limit, the connection will be temporarily accepted and immediately dropped.
173
+ // Docs: https://nodejs.org/api/net.html#servermaxconnections
174
+ maxConnections: maxPeerCount * 2,
117
175
  // socket option: the maximum length of the queue of pending connections
118
- // https://nodejs.org/dist/latest-v18.x/docs/api/net.html#serverlisten
176
+ // https://nodejs.org/dist/latest-v22.x/docs/api/net.html#serverlisten
119
177
  // it's not safe if we increase this number
120
178
  backlog: 5,
121
179
  closeServerOnMaxConnections: {
122
- closeAbove: maxPeerCount ?? Infinity,
123
- listenBelow: maxPeerCount ?? Infinity
180
+ // The property `maxConnections` will protect us against the most DDOS attack
181
+ // This property protects us in case of burst of new connections where server is not able to close them quickly enough
182
+ // In case closeAbove is reached, the server stops listening altogether
183
+ // It's important that there is enough difference between closeAbove and listenAbove,
184
+ // otherwise the server.listener will flap between being closed and open potentially degrading perf even more
185
+ closeAbove: maxPeerCount * 3,
186
+ listenBelow: Math.floor(maxPeerCount * 0.9)
124
187
  }
125
188
  })
126
189
  ],
127
190
  datastore,
128
191
  peerDiscovery,
129
192
  streamMuxers: [
130
- mplex(),
131
- yamux()
193
+ yamux(),
194
+ mplex()
132
195
  ],
133
196
  connectionEncryption: [
134
197
  noise()
135
198
  ],
136
199
  connectionManager: {
137
200
  minConnections: 0,
201
+ // We set maxConnections above maxPeerCount because if we hit limit of maxPeerCount
202
+ // libp2p will start aggressively rejecting all new connections, preventing network discovery and crawling.
203
+ maxConnections: maxPeerCount * 2,
138
204
  maxParallelDials: 100,
139
205
  dialTimeout: 30_000,
140
206
  maxPeerAddrsToDial: 5,
141
207
  maxIncomingPendingConnections: 5
142
208
  },
209
+ connectionGater: {
210
+ denyInboundConnection: (maConn)=>{
211
+ const allowed = peerManager.isNodeAllowedToConnect(maConn.remoteAddr.nodeAddress().address);
212
+ if (allowed) {
213
+ return false;
214
+ }
215
+ logger.debug(`Connection gater: Denying inbound connection from ${maConn.remoteAddr.toString()}`);
216
+ return true;
217
+ },
218
+ denyInboundEncryptedConnection: (peerId, _maConn)=>{
219
+ //NOTE: it is not necessary to check address here because this was already done by
220
+ // denyInboundConnection
221
+ const allowed = peerManager.isNodeAllowedToConnect(peerId);
222
+ if (allowed) {
223
+ return false;
224
+ }
225
+ logger.debug(`Connection gater: Denying inbound encrypted connection from ${peerId.toString()}`);
226
+ return true;
227
+ }
228
+ },
143
229
  services: {
144
230
  identify: identify({
145
- protocolPrefix: 'aztec'
231
+ protocolPrefix: 'aztec',
232
+ runOnConnectionOpen: true
146
233
  }),
147
234
  pubsub: gossipsub({
235
+ directPeers,
148
236
  debugName: 'gossipsub',
149
237
  globalSignaturePolicy: SignaturePolicy.StrictNoSign,
150
238
  allowPublishToZeroTopicPeers: true,
@@ -156,29 +244,30 @@ import { ReqResp } from '../reqresp/reqresp.js';
156
244
  heartbeatInterval: config.gossipsubInterval,
157
245
  mcacheLength: config.gossipsubMcacheLength,
158
246
  mcacheGossip: config.gossipsubMcacheGossip,
247
+ seenTTL: config.gossipsubSeenTTL,
159
248
  msgIdFn: getMsgIdFn,
160
249
  msgIdToStrFn: msgIdToStrFn,
161
250
  fastMsgIdFn: fastMsgIdFn,
162
251
  dataTransform: new SnappyTransform(),
163
252
  metricsRegister: otelMetricsAdapter,
164
- metricsTopicStrToLabel: metricsTopicStrToLabels(),
253
+ metricsTopicStrToLabel: metricsTopicStrToLabels(protocolVersion),
165
254
  asyncValidation: true,
166
255
  scoreThresholds: gossipScoreThresholds,
167
256
  scoreParams: createPeerScoreParams({
168
257
  // IPColocation factor can be disabled for local testing - default to -5
169
258
  IPColocationFactorWeight: config.debugDisableColocationPenalty ? 0 : -5.0,
170
259
  topics: {
171
- [Tx.p2pTopic]: createTopicScoreParams({
260
+ [txTopic]: createTopicScoreParams({
172
261
  topicWeight: 1,
173
262
  invalidMessageDeliveriesWeight: -20,
174
263
  invalidMessageDeliveriesDecay: 0.5
175
264
  }),
176
- [BlockAttestation.p2pTopic]: createTopicScoreParams({
265
+ [blockAttestationTopic]: createTopicScoreParams({
177
266
  topicWeight: 1,
178
267
  invalidMessageDeliveriesWeight: -20,
179
268
  invalidMessageDeliveriesDecay: 0.5
180
269
  }),
181
- [BlockProposal.p2pTopic]: createTopicScoreParams({
270
+ [blockProposalTopic]: createTopicScoreParams({
182
271
  topicWeight: 1,
183
272
  invalidMessageDeliveriesWeight: -20,
184
273
  invalidMessageDeliveriesDecay: 0.5
@@ -192,7 +281,13 @@ import { ReqResp } from '../reqresp/reqresp.js';
192
281
  },
193
282
  logger: createLibp2pComponentLogger(logger.module)
194
283
  });
195
- return new LibP2PService(clientType, config, node, peerDiscoveryService, mempools, l2BlockSource, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger);
284
+ const peerScoring = new PeerScoring(config, telemetry);
285
+ const reqresp = new ReqResp(config, node, peerScoring, createLogger(`${logger.module}:reqresp`));
286
+ const peerManager = new PeerManager(node, peerDiscoveryService, config, telemetry, createLogger(`${logger.module}:peer_manager`), peerScoring, reqresp, worldStateSynchronizer, protocolVersion, epochCache);
287
+ // Update gossipsub score params
288
+ node.services.pubsub.score.params.appSpecificWeight = 10;
289
+ node.services.pubsub.score.params.appSpecificScore = (peerId)=>peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
290
+ return new LibP2PService(clientType, config, node, peerDiscoveryService, reqresp, peerManager, mempools, l2BlockSource, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger);
196
291
  }
197
292
  /**
198
293
  * Starts the LibP2P service.
@@ -203,44 +298,57 @@ import { ReqResp } from '../reqresp/reqresp.js';
203
298
  throw new Error('P2P service already started');
204
299
  }
205
300
  // Get listen & announce addresses for logging
206
- const { tcpListenAddress, tcpAnnounceAddress } = this.config;
207
- if (!tcpAnnounceAddress) {
301
+ const { p2pIp, p2pPort } = this.config;
302
+ if (!p2pIp) {
208
303
  throw new Error('Announce address not provided.');
209
304
  }
210
- const announceTcpMultiaddr = convertToMultiaddr(tcpAnnounceAddress, 'tcp');
211
- // Start job queue, peer discovery service and libp2p node
212
- this.jobQueue.start();
213
- await this.peerDiscoveryService.start();
305
+ const announceTcpMultiaddr = convertToMultiaddr(p2pIp, p2pPort, 'tcp');
306
+ await this.peerManager.initializePeers();
307
+ if (!this.config.p2pDiscoveryDisabled) {
308
+ await this.peerDiscoveryService.start();
309
+ }
214
310
  await this.node.start();
215
311
  // Subscribe to standard GossipSub topics by default
216
- for (const topic of getTopicTypeForClientType(this.clientType)){
217
- this.subscribeToTopic(TopicTypeMap[topic].p2pTopic);
312
+ for (const topic of getTopicsForClientAndConfig(this.clientType, this.config.disableTransactions)){
313
+ this.subscribeToTopic(this.topicStrings[topic]);
218
314
  }
219
315
  // Create request response protocol handlers
220
316
  const txHandler = reqRespTxHandler(this.mempools);
221
317
  const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
222
- const blockHandler = reqRespBlockHandler(this.l2BlockSource);
318
+ const blockHandler = reqRespBlockHandler(this.archiver);
319
+ const statusHandler = reqRespStatusHandler(this.protocolVersion, this.worldStateSynchronizer, this.logger);
223
320
  const requestResponseHandlers = {
224
321
  [ReqRespSubProtocol.PING]: pingHandler,
225
- [ReqRespSubProtocol.STATUS]: statusHandler,
226
- [ReqRespSubProtocol.TX]: txHandler.bind(this),
322
+ [ReqRespSubProtocol.STATUS]: statusHandler.bind(this),
227
323
  [ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this),
228
324
  [ReqRespSubProtocol.BLOCK]: blockHandler.bind(this)
229
325
  };
326
+ // Only handle block transactions request if attestation pool is available to the client
327
+ if (this.mempools.attestationPool && !this.config.disableTransactions) {
328
+ const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.mempools.txPool);
329
+ requestResponseHandlers[ReqRespSubProtocol.BLOCK_TXS] = blockTxsHandler.bind(this);
330
+ }
331
+ if (!this.config.disableTransactions) {
332
+ requestResponseHandlers[ReqRespSubProtocol.TX] = txHandler.bind(this);
333
+ }
230
334
  // add GossipSub listener
231
- this.node.services.pubsub.addEventListener(GossipSubEvent.MESSAGE, this.handleGossipSubEvent.bind(this));
232
- // Start running promise for peer discovery
233
- this.discoveryRunningPromise = new RunningPromise(()=>this.peerManager.heartbeat(), this.logger, this.config.peerCheckIntervalMS);
335
+ this.node.services.pubsub.addEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
336
+ // Start running promise for peer discovery and metrics collection
337
+ this.discoveryRunningPromise = new RunningPromise(async ()=>{
338
+ await this.peerManager.heartbeat();
339
+ }, this.logger, this.config.peerCheckIntervalMS);
234
340
  this.discoveryRunningPromise.start();
235
341
  // Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
236
342
  const reqrespSubProtocolValidators = {
237
343
  ...DEFAULT_SUB_PROTOCOL_VALIDATORS,
238
- // TODO(#11336): A request validator for blocks
239
- [ReqRespSubProtocol.TX]: this.validateRequestedTx.bind(this)
344
+ [ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
345
+ [ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
346
+ [ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this)
240
347
  };
241
348
  await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
242
349
  this.logger.info(`Started P2P service`, {
243
- listen: tcpListenAddress,
350
+ listen: this.config.listenAddress,
351
+ port: this.config.p2pPort,
244
352
  announce: announceTcpMultiaddr,
245
353
  peerId: this.node.peerId.toString()
246
354
  });
@@ -250,12 +358,10 @@ import { ReqResp } from '../reqresp/reqresp.js';
250
358
  * @returns An empty promise.
251
359
  */ async stop() {
252
360
  // Remove gossip sub listener
253
- this.node.services.pubsub.removeEventListener(GossipSubEvent.MESSAGE, this.handleGossipSubEvent.bind(this));
361
+ this.node.services.pubsub.removeEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
254
362
  // Stop peer manager
255
363
  this.logger.debug('Stopping peer manager...');
256
364
  await this.peerManager.stop();
257
- this.logger.debug('Stopping job queue...');
258
- await this.jobQueue.end();
259
365
  this.logger.debug('Stopping running promise...');
260
366
  await this.discoveryRunningPromise?.stop();
261
367
  this.logger.debug('Stopping peer discovery service...');
@@ -266,6 +372,12 @@ import { ReqResp } from '../reqresp/reqresp.js';
266
372
  await this.stopLibP2P();
267
373
  this.logger.info('LibP2P service stopped');
268
374
  }
375
+ addReqRespSubProtocol(subProtocol, handler, validator) {
376
+ return this.reqresp.addSubProtocol(subProtocol, handler, validator);
377
+ }
378
+ registerThisValidatorAddresses(address) {
379
+ this.peerManager.registerThisValidatorAddresses(address);
380
+ }
269
381
  getPeers(includePending) {
270
382
  return this.peerManager.getPeers(includePending);
271
383
  }
@@ -281,24 +393,12 @@ import { ReqResp } from '../reqresp/reqresp.js';
281
393
  setImmediate(()=>void safeJob());
282
394
  }
283
395
  /**
284
- * Send Request via the ReqResp service
285
- * The subprotocol defined will determine the request and response types
286
- *
287
- * See the subProtocolMap for the mapping of subprotocols to request/response types in `interface.ts`
288
- *
289
- * @param protocol The request response protocol to use
290
- * @param request The request type to send
291
- * @returns
292
- */ sendRequest(protocol, request) {
293
- return this.reqresp.sendRequest(protocol, request);
294
- }
295
- /**
296
396
  * Send a batch of requests to peers, and return the responses
297
397
  * @param protocol - The request response protocol to use
298
398
  * @param requests - The requests to send to the peers
299
399
  * @returns The responses to the requests
300
- */ sendBatchRequest(protocol, requests) {
301
- return this.reqresp.sendBatchRequest(protocol, requests);
400
+ */ sendBatchRequest(protocol, requests, pinnedPeerId) {
401
+ return this.reqresp.sendBatchRequest(protocol, requests, pinnedPeerId);
302
402
  }
303
403
  /**
304
404
  * Get the ENR of the node
@@ -308,7 +408,6 @@ import { ReqResp } from '../reqresp/reqresp.js';
308
408
  }
309
409
  registerBlockReceivedCallback(callback) {
310
410
  this.blockReceivedCallback = callback;
311
- this.logger.verbose('Block received callback registered');
312
411
  }
313
412
  /**
314
413
  * Subscribes to a topic.
@@ -322,133 +421,326 @@ import { ReqResp } from '../reqresp/reqresp.js';
322
421
  /**
323
422
  * Publishes data to a topic.
324
423
  * @param topic - The topic to publish to.
325
- * @param data - The data to publish.
424
+ * @param data - The message to publish.
326
425
  * @returns The number of recipients the data was sent to.
327
- */ async publishToTopic(topic, data) {
426
+ */ async publishToTopic(topic, message) {
328
427
  if (!this.node.services.pubsub) {
329
428
  throw new Error('Pubsub service not available.');
330
429
  }
331
- const result = await this.node.services.pubsub.publish(topic, data);
430
+ const p2pMessage = P2PMessage.fromGossipable(message, this.config.debugP2PInstrumentMessages);
431
+ const result = await this.node.services.pubsub.publish(topic, p2pMessage.toMessageData());
332
432
  return result.recipients.length;
333
433
  }
334
434
  /**
435
+ * Checks if this message has already been seen, based on its msgId computed from hashing the message data.
436
+ * Note that we do not rely on the seenCache from gossipsub since we want to keep a longer history of seen
437
+ * messages to avoid tx echoes across the network.
438
+ */ preValidateReceivedMessage(msg, msgId, source) {
439
+ let topicType;
440
+ switch(msg.topic){
441
+ case this.topicStrings[TopicType.tx]:
442
+ topicType = TopicType.tx;
443
+ break;
444
+ case this.topicStrings[TopicType.block_attestation]:
445
+ topicType = TopicType.block_attestation;
446
+ break;
447
+ case this.topicStrings[TopicType.block_proposal]:
448
+ topicType = TopicType.block_proposal;
449
+ break;
450
+ default:
451
+ this.logger.error(`Received message on unknown topic: ${msg.topic}`);
452
+ break;
453
+ }
454
+ const validator = topicType ? this.msgIdSeenValidators[topicType] : undefined;
455
+ if (!validator || !validator.addMessage(msgId)) {
456
+ this.instrumentation.incMessagePrevalidationStatus(false, topicType);
457
+ this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
458
+ return {
459
+ result: false,
460
+ topicType
461
+ };
462
+ }
463
+ this.instrumentation.incMessagePrevalidationStatus(true, topicType);
464
+ return {
465
+ result: true,
466
+ topicType
467
+ };
468
+ }
469
+ /**
470
+ * Safely deserializes a P2PMessage from raw message data.
471
+ * @param msgId - The message ID.
472
+ * @param source - The peer ID of the message source.
473
+ * @param data - The raw message data.
474
+ * @returns The deserialized P2PMessage or undefined if deserialization fails.
475
+ */ safelyDeserializeP2PMessage(msgId, source, data) {
476
+ try {
477
+ return P2PMessage.fromMessageData(Buffer.from(data), this.config.debugP2PInstrumentMessages);
478
+ } catch (err) {
479
+ this.logger.error(`Error deserializing P2PMessage`, err, {
480
+ msgId,
481
+ source: source.toString()
482
+ });
483
+ this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Reject);
484
+ this.peerManager.penalizePeer(source, PeerErrorSeverity.LowToleranceError);
485
+ return undefined;
486
+ }
487
+ }
488
+ /**
335
489
  * Handles a new gossip message that was received by the client.
336
490
  * @param topic - The message's topic.
337
491
  * @param data - The message data
338
492
  */ async handleNewGossipMessage(msg, msgId, source) {
339
- if (msg.topic === Tx.p2pTopic) {
340
- await this.handleGossipedTx(msg, msgId, source);
493
+ const msgReceivedTime = Date.now();
494
+ let topicType;
495
+ const p2pMessage = this.safelyDeserializeP2PMessage(msgId, source, msg.data);
496
+ if (!p2pMessage) {
497
+ return;
341
498
  }
342
- if (msg.topic === BlockAttestation.p2pTopic && this.clientType === P2PClientType.Full) {
343
- await this.processAttestationFromPeer(msg, msgId, source);
499
+ const preValidationResult = this.preValidateReceivedMessage(msg, msgId, source);
500
+ if (!preValidationResult.result) {
501
+ return;
502
+ }
503
+ if (msg.topic === this.topicStrings[TopicType.tx]) {
504
+ topicType = TopicType.tx;
505
+ await this.handleGossipedTx(p2pMessage.payload, msgId, source);
506
+ }
507
+ if (msg.topic === this.topicStrings[TopicType.block_attestation]) {
508
+ topicType = TopicType.block_attestation;
509
+ if (this.clientType === P2PClientType.Full) {
510
+ await this.processAttestationFromPeer(p2pMessage.payload, msgId, source);
511
+ }
344
512
  }
345
- if (msg.topic == BlockProposal.p2pTopic) {
346
- await this.processBlockFromPeer(msg, msgId, source);
513
+ if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
514
+ topicType = TopicType.block_proposal;
515
+ await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
516
+ }
517
+ if (p2pMessage.timestamp !== undefined && topicType !== undefined) {
518
+ const latency = msgReceivedTime - p2pMessage.timestamp.getTime();
519
+ this.instrumentation.recordMessageLatency(topicType, latency);
347
520
  }
348
521
  return;
349
522
  }
350
- async validateReceivedMessage(validationFunc, msgId, source) {
523
+ async validateReceivedMessage(validationFunc, msgId, source, topicType) {
351
524
  let resultAndObj = {
352
- result: false,
353
- obj: undefined
525
+ result: TopicValidatorResult.Reject
354
526
  };
527
+ const timer = new Timer();
355
528
  try {
356
529
  resultAndObj = await validationFunc();
357
530
  } catch (err) {
358
- this.logger.error(`Error deserialising and validating message `, err);
531
+ this.peerManager.penalizePeer(source, PeerErrorSeverity.LowToleranceError);
532
+ this.logger.error(`Error deserializing and validating gossipsub message`, err, {
533
+ msgId,
534
+ source: source.toString(),
535
+ topicType
536
+ });
359
537
  }
360
- this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result && resultAndObj.obj ? TopicValidatorResult.Accept : TopicValidatorResult.Reject);
538
+ if (resultAndObj.result === TopicValidatorResult.Accept) {
539
+ this.instrumentation.recordMessageValidation(topicType, timer);
540
+ }
541
+ this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result);
361
542
  return resultAndObj;
362
543
  }
363
- async handleGossipedTx(msg, msgId, source) {
544
+ async handleGossipedTx(payloadData, msgId, source) {
364
545
  const validationFunc = async ()=>{
365
- const tx = Tx.fromBuffer(Buffer.from(msg.data));
366
- const result = await this.validatePropagatedTx(tx, source);
367
- return {
368
- result,
369
- obj: tx
370
- };
546
+ const tx = Tx.fromBuffer(payloadData);
547
+ const isValid = await this.validatePropagatedTx(tx, source);
548
+ const exists = isValid && await this.mempools.txPool.hasTx(tx.getTxHash());
549
+ this.logger.trace(`Validate propagated tx`, {
550
+ isValid,
551
+ exists,
552
+ [Attributes.P2P_ID]: source.toString()
553
+ });
554
+ if (!isValid) {
555
+ return {
556
+ result: TopicValidatorResult.Reject
557
+ };
558
+ } else if (exists) {
559
+ return {
560
+ result: TopicValidatorResult.Ignore,
561
+ obj: tx
562
+ };
563
+ } else {
564
+ return {
565
+ result: TopicValidatorResult.Accept,
566
+ obj: tx
567
+ };
568
+ }
371
569
  };
372
- const { result, obj: tx } = await this.validateReceivedMessage(validationFunc, msgId, source);
373
- if (!result || !tx) {
570
+ const { result, obj: tx } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.tx);
571
+ if (result !== TopicValidatorResult.Accept || !tx) {
374
572
  return;
375
573
  }
376
- const txHash = await tx.getTxHash();
574
+ const txHash = tx.getTxHash();
377
575
  const txHashString = txHash.toString();
378
- this.logger.verbose(`Received tx ${txHashString} from external peer ${source.toString()}.`);
576
+ this.logger.verbose(`Received tx ${txHashString} from external peer ${source.toString()} via gossip`, {
577
+ source: source.toString(),
578
+ txHash: txHashString
579
+ });
580
+ if (this.config.dropTransactions && randomInt(1000) < this.config.dropTransactionsProbability * 1000) {
581
+ this.logger.warn(`Intentionally dropping tx ${txHashString} (probability rule)`);
582
+ return;
583
+ }
584
+ this.instrumentation.incrementTxReceived(1);
379
585
  await this.mempools.txPool.addTxs([
380
586
  tx
381
587
  ]);
382
588
  }
383
- /**Process Attestation From Peer
589
+ /**
590
+ * Process Attestation From Peer
384
591
  * When a proposal is received from a peer, we add it to the attestation pool, so it can be accessed by other services.
385
592
  *
386
593
  * @param attestation - The attestation to process.
387
- */ async processAttestationFromPeer(msg, msgId, source) {
594
+ */ async processAttestationFromPeer(payloadData, msgId, source) {
388
595
  const validationFunc = async ()=>{
389
- const attestation = BlockAttestation.fromBuffer(Buffer.from(msg.data));
390
- const result = await this.validateAttestation(source, attestation);
391
- this.logger.trace(`validatePropagatedAttestation: ${result}`, {
392
- [Attributes.SLOT_NUMBER]: attestation.payload.header.globalVariables.slotNumber.toString(),
596
+ const attestation = BlockAttestation.fromBuffer(payloadData);
597
+ const pool = this.mempools.attestationPool;
598
+ const isValid = await this.validateAttestation(source, attestation);
599
+ const exists = isValid && await pool.hasAttestation(attestation);
600
+ let canAdd = true;
601
+ if (isValid && !exists) {
602
+ const slot = attestation.payload.header.slotNumber;
603
+ const { committee } = await this.epochCache.getCommittee(slot);
604
+ const committeeSize = committee?.length ?? 0;
605
+ canAdd = await pool.canAddAttestation(attestation, committeeSize);
606
+ }
607
+ this.logger.trace(`Validate propagated block attestation`, {
608
+ isValid,
609
+ exists,
610
+ canAdd,
611
+ [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toString(),
393
612
  [Attributes.P2P_ID]: source.toString()
394
613
  });
395
- return {
396
- result,
397
- obj: attestation
398
- };
614
+ if (!isValid) {
615
+ return {
616
+ result: TopicValidatorResult.Reject
617
+ };
618
+ } else if (exists) {
619
+ return {
620
+ result: TopicValidatorResult.Ignore,
621
+ obj: attestation
622
+ };
623
+ } else if (!canAdd) {
624
+ this.logger.warn(`Dropping block attestation due to per-(slot, proposalId) attestation cap`, {
625
+ slot: attestation.payload.header.slotNumber.toString(),
626
+ archive: attestation.archive.toString(),
627
+ source: source.toString()
628
+ });
629
+ return {
630
+ result: TopicValidatorResult.Ignore,
631
+ obj: attestation
632
+ };
633
+ } else {
634
+ return {
635
+ result: TopicValidatorResult.Accept,
636
+ obj: attestation
637
+ };
638
+ }
399
639
  };
400
- const { result, obj: attestation } = await this.validateReceivedMessage(validationFunc, msgId, source);
401
- if (!result || !attestation) {
640
+ const { result, obj: attestation } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.block_attestation);
641
+ if (result !== TopicValidatorResult.Accept || !attestation) {
402
642
  return;
403
643
  }
404
- this.logger.debug(`Received attestation for block ${attestation.blockNumber.toNumber()} slot ${attestation.slotNumber.toNumber()} from external peer.`, {
405
- p2pMessageIdentifier: await attestation.p2pMessageIdentifier(),
406
- slot: attestation.slotNumber.toNumber(),
644
+ this.logger.debug(`Received attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`, {
645
+ p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
646
+ slot: attestation.slotNumber,
407
647
  archive: attestation.archive.toString(),
408
- block: attestation.blockNumber.toNumber()
648
+ source: source.toString()
409
649
  });
410
650
  await this.mempools.attestationPool.addAttestations([
411
651
  attestation
412
652
  ]);
413
653
  }
414
- async processBlockFromPeer(msg, msgId, source) {
654
+ async processBlockFromPeer(payloadData, msgId, source) {
415
655
  const validationFunc = async ()=>{
416
- const block = BlockProposal.fromBuffer(Buffer.from(msg.data));
417
- const result = await this.validateBlockProposal(source, block);
418
- this.logger.trace(`validatePropagatedBlock: ${result}`, {
419
- [Attributes.SLOT_NUMBER]: block.payload.header.globalVariables.slotNumber.toString(),
656
+ const block = BlockProposal.fromBuffer(payloadData);
657
+ const isValid = await this.validateBlockProposal(source, block);
658
+ const pool = this.mempools.attestationPool;
659
+ // Note that we dont have an attestation pool if we're a prover node, but we still
660
+ // subscribe to block proposal topics in order to prevent their txs from being cleared.
661
+ const exists = isValid && await pool?.hasBlockProposal(block);
662
+ const canAdd = isValid && await pool?.canAddProposal(block);
663
+ this.logger.trace(`Validate propagated block proposal`, {
664
+ isValid,
665
+ exists,
666
+ canAdd,
667
+ [Attributes.SLOT_NUMBER]: block.payload.header.slotNumber.toString(),
420
668
  [Attributes.P2P_ID]: source.toString()
421
669
  });
422
- return {
423
- result,
424
- obj: block
425
- };
670
+ if (!isValid) {
671
+ return {
672
+ result: TopicValidatorResult.Reject
673
+ };
674
+ } else if (exists) {
675
+ return {
676
+ result: TopicValidatorResult.Ignore,
677
+ obj: block
678
+ };
679
+ } else if (!canAdd) {
680
+ this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
681
+ this.logger.warn(`Penalizing peer for block proposal exceeding per-slot cap`, {
682
+ slot: block.slotNumber.toString(),
683
+ archive: block.archive.toString(),
684
+ source: source.toString()
685
+ });
686
+ return {
687
+ result: TopicValidatorResult.Reject
688
+ };
689
+ } else {
690
+ return {
691
+ result: TopicValidatorResult.Accept,
692
+ obj: block
693
+ };
694
+ }
426
695
  };
427
- const { result, obj: block } = await this.validateReceivedMessage(validationFunc, msgId, source);
696
+ const { result, obj: block } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.block_proposal);
428
697
  if (!result || !block) {
429
698
  return;
430
699
  }
431
- await this.processValidBlockProposal(block);
700
+ await this.processValidBlockProposal(block, source);
432
701
  }
433
702
  // REVIEW: callback pattern https://github.com/AztecProtocol/aztec-packages/issues/7963
434
- async processValidBlockProposal(block) {
435
- this.logger.verbose(`Received block ${block.blockNumber.toNumber()} for slot ${block.slotNumber.toNumber()} from external peer.`, {
436
- p2pMessageIdentifier: await block.p2pMessageIdentifier(),
437
- slot: block.slotNumber.toNumber(),
703
+ async processValidBlockProposal(block, sender) {
704
+ const slot = block.slotNumber;
705
+ const previousSlot = SlotNumber(slot - 1);
706
+ this.logger.verbose(`Received block proposal for slot ${slot} from external peer ${sender.toString()}.`, {
707
+ p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier(),
708
+ slot: block.slotNumber,
438
709
  archive: block.archive.toString(),
439
- block: block.blockNumber.toNumber()
710
+ source: sender.toString()
440
711
  });
441
- const attestation = await this.blockReceivedCallback(block);
712
+ const attestationsForPreviousSlot = await this.mempools.attestationPool?.getAttestationsForSlot(previousSlot);
713
+ if (attestationsForPreviousSlot !== undefined) {
714
+ this.logger.verbose(`Received ${attestationsForPreviousSlot.length} attestations for slot ${previousSlot}`);
715
+ }
716
+ // Attempt to add proposal, then mark the txs in this proposal as non-evictable
717
+ try {
718
+ await this.mempools.attestationPool?.addBlockProposal(block);
719
+ } catch (err) {
720
+ // Drop proposals if we hit per-slot cap in the attestation pool; rethrow unknown errors
721
+ if (err instanceof ProposalSlotCapExceededError) {
722
+ this.logger.warn(`Dropping block proposal due to per-slot proposal cap`, {
723
+ slot: String(slot),
724
+ archive: block.archive.toString(),
725
+ error: err.message
726
+ });
727
+ return;
728
+ }
729
+ throw err;
730
+ }
731
+ await this.mempools.txPool.markTxsAsNonEvictable(block.txHashes);
732
+ const attestations = await this.blockReceivedCallback(block, sender);
442
733
  // TODO: fix up this pattern - the abstraction is not nice
443
- // The attestation can be undefined if no handler is registered / the validator deems the block invalid
444
- if (attestation != undefined) {
445
- this.logger.verbose(`Broadcasting attestation for block ${attestation.blockNumber.toNumber()} slot ${attestation.slotNumber.toNumber()}`, {
446
- p2pMessageIdentifier: await attestation.p2pMessageIdentifier(),
447
- slot: attestation.slotNumber.toNumber(),
448
- archive: attestation.archive.toString(),
449
- block: attestation.blockNumber.toNumber()
450
- });
451
- await this.broadcastAttestation(attestation);
734
+ // The attestation can be undefined if no handler is registered / the validator deems the block invalid / in fisherman mode
735
+ if (attestations?.length) {
736
+ for (const attestation of attestations){
737
+ this.logger.verbose(`Broadcasting attestation for slot ${attestation.slotNumber}`, {
738
+ p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
739
+ slot: attestation.slotNumber,
740
+ archive: attestation.archive.toString()
741
+ });
742
+ await this.broadcastAttestation(attestation);
743
+ }
452
744
  }
453
745
  }
454
746
  /**
@@ -461,96 +753,242 @@ import { ReqResp } from '../reqresp/reqresp.js';
461
753
  * Propagates provided message to peers.
462
754
  * @param message - The message to propagate.
463
755
  */ async propagate(message) {
464
- const p2pMessageIdentifier = await message.p2pMessageIdentifier();
756
+ const p2pMessageIdentifier = await message.p2pMessageLoggingIdentifier();
465
757
  this.logger.trace(`Message ${p2pMessageIdentifier} queued`, {
466
758
  p2pMessageIdentifier
467
759
  });
468
- void this.jobQueue.put(async ()=>{
469
- await this.sendToPeers(message);
470
- }).catch((error)=>{
760
+ void this.sendToPeers(message).catch((error)=>{
471
761
  this.logger.error(`Error propagating message ${p2pMessageIdentifier}`, {
472
762
  error
473
763
  });
474
764
  });
475
765
  }
476
766
  /**
477
- * Validate a tx that has been requested from a peer.
767
+ * Validate the requested block transactions. Allow partial returns.
768
+ * @param request - The block transactions request.
769
+ * @param response - The block transactions response.
770
+ * @param peerId - The ID of the peer that made the request.
771
+ * @returns True if the requested block transactions are valid, false otherwise.
772
+ */ async validateRequestedBlockTxs(request, response, peerId) {
773
+ const requestedTxValidator = this.createRequestedTxValidator();
774
+ try {
775
+ if (!response.blockHash.equals(request.blockHash)) {
776
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
777
+ throw new ValidationError(`Received block txs for unexpected block: expected ${request.blockHash.toString()}, got ${response.blockHash.toString()}`);
778
+ }
779
+ if (response.txIndices.getLength() !== request.txIndices.getLength()) {
780
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
781
+ throw new ValidationError(`Received block txs with mismatched bitvector length: expected ${request.txIndices.getLength()}, got ${response.txIndices.getLength()}`);
782
+ }
783
+ // Check no duplicates and not exceeding returnable count
784
+ const requestedIndices = new Set(request.txIndices.getTrueIndices());
785
+ const availableIndices = new Set(response.txIndices.getTrueIndices());
786
+ const maxReturnable = [
787
+ ...requestedIndices
788
+ ].filter((i)=>availableIndices.has(i)).length;
789
+ const returnedHashes = await Promise.all(response.txs.map((tx)=>tx.getTxHash().toString()));
790
+ const uniqueReturned = new Set(returnedHashes.map((h)=>h.toString()));
791
+ if (uniqueReturned.size !== returnedHashes.length) {
792
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
793
+ throw new ValidationError(`Received duplicate txs in block txs response`);
794
+ }
795
+ if (response.txs.length > maxReturnable) {
796
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
797
+ throw new ValidationError(`Received more txs (${response.txs.length}) than requested-and-available (${maxReturnable})`);
798
+ }
799
+ // Given proposal (should have locally), ensure returned txs are valid subset and match request indices
800
+ const proposal = await this.mempools.attestationPool?.getBlockProposal(request.blockHash.toString());
801
+ if (proposal) {
802
+ // Build intersected indices
803
+ const intersectIdx = request.txIndices.getTrueIndices().filter((i)=>response.txIndices.isSet(i));
804
+ // Enforce subset membership and preserve increasing order by index.
805
+ const hashToIndexInProposal = new Map(proposal.txHashes.map((h, i)=>[
806
+ h.toString(),
807
+ i
808
+ ]));
809
+ const allowedIndexSet = new Set(intersectIdx);
810
+ const indices = returnedHashes.map((h)=>hashToIndexInProposal.get(h));
811
+ const allAllowed = indices.every((idx)=>idx !== undefined && allowedIndexSet.has(idx));
812
+ const strictlyIncreasing = indices.every((idx, i)=>i === 0 ? idx !== undefined : idx > indices[i - 1]);
813
+ if (!allAllowed || !strictlyIncreasing) {
814
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
815
+ throw new ValidationError('Returned txs do not match expected subset/order for requested indices');
816
+ }
817
+ } else {
818
+ // No local proposal, cannot check the membership/order of the returned txs
819
+ this.logger.warn(`Block proposal not found for block hash ${request.blockHash.toString()}; cannot validate membership/order of returned txs`);
820
+ return false;
821
+ }
822
+ await Promise.all(response.txs.map((tx)=>this.validateRequestedTx(tx, peerId, requestedTxValidator)));
823
+ return true;
824
+ } catch (e) {
825
+ if (e instanceof ValidationError) {
826
+ this.logger.warn(`Failed validation for requested block txs from peer ${peerId.toString()}`);
827
+ } else {
828
+ this.logger.error(`Error during validation of requested block txs`, e);
829
+ }
830
+ return false;
831
+ }
832
+ }
833
+ /**
834
+ * Validate a collection of txs that has been requested from a peer.
478
835
  *
479
- * The core component of this validator is that the tx hash MUST match the requested tx hash,
836
+ * The core component of this validator is that each tx hash MUST match the requested tx hash,
480
837
  * In order to perform this check, the tx proof must be verified.
481
838
  *
482
839
  * Note: This function is called from within `ReqResp.sendRequest` as part of the
483
840
  * ReqRespSubProtocol.TX subprotocol validation.
484
841
  *
485
- * @param requestedTxHash - The hash of the tx that was requested.
486
- * @param responseTx - The tx that was received as a response to the request.
842
+ * @param requestedTxHash - The collection of the txs that was requested.
843
+ * @param responseTx - The collection of txs that was received as a response to the request.
487
844
  * @param peerId - The peer ID of the peer that sent the tx.
488
- * @returns True if the tx is valid, false otherwise.
489
- */ async validateRequestedTx(requestedTxHash, responseTx, peerId) {
490
- const proofValidator = new TxProofValidator(this.proofVerifier);
491
- const validProof = await proofValidator.validateTx(responseTx);
492
- // If the node returns the wrong data, we penalize it
493
- if (!requestedTxHash.equals(await responseTx.getTxHash())) {
494
- // Returning the wrong data is a low tolerance error
495
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
845
+ * @returns True if the whole collection of txs is valid, false otherwise.
846
+ */ async validateRequestedTxs(requestedTxHash, responseTx, peerId) {
847
+ const requested = new Set(requestedTxHash.map((h)=>h.toString()));
848
+ const requestedTxValidator = this.createRequestedTxValidator();
849
+ //TODO: (mralj) - this is somewhat naive implementation, if single tx is invlid we consider the whole response invalid.
850
+ // I think we should still extract the valid txs and return them, so that we can still use the response.
851
+ try {
852
+ await Promise.all(responseTx.map((tx)=>this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
853
+ return true;
854
+ } catch (e) {
855
+ if (e instanceof ValidationError) {
856
+ this.logger.warn(`Failed to validate requested txs from peer ${peerId.toString()}, reason ${e.message}`);
857
+ } else {
858
+ this.logger.error(`Error during validation of requested txs`, e);
859
+ }
496
860
  return false;
497
861
  }
498
- if (validProof.result === 'invalid') {
499
- // If the proof is invalid, but the txHash is correct, then this is an active attack and we severly punish
500
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
862
+ }
863
+ /**
864
+ * Validates a BLOCK response.
865
+ *
866
+ * If a local copy exists, enforces hash equality. If missing, rejects (no penalty) since the hash cannot be verified.
867
+ * Penalizes on block number mismatch or hash mismatch.
868
+ *
869
+ * @param requestedBlockNumber - The requested block number.
870
+ * @param responseBlock - The block returned by the peer.
871
+ * @param peerId - The peer that returned the block.
872
+ * @returns True if the response is valid, false otherwise.
873
+ */ async validateRequestedBlock(requestedBlockNumber, responseBlock, peerId) {
874
+ try {
875
+ const reqNum = Number(requestedBlockNumber.toString());
876
+ if (responseBlock.number !== reqNum) {
877
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
878
+ return false;
879
+ }
880
+ const local = await this.archiver.getBlock(reqNum);
881
+ if (!local) {
882
+ // We are missing the local block; we cannot verify the hash yet. Reject without penalizing.
883
+ // TODO: Consider extending this validator to accept an expected hash or
884
+ // performing quorum-based checks when using P2P syncing prior to L1 sync.
885
+ this.logger.warn(`Local block ${reqNum} not found; rejecting BLOCK response without hash verification`);
886
+ return false;
887
+ }
888
+ const [localHash, respHash] = await Promise.all([
889
+ local.hash(),
890
+ responseBlock.hash()
891
+ ]);
892
+ if (!localHash.equals(respHash)) {
893
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
894
+ return false;
895
+ }
896
+ return true;
897
+ } catch (e) {
898
+ this.logger.warn(`Error validating requested block`, e);
501
899
  return false;
502
900
  }
503
- return true;
901
+ }
902
+ createRequestedTxValidator() {
903
+ return new AggregateTxValidator(new DataTxValidator(), new MetadataTxValidator({
904
+ l1ChainId: new Fr(this.config.l1ChainId),
905
+ rollupVersion: new Fr(this.config.rollupVersion),
906
+ protocolContractsHash,
907
+ vkTreeRoot: getVKTreeRoot()
908
+ }), new TxProofValidator(this.proofVerifier));
909
+ }
910
+ async validateRequestedTx(tx, peerId, txValidator, requested) {
911
+ const penalize = (severity)=>this.peerManager.penalizePeer(peerId, severity);
912
+ if (!await tx.validateTxHash()) {
913
+ penalize(PeerErrorSeverity.MidToleranceError);
914
+ throw new ValidationError(`Received tx with invalid hash ${tx.getTxHash().toString()}.`);
915
+ }
916
+ if (requested && !requested.has(tx.getTxHash().toString())) {
917
+ penalize(PeerErrorSeverity.MidToleranceError);
918
+ throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
919
+ }
920
+ const { result } = await txValidator.validateTx(tx);
921
+ if (result === 'invalid') {
922
+ penalize(PeerErrorSeverity.LowToleranceError);
923
+ throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that is invalid.`);
924
+ }
504
925
  }
505
926
  async validatePropagatedTx(tx, peerId) {
506
- const blockNumber = await this.l2BlockSource.getBlockNumber() + 1;
507
- const messageValidators = this.createMessageValidators(blockNumber);
508
- const outcome = await this.runValidations(tx, messageValidators);
509
- if (outcome.allPassed) {
510
- return true;
927
+ const currentBlockNumber = await this.archiver.getBlockNumber();
928
+ // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
929
+ const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
930
+ const messageValidators = await this.createMessageValidators(currentBlockNumber, nextSlotTimestamp);
931
+ for (const validator of messageValidators){
932
+ const outcome = await this.runValidations(tx, validator);
933
+ if (outcome.allPassed) {
934
+ continue;
935
+ }
936
+ const { name } = outcome.failure;
937
+ let { severity } = outcome.failure;
938
+ // Double spend validator has a special case handler
939
+ if (name === 'doubleSpendValidator') {
940
+ const txBlockNumber = currentBlockNumber + 1; // tx is expected to be in the next block
941
+ severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
942
+ }
943
+ this.peerManager.penalizePeer(peerId, severity);
944
+ return false;
511
945
  }
512
- const { name } = outcome.failure;
513
- let { severity } = outcome.failure;
514
- // Double spend validator has a special case handler
515
- if (name === 'doubleSpendValidator') {
516
- severity = await this.handleDoubleSpendFailure(tx, blockNumber);
946
+ return true;
947
+ }
948
+ async getGasFees(blockNumber) {
949
+ if (blockNumber === this.feesCache?.blockNumber) {
950
+ return this.feesCache.gasFees;
517
951
  }
518
- this.peerManager.penalizePeer(peerId, severity);
519
- return false;
952
+ const header = await this.archiver.getBlockHeader(blockNumber);
953
+ const gasFees = header?.globalVariables.gasFees ?? GasFees.empty();
954
+ this.feesCache = {
955
+ blockNumber,
956
+ gasFees
957
+ };
958
+ return gasFees;
959
+ }
960
+ async validate(txs) {
961
+ const currentBlockNumber = await this.archiver.getBlockNumber();
962
+ // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
963
+ const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
964
+ const messageValidators = await this.createMessageValidators(currentBlockNumber, nextSlotTimestamp);
965
+ await Promise.all(txs.map(async (tx)=>{
966
+ for (const validator of messageValidators){
967
+ const outcome = await this.runValidations(tx, validator);
968
+ if (!outcome.allPassed) {
969
+ throw new Error('Invalid tx detected', {
970
+ cause: {
971
+ outcome
972
+ }
973
+ });
974
+ }
975
+ }
976
+ }));
520
977
  }
521
978
  /**
522
- * Create message validators for the given block number.
979
+ * Create message validators for the given block number and timestamp.
523
980
  *
524
981
  * Each validator is a pair of a validator and a severity.
525
982
  * If a validator fails, the peer is penalized with the severity of the validator.
526
983
  *
527
- * @param blockNumber - The block number to create validators for.
984
+ * @param currentBlockNumber - The current synced block number.
985
+ * @param nextSlotTimestamp - The timestamp of the next slot (used to validate txs are not expired).
528
986
  * @returns The message validators.
529
- */ createMessageValidators(blockNumber) {
530
- return {
531
- dataValidator: {
532
- validator: new DataTxValidator(),
533
- severity: PeerErrorSeverity.HighToleranceError
534
- },
535
- metadataValidator: {
536
- validator: new MetadataTxValidator(new Fr(this.config.l1ChainId), new Fr(blockNumber)),
537
- severity: PeerErrorSeverity.HighToleranceError
538
- },
539
- proofValidator: {
540
- validator: new TxProofValidator(this.proofVerifier),
541
- severity: PeerErrorSeverity.MidToleranceError
542
- },
543
- doubleSpendValidator: {
544
- validator: new DoubleSpendTxValidator({
545
- nullifiersExist: async (nullifiers)=>{
546
- const merkleTree = this.worldStateSynchronizer.getCommitted();
547
- const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
548
- return indices.map((index)=>index !== undefined);
549
- }
550
- }),
551
- severity: PeerErrorSeverity.HighToleranceError
552
- }
553
- };
987
+ */ async createMessageValidators(currentBlockNumber, nextSlotTimestamp) {
988
+ const gasFees = await this.getGasFees(currentBlockNumber);
989
+ const allowedInSetup = this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
990
+ const blockNumberInWhichTheTxIsConsideredToBeIncluded = currentBlockNumber + 1;
991
+ return createTxMessageValidators(nextSlotTimestamp, blockNumberInWhichTheTxIsConsideredToBeIncluded, this.worldStateSynchronizer, gasFees, this.config.l1ChainId, this.config.rollupVersion, protocolContractsHash, this.archiver, this.proofVerifier, !this.config.disableTransactions, allowedInSetup);
554
992
  }
555
993
  /**
556
994
  * Run validations on a tx.
@@ -562,29 +1000,32 @@ import { ReqResp } from '../reqresp/reqresp.js';
562
1000
  const { result } = await validator.validateTx(tx);
563
1001
  return {
564
1002
  name,
565
- isValid: result === 'valid',
1003
+ isValid: result !== 'invalid',
566
1004
  severity
567
1005
  };
568
1006
  });
569
1007
  // A promise that resolves when all validations have been run
570
- const allValidations = Promise.all(validationPromises);
571
- // A promise that resolves when the first validation fails
572
- const firstFailure = Promise.race(validationPromises.map(async (promise)=>{
573
- const result = await promise;
574
- return result.isValid ? new Promise(()=>{}) : result;
575
- }));
576
- // Wait for the first validation to fail or all validations to pass
577
- const result = await Promise.race([
578
- allValidations.then(()=>({
579
- allPassed: true
580
- })),
581
- firstFailure.then((failure)=>({
582
- allPassed: false,
583
- failure: failure
584
- }))
585
- ]);
586
- // If all validations pass, allPassed will be true, if failed, then the failure will be the first validation to fail
587
- return result;
1008
+ const allValidations = await Promise.all(validationPromises);
1009
+ const failed = allValidations.find((x)=>!x.isValid);
1010
+ if (failed) {
1011
+ return {
1012
+ allPassed: false,
1013
+ failure: {
1014
+ isValid: {
1015
+ result: 'invalid',
1016
+ reason: [
1017
+ 'Failed validation'
1018
+ ]
1019
+ },
1020
+ name: failed.name,
1021
+ severity: failed.severity
1022
+ }
1023
+ };
1024
+ } else {
1025
+ return {
1026
+ allPassed: true
1027
+ };
1028
+ }
588
1029
  }
589
1030
  /**
590
1031
  * Handle a double spend failure.
@@ -634,6 +1075,7 @@ import { ReqResp } from '../reqresp/reqresp.js';
634
1075
  */ async validateBlockProposal(peerId, block) {
635
1076
  const severity = await this.blockProposalValidator.validate(block);
636
1077
  if (severity) {
1078
+ this.logger.debug(`Penalizing peer ${peerId} for block proposal validation failure`);
637
1079
  this.peerManager.penalizePeer(peerId, severity);
638
1080
  return false;
639
1081
  }
@@ -642,13 +1084,16 @@ import { ReqResp } from '../reqresp/reqresp.js';
642
1084
  getPeerScore(peerId) {
643
1085
  return this.node.services.pubsub.score.score(peerId.toString());
644
1086
  }
1087
+ handleAuthRequestFromPeer(authRequest, peerId) {
1088
+ return this.peerManager.handleAuthRequestFromPeer(authRequest, peerId);
1089
+ }
645
1090
  async sendToPeers(message) {
646
1091
  const parent = message.constructor;
647
- const identifier = await message.p2pMessageIdentifier().then((i)=>i.toString());
1092
+ const identifier = await message.p2pMessageLoggingIdentifier().then((i)=>i.toString());
648
1093
  this.logger.trace(`Sending message ${identifier}`, {
649
1094
  p2pMessageIdentifier: identifier
650
1095
  });
651
- const recipientsNum = await this.publishToTopic(parent.p2pTopic, message.toBuffer());
1096
+ const recipientsNum = await this.publishToTopic(this.topicStrings[parent.p2pTopic], message);
652
1097
  this.logger.debug(`Sent message ${identifier} to ${recipientsNum} peers`, {
653
1098
  p2pMessageIdentifier: identifier,
654
1099
  sourcePeer: this.node.peerId.toString()
@@ -673,40 +1118,47 @@ import { ReqResp } from '../reqresp/reqresp.js';
673
1118
  }
674
1119
  _ts_decorate([
675
1120
  trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
676
- [Attributes.BLOCK_NUMBER]: block.blockNumber.toNumber(),
677
- [Attributes.SLOT_NUMBER]: block.slotNumber.toNumber(),
1121
+ [Attributes.SLOT_NUMBER]: block.slotNumber,
678
1122
  [Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
679
- [Attributes.P2P_ID]: await block.p2pMessageIdentifier().then((i)=>i.toString())
1123
+ [Attributes.P2P_ID]: await block.p2pMessageLoggingIdentifier().then((i)=>i.toString())
680
1124
  }))
681
1125
  ], LibP2PService.prototype, "processValidBlockProposal", null);
682
1126
  _ts_decorate([
683
1127
  trackSpan('Libp2pService.broadcastAttestation', async (attestation)=>({
684
- [Attributes.BLOCK_NUMBER]: attestation.payload.header.globalVariables.blockNumber.toNumber(),
685
- [Attributes.SLOT_NUMBER]: attestation.payload.header.globalVariables.slotNumber.toNumber(),
1128
+ [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
686
1129
  [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
687
- [Attributes.P2P_ID]: await attestation.p2pMessageIdentifier().then((i)=>i.toString())
1130
+ [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then((i)=>i.toString())
688
1131
  }))
689
1132
  ], LibP2PService.prototype, "broadcastAttestation", null);
1133
+ _ts_decorate([
1134
+ trackSpan('Libp2pService.validateRequestedBlockTxs', (request)=>({
1135
+ [Attributes.BLOCK_HASH]: request.blockHash.toString()
1136
+ }))
1137
+ ], LibP2PService.prototype, "validateRequestedBlockTxs", null);
690
1138
  _ts_decorate([
691
1139
  trackSpan('Libp2pService.validateRequestedTx', (requestedTxHash, _responseTx)=>({
692
1140
  [Attributes.TX_HASH]: requestedTxHash.toString()
693
1141
  }))
694
- ], LibP2PService.prototype, "validateRequestedTx", null);
1142
+ ], LibP2PService.prototype, "validateRequestedTxs", null);
1143
+ _ts_decorate([
1144
+ trackSpan('Libp2pService.validateRequestedBlock', (requestedBlockNumber, _responseBlock)=>({
1145
+ [Attributes.BLOCK_NUMBER]: requestedBlockNumber.toString()
1146
+ }))
1147
+ ], LibP2PService.prototype, "validateRequestedBlock", null);
695
1148
  _ts_decorate([
696
- trackSpan('Libp2pService.validatePropagatedTx', async (tx)=>({
697
- [Attributes.TX_HASH]: (await tx.getTxHash()).toString()
1149
+ trackSpan('Libp2pService.validatePropagatedTx', (tx)=>({
1150
+ [Attributes.TX_HASH]: tx.getTxHash().toString()
698
1151
  }))
699
1152
  ], LibP2PService.prototype, "validatePropagatedTx", null);
700
1153
  _ts_decorate([
701
1154
  trackSpan('Libp2pService.validateAttestation', async (_, attestation)=>({
702
- [Attributes.BLOCK_NUMBER]: attestation.payload.header.globalVariables.blockNumber.toNumber(),
703
- [Attributes.SLOT_NUMBER]: attestation.payload.header.globalVariables.slotNumber.toNumber(),
1155
+ [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
704
1156
  [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
705
- [Attributes.P2P_ID]: await attestation.p2pMessageIdentifier().then((i)=>i.toString())
1157
+ [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then((i)=>i.toString())
706
1158
  }))
707
1159
  ], LibP2PService.prototype, "validateAttestation", null);
708
1160
  _ts_decorate([
709
1161
  trackSpan('Libp2pService.validateBlockProposal', (_peerId, block)=>({
710
- [Attributes.SLOT_NUMBER]: block.payload.header.globalVariables.slotNumber.toString()
1162
+ [Attributes.SLOT_NUMBER]: block.payload.header.slotNumber.toString()
711
1163
  }))
712
1164
  ], LibP2PService.prototype, "validateBlockProposal", null);