CLIを使用したチェーンコードのデプロイ

チェーンコード・プロジェクトが作成されると、自動的に生成されたHyperledger Fabricネットワークにローカルにデプロイするか、Oracle Blockchain Platform CloudまたはEnterprise Editionにリモートにデプロイできます。チェーンコード・プロジェクトをパッケージ化して、Oracle Blockchain Platformに手動でデプロイすることもできます。

ローカルHyperledger Fabricネットワークへのチェーンコードのデプロイ

チェーンコード・プロジェクトを作成したら、ローカルHyperledger Fabricネットワークにデプロイできます。この基本的な単一チャネル・ネットワークは、ブロックチェーン・アプリケーション・ビルダーのインストール時に作成されます。

ブロックチェーン・アプリケーション・ビルダーのochain runコマンドは、Hyperledger Fabricネットワークおよびその他のサービスを起動し、チェーンコードをインストールしてインスタンス化します。

my-mac:GOProject myname$ ochain run -h
Usage: run [options] [...args]
Run chaincode project locally in debug mode.

Arguments :
[...args] (optional) Chaincode instantiate arguments. Arguments should be space separated.

Options:
-h, --help        output command usage information 
-D, --debug       enable debug logging
-P, --debug-port  (optional) specify debug process port
-b, --build       (optional) rebuild runtime if already exists
-p, --project     (optional) Path to Chaincode project to run. If not specified, it defaults to current directory.  

Examples :
$> ochain run   

デバッグ・ログを表示する場合は、--debugオプションをコマンドに渡すことができます。--portオプションをコマンドに渡すことで、基本ネットワークを実行し、チェーンコードをデフォルトとは異なるポートにデプロイできます。

確認

次のログは、チェーンコードが正常にインストールおよびインスタンス化されたことを示しています。

my-mac:TSProject myname$ ochain run
Recreating orderer.example.com ... done
Recreating ca.example.com ... done
Recreating peer0.org1.example.com ... done
[2020-09-23T18: 04:09.132] [INFO] default -
============ Started Install Chaincode ============
[2020-09-23T18:04:09.193] [INFO] default Chaincode TSProject:l not installed.
[2020-09-23T18:04:09.317] [INFO] default - Successfully sent install Proposal and received ProposalResponse
[2020-09-23T18:04:09.317] [INFO] default - Successfully installed chaincode TSProject
[2020-09-23T18:04:09.317] [INFO] default -
============ Finished Install Chaincode ============
[2020-09-23T18:04:09.317] [INFO] default - Successfully installed chaincode TSProject
[2020-09-23T18:04:09.318] [INFO] default -
============ started instantiate Chaincode ============
[2020-09-23T18:04:09.366] [INFO] default - Successfully sent Proposal and received ProposalResponse
[2020-09-23T18:04:11.434] [INFO] default - The chaincode instantiate transaction has been committed on peer localhost:7051
[2020-09-23T18:04:11.434] [INFO] default - The chaincode instantiate transaction was valid.
[2020-09-23T18:04:11.435] [INFO] default - Successfully sent transaction to the orderer.
[2020-09-23T18:04:11.435] [INFO] default - Successfully instantiated chaincode TSProject on channel mychannel
[2020-09-23T18:04:11.435] [INFO] default - 
============ Finished instantiate Chaincode ============
[2020-09-23T18:04:11.4351 INFO] default - Successfully instantiated chaincode TSProject on channel mychannel 
INFO (Runtime): Chaincode TSProject installed and ready:
INFO (RunCommand): Chaincode TSProject deployed

トラブルシューティング

チェーンコード・プロジェクトをローカル・ネットワークで実行すると、次の問題が発生する場合があります。

Go権限の欠落
Goチェーンコード・プロジェクトをローカル・ネットワークにインストール中に、次のようなエラーが表示される場合があります:
My-Mac:GoProj myname$ ochain run
Starting ca.example.com    ... done
Starting orderer.example.com ... done
Starting peer0.orgl.example.com ... done
INFO (Runtime): 2020/06/22 22:57:09 build started

INFO (Runtime): Building ....

INFO (Runtime): go build runtime/cgo: copying /Users/myname/Library/Caches/go-build/f8/.….….d: open /usr/local/go/pkg/darwin_amd64/runtine/ 
cgo.a: permission denied

ERROR (Runtime): go build runtine/cgo: copying /Users/myname/Library/Caches/go-build/f8/.….….d: open /usr/local/go/pkg/darwin_amd64/runtime/
cgo.a: permission denied

INFO (Runtime): An error occurred while building: exit status 1

Stopping peer0.orgl.exmple.com ... done 
Stopping ca.example.com	... done
Stopping orderer.example.con ... done
これは、Goに対する権限がないことが原因です。このエラーはMac OSでのみ表示されています。これは既知の問題です:
解決策: $GOROOTの権限を変更し、ochain runを再試行します:
sudo chmod -R 777 /usr/local/go
インスタンス化の失敗
インスタンス化が失敗したか、インスタンス化が破損したか、Dockerピア・コンテナがいっぱいになったか、Dockerピアがローカル・ネットワークで強制終了されたため、次のようなエラーが表示される場合があります:
============ Started instantiate Chaincode ============
[2028-19-01T19:25:lO.372] [ERROR] default - Error instantiating Chaincode GollGl on channel mychannel, detailed 
error: Error: error starting container: error starting container: Failed to generate platform-specific docker 
build: Failed to pull hyperledger/fabric-ccenv:latest : API error (404): manifest for hyperledger/ 
fabric-ccenv:latest not found: manifest unknown: manifest unknown [2020-19-01T19:25:10.372] (INFO) default -
============ Finished instantiate Chaincode ============
[2020-19-01119:25:10.372] [ERROR] default - Error: Error instantiating Chaincode Goll01 on channel mychannel, 
detailed error: Error: error starting container: error starting container: Failed to generate platfom-specific 
docker build: Failed to pull hyperledger/fabric-ccenv: latest : API error (404): manifest for hyperledger/ 
fabric-ccenv:lalest not found: manifest unknown: manifest unknown exited: signal: terminated 
INFO: exited: signal: terminated

ERROR: Error in Chaincode deployment
これは、ピア・コンテナが正しく再起動できないことが原因です。
解決策: ochain runコマンドを再試行しますが、-bオプションを指定します。このオプションでは、ランタイムが自動的に再構築されます。
ochain run -b
環境の再構築が必要な場合
次のようなエラーが表示されることがあります:
Starting ca.example.com ... 
Starting orderer.example.com ... 
Starting orderer.example.com ... error
ERROR: for orderer.example.com  
Cannot start service orderer.example.com: 
error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/config': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted
Starting ca.example.com... error
ERROR: for ca.example.com  
Cannot start service ca.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/crypto-config/peerOrganizations/org1.example.com/ca': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted
ERROR: for orderer.example.com  
Cannot start service orderer.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/config': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted
ERROR: for ca.example.com  
Cannot start service ca.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/crypto-config/peerOrganizations/org1.example.com/ca': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted
Encountered errors while bringing up the project.
ERROR: Starting ca.example.com ... 
Starting orderer.example.com ... 
Starting orderer.example.com ... error
ERROR: for orderer.example.com  
Cannot start service orderer.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/config': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted
Starting ca.example.com ... error
ERROR: for ca.example.com  
Cannot start service ca.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/crypto-config/peerOrganizations/org1.example.com/ca': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted
ERROR: for orderer.example.com  
Cannot start service orderer.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/config': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted
ERROR: for ca.example.com  
Cannot start service ca.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/crypto-config/peerOrganizations/org1.example.com/ca': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted
Encountered errors while bringing up the project.
ERROR: Error in Chaincode deployment
ローカル環境を再構築する必要があります:
ochain run -b

リモートOracle Blockchain Platformネットワークへのチェーンコードのデプロイ

チェーンコード・プロジェクトをローカル・ネットワークでインスタンス化およびテストして、設計どおりに動作することを確認したら、Oracle Blockchain Platformにデプロイできます。

接続プロファイルの作成

Oracle Blockchain Platform CloudまたはEnterpriseインスタンスから接続プロファイルをダウンロードするには、インスタンスのコンソールで、開発者ツール・タブ、アプリケーション開発開発パッケージのダウンロードの順に移動します。ダウンロードしたパッケージを解凍します。内容は次のようになります:
artifacts
    crypto
        ordererOrganizations
        peerOrganizations
network.yaml

インスタンスのコンソールから管理資格証明を取得します。「ネットワーク」タブで、リストから組織を見つけます。組織の「その他のアクション」アイコンをクリックし、組織からの管理資格証明のエクスポートを選択します。

  1. 管理資格証明からartifacts/crypto/ordererOrganizations/<instance-name>/signcert/<instance-name>-signcert.pemおよびartifacts/crypto/peerOrganizations/<instance-name>/signcert/<instance-name>-signcert.pemに管理者証明書をコピーします。
  2. 管理資格証明からartifacts/crypto/ordererOrganizations/<instance-name>/keystore/<instance-name>-key.pemおよびartifacts/crypto/peerOrganizations/<instance-name>/keystore/<instance-name>-key.pemに管理キーをコピーします。

ノート:

プロジェクト・フォルダに接続プロファイルを配置する場合、これをGithubなどのコンテンツ・リポジトリと同期すると、誤って秘密キーを共有する可能性があることに注意してください。プライベートなすべてのものが.gitignoreファイルに追加されていることを確認します。

ochain loginコマンドを使用したログイン

デプロイする前に、Oracle Blockchain Platformインスタンスにログインする必要があります。ochain loginコマンドは、認証およびログインに役立ちます。これを使用すると、ユーザー名とパスワードの入力を求められます。ユーザー名とパスワードは、ブロックチェーン・インスタンスの詳細と同じです。

ノート:

チェーンコードをリモートのOracle Blockchain Platform Cloudインスタンスにデプロイする前に、ochain loginを実行する必要があります。

使用方法: ochain login [options]

このコマンドでは、次の引数を使用できます:
my-mac:TSProject myname$ ochain login -h 
Usage: login [options]
Login to Oracle Blockchain Cloud Service instance 

Options :
    -h, --help            output command usage information
    -0, --debug           enable debug logging
    -P, --project         (optional) Path to Chaincode project to deploy. If not specified, it defaults to current directory.
    -d, --obp-dev-package (optional) Path to the downloaded and unzipped Oracle Blockchain Development Package. If not specified, it defaults to CURRENT_DIRECTORY/obp
    -u, --username        (optional) A user name that has install chaincode privileges. Contact your administrator for more details.
    -p, --password        (optional) user password. 

Examples:
$> ochain login
$> ochain login -u john.doe
S> ochain login -u john.doe -p MyPassword!

loginコマンドは、ダウンロードしたOracle Blockchain Development接続プロファイルへのパスを-dオプションで使用します。指定しない場合、デフォルトは<current_project_directory>/obpです

ログインに成功すると、「ログインに成功」を示すメッセージが返されます。

デプロイ

使用方法: ochain deploy [options] [...args]

次に、ochain deployコマンドで使用される引数およびオプションを示します:

my-mac:TSProject myname$ ochain deploy -h 
Usage: deploy [options] [...args]
Deploy chaincode project to Oracle Blockchain Cloud Service

Arguments:
     [...args]    (optional) Chaincode instantiate arguments. Arguments should be comma separated.
 
Options :
    -h, --help               output command usage information
    -0, --debug              enable debug logging
    -P, --project            (optional) Path to Chaincode project to deploy. If not specified, it defaults to current directory.
    -d, --obp-dev-package    (optional) Path to the downloaded and unzipped Oracle Blockchain Development Package. If not specified, it defaults to CURRENT_DIRECTORY/obp
    -c, --channel            (optional) Blockchain Platform channel to deploy chaincode to. If not specified, defaults to the 'default' channel.
    -u, --wait               (optional) GRPC wait for ready timeout in milliseconds.
    -p, --username           (optional) A user name that has install chaincode privileges. Contact your administrator for more details.
    -v, --userversion        (optional) A user-specified chaincode version.
                             If a version isn't specified, for a new chaincode it will start at v1 and then increment to v2, v3, and so on.
                             For an existing chaincode, v1.a will increment to v1.a1, v1 will increment to v2, and v1.0 will increment to v1.1.

Examples:
$> ochain deploy -u john.doe -d <path to connection profile> -c channelname
チェーンコードがリモートのOracle Blockchain Platformに正常にデプロイされると、ログに次の内容が表示されます:
  • チェーンコード・プロジェクトが正常にインストールされました。
  • 各ピアおよびチャネルでチェーンコードが正常にインスタンス化されました。

チェーンコード・プロジェクトの更新

チェーンコードのアップグレードは、ブロックチェーン・アプリケーション・ビルダーによって自動的に処理されます。チェーンコードを変更した後、ochain deployコマンドを再度コールします。これにより、更新が自動的に実行されます。

更新が成功すると、ログに次のように表示されます
  • チェーンコード・バージョンが正常にアップグレードされました(たとえば、バージョン1.0から2.0へ)。
  • チェーンコード・プロジェクトが正常にインストールされました。
  • 各ピアおよびチャネルでチェーンコードが正常にインスタンス化されました。

デプロイメントのトラブルシューティング

チェーンコード・プロジェクトをOracle Blockchain Platformにデプロイする際に、次の問題が発生する場合があります:

GRPCタイムアウト・エラー
リモートのOracle Blockchain Platformネットワークへのデプロイ中に、次のGRPCタイムアウト・エラーが発生することがあります:
[2020-09-23T18:40:17.923] [ERROR] default - Error Invoking chaincode "TSProject:" Failed to connect
before the deadline
これは、ネットワークの問題が発生しているか、GRPC待機タイムアウトの期限が切れている可能性があります。
-w <timeout>オプションを指定してチェーンコードを再度デプロイします。デフォルトでは、タイムアウトは10000ミリ秒に設定されています。
> ochain deploy -u idcqa -d /Blockchain/DevTools/bp1/oraclebp1-instance-info -w 30000

Oracle Blockchain Platformへの手動デプロイメント用のチェーンコード・プロジェクトのパッケージ化

チェーンコード・プロジェクトをパッケージ化して、Oracle Blockchain Platform CloudまたはEnterprise Editionに手動でデプロイできます。

使用方法: ochain package

パッケージ関数は、ビルド・ファイルと配布ファイルのみを含むzipファイルを作成します。チェーンコード・プロジェクトのbinarylibsnode_modulesおよびtestフォルダは含まれません。このzipは、デプロイメントのためにOracle Blockchain Platformに手動でアップロードできます。

my-mac:~ myname$ ochain package -h 
Usage: package [options]
Package and archive an Ochain chaincode project 
Options :
    -h, --help             output command usage information
    -D, --debug            enable debug logging
    -p, --project <path>   Path to the Ochain chaincode project to be packaged. If not specified, it defaults to current directory.
    -o, --out <path>       Path to the generated chaincode archive file. If not specified, it defaults to current directory.
About:
This CLI command packages and archives an existing chaincode project 
Examples:
$> ochain package --project <Path to the Ochain chaicode project> —out <Path to the generated chaincode archive file>

コマンドが正常に完了すると、パッケージの場所が返されます。

このコマンドは次の2つのオプションの引数を使用します:
  • --project

    このオプションは、パッケージ化するブロックチェーン・アプリケーション・ビルダーのチェーンコード・プロジェクトの場所を定義します。指定しない場合は、デフォルトで現在のディレクトリが使用されます。

  • --out

    このオプションを使用すると、生成されたアーカイブ・ファイルの出力パスを指定できます。指定しない場合は、デフォルトで現在のディレクトリが使用されます。

例:
> ochain package -p /Blockchain/DevTools/bp1/CC -o /Blockchain/DevTools/bp1/output

"Your chaincode project has been packaged at /Blockchain/DevTools/bp1/output/CC.zip"