@aztec/p2p 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5d02921e

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 (423) hide show
  1. package/README.md +129 -3
  2. package/dest/client/factory.d.ts +9 -9
  3. package/dest/client/factory.d.ts.map +1 -1
  4. package/dest/client/factory.js +52 -14
  5. package/dest/client/interface.d.ts +47 -34
  6. package/dest/client/interface.d.ts.map +1 -1
  7. package/dest/client/p2p_client.d.ts +39 -51
  8. package/dest/client/p2p_client.d.ts.map +1 -1
  9. package/dest/client/p2p_client.js +164 -224
  10. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +20 -10
  11. package/dest/config.d.ts +52 -16
  12. package/dest/config.d.ts.map +1 -1
  13. package/dest/config.js +100 -37
  14. package/dest/errors/p2p-service.error.d.ts +9 -0
  15. package/dest/errors/p2p-service.error.d.ts.map +1 -0
  16. package/dest/errors/p2p-service.error.js +10 -0
  17. package/dest/errors/tx-pool.error.d.ts +8 -0
  18. package/dest/errors/tx-pool.error.d.ts.map +1 -0
  19. package/dest/errors/tx-pool.error.js +9 -0
  20. package/dest/index.d.ts +2 -2
  21. package/dest/index.d.ts.map +1 -1
  22. package/dest/index.js +1 -1
  23. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +21 -12
  24. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  25. package/dest/mem_pools/attestation_pool/attestation_pool.js +75 -40
  26. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  27. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  28. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +57 -57
  29. package/dest/mem_pools/attestation_pool/index.d.ts +2 -2
  30. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  31. package/dest/mem_pools/attestation_pool/index.js +1 -1
  32. package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
  33. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  34. package/dest/mem_pools/attestation_pool/mocks.js +2 -2
  35. package/dest/mem_pools/index.d.ts +2 -2
  36. package/dest/mem_pools/index.d.ts.map +1 -1
  37. package/dest/mem_pools/instrumentation.d.ts +4 -2
  38. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  39. package/dest/mem_pools/instrumentation.js +16 -14
  40. package/dest/mem_pools/interface.d.ts +3 -3
  41. package/dest/mem_pools/interface.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
  43. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  44. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
  45. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  46. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  47. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  48. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  49. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  50. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +7 -3
  51. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  52. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  53. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
  54. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
  55. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  56. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
  57. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +54 -5
  58. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  59. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  60. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +7 -5
  61. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +7 -5
  62. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  63. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  64. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +14 -6
  65. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  66. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  67. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +16 -4
  68. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  69. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  70. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +3 -3
  71. package/dest/mem_pools/tx_pool_v2/index.d.ts +3 -2
  72. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  73. package/dest/mem_pools/tx_pool_v2/index.js +2 -1
  74. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  75. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  76. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  77. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +30 -12
  78. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  79. package/dest/mem_pools/tx_pool_v2/interfaces.js +5 -1
  80. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +78 -15
  81. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  82. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +144 -19
  83. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +12 -3
  84. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  85. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +50 -45
  86. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +12 -5
  87. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  88. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +17 -6
  89. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +14 -5
  90. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  91. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +364 -189
  92. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -1
  93. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  94. package/dest/msg_validators/attestation_validator/attestation_validator.js +5 -4
  95. package/dest/msg_validators/clock_tolerance.d.ts +1 -1
  96. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
  97. package/dest/msg_validators/clock_tolerance.js +4 -3
  98. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +6 -4
  99. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  100. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
  101. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +6 -4
  102. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  103. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
  104. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -8
  105. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  106. package/dest/msg_validators/proposal_validator/proposal_validator.js +53 -41
  107. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
  108. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  109. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  110. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  111. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  112. package/dest/msg_validators/tx_validator/allowed_public_setup.js +24 -20
  113. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  114. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  115. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  116. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
  117. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  118. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  119. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
  120. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
  121. package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
  122. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  123. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  124. package/dest/msg_validators/tx_validator/data_validator.js +35 -2
  125. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
  126. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  127. package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
  128. package/dest/msg_validators/tx_validator/factory.d.ts +133 -6
  129. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  130. package/dest/msg_validators/tx_validator/factory.js +247 -60
  131. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  132. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  133. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  134. package/dest/msg_validators/tx_validator/gas_validator.d.ts +67 -3
  135. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  136. package/dest/msg_validators/tx_validator/gas_validator.js +104 -37
  137. package/dest/msg_validators/tx_validator/index.d.ts +3 -1
  138. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  139. package/dest/msg_validators/tx_validator/index.js +2 -0
  140. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  141. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  142. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  143. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  144. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  145. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  146. package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
  147. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  148. package/dest/msg_validators/tx_validator/phases_validator.js +72 -24
  149. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
  150. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  151. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  152. package/dest/services/dummy_service.d.ts +12 -6
  153. package/dest/services/dummy_service.d.ts.map +1 -1
  154. package/dest/services/dummy_service.js +12 -5
  155. package/dest/services/encoding.d.ts +7 -3
  156. package/dest/services/encoding.d.ts.map +1 -1
  157. package/dest/services/encoding.js +18 -11
  158. package/dest/services/gossipsub/topic_score_params.d.ts +18 -6
  159. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
  160. package/dest/services/gossipsub/topic_score_params.js +32 -10
  161. package/dest/services/libp2p/libp2p_service.d.ts +37 -23
  162. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  163. package/dest/services/libp2p/libp2p_service.js +274 -173
  164. package/dest/services/peer-manager/metrics.d.ts +3 -1
  165. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  166. package/dest/services/peer-manager/metrics.js +6 -0
  167. package/dest/services/peer-manager/peer_manager.d.ts +6 -2
  168. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  169. package/dest/services/peer-manager/peer_manager.js +24 -9
  170. package/dest/services/peer-manager/peer_scoring.d.ts +5 -2
  171. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  172. package/dest/services/peer-manager/peer_scoring.js +28 -10
  173. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +12 -8
  174. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  175. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +83 -106
  176. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +4 -7
  177. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  178. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +11 -13
  179. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  180. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +31 -46
  181. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
  182. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  183. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
  184. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
  185. package/dest/services/reqresp/interface.d.ts +10 -1
  186. package/dest/services/reqresp/interface.d.ts.map +1 -1
  187. package/dest/services/reqresp/interface.js +15 -1
  188. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +3 -3
  189. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  190. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +7 -1
  191. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  192. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +15 -0
  193. package/dest/services/reqresp/protocols/tx.d.ts +7 -1
  194. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  195. package/dest/services/reqresp/protocols/tx.js +20 -0
  196. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
  197. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  198. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
  199. package/dest/services/reqresp/reqresp.d.ts +1 -1
  200. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  201. package/dest/services/reqresp/reqresp.js +30 -14
  202. package/dest/services/service.d.ts +26 -4
  203. package/dest/services/service.d.ts.map +1 -1
  204. package/dest/services/tx_collection/config.d.ts +19 -1
  205. package/dest/services/tx_collection/config.d.ts.map +1 -1
  206. package/dest/services/tx_collection/config.js +46 -0
  207. package/dest/services/tx_collection/fast_tx_collection.d.ts +3 -4
  208. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  209. package/dest/services/tx_collection/fast_tx_collection.js +80 -76
  210. package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
  211. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  212. package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
  213. package/dest/services/tx_collection/file_store_tx_source.d.ts +38 -0
  214. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  215. package/dest/services/tx_collection/file_store_tx_source.js +100 -0
  216. package/dest/services/tx_collection/index.d.ts +2 -1
  217. package/dest/services/tx_collection/index.d.ts.map +1 -1
  218. package/dest/services/tx_collection/index.js +1 -0
  219. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  220. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  221. package/dest/services/tx_collection/instrumentation.js +2 -1
  222. package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -7
  223. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  224. package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
  225. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  226. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  227. package/dest/services/tx_collection/request_tracker.js +84 -0
  228. package/dest/services/tx_collection/slow_tx_collection.d.ts +7 -3
  229. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  230. package/dest/services/tx_collection/slow_tx_collection.js +60 -26
  231. package/dest/services/tx_collection/tx_collection.d.ts +23 -13
  232. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  233. package/dest/services/tx_collection/tx_collection.js +75 -3
  234. package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
  235. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  236. package/dest/services/tx_collection/tx_collection_sink.js +26 -29
  237. package/dest/services/tx_collection/tx_source.d.ts +13 -7
  238. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  239. package/dest/services/tx_collection/tx_source.js +26 -7
  240. package/dest/services/tx_file_store/config.d.ts +1 -3
  241. package/dest/services/tx_file_store/config.d.ts.map +1 -1
  242. package/dest/services/tx_file_store/config.js +0 -4
  243. package/dest/services/tx_file_store/tx_file_store.d.ts +4 -3
  244. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  245. package/dest/services/tx_file_store/tx_file_store.js +9 -6
  246. package/dest/services/tx_provider.d.ts +4 -4
  247. package/dest/services/tx_provider.d.ts.map +1 -1
  248. package/dest/services/tx_provider.js +9 -8
  249. package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
  250. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  251. package/dest/test-helpers/make-test-p2p-clients.js +1 -2
  252. package/dest/test-helpers/mock-pubsub.d.ts +30 -4
  253. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  254. package/dest/test-helpers/mock-pubsub.js +105 -4
  255. package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
  256. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  257. package/dest/test-helpers/reqresp-nodes.js +2 -2
  258. package/dest/test-helpers/testbench-utils.d.ts +35 -24
  259. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  260. package/dest/test-helpers/testbench-utils.js +115 -38
  261. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  262. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  263. package/dest/testbench/p2p_client_testbench_worker.js +57 -27
  264. package/dest/testbench/worker_client_manager.d.ts +3 -1
  265. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  266. package/dest/testbench/worker_client_manager.js +6 -3
  267. package/dest/util.d.ts +3 -3
  268. package/dest/util.d.ts.map +1 -1
  269. package/package.json +14 -14
  270. package/src/client/factory.ts +102 -25
  271. package/src/client/interface.ts +52 -34
  272. package/src/client/p2p_client.ts +190 -266
  273. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +33 -14
  274. package/src/config.ts +149 -43
  275. package/src/errors/p2p-service.error.ts +11 -0
  276. package/src/errors/tx-pool.error.ts +12 -0
  277. package/src/index.ts +1 -1
  278. package/src/mem_pools/attestation_pool/attestation_pool.ts +104 -50
  279. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +61 -57
  280. package/src/mem_pools/attestation_pool/index.ts +3 -3
  281. package/src/mem_pools/attestation_pool/mocks.ts +2 -1
  282. package/src/mem_pools/index.ts +1 -1
  283. package/src/mem_pools/instrumentation.ts +17 -13
  284. package/src/mem_pools/interface.ts +2 -2
  285. package/src/mem_pools/tx_pool_v2/README.md +85 -11
  286. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
  287. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  288. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +7 -3
  289. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
  290. package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
  291. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +59 -4
  292. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
  293. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
  294. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -9
  295. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +33 -6
  296. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +4 -3
  297. package/src/mem_pools/tx_pool_v2/index.ts +2 -1
  298. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  299. package/src/mem_pools/tx_pool_v2/interfaces.ts +32 -12
  300. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +209 -27
  301. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +58 -45
  302. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +34 -8
  303. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +410 -187
  304. package/src/msg_validators/attestation_validator/README.md +49 -0
  305. package/src/msg_validators/attestation_validator/attestation_validator.ts +5 -4
  306. package/src/msg_validators/clock_tolerance.ts +4 -3
  307. package/src/msg_validators/proposal_validator/README.md +123 -0
  308. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +14 -4
  309. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +20 -7
  310. package/src/msg_validators/proposal_validator/proposal_validator.ts +69 -45
  311. package/src/msg_validators/tx_validator/README.md +119 -0
  312. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
  313. package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
  314. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  315. package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
  316. package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
  317. package/src/msg_validators/tx_validator/data_validator.ts +42 -1
  318. package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
  319. package/src/msg_validators/tx_validator/factory.ts +394 -78
  320. package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
  321. package/src/msg_validators/tx_validator/gas_validator.ts +123 -27
  322. package/src/msg_validators/tx_validator/index.ts +2 -0
  323. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  324. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  325. package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
  326. package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
  327. package/src/services/dummy_service.ts +18 -7
  328. package/src/services/encoding.ts +18 -10
  329. package/src/services/gossipsub/README.md +29 -14
  330. package/src/services/gossipsub/topic_score_params.ts +49 -13
  331. package/src/services/libp2p/libp2p_service.ts +288 -198
  332. package/src/services/peer-manager/metrics.ts +7 -0
  333. package/src/services/peer-manager/peer_manager.ts +28 -9
  334. package/src/services/peer-manager/peer_scoring.ts +21 -5
  335. package/src/services/reqresp/README.md +229 -0
  336. package/src/services/reqresp/batch-tx-requester/README.md +46 -7
  337. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +79 -112
  338. package/src/services/reqresp/batch-tx-requester/interface.ts +3 -6
  339. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +30 -71
  340. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
  341. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
  342. package/src/services/reqresp/interface.ts +26 -1
  343. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +2 -2
  344. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +17 -0
  345. package/src/services/reqresp/protocols/tx.ts +22 -0
  346. package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
  347. package/src/services/reqresp/reqresp.ts +35 -15
  348. package/src/services/service.ts +37 -3
  349. package/src/services/tx_collection/config.ts +68 -0
  350. package/src/services/tx_collection/fast_tx_collection.ts +83 -76
  351. package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
  352. package/src/services/tx_collection/file_store_tx_source.ts +129 -0
  353. package/src/services/tx_collection/index.ts +1 -0
  354. package/src/services/tx_collection/instrumentation.ts +7 -1
  355. package/src/services/tx_collection/proposal_tx_collector.ts +9 -13
  356. package/src/services/tx_collection/request_tracker.ts +127 -0
  357. package/src/services/tx_collection/slow_tx_collection.ts +66 -33
  358. package/src/services/tx_collection/tx_collection.ts +114 -19
  359. package/src/services/tx_collection/tx_collection_sink.ts +30 -34
  360. package/src/services/tx_collection/tx_source.ts +28 -8
  361. package/src/services/tx_file_store/config.ts +0 -6
  362. package/src/services/tx_file_store/tx_file_store.ts +10 -8
  363. package/src/services/tx_provider.ts +10 -9
  364. package/src/test-helpers/make-test-p2p-clients.ts +4 -6
  365. package/src/test-helpers/mock-pubsub.ts +146 -9
  366. package/src/test-helpers/reqresp-nodes.ts +3 -6
  367. package/src/test-helpers/testbench-utils.ts +137 -43
  368. package/src/testbench/p2p_client_testbench_worker.ts +63 -30
  369. package/src/testbench/worker_client_manager.ts +13 -6
  370. package/src/util.ts +8 -2
  371. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
  372. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
  373. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
  374. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
  375. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
  376. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
  377. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
  378. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
  379. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
  380. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
  381. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
  382. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
  383. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
  384. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
  385. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
  386. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
  387. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
  388. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
  389. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
  390. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
  391. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
  392. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
  393. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
  394. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
  395. package/dest/mem_pools/tx_pool/index.d.ts +0 -3
  396. package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
  397. package/dest/mem_pools/tx_pool/index.js +0 -2
  398. package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
  399. package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
  400. package/dest/mem_pools/tx_pool/priority.js +0 -15
  401. package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
  402. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
  403. package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
  404. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
  405. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
  406. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
  407. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
  408. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  409. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
  410. package/src/mem_pools/tx_pool/README.md +0 -270
  411. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
  412. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
  413. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
  414. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
  415. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
  416. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
  417. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
  418. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
  419. package/src/mem_pools/tx_pool/index.ts +0 -2
  420. package/src/mem_pools/tx_pool/priority.ts +0 -20
  421. package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
  422. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
  423. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
