@aztec/p2p 0.0.0-test.0 → 0.0.1-commit.03f7ef2

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 (387) 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 +15 -5
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +60 -25
  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 +75 -190
  14. package/dest/client/p2p_client.d.ts.map +1 -1
  15. package/dest/client/p2p_client.js +381 -183
  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 +216 -65
  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 +127 -26
  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 +227 -7
  44. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  45. package/dest/mem_pools/attestation_pool/mocks.js +10 -16
  46. package/dest/mem_pools/index.d.ts +1 -1
  47. package/dest/mem_pools/instrumentation.d.ts +16 -12
  48. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  49. package/dest/mem_pools/instrumentation.js +57 -35
  50. package/dest/mem_pools/interface.d.ts +3 -4
  51. package/dest/mem_pools/interface.d.ts.map +1 -1
  52. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +64 -14
  53. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  54. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +472 -97
  55. package/dest/mem_pools/tx_pool/index.d.ts +1 -1
  56. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +36 -11
  57. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
  58. package/dest/mem_pools/tx_pool/memory_tx_pool.js +137 -36
  59. package/dest/mem_pools/tx_pool/priority.d.ts +1 -1
  60. package/dest/mem_pools/tx_pool/priority.js +1 -1
  61. package/dest/mem_pools/tx_pool/tx_pool.d.ts +67 -10
  62. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  63. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  64. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  65. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +273 -42
  66. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -2
  67. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  68. package/dest/msg_validators/attestation_validator/attestation_validator.js +45 -9
  69. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
  70. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
  71. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +67 -0
  72. package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
  73. package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
  74. package/dest/msg_validators/attestation_validator/index.js +1 -0
  75. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +6 -2
  76. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
  77. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +73 -12
  78. package/dest/msg_validators/block_proposal_validator/index.d.ts +1 -1
  79. package/dest/msg_validators/index.d.ts +1 -1
  80. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +10 -0
  81. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
  82. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
  83. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
  84. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  85. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +3 -0
  86. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
  87. package/dest/msg_validators/tx_validator/allowed_public_setup.js +27 -0
  88. package/dest/msg_validators/tx_validator/archive_cache.d.ts +14 -0
  89. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -0
  90. package/dest/msg_validators/tx_validator/archive_cache.js +22 -0
  91. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +2 -2
  92. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  93. package/dest/msg_validators/tx_validator/block_header_validator.js +4 -4
  94. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  95. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  96. package/dest/msg_validators/tx_validator/data_validator.js +56 -86
  97. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +1 -3
  98. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  99. package/dest/msg_validators/tx_validator/double_spend_validator.js +21 -27
  100. package/dest/msg_validators/tx_validator/factory.d.ts +16 -0
  101. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
  102. package/dest/msg_validators/tx_validator/factory.js +74 -0
  103. package/dest/msg_validators/tx_validator/gas_validator.d.ts +11 -0
  104. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
  105. package/dest/msg_validators/tx_validator/gas_validator.js +115 -0
  106. package/dest/msg_validators/tx_validator/index.d.ts +8 -1
  107. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  108. package/dest/msg_validators/tx_validator/index.js +7 -0
  109. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +9 -5
  110. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  111. package/dest/msg_validators/tx_validator/metadata_validator.js +39 -20
  112. package/dest/msg_validators/tx_validator/phases_validator.d.ts +14 -0
  113. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
  114. package/dest/msg_validators/tx_validator/phases_validator.js +93 -0
  115. package/dest/msg_validators/tx_validator/test_utils.d.ts +17 -0
  116. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
  117. package/dest/msg_validators/tx_validator/test_utils.js +22 -0
  118. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +13 -0
  119. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
  120. package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
  121. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +8 -0
  122. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -0
  123. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +24 -0
  124. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +1 -1
  125. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  126. package/dest/msg_validators/tx_validator/tx_proof_validator.js +6 -5
  127. package/dest/services/data_store.d.ts +1 -1
  128. package/dest/services/data_store.d.ts.map +1 -1
  129. package/dest/services/discv5/discV5_service.d.ts +10 -9
  130. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  131. package/dest/services/discv5/discV5_service.js +63 -36
  132. package/dest/services/dummy_service.d.ts +50 -11
  133. package/dest/services/dummy_service.d.ts.map +1 -1
  134. package/dest/services/dummy_service.js +88 -5
  135. package/dest/services/encoding.d.ts +26 -7
  136. package/dest/services/encoding.d.ts.map +1 -1
  137. package/dest/services/encoding.js +74 -6
  138. package/dest/services/gossipsub/scoring.d.ts +1 -1
  139. package/dest/services/index.d.ts +5 -1
  140. package/dest/services/index.d.ts.map +1 -1
  141. package/dest/services/index.js +4 -0
  142. package/dest/services/libp2p/instrumentation.d.ts +20 -0
  143. package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
  144. package/dest/services/libp2p/instrumentation.js +164 -0
  145. package/dest/services/libp2p/libp2p_service.d.ts +78 -89
  146. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  147. package/dest/services/libp2p/libp2p_service.js +695 -248
  148. package/dest/services/peer-manager/interface.d.ts +23 -0
  149. package/dest/services/peer-manager/interface.d.ts.map +1 -0
  150. package/dest/services/peer-manager/interface.js +1 -0
  151. package/dest/services/peer-manager/metrics.d.ts +6 -2
  152. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  153. package/dest/services/peer-manager/metrics.js +22 -2
  154. package/dest/services/peer-manager/peer_manager.d.ts +102 -22
  155. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  156. package/dest/services/peer-manager/peer_manager.js +549 -72
  157. package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
  158. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  159. package/dest/services/peer-manager/peer_scoring.js +40 -2
  160. package/dest/services/reqresp/config.d.ts +11 -9
  161. package/dest/services/reqresp/config.d.ts.map +1 -1
  162. package/dest/services/reqresp/config.js +18 -4
  163. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +2 -2
  164. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  165. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +10 -6
  166. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +31 -17
  167. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  168. package/dest/services/reqresp/connection-sampler/connection_sampler.js +142 -84
  169. package/dest/services/reqresp/index.d.ts +3 -2
  170. package/dest/services/reqresp/index.d.ts.map +1 -1
  171. package/dest/services/reqresp/index.js +2 -1
  172. package/dest/services/reqresp/interface.d.ts +73 -24
  173. package/dest/services/reqresp/interface.d.ts.map +1 -1
  174. package/dest/services/reqresp/interface.js +46 -27
  175. package/dest/services/reqresp/metrics.d.ts +1 -1
  176. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  177. package/dest/services/reqresp/protocols/auth.d.ts +43 -0
  178. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
  179. package/dest/services/reqresp/protocols/auth.js +71 -0
  180. package/dest/services/reqresp/protocols/block.d.ts +6 -1
  181. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  182. package/dest/services/reqresp/protocols/block.js +30 -6
  183. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +30 -0
  184. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
  185. package/dest/services/reqresp/protocols/block_txs/bitvector.js +75 -0
  186. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
  187. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
  188. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +39 -0
  189. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +47 -0
  190. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
  191. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
  192. package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
  193. package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
  194. package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
  195. package/dest/services/reqresp/protocols/goodbye.d.ts +3 -5
  196. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
  197. package/dest/services/reqresp/protocols/goodbye.js +7 -7
  198. package/dest/services/reqresp/protocols/index.d.ts +3 -1
  199. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  200. package/dest/services/reqresp/protocols/index.js +2 -0
  201. package/dest/services/reqresp/protocols/ping.d.ts +1 -3
  202. package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
  203. package/dest/services/reqresp/protocols/status.d.ts +40 -7
  204. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  205. package/dest/services/reqresp/protocols/status.js +73 -5
  206. package/dest/services/reqresp/protocols/tx.d.ts +14 -4
  207. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  208. package/dest/services/reqresp/protocols/tx.js +34 -6
  209. package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
  210. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +6 -4
  211. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  212. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
  213. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  214. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  215. package/dest/services/reqresp/rate-limiter/rate_limits.js +21 -1
  216. package/dest/services/reqresp/reqresp.d.ts +24 -66
  217. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  218. package/dest/services/reqresp/reqresp.js +298 -207
  219. package/dest/services/reqresp/status.d.ts +10 -4
  220. package/dest/services/reqresp/status.d.ts.map +1 -1
  221. package/dest/services/reqresp/status.js +9 -2
  222. package/dest/services/service.d.ts +23 -19
  223. package/dest/services/service.d.ts.map +1 -1
  224. package/dest/services/tx_collection/config.d.ts +25 -0
  225. package/dest/services/tx_collection/config.d.ts.map +1 -0
  226. package/dest/services/tx_collection/config.js +58 -0
  227. package/dest/services/tx_collection/fast_tx_collection.d.ts +51 -0
  228. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
  229. package/dest/services/tx_collection/fast_tx_collection.js +300 -0
  230. package/dest/services/tx_collection/index.d.ts +3 -0
  231. package/dest/services/tx_collection/index.d.ts.map +1 -0
  232. package/dest/services/tx_collection/index.js +2 -0
  233. package/dest/services/tx_collection/instrumentation.d.ts +10 -0
  234. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
  235. package/dest/services/tx_collection/instrumentation.js +34 -0
  236. package/dest/services/tx_collection/slow_tx_collection.d.ts +53 -0
  237. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
  238. package/dest/services/tx_collection/slow_tx_collection.js +177 -0
  239. package/dest/services/tx_collection/tx_collection.d.ts +110 -0
  240. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
  241. package/dest/services/tx_collection/tx_collection.js +128 -0
  242. package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
  243. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
  244. package/dest/services/tx_collection/tx_collection_sink.js +111 -0
  245. package/dest/services/tx_collection/tx_source.d.ts +18 -0
  246. package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
  247. package/dest/services/tx_collection/tx_source.js +31 -0
  248. package/dest/services/tx_provider.d.ts +51 -0
  249. package/dest/services/tx_provider.d.ts.map +1 -0
  250. package/dest/services/tx_provider.js +217 -0
  251. package/dest/services/tx_provider_instrumentation.d.ts +16 -0
  252. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
  253. package/dest/services/tx_provider_instrumentation.js +47 -0
  254. package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
  255. package/dest/test-helpers/get-ports.d.ts +1 -1
  256. package/dest/test-helpers/get-ports.d.ts.map +1 -1
  257. package/dest/test-helpers/index.d.ts +2 -1
  258. package/dest/test-helpers/index.d.ts.map +1 -1
  259. package/dest/test-helpers/index.js +1 -0
  260. package/dest/test-helpers/make-enrs.d.ts +1 -1
  261. package/dest/test-helpers/make-enrs.d.ts.map +1 -1
  262. package/dest/test-helpers/make-enrs.js +4 -5
  263. package/dest/test-helpers/make-test-p2p-clients.d.ts +33 -5
  264. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  265. package/dest/test-helpers/make-test-p2p-clients.js +86 -16
  266. package/dest/test-helpers/mock-pubsub.d.ts +59 -0
  267. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
  268. package/dest/test-helpers/mock-pubsub.js +130 -0
  269. package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
  270. package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
  271. package/dest/test-helpers/mock-tx-helpers.js +19 -0
  272. package/dest/test-helpers/reqresp-nodes.d.ts +15 -11
  273. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  274. package/dest/test-helpers/reqresp-nodes.js +62 -28
  275. package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
  276. package/dest/testbench/p2p_client_testbench_worker.js +103 -29
  277. package/dest/testbench/parse_log_file.d.ts +1 -1
  278. package/dest/testbench/parse_log_file.js +4 -4
  279. package/dest/testbench/testbench.d.ts +1 -1
  280. package/dest/testbench/testbench.js +4 -4
  281. package/dest/testbench/worker_client_manager.d.ts +1 -6
  282. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  283. package/dest/testbench/worker_client_manager.js +11 -19
  284. package/dest/types/index.d.ts +4 -2
  285. package/dest/types/index.d.ts.map +1 -1
  286. package/dest/types/index.js +2 -0
  287. package/dest/util.d.ts +24 -16
  288. package/dest/util.d.ts.map +1 -1
  289. package/dest/util.js +75 -69
  290. package/dest/versioning.d.ts +4 -4
  291. package/dest/versioning.d.ts.map +1 -1
  292. package/dest/versioning.js +8 -3
  293. package/package.json +32 -27
  294. package/src/bootstrap/bootstrap.ts +27 -11
  295. package/src/client/factory.ts +139 -53
  296. package/src/client/index.ts +1 -0
  297. package/src/client/interface.ts +198 -0
  298. package/src/client/p2p_client.ts +484 -348
  299. package/src/config.ts +305 -134
  300. package/src/enr/generate-enr.ts +39 -6
  301. package/src/errors/attestation-pool.error.ts +13 -0
  302. package/src/index.ts +4 -0
  303. package/src/mem_pools/attestation_pool/attestation_pool.ts +75 -7
  304. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +266 -67
  305. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +174 -35
  306. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +156 -30
  307. package/src/mem_pools/attestation_pool/mocks.ts +13 -12
  308. package/src/mem_pools/instrumentation.ts +70 -40
  309. package/src/mem_pools/interface.ts +2 -4
  310. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +555 -110
  311. package/src/mem_pools/tx_pool/memory_tx_pool.ts +160 -46
  312. package/src/mem_pools/tx_pool/priority.ts +1 -1
  313. package/src/mem_pools/tx_pool/tx_pool.ts +69 -9
  314. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +224 -35
  315. package/src/msg_validators/attestation_validator/attestation_validator.ts +54 -11
  316. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +91 -0
  317. package/src/msg_validators/attestation_validator/index.ts +1 -0
  318. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +82 -14
  319. package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
  320. package/src/msg_validators/tx_validator/allowed_public_setup.ts +35 -0
  321. package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
  322. package/src/msg_validators/tx_validator/block_header_validator.ts +5 -5
  323. package/src/msg_validators/tx_validator/data_validator.ts +81 -69
  324. package/src/msg_validators/tx_validator/double_spend_validator.ts +19 -17
  325. package/src/msg_validators/tx_validator/factory.ts +110 -0
  326. package/src/msg_validators/tx_validator/gas_validator.ts +134 -0
  327. package/src/msg_validators/tx_validator/index.ts +7 -0
  328. package/src/msg_validators/tx_validator/metadata_validator.ts +59 -22
  329. package/src/msg_validators/tx_validator/phases_validator.ts +116 -0
  330. package/src/msg_validators/tx_validator/test_utils.ts +43 -0
  331. package/src/msg_validators/tx_validator/timestamp_validator.ts +47 -0
  332. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +17 -0
  333. package/src/msg_validators/tx_validator/tx_proof_validator.ts +6 -5
  334. package/src/services/discv5/discV5_service.ts +84 -38
  335. package/src/services/dummy_service.ts +147 -9
  336. package/src/services/encoding.ts +81 -6
  337. package/src/services/index.ts +4 -0
  338. package/src/services/libp2p/instrumentation.ts +167 -0
  339. package/src/services/libp2p/libp2p_service.ts +865 -298
  340. package/src/services/peer-manager/interface.ts +29 -0
  341. package/src/services/peer-manager/metrics.ts +26 -1
  342. package/src/services/peer-manager/peer_manager.ts +654 -78
  343. package/src/services/peer-manager/peer_scoring.ts +46 -3
  344. package/src/services/reqresp/config.ts +26 -9
  345. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +12 -6
  346. package/src/services/reqresp/connection-sampler/connection_sampler.ts +148 -95
  347. package/src/services/reqresp/index.ts +2 -0
  348. package/src/services/reqresp/interface.ts +92 -37
  349. package/src/services/reqresp/metrics.ts +4 -1
  350. package/src/services/reqresp/protocols/auth.ts +83 -0
  351. package/src/services/reqresp/protocols/block.ts +26 -4
  352. package/src/services/reqresp/protocols/block_txs/bitvector.ts +90 -0
  353. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +53 -0
  354. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +79 -0
  355. package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
  356. package/src/services/reqresp/protocols/goodbye.ts +9 -7
  357. package/src/services/reqresp/protocols/index.ts +2 -0
  358. package/src/services/reqresp/protocols/status.ts +118 -5
  359. package/src/services/reqresp/protocols/tx.ts +36 -8
  360. package/src/services/reqresp/rate-limiter/rate_limiter.ts +12 -3
  361. package/src/services/reqresp/rate-limiter/rate_limits.ts +21 -1
  362. package/src/services/reqresp/reqresp.ts +387 -256
  363. package/src/services/reqresp/status.ts +12 -3
  364. package/src/services/service.ts +45 -21
  365. package/src/services/tx_collection/config.ts +84 -0
  366. package/src/services/tx_collection/fast_tx_collection.ts +341 -0
  367. package/src/services/tx_collection/index.ts +2 -0
  368. package/src/services/tx_collection/instrumentation.ts +43 -0
  369. package/src/services/tx_collection/slow_tx_collection.ts +233 -0
  370. package/src/services/tx_collection/tx_collection.ts +216 -0
  371. package/src/services/tx_collection/tx_collection_sink.ts +129 -0
  372. package/src/services/tx_collection/tx_source.ts +37 -0
  373. package/src/services/tx_provider.ts +229 -0
  374. package/src/services/tx_provider_instrumentation.ts +61 -0
  375. package/src/test-helpers/index.ts +1 -0
  376. package/src/test-helpers/make-enrs.ts +4 -5
  377. package/src/test-helpers/make-test-p2p-clients.ts +111 -21
  378. package/src/test-helpers/mock-pubsub.ts +188 -0
  379. package/src/test-helpers/mock-tx-helpers.ts +24 -0
  380. package/src/test-helpers/reqresp-nodes.ts +87 -36
  381. package/src/testbench/p2p_client_testbench_worker.ts +151 -25
  382. package/src/testbench/parse_log_file.ts +4 -4
  383. package/src/testbench/testbench.ts +4 -4
  384. package/src/testbench/worker_client_manager.ts +17 -23
  385. package/src/types/index.ts +2 -0
  386. package/src/util.ts +105 -91
  387. package/src/versioning.ts +11 -4
@@ -4,25 +4,27 @@ 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 { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
7
+ import { GENESIS_BLOCK_HEADER_HASH, INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
8
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
8
9
  import { createLogger } from '@aztec/foundation/log';
10
+ import { DateProvider } from '@aztec/foundation/timer';
11
+ import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
12
+ import { tryStop } from '@aztec/stdlib/interfaces/server';
9
13
  import { Attributes, TraceableL2BlockStream, WithTracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
10
14
  import { getP2PDefaultConfig } from '../config.js';
11
15
  import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
12
- /**
13
- * Enum defining the possible states of the p2p client.
14
- */ export var P2PClientState = /*#__PURE__*/ function(P2PClientState) {
15
- P2PClientState[P2PClientState["IDLE"] = 0] = "IDLE";
16
- P2PClientState[P2PClientState["SYNCHING"] = 1] = "SYNCHING";
17
- P2PClientState[P2PClientState["RUNNING"] = 2] = "RUNNING";
18
- P2PClientState[P2PClientState["STOPPED"] = 3] = "STOPPED";
19
- return P2PClientState;
20
- }({});
16
+ import { chunkTxHashesRequest } from '../services/reqresp/protocols/tx.js';
17
+ import { TxProvider } from '../services/tx_provider.js';
18
+ import { P2PClientState } from './interface.js';
21
19
  /**
22
20
  * The P2P client implementation.
23
21
  */ export class P2PClient extends WithTracer {
22
+ store;
24
23
  l2BlockSource;
25
24
  p2pService;
25
+ txCollection;
26
+ _dateProvider;
27
+ telemetry;
26
28
  log;
27
29
  /** The JS promise that will be running to keep the client's data in sync. Can be interrupted if the client is stopped. */ runningPromise;
28
30
  currentState;
@@ -30,102 +32,159 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
30
32
  syncResolve;
31
33
  latestBlockNumberAtStart;
32
34
  provenBlockNumberAtStart;
35
+ finalizedBlockNumberAtStart;
33
36
  synchedBlockHashes;
34
37
  synchedLatestBlockNumber;
35
38
  synchedProvenBlockNumber;
39
+ synchedFinalizedBlockNumber;
40
+ synchedLatestSlot;
36
41
  txPool;
37
42
  attestationPool;
38
- /** How many slots to keep attestations for. */ keepAttestationsInPoolFor;
39
- /** How many slots to keep proven txs for. */ keepProvenTxsFor;
43
+ config;
40
44
  blockStream;
45
+ txProvider;
46
+ validatorAddresses;
41
47
  /**
42
48
  * In-memory P2P client constructor.
43
49
  * @param store - The client's instance of the KV store.
44
50
  * @param l2BlockSource - P2P client's source for fetching existing blocks.
45
51
  * @param txPool - The client's instance of a transaction pool. Defaults to in-memory implementation.
46
52
  * @param p2pService - The concrete instance of p2p networking to use.
47
- * @param keepProvenTxsFor - How many blocks have to pass after a block is proven before its txs are deleted (zero to delete immediately once proven).
48
53
  * @param log - A logger.
49
- */ constructor(_clientType, store, l2BlockSource, mempools, p2pService, config = {}, telemetry = getTelemetryClient(), log = createLogger('p2p')){
50
- super(telemetry, 'P2PClient'), this.l2BlockSource = l2BlockSource, this.p2pService = p2pService, this.log = log, this.currentState = 0, this.syncPromise = Promise.resolve(), this.syncResolve = undefined, this.latestBlockNumberAtStart = -1, this.provenBlockNumberAtStart = -1;
51
- const { keepProvenTxsInPoolFor, blockCheckIntervalMS, blockRequestBatchSize, keepAttestationsInPoolFor } = {
54
+ */ constructor(_clientType, store, l2BlockSource, mempools, p2pService, txCollection, config = {}, _dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('p2p')){
55
+ super(telemetry, 'P2PClient'), this.store = store, this.l2BlockSource = l2BlockSource, this.p2pService = p2pService, this.txCollection = txCollection, this._dateProvider = _dateProvider, this.telemetry = telemetry, this.log = log, this.currentState = P2PClientState.IDLE, this.syncPromise = Promise.resolve(), this.syncResolve = undefined, this.latestBlockNumberAtStart = -1, this.provenBlockNumberAtStart = -1, this.finalizedBlockNumberAtStart = -1, this.validatorAddresses = [];
56
+ this.config = {
52
57
  ...getP2PDefaultConfig(),
53
58
  ...config
54
59
  };
55
- this.keepProvenTxsFor = keepProvenTxsInPoolFor;
56
- this.keepAttestationsInPoolFor = keepAttestationsInPoolFor;
57
- const tracer = telemetry.getTracer('P2PL2BlockStream');
58
- const logger = createLogger('p2p:l2-block-stream');
59
- this.blockStream = new TraceableL2BlockStream(l2BlockSource, this, this, tracer, 'P2PL2BlockStream', logger, {
60
- batchSize: blockRequestBatchSize,
61
- pollIntervalMS: blockCheckIntervalMS
60
+ this.txPool = mempools.txPool;
61
+ this.attestationPool = mempools.attestationPool;
62
+ this.txProvider = new TxProvider(this.txCollection, this.txPool, this, this.log.createChild('tx-provider'), this.telemetry);
63
+ // Default to collecting all txs when we see a valid proposal
64
+ // This can be overridden by the validator client to attest, and it will call getTxsForBlockProposal on its own
65
+ // TODO(palla/txs): We should not trigger a request for txs on a proposal before fully validating it. We need to bring
66
+ // validator-client code into here so we can validate a proposal is reasonable.
67
+ this.registerBlockProposalHandler(async (block, sender)=>{
68
+ this.log.debug(`Received block proposal from ${sender.toString()}`);
69
+ // TODO(palla/txs): Need to subtract validatorReexecuteDeadlineMs from this deadline (see ValidatorClient.getReexecutionDeadline)
70
+ const constants = this.txCollection.getConstants();
71
+ const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(block.slotNumber + 1), constants));
72
+ const deadline = new Date(nextSlotTimestampSeconds * 1000);
73
+ const parentBlock = await this.l2BlockSource.getBlockHeaderByArchive(block.payload.header.lastArchiveRoot);
74
+ if (!parentBlock) {
75
+ this.log.debug(`Cannot collect txs for proposal as parent block not found`);
76
+ return;
77
+ }
78
+ const blockNumber = BlockNumber(parentBlock.getBlockNumber() + 1);
79
+ await this.txProvider.getTxsForBlockProposal(block, blockNumber, {
80
+ pinnedPeer: sender,
81
+ deadline
82
+ });
83
+ return undefined;
62
84
  });
85
+ // REFACTOR: Try replacing these with an L2TipsStore
63
86
  this.synchedBlockHashes = store.openMap('p2p_pool_block_hashes');
64
87
  this.synchedLatestBlockNumber = store.openSingleton('p2p_pool_last_l2_block');
65
88
  this.synchedProvenBlockNumber = store.openSingleton('p2p_pool_last_proven_l2_block');
66
- this.txPool = mempools.txPool;
67
- this.attestationPool = mempools.attestationPool;
89
+ this.synchedFinalizedBlockNumber = store.openSingleton('p2p_pool_last_finalized_l2_block');
90
+ this.synchedLatestSlot = store.openSingleton('p2p_pool_last_l2_slot');
91
+ }
92
+ registerThisValidatorAddresses(addresses) {
93
+ this.validatorAddresses = [
94
+ ...addresses
95
+ ];
96
+ this.p2pService.registerThisValidatorAddresses(this.validatorAddresses);
97
+ }
98
+ clear() {
99
+ return this.store.clear();
68
100
  }
69
101
  isP2PClient() {
70
102
  return true;
71
103
  }
104
+ getTxProvider() {
105
+ return this.txProvider;
106
+ }
72
107
  getPeers(includePending) {
73
108
  return Promise.resolve(this.p2pService.getPeers(includePending));
74
109
  }
75
110
  getL2BlockHash(number) {
76
111
  return this.synchedBlockHashes.getAsync(number);
77
112
  }
113
+ updateP2PConfig(config) {
114
+ this.txPool.updateConfig(config);
115
+ this.p2pService.updateConfig(config);
116
+ return Promise.resolve();
117
+ }
78
118
  async getL2Tips() {
79
119
  const latestBlockNumber = await this.getSyncedLatestBlockNum();
80
120
  let latestBlockHash;
81
121
  const provenBlockNumber = await this.getSyncedProvenBlockNum();
82
122
  let provenBlockHash;
123
+ const finalizedBlockNumber = await this.getSyncedFinalizedBlockNum();
124
+ let finalizedBlockHash;
83
125
  if (latestBlockNumber > 0) {
84
126
  latestBlockHash = await this.synchedBlockHashes.getAsync(latestBlockNumber);
85
127
  if (typeof latestBlockHash === 'undefined') {
86
- this.log.warn(`Block hash for latest block ${latestBlockNumber} not found`);
87
- throw new Error();
128
+ throw new Error(`Block hash for latest block ${latestBlockNumber} not found in p2p client`);
88
129
  }
89
130
  }
90
131
  if (provenBlockNumber > 0) {
91
132
  provenBlockHash = await this.synchedBlockHashes.getAsync(provenBlockNumber);
92
133
  if (typeof provenBlockHash === 'undefined') {
93
- this.log.warn(`Block hash for proven block ${provenBlockNumber} not found`);
94
- throw new Error();
134
+ throw new Error(`Block hash for proven block ${provenBlockNumber} not found in p2p client`);
135
+ }
136
+ }
137
+ if (finalizedBlockNumber > 0) {
138
+ finalizedBlockHash = await this.synchedBlockHashes.getAsync(finalizedBlockNumber);
139
+ if (typeof finalizedBlockHash === 'undefined') {
140
+ throw new Error(`Block hash for finalized block ${finalizedBlockNumber} not found in p2p client`);
95
141
  }
96
142
  }
97
- return Promise.resolve({
143
+ const genesisHash = GENESIS_BLOCK_HEADER_HASH.toString();
144
+ return {
98
145
  latest: {
99
- hash: latestBlockHash,
146
+ hash: latestBlockHash ?? genesisHash,
100
147
  number: latestBlockNumber
101
148
  },
102
149
  proven: {
103
- hash: provenBlockHash,
150
+ hash: provenBlockHash ?? genesisHash,
104
151
  number: provenBlockNumber
105
152
  },
106
153
  finalized: {
107
- hash: provenBlockHash,
108
- number: provenBlockNumber
154
+ hash: finalizedBlockHash ?? genesisHash,
155
+ number: finalizedBlockNumber
109
156
  }
110
- });
157
+ };
111
158
  }
112
159
  async handleBlockStreamEvent(event) {
113
160
  this.log.debug(`Handling block stream event ${event.type}`);
114
161
  switch(event.type){
115
162
  case 'blocks-added':
116
- await this.handleLatestL2Blocks(event.blocks);
163
+ await this.handleLatestL2Blocks(event.blocks.map((b)=>b.block.toL2Block()));
117
164
  break;
118
165
  case 'chain-finalized':
119
- break;
166
+ {
167
+ // TODO (alexg): I think we can prune the block hashes map here
168
+ await this.setBlockHash(event.block);
169
+ const from = BlockNumber(await this.getSyncedFinalizedBlockNum() + 1);
170
+ const limit = event.block.number - from + 1;
171
+ if (limit > 0) {
172
+ const oldBlocks = await this.l2BlockSource.getBlocks(from, limit);
173
+ await this.handleFinalizedL2Blocks(oldBlocks.map((b)=>b.toL2Block()));
174
+ }
175
+ break;
176
+ }
120
177
  case 'chain-proven':
121
178
  {
122
- const from = await this.getSyncedProvenBlockNum() + 1;
123
- const limit = event.blockNumber - from + 1;
124
- await this.handleProvenL2Blocks(await this.l2BlockSource.getBlocks(from, limit));
179
+ await this.setBlockHash(event.block);
180
+ this.txCollection.stopCollectingForBlocksUpTo(event.block.number);
181
+ await this.synchedProvenBlockNumber.set(event.block.number);
125
182
  break;
126
183
  }
127
184
  case 'chain-pruned':
128
- await this.handlePruneL2Blocks(event.blockNumber);
185
+ await this.setBlockHash(event.block);
186
+ this.txCollection.stopCollectingForBlocksAfter(event.block.number);
187
+ await this.handlePruneL2Blocks(event.block.number);
129
188
  break;
130
189
  default:
131
190
  {
@@ -134,6 +193,11 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
134
193
  }
135
194
  }
136
195
  }
196
+ async setBlockHash(block) {
197
+ if (block.hash !== undefined) {
198
+ await this.synchedBlockHashes.set(block.number, block.hash.toString());
199
+ }
200
+ }
137
201
  #assertIsReady() {
138
202
  // this.log.info('Checking if p2p client is ready, current state: ', this.currentState);
139
203
  if (!this.isReady()) {
@@ -144,54 +208,106 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
144
208
  * Starts the P2P client.
145
209
  * @returns An empty promise signalling the synching process.
146
210
  */ async start() {
147
- if (this.currentState === 3) {
211
+ if (this.currentState === P2PClientState.STOPPED) {
148
212
  throw new Error('P2P client already stopped');
149
213
  }
150
- if (this.currentState !== 0) {
214
+ if (this.currentState !== P2PClientState.IDLE) {
151
215
  return this.syncPromise;
152
216
  }
153
217
  // get the current latest block numbers
154
- this.latestBlockNumberAtStart = await this.l2BlockSource.getBlockNumber();
155
- this.provenBlockNumberAtStart = await this.l2BlockSource.getProvenBlockNumber();
218
+ const latestBlockNumbers = await this.l2BlockSource.getL2Tips();
219
+ this.latestBlockNumberAtStart = latestBlockNumbers.latest.number;
220
+ this.provenBlockNumberAtStart = latestBlockNumbers.proven.number;
221
+ this.finalizedBlockNumberAtStart = latestBlockNumbers.finalized.number;
156
222
  const syncedLatestBlock = await this.getSyncedLatestBlockNum() + 1;
157
223
  const syncedProvenBlock = await this.getSyncedProvenBlockNum() + 1;
158
- // if there are blocks to be retrieved, go to a synching state
159
- if (syncedLatestBlock <= this.latestBlockNumberAtStart || syncedProvenBlock <= this.provenBlockNumberAtStart) {
160
- this.setCurrentState(1);
224
+ const syncedFinalizedBlock = await this.getSyncedFinalizedBlockNum() + 1;
225
+ if (await this.txPool.isEmpty() && await this.attestationPool.isEmpty()) {
226
+ // if mempools are empty, we don't care about syncing prior blocks
227
+ this.initBlockStream(BlockNumber(this.latestBlockNumberAtStart));
228
+ this.setCurrentState(P2PClientState.RUNNING);
229
+ this.syncPromise = Promise.resolve();
230
+ await this.p2pService.start();
231
+ this.log.info(`Starting p2p client from block ${this.latestBlockNumberAtStart} with empty mempools`);
232
+ } else if (syncedLatestBlock <= this.latestBlockNumberAtStart || syncedProvenBlock <= this.provenBlockNumberAtStart || syncedFinalizedBlock <= this.finalizedBlockNumberAtStart) {
233
+ // if there are blocks to be retrieved, go to a synching state
234
+ // this gets resolved on `startServiceIfSynched`
235
+ this.initBlockStream();
236
+ this.setCurrentState(P2PClientState.SYNCHING);
161
237
  this.syncPromise = new Promise((resolve)=>{
162
238
  this.syncResolve = resolve;
163
239
  });
164
- this.log.verbose(`Starting sync from ${syncedLatestBlock} (last proven ${syncedProvenBlock})`);
240
+ this.log.info(`Initiating p2p sync from ${syncedLatestBlock}`, {
241
+ syncedLatestBlock,
242
+ syncedProvenBlock,
243
+ syncedFinalizedBlock
244
+ });
165
245
  } else {
166
246
  // if no blocks to be retrieved, go straight to running
167
- this.setCurrentState(2);
247
+ this.initBlockStream();
248
+ this.setCurrentState(P2PClientState.RUNNING);
168
249
  this.syncPromise = Promise.resolve();
169
250
  await this.p2pService.start();
170
- this.log.debug(`Block ${syncedLatestBlock} (proven ${syncedProvenBlock}) already beyond current block`);
251
+ this.log.info(`Starting P2P client synced to ${syncedLatestBlock}`, {
252
+ syncedLatestBlock,
253
+ syncedProvenBlock,
254
+ syncedFinalizedBlock
255
+ });
171
256
  }
172
257
  this.blockStream.start();
173
- this.log.verbose(`Started block downloader from block ${syncedLatestBlock}`);
258
+ await this.txCollection.start();
174
259
  return this.syncPromise;
175
260
  }
261
+ addReqRespSubProtocol(subProtocol, handler, validator) {
262
+ return this.p2pService.addReqRespSubProtocol(subProtocol, handler, validator);
263
+ }
264
+ initBlockStream(startingBlock) {
265
+ if (!this.blockStream) {
266
+ const { blockRequestBatchSize: batchSize, blockCheckIntervalMS: pollIntervalMS } = this.config;
267
+ this.blockStream = new TraceableL2BlockStream(this.l2BlockSource, this, this, this.telemetry.getTracer('P2PL2BlockStream'), 'P2PL2BlockStream', createLogger(`${this.log.module}:l2-block-stream`), {
268
+ batchSize,
269
+ pollIntervalMS,
270
+ startingBlock
271
+ });
272
+ }
273
+ }
176
274
  /**
177
275
  * Allows consumers to stop the instance of the P2P client.
178
276
  * 'ready' will now return 'false' and the running promise that keeps the client synced is interrupted.
179
277
  */ async stop() {
180
278
  this.log.debug('Stopping p2p client...');
279
+ await tryStop(this.txCollection);
280
+ this.log.debug('Stopped tx collection service');
181
281
  await this.p2pService.stop();
182
282
  this.log.debug('Stopped p2p service');
183
- await this.blockStream.stop();
283
+ await this.blockStream?.stop();
184
284
  this.log.debug('Stopped block downloader');
185
285
  await this.runningPromise;
186
- this.setCurrentState(3);
187
- this.log.info('P2P client stopped.');
286
+ this.setCurrentState(P2PClientState.STOPPED);
287
+ this.log.info('P2P client stopped');
288
+ }
289
+ /** Triggers a sync to the archiver. Used for testing. */ async sync() {
290
+ this.initBlockStream();
291
+ await this.blockStream.sync();
188
292
  }
189
293
  broadcastProposal(proposal) {
190
- this.log.verbose(`Broadcasting proposal for slot ${proposal.slotNumber.toNumber()} to peers`);
294
+ this.log.verbose(`Broadcasting proposal for slot ${proposal.slotNumber} to peers`);
191
295
  return this.p2pService.propagate(proposal);
192
296
  }
297
+ async broadcastAttestations(attestations) {
298
+ this.log.verbose(`Broadcasting ${attestations.length} attestations to peers`);
299
+ await Promise.all(attestations.map((att)=>this.p2pService.propagate(att)));
300
+ }
193
301
  async getAttestationsForSlot(slot, proposalId) {
194
- return await this.attestationPool?.getAttestationsForSlot(slot, proposalId) ?? [];
302
+ return await (proposalId ? this.attestationPool.getAttestationsForSlotAndProposal(slot, proposalId) : this.attestationPool.getAttestationsForSlot(slot));
303
+ }
304
+ addAttestations(attestations) {
305
+ return this.attestationPool.addAttestations(attestations);
306
+ }
307
+ deleteAttestation(attestation) {
308
+ return this.attestationPool.deleteAttestations([
309
+ attestation
310
+ ]);
195
311
  }
196
312
  // REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
197
313
  // ^ This pattern is not my favorite (md)
@@ -199,52 +315,27 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
199
315
  this.p2pService.registerBlockReceivedCallback(handler);
200
316
  }
201
317
  /**
202
- * Requests the transactions with the given hashes from the network.
203
- *
204
- * If a transaction can be retrieved, it will be returned, if not an undefined
205
- * will be returned. In place.
206
- *
207
- * @param txHashes - The hashes of the transactions to request.
208
- * @returns A promise that resolves to an array of transactions or undefined.
209
- */ async requestTxs(txHashes) {
210
- const res = await this.p2pService.sendBatchRequest(ReqRespSubProtocol.TX, txHashes);
211
- return Promise.resolve(res ?? []);
212
- }
213
- /**
214
- * Uses the Request Response protocol to request a transaction from the network.
215
- *
216
- * If the underlying request response protocol fails, then we return undefined.
217
- * If it succeeds then we add the transaction to our transaction pool and return.
218
- *
219
- * @param txHash - The hash of the transaction to request.
220
- * @returns A promise that resolves to a transaction or undefined.
221
- */ async requestTxByHash(txHash) {
222
- const tx = await this.p2pService.sendRequest(ReqRespSubProtocol.TX, txHash);
223
- if (tx) {
224
- this.log.debug(`Received tx ${txHash.toString()} from peer`);
225
- await this.txPool.addTxs([
226
- tx
227
- ]);
228
- } else {
229
- this.log.debug(`Failed to receive tx ${txHash.toString()} from peer`);
230
- }
231
- return tx;
232
- }
233
- /**
234
318
  * Uses the batched Request Response protocol to request a set of transactions from the network.
235
- */ async requestTxsByHash(txHashes) {
236
- const txs = await this.p2pService.sendBatchRequest(ReqRespSubProtocol.TX, txHashes) ?? [];
237
- await this.txPool.addTxs(txs);
319
+ */ async requestTxsByHash(txHashes, pinnedPeerId) {
320
+ const timeoutMs = 8000; // Longer timeout for now
321
+ const maxRetryAttempts = 10; // Keep retrying within the timeout
322
+ const requests = chunkTxHashesRequest(txHashes);
323
+ const maxPeers = Math.min(Math.ceil(requests.length / 3), 10);
324
+ const txBatches = await this.p2pService.sendBatchRequest(ReqRespSubProtocol.TX, requests, pinnedPeerId, timeoutMs, maxPeers, maxRetryAttempts);
325
+ const txs = txBatches.flat();
326
+ if (txs.length > 0) {
327
+ await this.txPool.addTxs(txs);
328
+ }
238
329
  const txHashesStr = txHashes.map((tx)=>tx.toString()).join(', ');
239
- this.log.debug(`Received batched txs ${txHashesStr} (${txs.length} / ${txHashes.length}}) from peers`);
330
+ this.log.debug(`Requested txs ${txHashesStr} (${txs.length} / ${txHashes.length}) from peers`);
331
+ // We return all transactions, even the not found ones to the caller, such they can handle missing items themselves.
240
332
  return txs;
241
333
  }
242
- getPendingTxs() {
243
- return Promise.resolve(this.getTxs('pending'));
334
+ getPendingTxs(limit, after) {
335
+ return this.getTxs('pending', limit, after);
244
336
  }
245
- async getPendingTxCount() {
246
- const pendingTxs = await this.txPool.getPendingTxHashes();
247
- return pendingTxs.length;
337
+ getPendingTxCount() {
338
+ return this.txPool.getPendingTxCount();
248
339
  }
249
340
  async *iteratePendingTxs() {
250
341
  for (const txHash of (await this.txPool.getPendingTxHashes())){
@@ -256,22 +347,50 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
256
347
  }
257
348
  /**
258
349
  * Returns all transactions in the transaction pool.
350
+ * @param filter - The type of txs to return
351
+ * @param limit - How many txs to return
352
+ * @param after - If paginating, the last known tx hash. Will return txs after this hash
259
353
  * @returns An array of Txs.
260
- */ async getTxs(filter) {
354
+ */ async getTxs(filter, limit, after) {
355
+ if (limit !== undefined && limit <= 0) {
356
+ throw new TypeError('limit must be greater than 0');
357
+ }
358
+ let txs = undefined;
359
+ let txHashes;
261
360
  if (filter === 'all') {
262
- return this.txPool.getAllTxs();
361
+ txs = await this.txPool.getAllTxs();
362
+ txHashes = await Promise.all(txs.map((tx)=>tx.getTxHash()));
263
363
  } else if (filter === 'mined') {
264
- const minedHashes = await this.txPool.getMinedTxHashes();
265
- const minedTx = await Promise.all(minedHashes.map(([txHash])=>this.txPool.getTxByHash(txHash)));
266
- return minedTx.filter((tx)=>!!tx);
364
+ const minedTxHashes = await this.txPool.getMinedTxHashes();
365
+ txHashes = minedTxHashes.map(([txHash])=>txHash);
267
366
  } else if (filter === 'pending') {
268
- const pendingHashses = await this.txPool.getPendingTxHashes();
269
- const pendingTxs = await Promise.all(pendingHashses.map((txHash)=>this.txPool.getTxByHash(txHash)));
270
- return pendingTxs.filter((tx)=>!!tx);
367
+ txHashes = await this.txPool.getPendingTxHashes();
271
368
  } else {
272
369
  const _ = filter;
273
370
  throw new Error(`Unknown filter ${filter}`);
274
371
  }
372
+ let startIndex = 0;
373
+ let endIndex = undefined;
374
+ if (after) {
375
+ startIndex = txHashes.findIndex((txHash)=>after.equals(txHash));
376
+ // if we can't find the last tx in our set then return an empty array as pagination is no longer valid.
377
+ if (startIndex === -1) {
378
+ return [];
379
+ }
380
+ // increment by one because we don't want to return the same tx again
381
+ startIndex++;
382
+ }
383
+ if (limit !== undefined) {
384
+ endIndex = startIndex + limit;
385
+ }
386
+ txHashes = txHashes.slice(startIndex, endIndex);
387
+ if (txs) {
388
+ txs = txs.slice(startIndex, endIndex);
389
+ } else {
390
+ const maybeTxs = await Promise.all(txHashes.map((txHash)=>this.txPool.getTxByHash(txHash)));
391
+ txs = maybeTxs.filter((tx)=>!!tx);
392
+ }
393
+ return txs;
275
394
  }
276
395
  /**
277
396
  * Returns a transaction in the transaction pool by its hash.
@@ -281,23 +400,21 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
281
400
  return this.txPool.getTxByHash(txHash);
282
401
  }
283
402
  /**
284
- * Returns a transaction in the transaction pool by its hash.
285
- * If the transaction is not in the pool, it will be requested from the network.
286
- * @param txHash - Hash of the transaction to look for in the pool.
287
- * @returns A single tx or undefined.
288
- */ async getTxByHash(txHash) {
289
- const tx = await this.txPool.getTxByHash(txHash);
290
- if (tx) {
291
- return tx;
292
- }
293
- return this.requestTxByHash(txHash);
403
+ * Returns transactions in the transaction pool by hash.
404
+ * @param txHashes - Hashes of the transactions to look for.
405
+ * @returns The txs found, in the same order as the requested hashes. If a tx is not found, it will be undefined.
406
+ */ getTxsByHashFromPool(txHashes) {
407
+ return this.txPool.getTxsByHash(txHashes);
408
+ }
409
+ hasTxsInPool(txHashes) {
410
+ return this.txPool.hasTxs(txHashes);
294
411
  }
295
412
  /**
296
413
  * Returns transactions in the transaction pool by hash.
297
414
  * If a transaction is not in the pool, it will be requested from the network.
298
415
  * @param txHashes - Hashes of the transactions to look for.
299
- * @returns The txs found, not necessarily on the same order as the hashes.
300
- */ async getTxsByHash(txHashes) {
416
+ * @returns The txs found, or undefined if not found in the order requested.
417
+ */ async getTxsByHash(txHashes, pinnedPeerId) {
301
418
  const txs = await Promise.all(txHashes.map((txHash)=>this.txPool.getTxByHash(txHash)));
302
419
  const missingTxHashes = txs.map((tx, index)=>[
303
420
  tx,
@@ -306,8 +423,27 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
306
423
  if (missingTxHashes.length === 0) {
307
424
  return txs;
308
425
  }
309
- const missingTxs = await this.requestTxsByHash(missingTxHashes);
310
- return txs.filter((tx)=>!!tx).concat(missingTxs);
426
+ const missingTxs = await this.requestTxsByHash(missingTxHashes, pinnedPeerId);
427
+ // TODO: optimize
428
+ // Merge the found txs in order
429
+ const mergingTxs = txHashes.map((txHash)=>{
430
+ // Is it in the txs list from the mempool?
431
+ for (const tx of txs){
432
+ if (tx !== undefined && tx.getTxHash().equals(txHash)) {
433
+ return tx;
434
+ }
435
+ }
436
+ // Is it in the fetched missing txs?
437
+ // Note: this is an O(n^2) operation, but we expect the number of missing txs to be small.
438
+ for (const tx of missingTxs){
439
+ if (tx.getTxHash().equals(txHash)) {
440
+ return tx;
441
+ }
442
+ }
443
+ // Otherwise return undefined
444
+ return undefined;
445
+ });
446
+ return mergingTxs;
311
447
  }
312
448
  /**
313
449
  * Returns an archived transaction in the transaction pool by its hash.
@@ -321,11 +457,20 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
321
457
  * @param tx - The tx to verify.
322
458
  * @returns Empty promise.
323
459
  **/ async sendTx(tx) {
324
- this.#assertIsReady();
325
- await this.txPool.addTxs([
460
+ const addedCount = await this.addTxsToPool([
326
461
  tx
327
462
  ]);
328
- this.p2pService.propagate(tx);
463
+ const txAddedSuccessfully = addedCount === 1;
464
+ if (txAddedSuccessfully) {
465
+ await this.p2pService.propagate(tx);
466
+ }
467
+ }
468
+ /**
469
+ * Adds transactions to the pool. Does not send to peers or validate the txs.
470
+ * @param txs - The transactions.
471
+ **/ async addTxsToPool(txs) {
472
+ this.#assertIsReady();
473
+ return await this.txPool.addTxs(txs);
329
474
  }
330
475
  /**
331
476
  * Returns whether the given tx hash is flagged as pending or mined.
@@ -353,26 +498,32 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
353
498
  * Public function to check if the p2p client is fully synced and ready to receive txs.
354
499
  * @returns True if the P2P client is ready to receive txs.
355
500
  */ isReady() {
356
- return this.currentState === 2;
501
+ return this.currentState === P2PClientState.RUNNING;
357
502
  }
358
503
  /**
359
504
  * Public function to check the latest block number that the P2P client is synced to.
360
505
  * @returns Block number of latest L2 Block we've synced with.
361
506
  */ async getSyncedLatestBlockNum() {
362
- return await this.synchedLatestBlockNumber.getAsync() ?? INITIAL_L2_BLOCK_NUM - 1;
507
+ return await this.synchedLatestBlockNumber.getAsync() ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
363
508
  }
364
509
  /**
365
510
  * Public function to check the latest proven block number that the P2P client is synced to.
366
511
  * @returns Block number of latest proven L2 Block we've synced with.
367
512
  */ async getSyncedProvenBlockNum() {
368
- return await this.synchedProvenBlockNumber.getAsync() ?? INITIAL_L2_BLOCK_NUM - 1;
513
+ return await this.synchedProvenBlockNumber.getAsync() ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
514
+ }
515
+ async getSyncedFinalizedBlockNum() {
516
+ return await this.synchedFinalizedBlockNumber.getAsync() ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
517
+ }
518
+ /** Returns latest L2 slot for which we have seen an L2 block. */ async getSyncedLatestSlot() {
519
+ return await this.synchedLatestSlot.getAsync() ?? BigInt(0);
369
520
  }
370
521
  /**
371
522
  * Method to check the status the p2p client.
372
523
  * @returns Information about p2p client status: state & syncedToBlockNum.
373
524
  */ async getStatus() {
374
525
  const blockNumber = await this.getSyncedLatestBlockNum();
375
- const blockHash = blockNumber === 0 ? '' : await this.l2BlockSource.getBlockHeader(blockNumber).then((header)=>header?.hash()).then((hash)=>hash?.toString());
526
+ const blockHash = blockNumber === 0 ? GENESIS_BLOCK_HEADER_HASH.toString() : await this.l2BlockSource.getBlockHeader(blockNumber).then((header)=>header?.hash()).then((hash)=>hash?.toString());
376
527
  return {
377
528
  state: this.currentState,
378
529
  syncedToL2Block: {
@@ -388,18 +539,7 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
388
539
  */ async markTxsAsMinedFromBlocks(blocks) {
389
540
  for (const block of blocks){
390
541
  const txHashes = block.body.txEffects.map((txEffect)=>txEffect.txHash);
391
- await this.txPool.markAsMined(txHashes, block.number);
392
- }
393
- }
394
- /**
395
- * Deletes txs from these blocks.
396
- * @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
397
- * @returns Empty promise.
398
- */ async deleteTxsFromBlocks(blocks) {
399
- this.log.debug(`Deleting txs from blocks ${blocks[0].number} to ${blocks[blocks.length - 1].number}`);
400
- for (const block of blocks){
401
- const txHashes = block.body.txEffects.map((txEffect)=>txEffect.txHash);
402
- await this.txPool.deleteTxs(txHashes);
542
+ await this.txPool.markAsMined(txHashes, block.header);
403
543
  }
404
544
  }
405
545
  /**
@@ -411,75 +551,122 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
411
551
  return Promise.resolve();
412
552
  }
413
553
  await this.markTxsAsMinedFromBlocks(blocks);
414
- const lastBlockNum = blocks[blocks.length - 1].number;
415
- await Promise.all(blocks.map(async (block)=>this.synchedBlockHashes.set(block.number, (await block.hash()).toString())));
416
- await this.synchedLatestBlockNumber.set(lastBlockNum);
417
- this.log.verbose(`Synched to latest block ${lastBlockNum}`);
554
+ await this.startCollectingMissingTxs(blocks);
555
+ const lastBlock = blocks.at(-1);
556
+ await Promise.all(blocks.map(async (block)=>this.setBlockHash({
557
+ number: block.number,
558
+ hash: await block.hash().then((h)=>h.toString())
559
+ })));
560
+ await this.synchedLatestBlockNumber.set(lastBlock.number);
561
+ await this.synchedLatestSlot.set(BigInt(lastBlock.header.getSlot()));
562
+ this.log.verbose(`Synched to latest block ${lastBlock.number}`);
418
563
  await this.startServiceIfSynched();
419
564
  }
565
+ /** Request txs for unproven blocks so the prover node has more chances to get them. */ async startCollectingMissingTxs(blocks) {
566
+ try {
567
+ // TODO(#15435): If the archiver has lagged behind L1, the reported proven block number may
568
+ // be much lower than the actual one, and it does not update until the pending chain is
569
+ // fully synced. This could lead to a ton of tx collection requests for blocks that
570
+ // are already proven, but the archiver has not yet updated its state. Until this is properly
571
+ // fixed, it is mitigated by the expiration date of collection requests, which depends on
572
+ // the slot number of the block.
573
+ const provenBlockNumber = await this.l2BlockSource.getProvenBlockNumber();
574
+ const unprovenBlocks = blocks.filter((block)=>block.number > provenBlockNumber);
575
+ for (const block of unprovenBlocks){
576
+ const txHashes = block.body.txEffects.map((txEffect)=>txEffect.txHash);
577
+ const missingTxHashes = await this.txPool.hasTxs(txHashes).then((availability)=>txHashes.filter((_, index)=>!availability[index]));
578
+ if (missingTxHashes.length > 0) {
579
+ this.log.verbose(`Starting collection of ${missingTxHashes.length} missing txs for unproven mined block ${block.number}`, {
580
+ missingTxHashes,
581
+ blockNumber: block.number,
582
+ blockHash: await block.hash().then((h)=>h.toString())
583
+ });
584
+ this.txCollection.startCollecting(block, missingTxHashes);
585
+ }
586
+ }
587
+ } catch (err) {
588
+ this.log.error(`Error while starting collection of missing txs for unproven blocks`, err);
589
+ }
590
+ }
420
591
  /**
421
- * Handles new proven blocks by deleting the txs in them, or by deleting the txs in blocks `keepProvenTxsFor` ago.
422
- * @param blocks - A list of proven L2 blocks.
592
+ * Handles new finalized blocks by deleting the txs and attestations in them.
593
+ * @param blocks - A list of finalized L2 blocks.
423
594
  * @returns Empty promise.
424
- */ async handleProvenL2Blocks(blocks) {
595
+ */ async handleFinalizedL2Blocks(blocks) {
425
596
  if (!blocks.length) {
426
597
  return Promise.resolve();
427
598
  }
428
- const firstBlockNum = blocks[0].number;
599
+ this.log.debug(`Handling finalized blocks ${blocks.length} up to ${blocks.at(-1)?.number}`);
429
600
  const lastBlockNum = blocks[blocks.length - 1].number;
430
- const lastBlockSlot = blocks[blocks.length - 1].header.globalVariables.slotNumber.toBigInt();
431
- // If keepProvenTxsFor is 0, we delete all txs from all proven blocks.
432
- if (this.keepProvenTxsFor === 0) {
433
- await this.deleteTxsFromBlocks(blocks);
434
- } else if (lastBlockNum - this.keepProvenTxsFor >= INITIAL_L2_BLOCK_NUM) {
435
- const fromBlock = Math.max(INITIAL_L2_BLOCK_NUM, firstBlockNum - this.keepProvenTxsFor);
436
- const toBlock = lastBlockNum - this.keepProvenTxsFor;
437
- const limit = toBlock - fromBlock + 1;
438
- const blocksToDeleteTxsFrom = await this.l2BlockSource.getBlocks(fromBlock, limit, true);
439
- await this.deleteTxsFromBlocks(blocksToDeleteTxsFrom);
440
- }
441
- // We delete attestations older than the last block slot minus the number of slots we want to keep in the pool.
442
- const lastBlockSlotMinusKeepAttestationsInPoolFor = lastBlockSlot - BigInt(this.keepAttestationsInPoolFor);
443
- if (lastBlockSlotMinusKeepAttestationsInPoolFor >= BigInt(INITIAL_L2_BLOCK_NUM)) {
444
- await this.attestationPool?.deleteAttestationsOlderThan(lastBlockSlotMinusKeepAttestationsInPoolFor);
445
- }
446
- await this.synchedProvenBlockNumber.set(lastBlockNum);
447
- this.log.debug(`Synched to proven block ${lastBlockNum}`);
601
+ const lastBlockSlot = blocks[blocks.length - 1].header.getSlot();
602
+ const txHashes = blocks.flatMap((block)=>block.body.txEffects.map((txEffect)=>txEffect.txHash));
603
+ this.log.debug(`Deleting ${txHashes.length} txs from pool from finalized blocks up to ${lastBlockNum}`);
604
+ await this.txPool.deleteTxs(txHashes, {
605
+ permanently: true
606
+ });
607
+ await this.txPool.cleanupDeletedMinedTxs(lastBlockNum);
608
+ await this.attestationPool.deleteAttestationsOlderThan(lastBlockSlot);
609
+ await this.synchedFinalizedBlockNumber.set(lastBlockNum);
610
+ this.log.debug(`Synched to finalized block ${lastBlockNum} at slot ${lastBlockSlot}`);
448
611
  await this.startServiceIfSynched();
449
612
  }
450
613
  /**
451
614
  * Updates the tx pool after a chain prune.
452
615
  * @param latestBlock - The block number the chain was pruned to.
453
616
  */ async handlePruneL2Blocks(latestBlock) {
454
- const txsToDelete = [];
617
+ const txsToDelete = new Map();
618
+ const minedTxs = await this.txPool.getMinedTxHashes();
619
+ // Find transactions that reference pruned blocks in their historical header
455
620
  for (const tx of (await this.txPool.getAllTxs())){
456
621
  // every tx that's been generated against a block that has now been pruned is no longer valid
457
- if (tx.data.constants.historicalHeader.globalVariables.blockNumber.toNumber() > latestBlock) {
458
- txsToDelete.push(await tx.getTxHash());
622
+ if (tx.data.constants.anchorBlockHeader.globalVariables.blockNumber > latestBlock) {
623
+ const txHash = tx.getTxHash();
624
+ txsToDelete.set(txHash.toString(), txHash);
459
625
  }
460
626
  }
461
- this.log.info(`Detected chain prune. Removing invalid txs count=${txsToDelete.length} newLatestBlock=${latestBlock} previousLatestBlock=${this.getSyncedLatestBlockNum()}`);
627
+ this.log.info(`Detected chain prune. Removing ${txsToDelete.size} txs built against pruned blocks.`, {
628
+ newLatestBlock: latestBlock,
629
+ previousLatestBlock: await this.getSyncedLatestBlockNum(),
630
+ txsToDelete: Array.from(txsToDelete.keys())
631
+ });
462
632
  // delete invalid txs (both pending and mined)
463
- await this.txPool.deleteTxs(txsToDelete);
633
+ await this.txPool.deleteTxs(Array.from(txsToDelete.values()));
464
634
  // everything left in the mined set was built against a block on the proven chain so its still valid
465
- // move back to pending the txs that were reorged out of the chain
635
+ // move back to pending the txs that were reorged out of the chain, unless txPoolDeleteTxsAfterReorg is set,
636
+ // in which case we clean them up to avoid potential reorg loops
466
637
  // NOTE: we can't move _all_ txs back to pending because the tx pool could keep hold of mined txs for longer
467
638
  // (see this.keepProvenTxsFor)
468
- const txsToMoveToPending = [];
469
- for (const [txHash, blockNumber] of (await this.txPool.getMinedTxHashes())){
470
- if (blockNumber > latestBlock) {
471
- txsToMoveToPending.push(txHash);
639
+ const minedTxsFromReorg = [];
640
+ for (const [txHash, blockNumber] of minedTxs){
641
+ // We keep the txsToDelete out of this list as they have already been deleted above
642
+ if (blockNumber > latestBlock && !txsToDelete.has(txHash.toString())) {
643
+ minedTxsFromReorg.push(txHash);
472
644
  }
473
645
  }
474
- this.log.info(`Moving ${txsToMoveToPending.length} mined txs back to pending`);
475
- await this.txPool.markMinedAsPending(txsToMoveToPending);
646
+ if (this.config.txPoolDeleteTxsAfterReorg) {
647
+ this.log.info(`Deleting ${minedTxsFromReorg.length} mined txs from reorg`);
648
+ await this.txPool.deleteTxs(minedTxsFromReorg);
649
+ } else {
650
+ this.log.info(`Moving ${minedTxsFromReorg.length} mined txs from reorg back to pending`);
651
+ await this.txPool.markMinedAsPending(minedTxsFromReorg);
652
+ }
476
653
  await this.synchedLatestBlockNumber.set(latestBlock);
477
654
  // no need to update block hashes, as they will be updated as new blocks are added
478
655
  }
479
656
  async startServiceIfSynched() {
480
- if (this.currentState === 1 && await this.getSyncedLatestBlockNum() >= this.latestBlockNumberAtStart && await this.getSyncedProvenBlockNum() >= this.provenBlockNumberAtStart) {
481
- this.log.debug(`Synched to blocks at start`);
482
- this.setCurrentState(2);
657
+ if (this.currentState !== P2PClientState.SYNCHING) {
658
+ return;
659
+ }
660
+ const syncedFinalizedBlock = await this.getSyncedFinalizedBlockNum();
661
+ const syncedProvenBlock = await this.getSyncedProvenBlockNum();
662
+ const syncedLatestBlock = await this.getSyncedLatestBlockNum();
663
+ if (syncedLatestBlock >= this.latestBlockNumberAtStart && syncedProvenBlock >= this.provenBlockNumberAtStart && syncedFinalizedBlock >= this.finalizedBlockNumberAtStart) {
664
+ this.log.info(`Completed P2P client sync to block ${syncedLatestBlock}. Starting service.`, {
665
+ syncedLatestBlock,
666
+ syncedProvenBlock,
667
+ syncedFinalizedBlock
668
+ });
669
+ this.setCurrentState(P2PClientState.RUNNING);
483
670
  if (this.syncResolve !== undefined) {
484
671
  this.syncResolve();
485
672
  await this.p2pService.start();
@@ -494,12 +681,23 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
494
681
  this.currentState = newState;
495
682
  this.log.debug(`Moved from state ${P2PClientState[oldState]} to ${P2PClientState[this.currentState]}`);
496
683
  }
684
+ validate(txs) {
685
+ return this.p2pService.validate(txs);
686
+ }
687
+ /**
688
+ * Marks transactions as non-evictable in the pool.
689
+ * @param txHashes - Hashes of the transactions to mark as non-evictable.
690
+ */ markTxsAsNonEvictable(txHashes) {
691
+ return this.txPool.markTxsAsNonEvictable(txHashes);
692
+ }
693
+ handleAuthRequestFromPeer(authRequest, peerId) {
694
+ return this.p2pService.handleAuthRequestFromPeer(authRequest, peerId);
695
+ }
497
696
  }
498
697
  _ts_decorate([
499
698
  trackSpan('p2pClient.broadcastProposal', async (proposal)=>({
500
- [Attributes.BLOCK_NUMBER]: proposal.blockNumber.toNumber(),
501
- [Attributes.SLOT_NUMBER]: proposal.slotNumber.toNumber(),
699
+ [Attributes.SLOT_NUMBER]: proposal.slotNumber,
502
700
  [Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
503
- [Attributes.P2P_ID]: (await proposal.p2pMessageIdentifier()).toString()
701
+ [Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString()
504
702
  }))
505
703
  ], P2PClient.prototype, "broadcastProposal", null);