Skip to content

Conversation

@AlanRuno
Copy link
Owner

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 caused mxd_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

  • Thread safety: Verify that peer_list modifications are protected by mutex. The diff doesn't show locking, but callers may handle this.
  • Port update assumption: Confirm that always preferring the newer port is correct behavior. The assumption is that handshake-provided ports are authoritative over ephemeral TCP source ports.
  • End-to-end test: Run 10-node test with ./letsgo testnet -reset and verify ALL 10 nodes reach Height: 1 (not just 3/10).
  • Check logs for: "Updated peer %s port from %d to %d" messages to confirm the fix is being triggered.

Notes

When a peer is added to the DHT with a different port than an existing entry
for the same address, update the port instead of adding a duplicate entry.
This fixes the issue where ephemeral TCP source ports were being stored
instead of the correct listening port (8000), causing broadcast messages
to fail for most peers.

The fix ensures that when a handshake provides the correct listen_port,
it updates any existing DHT entry for that address, replacing the
ephemeral port with the correct listening port.
@devin-ai-integration
Copy link

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@AlanRuno AlanRuno merged commit 7500825 into main Jan 15, 2026
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants