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

Added -whiteconnections=<n> option #5288

Merged
merged 1 commit into from Jul 10, 2015
Merged

Conversation

@Krellan
Copy link
Contributor

Krellan commented Nov 16, 2014

This allows whitelisted peers a higher connection limit,
so they can exceed the normal -maxconnections limit,
useful for ensuring your local users and miners can always get in.

@Krellan Krellan force-pushed the Krellan:whiteconnections branch 3 times, most recently Nov 16, 2014
@Krellan
Copy link
Contributor Author

Krellan commented Nov 18, 2014

Refactored, after conversation with gmaxwell on #bitcoin-dev.

Default of whiteconnections is now 4 (if user isn't using whitelist feature at all, default is 0).

Now acts to essentially reserve slots for exclusive use by whitelisted peers, against the given maxconnections limit, instead of increasing the maxconnections limit.

Warning message given if whiteconnections value is so high that it will reserve all inbound slots, preventing any non-whitelisted peer from ever being able to connect.

If user has not given a maxconnections value, then as a special case it adds the value of whiteconnections to the default for maxconnections. This is to avoid establishing a new default which would inadvertently reduce the number of incoming slots available for public (non-whitelisted) use. With the popularity of SPV wallets these days, incoming slots on full nodes are a rather precious resource.

This whiteconnections feature is rather nice, especially for long-lived full nodes which reach their capacity of inbound connections. Now, you don't have to restart your node whenever you restart your miner, just to free up a slot so that your miner can get in!

@sipa
sipa reviewed Nov 18, 2014
View changes
src/net.h Outdated
@@ -122,6 +122,7 @@ extern uint64_t nLocalServices;
extern uint64_t nLocalHostNonce;
extern CAddrMan addrman;
extern int nMaxConnections;
extern int nWhiteConnections;

This comment has been minimized.

Copy link
@sipa

sipa Nov 18, 2014

Member

Can you add a comment here saying that this number is the reserved number of connections for white connections?

@sipa
Copy link
Member

sipa commented Nov 18, 2014

Tested that whitelisted connections are restricted to the whitelisted reserved count, and that the implicit + 4 without specified -maxconnections works as intended.

@Krellan Krellan force-pushed the Krellan:whiteconnections branch Nov 19, 2014
@Krellan
Copy link
Contributor Author

Krellan commented Nov 19, 2014

Thanks, sipa, I added a comment showing some of the theory of operation behind nMaxConnections and nWhiteConnections.

@Krellan Krellan force-pushed the Krellan:whiteconnections branch to 48610c2 Nov 24, 2014
@Krellan
Copy link
Contributor Author

Krellan commented Dec 28, 2014

Rebased against the latest, no changes were necessary :)

@Krellan Krellan force-pushed the Krellan:whiteconnections branch from 48610c2 to 910d9a8 Dec 28, 2014
@laanwj laanwj added Feature P2P labels Jan 8, 2015
@@ -123,7 +123,17 @@ extern bool fListen;
extern uint64_t nLocalServices;
extern uint64_t nLocalHostNonce;
extern CAddrMan addrman;

This comment has been minimized.

Copy link
@fanquake

fanquake Feb 2, 2015

Member

Could you update this to use our doxygen comment format.

This comment has been minimized.

Copy link
@laanwj

laanwj Jun 12, 2015

Member

It's not easy to integrate a 'floating' comment like this into doxygen.
One way would be to group nMaxConnections and nWhiteConnections using @{ @} and add it as doxygen comment of the group.

@Krellan
Copy link
Contributor Author

Krellan commented Feb 9, 2015

Thanks, will update it.

@ghost
Copy link

ghost commented Mar 11, 2015

utAck. Is the pending update keeping the merge up?

@Krellan
Copy link
Contributor Author

Krellan commented Mar 11, 2015

Yikes! Forgot about this. Will update ASAP.

@Krellan Krellan force-pushed the Krellan:whiteconnections branch from 910d9a8 to 334299f Mar 12, 2015
@Krellan
Copy link
Contributor Author

Krellan commented Mar 12, 2015

There, got it merged with latest master, and made the requested documentation cleanup changes!

The Travis build still fails for the "no wallet" case, but the same thing happens right now for the latest upstream master....

@Krellan Krellan force-pushed the Krellan:whiteconnections branch from 334299f to 55b94ad Mar 12, 2015
@Krellan
Copy link
Contributor Author

Krellan commented Mar 12, 2015

No code change, just rebased with latest master to pick up the Travis build fix.

@ghost
Copy link

ghost commented Mar 12, 2015

Thanks!

// User not using whitelist feature.
// Silently disable connection reservation,
// for the same reason as above.
nWhiteConnections = 0;

This comment has been minimized.

Copy link
@laanwj

laanwj Mar 18, 2015

Member

What if the user is using whitebind instead?

@Krellan
Copy link
Contributor Author

Krellan commented Mar 18, 2015

Good to point out! I will change it so that the "User is using whitelist feature" test matches on either -whitelist or -whitebind options.

@Krellan Krellan force-pushed the Krellan:whiteconnections branch 2 times, most recently from e317c43 to d7fcdd0 Mar 18, 2015
@Krellan
Copy link
Contributor Author

Krellan commented Mar 18, 2015

There, updated it as described (both whitelist and whitebind will work to trigger the nMaxConnections fixup). Also rebased against latest master.

nWhiteConnections = std::max(nUserWhiteConnections, 0);

if ((mapArgs.count("-whitelist")) || (mapArgs.count("-whitebind"))) {
if (!(mapArgs.count("-maxconnections"))) {

This comment has been minimized.

Copy link
@laanwj

laanwj Mar 19, 2015

Member

This inner if() seems a bit overcomplicated. I think this addition should either be always done (when whitelisting is used), or never at all. To me it doesn't hold up to the principle of least surprise to do this only to the default -maxconnections but not when the user provides one. Too much parameter interaction...

@Krellan
Copy link
Contributor Author

Krellan commented Mar 20, 2015

I thought about that as well, during initial implementation thoughts over IRC. Talked about it with a few others. Tried to avoid surprise and unintended behavior as best as possible, and this was a compromise.

If the increase was done always, then it would be surprising to the user, because it would look like we were blatantly disobeying their given maxconnections limit.

If user doesn't provide maxconnections at all, then the thinking was that they wouldn't care as much, therefore we could get away with doing the increase. We definitely do want to do the increase, as mentioned in the comments, to avoid reducing connection capacity of the Bitcoin network.

So, there's thinking that went into both sides of this decision.

@ghost
Copy link

ghost commented Mar 24, 2015

Changing from utAck to tAck.

@ghost
Copy link

ghost commented Apr 21, 2015

I am not sure what's been keeping the PR open?

@Krellan
Copy link
Contributor Author

Krellan commented Apr 22, 2015

I'm not sure either. I'm hoping there is no issue preventing this from being merged.

@Krellan Krellan force-pushed the Krellan:whiteconnections branch from d7fcdd0 to 316ceed Apr 25, 2015
@Krellan
Copy link
Contributor Author

Krellan commented Apr 25, 2015

Trivial change to keep up with latest upstream.

@sipa
Copy link
Member

sipa commented Apr 26, 2015

@Krellan There are several unaddressed comments?

@Krellan
Copy link
Contributor Author

Krellan commented Apr 26, 2015

@sipa Which comments? Thought I addressed all concerns.

@sipa
Copy link
Member

sipa commented Apr 26, 2015

Sorry, I missed that you answered in the PR rather than on the commits.

@sipa
Copy link
Member

sipa commented Apr 27, 2015

The "increase the maxconnections if not specified, don't if it is" is fine, I think, but I wonder if the -whiteconnections default = 4 is needed. An existing user of one of the white* features won't expect a change in behaviour.

I wonder if this isn't a concise way to specify it:

  • -whiteconnections defaults to 0, no matter what
  • -maxconnections defaults to 125 + [-whiteconnections](or whatever the FD limit permits)

Seems easier to explain, and wouldn't violate the least surprise principle either?

@Krellan
Copy link
Contributor Author

Krellan commented May 8, 2015

Good point. I will make it default to 0 instead of 4, so that the default behavior is to change nothing at all.

@Krellan Krellan force-pushed the Krellan:whiteconnections branch from 316ceed to 40dc4a7 May 26, 2015
@Krellan
Copy link
Contributor Author

Krellan commented May 26, 2015

There, as requested, changed the default from 4 to 0. Made no other code changes, just these constants. Also rebased to latest upstream.

So, the behavior is now unchanged, by default. If the user wants the benefit of reserved slots for their whitelisted incoming connections, they will have to explicitly specify how many slots they want to reserve.

if (nFD < MIN_CORE_FILEDESCRIPTORS)
return InitError(_("Not enough file descriptors available."));
if (nFD - MIN_CORE_FILEDESCRIPTORS < nMaxConnections)
nMaxConnections = nFD - MIN_CORE_FILEDESCRIPTORS;

This comment has been minimized.

Copy link
@laanwj

laanwj Jun 12, 2015

Member

Slightly preferred for readability:

nMaxConnections = std::min(nFD - MIN_CORE_FILEDESCRIPTORS, nMaxConnections);
@laanwj
Copy link
Member

laanwj commented Jun 12, 2015

utACK apart from nit (but needs rebase)

@Krellan Krellan force-pushed the Krellan:whiteconnections branch from 40dc4a7 Jun 14, 2015
@Krellan
Copy link
Contributor Author

Krellan commented Jun 14, 2015

Rebased.

This sets aside a number of connection slots for whitelisted peers,
useful for ensuring your local users and miners can always get in,
even if your limit on inbound connections has already been reached.
@Krellan Krellan force-pushed the Krellan:whiteconnections branch to e3cae52 Jun 14, 2015
@Krellan
Copy link
Contributor Author

Krellan commented Jun 14, 2015

Addressed the nit, good catch.

Also found another place where the default was still 4, changed to 0.

@sipa
Copy link
Member

sipa commented Jun 14, 2015

Untested ACK

@laanwj laanwj merged commit e3cae52 into bitcoin:master Jul 10, 2015
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
laanwj added a commit that referenced this pull request Jul 10, 2015
e3cae52 Added -whiteconnections=<n> option (Josh Lehan)
str4d added a commit to str4d/zcash that referenced this pull request Jul 13, 2017
Zcash: Was "Added -whiteconnections=<n> option" from bitcoin/bitcoin#5288. The
option was later removed in bitcoin/bitcoin#6374 which we merged in zcash#1258. This
commit contains the difference between the two.
str4d added a commit to str4d/zcash that referenced this pull request Nov 9, 2017
Zcash: Was "Added -whiteconnections=<n> option" from bitcoin/bitcoin#5288. The
option was later removed in bitcoin/bitcoin#6374 which we merged in zcash#1258. This
commit contains the difference between the two.
str4d added a commit to str4d/zcash that referenced this pull request Apr 5, 2018
Zcash: Was "Added -whiteconnections=<n> option" from bitcoin/bitcoin#5288. The
option was later removed in bitcoin/bitcoin#6374 which we merged in zcash#1258. This
commit contains the difference between the two.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.