Hyperledger Fabric:panic:运行时错误:fabric / peer / common.NewPeerClientForAddress上的内存地址无效或nil指针取消引用

问题描述 投票:0回答:1

我们尝试使用以下命令调用chaincode:

FABRIC_CFG_PATH=${PWD} CORE_PEER_LOCALMSPID=org1MSP CORE_LOGGING_LEVEL=debug CORE_PEER_TLS_ENABLED=true CORE_PEER_TLS_CLIENTAUTHREQUIRED=true CORE_PEER_MSPCONFIGPATH=msp CORE_PEER_TLS_CLIENTCERT_FILE=user-org1-tls.pem CORE_PEER_TLS_CLIENTKEY_FILE=user-org1-tls.key peer chaincode invoke -C dscsa -n mycc -c '{"Args":["create","00000"]}' -o orderer1-ord:7050 --tls --cafile ord-ca-chain.pem --peerAddresses peer3-org1:7051 --tlsRootCertFiles org1-ca-chain.pem --peerAddresses peer3-org2:7051 --tlsRootCertFiles org2-ca-chain.pem --peerAddresses peer3-org3:7051 --tlsRootCertFiles org3-ca-chain.pem

但得到这个错误:

2019-03-21 19:04:37.459 UTC [msp] Validate -> DEBU 036 MSP org1MSP validating identity
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x60 pc=0x110fddc]

goroutine 1 [running]:
github.com/hyperledger/fabric/peer/common.NewPeerClientForAddress(0x7ffd955fe783, 0x9, 0x7ffd955fe7a0, 0x10, 0x8fb52c, 0x9e8745, 0x14848a7)
    /opt/gopath/src/github.com/hyperledger/fabric/peer/common/peerclient.go:44 +0x8c
github.com/hyperledger/fabric/peer/common.GetEndorserClient(0x7ffd955fe783, 0x9, 0x7ffd955fe7a0, 0x10, 0x4, 0x1, 0xc4205d1988, 0x9e5bec)
    /opt/gopath/src/github.com/hyperledger/fabric/peer/common/peerclient.go:122 +0x56
github.com/hyperledger/fabric/peer/chaincode.InitCmdFactory(0x1482fcf, 0x6, 0x101, 0x1a, 0x13b1dc0, 0xc420181f90)
    /opt/gopath/src/github.com/hyperledger/fabric/peer/chaincode/common.go:369 +0xb19
github.com/hyperledger/fabric/peer/chaincode.chaincodeInvoke(0xc4200d9680, 0x0, 0x0, 0x0)
    /opt/gopath/src/github.com/hyperledger/fabric/peer/chaincode/invoke.go:53 +0xff
github.com/hyperledger/fabric/peer/chaincode.invokeCmd.func1(0xc4200d9680, 0xc4202be600, 0x0, 0x17, 0x0, 0x0)
    /opt/gopath/src/github.com/hyperledger/fabric/peer/chaincode/invoke.go:26 +0x34
github.com/hyperledger/fabric/vendor/github.com/spf13/cobra.(*Command).execute(0xc4200d9680, 0xc4202be480, 0x17, 0x18, 0xc4200d9680, 0xc4202be480)
    /opt/gopath/src/github.com/hyperledger/fabric/vendor/github.com/spf13/cobra/command.go:698 +0x46d
github.com/hyperledger/fabric/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0x1c90320, 0x1d78c30, 0xf, 0x1)
    /opt/gopath/src/github.com/hyperledger/fabric/vendor/github.com/spf13/cobra/command.go:783 +0x2e4
github.com/hyperledger/fabric/vendor/github.com/spf13/cobra.(*Command).Execute(0x1c90320, 0x1, 0xffffffffffffffff)
    /opt/gopath/src/github.com/hyperledger/fabric/vendor/github.com/spf13/cobra/command.go:736 +0x2b
main.main()
    /opt/gopath/src/github.com/hyperledger/fabric/peer/main.go:97 +0x5bf

我们正在使用v1.3的面料。我们怎么解决这个问题?

hyperledger-fabric
1个回答
0
投票

如果CORE_PEER_TLS_CLIENTCERT_FILECORE_PEER_TLS_CLIENTKEY_FILE不存在,则可能发生上述错误。您不会收到错误,说文件不存在。而是你得到上面的错误。

还需要设置CORE_PEER_ADDRESSCORE_PEER_TLS_ROOTCERT_FILE。如果未设置环境变量,Fabric将使用core.yaml中的设置来获取这些变量。

func NewPeerClientForAddress(address, tlsRootCertFile string) (*PeerClient, error) {
    if address == "" {
        return nil, errors.New("peer address must be set")
    }

    _, override, clientConfig, err := configFromEnv("peer")
    if clientConfig.SecOpts.UseTLS {
        if tlsRootCertFile == "" {
            return nil, errors.New("tls root cert file must be set")
        }
        caPEM, res := ioutil.ReadFile(tlsRootCertFile)
        if res != nil {
            err = errors.WithMessage(res, fmt.Sprintf("unable to load TLS root cert file from %s", tlsRootCertFile))
            return nil, err
        }
        clientConfig.SecOpts.ServerRootCAs = [][]byte{caPEM}
    }
    return newPeerClientForClientConfig(address, override, clientConfig)
}
© www.soinside.com 2019 - 2024. All rights reserved.