@aztec/p2p 0.0.0-test.1 → 0.0.1-commit.5476d83

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 (385) hide show
  1. package/dest/bootstrap/bootstrap.d.ts +1 -1
  2. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  3. package/dest/bootstrap/bootstrap.js +22 -9
  4. package/dest/client/factory.d.ts +14 -4
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +60 -24
  7. package/dest/client/index.d.ts +2 -1
  8. package/dest/client/index.d.ts.map +1 -1
  9. package/dest/client/index.js +1 -0
  10. package/dest/client/interface.d.ts +157 -0
  11. package/dest/client/interface.d.ts.map +1 -0
  12. package/dest/client/interface.js +9 -0
  13. package/dest/client/p2p_client.d.ts +72 -187
  14. package/dest/client/p2p_client.d.ts.map +1 -1
  15. package/dest/client/p2p_client.js +373 -177
  16. package/dest/config.d.ts +151 -125
  17. package/dest/config.d.ts.map +1 -1
  18. package/dest/config.js +183 -34
  19. package/dest/enr/generate-enr.d.ts +11 -3
  20. package/dest/enr/generate-enr.d.ts.map +1 -1
  21. package/dest/enr/generate-enr.js +27 -5
  22. package/dest/enr/index.d.ts +1 -1
  23. package/dest/errors/attestation-pool.error.d.ts +7 -0
  24. package/dest/errors/attestation-pool.error.d.ts.map +1 -0
  25. package/dest/errors/attestation-pool.error.js +12 -0
  26. package/dest/errors/reqresp.error.d.ts +1 -1
  27. package/dest/errors/reqresp.error.d.ts.map +1 -1
  28. package/dest/index.d.ts +4 -1
  29. package/dest/index.d.ts.map +1 -1
  30. package/dest/index.js +2 -0
  31. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +68 -8
  32. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  33. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  34. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  35. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +214 -63
  36. package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
  37. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +21 -6
  38. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  39. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +126 -25
  40. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +19 -6
  41. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  42. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +111 -21
  43. package/dest/mem_pools/attestation_pool/mocks.d.ts +225 -5
  44. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  45. package/dest/mem_pools/attestation_pool/mocks.js +9 -15
  46. package/dest/mem_pools/index.d.ts +1 -1
  47. package/dest/mem_pools/instrumentation.d.ts +10 -12
  48. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  49. package/dest/mem_pools/instrumentation.js +35 -38
  50. package/dest/mem_pools/interface.d.ts +1 -1
  51. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +62 -13
  52. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  53. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +469 -97
  54. package/dest/mem_pools/tx_pool/index.d.ts +1 -1
  55. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +34 -10
  56. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
  57. package/dest/mem_pools/tx_pool/memory_tx_pool.js +133 -36
  58. package/dest/mem_pools/tx_pool/priority.d.ts +1 -1
  59. package/dest/mem_pools/tx_pool/priority.js +1 -1
  60. package/dest/mem_pools/tx_pool/tx_pool.d.ts +65 -9
  61. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  62. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  63. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  64. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +264 -39
  65. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -2
  66. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  67. package/dest/msg_validators/attestation_validator/attestation_validator.js +45 -9
  68. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
  69. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
  70. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +67 -0
  71. package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
  72. package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
  73. package/dest/msg_validators/attestation_validator/index.js +1 -0
  74. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +6 -2
  75. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
  76. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +73 -12
  77. package/dest/msg_validators/block_proposal_validator/index.d.ts +1 -1
  78. package/dest/msg_validators/index.d.ts +1 -1
  79. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +10 -0
  80. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
  81. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
  82. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
  83. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  84. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +3 -0
  85. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
  86. package/dest/msg_validators/tx_validator/allowed_public_setup.js +27 -0
  87. package/dest/msg_validators/tx_validator/archive_cache.d.ts +14 -0
  88. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -0
  89. package/dest/msg_validators/tx_validator/archive_cache.js +22 -0
  90. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +1 -1
  91. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  92. package/dest/msg_validators/tx_validator/block_header_validator.js +4 -4
  93. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  94. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  95. package/dest/msg_validators/tx_validator/data_validator.js +56 -86
  96. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +1 -3
  97. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  98. package/dest/msg_validators/tx_validator/double_spend_validator.js +21 -27
  99. package/dest/msg_validators/tx_validator/factory.d.ts +15 -0
  100. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
  101. package/dest/msg_validators/tx_validator/factory.js +74 -0
  102. package/dest/msg_validators/tx_validator/gas_validator.d.ts +11 -0
  103. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
  104. package/dest/msg_validators/tx_validator/gas_validator.js +115 -0
  105. package/dest/msg_validators/tx_validator/index.d.ts +8 -1
  106. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  107. package/dest/msg_validators/tx_validator/index.js +7 -0
  108. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +8 -4
  109. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  110. package/dest/msg_validators/tx_validator/metadata_validator.js +39 -20
  111. package/dest/msg_validators/tx_validator/phases_validator.d.ts +14 -0
  112. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
  113. package/dest/msg_validators/tx_validator/phases_validator.js +93 -0
  114. package/dest/msg_validators/tx_validator/test_utils.d.ts +17 -0
  115. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
  116. package/dest/msg_validators/tx_validator/test_utils.js +22 -0
  117. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +12 -0
  118. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
  119. package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
  120. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +8 -0
  121. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -0
  122. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +24 -0
  123. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +1 -1
  124. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  125. package/dest/msg_validators/tx_validator/tx_proof_validator.js +6 -5
  126. package/dest/services/data_store.d.ts +1 -1
  127. package/dest/services/data_store.d.ts.map +1 -1
  128. package/dest/services/discv5/discV5_service.d.ts +10 -9
  129. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  130. package/dest/services/discv5/discV5_service.js +63 -36
  131. package/dest/services/dummy_service.d.ts +50 -11
  132. package/dest/services/dummy_service.d.ts.map +1 -1
  133. package/dest/services/dummy_service.js +88 -5
  134. package/dest/services/encoding.d.ts +26 -7
  135. package/dest/services/encoding.d.ts.map +1 -1
  136. package/dest/services/encoding.js +73 -5
  137. package/dest/services/gossipsub/scoring.d.ts +1 -1
  138. package/dest/services/index.d.ts +5 -1
  139. package/dest/services/index.d.ts.map +1 -1
  140. package/dest/services/index.js +4 -0
  141. package/dest/services/libp2p/instrumentation.d.ts +20 -0
  142. package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
  143. package/dest/services/libp2p/instrumentation.js +164 -0
  144. package/dest/services/libp2p/libp2p_service.d.ts +78 -89
  145. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  146. package/dest/services/libp2p/libp2p_service.js +698 -246
  147. package/dest/services/peer-manager/interface.d.ts +23 -0
  148. package/dest/services/peer-manager/interface.d.ts.map +1 -0
  149. package/dest/services/peer-manager/interface.js +1 -0
  150. package/dest/services/peer-manager/metrics.d.ts +6 -2
  151. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  152. package/dest/services/peer-manager/metrics.js +22 -2
  153. package/dest/services/peer-manager/peer_manager.d.ts +102 -22
  154. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  155. package/dest/services/peer-manager/peer_manager.js +549 -72
  156. package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
  157. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  158. package/dest/services/peer-manager/peer_scoring.js +40 -2
  159. package/dest/services/reqresp/config.d.ts +11 -9
  160. package/dest/services/reqresp/config.d.ts.map +1 -1
  161. package/dest/services/reqresp/config.js +18 -4
  162. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +2 -2
  163. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  164. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +10 -6
  165. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +31 -17
  166. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  167. package/dest/services/reqresp/connection-sampler/connection_sampler.js +142 -84
  168. package/dest/services/reqresp/index.d.ts +3 -2
  169. package/dest/services/reqresp/index.d.ts.map +1 -1
  170. package/dest/services/reqresp/index.js +2 -1
  171. package/dest/services/reqresp/interface.d.ts +73 -24
  172. package/dest/services/reqresp/interface.d.ts.map +1 -1
  173. package/dest/services/reqresp/interface.js +45 -26
  174. package/dest/services/reqresp/metrics.d.ts +1 -1
  175. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  176. package/dest/services/reqresp/protocols/auth.d.ts +43 -0
  177. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
  178. package/dest/services/reqresp/protocols/auth.js +71 -0
  179. package/dest/services/reqresp/protocols/block.d.ts +6 -1
  180. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  181. package/dest/services/reqresp/protocols/block.js +28 -5
  182. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +30 -0
  183. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
  184. package/dest/services/reqresp/protocols/block_txs/bitvector.js +75 -0
  185. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
  186. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
  187. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +39 -0
  188. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +47 -0
  189. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
  190. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
  191. package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
  192. package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
  193. package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
  194. package/dest/services/reqresp/protocols/goodbye.d.ts +3 -5
  195. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
  196. package/dest/services/reqresp/protocols/goodbye.js +7 -7
  197. package/dest/services/reqresp/protocols/index.d.ts +3 -1
  198. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  199. package/dest/services/reqresp/protocols/index.js +2 -0
  200. package/dest/services/reqresp/protocols/ping.d.ts +1 -3
  201. package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
  202. package/dest/services/reqresp/protocols/status.d.ts +39 -7
  203. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  204. package/dest/services/reqresp/protocols/status.js +72 -5
  205. package/dest/services/reqresp/protocols/tx.d.ts +13 -2
  206. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  207. package/dest/services/reqresp/protocols/tx.js +34 -6
  208. package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
  209. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +6 -4
  210. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  211. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
  212. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  213. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  214. package/dest/services/reqresp/rate-limiter/rate_limits.js +21 -1
  215. package/dest/services/reqresp/reqresp.d.ts +24 -66
  216. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  217. package/dest/services/reqresp/reqresp.js +298 -207
  218. package/dest/services/reqresp/status.d.ts +10 -4
  219. package/dest/services/reqresp/status.d.ts.map +1 -1
  220. package/dest/services/reqresp/status.js +9 -2
  221. package/dest/services/service.d.ts +23 -19
  222. package/dest/services/service.d.ts.map +1 -1
  223. package/dest/services/tx_collection/config.d.ts +25 -0
  224. package/dest/services/tx_collection/config.d.ts.map +1 -0
  225. package/dest/services/tx_collection/config.js +58 -0
  226. package/dest/services/tx_collection/fast_tx_collection.d.ts +50 -0
  227. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
  228. package/dest/services/tx_collection/fast_tx_collection.js +300 -0
  229. package/dest/services/tx_collection/index.d.ts +3 -0
  230. package/dest/services/tx_collection/index.d.ts.map +1 -0
  231. package/dest/services/tx_collection/index.js +2 -0
  232. package/dest/services/tx_collection/instrumentation.d.ts +10 -0
  233. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
  234. package/dest/services/tx_collection/instrumentation.js +34 -0
  235. package/dest/services/tx_collection/slow_tx_collection.d.ts +52 -0
  236. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
  237. package/dest/services/tx_collection/slow_tx_collection.js +177 -0
  238. package/dest/services/tx_collection/tx_collection.d.ts +109 -0
  239. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
  240. package/dest/services/tx_collection/tx_collection.js +128 -0
  241. package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
  242. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
  243. package/dest/services/tx_collection/tx_collection_sink.js +111 -0
  244. package/dest/services/tx_collection/tx_source.d.ts +18 -0
  245. package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
  246. package/dest/services/tx_collection/tx_source.js +31 -0
  247. package/dest/services/tx_provider.d.ts +49 -0
  248. package/dest/services/tx_provider.d.ts.map +1 -0
  249. package/dest/services/tx_provider.js +210 -0
  250. package/dest/services/tx_provider_instrumentation.d.ts +13 -0
  251. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
  252. package/dest/services/tx_provider_instrumentation.js +34 -0
  253. package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
  254. package/dest/test-helpers/get-ports.d.ts +1 -1
  255. package/dest/test-helpers/get-ports.d.ts.map +1 -1
  256. package/dest/test-helpers/index.d.ts +2 -1
  257. package/dest/test-helpers/index.d.ts.map +1 -1
  258. package/dest/test-helpers/index.js +1 -0
  259. package/dest/test-helpers/make-enrs.d.ts +1 -1
  260. package/dest/test-helpers/make-enrs.d.ts.map +1 -1
  261. package/dest/test-helpers/make-enrs.js +4 -5
  262. package/dest/test-helpers/make-test-p2p-clients.d.ts +33 -5
  263. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  264. package/dest/test-helpers/make-test-p2p-clients.js +86 -16
  265. package/dest/test-helpers/mock-pubsub.d.ts +59 -0
  266. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
  267. package/dest/test-helpers/mock-pubsub.js +130 -0
  268. package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
  269. package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
  270. package/dest/test-helpers/mock-tx-helpers.js +19 -0
  271. package/dest/test-helpers/reqresp-nodes.d.ts +15 -11
  272. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  273. package/dest/test-helpers/reqresp-nodes.js +62 -28
  274. package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
  275. package/dest/testbench/p2p_client_testbench_worker.js +103 -29
  276. package/dest/testbench/parse_log_file.d.ts +1 -1
  277. package/dest/testbench/parse_log_file.js +4 -4
  278. package/dest/testbench/testbench.d.ts +1 -1
  279. package/dest/testbench/testbench.js +4 -4
  280. package/dest/testbench/worker_client_manager.d.ts +1 -6
  281. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  282. package/dest/testbench/worker_client_manager.js +11 -19
  283. package/dest/types/index.d.ts +4 -2
  284. package/dest/types/index.d.ts.map +1 -1
  285. package/dest/types/index.js +2 -0
  286. package/dest/util.d.ts +24 -16
  287. package/dest/util.d.ts.map +1 -1
  288. package/dest/util.js +75 -69
  289. package/dest/versioning.d.ts +4 -4
  290. package/dest/versioning.d.ts.map +1 -1
  291. package/dest/versioning.js +8 -3
  292. package/package.json +32 -27
  293. package/src/bootstrap/bootstrap.ts +27 -11
  294. package/src/client/factory.ts +136 -45
  295. package/src/client/index.ts +1 -0
  296. package/src/client/interface.ts +198 -0
  297. package/src/client/p2p_client.ts +469 -330
  298. package/src/config.ts +305 -134
  299. package/src/enr/generate-enr.ts +39 -6
  300. package/src/errors/attestation-pool.error.ts +13 -0
  301. package/src/index.ts +4 -0
  302. package/src/mem_pools/attestation_pool/attestation_pool.ts +75 -7
  303. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +264 -65
  304. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +173 -34
  305. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +156 -30
  306. package/src/mem_pools/attestation_pool/mocks.ts +11 -10
  307. package/src/mem_pools/instrumentation.ts +43 -44
  308. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +549 -108
  309. package/src/mem_pools/tx_pool/memory_tx_pool.ts +153 -44
  310. package/src/mem_pools/tx_pool/priority.ts +1 -1
  311. package/src/mem_pools/tx_pool/tx_pool.ts +67 -8
  312. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +217 -34
  313. package/src/msg_validators/attestation_validator/attestation_validator.ts +54 -11
  314. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +91 -0
  315. package/src/msg_validators/attestation_validator/index.ts +1 -0
  316. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +82 -14
  317. package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
  318. package/src/msg_validators/tx_validator/allowed_public_setup.ts +35 -0
  319. package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
  320. package/src/msg_validators/tx_validator/block_header_validator.ts +4 -4
  321. package/src/msg_validators/tx_validator/data_validator.ts +81 -69
  322. package/src/msg_validators/tx_validator/double_spend_validator.ts +19 -17
  323. package/src/msg_validators/tx_validator/factory.ts +109 -0
  324. package/src/msg_validators/tx_validator/gas_validator.ts +134 -0
  325. package/src/msg_validators/tx_validator/index.ts +7 -0
  326. package/src/msg_validators/tx_validator/metadata_validator.ts +58 -21
  327. package/src/msg_validators/tx_validator/phases_validator.ts +116 -0
  328. package/src/msg_validators/tx_validator/test_utils.ts +43 -0
  329. package/src/msg_validators/tx_validator/timestamp_validator.ts +46 -0
  330. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +17 -0
  331. package/src/msg_validators/tx_validator/tx_proof_validator.ts +6 -5
  332. package/src/services/discv5/discV5_service.ts +84 -38
  333. package/src/services/dummy_service.ts +147 -9
  334. package/src/services/encoding.ts +80 -5
  335. package/src/services/index.ts +4 -0
  336. package/src/services/libp2p/instrumentation.ts +167 -0
  337. package/src/services/libp2p/libp2p_service.ts +866 -294
  338. package/src/services/peer-manager/interface.ts +29 -0
  339. package/src/services/peer-manager/metrics.ts +26 -1
  340. package/src/services/peer-manager/peer_manager.ts +654 -78
  341. package/src/services/peer-manager/peer_scoring.ts +46 -3
  342. package/src/services/reqresp/config.ts +26 -9
  343. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +12 -6
  344. package/src/services/reqresp/connection-sampler/connection_sampler.ts +148 -95
  345. package/src/services/reqresp/index.ts +2 -0
  346. package/src/services/reqresp/interface.ts +91 -36
  347. package/src/services/reqresp/metrics.ts +4 -1
  348. package/src/services/reqresp/protocols/auth.ts +83 -0
  349. package/src/services/reqresp/protocols/block.ts +24 -3
  350. package/src/services/reqresp/protocols/block_txs/bitvector.ts +90 -0
  351. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +53 -0
  352. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +79 -0
  353. package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
  354. package/src/services/reqresp/protocols/goodbye.ts +9 -7
  355. package/src/services/reqresp/protocols/index.ts +2 -0
  356. package/src/services/reqresp/protocols/status.ts +117 -5
  357. package/src/services/reqresp/protocols/tx.ts +35 -6
  358. package/src/services/reqresp/rate-limiter/rate_limiter.ts +12 -3
  359. package/src/services/reqresp/rate-limiter/rate_limits.ts +21 -1
  360. package/src/services/reqresp/reqresp.ts +387 -256
  361. package/src/services/reqresp/status.ts +12 -3
  362. package/src/services/service.ts +45 -21
  363. package/src/services/tx_collection/config.ts +84 -0
  364. package/src/services/tx_collection/fast_tx_collection.ts +340 -0
  365. package/src/services/tx_collection/index.ts +2 -0
  366. package/src/services/tx_collection/instrumentation.ts +43 -0
  367. package/src/services/tx_collection/slow_tx_collection.ts +233 -0
  368. package/src/services/tx_collection/tx_collection.ts +215 -0
  369. package/src/services/tx_collection/tx_collection_sink.ts +129 -0
  370. package/src/services/tx_collection/tx_source.ts +37 -0
  371. package/src/services/tx_provider.ts +216 -0
  372. package/src/services/tx_provider_instrumentation.ts +44 -0
  373. package/src/test-helpers/index.ts +1 -0
  374. package/src/test-helpers/make-enrs.ts +4 -5
  375. package/src/test-helpers/make-test-p2p-clients.ts +111 -21
  376. package/src/test-helpers/mock-pubsub.ts +188 -0
  377. package/src/test-helpers/mock-tx-helpers.ts +24 -0
  378. package/src/test-helpers/reqresp-nodes.ts +86 -35
  379. package/src/testbench/p2p_client_testbench_worker.ts +151 -25
  380. package/src/testbench/parse_log_file.ts +4 -4
  381. package/src/testbench/testbench.ts +4 -4
  382. package/src/testbench/worker_client_manager.ts +17 -23
  383. package/src/types/index.ts +2 -0
  384. package/src/util.ts +105 -91
  385. package/src/versioning.ts +11 -4
@@ -0,0 +1,35 @@
1
+ import { FPCContract } from '@aztec/noir-contracts.js/FPC';
2
+ import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
3
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
4
+ import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
5
+ import type { AllowedElement } from '@aztec/stdlib/interfaces/server';
6
+
7
+ let defaultAllowedSetupFunctions: AllowedElement[] | undefined = undefined;
8
+ export async function getDefaultAllowedSetupFunctions(): Promise<AllowedElement[]> {
9
+ if (defaultAllowedSetupFunctions === undefined) {
10
+ defaultAllowedSetupFunctions = [
11
+ // needed for authwit support
12
+ {
13
+ address: ProtocolContractAddress.AuthRegistry,
14
+ },
15
+ // needed for claiming on the same tx as a spend
16
+ {
17
+ address: ProtocolContractAddress.FeeJuice,
18
+ // We can't restrict the selector because public functions get routed via dispatch.
19
+ // selector: FunctionSelector.fromSignature('_increase_public_balance((Field),u128)'),
20
+ },
21
+ // needed for private transfers via FPC
22
+ {
23
+ classId: (await getContractClassFromArtifact(TokenContractArtifact)).id,
24
+ // We can't restrict the selector because public functions get routed via dispatch.
25
+ // selector: FunctionSelector.fromSignature('_increase_public_balance((Field),u128)'),
26
+ },
27
+ {
28
+ classId: (await getContractClassFromArtifact(FPCContract.artifact)).id,
29
+ // We can't restrict the selector because public functions get routed via dispatch.
30
+ // selector: FunctionSelector.fromSignature('prepare_fee((Field),Field,(Field),Field)'),
31
+ },
32
+ ];
33
+ }
34
+ return defaultAllowedSetupFunctions;
35
+ }
@@ -0,0 +1,28 @@
1
+ import type { Fr } from '@aztec/foundation/fields';
2
+ import type { ArchiveSource } from '@aztec/p2p';
3
+ import type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
4
+ import { MerkleTreeId } from '@aztec/stdlib/trees';
5
+
6
+ /**
7
+ * Implements an archive source by checking a DB and an in-memory collection.
8
+ * Intended for validating transactions as they are added to a block.
9
+ */
10
+ export class ArchiveCache implements ArchiveSource {
11
+ archives: Map<string, bigint>;
12
+
13
+ constructor(private db: MerkleTreeReadOperations) {
14
+ this.archives = new Map<string, bigint>();
15
+ }
16
+
17
+ public async getArchiveIndices(archives: Fr[]): Promise<(bigint | undefined)[]> {
18
+ const toCheckDb = archives.filter(n => !this.archives.has(n.toString()));
19
+ const dbHits = await this.db.findLeafIndices(MerkleTreeId.ARCHIVE, toCheckDb);
20
+ dbHits.forEach((x, index) => {
21
+ if (x !== undefined) {
22
+ this.archives.set(toCheckDb[index].toString(), x);
23
+ }
24
+ });
25
+
26
+ return archives.map(n => this.archives.get(n.toString()));
27
+ }
28
+ }
@@ -1,6 +1,6 @@
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 { type AnyTx, TX_ERROR_BLOCK_HEADER, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
4
4
 
5
5
  export interface ArchiveSource {
6
6
  getArchiveIndices: (archives: Fr[]) => Promise<(bigint | undefined)[]>;
@@ -15,10 +15,10 @@ export class BlockHeaderTxValidator<T extends AnyTx> implements TxValidator<T> {
15
15
  }
16
16
 
17
17
  async validateTx(tx: T): Promise<TxValidationResult> {
18
- const [index] = await this.#archiveSource.getArchiveIndices([await tx.data.constants.historicalHeader.hash()]);
18
+ const [index] = await this.#archiveSource.getArchiveIndices([await tx.data.constants.anchorBlockHeader.hash()]);
19
19
  if (index === undefined) {
20
- this.#log.warn(`Rejecting tx ${await Tx.getHash(tx)} for referencing an unknown block header`);
21
- return { result: 'invalid', reason: ['Block header not found'] };
20
+ this.#log.verbose(`Rejecting tx ${'txHash' in tx ? tx.txHash : tx.hash} for referencing an unknown block header`);
21
+ return { result: 'invalid', reason: [TX_ERROR_BLOCK_HEADER] };
22
22
  }
23
23
  return { result: 'valid' };
24
24
  }
@@ -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';