最新内容会更新在主站深入浅出区块链社区

原文链接:Fabric1.0 交易流程

这篇文章对fabric的网络环境启动过程进行讲解,也就是我们上节讲到的启动测试fabric网络环境时运行network_setup.sh这个文件的执行流程

fabric网络环境启动过程详解

上一节我们讲到 fabric网络环境的启动测试,主要是使用 ./network_setup.sh up 这个命令,所以fabric网络环境启动的重点就在network_setup.sh这个文件中。接下来我们就分析一下network_setup.sh这个文件

network_setup.sh其中包括两个部分,一个是利用generateArtifacts.sh脚本文件配置组织关系和颁发证书、公/私钥、通道证书等,另一个是docker-compose-cli.yaml用于根据配置启动集群并测试chaincode的示例代码。下面是具体的流程图介绍:

![在这里插入图片描述](https://learnblockchain.cn/images/startup _process.png)

首先看下generateArtifacts.sh脚本文件,它包含三个函数,分别是:

  1. 1.generateCerts
  2. 该函数使用cryptogen工具根据crypto-config.yaml来生成公私钥和证书信息等。
  3. 2.replacePrivateKey
  4. docker-compose-e2e-template.yaml文档中的ca私钥替换成具体的私钥。
  5. 3.generateChannelArtifacts
  6. 使用configtxgen工具根据configtx.yaml文件来生成创世区块和通道相关信息,更新锚节点。

接着是docker-compose-cli.yaml文件

docker-compose-cli.yaml文件根据组织关系启动docker集群,并在cli容器中执行command命令运行./scripts/script.sh脚本文件。 那./scripts/script.sh脚本具体做了什么呢?

  1. 1.createChannel:创建channel
  2. 2. joinChannel:将每个peer节点加入channel
  3. 3. updateAnchorPeers:更新锚节点
  4. 4. installChaincode:部署chaincode
  5. 5. instantiateChaincode:初始化chaincode
  6. 6. chaincodeQuerychaincode查询

另外docker-compose-cli.yaml这个文件还有一个配置项是需要注意的地方,那就是:

  1. file: base/docker-compose-base.yaml

这里的docker-compose-base.yaml其实就是Orderer和peer的基础配置文件,包括指定端口等。

几个重要的配置文件

1.crypto-config.yaml

基于crypto-config.yaml(此文件在../fabric/examples/e2e_cli中)生成公、私钥和证书信息,并保存在crypto-config文件夹中。另外crypto-config.yaml还定义了组织成员以及组织下的peer节点个数。

crypto-config.yaml文件讲解:

字段Name和Domain就是关于这个组织的名字和域名,这主要是用于生成证书的时候,证书内会包含该信息。而Template.Count=2是说我们要生成2套公私钥和证书,一套是peer0.org1的,还有一套是peer1.org1的(也就指定了org中存在peer0和peer1两个节点)。最后Users.Count=1是说每个Template下面会有几个普通User(注意,Admin是Admin,不包含在这个计数中),这里配置了1,也就是说我们只需要一个普通用户User1@org1.example.com 我们可以根据实际需要调整这个配置文件,增删Org Users等。文件内容如下:

  1. # ---------------------------------------------------------------------------
  2. # Orderer
  3. # ---------------------------------------------------------------------------
  4. - Name: Orderer
  5. Domain: example.com
  6. # ---------------------------------------------------------------------------
  7. # "Specs" - See PeerOrgs below for complete description
  8. # ---------------------------------------------------------------------------
  9. Specs:
  10. - Hostname: orderer
  11. # ---------------------------------------------------------------------------
  12. # "PeerOrgs" - Definition of organizations managing peer nodes
  13. # ---------------------------------------------------------------------------
  14. PeerOrgs:
  15. # ---------------------------------------------------------------------------
  16. # Org1
  17. # ---------------------------------------------------------------------------
  18. - Name: Org1
  19. Domain: org1.example.com
  20. # ---------------------------------------------------------------------------
  21. # "Specs"
  22. # ---------------------------------------------------------------------------
  23. # Uncomment this section to enable the explicit definition of hosts in your
  24. # configuration. Most users will want to use Template, below
  25. #
  26. # Specs is an array of Spec entries. Each Spec entry consists of two fields:
  27. # - Hostname: (Required) The desired hostname, sans the domain.
  28. # - CommonName: (Optional) Specifies the template or explicit override for
  29. # the CN. By default, this is the template:
  30. #
  31. # "{{.Hostname}}.{{.Domain}}"
  32. #
  33. # which obtains its values from the Spec.Hostname and
  34. # Org.Domain, respectively.
  35. # ---------------------------------------------------------------------------
  36. # Specs:
  37. # - Hostname: foo # implicitly "foo.org1.example.com"
  38. # CommonName: foo27.org5.example.com # overrides Hostname-based FQDN set above
  39. # - Hostname: bar
  40. # - Hostname: baz
  41. # ---------------------------------------------------------------------------
  42. # "Template"
  43. # ---------------------------------------------------------------------------
  44. # Allows for the definition of 1 or more hosts that are created sequentially
  45. # from a template. By default, this looks like "peer%d" from 0 to Count-1.
  46. # You may override the number of nodes (Count), the starting index (Start)
  47. # or the template used to construct the name (Hostname).
  48. #
  49. # Note: Template and Specs are not mutually exclusive. You may define both
  50. # sections and the aggregate nodes will be created for you. Take care with
  51. # name collisions
  52. # ---------------------------------------------------------------------------
  53. Template:
  54. Count: 2
  55. # Start: 5
  56. # Hostname: {{.Prefix}}{{.Index}} # default
  57. # ---------------------------------------------------------------------------
  58. # "Users"
  59. # ---------------------------------------------------------------------------
  60. # Count: The number of user accounts _in addition_ to Admin
  61. # ---------------------------------------------------------------------------
  62. Users:
  63. Count: 1
  64. # ---------------------------------------------------------------------------
  65. # Org2: See "Org1" for full specification
  66. # ---------------------------------------------------------------------------
  67. - Name: Org2
  68. Domain: org2.example.com
  69. Template:
  70. Count: 2
  71. Users:
  72. Count: 1

注:

peer:

Fabric 网络中的节点,表现为一个运行着的docker容器。可以与网络中的其他peer进行通信,每个peer都在本地保留一份ledger的副本。它是org下的组织成员。

org:

一个组织,它可以由一个或多个peer组成。

Orderer :

联盟成员共享的中心化节点。用来对交易进行排序,是 Fabric 共识机制的重要组成部分。

2.configtx.yaml

基于configtx.yaml(此文件在../fabric/examples/e2e_cli中)生成创世区块和通道相关信息,并保存在channel-artifacts文件夹。还可以指定背书策略。

configtx.yaml文件讲解:

1.官方提供的examples/e2e_cli/configtx.yaml这个文件里面配置了由2个Org参与的Orderer共识配置TwoOrgsOrdererGenesis,以及由2个Org参与的Channel配置:TwoOrgsChannel。

2.另外我们可以在此文件的Orderer部分设置共识的算法是Solo还是Kafka,以及共识时区块大小,超时时间等,我们使用默认值即可,不用更改。而Peer节点的配置包含了MSP的配置,锚节点的配置。如果我们有更多的Org,或者有更多的Channel,那么就可以根据模板进行对应的修改。

3.Policies配置也要特别注意,该配置项定义了不同角色的权限,Reader,Writer以及Admin分别对应读,写,以及admin权限,读权限角色只能从别的peer节点同步账本而不能发起交易,只有writer定义项下的角色才拥有发起交易的也就是调用chaincode的invoke方法的权限(不一定都是invoke方案,只要涉及到chaincode中状态修改的方法,都只有拥有writer权限或admin权限的角色才能调用)。以该配置的Organizations配置下的Org1配置为例,"OR('Org1MSP.admin', 'Org1MSP.client')",表示org1的msp服务中的admin或者client角色拥有发起交易的权限。文件内容如下:

  1. # Copyright IBM Corp. All Rights Reserved.
  2. #
  3. # SPDX-License-Identifier: Apache-2.0
  4. #
  5. ---
  6. ################################################################################
  7. #
  8. # Profile
  9. #
  10. # - Different configuration profiles may be encoded here to be specified
  11. # as parameters to the configtxgen tool
  12. #
  13. ################################################################################
  14. Profiles:
  15. TwoOrgsOrdererGenesis:
  16. Orderer:
  17. <<: *OrdererDefaults
  18. Organizations:
  19. - *OrdererOrg
  20. Consortiums:
  21. SampleConsortium:
  22. Organizations:
  23. - *Org1
  24. - *Org2
  25. TwoOrgsChannel:
  26. Consortium: SampleConsortium
  27. Application:
  28. <<: *ApplicationDefaults
  29. Organizations:
  30. - *Org1
  31. - *Org2
  32. ################################################################################
  33. #
  34. # Section: Organizations
  35. #
  36. # - This section defines the different organizational identities which will
  37. # be referenced later in the configuration.
  38. #
  39. ################################################################################
  40. Organizations:
  41. # SampleOrg defines an MSP using the sampleconfig. It should never be used
  42. # in production but may be used as a template for other definitions
  43. - &OrdererOrg
  44. # DefaultOrg defines the organization which is used in the sampleconfig
  45. # of the fabric.git development environment
  46. Name: OrdererOrg
  47. # ID to load the MSP definition as
  48. ID: OrdererMSP
  49. # MSPDir is the filesystem path which contains the MSP configuration
  50. MSPDir: crypto-config/ordererOrganizations/example.com/msp
  51. - &Org1
  52. # DefaultOrg defines the organization which is used in the sampleconfig
  53. # of the fabric.git development environment
  54. Name: Org1MSP
  55. # ID to load the MSP definition as
  56. ID: Org1MSP
  57. MSPDir: crypto-config/peerOrganizations/org1.example.com/msp
  58. AnchorPeers:
  59. # AnchorPeers defines the location of peers which can be used
  60. # for cross org gossip communication. Note, this value is only
  61. # encoded in the genesis block in the Application section context
  62. - Host: peer0.org1.example.com
  63. Port: 7051
  64. - &Org2
  65. # DefaultOrg defines the organization which is used in the sampleconfig
  66. # of the fabric.git development environment
  67. Name: Org2MSP
  68. # ID to load the MSP definition as
  69. ID: Org2MSP
  70. MSPDir: crypto-config/peerOrganizations/org2.example.com/msp
  71. AnchorPeers:
  72. # AnchorPeers defines the location of peers which can be used
  73. # for cross org gossip communication. Note, this value is only
  74. # encoded in the genesis block in the Application section context
  75. - Host: peer0.org2.example.com
  76. Port: 7051
  77. ################################################################################
  78. #
  79. # SECTION: Orderer
  80. #
  81. # - This section defines the values to encode into a config transaction or
  82. # genesis block for orderer related parameters
  83. #
  84. ################################################################################
  85. Orderer: &OrdererDefaults
  86. # Orderer Type: The orderer implementation to start
  87. # Available types are "solo" and "kafka"
  88. OrdererType: solo
  89. Addresses:
  90. - orderer.example.com:7050
  91. # Batch Timeout: The amount of time to wait before creating a batch
  92. BatchTimeout: 2s
  93. # Batch Size: Controls the number of messages batched into a block
  94. BatchSize:
  95. # Max Message Count: The maximum number of messages to permit in a batch
  96. MaxMessageCount: 10
  97. # Absolute Max Bytes: The absolute maximum number of bytes allowed for
  98. # the serialized messages in a batch.
  99. AbsoluteMaxBytes: 98 MB
  100. # Preferred Max Bytes: The preferred maximum number of bytes allowed for
  101. # the serialized messages in a batch. A message larger than the preferred
  102. # max bytes will result in a batch larger than preferred max bytes.
  103. PreferredMaxBytes: 512 KB
  104. Kafka:
  105. # Brokers: A list of Kafka brokers to which the orderer connects
  106. # NOTE: Use IP:port notation
  107. Brokers:
  108. - 127.0.0.1:9092
  109. # Organizations is the list of orgs which are defined as participants on
  110. # the orderer side of the network
  111. Organizations:
  112. ################################################################################
  113. #
  114. # SECTION: Application
  115. #
  116. # - This section defines the values to encode into a config transaction or
  117. # genesis block for application related parameters
  118. #
  119. ################################################################################
  120. Application: &ApplicationDefaults
  121. # Organizations is the list of orgs which are defined as participants on
  122. # the application side of the network
  123. Organizations:

fabric网络环境启动过程详解的更多相关文章

  1. Linux启动过程详解(inittab、rc.sysinit、rcX.d、rc.local)

    启动第一步--加载BIOS 当你打开计算机电源,计算机会首先加载BIOS信息,BIOS信息是如此的重要,以至于计算机必须在最开始就找到它.这是因为BIOS中包含了CPU的相关信息.设备启动顺序信息.硬 ...

  2. Linux启动过程详解

    Linux启动过程详解 附上两张图,加深记忆 图1: 图2: 第一张图比较简洁明了,下面对第一张图的步骤进行详解: 加载BIOS 当你打开计算机电源,计算机会首先加载BIOS信息,BIOS信息是如此的 ...

  3. (转)Linux 开机引导和启动过程详解

    Linux 开机引导和启动过程详解 编译自:https://opensource.com/article/17/2/linux-boot-and-startup作者: David Both 原创:LC ...

  4. Android 核心分析 之八Android 启动过程详解

    Android 启动过程详解 Android从Linux系统启动有4个步骤: (1) init进程启动 (2) Native服务启动 (3) System Server,Android服务启动 (4) ...

  5. 【STM32H7教程】第13章 STM32H7启动过程详解

    完整教程下载地址:http://forum.armfly.com/forum.php?mod=viewthread&tid=86980 第13章       STM32H7启动过程详解 本章教 ...

  6. linux 开机启动过程详解

    Linux开机执行内核后会启动init进程,该进程根据runlevel(如x)执行/etc/rcx.d/下的程序,其下的程序是符号链接,真正的程序放在/etc/init.d/下.开机启动的程序(服务等 ...

  7. 转-Linux启动过程详解(inittab、rc.sysinit、rcX.d、rc.local)

    http://blog.chinaunix.net/space.php?uid=10167808&do=blog&id=26042   1)BIOS自检2)启动Grub/Lilo3)加 ...

  8. [转载] Linux启动过程详解-《别怕Linux编程》之八

    本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket.为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. = ...

  9. Linux启动过程详解 (转)

    启动第一步--加载BIOS当你打开计算机电源,计算机会首先加载BIOS信息,BIOS信息是如此的重要,以至于计算机必须在最开始就找到它.这是因为BIOS中包含了CPU的相关信息.设备启动顺序信息.硬盘 ...

随机推荐

  1. Java 关于密码处理的工具类[MD5编码][AES加密/解密]

    项目中又遇到了加密问题,又去翻了半天,然后做测试,干脆就把常用的两类小结一下. 1.第一种所谓的MD5加密 其实也不算加密,只是基于Hash算法的不可逆编码而已,等于说,一旦经过MD5处理,是不可能从 ...

  2. odoo二次开发 tips

    1.model属性 每个对象(即class)一般由字段(变量)和函数组成,每个对象对应着数据库中的一张表,驼峰命名方式 models.Model 基础模块,会根据字段和模型名在后台数据库生成对应得表文 ...

  3. 洛谷P4092 [HEOI2016/TJOI2016]树 并查集/树链剖分+线段树

    正解:并查集/树链剖分+线段树 解题报告: 传送门 感觉并查集的那个方法挺妙的,,,刚好又要复习下树剖了,所以就写个题解好了QwQ 首先说下并查集的方法趴QwQ 首先离线,读入所有操作,然后dfs遍历 ...

  4. airsim 无法打开包括文件corecrt.h

    原因: 显示无法打开包括文件corecrt.h.在网上找了很多方法,最后综合起来发现,这个问题网上很多人反映,应该是vs2015的一个BUG,如果是选择"从父级或项目默认设置继承" ...

  5. 绿色版mssql

    1.安装2008绿色版,缺少对应的企业管理器,安装官方版本的提示电脑没有重启(已经重启后) 2.选择一个可用版本的mssql,2000的可以用,MSSQL2000-HaoSQL,自带企业管理器和查询器

  6. C# xml数组的序列和反序列化

    先来看xml <?xml version="1.0"?> <root xmlns:xsi="http://www.w3.org/2001/XMLSche ...

  7. 开发流程(Vue)

    1.当你拿到一个需求时,先不要着急完成静态页面 2.重点观察数据结构,进行数据的分析,包括前端所需要的数据类型从而进行数据类型定义(如果是前后端分离的情况下,建议不要考虑前端数据和数据库的数据类型对应 ...

  8. linux 生成密钥,并向git服务器导入公钥

    1.      server1 上使用haieradmin用户 ,先清理之前的ssh登录记录,rm –rf ~/.ssh , 运行ssh-keygen –t rsa(只需回车下一步即可,无需输入任何密 ...

  9. mongodb 安装遇到问题:the domain,user name and/or password are incorrect.remember to use"." for the domain if the account is on the local machine

    安装mongoDB遇到如下问题:the domain,user name  and/or password are incorrect.remember to use"." for ...

  10. vue axios使用form-data的形式提交数据的问题

    vue axios使用form-data的形式提交数据vue axios request payload form data由于axios默认发送数据时,数据格式是Request Payload,而并 ...