[Reprint] Hyperledger Fabric learning One: Introduction

Hyperledger Fabric learning One: Introduction

https://www.jianshu.com/p/f971858b70f3?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

 

1, Hyperledger Profile

Hyperledger: super books, is the first business-oriented scenarios of books distributed platforms, including: Contribution IBM, Intel, Cisco, DAH, JP Morgan Chase, R3, including many technology and financial giants in banking, supply chain and other fields has been widely attention and development, now has more than 200 corporate members.

  • Hyperledger project:
    in December 2015, led by the flagship open source world organization Linux Foundation, 30 initial member companies jointly announced the establishment of joint projects Hyperledger.
    Its inception, IBM has contributed more than 40,000 lines of code that OpenBlockchain, Digital Asset contribution to the company and the developer-related resources, R3 contributed new financial transaction architecture, Inter also contributed code distributed books related.

As a joint project, made up of its sub-projects for different scenarios: including Fabric, Sawtooth, Iroha, BlockChain Explorer, Cello, indy, Composer, Burrow eight major top-level project.

  • Fabric: Enterprise Alliance is a project with a chain of access mechanism, which is the predecessor IBM contribution OpenBlockchain;

  • Sawtooth: it is a creation, deployment and operation of distributed books modular platform. It contains a new consensus algorithm, called the elapsed time proof (Proof of Elapsed Time, abbreviated PoET), for large-scale distributed validator group, consume minimal resources;

  • Iroha: the books are distributed to the technique is simple and easy design integration of a block chain framework project and infrastructure-type projects;

  • indy: Special equipment is a distributed books for the decentralized identity established, it provides the interoperability tools to create and use a separate digital identity-based block chain or other distributed books, the code base and can be reused components;

  • Burrow: is a support contract machine only licensed, burrow provides a modular block chain clients with a smart licensed contract interpreter that part based on Ethernet Square Virtual Machine (EVM) specification on ;

 
image.png

2, Fabric Introduction

Hyperledger Fabric is to provide a platform solution books distributed scheme aims to implement a generic permission block chain (Permissioned Chain) of the underlying frame, for application to different occasions, provide a modular architecture and scalable switch components, including consensus algorithm, encryption security, digital assets, contracts and intelligent identity authentication services.

Hyperledger Fabric is designed to support different modular components enable direct plug, and can adapt to complex economic and ecological systems in various scenes

Fabric overcomes the shortcomings of bitcoin chain and other public projects, such as low throughput, transaction disclosed no privacy, no final consensus algorithm uncertainties and inefficiencies and other problems, enabling users to easily develop business applications.

On the other hand, Fabric there are also shortcomings, such as v1.2 consensus algorithm does not yet support BFT type, there are limitations transaction concurrency control, the overall performance to be improved and so on.

3, Fabric scenarios

  • Business integration, the use of multi-block chain to expand the issuance of participants, so that the free flow of integration to attract users to consume again

  • Cross-border payment and settlement, reducing the cost of trust between the agency and reduce fees

  • Data as evidence, copyright protection, authentication data authenticity

4, Fabric Glossary

  • Member Services (Membership Services): members of the service used to authenticate on the block chain network license, authorization and identity management;

  • Sort by consensus or service (Ordering Service): confirmation of the transaction and sorted into block trade

  • Books (Ledger), a state of persistent trade

  • Node (the Node), a network entity, to maintain the container Ledger, execute the contract

  • SDK, and the block chains to interact with the network

5, Fabric chain code describes

chaincode (chain code) are deployed in network nodes Hyperledger fabric, it may be invoked for a program code that interacts with the books distributed, i.e. "smart contract" on narrow areas.

Chain codes are divided into users system and chain code chain code.

  • System chain code used to implement system-level functions, including the deployment of the system configuration, user chain code, upgrades, and signature verification strategies such as user transactions;

  • User chain code for implementing a user's applications, developers writing code chain applications, and deploy it in the network, the end-user through the client application calls the chain code interacting with a network node; chain code in VP (billing node, also called isolation sandbox the check node) (currently Docker container) is performed, by the respective protocol gRPC VP call and billing inquiry node;

6, fabric channel

 
image.png

The current channel into the channel system (System Channel) channels and applications (Application Channel). Sort node to the channel through the system channel management application, the user's transaction information transmitted through channel applications. For the average user, the channel refers to the application channel.

  • Channel concept
    channel is Fabric is very important concept, it is essentially a private atomic broadcast channel sorting node partitioning and management with the aim of the information channel isolation, making entity outside the channel can not access the information in the channel, in order to achieve the transaction privacy.

    An important requirement for commercial applications is a private transaction, for Fabric design the channel (Channel) to provide privacy between members. Channel is a communication channel between the independent members of the network, the transaction is sent in the channel only members belonging to the channel to be visible, and therefore can be regarded as a private communication channel, "subnet" Fabric of some members of the network.

  • Channel management
    channel ordering service by the management. In the creation of the channel, to define the organization and its members, the anchor node (anchor peer) nodes and ordering services, and a channel structure corresponding to the chain block generated simultaneously recording the books for the transaction, the initial configuration of the channel Creation block (first block) of information recorded in a block chain. Configure the information channel can be used to add a new configuration to block change.

    每个组织可有多个节点加入同一个通道,这些节点中可以指定一个锚节点(或多个锚节点做备份)。锚节点代表本组织与其他组织的节点交互,从而发现通道中的所有节点。另外,同一组织的节点会选举或指定主导节点( leading peer ),主导节点负责接收从排序服务发来的区块,然后转发给本组织的其他节点。主导节点可以通过特定的算法选出,因此保证了在节点数量不断变动的情况下仍能维持整个网络的稳定性。

    在 Fabric 的网络中,可能同时存在多个彼此隔离的通道,每个通道包含一条私有的区块链和一个私有账本,通道中可以实例化一个或多个链码,以操作区块链上的数据。由此可见,Fabric 是以通道为基础的多链多账本系统。

  • 通道创建
    通道由排序服务节点负责管理,同时该节点还负责排序通道中的交易。在通道中一般包含有若干成员(组织),若两个网络实体的身份证书能够追溯到同一个根CA,则认为这两个实体属于同一组织。此外,通道中的每个组织都会有一个或以上的“锚节点”,它负责与其他组织交换共享账本的数据。

    创建通道的时候定义了成员,只有通过成员MSP验证的实体,才能够加入到通道并访问通道数据。一个验证例子如下:

    Org1 是通道 mychannel 的成员之一,与 Org1 绑定的 MSP 标识为 Org1MSP,其代表的 CA 称为 CA1;若实体的 MSP 满足以下条件则认为实体有权限访问 mychannel 的数据:

    • 实体的MSP标识(ID)为 Org1MSP;
    • 实体身份证书的信任链源头为 CA1。

    实体只要满足通道中任意成员的 MSP 校验,则认为该实体有权限访问通道中的数据

  • 通道的配置

通道的配置信息都被打包到一个区块中,并存放在通道的共享账本中。该区块除了配置信息外不包含其他交易信息,称之为通道的配置区块(Configuration Block)。通道可以使用配置区块来更新配置,因此在账本中每新添加一个配置区块,通道就按照最新配置区块的定义来修改配置。

通道账本的首个区块一定是配置区块,也称为初始区块(Genesis Block)。

7、分布式账本

Fabric 里的数据以分布式账本的形式存储。账本由一系列有顺序和防篡改的记录组成,记录包含着数据的全部状态改变。账本中的数据项以键值对的形式存放,账本中所有的键值对构成了账本的状态,也称为“世界状态”( World State )。

每个通道中有唯一的账本,由通道中所有成员共同维护着这个账本,每个确认节点上都保存了它所属通道的账本的一个副本,因而是分布式账本。对账本的访问需要通过链码实现对账本键值对的增加、删除、更新和查询等的操作。

账本由区块链(File System)和状态数据库(Level DB)两部分组成。如下图所示,

 
image.png
  • 区块链,是一组不可更改的有序的区块(数据块),记录着全部交易的日志。每个区块中包含若干个交易的数据,不同区块所包含的交易数量可以不同。区块之间用哈希链( Hashed-link )关联:每个区块头包含该区块所有交易的哈希值,以及上一个区块头的哈希值。这样的链式架构可以确保每个区块的数据不可更改,以及每个区块之间的顺序关系不可更改。这个特点决定了区块链的区块只可以添加在链的尾部。

    区块链的数据块以文件形式(File System)保存在各个节点中。

  • 状态数据库,记录了账本中所有键值对的当前值,相当于对当前账本的交易日志做了索引。链码执行交易的时候需要读取账本的当前状态,从状态数据库可以迅速获取键值的最新状态。

    如果没有状态数据库,要获得某个键值时,需要遍历整个区块链中和该键值相关的交易,效率非常低,因此,读取状态数据库可以认为是快速定位和访问某个键值的方法。另外,当状态数据库出现故障的时候,可以通过遍历账本重新生成。

    当一个区块附加到区块链尾部的时候,如果区块中的有效交易修改了键值对,则会在状态数据库中作相应的更新,这样区块链和状态数据库始终保持一致。

    状态数据库原理上可以是各种键值数据库,Fabric 缺省使用的是 LevelDB ,也支持 CouchDB 的选项。CouchDB 除了支持键值数据之外,也支持 JSON 格式的文档模型,能够做复杂的查询。

Frabric 账本逻辑结构

 
image.png

8、Fabric网络模块

Fabric P2P算法用的是Gossip算法。

  • Gossip是一个带冗余的容错算法,更进一步 ,Gossip是一个最终一致性算法。虽然无法保证在某个时刻所有节点状态一致,但可以保证在 “最终” 所有节点一致, 但是 “最终” 是一个现实中存在,但理论上无法证明的时间点;

  • Gossip不要求节点知道所有其他节点,因此又具有去中心话的特点,节点之间完全对等,不需要任何的中心节点;

  • Gossip的缺点很明显,冗余通信会对网络带宽、CPU资源造成很大的负载,而这些负载又受限于通信频率,该频率又影响着算法收敛的速度;

 
image.png

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/11953458.html