Issue with hyprledger node sdk on calling API? - hyperledger-fabric

When i am upgrading and instantiating chaincode for first time and then i hit a API from node sdk then i get below error for first time only.
"Peer localhost:7051 has rejected transaction \"1b0f72d31c2d2baa1b7fa2d5f079ba62982f67359b30a490dae901d74b8a3a1d\"
with code \"ENDORSEMENT_POLICY_FAILURE\"","stack":"Error: Peer
localhost:7051 has rejected transaction
\"1b0f72d31c2d2baa1b7fa2d5f079ba62982f67359b30a490dae901d74b8a3a1d\"
with code \"ENDORSEMENT_POLICY_FAILURE\"\n
Please tell me how can i resolve this issue ?

Its seems issue with endorsement policy, check if your transaction is endorsed by all required endorser in the network.
You must be get endorsed by all endorser to commit the transaction in peer world state.

I solved this issue by adding "grpc.keepalive_timeout_ms": 20000 in connection.js file in node sdk.
For more information visit here

Related

How to add an endorsing peer in hyperledger fabric?

What steps are required in order to add an endorsing peer to a blockchain network (in hyperledger-fabric)? What about promoting a committing peer in an endorsing one?
Should I just alter files crypto-config.yaml and configtx.yaml by adding the new peer?
I am using the fabcar example from the fabric-samples repo (https://github.com/hyperledger/fabric-samples), so should I change the docker-compose(-cli).yaml also? When starting the network with startFabric.sh script, should I just install chaincode on the new peers, or are other steps requires also?
I tried it with just installing a chaincode on the new peers, however I got an error stating that "... Consortium was not met when instantiating the chaincode ..."
Edit:
I was able to install the chaincode on all four peers and instantiate it on the channel. Initial non-query transaction is successful and another one after it. However, after the first two transactions I get:
Failed to submit transaction createInquiry: Error: Peer localhost:8051 has rejected transaction "e8a83c12bfbcae97c7a3f2baaad7735fe8b44195a0ce252a3533a7b4a2a8103b" with code "ENDORSEMENT_POLICY_FAILURE"
can you stop, remove and kill containers and try once again to instantiate.

Hyperledger Fabric: Error: could not assemble transaction: ProposalResponsePayloads do not match

what are the steps to troubleshoot below error when trying to invoke a chaincode?
Error: could not assemble transaction: ProposalResponsePayloads do not match - proposal response: version:1 response:<status:200 payload:"[\"00000\"]" > ...
we get this error when trying to invoke a chaincode using peer chaincode invoke
#morpheus: Has answered it excellently:
So I thought I will add to the above list of possible reasons:
I had by mistake added something like getting the current timestamp, and was using this for capturing the event date. This led to the different transaction responses by the endorsers, thus leading to the Response Payload not matching. The whole point to remember is that the result of execution should be deterministic as it is going to be run on all of the selected endorsing peers.
So use ctx.GetStub().GetTxTimestamp() for capturing the event time. This is the time when the transaction began and it will be constant across the endorser executions.
Check that you have installed the chaincode on all the peers your peer chaincode invoke command is targetting. That is the most likely cause of this error.
Other ways this error can occur:
You modified your chaincode and instead of installing a new version and upgrading the chaincode, you tried to be smart and overwrite the chaincode with the new file thinking that Fabric would not notice.
It can also happen if there is no chaincode container running on target peer and Docker daemon cannot be found on the peer node when it tries to instantiate a container or instantiation fails for some other reason
Another reason why this error can happen is if some peer nodes are using LevelDB and others are using CouchDB
The error itself originates from here. The first step to debug this error is to invoke the chaincode individually one-by-one on one peer node at a time.
Another reason that I forgot to check is using storing randomly generated values.
I never used random "Id" until now and didn't notice that it leads to ENDORSEMENT_MISMATCH

Endorement Error while invoking chain code

I have a hyperledger fabric network setup in multiple servers and I successfully installed chaincode in different peers(peer0.org1.com and peer0.org2.com) of different organizations.
When I call the chaincode with putState(key,value) from peer0.org1.com I am able to commit the change but when I call the same chaincode from peer0.org2.com putstate(key, value) is failing with endorsement error.
This might be because you didn't include peer0.org2.com in the endorsement policy while installing the chaincode.
Ex: Include OR/AND ('ORG1MSP.member','ORG2MSP.member') in chaincode installation step
I hope this solves the issue

Hyperledger Composer error: status: 500, message: chaincode exists

I started a new composer network (two org setup), i.e. a second chaincode (one was already installed and running). I installed it and while starting, couple of chaincode containers were stuck while downloading node modules, and the command to start chaincode was timed out. To start again I removed the chaincode containers and tried to start again. But I am getting error : status: 500, message: chaincode exists.
That message from hyperledger fabric means that the chaincode has already been instantiated, so you do not need to invoke composer network start again. Any request you send to a peer will try to bring up a chaincode container to process that request if there isn't one already started.
composer network start sends the instantiate transaction to peers and as such the peers need to simulate the request proposal and to do that it needs a chaincode container so goes through the process of creating a chaincode container image and chaincode container to execute the request (but any transaction proposal causes the same process to be followed). So long as the instantiation policy is satisfied (and the default I believe is for 1 successful instantiation proposal) then the chaincode is then defined as instantiated.

How to instantiate all chaincodes at once in the channel?

I have a question about chaincode instantiation.
I think all same chaincode in a channel will be instantiated all at once by one request from this doc.
http://hyperledger-fabric.readthedocs.io/en/release-1.1/install_instantiate.html
Note: The initial instantiation applies to all peers in the channel, and is affected upon any peer that has the chaincode installed.
but in my vagrant environment with v1.0.6 fabric, always only one (of three installed cc on endorsers) chaincode is instantiated by my Instantiate request from Node SDK.
then it seems that if any other proposal request is received, that endorser start to instantiate other chaincode. so if my endorsement policy needs that endorsement, first invoke request is failed...
Initially, chaincode will only be launched on peers to which you send the actual instantiate proposal. It will then be launched on other peers in the channel upon the first invoke request. If you want to have the chaincode launched at instantiate time, you need to send the instantiate request to all of the endorsing peers. The channel.sendInstantiateProposal takes a ChaincodeInstantiateUpgradeRequest which allows you to specify an array of peers in it's target property.

Resources