@aztec/p2p 0.0.0-test.0

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 (311) hide show
  1. package/README.md +7 -0
  2. package/dest/bootstrap/bootstrap.d.ts +38 -0
  3. package/dest/bootstrap/bootstrap.d.ts.map +1 -0
  4. package/dest/bootstrap/bootstrap.js +123 -0
  5. package/dest/client/factory.d.ts +21 -0
  6. package/dest/client/factory.d.ts.map +1 -0
  7. package/dest/client/factory.js +37 -0
  8. package/dest/client/index.d.ts +3 -0
  9. package/dest/client/index.d.ts.map +1 -0
  10. package/dest/client/index.js +2 -0
  11. package/dest/client/p2p_client.d.ts +314 -0
  12. package/dest/client/p2p_client.d.ts.map +1 -0
  13. package/dest/client/p2p_client.js +505 -0
  14. package/dest/config.d.ts +180 -0
  15. package/dest/config.d.ts.map +1 -0
  16. package/dest/config.js +193 -0
  17. package/dest/enr/generate-enr.d.ts +9 -0
  18. package/dest/enr/generate-enr.d.ts.map +1 -0
  19. package/dest/enr/generate-enr.js +30 -0
  20. package/dest/enr/index.d.ts +2 -0
  21. package/dest/enr/index.d.ts.map +1 -0
  22. package/dest/enr/index.js +1 -0
  23. package/dest/errors/reqresp.error.d.ts +28 -0
  24. package/dest/errors/reqresp.error.d.ts.map +1 -0
  25. package/dest/errors/reqresp.error.js +30 -0
  26. package/dest/index.d.ts +8 -0
  27. package/dest/index.d.ts.map +1 -0
  28. package/dest/index.js +7 -0
  29. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +57 -0
  30. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -0
  31. package/dest/mem_pools/attestation_pool/attestation_pool.js +6 -0
  32. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +3 -0
  33. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -0
  34. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +195 -0
  35. package/dest/mem_pools/attestation_pool/index.d.ts +3 -0
  36. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -0
  37. package/dest/mem_pools/attestation_pool/index.js +2 -0
  38. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +22 -0
  39. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -0
  40. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +112 -0
  41. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +17 -0
  42. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -0
  43. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +129 -0
  44. package/dest/mem_pools/attestation_pool/mocks.d.ts +19 -0
  45. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -0
  46. package/dest/mem_pools/attestation_pool/mocks.js +33 -0
  47. package/dest/mem_pools/index.d.ts +4 -0
  48. package/dest/mem_pools/index.d.ts.map +1 -0
  49. package/dest/mem_pools/index.js +1 -0
  50. package/dest/mem_pools/instrumentation.d.ts +30 -0
  51. package/dest/mem_pools/instrumentation.d.ts.map +1 -0
  52. package/dest/mem_pools/instrumentation.js +84 -0
  53. package/dest/mem_pools/interface.d.ts +11 -0
  54. package/dest/mem_pools/interface.d.ts.map +1 -0
  55. package/dest/mem_pools/interface.js +3 -0
  56. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +66 -0
  57. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -0
  58. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +245 -0
  59. package/dest/mem_pools/tx_pool/index.d.ts +4 -0
  60. package/dest/mem_pools/tx_pool/index.d.ts.map +1 -0
  61. package/dest/mem_pools/tx_pool/index.js +3 -0
  62. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +56 -0
  63. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -0
  64. package/dest/mem_pools/tx_pool/memory_tx_pool.js +141 -0
  65. package/dest/mem_pools/tx_pool/priority.d.ts +8 -0
  66. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -0
  67. package/dest/mem_pools/tx_pool/priority.js +10 -0
  68. package/dest/mem_pools/tx_pool/tx_pool.d.ts +66 -0
  69. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -0
  70. package/dest/mem_pools/tx_pool/tx_pool.js +3 -0
  71. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +7 -0
  72. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -0
  73. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +169 -0
  74. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +8 -0
  75. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -0
  76. package/dest/msg_validators/attestation_validator/attestation_validator.js +19 -0
  77. package/dest/msg_validators/attestation_validator/index.d.ts +2 -0
  78. package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -0
  79. package/dest/msg_validators/attestation_validator/index.js +1 -0
  80. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +8 -0
  81. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -0
  82. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +21 -0
  83. package/dest/msg_validators/block_proposal_validator/index.d.ts +2 -0
  84. package/dest/msg_validators/block_proposal_validator/index.d.ts.map +1 -0
  85. package/dest/msg_validators/block_proposal_validator/index.js +1 -0
  86. package/dest/msg_validators/index.d.ts +4 -0
  87. package/dest/msg_validators/index.d.ts.map +1 -0
  88. package/dest/msg_validators/index.js +3 -0
  89. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +7 -0
  90. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -0
  91. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +31 -0
  92. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +11 -0
  93. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -0
  94. package/dest/msg_validators/tx_validator/block_header_validator.js +26 -0
  95. package/dest/msg_validators/tx_validator/data_validator.d.ts +6 -0
  96. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -0
  97. package/dest/msg_validators/tx_validator/data_validator.js +107 -0
  98. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +12 -0
  99. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -0
  100. package/dest/msg_validators/tx_validator/double_spend_validator.js +41 -0
  101. package/dest/msg_validators/tx_validator/index.d.ts +7 -0
  102. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -0
  103. package/dest/msg_validators/tx_validator/index.js +6 -0
  104. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +10 -0
  105. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -0
  106. package/dest/msg_validators/tx_validator/metadata_validator.js +44 -0
  107. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +9 -0
  108. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -0
  109. package/dest/msg_validators/tx_validator/tx_proof_validator.js +25 -0
  110. package/dest/services/data_store.d.ts +27 -0
  111. package/dest/services/data_store.d.ts.map +1 -0
  112. package/dest/services/data_store.js +188 -0
  113. package/dest/services/discv5/discV5_service.d.ts +42 -0
  114. package/dest/services/discv5/discV5_service.d.ts.map +1 -0
  115. package/dest/services/discv5/discV5_service.js +214 -0
  116. package/dest/services/dummy_service.d.ts +85 -0
  117. package/dest/services/dummy_service.d.ts.map +1 -0
  118. package/dest/services/dummy_service.js +92 -0
  119. package/dest/services/encoding.d.ts +31 -0
  120. package/dest/services/encoding.d.ts.map +1 -0
  121. package/dest/services/encoding.js +66 -0
  122. package/dest/services/gossipsub/scoring.d.ts +7 -0
  123. package/dest/services/gossipsub/scoring.d.ts.map +1 -0
  124. package/dest/services/gossipsub/scoring.js +10 -0
  125. package/dest/services/index.d.ts +3 -0
  126. package/dest/services/index.d.ts.map +1 -0
  127. package/dest/services/index.js +2 -0
  128. package/dest/services/libp2p/libp2p_service.d.ts +186 -0
  129. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -0
  130. package/dest/services/libp2p/libp2p_service.js +712 -0
  131. package/dest/services/peer-manager/metrics.d.ts +12 -0
  132. package/dest/services/peer-manager/metrics.d.ts.map +1 -0
  133. package/dest/services/peer-manager/metrics.js +33 -0
  134. package/dest/services/peer-manager/peer_manager.d.ts +94 -0
  135. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -0
  136. package/dest/services/peer-manager/peer_manager.js +445 -0
  137. package/dest/services/peer-manager/peer_scoring.d.ts +28 -0
  138. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -0
  139. package/dest/services/peer-manager/peer_scoring.js +86 -0
  140. package/dest/services/reqresp/config.d.ts +16 -0
  141. package/dest/services/reqresp/config.d.ts.map +1 -0
  142. package/dest/services/reqresp/config.js +20 -0
  143. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +45 -0
  144. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -0
  145. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +88 -0
  146. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +61 -0
  147. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -0
  148. package/dest/services/reqresp/connection-sampler/connection_sampler.js +181 -0
  149. package/dest/services/reqresp/index.d.ts +6 -0
  150. package/dest/services/reqresp/index.d.ts.map +1 -0
  151. package/dest/services/reqresp/index.js +4 -0
  152. package/dest/services/reqresp/interface.d.ts +116 -0
  153. package/dest/services/reqresp/interface.d.ts.map +1 -0
  154. package/dest/services/reqresp/interface.js +84 -0
  155. package/dest/services/reqresp/metrics.d.ts +15 -0
  156. package/dest/services/reqresp/metrics.d.ts.map +1 -0
  157. package/dest/services/reqresp/metrics.js +55 -0
  158. package/dest/services/reqresp/protocols/block.d.ts +4 -0
  159. package/dest/services/reqresp/protocols/block.d.ts.map +1 -0
  160. package/dest/services/reqresp/protocols/block.js +8 -0
  161. package/dest/services/reqresp/protocols/goodbye.d.ts +51 -0
  162. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -0
  163. package/dest/services/reqresp/protocols/goodbye.js +87 -0
  164. package/dest/services/reqresp/protocols/index.d.ts +9 -0
  165. package/dest/services/reqresp/protocols/index.d.ts.map +1 -0
  166. package/dest/services/reqresp/protocols/index.js +7 -0
  167. package/dest/services/reqresp/protocols/ping.d.ts +9 -0
  168. package/dest/services/reqresp/protocols/ping.d.ts.map +1 -0
  169. package/dest/services/reqresp/protocols/ping.js +7 -0
  170. package/dest/services/reqresp/protocols/status.d.ts +9 -0
  171. package/dest/services/reqresp/protocols/status.d.ts.map +1 -0
  172. package/dest/services/reqresp/protocols/status.js +7 -0
  173. package/dest/services/reqresp/protocols/tx.d.ts +13 -0
  174. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -0
  175. package/dest/services/reqresp/protocols/tx.js +20 -0
  176. package/dest/services/reqresp/rate-limiter/index.d.ts +2 -0
  177. package/dest/services/reqresp/rate-limiter/index.d.ts.map +1 -0
  178. package/dest/services/reqresp/rate-limiter/index.js +1 -0
  179. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +102 -0
  180. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -0
  181. package/dest/services/reqresp/rate-limiter/rate_limiter.js +184 -0
  182. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +3 -0
  183. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -0
  184. package/dest/services/reqresp/rate-limiter/rate_limits.js +54 -0
  185. package/dest/services/reqresp/reqresp.d.ts +166 -0
  186. package/dest/services/reqresp/reqresp.d.ts.map +1 -0
  187. package/dest/services/reqresp/reqresp.js +516 -0
  188. package/dest/services/reqresp/status.d.ts +31 -0
  189. package/dest/services/reqresp/status.d.ts.map +1 -0
  190. package/dest/services/reqresp/status.js +51 -0
  191. package/dest/services/service.d.ts +87 -0
  192. package/dest/services/service.d.ts.map +1 -0
  193. package/dest/services/service.js +5 -0
  194. package/dest/test-helpers/generate-peer-id-private-keys.d.ts +7 -0
  195. package/dest/test-helpers/generate-peer-id-private-keys.d.ts.map +1 -0
  196. package/dest/test-helpers/generate-peer-id-private-keys.js +13 -0
  197. package/dest/test-helpers/get-ports.d.ts +7 -0
  198. package/dest/test-helpers/get-ports.d.ts.map +1 -0
  199. package/dest/test-helpers/get-ports.js +8 -0
  200. package/dest/test-helpers/index.d.ts +6 -0
  201. package/dest/test-helpers/index.d.ts.map +1 -0
  202. package/dest/test-helpers/index.js +5 -0
  203. package/dest/test-helpers/make-enrs.d.ts +16 -0
  204. package/dest/test-helpers/make-enrs.d.ts.map +1 -0
  205. package/dest/test-helpers/make-enrs.js +32 -0
  206. package/dest/test-helpers/make-test-p2p-clients.d.ts +36 -0
  207. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -0
  208. package/dest/test-helpers/make-test-p2p-clients.js +68 -0
  209. package/dest/test-helpers/reqresp-nodes.d.ts +66 -0
  210. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -0
  211. package/dest/test-helpers/reqresp-nodes.js +207 -0
  212. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -0
  213. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -0
  214. package/dest/testbench/p2p_client_testbench_worker.js +132 -0
  215. package/dest/testbench/parse_log_file.d.ts +2 -0
  216. package/dest/testbench/parse_log_file.d.ts.map +1 -0
  217. package/dest/testbench/parse_log_file.js +131 -0
  218. package/dest/testbench/testbench.d.ts +2 -0
  219. package/dest/testbench/testbench.d.ts.map +1 -0
  220. package/dest/testbench/testbench.js +61 -0
  221. package/dest/testbench/worker_client_manager.d.ts +56 -0
  222. package/dest/testbench/worker_client_manager.d.ts.map +1 -0
  223. package/dest/testbench/worker_client_manager.js +266 -0
  224. package/dest/types/index.d.ts +32 -0
  225. package/dest/types/index.d.ts.map +1 -0
  226. package/dest/types/index.js +28 -0
  227. package/dest/util.d.ts +53 -0
  228. package/dest/util.d.ts.map +1 -0
  229. package/dest/util.js +140 -0
  230. package/dest/versioning.d.ts +12 -0
  231. package/dest/versioning.d.ts.map +1 -0
  232. package/dest/versioning.js +33 -0
  233. package/package.json +127 -0
  234. package/src/bootstrap/bootstrap.ts +146 -0
  235. package/src/client/factory.ts +89 -0
  236. package/src/client/index.ts +2 -0
  237. package/src/client/p2p_client.ts +754 -0
  238. package/src/config.ts +371 -0
  239. package/src/enr/generate-enr.ts +39 -0
  240. package/src/enr/index.ts +1 -0
  241. package/src/errors/reqresp.error.ts +35 -0
  242. package/src/index.ts +7 -0
  243. package/src/mem_pools/attestation_pool/attestation_pool.ts +62 -0
  244. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +230 -0
  245. package/src/mem_pools/attestation_pool/index.ts +2 -0
  246. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +159 -0
  247. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +161 -0
  248. package/src/mem_pools/attestation_pool/mocks.ts +44 -0
  249. package/src/mem_pools/index.ts +3 -0
  250. package/src/mem_pools/instrumentation.ts +126 -0
  251. package/src/mem_pools/interface.ts +12 -0
  252. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +309 -0
  253. package/src/mem_pools/tx_pool/index.ts +3 -0
  254. package/src/mem_pools/tx_pool/memory_tx_pool.ts +174 -0
  255. package/src/mem_pools/tx_pool/priority.ts +13 -0
  256. package/src/mem_pools/tx_pool/tx_pool.ts +76 -0
  257. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +130 -0
  258. package/src/msg_validators/attestation_validator/attestation_validator.ts +26 -0
  259. package/src/msg_validators/attestation_validator/index.ts +1 -0
  260. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +29 -0
  261. package/src/msg_validators/block_proposal_validator/index.ts +1 -0
  262. package/src/msg_validators/index.ts +3 -0
  263. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +32 -0
  264. package/src/msg_validators/tx_validator/block_header_validator.ts +25 -0
  265. package/src/msg_validators/tx_validator/data_validator.ts +106 -0
  266. package/src/msg_validators/tx_validator/double_spend_validator.ts +38 -0
  267. package/src/msg_validators/tx_validator/index.ts +6 -0
  268. package/src/msg_validators/tx_validator/metadata_validator.ts +48 -0
  269. package/src/msg_validators/tx_validator/tx_proof_validator.ts +18 -0
  270. package/src/services/data_store.ts +235 -0
  271. package/src/services/discv5/discV5_service.ts +256 -0
  272. package/src/services/dummy_service.ts +134 -0
  273. package/src/services/encoding.ts +79 -0
  274. package/src/services/gossipsub/scoring.ts +13 -0
  275. package/src/services/index.ts +2 -0
  276. package/src/services/libp2p/libp2p_service.ts +871 -0
  277. package/src/services/peer-manager/metrics.ts +41 -0
  278. package/src/services/peer-manager/peer_manager.ts +530 -0
  279. package/src/services/peer-manager/peer_scoring.ts +105 -0
  280. package/src/services/reqresp/config.ts +35 -0
  281. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +94 -0
  282. package/src/services/reqresp/connection-sampler/connection_sampler.ts +217 -0
  283. package/src/services/reqresp/index.ts +4 -0
  284. package/src/services/reqresp/interface.ts +185 -0
  285. package/src/services/reqresp/metrics.ts +57 -0
  286. package/src/services/reqresp/protocols/block.ts +15 -0
  287. package/src/services/reqresp/protocols/goodbye.ts +101 -0
  288. package/src/services/reqresp/protocols/index.ts +8 -0
  289. package/src/services/reqresp/protocols/ping.ts +8 -0
  290. package/src/services/reqresp/protocols/status.ts +8 -0
  291. package/src/services/reqresp/protocols/tx.ts +29 -0
  292. package/src/services/reqresp/rate-limiter/index.ts +1 -0
  293. package/src/services/reqresp/rate-limiter/rate_limiter.ts +228 -0
  294. package/src/services/reqresp/rate-limiter/rate_limits.ts +55 -0
  295. package/src/services/reqresp/reqresp.ts +661 -0
  296. package/src/services/reqresp/status.ts +59 -0
  297. package/src/services/service.ts +112 -0
  298. package/src/test-helpers/generate-peer-id-private-keys.ts +15 -0
  299. package/src/test-helpers/get-ports.ts +8 -0
  300. package/src/test-helpers/index.ts +5 -0
  301. package/src/test-helpers/make-enrs.ts +44 -0
  302. package/src/test-helpers/make-test-p2p-clients.ts +122 -0
  303. package/src/test-helpers/reqresp-nodes.ts +289 -0
  304. package/src/testbench/README.md +20 -0
  305. package/src/testbench/p2p_client_testbench_worker.ts +152 -0
  306. package/src/testbench/parse_log_file.ts +175 -0
  307. package/src/testbench/testbench.ts +66 -0
  308. package/src/testbench/worker_client_manager.ts +318 -0
  309. package/src/types/index.ts +36 -0
  310. package/src/util.ts +196 -0
  311. package/src/versioning.ts +50 -0
@@ -0,0 +1,245 @@
1
+ import { toArray } from '@aztec/foundation/iterable';
2
+ import { createLogger } from '@aztec/foundation/log';
3
+ import { ClientIvcProof } from '@aztec/stdlib/proofs';
4
+ import { Tx, TxHash } from '@aztec/stdlib/tx';
5
+ import { getTelemetryClient } from '@aztec/telemetry-client';
6
+ import { PoolInstrumentation, PoolName } from '../instrumentation.js';
7
+ import { getPendingTxPriority } from './priority.js';
8
+ /**
9
+ * KV implementation of the Transaction Pool.
10
+ */ export class AztecKVTxPool {
11
+ #store;
12
+ /** Our tx pool, stored as a Map, with K: tx hash and V: the transaction. */ #txs;
13
+ /** Index from tx hash to the block number in which they were mined, filtered by mined txs. */ #minedTxHashToBlock;
14
+ /** Index from tx priority (stored as hex) to its tx hash, filtered by pending txs. */ #pendingTxPriorityToHash;
15
+ /** KV store for archived txs. */ #archive;
16
+ /** Archived txs map for future lookup. */ #archivedTxs;
17
+ /** Indexes of the archived txs by insertion order. */ #archivedTxIndices;
18
+ /** Number of txs to archive. */ #archivedTxLimit;
19
+ #log;
20
+ #metrics;
21
+ /**
22
+ * Class constructor for KV TxPool. Initiates our transaction pool as an AztecMap.
23
+ * @param store - A KV store for live txs in the pool.
24
+ * @param archive - A KV store for archived txs.
25
+ * @param telemetry - A telemetry client.
26
+ * @param archivedTxLimit - The number of txs to archive.
27
+ * @param log - A logger.
28
+ */ constructor(store, archive, telemetry = getTelemetryClient(), archivedTxLimit = 0, log = createLogger('p2p:tx_pool')){
29
+ this.#txs = store.openMap('txs');
30
+ this.#minedTxHashToBlock = store.openMap('txHashToBlockMined');
31
+ this.#pendingTxPriorityToHash = store.openMultiMap('pendingTxFeeToHash');
32
+ this.#archivedTxs = archive.openMap('archivedTxs');
33
+ this.#archivedTxIndices = archive.openMap('archivedTxIndices');
34
+ this.#archivedTxLimit = archivedTxLimit;
35
+ this.#store = store;
36
+ this.#archive = archive;
37
+ this.#log = log;
38
+ this.#metrics = new PoolInstrumentation(telemetry, PoolName.TX_POOL, ()=>store.estimateSize());
39
+ }
40
+ markAsMined(txHashes, blockNumber) {
41
+ if (txHashes.length === 0) {
42
+ return Promise.resolve();
43
+ }
44
+ let deletedPending = 0;
45
+ return this.#store.transactionAsync(async ()=>{
46
+ for (const hash of txHashes){
47
+ const key = hash.toString();
48
+ await this.#minedTxHashToBlock.set(key, blockNumber);
49
+ const tx = await this.getTxByHash(hash);
50
+ if (tx) {
51
+ deletedPending++;
52
+ const fee = getPendingTxPriority(tx);
53
+ await this.#pendingTxPriorityToHash.deleteValue(fee, key);
54
+ }
55
+ }
56
+ this.#metrics.recordAddedObjects(txHashes.length, 'mined');
57
+ this.#metrics.recordRemovedObjects(deletedPending, 'pending');
58
+ });
59
+ }
60
+ markMinedAsPending(txHashes) {
61
+ if (txHashes.length === 0) {
62
+ return Promise.resolve();
63
+ }
64
+ let markedAsPending = 0;
65
+ return this.#store.transactionAsync(async ()=>{
66
+ for (const hash of txHashes){
67
+ const key = hash.toString();
68
+ await this.#minedTxHashToBlock.delete(key);
69
+ const tx = await this.getTxByHash(hash);
70
+ if (tx) {
71
+ await this.#pendingTxPriorityToHash.set(getPendingTxPriority(tx), key);
72
+ markedAsPending++;
73
+ }
74
+ }
75
+ this.#metrics.recordAddedObjects(markedAsPending, 'pending');
76
+ this.#metrics.recordRemovedObjects(markedAsPending, 'mined');
77
+ });
78
+ }
79
+ async getPendingTxHashes() {
80
+ const vals = await toArray(this.#pendingTxPriorityToHash.valuesAsync({
81
+ reverse: true
82
+ }));
83
+ return vals.map((x)=>TxHash.fromString(x));
84
+ }
85
+ async getMinedTxHashes() {
86
+ const vals = await toArray(this.#minedTxHashToBlock.entriesAsync());
87
+ return vals.map(([txHash, blockNumber])=>[
88
+ TxHash.fromString(txHash),
89
+ blockNumber
90
+ ]);
91
+ }
92
+ async getTxStatus(txHash) {
93
+ const key = txHash.toString();
94
+ const [isMined, isKnown] = await Promise.all([
95
+ this.#minedTxHashToBlock.hasAsync(key),
96
+ this.#txs.hasAsync(key)
97
+ ]);
98
+ if (isMined) {
99
+ return 'mined';
100
+ } else if (isKnown) {
101
+ return 'pending';
102
+ } else {
103
+ return undefined;
104
+ }
105
+ }
106
+ /**
107
+ * Checks if a transaction exists in the pool and returns it.
108
+ * @param txHash - The generated tx hash.
109
+ * @returns The transaction, if found, 'undefined' otherwise.
110
+ */ async getTxByHash(txHash) {
111
+ const buffer = await this.#txs.getAsync(txHash.toString());
112
+ if (buffer) {
113
+ const tx = Tx.fromBuffer(buffer);
114
+ tx.setTxHash(txHash);
115
+ return tx;
116
+ }
117
+ return undefined;
118
+ }
119
+ /**
120
+ * Checks if an archived tx exists and returns it.
121
+ * @param txHash - The tx hash.
122
+ * @returns The transaction metadata, if found, 'undefined' otherwise.
123
+ */ async getArchivedTxByHash(txHash) {
124
+ const buffer = await this.#archivedTxs.getAsync(txHash.toString());
125
+ if (buffer) {
126
+ const tx = Tx.fromBuffer(buffer);
127
+ tx.setTxHash(txHash);
128
+ return tx;
129
+ }
130
+ return undefined;
131
+ }
132
+ /**
133
+ * Adds a list of transactions to the pool. Duplicates are ignored.
134
+ * @param txs - An array of txs to be added to the pool.
135
+ * @returns Empty promise.
136
+ */ async addTxs(txs) {
137
+ const hashesAndStats = await Promise.all(txs.map(async (tx)=>({
138
+ txHash: await tx.getTxHash(),
139
+ txStats: await tx.getStats()
140
+ })));
141
+ await this.#store.transactionAsync(async ()=>{
142
+ let pendingCount = 0;
143
+ await Promise.all(txs.map(async (tx, i)=>{
144
+ const { txHash, txStats } = hashesAndStats[i];
145
+ this.#log.verbose(`Adding tx ${txHash.toString()} to pool`, {
146
+ eventName: 'tx-added-to-pool',
147
+ ...txStats
148
+ });
149
+ const key = txHash.toString();
150
+ await this.#txs.set(key, tx.toBuffer());
151
+ if (!await this.#minedTxHashToBlock.hasAsync(key)) {
152
+ pendingCount++;
153
+ // REFACTOR: Use an lmdb conditional write to avoid race conditions with this write tx
154
+ await this.#pendingTxPriorityToHash.set(getPendingTxPriority(tx), key);
155
+ this.#metrics.recordSize(tx);
156
+ }
157
+ }));
158
+ this.#metrics.recordAddedObjects(pendingCount, 'pending');
159
+ });
160
+ }
161
+ /**
162
+ * Deletes transactions from the pool. Tx hashes that are not present are ignored.
163
+ * @param txHashes - An array of tx hashes to be removed from the tx pool.
164
+ * @returns Empty promise.
165
+ */ deleteTxs(txHashes) {
166
+ let pendingDeleted = 0;
167
+ let minedDeleted = 0;
168
+ const deletedTxs = [];
169
+ const poolDbTx = this.#store.transactionAsync(async ()=>{
170
+ for (const hash of txHashes){
171
+ const key = hash.toString();
172
+ const tx = await this.getTxByHash(hash);
173
+ if (tx) {
174
+ const fee = getPendingTxPriority(tx);
175
+ await this.#pendingTxPriorityToHash.deleteValue(fee, key);
176
+ const isMined = await this.#minedTxHashToBlock.hasAsync(key);
177
+ if (isMined) {
178
+ minedDeleted++;
179
+ } else {
180
+ pendingDeleted++;
181
+ }
182
+ if (this.#archivedTxLimit) {
183
+ deletedTxs.push(tx);
184
+ }
185
+ await this.#txs.delete(key);
186
+ await this.#minedTxHashToBlock.delete(key);
187
+ }
188
+ }
189
+ this.#metrics.recordRemovedObjects(pendingDeleted, 'pending');
190
+ this.#metrics.recordRemovedObjects(minedDeleted, 'mined');
191
+ });
192
+ return this.#archivedTxLimit ? poolDbTx.then(()=>this.archiveTxs(deletedTxs)) : poolDbTx;
193
+ }
194
+ /**
195
+ * Gets all the transactions stored in the pool.
196
+ * @returns Array of tx objects in the order they were added to the pool.
197
+ */ async getAllTxs() {
198
+ const vals = await toArray(this.#txs.entriesAsync());
199
+ return vals.map(([hash, buffer])=>{
200
+ const tx = Tx.fromBuffer(buffer);
201
+ tx.setTxHash(TxHash.fromString(hash));
202
+ return tx;
203
+ });
204
+ }
205
+ /**
206
+ * Gets the hashes of all transactions currently in the tx pool.
207
+ * @returns An array of transaction hashes found in the tx pool.
208
+ */ async getAllTxHashes() {
209
+ const vals = await toArray(this.#txs.keysAsync());
210
+ return vals.map((x)=>TxHash.fromString(x));
211
+ }
212
+ /**
213
+ * Archives a list of txs for future reference. The number of archived txs is limited by the specified archivedTxLimit.
214
+ * @param txs - The list of transactions to archive.
215
+ * @returns Empty promise.
216
+ */ async archiveTxs(txs) {
217
+ const txHashes = await Promise.all(txs.map((tx)=>tx.getTxHash()));
218
+ await this.#archive.transactionAsync(async ()=>{
219
+ // calcualte the head and tail indices of the archived txs by insertion order.
220
+ let headIdx = ((await this.#archivedTxIndices.entriesAsync({
221
+ limit: 1,
222
+ reverse: true
223
+ }).next()).value?.[0] ?? -1) + 1;
224
+ let tailIdx = (await this.#archivedTxIndices.entriesAsync({
225
+ limit: 1
226
+ }).next()).value?.[0] ?? 0;
227
+ for(let i = 0; i < txs.length; i++){
228
+ const tx = txs[i];
229
+ while(headIdx - tailIdx >= this.#archivedTxLimit){
230
+ const txHash = await this.#archivedTxIndices.getAsync(tailIdx);
231
+ if (txHash) {
232
+ await this.#archivedTxs.delete(txHash);
233
+ await this.#archivedTxIndices.delete(tailIdx);
234
+ }
235
+ tailIdx++;
236
+ }
237
+ const archivedTx = new Tx(tx.data, ClientIvcProof.empty(), tx.contractClassLogs, tx.enqueuedPublicFunctionCalls, tx.publicTeardownFunctionCall);
238
+ const txHash = txHashes[i].toString();
239
+ await this.#archivedTxs.set(txHash, archivedTx.toBuffer());
240
+ await this.#archivedTxIndices.set(headIdx, txHash);
241
+ headIdx++;
242
+ }
243
+ });
244
+ }
245
+ }
@@ -0,0 +1,4 @@
1
+ export * from './tx_pool.js';
2
+ export * from './memory_tx_pool.js';
3
+ export * from './aztec_kv_tx_pool.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './tx_pool.js';
2
+ export * from './memory_tx_pool.js';
3
+ export * from './aztec_kv_tx_pool.js';
@@ -0,0 +1,56 @@
1
+ import { Tx, TxHash } from '@aztec/stdlib/tx';
2
+ import { type TelemetryClient } from '@aztec/telemetry-client';
3
+ import type { TxPool } from './tx_pool.js';
4
+ /**
5
+ * In-memory implementation of the Transaction Pool.
6
+ */
7
+ export declare class InMemoryTxPool implements TxPool {
8
+ private log;
9
+ /**
10
+ * Our tx pool, stored as a Map in-memory, with K: tx hash and V: the transaction.
11
+ */
12
+ private txs;
13
+ private minedTxs;
14
+ private pendingTxs;
15
+ private metrics;
16
+ /**
17
+ * Class constructor for in-memory TxPool. Initiates our transaction pool as a JS Map.
18
+ * @param log - A logger.
19
+ */
20
+ constructor(telemetry?: TelemetryClient, log?: import("@aztec/foundation/log").Logger);
21
+ markAsMined(txHashes: TxHash[], blockNumber: number): Promise<void>;
22
+ markMinedAsPending(txHashes: TxHash[]): Promise<void>;
23
+ getPendingTxHashes(): Promise<TxHash[]>;
24
+ getMinedTxHashes(): Promise<[TxHash, number][]>;
25
+ getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | undefined>;
26
+ /**
27
+ * Checks if a transaction exists in the pool and returns it.
28
+ * @param txHash - The generated tx hash.
29
+ * @returns The transaction, if found, 'undefined' otherwise.
30
+ */
31
+ getTxByHash(txHash: TxHash): Promise<Tx | undefined>;
32
+ getArchivedTxByHash(): Promise<Tx | undefined>;
33
+ /**
34
+ * Adds a list of transactions to the pool. Duplicates are ignored.
35
+ * @param txs - An array of txs to be added to the pool.
36
+ * @returns Empty promise.
37
+ */
38
+ addTxs(txs: Tx[]): Promise<void>;
39
+ /**
40
+ * Deletes transactions from the pool. Tx hashes that are not present are ignored.
41
+ * @param txHashes - An array of tx hashes to be removed from the tx pool.
42
+ * @returns The number of transactions that was deleted from the pool.
43
+ */
44
+ deleteTxs(txHashes: TxHash[]): Promise<void>;
45
+ /**
46
+ * Gets all the transactions stored in the pool.
47
+ * @returns Array of tx objects in the order they were added to the pool.
48
+ */
49
+ getAllTxs(): Promise<Tx[]>;
50
+ /**
51
+ * Gets the hashes of all transactions currently in the tx pool.
52
+ * @returns An array of transaction hashes found in the tx pool.
53
+ */
54
+ getAllTxHashes(): Promise<TxHash[]>;
55
+ }
56
+ //# sourceMappingURL=memory_tx_pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory_tx_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/memory_tx_pool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAInF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C;;GAEG;AACH,qBAAa,cAAe,YAAW,MAAM;IAcoB,OAAO,CAAC,GAAG;IAb1E;;OAEG;IACH,OAAO,CAAC,GAAG,CAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,UAAU,CAAc;IAEhC,OAAO,CAAC,OAAO,CAA0B;IAEzC;;;OAGG;gBACS,SAAS,GAAE,eAAsC,EAAU,GAAG,yCAA8B;IAOjG,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWnE,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA0B/C,kBAAkB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAQ7C,gBAAgB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IAM/C,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IAW5E;;;;OAIG;IACI,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;IAKpD,mBAAmB,IAAI,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;IAIrD;;;;OAIG;IACU,MAAM,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAsB7C;;;;OAIG;IACI,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBnD;;;OAGG;IACI,SAAS,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;IAIjC;;;OAGG;IACI,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAG3C"}
@@ -0,0 +1,141 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+ import { Tx, TxHash } from '@aztec/stdlib/tx';
3
+ import { getTelemetryClient } from '@aztec/telemetry-client';
4
+ import { PoolInstrumentation, PoolName } from '../instrumentation.js';
5
+ import { getPendingTxPriority } from './priority.js';
6
+ /**
7
+ * In-memory implementation of the Transaction Pool.
8
+ */ export class InMemoryTxPool {
9
+ log;
10
+ /**
11
+ * Our tx pool, stored as a Map in-memory, with K: tx hash and V: the transaction.
12
+ */ txs;
13
+ minedTxs;
14
+ pendingTxs;
15
+ metrics;
16
+ /**
17
+ * Class constructor for in-memory TxPool. Initiates our transaction pool as a JS Map.
18
+ * @param log - A logger.
19
+ */ constructor(telemetry = getTelemetryClient(), log = createLogger('p2p:tx_pool')){
20
+ this.log = log;
21
+ this.txs = new Map();
22
+ this.minedTxs = new Map();
23
+ this.pendingTxs = new Set();
24
+ this.metrics = new PoolInstrumentation(telemetry, PoolName.TX_POOL);
25
+ }
26
+ markAsMined(txHashes, blockNumber) {
27
+ const keys = txHashes.map((x)=>x.toBigInt());
28
+ for (const key of keys){
29
+ this.minedTxs.set(key, blockNumber);
30
+ this.pendingTxs.delete(key);
31
+ }
32
+ this.metrics.recordRemovedObjects(txHashes.length, 'pending');
33
+ this.metrics.recordAddedObjects(txHashes.length, 'mined');
34
+ return Promise.resolve();
35
+ }
36
+ markMinedAsPending(txHashes) {
37
+ if (txHashes.length === 0) {
38
+ return Promise.resolve();
39
+ }
40
+ const keys = txHashes.map((x)=>x.toBigInt());
41
+ let deleted = 0;
42
+ let added = 0;
43
+ for (const key of keys){
44
+ if (this.minedTxs.delete(key)) {
45
+ deleted++;
46
+ }
47
+ // only add back to the pending set if we have the tx object
48
+ if (this.txs.has(key)) {
49
+ added++;
50
+ this.pendingTxs.add(key);
51
+ }
52
+ }
53
+ this.metrics.recordRemovedObjects(deleted, 'mined');
54
+ this.metrics.recordAddedObjects(added, 'pending');
55
+ return Promise.resolve();
56
+ }
57
+ async getPendingTxHashes() {
58
+ const txs = (await this.getAllTxs()).sort((tx1, tx2)=>-getPendingTxPriority(tx1).localeCompare(getPendingTxPriority(tx2)));
59
+ const txHashes = await Promise.all(txs.map((tx)=>tx.getTxHash()));
60
+ return txHashes.filter((txHash)=>this.pendingTxs.has(txHash.toBigInt()));
61
+ }
62
+ getMinedTxHashes() {
63
+ return Promise.resolve(Array.from(this.minedTxs.entries()).map(([txHash, blockNumber])=>[
64
+ TxHash.fromBigInt(txHash),
65
+ blockNumber
66
+ ]));
67
+ }
68
+ getTxStatus(txHash) {
69
+ const key = txHash.toBigInt();
70
+ if (this.pendingTxs.has(key)) {
71
+ return Promise.resolve('pending');
72
+ }
73
+ if (this.minedTxs.has(key)) {
74
+ return Promise.resolve('mined');
75
+ }
76
+ return Promise.resolve(undefined);
77
+ }
78
+ /**
79
+ * Checks if a transaction exists in the pool and returns it.
80
+ * @param txHash - The generated tx hash.
81
+ * @returns The transaction, if found, 'undefined' otherwise.
82
+ */ getTxByHash(txHash) {
83
+ const result = this.txs.get(txHash.toBigInt());
84
+ return Promise.resolve(result === undefined ? undefined : Tx.clone(result));
85
+ }
86
+ getArchivedTxByHash() {
87
+ return Promise.resolve(undefined);
88
+ }
89
+ /**
90
+ * Adds a list of transactions to the pool. Duplicates are ignored.
91
+ * @param txs - An array of txs to be added to the pool.
92
+ * @returns Empty promise.
93
+ */ async addTxs(txs) {
94
+ let pending = 0;
95
+ for (const tx of txs){
96
+ const txHash = await tx.getTxHash();
97
+ this.log.verbose(`Adding tx ${txHash.toString()} to pool`, {
98
+ eventName: 'tx-added-to-pool',
99
+ ...await tx.getStats()
100
+ });
101
+ const key = txHash.toBigInt();
102
+ this.txs.set(key, tx);
103
+ if (!this.minedTxs.has(key)) {
104
+ pending++;
105
+ this.metrics.recordSize(tx);
106
+ this.pendingTxs.add(key);
107
+ }
108
+ }
109
+ this.metrics.recordAddedObjects(pending, 'pending');
110
+ return;
111
+ }
112
+ /**
113
+ * Deletes transactions from the pool. Tx hashes that are not present are ignored.
114
+ * @param txHashes - An array of tx hashes to be removed from the tx pool.
115
+ * @returns The number of transactions that was deleted from the pool.
116
+ */ deleteTxs(txHashes) {
117
+ let deletedMined = 0;
118
+ let deletedPending = 0;
119
+ for (const txHash of txHashes){
120
+ const key = txHash.toBigInt();
121
+ this.txs.delete(key);
122
+ deletedPending += this.pendingTxs.delete(key) ? 1 : 0;
123
+ deletedMined += this.minedTxs.delete(key) ? 1 : 0;
124
+ }
125
+ this.metrics.recordRemovedObjects(deletedPending, 'pending');
126
+ this.metrics.recordRemovedObjects(deletedMined, 'mined');
127
+ return Promise.resolve();
128
+ }
129
+ /**
130
+ * Gets all the transactions stored in the pool.
131
+ * @returns Array of tx objects in the order they were added to the pool.
132
+ */ getAllTxs() {
133
+ return Promise.resolve(Array.from(this.txs.values()).map((x)=>Tx.clone(x)));
134
+ }
135
+ /**
136
+ * Gets the hashes of all transactions currently in the tx pool.
137
+ * @returns An array of transaction hashes found in the tx pool.
138
+ */ getAllTxHashes() {
139
+ return Promise.resolve(Array.from(this.txs.keys()).map((x)=>TxHash.fromBigInt(x)));
140
+ }
141
+ }
@@ -0,0 +1,8 @@
1
+ import type { Tx } from '@aztec/stdlib/tx';
2
+ /**
3
+ * Returns a string representing the priority of a tx.
4
+ * Txs with a higher priority value are returned first when retrieving pending tx hashes.
5
+ * We currently use the sum of the priority fees for the tx for this value, represented as hex.
6
+ */
7
+ export declare function getPendingTxPriority(tx: Tx): string;
8
+ //# sourceMappingURL=priority.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"priority.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/priority.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAE3C;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,EAAE,GAAG,MAAM,CAInD"}
@@ -0,0 +1,10 @@
1
+ import { Buffer32 } from '@aztec/foundation/buffer';
2
+ /**
3
+ * Returns a string representing the priority of a tx.
4
+ * Txs with a higher priority value are returned first when retrieving pending tx hashes.
5
+ * We currently use the sum of the priority fees for the tx for this value, represented as hex.
6
+ */ export function getPendingTxPriority(tx) {
7
+ const priorityFees = tx.getGasSettings().maxPriorityFeesPerGas;
8
+ const totalFees = priorityFees.feePerDaGas.toBigInt() + priorityFees.feePerL2Gas.toBigInt();
9
+ return Buffer32.fromBigInt(totalFees).toString();
10
+ }
@@ -0,0 +1,66 @@
1
+ import type { Tx, TxHash } from '@aztec/stdlib/tx';
2
+ /**
3
+ * Interface of a transaction pool. The pool includes tx requests and is kept up-to-date by a P2P client.
4
+ */
5
+ export interface TxPool {
6
+ /**
7
+ * Adds a list of transactions to the pool. Duplicates are ignored.
8
+ * @param txs - An array of txs to be added to the pool.
9
+ */
10
+ addTxs(txs: Tx[]): Promise<void>;
11
+ /**
12
+ * Checks if a transaction exists in the pool and returns it.
13
+ * @param txHash - The hash of the transaction, used as an ID.
14
+ * @returns The transaction, if found, 'undefined' otherwise.
15
+ */
16
+ getTxByHash(txHash: TxHash): Promise<Tx | undefined>;
17
+ /**
18
+ * Checks if an archived transaction exists in the pool and returns it.
19
+ * @param txHash - The hash of the transaction, used as an ID.
20
+ * @returns The transaction, if found, 'undefined' otherwise.
21
+ */
22
+ getArchivedTxByHash(txHash: TxHash): Promise<Tx | undefined>;
23
+ /**
24
+ * Marks the set of txs as mined, as opposed to pending.
25
+ * @param txHashes - Hashes of the txs to flag as mined.
26
+ */
27
+ markAsMined(txHashes: TxHash[], blockNumber: number): Promise<void>;
28
+ /**
29
+ * Moves mined txs back to the pending set in the case of a reorg.
30
+ * Note: txs not known by this peer will be ignored.
31
+ * @param txHashes - Hashes of the txs to flag as pending.
32
+ */
33
+ markMinedAsPending(txHashes: TxHash[]): Promise<void>;
34
+ /**
35
+ * Deletes transactions from the pool. Tx hashes that are not present are ignored.
36
+ * @param txHashes - An array of tx hashes to be removed from the tx pool.
37
+ */
38
+ deleteTxs(txHashes: TxHash[]): Promise<void>;
39
+ /**
40
+ * Gets all transactions currently in the tx pool.
41
+ * @returns An array of transaction objects found in the tx pool.
42
+ */
43
+ getAllTxs(): Promise<Tx[]>;
44
+ /**
45
+ * Gets the hashes of all transactions currently in the tx pool.
46
+ * @returns An array of transaction hashes found in the tx pool.
47
+ */
48
+ getAllTxHashes(): Promise<TxHash[]>;
49
+ /**
50
+ * Gets the hashes of pending transactions currently in the tx pool sorted by priority (see getPendingTxPriority).
51
+ * @returns An array of pending transaction hashes found in the tx pool.
52
+ */
53
+ getPendingTxHashes(): Promise<TxHash[]>;
54
+ /**
55
+ * Gets the hashes of mined transactions currently in the tx pool.
56
+ * @returns An array of mined transaction hashes found in the tx pool.
57
+ */
58
+ getMinedTxHashes(): Promise<[tx: TxHash, blockNumber: number][]>;
59
+ /**
60
+ * Returns whether the given tx hash is flagged as pending or mined.
61
+ * @param txHash - Hash of the tx to query.
62
+ * @returns Pending or mined depending on its status, or undefined if not found.
63
+ */
64
+ getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | undefined>;
65
+ }
66
+ //# sourceMappingURL=tx_pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tx_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/tx_pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;;OAGG;IACH,MAAM,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjC;;;;OAIG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC;IAErD;;;;OAIG;IACH,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC;IAE7D;;;OAGG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpE;;;;OAIG;IACH,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtD;;;OAGG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7C;;;OAGG;IACH,SAAS,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;IAE3B;;;OAGG;IACH,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAEpC;;;OAGG;IACH,kBAAkB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAExC;;;OAGG;IACH,gBAAgB,IAAI,OAAO,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IAEjE;;;;OAIG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;CACvE"}
@@ -0,0 +1,3 @@
1
+ /**
2
+ * Interface of a transaction pool. The pool includes tx requests and is kept up-to-date by a P2P client.
3
+ */ export { };
@@ -0,0 +1,7 @@
1
+ import type { TxPool } from './tx_pool.js';
2
+ /**
3
+ * Tests a TxPool implementation.
4
+ * @param getTxPool - Gets a fresh TxPool
5
+ */
6
+ export declare function describeTxPool(getTxPool: () => TxPool): void;
7
+ //# sourceMappingURL=tx_pool_test_suite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tx_pool_test_suite.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/tx_pool_test_suite.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C;;;GAGG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,MAAM,QAsHrD"}