@aztec/p2p 0.76.4 → 0.77.0-testnet-ignition.21

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 (241) hide show
  1. package/dest/bootstrap/bootstrap.d.ts +2 -2
  2. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  3. package/dest/bootstrap/bootstrap.js +55 -41
  4. package/dest/client/factory.d.ts +8 -6
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +8 -10
  7. package/dest/client/index.js +0 -1
  8. package/dest/client/p2p_client.d.ts +7 -4
  9. package/dest/client/p2p_client.d.ts.map +1 -1
  10. package/dest/client/p2p_client.js +492 -514
  11. package/dest/config.d.ts +8 -10
  12. package/dest/config.d.ts.map +1 -1
  13. package/dest/config.js +54 -47
  14. package/dest/enr/generate-enr.d.ts +9 -0
  15. package/dest/enr/generate-enr.d.ts.map +1 -0
  16. package/dest/enr/generate-enr.js +30 -0
  17. package/dest/enr/index.d.ts +2 -0
  18. package/dest/enr/index.d.ts.map +1 -0
  19. package/dest/enr/index.js +1 -0
  20. package/dest/errors/reqresp.error.js +6 -10
  21. package/dest/index.js +0 -1
  22. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +1 -1
  23. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  24. package/dest/mem_pools/attestation_pool/attestation_pool.js +6 -2
  25. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  26. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  27. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +65 -33
  28. package/dest/mem_pools/attestation_pool/index.js +0 -1
  29. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +3 -3
  30. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  31. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +23 -20
  32. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +2 -2
  33. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  34. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +22 -26
  35. package/dest/mem_pools/attestation_pool/mocks.d.ts +3 -2
  36. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  37. package/dest/mem_pools/attestation_pool/mocks.js +12 -7
  38. package/dest/mem_pools/index.d.ts +2 -2
  39. package/dest/mem_pools/index.d.ts.map +1 -1
  40. package/dest/mem_pools/index.js +1 -2
  41. package/dest/mem_pools/instrumentation.d.ts +1 -1
  42. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  43. package/dest/mem_pools/instrumentation.js +35 -39
  44. package/dest/mem_pools/interface.d.ts +3 -3
  45. package/dest/mem_pools/interface.d.ts.map +1 -1
  46. package/dest/mem_pools/interface.js +3 -2
  47. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +2 -2
  48. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +129 -136
  50. package/dest/mem_pools/tx_pool/index.js +0 -1
  51. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +2 -2
  52. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
  53. package/dest/mem_pools/tx_pool/memory_tx_pool.js +46 -44
  54. package/dest/mem_pools/tx_pool/priority.d.ts +1 -1
  55. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
  56. package/dest/mem_pools/tx_pool/priority.js +1 -3
  57. package/dest/mem_pools/tx_pool/tx_pool.d.ts +1 -1
  58. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  59. package/dest/mem_pools/tx_pool/tx_pool.js +3 -2
  60. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  61. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  62. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +109 -39
  63. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +2 -2
  64. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  65. package/dest/msg_validators/attestation_validator/attestation_validator.js +4 -4
  66. package/dest/msg_validators/attestation_validator/index.js +0 -1
  67. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +2 -2
  68. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
  69. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +3 -3
  70. package/dest/msg_validators/block_proposal_validator/index.js +0 -1
  71. package/dest/msg_validators/index.js +0 -1
  72. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
  73. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  74. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +9 -11
  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/block_header_validator.js +18 -13
  78. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  79. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  80. package/dest/msg_validators/tx_validator/data_validator.js +102 -33
  81. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +1 -1
  82. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  83. package/dest/msg_validators/tx_validator/double_spend_validator.js +34 -20
  84. package/dest/msg_validators/tx_validator/index.js +0 -1
  85. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +2 -2
  86. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  87. package/dest/msg_validators/tx_validator/metadata_validator.js +30 -27
  88. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +2 -1
  89. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  90. package/dest/msg_validators/tx_validator/tx_proof_validator.js +17 -12
  91. package/dest/services/data_store.js +57 -57
  92. package/dest/services/discv5/discV5_service.d.ts +2 -0
  93. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  94. package/dest/services/discv5/discV5_service.js +64 -36
  95. package/dest/services/dummy_service.d.ts +4 -2
  96. package/dest/services/dummy_service.d.ts.map +1 -1
  97. package/dest/services/dummy_service.js +41 -59
  98. package/dest/services/encoding.d.ts +3 -3
  99. package/dest/services/encoding.d.ts.map +1 -1
  100. package/dest/services/encoding.js +10 -9
  101. package/dest/services/gossipsub/scoring.d.ts +7 -0
  102. package/dest/services/gossipsub/scoring.d.ts.map +1 -0
  103. package/dest/services/gossipsub/scoring.js +10 -0
  104. package/dest/services/index.js +0 -1
  105. package/dest/services/libp2p/libp2p_service.d.ts +10 -33
  106. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  107. package/dest/services/libp2p/libp2p_service.js +682 -673
  108. package/dest/services/peer-manager/metrics.js +14 -7
  109. package/dest/services/peer-manager/peer_manager.d.ts +24 -6
  110. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  111. package/dest/services/peer-manager/peer_manager.js +390 -340
  112. package/dest/services/peer-manager/peer_scoring.d.ts +3 -3
  113. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  114. package/dest/services/peer-manager/peer_scoring.js +21 -19
  115. package/dest/services/reqresp/config.js +4 -5
  116. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +2 -2
  117. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  118. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +35 -28
  119. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -1
  120. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  121. package/dest/services/reqresp/connection-sampler/connection_sampler.js +67 -61
  122. package/dest/services/reqresp/index.js +1 -3
  123. package/dest/services/reqresp/interface.d.ts +2 -2
  124. package/dest/services/reqresp/interface.d.ts.map +1 -1
  125. package/dest/services/reqresp/interface.js +27 -31
  126. package/dest/services/reqresp/metrics.d.ts +1 -1
  127. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  128. package/dest/services/reqresp/metrics.js +23 -10
  129. package/dest/services/reqresp/protocols/block.d.ts +2 -2
  130. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  131. package/dest/services/reqresp/protocols/block.js +1 -2
  132. package/dest/services/reqresp/protocols/goodbye.d.ts +5 -5
  133. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
  134. package/dest/services/reqresp/protocols/goodbye.js +36 -41
  135. package/dest/services/reqresp/protocols/index.js +1 -3
  136. package/dest/services/reqresp/protocols/ping.js +1 -3
  137. package/dest/services/reqresp/protocols/status.js +1 -3
  138. package/dest/services/reqresp/protocols/tx.d.ts +3 -3
  139. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  140. package/dest/services/reqresp/protocols/tx.js +6 -9
  141. package/dest/services/reqresp/rate-limiter/index.js +0 -1
  142. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +9 -9
  143. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  144. package/dest/services/reqresp/rate-limiter/rate_limiter.js +53 -46
  145. package/dest/services/reqresp/rate-limiter/rate_limits.js +16 -17
  146. package/dest/services/reqresp/reqresp.d.ts +4 -4
  147. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  148. package/dest/services/reqresp/reqresp.js +467 -464
  149. package/dest/services/reqresp/status.js +16 -17
  150. package/dest/services/service.d.ts +3 -2
  151. package/dest/services/service.d.ts.map +1 -1
  152. package/dest/services/service.js +3 -4
  153. package/dest/test-helpers/generate-peer-id-private-keys.js +2 -4
  154. package/dest/test-helpers/get-ports.js +3 -3
  155. package/dest/test-helpers/index.js +0 -1
  156. package/dest/test-helpers/make-enrs.d.ts +1 -1
  157. package/dest/test-helpers/make-enrs.d.ts.map +1 -1
  158. package/dest/test-helpers/make-enrs.js +3 -6
  159. package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -6
  160. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  161. package/dest/test-helpers/make-test-p2p-clients.js +10 -12
  162. package/dest/test-helpers/reqresp-nodes.d.ts +18 -7
  163. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  164. package/dest/test-helpers/reqresp-nodes.js +64 -40
  165. package/dest/testbench/p2p_client_testbench_worker.js +61 -45
  166. package/dest/testbench/parse_log_file.d.ts +2 -0
  167. package/dest/testbench/parse_log_file.d.ts.map +1 -0
  168. package/dest/testbench/parse_log_file.js +131 -0
  169. package/dest/testbench/testbench.d.ts +2 -0
  170. package/dest/testbench/testbench.d.ts.map +1 -0
  171. package/dest/testbench/testbench.js +141 -0
  172. package/dest/{services/types.d.ts → types/index.d.ts} +1 -1
  173. package/dest/types/index.d.ts.map +1 -0
  174. package/dest/types/index.js +28 -0
  175. package/dest/util.d.ts +5 -5
  176. package/dest/util.d.ts.map +1 -1
  177. package/dest/util.js +23 -34
  178. package/dest/versioning.d.ts +3 -3
  179. package/dest/versioning.d.ts.map +1 -1
  180. package/dest/versioning.js +7 -12
  181. package/package.json +15 -13
  182. package/src/bootstrap/bootstrap.ts +30 -17
  183. package/src/client/factory.ts +9 -12
  184. package/src/client/p2p_client.ts +13 -24
  185. package/src/config.ts +14 -15
  186. package/src/enr/generate-enr.ts +39 -0
  187. package/src/enr/index.ts +1 -0
  188. package/src/mem_pools/attestation_pool/attestation_pool.ts +1 -1
  189. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +4 -3
  190. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +3 -3
  191. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +2 -2
  192. package/src/mem_pools/attestation_pool/mocks.ts +5 -5
  193. package/src/mem_pools/index.ts +2 -2
  194. package/src/mem_pools/instrumentation.ts +4 -3
  195. package/src/mem_pools/interface.ts +3 -3
  196. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +4 -4
  197. package/src/mem_pools/tx_pool/memory_tx_pool.ts +3 -3
  198. package/src/mem_pools/tx_pool/priority.ts +1 -1
  199. package/src/mem_pools/tx_pool/tx_pool.ts +1 -1
  200. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +4 -3
  201. package/src/msg_validators/attestation_validator/attestation_validator.ts +2 -2
  202. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +2 -2
  203. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +1 -1
  204. package/src/msg_validators/tx_validator/block_header_validator.ts +2 -2
  205. package/src/msg_validators/tx_validator/data_validator.ts +57 -4
  206. package/src/msg_validators/tx_validator/double_spend_validator.ts +17 -12
  207. package/src/msg_validators/tx_validator/metadata_validator.ts +2 -2
  208. package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -6
  209. package/src/services/discv5/discV5_service.ts +33 -8
  210. package/src/services/dummy_service.ts +4 -2
  211. package/src/services/encoding.ts +3 -3
  212. package/src/services/gossipsub/scoring.ts +13 -0
  213. package/src/services/libp2p/libp2p_service.ts +124 -146
  214. package/src/services/peer-manager/peer_manager.ts +71 -13
  215. package/src/services/peer-manager/peer_scoring.ts +3 -3
  216. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +2 -2
  217. package/src/services/reqresp/connection-sampler/connection_sampler.ts +9 -3
  218. package/src/services/reqresp/interface.ts +4 -3
  219. package/src/services/reqresp/metrics.ts +1 -1
  220. package/src/services/reqresp/protocols/block.ts +3 -3
  221. package/src/services/reqresp/protocols/goodbye.ts +7 -7
  222. package/src/services/reqresp/protocols/tx.ts +5 -5
  223. package/src/services/reqresp/rate-limiter/rate_limiter.ts +22 -18
  224. package/src/services/reqresp/reqresp.ts +18 -11
  225. package/src/services/service.ts +3 -2
  226. package/src/test-helpers/make-enrs.ts +1 -1
  227. package/src/test-helpers/make-test-p2p-clients.ts +9 -7
  228. package/src/test-helpers/reqresp-nodes.ts +32 -18
  229. package/src/testbench/p2p_client_testbench_worker.ts +16 -9
  230. package/src/testbench/parse_log_file.ts +175 -0
  231. package/src/testbench/testbench.ts +157 -0
  232. package/src/util.ts +5 -5
  233. package/src/versioning.ts +7 -7
  234. package/dest/services/libp2p/libp2p_logger.d.ts +0 -7
  235. package/dest/services/libp2p/libp2p_logger.d.ts.map +0 -1
  236. package/dest/services/libp2p/libp2p_logger.js +0 -67
  237. package/dest/services/types.d.ts.map +0 -1
  238. package/dest/services/types.js +0 -35
  239. package/src/services/libp2p/libp2p_logger.ts +0 -78
  240. package/src/testbench/scripts/run_testbench.sh +0 -7
  241. /package/src/{services/types.ts → types/index.ts} +0 -0
@@ -1,9 +1,9 @@
1
- import { type BlockAttestation } from '@aztec/circuit-types';
2
1
  import { createLogger } from '@aztec/foundation/log';
2
+ import type { BlockAttestation } from '@aztec/stdlib/p2p';
3
3
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
4
4
 
5
5
  import { PoolInstrumentation, PoolName } from '../instrumentation.js';
6
- import { type AttestationPool } from './attestation_pool.js';
6
+ import type { AttestationPool } from './attestation_pool.js';
7
7
 
8
8
  export class InMemoryAttestationPool implements AttestationPool {
9
9
  private metrics: PoolInstrumentation<BlockAttestation>;
@@ -1,13 +1,13 @@
1
+ import type { Secp256k1Signer } from '@aztec/foundation/crypto';
2
+ import { Fr } from '@aztec/foundation/fields';
1
3
  import {
2
4
  BlockAttestation,
3
5
  ConsensusPayload,
4
6
  SignatureDomainSeparator,
5
- TxHash,
6
7
  getHashedSignaturePayloadEthSignedMessage,
7
- } from '@aztec/circuit-types';
8
- import { makeHeader } from '@aztec/circuits.js/testing';
9
- import { type Secp256k1Signer } from '@aztec/foundation/crypto';
10
- import { Fr } from '@aztec/foundation/fields';
8
+ } from '@aztec/stdlib/p2p';
9
+ import { makeHeader } from '@aztec/stdlib/testing';
10
+ import { TxHash } from '@aztec/stdlib/tx';
11
11
 
12
12
  import { type LocalAccount, generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
13
13
 
@@ -1,3 +1,3 @@
1
- export { AttestationPool } from './attestation_pool/attestation_pool.js';
1
+ export { type AttestationPool } from './attestation_pool/attestation_pool.js';
2
2
  export { type MemPools } from './interface.js';
3
- export { TxPool } from './tx_pool/tx_pool.js';
3
+ export { type TxPool } from './tx_pool/tx_pool.js';
@@ -1,10 +1,11 @@
1
- import { type Gossipable } from '@aztec/circuit-types';
1
+ import type { Gossipable } from '@aztec/stdlib/p2p';
2
2
  import {
3
3
  Attributes,
4
4
  type Histogram,
5
5
  LmdbMetrics,
6
6
  type LmdbStatsCallback,
7
7
  Metrics,
8
+ type MetricsType,
8
9
  type TelemetryClient,
9
10
  type UpDownCounter,
10
11
  } from '@aztec/telemetry-client';
@@ -15,8 +16,8 @@ export enum PoolName {
15
16
  }
16
17
 
17
18
  type MetricsLabels = {
18
- objectInMempool: Metrics;
19
- objectSize: Metrics;
19
+ objectInMempool: MetricsType;
20
+ objectSize: MetricsType;
20
21
  };
21
22
 
22
23
  /**
@@ -1,7 +1,7 @@
1
- import { type P2PClientType } from '@aztec/circuit-types';
1
+ import type { P2PClientType } from '@aztec/stdlib/p2p';
2
2
 
3
- import { type AttestationPool } from './attestation_pool/attestation_pool.js';
4
- import { type TxPool } from './tx_pool/tx_pool.js';
3
+ import type { AttestationPool } from './attestation_pool/attestation_pool.js';
4
+ import type { TxPool } from './tx_pool/tx_pool.js';
5
5
 
6
6
  /**
7
7
  * A interface the combines all mempools
@@ -1,14 +1,14 @@
1
- import { Tx, TxHash } from '@aztec/circuit-types';
2
- import { type TxAddedToPoolStats } from '@aztec/circuit-types/stats';
3
- import { ClientIvcProof } from '@aztec/circuits.js';
4
1
  import { toArray } from '@aztec/foundation/iterable';
5
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
6
3
  import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec/kv-store';
4
+ import { ClientIvcProof } from '@aztec/stdlib/proofs';
5
+ import type { TxAddedToPoolStats } from '@aztec/stdlib/stats';
6
+ import { Tx, TxHash } from '@aztec/stdlib/tx';
7
7
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
8
8
 
9
9
  import { PoolInstrumentation, PoolName } from '../instrumentation.js';
10
10
  import { getPendingTxPriority } from './priority.js';
11
- import { type TxPool } from './tx_pool.js';
11
+ import type { TxPool } from './tx_pool.js';
12
12
 
13
13
  /**
14
14
  * KV implementation of the Transaction Pool.
@@ -1,11 +1,11 @@
1
- import { Tx, TxHash } from '@aztec/circuit-types';
2
- import { type TxAddedToPoolStats } from '@aztec/circuit-types/stats';
3
1
  import { createLogger } from '@aztec/foundation/log';
2
+ import type { TxAddedToPoolStats } from '@aztec/stdlib/stats';
3
+ import { Tx, TxHash } from '@aztec/stdlib/tx';
4
4
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
5
5
 
6
6
  import { PoolInstrumentation, PoolName } from '../instrumentation.js';
7
7
  import { getPendingTxPriority } from './priority.js';
8
- import { type TxPool } from './tx_pool.js';
8
+ import type { TxPool } from './tx_pool.js';
9
9
 
10
10
  /**
11
11
  * In-memory implementation of the Transaction Pool.
@@ -1,5 +1,5 @@
1
- import { type Tx } from '@aztec/circuit-types';
2
1
  import { Buffer32 } from '@aztec/foundation/buffer';
2
+ import type { Tx } from '@aztec/stdlib/tx';
3
3
 
4
4
  /**
5
5
  * Returns a string representing the priority of a tx.
@@ -1,4 +1,4 @@
1
- import { type Tx, type TxHash } from '@aztec/circuit-types';
1
+ import type { Tx, TxHash } from '@aztec/stdlib/tx';
2
2
 
3
3
  /**
4
4
  * Interface of a transaction pool. The pool includes tx requests and is kept up-to-date by a P2P client.
@@ -1,8 +1,9 @@
1
- import { type Tx, mockTx } from '@aztec/circuit-types';
2
- import { GasFees } from '@aztec/circuits.js';
3
1
  import { unfreeze } from '@aztec/foundation/types';
2
+ import { GasFees } from '@aztec/stdlib/gas';
3
+ import { mockTx } from '@aztec/stdlib/testing';
4
+ import type { Tx } from '@aztec/stdlib/tx';
4
5
 
5
- import { type TxPool } from './tx_pool.js';
6
+ import type { TxPool } from './tx_pool.js';
6
7
 
7
8
  /**
8
9
  * Tests a TxPool implementation.
@@ -1,5 +1,5 @@
1
- import { type BlockAttestation, type P2PValidator, PeerErrorSeverity } from '@aztec/circuit-types';
2
- import { type EpochCacheInterface } from '@aztec/epoch-cache';
1
+ import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
+ import { type BlockAttestation, type P2PValidator, PeerErrorSeverity } from '@aztec/stdlib/p2p';
3
3
 
4
4
  export class AttestationValidator implements P2PValidator<BlockAttestation> {
5
5
  private epochCache: EpochCacheInterface;
@@ -1,5 +1,5 @@
1
- import { type BlockProposal, type P2PValidator, PeerErrorSeverity } from '@aztec/circuit-types';
2
- import { type EpochCacheInterface } from '@aztec/epoch-cache';
1
+ import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
+ import { type BlockProposal, type P2PValidator, PeerErrorSeverity } from '@aztec/stdlib/p2p';
3
3
 
4
4
  export class BlockProposalValidator implements P2PValidator<BlockProposal> {
5
5
  private epochCache: EpochCacheInterface;
@@ -1,4 +1,4 @@
1
- import { type ProcessedTx, type Tx, type TxValidationResult, type TxValidator } from '@aztec/circuit-types';
1
+ import type { ProcessedTx, Tx, TxValidationResult, TxValidator } from '@aztec/stdlib/tx';
2
2
 
3
3
  export class AggregateTxValidator<T extends Tx | ProcessedTx> implements TxValidator<T> {
4
4
  #validators: TxValidator<T>[];
@@ -1,6 +1,6 @@
1
- import { type AnyTx, Tx, type TxValidationResult, type TxValidator } from '@aztec/circuit-types';
2
- import { type Fr } from '@aztec/circuits.js';
1
+ import type { Fr } from '@aztec/foundation/fields';
3
2
  import { createLogger } from '@aztec/foundation/log';
3
+ import { type AnyTx, Tx, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
4
4
 
5
5
  export interface ArchiveSource {
6
6
  getArchiveIndices: (archives: Fr[]) => Promise<(bigint | undefined)[]>;
@@ -1,11 +1,14 @@
1
- import { Tx, type TxValidationResult, type TxValidator } from '@aztec/circuit-types';
1
+ import { MAX_FR_ARGS_TO_ALL_ENQUEUED_CALLS } from '@aztec/constants';
2
2
  import { createLogger } from '@aztec/foundation/log';
3
+ import { Tx, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
3
4
 
4
5
  export class DataTxValidator implements TxValidator<Tx> {
5
6
  #log = createLogger('p2p:tx_validator:tx_data');
6
7
 
7
- validateTx(tx: Tx): Promise<TxValidationResult> {
8
- return this.#hasCorrectExecutionRequests(tx);
8
+ async validateTx(tx: Tx): Promise<TxValidationResult> {
9
+ const execRequestRes = this.#hasCorrectExecutionRequests(tx);
10
+ // Note: If we ever skip txs here, must change this return statement to account for them.
11
+ return (await execRequestRes).result === 'invalid' ? execRequestRes : this.#hasCorrectContractClassLogs(tx);
9
12
  }
10
13
 
11
14
  async #hasCorrectExecutionRequests(tx: Tx): Promise<TxValidationResult> {
@@ -21,6 +24,15 @@ export class DataTxValidator implements TxValidator<Tx> {
21
24
  );
22
25
  return { result: 'invalid', reason: ['Wrong number of execution requests for public calls'] };
23
26
  }
27
+
28
+ if (tx.getTotalPublicArgsCount() > MAX_FR_ARGS_TO_ALL_ENQUEUED_CALLS) {
29
+ this.#log.warn(
30
+ `Rejecting tx ${await Tx.getHash(
31
+ tx,
32
+ )} because the total length of args to public enqueued calls is greater than ${MAX_FR_ARGS_TO_ALL_ENQUEUED_CALLS}`,
33
+ );
34
+ return { result: 'invalid', reason: ['Too many args in total to enqueued public calls'] };
35
+ }
24
36
  const invalidExecutionRequestIndex = (
25
37
  await Promise.all(
26
38
  tx.enqueuedPublicFunctionCalls.map(
@@ -49,5 +61,46 @@ export class DataTxValidator implements TxValidator<Tx> {
49
61
  return { result: 'valid' };
50
62
  }
51
63
 
52
- // TODO: Check logs.
64
+ async #hasCorrectContractClassLogs(tx: Tx): Promise<TxValidationResult> {
65
+ const contractClassLogsHashes = tx.data.getNonEmptyContractClassLogsHashes();
66
+ const hashedContractClasslogs = await Promise.all(tx.contractClassLogs.map(l => l.hash()));
67
+ if (contractClassLogsHashes.length !== hashedContractClasslogs.length) {
68
+ this.#log.warn(
69
+ `Rejecting tx ${Tx.getHash(tx)} because of mismatched number of contract class logs. Expected ${
70
+ contractClassLogsHashes.length
71
+ }. Got ${hashedContractClasslogs.length}.`,
72
+ );
73
+ return { result: 'invalid', reason: ['Mismatched number of contract class logs'] };
74
+ }
75
+ for (const [i, logHash] of contractClassLogsHashes.entries()) {
76
+ const hashedLog = hashedContractClasslogs[i];
77
+ if (!logHash.value.equals(hashedLog)) {
78
+ if (hashedContractClasslogs.some(l => logHash.value.equals(l))) {
79
+ const matchingLogIndex = hashedContractClasslogs.findIndex(l => logHash.value.equals(l));
80
+ this.#log.warn(
81
+ `Rejecting tx ${Tx.getHash(
82
+ tx,
83
+ )} because of mismatched contract class logs indices. Expected ${i} from the kernel's log hashes. Got ${matchingLogIndex} in the tx.`,
84
+ );
85
+ return { result: 'invalid', reason: ['Incorrectly sorted contract class logs'] };
86
+ } else {
87
+ this.#log.warn(
88
+ `Rejecting tx ${Tx.getHash(tx)} because of mismatched contract class logs. Expected hash ${
89
+ logHash.value
90
+ } from the kernels. Got ${hashedLog} in the tx.`,
91
+ );
92
+ return { result: 'invalid', reason: ['Mismatched contract class logs'] };
93
+ }
94
+ }
95
+ if (logHash.logHash.length !== tx.contractClassLogs[i].getEmittedLength()) {
96
+ this.#log.warn(
97
+ `Rejecting tx ${Tx.getHash(tx)} because of mismatched contract class logs length. Expected ${
98
+ logHash.logHash.length
99
+ } from the kernel's log hashes. Got ${tx.contractClassLogs[i].getEmittedLength()} in the tx.`,
100
+ );
101
+ return { result: 'invalid', reason: ['Mismatched contract class logs length'] };
102
+ }
103
+ }
104
+ return { result: 'valid' };
105
+ }
53
106
  }
@@ -1,5 +1,5 @@
1
- import { type AnyTx, Tx, type TxValidationResult, type TxValidator } from '@aztec/circuit-types';
2
1
  import { createLogger } from '@aztec/foundation/log';
2
+ import { type AnyTx, Tx, type TxValidationResult, type TxValidator, hasPublicCalls } from '@aztec/stdlib/tx';
3
3
 
4
4
  export interface NullifierSource {
5
5
  nullifiersExist: (nullifiers: Buffer[]) => Promise<boolean[]>;
@@ -14,20 +14,25 @@ export class DoubleSpendTxValidator<T extends AnyTx> implements TxValidator<T> {
14
14
  }
15
15
 
16
16
  async validateTx(tx: T): Promise<TxValidationResult> {
17
- const nullifiers = tx instanceof Tx ? tx.data.getNonEmptyNullifiers() : tx.txEffect.nullifiers;
17
+ // Don't need to check for duplicate nullifiers if the tx has public calls
18
+ // because the AVM will perform merkle insertions as it goes and will fail on
19
+ // duplicate nullifier. In fact we CANNOT check here because the nullifiers
20
+ // have already been inserted, and so they will exist in nullifierSource.
21
+ if (!hasPublicCalls(tx)) {
22
+ const nullifiers = tx instanceof Tx ? tx.data.getNonEmptyNullifiers() : tx.txEffect.nullifiers;
18
23
 
19
- // Ditch this tx if it has repeated nullifiers
20
- const uniqueNullifiers = new Set(nullifiers);
21
- if (uniqueNullifiers.size !== nullifiers.length) {
22
- this.#log.warn(`Rejecting tx ${await Tx.getHash(tx)} for emitting duplicate nullifiers`);
23
- return { result: 'invalid', reason: ['Duplicate nullifier in tx'] };
24
- }
24
+ // Ditch this tx if it has repeated nullifiers
25
+ const uniqueNullifiers = new Set(nullifiers);
26
+ if (uniqueNullifiers.size !== nullifiers.length) {
27
+ this.#log.warn(`Rejecting tx ${await Tx.getHash(tx)} for emitting duplicate nullifiers`);
28
+ return { result: 'invalid', reason: ['Duplicate nullifier in tx'] };
29
+ }
25
30
 
26
- if ((await this.#nullifierSource.nullifiersExist(nullifiers.map(n => n.toBuffer()))).some(Boolean)) {
27
- this.#log.warn(`Rejecting tx ${await Tx.getHash(tx)} for repeating a nullifier`);
28
- return { result: 'invalid', reason: ['Existing nullifier'] };
31
+ if ((await this.#nullifierSource.nullifiersExist(nullifiers.map(n => n.toBuffer()))).some(Boolean)) {
32
+ this.#log.warn(`Rejecting tx ${await Tx.getHash(tx)} for repeating a nullifier`);
33
+ return { result: 'invalid', reason: ['Existing nullifier'] };
34
+ }
29
35
  }
30
-
31
36
  return { result: 'valid' };
32
37
  }
33
38
  }
@@ -1,6 +1,6 @@
1
- import { type AnyTx, Tx, type TxValidationResult, type TxValidator } from '@aztec/circuit-types';
2
- import { type Fr } from '@aztec/circuits.js';
1
+ import type { Fr } from '@aztec/foundation/fields';
3
2
  import { createLogger } from '@aztec/foundation/log';
3
+ import { type AnyTx, Tx, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
4
4
 
5
5
  export class MetadataTxValidator<T extends AnyTx> implements TxValidator<T> {
6
6
  #log = createLogger('p2p:tx_validator:tx_metadata');
@@ -1,10 +1,6 @@
1
- import {
2
- type ClientProtocolCircuitVerifier,
3
- Tx,
4
- type TxValidationResult,
5
- type TxValidator,
6
- } from '@aztec/circuit-types';
7
1
  import { createLogger } from '@aztec/foundation/log';
2
+ import type { ClientProtocolCircuitVerifier } from '@aztec/stdlib/interfaces/server';
3
+ import { Tx, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
8
4
 
9
5
  export class TxProofValidator implements TxValidator<Tx> {
10
6
  #log = createLogger('p2p:tx_validator:private_proof');
@@ -1,6 +1,6 @@
1
- import { type ComponentsVersions, checkCompressedComponentVersion } from '@aztec/circuit-types';
2
1
  import { createLogger } from '@aztec/foundation/log';
3
2
  import { sleep } from '@aztec/foundation/sleep';
3
+ import { type ComponentsVersions, checkCompressedComponentVersion } from '@aztec/stdlib/versioning';
4
4
  import { OtelMetricsAdapter, type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
5
5
 
6
6
  import { Discv5, type Discv5EventEmitter } from '@chainsafe/discv5';
@@ -10,10 +10,10 @@ import { type Multiaddr, multiaddr } from '@multiformats/multiaddr';
10
10
  import EventEmitter from 'events';
11
11
 
12
12
  import type { P2PConfig } from '../../config.js';
13
+ import { AZTEC_ENR_KEY, Discv5Event, PeerEvent } from '../../types/index.js';
13
14
  import { convertToMultiaddr } from '../../util.js';
14
15
  import { setAztecEnrKey } from '../../versioning.js';
15
16
  import { type PeerDiscoveryService, PeerDiscoveryState } from '../service.js';
16
- import { AZTEC_ENR_KEY, Discv5Event, PeerEvent } from '../types.js';
17
17
 
18
18
  const delayBeforeStart = 2000; // 2sec
19
19
 
@@ -37,6 +37,7 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
37
37
 
38
38
  public readonly bootstrapNodes: string[] = [];
39
39
  private bootstrapNodePeerIds: PeerId[] = [];
40
+ private bootstrapNodeEnrs: ENR[] = [];
40
41
 
41
42
  private startTime = 0;
42
43
 
@@ -49,6 +50,7 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
49
50
  super();
50
51
  const { tcpAnnounceAddress, udpAnnounceAddress, udpListenAddress, bootstrapNodes } = config;
51
52
  this.bootstrapNodes = bootstrapNodes ?? [];
53
+ this.bootstrapNodeEnrs = this.bootstrapNodes.map(x => ENR.decodeTxt(x));
52
54
  // create ENR from PeerId
53
55
  this.enr = SignableENR.createFromPeerId(peerId);
54
56
  // Add aztec identification to ENR
@@ -92,6 +94,11 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
92
94
  const origOnEstablished = this.discv5.onEstablished.bind(this.discv5);
93
95
  this.discv5.onEstablished = (...args: unknown[]) => {
94
96
  const enr = args[1] as ENR;
97
+ // A special case is for bootnodes. If this is a bootnode and we have been told to skip version checks
98
+ // then proceed straight to handling the event
99
+ if (!this.config.bootstrapNodeEnrVersionCheck && this.isOurBootnode(enr)) {
100
+ return origOnEstablished(...args);
101
+ }
95
102
  if (this.validateEnr(enr)) {
96
103
  return origOnEstablished(...args);
97
104
  }
@@ -121,10 +128,9 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
121
128
  // Add bootnode ENR if provided
122
129
  if (this.bootstrapNodes?.length) {
123
130
  // Do this conversion once since it involves an async function call
124
- const bootstrapNodesEnrs = this.bootstrapNodes.map(enr => ENR.decodeTxt(enr));
125
- this.bootstrapNodePeerIds = await Promise.all(bootstrapNodesEnrs.map(enr => enr.peerId()));
131
+ this.bootstrapNodePeerIds = await Promise.all(this.bootstrapNodeEnrs.map(enr => enr.peerId()));
126
132
  this.logger.info(`Adding ${this.bootstrapNodes} bootstrap nodes ENRs: ${this.bootstrapNodes.join(', ')}`);
127
- for (const enr of bootstrapNodesEnrs) {
133
+ for (const enr of this.bootstrapNodeEnrs) {
128
134
  try {
129
135
  if (this.config.bootstrapNodeEnrVersionCheck) {
130
136
  const value = enr.kvs.get(AZTEC_ENR_KEY);
@@ -196,7 +202,26 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
196
202
  this.onDiscovered(enr);
197
203
  }
198
204
 
205
+ private isOurBootnode(enr: ENR) {
206
+ return this.bootstrapNodeEnrs.some(x => x.nodeId === enr.nodeId);
207
+ }
208
+
199
209
  private onDiscovered(enr: ENR) {
210
+ // Find out if this is one of our bootnodes
211
+ if (this.isOurBootnode(enr)) {
212
+ // it is, what we do here depends
213
+ if (!this.config.bootstrapNodesAsFullPeers) {
214
+ // we don't consider bootnodes as full peers, don't perform any checks and don't emit anything
215
+ return;
216
+ }
217
+ if (!this.config.bootstrapNodeEnrVersionCheck) {
218
+ // we do consider bootnodes to be full peers and we have been told to NOT version check them, so emit
219
+ this.logger.trace(`Skipping version check for bootnode ${enr.nodeId}`);
220
+ this.emit(PeerEvent.DISCOVERED, enr);
221
+ return;
222
+ }
223
+ // here, we do consider bootnodes as full peers and we must version check so we continue to regular validation
224
+ }
200
225
  if (this.validateEnr(enr)) {
201
226
  this.emit(PeerEvent.DISCOVERED, enr);
202
227
  }
@@ -206,19 +231,19 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
206
231
  // Check the peer is an aztec peer
207
232
  const value = enr.kvs.get(AZTEC_ENR_KEY);
208
233
  if (!value) {
209
- this.logger.warn(`Peer ${enr.nodeId} does not have aztec key in ENR`);
234
+ this.logger.warn(`Peer node ${enr.nodeId} does not have aztec key in ENR`);
210
235
  return false;
211
236
  }
212
237
 
238
+ // And check it has the correct version
213
239
  let compressedVersion;
214
240
  try {
215
- // And check it has the correct version
216
241
  compressedVersion = Buffer.from(value).toString();
217
242
  checkCompressedComponentVersion(compressedVersion, this.versions);
218
243
  return true;
219
244
  } catch (err: any) {
220
245
  if (err.name === 'ComponentsVersionsError') {
221
- this.logger.warn(`Peer ${enr.nodeId} has incorrect version: ${err.message}`, {
246
+ this.logger.warn(`Peer node ${enr.nodeId} has incorrect version: ${err.message}`, {
222
247
  compressedVersion,
223
248
  expected: this.versions,
224
249
  });
@@ -1,9 +1,11 @@
1
- import type { BlockAttestation, BlockProposal, Gossipable, PeerInfo, TxHash } from '@aztec/circuit-types';
1
+ import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
2
+ import type { BlockAttestation, BlockProposal, Gossipable } from '@aztec/stdlib/p2p';
3
+ import { TxHash } from '@aztec/stdlib/tx';
2
4
 
3
5
  import type { PeerId } from '@libp2p/interface';
4
6
  import EventEmitter from 'events';
5
7
 
6
- import { type ReqRespSubProtocol, type SubProtocolMap } from './reqresp/interface.js';
8
+ import type { ReqRespSubProtocol, SubProtocolMap } from './reqresp/interface.js';
7
9
  import { type P2PService, type PeerDiscoveryService, PeerDiscoveryState } from './service.js';
8
10
 
9
11
  /**
@@ -1,9 +1,9 @@
1
1
  // Taken from lodestar: https://github.com/ChainSafe/lodestar
2
2
  import { sha256 } from '@aztec/foundation/crypto';
3
3
 
4
- import { type RPC } from '@chainsafe/libp2p-gossipsub/message';
5
- import { type DataTransform } from '@chainsafe/libp2p-gossipsub/types';
6
- import { type Message } from '@libp2p/interface';
4
+ import type { RPC } from '@chainsafe/libp2p-gossipsub/message';
5
+ import type { DataTransform } from '@chainsafe/libp2p-gossipsub/types';
6
+ import type { Message } from '@libp2p/interface';
7
7
  import { compressSync, uncompressSync } from 'snappy';
8
8
  import xxhashFactory from 'xxhash-wasm';
9
9
 
@@ -0,0 +1,13 @@
1
+ import type { PeerScoreThresholds } from '@chainsafe/libp2p-gossipsub/score';
2
+
3
+ /**
4
+ * The following params is implemented by Lighthouse at
5
+ * https://github.com/sigp/lighthouse/blob/b0ac3464ca5fb1e9d75060b56c83bfaf990a3d25/beacon_node/eth2_libp2p/src/behaviour/gossipsub_scoring_parameters.rs#L83
6
+ */
7
+ export const gossipScoreThresholds: PeerScoreThresholds = {
8
+ gossipThreshold: -4000,
9
+ publishThreshold: -8000,
10
+ graylistThreshold: -16000,
11
+ acceptPXThreshold: 100,
12
+ opportunisticGraftThreshold: 5,
13
+ };