@aztec/p2p 0.0.1-commit.4d79d1f2d → 0.0.1-commit.4d9804df

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 (499) hide show
  1. package/README.md +130 -3
  2. package/dest/bootstrap/bootstrap.d.ts +1 -1
  3. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  4. package/dest/bootstrap/bootstrap.js +22 -6
  5. package/dest/client/factory.d.ts +9 -8
  6. package/dest/client/factory.d.ts.map +1 -1
  7. package/dest/client/factory.js +50 -34
  8. package/dest/client/interface.d.ts +59 -27
  9. package/dest/client/interface.d.ts.map +1 -1
  10. package/dest/client/p2p_client.d.ts +40 -34
  11. package/dest/client/p2p_client.d.ts.map +1 -1
  12. package/dest/client/p2p_client.js +162 -135
  13. package/dest/config.d.ts +164 -100
  14. package/dest/config.d.ts.map +1 -1
  15. package/dest/config.js +149 -49
  16. package/dest/errors/p2p-service.error.d.ts +9 -0
  17. package/dest/errors/p2p-service.error.d.ts.map +1 -0
  18. package/dest/errors/p2p-service.error.js +10 -0
  19. package/dest/errors/reqresp.error.d.ts +9 -16
  20. package/dest/errors/reqresp.error.d.ts.map +1 -1
  21. package/dest/errors/reqresp.error.js +10 -17
  22. package/dest/errors/tx-pool.error.d.ts +8 -0
  23. package/dest/errors/tx-pool.error.d.ts.map +1 -0
  24. package/dest/errors/tx-pool.error.js +9 -0
  25. package/dest/index.d.ts +1 -2
  26. package/dest/index.d.ts.map +1 -1
  27. package/dest/index.js +0 -1
  28. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +103 -59
  29. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  30. package/dest/mem_pools/attestation_pool/attestation_pool.js +278 -196
  31. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  32. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  33. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +224 -65
  34. package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
  35. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  36. package/dest/mem_pools/attestation_pool/mocks.js +7 -5
  37. package/dest/mem_pools/index.d.ts +1 -2
  38. package/dest/mem_pools/index.d.ts.map +1 -1
  39. package/dest/mem_pools/instrumentation.d.ts +12 -5
  40. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  41. package/dest/mem_pools/instrumentation.js +38 -17
  42. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +1 -5
  43. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -1
  44. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +1 -7
  45. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +32 -15
  46. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
  47. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +95 -24
  48. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  49. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  50. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  51. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  52. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  53. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +8 -4
  54. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  55. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  56. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
  57. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +3 -2
  58. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  59. package/dest/mem_pools/tx_pool_v2/eviction/index.js +2 -1
  60. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
  61. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
  62. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +62 -0
  63. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +54 -5
  64. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  65. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  66. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +7 -5
  67. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +9 -7
  68. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  69. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  70. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +14 -6
  71. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  72. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  73. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +16 -4
  74. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  75. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  76. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +3 -3
  77. package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -2
  78. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  79. package/dest/mem_pools/tx_pool_v2/index.js +1 -1
  80. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  81. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  82. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  83. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +60 -14
  84. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  85. package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -1
  86. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +59 -15
  87. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  88. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +116 -20
  89. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +26 -3
  90. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  91. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +79 -43
  92. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +20 -7
  93. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  94. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +34 -12
  95. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +29 -7
  96. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  97. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +473 -211
  98. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +10 -3
  99. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  100. package/dest/msg_validators/attestation_validator/attestation_validator.js +38 -15
  101. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +7 -3
  102. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  103. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +4 -5
  104. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +12 -5
  105. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  106. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +11 -3
  107. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +12 -5
  108. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  109. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +23 -3
  110. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +36 -9
  111. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  112. package/dest/msg_validators/proposal_validator/proposal_validator.js +130 -48
  113. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +2 -2
  114. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  115. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +11 -18
  116. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  117. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  118. package/dest/msg_validators/tx_validator/allowed_public_setup.js +25 -21
  119. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  120. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  121. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  122. package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
  123. package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts +15 -0
  124. package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts.map +1 -0
  125. package/dest/msg_validators/tx_validator/cached_tx_validator.js +19 -0
  126. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
  127. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
  128. package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
  129. package/dest/msg_validators/tx_validator/data_validator.d.ts +2 -1
  130. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  131. package/dest/msg_validators/tx_validator/data_validator.js +36 -2
  132. package/dest/msg_validators/tx_validator/factory.d.ts +133 -7
  133. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  134. package/dest/msg_validators/tx_validator/factory.js +261 -61
  135. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  136. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  137. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  138. package/dest/msg_validators/tx_validator/gas_validator.d.ts +104 -3
  139. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  140. package/dest/msg_validators/tx_validator/gas_validator.js +137 -53
  141. package/dest/msg_validators/tx_validator/index.d.ts +5 -1
  142. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  143. package/dest/msg_validators/tx_validator/index.js +4 -0
  144. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  145. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  146. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  147. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  148. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  149. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  150. package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
  151. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  152. package/dest/msg_validators/tx_validator/phases_validator.js +72 -24
  153. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +2 -2
  154. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  155. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  156. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +2 -1
  157. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  158. package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -0
  159. package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts +48 -0
  160. package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts.map +1 -0
  161. package/dest/msg_validators/tx_validator/tx_validation_cache.js +68 -0
  162. package/dest/services/data_store.d.ts +1 -1
  163. package/dest/services/data_store.d.ts.map +1 -1
  164. package/dest/services/data_store.js +5 -5
  165. package/dest/services/discv5/discV5_service.d.ts +13 -2
  166. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  167. package/dest/services/discv5/discV5_service.js +119 -23
  168. package/dest/services/discv5/persisted_enr_store.d.ts +38 -0
  169. package/dest/services/discv5/persisted_enr_store.d.ts.map +1 -0
  170. package/dest/services/discv5/persisted_enr_store.js +145 -0
  171. package/dest/services/dummy_service.d.ts +18 -18
  172. package/dest/services/dummy_service.d.ts.map +1 -1
  173. package/dest/services/dummy_service.js +19 -20
  174. package/dest/services/encoding.d.ts +23 -6
  175. package/dest/services/encoding.d.ts.map +1 -1
  176. package/dest/services/encoding.js +41 -24
  177. package/dest/services/gossipsub/topic_score_params.d.ts +23 -17
  178. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
  179. package/dest/services/gossipsub/topic_score_params.js +36 -24
  180. package/dest/services/libp2p/instrumentation.d.ts +3 -1
  181. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  182. package/dest/services/libp2p/instrumentation.js +14 -0
  183. package/dest/services/libp2p/libp2p_service.d.ts +57 -56
  184. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  185. package/dest/services/libp2p/libp2p_service.js +483 -373
  186. package/dest/services/peer-manager/metrics.d.ts +3 -1
  187. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  188. package/dest/services/peer-manager/metrics.js +6 -0
  189. package/dest/services/peer-manager/peer_manager.d.ts +20 -3
  190. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  191. package/dest/services/peer-manager/peer_manager.js +83 -26
  192. package/dest/services/peer-manager/peer_scoring.d.ts +34 -2
  193. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  194. package/dest/services/peer-manager/peer_scoring.js +102 -13
  195. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +5 -8
  196. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  197. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +95 -127
  198. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +11 -11
  199. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  200. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +11 -13
  201. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  202. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +31 -46
  203. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
  204. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  205. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
  206. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +5 -14
  207. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -1
  208. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +6 -20
  209. package/dest/services/reqresp/config.d.ts +15 -3
  210. package/dest/services/reqresp/config.d.ts.map +1 -1
  211. package/dest/services/reqresp/config.js +11 -0
  212. package/dest/services/reqresp/interface.d.ts +16 -18
  213. package/dest/services/reqresp/interface.d.ts.map +1 -1
  214. package/dest/services/reqresp/interface.js +10 -20
  215. package/dest/services/reqresp/metrics.d.ts +1 -1
  216. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  217. package/dest/services/reqresp/metrics.js +0 -1
  218. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +4 -3
  219. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  220. package/dest/services/reqresp/protocols/block_txs/bitvector.js +3 -2
  221. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
  222. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  223. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +31 -28
  224. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +12 -7
  225. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  226. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +42 -24
  227. package/dest/services/reqresp/protocols/index.d.ts +1 -2
  228. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  229. package/dest/services/reqresp/protocols/index.js +0 -1
  230. package/dest/services/reqresp/protocols/tx.d.ts +1 -1
  231. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  232. package/dest/services/reqresp/protocols/tx.js +1 -3
  233. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
  234. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  235. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
  236. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  237. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  238. package/dest/services/reqresp/rate-limiter/rate_limits.js +3 -13
  239. package/dest/services/reqresp/reqresp.d.ts +7 -29
  240. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  241. package/dest/services/reqresp/reqresp.js +75 -216
  242. package/dest/services/service.d.ts +29 -14
  243. package/dest/services/service.d.ts.map +1 -1
  244. package/dest/services/tx_collection/config.d.ts +8 -17
  245. package/dest/services/tx_collection/config.d.ts.map +1 -1
  246. package/dest/services/tx_collection/config.js +17 -40
  247. package/dest/services/tx_collection/file_store_tx_collection.d.ts +25 -32
  248. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
  249. package/dest/services/tx_collection/file_store_tx_collection.js +96 -87
  250. package/dest/services/tx_collection/file_store_tx_source.d.ts +17 -6
  251. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
  252. package/dest/services/tx_collection/file_store_tx_source.js +53 -10
  253. package/dest/services/tx_collection/index.d.ts +2 -3
  254. package/dest/services/tx_collection/index.d.ts.map +1 -1
  255. package/dest/services/tx_collection/index.js +0 -1
  256. package/dest/services/tx_collection/instrumentation.js +1 -2
  257. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  258. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  259. package/dest/services/tx_collection/request_tracker.js +84 -0
  260. package/dest/services/tx_collection/tx_collection.d.ts +39 -55
  261. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  262. package/dest/services/tx_collection/tx_collection.js +280 -108
  263. package/dest/services/tx_collection/tx_collection_sink.d.ts +7 -6
  264. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  265. package/dest/services/tx_collection/tx_collection_sink.js +15 -24
  266. package/dest/services/tx_collection/tx_source.d.ts +13 -7
  267. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  268. package/dest/services/tx_collection/tx_source.js +29 -7
  269. package/dest/services/tx_file_store/tx_file_store.d.ts +3 -4
  270. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  271. package/dest/services/tx_file_store/tx_file_store.js +13 -20
  272. package/dest/services/tx_provider.d.ts +5 -3
  273. package/dest/services/tx_provider.d.ts.map +1 -1
  274. package/dest/services/tx_provider.js +7 -4
  275. package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
  276. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  277. package/dest/test-helpers/make-test-p2p-clients.js +5 -3
  278. package/dest/test-helpers/mock-pubsub.d.ts +26 -12
  279. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  280. package/dest/test-helpers/mock-pubsub.js +51 -45
  281. package/dest/test-helpers/reqresp-nodes.d.ts +5 -7
  282. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  283. package/dest/test-helpers/reqresp-nodes.js +17 -19
  284. package/dest/test-helpers/test_tx_provider.d.ts +3 -1
  285. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -1
  286. package/dest/test-helpers/test_tx_provider.js +3 -0
  287. package/dest/test-helpers/testbench-utils.d.ts +22 -16
  288. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  289. package/dest/test-helpers/testbench-utils.js +56 -16
  290. package/dest/testbench/p2p_client_testbench_worker.d.ts +3 -5
  291. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  292. package/dest/testbench/p2p_client_testbench_worker.js +111 -48
  293. package/dest/testbench/worker_client_manager.d.ts +12 -6
  294. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  295. package/dest/testbench/worker_client_manager.js +57 -11
  296. package/dest/util.d.ts +13 -8
  297. package/dest/util.d.ts.map +1 -1
  298. package/dest/util.js +35 -14
  299. package/dest/versioning.d.ts +3 -6
  300. package/dest/versioning.d.ts.map +1 -1
  301. package/dest/versioning.js +3 -24
  302. package/package.json +16 -16
  303. package/src/bootstrap/bootstrap.ts +17 -3
  304. package/src/client/factory.ts +95 -51
  305. package/src/client/interface.ts +59 -35
  306. package/src/client/p2p_client.ts +186 -196
  307. package/src/client/test/{tx_proposal_collector/README.md → p2p_client.batch_tx_requester.bench.README.md} +23 -53
  308. package/src/config.ts +259 -57
  309. package/src/errors/p2p-service.error.ts +11 -0
  310. package/src/errors/reqresp.error.ts +13 -19
  311. package/src/errors/tx-pool.error.ts +12 -0
  312. package/src/index.ts +0 -1
  313. package/src/mem_pools/attestation_pool/attestation_pool.ts +336 -242
  314. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +244 -69
  315. package/src/mem_pools/attestation_pool/mocks.ts +14 -8
  316. package/src/mem_pools/index.ts +0 -3
  317. package/src/mem_pools/instrumentation.ts +27 -17
  318. package/src/mem_pools/tx_pool_v2/README.md +52 -28
  319. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +1 -9
  320. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +114 -27
  321. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  322. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +8 -4
  323. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
  324. package/src/mem_pools/tx_pool_v2/eviction/index.ts +5 -0
  325. package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +65 -0
  326. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +59 -4
  327. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
  328. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +8 -8
  329. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -9
  330. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +33 -6
  331. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +4 -3
  332. package/src/mem_pools/tx_pool_v2/index.ts +1 -1
  333. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  334. package/src/mem_pools/tx_pool_v2/interfaces.ts +61 -14
  335. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +170 -28
  336. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +91 -43
  337. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +54 -14
  338. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +527 -207
  339. package/src/msg_validators/attestation_validator/README.md +49 -0
  340. package/src/msg_validators/attestation_validator/attestation_validator.ts +46 -14
  341. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +15 -7
  342. package/src/msg_validators/proposal_validator/README.md +123 -0
  343. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +26 -4
  344. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +43 -7
  345. package/src/msg_validators/proposal_validator/proposal_validator.ts +155 -49
  346. package/src/msg_validators/tx_validator/README.md +129 -0
  347. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +6 -15
  348. package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
  349. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  350. package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
  351. package/src/msg_validators/tx_validator/cached_tx_validator.ts +31 -0
  352. package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
  353. package/src/msg_validators/tx_validator/data_validator.ts +44 -1
  354. package/src/msg_validators/tx_validator/factory.ts +413 -80
  355. package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
  356. package/src/msg_validators/tx_validator/gas_validator.ts +195 -54
  357. package/src/msg_validators/tx_validator/index.ts +4 -0
  358. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  359. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  360. package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
  361. package/src/msg_validators/tx_validator/timestamp_validator.ts +7 -7
  362. package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -0
  363. package/src/msg_validators/tx_validator/tx_validation_cache.ts +101 -0
  364. package/src/services/data_store.ts +5 -13
  365. package/src/services/discv5/discV5_service.ts +126 -14
  366. package/src/services/discv5/persisted_enr_store.ts +158 -0
  367. package/src/services/dummy_service.ts +26 -45
  368. package/src/services/encoding.ts +40 -24
  369. package/src/services/gossipsub/README.md +59 -22
  370. package/src/services/gossipsub/topic_score_params.ts +58 -31
  371. package/src/services/libp2p/instrumentation.ts +14 -0
  372. package/src/services/libp2p/libp2p_service.ts +554 -428
  373. package/src/services/peer-manager/metrics.ts +7 -0
  374. package/src/services/peer-manager/peer_manager.ts +91 -25
  375. package/src/services/peer-manager/peer_scoring.ts +102 -8
  376. package/src/services/reqresp/README.md +194 -0
  377. package/src/services/reqresp/batch-tx-requester/README.md +46 -7
  378. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +92 -138
  379. package/src/services/reqresp/batch-tx-requester/interface.ts +14 -10
  380. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +30 -71
  381. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
  382. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +12 -25
  383. package/src/services/reqresp/config.ts +19 -2
  384. package/src/services/reqresp/interface.ts +21 -47
  385. package/src/services/reqresp/metrics.ts +0 -1
  386. package/src/services/reqresp/protocols/block_txs/bitvector.ts +3 -2
  387. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +34 -30
  388. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +47 -20
  389. package/src/services/reqresp/protocols/index.ts +0 -1
  390. package/src/services/reqresp/protocols/tx.ts +1 -3
  391. package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
  392. package/src/services/reqresp/rate-limiter/rate_limits.ts +3 -13
  393. package/src/services/reqresp/reqresp.ts +87 -260
  394. package/src/services/service.ts +42 -30
  395. package/src/services/tx_collection/config.ts +24 -59
  396. package/src/services/tx_collection/file_store_tx_collection.ts +108 -107
  397. package/src/services/tx_collection/file_store_tx_source.ts +69 -10
  398. package/src/services/tx_collection/index.ts +1 -6
  399. package/src/services/tx_collection/instrumentation.ts +1 -1
  400. package/src/services/tx_collection/request_tracker.ts +127 -0
  401. package/src/services/tx_collection/tx_collection.ts +342 -156
  402. package/src/services/tx_collection/tx_collection_sink.ts +17 -31
  403. package/src/services/tx_collection/tx_source.ts +29 -8
  404. package/src/services/tx_file_store/tx_file_store.ts +11 -21
  405. package/src/services/tx_provider.ts +7 -2
  406. package/src/test-helpers/make-test-p2p-clients.ts +4 -3
  407. package/src/test-helpers/mock-pubsub.ts +59 -66
  408. package/src/test-helpers/reqresp-nodes.ts +15 -28
  409. package/src/test-helpers/test_tx_provider.ts +5 -0
  410. package/src/test-helpers/testbench-utils.ts +74 -31
  411. package/src/testbench/p2p_client_testbench_worker.ts +120 -63
  412. package/src/testbench/worker_client_manager.ts +72 -25
  413. package/src/util.ts +40 -19
  414. package/src/versioning.ts +3 -33
  415. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +0 -2
  416. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +0 -1
  417. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +0 -305
  418. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +0 -73
  419. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +0 -1
  420. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +0 -8
  421. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
  422. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
  423. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
  424. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
  425. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
  426. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
  427. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
  428. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
  429. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
  430. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
  431. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
  432. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
  433. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
  434. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
  435. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
  436. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
  437. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
  438. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
  439. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
  440. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
  441. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
  442. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
  443. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
  444. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
  445. package/dest/mem_pools/tx_pool/index.d.ts +0 -3
  446. package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
  447. package/dest/mem_pools/tx_pool/index.js +0 -2
  448. package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
  449. package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
  450. package/dest/mem_pools/tx_pool/priority.js +0 -15
  451. package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
  452. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
  453. package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
  454. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
  455. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
  456. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
  457. package/dest/msg_validators/clock_tolerance.d.ts +0 -21
  458. package/dest/msg_validators/clock_tolerance.d.ts.map +0 -1
  459. package/dest/msg_validators/clock_tolerance.js +0 -37
  460. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
  461. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  462. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
  463. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +0 -64
  464. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +0 -1
  465. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +0 -151
  466. package/dest/services/reqresp/protocols/block.d.ts +0 -9
  467. package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
  468. package/dest/services/reqresp/protocols/block.js +0 -32
  469. package/dest/services/tx_collection/fast_tx_collection.d.ts +0 -54
  470. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
  471. package/dest/services/tx_collection/fast_tx_collection.js +0 -321
  472. package/dest/services/tx_collection/proposal_tx_collector.d.ts +0 -48
  473. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +0 -1
  474. package/dest/services/tx_collection/proposal_tx_collector.js +0 -49
  475. package/dest/services/tx_collection/slow_tx_collection.d.ts +0 -55
  476. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +0 -1
  477. package/dest/services/tx_collection/slow_tx_collection.js +0 -206
  478. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +0 -336
  479. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +0 -43
  480. package/src/mem_pools/tx_pool/README.md +0 -270
  481. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
  482. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
  483. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
  484. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
  485. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
  486. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
  487. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
  488. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
  489. package/src/mem_pools/tx_pool/index.ts +0 -2
  490. package/src/mem_pools/tx_pool/priority.ts +0 -20
  491. package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
  492. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
  493. package/src/msg_validators/clock_tolerance.ts +0 -51
  494. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
  495. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +0 -161
  496. package/src/services/reqresp/protocols/block.ts +0 -37
  497. package/src/services/tx_collection/fast_tx_collection.ts +0 -366
  498. package/src/services/tx_collection/proposal_tx_collector.ts +0 -112
  499. package/src/services/tx_collection/slow_tx_collection.ts +0 -262
@@ -1,30 +1,31 @@
1
- import { GENESIS_BLOCK_HEADER_HASH } from '@aztec/constants';
2
1
  import type { EpochCacheInterface } from '@aztec/epoch-cache';
3
- import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
+ import {
3
+ BlockNumber,
4
+ CheckpointNumber,
5
+ type CheckpointProposalHash,
6
+ SlotNumber,
7
+ } from '@aztec/foundation/branded-types';
4
8
  import { createLogger } from '@aztec/foundation/log';
5
- import { RunningPromise } from '@aztec/foundation/promise';
6
9
  import { DateProvider } from '@aztec/foundation/timer';
7
10
  import type { AztecAsyncKVStore, AztecAsyncSingleton } from '@aztec/kv-store';
8
11
  import { L2TipsKVStore } from '@aztec/kv-store/stores';
9
12
  import {
13
+ type BlockData,
14
+ type BlockHash,
15
+ type CheckpointId,
10
16
  type EthAddress,
17
+ EventDrivenL2BlockStream,
11
18
  type L2Block,
12
19
  type L2BlockId,
13
20
  type L2BlockSource,
14
- L2BlockStream,
15
21
  type L2BlockStreamEvent,
16
- type L2Tips,
17
22
  type L2TipsStore,
23
+ type LocalL2Tips,
18
24
  } from '@aztec/stdlib/block';
19
25
  import type { ContractDataSource } from '@aztec/stdlib/contract';
20
26
  import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
21
- import { type PeerInfo, tryStop } from '@aztec/stdlib/interfaces/server';
22
- import {
23
- type BlockProposal,
24
- CheckpointAttestation,
25
- type CheckpointProposal,
26
- type P2PClientType,
27
- } from '@aztec/stdlib/p2p';
27
+ import { type GetTxByHashOptions, type PeerInfo, tryStop } from '@aztec/stdlib/interfaces/server';
28
+ import { type BlockProposal, CheckpointAttestation, type CheckpointProposal, type TopicType } from '@aztec/stdlib/p2p';
28
29
  import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
29
30
  import { Attributes, type TelemetryClient, WithTracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
30
31
 
@@ -32,19 +33,16 @@ import type { PeerId } from '@libp2p/interface';
32
33
  import type { ENR } from '@nethermindeth/enr';
33
34
 
34
35
  import { type P2PConfig, getP2PDefaultConfig } from '../config.js';
35
- import type { AttestationPoolApi } from '../mem_pools/attestation_pool/attestation_pool.js';
36
+ import { TxPoolError } from '../errors/tx-pool.error.js';
37
+ import type { AttestationPoolApi, ProposalsForSlot } from '../mem_pools/attestation_pool/attestation_pool.js';
36
38
  import type { MemPools } from '../mem_pools/interface.js';
37
39
  import type { TxPoolV2 } from '../mem_pools/tx_pool_v2/interfaces.js';
38
40
  import type { AuthRequest, StatusMessage } from '../services/index.js';
39
- import {
40
- ReqRespSubProtocol,
41
- type ReqRespSubProtocolHandler,
42
- type ReqRespSubProtocolValidators,
43
- } from '../services/reqresp/interface.js';
44
- import { chunkTxHashesRequest } from '../services/reqresp/protocols/tx.js';
41
+ import { ReqRespSubProtocol, type ReqRespSubProtocolHandler } from '../services/reqresp/interface.js';
45
42
  import type {
46
43
  DuplicateAttestationInfo,
47
44
  DuplicateProposalInfo,
45
+ OversizedProposalInfo,
48
46
  P2PBlockReceivedCallback,
49
47
  P2PCheckpointReceivedCallback,
50
48
  P2PService,
@@ -57,10 +55,7 @@ import { type P2P, P2PClientState, type P2PSyncState } from './interface.js';
57
55
  /**
58
56
  * The P2P client implementation.
59
57
  */
60
- export class P2PClient<T extends P2PClientType = P2PClientType.Full>
61
- extends WithTracer
62
- implements P2P, P2P<P2PClientType.Prover>
63
- {
58
+ export class P2PClient extends WithTracer implements P2P {
64
59
  /** The JS promise that will be running to keep the client's data in sync. Can be interrupted if the client is stopped. */
65
60
  private runningPromise!: Promise<void>;
66
61
 
@@ -79,7 +74,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
79
74
 
80
75
  private config: P2PConfig;
81
76
 
82
- private blockStream: L2BlockStream | undefined;
77
+ private blockStream: EventDrivenL2BlockStream | undefined;
83
78
 
84
79
  private txProvider: TxProvider;
85
80
 
@@ -88,11 +83,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
88
83
  /** Tracks the last slot for which we called prepareForSlot */
89
84
  private lastSlotProcessed: SlotNumber = SlotNumber.ZERO;
90
85
 
91
- /** Polls for slot changes and calls prepareForSlot on the tx pool */
92
- private slotMonitor: RunningPromise | undefined;
93
-
94
86
  constructor(
95
- _clientType: T,
96
87
  private store: AztecAsyncKVStore,
97
88
  private l2BlockSource: L2BlockSource & ContractDataSource,
98
89
  mempools: MemPools,
@@ -104,6 +95,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
104
95
  private _dateProvider: DateProvider = new DateProvider(),
105
96
  private telemetry: TelemetryClient = getTelemetryClient(),
106
97
  private log = createLogger('p2p'),
98
+ initialBlockHash: BlockHash,
107
99
  ) {
108
100
  super(telemetry, 'P2PClient');
109
101
 
@@ -119,28 +111,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
119
111
  this.telemetry,
120
112
  );
121
113
 
122
- // Default to collecting all txs when we see a valid proposal
123
- // This can be overridden by the validator client to validate, and it will call getTxsForBlockProposal on its own
124
- // Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
125
- // TODO(palla/txs): We should not trigger a request for txs on a proposal before fully validating it. We need to bring
126
- // validator-client code into here so we can validate a proposal is reasonable.
127
- this.registerBlockProposalHandler(async (block, sender) => {
128
- this.log.debug(`Received block proposal from ${sender.toString()}`);
129
- // TODO(palla/txs): Need to subtract validatorReexecuteDeadlineMs from this deadline (see ValidatorClient.getReexecutionDeadline)
130
- const constants = this.txCollection.getConstants();
131
- const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(block.slotNumber + 1), constants));
132
- const deadline = new Date(nextSlotTimestampSeconds * 1000);
133
- const parentBlock = await this.l2BlockSource.getBlockHeaderByArchive(block.blockHeader.lastArchive.root);
134
- if (!parentBlock) {
135
- this.log.debug(`Cannot collect txs for proposal as parent block not found`);
136
- return false;
137
- }
138
- const blockNumber = BlockNumber(parentBlock.getBlockNumber() + 1);
139
- await this.txProvider.getTxsForBlockProposal(block, blockNumber, { pinnedPeer: sender, deadline });
140
- return true;
141
- });
142
-
143
- this.l2Tips = new L2TipsKVStore(store, 'p2p_client');
114
+ this.l2Tips = new L2TipsKVStore(store, 'p2p_client', initialBlockHash);
144
115
  this.synchedLatestSlot = store.openSingleton('p2p_pool_last_l2_slot');
145
116
  }
146
117
 
@@ -165,6 +136,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
165
136
  return Promise.resolve(this.p2pService.getPeers(includePending));
166
137
  }
