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

net: only enforce expected services for half of outgoing connections #10441

Merged
merged 1 commit into from Jun 1, 2017

Conversation

theuni
Copy link
Member

@theuni theuni commented May 22, 2017

This ensures that future flags can be turned off after being enabled without causing all outbound nodes to refuse to connect to it in the future for lack of expected services.

Should probably be backported to 0.14 as well.

@laanwj
Copy link
Member

laanwj commented May 23, 2017

utACK 0f1e7d3

Copy link
Contributor

@jonasschnelli jonasschnelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 0f1e7d3623f37d8ba12ea63543794c90682567bd

@theuni
Copy link
Member Author

theuni commented May 25, 2017

Updated to fix an issue pointed out by @gmaxwell

@sdaftuar
Copy link
Member

utACK 7e1718d

1 similar comment
@morcos
Copy link
Member

morcos commented May 25, 2017

utACK 7e1718d

@jonasschnelli
Copy link
Contributor

(re)utACK 7e1718d389d6cb1223124cefa594f136f56ec4d1

@gmaxwell
Copy link
Contributor

Perhaps consider bracing the conditionals? (at least the new ones?)

@theuni
Copy link
Member Author

theuni commented May 26, 2017

@gmaxwell done. diff from before is cosmetic only:

diff --git a/src/net.cpp b/src/net.cpp
index 1e50cfb..22d26a9 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -1796,11 +1796,13 @@ void CConnman::ThreadOpenConnections()
 
             // only consider nodes missing relevant services after 40 failed attempts and only if less than half the outbound are up.
             ServiceFlags nRequiredServices = nRelevantServices;
-            if (nTries >= 40 && nOutbound < (nMaxOutbound >> 1))
+            if (nTries >= 40 && nOutbound < (nMaxOutbound >> 1)) {
                 nRequiredServices = REQUIRED_SERVICES;
+            }
 
-            if ((addr.nServices & nRequiredServices) != nRequiredServices)
+            if ((addr.nServices & nRequiredServices) != nRequiredServices) {
                 continue;
+            }
 
             // do not allow non-default ports, unless after 50 invalid addresses selected already
             if (addr.GetPort() != Params().GetDefaultPort() && nTries < 50)

// regardless of the services assumed to be available, only require the minimum if half or more outbound have relevant services
if (nOutboundRelevant >= (nMaxOutbound >> 1)) {
addrConnect.nServices = REQUIRED_SERVICES;
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this else branch is unnecessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It possibly downgrades the requirement from line 1799.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed!

@sipa
Copy link
Member

sipa commented May 28, 2017

net.cpp: In member function ‘void CConnman::ThreadOpenConnections()’:
net.cpp:1732:115: warning: self-comparison always evaluates to true [-Wtautological-compare]
                     if (pnode->fSuccessfullyConnected && !pnode->fFeeler && (pnode->nServices & nRelevantServices == nRelevantServices)) {
                                                                                                 ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
net.cpp:1732:115: warning: suggest parentheses around comparison in operand of ‘&’ [-Wparentheses]

@theuni
Copy link
Member Author

theuni commented May 28, 2017

Yikes, thanks. Pushed the fixup.

also once half of all outgoing nodes have our preferred flags, require only
minimal flags from the rest.
@laanwj laanwj merged commit b6fbfc2 into bitcoin:master Jun 1, 2017
laanwj added a commit that referenced this pull request Jun 1, 2017
…g connections

b6fbfc2 net: only enforce the services required to connect (Cory Fields)

Tree-SHA512: 88943bff63213a734f3c96c45760cadaeb9ba18287c8a20c279851ebaf058a334c969028fb2180f155508e3eea4b838147382e4f2b655e7a9aa098eadc81d53e
laanwj pushed a commit that referenced this pull request Jun 1, 2017
also once half of all outgoing nodes have our preferred flags, require only
minimal flags from the rest.

Github-Pull: #10441
Rebased-From: b6fbfc2
@TheBlueMatt
Copy link
Contributor

utACK b6fbfc2

nomnombtc pushed a commit to nomnombtc/bitcoin that referenced this pull request Jul 17, 2017
also once half of all outgoing nodes have our preferred flags, require only
minimal flags from the rest.

Github-Pull: bitcoin#10441
Rebased-From: b6fbfc2
codablock pushed a commit to codablock/dash that referenced this pull request Jan 26, 2018
…outgoing connections

b6fbfc2 net: only enforce the services required to connect (Cory Fields)

Tree-SHA512: 88943bff63213a734f3c96c45760cadaeb9ba18287c8a20c279851ebaf058a334c969028fb2180f155508e3eea4b838147382e4f2b655e7a9aa098eadc81d53e
andvgal pushed a commit to energicryptocurrency/gen2-energi that referenced this pull request Jan 6, 2019
…outgoing connections

b6fbfc2 net: only enforce the services required to connect (Cory Fields)

Tree-SHA512: 88943bff63213a734f3c96c45760cadaeb9ba18287c8a20c279851ebaf058a334c969028fb2180f155508e3eea4b838147382e4f2b655e7a9aa098eadc81d53e
andvgal pushed a commit to energicryptocurrency/gen2-energi that referenced this pull request Jan 6, 2019
…outgoing connections

b6fbfc2 net: only enforce the services required to connect (Cory Fields)

Tree-SHA512: 88943bff63213a734f3c96c45760cadaeb9ba18287c8a20c279851ebaf058a334c969028fb2180f155508e3eea4b838147382e4f2b655e7a9aa098eadc81d53e
CryptoCentric pushed a commit to absolute-community/absolute that referenced this pull request Feb 27, 2019
…outgoing connections

b6fbfc2 net: only enforce the services required to connect (Cory Fields)

Tree-SHA512: 88943bff63213a734f3c96c45760cadaeb9ba18287c8a20c279851ebaf058a334c969028fb2180f155508e3eea4b838147382e4f2b655e7a9aa098eadc81d53e
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants