1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

1年目エンジニアがHyperledger-Fabricのサンプルを触ってみた!(ネットワーク設定編1)

Last updated at Posted at 2019-01-18

はじめに

文系出身エンジニアです。1年目です。

Blockchainに携わることとなり、とりあえずHyperledgerのサンプルアプリでも動かしてみようか、という次第でこの記事を書いてます。
ただの作業ログだと思って見てください。

こちらの記事は、以下の記事の続編です。
1年目エンジニアがHyperledger-Fabricのサンプルを触ってみた!(準備編)

以下のチュートリアルに沿って、fabric-sampleの中のfirst-networkというサンプルを用いて、ブロックチェーンネットワークの設定を行います。
Building Your First Network

環境

  • ホストOS:MacOS(v10.13.6)

  • ゲストOS:VirtualBox(v5.2.22)上に構築したUbuntu(v16.04.5)

  • Hyperledger Fabric v1.4.0

  • Docker 18.09.1

  • Docker Compose 1.8.0

  • go1.6.2

  • Python 2.7.12

  • Node.js v10.15.0

  • npm 6.5.0

ネットワーク

ダウンロードしたサンプル集(fabric-samples)の、first-networkというサンプルを使います。

$ cd fabric-samples/first-network

ネットワークの作成

byfn.shと名付けられたシェルスクリプトを使用します。
以下の5つのモードを指定して動かすことができます。

モード 行われること
up ネットワークとコンテナを立ち上げる
restart ネットワークとコンテナを停止・削除する
down ネットワークを再起動する
generate 証明書とgenesis blockを生成する
upgrade ネットワークをv1.0.xからv1.1にアップグレードする

では、ネットワークを作りましょう。

$ ./byfn.sh generate

実行すると、以下のものが生成されます。

  • crypto-configディレクトリ
    ->全エンティティの証明書等が格納されています

  • channel-artifacts/genesis.block
    ->ブロックチェーンの先頭のブロックです

  • channel-artifacts/channel.tx
    ->チャネルの設定を行うためのトランザクションファイル

ネットワーク立ち上げ

作成したネットワークを立ち上げます。少し時間がかかります。

$ ./byfn.sh up
Starting for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
LOCAL_VERSION=1.4.0
DOCKER_IMAGE_VERSION=1.4.0
Creating network "net_byfn" with the default driver
Creating volume "net_peer0.org2.example.com" with default driver
Creating volume "net_peer1.org2.example.com" with default driver
Creating volume "net_peer1.org1.example.com" with default driver
Creating volume "net_peer0.org1.example.com" with default driver
Creating volume "net_orderer.example.com" with default driver
Creating peer0.org2.example.com
Creating orderer.example.com
Creating peer1.org1.example.com
Creating peer0.org1.example.com
Creating peer1.org2.example.com
Creating cli

 ____    _____      _      ____    _____
/ ___|  |_   _|    / \    |  _ \  |_   _|
\___ \    | |     / _ \   | |_) |   | |
 ___) |   | |    / ___ \  |  _ <    | |
|____/    |_|   /_/   \_\ |_| \_\   |_|

(省略)
========= All GOOD, BYFN execution completed ===========


 _____   _   _   ____
| ____| | \ | | |  _ \
|  _|   |  \| | | | | |
| |___  | |\  | | |_| |
|_____| |_| \_| |____/

ネットワークの停止

ネットワークを停止させましょう。

$ ./byfn.sh down
Stopping for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
Stopping cli ... done

(省略)

Removing cli ... done

(省略)

Deleted: sha256:dd95fda39cd5033e743deaf30ab698ff095403dbafc4316a4fa0e57c5d727e75

(省略)

暗号化ツール

cryptogenツールを使用して、チャネルごとのMSP(Membership Service Provider)をつくる。
MSPについては、以下の記事で勉強しました。
Hyperledger FabricのMSPについて
認証のナニカであることはワカリマシタ...

Crypto Generator

  • 起動
$ ../bin/cryptogen generate --config=./crypto-config.yaml
org1.example.com
org2.example.com

crypto-configディレクトリと、first-networkディレクトリに証明書などができます。

  • パスを通す(必ずfirst-networkのディレクトリで!)
$ export FABRIC_CFG_PATH=$PWD
  • Ordererのgenesis blockを作る
$ ../bin/configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
2019-01-10 13:11:16.145 JST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-01-10 13:11:16.187 JST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: solo
2019-01-10 13:11:16.188 JST [common.tools.configtxgen.localconfig] Load -> INFO 003 Loaded configuration: /home/user01/fabric-samples/first-network/configtx.yaml
2019-01-10 13:11:16.225 JST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 004 orderer type: solo
2019-01-10 13:11:16.225 JST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 005 Loaded configuration: /home/user01/fabric-samples/first-network/configtx.yaml
2019-01-10 13:11:16.231 JST [common.tools.configtxgen] doOutputBlock -> INFO 006 Generating genesis block
2019-01-10 13:11:16.232 JST [common.tools.configtxgen] doOutputBlock -> INFO 007 Writing genesis block

チャネル構成ファイルの作成

  • CHANNEL_NAMEをmychannelに設定&channel.txを作成
$ export CHANNEL_NAME=mychannel  && ../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
2019-01-10 13:11:48.153 JST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-01-10 13:11:48.199 JST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/user01/fabric-samples/first-network/configtx.yaml
2019-01-10 13:11:48.242 JST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-01-10 13:11:48.242 JST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/user01/fabric-samples/first-network/configtx.yaml
2019-01-10 13:11:48.243 JST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 005 Generating new channel configtx
2019-01-10 13:11:48.248 JST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 006 Writing new channel tx
  • Org1のアンカーピアを定義

アンカーピアとは

Anchor Peer はブロックチェーンネットワーク上の他の組織の Peer との通信の窓口となる Peer のことを言います。 各組織の Anchor Peer のアドレスはブロックチェーンネットワークの起動時に受け取ることができるので、Anchor Peer を通じて各組織の持つ Peer の情報を知ることができます。

$ ../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
2019-01-10 13:12:17.107 JST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-01-10 13:12:17.152 JST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/user01/fabric-samples/first-network/configtx.yaml
2019-01-10 13:12:17.190 JST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-01-10 13:12:17.190 JST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/user01/fabric-samples/first-network/configtx.yaml
2019-01-10 13:12:17.191 JST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2019-01-10 13:12:17.193 JST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
  • Org2のアンカーピアを定義
$ ../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP
2019-01-10 13:12:27.910 JST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-01-10 13:12:27.948 JST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/user01/fabric-samples/first-network/configtx.yaml
2019-01-10 13:12:27.986 JST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-01-10 13:12:27.987 JST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/user01/fabric-samples/first-network/configtx.yaml
2019-01-10 13:12:27.988 JST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2019-01-10 13:12:27.989 JST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update

まとめ

今回はネットワーク作成し、立ち上げてから一回停止させて、証明書やらなんやらを作り、チャネルの設定まで行いました。

次回は、ネットワークを立ち上げてCLIコンテナに入り、コンテナ側の設定と、チェーンコードをインスタンス化して、使えるところまでを書きます。
長編になりそうです。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?