@aztec/p2p 3.0.0-devnet.2 → 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 (259) hide show
  1. package/dest/bootstrap/bootstrap.d.ts +1 -1
  2. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  3. package/dest/client/factory.d.ts +1 -1
  4. package/dest/client/index.d.ts +1 -1
  5. package/dest/client/interface.d.ts +4 -2
  6. package/dest/client/interface.d.ts.map +1 -1
  7. package/dest/client/p2p_client.d.ts +8 -26
  8. package/dest/client/p2p_client.d.ts.map +1 -1
  9. package/dest/client/p2p_client.js +31 -24
  10. package/dest/config.d.ts +60 -54
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +12 -2
  13. package/dest/enr/generate-enr.d.ts +1 -1
  14. package/dest/enr/index.d.ts +1 -1
  15. package/dest/errors/attestation-pool.error.d.ts +7 -0
  16. package/dest/errors/attestation-pool.error.d.ts.map +1 -0
  17. package/dest/errors/attestation-pool.error.js +12 -0
  18. package/dest/errors/reqresp.error.d.ts +1 -1
  19. package/dest/errors/reqresp.error.d.ts.map +1 -1
  20. package/dest/index.d.ts +1 -1
  21. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +43 -6
  22. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  23. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  24. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  25. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +67 -34
  26. package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
  27. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +15 -6
  28. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  29. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +57 -18
  30. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +13 -6
  31. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  32. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +51 -7
  33. package/dest/mem_pools/attestation_pool/mocks.d.ts +226 -5
  34. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  35. package/dest/mem_pools/attestation_pool/mocks.js +2 -2
  36. package/dest/mem_pools/index.d.ts +1 -1
  37. package/dest/mem_pools/instrumentation.d.ts +3 -1
  38. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  39. package/dest/mem_pools/instrumentation.js +11 -2
  40. package/dest/mem_pools/interface.d.ts +1 -1
  41. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +5 -38
  42. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  43. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +9 -3
  44. package/dest/mem_pools/tx_pool/index.d.ts +1 -1
  45. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +5 -3
  46. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
  47. package/dest/mem_pools/tx_pool/memory_tx_pool.js +7 -0
  48. package/dest/mem_pools/tx_pool/priority.d.ts +1 -1
  49. package/dest/mem_pools/tx_pool/tx_pool.d.ts +10 -3
  50. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  51. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  52. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  53. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +5 -4
  54. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -3
  55. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  56. package/dest/msg_validators/attestation_validator/attestation_validator.js +12 -12
  57. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
  58. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
  59. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +67 -0
  60. package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
  61. package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
  62. package/dest/msg_validators/attestation_validator/index.js +1 -0
  63. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +1 -1
  64. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
  65. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +22 -10
  66. package/dest/msg_validators/block_proposal_validator/index.d.ts +1 -1
  67. package/dest/msg_validators/index.d.ts +1 -1
  68. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +1 -1
  69. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -1
  70. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
  71. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  72. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +1 -1
  73. package/dest/msg_validators/tx_validator/archive_cache.d.ts +2 -2
  74. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
  75. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +2 -2
  76. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  77. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  78. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  79. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +1 -1
  80. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  81. package/dest/msg_validators/tx_validator/factory.d.ts +4 -3
  82. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  83. package/dest/msg_validators/tx_validator/factory.js +1 -1
  84. package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
  85. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  86. package/dest/msg_validators/tx_validator/index.d.ts +1 -1
  87. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +2 -2
  88. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  89. package/dest/msg_validators/tx_validator/phases_validator.d.ts +1 -1
  90. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  91. package/dest/msg_validators/tx_validator/phases_validator.js +3 -1
  92. package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
  93. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
  94. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +3 -2
  95. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  96. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +1 -1
  97. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
  98. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +1 -1
  99. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  100. package/dest/services/data_store.d.ts +1 -1
  101. package/dest/services/data_store.d.ts.map +1 -1
  102. package/dest/services/discv5/discV5_service.d.ts +1 -1
  103. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  104. package/dest/services/dummy_service.d.ts +1 -1
  105. package/dest/services/dummy_service.d.ts.map +1 -1
  106. package/dest/services/encoding.d.ts +25 -4
  107. package/dest/services/encoding.d.ts.map +1 -1
  108. package/dest/services/encoding.js +74 -6
  109. package/dest/services/gossipsub/scoring.d.ts +1 -1
  110. package/dest/services/index.d.ts +1 -1
  111. package/dest/services/libp2p/instrumentation.d.ts +3 -1
  112. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  113. package/dest/services/libp2p/instrumentation.js +9 -2
  114. package/dest/services/libp2p/libp2p_service.d.ts +25 -74
  115. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  116. package/dest/services/libp2p/libp2p_service.js +308 -84
  117. package/dest/services/peer-manager/interface.d.ts +1 -1
  118. package/dest/services/peer-manager/metrics.d.ts +3 -1
  119. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  120. package/dest/services/peer-manager/metrics.js +11 -0
  121. package/dest/services/peer-manager/peer_manager.d.ts +1 -32
  122. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  123. package/dest/services/peer-manager/peer_manager.js +4 -2
  124. package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
  125. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  126. package/dest/services/peer-manager/peer_scoring.js +40 -2
  127. package/dest/services/reqresp/config.d.ts +1 -1
  128. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +1 -1
  129. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  130. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -4
  131. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  132. package/dest/services/reqresp/index.d.ts +1 -1
  133. package/dest/services/reqresp/interface.d.ts +2 -2
  134. package/dest/services/reqresp/interface.d.ts.map +1 -1
  135. package/dest/services/reqresp/interface.js +1 -1
  136. package/dest/services/reqresp/metrics.d.ts +1 -1
  137. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  138. package/dest/services/reqresp/protocols/auth.d.ts +2 -2
  139. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
  140. package/dest/services/reqresp/protocols/auth.js +2 -2
  141. package/dest/services/reqresp/protocols/block.d.ts +1 -1
  142. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  143. package/dest/services/reqresp/protocols/block.js +3 -2
  144. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +1 -1
  145. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  146. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
  147. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +4 -6
  148. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  149. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +1 -1
  150. package/dest/services/reqresp/protocols/block_txs/index.d.ts +1 -1
  151. package/dest/services/reqresp/protocols/goodbye.d.ts +1 -1
  152. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
  153. package/dest/services/reqresp/protocols/index.d.ts +1 -1
  154. package/dest/services/reqresp/protocols/ping.d.ts +1 -1
  155. package/dest/services/reqresp/protocols/status.d.ts +6 -5
  156. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  157. package/dest/services/reqresp/protocols/status.js +4 -3
  158. package/dest/services/reqresp/protocols/tx.d.ts +1 -1
  159. package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
  160. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +2 -2
  161. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  162. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  163. package/dest/services/reqresp/reqresp.d.ts +1 -41
  164. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  165. package/dest/services/reqresp/reqresp.js +2 -2
  166. package/dest/services/reqresp/status.d.ts +2 -2
  167. package/dest/services/reqresp/status.d.ts.map +1 -1
  168. package/dest/services/service.d.ts +1 -1
  169. package/dest/services/tx_collection/config.d.ts +1 -1
  170. package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -9
  171. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  172. package/dest/services/tx_collection/index.d.ts +1 -1
  173. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  174. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  175. package/dest/services/tx_collection/slow_tx_collection.d.ts +6 -7
  176. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  177. package/dest/services/tx_collection/slow_tx_collection.js +2 -1
  178. package/dest/services/tx_collection/tx_collection.d.ts +11 -11
  179. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  180. package/dest/services/tx_collection/tx_collection_sink.d.ts +3 -3
  181. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  182. package/dest/services/tx_collection/tx_source.d.ts +1 -1
  183. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  184. package/dest/services/tx_provider.d.ts +5 -4
  185. package/dest/services/tx_provider.d.ts.map +1 -1
  186. package/dest/services/tx_provider_instrumentation.d.ts +1 -1
  187. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  188. package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
  189. package/dest/test-helpers/get-ports.d.ts +1 -1
  190. package/dest/test-helpers/get-ports.d.ts.map +1 -1
  191. package/dest/test-helpers/index.d.ts +1 -1
  192. package/dest/test-helpers/make-enrs.d.ts +1 -1
  193. package/dest/test-helpers/make-test-p2p-clients.d.ts +2 -2
  194. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  195. package/dest/test-helpers/mock-pubsub.d.ts +4 -4
  196. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  197. package/dest/test-helpers/mock-tx-helpers.d.ts +2 -2
  198. package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -1
  199. package/dest/test-helpers/mock-tx-helpers.js +1 -1
  200. package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
  201. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  202. package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
  203. package/dest/testbench/p2p_client_testbench_worker.js +14 -8
  204. package/dest/testbench/parse_log_file.d.ts +1 -1
  205. package/dest/testbench/testbench.d.ts +1 -1
  206. package/dest/testbench/testbench.js +2 -2
  207. package/dest/testbench/worker_client_manager.d.ts +1 -1
  208. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  209. package/dest/types/index.d.ts +1 -1
  210. package/dest/util.d.ts +2 -1
  211. package/dest/util.d.ts.map +1 -1
  212. package/dest/util.js +11 -2
  213. package/dest/versioning.d.ts +1 -1
  214. package/package.json +19 -18
  215. package/src/client/interface.ts +4 -1
  216. package/src/client/p2p_client.ts +51 -43
  217. package/src/config.ts +19 -2
  218. package/src/errors/attestation-pool.error.ts +13 -0
  219. package/src/mem_pools/attestation_pool/attestation_pool.ts +46 -5
  220. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +84 -34
  221. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +87 -24
  222. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +77 -15
  223. package/src/mem_pools/attestation_pool/mocks.ts +3 -3
  224. package/src/mem_pools/instrumentation.ts +13 -0
  225. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +15 -9
  226. package/src/mem_pools/tx_pool/memory_tx_pool.ts +13 -6
  227. package/src/mem_pools/tx_pool/tx_pool.ts +10 -2
  228. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +5 -4
  229. package/src/msg_validators/attestation_validator/attestation_validator.ts +14 -16
  230. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +91 -0
  231. package/src/msg_validators/attestation_validator/index.ts +1 -0
  232. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +26 -10
  233. package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
  234. package/src/msg_validators/tx_validator/block_header_validator.ts +1 -1
  235. package/src/msg_validators/tx_validator/factory.ts +3 -2
  236. package/src/msg_validators/tx_validator/metadata_validator.ts +1 -1
  237. package/src/msg_validators/tx_validator/phases_validator.ts +3 -1
  238. package/src/msg_validators/tx_validator/test_utils.ts +1 -1
  239. package/src/msg_validators/tx_validator/timestamp_validator.ts +2 -1
  240. package/src/services/encoding.ts +81 -6
  241. package/src/services/libp2p/instrumentation.ts +10 -1
  242. package/src/services/libp2p/libp2p_service.ts +334 -91
  243. package/src/services/peer-manager/metrics.ts +10 -0
  244. package/src/services/peer-manager/peer_manager.ts +4 -2
  245. package/src/services/peer-manager/peer_scoring.ts +46 -3
  246. package/src/services/reqresp/interface.ts +1 -1
  247. package/src/services/reqresp/protocols/auth.ts +2 -2
  248. package/src/services/reqresp/protocols/block.ts +3 -2
  249. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +1 -1
  250. package/src/services/reqresp/protocols/status.ts +9 -8
  251. package/src/services/reqresp/reqresp.ts +2 -2
  252. package/src/services/tx_collection/fast_tx_collection.ts +3 -2
  253. package/src/services/tx_collection/slow_tx_collection.ts +7 -6
  254. package/src/services/tx_collection/tx_collection.ts +10 -9
  255. package/src/services/tx_provider.ts +4 -3
  256. package/src/test-helpers/mock-tx-helpers.ts +1 -1
  257. package/src/testbench/p2p_client_testbench_worker.ts +11 -5
  258. package/src/testbench/testbench.ts +2 -2
  259. package/src/util.ts +12 -2
@@ -1,16 +1,16 @@
1
- import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
1
+ import { GENESIS_BLOCK_HEADER_HASH, INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
2
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
3
  import { createLogger } from '@aztec/foundation/log';
3
4
  import { DateProvider } from '@aztec/foundation/timer';
4
5
  import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncSingleton } from '@aztec/kv-store';
5
6
  import type {
6
7
  EthAddress,
7
- L2Block,
8
8
  L2BlockId,
9
+ L2BlockNew,
9
10
  L2BlockSource,
10
11
  L2BlockStream,
11
12
  L2BlockStreamEvent,
12
13
  L2Tips,
13
- PublishedL2Block,
14
14
  } from '@aztec/stdlib/block';
15
15
  import type { ContractDataSource } from '@aztec/stdlib/contract';
16
16
  import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
@@ -62,10 +62,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
62
62
  private provenBlockNumberAtStart = -1;
63
63
  private finalizedBlockNumberAtStart = -1;
64
64
 
65
- private synchedBlockHashes: AztecAsyncMap<number, string>;
66
- private synchedLatestBlockNumber: AztecAsyncSingleton<number>;
67
- private synchedProvenBlockNumber: AztecAsyncSingleton<number>;
68
- private synchedFinalizedBlockNumber: AztecAsyncSingleton<number>;
65
+ private synchedBlockHashes: AztecAsyncMap<BlockNumber, string>;
66
+ private synchedLatestBlockNumber: AztecAsyncSingleton<BlockNumber>;
67
+ private synchedProvenBlockNumber: AztecAsyncSingleton<BlockNumber>;
68
+ private synchedFinalizedBlockNumber: AztecAsyncSingleton<BlockNumber>;
69
69
  private synchedLatestSlot: AztecAsyncSingleton<bigint>;
70
70
 
71
71
  private txPool: TxPool;
@@ -121,14 +121,14 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
121
121
  this.log.debug(`Received block proposal from ${sender.toString()}`);
122
122
  // TODO(palla/txs): Need to subtract validatorReexecuteDeadlineMs from this deadline (see ValidatorClient.getReexecutionDeadline)
123
123
  const constants = this.txCollection.getConstants();
124
- const nextSlotTimestampSeconds = Number(getTimestampForSlot(block.slotNumber.toBigInt() + 1n, constants));
124
+ const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(block.slotNumber + 1), constants));
125
125
  const deadline = new Date(nextSlotTimestampSeconds * 1000);
126
126
  const parentBlock = await this.l2BlockSource.getBlockHeaderByArchive(block.payload.header.lastArchiveRoot);
127
127
  if (!parentBlock) {
128
128
  this.log.debug(`Cannot collect txs for proposal as parent block not found`);
129
129
  return;
130
130
  }
131
- const blockNumber = parentBlock.getBlockNumber() + 1;
131
+ const blockNumber = BlockNumber(parentBlock.getBlockNumber() + 1);
132
132
  await this.txProvider.getTxsForBlockProposal(block, blockNumber, { pinnedPeer: sender, deadline });
133
133
  return undefined;
134
134
  });
@@ -162,7 +162,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
162
162
  return Promise.resolve(this.p2pService.getPeers(includePending));
163
163
  }
164
164
 
165
- public getL2BlockHash(number: number): Promise<string | undefined> {
165
+ public getL2BlockHash(number: BlockNumber): Promise<string | undefined> {
166
166
  return this.synchedBlockHashes.getAsync(number);
167
167
  }
168
168
 
@@ -203,10 +203,12 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
203
203
  }
204
204
  }
205
205
 
206
+ const genesisHash = GENESIS_BLOCK_HEADER_HASH.toString();
207
+
206
208
  return {
207
- latest: { hash: latestBlockHash!, number: latestBlockNumber },
208
- proven: { hash: provenBlockHash!, number: provenBlockNumber },
209
- finalized: { hash: finalizedBlockHash!, number: finalizedBlockNumber },
209
+ latest: { hash: latestBlockHash ?? genesisHash, number: latestBlockNumber },
210
+ proven: { hash: provenBlockHash ?? genesisHash, number: provenBlockNumber },
211
+ finalized: { hash: finalizedBlockHash ?? genesisHash, number: finalizedBlockNumber },
210
212
  };
211
213
  }
212
214
 
@@ -214,15 +216,16 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
214
216
  this.log.debug(`Handling block stream event ${event.type}`);
215
217
  switch (event.type) {
216
218
  case 'blocks-added':
217
- await this.handleLatestL2Blocks(event.blocks);
219
+ await this.handleLatestL2Blocks(event.blocks.map(b => b.block.toL2Block()));
218
220
  break;
219
221
  case 'chain-finalized': {
220
222
  // TODO (alexg): I think we can prune the block hashes map here
221
223
  await this.setBlockHash(event.block);
222
- const from = (await this.getSyncedFinalizedBlockNum()) + 1;
224
+ const from = BlockNumber((await this.getSyncedFinalizedBlockNum()) + 1);
223
225
  const limit = event.block.number - from + 1;
224
226
  if (limit > 0) {
225
- await this.handleFinalizedL2Blocks(await this.l2BlockSource.getBlocks(from, limit));
227
+ const oldBlocks = await this.l2BlockSource.getBlocks(from, limit);
228
+ await this.handleFinalizedL2Blocks(oldBlocks.map(b => b.toL2Block()));
226
229
  }
227
230
  break;
228
231
  }
@@ -284,7 +287,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
284
287
  (this.attestationPool === undefined || (await this.attestationPool?.isEmpty()))
285
288
  ) {
286
289
  // if mempools are empty, we don't care about syncing prior blocks
287
- this.initBlockStream(this.latestBlockNumberAtStart);
290
+ this.initBlockStream(BlockNumber(this.latestBlockNumberAtStart));
288
291
  this.setCurrentState(P2PClientState.RUNNING);
289
292
  this.syncPromise = Promise.resolve();
290
293
  await this.p2pService.start();
@@ -332,7 +335,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
332
335
  return this.p2pService.addReqRespSubProtocol(subProtocol, handler, validator);
333
336
  }
334
337
 
335
- private initBlockStream(startingBlock?: number) {
338
+ private initBlockStream(startingBlock?: BlockNumber) {
336
339
  if (!this.blockStream) {
337
340
  const { blockRequestBatchSize: batchSize, blockCheckIntervalMS: pollIntervalMS } = this.config;
338
341
  this.blockStream = new TraceableL2BlockStream(
@@ -371,16 +374,21 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
371
374
  }
372
375
 
373
376
  @trackSpan('p2pClient.broadcastProposal', async proposal => ({
374
- [Attributes.SLOT_NUMBER]: proposal.slotNumber.toNumber(),
377
+ [Attributes.SLOT_NUMBER]: proposal.slotNumber,
375
378
  [Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
376
- [Attributes.P2P_ID]: (await proposal.p2pMessageIdentifier()).toString(),
379
+ [Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString(),
377
380
  }))
378
381
  public broadcastProposal(proposal: BlockProposal): Promise<void> {
379
- this.log.verbose(`Broadcasting proposal for slot ${proposal.slotNumber.toNumber()} to peers`);
382
+ this.log.verbose(`Broadcasting proposal for slot ${proposal.slotNumber} to peers`);
380
383
  return this.p2pService.propagate(proposal);
381
384
  }
382
385
 
383
- public async getAttestationsForSlot(slot: bigint, proposalId?: string): Promise<BlockAttestation[]> {
386
+ public async broadcastAttestations(attestations: BlockAttestation[]): Promise<void> {
387
+ this.log.verbose(`Broadcasting ${attestations.length} attestations to peers`);
388
+ await Promise.all(attestations.map(att => this.p2pService.propagate(att)));
389
+ }
390
+
391
+ public async getAttestationsForSlot(slot: SlotNumber, proposalId?: string): Promise<BlockAttestation[]> {
384
392
  return (
385
393
  (await (proposalId
386
394
  ? this.attestationPool?.getAttestationsForSlotAndProposal(slot, proposalId)
@@ -643,20 +651,20 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
643
651
  * Public function to check the latest block number that the P2P client is synced to.
644
652
  * @returns Block number of latest L2 Block we've synced with.
645
653
  */
646
- public async getSyncedLatestBlockNum(): Promise<number> {
647
- return (await this.synchedLatestBlockNumber.getAsync()) ?? INITIAL_L2_BLOCK_NUM - 1;
654
+ public async getSyncedLatestBlockNum(): Promise<BlockNumber> {
655
+ return (await this.synchedLatestBlockNumber.getAsync()) ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
648
656
  }
649
657
 
650
658
  /**
651
659
  * Public function to check the latest proven block number that the P2P client is synced to.
652
660
  * @returns Block number of latest proven L2 Block we've synced with.
653
661
  */
654
- public async getSyncedProvenBlockNum(): Promise<number> {
655
- return (await this.synchedProvenBlockNumber.getAsync()) ?? INITIAL_L2_BLOCK_NUM - 1;
662
+ public async getSyncedProvenBlockNum(): Promise<BlockNumber> {
663
+ return (await this.synchedProvenBlockNumber.getAsync()) ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
656
664
  }
657
665
 
658
- public async getSyncedFinalizedBlockNum(): Promise<number> {
659
- return (await this.synchedFinalizedBlockNumber.getAsync()) ?? INITIAL_L2_BLOCK_NUM - 1;
666
+ public async getSyncedFinalizedBlockNum(): Promise<BlockNumber> {
667
+ return (await this.synchedFinalizedBlockNumber.getAsync()) ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
660
668
  }
661
669
 
662
670
  /** Returns latest L2 slot for which we have seen an L2 block. */
@@ -672,7 +680,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
672
680
  const blockNumber = await this.getSyncedLatestBlockNum();
673
681
  const blockHash =
674
682
  blockNumber === 0
675
- ? ''
683
+ ? GENESIS_BLOCK_HEADER_HASH.toString()
676
684
  : await this.l2BlockSource
677
685
  .getBlockHeader(blockNumber)
678
686
  .then(header => header?.hash())
@@ -680,8 +688,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
680
688
 
681
689
  return {
682
690
  state: this.currentState,
683
- syncedToL2Block: { number: blockNumber, hash: blockHash },
684
- } as P2PSyncState;
691
+ syncedToL2Block: { number: blockNumber, hash: blockHash! },
692
+ };
685
693
  }
686
694
 
687
695
  /**
@@ -689,10 +697,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
689
697
  * @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
690
698
  * @returns Empty promise.
691
699
  */
692
- private async markTxsAsMinedFromBlocks(blocks: L2Block[]): Promise<void> {
700
+ private async markTxsAsMinedFromBlocks(blocks: L2BlockNew[]): Promise<void> {
693
701
  for (const block of blocks) {
694
702
  const txHashes = block.body.txEffects.map(txEffect => txEffect.txHash);
695
- await this.txPool.markAsMined(txHashes, block.getBlockHeader());
703
+ await this.txPool.markAsMined(txHashes, block.header);
696
704
  }
697
705
  }
698
706
 
@@ -701,33 +709,33 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
701
709
  * @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
702
710
  * @returns Empty promise.
703
711
  */
704
- private async handleLatestL2Blocks(blocks: PublishedL2Block[]): Promise<void> {
712
+ private async handleLatestL2Blocks(blocks: L2BlockNew[]): Promise<void> {
705
713
  if (!blocks.length) {
706
714
  return Promise.resolve();
707
715
  }
708
716
 
709
- await this.markTxsAsMinedFromBlocks(blocks.map(b => b.block));
710
- await this.startCollectingMissingTxs(blocks.map(b => b.block));
717
+ await this.markTxsAsMinedFromBlocks(blocks);
718
+ await this.startCollectingMissingTxs(blocks);
711
719
 
712
- const lastBlock = blocks.at(-1)!.block;
720
+ const lastBlock = blocks.at(-1)!;
713
721
 
714
722
  await Promise.all(
715
723
  blocks.map(async block =>
716
724
  this.setBlockHash({
717
- number: block.block.number,
718
- hash: await block.block.hash().then(h => h.toString()),
725
+ number: block.number,
726
+ hash: await block.hash().then(h => h.toString()),
719
727
  }),
720
728
  ),
721
729
  );
722
730
 
723
731
  await this.synchedLatestBlockNumber.set(lastBlock.number);
724
- await this.synchedLatestSlot.set(lastBlock.header.getSlot());
732
+ await this.synchedLatestSlot.set(BigInt(lastBlock.header.getSlot()));
725
733
  this.log.verbose(`Synched to latest block ${lastBlock.number}`);
726
734
  await this.startServiceIfSynched();
727
735
  }
728
736
 
729
737
  /** Request txs for unproven blocks so the prover node has more chances to get them. */
730
- private async startCollectingMissingTxs(blocks: L2Block[]): Promise<void> {
738
+ private async startCollectingMissingTxs(blocks: L2BlockNew[]): Promise<void> {
731
739
  try {
732
740
  // TODO(#15435): If the archiver has lagged behind L1, the reported proven block number may
733
741
  // be much lower than the actual one, and it does not update until the pending chain is
@@ -760,7 +768,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
760
768
  * @param blocks - A list of finalized L2 blocks.
761
769
  * @returns Empty promise.
762
770
  */
763
- private async handleFinalizedL2Blocks(blocks: L2Block[]): Promise<void> {
771
+ private async handleFinalizedL2Blocks(blocks: L2BlockNew[]): Promise<void> {
764
772
  if (!blocks.length) {
765
773
  return Promise.resolve();
766
774
  }
@@ -786,7 +794,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
786
794
  * Updates the tx pool after a chain prune.
787
795
  * @param latestBlock - The block number the chain was pruned to.
788
796
  */
789
- private async handlePruneL2Blocks(latestBlock: number): Promise<void> {
797
+ private async handlePruneL2Blocks(latestBlock: BlockNumber): Promise<void> {
790
798
  const txsToDelete = new Map<string, TxHash>();
791
799
  const minedTxs = await this.txPool.getMinedTxHashes();
792
800
 
package/src/config.ts CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  pickConfigMappings,
10
10
  secretStringConfigHelper,
11
11
  } from '@aztec/foundation/config';
12
- import { Fr } from '@aztec/foundation/fields';
12
+ import { Fr } from '@aztec/foundation/curves/bn254';
13
13
  import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
14
14
  import { FunctionSelector } from '@aztec/stdlib/abi';
15
15
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -164,6 +164,12 @@ export interface P2PConfig extends P2PReqRespConfig, ChainConfig, TxCollectionCo
164
164
 
165
165
  /** Whether to delete transactions from the pool after a reorg instead of moving them back to pending. */
166
166
  txPoolDeleteTxsAfterReorg: boolean;
167
+
168
+ /** Alters the format of p2p messages to include things like broadcast timestamp FOR TESTING ONLY */
169
+ debugP2PInstrumentMessages: boolean;
170
+
171
+ /** Whether to run in fisherman mode: validates all proposals and attestations but does not broadcast attestations or participate in consensus */
172
+ fishermanMode: boolean;
167
173
  }
168
174
 
169
175
  export const DEFAULT_P2P_PORT = 40400;
@@ -406,7 +412,7 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
406
412
  },
407
413
  dropTransactionsProbability: {
408
414
  env: 'P2P_DROP_TX_CHANCE',
409
- description: 'The probability that a transaction is discarded. - For testing purposes only',
415
+ description: 'The probability that a transaction is discarded (0 - 1). - For testing purposes only',
410
416
  ...floatConfigHelper(0),
411
417
  },
412
418
  disableTransactions: {
@@ -420,6 +426,17 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
420
426
  description: 'Whether to delete transactions from the pool after a reorg instead of moving them back to pending.',
421
427
  ...booleanConfigHelper(false),
422
428
  },
429
+ debugP2PInstrumentMessages: {
430
+ env: 'DEBUG_P2P_INSTRUMENT_MESSAGES',
431
+ description: 'Alters the format of p2p messages to include things like broadcast timestamp FOR TESTING ONLY',
432
+ ...booleanConfigHelper(false),
433
+ },
434
+ fishermanMode: {
435
+ env: 'FISHERMAN_MODE',
436
+ description:
437
+ 'Whether to run in fisherman mode: validates all proposals and attestations but does not broadcast attestations or participate in consensus.',
438
+ ...booleanConfigHelper(false),
439
+ },
423
440
  ...p2pReqRespConfigMappings,
424
441
  ...chainConfigMappings,
425
442
  ...txCollectionConfigMappings,
@@ -0,0 +1,13 @@
1
+ export class AttestationPoolError extends Error {
2
+ constructor(message?: string) {
3
+ super(message);
4
+ this.name = 'AttestationPoolError';
5
+ }
6
+ }
7
+
8
+ export class ProposalSlotCapExceededError extends AttestationPoolError {
9
+ constructor(message?: string) {
10
+ super(message);
11
+ this.name = 'ProposalSlotCapExceededError';
12
+ }
13
+ }
@@ -1,3 +1,4 @@
1
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
1
2
  import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
2
3
 
3
4
  /**
@@ -21,6 +22,15 @@ export interface AttestationPool {
21
22
  */
22
23
  getBlockProposal(id: string): Promise<BlockProposal | undefined>;
23
24
 
25
+ /**
26
+ * Check if a block proposal exists in the pool
27
+ *
28
+ * @param idOrProposal - The ID of the block proposal or the block proposal itself to check. The ID is proposal.payload.archive
29
+ *
30
+ * @return True if the block proposal exists, false otherwise.
31
+ */
32
+ hasBlockProposal(idOrProposal: string | BlockProposal): Promise<boolean>;
33
+
24
34
  /**
25
35
  * AddAttestations
26
36
  *
@@ -42,7 +52,7 @@ export interface AttestationPool {
42
52
  *
43
53
  * @param slot - The oldest slot to keep.
44
54
  */
45
- deleteAttestationsOlderThan(slot: bigint): Promise<void>;
55
+ deleteAttestationsOlderThan(slot: SlotNumber): Promise<void>;
46
56
 
47
57
  /**
48
58
  * Delete Attestations for slot
@@ -51,7 +61,7 @@ export interface AttestationPool {
51
61
  *
52
62
  * @param slot - The slot to delete.
53
63
  */
54
- deleteAttestationsForSlot(slot: bigint): Promise<void>;
64
+ deleteAttestationsForSlot(slot: SlotNumber): Promise<void>;
55
65
 
56
66
  /**
57
67
  * Delete Attestations for slot and proposal
@@ -61,7 +71,7 @@ export interface AttestationPool {
61
71
  * @param slot - The slot to delete.
62
72
  * @param proposalId - The proposal to delete.
63
73
  */
64
- deleteAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<void>;
74
+ deleteAttestationsForSlotAndProposal(slot: SlotNumber, proposalId: string): Promise<void>;
65
75
 
66
76
  /**
67
77
  * Get all Attestations for all proposals for a given slot
@@ -71,7 +81,7 @@ export interface AttestationPool {
71
81
  * @param slot - The slot to query
72
82
  * @return BlockAttestations
73
83
  */
74
- getAttestationsForSlot(slot: bigint): Promise<BlockAttestation[]>;
84
+ getAttestationsForSlot(slot: SlotNumber): Promise<BlockAttestation[]>;
75
85
 
76
86
  /**
77
87
  * Get Attestations for slot and given proposal
@@ -82,7 +92,38 @@ export interface AttestationPool {
82
92
  * @param proposalId - The proposal to query
83
93
  * @return BlockAttestations
84
94
  */
85
- getAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<BlockAttestation[]>;
95
+ getAttestationsForSlotAndProposal(slot: SlotNumber, proposalId: string): Promise<BlockAttestation[]>;
96
+
97
+ /**
98
+ * Check if a specific attestation exists in the pool
99
+ *
100
+ * @param attestation - The attestation to check
101
+ * @return True if the attestation exists, false otherwise
102
+ */
103
+ hasAttestation(attestation: BlockAttestation): Promise<boolean>;
104
+
105
+ /**
106
+ * Returns whether adding this proposal is permitted at current capacity:
107
+ * - True if the proposal already exists, allow overwrite to keep parity with tests.
108
+ * - True if the slot is below the proposal cap.
109
+ * - False if the slot is at/above cap and this would be a new unique proposal.
110
+ *
111
+ * @param block - The block proposal to check
112
+ * @returns True if the proposal can be added (or already exists), false otherwise.
113
+ */
114
+ canAddProposal(block: BlockProposal): Promise<boolean>;
115
+
116
+ /**
117
+ * Returns whether an attestation would be accepted for (slot, proposalId):
118
+ * - True if the attestation already exists for this sender.
119
+ * - True if the attestation cap for (slot, proposalId) has not been reached.
120
+ * - False if the cap is reached and this attestation would be a new unique entry.
121
+ *
122
+ * @param attestation - The attestation to check
123
+ * @param committeeSize - Committee size for the attestation's slot, implementation may add a small buffer
124
+ * @returns True if the attestation can be added, false otherwise.
125
+ */
126
+ canAddAttestation(attestation: BlockAttestation, committeeSize: number): Promise<boolean>;
86
127
 
87
128
  /** Returns whether the pool is empty. */
88
129
  isEmpty(): Promise<boolean>;