Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(p2p): move services into folders #10694

Merged
merged 5 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion yarn-project/p2p/src/bootstrap/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/p2p/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/p2p/src/client/p2p_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/p2p/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/p2p/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
14 changes: 7 additions & 7 deletions yarn-project/p2p/src/mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ 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,
type ReqRespSubProtocolValidators,
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';

/**
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/p2p/src/service/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
const timeout = 7_000;
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/p2p/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './service.js';
export * from './libp2p/libp2p_service.js';
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -500,6 +500,9 @@ export class LibP2PService<T extends P2PClientType> 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<boolean> {
const proofValidator = new TxProofValidator(this.proofVerifier);
const validProof = await proofValidator.validateTx(responseTx);
Expand All @@ -520,6 +523,9 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
return true;
}

@trackSpan('Libp2pService.validatePropagatedTx', tx => ({
[Attributes.TX_HASH]: tx.getTxHash().toString(),
}))
private async validatePropagatedTx(tx: Tx, peerId: PeerId): Promise<boolean> {
const blockNumber = (await this.l2BlockSource.getBlockNumber()) + 1;
// basic data validation
Expand Down
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading