Home > Blockchain >  Distributed uniformity of block chain algorithm
Distributed uniformity of block chain algorithm

Time:09-17

The problem of data consistency
The basic production environment background system is a distributed system, such as a change (configuration files or other content) how to get consistent results in a distributed network, this is a problem,

Cap principle and consistency algorithm classification
In 2000, all of Distributed Computing conference Eric Brewer published a theory of CAP, in 2002, the Seth Gilbert and Nancy Lynch published a more formal CAP theoretical arguments, CAP principle, there are three key elements:

1. The Consistency (Consistency)
2. Availability (Availablity)
3. The Partition Tolerance (how)
Can only meet two of the key elements of the distributed system to distributed system, the partition tolerance is the basic requirement, design a distributed system is a balance in consistency and availability, there are two ways of measuring the consistency, consistency: client from the developer/client point of view: how they observe data updates, server side consistency: from the perspective of the server side: update how to through the system, and ensure the system to update and,

Client-side consistency
1. The strong consistency: after the update operation, any subsequent visit will return the value of the update,
2. The weak consistency: the system cannot ensure follow-up visits return values of update, need to be in some condition is met, the updated value to return, since the update operation, to ensure that any observer will always see update system value of this period is called the inconsistency window,
3. The eventual consistency: this is a special form of weak consistency; Storage system to ensure if there is no new update of an object, the end all access will return the value of this object at the end of the update,
The server side consistency
On the server side, we need to update more in-depth analysis is how to through the system, and thus to understand what drives different patterns, these patterns are system developers to experience, let's make the following definition,

1. The number of nodes N=copy of data is stored
2. W=before the upgrade is complete, need approval at the same time receive the number of copies of the
(3) R=when a read operation to access the data object, need access to the number of copies of the
If W + R> N, then set and read always overlap and can guarantee strong consistency, such as in the main case of RDBMS, if use a copy of the synchronous way, N=2, W=2 and R=1, regardless of which copies the client to read, and it is always get consistent results,

If W + R<=N, then can guarantee strong consistency, can only be weak consistency or eventual consistency, such as in the main case of RDBMS, using asynchronous synchronous replicas, open and read from the copy function, N=2, W=1 and R=1, in this case, the R + W=N, consistency is not guaranteed,

A two-phase commit algorithm
To write

Paxos algorithm
Paxos algorithm is mainly used in the malicious nodes, there is no only a faulty node of the distributed system, Paxos algorithm to all nodes on the network is divided into three roles:

Proposer: put forward a proposal for approval for the settlement, are often the client for the role,
2. The Accepter: responsible for the vote on the proposal, often is the service side served as the role,
3. Learner: informed as a result, the settlement and the unification, not to participate in the voting process, may be a client or server,
Need to meet safety and lack of algorithm (saftey) and activity (liveness) constraint requirements:

1. Safety: to ensure that the results of the resolution is correct, an executive decision process, only approved a final decision, means that most acceptable results can be a resolution,
2. Liveness: ensure the resolution process can be finished in the limited time, the resolution will produce, and learners can get approved resolution,
Raft algorithm
Raft algorithm to all nodes on the network is divided into three roles:

Leader: handle all interact with the client, copy log, generally only one at a time,
2. The followers: similar to voters, passive receive information,
3. The Candidate: similar to the Proposer, but can be chosen as a new Leader,
Raft algorithm is divided into two phases, the first stage is the election process, the second stage is operating under the Leader to lead, such as log copying, assume that a total of N servers on the network, the following is the specific project:

1. Any server can be a Candidate, it to other servers to choose your own demand
2. The other server reply to agree, as long as meet the N/2 + 1 votes, the server was elected Leader
3. The Leader sends a command to the other servers such as log copy command
4. Through the heart to maintain communication between Leader and Followers
5. Once the Leader lost, Followers of waiting for a certain time after the timeout to become a Candidate, and then repeat the previous process
Specific process can take a look at this animation Raft Demo

POW
Said in front of the algorithm is more distributed consensus algorithm to determine the number of nodes, in fact, there are many nodes in the block chain network, and node number variable, in this case, we say the foregoing resolutions into account (both are the same), to reach consistency of charge to an account in the chain of blocks (consensus), only needs to solve three problems:

1. Who has the right to charge to an account
2. Why need to adopt other nodes forward node result of charge to an account
3. The result of charge to an account how to ensure consistency
In 2009, in the hearing based on probability landmark POW (Proof Of the Work, the Work proved) algorithm, and applied to the currency, POW algorithm principle is simple, the circumstances Of a comparatively simple say first, in the process Of round Of charge to an account, so will set a difficulty value, each node to package after continuously through a specific algorithm to calculate the block hash value, until you find difficulty smaller, it can be a legitimate hash value accounting, and broadcast, after other nodes to receive an account can easily verify the legitimacy Of charge to an account, after the legal charge to their local books, at the same time let yourself into the next round Of the accounting Work force competition, due to the legal accounting needs to consume large amounts Of Work force, takes the actual power, other nodes will tend to be admitted to the charge to an account,

Algorithm can be used reduce the number of the specific legal billing period, but there is no guarantee that conflict, such as legal to have two pens in the same competition cycle accounting resulting in split ends, while the rest of the node to receive two legal billing, through specific strategies, such as random choice or preference to receive the first), select a legal billing block, and on this basis to continue the next round of accounting to calculate power competition, due to legal billing output with memory, eventually get faster to confirm (such as 6 times confirmed) will give priority to charge to an account of the chain in the block of charge to an account, bifurcate billing block is abandoned,

POS
POW need to waste a lot Of work force do meaningless operation to protect the network security, this is the place that has long been criticized, for this, POS (Proof Of gaining interest) algorithm is proposed, proved by the owner's equity to produce legal billing, POS algorithm principle is in the network have more specific rights and interests Of the people more opportunities to produce legal billing, but due to the more specific interests tend to protect the safety Of the network, at the same time introducing some disciplinary measures to ensure that evil will be punished,
POS algorithm of rights and there are many kinds of way, for example to introduce the concept of "currency age", that is to say, the longer cash cash, the longer the currency of age, have the rights and interests, the greater the to encourage more people to hold at the same time, the system of interest can be introduced through economic encouragement, let more people loyal to the network maintenance, network, network security
, produce equally legal billing methods also have a variety of, such as through the rights and interests of appropriate size to reduce calculation difficulty quickly produce a legal billing, or training in rotation in the rights and interests of a group of high node get rapidly developed a legitimate rights and interests of accounting bookkeeping,
By introducing the rights and interests for endorsement credibility, can reduce the number of calculation and improve the speed,

DPOS
In POS algorithm based on derivative DPOS (Delegated Proof of gaining, authorized shares mechanism) algorithm, the principle is to make all ChiBiRen have chance to elect their representatives, such as the entire network had 10000 participants, through a certain algorithm, participants in its own scrip for rights and interests has been proved that the elected representatives of 101, the delegates can take turns or POS algorithm of weighted get the billing, billing, the elected representatives of the DPOS theory does not require the individual itself is the rights and interests of all people, look more democratic, more open, the network participants as voters have a chance to choose their own representative, to represent their own interests, if elected representatives are not as (when their turn accounting bookkeeping), or to do evil, can kick them off, if necessary to punish (voters may also be punished), have the opportunity to get the corresponding reward or charge to an account, it is also possible to reward to choose their own people,

PBFT
POW, POS, DPOS are public chain eventual consistency above consensus algorithm, as public chain is actually more nodes to connect to the Internet, there is the communication latency and network failures, etc., so will be in the same time there is a big probability get billing rights exist multiple nodes, produce multiple legal charge to an account which can lead to split ends, the existence of bifurcation in fact means that the current legal billing block just be accepted temporarily, need as time goes by, more and more legal billing block to confirm it will be a higher probability of being accepted and eventual consistency (such as legal billing currency block 6 times confirmed officially into the main chain blocks to big probability),
Practice, some business scenarios need to achieve strong consistency, such as the consumption of scenario, a payment after the completion of the finished goods delivery, immediately behind the payment may not be overturned, in order to achieve this business scenario, can adopt the way of more small block chain, is the manner in which the league chain,
League chain business scenarios, most of the node are institutions, limited number, PBFT (Practical Byzantine Fault how) algorithm can be very good use in the league chain scenario,
  • Related