Skip to content

Commit 36fd93f

Browse files
fix: false negative retrieving seed peers in connectivity manager at startup (#7474)
Description --- This PR fixes a race condition between adding seed peers at startup and retrieving them from the peer manager in the connectivity manager. Motivation and Context --- The warning message `WARN Failed to get seed peers from PeerManager, using empty list // comms/core/src/connectivity/manager.rs:207` is a timing issue. In this context the seed peer list is passed to the proactive dialer to exclude them from being proactively dialed if other connections exist. On a node with proper connectivity, seed peer dial requests are coming through straight after. - `2025-09-04 16:28:05.638210600 [p2p::initialization] DEBUG Adding seed peer [PeerFlags(SEED)[0984896e74022c44] ` - `2025-09-04 16:28:05.648016500 [comms::connectivity::manager] DEBUG ConnectivityManager started` - `2025-09-04 16:28:05.648239900 [comms::connectivity::manager] WARN Failed to get seed peers from PeerManager, using empty list` - `2025-09-04 16:28:05.648850400 [comms::dht::connectivity] DEBUG Adding 5 neighbouring peer(s), removing 0 peers: 0984896e74022c442c1034852c, ` - `2025-09-04 16:28:05.648912900 [comms::connectivity::manager] TRACE Request (11267568784269984977): DialPeer { node_id: NodeId(0984896e74022c442c1034852c), reply_tx: None }` ... - `2025-09-04 16:31:05.655859300 [comms::connectivity::manager] DEBUG (5619097807157888458) Starting proactive dialing execution - current connections: 10, target: 8` How Has This Been Tested? --- System-level testing What process can a PR reviewer use to test or verify this change? --- Code review <!-- Checklist --> <!-- 1. Is the title of your PR in the form that would make nice release notes? The title, excluding the conventional commit tag, will be included exactly as is in the CHANGELOG, so please think about it carefully. --> Breaking Changes --- - [x] None - [ ] Requires data directory on base node to be deleted - [ ] Requires hard fork - [ ] Other - Please specify <!-- Does this include a breaking change? If so, include this line as a footer --> <!-- BREAKING CHANGE: Description what the user should do, e.g. delete a database, resync the chain --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Seed peers now load on-demand instead of at startup, reducing startup overhead and improving initial responsiveness. * **Chores** * Improved diagnostic logging around seed peer retrieval and DNS seed parsing, including warnings for parse failures and failed seed lookups to aid troubleshooting. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent b0cfe30 commit 36fd93f

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

base_layer/p2p/src/peer_seeds.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ impl DnsSeedResolver {
7676
/// ```
7777
pub async fn resolve(&mut self, addr: &str) -> Result<Vec<SeedPeer>, DnsClientError> {
7878
let records = self.client.query_txt(addr).await?;
79-
let peers = records
79+
trace!(target: LOG_TARGET, "DNS records: {:?}", records);
80+
let peers: Vec<_> = records
8081
.into_iter()
8182
.filter_map(|txt| {
8283
txt.parse()
@@ -89,6 +90,7 @@ impl DnsSeedResolver {
8990
.ok()
9091
})
9192
.collect();
93+
trace!(target: LOG_TARGET, "Seed peers: {:?}", peers.iter().map(|p| format!("{}", p)).collect::<Vec<_>>());
9294
Ok(peers)
9395
}
9496
}

comms/core/src/connectivity/manager.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,6 @@ impl ConnectivityManagerActor {
199199

200200
self.publish_event(ConnectivityEvent::ConnectivityStateInitialized);
201201

202-
self.seeds = self
203-
.peer_manager
204-
.get_seed_peers()
205-
.await
206-
.unwrap_or({
207-
warn!(target: LOG_TARGET, "Failed to get seed peers from PeerManager, using empty list");
208-
vec![]
209-
})
210-
.iter()
211-
.map(|s| s.node_id.clone())
212-
.collect();
213-
214202
loop {
215203
tokio::select! {
216204
Some(req) = self.request_rx.recv() => {
@@ -1217,6 +1205,23 @@ impl ConnectivityManagerActor {
12171205
self.update_circuit_breaker_metrics();
12181206

12191207
// Execute proactive dialing logic
1208+
if self.seeds.is_empty() {
1209+
self.seeds = self
1210+
.peer_manager
1211+
.get_seed_peers()
1212+
.await
1213+
.inspect_err(|err| {
1214+
warn!(
1215+
target: LOG_TARGET,
1216+
"Failed to get seed peers from PeerManager, using empty list for proactive dialing, seed peers \
1217+
will not be excluded as a first pass. ({})", err
1218+
);
1219+
})
1220+
.unwrap_or(vec![])
1221+
.iter()
1222+
.map(|s| s.node_id.clone())
1223+
.collect();
1224+
}
12201225
match self
12211226
.proactive_dialer
12221227
.execute_proactive_dialing(&self.pool, &self.connection_stats, &self.seeds, task_id)

comms/core/src/peer_manager/peer_storage_sql.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,15 @@ impl PeerStorageSql {
265265
)?)
266266
}
267267

268+
/// Get all seed peers
268269
pub fn get_seed_peers(&self) -> Result<Vec<Peer>, PeerManagerError> {
269-
Ok(self.peer_db.get_seed_peers()?)
270+
let seed_peers = self.peer_db.get_seed_peers()?;
271+
trace!(
272+
target: LOG_TARGET,
273+
"Get seed peers: {:?}",
274+
seed_peers.iter().map(|p| p.node_id.short_str()).collect::<Vec<_>>(),
275+
);
276+
Ok(seed_peers)
270277
}
271278

272279
/// Compile a random list of communication node peers of size _n_ that are not banned or offline and

0 commit comments

Comments
 (0)