Sumit Arora
Sumit Arora

Reputation: 5241

HyperLedger Fabric SDK Go showing cannot convert nil to type csr.KeyRequest

One of the go-lang based microservice code require to connect with fabric's chain code, It was working fine until last time, no issue so far.

But now it's showing the following issue while building the go based microservice which have fabric client code to connect with fabric chaincode.

../vendor/github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/util

../../vendor/github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/util/csp.go:47:8: cannot convert nil to type csr.KeyRequest ../../vendor/github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/util/csp.go:132:37: cannot use req.KeyRequest (type *csr.KeyRequest) as type csr.KeyRequest in argument to getBCCSPKeyOpts

Maybe its a dependency issue, I cleaned up the complete vendor directory and and done dep ensure --update ,but it showing same issue,

Further information :

Go Version 1.12

On GoPkg.Toml

[[override]] name = "github.com/hyperledger/fabric" branch = "master"

[[override]] name = "github.com/hyperledger/fabric-sdk-go" branch = "master"

I have tried various combination and different branches of fabric-sdk-go, its still showing the same, though it worked fine earlier.

Upvotes: 1

Views: 1572

Answers (5)

Sumit Arora
Sumit Arora

Reputation: 5241

I have found the root cause of that issue, Its like frequent incremental fixes/development on fab-sdk-go, and I defined the master version of fab-sdk-go on my code, and that to be fetched from Gopkg.toml file.

It took me like manually apply various versions of fab-sdk-go by dates, to figure out which is the best fab-sdk-go version, means that version which won’t give any compilation issue like above.

And when applied following version:

FAB-SDK-Go [FABG-815] make multi-errors on a single line: 56ebf9adac580e7e3251685fe4fe6e793df838dc , https://github.com/hyperledger/fabric-sdk-go/commit/56ebf9adac580e7e3251685fe4fe6e793df838dc

It didn't give any error and it worked out.

Even I applied for releases like alpha1,alpha2,aplha3 as well for fab-sdk-go, but again those gave compilation issues.

EDIT

This issue came again, done the following to fix this :

apis git:(master) ✗ go get github.com/cloudflare/cfssl@1.3.3 go: downloading github.com/cloudflare/cfssl v0.0.0-20190409034051-768cd563887f

go get: downgraded github.com/cloudflare/cfssl v1.4.1 => v0.0.0-20190409034051-768cd563887f

go get: downgraded github.com/hyperledger/fabric-sdk-go v1.0.0 => v1.0.0-beta2

apis git:(master) ✗ go mod tidy
go: downloading github.com/hyperledger/fabric-sdk-go v1.0.0-beta2

apis git:(master) ✗ go get github.com/hyperledger/fabric-sdk-go@master

go: downloading github.com/hyperledger/fabric-sdk-go v1.0.1-0.20210201220314-86344dc25e5d

go get: upgraded github.com/cloudflare/cfssl v0.0.0-20190409034051-768cd563887f => v1.4.1

go get: upgraded github.com/hyperledger/fabric-sdk-go v1.0.0-beta2 => v1.0.1-0.20210201220314-86344dc25e5d

Upvotes: 4

Adam B
Adam B

Reputation: 1158

The cause of the issue is a breaking change in verson 1.3.4 of github.com/cloudflare/cfssl/csr.

Simply install 1.3.3 with the command below and the latest version of fabric-sdk-go works without any issues.

go get github.com/cloudflare/cfssl@1.3.3

Upvotes: 1

Umutcan Korkmaz
Umutcan Korkmaz

Reputation: 11

since KeyRequest does not have an instance, it can not be converted to nil. You only have the variable kr that holds the values of the KeyRequest structure, which are string A and int S. You can try editing the csp.go like "if kr.A == "" && (kr.S != 2048 || kr.S != 3072 || kr.S != 4096)" in the line 48.

Upvotes: 0

Dave
Dave

Reputation: 21

Clean environment

Clean go.mod all require

Download the latest version

 go get github.com/hyperledger/fabric-sdk-go@master

Download dependency

go mod tidy

Upvotes: 1

rnd04
rnd04

Reputation: 51

It seems that there have been many changes on the packages which fabric-sdk-go depends on, since the release of 1.0.0-alpha5.

When I run go build now with just one importing of external dependency(github.com/hyperledger/fabric-sdk-go), I got the following go.mod file, (I use go mod for package management)

...

require (
    github.com/cloudflare/cfssl v0.0.0-20190726000631-633726f6bcb7 // indirect
    github.com/go-kit/kit v0.9.0 // indirect
    github.com/golang/mock v1.3.1 // indirect
    github.com/golang/protobuf v1.3.2 // indirect
    github.com/google/certificate-transparency-go v1.0.21 // indirect
    github.com/hyperledger/fabric-lib-go v1.0.0 // indirect
    github.com/hyperledger/fabric-sdk-go v1.0.0-alpha5
    github.com/pkg/errors v0.8.1 // indirect
    github.com/prometheus/client_golang v1.0.0 // indirect
    github.com/spf13/viper v1.4.0 // indirect
    github.com/zmap/zlint v0.0.0-20190730215301-9971d62266e7 // indirect
    golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
    google.golang.org/grpc v1.22.1 // indirect
)

which contains packages of cutting-edge version and seems to make some build problems like below, including what you had.

# github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/core/operations
../../Go/pkg/mod/github.com/hyperledger/fabric-sdk-go@v1.0.0-alpha5/internal/github.com/hyperledger/fabric/core/operations/system.go:185:43: undefined: "github.com/prometheus/client_golang/prometheus".Handler
../../Go/pkg/mod/github.com/hyperledger/fabric-sdk-go@v1.0.0-alpha5/internal/github.com/hyperledger/fabric/core/operations/system.go:227:23: not enough arguments in call to s.statsd.SendLoop
        have (<-chan time.Time, string, string)
        want (context.Context, <-chan time.Time, string, string)
# github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/util
../../Go/pkg/mod/github.com/hyperledger/fabric-sdk-go@v1.0.0-alpha5/internal/github.com/hyperledger/fabric-ca/util/csp.go:46:8: cannot convert nil to type csr.KeyRequest
../../Go/pkg/mod/github.com/hyperledger/fabric-sdk-go@v1.0.0-alpha5/internal/github.com/hyperledger/fabric-ca/util/csp.go:131:37: cannot use req.KeyRequest (type *csr.KeyRequest) as type csr.KeyRequest in argument to getBCCSPKeyOpts

I wrote go.mod file manually to contain specific versions of dependencies when I succeeded the build last time.

...
require (
    github.com/cloudflare/cfssl v0.0.0-20190409034051-768cd563887f // indirect
    github.com/go-kit/kit v0.8.0 // indirect
    github.com/go-logfmt/logfmt v0.4.0 // indirect
    github.com/golang/mock v1.3.0 // indirect
    github.com/google/certificate-transparency-go v1.0.21 // indirect
    github.com/hyperledger/fabric-lib-go v1.0.0 // indirect
    github.com/hyperledger/fabric-sdk-go v1.0.0-alpha5
    github.com/pkg/errors v0.8.1 // indirect
    github.com/prometheus/client_golang v0.9.2 // indirect
    github.com/spf13/viper v1.3.2 // indirect
    google.golang.org/grpc v1.20.1 // indirect
)

and it works well.

Upvotes: 5

Related Questions