Is Paxos a blockchain communication protocol
e to the high network delay in peer-to-peer network, the transaction order observed by each node can not be completely consistent. Therefore, the blockchain system needs to design a mechanism to reach a consensus on the sequence of transactions that occur in the same time. This algorithm to reach consensus on the order of transactions in a time window is called consensus mechanism
-- chainknow
The way in which people keep accounts together is also known as "distributed" or "decentralized", because everyone keeps accounts, and the accuracy of the account book is determined by the program algorithm, not by an authoritative organization
this is the blockchain, the core is finished, blockchain is so simple, a common account book
six core algorithms of blockchain Technology:
blockchain core algorithm 1: Byzantine agreement
the story of Byzantine is like this: the Byzantine Empire has great wealth, and the surrounding 10 neighbors have been around for a long time, but the Byzantine walls stand tall and firm, No single neighbor has been able to successfully invade. Any single neighbor's invasion will fail, and at the same time, it may be invaded by other nine neighbors. Byzantine Empire's defense ability is so strong that at least more than half of its ten neighbors attack at the same time before it can be broken. However, if one or several of the neighbors agree to attack together, but betray in the actual process, then the invaders may be annihilated. So each side was careful and could not easily trust its neighbors. This is the question of Byzantine Generals
blockchain core algorithm 2: asymmetric encryption technology
in the above Byzantine agreement, if several of the 10 generals send messages at the same time, it is bound to cause confusion in the system, resulting in different attack time schemes and inconsistent actions. Anyone can send the message of attack, but who will send it? In fact, it only needs to add a cost, that is, only one node can spread information in a period of time. When a node sends a unified attack message, each node must sign and seal to confirm its identity when receiving the message from the initiator
blockchain core algorithm 3: fault tolerance problem
we assume that in this network, messages may be lost, damaged, delayed and sent repeatedly, and the order of receiving is inconsistent with the order of sending. In addition, the behavior of nodes can be arbitrary: they can join or exit the network at any time, they can discard messages, forge messages, stop working and so on, and they may also have all kinds of human or non-human failures. Our algorithm provides fault tolerance for consensus system composed of consensus nodes, which includes both security and availability, and is suitable for any network environment
blockchain core algorithm 4: Paxos algorithm (consistency algorithm)
the problem solved by Paxos algorithm is how a distributed system can reach an agreement on a certain value (decision). A typical scenario is that in a distributed database system, if the initial state of each node is consistent, and each node performs the same operation sequence, then they can finally get a consistent state. In order to ensure that each node executes the same command sequence, it is necessary to execute a "consistency algorithm" on each instruction to ensure that the instructions seen by each node are consistent. A general consistency algorithm can be applied in many scenarios, which is an important problem in distributed computing. There are two models of node communication: shared memory and message passing. Paxos algorithm is a consistency algorithm based on message passing model
blockchain core algorithm 5: consensus mechanism
blockchain consensus algorithm is mainly workload proof and equity proof. Take bitcoin as an example. In fact, from a technical point of view, POW can be regarded as a reusable hashcash, and the generation workload proves to be a random process in probability. When mining a new secret currency and generating a block, the consent of all participants must be obtained, and the miner must obtain the pow work proof of all data in the block. At the same time, miners have to constantly observe and adjust the difficulty of this work, because the requirement for the network is to generate a block every 10 minutes on average
blockchain core algorithm 6: distributed storage is a kind of data storage technology, which uses the disk space of each machine through the network, and forms a virtual storage device with these scattered storage resources, and the data is stored in every corner of the network. Therefore, distributed storage technology does not store complete data in each computer, but stores the data in different computers after cutting. It's like storing 100 eggs, not in the same basket, but separately in different places. The total number is 100. Want to learn more, you can make more use of network search, network search results - small knowledge
hash function in blockchain is the key to anti tampering, and hash algorithm is a one-way cryptographic mechanism to ensure that transaction information is not tampered in blockchain. After receiving a piece of plaintext, hash algorithm will transform it into a short and fixed hash data in an irreversible way. So block association has but is not limited to tamper proof
2. Quantum secure communication is divided into quantum cryptography communication, quantum teleportation and quantum dense coding. It can be divided into classical communication and quantum communication. The former mainly transmits quantum key, while the latter can be used for quantum teleportation and quantum entanglement distribution. When quantum communication is eavesdropped, although the eavesdropper can't get the information, the communication is interrupted, which affects the normal communication. His anti eavesdropping is at the cost of interrupting the communication, so it doesn't seem as good as the legend.. At present, there are still many unsolved problems in quantum communication, such as short transmission distance, relay difficulty and so on
3. In secure communication, technology competition and complementarity are mutual reference and common development. In secure communication, blockchain should belong to network layer, and quantum communication should belong to physical layer. Therefore, there should be no competition result of who will replace who.
when it comes to blockchain, we must talk about its consensus mechanism. If we don't understand the consensus mechanism of blockchain, we can't understand the real meaning of blockchain. So, what about the consensus mechanism of today's blockchain
what is the consensus mechanism
what is consensus? Take its literal meaning, that is & quot; Common understanding & quot
people are different, not only in stature, appearance and ability, but also in culture, views, ideas, interests and so on
consensus, in short, is the consensus reached by members of a group in a certain aspect
we have learned that trust is a major pain point in the operation of society. Banks have their own credit system. In the past, the financial system only served a few entrepreneurs, because the establishment of credit system cost a lot. Later, Alipay had sesame credit. Credit has already been related to many aspects of life, credit card size, spending amount of flowers, sesame credit and high going abroad can be avoided. We are enjoying the convenience of credit
the essence of blockchain is decentralization, and the core of decentralization is consensus mechanism. The consensus mechanism on blockchain mainly solves the problems of who constructs the block and how to maintain the unity of blockchain
the goal of the blockchain consensus mechanism is to make all honest nodes save consistent blockchain views, while meeting two properties:
1) consistency: the prefix part of the blockchain saved by all honest nodes is exactly the same
2) effectiveness: the information released by an honest node will be recorded in its own blockchain by all other honest nodes
the confidence of blockchain is mainly reflected in the fact that users distributed in the blockchain do not need to trust the other party of the transaction or a centralized organization, and only need to trust the software system under the blockchain protocol to realize the transaction
what is the consensus mechanism? What do pow, POS and dpow mean
the necessity of consensus mechanism
in a distributed system, multiple hosts form a network cluster through asynchronous communication. In such an asynchronous system, state replication between hosts is needed to ensure that each host can reach a consensus. Error messages may appear in asynchronous systems and propagate continuously, so it is necessary to define fault-tolerant protocols in default unreliable asynchronous networks to ensure that all hosts reach a safe and reliable state consensus, which is the necessity of consensus mechanism
the premise of such self-confidence is the consensus mechanism of the blockchain, that is, in a market of mutual distrust, the sufficient and necessary condition for each node to reach an agreement is that each node will spontaneously and honestly abide by the pre-set rules in the agreement to judge the authenticity of each record for the sake of maximizing its own interests, Finally, the records judged to be true are recorded in the blockchain. Attachments-2018-08-9yy7vrha5b738e3d96021. JPG
in other words, if each node has its own independent interests and competes with each other, it is almost impossible for these nodes to conspire to cheat you, especially when they have public reputation in the network. Blockchain technology is the use of a set of mathematical algorithms based on consensus to establish & quot; Trust & quot; Network, so as to create new credit through technical endorsement rather than centralized credit institutions
Introction to several consensus mechanisms in today's blockchain
there are many consensus mechanisms in blockchain, but none of them is perfect, or suitable for all application scenarios
POW workload proof
each node in the whole system provides computing power (referred to as computing power) for the whole system. Through a competitive mechanism, the node with the best computing work can be rewarded by the system, that is, to complete the allocation of newly generated currency. It is simply understood that more work pays more. Currency blockchains such as bitcoin and LTC apply POW mechanism
advantages
completely decentralize the nodes to get in and out freely, the algorithm is simple, easy to realize, and the cost of destroying the system is huge. As long as the computing power of the network destroyer does not exceed 50% of the total computing power of the network, the transaction status of the network can reach an agreement
disadvantages
waste energy, which is the biggest disadvantage. It is difficult to shorten the block confirmation time, for example, bitcoin can only do 7 transactions per second, It is not suitable for commercial application. A new blockchain must find a different hash algorithm, or it will face bitcoin's computing power attack. It has high requirements on the performance of the nodes, and the network environment is prone to bifurcation. It needs to wait for multiple confirmations, and can not reach the final agreement
POS proof of equity
also known as proof of equity, which is similar to you deposit your property in the bank, This model will allocate interest to you according to the amount and time of cryptocurrency you hold< Advantages
low requirements for node performance and short consensus time
disadvantages
there is no final consistency, so checkpoint mechanism is needed to make up for the finality
dpow is an evolutionary scheme of pos. in conventional POW and POS, any newly added block needs to be confirmed by all nodes of the whole network, which greatly affects the efficiency
dpos is similar to the voting mechanism of modern board of directors, which elects representatives to vote and make decisions. The N selected accounting nodes are used for the creation, verification, signature and mutual supervision of new blocks, which greatly reces the time and computational cost of block creation and confirmation
advantages
greatly rece the number of nodes participating in verification and accounting, which can achieve second level consensus verification
disadvantages
sacrifice the concept of decentralization, which is not suitable for public chain
pbft practical Byzantine fault tolerance
practical Byzantine fault tolerance mechanism is a kind of adoption & quot; Permission to vote, minority subject to majority & quot; The consensus mechanism allows Byzantine fault tolerance, allows strong supervision nodes to participate, has the ability of authority classification, higher performance and lower energy consumption, and each round of bookkeeping will be jointly elected by the whole network nodes, allowing 33% of nodes to do evil, and the fault tolerance rate is 33%. Practical Byzantine fault tolerance is especially suitable for the application scenario of alliance chain<
advantages
will deviate from centralization, the existence of cryptocurrency and reward mechanism will proce Matthew effect, making the poor poorer and the rich richer in the community, achieving high consensus efficiency and realizing high-frequency trading
disadvantages
when only 33% of the nodes in the system are running, the system will stop running
dbft authorizes Byzantine fault tolerance
this mechanism is to use rights to select bookkeeper, Then bookkeepers reach a consensus through Byzantine fault-tolerant algorithm. The core of Byzantine fault tolerance mechanism is to ensure the system's finality to the maximum extent, so that the blockchain can be applied to real financial application scenarios
advantages
Professional bookkeeper can tolerate any type of error, bookkeeping is completed by multiple people, each block has finality, no bifurcation, the reliability of the algorithm has strict mathematical proof
disadvantages
when one-third or more bookkeepers stop working, the system will not be able to provide services, when one-third or more bookkeepers jointly commit crimes, The system may be bifurcated
pool verification pool
based on traditional distributed consistency technology and data verification mechanism
advantages
it can work without cryptocurrency. Based on the mature distributed consistency algorithms (pasox, raft), it realizes second level consensus verification
disadvantages
the degree of decentralization is not as good as bitcoin, which is more suitable for the multi center business model with multi participation
Paxos
this is a traditional distributed consensus algorithm, which is a consensus mechanism based on election leaders. The leader node has absolute authority, and allows strong supervision node to participate, which has high performance and low resource consumption. Generally, all nodes have wired access mechanism, but there is no malicious node in the election process, which is not fault-tolerant< In Paxos algorithm, nodes are divided into three types:
proposer: put forward a proposal and wait for everyone's approval. The client often plays the role
acceptor: responsible for voting on the proposal. Usually, the server plays this role
learner: is informed of the result of the case settlement, and unifies with it, and does not participate in the voting process. Maybe the client or server
Paxos can ensure that the system can reach a consensus when more than 50% of the normal nodes exist
REBO consensus mechanism
REBO consensus algorithm enables a group of nodes to form a consensus based on the special node list. The initial special node list is like a club. To accept a new member, it must be voted by 51% of the members of the club. Consensus follows the & quot; 51% rights;, Outsiders have no influence. Since the club starts with centralization, it will always be, and if it starts to corrupt, shareholders can do nothing. Like bitcoin and peercoin, the reborn system separates shareholders from their voting rights, so it is more centralized than other systems
peercoin
peercoin (PPC) is a combination of proof of pow workload and proof of POS equity. POW is mainly used to issue currency. In the future, with the increase of mining difficulty, the output will decrease, and the system security will be mainly maintained by POS
in the blockchain network, e to different application scenarios, different goals are designed, and different blockchain systems adopt different consensus algorithms. Each consensus algorithm is not perfect and has its own advantages and limitations
blockchain solves the problems of transmitting trusted information and value transfer on untrusted channels, while consensus mechanism solves the problem of how blockchain achieves consistency in distributed scenarios
although the blockchain is still in the early stage of development, and the instry development is still facing some obstacles, the society has recognized the value of the blockchain enough, the pace of blockchain development will never stop, and the instry development will certainly find a way to break through the obstacles.
phase 2: the proposal is submitted by the person with the highest number. If no other node proposes a proposal with a higher number, the proposal will be passed smoothly; Otherwise, the whole process will start again
repeatedly, the algorithm will never end, which is called livelock. FLP impossibility has proved that there is no consistency algorithm in asynchronous communication, and livelock is a tough problem that Paxos cannot solve
Phase1 and Phase2 are very similar to the two phases in 2pc, so Paxos is essentially executed alternately by multiple 2pcs
in addition, even if we understand it, we will know how difficult it is to realize it. There is a big gap between engineering implementation and theory.
Paxos algorithm is Leslie Lamport, which is "La & quot;" in latex;, This person is now in Microsoft Research Institute) in 1990 proposed a consistency algorithm based on message passing. This algorithm is considered to be the most effective of the similar algorithms
Lambert's Paxos algorithm consists of two parts:
one is basic Paxos algorithm, which describes how to reach a consensus on a certain value among multiple nodes
the other is the idea of multi Paxos, which describes the implementation of multiple basic Paxos instances to reach a consensus on a series of values
but the idea of multi Paxos mentioned by Lambert lacks the necessary details of code implementation (such as how to elect leaders), so it is difficult to understand. Basic Paxos is the core of multi Paxos
extended data
background
the problem solved by Paxos algorithm is how to reach an agreement on a certain value (decision) in a distributed system. A typical scenario is that in a distributed database system, if the initial state of each node is consistent and each node performs the same operation sequence, then they can get a consistent state at last
in order to ensure that each node executes the same command sequence, it is necessary to execute a "consistency algorithm" on each instruction to ensure that the instructions seen by each node are consistent
a general consistency algorithm can be applied in many scenarios, which is an important problem in distributed computing. Therefore, the research on consistency algorithm has not stopped since 1980s. There are two models of node communication: shared memory and messages passing. Paxos algorithm is a consistency algorithm based on message passing model
Paxos is an algorithm used to solve the consistency problem. If there are multiple nodes, there will be communication problems between them,
It is proved that if a protocol satisfies b1-b3 constraints, then consistency can be guaranteed. The basic protocol is the restricted version of the preliminary protocol, which ensures the consistency. Complete Synod protocol further limits basic protocol to meet consistency and progress requirements. The specific process of these three algorithms is described below. If B1 is satisfied, the number of an election initiated by a pastor must satisfy the partial order relation. One way is that each initiating pastor uses an increasing number as the election number, but in this way, the pastor cannot immediately know whether the number they selected has been used by other pastors. Another method is to use the number + pastor's name as the election number, so as to avoid the use of their own election number by other pastors
If B2 is satisfied, the quorum of each election must be a majority set Q, so that any two elections will have a common pastor. In the original text, Lamport uses weight as a metaphor. People who are overweight are more likely to stay in the parliament hall, so that they can use pastors who are more than half of their weight as the majority. As for the actual situation, what most of the sets are depends on the specific situation
to meet B3, each pastor must find B before launching an election_ Maxvote (B, Q, b) of each priest Q in QRM< According to the above requirements, we can get the initial agreement:
1. Pastor P selects an election number B and sends nextball (b) to other pastors
2. After receiving nextball (b), other pastors Q returns lastvote (B, V) to pastor P, v = maxvote (B, Q, b) $which is the largest affirmative vote of Q less than B number. In order to guarantee B3, Q cannot be in B and B_ Vote for the election between BAL If Q sends last vote (B, V) and votes for a new election, then V is not the largest vote for Q)
3. Pastor P receives last vote (B, V) from each pastor Q in a large set of Q, and initiates a new election with the number of B, the quorum of Q, and the law D satisfies B3. Then pastor P writes the law on the back of his account and sends beginballot (B, d) to each pastor in Q
4. After receiving beginballot (B, d), pastor Q decides whether to vote for the election. If yes, he will send a vote (B, q) to pastor P
5. If pastor P receives vote vote (B, q) from each pastor Q in Q, he will write law d into his account and send success (d) message to all pastors
6. After receiving the success (d) message, pastor Q writes law d into his account
note: the first step indicates that the pastor who initiated the law wants the number of the next election to be B. Pastor Q responds to pastor P's request with lastvote (B, V), that is to say, when passing the law to pastor P, v = maxvote (B, Q, b) is guaranteed to be changed. Specifically, it is not in B and B_ Vote for the election between BAL
in the third step, the law D needs to meet B3. I am a little confused here. The value in the actual system is determined by the client, not B3. Here we will use the above example of key value database to clarify the following idea: when a node / pastor initiates an update for the first time, it means that B is an empty set, and the operation of initiating an update / election continues until all the quorum vote for the law (that is, if the node of the priority set updates the value of the key value, it is considered that the update is successful), B3 corresponds to the situation that if the previous update fails, the new election value needs to be maintained. In the fourth step, the pastor is allowed not to send vote (B, q) or send it several times. The corresponding message may not be sent or sent many times e to communication failure. Once the priest votes in favor, confirm that the value can be changed
considering that the law D was written into the account by Pastor Q in the sixth step, it is possible that pastor P wrote the law into his own account in the fifth step, and then sent success (d) to other pastors, which was not written into his own account because of correspondence or pastor leaving the Council hall, resulting in inconsistency. So the real time to write it into the accounts should be in the fourth step, when pastor Q sends pastor P's affirmative vote, he writes the law into his own accounts. It is not necessary to consider how to ensure that the law written in step 4 will lead to inconsistency, because if the law is not passed, there will be more elections to ensure consistency. Later also talked about when the law is not written into the accounts for the first time. The preliminary protocol requires every priest to keep (I) every election he initiates II) each of his votes in favour III) each $lastvote $he sends. In order to simplify the data that priests need to save, we make a restriction on the above protocol and get the basic protocol. First, three new parameters are introced:
lasttried [P] the last election initiated by Pastor P
prevvote [P] pastor P's latest vote
nextbal [P] the maximum value of B of the election number received by Pastor P, that is, the maximum election number that pastor P participates in
in the initial agreement, each pastor can launch any election at the same time, In the basic agreement, each priest is required to launch only one election last tried [P]. Once an election is launched, the information of the previous election is not important. In the initial agreement, each priest is required not to be in B_ BAL and B vote in favor of each other. In the basic agreement, it is more strictly required not to vote in favor of the election less than B. Then the basic protocol can be summarized as the following steps:
1. Pastor P selects an election number B larger than lasttried [P], and sends nextball (b) to other pastors
2. Pastor Q receives nextball (b) and B & gt; After nextbal [q], set nextbal [q] = B, and then send lastvote (B, V) to pastor P, where V = = prevba [q] If B is less than or equal to nextbal [q], then do not reply)
3. Each pastor in a certain set Q receives the last vote (B, V) message, pastor P initiates an election with the number of B, the quorum of Q, and the law of D (satisfying B3), and sends beginballot (B, d) to each pastor in Q If there is no pastor who satisfies any majority of set Q, return to the first step)
4. Pastor Q receives beginballot (B, d), decides to vote for it, sets prevvote [P] as the vote, and sends the vote (B, q) to pastor P If we find that B is not equal to nextbal [q] after receiving beginballot (B, d), we will ignore this message, which means that pastor Q has received other elections with larger number ring this period)
5. Pastor P receives voted (B, d) from each pastor Q in most of the set Q, and B = = lasttried [P], then we think that this election is successful and record law D in the account, And send success (d) to each priest Q in Q
6. After receiving the success (d) message, each pastor will write the law into the account
the basic protocol is a restricted version of the original protocol, because both of them have no behavior requirements for priests, so they do not guarantee the process (QS). The following is a protocol to guarantee the process complete synode protocol. The basic agreement guarantees consistency, but it does not guarantee any process, because it only states what the pastor may do and does not require what the pastor should do. In order to achieve the above mentioned process requirements, we need to add some additional requirements to enable the priests to complete 2-6 steps as soon as possible
consider a case in which if the election number B received by Pastor Q in the second step is larger than that received before, then pastor Q has to give up all the elections received before. However, before the confirmation of the election No. B, a larger number of "B" may be received, so that no law can be passed and the process can not be guaranteed. Therefore, in order to meet the needs of the process, we need to launch another election after one election is successful. First of all, we should know the time for the server to deliver the message and the pastor to process the message. In the network, we often set a timeout to achieve this. Similarly, if the pastor does not receive a reply from the server after a certain period of time, he will think that the server or the corresponding pastor has left the Council hall
suppose the pastor performs an action within 7 minutes and the server delivers a message within 4 minutes, then a pastor P sends a message to pastor Q, hoping that the reply time should be within 22 minutes (7 + 4 + 7 + 4 minutes)
with the assumption of the above time and considering the situation discussed above, if the pastor P who initiated the election expects to receive a reply from other pastors in the second and fourth steps within 22 minutes, if not, some pastors or waiters may have left the Council hall, or some pastors may have initiated an election with a larger number. In both cases, pastor P should terminate the election and start a new election. In order to avoid that the new election number is too small to be executed, he needs to get the latest election number from other pastors, so as to select a larger number to start the election
assuming that pastor P is the only pastor who can initiate an election and there are a large number of pastors gathered in the assembly hall, we can guarantee that a law will be passed in 99 minutes: a law with a larger number will be found in 22 minutes, and the largest number will be obtained and a larger number will be selected in 22 minutes, Complete 1-6 steps in 55 minutes to complete a successful election (question: since only pastor P can initiate an election, then the number is controlled by him. It seems unnecessary to find and choose a larger number in the first two steps. A: not all elections are sponsored by the president. The president will assign election numbers to other priests who wish to sponsor elections. From the above process, we find that a complete parliamentary agreement needs a process of electing the president, and the election algorithm of the president is not the focus of the article, so only t minutes are used to replace the time of electing the president in the article, so that a law can be passed in T + 99 minutes
the way to select president in this paper is to send his last name to all the priests in the assembly hall. If a priest does not receive a last name in the alphabet within T-11 minutes, he thinks he is president (I think the broadcast weight should be good, too, Doesn't it mean heavier people stay in the chamber longer. There is another detail: when electing the president, each pastor needs to send his last tried [P] to other pastors, so that the president can choose a sufficiently large number in the first election
so far, by electing the president and setting the timeout, the complete parliamentary agreement can guarantee the process
multi law Congress agreement
in the last section of the complete Synod protocol, after the president is elected, every pastor who wants to launch an election informs him, and the president assigns an election number to the pastor to pass only one law at a time. The multi law parliament agreement selects a president to pass a series of laws, and only needs to implement the first two steps once
specific
phase 1: determine who has the highest number, and only the one with the highest number has the right to submit proposal
phase 2: the proposal is submitted by the person with the highest number. If no other node proposes a proposal with a higher number, the proposal will be passed smoothly; Otherwise, the whole process will start again
if your number is high, I am higher than you. If you repeat this, the algorithm will never end. This is called livelock. FLP impossibility has proved that there is no consistency algorithm in asynchronous communication, and livelock is a tough problem that Paxos cannot solve
Phase1 and Phase2 are very similar to the two phases in 2pc, so Paxos is essentially executed alternately by multiple 2pcs
in addition, even if you understand it, you will know how difficult it is to implement it. There is a big gap between engineering implementation and theory!