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