Skip to content

v7.2.3

Choose a tag to compare

@OSXBasedAnon OSXBasedAnon released this 21 Jan 17:08
· 629 commits to main since this release
69cf451

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 --connect command now attempts to establish a connection up to MAX_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 --test flag 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 --connect command have been improved to be more user-friendly, including an example and an explanation of the --test flag.

Code Breakdown:

  • The code uses a while loop to retry the connection up to MAX_ATTEMPTS times.
  • tokio::time::timeout is 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_peer function is assumed to handle the actual connection and peer verification logic.
  • The handle_chain_sync function 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.