Skip to content

Conversation

@yashksaini-coder
Copy link
Contributor

PR: Enhance DNS support in bootstrap discovery

Issue: #1187
Discussion: #1171 (Bootstrap DNS enhancement)

Summary

This PR enhances DNS support in bootstrap discovery by:

  1. Extended protocol support: Recognizing dns, dns4, and dns6 in addition to dnsaddr in is_dns_addr(), enabling IPv4/IPv6-specific resolution control and alignment with the libp2p multiaddr specification.
  2. Robust error handling: Wrapping DNS resolution in try/except, distinguishing “resolution failed” from “no results,” logging informative messages (address + error/details), and ensuring bootstrap continues processing other addresses after DNS failures.

Motivation

  • Limited protocol support: Previously only dnsaddr was treated as a DNS address; dns, dns4, and dns6 were ignored, preventing IPv4/IPv6-specific bootstrap behaviour.
  • Minimal error handling: Only None was checked; there was no distinction between resolution failure and empty results, and little diagnostic information for debugging.

Changes

Code

  • libp2p/discovery/bootstrap/bootstrap.py
    • is_dns_addr(addr): Now returns True for addresses whose first protocol is one of dns, dns4, dns6, or dnsaddr (set-based check over addr.protocols()).
    • _process_bootstrap_addr(addr_str):
      • Invalid multiaddr format: caught and logged at debug level; return (no raise).
      • DNS addresses: resolver.resolve(multiaddr) wrapped in try/except. On exception: log warning with address and exception; return. On success: if resolved_addrs is falsy (None or empty list), log warning and return. Otherwise use resolved addresses and existing peer_id/add_addr logic.
      • Ensures one failing DNS address does not stop other bootstrap addresses from being processed.

Tests

  • tests/core/discovery/bootstrap/test_utils.py
    • test_is_dns_addr_dns_protocols: Asserts that is_dns_addr() returns True for /dns4/..., /dns6/..., /dns/..., /dnsaddr/... and False for /ip4/..., /ip6/....

Behaviour

  • Backward compatibility: Existing dnsaddr bootstrap entries behave as before.
  • Existing tests: All existing discovery/bootstrap tests continue to pass.

Requirements coverage (from issue)

Req Description Status
1 is_dns_addr() recognizes dns, dns4, dns6, dnsaddr
2 Exception handling for DNS resolution ✅ (py-multiaddr does not expose ResolutionError/RecursionLimitError; all failures caught and logged)
3 Distinguish “no results” vs “resolution failed”
4 Informative error messages (address + details)
5 Bootstrap continues after DNS failures
6 Backward compatibility with dnsaddr
7 Unit tests for DNS protocol types ✅ (protocol detection); optional: explicit exception-path test
8 Integration tests with dns4/dns6 ✅ (test_integration: DNS addresses in host, DNS failure/empty continues with mocks)
9 Documentation with examples ✅ (Getting Started + libp2p.discovery.bootstrap + newsfragment 1171)
10 All existing tests pass

Testing

  • pytest tests/core/discovery/bootstrap/ -v
  • Broader discovery/transport test runs as needed for regressions.

Open questions (from issue, out of scope for this PR)

  • Retry with exponential backoff for DNS failures
  • Metrics/monitoring for DNS resolution success/failure
  • Default DNS timeout
  • DNS caching

Checklist

  • is_dns_addr() updated for dns, dns4, dns6, dnsaddr
  • DNS resolution wrapped in try/except with informative logging
  • “No results” and “resolution failed” handled separately
  • Bootstrap continues with other addresses on DNS failure
  • Unit test for DNS protocol detection added
  • Existing tests pass
  • Integration test with dns4/dns6 (test_bootstrap_integration_with_dns_addresses; test_bootstrap_dns_resolution_failure_continues; test_bootstrap_dns_empty_results_continues)
  • User-facing doc with DNS bootstrap examples (Getting Started: Bootstrap address formats; libp2p.discovery.bootstrap: supported types + examples; newsfragment 1171.feature.rst)

yashksaini-coder and others added 7 commits February 8, 2026 16:30
- Improved error handling for DNS resolution failures in TCP and WebSocket transports, logging specific issues encountered during resolution.
- Refactored multiaddr parsing in CircuitV2Transport to utilize decapsulation for better efficiency and clarity.
- Updated BootstrapDiscovery to handle DNS resolution exceptions and log warnings for missing peer IDs and resolved addresses.
- Utilized protocol codes for type-safe comparisons in multiaddr handling, ensuring robust address validation.
- Consolidated IP extraction logic in multiaddr utilities for consistent parsing across the codebase.
- Updated the test for bootstrap address validation to include DNS protocol detection.
- Introduced a new test to verify that DNS addresses are correctly identified across various DNS protocol formats.
- Refactored existing tests for circuit multiaddr parsing to improve clarity and error handling for invalid cases.
- Updated bootstrap discovery to recognize multiple DNS address formats: `dns`, `dns4`, `dns6`, and `dnsaddr`, improving flexibility for IPv4/IPv6-specific entries.
- Implemented exception handling for DNS resolution failures, ensuring that the process continues with the next address if a resolution fails or returns no results.
- Added user-facing documentation and examples for DNS bootstrap addresses in the Getting Started guide and the bootstrap discovery API documentation.
- Added new tests to validate bootstrap integration with DNS addresses, including support for `dns4`, `dns6`, and `dnsaddr` formats.
- Implemented tests to ensure that DNS resolution failures do not halt the bootstrap process, allowing for continued attempts with other addresses.
- Updated existing tests to utilize validated peer IDs and improved clarity in bootstrap address handling.
@sumanjeet0012
Copy link
Contributor

@yashksaini-coder The current PR and issue focus on enhancing the bootstrap module to support DNS resolution. However, the proposed changes also modify the circuit relay, WebSockets, and several other modules.
To maintain clarity and proper scope management, please either update the issue and PR descriptions to reflect these additional changes or create separate issues for adding DNS resolution support to the other affected modules.

@yashksaini-coder
Copy link
Contributor Author

@yashksaini-coder The current PR and issue focus on enhancing the bootstrap module to support DNS resolution. However, the proposed changes also modify the circuit relay, WebSockets, and several other modules. To maintain clarity and proper scope management, please either update the issue and PR descriptions to reflect these additional changes or create separate issues for adding DNS resolution support to the other affected modules.

Yes Understood I will update the issue and PR regarding the new changes required

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