Today I'm going to help the Bitcoin network by setting up and running a full node. I am documenting my setup process in the hopes that maybe a few of you will do the same. In the near future I plan to also blog about setting up and running a Lightning node as well.
What Is A Full Bitcoin Node?
A full node is a program that fully validates transactions and blocks. Almost all full nodes also help the network by accepting transactions and blocks from other full nodes, validating those transactions and blocks, and then relaying them to further full nodes.
Why This Is Important?
Full nodes help enforce the consensus rules of the Bitcoin network. When a full node client is running, it downloads every new block and every new transaction and checks them to make sure they are valid. Here are some examples of consensus rules, though there are many more:
- Blocks may only create a certain number of bitcoins.
- Transactions must have correct signatures for the bitcoins being spent.
- Transactions/blocks must be in the correct data format.
- Within the block chain, a transaction output cannot be double-spent.
Minimum System Requirements
Bitcoin Core full nodes have certain requirements. If you try running a node on weak hardware, it may work — but you’ll likely spend more time dealing with issues. If you can meet the following requirements, you’ll have an easy-to-use node.
- Desktop or laptop hardware running recent versions of Windows, Mac OS X, or Linux.
- 150GB of free disk space (size of the blockchain plus room to grow)
- 2GB of memory (RAM)
- A broadband Internet connection with upload speeds of at least 50 Kb per second
- An unmetered connection, a connection with high upload limits, or a connection you regularly monitor to ensure it doesn’t exceed its upload limits. It’s common for full nodes on high-speed connections to use 200GB in uploads or more a month. Download usage is around 20GB/month, plus around an additional 100GB the first time you start your node.
I will be using a small Lenovo Thinkpad running Ubuntu 17.10.1. A unique challenge with my setup is that the internal HD in my machine is only 32 GB, which is far less than the required ~150GB needed to store the entire blockchain. To work around this I will be storing only the most recent chainstate on the HD itself while storing the rest of the chain on the an external HD. I will cover this setup in more details later.
Before installing Bitcoin Core, it is important to first make sure that your machine has all the latest software updates, security patches, drivers and BIOS installed. Install and updated as needed before proceeding.
Now that your machine is fully up to date, lets download Bitcoin Core and sync with the latest blockchain.
Installing Bitcoin Core and Syncing
First open your console or terminal emulator and run the following commands as an admin level user:
// Add the Bitcoin Personal Package Archive (PPA) to your system sudo apt-add-repository ppa:bitcoin/bitcoin // Install both the Bitcoin GUI and the daemon sudo apt-get install bitcoin-qt bitcoind
Note that even though we installed both the GUI and daemon, you can’t run both at the same time using the same configuration directory.
Next start the Bitcoin Core GUI. You will immediately be prompted to choose a directory to store the blockchain and your wallet. Unless you have a separate partition or drive you want to use, click OK to use the default. Since I do not have enough internal storage on my machine, I chose to download the data to my external drive.
The Bitcoin Core GUI will now begin to download the block chain. **This step will take at least 16 hours based on your internet connection and computer speed. Also be aware that during the download, Bitcoin Core will use a significant part of your connection bandwidth. Thankfully can stop Bitcoin Core at any time by closing it and it will resume from the point where it stopped the next time you start it.
Autostarting the Bitcoin Daemon (Optional)
Starting your node automatically each time you login to your computer makes it easy for you to always contribute to the network. The easiest way to do this is to tell Bitcoin Core GUI or Daemon to start at login.
Since I will be only be accessing my node via
SSH, I will configure my machine to autostart the Daemon only via
crontab. To edit
crontab, run the following command via your terminal:
Scroll to the bottom of the file displayed and add the following line.
@reboot bitcoind -daemon
Save the file and exit. Now Bitcoin Core daemon will be automatically started each time your reboot your computer.
To support the Bitcoin network, you must allow inbound connections on
port 8333. By default when Bitcoin Core starts, it will establish 8 outbound connections to other full nodes so it can download the latest blocks and transactions. If you just want to use your full node as a wallet only, you don’t need more than these 8 connections—but if you want to support lightweight clients and other full nodes on the network, you must allow inbound connections.
Since almost all home internet connections are filtered by a router or modem and sometimes also a firewall. Bitcoin Core will request your router automatically configure itself to allow inbound connections to Bitcoin’s port,
port 8333. Unfortunately many routers don’t allow automatic configuration, so you must manually configure your router. You may also need to configure your firewall to allow inbound connections to
Enabling inbound connections requires two steps, plus an extra third step for firewall users:
- Giving your computer a static (unchanging) internal IP address by configuring the Dynamic Host Configuration Protocol (DHCP) on your router.
- Forwarding inbound connections from the Internet through your router to your computer where Bitcoin Core can process them.
- Configuring your firewall to allow inbound connections. This step mainly applies to power users and Windows users. (Mac OS X and most Linux distributions do not enable a firewall by default.)
Let's configure all of this now!
In order for your router to direct incoming
port 8333 connections to your computer, it needs to know your computer’s internal IP address. Routers usually assign computers on your network dynamic IP addresses that change frequently, so we need to ensure your router always gives your computer the same internal IP address.
Start by logging into your router’s administration interface. Usually this can be done by going to
http://192.168.[0,1 or 2].1 depending upon the brand of your router. Authenticate when prompted and then search the menus for options related to DHCP. These options may also be called "Address Reservation" or "DHCP Resveration".
Once this menu is found, most routers will display a list of computers and devices currently connected to your network, and then let you select a device to make its current IP address permanent. Find the computer running Bitcoin Core in the list, select it, and add it to the list of reserved addresses. Make a note of its current IP address as we’ll use the address in the next section.
Enabling Port Forwarding
For this step, you need to know the local IP address of the computer running Bitcoin Core. You should now have this information from configuring the DHCP reservation table in the previous step. Again from your routers configuration page, look for an option called "Port Forwarding", "Port Assignment" or anything with “Port” in its name.
Both the external port and the internal port should be
8333 for Bitcoin. Make sure the IP address you enter is the same one you configured in the previous subsection.
After filling in the details for the mapping, save the entry. If you are not behind a firewall, your bitcoin node should now be fully accessible to the network! To verify your node visit this handy verification page provided by Bitnodes. The tool will attempt to guess your IP address. If the address is wrong or blank, you will need to enter your address manually. Note that your node doesn't have have to be completely synced to verify it's visibility!
After you fill in the field with your IP address, press the "Check Node" button and the tool will inform you whether your port is open (green box) or not open (red box). If you get the green box, congratulations you're all setup. If you get the red box, you either misconfigured your router or are possibly behind a firewall. Verify your DHCP and Port Forwarding configurations and/or view the "Firewall Configuration" section below for help configuring your firewall.
Here are some helpful links for the most common firewalls to allow inbound connections on
This section contains advice about how to change your Bitcoin Core configuration to adapt it to your needs.
There are two ways to change your configuration. The first is to start Bitcoin Core with the options you want. For example, if you want to limit it to using one CPU core for signature verification, you can start Bitcoin Core like this:
// Bitcoin Core daemon bitcoind -par=1 -daemon // Bitcoin Core GUI bitcoin-qt -par=1
Once you’ve decided you like your configuration, you can add it to the Bitcoin Core configuration file. You can find that file in the following directories:
- Windows: %APPDATA%\Bitcoin\
- Mac OSX: $HOME/Library/Application Support/Bitcoin/
- Linux: $HOME/.bitcoin/
To add an option to the configuration file, just remove its leading dash. You may also need to remove any quotation marks you used in your shell. For example, the -par option seen above would look like this in the configuration file:
It is possible to configure your node to to run in pruned mode in order to reduce storage requirements. This can reduce the disk usage from over 150GB to around 5GB. Be ware that running a pruned node is incompatible with
-rescan. It also disables the RPC
importwallet. Two RPCs that are available and potentially helpful, however, are
To enable block pruning set
prune=N on the command line or in
N is the number of MiB to allot for block and undo data. A value of
0 disables pruning entirely.
Depending on the limitations imposed by your household, or more likely, your ISP, you may need to set limits on the amount of bandwidth your node consumes.
By default, bitcoin-core allows up to 125 connections to different peers, 8 of which are outbound. You can therefore, have at most 117 inbound connections. The default settings can result in relatively significant traffic consumption.
Here are some useful configuration commands to help reduce overall traffic to your node:
Maximum Upload Targets:
-maxuploadtarget=<MiB per day>
A major component of the traffic is caused by serving historic blocks to other nodes during the initial blocks download phase (syncing up a new node). This option can be specified in MiB per day and is turned off by default. The recommended minimum is 144 blocks per day (max. 144MB per day).
Disabling listening will result in fewer nodes connected (remember the maximum of 8 outbound peers). Fewer nodes will result in less traffic usage as you are relaying blocks and transactions to fewer nodes.
Reduce Max Connections:
Reducing the maximum connected nodes to a minimum could be desirable if traffic limits are tiny. Keep in mind that bitcoin’s trustless model works best if you are connected to a handful of nodes.
Causes your node to stop requesting and relaying transactions unless they are part of a block and also disables listening as described above. This reduces your node’s bandwidth to the absolute minimum necessary to stay synchronized with the network, about 150 megabytes incoming data per day and about 1 megabyte of outgoing data per day
Note that there are tons of other ways to configure your node to suit your needs but these are some of the most common.
Splitting Blockchain Storage Area
Bitcoin Core normally puts all of its data into one data directory, but oftentimes it is useful to adjust things so that certain of these files go elsewhere. In my case, I need to split storage between my internal HD and external.
Bitcoin Core's overall speed is significantly affected by the random-access speed of the contents of the
chainstate directory; if your data directory is located on a magnetic disk, your
chainstate access speed will very probably be the biggest performance bottleneck. You can therefore often massively improve performance by moving just the
chainstate directory (which is only a few GB) to an SSD drive. Even moving the
chainstate directory to a USB flash drive can often provide a large performance improvement, especially if the USB flash drive is advertised as being particularly high-speed.
To move your chainstate, do the following steps in order:
- Shut down Bitcoin Core
- From the data directory, cut the
chainstatedirectory (not just its contents, but the directory itself) and paste it somewhere on the target drive. On Linux, make sure that permissions allow for Bitcoin Core to read/write the directory and its files at the new location.
- Open a terminal in the data directory. For example, if you moved your chainstate so that its new location is
/mnt/ssd/core/chainstate(ie. within that directory are a bunch of .ldb files), you'd run
ln -s /mnt/ssd/core/chainstatefrom immediately within the data directory. On Windows, run
mklink /D chainstate ?:\path\to\chainstate. For example, if you moved your chainstate so that its new location is F:\core\chainstate (ie. within that directory are a bunch of .ldb files), you'd run
mklink /D chainstate F:\core\chainstatefrom immediately within the data directory.
If you're using a removable drive, make sure that the path to the real chainstate does not change.
Congratulations you have now improved the overall health, stability and security of the entire Bitcoin network. Be sure to run node as often as possible. Now relax and pour yourself a nice drink! Cheers!