davidkel / hlf

0 stars 0 forks source link

sendTransactionProposal returns completely different things depending on whether discovery is used or not. #31

Open davidkel opened 4 years ago

davidkel commented 4 years ago

If chaincode returns an error through shim.Error then sendTransactionProposal does completely different things depending on if discovery is used or not. If discovery is not used then it returns an array as follows :-

res [ [ { Error: I'm a shim error
    at self._endorserClient.processProposal (/home/dave/Documents/gow/src/testclient/node_modules/fabric-client/lib/Peer.js:140:36)
    at Object.onReceiveStatus (/home/dave/Documents/gow/src/testclient/node_modules/grpc/src/client_interceptors.js:1207:9)
    at InterceptingListener._callNext (/home/dave/Documents/gow/src/testclient/node_modules/grpc/src/client_interceptors.js:568:42)
    at InterceptingListener.onReceiveStatus (/home/dave/Documents/gow/src/testclient/node_modules/grpc/src/client_interceptors.js:618:8)
    at callback (/home/dave/Documents/gow/src/testclient/node_modules/grpc/src/client_interceptors.js:845:24)
      status: 500,
      payload: <Buffer >,
      peer: [Object],
      isProposalResponse: true } ],
  { header: 
...
    payload: 
...
    extension: 
...
 } ]

If however discovery is used, then it doesn't just return, it throws an error as follows

ERROR { Error: Endorsement has failed
    at DiscoveryEndorsementHandler._endorse (/home/dave/Documents/gow/src/testclient/node_modules/fabric-client/lib/impl/DiscoveryEndorsementHandler.js:186:19)
    at <anonymous>
  endorsements: 
   [ { Error: I'm a shim error
    at self._endorserClient.processProposal (/home/dave/Documents/gow/src/testclient/node_modules/fabric-client/lib/Peer.js:140:36)
    at Object.onReceiveStatus (/home/dave/Documents/gow/src/testclient/node_modules/grpc/src/client_interceptors.js:1207:9)
    at InterceptingListener._callNext (/home/dave/Documents/gow/src/testclient/node_modules/grpc/src/client_interceptors.js:568:42)
    at InterceptingListener.onReceiveStatus (/home/dave/Documents/gow/src/testclient/node_modules/grpc/src/client_interceptors.js:618:8)
    at callback (/home/dave/Documents/gow/src/testclient/node_modules/grpc/src/client_interceptors.js:845:24)
       status: 500,
       payload: <Buffer >,
       peer: [Object],
       isProposalResponse: true } ] }

The api should be consistent irrespective of discovery. Unfortunately it can't be changed for V1, but should be made consistent for V2.

davidkel commented 4 years ago

[FABRIC-NETWORK] Calling submitTransaction on chaincode that returns an error (shim.Error) you get different output depending on whether you have used discovery or not

For example, If I don't use discovery or use the default endorsement handler (not the discovery handler) the result I get is

ERROR Error: No valid responses from any peers. 1 peer error responses:
    peer=peer0.org1.example.com, status=500, message=my shim error
    at Transaction._validatePeerResponses (/home/dave/Documents/gow/src/testclient/node_modules/fabric-network/lib/transaction.js:227:10)
    at Transaction.submit (/home/dave/Documents/gow/src/testclient/node_modules/fabric-network/lib/transaction.js:145:33)
    at <anonymous>

If however I use discovery then the result I get is

ERROR { Error: Endorsement has failed
    at DiscoveryEndorsementHandler._endorse (/home/dave/Documents/gow/src/testclient/node_modules/fabric-client/lib/impl/DiscoveryEndorsementHandler.js:186:19)
    at <anonymous>
  endorsements: 
   [ { Error: my shim error
    at self._endorserClient.processProposal (/home/dave/Documents/gow/src/testclient/node_modules/fabric-client/lib/Peer.js:140:36)
    at Object.onReceiveStatus (/home/dave/Documents/gow/src/testclient/node_modules/grpc/src/client_interceptors.js:1207:9)
    at InterceptingListener._callNext (/home/dave/Documents/gow/src/testclient/node_modules/grpc/src/client_interceptors.js:568:42)
    at InterceptingListener.onReceiveStatus (/home/dave/Documents/gow/src/testclient/node_modules/grpc/src/client_interceptors.js:618:8)
    at callback (/home/dave/Documents/gow/src/testclient/node_modules/grpc/src/client_interceptors.js:845:24)
       status: 500,
       payload: <Buffer >,
       peer: [Object],
       isProposalResponse: true } ] }

Both are error objects, but the message is different and in the latter case all the endorsement responses can be found in as a property of the error object.

The reason for this is that the underlying sendTransactionProposal returns different values depending on the discovery setup (subject of another Jira) however fabric-network processes one but ignores the other.

fabric-network should make the 2 consistent. My suggestion would be

  1. In both cases make the error message the same
  2. in both cases ensure that the error object has the endorsement property

This should mean it remains backward compatible (apart from the error message for the discovery version which could be a bit more useful)