Cryptocurrency Research Lab.

Cryptocurrency関連技術についての調査・研究

【Reef】Reef chain① 開発ノード構築

PancakeSwapのSyrup Poolで知ることとなったReef、これから色々とはじまりそうな予感がしたので少しずつ調べてみることにしました。

docs.reef.finance

Reef chain

2021/03/31(水)にReef chainのTestnetが公開されるとのこと、『The First DeFi Blockchain on Substrate for DeFi Applications of the Future』と謳われており、PolkadotのParachainとして動作するEVM互換のDeFiプラットフォームを目指しているようです。

開発者向けのドキュメントに、『If you’re a developer, you can deploy your DeFi project on Reef』と書かれてあるように、DeFiプロジェクトをReef chain上に配置することができるようになるようです。

私自身はただの『新しいもの好き』にすぎないので、今のところReef chain上で何かするというわけでもありませんが、最近githubに公開されたのでWSL2のUbuntu 20.04上で手順を試してみることにしました。

新しい技術を学ぶときには、マニュアルを読んでみて、実際に動かしてみるのがよいですね。

github.com

1. Rustのインストール

Reef chainはRust言語で書かれていますので、rustインストールが必要です。

curl https://sh.rustup.rs -sSf | sh

~/.cargo/以下にインストールされます。環境変数PATHにrustcのパスが追加されるよう、ターミナルを起動しなおすとよいでしょう。

$ rustc --version
rustc 1.51.0 (2fd73fabe 2021-03-23)

2. LLVMのインストール

LLVMも必要のようですので、https://apt.llvm.org/を参考にインストールしておくとよいでしょう。

sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"

3. reef-chainのソース取得

reef-chainのソースをGithubから取得します。
submoduleとして orml というものが必要となるので、--recursiveオプションを付けて取得します。

$ git clone --recursive https://github.com/reef-defi/reef-chain
︙
Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@github.com:open-web3-stack/open-runtime-module-library.git' into submodule path '/home/<ユーザ名>/reef-chain/orml' failed
Failed to clone 'orml' a second time, aborting

自分の環境ではsubmoduleの取得に失敗してしまいましたので、以下のように設定を変えてみました。
(たぶんもっと良い方法はあるはずだけど、submoduleの扱いについてあまり分かっていないので・・・)

※4/2追記: 修正されたようですので、以下の手順は不要ですね。

$ vi .gitmodules 
        path = orml
        url = git@github.com:open-web3-stack/open-runtime-module-library.git
        url = https://github.com/open-web3-stack/open-runtime-module-library.git

.gitmodulesを修正した後に以下を実行しました。

$ git submodule sync
$ git submodule update
Cloning into '/home/<ユーザ名>/reef-chain/orml'...
Submodule path 'orml': checked out '266768bb90918aab25723ac70ddd93310b378cee'

4. 初期化

$ cd reef-chain/
$ make init

5. 開発ノード起動①

開発用のノードを起動します。

$ make eth
RUST_BACKTRACE=1 cargo run --manifest-path node/Cargo.toml --features with-ethereum-compatibility  -- --dev --tmp
︙
2021-03-28 18:48:09  Low open file descriptor limit configured for the process. Current value: 4096, recommended value: 10000.    
2021-03-28 18:48:09  Running in --dev mode, RPC CORS has been disabled.    
2021-03-28 18:48:09  Reef Substrate Node    
2021-03-28 18:48:09  ✌️  version 3.0.0-e68d73f-x86_64-linux-gnu    
2021-03-28 18:48:09  ❤️  by Reef Finance <https://reef.finance>, 2021-2021    
2021-03-28 18:48:09  📋 Chain specification: Development    
︙

一定間隔でブロックが生成されているように見えますね。

なお、開発向けのシングルノード構成でプロセスを止めるとブロックチェーンは廃棄されるようです。

6. 開発ノード起動②: チェーン永続化

開発向けのシングルノード構成にてブロックチェーンを永続化させたい場合には、以下の方法で実行するとよいとのことです。

$ make build
$ ./target/release/reef-node --dev
2021-03-28 19:50:26  Low open file descriptor limit configured for the process. Current value: 4096, recommended value: 10000.    
2021-03-28 19:50:26  Running in --dev mode, RPC CORS has been disabled.    
2021-03-28 19:50:26  Reef Substrate Node    
2021-03-28 19:50:26  ✌️  version 3.0.0-e68d73f-x86_64-linux-gnu    
2021-03-28 19:50:26  ❤️  by Reef Finance <https://reef.finance>, 2021-2021    
2021-03-28 19:50:26  📋 Chain specification: Development    
︙

また、ブロックチェーンを破棄する場合には以下を実行します。

$ ./target/release/reef-node purge-chain --dev
Are you sure to remove "/home/<ユーザ名>/.local/share/reef-node/chains/dev/db"? [y/N]: y
"/home/<ユーザ名>/.local/share/reef-node/chains/dev/db" removed.

今日はここまで。