首页 > 解决方案 > Hyperledger Composer Couchdb not replicating on all peers

问题描述

I have hyperledger composer network setup as follows:

All Peers are subscribed to a common channel (composerchannel). I create a sample application (tutorial-network) provided in tutorial section of the main web site and installed it on the network.

When I browse couchdb1 I can see a database named "composerchannel_tutorial-network" for my imported application. I added couple of participants through REST interface and they appears in couchdb1 too.

The problem is when I look at the couchdb2 and couchdb3 instance I don't see database "composerchannel_tutorial-network" on them. I believe since all these peers are subscribed to a single channel it should replicate this database on all peers automatically.

I see following error in my Peer2 docker logs

unable to get chaincode data from ledger for tx due to lscc's state for [tutorial-network] not found

I see following error in my Peer3 docker logs (external system)

error getting chaincode tutorial-network on channel: composerchannel (err: could not find chaincode with name 'tutorial-network')

Peer1 container log can be seen at https://www.dropbox.com/s/8ylqssm0bxz3x51/peer1.log?dl=0

I think "composer network install" and "composer network start" should handle all peers on the network subscribed to a channel.

I have updated ./startFabric.sh so that Peer1 join the channel "composerchannel". None of the command below shows any error.

Here are the steps I follow:

./startFabric.sh
./createPeerAdminCard.sh

composer network install --card PeerAdmin@hlfv1 --archiveFile tutorial-network@0.0.1.bna

composer network start --networkName tutorial-network --networkVersion 0.0.1 --networkAdmin admin --networkAdminEnrollSecret adminpw --card PeerAdmin@hlfv1 --file networkadmin.card

composer card import --file networkadmin.card

composer network ping --card admin@tutorial-network

composer-rest-server

Can someone please advise what could be wrong?

标签: hyperledger-fabrichyperledger-composer

解决方案


链码需要安装在所有背书节点上。Composer 网络安装将在您组织中的所有背书节点上安装链代码,并且是连接配置文件定义的通道的一部分。因此,如果您有多个组织,那么您需要为每个组织执行安装。我还将检查已为每个对等方建立了与正确 couchdb 通信的对等日志,并检查当您将每个对等方加入频道时是否收到成功消息。

这是我的 docker-compose 文件,用于同一组织中的 2 个对等点,它们有自己的 couchdb 实例。我可以看到两个 couchdb 实例都在从它们的日志中创建和使用数据


version: '2'

services:
  ca.org1.example.com:
    image: hyperledger/fabric-ca:$ARCH-1.1.0
    environment:
      - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
      - FABRIC_CA_SERVER_CA_NAME=ca.org1.example.com

    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/19ab65abbb04807dad12e4c0a9aaa6649e70868e3abd0217a322d89e47e1a6ae_sk -b admin:adminpw -d'
    volumes:
      - ./crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
    container_name: ca.org1.example.com

  orderer.example.com:
    container_name: orderer.example.com
    image: hyperledger/fabric-orderer:$ARCH-1.1.0
    environment:
      - ORDERER_GENERAL_LOGLEVEL=debug
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/etc/hyperledger/configtx/composer-genesis.block
      - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
      - ORDERER_GENERAL_LOCALMSPDIR=/etc/hyperledger/msp/orderer/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: orderer
    ports:
      - 7050:7050
    volumes:
        - ./:/etc/hyperledger/configtx
        - ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/etc/hyperledger/msp/orderer/msp

  peer0.org1.example.com:
    container_name: peer0.org1.example.com
    image: hyperledger/fabric-peer:$ARCH-1.1.0
    environment:
      - CORE_LOGGING_LEVEL=debug
      - CORE_CHAINCODE_LOGGING_LEVEL=DEBUG
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_PEER_ID=peer0.org1.example.com
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=composer_default
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/msp
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: peer node start
    ports:
      - 7051:7051
      - 7053:7053
    volumes:
        - /var/run/:/host/var/run/
        - ./:/etc/hyperledger/configtx
        - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/peer/msp
        - ./crypto-config/peerOrganizations/org1.example.com/users:/etc/hyperledger/msp/users
    depends_on:
      - orderer.example.com
      - couchdb

  couchdb:
    container_name: couchdb
    image: hyperledger/fabric-couchdb:$ARCH-0.4.6
    ports:
      - 5984:5984
    environment:
      DB_URL: http://localhost:5984/member_db

  peer1.org1.example.com:
    container_name: peer1.org1.example.com
    image: hyperledger/fabric-peer:$ARCH-1.1.0
    environment:
      - CORE_LOGGING_LEVEL=debug
      - CORE_CHAINCODE_LOGGING_LEVEL=DEBUG
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_PEER_ID=peer1.org1.example.com
      - CORE_PEER_ADDRESS=peer1.org1.example.com:7051
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=composer_default
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/msp
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb2:5984
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: peer node start
    ports:
      - 8051:7051
      - 8053:7053
    volumes:
        - /var/run/:/host/var/run/
        - ./:/etc/hyperledger/configtx
        - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/peer/msp
        - ./crypto-config/peerOrganizations/org1.example.com/users:/etc/hyperledger/msp/users
    depends_on:
      - orderer.example.com
      - couchdb2

  couchdb2:
    container_name: couchdb2
    image: hyperledger/fabric-couchdb:$ARCH-0.4.6
    ports:
      - 6984:5984
    environment:
      DB_URL: http://localhost:5984/member_db

startFabric.sh


#!/bin/bash

# Exit on first error, print all commands.
set -e

Usage() {
    echo ""
    echo "Usage: ./startFabric.sh [-d || --dev]"
    echo ""
    echo "Options:"
    echo -e "\t-d or --dev: (Optional) enable fabric development mode"
    echo ""
    echo "Example: ./startFabric.sh"
    echo ""
    exit 1
}

Parse_Arguments() {
    while [ $# -gt 0 ]; do
        case $1 in
            --help)
                HELPINFO=true
                ;;
            --dev | -d)
                FABRIC_DEV_MODE=true
                ;;
        esac
        shift
    done
}

Parse_Arguments $@

if [ "${HELPINFO}" == "true" ]; then
    Usage
fi

#Detect architecture
ARCH=`uname -m`

# Grab the current directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if [ "${FABRIC_DEV_MODE}" == "true" ]; then
    DOCKER_FILE="${DIR}"/composer/docker-compose-dev.yml
else
    DOCKER_FILE="${DIR}"/composer/docker-compose.yml
fi

ARCH=$ARCH docker-compose -f "${DOCKER_FILE}" down
ARCH=$ARCH docker-compose -f "${DOCKER_FILE}" up -d

# wait for Hyperledger Fabric to start
# incase of errors when running later commands, issue export FABRIC_START_TIMEOUT=
echo "sleeping for ${FABRIC_START_TIMEOUT} seconds to wait for fabric to complete start up"
sleep ${FABRIC_START_TIMEOUT}

# Create the channel
docker exec peer0.org1.example.com peer channel create -o orderer.example.com:7050 -c composerchannel -f /etc/hyperledger/configtx/composer-channel.tx

# Join peer0.org1.example.com to the channel.
docker exec -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer0.org1.example.com peer channel join -b composerchannel.block

echo fetching block
docker exec -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer1.org1.example.com peer channel fetch config -o orderer.example.com:7050 -c composerchannel composerchannel.block

echo joining peer1
# Join peer1.org1.example.com to the channel.
docker exec -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer1.org1.example.com peer channel join -b composerchannel.block

if [ "${FABRIC_DEV_MODE}" == "true" ]; then
    echo "Fabric Network started in chaincode development mode"
fi

推荐阅读