DEV Community

sot528
sot528

Posted on • Edited on

4 2

EC2にEthereumメインネットのparityノードを立てる

AWSのEC2インスタンスにメインネットのparityのノード(light client mode)を構築して開発に使用する手順を記載する。
最短で構築するために意識は低くマネコンから作業。以下のビデオを参考にする。

インスタンスを立てる

ビデオを参考に以下の設定を行ったインスタンスを立てる。

  • AMI: Canonical, Ubuntu, 16.04 LTS, amd64 xenial image build on 2017-11-21
  • ポート解放: 8545
  • ストレージ容量確保: 20GB

parityをインストール

ビデオを参考にSSH接続してparityをインストール。

  • bash <(curl https://get.parity.io -kL)

parityを起動

ここはビデオと異なり、--lightオプションを付加してlight client modeとする。

  • parity --jsonrpc-hosts all --jsonrpc-interface all --light

クライアントから接続して同期状態を確認

ビデオを参考にインスタンスのipを取得し、以下のようなスクリプト(getBlockNumber.js)を記載(xx.xx.xx.xxは取得したipに書き換え)

W3 = require('web3')
web3 = new W3(new W3.providers.HttpProvider('http://xx.xx.xx.xx:8545'))
web3.eth.getBlockNumber().then(result => {console.log(result)})
Enter fullscreen mode Exit fullscreen mode
  • 実行

    node getBlockNumber.js
    
  • 以下のようにブロックナンバーが出力されれば同期が成功し、進行している。

    308485
    
  • 最新のブロックがいくつかはethstatsをチェック。2018/02時点で500万ブロックくらい。

    • light client modeでも完全同期まで数日かかる。

parityが途中で落ちる場合はデーモン化する

parityをlight client modeで動かしているとしばらく同期したあとで落ちる場合がある。
その場合はデーモン化すると良い。supervisorを使用してデーモン化する手順をまとめる。

  1. supervisorをインストール

    sudo apt-get update
    sudo apt-get install supervisor
    sudo mkdir /var/log/supervisor/jobs    
    
  2. 以下のような設定ファイルを /etc/supervisor/conf.d/ 以下にparity.confとして配置。

    [program:Parity]
    command=/usr/bin/parity --jsonrpc-hosts all --jsonrpc-interface all --light
    user=root
    autorestart=true
    stdout_logfile=/var/log/supervisor/jobs/parity.log
    stdout_logfile_maxbytes=1MB
    stdout_logfile_backups=5
    stdout_capture_maxbytes=1MB
    redirect_stderr=true
    
  3. supervisorを起動

    sudo supervisord
    sudo supervisorctl start all
    
  4. ログを確認しparityが同期を開始していればOK。

    tail -f /var/log/supervisor/jobs/parity.log
    
  • 落ちても再度立ち上がる。

  • ちゃんとやるならsupervisor自体をサービス化しておく(割愛)。

備考

  • Parity: v1.9.0-beta
  • 2018/02現在、上記手順で最新のブロックまで同期できることを確認(数日かかる)。
  • gethでも良いが、parityはまだ多少安定している印象。しかしフルノード(非light client mode)だと完全に同期するまで何週間も待つ場合がある。
  • light client modeはまだ実験段階なので本番運用は要注意。

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay