Chaincode instantiation failing with other go packages - hyperledger-fabric

need help on chaincode instantiation which is dependent on other go packages like golang/protobuf and pkg/errors. Below is the error i am getting in the peer logs,
2018-01-10 19:59:42.040 UTC [endorser] simulateProposal -> ERRO 405 failed to invoke chaincode name:"lscc" on transaction 380f014688cb8638b66cc9e9c8c85f1bf06ba062fbb979442483f7e9ae2139be, error: Error starting container: Failed to generate platform-specific docker build: Error returned from build: 1 "chaincode/input/src/Loyalty/loyalty.go:15:2: cannot find package "github.com/golang/protobuf/proto" in any of:
/opt/go/src/github.com/golang/protobuf/proto (from $GOROOT)
/chaincode/input/src/github.com/golang/protobuf/proto (from $GOPATH)
/opt/gopath/src/github.com/golang/protobuf/proto
chaincode/input/src/Loyalty/loyalty.go:18:2: cannot find package "github.com/pkg/errors" in any of:
/opt/go/src/github.com/pkg/errors (from $GOROOT)
/chaincode/input/src/github.com/pkg/errors (from $GOPATH)
/opt/gopath/src/github.com/pkg/errors
I've already mounted these to the peer docker and are present at these /opt/gopath/src/github.com/golang/protobuf/proto locations

In order to compile chaincode the peer starts new container using fabric-ccenv base image. As a result mounted to the peer folder /opt/gopath/src/github.com/golang/protobuf/proto is not available at runtime.
It's better to vendor the proto package with the chaincode, try to run following command in the root folder of your project:
govendor add github.com/golang/protobuf/proto
This command should create subfolder vendor/github.com/golang/protobuf/proto and populate it with all necessary files.
Just try to install your chaincode again, required dependencies will be shipped with your source code and are availalbe in runtime.

Related

Error While Installing Fabric Chaincode: _lifecycle.syscc: no such file or directory

While trying to install chaincode using Fabric v2.1, I am encountering an error. Does anyone face similar issues? My peer is running fine and able to join the channel as well. I am able to list the channel details as well.
Note: I am doing Native installation without using docker images for running orderer and peer.
Highly appreciate for your support and looking forward to hear from you.
Error:
chaincode install failed with status: 500 - error in simulation: failed to execute transaction 44688cc50afeda03e3f5e7735ae650030952477b6bdfce83064582f42bec6c84: could not launch chaincode _lifecycle.syscc: error building chaincode: error building image: failed to get chaincode package for external build: could not get legacy chaincode package '_lifecycle.syscc': open /home/vagrant/ledger/ORG2/peer1-org2/ledger/chaincodes/_lifecycle.syscc: no such file or directory
I got this error after upgrading from 1.4. In my case the problem was in the old config file for the peer.
Make sure you have next lines in your core.yaml:
chaincode:
...
# enabled system chaincodes
system:
_lifecycle: enable

Error when deploying chaincode in test network

I've just started working on fabric an am having some trouble using the command:
./network.sh deployCC
after setting up my channels. This is the terminal readout:
'''
deploying chaincode on channel 'mychannel'
Vendoring Go dependencies ...
~/desktop/HF/fabric-samples/chaincode/fabcar/go ~/desktop/HF/fabric-samples/test-network
scripts/deployCC.sh: line 24: go: command not found
~/desktop/HF/fabric-samples/test-network
Finished vendoring Go dependencies
Using organization 1
++ peer lifecycle chaincode package fabcar.tar.gz --path ../chaincode/fabcar/go/ --lang golang --label fabcar_1
++ res=1
++ set +x
Error: failed to normalize chaincode path: failed to determine module root: exec: "go": executable file not found in $PATH
!!!!!!!!!!!!!!! Chaincode packaging on peer0.org1 has failed !!!!!!!!!!!!!!!!
ERROR !!! Deploying chaincode failed
'''
It seems that I must have messed something up in the prereqs. Any suggestions?
You are missing 'go' prerequisite. See in the test network documentation, the prerequisites section. You will need to install golang.
The Golang chaincodes can only be packaged through the CLI container. All the other language chain codes can be packaged through peer containers as well.

Where do we add external go dependenices so that while deploying the chaincode using fabric-java-sdk , the chaincode builder picks it up accordingly?

While deploying the chaincode using fabric-java-sdk , if the chaincode contains external dependencies peer throws the below error:
2019-01-11 06:10:46.220 UTC [endorser] SimulateProposal -> ERRO 2ed [mychannel][c310d352] failed to invoke chaincode name:"lscc" , error: Failed to generate platform-specific docker build: Error returned from build: 1 "chaincode/input/src/anjy/anjy.go:10:2: cannot find package "github.com/rs/xid" in any of:
/opt/go/src/github.com/rs/xid (from $GOROOT)
/chaincode/input/src/github.com/rs/xid (from $GOPATH)
/opt/gopath/src/github.com/rs/xid
"
error starting container
error starting container
The error says it was unable to find the dependencies in the $GOPATH. However my $GOPATH contains those dependencies, yet the chaincode builder is unable to pick it up.
We have to create a "vendor"-folder in the same path the chaincode is stored in.
https://hyperledger-fabric.readthedocs.io/en/v1.1.0-alpha/chaincode4ade.html#managing-external-dependencies-for-chaincode-written-in-go
Suppose the chaincode is stored in below file structure:
../src/chaincode/chaincode.go
then the vendor folder goes inside the below structure: [with dependency to the files in the vendor folder]
./src/chaincode/vendor

