github.com/yous1230/fabric@v2.0.0-beta.0.20191224111736-74345bee6ac2+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 1.4.0 74 network.sh createChannel -c channelName 75 network.sh deployCC -l node 76 ``` 77 78 From inside the `test-network` directory, you can bring up the network by issuing 79 the following command. You will experience problems if you try to run the script 80 from another directory: 81 ``` 82 ./network.sh up 83 ``` 84 85 This command creates a Fabric network that consists of two peer nodes, one 86 ordering node. No channel is created when you run `./network.sh up`, though we 87 will get there in a [future step](#creating-a-channel). If the command completes 88 successfully, the script will print out logs similar to these of the nodes being 89 created. 90 ``` 91 Creating network "net_test" with the default driver 92 Creating volume "net_orderer.example.com" with default driver 93 Creating volume "net_peer0.org1.example.com" with default driver 94 Creating volume "net_peer0.org2.example.com" with default driver 95 Creating orderer.example.com ... done 96 Creating peer0.org2.example.com ... done 97 Creating peer0.org1.example.com ... done 98 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 99 8d0c74b9d6af hyperledger/fabric-orderer:latest "orderer" 4 seconds ago Up Less than a second 0.0.0.0:7050->7050/tcp orderer.example.com 100 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 101 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 102 ``` 103 104 If you don't get this result, jump down to [Troubleshooting](#troubleshooting) 105 for help on what might have gone wrong. By default, the network uses the 106 cryptogen tool to bring up the network. However, you can also 107 [bring up the network with Certificate Authorities](#bring-up-the-network-with-certificate-authorities). 108 109 ### The components of the test network 110 111 After your test network is deployed, you can take some time to examine its 112 components. Run the following command to list all of Docker containers that 113 are running on your machine. You should see the three nodes that were created by 114 the `network.sh` script: 115 ``` 116 docker ps -a 117 ``` 118 119 Each node and user that interacts with a Fabric network needs to belong to an 120 organization that is a network member. The group of organizations that are 121 members of a Fabric network are often referred to as the consortium. The test 122 network has two consortium members, Org1 and Org2. The network also includes one 123 orderer organization that maintains the ordering service of the network. 124 125 [Peers](peers/peers.html) are the fundamental components of any Fabric network. 126 Peers store the blockchain ledger and validate transactions before they are 127 committed to the ledger. Peers run the smart contracts that contain the business 128 logic that is used to manage the assets on the blockchain ledger. 129 130 Every peer in the network needs to belong to a member of the consortium. In the 131 test network, each organization operates one peer each, `peer0.org1.example.com` 132 and `peer0.org2.example.com`. 133 134 Every Fabric network also includes an [ordering service](orderer/ordering_service.html). 135 While peers validate transactions and add blocks of transactions to the 136 blockchain ledger, they do not decide on the order of transactions or include 137 them into new blocks. On a distributed network, peers may be running far away 138 from each other and not have a common view of when a transaction was created. 139 Coming to consensus on the order of transactions is a costly process that would 140 create overhead for the peers. 141 142 An ordering service allows peers to focus on validating transactions and 143 committing them to the ledger. After ordering nodes receive endorsed transactions 144 from clients, they come to consensus on the order of transactions and then add 145 them to blocks. The blocks are then distributed to peer nodes, which add the 146 blocks the blockchain ledger. Ordering nodes also operate the system channel 147 that defines the capabilities of a Fabric network, such as how blocks are made 148 and which version of Fabric that nodes can use. The system channel defines which 149 organizations are members of the consortium. 150 151 The sample network uses a single node Raft ordering service that is operated by 152 the ordering organization. You can see the ordering node running on your machine 153 as `orderer.example.com`. While the test network only uses a single node ordering 154 service, a real network would have multiple ordering nodes, operated by one or 155 multiple orderer organizations. The different ordering nodes would use the Raft 156 consensus algorithm to come to agreement on the order of transactions across 157 the network. 158 159 ## Creating a channel 160 161 Now that we have peer and orderer nodes running on our machine, we can use the 162 script to create a Fabric channel for transactions between Org1 and Org2. 163 Channels are a private layer of communication between specific network members. 164 Channels can be used only by organizations that are invited to the channel, and 165 are invisible to other members of the network. Each channel has a separate 166 blockchain ledger. Organizations that have been invited "join" their peers to 167 the channel to store the channel ledger and validate the transactions on the 168 channel. 169 170 You can use the `network.sh` script to create a channel between Org1 and Org2 171 and join their peers to the channel. Run the following command to create a 172 channel with the default name of `mychannel`: 173 ``` 174 ./network.sh createChannel 175 ``` 176 If the command was successful, you can see the following message printed in your 177 logs: 178 ``` 179 ========= Channel successfully joined =========== 180 ``` 181 182 You can also use the channel flag to create a channel with custom name. As an 183 example, the following command would create a channel named `channel1`: 184 ``` 185 ./network.sh createChannel -c channel1 186 ``` 187 188 The channel flag also allows you to create multiple channels by specifying 189 different channel names. After you create `mychannel` or `channel1`, you can use 190 the command below to create a second channel named `channel2`: 191 ``` 192 ./network.sh createChannel -c channel2 193 ``` 194 195 If you want to bring up the network and create a channel in a single step, you 196 can use the `up` and `createChannel` modes together: 197 ``` 198 ./network.sh up createChannel 199 ``` 200 201 ## Starting a chaincode on the channel 202 203 After you have created a channel, you can start using [smart contracts](smartcontract/smartcontract.html) to 204 interact with the channel ledger. Smart contracts contain the business logic 205 that governs assets on the blockchain ledger. Applications run by members of the 206 network can invoke smart contracts to create assets on the ledger, as well as 207 change and transfer those assets. Applications also query smart contracts to 208 read data on the ledger. 209 210 To ensure that transactions are valid, transactions created using smart contracts 211 typically need to be signed by multiple organizations to be committed to the 212 channel ledger. Multiple signatures are integral to the trust model of Fabric. 213 Requiring multiple endorsements for a transaction prevents one organization on 214 a channel from tampering with the ledger on their peer or using business logic 215 that was not agreed to. To sign a transaction, each organization needs to invoke 216 and execute the smart contract on their peer, which then signs the output of the 217 transaction. If the output is consistent and has been signed by enough 218 organizations, the transaction can be committed to the ledger. The policy that 219 specifies the set organizations on the channel that need to execute the smart 220 contract is referred to as the endorsement policy, which is set for each 221 chaincode as part of the chaincode definition. 222 223 In Fabric, smart contracts are deployed on the network in packages referred to 224 as chaincode. A Chaincode is installed on the peers of an organization and then 225 deployed to a channel, where it can then be used to endorse transactions and 226 interact with the blockchain ledger. Before a chaincode can be deployed to a 227 channel, the members of the channel need to agree on a chaincode definition that 228 establishes chaincode governance. When the required number of organizations 229 agree, the chaincode definition can be committed to the channel, and the 230 chaincode is ready to be used. 231 232 After you have used the `network.sh` to create a channel, you can start a 233 chaincode on the channel using the following command: 234 ``` 235 ./network.sh deployCC 236 ``` 237 The `deployCC` subcommand will install the **fabcar** chaincode on 238 ``peer0.org1.example.com`` and ``peer0.org2.example.com`` and then deploy 239 the chaincode on the channel specified using the channel flag (or `mychannel` 240 if no channel is specified). By default, The script installs the Golang version 241 of the fabcar chaincode. However, you can use the language flag, `-l`, to install 242 the Java or javascript versions of the chaincode. 243 244 After the **fabcar** chaincode definition has been committed to the channel, the 245 script initializes the chaincode by invoking the `init` function and then invokes 246 the chaincode to put an initial list of cars on the ledger. The script then 247 queries the chaincode to verify the that the data was added. If the chaincode was 248 installed, deployed, and invoked correctly, you should see the following list of 249 cars printed in your logs: 250 ``` 251 [{"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"}}] 252 ===================== Query successful on peer0.org1 on channel 'mychannel' ===================== 253 ``` 254 255 ## Interacting with the network 256 257 After you bring up the test network, you can use the `peer` CLI to interact 258 with your network. The `peer` CLI allows you to invoke deployed smart contracts, 259 update channels, or install and deploy new smart contracts from the CLI. 260 261 Make sure that you are operating from the `test-network` directory. If you 262 followed the instructions to [install the Samples, Binaries and Docker Images](install.html), 263 You can find the `peer` binaries in the `bin` folder of the `fabric-samples` 264 repository. Use the following command to add those binaries to your CLI Path: 265 ``` 266 export PATH=${PWD}/../bin:${PWD}:$PATH 267 ``` 268 You also need to set the `FABRIC_CFG_PATH` to point to the `core.yaml` file in 269 the `fabric-samples` repository: 270 ``` 271 export FABRIC_CFG_PATH=$PWD/../config/ 272 ``` 273 You can now set the environment variables that allow you to operate the `peer` 274 CLI as Org1: 275 ``` 276 # Environment variables for Org1 277 278 export CORE_PEER_TLS_ENABLED=true 279 export CORE_PEER_LOCALMSPID="Org1MSP" 280 export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt 281 export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp 282 export CORE_PEER_ADDRESS=localhost:7051 283 ``` 284 285 The `CORE_PEER_TLS_ROOTCERT_FILE` and `CORE_PEER_MSPCONFIGPATH` environment 286 variables point to the Org1 crypto material in the `organizations` folder. 287 288 If you used `./network.sh deployCC` to install and start the fabcar chaincode, 289 you can now query the ledger from your CLI. Run the following command to get the 290 list of cars that were added to your channel ledger: 291 ``` 292 peer chaincode query -C mychannel -n fabcar -c '{"Args":["queryAllCars"]}' 293 ``` 294 295 If the command is successful, you can see the same list of cars that were printed 296 in the logs when you ran the script: 297 ``` 298 [{"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"}}] 299 ``` 300 301 Chaincodes are invoked when a network member wants to transfer or change an 302 asset on the ledger. Use the following command to change the owner of a car on 303 the ledger by invoking the fabcar chaincode: 304 ``` 305 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"]}' 306 ``` 307 308 If the command is successful, you should see the following response: 309 ``` 310 2019-12-04 17:38:21.048 EST [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200 311 ``` 312 313 Because the endorsement policy for the fabcar chaincode requires the transaction 314 to be signed by Org1 and Org2, any chaincode invoke using the peer binaries 315 needs to target both `peer0.org1.example.com` and `peer0.org1.example.com`. You 316 can pass the following values to your invoke commands to target both peers: 317 ``` 318 --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 319 ``` 320 321 The section above passes the endpoints of both peers to the `--peerAddresses` 322 flag, and provides the path to each peer's TLS certificate in the organizations 323 folder to the `--tlsRootCertFiles` flags. 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). You can learn more about how 453 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 :ref:`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 you continue to see errors, share your logs on the **fabric-questions** 586 channel on [Hyperledger Rocket Chat](https://chat.hyperledger.org/home) or on 587 [StackOverflow](https://stackoverflow.com/questions/tagged/hyperledger-fabric). 588 589 <!--- Licensed under Creative Commons Attribution 4.0 International License 590 https://creativecommons.org/licenses/by/4.0/ -->