kalleknast / Microgrid

Hyperledger network for microgrids
GNU General Public License v3.0
4 stars 1 forks source link

Query fails with Error: 2 UNKNOWN: Stream removed #5

Open kalleknast opened 5 years ago

kalleknast commented 5 years ago

I updated to fabric 1.4 and fixed the "Failed to find private key for certificate..." error that was brought up before. I still haven't fixed the affiliation issue, but its not critical so I put it on hold.

Unfortunately, I cannot query the ledger. I added query.js, a modification of fabcar query.js but it fails with 2019-01-24T15:09:00.316Z - error: [Network]: _initializeInternalChannel: Unable to initialize channel. Attempted to contact 1 Peers. Last error was Error: 2 UNKNOWN: Stream removed. The last error Error: 2 UNKNOWN: Stream removed seems to be a grpc error. I tried running the fabcar example, just the check that there was nothing wrong with my installations in general, but it worked fine.

query.js fails on const network = await gateway.getNetwork('hachannel');, and specifically when it tries to initialize the channel. I compared the gateway returned by the previous line: await gateway.connect(ccp, { wallet, identity: 'user1', discovery: { enabled: false } }); of fabcar and microgrid and they identical (except where they should be different).

However, I can write and query to the chaincode from the cli. This works: TLS_ROOT_CERT_FILES_PEER1=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/house01.microgrid.org/peers/peer0.house01.microgrid.org/tls/ca.crt TLS_ROOT_CERT_FILES_PEER2=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/house03.microgrid.org/peers/peer0.house03.microgrid.org/tls/ca.crt CA_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/microgrid.org/orderers/orderer.microgrid.org/msp/tlscacerts/tlsca.microgrid.org-cert.pem

peer chaincode invoke -o orderer.microgrid.org:7050 --tls true --cafile $CA_FILE -C $CHANNEL_NAME -n carecords --peerAddresses peer0.house01.microgrid.org:7051 --tlsRootCertFiles $TLS_ROOT_CERT_FILES_PEER1 --peerAddresses peer0.house03.microgrid.org:7051 --tlsRootCertFiles $TLS_ROOT_CERT_FILES_PEER2 -c '{"Args":["appendRecord","House01","2019-01-25 12:03","10"]}'

as does this: peer chaincode query -C $CHANNEL_NAME -n carecords -c '{"Args": ["getAllRecords"]}'

returning: [{"Key":"House01", "Record":{"amount":"10","house":"House01","time":"2019-01-25 12:03"}}]

erickzzh commented 5 years ago

Have you tried to run the query.js script as an admin? So change "user1" to admin and change the identity to the admin identity. I feel like there might be something wrong with the add new user script. It could be possible that when you query from the CLI you are running as the root user and that's why it returned a correct value. I am trying to set up the program but I just couldn't get to your problem for some reasons.

kalleknast commented 5 years ago

I got stuck on js, gave it up and continued using the CLI (works fine). If you want to fix the add new user script, please do.