github.com/kaituanwang/hyperledger@v2.0.1+incompatible/docs/source/network/network.md (about) 1 # Blockchain network 2 3 This topic will describe, **at a conceptual level**, how Hyperledger Fabric 4 allows organizations to collaborate in the formation of blockchain networks. If 5 you're an architect, administrator or developer, you can use this topic to get a 6 solid understanding of the major structure and process components in a 7 Hyperledger Fabric blockchain network. This topic will use a manageable worked 8 example that introduces all of the major components in a blockchain network. 9 10 After reading this topic and understanding the concept of policies, you will 11 have a solid understanding of the decisions that organizations need to make to 12 establish the policies that control a deployed Hyperledger Fabric network. 13 You'll also understand how organizations manage network evolution using 14 declarative policies -- a key feature of Hyperledger Fabric. In a nutshell, 15 you'll understand the major technical components of Hyperledger Fabric and the 16 decisions organizations need to make about them. 17 18 ## What is a blockchain network? 19 20 A blockchain network is a technical infrastructure that provides ledger and 21 smart contract (chaincode) services to applications. Primarily, smart contracts 22 are used to generate transactions which are subsequently distributed to every 23 peer node in the network where they are immutably recorded on their copy of the 24 ledger. The users of applications might be end users using client applications 25 or blockchain network administrators. 26 27 In most cases, multiple [organizations](../glossary.html#organization) come 28 together as a [consortium](../glossary.html#consortium) to form the network and 29 their permissions are determined by a set of [policies](../glossary.html#policy) 30 that are agreed by the consortium when the network is originally configured. 31 Moreover, network policies can change over time subject to the agreement of the 32 organizations in the consortium, as we'll discover when we discuss the concept 33 of *modification policy*. 34 35 ## The sample network 36 37 Before we start, let's show you what we're aiming at! Here's a diagram 38 representing the **final state** of our sample network. 39 40 Don't worry that this might look complicated! As we go through this topic, we 41 will build up the network piece by piece, so that you see how the organizations 42 R1, R2, R3 and R4 contribute infrastructure to the network to help form it. This 43 infrastructure implements the blockchain network, and it is governed by policies 44 agreed by the organizations who form the network -- for example, who can add new 45 organizations. You'll discover how applications consume the ledger and smart 46 contract services provided by the blockchain network. 47 48 ![network.structure](./network.diagram.1.png) 49 50 *Four organizations, R1, R2, R3 and R4 have jointly decided, and written into an 51 agreement, that they will set up and exploit a Hyperledger Fabric 52 network. R4 has been assigned to be the network initiator -- it has been given 53 the power to set up the initial version of the network. R4 has no intention to 54 perform business transactions on the network. R1 and R2 have a need for a 55 private communications within the overall network, as do R2 and R3. 56 Organization R1 has a client application that can perform business transactions 57 within channel C1. Organization R2 has a client application that can do similar 58 work both in channel C1 and C2. Organization R3 has a client application that 59 can do this on channel C2. Peer node P1 maintains a copy of the ledger L1 60 associated with C1. Peer node P2 maintains a copy of the ledger L1 associated 61 with C1 and a copy of ledger L2 associated with C2. Peer node P3 maintains a 62 copy of the ledger L2 associated with C2. The network is governed according to 63 policy rules specified in network configuration NC4, the network is under the 64 control of organizations R1 and R4. Channel C1 is governed according to the 65 policy rules specified in channel configuration CC1; the channel is under the 66 control of organizations R1 and R2. Channel C2 is governed according to the 67 policy rules specified in channel configuration CC2; the channel is under the 68 control of organizations R2 and R3. There is an ordering service O4 that 69 services as a network administration point for N, and uses the system channel. 70 The ordering service also supports application channels C1 and C2, for the 71 purposes of transaction ordering into blocks for distribution. Each of the four 72 organizations has a preferred Certificate Authority.* 73 74 ## Creating the Network 75 76 Let's start at the beginning by creating the basis for the network: 77 78 ![network.creation](./network.diagram.2.png) 79 80 *The network is formed when an orderer is started. In our example network, N, 81 the ordering service comprising a single node, O4, is configured according to a 82 network configuration NC4, which gives administrative rights to organization 83 R4. At the network level, Certificate Authority CA4 is used to dispense 84 identities to the administrators and network nodes of the R4 organization.* 85 86 We can see that the first thing that defines a **network, N,** is an **ordering 87 service, O4**. It's helpful to think of the ordering service as the initial 88 administration point for the network. As agreed beforehand, O4 is initially 89 configured and started by an administrator in organization R4, and hosted in R4. 90 The configuration NC4 contains the policies that describe the starting set of 91 administrative capabilities for the network. Initially this is set to only give 92 R4 rights over the network. This will change, as we'll see later, but for now R4 93 is the only member of the network. 94 95 ### Certificate Authorities 96 97 You can also see a Certificate Authority, CA4, which is used to issue 98 certificates to administrators and network nodes. CA4 plays a key role in our 99 network because it dispenses X.509 certificates that can be used to identify 100 components as belonging to organization R4. Certificates issued by CAs 101 can also be used to sign transactions to indicate that an organization endorses 102 the transaction result -- a precondition of it being accepted onto the 103 ledger. Let's examine these two aspects of a CA in a little more detail. 104 105 Firstly, different components of the blockchain network use certificates to 106 identify themselves to each other as being from a particular organization. 107 That's why there is usually more than one CA supporting a blockchain network -- 108 different organizations often use different CAs. We're going to use four CAs in 109 our network; one for each organization. Indeed, CAs are so important that 110 Hyperledger Fabric provides you with a built-in one (called *Fabric-CA*) to help 111 you get going, though in practice, organizations will choose to use their own 112 CA. 113 114 The mapping of certificates to member organizations is achieved by via 115 a structure called a 116 [Membership Services Provider (MSP)](../glossary.html#membership-services). 117 Network configuration NC4 uses a named 118 MSP to identify the properties of certificates dispensed by CA4 which associate 119 certificate holders with organization R4. NC4 can then use this MSP name in 120 policies to grant actors from R4 particular 121 rights over network resources. An example of such a policy is to identify the 122 administrators in R4 who can add new member organizations to the network. We 123 don't show MSPs on these diagrams, as they would just clutter them up, but they 124 are very important. 125 126 Secondly, we'll see later how certificates issued by CAs are at the heart of the 127 [transaction](../glossary.html#transaction) generation and validation process. 128 Specifically, X.509 certificates are used in client application 129 [transaction proposals](../glossary.html#proposal) and smart contract 130 [transaction responses](../glossary.html#response) to digitally sign 131 [transactions](../glossary.html#transaction). Subsequently the network nodes 132 who host copies of the ledger verify that transaction signatures are valid 133 before accepting transactions onto the ledger. 134 135 Let's recap the basic structure of our example blockchain network. There's a 136 resource, the network N, accessed by a set of users defined by a Certificate 137 Authority CA4, who have a set of rights over the resources in the network N as 138 described by policies contained inside a network configuration NC4. All of this 139 is made real when we configure and start the ordering service node O4. 140 141 ## Adding Network Administrators 142 143 NC4 was initially configured to only allow R4 users administrative rights over 144 the network. In this next phase, we are going to allow organization R1 users to 145 administer the network. Let's see how the network evolves: 146 147 ![network.admins](./network.diagram.2.1.png) 148 149 *Organization R4 updates the network configuration to make organization R1 an 150 administrator too. After this point R1 and R4 have equal rights over the 151 network configuration.* 152 153 We see the addition of a new organization R1 as an administrator -- R1 and R4 154 now have equal rights over the network. We can also see that certificate 155 authority CA1 has been added -- it can be used to identify users from the R1 156 organization. After this point, users from both R1 and R4 can administer the 157 network. 158 159 Although the orderer node, O4, is running on R4's infrastructure, R1 has shared 160 administrative rights over it, as long as it can gain network access. It means 161 that R1 or R4 could update the network configuration NC4 to allow the R2 162 organization a subset of network operations. In this way, even though R4 is 163 running the ordering service, and R1 has full administrative rights over it, R2 164 has limited rights to create new consortia. 165 166 In its simplest form, the ordering service is a single node in the network, and 167 that's what you can see in the example. Ordering services are usually 168 multi-node, and can be configured to have different nodes in different 169 organizations. For example, we might run O4 in R4 and connect it to O2, a 170 separate orderer node in organization R1. In this way, we would have a 171 multi-site, multi-organization administration structure. 172 173 We'll discuss the ordering service a little [later in this topic](#the-ordering-service), 174 but for now just think of the ordering service as an administration point which 175 provides different organizations controlled access to the network. 176 177 ## Defining a Consortium 178 179 Although the network can now be administered by R1 and R4, there is very little 180 that can be done. The first thing we need to do is define a consortium. This 181 word literally means "a group with a shared destiny", so it's an appropriate 182 choice for a set of organizations in a blockchain network. 183 184 Let's see how a consortium is defined: 185 186 ![network.consortium](./network.diagram.3.png) 187 188 *A network administrator defines a consortium X1 that contains two members, 189 the organizations R1 and R2. This consortium definition is stored in the 190 network configuration NC4, and will be used at the next stage of network 191 development. CA1 and CA2 are the respective Certificate Authorities for these 192 organizations.* 193 194 Because of the way NC4 is configured, only R1 or R4 can create new consortia. 195 This diagram shows the addition of a new consortium, X1, which defines R1 and R2 196 as its constituting organizations. We can also see that CA2 has been added to 197 identify users from R2. Note that a consortium can have any number of 198 organizational members -- we have just shown two as it is the simplest 199 configuration. 200 201 Why are consortia important? We can see that a consortium defines the set of 202 organizations in the network who share a need to **transact** with one another -- 203 in this case R1 and R2. It really makes sense to group organizations together if 204 they have a common goal, and that's exactly what's happening. 205 206 The network, although started by a single organization, is now controlled by a 207 larger set of organizations. We could have started it this way, with R1, R2 and 208 R4 having shared control, but this build up makes it easier to understand. 209 210 We're now going to use consortium X1 to create a really important part of a 211 Hyperledger Fabric blockchain -- **a channel**. 212 213 ## Creating a channel for a consortium 214 215 So let's create this key part of the Fabric blockchain network -- **a channel**. 216 A channel is a primary communications mechanism by which the members of a 217 consortium can communicate with each other. There can be multiple channels in a 218 network, but for now, we'll start with one. 219 220 Let's see how the first channel has been added to the network: 221 222 ![network.channel](./network.diagram.4.png) 223 224 *A channel C1 has been created for R1 and R2 using the consortium definition X1. 225 The channel is governed by a channel configuration CC1, completely separate to 226 the network configuration. CC1 is managed by R1 and R2 who have equal rights 227 over C1. R4 has no rights in CC1 whatsoever.* 228 229 The channel C1 provides a private communications mechanism for the consortium 230 X1. We can see channel C1 has been connected to the ordering service O4 but that 231 nothing else is attached to it. In the next stage of network development, we're 232 going to connect components such as client applications and peer nodes. But at 233 this point, a channel represents the **potential** for future connectivity. 234 235 Even though channel C1 is a part of the network N, it is quite distinguishable 236 from it. Also notice that organizations R3 and R4 are not in this channel -- it 237 is for transaction processing between R1 and R2. In the previous step, we saw 238 how R4 could grant R1 permission to create new consortia. It's helpful to 239 mention that R4 **also** allowed R1 to create channels! In this diagram, it 240 could have been organization R1 or R4 who created a channel C1. Again, note 241 that a channel can have any number of organizations connected to it -- we've 242 shown two as it's the simplest configuration. 243 244 Again, notice how channel C1 has a completely separate configuration, CC1, to 245 the network configuration NC4. CC1 contains the policies that govern the 246 rights that R1 and R2 have over the channel C1 -- and as we've seen, R3 and 247 R4 have no permissions in this channel. R3 and R4 can only interact with C1 if 248 they are added by R1 or R2 to the appropriate policy in the channel 249 configuration CC1. An example is defining who can add a new organization to the 250 channel. Specifically, note that R4 cannot add itself to the channel C1 -- it 251 must, and can only, be authorized by R1 or R2. 252 253 Why are channels so important? Channels are useful because they provide a 254 mechanism for private communications and private data between the members of a 255 consortium. Channels provide privacy from other channels, and from the network. 256 Hyperledger Fabric is powerful in this regard, as it allows organizations to 257 share infrastructure and keep it private at the same time. There's no 258 contradiction here -- different consortia within the network will have a need 259 for different information and processes to be appropriately shared, and channels 260 provide an efficient mechanism to do this. Channels provide an efficient 261 sharing of infrastructure while maintaining data and communications privacy. 262 263 We can also see that once a channel has been created, it is in a very real sense 264 "free from the network". It is only organizations that are explicitly specified 265 in a channel configuration that have any control over it, from this time forward 266 into the future. Likewise, any updates to network configuration NC4 from this 267 time onwards will have no direct effect on channel configuration CC1; for 268 example if consortia definition X1 is changed, it will not affect the members of 269 channel C1. Channels are therefore useful because they allow private 270 communications between the organizations constituting the channel. Moreover, the 271 data in a channel is completely isolated from the rest of the network, including 272 other channels. 273 274 As an aside, there is also a special **system channel** defined for use by the 275 ordering service. It behaves in exactly the same way as a regular channel, 276 which are sometimes called **application channels** for this reason. We don't 277 normally need to worry about this channel, but we'll discuss a little bit more 278 about it [later in this topic](#the-ordering-service). 279 280 ## Peers and Ledgers 281 282 Let's now start to use the channel to connect the blockchain network and the 283 organizational components together. In the next stage of network development, we 284 can see that our network N has just acquired two new components, namely a peer 285 node P1 and a ledger instance, L1. 286 287 ![network.peersledger](./network.diagram.5.png) 288 289 *A peer node P1 has joined the channel C1. P1 physically hosts a copy of the 290 ledger L1. P1 and O4 can communicate with each other using channel C1.* 291 292 Peer nodes are the network components where copies of the blockchain ledger are 293 hosted! At last, we're starting to see some recognizable blockchain components! 294 P1's purpose in the network is purely to host a copy of the ledger L1 for others 295 to access. We can think of L1 as being **physically hosted** on P1, but 296 **logically hosted** on the channel C1. We'll see this idea more clearly when we 297 add more peers to the channel. 298 299 A key part of a P1's configuration is an X.509 identity issued by CA1 which 300 associates P1 with organization R1. Once P1 is started, it can **join** channel 301 C1 using the orderer O4. When O4 receives this join request, it uses the channel 302 configuration CC1 to determine P1's permissions on this channel. For example, 303 CC1 determines whether P1 can read and/or write information to the ledger L1. 304 305 Notice how peers are joined to channels by the organizations that own them, and 306 though we've only added one peer, we'll see how there can be multiple peer 307 nodes on multiple channels within the network. We'll see the different roles 308 that peers can take on a little later. 309 310 ## Applications and Smart Contract chaincode 311 312 Now that the channel C1 has a ledger on it, we can start connecting client 313 applications to consume some of the services provided by workhorse of the 314 ledger, the peer! 315 316 Notice how the network has grown: 317 318 ![network.appsmartcontract](./network.diagram.6.png) 319 320 *A smart contract S5 has been installed onto P1. Client application A1 in 321 organization R1 can use S5 to access the ledger via peer node P1. A1, P1 and 322 O4 are all joined to channel C1, i.e. they can all make use of the 323 communication facilities provided by that channel.* 324 325 In the next stage of network development, we can see that client application A1 326 can use channel C1 to connect to specific network resources -- in this case A1 327 can connect to both peer node P1 and orderer node O4. Again, see how channels 328 are central to the communication between network and organization components. 329 Just like peers and orderers, a client application will have an identity that 330 associates it with an organization. In our example, client application A1 is 331 associated with organization R1; and although it is outside the Fabric 332 blockchain network, it is connected to it via the channel C1. 333 334 It might now appear that A1 can access the ledger L1 directly via P1, but in 335 fact, all access is managed via a special program called a smart contract 336 chaincode, S5. Think of S5 as defining all the common access patterns to the 337 ledger; S5 provides a well-defined set of ways by which the ledger L1 can 338 be queried or updated. In short, client application A1 has to go through smart 339 contract S5 to get to ledger L1! 340 341 Smart contracts can be created by application developers in each organization to 342 implement a business process shared by the consortium members. Smart contracts 343 are used to help generate transactions which can be subsequently distributed to 344 every node in the network. We'll discuss this idea a little later; it'll be 345 easier to understand when the network is bigger. For now, the important thing to 346 understand is that to get to this point two operations must have been performed 347 on the smart contract; it must have been **installed** on peers, and then 348 **defined** on a channel. 349 350 Hyperledger Fabric users often use the terms **smart contract** and 351 **chaincode** interchangeably. In general, a smart contract defines the 352 **transaction logic** that controls the lifecycle of a business object contained 353 in the world state. It is then packaged into a chaincode which is then deployed 354 to a blockchain network. Think of smart contracts as governing transactions, 355 whereas chaincode governs how smart contracts are packaged for deployment. 356 357 ### Installing a chaincode package 358 359 After a smart contract S5 has been developed, an administrator in organization 360 R1 must create a chaincode package and [install](../glossary.html#install) it 361 onto peer node P1. This is a straightforward operation; once completed, P1 has 362 full knowledge of S5. Specifically, P1 can see the **implementation** logic of 363 S5 -- the program code that it uses to access the ledger L1. We contrast this to 364 the S5 **interface** which merely describes the inputs and outputs of S5, 365 without regard to its implementation. 366 367 When an organization has multiple peers in a channel, it can choose the peers 368 upon which it installs smart contracts; it does not need to install a smart 369 contract on every peer. 370 371 ### Defining a chaincode 372 373 Although a chaincode is installed on the peers of individual organizations, it 374 is governed and operated in the scope of a channel. Each organization needs to 375 approve a **chaincode definition**, a set of parameters that establish how a 376 chaincode will be used on a channel. An organization must approve a chaincode 377 definition in order to use the installed smart contract to query the ledger 378 and endorse transactions. In our example, which only has a single peer node P1, 379 an administrator in organization R1 must approve a chaincode definition for S5. 380 381 A sufficient number of organizations need to approve a chaincode definition (A 382 majority, by default) before the chaincode definition can be committed to the 383 channel and used to interact with the channel ledger. Because the channel only 384 has one member, the administrator of R1 can commit the chaincode definition of 385 S5 to the channel C1. Once the definition has been committed, S5 can now be 386 [invoked](../glossary.html#invoke) by client application A1! 387 388 Note that although every component on the channel can now access S5, they are 389 not able to see its program logic. This remains private to those nodes who have 390 installed it; in our example that means P1. Conceptually this means that it's 391 the smart contract **interface** that is defined and committed to a channel, in 392 contrast to the smart contract **implementation** that is installed. To reinforce 393 this idea; installing a smart contract shows how we think of it being 394 **physically hosted** on a peer, whereas a smart contract that has been defined 395 on a channel shows how we consider it **logically hosted** by the channel. 396 397 ### Endorsement policy 398 399 The most important piece of information supplied within the chaincode definition 400 is the [endorsement policy](../glossary.html#endorsement-policy). It describes 401 which organizations must approve transactions before they will be accepted by other 402 organizations onto their copy of the ledger. In our sample network, transactions 403 can only be accepted onto ledger L1 if R1 or R2 endorse them. 404 405 Committing the chaincode definition to the channel places the endorsement policy 406 on the channel ledger; it enables it to be accessed by any member of the channel. 407 You can read more about endorsement policies in the [transaction flow topic](../txflow.html). 408 409 ### Invoking a smart contract 410 411 Once a smart contract has been installed on a peer node and defined on a 412 channel it can be [invoked](../glossary.html#invoke) by a client application. 413 Client applications do this by sending transaction proposals to peers owned by 414 the organizations specified by the smart contract endorsement policy. The 415 transaction proposal serves as input to the smart contract, which uses it to 416 generate an endorsed transaction response, which is returned by the peer node to 417 the client application. 418 419 It's these transactions responses that are packaged together with the 420 transaction proposal to form a fully endorsed transaction, which can be 421 distributed to the entire network. We'll look at this in more detail later For 422 now, it's enough to understand how applications invoke smart contracts to 423 generate endorsed transactions. 424 425 By this stage in network development we can see that organization R1 is fully 426 participating in the network. Its applications -- starting with A1 -- can access 427 the ledger L1 via smart contract S5, to generate transactions that will be 428 endorsed by R1, and therefore accepted onto the ledger because they conform to 429 the endorsement policy. 430 431 ## Network completed 432 433 Recall that our objective was to create a channel for consortium X1 -- 434 organizations R1 and R2. This next phase of network development sees 435 organization R2 add its infrastructure to the network. 436 437 Let's see how the network has evolved: 438 439 ![network.grow](./network.diagram.7.png) 440 441 *The network has grown through the addition of infrastructure from 442 organization R2. Specifically, R2 has added peer node P2, which hosts a copy of 443 ledger L1, and chaincode S5. R2 approves the same chaincode definition as R1. 444 P2 has also joined channel C1, as has application A2. A2 and P2 are identified 445 using certificates from CA2. All of this means that both applications A1 and A2 446 can invoke S5 on C1 either using peer node P1 or P2.* 447 448 We can see that organization R2 has added a peer node, P2, on channel C1. P2 449 also hosts a copy of the ledger L1 and smart contract S5. We can see that R2 has 450 also added client application A2 which can connect to the network via channel 451 C1. To achieve this, an administrator in organization R2 has created peer node 452 P2 and joined it to channel C1, in the same way as an administrator in R1. The 453 administrator also has to approve the same chaincode definition as R1. 454 455 We have created our first operational network! At this stage in network 456 development, we have a channel in which organizations R1 and R2 can fully 457 transact with each other. Specifically, this means that applications A1 and A2 458 can generate transactions using smart contract S5 and ledger L1 on channel C1. 459 460 ### Generating and accepting transactions 461 462 In contrast to peer nodes, which always host a copy of the ledger, we see that 463 there are two different kinds of peer nodes; those which host smart contracts 464 and those which do not. In our network, every peer hosts a copy of the smart 465 contract, but in larger networks, there will be many more peer nodes that do not 466 host a copy of the smart contract. A peer can only *run* a smart contract if it 467 is installed on it, but it can *know* about the interface of a smart contract by 468 being connected to a channel. 469 470 You should not think of peer nodes which do not have smart contracts installed 471 as being somehow inferior. It's more the case that peer nodes with smart 472 contracts have a special power -- to help **generate** transactions. Note that 473 all peer nodes can **validate** and subsequently **accept** or **reject** 474 transactions onto their copy of the ledger L1. However, only peer nodes with a 475 smart contract installed can take part in the process of transaction 476 **endorsement** which is central to the generation of valid transactions. 477 478 We don't need to worry about the exact details of how transactions are 479 generated, distributed and accepted in this topic -- it is sufficient to 480 understand that we have a blockchain network where organizations R1 and R2 can 481 share information and processes as ledger-captured transactions. We'll learn a 482 lot more about transactions, ledgers, smart contracts in other topics. 483 484 ### Types of peers 485 486 In Hyperledger Fabric, while all peers are the same, they can assume multiple 487 roles depending on how the network is configured. We now have enough 488 understanding of a typical network topology to describe these roles. 489 490 * [*Committing peer*](../glossary.html#commitment). Every peer node in a 491 channel is a committing peer. It receives blocks of generated transactions, 492 which are subsequently validated before they are committed to the peer 493 node's copy of the ledger as an append operation. 494 495 * [*Endorsing peer*](../glossary.html#endorsement). Every peer with a smart 496 contract *can* be an endorsing peer if it has a smart contract installed. 497 However, to actually *be* an endorsing peer, the smart contract on the peer 498 must be used by a client application to generate a digitally signed 499 transaction response. The term *endorsing peer* is an explicit reference to 500 this fact. 501 502 An endorsement policy for a smart contract identifies the 503 organizations whose peer should digitally sign a generated transaction 504 before it can be accepted onto a committing peer's copy of the ledger. 505 506 These are the two major types of peer; there are two other roles a peer can 507 adopt: 508 509 * [*Leader peer*](../glossary.html#leading-peer). When an organization has 510 multiple peers in a channel, a leader peer is a node which takes 511 responsibility for distributing transactions from the orderer to the other 512 committing peers in the organization. A peer can choose to participate in 513 static or dynamic leadership selection. 514 515 It is helpful, therefore to think of two sets of peers from leadership 516 perspective -- those that have static leader selection, and those with 517 dynamic leader selection. For the static set, zero or more peers can be 518 configured as leaders. For the dynamic set, one peer will be elected leader 519 by the set. Moreover, in the dynamic set, if a leader peer fails, then the 520 remaining peers will re-elect a leader. 521 522 It means that an organization's peers can have one or more leaders connected 523 to the ordering service. This can help to improve resilience and scalability 524 in large networks which process high volumes of transactions. 525 526 * [*Anchor peer*](../glossary.html#anchor-peer). If a peer needs to 527 communicate with a peer in another organization, then it can use one of the 528 **anchor peers** defined in the channel configuration for that organization. 529 An organization can have zero or more anchor peers defined for it, and an 530 anchor peer can help with many different cross-organization communication 531 scenarios. 532 533 Note that a peer can be a committing peer, endorsing peer, leader peer and 534 anchor peer all at the same time! Only the anchor peer is optional -- for all 535 practical purposes there will always be a leader peer and at least one 536 endorsing peer and at least one committing peer. 537 538 ### Adding organizations and peers to the channel 539 540 When R2 joins the channel, the organization must install smart contract S5 541 onto its peer node, P2. That's obvious -- if applications A1 or A2 wish to use 542 S5 on peer node P2 to generate transactions, it must first be present; 543 installation is the mechanism by which this happens. At this point, peer node P2 544 has a physical copy of the smart contract and the ledger; like P1, it can both 545 generate and accept transactions onto its copy of ledger L1. 546 547 R2 must approve the same chaincode definition as was approved by R1 in order to 548 use smart contract S5. Because the chaincode definition has already been 549 committed to the channel by organization R1, R2 can use the chaincode as soon as 550 the organization approves the chaincode definition and installs the chaincode 551 package. The commit transaction only needs to happen once. A new organization 552 can use the chaincode as soon as they approve the chaincode parameters agreed to 553 by other members of the channel. Because the approval of a chaincode definition 554 occurs at the organization level, R2 can approve the chaincode definition once 555 and join multiple peers to the channel with the chaincode package installed. 556 However, if R2 wanted to change the chaincode definition, both R1 and R2 would 557 need to approve a new definition for their organization, and then one of the 558 organizations would need to commit the definition to the channel. 559 560 In our network, we can see that channel C1 connects two client applications, two 561 peer nodes and an ordering service. Since there is only one channel, there is 562 only one **logical** ledger with which these components interact. Peer nodes P1 563 and P2 have identical copies of ledger L1. Copies of smart contract S5 will 564 usually be identically implemented using the same programming language, but 565 if not, they must be semantically equivalent. 566 567 We can see that the careful addition of peers to the network can help support 568 increased throughput, stability, and resilience. For example, more peers in a 569 network will allow more applications to connect to it; and multiple peers in an 570 organization will provide extra resilience in the case of planned or unplanned 571 outages. 572 573 It all means that it is possible to configure sophisticated topologies which 574 support a variety of operational goals -- there is no theoretical limit to how 575 big a network can get. Moreover, the technical mechanism by which peers within 576 an individual organization efficiently discover and communicate with each other -- 577 the [gossip protocol](../gossip.html#gossip-protocol) -- will accommodate a 578 large number of peer nodes in support of such topologies. 579 580 The careful use of network and channel policies allow even large networks to be 581 well-governed. Organizations are free to add peer nodes to the network so long 582 as they conform to the policies agreed by the network. Network and channel 583 policies create the balance between autonomy and control which characterizes a 584 de-centralized network. 585 586 ## Simplifying the visual vocabulary 587 588 We’re now going to simplify the visual vocabulary used to represent our sample 589 blockchain network. As the size of the network grows, the lines initially used 590 to help us understand channels will become cumbersome. Imagine how complicated 591 our diagram would be if we added another peer or client application, or another 592 channel? 593 594 That's what we're going to do in a minute, so before we do, let's simplify the 595 visual vocabulary. Here's a simplified representation of the network we've 596 developed so far: 597 598 ![network.vocabulary](./network.diagram.8.png) 599 600 *The diagram shows the facts relating to channel C1 in the network N as follows: 601 Client applications A1 and A2 can use channel C1 for communication with peers 602 P1 and P2, and orderer O4. Peer nodes P1 and P2 can use the communication 603 services of channel C1. Ordering service O4 can make use of the communication 604 services of channel C1. Channel configuration CC1 applies to channel C1.* 605 606 Note that the network diagram has been simplified by replacing channel lines 607 with connection points, shown as blue circles which include the channel number. 608 No information has been lost. This representation is more scalable because it 609 eliminates crossing lines. This allows us to more clearly represent larger 610 networks. We've achieved this simplification by focusing on the connection 611 points between components and a channel, rather than the channel itself. 612 613 ## Adding another consortium definition 614 615 In this next phase of network development, we introduce organization R3. We're 616 going to give organizations R2 and R3 a separate application channel which 617 allows them to transact with each other. This application channel will be 618 completely separate to that previously defined, so that R2 and R3 transactions 619 can be kept private to them. 620 621 Let's return to the network level and define a new consortium, X2, for R2 and 622 R3: 623 624 ![network.consortium2](./network.diagram.9.png) 625 626 *A network administrator from organization R1 or R4 has added a new consortium 627 definition, X2, which includes organizations R2 and R3. This will be used to 628 define a new channel for X2.* 629 630 Notice that the network now has two consortia defined: X1 for organizations R1 631 and R2 and X2 for organizations R2 and R3. Consortium X2 has been introduced in 632 order to be able to create a new channel for R2 and R3. 633 634 A new channel can only be created by those organizations specifically identified 635 in the network configuration policy, NC4, as having the appropriate rights to do 636 so, i.e. R1 or R4. This is an example of a policy which separates organizations 637 that can manage resources at the network level versus those who can manage 638 resources at the channel level. Seeing these policies at work helps us 639 understand why Hyperledger Fabric has a sophisticated **tiered** policy 640 structure. 641 642 In practice, consortium definition X2 has been added to the network 643 configuration NC4. We discuss the exact mechanics of this operation elsewhere in 644 the documentation. 645 646 ## Adding a new channel 647 648 Let's now use this new consortium definition, X2, to create a new channel, C2. 649 To help reinforce your understanding of the simpler channel notation, we've used 650 both visual styles -- channel C1 is represented with blue circular end points, 651 whereas channel C2 is represented with red connecting lines: 652 653 ![network.channel2](./network.diagram.10.png) 654 655 *A new channel C2 has been created for R2 and R3 using consortium definition X2. 656 The channel has a channel configuration CC2, completely separate to the network 657 configuration NC4, and the channel configuration CC1. Channel C2 is managed by 658 R2 and R3 who have equal rights over C2 as defined by a policy in CC2. R1 and 659 R4 have no rights defined in CC2 whatsoever.* 660 661 The channel C2 provides a private communications mechanism for the consortium 662 X2. Again, notice how organizations united in a consortium are what form 663 channels. The channel configuration CC2 now contains the policies that govern 664 channel resources, assigning management rights to organizations R2 and R3 over 665 channel C2. It is managed exclusively by R2 and R3; R1 and R4 have no power in 666 channel C2. For example, channel configuration CC2 can subsequently be updated 667 to add organizations to support network growth, but this can only be done by R2 668 or R3. 669 670 Note how the channel configurations CC1 and CC2 remain completely separate from 671 each other, and completely separate from the network configuration, NC4. Again 672 we're seeing the de-centralized nature of a Hyperledger Fabric network; once 673 channel C2 has been created, it is managed by organizations R2 and R3 674 independently to other network elements. Channel policies always remain separate 675 from each other and can only be changed by the organizations authorized to do so 676 in the channel. 677 678 As the network and channels evolve, so will the network and channel 679 configurations. There is a process by which this is accomplished in a controlled 680 manner -- involving configuration transactions which capture the change to these 681 configurations. Every configuration change results in a new configuration block 682 transaction being generated, and [later in this topic](#the-ordering-serivce), 683 we'll see how these blocks are validated and accepted to create updated network 684 and channel configurations respectively. 685 686 ### Network and channel configurations 687 688 Throughout our sample network, we see the importance of network and channel 689 configurations. These configurations are important because they encapsulate the 690 **policies** agreed by the network members, which provide a shared reference for 691 controlling access to network resources. Network and channel configurations also 692 contain **facts** about the network and channel composition, such as the name of 693 consortia and its organizations. 694 695 For example, when the network is first formed using the ordering service node 696 O4, its behaviour is governed by the network configuration NC4. The initial 697 configuration of NC4 only contains policies that permit organization R4 to 698 manage network resources. NC4 is subsequently updated to also allow R1 to manage 699 network resources. Once this change is made, any administrator from organization 700 R1 or R4 that connects to O4 will have network management rights because that is 701 what the policy in the network configuration NC4 permits. Internally, each node 702 in the ordering service records each channel in the network configuration, so 703 that there is a record of each channel created, at the network level. 704 705 It means that although ordering service node O4 is the actor that created 706 consortia X1 and X2 and channels C1 and C2, the **intelligence** of the network 707 is contained in the network configuration NC4 that O4 is obeying. As long as O4 708 behaves as a good actor, and correctly implements the policies defined in NC4 709 whenever it is dealing with network resources, our network will behave as all 710 organizations have agreed. In many ways NC4 can be considered more important 711 than O4 because, ultimately, it controls network access. 712 713 The same principles apply for channel configurations with respect to peers. In 714 our network, P1 and P2 are likewise good actors. When peer nodes P1 and P2 are 715 interacting with client applications A1 or A2 they are each using the policies 716 defined within channel configuration CC1 to control access to the channel C1 717 resources. 718 719 For example, if A1 wants to access the smart contract chaincode S5 on peer nodes 720 P1 or P2, each peer node uses its copy of CC1 to determine the operations that 721 A1 can perform. For example, A1 may be permitted to read or write data from the 722 ledger L1 according to policies defined in CC1. We'll see later the same pattern 723 for actors in channel and its channel configuration CC2. Again, we can see that 724 while the peers and applications are critical actors in the network, their 725 behaviour in a channel is dictated more by the channel configuration policy than 726 any other factor. 727 728 Finally, it is helpful to understand how network and channel configurations are 729 physically realized. We can see that network and channel configurations are 730 logically singular -- there is one for the network, and one for each channel. 731 This is important; every component that accesses the network or the channel must 732 have a shared understanding of the permissions granted to different 733 organizations. 734 735 Even though there is logically a single configuration, it is actually replicated 736 and kept consistent by every node that forms the network or channel. For 737 example, in our network peer nodes P1 and P2 both have a copy of channel 738 configuration CC1, and by the time the network is fully complete, peer nodes P2 739 and P3 will both have a copy of channel configuration CC2. Similarly ordering 740 service node O4 has a copy of the network configuration, but in a [multi-node 741 configuration](#the-ordering-service), every ordering service node will have its 742 own copy of the network configuration. 743 744 Both network and channel configurations are kept consistent using the same 745 blockchain technology that is used for user transactions -- but for 746 **configuration** transactions. To change a network or channel configuration, an 747 administrator must submit a configuration transaction to change the network or 748 channel configuration. It must be signed by the organizations identified in the 749 appropriate policy as being responsible for configuration change. This policy is 750 called the **mod_policy** and we'll [discuss it later](#changing-policy). 751 752 Indeed, the ordering service nodes operate a mini-blockchain, connected via the 753 **system channel** we mentioned earlier. Using the system channel ordering 754 service nodes distribute network configuration transactions. These transactions 755 are used to co-operatively maintain a consistent copy of the network 756 configuration at each ordering service node. In a similar way, peer nodes in an 757 **application channel** can distribute channel configuration transactions. 758 Likewise, these transactions are used to maintain a consistent copy of the 759 channel configuration at each peer node. 760 761 This balance between objects that are logically singular, by being physically 762 distributed is a common pattern in Hyperledger Fabric. Objects like network 763 configurations, that are logically single, turn out to be physically replicated 764 among a set of ordering services nodes for example. We also see it with channel 765 configurations, ledgers, and to some extent smart contracts which are installed 766 in multiple places but whose interfaces exist logically at the channel level. 767 It's a pattern you see repeated time and again in Hyperledger Fabric, and 768 enables Hyperledger Fabric to be both de-centralized and yet manageable at the 769 same time. 770 771 ## Adding another peer 772 773 Now that organization R3 is able to fully participate in channel C2, let's add 774 its infrastructure components to the channel. Rather than do this one component 775 at a time, we're going to add a peer, its local copy of a ledger, a smart 776 contract and a client application all at once! 777 778 Let's see the network with organization R3's components added: 779 780 ![network.peer2](./network.diagram.11.png) 781 782 *The diagram shows the facts relating to channels C1 and C2 in the network N as 783 follows: Client applications A1 and A2 can use channel C1 for communication 784 with peers P1 and P2, and ordering service O4; client applications A3 can use 785 channel C2 for communication with peer P3 and ordering service O4. Ordering 786 service O4 can make use of the communication services of channels C1 and C2. 787 Channel configuration CC1 applies to channel C1, CC2 applies to channel C2.* 788 789 First of all, notice that because peer node P3 is connected to channel C2, it 790 has a **different** ledger -- L2 -- to those peer nodes using channel C1. The 791 ledger L2 is effectively scoped to channel C2. The ledger L1 is completely 792 separate; it is scoped to channel C1. This makes sense -- the purpose of the 793 channel C2 is to provide private communications between the members of the 794 consortium X2, and the ledger L2 is the private store for their transactions. 795 796 In a similar way, the smart contract S6, installed on peer node P3, and defined 797 on channel C2, is used to provide controlled access to ledger L2. Application A3 798 can now use channel C2 to invoke the services provided by smart contract S6 to 799 generate transactions that can be accepted onto every copy of the ledger L2 in 800 the network. 801 802 At this point in time, we have a single network that has two completely separate 803 channels defined within it. These channels provide independently managed 804 facilities for organizations to transact with each other. Again, this is 805 de-centralization at work; we have a balance between control and autonomy. This 806 is achieved through policies which are applied to channels which are controlled 807 by, and affect, different organizations. 808 809 ## Joining a peer to multiple channels 810 811 In this final stage of network development, let's return our focus to 812 organization R2. We can exploit the fact that R2 is a member of both consortia 813 X1 and X2 by joining it to multiple channels: 814 815 ![network.multichannel](./network.diagram.12.png) 816 817 *The diagram shows the facts relating to channels C1 and C2 in the network N as 818 follows: Client applications A1 can use channel C1 for communication with peers 819 P1 and P2, and ordering service O4; client application A2 can use channel C1 820 for communication with peers P1 and P2 and channel C2 for communication with 821 peers P2 and P3 and ordering service O4; client application A3 can use channel 822 C2 for communication with peer P3 and P2 and ordering service O4. Ordering service O4 823 can make use of the communication services of channels C1 and C2. Channel 824 configuration CC1 applies to channel C1, CC2 applies to channel C2.* 825 826 We can see that R2 is a special organization in the network, because it is the 827 only organization that is a member of two application channels! It is able to 828 transact with organization R1 on channel C1, while at the same time it can also 829 transact with organization R3 on a different channel, C2. 830 831 Notice how peer node P2 has smart contract S5 installed for channel C1 and smart 832 contract S6 installed for channel C2. Peer node P2 is a full member of both 833 channels at the same time via different smart contracts for different ledgers. 834 835 This is a very powerful concept -- channels provide both a mechanism for the 836 separation of organizations, and a mechanism for collaboration between 837 organizations. All the while, this infrastructure is provided by, and shared 838 between, a set of independent organizations. 839 840 It is also important to note that peer node P2's behaviour is controlled very 841 differently depending upon the channel in which it is transacting. Specifically, 842 the policies contained in channel configuration CC1 dictate the operations 843 available to P2 when it is transacting in channel C1, whereas it is the policies 844 in channel configuration CC2 that control P2's behaviour in channel C2. 845 846 Again, this is desirable -- R2 and R1 agreed the rules for channel C1, whereas 847 R2 and R3 agreed the rules for channel C2. These rules were captured in the 848 respective channel policies -- they can and must be used by every 849 component in a channel to enforce correct behaviour, as agreed. 850 851 Similarly, we can see that client application A2 is now able to transact on 852 channels C1 and C2. And likewise, it too will be governed by the policies in 853 the appropriate channel configurations. As an aside, note that client 854 application A2 and peer node P2 are using a mixed visual vocabulary -- both 855 lines and connections. You can see that they are equivalent; they are visual 856 synonyms. 857 858 ### The ordering service 859 860 The observant reader may notice that the ordering service node appears to be a 861 centralized component; it was used to create the network initially, and connects 862 to every channel in the network. Even though we added R1 and R4 to the network 863 configuration policy NC4 which controls the orderer, the node was running on 864 R4's infrastructure. In a world of de-centralization, this looks wrong! 865 866 Don't worry! Our example network showed the simplest ordering service 867 configuration to help you understand the idea of a network administration point. 868 In fact, the ordering service can itself too be completely de-centralized! We 869 mentioned earlier that an ordering service could be comprised of many individual 870 nodes owned by different organizations, so let's see how that would be done in 871 our sample network. 872 873 Let's have a look at a more realistic ordering service node configuration: 874 875 ![network.finalnetwork2](./network.diagram.15.png) 876 877 *A multi-organization ordering service. The ordering service comprises ordering 878 service nodes O1 and O4. O1 is provided by organization R1 and node O4 is 879 provided by organization R4. The network configuration NC4 defines network 880 resource permissions for actors from both organizations R1 and R4.* 881 882 We can see that this ordering service completely de-centralized -- it runs in 883 organization R1 and it runs in organization R4. The network configuration 884 policy, NC4, permits R1 and R4 equal rights over network resources. Client 885 applications and peer nodes from organizations R1 and R4 can manage network 886 resources by connecting to either node O1 or node O4, because both nodes behave 887 the same way, as defined by the policies in network configuration NC4. In 888 practice, actors from a particular organization *tend* to use infrastructure 889 provided by their home organization, but that's certainly not always the case. 890 891 ### De-centralized transaction distribution 892 893 As well as being the management point for the network, the ordering service also 894 provides another key facility -- it is the distribution point for transactions. 895 The ordering service is the component which gathers endorsed transactions 896 from applications and orders them into transaction blocks, which are 897 subsequently distributed to every peer node in the channel. At each of these 898 committing peers, transactions are recorded, whether valid or invalid, and their 899 local copy of the ledger updated appropriately. 900 901 Notice how the ordering service node O4 performs a very different role for the 902 channel C1 than it does for the network N. When acting at the channel level, 903 O4's role is to gather transactions and distribute blocks inside channel C1. It 904 does this according to the policies defined in channel configuration CC1. In 905 contrast, when acting at the network level, O4's role is to provide a management 906 point for network resources according to the policies defined in network 907 configuration NC4. Notice again how these roles are defined by different 908 policies within the channel and network configurations respectively. This should 909 reinforce to you the importance of declarative policy based configuration in 910 Hyperledger Fabric. Policies both define, and are used to control, the agreed 911 behaviours by each and every member of a consortium. 912 913 We can see that the ordering service, like the other components in Hyperledger 914 Fabric, is a fully de-centralized component. Whether acting as a network 915 management point, or as a distributor of blocks in a channel, its nodes can be 916 distributed as required throughout the multiple organizations in a network. 917 918 ### Changing policy 919 920 Throughout our exploration of the sample network, we've seen the importance of 921 the policies to control the behaviour of the actors in the system. We've only 922 discussed a few of the available policies, but there are many that can be 923 declaratively defined to control every aspect of behaviour. These individual 924 policies are discussed elsewhere in the documentation. 925 926 Most importantly of all, Hyperledger Fabric provides a uniquely powerful policy 927 that allows network and channel administrators to manage policy change itself! 928 The underlying philosophy is that policy change is a constant, whether it occurs 929 within or between organizations, or whether it is imposed by external 930 regulators. For example, new organizations may join a channel, or existing 931 organizations may have their permissions increased or decreased. Let's 932 investigate a little more how change policy is implemented in Hyperledger 933 Fabric. 934 935 They key point of understanding is that policy change is managed by a 936 policy within the policy itself. The **modification policy**, or 937 **mod_policy** for short, is a first class policy within a network or channel 938 configuration that manages change. Let's give two brief examples of how we've 939 **already** used mod_policy to manage change in our network! 940 941 The first example was when the network was initially set up. At this time, only 942 organization R4 was allowed to manage the network. In practice, this was 943 achieved by making R4 the only organization defined in the network configuration 944 NC4 with permissions to network resources. Moreover, the mod_policy for NC4 945 only mentioned organization R4 -- only R4 was allowed to change this 946 configuration. 947 948 We then evolved the network N to also allow organization R1 to administer the 949 network. R4 did this by adding R1 to the policies for channel creation and 950 consortium creation. Because of this change, R1 was able to define the 951 consortia X1 and X2, and create the channels C1 and C2. R1 had equal 952 administrative rights over the channel and consortium policies in the network 953 configuration. 954 955 R4 however, could grant even more power over the network configuration to R1! R4 956 could add R1 to the mod_policy such that R1 would be able to manage change of 957 the network policy too. 958 959 This second power is much more powerful than the first, because R1 now has 960 **full control** over the network configuration NC4! This means that R1 can, in 961 principle remove R4's management rights from the network. In practice, R4 would 962 configure the mod_policy such that R4 would need to also approve the change, or 963 that all organizations in the mod_policy would have to approve the change. 964 There's lots of flexibility to make the mod_policy as sophisticated as it needs 965 to be to support whatever change process is required. 966 967 This is mod_policy at work -- it has allowed the graceful evolution of a basic 968 configuration into a sophisticated one. All the time this has occurred with the 969 agreement of all organization involved. The mod_policy behaves like every other 970 policy inside a network or channel configuration; it defines a set of 971 organizations that are allowed to change the mod_policy itself. 972 973 We've only scratched the surface of the power of policies and mod_policy in 974 particular in this subsection. It is discussed at much more length in the policy 975 topic, but for now let's return to our finished network! 976 977 ## Network fully formed 978 979 Let's recap what our network looks like using a consistent visual vocabulary. 980 We've re-organized it slightly using our more compact visual syntax, because it 981 better accommodates larger topologies: 982 983 ![network.finalnetwork2](./network.diagram.14.png) 984 985 *In this diagram we see that the Fabric blockchain network consists of two 986 application channels and one ordering channel. The organizations R1 and R4 are 987 responsible for the ordering channel, R1 and R2 are responsible for the blue 988 application channel while R2 and R3 are responsible for the red application 989 channel. Client applications A1 is an element of organization R1, and CA1 is 990 it's certificate authority. Note that peer P2 of organization R2 can use the 991 communication facilities of the blue and the red application channel. Each 992 application channel has its own channel configuration, in this case CC1 and 993 CC2. The channel configuration of the system channel is part of the network 994 configuration, NC4.* 995 996 We're at the end of our conceptual journey to build a sample Hyperledger Fabric 997 blockchain network. We've created a four organization network with two channels 998 and three peer nodes, with two smart contracts and an ordering service. It is 999 supported by four certificate authorities. It provides ledger and smart contract 1000 services to three client applications, who can interact with it via the two 1001 channels. Take a moment to look through the details of the network in the 1002 diagram, and feel free to read back through the topic to reinforce your 1003 knowledge, or go to a more detailed topic. 1004 1005 ### Summary of network components 1006 1007 Here's a quick summary of the network components we've discussed: 1008 1009 * [Ledger](../glossary.html#ledger). One per channel. Comprised of the 1010 [Blockchain](../glossary.html#block) and 1011 the [World state](../glossary.html#world-state) 1012 * [Smart contract](../glossary.html#smart-contract) (aka chaincode) 1013 * [Peer nodes](../glossary.html#peer) 1014 * [Ordering service](../glossary.html#ordering-service) 1015 * [Channel](../glossary.html#channel) 1016 * [Certificate Authority](../glossary.html#hyperledger-fabric-ca) 1017 1018 ## Network summary 1019 1020 In this topic, we've seen how different organizations share their infrastructure 1021 to provide an integrated Hyperledger Fabric blockchain network. We've seen how 1022 the collective infrastructure can be organized into channels that provide 1023 private communications mechanisms that are independently managed. We've seen 1024 how actors such as client applications, administrators, peers and orderers are 1025 identified as being from different organizations by their use of certificates 1026 from their respective certificate authorities. And in turn, we've seen the 1027 importance of policy to define the agreed permissions that these organizational 1028 actors have over network and channel resources.