使用 Hyperledger Caliper 对不同机器中的 Hyperledger 结构进行基准测试

问题描述

Caliper (v.0.4.2) 已安装并在我的机器(笔记本电脑)上设置配置,并准备与 google-cloud 中现有的已部署结构网络进行通信。为了通信这两个卡尺和结构网络,我提供了 org1(部署我的合约的位置)的连接配置文件。我发现错误并没有解决
如何解决这个错误

错误:找不到合同 ID 的详细信息


以下是找到给定问题的解决方案的信息。


Caliper 正在使用以下命令启动

gopal@gopal:~/workspace/newcalliper/caliper-workspace$ npx caliper launch manager --caliper-workspace ./ --caliper-networkconfig networks/networkConfig.yaml --caliper-benchconfig benchmarks/myAssetBenchmark.yaml --caliper-flow-only-test --caliper-fabric-gateway-enabled

网络配置上的设置:

name: Fabric Calier test network
version: "2.0.0"
 
caliper:
 blockchain: fabric
 sutoptions:
   mutualTls: false
channels:
 - channelName: mychannel
   contract:
   - id: abc
 
organizations:
 - mspid: Org1MSP
   identities:
     certificates:
     - name: 'adminorg1'
       admin: true
       clientPrivateKey:
         path: '../fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/crypto-config/peerOrganizations/org1.example.com/msp/keystore/key.pem'
 
       clientSignedCert:
         path: '../fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/crypto-config/peerOrganizations/org1.example.com/msp/signcerts/cert.pem'
   connectionProfile:
     path: '../fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/connection-org1.yaml'
     discover: false

基准配置:

test:
    name: basic-contract-benchmark
    description: test benchmark
    workers:
      type: local
      number: 1
    rounds:
      - label: readAsset
        description: Read asset benchmark
        txDuration: 5
        rateControl: 
          type: fixed-load
          opts:
            transactionLoad: 1
        workload:
          module: workload/readAsset.js
          arguments:
            contractId: abc

readAsset.js 并提交交易:

'use strict';
 
const { WorkloadModuleBase } = require('@hyperledger/caliper-core');
 
class MyWorkload extends WorkloadModuleBase {
   constructor() {
       super();
   }
   // this initializeWorkloadModule is called by the workloadeModuleBase.js from the caliper inside.
   //and send to sutAdptor as a request to simulate.
   async initializeWorkloadModule(workerIndex,totalWorkers,roundindex,roundArguments,sutAdapter,sutContext) {
       await super.initializeWorkloadModule(workerIndex,sutContext);
           const request = {
               contractId: this.roundArguments.contractId,contractFunction: 'GetAllAssetCategory',invokerIdentity: 'adminorg1',contractArguments: [],readOnly: false
           };
           await this.sutAdapter.sendRequests(request);
   }
 
   async submitTransaction() {
       const myArgs = {
           contractId:this.roundArguments.contractId,readOnly: false,targetPeers:['peer0.org1.exmple.com'],targetorganizations:['peer0.org1.example.com'],orderer:['orderer0.org1.example.com'],channel:['mychannel']
       };
      
       await this.sutAdapter.sendRequests(myArgs);
   }
   async cleanupWorkloadModule() {
       for (let i=0; i<this.roundArguments.assets; i++) {
           const assetID = `${this.workerIndex}_${i}`;
           console.log(`Worker ${this.workerIndex}: Deleting asset ${assetID}`);
           const request = {
               contractId: this.roundArguments.contractId,readOnly: false
           };
 
           await this.sutAdapter.sendRequests(request);
       }
   }
}
 
function createWorkloadModule() {
   return new MyWorkload();
}
 
module.exports.createWorkloadModule = createWorkloadModule;

卡尺日志:

2021.01.26-23:11:54.759[32m info [39m [caliper] [caliper-worker]    Info: worker 0 prepare test phase for round 0 is starting...
2021.01.26-23:11:54.764[90m debug[39m [caliper] [workload-module-base]  Workload module initialized with: workerIndex=0,totalWorkers=1,roundindex=0,roundArguments={"contractId":"abc"}
**2021.01.26-23:11:54.771[32m info [39m [caliper] [caliper-worker]  Worker [0] encountered an error during prepare test phase for round 0: Error: Could not find details for contract ID abc
    at V2FabricGateway._sendSingleRequest (/home/gopal/node_modules/@hyperledger/caliper-fabric/lib/connector-versions/v2/FabricGateway.js:156:23)**
    at V2FabricGateway.sendRequests (/home/gopal/node_modules/@hyperledger/caliper-core/lib/common/core/connector-base.js:78:39)
    at MyWorkload.initializeWorkloadModule (/home/gopal/workspace/newcalliper/caliper-workspace/workload/readAsset.js:20:35)
    at process._tickCallback (internal/process/next_tick.js:68:7)
2021.01.26-23:11:54.772[32m info [39m [caliper] [caliper-worker]    Info: worker 0 prepare test phase for round 0 is completed
2021.01.26-23:11:54.773[90m debug[39m [caliper] [process-messenger]     Process "10624" sent message: {"sender":"10624","recipients":["10611"],"type":"prepared","content":{},"date":"2021-01-26T17:26:54.773Z","error":"Error: Could not find details for contract ID abc"}
2021.01.26-23:11:54.774[31m error[39m [caliper] [worker-message-handler]    Error while handling "prepare" message for Worker (10624): Error: Could not find details for contract ID abc
    at V2FabricGateway._sendSingleRequest (/home/gopal/node_modules/@hyperledger/caliper-fabric/lib/connector-versions/v2/FabricGateway.js:156:23)
    at V2FabricGateway.sendRequests (/home/gopal/node_modules/@hyperledger/caliper-core/lib/common/core/connector-base.js:78:39)
    at MyWorkload.initializeWorkloadModule (/home/gopal/workspace/newcalliper/caliper-workspace/workload/readAsset.js:20:35)
    at process._tickCallback (internal/process/next_tick.js:68:7)
2021.01.26-23:11:54.793[90m debug[39m [caliper] [process-messenger]     Process "10624" handling message: {"sender":"10611","recipients":["all"],"type":"exit","date":"2021-01-26T17:26:54.793Z"}
2021.01.26-23:11:54.798[90m debug[39m [caliper] [worker-message-handler]    Handling "exit" message for Worker (10624): {"sender":"10611","date":"2021-01-26T17:26:54.793Z"}
2021.01.26-23:11:54.799[32m info [39m [caliper] [worker-message-handler]    Worker#0 is exiting
2021.01.26-23:11:54.799[90m debug[39m [caliper] [worker-message-handler]    Handled "exit" message for Worker (10624)

此外,当 discover: true 用于连接配置文件时,只有对等方将控制台上的信息显示

2021-01-27 14:25:22.811 UTC [comm.grpc.server] 1 -> INFO 098 unary call completed grpc.service=discovery.discovery grpc.method=discover grpc.peer_address=202.52.76.41:33878 grpc.peer_subject="CN=fabric-common" grpc.code=OK grpc.call_duration=1.059889ms

但是 orderer 和 CA 都没有显示使用 gateway 作为交易提交的 caliper 请求的任何信息。卡尺控制台中另外显示以下错误

2021.01.27-19:25:35.887 info [caliper] [connectors/v2/FabricGateway] Successfully connected user with identity adminorg1 to a Network Gateway
2021.01.27-19:25:35.892 info [caliper] [connectors/v2/FabricGateway] Generating contract map for user adminorg1
2021-01-27T13:40:39.803Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Committer- name: orderer0.org1.example.com:7050,url:grpcs://localhost:7050,connected:false,connectAttempted:true
2021-01-27T13:40:39.808Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server orderer0.org1.example.com:7050 url:grpcs://localhost:7050 timeout:3000
2021-01-27T13:40:39.810Z - error: [discoveryService]: _buildOrderer[mychannel] - Unable to connect to the discovered orderer orderer0.org1.example.com:7050 due to Error: Failed to connect before the deadline on Committer- name: orderer0.org1.example.com:7050,connectAttempted:true

2021-01-27T13:40:42.844Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.org1.example.com:7051,url:grpcs://localhost:7051,connectAttempted:true
2021-01-27T13:40:42.844Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.org1.example.com:7051 url:grpcs://localhost:7051 timeout:3000
2021-01-27T13:40:42.845Z - error: [discoveryService]: _buildPeer[mychannel] - Unable to connect to the discovered peer peer0.org1.example.com:7051 due to Error: Failed to connect before the deadline on Endorser- name: peer0.org1.example.com:7051,connectAttempted:true
2021.01.27-19:25:42.854 info [caliper] [caliper-worker] Info: worker 0 prepare test phase for round 0 is starting...
2021.01.27-19:25:42.861 info [caliper] [caliper-worker] Worker [0] encountered an error during prepare test phase for round 0: Error: Could not find details for contract ID abc

编辑:使用 discover 真假案例添加了额外的设置结果以明确定义问题。


谢谢!

解决方法

您的网络配置文件不完整。 Caliper 仍然必须明确知道已部署到您的频道上的链码(又名合约)。 参考教程中的这一部分 https://hyperledger.github.io/caliper/v0.4.2/fabric-tutorial/tutorials-fabric-existing/#populating-the-template-file 您将看到关于 Channels 的部分,其中描述了将有关通道的信息添加到网络配置文件中。例如从那个教程它定义了这个部分

channels:
  - channelName: mychannel
    contracts:
    - id: basic

这表明有一个通道 mychannel 部署了一个合约(链码),ID 为 basic

,

这里是一台机器上的 caliper 配置示例和完整配置,而 hyperledger 结构在另一台机器上。


起始卡尺:

npx caliper launch manager --caliper-workspace ./ --caliper-networkconfig networks/networkConfig.yaml --caliper-benchconfig benchmarks/myAssetBenchmark.yaml --caliper-flow-only-test --caliper-fabric-gateway-enabled --caliper-fabric-gateway-localhost=false

网络配置:

name: Fabric Calier test network
version: "2.0.0"
 
caliper:
 blockchain: fabric
 sutOptions:
   mutualTls: false
channels:
 - channelName: mychannel
   contract:
   - id: abc
 
organizations:
 - mspid: Org1MSP
   identities:
     certificates:
     - name: 'adminorg1'
       admin: true
       clientPrivateKey:
         path: '../fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/crypto-config/peerOrganizations/org1.example.com/msp/keystore/key.pem'
 
       clientSignedCert:
         path: '../fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/crypto-config/peerOrganizations/org1.example.com/msp/signcerts/cert.pem'
   connectionProfile:
     path: '../fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/connection-org1.yaml'
     discover: false

基准配置

test:
    name: basic-contract-benchmark
    description: test benchmark
    workers:
      type: local
      number: 1
    rounds:
      - label: readAsset
        description: Read asset benchmark
        txDuration: 5
        rateControl: 
          type: fixed-load
          opts:
            transactionLoad: 1
        workload:
          module: workload/readAsset.js
          arguments:
            contractId: abc

readAsset.js 并提交交易:

'use strict';
 
const { WorkloadModuleBase } = require('@hyperledger/caliper-core');
 
class MyWorkload extends WorkloadModuleBase {
   constructor() {
       super();
   }
   // this initializeWorkloadModule is called by the workloadeModuleBase.js from the caliper inside.
   //and send to sutAdptor as a request to simulate.
   async initializeWorkloadModule(workerIndex,totalWorkers,roundIndex,roundArguments,sutAdapter,sutContext) {
       await super.initializeWorkloadModule(workerIndex,sutContext);
           const request = {
               contractId: this.roundArguments.contractId,contractFunction: 'GetAllAssetCategory',invokerIdentity: 'adminorg1',contractArguments: [],readOnly: false
           };
           await this.sutAdapter.sendRequests(request);
   }
 
   async submitTransaction() {
       const myArgs = {
           contractId:this.roundArguments.contractId,readOnly: false,targetPeers:['peer0.org1.exmple.com'],targetOrganizations:['peer0.org1.example.com'],orderer:['orderer0.org1.example.com'],channel:['mychannel']
       };
      
       await this.sutAdapter.sendRequests(myArgs);
   }
   async cleanupWorkloadModule() {
       for (let i=0; i<this.roundArguments.assets; i++) {
           const assetID = `${this.workerIndex}_${i}`;
           console.log(`Worker ${this.workerIndex}: Deleting asset ${assetID}`);
           const request = {
               contractId: this.roundArguments.contractId,readOnly: false
           };
 
           await this.sutAdapter.sendRequests(request);
       }
   }
}
 
function createWorkloadModule() {
   return new MyWorkload();
}
 
module.exports.createWorkloadModule = createWorkloadModule;

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...