Disclosure of Invention
The consensus method and the device for the blockchain system based on the non-negotiation random drawing can prevent malicious nodes from manipulating the drawing result and ensure the safety of blockchain operation; on the other hand, only the unique node has block qualification in each specific time period, so that competitive bifurcation is avoided, and the transaction real-time performance of the block chain system is improved.
In a first aspect, the present invention provides a consensus method for blockchain system based on non-negotiation random drawing, where the method includes:
after a legal block is received, determining a node which is qualified as a candidate currently according to a whole network trust certificate list;
carrying out non-negotiation random drawing on the nodes with the candidate qualification at present to obtain a node sequence arranged in sequence, wherein the node sequence determines the only block outlet node with the block qualification at each subsequent specific time period;
in each subsequent specific time period, the block output node sends a pre-output block and collects endorsements;
after receiving the endorsement request, the endorsement node checks the legality of the pre-output block and signs the legal pre-output block;
after more than 50% endorsement signatures are collected by the block output node, the endorsement signatures are added to the pre-output block to form a formal block, and the formal block is broadcasted to the whole network.
Optionally, the performing a non-negotiation random drawing on the node currently having the candidate qualification to obtain a sequence of sequentially arranged nodes includes: and taking the received hash value of the legal block as a random seed, taking the set of nodes with candidate qualification as input, and executing the same formula to obtain a node sequence arranged in sequence.
Optionally, the sending the pre-out block and collecting the endorsement in each subsequent specific time period comprises:
in each subsequent specific time period, sequencing and pre-executing according to the collected transactions to obtain an effective transaction set, packaging and signing to form a pre-outgoing block, broadcasting to an endorsement node, and requesting the endorsement node to sign the pre-outgoing block;
signatures of endorsement nodes are collected.
Optionally, the method further comprises: after the block output node finishes formal block output, locally determining the node with candidate qualification in the next round, and performing non-negotiation random drawing.
Optionally, the method further comprises: after the full network node receives a formal block of a broadcast, checking the legality of the formal block;
after the validity check of the formal block is passed, sequentially executing the transactions in the formal block to complete state transition;
and locally determining the node with candidate qualification of the next round, and carrying out non-negotiation random drawing.
Optionally, the method further comprises:
and if the state migration is not finished in the block output time period, designating the next node in the node sequence as a legal block output node of the current time period.
In a second aspect, the present invention provides a consensus device for blockchain system based on non-negotiation random drawing, the device comprising:
the determining unit is used for determining the current nodes with candidate qualification according to the whole network trust certificate list after the legal blocks are received;
the first election unit carries out non-negotiation random drawing and signing on the nodes with the candidate qualification at present to obtain a node sequence arranged in sequence, wherein the node sequence determines the only block outlet node with the block qualification in each subsequent specific time period;
the pre-execution unit is used for sending a pre-output block and collecting endorsements by the output block node in each subsequent specific time period;
the endorsement unit is used for checking the legality of the pre-output block and signing the legal pre-output block after the endorsement node receives the endorsement request;
and the block output unit is used for adding the endorsement signatures to the pre-output block after the block output node collects more than 50% of the endorsement signatures to form a formal block and broadcasting the formal block to the whole network.
Optionally, the first election unit is configured to execute the same equation by taking the received hash value of the legal block as a random seed and taking the set of nodes that currently have the candidate qualification as an input, and obtain a sequence of nodes arranged in order.
Optionally, the pre-execution unit includes:
the system comprises a pre-execution module, a data processing module and a data processing module, wherein the pre-execution module is used for sequencing and pre-executing according to collected transactions to obtain an effective transaction set, forming a pre-output block after packaging and signing, broadcasting the pre-output block to an endorsement node and requesting the endorsement node to sign the pre-output block;
and the collection module is used for collecting the signature of the endorsement node.
Optionally, the apparatus further comprises:
and the second election unit is used for locally determining the node with candidate qualification in the next round after the block output unit finishes formal block output and performing non-negotiation random drawing.
Optionally, the apparatus further comprises:
the system comprises a checking unit, a judging unit and a judging unit, wherein the checking unit is used for checking the validity of a formal block after the formal block of the broadcast is received by a whole network node;
the execution unit is used for sequentially executing the transactions in the formal block after the validity check of the formal block passes and finishing the state transition;
and the third election unit is used for locally determining the node with candidate qualification in the next round and carrying out non-negotiation random drawing.
Optionally, the apparatus further comprises:
and the specifying unit is used for specifying the next node in the node sequence as a legal block output node of the current time period if the state migration is not completed in the block output time period.
According to the consensus method and device for the block chain system based on the non-negotiation random drawing, provided by the embodiment of the invention, each node elects a consistent block output node sequence based on a non-negotiation random drawing algorithm, so that input consensus among distributed nodes is achieved, transactions in blocks are executed in sequence according to an election result, and the migration of a previous state to a next state of the block chain is completed. Compared with the prior art, the invention can prevent malicious nodes from operating the drawing result and ensure the safety of block chain operation; on the other hand, only the unique node has block qualification in each specific time period, so that competitive bifurcation is avoided, and the transaction real-time performance of the block chain system is improved.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The non-negotiation consensus mechanism adopted by the invention achieves the effect that the consensus result can not be predicted in advance by presetting and embedding a rule between the nodes and introducing unpredictable random factors on the rule. The invention adopts a negotiation-free random draw algorithm (CFRD) to realize the aim. Based on the non-negotiation random drawing algorithm, the invention provides a consensus method for a block chain system based on non-negotiation random drawing, as shown in fig. 1, the method comprises:
s11, after a legal block is received, determining a node with candidate qualification according to the whole network trust certificate list;
s12, carrying out non-negotiation random drawing on the current candidate qualified nodes to obtain a node sequence arranged in sequence, wherein the node sequence determines the only block outlet node with block qualification in each subsequent specific time period;
specifically, S11 and S12 are processes for executing the non-negotiation random drawing algorithm, and the precondition for executing the non-negotiation random drawing algorithm provided by the present invention includes: each node of the block chain networking is provided with a means for communicating with other nodes; each node maintains a whole network trust certificate list; each node that may become a candidate constantly collects the transactions that are propagated throughout the network.
The time for triggering the non-negotiation random drawing algorithm provided by the invention is as follows: after each node receives the last legal block, the next round of election of the sequence of nodes responsible for the outgoing block is triggered locally.
Optionally, the determining, according to the full-network trust certificate list, a node currently qualified as a candidate includes: after receiving the formal block, determining nodes which are qualified as candidates at present according to role configuration by taking the nodes in the network as a complete set;
the performing non-negotiation random drawing on the nodes with the current candidate qualification to obtain the node sequence arranged in sequence comprises: and taking the received hash value of the legal block as a random seed, taking the set of nodes with candidate qualification as input, and executing the same formula to obtain a node sequence arranged in sequence.
Because the hash value of the last formal block is disturbed by factors which can not be predicted in advance, such as a timestamp, a transaction set and the like, the election result can not be predicted, so that the malicious nodes are prevented from operating the election, and meanwhile, the hash value is consistent on each node, so that each node operates respectively, and the obtained election result is consistent. By achieving the input consensus without negotiation, the consensus cost can be greatly reduced, and the transaction flux and the transaction real-time performance of the blockchain system are improved.
After the non-negotiation random drawing is completed, it is decided that in the current round of block, every certain time period, a certain node must be in one of the following three roles:
out-of-block node (packer): the system is responsible for determining the transaction set and the sequence of the blocks in the current round; and sending a pre-output block and collecting endorsements, and if the endorsements with sufficient amount are collected and the formal endorsement is finished, finishing the state transition and triggering the execution of a next round of non-negotiation random drawing algorithm.
Endorsement node (Endorser): the system is responsible for checking the validity of the pre-output block sent by the Blocker, and if the pre-output block is legal, endorsement signing is carried out on the pre-output block; and receiving the formal block and checking the legality of the formal block, if the formal block passes the checking, sequentially executing the transaction in the formal block, completing state transition, and triggering the next round of execution of the non-negotiation random drawing algorithm.
Common node (Follower): and receiving the formal block and checking the legality of the formal block, if the formal block passes the checking, sequentially executing the transaction in the formal block, completing state transition, and triggering the next round of execution of the non-negotiation random drawing algorithm.
Each block output node in the sequence has a block output time period corresponding to the sequence, the time period base line is the time when the last formal block is received, each node receives the time in sequence, the time base line error between the nodes depends on the network propagation speed of the formal block, and the error is in a range capable of being pre-judged for most normal nodes, so that the system can set block output overtime time according to the pre-judgment, and the block output overtime can be realized: the block output node has enough time to finish the block output; most nodes can correctly determine the time quantum qualification of the block-righting person.
Assuming that a node currently qualified as a candidate is subjected to non-negotiation random drawing, a node sequence responsible for block outputting is obtained as [ Blocker1, Blocker2, … and blockern ], a block timeout is configured to be 1 minute, then all nodes acknowledge that the block 1 has block qualification (Blocker) at the 1 st minute, other nodes in the sequence have endorsement qualification (Endorser), and nodes not in the sequence are ordinary nodes (Follower). As shown in fig. 2, it is a flowchart of operations of the export node block 1, the endorsement node block 2 and the common node Follower.
S13, in each specific period, the block output node sends a pre-output block and collects endorsements;
optionally, the sending a pre-egress block and collecting endorsements in the egress block time period of the egress block node includes:
in each subsequent specific time period, sequencing and pre-executing according to the collected transactions to obtain an effective transaction set, packaging and signing to form a pre-outgoing block, broadcasting to an endorsement node, and requesting the endorsement node to sign the pre-outgoing block;
signatures of endorsement nodes are collected.
Within the 1 st minute, the blocker1 sorts and pre-executes the transactions it collects, obtains a sorted valid set of transactions, packages and signs them, and broadcasts them to the endorsement node.
S14, after receiving the endorsement request, the endorsement node checks the validity of the pre-output block and signs the legal pre-output block;
after receiving the endorsement request, the endorsement node verifies the validity of the sender block 1, and the verification process comprises the following steps: in contrast to the local election results, the following checks are performed:
1. whether sender blocker1 is the out-blockman elected in the round;
2. whether the current slot is an out-of-block slot of block 1;
3. whether each transaction in the package has a legal signature;
4. pre-executing each transaction in sequence, and judging whether the execution process is normal or not; whether the output result is consistent with what block 1 claims in the spine block.
If both checks pass, the endorsement node signs the block.
And S15, after the endorsement signatures of more than 50% are collected at the block output node, adding the endorsement signatures to the pre-output block to form a formal block, and broadcasting the formal block to the whole network.
The node of the block is collected to have more than 50% endorsement signature to form a formal block, and the selection result of the non-negotiation random drawing algorithm is applied in the process to prevent the attack of non-51% nodes.
Optionally, the method further comprises: after the block output node finishes formal block output, locally determining the node with candidate qualification in the next round, and performing non-negotiation random drawing.
After blocker1 completes the formal out of the block, the execution of the next round of the non-negotiated random drawing algorithm is triggered locally.
Optionally, the method further comprises: after the full network node receives a formal block of a broadcast, checking the legality of the formal block;
after the validity check of the formal block is passed, sequentially executing the transactions in the formal block to complete state transition;
and locally determining the node with candidate qualification of the next round, and carrying out non-negotiation random drawing.
After each node of the whole network receives the formal block, the following checks are performed:
1. whether sender blocker1 is the out-blockman elected in the round;
2. whether the current slot is an out-of-block slot of block 1;
3. whether the endorsement signer qualifies for endorsement;
4. whether the number of endorsement signatures meets the requirement or not.
If the checks pass, the node acknowledges the validity of the block and executes the transaction in the block to realize the transition from the former state to the latter state. Each node locally triggers the execution of the next round of the non-negotiated random drawing algorithm.
Optionally, the method further comprises: and if the state migration is not finished in the block output time period, designating the next node in the node sequence as a legal block output node of the current time period.
If the formal block output is not completed in the block output period (1 st minute) of the agreed block 1, the whole network node regards the next block output node block 2 as a legal block output node of the current period according to the block output node sequence, and so on.
In the consensus method for the blockchain system based on non-negotiation random drawing provided by the embodiment of the invention, each node elects a consistent block output node sequence based on a non-negotiation random drawing algorithm to achieve input consensus among distributed nodes, and executes transactions in a block according to an election result in sequence to complete the transition from a previous state to a next state of the blockchain. Compared with the prior art, the invention can prevent malicious nodes from operating the drawing result and ensure the safety of block chain operation; on the other hand, only the unique node has block qualification in each specific time period, so that competitive bifurcation is avoided, and the transaction real-time performance of the block chain system is improved.
An embodiment of the present invention further provides a consensus device for a blockchain system based on non-negotiation random drawing, as shown in fig. 3, where the device includes:
a determining unit 11, configured to determine, after a legal block is received, a node currently qualified as a candidate according to the whole network trust certificate list;
the first election unit 12 performs non-negotiation random drawing on the nodes with the candidate qualification at present to obtain a node sequence arranged in sequence, wherein the node sequence determines the only block-out node with the block qualification in each subsequent specific time period;
a pre-execution unit 13, configured to send a pre-outgoing block and collect endorsements by the outgoing block node in each subsequent specific time period;
an endorsement unit 14, configured to check validity of the pre-endorsement block and sign the legal pre-endorsement block after the endorsement node receives the endorsement request;
and the block output unit 15 is used for adding the endorsement signatures to the pre-output block after the block output node collects more than 50% of the endorsement signatures to form a formal block and broadcasting the formal block to the whole network.
Optionally, the first election unit is configured to execute the same equation by taking the received hash value of the legal block as a random seed and taking the set of nodes that currently have the candidate qualification as an input, and obtain a sequence of nodes arranged in order.
Optionally, the pre-execution unit 13 includes:
the system comprises a pre-execution module, a data processing module and a data processing module, wherein the pre-execution module is used for sequencing and pre-executing according to collected transactions to obtain an effective transaction set, forming a pre-output block after packaging and signing, broadcasting the pre-output block to an endorsement node and requesting the endorsement node to sign the pre-output block;
and the collection module is used for collecting the signature of the endorsement node.
Optionally, the apparatus further comprises:
and the second election unit is used for locally determining the node with candidate qualification in the next round after the block output unit finishes formal block output and performing non-negotiation random drawing.
Optionally, the apparatus further comprises:
the system comprises a checking unit, a judging unit and a judging unit, wherein the checking unit is used for checking the validity of a formal block after the formal block of the broadcast is received by a whole network node;
the execution unit is used for sequentially executing the transactions in the formal block after the validity check of the formal block passes and finishing the state transition;
and the third election unit is used for locally determining the node with candidate qualification in the next round and carrying out non-negotiation random drawing.
Optionally, the apparatus further comprises:
and the specifying unit is used for specifying the next node in the node sequence as a legal block output node of the current time period if the state migration is not completed in the block output time period.
In the consensus device for a blockchain system based on non-negotiation random drawing provided in the embodiments of the present invention, each node elects a consistent sequence of block output nodes based on a non-negotiation random drawing algorithm to achieve input consensus among distributed nodes, and executes transactions in a block in order according to an election result to complete transition from a previous state to a subsequent state of a blockchain. Compared with the prior art, the invention can prevent malicious nodes from operating the drawing result and ensure the safety of block chain operation; on the other hand, only the unique node has block qualification in each specific time period, so that competitive bifurcation is avoided, and the transaction real-time performance of the block chain system is improved.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like.
The above description is only for the specific embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.