Advertisement
Guest User

Untitled

a guest
Jun 17th, 2018
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.66 KB | None | 0 0
  1. This is a step-by-step technical guide on how to setup [LND](https://github.com/lightningnetwork/lnd) with Autopilot in Bitcoin Testnet. Security and Backup sections are a consideration for the future - they can be skipped because Testnet does not involve real funds.
  2.  
  3. Once you have LND running, read manitanance procedures in [OTHER.md](https://github.com/alevchuk/pstm/blob/master/lnd-e2e-testing/OTHER.md)
  4.  
  5. Table of contents
  6. =================
  7.  
  8. * [System Requirements](#system-requirements)
  9. * [Security](#security)
  10. * [Backups](#backups)
  11. * [Ergonomics](#ergonomics)
  12. * [Build Go](#build-go)
  13. * [Build LND](#build-lnd)
  14. * [Build BTCD](#build-btcd)
  15. * [Configure BTCD](#configure-btcd)
  16. * [Start BTCD - takes 1 to 4 days](#start-btcd)
  17. * [Configure LND](#configure-lnd)
  18. * [Start LND](#start-lnd)
  19. * [Fund your LND wallet and enable AutoPilot](#fund-your-lnd-wallet-and-enable-autopilot)
  20. * [Enable incoming channels](#enable-incoming-channels)
  21.  
  22. # System Requirements
  23.  
  24. Read https://bitcoin.org/en/full-node#minimum-requirements for Bitcoin blockchain requirements.
  25.  
  26. You need 4 GB of RAM because LND can get memory hungry at times. Yet currently my LND process runs with 1.3 GB virtual memory (of which 600 MB is in RSS).
  27.  
  28. For testnet the disk usage will be 8x smaller than the 145 GB mainnet recommendation:
  29.  
  30. du -sch ~/*
  31. ...
  32. 1.2M /home/lightning/.btcd/logs
  33. 16M /home/lightning/.lnd/logs
  34. ...
  35. 2.G /home/lightning/.lnd/data
  36. 15G /home/lightning/.btcd/data
  37.  
  38. 18G total
  39.  
  40.  
  41. # Security
  42.  
  43. 0. Use hardware that you control (e.g. laptop) and trust. E.g. I don't trust Intel's proprietary firmare because of the [known flaws in their remote administration features](https://www.wired.com/story/intel-management-engine-vulnerabilities-pcs-servers-iot/). A good start would be hardware that is certified by Free Software Foundation: https://www.fsf.org/resources/hw/endorsement/respects-your-freedom because the firmware is open source and can be audited.
  44.  
  45. 1. When setting up your laptop, make firewall _Drop all_ Incoming Connections _before_ connecting to the network. Later you may need to open 1 port for Lightning (see [Enable incoming channels](#enable-incoming-channels))
  46.  
  47. ```
  48. echo ":INPUT DROP
  49. :FORWARD DROP
  50. :OUTPUT ACCEPT
  51. -A INPUT -i lo -j ACCEPT
  52. -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
  53. -A OUTPUT -o lo -j ACCEPT" | iptables-restore
  54. ```
  55.  
  56. Persist firewall across reboots:
  57.  
  58. apt-get install iptables-persistent
  59. iptables-save # show current rules
  60. # Copy rules to /etc/iptables/
  61. # Reboot to test persistence
  62.  
  63. 2. Run system updates regularly
  64.  
  65. ```
  66. apt-get install aptitude
  67. sudo aptitude
  68. # press "/" to search for packages
  69. # press "+" to select a package for installing
  70. # press "-" to de-select
  71. # press Enter to read more able the package, "q" to go back
  72. # press "u" to refresh cache
  73. # press "U" to select all available upgrades
  74. # press "g" to review changes before installing
  75. # press "g" again to install/upgrade
  76. ```
  77.  
  78. 3. Track changes to your filesystem. This can come in handy when you get paranoid (e.g. what changed after laptop update or reboot?)
  79.  
  80. E.g. you can use [alevchuk/pstm/fs-time-machine method](../fs-time-machine) of tracking fs changes:
  81. ```
  82. cd /
  83. curl https://raw.githubusercontent.com/alevchuk/pstm/master/fs-time-machine/fs-gitignore > /.gitignore
  84. curl https://raw.githubusercontent.com/alevchuk/pstm/master/fs-time-machine/fs-metadata-get.sh > /.fs-metadata-get.sh
  85. chmod +x /.fs-metadata-get.sh
  86. git init
  87.  
  88. /.fs-metadata-get.sh && git add --all / && git commit -a -m 'LND Notes about SegWit addresses'
  89. ```
  90.  
  91. 4. Make unix account for lightning
  92. ```
  93. adduser lightning
  94. ```
  95.  
  96. # Backups
  97.  
  98. Backup /.git to an external drive
  99.  
  100. df -h
  101. mkdir /mnt/orig/
  102. mount /dev/sdb1 /mnt/orig/
  103. rsync -a --delete /.git/ /mnt/orig/home/backup/.git/
  104. umount /mnt/orig
  105.  
  106.  
  107. # Ergonomics
  108.  
  109. Configure ~/.screenrc so it lables tabs, has good scrollback history, and always shows what host your on, e.g. Laptop, AWS, Google Cloud, ... (I setup addtition nodes in the clouds for temorary experiments. Yet, the dedicated laptop node is the only one I'd trust)
  110.  
  111. escape ^Bb
  112. defscrollback 60000
  113. maptimeout 0
  114. defhstatus 'amazon'
  115. hardstatus alwayslastline '%{= G}[ %{G} %h %{g} ][%= %{= w}%?%-Lw%?%{= B}%n*%f %t%?%{= B}(%u)%?%{= w}%+Lw%?%= %{= g}][%{B} %Y %{g}]'
  116.  
  117. Use your "desktop" account to sudo into root and lightning as needed
  118.  
  119. screen
  120.  
  121. sudo su # screen tab for root
  122. sudo su -l lightning # new tab
  123.  
  124.  
  125. # Build Go
  126.  
  127. This is based on https://golang.org/doc/install/source
  128.  
  129. 1. Fetch bootstrap go
  130.  
  131. ```
  132. apt-get install golang-1.6
  133. ```
  134.  
  135. 2. Set bootstrap path and gopath. To ~/.bashrc add:
  136.  
  137. ```
  138. export GOOS=linux
  139. export GOARCH=amd64
  140. export GOROOT_BOOTSTRAP=/usr/lib/go-1.6
  141.  
  142. export GOROOT=/home/lightning/src/go
  143. export GOPATH=~/gocode
  144. export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
  145. ```
  146.  
  147. 3. Fetch new go
  148. ```
  149. mkdir ~/src
  150. cd ~/src
  151. git clone https://go.googlesource.com/go
  152. cd go
  153. git fetch
  154. git checkout go1.10.2
  155. ```
  156.  
  157. 4. Build new go
  158. ```
  159. . ~/.bashrc
  160. cd ~/src/go/src
  161. ./make.bash
  162. ```
  163. At the end it should say "Installed commands in /home/lightning/src/go/bin"
  164.  
  165.  
  166. # Build LND
  167.  
  168. This is based on https://github.com/lightningnetwork/lnd/blob/master/docs/INSTALL.md
  169.  
  170. 1. Fetch LND, build it, and install binaries
  171.  
  172. ```
  173. . ~/.bashrc
  174. go get -d github.com/lightningnetwork/lnd
  175.  
  176. cd ~/gocode/src/github.com/lightningnetwork/lnd
  177. git checkout master
  178. git pull
  179. make && make install
  180. ```
  181.  
  182. 2. Run unit tests
  183. ```
  184. make check
  185. ```
  186.  
  187. # Build BTCD
  188.  
  189. rm -rf $GOPATH/src/github.com/Masterminds/glide
  190. go get -u github.com/Masterminds/glide
  191.  
  192. git clone https://github.com/roasbeef/btcd $GOPATH/src/github.com/roasbeef/btcd
  193. cd $GOPATH/src/github.com/roasbeef/btcd
  194. glide install
  195. go install . ./cmd/...
  196.  
  197. # Configure BTCD
  198.  
  199. 1. Copy the official config sample https://github.com/Roasbeef/btcd/blob/master/sample-btcd.conf
  200. ```
  201. curl https://raw.githubusercontent.com/Roasbeef/btcd/master/sample-btcd.conf > ~/.btcd/sample-btcd.conf
  202. ```
  203.  
  204. 2. Find, uncomment (remove ";") and set the following config option
  205. ```
  206. testnet=1
  207. rpcuser=
  208. rpcpass=
  209. ```
  210. 3. Generate some random values for `rpcuser=` and `rpcpass=`
  211.  
  212. 4. Place the config:
  213. ```
  214. diff ~/.btcd/sample-btcd.conf ~/.btcd/btcd.conf
  215. cp ~/.btcd/sample-btcd.conf ~/.btcd/btcd.conf
  216. ```
  217.  
  218.  
  219. # Start BTCD
  220.  
  221. Run:
  222.  
  223. ```
  224. btcd
  225.  
  226. # It will take several days to replicate and verify the blockchain:
  227. # Laptop (Taurinus, 3.9G RAM): 2 days
  228. # Amazon AWS (t2.micro, 0.9G RAM): 4 days
  229. # Google VM (Intel N1, 1 VCPU, 3.7G RAM): 1 day
  230. ```
  231.  
  232. # Configure LND
  233.  
  234. 1. Copy the official config sample https://github.com/lightningnetwork/lnd/blob/master/sample-lnd.conf
  235. ```
  236. curl https://raw.githubusercontent.com/lightningnetwork/lnd/master/sample-lnd.conf > ~/.lnd/sample-lnd.conf
  237. ```
  238.  
  239. 2. Find and change the following config options in ~/.lnd/sample-lnd.conf
  240. ```
  241. debuglevel=ATPL=debug,CRTR=warn
  242. bitcoin.simnet=0
  243. bitcoin.testnet=1
  244.  
  245. autopilot.active=1
  246. autopilot.maxchannels=5
  247. autopilot.allocation=1.0
  248. ```
  249.  
  250. 3. Place the config
  251. ```
  252. diff ~/.lnd/sample-lnd.conf ~/.lnd/lnd.conf
  253. cp ~/.lnd/sample-lnd.conf ~/.lnd/lnd.conf
  254. ```
  255.  
  256. # Start LND
  257. 1. Bash completion for lncli, which was contributed to LND by [Andreas M. Antonopoulos](https://github.com/lightningnetwork/lnd/commits/master/contrib/lncli.bash-completion)
  258.  
  259. ```
  260. cp /home/lightning/src/go/src/github.com/lightningnetwork/lnd/contrib/lncli.bash-completion /etc/bash_completion.d/lncli
  261. # in Debian install "bash-completion" and uncomment "enable bash completion" in /etc/bash.bashrc
  262. ```
  263.  
  264. 2. Run
  265.  
  266. ```
  267. lnd
  268. ```
  269.  
  270.  
  271.  
  272. 3. Create a wallet
  273.  
  274. ```
  275. lncli create
  276. ```
  277.  
  278. # Fund your LND wallet and enable AutoPilot
  279.  
  280. 1. Get some free testing bitcoin
  281.  
  282. ```
  283. lncli newaddress np2wkh # Nested SegWit address
  284. ```
  285.  
  286. Paste the address into https://testnet.coinfaucet.eu/en/, get txn link, wait for 6 confirmations.
  287.  
  288. ```
  289. lncli walletbalance # will show unconfirmed balance within a few seconds, and confirmed in 2 hours
  290. ```
  291.  
  292. 2. Enable autopilot by commenting out the last 3 properties in lnd.conf
  293. 3. Restart LND
  294. 4. Then check activity in 1 hour:
  295.  
  296. ```
  297. lncli walletbalance
  298. lncli channelbalance
  299. lncli listchannels | grep active | sort | uniq -c # number of open channels
  300. lncli listpeers | grep inbound | uniq -c # to be a relay you'll need to get inbound peers
  301. ```
  302.  
  303. 5. Keep track of your total balance:
  304.  
  305. Use [get_balance_report.py script](get_balance_report.py)
  306. ```
  307. curl https://raw.githubusercontent.com/alevchuk/pstm/master/lnd-e2e-testing/get_balance_report.py > ~/get_balance_report.py
  308. chmod +x ~/get_balance_report.py
  309. ~/get_balance_report.py
  310. ```
  311.  
  312. As channels open and close you may see total balance go down but should it recover eventually.
  313.  
  314. # Enable incoming channels
  315.  
  316. To get incoming channels you'll need allow incoming connections on port 9735:
  317.  
  318. 1. Open port in iptabels rules (don't froget to persit in /etc/...)
  319.  
  320. ```
  321. iptables -I INPUT -p tcp --dport 9735 -j ACCEPT
  322. ```
  323.  
  324. 2. Configure your home router to do port forwarding
  325.  
  326. 3. Start LND with your external IP specified:
  327.  
  328. ```
  329. lnd --externalip=$(dig +short myip.opendns.com @resolver1.opendns.com)
  330.  
  331. # On Debian, to get dig, you'll need to install the "dnsutils" package
  332. ```
  333.  
  334. 4. Test with netcat from a different host
  335.  
  336. ```
  337. echo hi | nc <external_ip_of_LND_host> 9735
  338. ```
  339.  
  340. lnc logs will show
  341.  
  342. 2018-01-08 20:41:07.856 [ERR] CMGR: Can't accept connection: unexpected EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement