@aztec/p2p 0.0.1-commit.358457c → 0.0.1-commit.3750d92a7

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 (348) hide show
  1. package/README.md +129 -3
  2. package/dest/client/factory.d.ts +5 -6
  3. package/dest/client/factory.d.ts.map +1 -1
  4. package/dest/client/factory.js +30 -16
  5. package/dest/client/interface.d.ts +12 -5
  6. package/dest/client/interface.d.ts.map +1 -1
  7. package/dest/client/p2p_client.d.ts +6 -5
  8. package/dest/client/p2p_client.d.ts.map +1 -1
  9. package/dest/client/p2p_client.js +47 -39
  10. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +18 -8
  11. package/dest/config.d.ts +125 -100
  12. package/dest/config.d.ts.map +1 -1
  13. package/dest/config.js +92 -33
  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/index.d.ts +1 -2
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +0 -1
  20. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +7 -5
  21. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  22. package/dest/mem_pools/attestation_pool/attestation_pool.js +16 -9
  23. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +6 -6
  24. package/dest/mem_pools/index.d.ts +1 -2
  25. package/dest/mem_pools/index.d.ts.map +1 -1
  26. package/dest/mem_pools/instrumentation.d.ts +4 -2
  27. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  28. package/dest/mem_pools/instrumentation.js +16 -14
  29. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  30. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  31. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +2 -1
  32. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +1 -1
  33. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  34. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +2 -0
  35. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +7 -1
  36. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  37. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +2 -2
  38. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +1 -1
  39. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  40. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +8 -6
  41. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +2 -2
  42. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  43. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
  44. package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -2
  45. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  46. package/dest/mem_pools/tx_pool_v2/index.js +1 -1
  47. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +9 -5
  48. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool_v2/interfaces.js +2 -1
  50. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +40 -11
  51. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  52. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +75 -19
  53. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +1 -1
  54. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  55. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +26 -44
  56. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +4 -2
  57. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  58. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +6 -0
  59. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +2 -1
  60. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  61. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +60 -28
  62. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +5 -2
  63. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  64. package/dest/msg_validators/attestation_validator/attestation_validator.js +20 -11
  65. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +4 -2
  66. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  67. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +2 -2
  68. package/dest/msg_validators/clock_tolerance.d.ts +12 -1
  69. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
  70. package/dest/msg_validators/clock_tolerance.js +54 -3
  71. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +7 -4
  72. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  73. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
  74. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +7 -4
  75. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  76. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
  77. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +15 -8
  78. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  79. package/dest/msg_validators/proposal_validator/proposal_validator.js +67 -47
  80. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  81. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  82. package/dest/msg_validators/tx_validator/allowed_public_setup.js +24 -20
  83. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  84. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  85. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  86. package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
  87. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
  88. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
  89. package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
  90. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  91. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  92. package/dest/msg_validators/tx_validator/data_validator.js +35 -2
  93. package/dest/msg_validators/tx_validator/factory.d.ts +23 -4
  94. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  95. package/dest/msg_validators/tx_validator/factory.js +36 -10
  96. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  97. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  98. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  99. package/dest/msg_validators/tx_validator/gas_validator.d.ts +13 -4
  100. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  101. package/dest/msg_validators/tx_validator/gas_validator.js +49 -17
  102. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  103. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  104. package/dest/msg_validators/tx_validator/index.js +1 -0
  105. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  106. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  107. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  108. package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
  109. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  110. package/dest/msg_validators/tx_validator/phases_validator.js +72 -24
  111. package/dest/services/data_store.d.ts +1 -1
  112. package/dest/services/data_store.d.ts.map +1 -1
  113. package/dest/services/data_store.js +5 -5
  114. package/dest/services/dummy_service.d.ts +6 -3
  115. package/dest/services/dummy_service.d.ts.map +1 -1
  116. package/dest/services/dummy_service.js +6 -1
  117. package/dest/services/encoding.d.ts +6 -2
  118. package/dest/services/encoding.d.ts.map +1 -1
  119. package/dest/services/encoding.js +14 -8
  120. package/dest/services/gossipsub/topic_score_params.d.ts +13 -2
  121. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
  122. package/dest/services/gossipsub/topic_score_params.js +21 -4
  123. package/dest/services/libp2p/libp2p_service.d.ts +19 -30
  124. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  125. package/dest/services/libp2p/libp2p_service.js +171 -135
  126. package/dest/services/peer-manager/metrics.d.ts +3 -1
  127. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  128. package/dest/services/peer-manager/metrics.js +6 -0
  129. package/dest/services/peer-manager/peer_manager.d.ts +6 -2
  130. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  131. package/dest/services/peer-manager/peer_manager.js +39 -11
  132. package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
  133. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  134. package/dest/services/peer-manager/peer_scoring.js +32 -10
  135. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +11 -8
  136. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  137. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +69 -65
  138. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +3 -2
  139. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  140. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +5 -4
  141. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  142. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +13 -7
  143. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +3 -1
  144. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  145. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +3 -0
  146. package/dest/services/reqresp/config.d.ts +3 -3
  147. package/dest/services/reqresp/config.d.ts.map +1 -1
  148. package/dest/services/reqresp/interface.d.ts +14 -9
  149. package/dest/services/reqresp/interface.d.ts.map +1 -1
  150. package/dest/services/reqresp/interface.js +10 -11
  151. package/dest/services/reqresp/metrics.d.ts +1 -1
  152. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  153. package/dest/services/reqresp/metrics.js +0 -1
  154. package/dest/services/reqresp/protocols/index.d.ts +1 -2
  155. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  156. package/dest/services/reqresp/protocols/index.js +0 -1
  157. package/dest/services/reqresp/protocols/tx.d.ts +1 -1
  158. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  159. package/dest/services/reqresp/protocols/tx.js +1 -3
  160. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
  161. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  162. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
  163. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  164. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  165. package/dest/services/reqresp/rate-limiter/rate_limits.js +0 -10
  166. package/dest/services/reqresp/reqresp.d.ts +4 -2
  167. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  168. package/dest/services/reqresp/reqresp.js +30 -12
  169. package/dest/services/service.d.ts +5 -2
  170. package/dest/services/service.d.ts.map +1 -1
  171. package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -4
  172. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  173. package/dest/services/tx_collection/fast_tx_collection.js +57 -73
  174. package/dest/services/tx_collection/file_store_tx_source.d.ts +5 -4
  175. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
  176. package/dest/services/tx_collection/file_store_tx_source.js +39 -29
  177. package/dest/services/tx_collection/proposal_tx_collector.d.ts +6 -7
  178. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  179. package/dest/services/tx_collection/proposal_tx_collector.js +4 -4
  180. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  181. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  182. package/dest/services/tx_collection/request_tracker.js +84 -0
  183. package/dest/services/tx_collection/slow_tx_collection.js +1 -1
  184. package/dest/services/tx_collection/tx_collection.d.ts +3 -6
  185. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  186. package/dest/services/tx_collection/tx_source.d.ts +6 -5
  187. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  188. package/dest/services/tx_collection/tx_source.js +9 -7
  189. package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
  190. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  191. package/dest/test-helpers/make-test-p2p-clients.js +1 -2
  192. package/dest/test-helpers/mock-pubsub.d.ts +12 -5
  193. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  194. package/dest/test-helpers/mock-pubsub.js +37 -12
  195. package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
  196. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  197. package/dest/test-helpers/reqresp-nodes.js +3 -4
  198. package/dest/test-helpers/testbench-utils.d.ts +1 -1
  199. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  200. package/dest/test-helpers/testbench-utils.js +23 -3
  201. package/dest/testbench/p2p_client_testbench_worker.js +73 -21
  202. package/dest/testbench/worker_client_manager.d.ts +10 -1
  203. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  204. package/dest/testbench/worker_client_manager.js +55 -3
  205. package/dest/util.d.ts +1 -1
  206. package/package.json +14 -14
  207. package/src/client/factory.ts +51 -27
  208. package/src/client/interface.ts +12 -10
  209. package/src/client/p2p_client.ts +52 -51
  210. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +20 -11
  211. package/src/config.ts +137 -35
  212. package/src/errors/p2p-service.error.ts +11 -0
  213. package/src/index.ts +0 -1
  214. package/src/mem_pools/attestation_pool/attestation_pool.ts +17 -12
  215. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +6 -6
  216. package/src/mem_pools/index.ts +0 -3
  217. package/src/mem_pools/instrumentation.ts +17 -13
  218. package/src/mem_pools/tx_pool_v2/README.md +9 -1
  219. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +2 -1
  220. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +3 -0
  221. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +11 -1
  222. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +3 -3
  223. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +15 -6
  224. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +2 -1
  225. package/src/mem_pools/tx_pool_v2/index.ts +1 -1
  226. package/src/mem_pools/tx_pool_v2/interfaces.ts +9 -4
  227. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +110 -22
  228. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +29 -43
  229. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +16 -1
  230. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +68 -26
  231. package/src/msg_validators/attestation_validator/README.md +49 -0
  232. package/src/msg_validators/attestation_validator/attestation_validator.ts +21 -9
  233. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +4 -1
  234. package/src/msg_validators/clock_tolerance.ts +72 -3
  235. package/src/msg_validators/proposal_validator/README.md +123 -0
  236. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +17 -4
  237. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +23 -7
  238. package/src/msg_validators/proposal_validator/proposal_validator.ts +79 -49
  239. package/src/msg_validators/tx_validator/README.md +5 -1
  240. package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
  241. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  242. package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
  243. package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
  244. package/src/msg_validators/tx_validator/data_validator.ts +42 -1
  245. package/src/msg_validators/tx_validator/factory.ts +43 -3
  246. package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
  247. package/src/msg_validators/tx_validator/gas_validator.ts +65 -16
  248. package/src/msg_validators/tx_validator/index.ts +1 -0
  249. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  250. package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
  251. package/src/services/data_store.ts +5 -13
  252. package/src/services/dummy_service.ts +8 -2
  253. package/src/services/encoding.ts +14 -7
  254. package/src/services/gossipsub/topic_score_params.ts +36 -4
  255. package/src/services/libp2p/libp2p_service.ts +169 -150
  256. package/src/services/peer-manager/metrics.ts +7 -0
  257. package/src/services/peer-manager/peer_manager.ts +45 -11
  258. package/src/services/peer-manager/peer_scoring.ts +27 -5
  259. package/src/services/reqresp/README.md +229 -0
  260. package/src/services/reqresp/batch-tx-requester/README.md +46 -7
  261. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +64 -69
  262. package/src/services/reqresp/batch-tx-requester/interface.ts +2 -1
  263. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +13 -6
  264. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +5 -0
  265. package/src/services/reqresp/config.ts +2 -2
  266. package/src/services/reqresp/interface.ts +21 -11
  267. package/src/services/reqresp/metrics.ts +0 -1
  268. package/src/services/reqresp/protocols/index.ts +0 -1
  269. package/src/services/reqresp/protocols/tx.ts +1 -3
  270. package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
  271. package/src/services/reqresp/rate-limiter/rate_limits.ts +0 -10
  272. package/src/services/reqresp/reqresp.ts +40 -13
  273. package/src/services/service.ts +6 -1
  274. package/src/services/tx_collection/fast_tx_collection.ts +57 -83
  275. package/src/services/tx_collection/file_store_tx_source.ts +43 -31
  276. package/src/services/tx_collection/proposal_tx_collector.ts +8 -13
  277. package/src/services/tx_collection/request_tracker.ts +127 -0
  278. package/src/services/tx_collection/slow_tx_collection.ts +1 -1
  279. package/src/services/tx_collection/tx_collection.ts +3 -5
  280. package/src/services/tx_collection/tx_source.ts +8 -7
  281. package/src/test-helpers/make-test-p2p-clients.ts +1 -3
  282. package/src/test-helpers/mock-pubsub.ts +34 -11
  283. package/src/test-helpers/reqresp-nodes.ts +5 -8
  284. package/src/test-helpers/testbench-utils.ts +30 -3
  285. package/src/testbench/p2p_client_testbench_worker.ts +74 -21
  286. package/src/testbench/worker_client_manager.ts +68 -6
  287. package/src/util.ts +1 -1
  288. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
  289. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
  290. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
  291. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
  292. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
  293. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
  294. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
  295. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
  296. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
  297. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
  298. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
  299. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
  300. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
  301. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
  302. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
  303. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
  304. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
  305. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
  306. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
  307. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
  308. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
  309. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
  310. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
  311. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
  312. package/dest/mem_pools/tx_pool/index.d.ts +0 -3
  313. package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
  314. package/dest/mem_pools/tx_pool/index.js +0 -2
  315. package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
  316. package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
  317. package/dest/mem_pools/tx_pool/priority.js +0 -15
  318. package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
  319. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
  320. package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
  321. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
  322. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
  323. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
  324. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
  325. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  326. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
  327. package/dest/services/reqresp/protocols/block.d.ts +0 -9
  328. package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
  329. package/dest/services/reqresp/protocols/block.js +0 -32
  330. package/dest/services/tx_collection/missing_txs_tracker.d.ts +0 -32
  331. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +0 -1
  332. package/dest/services/tx_collection/missing_txs_tracker.js +0 -27
  333. package/src/mem_pools/tx_pool/README.md +0 -270
  334. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
  335. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
  336. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
  337. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
  338. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
  339. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
  340. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
  341. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
  342. package/src/mem_pools/tx_pool/index.ts +0 -2
  343. package/src/mem_pools/tx_pool/priority.ts +0 -20
  344. package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
  345. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
  346. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
  347. package/src/services/reqresp/protocols/block.ts +0 -37
  348. package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
