Lightning Network node (c-lightning) on RBP3

BTC & LN ssh login dashboard

Before starting

It is HIGHLY recommended you play with testnet nodes first, and only move to the world of real, mainnet money when you feel comfortable enough!

Connect to RBP

ssh pi@192.168.1.102
sudo apt update
sudo apt -y upgrade

Get c-lightning

Dependencies

sudo apt-get install -y autoconf automake build-essential git libtool libgmp-dev libsqlite3-dev python python3 net-tools zlib1g-dev

Get the source code

cd ~ 
git clone https://github.com/ElementsProject/lightning.git
cd lightning
git -c http.proxy=socks5h://127.0.0.1:9050 clone http://nxshomzlgqmwfwhcnyvbznyrybh3gotlfgis7wkv7iur2yj2rarlhiad.onion/git/lightning.git
cd lightning
git config --add remote.origin.proxy "socks5h://127.0.0.1:9050"
git remote add github https://github.com/ElementsProject/lightning.git

What to compile

Latest c-lightning Release being v0.6
git checkout v0.6

Compile

./configure
make
sudo make install

Set things up

Generate Bitcoin RPC password

python3 ~/bitcoin/share/rpcauth/rpcauth.py lightning
String to be appended to bitcoin.conf:
rpcauth=lightning:b721f772112599d454e5192c345c68$bcf157cf3debaf85de0eefaf90b3565f90717c5029b520befa74fbf35f80d46c
Your password:
a11IIMZKndBeFBsGaFV81X-mwX14nIr8b0EN9ltuF7o=

Enable Bitcoin RPC authentication

sudo su - bitcoin
nano ~/.bitcoin/bitcoin.conf
exit
sudo systemctl restart bitcoind

c-lightning user

sudo adduser lightning
Adding user `lightning' ...
Adding new group `lightning' (1002) ...
Adding new user `lightning' (1002) with group `lightning' ...
Creating home directory `/home/lightning' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
securePasswordIveSavedToPasswordManager
Retype new UNIX password:
securePasswordIveSavedToPasswordManager
passwd: password updated successfully
Changing the user information for lightning
Enter the new value, or press ENTER for the default
Full Name []:
BlockStream Core
Room Number []:
666
Work Phone []:
Home Phone []:
Other []:
probably lizard people
Is the information correct? [Y/n]
y
sudo su - lightning

Create configuration file

mkdir ~/.lightning
nano ~/.lightning/config
daemon
network=bitcoin
alias=ExtraPointsForMakingThisCreative
rgb=000000
bitcoin-rpcuser=lightning
bitcoin-rpcpassword=a11IIMZKndBeFBsGaFV81X-mwX14nIr8b0EN9ltuF7o=
  • network=testnet —use this instead of network=bitcoin, if you want to run the node on Bitcoin testnet instead;
  • log-level=debug — makes your node log a lot more information (useful to have this on when something goes wrong);
  • log-file=/home/lightning/.lightning/debug.log — moves your logs from syslog, to a file in c-lightning data directory.

Allow port on the router

sudo ufw allow 9735 comment 'c-lightning'

Should work now…

Additional Steps

Get your own IP

curl ipinfo.io/ip
203.150.176.91

Use the IP and port

announce-addr=203.150.176.91:9735
bind-addr=0.0.0.0:9735

Configure router

exit
whoami
pi
sudo apt install miniupnpc
mkdir ~/bin
nano ~/bin/set_ports.sh
#!/bin/shupnpc -e "c-lightning" -a $(ip route get 1 | awk '{print $NF;exit}') 9735 9735 TCP
chmod +x ~/bin/set_ports.sh
crontab -e
@reboot       /home/pi/bin/set_ports.sh
*/10 * * * * /home/pi/bin/set_ports.sh

Add Tor

If you want your node running on clearnet (IPv4/IPv6) only, and being discoverable, you can skip this whole section.

Authentication

sudo usermod -a -G debian-tor lightning
id lightning
uid=1002(lightning) gid=1002(lightning) groups=1002(lightning),113(debian-tor)

Choose

  • you want your node to be Tor v3 address only;
  • you want your node to be discoverable only as Tor v2, but also able to communicate over clearnet;
  • you want you node to be available through all possible networks;

Tor hidden services

sudo nano /etc/tor/torrc
HiddenServiceDir /var/lib/tor/ln-service-v3/
HiddenServiceVersion 3
HiddenServicePort 9737 127.0.0.1:9737
sudo systemctl restart tor@default
sudo cat /var/lib/tor/ln-service-v2/hostname
3fogovde3pptrkub.onion
sudo cat /var/lib/tor/ln-service-v3/hostname
6g3y7ahr5uxjzedgmu5etxtrc6hqmb2bl7kyipl3nzrcnyp64afrfwyd.onion

Add hidden services to c-lightning config

sudo su - lightning
nano ~/.lightning/config
announce-addr=3fogovde3pptrkub.onion
announce-addr=6g3y7ahr5uxjzedgmu5etxtrc6hqmb2bl7kyipl3nzrcnyp64afrfwyd.onion
proxy=127.0.0.1:9050
always-use-proxy=false
bind-addr=127.0.0.1:9737

Disable clearnet

always-use-proxy=true

Done

exit

Create lightningd service

sudo nano /etc/systemd/system/lightningd.service
[Unit]
Description=c-lightning Daemon
Requires=bitcoind.service
After=bitcoind.service

[Service]
ExecStart=/usr/local/bin/lightningd --pid-file=/home/lightning/.lightning/lightning.pid
PIDFile=/home/lightning/.lightning/lightning.pid
User=lightning
Type=forking
Restart=on-failure
# Hardening measures
####################
# Provide a private /tmp and /var/tmp.
PrivateTmp=true
# Mount /usr, /boot/ and /etc read-only for the process.
ProtectSystem=full
# Disallow the process and all of its children to gain
# new privileges through execve().
NoNewPrivileges=true
# Use a new /dev namespace only populated with API pseudo devices
# such as /dev/null, /dev/zero and /dev/random.
PrivateDevices=true
# Deny the creation of writable and executable memory mappings.
MemoryDenyWriteExecute=true
[Install]
WantedBy=multi-user.target
sudo systemctl enable lightningd
sudo systemctl start lightningd

Verify it’s up and running

sudo su - lightning
lightning-cli getinfo | jq
tail -n 100 -f ~/.lightning/debug.log
lightning-cli getinfo
listfunds
listconfigs
listpeers
listpayments
lightning-cli connect 032260c3b64b471b7eb0630b4af5d07ca94ff4e759573cbbe1bfb25845c375ed6e@o3s5j4j37nbyzgvbngn3ahpmttvviyensw34klhqzw7in7vfzz646lqd.onion:9735
03f156811eee5078add53d46ef9b00cf1ab9a1c43fc74d3db64312cb65815f3a99@6g3y7ahr5uxjzedgmu5etxtrc6hqmb2bl7kyipl3nzrcnyp64afrfwyd.onion:9735

Fund your node

Deposit coins

lightning-cli newaddr bech32
bc1qtuky38xfqja4e8yymvgj0m07ykrqvr68lhhfec
tb1qvr5y9da90eq95k64udh8q9hh5m0yuemt0k8kej

Open channels

  • open channels with nodes you transact with frequently, ex. Bitrefill, Blockstream, TorGuard VPN, etc…;
  • open channels with nodes that seem well connected. Ideally not the biggest ones on the network, but ones that are closest to nodes you might transact with;
  • open channels to at least 2–3 nodes, and make sure they are all in different partitions of the network;
  • open channels with other RBPs :) (this is my node, leave your connect strings in comments below along with a mainnet/testnet note).
lightning-cli fundchannel 032260c3b64b471b7eb0630b4af5d07ca94ff4e759573cbbe1bfb25845c375ed6e 100000

Use your node

  • While Bitcoin node can be offline while receiving a payment, LN one needs to be online and communicating;
  • While you can pay anyone on-chain whether they like it or not, on LN you need to obtain an invoice for each payment first;
  • While on-chain transactions can take up to 128 hours 39 minutes and 20 seconds to confirm, LN transactions are instant.

Decode Invoice

lnbc900u1pdnyugcpp59xh3dkm545rjserwtayjyvy7d59f3m4lgep6fk0m5s4xhju7fm5qdzhw35xjueqd9ejqctwyp5kuan0d93k2grrwfjkzar9vssxvmmjypjx2mt0deehgunpvd6xjmmwypc82unsdaek2ucxq97rplqcqp25faxg3gr9sxgd6x4d2jvxus8nmurw98qdkenfpsckv50ttsafqn3gayvrszd55sgsgrxc9tmq9m2czuyk4yh5f50lrepv3hq0z87klsq4xsnda
lnbc1m1
  • ln — this one just indicates it’s a Lightning Network invoice;
  • bc — indicates what currency the invoice is for (bc stands for Bitcoin, ltc for Litecoin, etc…);
  • 900u — is an encoded amount. To get a one that’s easier to understand, you need to separate number 900 from a multiplier u. In this case u stands for μ/micro, ergo 0.000001, so 900 * 0.000001 = 0.0009 BTC. All multipliers are regular metric prefixes, so: m: 0.001, u: 0.000001, n: 0.000000001, and p: 0.000000000001.
  • 1 — the last 1 in the HRP is just a separator, between HRP and machine stuff.
lnltc130299u1pdnymugpp56qq62vn34qf70f2he0d0smwycl92nnarwpuz94s29yk9wxh6lhaqdphgf5hgun9ve5kcmpqx43rxv3kvcurwctyxs6kgvesxqcrgdnxx9nxgeqcqzjqxqrpcg42vfd9eu5jysmzp758s4pxhqkln6hr0xevj2pcgnxuj9e0fza5ej9u5tjhm0vuny408y97qqy0gdvxnu69yz9zhdvrrstt56pfrljkspgd5wks
lightning-cli decodepay lnbc900u1pdnyugcpp59xh3dkm545rjserwtayjyvy7d59f3m4lgep6fk0m5s4xhju7fm5qdzhw35xjueqd9ejqctwyp5kuan0d93k2grrwfjkzar9vssxvmmjypjx2mt0deehgunpvd6xjmmwypc82unsdaek2ucxq97rplqcqp25faxg3gr9sxgd6x4d2jvxus8nmurw98qdkenfpsckv50ttsafqn3gayvrszd55sgsgrxc9tmq9m2czuyk4yh5f50lrepv3hq0z87klsq4xsnda | jq
{
"currency": "bc",
"timestamp": 1530032408,
"created_at": 1530032408,
"expiry": 31557600,
"payee": "032260c3b64b471b7eb0630b4af5d07ca94ff4e759573cbbe1bfb25845c375ed6e",
"msatoshi": 90000000,
"description": "this is an invoice created for demonstraction purposes",
"min_final_cltv_expiry": 10,
"payment_hash": "29af16db74ad0728646e5f4922309e6d0a98eebf4643a4d9fba42a6bcb9e4ee8",
"signature": "3045022100a27a6445032c0c86e8d56aa4c372079ef83714e06db3348618b328f5ae1d4827022014748c1c04da520882066c157b0176ac0b84b5497a268ff8f21646e0788feb7e"
}

Send transactions

lightning-cli pay lnbc900u1pdnyugcpp59xh3dkm545rjserwtayjyvy7d59f3m4lgep6fk0m5s4xhju7fm5qdzhw35xjueqd9ejqctwyp5kuan0d93k2grrwfjkzar9vssxvmmjypjx2mt0deehgunpvd6xjmmwypc82unsdaek2ucxq97rplqcqp25faxg3gr9sxgd6x4d2jvxus8nmurw98qdkenfpsckv50ttsafqn3gayvrszd55sgsgrxc9tmq9m2czuyk4yh5f50lrepv3hq0z87klsq4xsnda

Receive payments

lcli invoice 1000 "test-invoice" "For generating a test invoice" | jq
{
"payment_hash": "ce44137a5589f811eeb0ca0d0ae194f50aa2d83dba91707fcb1bede49f53f45a",
"expiry_time": 1530037058,
"expires_at": 1530037058,
"bolt11": "lnbc10n1pdnyafjpp5eezpx7j438uprm4segxs4cv575929kpah2ghql7tr0k7f86n73dqdp0gehhygr8v4hx2unpw35kueeqvys8getnwssxjmnkda5kxegcqp2u7mmum0enmlx24chsumdzgvfq565jve5mtf6lfsj2nagsup67uyqh0pch7ukadpxlymdt0ls6r4dh89syj8tsfvpahj8wcj026mejhgqy492cq"
}
lnbc10n1pdnyafjpp5eezpx7j438uprm4segxs4cv575929kpah2ghql7tr0k7f86n73dqdp0gehhygr8v4hx2unpw35kueeqvys8getnwssxjmnkda5kxegcqp2u7mmum0enmlx24chsumdzgvfq565jve5mtf6lfsj2nagsup67uyqh0pch7ukadpxlymdt0ls6r4dh89syj8tsfvpahj8wcj026mejhgqy492cq

All the rest

Other thingies

Make ssh welcome message pretty

wget -qO- https://gist.githubusercontent.com/meeDamian/0006c766340e0afd16936b13a0c7dbd8/raw/c9ebf744372325e8b5c42f271fb046a6eebcaf14/na%25C3%25AFve-rbp-btc.sh | sudo sh

Manual

/etc/etc/update-motd.d/
cd /etc/etc/update-motd.d/
chmod +x 10-uname 20-raspberry-bitcoin 26-raspberry-lightning 30-swap-warning
run-parts --lsbsysinit /etc/update-motd.d

Update c-lightning Node

sudo systemctl stop lightningdcd lightning
git fetch origin master
git checkout v0.6.1
./autogen.sh
make
sudo make install
sudo systemctl start lightningd

Where to get help or knowledge?

Mistakes? Improvements? Tips?

Edits

Other Guides…

  1. Litecoin Full Node on RBP3,
  2. (obsolete) Bitcoin Full Node (with or w/o BIP148 UASF 🙊) on RBP3,
  3. Bitcoin Full Node on RBP3 (revised),
  4. Bitcoin through Tor on RBP3,
  5. Lightning Network (c-lightning) on RBP3,
  6. Lightning Network (lnd) on RBP3.

--

--

--

Bitcoin. Lightning. Golang. Applied cryptography, not Blockchain. https://keybase.io/meedamian . PGP: D8CA 1776 EB92 6549 1D07 CE67 F546 ECBE A809 CB18

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Shade Protocol: What Is A Permit?

The First Year at Little Taller — Elise

Log4j/Log4Shell Vulnerability Scanning and Exploit Detection in Uptycs osquery

Rest in Go with Blue wheel, Uuuh

Stream Data Processing using Apache Beam

Kth Smallest Element in a Sorted Matrix

How to Learn Linux and Git

Summer of Technologies

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Damian Mee

Damian Mee

Bitcoin. Lightning. Golang. Applied cryptography, not Blockchain. https://keybase.io/meedamian . PGP: D8CA 1776 EB92 6549 1D07 CE67 F546 ECBE A809 CB18

More from Medium

EIP 0027 Soft Fork Proposal

ℓDEFI February Rebalancing

A simple explanation of the Lightning Network

Quantum Inevitability and it’s Blockchain & Cryptocurrency-Related Implications