diff --git a/yarn-project/p2p/src/bootstrap/bootstrap.ts b/yarn-project/p2p/src/bootstrap/bootstrap.ts index ab4f84b6b79..32aa21faf3e 100644 --- a/yarn-project/p2p/src/bootstrap/bootstrap.ts +++ b/yarn-project/p2p/src/bootstrap/bootstrap.ts @@ -9,7 +9,7 @@ import type { PeerId } from '@libp2p/interface'; import { type Multiaddr, multiaddr } from '@multiformats/multiaddr'; import type { BootnodeConfig } from '../config.js'; -import { AZTEC_ENR_KEY, AZTEC_NET } from '../service/discV5_service.js'; +import { AZTEC_ENR_KEY, AZTEC_NET } from '../services/discv5/discV5_service.js'; import { convertToMultiaddr, createLibP2PPeerIdFromPrivateKey, getPeerIdPrivateKey } from '../util.js'; /** diff --git a/yarn-project/p2p/src/client/index.ts b/yarn-project/p2p/src/client/index.ts index 3e3d5de5ca3..c2a01ff4294 100644 --- a/yarn-project/p2p/src/client/index.ts +++ b/yarn-project/p2p/src/client/index.ts @@ -19,9 +19,9 @@ import { type EpochProofQuotePool } from '../mem_pools/epoch_proof_quote_pool/ep import { MemoryEpochProofQuotePool } from '../mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.js'; import { type MemPools } from '../mem_pools/interface.js'; import { AztecKVTxPool, type TxPool } from '../mem_pools/tx_pool/index.js'; -import { DiscV5Service } from '../service/discV5_service.js'; -import { DummyP2PService } from '../service/dummy_service.js'; -import { LibP2PService } from '../service/index.js'; +import { DiscV5Service } from '../services/discv5/discV5_service.js'; +import { DummyP2PService } from '../services/dummy_service.js'; +import { LibP2PService } from '../services/index.js'; import { configureP2PClientAddresses, createLibP2PPeerIdFromPrivateKey, getPeerIdPrivateKey } from '../util.js'; export * from './p2p_client.js'; diff --git a/yarn-project/p2p/src/client/p2p_client.ts b/yarn-project/p2p/src/client/p2p_client.ts index d138e1e6ceb..f2864607592 100644 --- a/yarn-project/p2p/src/client/p2p_client.ts +++ b/yarn-project/p2p/src/client/p2p_client.ts @@ -32,8 +32,8 @@ import { type AttestationPool } from '../mem_pools/attestation_pool/attestation_ import { type EpochProofQuotePool } from '../mem_pools/epoch_proof_quote_pool/epoch_proof_quote_pool.js'; import { type MemPools } from '../mem_pools/interface.js'; import { type TxPool } from '../mem_pools/tx_pool/index.js'; -import { TX_REQ_PROTOCOL } from '../service/reqresp/interface.js'; -import type { P2PService } from '../service/service.js'; +import { TX_REQ_PROTOCOL } from '../services/reqresp/interface.js'; +import type { P2PService } from '../services/service.js'; /** * Enum defining the possible states of the p2p client. diff --git a/yarn-project/p2p/src/config.ts b/yarn-project/p2p/src/config.ts index ee3f4e98868..0e30bc2efe3 100644 --- a/yarn-project/p2p/src/config.ts +++ b/yarn-project/p2p/src/config.ts @@ -8,7 +8,7 @@ import { } from '@aztec/foundation/config'; import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config'; -import { type P2PReqRespConfig, p2pReqRespConfigMappings } from './service/reqresp/config.js'; +import { type P2PReqRespConfig, p2pReqRespConfigMappings } from './services/reqresp/config.js'; /** * P2P client configuration values. diff --git a/yarn-project/p2p/src/index.ts b/yarn-project/p2p/src/index.ts index d1cf3187d46..f8510cf8552 100644 --- a/yarn-project/p2p/src/index.ts +++ b/yarn-project/p2p/src/index.ts @@ -3,6 +3,6 @@ export * from './bootstrap/bootstrap.js'; export * from './client/index.js'; export * from './config.js'; export * from './mem_pools/epoch_proof_quote_pool/index.js'; -export * from './service/index.js'; +export * from './services/index.js'; export * from './mem_pools/tx_pool/index.js'; export * from './tx_validator/index.js'; diff --git a/yarn-project/p2p/src/mocks/index.ts b/yarn-project/p2p/src/mocks/index.ts index bee6dc519fa..56a98c4462d 100644 --- a/yarn-project/p2p/src/mocks/index.ts +++ b/yarn-project/p2p/src/mocks/index.ts @@ -24,11 +24,11 @@ import { type Libp2p, type Libp2pOptions, createLibp2p } from 'libp2p'; import { BootstrapNode } from '../bootstrap/bootstrap.js'; import { type BootnodeConfig, type P2PConfig } from '../config.js'; import { type MemPools } from '../mem_pools/interface.js'; -import { DiscV5Service } from '../service/discV5_service.js'; -import { LibP2PService } from '../service/libp2p_service.js'; -import { type PeerManager } from '../service/peer_manager.js'; -import { type P2PReqRespConfig } from '../service/reqresp/config.js'; -import { pingHandler, statusHandler } from '../service/reqresp/handlers.js'; +import { DiscV5Service } from '../services/discv5/discV5_service.js'; +import { LibP2PService } from '../services/libp2p/libp2p_service.js'; +import { type PeerManager } from '../services/peer_manager.js'; +import { type P2PReqRespConfig } from '../services/reqresp/config.js'; +import { pingHandler, statusHandler } from '../services/reqresp/handlers.js'; import { PING_PROTOCOL, type ReqRespSubProtocolHandlers, @@ -36,8 +36,8 @@ import { STATUS_PROTOCOL, TX_REQ_PROTOCOL, noopValidator, -} from '../service/reqresp/interface.js'; -import { ReqResp } from '../service/reqresp/reqresp.js'; +} from '../services/reqresp/interface.js'; +import { ReqResp } from '../services/reqresp/reqresp.js'; import { type PubSubLibp2p } from '../util.js'; /** diff --git a/yarn-project/p2p/src/service/index.ts b/yarn-project/p2p/src/service/index.ts deleted file mode 100644 index 4e197f1c107..00000000000 --- a/yarn-project/p2p/src/service/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './service.js'; -export * from './libp2p_service.js'; diff --git a/yarn-project/p2p/src/service/data_store.test.ts b/yarn-project/p2p/src/services/data_store.test.ts similarity index 100% rename from yarn-project/p2p/src/service/data_store.test.ts rename to yarn-project/p2p/src/services/data_store.test.ts diff --git a/yarn-project/p2p/src/service/data_store.ts b/yarn-project/p2p/src/services/data_store.ts similarity index 100% rename from yarn-project/p2p/src/service/data_store.ts rename to yarn-project/p2p/src/services/data_store.ts diff --git a/yarn-project/p2p/src/service/discV5_service.ts b/yarn-project/p2p/src/services/discv5/discV5_service.ts similarity index 98% rename from yarn-project/p2p/src/service/discV5_service.ts rename to yarn-project/p2p/src/services/discv5/discV5_service.ts index 5b2ceffcd4c..3ce7e499ae6 100644 --- a/yarn-project/p2p/src/service/discV5_service.ts +++ b/yarn-project/p2p/src/services/discv5/discV5_service.ts @@ -8,9 +8,9 @@ import type { PeerId } from '@libp2p/interface'; import { type Multiaddr, multiaddr } from '@multiformats/multiaddr'; import EventEmitter from 'events'; -import type { P2PConfig } from '../config.js'; -import { convertToMultiaddr } from '../util.js'; -import { type PeerDiscoveryService, PeerDiscoveryState } from './service.js'; +import type { P2PConfig } from '../../config.js'; +import { convertToMultiaddr } from '../../util.js'; +import { type PeerDiscoveryService, PeerDiscoveryState } from '../service.js'; export const AZTEC_ENR_KEY = 'aztec_network'; diff --git a/yarn-project/p2p/src/service/discv5_service.test.ts b/yarn-project/p2p/src/services/discv5/discv5_service.test.ts similarity index 97% rename from yarn-project/p2p/src/service/discv5_service.test.ts rename to yarn-project/p2p/src/services/discv5/discv5_service.test.ts index 1f2ce69cb34..552aa98e6df 100644 --- a/yarn-project/p2p/src/service/discv5_service.test.ts +++ b/yarn-project/p2p/src/services/discv5/discv5_service.test.ts @@ -7,10 +7,10 @@ import { jest } from '@jest/globals'; import type { PeerId } from '@libp2p/interface'; import { createSecp256k1PeerId } from '@libp2p/peer-id-factory'; -import { BootstrapNode } from '../bootstrap/bootstrap.js'; -import { type BootnodeConfig, type P2PConfig, getP2PDefaultConfig } from '../config.js'; +import { BootstrapNode } from '../../bootstrap/bootstrap.js'; +import { type BootnodeConfig, type P2PConfig, getP2PDefaultConfig } from '../../config.js'; +import { PeerDiscoveryState } from '../service.js'; import { DiscV5Service } from './discV5_service.js'; -import { PeerDiscoveryState } from './service.js'; const waitForPeers = (node: DiscV5Service, expectedCount: number): Promise => { const timeout = 7_000; diff --git a/yarn-project/p2p/src/service/dummy_service.ts b/yarn-project/p2p/src/services/dummy_service.ts similarity index 100% rename from yarn-project/p2p/src/service/dummy_service.ts rename to yarn-project/p2p/src/services/dummy_service.ts diff --git a/yarn-project/p2p/src/service/encoding.ts b/yarn-project/p2p/src/services/encoding.ts similarity index 100% rename from yarn-project/p2p/src/service/encoding.ts rename to yarn-project/p2p/src/services/encoding.ts diff --git a/yarn-project/p2p/src/services/index.ts b/yarn-project/p2p/src/services/index.ts new file mode 100644 index 00000000000..41c15c7624b --- /dev/null +++ b/yarn-project/p2p/src/services/index.ts @@ -0,0 +1,2 @@ +export * from './service.js'; +export * from './libp2p/libp2p_service.js'; diff --git a/yarn-project/p2p/src/service/libp2p_service.ts b/yarn-project/p2p/src/services/libp2p/libp2p_service.ts similarity index 96% rename from yarn-project/p2p/src/service/libp2p_service.ts rename to yarn-project/p2p/src/services/libp2p/libp2p_service.ts index a95d1368064..e4a6449a539 100644 --- a/yarn-project/p2p/src/service/libp2p_service.ts +++ b/yarn-project/p2p/src/services/libp2p/libp2p_service.ts @@ -35,20 +35,20 @@ import { mplex } from '@libp2p/mplex'; import { tcp } from '@libp2p/tcp'; import { createLibp2p } from 'libp2p'; -import { type P2PConfig } from '../config.js'; -import { type MemPools } from '../mem_pools/interface.js'; +import { type P2PConfig } from '../../config.js'; +import { type MemPools } from '../../mem_pools/interface.js'; import { DataTxValidator, DoubleSpendTxValidator, MetadataTxValidator, TxProofValidator, -} from '../tx_validator/index.js'; -import { type PubSubLibp2p, convertToMultiaddr } from '../util.js'; -import { AztecDatastore } from './data_store.js'; -import { SnappyTransform, fastMsgIdFn, getMsgIdFn, msgIdToStrFn } from './encoding.js'; -import { PeerManager } from './peer_manager.js'; -import { PeerErrorSeverity } from './peer_scoring.js'; -import { pingHandler, statusHandler } from './reqresp/handlers.js'; +} from '../../tx_validator/index.js'; +import { type PubSubLibp2p, convertToMultiaddr } from '../../util.js'; +import { AztecDatastore } from '../data_store.js'; +import { SnappyTransform, fastMsgIdFn, getMsgIdFn, msgIdToStrFn } from '../encoding.js'; +import { PeerErrorSeverity } from '../peer-scoring/peer_scoring.js'; +import { PeerManager } from '../peer_manager.js'; +import { pingHandler, statusHandler } from '../reqresp/handlers.js'; import { DEFAULT_SUB_PROTOCOL_HANDLERS, DEFAULT_SUB_PROTOCOL_VALIDATORS, @@ -58,9 +58,9 @@ import { STATUS_PROTOCOL, type SubProtocolMap, TX_REQ_PROTOCOL, -} from './reqresp/interface.js'; -import { ReqResp } from './reqresp/reqresp.js'; -import type { P2PService, PeerDiscoveryService } from './service.js'; +} from '../reqresp/interface.js'; +import { ReqResp } from '../reqresp/reqresp.js'; +import type { P2PService, PeerDiscoveryService } from '../service.js'; /** * Lib P2P implementation of the P2PService interface. @@ -500,6 +500,9 @@ export class LibP2PService extends WithTracer implement * @param peerId - The peer ID of the peer that sent the tx. * @returns True if the tx is valid, false otherwise. */ + @trackSpan('Libp2pService.validateRequestedTx', (requestedTxHash, _responseTx) => ({ + [Attributes.TX_HASH]: requestedTxHash.toString(), + })) private async validateRequestedTx(requestedTxHash: TxHash, responseTx: Tx, peerId: PeerId): Promise { const proofValidator = new TxProofValidator(this.proofVerifier); const validProof = await proofValidator.validateTx(responseTx); @@ -520,6 +523,9 @@ export class LibP2PService extends WithTracer implement return true; } + @trackSpan('Libp2pService.validatePropagatedTx', tx => ({ + [Attributes.TX_HASH]: tx.getTxHash().toString(), + })) private async validatePropagatedTx(tx: Tx, peerId: PeerId): Promise { const blockNumber = (await this.l2BlockSource.getBlockNumber()) + 1; // basic data validation diff --git a/yarn-project/p2p/src/service/peer_scoring.test.ts b/yarn-project/p2p/src/services/peer-scoring/peer_scoring.test.ts similarity index 98% rename from yarn-project/p2p/src/service/peer_scoring.test.ts rename to yarn-project/p2p/src/services/peer-scoring/peer_scoring.test.ts index 328f5dcd232..92592d9a026 100644 --- a/yarn-project/p2p/src/service/peer_scoring.test.ts +++ b/yarn-project/p2p/src/services/peer-scoring/peer_scoring.test.ts @@ -1,6 +1,6 @@ import { jest } from '@jest/globals'; -import { getP2PDefaultConfig } from '../config.js'; +import { getP2PDefaultConfig } from '../../config.js'; import { PeerErrorSeverity, PeerScoring } from './peer_scoring.js'; describe('PeerScoring', () => { diff --git a/yarn-project/p2p/src/service/peer_scoring.ts b/yarn-project/p2p/src/services/peer-scoring/peer_scoring.ts similarity index 98% rename from yarn-project/p2p/src/service/peer_scoring.ts rename to yarn-project/p2p/src/services/peer-scoring/peer_scoring.ts index abf407798e1..93a62645e0e 100644 --- a/yarn-project/p2p/src/service/peer_scoring.ts +++ b/yarn-project/p2p/src/services/peer-scoring/peer_scoring.ts @@ -1,6 +1,6 @@ import { median } from '@aztec/foundation/collection'; -import { type P2PConfig } from '../config.js'; +import { type P2PConfig } from '../../config.js'; export enum PeerErrorSeverity { /** diff --git a/yarn-project/p2p/src/service/peer_manager.ts b/yarn-project/p2p/src/services/peer_manager.ts similarity index 99% rename from yarn-project/p2p/src/service/peer_manager.ts rename to yarn-project/p2p/src/services/peer_manager.ts index e2cc4db28cc..f078b2924d4 100644 --- a/yarn-project/p2p/src/service/peer_manager.ts +++ b/yarn-project/p2p/src/services/peer_manager.ts @@ -9,7 +9,7 @@ import { inspect } from 'util'; import { type P2PConfig } from '../config.js'; import { type PubSubLibp2p } from '../util.js'; -import { type PeerErrorSeverity, PeerScoring } from './peer_scoring.js'; +import { type PeerErrorSeverity, PeerScoring } from './peer-scoring/peer_scoring.js'; import { type PeerDiscoveryService } from './service.js'; const MAX_DIAL_ATTEMPTS = 3; diff --git a/yarn-project/p2p/src/service/reqresp/config.ts b/yarn-project/p2p/src/services/reqresp/config.ts similarity index 100% rename from yarn-project/p2p/src/service/reqresp/config.ts rename to yarn-project/p2p/src/services/reqresp/config.ts diff --git a/yarn-project/p2p/src/service/reqresp/handlers.ts b/yarn-project/p2p/src/services/reqresp/handlers.ts similarity index 100% rename from yarn-project/p2p/src/service/reqresp/handlers.ts rename to yarn-project/p2p/src/services/reqresp/handlers.ts diff --git a/yarn-project/p2p/src/service/reqresp/index.ts b/yarn-project/p2p/src/services/reqresp/index.ts similarity index 100% rename from yarn-project/p2p/src/service/reqresp/index.ts rename to yarn-project/p2p/src/services/reqresp/index.ts diff --git a/yarn-project/p2p/src/service/reqresp/interface.ts b/yarn-project/p2p/src/services/reqresp/interface.ts similarity index 100% rename from yarn-project/p2p/src/service/reqresp/interface.ts rename to yarn-project/p2p/src/services/reqresp/interface.ts diff --git a/yarn-project/p2p/src/service/reqresp/rate_limiter/index.ts b/yarn-project/p2p/src/services/reqresp/rate_limiter/index.ts similarity index 100% rename from yarn-project/p2p/src/service/reqresp/rate_limiter/index.ts rename to yarn-project/p2p/src/services/reqresp/rate_limiter/index.ts diff --git a/yarn-project/p2p/src/service/reqresp/rate_limiter/rate_limiter.test.ts b/yarn-project/p2p/src/services/reqresp/rate_limiter/rate_limiter.test.ts similarity index 98% rename from yarn-project/p2p/src/service/reqresp/rate_limiter/rate_limiter.test.ts rename to yarn-project/p2p/src/services/reqresp/rate_limiter/rate_limiter.test.ts index 813eb1ddbc9..019d0a7183b 100644 --- a/yarn-project/p2p/src/service/reqresp/rate_limiter/rate_limiter.test.ts +++ b/yarn-project/p2p/src/services/reqresp/rate_limiter/rate_limiter.test.ts @@ -2,8 +2,8 @@ import { jest } from '@jest/globals'; import { type PeerId } from '@libp2p/interface'; import { type MockProxy, mock } from 'jest-mock-extended'; +import { PeerErrorSeverity } from '../../peer-scoring/peer_scoring.js'; import { type PeerManager } from '../../peer_manager.js'; -import { PeerErrorSeverity } from '../../peer_scoring.js'; import { PING_PROTOCOL, type ReqRespSubProtocolRateLimits, TX_REQ_PROTOCOL } from '../interface.js'; import { RequestResponseRateLimiter } from './rate_limiter.js'; diff --git a/yarn-project/p2p/src/service/reqresp/rate_limiter/rate_limiter.ts b/yarn-project/p2p/src/services/reqresp/rate_limiter/rate_limiter.ts similarity index 99% rename from yarn-project/p2p/src/service/reqresp/rate_limiter/rate_limiter.ts rename to yarn-project/p2p/src/services/reqresp/rate_limiter/rate_limiter.ts index 37b2909c9ae..be92f06ec2f 100644 --- a/yarn-project/p2p/src/service/reqresp/rate_limiter/rate_limiter.ts +++ b/yarn-project/p2p/src/services/reqresp/rate_limiter/rate_limiter.ts @@ -5,8 +5,8 @@ */ import { type PeerId } from '@libp2p/interface'; +import { PeerErrorSeverity } from '../../peer-scoring/peer_scoring.js'; import { type PeerManager } from '../../peer_manager.js'; -import { PeerErrorSeverity } from '../../peer_scoring.js'; import { type ReqRespSubProtocol, type ReqRespSubProtocolRateLimits } from '../interface.js'; import { DEFAULT_RATE_LIMITS } from './rate_limits.js'; diff --git a/yarn-project/p2p/src/service/reqresp/rate_limiter/rate_limits.ts b/yarn-project/p2p/src/services/reqresp/rate_limiter/rate_limits.ts similarity index 100% rename from yarn-project/p2p/src/service/reqresp/rate_limiter/rate_limits.ts rename to yarn-project/p2p/src/services/reqresp/rate_limiter/rate_limits.ts diff --git a/yarn-project/p2p/src/service/reqresp/reqresp.integration.test.ts b/yarn-project/p2p/src/services/reqresp/reqresp.integration.test.ts similarity index 98% rename from yarn-project/p2p/src/service/reqresp/reqresp.integration.test.ts rename to yarn-project/p2p/src/services/reqresp/reqresp.integration.test.ts index f6483ba9563..6b11f5b01c6 100644 --- a/yarn-project/p2p/src/service/reqresp/reqresp.integration.test.ts +++ b/yarn-project/p2p/src/services/reqresp/reqresp.integration.test.ts @@ -26,8 +26,8 @@ import { type EpochProofQuotePool } from '../../mem_pools/epoch_proof_quote_pool import { type TxPool } from '../../mem_pools/tx_pool/index.js'; import { AlwaysFalseCircuitVerifier, AlwaysTrueCircuitVerifier } from '../../mocks/index.js'; import { convertToMultiaddr, createLibP2PPeerIdFromPrivateKey } from '../../util.js'; -import { AZTEC_ENR_KEY, AZTEC_NET } from '../discV5_service.js'; -import { PeerErrorSeverity } from '../peer_scoring.js'; +import { AZTEC_ENR_KEY, AZTEC_NET } from '../discv5/discV5_service.js'; +import { PeerErrorSeverity } from '../peer-scoring/peer_scoring.js'; /** * Mockify helper for testing purposes. diff --git a/yarn-project/p2p/src/service/reqresp/reqresp.test.ts b/yarn-project/p2p/src/services/reqresp/reqresp.test.ts similarity index 99% rename from yarn-project/p2p/src/service/reqresp/reqresp.test.ts rename to yarn-project/p2p/src/services/reqresp/reqresp.test.ts index 0caeda85991..499ebd63564 100644 --- a/yarn-project/p2p/src/service/reqresp/reqresp.test.ts +++ b/yarn-project/p2p/src/services/reqresp/reqresp.test.ts @@ -14,8 +14,8 @@ import { startNodes, stopNodes, } from '../../mocks/index.js'; +import { PeerErrorSeverity } from '../peer-scoring/peer_scoring.js'; import { type PeerManager } from '../peer_manager.js'; -import { PeerErrorSeverity } from '../peer_scoring.js'; import { PING_PROTOCOL, RequestableBuffer, TX_REQ_PROTOCOL } from './interface.js'; const PING_REQUEST = RequestableBuffer.fromBuffer(Buffer.from('ping')); diff --git a/yarn-project/p2p/src/service/reqresp/reqresp.ts b/yarn-project/p2p/src/services/reqresp/reqresp.ts similarity index 99% rename from yarn-project/p2p/src/service/reqresp/reqresp.ts rename to yarn-project/p2p/src/services/reqresp/reqresp.ts index 43aa2cfa75d..261c2d09fd2 100644 --- a/yarn-project/p2p/src/service/reqresp/reqresp.ts +++ b/yarn-project/p2p/src/services/reqresp/reqresp.ts @@ -13,8 +13,8 @@ import { InvalidResponseError, } from '../../errors/reqresp.error.js'; import { SnappyTransform } from '../encoding.js'; +import { PeerErrorSeverity } from '../peer-scoring/peer_scoring.js'; import { type PeerManager } from '../peer_manager.js'; -import { PeerErrorSeverity } from '../peer_scoring.js'; import { type P2PReqRespConfig } from './config.js'; import { DEFAULT_SUB_PROTOCOL_HANDLERS, diff --git a/yarn-project/p2p/src/service/service.ts b/yarn-project/p2p/src/services/service.ts similarity index 100% rename from yarn-project/p2p/src/service/service.ts rename to yarn-project/p2p/src/services/service.ts