Fabric v1.3 chaincode could not instantiate while import 'shim/ext/statebased'

Since I tried the new feature of Fabric v1.3: key-level-endorsement from this doc, I have to generate my key-level endorsement policy by KeyEndorsementPolicy.Policy() function.
However, I cannot instantiate the chaincode after I have imported the package github.com/hyperledger/fabric/core/chaincode/shim/ext/statebased
Here are the error logs:
2018-12-11 09:58:25.518 UTC [dockercontroller] deployImage -> ERRO 053 Error building images: Failed to generate platform-specific docker build: Error returned from build: 1 "opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim/ext/statebased/statebasedimpl.go:14:2: cannot find package "github.com/hyperledger/fabric/common/cauthdsl" in any of:
/opt/gopath/src/github.com/hyperledger/fabric/vendor/github.com/hyperledger/fabric/common/cauthdsl (vendor tree)
/opt/go/src/github.com/hyperledger/fabric/common/cauthdsl (from $GOROOT)
/chaincode/input/src/github.com/hyperledger/fabric/common/cauthdsl (from $GOPATH)
/opt/gopath/src/github.com/hyperledger/fabric/common/cauthdsl
"
I know that it means ccenv container lack this dependence, so I tried to add my vendor directory under gopath to chaincode path directory of my instantiate request. Then I got another try and there are still errors:
2018-12-12 02:06:32.976 UTC [endorser] callChaincode -> INFO 092 [channelforkvepdemo][75cd50e5] Exit chaincode: name:"lscc" (34907ms)
2018-12-12 02:06:32.976 UTC [endorser] SimulateProposal -> ERRO 093 [channelforkvepdemo][75cd50e5] failed to invoke chaincode name:"lscc" , error: Failed to generate platform-specific docker build: Error returned from build: 2 "# github.com/chaincode/vendor/golang.org/x/crypto/sha3
chaincode/input/src/github.com/chaincode/vendor/golang.org/x/crypto/sha3/keccakf_amd64.go:13:6: missing function body
# github.com/chaincode/vendor/golang.org/x/sys/unix
chaincode/input/src/github.com/chaincode/vendor/golang.org/x/sys/unix/syscall_linux_amd64_gc.go:13:6: missing function body
chaincode/input/src/github.com/chaincode/vendor/golang.org/x/sys/unix/syscall_linux_gc.go:10:6: missing function body
chaincode/input/src/github.com/chaincode/vendor/golang.org/x/sys/unix/syscall_linux_gc.go:14:6: missing function body
chaincode/input/src/github.com/chaincode/vendor/golang.org/x/sys/unix/syscall_unix_gc.go:12:6: missing function body
chaincode/input/src/github.com/chaincode/vendor/golang.org/x/sys/unix/syscall_unix_gc.go:13:6: missing function body
chaincode/input/src/github.com/chaincode/vendor/golang.org/x/sys/unix/syscall_unix_gc.go:14:6: missing function body
chaincode/input/src/github.com/chaincode/vendor/golang.org/x/sys/unix/syscall_unix_gc.go:15:6: missing function body
"
error starting container
I suspect that there are still some c/c++ libraries missing in ccenv image.
So, how can I generate a key-level endorsement policy []byte without this KeyEndorsementPolicy? or, how can I import this shim/ext/statebased package?
That's because of a bug from fabric-sdk-node, here is the link.
After upgrade to fabric-client#1.3.0, problem solved:
npm install fabric-client#1.3.0
npm install fabric-ca-client#1.3.0

Instantiate chaincode from Java SDK

I am trying to instantiate a chaincode from a Fabric Java SDK Client using code from this
example
When i am trying to add imports inside chaincode ie
github.com/hyperledger/fabric/core/chaincode/lib/ci
I am getting error from the peer
2018-05-30 17:03:24.813 UTC [endorser] simulateProposal -> ERRO 038 [mychannel][6326fbfe] failed to invoke chaincode name:"lscc" , error: Failed to generate platform-specific docker build: Error returned from build: 1 "chaincode/input/src/github.com/ify/ify.go:40:2: cannot find package "github.com/hyperledger/fabric/core/chaincode/lib/cid" in any of:
/opt/go/src/github.com/hyperledger/fabric/core/chaincode/lib/cid (from $GOROOT)
/chaincode/input/src/github.com/hyperledger/fabric/core/chaincode/lib/cid (from $GOPATH)
/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/lib/cid
where should i install the packages inside peer in order to be visible from the go builder?
You have to put everything in vendor, as stated in the coding guidelines: Hyperledger Fabric uses Go Vendoring for package management.
In this way you can import external libraries in the chaincode.

Resources