I am trying to connect multi host with hyperledger fabric 1.2.
I used docker swarm with virtualbox.
I executed this code with PC1.
docker swarm init
docker swarm join-token manager
docker network create --attachable --driver overlay byfn
and executed code like this to make it join PC1.
docker swarm join — token SWMTKN-1–3as8cvf3yxk8e7zj98954jhjza3w75mngmxh543llgpo0c8k7z-61zyibtaqjjimkqj8p6t9lwgu 172.16.0.153:2377
and executed each PC1 command in a separate terminal on PC1.
and executed each PC2 command in a separate terminal on PC2.
but, when I execute cli command, error occurred.
2018-08-07 01:53:32.659 UTC [grpc] Printf -> DEBU 040 grpc: addrConn.createTransport failed to connect to {0.0.0.0:7050 0 <nil>}. Err :connection error: desc = "transport: Error while dialing dial tcp 0.0.0.0:7050: connect: connection refused". Reconnecting...
2018-08-07 01:53:32.659 UTC [grpc] Printf -> DEBU 041 pickfirstBalancer: HandleSubConnStateChange: 0xc420460ad0, TRANSIENT_FAILURE
2018-08-07 01:53:34.326 UTC [grpc] Printf -> DEBU 042 pickfirstBalancer: HandleSubConnStateChange: 0xc420460ad0, CONNECTING
2018-08-07 01:53:34.328 UTC [grpc] Printf -> DEBU 043 grpc: addrConn.createTransport failed to connect to {0.0.0.0:7050 0 <nil>}. Err :connection error: desc = "transport: Error while dialing dial tcp 0.0.0.0:7050: connect: connection refused". Reconnecting...
2018-08-07 01:53:34.328 UTC [grpc] Printf -> DEBU 044 pickfirstBalancer: HandleSubConnStateChange: 0xc420460ad0, TRANSIENT_FAILURE
Error: failed to create deliver client: orderer client failed to connect to orderer.example.com:7050: failed to create new connection: context deadline exceeded
!!!!!!!!!!!!!!! Channel creation failed !!!!!!!!!!!!!!!!
========= ERROR !!! FAILED to execute End-2-End Scenario ===========
orderer error logs
2018-08-07 06:29:04.357 UTC [grpc] Println -> DEBU 0c6 grpc: Server.Serve failed to create ServerTransport: connection error: desc = "transport: http2Server.HandleStreams received bogus greeting from client: \"\\x16\\x03\\x01\\x00\\xb2\\x01\\x00\\x00\\xae\\x03\\x03\\x04w\\xffLbc0\\x94\\xec\\x8cV\\xdfa\""
2018-08-07 06:29:05.340 UTC [grpc] Println -> DEBU 0c7 grpc: Server.Serve failed to create ServerTransport: connection error: desc = "transport: http2Server.HandleStreams received bogus greeting from client: \"\\x16\\x03\\x01\\x00\\xb2\\x01\\x00\\x00\\xae\\x03\\x03\\xb6\\x8cU-\\xfa\\xd8&\\x8fp\\x16(:\\xa4\""
2018-08-07 06:29:07.053 UTC [grpc] Println -> DEBU 0c8 grpc: Server.Serve failed to create ServerTransport: connection error: desc = "transport: http2Server.HandleStreams received bogus greeting from client: \"\\x16\\x03\\x01\\x00\\xb2\\x01\\x00\\x00\\xae\\x03\\x03\\xfe\\xcf\\xd1\\xea,7we\\xa3\\x10Γ\\x06\""
I refer to this site.
https://medium.com/#wahabjawed/hyperledger-fabric-on-multiple-hosts-a33b08ef24f
Network Topology
PC1
CA0
CA1
ORDERER
PEER0(ORG1)
PC2
PEER0(ORG2)
CLI
PC1
CA0
docker run --rm -it --network="byfn" --name ca_peerOrg1 \
-p 7054:7054 \
-e CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=byfn \
-e FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server \
-e FABRIC_CA_SERVER_CA_NAME=ca-org1 \
-e FABRIC_CA_SERVER_TLS_ENABLED=true \
-e FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem \
-e FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/e723fd0eac7f338381b2bb7f74b417ae42ed28b3c47faaa119837f2405c337da_sk \
-v $PWD/crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config \
hyperledger/fabric-ca \
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/e723fd0eac7f338381b2bb7f74b417ae42ed28b3c47faaa119837f2405c337da_sk -b admin:adminpw -d'
CA1
docker run --rm -it --network="byfn" --name ca_peerOrg2
-p 8054:7054
-e CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=byfn
-e FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
-e FABRIC_CA_SERVER_CA_NAME=ca-org2
-e FABRIC_CA_SERVER_TLS_ENABLED=true
-e FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org2.example.com-cert.pem
-e FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/3d8b514fa72a496e6715413d4c2dec90c335c827c7049a8de0aa712435ce1f7f_sk
-v $PWD/crypto-config/peerOrganizations/org2.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
hyperledger/fabric-ca
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/3d8b514fa72a496e6715413d4c2dec90c335c827c7049a8de0aa712435ce1f7f_sk -b admin:adminpw -d'
orderer
docker run --rm -it --network="byfn" --name orderer.example.com \
-p 7050:7050 \
-e CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=byfn \
-e ORDERER_GENERAL_LOGLEVEL=DEBUG \
-e ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 \
-e ORDERER_GENERAL_LISTENPORT=7050 \
-e ORDERER_GENERAL_GENESISMETHOD=file \
-e ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block \
-e ORDERER_GENERAL_LOCALMSPID=OrdererMSP \
-e ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp \
-e ORDERER_GENERAL_TLS_ENABLED=false \
-e ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key \
-e ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt \
-e ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] \
-v $PWD/channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block \
-v $PWD/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/:/var/hyperledger/orderer/msp \
-v $PWD/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls \
-v orderer.example.com:/var/hyperledger/production/orderer \
-w /opt/gopath/src/github.com/hyperledger/fabric \
hyperledger/fabric-orderer \
orderer
peer0
docker run --rm -it --network="byfn" --name peer0.org1.example.com \
--link orderer.example.com:orderer.example.com \
-p 7051:7051 \
-p 7053:7053 \
-e CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=byfn \
-e CORE_PEER_ID=peer0.org1.example.com \
-e CORE_PEER_ADDRESS=peer0.org1.example.com:7051 \
-e CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051 \
-e CORE_PEER_LOCALMSPID=Org1MSP \
-e CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock \
-e CORE_LOGGING_LEVEL=DEBUG \
-e CORE_PEER_TLS_ENABLED=true \
-e CORE_PEER_GOSSIP_USELEADERELECTION=true \
-e CORE_PEER_GOSSIP_ORGLEADER=false \
-e CORE_PEER_PROFILE_ENABLED=true \
-e CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt \
-e CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key \
-e CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt \
-v /var/run/:/host/var/run/ \
-v $PWD/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp \
-v $PWD/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls \
-v peer0.org1.example.com:/var/hyperledger/production \
-w /opt/gopath/src/github.com/hyperledger/fabric/peer \
hyperledger/fabric-peer \
peer node start
PC2
peer0
docker run --rm -it --network="byfn" --name peer0.org2.example.com \
--link orderer.example.com:orderer.example.com \
-p 9051:7051 \
-p 9053:7053 \
-e CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=byfn \
-e CORE_PEER_ID=peer0.org2.example.com \
-e CORE_PEER_ADDRESS=peer0.org2.example.com:7051 \
-e CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:7051 \
-e CORE_PEER_LOCALMSPID=Org2MSP \
-e CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock \
-e CORE_LOGGING_LEVEL=DEBUG \
-e CORE_PEER_TLS_ENABLED=true \
-e CORE_PEER_GOSSIP_USELEADERELECTION=true \
-e CORE_PEER_GOSSIP_ORGLEADER=false \
-e CORE_PEER_PROFILE_ENABLED=true \
-e CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt \
-e CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key \
-e CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt \
-v /var/run/:/host/var/run/ \
-v $PWD/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp \
-v $PWD/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls \
-v peer0.org2.example.com:/var/hyperledger/production \
-w /opt/gopath/src/github.com/hyperledger/fabric/peer \
hyperledger/fabric-peer \
peer node start
cli
docker run --rm -it --network="byfn" --name cli \
--link orderer.example.com:orderer.example.com \
--link peer0.org1.example.com:peer0.org1.example.com \
--link peer0.org2.example.com:peer0.org2.example.com \
-p 12051:7051 \
-p 12053:7053 \
-e CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=byfn \
-e GOPATH=/opt/gopath \
-e CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock \
-e CORE_LOGGING_LEVEL=DEBUG \
-e CORE_PEER_ID=cli \
-e CORE_PEER_ADDRESS=peer0.org1.example.com:7051 \
-e CORE_PEER_LOCALMSPID=Org1MSP \
-e CORE_PEER_TLS_ENABLED=true \
-e 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 \
-e 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 \
-e 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 \
-e CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp \
-v /var/run/:/host/var/run/ \
-v $PWD/crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ \
-v $PWD/scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/ \
-v $PWD/channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts \
-v $HOME/fabric-samples/chaincode/:/opt/gopath/src/github.com/chaincode \
-w /opt/gopath/src/github.com/hyperledger/fabric/peer \
hyperledger/fabric-tools \
/bin/bash \
-c './scripts/script.sh'
script.sh
#!/bin/bash
echo
echo " ____ _____ _ ____ _____ "
echo "/ ___| |_ _| / \ | _ \ |_ _|"
echo "\___ \ | | / _ \ | |_) | | | "
echo " ___) | | | / ___ \ | _ < | | "
echo "|____/ |_| /_/ \_\ |_| \_\ |_| "
echo
echo "Build your first network (BYFN) end-to-end test"
echo
CHANNEL_NAME="$1"
DELAY="$2"
LANGUAGE="$3"
TIMEOUT="$4"
VERBOSE="$5"
: ${CHANNEL_NAME:="mychannel"}
: ${DELAY:="3"}
: ${LANGUAGE:="golang"}
: ${TIMEOUT:="10"}
: ${VERBOSE:="false"}
LANGUAGE=`echo "$LANGUAGE" | tr [:upper:] [:lower:]`
COUNTER=1
MAX_RETRY=5
CC_SRC_PATH="github.com/chaincode/chaincode_example02/go/"
if [ "$LANGUAGE" = "node" ]; then
CC_SRC_PATH="/opt/gopath/src/github.com/chaincode/chaincode_example02/node/"
fi
echo "Channel name : "$CHANNEL_NAME
# import utils
. scripts/utils.sh
createChannel() {
setGlobals 0 1
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
set -x
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx >&log.txt
res=$?
set +x
else
set -x
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA >&log.txt
res=$?
set +x
fi
cat log.txt
verifyResult $res "Channel creation failed"
echo "===================== Channel '$CHANNEL_NAME' created ===================== "
echo
}
joinChannel () {
for org in 1 2; do
for peer in 0 1; do
joinChannelWithRetry $peer $org
echo "===================== peer${peer}.org${org} joined channel '$CHANNEL_NAME' ===================== "
sleep $DELAY
echo
done
done
}
## Create channel
echo "Creating channel..."
createChannel
## Join all the peers to the channel
echo "Having all peers join the channel..."
joinChannel
## Set the anchor peers for each org in the channel
echo "Updating anchor peers for org1..."
updateAnchorPeers 0 1
echo "Updating anchor peers for org2..."
updateAnchorPeers 0 2
## Install chaincode on peer0.org1 and peer0.org2
echo "Installing chaincode on peer0.org1..."
installChaincode 0 1
echo "Install chaincode on peer0.org2..."
installChaincode 0 2
# Instantiate chaincode on peer0.org2
#echo "Instantiating chaincode on peer0.org2..."
#instantiateChaincode 0 2
# Query chaincode on peer0.org1
#echo "Querying chaincode on peer0.org1..."
#chaincodeQuery 0 1 100
# Invoke chaincode on peer0.org1 and peer0.org2
#echo "Sending invoke transaction on peer0.org1 peer0.org2..."
#chaincodeInvoke 0 1 0 2
## Install chaincode on peer1.org2
#echo "Installing chaincode on peer1.org2..."
#installChaincode 1 2
# Query on chaincode on peer1.org2, check if the result is 90
#echo "Querying chaincode on peer1.org2..."
#chaincodeQuery 1 2 90
echo
echo "========= All GOOD, BYFN execution completed =========== "
echo
echo
echo " _____ _ _ ____ "
echo "| ____| | \ | | | _ \ "
echo "| _| | \| | | | | | "
echo "| |___ | |\ | | |_| | "
echo "|_____| |_| \_| |____/ "
echo
exit 0
I just resolved the same issue just deleting all docker images of fabric and the volumes too. And re installed with the fabric version 1.2.0-rc1curl -sSL http:// url /2ysbOFE | bash -s 1.2.0-rc1 url: bit dot ly I can't post that url
Edit: you can check if your docker containers have some capabilities troubles? with docker logs _container_name_
In container name you should put the container name of the dead container, you can check out with docker ps -a, the 'exit (n time) ago'.
If you have capabilities troubles please put capabilities like that capabilities there are in configtx.yaml
One of the problems could be that you have an old version of the cryptogen tool, if you are pointing to an old version of it, your crypto files must be all corruped, you should always point to your version downloaded with the examples.
Another solution can be disable the firewall in both PCs, be sure that they can see each other, and open the correspondant ports, also you should add a extra-hosts section to your docker compose files (check the link below, I talk about that in the blog)
If you had run lot of tests, clean all images and containers, that always help.
If nothing of that works, I wrote a tutorial based on the basic-network example and how to run it in multiple hosts, maybe you can take some information from there.
Setup Hyperledger Fabric in multiple physical machines
Please, feel free to ask, if you have doubts!
Related
I got problems during my invoke.
1.) I rund following command:
peer lifecycle chaincode querycommitted \
--channelID mychannel \
--name basic \
--cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
--> till here everything worked well.
Than I wanted to invoke the chaincode:
peer chaincode invoke \
-o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
--tls \
--cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem \
-C mychannel \
-n basic \
--peerAddresses localhost:7051 \
--tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt \
--peerAddresses localhost:9051 \
--tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt \
-c '{"function":"InitLedger","Args":[]}'
Afterwards I got the Error:
Error: endorsement failure during invoke. response: status:500 message:"error in simulation: failed to execute transaction 93.....: could not launch chaincode basic_1.0:465......: chaincode registration failed: container exited with 1"
I tried the whole process serveral times, to make sure, that I do not have any mistakes before.
I also checked the dockers by docker ps , all are normal.
So I have no glue, what the source for the error could be.I will be happy about every help! Thank you!!!
Initially after committing the chaincode, init must be performed first. To execute init, you just need to specify --isInit in the invoke parameter option. See the documentation below.
fabric/peer/chaincode
peer chaincode invoke \
-o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
--tls \
--cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem \
-C mychannel \
-n basic \
--isInit \
--peerAddresses localhost:7051 \
--tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt \
--peerAddresses localhost:9051 \
--tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt \
-c '{"function":"InitLedger","Args":[]}'
I wrote a script (see below) based on startFabric.sh to upgrade the fabcar chaincode. Basically, (1) I executed ./startFabric.sh, (2) modified the chaincode which is the fabcar.js file in the chaincodes folder, (3) ran my upgrade script (below), (4) cd javascript folder, (5) executed node query.js, and received error retrieving package and opening directory. What is wrong with my upgradeFabric.sh script?
#!/bin/bash
set -e
# don't rewrite paths for Windows Git Bash users
export MSYS_NO_PATHCONV=1
starttime=$(date +%s)
CC_SRC_LANGUAGE=${1:-"go"}
CC_SRC_LANGUAGE=`echo "$CC_SRC_LANGUAGE" | tr [:upper:] [:lower:]`
if [ "$CC_SRC_LANGUAGE" = "go" -o "$CC_SRC_LANGUAGE" = "golang" ]; then
CC_RUNTIME_LANGUAGE=golang
CC_SRC_PATH=github.com/chaincode/fabcar/go
elif [ "$CC_SRC_LANGUAGE" = "java" ]; then
CC_RUNTIME_LANGUAGE=java
CC_SRC_PATH=/opt/gopath/src/github.com/chaincode/fabcar/java
elif [ "$CC_SRC_LANGUAGE" = "javascript" ]; then
CC_RUNTIME_LANGUAGE=node # chaincode runtime language is node.js
CC_SRC_PATH=/opt/gopath/src/github.com/chaincode/fabcar/javascript
elif [ "$CC_SRC_LANGUAGE" = "typescript" ]; then
CC_RUNTIME_LANGUAGE=node # chaincode runtime language is node.js
CC_SRC_PATH=/opt/gopath/src/github.com/chaincode/fabcar/typescript
echo Compiling TypeScript code into JavaScript ...
pushd ../chaincode/fabcar/typescript
npm install
npm run build
popd
echo Finished compiling TypeScript code into JavaScript
else
echo The chaincode language ${CC_SRC_LANGUAGE} is not supported by this script
echo Supported chaincode languages are: go, javascript, and typescript
exit 1
fi
# clean the keystore
rm -rf ./hfc-key-store
CONFIG_ROOT=/opt/gopath/src/github.com/hyperledger/fabric/peer
ORG1_MSPCONFIGPATH=${CONFIG_ROOT}/crypto/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp
ORG1_TLS_ROOTCERT_FILE=${CONFIG_ROOT}/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
ORG2_MSPCONFIGPATH=${CONFIG_ROOT}/crypto/peerOrganizations/org2.example.com/users/Admin#org2.example.com/msp
ORG2_TLS_ROOTCERT_FILE=${CONFIG_ROOT}/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
ORDERER_TLS_ROOTCERT_FILE=${CONFIG_ROOT}/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
set -x
echo "Installing smart contract on peer0.org1.example.com"
docker exec \
-e CORE_PEER_LOCALMSPID=Org1MSP \
-e CORE_PEER_ADDRESS=peer0.org1.example.com:7051 \
-e CORE_PEER_MSPCONFIGPATH=${ORG1_MSPCONFIGPATH} \
-e CORE_PEER_TLS_ROOTCERT_FILE=${ORG1_TLS_ROOTCERT_FILE} \
cli \
peer chaincode install \
-n fabcar \
-v 1.6 \
-p "$CC_SRC_PATH" \
-l "$CC_RUNTIME_LANGUAGE"
echo "Installing smart contract on peer0.org2.example.com"
docker exec \
-e CORE_PEER_LOCALMSPID=Org2MSP \
-e CORE_PEER_ADDRESS=peer0.org2.example.com:9051 \
-e CORE_PEER_MSPCONFIGPATH=${ORG2_MSPCONFIGPATH} \
-e CORE_PEER_TLS_ROOTCERT_FILE=${ORG2_TLS_ROOTCERT_FILE} \
cli \
peer chaincode install \
-n fabcar \
-v 1.6 \
-p "$CC_SRC_PATH" \
-l "$CC_RUNTIME_LANGUAGE"
echo "(1/2) Upgrading smart contract on mychannel"
docker exec \
-e CORE_PEER_LOCALMSPID=Org1MSP \
-e CORE_PEER_MSPCONFIGPATH=${ORG1_MSPCONFIGPATH} \
cli \
peer chaincode upgrade \
-o orderer.example.com:7050 \
-C mychannel \
-n fabcar \
-l "$CC_RUNTIME_LANGUAGE" \
-v 1.6 \
-c '{"Args":[]}' \
-P "AND('Org1MSP.member','Org2MSP.member')" \
--tls \
--cafile ${ORDERER_TLS_ROOTCERT_FILE} \
--peerAddresses peer0.org1.example.com:7051 \
--tlsRootCertFiles ${ORG1_TLS_ROOTCERT_FILE}
echo "(2/2) Upgrading smart contract on mychannel"
docker exec \
-e CORE_PEER_LOCALMSPID=Org2MSP \
-e CORE_PEER_MSPCONFIGPATH=${ORG2_MSPCONFIGPATH} \
cli \
peer chaincode upgrade \
-o orderer.example.com:7050 \
-C mychannel \
-n fabcar \
-l "$CC_RUNTIME_LANGUAGE" \
-v 1.6 \
-c '{"Args":[]}' \
-P "AND('Org1MSP.member','Org2MSP.member')" \
--tls \
--cafile ${ORDERER_TLS_ROOTCERT_FILE} \
--peerAddresses peer0.org2.example.com:9051 \
--tlsRootCertFiles ${ORG2_TLS_ROOTCERT_FILE}
echo "Waiting for upgrade request to be committed ..."
sleep 10
echo "Submitting initLedger transaction to smart contract on mychannel"
echo "The transaction is sent to the two peers with the chaincode installed (peer0.org1.example.com and peer0.org2.example.com) so that chaincode is built before receiving the following requests"
docker exec \
-e CORE_PEER_LOCALMSPID=Org1MSP \
-e CORE_PEER_MSPCONFIGPATH=${ORG1_MSPCONFIGPATH} \
cli \
peer chaincode invoke \
-o orderer.example.com:7050 \
-C mychannel \
-n fabcar \
-c '{"function":"initLedger","Args":[]}' \
--waitForEvent \
--tls \
--cafile ${ORDERER_TLS_ROOTCERT_FILE} \
--peerAddresses peer0.org1.example.com:7051 \
--peerAddresses peer0.org2.example.com:9051 \
--tlsRootCertFiles ${ORG1_TLS_ROOTCERT_FILE} \
--tlsRootCertFiles ${ORG2_TLS_ROOTCERT_FILE}
set +x
cat <<EOF
Total setup execution time : $(($(date +%s) - starttime)) secs ...
EOF
And this is the error when executing node query.js...
allet path: /home/seans/go/src/fabric-samples/fabcar/javascript/wallet
2020-06-20T00:08:33.951Z - warn: [Query]: evaluate: Query ID "[object Object]" of peer "peer1.org1.example.com:8051" failed: message=cannot retrieve package for chaincode fabcar/1.6, error open /var/hyperledger/production/chaincodes/fabcar.1.6: no such file or directory, stack=Error: cannot retrieve package for chaincode fabcar/1.6, error open /var/hyperledger/production/chaincodes/fabcar.1.6: no such file or directory
at self._endorserClient.processProposal (/home/seans/node_modules/fabric-client/lib/Peer.js:144:36)
at Object.onReceiveStatus (/home/seans/node_modules/grpc/src/client_interceptors.js:1212:9)
at InterceptingListener._callNext (/home/seans/node_modules/grpc/src/client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (/home/seans/node_modules/grpc/src/client_interceptors.js:618:8)
at callback (/home/seans/node_modules/grpc/src/client_interceptors.js:847:24), status=500, , url=grpcs://localhost:8051, name=peer1.org1.example.com:8051, grpc.max_receive_message_length=-1, grpc.max_send_message_length=-1, grpc.keepalive_time_ms=120000, grpc.http2.min_time_between_pings_ms=120000, grpc.keepalive_timeout_ms=20000, grpc.http2.max_pings_without_data=0, grpc.keepalive_permit_without_calls=1, name=peer1.org1.example.com:8051, grpc.ssl_target_name_override=peer1.org1.example.com, grpc.default_authority=peer1.org1.example.com, isProposalResponse=true
Failed to evaluate transaction: Error: cannot retrieve package for chaincode fabcar/1.6, error open /var/hyperledger/production/chaincodes/fabcar.1.6: no such file or directory
I would recommend a couple of things.
Check to see if you're using the 2.X release of Fabric (v2.1.1 is the latest stable version at the moment). It has the new lifecycle functionality which will make working with chaincode a lot easier. For instance, with the new lifecycle, installing and upgrading a chaincode follows the same process and commands, you use peer lifecycle chaincode install to install and/or upgrade a chaincode.
The overall flow to deploy chaincode becomes pretty straightforward (1) package the chaincode, (2) install it on your peers, (3) approve the chaincode definition for your organization, and (4) commit the definition to your channel.
You can use the test-network tutorial to get set up with 2.X, it takes you through the complete network and chaincode set up. Look at network.sh and deployCC.sh scripts from the tutorial for details on how to work with Chaincode.
Further Reading
The upgrade process with new lifecycle based chaincode mgmt.
Blog on deploying CC with Fabric 2.X based on the test-network.
I am using Basic network with my changed organizations "user" and "legaldocxauth" and fabcar chaincode to run with it (later i will change chaincode functions according to my use case) but whenever i run startFabric.sh on instantiating chaincode it gives error "failed to deserialize creator identity, err usermsp msp is unknown"
Docker version latest 18.09.0
I have changed other network files configtx , docker-compose yaml and
crypto configtx Msps accordingly
I have also tried other solutions(on stackoverflow) of similar problem but no luck :(
Here is code for Startfabric.sh
set -e
# don't rewrite paths for Windows Git Bash users
export MSYS_NO_PATHCONV=1
starttime=$(date +%s)
LANGUAGE=${1:-"golang"}
CC_SRC_PATH=user/go
if [ "$LANGUAGE" = "node" -o "$LANGUAGE" = "NODE" ]; then
CC_SRC_PATH=/opt/gopath/src/github.com/fabcar/node
fi
# clean the keystore
rm -rf ./../client/hfc-key-store
docker exec -e "CORE_PEER_LOCALMSPID=userMSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/user.example.com/users/Admin#user.example.com/msp" cli peer chaincode install -n newCC -v 2.0 -p "$CC_SRC_PATH" -l "$LANGUAGE"
docker exec -e "CORE_PEER_LOCALMSPID=userMSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/user.example.com/users/Admin#user.example.com/msp" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n newCC -l "$LANGUAGE" -v 2.0 -c '{"Args":[""]}' -P "OR ('userMSP.member','legaldocxauthMSP.member')"
sleep 10
docker exec -e "CORE_PEER_LOCALMSPID=userMSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/user.example.com/users/Admin#user.example.com/msp" cli peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n newCC -c '{"function":"initLedger","Args":[""]}'
printf "\nTotal setup execution time : $(($(date +%s) - starttime)) secs ...\n\n\n"
printf "Start by installing required packages run 'npm install'\n"
printf "Then run 'node enrollAdmin.js', then 'node registerUser'\n\n"
printf "The 'node invoke.js' will fail until it has been updated with valid arguments\n"
printf "The 'node query.js' may be run at anytime once the user has been registered\n\n"
I successfully got https://github.com/blacklabelops/letsencrypt and the nginx running on my virtual machine on azure.
In Docker I hae now 2 containers. One with my go application running and being reachable on port 8080 on the web, one with the nginx container of blacklabelops. this one is binded to ports 80 and 443. I followed the tutorial "Letsencrypt and Nginx" on github for the steps 1-3 and replaced "http://yourserver" in step 3 with the url of my go application and port 8080 where I can reach it via http.
When I call https and the domain nothing happens. Ports 8080,443 and 80 are open in the azure network security group.
Can you give me a hint?
Update: I can post the commands _i performed here.
I have "my" application running on http://myapp.westeurope.cloudapp.azure.com:8080
I performed 1:
sudo docker run -d \
-p 80:80 \
-p 443:443 \
-e "SERVER1REVERSE_PROXY_LOCATION1=/" \
-e "SERVER1REVERSE_PROXY_PASS1=172.17.0.2" \
-e "SERVER1CERTIFICATE_DNAME=/CN=Chatbot/OU=Kundenservice/O=myapp.westeurope.cloudapp.azure.com/L=Frankfurt/C=DE" \
-e "SERVER1HTTPS_ENABLED=true" \
--name nginx \
blacklabelops/nginx
Than I performed 2:
sudo docker run --rm \
-p 80:80 \
-p 443:443 \
-v letsencrypt_certificates:/etc/letsencrypt \
-e "LETSENCRYPT_EMAIL=mymail#azure.com" \
-e "LETSENCRYPT_DOMAIN1=myapp.westeurope.cloudapp.azure.com" \
blacklabelops/letsencrypt install
I did 3:
sudo docker volume create letsencrypt_challenges
And 4:
-p 443:443 \
-p 80:80 \
-v letsencrypt_certificates:/etc/letsencrypt \
-v letsencrypt_challenges:/var/www/letsencrypt \
-e "NGINX_REDIRECT_PORT80=true" \
-e "SERVER1REVERSE_PROXY_LOCATION1=/" \
-e "SERVER1REVERSE_PROXY_PASS1=http://myapp.westeurope.cloudapp.azure.com" \
-e "SERVER1HTTPS_ENABLED=true" \
-e "SERVER1HTTP_ENABLED=true" \
-e "SERVER1LETSENCRYPT_CERTIFICATES=true" \
-e "SERVER1CERTIFICATE_FILE=/etc/letsencrypt/live/myapp.westeurope.cloudapp.azure.com/fullchain.pem" \
-e "SERVER1CERTIFICATE_KEY=/etc/letsencrypt/live/myapp.westeurope.cloudapp.azure.com/privkey.pem" \
-e "SERVER1CERTIFICATE_TRUSTED=/etc/letsencrypt/live/myapp.westeurope.cloudapp.azure.com/fullchain.pem" \
--name nginx \
blacklabelops/nginx
I am new to hyperledger and is going through the example here . I am tried to play around the chaincode but is now stuck at the part where I am suppose to upgrade the chaincode
I have tried to execute the peer chaincode upgrade within the docker peer node:
peer chaincode upgrade -n tuna-app -p github.com/tuna-app
but end up with the error
Error getting (testchainid) orderer endpoint: Error endorsing GetConfigBlock: rpc error: code = Unknown desc = chaincode error (status: 500, message: "GetConfigBlock" request failed authorization check for channel [testchainid]: [Failed to get policy manager for channel [testchainid]])
You need to specify the channel name for which you'd like to upgrade the chaincode, also need to specify args and new version. Moreover you have to specify the ordering service endpoints so peer cli will be able to submit the upgrade transaction:
peer chaincode upgrade -n tuna-app -v 2.0 \
-c '{"Args":[""]}' \
-p github.com/tuna-app -C mychannel \
-o orderer:7051
You can find more here.
Here you have some basic script in bash:
#!/bin/bash
PRV_VERSION='v2';
VERSION='v3';
CONTAINER_IDS=$(docker ps -a | grep "mycc-$PRV_VERSION" | awk '{print $1}')
docker rm -f $CONTAINER_IDS
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/users/Admin#org1.example.com/msp" peer0.org1.example.com \
peer chaincode install \
-n mycc \
-v $VERSION \
-p /etc/hyperledger/chaincode \
-l node;
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/users/Admin#org1.example.com/msp" peer1.org1.example.com \
peer chaincode install \
-n mycc \
-v $VERSION \
-p /etc/hyperledger/chaincode \
-l node;
docker exec -e "CORE_PEER_LOCALMSPID=Org2MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/users/Admin#org2.example.com/msp" peer0.org2.example.com \
peer chaincode install \
-n mycc \
-v $VERSION \
-p /etc/hyperledger/chaincode \
-l node;
docker exec -e "CORE_PEER_LOCALMSPID=Org2MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/users/Admin#org2.example.com/msp" peer1.org2.example.com \
peer chaincode install \
-n mycc \
-v $VERSION \
-p /etc/hyperledger/chaincode \
-l node;
sleep 10;
ORDERER_CA=/etc/hyperledger/organizations/users/Admin#example.com/msp/tlscacerts/tlsca.example.com-cert.pem
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" \
-e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/users/Admin#org1.example.com/msp" \
peer0.org1.example.com \
peer chaincode upgrade \
-o orderer.example.com:7050 --tls --cafile $ORDERER_CA \
-C mychannel \
-n mycc \
-v $VERSION \
-c '{"Args":[""]}' \
-p /etc/hyperledger/chaincode
ORDERER_CA=/etc/hyperledger/organizations/users/Admin#example.com/msp/tlscacerts/tlsca.example.com-cert.pem
docker exec -e "CORE_PEER_LOCALMSPID=Org2MSP" \
-e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/users/Admin#org2.example.com/msp" \
peer0.org2.example.com \
peer chaincode upgrade \
-o orderer.example.com:7050 --tls --cafile $ORDERER_CA \
-C mychannel \
-n mycc \
-v $VERSION \
-c '{"Args":[""]}' \
-p /etc/hyperledger/chaincode
You need of course share some certs to your peer0.org1 and of course the chaincode itself (in js or go), here you have some docker-compose.yml part:
peer0.org1.example.com:
container_name: peer0.org1.example.com
extends:
file: base.yaml
service: peer-base
environment:
- CORE_PEER_ID=peer0.org1.example.com
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
ports:
- 7051:7051
- 7053:7053
volumes:
- ./channel/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/:/etc/hyperledger/crypto/peer
- ./channel/crypto-config/peerOrganizations/org1.example.com/users:/etc/hyperledger/peer/users
- ./channel/crypto-config/ordererOrganizations/example.com/users:/etc/hyperledger/organizations/users
- ./src/github.com/example_cc/node:/etc/hyperledger/chaincode
Then you can check the logs by:
docker logs dev-peer0.org1.example.com-mycc-v3 -f
I need to say, that upgrading chaincode in development take the same amount of time as just recreate whole blockchain (without pulling new images - this should be removed from ./runApp.sh script).