@aztec/p2p 0.0.0-test.0

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 (311) hide show
  1. package/README.md +7 -0
  2. package/dest/bootstrap/bootstrap.d.ts +38 -0
  3. package/dest/bootstrap/bootstrap.d.ts.map +1 -0
  4. package/dest/bootstrap/bootstrap.js +123 -0
  5. package/dest/client/factory.d.ts +21 -0
  6. package/dest/client/factory.d.ts.map +1 -0
  7. package/dest/client/factory.js +37 -0
  8. package/dest/client/index.d.ts +3 -0
  9. package/dest/client/index.d.ts.map +1 -0
  10. package/dest/client/index.js +2 -0
  11. package/dest/client/p2p_client.d.ts +314 -0
  12. package/dest/client/p2p_client.d.ts.map +1 -0
  13. package/dest/client/p2p_client.js +505 -0
  14. package/dest/config.d.ts +180 -0
  15. package/dest/config.d.ts.map +1 -0
  16. package/dest/config.js +193 -0
  17. package/dest/enr/generate-enr.d.ts +9 -0
  18. package/dest/enr/generate-enr.d.ts.map +1 -0
  19. package/dest/enr/generate-enr.js +30 -0
  20. package/dest/enr/index.d.ts +2 -0
  21. package/dest/enr/index.d.ts.map +1 -0
  22. package/dest/enr/index.js +1 -0
  23. package/dest/errors/reqresp.error.d.ts +28 -0
  24. package/dest/errors/reqresp.error.d.ts.map +1 -0
  25. package/dest/errors/reqresp.error.js +30 -0
  26. package/dest/index.d.ts +8 -0
  27. package/dest/index.d.ts.map +1 -0
  28. package/dest/index.js +7 -0
  29. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +57 -0
  30. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -0
  31. package/dest/mem_pools/attestation_pool/attestation_pool.js +6 -0
  32. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +3 -0
  33. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -0
  34. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +195 -0
  35. package/dest/mem_pools/attestation_pool/index.d.ts +3 -0
  36. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -0
  37. package/dest/mem_pools/attestation_pool/index.js +2 -0
  38. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +22 -0
  39. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -0
  40. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +112 -0
  41. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +17 -0
  42. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -0
  43. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +129 -0
  44. package/dest/mem_pools/attestation_pool/mocks.d.ts +19 -0
  45. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -0
  46. package/dest/mem_pools/attestation_pool/mocks.js +33 -0
  47. package/dest/mem_pools/index.d.ts +4 -0
  48. package/dest/mem_pools/index.d.ts.map +1 -0
  49. package/dest/mem_pools/index.js +1 -0
  50. package/dest/mem_pools/instrumentation.d.ts +30 -0
  51. package/dest/mem_pools/instrumentation.d.ts.map +1 -0
  52. package/dest/mem_pools/instrumentation.js +84 -0
  53. package/dest/mem_pools/interface.d.ts +11 -0
  54. package/dest/mem_pools/interface.d.ts.map +1 -0
  55. package/dest/mem_pools/interface.js +3 -0
  56. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +66 -0
  57. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -0
  58. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +245 -0
  59. package/dest/mem_pools/tx_pool/index.d.ts +4 -0
  60. package/dest/mem_pools/tx_pool/index.d.ts.map +1 -0
  61. package/dest/mem_pools/tx_pool/index.js +3 -0
  62. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +56 -0
  63. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -0
  64. package/dest/mem_pools/tx_pool/memory_tx_pool.js +141 -0
  65. package/dest/mem_pools/tx_pool/priority.d.ts +8 -0
  66. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -0
  67. package/dest/mem_pools/tx_pool/priority.js +10 -0
  68. package/dest/mem_pools/tx_pool/tx_pool.d.ts +66 -0
  69. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -0
  70. package/dest/mem_pools/tx_pool/tx_pool.js +3 -0
  71. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +7 -0
  72. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -0
  73. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +169 -0
  74. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +8 -0
  75. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -0
  76. package/dest/msg_validators/attestation_validator/attestation_validator.js +19 -0
  77. package/dest/msg_validators/attestation_validator/index.d.ts +2 -0
  78. package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -0
  79. package/dest/msg_validators/attestation_validator/index.js +1 -0
  80. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +8 -0
  81. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -0
  82. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +21 -0
  83. package/dest/msg_validators/block_proposal_validator/index.d.ts +2 -0
  84. package/dest/msg_validators/block_proposal_validator/index.d.ts.map +1 -0
  85. package/dest/msg_validators/block_proposal_validator/index.js +1 -0
  86. package/dest/msg_validators/index.d.ts +4 -0
  87. package/dest/msg_validators/index.d.ts.map +1 -0
  88. package/dest/msg_validators/index.js +3 -0
  89. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +7 -0
  90. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -0
  91. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +31 -0
  92. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +11 -0
  93. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -0
  94. package/dest/msg_validators/tx_validator/block_header_validator.js +26 -0
  95. package/dest/msg_validators/tx_validator/data_validator.d.ts +6 -0
  96. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -0
  97. package/dest/msg_validators/tx_validator/data_validator.js +107 -0
  98. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +12 -0
  99. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -0
  100. package/dest/msg_validators/tx_validator/double_spend_validator.js +41 -0
  101. package/dest/msg_validators/tx_validator/index.d.ts +7 -0
  102. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -0
  103. package/dest/msg_validators/tx_validator/index.js +6 -0
  104. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +10 -0
  105. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -0
  106. package/dest/msg_validators/tx_validator/metadata_validator.js +44 -0
  107. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +9 -0
  108. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -0
  109. package/dest/msg_validators/tx_validator/tx_proof_validator.js +25 -0
  110. package/dest/services/data_store.d.ts +27 -0
  111. package/dest/services/data_store.d.ts.map +1 -0
  112. package/dest/services/data_store.js +188 -0
  113. package/dest/services/discv5/discV5_service.d.ts +42 -0
  114. package/dest/services/discv5/discV5_service.d.ts.map +1 -0
  115. package/dest/services/discv5/discV5_service.js +214 -0
  116. package/dest/services/dummy_service.d.ts +85 -0
  117. package/dest/services/dummy_service.d.ts.map +1 -0
  118. package/dest/services/dummy_service.js +92 -0
  119. package/dest/services/encoding.d.ts +31 -0
  120. package/dest/services/encoding.d.ts.map +1 -0
  121. package/dest/services/encoding.js +66 -0
  122. package/dest/services/gossipsub/scoring.d.ts +7 -0
  123. package/dest/services/gossipsub/scoring.d.ts.map +1 -0
  124. package/dest/services/gossipsub/scoring.js +10 -0
  125. package/dest/services/index.d.ts +3 -0
  126. package/dest/services/index.d.ts.map +1 -0
  127. package/dest/services/index.js +2 -0
  128. package/dest/services/libp2p/libp2p_service.d.ts +186 -0
  129. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -0
  130. package/dest/services/libp2p/libp2p_service.js +712 -0
  131. package/dest/services/peer-manager/metrics.d.ts +12 -0
  132. package/dest/services/peer-manager/metrics.d.ts.map +1 -0
  133. package/dest/services/peer-manager/metrics.js +33 -0
  134. package/dest/services/peer-manager/peer_manager.d.ts +94 -0
  135. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -0
  136. package/dest/services/peer-manager/peer_manager.js +445 -0
  137. package/dest/services/peer-manager/peer_scoring.d.ts +28 -0
  138. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -0
  139. package/dest/services/peer-manager/peer_scoring.js +86 -0
  140. package/dest/services/reqresp/config.d.ts +16 -0
  141. package/dest/services/reqresp/config.d.ts.map +1 -0
  142. package/dest/services/reqresp/config.js +20 -0
  143. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +45 -0
  144. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -0
  145. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +88 -0
  146. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +61 -0
  147. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -0
  148. package/dest/services/reqresp/connection-sampler/connection_sampler.js +181 -0
  149. package/dest/services/reqresp/index.d.ts +6 -0
  150. package/dest/services/reqresp/index.d.ts.map +1 -0
  151. package/dest/services/reqresp/index.js +4 -0
  152. package/dest/services/reqresp/interface.d.ts +116 -0
  153. package/dest/services/reqresp/interface.d.ts.map +1 -0
  154. package/dest/services/reqresp/interface.js +84 -0
  155. package/dest/services/reqresp/metrics.d.ts +15 -0
  156. package/dest/services/reqresp/metrics.d.ts.map +1 -0
  157. package/dest/services/reqresp/metrics.js +55 -0
  158. package/dest/services/reqresp/protocols/block.d.ts +4 -0
  159. package/dest/services/reqresp/protocols/block.d.ts.map +1 -0
  160. package/dest/services/reqresp/protocols/block.js +8 -0
  161. package/dest/services/reqresp/protocols/goodbye.d.ts +51 -0
  162. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -0
  163. package/dest/services/reqresp/protocols/goodbye.js +87 -0
  164. package/dest/services/reqresp/protocols/index.d.ts +9 -0
  165. package/dest/services/reqresp/protocols/index.d.ts.map +1 -0
  166. package/dest/services/reqresp/protocols/index.js +7 -0
  167. package/dest/services/reqresp/protocols/ping.d.ts +9 -0
  168. package/dest/services/reqresp/protocols/ping.d.ts.map +1 -0
  169. package/dest/services/reqresp/protocols/ping.js +7 -0
  170. package/dest/services/reqresp/protocols/status.d.ts +9 -0
  171. package/dest/services/reqresp/protocols/status.d.ts.map +1 -0
  172. package/dest/services/reqresp/protocols/status.js +7 -0
  173. package/dest/services/reqresp/protocols/tx.d.ts +13 -0
  174. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -0
  175. package/dest/services/reqresp/protocols/tx.js +20 -0
  176. package/dest/services/reqresp/rate-limiter/index.d.ts +2 -0
  177. package/dest/services/reqresp/rate-limiter/index.d.ts.map +1 -0
  178. package/dest/services/reqresp/rate-limiter/index.js +1 -0
  179. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +102 -0
  180. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -0
  181. package/dest/services/reqresp/rate-limiter/rate_limiter.js +184 -0
  182. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +3 -0
  183. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -0
  184. package/dest/services/reqresp/rate-limiter/rate_limits.js +54 -0
  185. package/dest/services/reqresp/reqresp.d.ts +166 -0
  186. package/dest/services/reqresp/reqresp.d.ts.map +1 -0
  187. package/dest/services/reqresp/reqresp.js +516 -0
  188. package/dest/services/reqresp/status.d.ts +31 -0
  189. package/dest/services/reqresp/status.d.ts.map +1 -0
  190. package/dest/services/reqresp/status.js +51 -0
  191. package/dest/services/service.d.ts +87 -0
  192. package/dest/services/service.d.ts.map +1 -0
  193. package/dest/services/service.js +5 -0
  194. package/dest/test-helpers/generate-peer-id-private-keys.d.ts +7 -0
  195. package/dest/test-helpers/generate-peer-id-private-keys.d.ts.map +1 -0
  196. package/dest/test-helpers/generate-peer-id-private-keys.js +13 -0
  197. package/dest/test-helpers/get-ports.d.ts +7 -0
  198. package/dest/test-helpers/get-ports.d.ts.map +1 -0
  199. package/dest/test-helpers/get-ports.js +8 -0
  200. package/dest/test-helpers/index.d.ts +6 -0
  201. package/dest/test-helpers/index.d.ts.map +1 -0
  202. package/dest/test-helpers/index.js +5 -0
  203. package/dest/test-helpers/make-enrs.d.ts +16 -0
  204. package/dest/test-helpers/make-enrs.d.ts.map +1 -0
  205. package/dest/test-helpers/make-enrs.js +32 -0
  206. package/dest/test-helpers/make-test-p2p-clients.d.ts +36 -0
  207. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -0
  208. package/dest/test-helpers/make-test-p2p-clients.js +68 -0
  209. package/dest/test-helpers/reqresp-nodes.d.ts +66 -0
  210. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -0
  211. package/dest/test-helpers/reqresp-nodes.js +207 -0
  212. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -0
  213. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -0
  214. package/dest/testbench/p2p_client_testbench_worker.js +132 -0
  215. package/dest/testbench/parse_log_file.d.ts +2 -0
  216. package/dest/testbench/parse_log_file.d.ts.map +1 -0
  217. package/dest/testbench/parse_log_file.js +131 -0
  218. package/dest/testbench/testbench.d.ts +2 -0
  219. package/dest/testbench/testbench.d.ts.map +1 -0
  220. package/dest/testbench/testbench.js +61 -0
  221. package/dest/testbench/worker_client_manager.d.ts +56 -0
  222. package/dest/testbench/worker_client_manager.d.ts.map +1 -0
  223. package/dest/testbench/worker_client_manager.js +266 -0
  224. package/dest/types/index.d.ts +32 -0
  225. package/dest/types/index.d.ts.map +1 -0
  226. package/dest/types/index.js +28 -0
  227. package/dest/util.d.ts +53 -0
  228. package/dest/util.d.ts.map +1 -0
  229. package/dest/util.js +140 -0
  230. package/dest/versioning.d.ts +12 -0
  231. package/dest/versioning.d.ts.map +1 -0
  232. package/dest/versioning.js +33 -0
  233. package/package.json +127 -0
  234. package/src/bootstrap/bootstrap.ts +146 -0
  235. package/src/client/factory.ts +89 -0
  236. package/src/client/index.ts +2 -0
  237. package/src/client/p2p_client.ts +754 -0
  238. package/src/config.ts +371 -0
  239. package/src/enr/generate-enr.ts +39 -0
  240. package/src/enr/index.ts +1 -0
  241. package/src/errors/reqresp.error.ts +35 -0
  242. package/src/index.ts +7 -0
  243. package/src/mem_pools/attestation_pool/attestation_pool.ts +62 -0
  244. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +230 -0
  245. package/src/mem_pools/attestation_pool/index.ts +2 -0
  246. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +159 -0
  247. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +161 -0
  248. package/src/mem_pools/attestation_pool/mocks.ts +44 -0
  249. package/src/mem_pools/index.ts +3 -0
  250. package/src/mem_pools/instrumentation.ts +126 -0
  251. package/src/mem_pools/interface.ts +12 -0
  252. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +309 -0
  253. package/src/mem_pools/tx_pool/index.ts +3 -0
  254. package/src/mem_pools/tx_pool/memory_tx_pool.ts +174 -0
  255. package/src/mem_pools/tx_pool/priority.ts +13 -0
  256. package/src/mem_pools/tx_pool/tx_pool.ts +76 -0
  257. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +130 -0
  258. package/src/msg_validators/attestation_validator/attestation_validator.ts +26 -0
  259. package/src/msg_validators/attestation_validator/index.ts +1 -0
  260. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +29 -0
  261. package/src/msg_validators/block_proposal_validator/index.ts +1 -0
  262. package/src/msg_validators/index.ts +3 -0
  263. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +32 -0
  264. package/src/msg_validators/tx_validator/block_header_validator.ts +25 -0
  265. package/src/msg_validators/tx_validator/data_validator.ts +106 -0
  266. package/src/msg_validators/tx_validator/double_spend_validator.ts +38 -0
  267. package/src/msg_validators/tx_validator/index.ts +6 -0
  268. package/src/msg_validators/tx_validator/metadata_validator.ts +48 -0
  269. package/src/msg_validators/tx_validator/tx_proof_validator.ts +18 -0
  270. package/src/services/data_store.ts +235 -0
  271. package/src/services/discv5/discV5_service.ts +256 -0
  272. package/src/services/dummy_service.ts +134 -0
  273. package/src/services/encoding.ts +79 -0
  274. package/src/services/gossipsub/scoring.ts +13 -0
  275. package/src/services/index.ts +2 -0
  276. package/src/services/libp2p/libp2p_service.ts +871 -0
  277. package/src/services/peer-manager/metrics.ts +41 -0
  278. package/src/services/peer-manager/peer_manager.ts +530 -0
  279. package/src/services/peer-manager/peer_scoring.ts +105 -0
  280. package/src/services/reqresp/config.ts +35 -0
  281. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +94 -0
  282. package/src/services/reqresp/connection-sampler/connection_sampler.ts +217 -0
  283. package/src/services/reqresp/index.ts +4 -0
  284. package/src/services/reqresp/interface.ts +185 -0
  285. package/src/services/reqresp/metrics.ts +57 -0
  286. package/src/services/reqresp/protocols/block.ts +15 -0
  287. package/src/services/reqresp/protocols/goodbye.ts +101 -0
  288. package/src/services/reqresp/protocols/index.ts +8 -0
  289. package/src/services/reqresp/protocols/ping.ts +8 -0
  290. package/src/services/reqresp/protocols/status.ts +8 -0
  291. package/src/services/reqresp/protocols/tx.ts +29 -0
  292. package/src/services/reqresp/rate-limiter/index.ts +1 -0
  293. package/src/services/reqresp/rate-limiter/rate_limiter.ts +228 -0
  294. package/src/services/reqresp/rate-limiter/rate_limits.ts +55 -0
  295. package/src/services/reqresp/reqresp.ts +661 -0
  296. package/src/services/reqresp/status.ts +59 -0
  297. package/src/services/service.ts +112 -0
  298. package/src/test-helpers/generate-peer-id-private-keys.ts +15 -0
  299. package/src/test-helpers/get-ports.ts +8 -0
  300. package/src/test-helpers/index.ts +5 -0
  301. package/src/test-helpers/make-enrs.ts +44 -0
  302. package/src/test-helpers/make-test-p2p-clients.ts +122 -0
  303. package/src/test-helpers/reqresp-nodes.ts +289 -0
  304. package/src/testbench/README.md +20 -0
  305. package/src/testbench/p2p_client_testbench_worker.ts +152 -0
  306. package/src/testbench/parse_log_file.ts +175 -0
  307. package/src/testbench/testbench.ts +66 -0
  308. package/src/testbench/worker_client_manager.ts +318 -0
  309. package/src/types/index.ts +36 -0
  310. package/src/util.ts +196 -0
  311. package/src/versioning.ts +50 -0
@@ -0,0 +1,505 @@
1
+ function _ts_decorate(decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ }
7
+ import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
8
+ import { createLogger } from '@aztec/foundation/log';
9
+ import { Attributes, TraceableL2BlockStream, WithTracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
10
+ import { getP2PDefaultConfig } from '../config.js';
11
+ 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
+ }({});
21
+ /**
22
+ * The P2P client implementation.
23
+ */ export class P2PClient extends WithTracer {
24
+ l2BlockSource;
25
+ p2pService;
26
+ log;
27
+ /** 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
+ currentState;
29
+ syncPromise;
30
+ syncResolve;
31
+ latestBlockNumberAtStart;
32
+ provenBlockNumberAtStart;
33
+ synchedBlockHashes;
34
+ synchedLatestBlockNumber;
35
+ synchedProvenBlockNumber;
36
+ txPool;
37
+ attestationPool;
38
+ /** How many slots to keep attestations for. */ keepAttestationsInPoolFor;
39
+ /** How many slots to keep proven txs for. */ keepProvenTxsFor;
40
+ blockStream;
41
+ /**
42
+ * In-memory P2P client constructor.
43
+ * @param store - The client's instance of the KV store.
44
+ * @param l2BlockSource - P2P client's source for fetching existing blocks.
45
+ * @param txPool - The client's instance of a transaction pool. Defaults to in-memory implementation.
46
+ * @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
+ * @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 } = {
52
+ ...getP2PDefaultConfig(),
53
+ ...config
54
+ };
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
62
+ });
63
+ this.synchedBlockHashes = store.openMap('p2p_pool_block_hashes');
64
+ this.synchedLatestBlockNumber = store.openSingleton('p2p_pool_last_l2_block');
65
+ this.synchedProvenBlockNumber = store.openSingleton('p2p_pool_last_proven_l2_block');
66
+ this.txPool = mempools.txPool;
67
+ this.attestationPool = mempools.attestationPool;
68
+ }
69
+ isP2PClient() {
70
+ return true;
71
+ }
72
+ getPeers(includePending) {
73
+ return Promise.resolve(this.p2pService.getPeers(includePending));
74
+ }
75
+ getL2BlockHash(number) {
76
+ return this.synchedBlockHashes.getAsync(number);
77
+ }
78
+ async getL2Tips() {
79
+ const latestBlockNumber = await this.getSyncedLatestBlockNum();
80
+ let latestBlockHash;
81
+ const provenBlockNumber = await this.getSyncedProvenBlockNum();
82
+ let provenBlockHash;
83
+ if (latestBlockNumber > 0) {
84
+ latestBlockHash = await this.synchedBlockHashes.getAsync(latestBlockNumber);
85
+ if (typeof latestBlockHash === 'undefined') {
86
+ this.log.warn(`Block hash for latest block ${latestBlockNumber} not found`);
87
+ throw new Error();
88
+ }
89
+ }
90
+ if (provenBlockNumber > 0) {
91
+ provenBlockHash = await this.synchedBlockHashes.getAsync(provenBlockNumber);
92
+ if (typeof provenBlockHash === 'undefined') {
93
+ this.log.warn(`Block hash for proven block ${provenBlockNumber} not found`);
94
+ throw new Error();
95
+ }
96
+ }
97
+ return Promise.resolve({
98
+ latest: {
99
+ hash: latestBlockHash,
100
+ number: latestBlockNumber
101
+ },
102
+ proven: {
103
+ hash: provenBlockHash,
104
+ number: provenBlockNumber
105
+ },
106
+ finalized: {
107
+ hash: provenBlockHash,
108
+ number: provenBlockNumber
109
+ }
110
+ });
111
+ }
112
+ async handleBlockStreamEvent(event) {
113
+ this.log.debug(`Handling block stream event ${event.type}`);
114
+ switch(event.type){
115
+ case 'blocks-added':
116
+ await this.handleLatestL2Blocks(event.blocks);
117
+ break;
118
+ case 'chain-finalized':
119
+ break;
120
+ case 'chain-proven':
121
+ {
122
+ const from = await this.getSyncedProvenBlockNum() + 1;
123
+ const limit = event.blockNumber - from + 1;
124
+ await this.handleProvenL2Blocks(await this.l2BlockSource.getBlocks(from, limit));
125
+ break;
126
+ }
127
+ case 'chain-pruned':
128
+ await this.handlePruneL2Blocks(event.blockNumber);
129
+ break;
130
+ default:
131
+ {
132
+ const _ = event;
133
+ break;
134
+ }
135
+ }
136
+ }
137
+ #assertIsReady() {
138
+ // this.log.info('Checking if p2p client is ready, current state: ', this.currentState);
139
+ if (!this.isReady()) {
140
+ throw new Error('P2P client not ready');
141
+ }
142
+ }
143
+ /**
144
+ * Starts the P2P client.
145
+ * @returns An empty promise signalling the synching process.
146
+ */ async start() {
147
+ if (this.currentState === 3) {
148
+ throw new Error('P2P client already stopped');
149
+ }
150
+ if (this.currentState !== 0) {
151
+ return this.syncPromise;
152
+ }
153
+ // get the current latest block numbers
154
+ this.latestBlockNumberAtStart = await this.l2BlockSource.getBlockNumber();
155
+ this.provenBlockNumberAtStart = await this.l2BlockSource.getProvenBlockNumber();
156
+ const syncedLatestBlock = await this.getSyncedLatestBlockNum() + 1;
157
+ 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);
161
+ this.syncPromise = new Promise((resolve)=>{
162
+ this.syncResolve = resolve;
163
+ });
164
+ this.log.verbose(`Starting sync from ${syncedLatestBlock} (last proven ${syncedProvenBlock})`);
165
+ } else {
166
+ // if no blocks to be retrieved, go straight to running
167
+ this.setCurrentState(2);
168
+ this.syncPromise = Promise.resolve();
169
+ await this.p2pService.start();
170
+ this.log.debug(`Block ${syncedLatestBlock} (proven ${syncedProvenBlock}) already beyond current block`);
171
+ }
172
+ this.blockStream.start();
173
+ this.log.verbose(`Started block downloader from block ${syncedLatestBlock}`);
174
+ return this.syncPromise;
175
+ }
176
+ /**
177
+ * Allows consumers to stop the instance of the P2P client.
178
+ * 'ready' will now return 'false' and the running promise that keeps the client synced is interrupted.
179
+ */ async stop() {
180
+ this.log.debug('Stopping p2p client...');
181
+ await this.p2pService.stop();
182
+ this.log.debug('Stopped p2p service');
183
+ await this.blockStream.stop();
184
+ this.log.debug('Stopped block downloader');
185
+ await this.runningPromise;
186
+ this.setCurrentState(3);
187
+ this.log.info('P2P client stopped.');
188
+ }
189
+ broadcastProposal(proposal) {
190
+ this.log.verbose(`Broadcasting proposal for slot ${proposal.slotNumber.toNumber()} to peers`);
191
+ return this.p2pService.propagate(proposal);
192
+ }
193
+ async getAttestationsForSlot(slot, proposalId) {
194
+ return await this.attestationPool?.getAttestationsForSlot(slot, proposalId) ?? [];
195
+ }
196
+ // REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
197
+ // ^ This pattern is not my favorite (md)
198
+ registerBlockProposalHandler(handler) {
199
+ this.p2pService.registerBlockReceivedCallback(handler);
200
+ }
201
+ /**
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
+ * 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);
238
+ const txHashesStr = txHashes.map((tx)=>tx.toString()).join(', ');
239
+ this.log.debug(`Received batched txs ${txHashesStr} (${txs.length} / ${txHashes.length}}) from peers`);
240
+ return txs;
241
+ }
242
+ getPendingTxs() {
243
+ return Promise.resolve(this.getTxs('pending'));
244
+ }
245
+ async getPendingTxCount() {
246
+ const pendingTxs = await this.txPool.getPendingTxHashes();
247
+ return pendingTxs.length;
248
+ }
249
+ async *iteratePendingTxs() {
250
+ for (const txHash of (await this.txPool.getPendingTxHashes())){
251
+ const tx = await this.txPool.getTxByHash(txHash);
252
+ if (tx) {
253
+ yield tx;
254
+ }
255
+ }
256
+ }
257
+ /**
258
+ * Returns all transactions in the transaction pool.
259
+ * @returns An array of Txs.
260
+ */ async getTxs(filter) {
261
+ if (filter === 'all') {
262
+ return this.txPool.getAllTxs();
263
+ } 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);
267
+ } 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);
271
+ } else {
272
+ const _ = filter;
273
+ throw new Error(`Unknown filter ${filter}`);
274
+ }
275
+ }
276
+ /**
277
+ * Returns a transaction in the transaction pool by its hash.
278
+ * @param txHash - Hash of the transaction to look for in the pool.
279
+ * @returns A single tx or undefined.
280
+ */ getTxByHashFromPool(txHash) {
281
+ return this.txPool.getTxByHash(txHash);
282
+ }
283
+ /**
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);
294
+ }
295
+ /**
296
+ * Returns transactions in the transaction pool by hash.
297
+ * If a transaction is not in the pool, it will be requested from the network.
298
+ * @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) {
301
+ const txs = await Promise.all(txHashes.map((txHash)=>this.txPool.getTxByHash(txHash)));
302
+ const missingTxHashes = txs.map((tx, index)=>[
303
+ tx,
304
+ index
305
+ ]).filter(([tx, _index])=>!tx).map(([_tx, index])=>txHashes[index]);
306
+ if (missingTxHashes.length === 0) {
307
+ return txs;
308
+ }
309
+ const missingTxs = await this.requestTxsByHash(missingTxHashes);
310
+ return txs.filter((tx)=>!!tx).concat(missingTxs);
311
+ }
312
+ /**
313
+ * Returns an archived transaction in the transaction pool by its hash.
314
+ * @param txHash - Hash of the archived transaction to look for.
315
+ * @returns A single tx or undefined.
316
+ */ getArchivedTxByHash(txHash) {
317
+ return this.txPool.getArchivedTxByHash(txHash);
318
+ }
319
+ /**
320
+ * Verifies the 'tx' and, if valid, adds it to local tx pool and forwards it to other peers.
321
+ * @param tx - The tx to verify.
322
+ * @returns Empty promise.
323
+ **/ async sendTx(tx) {
324
+ this.#assertIsReady();
325
+ await this.txPool.addTxs([
326
+ tx
327
+ ]);
328
+ this.p2pService.propagate(tx);
329
+ }
330
+ /**
331
+ * Returns whether the given tx hash is flagged as pending or mined.
332
+ * @param txHash - Hash of the tx to query.
333
+ * @returns Pending or mined depending on its status, or undefined if not found.
334
+ */ getTxStatus(txHash) {
335
+ return this.txPool.getTxStatus(txHash);
336
+ }
337
+ getEnr() {
338
+ return this.p2pService.getEnr();
339
+ }
340
+ getEncodedEnr() {
341
+ return Promise.resolve(this.p2pService.getEnr()?.encodeTxt());
342
+ }
343
+ /**
344
+ * Deletes the 'txs' from the pool.
345
+ * NOT used if we use sendTx as reconcileTxPool will handle this.
346
+ * @param txHashes - Hashes of the transactions to delete.
347
+ * @returns Empty promise.
348
+ **/ async deleteTxs(txHashes) {
349
+ this.#assertIsReady();
350
+ await this.txPool.deleteTxs(txHashes);
351
+ }
352
+ /**
353
+ * Public function to check if the p2p client is fully synced and ready to receive txs.
354
+ * @returns True if the P2P client is ready to receive txs.
355
+ */ isReady() {
356
+ return this.currentState === 2;
357
+ }
358
+ /**
359
+ * Public function to check the latest block number that the P2P client is synced to.
360
+ * @returns Block number of latest L2 Block we've synced with.
361
+ */ async getSyncedLatestBlockNum() {
362
+ return await this.synchedLatestBlockNumber.getAsync() ?? INITIAL_L2_BLOCK_NUM - 1;
363
+ }
364
+ /**
365
+ * Public function to check the latest proven block number that the P2P client is synced to.
366
+ * @returns Block number of latest proven L2 Block we've synced with.
367
+ */ async getSyncedProvenBlockNum() {
368
+ return await this.synchedProvenBlockNumber.getAsync() ?? INITIAL_L2_BLOCK_NUM - 1;
369
+ }
370
+ /**
371
+ * Method to check the status the p2p client.
372
+ * @returns Information about p2p client status: state & syncedToBlockNum.
373
+ */ async getStatus() {
374
+ const blockNumber = await this.getSyncedLatestBlockNum();
375
+ const blockHash = blockNumber === 0 ? '' : await this.l2BlockSource.getBlockHeader(blockNumber).then((header)=>header?.hash()).then((hash)=>hash?.toString());
376
+ return {
377
+ state: this.currentState,
378
+ syncedToL2Block: {
379
+ number: blockNumber,
380
+ hash: blockHash
381
+ }
382
+ };
383
+ }
384
+ /**
385
+ * Mark all txs from these blocks as mined.
386
+ * @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
387
+ * @returns Empty promise.
388
+ */ async markTxsAsMinedFromBlocks(blocks) {
389
+ for (const block of blocks){
390
+ 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);
403
+ }
404
+ }
405
+ /**
406
+ * Handles new mined blocks by marking the txs in them as mined.
407
+ * @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
408
+ * @returns Empty promise.
409
+ */ async handleLatestL2Blocks(blocks) {
410
+ if (!blocks.length) {
411
+ return Promise.resolve();
412
+ }
413
+ 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}`);
418
+ await this.startServiceIfSynched();
419
+ }
420
+ /**
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.
423
+ * @returns Empty promise.
424
+ */ async handleProvenL2Blocks(blocks) {
425
+ if (!blocks.length) {
426
+ return Promise.resolve();
427
+ }
428
+ const firstBlockNum = blocks[0].number;
429
+ 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}`);
448
+ await this.startServiceIfSynched();
449
+ }
450
+ /**
451
+ * Updates the tx pool after a chain prune.
452
+ * @param latestBlock - The block number the chain was pruned to.
453
+ */ async handlePruneL2Blocks(latestBlock) {
454
+ const txsToDelete = [];
455
+ for (const tx of (await this.txPool.getAllTxs())){
456
+ // 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());
459
+ }
460
+ }
461
+ this.log.info(`Detected chain prune. Removing invalid txs count=${txsToDelete.length} newLatestBlock=${latestBlock} previousLatestBlock=${this.getSyncedLatestBlockNum()}`);
462
+ // delete invalid txs (both pending and mined)
463
+ await this.txPool.deleteTxs(txsToDelete);
464
+ // 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
466
+ // NOTE: we can't move _all_ txs back to pending because the tx pool could keep hold of mined txs for longer
467
+ // (see this.keepProvenTxsFor)
468
+ const txsToMoveToPending = [];
469
+ for (const [txHash, blockNumber] of (await this.txPool.getMinedTxHashes())){
470
+ if (blockNumber > latestBlock) {
471
+ txsToMoveToPending.push(txHash);
472
+ }
473
+ }
474
+ this.log.info(`Moving ${txsToMoveToPending.length} mined txs back to pending`);
475
+ await this.txPool.markMinedAsPending(txsToMoveToPending);
476
+ await this.synchedLatestBlockNumber.set(latestBlock);
477
+ // no need to update block hashes, as they will be updated as new blocks are added
478
+ }
479
+ 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);
483
+ if (this.syncResolve !== undefined) {
484
+ this.syncResolve();
485
+ await this.p2pService.start();
486
+ }
487
+ }
488
+ }
489
+ /**
490
+ * Method to set the value of the current state.
491
+ * @param newState - New state value.
492
+ */ setCurrentState(newState) {
493
+ const oldState = this.currentState;
494
+ this.currentState = newState;
495
+ this.log.debug(`Moved from state ${P2PClientState[oldState]} to ${P2PClientState[this.currentState]}`);
496
+ }
497
+ }
498
+ _ts_decorate([
499
+ trackSpan('p2pClient.broadcastProposal', async (proposal)=>({
500
+ [Attributes.BLOCK_NUMBER]: proposal.blockNumber.toNumber(),
501
+ [Attributes.SLOT_NUMBER]: proposal.slotNumber.toNumber(),
502
+ [Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
503
+ [Attributes.P2P_ID]: (await proposal.p2pMessageIdentifier()).toString()
504
+ }))
505
+ ], P2PClient.prototype, "broadcastProposal", null);
@@ -0,0 +1,180 @@
1
+ import { type ConfigMappingsType } from '@aztec/foundation/config';
2
+ import { type DataStoreConfig } from '@aztec/kv-store/config';
3
+ import { type ChainConfig } from '@aztec/stdlib/config';
4
+ import { type P2PReqRespConfig } from './services/reqresp/config.js';
5
+ /**
6
+ * P2P client configuration values.
7
+ */
8
+ export interface P2PConfig extends P2PReqRespConfig, ChainConfig {
9
+ /**
10
+ * A flag dictating whether the P2P subsystem should be enabled.
11
+ */
12
+ p2pEnabled: boolean;
13
+ /**
14
+ * The frequency in which to check for new L2 blocks.
15
+ */
16
+ blockCheckIntervalMS: number;
17
+ /**
18
+ * The number of blocks to fetch in a single batch.
19
+ */
20
+ blockRequestBatchSize: number;
21
+ /**
22
+ * DEBUG: Disable colocation penalty - for testing purposes only
23
+ */
24
+ debugDisableColocationPenalty: boolean;
25
+ /**
26
+ * The frequency in which to check for new peers.
27
+ */
28
+ peerCheckIntervalMS: number;
29
+ /**
30
+ * Size of queue of L2 blocks to store.
31
+ */
32
+ l2QueueSize: number;
33
+ /**
34
+ * The announce address for TCP.
35
+ */
36
+ tcpAnnounceAddress?: string;
37
+ /**
38
+ * The announce address for UDP.
39
+ */
40
+ udpAnnounceAddress?: string;
41
+ /**
42
+ * The listen address for TCP.
43
+ */
44
+ tcpListenAddress: string;
45
+ /**
46
+ * The listen address for UDP.
47
+ */
48
+ udpListenAddress: string;
49
+ /**
50
+ * An optional peer id private key. If blank, will generate a random key.
51
+ */
52
+ peerIdPrivateKey?: string;
53
+ /**
54
+ * A list of bootstrap peers to connect to.
55
+ */
56
+ bootstrapNodes: string[];
57
+ /** Whether to execute the version check in the bootstrap node ENR. */
58
+ bootstrapNodeEnrVersionCheck: boolean;
59
+ /** Whether to consider any configured bootnodes as full peers, e.g. for transaction gossiping */
60
+ bootstrapNodesAsFullPeers: boolean;
61
+ /**
62
+ * The maximum number of peers (a peer count above this will cause the node to refuse connection attempts)
63
+ */
64
+ maxPeerCount: number;
65
+ /**
66
+ * If announceUdpAddress or announceTcpAddress are not provided, query for the IP address of the machine. Default is false.
67
+ */
68
+ queryForIp: boolean;
69
+ /** How many blocks have to pass after a block is proven before its txs are deleted (zero to delete immediately once proven) */
70
+ keepProvenTxsInPoolFor: number;
71
+ /** How many slots to keep attestations for. */
72
+ keepAttestationsInPoolFor: number;
73
+ /**
74
+ * The interval of the gossipsub heartbeat to perform maintenance tasks.
75
+ */
76
+ gossipsubInterval: number;
77
+ /**
78
+ * The D parameter for the gossipsub protocol.
79
+ */
80
+ gossipsubD: number;
81
+ /**
82
+ * The Dlo parameter for the gossipsub protocol.
83
+ */
84
+ gossipsubDlo: number;
85
+ /**
86
+ * The Dhi parameter for the gossipsub protocol.
87
+ */
88
+ gossipsubDhi: number;
89
+ /**
90
+ * The Dlazy parameter for the gossipsub protocol.
91
+ */
92
+ gossipsubDLazy: number;
93
+ /**
94
+ * Whether to flood publish messages. - For testing purposes only
95
+ */
96
+ gossipsubFloodPublish: boolean;
97
+ /**
98
+ * The number of gossipsub interval message cache windows to keep.
99
+ */
100
+ gossipsubMcacheLength: number;
101
+ /**
102
+ * How many message cache windows to include when gossiping with other pears.
103
+ */
104
+ gossipsubMcacheGossip: number;
105
+ /**
106
+ * The 'age' (in # of L2 blocks) of a processed tx after which we heavily penalize a peer for re-sending it.
107
+ */
108
+ doubleSpendSeverePeerPenaltyWindow: number;
109
+ /**
110
+ * The weight of the tx topic for the gossipsub protocol. This determines how much the score for this specific topic contributes to the overall peer score.
111
+ */
112
+ gossipsubTxTopicWeight: number;
113
+ /**
114
+ * This is the weight applied to the penalty for delivering invalid messages.
115
+ */
116
+ gossipsubTxInvalidMessageDeliveriesWeight: number;
117
+ /**
118
+ * determines how quickly the penalty for invalid message deliveries decays over time. Between 0 and 1.
119
+ */
120
+ gossipsubTxInvalidMessageDeliveriesDecay: number;
121
+ /**
122
+ * The values for the peer scoring system. Passed as a comma separated list of values in order: low, mid, high tolerance errors.
123
+ */
124
+ peerPenaltyValues: number[];
125
+ /** Limit of transactions to archive in the tx pool. Once the archived tx limit is reached, the oldest archived txs will be purged. */
126
+ archivedTxLimit: number;
127
+ }
128
+ export declare const p2pConfigMappings: ConfigMappingsType<P2PConfig>;
129
+ /**
130
+ * Gets the config values for p2p client from environment variables.
131
+ * @returns The config values for p2p client.
132
+ */
133
+ export declare function getP2PConfigFromEnv(): P2PConfig;
134
+ export declare function getP2PDefaultConfig(): P2PConfig;
135
+ /**
136
+ * Required P2P config values for a bootstrap node.
137
+ */
138
+ export type BootnodeConfig = Pick<P2PConfig, 'udpAnnounceAddress' | 'peerIdPrivateKey' | 'bootstrapNodes'> & Required<Pick<P2PConfig, 'udpListenAddress'>> & Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKB'> & Pick<ChainConfig, 'l1ChainId'>;
139
+ export declare const bootnodeConfigMappings: ConfigMappingsType<Pick<{
140
+ l1ChainId: unknown;
141
+ version: unknown;
142
+ l1Contracts: unknown;
143
+ dataDirectory: unknown;
144
+ dataStoreMapSizeKB: unknown;
145
+ overallRequestTimeoutMs: unknown;
146
+ individualRequestTimeoutMs: unknown;
147
+ p2pEnabled: unknown;
148
+ blockCheckIntervalMS: unknown;
149
+ blockRequestBatchSize: unknown;
150
+ debugDisableColocationPenalty: unknown;
151
+ peerCheckIntervalMS: unknown;
152
+ l2QueueSize: unknown;
153
+ tcpAnnounceAddress: unknown;
154
+ udpAnnounceAddress: unknown;
155
+ tcpListenAddress: unknown;
156
+ udpListenAddress: unknown;
157
+ peerIdPrivateKey: unknown;
158
+ bootstrapNodes: unknown;
159
+ bootstrapNodeEnrVersionCheck: unknown;
160
+ bootstrapNodesAsFullPeers: unknown;
161
+ maxPeerCount: unknown;
162
+ queryForIp: unknown;
163
+ keepProvenTxsInPoolFor: unknown;
164
+ keepAttestationsInPoolFor: unknown;
165
+ gossipsubInterval: unknown;
166
+ gossipsubD: unknown;
167
+ gossipsubDlo: unknown;
168
+ gossipsubDhi: unknown;
169
+ gossipsubDLazy: unknown;
170
+ gossipsubFloodPublish: unknown;
171
+ gossipsubMcacheLength: unknown;
172
+ gossipsubMcacheGossip: unknown;
173
+ doubleSpendSeverePeerPenaltyWindow: unknown;
174
+ gossipsubTxTopicWeight: unknown;
175
+ gossipsubTxInvalidMessageDeliveriesWeight: unknown;
176
+ gossipsubTxInvalidMessageDeliveriesDecay: unknown;
177
+ peerPenaltyValues: unknown;
178
+ archivedTxLimit: unknown;
179
+ }, "udpAnnounceAddress" | "udpListenAddress" | "peerIdPrivateKey" | "bootstrapNodes" | "l1ChainId" | "dataDirectory" | "dataStoreMapSizeKB">>;
180
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAMxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,KAAK,WAAW,EAAuB,MAAM,sBAAsB,CAAC;AAE7E,OAAO,EAAE,KAAK,gBAAgB,EAA4B,MAAM,8BAA8B,CAAC;AAE/F;;GAEG;AACH,MAAM,WAAW,SAAU,SAAQ,gBAAgB,EAAE,WAAW;IAC9D;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,qBAAqB,EAAE,MAAM,CAAC;IAE9B;;OAEG;IACH,6BAA6B,EAAE,OAAO,CAAC;IAEvC;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,cAAc,EAAE,MAAM,EAAE,CAAC;IAEzB,sEAAsE;IACtE,4BAA4B,EAAE,OAAO,CAAC;IAEtC,iGAAiG;IACjG,yBAAyB,EAAE,OAAO,CAAC;IAEnC;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC;IAEpB,+HAA+H;IAC/H,sBAAsB,EAAE,MAAM,CAAC;IAE/B,+CAA+C;IAC/C,yBAAyB,EAAE,MAAM,CAAC;IAElC;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,qBAAqB,EAAE,OAAO,CAAC;IAE/B;;OAEG;IACH,qBAAqB,EAAE,MAAM,CAAC;IAE9B;;OAEG;IACH,qBAAqB,EAAE,MAAM,CAAC;IAE9B;;OAEG;IACH,kCAAkC,EAAE,MAAM,CAAC;IAE3C;;OAEG;IACH,sBAAsB,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,yCAAyC,EAAE,MAAM,CAAC;IAElD;;OAEG;IACH,wCAAwC,EAAE,MAAM,CAAC;IAEjD;;OAEG;IACH,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAE5B,sIAAsI;IACtI,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,iBAAiB,EAAE,kBAAkB,CAAC,SAAS,CAuK3D,CAAC;AAEF;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,SAAS,CAE/C;AAED,wBAAgB,mBAAmB,IAAI,SAAS,CAE/C;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,EAAE,oBAAoB,GAAG,kBAAkB,GAAG,gBAAgB,CAAC,GACxG,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC,GAC7C,IAAI,CAAC,eAAe,EAAE,eAAe,GAAG,oBAAoB,CAAC,GAC7D,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAYjC,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6IAGlC,CAAC"}