bitcoindが起動しなくなった
まえおき
タイトル通りbitcoindが起動しなくなりました。正確にはターミナルから$bitcoind を打っても起動しなくなりました。
Lightning Network を触ってみようと思ってLNDをインストールしていたんですが、それでなんかやってしまったのではないかと思っています。しばらく悲しみに打ちひしがれて、解決策も全く出なくて死んでたのですが、なんとか治ったので記事にしました。同じようなエラーが出た人の助けになれば幸いです。
環境
PC:Mac
OS:Mojava 10.14.1
Bitcoin Core:0.17.0.1
状況
普通は $bitcoind で動くはずなのに、以下のエラーが出る。
$ bitcoind
dyld: Symbol not found: __ZN5boost6system15system_categoryEv
Referenced from: /usr/local/bin/bitcoind
Expected in: /usr/local/opt/boost/lib/libboost_system.dylib
in /usr/local/bin/bitcoind
Abort trap: 6
でも、Finderから直接起動するとちゃんと動く
GUIを起動した状態で bitcoin-cli をやっても同じエラーが出る。
dyld: Symbol not found: __ZN5boost6system16generic_categoryEv
Referenced from: /usr/local/bin/bitcoin-cli
Expected in: /usr/local/opt/boost/lib/libboost_system.dylib
Abort trap: 6
原因
リンクがうまくできていないらしい。でもなぜそうなったかはわからない(誰かわかりそうな人いたら教えてください)
解決策
以下を入力するだけ。
$ brew link --overwrite bitcoin
実行後、リンクがうまくされていればターミナルで bitcoind と入力すれば普通に起動した。
解決策までの道のり
調査①
とりあえずググるとこんなのが出てきました。
これだ!絶対これだ!!
どうも boost ってやつがインストール出来ていない、もしくはうまくいってないらしい。
$ brew install boost
このあと起動を心みるが、同じエラーが出る。試しに次もやってみる。
$ brew reinstall boost
これも同じくうまくいかない。一回消してもう一回やれば?みたいなのも書いてあるので試してみる。
$ brew uninstall --force boost
Error: Refusing to uninstall /usr/local/Cellar/boost/1.68.0
because it is required by bitcoin, which is currently installed.
You can override this and force removal with:
brew uninstall --ignore-dependencies boost
なんか拒否しているみたいなので、最後に出たコマンドを使って強制的にアンインストールしてみる。その後もう一度インストール。
$ brew uninstall --ignore-dependencies boost
$ brew install boost
で、もう一回 $bitcoind で起動してみる。
$ bitcoind
dyld: Symbol not found: __ZN5boost6system15system_categoryEv
Referenced from: /usr/local/bin/bitcoind
Expected in: /usr/local/opt/boost/lib/libboost_system.dylib
in /usr/local/bin/bitcoind
Abort trap: 6
はい、予想できてました。ありがとうございます。
下の方に行くと、同じように解決してない人がいる様子。その場合は
1. 正しいboostのバージョンをインストールしろよ。
2. bitcoindを再ビルドしろ
の二つが提案されている。
でもさっきboostの最新版インストールしちゃったし、これからバージョン下げるとか怖いし、やり方わからんし。。。
make は問題なく通るので、解決せず。少し深めのため息をしながら天を仰ぐ。
調査②
きっとPATHがうまく通ってないんだな、と思って探したら以下を発見。
これはboostというc++のライブラリが、bicoindのコンパイル時にうまくリンク出来てない為に発生します。otoolで確認するとやはりリンクがされてないようです。
stack overflow辺りを見ると色々と解決方法はあるのですが、個人的に採用している方法はbrewでboostを入れてconfigureでパスを指定する方法です。
。。。リンク?何それ?PATHと違うんか? 調べてもようわからん。変なことして再起不能になるのも怖いとか思いつつやってみる。
$ cd bitcoin
$ ./configure --with-boost-libdir=/usr/local/Cellar/boost/1.64.0_1/lib
checking build system type... x86_64-apple-darwin18.2.0
checking host system type... x86_64-apple-darwin18.2.0
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... build-aux/install-sh -c -d
checking whether the linker accepts -framework Foundation -framework ApplicationServices -framework AppKit... yes
checking whether to build Bitcoin Core GUI... yes (Qt5)
configure: error: --with-boost-libdir expected directory name
そんなディレクトリーねえぞとのこと。ですよね〜、と思いつつお布団にダイブ。
調査③
改めてmake checkしてみて確かめてみる。
$ make check
Making check in src
/Applications/Xcode.app/Contents/Developer/usr/bin/make check-TESTS check-local
PASS: qt/test/test_bitcoin-qt
============================================================================
Testsuite summary for Bitcoin Core 0.17.99
============================================================================
# TOTAL: 1
# PASS: 1
# SKIP: 0
# XFAIL: 0
# FAIL: 0
# XPASS: 0
# ERROR: 0
==========================================================
Running tests: arith_uint256_tests from test/arith_uint256_tests.cpp
Running tests: addrman_tests from test/addrman_tests.cpp
Running tests: amount_tests from test/amount_tests.cpp
Running tests: coinselector_tests from wallet/test/coinselector_tests.cpp
Running tests: init_tests from wallet/test/init_tests.cpp
Running test/util/bitcoin-util-test.py...
/usr/local/bin/python ../test/util/bitcoin-util-test.py
Traceback (most recent call last):
File "../test/util/bitcoin-util-test.py", line 180, in <module>
main()
File "../test/util/bitcoin-util-test.py", line 31, in main
config.read_file(open(os.path.join(os.path.dirname(__file__), "../config.ini"), encoding="utf8"))
AttributeError: ConfigParser instance has no attribute 'read_file'
make[3]: *** [check-local] Error 1
make[2]: *** [check-am] Error 2
make[1]: *** [check-recursive] Error 1
make: *** [check-recursive] Error 1
やっぱりエラーが出る。”read_fileがないよ!”とか書いてあるけど、別にいらんだろと思って無視。実際にググってもそれらしきものは見当たらないのでYouthubeとSNSを往復しながら自然治癒を願う。
調査④
こうなったら無理やり起動させてやるぜ!と思ってbitcoinのsrcまで行って起動させてみる。
$ cd ~/bitcoin/src
$ bitcoind
これで起動っと。
$ bitcoind
dyld: Symbol not found: __ZN5boost6system15system_categoryEv
Referenced from: /usr/local/bin/bitcoind
Expected in: /usr/local/opt/boost/lib/libboost_system.dylib
in /usr/local/bin/bitcoind
Abort trap: 6
!!!???なぜ!!?? まさかbitcoind自体がないのか?と思って見てみる。
$ ls | grep bitcoind
bitcoind
bitcoind-bitcoind.o
bitcoind-res.rc
bitcoind.cpp
。。。ある。じゃあなんで!!と思いながらそっとパソコンを閉じる。
調査⑤
そろそろ心が壊れ始めたので全部消してもう一回入れ直すことを決意。
。。。の前にダメ元でもう一回入れてみるか〜、と思ってやってみる。今回はbrewで入れてみる。というのも、実はこの前みたいにめんどくさいことをしなくても brew install bitcoin で一発で入れられることを最近知ったので、やってみる。
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
astrometry-net minica
==> Updated Formulae
armor davix fselect lcm pcl php@7.1
aws-es-proxy dcm2niix gmime logstash pdal pygobject3
cayley doctl jbig2dec mlt phoronix-test-suite swift
cockroach elasticsearch kubectx nghttp2 php@5.6
console_bridge epubcheck kubernetes-cli paket php@7.0
Warning: bitcoin 0.17.0_1 is already installed, it's just not linked
You can use `brew link bitcoin` to link this version.
ダメか〜。。。。ん?
Warning: bitcoin 0.17.0_1 is already installed, it's just not linked
You can use `brew link bitcoin` to link this version.
「すでにbitcoin0.17.0_1はあるぜ、リンク出来てないけどな。 brew link bitcoin でリンクできるぜ」
You can use `brew link bitcoin` to link this version.
これだ!!
Linking /usr/local/Cellar/bitcoin/0.17.0_1...
Error: Could not symlink bin/bench_bitcoin
Target /usr/local/bin/bench_bitcoin
already exists. You may want to remove it:
rm '/usr/local/bin/bench_bitcoin'
To force the link and overwrite all conflicting files:
To list all files that would be deleted:
brew link --overwrite --dry-run bitcoin
「強制的にリンクしてconfig filesを上書きするなら brew link --overwrite bitcoin
消去一覧も表示するなら brew link --overwrite --dry-run bitcoin」
ということらしい。(まちがってたらごめんね)まあ一覧出されてもわからんし、今回は brew link --overwrite bitcoinをやってみる。
$ brew link --overwrite bitcoin
Linking /usr/local/Cellar/bitcoin/0.17.0_1... 14 symlinks created
。。。できたのか? おそるおそる試してみる。
$ bitcoind
2018-11-27T15:18:15Z Bitcoin Core version v0.17.0.0-ge1ed37edaedc85b8c3468bd9a726046344036243 (release build)
2018-11-27T15:18:15Z InitParameterInteraction: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1
2018-11-27T15:18:15Z Warning: Config setting for -rpcport only applied on test ne
twork when in [test] section.
動いた!!!!!!感激(T ^ T)
まとめ
とりあえずリンクがちゃんとされていないと動かないんだなという事がわかりました。でもなんでこうなったんだろう(´Д` )
ちなみにboost、リンク、PATHがよくわかってないので、ここら辺もちゃんと勉強しなきゃなとしみじみ思いました。
// こういうのってどうやって覚えたり知るもんなんですかね。
参考資料
Cannot run bitcoind · Issue #11040 · bitcoin/bitcoin · GitHub