github.com/kaituanwang/hyperledger@v2.0.1+incompatible/docs/source/test_network.md (about) 1 # Using the Fabric test network 2 3 After you have downloaded the Hyperledger Fabric Docker images and samples, you 4 can deploy a test network by using scripts that are provided in the 5 `fabric-samples` repository. You can use the test network to learn about Fabric 6 by running nodes on your local machine. More experienced developers can use the 7 network to test their smart contracts and applications. The network is meant to 8 be used only as a tool for education and testing. It should not be used as a 9 template for deploying a production network. The test network is being introduced 10 in Fabric v2.0 as the long term replacement for the `first-network` sample. 11 12 The sample network deploys a Fabric network with Docker Compose. Because the 13 nodes are isolated within a Docker Compose network, the test network is not 14 configured to connect to other running fabric nodes. 15 16 **Note:** These instructions have been verified to work against the 17 latest stable Docker images and the pre-compiled setup utilities within the 18 supplied tar file. If you run these commands with images or tools from the 19 current master branch, it is possible that you will encounter errors. 20 21 ## Before you begin 22 23 Before you can run the test network, you need to clone the `fabric-samples` 24 repository and download the Fabric images. Make sure that that you have installed 25 the [Prerequisites](prereqs.html) and [Installed the Samples, Binaries and Docker Images](install.html). 26 27 ## Bring up the test network 28 29 You can find the scripts to bring up the network in the `test-network` directory 30 of the ``fabric-samples`` repository. Navigate to the test network directory by 31 using the following command: 32 ``` 33 cd fabric-samples/test-network 34 ``` 35 36 In this directory, you can find an annotated script, ``network.sh``, that stands 37 up a Fabric network using the Docker images on your local machine. You can run 38 ``./network.sh -h`` to print the script help text: 39 40 ``` 41 Usage: 42 network.sh <Mode> [Flags] 43 <Mode> 44 - 'up' - bring up fabric orderer and peer nodes. No channel is created 45 - 'up createChannel' - bring up fabric network with one channel 46 - 'createChannel' - create and join a channel after the network is created 47 - 'deployCC' - deploy the fabcar chaincode on the channel 48 - 'down' - clear the network with docker-compose down 49 - 'restart' - restart the network 50 51 Flags: 52 -ca <use CAs> - create Certificate Authorities to generate the crypto material 53 -c <channel name> - channel name to use (defaults to "mychannel") 54 -s <dbtype> - the database backend to use: goleveldb (default) or couchdb 55 -r <max retry> - CLI times out after certain number of attempts (defaults to 5) 56 -d <delay> - delay duration in seconds (defaults to 3) 57 -l <language> - the programming language of the chaincode to deploy: go (default), javascript, or java 58 -v <version> - chaincode version. Must be a round number, 1, 2, 3, etc 59 -i <imagetag> - the tag to be used to launch the network (defaults to "latest") 60 -verbose - verbose mode 61 network.sh -h (print this message) 62 63 Possible Mode and flags 64 network.sh up -ca -c -r -d -s -i -verbose 65 network.sh up createChannel -ca -c -r -d -s -i -verbose 66 network.sh createChannel -c -r -d -verbose 67 network.sh deployCC -l -v -r -d -verbose 68 69 Taking all defaults: 70 network.sh up 71 72 Examples: 73 network.sh up createChannel -ca -c mychannel -s couchdb -i 2.0.0-beta 74 network.sh createChannel -c channelName 75 network.sh deployCC -l javascript 76 ``` 77 78 From inside the `test-network` directory, run the following command to remove 79 any containers or artifacts from any previous runs: 80 ``` 81 ./network.sh down 82 ``` 83 84 You can then bring up the network by issuing the following command. You will 85 experience problems if you try to run the script from another directory: 86 ``` 87 ./network.sh up 88 ``` 89 90 This command creates a Fabric network that consists of two peer nodes, one 91 ordering node. No channel is created when you run `./network.sh up`, though we 92 will get there in a [future step](#creating-a-channel). If the command completes 93 successfully, the script will print out logs similar to these of the nodes being 94 created. 95 ``` 96 Creating network "net_test" with the default driver 97 Creating volume "net_orderer.example.com" with default driver 98 Creating volume "net_peer0.org1.example.com" with default driver 99 Creating volume "net_peer0.org2.example.com" with default driver 100 Creating orderer.example.com ... done 101 Creating peer0.org2.example.com ... done 102 Creating peer0.org1.example.com ... done 103 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 104 8d0c74b9d6af hyperledger/fabric-orderer:latest "orderer" 4 seconds ago Up Less than a second 0.0.0.0:7050->7050/tcp orderer.example.com 105 ea1cf82b5b99 hyperledger/fabric-peer:latest "peer node start" 4 seconds ago Up Less than a second 0.0.0.0:7051->7051/tcp peer0.org1.example.com 106 cd8d9b23cb56 hyperledger/fabric-peer:latest "peer node start" 4 seconds ago Up 1 second 7051/tcp, 0.0.0.0:9051->9051/tcp peer0.org2.example.com 107 ``` 108 109 If you don't get this result, jump down to [Troubleshooting](#troubleshooting) 110 for help on what might have gone wrong. By default, the network uses the 111 cryptogen tool to bring up the network. However, you can also 112 [bring up the network with Certificate Authorities](#bring-up-the-network-with-certificate-authorities). 113 114 ### The components of the test network 115 116 After your test network is deployed, you can take some time to examine its 117 components. Run the following command to list all of Docker containers that 118 are running on your machine. You should see the three nodes that were created by 119 the `network.sh` script: 120 ``` 121 docker ps -a 122 ``` 123 124 Each node and user that interacts with a Fabric network needs to belong to an 125 organization that is a network member. The group of organizations that are 126 members of a Fabric network are often referred to as the consortium. The test 127 network has two consortium members, Org1 and Org2. The network also includes one 128 orderer organization that maintains the ordering service of the network. 129 130 [Peers](peers/peers.html) are the fundamental components of any Fabric network. 131 Peers store the blockchain ledger and validate transactions before they are 132 committed to the ledger. Peers run the smart contracts that contain the business 133 logic that is used to manage the assets on the blockchain ledger. 134 135 Every peer in the network needs to belong to a member of the consortium. In the 136 test network, each organization operates one peer each, `peer0.org1.example.com` 137 and `peer0.org2.example.com`. 138 139 Every Fabric network also includes an [ordering service](orderer/ordering_service.html). 140 While peers validate transactions and add blocks of transactions to the 141 blockchain ledger, they do not decide on the order of transactions or include 142 them into new blocks. On a distributed network, peers may be running far away 143 from each other and not have a common view of when a transaction was created. 144 Coming to consensus on the order of transactions is a costly process that would 145 create overhead for the peers. 146 147 An ordering service allows peers to focus on validating transactions and 148 committing them to the ledger. After ordering nodes receive endorsed transactions 149 from clients, they come to consensus on the order of transactions and then add 150 them to blocks. The blocks are then distributed to peer nodes, which add the 151 blocks the blockchain ledger. Ordering nodes also operate the system channel 152 that defines the capabilities of a Fabric network, such as how blocks are made 153 and which version of Fabric that nodes can use. The system channel defines which 154 organizations are members of the consortium. 155 156 The sample network uses a single node Raft ordering service that is operated by 157 the ordering organization. You can see the ordering node running on your machine 158 as `orderer.example.com`. While the test network only uses a single node ordering 159 service, a real network would have multiple ordering nodes, operated by one or 160 multiple orderer organizations. The different ordering nodes would use the Raft 161 consensus algorithm to come to agreement on the order of transactions across 162 the network. 163 164 ## Creating a channel 165 166 Now that we have peer and orderer nodes running on our machine, we can use the 167 script to create a Fabric channel for transactions between Org1 and Org2. 168 Channels are a private layer of communication between specific network members. 169 Channels can be used only by organizations that are invited to the channel, and 170 are invisible to other members of the network. Each channel has a separate 171 blockchain ledger. Organizations that have been invited "join" their peers to 172 the channel to store the channel ledger and validate the transactions on the 173 channel. 174 175 You can use the `network.sh` script to create a channel between Org1 and Org2 176 and join their peers to the channel. Run the following command to create a 177 channel with the default name of `mychannel`: 178 ``` 179 ./network.sh createChannel 180 ``` 181 If the command was successful, you can see the following message printed in your 182 logs: 183 ``` 184 ========= Channel successfully joined =========== 185 ``` 186 187 You can also use the channel flag to create a channel with custom name. As an 188 example, the following command would create a channel named `channel1`: 189 ``` 190 ./network.sh createChannel -c channel1 191 ``` 192 193 The channel flag also allows you to create multiple channels by specifying 194 different channel names. After you create `mychannel` or `channel1`, you can use 195 the command below to create a second channel named `channel2`: 196 ``` 197 ./network.sh createChannel -c channel2 198 ``` 199 200 If you want to bring up the network and create a channel in a single step, you 201 can use the `up` and `createChannel` modes together: 202 ``` 203 ./network.sh up createChannel 204 ``` 205 206 ## Starting a chaincode on the channel 207 208 After you have created a channel, you can start using [smart contracts](smartcontract/smartcontract.html) to 209 interact with the channel ledger. Smart contracts contain the business logic 210 that governs assets on the blockchain ledger. Applications run by members of the 211 network can invoke smart contracts to create assets on the ledger, as well as 212 change and transfer those assets. Applications also query smart contracts to 213 read data on the ledger. 214 215 To ensure that transactions are valid, transactions created using smart contracts 216 typically need to be signed by multiple organizations to be committed to the 217 channel ledger. Multiple signatures are integral to the trust model of Fabric. 218 Requiring multiple endorsements for a transaction prevents one organization on 219 a channel from tampering with the ledger on their peer or using business logic 220 that was not agreed to. To sign a transaction, each organization needs to invoke 221 and execute the smart contract on their peer, which then signs the output of the 222 transaction. If the output is consistent and has been signed by enough 223 organizations, the transaction can be committed to the ledger. The policy that 224 specifies the set organizations on the channel that need to execute the smart 225 contract is referred to as the endorsement policy, which is set for each 226 chaincode as part of the chaincode definition. 227 228 In Fabric, smart contracts are deployed on the network in packages referred to 229 as chaincode. A Chaincode is installed on the peers of an organization and then 230 deployed to a channel, where it can then be used to endorse transactions and 231 interact with the blockchain ledger. Before a chaincode can be deployed to a 232 channel, the members of the channel need to agree on a chaincode definition that 233 establishes chaincode governance. When the required number of organizations 234 agree, the chaincode definition can be committed to the channel, and the 235 chaincode is ready to be used. 236 237 After you have used the `network.sh` to create a channel, you can start a 238 chaincode on the channel using the following command: 239 ``` 240 ./network.sh deployCC 241 ``` 242 The `deployCC` subcommand will install the **fabcar** chaincode on 243 ``peer0.org1.example.com`` and ``peer0.org2.example.com`` and then deploy 244 the chaincode on the channel specified using the channel flag (or `mychannel` 245 if no channel is specified). If are deploying a chaincode for the first time, the 246 script will install the chaincode dependencies. By default, The script installs 247 the Golang version of the fabcar chaincode. However, you can use the language 248 flag, `-l`, to install the Java or javascript versions of the chaincode. 249 250 After the **fabcar** chaincode definition has been committed to the channel, the 251 script initializes the chaincode by invoking the `init` function and then invokes 252 the chaincode to put an initial list of cars on the ledger. The script then 253 queries the chaincode to verify the that the data was added. If the chaincode was 254 installed, deployed, and invoked correctly, you should see the following list of 255 cars printed in your logs: 256 ``` 257 [{"Key":"CAR0", "Record":{"make":"Toyota","model":"Prius","colour":"blue","owner":"Tomoko"}},{"Key":"CAR1", "Record":{"make":"Ford","model":"Mustang","colour":"red","owner":"Brad"}},{"Key":"CAR2", "Record":{"make":"Hyundai","model":"Tucson","colour":"green","owner":"Jin Soo"}},{"Key":"CAR3", "Record":{"make":"Volkswagen","model":"Passat","colour":"yellow","owner":"Max"}},{"Key":"CAR4", "Record":{"make":"Tesla","model":"S","colour":"black","owner":"Adriana"}},{"Key":"CAR5", "Record":{"make":"Peugeot","model":"205","colour":"purple","owner":"Michel"}},{"Key":"CAR6", "Record":{"make":"Chery","model":"S22L","colour":"white","owner":"Aarav"}},{"Key":"CAR7", "Record":{"make":"Fiat","model":"Punto","colour":"violet","owner":"Pari"}},{"Key":"CAR8", "Record":{"make":"Tata","model":"Nano","colour":"indigo","owner":"Valeria"}},{"Key":"CAR9", "Record":{"make":"Holden","model":"Barina","colour":"brown","owner":"Shotaro"}}] 258 ===================== Query successful on peer0.org1 on channel 'mychannel' ===================== 259 ``` 260 261 ## Interacting with the network 262 263 After you bring up the test network, you can use the `peer` CLI to interact 264 with your network. The `peer` CLI allows you to invoke deployed smart contracts, 265 update channels, or install and deploy new smart contracts from the CLI. 266 267 Make sure that you are operating from the `test-network` directory. If you 268 followed the instructions to [install the Samples, Binaries and Docker Images](install.html), 269 You can find the `peer` binaries in the `bin` folder of the `fabric-samples` 270 repository. Use the following command to add those binaries to your CLI Path: 271 ``` 272 export PATH=${PWD}/../bin:${PWD}:$PATH 273 ``` 274 You also need to set the `FABRIC_CFG_PATH` to point to the `core.yaml` file in 275 the `fabric-samples` repository: 276 ``` 277 export FABRIC_CFG_PATH=$PWD/../config/ 278 ``` 279 You can now set the environment variables that allow you to operate the `peer` 280 CLI as Org1: 281 ``` 282 # Environment variables for Org1 283 284 export CORE_PEER_TLS_ENABLED=true 285 export CORE_PEER_LOCALMSPID="Org1MSP" 286 export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt 287 export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp 288 export CORE_PEER_ADDRESS=localhost:7051 289 ``` 290 291 The `CORE_PEER_TLS_ROOTCERT_FILE` and `CORE_PEER_MSPCONFIGPATH` environment 292 variables point to the Org1 crypto material in the `organizations` folder. 293 294 If you used `./network.sh deployCC` to install and start the fabcar chaincode, 295 you can now query the ledger from your CLI. Run the following command to get the 296 list of cars that were added to your channel ledger: 297 ``` 298 peer chaincode query -C mychannel -n fabcar -c '{"Args":["queryAllCars"]}' 299 ``` 300 301 If the command is successful, you can see the same list of cars that were printed 302 in the logs when you ran the script: 303 ``` 304 [{"Key":"CAR0", "Record":{"make":"Toyota","model":"Prius","colour":"blue","owner":"Tomoko"}},{"Key":"CAR1", "Record":{"make":"Ford","model":"Mustang","colour":"red","owner":"Brad"}},{"Key":"CAR2", "Record":{"make":"Hyundai","model":"Tucson","colour":"green","owner":"Jin Soo"}},{"Key":"CAR3", "Record":{"make":"Volkswagen","model":"Passat","colour":"yellow","owner":"Max"}},{"Key":"CAR4", "Record":{"make":"Tesla","model":"S","colour":"black","owner":"Adriana"}},{"Key":"CAR5", "Record":{"make":"Peugeot","model":"205","colour":"purple","owner":"Michel"}},{"Key":"CAR6", "Record":{"make":"Chery","model":"S22L","colour":"white","owner":"Aarav"}},{"Key":"CAR7", "Record":{"make":"Fiat","model":"Punto","colour":"violet","owner":"Pari"}},{"Key":"CAR8", "Record":{"make":"Tata","model":"Nano","colour":"indigo","owner":"Valeria"}},{"Key":"CAR9", "Record":{"make":"Holden","model":"Barina","colour":"brown","owner":"Shotaro"}}] 305 ``` 306 307 Chaincodes are invoked when a network member wants to transfer or change an 308 asset on the ledger. Use the following command to change the owner of a car on 309 the ledger by invoking the fabcar chaincode: 310 ``` 311 peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls true --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n fabcar --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":"changeCarOwner","Args":["CAR9","Dave"]}' 312 ``` 313 314 If the command is successful, you should see the following response: 315 ``` 316 2019-12-04 17:38:21.048 EST [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200 317 ``` 318 319 Because the endorsement policy for the fabcar chaincode requires the transaction 320 to be signed by Org1 and Org2, the chaincode invoke command needs to target both 321 `peer0.org1.example.com` and `peer0.org2.example.com` using the `--peerAddresses` 322 flag. Because TLS is enabled for the network, the command also needs to reference 323 the TLS certificate for each peer using the `--tlsRootCertFiles` flag. 324 325 After we invoke the chaincode, we can use another query to see how the invoke 326 changed the assets on the blockchain ledger. Since we already queried the Org1 327 peer, we can take this opportunity to query the chaincode running on the Org2 328 peer. Set the following environment variables to operate as Org2: 329 ``` 330 # Environment variables for Org2 331 332 export CORE_PEER_TLS_ENABLED=true 333 export CORE_PEER_LOCALMSPID="Org2MSP" 334 export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt 335 export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp 336 export CORE_PEER_ADDRESS=localhost:9051 337 ``` 338 339 You can now query the fabcar chaincode running on `peer0.org2.example.com`: 340 ``` 341 peer chaincode query -C mychannel -n fabcar -c '{"Args":["queryAllCars"]}' 342 ``` 343 344 The result will show that `"CAR9"` was transferred to Dave: 345 ``` 346 [{"Key":"CAR0", "Record":{"make":"Toyota","model":"Prius","colour":"blue","owner":"Tomoko"}},{"Key":"CAR1", "Record":{"make":"Ford","model":"Mustang","colour":"red","owner":"Brad"}},{"Key":"CAR2", "Record":{"make":"Hyundai","model":"Tucson","colour":"green","owner":"Jin Soo"}},{"Key":"CAR3", "Record":{"make":"Volkswagen","model":"Passat","colour":"yellow","owner":"Max"}},{"Key":"CAR4", "Record":{"make":"Tesla","model":"S","colour":"black","owner":"Adriana"}},{"Key":"CAR5", "Record":{"make":"Peugeot","model":"205","colour":"purple","owner":"Michel"}},{"Key":"CAR6", "Record":{"make":"Chery","model":"S22L","colour":"white","owner":"Aarav"}},{"Key":"CAR7", "Record":{"make":"Fiat","model":"Punto","colour":"violet","owner":"Pari"}},{"Key":"CAR8", "Record":{"make":"Tata","model":"Nano","colour":"indigo","owner":"Valeria"}},{"Key":"CAR9", "Record":{"make":"Holden","model":"Barina","colour":"brown","owner":"Dave"}}] 347 ``` 348 349 ## Bring down the network 350 351 When you are finished using the test network, you can bring down the network 352 with the following command: 353 ``` 354 ./network.sh down 355 ``` 356 357 The command will stop and remove the node and chaincode containers, delete the 358 organization crypto material, and remove the chaincode images from your Docker 359 Registry. The command also removes the channel artifacts and docker volumes from 360 previous runs, allowing you to run `./network.sh up` again if you encountered 361 any problems. 362 363 ## Bring up the network with Certificate Authorities 364 365 Hyperledger Fabric uses public key infrastructure (PKI) to verify the actions of 366 all network participants. Every node, network administrator, and user submitting 367 transactions need to have a public certificate and private key to verify their 368 identity. These identities need to have a valid root of trust, establishing 369 that the certificates and keys were issued by an organization that is a member 370 of the network. 371 372 The `network.sh` script must create all of the crypto material that is required 373 to deploy and operate the network before it creates the peer and ordering nodes. 374 375 By default, the script uses a tool called cryptogen to create the certificates 376 and keys. The tool is provided for development and testing, and can quickly 377 create the required crypto material for Fabric organizations with a valid root 378 of trust. When you run `./network.sh up`, you can see the cryptogen tool creating 379 the certificates and keys for Org1, Org2, and the Orderer Org. 380 381 ``` 382 creating Org1, Org2, and ordering service organization with crypto from 'cryptogen' 383 384 /Usr/fabric-samples/test-network/../bin/cryptogen 385 386 ########################################################## 387 ##### Generate certificates using cryptogen tool ######### 388 ########################################################## 389 390 ########################################################## 391 ############ Create Org1 Identities ###################### 392 ########################################################## 393 + cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations 394 org1.example.com 395 + res=0 396 + set +x 397 ########################################################## 398 ############ Create Org2 Identities ###################### 399 ########################################################## 400 + cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations 401 org2.example.com 402 + res=0 403 + set +x 404 ########################################################## 405 ############ Create Orderer Org Identities ############### 406 ########################################################## 407 + cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations 408 + res=0 409 + set +x 410 ``` 411 412 However, `network.sh` also provides the option to bring up the network using 413 Certificate Authorities (CAs). In a production network, each organization would 414 operate a CA (or multiple intermediate CAs) that creates the identities that 415 belong to their organization. All of the identities created by a CA run by the 416 organization would share the same root of trust. Although it takes more time to 417 run the test network using CAs than to use cryptogen, bringing up a network using 418 CAs can provide an introduction to a production network would be deployed. 419 Standing up the Fabric CAs also provides you with the ability to enroll 420 a client identity using the Fabric SDKs and create a certificate and private key 421 that can be used by your application. Both cryptogen and the Fabric CAs generate 422 the crypto material for each organization in the `organizations` folder. 423 424 If you would like to bring up a network using Fabric CAs, first run the following 425 command to bring down any running networks: 426 ``` 427 ./network.sh down 428 ``` 429 430 You can then bring up the network with the CA flag: 431 ``` 432 ./network.sh up -ca 433 ``` 434 435 After you issue the command, you can see the script bringing up three CAs, one 436 for each organization in the network. 437 ``` 438 ########################################################## 439 ##### Generate certificates using Fabric CA's ############ 440 ########################################################## 441 Creating network "net_default" with the default driver 442 Creating ca_org2 ... done 443 Creating ca_org1 ... done 444 Creating ca_orderer ... done 445 ``` 446 447 The script then uses the Fabric CA client to register the users that belong to 448 each organization and generate the certificates and keys for each identity. You 449 can find the commands that are used to set up the network in the `registerEnroll.sh` 450 script in the `organizations/fabric-ca` directory. To learn more about how you 451 would use the Fabric CA to deploy a Fabric network, visit the 452 [Fabric CA operations guide](https://hyperledger-fabric-ca.readthedocs.io/en/latest/operations_guide.html). 453 You can learn more about how Fabric uses PKI by visiting the [identity](identity/identity.html) and [membership](membership/membership.html) concept topics. 454 455 ## What's happening behind the scenes? 456 457 If you are interested in learning more about the sample network, you can 458 investigate the files and scripts in the `test-network` directory. The steps 459 below provide a guided tour of what happens when you issue the command of 460 `./network.sh up`. 461 462 - `./network.sh` creates the certificates and keys for two peer organizations 463 and the orderer organization. By default, the script uses the cryptogen tool 464 using the configuration files located in the `organizations/cryptogen` folder. 465 If you use the `-ca` flag to create Certificate Authorities, the script uses 466 Fabric CA server configuration files and `registerEnroll.sh` script located in 467 the `organizations/fabric-ca` folder. Both cryptogen and the Fabric CAs create 468 the crypto material and MSP folders for all three organizations in the 469 `organizations` folder. 470 471 - The script uses configtxgen tool to create the system channel genesis block. 472 Configtxgen consumes the `TwoOrgsOrdererGenesis` channel profile in the 473 `configtx/configtx.yaml` file to create the genesis block. The block is stored 474 in the `system-genesis-block` folder. 475 476 - Once the organization crypto material and the system channel genesis block have 477 been generated, the `network.sh` can bring up the nodes of the netwowrk. The 478 script uses the ``docker-compose-test-net.yaml`` file in the `docker` folder 479 to create the peer and orderer nodes. The `docker` folder also contains the 480 ``docker-compose-e2e.yaml`` file that brings up the nodes of the network 481 alongside three Fabric CAs. This file is meant to be used to run end-to-end 482 tests by the Fabric SDK. Refer to the [Node SDK](https://github.com/hyperledger/fabric-sdk-node) 483 repo for details on running these tests. 484 485 - If you use the `createChannel` subcommand, `./network.sh` runs the 486 `createChannel.sh` script in the `scripts` folder to create a channel 487 using the supplied channel name. The script uses the `configtx.yaml` file to 488 create the channel creation transaction, as well as two anchor peer update 489 transactions. The script uses the peer cli to create the channel, join 490 ``peer0.org1.example.com`` and ``peer0.org2.example.com`` to the channel, and 491 make both of the peers anchor peers. 492 493 - If you issue the `deployCC` command, `./network.sh` runs the ``deployCC.sh`` 494 script to install the **fabcar** chaincode on both peers and then define then 495 chaincode on the channel. Once the chaincode definition is committed to the 496 channel, the peer cli initializes the chainocde using the `Init` and invokes 497 the chaincode to put initial data on the ledger. 498 499 ## Troubleshooting 500 501 If you have any problems with the tutorial, review the following: 502 503 - You should always start your network fresh. You can use the following command 504 to remove the artifacts, crypto material, containers, volumes, and chaincode 505 images from previous runs: 506 ``` 507 ./network.sh down 508 ``` 509 You **will** see errors if you do not remove old containers, images, and 510 volumes. 511 512 - If you see Docker errors, first check your Docker version ([Prerequisites](prereqs.html)), 513 and then try restarting your Docker process. Problems with Docker are 514 oftentimes not immediately recognizable. For example, you may see errors 515 that are the result of your node not being able to access the crypto material 516 mounted within a container. 517 518 If problems persist, you can remove your images and start from scratch: 519 ``` 520 docker rm -f $(docker ps -aq) 521 docker rmi -f $(docker images -q) 522 ``` 523 524 - If you see errors on your create, approve, commit, invoke or query commands, 525 make sure you have properly updated the channel name and chaincode name. 526 There are placeholder values in the supplied sample commands. 527 528 - If you see the error below: 529 ``` 530 Error: Error endorsing chaincode: rpc error: code = 2 desc = Error installing chaincode code mycc:1.0(chaincode /var/hyperledger/production/chaincodes/mycc.1.0 exits) 531 ``` 532 533 You likely have chaincode images (e.g. ``dev-peer1.org2.example.com-fabcar-1.0`` or 534 ``dev-peer0.org1.example.com-fabcar-1.0``) from prior runs. Remove them and try 535 again. 536 ``` 537 docker rmi -f $(docker images | grep peer[0-9]-peer[0-9] | awk '{print $3}') 538 ``` 539 540 - If you see the below error: 541 542 ``` 543 [configtx/tool/localconfig] Load -> CRIT 002 Error reading configuration: Unsupported Config Type "" 544 panic: Error reading configuration: Unsupported Config Type "" 545 ``` 546 547 Then you did not set the ``FABRIC_CFG_PATH`` environment variable properly. The 548 configtxgen tool needs this variable in order to locate the configtx.yaml. Go 549 back and execute an ``export FABRIC_CFG_PATH=$PWD/configtx/configtx.yaml``, 550 then recreate your channel artifacts. 551 552 - If you see an error stating that you still have "active endpoints", then prune 553 your Docker networks. This will wipe your previous networks and start you with a 554 fresh environment: 555 ``` 556 docker network prune 557 ``` 558 559 You will see the following message: 560 ``` 561 WARNING! This will remove all networks not used by at least one container. 562 Are you sure you want to continue? [y/N] 563 ``` 564 Select ``y``. 565 566 - If you see an error similar to the following: 567 ``` 568 /bin/bash: ./scripts/createChannel.sh: /bin/bash^M: bad interpreter: No such file or directory 569 ``` 570 571 Ensure that the file in question (**createChannel.sh** in this example) is 572 encoded in the Unix format. This was most likely caused by not setting 573 ``core.autocrlf`` to ``false`` in your Git configuration (see 574 [Windows extras](prereqs.html#windows-extras)). There are several ways of fixing this. If you have 575 access to the vim editor for instance, open the file: 576 ``` 577 vim ./fabric-samples/test-network/scripts/createChannel.sh 578 ``` 579 580 Then change its format by executing the following vim command: 581 ``` 582 :set ff=unix 583 ``` 584 585 - If your orderer exits upon creation or if you see that the create channel 586 command fails due to an inability to connect to your ordering service, use 587 the `docker logs` command to read the logs from the ordering node. You may see 588 the following message: 589 ``` 590 PANI 007 [channel system-channel] config requires unsupported orderer capabilities: Orderer capability V2_0 is required but not supported: Orderer capability V2_0 is required but not supported 591 ``` 592 This occurs when you are trying to run the network using Fabric version 1.4.x 593 docker images. The test network needs to run using Fabric version 2.x. 594 595 If you continue to see errors, share your logs on the **fabric-questions** 596 channel on [Hyperledger Rocket Chat](https://chat.hyperledger.org/home) or on 597 [StackOverflow](https://stackoverflow.com/questions/tagged/hyperledger-fabric). 598 599 <!--- Licensed under Creative Commons Attribution 4.0 International License 600 https://creativecommons.org/licenses/by/4.0/ -->