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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (334) hide show
  1. package/dest/bootstrap/bootstrap.d.ts +1 -1
  2. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  3. package/dest/bootstrap/bootstrap.js +14 -4
  4. package/dest/client/factory.d.ts +3 -2
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +9 -5
  7. package/dest/client/index.d.ts +1 -1
  8. package/dest/client/interface.d.ts +8 -6
  9. package/dest/client/interface.d.ts.map +1 -1
  10. package/dest/client/p2p_client.d.ts +13 -36
  11. package/dest/client/p2p_client.d.ts.map +1 -1
  12. package/dest/client/p2p_client.js +460 -63
  13. package/dest/config.d.ts +67 -61
  14. package/dest/config.d.ts.map +1 -1
  15. package/dest/config.js +28 -15
  16. package/dest/enr/generate-enr.d.ts +2 -2
  17. package/dest/enr/generate-enr.d.ts.map +1 -1
  18. package/dest/enr/generate-enr.js +1 -1
  19. package/dest/enr/index.d.ts +1 -1
  20. package/dest/errors/attestation-pool.error.d.ts +7 -0
  21. package/dest/errors/attestation-pool.error.d.ts.map +1 -0
  22. package/dest/errors/attestation-pool.error.js +12 -0
  23. package/dest/errors/reqresp.error.d.ts +1 -1
  24. package/dest/errors/reqresp.error.d.ts.map +1 -1
  25. package/dest/index.d.ts +1 -1
  26. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +43 -6
  27. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  28. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  29. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  30. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +72 -46
  31. package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
  32. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +15 -6
  33. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  34. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +73 -18
  35. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +13 -6
  36. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  37. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +69 -11
  38. package/dest/mem_pools/attestation_pool/mocks.d.ts +226 -5
  39. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  40. package/dest/mem_pools/attestation_pool/mocks.js +9 -7
  41. package/dest/mem_pools/index.d.ts +1 -1
  42. package/dest/mem_pools/instrumentation.d.ts +9 -1
  43. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  44. package/dest/mem_pools/instrumentation.js +38 -2
  45. package/dest/mem_pools/interface.d.ts +3 -4
  46. package/dest/mem_pools/interface.d.ts.map +1 -1
  47. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +39 -58
  48. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +314 -317
  50. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +18 -0
  51. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
  52. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +56 -0
  53. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +83 -0
  54. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
  55. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +5 -0
  56. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +15 -0
  57. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +1 -0
  58. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +88 -0
  59. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
  60. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  61. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
  62. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
  63. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  64. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +76 -0
  65. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
  66. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  67. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
  68. package/dest/mem_pools/tx_pool/index.d.ts +1 -2
  69. package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
  70. package/dest/mem_pools/tx_pool/index.js +0 -1
  71. package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
  72. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
  73. package/dest/mem_pools/tx_pool/priority.js +6 -1
  74. package/dest/mem_pools/tx_pool/tx_pool.d.ts +28 -9
  75. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  76. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  77. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  78. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +155 -25
  79. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -2
  80. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  81. package/dest/msg_validators/attestation_validator/attestation_validator.js +32 -5
  82. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
  83. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
  84. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +67 -0
  85. package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
  86. package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
  87. package/dest/msg_validators/attestation_validator/index.js +1 -0
  88. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +5 -2
  89. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
  90. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +44 -12
  91. package/dest/msg_validators/block_proposal_validator/index.d.ts +1 -1
  92. package/dest/msg_validators/index.d.ts +1 -1
  93. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +1 -1
  94. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -1
  95. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
  96. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  97. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +1 -1
  98. package/dest/msg_validators/tx_validator/archive_cache.d.ts +2 -2
  99. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
  100. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +2 -2
  101. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  102. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  103. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  104. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  105. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +1 -1
  106. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  107. package/dest/msg_validators/tx_validator/double_spend_validator.js +1 -1
  108. package/dest/msg_validators/tx_validator/factory.d.ts +4 -3
  109. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  110. package/dest/msg_validators/tx_validator/factory.js +11 -5
  111. package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
  112. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  113. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  114. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  115. package/dest/msg_validators/tx_validator/index.js +1 -0
  116. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +3 -6
  117. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  118. package/dest/msg_validators/tx_validator/metadata_validator.js +6 -24
  119. package/dest/msg_validators/tx_validator/phases_validator.d.ts +1 -1
  120. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  121. package/dest/msg_validators/tx_validator/phases_validator.js +3 -1
  122. package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
  123. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
  124. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +13 -0
  125. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
  126. package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
  127. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +1 -1
  128. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
  129. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +1 -1
  130. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  131. package/dest/services/data_store.d.ts +1 -1
  132. package/dest/services/data_store.d.ts.map +1 -1
  133. package/dest/services/discv5/discV5_service.d.ts +3 -3
  134. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  135. package/dest/services/discv5/discV5_service.js +2 -2
  136. package/dest/services/dummy_service.d.ts +2 -2
  137. package/dest/services/dummy_service.d.ts.map +1 -1
  138. package/dest/services/encoding.d.ts +25 -4
  139. package/dest/services/encoding.d.ts.map +1 -1
  140. package/dest/services/encoding.js +74 -6
  141. package/dest/services/gossipsub/scoring.d.ts +1 -1
  142. package/dest/services/index.d.ts +1 -1
  143. package/dest/services/libp2p/instrumentation.d.ts +3 -1
  144. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  145. package/dest/services/libp2p/instrumentation.js +9 -2
  146. package/dest/services/libp2p/libp2p_service.d.ts +33 -72
  147. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  148. package/dest/services/libp2p/libp2p_service.js +841 -175
  149. package/dest/services/peer-manager/interface.d.ts +1 -1
  150. package/dest/services/peer-manager/metrics.d.ts +8 -1
  151. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  152. package/dest/services/peer-manager/metrics.js +28 -0
  153. package/dest/services/peer-manager/peer_manager.d.ts +2 -33
  154. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  155. package/dest/services/peer-manager/peer_manager.js +29 -22
  156. package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
  157. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  158. package/dest/services/peer-manager/peer_scoring.js +40 -2
  159. package/dest/services/reqresp/config.d.ts +1 -1
  160. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +1 -1
  161. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  162. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -4
  163. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  164. package/dest/services/reqresp/index.d.ts +1 -1
  165. package/dest/services/reqresp/interface.d.ts +2 -11
  166. package/dest/services/reqresp/interface.d.ts.map +1 -1
  167. package/dest/services/reqresp/interface.js +1 -18
  168. package/dest/services/reqresp/metrics.d.ts +1 -1
  169. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  170. package/dest/services/reqresp/protocols/auth.d.ts +2 -2
  171. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
  172. package/dest/services/reqresp/protocols/auth.js +2 -2
  173. package/dest/services/reqresp/protocols/block.d.ts +1 -1
  174. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  175. package/dest/services/reqresp/protocols/block.js +3 -2
  176. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +1 -1
  177. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  178. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
  179. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +4 -6
  180. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  181. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +1 -1
  182. package/dest/services/reqresp/protocols/block_txs/index.d.ts +1 -1
  183. package/dest/services/reqresp/protocols/goodbye.d.ts +1 -1
  184. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
  185. package/dest/services/reqresp/protocols/index.d.ts +1 -1
  186. package/dest/services/reqresp/protocols/ping.d.ts +1 -1
  187. package/dest/services/reqresp/protocols/status.d.ts +6 -5
  188. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  189. package/dest/services/reqresp/protocols/status.js +4 -3
  190. package/dest/services/reqresp/protocols/tx.d.ts +2 -3
  191. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  192. package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
  193. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +2 -2
  194. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  195. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  196. package/dest/services/reqresp/reqresp.d.ts +1 -41
  197. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  198. package/dest/services/reqresp/reqresp.js +416 -34
  199. package/dest/services/reqresp/status.d.ts +2 -2
  200. package/dest/services/reqresp/status.d.ts.map +1 -1
  201. package/dest/services/service.d.ts +2 -2
  202. package/dest/services/service.d.ts.map +1 -1
  203. package/dest/services/tx_collection/config.d.ts +1 -1
  204. package/dest/services/tx_collection/config.js +1 -1
  205. package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -9
  206. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  207. package/dest/services/tx_collection/fast_tx_collection.js +6 -1
  208. package/dest/services/tx_collection/index.d.ts +1 -1
  209. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  210. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  211. package/dest/services/tx_collection/slow_tx_collection.d.ts +6 -7
  212. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  213. package/dest/services/tx_collection/slow_tx_collection.js +2 -1
  214. package/dest/services/tx_collection/tx_collection.d.ts +12 -11
  215. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  216. package/dest/services/tx_collection/tx_collection.js +3 -2
  217. package/dest/services/tx_collection/tx_collection_sink.d.ts +3 -3
  218. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  219. package/dest/services/tx_collection/tx_collection_sink.js +34 -4
  220. package/dest/services/tx_collection/tx_source.d.ts +1 -1
  221. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  222. package/dest/services/tx_collection/tx_source.js +2 -2
  223. package/dest/services/tx_provider.d.ts +6 -4
  224. package/dest/services/tx_provider.d.ts.map +1 -1
  225. package/dest/services/tx_provider.js +19 -6
  226. package/dest/services/tx_provider_instrumentation.d.ts +5 -2
  227. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  228. package/dest/services/tx_provider_instrumentation.js +14 -1
  229. package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
  230. package/dest/test-helpers/get-ports.d.ts +1 -1
  231. package/dest/test-helpers/get-ports.d.ts.map +1 -1
  232. package/dest/test-helpers/index.d.ts +1 -1
  233. package/dest/test-helpers/make-enrs.d.ts +1 -1
  234. package/dest/test-helpers/make-enrs.js +1 -1
  235. package/dest/test-helpers/make-test-p2p-clients.d.ts +2 -2
  236. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  237. package/dest/test-helpers/mock-pubsub.d.ts +4 -4
  238. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  239. package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
  240. package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
  241. package/dest/test-helpers/mock-tx-helpers.js +19 -0
  242. package/dest/test-helpers/reqresp-nodes.d.ts +3 -3
  243. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  244. package/dest/test-helpers/reqresp-nodes.js +4 -3
  245. package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
  246. package/dest/testbench/p2p_client_testbench_worker.js +17 -9
  247. package/dest/testbench/parse_log_file.d.ts +1 -1
  248. package/dest/testbench/testbench.d.ts +1 -1
  249. package/dest/testbench/testbench.js +2 -2
  250. package/dest/testbench/worker_client_manager.d.ts +1 -1
  251. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  252. package/dest/types/index.d.ts +1 -1
  253. package/dest/util.d.ts +2 -1
  254. package/dest/util.d.ts.map +1 -1
  255. package/dest/util.js +11 -2
  256. package/dest/versioning.d.ts +2 -2
  257. package/dest/versioning.d.ts.map +1 -1
  258. package/dest/versioning.js +2 -2
  259. package/package.json +21 -21
  260. package/src/bootstrap/bootstrap.ts +15 -4
  261. package/src/client/factory.ts +21 -12
  262. package/src/client/interface.ts +8 -5
  263. package/src/client/p2p_client.ts +106 -106
  264. package/src/config.ts +42 -21
  265. package/src/enr/generate-enr.ts +1 -1
  266. package/src/errors/attestation-pool.error.ts +13 -0
  267. package/src/mem_pools/attestation_pool/attestation_pool.ts +46 -5
  268. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +89 -48
  269. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +107 -24
  270. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +98 -19
  271. package/src/mem_pools/attestation_pool/mocks.ts +11 -8
  272. package/src/mem_pools/instrumentation.ts +46 -0
  273. package/src/mem_pools/interface.ts +2 -4
  274. package/src/mem_pools/tx_pool/README.md +255 -0
  275. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +368 -360
  276. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +71 -0
  277. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +93 -0
  278. package/src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts +108 -0
  279. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
  280. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +91 -0
  281. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
  282. package/src/mem_pools/tx_pool/index.ts +0 -1
  283. package/src/mem_pools/tx_pool/priority.ts +8 -1
  284. package/src/mem_pools/tx_pool/tx_pool.ts +28 -8
  285. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +131 -18
  286. package/src/msg_validators/attestation_validator/attestation_validator.ts +41 -6
  287. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +91 -0
  288. package/src/msg_validators/attestation_validator/index.ts +1 -0
  289. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +53 -12
  290. package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
  291. package/src/msg_validators/tx_validator/block_header_validator.ts +2 -2
  292. package/src/msg_validators/tx_validator/double_spend_validator.ts +1 -1
  293. package/src/msg_validators/tx_validator/factory.ts +13 -6
  294. package/src/msg_validators/tx_validator/index.ts +1 -0
  295. package/src/msg_validators/tx_validator/metadata_validator.ts +8 -42
  296. package/src/msg_validators/tx_validator/phases_validator.ts +3 -1
  297. package/src/msg_validators/tx_validator/test_utils.ts +1 -1
  298. package/src/msg_validators/tx_validator/timestamp_validator.ts +47 -0
  299. package/src/services/discv5/discV5_service.ts +2 -2
  300. package/src/services/dummy_service.ts +1 -1
  301. package/src/services/encoding.ts +81 -6
  302. package/src/services/libp2p/instrumentation.ts +10 -1
  303. package/src/services/libp2p/libp2p_service.ts +494 -169
  304. package/src/services/peer-manager/metrics.ts +32 -0
  305. package/src/services/peer-manager/peer_manager.ts +25 -16
  306. package/src/services/peer-manager/peer_scoring.ts +46 -3
  307. package/src/services/reqresp/interface.ts +1 -22
  308. package/src/services/reqresp/protocols/auth.ts +2 -2
  309. package/src/services/reqresp/protocols/block.ts +3 -2
  310. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +1 -1
  311. package/src/services/reqresp/protocols/status.ts +9 -8
  312. package/src/services/reqresp/protocols/tx.ts +1 -2
  313. package/src/services/reqresp/reqresp.ts +15 -11
  314. package/src/services/service.ts +1 -1
  315. package/src/services/tx_collection/config.ts +1 -1
  316. package/src/services/tx_collection/fast_tx_collection.ts +8 -5
  317. package/src/services/tx_collection/slow_tx_collection.ts +7 -6
  318. package/src/services/tx_collection/tx_collection.ts +12 -10
  319. package/src/services/tx_collection/tx_collection_sink.ts +34 -3
  320. package/src/services/tx_collection/tx_source.ts +2 -2
  321. package/src/services/tx_provider.ts +26 -9
  322. package/src/services/tx_provider_instrumentation.ts +19 -2
  323. package/src/test-helpers/make-enrs.ts +1 -1
  324. package/src/test-helpers/mock-pubsub.ts +1 -1
  325. package/src/test-helpers/mock-tx-helpers.ts +24 -0
  326. package/src/test-helpers/reqresp-nodes.ts +4 -3
  327. package/src/testbench/p2p_client_testbench_worker.ts +14 -6
  328. package/src/testbench/testbench.ts +2 -2
  329. package/src/util.ts +12 -2
  330. package/src/versioning.ts +3 -3
  331. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -68
  332. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
  333. package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -160
  334. package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -199