@@ -45,6 +45,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
45
45
  export interface TxPoolV2Callbacks {
46
46
  onTxsAdded: (txs: Tx[], opts: { source?: string }) => void;
47
47
  onTxsRemoved: (txHashes: string[] | bigint[]) => void;
48
+ onTxsMined: (txHashes: string[]) => void;
48
49
  }
49
50
 
50
51
  /**
@@ -61,6 +62,7 @@ export class TxPoolV2Impl {
61
62
  #l2BlockSource: L2BlockSource;
62
63
  #worldStateSynchronizer: WorldStateSynchronizer;
63
64
  #createTxValidator: TxPoolV2Dependencies['createTxValidator'];
65
+ #checkAllowedSetupCalls: TxPoolV2Dependencies['checkAllowedSetupCalls'];
64
66
 
65
67
  // === In-Memory Indices ===
66
68
  #indices: TxPoolIndices = new TxPoolIndices();
@@ -92,6 +94,7 @@ export class TxPoolV2Impl {
92
94
  this.#l2BlockSource = deps.l2BlockSource;
93
95
  this.#worldStateSynchronizer = deps.worldStateSynchronizer;
94
96
  this.#createTxValidator = deps.createTxValidator;
97
+ this.#checkAllowedSetupCalls = deps.checkAllowedSetupCalls;
95
98
 
96
99
  this.#config = { ...DEFAULT_TX_POOL_V2_CONFIG, ...config };
97
100
  this.#archive = new TxArchive(archiveStore, this.#config.archivedTxLimit, log);
@@ -187,9 +190,35 @@ export class TxPoolV2Impl {
187
190
  const errors = new Map<string, TxPoolRejectionError>();
188
191
  const acceptedPending = new Set<string>();
189
192
 
193
+ // Phase 1: Pre-compute all throwable I/O outside the transaction.
194
+ // If any pre-computation throws, the entire call fails before mutations happen.
195
+ const precomputed = new Map<string, { meta: TxMetaData; minedBlockId: L2BlockId | undefined; isValid: boolean }>();
196
+
197
+ const validator = await this.#createTxValidator();
198
+
199
+ for (const tx of txs) {
200
+ const txHash = tx.getTxHash();
201
+ const txHashStr = txHash.toString();
202
+
203
+ const meta = await buildTxMetaData(tx);
204
+ const minedBlockId = await this.#getMinedBlockId(txHash);
205
+
206
+ // Validate non-mined txs (mined and pre-protected txs bypass validation inside the transaction)
207
+ let isValid = true;
208
+ if (!minedBlockId) {
209
+ isValid = await this.#validateMeta(meta, validator);
210
+ }
211
+
212
+ precomputed.set(txHashStr, { meta, minedBlockId, isValid });
213
+ }
214
+
215
+ // Phase 2: Apply mutations inside the transaction using only pre-computed results,
216
+ // in-memory reads, and buffered DB writes. Nothing here can throw an unhandled exception.
190
217
  const poolAccess = this.#createPreAddPoolAccess();
191
218
  const preAddContext: PreAddContext | undefined =
192
- opts.feeComparisonOnly !== undefined ? { feeComparisonOnly: opts.feeComparisonOnly } : undefined;
219
+ opts.feeComparisonOnly !== undefined
220
+ ? { feeComparisonOnly: opts.feeComparisonOnly, priceBumpPercentage: this.#config.priceBumpPercentage }
221
+ : undefined;
193
222
 
194
223
  await this.#store.transactionAsync(async () => {
195
224
  for (const tx of txs) {
@@ -202,22 +231,25 @@ export class TxPoolV2Impl {
202
231
  continue;
203
232
  }
204
233
 
205
- // Check mined status first (applies to all paths)
206
- const minedBlockId = await this.#getMinedBlockId(txHash);
234
+ const { meta, minedBlockId, isValid } = precomputed.get(txHashStr)!;
207
235
  const preProtectedSlot = this.#indices.getProtectionSlot(txHashStr);
208
236
 
209
237
  if (minedBlockId) {
210
238
  // Already mined - add directly (protection already set if pre-protected)
211
- await this.#addTx(tx, { mined: minedBlockId }, opts);
239
+ await this.#addTx(tx, { mined: minedBlockId }, opts, meta);
212
240
  accepted.push(txHash);
213
241
  } else if (preProtectedSlot !== undefined) {
214
242
  // Pre-protected and not mined - add as protected (bypass validation)
215
- await this.#addTx(tx, { protected: preProtectedSlot }, opts);
243
+ await this.#addTx(tx, { protected: preProtectedSlot }, opts, meta);
216
244
  accepted.push(txHash);
245
+ } else if (!isValid) {
246
+ // Failed pre-computed validation
247
+ rejected.push(txHash);
217
248
  } else {
218
- // Regular pending tx - validate and run pre-add rules
249
+ // Regular pending tx - run pre-add rules using pre-computed metadata
219
250
  const result = await this.#tryAddRegularPendingTx(
220
251
  tx,
252
+ meta,
221
253
  opts,
222
254
  poolAccess,
223
255
  acceptedPending,
@@ -227,8 +259,6 @@ export class TxPoolV2Impl {
227
259
  );
228
260
  if (result.status === 'accepted') {
229
261
  acceptedPending.add(txHashStr);
230
- } else if (result.status === 'rejected') {
231
- rejected.push(txHash);
232
262
  } else {
233
263
  ignored.push(txHash);
234
264
  }
@@ -259,27 +289,21 @@ export class TxPoolV2Impl {
259
289
  return { accepted, ignored, rejected, ...(errors.size > 0 ? { errors } : {}) };
260
290
  }
261
291
 
262
- /** Validates and adds a regular pending tx. Returns status. */
292
+ /** Adds a validated pending tx, running pre-add rules and evicting conflicts. */
263
293
  async #tryAddRegularPendingTx(
264
294
  tx: Tx,
295
+ precomputedMeta: TxMetaData,
265
296
  opts: { source?: string },
266
297
  poolAccess: PreAddPoolAccess,
267
298
  acceptedPending: Set<string>,
268
299
  ignored: TxHash[],
269
300
  errors: Map<string, TxPoolRejectionError>,
270
301
  preAddContext?: PreAddContext,
271
- ): Promise<{ status: 'accepted' | 'ignored' | 'rejected' }> {
272
- const txHash = tx.getTxHash();
273
- const txHashStr = txHash.toString();
274
-
275
- // Build metadata and validate using metadata
276
- const meta = await buildTxMetaData(tx);
277
- if (!(await this.#validateMeta(meta))) {
278
- return { status: 'rejected' };
279
- }
302
+ ): Promise<{ status: 'accepted' | 'ignored' }> {
303
+ const txHashStr = tx.getTxHash().toString();
280
304
 
281
305
  // Run pre-add rules
282
- const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess, preAddContext);
306
+ const preAddResult = await this.#evictionManager.runPreAddRules(precomputedMeta, poolAccess, preAddContext);
283
307
 
284
308
  if (preAddResult.shouldIgnore) {
285
309
  this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason?.message ?? 'unknown reason'}`);
@@ -323,7 +347,7 @@ export class TxPoolV2Impl {
323
347
  }
324
348
 
325
349
  // Add the transaction
326
- await this.#addTx(tx, 'pending', opts);
350
+ await this.#addTx(tx, 'pending', opts, precomputedMeta);
327
351
  return { status: 'accepted' };
328
352
  }
329
353
 
@@ -332,6 +356,7 @@ export class TxPoolV2Impl {
332
356
 
333
357
  // Check if already in pool
334
358
  if (this.#indices.has(txHashStr)) {
359
+ this.#log.verbose(`canAddPendingTx: tx ${txHashStr} already in pool`);
335
360
  return 'ignored';
336
361
  }
337
362
 
@@ -340,26 +365,37 @@ export class TxPoolV2Impl {
340
365
  const poolAccess = this.#createPreAddPoolAccess();
341
366
  const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
342
367
 
343
- return preAddResult.shouldIgnore ? 'ignored' : 'accepted';
368
+ if (preAddResult.shouldIgnore) {
369
+ this.#log.verbose(`canAddPendingTx: tx ${txHashStr} ignored by pre-add rule`, {
370
+ reason: preAddResult.reason?.message ?? 'no reason provided',
371
+ });
372
+ return 'ignored';
373
+ }
374
+ return 'accepted';
344
375
  }
345
376
 
346
377
  async addProtectedTxs(txs: Tx[], block: BlockHeader, opts: { source?: string }): Promise<void> {
347
378
  const slotNumber = block.globalVariables.slotNumber;
348
379
 
380
+ // Precompute setup-call allow-list flags outside the store transaction
381
+ const allowedFlags = await Promise.all(txs.map(tx => this.#checkAllowedSetupCalls(tx)));
382
+
349
383
  await this.#store.transactionAsync(async () => {
350
- for (const tx of txs) {
384
+ for (let i = 0; i < txs.length; i++) {
385
+ const tx = txs[i];
351
386
  const txHash = tx.getTxHash();
352
387
  const txHashStr = txHash.toString();
353
388
  const isNew = !this.#indices.has(txHashStr);
354
389
  const minedBlockId = await this.#getMinedBlockId(txHash);
355
390
 
356
391
  if (isNew) {
392
+ const meta = await buildTxMetaData(tx, allowedFlags[i]);
357
393
  // New tx - add as mined or protected (callback emitted by #addTx)
358
394
  if (minedBlockId) {
359
- await this.#addTx(tx, { mined: minedBlockId }, opts);
395
+ await this.#addTx(tx, { mined: minedBlockId }, opts, meta);
360
396
  this.#indices.setProtection(txHashStr, slotNumber);
361
397
  } else {
362
- await this.#addTx(tx, { protected: slotNumber }, opts);
398
+ await this.#addTx(tx, { protected: slotNumber }, opts, meta);
363
399
  }
364
400
  } else {
365
401
  // Existing tx - update protection and mined status
@@ -479,6 +515,10 @@ export class TxPoolV2Impl {
479
515
  await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
480
516
  });
481
517
 
518
+ if (found.length > 0) {
519
+ this.#callbacks.onTxsMined(found.map(m => m.txHash));
520
+ }
521
+
482
522
  this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
483
523
  }
484
524
 
@@ -765,9 +805,10 @@ export class TxPoolV2Impl {
765
805
  tx: Tx,
766
806
  state: 'pending' | { protected: SlotNumber } | { mined: L2BlockId },
767
807
  opts: { source?: string } = {},
808
+ precomputedMeta?: TxMetaData,
768
809
  ): Promise<TxMetaData> {
769
810
  const txHashStr = tx.getTxHash().toString();
770
- const meta = await buildTxMetaData(tx);
811
+ const meta = precomputedMeta ?? (await buildTxMetaData(tx));
771
812
  meta.receivedAt = this.#dateProvider.now();
772
813
 
773
814
  await this.#txsDB.set(txHashStr, tx.toBuffer());
@@ -949,7 +990,8 @@ export class TxPoolV2Impl {
949
990
 
950
991
  try {
951
992
  const tx = Tx.fromBuffer(buffer);
952
- const meta = await buildTxMetaData(tx);
993
+ const allowedSetupCalls = await this.#checkAllowedSetupCalls(tx);
994
+ const meta = await buildTxMetaData(tx, allowedSetupCalls);
953
995
  loaded.push({ tx, meta });
954
996
  } catch (err) {
955
997
  this.#log.warn(`Failed to deserialize tx ${txHashStr}, deleting`, { err });
@@ -0,0 +1,49 @@
1
+ # Attestation Validation
2
+
3
+ This module validates `CheckpointAttestation` gossipsub messages. Attestations are signatures from committee members endorsing a checkpoint proposal.
4
+
5
+ **Topic**: `checkpoint_attestation` | **Snappy size limit**: 5 KB
6
+
7
+ ## Stage 1: AttestationValidator (Gossipsub Validation)
8
+
9
+ | # | Rule | Consequence | Severity | File |
10
+ |---|------|-------------|----------|------|
11
+ | 1 | **Slot timeliness**: `currentSlot` or `nextSlot`. Previous slot within 500ms: IGNORE. Older: REJECT. | REJECT or IGNORE | HighToleranceError | `attestation_validator.ts` |
12
+ | 2 | **Attester signature**: `getSender()` must recover valid address | REJECT | LowToleranceError | same |
13
+ | 3 | **Attester in committee**: recovered address in committee for slot | REJECT | HighToleranceError | same |
14
+ | 4 | **Proposer exists**: `getProposerAttesterAddressInSlot` must return defined | REJECT | HighToleranceError | same |
15
+ | 5 | **Proposer signature**: `getProposer()` must recover valid address | REJECT | LowToleranceError | same |
16
+ | 6 | **Proposer matches expected**: recovered proposer = expected for slot | REJECT | HighToleranceError | same |
17
+ | 7 | **NoCommitteeError**: committee unavailable | REJECT | LowToleranceError | same |
18
+
19
+ **Fisherman mode extension** (`FishermanAttestationValidator`): if a checkpoint proposal for the same archive exists in pool, the attestation's `ConsensusPayload` must `.equals()` the stored proposal's payload. On mismatch: REJECT + LowToleranceError.
20
+
21
+ ## Stage 2: Pool Admission
22
+
23
+ | # | Rule | Consequence |
24
+ |---|------|-------------|
25
+ | 8 | Sender recoverable (pool-side) | Silent drop |
26
+ | 9 | Not a duplicate (same slot + proposalId + signer) | IGNORE |
27
+ | 10 | Per-signer cap: `MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER` = 2 | IGNORE |
28
+
29
+ Own attestations added via `addOwnCheckpointAttestations` bypass the per-signer cap.
30
+
31
+ ## Stage 3: Equivocation Detection
32
+
33
+ When a signer's attestation count for a slot reaches exactly 2 (different proposals): `duplicateAttestationCallback` fires -> `WANT_TO_SLASH_EVENT` with `OffenseType.DUPLICATE_ATTESTATION`. Attestation still ACCEPTED and rebroadcast. Callback fires once (not again at count 3+).
34
+
35
+ ## Validation at L1 Checkpoint Submission (Archiver)
36
+
37
+ | Rule | Consequence | File |
38
+ |------|-------------|------|
39
+ | Each attestation must have recoverable signature (or address-only is allowed but does not count toward quorum) | Checkpoint rejected as invalid | `archiver/src/modules/validation.ts` |
40
+ | Attestation at index `i` must correspond to committee member at index `i` | Checkpoint rejected as invalid | same |
41
+ | Valid attestation count >= floor(committee * 2/3) + 1 | Checkpoint rejected as invalid | same |
42
+ | No committee / escape hatch open | Accepted unconditionally | same |
43
+
44
+ Note: `skipValidateCheckpointAttestations` config flag bypasses all archiver attestation validation.
45
+
46
+ ## Gossipsub Topic Scoring
47
+
48
+ P3 enabled with expected messages per slot = `targetCommitteeSize`. Conservative threshold (30% of convergence value). Max P3 penalty = -34 per topic.
49
+
@@ -8,14 +8,21 @@ import {
8
8
  type ValidationResult,
9
9
  } from '@aztec/stdlib/p2p';
10
10
 
11
- import { isWithinClockTolerance } from '../clock_tolerance.js';
11
+ import { PipeliningWindow, isWithinClockTolerance } from '../clock_tolerance.js';
12
12
 
13
13
  export class CheckpointAttestationValidator implements P2PValidator<CheckpointAttestation> {
14
14
  protected epochCache: EpochCacheInterface;
15
15
  protected logger: Logger;
16
+ private readonly pipeliningWindow: PipeliningWindow;
16
17
 
17
- constructor(epochCache: EpochCacheInterface) {
18
+ constructor(
19
+ epochCache: EpochCacheInterface,
20
+ opts: {
21
+ l1PublishingTime?: number;
22
+ },
23
+ ) {
18
24
  this.epochCache = epochCache;
25
+ this.pipeliningWindow = new PipeliningWindow(epochCache, { l1PublishingTime: opts.l1PublishingTime });
19
26
  this.logger = createLogger('p2p:checkpoint-attestation-validator');
20
27
  }
21
28
 
@@ -23,18 +30,23 @@ export class CheckpointAttestationValidator implements P2PValidator<CheckpointAt
23
30
  const slotNumber = message.payload.header.slotNumber;
24
31
 
25
32
  try {
26
- const { currentSlot, nextSlot } = this.epochCache.getCurrentAndNextSlot();
33
+ // Use target slots since proposals target pipeline slots (slot + 1 when pipelining).
34
+ const { targetSlot, nextSlot } = this.epochCache.getTargetAndNextSlot();
27
35
 
28
- if (slotNumber !== currentSlot && slotNumber !== nextSlot) {
29
- // Check if message is for previous slot and within clock tolerance
30
- if (!isWithinClockTolerance(slotNumber, currentSlot, this.epochCache)) {
36
+ if (slotNumber !== targetSlot && slotNumber !== nextSlot) {
37
+ // When pipelining, accept attestations for the current slot (built in the previous slot)
38
+ // until the target slot reaches its L1 publish cutoff.
39
+ if (this.pipeliningWindow.acceptsAttestation(slotNumber)) {
40
+ // Fall through to remaining validation (signature, committee, etc.)
41
+ } else if (!isWithinClockTolerance(slotNumber, targetSlot, this.epochCache)) {
31
42
  this.logger.warn(
32
- `Checkpoint attestation slot ${slotNumber} is not current (${currentSlot}) or next (${nextSlot}) slot`,
43
+ `Checkpoint attestation slot ${slotNumber} is not current (${targetSlot}) or next (${nextSlot}) slot`,
33
44
  );
34
45
  return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
46
+ } else {
47
+ this.logger.debug(`Ignoring checkpoint attestation for previous slot ${slotNumber} within clock tolerance`);
48
+ return { result: 'ignore' };
35
49
  }
36
- this.logger.debug(`Ignoring checkpoint attestation for previous slot ${slotNumber} within clock tolerance`);
37
- return { result: 'ignore' };
38
50
  }
39
51
 
40
52
  // Verify the signature is valid
@@ -20,8 +20,11 @@ export class FishermanAttestationValidator extends CheckpointAttestationValidato
20
20
  epochCache: EpochCacheInterface,
21
21
  private attestationPool: AttestationPoolApi,
22
22
  telemetryClient: TelemetryClient,
23
+ opts: {
24
+ l1PublishingTime?: number;
25
+ } = {},
23
26
  ) {
24
- super(epochCache);
27
+ super(epochCache, opts);
25
28
  this.logger = this.logger.createChild('[FISHERMAN]');
26
29
 
27
30
  const meter = telemetryClient.getMeter('FishermanAttestationValidator');
@@ -1,5 +1,6 @@
1
1
  import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
2
  import { SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { DEFAULT_P2P_PROPAGATION_TIME, createPipelinedCheckpointTimingModel } from '@aztec/stdlib/timetable';
3
4
 
4
5
  /**
5
6
  * Maximum clock disparity tolerance for P2P message validation (in milliseconds).
@@ -36,10 +37,11 @@ export function isWithinClockTolerance(
36
37
  }
37
38
 
38
39
  // Check how far we are into the current slot (in milliseconds)
39
- const { ts: slotStartTs, nowMs, slot } = epochCache.getEpochAndSlotNow();
40
+ const { ts: slotStartTs, nowMs } = epochCache.getEpochAndSlotNow();
41
+ const targetSlot = epochCache.getTargetSlot();
40
42
 
41
- // Sanity check: ensure the epoch cache's current slot matches the expected current slot
42
- if (slot !== currentSlot) {
43
+ // Sanity check: ensure the epoch cache's target slot matches the expected current slot
44
+ if (targetSlot !== currentSlot) {
43
45
  return false;
44
46
  }
45
47
 
@@ -49,3 +51,70 @@ export function isWithinClockTolerance(
49
51
 
50
52
  return elapsedMs < MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS;
51
53
  }
54
+
55
+ /**
56
+ * Checks if a message should be accepted under the pipelining grace period.
57
+ *
58
+ * When pipelining is enabled, `targetSlot = slotNow + 1`. A proposal built in slot N-1
59
+ * for slot N arrives when validators are in slot N, so their `targetSlot = N+1`.
60
+ * This function accepts proposals for the current wallclock slot if we're within the
61
+ * first `windowSeconds` seconds of the slot (the pipelining grace period). - see stdlib/timetable/index.ts
62
+ *
63
+ * @param messageSlot - The slot number from the received message
64
+ * @param epochCache - EpochCache to get timing and pipelining state
65
+ * @param windowSeconds - The window grace period allowed for attestations into the next slot
66
+ * @returns true if pipelining is enabled, the message is for the current slot, and we're within the grace period
67
+ */
68
+ function isWithinPipeliningWindow(
69
+ messageSlot: SlotNumber,
70
+ epochCache: EpochCacheInterface,
71
+ windowSeconds: number,
72
+ ): boolean {
73
+ if (!epochCache.isProposerPipeliningEnabled()) {
74
+ return false;
75
+ }
76
+
77
+ const currentSlot = epochCache.getSlotNow();
78
+ if (messageSlot !== currentSlot) {
79
+ return false;
80
+ }
81
+
82
+ const { ts: slotStartTs, nowMs } = epochCache.getEpochAndSlotNow();
83
+ const slotStartMs = slotStartTs * 1000n;
84
+ const elapsedMs = Number(nowMs - slotStartMs);
85
+ const windowMs = windowSeconds * 1000 + MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS;
86
+
87
+ return elapsedMs < windowMs;
88
+ }
89
+
90
+ export class PipeliningWindow {
91
+ private readonly proposalWindowIntoTargetSlot: number;
92
+ private readonly attestationWindowIntoTargetSlot: number;
93
+
94
+ constructor(
95
+ private readonly epochCache: EpochCacheInterface,
96
+ opts: {
97
+ p2pPropagationTime?: number;
98
+ l1PublishingTime?: number;
99
+ } = {},
100
+ ) {
101
+ const l1Constants = epochCache.getL1Constants();
102
+ const checkpointTiming = createPipelinedCheckpointTimingModel({
103
+ aztecSlotDuration: l1Constants.slotDuration,
104
+ ethereumSlotDuration: l1Constants.ethereumSlotDuration,
105
+ l1PublishingTime: opts.l1PublishingTime ?? l1Constants.ethereumSlotDuration,
106
+ p2pPropagationTime: opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME,
107
+ });
108
+
109
+ this.proposalWindowIntoTargetSlot = checkpointTiming.proposalWindowIntoTargetSlot;
110
+ this.attestationWindowIntoTargetSlot = checkpointTiming.attestationWindowIntoTargetSlot;
111
+ }
112
+
113
+ public acceptsProposal(messageSlot: SlotNumber): boolean {
114
+ return isWithinPipeliningWindow(messageSlot, this.epochCache, this.proposalWindowIntoTargetSlot);
115
+ }
116
+
117
+ public acceptsAttestation(messageSlot: SlotNumber): boolean {
118
+ return isWithinPipeliningWindow(messageSlot, this.epochCache, this.attestationWindowIntoTargetSlot);
119
+ }
120
+ }
@@ -0,0 +1,123 @@
1
+ # Proposal Validation
2
+
3
+ This module validates `BlockProposal` and `CheckpointProposal` gossipsub messages. Both share the same base `ProposalValidator` (neither subclass overrides `validate()`), with checkpoint-specific logic layered on top in the gossipsub handler.
4
+
5
+ ## BlockProposal
6
+
7
+ **Topic**: `block_proposal` | **Snappy size limit**: 10 MB
8
+
9
+ ### Stage 1: Gossipsub Validation (ProposalValidator)
10
+
11
+ File: `proposal_validator.ts`
12
+
13
+ | # | Rule | Consequence | Severity |
14
+ |---|------|-------------|----------|
15
+ | 1 | **Slot check**: must be `currentSlot` or `nextSlot`. Previous slot within 500ms tolerance: IGNORE. | REJECT | HighToleranceError |
16
+ | 2 | **Signature**: `getSender()` must recover a valid address. If `signedTxs` present, its recovered sender must match. | REJECT | MidToleranceError |
17
+ | 3 | **Txs permitted**: if `disableTransactions`, must have 0 txHashes and 0 embedded txs | REJECT | MidToleranceError |
18
+ | 4 | **Max txs**: `txHashes.length <= maxTxsPerBlock` | REJECT | MidToleranceError |
19
+ | 5 | **Embedded txs in txHashes**: every embedded tx's hash must appear in `txHashes` | REJECT | MidToleranceError |
20
+ | 6 | **Proposer check**: signer must match expected proposer for slot (skipped if committee size = 0) | REJECT | MidToleranceError |
21
+ | 7 | **Tx hash integrity**: each embedded tx's recomputed hash must match declared hash | REJECT | LowToleranceError |
22
+ | 8 | **NoCommitteeError**: epoch cache cannot determine committee | REJECT | LowToleranceError |
23
+
24
+ Deserialization guards: `BlockProposal.fromBuffer` and `SignedTxs.fromBuffer` both enforce `txCount <= MAX_TXS_PER_BLOCK` (65536). Violation -> REJECT + LowToleranceError.
25
+
26
+ ### Stage 2: Mempool (Attestation Pool)
27
+
28
+ | # | Rule | Consequence |
29
+ |---|------|-------------|
30
+ | 9 | **Duplicate**: same archive root already stored | IGNORE (no penalty) |
31
+ | 10 | **Per-position cap**: max 2 proposals per (slot, indexWithinCheckpoint) | REJECT + HighToleranceError |
32
+ | 11 | **Equivocation**: >1 distinct proposal for same (slot, index) | ACCEPT (rebroadcast for detection). At count=2: `duplicateProposalCallback` fires -> slash event (`OffenseType.DUPLICATE_PROPOSAL`, configured via `slashDuplicateProposalPenalty`) |
33
+
34
+ ### Stage 3: Validator-Client Processing (BlockProposalHandler)
35
+
36
+ Only runs on validator nodes. Non-validator nodes use a default handler that triggers tx collection without deep validation.
37
+
38
+ | # | Rule | Failure Reason |
39
+ |---|------|----------------|
40
+ | 12 | Signature re-check | `invalid_proposal` |
41
+ | 13 | ProposalValidator re-run | `invalid_proposal` |
42
+ | 14 | Self-proposal filter | Ignored silently |
43
+ | 15 | Parent block exists (`lastArchive.root` matches known block or genesis) | `parent_block_not_found` |
44
+ | 16 | Parent block slot <= proposal slot | `parent_block_wrong_slot` |
45
+ | 17 | Block number not already in archiver | `block_number_already_exists` |
46
+ | 18 | Checkpoint number consistency (multiple sub-rules for first/non-first blocks) | `invalid_proposal` |
47
+ | 19 | Global variables consistency (non-first block: chainId, version, slot, timestamp, coinbase, feeRecipient, gasFees match parent) | `global_variables_mismatch` |
48
+ | 20 | L1-to-L2 message hash matches `proposal.inHash` | `in_hash_mismatch` |
49
+ | 21 | All txs referenced by `txHashes` obtainable | `txs_not_available` |
50
+ | 22 | **Re-execution**: processed tx count matches `txHashes.length` | `timeout` (ReExTimeoutError) |
51
+ | 23 | **Re-execution**: no failed txs | `failed_txs` (ReExFailedTxsError) -- **SLASHABLE** |
52
+ | 24 | **Re-execution**: archive root and header match proposal | `state_mismatch` (ReExStateMismatchError) -- **SLASHABLE** |
53
+
54
+ **Escape hatch**: during escape hatch periods (`isEscapeHatchOpenAtSlot`), re-execution and slashing are both disabled, and the proposal is rejected locally.
55
+
56
+ **Conditional re-execution**: rules 22-24 only run when at least one condition is true: `fishermanMode` enabled, `slashBroadcastedInvalidBlockPenalty > 0`, committee membership, `alwaysReexecuteBlockProposals`, or `blobClient.canUpload()`.
57
+
58
+ **Slashing**: only `state_mismatch` and `failed_txs` trigger on-chain slashing (`OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL`, gated by `slashBroadcastedInvalidBlockPenalty > 0`). Unknown errors during re-execution do NOT slash.
59
+
60
+ **Embedded tx validation**: txs in `signedTxs` are validated via `createTxValidatorForBlockProposalReceivedTxs` (well-formedness only) when stored in the tx pool. Invalid embedded txs are rejected from the pool but do not cause the block proposal itself to be rejected at gossipsub level.
61
+
62
+ ### Gossipsub Topic Scoring
63
+
64
+ | Parameter | Effect |
65
+ |-----------|--------|
66
+ | P4 (invalidMessageDeliveries) | weight = -20, decay over 4 slots |
67
+ | P3 (meshMessageDeliveries) | Enabled only when `expectedBlockProposalsPerSlot > 0` (MBPS mode) |
68
+ | P1/P2 | Only active when P3 is enabled |
69
+
70
+ ---
71
+
72
+ ## CheckpointProposal
73
+
74
+ **Topic**: `checkpoint_proposal` | **Snappy size limit**: 10 MB
75
+
76
+ ### Stage 1: Gossipsub Validation (ProposalValidator)
77
+
78
+ Same `ProposalValidator.validate()` as BlockProposal (shared implementation, neither subclass overrides it). See BlockProposal Stage 1 rules 1-8.
79
+
80
+ ### Stage 2: Embedded Block Proposal Validation (if `lastBlock` present)
81
+
82
+ The checkpoint's embedded `lastBlock` is extracted via `getBlockProposal()` and validated through `BlockProposalValidator.validate()` plus block mempool checks.
83
+
84
+ | Rule | Consequence | File |
85
+ |------|-------------|------|
86
+ | Block proposal must pass `BlockProposalValidator.validate()` | If REJECT: entire checkpoint REJECTED | `libp2p_service.ts` |
87
+ | Block proposal must not exceed per-position cap (2) | Checkpoint REJECTED + HighToleranceError | same |
88
+ | Block equivocation detected (>1 proposals for same slot+index) | Checkpoint REJECTED (block itself is ACCEPT for re-broadcast) | same |
89
+
90
+ ### Stage 3: Mempool (Attestation Pool)
91
+
92
+ | Rule | Consequence | File |
93
+ |------|-------------|------|
94
+ | Duplicate (same archive ID) | IGNORE (no penalty). Embedded block still processed if valid. | `attestation_pool.ts` |
95
+ | Per-slot cap: `MAX_CHECKPOINT_PROPOSALS_PER_SLOT` = 2 | REJECT + HighToleranceError. Embedded block still processed. | same |
96
+
97
+ ### Stage 4: Equivocation Detection
98
+
99
+ When >1 checkpoint proposals exist for same slot (count > 1): ACCEPT (re-broadcast). At count == 2 (exactly): `duplicateProposalCallback` fires. Proposal NOT further processed. Callback fires only once per equivocation pair.
100
+
101
+ ### Stage 5: Validator-Client Consensus Validation
102
+
103
+ Determines whether the validator signs an attestation.
104
+
105
+ | Rule | Consequence | File |
106
+ |------|-------------|------|
107
+ | Escape hatch open | No attestation | `validator-client/src/validator.ts` |
108
+ | Signature invalid (re-check) | No attestation | same |
109
+ | Self-proposal | No attestation (ignored) | same |
110
+ | `feeAssetPriceModifier` outside [-100, +100] bps | No attestation | same |
111
+ | Not in committee (unless fisherman mode) | No attestation | same |
112
+ | Checkpoint header mismatch (computed vs proposal) | No attestation | same |
113
+ | Archive root mismatch | No attestation | same |
114
+ | Epoch out hash mismatch | No attestation | same |
115
+ | Last block not found / not matching | No attestation | same |
116
+ | Already attested to this or earlier slot | No attestation (unless `attestToEquivocatedProposals`) | same |
117
+
118
+ **`skipCheckpointProposalValidation` config**: when true, the re-execution checks (header/archive/epoch hash) are all skipped. Signature, fee modifier, committee, escape hatch, and equivocation checks still apply.
119
+
120
+ ### Gossipsub Topic Scoring
121
+
122
+ P3 enabled with expected rate of 1 message per slot. P4 weight = -20, max P3 penalty = -34 per topic.
123
+
@@ -1,10 +1,23 @@
1
1
  import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
- import type { BlockProposal, P2PValidator } from '@aztec/stdlib/p2p';
2
+ import type { BlockProposal, P2PValidator, ValidationResult } from '@aztec/stdlib/p2p';
3
3
 
4
4
  import { ProposalValidator } from '../proposal_validator/proposal_validator.js';
5
5
 
6
- export class BlockProposalValidator extends ProposalValidator<BlockProposal> implements P2PValidator<BlockProposal> {
7
- constructor(epochCache: EpochCacheInterface, opts: { txsPermitted: boolean }) {
8
- super(epochCache, opts, 'p2p:block_proposal_validator');
6
+ export class BlockProposalValidator implements P2PValidator<BlockProposal> {
7
+ private proposalValidator: ProposalValidator;
8
+
9
+ constructor(
10
+ epochCache: EpochCacheInterface,
11
+ opts: { txsPermitted: boolean; maxTxsPerBlock?: number; p2pPropagationTime?: number },
12
+ ) {
13
+ this.proposalValidator = new ProposalValidator(epochCache, opts, 'p2p:block_proposal_validator');
14
+ }
15
+
16
+ async validate(proposal: BlockProposal): Promise<ValidationResult> {
17
+ const headerResult = await this.proposalValidator.validate(proposal);
18
+ if (headerResult.result !== 'accept') {
19
+ return headerResult;
20
+ }
21
+ return this.proposalValidator.validateTxs(proposal);
9
22
  }
10
23
  }
@@ -1,13 +1,29 @@
1
1
  import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
- import type { CheckpointProposal, P2PValidator } from '@aztec/stdlib/p2p';
2
+ import type { CheckpointProposal, P2PValidator, ValidationResult } from '@aztec/stdlib/p2p';
3
3
 
4
4
  import { ProposalValidator } from '../proposal_validator/proposal_validator.js';
5
5
 
6
- export class CheckpointProposalValidator
7
- extends ProposalValidator<CheckpointProposal>
8
- implements P2PValidator<CheckpointProposal>
9
- {
10
- constructor(epochCache: EpochCacheInterface, opts: { txsPermitted: boolean }) {
11
- super(epochCache, opts, 'p2p:checkpoint_proposal_validator');
6
+ export class CheckpointProposalValidator implements P2PValidator<CheckpointProposal> {
7
+ private proposalValidator: ProposalValidator;
8
+
9
+ constructor(
10
+ epochCache: EpochCacheInterface,
11
+ opts: { txsPermitted: boolean; maxTxsPerBlock?: number; p2pPropagationTime?: number },
12
+ ) {
13
+ this.proposalValidator = new ProposalValidator(epochCache, opts, 'p2p:checkpoint_proposal_validator');
14
+ }
15
+
16
+ async validate(proposal: CheckpointProposal): Promise<ValidationResult> {
17
+ const headerResult = await this.proposalValidator.validate(proposal);
18
+ if (headerResult.result !== 'accept') {
19
+ return headerResult;
20
+ }
21
+
22
+ const blockProposal = proposal.getBlockProposal();
23
+ if (blockProposal) {
24
+ return this.proposalValidator.validateTxs(blockProposal);
25
+ }
26
+
27
+ return { result: 'accept' };
12
28
  }
13
29
  }