对多台计算机执行对等链代码查询时,无法获取mycc:1.0的链代码容器信息

时间:2019-04-05 15:19:47

标签: docker hyperledger-fabric hyperledger blockchain chaincode

我正在尝试在2个不同的物理机上运行2个组织来建立一个超级账本网络。因此,机器1具有订购者,peer0.org1,peer1.org1,ca-org1,couchdb1,couchdb2和cli容器。机器2具有peer0.org2,peer1.org2,ca-org2,couchdb3,couchdb4和cli容器。

下面是docker-compose-org1.yaml文件-

version: '2'

volumes:
  orderer.example.com:
  peer0.org1.example.com:
  peer1.org1.example.com:

networks:
  byfn:

services:
  ca0.example.com:
    image: hyperledger/fabric-ca:$IMAGE_TAG
    environment:
      - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
      - FABRIC_CA_SERVER_CA_NAME=ca-org1
      - FABRIC_CA_SERVER_TLS_ENABLED=true
      - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem
      - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/65cc7012f64e12926807f9b731d3f4dbbda27dc577cb5a6afdb3730fcf53c48c_sk
    ports:
      - '7054:7054'
    command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/65cc7012f64e12926807f9b731d3f4dbbda27dc577cb5a6afdb3730fcf53c48c_sk -b admin:adminpw -d'
    volumes:
      - ./crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
    container_name: ca0.example.com
    extra_hosts:
      - "peer0.org2.example.com:10.160.151.114"
      - "peer1.org2.example.com:10.160.151.114"      
      - "ca1.example.com:10.160.151.114"
    networks:
      - byfn


  orderer.example.com:
    container_name: orderer.example.com
    image: hyperledger/fabric-orderer:$IMAGE_TAG
    environment:
      - ORDERER_GENERAL_LOGLEVEL=INFO
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
      - 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]
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: orderer
    volumes:
      - ./channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
      - ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp
      - ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls
      - orderer.example.com:/var/hyperledger/production/orderer
    extra_hosts:
      - "peer0.org2.example.com:10.160.151.114"
      - "peer1.org2.example.com:10.160.151.114"
      - "ca1.example.com:10.160.151.114"
    ports:
      - 7050:7050
    networks:
      - byfn

  peer0.org1.example.com:
    container_name: peer0.org1.example.com
    image: hyperledger/fabric-peer:$IMAGE_TAG
    environment:
      - CORE_PEER_ID=peer0.org1.example.com
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org1.example.com:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_byfn
      - CORE_LOGGING_LEVEL=INFO
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_PROFILE_ENABLED=true
      - 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
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb0:5984
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
    volumes:
      - /var/run/:/host/var/run/
      - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp
      - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls
      - peer0.org1.example.com:/var/hyperledger/production
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    extra_hosts:
      - "peer0.org2.example.com:10.160.151.114"
      - "peer1.org2.example.com:10.160.151.114"
      - "ca1.example.com:10.160.151.114"
    command: peer node start
    ports:
      - 7051:7051
      - 7053:7053
    depends_on:
      - couchdb0
    networks:
      - byfn

  couchdb0:
    container_name: couchdb0
    image: hyperledger/fabric-couchdb
    environment:
      - COUCHDB_USER=
      - COUCHDB_PASSWORD=
    ports:
      - '5984:5984'
    networks:
      - byfn

  peer1.org1.example.com:
    container_name: peer1.org1.example.com
    image: hyperledger/fabric-peer:$IMAGE_TAG
    environment:
      - CORE_PEER_ID=peer1.org1.example.com
      - CORE_PEER_ADDRESS=peer1.org1.example.com:7051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_byfn
      - CORE_LOGGING_LEVEL=INFO
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_PROFILE_ENABLED=true
      - 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
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb1:5984
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
    volumes:
      - /var/run/:/host/var/run/
      - ./crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/msp:/etc/hyperledger/fabric/msp
      - ./crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls:/etc/hyperledger/fabric/tls
      - peer1.org1.example.com:/var/hyperledger/production
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    extra_hosts:
      - "peer0.org2.example.com:10.160.151.114"
      - "peer1.org2.example.com:10.160.151.114"
      - "ca1.example.com:10.160.151.114"
    command: peer node start
    ports:
      - 8051:7051
      - 8053:7053
    depends_on:
      - couchdb1
    networks:
      - byfn

  couchdb1:
    container_name: couchdb1
    image: hyperledger/fabric-couchdb
    environment:
      - COUCHDB_USER=
      - COUCHDB_PASSWORD=
    ports:
      - '6984:5984'
    networks:
      - byfn


  cli:
    container_name: cli
    image: hyperledger/fabric-tools:$IMAGE_TAG
    tty: true
    stdin_open: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      #- CORE_LOGGING_LEVEL=DEBUG
      - CORE_LOGGING_LEVEL=INFO
      - CORE_PEER_ID=cli
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer

    extra_hosts:
      - "peer0.org2.example.com:10.160.151.114"
      - "peer1.org2.example.com:10.160.151.114"
      - "ca1.example.com:10.160.151.114"

    command: /bin/bash
    volumes:
      - /var/run/:/host/var/run/
      - ./../chaincode/:/opt/gopath/src/github.com/chaincode
      - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
      - ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
      - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    depends_on:
      - orderer.example.com
      - peer0.org1.example.com
      - peer1.org1.example.com
    networks:
      - byfn

docker-compose-org2.yaml文件-

version: '2'

volumes:
  peer0.org2.example.com:
  peer1.org2.example.com:

networks:
  byfn:

services:
  ca1.example.com:
    image: hyperledger/fabric-ca
    environment:
      - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
      - FABRIC_CA_SERVER_CA_NAME=ca-org2
      - FABRIC_CA_SERVER_TLS_ENABLED=true
      - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org2.example.com-cert.pem
      - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/16acd23be9bbaf215828ddb410074828ce2b87ab68dff5976725b36f439f8c47_sk
    ports:
      - '7054:7054'
    command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/ca.org2.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/16acd23be9bbaf215828ddb410074828ce2b87ab68dff5976725b36f439f8c47_sk -b admin:adminpw -d'
    volumes:
      - ./crypto-config/peerOrganizations/org2.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
    container_name: ca0.example.com
    extra_hosts:
      - 'peer0.org1.example.com:10.160.151.121'
      - 'peer1.org1.example.com:10.160.151.121'
      - 'ca0.example.com:10.160.151.121'
      - 'orderer.example.com:10.160.151.121'
    networks:
      - byfn

  peer0.org2.example.com:
    container_name: peer0.org2.example.com
    image: hyperledger/fabric-peer:latest
    environment:
      - CORE_PEER_ID=peer0.org2.example.com
      - CORE_PEER_ADDRESS=peer0.org2.example.com:7051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org2.example.com:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:7051
      - CORE_PEER_LOCALMSPID=Org2MSP
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_byfn
      - CORE_LOGGING_LEVEL=INFO
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_PROFILE_ENABLED=true
      - 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
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb2:5984
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
    volumes:
      - /var/run/:/host/var/run/
      - ./crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp
      - ./crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls
      - peer0.org2.example.com:/var/hyperledger/production

    extra_hosts:
      - 'peer0.org1.example.com:10.160.151.121'
      - 'peer1.org1.example.com:10.160.151.121'
      - 'ca0.example.com:10.160.151.121'
      - 'orderer.example.com:10.160.151.121'

    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 9051:7051
      - 9053:7053
    depends_on:
      - couchdb2
    networks:
      - byfn

  couchdb2:
    container_name: couchdb2
    image: hyperledger/fabric-couchdb
    environment:
      - COUCHDB_USER=
      - COUCHDB_PASSWORD=
    ports:
      - '7984:5984'
    networks:
      - byfn

  peer1.org2.example.com:
    container_name: peer1.org2.example.com
    image: hyperledger/fabric-peer:latest
    environment:
      - CORE_PEER_ID=peer1.org2.example.com
      - CORE_PEER_ADDRESS=peer1.org2.example.com:7051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org2.example.com:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org2.example.com:7051
      - CORE_PEER_LOCALMSPID=Org2MSP
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_byfn
      - CORE_LOGGING_LEVEL=INFO
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_PROFILE_ENABLED=true
      - 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
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb3:5984
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
    volumes:
      - /var/run/:/host/var/run/
      - ./crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/msp:/etc/hyperledger/fabric/msp
      - ./crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls:/etc/hyperledger/fabric/tls
      - peer1.org2.example.com:/var/hyperledger/production

    extra_hosts:
      - 'peer0.org1.example.com:10.160.151.121'
      - 'peer1.org1.example.com:10.160.151.121'
      - 'ca0.example.com:10.160.151.121'
      - 'orderer.example.com:10.160.151.121'

    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 10051:7051
      - 10053:7053
    depends_on:
      - couchdb3
    networks:
      - byfn

  couchdb3:
    container_name: couchdb3
    image: hyperledger/fabric-couchdb
    environment:
      - COUCHDB_USER=
      - COUCHDB_PASSWORD=
    ports:
      - '8984:5984'
    networks:
      - byfn

  cli:
    container_name: cli
    image: hyperledger/fabric-tools:latest
    tty: true
    stdin_open: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      #- CORE_LOGGING_LEVEL=DEBUG
      - CORE_LOGGING_LEVEL=INFO
      - CORE_PEER_ID=cli
      - CORE_PEER_ADDRESS=peer0.org2.example.com:7051
      - CORE_PEER_LOCALMSPID=Org2MSP
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer

    extra_hosts:
      - 'peer0.org1.example.com:10.160.151.121'
      - 'peer1.org1.example.com:10.160.151.121'
      - 'ca0.example.com:10.160.151.121'
      - 'orderer.example.com:10.160.151.121'

    command: /bin/bash
    volumes:
      - /var/run/:/host/var/run/
      - ./chaincode/:/opt/gopath/src/github.com/chaincode
      - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
      - ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
      - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    depends_on:
      - peer0.org2.example.com
      - peer1.org2.example.com
    networks:
      - byfn

如您所见,我正在使用“ extra_hosts”连接到另一台机器上的docker容器。 这样,我可以在一台计算机上创建频道,并从该计算机为两个对等方加入该频道。在另一台机器上,我为两个对等端获取了相同的通道配置并加入了相同的通道。 我通过以下命令-

检查了两台计算机上的所有4个对等端是否都已加入同一通道
peer channel list
peer channel getinfo -c mychannel

现在从机器1开始,我已经安装并实例化了chaincode。一切正常。在以下命令中用于安装和实例化-

peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/

peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"

如果我从同一台计算机查询链码,则它工作正常,并且得到了正确的结果。

peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'

但是当我从另一台机器执行同一链码查询命令时,它给出了以下错误-

  

错误:查询期间背书失败。响应:状态:500消息:“未能执行事务2444b829db1485ad097b2e11442d65cb36f02de1c6a3f3372ad53594af4d1a4d:[channel mychannel]无法获取mycc的链码容器信息:1.0:无法获取链码:链码指纹不匹配:数据不匹配”

我可以看到超级账本结构正在两台机器上正确同步所有对等端。因为当我运行peer channel getinfo -c mychannel时,我可以匹配所有4个对等方的currentBlockHash,previousBlockHash和height值。我只是无法从另一台计算机上执行peer chaincode query命令。

当我运行peer chaincode instantiate命令时,我可以看到在机器1中创建了一个新的docker容器,用于运行链码。但是机器2中没有这样的容器。 我是否在这里缺少任何配置,以便可以从机器2访问在机器1上创建的链码容器?


新发现: 通过从CLI容器运行peer chaincode install命令,我已经在两台机器上的所有4个对等节点上安装了chaincode。我有两个计算机上运行的两个CLI容器。

当我运行命令peer chaincode list --installed时。在机器1中,我得到如下结果

  

名称:mycc,版本:1.0,路径:github.com/chaincode/chaincode_example02/go/,ID:333a19b11063d0ade7be691f9f22c04ad369baba15660f7ae9511fd1a6488209

当我在机器2中运行相同的命令时,结果相同,除了Id值不同。但是我还发现Id的值对于同一台计算机上的两个对等方都是相同的。也许这就是为什么我能够在同一台计算机上从两个对等节点执行链码查询的原因。但是无法从其他计算机上运行它。看起来这是此问题的根本原因。

3 个答案:

答案 0 :(得分:1)

我最终能够找出问题所在,因此在此处发布答案。问题是,当我从两台不同的计算机上安装了链码时,链码Id是不同的。以前,我使用命令peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/在两台计算机上分别安装链码。因此,当我执行peer chaincode list --installed时,它显示的Id值是不同的。

我能够使用稍微不同的方法来解决它。首先使用命令peer chaincode package ccpack.out -n mycc -l golang -p github.com/chaincode/chaincode_example02/go/ -v 1.0创建链码包。它将生成文件ccpack.out。将此文件从一台计算机物理移动到另一台计算机。然后使用命令peer chaincode install ccpack.out在两台计算机上安装相同的软件包文件。这样,链码Id保持不变,并且可以正常工作。

答案 1 :(得分:0)

您是否也在其他对等方上安装了ChainCode?

  

当我运行对等的chaincode实例化命令时,我可以看到在机器1中创建了一个新的docker容器,用于运行chaincode。但是机器2中没有这样的容器。我是否在这里缺少任何配置,以便可以从机器2访问在机器1上创建的链码容器?

这是预期的。摘自文档:“ 对等对象的链代码容器只有在对该链代码执行初始化或传统事务(读/写)之前,才为同伴启动

因此,只需将其标识为其他对等方,以与第一个对等方相同的方式安装链码,然后可以与该对等方进行调用(查询或调用无关紧要),然后您会看到chaincode-container上。

答案 2 :(得分:0)

我遇到了同样的错误。对我来说,chaincode文件是不同的。将整个chaincode文件夹复制到同一位置的另一台机器对我来说很有效。 看看这个: https://stackoverflow.com/a/57628211/3750798