Skip to content
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

Merged
merged 17 commits into from
Apr 7, 2022
Merged

Network tests & updates #692

merged 17 commits into from
Apr 7, 2022

Conversation

nodech
Copy link
Contributor

@nodech nodech commented Feb 24, 2022

This PR adds tests and also includes several older PRs.

nodech and others added 12 commits December 25, 2021 16:18
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>
@coveralls
Copy link

coveralls commented Feb 24, 2022

Coverage Status

Coverage increased (+1.8%) to 64.558% when pulling c96b6ec on nodech:net-updates into 107ed2b on handshake-org:master.

@nodech nodech added net/p2p part of the codebase patch Release version tests part of the codebase labels Feb 27, 2022
test/net-netaddress-test.js Show resolved Hide resolved
test/net-netaddress-test.js Outdated Show resolved Hide resolved
test/net-lookup.js Outdated Show resolved Hide resolved
test/net-lookup.js Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
test/net-hostlist-test.js Outdated Show resolved Hide resolved
test/net-hostlist-test.js Outdated Show resolved Hide resolved
lib/net/netaddress.js Show resolved Hide resolved
lib/net/netaddress.js Show resolved Hide resolved
lib/net/pool.js Outdated
Comment on lines 3395 to 3397
// Don't connect to outbound peers in the same group.
if (this.connectedGroups.has(addr.getGroup()))
continue;
Copy link
Member

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

Copy link
Contributor Author

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 ?

Copy link
Member

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.

@pinheadmz
Copy link
Member

We should also make sure we don't connect to the same peer twice. This usually happens on clearnet + brontide

#501
#487

@pinheadmz
Copy link
Member

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.

@nodech nodech force-pushed the net-updates branch 2 times, most recently from 5cc8615 to 09f9133 Compare March 30, 2022 07:26
@nodech nodech added this to the 4.0.0 milestone Mar 31, 2022
@nodech nodech merged commit 6213460 into handshake-org:master Apr 7, 2022
pinheadmz added a commit to pinheadmz/hsd that referenced this pull request Aug 12, 2022
@nodech nodech deleted the net-updates branch January 6, 2023 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
net/p2p part of the codebase patch Release version tests part of the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants