kharukaのブログ~お金と技術とキャリア~

Edu Fin~金融×教育~若いうちからお金について学ぶってだいじ!学んだテクノロジーはみんなの財産。過去、現在、将来の人生についてのブログ

はじめてのCounterpartyノード構築Part5(2019年1月20日執筆)

エンジニアスクールFLOC

ビットコインとブロックチェーン

ビットコインとブロックチェーン

▼前回の記事はこちらです。

はじめてのCounterpartyノード構築Part4(2019年1月20日執筆) - kharukaのブログ~お金と技術とキャリア~

環境情報

OS

OS バージョン 備考
macOS Mojava 10.14.2 ホストOS
Oracle VM VirtualBox 5.2.24
Ubuntu 18.04.1LTS ゲストOS

Node.js

Node.js バージョン 備考
npm 6.4.1
node v8.15.0

環境構築

▼環境構築の仕方はこちらなどをご参考に。

kharuka2016.hatenablog.com

counterparty-serverのインストール

counterparty-libのインストール

cd work
git clone https://github.com/CounterpartyXCP/counterparty-lib.git
cd counterparty-lib
sudo apt install -y python3-pip
sudo pip3 install --upgrade -r requirements.txt
sudo python3 setup.py install
cd

counterparty-cliのインストール

cd work
git clone https://github.com/CounterpartyXCP/counterparty-cli.git
cd counterparty-cli
sudo pip3 install --upgrade -r requirements.txt
sudo python3 setup.py install
cd

server.confファイル修正

sudo vi .config/counterparty/server.conf

server.conf

[Default]
backend-name = indexd
backend-user = <RPCUSER>
backend-password = <RPCPASSWORD>
indexd-connect = localhost
indexd-port = 18432
rpc-host = 0.0.0.0
rpc-user = <CPRPCUSER>
rpc-password = <CPRPCPASSWORD>
testnet = 1

client.confファイル修正

sudo vi .config/counterparty/client.conf

client.conf

[Default]
wallet-name = bitcoincore
wallet-connect = localhost
wallet-user = <RPCUSER>
wallet-password = <RPCPASSWORD>
counterparty-rpc-connect = localhost
counterparty-rpc-user = <CPRPCUSER>
counterparty-rpc-password = <CPRPCPASSWORD>
testnet = 1

confファイルのアクセス権限を変更します。

sudo chown -R kharuka:kharuka /home/kharuka/.config/counterparty/

counterparty-serverデーモンの起動

counterparty-server bootstrap
counterparty-server start &

ブロック同期確認

Block: 1442892の次のブロックで何故かエラーが発生してしまう。

それとも別の理由でエラーが発生しているのか?

testnet の XCHAIN ( counterparty explorer ) で探してもそんなブロック存在せーへん。

惜しい。

[2019-01-20 08:26:57][INFO] Block: 1442892 (0.16s, hashes: L:c3e66 / TX:0aa90 / M:1d6d9)
[2019-01-20 08:26:57][ERROR] Unhandled Exception
Traceback (most recent call last):
  File "/usr/local/bin/counterparty-server", line 11, in <module>
    load_entry_point('counterparty-cli==1.1.4', 'console_scripts', 'counterparty-server')()
  File "/usr/local/lib/python3.6/dist-packages/counterpartycli/__init__.py", line 16, in server_main
    server.main()
  File "/usr/local/lib/python3.6/dist-packages/counterpartycli/server.py", line 164, in main
    server.start_all(db)
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/server.py", line 466, in start_all
    blocks.follow(db)
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/blocks.py", line 1261, in follow
    block_count = backend.getblockcount()
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/backend/__init__.py", line 42, in getblockcount
    return BACKEND().getblockcount()
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/backend/indexd.py", line 148, in getblockcount
    return rpc('getblockcount', [])
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/backend/indexd.py", line 87, in rpc
    return rpc_call(payload)
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/backend/indexd.py", line 59, in rpc_call
    response_json = response.json()
  File "/usr/local/lib/python3.6/dist-packages/requests-2.10.0-py3.6.egg/requests/models.py", line 812, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

もう一度counterparty-server start &をはしらせたら、ブロック同期再開???

エラー再発。泣

[2019-01-20 08:52:57][INFO] Block: 1446988 (0.31s, hashes: L:a0bb2 / TX:e40a1 / M:355c8)
[2019-01-20 08:52:57][ERROR] Unhandled Exception
Traceback (most recent call last):
  File "/usr/local/bin/counterparty-server", line 11, in <module>
    load_entry_point('counterparty-cli==1.1.4', 'console_scripts', 'counterparty-server')()
  File "/usr/local/lib/python3.6/dist-packages/counterpartycli/__init__.py", line 16, in server_main
    server.main()
  File "/usr/local/lib/python3.6/dist-packages/counterpartycli/server.py", line 164, in main
    server.start_all(db)
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/server.py", line 466, in start_all
    blocks.follow(db)
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/blocks.py", line 1214, in follow
    block_hash = backend.getblockhash(current_index)
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/backend/__init__.py", line 45, in getblockhash
    return BACKEND().getblockhash(blockcount)
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/backend/indexd.py", line 151, in getblockhash
    return rpc('getblockhash', [blockcount])
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/backend/indexd.py", line 87, in rpc
    return rpc_call(payload)
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/backend/indexd.py", line 59, in rpc_call
    response_json = response.json()
  File "/usr/local/lib/python3.6/dist-packages/requests-2.10.0-py3.6.egg/requests/models.py", line 812, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

もう一度counterparty-server start &をはしらせる。

おぉー、同期完了!

[2019-01-20 09:18:09][INFO] Ready for queries.

結果オーライですが、しっくりこない感じですね。

counterparty-clientの動作確認

$ counterparty-client getinfo
[2019-01-20 09:52:24][INFO] Running v1.1.4 of counterparty-client.
Unhandled Exception
Traceback (most recent call last):
  File "/usr/local/bin/counterparty-client", line 11, in <module>
    load_entry_point('counterparty-cli==1.1.4', 'console_scripts', 'counterparty-client')()
  File "/usr/local/lib/python3.6/dist-packages/counterpartycli/__init__.py", line 12, in client_main
    client.main()
  File "/usr/local/lib/python3.6/dist-packages/counterpartycli/client.py", line 251, in main
    view = console.get_view(args.action, args)
  File "/usr/local/lib/python3.6/dist-packages/counterpartycli/console.py", line 16, in get_view
    return util.api('get_running_info')
  File "/usr/local/lib/python3.6/dist-packages/counterpartycli/util.py", line 92, in api
    return rpc(config.COUNTERPARTY_RPC, method, params=params, ssl_verify=config.COUNTERPARTY_RPC_SSL_VERIFY)
  File "/usr/local/lib/python3.6/dist-packages/counterpartycli/util.py", line 82, in rpc
    raise RPCError(str(response.status_code) + ' ' + response.reason + ' ' + response.text)
counterpartycli.util.RPCError: 503 SERVICE UNAVAILABLE {"code": -32000, "message": "Server error", "data": "Indexd is running 729748 blocks behind."}

これはあかんやつや。。。

$ counterparty-client wallet
[2019-01-20 09:49:30][INFO] Running v1.1.4 of counterparty-client.
TOTAL
+-------+---------+
| Asset | Balance |
+-------+---------+
+-------+---------+

こっちは動くの何でやねん?

counterparty-serverたびたび落ちる。。。

[2019-01-20 14:45:09][INFO] Block: 1453242 (0.27s, hashes: L:1e618 / TX:2eea4 / M:d3718)
[2019-01-20 14:49:07][ERROR] Unhandled Exception
Traceback (most recent call last):
  File "/usr/local/bin/counterparty-server", line 11, in <module>
    load_entry_point('counterparty-cli==1.1.4', 'console_scripts', 'counterparty-server')()
  File "/usr/local/lib/python3.6/dist-packages/counterpartycli/__init__.py", line 16, in server_main
    server.main()
  File "/usr/local/lib/python3.6/dist-packages/counterpartycli/server.py", line 164, in main
    server.start_all(db)
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/server.py", line 466, in start_all
    blocks.follow(db)
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/blocks.py", line 1156, in follow
    block_count = backend.getblockcount()
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/backend/__init__.py", line 42, in getblockcount
    return BACKEND().getblockcount()
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/backend/indexd.py", line 148, in getblockcount
    return rpc('getblockcount', [])
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/backend/indexd.py", line 87, in rpc
    return rpc_call(payload)
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/backend/indexd.py", line 59, in rpc_call
    response_json = response.json()
  File "/usr/local/lib/python3.6/dist-packages/requests-2.10.0-py3.6.egg/requests/models.py", line 812, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

再度ブロッック同期完了直後にもcounterparty-serverが落ちる。

[2019-01-20 16:36:34][INFO] Block: 1453255 (0.51s, hashes: L:6c796 / TX:067db / M:5d665)
[2019-01-20 16:36:34][INFO] Mempool cache initialized: 0.13s for 93 transactions
[2019-01-20 16:36:34][INFO] Ready for queries.
[2019-01-20 16:39:08][ERROR] Unhandled Exception
Traceback (most recent call last):
  File "/usr/local/bin/counterparty-server", line 11, in <module>
    load_entry_point('counterparty-cli==1.1.4', 'console_scripts', 'counterparty-server')()
  File "/usr/local/lib/python3.6/dist-packages/counterpartycli/__init__.py", line 16, in server_main
    server.main()
  File "/usr/local/lib/python3.6/dist-packages/counterpartycli/server.py", line 164, in main
    server.start_all(db)
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/server.py", line 466, in start_all
    blocks.follow(db)
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/blocks.py", line 1156, in follow
    block_count = backend.getblockcount()
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/backend/__init__.py", line 42, in getblockcount
    return BACKEND().getblockcount()
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/backend/indexd.py", line 148, in getblockcount
    return rpc('getblockcount', [])
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/backend/indexd.py", line 87, in rpc
    return rpc_call(payload)
  File "/usr/local/lib/python3.6/dist-packages/counterparty_lib-9.56.0-py3.6.egg/counterpartylib/lib/backend/indexd.py", line 59, in rpc_call
    response_json = response.json()
  File "/usr/local/lib/python3.6/dist-packages/requests-2.10.0-py3.6.egg/requests/models.py", line 812, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

おやおや?

pm2 restart indexでindexd-serverを再起動したら

ブロッック同期完了直後にcounterparty-serverが落ちることは少なくなった。

この子メンテナンスがかなり大変そうやな。。。

そしてgetinfoも動きました。

$ counterparty-client getinfo
[2019-01-20 17:04:03][INFO] Running v1.1.4 of counterparty-client.
{
    "api_limit_rows": 1000,
    "bitcoin_block_count": 1453260,
    "db_caught_up": true,
    "indexd_blocks_behind": 0,
    "indexd_caught_up": true,
    "last_block": {
        "block_hash": "000000000000011228b6f1041285d29c3107c2f8d5bb95f154873a4a62a9dd5b",
        "block_index": 1453260,
        "block_time": 1547970957,
        "difficulty": 13279725.231716892,
        "ledger_hash": "79ea0acfa0e9efa52d03953ab668fd8b7250a63887175a10a3e81c393a358efe",
        "messages_hash": "afb3610118851e0aa8e8f01fca7371623ae1e1e2a163f5079c2038a2d4ba507d",
        "previous_block_hash": "0000000000000113313817965bea29f72f71fc981a3b02e57b6c0f6d1b92eea9",
        "txlist_hash": "b045d795f47809cb9a84d32264154313dc4c3ffe8509c5810d1e49d4f48eb616"
    },
    "last_message_index": 73906,
    "running_regtest": false,
    "running_testcoin": false,
    "running_testnet": true,
    "server_ready": true,
    "version_major": 9,
    "version_minor": 56,
    "version_revision": 0
}

getinfo時のエラーログ最終行に答えがそのまま書いてありましたね。

(省略)
counterpartycli.util.RPCError: 503 SERVICE UNAVAILABLE {"code": -32000, "message": "Server error", "data": "Indexd is running 729748 blocks behind."}

"data": "Indexd is running 729748 blocks behind."とある様に

indexd-serverのブロック同期(address index)がcounterparty-serverのブロック同期に追いついていないだけでした。

とりあえず、めでたしめでたし!

▼記事の続きは以下へ。

執筆中です。

仮想通貨取引所・販売所

  • bitbank

https://bitcoinbank.co.jp

https://bitflyer.com/ex/sp/home

【BITPoint】ビットコイン・イーサリアムなど仮想通貨の口座開設ならビットポイント

https://coincheck.com/ja/

https://bitcoin.dmm.com

フィスコ仮想通貨取引所 口座開設プロモーション

  • Liquid by Quoine

https://ja.quoinex.com

  • SBI Virtual Currencies

https://www.sbivc.co.jp

https://zaif.jp/?lang=ja

ハードウェアウォレット

  • Ledger Nano S

  • トレザー

ソフトウェアウォレット

  • Ginco

Ginco - 安心・安全の仮想通貨ウォレット

参考

ビットコインとブロックチェーン

ビットコインとブロックチェーン