Skip to content

Conversation

@michaelgpt
Copy link
Contributor

This pull request introduces a new utility function for parsing multiple multiaddresses from a string and updates the network handler to support dialing multiple bootnodes. The changes improve flexibility in handling multiaddress formats and enhance error handling for dialing operations.

Parsing multiple multiaddresses:

  • Added the parse_multiple_multiaddrs function in app/src/network/mod.rs to parse multiaddresses from strings in various formats: comma-separated, space-separated, or concatenated. It includes logic to identify and split concatenated multiaddresses at protocol boundaries.
  • Added comprehensive unit tests for the parse_multiple_multiaddrs function to ensure correctness across different input formats, including valid, invalid, and empty inputs.

Enhancements to network handler:

  • Updated the spawn_network_handler function in app/src/network/mod.rs to use the new parse_multiple_multiaddrs function for parsing the remote_bootnode parameter. This allows dialing multiple bootnodes instead of a single one.
  • Improved error handling in spawn_network_handler by logging warnings for individual bootnode dialing failures, ensuring the process continues for other addresses.

…figuration

Add support for connecting to multiple peers via the --remote-bootnode argument
to improve network resilience and connectivity options.

Key changes:
- Add parse_multiple_multiaddrs() function to handle various multiaddress formats
- Support concatenated format: /ip4/1.2.3.4/tcp/1234/ip4/5.6.7.8/tcp/5678
- Support comma-separated format: /ip4/1.2.3.4/tcp/1234,/ip4/5.6.7.8/tcp/5678
- Support space-separated format: /ip4/1.2.3.4/tcp/1234 /ip4/5.6.7.8/tcp/5678
- Maintain backward compatibility with single peer addresses
- Handle connection failures gracefully with warning-level logging
- Add comprehensive test suite covering all supported formats

The network handler now attempts to connect to all specified peers sequentially,
logging each attempt and continuing even if some peers are unreachable.

Example usage:
  --remote-bootnode "/ip4/10.38.1.103/tcp/55444/ip4/10.38.1.105/tcp/55444"

Fixes: AN-268
@michaelgpt michaelgpt requested a review from Copilot August 1, 2025 21:07
@michaelgpt michaelgpt self-assigned this Aug 1, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for parsing and dialing multiple bootnode addresses in the network handler, allowing for more flexible peer discovery and connection redundancy.

  • Introduces a new parse_multiple_multiaddrs function that can handle comma-separated, space-separated, and concatenated multiaddress formats
  • Updates the network handler to dial multiple bootnodes with improved error handling
  • Adds comprehensive unit tests for the new parsing functionality

}

if addresses.is_empty() {
return Err(Error::MultiaddrError(libp2p::multiaddr::Error::InvalidMultiaddr));
Copy link

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message for empty addresses is not descriptive. Consider using a more specific error message like 'No valid multiaddresses found in input' to help with debugging.

Suggested change
return Err(Error::MultiaddrError(libp2p::multiaddr::Error::InvalidMultiaddr));
return Err(Error::NoValidMultiaddrsFound("No valid multiaddresses found in input".to_string()));

Copilot uses AI. Check for mistakes.
Comment on lines +482 to +486
/// Parse multiple multiaddresses from a string.
/// Supports the following formats:
/// - Comma-separated: "/ip4/1.2.3.4/tcp/1234,/ip4/5.6.7.8/tcp/5678"
/// - Space-separated: "/ip4/1.2.3.4/tcp/1234 /ip4/5.6.7.8/tcp/5678"
/// - Concatenated: "/ip4/1.2.3.4/tcp/1234/ip4/5.6.7.8/tcp/5678"
Copy link

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function lacks proper documentation. Consider adding a docstring that explains the parsing logic, error conditions, and provides examples of the supported formats.

Suggested change
/// Parse multiple multiaddresses from a string.
/// Supports the following formats:
/// - Comma-separated: "/ip4/1.2.3.4/tcp/1234,/ip4/5.6.7.8/tcp/5678"
/// - Space-separated: "/ip4/1.2.3.4/tcp/1234 /ip4/5.6.7.8/tcp/5678"
/// - Concatenated: "/ip4/1.2.3.4/tcp/1234/ip4/5.6.7.8/tcp/5678"
/// Parses multiple multiaddresses from a string input.
///
/// # Supported formats
/// - **Comma-separated:** `"/ip4/1.2.3.4/tcp/1234,/ip4/5.6.7.8/tcp/5678"`
/// - **Space-separated:** `"/ip4/1.2.3.4/tcp/1234 /ip4/5.6.7.8/tcp/5678"`
/// - **Concatenated:** `"/ip4/1.2.3.4/tcp/1234/ip4/5.6.7.8/tcp/5678"`
///
/// The function attempts to parse the input string as a list of multiaddresses using the following logic:
/// 1. If the input contains commas, it is split by commas and each part is parsed as a separate multiaddress.
/// 2. If the input contains spaces, it is split by whitespace and each part is parsed as a separate multiaddress.
/// 3. Otherwise, the input is parsed as a single multiaddress, or as concatenated multiaddresses if supported.
///
/// # Error conditions
/// - If any substring fails to parse as a valid `Multiaddr`, the function returns an error.
/// - The error is propagated from `Multiaddr::from_str`.
///
/// # Examples
/// ```
/// // Comma-separated
/// let input = "/ip4/1.2.3.4/tcp/1234,/ip4/5.6.7.8/tcp/5678";
/// let addrs = parse_multiple_multiaddrs(input)?;
///
/// // Space-separated
/// let input = "/ip4/1.2.3.4/tcp/1234 /ip4/5.6.7.8/tcp/5678";
/// let addrs = parse_multiple_multiaddrs(input)?;
///
/// // Concatenated
/// let input = "/ip4/1.2.3.4/tcp/1234/ip4/5.6.7.8/tcp/5678";
/// let addrs = parse_multiple_multiaddrs(input)?;
/// ```

Copilot uses AI. Check for mistakes.
for (i, address) in addresses.iter().enumerate() {
trace!("Dialing bootnode {}: {}", i + 1, address);
if let Err(e) = client.dial(address.clone()).await {
warn!("Failed to dial bootnode {} ({}): {}", i + 1, address, e);
Copy link

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider tracking and returning information about failed dial attempts to the caller, as silently continuing after failures might mask important connectivity issues.

Copilot uses AI. Check for mistakes.
@michaelgpt michaelgpt merged commit 5e34168 into main Aug 1, 2025
3 of 4 checks passed
@michaelgpt michaelgpt deleted the AN-268-alys-support-multiple-peer-addresses-in-remote-bootnode-configuration branch August 1, 2025 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants