LND を立ててみよう with bitcoind on Mac


はじめに

Lightning Network のデーモンの実装である lnd を立てるチュートリアルです。某connpass のイベントで、建てられなかった人が多かったということで、需要があると思い書いた次第。
lnd は、btcd という Go 製のフルノードを使うことを想定して作られていますが、bitcoind も使えますし、macOSならインストールも簡単です。ほとんど迷いなく建てられると思います。今回は testnet です。

bitcoind のインストール

コマンド一発です。

$ brew install bitcoin

bitcoind ではないことに注意。

bitcoind の設定と同期

bitcoind の設定ファイルを書きます。Mac の場合は ~/Library/Application Support/Bitcoin/bitcoin.conf にあります。

bitcoin.conf
testnet=3
txindex=1
daemon=1

server=1
rest=1

rpcuser=REPLACEME
rpcpassword=REPLACEME
rpcport=18332

zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28333

minrelaytxfee=0.00000000
incrementalrelayfee=0.00000010

設定を書いたら起動します。

$ bitcoind

すると同期が始まります。同期の様子は、

$ tail -f ~/Library/Application\ Support/Bitcoin/testnet3/debug.log

などで見ることができます。また、 $ bitcoin-cli getblockcount でいくつブロックが同期されたが確認できます。

全ブロック同期までには数時間かかりますが、たしかすべての同期を待たずして lnd を建てられた気がします。

lnd のインストール

go言語のインストール

$ brew install go

簡単だなあ。

次に、 $GOPATH というものを設定します。どこでもいいのですが、今回はホームディレクトリに設定しましょう。

$ cd && mkdir go

PATHを通します。

~/.bashrc
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
$ source ~/.bashrc

lnd を github から clone してビルド

$ go get -d github.com/lightningnetwork/lnd
$ cd $GOPATH/src/github.com/lightningnetwork/lnd
$ make && make install

ビルドが終了したら、立ち上げてみます。

lnd --bitcoin.active --bitcoin.testnet --debuglevel=debug --bitcoin.node=bitcoind --bitcoind.rpcuser=REPLACEME --bitcoind.rpcpass=REPLACEME --bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332 --bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333

すると画面に文字が流れ、ウォレットを unlock するか create しろと言われます。はじめなのでもちろん create します。

$ lncli create

適当にパスワードを入力したら終了です!

lnd と会話してみる

lnd の情報を見てみるコマンド

$ lncli getinfo

peer を確認して孤独を癒やすコマンド

$ lncli listpeers

peer につないだり、チャネルを張ったり、送金したりする手順は他の記事に譲ります。

簡単に lnd を立ち上げる

bitcoind と同様に、 ~/Library/Application\ Support/Lnd/lnd.conf に設定を書くことができます。

[Application Options]
debuglevel=debug
maxpendingchannels=10
MinChanSize=20000
maxlogfiles=0
maxlogfilesize=10

[Bitcoin]
bitcoin.active=1
bitcoin.testnet=1
bitcoin.node=bitcoind

[Bitcoind]
bitcoind.rpcuser=REPLACE
bitcoind.rpcpass=REPLACE
bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332
bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333

[Autopilot]
; autopilot.active=1
; The maximum number of channels that should be created.
; autopilot.maxchannels=5
; The percentage of total funds that should be committed to automatic channel
; establishment
; autopilot.allocation=0.6

こんな感じです。 lnd.conf を書くと、煩わしいオプションを指定する必要がなくなり、

$ lnd

だけで lnd が立ち上げられます。