How does one attain 1,000+ connections like blockchain.info?

32

12

At this moment, blockchain.info has over 1,900 nodes connected to their bitcoin client.

I have been running an m1.small ubuntu 12.04 server and bitcoind for ~4 days straight now with no reboots. My bitcoind client still only shows ~60 connections maximum when performing a "./bitcoind getinfo" command.

How can I achieve 1,000+ connections to my bitcoind client? And is it "worth it" in your opinion?

EDIT: I have re-started my bitcoind client with the -maxconnections=1000 and -timeout=15000 parameters but after ~12 hours of running bitcoind, the number of connections is only up to ~40. And I don't seem to be maxing out my CPU, RAM, or bandwidth just yet.

EDIT 2: I have not seen a "connected time" over 8 hours in the list provided by blockchain.info so that tells me they must restart their server every 8 hours or so. Either that, or connections drop and refresh after 8 hours? I am beginning to think that blockchain.info keeps track of IP addresses running bitcoin in a database of sorts... and forefully connects to them every time their bitcoind reboots. Am I right?

user3145

Posted 2013-03-04T08:45:47.077

Reputation: 777

5Blockchain runs multiple bitcoind nodes and the networking components were also modified to use boost::asio rather posix sockets. you should be able to get at least 1024 connections with standard bitcoind though.Ben Reeves 2013-03-04T19:22:40.127

1Any idea on what might be holding me back from achieving 1,024 connections on my bitcoind? I don't seem to be maxing out my CPU, RAM, or bandwidth just yet.user3145 2013-03-04T21:53:13.227

Bitcoin Unlimited has an option -maxoutconnections that allows you to increase outgoing connections to peers. It defaults to 8 but you can set it to something higher without having to recompile the node from modified source.greatwolf 2016-10-29T20:23:12.713

1When I set -maxconnections to something high I get the following error:

> Warning: Reducing -maxconnections from 4096 to 865, because of system limitations.

so it seems like one can not even go super high with incoming connections as well? – lifeofguenter 2017-06-18T10:49:27.323

@greatwolf is bitcoin unlimited works for bitcoin or bitcoin cash ?AMB 2017-09-07T13:25:52.343

@AMB I believe BU offers two versions of the client, one works with the legacy chain and the other works with Bitcoin Cash.greatwolf 2017-09-10T01:33:42.290

Answers

12

The bitcoind client has a maxconnections configuration option. The client launched With -maxconnections=N will allow up to N incoming connections to be established simultaneously.

Perhaps you may need to increase the connection timeout for that many connection attempts from a single (possibly underpowered) node. Perhaps set it to like 15 seconds (15000 ms).

-timeout= Specify connection timeout in milliseconds (default: 5000)

[Edit: Pieter Wuille's answer gets you further there. -addnode will let you force new outgoing conections to nodes when you have their IP addresses.]

Stephen Gornick

Posted 2013-03-04T08:45:47.077

Reputation: 26 118

I will re-start my bitcoind client now with the timeout increased to 15 seconds as suggested as well as the -maxconnections=1000 and get back to you.user3145 2013-03-04T21:54:49.013

6So after 7 hours of running bitcoind with a 15 second timeout and 1,000 max connections.. I was at 32 connections at one point but have now dropped to 28, so I doubt adding the maxconnections or the timeout variable did much at all unfortunately. In fact I think it may have hindered the number of connections I would normally have after 7 hours.user3145 2013-03-05T05:16:53.463

does maxonnections in the .conf override what's in code as the max?Sun 2019-03-08T01:24:14.560

20

The given answers don't answer the question. Even though it might not makes sense to achieve a thousand connections, here's how to do that on Debian. You want to make some slightly changes in the code and recompile bitcoind:

Get required packages for compiling:

$ aptitude install git make build-essential libssl-dev libboost-all-dev libdb-dev libdb++-dev libminiupnpc-dev

Clone the git repository (make sure the version is the most recent branch):

$ cd /usr/src
$ sudo git clone -b 0.8.4 https://github.com/bitcoin/bitcoin
$ cd bitcoin/src

Edit the net.cpp file:

@@ -27,7 +27,7 @@
 using namespace std;
 using namespace boost;

-static const int MAX_OUTBOUND_CONNECTIONS = 8;
+static const int MAX_OUTBOUND_CONNECTIONS = 1000;

 bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false);

@@ -1533,7 +1533,7 @@
             OpenNetworkConnection(CAddress(vserv[i % vserv.size()]), &grant);
             MilliSleep(500);
         }
-        MilliSleep(120000); // Retry every 2 minutes
+        MilliSleep(5000); // Retry every 5 seconds
     }
 }

1.) By changing MAX_OUTBOUND_CONNECTIONS, the client will go on connecting until it reaches 1000 proactive connections.

2.) By changing the sleep timeout new connections are tried more frequently.

Compile and install bitcoind:

$ sudo make -f makefile.unix
$ sudo mv bitcoind /usr/bin

Don't forget to set the maxconnections in bitcoin.conf:

maxconnections=1000

Start bitcoind and your done. The client will make lots of connections really fast.

Disclaimer: As Pieter Wuille pointed out, it can harm the network to run a modified client like this one. Please use this solution for research purposes only and not as a permanent solution.

MorbZ

Posted 2013-03-04T08:45:47.077

Reputation: 317

7I don't want to downvote because you're indeed actually answering the question, but I really strongly want to stress that doing this is a horrible idea and unnecessary. See my answer for why.Pieter Wuille 2013-08-25T23:37:16.097

3@Pieter Wuille: How do you want to stop people from exploiting the Bitcoin network? Just telling them "hey, you bad boys, don't do this or that"? That's not going to work...Kozuch 2013-12-16T10:39:11.577

3I'm not trying to stop bad guys - they're a fact of life, and I'm sure we can deal with a few. What I want to avoid is people incorrectly assuming that more connections is better for them and/or the network.Pieter Wuille 2013-12-16T23:39:05.327

2This is the real answer!Felipe 2014-03-12T11:29:48.990

20

Bitcoin by default will not make more than 8 outgoing connections, and -maxconnections only controls how many incoming connections you allow. Feel free to set this higher, but it will take time before others connect to you in large numbers.

Please don't change this, as there is no need. Connectable peers on the network are a scarce resource, and essential to the decentralization. If people go try connect to all of them like some sites do, we'll very quickly run out.

In case you're a merchant or miner, you perhaps want to set up a few fixed connections to trusted others (see the -addnode command line/config option), but having more connections does not mean stronger verification (the reference client always verifies everything) or even faster relaying (as you'll slow down by distributing new blocks and transactions to all your peers). It is mostly a matter of providing a service to the network.

Pieter Wuille

Posted 2013-03-04T08:45:47.077

Reputation: 54 032

2

After 4 days of running my box with -maxconnections=1000, I was still only at ~50 connections. I have not seen a "connected time" over 8 hours in the list provided by blockchain.info so that tells me they must restart their server every 8 hours or so. Either that, or connections drop and refresh after 8 hours?

user3145 2013-03-05T18:23:25.403

I'm sure they have a custom infrastructure that creates thousands of outgoing connections. Bitcoind never creates more than 8. As I said, there is no need for more.Pieter Wuille 2013-03-05T23:27:16.687

2

As nobody seems to have mentioned it I'll chip in for future reference. If your bitcoind node is behind a router/NAT then you can only connect to others, they cannot connect to you. Let's assume most people are in that situation, which makes most nodes unconnectable (directly at least). If you open up your node port on your router then every bitcoind node out there will be able to connect to you if they wish rather than your node only being able to connect to others who have opened their port. The same applies to Bittorrent and other p2p systems.

George

Posted 2013-03-04T08:45:47.077

Reputation: 586

1

Why do you need 1,000+ connections?

By default bitcoind cannot have more than 125 connections. You need to start bitcoind with the parameter -maxconnections=<n> or set maxconnections=<n> in bitcoin.conf to be able to connect to more peers.

Nicolai

Posted 2013-03-04T08:45:47.077

Reputation: 1 748

7Why?! Why not should be the real question! If you must know, I want to have the most verified blockchain in the world.user3145 2013-03-04T19:06:00.400

4"The most verified"? That makes no sense. Every node at the same block height and block hash is equal. And yours may have a blockchain fork that eventually becomes orphaned.Stephen Gornick 2013-03-04T20:38:43.963

7Sorry for the typo, I'm not up to speed on the entire bitcoin lexicon just yet. If not the most verified, then I want to be the fastest at recognizing new transactions. That is what I meant.user3145 2013-03-04T21:52:26.003

-3

To check whether you allow incoming, use this: https://bitnodes.21.co There is a button to check your ip and if it results in green, you are fine to have incoming connection. Once you have that, I was told you can have more outgoing connection. Good luck.

Dennis Ng

Posted 2013-03-04T08:45:47.077

Reputation: 1

That's not an answer to the question.Pieter Wuille 2016-06-30T13:27:13.143