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