@@ -1,10 +1,10 @@
1
1
  import type { EthAddress, L2BlockId } from '@aztec/stdlib/block';
2
2
  import type { P2PApiFull } from '@aztec/stdlib/interfaces/server';
3
- import type { BlockProposal, P2PClientType } from '@aztec/stdlib/p2p';
3
+ import type { BlockAttestation, BlockProposal, P2PClientType } from '@aztec/stdlib/p2p';
4
4
  import type { Tx, TxHash } from '@aztec/stdlib/tx';
5
5
 
6
- import type { ENR } from '@chainsafe/enr';
7
6
  import type { PeerId } from '@libp2p/interface';
7
+ import type { ENR } from '@nethermindeth/enr';
8
8
 
9
9
  import type { P2PConfig } from '../config.js';
10
10
  import type { AuthRequest, StatusMessage } from '../services/index.js';
@@ -50,6 +50,9 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
50
50
  */
51
51
  broadcastProposal(proposal: BlockProposal): Promise<void>;
52
52
 
53
+ /** Broadcasts block attestations to other peers. */
54
+ broadcastAttestations(attestations: BlockAttestation[]): Promise<void>;
55
+
53
56
  /**
54
57
  * Registers a callback from the validator client that determines how to behave when
55
58
  * foreign block proposals are received
@@ -125,11 +128,11 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
125
128
  getArchivedTxByHash(txHash: TxHash): Promise<Tx | undefined>;
126
129
 
127
130
  /**
128
- * Returns whether the given tx hash is flagged as pending or mined.
131
+ * Returns whether the given tx hash is flagged as pending, mined, or deleted.
129
132
  * @param txHash - Hash of the tx to query.
130
- * @returns Pending or mined depending on its status, or undefined if not found.
133
+ * @returns Pending, mined, or deleted depending on its status, or undefined if not found.
131
134
  */
132
- getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | undefined>;
135
+ getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | 'deleted' | undefined>;
133
136
 
134
137
  /** Returns an iterator over pending txs on the mempool. */
135
138
  iteratePendingTxs(): AsyncIterableIterator<Tx>;
@@ -1,33 +1,26 @@
1
- import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
1
+ import { GENESIS_BLOCK_HEADER_HASH, INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
2
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
3
  import { createLogger } from '@aztec/foundation/log';
3
4
  import { DateProvider } from '@aztec/foundation/timer';
4
5
  import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncSingleton } from '@aztec/kv-store';
5
- import type {
6
- EthAddress,
7
- L2Block,
8
- L2BlockId,
9
- L2BlockSource,
6
+ import {
7
+ type EthAddress,
8
+ type L2BlockId,
9
+ type L2BlockNew,
10
+ type L2BlockSource,
10
11
  L2BlockStream,
11
- L2BlockStreamEvent,
12
- L2Tips,
13
- PublishedL2Block,
12
+ type L2BlockStreamEvent,
13
+ type L2Tips,
14
14
  } from '@aztec/stdlib/block';
15
15
  import type { ContractDataSource } from '@aztec/stdlib/contract';
16
16
  import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
17
17
  import { type PeerInfo, tryStop } from '@aztec/stdlib/interfaces/server';
18
18
  import { BlockAttestation, type BlockProposal, type P2PClientType } from '@aztec/stdlib/p2p';
19
19
  import type { Tx, TxHash } from '@aztec/stdlib/tx';
20
- import {
21
- Attributes,
22
- type TelemetryClient,
23
- TraceableL2BlockStream,
24
- WithTracer,
25
- getTelemetryClient,
26
- trackSpan,
27
- } from '@aztec/telemetry-client';
28
-
29
- import type { ENR } from '@chainsafe/enr';
20
+ import { Attributes, type TelemetryClient, WithTracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
21
+
30
22
  import type { PeerId } from '@libp2p/interface';
23
+ import type { ENR } from '@nethermindeth/enr';
31
24
 
32
25
  import { type P2PConfig, getP2PDefaultConfig } from '../config.js';
33
26
  import type { AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js';
@@ -62,14 +55,14 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
62
55
  private provenBlockNumberAtStart = -1;
63
56
  private finalizedBlockNumberAtStart = -1;
64
57
 
65
- private synchedBlockHashes: AztecAsyncMap<number, string>;
66
- private synchedLatestBlockNumber: AztecAsyncSingleton<number>;
67
- private synchedProvenBlockNumber: AztecAsyncSingleton<number>;
68
- private synchedFinalizedBlockNumber: AztecAsyncSingleton<number>;
58
+ private synchedBlockHashes: AztecAsyncMap<BlockNumber, string>;
59
+ private synchedLatestBlockNumber: AztecAsyncSingleton<BlockNumber>;
60
+ private synchedProvenBlockNumber: AztecAsyncSingleton<BlockNumber>;
61
+ private synchedFinalizedBlockNumber: AztecAsyncSingleton<BlockNumber>;
69
62
  private synchedLatestSlot: AztecAsyncSingleton<bigint>;
70
63
 
71
64
  private txPool: TxPool;
72
- private attestationPool: T extends P2PClientType.Full ? AttestationPool : undefined;
65
+ private attestationPool: AttestationPool;
73
66
 
74
67
  private config: P2PConfig;
75
68
 
@@ -91,7 +84,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
91
84
  _clientType: T,
92
85
  private store: AztecAsyncKVStore,
93
86
  private l2BlockSource: L2BlockSource & ContractDataSource,
94
- mempools: MemPools<T>,
87
+ mempools: MemPools,
95
88
  private p2pService: P2PService,
96
89
  private txCollection: TxCollection,
97
90
  config: Partial<P2PConfig> = {},
@@ -103,7 +96,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
103
96
 
104
97
  this.config = { ...getP2PDefaultConfig(), ...config };
105
98
  this.txPool = mempools.txPool;
106
- this.attestationPool = mempools.attestationPool!;
99
+ this.attestationPool = mempools.attestationPool;
107
100
 
108
101
  this.txProvider = new TxProvider(
109
102
  this.txCollection,
@@ -121,9 +114,15 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
121
114
  this.log.debug(`Received block proposal from ${sender.toString()}`);
122
115
  // TODO(palla/txs): Need to subtract validatorReexecuteDeadlineMs from this deadline (see ValidatorClient.getReexecutionDeadline)
123
116
  const constants = this.txCollection.getConstants();
124
- const nextSlotTimestampSeconds = Number(getTimestampForSlot(block.slotNumber.toBigInt() + 1n, constants));
117
+ const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(block.slotNumber + 1), constants));
125
118
  const deadline = new Date(nextSlotTimestampSeconds * 1000);
126
- await this.txProvider.getTxsForBlockProposal(block, { pinnedPeer: sender, deadline });
119
+ const parentBlock = await this.l2BlockSource.getBlockHeaderByArchive(block.payload.header.lastArchiveRoot);
120
+ if (!parentBlock) {
121
+ this.log.debug(`Cannot collect txs for proposal as parent block not found`);
122
+ return;
123
+ }
124
+ const blockNumber = BlockNumber(parentBlock.getBlockNumber() + 1);
125
+ await this.txProvider.getTxsForBlockProposal(block, blockNumber, { pinnedPeer: sender, deadline });
127
126
  return undefined;
128
127
  });
