koinos / koinos-p2p

The p2p microservice orchestrates the distribution of blocks and transactions between peers.
MIT License
6 stars 4 forks source link

Add a flag to turn DHT local peer discovery, default the flag to false #300

Closed sgerbino closed 3 months ago

sgerbino commented 3 months ago

Resolves #295.

Brief description

Disables DHT routing with a flag, defaults to false. Needs testing. Do not merge.

Checklist

Demonstration

sgerbino commented 3 months ago

@bgornicki, this PR requires testing. Can you verify if these changes resolve your issue? You should be able to specify a docker image called 295-disable-dht-routing in the Koinos node configuration after it has been built.

bgornicki commented 3 months ago

This kinda solves the issue but not in the way I was thinking about :D With this version, my node couldn't connect to any other peer but seed nodes. I expect it to connect with other valid peers available on public addresses.

My address:
 - /ip4/127.0.0.1/tcp/8888/p2p/QmVb7UWY431jVZej1rdXx7hYqY7yJDJa15Gav4Y4cLKMfY
Connected peers:
 - /ip4/50.116.19.109/tcp/8888/p2p/Qmd2bkf65yCKVZb2PG3FiRQWzrYgKf47zGBFuoU5qdebEY
 - /ip4/70.107.109.42/tcp/8888/p2p/QmYAC9nxqgVt2p8NvmxNFsoMpQS7c4zEBmsZndEBTRHNu4

I also figured out a way to verify if it's trying to connect to local addresses or not. You can use tcpdump.

  1. Exec to p2p container shell and install tcpdump with apk add tcpdump
  2. Determine the local IP address of the container with ifconfig
  3. Verify if the node is trying to connect to local IP addresses with tcpdump -i eth0 -n 'src <CONTAINER_IP> and (dst net 172.16.0.0/12 or dst net 10.0.0.0/8 or dst net 192.168.0.0/16 or dst net 100.64.0.0/10) and port 8888'

Current master will show a lot of attempts:

14:36:55.924883 IP 172.27.0.5.8888 > 172.18.0.6.4001: Flags [S], seq 791170238, win 64240, options [mss 1460,sackOK,TS val 4134179535 ecr 0,nop,wscale 7], length 0
14:36:56.056364 IP 172.27.0.5.8888 > 10.8.0.1.4001: Flags [S], seq 3590235538, win 64240, options [mss 1460,sackOK,TS val 23006023 ecr 0,nop,wscale 7], length 0
14:36:56.056503 IP 172.27.0.5.8888 > 10.0.0.250.4001: Flags [S], seq 1303243861, win 64240, options [mss 1460,sackOK,TS val 2743302448 ecr 0,nop,wscale 7], length 0
14:36:56.056582 IP 172.27.0.5.8888 > 172.18.0.1.4001: Flags [S], seq 2385284208, win 64240, options [mss 1460,sackOK,TS val 2943920614 ecr 0,nop,wscale 7], length 0
14:36:56.056641 IP 172.27.0.5.8888 > 172.17.0.1.4001: Flags [S], seq 1356016273, win 64240, options [mss 1460,sackOK,TS val 3450766262 ecr 0,nop,wscale 7], length 0
14:36:56.308794 IP 172.27.0.5.8888 > 100.76.241.107.4001: Flags [S], seq 1455763984, win 64240, options [mss 1460,sackOK,TS val 3732960585 ecr 0,nop,wscale 7], length 0
14:36:57.203619 IP 172.27.0.5.8888 > 100.76.241.107.4001: Flags [S], seq 1485424897, win 64240, options [mss 1460,sackOK,TS val 3732961479 ecr 0,nop,wscale 7], length 0
14:36:57.204362 IP 172.27.0.5.8888 > 192.168.100.32.4001: Flags [S], seq 122675091, win 64240, options [mss 1460,sackOK,TS val 642996303 ecr 0,nop,wscale 7], length 0
14:36:58.228813 IP 172.27.0.5.8888 > 192.168.100.32.4001: Flags [S], seq 122675091, win 64240, options [mss 1460,sackOK,TS val 642997328 ecr 0,nop,wscale 7], length 0
14:36:58.228830 IP 172.27.0.5.8888 > 100.76.241.107.4001: Flags [S], seq 1485424897, win 64240, options [mss 1460,sackOK,TS val 3732962505 ecr 0,nop,wscale 7], length 0
14:37:00.244803 IP 172.27.0.5.8888 > 100.76.241.107.4001: Flags [S], seq 1485424897, win 64240, options [mss 1460,sackOK,TS val 3732964521 ecr 0,nop,wscale 7], length 0
14:37:00.244817 IP 172.27.0.5.8888 > 192.168.100.32.4001: Flags [S], seq 122675091, win 64240, options [mss 1460,sackOK,TS val 642999344 ecr 0,nop,wscale 7], length 0
14:37:01.535086 IP 172.27.0.5.8888 > 192.168.2.9.4001: Flags [S], seq 3953508295, win 64240, options [mss 1460,sackOK,TS val 4228667709 ecr 0,nop,wscale 7], length 0
14:37:02.548805 IP 172.27.0.5.8888 > 192.168.2.9.4001: Flags [S], seq 3953508295, win 64240, options [mss 1460,sackOK,TS val 4228668723 ecr 0,nop,wscale 7], length 0
14:37:04.564807 IP 172.27.0.5.8888 > 192.168.2.9.4001: Flags [S], seq 3953508295, win 64240, options [mss 1460,sackOK,TS val 4228670739 ecr 0,nop,wscale 7], length 0
14:37:10.962802 IP 172.27.0.5.8888 > 172.31.7.245.4001: Flags [S], seq 604414821, win 64240, options [mss 1460,sackOK,TS val 2928080605 ecr 0,nop,wscale 7], length 0
14:37:11.541363 IP 172.27.0.5.8888 > 10.0.0.175.44005: Flags [S], seq 2383163687, win 64240, options [mss 1460,sackOK,TS val 9462805 ecr 0,nop,wscale 7], length 0
14:37:11.545181 IP 172.27.0.5.8888 > 10.97.21.155.4001: Flags [S], seq 631842767, win 64240, options [mss 1460,sackOK,TS val 3189719570 ecr 0,nop,wscale 7], length 0
14:37:12.564794 IP 172.27.0.5.8888 > 10.97.21.155.4001: Flags [S], seq 631842767, win 64240, options [mss 1460,sackOK,TS val 3189720590 ecr 0,nop,wscale 7], length 0
14:37:12.564808 IP 172.27.0.5.8888 > 10.0.0.175.44005: Flags [S], seq 2383163687, win 64240, options [mss 1460,sackOK,TS val 9463829 ecr 0,nop,wscale 7], length 0
14:37:14.580907 IP 172.27.0.5.8888 > 10.0.0.175.44005: Flags [S], seq 2383163687, win 64240, options [mss 1460,sackOK,TS val 9465845 ecr 0,nop,wscale 7], length 0
14:37:14.580961 IP 172.27.0.5.8888 > 10.97.21.155.4001: Flags [S], seq 631842767, win 64240, options [mss 1460,sackOK,TS val 3189722606 ecr 0,nop,wscale 7], length 0
14:37:36.485203 IP 172.27.0.5.8888 > 172.17.0.2.4001: Flags [S], seq 938673582, win 64240, options [mss 1460,sackOK,TS val 2581688141 ecr 0,nop,wscale 7], length 0
14:37:36.535149 IP 172.27.0.5.8888 > 172.17.0.2.4001: Flags [S], seq 939453972, win 64240, options [mss 1460,sackOK,TS val 2581688191 ecr 0,nop,wscale 7], length 0

This version is silent but it does not connect to others.

sgerbino commented 3 months ago

Pasting my outputs on the latest commits:

p2p-1          | 2024-07-30 15:45:31.907835 (p2p.Koinos) [p2p/peer_connection.go:158] <info>: Requesting blocks 104206-104706 from peer Qmd2bkf65yCKVZb2PG3FiRQWzrYgKf47zGBFuoU5qdebEY
p2p-1          | 2024-07-30 15:45:33.299905 (p2p.Koinos) [p2p/peer_connection.go:158] <info>: Requesting blocks 104348-104848 from peer QmSt8SKKtsNWcBbx2WEZdiHKb4XGPZyVGK2bmgneFZyRcL
p2p-1          | 2024-07-30 15:45:33.910059 (p2p.Koinos) [p2p/peer_connection.go:158] <info>: Requesting blocks 104373-104873 from peer QmYAC9nxqgVt2p8NvmxNFsoMpQS7c4zEBmsZndEBTRHNu4
p2p-1          | 2024-07-30 15:45:34.146044 (p2p.Koinos) [p2p/peer_connection.go:158] <info>: Requesting blocks 104422-104922 from peer Qme2HRSiGYfEA5fF7D5fjpAMsnd8dBs7rgFzN2CSHfhb9K
p2p-1          | 2024-07-30 15:45:34.193448 (p2p.Koinos) [p2p/peer_connection.go:158] <info>: Requesting blocks 104424-104924 from peer QmdsbSpN4Jc2iTLEUtY8LUHLSS2eZ2yshVU9axVS8dTwmm
p2p-1          | 2024-07-30 15:45:34.392976 (p2p.Koinos) [p2p/peer_connection.go:158] <info>: Requesting blocks 104440-104940 from peer QmeAHnanCapq1yY8cNkBA8gnv8k5YysaUCLGF7zeB59eTn
p2p-1          | 2024-07-30 15:45:34.881827 (p2p.Koinos) [node/node.go:387] <info>: My address:
p2p-1          | 2024-07-30 15:45:34.881953 (p2p.Koinos) [node/node.go:388] <info>:  - /ip4/127.0.0.1/tcp/8888/p2p/QmWMJAfjxow47bdNdB1u3KjmcbpHW27SmTVbQeGNwSinUA
p2p-1          | 2024-07-30 15:45:34.881969 (p2p.Koinos) [node/node.go:389] <info>: Connected peers:
p2p-1          | 2024-07-30 15:45:34.881992 (p2p.Koinos) [node/node.go:391] <info>:  - /ip4/144.76.219.133/tcp/8888/p2p/QmUNURuZxSu5wLnmBNJdwGtwjLmV5JxGhu4uNSAS8ZNcze
p2p-1          | 2024-07-30 15:45:34.882008 (p2p.Koinos) [node/node.go:391] <info>:  - /ip4/89.117.57.67/tcp/8888/p2p/Qme2HRSiGYfEA5fF7D5fjpAMsnd8dBs7rgFzN2CSHfhb9K
p2p-1          | 2024-07-30 15:45:34.882024 (p2p.Koinos) [node/node.go:391] <info>:  - /ip4/68.183.68.41/tcp/8888/p2p/QmdsbSpN4Jc2iTLEUtY8LUHLSS2eZ2yshVU9axVS8dTwmm
p2p-1          | 2024-07-30 15:45:34.882041 (p2p.Koinos) [node/node.go:391] <info>:  - /ip4/192.241.151.61/tcp/8888/p2p/Qmd9YTHDGHXZWvZGiGL7vLm4FKc4B6Qs5yHtv33LW8L7yu
p2p-1          | 2024-07-30 15:45:34.882081 (p2p.Koinos) [node/node.go:391] <info>:  - /ip4/70.107.109.42/tcp/8888/p2p/QmYAC9nxqgVt2p8NvmxNFsoMpQS7c4zEBmsZndEBTRHNu4
p2p-1          | 2024-07-30 15:45:34.882096 (p2p.Koinos) [node/node.go:391] <info>:  - /ip4/95.216.2.248/tcp/8888/p2p/QmSt8SKKtsNWcBbx2WEZdiHKb4XGPZyVGK2bmgneFZyRcL
p2p-1          | 2024-07-30 15:45:34.882103 (p2p.Koinos) [node/node.go:391] <info>:  - /ip4/92.233.41.39/tcp/8888/p2p/QmeAHnanCapq1yY8cNkBA8gnv8k5YysaUCLGF7zeB59eTn
p2p-1          | 2024-07-30 15:45:34.882110 (p2p.Koinos) [node/node.go:391] <info>:  - /ip4/50.116.19.109/tcp/8888/p2p/Qmd2bkf65yCKVZb2PG3FiRQWzrYgKf47zGBFuoU5qdebEY
p2p-1          | 2024-07-30 15:45:34.882117 (p2p.Koinos) [node/node.go:391] <info>:  - /ip4/72.14.176.133/tcp/8888/p2p/Qme9LYvFyMu1FESNcm7vjPqqcbF6u7ZG8hhVkk5sUE9kWf
p2p-1          | 2024-07-30 15:45:35.174508 (p2p.Koinos) [p2p/peer_connection.go:158] <info>: Requesting blocks 104469-104969 from peer Qmd9YTHDGHXZWvZGiGL7vLm4FKc4B6Qs5yHtv33LW8L7yu
p2p-1          | 2024-07-30 15:45:35.553839 (p2p.Koinos) [p2p/peer_connection.go:158] <info>: Requesting blocks 104483-104983 from peer Qme9LYvFyMu1FESNcm7vjPqqcbF6u7ZG8hhVkk5sUE9kWf
p2p-1          | 2024-07-30 15:45:35.906559 (p2p.Koinos) [p2p/peer_connection.go:158] <info>: Requesting blocks 104540-105040 from peer QmUNURuZxSu5wLnmBNJdwGtwjLmV5JxGhu4uNSAS8ZNcze
p2p-1          | 2024-07-30 15:45:37.766296 (p2p.Koinos) [p2p/peer_connection.go:158] <info>: Requesting blocks 104646-105146 from peer Qmd2bkf65yCKVZb2PG3FiRQWzrYgKf47zGBFuoU5qdebEY
p2p-1          | 2024-07-30 15:45:39.165334 (p2p.Koinos) [p2p/peer_connection.go:158] <info>: Requesting blocks 104788-105288 from peer QmSt8SKKtsNWcBbx2WEZdiHKb4XGPZyVGK2bmgneFZyRcL
p2p-1          | 2024-07-30 15:45:39.630716 (p2p.Koinos) [p2p/peer_connection.go:158] <info>: Requesting blocks 104813-105313 from peer QmYAC9nxqgVt2p8NvmxNFsoMpQS7c4zEBmsZndEBTRHNu4
p2p-1          | 2024-07-30 15:45:40.030586 (p2p.Koinos) [p2p/peer_connection.go:158] <info>: Requesting blocks 104862-105362 from peer Qme2HRSiGYfEA5fF7D5fjpAMsnd8dBs7rgFzN2CSHfhb9K
p2p-1          | 2024-07-30 15:45:40.095150 (p2p.Koinos) [p2p/peer_connection.go:158] <info>: Requesting blocks 104864-105364 from peer QmdsbSpN4Jc2iTLEUtY8LUHLSS2eZ2yshVU9axVS8dTwmm
p2p-1          | 2024-07-30 15:45:40.366568 (p2p.Koinos) [p2p/peer_connection.go:158] <info>: Requesting blocks 104880-105380 from peer QmeAHnanCapq1yY8cNkBA8gnv8k5YysaUCLGF7zeB59eTn
/ # tcpdump -i eth0 -n 'src 172.18.0.6 and (dst net 172.16.0.0/12 or dst net 10.0.0.0/8 or dst net 192.168.0.0/16 or dst net 100.64.0.0/10) and port 8888'
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes