Specific embodiment
In order to enable those skilled in the art to better understand the solution of the present invention, below in conjunction in the embodiment of the present invention
Attached drawing, technical scheme in the embodiment of the invention is clearly and completely described, it is clear that described embodiment is only this
Invention a part of the embodiment, instead of all the embodiments.Based on the embodiments of the present invention, those of ordinary skill in the art exist
Every other embodiment obtained under the premise of creative work is not made, shall fall within the protection scope of the present invention.
Embodiment of the method one
Referring to Fig. 1, which is the sharding method flow chart for the block chain that the application embodiment of the method one provides.
The sharding method of block chain provided by the embodiments of the present application, comprising:
S101: when block chain network is added in new node, existing node of the new node into the block chain network
Subregion acquisition request is sent, so that the existing node is informed according to the subregion acquisition request to new node feedback subregion
Response.
S102: the new node informs the arrival time of response according to the subregion, receives the K subregion reached at first and accuses
Know response.
S103: subregion informs response to the new node based on the received, using k nearest neighbor sorting algorithm, determines target network
Subregion.
S104: the new node is added in the target network subregion.
The above are the application embodiment of the method one provide block chain sharding method specific execution step, for the ease of
The specific embodiment of the sharding method for the block chain that explanation and understanding the application embodiment of the method one provides, will successively be situated between below
Continue S101, S102 and S103.
The specific embodiment of S101 is introduced first.
In S101, block chain network includes at least one network partition, moreover, each network partition includes at least one
Existing node;Wherein, existing node refers to included node in current time, block chain network.
For the ease of explanation and understanding S101, below will in one embodiment for be introduced.
As an implementation, S101 is specifically as follows:
S1011: when block chain network is added in new node, existing node of the new node into the block chain network
Subregion acquisition request is sent respectively.
Subregion acquisition request is the request that the existing node from new node to be added into block chain network is sent, and
And subregion acquisition request is used to that the existing node in block chain network to be requested to inform the network partition belonging to it.
New node can all have node into block chain network and send subregion acquisition request, to obtain block link network
Network partition belonging to all existing nodes in network.Thus, as an implementation, when in block chain network include it is N number of
When having node, S1011 is specifically as follows: when block chain network is added in new node, the new node is to the block chain network
In N number of existing node send subregion acquisition request respectively.
The above are a kind of embodiments of S1011, and in this embodiment, new node can be into block chain network all
Existing node sends subregion acquisition request, can so obtain network partition belonging to all existing nodes in block chain network,
Be conducive to improve the accuracy of network partition belonging to determining new node.
In addition, new node, which can also have node to the part in block chain network, sends subregion acquisition request, to obtain
Know partially have network partition belonging to node in block chain network.Wherein, the part in block chain network has node and refers to
For determining that network partition belonging to new node is highly important node, and the existing node in the part can be according to default choosing
Algorithm acquisition is selected, and default selection algorithm can be any selection algorithm.
Thus, as another embodiment, when in block chain network including N number of existing node, S1011 specifically can be with
Are as follows: when block chain network is added in new node, selected from N number of existing node in block chain network according to default selection algorithm
M existing nodes out, and subregion acquisition request is sent respectively from new node to the M existing nodes;Wherein, M≤N, M are positive whole
Number.
The above are the another embodiments of S1011, in this embodiment, can select first with default selection algorithm
Important part has node out, then has node to the part from new node and send subregion acquisition request, so can
The efficiency for determining network partition belonging to new node is improved, to improve the sharding method execution efficiency of block chain.
S1012: when the existing node in block chain network receives subregion acquisition request, then the existing node is according to this
Subregion acquisition request generates subregion and informs response, and the subregion is informed that response feeds back to new node.
Subregion informs that response is to be generated according to subregion acquisition request by the existing node in block chain network and fed back to newly
The response of node, moreover, subregion inform response for by network partition belonging to the existing node in block chain network inform to
New node.In this way, subregion informs that response may include network partition belonging to the existing node.
As an example, the first existing node in block chain network receives subregion acquisition request, and first has section
When point belongs to first network subregion, then S1012 is specifically as follows: subregion acquisition request generates the first existing node based on the received
Subregion informs response, so that the subregion informs that response includes first network subregion;Moreover, the first existing node will include the first net
The subregion of network subregion informs that response feeds back to new node.
The above are the specific embodiments of S101, in this embodiment, described when block chain network is added in new node
Existing node of the new node into the block chain network sends subregion acquisition request, so that the existing node is according to described point
Area's acquisition request informs response to new node feedback subregion.
The specific embodiment of S102 is described below.
In block chain network, the distance between different nodes can be determined according to the call duration time between different nodes,
Specifically: if the call duration time between two nodes is shorter, and the distance between two nodes are closer.Thus, in this application,
The subregion that existing node is sent can be received according to new node informs the time point of response to determine new node and existing node
Distance, specifically: if new node receives the subregion that existing node is sent and informs that the time of response is more early, it is determined that new node
Has the distance between node relatively closely with this;If new node receive the subregion that existing node is sent inform time of response compared with
Evening, it is determined that the distance between new node and the existing node are farther out.
It, can basis based on above content it is found that in order to enable the node being closer can belong to the same subregion
Network partition belonging to the existing node being closer with new node determines network partition belonging to the new node, thus, in order to
The efficiency of network partition belonging to determining new node is further increased, can only be obtained in this application closer apart from new node
Network partition belonging to existing node, it is, new node only needs point for receiving to send apart from its closer existing node
Inform response in area.
In addition, subregion informs that the arrival time of response refers to that new node receives the subregion and informs response in S102
Time point.
K is positive integer, and K can be preset, for example, K can be determined according to application scenarios.
As an example it is supposed that then S102 is specifically as follows when K is 10: when the M existing nodes in block chain network to
New node sends subregion and informs that then new node informs the arrival time of response according to the subregion that the M node is sent when responding, and connects
It receives 10 subregions reached at first and informs response;Wherein, M >=10.
The above are the specific embodiments of S102, and in this embodiment, new node informs response according to the subregion
Arrival time receives the K subregion reached at first and informs response.It is rung in this way, new node can be informed with K subregion based on the received
Answer, can know network partition belonging to the K nearest apart from the new node existing nodes, in order to it is subsequent can be according to the K
Network partition belonging to a existing node determines network partition belonging to new node, can be realized the node that will be closer and draws
Divide to the purpose of the same subregion.
The specific embodiment of S103 is described below.
In S103, target network subregion is for indicating network partition belonging to new node.
The process of k nearest neighbor sorting algorithm can be with are as follows: according to network point belonging to the K nearest apart from new node existing nodes
The network partition most including neighboring node is selected in area, so as to using the network partition being selected as new node institute
The network partition of category.
In addition, k nearest neighbor sorting algorithm can be any category that can determine target object according to the attribute of neighbour's object
The algorithm of property.
It for the ease of explanation and understanding S103, is illustrated below in conjunction with Fig. 2, wherein Fig. 2 mentions for the embodiment of the present application
A kind of schematic diagram of embodiment of the S103 of confession.
It include three network partitions in block chain network shown in Fig. 2: first network partition, 201, second networks point
Area 202 and third network partition 203, wherein first network partition 201 includes 9 existing nodes, second network partition
202 include 7 existing nodes and third network partition 203 includes 7 existing nodes.
Assuming that can then determine when K is 5 apart from new node Pnew5 nearest existing nodes are as follows: the first existing node
P1, the second existing node P2, third have node P3, the 4th existing node P4With the 5th existing node P5.At this point, S103 specifically may be used
With are as follows: due to the first existing node P1, the second existing node P2Has node P with third3First network partition 201 is belonged to,
And the 4th existing node P4Belong to second network partition 202, and the 5th existing node P5Belong to third network partition 203, because
This, it is known that is in new node Pnew5 neighboring nodes in, 3 nodes belong to 201,1 node of first network subregion and belong to second
202,1 node of network partition belongs to third network partition 203, it follows that k nearest neighbor sorting algorithm will select to include neighbour
The most first network subregion 203 of node is used as new node PnewAffiliated network partition, that is, target network subregion.
The above are the specific embodiments of S103, in this embodiment, can K subregion is accused based on the received with new node
Know response, using k nearest neighbor sorting algorithm, determines target network subregion.Since k nearest neighbor sorting algorithm can be according to K neighbour
There is network area belonging to node, select the network partition most including neighboring node, to divide the network being selected
Area is as network partition belonging to new node, in this way, ensure that new node can be added to the net most including its neighboring node
Network subregion, realize the purpose that the node that will be closer is divided to the same subregion.
The above are the specific embodiments of the sharding method of the block chain of the offer of embodiment of the method one, preferably
In, it is responded by being informed according to the received K subregion of new node, using k nearest neighbor sorting algorithm, determines target network subregion, with
Just new node is added in the target network subregion.Since the received K subregion of new node informs that response is by block chain network
What the K existing nodes nearest apart from new node were sent, and k nearest neighbor sorting algorithm can will include that its neighboring node is most
New node can be divided to using k nearest neighbor sorting algorithm and be saved including its neighbour as target network subregion by network partition
In the most network partition of point, the node being closer is enabled to be divided to the same network partition, improves network point
Communication efficiency in area between different nodes, and then improve transaction processing efficiency in network partition.In addition, block chain network packet
Include multiple network partitions, each network partition enabled to handle transaction by oneself, enable each fragment parallel processing not
Same transaction to improve the concurrency of trading processing and confirmation, and then improves the handling capacity of entire block chain network.
It should be noted that new node just becomes target network point after new node is added to target network subregion
Existing node in area.
Sharding method based on the block chain that embodiment of the method one provides, in order to avoid included in heterogeneous networks subregion
The number of existing node is excessive, and present invention also provides the sharding methods of another block chain, are solved below in conjunction with attached drawing
It releases and illustrates.
Embodiment of the method two
Embodiment of the method is second is that the improvement carried out on the basis of embodiment of the method one, for the sake of brevity, method are implemented
The part identical with content in embodiment of the method one of example two, details are not described herein.
Referring to Fig. 3, which is the flow chart of the sharding method for the block chain that the application embodiment of the method two provides.
The sharding method of block chain provided by the embodiments of the present application, comprising:
S301: when block chain network is added in new node, existing node of the new node into the block chain network
Subregion acquisition request is sent, so that the existing node is informed according to the subregion acquisition request to new node feedback subregion
Response.
S302: the new node informs the arrival time of response according to the subregion, receives the K subregion reached at first and accuses
Know response.
S303: subregion informs response to the new node based on the received, using k nearest neighbor sorting algorithm, determines target network
Subregion.
S304: the new node is added in the target network subregion.
The specific embodiment of S301 to S304 is identical as the specific embodiment of S101 to S104 respectively, in order to briefly rise
See, details are not described herein.
S305: judging whether the number of nodes of the target network subregion reaches the first preset threshold, if so, executing
S306;If it is not, then executing S307.
S306: the target network subregion is split into first network subregion and the second network partition.
S307: terminate the process that block chain network is added in the new node currently carried out.
The above are the application embodiment of the method two provide block chain sharding method specific execution step, for the ease of
The specific embodiment of the sharding method for the block chain that explanation and understanding the application embodiment of the method two provides, will successively be situated between below
Continue S305 and S306.
The specific embodiment of S305 is introduced first.
In S305, the first preset threshold can be preset, for example, the first preset threshold can be true according to application scenarios
It is fixed.
As an example, then S305 is specifically as follows: judging the target network subregion when the first preset threshold is 15
Whether number of nodes reaches 15, if so, executing S306;If it is not, then executing S307.
The above are the specific embodiments of S305.
The specific embodiment of S306 is described below.
As an implementation, S306 is specifically as follows:
S3061: electing the management node (referred to as, leader) of the target network subregion using default election algorithm,
As the first management node.
Management node is for being managed network area fission process or merging process belonging to the management node.
Default election algorithm can be it is any for electing the algorithm of management node, for example, default election algorithm can be with
It is Paxos-like algorithm.
For the ease of explanation and understanding Paxos-like algorithm, it is introduced below in conjunction with Fig. 4.
The voting rule of Paxos-like algorithm is specifically as follows:
(1) timestamp of target network subregion is added as the mark id of the node in each node.
(2) in every wheel voting process, each node elects a leader, and will include node election
The vote information of the id ballot round corresponding with the current ballot process of the node of leader, the node is broadcasted, also
It is that vote information is sent to other nodes other than the node in target network subregion by the node.
(3) each node is when carrying out the first round of voting, it will usually elect oneself as leader.
(4) each node will vote, moreover, the throwing in the non-first round of voting according to its received vote information
Ticket process specifically: when first node receives the first vote information, first have to see included ballot in the first vote information
Round, if ballot round included by the first vote information is greater than the current ballot round of first node, by the first ballot
Newest ballot round of the ballot round included by information as first node, and it is small to empty all ballot rounds on first node
In the polled data of newest ballot round;Further according to the corresponding polled data election of current ballot round existing on first node
Leader, and the voting results of first node are updated using the leader of the election, so that first node is by current ballot round
Corresponding vote information is broadcasted.Wherein, the voting results of first node are according to the id of voter (it is, other nodes
Id) determine, voter id is big to win, and voter id is consistent determines according to the id of the leader of vote by ballot,
The id of leader is big to win.
It should be noted that above-mentioned voting process is illustrated so that first node receives the first vote information as an example
, in this application, each node in target network region can be carried out using above-mentioned voting process, in order to briefly rise
See, details are not described herein.
(4) if some node has had collected the poll of all nodes in a certain wheel ballot, or a certain
There are the voting results of half to be directed toward the same leader in wheel ballot, then the node can select directly to receive the ballot knot
Fruit, and the state of oneself is become no longer to receive new voting results, the node receives any ballot later, only can will really
Fixed voting results are broadcasted.
(5) when some node has determined voting results and no longer receives new voting results, even if there is id very little
Node attempts to elect oneself to be leader, other nodes can only return to determining voting results, which can only abandon
The election of leader.
The above are the related contents of Paxos-like algorithm.
S3062: it according to the distance of existing nodes all in the target network subregion to first management node, obtains
The existing node farthest to the first management node distance, as the second management node.
For the ease of explanation and understanding S3062, will be introduced by taking target network subregion shown in fig. 5 as an example below,
In, Fig. 5 is that target network subregion provided by the embodiments of the present application divides schematic diagram.
Target network subregion 50 shown in fig. 5 includes 15 nodes, wherein PM1It is exactly the first management node, at this point,
S3062 is specifically as follows: calculating and compares in target network subregion 50 in addition to the first management node PM1Other 14 sections in addition
O'clock to the first management node PM1Distance, obtain node PM2It is to the first management node PM1The farthest existing node of distance, and will
Node PM2As the second management node.
S3063: using first management node as the management node of first network subregion, and second management is saved
Management node of the point as the second network partition.
As an example, as shown in figure 5, S3063 is specifically as follows: by the first management node PM1As first network point
The management node in area 501, and by the second management node PM2Management node as the second network partition 502.
S3064: distance and institute of all existing nodes to first management node in the target network subregion
All existing nodes in target network subregion are stated to the distance of second management node, and it will be apart from first management node
Closer existing node is added to first network subregion, and will be added to apart from the closer existing node of second management node
Two network partitions.
As an example, as shown in figure 5, S3064 is specifically as follows: all distances first in target network subregion 50 are managed
Manage node PM1Closer existing node is added in first network subregion 501, and by all distances in target network subregion 50
Second management node PM2Closer existing node is added in the second network partition 502.
The above are 306 specific embodiments, in this embodiment, target network subregion can be divided into two points
Area.
The above are the specific embodiments of the sharding method of the block chain of the offer of embodiment of the method two, preferably
In, after the target network subregion is added in the new node, it is also necessary to which judging the number of nodes of the target network subregion is
It is no to reach the first preset threshold;When the number of nodes of the target network subregion reaches the first preset threshold, the target network
Subregion is split into first network subregion and the second network partition.It so, it is possible to guarantee each network partition in block chain network
Number of nodes be no more than the first preset threshold, the network partition more including node is avoided the occurrence of, to advantageously ensure that every
The ability of a network partition processing transaction keeps powerful and stablizes, and then improves the handling capacity of entire block chain network.
It should be noted that the process of block chain network and the target network point of an old wheel are added when the new node of a new round
When area's fission process occurs simultaneously, the new node that node included by the target network subregion of an old wheel is not involved in a new round is added
The process of block chain network.
Sharding method based on the block chain that above method embodiment one and embodiment of the method two provide, the embodiment of the present application
The sharding method of another block chain is additionally provided, is explained and illustrated below in conjunction with attached drawing.
Embodiment of the method three
Embodiment of the method third is that the improvement carried out on the basis of embodiment of the method two or embodiment of the method one, for the ease of
Explanation and illustration will be illustrated by taking the improvement carried out on the basis of embodiment of the method two as an example below, moreover, method is implemented
The part identical with two content of embodiment of the method for example three, for the sake of brevity, details are not described herein.
Referring to Fig. 6, which is the flow chart of the sharding method for the block chain that the application embodiment of the method three provides.
The sharding method of block chain provided by the embodiments of the present application, comprising:
S601: when block chain network is added in new node, existing node of the new node into the block chain network
Subregion acquisition request is sent, so that the existing node is informed according to the subregion acquisition request to new node feedback subregion
Response.
S602: the new node informs the arrival time of response according to the subregion, receives the K subregion reached at first and accuses
Know response.
S603: subregion informs response to the new node based on the received, using k nearest neighbor sorting algorithm, determines target network
Subregion.
S604: the new node is added in the target network subregion.
S605: judging whether the number of nodes of the target network subregion reaches the first preset threshold, if so, executing
S606;If it is not, then executing S607.
S606: the target network subregion is split into first network subregion and the second network partition.
S607: terminate the process that block chain network is added in the new node currently carried out.
The specific embodiment of S601 to S607 is identical as the specific embodiment of S301 to S307 respectively, in order to briefly rise
See, details are not described herein.
S608: after old node is exited from third network partition, third management node is into the block chain network
Other network partitions in addition to the third network partition send heartbeat signal.
S609: other network partitions in block chain network in addition to the third network partition are according to the heartbeat signal
Generate feedback signal.
S610: whether third management node judges that the feedback signal is carried and merges with the third network partition
Information, if so, execute S611;If it is not, then executing S613.
S611: the third management node determines network to be combined point according to the corresponding network partition of the feedback signal
Area.
S612: the third network partition and the network partition to be combined are merged.
S613: the current state of third network partition is kept.
It should be noted that the execution sequence of S601 to S607 and S608 to S613 is not fixed, S608 can be first carried out extremely
S613, then S601 is executed to S607;S601 to S607 can also be first carried out, then executes S608 to S613;It can also only carry out
S601 to S607 does not execute S608 to S613;S608 to S613 can also be executed, does not execute S601 to S607, the application is to this
It is not specifically limited.
The above are the application embodiment of the method three provide block chain sharding method specific execution step, for the ease of
The specific embodiment of the sharding method for the block chain that explanation and understanding the application embodiment of the method three provides, will successively be situated between below
Continue S608, S609 and S611.
The specific embodiment of S608 is introduced first.
In S608, third management node is the management node of the third network partition, moreover, for managing third net
The division of network subregion merges related matters.
Heartbeat signal is used for other networks of third network partition into block chain network other than third network partition
Subregion informs number of nodes included by third network partition, thus, heartbeat signal carries the node of the third network partition
Number.
Third management node can into block chain network in addition to the third network partition all-network subregion hair
Heartbeat signal is sent, thus, as an implementation, when block chain network includes N number of network partition, then S608 specifically can be with
Are as follows: after old node is exited from third network partition, third management node removes the third network into block chain network
N-1 network partition other than subregion sends heartbeat signal.
In order to further increase the division efficiency of network partition, and it is same to guarantee that the node being closer can be divided into
In network partition, heartbeat signal only can be sent apart from the closer network partition of third network partition into block chain network, because
And present invention also provides the another embodiments of S608, in this embodiment, S608 is specifically as follows:
The third management node sends heartbeat signal to the network partition of preset quantity, wherein the preset quantity
Network partition is the distance chosen from other network partitions in the block chain network in addition to the third network partition
The nearest network partition of the third network partition.
In addition, preset quantity can be preset, determined for example, preset quantity can be according to application scenarios.
The distance between two network partitions can be according to the flat of the distance between the node for belonging to heterogeneous networks subregion
Mean value or adduction.
For example, it is assumed that first network subregion includes first node and second node, the second network partition includes third node
And fourth node, then can by the distance between the distance between first node and third node, first node and fourth node,
The distance between second node and third node and the distance between second node and fourth node sum up, and according to adduction
Resulting result determines the distance between first network subregion and the second network partition.
The above are the specific embodiments of S608, in this embodiment, when old node is exited from third network partition
Later, other network partitions of third management node into the block chain network in addition to the third network partition send the heart
Jump signal.
The specific embodiment of S609 is described below.
In S609, feedback signal carries the information whether merged with the third network partition.
It should be noted that the network partition for each receiving heartbeat signal is performed both by S609's in block chain network
All specific embodiments.
As an implementation, S609 is specifically as follows (for each network partition for receiving heartbeat signal
To execute S6091-S6094):
S6091: by the node of the number of nodes of third network partition and current network subregion entrained by the heartbeat signal
Number sums up, and obtains number of nodes summation.
S6092: number of nodes summation is judged whether less than the second preset threshold, if so, executing S6093;If it is not, then executing
S6094。
Wherein, second preset threshold is less than first preset threshold, moreover, the second preset threshold can be set in advance
It is fixed.For example, the second preset threshold can be 0.75 times of the first preset threshold.
S6093: the feedback signal for carrying the information merged with the third network partition is generated.
S6094: the feedback signal for not carrying the information merged with the third network partition is generated.
It should be noted that in order to avoid a network partition to other multiple network partitions while including pooling information
The network partition can also be set as preparing to close by feedback signal while " generating the feedback signal including pooling information "
And state, at this point, the heartbeat message of other no longer corresponding network partitions so can be avoided network point by the network partition
Area and multiple network partitions merge generation, ensure that accuracy and unicity that subregion merges.
The above are the specific embodiments of S609, in this embodiment, except the third network point in block chain network
Other network partitions other than area generate feedback signal according to the heartbeat signal, wherein include whether in feedback signal and the
The information that three network partitions merge.
The specific embodiment of S611 is described below.
As an implementation, when the third management node receives carrying at least one network partition transmission
When the feedback signal of the information merged with the third network partition, S611 is specifically as follows: the third management node
Using the corresponding network partition of the feedback signal being initially received as network partition to be combined.
As an example it is supposed that third management node is sequentially received first network subregion, the second network partition and the 4th net
The feedback signal for carrying the information merged with the third network partition that network subregion is sent, then S611 specifically can be with
Are as follows: it is closed since third management node is initially received carrying for first network subregion transmission with the third network partition
And information feedback signal, thus, third management node determine first network subregion be network partition to be combined.
It, can be with it should be noted that in order to avoid multiple network partitions wait third network partition and merge simultaneously
It after network partition to be combined has been determined, sets third network partition to prepare merging phase, at this point, when in addition to be combined
Other network partitions other than network partition are carried to the transmission of third network partition to be merged with the third network partition
Information feedback signal when, third network partition will to other network partitions send carry merge failure information feedback
Signal, to set general state for other network partitions other than network partition to be combined, at this point, other networks
Subregion can continue to receive the heartbeat signal of other network partitions transmission.
The above are the specific embodiments of S611, and in this embodiment, third management node can be according to the feedback
The corresponding network partition of signal determines network partition to be combined.
The above are the specific embodiments of the sharding method of the block chain of the offer of embodiment of the method three, preferably
In, after old node is exited from third network partition, third management node removes the third into the block chain network
Other network partitions other than network partition send heartbeat signal, so that other described network partitions are raw according to the heartbeat signal
It is at feedback signal, and when the feedback signal carries the information merged with the third network partition, then described
Third management node determines network partition to be combined according to the corresponding network partition of the feedback signal, and by the third network
Subregion is merged with the network partition to be combined.It so, it is possible to guarantee that each network partition in block chain network is wrapped
The number of nodes included is not less than the second preset threshold, the appearance of smaller network partition is avoided, to ensure that heterogeneous networks subregion
The capacity variance for handling transaction is smaller, ensure that and has advantageously ensured that the ability of each network partition processing transaction keeps powerful
And stablize, and then improve the handling capacity of entire block chain network.
It should be noted that in this application, if the process of block chain network is added in new node, network partition divides
At least two implementation procedures during process and network partition merge occur simultaneously, then each process is independent progress
, moreover, each network partition is only capable of participating in an implementation procedure, two implementation procedures cannot be simultaneously participated in.It can so keep away
Exempt from the interference between different implementation procedures, ensure that going on smoothly for different implementation procedures.
Sharding method based on the block chain that above method embodiment one to embodiment of the method two provides, the embodiment of the present application
A kind of specific embodiment of sharding method of block chain is additionally provided, is explained and illustrated below in conjunction with attached drawing.
Embodiment of the method four
Embodiment of the method is fourth is that carry out on the basis of embodiment of the method three, embodiment of the method two or embodiment of the method one
It improves, for the ease of explanation and illustration, will be illustrated by taking the improvement carried out on the basis of embodiment of the method three as an example below,
Moreover, the part identical with three content of embodiment of the method for embodiment of the method four, for the sake of brevity, details are not described herein.
Referring to Fig. 7, which is the flow chart of the sharding method for the block chain that the application embodiment of the method four provides.
The sharding method of block chain provided by the embodiments of the present application, comprising:
S701: when new node be added block chain network when, judge new node whether be block chain network first node,
If so, executing S702;If it is not, then executing S703.
S702: new node is added in the first network subregion of block chain network, and is carried out to block chain network initial
Change.
S703: existing node of the new node into the block chain network sends subregion acquisition request, so as to described
Existing node informs response to new node feedback subregion according to the subregion acquisition request.
S704: the new node informs the arrival time of response according to the subregion, receives the K subregion reached at first and accuses
Know response.
S705: subregion informs response to the new node based on the received, using k nearest neighbor sorting algorithm, determines target network
Subregion.
S706: the new node is added in the target network subregion.
S707: judging whether the number of nodes of the target network subregion reaches the first preset threshold, if so, executing
S708;If it is not, then executing S709.
S708: the target network subregion is split into first network subregion and the second network partition.
S709: terminate the process that block chain network is added in the new node currently carried out.
S710: after old node is exited from third network partition, third management node is into the block chain network
Other network partitions in addition to the third network partition send heartbeat signal.
S711: other network partitions in block chain network in addition to the third network partition are according to the heartbeat signal
Generate feedback signal.
S712: whether third management node judges that the feedback signal is carried and merges with the third network partition
Information, if so, execute S713;If it is not, then executing S715.
S713: the third management node determines network to be combined point according to the corresponding network partition of the feedback signal
Area.
S714: the third network partition and the network partition to be combined are merged.
S715: the current state of third network partition is kept.
The specific embodiment of S703 to S715 is identical as the specific embodiment of S601 to S613 respectively, in order to briefly rise
See, details are not described herein.
The above are the application embodiment of the method four provide block chain sharding method specific execution step, for the ease of
The specific embodiment of the sharding method for the block chain that explanation and understanding the application embodiment of the method four provides, will successively be situated between below
Continue S701 and S702.
The specific embodiment of S701 is introduced first.
In S701, when new node is first node of block chain network, then it represents that the block chain network starts to create
It builds, at this point, any node is not present in block chain network, therefore, it is possible to new node is added directly into the block chain network,
And the new node is divided into first network subregion, so that the node of subsequent addition can be according to first of block chain network
Node determines the network partition belonging to it.
When new node is not first node of block chain network, then it represents that had at least one in the block chain network
A node, at this point, the new node it can be determined according to node existing in block chain network belonging to network partition.
The above are the specific embodiments of S701.
The specific embodiment of S702 is described below.
In S702, since new node is first node in block chain network, therefore, it is possible to be divided to first
In network partition, but also can be using the new node as the management node of first network subregion.
Moreover, first node as block chain network, new node are also responsible for the initial work of block chain network, and
And the initial work specifically includes (A) to (D):
(A) primary account is created, transaction is initiated by account.
(B) creation wound generation block.The starting of one new block chain needs to create first block, that is, wound generation block, wound
Some basic setups are needed to configure in generation block: (a) independent block chain network id, network id meeting when connecting other nodes
It uses, the node of different id networks can not be connected with each other;(b) mine complexity is dug, the efficiency that mine disaster degree determines out block is dug, it can
It is configured according to business demand;(c) primary account remaining sum.Initial phase, the remaining sum of primary account;(d) each block
Generate the upper limit for needing the resource consumed.The generation of each block needs to consume a certain number of token.
(C) block chain is initialized, the local directory that block chain related data saves is formulated.
(D) account and miner are bound, and starts to dig mine.
The above are the specific embodiments of S702, in this embodiment, will be as first node in block chain network
New node be added in the first network subregion of block chain network, and block chain network is initialized.
In addition, each network in each network partition occurs for common recognition mechanism in block chain network provided by the present application
Subregion carries out the related content of common recognition mechanism are as follows: (1) initiation traded every time initiates subregion belonging to node by transaction to execute
Common recognition;(2) existing common common recognition agreement, such as PBFT, PoW etc. can be used in the common recognition in subregion.PBFT is in fragment scale
It is smaller, and in the lesser situation of network overhead, higher efficiency can be reached, therefore in the lesser situation of fragment scale, this hair
It is bright to be recommended to use PBFT common recognition agreement to make full use of the advantage of fragment mechanism.(3) it after each subregion obtains common recognition, can will obtain
The transaction of common recognition is submitted to block chain, and is responsible for whether submitted transaction conflicts with transaction existing on block chain, once it hands over
It easily is submitted to block chain, is final state, it will not forked situation.
It should be noted that in this application, existing common recognition mechanism can be used in common recognition mechanism, it should be noted that each
The leader of a network partition is merely responsible for the related work that processing subregion merges and divides, and common recognition mechanism is not influenced, i.e.,
Node as leader does not have high priority in common recognition mechanism.
The above are the specific embodiments of the sharding method of the block chain of the offer of embodiment of the method four, preferably
In, when block chain network is added in new node, and new node is first node of block chain network, then new node is added to
In the first network subregion of block chain network, and block chain network is initialized.So realize the first of block chain network
Beginningization is conducive to subsequent to carry out embodiment of the method one using the block chain network of initialization and provide to embodiment of the method three
The sharding method of block chain.
Sharding method based on the block chain that above method embodiment one to embodiment of the method four provides, the embodiment of the present application
The slicing apparatus of block chain is additionally provided, is explained and illustrated below in conjunction with attached drawing.
Installation practice one
Referring to Fig. 8, which is the structural schematic diagram of the slicing apparatus for the block chain that the application Installation practice one provides.
The slicing apparatus of block chain provided by the embodiments of the present application, comprising:
Subregion acquisition request transmission unit 801, for when block chain network is added in new node, the new node to be to described
Existing node in block chain network sends subregion acquisition request, so as to the existing node according to the subregion acquisition request to
The new node feedback subregion informs response;Wherein, the block chain network includes at least one network partition;The network point
Area includes at least one described existing node;The subregion informs that response includes network partition belonging to the existing node;
Subregion informs response receiving unit 802, informs the arrival time of response according to the subregion for the new node,
It receives the K subregion reached at first and informs response;
Subregion determination unit 803, for the new node, K subregion informs response based on the received, is classified using k nearest neighbor
Algorithm determines target network subregion, so that the new node is added in the target network subregion.
It as an implementation, should in order to further increase the trading processing ability and handling capacity of block chain network
The slicing apparatus of block chain further include:
Judging unit, for judging the target network point after the target network subregion is added in the new node
Whether the number of nodes in area reaches the first preset threshold;
Divide unit, for when the number of nodes of the target network subregion reaches the first preset threshold, the target network
Network subregion is split into first network subregion and the second network partition.
As an implementation, in order to further increase the trading processing ability and handling capacity of block chain network, institute
Division unit is stated to specifically include:
Subelement is elected, for electing the management node of the target network subregion using default election algorithm, as
First management node;
Subelement is obtained, for according to existing nodes all in the target network subregion to first management node
Distance gets the farthest existing node of the first management node distance, as the second management node;
Subelement is set, for using first management node as the management node of first network subregion, and will described in
Management node of second management node as the second network partition;
Subelement is divided, for all existing nodes in the target network subregion to first management node
Distance, and will be apart from described first at a distance from all existing nodes to second management node in the target network subregion
The closer existing node of management node is added to first network subregion, will be apart from the closer existing node of second management node
It is added to the second network partition.
It as an implementation, should in order to further increase the trading processing ability and handling capacity of block chain network
The slicing apparatus of block chain further include:
Heartbeat signal transmission unit, for after old node is exited from third network partition, third management node to
Other network partitions in the block chain network in addition to the third network partition send heartbeat signal;Wherein, described
Three management nodes are the management node of the third network partition;The heartbeat signal carries the section of the third network partition
Points;
Feedback signal generating unit generates feedback signal according to the heartbeat signal for other described network partitions;Its
In, the feedback signal carries the information whether merged with the third network partition;
Subregion combining unit, for carrying the information merged with the third network partition when the feedback signal
When, then the third management node determines network partition to be combined according to the corresponding network partition of the feedback signal, and by institute
Third network partition is stated to merge with the network partition to be combined.
As an implementation, in order to further increase the trading processing ability and handling capacity of block chain network, institute
Feedback signal generating unit is stated, is specifically included:
Subelement is summed it up, for dividing the number of nodes of third network partition entrained by the heartbeat signal and current network
The number of nodes in area sums up, and obtains number of nodes summation;
Generate subelement, for when determining the number of nodes summation less than the second preset threshold, then generate carry with
The feedback signal for the information that the third network partition merges;Wherein, it is pre- to be less than described first for second preset threshold
If threshold value.
As an implementation, in order to further increase the trading processing ability and handling capacity of block chain network, institute
Combining unit is stated, is specifically included:
When the third management node receives carrying and the third network point at least one network partition transmission
When the feedback signal for the information that area merges, the third management node will be initially received described in carry and described
The corresponding network partition of the feedback signal for the information that three network partitions merge is as network partition to be combined, and by described
Three network partitions are merged with the network partition to be combined.
As an implementation, in order to further increase the trading processing ability and handling capacity of block chain network, institute
Heartbeat signal transmission unit is stated, is specifically included:
The third management node sends heartbeat signal to the network partition of preset quantity, wherein the preset quantity
Network partition is the distance chosen from other network partitions in the block chain network in addition to the third network partition
The nearest network partition of the third network partition.
The above are the specific embodiments of the slicing apparatus of the block chain of the offer of Installation practice one, preferably
In, it is responded by being informed according to the received K subregion of new node, using k nearest neighbor sorting algorithm, determines target network subregion, with
Just new node is added in the target network subregion.Since the received K subregion of new node informs that response is by block chain network
What the K existing nodes nearest apart from new node were sent, and k nearest neighbor sorting algorithm can will include that its neighboring node is most
New node can be divided to using k nearest neighbor sorting algorithm and be saved including its neighbour as target network subregion by network partition
In the most network partition of point, the node being closer is enabled to be divided to the same network partition, improves network point
Communication efficiency in area between different nodes, and then improve transaction processing efficiency in network partition.In addition, block chain network packet
Include multiple network partitions, each network partition enabled to handle transaction by oneself, enable each fragment parallel processing not
Same transaction to improve the concurrency of trading processing and confirmation, and then improves the handling capacity of entire block chain network.
It should be appreciated that in this application, " at least one (item) " refers to one or more, and " multiple " refer to two or two
More than a."and/or" indicates may exist three kinds of relationships, for example, " A and/or B " for describing the incidence relation of affiliated partner
It can indicate: only exist A, only exist B and exist simultaneously tri- kinds of situations of A and B, wherein A, B can be odd number or plural number.Word
Symbol "/" typicallys represent the relationship that forward-backward correlation object is a kind of "or"." at least one of following (a) " or its similar expression, refers to
Any combination in these, any combination including individual event (a) or complex item (a).At least one of for example, in a, b or c
(a) can indicate: a, b, c, " a and b ", " a and c ", " b and c ", or " a and b and c ", and wherein a, b, c can be individually, can also
To be multiple.
The above described is only a preferred embodiment of the present invention, being not intended to limit the present invention in any form.Though
So the present invention has been disclosed as a preferred embodiment, and however, it is not intended to limit the invention.It is any to be familiar with those skilled in the art
Member, without departing from the scope of the technical proposal of the invention, all using the methods and technical content of the disclosure above to the present invention
Technical solution makes many possible changes and modifications or equivalent example modified to equivalent change.Therefore, it is all without departing from
The content of technical solution of the present invention, according to the technical essence of the invention any simple modification made to the above embodiment, equivalent
Variation and modification, all of which are still within the scope of protection of the technical scheme of the invention.