1 thought on “Common consensus algorithm introduction”

  1. In the asynchronous system, the state needs to be replicated between the host to ensure that each host consensus consensus. In the asynchronous system, there may be faults between the host, so it is necessary to define the fault tolerance protocol in the default asynchronous network to ensure that each host reaches a safe and reliable state consensus.
    The consensus algorithm is actually a set of rules, setting a set of conditions to screen out a representative node. In the blockchain system, there are many such screening solutions, such as POW, POS, DPOS, etc. in the public chain. The public chain consensus algorithm cannot be provided. For such blockchain, traditional consistent consensus algorithms have become the first choice, such as PBFT, PAXOS, RAFT, etc.
    Catalog
    . BFT (Bayzing Ting Error)
    . PBFT (Practical Byzantine Mistake Etworthy Algorithm)
    3, PAXOS
    Fourth POW (workload certificate)
    6. POS (Certificate of Equity)
    Seven, DPOS (Certificate of Appointment of Railive Power)
    , Ripple
    Fast fault tolerance technology. Byzantine assumes that there are unpredictable behaviors of computers and networks due to hardware errors, network congestion or interruptions, and malicious attacks. Byzantine fault tolerance to handle this abnormal behavior and meet the specifications to be solved.
    The Byzantine error system is a system with n nodes. The entire system meets the following conditions for each request:
    ) All non -Byzantine nodes use the same input information to generate the same result; r;
    ) If the input information is correct, then all Hollying Treaty nodes must receive this information and calculate the corresponding results.
    The assumptions generally adopted by the Byzantine system include:
    1) The behavior of the Byzantine node can be arbitrarily, and the Byzantine nodes can be conspired together; ;
    3) The news of the nodes can be lost through asynchronous networks. The messages in the network may be lost, sequence and delay to reach, but most of the protocols assume that the message can be conveyed to the destination in a limited time; n 4) The third party can be sniffed between the information transmitted between the server, but it cannot tamper and the content of the information and the completeness of the information of the information.
    Byznatta error tolerance is lacking practicality due to its theoretical feasibility. In addition, additional clock synchronization mechanism is required. The complexity of the algorithm is also increased with the increase of the node.
    The actual Byzantine tolerance reduces the complexity of the operation of the Byzantine Agreement and decreases from the index level to the polynomial level.
    PBFT is a copy of the copy machine copy algorithm, that is, the service is modeling as a state machine, and the status machine replicates copy at different nodes of the distributed system. PBFT requires a joint state. Three basic protocols are needed, including consistency protocols, checkpoint protocols, and view replacement protocols.
    Consistency protocol. The consistency protocol contains at least several stages: requests, pre-prepares, and response, which may include interactive interaction, COMMIT and other stages.
    It PBFT communication mode, the request of each client needs to pass through 5 stages. Since the client cannot obtain any information about the operating status of the server from the server, whether the main node in the PBFT can only be monitored by the server. If the server cannot complete the client request for a period of time, the view replacement protocol will be triggered.
    The basic process of the entire protocol is as follows:
    1) The client sends a request to activate the service operation of the master node.
    2) When the main node receives the request, start the three -stage protocol to request the node broadcast from the node.
    [2.1] The serial number distribution stage, the master node assigns a serial number n, the broadcast serial number allocation message and the client's request message m, and the constructing pre-prepare message to each node;
    [2.2 2.2 2.2 ] In the interaction phase, receive Pre-Prepare messages from the node, broadcast prepare messages to other service nodes;
    [2.3] The sequence number confirmation phase, each node verify the requests and sequences in the view, and broadcast the Commit message to execute the receiving collection. The client request to the client and respond to the client.
    3) The client is waiting for the response from different nodes. If there is an M 1 response, the response is the result of the operation.
    PBFT is generally suitable for private ownership and alliance chains that require strong consistency. For example, PBFT is an optional consensus agreement in IBM -led blockchain super ledger projects. In the Fabric project, the consensus module is designed as insertable modules and supports consensus algorithms such as PBFT and RAFT.
    In some distributed scenarios, its assumptions do not need to consider Byzantine failure, but only deal with general crash failures. In this case, the use of Paxos and other agreements is more efficient. Essence PAXOS is a consistency algorithm based on message transmission and high fault tolerance characteristics.
    Paxos has three types of characters Proposer, Acceptor, and Learner. The main interaction processes are between Proposer and Acceptor. The algorithm process is divided into two stages:
    Phase 1
    a) PROPOSER sends Prepare messages to more than half of the accessor on the Internet
    b) Acceptor reciprocate promise message
    phase 2 r 2
    a) When there is enough accessor to reply to the promise message, the Proposer sends an access message
    b) Under normal circumstances, the Acceptor reply Accepts
    The flow chart is shown in the figure:
    Paxos protocol is used in WeChat The PAXOS protocol process per minute is billions of magnitude.
    PAXOS is a protocol that maintains the distributed system consistency of LAMPORT design. However, because Paxos is very complicated and it is difficult to understand, various implementation and variants have later appeared. Raft is a easier to understand consistency algorithm proposed by Stanford, which is intended to replace the PAXOS algorithm currently widely used.
    RAFT was originally a consensus algorithm used to manage copying logs. It is a strong agreement that reached a consensus under non -Byzantine failure. Raft realizes the consensus process as follows: First of all, select a leader. Leader receives the accounting request from the client, completes the bookkeeping operation, generates blocks, and copies it to other bookkeeping nodes. Leader has a complete management accounting right. For example, Leader can decide whether to accept new transaction records without considering other bookkeeping nodes. Leader may fail or lose contact with other nodes. At this time, a new leader is re -selected.
    In Raft, each node will be in one of the following three states:
    (1) Follower: All nodes start in the state of Follower. If the leader message is not received, it will become a candidate state;
    (2) Candidate: "Pull the votes" to other nodes, if most of the tickets are obtained, it will become a leader. This process is called Leader Election;
    (3) Leader: All modifications of the system will pass through the leader first. Each modification is written with a log entry. The process of Leader after receiving the modification request is as follows: This process is called log copy (log)
    ) Copy logs to all follower nodes
    ) 3) Notify all follower node logs to submit
    4) All follower also submits logs
    ) Now the entire system is in the same state
    RAFT stage is mainly divided into two, first of all, Leader elections The process, and then conduct normal operations on the basis of the elected leader, such as log replication and bookkeeping.
    (1) Leader election
    Is when Follower did not receive information from leaders during the election time, it was converted to the candidate state. In the RAFT system:
    1) Any server can become candidate Candidate, as long as it sends a request to election to other server Follower.
    ) If other servers agree, it will be OK. If in this process, there is a follower down and no request for request election. At this time, the candidate can choose themselves. As long as you reach most of the votes of N/2 1, the candidate can still become a leader.
    3) This candidate has become a leader leader. It can send instructions to voters, such as Follower, such as accounting.
    4) Notice of accounting by heartbeat message later.
    5) Once the leader collapses, there is one in the Follower as a candidate and issued an invitation election.
    6) After the consent of Follower, it became a leader and continued to undertake the guidance work of accounting.
    (2) Log replication
    The accounting steps are shown below:
    ) Assuming that the leader has been selected, then the client issues an additional log requirement;
    ) Leader Follower is required to follow his instructions and add this new log content to their respective diary;
    ) After most of the Follower server write the transaction records to the ledger, confirm the addition of successful and issue confirmation information;
    4) In the next heartbeat message, Leader will notify all Follower to update the project.
    For each new transaction record, repeat the above process.
    In this process, if a network communication failure occurs, so that the leader cannot access most Follower, then the leader can only update the Follower server that it can access normally. Because most server Follower has no leader, they will re -elected a candidate as a leader, and then this leader deal with the outside world as a representative. Most follower. When network communication is restored, the original leader becomes a follower. In the lost contact stage, any update of this old leader can not be regarded as confirmation. It must be rolled back and received new new updates of new leaders.
    In the decentralized ledger system, each node that adds this system must save a complete ledger, but each node cannot be allowed at the same time, because the node is in different environments and receives different information. At the same time, accounting will inevitably lead to inconsistent ledger. Therefore, the node decides that the node has the right to record.
    In the Bitcoin system, a round of computing power competitions every 10 minutes.
    The main features of the POW system are the asymmetry of calculation. The working side must do a certain difficulty to get a result, but the verification party can easily check whether the working side has done the corresponding work through the result. The requirements of this workload are to connect an integer value string called Nonce behind a string, and perform the SHA256 hash operation on the connected string. ) It starts with a number of 0. The verification is passed.
    The node in the Bitcoin network, if you want to generate a new block and write to the blockchain, you must solve the POW problem from the Bitcoin network. The three key elements are the workload proof function, block and difficulty value. The workload proof function is the calculation method of this question. The block determines the input data of this question. The difficulty value determines the calculation required for this question.
    (1) The workingload proof function is u003Cu style = "box-sizing: border-box;"> SHA256 u003C/u>
    Composition of trading list. The block head with a fixed length of 80 bytes is the input string used for the workload of Bitcoin.
    (2) The adjustment of difficulty occurs independently in each complete node. Every 2016 block, all nodes will automatically adjust the difficulty according to the unified formula. If the rate of blocks generate faster than 10 minutes, it will increase difficulty and slower than 10 minutes.
    Formulas can be summarized as: new difficulty value = old difficulty value × (the past 2016 block costs time/20160 minutes)
    The workload certificate requires a target value. Calculation formula for the target value of Bitcoin workload (target): target value = maximum target value/difficulty value
    The maximum target value is a constant value:

    The difficulty value is inverse. The achievement of Bitcoin's workload is that the block hash value calculated by the miners must be less than the target value.
    (3) Whether POW can solve the problem of Byzantine general
    Bitcoin's POW consensus algorithm is a probability of Byzantine Agreement (BA)
    At the time of 50%, the concept of mining is more difficult (in about 10 minutes) the concept of consistency in the Bitcoin network will increase with the number of confirmed blocks. However, when the dishonesty is a certain scale, even when it does not need to be close to 50%, the consensus algorithm of Bitcoin cannot guarantee correctness, that is, it cannot guarantee that most blocks are provided by honest nodes.
    The consensus algorithm of Bitcoin is not suitable for private ownership and alliance chain. The reason is that it is a final consistency consensus algorithm, not a strong consistency consensus algorithm. The second reason is that its consensus efficiency is low.
    The expansion knowledge: Consistency
    Strict consistency is that there is no failure in the system, and the communication between all nodes can be achieved without any time. At this time, the entire system is equivalent to a machine. It is impossible to achieve in reality.
    strong consistency. When the operation is updated in the distributed system, any multiple processes or threads will get the latest value.
    Ilains that the system does not guarantee that the system of subsequent processes or threads will return the latest updated value. After the system is successfully written, the latest value can be read immediately, and it will not be read for a long time. But it will guarantee after a certain time level (second) as much as possible. Can make the data be consistent.
    The ultimate consistency is a specific form of weak consistency. The system guarantees that without subsequent updates, the system finally returns the value of the last update operation. In other words, if the updated data is required after a period of time, it is the ultimate consistency.
    In the POS model of the equity certificate, there is a term called currency age. Each currency generates 1 currency every day. For example, you hold 100 dollars and hold a total of 30 days. Then, at this time, your currency age It is 3000. At this time, if you find a POS block, your currency age will be clear to 0. Every time you be cleared 365 years old, you will get 0.05 coins from the block (assuming that interest can be understood as an annual interest rate of 5%), then in this case, interest = 3000 * 5% / 365 = 0.41 Coins, this time is very interesting, with interest holdings.
    Percoin is the first currency of equity proof. , The mechanism of the equity of some coins combines the concept of randomization and currency age. The coins that are not used for at least 30 days can participate in the next block. Essence Once the equity of the currency is used to sign a block, the currency age will be clear to zero, so that it must be waited for at least 30 days to sign another block.
    Although the POS mechanism has taken into account the lack of POW, it will be selected according to the balance of equity, which will lead to greater power of the richest account, which may dominate the right to record. The emergence of the Delegated Proof of Stake (DPOS) is based on the deficiency of the POW mechanism and the POS mechanism.
    Bitshare is a type of crypto currency using the DPOS mechanism. The principle is that everyone who holds a special stock to vote, which generates 101 representatives. We can understand it as 101 super nodes or mining pools, and these 101 super nodes' rights are exactly equal equal to each other's rights are exactly equal equal of. If it means that they cannot fulfill their duties (when they are turn, they fail to generate blocks), they will be removed, and new super nodes will be selected to replace them.
    The concept of witnesses is introduced, and witnesses can generate blocks. Everyone holding Special stocks can vote for the witness. The first n (n is usually defined as 101) candidates of the total consent votes can be elected as a witness. Essence
    The testimonial list of witnesses is updated every maintenance cycle (1 day). The witness and then arranged randomly. Each witness has a permissions of 2 seconds in order to generate blocks. If the witnesses cannot generate the block at a given time, the block generates permissions to the witnesses corresponding to the next time film. Essence
    The Bit shares also designed another type of campaign to represent the campaign. The selected representatives have the privileges that propose to change the network parameters, including transaction costs, block size, witness costs and block interval. If most representatives agree, the holder has a two -week review period, and the representative can be dismissed during this period and abolished the changes proposed. This design ensures that there is no right to modify the parameters in the technology and the change of all network parameters. The consent of the holder must be obtained.
    Ripple (Ripple) is an open source payment agreement based on the Internet. In the Ripple network, the transaction is initiated by the client (application). The entire network.
    The main functions of the tracking node are distributing transaction information and responding to the client's ledger requests. In addition to all functions that contain the tracking nodes, the verification node can also add new account instance data to the ledger through the consensus protocol.
    Ripple consensus reached between the verification nodes. Each verification node is pre -configured with a trusted node list called UNL (Unique Node List). The nodes on the list can vote on the transaction.每隔几秒,Ripple网络将进行如下共识过程:rn 1)每个验证节点会不断收到从网络发送过来的交易,通过与本地账本数据验证后,不合法的交易直接丢弃,合法The transaction will summarize the Candidate Set. The trading candidate also includes transactions left over from the previous consensus process that cannot be confirmed.
    2) Each verification node sends its own transaction candidate to other verification nodes as a proposal.
    3) After receiving a proposal sent by other nodes, the verification node is not ignored by nodes from UNL; if it is a node from UNL, it will compare the transactions in the proposal and the local area of ​​the local area. The transaction candidate set, if there is the same transaction, the transaction will get a vote. In a certain period of time, when the transaction gets more than 50%of the votes, the transaction enters the next round. Without more than 50%of the transactions, it will stay for the next consensus process to confirm.
    4) Verification nodes are sent to other nodes with more than 50%of the transactions as the proposal, and at the same time increase the threshold value of the required votes to 60%, repeat steps 3), step 4), until the threshold reaches 80%.
    5) Verifying nodes are officially written in local ledger data that the 80%UNL node confirmed transaction is called the Last Closed Ledger, which is the state of the ledger at the end of the last (latest).
    It in Ripple's consensus algorithm, the identity of participating in the voting node is known in advance. The consensus algorithm is only suitable for the scenario of the chain. The Byzantine fault (BFT) capability of the Ripple consensus algorithm is (N-1)/5, that is, the Byzantine error in the entire network can tolerate the 20%of the nodes in the entire network without affecting the correct consensus.
    In the blockchain network, due to the different application scenarios, the designed goals are different. Different blockchain systems use different consensus algorithms. Generally speaking, in the case of private chain and alliance chain, there are strong requirements for consistency and correctness. Generally speaking, a strong consistency consensus algorithm should be adopted. In the case of public chain, consistency and correctness are usually 100 %, and the consensus algorithm of final consistency is usually used.
    The selection of consensus algorithms is highly related to the application scenario. The trusted environment uses PAXOS or RAFT. The alliance with licenses can use PBFT. Non -licensed chains can be POW, POS, Ripple consensus, etc. Free selection consensus mechanism.

Leave a Comment