Skip to content

Commit 5f0c6b6

Browse files
author
EchoBT
committed
fix: Skip dialing self as bootstrap peer
When the validator is the bootnode itself, it would try to dial its own peer ID which causes 'tried to dial local peer id' error. Now extracts peer ID from bootstrap multiaddr and skips if it matches the local peer ID.
1 parent 11cfe4a commit 5f0c6b6

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

crates/network/src/node.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,23 @@ impl NetworkNode {
178178
Ok(())
179179
}
180180

181-
/// Dial all bootstrap peers
181+
/// Dial all bootstrap peers (skips self)
182182
pub fn dial_bootstrap_peers(&mut self) {
183183
for addr in self.bootstrap_peers.clone() {
184+
// Extract peer ID from multiaddr and skip if it's our own
185+
if let Some(peer_id) = addr.iter().find_map(|p| {
186+
if let libp2p::multiaddr::Protocol::P2p(id) = p {
187+
Some(id)
188+
} else {
189+
None
190+
}
191+
}) {
192+
if peer_id == self.local_peer_id {
193+
debug!("Skipping bootstrap peer {} (it's us)", addr);
194+
continue;
195+
}
196+
}
197+
184198
info!("Dialing bootstrap peer: {}", addr);
185199
if let Err(e) = self.swarm.dial(addr.clone()) {
186200
warn!("Failed to dial bootstrap peer {}: {}", addr, e);

0 commit comments

Comments
 (0)