Skip to main content

Crate ethrex_p2p

Crate ethrex_p2p 

Source
Expand description

§ethrex P2P Networking

Peer-to-peer networking layer for the ethrex Ethereum client.

§Overview

This crate implements the Ethereum P2P networking stack:

  • Discovery: Node discovery using discv4 (and experimental discv5)
  • RLPx: Encrypted transport protocol for peer communication
  • eth Protocol: Block and transaction propagation
  • snap Protocol: Fast state synchronization

§Architecture

┌─────────────────────────────────────────────────────────────┐
│                      Network Layer                           │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐ │
│  │   discv4    │  │    RLPx     │  │   Peer Handler      │ │
│  │ (Discovery) │  │ (Transport) │  │   (Messages)        │ │
│  └─────────────┘  └─────────────┘  └─────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
                             │
          ┌──────────────────┼──────────────────┐
          ▼                  ▼                  ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│   Sync Manager  │ │ TX Broadcaster  │ │  Snap Sync      │
└─────────────────┘ └─────────────────┘ └─────────────────┘

§Key Components

  • network: Network initialization and peer management
  • peer_handler: Message handling for connected peers
  • sync_manager: Block synchronization coordination
  • sync: Full and snap sync implementations
  • tx_broadcaster: Transaction pool broadcasting
  • discv4: Node discovery protocol v4
  • rlpx: RLPx encrypted transport

§Usage

use ethrex_p2p::{start_network, SyncManager};

// Start the P2P network
let (sync_manager, peer_handler) = start_network(
    udp_addr,
    tcp_addr,
    bootnodes,
    signer,
    storage,
    blockchain,
).await?;

// Start synchronization
sync_manager.start_sync().await?;

§Protocols

  • eth/68: Block and transaction exchange
  • snap/1: State snapshot synchronization

Re-exports§

pub use discovery::DiscoveryConfig;
pub use network::periodically_show_peer_stats;
pub use network::start_network;

Modules§

backend
discovery
Discovery protocol implementation for running both discv4 and discv5 on a shared UDP port.
discv4
discv5
network
peer_handler
peer_table
Unified peer table for both discv4 and discv5 discovery protocols.
rlpx
snap
Snap Sync Protocol Implementation
sync
Sync module - orchestrates full and snap synchronization
sync_manager
tx_broadcaster
types
utils