@aztec/p2p 1.2.1 → 2.0.0-nightly.20250813

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 (221) hide show
  1. package/dest/client/factory.d.ts +5 -1
  2. package/dest/client/factory.d.ts.map +1 -1
  3. package/dest/client/factory.js +29 -12
  4. package/dest/client/interface.d.ts +8 -13
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +18 -22
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +86 -83
  9. package/dest/config.d.ts +30 -1
  10. package/dest/config.d.ts.map +1 -1
  11. package/dest/config.js +34 -1
  12. package/dest/index.d.ts +1 -0
  13. package/dest/index.d.ts.map +1 -1
  14. package/dest/index.js +1 -0
  15. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +13 -1
  16. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  17. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  18. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +117 -10
  19. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +4 -1
  20. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  21. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +22 -1
  22. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +4 -1
  23. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  24. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +21 -1
  25. package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -2
  26. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  27. package/dest/mem_pools/attestation_pool/mocks.js +2 -10
  28. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +8 -3
  29. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  30. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +64 -37
  31. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +8 -3
  32. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
  33. package/dest/mem_pools/tx_pool/memory_tx_pool.js +18 -10
  34. package/dest/mem_pools/tx_pool/tx_pool.d.ts +11 -2
  35. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  36. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  37. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +73 -44
  38. package/dest/msg_validators/attestation_validator/attestation_validator.js +1 -1
  39. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  40. package/dest/msg_validators/tx_validator/block_header_validator.js +2 -2
  41. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  42. package/dest/msg_validators/tx_validator/data_validator.js +35 -59
  43. package/dest/msg_validators/tx_validator/double_spend_validator.js +2 -2
  44. package/dest/msg_validators/tx_validator/gas_validator.js +4 -4
  45. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  46. package/dest/msg_validators/tx_validator/metadata_validator.js +21 -21
  47. package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
  48. package/dest/msg_validators/tx_validator/tx_proof_validator.js +3 -3
  49. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  50. package/dest/services/discv5/discV5_service.js +4 -1
  51. package/dest/services/dummy_service.d.ts +13 -3
  52. package/dest/services/dummy_service.d.ts.map +1 -1
  53. package/dest/services/dummy_service.js +26 -3
  54. package/dest/services/index.d.ts +3 -1
  55. package/dest/services/index.d.ts.map +1 -1
  56. package/dest/services/index.js +3 -1
  57. package/dest/services/libp2p/libp2p_service.d.ts +13 -20
  58. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  59. package/dest/services/libp2p/libp2p_service.js +123 -46
  60. package/dest/services/peer-manager/interface.d.ts +8 -1
  61. package/dest/services/peer-manager/interface.d.ts.map +1 -1
  62. package/dest/services/peer-manager/peer_manager.d.ts +70 -3
  63. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  64. package/dest/services/peer-manager/peer_manager.js +369 -39
  65. package/dest/services/reqresp/config.d.ts +3 -3
  66. package/dest/services/reqresp/config.d.ts.map +1 -1
  67. package/dest/services/reqresp/config.js +3 -3
  68. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +3 -4
  69. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  70. package/dest/services/reqresp/connection-sampler/connection_sampler.js +35 -52
  71. package/dest/services/reqresp/index.d.ts +2 -1
  72. package/dest/services/reqresp/index.d.ts.map +1 -1
  73. package/dest/services/reqresp/index.js +2 -1
  74. package/dest/services/reqresp/interface.d.ts +61 -10
  75. package/dest/services/reqresp/interface.d.ts.map +1 -1
  76. package/dest/services/reqresp/interface.js +41 -6
  77. package/dest/services/reqresp/protocols/auth.d.ts +43 -0
  78. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
  79. package/dest/services/reqresp/protocols/auth.js +71 -0
  80. package/dest/services/reqresp/protocols/block.d.ts +5 -0
  81. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  82. package/dest/services/reqresp/protocols/block.js +28 -5
  83. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +30 -0
  84. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
  85. package/dest/services/reqresp/protocols/block_txs/bitvector.js +75 -0
  86. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
  87. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
  88. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +39 -0
  89. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +49 -0
  90. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
  91. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
  92. package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
  93. package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
  94. package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
  95. package/dest/services/reqresp/protocols/goodbye.js +3 -5
  96. package/dest/services/reqresp/protocols/index.d.ts +2 -0
  97. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  98. package/dest/services/reqresp/protocols/index.js +2 -0
  99. package/dest/services/reqresp/protocols/status.d.ts +2 -0
  100. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  101. package/dest/services/reqresp/protocols/status.js +7 -0
  102. package/dest/services/reqresp/protocols/tx.d.ts +12 -1
  103. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  104. package/dest/services/reqresp/protocols/tx.js +34 -6
  105. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  106. package/dest/services/reqresp/rate-limiter/rate_limits.js +20 -0
  107. package/dest/services/reqresp/reqresp.d.ts +37 -39
  108. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  109. package/dest/services/reqresp/reqresp.js +220 -220
  110. package/dest/services/reqresp/status.d.ts +8 -3
  111. package/dest/services/reqresp/status.d.ts.map +1 -1
  112. package/dest/services/reqresp/status.js +6 -2
  113. package/dest/services/service.d.ts +10 -10
  114. package/dest/services/service.d.ts.map +1 -1
  115. package/dest/services/tx_collection/config.d.ts +25 -0
  116. package/dest/services/tx_collection/config.d.ts.map +1 -0
  117. package/dest/services/tx_collection/config.js +58 -0
  118. package/dest/services/tx_collection/fast_tx_collection.d.ts +56 -0
  119. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
  120. package/dest/services/tx_collection/fast_tx_collection.js +295 -0
  121. package/dest/services/tx_collection/index.d.ts +3 -0
  122. package/dest/services/tx_collection/index.d.ts.map +1 -0
  123. package/dest/services/tx_collection/index.js +2 -0
  124. package/dest/services/tx_collection/instrumentation.d.ts +10 -0
  125. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
  126. package/dest/services/tx_collection/instrumentation.js +34 -0
  127. package/dest/services/tx_collection/slow_tx_collection.d.ts +54 -0
  128. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
  129. package/dest/services/tx_collection/slow_tx_collection.js +176 -0
  130. package/dest/services/tx_collection/tx_collection.d.ts +109 -0
  131. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
  132. package/dest/services/tx_collection/tx_collection.js +127 -0
  133. package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
  134. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
  135. package/dest/services/tx_collection/tx_collection_sink.js +81 -0
  136. package/dest/services/tx_collection/tx_source.d.ts +18 -0
  137. package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
  138. package/dest/services/tx_collection/tx_source.js +31 -0
  139. package/dest/services/tx_provider.d.ts +49 -0
  140. package/dest/services/tx_provider.d.ts.map +1 -0
  141. package/dest/services/tx_provider.js +206 -0
  142. package/dest/services/{tx_collect_instrumentation.d.ts → tx_provider_instrumentation.d.ts} +2 -2
  143. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
  144. package/dest/services/{tx_collect_instrumentation.js → tx_provider_instrumentation.js} +5 -5
  145. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  146. package/dest/test-helpers/make-test-p2p-clients.js +4 -3
  147. package/dest/test-helpers/mock-pubsub.d.ts +2 -1
  148. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  149. package/dest/test-helpers/mock-pubsub.js +2 -1
  150. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  151. package/dest/test-helpers/reqresp-nodes.js +8 -4
  152. package/dest/testbench/p2p_client_testbench_worker.js +11 -5
  153. package/dest/util.d.ts +1 -1
  154. package/dest/util.d.ts.map +1 -1
  155. package/package.json +14 -15
  156. package/src/client/factory.ts +87 -12
  157. package/src/client/interface.ts +19 -15
  158. package/src/client/p2p_client.ts +108 -92
  159. package/src/config.ts +52 -1
  160. package/src/index.ts +1 -0
  161. package/src/mem_pools/attestation_pool/attestation_pool.ts +15 -1
  162. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +155 -4
  163. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +28 -1
  164. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +28 -2
  165. package/src/mem_pools/attestation_pool/mocks.ts +1 -3
  166. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +59 -41
  167. package/src/mem_pools/tx_pool/memory_tx_pool.ts +19 -9
  168. package/src/mem_pools/tx_pool/tx_pool.ts +7 -2
  169. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +63 -40
  170. package/src/msg_validators/attestation_validator/attestation_validator.ts +1 -1
  171. package/src/msg_validators/tx_validator/block_header_validator.ts +2 -2
  172. package/src/msg_validators/tx_validator/data_validator.ts +36 -27
  173. package/src/msg_validators/tx_validator/double_spend_validator.ts +2 -2
  174. package/src/msg_validators/tx_validator/gas_validator.ts +4 -4
  175. package/src/msg_validators/tx_validator/metadata_validator.ts +22 -28
  176. package/src/msg_validators/tx_validator/phases_validator.ts +2 -2
  177. package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -2
  178. package/src/services/discv5/discV5_service.ts +4 -1
  179. package/src/services/dummy_service.ts +44 -4
  180. package/src/services/index.ts +3 -1
  181. package/src/services/libp2p/libp2p_service.ts +147 -55
  182. package/src/services/peer-manager/interface.ts +10 -1
  183. package/src/services/peer-manager/peer_manager.ts +441 -41
  184. package/src/services/reqresp/config.ts +3 -3
  185. package/src/services/reqresp/connection-sampler/connection_sampler.ts +38 -63
  186. package/src/services/reqresp/index.ts +2 -0
  187. package/src/services/reqresp/interface.ts +63 -17
  188. package/src/services/reqresp/protocols/auth.ts +83 -0
  189. package/src/services/reqresp/protocols/block.ts +24 -3
  190. package/src/services/reqresp/protocols/block_txs/bitvector.ts +90 -0
  191. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +53 -0
  192. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +79 -0
  193. package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
  194. package/src/services/reqresp/protocols/goodbye.ts +3 -3
  195. package/src/services/reqresp/protocols/index.ts +2 -0
  196. package/src/services/reqresp/protocols/status.ts +20 -0
  197. package/src/services/reqresp/protocols/tx.ts +35 -6
  198. package/src/services/reqresp/rate-limiter/rate_limits.ts +20 -0
  199. package/src/services/reqresp/reqresp.ts +294 -264
  200. package/src/services/reqresp/status.ts +9 -3
  201. package/src/services/service.ts +23 -14
  202. package/src/services/tx_collection/config.ts +84 -0
  203. package/src/services/tx_collection/fast_tx_collection.ts +338 -0
  204. package/src/services/tx_collection/index.ts +2 -0
  205. package/src/services/tx_collection/instrumentation.ts +43 -0
  206. package/src/services/tx_collection/slow_tx_collection.ts +232 -0
  207. package/src/services/tx_collection/tx_collection.ts +214 -0
  208. package/src/services/tx_collection/tx_collection_sink.ts +98 -0
  209. package/src/services/tx_collection/tx_source.ts +37 -0
  210. package/src/services/tx_provider.ts +215 -0
  211. package/src/services/{tx_collect_instrumentation.ts → tx_provider_instrumentation.ts} +5 -5
  212. package/src/test-helpers/make-test-p2p-clients.ts +4 -2
  213. package/src/test-helpers/mock-pubsub.ts +1 -0
  214. package/src/test-helpers/reqresp-nodes.ts +7 -1
  215. package/src/testbench/p2p_client_testbench_worker.ts +9 -2
  216. package/src/util.ts +1 -1
  217. package/dest/services/tx_collect_instrumentation.d.ts.map +0 -1
  218. package/dest/services/tx_collector.d.ts +0 -23
  219. package/dest/services/tx_collector.d.ts.map +0 -1
  220. package/dest/services/tx_collector.js +0 -95
  221. package/src/services/tx_collector.ts +0 -134
@@ -4,6 +4,7 @@ function _ts_decorate(decorators, target, key, desc) {
4
4
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  }
7
+ import { randomInt } from '@aztec/foundation/crypto';
7
8
  import { createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
8
9
  import { SerialQueue } from '@aztec/foundation/queue';
9
10
  import { RunningPromise } from '@aztec/foundation/running-promise';
@@ -15,6 +16,7 @@ import { MerkleTreeId } from '@aztec/stdlib/trees';
15
16
  import { Tx } from '@aztec/stdlib/tx';
16
17
  import { compressComponentVersions } from '@aztec/stdlib/versioning';
17
18
  import { Attributes, OtelMetricsAdapter, WithTracer, trackSpan } from '@aztec/telemetry-client';
19
+ import { ENR } from '@chainsafe/enr';
18
20
  import { gossipsub } from '@chainsafe/libp2p-gossipsub';
19
21
  import { createPeerScoreParams, createTopicScoreParams } from '@chainsafe/libp2p-gossipsub/score';
20
22
  import { SignaturePolicy } from '@chainsafe/libp2p-gossipsub/types';
@@ -41,7 +43,8 @@ import { SnappyTransform, fastMsgIdFn, getMsgIdFn, msgIdToStrFn } from '../encod
41
43
  import { gossipScoreThresholds } from '../gossipsub/scoring.js';
42
44
  import { PeerManager } from '../peer-manager/peer_manager.js';
43
45
  import { PeerScoring } from '../peer-manager/peer_scoring.js';
44
- import { DEFAULT_SUB_PROTOCOL_VALIDATORS, ReqRespSubProtocol } from '../reqresp/interface.js';
46
+ import { DEFAULT_SUB_PROTOCOL_VALIDATORS, ReqRespSubProtocol, ValidationError } from '../reqresp/interface.js';
47
+ import { reqRespBlockTxsHandler } from '../reqresp/protocols/block_txs/block_txs_handler.js';
45
48
  import { reqGoodbyeHandler } from '../reqresp/protocols/goodbye.js';
46
49
  import { pingHandler, reqRespBlockHandler, reqRespStatusHandler, reqRespTxHandler } from '../reqresp/protocols/index.js';
47
50
  import { ReqResp } from '../reqresp/reqresp.js';
@@ -114,10 +117,11 @@ import { P2PInstrumentation } from './instrumentation.js';
114
117
  const datastore = new AztecDatastore(peerStore);
115
118
  const otelMetricsAdapter = new OtelMetricsAdapter(telemetry);
116
119
  const peerDiscoveryService = new DiscV5Service(peerId, config, packageVersion, telemetry, createLogger(`${logger.module}:discv5_service`));
117
- const bootstrapNodes = peerDiscoveryService.bootstrapNodeEnrs.map((enr)=>enr.encodeTxt());
118
- // If trusted peers are provided, also provide them to the p2p service
119
- bootstrapNodes.push(...config.trustedPeers);
120
- // If bootstrap nodes are provided, also provide them to the p2p service
120
+ // Seed libp2p's bootstrap discovery with private and trusted peers
121
+ const bootstrapNodes = [
122
+ ...config.privatePeers,
123
+ ...config.trustedPeers
124
+ ];
121
125
  const peerDiscovery = [];
122
126
  if (bootstrapNodes.length > 0) {
123
127
  peerDiscovery.push(bootstrap({
@@ -129,6 +133,23 @@ import { P2PInstrumentation } from './instrumentation.js';
129
133
  const txTopic = createTopicString(TopicType.tx, protocolVersion);
130
134
  const blockProposalTopic = createTopicString(TopicType.block_proposal, protocolVersion);
131
135
  const blockAttestationTopic = createTopicString(TopicType.block_attestation, protocolVersion);
136
+ const preferredPeersEnrs = config.preferredPeers.map((enr)=>ENR.decodeTxt(enr));
137
+ const directPeers = (await Promise.all(preferredPeersEnrs.map(async (enr)=>{
138
+ const peerId = await enr.peerId();
139
+ const address = enr.getLocationMultiaddr('tcp');
140
+ if (address === undefined) {
141
+ throw new Error(`Direct peer ${peerId.toString()} has no TCP address, ENR: ${enr.encodeTxt()}`);
142
+ }
143
+ return {
144
+ id: peerId,
145
+ addrs: [
146
+ address
147
+ ]
148
+ };
149
+ }))).filter((peer)=>peer !== undefined);
150
+ const announceTcpMultiaddr = config.p2pIp ? [
151
+ convertToMultiaddr(config.p2pIp, p2pPort, 'tcp')
152
+ ] : [];
132
153
  const node = await createLibp2p({
133
154
  start: false,
134
155
  peerId,
@@ -136,18 +157,27 @@ import { P2PInstrumentation } from './instrumentation.js';
136
157
  listen: [
137
158
  bindAddrTcp
138
159
  ],
139
- announce: []
160
+ announce: announceTcpMultiaddr
140
161
  },
141
162
  transports: [
142
163
  tcp({
143
- maxConnections: config.maxPeerCount,
164
+ // It's better to have this number a bit higher than our maxPeerCount because it's sets the limit on transport (TCP) layer
165
+ // The connection attempts to the node on TCP layer are not necessarily valid Aztec peers so we want to have a bit of leeway here
166
+ // If we hit the limit, the connection will be temporarily accepted and immediately dropped.
167
+ // Docs: https://nodejs.org/api/net.html#servermaxconnections
168
+ maxConnections: Math.ceil(maxPeerCount * 1.5),
144
169
  // socket option: the maximum length of the queue of pending connections
145
170
  // https://nodejs.org/dist/latest-v22.x/docs/api/net.html#serverlisten
146
171
  // it's not safe if we increase this number
147
172
  backlog: 5,
148
173
  closeServerOnMaxConnections: {
149
- closeAbove: maxPeerCount ?? Infinity,
150
- listenBelow: maxPeerCount ?? Infinity
174
+ // The property `maxConnections` will protect us against the most DDOS attack
175
+ // This property protects us in case of burst of new connections where server is not able to close them quickly enough
176
+ // In case closeAbove is reached, the server stops listening altogether
177
+ // It's important that there is enough difference between closeAbove and listenAbove,
178
+ // otherwise the server.listener will flap between being closed and open potentially degrading perf even more
179
+ closeAbove: maxPeerCount * 2,
180
+ listenBelow: Math.floor(maxPeerCount * 0.9)
151
181
  }
152
182
  })
153
183
  ],
@@ -162,16 +192,39 @@ import { P2PInstrumentation } from './instrumentation.js';
162
192
  ],
163
193
  connectionManager: {
164
194
  minConnections: 0,
195
+ maxConnections: maxPeerCount,
165
196
  maxParallelDials: 100,
166
197
  dialTimeout: 30_000,
167
198
  maxPeerAddrsToDial: 5,
168
199
  maxIncomingPendingConnections: 5
169
200
  },
201
+ connectionGater: {
202
+ denyInboundConnection: (maConn)=>{
203
+ const allowed = peerManager.isNodeAllowedToConnect(maConn.remoteAddr.nodeAddress().address);
204
+ if (allowed) {
205
+ return false;
206
+ }
207
+ logger.debug(`Connection gater: Denying inbound connection from ${maConn.remoteAddr.toString()}`);
208
+ return true;
209
+ },
210
+ denyInboundEncryptedConnection: (peerId, _maConn)=>{
211
+ //NOTE: it is not necessary to check address here because this was already done by
212
+ // denyInboundConnection
213
+ const allowed = peerManager.isNodeAllowedToConnect(peerId);
214
+ if (allowed) {
215
+ return false;
216
+ }
217
+ logger.debug(`Connection gater: Denying inbound encrypted connection from ${peerId.toString()}`);
218
+ return true;
219
+ }
220
+ },
170
221
  services: {
171
222
  identify: identify({
172
- protocolPrefix: 'aztec'
223
+ protocolPrefix: 'aztec',
224
+ runOnConnectionOpen: true
173
225
  }),
174
226
  pubsub: gossipsub({
227
+ directPeers,
175
228
  debugName: 'gossipsub',
176
229
  globalSignaturePolicy: SignaturePolicy.StrictNoSign,
177
230
  allowPublishToZeroTopicPeers: true,
@@ -222,10 +275,10 @@ import { P2PInstrumentation } from './instrumentation.js';
222
275
  });
223
276
  const peerScoring = new PeerScoring(config);
224
277
  const reqresp = new ReqResp(config, node, peerScoring, createLogger(`${logger.module}:reqresp`));
225
- const peerManager = new PeerManager(node, peerDiscoveryService, config, telemetry, createLogger(`${logger.module}:peer_manager`), peerScoring, reqresp, worldStateSynchronizer, protocolVersion);
278
+ const peerManager = new PeerManager(node, peerDiscoveryService, config, telemetry, createLogger(`${logger.module}:peer_manager`), peerScoring, reqresp, worldStateSynchronizer, protocolVersion, epochCache);
226
279
  // Update gossipsub score params
227
280
  node.services.pubsub.score.params.appSpecificWeight = 10;
228
- node.services.pubsub.score.params.appSpecificScore = (peerId)=>peerManager.getPeerScore(peerId);
281
+ node.services.pubsub.score.params.appSpecificScore = (peerId)=>peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
229
282
  return new LibP2PService(clientType, config, node, peerDiscoveryService, reqresp, peerManager, mempools, l2BlockSource, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger);
230
283
  }
231
284
  /**
@@ -245,7 +298,9 @@ import { P2PInstrumentation } from './instrumentation.js';
245
298
  // Start job queue, peer discovery service and libp2p node
246
299
  this.jobQueue.start();
247
300
  await this.peerManager.initializePeers();
248
- await this.peerDiscoveryService.start();
301
+ if (!this.config.p2pDiscoveryDisabled) {
302
+ await this.peerDiscoveryService.start();
303
+ }
249
304
  await this.node.start();
250
305
  // Subscribe to standard GossipSub topics by default
251
306
  for (const topic of getTopicTypeForClientType(this.clientType)){
@@ -256,6 +311,10 @@ import { P2PInstrumentation } from './instrumentation.js';
256
311
  const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
257
312
  const blockHandler = reqRespBlockHandler(this.archiver);
258
313
  const statusHandler = reqRespStatusHandler(this.protocolVersion, this.worldStateSynchronizer, this.logger);
314
+ // In case P2P client doesnt'have attestation pool,
315
+ // const blockTxsHandler = this.mempools.attestationPool
316
+ // ? reqRespBlockTxsHandler(this.mempools.attestationPool, this.mempools.txPool)
317
+ // : def;
259
318
  const requestResponseHandlers = {
260
319
  [ReqRespSubProtocol.PING]: pingHandler,
261
320
  [ReqRespSubProtocol.STATUS]: statusHandler.bind(this),
@@ -263,6 +322,11 @@ import { P2PInstrumentation } from './instrumentation.js';
263
322
  [ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this),
264
323
  [ReqRespSubProtocol.BLOCK]: blockHandler.bind(this)
265
324
  };
325
+ // Only handle block transactions request if attestation pool is available to the client
326
+ if (this.mempools.attestationPool) {
327
+ const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.mempools.txPool);
328
+ requestResponseHandlers[ReqRespSubProtocol.BLOCK_TXS] = blockTxsHandler.bind(this);
329
+ }
266
330
  // add GossipSub listener
267
331
  this.node.services.pubsub.addEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
268
332
  // Start running promise for peer discovery
@@ -303,6 +367,12 @@ import { P2PInstrumentation } from './instrumentation.js';
303
367
  await this.stopLibP2P();
304
368
  this.logger.info('LibP2P service stopped');
305
369
  }
370
+ addReqRespSubProtocol(subProtocol, handler, validator) {
371
+ return this.reqresp.addSubProtocol(subProtocol, handler, validator);
372
+ }
373
+ registerThisValidatorAddresses(address) {
374
+ this.peerManager.registerThisValidatorAddresses(address);
375
+ }
306
376
  getPeers(includePending) {
307
377
  return this.peerManager.getPeers(includePending);
308
378
  }
@@ -318,18 +388,6 @@ import { P2PInstrumentation } from './instrumentation.js';
318
388
  setImmediate(()=>void safeJob());
319
389
  }
320
390
  /**
321
- * Send Request via the ReqResp service
322
- * The subprotocol defined will determine the request and response types
323
- *
324
- * See the subProtocolMap for the mapping of subprotocols to request/response types in `interface.ts`
325
- *
326
- * @param protocol The request response protocol to use
327
- * @param request The request type to send
328
- * @returns
329
- */ sendRequest(protocol, request) {
330
- return this.reqresp.sendRequest(protocol, request);
331
- }
332
- /**
333
391
  * Send a batch of requests to peers, and return the responses
334
392
  * @param protocol - The request response protocol to use
335
393
  * @param requests - The requests to send to the peers
@@ -466,12 +524,16 @@ import { P2PInstrumentation } from './instrumentation.js';
466
524
  if (!result || !tx) {
467
525
  return;
468
526
  }
469
- const txHash = await tx.getTxHash();
527
+ const txHash = tx.getTxHash();
470
528
  const txHashString = txHash.toString();
471
529
  this.logger.verbose(`Received tx ${txHashString} from external peer ${source.toString()} via gossip`, {
472
530
  source: source.toString(),
473
531
  txHash: txHashString
474
532
  });
533
+ if (this.config.dropTransactions && randomInt(1000) < this.config.dropTransactionsProbability * 1000) {
534
+ this.logger.debug(`Intentionally dropping tx ${txHashString} (probability rule)`);
535
+ return;
536
+ }
475
537
  await this.mempools.txPool.addTxs([
476
538
  tx
477
539
  ]);
@@ -545,7 +607,8 @@ import { P2PInstrumentation } from './instrumentation.js';
545
607
  this.logger.verbose(`Received ${attestationsForPreviousSlot.length} attestations for slot ${previousSlot}`);
546
608
  }
547
609
  // Mark the txs in this proposal as non-evictable
548
- await this.mempools.txPool.markTxsAsNonEvictable(block.payload.txHashes);
610
+ await this.mempools.txPool.markTxsAsNonEvictable(block.txHashes);
611
+ await this.mempools.attestationPool?.addBlockProposal(block);
549
612
  const attestations = await this.blockReceivedCallback(block, sender);
550
613
  // TODO: fix up this pattern - the abstraction is not nice
551
614
  // The attestation can be undefined if no handler is registered / the validator deems the block invalid
@@ -584,33 +647,44 @@ import { P2PInstrumentation } from './instrumentation.js';
584
647
  });
585
648
  }
586
649
  /**
587
- * Validate a tx that has been requested from a peer.
650
+ * Validate a collection of txs that has been requested from a peer.
588
651
  *
589
- * The core component of this validator is that the tx hash MUST match the requested tx hash,
652
+ * The core component of this validator is that each tx hash MUST match the requested tx hash,
590
653
  * In order to perform this check, the tx proof must be verified.
591
654
  *
592
655
  * Note: This function is called from within `ReqResp.sendRequest` as part of the
593
656
  * ReqRespSubProtocol.TX subprotocol validation.
594
657
  *
595
- * @param requestedTxHash - The hash of the tx that was requested.
596
- * @param responseTx - The tx that was received as a response to the request.
658
+ * @param requestedTxHash - The collection of the txs that was requested.
659
+ * @param responseTx - The collectin of txs that was received as a response to the request.
597
660
  * @param peerId - The peer ID of the peer that sent the tx.
598
- * @returns True if the tx is valid, false otherwise.
599
- */ async validateRequestedTx(requestedTxHash, responseTx, peerId) {
661
+ * @returns True if the whole collection of txs is valid, false otherwise.
662
+ */ //TODO: (mralj) - this is somewhat naive implementation, if single tx is invlid we consider the whole response invalid.
663
+ // I think we should still extract the valid txs and return them, so that we can still use the response.
664
+ async validateRequestedTx(requestedTxHash, responseTx, peerId) {
665
+ const requested = new Set(requestedTxHash.map((h)=>h.toString()));
600
666
  const proofValidator = new TxProofValidator(this.proofVerifier);
601
- const validProof = await proofValidator.validateTx(responseTx);
602
- // If the node returns the wrong data, we penalize it
603
- if (!requestedTxHash.equals(await responseTx.getTxHash())) {
604
- // Returning the wrong data is a low tolerance error
605
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
606
- return false;
607
- }
608
- if (validProof.result === 'invalid') {
609
- // If the proof is invalid, but the txHash is correct, then this is an active attack and we severly punish
610
- this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
667
+ try {
668
+ await Promise.all(responseTx.map(async (tx)=>{
669
+ if (!requested.has(tx.getTxHash().toString())) {
670
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
671
+ throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
672
+ }
673
+ const { result } = await proofValidator.validateTx(tx);
674
+ if (result === 'invalid') {
675
+ this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
676
+ throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that is invalid.`);
677
+ }
678
+ }));
679
+ return true;
680
+ } catch (e) {
681
+ if (e instanceof ValidationError) {
682
+ this.logger.debug(`Failed to validate requested txs from peer ${peerId.toString()}, reason ${e.message}`);
683
+ } else {
684
+ this.logger.warn(`Error during validation of requested txs`, e);
685
+ }
611
686
  return false;
612
687
  }
613
- return true;
614
688
  }
615
689
  async validatePropagatedTx(tx, peerId) {
616
690
  const currentBlockNumber = await this.archiver.getBlockNumber();
@@ -773,6 +847,9 @@ import { P2PInstrumentation } from './instrumentation.js';
773
847
  getPeerScore(peerId) {
774
848
  return this.node.services.pubsub.score.score(peerId.toString());
775
849
  }
850
+ handleAuthRequestFromPeer(authRequest, peerId) {
851
+ return this.peerManager.handleAuthRequestFromPeer(authRequest, peerId);
852
+ }
776
853
  async sendToPeers(message) {
777
854
  const parent = message.constructor;
778
855
  const identifier = await message.p2pMessageIdentifier().then((i)=>i.toString());
@@ -824,8 +901,8 @@ _ts_decorate([
824
901
  }))
825
902
  ], LibP2PService.prototype, "validateRequestedTx", null);
826
903
  _ts_decorate([
827
- trackSpan('Libp2pService.validatePropagatedTx', async (tx)=>({
828
- [Attributes.TX_HASH]: (await tx.getTxHash()).toString()
904
+ trackSpan('Libp2pService.validatePropagatedTx', (tx)=>({
905
+ [Attributes.TX_HASH]: tx.getTxHash().toString()
829
906
  }))
830
907
  ], LibP2PService.prototype, "validatePropagatedTx", null);
831
908
  _ts_decorate([
@@ -1,16 +1,23 @@
1
+ import type { EthAddress } from '@aztec/foundation/eth-address';
1
2
  import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
2
3
  import type { PeerErrorSeverity } from '@aztec/stdlib/p2p';
3
4
  import type { PeerId } from '@libp2p/interface';
5
+ import type { AuthRequest, StatusMessage } from '../reqresp/index.js';
4
6
  import type { GoodByeReason } from '../reqresp/protocols/goodbye.js';
5
7
  export interface PeerManagerInterface {
6
8
  getPeers(_includePending?: boolean): PeerInfo[];
7
9
  initializePeers(): Promise<void>;
8
- heartbeat(): void;
10
+ heartbeat(): Promise<void>;
9
11
  addTrustedPeer(peerId: PeerId): void;
10
12
  addPrivatePeer(peerId: PeerId): void;
13
+ addPreferredPeer(peerId: PeerId): void;
11
14
  goodbyeReceived(peerId: PeerId, reason: GoodByeReason): void;
12
15
  penalizePeer(peerId: PeerId, penalty: PeerErrorSeverity): void;
16
+ handleAuthRequestFromPeer(authRequest: AuthRequest, peerId: PeerId): Promise<StatusMessage>;
13
17
  getPeerScore(peerId: string): number;
18
+ shouldDisableP2PGossip(peerId: string): boolean;
14
19
  stop(): Promise<void>;
20
+ /** If node running this P2P stack is validator, passes in validator address to P2P layer */
21
+ registerThisValidatorAddresses(address: EthAddress[]): void;
15
22
  }
16
23
  //# sourceMappingURL=interface.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/services/peer-manager/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAErE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,GAAG,QAAQ,EAAE,CAAC;IAEhD,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,SAAS,IAAI,IAAI,CAAC;IAClB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,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;IAC/D,yBAAyB,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAE5F,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACrC,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IAEhD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtB,4FAA4F;IAC5F,8BAA8B,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;CAC7D"}
@@ -1,10 +1,15 @@
1
+ import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
+ import type { EthAddress } from '@aztec/foundation/eth-address';
3
+ import { DateProvider } from '@aztec/foundation/timer';
1
4
  import type { PeerInfo, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
2
5
  import type { PeerErrorSeverity } from '@aztec/stdlib/p2p';
3
6
  import { type TelemetryClient } from '@aztec/telemetry-client';
4
7
  import type { PeerId } from '@libp2p/interface';
5
- import type { Libp2p } from 'libp2p';
6
8
  import type { P2PConfig } from '../../config.js';
9
+ import type { FullLibp2p } from '../../util.js';
10
+ import { AuthRequest } from '../reqresp/protocols/auth.js';
7
11
  import { GoodByeReason } from '../reqresp/protocols/goodbye.js';
12
+ import { StatusMessage } from '../reqresp/protocols/status.js';
8
13
  import type { ReqResp } from '../reqresp/reqresp.js';
9
14
  import type { PeerDiscoveryService } from '../service.js';
10
15
  import type { PeerManagerInterface } from './interface.js';
@@ -18,6 +23,8 @@ export declare class PeerManager implements PeerManagerInterface {
18
23
  private reqresp;
19
24
  private readonly worldStateSynchronizer;
20
25
  private readonly protocolVersion;
26
+ private readonly epochCache;
27
+ private readonly dateProvider;
21
28
  private cachedPeers;
22
29
  private heartbeatCounter;
23
30
  private displayPeerCountsPeerHeartbeat;
@@ -26,9 +33,16 @@ export declare class PeerManager implements PeerManagerInterface {
26
33
  private trustedPeersInitialized;
27
34
  private privatePeers;
28
35
  private privatePeersInitialized;
36
+ private preferredPeers;
37
+ private authenticatedPeerIdToValidatorAddress;
38
+ private authenticatedValidatorAddressToPeerId;
39
+ private peersToBeDisconnected;
40
+ private failedAuthHandshakes;
41
+ private validatorAddresses;
42
+ private initializedPreferredPeers;
29
43
  private metrics;
30
44
  private handlers;
31
- constructor(libP2PNode: Libp2p, peerDiscoveryService: PeerDiscoveryService, config: P2PConfig, telemetryClient: TelemetryClient, logger: import("@aztec/foundation/log").Logger | undefined, peerScoring: PeerScoring, reqresp: ReqResp, worldStateSynchronizer: WorldStateSynchronizer, protocolVersion: string);
45
+ constructor(libP2PNode: FullLibp2p, peerDiscoveryService: PeerDiscoveryService, config: P2PConfig, telemetryClient: TelemetryClient, logger: import("@aztec/foundation/log").Logger | undefined, peerScoring: PeerScoring, reqresp: ReqResp, worldStateSynchronizer: WorldStateSynchronizer, protocolVersion: string, epochCache: EpochCacheInterface, dateProvider?: DateProvider);
32
46
  /**
33
47
  * Initializes the trusted peers.
34
48
  *
@@ -36,7 +50,8 @@ export declare class PeerManager implements PeerManagerInterface {
36
50
  */
37
51
  initializePeers(): Promise<void>;
38
52
  get tracer(): import("@aztec/telemetry-client").Tracer;
39
- heartbeat(): void;
53
+ heartbeat(): Promise<void>;
54
+ setupDirectPeersIfValidator(): Promise<void>;
40
55
  /**
41
56
  * Cleans up expired timeouts.
42
57
  *
@@ -45,6 +60,13 @@ export declare class PeerManager implements PeerManagerInterface {
45
60
  * To give them a chance to reconnect.
46
61
  */
47
62
  private cleanupExpiredTimeouts;
63
+ /**
64
+ * Processes scheduled disconnects during heartbeat.
65
+ *
66
+ * This batch processes all peers that have been marked for disconnect.
67
+ * preventing immediate disconnects that could cause libp2p state corruption.
68
+ */
69
+ private processScheduledDisconnects;
48
70
  /**
49
71
  * Performs Status Handshake with a connected peer.
50
72
  * @param e - The connected peer event.
@@ -55,6 +77,7 @@ export declare class PeerManager implements PeerManagerInterface {
55
77
  * @param e - The disconnected peer event.
56
78
  */
57
79
  private handleDisconnectedPeerEvent;
80
+ registerThisValidatorAddresses(address: EthAddress[]): void;
58
81
  /**
59
82
  * Checks if a peer is trusted.
60
83
  * @param peerId - The peer ID.
@@ -78,6 +101,17 @@ export declare class PeerManager implements PeerManagerInterface {
78
101
  * @returns True if the peer is private, false otherwise.
79
102
  */
80
103
  private isPrivatePeer;
104
+ /**
105
+ * Adds a peer to the preferred peers set.
106
+ * @param peerId - The peer ID to add to preferred peers.
107
+ */
108
+ addPreferredPeer(peerId: PeerId): void;
109
+ /**
110
+ * Checks if a peer is preferred.
111
+ * @param peerId - The peer ID.
112
+ * @returns True if the peer is preferred, false otherwise.
113
+ */
114
+ private isPreferredPeer;
81
115
  /**
82
116
  * Checks if a peer is protected (either trusted or private).
83
117
  * @param peerId - The peer ID.
@@ -94,12 +128,16 @@ export declare class PeerManager implements PeerManagerInterface {
94
128
  goodbyeReceived(peerId: PeerId, reason: GoodByeReason): void;
95
129
  penalizePeer(peerId: PeerId, penalty: PeerErrorSeverity): void;
96
130
  getPeerScore(peerId: string): number;
131
+ shouldDisableP2PGossip(peerId: string): boolean;
97
132
  getPeers(includePending?: boolean): PeerInfo[];
133
+ isAuthenticatedPeer(peerId: PeerId): boolean;
134
+ isNodeAllowedToConnect(id: string | PeerId): boolean;
98
135
  /**
99
136
  * Discovers peers.
100
137
  */
101
138
  private discover;
102
139
  private getNonProtectedPeers;
140
+ private getProtectedPeerCount;
103
141
  private pruneUnhealthyPeers;
104
142
  /**
105
143
  * If the max peer count is reached, the lowest scoring peers will be pruned to satisfy the max peer count.
@@ -119,6 +157,13 @@ export declare class PeerManager implements PeerManagerInterface {
119
157
  */
120
158
  private pruneDuplicatePeers;
121
159
  private goodbyeAndDisconnectPeer;
160
+ private markPeerForDisconnect;
161
+ /**
162
+ * Performs the actual disconnection of a peer.
163
+ * This is called during heartbeat processing to avoid immediate disconnections.
164
+ *
165
+ * @returns True if peer was disconnect, otherwise false
166
+ */
122
167
  private disconnectPeer;
123
168
  /**
124
169
  * Handles a discovered peer.
@@ -128,6 +173,7 @@ export declare class PeerManager implements PeerManagerInterface {
128
173
  private dialPeer;
129
174
  private shouldDialPeer;
130
175
  private pruneCachedPeers;
176
+ private createStatusMessage;
131
177
  /**
132
178
  * Performs status Handshake with the Peer
133
179
  * The way the protocol is designed is that each peer will call this method on newly established p2p connection.
@@ -139,10 +185,31 @@ export declare class PeerManager implements PeerManagerInterface {
139
185
  * @param: peerId The Id of the peer to request the Status from.
140
186
  * */
141
187
  private exchangeStatusHandshake;
188
+ /**
189
+ * Performs auth Handshake with the Peer
190
+ * A superset of the status handshake. Also includes a challenge that needs to be signed by the peer's validator key.
191
+ * @param: peerId The Id of the peer to request the Status from.
192
+ * */
193
+ private exchangeAuthHandshake;
194
+ private markAuthHandshakeFailed;
195
+ private markAuthHandshakeSuccess;
142
196
  /**
143
197
  * Stops the peer manager.
144
198
  * Removing all event listeners.
145
199
  */
146
200
  stop(): Promise<void>;
201
+ private shouldTrustWithIdentity;
202
+ /**
203
+ * Performs auth request verification from peer. An auth request is valid if requested by an authorized peer (a peer we trust).
204
+ *
205
+ * @param: _authRequest - Auth request (unused)
206
+ * @param: peerId - The ID of the peer that requested the auth handshake
207
+ *
208
+ * @returns: StatusMessage if peer is trusted
209
+ *
210
+ * @throws: If peer is unauthorized
211
+ * */
212
+ handleAuthRequestFromPeer(_authRequest: AuthRequest, peerId: PeerId): Promise<StatusMessage>;
213
+ private updateAuthenticatedPeers;
147
214
  }
148
215
  //# sourceMappingURL=peer_manager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"peer_manager.d.ts","sourceRoot":"","sources":["../../../src/services/peer-manager/peer_manager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACxF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,KAAK,eAAe,EAAa,MAAM,yBAAyB,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