@aztec/p2p 0.0.0-test.0 → 0.0.1-commit.24de95ac

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 (339) hide show
  1. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  2. package/dest/bootstrap/bootstrap.js +22 -9
  3. package/dest/client/factory.d.ts +13 -3
  4. package/dest/client/factory.d.ts.map +1 -1
  5. package/dest/client/factory.js +60 -24
  6. package/dest/client/index.d.ts +1 -0
  7. package/dest/client/index.d.ts.map +1 -1
  8. package/dest/client/index.js +1 -0
  9. package/dest/client/interface.d.ts +155 -0
  10. package/dest/client/interface.d.ts.map +1 -0
  11. package/dest/client/interface.js +9 -0
  12. package/dest/client/p2p_client.d.ts +72 -169
  13. package/dest/client/p2p_client.d.ts.map +1 -1
  14. package/dest/client/p2p_client.js +365 -174
  15. package/dest/config.d.ts +123 -103
  16. package/dest/config.d.ts.map +1 -1
  17. package/dest/config.js +173 -34
  18. package/dest/enr/generate-enr.d.ts +10 -2
  19. package/dest/enr/generate-enr.d.ts.map +1 -1
  20. package/dest/enr/generate-enr.js +27 -5
  21. package/dest/index.d.ts +3 -0
  22. package/dest/index.d.ts.map +1 -1
  23. package/dest/index.js +2 -0
  24. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +42 -4
  25. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  26. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  27. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +204 -54
  28. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +10 -2
  29. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  30. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +93 -15
  31. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +10 -2
  32. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  33. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +86 -18
  34. package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -2
  35. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  36. package/dest/mem_pools/attestation_pool/mocks.js +9 -15
  37. package/dest/mem_pools/instrumentation.d.ts +7 -11
  38. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  39. package/dest/mem_pools/instrumentation.js +25 -37
  40. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +93 -9
  41. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +469 -97
  43. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +33 -9
  44. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
  45. package/dest/mem_pools/tx_pool/memory_tx_pool.js +133 -36
  46. package/dest/mem_pools/tx_pool/priority.js +1 -1
  47. package/dest/mem_pools/tx_pool/tx_pool.d.ts +64 -8
  48. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  50. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +264 -39
  51. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -0
  52. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  53. package/dest/msg_validators/attestation_validator/attestation_validator.js +45 -9
  54. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +5 -1
  55. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
  56. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +61 -12
  57. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +10 -0
  58. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
  59. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
  60. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +3 -0
  61. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
  62. package/dest/msg_validators/tx_validator/allowed_public_setup.js +27 -0
  63. package/dest/msg_validators/tx_validator/archive_cache.d.ts +14 -0
  64. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -0
  65. package/dest/msg_validators/tx_validator/archive_cache.js +22 -0
  66. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  67. package/dest/msg_validators/tx_validator/block_header_validator.js +4 -4
  68. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  69. package/dest/msg_validators/tx_validator/data_validator.js +56 -86
  70. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +0 -2
  71. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  72. package/dest/msg_validators/tx_validator/double_spend_validator.js +21 -27
  73. package/dest/msg_validators/tx_validator/factory.d.ts +15 -0
  74. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
  75. package/dest/msg_validators/tx_validator/factory.js +74 -0
  76. package/dest/msg_validators/tx_validator/gas_validator.d.ts +11 -0
  77. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
  78. package/dest/msg_validators/tx_validator/gas_validator.js +115 -0
  79. package/dest/msg_validators/tx_validator/index.d.ts +7 -0
  80. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  81. package/dest/msg_validators/tx_validator/index.js +7 -0
  82. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +7 -3
  83. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  84. package/dest/msg_validators/tx_validator/metadata_validator.js +39 -20
  85. package/dest/msg_validators/tx_validator/phases_validator.d.ts +14 -0
  86. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
  87. package/dest/msg_validators/tx_validator/phases_validator.js +91 -0
  88. package/dest/msg_validators/tx_validator/test_utils.d.ts +17 -0
  89. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
  90. package/dest/msg_validators/tx_validator/test_utils.js +22 -0
  91. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +12 -0
  92. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
  93. package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
  94. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +8 -0
  95. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -0
  96. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +24 -0
  97. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  98. package/dest/msg_validators/tx_validator/tx_proof_validator.js +6 -5
  99. package/dest/services/discv5/discV5_service.d.ts +9 -8
  100. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  101. package/dest/services/discv5/discV5_service.js +63 -36
  102. package/dest/services/dummy_service.d.ts +49 -10
  103. package/dest/services/dummy_service.d.ts.map +1 -1
  104. package/dest/services/dummy_service.js +88 -5
  105. package/dest/services/encoding.d.ts +25 -6
  106. package/dest/services/encoding.d.ts.map +1 -1
  107. package/dest/services/encoding.js +73 -5
  108. package/dest/services/index.d.ts +4 -0
  109. package/dest/services/index.d.ts.map +1 -1
  110. package/dest/services/index.js +4 -0
  111. package/dest/services/libp2p/instrumentation.d.ts +18 -0
  112. package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
  113. package/dest/services/libp2p/instrumentation.js +157 -0
  114. package/dest/services/libp2p/libp2p_service.d.ts +87 -42
  115. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  116. package/dest/services/libp2p/libp2p_service.js +500 -218
  117. package/dest/services/peer-manager/interface.d.ts +23 -0
  118. package/dest/services/peer-manager/interface.d.ts.map +1 -0
  119. package/dest/services/peer-manager/interface.js +1 -0
  120. package/dest/services/peer-manager/metrics.d.ts +3 -1
  121. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  122. package/dest/services/peer-manager/metrics.js +11 -2
  123. package/dest/services/peer-manager/peer_manager.d.ts +126 -15
  124. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  125. package/dest/services/peer-manager/peer_manager.js +547 -72
  126. package/dest/services/reqresp/config.d.ts +10 -8
  127. package/dest/services/reqresp/config.d.ts.map +1 -1
  128. package/dest/services/reqresp/config.js +18 -4
  129. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +1 -1
  130. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  131. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +10 -6
  132. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +30 -13
  133. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  134. package/dest/services/reqresp/connection-sampler/connection_sampler.js +142 -84
  135. package/dest/services/reqresp/index.d.ts +2 -1
  136. package/dest/services/reqresp/index.d.ts.map +1 -1
  137. package/dest/services/reqresp/index.js +2 -1
  138. package/dest/services/reqresp/interface.d.ts +72 -23
  139. package/dest/services/reqresp/interface.d.ts.map +1 -1
  140. package/dest/services/reqresp/interface.js +45 -26
  141. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  142. package/dest/services/reqresp/protocols/auth.d.ts +43 -0
  143. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
  144. package/dest/services/reqresp/protocols/auth.js +71 -0
  145. package/dest/services/reqresp/protocols/block.d.ts +5 -0
  146. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  147. package/dest/services/reqresp/protocols/block.js +28 -5
  148. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +30 -0
  149. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
  150. package/dest/services/reqresp/protocols/block_txs/bitvector.js +75 -0
  151. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
  152. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
  153. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +39 -0
  154. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +49 -0
  155. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
  156. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
  157. package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
  158. package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
  159. package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
  160. package/dest/services/reqresp/protocols/goodbye.d.ts +2 -4
  161. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
  162. package/dest/services/reqresp/protocols/goodbye.js +7 -7
  163. package/dest/services/reqresp/protocols/index.d.ts +2 -0
  164. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  165. package/dest/services/reqresp/protocols/index.js +2 -0
  166. package/dest/services/reqresp/protocols/ping.d.ts +0 -2
  167. package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
  168. package/dest/services/reqresp/protocols/status.d.ts +38 -6
  169. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  170. package/dest/services/reqresp/protocols/status.js +72 -5
  171. package/dest/services/reqresp/protocols/tx.d.ts +12 -1
  172. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  173. package/dest/services/reqresp/protocols/tx.js +34 -6
  174. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +4 -2
  175. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  176. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
  177. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  178. package/dest/services/reqresp/rate-limiter/rate_limits.js +21 -1
  179. package/dest/services/reqresp/reqresp.d.ts +45 -47
  180. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  181. package/dest/services/reqresp/reqresp.js +298 -207
  182. package/dest/services/reqresp/status.d.ts +9 -3
  183. package/dest/services/reqresp/status.d.ts.map +1 -1
  184. package/dest/services/reqresp/status.js +9 -2
  185. package/dest/services/service.d.ts +22 -18
  186. package/dest/services/service.d.ts.map +1 -1
  187. package/dest/services/tx_collection/config.d.ts +25 -0
  188. package/dest/services/tx_collection/config.d.ts.map +1 -0
  189. package/dest/services/tx_collection/config.js +58 -0
  190. package/dest/services/tx_collection/fast_tx_collection.d.ts +56 -0
  191. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
  192. package/dest/services/tx_collection/fast_tx_collection.js +300 -0
  193. package/dest/services/tx_collection/index.d.ts +3 -0
  194. package/dest/services/tx_collection/index.d.ts.map +1 -0
  195. package/dest/services/tx_collection/index.js +2 -0
  196. package/dest/services/tx_collection/instrumentation.d.ts +10 -0
  197. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
  198. package/dest/services/tx_collection/instrumentation.js +34 -0
  199. package/dest/services/tx_collection/slow_tx_collection.d.ts +54 -0
  200. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
  201. package/dest/services/tx_collection/slow_tx_collection.js +176 -0
  202. package/dest/services/tx_collection/tx_collection.d.ts +110 -0
  203. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
  204. package/dest/services/tx_collection/tx_collection.js +128 -0
  205. package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
  206. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
  207. package/dest/services/tx_collection/tx_collection_sink.js +111 -0
  208. package/dest/services/tx_collection/tx_source.d.ts +18 -0
  209. package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
  210. package/dest/services/tx_collection/tx_source.js +31 -0
  211. package/dest/services/tx_provider.d.ts +49 -0
  212. package/dest/services/tx_provider.d.ts.map +1 -0
  213. package/dest/services/tx_provider.js +210 -0
  214. package/dest/services/tx_provider_instrumentation.d.ts +13 -0
  215. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
  216. package/dest/services/tx_provider_instrumentation.js +34 -0
  217. package/dest/test-helpers/get-ports.d.ts.map +1 -1
  218. package/dest/test-helpers/index.d.ts +1 -0
  219. package/dest/test-helpers/index.d.ts.map +1 -1
  220. package/dest/test-helpers/index.js +1 -0
  221. package/dest/test-helpers/make-enrs.d.ts.map +1 -1
  222. package/dest/test-helpers/make-enrs.js +4 -5
  223. package/dest/test-helpers/make-test-p2p-clients.d.ts +32 -4
  224. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  225. package/dest/test-helpers/make-test-p2p-clients.js +86 -16
  226. package/dest/test-helpers/mock-pubsub.d.ts +59 -0
  227. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
  228. package/dest/test-helpers/mock-pubsub.js +130 -0
  229. package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
  230. package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
  231. package/dest/test-helpers/mock-tx-helpers.js +19 -0
  232. package/dest/test-helpers/reqresp-nodes.d.ts +14 -10
  233. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  234. package/dest/test-helpers/reqresp-nodes.js +62 -28
  235. package/dest/testbench/p2p_client_testbench_worker.js +96 -25
  236. package/dest/testbench/parse_log_file.js +4 -4
  237. package/dest/testbench/testbench.js +4 -4
  238. package/dest/testbench/worker_client_manager.d.ts +0 -5
  239. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  240. package/dest/testbench/worker_client_manager.js +11 -19
  241. package/dest/types/index.d.ts +3 -1
  242. package/dest/types/index.d.ts.map +1 -1
  243. package/dest/types/index.js +2 -0
  244. package/dest/util.d.ts +22 -15
  245. package/dest/util.d.ts.map +1 -1
  246. package/dest/util.js +64 -67
  247. package/dest/versioning.d.ts +3 -3
  248. package/dest/versioning.d.ts.map +1 -1
  249. package/dest/versioning.js +8 -3
  250. package/package.json +28 -24
  251. package/src/bootstrap/bootstrap.ts +27 -11
  252. package/src/client/factory.ts +136 -45
  253. package/src/client/index.ts +1 -0
  254. package/src/client/interface.ts +195 -0
  255. package/src/client/p2p_client.ts +460 -327
  256. package/src/config.ts +288 -134
  257. package/src/enr/generate-enr.ts +39 -6
  258. package/src/index.ts +4 -0
  259. package/src/mem_pools/attestation_pool/attestation_pool.ts +48 -4
  260. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +241 -55
  261. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +117 -20
  262. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +114 -22
  263. package/src/mem_pools/attestation_pool/mocks.ts +11 -10
  264. package/src/mem_pools/instrumentation.ts +32 -46
  265. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +549 -108
  266. package/src/mem_pools/tx_pool/memory_tx_pool.ts +153 -44
  267. package/src/mem_pools/tx_pool/priority.ts +1 -1
  268. package/src/mem_pools/tx_pool/tx_pool.ts +67 -8
  269. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +217 -34
  270. package/src/msg_validators/attestation_validator/attestation_validator.ts +55 -10
  271. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +66 -14
  272. package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
  273. package/src/msg_validators/tx_validator/allowed_public_setup.ts +35 -0
  274. package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
  275. package/src/msg_validators/tx_validator/block_header_validator.ts +4 -4
  276. package/src/msg_validators/tx_validator/data_validator.ts +81 -69
  277. package/src/msg_validators/tx_validator/double_spend_validator.ts +19 -17
  278. package/src/msg_validators/tx_validator/factory.ts +109 -0
  279. package/src/msg_validators/tx_validator/gas_validator.ts +134 -0
  280. package/src/msg_validators/tx_validator/index.ts +7 -0
  281. package/src/msg_validators/tx_validator/metadata_validator.ts +58 -21
  282. package/src/msg_validators/tx_validator/phases_validator.ts +114 -0
  283. package/src/msg_validators/tx_validator/test_utils.ts +43 -0
  284. package/src/msg_validators/tx_validator/timestamp_validator.ts +46 -0
  285. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +17 -0
  286. package/src/msg_validators/tx_validator/tx_proof_validator.ts +6 -5
  287. package/src/services/discv5/discV5_service.ts +84 -38
  288. package/src/services/dummy_service.ts +147 -9
  289. package/src/services/encoding.ts +80 -5
  290. package/src/services/index.ts +4 -0
  291. package/src/services/libp2p/instrumentation.ts +158 -0
  292. package/src/services/libp2p/libp2p_service.ts +646 -263
  293. package/src/services/peer-manager/interface.ts +29 -0
  294. package/src/services/peer-manager/metrics.ts +16 -1
  295. package/src/services/peer-manager/peer_manager.ts +652 -78
  296. package/src/services/reqresp/config.ts +26 -9
  297. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +12 -6
  298. package/src/services/reqresp/connection-sampler/connection_sampler.ts +148 -95
  299. package/src/services/reqresp/index.ts +2 -0
  300. package/src/services/reqresp/interface.ts +91 -36
  301. package/src/services/reqresp/metrics.ts +4 -1
  302. package/src/services/reqresp/protocols/auth.ts +83 -0
  303. package/src/services/reqresp/protocols/block.ts +24 -3
  304. package/src/services/reqresp/protocols/block_txs/bitvector.ts +90 -0
  305. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +53 -0
  306. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +79 -0
  307. package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
  308. package/src/services/reqresp/protocols/goodbye.ts +9 -7
  309. package/src/services/reqresp/protocols/index.ts +2 -0
  310. package/src/services/reqresp/protocols/status.ts +117 -5
  311. package/src/services/reqresp/protocols/tx.ts +35 -6
  312. package/src/services/reqresp/rate-limiter/rate_limiter.ts +12 -3
  313. package/src/services/reqresp/rate-limiter/rate_limits.ts +21 -1
  314. package/src/services/reqresp/reqresp.ts +387 -256
  315. package/src/services/reqresp/status.ts +12 -3
  316. package/src/services/service.ts +45 -21
  317. package/src/services/tx_collection/config.ts +84 -0
  318. package/src/services/tx_collection/fast_tx_collection.ts +340 -0
  319. package/src/services/tx_collection/index.ts +2 -0
  320. package/src/services/tx_collection/instrumentation.ts +43 -0
  321. package/src/services/tx_collection/slow_tx_collection.ts +232 -0
  322. package/src/services/tx_collection/tx_collection.ts +215 -0
  323. package/src/services/tx_collection/tx_collection_sink.ts +129 -0
  324. package/src/services/tx_collection/tx_source.ts +37 -0
  325. package/src/services/tx_provider.ts +216 -0
  326. package/src/services/tx_provider_instrumentation.ts +44 -0
  327. package/src/test-helpers/index.ts +1 -0
  328. package/src/test-helpers/make-enrs.ts +4 -5
  329. package/src/test-helpers/make-test-p2p-clients.ts +111 -21
  330. package/src/test-helpers/mock-pubsub.ts +188 -0
  331. package/src/test-helpers/mock-tx-helpers.ts +24 -0
  332. package/src/test-helpers/reqresp-nodes.ts +86 -35
  333. package/src/testbench/p2p_client_testbench_worker.ts +145 -22
  334. package/src/testbench/parse_log_file.ts +4 -4
  335. package/src/testbench/testbench.ts +4 -4
  336. package/src/testbench/worker_client_manager.ts +17 -23
  337. package/src/types/index.ts +2 -0
  338. package/src/util.ts +93 -89
  339. package/src/versioning.ts +11 -4
@@ -1,106 +1,118 @@
1
- import { MAX_FR_ARGS_TO_ALL_ENQUEUED_CALLS } from '@aztec/constants';
1
+ import { MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS } from '@aztec/constants';
2
2
  import { createLogger } from '@aztec/foundation/log';
3
- import { Tx, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
3
+ import { computeCalldataHash } from '@aztec/stdlib/hash';
4
+ import {
5
+ TX_ERROR_CALLDATA_COUNT_MISMATCH,
6
+ TX_ERROR_CALLDATA_COUNT_TOO_LARGE,
7
+ TX_ERROR_CONTRACT_CLASS_LOGS,
8
+ TX_ERROR_CONTRACT_CLASS_LOG_COUNT,
9
+ TX_ERROR_CONTRACT_CLASS_LOG_LENGTH,
10
+ TX_ERROR_CONTRACT_CLASS_LOG_SORTING,
11
+ TX_ERROR_INCORRECT_CALLDATA,
12
+ TX_ERROR_INCORRECT_HASH,
13
+ Tx,
14
+ type TxValidationResult,
15
+ type TxValidator,
16
+ } from '@aztec/stdlib/tx';
4
17
 
5
18
  export class DataTxValidator implements TxValidator<Tx> {
6
19
  #log = createLogger('p2p:tx_validator:tx_data');
7
20
 
8
21
  async validateTx(tx: Tx): Promise<TxValidationResult> {
9
- const execRequestRes = this.#hasCorrectExecutionRequests(tx);
10
- // Note: If we ever skip txs here, must change this return statement to account for them.
11
- return (await execRequestRes).result === 'invalid' ? execRequestRes : this.#hasCorrectContractClassLogs(tx);
22
+ const reason =
23
+ (await this.#hasCorrectHash(tx)) ??
24
+ (await this.#hasCorrectCalldata(tx)) ??
25
+ (await this.#hasCorrectContractClassLogs(tx));
26
+ return reason ? { result: 'invalid', reason: [reason] } : { result: 'valid' };
12
27
  }
13
28
 
14
- async #hasCorrectExecutionRequests(tx: Tx): Promise<TxValidationResult> {
15
- const callRequests = [
16
- ...tx.data.getRevertiblePublicCallRequests(),
17
- ...tx.data.getNonRevertiblePublicCallRequests(),
18
- ];
19
- if (callRequests.length !== tx.enqueuedPublicFunctionCalls.length) {
20
- this.#log.warn(
21
- `Rejecting tx ${Tx.getHash(tx)} because of mismatch number of execution requests for public calls. Expected ${
22
- callRequests.length
23
- }. Got ${tx.enqueuedPublicFunctionCalls.length}.`,
29
+ async #hasCorrectHash(tx: Tx): Promise<string | undefined> {
30
+ const expected = await Tx.computeTxHash(tx);
31
+ if (!tx.getTxHash().equals(expected)) {
32
+ const reason = TX_ERROR_INCORRECT_HASH;
33
+ this.#log.verbose(
34
+ `Rejecting tx ${tx.getTxHash().toString()}. Reason: ${reason}. Expected hash ${expected.toString()}. Got ${tx.getTxHash().toString()}.`,
24
35
  );
25
- return { result: 'invalid', reason: ['Wrong number of execution requests for public calls'] };
36
+ return reason;
26
37
  }
38
+ return undefined;
39
+ }
27
40
 
28
- if (tx.getTotalPublicArgsCount() > MAX_FR_ARGS_TO_ALL_ENQUEUED_CALLS) {
29
- this.#log.warn(
30
- `Rejecting tx ${await Tx.getHash(
31
- tx,
32
- )} because the total length of args to public enqueued calls is greater than ${MAX_FR_ARGS_TO_ALL_ENQUEUED_CALLS}`,
41
+ async #hasCorrectCalldata(tx: Tx): Promise<string | undefined> {
42
+ if (tx.publicFunctionCalldata.length !== tx.numberOfPublicCalls()) {
43
+ const reason = TX_ERROR_CALLDATA_COUNT_MISMATCH;
44
+ this.#log.verbose(
45
+ `Rejecting tx ${tx.getTxHash().toString()}. Reason: ${reason}. Expected ${tx.numberOfPublicCalls()}. Got ${
46
+ tx.publicFunctionCalldata.length
47
+ }.`,
33
48
  );
34
- return { result: 'invalid', reason: ['Too many args in total to enqueued public calls'] };
49
+ return reason;
35
50
  }
36
- const invalidExecutionRequestIndex = (
37
- await Promise.all(
38
- tx.enqueuedPublicFunctionCalls.map(
39
- async (execRequest, i) => !(await execRequest.isForCallRequest(callRequests[i])),
40
- ),
41
- )
42
- ).findIndex(Boolean);
43
- if (invalidExecutionRequestIndex !== -1) {
44
- this.#log.warn(
45
- `Rejecting tx ${await Tx.getHash(
46
- tx,
47
- )} because of incorrect execution requests for public call at index ${invalidExecutionRequestIndex}.`,
51
+
52
+ if (tx.getTotalPublicCalldataCount() > MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS) {
53
+ const reason = TX_ERROR_CALLDATA_COUNT_TOO_LARGE;
54
+ this.#log.verbose(
55
+ `Rejecting tx ${tx.getTxHash().toString()}. Reason: ${reason}. Expected no greater than ${MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS} fields. Got ${tx.getTotalPublicCalldataCount()}.`,
48
56
  );
49
- return { result: 'invalid', reason: ['Incorrect execution request for public call'] };
57
+ return reason;
50
58
  }
51
59
 
52
- const teardownCallRequest = tx.data.getTeardownPublicCallRequest();
53
- const isInvalidTeardownExecutionRequest =
54
- (!teardownCallRequest && !tx.publicTeardownFunctionCall.isEmpty()) ||
55
- (teardownCallRequest && !(await tx.publicTeardownFunctionCall.isForCallRequest(teardownCallRequest)));
56
- if (isInvalidTeardownExecutionRequest) {
57
- this.#log.warn(`Rejecting tx ${await Tx.getHash(tx)} because of incorrect teardown execution requests.`);
58
- return { result: 'invalid', reason: ['Incorrect teardown execution request'] };
60
+ const callRequests = tx.getPublicCallRequestsWithCalldata();
61
+ for (let i = 0; i < callRequests.length; i++) {
62
+ const { request, calldata } = callRequests[i];
63
+ const hash = await computeCalldataHash(calldata);
64
+ if (!hash.equals(request.calldataHash)) {
65
+ const reason = TX_ERROR_INCORRECT_CALLDATA;
66
+ this.#log.verbose(`Rejecting tx ${tx.getTxHash().toString()}. Reason: ${reason}. Call request index: ${i}.`);
67
+ return reason;
68
+ }
59
69
  }
60
70
 
61
- return { result: 'valid' };
71
+ return undefined;
62
72
  }
63
73
 
64
- async #hasCorrectContractClassLogs(tx: Tx): Promise<TxValidationResult> {
74
+ async #hasCorrectContractClassLogs(tx: Tx): Promise<string | undefined> {
65
75
  const contractClassLogsHashes = tx.data.getNonEmptyContractClassLogsHashes();
66
- const hashedContractClasslogs = await Promise.all(tx.contractClassLogs.map(l => l.hash()));
67
- if (contractClassLogsHashes.length !== hashedContractClasslogs.length) {
68
- this.#log.warn(
69
- `Rejecting tx ${Tx.getHash(tx)} because of mismatched number of contract class logs. Expected ${
76
+ if (contractClassLogsHashes.length !== tx.contractClassLogFields.length) {
77
+ this.#log.verbose(
78
+ `Rejecting tx ${tx.getTxHash().toString()} because of mismatched number of contract class logs. Expected ${
70
79
  contractClassLogsHashes.length
71
- }. Got ${hashedContractClasslogs.length}.`,
80
+ }. Got ${tx.contractClassLogFields.length}.`,
72
81
  );
73
- return { result: 'invalid', reason: ['Mismatched number of contract class logs'] };
82
+ return TX_ERROR_CONTRACT_CLASS_LOG_COUNT;
74
83
  }
84
+
85
+ const expectedHashes = await Promise.all(tx.contractClassLogFields.map(l => l.hash()));
75
86
  for (const [i, logHash] of contractClassLogsHashes.entries()) {
76
- const hashedLog = hashedContractClasslogs[i];
77
- if (!logHash.value.equals(hashedLog)) {
78
- if (hashedContractClasslogs.some(l => logHash.value.equals(l))) {
79
- const matchingLogIndex = hashedContractClasslogs.findIndex(l => logHash.value.equals(l));
80
- this.#log.warn(
81
- `Rejecting tx ${Tx.getHash(
82
- tx,
83
- )} because of mismatched contract class logs indices. Expected ${i} from the kernel's log hashes. Got ${matchingLogIndex} in the tx.`,
87
+ const hash = expectedHashes[i];
88
+ if (!logHash.value.equals(hash)) {
89
+ if (expectedHashes.some(h => logHash.value.equals(h))) {
90
+ const matchingLogIndex = expectedHashes.findIndex(l => logHash.value.equals(l));
91
+ this.#log.verbose(
92
+ `Rejecting tx ${tx.getTxHash().toString()} because of mismatched contract class logs indices. Expected ${i} from the kernel's log hashes. Got ${matchingLogIndex} in the tx.`,
84
93
  );
85
- return { result: 'invalid', reason: ['Incorrectly sorted contract class logs'] };
94
+ return TX_ERROR_CONTRACT_CLASS_LOG_SORTING;
86
95
  } else {
87
- this.#log.warn(
88
- `Rejecting tx ${Tx.getHash(tx)} because of mismatched contract class logs. Expected hash ${
96
+ this.#log.verbose(
97
+ `Rejecting tx ${tx.getTxHash().toString()} because of mismatched contract class logs. Expected hash ${
89
98
  logHash.value
90
- } from the kernels. Got ${hashedLog} in the tx.`,
99
+ } from the kernels. Got ${hash} in the tx.`,
91
100
  );
92
- return { result: 'invalid', reason: ['Mismatched contract class logs'] };
101
+ return TX_ERROR_CONTRACT_CLASS_LOGS;
93
102
  }
94
103
  }
95
- if (logHash.logHash.length !== tx.contractClassLogs[i].getEmittedLength()) {
96
- this.#log.warn(
97
- `Rejecting tx ${Tx.getHash(tx)} because of mismatched contract class logs length. Expected ${
104
+
105
+ const expectedMinLength = 1 + tx.contractClassLogFields[i].fields.findLastIndex(f => !f.isZero());
106
+ if (logHash.logHash.length < expectedMinLength) {
107
+ this.#log.verbose(
108
+ `Rejecting tx ${tx.getTxHash().toString()} because of incorrect contract class log length. Expected the length to be at least ${expectedMinLength}. Got ${
98
109
  logHash.logHash.length
99
- } from the kernel's log hashes. Got ${tx.contractClassLogs[i].getEmittedLength()} in the tx.`,
110
+ }.`,
100
111
  );
101
- return { result: 'invalid', reason: ['Mismatched contract class logs length'] };
112
+ return TX_ERROR_CONTRACT_CLASS_LOG_LENGTH;
102
113
  }
103
114
  }
104
- return { result: 'valid' };
115
+
116
+ return undefined;
105
117
  }
106
118
  }
@@ -1,5 +1,12 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
- import { type AnyTx, Tx, type TxValidationResult, type TxValidator, hasPublicCalls } from '@aztec/stdlib/tx';
2
+ import {
3
+ type AnyTx,
4
+ TX_ERROR_DUPLICATE_NULLIFIER_IN_TX,
5
+ TX_ERROR_EXISTING_NULLIFIER,
6
+ Tx,
7
+ type TxValidationResult,
8
+ type TxValidator,
9
+ } from '@aztec/stdlib/tx';
3
10
 
4
11
  export interface NullifierSource {
5
12
  nullifiersExist: (nullifiers: Buffer[]) => Promise<boolean[]>;
@@ -14,25 +21,20 @@ export class DoubleSpendTxValidator<T extends AnyTx> implements TxValidator<T> {
14
21
  }
15
22
 
16
23
  async validateTx(tx: T): Promise<TxValidationResult> {
17
- // Don't need to check for duplicate nullifiers if the tx has public calls
18
- // because the AVM will perform merkle insertions as it goes and will fail on
19
- // duplicate nullifier. In fact we CANNOT check here because the nullifiers
20
- // have already been inserted, and so they will exist in nullifierSource.
21
- if (!hasPublicCalls(tx)) {
22
- const nullifiers = tx instanceof Tx ? tx.data.getNonEmptyNullifiers() : tx.txEffect.nullifiers;
24
+ const nullifiers = tx instanceof Tx ? tx.data.getNonEmptyNullifiers() : tx.txEffect.nullifiers;
23
25
 
24
- // Ditch this tx if it has repeated nullifiers
25
- const uniqueNullifiers = new Set(nullifiers);
26
- if (uniqueNullifiers.size !== nullifiers.length) {
27
- this.#log.warn(`Rejecting tx ${await Tx.getHash(tx)} for emitting duplicate nullifiers`);
28
- return { result: 'invalid', reason: ['Duplicate nullifier in tx'] };
29
- }
26
+ // Ditch this tx if it has repeated nullifiers
27
+ const uniqueNullifiers = new Set(nullifiers.map(n => n.toBigInt()));
28
+ if (uniqueNullifiers.size !== nullifiers.length) {
29
+ this.#log.verbose(`Rejecting tx ${'txHash' in tx ? tx.txHash : tx.hash} for emitting duplicate nullifiers`);
30
+ return { result: 'invalid', reason: [TX_ERROR_DUPLICATE_NULLIFIER_IN_TX] };
31
+ }
30
32
 
31
- if ((await this.#nullifierSource.nullifiersExist(nullifiers.map(n => n.toBuffer()))).some(Boolean)) {
32
- this.#log.warn(`Rejecting tx ${await Tx.getHash(tx)} for repeating a nullifier`);
33
- return { result: 'invalid', reason: ['Existing nullifier'] };
34
- }
33
+ if ((await this.#nullifierSource.nullifiersExist(nullifiers.map(n => n.toBuffer()))).some(Boolean)) {
34
+ this.#log.verbose(`Rejecting tx ${'txHash' in tx ? tx.txHash : tx.hash} for repeating a nullifier`);
35
+ return { result: 'invalid', reason: [TX_ERROR_EXISTING_NULLIFIER] };
35
36
  }
37
+
36
38
  return { result: 'valid' };
37
39
  }
38
40
  }
@@ -0,0 +1,109 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
3
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
4
+ import type { ContractDataSource } from '@aztec/stdlib/contract';
5
+ import type { GasFees } from '@aztec/stdlib/gas';
6
+ import type {
7
+ AllowedElement,
8
+ ClientProtocolCircuitVerifier,
9
+ WorldStateSynchronizer,
10
+ } from '@aztec/stdlib/interfaces/server';
11
+ import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
12
+ import { DatabasePublicStateSource, MerkleTreeId } from '@aztec/stdlib/trees';
13
+ import type { Tx, TxValidationResult } from '@aztec/stdlib/tx';
14
+ import type { UInt64 } from '@aztec/stdlib/types';
15
+
16
+ import { ArchiveCache } from './archive_cache.js';
17
+ import { BlockHeaderTxValidator } from './block_header_validator.js';
18
+ import { DataTxValidator } from './data_validator.js';
19
+ import { DoubleSpendTxValidator } from './double_spend_validator.js';
20
+ import { GasTxValidator } from './gas_validator.js';
21
+ import { MetadataTxValidator } from './metadata_validator.js';
22
+ import { PhasesTxValidator } from './phases_validator.js';
23
+ import { TimestampTxValidator } from './timestamp_validator.js';
24
+ import { TxPermittedValidator } from './tx_permitted_validator.js';
25
+ import { TxProofValidator } from './tx_proof_validator.js';
26
+
27
+ export interface MessageValidator {
28
+ validator: {
29
+ validateTx(tx: Tx): Promise<TxValidationResult>;
30
+ };
31
+ severity: PeerErrorSeverity;
32
+ }
33
+
34
+ export function createTxMessageValidators(
35
+ timestamp: UInt64,
36
+ blockNumber: number,
37
+ worldStateSynchronizer: WorldStateSynchronizer,
38
+ gasFees: GasFees,
39
+ l1ChainId: number,
40
+ rollupVersion: number,
41
+ protocolContractsHash: Fr,
42
+ contractDataSource: ContractDataSource,
43
+ proofVerifier: ClientProtocolCircuitVerifier,
44
+ txsPermitted: boolean,
45
+ allowedInSetup: AllowedElement[] = [],
46
+ ): Record<string, MessageValidator>[] {
47
+ const merkleTree = worldStateSynchronizer.getCommitted();
48
+
49
+ return [
50
+ {
51
+ txsPermittedValidator: {
52
+ validator: new TxPermittedValidator(txsPermitted),
53
+ severity: PeerErrorSeverity.MidToleranceError,
54
+ },
55
+ dataValidator: {
56
+ validator: new DataTxValidator(),
57
+ severity: PeerErrorSeverity.HighToleranceError,
58
+ },
59
+ metadataValidator: {
60
+ validator: new MetadataTxValidator({
61
+ l1ChainId: new Fr(l1ChainId),
62
+ rollupVersion: new Fr(rollupVersion),
63
+ protocolContractsHash,
64
+ vkTreeRoot: getVKTreeRoot(),
65
+ }),
66
+ severity: PeerErrorSeverity.HighToleranceError,
67
+ },
68
+ timestampValidator: {
69
+ validator: new TimestampTxValidator<Tx>({
70
+ timestamp,
71
+ blockNumber,
72
+ }),
73
+ severity: PeerErrorSeverity.MidToleranceError,
74
+ },
75
+ doubleSpendValidator: {
76
+ validator: new DoubleSpendTxValidator({
77
+ nullifiersExist: async (nullifiers: Buffer[]) => {
78
+ const merkleTree = worldStateSynchronizer.getCommitted();
79
+ const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
80
+ return indices.map(index => index !== undefined);
81
+ },
82
+ }),
83
+ severity: PeerErrorSeverity.HighToleranceError,
84
+ },
85
+ gasValidator: {
86
+ validator: new GasTxValidator(
87
+ new DatabasePublicStateSource(merkleTree),
88
+ ProtocolContractAddress.FeeJuice,
89
+ gasFees,
90
+ ),
91
+ severity: PeerErrorSeverity.HighToleranceError,
92
+ },
93
+ phasesValidator: {
94
+ validator: new PhasesTxValidator(contractDataSource, allowedInSetup, timestamp),
95
+ severity: PeerErrorSeverity.MidToleranceError,
96
+ },
97
+ blockHeaderValidator: {
98
+ validator: new BlockHeaderTxValidator(new ArchiveCache(merkleTree)),
99
+ severity: PeerErrorSeverity.HighToleranceError,
100
+ },
101
+ },
102
+ {
103
+ proofValidator: {
104
+ validator: new TxProofValidator(proofVerifier),
105
+ severity: PeerErrorSeverity.MidToleranceError,
106
+ },
107
+ },
108
+ ];
109
+ }
@@ -0,0 +1,134 @@
1
+ import { AVM_MAX_PROCESSABLE_L2_GAS, FIXED_DA_GAS, FIXED_L2_GAS } from '@aztec/constants';
2
+ import { createLogger } from '@aztec/foundation/log';
3
+ import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
4
+ import { getCallRequestsWithCalldataByPhase } from '@aztec/simulator/server';
5
+ import { FunctionSelector } from '@aztec/stdlib/abi';
6
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
7
+ import { Gas, GasFees } from '@aztec/stdlib/gas';
8
+ import type { PublicStateSource } from '@aztec/stdlib/trees';
9
+ import {
10
+ TX_ERROR_GAS_LIMIT_TOO_HIGH,
11
+ TX_ERROR_INSUFFICIENT_FEE_PAYER_BALANCE,
12
+ TX_ERROR_INSUFFICIENT_FEE_PER_GAS,
13
+ TX_ERROR_INSUFFICIENT_GAS_LIMIT,
14
+ type Tx,
15
+ TxExecutionPhase,
16
+ type TxValidationResult,
17
+ type TxValidator,
18
+ } from '@aztec/stdlib/tx';
19
+
20
+ export class GasTxValidator implements TxValidator<Tx> {
21
+ #log = createLogger('sequencer:tx_validator:tx_gas');
22
+ #publicDataSource: PublicStateSource;
23
+ #feeJuiceAddress: AztecAddress;
24
+ #gasFees: GasFees;
25
+
26
+ constructor(publicDataSource: PublicStateSource, feeJuiceAddress: AztecAddress, gasFees: GasFees) {
27
+ this.#publicDataSource = publicDataSource;
28
+ this.#feeJuiceAddress = feeJuiceAddress;
29
+ this.#gasFees = gasFees;
30
+ }
31
+
32
+ async validateTx(tx: Tx): Promise<TxValidationResult> {
33
+ const gasLimitValidation = this.#validateGasLimit(tx);
34
+ if (gasLimitValidation.result === 'invalid') {
35
+ return Promise.resolve(gasLimitValidation);
36
+ }
37
+ if (this.#shouldSkip(tx)) {
38
+ return Promise.resolve({ result: 'skipped', reason: [TX_ERROR_INSUFFICIENT_FEE_PER_GAS] });
39
+ }
40
+ return await this.validateTxFee(tx);
41
+ }
42
+
43
+ /**
44
+ * Check whether the tx's max fees are valid for the current block, and skip if not.
45
+ * We skip instead of invalidating since the tx may become eligible later.
46
+ * Note that circuits check max fees even if fee payer is unset, so we
47
+ * keep this validation even if the tx does not pay fees.
48
+ */
49
+ #shouldSkip(tx: Tx): boolean {
50
+ const gasSettings = tx.data.constants.txContext.gasSettings;
51
+
52
+ // Skip the tx if its max fees are not enough for the current block's gas fees.
53
+ const maxFeesPerGas = gasSettings.maxFeesPerGas;
54
+ const notEnoughMaxFees =
55
+ maxFeesPerGas.feePerDaGas < this.#gasFees.feePerDaGas || maxFeesPerGas.feePerL2Gas < this.#gasFees.feePerL2Gas;
56
+
57
+ if (notEnoughMaxFees) {
58
+ this.#log.verbose(`Skipping transaction ${tx.getTxHash().toString()} due to insufficient fee per gas`, {
59
+ txMaxFeesPerGas: maxFeesPerGas.toInspect(),
60
+ currentGasFees: this.#gasFees.toInspect(),
61
+ });
62
+ }
63
+ return notEnoughMaxFees;
64
+ }
65
+
66
+ /**
67
+ * Check whether the tx's gas limit is above the minimum amount.
68
+ */
69
+ #validateGasLimit(tx: Tx): TxValidationResult {
70
+ const gasLimits = tx.data.constants.txContext.gasSettings.gasLimits;
71
+ const minGasLimits = new Gas(FIXED_DA_GAS, FIXED_L2_GAS);
72
+
73
+ if (minGasLimits.gtAny(gasLimits)) {
74
+ this.#log.verbose(`Rejecting transaction due to the gas limit(s) not being above the minimum gas limit`, {
75
+ gasLimits,
76
+ minGasLimits,
77
+ });
78
+ return { result: 'invalid', reason: [TX_ERROR_INSUFFICIENT_GAS_LIMIT] };
79
+ }
80
+
81
+ if (gasLimits.l2Gas > AVM_MAX_PROCESSABLE_L2_GAS) {
82
+ this.#log.verbose(`Rejecting transaction due to the gas limit(s) being higher than the maximum processable gas`, {
83
+ gasLimits,
84
+ minGasLimits,
85
+ });
86
+ return { result: 'invalid', reason: [TX_ERROR_GAS_LIMIT_TOO_HIGH] };
87
+ }
88
+
89
+ return { result: 'valid' };
90
+ }
91
+
92
+ public async validateTxFee(tx: Tx): Promise<TxValidationResult> {
93
+ const feePayer = tx.data.feePayer;
94
+
95
+ // Compute the maximum fee that this tx may pay, based on its gasLimits and maxFeePerGas
96
+ const feeLimit = tx.data.constants.txContext.gasSettings.getFeeLimit();
97
+
98
+ // Read current balance of the feePayer
99
+ const initialBalance = await this.#publicDataSource.storageRead(
100
+ this.#feeJuiceAddress,
101
+ await computeFeePayerBalanceStorageSlot(feePayer),
102
+ );
103
+
104
+ // If there is a claim in this tx that increases the fee payer balance in Fee Juice, add it to balance
105
+ const setupFns = getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.SETUP);
106
+ const increasePublicBalanceSelector = await FunctionSelector.fromSignature(
107
+ '_increase_public_balance((Field),u128)',
108
+ );
109
+
110
+ // Arguments of the claim function call:
111
+ // - args[0]: Amount recipient.
112
+ // - args[1]: Amount being claimed.
113
+ const claimFunctionCall = setupFns.find(
114
+ fn =>
115
+ fn.request.contractAddress.equals(this.#feeJuiceAddress) &&
116
+ fn.request.msgSender.equals(this.#feeJuiceAddress) &&
117
+ fn.calldata.length > 2 &&
118
+ fn.functionSelector.equals(increasePublicBalanceSelector) &&
119
+ fn.args[0].equals(feePayer.toField()) &&
120
+ !fn.request.isStaticCall,
121
+ );
122
+
123
+ const balance = claimFunctionCall ? initialBalance.add(claimFunctionCall.args[1]) : initialBalance;
124
+ if (balance.lt(feeLimit)) {
125
+ this.#log.verbose(`Rejecting transaction due to not enough fee payer balance`, {
126
+ feePayer,
127
+ balance: balance.toBigInt(),
128
+ feeLimit: feeLimit.toBigInt(),
129
+ });
130
+ return { result: 'invalid', reason: [TX_ERROR_INSUFFICIENT_FEE_PAYER_BALANCE] };
131
+ }
132
+ return { result: 'valid' };
133
+ }
134
+ }
@@ -4,3 +4,10 @@ export * from './double_spend_validator.js';
4
4
  export * from './metadata_validator.js';
5
5
  export * from './tx_proof_validator.js';
6
6
  export * from './block_header_validator.js';
7
+ export * from './gas_validator.js';
8
+ export * from './phases_validator.js';
9
+ export * from './test_utils.js';
10
+ export * from './allowed_public_setup.js';
11
+ export * from './archive_cache.js';
12
+ export * from './tx_permitted_validator.js';
13
+ export * from './timestamp_validator.js';
@@ -1,29 +1,49 @@
1
1
  import type { Fr } from '@aztec/foundation/fields';
2
2
  import { createLogger } from '@aztec/foundation/log';
3
- import { type AnyTx, Tx, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
3
+ import {
4
+ type AnyTx,
5
+ TX_ERROR_INCORRECT_L1_CHAIN_ID,
6
+ TX_ERROR_INCORRECT_PROTOCOL_CONTRACTS_HASH,
7
+ TX_ERROR_INCORRECT_ROLLUP_VERSION,
8
+ TX_ERROR_INCORRECT_VK_TREE_ROOT,
9
+ type TxValidationResult,
10
+ type TxValidator,
11
+ } from '@aztec/stdlib/tx';
4
12
 
5
13
  export class MetadataTxValidator<T extends AnyTx> implements TxValidator<T> {
6
14
  #log = createLogger('p2p:tx_validator:tx_metadata');
7
15
 
8
- constructor(private chainId: Fr, private blockNumber: Fr) {}
16
+ constructor(
17
+ private values: {
18
+ l1ChainId: Fr;
19
+ rollupVersion: Fr;
20
+ vkTreeRoot: Fr;
21
+ protocolContractsHash: Fr;
22
+ },
23
+ ) {}
9
24
 
10
- async validateTx(tx: T): Promise<TxValidationResult> {
25
+ validateTx(tx: T): Promise<TxValidationResult> {
11
26
  const errors = [];
12
- if (!(await this.#hasCorrectChainId(tx))) {
13
- errors.push('Incorrect chain id');
27
+ if (!this.#hasCorrectL1ChainId(tx)) {
28
+ errors.push(TX_ERROR_INCORRECT_L1_CHAIN_ID);
14
29
  }
15
- if (!(await this.#isValidForBlockNumber(tx))) {
16
- errors.push('Invalid block number');
30
+ if (!this.#hasCorrectRollupVersion(tx)) {
31
+ errors.push(TX_ERROR_INCORRECT_ROLLUP_VERSION);
17
32
  }
18
- return errors.length > 0 ? { result: 'invalid', reason: errors } : { result: 'valid' };
33
+ if (!this.#hasCorrectVkTreeRoot(tx)) {
34
+ errors.push(TX_ERROR_INCORRECT_VK_TREE_ROOT);
35
+ }
36
+ if (!this.#hasCorrectprotocolContractsHash(tx)) {
37
+ errors.push(TX_ERROR_INCORRECT_PROTOCOL_CONTRACTS_HASH);
38
+ }
39
+ return Promise.resolve(errors.length > 0 ? { result: 'invalid', reason: errors } : { result: 'valid' });
19
40
  }
20
41
 
21
- async #hasCorrectChainId(tx: T): Promise<boolean> {
22
- if (!tx.data.constants.txContext.chainId.equals(this.chainId)) {
23
- this.#log.warn(
24
- `Rejecting tx ${await Tx.getHash(
25
- tx,
26
- )} because of incorrect chain ${tx.data.constants.txContext.chainId.toNumber()} != ${this.chainId.toNumber()}`,
42
+ #hasCorrectVkTreeRoot(tx: T): boolean {
43
+ // This gets implicitly tested in the proof validator, but we can get a much cheaper check here by looking early at the vk.
44
+ if (!tx.data.constants.vkTreeRoot.equals(this.values.vkTreeRoot)) {
45
+ this.#log.verbose(
46
+ `Rejecting tx ${'txHash' in tx ? tx.txHash : tx.hash} because of incorrect vk tree root ${tx.data.constants.vkTreeRoot.toString()} != ${this.values.vkTreeRoot.toString()}`,
27
47
  );
28
48
  return false;
29
49
  } else {
@@ -31,14 +51,31 @@ export class MetadataTxValidator<T extends AnyTx> implements TxValidator<T> {
31
51
  }
32
52
  }
33
53
 
34
- async #isValidForBlockNumber(tx: T): Promise<boolean> {
35
- const maxBlockNumber = tx.data.rollupValidationRequests.maxBlockNumber;
54
+ #hasCorrectprotocolContractsHash(tx: T): boolean {
55
+ if (!tx.data.constants.protocolContractsHash.equals(this.values.protocolContractsHash)) {
56
+ this.#log.verbose(
57
+ `Rejecting tx ${'txHash' in tx ? tx.txHash : tx.hash} because of incorrect protocol contracts hash ${tx.data.constants.protocolContractsHash.toString()} != ${this.values.protocolContractsHash.toString()}`,
58
+ );
59
+ return false;
60
+ }
61
+ return true;
62
+ }
63
+
64
+ #hasCorrectL1ChainId(tx: T): boolean {
65
+ if (!tx.data.constants.txContext.chainId.equals(this.values.l1ChainId)) {
66
+ this.#log.verbose(
67
+ `Rejecting tx ${'txHash' in tx ? tx.txHash : tx.hash} because of incorrect L1 chain ${tx.data.constants.txContext.chainId.toNumber()} != ${this.values.l1ChainId.toNumber()}`,
68
+ );
69
+ return false;
70
+ } else {
71
+ return true;
72
+ }
73
+ }
36
74
 
37
- if (maxBlockNumber.isSome && maxBlockNumber.value < this.blockNumber) {
38
- this.#log.warn(
39
- `Rejecting tx ${await Tx.getHash(tx)} for low max block number. Tx max block number: ${
40
- maxBlockNumber.value
41
- }, current block number: ${this.blockNumber}.`,
75
+ #hasCorrectRollupVersion(tx: T): boolean {
76
+ if (!tx.data.constants.txContext.version.equals(this.values.rollupVersion)) {
77
+ this.#log.verbose(
78
+ `Rejecting tx ${'txHash' in tx ? tx.txHash : tx.hash} because of incorrect rollup version ${tx.data.constants.txContext.version.toNumber()} != ${this.values.rollupVersion.toNumber()}`,
42
79
  );
43
80
  return false;
44
81
  } else {