129
128
 
@@ -156,7 +155,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
156
155
  return Promise.resolve(this.p2pService.getPeers(includePending));
157
156
  }
158
157
 
159
- public getL2BlockHash(number: number): Promise<string | undefined> {
158
+ public getL2BlockHash(number: BlockNumber): Promise<string | undefined> {
160
159
  return this.synchedBlockHashes.getAsync(number);
161
160
  }
162
161
 
@@ -197,10 +196,12 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
197
196
  }
198
197
  }
199
198
 
199
+ const genesisHash = GENESIS_BLOCK_HEADER_HASH.toString();
200
+
200
201
  return {
201
- latest: { hash: latestBlockHash!, number: latestBlockNumber },
202
- proven: { hash: provenBlockHash!, number: provenBlockNumber },
203
- finalized: { hash: finalizedBlockHash!, number: finalizedBlockNumber },
202
+ latest: { hash: latestBlockHash ?? genesisHash, number: latestBlockNumber },
203
+ proven: { hash: provenBlockHash ?? genesisHash, number: provenBlockNumber },
204
+ finalized: { hash: finalizedBlockHash ?? genesisHash, number: finalizedBlockNumber },
204
205
  };
205
206
  }
206
207
 
@@ -208,15 +209,16 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
208
209
  this.log.debug(`Handling block stream event ${event.type}`);
