Tuesday, April 13, 2021

How to compile your own node

This post is just going to be practical advice on how to compile your own Bitcoin node on Linux, for which I sense a shortage on an Internet filled with endless halfwits who recommend lesser solutions. I mean the real thing, Bitcoin Core, the reference implementation with no nonsense, which is the proper, safest way to use bitcoin. Assuming your machine is secure, your setup will be 100% trustless and permissionless and give you complete mastery of your bitcoin transactions with awesome coin control features dependent on no other entity except the decentralized blockchain itself. Unlike the other guides that seem to be out there, here are COMPLETE idiot-proof instructions that work at least on Ubuntu and Debian and Mint in my testing and probably many other distros, so move on over from Windows if you need to or if you already have one of these let's just get right down to it and start with one very important ingredient. Open a terminal window and write:

"sudo apt-get install libboost-all-dev"

Then get Berkeley DB:

"sudo apt-get install libdb++-dev"

"sudo apt-get install libdb-dev"

Some optional port mapping libraries that I recommend you get in order to make your node more easily reachable:

"sudo apt install libminiupnpc-dev libnatpmp-dev"

You also need:

"sudo apt-get install build-essential libtool autotools-dev automake pkg-config bsdmainutils python3"

"sudo apt-get install libevent-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-test-dev"

"sudo apt install libsqlite3-dev"

"sudo apt-get install libzmq3-dev"

"sudo apt-get install libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools"

Get Git if you don't have it already:

"sudo apt-get install git"

Stand in your source code directory such as "scr" (make one if you don't have it with "mkdir scr", then go there using "cd scr") and clone bitcoin into it:

"git clone https://github.com/bitcoin/bitcoin.git"

Now you need to switch to your new bitcoin directory (type "cd bitcoin" for that) and check out the current version, ignoring the warning about detached head:

"git checkout v23.0"

Issue this command:

"./autogen.sh"

The distributed binaries are stuck with an old version of Berkeley DB for compatibility, but we are going to screw that since we don't need them anymore and configure with the latest (don't worry, your node will still accept your old wallet files, just can't necessarily go the other way):

"./configure --with-incompatible-bdb"

Now we are ready to compile, which takes anywhere from minutes to several hours depending on your system, but this should work on very old hardware and even 32-bit:

"make"

Then install it:

"sudo make install"

And that's it, you got the power! (You can delete your scr directory now if you want, which will free up 5 gigabytes.) Type "bitcoin-qt" anywhere in a terminal to start the GUI or "bitcoind" for the daemon (then talk to it with bitcoin-cli) and enjoy your node. Be patient for it to synchronize though, which will take days to months depending on your system resources. Once you have compiled it yourself you never go back, so kiss the Core team's releases goodbye -- or SPV or God forbid, custodial wallets -- and if this was helpful, as you move your coins from shady soon-to-be-hacked-or-outlawed places to your own personally compiled node, remember that I have a bitcoin donation address. Especially if you are an old bitcoiner who never bothered to run your own node before, the potential losses this can save you from are enormous.

This is beyond the scope of what I wanted to cover here and much easier to find information about elsewhere, but of course you want to optimize your bitcoin.conf file which is kept in your bitcoin data directory (/home/.bitcoin by default) to work best on your system. Say, if you want to prune or not (or must due to low disk space since nearly 400 gigabytes is currently needed for a full archival node, growing by some 300 megabytes every day, so if you don't have that might as well set something like prune=550 right away, which results in the smallest possible node, keeping only 550 megabytes of blocks), how big your mempool and how much memory to give the UTXO cache and so on -- for which I recommend this guide to familiarize yourself with all the settings:

https://manpages.debian.org/unstable/bitcoind/bitcoind.1.en.html

And if you think your hardware is too weak, you are probably wrong. Sure it is nicest to have at least an SSD and a CPU no older than Sandy Bridge or so (beyond which there is no significant improvement in user experience), but it's a testament to the awesome power of bitcoin that you can comfortably run a fully consensus-rules-enforcing, validating-of-every-single-transaction and usually even archival node of the greatest payment network in the world on weaker hardware than you feel you need for office work or web browsing. Mind-boggling, but true. So if you have a decades-old laptop or something lying around that you didn't think was useful anymore, this is a great way to breathe life into it, after first installing Linux of course. It works wonderfully on as little as two gigabytes of RAM and ten gigabytes extra disk space just using the default settings plus pruning, and you can have as little as 1 GB RAM if you make some adjustments. Having a weak CPU is just a matter of patience for your node to sync, and then that either won't break a sweat during constant use; forget about turning your node off ever, which is a nuisance having to resync every time you turn it back on. And one last thing: don't forget to encrypt your wallet (which is easily done in the GUI) and/or your hard drive using LUKS with a strong password (easily done when setting up Linux) and back up your wallet file before putting large amounts of bitcoin in it, plus have a reasonably strong user password so your node won't get hijacked while running unattended. You can also run your node over Tor or at least broadcast your transactions that way if you feel extra paranoid. But first it is most important to play around with all the settings and learn how nodes work so you never again will be dependent on anyone else's and you will be impervious to any and all attempts at censorship by governments. It is too late to mine your own bitcoin, but it is most assuredly not too late -- and by incontrovertible design NEVER will be too late -- to run your own full node to be completely in control of whatever bitcoin you obtain by any means.

No comments: