@aztec/p2p 3.0.0-canary.a9708bd → 3.0.0-devnet.2-patch.1

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 (294) 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 +14 -4
  4. package/dest/client/factory.d.ts +2 -1
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +8 -3
  7. package/dest/client/index.d.ts +1 -1
  8. package/dest/client/interface.d.ts +8 -6
  9. package/dest/client/interface.d.ts.map +1 -1
  10. package/dest/client/p2p_client.d.ts +11 -34
  11. package/dest/client/p2p_client.d.ts.map +1 -1
  12. package/dest/client/p2p_client.js +68 -46
  13. package/dest/config.d.ts +65 -56
  14. package/dest/config.d.ts.map +1 -1
  15. package/dest/config.js +21 -5
  16. package/dest/enr/generate-enr.d.ts +2 -2
  17. package/dest/enr/generate-enr.d.ts.map +1 -1
  18. package/dest/enr/generate-enr.js +1 -1
  19. package/dest/enr/index.d.ts +1 -1
  20. package/dest/errors/attestation-pool.error.d.ts +7 -0
  21. package/dest/errors/attestation-pool.error.d.ts.map +1 -0
  22. package/dest/errors/attestation-pool.error.js +12 -0
  23. package/dest/errors/reqresp.error.d.ts +1 -1
  24. package/dest/errors/reqresp.error.d.ts.map +1 -1
  25. package/dest/index.d.ts +1 -1
  26. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +43 -6
  27. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  28. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  29. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  30. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +72 -46
  31. package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
  32. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +15 -6
  33. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  34. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +73 -18
  35. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +13 -6
  36. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  37. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +69 -11
  38. package/dest/mem_pools/attestation_pool/mocks.d.ts +226 -5
  39. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  40. package/dest/mem_pools/attestation_pool/mocks.js +9 -7
  41. package/dest/mem_pools/index.d.ts +1 -1
  42. package/dest/mem_pools/instrumentation.d.ts +3 -1
  43. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  44. package/dest/mem_pools/instrumentation.js +11 -2
  45. package/dest/mem_pools/interface.d.ts +1 -1
  46. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +17 -40
  47. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  48. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +103 -44
  49. package/dest/mem_pools/tx_pool/index.d.ts +1 -1
  50. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +19 -6
  51. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
  52. package/dest/mem_pools/tx_pool/memory_tx_pool.js +88 -9
  53. package/dest/mem_pools/tx_pool/priority.d.ts +1 -1
  54. package/dest/mem_pools/tx_pool/tx_pool.d.ts +21 -6
  55. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  56. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  57. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  58. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +132 -7
  59. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -2
  60. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  61. package/dest/msg_validators/attestation_validator/attestation_validator.js +32 -5
  62. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
  63. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
  64. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +67 -0
  65. package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
  66. package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
  67. package/dest/msg_validators/attestation_validator/index.js +1 -0
  68. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +5 -2
  69. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
  70. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +56 -9
  71. package/dest/msg_validators/block_proposal_validator/index.d.ts +1 -1
  72. package/dest/msg_validators/index.d.ts +1 -1
  73. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +1 -1
  74. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -1
  75. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
  76. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  77. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +1 -1
  78. package/dest/msg_validators/tx_validator/archive_cache.d.ts +2 -2
  79. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
  80. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +2 -2
  81. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  82. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  83. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  84. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  85. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +1 -1
  86. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  87. package/dest/msg_validators/tx_validator/double_spend_validator.js +1 -1
  88. package/dest/msg_validators/tx_validator/factory.d.ts +4 -3
  89. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  90. package/dest/msg_validators/tx_validator/factory.js +11 -5
  91. package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
  92. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  93. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  94. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  95. package/dest/msg_validators/tx_validator/index.js +1 -0
  96. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +3 -6
  97. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  98. package/dest/msg_validators/tx_validator/metadata_validator.js +6 -24
  99. package/dest/msg_validators/tx_validator/phases_validator.d.ts +1 -1
  100. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  101. package/dest/msg_validators/tx_validator/phases_validator.js +3 -1
  102. package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
  103. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
  104. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +13 -0
  105. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
  106. package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
  107. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +1 -1
  108. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
  109. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +1 -1
  110. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  111. package/dest/services/data_store.d.ts +1 -1
  112. package/dest/services/data_store.d.ts.map +1 -1
  113. package/dest/services/discv5/discV5_service.d.ts +3 -3
  114. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  115. package/dest/services/discv5/discV5_service.js +2 -2
  116. package/dest/services/dummy_service.d.ts +2 -2
  117. package/dest/services/dummy_service.d.ts.map +1 -1
  118. package/dest/services/encoding.d.ts +25 -4
  119. package/dest/services/encoding.d.ts.map +1 -1
  120. package/dest/services/encoding.js +74 -6
  121. package/dest/services/gossipsub/scoring.d.ts +1 -1
  122. package/dest/services/index.d.ts +1 -1
  123. package/dest/services/libp2p/instrumentation.d.ts +3 -1
  124. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  125. package/dest/services/libp2p/instrumentation.js +9 -2
  126. package/dest/services/libp2p/libp2p_service.d.ts +29 -69
  127. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  128. package/dest/services/libp2p/libp2p_service.js +375 -133
  129. package/dest/services/peer-manager/interface.d.ts +1 -1
  130. package/dest/services/peer-manager/metrics.d.ts +3 -1
  131. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  132. package/dest/services/peer-manager/metrics.js +11 -0
  133. package/dest/services/peer-manager/peer_manager.d.ts +1 -32
  134. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  135. package/dest/services/peer-manager/peer_manager.js +27 -12
  136. package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
  137. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  138. package/dest/services/peer-manager/peer_scoring.js +40 -2
  139. package/dest/services/reqresp/config.d.ts +1 -1
  140. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +1 -1
  141. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  142. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -4
  143. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  144. package/dest/services/reqresp/index.d.ts +1 -1
  145. package/dest/services/reqresp/interface.d.ts +2 -11
  146. package/dest/services/reqresp/interface.d.ts.map +1 -1
  147. package/dest/services/reqresp/interface.js +1 -18
  148. package/dest/services/reqresp/metrics.d.ts +1 -1
  149. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  150. package/dest/services/reqresp/protocols/auth.d.ts +2 -2
  151. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
  152. package/dest/services/reqresp/protocols/auth.js +2 -2
  153. package/dest/services/reqresp/protocols/block.d.ts +1 -1
  154. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  155. package/dest/services/reqresp/protocols/block.js +3 -2
  156. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +1 -1
  157. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  158. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
  159. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +4 -6
  160. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  161. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +1 -1
  162. package/dest/services/reqresp/protocols/block_txs/index.d.ts +1 -1
  163. package/dest/services/reqresp/protocols/goodbye.d.ts +1 -1
  164. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
  165. package/dest/services/reqresp/protocols/index.d.ts +1 -1
  166. package/dest/services/reqresp/protocols/ping.d.ts +1 -1
  167. package/dest/services/reqresp/protocols/status.d.ts +6 -5
  168. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  169. package/dest/services/reqresp/protocols/status.js +4 -3
  170. package/dest/services/reqresp/protocols/tx.d.ts +1 -1
  171. package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
  172. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +2 -2
  173. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  174. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  175. package/dest/services/reqresp/reqresp.d.ts +1 -41
  176. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  177. package/dest/services/reqresp/reqresp.js +14 -10
  178. package/dest/services/reqresp/status.d.ts +2 -2
  179. package/dest/services/reqresp/status.d.ts.map +1 -1
  180. package/dest/services/service.d.ts +2 -2
  181. package/dest/services/service.d.ts.map +1 -1
  182. package/dest/services/tx_collection/config.d.ts +1 -1
  183. package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -9
  184. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  185. package/dest/services/tx_collection/fast_tx_collection.js +6 -1
  186. package/dest/services/tx_collection/index.d.ts +1 -1
  187. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  188. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  189. package/dest/services/tx_collection/slow_tx_collection.d.ts +6 -7
  190. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  191. package/dest/services/tx_collection/slow_tx_collection.js +2 -1
  192. package/dest/services/tx_collection/tx_collection.d.ts +12 -11
  193. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  194. package/dest/services/tx_collection/tx_collection.js +3 -2
  195. package/dest/services/tx_collection/tx_collection_sink.d.ts +3 -3
  196. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  197. package/dest/services/tx_collection/tx_collection_sink.js +34 -4
  198. package/dest/services/tx_collection/tx_source.d.ts +1 -1
  199. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  200. package/dest/services/tx_collection/tx_source.js +2 -2
  201. package/dest/services/tx_provider.d.ts +5 -4
  202. package/dest/services/tx_provider.d.ts.map +1 -1
  203. package/dest/services/tx_provider.js +8 -4
  204. package/dest/services/tx_provider_instrumentation.d.ts +1 -1
  205. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  206. package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
  207. package/dest/test-helpers/get-ports.d.ts +1 -1
  208. package/dest/test-helpers/get-ports.d.ts.map +1 -1
  209. package/dest/test-helpers/index.d.ts +1 -1
  210. package/dest/test-helpers/make-enrs.d.ts +1 -1
  211. package/dest/test-helpers/make-enrs.js +1 -1
  212. package/dest/test-helpers/make-test-p2p-clients.d.ts +2 -2
  213. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  214. package/dest/test-helpers/mock-pubsub.d.ts +4 -4
  215. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  216. package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
  217. package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
  218. package/dest/test-helpers/mock-tx-helpers.js +19 -0
  219. package/dest/test-helpers/reqresp-nodes.d.ts +2 -2
  220. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  221. package/dest/test-helpers/reqresp-nodes.js +4 -3
  222. package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
  223. package/dest/testbench/p2p_client_testbench_worker.js +16 -9
  224. package/dest/testbench/parse_log_file.d.ts +1 -1
  225. package/dest/testbench/testbench.d.ts +1 -1
  226. package/dest/testbench/testbench.js +2 -2
  227. package/dest/testbench/worker_client_manager.d.ts +1 -1
  228. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  229. package/dest/types/index.d.ts +1 -1
  230. package/dest/util.d.ts +2 -1
  231. package/dest/util.d.ts.map +1 -1
  232. package/dest/util.js +11 -2
  233. package/dest/versioning.d.ts +2 -2
  234. package/dest/versioning.d.ts.map +1 -1
  235. package/dest/versioning.js +2 -2
  236. package/package.json +21 -21
  237. package/src/bootstrap/bootstrap.ts +15 -4
  238. package/src/client/factory.ts +17 -3
  239. package/src/client/interface.ts +8 -5
  240. package/src/client/p2p_client.ts +88 -74
  241. package/src/config.ts +33 -6
  242. package/src/enr/generate-enr.ts +1 -1
  243. package/src/errors/attestation-pool.error.ts +13 -0
  244. package/src/mem_pools/attestation_pool/attestation_pool.ts +46 -5
  245. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +89 -48
  246. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +107 -24
  247. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +98 -19
  248. package/src/mem_pools/attestation_pool/mocks.ts +11 -8
  249. package/src/mem_pools/instrumentation.ts +13 -0
  250. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +116 -48
  251. package/src/mem_pools/tx_pool/memory_tx_pool.ts +98 -12
  252. package/src/mem_pools/tx_pool/tx_pool.ts +20 -5
  253. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +115 -7
  254. package/src/msg_validators/attestation_validator/attestation_validator.ts +41 -6
  255. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +91 -0
  256. package/src/msg_validators/attestation_validator/index.ts +1 -0
  257. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +63 -18
  258. package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
  259. package/src/msg_validators/tx_validator/block_header_validator.ts +2 -2
  260. package/src/msg_validators/tx_validator/double_spend_validator.ts +1 -1
  261. package/src/msg_validators/tx_validator/factory.ts +13 -6
  262. package/src/msg_validators/tx_validator/index.ts +1 -0
  263. package/src/msg_validators/tx_validator/metadata_validator.ts +8 -42
  264. package/src/msg_validators/tx_validator/phases_validator.ts +3 -1
  265. package/src/msg_validators/tx_validator/test_utils.ts +1 -1
  266. package/src/msg_validators/tx_validator/timestamp_validator.ts +47 -0
  267. package/src/services/discv5/discV5_service.ts +2 -2
  268. package/src/services/dummy_service.ts +1 -1
  269. package/src/services/encoding.ts +81 -6
  270. package/src/services/libp2p/instrumentation.ts +10 -1
  271. package/src/services/libp2p/libp2p_service.ts +427 -157
  272. package/src/services/peer-manager/metrics.ts +10 -0
  273. package/src/services/peer-manager/peer_manager.ts +22 -14
  274. package/src/services/peer-manager/peer_scoring.ts +46 -3
  275. package/src/services/reqresp/interface.ts +1 -22
  276. package/src/services/reqresp/protocols/auth.ts +2 -2
  277. package/src/services/reqresp/protocols/block.ts +3 -2
  278. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +1 -1
  279. package/src/services/reqresp/protocols/status.ts +9 -8
  280. package/src/services/reqresp/reqresp.ts +15 -11
  281. package/src/services/service.ts +1 -1
  282. package/src/services/tx_collection/fast_tx_collection.ts +8 -5
  283. package/src/services/tx_collection/slow_tx_collection.ts +7 -6
  284. package/src/services/tx_collection/tx_collection.ts +12 -10
  285. package/src/services/tx_collection/tx_collection_sink.ts +34 -3
  286. package/src/services/tx_collection/tx_source.ts +2 -2
  287. package/src/services/tx_provider.ts +9 -7
  288. package/src/test-helpers/make-enrs.ts +1 -1
  289. package/src/test-helpers/mock-tx-helpers.ts +24 -0
  290. package/src/test-helpers/reqresp-nodes.ts +3 -2
  291. package/src/testbench/p2p_client_testbench_worker.ts +12 -5
  292. package/src/testbench/testbench.ts +2 -2
  293. package/src/util.ts +12 -2
  294. package/src/versioning.ts +3 -3
@@ -15,6 +15,7 @@ export class PeerManagerMetrics {
15
15
  private sentGoodbyes: UpDownCounter;
16
16
  private receivedGoodbyes: UpDownCounter;
17
17
  private peerCount: Gauge;
18
+ private lowScoreDisconnects: UpDownCounter;
18
19
 
19
20
  public readonly tracer: Tracer;
20
21
 
@@ -40,6 +41,11 @@ export class PeerManagerMetrics {
40
41
  unit: 'peers',
41
42
  valueType: ValueType.INT,
42
43
  });
44
+ this.lowScoreDisconnects = meter.createUpDownCounter(Metrics.PEER_MANAGER_LOW_SCORE_DISCONNECTS, {
45
+ description: 'Number of peers disconnected due to low score',
46
+ unit: 'peers',
47
+ valueType: ValueType.INT,
48
+ });
43
49
  }
44
50
 
45
51
  public recordGoodbyeSent(reason: GoodByeReason) {
@@ -53,4 +59,8 @@ export class PeerManagerMetrics {
53
59
  public recordPeerCount(count: number) {
54
60
  this.peerCount.record(count);
55
61
  }
62
+
63
+ public recordLowScoreDisconnect(scoreState: 'Banned' | 'Disconnect') {
64
+ this.lowScoreDisconnects.add(1, { [Attributes.P2P_PEER_SCORE_STATE]: scoreState });
65
+ }
56
66
  }
@@ -1,7 +1,7 @@
1
1
  import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
- import { makeEthSignDigest, recoverAddress } from '@aztec/foundation/crypto';
2
+ import { makeEthSignDigest, tryRecoverAddress } from '@aztec/foundation/crypto/secp256k1-signer';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import type { EthAddress } from '@aztec/foundation/eth-address';
4
- import { Fr } from '@aztec/foundation/fields';
5
5
  import { createLogger } from '@aztec/foundation/log';
6
6
  import { bufferToHex } from '@aztec/foundation/string';
7
7
  import { DateProvider } from '@aztec/foundation/timer';
@@ -9,10 +9,10 @@ import type { PeerInfo, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/
9
9
  import type { PeerErrorSeverity } from '@aztec/stdlib/p2p';
10
10
  import { type TelemetryClient, trackSpan } from '@aztec/telemetry-client';
11
11
 
12
- import { ENR } from '@chainsafe/enr';
13
12
  import type { Connection, PeerId } from '@libp2p/interface';
14
13
  import { peerIdFromString } from '@libp2p/peer-id';
15
14
  import type { Multiaddr } from '@multiformats/multiaddr';
15
+ import { ENR } from '@nethermindeth/enr';
16
16
  import { inspect } from 'util';
17
17
 
18
18
  import type { P2PConfig } from '../../config.js';
@@ -577,9 +577,11 @@ export class PeerManager implements PeerManagerInterface {
577
577
  const score = this.peerScoring.getScoreState(peer.remotePeer.toString());
578
578
  switch (score) {
579
579
  case PeerScoreState.Banned:
580
+ this.metrics.recordLowScoreDisconnect('Banned');
580
581
  void this.goodbyeAndDisconnectPeer(peer.remotePeer, GoodByeReason.BANNED);
581
582
  break;
582
583
  case PeerScoreState.Disconnect:
584
+ this.metrics.recordLowScoreDisconnect('Disconnect');
583
585
  void this.goodbyeAndDisconnectPeer(peer.remotePeer, GoodByeReason.LOW_SCORE);
584
586
  break;
585
587
  case PeerScoreState.Healthy:
@@ -883,7 +885,7 @@ export class PeerManager implements PeerManagerInterface {
883
885
  const response = await this.reqresp.sendRequestToPeer(peerId, ReqRespSubProtocol.AUTH, authRequest.toBuffer());
884
886
  const { status } = response;
885
887
  if (status !== ReqRespStatus.SUCCESS) {
886
- this.logger.debug(`Disconnecting peer ${peerId} who failed to respond auth handshake`, {
888
+ this.logger.verbose(`Disconnecting peer ${peerId} who failed to respond auth handshake`, {
887
889
  peerId,
888
890
  status: ReqRespStatus[status],
889
891
  });
@@ -899,7 +901,7 @@ export class PeerManager implements PeerManagerInterface {
899
901
 
900
902
  const peerStatusMessage = peerAuthResponse.status;
901
903
  if (!ourStatus.validate(peerStatusMessage)) {
902
- this.logger.debug(`Disconnecting peer ${peerId} due to failed status handshake as part of auth.`, logData);
904
+ this.logger.verbose(`Disconnecting peer ${peerId} due to failed status handshake as part of auth.`, logData);
903
905
  this.markAuthHandshakeFailed(peerId);
904
906
  this.markPeerForDisconnect(peerId);
905
907
  return;
@@ -907,16 +909,20 @@ export class PeerManager implements PeerManagerInterface {
907
909
 
908
910
  const hashToRecover = authRequest.getPayloadToSign();
909
911
  const ethSignedHash = makeEthSignDigest(hashToRecover);
910
- const sender = recoverAddress(ethSignedHash, peerAuthResponse.signature);
912
+ const sender = tryRecoverAddress(ethSignedHash, peerAuthResponse.signature);
913
+ if (!sender) {
914
+ this.logger.verbose(`Disconnecting peer ${peerId} due to failed auth handshake, invalid signature.`, logData);
915
+ this.markAuthHandshakeFailed(peerId);
916
+ this.markPeerForDisconnect(peerId);
917
+ return;
918
+ }
919
+
911
920
  const registeredValidators = await this.epochCache.getRegisteredValidators();
912
921
  const found = registeredValidators.find(v => v.toString() === sender.toString()) !== undefined;
913
922
  if (!found) {
914
- this.logger.debug(
923
+ this.logger.verbose(
915
924
  `Disconnecting peer ${peerId} due to failed auth handshake, peer is not a registered validator.`,
916
- {
917
- peerId,
918
- address: sender.toString(),
919
- },
925
+ { ...logData, address: sender.toString() },
920
926
  );
921
927
  this.markAuthHandshakeFailed(peerId);
922
928
  this.markPeerForDisconnect(peerId);
@@ -926,8 +932,9 @@ export class PeerManager implements PeerManagerInterface {
926
932
  // Check to see that this validator address isn't already allocated to a different peer
927
933
  const peerForAddress = this.authenticatedValidatorAddressToPeerId.get(sender.toString());
928
934
  if (peerForAddress !== undefined && peerForAddress.toString() !== peerIdString) {
929
- this.logger.debug(
935
+ this.logger.verbose(
930
936
  `Received auth for validator ${sender.toString()} from peer ${peerIdString}, but this validator is already authenticated to peer ${peerForAddress.toString()}`,
937
+ { ...logData, address: sender.toString() },
931
938
  );
932
939
  return;
933
940
  }
@@ -937,12 +944,13 @@ export class PeerManager implements PeerManagerInterface {
937
944
  this.authenticatedValidatorAddressToPeerId.set(sender.toString(), peerId);
938
945
  this.logger.info(
939
946
  `Successfully completed auth handshake with peer ${peerId}, validator address ${sender.toString()}`,
940
- logData,
947
+ { ...logData, address: sender.toString() },
941
948
  );
942
949
  } catch (err: any) {
943
950
  //TODO: maybe hard ban these peers in the future
944
- this.logger.debug(`Disconnecting peer ${peerId} due to error during auth handshake: ${err.message ?? err}`, {
951
+ this.logger.verbose(`Disconnecting peer ${peerId} due to error during auth handshake: ${err.message}`, {
945
952
  peerId,
953
+ err,
946
954
  });
947
955
  this.markAuthHandshakeFailed(peerId);
948
956
  this.markPeerForDisconnect(peerId);
@@ -1,6 +1,14 @@
1
1
  import { median } from '@aztec/foundation/collection';
2
2
  import { createLogger } from '@aztec/foundation/log';
3
3
  import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
4
+ import {
5
+ Attributes,
6
+ Metrics,
7
+ type TelemetryClient,
8
+ type UpDownCounter,
9
+ ValueType,
10
+ getTelemetryClient,
11
+ } from '@aztec/telemetry-client';
4
12
 
5
13
  import type { PeerId } from '@libp2p/interface';
6
14
 
@@ -30,7 +38,9 @@ export class PeerScoring {
30
38
  private decayFactor = 0.9;
31
39
  peerPenalties: { [key in PeerErrorSeverity]: number };
32
40
 
33
- constructor(config: P2PConfig) {
41
+ private peerStateCounter: UpDownCounter;
42
+
43
+ constructor(config: P2PConfig, telemetry: TelemetryClient = getTelemetryClient()) {
34
44
  const orderedValues = config.peerPenaltyValues?.sort((a, b) => a - b);
35
45
  this.peerPenalties = {
36
46
  [PeerErrorSeverity.HighToleranceError]:
@@ -40,6 +50,13 @@ export class PeerScoring {
40
50
  [PeerErrorSeverity.LowToleranceError]:
41
51
  orderedValues?.[2] ?? DefaultPeerPenalties[PeerErrorSeverity.LowToleranceError],
42
52
  };
53
+
54
+ const meter = telemetry.getMeter('PeerScoring');
55
+
56
+ this.peerStateCounter = meter.createUpDownCounter(Metrics.P2P_PEER_STATE_COUNT, {
57
+ description: 'Count of peers by state (Healthy, Disconnect, Banned)',
58
+ valueType: ValueType.INT,
59
+ });
43
60
  }
44
61
 
45
62
  public penalizePeer(peerId: PeerId, penalty: PeerErrorSeverity) {
@@ -99,7 +116,33 @@ export class PeerScoring {
99
116
  return PeerScoreState.Healthy;
100
117
  }
101
118
 
102
- getStats(): { medianScore: number } {
103
- return { medianScore: median(Array.from(this.scores.values())) ?? 0 };
119
+ getStats(): { medianScore: number; healthyCount: number; disconnectCount: number; bannedCount: number } {
120
+ const stateCounts = { healthy: 0, disconnect: 0, banned: 0 };
121
+
122
+ for (const peerId of this.scores.keys()) {
123
+ const state = this.getScoreState(peerId);
124
+ switch (state) {
125
+ case PeerScoreState.Healthy:
126
+ stateCounts.healthy++;
127
+ break;
128
+ case PeerScoreState.Disconnect:
129
+ stateCounts.disconnect++;
130
+ break;
131
+ case PeerScoreState.Banned:
132
+ stateCounts.banned++;
133
+ break;
134
+ }
135
+ }
136
+
137
+ this.peerStateCounter.add(stateCounts.healthy, { [Attributes.P2P_PEER_SCORE_STATE]: 'Healthy' });
138
+ this.peerStateCounter.add(stateCounts.disconnect, { [Attributes.P2P_PEER_SCORE_STATE]: 'Disconnect' });
139
+ this.peerStateCounter.add(stateCounts.banned, { [Attributes.P2P_PEER_SCORE_STATE]: 'Banned' });
140
+
141
+ return {
142
+ medianScore: median(Array.from(this.scores.values())) ?? 0,
143
+ healthyCount: stateCounts.healthy,
144
+ disconnectCount: stateCounts.disconnect,
145
+ bannedCount: stateCounts.banned,
146
+ };
104
147
  }
105
148
  }
@@ -1,4 +1,4 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { L2Block } from '@aztec/stdlib/block';
3
3
  import { TxArray, TxHashArray } from '@aztec/stdlib/tx';
4
4
 
@@ -122,27 +122,6 @@ export type SubProtocolMap = {
122
122
  >;
123
123
  };
124
124
 
125
- /**
126
- * Default handler for unimplemented sub protocols, this SHOULD be overwritten
127
- * by the service, but is provided as a fallback
128
- */
129
- export const defaultHandler = (_msg: any): Promise<Buffer> => {
130
- return Promise.resolve(Buffer.from('unimplemented'));
131
- };
132
-
133
- /**
134
- * Default sub protocol handlers - this SHOULD be overwritten by the service,
135
- */
136
- export const DEFAULT_SUB_PROTOCOL_HANDLERS: ReqRespSubProtocolHandlers = {
137
- [ReqRespSubProtocol.PING]: defaultHandler,
138
- [ReqRespSubProtocol.STATUS]: defaultHandler,
139
- [ReqRespSubProtocol.TX]: defaultHandler,
140
- [ReqRespSubProtocol.GOODBYE]: defaultHandler,
141
- [ReqRespSubProtocol.BLOCK]: defaultHandler,
142
- [ReqRespSubProtocol.AUTH]: defaultHandler,
143
- [ReqRespSubProtocol.BLOCK_TXS]: defaultHandler,
144
- };
145
-
146
125
  /**
147
126
  * The Request Response Pair interface defines the methods that each
148
127
  * request response pair must implement
@@ -1,7 +1,7 @@
1
1
  import { Buffer32 } from '@aztec/foundation/buffer';
2
- import { keccak256 } from '@aztec/foundation/crypto';
2
+ import { keccak256 } from '@aztec/foundation/crypto/keccak';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import { Signature } from '@aztec/foundation/eth-signature';
4
- import { Fr } from '@aztec/foundation/fields';
5
5
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
6
6
 
7
7
  import { StatusMessage } from './status.js';
@@ -1,4 +1,5 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
3
  import type { L2BlockSource } from '@aztec/stdlib/block';
3
4
 
4
5
  import type { PeerId } from '@libp2p/interface';
@@ -27,7 +28,7 @@ export function reqRespBlockHandler(l2BlockSource: L2BlockSource): ReqRespSubPro
27
28
  }
28
29
 
29
30
  try {
30
- const foundBlock = await l2BlockSource.getBlock(Number(blockNumber));
31
+ const foundBlock = await l2BlockSource.getBlock(BlockNumber(Number(blockNumber)));
31
32
  return foundBlock ? foundBlock.toBuffer() : Buffer.alloc(0);
32
33
  } catch (err: any) {
33
34
  throw new ReqRespStatusError(ReqRespStatus.INTERNAL_ERROR, { cause: err });
@@ -1,4 +1,4 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
3
3
  import { TxArray } from '@aztec/stdlib/tx';
4
4
 
@@ -1,3 +1,4 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import { Buffer32 } from '@aztec/foundation/buffer';
2
3
  import type { Logger } from '@aztec/foundation/log';
3
4
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
@@ -15,9 +16,9 @@ import type { PeerId } from '@libp2p/interface';
15
16
  export class StatusMessage {
16
17
  constructor(
17
18
  readonly compressedComponentsVersion: string,
18
- readonly latestBlockNumber: number,
19
+ readonly latestBlockNumber: BlockNumber,
19
20
  readonly latestBlockHash: string,
20
- readonly finalizedBlockNumber: number,
21
+ readonly finalizedBlockNumber: BlockNumber,
21
22
  //TODO: add finalizedBlockHash
22
23
  //readonly finalizedBlockHash: string,
23
24
  ) {}
@@ -31,9 +32,9 @@ export class StatusMessage {
31
32
  const reader = BufferReader.asReader(buffer);
32
33
  return new StatusMessage(
33
34
  reader.readString(), // compressedComponentsVersion
34
- reader.readNumber(), // latestBlockNumber
35
+ BlockNumber(reader.readNumber()), // latestBlockNumber
35
36
  reader.readString(), // latestBlockHash
36
- reader.readNumber(), // finalizedBlockNumber
37
+ BlockNumber(reader.readNumber()), // finalizedBlockNumber
37
38
  //TODO: add finalizedBlockHash
38
39
  //reader.readString(), // finalizedBlockHash
39
40
  );
@@ -63,9 +64,9 @@ export class StatusMessage {
63
64
  static fromWorldStateSyncStatus(version: string, syncStatus: WorldStateSyncStatus): StatusMessage {
64
65
  return new StatusMessage(
65
66
  version,
66
- syncStatus.latestBlockNumber,
67
+ BlockNumber(syncStatus.latestBlockNumber),
67
68
  syncStatus.latestBlockHash,
68
- syncStatus.finalizedBlockNumber,
69
+ BlockNumber(syncStatus.finalizedBlockNumber),
69
70
  //TODO: add finalizedBlockHash
70
71
  );
71
72
  }
@@ -73,9 +74,9 @@ export class StatusMessage {
73
74
  static random(): StatusMessage {
74
75
  return new StatusMessage(
75
76
  '1.0.0',
76
- Math.floor(Math.random() * 100),
77
+ BlockNumber(Math.floor(Math.random() * 100)),
77
78
  Buffer32.random().toString(),
78
- Math.floor(Math.random() * 100),
79
+ BlockNumber(Math.floor(Math.random() * 100)),
79
80
  //TODO: add finalizedBlockHash
80
81
  );
81
82
  }
@@ -26,7 +26,6 @@ import {
26
26
  import { BatchConnectionSampler } from './connection-sampler/batch_connection_sampler.js';
27
27
  import { ConnectionSampler, RandomSampler } from './connection-sampler/connection_sampler.js';
28
28
  import {
29
- DEFAULT_SUB_PROTOCOL_HANDLERS,
30
29
  DEFAULT_SUB_PROTOCOL_VALIDATORS,
31
30
  type ReqRespInterface,
32
31
  type ReqRespResponse,
@@ -64,9 +63,8 @@ export class ReqResp implements ReqRespInterface {
64
63
  private individualRequestTimeoutMs: number = DEFAULT_INDIVIDUAL_REQUEST_TIMEOUT_MS;
65
64
  private dialTimeoutMs: number = DEFAULT_REQRESP_DIAL_TIMEOUT_MS;
66
65
 
67
- // Warning, if the `start` function is not called as the parent class constructor, then the default sub protocol handlers will be used ( not good )
68
- private subProtocolHandlers: ReqRespSubProtocolHandlers = DEFAULT_SUB_PROTOCOL_HANDLERS;
69
- private subProtocolValidators: ReqRespSubProtocolValidators = DEFAULT_SUB_PROTOCOL_VALIDATORS;
66
+ private subProtocolHandlers: Partial<ReqRespSubProtocolHandlers> = {};
67
+ private subProtocolValidators: Partial<ReqRespSubProtocolValidators> = {};
70
68
 
71
69
  private connectionSampler: ConnectionSampler;
72
70
  private rateLimiter: RequestResponseRateLimiter;
@@ -117,11 +115,12 @@ export class ReqResp implements ReqRespInterface {
117
115
  * Start the reqresp service
118
116
  */
119
117
  async start(subProtocolHandlers: ReqRespSubProtocolHandlers, subProtocolValidators: ReqRespSubProtocolValidators) {
120
- this.subProtocolHandlers = subProtocolHandlers;
121
- this.subProtocolValidators = subProtocolValidators;
118
+ Object.assign(this.subProtocolHandlers, subProtocolHandlers);
119
+ Object.assign(this.subProtocolValidators, subProtocolValidators);
122
120
 
123
121
  // Register all protocol handlers
124
- for (const subProtocol of Object.keys(this.subProtocolHandlers)) {
122
+ for (const subProtocol of Object.keys(subProtocolHandlers)) {
123
+ this.logger.debug(`Registering handler for sub protocol ${subProtocol}`);
125
124
  await this.libp2p.handle(
126
125
  subProtocol,
127
126
  (data: IncomingStreamData) =>
@@ -140,6 +139,7 @@ export class ReqResp implements ReqRespInterface {
140
139
  ): Promise<void> {
141
140
  this.subProtocolHandlers[subProtocol] = handler;
142
141
  this.subProtocolValidators[subProtocol] = validator;
142
+ this.logger.debug(`Registering handler for sub protocol ${subProtocol}`);
143
143
  await this.libp2p.handle(
144
144
  subProtocol,
145
145
  (data: IncomingStreamData) =>
@@ -209,7 +209,7 @@ export class ReqResp implements ReqRespInterface {
209
209
  maxPeers = Math.max(10, Math.ceil(requests.length / 3)),
210
210
  maxRetryAttempts = 3,
211
211
  ): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]> {
212
- const responseValidator = this.subProtocolValidators[subProtocol];
212
+ const responseValidator = this.subProtocolValidators[subProtocol] ?? DEFAULT_SUB_PROTOCOL_VALIDATORS[subProtocol];
213
213
  const responses: InstanceType<SubProtocolMap[SubProtocol]['response']>[] = new Array(requests.length);
214
214
  const requestBuffers = requests.map(req => req.toBuffer());
215
215
 
@@ -489,7 +489,7 @@ export class ReqResp implements ReqRespInterface {
489
489
  }
490
490
 
491
491
  const messageData = Buffer.concat(chunks);
492
- const message: Buffer = this.snappyTransform.inboundTransformNoTopic(messageData);
492
+ const message: Buffer = this.snappyTransform.inboundTransformData(messageData);
493
493
 
494
494
  return {
495
495
  status: status ?? ReqRespStatus.UNKNOWN,
@@ -594,7 +594,11 @@ export class ReqResp implements ReqRespInterface {
594
594
  *
595
595
  * */
596
596
  private async processStream(protocol: ReqRespSubProtocol, { stream, connection }: IncomingStreamData): Promise<void> {
597
- const handler = this.subProtocolHandlers[protocol]!;
597
+ const handler = this.subProtocolHandlers[protocol];
598
+ if (!handler) {
599
+ throw new Error(`No handler defined for reqresp subprotocol ${protocol}`);
600
+ }
601
+
598
602
  const snappy = this.snappyTransform;
599
603
  const SUCCESS = Uint8Array.of(ReqRespStatus.SUCCESS);
600
604
 
@@ -614,7 +618,7 @@ export class ReqResp implements ReqRespInterface {
614
618
  stream.metadata.written = true; // Mark the stream as written to;
615
619
 
616
620
  yield SUCCESS;
617
- yield snappy.outboundTransformNoTopic(response);
621
+ yield snappy.outboundTransformData(response);
618
622
  }
619
623
  },
620
624
  stream.sink,
@@ -3,8 +3,8 @@ import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
3
3
  import type { BlockAttestation, BlockProposal, Gossipable } from '@aztec/stdlib/p2p';
4
4
  import type { Tx } from '@aztec/stdlib/tx';
5
5
 
6
- import type { ENR } from '@chainsafe/enr';
7
6
  import type { PeerId } from '@libp2p/interface';
7
+ import type { ENR } from '@nethermindeth/enr';
8
8
  import type EventEmitter from 'events';
9
9
 
10
10
  import type { P2PReqRespConfig } from './reqresp/config.js';
@@ -1,3 +1,4 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import { times } from '@aztec/foundation/collection';
2
3
  import { AbortError, TimeoutError } from '@aztec/foundation/error';
3
4
  import { type Logger, createLogger } from '@aztec/foundation/log';
@@ -5,7 +6,7 @@ import { boundInclusive } from '@aztec/foundation/number';
5
6
  import { promiseWithResolvers } from '@aztec/foundation/promise';
6
7
  import { sleep } from '@aztec/foundation/sleep';
7
8
  import { DateProvider, elapsed } from '@aztec/foundation/timer';
8
- import type { BlockInfo } from '@aztec/stdlib/block';
9
+ import type { L2BlockInfo } from '@aztec/stdlib/block';
9
10
  import type { BlockProposal } from '@aztec/stdlib/p2p';
10
11
  import { type Tx, TxHash } from '@aztec/stdlib/tx';
11
12
 
@@ -54,8 +55,10 @@ export class FastTxCollection {
54
55
  return [];
55
56
  }
56
57
 
57
- const blockInfo: BlockInfo =
58
- input.type === 'proposal' ? input.blockProposal.toBlockInfo() : input.block.toBlockInfo();
58
+ const blockInfo: L2BlockInfo =
59
+ input.type === 'proposal'
60
+ ? { ...input.blockProposal.toBlockInfo(), blockNumber: input.blockNumber }
61
+ : { ...input.block.toBlockInfo() };
59
62
 
60
63
  // This promise is used to await for the collection to finish during the main collectFast method.
61
64
  // It gets resolved in `foundTxs` when all txs have been collected, or rejected if the request is aborted or hits the deadline.
@@ -314,7 +317,7 @@ export class FastTxCollection {
314
317
  * Stop collecting all txs for blocks less than or requal to the block number specified.
315
318
  * To be called when we no longer care about gathering txs up to a certain block, eg when they become proven or finalized.
316
319
  */
317
- public stopCollectingForBlocksUpTo(blockNumber: number): void {
320
+ public stopCollectingForBlocksUpTo(blockNumber: BlockNumber): void {
318
321
  for (const request of this.requests) {
319
322
  if (request.blockInfo.blockNumber <= blockNumber) {
320
323
  request.promise.reject(new AbortError(`Stopped collecting txs up to block ${blockNumber}`));
@@ -327,7 +330,7 @@ export class FastTxCollection {
327
330
  * Stop collecting all txs for blocks greater than the block number specified.
328
331
  * To be called when there is a chain prune and previously mined txs are no longer relevant.
329
332
  */
330
- public stopCollectingForBlocksAfter(blockNumber: number): void {
333
+ public stopCollectingForBlocksAfter(blockNumber: BlockNumber): void {
331
334
  for (const request of this.requests) {
332
335
  if (request.blockInfo.blockNumber > blockNumber) {
333
336
  request.promise.reject(new AbortError(`Stopped collecting txs after block ${blockNumber}`));
@@ -1,9 +1,10 @@
1
+ import { BlockNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
1
2
  import { chunk } from '@aztec/foundation/collection';
2
3
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
4
  import { boundInclusive } from '@aztec/foundation/number';
4
5
  import { RunningPromise } from '@aztec/foundation/promise';
5
6
  import { DateProvider } from '@aztec/foundation/timer';
6
- import type { L2Block } from '@aztec/stdlib/block';
7
+ import type { L2BlockNew } from '@aztec/stdlib/block';
7
8
  import { type L1RollupConstants, getEpochAtSlot, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
8
9
  import { type Tx, TxHash } from '@aztec/stdlib/tx';
9
10
 
@@ -75,7 +76,7 @@ export class SlowTxCollection {
75
76
  }
76
77
 
77
78
  /** Starts collecting the given tx hashes for the given L2Block in the slow loop */
78
- public startCollecting(block: L2Block, txHashes: TxHash[]) {
79
+ public startCollecting(block: L2BlockNew, txHashes: TxHash[]) {
79
80
  const slot = block.header.getSlot();
80
81
  const deadline = this.getDeadlineForSlot(slot);
81
82
  if (+deadline < this.dateProvider.now()) {
@@ -202,7 +203,7 @@ export class SlowTxCollection {
202
203
  * Stop collecting all txs for blocks less than or requal to the block number specified.
203
204
  * To be called when we no longer care about gathering txs up to a certain block, eg when they become proven or finalized.
204
205
  */
205
- public stopCollectingForBlocksUpTo(blockNumber: number): void {
206
+ public stopCollectingForBlocksUpTo(blockNumber: BlockNumber): void {
206
207
  for (const [txHash, info] of this.missingTxs.entries()) {
207
208
  if (info.blockNumber <= blockNumber) {
208
209
  this.missingTxs.delete(txHash);
@@ -214,7 +215,7 @@ export class SlowTxCollection {
214
215
  * Stop collecting all txs for blocks greater than the block number specified.
215
216
  * To be called when there is a chain prune and previously mined txs are no longer relevant.
216
217
  */
217
- public stopCollectingForBlocksAfter(blockNumber: number): void {
218
+ public stopCollectingForBlocksAfter(blockNumber: BlockNumber): void {
218
219
  for (const [txHash, info] of this.missingTxs.entries()) {
219
220
  if (info.blockNumber > blockNumber) {
220
221
  this.missingTxs.delete(txHash);
@@ -223,9 +224,9 @@ export class SlowTxCollection {
223
224
  }
224
225
 
225
226
  /** Computes the proof submission deadline for a given slot, a tx mined in this slot is no longer interesting after this deadline */
226
- private getDeadlineForSlot(slotNumber: bigint): Date {
227
+ private getDeadlineForSlot(slotNumber: SlotNumber): Date {
227
228
  const epoch = getEpochAtSlot(slotNumber, this.constants);
228
- const submissionEndEpoch = epoch + BigInt(this.constants.proofSubmissionEpochs);
229
+ const submissionEndEpoch = EpochNumber(epoch + this.constants.proofSubmissionEpochs);
229
230
  const submissionEndTimestamp = getTimestampRangeForEpoch(submissionEndEpoch, this.constants)[1];
230
231
  return new Date(Number(submissionEndTimestamp) * 1000);
231
232
  }
@@ -1,8 +1,9 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import { compactArray } from '@aztec/foundation/collection';
2
3
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
4
  import { type PromiseWithResolvers, RunningPromise } from '@aztec/foundation/promise';
4
5
  import { DateProvider } from '@aztec/foundation/timer';
5
- import type { BlockInfo, L2Block } from '@aztec/stdlib/block';
6
+ import type { L2BlockInfo, L2BlockNew } from '@aztec/stdlib/block';
6
7
  import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
7
8
  import type { BlockProposal } from '@aztec/stdlib/p2p';
8
9
  import { Tx, TxHash } from '@aztec/stdlib/tx';
@@ -21,16 +22,16 @@ import type { TxSource } from './tx_source.js';
21
22
 
22
23
  export type CollectionMethod = 'fast-req-resp' | 'fast-node-rpc' | 'slow-req-resp' | 'slow-node-rpc';
23
24
 
24
- export type MissingTxInfo = { blockNumber: number; deadline: Date; readyForReqResp: boolean };
25
+ export type MissingTxInfo = { blockNumber: BlockNumber; deadline: Date; readyForReqResp: boolean };
25
26
 
26
27
  export type FastCollectionRequestInput =
27
- | { type: 'block'; block: L2Block }
28
- | { type: 'proposal'; blockProposal: BlockProposal };
28
+ | { type: 'block'; block: L2BlockNew }
29
+ | { type: 'proposal'; blockProposal: BlockProposal; blockNumber: BlockNumber };
29
30
 
30
31
  export type FastCollectionRequest = FastCollectionRequestInput & {
31
32
  missingTxHashes: Set<string>;
32
33
  deadline: Date;
33
- blockInfo: BlockInfo;
34
+ blockInfo: L2BlockInfo;
34
35
  promise: PromiseWithResolvers<void>;
35
36
  foundTxs: Map<string, Tx>;
36
37
  };
@@ -145,22 +146,23 @@ export class TxCollection {
145
146
  }
146
147
 
147
148
  /** Starts collecting the given tx hashes for the given L2Block in the slow loop */
148
- public startCollecting(block: L2Block, txHashes: TxHash[]) {
149
+ public startCollecting(block: L2BlockNew, txHashes: TxHash[]) {
149
150
  return this.slowCollection.startCollecting(block, txHashes);
150
151
  }
151
152
 
152
153
  /** Collects the set of txs for the given block proposal as fast as possible */
153
154
  public collectFastForProposal(
154
155
  blockProposal: BlockProposal,
156
+ blockNumber: BlockNumber,
155
157
  txHashes: TxHash[] | string[],
156
158
  opts: { deadline: Date; pinnedPeer?: PeerId },
157
159
  ) {
158
- return this.collectFastFor({ type: 'proposal', blockProposal }, txHashes, opts);
160
+ return this.collectFastFor({ type: 'proposal', blockProposal, blockNumber }, txHashes, opts);
159
161
  }
160
162
 
161
163
  /** Collects the set of txs for the given mined block as fast as possible */
162
164
  public collectFastForBlock(
163
- block: L2Block,
165
+ block: L2BlockNew,
164
166
  txHashes: TxHash[] | string[],
165
167
  opts: { deadline: Date; pinnedPeer?: PeerId },
166
168
  ) {
@@ -186,7 +188,7 @@ export class TxCollection {
186
188
  * Stop collecting all txs for blocks less than or requal to the block number specified.
187
189
  * To be called when we no longer care about gathering txs up to a certain block, eg when they become proven or finalized.
188
190
  */
189
- public stopCollectingForBlocksUpTo(blockNumber: number): void {
191
+ public stopCollectingForBlocksUpTo(blockNumber: BlockNumber): void {
190
192
  this.slowCollection.stopCollectingForBlocksUpTo(blockNumber);
191
193
  this.fastCollection.stopCollectingForBlocksUpTo(blockNumber);
192
194
  }
@@ -195,7 +197,7 @@ export class TxCollection {
195
197
  * Stop collecting all txs for blocks greater than the block number specified.
196
198
  * To be called when there is a chain prune and previously mined txs are no longer relevant.
197
199
  */
198
- public stopCollectingForBlocksAfter(blockNumber: number): void {
200
+ public stopCollectingForBlocksAfter(blockNumber: BlockNumber): void {
199
201
  this.slowCollection.stopCollectingForBlocksAfter(blockNumber);
200
202
  this.fastCollection.stopCollectingForBlocksAfter(blockNumber);
201
203
  }
@@ -58,17 +58,48 @@ export class TxCollectionSink extends (EventEmitter as new () => TypedEventEmitt
58
58
  return { txs, requested, duration };
59
59
  }
60
60
 
61
+ // Validate tx hashes for all collected txs from external sources
62
+ const validTxs: Tx[] = [];
63
+ const invalidTxHashes: string[] = [];
64
+ await Promise.all(
65
+ txs.map(async tx => {
66
+ const isValid = await tx.validateTxHash();
67
+ if (isValid) {
68
+ validTxs.push(tx);
69
+ } else {
70
+ invalidTxHashes.push(tx.getTxHash().toString());
71
+ }
72
+ }),
73
+ );
74
+
75
+ if (invalidTxHashes.length > 0) {
76
+ this.log.warn(`Rejecting ${invalidTxHashes.length} txs with invalid hashes from ${info.description}`, {
77
+ ...info,
78
+ invalidTxHashes,
79
+ });
80
+ }
81
+
82
+ if (validTxs.length === 0) {
83
+ this.log.trace(`No valid txs found via ${info.description} after validation`, {
84
+ ...info,
85
+ requestedTxs: requested.map(t => t.toString()),
86
+ invalidTxHashes,
87
+ });
88
+ return { txs: [], requested, duration };
89
+ }
90
+
61
91
  this.log.verbose(
62
- `Collected ${txs.length} txs out of ${requested.length} requested via ${info.description} in ${duration}ms`,
92
+ `Collected ${validTxs.length} txs out of ${requested.length} requested via ${info.description} in ${duration}ms`,
63
93
  {
64
94
  ...info,
65
95
  duration,
66
- txs: txs.map(t => t.getTxHash().toString()),
96
+ txs: validTxs.map(t => t.getTxHash().toString()),
67
97
  requestedTxs: requested.map(t => t.toString()),
98
+ rejectedCount: invalidTxHashes.length,
68
99
  },
69
100
  );
70
101
 
71
- return await this.foundTxs(txs, { ...info, duration });
102
+ return await this.foundTxs(validTxs, { ...info, duration });
72
103
  }
73
104
 
74
105
  private async foundTxs(