Fix: update DHT peer port when same address exists with different port #226
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 genesis block propagation issue where only 3/10 nodes received the genesis block. The root cause was that ephemeral TCP source ports (e.g., 41092) were being stored in the DHT peer list instead of the correct listening port (8000).
When a node receives an inbound connection, the TCP source port is ephemeral. Previously, when the handshake later provided the correct listening port,
mxd_dht_add_peer()would add a new entry instead of updating the existing one. This causedmxd_broadcast_message()to fail when trying to connect to ephemeral ports.The fix adds a second loop that checks for existing entries with the same IP address but different port, and updates the port rather than creating a duplicate entry.
Review & Testing Checklist for Human
peer_listmodifications are protected by mutex. The diff doesn't show locking, but callers may handle this../letsgo testnet -resetand verify ALL 10 nodes reach Height: 1 (not just 3/10)."Updated peer %s port from %d to %d"messages to confirm the fix is being triggered.Notes