209
210
  switch (event.type) {
210
211
  case 'blocks-added':
211
- await this.handleLatestL2Blocks(event.blocks);
212
+ await this.handleLatestL2Blocks(event.blocks.map(b => b.block.toL2Block()));
212
213
  break;
213
214
  case 'chain-finalized': {
214
215
  // TODO (alexg): I think we can prune the block hashes map here
215
216
  await this.setBlockHash(event.block);
216
- const from = (await this.getSyncedFinalizedBlockNum()) + 1;
217
+ const from = BlockNumber((await this.getSyncedFinalizedBlockNum()) + 1);
217
218
  const limit = event.block.number - from + 1;
218
219
  if (limit > 0) {
219
- await this.handleFinalizedL2Blocks(await this.l2BlockSource.getBlocks(from, limit));
220
+ const oldBlocks = await this.l2BlockSource.getBlocks(from, limit);
221
+ await this.handleFinalizedL2Blocks(oldBlocks.map(b => b.toL2Block()));
220
222
  }
221
223
  break;
222
224
  }
@@ -273,12 +275,9 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
273
275
  const syncedProvenBlock = (await this.getSyncedProvenBlockNum()) + 1;
274
276
  const syncedFinalizedBlock = (await this.getSyncedFinalizedBlockNum()) + 1;
275
277
 
276
- if (
277
- (await this.txPool.isEmpty()) &&
278
- (this.attestationPool === undefined || (await this.attestationPool?.isEmpty()))
279
- ) {
278
+ if ((await this.txPool.isEmpty()) && (await this.attestationPool.isEmpty())) {
280
279
  // if mempools are empty, we don't care about syncing prior blocks
281
- this.initBlockStream(this.latestBlockNumberAtStart);
280
+ this.initBlockStream(BlockNumber(this.latestBlockNumberAtStart));
282
281
  this.setCurrentState(P2PClientState.RUNNING);
283
282
  this.syncPromise = Promise.resolve();
284
283
  await this.p2pService.start();
@@ -326,15 +325,13 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
326
325
  return this.p2pService.addReqRespSubProtocol(subProtocol, handler, validator);
327
326
  }
328
327
 
329
- private initBlockStream(startingBlock?: number) {
328
+ private initBlockStream(startingBlock?: BlockNumber) {
330
329
  if (!this.blockStream) {
331
330
  const { blockRequestBatchSize: batchSize, blockCheckIntervalMS: pollIntervalMS } = this.config;
332
- this.blockStream = new TraceableL2BlockStream(
331
+ this.blockStream = new L2BlockStream(
333
332
  this.l2BlockSource,
334
333
  this,
335
334
  this,
336
- this.telemetry.getTracer('P2PL2BlockStream'),
337
- 'P2PL2BlockStream',
338
335
  createLogger(`${this.log.module}:l2-block-stream`),
339
336
  { batchSize, pollIntervalMS, startingBlock },
340
337
  );
@@ -365,26 +362,32 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
365
362
  }
366
363
 
367
364
  @trackSpan('p2pClient.broadcastProposal', async proposal => ({
368
- [Attributes.BLOCK_NUMBER]: proposal.blockNumber,
369
- [Attributes.SLOT_NUMBER]: proposal.slotNumber.toNumber(),
365
+ [Attributes.SLOT_NUMBER]: proposal.slotNumber,
370
366
  [Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
371
- [Attributes.P2P_ID]: (await proposal.p2pMessageIdentifier()).toString(),
367
+ [Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString(),
372
368
  }))
373
369
  public broadcastProposal(proposal: BlockProposal): Promise<void> {
374
- this.log.verbose(`Broadcasting proposal for slot ${proposal.slotNumber.toNumber()} to peers`);
370
+ this.log.verbose(`Broadcasting proposal for slot ${proposal.slotNumber} to peers`);
375
371
  return this.p2pService.propagate(proposal);
376
372
  }
377
373
 
378
- public async getAttestationsForSlot(slot: bigint, proposalId?: string): Promise<BlockAttestation[]> {
379
- return (
380
- (await (proposalId
381
- ? this.attestationPool?.getAttestationsForSlotAndProposal(slot, proposalId)
382
- : this.attestationPool?.getAttestationsForSlot(slot))) ?? []
383
- );
374
+ public async broadcastAttestations(attestations: BlockAttestation[]): Promise<void> {
375
+ this.log.verbose(`Broadcasting ${attestations.length} attestations to peers`);
376
+ await Promise.all(attestations.map(att => this.p2pService.propagate(att)));
377
+ }
378
+
379
+ public async getAttestationsForSlot(slot: SlotNumber, proposalId?: string): Promise<BlockAttestation[]> {
380
+ return await (proposalId
381
+ ? this.attestationPool.getAttestationsForSlotAndProposal(slot, proposalId)
382
+ : this.attestationPool.getAttestationsForSlot(slot));
384
383
  }
385
384
 
386
385
  public addAttestations(attestations: BlockAttestation[]): Promise<void> {
387
- return this.attestationPool?.addAttestations(attestations) ?? Promise.resolve();
386
+ return this.attestationPool.addAttestations(attestations);
387
+ }
388
+
389
+ public deleteAttestation(attestation: BlockAttestation): Promise<void> {
390
+ return this.attestationPool.deleteAttestations([attestation]);
388
391
  }
389
392
 
390
393
  // REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
@@ -599,7 +602,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
599
602
  * @param txHash - Hash of the tx to query.
600
603
  * @returns Pending or mined depending on its status, or undefined if not found.
601
604
  */
602
- public getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | undefined> {
605
+ public getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | 'deleted' | undefined> {
603
606
  return this.txPool.getTxStatus(txHash);
604
607
  }
605
608
 
@@ -634,20 +637,20 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
634
637
  * Public function to check the latest block number that the P2P client is synced to.
635
638
  * @returns Block number of latest L2 Block we've synced with.
636
639
  */
637
- public async getSyncedLatestBlockNum(): Promise<number> {
638
- return (await this.synchedLatestBlockNumber.getAsync()) ?? INITIAL_L2_BLOCK_NUM - 1;
640
+ public async getSyncedLatestBlockNum(): Promise<BlockNumber> {
641
+ return (await this.synchedLatestBlockNumber.getAsync()) ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
639
642
  }
640
643
 
641
644
  /**
642
645
  * Public function to check the latest proven block number that the P2P client is synced to.
643
646
  * @returns Block number of latest proven L2 Block we've synced with.
644
647
  */
645
- public async getSyncedProvenBlockNum(): Promise<number> {
646
- return (await this.synchedProvenBlockNumber.getAsync()) ?? INITIAL_L2_BLOCK_NUM - 1;
648
+ public async getSyncedProvenBlockNum(): Promise<BlockNumber> {
649
+ return (await this.synchedProvenBlockNumber.getAsync()) ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
647
650
  }
648
651
 
649
- public async getSyncedFinalizedBlockNum(): Promise<number> {
650
- return (await this.synchedFinalizedBlockNumber.getAsync()) ?? INITIAL_L2_BLOCK_NUM - 1;
652
+ public async getSyncedFinalizedBlockNum(): Promise<BlockNumber> {
653
+ return (await this.synchedFinalizedBlockNumber.getAsync()) ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
651
654
  }
652
655
 
653
656
  /** Returns latest L2 slot for which we have seen an L2 block. */
@@ -663,7 +666,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
663
666
  const blockNumber = await this.getSyncedLatestBlockNum();
664
667
  const blockHash =
665
668
  blockNumber === 0
666
- ? ''
669
+ ? GENESIS_BLOCK_HEADER_HASH.toString()
667
670
  : await this.l2BlockSource
668
671
  .getBlockHeader(blockNumber)
669
672
  .then(header => header?.hash())
@@ -671,8 +674,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
671
674
 
672
675
  return {
673
676
  state: this.currentState,
674
- syncedToL2Block: { number: blockNumber, hash: blockHash },
675
- } as P2PSyncState;
677
+ syncedToL2Block: { number: blockNumber, hash: blockHash! },
678
+ };
676
679
  }
677
680
 
678
681
  /**
@@ -680,58 +683,46 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
680
683
  * @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
681
684
  * @returns Empty promise.
682
685
  */
683
- private async markTxsAsMinedFromBlocks(blocks: L2Block[]): Promise<void> {
686
+ private async markTxsAsMinedFromBlocks(blocks: L2BlockNew[]): Promise<void> {
684
687
  for (const block of blocks) {
685
688
  const txHashes = block.body.txEffects.map(txEffect => txEffect.txHash);
686
689
  await this.txPool.markAsMined(txHashes, block.header);
687
690
  }
688
691
  }
689
692
 
690
- /**
691
- * Deletes txs from these blocks.
692
- * @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
693
- * @returns Empty promise.
694
- */
695
- private async deleteTxsFromBlocks(blocks: L2Block[]): Promise<void> {
696
- this.log.debug(`Deleting txs from blocks ${blocks[0].number} to ${blocks[blocks.length - 1].number}`);
697
- for (const block of blocks) {
698
- const txHashes = block.body.txEffects.map(txEffect => txEffect.txHash);
699
- await this.txPool.deleteTxs(txHashes);
700
- }
701
- }
702
-
703
693
  /**
704
694
  * Handles new mined blocks by marking the txs in them as mined.
705
695
  * @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
706
696
  * @returns Empty promise.
707
697
  */
708
- private async handleLatestL2Blocks(blocks: PublishedL2Block[]): Promise<void> {
698
+ private async handleLatestL2Blocks(blocks: L2BlockNew[]): Promise<void> {
709
699
  if (!blocks.length) {
710
700
  return Promise.resolve();
711
701
  }
712
702
 
713
- await this.markTxsAsMinedFromBlocks(blocks.map(b => b.block));
714
- await this.startCollectingMissingTxs(blocks.map(b => b.block));
703
+ await this.markTxsAsMinedFromBlocks(blocks);
704
+ await this.txPool.clearNonEvictableTxs();
705
+ await this.startCollectingMissingTxs(blocks);
715
706
 
716
- const lastBlock = blocks.at(-1)!.block;
707
+ const lastBlock = blocks.at(-1)!;
717
708
 
718
709
  await Promise.all(
719
710
  blocks.map(async block =>
720
711
  this.setBlockHash({
721
- number: block.block.number,
722
- hash: await block.block.hash().then(h => h.toString()),
712
+ number: block.number,
713
+ hash: await block.hash().then(h => h.toString()),
723
714
  }),
724
715
  ),
725
716
  );
726
717
 
727
718
  await this.synchedLatestBlockNumber.set(lastBlock.number);
728
- await this.synchedLatestSlot.set(lastBlock.header.getSlot());
719
+ await this.synchedLatestSlot.set(BigInt(lastBlock.header.getSlot()));
729
720
  this.log.verbose(`Synched to latest block ${lastBlock.number}`);
730
721
  await this.startServiceIfSynched();
731
722
  }
732
723
 
733
724
  /** Request txs for unproven blocks so the prover node has more chances to get them. */
734
- private async startCollectingMissingTxs(blocks: L2Block[]): Promise<void> {
725
+ private async startCollectingMissingTxs(blocks: L2BlockNew[]): Promise<void> {
735
726
  try {
736
727
  // TODO(#15435): If the archiver has lagged behind L1, the reported proven block number may
737
728
  // be much lower than the actual one, and it does not update until the pending chain is
@@ -764,20 +755,24 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
764
755
  * @param blocks - A list of finalized L2 blocks.
765
756
  * @returns Empty promise.
766
757
  */
767
- private async handleFinalizedL2Blocks(blocks: L2Block[]): Promise<void> {
768
- this.log.trace(`Handling finalized blocks ${blocks.length} up to ${blocks.at(-1)?.number}`);
758
+ private async handleFinalizedL2Blocks(blocks: L2BlockNew[]): Promise<void> {
769
759
  if (!blocks.length) {
770
760
  return Promise.resolve();
771
761
  }
762
+ this.log.debug(`Handling finalized blocks ${blocks.length} up to ${blocks.at(-1)?.number}`);
772
763
 
773
764
  const lastBlockNum = blocks[blocks.length - 1].number;
774
765
  const lastBlockSlot = blocks[blocks.length - 1].header.getSlot();
775
766
 
776
- await this.deleteTxsFromBlocks(blocks);
777
- await this.attestationPool?.deleteAttestationsOlderThan(lastBlockSlot);
767
+ const txHashes = blocks.flatMap(block => block.body.txEffects.map(txEffect => txEffect.txHash));
768
+ this.log.debug(`Deleting ${txHashes.length} txs from pool from finalized blocks up to ${lastBlockNum}`);
769
+ await this.txPool.deleteTxs(txHashes, { permanently: true });
770
+ await this.txPool.cleanupDeletedMinedTxs(lastBlockNum);
771
+
772
+ await this.attestationPool.deleteAttestationsOlderThan(lastBlockSlot);
778
773
 
779
774
  await this.synchedFinalizedBlockNumber.set(lastBlockNum);
780
- this.log.debug(`Synched to finalized block ${lastBlockNum}`);
775
+ this.log.debug(`Synched to finalized block ${lastBlockNum} at slot ${lastBlockSlot}`);
781
776
 
782
777
  await this.startServiceIfSynched();
783
778
  }
@@ -786,42 +781,47 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
786
781
  * Updates the tx pool after a chain prune.
787
782
  * @param latestBlock - The block number the chain was pruned to.
788
783
  */
789
- private async handlePruneL2Blocks(latestBlock: number): Promise<void> {
784
+ private async handlePruneL2Blocks(latestBlock: BlockNumber): Promise<void> {
790
785
  const txsToDelete = new Map<string, TxHash>();
791
786
  const minedTxs = await this.txPool.getMinedTxHashes();
792
787
 
793
788
  // Find transactions that reference pruned blocks in their historical header
794
789
  for (const tx of await this.txPool.getAllTxs()) {
795
790
  // every tx that's been generated against a block that has now been pruned is no longer valid
796
- if (tx.data.constants.historicalHeader.globalVariables.blockNumber > latestBlock) {
791
+ if (tx.data.constants.anchorBlockHeader.globalVariables.blockNumber > latestBlock) {
797
792
  const txHash = tx.getTxHash();
798
793
  txsToDelete.set(txHash.toString(), txHash);
799
794
  }
800
795
  }
801
796
 
802
- this.log.info(
803
- `Detected chain prune. Removing invalid txs count=${
804
- txsToDelete.size
805
- } newLatestBlock=${latestBlock} previousLatestBlock=${await this.getSyncedLatestBlockNum()}`,
806
- );
797
+ this.log.info(`Detected chain prune. Removing ${txsToDelete.size} txs built against pruned blocks.`, {
798
+ newLatestBlock: latestBlock,
799
+ previousLatestBlock: await this.getSyncedLatestBlockNum(),
800
+ txsToDelete: Array.from(txsToDelete.keys()),
801
+ });
807
802
 
808
803
  // delete invalid txs (both pending and mined)
809
804
  await this.txPool.deleteTxs(Array.from(txsToDelete.values()));
810
805
 
811
806
  // everything left in the mined set was built against a block on the proven chain so its still valid
812
- // move back to pending the txs that were reorged out of the chain
807
+ // move back to pending the txs that were reorged out of the chain, unless txPoolDeleteTxsAfterReorg is set,
808
+ // in which case we clean them up to avoid potential reorg loops
813
809
  // NOTE: we can't move _all_ txs back to pending because the tx pool could keep hold of mined txs for longer
814
810
  // (see this.keepProvenTxsFor)
815
-
816
- const txsToMoveToPending: TxHash[] = [];
811
+ const minedTxsFromReorg: TxHash[] = [];
817
812
  for (const [txHash, blockNumber] of minedTxs) {
818
- if (blockNumber > latestBlock) {
819
- txsToMoveToPending.push(txHash);
813
+ // We keep the txsToDelete out of this list as they have already been deleted above
814
+ if (blockNumber > latestBlock && !txsToDelete.has(txHash.toString())) {
815
+ minedTxsFromReorg.push(txHash);
820
816
  }
821
817
  }
822
818
 
823
- this.log.info(`Moving ${txsToMoveToPending.length} mined txs back to pending`);
824
- await this.txPool.markMinedAsPending(txsToMoveToPending);
819
+ if (this.config.txPoolDeleteTxsAfterReorg) {
820
+ this.log.info(`Deleting ${minedTxsFromReorg.length} mined txs from reorg`);
821
+ await this.txPool.deleteTxs(minedTxsFromReorg);
822
+ } else {
823
+ await this.txPool.markMinedAsPending(minedTxsFromReorg, latestBlock);
824
+ }
825
825
 
826
826
  await this.synchedLatestBlockNumber.set(latestBlock);
827
827
  // no need to update block hashes, as they will be updated as new blocks are added
package/src/config.ts CHANGED
@@ -9,9 +9,9 @@ import {
9
9
  pickConfigMappings,
10
10
  secretStringConfigHelper,
11
11
  } from '@aztec/foundation/config';
12
- import { Fr } from '@aztec/foundation/fields';
12
+ import { Fr } from '@aztec/foundation/curves/bn254';
13
13
  import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
14
- import { FunctionSelector } from '@aztec/stdlib/abi';
14
+ import { FunctionSelector } from '@aztec/stdlib/abi/function-selector';
15
15
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
16
16
  import { type AllowedElement, type ChainConfig, chainConfigMappings } from '@aztec/stdlib/config';
17
17
 
@@ -127,17 +127,14 @@ export interface P2PConfig extends P2PReqRespConfig, ChainConfig, TxCollectionCo
127
127
  /** A list of preferred peers. */
128
128
  preferredPeers: string[];
129
129
 
130
- /** The maximum possible size of the P2P DB in KB. Overwrites the general dataStoreMapSizeKB. */
130
+ /** The maximum possible size of the P2P DB in KB. Overwrites the general dataStoreMapSizeKb. */
131
131
  p2pStoreMapSizeKb?: number;
132
132
 
133
133
  /** Which calls are allowed in the public setup phase of a tx. */
134
134
  txPublicSetupAllowList: AllowedElement[];
135
135
 
136
- /** The maximum cumulative tx size (in bytes) of pending txs before evicting lower priority txs. */
137
- maxTxPoolSize: number;
138
-
139
- /** If the pool is full, it will still accept a few more txs until it reached maxTxPoolOverspillFactor * maxTxPoolSize. Then it will evict */
140
- txPoolOverflowFactor: number;
136
+ /** The maximum number of pending txs before evicting lower priority txs. */
137
+ maxPendingTxCount: number;
141
138
 
142
139
  /** The node's seen message ID cache size */
143
140
  seenMessageCacheSize: number;
@@ -161,6 +158,15 @@ export interface P2PConfig extends P2PReqRespConfig, ChainConfig, TxCollectionCo
161
158
 
162
159
  /** The probability that a transaction is discarded. - For testing purposes only */
163
160
  dropTransactionsProbability: number;
161
+
162
+ /** Whether to delete transactions from the pool after a reorg instead of moving them back to pending. */
163
+ txPoolDeleteTxsAfterReorg: boolean;
164
+
165
+ /** Alters the format of p2p messages to include things like broadcast timestamp FOR TESTING ONLY */
166
+ debugP2PInstrumentMessages: boolean;
167
+
168
+ /** Whether to run in fisherman mode: validates all proposals and attestations but does not broadcast attestations or participate in consensus */
169
+ fishermanMode: boolean;
164
170
  }
165
171
 
166
172
  export const DEFAULT_P2P_PORT = 40400;
@@ -357,7 +363,7 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
357
363
  p2pStoreMapSizeKb: {
358
364
  env: 'P2P_STORE_MAP_SIZE_KB',
359
365
  parseEnv: (val: string | undefined) => (val ? +val : undefined),
360
- description: 'The maximum possible size of the P2P DB in KB. Overwrites the general dataStoreMapSizeKB.',
366
+ description: 'The maximum possible size of the P2P DB in KB. Overwrites the general dataStoreMapSizeKb.',
361
367
  },
362
368
  txPublicSetupAllowList: {
363
369
  env: 'TX_PUBLIC_SETUP_ALLOWLIST',
@@ -366,15 +372,12 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
366
372
  printDefault: () =>
367
373
  'AuthRegistry, FeeJuice.increase_public_balance, Token.increase_public_balance, FPC.prepare_fee',
368
374
  },
369
- maxTxPoolSize: {
370
- env: 'P2P_MAX_TX_POOL_SIZE',
371
- description: 'The maximum cumulative tx size of pending txs (in bytes) before evicting lower priority txs.',
372
- ...numberConfigHelper(100_000_000), // 100MB
373
- },
374
- txPoolOverflowFactor: {
375
- env: 'P2P_TX_POOL_OVERFLOW_FACTOR',
376
- description: 'How much the tx pool can overflow before it starts evicting txs. Must be greater than 1',
377
- ...floatConfigHelper(1.1), // 10% overflow
375
+ maxPendingTxCount: {
376
+ env: 'P2P_MAX_PENDING_TX_COUNT',
377
+ description: 'The maximum number of pending txs before evicting lower priority txs.',
378
+ // Worst case scenario: Uncompressed public/private tx is ~ 156kb
379
+ // This implies we are using ~156MB of memory for pending pool
380
+ ...numberConfigHelper(1_000),
378
381
  },
379
382
  seenMessageCacheSize: {
380
383
  env: 'P2P_SEEN_MSG_CACHE_SIZE',
@@ -403,7 +406,7 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
403
406
  },
404
407
  dropTransactionsProbability: {
405
408
  env: 'P2P_DROP_TX_CHANCE',
406
- description: 'The probability that a transaction is discarded. - For testing purposes only',
409
+ description: 'The probability that a transaction is discarded (0 - 1). - For testing purposes only',
407
410
  ...floatConfigHelper(0),
408
411
  },
409
412
  disableTransactions: {
@@ -412,6 +415,22 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
412
415
  'Whether transactions are disabled for this node. This means transactions will be rejected at the RPC and P2P layers.',
413
416
  ...booleanConfigHelper(false),
414
417
  },
418
+ txPoolDeleteTxsAfterReorg: {
419
+ env: 'P2P_TX_POOL_DELETE_TXS_AFTER_REORG',
420
+ description: 'Whether to delete transactions from the pool after a reorg instead of moving them back to pending.',
421
+ ...booleanConfigHelper(false),
422
+ },
423
+ debugP2PInstrumentMessages: {
424
+ env: 'DEBUG_P2P_INSTRUMENT_MESSAGES',
425
+ description: 'Alters the format of p2p messages to include things like broadcast timestamp FOR TESTING ONLY',
426
+ ...booleanConfigHelper(false),
427
+ },
428
+ fishermanMode: {
429
+ env: 'FISHERMAN_MODE',
430
+ description:
431
+ 'Whether to run in fisherman mode: validates all proposals and attestations but does not broadcast attestations or participate in consensus.',
432
+ ...booleanConfigHelper(false),
433
+ },
415
434
  ...p2pReqRespConfigMappings,
416
435
  ...chainConfigMappings,
417
436
  ...txCollectionConfigMappings,
@@ -441,9 +460,10 @@ export type BootnodeConfig = Pick<
441
460
  | 'peerIdPrivateKeyPath'
442
461
  | 'bootstrapNodes'
443
462
  | 'listenAddress'
463
+ | 'queryForIp'
444
464
  > &
445
465
  Required<Pick<P2PConfig, 'p2pIp' | 'p2pPort'>> &
446
- Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKB'> &
466
+ Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb'> &
447
467
  Pick<ChainConfig, 'l1ChainId'>;
448
468
 
449
469
  const bootnodeConfigKeys: (keyof BootnodeConfig)[] = [
@@ -454,9 +474,10 @@ const bootnodeConfigKeys: (keyof BootnodeConfig)[] = [
454
474
  'peerIdPrivateKey',
455
475
  'peerIdPrivateKeyPath',
456
476
  'dataDirectory',
457
- 'dataStoreMapSizeKB',
477
+ 'dataStoreMapSizeKb',
458
478
  'bootstrapNodes',
459
479
  'l1ChainId',
480
+ 'queryForIp',
460
481
  ];
461
482
 
462
483
  export const bootnodeConfigMappings = pickConfigMappings(
@@ -2,9 +2,9 @@ import type { LogFn } from '@aztec/foundation/log';
2
2
  import { type ChainConfig, emptyChainConfig } from '@aztec/stdlib/config';
3
3
  import type { ComponentsVersions } from '@aztec/stdlib/versioning';
4
4
 
5
- import { ENR, SignableENR } from '@chainsafe/enr';
6
5
  import type { PeerId } from '@libp2p/interface';
7
6
  import { type Multiaddr, multiaddr } from '@multiformats/multiaddr';
7
+ import { ENR, SignableENR } from '@nethermindeth/enr';
8
8
 
9
9
  import { AZTEC_ENR_CLIENT_VERSION_KEY, AZTEC_ENR_KEY } from '../types/index.js';
10
10
  import { convertToMultiaddr, createLibP2PPeerIdFromPrivateKey } from '../util.js';
@@ -0,0 +1,13 @@
1
+ export class AttestationPoolError extends Error {
2
+ constructor(message?: string) {
3
+ super(message);
4
+ this.name = 'AttestationPoolError';
5
+ }
6
+ }
7
+
8
+ export class ProposalSlotCapExceededError extends AttestationPoolError {
9
+ constructor(message?: string) {
10
+ super(message);
11
+ this.name = 'ProposalSlotCapExceededError';
12
+ }
13
+ }