Detailed analysis of Fabric, make a record

1. Overview of Hyperledger Fabric

Hyperledger Fabric is an open source project for enterprise-level customers led by IBM. Unlike public chains such as Bitcoin and Ethereum, nodes in the Hyperledger Fabric network must be authorized and authenticated before joining , thereby avoiding POW resource overhead and greatly improving transaction processing efficiency.

2. Basic concepts

  1. Ledger : The ledger in fabric is divided into two parts,Part is file-based storage, File-based storage meets the non-tamperable characteristics of the blockchain . This method of storage basically uses Merkle Tree . The entire storage method can only be added , not deleted or modified.The other part is to use the database for storageThis method is called world state in fabric , such as KV databases such as leveldb and couchdb. The advantage of using this type of database is that the database only stores the current latest value , which is convenient for business expansion, so that the current value can be found quickly. No need to traverse to find.

  2. Channel : Channel, private sub-network, the nodes in the channel jointly maintain the ledger to achieveData isolation and confidentiality. Each channel corresponds to a ledger, which is maintained by the peer that joins the channel. A peer can join multiple channels to maintain multiple ledger.

  3. Org : Orginazation, an organization that manages a series of members. There can be multiple organizations in a channel.

  4. Chaincode : Chaincode (smart contract), a program running in the node, providing business logic interfaces, and querying or updating the ledger .

  5. Endorse : endorsement, refers to oneThe process of returning a response after a node has executed a transaction and signed the result

  6. Ordering Service : Ordering service, which sorts transactions into blocks and broadcasts them to all nodes in the network.

  7. PKI : Public Key Infrastructure, a standard-compliant technology and specification that uses public key encryption technology to provide a secure basic platform for the development of e-commerce.

  8. MSP : Membership Service Provider, member management service, based on PKI implementation,Generate certificates for network members and manage identities

3. The consensus algorithm of Hyperledger Fabric Network

Since fabric is a distributed system, a consensus mechanism is needed toEnsure that each node saves the ledger in the same order state to achieve consistency. In the current version of fabric1.4, there are three consensus mechanisms, namely solo, kafka, and Raft . The transaction consensus includes three stages of processing: proposal stage, packaging stage and verification stage.
The fabric consensus is divided into three stages:
①Proposal stage : The client sends a transaction proposal to the transaction endorsement node, and the endorsement node returns the endorsement result and signature to the client after the transaction simulation is executed.
②Packaging stage : The client will endorse the result and The signature is handed over to the sorting node for sorting
③Verification phase : The sorting node generates blocks and broadcasts to the entire network. After receiving these blocks, the accounting node first verifies its correctness.Stored in the local ledger after verification

  1. Solo consensus mode
    Solo consensus mode means that there is only one sorting node in the network environment, and the messages sent from the peer node are sorted and generated by one sorting node; because the sorting service has only one sorting node serving all peer nodes, there is no high availability and Scalability, not suitable for production environment, usually used in development and test environment.

  2. Raft consensus model
    It is a crash fault tolerance (CFT) sorting service based on etcd. Raft follows the "leader and follower" model, in which each channel will elect a leader, and its decisions will be copied to followers. Compared with Kafka-based sorting services, Raft-based sorting services will become easier to set up and manage, and its design allows organizations around the world to become decentralized sorting service contribution nodes.
    See this for details

