Skip to content

Conversation

@jonatack
Copy link
Member

@jonatack jonatack commented Apr 16, 2021

Since #9319 proposed by Gregory Maxwell and released in v0.14, peers manually added through the -addnode config option or using the addnode RPC have their own separate limit of 8 connections that does not compete with other inbound or outbound connection usage and is not subject to the limitation imposed by the -maxconnections option.

This PR updates the -addnode and -maxconnections config options and the addnode RPC help docs with this information.

-addnode config option help

$ bitcoind -h | grep -A5 addnode=
  -addnode=<ip>
       Add a node to connect to and attempt to keep the connection open (see
       the addnode RPC help for more info). This option can be specified
       multiple times to add multiple nodes; connections are limited to
       8 at a time and are counted separately from the -maxconnections
       limit.

$ bitcoind -h | grep -A3 maxconnections=
  -maxconnections=<n>
       Maintain at most <n> connections to peers (default: 125). This limit
       does not apply to connections manually added via -addnode or the
       addnode RPC, which have a separate limit of 8.

addnode rpc help

$ bitcoin-cli help addnode
addnode "node" "command"

Attempts to add or remove a node from the addnode list.
Or try a connection to a node once.
Nodes added using addnode (or -connect) are protected from DoS disconnection and are not required to be
full nodes/support SegWit as other outbound peers are (though such peers will not be synced from).
Addnode connections are limited to 8 at a time and are counted separately from the -maxconnections limit.

@ghost
Copy link

ghost commented Apr 16, 2021

Interesting. I didn't know -addnode had any separate limits. Concept ACK.

Will have to test today and maybe ask related questions here or SE or Reddit.

@jonatack
Copy link
Member Author

Interesting. I didn't know -addnode had any limits. Concept ACK.

Thanks @prayank23. Indeed, as it's not documented AFAIK except in the 0.14 release notes a few years back, I imagine that many users won't ever know unless they look into the codebase, e.g. in net.h

static const int MAX_ADDNODE_CONNECTIONS = 8;

and then verifying how the constant is used, or they infer it by using -netinfo with more than 8 addnode peers configured and seeing that the number of manual connections never exceeds 8 (or by using getpeerinfo with jq).

@jonatack jonatack changed the title doc: update help docs for -addnode config option and addnode rpc doc: update helps for addnode rpc and -addnode/-maxconnections config options Apr 17, 2021
@ghost
Copy link

ghost commented Apr 17, 2021

I imagine that many users won't ever know unless they look into the codebase, e.g. in net.h

Maybe I missed it when I was experimenting with outgoing connections few days back: https://bitcoin.stackexchange.com/questions/103753/increase-maximum-number-of-outgoing-connections-for-full-node

I should have tried addnode to get more outgoing connections.

Not sure what's the best way to test this. I tried adding random nodes from https://bitnodes.io/nodes/?q=United%20States using addnode RPC in Bitcoin Core (Mainnet). Looking at the total number of outgoing connections: 13 which is more than 10 I can verify addnode has separate limits that do not compete with other inbound or outbound connection usage.

Added maxconnections=4 in bitcoin.conf, relaunched Bitcoin Core, tried adding random nodes from above link and it worked as expected (I could see more than 4 peers connected) and mentioned in b4fcbcf

@jonatack
Copy link
Member Author

@prayank23 thanks for having a look. If you run a node with more than 8 -addnode peers (you can get a list of, say, 20 peers from your addrman if needed with bitcoin-cli getnodeaddresses 20), you'll never see more than 8 connections in the "manual" column of cli -netinfo:

        ipv4    ipv6   onion     i2p   total   block  manual
in         0       0       1       0       1
out        4       0      10       4      18       2       8
total      4       0      11       4      19

Codewise, I suggest looking at the code returned by git grep nMaxAddnode -- there are only six lines.

Copy link
Contributor

@jarolrod jarolrod left a comment

Choose a reason for hiding this comment

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

ACK b4fcbcf

Looks good to me. Documenting in the help that addnode connections are counted separately from maxconnections is useful context to add.

@jonatack
Copy link
Member Author

Thanks @jarolrod!

If anyone is curious, the separate connections limit for addnode peers was added by @gmaxwell in #9319. I've added the PR link to the PR description.

@jonatack
Copy link
Member Author

I was experimenting with outgoing connections few days back: https://bitcoin.stackexchange.com/questions/103753/increase-maximum-number-of-outgoing-connections-for-full-node

I should have tried addnode to get more outgoing connections.

FWIW, I found #6014 to be an interesting discussion about connection counts.

@ghost
Copy link

ghost commented Apr 18, 2021

ACK b4fcbcf

FWIW, I found #6014 to be an interesting discussion about connection counts.

Thanks for sharing the link. I have 3 follow up questions after reading few things in that PR:

  1. If more than 8 outgoing connections are bad for the network, can we at least have one option in bitcoin.conf to reduce this to something below 8 if the user wants to? Maybe keep Default=8, MIN=2, MAX=8 and OUTBOUND_FULL_RELAY_CONNECTIONS can be anything between 2 and 8.
  2. If the user can add more outgoing connections using addnode which has a separate limit so total number of full relay outgoing connections can be more than 8, is this okay and does not the involve the risks mentioned in Add a -maxoutbound option for use on pool servers to increase bitcoin network connectivity. #6014 ?
  3. How did we decide this number 8? Why is it not 7 or 9?

@jonatack
Copy link
Member Author

If more than 8 outgoing connections are bad for the network, can we at least have one option in bitcoin.conf to reduce this to something below 8 if the user wants to?

See #4687.

@DrahtBot DrahtBot mentioned this pull request Apr 30, 2021
@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 30, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

@laanwj laanwj merged commit b8b6801 into bitcoin:master May 5, 2021
@jonatack jonatack deleted the update-addnode-docs branch May 5, 2021 15:02
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 5, 2021
…maxconnections config options

b4fcbcf doc: update -maxconnections config option help (Jon Atack)
79685a8 doc: update -addnode config option help (Jon Atack)
2896c6c doc: update addnode rpc help (Jon Atack)

Pull request description:

  Since bitcoin#9319 proposed by Gregory Maxwell and released in v0.14, peers manually added through the `-addnode` config option or using the `addnode` RPC have their own separate limit of 8 connections that does not compete with other inbound or outbound connection usage and is not subject to the limitation imposed by the `-maxconnections` option.

  This PR updates the `-addnode` and `-maxconnections` config options and the `addnode` RPC help docs with this information.

  `-addnode` config option help
  ```
  $ bitcoind -h | grep -A5 addnode=
    -addnode=<ip>
         Add a node to connect to and attempt to keep the connection open (see
         the addnode RPC help for more info). This option can be specified
         multiple times to add multiple nodes; connections are limited to
         8 at a time and are counted separately from the -maxconnections
         limit.

  $ bitcoind -h | grep -A3 maxconnections=
    -maxconnections=<n>
         Maintain at most <n> connections to peers (default: 125). This limit
         does not apply to connections manually added via -addnode or the
         addnode RPC, which have a separate limit of 8.
  ```

  `addnode` rpc help
  ```
  $ bitcoin-cli help addnode
  addnode "node" "command"

  Attempts to add or remove a node from the addnode list.
  Or try a connection to a node once.
  Nodes added using addnode (or -connect) are protected from DoS disconnection and are not required to be
  full nodes/support SegWit as other outbound peers are (though such peers will not be synced from).
  Addnode connections are limited to 8 at a time and are counted separately from the -maxconnections limit.
  ```

ACKs for top commit:
  prayank23:
    ACK bitcoin@b4fcbcf
  jarolrod:
    ACK b4fcbcf

Tree-SHA512: b6d69baa6cbf6d53f91bac5b39b549d49db6c95f92ea1bdd3588a6432794a25ac2c8b3c89e2c72bb9097e61f2717c8b5ecc404745d5992b88e523db03200898f
gwillen pushed a commit to ElementsProject/elements that referenced this pull request Jun 1, 2022
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
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.

4 participants