-
Notifications
You must be signed in to change notification settings - Fork 86
network: improve peer management #3911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AnnaShaleva
wants to merge
3
commits into
master
Choose a base branch
from
fix-disconnected
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3911 +/- ##
==========================================
- Coverage 82.58% 81.86% -0.73%
==========================================
Files 342 345 +3
Lines 48370 48857 +487
==========================================
+ Hits 39948 39995 +47
- Misses 6771 7191 +420
- Partials 1651 1671 +20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
c588f5f
to
b1fd639
Compare
Peer should not be marked as "connected" and "disconnected" at the same time. Fixes the first part of #3914. Reproduced and checked on custom privnet. Before: ``` anna@kiwi:~/Documents/GitProjects/nspcc-dev/neo-go$ curl -d '{ "jsonrpc": "2.0", "id": 1, "method": "getpeers", "params": ["0x398dbf659b3ea356845aafdc54227833550855e8956f5a9eae338c025dfa8a77"] }' http://localhost:30336 | json_pp % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 862 100 729 100 133 65363 11925 --:--:-- --:--:-- --:--:-- 78363 { "id" : 1, "jsonrpc" : "2.0", "result" : { "bad" : [ { "address" : "172.17.0.1", "port" : 50336 }, { "address" : "172.200.0.254", "port" : 47766 }, { "address" : "172.200.0.254", "port" : 50336 }, { "address" : "172.17.0.1", "port" : 50333 } ], "connected" : [ { "address" : "172.17.0.1", "port" : 50334, "useragent" : "/NEO-GO:0.109.2-pre-11-gc39f7f7f/" }, { "address" : "172.17.0.1", "lastknownheight" : 1, "port" : 50335, "useragent" : "/NEO-GO:0.109.2-pre-11-gc39f7f7f/" }, { "address" : "172.200.0.254", "port" : 50333, "useragent" : "/NEO-GO:0.109.2-pre-11-gc39f7f7f/" }, { "address" : "172.200.0.254", "port" : 50334, "useragent" : "/NEO-GO:0.109.2-pre-11-gc39f7f7f/" }, { "address" : "172.200.0.254", "port" : 50335, "useragent" : "/NEO-GO:0.109.2-pre-11-gc39f7f7f/" } ], "unconnected" : [ { "address" : "172.17.0.1", "port" : 50335 } ] } } ``` After: ``` anna@kiwi:~/Documents/GitProjects/nspcc-dev/neo-go$ curl -d '{ "jsonrpc": "2.0", "id": 1, "method": "getpeers", "params": ["0x398dbf659b3ea356845aafdc54227833550855e8956f5a9eae338c025dfa8a77"] }' http://localhost:30336 | json_pp % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 926 100 793 100 133 723k 121k --:--:-- --:--:-- --:--:-- 904k { "id" : 1, "jsonrpc" : "2.0", "result" : { "bad" : [ { "address" : "172.200.0.254", "port" : 45608 }, { "address" : "172.200.0.254", "port" : 50336 }, { "address" : "172.17.0.1", "port" : 50336 }, { "address" : "172.17.0.1", "port" : 50333 }, { "address" : "172.200.0.254", "port" : 50335 } ], "connected" : [ { "address" : "172.17.0.1", "port" : 50334, "useragent" : "/NEO-GO:0.109.2-pre-12-ge11a83d8/" }, { "address" : "172.200.0.254", "lastknownheight" : 1, "port" : 50335, "useragent" : "/NEO-GO:0.109.2-pre-12-ge11a83d8/" }, { "address" : "172.200.0.254", "lastknownheight" : 1, "port" : 50334, "useragent" : "/NEO-GO:0.109.2-pre-12-ge11a83d8/" }, { "address" : "172.200.0.254", "lastknownheight" : 1, "port" : 50333, "useragent" : "/NEO-GO:0.109.2-pre-12-ge11a83d8/" }, { "address" : "172.17.0.1", "lastknownheight" : 1, "port" : 50335, "useragent" : "/NEO-GO:0.109.2-pre-12-ge11a83d8/" } ], "unconnected" : [] } } ``` Signed-off-by: Anna Shaleva <[email protected]>
Fix the second part of #3914. Signed-off-by: Anna Shaleva <[email protected]>
On dockerized private network with non-default ext/int ports mapping there's no way to distinguish connections by underlying connecion address prior to handshake. Even after handshake, if the peer doesn't declare announced address/port the same way as it is declared in the node's local peer record, there's still no other way than server nonce to distinguish duplicating connections. For example, on privnet with configuration from #3915, node will maintain two connection to every seed: ``` // Start the node, wait for some connections to be established. ... // Try to connect to seed nodes, in particular, with the seed 172.17.0.1:20334: 2025-05-22T10:44:55.779Z INFO choosing peer from seeds {"addr": "172.17.0.1:20334", "requested": 1} ... 2025-05-22T10:44:55.779Z INFO dealing address {"addr": "172.17.0.1:20334"} ... // New peer is connected (incoming connection), it's the seed node // 172.17.0.1:20334 in fact, start protocol with this node: 2025-05-22T10:44:55.908Z INFO new peer connected {"peer addr": "172.200.0.254:42654", "fake conn addr": "172.200.0.254:42654", "conn addr": "172.200.0.254:42654", "peerCount": 1} 2025-05-22T10:44:55.909Z INFO started protocol {"addr": "172.200.0.254:42654", "userAgent": "/NEO-GO:0.109.2-pre-16-g953c3580/", "startHeight": 0, "id": 2422991527} ... // Outgoing seed connection succeeds, there's no way to distinguish this // connection from incoming one based on any available address: 2025-05-22T10:44:55.994Z INFO updating seed address {"seed": "172.17.0.1:20334", "old": "", "new": "172.17.0.1:20334"} 2025-05-22T10:44:55.994Z INFO register connected {"addr": "172.17.0.1:20334"} 2025-05-22T10:44:55.994Z INFO new peer connected {"peer addr": "172.17.0.1:20334", "fake conn addr": "172.17.0.1:20334", "conn addr": "172.17.0.1:20334", "peerCount": 2} ... // Start protocol with the same seed based on outgoing connection: 2025-05-22T10:44:55.996Z INFO started protocol {"addr": "172.17.0.1:20334", "userAgent": "/NEO-GO:0.109.2-pre-16-g953c3580/", "startHeight": 0, "id": 2422991527} ``` That's it, addresses can't tell us anything in this case. So we either live with duplicating connections or filter out connections by server ID. The latter is not the best option sice an invironment is untrusted and peer may intentionally fake its ID, but we don't have more reliable information. Close #3915. Signed-off-by: Anna Shaleva <[email protected]>
b1fd639
to
8ecc928
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Close #3914, close #3915.