Four. Various nodes in Hyperledger Fabric

  1. Client node: The
    client must be connected to a peer node or ordering service node to communicate with the blockchain network. The client submits a transaction proposal to the endorser,Collect enough endorsements(It can be understood as a guarantee), after broadcasting the transaction proposal to the sorting service, sorting, and generating blocks.
  2. Peer node (Committer, Endorser, Leader, Anchor):
  • Commitment node (Committer) :All peer nodes are accounting nodes (committer), Responsible for verifying transactions in the ordering service node block, maintaining state and a copy of Ledger. Use of accounting nodesP2p data distribution based on Gossip, The node will regularly exchange information with other nodes. If a node fails during this process, the information of this node will be deleted from the surviving nodes. For the failed node, it will also periodically check whether it has been restored, and the restored node will be updated to the list of surviving nodes. If there is a newly added node, it can also be obtained through the exchange of node information, added to the survival list, and broadcast to other nodes . The committer node cannot be configured through the configuration file. You need to manually specify the relevant committer node when the current client or command line initiates a transaction request. There can be multiple accounting nodes.
  • Endorser : Some nodes will also execute transactions and sign and endorse the results, acting as an endorser. The endorsement node has a dynamic role and is bound to a specific chain code. Each chaincode will set an endorsement strategy when it is instantiated, specifying which nodes endorse the transaction before the transaction is valid. And only when the application initiates a transaction endorsement request to it, it is an endorsing node. Other times, it is an ordinary accounting node, which is only responsible for verifying transactions and accounting. The endorsement node cannot be specified through the configuration file, but is specified by the client that initiates the transaction request. There can be multiple endorsement nodes.
  • Leader : The peer node can also be the leader peer, which can communicate with the ordering service node orderer , and is responsible for obtaining the latest block from the ordering service node and synchronizing it within the organization. There can only be one master node in the entire organization.
  • Anchor : The peer node can also be an anchor peer. The anchor node is mainlyResponsible for information exchange on behalf of the organization and other organizations. Every organization has an anchor node, which is very important to the organization. If there is a problem with the anchor node, the current organization will lose contact with other organizations. The configuration information of the anchor node is configured in the configuration file configtx.yaml of the configtxgen module.
  1. Ordering service node orderer:
    receives transactions containing endorsement signatures, sorts unpackaged transactions to generate blocks, and broadcasts them to peer nodes. The ordering service provides atomic broadcasting to ensure that nodes on the same chain receive the same information and have the same logical sequence.
  2. CA (Certificate Authority) node: The
    CA node receives the registration application from the client and returns the registration password for the user to log in to obtain the identity certificate. All operations on the blockchain require user identity verification.
    Insert picture description here

V. Transaction Process

The following is the classic transaction process of fabric. All operations related to the update of account book data are completed based on this transaction process.
Insert picture description here

  1. Send transaction proposal: The
    application uses the API provided by the corresponding SDK (Node, Java, Python) to construct a transaction proposal and submit it to the corresponding endorsement node. The transaction proposal contains:
channelID:通道信息
chaincodeID:要调用的链码信息
timestamp:时间戳
sign:客户端的签名
txPayload:提交的事务本身包含的内容,包含两项:
operation:要调用的链码的函数及相应的参数
metadata:调用的相关属性
  1. The endorsement node simulates the execution of the transaction proposal:
    when receiving a message from the client, the endorsement nodeFirst verify the client's signature clientSig(Using MSP), thenSimulated transaction. The endorsing node will call the chain code to simulate the execution of the transaction proposal, and generate the transaction result including the response value and the read-write set (the read-write set is the main content recorded in the transaction). These executions will not update the ledger.
  2. Return proposal response: The
    endorsement node will endorse the read-write set, generate a proposal response (Proposal response) and return it to the application.
  3. Transaction ordering: The
    application generates a transaction based on the received proposal response and sends it to the ordering service node ( Orderer node ). The transaction request is submitted to the Ordering service node. The transaction will include the read/write set, endorsement signature and channel ID ; after the Orderer node receives the transaction request, it willNo need to check specific data in the transaction, It just receives transactions from all channels in the network,Sort them in chronological order and create transaction blocks. It is then broadcast to the leader nodes of all organizations in the same channel.
  4. Transaction verification and submission: The
    accounting node verifies the received block (whether the transaction message structure is correct, whether it is repeated, whether there is enough endorsement, the read-write set version),After passing the verification, write the result to the local ledger. Transactions that fail the verification will be marked as invalid (Invalid).
  5. Ledger update : every peer node willAppend the block to the channel chain,andFor each valid transaction , the write set will be committed to the current state database. Send an event to notify the client application that the transaction (call) has been immutably attached to the chain, and to notify whether the transaction is valid or invalid.

Guess you like

Origin blog.csdn.net/qq_40169189/article/details/109189972