Invention content
In view of this, a kind of block chain common recognition processing method of present invention proposition, electronic device and computer-readable storage medium
Probabilistic consistency common recognition algorithm is combined with absolute consistency common recognition algorithm, is first passed through in large-scale network node by matter
The probabilistic consistency common recognition relatively few number of node of algorithm picks, then recycles absolute consistency to know together algorithm in common recognition
Appearance is efficiently known together.
First, to achieve the above object, the present invention proposes a kind of block chain common recognition processing method, and the method comprising the steps of:
According to the high quality node of periodical rotation mechanism and POW algorithm picks preset quantities from block catenary system;And
Common recognition processing is traded between the node chosen.
Optionally, according to the height of periodical rotation mechanism and POW algorithm picks preset quantities in the catenary system from block
The step of quality node includes:
Rotational cycle is set;
When reaching the election contest starting point in the rotational cycle, pass through the alternate node of POW algorithms selection preset quantities;
When next rotational cycle starts, currently used common recognition node is replaced with the alternate node.
Optionally, the rotational cycle is N number of block, and the election contest starting point can be divided exactly by N/2 for block height and cannot
When evenly divisible by N.
Optionally, the step of alternate node by POW algorithms selection preset quantities includes:
When reaching the election contest starting point in the rotational cycle, all nodes do POW fortune to the block of the election contest starting point
It calculates;
Each node sends a transaction into preset target account after calculating result, and operation result is attached to friendship
In easy extension fields, it to be used for checkout transaction validity;
Effective transaction is searched from the account, and the alternate node is added by trading order.
Optionally, described the step of common recognition processing is traded between the node chosen, includes:
When each rotational cycle starts, according to replaced common recognition node, after transaction is packaged as block, use
Practical Byzantine failure tolerance algorithm is reached common understanding between the replaced common recognition node.
In addition, to achieve the above object, it is described to deposit the present invention also provides a kind of electronic device, including memory, processor
The block chain common recognition processing routine that can be run on the processor, the block chain common recognition processing routine quilt are stored on reservoir
The processor realizes following steps when executing:
According to the high quality node of periodical rotation mechanism and POW algorithm picks preset quantities from block catenary system;And
Common recognition processing is traded between the node chosen.
Optionally, according to the height of periodical rotation mechanism and POW algorithm picks preset quantities in the catenary system from block
The step of quality node includes:
Rotational cycle is set;
When reaching the election contest starting point in the rotational cycle, pass through the alternate node of POW algorithms selection preset quantities;
When next rotational cycle starts, currently used common recognition node is replaced with the alternate node.
Optionally, the rotational cycle is N number of block, and the election contest starting point can be divided exactly by N/2 for block height and cannot
When evenly divisible by N.
Optionally, the step of alternate node by POW algorithms selection preset quantities includes:
When reaching the election contest starting point in the rotational cycle, all nodes do POW fortune to the block of the election contest starting point
It calculates;
Each node sends a transaction into preset target account after calculating result, and operation result is attached to friendship
In easy extension fields, it to be used for checkout transaction validity;
Effective transaction is searched from the account, and the alternate node is added by trading order.
Optionally, described the step of common recognition processing is traded between the node chosen, includes:
When each rotational cycle starts, according to replaced common recognition node, after transaction is packaged as block, use
Practical Byzantine failure tolerance algorithm is reached common understanding between the replaced common recognition node.
Further, to achieve the above object, the present invention also provides a kind of computer readable storage medium, the computers
Readable storage medium storing program for executing is stored with block chain common recognition processing routine, and the block chain common recognition processing routine can be by least one processor
It executes, so that at least one processor is executed such as the step of above-mentioned block chain common recognition processing method.
Compared to the prior art, block chain common recognition processing method proposed by the invention, electronic device and computer-readable
Storage medium can realize a kind of common recognition mechanism of layering in block catenary system, by probabilistic consistency common recognition algorithm and absolutely
Consistency common recognition algorithm is combined, and it is relatively a small number of that probabilistic consistency common recognition algorithm picks are first passed through in large-scale network node
Then the node of amount recycles absolute consistency common recognition algorithm efficiently to be known together to common recognition content in selected node.Also,
Selected node ensure that number in following rotational cycle based on block chain common recognition itself in the form of periodical rotation mechanism
According to common recognition.This programme both can be adapted in large-scale distributed network, while can also efficiently produce block, improve
The availability of block catenary system, and the scope of application of block catenary system is extended, so that block catenary system bottom is met more
The demand of kind business scenario.
Specific implementation mode
In order to make the purpose , technical scheme and advantage of the present invention be clearer, with reference to the accompanying drawings and embodiments, right
The present invention is further elaborated.It should be appreciated that described herein, specific examples are only used to explain the present invention, not
For limiting the present invention.Based on the embodiments of the present invention, those of ordinary skill in the art are not before making creative work
The every other embodiment obtained is put, shall fall within the protection scope of the present invention.
It should be noted that the description for being related to " first ", " second " etc. in the present invention is used for description purposes only, and cannot
It is interpreted as indicating or implying its relative importance or implicitly indicates the quantity of indicated technical characteristic.Define as a result, " the
One ", the feature of " second " can explicitly or implicitly include at least one of the features.In addition, the skill between each embodiment
Art scheme can be combined with each other, but must can be implemented as basis with those of ordinary skill in the art, when technical solution
Will be understood that the combination of this technical solution is not present in conjunction with there is conflicting or cannot achieve when, also not the present invention claims
Protection domain within.
First embodiment
As shown in fig.1, first embodiment of the invention proposes a kind of electronic device for realizing block chain common recognition processing method
1。
In the present embodiment, electronic device 1 can be server, smart mobile phone, tablet computer, PC, portable meter
Calculation machine and other electronic equipments with calculation function.
The electronic device 1 includes:Memory 11, processor 13, network interface 15 and communication bus 17.Wherein, network
Interface 15 may include optionally standard wireline interface and wireless interface (such as WI-FI interface).Communication bus 17 is for realizing this
Connection communication between a little components.
Memory 11 includes at least a type of readable storage medium storing program for executing.The readable storage medium storing program for executing of at least one type
It can be the non-volatile memory medium of such as flash memory, hard disk, multimedia card, card-type memory.In some embodiments, described to deposit
Reservoir 11 can be the internal storage unit of the electronic device 1, such as the hard disk of the electronic device 1.In other embodiments
In, the memory 11 can also be to be equipped on the external memory unit of the electronic device 1, such as the electronic device 1
Plug-in type hard disk, intelligent memory card (Smart Media Card, SMC), secure digital (Secure Digital, SD) card dodge
Deposit card (Flash Card) etc..
In the present embodiment, the memory 11 can be used for store be installed on the electronic device 1 application software and
The related data generated in Various types of data, such as the program code and its operational process of block chain common recognition processing routine 10.
Processor 13 can be in some embodiments a central processing unit (Central Processing Unit,
CPU), microprocessor or other data processing chips, the program code for being stored in run memory 11 or processing data.
Fig. 1 illustrates only the electronic device 1 for processing routine 10 of knowing together with component 11-17 and block chain, but should manage
Solution, Fig. 1 do not show that all components of electronic device 1, can substitute and implement more or less component.
In 1 embodiment of electronic device shown in Fig. 1, as memory block in a kind of memory 11 of computer storage media
The program code of block chain common recognition processing routine 10, processor 13 execute the program code of the block chain common recognition processing routine 10
When, realize following steps:
(1) according to the high quality node of periodical rotation mechanism and POW algorithm picks preset quantities from block catenary system.
It specifically includes:
A., rotational cycle is set.In the present embodiment, can be arranged per N number of block (such as N=10000) is a rotation
Period will choose a collection of high quality node again for each rotational cycle.
B. when reaching the election contest starting point in the rotational cycle, pass through the alternate node of POW algorithms selection preset quantities.
In the present embodiment, the election contest starting point, which is block height, can be divided exactly by N/2 and evenly divisible by N (such as cannot can be divided exactly by 5000
And cannot be divided exactly by 10000) when, that is, when the rotational cycle proceeds to half, the time for being left half of rotational cycle is used
To do the selection of the alternate node.At this point, all nodes do POW operations to the block of the election contest starting point, and tied calculating
A transaction is sent to preset open system account after fruit, turnover can be arbitrary value (being recommended as the minimum allowed),
Operation result is attached in the extension fields of transaction, subsequent check validity is used for.Then, it is looked into from the account
Effective transaction is looked for, the alternate node is added by trading order.
C. when next rotational cycle starts, currently used common recognition node is replaced with the alternate node.?
In the present embodiment, each rotational cycle is corresponding with the common recognition node of preset quantity.When next rotational cycle is opened
When the beginning, currently used common recognition node failure is replaced with new a batch common recognition node with the selected alternate node, is used for
Handle the common recognition work of the rotational cycle.
(2) common recognition processing is traded between the node chosen.In the present embodiment, it is opened in each rotational cycle
When the beginning, according to replaced common recognition node, after transaction is packaged as block, reach between these replaced common recognition nodes altogether
Know.
The detailed description of above-mentioned steps please refers to following second embodiments, and details are not described herein.
Second embodiment
As shown in fig.2, second embodiment of the invention proposes a kind of block chain common recognition processing method.In the present embodiment,
The execution sequence of the step in flow chart shown in Fig. 2 can change according to different requirements, and certain steps can be omitted.This
Outside, the Conventional processing steps in relation to block catenary system can be included in the present invention according to practical application scene.This method includes following
Step:
Step S10, according to the high quality of periodical rotation mechanism and POW algorithm picks preset quantities from block catenary system
Node.
As shown in fig.3, for the specific refined flow chart of the step.In the present embodiment, which specifically includes:
Rotational cycle is arranged in step S100.
Specifically, in order to which the fairness and the high availability for ensureing node, selected common recognition node that ensure election will adopt
Take periodical rotation mechanism.In the present embodiment, it is a rotational cycle that can be arranged per N number of block (such as N=10000),
For each rotational cycle, a collection of high quality node will be chosen again as common recognition node.
Step S102 passes through the standby of POW algorithms selection preset quantities when reaching the election contest starting point in the rotational cycle
Select node.
In the present embodiment, the election contest starting point be block height can be divided exactly by N/2 and cannot it is evenly divisible by N (such as can quilt
5000 divide exactly and cannot be divided exactly by 10000) when, that is, when the rotational cycle proceeds to half, it is left half of rotational cycle
Time be used for doing the selection of the alternate node.At this point, all nodes do POW operations to the block of the election contest starting point, and
A transaction is sent to preset open system account (POW target accounts) after calculating result, turnover can be arbitrary value
(being recommended as the minimum allowed), operation result is attached in the extension fields of transaction, effective for subsequent check
Property.Then, effective transaction (i.e. operation result is correctly merchandised) is searched from the account, is added by trading order described standby
Select node.
Specifically, in block catenary system, for each node, there are three types of states:Peer, Validator and
Candidate.Wherein, Peer nodes are still not selected node, are responsible for block synchronization and transaction forwarding;Validator is saved
Point is the node elected, is used to carry out block common recognition in next step;Candidate nodes are the standby of Validator nodes
Use node.Validator nodes still possess with Candidate nodes the block of Peer nodes it is synchronous and transaction forwarding capability.
When reaching the election contest starting point in the rotational cycle, all nodes do POW fortune to the block of the election contest starting point
It calculates, concrete operation is to find a random number nonce, is met:
SHA256(SHA256(block_header_hash||nonce))<=2^M,
Wherein M is the positive integer less than 256, indicates degree-of-difficulty factor, and M can be 240 in the present embodiment.
The node for calculating nonce sends a transaction to preset open system account at once, and operation result is attached
It is added in the extension fields of transaction, the validity for the subsequent check transaction.The purpose of the POW operations be in order to
The network environment and computing environment for examining each node, subsequently receive the sequence of the transaction according to the account, can sentence
Break and the arithmetic speed of each node, to pick out the node of high quality.
In the present embodiment, each node needs to preserve three tables and mesh information.Three tables are appointed for present node
The effective node listing of duty table, current period, effective node of next period (i.e. alternate node) list.Wherein:
Table 1:Present node tenure table
In the present node holds a post table, ID is Validator node serial numbers, and Validator is that each ID is corresponding
Validator node address, Candidate are the corresponding Candidate node address of each Validator nodes.It is described
The quantity of Validator nodes can need to set according to what is currently merchandised, and being 4 in table 1 with Validator number of nodes is
Example.The Validator nodes and Candidate nodes are the effective node of current period, that is, current rotational cycle makes
Common recognition node.When the present node tenure table is that each rotational cycle starts, carried out according to following table 2 and table 3
It fills in.
Table 2:The effective node listing of current period
ID |
ADDR |
IP |
BLOCK_POS |
TX_POS |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In the effective node listing of the current period, ID is the sequencing that the account receives transaction, and ranking is leaned on
Preceding transaction id is also located further forward, and corresponding node also can preferentially be chosen as Validator nodes.ADDR is node address, and IP is section
The IP address of point, BLOCK_POS, which is POW, proves the transaction (friendship with POW operation results that i.e. node is sent to the account
Block height where easily), TX_POS, which is POW, proves the transaction id of exchange within a block, for verifying whether the node is conjunction
Method node.It is obtained from the transaction (POW proves transaction) that the account receives according to the effective node listing of current period
The information solicitation taken, since these transaction are by common recognition, the result of all querying nodes is identical.
Table 3:Next period effective node listing
ID |
ADDR |
IP |
BLOCK_POS |
TX_POS |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In next period effective node listing, ID is the sequencing that the account receives transaction, and ranking is leaned on
Preceding transaction id is also located further forward, and corresponding node also can preferentially be chosen as Validator nodes.ADDR is node address, and IP is section
The IP address of point, BLOCK_POS, which is POW, proves exchange in block height, and TX_POS, which is POW, proves exchange within a block
Transaction id, for verifying whether the node is legitimate node.Effective node listing of next period is also according to from the account
The information solicitation obtained in the transaction (POW proves transaction) that family receives, since these transaction are by common recognition, Suo Youjie
The result of point inquiry is identical.
After reaching the election contest starting point in the rotational cycle, the account receives the POW that each node is sent successively
It proves to search effective transaction during transaction, all nodes are merchandised from subregion where the account, it will be corresponding legal by trading order
Node is added in table 3.
Wherein, each Validator nodes cannot be reappointed or reelected consecutively, that is, identical node cannot be in continuous two rotational cycles
In serve as Validator nodes.By taking Validator number of nodes in table 1 is 4 as an example, i.e., preceding 4 nodes in table 2 cannot
It is packed into the position of preceding 4 nodes in table 3.Even if preceding 4 nodes in table 2 are current in the account, there are rankings again
Forward effective transaction also will prevent Validator nodes from connecting during inserting table 3 from the 5th position start recording
Appoint.
Step S104 replaces currently used common recognition with the alternate node when next rotational cycle starts
Node.
In the present embodiment, each rotational cycle is corresponding with the common recognition node of preset quantity.When next described
When rotational cycle starts, it is total to replace with new a batch with the selected alternate node for currently used common recognition node failure
Node is known, for handling the common recognition work of the rotational cycle.
Specifically, after current rotational cycle, when next rotational cycle starts, former table 2 is replaced with table 3, i.e.,
Selected alternate node becomes the effective common recognition node of next rotational cycle.In addition, according to required
The quantity of Validator nodes obtains the Validator of respective numbers respectively from replaced table 2 (former table 3) in sequence
Node and Candidate nodes insert table 1.For example, by taking required Validator nodes are 4 as an example, by replaced table 2
In preceding 4 nodal informations filling table 1 the parts Validator, the parts Candidate of the 5th~8 nodal information filling table 1.
Fig. 2, step S20 are returned to, common recognition processing is traded between the node chosen.
In the present embodiment, when each rotational cycle starts, according to replaced common recognition node, transaction is packaged
After block, reach common understanding between these replaced common recognition nodes.
Specifically, it when each rotational cycle starts, is known together by the Validator node networkings in table 1.
Any one consistency common recognition algorithm may be used in the common recognition, in the present embodiment by taking PBFT as an example.Selected
Validator nodes are packaged transaction and generate block, and know together to block in validator nodes.Know together successful area
Block can be stored into validator nodes local block chain, other nodes can also synchronize newest block from validator nodes.
When some validator node can not be normally carried out common recognition work, other nodes will select this from public table 1
The corresponding candidate nodes of validator nodes are replaced.Also, the corresponding candidate nodes are as new
Validator nodes before, will also from table 2 the legal next node of sequential selection as new validator
The corresponding candidate nodes of node.By taking Validator number of nodes in table 1 is 4 as an example, when some validator node
When can not be normally carried out common recognition work, other nodes will select this validator node corresponding from table 1
Candidate nodes are replaced, and select the 9th node corresponding as new validator nodes from table 2
Candidate nodes.
Block chain common recognition processing method provided in this embodiment, can realize a kind of common recognition of layering in block catenary system
Probabilistic consistency common recognition algorithm is combined with absolute consistency common recognition algorithm, is first passed through in large-scale network node by mechanism
The probabilistic consistency common recognition relatively few number of node of algorithm picks, then recycles absolute consistency to know together algorithm in selected section
It is efficiently known together to common recognition content in point.Also, selected node is based on block chain in the form of periodical rotation mechanism
Common recognition itself ensure that the common recognition of data in following rotational cycle.This programme both can be adapted for large-scale distributed network
In, while block can also be efficiently produced, the availability of block catenary system is improved, and extend being applicable in for block catenary system
Range allows block catenary system bottom to meet the needs of more kinds of business scenarios.
3rd embodiment
The present invention also provides another embodiments, that is, provide a kind of computer readable storage medium, the computer
Readable storage medium storing program for executing is stored with block chain common recognition processing routine 10, and the block chain common recognition processing routine 10 can be by least one place
It manages device to execute, so that at least one processor is executed such as the step of above-mentioned block chain common recognition processing method.
Through the above description of the embodiments, those skilled in the art can be understood that above-described embodiment side
Method can add the mode of required general hardware platform to realize by software, naturally it is also possible to by hardware, but in many cases
The former is more preferably embodiment.Based on this understanding, technical scheme of the present invention substantially in other words does the prior art
Going out the part of contribution can be expressed in the form of software products, which is stored in a storage medium
In (such as ROM/RAM, magnetic disc, CD), including some instructions are used so that a client (can be mobile phone, computer, electronics
Device, air conditioner or network equipment etc.) execute method described in each embodiment of the present invention.
It these are only the preferred embodiment of the present invention, be not intended to limit the scope of the invention, it is every to utilize this hair
Equivalent structure or equivalent flow shift made by bright specification and accompanying drawing content is applied directly or indirectly in other relevant skills
Art field, is included within the scope of the present invention.