Unable to instantiate chaincode on peer, connection reset by peer - go

I am trying to get started with Hyperledger Fabric. I managed to run the "build your first network"-tutorial from the samples, and I followed the "write your first application"-tutorial as well, which also worked.
As a next step, I wanted to create my own network more or less from scratch, by adjusting the .yaml files from the samples and running cryptogen and configtxgen manually. I managed to build a network with three organisations, two peers per org and a solo ordering service. I now want to install some basic chaincode on one of the peers, but I'm stuck, as I get a couple of weird errors:
2018-03-01 22:27:30.525 UTC [grpc] Printf -> DEBU 003 transport: http2Client.notifyError got notified that the client transport was broken read tcp 172.20.0.9:45178->172.20.0.3:7050: read: connection reset by peer.
Error: Error getting broadcast client: Error connecting to orderer.rle.de:7050 due to rpc error: code = Internal desc = transport: write tcp 172.20.0.9:45178->172.20.0.3:7050: write: broken pipe
2018-03-01 22:27:30.525 UTC [grpc] Printf -> DEBU 004 grpc: addrConn.resetTransport failed to create client transport: connection error: desc = "transport: Error while dialing dial tcp: lookup orderer.rle.de on 127.0.0.11:53: dial udp 127.0.0.11:53: operation was canceled"; Reconnecting to {orderer.rle.de:7050 <nil>}
2018-03-01 22:27:30.525 UTC [grpc] Printf -> DEBU 005 grpc: addrConn.transportMonitor exits due to: grpc: the connection is closing
After that, I get the usage information for peer chaincode instantiate
If you could provide any insight into what might be causing this error, I would be super grateful. I don't even know if it is caused by the network config or by the chaincode itself (I don't think so, since I tried two different chaincodes, one of which was "sacc" from the samples) but the installation of the chaincode seems to be working. My problem is that I have no idea what I'm doing, so after googling and fooling around with the arguments for peer chaincode instantiate, I'm all out of ideas.
My command (I run it from a .sh file) is:
peer chaincode instantiate -o orderer.rle.de:7050 -C driverlogschannel -n test -v 1.0 -c '{"Args":["John","0"]}' -P "OR ('rleMSP.member')"
The chaincode is taken from the sacc example installed via
peer chaincode install -n test -v 1.0 -p sacc
Thanks a lot! If you need more logs or other info, I can provide them.

Solved it. The problem had to do with the fact that I was not submitting a cafile. Basically, what I did is going back to this tutorial and trying it with their chaincode again:
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
but I adjusted it to
peer chaincode install -n mycc -v 1.0 -p chaincode_example02
(I put the chaincode_example02.go file from fabric-samples/chaincode/ into my $GOPATH/src/chaincode_example02 folder and adjusted my docker-compose-cli.yaml by adding this line to cli -->volumes)
- $GOPATH/src/chaincode_example02:/opt/gopath/src/chaincode_example02
Then, the crucial point:
peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --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 $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
although I adjusted this line again so that it matched my folder structure (exchanging example.com for my domain and so on.)
That solved the issue.

Related

Some problems on QUIC-GO example server

The situation is, I wanna establish a QUIC connection based on quic-go from local to ECS server. The related tests using localhost are done both on local and remote device. That is:
#local: .$QUIC-GO-PATH/example/client/main -insecure -keylog ssl.log -qlog trial.log -v https://127.0.0.1:6121/demo/tile
#local: .$QUIC-GO-PATH/example/main -qlog -tcp -v
These tests are completed.
Now is the problem,when I start local-remote connection an error occurred:
#remote: .$QUIC-GO-PATH/example/main -qlog -tcp -v
#local: .$QUIC-GO-PATH/example/client/main -insecure -keylog ssl.log -qlog trial.log -v https://$REMOTE_IPADDR:6121/demo/tile
timeout: no recent network activity
When I go through a wireshark examination, it seems like the CRYPTO handshake never finishes:
Wireshark
Also client Qlog file atteched here:
Qlog file
Codes are all the same with https://github.com/lucas-clemente/quic-go
Help!
This problem has been solved.
Code $QUIC-GO-PATH/example/main.go has binded the port as a default onto 127.0.0.1:6121, which led to the problem that the server cannot get reached by client outside, just get this on server running:
-bind 0.0.0.0:6121

No chaincode found on peer after installation through peer lifecycle

I follow by instruction from the fabric-sample/test-network, but trying to reproduce steps of control in docker container. All steps of chaincode installation went good except one of the final - peer chaincode invoke.
On this step I got an error: 2020-07-09 10:40:00.755 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> DEBU 05a ESCC invoke result: response:<status:500 message:"make sure the chaincode fabcar has been successfully defined on channel appchannel and try again: chaincode definition for 'fabcar' exists, but chaincode is not installed" > Error: endorsement failure during invoke. response: status:500 message:"make sure the chaincode fabcar has been successfully defined on channel appchannel and try again: chaincode definition for 'fabcar' exists, but chaincode is not installed"
When I check chaincode with peer lifecycle chaincode queryinstalled I receive a normal response:
Installed chaincodes on peer: Package ID: fabcar_1:644530ed4e097a65073d6e0fc8a7aaa9282945e55aa1ec7d2014746fd598f631, Label: fabcar_1
But when I check chaincode with peer chaincode list --installed I receive empty set:
Get installed chaincodes on peer:
configtx.yaml from test-example is used.
Where is my mistake?
Here is my Dockerfile. The main idea is to make a self-sufficient docker environment of hyperledger with outscripting needs.
The command peer chaincode ... use the LSCC - Lifecycle System Chaincode, which is used for the 1.x Fabric network. The 2.x docs about this here
You can try using the old-style command to install chaincode peer chaincode install ..., then you can query the installed chaincode with peer chaincode list --installed. But from version 2.0, it's recommended using the new lifecycle chaincode.
I also found the in-practice chaincode comparison of version 1.4 and 2.0 here. Hope this can give you some ideas.
As mentioned by #HoaiNam that you have to use fabricv2.x api's since you are using test-network. Also you can try previous command by adding v1.4.x capabilities(not sure). for understanding latest CC lifecycle process, you can refer here. for commands, you can refer to test-network/scripts/deployCC.sh. I hope this helps.
In the new lifecycle we have to use :
peer lifecycle chaincode queryinstalled
In the old lifecycle we use
peer chaincode list --installed

Error starting hyperledger-composer network after Fabric and Composer version upgrade

I've come across an error starting the hyperledger-composer network that isn't answered in the composer-wiki.
✖ Starting business network definition. This may take a minute...
Error: Error trying to start business network. Error: No valid responses from any peers.
Response from attempted peer comms was an error: Error: transaction returned with failure: can't find PEM header: undefined
Command failed
Checking pre-requisites,
Fabric 1.2
Composer 0.20.4
Node 8.12.0
Docker 18.01.1
"composer network install" was successful, with file appearing in the docker peer at /var/hyperleder/production/chaincodes
After running the "composer network start" command, a "docker ps" shows new docker instance with name:
dev-peer0.org1.example.com-<<business-network-name>>-0.0.7
But any attempt to ping this results in a failure like this:
Error: Error trying to ping. Error: make sure the chaincode <<business-network-name>> has been successfully instantiated and try again: getccdata composerchannel/<<business-network-name>> responded with error: could not find chaincode with name '<<business-network-name>>'
Checking the log of the dev-peer0, it ends with the following:
2018-11-05T05:03:18.227Z [4264161f] ERROR :Composer :Init() can't find PEM header: undefined
2018-11-05T05:03:18.227Z [4264161f] VERBOSE :Composer :#PERF Init() Total (ms) duration for txnID [4264161fc30a61c70884d4c7efb460fea6a755d07bc4852875c393346795227a]: 929.00
2018-11-05T05:03:18.228Z ERROR [lib/handler.js] [composerchannel-4264161f]Calling chaincode Init() returned error response [can't find PEM header: undefined]. Sending ERROR message back to peer
The corresponding error in the peer0 log is a big larger:
2018-11-05 05:03:18.229 UTC [endorser] SimulateProposal -> ERRO 439d [composerchannel][4264161f] failed to invoke chaincode name:"lscc" , error: transaction returned with failure: can't find PEM header: undefined
github.com/hyperledger/fabric/core/chaincode.(*ChaincodeSupport).Execute
/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/chaincode_support.go:202
github.com/hyperledger/fabric/core/endorser.(*SupportImpl).Execute
/opt/gopath/src/github.com/hyperledger/fabric/core/endorser/support.go:131
github.com/hyperledger/fabric/core/endorser.(*Endorser).callChaincode
/opt/gopath/src/github.com/hyperledger/fabric/core/endorser/endorser.go:173
github.com/hyperledger/fabric/core/endorser.(*Endorser).SimulateProposal
/opt/gopath/src/github.com/hyperledger/fabric/core/endorser/endorser.go:287
github.com/hyperledger/fabric/core/endorser.(*Endorser).ProcessProposal
/opt/gopath/src/github.com/hyperledger/fabric/core/endorser/endorser.go:501
github.com/hyperledger/fabric/core/handlers/auth/filter.(*expirationCheckFilter).ProcessProposal
/opt/gopath/src/github.com/hyperledger/fabric/core/handlers/auth/filter/expiration.go:61
github.com/hyperledger/fabric/core/handlers/auth/filter.(*filter).ProcessProposal
/opt/gopath/src/github.com/hyperledger/fabric/core/handlers/auth/filter/filter.go:31
github.com/hyperledger/fabric/protos/peer._Endorser_ProcessProposal_Handler
/opt/gopath/src/github.com/hyperledger/fabric/protos/peer/peer.pb.go:112
github.com/hyperledger/fabric/vendor/google.golang.org/grpc.(*Server).processUnaryRPC
/opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/server.go:923
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:1148
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:637
runtime.goexit
/opt/go/src/runtime/asm_amd64.s:2361
2018-11-05 05:03:18.229 UTC [endorser] SimulateProposal -> DEBU 439e [composerchannel][4264161f] Exit
Since this last worked I have updated composer from 0.19 to 0.20.4, and taken Fabric from 1.1 to 1.2.
Googling suggests that this kind of error "can't find PEM header: undefined" is associated with a change in key signing. After tearing down Fabric I re-ran ./createPeerAdminCard.sh - is there another card or similar that needs to be re-created to accomodate the latest versions?
Thanks to #R Thatcher for putting me onto the right direction. This was all down to mismatching cards, and was resolved by clearing out everything and starting again.
Specifically, in /fabric-dev-servers:
./stopFabric.sh
./teardownFabric.sh
composer card list
composer card delete -c admin#<business-network-name>
composer card delete -c PeerAdmin#hlfv1
./startFabric.sh
./createPeerAdminCard.sh
Then changing into the composer/business-network-name directory:
composer network install --card PeerAdmin#hlfv1 --archiveFile business-network-name\#0.0.7.bna
composer network start -c PeerAdmin#hlfv1 -n business-network-name -V 0.0.7 -A admin -S adminpw --file networkadmin.card
composer card import --file networkadmin.card --card admin#business-network-name
composer network ping -c admin#business-network-name
So yes, it was about mismatching cards and not cleaning these up as part of a new deployment.
Although not part of the original problem, it's also worth noting that the -A and -S parameters of the composer network start command HAD to be set to admin and adminpw respectively. See composer issue #3781.
Answering the the last remark from #Capn Sparrow
"the -A and -S parameters of the composer network start command HAD to be set to admin and adminpw respectively."
This is the correct and expected behaviour :-)
with the composer network start command the -A and -S are specifying an existing user in the CA that we want a new set of Credentials (certificate and keys) for which is then bound to a Composer System participant.
When you use the 'standard development fabric' this has a CA configured with a user called 'admin' with a secret of 'adminpw'. If you had build your own Fabric from scratch you could choose the name and secret of your first default user. Alternatively you could work with the fabric-ca client software to create additional users in the CA.

How to connect to Bigtable Emulator from a GoLang application? How to use it?

I am trying to use BigTable Emulator. I have never used it before. I followed the documentation but not able to understand,
How to connect an application to Emulator.
How to set BIGTABLE_EMULATOR_HOST environment variable.
Please help by explaining it or pointing me to any examples or links.
Thank you.
The BIGTABLE_EMULATOR_HOST environment variable overrides the normal connection logic. Having it set causes a client to connect to the emulator without any special changes needed in the code (i.e. the project/instance values passed to NewAdminClient()/NewClient() are ignored).
The command provided in step 2 of the Using the emulator instructions sets the environment variable for you.
See the implementation of GoogleCloudPlatform/golang-samples/bigtable/helloworld/main.go for a simple, concrete example of interacting with a BigTable instance.
Walkthrough
To demonstrate using the Bigtable Emulator from go, I'm using a free tier, f1-micro Compute Engine instance. It's an instance where I hadn't used go before, so it's basically a clean slate.
First things first, I setup my go environment:
$ sudo apt install golang
<... SNIP apt output ...>
$ mkdir ~/go
$ export GOPATH=$HOME/go
Then I updated the google-cloud-sdk package and installed the google-cloud-sdk-bigtable-emulator package:
$ sudo apt install google-cloud-sdk
<... SNIP apt output ...>
$ sudo apt install google-cloud-sdk-bigtable-emulator
<... SNIP apt output ...>
At this point the emulator is ready to run, so I started it using the documented command:
$ gcloud beta emulators bigtable start
Executing: /usr/lib/google-cloud-sdk/platform/bigtable-emulator/cbtemulator --host=localhost --port=8086
[bigtable] Cloud Bigtable emulator running on 127.0.0.1:8086
After starting it, it runs in the foreground, so I left that terminal alone and started a new one.
In the new terminal, the first thing is setting the BIGTABLE_EMULATOR_HOST environment variable. This step is documented in the emulator instructions. The following command generates the shell command for setting the variable. To see the command it generates it, run it directly:
$ gcloud beta emulators bigtable env-init
export BIGTABLE_EMULATOR_HOST=localhost:8086
Running the command enclosed in $(...) as documented tells the shell to execute the output of the command, thereby setting the variable:
$ $(gcloud beta emulators bigtable env-init)
Now that the emulator is running and the environment is ready, I need a client application to to connect to it. I chose to use the helloworld application from the GoogleCloudPlatform/golang-samples repository.
$ git clone https://github.com/GoogleCloudPlatform/golang-samples.git
$ cd golang-samples/bigtable/helloworld
In the main.go file in the above directory, the cloud.google.com/go/bigtable and golang.org/x/net/context packages are imported, so I ran go get to fetch both of them.
$ go get cloud.google.com/go/bigtable
$ go get golang.org/x/net/context
Then I ran the example application, using dummy values for the -project and -instance flags, since it's going to be connecting to the locally running emulator.
$ go run main.go -project foo -instance bar
2018/06/18 00:39:27 Creating table Hello-Bigtable
2018/06/18 00:39:27 Writing greeting rows to table
2018/06/18 00:39:27 Getting a single greeting by row key:
2018/06/18 00:39:27 greeting0 = Hello World!
2018/06/18 00:39:27 Reading all greeting rows:
2018/06/18 00:39:27 greeting0 = Hello World!
2018/06/18 00:39:27 greeting1 = Hello Cloud Bigtable!
2018/06/18 00:39:27 greeting2 = Hello golang!
2018/06/18 00:39:27 Deleting the table
Nothing really happens in the emulator terminal to indicate it's being used. So, to demonstrate that it's actually interacting with the emulator, I stopped the emulator process (by pressing Ctrl-C in it's terminal) and tried executing the client application again:
$ go run main.go -project foo -instance bar
2018/06/18 00:40:03 Retryable error: rpc error: code = Unavailable desc = all SubConns are in TransientFailure, latest connection error: connection error: desc = "transport: Error while dialing dial tcp [::1]:8086: getsockopt: connection refused", retrying in 47.77941ms
2018/06/18 00:40:03 Retryable error: rpc error: code = Unavailable desc = all SubConns are in TransientFailure, latest connection error: connection error: desc = "transport: Error while dialing dial tcp [::1]:8086: getsockopt: connection refused", retrying in 2.153551ms
2018/06/18 00:40:03 Retryable error: rpc error: code = Unavailable desc = all SubConns are in TransientFailure, latest connection error: connection error: desc = "transport: Error while dialing dial tcp [::1]:8086: getsockopt: connection refused", retrying in 114.145821ms
<... SNIP repeated errors ...>
^Csignal: interrupt
$
So, using an unmodified client application interacts with the emulator just by having the proper environment variable set.

Hyperledger-fabric fails to instantiate chaincode

I am unable to instantiate chaincode in Hyperledge Fabric.
When executing:
peer chaincode instantiate -o orderer -n test_cc -C test-channel -v 0.1 -c '{"Args":["initLedger"]}'
I get the error:
peer0 | 2018-04-17 13:02:11.097 UTC [dockercontroller] Start -> ERRO 046 start-could not start container: API error (400): {"message":"OCI runtime create failed: container_linux.go:348: starting container process caused \"exec: \\\"chaincode\\\": executable file not found in $PATH\": unknown"}
When searching the internet, the error message is the same as on the original post at [OCI Runtimer Error when installing Hyperledger Chaincode via Java-SDK and [OCI runtime error when sending Hyperledger Fabric's chaincode instantiation request to peers, but the comments on these posts did not led me to the solution.
I am using the following software versions:
Hyperledger 1.1.0
Docker version 18.03.0-ce (on Linux), Hyperledger Docker images: x86_64-1.1.0
The following steps succeed:
Building the chaincode. The code compiles without errors. I did not include any dependencies except the two required "github.com/hyperledger/fabric/core/chaincode/shim" and
"github.com/hyperledger/fabric/protos/peer"
Packaging the chaincode.
Signing the chaincode.
Installing the chaincode (it ends up in the peer's /var/hyperledger/production/chaincodes/test_cc.0.1.
(Steps according to Hyperledger documentation: [http://hyperledger-fabric-docs.readthedocs.io/en/latest/chaincode4noah.html])
In the CLI Docker container, files are located in the directory /opt/gopath/src/chaincode/go/test_cc/, where 4 files are present: test_cc, test_cc.go, test_cc_pack.out, test_cc_signed_pack.out (the binary, source file, packaged file and signed package file).
The full output of the orderer and peer is:
orderer | 2018-04-17 13:29:43.617 UTC [orderer/common/server] Broadcast -> DEBU 167 Starting new Broadcast handler
orderer | 2018-04-17 13:29:43.617 UTC [orderer/common/broadcast] Handle -> DEBU 168 Starting new broadcast loop for 172.18.0.6:41228
couchdb | [notice] 2018-04-17T13:29:43.624931Z nonode#nohost <0.16042.3> b5d38cd27d couchdb:5984 172.18.0.5 undefined GET /test-channel_lscc/test_cc?attachments=true 404 ok 2
peer | 2018-04-17 13:29:44.416 UTC [dockercontroller] Start -> ERRO 04a start-could not start container: API error (400): {"message":"OCI runtime create failed: container_linux.go:348: starting container process caused \"exec: \\\"chaincode\\\": executable file not found in $PATH\": unknown"}
peer | 2018-04-17 13:29:44.647 UTC [chaincode] Launch -> ERRO 04b launchAndWaitForRegister failed: API error (400): {"message":"OCI runtime create failed: container_linux.go:348: starting container process caused \"exec: \\\"chaincode\\\": executable file not found in $PATH\": unknown"}
peer |
peer | error starting container
peer | 2018-04-17 13:29:44.647 UTC [endorser] simulateProposal -> ERRO 04c [test-channel][39e4414a] failed to invoke chaincode name:"lscc" , error: API error (400): {"message":"OCI runtime create failed: container_linux.go:348: starting container process caused \"exec: \\\"chaincode\\\": executable file not found in $PATH\": unknown"}
peer |
peer | error starting container
orderer | 2018-04-17 13:29:44.648 UTC [orderer/common/broadcast] Handle -> DEBU 169 Received EOF from 172.18.0.6:41228, hangup
orderer | 2018-04-17 13:29:44.648 UTC [orderer/common/server] func1 -> DEBU 16a Closing Broadcast stream
It looks like there is some path issue, but the process of the creation of the chaincode container and the variables which influence this process.
I'm messing around with this issue for few days(!) now, tried all path combinations like placing the file in /opt/gopath/bin, etcetera, but to no avail.
Someone who can shine a light on this issue? Or knows what the correct paths are and where they are, or where they should be defined?
Thanks
The issue was that in the Go source files I used 'package test_package', which, when building, does not create an executable file, but a linkable object file.
Having 'package main' in my Go files, then rebuilding and repackaging, made the 'peer chaincode install' and 'peer chaincode instantiate' commands working as expected.

Resources