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 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 whiteconnections branch 3 times, most recently from 5b7faeb to 46a7467 Compare Nov 18, 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!

@@ -122,6 +122,7 @@ extern uint64_t nLocalServices;
extern uint64_t nLocalHostNonce;
extern CAddrMan addrman;
extern int nMaxConnections;
extern int nWhiteConnections;
Copy link
Member

@sipa sipa Nov 18, 2014

Choose a reason for hiding this comment

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

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
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
Copy link
Contributor Author

Krellan commented Dec 28, 2014

Rebased against the latest, no changes were necessary :)

@@ -123,7 +123,17 @@ extern bool fListen;
extern uint64_t nLocalServices;
extern uint64_t nLocalHostNonce;
extern CAddrMan addrman;

Copy link
Member

@fanquake fanquake Feb 2, 2015

Choose a reason for hiding this comment

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

Could you update this to use our doxygen comment format.

Copy link
Member

@laanwj laanwj Jun 12, 2015

Choose a reason for hiding this comment

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

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
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
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;
Copy link
Member

@laanwj laanwj Mar 18, 2015

Choose a reason for hiding this comment

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

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 whiteconnections branch 2 times, most recently from e317c43 to d7fcdd0 Compare 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"))) {
Copy link
Member

@laanwj laanwj Mar 19, 2015

Choose a reason for hiding this comment

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

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.

@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
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;
Copy link
Member

@laanwj laanwj Jun 12, 2015

Choose a reason for hiding this comment

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

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
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
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
laanwj added a commit that referenced this issue Jul 10, 2015
e3cae52 Added -whiteconnections=<n> option (Josh Lehan)
str4d pushed a commit to str4d/zcash that referenced this issue 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 pushed a commit to str4d/zcash that referenced this issue 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 pushed a commit to str4d/zcash that referenced this issue 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.
str4d pushed a commit to str4d/zcash that referenced this issue Feb 18, 2021
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 pushed a commit to str4d/zcash that referenced this issue Feb 18, 2021
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.
zkbot added a commit to zcash/zcash that referenced this issue Feb 18, 2021
Bitcoin 0.12 misc P2P/Net PRs

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#5288
  - Only the reorg, option was removed in bitcoin/bitcoin#6374 which we merged in #1258
- bitcoin/bitcoin#6561
- bitcoin/bitcoin#6728
- bitcoin/bitcoin#6829
- bitcoin/bitcoin#6974
- bitcoin/bitcoin#7075
- bitcoin/bitcoin#7166

Part of #2074.
zkbot added a commit to zcash/zcash that referenced this issue Feb 19, 2021
Bitcoin 0.12 misc P2P/Net PRs

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#5288
  - Only the reorg, option was removed in bitcoin/bitcoin#6374 which we merged in #1258
- bitcoin/bitcoin#6561
- bitcoin/bitcoin#6728
- bitcoin/bitcoin#6829
- bitcoin/bitcoin#6974
- bitcoin/bitcoin#7075
- bitcoin/bitcoin#7166

Part of #2074.
zkbot added a commit to zcash/zcash that referenced this issue Feb 19, 2021
Bitcoin 0.12 misc P2P/Net PRs

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#5288
  - Only the reorg, option was removed in bitcoin/bitcoin#6374 which we merged in #1258
- bitcoin/bitcoin#6561
- bitcoin/bitcoin#6728
- bitcoin/bitcoin#6829
- bitcoin/bitcoin#6974
- bitcoin/bitcoin#7075
- bitcoin/bitcoin#7166

Part of #2074.
@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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants