Hyperledger Fabric2.5環境を0から構築

Hyperledger Fabric 2.5環境構築

1. Linux環境の準備

# root登录
yum -y install git curl docker docker-compose tree
yum -y install autoconf autotools-dev automake m4 perl
yum -y install libtool
autoreconf -ivf
# 安装jq相关包
cd /opt
git clone --recursive https://github.com/jqlang/jq.git
cd jq
autoreconf -i
./configure --disable-maintainer-mode
make
make install

# 强制删除之前的镜像
docker rmi --force $(docker images -q)

# 创建用户,设置密码
useradd fabric
passwd fabric
# 添加sudo权限
vi /etc/sudoers
# 在wheel下添加fabric配置
## Same thing without a password
# %wheel        ALL=(ALL)       NOPASSWD: ALL
fabric          ALL=(ALL)       NOPASSWD: ALL
# :wq保存
# 验证是否配置成功
[root@localhost ~]# visudo -cf /etc/sudoers
/etc/sudoers:解析正确

# 切换fabric用户
su - fabric

# 安装过后检查版本
docker --version
docker-compose --version
# docker后台运行
sudo systemctl start docker
# 开机自启
sudo systemctl enable docker
# 用户添加到组
sudo usermod -a -G docker fabric

# 安装go
cd /home/fabric
wget https://golang.google.cn/dl/go1.20.5.linux-amd64.tar.gz
mkdir godir
tar -zxvf go1.20.5.linux-amd64.tar.gz -C ./godir
# 配置环境变量
sudo vi /etc/profile
#golang env config,1.18版本之后无需export GO111MODULE=on,可不设置gopath
export GOROOT=/home/fabric/godir/go
export PATH=$PATH:$GOROOT/bin
export GOPROXY=https://goproxy.cn

source /etc/profile
# 设置代理或者
# go env -w GOPROXY=https://goproxy.cn,direct

2. ファブリック、ファブリックサンプルのインストール

  • Hyperledger/Structure サンプル リポジトリのクローンを作成します。
  • 最新の Hyperledger Fabric Docker イメージをダウンロードし、最新としてマークします。
  • 次のプラットフォーム固有の Hyperledger Fabric CLI ツールのバイナリと構成ファイルを、fabric-samples /bin および /config ディレクトリにダウンロードします。

これらのバイナリは、テストネットとの対話に役立ちます。ファブリックサンプル/bin/config

configtxgen,
configtxlator,
cryptogen,
discover,
idemixgen,
orderer,
osnadmin,
peer,
fabric-ca-client,
fabric-ca-server

サンプル、Docker イメージ、バイナリをダウンロードする

su - fabric
# 创建目录
mkdir -p $HOME/go/src/github.com/myproject
cd $HOME/go/src/github.com/myproject
# 获取安装脚本
curl -sSLO https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh && chmod +x install-fabric.sh
# 查看帮助
./install-fabric.sh -h

ここに画像の説明を挿入

コンポーネントを選択する

  • Docker を使用してファブリック コンテナ イメージをダウンロードする docker
  • podman は podman を使用して構造コンテナー イメージをダウンロードします
  • バイナリのダウンロード構造 バイナリ
  • サンプルは、構築サンプルの GitHub リポジトリを現在のディレクトリに複製します。
# 下载之前修改脚本,添加github代理
#在download附近的https,前面加上https://ghproxy.com/
download "${BINARY_FILE}" "https://github.com/hyperledger/fabric/releases/download/v${VERSION}/${BINARY_FILE}"
修改为
download "${BINARY_FILE}" "https://ghproxy.com/https://github.com/hyperledger/fabric/releases/download/v${VERSION}/${BINARY_FILE}"

download "${CA_BINARY_FILE}" "https://github.com/hyperledger/fabric-ca/releases/download/v${CA_VERSION}/${CA_BINARY_FILE}"
修改为
download "${CA_BINARY_FILE}" "https://ghproxy.com/https://github.com/hyperledger/fabric-ca/releases/download/v${CA_VERSION}/${CA_BINARY_FILE}"

# 执行安装,当前默认fabric 2.5.0, fabric-ca 1.5.6
./install-fabric.sh docker samples binary
or
./install-fabric.sh d s b

# 若需要选择fabric版本,则执行如下
# --fabric-version -ca-version 简写分别为-f -c,此处默认ca 1.5.6版本
# ./install-fabric.sh --fabric-version 2.5.0 binary

3. テストネットワークを実行します(テストネットワーク)

テストネットワークを開始する

ネットワークを開始し、順序付け者と 2 つのピアを作成します。現時点ではチャネルはありません

cd fabric-samples/test-network
# 删除之前运行的容器或项目
./network.sh down
# 清理容器
docker ps -qa | xargs docker rm
# 启动网络,创建一个orderer 两个peer,此时不含通道
./network.sh up

# 查看test-network运行的容器
docker ps -a

ここに画像の説明を挿入

ファブリック ネットワークと対話するすべてのノードとユーザーは、ネットワークに参加するために組織に所属する必要があります。テスト コンテンツ ネットワークには、Org1 と Org2 という 2 つのピア組織が含まれています。これには、ネットワーク注文サービスを維持する注文者組織も含まれます。

ピアはブロックチェーン台帳を保存し、トランザクションが取引される前に台帳にコミットされていることを確認します。ピアは、ブロックチェーン台帳上の資産を管理するビジネスを含むスマート コントラクトのロジックを実行します。

ネットワーク内のすべてのピアは組織に属している必要があります。各組織は、peer0.org1.example.com、peer0.org2.example.com などのテスト ネットワークでピアを実行します。

