Error while installing chaincode in fabric 2.0 - hyperledger-fabric

when I try to approve chaincode definition for my organization using peer lifecycle chaincode approveformyorg I got this error
Error: proposal failed with status: 500 - failed to invoke backing implementation of 'ApproveChaincodeDefinitionForMyOrg': could not
serialize chaincode parameters to state: could not deserialize
metadata for namespace namespaces/hei-authorization-contract#1: could
not query metadata for namespace
namespaces/hei-authorization-contract#1: GET_STATE failed: transaction
ID: 85c9a7441cda90c5860c0d64b45e3d0fb3aaf963ccb2b3c0420e517c60880a5a:
private data matching public hash version is not available. Public
hash version = {BlockNum: 9, TxNum: 0}, Private data version =
can someone please explain the cause of this error
I am using the following commands to install chaincode
peer lifecycle chaincode package contracts.tar.gz --path /opt/gopath/src/github.com/chaincode/Contracts/ --lang node --label contracts_0.0.1
peer lifecycle chaincode install contracts.tar.gz
peer lifecycle chaincode queryinstalled >&log.txt
export PACKAGE_ID=$(sed -n "/contracts_0.0.1/{s/^Package ID: //; s/, Label:.*$//; p;}" log.txt)
echo PackageID is ${PACKAGE_ID}
peer lifecycle chaincode approveformyorg -o orderer1.regulator.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/regulator.com/orderers/orderer1.regulator.com/msp/tlscacerts/tlsca.regulator.com-cert.pem --channelID dvchannel --name contracts --version 1 --init-required --package-id ${PACKAGE_ID} --sequence 1
peer lifecycle chaincode querycommitted --channelID dvchannel --name contracts

Related

Endoresement Failure during query

while running the secured-asset transfer in hyperledger fabric I am getting this error and the query command is not passing
Command:-
peer chaincode query -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 secured -c '{"function":"GetAssetPrivateProperties","Args":["asset1"]}'
Error:-
Error: endorsement failure during query. response: status:500 message:"asset private details does not exist in client org's collection: asset1"
Can anyone help me with it ??
This error is thrown from the chaincode. Make sure you have added the data to the private data collection with the key 'asset1' before querying it. Also, orderer endpoints are not required for query command.
peer chaincode query -C mychannel -n basic -c '{"function":"GetAssetPrivateProperties","Args":["asset1"]}'
The source code from the hyperledger /fabric-samples seems is not compatible with the command provided in the hyperledger fabric document.
Change the code in the repository of
fabric-samples/asset-transfer-secured-agreement/chaincode-go/asset_transfer.go
Add argument asset_id string to this function head.
CreateAsset(ctx contractapi.TransactionContextInterface,asset_id string, publicDescription string)
In this function body
comment this line assetID := hex.EncodeToString(hash.Sum(nil))
and reset the assetID := asset_id
hope helpful

Peer chaincode install failed due to chaincode definition sequence mismatch

Recently I have ran into a situation where I accidentally delete the /var/hyperledger/production folder. After rejoining the channel and finished syncing from other peers, I got this error
+ peer lifecycle chaincode approveformyorg -o orderer0-orderer.orderer20:7050 --tls true --cafile /shared/crypto-config/orderer.orderer20/orderers/orderer0-orderer.orderer20/msp/tlsintermediatecerts/ica-orderer-orderer20-7054.pem --channelID htqachannel --name ht_cc --version b21734e0c25e509e3ff4b3dc96b78ca83047aa9e --package-id ht_cc_b21734e0c25e509e3ff4b3dc96b78ca83047aa9e:76c6642ba927c690ad5a402d22f3ec28c581ef76cea8828b9af583a5021bea23 --sequence 1 --waitForEvent
+ res=1
+ set +x
Error: proposal failed with status: 500 - failed to invoke backing implementation of 'ApproveChaincodeDefinitionForMyOrg': currently defined sequence 109 is larger than requested sequence 1
Are there anyway to make the chaincode definition sequence on this peer to match the current defined sequence ?
You have to increment the chaincode sequence number when upgrading chaincode definition. From the error it seems your current definition is having a sequence number 109. So you have to provide 110 as sequence instead of 1.

Hyperledger Fabric: CouchDB doesn't show the worldstate of a channel

The HLF Version I use is 2.2
I set up my own network consisting of 3 Orgs, 1 Orderer and 2 Channels. The network is set up and I can call Chaincode Functions responding with 200. So far, so good. The problem is I don't see the worldstate in CouchDB. I think it's related due to the fact the chaincode is not instantiated properly or at all
When I call:
peer chaincode list --instantiated -C examplechannel
It doesn't return anything. But if I try to set the flag --isInit on the first Invoke.
peer chaincode invoke -o localhost:7050 -C examplechannel -n example --peerAddresses localhost:9051 --isInit -c '{"function":"instantiate","Args":[]}'
The response is:
chaincode 'example' does not require initialization but called as init
When I try to instantiate the Chaincode by:
peer chaincode instantiate -o localhost:7050 -C examplechannel -n example -v 1 -c '{"function":"instantiate","Args":[]}'
I get the response:
Error: could not assemble transaction, err proposal response was not successful, error code 500, msg Channel 'examplechannel' has been migrated to the new lifecycle, LSCC is now read-only
Any suggestions?
There is difference in the chaincode installation from Fabric version 2.0 when compare to previous version. Please refer below documentation for more details regarding new chaincode lifecycle
https://hyperledger-fabric.readthedocs.io/en/release-2.2/deploy_chaincode.html

Error: endorsement failure during invoke. response: status:500 message:"error in simulation:

I'm using hyperledger fabric 2.0. I have two orgs. ORGA and ORGB. I'm using "test-network" of fabric-samples repository as my network.
I have edited javascript version of fabcar chaincode by changing the variable names in the init functions and other functions of fabcar.js chaincode.
I have installed my edited chaincode on the peers of two orgs. I have also successfully approved chaincode on 2 orgs. Successfully committed chaincode definition to the channel. But when I'm trying to invoke chaincode using command with function initLedger I'm getting error:
Command:
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls true --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n deed --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 --isInit -c '{"function":"initLedger","Args":[]}'
I'm getting an error shown below:
Error: endorsement failure during invoke. response: status:500
message:"error in simulation: failed to execute transaction
5b14718ab2408cd29dafc9daf33e193534c7a1262afebd0ca5eae3b0116aeca0:
could not launch chaincode
deed_1:48b197c4e734f589019d61ba1615ad9fc2b0007f478ab92a8b34714bc3c404e0:
chaincode registration failed: container exited with 1"
help me.
Regards,
Satish
Fabric provides monitordocker.sh along with its commercial-paper sample in the Fabric sample (https://hyperledger-fabric.readthedocs.io/en/latest/deploy_chaincode.html#setup-logspout-optional)
Run the below line in a separate PUTTY window to keep monitoring the logs across all containers in docker. Note that "fabric_test" is the name of the network that needs to be monitored.
./monitordocker.sh fabric_test
Now run the fabric command that results in error and you should see details on the log in the other PUTTY window.
The error is telling you that the container hosting the chaincode has exited after the chaincode process terminated with an exit code of 1. If you've configured the peer to stream the chaincode container logs (vm.docker.attachStdout=true / CORE_VM_DOCKER_ATTACHSTDOUT=true), you can look at the peer logs to see any errors produced by the chaincode.
Check your chaincode, their is some typo in your code.
check --> repair --> run following script -->
./startFabric.sh javascript
The name of the invoked chaincode does not match the name of the committed one.
Check it.

Instantiate test contract fails with Contract name is not known

I am trying to adapt the commercial paper tutorial to a custom contract. As soon as I change the contract name, I cannot instantiate it.
In commercial-paper/organization/magnetocorp/contract/lib, I updated paper.js to replace:
static getClass() {
return 'org.papernet.commercialpaper';
}
... with
static getClass() {
return 'org.papernet.commercialpapertest';
}
Similarly, in commercial-paper/organization/magnetocorp/contract/lib, I updated papercontract.js to replace:
constructor() {
// Unique name when multiple contracts per chaincode file
super('org.papernet.commercialpaper');
}
... with:
constructor() {
// Unique name when multiple contracts per chaincode file
super('org.papernet.commercialpapertest');
}
I then changed the instantiate command from:
docker exec cliMagnetoCorp peer chaincode instantiate -n papercontract -v 0 -l node -c '{"Args":["org.papernet.commercialpaper:instantiate"]}' -C mychannel -P "AND ('Org1MSP.member')"
... to:
docker exec cliMagnetoCorp peer chaincode instantiate -n papercontract -v 0 -l node -c '{"Args":["org.papernet.commercialpapertest:instantiate"]}' -C mychannel -P "AND ('Org1MSP.member')"
On deleting the couchdb databases, stopping then removing all containers, and rerunning the example from scratch, these changes causes instantiate to fail with Contract name is not known:
Error: could not assemble transaction, err proposal response was not successful, error code 500, msg transaction returned with failure: Error: Contract name is not known: org.papernet.commercialpapertest
Here is the docker log:
> papercontract#0.0.3 start /usr/local/src
> fabric-chaincode-node start "--peer.address" "peer0.org1.example.com:7052"
2019-09-08T16:11:08.911Z info [shim:contracts-spi/bootstrap.js]
No metadata file supplied in contract, introspection will generate all the data
2019-09-08T16:11:08.914Z info [shim:contracts-spi/chaincodefromcontract.js]
Using serializers {"transaction":"jsonSerializer","serializers":{}}
2019-09-08T16:11:08.942Z info [shim:lib/chaincode.js]
Registering with peer peer0.org1.example.com:7052 as chaincode "papercontract:0"
Command succeeded
2019-09-08T16:11:08.971Z info [shim:lib/handler.js] Successfully registered with peer node. State transferred to "established"
2019-09-08T16:11:08.972Z info [shim:lib/handler.js] Successfully established communication with peer node. State transferred to "ready"
2019-09-08T16:11:08.977Z error [shim:contracts-spi/chaincodefromcontract.js [mychannel-971a76f9] Error: Contract name is not known: org.papernet.commercialpapertest
2019-09-08T16:11:08.977Z error [shim:lib/handler.js] [mychannel-971a76f9] Calling chaincode Init() returned error response [Error: Contract name is not known: org.papernet.commercialpapertest]. Sending ERROR message back to peer
Listing installed contracts shows that the contract is installed:
Get installed chaincodes on peer:
Name: papercontract, Version: 0, Path: /opt/gopath/src/github.com/contract, Id: a766e52585dbf1c0c9b725a72e66bd0e3f50f83da8641c9a4b4d6aebd6b85777
Listing instantiated contracts show that it is not instantiated:
Get instantiated chaincodes on channel mychannel:
It seems as if the original contract name is set somewhere else also? If so, I cannot locate it with a "Find in Files" search from VS Code.
Help gratefully received.
It seems you didn't change the contract name in package.json papercontract as the contract installed on peer with details name: papercontract, Version: 0

Resources