0

当我使用 fabric-sdk-go 连接我的本地网络时,它不起作用,因为对等 peer1.org1.adbc.com 的 tls.certificate 不存在或为空。在我使用shell的时候,一切都可以正常运行,并且可以在各个节点上调用invoke命令。这个网络是基于2.3版本的fabric示例。在此基础上,我在每个组织中添加了一个节点。这是错误信息。

Failed to connect to gateway: Failed to apply config option: failed to initialize configuration: unable to load endpoint config: failed to initialize endpoint config from config backend: network configuration load failed: failed to load channel configs: failed to load channel peers: tls.certificate does not exist or empty for peer peer1.org1.adbc.com

这是 docker-compose.yaml

# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

version: '3.7'

volumes:
  orderer.adbc.com:
  peer0.org1.adbc.com:
  peer1.org1.adbc.com:
  peer0.org2.adbc.com:
  peer1.org2.adbc.com:

networks:
  test:
    name: fabric_test

services:

  orderer.adbc.com:
    container_name: orderer.adbc.com
    image: hyperledger/fabric-orderer:latest
    labels:
      service: hyperledger-fabric
    environment:
      - FABRIC_LOGGING_SPEC=INFO
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_LISTENPORT=7050
      - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
      - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
      # enabled TLS
      - ORDERER_GENERAL_TLS_ENABLED=true
      - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
      - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
      - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
      - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt
      - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key
      - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
      - ORDERER_GENERAL_BOOTSTRAPMETHOD=none
      - ORDERER_CHANNELPARTICIPATION_ENABLED=true
      - ORDERER_ADMIN_TLS_ENABLED=true
      - ORDERER_ADMIN_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
      - ORDERER_ADMIN_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
      - ORDERER_ADMIN_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
      - ORDERER_ADMIN_TLS_CLIENTROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
      - ORDERER_ADMIN_LISTENADDRESS=0.0.0.0:7053
      - ORDERER_OPERATIONS_LISTENADDRESS=0.0.0.0:17050
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: orderer
    volumes:
        - ../system-genesis-block/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
        - ../organizations/ordererOrganizations/adbc.com/orderers/orderer.adbc.com/msp:/var/hyperledger/orderer/msp
        - ../organizations/ordererOrganizations/adbc.com/orderers/orderer.adbc.com/tls/:/var/hyperledger/orderer/tls
        - orderer.adbc.com:/var/hyperledger/production/orderer
    ports:
      - 7050:7050
      - 7053:7053
      - 17050:17050
    networks:
      - test

  peer0.org1.adbc.com:
    container_name: peer0.org1.adbc.com
    image: hyperledger/fabric-peer:latest
    labels:
      service: hyperledger-fabric
    environment:
      #Generic peer variables
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=fabric_test
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_PROFILE_ENABLED=false
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
      # Peer specific variables
      - CORE_PEER_ID=peer0.org1.adbc.com
      - CORE_PEER_ADDRESS=peer0.org1.adbc.com:7051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:7051
      - CORE_PEER_CHAINCODEADDRESS=peer0.org1.adbc.com:7052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org1.adbc.com:8051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.adbc.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
    volumes:
        - ${DOCKER_SOCK}:/host/var/run/docker.sock
        - ../organizations/peerOrganizations/org1.adbc.com/peers/peer0.org1.adbc.com/msp:/etc/hyperledger/fabric/msp
        - ../organizations/peerOrganizations/org1.adbc.com/peers/peer0.org1.adbc.com/tls:/etc/hyperledger/fabric/tls
        - peer0.org1.adbc.com:/var/hyperledger/production
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 7051:7051
    networks:
      - test

  peer1.org1.adbc.com:
    container_name: peer1.org1.adbc.com
    image: hyperledger/fabric-peer:latest
    labels:
      service: hyperledger-fabric
    environment:
      #Generic peer variables
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=fabric_test
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_PROFILE_ENABLED=false
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
      # Peer specific variables
      - CORE_PEER_ID=peer1.org1.adbc.com
      - CORE_PEER_ADDRESS=peer1.org1.adbc.com:8051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:8051
      - CORE_PEER_CHAINCODEADDRESS=peer1.org1.adbc.com:7052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.adbc.com:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.adbc.com:8051
      - CORE_PEER_LOCALMSPID=Org1MSP
    volumes:
      - ${DOCKER_SOCK}:/host/var/run/docker.sock
      - ../organizations/peerOrganizations/org1.adbc.com/peers/peer1.org1.adbc.com/msp:/etc/hyperledger/fabric/msp
      - ../organizations/peerOrganizations/org1.adbc.com/peers/peer1.org1.adbc.com/tls:/etc/hyperledger/fabric/tls
      - peer1.org1.adbc.com:/var/hyperledger/production
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 8051:8051
    networks:
      - test
  peer0.org2.adbc.com:
    container_name: peer0.org2.adbc.com
    image: hyperledger/fabric-peer:latest
    labels:
      service: hyperledger-fabric
    environment:
      #Generic peer variables
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=fabric_test
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_PROFILE_ENABLED=false
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
      # Peer specific variables
      - CORE_PEER_ID=peer0.org2.adbc.com
      - CORE_PEER_ADDRESS=peer0.org2.adbc.com:9051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:9051
      - CORE_PEER_CHAINCODEADDRESS=peer0.org2.adbc.com:9052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:9052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.adbc.com:9051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org2.adbc.com:10051
      - CORE_PEER_LOCALMSPID=Org2MSP
    volumes:
        - ${DOCKER_SOCK}:/host/var/run/docker.sock
        - ../organizations/peerOrganizations/org2.adbc.com/peers/peer0.org2.adbc.com/msp:/etc/hyperledger/fabric/msp
        - ../organizations/peerOrganizations/org2.adbc.com/peers/peer0.org2.adbc.com/tls:/etc/hyperledger/fabric/tls
        - peer0.org2.adbc.com:/var/hyperledger/production
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 9051:9051
    networks:
      - test
  peer1.org2.adbc.com:
    container_name: peer1.org2.adbc.com
    image: hyperledger/fabric-peer:latest
    labels:
      service: hyperledger-fabric
    environment:
      #Generic peer variables
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=fabric_test
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_PROFILE_ENABLED=false
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
      # Peer specific variables
      - CORE_PEER_ID=peer1.org2.adbc.com
      - CORE_PEER_ADDRESS=peer1.org2.adbc.com:10051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:10051
      - CORE_PEER_CHAINCODEADDRESS=peer1.org2.adbc.com:10052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:10052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org2.adbc.com:10051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org2.adbc.com:9051
      - CORE_PEER_LOCALMSPID=Org2MSP
    volumes:
      - ${DOCKER_SOCK}:/host/var/run/docker.sock
      - ../organizations/peerOrganizations/org2.adbc.com/peers/peer1.org2.adbc.com/msp:/etc/hyperledger/fabric/msp
      - ../organizations/peerOrganizations/org2.adbc.com/peers/peer1.org2.adbc.com/tls:/etc/hyperledger/fabric/tls
      - peer1.org2.adbc.com:/var/hyperledger/production
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 10051:10051
    networks:
      - test

  cli:
    container_name: cli
    image: hyperledger/fabric-tools:latest
    labels:
      service: hyperledger-fabric
    tty: true
    stdin_open: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: /bin/bash
    volumes:
        - ../organizations:/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations
        - ../scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
    depends_on:
      - peer0.org1.adbc.com
      - peer0.org2.adbc.com
      - peer1.org1.adbc.com
      - peer1.org2.adbc.com
    networks:
      - test

这是连接配置

---
name: test-network-org1
version: 1.0.0
client:
  organization: Org1
  connection:
    timeout:
      peer:
        endorser: '300'
organizations:
  Org1:
    mspid: Org1MSP
    peers:
    - peer0.org1.adbc.com
    - peer1.org1.adbc.com
    certificateAuthorities:
    - ca.org1.adbc.com
peers:
  peer0.org1.adbc.com:
    url: grpcs://localhost:7051
    tlsCACerts:
      pem: |
          -----BEGIN CERTIFICATE-----
          MIICGzCCAcGgAwIBAgIUMLjRu7uVatvrmN1BQ9Seprx5ooUwCgYIKoZIzj0EAwIw
          ajELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMQ8wDQYDVQQH
          EwZEdXJoYW0xFjAUBgNVBAoTDW9yZzEuYWRiYy5jb20xGTAXBgNVBAMTEGNhLm9y
          ZzEuYWRiYy5jb20wHhcNMjExMDIyMTYxMDAwWhcNMzYxMDE4MTYxMDAwWjBqMQsw
          CQYDVQQGEwJVUzEXMBUGA1UECBMOTm9ydGggQ2Fyb2xpbmExDzANBgNVBAcTBkR1
          cmhhbTEWMBQGA1UEChMNb3JnMS5hZGJjLmNvbTEZMBcGA1UEAxMQY2Eub3JnMS5h
          ZGJjLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABC/S114fxHG5/bJobeHm
          mskHOl/I2BkSM+1yzH8XEXAXtSd27V57t1OJgDYHw9nSyoQWjQjIqXnakp9Cya4N
          ddKjRTBDMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMBAf8ECDAGAQH/AgEBMB0GA1Ud
          DgQWBBTsgWbGM94+Ux1Jn1sLIOjtP6S2HzAKBggqhkjOPQQDAgNIADBFAiEAyH1/
          PdzwEn1ZzLKt7/1J3kOnZC8NbI6saKS6DX/J+5sCIAy+TgDKqywS6KNLo5CupFqe
          qJ2oPzdO9edv5mXUwhju
          -----END CERTIFICATE-----
          
    grpcOptions:
      ssl-target-name-override: peer0.org1.adbc.com
      hostnameOverride: peer0.org1.adbc.com
  peer1.org1.adbc.com:
    url: grpcs://localhost:8051
    tlsCACerts:
      pem: |
        -----BEGIN CERTIFICATE-----
          MIICGzCCAcGgAwIBAgIUMLjRu7uVatvrmN1BQ9Seprx5ooUwCgYIKoZIzj0EAwIw
          ajELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMQ8wDQYDVQQH
          EwZEdXJoYW0xFjAUBgNVBAoTDW9yZzEuYWRiYy5jb20xGTAXBgNVBAMTEGNhLm9y
          ZzEuYWRiYy5jb20wHhcNMjExMDIyMTYxMDAwWhcNMzYxMDE4MTYxMDAwWjBqMQsw
          CQYDVQQGEwJVUzEXMBUGA1UECBMOTm9ydGggQ2Fyb2xpbmExDzANBgNVBAcTBkR1
          cmhhbTEWMBQGA1UEChMNb3JnMS5hZGJjLmNvbTEZMBcGA1UEAxMQY2Eub3JnMS5h
          ZGJjLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABC/S114fxHG5/bJobeHm
          mskHOl/I2BkSM+1yzH8XEXAXtSd27V57t1OJgDYHw9nSyoQWjQjIqXnakp9Cya4N
          ddKjRTBDMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMBAf8ECDAGAQH/AgEBMB0GA1Ud
          DgQWBBTsgWbGM94+Ux1Jn1sLIOjtP6S2HzAKBggqhkjOPQQDAgNIADBFAiEAyH1/
          PdzwEn1ZzLKt7/1J3kOnZC8NbI6saKS6DX/J+5sCIAy+TgDKqywS6KNLo5CupFqe
          qJ2oPzdO9edv5mXUwhju
          -----END CERTIFICATE-----
          
    grpcOptions:
      ssl-target-name-override: peer1.org1.adbc.com
      hostnameOverride: peer1.org1.adbc.com
certificateAuthorities:
  ca.org1.adbc.com:
    url: https://localhost:7054
    caName: ca-org1
    tlsCACerts:
      pem: 
        - |
          -----BEGIN CERTIFICATE-----
          MIICGzCCAcGgAwIBAgIUMLjRu7uVatvrmN1BQ9Seprx5ooUwCgYIKoZIzj0EAwIw
          ajELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMQ8wDQYDVQQH
          EwZEdXJoYW0xFjAUBgNVBAoTDW9yZzEuYWRiYy5jb20xGTAXBgNVBAMTEGNhLm9y
          ZzEuYWRiYy5jb20wHhcNMjExMDIyMTYxMDAwWhcNMzYxMDE4MTYxMDAwWjBqMQsw
          CQYDVQQGEwJVUzEXMBUGA1UECBMOTm9ydGggQ2Fyb2xpbmExDzANBgNVBAcTBkR1
          cmhhbTEWMBQGA1UEChMNb3JnMS5hZGJjLmNvbTEZMBcGA1UEAxMQY2Eub3JnMS5h
          ZGJjLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABC/S114fxHG5/bJobeHm
          mskHOl/I2BkSM+1yzH8XEXAXtSd27V57t1OJgDYHw9nSyoQWjQjIqXnakp9Cya4N
          ddKjRTBDMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMBAf8ECDAGAQH/AgEBMB0GA1Ud
          DgQWBBTsgWbGM94+Ux1Jn1sLIOjtP6S2HzAKBggqhkjOPQQDAgNIADBFAiEAyH1/
          PdzwEn1ZzLKt7/1J3kOnZC8NbI6saKS6DX/J+5sCIAy+TgDKqywS6KNLo5CupFqe
          qJ2oPzdO9edv5mXUwhju
          -----END CERTIFICATE-----
          
    httpOptions:
      verify: false

这是我的代码:

os.Setenv("DISCOVERY_AS_LOCALHOST", "true")
wallet, err := gateway.NewFileSystemWallet("wallet")
if err != nil {
    fmt.Printf("Failed to create wallet: %s\n", err)
    os.Exit(1)
}

if !wallet.Exists("appUser") {
    err = populateWallet(wallet)
    if err != nil {
        fmt.Printf("Failed to populate wallet contents: %s\n", err)
        os.Exit(1)
    }
}

ccpPath := filepath.Join(
    "..",
    "organizations",
    "peerOrganizations",
    "org1.adbc.com",
    "connection-org1.yaml",
)
gw, err := gateway.Connect(
    gateway.WithConfig(config.FromFile(filepath.Clean(ccpPath))),
    gateway.WithIdentity(wallet, "appUser"),
)

模块是

"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
"github.com/hyperledger/fabric-sdk-go/pkg/gateway"

如何像示例一样使用 fabric-sdk-go 连接我的网络?

4

0 回答 0