メインコンテンツまでスキップ

NodeWatch のセットアップ

1. インストールディレクトリの作成

最初に、ソースコードを配置するディレクトリを作成し、移動します。

mkdir nodewatch-src
cd nodewatch-src

2. Python 3.11 のインストールと仮想環境の作成

pyenv を使用します。 pyenv のインストール方法は、pyenv インストールを参照してください。

Python 3.11 をインストールし、NodeWatch 用の仮想環境を作成します。

pyenv install 3.11
pyenv virtualenv 3.11 nw311
pyenv local nw311
pip install --upgrade pip

3. miscellaneous のクローン

NodeWatch の依存ツール「miscellaneous」をクローンし、必要なパッケージをインストールします。

本家は https://github.com/symbol/miscellaneous.git ですが、 そのままでは不具合があるため、修正版を使用します。

git clone https://github.com/ccHarvestasya/miscellaneous.git -b fix/add-timeout-parameter-for-nodewatch
cd miscellaneous
pip install -r requirements.txt
cd ..

4. NodeWatch のクローン

NodeWatch をクローンし、必要なパッケージをインストールします。

git clone https://github.com/ccHarvestasya/product.git -b explorer/nodewatch-finalized-block-field-names
cd product/explorer/nodewatch
pip install -r requirements.txt

必要なディレクトリも作成します。

mkdir -p puller/cert
mkdir -p resources

5. 証明書の作成

puller/certディレクトリに証明書を作成します。 詳細はSymbol ノード証明書を参照してください。

同じサーバーに Symbol ノードが同居する場合は、ノード証明書を流用してください。 異なる証明書を使用するとフォーク耐性が下がります。

6. メインネット

6.1. Symbol と NEM のノード情報取得(メインネット)

ノード情報を取得します。 puller/certディレクトリにいる場合は、ひとつ上の階層に移動します。

cd ..

そのままでも動作しますが、安定性向上のため最初に接続するノードリストを変更します。

network/symbol.yaml
friendly_name: symbol
ticker_name: symbol
currency_symbol: xym

accounts: []

nodes:
- host: wolf.importance.jp
- host: xymharvesting.net
- host: ahra-symbol.com
- host: harvest-01.symbol.farm
- host: symbol-main-1.nemtus.com
- host: xxx-welcome-to-a-powerful-node.com
- host: 00A06705.xym.stir-hosyu.com
network/nem.yaml
friendly_name: nem
ticker_name: nem
currency_symbol: xem

accounts: []

nodes:
- host: zombie.nem.monster
- host: cyan.siglight.xyz
- host: thrush.sixis.xyz
- host: chika03.kuzi.online
- host: node15.symbol-nem.net
- host: sqiqi13.seventys.site

デフォルトのタイムアウト時間だと時間がかかるため、--timeoutオプションを追加します。

pull.sh
#!/bin/bash

echo "$0: generating files in \"$1\" with timeout \"$2\""

echo "[$(date)] crawling Symbol network"

python3 -m network.nodes \
--resources ./networks/symbol.yaml \
--thread-count 64 \
--certs ./cert \
--output "$1/symbol_nodes.json" \
--timeout "$2"

echo "[$(date)] downloading Symbol richlist"

python3 -m network.richlist_symbol \
--resources ./networks/symbol.yaml \
--min-balance 250000 \
--nodes "$1/symbol_nodes.json" \
--output "$1/symbol_richlist.csv" \
--timeout "$2"

echo "[$(date)] downloading Symbol harvesters"

python3 -m network.harvester \
--resources ./networks/symbol.yaml \
--thread-count 64 \
--nodes "$1/symbol_nodes.json" \
--days 3.5 \
--output "$1/symbol_harvesters.csv" \
--timeout "$2"

echo "[$(date)] crawling NEM network"

python3 -m network.nodes \
--resources ./networks/nem.yaml \
--thread-count 64 \
--output "$1/nem_nodes.json" \
--timeout "$2"

echo "[$(date)] downloading NEM harvesters"

python3 -m network.harvester \
--resources ./networks/nem.yaml \
--thread-count 64 \
--nodes "$1/nem_nodes.json" \
--days 3.5 \
--output "$1/nem_harvesters.csv" \
--timeout "$2"

pull.shを使ってノード情報を取得します。

PYTHONPATH=../../../../miscellaneous ./pull.sh ../resources 3

同様にnodewatch_daily.shを使ってノード設置場所情報などを取得します。

PYTHONPATH=../../../../miscellaneous ./nodewatch_daily.sh ../resources

これらは定期的に実行する必要があります。 Cron に登録しておくことをおすすめします。

6.2. 設定ファイルの作成(メインネット)

pullerディレクトリにいる場合は、ひとつ上の階層に移動します。

cd ..

config.pyを作成します。

config.py
RESOURCES_PATH = "./resources"
SYMBOL_EXPLORER_ENDPOINT = "https://sakia.harvestasya.com:3001"
SYMBOL_GENERATION_HASH_SEED = "57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6"
NEM_EXPLORER_ENDPOINT = "http://eolia.nis1.harvestasya.com:7890"

7. テストネット

7.1. Symbol と NEM のノード情報取得(テストネット)

ノード情報を取得します。 puller/certディレクトリにいる場合は、ひとつ上の階層に移動します。

cd ..

テストネットを参照するよう、最初に接続するノードリストを変更します。

network/symbol.yaml
friendly_name: symbol
ticker_name: symbol
currency_symbol: xym
network: testnet

accounts: []

nodes:
- host: 001-sai-dual.symboltest.net
- host: 2.dusanjp.com
- host: sym-test-01.opening-line.jp
- host: t.sakia.harvestasya.com
- host: vmi831828.contaboserver.net
network/nem.yaml
friendly_name: nem
ticker_name: nem
currency_symbol: xem
network: testnet

accounts: []

nodes:
- host: libertalia.nemtest.net
- host: ntn1.dusanjp.com
- host: ocracoke.nemtest.net
- host: tortuga.nemtest.net

オプションに--network "testnet"を追加します。

pull.sh
#!/bin/bash

echo "$0: generating files in \"$1\" with timeout \"$2\""

echo "[$(date)] crawling Symbol network"

python3 -m network.nodes \
--resources ./networks/symbol.yaml \
--thread-count 64 \
--certs ./cert \
--output "$1/symbol_nodes.json" \
--timeout "$2" \
--network "testnet"

echo "[$(date)] downloading Symbol richlist"

python3 -m network.richlist_symbol \
--resources ./networks/symbol.yaml \
--min-balance 250000 \
--nodes "$1/symbol_nodes.json" \
--output "$1/symbol_richlist.csv" \
--timeout "$2" \
--mosaic-id "72C0212E67A08BCE"

echo "[$(date)] downloading Symbol harvesters"

python3 -m network.harvester \
--resources ./networks/symbol.yaml \
--thread-count 64 \
--nodes "$1/symbol_nodes.json" \
--days 3.5 \
--output "$1/symbol_harvesters.csv" \
--timeout "$2" \
--mosaic-id "72C0212E67A08BCE"

echo "[$(date)] crawling NEM network"

python3 -m network.nodes \
--resources ./networks/nem.yaml \
--thread-count 64 \
--output "$1/nem_nodes.json" \
--timeout "$2" \
--network "testnet"

echo "[$(date)] downloading NEM harvesters"

python3 -m network.harvester \
--resources ./networks/nem.yaml \
--thread-count 64 \
--nodes "$1/nem_nodes.json" \
--days 3.5 \
--output "$1/nem_harvesters.csv" \
--timeout "$2"

pull.shを使ってノード情報を取得します。

PYTHONPATH=../../../../miscellaneous ./pull.sh ../resources 3

同様にnodewatch_daily.shを使ってノード設置場所情報などを取得します。

PYTHONPATH=../../../../miscellaneous ./nodewatch_daily.sh ../resources

これらは定期的に実行する必要があります。 Cron に登録しておくことをおすすめします。

7.2. 設定ファイルの作成(テストネット)

pullerディレクトリにいる場合は、ひとつ上の階層に移動します。

cd ..

config.pyを作成します。

config.py
RESOURCES_PATH = "./resources"
SYMBOL_EXPLORER_ENDPOINT = "https://t.sakia.harvestasya.com:3001"
SYMBOL_GENERATION_HASH_SEED = "49D6E1CE276A85B70EAFE52349AACCA389302E7A9754BCF1221E79494FC665A4"
NEM_EXPLORER_ENDPOINT = "http://libertalia.nemtest.net:7890"
NETWORK_NAME = "testnet"
SYMBOL_VOTING_SET_GROUPING = 720

8. Gunicorn での起動

gunicornをインストールします。

pip install gunicorn

NodeWatch を起動します。

NODEWATCH_SETTINGS=../config.py gunicorn "nodewatch:create_app()"

9. サービス化

9.1. NodeWatch のサービス化

/etc/systemd/system/nodewatch.serviceを作成します。

/etc/systemd/system/nodewatch.service
[Unit]
Description=NodeWatch
After=network.target

[Service]
User=<USER>
Group=<GROUP>
WorkingDirectory=/home/<USER>/nodewatch-src/product/explorer/nodewatch
Environment="NODEWATCH_SETTINGS=../config.py"
ExecStart=/home/<USER>/.pyenv/versions/nw311/bin/gunicorn \
--bind 127.0.0.1:8000 \
"nodewatch:create_app()"
Restart=always

[Install]
WantedBy=multi-user.target

9.2. pull.sh のサービス化

/etc/systemd/system/nodewatch-puller.serviceを作成します。

/etc/systemd/system/nodewatch-puller.service
[Unit]
Description=Pull NodeWatch Data

[Service]
Type=oneshot
WorkingDirectory=/home/<USER>/nodewatch-src/product/explorer/nodewatch/puller
Environment="PATH=/home/<USER>/.pyenv/versions/nw311/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
Environment="PYTHONPATH=/home/<USER>/nodewatch-src/miscellaneous"
ExecStart=/home/<USER>/nodewatch-src/product/explorer/nodewatch/puller/pull.sh ../resources 3

前回の実行から 20 分以上経過している場合のみ実行するよう、/etc/systemd/system/nodewatch-puller.timerを作成します。

/etc/systemd/system/nodewatch-puller.timer
[Unit]
Description=Run pull-nodewatch every 20 minutes after last completion

[Timer]
OnUnitInactiveSec=20min
Persistent=true

[Service]
Restart=on-failure
RestartSec=20min

[Install]
WantedBy=timers.target

9.3. nodewatch_daily.sh のサービス化

/etc/systemd/system/pull-daily-nodewatch.serviceを作成します。

/etc/systemd/system/pull-daily-nodewatch.service
[Unit]
Description=Pull Daily NodeWatch Data

[Service]
Type=oneshot
WorkingDirectory=/home/<USER>/nodewatch-src/product/explorer/nodewatch/puller
Environment="PATH=/home/<USER>/.pyenv/versions/nw311/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
Environment="PYTHONPATH=/home/<USER>/nodewatch-src/miscellaneous"
ExecStart=/home/<USER>/nodewatch-src/product/explorer/nodewatch/puller/nodewatch_daily.sh ../resources

9.4. サービスの起動と有効化

サービスを起動し、有効化します。

sudo systemctl daemon-reload

sudo systemctl enable nodewatch
sudo systemctl start nodewatch
sudo systemctl status nodewatch

sudo systemctl enable pull-nodewatch.timer
sudo systemctl start pull-nodewatch.timer
sudo systemctl status pull-nodewatch.timer

sudo systemctl enable pull-daily-nodewatch.timer
sudo systemctl start pull-daily-nodewatch.timer
sudo systemctl status pull-daily-nodewatch.timer

次回のpull-nodewatch.timerの実行時間は、systemctl list-timersで確認できます。