Skip to content

v7.2.1

Choose a tag to compare

@OSXBasedAnon OSXBasedAnon released this 20 Jan 05:20
· 647 commits to main since this release
a68b3f5

Network Discovery and Connection Handling Overhaul

This release introduces a substantial overhaul of the network discovery and connection handling mechanisms, focusing on enhanced performance, stability, and maintainability.

Key Changes:

  • Refactored Network Discovery (discover_network_nodes):
    • Introduced NetworkRange enum (enum NetworkRange { V4((Ipv4Net, usize)), V6((Ipv6Net, usize)) }) to encapsulate IP network ranges and scan sizes, improving type safety and code clarity.
    • Moved network range parsing from within the discovery tasks to the main discover_network_nodes function, significantly reducing redundant computations.
    • Simplified IPv6 address generation using a more deterministic approach based on prefix manipulation, reducing randomness within the scan loop and improving testability.
    • Improved concurrency control with Semaphore and atomic counters for managing active connections and peer count.
    • Implemented a timeout mechanism using tokio::select! to prevent indefinite discovery attempts.
  • Enhanced Connection Handling (handle_connection and handle_network_event):
    • Implemented the handle_peer_message function, responsible for deserializing incoming messages using bincode and dispatching them for processing.
    • Corrected the handling of NetworkEvent::ChainRequest within handle_network_event. The event now includes the requesting peer's SocketAddr, enabling the sending of NetworkEvent::ChainResponse directly back to the requester.
    • Added peer_txs: RwLock<HashMap<SocketAddr, mpsc::Sender<NetworkEvent>>> to the Node struct to efficiently manage senders for connected peers. This eliminates the redundant passing of the tx sender to handle_peer_message.
    • Improved error handling within ChainRequest to manage potential errors during block retrieval from the local blockchain.

Bug Fixes:

  • Fixed a critical bug where ChainResponse messages were not being sent to peers requesting chain data, preventing proper chain synchronization.
  • Mitigated a potential race condition where the number of connected peers could briefly exceed MAX_PEERS due to asynchronous task execution. While the issue is largely mitigated with the new concurrency controls, further refinements for absolute guarantees may be explored in future releases.

Technical Details:

  • Utilized Ipv4Net and Ipv6Net for structured IP address range representation and manipulation.
  • Employed tokio::sync::Semaphore for controlled concurrency during network scans.
  • Leveraged tokio::select! for efficient timeout management.
  • Used RwLock for safe concurrent access to peer information and senders.

Full Changelog: v7.1.5...v7.2.1