SPRTS(Sprouts)コインのWalletをUbuntu 16.04でビルドする(daemon編)
以前の記事ではUbuntuでSproutsコインのGUI付きのビルド方法を書きましたが、VPSで常時稼働するのにGUIは邪魔なだけです。
daemonとしてビルドする、ほぼ正式(?)なやり方がわかったので記事に書いておきます。
GCEでUbuntu 16.04のインスタンスを作成
Ubuntu 16.04のイメージで
- vCPU:1個
- メモリ:1GB
- SSD:20GB
で作成しています。
1 か月あたりの推定使用料金は $20.02 くらい。 単純比較できませんが、さくらのVPSの方がお得ですね。 SproutsはPoWではなくPoSなので、CPUリソースをあまり使いません。 一番安いプランでも十分です。 vps.sakura.ad.jp
今回はGCEでインスタンスを作っちゃったのでそのままいきます。
前準備
ここのビルド手順の通りにやると上手く行きません。(もう3年以上前の手順) github.com
まず以下のパッケージをインストールします。
sudo apt-get install build-essential sudo apt-get install libssl-dev sudo apt-get install libboost-all-dev sudo apt-get install libqrencode-dev sudo apt-get install libminiupnpc-dev
手順にはlibdb4.8-devとlibdb4.8++-devもインストールしろと書いてありますが、そのままだと以下のようなエラーが出ます。
sudo apt-get install libdb4.8-dev :中略 Package libdb4.8-dev is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Package 'libdb4.8-dev' has no installation candidate
以下のようにbitcoinのリポジトリを追加してからだとうまくいきます。
sudo add-apt-repository ppa:bitcoin/bitcoin sudo apt-get update sudo apt-get install libdb4.8-dev libdb4.8++-dev
Sprouts Walletのビルド
sproutsのリポジトリを取ってきます。
git clone https://github.com/gjhiggins/sprouts.git
終わったら、ディレクトリを移動してビルド
cd ~/sprouts/src make -f makefile.unix
と思ったら途中でメモリ不足のエラーが出てしまいました。
virtual memory exhausted: Cannot allocate memory makefile.unix:128: recipe for target 'obj/bitcoinrpc.o' failed make: *** [obj/bitcoinrpc.o] Error 1
ちょっとメモリをケチりすぎたようです。でも運用費が変わるのでベースは少ない方が良い。 そこで、swapファイルを導入して回避します。
※メモリが2GBあればビルドできると思うので、以下の手順はメモリ不足のエラーが出た時に試してください。
メモリ不足の場合の対処
以下のようにしてswapファイルを作って適用します。
sudo dd if=/dev/zero of=/var/swap/swap bs=1M count=1024 sudo chmod 600 /var/swap/swap sudo mkswap /var/swap/swap sudo swapon /var/swap/swap
正常に適用できたか確認するには以下のようにします。 ※適用できていない時はswapファイル名が出ません。
$ sudo cat /proc/swaps Filename Type Size Used Priority /var/swap/swap file 1048572 53504 -1
また、再起動してもswapを有効にしたい場合はfstabを書き換えます。
sudo vi /etc/fstab
でfstabを開き、最終行に、
/var/swap/swap swap swap defaults 0 0
を追加して保存します。 swapが多すぎてゲシュタルト崩壊しそうですね。
正常にビルドできたら
最後の行に
g++ -pthread -Wall -Wextra -Wno-sign-compare -Wno-invalid-offsetof -Wno-unused-parameter -Wformat -Wformat-security -g -DBOOST_SPIRIT_THREADSAFE -DUSE_IPV6 -I/home/develop/sprouts/src -I/home/develop/sprouts/src/obj -DUSE_UPNP=0 - DHAVE_BUILD_INFO -fno-stack-protector -fstack-protector-all -Wstack-protector -Wl,-z,relro -Wl,-z,now -D_FORTIFY_SO URCE=2 -O2 -rdynamic -o sproutsd obj/version.o obj/checkpoints.o obj/netbase.o obj/addrman.o obj/crypter.o obj/key. o obj/db.o obj/init.o obj/irc.o obj/keystore.o obj/main.o obj/net.o obj/protocol.o obj/kernelrecord.o obj/bitcoinrp c.o obj/rpcdump.o obj/script.o obj/util.o obj/wallet.o obj/walletdb.o obj/noui.o obj/kernel.o -Wl,-Bdynamic -l bo ost_system -l boost_filesystem -l boost_program_options -l boost_thread -l db_cxx -l ssl -l crypto -l rt -l miniupn pc -Wl,-Bdynamic -l z -l dl -l pthread
となど出ていたらビルドが完了しています。
今回はswapファイルを使ったのと、しょぼい環境のため10分近くかかりました。
real 9m34.293s user 2m38.799s sys 0m10.539s
上手くビルドができていれば、カレントディレクトリに
sproutsd
が生成されているはずです。
walletのデーモンを起動するには
./sproutsd -daemon
で起動できます。 しかし、
Sprouts server starting Error: To use the "-daemon" option, you must set a rpcpassword in the configuration file: /home/develop/.sprouts/sprouts.conf It is recommended you use the following random password: rpcuser=bitcoinrpc rpcpassword=91bxR62uShfrRvPWvaeia4ZHTW5DjBnghM9oMJNMLFJ5 (you do not need to remember this password) If the file does not exist, create it with owner-readable-only file permissions.
のようなエラーが出ます。
daemonとのやり取りが、jsonrpcなのでそれ用のuserとpasswordを設定してやる必要があります。
~/.sprouts
以下にsprouts.conf
ファイルを作成してrcpuserとrpcpasswordを設定しておきます。
vi ~/.sprouts/sprouts.conf ※先頭あたりに入れる rpcuser=jibundekangaetausername rpcpassword=jibundekangaetapassword
上手くいけば以下のように表示されるはずです。
./sproutsd -daemon
Sprouts server starting
ポートについて
GCPのVPS ネットワーク設定で9901のポートを開放した構成を作成します。
ターゲットタグをsprouts
にしておきます。
GCEのインスタンスを編集して、ネットワークタグにsprouts
を入力して保存。
ノードについて
sprouts.confにノードを書いておく必要があります。
ログから、最近繋がった実績のあるノードをsprouts.conf
に入れて置いたものを以下で配布しています。
sprouts.conf - Google ドライブ
bootstrapについて
日本から参照しにくかったので、公式が配布していたbootstrapをGoogleDriveに上げ直しました。 Sprouts_Bootstrap_2017-10-12.zip - Google ドライブ
これを解凍して、sproutsのdaemonを停止した状態で、~/.sprouts/
以下に中身を上書きしてください。
sproutsdを止めるには
./sproutsd stop
で止まります。
walletのコマンドについて
./sproutsd help addmultisigaddress <nrequired> <'["key","key"]'> [account] backupwallet <destination> checkwallet createmultisig nrequired ["key",...] createrawtransaction [{"txid":txid,"vout":n},...] {address:amount,...} decoderawtransaction <hex string> dumpprivkey <peercoinaddress> encryptwallet <passphrase> getaccount <peercoinaddress> getaccountaddress <account> getaddressesbyaccount <account> getbalance [account] [minconf=1] getblock <hash> [txinfo] [txdetails] getblockcount getblockhash <index> getblocktemplate [params] getcheckpoint getconnectioncount getdifficulty getgenerate gethashespersec getinfo getmininginfo getnetworkghps getnewaddress [account] getpeerinfo getrawmempool getrawtransaction <txid> [verbose=0] getreceivedbyaccount <account> [minconf=1] getreceivedbyaddress <peercoinaddress> [minconf=1] gettransaction <txid> gettxout "txid" n ( includemempool ) getwork [data] help [command] importprivkey <peercoinprivkey> [label] keypoolrefill listaccounts [minconf=1] listminting [count=-1] [from=0] listreceivedbyaccount [minconf=1] [includeempty=false] listreceivedbyaddress [minconf=1] [includeempty=false] listsinceblock [blockhash] [target-confirmations] listtransactions [account] [count=10] [from=0] listunspent [minconf=1] [maxconf=9999999] ["address",...] makekeypair [prefix] move <fromaccount> <toaccount> <amount> [minconf=1] [comment] repairwallet reservebalance [<reserve> [amount]] sendalert <message> <privatekey> <minver> <maxver> <priority> <id> [cancelupto] sendfrom <fromaccount> <topeercoinaddress> <amount> [minconf=1] [comment] [comment-to] sendmany <fromaccount> {address:amount,...} [minconf=1] [comment] sendrawtransaction <hex string> [checkinputs=0] sendtoaddress <peercoinaddress> <amount> [comment] [comment-to] setaccount <peercoinaddress> <account> setgenerate <generate> [genproclimit] settxfee <amount> signmessage <peercoinaddress> <message> signrawtransaction <hex string> [{"txid":txid,"vout":n,"scriptPubKey":hex},...] [<privatekey1>,...] [sighashtype="ALL"] stop submitblock <hex data> [optional-params-obj] validateaddress <peercoinaddress> verifymessage <peercoinaddress> <signature> <message>
で確認できます。
まず必要なのはWalletへの入金アドレスを知ることでしょう。 初回起動時にアドレスが作成されているので、 getaddressesbyaccountで入金用のアドレスが確認できます。 引数が""なのはデフォルトのアカウント名が空だからです。
$ ./sproutsd getaddressesbyaccount "" [ "実際のアドレス" ]
その後に使うのは、getinfo
とlistminting
でしょう。
- getinfo
- 現在の残高やその他の情報が確認できます。
- listminting
- PoS鋳造の状態を確認することができます。
外部に送信するにはsendfrom
コマンドです。
sendfrom "" <topeercoinaddress> <amount>
で送信できます。
ここまで書いておいて何ですが、walletのコマンド操作を誤ると、セルフGOXする可能性が非常に高いので、覚悟を持って慎重に使用しましょう。