Repository navigation
v7.2.1
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
NetworkRangeenum (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_nodesfunction, 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
Semaphoreand atomic counters for managing active connections and peer count. - Implemented a timeout mechanism using
tokio::select!to prevent indefinite discovery attempts.
- Introduced
- Enhanced Connection Handling (
handle_connectionandhandle_network_event):- Implemented the
handle_peer_messagefunction, responsible for deserializing incoming messages usingbincodeand dispatching them for processing. - Corrected the handling of
NetworkEvent::ChainRequestwithinhandle_network_event. The event now includes the requesting peer'sSocketAddr, enabling the sending ofNetworkEvent::ChainResponsedirectly back to the requester. - Added
peer_txs: RwLock<HashMap<SocketAddr, mpsc::Sender<NetworkEvent>>>to theNodestruct to efficiently manage senders for connected peers. This eliminates the redundant passing of thetxsender tohandle_peer_message. - Improved error handling within
ChainRequestto manage potential errors during block retrieval from the local blockchain.
- Implemented the
Bug Fixes:
- Fixed a critical bug where
ChainResponsemessages 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_PEERSdue 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
Ipv4NetandIpv6Netfor structured IP address range representation and manipulation. - Employed
tokio::sync::Semaphorefor controlled concurrency during network scans. - Leveraged
tokio::select!for efficient timeout management. - Used
RwLockfor safe concurrent access to peer information and senders.
Full Changelog: v7.1.5...v7.2.1