0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Lightning Network Daemon(Lnd)で遊んでみた ~Installation編~

Last updated at Posted at 2019-10-25

はじめに

今回はLND Developer SiteInstallationを翻訳&要約。
基本的に書いてある通りにコマンド打っていればできるので、こっちみたほうがいいかも。
一応、Oshikawaメモを散らばらせておいた。

**追記:**こっち↓では翻訳ではなく実際に試した様子を記している。
Ubuntuでlndとbtcdの環境を構築してみる

見出し

  • インストール
  • 事前準備
  • lndのインストール
  • 利用可能なオペレーティングモード
  • btcd オプション
  • Neutrino オプション
  • Bitcoind オプション
  • btcdを使う
  • Neutrinoを使う
  • bitcoindかlitecoindを使う
  • Macaroons
  • Network Reachability
  • Simnet vs. Testnet Development
  • lnd.confを作る(オプション)

インストール

事前準備

lndを動かすには以下の依存環境が必要

  • Go: lndはGo言語で書かれている。インストールするには以下のコマンドを実行。

 備考:Goの最低必須バージョンはGo 1.11。我々はGoの最新バージョン(制作時は1.11だった)を使うことを勧めている。

☆ Oshikawaメモ:これを忘れていて、lndのBuildエラーが出まくって時間が食われた記憶があるので要注意。☆

Linuxの場合:
sudo apt-get install golang-1.11-go

Mac OS Xの場合:
brew install go

FreeBSDの場合:
pkg install go

☆ Oshikawaメ:Linuxユーザーは自分の環境に合ったインストール方法をググってインストールした方がいいかも。☆

あるいは、プレコンパイル済みのバイナリをGo言語ダウンロードページでダウンロードもできる。
ソースからインストールしたいなら、もっと詳細なインストール方法はここに書いてるよ。

この時点で、ワークスペースのパスを意味する$GOPATH環境変数を設定すべき。デフォルトでは、$GOPATH~/goに設定されている。$GOPATH/binにあなたのPATHを設定する必要がある。

export GOPATH=~/gocode
export PATH=$PATH:$GOPATH/bin

我々のオススメはターミナルを開くたびいちいち上のスクリプト書かなくていいために.bashrcかsetupスクリプトに置いくこと。


Oshikawaメモ:
要は、.bashrcに上のスクリプトをコピペしてsource /.bashrcすればいいってこと。

  • go_modules:依存関係の管理と再現性のあるビルドをするために、このプロジェクトはgo moduleを使う。

go moduleを使えば、$GOPATHにlndを追加する必要がなくなる。代わりに、lndリポジトリーがどこでも使えるようになる。

lndのインストール

事前準備が終わったら、lndとlncli、そのとの依存環境を以下のコマンドで実行しよう。

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

備考:我々のこのインストール手順では,前のGoのバージョンのディレクトリから$GOPATHを使たが、しかしgo 1.11ではlndはあなたのファイルシステムのどこからでも実行できるようになりました。

Windows WSLユーザーは/usr/bin/make/経由でmakeをするか、makeの周りにクオテーションマークをつけて、以下みたいにする。

/usr/bin/make && /usr/bin/make install

"make" && "make" install

FreeBSDでは、makeの代わりにgameを使う。
makeコマンドを使いたくないなら、代わりにgoコマンドをGO111MODULE=on go install -v ./...のディレクトリでつかえる。

アップデート

lndのバージョンをアップデートしたいなら、

cd $GOPATH/src/github.com/lightningnetwork/lnd
git pull
make clean && make && make install

FreeBSD,

cd $GOPATH/src/github.com/lightningnetwork/lnd
git pull
GO111MODULE=on go install -v ./...

テスト

lndが正しくインストールされているか確かめるには

make check

利用可能なオペレーティングモード

lndを実行できるようにするには、チェーンバックエンドを検証する必要がある。このdocumentを書いている時に、利用可能なバックエンドは:btcd, neutrino, bitcoindがある。neutrino以外のそれらすべてはメインネットでlndインスタンスから実行できる。bitcoindとbtcdでは--txindexを必要としないがtxindexをつけるとlndはつけたほうが早く実行できる。


Oshikawaメモ:
lndはbtcdを使うことをオススメしている。
でも最近btcdは数十ノードしか稼働してないらしい...
詳しくは、coin danceを参照。

btcd オプション

btcd:
      --btcd.dir=                       ノードのデータ、設定、ログなどを格納する基本ディレクトリ. 
                                       (default: /Users/roasbeef/Library/Application Support/Btcd)
      --btcd.rpchost=                                         The daemon's rpc listening address. If a port is omitted, then the default port for the selected chain parameters will be used. (default: localhost)
      --btcd.rpcuser=                                         Username for RPC connections
      --btcd.rpcpass=                                         Password for RPC connections
      --btcd.rpccert=                                         File containing the daemon's certificate file (default: /Users/roasbeef/Library/Application Support/Btcd/rpc.cert)
      --btcd.rawrpccert=                                      The raw bytes of the daemon's PEM-encoded certificate chain which will be used to authenticate the RPC connection

Neutrino オプション

neutrino:
  -a, --neutrino.addpeer=                                     Add a peer to connect with at startup
      --neutrino.connect=                                     Connect only to the specified peers at startup
      --neutrino.maxpeers=                                    Max number of inbound and outbound peers
      --neutrino.banduration=                                 How long to ban misbehaving peers.  Valid time units are {s, m, h}.  Minimum 1 second
      --neutrino.banthreshold=                                Maximum allowed ban score before disconnecting and banning misbehaving peers

Bitcoind オプション

bitcoind:
      --bitcoind.dir=                                         The base directory that contains the node's data, logs, configuration file, etc. (default: /Users/roasbeef/Library/Application Support/Bitcoin)
      --bitcoind.rpchost=                                     The daemon's rpc listening address. If a port is omitted, then the default port for the selected chain parameters will be used. (default: localhost)
      --bitcoind.rpcuser=                                     Username for RPC connections
      --bitcoind.rpcpass=                                     Password for RPC connections
      --bitcoind.zmqpubrawblock=                              The address listening for ZMQ connections to deliver raw block notifications
      --bitcoind.zmqpubrawtx=                                 The address listening for ZMQ connections to deliver raw transaction notifications

btcdを使う場合

btcdのインストール手順

FreeBSD,
Install btcd:
make btcd

それか、btcdのリポジトリからインストールできる。

btcdの起動

 以下のコマンドを実行すればrpc.certとデフォルトのbtcd.confを作ってくれる。

btcd --testnet --rpcuser=REPLACEME --rpcpass=REPLACEME

もしテストネットでlndを実行したいのなら、btcdでテストネットのフルノードを同期させる必要がある。PCによりけりだが、数時間かかる。Note that adding --txindex is optional, as it will take longer to sync the node, but then lnd will generally operate faster as it can hit the index directly, rather than scanning blocks or BIP 158 filters for relevant items.

btcdの同期をしている間、btcdのnetinfo RPCコマンドで進行状況を確認できる。

btcctl --testnet --rpcuser=REPLACEME --rpcpass=REPLACEME getinfo
{
  "version": 120000,
  "protocolversion": 70002,
  "blocks": 1114996,
  "timeoffset": 0,
  "connections": 7,
  "proxy": "",
  "difficulty": 422570.58270815,
  "testnet": true,
  "relayfee": 0.00001,
  "errors": ""
}

さらに、リアルタイムで同期の進行状況を見たいならbtcdのログを見ることができる。

getpeerinfoコマンドであなたのbtcdノードの接続性をみれる。

btcctl --testnet --rpcuser=REPLACEME --rpcpass=REPLACEME getpeerinfo | more

btcdのバックエンドでlndを動かす

テストネットにいるなら、btcdの同期が終わった後、以下のコマンドを実行しよう。それか、e --bitcoin.testnet--bitcoin.simnetに置きかえよう。

