[ Intro ] - [ Jail Creation ] - [ Bitcoin ] - [ Tor & i2p ] - [ Electrum ] - [lnd] - [ loopd ] - [ RTL ] - [ mempool ] - [ Extras ]
Join the chatroom on the matrix chat protocol: #truenasnode:nym.im
If not already there, SSH into your freenas box as root, then switch to your bitcoin jail:
root@freenas[~] # iocage console bitcoin
Check LND's github repo for the latest release, make sure you select the correct binaries for your processor and operating system. (amd64 is for amd and intel processors)
# pkg install wget ca_root_nss
# cd ~
# wget https://github.com/lightningnetwork/lnd/releases/download/v0.15.5-beta/lnd-freebsd-amd64-v0.15.5-beta.tar.gz
# tar -xvf lnd-freebsd-amd64*
# install -m 0755 -o root -g wheel ~/lnd-freebsd-amd64*/* /usr/local/bin
# rm -r /lnd-freebsd-amd64* lnd-freebsd-amd64*
Read up on configuration options here.
Edit your lnd config file with command nano /usr/local/etc/lnd.conf
:
[Application Options]
lnddir=/var/db/lnd
alias=insert_something_catchy_here
listen=localhost
restlisten=127.0.0.1:8080
rpclisten=127.0.0.1:10009
tlsextraip=0.0.0.0
minchansize=900000
maxlogfiles=1
maxlogfilesize=10
accept-keysend=true
accept-amp=true
protocol.wumbo-channels=1
[Bitcoin]
bitcoin.active=1
bitcoin.mainnet=1
bitcoin.node=bitcoind
bitcoin.basefee=1000
bitcoin.feerate=100
bitcoin.timelockdelta=40
[Bitcoind]
bitcoind.dir=/var/db/bitcoin
[tor]
tor.active=true
tor.socks=localhost:9050
tor.dns=nodes.lightning.directory
tor.control=localhost:9051
tor.v3=1
Save (CTRL+O, ENTER) and exit (CTRL+X)
This configuration uses tor for the benefit of a static address, NAT traversal, and to prevent doxing your home IP address. Don't tell the world "this house has bitcoins!"! If you want to run on clearnet and advertise your home IP address, check out the Extras page to set up nat=true
in a secure fashion.
Fees. You may have to pay fees to other nodes when you rebalance channels, and you may have to close and reopen channels to disconected nodes, which will require on-chain fees. Don't operate at a loss! Do NOT make a 0 fee node, this will leave you vulnerable to denial of service attacks!
bitcoin.basefee=1000
= Fee of 1 satoshi per payment forwarded
bitcoin.feerate=100
= Fee of 100 satoshis per million forwarded (0.01% fee)
Save (CTRL+O), then exit (CTRL+X)
Start lnd
:
# pw adduser lnd -d /nonexistent -s /usr/sbin/nologin
# pw usermod lnd -G lnd,_tor,bitcoin
# mkdir /var/db/lnd && chown lnd:lnd /var/db/lnd && chmod -R 700 /var/db/lnd
# su -m lnd -c 'lnd --configfile=/usr/local/etc/lnd.conf'
If it works, you should see the following message:
Attempting automatic RPC configuration to bitcoind
Automatically obtained bitcoind's RPC credentials
2019-02-07 22:00:34.994 [INF] LTND: Version: 0.5.2-beta commit=v0.5.2-beta, build=production, logging=default
2019-02-07 22:00:34.994 [INF] LTND: Active chain: Bitcoin (network=mainnet)
2019-02-07 22:00:35.013 [INF] CHDB: Checking for schema update: latest_version=7, db_version=7
2019-02-07 22:00:35.054 [INF] RPCS: password gRPC proxy started at [::]:8080
2019-02-07 22:00:35.054 [INF] RPCS: password RPC server listening on 127.0.0.1:10009
2019-02-07 22:00:35.054 [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.
Open another SSH terminal window, log into to your TrueNAS server, and switch to your bitcoin jail. We will use lncli
to create a wallet and store the recovery key.
# lncli -lnddir "/var/db/lnd" create
Follow the prompt to create a wallet. Pick a strong wallet password. Write down your 24 word seed on paper, and store it somewhere safe!
We are done with this terminal, close it.
In your other terminal window, lnd
will begin its sync. Once the sync is complete, you will see a bunch of "New channel disocvered" nessages, exit lnd
(CTRL+C).
We will again use daemon to run our lnd
process at bootup, and restart the process should it fail.
Lets make the rc.d script. Edit the script with nano /usr/local/etc/rc.d/lnd
:
#!/bin/sh
#
# PROVIDE: lnd
# REQUIRE: bitcoind tor
# KEYWORD: shutdown
. /etc/rc.subr
name="lnd"
rcvar="lnd_enable"
lnd_user="lnd"
start_cmd="lnd_start"
status_cmd="lnd_status"
stop_cmd="lnd_stop"
stop_postcmd="lnd_wait"
command="/usr/local/bin/lnd"
daemon_command="/usr/sbin/daemon"
pidfile="/var/run/${name}.pid"
load_rc_config $name
: ${lnd_enable:=no}
: ${lnd_config_file:="/usr/local/etc/lnd.conf"}
# set up dependant variables
procname="${command}"
required_files="${lnd_config_file}"
lnd_status()
{
local pid
pid=$(check_pidfile "${pidfile}" "${procname}")
if [ -z "${pid}" ]
then
echo "LND is not running"
return 1
else
echo "LND running, pid: ${pid}"
fi
}
lnd_start()
{
echo "Starting lnd:"
${daemon_command} -u "${lnd_user}" -p "${pidfile}" -f \
${command} \
--configfile="${lnd_config_file}"
}
lnd_stop()
{
echo "Stopping LND:"
pid=$(check_pidfile "${pidfile}" "${procname}")
if [ -z "${pid}" ]
then
echo "LND is not running"
return 1
else
kill ${pid}
fi
}
lnd_wait()
{
local n=60
echo "Waiting for LND shutdown:"
while :
do
printf '.'
pid=$(check_pidfile "${pidfile}" "${procname}")
if [ -z "${pid}" ]
then
printf '\n'
break
fi
sleep 1
n=$((${n} - 1))
if [ ${n} -eq 0 -a -f "${pidfile}" ]
then
printf "\nForce shutdown"
kill -9 $(cat "${pidfile}")
for n in 1 2 3
do
printf '.'
sleep 1
done
printf '\n'
break
fi
done
rm -f "${pidfile}"
echo "Shutdown complete"
}
run_rc_command "$1"
Save (CTRL+O,ENTER) and exit (CTRL+X)
Make the startup script executable:
# chmod +x /usr/local/etc/rc.d/lnd
Enable our service with nano /etc/rc.conf
and append the following line:
lnd_enable="YES"
Save, (CTRL+O,ENTER) then exit (CTRL+O)
Lets verify lnd auto boots on startup:
# exit
root@freenas[~]# iocage restart bitcoin
root@freenas[~]# iocage console bitcoin
# ps aux
Note: Any time lnd
reboots, you will need to unlock the wallet again.
# lncli -lnddir "/var/db/lnd" unlock
Type in the password to unlock your wallet. This is a security function in case someone steals your server! In the next guide, you will install a web user interface called RTL
, which makes unlocking your wallet much easier.
Read the release notes, if a lot changed, you may have to close channels or do something to prepare for the upgrade!
# service lnd stop
# cd ~
# wget https://github.com/lightningnetwork/lnd/releases/download/v0.15.5-beta/lnd-freebsd-amd64-v0.15.5-beta.tar.gz
# tar -xvf lnd-freebsd-amd64*
# install -m 0755 -o root -g wheel ~/lnd-freebsd-amd64*/* /usr/local/bin
# rm -r /lnd-freebsd-amd64* lnd-freebsd-amd64*
# service lnd start && tail -f /var/db/lnd/logs/bitcoin/mainnet/lnd.log
Unlock lnd with RTL. Watch the logs to make sure that the database migration is sucessful with the following command:
tail -f /var/db/lnd/logs/bitcoin/mainnet/lnd.log
Next: { Install Lightning Lab's Loop client ]