fix: topology manager uses actual connection count instead of filtered count #1963
+43
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1962 - The topology manager's
adjust_topology()
function was using filtered connection count instead of actual connection count when making topology decisions.Root Cause
The
adjust_topology()
function receivedneighbor_locations
which had been filtered to exclude connections younger than 5 seconds. During network startup, all connections are < 5 seconds old, soneighbor_locations.len() = 0
even when the node has connections. This caused the manager to constantly try adding more connections.This bug was actually helping some tests pass by bypassing the min_connections check during startup, preventing connection churn in small test networks that would otherwise try to reach 25 connections.
Changes
current_connections
parameter toadjust_topology()
to pass the actual connection countTesting
test_remove_connections
test_add_connections
test_no_adjustment
test_no_peers
test_topology
test_resource_manager_report
test_update_limits
test_no_duplicate_connections_with_few_peers
Impact
This fix ensures the topology manager makes decisions based on actual network state rather than filtered state. The early exit for small networks (< 5 connections) prevents resource-based adjustments from causing churn during network startup or in small test networks, improving stability.
Related
[AI-assisted debugging and comment]
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com