-
Notifications
You must be signed in to change notification settings - Fork 279
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
Network tests & updates #692
Conversation
Currently, pool::getHost() uses a fixed loop of 0-99 regardless of how many hosts it has in it's lists so it can use a percentage to factor in whether it should use an entry or not. Using network regtest and a single host of 127.0.0.1:14038, hsd burns a lot of CPU when refilling peers and this blocks incoming requests so much it times out. This is less noticeable the more hosts you have. Instead, use shorter loop of 10. This brings CPU utlisation on my NetBSD Xen DOMU on regtest with one host from 100% to 6% and connecting 4 to peers on testnet from 85% to 8%, allowing RPC commands to now work. Fixes handshake-org#220.
This commit removes the discover external check in the pool. Currently we already store all local addresses that are sent to us from peers in the hostlist, so there is no reason to rely on an external service to check for our local/external address. This was removed from bitcoin in commit 845c86d.
This commit adds the getGroup function to net addresses. It allows for network addresses to be grouped into buckets, such that we can limit the number of outgoing connections per group to a certain amount. This will allow for increased connection diversity and reduced attack surface area. Co-authored-by: Nodari Chkuaselidze <nodar.chkuaselidze@gmail.com>
This commit checks the outbound peers to see which group their network addresses lives in before connecting. By doing this, we prevent a node from connecting to all outbound addresses in a very close network group bunch. This helps prevent someone spinning up multiple nodes on a similar network e.g. AWS, GCP and using those to fill other nodes' outbounds. This commit just adds 2 operations in both addOutbound and addLoader. It first checks if the new address pull from hostlist belongs in the same group as an already connected peer. If it does not, it precedes as usual, and if the connection succeeds then it adds that new outbound group to the list of groups currently connected to. Co-authored-by: Nodari Chkuaselidze <nodar.chkuaselidze@gmail.com>
lib/net/pool.js
Outdated
// Don't connect to outbound peers in the same group. | ||
if (this.connectedGroups.has(addr.getGroup())) | ||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we allow this with some low probability? or is it always bad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm.. Maybe last 2 tries ? pc80 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like Bitcoin Core really doesnt allow this at all:
https://github.com/bitcoin/bitcoin/blob/master/src/net.cpp#L2114-L2117
So I defer to you, just not sure given the limited size of the handshake network if this is actually beneficial.
Another thing to consider: bump the version of the hosts.json file? Maybe even add a migration in this PR since we are grouping addrs in buckets in a different way now. |
5cc8615
to
09f9133
Compare
This PR adds tests and also includes several older PRs.
binet
with bug fixes.