もしチュートリアルのためにlndを準備しているのなら、このステップはスキップしていい。

lnd --bitcoin.active --bitcoin.testnet --debuglevel=debug --btcd.rpcuser=kek --btcd.rpcpass=kek --externalip=X.X.X.X

Neutrinoを使う場合

軽量クライエントモードでlndを実行するためには、この新しい軽量クライエントモードを提供てきるフルノードに位置する必要がある。lndは軽量クライエントモードのためにBIP 157BIP 158を使う。

neutrinoモードで、lndを使う場合、lndを以下の通り実行しよう。

lnd --bitcoin.active --bitcoin.testnet --debuglevel=debug --bitcoin.node=neutrino --neutrino.connect=faucet.lightning.community

bitcoindかlitecoindを使う場合

bitcoindとlitecoindの設定はかなり似ている。

以下がlndで使うbitcoin.confのサンプル。

testnet=1
server=1
daemon=1
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28333

Macaroons

lndの認証システムはmacaroonsと呼ばれており、非中央集権的な資格情報の権限の委任や減衰、その他色々できる。詳しいことはAlex AkselrodのGithubで読める。

lndを初めて実行した時、lndの認証に使うためのlndadmin.macaroon, read_only.macaroo, macaroons.dbがデフォルトで作成される。
それらはネットワークディレクトリに保存される。(default: lnddir/data/chain/bitcoin/mainnet) そのため、ainnet, testnet, simnet, その他で異なるパスワードを使える。もし他のディレクトリをしていいしたいなら(--datadir経由で)、--macaroonpathを使ってlncliのadmin.macaroonに新しいパスを通さないといけない。

macaroonsをテスト用に使えなくするためには、lndとlncliに--no-macaroonsフラグをつける。

Network Reachability

もし新しいチャンネルを受け入れるために(peersはチャンネル開設のワークフロー初期化のためにinboundを繋ぐ必要があるので)他のノードにシグナルをつけるには、あなたのパブリックなIPアドレスに--externalipフラグをつけるべきだ。

Simnet vs. Testnet Development

もしチュートリアルなどでローカルの開発環境を使うなら、simnetモードでbtcdlndを使いたいはず。simnetはregtestとよく似ていてlndをローカルで試すためのBlockの採掘を即座に行える。--bitcoin.testnetの代わりに--bitcoin.simnetをつけると、デーモンを起動する時testnetの代わりにsimnetを使える。

lndの開発環境で使える他のローカルテスト用の関連コマンドラインフラグは--debughtlcがある。このコマンドと一緒にlndを起動すると、特別なHTLCが自動で設置できるようになる。これでマニュアルどうりの試験的な送金用のinvoiceを発行する必要がなくなる。この特別なHTLCタイプに送金するには、--debugsendコマンドをsendpaymentコマンドの最後につける必要がある。

現在、lndを起動するために、主要な2つの方法がある。まず、RPCサービスに晒されたローカルのbtcdインスタンスを使うこと。もう一つは、フルに統合されたneutrinoの軽量クライエントを使うことである。

lnd.confを作る(オプション)

lndの起動の間、永続的な設定を持ちたいなら、lnd --bitcoin.testnet --bitcoin.activeとコマンドラインで打てばいい。すると、lnd.confが作られる。

MacOS: /Users/[username]/Library/Application Support/Lnd/lnd.conf
Linux: ~/.lnd/lnd.conf

btcdを始めるためのlnd.confのサンプル。

[Application Options]
debuglevel=trace
maxpendingchannels=10

[Bitcoin]
bitcoin.active=1

[Bitcoin]の部分に注目してください。ここにBitcoinのパラメータを置きます。lndはLitecoinのtestnet4(BTCとLTCを同時にはできない)もサポートしている。Litecoinを使うときはLitecoinのパラメーターを設定してください。詳細なサンプルファイルはここで見れて他の[Btcd], [Bitcoind], [Neutrino], [Ltcd], [Litecoind]も探せます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?