Running Bitcoin & Lightning Nodes Over The Tor Network (2021 Edition)

And Connecting Your Phone to Use Lightning On-The-Go

Preface

Primary:

Standalone:

Table Of Contents

Introduction

Part 1 — Installing Linux, Dependencies, And Tor

1-A) Downloading, Installing, And Updating Linux

Download Kubuntu ISO image

Install ISO Image To USB Or CD

Install The Operating System

Log In And Get Acquainted

Updating Linux

1-B) Installing & Configuring Tor

Adding The Tor Repository

$ lsb_release -c
$ sudo nano /etc/apt/sources.list.d/tor_repo.list
deb http://deb.torproject.org/torproject.org focal main
deb-src http://deb.torproject.org/torproject.org focal main

Adding The Tor GPG Key & Installing Tor

$ sudo apt install curl(Below is a single string, not two lines.)$ curl https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | sudo apt-key add -
$ sudo apt-get update$ sudo apt-get install tor deb.torproject.org-keyring
Video cuts off after 60 seconds. Just let the install complete. Press ‘y’ when prompted.

Configuring Tor For Bitcoin & Lightning

SOCKSPort 9050
Log notice stdout
ControlPort 9051
CookieAuthentication 1
CookieAuthFileGroupReadable 1
HiddenServiceDir /var/lib/tor/lnd/
HiddenServicePort 8080 127.0.0.1:8080
If the file doesn’t open: Right click, select “Open With” , then select the text editor.

Setting Tor User Permissions

$ grep User /usr/share/tor/tor-service-defaults-torrc
$ sudo usermod -a -G debian-tor satoshi

Restart Your Machine

Configure Tor To Start During Boot Up

$ sudo systemctl enable tor
$ sudo systemctl start tor

1-C) Prerequisites & Dependencies

Installing Git

In the standalone beginners guides, I include videos for nearly every step.

Cloning The Bitcoin Core Repository

$ mkdir -p ~/code && cd ~/code
$ cd ~/code$ git clone https://github.com/bitcoin/bitcoin.git

Installing Libraries

$ sudo apt-get install build-essential libtool autotools-dev automake pkg-config bsdmainutils python3 libevent-dev$ sudo apt-get install libboost-system-dev libboost-filesystem-dev libboost-test-dev libboost-thread-dev$ sudo apt-get install libsqlite3-dev$ sudo apt-get install libminiupnpc-dev$ sudo apt-get install libzmq3-dev$ sudo apt-get install libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools$ sudo apt-get install libqrencode-dev

Installing The Berkeley Database

$ cd ~/code/bitcoin$ ./contrib/install_db4.sh `pwd`

Part 2 — Installing Bitcoin & Fully Validating

2-A) Compile Bitcoin Core 0.21.1 From The Source Code

$ cd ~/code/bitcoin$ git checkout tags/v0.21.1$ ./autogen.sh

Pay attention to this step.

$ export BDB_PREFIX='/home/satoshi/code/bitcoin/db4'$ ./configure BDB_LIBS="-L${BDB_PREFIX}/lib -ldb_cxx-4.8" BDB_CFLAGS="-I${BDB_PREFIX}/include"
$ make$ sudo make install

2-B) Configure The Bitcoin Core Software

Creating The Configuration File

$ mkdir ~/.bitcoin
# Needed for full validation
assumevalid=0
# Improves LND performance
# Needs to be set now if you're going to install Lightning later
txindex=1
# Allows LND to connect to the Bitcoin node via an RPC user & pass
rpcuser=PICK-A-USERNAME
rpcpassword=PICK-A-PASSWORD
# Allows LND & Bitcoin Core to communicate via ZeroMQ
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28333
## Tor Settings
debug=tor
onlynet=onion
proxy=127.0.0.1:9050
bind=127.0.0.1
dnsseed=0
dns=0
## Tor v3 Seedsaddnode=kpgvmscirrdqpekbqjsvw5teanhatztpp2gl6eee4zkowvwfxwenqaid.onion
addnode=bnx4povtqynvwnui5oqm5xcxqvat3j7yzgn6mqciuyszqawhuayvyaid.onion:8333
addnode=wyg7twmf7t3pfvfpdcfd64wvjj2pkccuui7ew34ovnqung5f623b4yyd.onion
addnode=glm52zywiqrcxuwswvgjsxr5pfeggil7uci4z5tbpvb4rjyu5hwjhtid.onion
addnode=xspiicyddsdmzxsffzw6z4f22wi2iwyyufkjcaj2qr7cznxymtft5nid.onion
addnode=nqb5q6d4nhp54ziahhm2oxopqwyyulg7nrqwrcmfvwhj7y7xasaeg7ad.onion
addnode=vp4qo7u74cpckygkfoeu4vle2yqmxh7zuxqvtkazp4nbvjnxl2s3e6id.onion
addnode=ew7x2hv76f7w7irfyektnbhd42eut27ttbfgggu7lbpxsyrlfvsujuqd.onion
addnode=qxkgr5u4rmwme5jticjuuqrecw5vfc5thcqdxvbffwbqgqkdin7s7vid.onion
## Tor v2 Seedsaddnode=bitcoinostk4e4re.onion
addnode=bk7yp6epnmcllq72.onion
addnode=qg6embx5o6p4h4it.onion:8333
addnode=trjbor5uc63ghwug.onion:8333
addnode=3eznsanhteo4m2k2.onion:8333
addnode=ajjnxnxjtx6ci4cp.onion:8333
addnode=icbbaj7up3kzk4cl.onion:8333
addnode=n4n5lzeyiyi2755c.onion:8333
addnode=opw6r3lacfd4eyys.onion:8333
addnode=qdwrjk2ow3yjckne.onion:8333
addnode=wjpkhpyt2gd4jtid.onion:8333
addnode=k7ktw2e5mj4r4na5.onion:8333
addnode=zilzmq3jbzdj63md.onion:8333
addnode=4nnijtmfxeueix7s.onion:8333
addnode=s4gy4h3u5zjmpbtr.onion:8333
addnode=33vdhmzdfimfgov3.onion:8333
addnode=aipupphit3enggpj.onion:8333

Explaining The Tor Configurations

https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp#L116

Alternative Tor Options

2-C) Starting Up The Software And Syncing The Blockchain

$ touch ~/.bitcoin/debug.log$ tail -f ~/.bitcoin/debug.log
$ bitcoin-qt & tail -f ~/.bitcoin/debug.log | grep tor
https://thumbs.gfycat.com/CompassionateBlackandwhiteAcaciarat-mobile.mp4
By the time this tutorial is published I’ll have wiped my hard drive. The identifying information will be irrelevant.

Notes & Anecdotes

$ sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target$ systemctl restart systemd-logind.service
$ sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target

Part 3 — Installing Lightning & Opening Channels

3-A) Installing ‘Go’ & LND

Installing Go

$ wget https://dl.google.com/go/go1.15.6.linux-amd64.tar.gz$ sudo tar -C /usr/local -xzf go1.15.6.linux-amd64.tar.gz
https://golang.org/dl/

Installing LND

$ echo "export PATH=$PATH:~/go/bin:/usr/local/go/bin" >> ~/.bashrc
$ cd ~/code$ git clone https://github.com/lightningnetwork/lnd
$ cd ~/code/lnd$ git checkout tags/v0.12.0-beta$ make install

3-B) Configuring LND & Syncing The Graph

Configuring The lnd.conf File

## LND Settings# Lets LND know to run on top of Bitcoin (as opposed to Litecoin)
bitcoin.active=true
bitcoin.mainnet=true
# Lets LND know you are running Bitcoin Core (not btcd or Neutrino)
bitcoin.node=bitcoind
## Bitcoind Settings# Tells LND what User/Pass to use to RPC to the Bitcoin node
bitcoind.rpcuser=PICK-A-USERNAME
bitcoind.rpcpass=PICK-A-PASSWORD
# Allows LND & Bitcoin Core to communicate via ZeroMQ
bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332
bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333
## Zap Settings# Enables LND's REST interface
# Zap mobile wallet will connect over Tor through this interface
restlisten=localhost:8080
# Tor Settingstor.active=true
tor.v3=true
tor.streamisolation=true
listen=localhost

LND connects to Bitcoin Core via RPC

Zap connects to LND over Tor via REST

$ mkdir -p ~/.lnd && touch ~/.lnd/lnd.conf

Launching Bitcoin & LND

$ bitcoind
$ lnd
We’ll use the 3rd terminal window in the next step.

Creating The Lightning Wallet

[INF] LTND: Waiting for wallet encryption password. Use `lncli create` to create a wallet, `lncli unlock` to 
unlock an existing wallet, or `lncli changepassword` to change the password of an existing wallet and unlock it.
$ lncli create
Input wallet password:  
Confirm password:
Do you have an existing cipher seed mnemonic you want to use? (Enter y/n): n
Your cipher seed can optionally be encrypted. 
Input your passphrase if you wish to encrypt it (or press enter to proceed without a cipher seed passphrase):

3-C) Funding Your Wallet & Opening A Channel

Address Generation & Funding

$ lncli newaddress np2wkh
$ lncli walletbalance
$ lncli listunspent

Picking A Node And Connecting To It

$ lncli connect 03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3f8f@of7husrflx7sforh3fw6yqlpwstee3wg5imvvmkp4bz6rbjxtg5nljad.onion:9735
This image was taken for the non-Tor tutorial, but the premise is the same.

Opening A Channel

$ lncli openchannel --node_key=03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3f8f --local_amt=10000
$ lncli pendingchannels

Part 4 — Connecting Your Phone & Making Payments

4-A) Install ‘LND Connect’ & Connecting Zap To LND

Installing LND Connect

$ go get -d github.com/LN-Zap/lndconnect$ cd /home/satoshi/go/src/github.com/LN-Zap/lndconnect$ make

Obtain Our Onion Hostname

$ sudo cat /var/lib/tor/lnd/hostname

Connecting Zap

$ cd ~$ lndconnect --host=ONIONADDRESS --port=8080 --image

4-B) Interacting With Your LND Node Via Zap

Using Zap To Control & View Our LND Node

4-C) Balancing Your Channel

4-D) Testing Small Payments

Lightning Websites

Donations

Extra Guidance

How To Create A Transaction Index

$ bitcoind -reindex
$ bitcoind

How To Recompile/Update Bitcoin Core

$ bitcoind --version

How To Update LND

$ cd /home/satoshi/go/src/github.com/lightningnetwork/lnd$ git pull$ make clean && make && make install

Information Aggregator