Home > Blockchain >  Technical point reading | aelf consensus standard design
Technical point reading | aelf consensus standard design

Time:09-22

Block chain system consensus: decentralized consensus

In essence, block chain system is a distributed system, but is different from general distributed system, widely distributed system, its significance lies in: in the face of the growth of the business, with multiple machines bearing vertical separation or horizontal split after the business scenario, increasing the system capacity; Depending on the degree of the key business, eliminate single points of failure, to strengthen the system availability and when a block chain system for complex business scenarios such as widely distributed systems, of course, also need to do the above consideration, but block chain system should be taken seriously by people, the presence of evil nodes because it can solve the problem of data consistency, also is the problem the Byzantine generals,
Block chain in the world, there is no so-called centralized server, it is by all the lovers, the beneficiaries or other relevant people together form a P2P network, any a node in the network is not direct trust, any one of them has to do evil, it is a common distributed systems does not consider the problem, this problem with Byzantine generals of the hypothesis: there is no centralized leadership body, the general need to attack a city, all the general need of any general attack time reach a consensus, so the question comes, if the generals decide against time, even a general has become a traitor, so the generals to reach a consensus?
Similarly, in the chain of blocks in the P2P network, all nodes how to agree a deal? (that is, based on the transaction to the respective changes to a database)?
In a 1982 paper in The Byzantine Generals Problem, Leslie Lamport proved that when The traitor of no more than a third of The Generals, efficient algorithm, however, traitors loyal Generals always The result of The agreement, and if a traitor is overmuch, can't guarantee can reach consensus,
So we assume that block chain directly in the P2P network, evil node number no more than a third, or building block chain system failure, so, the next is the most difficult to solve the problem is that no more than a third of the block in an evil node chain system, whose data as to choose a final consensus data?
In a perspective: if a node wants to provide data to reach a consensus in the block chain system, he need to do? He will need to provide a Proof, a certificate, to persuade accept he provided data block chain system,
On this basis, we started to discuss how to block chain system design a consensus standard interface,
Interface design standard consensus

Block chain consensus process:

1. The node prepared A block, A broadcast to P2P network;

2. The other nodes of P2P network after receiving block, after a series of validation, decide whether to put the blocks in the local the longest chain;

3. When the block chain system most of the nodes (e.g., more than two-thirds) local a height corresponding to the block hash values are consistent, we can think the chain for the height of the block agreed,

If you need A service to help node A and chain blocks other nodes to complete the entire process of consensus, then service should be provided by the generally has two kinds:

1. Know nothing in the face of A, need to ask A, told the (in the world of chain blocks, A use A public key only sure identity) current can try to produce blocks, and how to try to make it produce blocks other nodes to accept;

2. The other nodes, other than A face from the Internet received an A broadcast out of blocks, all through an open source node implementation code consistent service to verify whether the block legitimate,

If A node through the validation of the block, learned that the block legitimate, says the node to A have reached A consensus on the block, because all of the validation service node is the same logic, chain blocks, all nodes in the network to the legitimacy of the block would have the same attitude, after all, the chain of A block in the P2P network (in the case of no longer A chain) of the block is added to the longest chain this event A final consistency and predictable,

Common interface standard aelf consensus

Now on, we based on "consensus standard interface design" in the statistics of two classes of service, aelf consensus common interface design,

First you need to clear, and the two consensus related services (request block production related instructions to validate new blocks) are read-only interface, the call itself without modifying the block chain network books information,

Second, the interface will actually be aelf main chain code calls, so its design needs to follow aelf main chain code of production and verify the block logic (and, of course, even in the main chain code, these interfaces are almost one-to-one correspondence to appear in the Consensus Consensus in Service),

We respectively discuss the two interfaces:

Request consensus command


To continue the previous example, or node A, this is A synchronous to the current aelf the longest Chain of nodes, the current time is on January 1, 2020 afternoon 13:59:56, A, as A honest nodes (without modifying the landlord Chain code), just sync A block (which is accepted by other nodes on the network of blocks, verification is successful, modified the local block Chain books information), the Best local Chain (maintenance) to A data structure of local block Chain be updated after the Event Bus carrying on an Event, one of the role of this Event, is to remind the node A consensus to ask service (via the relevant Event subscription and processing mechanism), what can he do next, when asked, A pass your public key to A consensus on service,

Consensus on the core logic of the service as A smart contracts, because only so can guarantee its code for each node in the chain blocks in the world are consistent (inconsistent means the node is trying to be evil or hard branch), after more than A few milliseconds of complex calculations (might be A simple calculation), consensus of intelligence information feedback to the node A to A contract, the selection of the mechanism of the generation of information is due to the consensus, but no matter what, should have the following structure:
A. what time can produce block?
, if can produce A block, then should use what the next step in the form of A request: that under the current consensus, A can produce anything blocks, says this information for additional tips here,

If cannot produce A block? Block chain in the world everyone could actually produce blocks in theory, but as A result of consensus mechanism design different (such as PoS consensus), some of the majority of nodes have production chain does not want the block of rights, in this case, the only need to return to A time set in one hundred after can (may be exaggerated, but after A few months total no problem), as long as the node can stick to hang up, and did not produce any new chain with the block (any effective new blocks of synchronous envoys from point A to regain A block of time),

It's not hard to imagine how easy it is based on the interface implementation PoW, as long as the time is set to "immediately", additional tips for empty can,

Services in the main chain of the aelf consensus that consensus after the time information feedback, will be immediately updated consensus scheduler (scheduler is not empty, if the consensus is kill unfinished before scheduling information, with a new point in time to fill, namely consensus inside the scheduler can only have one without the consensus of the mission, and consensus scheduler is a singleton object),

Then there is a long countdown,

We went back to the node A this example, assume that A consensus on request after the command, got A time: on January 1, 2020 afternoon 14:00:00, namely 4 seconds later, bonus tip: NextRound (this is AEDPoS consensus in A prompt, means that will end this round out A piece of the process, and update the next round of all agencies out of the block of the node of A piece of order), which means that the scheduler will immediately update for 4 seconds after executing A production blocks, this 4 seconds to do? If can synchronize to other nodes sending blocks, and the blocks can be verified, then use the Best Chain update the event processor, keep asking consensus service request consensus command (this operation in the code called TriggerConsensus), accordingly, consensus scheduler will constantly reset: 3.5 seconds, 3 seconds, 2.5 seconds, 2 seconds,...

Finally, the time came to 14:00:00, A node in the consensus under the domination of the scheduler to start preparing production blocks, at this point, according to our previous design, in addition to have played A role of A block of time, about how to produce blocks, the only know only consensus before service gave him extra tips,

At this moment, in aelf, service node, the extra hint information to A consensus, in package deal, can call the other two services:
Block header information, obtain consensus
Trading system, get consensus

Request the consensus of the command interface has a role is to try to make produce block through the verification, in aelf, in block a series of validation step, there are two related validation and consensus: before execution, validation block head; Executed, whether to modify consensus contract status information and the information in the block head consistency verification,
Do a simple analogy, a.net programmer to DNT offline salon, he took out an invitation to the salon messages to salon organizers for inspection, the message is similar to the block header, that is to say if he couldn't get the invite message, the organizers will not let him in, next, the organizers will also require..net programmers quote us a phone number, and then in the roster of participants to find the phone number, it is similar to the execution of the agreement in the block chain node trading after the verification, only this step is to verify through the.net programmers can smoothly at the salon,

To sum up, in view of the "order request consensus" this kind of service, we need three interfaces, directly with Protobuf described as follows:

Service ConsensusContract {
RPC GetConsensusCommand (Google. Protobuf. BytesValue)
Returns (ConsensusCommand) {
Option (aelf is_view)=true;
}
RPC GetConsensusExtraData (Google. Protobuf. BytesValue)
Returns (Google. Protobuf. BytesValue) {
Option (aelf is_view)=true;
}
RPC GenerateConsensusTransactions (Google. Protobuf. BytesValue)
Returns (TransactionList) {
Option (aelf is_view)=true;
}
}

The message ConsensusCommand {
Int32 limit_milliseconds_of_mining_block=2;
//the Time limit of mining, the next block.
Bytes hint=3;
//the Context of Hint is diverse "according to the consensus protocol we choose, so we use bytes.
Google. Protobuf. Timestamp arranged_mining_time=4;
Google. Protobuf. Timestamp mining_due_time=5;
}

The message TransactionList {
Repeated aelf. Transaction the transactions=1;
}
For the security and stability of the chain, in ConsensusCommand, in addition to the next block of time (arranged_mining_time) and additional tips (hint), includes a piece of time limit (limit_milliseconds_of_mining_block) and the latest broadcast time (mining_due_time), is behind two information to the block in the production of services as a reference, is used to implement if over a certain time limit, produced blocks without radio (or even radio and other nodes cannot be verified, of course, the validation is to be discussed below) in the specific implementation of the interface type of the warranty. How to produce a piece of is better than disturb the order of block production,
Block validation


If request consensus command also worth careful discussion, block to verify the relevant interface is good to Chen, since block validation logic is essentially completely varied from consensus,

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related