167
138
 
139
+ public getGossipMeshPeerCount(topicType: TopicType): Promise<number> {
140
+ return Promise.resolve(this.p2pService.getGossipMeshPeerCount(topicType));
141
+ }
142
+
168
143
  public getL2BlockHash(number: BlockNumber): Promise<string | undefined> {
169
144
  return this.l2Tips.getL2BlockHash(number);
170
145
  }
@@ -174,7 +149,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
174
149
  this.p2pService.updateConfig(config);
175
150
  }
176
151
 
177
- public getL2Tips(): Promise<L2Tips> {
152
+ public getL2Tips(): Promise<LocalL2Tips> {
178
153
  return this.l2Tips.getL2Tips();
179
154
  }
180
155
 
@@ -190,7 +165,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
190
165
  const from = BlockNumber(oldFinalizedBlockNum + 1);
191
166
  const limit = event.block.number - from + 1;
192
167
  if (limit > 0) {
193
- const oldBlocks = await this.l2BlockSource.getBlocks(from, limit);
168
+ const oldBlocks = await this.l2BlockSource.getBlocksData({ from, limit });
194
169
  await this.handleFinalizedL2Blocks(oldBlocks);
195
170
  }
196
171
  break;
@@ -200,10 +175,12 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
200
175
  break;
201
176
  case 'chain-pruned':
202
177
  this.txCollection.stopCollectingForBlocksAfter(event.block.number);
203
- await this.handlePruneL2Blocks(event.block);
178
+ await this.handlePruneL2Blocks(event.block, event.checkpointed.checkpoint);
204
179
  break;
205
180
  case 'chain-checkpointed':
206
181
  break;
182
+ case 'chain-proposed':
183
+ break;
207
184
  default: {
208
185
  const _: never = event;
209
186
  break;
@@ -283,33 +260,24 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
283
260
  });
