securekey / fabric-examples

133 stars 58 forks source link

Error when attempting to instantiate chaincode: cannot find package #18

Closed Shirikatsu closed 5 years ago

Shirikatsu commented 5 years ago

I am using the example network to attempt to deploy custom chaincode:

$ make example-network

and installing, in this instance, EVM chaincode:

$ go run fabric-cli.go chaincode install --ccp=github.com/hyperledger/fabric-chaincode-evm/evmcc --ccid=EvmCC --v v0 --gopath /home/me/go --config ../../test/fixtures/config/config_test_local.yaml
Installing chaincode EvmCC on org[org1] peers:
-- localhost:7051
-- localhost:7151
...successfuly installed chaincode EvmCC.v0 on peer localhost:7151.
...successfuly installed chaincode EvmCC.v0 on peer localhost:7051.
Installing chaincode EvmCC on org[org2] peers:
-- localhost:8051
-- localhost:9051
...successfuly installed chaincode EvmCC.v0 on peer localhost:9051.
...successfuly installed chaincode EvmCC.v0 on peer localhost:8051.

then instantiating results in an error that references unrecognised imports:

go run fabric-cli.go chaincode instantiate --cid orgchannel --ccp=github.com/hyperledger/fabric-chaincode-evm/evmcc --ccid=EvmCC --v v0 --args '{"Args":[]}' --policy "AND('Org1MSP.member','Org2MSP.member')" --config ../../test/fixtures/config/config_test_local.yaml
[fabriccli] 2019/01/04 11:04:20 UTC - chaincode.glob..func4 -> ERRO Error while running instantiateAction: error instantiating chaincode: sending deploy transaction proposal failed: Transaction processing for endorser [localhost:7051]: Chaincode status Code: (500) UNKNOWN. Description: error starting container: error starting container: Failed to generate platform-specific docker build: Error returned from build: 1 "chaincode/input/src/github.com/hyperledger/fabric-chaincode-evm/evmcc/evmcc.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/github.com/hyperledger/fabric-chaincode-evm/evmcc/evmcc.go:16:2: cannot find package "github.com/hyperledger/burrow/account" in any of:
    /opt/go/src/github.com/hyperledger/burrow/account (from $GOROOT)
    /chaincode/input/src/github.com/hyperledger/burrow/account (from $GOPATH)
    /opt/gopath/src/github.com/hyperledger/burrow/account
chaincode/input/src/github.com/hyperledger/fabric-chaincode-evm/evmcc/evmcc.go:17:2: cannot find package "github.com/hyperledger/burrow/binary" in any of:
    /opt/go/src/github.com/hyperledger/burrow/binary (from $GOROOT)
    /chaincode/input/src/github.com/hyperledger/burrow/binary (from $GOPATH)
    /opt/gopath/src/github.com/hyperledger/burrow/binary
chaincode/input/src/github.com/hyperledger/fabric-chaincode-evm/evmcc/evmcc.go:18:2: cannot find package "github.com/hyperledger/burrow/execution/evm" in any of:
    /opt/go/src/github.com/hyperledger/burrow/execution/evm (from $GOROOT)
    /chaincode/input/src/github.com/hyperledger/burrow/execution/evm (from $GOPATH)
    /opt/gopath/src/github.com/hyperledger/burrow/execution/evm
chaincode/input/src/github.com/hyperledger/fabric-chaincode-evm/evmcc/evmcc.go:19:2: cannot find package "github.com/hyperledger/burrow/logging" in any of:
    /opt/go/src/github.com/hyperledger/burrow/logging (from $GOROOT)
    /chaincode/input/src/github.com/hyperledger/burrow/logging (from $GOPATH)
    /opt/gopath/src/github.com/hyperledger/burrow/logging
chaincode/input/src/github.com/hyperledger/fabric-chaincode-evm/evmcc/evmcc.go:20:2: cannot find package "github.com/hyperledger/fabric-chaincode-evm/event" in any of:
    /opt/go/src/github.com/hyperledger/fabric-chaincode-evm/event (from $GOROOT)
    /chaincode/input/src/github.com/hyperledger/fabric-chaincode-evm/event (from $GOPATH)
    /opt/gopath/src/github.com/hyperledger/fabric-chaincode-evm/event
chaincode/input/src/github.com/hyperledger/fabric-chaincode-evm/evmcc/evmcc.go:21:2: cannot find package "github.com/hyperledger/fabric-chaincode-evm/statemanager" in any of:
    /opt/go/src/github.com/hyperledger/fabric-chaincode-evm/statemanager (from $GOROOT)
    /chaincode/input/src/github.com/hyperledger/fabric-chaincode-evm/statemanager (from $GOPATH)
    /opt/gopath/src/github.com/hyperledger/fabric-chaincode-evm/statemanager
chaincode/input/src/github.com/hyperledger/fabric-chaincode-evm/evmcc/evmcc.go:26:2: cannot find package "golang.org/x/crypto/sha3" in any of:
    /opt/go/src/golang.org/x/crypto/sha3 (from $GOROOT)
    /chaincode/input/src/golang.org/x/crypto/sha3 (from $GOPATH)
    /opt/gopath/src/golang.org/x/crypto/sha3
"

As a test I included an extra import to the successfully instantiating example_cc.go code (and an extra omitted line to silence the unused import error):

...
import (
    "fmt"
    "strconv"

    "github.com/hyperledger/fabric/core/chaincode/shim"
    pb "github.com/hyperledger/fabric/protos/peer"
    "github.com/golang/protobuf/proto" // The added import
)
...

and instantiating this failed with:

$ go run fabric-cli.go chaincode instantiate --cid orgchannel --ccp=github.com/securekey/example_cc --ccid ExampleCC --v v0 --args '{"Args":["A","1","B","2"]}' --policy "AND('Org1MSP.member','Org2MSP.member')" --config ../../test/fixtures/config/config_test_local.yaml
 [fabriccli] 2019/01/04 14:20:43 UTC - chaincode.glob..func4 -> ERRO Error while running instantiateAction: error instantiating chaincode: sending deploy transaction proposal failed: Transaction processing for endorser [localhost:7051]: Chaincode status Code: (500) UNKNOWN. Description: error starting container: error starting container: Failed to generate platform-specific docker build: Error returned from build: 2 "# github.com/securekey/example_cc
chaincode/input/src/github.com/securekey/example_cc/example_cc.go:38:2: undefined: proto
"

It seems as though other external imports are somehow not found. Is this due to the fact that they are not installed on the peer and as such only Hyperledger libraries are usable without manual installation? How would one install dependencies of chaincode like this?

bstasyszyn commented 5 years ago

You'll need to add all non-fabric dependencies to a vendor folder under your chaincode folder - i.e. github.com/hyperledger/fabric-chaincode-evm/evmcc/vendor. You can either use govendor or dep to populate it.

Shirikatsu commented 5 years ago

Thanks for educating me on some go dependency stuff and troubleshooting my issue :) It works, much appreciated.