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

Benchmarking with Hyperledger Caliper for Hyperledger fabric which are in different machine

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

Error: Could not find details for contract 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, totalWorkers, roundIndex, roundArguments, sutAdapter, 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,
           contractFunction: 'GetAllAssetCategory',
           invokerIdentity: 'adminorg1',
           contractArguments: [],
           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,
               contractFunction: 'GetAllAssetCategory',
               invokerIdentity: 'adminorg1',
               contractArguments: [],
               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","content":{},"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","recipients":["all"],"type":"exit","content":{},"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

但订购者和 CA 的 none 显示使用网关作为事务提交的 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, url:grpcs://localhost:7050, connected:false, 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, connected:false, 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, url:grpcs://localhost:7051, connected:false, 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 fabric 的示例和完整配置。


起始卡尺:

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, totalWorkers, roundIndex, roundArguments, sutAdapter, 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,
           contractFunction: 'GetAllAssetCategory',
           invokerIdentity: 'adminorg1',
           contractArguments: [],
           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,
               contractFunction: 'GetAllAssetCategory',
               invokerIdentity: 'adminorg1',
               contractArguments: [],
               readOnly: false
           };
 
           await this.sutAdapter.sendRequests(request);
       }
   }
}
 
function createWorkloadModule() {
   return new MyWorkload();
}
 
module.exports.createWorkloadModule = createWorkloadModule;