284
261
  }
285
262
 
286
- this.blockStream!.start();
287
- await this.txCollection.start();
263
+ // Should never happen: all branches above call initBlockStream()
264
+ if (!this.blockStream) {
265
+ throw new Error('Block stream not initialized');
266
+ }
267
+ this.blockStream.start();
288
268
  this.txFileStore?.start();
289
269
 
290
- // Start slot monitor to call prepareForSlot when the slot changes
291
- this.slotMonitor = new RunningPromise(
292
- () => this.maybeCallPrepareForSlot(),
293
- this.log,
294
- this.config.slotCheckIntervalMS,
295
- );
296
- this.slotMonitor.start();
297
-
298
270
  return this.syncPromise;
299
271
  }
300
272
 
301
- addReqRespSubProtocol(
302
- subProtocol: ReqRespSubProtocol,
303
- handler: ReqRespSubProtocolHandler,
304
- validator: ReqRespSubProtocolValidators[ReqRespSubProtocol],
305
- ): Promise<void> {
306
- return this.p2pService.addReqRespSubProtocol(subProtocol, handler, validator);
273
+ addReqRespSubProtocol(subProtocol: ReqRespSubProtocol, handler: ReqRespSubProtocolHandler): Promise<void> {
274
+ return this.p2pService.addReqRespSubProtocol(subProtocol, handler);
307
275
  }
308
276
 
309
277
  private initBlockStream(startingBlock?: BlockNumber) {
310
278
  if (!this.blockStream) {
311
279
  const { blockRequestBatchSize: batchSize, blockCheckIntervalMS: pollIntervalMS } = this.config;
312
- this.blockStream = new L2BlockStream(
280
+ this.blockStream = new EventDrivenL2BlockStream(
313
281
  this.l2BlockSource,
314
282
  this,
315
283
  this,
@@ -325,8 +293,6 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
325
293
  */
326
294
  public async stop() {
327
295
  this.log.debug('Stopping p2p client...');
328
- await this.slotMonitor?.stop();
329
- this.log.debug('Stopped slot monitor');
330
296
  await tryStop(this.txCollection);
331
297
  this.log.debug('Stopped tx collection service');
332
298
  await this.txFileStore?.stop();
@@ -345,7 +311,11 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
345
311
  /** Triggers a sync to the archiver. Used for testing. */
346
312
  public async sync() {
347
313
  this.initBlockStream();
348
- await this.blockStream!.sync();
314
+ // Should never happen: initBlockStream() creates blockStream if absent
315
+ if (!this.blockStream) {
316
+ throw new Error('Block stream not initialized');
317
+ }
318
+ await this.blockStream.sync();
349
319
  }
350
320
 
351
321
  @trackSpan('p2pClient.broadcastProposal', async proposal => ({
@@ -383,6 +353,19 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
383
353
  // Store our own last-block proposal so we can respond to req/resp requests for it.
384
354
  await this.attestationPool.tryAddBlockProposal(blockProposal);
385
355
  }
356
+ const checkpointCore = proposal.toCore();
357
+ const { count } = await this.attestationPool.tryAddCheckpointProposal(checkpointCore);
358
+ if (count > 1) {
359
+ if (this.config.broadcastEquivocatedProposals) {
360
+ this.log.warn(`Broadcasting equivocated checkpoint proposal for slot ${proposal.slotNumber}`, {
361
+ slot: proposal.slotNumber,
362
+ archive: proposal.archive.toString(),
363
+ count,
364
+ });
365
+ } else {
366
+ throw new Error(`Attempted to broadcast a duplicate checkpoint proposal for slot ${proposal.slotNumber}`);
367
+ }
368
+ }
386
369
  return this.p2pService.propagate(proposal);
387
370
  }
388
371
 
@@ -393,10 +376,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
393
376
 
394
377
  public async getCheckpointAttestationsForSlot(
395
378
  slot: SlotNumber,
396
- proposalId?: string,
379
+ proposalPayloadHash?: CheckpointProposalHash,
397
380
  ): Promise<CheckpointAttestation[]> {
398
- return await (proposalId
399
- ? this.attestationPool.getCheckpointAttestationsForSlotAndProposal(slot, proposalId)
381
+ return await (proposalPayloadHash
382
+ ? this.attestationPool.getCheckpointAttestationsForSlotAndProposal(slot, proposalPayloadHash)
400
383
  : this.attestationPool.getCheckpointAttestationsForSlot(slot));
401
384
  }
402
385
 
@@ -404,55 +387,49 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
404
387
  return this.attestationPool.addOwnCheckpointAttestations(attestations);
405
388
  }
406
389
 
390
+ public getProposalsForSlot(slot: SlotNumber): Promise<ProposalsForSlot> {
391
+ return this.attestationPool.getProposalsForSlot(slot);
392
+ }
393
+
394
+ public hasBlockProposalsForSlot(slot: SlotNumber): Promise<boolean> {
395
+ return this.attestationPool.hasBlockProposalsForSlot(slot);
396
+ }
397
+
398
+ public hasCheckpointProposalForSlot(slot: SlotNumber): Promise<boolean> {
399
+ return this.attestationPool.hasCheckpointProposalForSlot(slot);
400
+ }
401
+
407
402
  // REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
408
403
  // ^ This pattern is not my favorite (md)
409
404
  public registerBlockProposalHandler(handler: P2PBlockReceivedCallback): void {
410
405
  this.p2pService.registerBlockReceivedCallback(handler);
411
406
  }
412
407
 
413
- public registerCheckpointProposalHandler(handler: P2PCheckpointReceivedCallback): void {
414
- this.p2pService.registerCheckpointReceivedCallback(handler);
408
+ public registerValidatorCheckpointProposalHandler(handler: P2PCheckpointReceivedCallback): void {
409
+ this.p2pService.registerValidatorCheckpointReceivedCallback(handler);
410
+ }
411
+
412
+ public registerAllNodesCheckpointProposalHandler(handler: P2PCheckpointReceivedCallback): void {
413
+ this.p2pService.registerAllNodesCheckpointReceivedCallback(handler);
415
414
  }
416
415
 
417
416
  public registerDuplicateProposalCallback(callback: (info: DuplicateProposalInfo) => void): void {
418
417
  this.p2pService.registerDuplicateProposalCallback(callback);
419
418
  }
420
419
 
420
+ public registerOversizedProposalCallback(callback: (info: OversizedProposalInfo) => void): void {
421
+ this.p2pService.registerOversizedProposalCallback(callback);
422
+ }
423
+
421
424
  public registerDuplicateAttestationCallback(callback: (info: DuplicateAttestationInfo) => void): void {
422
425
  this.p2pService.registerDuplicateAttestationCallback(callback);
423
426
  }
424
427
 
425
- /**
426
- * Uses the batched Request Response protocol to request a set of transactions from the network.
427
- */
428
- private async requestTxsByHash(txHashes: TxHash[], pinnedPeerId: PeerId | undefined): Promise<Tx[]> {
429
- const timeoutMs = 8000; // Longer timeout for now
430
- const maxRetryAttempts = 10; // Keep retrying within the timeout
431
- const requests = chunkTxHashesRequest(txHashes);
432
- const maxPeers = Math.min(Math.ceil(requests.length / 3), 10);
433
-
434
- const txBatches = await this.p2pService.sendBatchRequest(
435
- ReqRespSubProtocol.TX,
436
- requests,
437
- pinnedPeerId,
438
- timeoutMs,
439
- maxPeers,
440
- maxRetryAttempts,
441
- );
442
-
443
- const txs = txBatches.flat();
444
- if (txs.length > 0) {
445
- await this.txPool.addPendingTxs(txs);
446
- }
447
-
448
- const txHashesStr = txHashes.map(tx => tx.toString()).join(', ');
449
- this.log.debug(`Requested txs ${txHashesStr} (${txs.length} / ${txHashes.length}) from peers`);
450
-
451
- // We return all transactions, even the not found ones to the caller, such they can handle missing items themselves.
452
- return txs;
428
+ public registerCheckpointAttestationCallback(callback: (attestation: CheckpointAttestation) => void): void {
429
+ this.p2pService.registerCheckpointAttestationCallback(callback);
453
430
  }
454
431
 
455
- public async getPendingTxs(limit?: number, after?: TxHash): Promise<Tx[]> {
432
+ public async getPendingTxs(limit?: number, after?: TxHash, options?: GetTxByHashOptions): Promise<Tx[]> {
456
433
  if (limit !== undefined && limit <= 0) {
457
434
  throw new TypeError('limit must be greater than 0');
458
435
  }
@@ -471,7 +448,9 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
471
448
  const endIndex = limit !== undefined ? startIndex + limit : undefined;
472
449
  txHashes = txHashes.slice(startIndex, endIndex);
473
450
 
474
- const maybeTxs = await Promise.all(txHashes.map(txHash => this.txPool.getTxByHash(txHash)));
451
+ // This is a public-facing API (exposed via both the node and the p2p RPC), so proofs are opt-in.
452
+ const includeProof = !!options?.includeProof;
453
+ const maybeTxs = await Promise.all(txHashes.map(txHash => this.txPool.getTxByHash(txHash, { includeProof })));
475
454
  return maybeTxs.filter((tx): tx is Tx => !!tx);
476
455
  }
477
456
 
@@ -479,9 +458,22 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
479
458
  return this.txPool.getPendingTxCount();
480
459
  }
481
460
 
482
- public async *iteratePendingTxs(): AsyncIterableIterator<Tx> {
461
+ public hasEligiblePendingTxs(minCount: number): Promise<boolean> {
462
+ return this.txPool.hasEligiblePendingTxs(minCount);
463
+ }
464
+
465
+ public async *iteratePendingTxs(opts?: { includeProof?: boolean }): AsyncIterableIterator<Tx> {
483
466
  for (const txHash of await this.txPool.getPendingTxHashes()) {
484
- const tx = await this.txPool.getTxByHash(txHash);
467
+ const tx = await this.txPool.getTxByHash(txHash, opts);
468
+ if (tx) {
469
+ yield tx;
470
+ }
471
+ }
472
+ }
473
+
474
+ public async *iterateEligiblePendingTxs(opts?: { includeProof?: boolean }): AsyncIterableIterator<Tx> {
475
+ for (const txHash of await this.txPool.getEligiblePendingTxHashes()) {
476
+ const tx = await this.txPool.getTxByHash(txHash, opts);
485
477
  if (tx) {
486
478
  yield tx;
487
479
  }
@@ -491,68 +483,27 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
491
483
  /**
492
484
  * Returns a transaction in the transaction pool by its hash.
493
485
  * @param txHash - Hash of the transaction to look for in the pool.
486
+ * @param opts - Set `includeProof: false` to skip loading the tx proof from the DB.
494
487
  * @returns A single tx or undefined.
495
488
  */
496
- getTxByHashFromPool(txHash: TxHash): Promise<Tx | undefined> {
497
- return this.txPool.getTxByHash(txHash);
489
+ getTxByHashFromPool(txHash: TxHash, opts?: { includeProof?: boolean }): Promise<Tx | undefined> {
490
+ return this.txPool.getTxByHash(txHash, opts);
498
491
  }
499
492
 
500
493
  /**
501
494
  * Returns transactions in the transaction pool by hash.
502
495
  * @param txHashes - Hashes of the transactions to look for.
496
+ * @param opts - Set `includeProof: false` to skip loading tx proofs from the DB.
503
497
  * @returns The txs found, in the same order as the requested hashes. If a tx is not found, it will be undefined.
504
498
  */
505
- getTxsByHashFromPool(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
506
- return this.txPool.getTxsByHash(txHashes);
499
+ getTxsByHashFromPool(txHashes: TxHash[], opts?: { includeProof?: boolean }): Promise<(Tx | undefined)[]> {
500
+ return this.txPool.getTxsByHash(txHashes, opts);
507
501
  }
508
502
 
509
503
  hasTxsInPool(txHashes: TxHash[]): Promise<boolean[]> {
510
504
  return this.txPool.hasTxs(txHashes);
511
505
  }
512
506
 
513
- /**
514
- * Returns transactions in the transaction pool by hash.
515
- * If a transaction is not in the pool, it will be requested from the network.
516
- * @param txHashes - Hashes of the transactions to look for.
517
- * @returns The txs found, or undefined if not found in the order requested.
518
- */
519
- async getTxsByHash(txHashes: TxHash[], pinnedPeerId: PeerId | undefined): Promise<(Tx | undefined)[]> {
520
- const txs = await Promise.all(txHashes.map(txHash => this.txPool.getTxByHash(txHash)));
521
- const missingTxHashes = txs
522
- .map((tx, index) => [tx, index] as const)
523
- .filter(([tx, _index]) => !tx)
524
- .map(([_tx, index]) => txHashes[index]);
525
-
526
- if (missingTxHashes.length === 0) {
527
- return txs as Tx[];
528
- }
529
-
530
- const missingTxs = await this.requestTxsByHash(missingTxHashes, pinnedPeerId);
531
- // TODO: optimize
532
- // Merge the found txs in order
533
- const mergingTxs = txHashes.map(txHash => {
534
- // Is it in the txs list from the mempool?
535
- for (const tx of txs) {
536
- if (tx !== undefined && tx.getTxHash().equals(txHash)) {
537
- return tx;
538
- }
539
- }
540
-
541
- // Is it in the fetched missing txs?
542
- // Note: this is an O(n^2) operation, but we expect the number of missing txs to be small.
543
- for (const tx of missingTxs) {
544
- if (tx.getTxHash().equals(txHash)) {
545
- return tx;
546
- }
547
- }
548
-
549
- // Otherwise return undefined
550
- return undefined;
551
- });
552
-
553
- return mergingTxs;
554
- }
555
-
556
507
  /**
557
508
  * Returns an archived transaction in the transaction pool by its hash.
558
509
  * @param txHash - Hash of the archived transaction to look for.
@@ -569,23 +520,22 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
569
520
  **/
570
521
  public async sendTx(tx: Tx): Promise<void> {
571
522
  this.#assertIsReady();
572
- const result = await this.txPool.addPendingTxs([tx]);
523
+ const result = await this.txPool.addPendingTxs([tx], { feeComparisonOnly: true });
573
524
  if (result.accepted.length === 1) {
574
525
  await this.p2pService.propagate(tx);
575
- } else {
576
- this.log.warn(
577
- `Tx ${tx.getTxHash()} not propagated: accepted=${result.accepted.length} ignored=${result.ignored.length} rejected=${result.rejected.length}`,
578
- );
526
+ return;
579
527
  }
580
- }
581
528
 
582
- /**
583
- * Adds transactions to the pool. Does not send to peers or validate the txs.
584
- * @param txs - The transactions.
585
- **/
586
- public async addTxsToPool(txs: Tx[]): Promise<number> {
587
- this.#assertIsReady();
588
- return (await this.txPool.addPendingTxs(txs)).accepted.length;
529
+ const txHashStr = tx.getTxHash().toString();
530
+ const reason = result.errors?.get(txHashStr);
531
+ if (reason) {
532
+ this.log.warn(`Tx ${txHashStr} not added to pool: ${reason.message}`);
533
+ throw new TxPoolError(reason);
534
+ }
535
+
536
+ this.log.warn(
537
+ `Tx ${txHashStr} not propagated: accepted=${result.accepted.length} ignored=${result.ignored.length} rejected=${result.rejected.length}`,
538
+ );
589
539
  }
590
540
 
591
541
  /**
@@ -657,13 +607,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
657
607
  */
658
608
  public async getStatus(): Promise<P2PSyncState> {
659
609
  const blockNumber = await this.getSyncedLatestBlockNum();
660
- const blockHash =
661
- blockNumber === 0
662
- ? GENESIS_BLOCK_HEADER_HASH.toString()
663
- : await this.l2BlockSource
664
- .getBlockHeader(blockNumber)
665
- .then(header => header?.hash())
666
- .then(hash => hash?.toString());
610
+ const blockHash = await this.l2BlockSource
611
+ .getBlockData({ number: blockNumber })
612
+ .then(data => data?.header.hash())
613
+ .then(hash => hash?.toString());
667
614
 
668
615
  return {
669
616
  state: this.currentState,
@@ -692,15 +639,20 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
692
639
  return;
693
640
  }
694
641
 
695
- await this.handleMinedBlocks(blocks);
696
- await this.maybeCallPrepareForSlot();
697
- await this.startCollectingMissingTxs(blocks);
698
642
  const lastBlock = blocks.at(-1)!;
699
- await this.synchedLatestSlot.set(BigInt(lastBlock.header.getSlot()));
643
+ const lastSlot = lastBlock.header.getSlot();
644
+
645
+ // Mark txs mined before releasing protections: a block landing at this slot supersedes any
646
+ // protection for txs it includes, so mined-marking must run first to keep just-landed txs from
647
+ // being unprotected into pending where they could be evicted before they are recorded as mined.
648
+ await this.handleMinedBlocks(blocks);
649
+ await this.maybeCallPrepareForSlot(lastSlot);
650
+ await this.collectingMissingTxs(blocks);
651
+ await this.synchedLatestSlot.set(BigInt(lastSlot));
700
652
  }
701
653
 
702
- /** Request txs for unproven blocks so the prover node has more chances to get them. */
703
- private async startCollectingMissingTxs(blocks: L2Block[]): Promise<void> {
654
+ /** Request txs for unproven blocks so the prover node can prove. */
655
+ private async collectingMissingTxs(blocks: L2Block[]): Promise<void> {
704
656
  try {
705
657
  // TODO(#15435): If the archiver has lagged behind L1, the reported proven block number may
706
658
  // be much lower than the actual one, and it does not update until the pending chain is
@@ -708,7 +660,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
708
660
  // are already proven, but the archiver has not yet updated its state. Until this is properly
709
661
  // fixed, it is mitigated by the expiration date of collection requests, which depends on
710
662
  // the slot number of the block.
711
- const provenBlockNumber = await this.l2BlockSource.getProvenBlockNumber();
663
+ const provenBlockNumber = (await this.l2BlockSource.getBlockNumber({ tag: 'proven' })) ?? BlockNumber.ZERO;
712
664
  const unprovenBlocks = blocks.filter(block => block.number > provenBlockNumber);
713
665
  for (const block of unprovenBlocks) {
714
666
  const txHashes = block.body.txEffects.map(txEffect => txEffect.txHash);
@@ -720,7 +672,17 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
720
672
  `Starting collection of ${missingTxHashes.length} missing txs for unproven mined block ${block.number}`,
721
673
  { missingTxHashes, blockNumber: block.number, blockHash: await block.hash().then(h => h.toString()) },
722
674
  );
723
- this.txCollection.startCollecting(block, missingTxHashes);
675
+ // Both `slashDataWithholdingToleranceSlots` and `p2pMissingTxCollectionDeadlineSlots`
676
+ // count *full slots after the block slot* — value N means collection runs until
677
+ // `slotStart(block.slot + N + 1)`. Take the larger of the two so collection never
678
+ // gives up before the data-withholding slash verdict is rendered.
679
+ const blockSlot = block.header.getSlot();
680
+ const toleranceSlots = this.config.slashDataWithholdingToleranceSlots;
681
+ const configuredSlots = this.config.p2pMissingTxCollectionDeadlineSlots ?? 0;
682
+ const deadlineSlot = SlotNumber(blockSlot + Math.max(toleranceSlots, configuredSlots) + 1);
683
+ const deadlineSeconds = getTimestampForSlot(deadlineSlot, this.epochCache.getL1Constants());
684
+ const deadline = new Date(Number(deadlineSeconds) * 1000);
685
+ await this.txCollection.collectFastForBlock(block, missingTxHashes, { deadline });
724
686
  }
725
687
  }
726
688
  } catch (err) {
@@ -733,7 +695,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
733
695
  * @param blocks - A list of finalized L2 blocks.
734
696
  * @returns Empty promise.
735
697
  */
736
- private async handleFinalizedL2Blocks(blocks: L2Block[]): Promise<void> {
698
+ private async handleFinalizedL2Blocks(blocks: BlockData[]): Promise<void> {
737
699
  if (!blocks.length) {
738
700
  return;
739
701
  }
@@ -746,20 +708,48 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
746
708
 
747
709
  /**
748
710
  * Updates the tx pool after a chain prune.
711
+ * Detects epoch prunes (checkpoint number changed) and deletes all txs in that case.
749
712
  * @param latestBlock - The block ID the chain was pruned to.
713
+ * @param newCheckpoint - The checkpoint ID after the prune.
714
+ */
715
+ private async handlePruneL2Blocks(latestBlock: L2BlockId, newCheckpoint: CheckpointId): Promise<void> {
716
+ const deleteAllTxs = this.config.txPoolDeleteTxsAfterReorg && (await this.isEpochPrune(newCheckpoint));
717
+ await this.txPool.handlePrunedBlocks(latestBlock, { deleteAllTxs });
718
+ }
719
+
720
+ /**
721
+ * Returns true if the prune is an epoch prune (new checkpoint number is less than old).
722
+ * If the checkpoint number stays the same or increases, the prune is within a checkpoint.
750
723
  */
751
- private async handlePruneL2Blocks(latestBlock: L2BlockId): Promise<void> {
752
- await this.txPool.handlePrunedBlocks(latestBlock);
724
+ private async isEpochPrune(newCheckpoint: CheckpointId): Promise<boolean> {
725
+ const tips = await this.l2Tips.getL2Tips();
726
+ const oldCheckpointNumber = tips.checkpointed.checkpoint.number;
727
+ if (oldCheckpointNumber <= CheckpointNumber.INITIAL) {
728
+ return false;
729
+ }
730
+ const newCheckpointNumber = newCheckpoint.number;
731
+ // We check that the new checkpoint number is less than the old checkpoint number in order to consider it an epoch prune.
732
+ // To be more certain that it is an epoch prune, we will check that at least 2 checkpoints were removed.
733
+ // This means we should avoid thinking checkpoints removed by L1 re-orgs are epoch prunes
734
+ const thresholdForEpochPrune = CheckpointNumber(oldCheckpointNumber - 2);
735
+ const isEpochPrune = newCheckpointNumber <= thresholdForEpochPrune;
736
+ if (isEpochPrune) {
737
+ this.log.info(`Detected epoch prune to ${newCheckpointNumber}`, {
738
+ oldCheckpointNumber,
739
+ newCheckpointNumber,
740
+ thresholdForEpochPrune,
741
+ });
742
+ }
743
+ return isEpochPrune;
753
744
  }
754
745
 
755
- /** Checks if the slot has changed and calls prepareForSlot if so. */
756
- private async maybeCallPrepareForSlot(): Promise<void> {
757
- const { currentSlot } = this.epochCache.getCurrentAndNextSlot();
758
- if (currentSlot <= this.lastSlotProcessed) {
746
+ /** Calls prepareForSlot for the given slot if it advances past the last slot we prepared for. */
747
+ private async maybeCallPrepareForSlot(slot: SlotNumber): Promise<void> {
748
+ if (slot <= this.lastSlotProcessed) {
759
749
  return;
760
750
  }
761
- this.lastSlotProcessed = currentSlot;
762
- await this.txPool.prepareForSlot(currentSlot);
751
+ this.lastSlotProcessed = slot;
752
+ await this.txPool.prepareForSlot(slot);
763
753
  }
764
754
 
765
755
  private async startServiceIfSynched() {
@@ -799,8 +789,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
799
789
  this.log.debug(`Moved from state ${P2PClientState[oldState]} to ${P2PClientState[this.currentState]}`);
800
790
  }
801
791
 
802
- public validate(txs: Tx[]): Promise<void> {
803
- return this.p2pService.validate(txs);
792
+ public validateTxsReceivedInBlockProposal(txs: Tx[]): Promise<void> {
793
+ return this.p2pService.validateTxsReceivedInBlockProposal(txs);
804
794
  }
805
795
 
806
796
  /**