hyperledger / caliper

A blockchain benchmark framework to measure performance of multiple blockchain solutions https://wiki.hyperledger.org/display/caliper
https://hyperledger.github.io/caliper/
Apache License 2.0
650 stars 403 forks source link

how to support a chaincode interact with other one? #1450

Open kangkang333 opened 1 year ago

kangkang333 commented 1 year ago

Please share the technical limitation of Caliper that you encountered.

  1. Hyperledger Fabric
  2. My case: there is a channel called mychannel, and it has two chaincode: basic1 and basic2 I use ctx.GetStub().InvokeChaincode in function "basic1CommWithbasic2" to implement basic1 updates basic2's ledger
  3. Now I want to use caliper to test the throughput of the above case [ networkConfig.yaml] name: Calier test version: "2.0.0" caliper: blockchain: fabric channels:
    • channelName: mychannel contracts:
    • id: basic1
    • id: basic2 organizations:
    • mspid: Org1MSP identities: certificates:
      • name: 'User1' clientPrivateKey: path: '../fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/keystore/priv_sk' clientSignedCert: path: '../fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/signcerts/User1@org1.example.com-cert.pem' connectionProfile: path: '../fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/connection-org1.yaml' discover: true

[Benckmark.yaml] test: name: basic-contract-benchmark description: test benchmark workers: number: 2 rounds:

class MyWorkload extends WorkloadModuleBase { constructor() { super(); }

async initializeWorkloadModule(workerIndex, totalWorkers, roundIndex, roundArguments, sutAdapter, sutContext) {
    await super.initializeWorkloadModule(workerIndex, totalWorkers, roundIndex, roundArguments, sutAdapter, sutContext);

    for (let i=0; i<this.roundArguments.assets; i++) {
        const assetID = `${this.workerIndex}_${i}`;
        console.log(`Worker ${this.workerIndex}: Creating asset ${assetID}`);
        const request = {
            contractId: this.roundArguments.contractId,
            contractFunction: 'CreateAsset',
            invokerIdentity: 'User1',
            contractArguments: [assetID,"Alice"],
            readOnly: false
        };

        await this.sutAdapter.sendRequests(request);         
    }
}

async submitTransaction() {
    const randomId = Math.floor(Math.random()*this.roundArguments.assets);  

        const myArgs = {
        contractId: this.roundArguments.contractId,
        contractFunction: 'basic1CommWithbasic2',
        invokerIdentity: 'User1',
        contractArguments: [`${this.workerIndex}_${randomId}`,"Alice","a/b/c"],
        readOnly: false
    };       

    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: 'DeleteAsset',
            invokerIdentity: 'User1',
            contractArguments: [assetID],
            readOnly: false
        };

        await this.sutAdapter.sendRequests(request);
    }
}

} function createWorkloadModule() { return new MyWorkload(); } module.exports.createWorkloadModule = createWorkloadModule;

  1. when I run "npx caliper launch manager --caliper-workspace ./ --caliper-networkconfig networks/networkConfig.yaml --caliper-benchconfigenchmark.yaml --caliper-flow-only-test"
  2. result : all test cases are failed, and Hyperledger Fabric gets refused connection

Please detail your feature idea that could alleviate the limitation.

how to test basic1 chaincode update basic2's ledger , in which basic1 and basic2 are in the same channel

Please share some details about your use case if possible, and how the new feature would make Caliper a better performance benchmarking framework.

No response

Please share any suggestions about the new feature's code/configuration API (using formatted YAML segments or pseudo-code).

No response

davidkel commented 1 year ago

Caliper like any other hyperledger fabric client that interacts with chaincode has no knowledge of what the chaincode does internally so the issue here is not about caliper not being able to support whether a chaincode may invoke another chaincode on the same channel, the only complication that can occur will be with whether it collects the right endorsements as binding to fabric:2.2 or fabric:1.4 and just relying on discovery may not be enough unless discovery hints are provided, in that case you need to use organisation targeting. If you are using fabric 2.4 and thus can bind to fabric:2.4 then more intelligence is built into the gateway peer service to address this so org targeting isn't required.

However you say access is refused which isn't very meaningful so more detail and the exact error messages would help however usually when access is refused is that usually the wrong identity has been used

kangkang333 commented 1 year ago
  1. " If you are using fabric 2.4 and thus can bind to fabric:2.4 "

1) I try this command to bind to fabric:2.4: npx caliper bind --caliper-bind-sut fabric:2.4 2) However, there is also the problem

  1. “However you say access is refused which isn't very meaningful so more detail ”

1) the detailed information on the caliper is as follows: error [caliper] [connectors/peer-gateway/PeerGateway] Failed to perform submit transaction [basic1CommWithbasic2] using arguments [1_9,Alice,a/b/c], with error: EndorseError: 14 UNAVAILABLE: No connection established

2) And after I use the caliper, the fabric network could not run other commands: Note: before I use the caliper, the fabric network works well

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":[]}'

Error: error getting endorser client for invoke: endorser client failed to connect to localhost:7051: failed to create new connection: connection error: desc = "transport: error while dialing: dial tcp [::1]:7051: connect: connection refused

  1. When I use the function "basic1CommWithbasic2" in the fabric network directly, it works
kangkang333 commented 1 year ago

“then more intelligence is built into the gateway peer service to address this so org targeting isn't required”

I want to know how to "built into the gateway peer service"

davidkel commented 1 year ago

Looks like you are running test network, and I assume that caliper and test-network are running on the same machine given the reference to localhost

The message

Error: error getting endorser client for invoke: endorser client failed to connect to localhost:7051: failed to create new connection: connection error: desc = "transport: error while dialing: dial tcp [::1]:7051: connect: connection refused

says that nothing is listening on localhost:7051 therefore if you are running that command on the same machine as test network (which uses docker) then either the peer process has terminated or the port mapping in docker is not working. You should check the state of the docker containers to see if they have terminated and also inspect the logs of the peer and the state of your test-network in general

Caliper should not cause a peer to terminate, but it is a load generator so there is the potential to overload a fabric network.

kangkang333 commented 1 year ago

Looks like you are running test network, and I assume that caliper and test-network are running on the same machine given the reference to localhost

The message

Error: error getting endorser client for invoke: endorser client failed to connect to localhost:7051: failed to create new connection: connection error: desc = "transport: error while dialing: dial tcp [::1]:7051: connect: connection refused

says that nothing is listening on localhost:7051 therefore if you are running that command on the same machine as test network (which uses docker) then either the peer process has terminated or the port mapping in docker is not working. You should check the state of the docker containers to see if they have terminated and also inspect the logs of the peer and the state of your test-network in general

Caliper should not cause a peer to terminate, but it is a load generator so there is the potential to overload a fabric network.

When I reduce the number of transactions, its works, thanks

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.