各ファブリック ネットワークには、順序付けサービス (順序付けサービス) も含まれています。ピアがトランザクションを検証し、トランザクション ブロックをブロックチェーン台帳に追加する場合、トランザクションの順序を決定したり、トランザクションを新しいブロックに含めたりすることはありません。分散ネットワークでは、ピアが互いに遠く離れている可能性があり、トランザクションがいつ作成されたかについての共通のビューがありません。トランザクションの順序について合意に達することは、ピアに高いオーバーヘッドを課すコストのかかるプロセスです。

順序付けサービスにより、ピアはトランザクションの検証と台帳へのコミットに集中できます。順序付けノードは、クライアントから承認されたトランザクションを受信した後、トランザクションの順序について合意に達し、トランザクション情報をブロックに追加します。その後、ブロックはピアノードに配布され、ピアノードがブロックをブロックチェーン台帳に追加します。

このネットワーク例では、発注者組織が運営する単一ノードの Raft 発注サービス (orderer.example.com) を使用します。
テスト ネットワーク: 単一ノードの注文サービス
実稼働環境: 複数の注文ノード、1 つ以上の注文者組織。
さまざまな順序付けノードは、Raft コンセンサス アルゴリズムを使用して、ネットワーク上のトランザクションの順序に同意します。

4. チャンネルチャンネルを作成する

Org1 と Org2 間のトランザクションにより、ファブリック チャネルが作成されます。チャネルは、特定のネットワークのメンバー間の専用の通信層です。チャネルは、チャネルに招待された組織のみが使用でき、ネットワークの他のメンバーには表示されません。各チャネルには個別のブロックチェーン台帳があります。招待された組織は、ピアにチャネルに参加して、チャネル台帳を保存し、チャネル上のトランザクションを検証します。

# 创建默认通道 mychannel
./network.sh createChannel
# 自定义通道名称
#./network.sh createChannel -c channel1
# 创建多个通道,上述创建完成后,还可以创建通道
./network.sh createChannel -c channel2

# 若需要创建通道和启动网络,则可执行
# ./network.sh up createChannel

ここに画像の説明を挿入

ここに画像の説明を挿入

チャンネルログを作成する

[fabric@localhost test-network]$ ./network.sh createChannel
Using docker and docker-compose
Creating channel 'mychannel'.
If network is not up, starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb 
Network Running Already
Using docker and docker-compose
Generating channel genesis block 'mychannel.block'
/home/fabric/go/src/github.com/myproject/fabric-samples/bin/configtxgen
+ configtxgen -profile TwoOrgsApplicationGenesis -outputBlock ./channel-artifacts/mychannel.block -channelID mychannel
2023-06-08 21:59:38.056 CST 0001 INFO [common.tools.configtxgen] main -> Loading configuration
2023-06-08 21:59:38.065 CST 0002 INFO [common.tools.configtxgen.localconfig] completeInitialization -> orderer type: etcdraft
2023-06-08 21:59:38.066 CST 0003 INFO [common.tools.configtxgen.localconfig] completeInitialization -> Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216 
2023-06-08 21:59:38.066 CST 0004 INFO [common.tools.configtxgen.localconfig] Load -> Loaded configuration: /home/fabric/go/src/github.com/myproject/fabric-samples/test-network/configtx/configtx.yaml
2023-06-08 21:59:38.069 CST 0005 INFO [common.tools.configtxgen] doOutputBlock -> Generating genesis block
2023-06-08 21:59:38.069 CST 0006 INFO [common.tools.configtxgen] doOutputBlock -> Creating application channel genesis block
2023-06-08 21:59:38.070 CST 0007 INFO [common.tools.configtxgen] doOutputBlock -> Writing genesis block
+ res=0
Creating channel mychannel
Using organization 1
+ osnadmin channel join --channelID mychannel --config-block ./channel-artifacts/mychannel.block -o localhost:7053 --ca-file /home/fabric/go/src/github.com/myproject/fabric-samples/test-network/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem --client-cert /home/fabric/go/src/github.com/myproject/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt --client-key /home/fabric/go/src/github.com/myproject/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.key
+ res=0
Status: 201
{
        "name": "mychannel",
        "url": "/participation/v1/channels/mychannel",
        "consensusRelation": "consenter",
        "status": "active",
        "height": 1
}

Channel 'mychannel' created
Joining org1 peer to the channel...
Using organization 1
+ peer channel join -b ./channel-artifacts/mychannel.block
+ res=0
2023-06-08 21:59:44.252 CST 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2023-06-08 21:59:44.281 CST 0002 INFO [channelCmd] executeJoin -> Successfully submitted proposal to join channel
Joining org2 peer to the channel...
Using organization 2
+ peer channel join -b ./channel-artifacts/mychannel.block
+ res=0
2023-06-08 21:59:47.363 CST 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2023-06-08 21:59:47.392 CST 0002 INFO [channelCmd] executeJoin -> Successfully submitted proposal to join channel
Setting anchor peer for org1...
Using organization 1
Fetching channel config for channel mychannel
Using organization 1
Fetching the most recent configuration block for the channel
+ peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c mychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
2023-06-08 13:59:47.844 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2023-06-08 13:59:47.850 UTC 0002 INFO [cli.common] readBlock -> Received block: 0
2023-06-08 13:59:47.850 UTC 0003 INFO [channelCmd] fetch -> Retrieving last config block: 0
2023-06-08 13:59:47.852 UTC 0004 INFO [cli.common] readBlock -> Received block: 0
Decoding config block to JSON and isolating config to Org1MSPconfig.json
+ configtxlator proto_decode --input config_block.pb --type common.Block --output config_block.json
+ jq '.data.data[0].payload.data.config' config_block.json
Generating anchor peer update transaction for Org1 on channel mychannel
+ jq '.channel_group.groups.Application.groups.Org1MSP.values += {
    
    "AnchorPeers":{
    
    "mod_policy": "Admins","value":{
    
    "anchor_peers": [{
    
    "host": "peer0.org1.example.com","port": 7051}]},"version": "0"}}' Org1MSPconfig.json
+ configtxlator proto_encode --input Org1MSPconfig.json --type common.Config --output original_config.pb
+ configtxlator proto_encode --input Org1MSPmodified_config.json --type common.Config --output modified_config.pb
+ configtxlator compute_update --channel_id mychannel --original original_config.pb --updated modified_config.pb --output config_update.pb
+ configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output config_update.json
+ jq .
++ cat config_update.json
+ echo '{
    
    "payload":{
    
    "header":{
    
    "channel_header":{
    
    "channel_id":"mychannel", "type":2}},"data":{
    
    "config_update":{
    
    ' '"channel_id":' '"mychannel",' '"isolated_data":' '{
    
    },' '"read_set":' '{
    
    ' '"groups":' '{
    
    ' '"Application":' '{
    
    ' '"groups":' '{
    
    ' '"Org1MSP":' '{
    
    ' '"groups":' '{
    
    },' '"mod_policy":' '"",' '"policies":' '{
    
    ' '"Admins":' '{
    
    ' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '},' '"write_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org1MSP":' '{' '"groups":' '{},' '"mod_policy":' '"Admins",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"AnchorPeers":' '{' '"mod_policy":' '"Admins",' '"value":' '{' '"anchor_peers":' '[' '{' '"host":' '"peer0.org1.example.com",' '"port":' 7051 '}' ']' '},' '"version":' '"0"' '},' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '}}}}'
+ configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output Org1MSPanchors.tx
2023-06-08 13:59:48.413 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2023-06-08 13:59:48.433 UTC 0002 INFO [channelCmd] update -> Successfully submitted channel update
Anchor peer set for org 'Org1MSP' on channel 'mychannel'
Setting anchor peer for org2...
Using organization 2
Fetching channel config for channel mychannel
Using organization 2
Fetching the most recent configuration block for the channel
+ peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c mychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
2023-06-08 13:59:48.945 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2023-06-08 13:59:48.950 UTC 0002 INFO [cli.common] readBlock -> Received block: 1
2023-06-08 13:59:48.950 UTC 0003 INFO [channelCmd] fetch -> Retrieving last config block: 1
2023-06-08 13:59:48.952 UTC 0004 INFO [cli.common] readBlock -> Received block: 1
Decoding config block to JSON and isolating config to Org2MSPconfig.json
+ configtxlator proto_decode --input config_block.pb --type common.Block --output config_block.json
+ jq '.data.data[0].payload.data.config' config_block.json
Generating anchor peer update transaction for Org2 on channel mychannel
+ jq '.channel_group.groups.Application.groups.Org2MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.org2.example.com","port": 9051}]},"version": "0"}}' Org2MSPconfig.json
+ configtxlator proto_encode --input Org2MSPconfig.json --type common.Config --output original_config.pb
+ configtxlator proto_encode --input Org2MSPmodified_config.json --type common.Config --output modified_config.pb
+ configtxlator compute_update --channel_id mychannel --original original_config.pb --updated modified_config.pb --output config_update.pb
+ configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output config_update.json
+ jq .
++ cat config_update.json
+ echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel", "type":2}},"data":{"config_update":{' '"channel_id":' '"mychannel",' '"isolated_data":' '{},' '"read_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org2MSP":' '{' '"groups":' '{},' '"mod_policy":' '"",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '},' '"write_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org2MSP":' '{' '"groups":' '{},' '"mod_policy":' '"Admins",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"AnchorPeers":' '{' '"mod_policy":' '"Admins",' '"value":' '{' '"anchor_peers":' '[' '{' '"host":' '"peer0.org2.example.com",' '"port":' 9051 '}' ']' '},' '"version":' '"0"' '},' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '}}}}'
+ configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output Org2MSPanchors.tx
2023-06-08 13:59:49.391 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2023-06-08 13:59:49.410 UTC 0002 INFO [channelCmd] update -> Successfully submitted channel update
Anchor peer set for org 'Org2MSP' on channel 'mychannel'
Channel 'mychannel' joined


チャネル名の考慮事項

  1. 小文字の ASCII 英数字、ドット「.」およびダッシュ「-」のみが含まれます。
  2. 250文字未満
  3. 手紙から始まる

5. チャネルでチェーンコードを開始します

チャネル間の台帳は、スマート コントラクトを通じて相互作用します。

  1. スマート コントラクトには、ブロックチェーン台帳上の資産を管理するためのビジネス ロジックが含まれています。ネットワーク メンバーによって実行されるアプリケーションは、スマート コントラクトを呼び出して資産を作成し、台帳上でそれらの資産を変更および転送します。アプリケーションはスマート コントラクトをクエリして台帳上のデータを読み取ることができます。

  2. トランザクションが有効であることを確認するために、多くの場合、スマート コントラクトを使用して作成されたトランザクションは、チャネル台帳にコミットされる前に複数の組織によって署名される必要があります。マルチシグは、ファブリックの信頼モデルに不可欠な部分です。トランザクションに対して複数の承認を要求することで、チャネル上の組織がピアの台帳を改ざんしたり、同意なしにビジネス ロジックを使用したりすることを防ぎます。トランザクションに署名するには、各組織がピア上でスマート コントラクトを呼び出して実行し、トランザクション出力に署名する必要があります。出力に一貫性があり、十分な組織によって署名されている場合、トランザクションを台帳にコミットできます。チャネル上でスマートコントラクトを実行する必要がある集合組織を指定するポリシーは、エンドースメントポリシーと呼ばれ、チェーンコード定義の一部としてチェーンコードごとに設定されます。

  3. Fabric では、スマート コントラクトはチェーンコードと呼ばれます。チェーンコードは組織のピアノードにインストールされ、トランザクションを承認したりブロックチェーン台帳とやり取りしたりするために使用できるチャネルにデプロイされます。チェーンコードをチャネルにデプロイする前に、チャネルのメンバーは、チェーンコードのガバナンスを確立するチェーンコードの定義に同意する必要があります。必要な数の組織が同意すると、チェーンコード定義をチャネルにコミットし、チェーンコードを使用できるようになります。

チャネルでチェーンコードを開始します

# 使用network.sh创建通道后,可以使用以下命令在通道上启动链代码:

./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go

applyCC サブコマンドは、アセット転送 (基本) チェーンコードをpeer0.org1.example.com およびpeer0.org2.example.comにインストールし、チャネルフラグで指定されたチャネル(デフォルトではmychannel)にチェーンコードをデプロイします。チェーンコードを初めてデプロイするときに、チェーンコード関連の依存関係がインストールされます。言語フラグ -ccl を使用すると、Go、Typescript、または JavaScript チェーンコードをインストールするように指定できます。アセット転送 (ベーシック) チェーンコードは、fabric-samples のasset-transfer-basic フォルダーにあります。このフォルダーには、例として提供されるサンプル チェーンコードとチュートリアルが含まれています。

ここに画像の説明を挿入

チェーンコードログ

[fabric@localhost test-network]$ ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go
Using docker and docker-compose
deploying chaincode on channel 'mychannel'
executing with the following
- CHANNEL_NAME: mychannel
- CC_NAME: basic
- CC_SRC_PATH: ../asset-transfer-basic/chaincode-go
- CC_SRC_LANGUAGE: go
- CC_VERSION: 1.0
- CC_SEQUENCE: 1
- CC_END_POLICY: NA
- CC_COLL_CONFIG: NA
- CC_INIT_FCN: NA
- DELAY: 3
- MAX_RETRY: 5
- VERBOSE: false
Vendoring Go dependencies at ../asset-transfer-basic/chaincode-go
~/go/src/github.com/myproject/fabric-samples/asset-transfer-basic/chaincode-go ~/go/src/github.com/myproject/fabric-samples/test-network
~/go/src/github.com/myproject/fabric-samples/test-network
Finished vendoring Go dependencies
+ peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go --lang golang --label basic_1.0
+ res=0
++ peer lifecycle chaincode calculatepackageid basic.tar.gz
+ PACKAGE_ID=basic_1.0:e4de097efb5be42d96aebc4bde18eea848aad0f5453453ba2aad97f2e41e0d57
Chaincode is packaged
Installing chaincode on peer0.org1...
Using organization 1
+ jq -r 'try (.installed_chaincodes[].package_id)'
+ grep '^basic_1.0:e4de097efb5be42d96aebc4bde18eea848aad0f5453453ba2aad97f2e41e0d57$'
+ peer lifecycle chaincode queryinstalled --output json
+ test 1 -ne 0
+ peer lifecycle chaincode install basic.tar.gz
+ res=0
2023-06-08 22:42:29.444 CST 0001 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Installed remotely: response:<status:200 payload:"\nJbasic_1.0:e4de097efb5be42d96aebc4bde18eea848aad0f5453453ba2aad97f2e41e0d57\022\tbasic_1.0" > 
2023-06-08 22:42:29.456 CST 0002 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Chaincode code package identifier: basic_1.0:e4de097efb5be42d96aebc4bde18eea848aad0f5453453ba2aad97f2e41e0d57
Chaincode is installed on peer0.org1
Install chaincode on peer0.org2...
Using organization 2
+ grep '^basic_1.0:e4de097efb5be42d96aebc4bde18eea848aad0f5453453ba2aad97f2e41e0d57$'
+ peer lifecycle chaincode queryinstalled --output json
+ jq -r 'try (.installed_chaincodes[].package_id)'
+ test 1 -ne 0
+ peer lifecycle chaincode install basic.tar.gz
+ res=0
2023-06-08 22:43:52.357 CST 0001 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Installed remotely: response:<status:200 payload:"\nJbasic_1.0:e4de097efb5be42d96aebc4bde18eea848aad0f5453453ba2aad97f2e41e0d57\022\tbasic_1.0" > 
2023-06-08 22:43:52.396 CST 0002 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Chaincode code package identifier: basic_1.0:e4de097efb5be42d96aebc4bde18eea848aad0f5453453ba2aad97f2e41e0d57
Chaincode is installed on peer0.org2
Using organization 1
+ jq -r 'try (.installed_chaincodes[].package_id)'
+ grep '^basic_1.0:e4de097efb5be42d96aebc4bde18eea848aad0f5453453ba2aad97f2e41e0d57$'
+ peer lifecycle chaincode queryinstalled --output json
+ res=0
basic_1.0:e4de097efb5be42d96aebc4bde18eea848aad0f5453453ba2aad97f2e41e0d57
Query installed successful on peer0.org1 on channel
Using organization 1
+ peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile /home/fabric/go/src/github.com/myproject/fabric-samples/test-network/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem --channelID mychannel --name basic --version 1.0 --package-id basic_1.0:e4de097efb5be42d96aebc4bde18eea848aad0f5453453ba2aad97f2e41e0d57 --sequence 1
+ res=0
2023-06-08 22:43:54.752 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [536e459cb17675dffd66b390222e9c1fbbd260c7b2352e3c3cc79e2c00fd2934] committed with status (VALID) at localhost:7051
Chaincode definition approved on peer0.org1 on channel 'mychannel'
Using organization 1
Checking the commit readiness of the chaincode definition on peer0.org1 on channel 'mychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org1, Retry after 3 seconds.
+ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --output json
+ res=0
{
    
    
        "approvals": {
    
    
                "Org1MSP": true,
                "Org2MSP": false
        }
}
Checking the commit readiness of the chaincode definition successful on peer0.org1 on channel 'mychannel'
Using organization 2
Checking the commit readiness of the chaincode definition on peer0.org2 on channel 'mychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org2, Retry after 3 seconds.
+ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --output json
+ res=0
{
    
    
        "approvals": {
    
    
                "Org1MSP": true,
                "Org2MSP": false
        }
}
Checking the commit readiness of the chaincode definition successful on peer0.org2 on channel 'mychannel'
Using organization 2
+ peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile /home/fabric/go/src/github.com/myproject/fabric-samples/test-network/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem --channelID mychannel --name basic --version 1.0 --package-id basic_1.0:e4de097efb5be42d96aebc4bde18eea848aad0f5453453ba2aad97f2e41e0d57 --sequence 1
+ res=0
2023-06-08 22:44:03.169 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [952e8fd42b124ae5006e7fd41816b1bc6dfb6320dcd6ccd7d09aedffc858dbe2] committed with status (VALID) at localhost:9051
Chaincode definition approved on peer0.org2 on channel 'mychannel'
Using organization 1
Checking the commit readiness of the chaincode definition on peer0.org1 on channel 'mychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org1, Retry after 3 seconds.
+ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --output json
+ res=0
{
    
    
        "approvals": {
    
    
                "Org1MSP": true,
                "Org2MSP": true
        }
}
Checking the commit readiness of the chaincode definition successful on peer0.org1 on channel 'mychannel'
Using organization 2
Checking the commit readiness of the chaincode definition on peer0.org2 on channel 'mychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org2, Retry after 3 seconds.
+ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --output json
+ res=0
{
    
    
        "approvals": {
    
    
                "Org1MSP": true,
                "Org2MSP": true
        }
}
Checking the commit readiness of the chaincode definition successful on peer0.org2 on channel 'mychannel'
Using organization 1
Using organization 2
+ peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile /home/fabric/go/src/github.com/myproject/fabric-samples/test-network/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem --channelID mychannel --name basic --peerAddresses localhost:7051 --tlsRootCertFiles /home/fabric/go/src/github.com/myproject/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem --peerAddresses localhost:9051 --tlsRootCertFiles /home/fabric/go/src/github.com/myproject/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/tlsca/tlsca.org2.example.com-cert.pem --version 1.0 --sequence 1
+ res=0
2023-06-08 22:44:11.781 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [009e9c153fb77c941a1aa77735f83ffbd21fe7a6d7afd7db0c004399ca06627c] committed with status (VALID) at localhost:9051
2023-06-08 22:44:11.784 CST 0002 INFO [chaincodeCmd] ClientWait -> txid [009e9c153fb77c941a1aa77735f83ffbd21fe7a6d7afd7db0c004399ca06627c] committed with status (VALID) at localhost:7051
Chaincode definition committed on channel 'mychannel'
Using organization 1
Querying chaincode definition on peer0.org1 on channel 'mychannel'...
Attempting to Query committed status on peer0.org1, Retry after 3 seconds.
+ peer lifecycle chaincode querycommitted --channelID mychannel --name basic
+ res=0
Committed chaincode definition for chaincode 'basic' on channel 'mychannel':
Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
Query chaincode definition successful on peer0.org1 on channel 'mychannel'
Using organization 2
Querying chaincode definition on peer0.org2 on channel 'mychannel'...
Attempting to Query committed status on peer0.org2, Retry after 3 seconds.
+ peer lifecycle chaincode querycommitted --channelID mychannel --name basic
+ res=0
Committed chaincode definition for chaincode 'basic' on channel 'mychannel':
Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
Query chaincode definition successful on peer0.org2 on channel 'mychannel'
Chaincode initialization is not required

6. ネットワークとの対話

ピアの CLI を使用してネットワークと対話します。ピア CLI は、展開されたスマート コントラクトを呼び出し、チャネルを更新するか、新しいスマート コントラクトをインストールして展開します。

環境変数の設定

cd fabric-samples/test-network
# 确保能使用fabric-samples二进制文件
export PATH=${
    
    PWD}/../bin:$PATH
# 如configtxgen  configtxlator  cryptogen  discover  fabric-ca-client  fabric-ca-server  ledgerutil  orderer  osnadmin  peer

# 设置FABRIC_CFG_PATH指向fabric-samples中的core.yaml的文件
export FABRIC_CFG_PATH=$PWD/../config/
ls $FABRIC_CFG_PATH

CLI 環境変数を使用するように Org1 のピアを設定する

# Environment variables for Org1

export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${
    
    PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${
    
    PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:7051

CORE_PEER_TLS_ROOTCERT_FILE および CORE_PEER_MSPCONFIGPATH 環境変数は、組織フォルダー内の Org1 暗号化マテリアルを指します。

台帳の初期化

資産初期化レジャーでは、CLI はファブリック ゲートウェイ ピアにアクセスしないため、承認された各ピアを指定する必要があります。

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${
     
     PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${
     
     PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${
     
     PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"InitLedger","Args":[]}'

ここに画像の説明を挿入

クエリ元帳

CLI から台帳をクエリし、チャネル台帳に追加されたアセットのリストをクエリします。

peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}'

ここに画像の説明を挿入

検索結果

[{
    
    "AppraisedValue":300,"Color":"blue","ID":"asset1","Owner":"Tomoko","Size":5},{
    
    "AppraisedValue":400,"Color":"red","ID":"asset2","Owner":"Brad","Size":5},{
    
    "AppraisedValue":500,"Color":"green","ID":"asset3","Owner":"Jin Soo","Size":10},{
    
    "AppraisedValue":600,"Color":"yellow","ID":"asset4","Owner":"Max","Size":10},{
    
    "AppraisedValue":700,"Color":"black","ID":"asset5","Owner":"Adriana","Size":15},{
    
    "AppraisedValue":800,"Color":"white","ID":"asset6","Owner":"Michel","Size":15}]

資産譲渡

ネットワークメンバーはチェーンコードを呼び出して台帳上の資産を転送または変更します。次のコマンドを使用して、資産転送 (基本) チェーンコードを呼び出して台帳上の資産の所有者を変更します。

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${
     
     PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${
     
     PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${
     
     PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"TransferAsset","Args":["asset6","Christopher"]}'

ここに画像の説明を挿入
アセット転送 (基本) チェーンコード承認ポリシー トランザクションは Org1 と Org2 の両方によって署名される必要があるため、チェーンコード呼び出しコマンドでは、peer0.org1.example.com およびpeer0.org2.example.com が --peerAddresses フラグを使用する必要があります。ネットワークでは TLS が有効になっているため、このコマンドでは各ピアの TLS 証明書を使用するために --tlsRootCertFiles フラグも必要です。

クエリ元帳

チェーンコードを呼び出した後、別のクエリを使用して、呼び出しによってブロックチェーン台帳上の資産がどのように変更されたかを確認できます。すでに Org1 ピアをクエリしているため、Org2 ピアで実行されているチェーンコードをクエリできます。Org2 として実行するように次の環境変数を設定します。

# Environment variables for Org2
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${
    
    PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${
    
    PWD}/organizations/peerOrganizations/org2.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:9051

##在peer0.org2.example.com上查询asset-transfer (basic)链码
peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","asset6"]}'

ここに画像の説明を挿入

7. ネットワークをオフにする

このコマンドは、ノードとチェーンコード コンテナーを停止して削除し、組織の暗号化マテリアルを削除し、Docker レジストリからチェーンコード イメージを削除します。このコマンドは、以前の実行からチャネルと Docker ボリュームも削除します。

./network.sh down

8. ディレクトリ構造

上記の操作は、ディレクトリ構造を観察するために完了しました。

cd fabric-samples/test-network
tree

.
├── addOrg3
│   ├── addOrg3.sh
│   ├── ccp-generate.sh
│   ├── ccp-template.json
│   ├── ccp-template.yaml
│   ├── compose
│   │   ├── compose-ca-org3.yaml
│   │   ├── compose-couch-org3.yaml
│   │   ├── compose-org3.yaml
│   │   ├── docker
│   │   │   ├── docker-compose-ca-org3.yaml
│   │   │   ├── docker-compose-couch-org3.yaml
│   │   │   ├── docker-compose-org3.yaml
│   │   │   └── peercfg
│   │   │       └── core.yaml
│   │   └── podman
│   │       ├── peercfg
│   │       │   └── core.yaml
│   │       ├── podman-compose-ca-org3.yaml
│   │       ├── podman-compose-couch-org3.yaml
│   │       └── podman-compose-org3.yaml
│   ├── configtx.yaml
│   ├── fabric-ca
│   │   ├── org3
│   │   │   └── fabric-ca-server-config.yaml
│   │   └── registerEnroll.sh
│   ├── org3-crypto.yaml
│   └── README.md
├── basic.tar.gz
├── CHAINCODE_AS_A_SERVICE_TUTORIAL.md
├── channel-artifacts
│   ├── channel2.block
│   └── mychannel.block
├── compose
│   ├── compose-ca.yaml
│   ├── compose-couch.yaml
│   ├── compose-test-net.yaml
│   ├── docker
│   │   ├── docker-compose-ca.yaml
│   │   ├── docker-compose-couch.yaml
│   │   ├── docker-compose-test-net.yaml
│   │   └── peercfg
│   │       └── core.yaml
│   └── podman
│       ├── peercfg
│       │   └── core.yaml
│       ├── podman-compose-ca.yaml
│       ├── podman-compose-couch.yaml
│       └── podman-compose-test-net.yaml
├── configtx
│   └── configtx.yaml
├── log.txt
├── monitordocker.sh
├── network.sh
├── organizations
│   ├── ccp-generate.sh
│   ├── ccp-template.json
│   ├── ccp-template.yaml
│   ├── cryptogen
│   │   ├── crypto-config-orderer.yaml
│   │   ├── crypto-config-org1.yaml
│   │   └── crypto-config-org2.yaml
│   ├── fabric-ca
│   │   ├── ordererOrg
│   │   │   └── fabric-ca-server-config.yaml
│   │   ├── org1
│   │   │   └── fabric-ca-server-config.yaml
│   │   ├── org2
│   │   │   └── fabric-ca-server-config.yaml
│   │   └── registerEnroll.sh
│   ├── ordererOrganizations
│   │   └── example.com
│   │       ├── ca
│   │       │   ├── ca.example.com-cert.pem
│   │       │   └── priv_sk
│   │       ├── msp
│   │       │   ├── admincerts
│   │       │   ├── cacerts
│   │       │   │   └── ca.example.com-cert.pem
│   │       │   ├── config.yaml
│   │       │   └── tlscacerts
│   │       │       └── tlsca.example.com-cert.pem
│   │       ├── orderers
│   │       │   └── orderer.example.com
│   │       │       ├── msp
│   │       │       │   ├── admincerts
│   │       │       │   ├── cacerts
│   │       │       │   │   └── ca.example.com-cert.pem
│   │       │       │   ├── config.yaml
│   │       │       │   ├── keystore
│   │       │       │   │   └── priv_sk
│   │       │       │   ├── signcerts
│   │       │       │   │   └── orderer.example.com-cert.pem
│   │       │       │   └── tlscacerts
│   │       │       │       └── tlsca.example.com-cert.pem
│   │       │       └── tls
│   │       │           ├── ca.crt
│   │       │           ├── server.crt
│   │       │           └── server.key
│   │       ├── tlsca
│   │       │   ├── priv_sk
│   │       │   └── tlsca.example.com-cert.pem
│   │       └── users
│   │           └── [email protected]
│   │               ├── msp
│   │               │   ├── admincerts
│   │               │   ├── cacerts
│   │               │   │   └── ca.example.com-cert.pem
│   │               │   ├── config.yaml
│   │               │   ├── keystore
│   │               │   │   └── priv_sk
│   │               │   ├── signcerts
│   │               │   │   └── [email protected]
│   │               │   └── tlscacerts
│   │               │       └── tlsca.example.com-cert.pem
│   │               └── tls
│   │                   ├── ca.crt
│   │                   ├── client.crt
│   │                   └── client.key
│   └── peerOrganizations
│       ├── org1.example.com
│       │   ├── ca
│       │   │   ├── ca.org1.example.com-cert.pem
│       │   │   └── priv_sk
│       │   ├── connection-org1.json
│       │   ├── connection-org1.yaml
│       │   ├── msp
│       │   │   ├── admincerts
│       │   │   ├── cacerts
│       │   │   │   └── ca.org1.example.com-cert.pem
│       │   │   ├── config.yaml
│       │   │   └── tlscacerts
│       │   │       └── tlsca.org1.example.com-cert.pem
│       │   ├── peers
│       │   │   └── peer0.org1.example.com
│       │   │       ├── msp
│       │   │       │   ├── admincerts
│       │   │       │   ├── cacerts
│       │   │       │   │   └── ca.org1.example.com-cert.pem
│       │   │       │   ├── config.yaml
│       │   │       │   ├── keystore
│       │   │       │   │   └── priv_sk
│       │   │       │   ├── signcerts
│       │   │       │   │   └── peer0.org1.example.com-cert.pem
│       │   │       │   └── tlscacerts
│       │   │       │       └── tlsca.org1.example.com-cert.pem
│       │   │       └── tls
│       │   │           ├── ca.crt
│       │   │           ├── server.crt
│       │   │           └── server.key
│       │   ├── tlsca
│       │   │   ├── priv_sk
│       │   │   └── tlsca.org1.example.com-cert.pem
│       │   └── users
│       │       ├── [email protected]
│       │       │   ├── msp
│       │       │   │   ├── admincerts
│       │       │   │   ├── cacerts
│       │       │   │   │   └── ca.org1.example.com-cert.pem
│       │       │   │   ├── config.yaml
│       │       │   │   ├── keystore
│       │       │   │   │   └── priv_sk
│       │       │   │   ├── signcerts
│       │       │   │   │   └── [email protected]
│       │       │   │   └── tlscacerts
│       │       │   │       └── tlsca.org1.example.com-cert.pem
│       │       │   └── tls
│       │       │       ├── ca.crt
│       │       │       ├── client.crt
│       │       │       └── client.key
│       │       └── [email protected]
│       │           ├── msp
│       │           │   ├── admincerts
│       │           │   ├── cacerts
│       │           │   │   └── ca.org1.example.com-cert.pem
│       │           │   ├── config.yaml
│       │           │   ├── keystore
│       │           │   │   └── priv_sk
│       │           │   ├── signcerts
│       │           │   │   └── [email protected]
│       │           │   └── tlscacerts
│       │           │       └── tlsca.org1.example.com-cert.pem
│       │           └── tls
│       │               ├── ca.crt
│       │               ├── client.crt
│       │               └── client.key
│       └── org2.example.com
│           ├── ca
│           │   ├── ca.org2.example.com-cert.pem
│           │   └── priv_sk
│           ├── connection-org2.json
│           ├── connection-org2.yaml
│           ├── msp
│           │   ├── admincerts
│           │   ├── cacerts
│           │   │   └── ca.org2.example.com-cert.pem
│           │   ├── config.yaml
│           │   └── tlscacerts
│           │       └── tlsca.org2.example.com-cert.pem
│           ├── peers
│           │   └── peer0.org2.example.com
│           │       ├── msp
│           │       │   ├── admincerts
│           │       │   ├── cacerts
│           │       │   │   └── ca.org2.example.com-cert.pem
│           │       │   ├── config.yaml
│           │       │   ├── keystore
│           │       │   │   └── priv_sk
│           │       │   ├── signcerts
│           │       │   │   └── peer0.org2.example.com-cert.pem
│           │       │   └── tlscacerts
│           │       │       └── tlsca.org2.example.com-cert.pem
│           │       └── tls
│           │           ├── ca.crt
│           │           ├── server.crt
│           │           └── server.key
│           ├── tlsca
│           │   ├── priv_sk
│           │   └── tlsca.org2.example.com-cert.pem
│           └── users
│               ├── [email protected]
│               │   ├── msp
│               │   │   ├── admincerts
│               │   │   ├── cacerts
│               │   │   │   └── ca.org2.example.com-cert.pem
│               │   │   ├── config.yaml
│               │   │   ├── keystore
│               │   │   │   └── priv_sk
│               │   │   ├── signcerts
│               │   │   │   └── [email protected]
│               │   │   └── tlscacerts
│               │   │       └── tlsca.org2.example.com-cert.pem
│               │   └── tls
│               │       ├── ca.crt
│               │       ├── client.crt
│               │       └── client.key
│               └── [email protected]
│                   ├── msp
│                   │   ├── admincerts
│                   │   ├── cacerts
│                   │   │   └── ca.org2.example.com-cert.pem
│                   │   ├── config.yaml
│                   │   ├── keystore
│                   │   │   └── priv_sk
│                   │   ├── signcerts
│                   │   │   └── [email protected]
│                   │   └── tlscacerts
│                   │       └── tlsca.org2.example.com-cert.pem
│                   └── tls
│                       ├── ca.crt
│                       ├── client.crt
│                       └── client.key
├── prometheus-grafana
│   ├── docker-compose.yaml
│   ├── grafana
│   │   ├── config.monitoring
│   │   └── provisioning
│   │       ├── dashboards
│   │       │   ├── dashboard.yml
│   │       │   └── hlf-performances.json
│   │       └── datasources
│   │           └── datasource.yml
│   ├── grafana_db
│   │   └── grafana.db
│   ├── prometheus
│   │   └── prometheus.yml
│   └── README.md
├── README.md
├── scripts
│   ├── ccutils.sh
│   ├── configUpdate.sh
│   ├── createChannel.sh
│   ├── deployCCAAS.sh
│   ├── deployCC.sh
│   ├── envVar.sh
│   ├── org3-scripts
│   │   ├── joinChannel.sh
│   │   └── updateChannelConfig.sh
│   ├── pkgcc.sh
│   ├── setAnchorPeer.sh
│   └── utils.sh
├── setOrgEnv.sh
└── system-genesis-block

9. ファブリック CA の使用

Hyperledger Fabric は、公開キー基盤 (PKI) を使用して、すべてのネットワーク参加者のアクションを検証します。トランザクションを送信するすべてのノード、ネットワーク管理者、およびユーザーは、身元を確認するために公開証明書と秘密キーを持っている必要があります。これらの ID には、これらの証明書がネットワークのメンバーである組織によって発行されたものであることを識別する有効な信頼のルートが必要です。network.sh スクリプトは、ピアノードを作成してノードを順序付ける前に、ネットワークの展開と実行に必要なすべての暗号化マテリアルを作成します。

  1. デフォルトの network.sh スクリプトは、cryptogen ツールを使用して証明書とキーを作成します。
  2. cryptogen ツールは、開発およびテスト環境で使用されます (有効な信頼ルートを持つファブリック組織に必要な暗号化マテリアルを迅速に作成するため)。

cryptogen ツールは、Org1、Org2、および Orderer Org の証明書とキーを作成します。
ここに画像の説明を挿入

テストと運用の両方で CA を使用して組織 ID を作成できます。
運用環境: 各組織は CA (または複数の中間 CA) を実行します。
組織によって実行される CA によって作成されたすべての ID は、単一の信頼のルートを共有します。

# 使用CA启动测试网络
./network down
./network.sh up -ca
# network.sh会调用organizations/fabric-ca/registerEnroll.sh脚本生成加密文件

ここに画像の説明を挿入
ここに画像の説明を挿入

Fabric CA クライアントを使用して、ノード ID とユーザー ID を各組織の CA に登録します。

  1. スクリプトは、enroll コマンドを使用して ID ごとに MSP フォルダーを生成します。
  2. MSP フォルダーには、各 ID の証明書と秘密キーが含まれており、CA を運用する組織内での ID の役割とメンバーシップを確立します。
# 查看MSP文件夹内容
tree organizations/peerOrganizations/org1.example.com/users/[email protected]/
# organizations/peerOrganizations/org1.example.com
# 使用cryptogen生成的结构
│       │   └── users
│       │       ├── [email protected]
│       │       │   ├── msp
│       │       │   │   ├── admincerts
│       │       │   │   ├── cacerts
│       │       │   │   │   └── ca.org1.example.com-cert.pem
│       │       │   │   ├── config.yaml
│       │       │   │   ├── keystore
│       │       │   │   │   └── priv_sk
│       │       │   │   ├── signcerts
│       │       │   │   │   └── [email protected]
│       │       │   │   └── tlscacerts
│       │       │   │       └── tlsca.org1.example.com-cert.pem
│       │       │   └── tls
│       │       │       ├── ca.crt
│       │       │       ├── client.crt
│       │       │       └── client.key

# 使用CA后的结构
│       │   └── users
│       │       ├── [email protected]
│       │       │   └── msp
│       │       │       ├── cacerts
│       │       │       │   └── localhost-7054-ca-org1.pem
│       │       │       ├── config.yaml
│       │       │       ├── IssuerPublicKey
│       │       │       ├── IssuerRevocationPublicKey
│       │       │       ├── keystore
│       │       │       │   └── 9f6fe34d35072af8dbfb800ba739fb0e7978d4340bf77333e2ac62c138732d39_sk
│       │       │       ├── signcerts
│       │       │       │   └── cert.pem
│       │       │       └── user

ユーザー証明書の管理:signcerts/cert.pem
秘密鍵:keystore/xxxx_sk

証明書の内容を表示する

cd fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/msp/signcerts

openssl x509 -in cert.pem -inform pem -noout -text

おすすめ

転載: blog.csdn.net/u010895512/article/details/131095387