介绍 (Introduction)
In this article, we introduce the fabric-config library and show how it can be used for channel configuration updates. Specifically, we will provide an example program that leverages the fabric-config library to make changes to block cutting parameters. You will find in this article explicit guidance on how to get started with the library and functions that you can include in your program so you can start using this library seamlessly in your next project.
在本文中,我们介绍了fabric-config库,并展示了如何将其用于通道配置更新。 具体来说,我们将提供一个示例程序,该程序利用fabric-config库更改块切割参数。 在本文中,您将找到有关如何开始使用可包含在程序中的库和函数的明确指导,以便可以在下一个项目中无缝使用该库。
通道配置概述 (Overview of channel configurations)
A Hyperledger Fabric network is made up of structures and processes that define how these structures interact with the blockchain network. In this context, structures include artifacts such as organizations, peers, identity credentials, ordering nodes, and certificate authorities among others.
Hyperledger Fabric网络由定义这些结构如何与区块链网络交互的结构和过程组成。 在这种情况下,结构包括工件,例如组织,对等方,身份凭证,订购节点和证书颁发机构等。
The data that identifies the structures and their corresponding processes (i.e. governing instructions for network interactions) are contained in channel configurations. These configurations are, in turn, found in blocks that have been committed to the ledger of a channel. Therefore, the process for modifying a channel configuration is referred to as a configuration update transaction. Concrete examples of channel configuration updates include some of the following common scenarios:
标识结构及其相应过程(即,用于网络交互的管理指令)的数据包含在通道配置中。 这些配置又可以在已提交给通道分类帐的块中找到。 因此,用于修改通道配置的过程称为配置更新事务。 通道配置更新的具体示例包括以下一些常见方案:
- Updating the maximum number of transactions that should appear within a block. 更新应该在一个区块中出现的最大事务数。
- Updating the amount of time to wait for additional transactions after the first transaction arrives before cutting a block. 在第一个交易到达之后,在切割区块之前,更新等待更多交易的时间。
- Updating the Raft ordering service parameters. 更新筏订购服务参数。
- Updating the signature requirements for a block to be considered valid. 更新被视为有效的块的签名要求。
- Adding a new organization to an existing channel. 将新组织添加到现有渠道。
- Adding a new organization to the consortium. 将新组织添加到联盟。
更新频道配置 (Updating channel configurations)
Until recently, the recommended approach for updating a channel configuration involved using the configtxlator and jq tools. The steps for using these tools when updating a channel configuration can be summarized as follows:
直到最近,使用configtxlator和jq工具进行更新通道配置的推荐方法。 在更新通道配置时使用这些工具的步骤可以概括如下:
1) Fetch the latest configuration block of a channel.
1)获取通道的最新配置块。
2) Decode the latest configuration block from protobuf format into JSON.
2)将最新的配置块从protobuf格式解码为JSON。
3) Remove unnecessary metadata from the JSON configuration block using jq.
3)使用jq从JSON配置块中删除不必要的元数据。
4) Create a copy of the JSON configuration block.
4)创建JSON配置块的副本。
5) Make the corresponding updates to the copied JSON configuration block (e.g. update the maximum number of transactions in a block).
5)对复制的JSON配置块进行相应的更新(例如,更新一个块中的最大事务数)。
6) Encode the JSON updated configuration block back to protobuf.
6)将JSON更新的配置块编码回protobuf。
7) Compute the difference between the two configuration protobufs (i.e. original configuration block and the updated configuration block). This results in a new config update protobuf which contains the delta.
7)计算两个配置协议(即原始配置块和更新后的配置块)之间的差异。 这将导致包含该增量的新配置更新协议。
8) Decode delta back into JSON.
8)将增量解码回JSON。
9) Add necessary header to JSON delta so it is wrapped in an envelope message using jq.
9)将必要的标头添加到JSON增量中,以便使用jq将其包装在信封消息中。
10) Encode JSON delta to protobuf.
10)将JSON增量编码为protobuf。
11) Sign the config update transaction.
11)签署配置更新事务。
12) Submit the config update transaction to the ordering service via a peer.
12)通过对等方将配置更新事务提交给订购服务。
Though the above approach works, it is quite tedious and error-prone. For instance, it is quite easy to forget to strip out the header (step 3) after decoding the latest configuration block or to add the header to the delta block (step 9). Also, step 5 is quite easy to mess up. While editing the JSON block either manually with a text editor [such as Visual Studio or Atom] or using jq, you could make the changes in the wrong section of the JSON document and/or introduce one or more typos. Also, while ideally, you should have a thorough understanding of the JSON schema before making any changes to the JSON block, the reality is that not everyone possesses this knowledge. Therefore, a different mechanism that is not error-prone and simplifies the process for updating a channel configuration is preferred. A much better approach would be one that allows you to use a type-safe and compiled language such as Go. In the next section, we introduce this new mechanism.
尽管上述方法可行,但它非常繁琐且容易出错。 例如,很容易忘记在解码最新的配置块后剥离标题(步骤3)或将标题添加到增量块(步骤9)。 而且,第5步很容易搞砸。 在使用文本编辑器(例如Visual Studio或Atom)或使用jq手动编辑JSON块时,可以在JSON文档的错误部分进行更改和/或引入一个或多个输入错误。 另外,理想情况下,在对JSON块进行任何更改之前,您应该对JSON模式有透彻的了解,但现实情况是,并不是每个人都拥有这一知识。 因此,优选不易出错并且简化用于更新信道配置的过程的不同机制。 一种更好的方法是允许您使用类型安全的 编译语言(例如Go)。 在下一节中,我们将介绍这种新机制。
It is also worth mentioning that the configtxlator tool should eventually be deprecated and later removed at some point in the future as consumers are encouraged to develop their own tooling utilizing the config update process detailed below. This is also another reason why you should start getting familiar with the newest mechanism for updating channel configurations.
还值得一提的是,由于鼓励消费者使用下面详细介绍的config update过程开发自己的工具,因此最终应弃用configtxlator工具,以后再将其删除。 这也是为什么您应该开始熟悉用于更新通道配置的最新机制的另一个原因。
Note: It is beyond the scope of this article to provide the low level details and instructions for using the configtxlator and jq tools. For complete details on this, see Updating a channel configur