Releases: OSXBasedAnon/alphanumeric
7.2.8
This update implements significant performance improvements and fixes a critical bug in the velocity module's
bloom filter implementation.
Major Performance Improvements:
- Mining: Eliminated transaction vector cloning in the hash calculation hot path. Mining now calculates hashes
directly using stack-allocated arrays instead of creating full Block objects, resulting in orders of magnitude
faster hash rates. - Mempool: Replaced O(n²) transaction selection algorithm with BinaryHeap-based O(n log n) implementation. Block
creation is now 5-10x faster under high transaction loads. - Block Hashing: Changed from heap-allocated Vec to stack-allocated fixed-size array for hash calculation,
eliminating allocations in the critical path. - Rate Limiting: Implemented binary search with efficient cleanup instead of full iteration on every check,
achieving 10x performance improvement. - Blockchain Sync: Increased batch processing size from 500 to 1000 blocks, improving sync speed by approximately
50%. - Hex Encoding: Replaced manual formatting with optimized hex::encode library function for 5-10x faster encoding.
Critical Bug Fix:
- Velocity BloomFilter: Fixed add() method which was checking bits but never setting them. The bloom filter was
non-functional, causing unnecessary duplicate network traffic. Now correctly implements atomic bit setting for
proper deduplication.
Code Quality:
- Removed unused variables and imports throughout the codebase
- Fixed all compilation errors
- Maintained backward compatibility with existing functionality
v7.2.7
Consensus and Network Security Enhancements
This release focuses on critical updates to the consensus mechanism and network protocol, improving validator security, network resilience, and data integrity.
Key Changes:
- Validator Tiering and Scoring: Implemented a new
ValidatorTiersystem with a weighted scoring algorithm to categorize validators based on performance. This promotes network health by rewarding reliable participation and establishing a transparent reward structure with new constants forBASE_APYand tier-specific multipliers. libp2pand Velocity Protocol: Refactored the network layer to uselibp2pfor a more robust peer-to-peer framework. This integrates theVelocityprotocol, which ensures data integrity and reliable synchronization.- Concurrency Control: A
ValidationPoolwith aSemaphorehas been added to limit parallel block validations, enhancing node stability and mitigating resource exhaustion attacks. - Protocol Expansion: The Network has been expanded to support the new data integrity and recovery mechanisms.
v7.2.6
Fix connection issue and improve handshake debugging
The problem stemmed from the incorrect use of non-blocking sockets in the connection setup. Additionally, comprehensive logging has been added to the perform_handshake function to facilitate easier debugging of future handshake issues.
Changes:
- Removed
sock.set_nonblocking(true);fromconfigure_tcp_socket. This ensures the use of blocking sockets, which is essential for the current handshake implementation usingread_exactandwrite_all. - Implemented extensive logging within
perform_handshake:- Logs the raw bytes of serialized messages before sending and after receiving.
- Logs the deserialized
HandshakeMessageobjects. - Logs any errors encountered during serialization or deserialization.
- Added logging to
validate_handshakefor key values and signature verification.
Testing:
- Manual testing of node connections has been conducted to verify successful communication following these changes.
Additional Notes:
- The detailed logging introduced in this PR will be instrumental in diagnosing any future handshake-related problems.
v7.2.4
Enhanced Node Startup with Resiliency and Monitoring
This update significantly improves the startup process and ongoing operation of the node, focusing on resiliency, peer management, and network health monitoring.
Key Improvements:
-
Retry Logic for P2P Services: The code now implements retry logic with backoff for initializing core P2P services. This enhances the node's ability to handle temporary service disruptions during startup.
-
Connection Limiter and Backoff: A connection limiter using a semaphore prevents Denial-of-Service (DoS) attacks by throttling incoming connections. Additionally, an exponential backoff mechanism is implemented for handling connection errors, preventing the node from overwhelming peers with retries in case of connection failures.
-
Automatic TCP_NODELAY Configuration: Incoming connections are automatically configured with the
TCP_NODELAYoption to optimize performance for short message transfers. -
Connection Timeouts: A timeout is set for handling incoming connections, preventing the node from hanging indefinitely if a peer connection cannot be established.
-
Peer Management Loop: A dedicated loop continuously monitors the peer list, performing the following actions:
- Periodic Peer Discovery: The node periodically attempts to discover new peers on the network, ensuring a healthy pool of connections.
- Peer Health Checks: The node checks for isolated states (no active peers) and initiates network recovery procedures if necessary.
- Blockchain Sync Checks: The node compares its blockchain height with connected peers and initiates chain synchronization if a peer has a higher block count.
-
Network Health Monitoring: A dedicated loop periodically updates network health metrics, including the number of active peers and the last successful network update time. This information can be used to diagnose potential network issues.
-
Clearer Logging: Informative messages are logged throughout the startup process, including successful initialization, connection events (successes and failures), peer discovery results, and network health checks.
Benefits:
- Improved Startup Reliability: Retry logic for P2P services and handling of connection errors make the node startup process more robust.
- Enhanced Security: Connection limiting protects against DoS attacks.
- Optimized Performance: Automatic
TCP_NODELAYconfiguration and timeouts improve connection efficiency. - Proactive Peer Management: The node actively seeks new peers, maintains existing connections, and initiates blockchain synchronization when necessary.
- Better Monitoring: Network health metrics provide valuable insights into the node's overall network state.
- Detailed Logging: Comprehensive logs aid in debugging and troubleshooting network-related issues.
Overall, this update significantly strengthens the node's ability to establish and maintain a healthy network connection, improving its overall reliability and performance.
v7.2.3
Improved Connection Handling with Retries and Timeout
This update enhances the --connect command functionality by adding retry logic with timeouts and improving user feedback.
Key Changes:
-
Connection Retries: The
--connectcommand now attempts to establish a connection up toMAX_ATTEMPTS(currently 3) times. This improves resilience against transient network issues. -
Timeout per Attempt: Each connection attempt now has a timeout of 10 seconds, preventing the command from hanging indefinitely if the target is unreachable. This timeout is implemented using
tokio::time::timeout. -
Progress Bar Updates: The progress bar now provides more granular feedback during the connection process:
- It displays the current connection attempt number (e.g., "Connection attempt 1/3").
- It shows detailed error messages if a connection attempt fails (including the specific error).
- It indicates when a connection attempt times out.
-
Self-Connection Check: The code includes a check to prevent connecting to the node's own bind address unless the
--testflag is used. This prevents accidental self-connections. -
Immediate Sync After Connection: Upon successful connection, the code now immediately attempts to synchronize the chain using
handle_chain_sync. This ensures that the node is up-to-date with the network as soon as a connection is established. A warning is logged if the initial sync fails. -
Clearer Usage Instructions: The usage instructions for the
--connectcommand have been improved to be more user-friendly, including an example and an explanation of the--testflag.
Code Breakdown:
- The code uses a
whileloop to retry the connection up toMAX_ATTEMPTStimes. tokio::time::timeoutis used to implement the timeout for each connection attempt.- The progress bar (
ProgressBar) is updated with informative messages at each stage of the connection process. - The
node.verify_peerfunction is assumed to handle the actual connection and peer verification logic. - The
handle_chain_syncfunction is called after a successful connection to initiate chain synchronization.
Benefits:
- Improved Reliability: The retry logic makes the connection process more robust against temporary network issues.
- Prevented Deadlocks: The timeout prevents the command from hanging indefinitely.
- Better User Experience: The improved progress bar provides more detailed feedback to the user.
- Prevented Accidental Self-Connections: The self-connection check prevents common user errors.
- Ensured Immediate Sync: The immediate sync after connection ensures that the node is quickly brought up-to-date with the network.
v7.2.2
Network Binding Improvements
This update enhances the network binding logic, providing more robust handling of port allocation and address binding, especially in scenarios where the default port is unavailable.
Key Changes:
-
Explicit Bind Address Handling: The code now explicitly handles cases where a bind address is provided by the user (
bind_addrisSome(addr)). It logs the provided address and attempts to bind to it directly. -
Binding to All Interfaces (0.0.0.0) with Fallback: When no bind address is provided (
bind_addrisNone), the code attempts to bind to all interfaces (0.0.0.0) using theDEFAULT_PORT.-
Primary Port Binding: The code first attempts to bind to the
DEFAULT_PORT. If this succeeds, it logs a success message and proceeds with listening. -
Alternative Port Binding (Fallback): If binding to the
DEFAULT_PORTfails (e.g., the port is already in use), the code now implements a fallback mechanism:- It creates a new socket.
- It attempts to bind to a random available port on all interfaces (using port 0). This ensures that the application can still start even if the default port is occupied.
- It logs the alternative port that was bound to.
-
-
Logging Improvements: More detailed logging has been added to provide better insight into the binding process, including:
- Logging the provided bind address (if any).
- Logging the attempt to bind to all interfaces.
- Logging success or failure of primary port binding.
- Logging the alternative port used in the fallback scenario.
- Logging the final listener address.
-
Socket Options: The following socket options are set for improved performance and reliability:
set_reuse_address(true): Allows reusing the address immediately after the socket is closed.set_reuse_port(true)(Unix only): Allows multiple sockets to bind to the same port.set_nodelay(true): Disables Nagle's algorithm, reducing latency for small packets.
Benefits:
- Improved Reliability: The fallback to a random port ensures that the application can start even if the default port is in use, increasing its robustness.
- Better Error Handling: The improved logging provides more information for diagnosing binding issues.
- Enhanced Performance: The socket options optimize network communication.
- Clearer Code: The logic is now more structured and easier to understand.
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
v7.1.5
Enhanced Peer Discovery with STUN and Prioritized Scanning
This update significantly improves peer discovery, especially for users behind NATs and firewalls.
Key Improvements:
- STUN Integration: Now uses STUN to discover external IP addresses, enabling connections with peers on the wider internet.
- Prioritized Scanning: Prioritizes scanning local and nearby networks (based on STUN results) for faster discovery.
- Common ISP Range Scanning: Includes scanning of common residential and ISP IP ranges to enhance basic discovery, even if STUN fails.
- TCP Socket Configuration: Configures TCP sockets for improved connection performance (e.g.,
TCP_NODELAY). - Peer Information Exchange: Exchanges peer lists with connected nodes to discover even more peers.
Benefits:
- More Reliable NAT Traversal: Significantly improves connections for users behind NATs.
- Faster Discovery: Prioritized scanning finds peers more quickly.
- Broader Reach: STUN and wider range scanning increase the number of discoverable peers.
This update makes peer discovery more robust, efficient, and suitable for real-world network conditions.
v7.1.3
Network Update
Major Improvements
- Enhanced P2P network resilience and synchronization
- Optimized block propagation and chain sync mechanisms
- Improved system sleep/wake handling
- Added exponential backoff for network discovery
- Added comprehensive peer quality assessment
Network Sync Optimizations
- Implemented adaptive peer selection based on latency metrics
- Added intelligent backoff strategy for peer discovery
- Progressive delay: 1s → 3s → 7s → 15s → 31s (capped at 30s)
- Automatic reset on successful connection
- Enhanced peer quality filtering using both latency and recent activity metrics
- Added memory-safe block height synchronization
Reliability Improvements
- Added robust sleep/wake detection and recovery
- Implemented safe state reset after system suspend
- Enhanced validation pool management
- Added comprehensive timeout handling for network operations
- Improved peer connection stability through better health checks
Performance Enhancements
- Optimized block time monitoring (target: 5s blocks)
- Added efficient peer latency tracking
- Improved memory usage in peer state management
- Enhanced network health metrics collection
- Added adaptive sync intervals based on network conditions
Technical Details
- Added type-safe counter implementations
- Improved error handling with detailed context
- Enhanced memory safety with proper bounds checking
- Optimized thread local task management
- Added comprehensive network diagnostics
Constants Configuration
FAST_SYNC_LATENCY: 50ms // Target latency for optimal sync
RECOVERY_LATENCY: 500ms // Maximum acceptable latency
MIN_VIABLE_PEERS: 3 // Minimum peer requirement
MAX_SYNC_ATTEMPTS: 3 // Sync retry limit
HEALTH_CHECK_INTERVAL: 100ms
SYNC_CHECK_INTERVAL: 500msv7.1.2: Add files via upload
Periodic Task Improvements
Sleep Detection
- Both the maintenance task and the P2P event monitoring task now incorporate sleep detection.
- If the time elapsed since the last check exceeds 10 seconds, it indicates that the system has likely been in sleep mode.
- Upon detecting sleep, the function resets various states, clears caches, and rediscovers network nodes to ensure a fresh start.
Adaptive Intervals and Batch Sizes
- The P2P event monitoring task now employs adaptive intervals and batch sizes based on the number of peers in the network.
- The batch size for processing P2P events starts at 100 and dynamically adjusts based on the processing time. It increases when processing is fast and decreases when errors occur, with a maximum of 500 and a minimum of 50.
Exponential Backoff and Reinitialization
- In case of consecutive failures during P2P event handling, an exponential backoff strategy is implemented.
- The backoff duration doubles with each consecutive failure, capped at a maximum of 64 seconds (2^6).
- If the number of consecutive failures exceeds 3, the function attempts to reinitialize the P2P system.
- If the reinitialization fails, the interval is set to 5 seconds to allow for a longer recovery period.
Memory Optimization
- For large networks and when events are processed, the function yields the task to prevent excessive memory usage and allow other tasks to run.
These enhancements aim to improve the overall performance, handle sleep scenarios gracefully, adapt to network conditions, and ensure the stability of the periodic tasks in our application.