@@ -1,4 +1,10 @@
1
- import { AVM_MAX_PROCESSABLE_L2_GAS, FIXED_DA_GAS, FIXED_L2_GAS } from '@aztec/constants';
1
+ import {
2
+ MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT,
3
+ MAX_PROCESSABLE_L2_GAS,
4
+ PRIVATE_TX_L2_GAS_OVERHEAD,
5
+ PUBLIC_TX_L2_GAS_OVERHEAD,
6
+ TX_DA_GAS_OVERHEAD,
7
+ } from '@aztec/constants';
2
8
  import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
3
9
  import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
4
10
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -16,26 +22,138 @@ import {
16
22
 
17
23
  import { getFeePayerClaimAmount, getTxFeeLimit } from './fee_payer_balance.js';
18
24
 
25
+ /** Structural interface for types that carry gas limit data, used by {@link GasLimitsValidator}. */
26
+ export interface HasGasLimitData {
27
+ txHash: { toString(): string };
28
+ data: {
29
+ // We just need to know whether there is something here or not
30
+ forPublic?: unknown;
31
+ constants: {
32
+ txContext: {
33
+ gasSettings: { gasLimits: Gas };
34
+ };
35
+ };
36
+ };
37
+ }
38
+
39
+ /**
40
+ * Validates that a transaction's gas limits are within acceptable bounds.
41
+ *
42
+ * Rejects transactions whose gas limits fall below the fixed minimums (FIXED_DA_GAS,
43
+ * FIXED_L2_GAS) or exceed the AVM's maximum processable L2 gas. This is a cheap,
44
+ * stateless check that operates on gas settings alone.
45
+ *
46
+ * Generic over T so it can validate both full {@link Tx} objects and {@link TxMetaData}
47
+ * (used during pending pool migration).
48
+ *
49
+ * Used by: pending pool migration (via factory), and indirectly by {@link GasTxValidator}.
50
+ */
51
+ export class GasLimitsValidator<T extends HasGasLimitData> implements TxValidator<T> {
52
+ #log: Logger;
53
+ #effectiveMaxL2Gas: number;
54
+ #effectiveMaxDAGas: number;
55
+ #rollupManaLimit: number;
56
+ #maxBlockL2Gas: number;
57
+ #maxBlockDAGas: number;
58
+
59
+ constructor(opts?: {
60
+ rollupManaLimit?: number;
61
+ maxBlockL2Gas?: number;
62
+ maxBlockDAGas?: number;
63
+ bindings?: LoggerBindings;
64
+ }) {
65
+ this.#log = createLogger('sequencer:tx_validator:tx_gas', opts?.bindings);
66
+ this.#rollupManaLimit = opts?.rollupManaLimit ?? Infinity;
67
+ this.#maxBlockL2Gas = opts?.maxBlockL2Gas ?? Infinity;
68
+ this.#maxBlockDAGas = opts?.maxBlockDAGas ?? Infinity;
69
+ this.#effectiveMaxL2Gas = Math.min(MAX_PROCESSABLE_L2_GAS, this.#rollupManaLimit, this.#maxBlockL2Gas);
70
+ this.#effectiveMaxDAGas = Math.min(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, this.#maxBlockDAGas);
71
+ }
72
+
73
+ validateTx(tx: T): Promise<TxValidationResult> {
74
+ return Promise.resolve(this.validateGasLimit(tx));
75
+ }
76
+
77
+ /** Checks gas limits are >= fixed minimums and <= effective max gas (L2 and DA). */
78
+ validateGasLimit(tx: T): TxValidationResult {
79
+ const gasLimits = tx.data.constants.txContext.gasSettings.gasLimits;
80
+ const minGasLimits = new Gas(
81
+ TX_DA_GAS_OVERHEAD,
82
+ tx.data.forPublic ? PUBLIC_TX_L2_GAS_OVERHEAD : PRIVATE_TX_L2_GAS_OVERHEAD,
83
+ );
84
+
85
+ if (minGasLimits.gtAny(gasLimits)) {
86
+ this.#log.verbose(`Rejecting transaction due to the gas limit(s) not being above the minimum gas limit`, {
87
+ gasLimits,
88
+ minGasLimits,
89
+ });
90
+ return { result: 'invalid', reason: [TX_ERROR_INSUFFICIENT_GAS_LIMIT] };
91
+ }
92
+
93
+ if (gasLimits.l2Gas > this.#effectiveMaxL2Gas) {
94
+ this.#log.verbose(`Rejecting transaction due to the L2 gas limit being higher than the effective maximum`, {
95
+ gasLimits,
96
+ effectiveMaxL2Gas: this.#effectiveMaxL2Gas,
97
+ rollupManaLimit: this.#rollupManaLimit,
98
+ maxBlockL2Gas: this.#maxBlockL2Gas,
99
+ });
100
+ return { result: 'invalid', reason: [TX_ERROR_GAS_LIMIT_TOO_HIGH] };
101
+ }
102
+
103
+ if (gasLimits.daGas > this.#effectiveMaxDAGas) {
104
+ this.#log.verbose(`Rejecting transaction due to the DA gas limit being higher than the effective maximum`, {
105
+ gasLimits,
106
+ effectiveMaxDAGas: this.#effectiveMaxDAGas,
107
+ maxBlockDAGas: this.#maxBlockDAGas,
108
+ });
109
+ return { result: 'invalid', reason: [TX_ERROR_GAS_LIMIT_TOO_HIGH] };
110
+ }
111
+
112
+ return { result: 'valid' };
113
+ }
114
+ }
115
+
116
+ /**
117
+ * Validates that a transaction can pay its gas fees.
118
+ *
119
+ * Runs three checks in order:
120
+ * 1. **Gas limits** (delegates to {@link GasLimitsValidator}) — rejects if limits are
121
+ * out of bounds.
122
+ * 2. **Max fee per gas** — skips (not rejects) the tx if its maxFeesPerGas is below
123
+ * the current block's gas fees. We skip rather than reject because the tx may
124
+ * become eligible in a later block with lower fees.
125
+ * 3. **Fee payer balance** — reads the fee payer's FeeJuice balance from public state,
126
+ * adds any pending claim from a setup-phase `_increase_public_balance` call, and
127
+ * rejects if the total is less than the tx's fee limit (gasLimits * maxFeePerGas).
128
+ *
129
+ * Used by: gossip (stage 1), RPC, and block building validators.
130
+ */
19
131
  export class GasTxValidator implements TxValidator<Tx> {
20
132
  #log: Logger;
21
133
  #publicDataSource: PublicStateSource;
22
134
  #feeJuiceAddress: AztecAddress;
23
135
  #gasFees: GasFees;
136
+ #gasLimitOpts?: { rollupManaLimit?: number; maxBlockL2Gas?: number; maxBlockDAGas?: number };
24
137
 
25
138
  constructor(
26
139
  publicDataSource: PublicStateSource,
27
140
  feeJuiceAddress: AztecAddress,
28
141
  gasFees: GasFees,
29
- bindings?: LoggerBindings,
142
+ private bindings?: LoggerBindings,
143
+ opts?: { rollupManaLimit?: number; maxBlockL2Gas?: number; maxBlockDAGas?: number },
30
144
  ) {
31
145
  this.#log = createLogger('sequencer:tx_validator:tx_gas', bindings);
32
146
  this.#publicDataSource = publicDataSource;
33
147
  this.#feeJuiceAddress = feeJuiceAddress;
34
148
  this.#gasFees = gasFees;
149
+ this.#gasLimitOpts = opts;
35
150
  }
36
151
 
37
152
  async validateTx(tx: Tx): Promise<TxValidationResult> {
38
- const gasLimitValidation = this.#validateGasLimit(tx);
153
+ const gasLimitValidation = new GasLimitsValidator({
154
+ ...this.#gasLimitOpts,
155
+ bindings: this.bindings,
156
+ }).validateGasLimit(tx);
39
157
  if (gasLimitValidation.result === 'invalid') {
40
158
  return Promise.resolve(gasLimitValidation);
41
159
  }
@@ -69,31 +187,9 @@ export class GasTxValidator implements TxValidator<Tx> {
69
187
  }
70
188
 
71
189
  /**
72
- * Check whether the tx's gas limit is above the minimum amount.
190
+ * Checks the fee payer has enough FeeJuice balance to cover the tx's fee limit.
191
+ * Accounts for any pending claim from a setup-phase `_increase_public_balance` call.
73
192
  */
74
- #validateGasLimit(tx: Tx): TxValidationResult {
75
- const gasLimits = tx.data.constants.txContext.gasSettings.gasLimits;
76
- const minGasLimits = new Gas(FIXED_DA_GAS, FIXED_L2_GAS);
77
-
78
- if (minGasLimits.gtAny(gasLimits)) {
79
- this.#log.verbose(`Rejecting transaction due to the gas limit(s) not being above the minimum gas limit`, {
80
- gasLimits,
81
- minGasLimits,
82
- });
83
- return { result: 'invalid', reason: [TX_ERROR_INSUFFICIENT_GAS_LIMIT] };
84
- }
85
-
86
- if (gasLimits.l2Gas > AVM_MAX_PROCESSABLE_L2_GAS) {
87
- this.#log.verbose(`Rejecting transaction due to the gas limit(s) being higher than the maximum processable gas`, {
88
- gasLimits,
89
- minGasLimits,
90
- });
91
- return { result: 'invalid', reason: [TX_ERROR_GAS_LIMIT_TOO_HIGH] };
92
- }
93
-
94
- return { result: 'valid' };
95
- }
96
-
97
193
  public async validateTxFee(tx: Tx): Promise<TxValidationResult> {
98
194
  const feePayer = tx.data.feePayer;
99
195
 
@@ -8,7 +8,9 @@ export * from './gas_validator.js';
8
8
  export * from './phases_validator.js';
9
9
  export * from './test_utils.js';
10
10
  export * from './allowed_public_setup.js';
11
+ export * from './allowed_setup_helpers.js';
11
12
  export * from './archive_cache.js';
12
13
  export * from './tx_permitted_validator.js';
13
14
  export * from './timestamp_validator.js';
14
15
  export * from './size_validator.js';
16
+ export * from './factory.js';
@@ -28,16 +28,24 @@ export class MetadataTxValidator<T extends AnyTx> implements TxValidator<T> {
28
28
  validateTx(tx: T): Promise<TxValidationResult> {
29
29
  const errors = [];
30
30
  if (!this.#hasCorrectL1ChainId(tx)) {
31
- errors.push(TX_ERROR_INCORRECT_L1_CHAIN_ID);
31
+ errors.push(
32
+ `${TX_ERROR_INCORRECT_L1_CHAIN_ID} (tx: ${tx.data.constants.txContext.chainId.toNumber()}, expected: ${this.values.l1ChainId.toNumber()})`,
33
+ );
32
34
  }
33
35
  if (!this.#hasCorrectRollupVersion(tx)) {
34
- errors.push(TX_ERROR_INCORRECT_ROLLUP_VERSION);
36
+ errors.push(
37
+ `${TX_ERROR_INCORRECT_ROLLUP_VERSION} (tx: ${tx.data.constants.txContext.version.toNumber()}, expected: ${this.values.rollupVersion.toNumber()})`,
38
+ );
35
39
  }
36
40
  if (!this.#hasCorrectVkTreeRoot(tx)) {
37
- errors.push(TX_ERROR_INCORRECT_VK_TREE_ROOT);
41
+ errors.push(
42
+ `${TX_ERROR_INCORRECT_VK_TREE_ROOT} (tx: ${tx.data.constants.vkTreeRoot.toString()}, expected: ${this.values.vkTreeRoot.toString()})`,
43
+ );
38
44
  }
39
45
  if (!this.#hasCorrectprotocolContractsHash(tx)) {
40
- errors.push(TX_ERROR_INCORRECT_PROTOCOL_CONTRACTS_HASH);
46
+ errors.push(
47
+ `${TX_ERROR_INCORRECT_PROTOCOL_CONTRACTS_HASH} (tx: ${tx.data.constants.protocolContractsHash.toString()}, expected: ${this.values.protocolContractsHash.toString()})`,
48
+ );
41
49
  }
42
50
  return Promise.resolve(errors.length > 0 ? { result: 'invalid', reason: errors } : { result: 'valid' });
43
51
  }
@@ -0,0 +1,30 @@
1
+ import type { NullifierSource } from '@aztec/p2p';
2
+ import type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
3
+ import { MerkleTreeId } from '@aztec/stdlib/trees';
4
+
5
+ /**
6
+ * Implements a nullifier source by checking a DB and an in-memory collection.
7
+ * Intended for validating transactions as they are added to a block.
8
+ */
9
+ export class NullifierCache implements NullifierSource {
10
+ nullifiers: Set<string>;
11
+
12
+ constructor(private db: MerkleTreeReadOperations) {
13
+ this.nullifiers = new Set();
14
+ }
15
+
16
+ public async nullifiersExist(nullifiers: Buffer[]): Promise<boolean[]> {
17
+ const cacheResults = nullifiers.map(n => this.nullifiers.has(n.toString()));
18
+ const toCheckDb = nullifiers.filter((_n, index) => !cacheResults[index]);
19
+ const dbHits = await this.db.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, toCheckDb);
20
+
21
+ let dbIndex = 0;
22
+ return nullifiers.map((_n, index) => cacheResults[index] || dbHits[dbIndex++] !== undefined);
23
+ }
24
+
25
+ public addNullifiers(nullifiers: Buffer[]) {
26
+ for (const nullifier of nullifiers) {
27
+ this.nullifiers.add(nullifier.toString());
28
+ }
29
+ }
30
+ }
@@ -1,11 +1,17 @@
1
+ import { NULL_MSG_SENDER_CONTRACT_ADDRESS } from '@aztec/constants';
1
2
  import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
2
3
  import { PublicContractsDB, getCallRequestsWithCalldataByPhase } from '@aztec/simulator/server';
4
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
3
5
  import type { ContractDataSource } from '@aztec/stdlib/contract';
4
6
  import type { AllowedElement } from '@aztec/stdlib/interfaces/server';
5
7
  import {
6
8
  type PublicCallRequestWithCalldata,
7
9
  TX_ERROR_DURING_VALIDATION,
8
10
  TX_ERROR_SETUP_FUNCTION_NOT_ALLOWED,
11
+ TX_ERROR_SETUP_FUNCTION_UNKNOWN_CONTRACT,
12
+ TX_ERROR_SETUP_NULL_MSG_SENDER,
13
+ TX_ERROR_SETUP_ONLY_SELF_WRONG_SENDER,
14
+ TX_ERROR_SETUP_WRONG_CALLDATA_LENGTH,
9
15
  Tx,
10
16
  TxExecutionPhase,
11
17
  type TxValidationResult,
@@ -34,7 +40,7 @@ export class PhasesTxValidator implements TxValidator<Tx> {
34
40
  // which are needed for public FPC flows, but fail if the account contract hasnt been deployed yet,
35
41
  // which is what we're trying to do as part of the current txs.
36
42
  // We only need to create/revert checkpoint here because of this addNewContracts call.
37
- await this.contractsDB.addNewContracts(tx);
43
+ this.contractsDB.addNewContracts(tx);
38
44
 
39
45
  if (!tx.data.forPublic) {
40
46
  this.#log.debug(
@@ -45,7 +51,8 @@ export class PhasesTxValidator implements TxValidator<Tx> {
45
51
 
46
52
  const setupFns = getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.SETUP);
47
53
  for (const setupFn of setupFns) {
48
- if (!(await this.isOnAllowList(setupFn, this.setupAllowList))) {
54
+ const rejectionReason = await this.checkAllowList(setupFn, this.setupAllowList);
55
+ if (rejectionReason) {
49
56
  this.#log.verbose(
50
57
  `Rejecting tx ${tx.getTxHash().toString()} because it calls setup function not on allow list: ${
51
58
  setupFn.request.contractAddress
@@ -53,7 +60,7 @@ export class PhasesTxValidator implements TxValidator<Tx> {
53
60
  { allowList: this.setupAllowList },
54
61
  );
55
62
 
56
- return { result: 'invalid', reason: [TX_ERROR_SETUP_FUNCTION_NOT_ALLOWED] };
63
+ return { result: 'invalid', reason: [rejectionReason] };
57
64
  }
58
65
  }
59
66
 
@@ -66,53 +73,101 @@ export class PhasesTxValidator implements TxValidator<Tx> {
66
73
  }
67
74
  }
68
75
 
69
- private async isOnAllowList(
76
+ /** Returns a rejection reason if the call is not on the allow list, or undefined if it is allowed. */
77
+ private async checkAllowList(
70
78
  publicCall: PublicCallRequestWithCalldata,
71
79
  allowList: AllowedElement[],
72
- ): Promise<boolean> {
80
+ ): Promise<string | undefined> {
73
81
  if (publicCall.isEmpty()) {
74
- return true;
82
+ return undefined;
75
83
  }
76
84
 
77
85
  const contractAddress = publicCall.request.contractAddress;
78
86
  const functionSelector = publicCall.functionSelector;
79
87
 
80
- // do these checks first since they don't require the contract class
88
+ // Check address-based entries first since they don't require the contract class.
81
89
  for (const entry of allowList) {
82
- if ('address' in entry && !('selector' in entry)) {
83
- if (contractAddress.equals(entry.address)) {
84
- return true;
85
- }
86
- }
87
-
88
- if ('address' in entry && 'selector' in entry) {
90
+ if ('address' in entry) {
89
91
  if (contractAddress.equals(entry.address) && entry.selector.equals(functionSelector)) {
90
- return true;
92
+ if (entry.calldataLength !== undefined && publicCall.calldata.length !== entry.calldataLength) {
93
+ return TX_ERROR_SETUP_WRONG_CALLDATA_LENGTH;
94
+ }
95
+ if (entry.onlySelf && !publicCall.request.msgSender.equals(contractAddress)) {
96
+ return TX_ERROR_SETUP_ONLY_SELF_WRONG_SENDER;
97
+ }
98
+ if (
99
+ entry.rejectNullMsgSender &&
100
+ publicCall.request.msgSender.equals(AztecAddress.fromBigInt(NULL_MSG_SENDER_CONTRACT_ADDRESS))
101
+ ) {
102
+ return TX_ERROR_SETUP_NULL_MSG_SENDER;
103
+ }
104
+ return undefined;
91
105
  }
92
106
  }
107
+ }
93
108
 
94
- const contractClass = await this.contractsDB.getContractInstance(contractAddress, this.timestamp);
95
-
96
- if (!contractClass) {
97
- throw new Error(`Contract not found: ${contractAddress}`);
109
+ // Check class-based entries. Fetch the contract instance lazily (only once).
110
+ let contractClassId: undefined | { value: string | undefined };
111
+ for (const entry of allowList) {
112
+ if (!('classId' in entry)) {
113
+ continue;
98
114
  }
99
115
 
100
- if ('classId' in entry && !('selector' in entry)) {
101
- if (contractClass.currentContractClassId.equals(entry.classId)) {
102
- return true;
116
+ if (contractClassId === undefined) {
117
+ const instance = await this.contractsDB.getContractInstance(contractAddress, this.timestamp);
118
+ contractClassId = { value: instance?.currentContractClassId.toString() };
119
+ if (!contractClassId.value) {
120
+ return TX_ERROR_SETUP_FUNCTION_UNKNOWN_CONTRACT;
103
121
  }
104
122
  }
105
123
 
106
- if ('classId' in entry && 'selector' in entry) {
124
+ if (contractClassId.value === entry.classId.toString() && entry.selector.equals(functionSelector)) {
125
+ if (entry.calldataLength !== undefined && publicCall.calldata.length !== entry.calldataLength) {
126
+ return TX_ERROR_SETUP_WRONG_CALLDATA_LENGTH;
127
+ }
128
+ if (entry.onlySelf && !publicCall.request.msgSender.equals(contractAddress)) {
129
+ return TX_ERROR_SETUP_ONLY_SELF_WRONG_SENDER;
130
+ }
107
131
  if (
108
- contractClass.currentContractClassId.equals(entry.classId) &&
109
- (entry.selector === undefined || entry.selector.equals(functionSelector))
132
+ entry.rejectNullMsgSender &&
133
+ publicCall.request.msgSender.equals(AztecAddress.fromBigInt(NULL_MSG_SENDER_CONTRACT_ADDRESS))
110
134
  ) {
111
- return true;
135
+ return TX_ERROR_SETUP_NULL_MSG_SENDER;
112
136
  }
137
+ return undefined;
113
138
  }
114
139
  }
115
140
 
116
- return false;
141
+ return TX_ERROR_SETUP_FUNCTION_NOT_ALLOWED;
142
+ }
143
+ }
144
+
145
+ /** Structural interface for the allowed-setup-calls flag check. */
146
+ export interface HasAllowedSetupCallsData {
147
+ txHash: { toString(): string };
148
+ allowedSetupCalls: boolean;
149
+ }
150
+
151
+ /**
152
+ * Validates that a transaction's setup-phase calls were allowed at receipt time.
153
+ *
154
+ * Checks the precomputed `allowedSetupCalls` flag on TxMetaData. The flag is
155
+ * computed by running the PhasesTxValidator on the full Tx when it first enters
156
+ * the pool. This lightweight validator is used during pending pool migration to
157
+ * reject txs whose setup calls are not on the allow list.
158
+ */
159
+ export class AllowedSetupCallsMetaValidator<T extends HasAllowedSetupCallsData> implements TxValidator<T> {
160
+ #log: Logger;
161
+
162
+ constructor(bindings?: LoggerBindings) {
163
+ this.#log = createLogger('sequencer:tx_validator:tx_phases_meta', bindings);
164
+ }
165
+
166
+ validateTx(tx: T): Promise<TxValidationResult> {
167
+ if (!tx.allowedSetupCalls) {
168
+ this.#log.verbose(`Rejecting tx ${tx.txHash} because its setup calls are not on the allow list`);
169
+ return Promise.resolve({ result: 'invalid', reason: [TX_ERROR_SETUP_FUNCTION_NOT_ALLOWED] });
170
+ }
171
+ return Promise.resolve({ result: 'valid' });
117
172
  }
118
173
  }
@@ -1,15 +1,24 @@
1
- import { BlockNumber } from '@aztec/foundation/branded-types';
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
3
- import {
4
- type AnyTx,
5
- TX_ERROR_INVALID_INCLUDE_BY_TIMESTAMP,
6
- type TxValidationResult,
7
- type TxValidator,
8
- getTxHash,
9
- } from '@aztec/stdlib/tx';
3
+ import { TX_ERROR_INVALID_EXPIRATION_TIMESTAMP, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
10
4
  import type { UInt64 } from '@aztec/stdlib/types';
11
5
 
12
- export class TimestampTxValidator<T extends AnyTx> implements TxValidator<T> {
6
+ /** Structural interface for timestamp validation. */
7
+ export interface HasTimestampData {
8
+ txHash: { toString(): string };
9
+ data: {
10
+ expirationTimestamp: bigint;
11
+ constants: {
12
+ anchorBlockHeader: {
13
+ globalVariables: {
14
+ blockNumber: BlockNumber;
15
+ };
16
+ };
17
+ };
18
+ };
19
+ }
20
+
21
+ export class TimestampTxValidator<T extends HasTimestampData> implements TxValidator<T> {
13
22
  #log: Logger;
14
23
 
15
24
  constructor(
@@ -26,25 +35,21 @@ export class TimestampTxValidator<T extends AnyTx> implements TxValidator<T> {
26
35
  }
27
36
 
28
37
  validateTx(tx: T): Promise<TxValidationResult> {
29
- const includeByTimestamp = tx.data.includeByTimestamp;
30
- // If building block 1, we skip the expiration check. For details on why see the `validate_include_by_timestamp`
38
+ const expirationTimestamp = tx.data.expirationTimestamp;
39
+ // If building block 1, we skip the expiration check. For details on why see the `validate_expiration_timestamp`
31
40
  // function in `noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/components/validation_requests.nr`.
32
41
  const buildingBlock1 = this.values.blockNumber === 1;
33
42
 
34
- if (!buildingBlock1 && includeByTimestamp < this.values.timestamp) {
43
+ if (!buildingBlock1 && expirationTimestamp < this.values.timestamp) {
35
44
  if (tx.data.constants.anchorBlockHeader.globalVariables.blockNumber === 0) {
36
45
  this.#log.warn(
37
46
  `A tx built against a genesis block failed to be included in block 1 which is the only block in which txs built against a genesis block are allowed to be included.`,
38
47
  );
39
48
  }
40
49
  this.#log.verbose(
41
- `Rejecting tx ${getTxHash(
42
- tx,
43
- )} for low expiration timestamp. Tx expiration timestamp: ${includeByTimestamp}, timestamp: ${
44
- this.values.timestamp
45
- }.`,
50
+ `Rejecting tx ${tx.txHash} for low expiration timestamp. Tx expiration timestamp: ${expirationTimestamp}, timestamp: ${this.values.timestamp}.`,
46
51
  );
47
- return Promise.resolve({ result: 'invalid', reason: [TX_ERROR_INVALID_INCLUDE_BY_TIMESTAMP] });
52
+ return Promise.resolve({ result: 'invalid', reason: [TX_ERROR_INVALID_EXPIRATION_TIMESTAMP] });
48
53
  } else {
49
54
  return Promise.resolve({ result: 'valid' });
50
55
  }
@@ -1,6 +1,6 @@
1
1
  import type { EthAddress } from '@aztec/foundation/eth-address';
2
2
  import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
3
- import type { Gossipable, PeerErrorSeverity } from '@aztec/stdlib/p2p';
3
+ import type { CheckpointProposalCore, Gossipable, PeerErrorSeverity, TopicType } from '@aztec/stdlib/p2p';
4
4
  import { Tx, TxHash } from '@aztec/stdlib/tx';
5
5
 
6
6
  import type { PeerId } from '@libp2p/interface';
@@ -26,6 +26,7 @@ import { ReqRespStatus } from './reqresp/status.js';
26
26
  import {
27
27
  type P2PBlockReceivedCallback,
28
28
  type P2PCheckpointReceivedCallback,
29
+ type P2PDuplicateAttestationCallback,
29
30
  type P2PDuplicateProposalCallback,
30
31
  type P2PService,
31
32
  type PeerDiscoveryService,
@@ -43,6 +44,10 @@ export class DummyP2PService implements P2PService {
43
44
  return [];
44
45
  }
45
46
 
47
+ getGossipMeshPeerCount(_topicType: TopicType): number {
48
+ return 0;
49
+ }
50
+
46
51
  /**
47
52
  * Starts the dummy implementation.
48
53
  * @returns A resolved promise.
@@ -81,13 +86,23 @@ export class DummyP2PService implements P2PService {
81
86
  /**
82
87
  * Register a callback into the validator client for when a checkpoint proposal is received
83
88
  */
84
- public registerCheckpointReceivedCallback(_callback: P2PCheckpointReceivedCallback) {}
89
+ public registerValidatorCheckpointReceivedCallback(_callback: P2PCheckpointReceivedCallback) {}
90
+ public registerAllNodesCheckpointReceivedCallback(_callback: P2PCheckpointReceivedCallback) {}
91
+
92
+ public notifyOwnCheckpointProposal(_checkpoint: CheckpointProposalCore): Promise<void> {
93
+ return Promise.resolve();
94
+ }
85
95
 
86
96
  /**
87
97
  * Register a callback for when a duplicate proposal is detected
88
98
  */
89
99
  public registerDuplicateProposalCallback(_callback: P2PDuplicateProposalCallback): void {}
90
100
 
101
+ /**
102
+ * Register a callback for when a duplicate attestation is detected
103
+ */
104
+ public registerDuplicateAttestationCallback(_callback: P2PDuplicateAttestationCallback): void {}
105
+
91
106
  /**
92
107
  * Sends a request to a peer.
93
108
  * @param _protocol - The protocol to send the request on.
@@ -131,14 +146,10 @@ export class DummyP2PService implements P2PService {
131
146
  return undefined;
132
147
  }
133
148
 
134
- validate(_txs: Tx[]): Promise<void> {
149
+ validateTxsReceivedInBlockProposal(_txs: Tx[]): Promise<void> {
135
150
  return Promise.resolve();
136
151
  }
137
152
 
138
- validatePropagatedTx(_tx: Tx, _peerId: PeerId): Promise<boolean> {
139
- return Promise.resolve(true);
140
- }
141
-
142
153
  addReqRespSubProtocol(
143
154
  _subProtocol: ReqRespSubProtocol,
144
155
  _handler: ReqRespSubProtocolHandler,
@@ -1,14 +1,22 @@
1
1
  // Taken from lodestar: https://github.com/ChainSafe/lodestar
2
- import { sha256 } from '@aztec/foundation/crypto/sha256';
3
2
  import { createLogger } from '@aztec/foundation/log';
4
3
  import { MAX_TX_SIZE_KB, TopicType, getTopicFromString } from '@aztec/stdlib/p2p';
5
4
 
6
5
  import type { RPC } from '@chainsafe/libp2p-gossipsub/message';
7
6
  import type { DataTransform } from '@chainsafe/libp2p-gossipsub/types';
8
7
  import type { Message } from '@libp2p/interface';
8
+ import { webcrypto } from 'node:crypto';
9
9
  import { compressSync, uncompressSync } from 'snappy';
10
10
  import xxhashFactory from 'xxhash-wasm';
11
11
 
12
+ /** Thrown when a Snappy-compressed response exceeds the allowed decompressed size. */
13
+ export class OversizedSnappyResponseError extends Error {
14
+ constructor(decompressedSize: number, maxSizeKb: number) {
15
+ super(`Decompressed size ${decompressedSize} exceeds maximum allowed size of ${maxSizeKb}kb`);
16
+ this.name = 'OversizedSnappyResponseError';
17
+ }
18
+ }
19
+
12
20
  // Load WASM
13
21
  const xxhash = await xxhashFactory();
14
22
 
@@ -44,11 +52,10 @@ export function msgIdToStrFn(msgId: Uint8Array): string {
44
52
  * @param message - The libp2p message
45
53
  * @returns The message identifier
46
54
  */
47
- export function getMsgIdFn(message: Message) {
48
- const { topic } = message;
49
-
50
- const vec = [Buffer.from(topic), message.data];
51
- return sha256(Buffer.concat(vec)).subarray(0, 20);
55
+ export async function getMsgIdFn({ topic, data }: Message): Promise<Uint8Array> {
56
+ const buffer = Buffer.concat([Buffer.from(topic), data]);
57
+ const hash = await webcrypto.subtle.digest('SHA-256', buffer);
58
+ return Buffer.from(hash.slice(0, 20));
52
59
  }
53
60
 
54
61
  const DefaultMaxSizesKb: Record<TopicType, number> = {
@@ -58,7 +65,8 @@ const DefaultMaxSizesKb: Record<TopicType, number> = {
58
65
  // Proposals may carry some tx objects, so we allow a larger size capped at 10mb
59
66
  // Note this may not be enough for carrying all tx objects in a block
60
67
  [TopicType.block_proposal]: 1024 * 10,
61
- // TODO(palla/mbps): Check size for checkpoint proposal
68
+ // Checkpoint proposals carry almost the same data as a block proposal (see the lastBlockProposal)
69
+ // Only diff is an additional header, which is pretty small compared to the 10mb limit
62
70
  [TopicType.checkpoint_proposal]: 1024 * 10,
63
71
  };
64
72
 
@@ -78,15 +86,15 @@ export class SnappyTransform implements DataTransform {
78
86
  return this.inboundTransformData(Buffer.from(data), topic);
79
87
  }
80
88
 
81
- public inboundTransformData(data: Buffer, topic?: TopicType): Buffer {
89
+ public inboundTransformData(data: Buffer, topic?: TopicType, maxSizeKbOverride?: number): Buffer {
82
90
  if (data.length === 0) {
83
91
  return data;
84
92
  }
85
- const maxSizeKb = this.maxSizesKb[topic!] ?? this.defaultMaxSizeKb;
93
+ const maxSizeKb = maxSizeKbOverride ?? this.maxSizesKb[topic!] ?? this.defaultMaxSizeKb;
86
94
  const { decompressedSize } = readSnappyPreamble(data);
87
95
  if (decompressedSize > maxSizeKb * 1024) {
88
96
  this.logger.warn(`Decompressed size ${decompressedSize} exceeds maximum allowed size of ${maxSizeKb}kb`);
89
- throw new Error(`Decompressed size ${decompressedSize} exceeds maximum allowed size of ${maxSizeKb}kb`);
97
+ throw new OversizedSnappyResponseError(decompressedSize, maxSizeKb);
90
98
  }
91
99
 
92
100
  return Buffer.from(uncompressSync(data, { asBuffer: true }));