Flair
Flair

Reputation: 93

Creating organisation with 2 peers

I am trying to extend this code to add 1 more endorsing peer in the organization org1. I updated /basic-network/crypto-config.yaml as follows:

PeerOrgs:
- Name: Org1
Domain: org1.example.com
Template:
  Count: 2
Users:
  Count: 1

Then I regenerated all the crypto material by running generate.sh again. I updated the FABRIC_CA_SERVER_CA_KEYFILE in the basic-network/docker-compose.yaml file. I added peer1.org1.example.com in docker-compose.yaml:

peer1.org1.example.com:
    container_name: peer1.org1.example.com
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_PEER_ID=peer1.org1.example.com
      - CORE_LOGGING_PEER=debug
      - CORE_CHAINCODE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
      - CORE_PEER_ADDRESS=peer1.org1.example.com:7056
      # # the following setting starts chaincode containers on the same
      # # bridge network as the peers
      # # https://docs.docker.com/compose/networking/
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_basic
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
      # The CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME and CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD
      # provide the credentials for ledger to connect to CouchDB.  The username and password must
      # match the username and password set for the associated CouchDB.
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: peer node start
    # command: peer node start --peer-chaincodedev=true
    ports:
      - 7056:7056
      - 7058:7058
    volumes:
        - /var/run/:/host/var/run/
        - ./crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/msp:/etc/hyperledger/msp/peer
        - ./crypto-config/peerOrganizations/org1.example.com/users:/etc/hyperledger/msp/users
        - ./config:/etc/hyperledger/configtx
    depends_on:
      - orderer.example.com
      - couchdb
      - peer0.org1.example.com
    networks:
      - basic

I ran the following commands then:

set -ev
export MSYS_NO_PATHCONV=1
docker-compose -f docker-compose.yml down
docker-compose -f docker-compose.yml up -d ca.example.com orderer.example.com peer0.org1.example.com peer1.org1.example.com couchdb

All the containers are up and running without any error.

CONTAINER ID        IMAGE                                                                                                      COMMAND                  CREATED             STATUS              PORTS                                            NAMES
3393fc796417        dev-peer0.org1.example.com-tuna-app-1.0-b58eb592ed6ced10f52cc063bda0c303a4272089a3f9a99000d921f94b9bae9b   "chaincode -peer.add…"   2 minutes ago       Up 2 minutes                                                         dev-peer0.org1.example.com-tuna-app-1.0
a45d7e943068        hyperledger/fabric-tools                                                                                   "/bin/bash"              2 minutes ago       Up 2 minutes                                                         cli
d3698fc6d3d3        hyperledger/fabric-peer                                                                                    "peer node start"        2 minutes ago       Up 2 minutes        0.0.0.0:7056->7056/tcp, 0.0.0.0:7058->7058/tcp   peer1.org1.example.com
b7c92a70fc89        hyperledger/fabric-peer                                                                                    "peer node start"        2 minutes ago       Up 2 minutes        0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp   peer0.org1.example.com
21fabe33e3e5        hyperledger/fabric-ca                                                                                      "sh -c 'fabric-ca-se…"   2 minutes ago       Up 2 minutes        0.0.0.0:7054->7054/tcp                           ca.example.com
ddaf8390c0ee        hyperledger/fabric-couchdb                                                                                 "tini -- /docker-ent…"   2 minutes ago       Up 2 minutes        4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp       couchdb
38bdb92c6de0        hyperledger/fabric-orderer                                                                                 "orderer"                2 minutes ago       Up 2 minutes        0.0.0.0:7050->7050/tcp                           orderer.example.com

Next, I need to create channel with two peers. How do I modify the below commands to add peer1 to org1?

# Create the channel
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/[email protected]/msp" peer0.org1.example.com peer channel create -o orderer.example.com:7050 -c mychannel -f /etc/hyperledger/configtx/channel.tx
# Join peer0.org1.example.com to the channel.
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/[email protected]/msp" peer0.org1.example.com peer channel join -b mychannel.block

Above two commands run successfully, but when I try to run following

docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/[email protected]/msp" peer1.org1.example.com peer channel join -b mychannel.block

I get following error:

Error: Error getting endorser client channel: endorser client failed to connect to peer1.org1.example.com:7056: failed to create new connection: context deadline exceeded

Upvotes: 0

Views: 560

Answers (1)

Yann39
Yann39

Reputation: 15699

Keep using 7051 and 7053 as internal ports for your peers, only the exposed ports must be changed :

ports:
      - 7056:7051
      - 7058:7053

I can't find any official documentation on this but it seems that by default it always use the address of the anchor peer of the organization. Ports used for handling incoming request for peers in an organization should be the same as the anchor peer port of that organization.

From the core.yaml config file.

# The Address at local network interface this Peer will listen on.
# By default, it will listen on all network interfaces
listenAddress: 0.0.0.0:7051

[...]

# When used as peer config, this represents the endpoint to other peers
# in the same organization. For peers in other organization, see
# gossip.externalEndpoint for more info.
# When used as CLI config, this means the peer's endpoint to interact with
address: 0.0.0.0:7051

[...]

gossip:
      # Bootstrap set to initialize gossip with.
      # This is a list of other peers that this peer reaches out to at startup.
      # Important: The endpoints here have to be endpoints of peers in the same
      # organization, because the peer would refuse connecting to these endpoints
      # unless they are in the same organization as the peer.
      bootstrap: 127.0.0.1:7051

If you really want to use another internal port (like 7056), try defining CORE_PEER_LISTENADDRESS in your docker-compose file for your new peer (defines the GRPC server's listen port) :

CORE_PEER_LISTENADDRESS=0.0.0.0:7056

Also I suggest you not to use the same CouchDb as ledger database for all your peers. Use a couchDB per peer (and it is recommended to set a username/password).

EDIT : As you don't run the peer channel join commands from your cli container, I think you have to fetch the channel through the orderer on your new peer to be able to join it (this will return the most recent configuration block for the targeted channel) :

docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/[email protected]/msp" peer1.org1.example.com peer channel fetch config -o orderer.example.com:7050 -c mychannel

Then you should be able to join your peer to the channel using the new created block (<channelID>_config.block).

Upvotes: 1

Related Questions