split script and add blocks

pull/56/head
qiang0723 2017-06-09 19:42:58 +08:00
parent 1e91338629
commit 6f25602b54
15 changed files with 299 additions and 194 deletions

View File

@ -32,7 +32,7 @@ $ bash scripts/download_images.sh
There are also some community [images](https://hub.docker.com/r/hyperledger/) at Dockerhub, use at your own choice.
### Bootup Fabric 1.0
### Bootup and test Fabric 1.0
Start a fabric cluster.
@ -62,13 +62,41 @@ cd21cfff8298 hyperledger/fabric-peer "peer node start --pe" 22 sec
47ce30077276 hyperledger/fabric-peer "peer node start --pe" 22 seconds ago Up 20 seconds 7050/tcp, 7052/tcp, 7054-7059/tcp, 0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp peer1.org1.example.com
```
#### Test fabric network
#### Initialize fabric network
Into the container fabric-cli and run the initialize.sh script, this will prepare the basic environment required for chaincode operations,
inclode `create channel`, `join channel`, `install` and `instantiate`. this script only needs to be executed once.
Into the container fabric-cli and run the test script.
```bash
$ docker exec -it fabric-cli bash
$ bash ./scripts/test_4peers.sh
$ bash ./scripts/initialize.sh
```
You should see the following output:
```bash
2017-06-09 10:13:01.015 UTC [main] main -> INFO 00c Exiting.....
===================== Chaincode Instantiation on PEER2 on channel 'businesschannel' is successful =====================
===================== All GOOD, initialization completed =====================
_____ _ _ ____
| ____| | \ | | | _ \
| _| | \| | | | | |
| |___ | |\ | | |_| |
|_____| |_| \_| |____/
```
#### Chaincode operation
After initialize network, you can execute some chaincode operations, such as `query` or `invoke`,
and you can modify the parameters and execute this script repeatedly.
```bash
$ bash ./scripts/test_4peers.sh #execute in container fabric-cli
```
You should see the following output:
@ -76,20 +104,34 @@ You should see the following output:
```bash
UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP
UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity
UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0AB1070A6708031A0C08F6DCDDC90510...6D7963631A0A0A0571756572790A0161
UTC [msp/identity] Sign -> DEBU 007 Sign: digest: 4095B73E1AA14FE681BCF891A6E08E55D7B01FA0C2D01E69E91DD1019E9E48CB
Query Result: 90
UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0AB7070A6D08031A0C08C3EAE9C90510...6D7963631A0A0A0571756572790A0161
UTC [msp/identity] Sign -> DEBU 007 Sign: digest: FA308EF50C4812BADB60D58CE15C1CF41089EFB93B27D46885D92C92F55E98A0
Query Result: 80
UTC [main] main -> INFO 008 Exiting.....
===================== Query on PEER3 on channel 'mychannel' is successful =====================
===================== Query on PEER3 on channel 'businesschannel' is successful =====================
===================== All GOOD, End-2-End execution completed =====================
_____ _ _ ____ _____ ____ _____
| ____| | \ | | | _ \ | ____| |___ \ | ____|
| _| | \| | | | | | _____ | _| __) | | _|
| |___ | |\ | | |_| | |_____| | |___ / __/ | |___
|_____| |_| \_| |____/ |_____| |_____| |_____|
_____ _ _ ____
| ____| | \ | | | _ \
| _| | \| | | | | |
| |___ | |\ | | |_| |
|_____| |_| \_| |____/
```
At last, you can fetch blocks using following command:
```bash
$ NUM= the block's num you want to fetch
$ peer channel fetch $NUM -o orderer.example.com:7050 -c businesschannel
```
In this example, we `install` 4 times, and `invoke` 2 times, so we have 6 blocks in total, and we put it into `/e2e_cli/channel-artifacts`.
you can also use following command to fetch blocks:
```bash
$ peer channel fetch oldest -o orderer.example.com:7050 -c businesschannel
$ peer channel fetch newest -o orderer.example.com:7050 -c businesschannel
```
## Explain the steps
@ -118,7 +160,7 @@ bea1154c7162 hyperledger/fabric-ca "fabric-ca-server ..." About
**You can skip this step**, as we already put the needed artifacts `orderer.genesis.block` and `channel.tx` under `e2e_cli/channel-artifacts/`.
Detailed steps in [GenerateArtifacts](./artifacts_generation/GenerateArtifacts.md) explains the creation of `orderer.genesis.block` (needed by orderering service) and `channel.tx` (needed by cli to create new channel) and crypto related configuration files.
Detailed steps in [GenerateArtifacts](./artifacts_generation/artifacts_generation.md) explains the creation of `orderer.genesis.block` (needed by orderering service) and `channel.tx` (needed by cli to create new channel) and crypto related configuration files.
#### Create new channel

View File

@ -15,20 +15,20 @@ and put cryptographic materials to e2e_cli/crypto_config. So this doc will expla
This tool will generate the x509 certificates used to identify and authenticate the various components in the network.
First boot network through `docker-compose-2orgs.yml`
First boot network through `docker-compose-2orgs-4peers.yaml`
```bash
$ (sudo) docker-compose -f docker-compose-2orgs.yml up
$ (sudo) docker-compose -f docker-compose-2orgs-4peers.yaml up
```
and execute `cryptogen generate` command
```bash
$ cryptogen generate --config=./peer/crypto-config.yaml --output ./peer/crypto
$ cryptogen generate --config=/etc/hyperledger/fabric/crypto-config.yaml --output ./crypto
```
cryptogen will read configuration from `crypto-config.yaml`, so if we want to add(change) Orgs or perrs topology, we should change this file first.
> The results will save under directory crypto, and this directory has mounted from host, defined in the `docker-compose-2orgs.yaml`.
> The results will save under directory crypto, and this directory has mounted from host, defined in the `docker-compose-2orgs-4peers.yaml.yaml`.
> for more information refer to Example2
@ -37,40 +37,34 @@ cryptogen will read configuration from `crypto-config.yaml`, so if we want to ad
This tool will generate genesis block, channel configuration transaction and update anchor peer.
the following is a general steps after changing the configtx.yaml.
#### Replace default configtx.yaml
```bash
root@cli: cp ./peer/configtx.yaml /etc/hyperledger/fabric
```
The `configtxgen` tool is in `/go/bin/`, and when it's executed,
it will read configuration from `/etc/hyperledger/fabric/configtx.yaml`,
So if we want to regenerate `orderer_genesis.block` and `channel.tx`, we should
So if we want to regenerate `orderer.genesis.block` and `channel.tx`, we should
replace `configtx.yaml` using our own configtx.yaml first.
#### Create orderer genesis block
```bash
root@cli: configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./peer/channel-artifacts/orderer_genesis.block
root@cli: configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/orderer.genesis.block
```
#### Create channel transaction artifact
```bash
root@cli: CHANNEL_NAME=mychannel
root@cli: configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./peer/channel-artifacts/channel.tx -channelID ${CHANNEL_NAME}
root@cli: CHANNEL_NAME=businesschannel
root@cli: configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID ${CHANNEL_NAME}
```
`channel.tx` is used for generating new channel `mychannel`
`channel.tx` is used for generating new channel `businesschannel`
#### Update anchor peer for Organizations on the channel
Chose peer peer0.org1.example.com as org1's anchor peer, and peer0.org2.example.com as org2's anchor peer.
```bash
root@cli: configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./peer/channel-artifacts/Org1MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org1MSP
root@cli: configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org1MSP
```
```bash
root@cli: configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./peer/channel-artifacts/Org2MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org2MSP
root@cli: configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org2MSP
```
> more details refer to Example2
@ -80,6 +74,7 @@ root@cli: configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./peer/ch
#### Example1: how to add and re-join a new channel
This example will explain how to add a new channel without change basic topology that desigend in configtx.yaml and crypto-config.yaml.
start a fabric network with `docker-compose-1peer.yaml`, and into container fabric-cli
* 1 Regenerate `channel.tx` using with new channel name
@ -87,29 +82,28 @@ Create channel configuration for the to-be-created `testchannel`.
```bash
$ root@cli: CHANNEL_NAME=testchannel
$ root@cli: cp ./peer/configtx.yaml /etc/hyperledger/fabric
$ root@cli: configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./peer/channel-artifacts/channel.tx -channelID ${CHANNEL_NAME}
$ root@cli: configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID ${CHANNEL_NAME}
```
* 2 regenerate anchor peer configuratoin for Organizations
```bash
$ root@cli: configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./peer/channel-artifacts/Org1MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org1MSP
$ root@cli: configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org1MSP
$ root@cli: configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./peer/channel-artifacts/Org2MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org2MSP
$ root@cli: configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org2MSP
```
* (optional)execute auto-test script
You can skip this step, this will quickly check whether the network works, and also you can verify manually.
```bash
$ root@cli: bash ./peer/scripts/new-channel-auto-test.sh testchannel
$ root@cli: bash ./peer/scripts/test_1peer.sh testchannel
```
* 3 Create new channel
```bash
$ root@cli: peer channel create -o orderer.example.com:7050 -c ${CHANNEL_NAME} -f ./peer/channel-artifacts/channel.tx
$ root@cli: peer channel create -o orderer.example.com:7050 -c ${CHANNEL_NAME} -f ./channel-artifacts/channel.tx
```
check whether genrated new block `testchannel.block`
@ -141,7 +135,7 @@ Channels peers has joined to:
* 5 Update anchor peer
```bash
$ root@cli: peer channel create -o orderer.example.com:7050 -c ${CHANNEL_NAME} -f ./peer/channel-artifacts/Org1MSPanchors.tx
$ root@cli: peer channel create -o orderer.example.com:7050 -c ${CHANNEL_NAME} -f ./channel-artifacts/Org1MSPanchors.tx
```
* 6 Install
@ -177,16 +171,18 @@ This example will explain how to add a new org or peer with changed the basic to
##### all-in-one
We privide some [instance](./example2), in this case we add a new organization `Org3` and new peer `peer0.org3.example.com`.
We privide some instance in current directory, in this case we add a new organization `Org3` and new peer `peer0.org3.example.com`.
* 1 Generate necessary config and certs
```bash
$ sudo docker-compose -f docker-compose-2orgs.yml up
$ sudo docker-compose -f docker-compose-2orgs-4peers-event.yaml up
$ docker exec -it fabric-cli bash
$ root@cli: ./peer/example2/add-org.sh
$ root@cli: ./scripts/add-org.sh
```
> ** notice: For docker-compose-file clean, we did not mount these in the container, you need to mount yourself.
* 2 Re-setup network
```bash
@ -198,14 +194,14 @@ docker rmi -f `docker images|grep mycc-1.0|awk '{print $3}'`
```
```bash
$ sudo docker-compose -f docker-compose-2orgs.yml up
$ sudo docker-compose -f docker-compose-2orgs-4peers-event.yaml up
```
* 3 execute auto-test
Throuth this script to test whether the network works.
```bash
$ root@cli: bash ./peer/scripts/new-channel-auto-test-5-peers.sh newchannel
$ root@cli: bash ./scripts/test-5-peers.sh newchannel
```
The final output may look like following
@ -224,60 +220,50 @@ The final output may look like following
modify configtx.yaml, crypto-cnfig.yaml and docker-compose files to adapt new change. and replace old file.
* 2 Bootstrap network with `docker-compose-2orgs.yml`
* 2 Bootstrap network with `docker-compose-2orgs-4peers-event.yaml`
```bash
$ docker-compose -f docker-compose-2orgs.yml up
$ docker-compose -f docker-compose-2orgs-4peers-event.yaml up
```
> notes:You may encounter some errors at startup and some peers can't start up, It's innocuous, ignore it,
because we will restart later, and now we just use tools in cli container.
* 3 Replace default configtx.yaml
* 3 Generate new certificates
```bash
root@cli: cp ./peer/configtx.yaml /etc/hyperledger/fabric
$ cryptogen generate --config=/etc/hyperledger/fabric/crypto-config.yaml --output ./crypto
```
* 4 Generate new certificates
* 4 Create the genesis block
```bash
$ cryptogen generate --config=./peer/crypto-config.yaml --output ./peer/crypto
root@cli: configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/orderer_genesis.block
```
* 5 Create the genesis block
```bash
root@cli: configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./peer/channel-artifacts/orderer_genesis.block
```
* 6 Create the configuration tx
* 5 Create the configuration tx
```bash
root@cli: CHANNEL_NAME=newchannel
root@cli: configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./peer/channel-artifacts/channel.tx -channelID ${CHANNEL_NAME}
root@cli: configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID ${CHANNEL_NAME}
```
`channel.tx` is used for generating new channel `newchannel`
* 7 Define the anchor peer for Orgs on the channel
* 6 Define the anchor peer for Orgs on the channel
```bash
root@cli: configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./peer/channel-artifacts/Org1MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org1MSP
root@cli: configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org1MSP
root@cli: configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./peer/channel-artifacts/Org2MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org2MSP
root@cli: configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org2MSP
root@cli: configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./peer/channel-artifacts/Org3MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org3MSP
root@cli: configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org3MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org3MSP
```
* 8 Restart network
* 7 Restart network
<<<<<<< HEAD
As we have changed the configtx.yaml and regenerate `orderer_genesis.block`,
we'd better restart orderering service or all the service.
=======
As we have regenerate `orderer.genesis.block` and add a new container,
we'd better re-execute docker-compose-2orgs.yaml,
>>>>>>> 2569f8bf1990a63850aee108528059a562d68b46
now we clean all the old service and boot a new network.
```bash
@ -292,12 +278,12 @@ docker rmi -f `docker images|grep mycc-1.0|awk '{print $3}'`
$ sudo docker-compose -f docker-compose-2orgs.yml up
```
* 9 Execute auto-test script
* 8 Execute auto-test script
Until this step, we complete the network re-setup, and then we will test whether it works.
```bash
$ root@cli: bash ./peer/scripts/new-channel-auto-test-5-peers.sh
$ root@cli: bash ./scripts/test-5-peers.sh
```
If the network works well. the output may looklike:

View File

@ -0,0 +1,184 @@
#!/bin/bash
echo
echo " ============================================== "
echo " ==========initialize businesschannel========== "
echo " ============================================== "
echo
CHANNEL_NAME="$1"
: ${CHANNEL_NAME:="businesschannel"}
: ${TIMEOUT:="60"}
COUNTER=1
MAX_RETRY=5
ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/cacerts/ca.example.com-cert.pem
echo "Channel name : "$CHANNEL_NAME
verifyResult () {
if [ $1 -ne 0 ] ; then
echo "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!"
echo "================== ERROR !!! FAILED to execute End-2-End Scenario =================="
echo
exit 1
fi
}
setGlobals () {
if [ $1 -eq 0 -o $1 -eq 1 ] ; then
CORE_PEER_LOCALMSPID="Org1MSP"
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
if [ $1 -eq 0 ]; then
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
else
CORE_PEER_ADDRESS=peer1.org1.example.com:7051
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
fi
else
CORE_PEER_LOCALMSPID="Org2MSP"
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
if [ $1 -eq 2 ]; then
CORE_PEER_ADDRESS=peer0.org2.example.com:7051
else
CORE_PEER_ADDRESS=peer1.org2.example.com:7051
fi
fi
env |grep CORE
}
createChannel() {
setGlobals 0
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx >&log.txt
else
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
fi
res=$?
cat log.txt
verifyResult $res "Channel creation failed"
echo "===================== Channel \"$CHANNEL_NAME\" is created successfully ===================== "
echo
}
updateAnchorPeers() {
PEER=$1
setGlobals $PEER
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx >&log.txt
else
peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA >&log.txt
fi
res=$?
cat log.txt
verifyResult $res "Anchor peer update failed"
echo "===================== Anchor peers for org \"$CORE_PEER_LOCALMSPID\" on \"$CHANNEL_NAME\" is updated successfully ===================== "
echo
}
## Sometimes Join takes time hence RETRY atleast for 5 times
joinWithRetry () {
peer channel join -b $CHANNEL_NAME.block >&log.txt
res=$?
cat log.txt
if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then
COUNTER=` expr $COUNTER + 1`
echo "PEER$1 failed to join the channel, Retry after 2 seconds"
sleep 2
joinWithRetry $1
else
COUNTER=1
fi
verifyResult $res "After $MAX_RETRY attempts, PEER$ch has failed to Join the Channel"
}
joinChannel () {
for ch in 0 1 2 3; do
setGlobals $ch
joinWithRetry $ch
echo "===================== PEER$ch joined on the channel \"$CHANNEL_NAME\" ===================== "
sleep 2
echo
done
}
installChaincode () {
PEER=$1
setGlobals $PEER
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 >&log.txt
res=$?
cat log.txt
verifyResult $res "Chaincode installation on remote peer PEER$PEER has Failed"
echo "===================== Chaincode is installed on remote peer PEER$PEER ===================== "
echo
}
instantiateChaincode () {
PEER=$1
setGlobals $PEER
# while 'peer chaincode' command can get the orderer endpoint from the peer (if join was successful),
# lets supply it directly as we know it using the "-o" option
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
peer chaincode instantiate -o orderer.example.com:7050 -C $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')" >&log.txt
else
peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')" >&log.txt
fi
res=$?
cat log.txt
verifyResult $res "Chaincode instantiation on PEER$PEER on channel '$CHANNEL_NAME' failed"
echo "===================== Chaincode Instantiation on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== "
echo
}
## 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
echo "Updating anchor peers for org2..."
updateAnchorPeers 2
## Install chaincode on Peer0/Org1 and Peer2/Org2
echo "Installing chaincode on org1/peer0..."
installChaincode 0
echo "Install chaincode on org1/peer1..."
installChaincode 1
echo "Install chaincode on org2/peer0..."
installChaincode 2
echo "Install chaincode on org2/peer1..."
installChaincode 3
# Instantiate chaincode on Peer0/Org2
# Instantiate can only be executed once on any node
echo "Instantiating chaincode on peer0/org2..."
instantiateChaincode 2
echo
echo "===================== All GOOD, initialization completed ===================== "
echo
echo
echo " _____ _ _ ____ "
echo "| ____| | \ | | | _ \ "
echo "| _| | \| | | | | |"
echo "| |___ | |\ | | |_| |"
echo "|_____| |_| \_| |____/ "
echo
exit 0

View File

@ -1,15 +1,16 @@
#!/bin/bash
echo
echo " ____ _____ _ ____ _____ _____ ____ _____ "
echo "/ ___| |_ _| / \ | _ \ |_ _| | ____| |___ \ | ____|"
echo "\___ \ | | / _ \ | |_) | | | _____ | _| __) | | _| "
echo " ___) | | | / ___ \ | _ < | | |_____| | |___ / __/ | |___ "
echo "|____/ |_| /_/ \_\ |_| \_\ |_| |_____| |_____| |_____|"
echo " ______ __ __ _ _____ ____ _ ______ ______ ______ _____ "
echo " / _____| | | | | / \ |_ _| | |\ \ | | / _____| / ______ \ | ___\ \ | ____|"
echo "/ / | |---| | / _ \ | | | | \ \ | | / / / / \ \ | | \ \ | _| "
echo "\ \_____ | |---| | / ___ \ _| |_ | | \ \ | | \ \_____ \ \______/ / | |____/ / | |___ "
echo " \______| |__| |__| /_/ \_\ |_____| |_| \_\|_| \______| \ ______ / |_______/ |_____|"
echo
CHANNEL_NAME="$1"
: ${CHANNEL_NAME:="mychannel"}
: ${CHANNEL_NAME:="businesschannel"}
: ${TIMEOUT:="60"}
COUNTER=1
MAX_RETRY=5
@ -52,91 +53,6 @@ setGlobals () {
env |grep CORE
}
createChannel() {
setGlobals 0
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx >&log.txt
else
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
fi
res=$?
cat log.txt
verifyResult $res "Channel creation failed"
echo "===================== Channel \"$CHANNEL_NAME\" is created successfully ===================== "
echo
}
updateAnchorPeers() {
PEER=$1
setGlobals $PEER
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx >&log.txt
else
peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA >&log.txt
fi
res=$?
cat log.txt
verifyResult $res "Anchor peer update failed"
echo "===================== Anchor peers for org \"$CORE_PEER_LOCALMSPID\" on \"$CHANNEL_NAME\" is updated successfully ===================== "
echo
}
## Sometimes Join takes time hence RETRY atleast for 5 times
joinWithRetry () {
peer channel join -b $CHANNEL_NAME.block >&log.txt
res=$?
cat log.txt
if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then
COUNTER=` expr $COUNTER + 1`
echo "PEER$1 failed to join the channel, Retry after 2 seconds"
sleep 2
joinWithRetry $1
else
COUNTER=1
fi
verifyResult $res "After $MAX_RETRY attempts, PEER$ch has failed to Join the Channel"
}
joinChannel () {
for ch in 0 1 2 3; do
setGlobals $ch
joinWithRetry $ch
echo "===================== PEER$ch joined on the channel \"$CHANNEL_NAME\" ===================== "
sleep 2
echo
done
}
installChaincode () {
PEER=$1
setGlobals $PEER
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 >&log.txt
res=$?
cat log.txt
verifyResult $res "Chaincode installation on remote peer PEER$PEER has Failed"
echo "===================== Chaincode is installed on remote peer PEER$PEER ===================== "
echo
}
instantiateChaincode () {
PEER=$1
setGlobals $PEER
# while 'peer chaincode' command can get the orderer endpoint from the peer (if join was successful),
# lets supply it directly as we know it using the "-o" option
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
peer chaincode instantiate -o orderer.example.com:7050 -C $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')" >&log.txt
else
peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')" >&log.txt
fi
res=$?
cat log.txt
verifyResult $res "Chaincode instantiation on PEER$PEER on channel '$CHANNEL_NAME' failed"
echo "===================== Chaincode Instantiation on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== "
echo
}
chaincodeQuery () {
PEER=$1
echo "===================== Querying on PEER$PEER on channel '$CHANNEL_NAME'... ===================== "
@ -183,56 +99,33 @@ chaincodeInvoke () {
echo
}
## 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
echo "Updating anchor peers for org2..."
updateAnchorPeers 2
## Install chaincode on Peer0/Org1 and Peer2/Org2
echo "Installing chaincode on org1/peer0..."
installChaincode 0
echo "Install chaincode on org2/peer2..."
installChaincode 2
#Instantiate chaincode on Peer0/Org2
echo "Instantiating chaincode on peer0/org2..."
instantiateChaincode 2
#Query on chaincode on Peer0/Org1
echo "Querying chaincode on org1/peer0..."
chaincodeQuery 0 100
chaincodeQuery 2 100
#Invoke on chaincode on Peer0/Org1
echo "Sending invoke transaction on org1/peer0..."
chaincodeInvoke 0
## Install chaincode on Peer1/Org2
echo "Installing chaincode on peer1/org2..."
installChaincode 3
chaincodeInvoke 1
#Query on chaincode on Peer1/Org2, check if the result is 90
echo "Querying chaincode on org2/peer1..."
chaincodeQuery 3 90
chaincodeInvoke 3
chaincodeQuery 3 80
echo
echo "===================== All GOOD, End-2-End execution completed ===================== "
echo
echo
echo " _____ _ _ ____ _____ ____ _____ "
echo "| ____| | \ | | | _ \ | ____| |___ \ | ____|"
echo "| _| | \| | | | | | _____ | _| __) | | _| "
echo "| |___ | |\ | | |_| | |_____| | |___ / __/ | |___ "
echo "|_____| |_| \_| |____/ |_____| |_____| |_____|"
echo " _____ _ _ ____ "
echo "| ____| | \ | | | _ \ "
echo "| _| | \| | | | | |"
echo "| |___ | |\ | | |_| |"
echo "|_____| |_| \_| |____/ "
echo
exit 0