Error while I run a p. benchmark with Hyperledger Caliper: No valid responses from any peers, chaincode registration failed: container exited with 0 - hyperledger-fabric

I want to run a performance benchmark for the contract (which is writen in typescript) from this repository:https://github.com/AleRapchan/hyperledger-supply-chain
So, I am using Hyperledger Caliper based on this tutorial: https://hyperledger.github.io/caliper/v0.5.0/fabric-tutorial/tutorials-fabric-existing/
to run the performance benchmark and I followed these steps:
Steps followed:
I have clonned this repo as I mentioned before: https://github.com/AleRapchan/hyperledger-supply-chain and, at the same level, I created the caliper-workspace folder as the tutorial said.
I created the channel "mychannel" and deployed the chaincode respectively.
./network.sh up createChannel -ca -s couchdb
./network.sh deployCC -ccn supplychain -ccp ../../chaincode -ccl typescript
I have configured the three caliper files as shown below (myAssetBenchmark.yaml, networkConfig.yaml, readAsset.js) into the caliper-workspace folder.
I have installed the caliper dependencies in the caliper-workspace folder.
npm install --only=prod #hyperledger/caliper-cli#0.5.0
npx caliper bind --caliper-bind-sut fabric:2.2
At the same directory, I run the performance benchmark with the following command:
npx caliper launch manager --caliper-workspace ./ --caliper-networkconfig networks/networkConfig.yaml --caliper-benchconfig benchmarks/myAssetBenchmark.yaml --caliper-flow-only-test
but I got the following errors:
Error 1
error: [Transaction]: Error: No valid responses from any peers. Errors:
peer=peer0.org2.example.com:9051, status=500, message=error in simulation: failed to execute transaction b6cc9ab28537a5539aa0876a823a679a952dee1232540e8efbe1ad01e02ebfbb: could not launch chaincode supplychain_1.0:a38d65123f915a15106ad4d0f8893b0880ed2979ddcc84106b9267f5ee31ddd4: chaincode registration failed: container exited with 0
peer=peer0.org1.example.com:7051, status=500, message=error in simulation: failed to execute transaction b6cc9ab28537a5539aa0876a823a679a952dee1232540e8efbe1ad01e02ebfbb: could not launch chaincode supplychain_1.0:a38d65123f915a15106ad4d0f8893b0880ed2979ddcc84106b9267f5ee31ddd4: chaincode registration failed: container exited with 0
Error 2
error [caliper] [connectors/v2/FabricGateway] Failed to perform submit transaction [createProduct] using arguments [1_0,1234567890,50,Fruit Juices,,2022-06-24T18:25:43.511Z,{},Apple Juice,Etobicoke, ON, Canada,2021-06-24T18:25:43.511Z,$9.00,200,ml], with error: Error: No valid responses from any peers. Errors:
peer=peer0.org2.example.com:9051, status=500, message=error in simulation: failed to execute transaction 5837e5ab8b41016290a3d204f4ffde53bad977e917eb1ae53784623959d4e359: could not launch chaincode supplychain_1.0:a38d65123f915a15106ad4d0f8893b0880ed2979ddcc84106b9267f5ee31ddd4: chaincode registration failed: container exited with 0
peer=peer0.org1.example.com:7051, status=500, message=error in simulation: failed to execute transaction 5837e5ab8b41016290a3d204f4ffde53bad977e917eb1ae53784623959d4e359: could not launch chaincode supplychain_1.0:a38d65123f915a15106ad4d0f8893b0880ed2979ddcc84106b9267f5ee31ddd4: chaincode registration failed: container exited with 0
myAssetBenchmark.yaml
test:
name: basic-contract-benchmark
description: test benchmark
workers:
number: 2
rounds:
- label: readAsset
description: Read asset benchmark
txDuration: 30
rateControl:
type: fixed-load
opts:
transactionLoad: 2
workload:
module: workload/readAsset.js
arguments:
assets: 10
contractId: supplychain
networkConfig.yaml
name: Caliper test
version: "2.0.0"
caliper:
blockchain: fabric
channels:
- channelName: mychannel
contracts:
- id: supplychain
organizations:
- mspid: Org1MSP
identities:
certificates:
- name: 'User1'
clientPrivateKey:
path: '../hyperledger-supply-chain/network/fabric-network/organizations/peerOrganizations/org1.example.com/users/User1#org1.example.com/msp/keystore/46d82eb2dbaed33f941f9a39394bba7b5167d09d116ba563de1675f22b083d3e_sk'
clientSignedCert:
path: '../hyperledger-supply-chain/network/fabric-network/organizations/peerOrganizations/org1.example.com/users/User1#org1.example.com/msp/signcerts/cert.pem'
connectionProfile:
path: '../hyperledger-supply-chain/network/fabric-network/organizations/peerOrganizations/org1.example.com/connection-org1.yaml'
discover: true
readAsset.js
'use strict';
const { WorkloadModuleBase } = require('#hyperledger/caliper-core');
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 id = `${this.workerIndex}_${i}`;
console.log(`Worker ${this.workerIndex}: Creating asset ${id}`);
const request = {
contractId: this.roundArguments.contractId,
contractFunction: 'createProduct',
invokerIdentity: 'User1',
contractArguments: [id, '1234567890', 50, 'Fruit Juices', [],
'2022-06-24T18:25:43.511Z', JSON.stringify({}),'Apple Juice', 'Etobicoke, ON, Canada',
'2021-06-24T18:25:43.511Z','$9.00', 200, 'ml'],
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: 'readProduct',
invokerIdentity: 'User1',
contractArguments: [`${this.workerIndex}_${randomId}`],
readOnly: true
};
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: null,
invokerIdentity: 'User1',
contractArguments: [id],
readOnly: false
};
await this.sutAdapter.sendRequests(request);
}
}
}
function createWorkloadModule() {
return new MyWorkload();
}
module.exports.createWorkloadModule = createWorkloadModule;
PD: I am using WSL2 based engine (Docker Desktop and WSL2).

Related

Validation Error in running Hyperledger Caliper V0.4.2 with Fabric 2.1

When I have been running the Caliper V0.4.2 for measuring the benchmarks of Fabric 2.1.0 1.4.7, I got the below error
ValidationError: child "version" fails because ["version" must be one of [1.0]]. child "clients" fails because ["clients" is required]. child "channels" fails because ["channels" must be an object]. child "organizations" fails because ["organizations" must be an object]. child "orderers" fails because ["orderers" is required]. child "peers" fails because ["peers" is required]
at Object.exports.process (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hapi/joi/lib/errors.js:202:19)
at internals.Object._validateWithOptions (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hapi/joi/lib/types/any/index.js:763:31)
at module.exports.internals.Any.root.validate (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hapi/joi/lib/index.js:145:23)
at Function._validateTopLevel (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hyperledger/caliper-fabric/lib/configValidator.js:208:26)
at Function.validateNetwork (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hyperledger/caliper-fabric/lib/configValidator.js:58:25)
at new FabricConnector (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hyperledger/caliper-fabric/lib/fabric-connector.js:107:25)
at CaliperEngine.connectorFactory [as adapterFactory] (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hyperledger/caliper-fabric/lib/connectorFactory.js:26:23)
at CaliperEngine.run (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hyperledger/caliper-core/lib/manager/caliper-engine.js:93:36)
at Function.handler (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hyperledger/caliper-cli/lib/launch/lib/launchManager.js:62:43)
at Object.module.exports.handler (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hyperledger/caliper-cli/lib/launch/launchManagerCommand.js:46:44)
isJoi: true,
name: 'ValidationError',
details:
[ { message: '"version" must be one of [1.0]',
path: [Array],
type: 'any.allowOnly',
context: [Object] },
{ message: '"clients" is required',
path: [Array],
type: 'any.required',
context: [Object] },
{ message: '"channels" must be an object',
path: [Array],
type: 'object.base',
context: [Object] },
{ message: '"organizations" must be an object',
path: [Array],
type: 'object.base',
context: [Object] },
{ message: '"orderers" is required',
path: [Array],
type: 'any.required',
context: [Object] },
{ message: '"peers" is required',
path: [Array],
type: 'any.required',
context: [Object] } ],
_object:
{ name: 'Caliper Benchmarks',
version: '2.1.0',
caliper: { blockchain: 'fabric' },
channels: [ [Object] ],
organizations: [ [Object] ] },
annotate: [Function] }
Command that I run are,
npm init -y
npm install --only=prod #hyperledger/caliper-cli#0.4.0
npx caliper bind --caliper-bind-sut fabric:2.1
./network.sh deployCC -ccn simple -ccp ../../caliper-benchmarks/src/fabric/scenario/simple/node -ccl javascript
npx caliper launch manager --caliper-workspace ./ --caliper-networkconfig networks/fabric/test-network.yaml --caliper-benchconfig benchmarks/scenario/simple/config.yaml --caliper-flow-only-test --caliper-fabric-gateway-enabled
Hyperledger network creation, channel creation and Chaincode deployment all were successful.
How to solve this error?
Looks like you are using the main branch of caliper-benchmarks. I would suggest you https://github.com/hyperledger/caliper-benchmarks/blob/main/networks/fabric/README.md
From what you have posted, you should use the latest available version of caliper which is 0.4.2, not 0.4.0. To do so the command you should issue is
npm install --only=prod #hyperledger/caliper-cli
You should bind to the latest 2.2 sdk (don't bind to 2.1 as fabric doesn't support 2.1). Note this is selecting the version of the sdk used to interact with a fabric network, not the version of the fabric network you are using. 2.2 will work with a fabric 2.2 and later 2.x versions
npx caliper bind --caliper-bind-sut fabric:2.2
Finally it looks like you tried to change the version number in the network configuration file. Don't change the version (it must be 2.0.0) as it refers to the version of the network configuration file and not the version of fabric you want to test
As you look to be using test-network, depending on which branch of fabric-samples you are using defines the version of fabric. The main branch tests the latest version of fabric which should have no problems.

Error: No valid responses from any peers. Failed to execute transaction could not launch chaincode

I am trying to run the app.js file in the provided asset-transfer-ledger-queries folder with a slight modification.
I made a change to the asset-transfer-ledger-chaincode.js file as shown below:
async CreateAsset(ctx, assetID, color, size, owner, appraisedValue) {
const exists = await this.AssetExists(ctx, assetID);
if (exists) {
throw new Error(`The asset ${assetID} already exists`);
}
// ==== Create asset object and marshal to JSON ====
let asset = {
docType: 'asset',
assetID: assetID,
color: color,
size: size,
owner: owner,
appraisedValue: appraisedValue,
couponID: assetID,
value: color,
expiration: size,
user: sha256(owner),
uuid: uuid.v5(),
redeemed: false
};
basically I just added some properties to the asset object.
After updating the chaincode and running node app.js, I get the following error:
--> Submit Transaction: InitLedger, function creates the initial set of assets on the ledger
2020-12-08T18:22:27.975Z - error: [Transaction]: Error: No valid responses from any peers. Errors:
peer=peer0.org1.example.com:7051, status=500, message=error in simulation: failed to execute transaction 3832a02eeafd57382fb4810bc263d41693764f0d8cb76c27e5613c359b14d42f: could not launch chaincode ledger_1.0:7230409065bcd9da163bc285287935a7d6a3799c99ee59b8a77c93883b607bdb: chaincode registration failed: container exited with 1
peer=peer0.org2.example.com:9051, status=500, message=error in simulation: failed to execute transaction 3832a02eeafd57382fb4810bc263d41693764f0d8cb76c27e5613c359b14d42f: could not launch chaincode ledger_1.0:7230409065bcd9da163bc285287935a7d6a3799c99ee59b8a77c93883b607bdb: chaincode registration failed: container exited with 1
******** initLedger failed :: Error: No valid responses from any peers. Errors:
peer=peer0.org1.example.com:7051, status=500, message=error in simulation: failed to execute transaction 3832a02eeafd57382fb4810bc263d41693764f0d8cb76c27e5613c359b14d42f: could not launch chaincode ledger_1.0:7230409065bcd9da163bc285287935a7d6a3799c99ee59b8a77c93883b607bdb: chaincode registration failed: container exited with 1
peer=peer0.org2.example.com:9051, status=500, message=error in simulation: failed to execute transaction 3832a02eeafd57382fb4810bc263d41693764f0d8cb76c27e5613c359b14d42f: could not launch chaincode ledger_1.0:7230409065bcd9da163bc285287935a7d6a3799c99ee59b8a77c93883b607bdb: chaincode registration failed: container exited with 1
It works fine if I don't make any changes to the chaincode file. Does anyone know what I can do?
I tried to reproduce your situation.
# fabric-samples/test-network
./network.sh down
./network.sh up createChannel -c mychannel -ca
./network.sh deployCC -ccn ledger -ccl javascript
# fabric-samples/asset-transfer-ledger-queries/application-javascript
node -v
# v12.13.1
npm install
node app.js
You can also, see error logs in chaincode container
# check <your_chaincode_container_name>
docker ps -a
# view logs
docker logs <your_chaincode_container_name>
1. Import library [chaincode.js]
#[ERROR CODE] - `node app.js`
--> Submit Transaction: InitLedger, function creates the initial set of assets on the ledger
2020-12-10T00:53:48.061Z - error: [Transaction]: Error: No valid responses from any peers. Errors:
peer=peer0.org2.example.com:9051, status=500, message=error in simulation: transaction returned with failure: ReferenceError: sha256 is not defined
peer=peer0.org1.example.com:7051, status=500, message=error in simulation: transaction returned with failure: ReferenceError: sha256 is not defined
do it
# asset_transfer_ledger_chaincode.js
const {Contract} = require('fabric-contract-api');
const sha256 = require('sha256'); // added
const uuid = require('uuid'); // added
# package.json
"dependencies": {
"fabric-contract-api": "^2.0.0",
"fabric-shim": "^2.0.0", // added ','
"sha256": "^0.2.0", // added
"uuid": "^8.3.2" // added
}
2. Fix wrong module code
#[ERROR CODE] - `node app.js`
--> Submit Transaction: InitLedger, function creates the initial set of assets on the ledger
2020-12-10T01:03:27.583Z - error: [Transaction]: Error: No valid responses from any peers. Errors:
peer=peer0.org1.example.com:7051, status=500, message=error in simulation: failed to execute transaction 62c19fbb84394ba1de399745c46f781078134b84de6b3d73419b9f65c5fa692b: could not launch chaincode ledger_1.0:5303ef138ca9cdb054cd3d814835fffca2706aa0c8e387611b93e4d6d1773742: chaincode registration failed: container exited with 1
peer=peer0.org2.example.com:9051, status=500, message=error in simulation: failed to execute transaction 62c19fbb84394ba1de399745c46f781078134b84de6b3d73419b9f65c5fa692b: could not launch chaincode ledger_1.0:5303ef138ca9cdb054cd3d814835fffca2706aa0c8e387611b93e4d6d1773742: chaincode registration failed: container exited with 1
******** initLedger failed :: Error: No valid responses from any peers. Errors:
peer=peer0.org1.example.com:7051, status=500, message=error in simulation: failed to execute transaction 62c19fbb84394ba1de399745c46f781078134b84de6b3d73419b9f65c5fa692b: could not launch chaincode ledger_1.0:5303ef138ca9cdb054cd3d814835fffca2706aa0c8e387611b93e4d6d1773742: chaincode registration failed: container exited with 1
peer=peer0.org2.example.com:9051, status=500, message=error in simulation: failed to execute transaction 62c19fbb84394ba1de399745c46f781078134b84de6b3d73419b9f65c5fa692b: could not launch chaincode ledger_1.0:5303ef138ca9cdb054cd3d814835fffca2706aa0c8e387611b93e4d6d1773742: chaincode registration failed: container exited with 1
uuid.v4() Create a version 4 (random) UUID
uuid.v5() Create a version 5 (namespace w/ SHA-1) UUID
uuid.v5() requires input parameters
do it
# asset_transfer_ledger_chaincode.js
// ==== Create asset object and marshal to JSON ====
let asset = {
docType: 'asset',
assetID: assetID,
color: color,
size: size,
owner: owner,
appraisedValue: appraisedValue,
couponID: assetID,
value: color,
expiration: size,
user: sha256(owner),
uuid: uuid.v5('Hello, World!', '1b671a64-40d5-491e-99b0-da01ff1f3341'), // modified
redeemed: false
};
3. Result (Solved)
# fabric-samples/asset-transfer-ledger-queries/application-javascript
# node app.js
Loaded the network configuration located at /Users/kmk/Project/src/github.com/hyperledger/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/connection-org1.json
Built a CA Client named ca-org1
Built a file system wallet at /Users/kmk/Project/src/github.com/hyperledger/fabric-samples/asset-transfer-ledger-queries/application-javascript/wallet
Successfully enrolled admin user and imported it into the wallet
Successfully registered and enrolled user appUser and imported it into the wallet
--> Submit Transaction: InitLedger, function creates the initial set of assets on the ledger
*** Result: committed
*** application ending

Cannot get state in Hyperledger fabric correctly?

Problem:
I have developed a Hyperledger fabric network and after that, I install a chain code in there. This is my Initialize ledger methods looks like.
async initLedger(stub, args) {
console.info("============= START : Initialize Ledger ===========");
let drivers = [];
drivers.push({
nic: "123",
firstName: "Saman",
lastName: "Frenando",
status: "Not verified",
licenceNo: "1234"
});
drivers.push({
nic: "124",
firstName: "Janith",
lastName: "Bentharaarachchi",
status: "Not verified",
licenceNo: "1235"
});
for (let i = 0; i < drivers.length; i++) {
drivers[i].docType = "driver";
console.log(drivers[i].nic);
await stub.putState(
drivers[i].nic,
Buffer.from(JSON.stringify(drivers[i]))
);
console.info("Added <--> ", drivers[i]);
}
console.info("============= END : Initialize Ledger ===========");
}
This is how I am retrieving those data.
async selectNthDriver(stub, args) {
if (args.length != 1) {
throw new Error(
"Incorrect number of arguments. Expecting NIC ex: 123"
);
}
let nic = args[0];
console.log(`nic: ${nic}`);
let driverAsBytes = await stub.getState(nic);
console.log("hi"+driverAsBytes);
if (!driverAsBytes || driverAsBytes.toString().length <= 0) {
throw new Error("Driver with NIC" + nic + " does not exist");
}
console.log(driverAsBytes.toString());
return driverAsBytes;
}
When I am Issuing this command on peer it successfully initializes the ledger.
peer chaincode invoke -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C myc -n mycc -c '{"Args":["initLedger"]}'
By Issuing the following command when I try to retrieve a driver it leaves me an error by saying this.
Error: endorsement failure during invoke. response: status:500 message:"transaction returned with failure: Error: Driver with NIC123 does not exist"
peer chaincode invoke -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C myc -n mycc -c '{"Args":["selectNthDriver","123"]}
This is the chaincode logs.
2019-05-09T05:18:51.184Z info [lib/handler.js]
info: [myc-09f261c4] Calling chaincode Init() succeeded.
Sending COMPLETED message back to peer
{"timestamp":"2019-05-09T05:18:51.184Z"} { fcn: 'initLedger', params:
[] }
============= START : Initialize Ledger =========== 123 Added <--> { nic: '123', firstName: 'Saman', lastName: 'Fernando', status:
'Not verified', licenceNo: '1234', docType: 'driver' } 124 Added
<--> { nic: '124', firstName: 'Janith', lastName:
'Bentharaarachchi', status: 'Not verified', licenceNo: '1235',
docType: 'driver' }
============= END : Initialize Ledger =========== { fcn: 'selectNthDriver', params: [ '123' ] } nic: 123 hi
Error: Driver with NIC123 does not exist
at selectNthDriver (/usr/local/src/mycc.js:494:13)
at
at process._tickCallback (internal/process/next_tick.js:188:7) 2019-05-09T05:43:42.430Z error [lib/handler.js]
error: [myc-e7aef847] Calling chaincode Invoke() returned
error response [Error: Driver with NIC123 does not exist].
Sending ERROR message back to peer
{"timestamp":"2019-05-09T05:43:42.430Z"}
And when I go to the CouchDB through browser It is not showing the data I initialized. It only shows this data.
{
"_id": "mycc",
"_rev": "1-5c5ecfec35f65ec74cbe52a52be96048",
"~version": "\u0000CgMBBwA=",
"_attachments": {
"valueBytes": {
"content_type": "application/octet-stream",
"revpos": 1,
"digest": "md5-SkPMcpW++nrvo5v00rCdRQ==",
"length": 424,
"stub": true
}
}
}
Can someone help me to find where am I doing wrong? Thank you.
You should use "query" command for querying a state from the ledger using the peer binary, the invoke command which you have used is for generating a transaction, which is not required for a query operation.
You should just try replacing invoke with query and it should look something like this:
peer chaincode query -o orderer.example.com:7050 -C myc -n mycc -c '{"Args":["selectNthDriver","123"]}
EDIT: Also please check for the following condition in your if statement in the selectNthDriver Method:
if (!driverAsBytes.toString())
Also please console for the same(driverAsBytes.toString()) in the line just before this if statement in your code.

Cannot invoke a function that change or retrieve function of a chaincode?

Problem:
I have created a Hyperledger fabric network with six organizations 2 peers for each. After running the network I install fabcar chaincode on one peer of each organization and then I instantaited the chaincode using this command.
peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -n fabcar -l node -v 1.0 -c '{"Args":["init"]}' -C myc -P "AND ('Org2MSP.peer','Org1MSP.peer',Org3MSP.peer','Org4MSP.peer','Org5MSP.peer','Org6MSP.peer')"
Up to this command, everything was successfully happened without giving me an error. After I tried to invoke a function using this command.
peer chaincode invoke -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C myc -n fabcar -c '{"Args":["initLedger"]}
This command leaves this error on the particular peer logs.
2019-05-12 13:38:01.162 UTC [gossip.privdata] StoreBlock -> INFO 191
[myc] Received block [8] from buffer 2019-05-12 13:38:01.213
UTC [vscc] Validate -> ERRO 192 VSCC error:
stateBasedValidator.Validate failed, err validation of endorsement
policy for chaincode fabcar in tx 8:0 failed: signature set did not
satisfy policy 2019-05-12 13:38:01.213 UTC [committer.txvalidator]
validateTx -> ERRO 193 VSCCValidateTx for transaction txId =
a17c0deb20af5a4e0a232fa432ea13e74fca101b63cb697384bbaced80905773
returned error: validation of endorsement policy for chaincode fabcar
in tx 8:0 failed: signature set did not satisfy policy 2019-05-12
13:38:01.258 UTC [committer.txvalidator] Validate -> INFO 194
[myc] Validated block [8] in 96ms 2019-05-12 13:38:01.259 UTC
[valimpl] preprocessProtoBlock -> WARN 195 Channel [trafficfine]:
Block [8] Transaction index [0] TxId
[a17c0deb20af5a4e0a232fa432ea13e74fca101b63cb697384bbaced80905773]
marked as invalid by committer. Reason code
[ENDORSEMENT_POLICY_FAILURE]
This was the logs on the chincode.
fabcar#1.0.0 start /usr/local/src
node fabcar.js "--peer.address" "peer0.org2.example.com:9052"
2019-05-12T13:35:08.951Z info [lib/chaincode.js]
info: Registering with peer peer0.org2.example.com:9052 as chaincode
"fabcar:1.0" {"timestamp":"2019-05-12T13:35:08.951Z"}
2019-05-12T13:35:09.232Z info [lib/handler.js]
info: Successfully registered with peer node. State transferred to
"established" {"timestamp":"2019-05-12T13:35:09.232Z"}
2019-05-12T13:35:09.234Z info [lib/handler.js]
info: Successfully established communication with peer node. State
transferred to "ready" {"timestamp":"2019-05-12T13:35:09.234Z"}
=========== Instantiated fabcar chaincode =========== 2019-05-12T13:35:09.240Z info [lib/handler.js]
info: [myc-8ecdb2a5] Calling chaincode Init() succeeded. Sending
COMPLETED message back to peer
{"timestamp":"2019-05-12T13:35:09.240Z"} { fcn: 'initLedger', params:
[] }
============= START : Initialize Ledger =========== successful { status: 200, message: '', payload: } Added <--> { make:
'Toyota', model: 'Prius', color: 'blue', owner: 'Tomoko',
docType: 'car' } successful { status: 200, message: '', payload:
} Added <--> { make: 'Ford', model: 'Mustang', color:
'red', owner: 'Brad', docType: 'car' } successful { status: 200,
message: '', payload: } Added <--> { make: 'Hyundai',
model: 'Tucson', color: 'green', owner: 'Jin Soo', docType:
'car' } successful { status: 200, message: '', payload: }
Added <--> { make: 'Volkswagen', model: 'Passat', color:
'yellow', owner: 'Max', docType: 'car' } successful { status: 200,
message: '', payload: } Added <--> { make: 'Tesla',
model: 'S', color: 'black', owner: 'Adriana', docType: 'car' }
successful { status: 200, message: '', payload: } Added <-->
{ make: 'Peugeot', model: '205', color: 'purple', owner:
'Michel', docType: 'car' } successful { status: 200, message: '',
payload: } Added <--> { make: 'Chery', model: 'S22L',
color: 'white', owner: 'Aarav', docType: 'car' } successful {
status: 200, message: '', payload: } Added <--> { make:
'Fiat', model: 'Punto', color: 'violet', owner: 'Pari',
docType: 'car' } successful { status: 200, message: '', payload:
} Added <--> { make: 'Tata', model: 'Nano', color:
'indigo', owner: 'Valeria', docType: 'car' } successful { status:
200, message: '', payload: } Added <--> { make: 'Holden',
model: 'Barina', color: 'brown', owner: 'Shotaro', docType:
'car' }
============= END : Initialize Ledger =========== 2019-05-12T13:37:58.998Z info [lib/handler.js]
info: [myc-a17c0deb] Calling chaincode Invoke() succeeded. Sending
COMPLETED message back to peer
{"timestamp":"2019-05-12T13:37:58.998Z"}
I tried a lot to figure out what is wrong with my network. But I was unable to find out. can someone help me to solve this problem? Thank you.
Your endorsement policy is an AND policy so you will need to collect endorsement from all the Organizations defined in your policy. You can use [--peerAddresses] flag in your invoke command to send the transaction to multiple peers in different organizations and get the required signatures required for the policy.

Fabric node sdk use service discovery function

I tried to use fabric node sdk to call for service discovery function of Fabric v1.2, but I got these errors:
2018-12-12 11:51:26.413 UTC [endorser] callChaincode -> INFO 05d [mychannel][16a59ced] Entry chaincode: name:"mycc"
2018-12-12 11:51:30.138 UTC [chaincode] ProcessStream -> ERRO 05e handling chaincode support stream: rpc error: code = Canceled desc = context canceled
receive failed
github.com/hyperledger/fabric/core/chaincode.(*Handler).ProcessStream
/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/handler.go:408
github.com/hyperledger/fabric/core/chaincode.(*ChaincodeSupport).HandleChaincodeStream
/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/chaincode_support.go:182
github.com/hyperledger/fabric/core/chaincode.(*ChaincodeSupport).Register
/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/chaincode_support.go:187
github.com/hyperledger/fabric/core/chaincode/accesscontrol.(*interceptor).Register
/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/accesscontrol/interceptor.go:57
github.com/hyperledger/fabric/protos/peer._ChaincodeSupport_Register_Handler
/opt/gopath/src/github.com/hyperledger/fabric/protos/peer/chaincode_shim.pb.go:1066
github.com/hyperledger/fabric/vendor/google.golang.org/grpc.(*Server).processStreamingRPC
/opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/server.go:1160
github.com/hyperledger/fabric/vendor/google.golang.org/grpc.(*Server).handleStream
/opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/server.go:1253
github.com/hyperledger/fabric/vendor/google.golang.org/grpc.(*Server).serveStreams.func1.1
/opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/server.go:680
runtime.goexit
/opt/go/src/runtime/asm_amd64.s:2361
2018-12-12 11:52:00.041 UTC [endorser] callChaincode -> INFO 05f [mychannel][16a59ced] Exit chaincode: name:"mycc" (33628ms)
However, I can totally ensure that I have already instantiated my chaincode, and I can normally invoke it if I do not use service discovery.
And here is my code for service discovery:
let client = await helper.getClientForOrg(orgName);
let channel = client.newChannel(channelName);
channel.addPeer(client.getPeer("peer0.org1.example.com"));
await channel.initialize({discover:true, asLocalhost:true});
let request = {
chaincodeId: chaincodeName,
fcn: functionName,
args: args,
transientMap: transient
};
logger.debug("Make query");
let response_payloads = await channel.queryByChaincode(request);
Where am I wrong? And there are codes before I use service discovery:
let client = await helper.getClientForOrg(orgName);
let channel = client.newChannel(channelName);
// assign orderer to channel
channel.addOrderer(client.getOrderer(ordererName));
// assign peers to channel
peers.forEach(function (peerName) {
channel.addPeer(client.getPeer(peerName));
});
let request = {
targets: peers,
chaincodeId: chaincodeName,
fcn: functionName,
args: args,
transientMap: transient
};
logger.debug("Make query");
let response_payloads = await channel.queryByChaincode(request);
I just solved it myself. That may be some kind of a network error.
Now I changed port of peer1.org1.example.com, peer0.org2.example.com, peer1.org2.example.com to 8051, 9051, 10051, 11051. According to the node sdk official doc, I set asLocalhost = true.
And here are my codes that could work for me:
let channel = client.newChannel(channelName);
channel.addPeer(client.getPeer("peer0.org1.example.com"));
await channel.initialize({discover: true, asLocalhost: true});
let tx_id = client.newTransactionID();
tx_id_string = tx_id.getTransactionID();
let request = {
args: args,
chaincodeId: chaincodeName,
chainId: channelName,
fcn: functionName,
txId: tx_id,
transientMap: transient
};
let results = await channel.sendTransactionProposal(request);
hope this could help others.

Resources