CN109255057B - Block generation method, device, equipment and storage medium - Google Patents

Block generation method, device, equipment and storage medium Download PDF

Info

Publication number
CN109255057B
CN109255057B CN201811087256.5A CN201811087256A CN109255057B CN 109255057 B CN109255057 B CN 109255057B CN 201811087256 A CN201811087256 A CN 201811087256A CN 109255057 B CN109255057 B CN 109255057B
Authority
CN
China
Prior art keywords
block
time
node
weight
chain
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811087256.5A
Other languages
Chinese (zh)
Other versions
CN109255057A (en
Inventor
肖伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Baidu Netcom Science and Technology Co Ltd
Original Assignee
Beijing Baidu Netcom Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Baidu Netcom Science and Technology Co Ltd filed Critical Beijing Baidu Netcom Science and Technology Co Ltd
Priority to CN201811087256.5A priority Critical patent/CN109255057B/en
Publication of CN109255057A publication Critical patent/CN109255057A/en
Application granted granted Critical
Publication of CN109255057B publication Critical patent/CN109255057B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The embodiment of the invention discloses a block generation method, a block generation device, block generation equipment and a storage medium. The method comprises the following steps: when the initial processing time reaching the local node is detected, processing the transaction request through at least one transaction processing type thread to generate transaction data; and if the detection result reaches the packing point, packing the transaction data to be packed through a packing thread to generate a new block. The embodiment of the invention provides a trigger condition for the packaging thread to package the transaction data through detecting the packaging point, so that effective transaction data are recorded in most blocks of the uplink, hollow blocks or invalid blocks in a block chain are reduced, the rationality of processing and transmission resource utilization is improved, and the storage space is saved.

Description

Block generation method, device, equipment and storage medium
Technical Field
The embodiment of the invention relates to the technical field of block chains, in particular to a block generation method, a block generation device, a block generation equipment and a storage medium.
Background
With the continuous development of internet technology, a decentralized and transparent block chain technology is developed. The block chain technology adopts the data block to break the dependence of the current internet on a central server, all data generated in the network are recorded by the block generating node, and a new block is formed and is linked to the tail part of the block chain through the broadcast of the data and the verification of other nodes. After the uplink block is confirmed, the new block is permanently recorded in the block chain; otherwise, rolling back the data in the block for the block which can not be confirmed.
In the prior art, from the viewpoint of generality, regardless of the adopted consensus mechanism and parameter deployment manner, the generally adopted uplink block acknowledgement manner is that if a block is successfully uplink for 6 blocks, it indicates that the block is acknowledged, and the block can be permanently recorded in the block chain.
Correspondingly, the block-out time of the block directly affects the uplink confirmation speed of the transaction data, and the block-out time of each node is shortened, so that the confirmation of the block can be accelerated. However, since the transaction requests occurring in the conventional blockchain network are in a sparse state rather than a full load state, when the block-out time is greatly shortened, a large number of empty blocks and invalid blocks exist in the blockchain, which results in invalid occupation of storage space and waste of processing and transmission resources.
Disclosure of Invention
The embodiment of the invention provides a block generation method, a block generation device, a block generation equipment and a storage medium, which can reduce empty blocks or invalid blocks in a block chain, improve the rationality of processing and transmission resource utilization and save storage space.
In a first aspect, an embodiment of the present invention provides a block generation method, which is performed by a block generation node, where the method includes:
when the initial processing time reaching the local node is detected, processing the transaction request through at least one transaction processing type thread to generate transaction data;
and if the detection result reaches the packing point, packing the transaction data to be packed through a packing thread to generate a new block.
In a second aspect, an embodiment of the present invention provides a block generation apparatus, configured in a block generation node, where the apparatus includes:
the transaction request processing module is used for processing the transaction request through at least one transaction processing thread to generate transaction data when detecting the initial processing time of reaching the local node;
and the transaction data packing module is used for packing the transaction data to be packed through the packing thread to generate a new block if the fact that the packing point is reached is detected.
In a third aspect, an embodiment of the present invention provides an apparatus, including:
one or more processors;
a memory for storing one or more programs;
when the one or more programs are executed by the one or more processors, the one or more processors implement the block generation method according to any embodiment of the present invention.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, and the computer program, when executed by a processor, implements the block generation method according to any embodiment of the present invention.
When the initial processing time reaching the local node is detected, the transaction request is processed through at least one transaction processing type thread to generate transaction data, the packing point is detected, and the transaction data to be packed is packed to generate a new block when the packing point is reached. The embodiment of the invention provides a trigger condition for the packaging thread to package the transaction data through detecting the packaging point, so that effective transaction data are recorded in most blocks of the uplink, hollow blocks or invalid blocks in a block chain are reduced, the rationality of processing and transmission resource utilization is improved, and the storage space is saved.
Drawings
Fig. 1 is a flowchart of a block generation method according to an embodiment of the present invention;
fig. 2 is a flowchart of a block generation method according to a second embodiment of the present invention;
fig. 3 is an exemplary diagram of a branch chain according to a second embodiment of the present invention;
FIG. 4 is a flowchart of determining a blockchain backbone according to a third embodiment of the present invention;
fig. 5 is a schematic structural diagram of a block generating apparatus according to a fourth embodiment of the present invention;
fig. 6 is a schematic structural diagram of an apparatus according to a fifth embodiment of the present invention.
Detailed Description
The embodiments of the present invention will be described in further detail with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the embodiments of the invention and that no limitation of the invention is intended. It should be further noted that, for convenience of description, only some structures, not all structures, relating to the embodiments of the present invention are shown in the drawings.
Example one
Fig. 1 is a flowchart of a block generation method according to an embodiment of the present invention, which is applicable to a case where at least two nodes alternately flow out a consensus mechanism of blocks according to a set rule. The method specifically comprises the following steps:
s110, when the initial processing time reaching the local node is detected, the transaction request is processed through at least one transaction processing type thread to generate transaction data.
In the embodiment of the present invention, the blockchain network may enable at least two nodes in the blockchain network to share the transaction right by means of election and the like according to the consensus mechanism and the deployed parameters, and take the nodes as the current blockchain generation node in turn to process the transaction request in the blockchain network, and finally generate a new block according to the processed transaction data and record the new block in the blockchain. Each node has a block generation period during which at least two blocks are generated, typically on the order of tens or hundreds. Illustratively, a Delegated Proof of trust (DPOS) is a typical consensus mechanism for out-of-block taking, which pre-selects a number of candidate out-of-block nodes, which may be 21 in general, each of which takes turns to be out-of-block as a block generation node. For example, an EOS system, which uses DPOS as a consensus mechanism, during the process of generating a block of a node in a block, the accounting time period of each node in the EOS is 10 minutes; the block generation period for each candidate out-of-block node in the hundred degree hyperchain is configurable, typically by default also 10 minutes.
In this embodiment, the blockchain consensus mechanism adopted by the node is a round-robin block consensus mechanism. The local node is a node which can be used as a block generation node in turn in the block chain network, namely one of at least two candidate block nodes which are selected in advance according to a consensus mechanism. The embodiment divides the transaction request processing and the new block packed generation into two types of thread separated processing, namely starting a transaction type thread for the transaction request processing and a packing thread for the new block packed generation. The transaction processing type threads continuously process the received transaction requests to form transaction data and cache the transaction data to form a queue, and the number of the transaction processing type threads can be a plurality of the transaction requests so as to process the transaction requests in the block chain network in series or in parallel; after the packing threads reach the set packing point, transaction data meeting the packing requirement are extracted from the buffer queue, new blocks are formed through packing and sent to a block chain network for verification and confirmation, the number of the packing threads can be 1, and the packing points are dynamically determined according to the time sequence to pack the transaction data to generate the new blocks. The starting processing time refers to the starting time point when the local node starts to start the transaction class thread to process the transaction request. It can be understood that the start processing time may be a start block-out time of the local node in the current block generation cycle, or may be earlier than the start block-out time, that is, a transaction-like thread may be started to perform a transaction request processing within an inter-node transition time.
Specifically, the starting block output time is determined according to the block generation period of the previous block generation node and the inter-node transition time, the inter-node transition time is acquired from the consensus mechanism data deployed by the local computer before the starting processing time of the local computer node is detected, and the sum of the ending block output time of the block generation period of the previous block generation node and the inter-node transition time is used as the starting block output time of the local computer node in the current block generation period. It can be understood that, if the consensus mechanism in the blockchain network specifies the block generation cycle time length with equal length in advance, the block generation cycle of each node may be determined in advance according to the specified transaction time length with equal length, the transition time between nodes, and the rotation order of each candidate block node; or determining the ending block-out time of the block generation period of the previous block generation node at any time, and determining the starting block-out time of the local node in the current block generation period by summing the transition time between the nodes. If multi-dimensional threshold information such as time and/or space is preset in a node switching rule of a consensus mechanism in the block chain network, determining the ending block-out time of a block generation cycle of a previous block generation node according to the node switching rule, and determining the starting block-out time of the local node in the current block generation cycle by summing with the transition time between nodes. And further acquiring the initial block-out time of the local node in the current block generation period as the initial processing time. In order to ensure that the tail block of the previous block generation node is generated and transmitted into the blockchain network, the inter-node transition time in this embodiment is greater than the intra-node out-block time, where the intra-node out-block time is the out-block interval in the block generation period of a single node.
Specifically, in this embodiment, by querying the previous node or all nodes, the block information such as the block ID may be used as a basis, and if it is detected that the local node successfully receives the tail block of the previous block generation node, the current time is used as the initial processing time. Correspondingly, if the tail block of the previous block generation node is earlier than the initial block output time in the inter-node transition time, the local node can process the transaction request in advance to a certain extent, namely, the transaction request processing is performed by fully utilizing the waiting time, namely the inter-node transition time. The problem that when the number of transaction requests in the block chain is large, the transaction requests are easy to accumulate and untimely to process is solved, and the block output efficiency and the timeliness of transaction data in the block are improved.
In this embodiment, when the start processing time of reaching the local node is detected, at least one transaction class thread is used to process a transaction request to generate transaction data, and the transaction data is buffered to form a queue.
And S120, if the packaging point is detected to be reached, packaging the transaction data to be packaged through a packaging thread to generate a new block.
In the embodiment of the present invention, the packing point is a starting time point when the packing thread starts to perform packing to generate a new chunk, and when the packing thread detects that the packing thread reaches the packing point, the packing thread is used to pack the transaction data to be packed to generate the new chunk. In this embodiment, a manner of dynamically determining a packing point is adopted, and whether the packing point is reached is detected according to a time length between a current time and a last block generation time generated by the local node and/or a size of transaction data to be packed.
The present embodiment may determine the packing point from the time dimension, i.e. by setting a packing time interval threshold; the packing point may also be determined from the spatial dimension, i.e., by setting a transaction packing size threshold, i.e., the amount of data of the transaction data currently buffered in the queue. The two conditions can be independent or combined in a crossed way to be used as the determination basis of the packing point.
Specifically, the determination of the packing point can be classified into at least three following cases according to the above two cases. In case one, if the time length between the current time and the last block generation time generated by the local node is equal to or greater than the first packetization interval threshold, the arrival of the packetization point is detected. In case two, if the size of the transaction data to be packed is greater than or equal to the first transaction packing size threshold, it is detected that the packing point is reached. And in case III, if the time length between the current time and the last block generation time generated by the local node is equal to or greater than the second packing time interval threshold, and the size of the transaction data to be packed is greater than the second transaction packing size threshold, the arrival of the packing point is detected.
In the embodiment of the present invention, since a dynamic packing point determination method is adopted, the packing point is unstable and unpredictable, which easily causes the block chain to be forked, so that the block chain is easily attacked by the longest chain. Furthermore, the main chain can be determined according to a novel longest chain determination algorithm when at least two branch chains are detected in the block chain. Specifically, if it is detected that at least two branch chains exist in a block chain, determining the weight of each block in each branch chain; determining the weight of each branch chain according to the weight of the block contained in each branch chain; and determining a main chain from the branched chains according to the weight of each branched chain, and rolling back the branched chains outside the main chain.
According to the technical scheme of the embodiment, when the initial processing time of reaching the local node is detected, the transaction request is processed through at least one transaction processing type thread to generate transaction data, the packing point is detected, and the transaction data to be packed is packed to generate the new block when the packing point is reached. The embodiment of the invention provides a trigger condition for the packaging thread to package the transaction data through detecting the packaging point, so that effective transaction data are recorded in most blocks of the uplink, hollow blocks or invalid blocks in a block chain are reduced, the rationality of processing and transmission resource utilization is improved, and the storage space is saved.
Example two
The present embodiment provides a preferred implementation of the block generation method based on the first embodiment, and can detect the packing point according to the multi-dimensional information. Fig. 2 is a flowchart of a block generation method according to a second embodiment of the present invention, as shown in fig. 2, the method includes the following steps:
and S210, determining the initial processing time of the local node.
In an embodiment of the present invention, the start processing time refers to a start time point when the native node starts to start the transaction class thread to perform the transaction request processing. It can be understood that the start processing time may be a start block-out time of the local node in the current block generation cycle, or may be earlier than the start block-out time, that is, a transaction-like thread may be started to perform a transaction request processing within an inter-node transition time.
Optionally, the starting block-out time of the local node in the current block generation cycle is obtained as the starting processing time.
In this embodiment, the starting block output time is determined according to the block generation period of the previous block generation node and the transition time between nodes. Before the initial processing time of the local node is detected, acquiring the transition time between the nodes from the consensus mechanism data deployed by the local node, and taking the sum of the ending block-out time of the block generation period of the previous block generation node and the transition time between the nodes as the initial block-out time of the local node in the current block generation period. In order to ensure that the tail block of the previous block generation node is generated and transmitted into the blockchain network, the inter-node transition time in this embodiment is greater than the intra-node out-block time, where the intra-node out-block time is the out-block interval in the block generation period of a single node.
Illustratively, the nodes adopt a round-robin block consensus mechanism, assuming that the time length of a block generation cycle with a preset equal length in the consensus mechanism is 10 minutes, the transition time between nodes is 3 seconds, and the current node aiIs going out of the block and turns to node a after going outi+1And (6) discharging blocks. If node ai+1And if the node is the native node, acquiring the inter-node transition time, namely 3 seconds, from the co-recognition mechanism data deployed in the native node.Suppose node aiAfter the last block is generated, the block generation period is 00:00:00 to 00:10:00, the node aiThe end out-of-block time of (1) is 00:10: 00. And summing the block ending time and the transition time between the nodes, determining that the initial block ending time of the local node in the current block generation period is 00:10:03, so that the initial processing time of the local node can be 00:10: 03.
Optionally, if it is detected that the local node successfully receives the tail block of the previous block generation node, the current time is used as the initial processing time.
In this embodiment, since the blocks generated by the same node are arranged according to the time sequence, the local node may query the previous node or all nodes based on the block information such as the block ID, and if it is detected that the local node successfully receives the tail block of the previous block generation node, it indicates that the previous block generation node has completed the transaction request processing to form the transaction data, and the new block generated according to the transaction data is successfully transmitted to the blockchain network, and the local node successfully receives the new block. And the local node can carry out the chain linking of the subsequent blocks after the new block, thereby avoiding the bifurcation phenomenon. The current time when the local node detects that the tail block of the previous block generation node is successfully received can be used as the starting processing time.
Illustratively, in the above example, if the native node determines that the native node successfully receives the tail block of the previous block generation node at 00:10:02 by querying the previous node or all nodes, the initial processing time of the native node may be 00:10: 02.
S220, when the initial processing time reaching the local node is detected, the transaction request is processed through at least one transaction processing type thread to generate transaction data.
In the embodiment of the invention, after the initial processing time of the local node is acquired, the time can be detected in real time. And if the initial processing time reaching the local node is detected, processing the transaction request by utilizing at least one transaction processing type thread to generate transaction data, and caching the transaction data to form a queue.
And S230, detecting whether a packing point is reached according to the time length between the current time and the last block generation time generated by the local node and/or the size of the transaction data to be packed.
In the embodiment of the present invention, after the initial block output time of the local node in the current block generation cycle is obtained, the time can be detected in real time. If the initial block output time reaching the local node is detected, the packing thread can pack the transaction data in the cache queue to generate a new block, and in the subsequent transaction data packing process, whether the packing point is reached is detected according to the time length between the current time and the last block generation time generated by the local node and/or the size of the transaction data to be packed. And if the packaging point is detected to be reached, the packaging thread performs packaging to generate a next new block. Wherein, the present embodiment can determine the packing point from the time dimension, i.e. by setting the packing time interval threshold; the packing point may also be determined from the spatial dimension, i.e., by setting a transaction packing size threshold, i.e., the amount of data of the transaction data currently buffered in the queue. The two conditions can be independent or combined in a crossed way to be used as the determination basis of the packing point.
Optionally, if the time length between the current time and the last block generation time generated by the local node is equal to or greater than the first packing time interval threshold, the arrival of the packing point is detected.
In this embodiment, the first packing time interval may be a minimum packing time interval in the case where the condition is set, that is, as long as the minimum packing time interval is satisfied in time, the new block is generated by packing.
For example, assuming that the first packing time interval, that is, the minimum packing time interval, is 0.1 second, after the local node packs and generates the first new block according to the initial block output time, as long as the time length between the current time and the last block generation time generated by the local node is equal to or greater than 0.1 second, it is detected that the packing point is reached, and the packing thread packs and generates the new block.
Optionally, if the size of the transaction data to be packed is greater than or equal to the first transaction packing size threshold, the arrival at the packing point is detected.
In this embodiment, the first transaction packing size threshold may be a data amount threshold that limits the transaction data under the condition that the condition is set, that is, when the data amount of the transaction data in the cache reaches the first transaction packing size threshold, the transaction data is packed to generate a new block. Alternatively, the first transaction packing size threshold may be a quantity threshold that defines the number of pieces of transaction data under the condition that the condition is set, that is, when the number of pieces of transaction data in the cache reaches the first transaction packing size threshold, the transaction data is packed to generate a new block.
For example, assuming that the first transaction packing size threshold is 100 megabytes, after the local node packs and generates the first new block according to the initial block output time, as long as the data amount of the transaction data in the current cache queue is greater than or equal to 100 megabytes, it is detected that the packing point is reached, and the packing thread packs and generates the new block. Or, assuming that the first transaction packing size threshold is 5, after the local node packs and generates the first new block according to the initial block output time, as long as 5 pieces of transaction data are cached in the current cache queue, it is detected that a packing point is reached, and the packing thread packs and generates a new block.
Optionally, if the time length between the current time and the last block generation time generated by the local node is equal to or greater than the second packing time interval threshold, and the size of the transaction data to be packed is greater than the second transaction packing size threshold, it is detected that the packing point is reached.
In this embodiment, the second packing time interval may be a minimum packing time interval under the condition set, and the second transaction packing size threshold may be a data amount threshold or a quantity threshold that is defined for the transaction data in the packing block under the third condition, that is, when the minimum packing time interval is met and the data amount or quantity of the transaction data in the cache reaches the second transaction packing size threshold, the transaction data is packed to generate a new block.
For example, assuming that the second packing time interval is 0.1 second and the second transaction packing size threshold is 100 megabits, after the local node packs and generates the first new block according to the initial block output time, the time length between the current time and the generation time of the last block generated by the local node is equal to or greater than 0.1 second, and the data amount of the transaction data in the current cache queue is greater than or equal to 100 megabits, it is detected that the packing point is reached, and the packing thread performs packing and generates the new block.
In addition, in this embodiment, as long as the minimum packing time interval is satisfied, when there is transaction data formed by the transaction type thread processing in the cache, the transaction data may be packed to generate a new chunk. Alternatively, in this embodiment, the maximum packing time interval may be set at the same time, and as long as the maximum packing time interval is within, the transaction data meeting the data amount threshold or the number threshold is packed to generate a new block. Or, even if the data amount or the number of the transaction data buffered in the queue does not satisfy the data amount threshold or the number threshold, the transaction data is packed to generate a new block as long as the maximum packing time interval is satisfied. The present embodiment may also implement condition combination situations other than the above situations, and the present embodiment does not list each situation, and any situation that can reasonably combine the time and/or space dimension conditions may be applied to the present embodiment.
S240, if the packaging point is detected to be reached, packaging the transaction data to be packaged through a packaging thread to generate a new block.
In the embodiment of the invention, according to a preset packing point detection condition, if the packing point is detected to be reached, a packing thread is utilized to pack the transaction data meeting the detection condition to generate a new block.
And S250, if the block chain is detected to have at least two branch chains, determining the weight of each block in each branch chain.
In the embodiment of the present invention, since a dynamic packing point determination method is adopted, the packing point is unstable and unpredictable, which easily causes the block chain to be forked, so that the block chain is easily attacked by the longest chain. Furthermore, the main chain of the block chain can be determined according to a novel longest chain determination algorithm when the block chain is detected to have at least two bifurcate chains.
In this embodiment, the block data in each block in the block chain not only includes the transaction data recorded in the block body, but also includes block header information, such as the hash value of the previous block header, the timestamp, i.e., the block generation time, the workload difficulty, and the block identification information, i.e., the Merkle root, i.e., the trusted tree. Since almost every node in the network can observe data in each block in the whole network, supervision of network data by all nodes is realized. Therefore, nodes having blockchain storage authority in the blockchain system can detect whether a branch chain exists, and if any node detects that at least two branch chains exist in the blockchain, a main chain needs to be determined from the at least two branch chains. Specifically, whether a branch chain is generated may be determined as follows: if the time difference of the timestamps in the at least two blocks is detected to be smaller than a certain time threshold, the generation time of the at least two blocks is very close; or, if it is detected that the last chunk header hash values of the at least two chunks are the same, it is determined that a branch chain occurs in the chunk chain. The present embodiment does not limit the detection method of the branch phenomenon, and any detection method capable of detecting the block chain branch phenomenon may be applied to the present embodiment. Any one of the above detection methods of the branched chains can be adopted, or according to the actual situation, the detection of the branched chains can be realized by adopting the combination of at least two of the detection methods.
Specifically, in this embodiment, the bifurcation block refers to a tail block of the block chain before the bifurcation phenomenon occurs, that is, the bifurcation phenomenon occurs after the bifurcation block. Accordingly, the branch chain is extended by using the next block of the branch block as the starting block of the branch chain. Fig. 3 is an exemplary diagram of a branch chain, as shown in fig. 3, a branch phenomenon occurs after block 1, and block 1 is a branch block; the block 2 is the initial block of the forked chain (1), and the block 3 which follows the initial block forms the current forked chain (1); block 4 is the starting block of the forking chain (2) and together with the following blocks 5 and 6 constitutes the current forking chain (2). When the starting block of the branch chain is linked to the block chain, that is, the branching phenomenon occurs, because the block output time is shortened, the situation that the tail block of the previous block generation node is not received when the local node is used as the current block generation node exists, the branching phenomenon occurs when a new block is generated again, and the growth speeds of the at least two corresponding branch chains are also different. After a period of time, the transaction data stored by the blocks on different bifurcated chains is different.
In order to ensure the uniqueness of the block chain data in the network, in this embodiment, when a bifurcation phenomenon is detected, or when a block generation node completes processing a certain number of transaction requests and recording transaction data within a period of time, the block information included in each bifurcation chain is detected and judged, so that all nodes in the block chain can follow a uniform block weight setting algorithm, and different weights are set for each block in the bifurcation chain according to a specific weight setting rule, so as to select a main chain according to the weights of the bifurcation chain.
In this embodiment, for setting the block weight satisfying a certain block chain attack type, a plurality of block chain attack types may be analyzed according to the association relationship between blocks in a branch chain, the workload difficulty of each block, the timestamp, and multidimensional information such as a block generation node to which the block belongs, and the formation condition of the attack type may be determined according to the association relationship between the attack type and the block information. And the forming condition is used as a preset condition to detect and judge the attack type of the branch chain, so that the weight of each block in the branch chain is set in a targeted manner according to the attack type, namely, the incidence relation between each attack type and the weight setting rule is generated.
Specifically, the present embodiment may further determine whether a malicious discarded block phenomenon exists according to the block information of the branch chain. For example, a malicious peer has a computationally powerful node and generates more blocks to form and extend the fork chain to maliciously discard the correct block. That is, a certain number of blocks in the branching chain from the branching start block may be detected to be generated at the same node as the block generation node of the branching start block. Thus, the weight of the block formed by the malicious end node is set to a lower value, even 0, so that the weight of the block in the longer branch chain generated by the malicious end is reduced.
Illustratively, as shown in fig. 3, assume that blocks 1, 2 and 3 generate node a for the previous blockiThe resulting block, blocks 4, 5 and 6, generates node a for the current blocki+1The resulting block. If a certain node in the blockchain system detects that the hash values of the previous block headers in the blocks 2 and 4 are the same by observing the block data of each block in the network, the previous block of the blocks 2 and 4 is determined to be the same block, namely block 1, so that the phenomenon of forking of the blockchain is determined. All nodes in the block chain system can follow a uniform block weight setting algorithm, detect and set different weights for each block in the branch chain according to the block information on the two branch chains.
In the above example, assume node ai+1If the node is a node for attack mastered by the malicious end, the malicious end discards the node aiThe transaction data recorded in blocks 2 and 3, after block 1, form a fork chain (2) and are extended. Therefore, in order to prevent the main chain from being directly determined due to the long length of the branch chain (2), the present embodiment sets a weight for each block according to the block information in the branch chain. Further, the weight setting rule associated with the longest-chain-based malicious attack may be set as: setting the weights of the two bifurcation starting blocks to be 1, and if the block generating node of the block behind the bifurcation starting block in the first bifurcation chain is different from the block generating node of the bifurcation starting block, setting the weights of the blocks to be 1; and the weight of the block on the second branch chain after the starting block of the branch is set to 0 to invalidate the block as a double-flower attack. Therefore, the determination of the weight of each block in each branch chain is completed according to the incidence relation between the attack of the malicious discarded block and the weight setting rule and the block access condition of the branch chain.
S260, determining the weight of each branch chain according to the weight of the block included in each branch chain.
In the embodiment of the present invention, the weights of the branch chains are determined based on the weights of the blocks, and the weights of the blocks included in the branch chains can be summed to obtain the weight of the branch chain, which is used as a basis for judging the branch chain, rather than simply judging the recognition degree of each branch chain based on the number of the blocks included in the branch chain.
Illustratively, in the above example of a longest chain based malicious attack, since such an attack typically occurs in the case of a node switch, blocks are subsequently generated by the new node and incorporated into the branch chain of branch chain (1), and thus the weight of branch chain (1) is greater than 1. And as the malicious node maliciously extends the branch chain (2), block generation nodes of blocks in the branch chain (2) are all the same node, namely the malicious node, so that the weights of the blocks except the initial block in the branch chain (2) are all set to be 0, and further the weight of the branch chain (2) is only 1.
S270, determining a main chain from the branched chains according to the weight of each branched chain, and rolling back the branched chains except the main chain.
In the embodiment of the present invention, since the weight of the block is set, and the weight of the block is equivalent to the recognition degree of the block by the network, the branch chain with the largest weight can be determined as the main chain of the block chain from all branch chains according to the weight of each branch chain. In order to ensure the uniqueness of the block chain data in the network, all branch chains except the branch chain selected as the main chain are regarded as invalid, and the transaction data in the branch chains are restored to the main chain regarded as correct at last time. It should be noted that the main chain determining method provided in S250-S270 may be performed by each node in the blockchain network, where the blockchain is synchronized.
Illustratively, in the malicious attack example based on the longest chain, since the weight of the branch chain (1) is greater than 1, and the weight of the branch chain (2) is only 1, the weight of the branch chain (1) is greater than the weight of the branch chain (2), and then the branch chain (1) is determined as the main chain of the block chain, while the branch chain (2) with a large number of blocks, i.e., the longest chain, is prevented from being directly determined as the main chain. Because the contention of the transaction processing right or the block generation right and the processing of the transaction data need to pay a large workload, and the transaction processing right or the block generation right and the processing of the transaction data can be completed only by overcoming high workload difficulty, different weights are set for the blocks, and the main chain determining mode based on the block weights is favorable for increasing the attack cost of the malicious end to the block chain under the condition of not influencing the extension of the normal block chain, and the attack success rate of the malicious end is reduced.
It should be noted that the embodiment is an example of setting the block weight when there is an attack condition in the bifurcation phenomenon, but the embodiment of the present invention can also be applied to setting the block weight of the bifurcation chain when there is a non-attack condition in the bifurcation phenomenon. Therefore, the embodiment of the invention is suitable for all situations in the bifurcation phenomenon, no matter the node is a normal node or an aggressive malicious node, all nodes in the block chain system can follow a uniform block weight setting algorithm in the bifurcation chain, and when the bifurcation phenomenon occurs in the block chain system, the main chain determining method based on the bifurcation chain weight can be realized.
According to the technical scheme of the embodiment, by determining the processing time of the transaction request, when the initial processing time of the local node is detected, the transaction request is processed through at least one transaction processing type thread to generate transaction data; detecting whether a packing point is reached or not according to the time length between the current time and the last block generation time generated by the local node and/or the size of the transaction data to be packed, and if the packing point is detected to be reached, packing the transaction data to be packed to generate a new block; and detecting the branching phenomenon in the block chain network, and when a block chain generates a branching chain, setting different weights for each block in the branching chain to obtain the weight of each branching chain, so as to determine a main chain from the branching chains according to the weights of the branching chains, and rolling back the branching chains except the main chain. The embodiment of the invention provides a trigger condition for the packaging thread to package the transaction data through detecting the packaging point, so that effective transaction data are recorded in most blocks of the uplink, hollow blocks or invalid blocks in a block chain are reduced, the rationality of processing and transmission resource utilization is improved, and the storage space is saved. Meanwhile, different weights are set for each block in the branch chain according to the specific situation of the branch chain, and the actual proportion of each block in the block chain is reasonably distributed in advance, so that the main chain is determined from the branch chain based on the weights of the branch chain, and the reasonability of the main chain determination is improved. And the problem that the tail block of the previous block generation node is maliciously discarded by the next block generation node in the switching process of the block generation nodes is avoided to a certain extent, the maliciousness cost of the next block generation node is increased, and the success rate of maliciousness attack is reduced.
EXAMPLE III
This embodiment provides a preferred implementation of the block generation method based on the first embodiment, and the main chain can be determined when the block chain branches. Fig. 4 is a flowchart of determining a block chain main chain according to a third embodiment of the present invention, and as shown in fig. 4, the method includes the following specific steps:
s410, when the initial processing time reaching the local node is detected, the transaction request is processed through at least one transaction processing type thread to generate transaction data.
In the embodiment of the invention, after the initial processing time of the local node is acquired, the time can be detected in real time. And if the initial processing time reaching the local node is detected, processing the transaction request by utilizing at least one transaction processing type thread to generate transaction data, and caching the transaction data to form a queue.
And S420, if the packaging point is detected to be reached, packaging the transaction data to be packaged through a packaging thread to generate a new block.
In the embodiment of the invention, a mode of dynamically determining the packing point is adopted, and whether the packing point is reached is detected according to the time length between the current time and the last block generation time generated by the local node and/or the size of the transaction data to be packed. And when the packaging point is detected to be reached, packaging the transaction data to be packaged by using the packaging thread to generate a new block.
S430, if the block chain is detected to have at least two branch chains, determining the target attack type according to the block information contained in each branch chain.
In the embodiment of the present invention, since the attack of the malicious end aims to make the illegal transaction data become effective to profit from the attack, the common attack types are mostly in the attack mode based on the longest chain main chain determination method, such as the double-flower attack. So that the illegal branch chain of the malicious end is extended to the longest chain, and the correct block in the block chain is discarded. The attack types of the block chains can be analyzed according to the association relationship among the blocks in the branch chain, the workload difficulty of each block, the time stamp, the multi-dimensional information of the block generation node and the like, and the forming conditions of the attack types can be determined according to the association relationship between the attack types and the block information.
In the embodiment, each node in the network can almost observe data in each block in the whole network, so that supervision of network data by all nodes is realized. Therefore, nodes having blockchain storage authority in the blockchain system can detect whether a branch chain exists, and if any node detects that at least two branch chains exist in the blockchain, a main chain needs to be determined from the at least two branch chains. Specifically, whether a branch chain is generated may be determined as follows: if the time difference of the timestamps in the at least two blocks is detected to be smaller than a certain time threshold, the generation time of the at least two blocks is very close; or, if it is detected that the last chunk header hash values of the at least two chunks are the same, it is determined that a branch chain occurs in the chunk chain. Any one of the above detection methods of the branched chains can be adopted, or according to the actual situation, the detection of the branched chains can be realized by adopting the combination of at least two of the detection methods. And when the bifurcation phenomenon is detected, or when the block generation node finishes processing and recording transaction requests within a period of time or in a certain number, detecting and judging the block information contained in each bifurcation chain, and determining the target attack type currently suffered by the bifurcation chain according to the forming conditions of each attack type, the association relation among the blocks in the bifurcation chain, the workload difficulty of each block, the timestamp, the multi-dimensional information of the block generation node to which the block generation node belongs and the like.
For example, the formation conditions of the double blossom attack may be: in a bit currency transfer scenario, when two branch chains are generated, if block generation nodes of a branch starting block in each branch chain are the same, and a block generation node of a block after the branch starting block on one branch chain is also the block generation node, a double-flower attack can be determined as a target attack type of the branch chain.
S440, determining a target weight setting rule associated with the target attack type according to the association relationship between the preset attack type and the weight setting rule.
In the embodiment of the invention, the attack type of the branch chain is detected and judged according to the forming condition of each attack type, so that the weight of each block in the branch chain is set in a targeted manner according to the attack type, namely, the incidence relation between each attack type and the weight setting rule is generated, so as to inhibit or prevent the attack of a malicious end, increase the attack cost of the malicious end and reduce the success rate of the attack.
For example, according to the formation condition of the double flower attack and the harm brought by the double flower attack, the weight setting rule associated with the double flower attack can be set as follows: if the block generation node of any block in the branch chain is different from the block generation node of the last block of the block, setting the weight of the block to be 1; if the block generation node of the block is the same as the block generation node of the previous block of the block, and the previous block of the block is a forked block, setting the weight of the block to 1; if the block generation node of the block is the same as the block generation node of the previous block of the block, and the previous block of the block is not a forked block, the weight of the block is set to 0.
S450, determining the weight of each block in the branch chain according to the target weight setting rule.
In an embodiment of the present invention, a corresponding weight is set for each block in the branch chain that satisfies the target weight setting rule according to the target weight setting rule.
Optionally, for most attack modes that maliciously discard blocks based on the longest chain, the following general setting of weights may be performed: if the block generating node of any current block in the branch chain is different from the block generating node of the last block of the current block, setting the weight of the current block as a first numerical value; if the block generation node of the current block is the same as the block generation node of the previous block of the current block and the previous block is a forked block, setting the weight of the current block as a first numerical value; if the block generation node of the current block is the same as the block generation node of the previous block of the current block and the previous block is not a forked block, setting the weight of the current block as a second numerical value; wherein the first value is greater than the second value.
In this embodiment, it can be understood that, through the identification of the attack type, according to the block information in the branch chain, the correct block in the branch chain is set with a larger weight, the incorrect block in the branch chain is set with a smaller weight, and different weights are set for the blocks in the branch chain, so as to effectively reduce or even eliminate the recognition degree of the malicious block, thereby invalidating the branch chain extended by the malicious end and protecting the correct block in the block chain.
S460, summing the weights of the blocks included in the branch chains to obtain the weights of the branch chains according to the weights of the blocks included in the branch chains.
In the embodiment of the present invention, the weights of the branch chains are determined based on the weights of the blocks, and the weights of the blocks included in the branch chains can be summed to obtain the weight of the branch chain, which is used as a basis for judging the branch chain, rather than simply judging the recognition degree of each branch chain based on the number of the blocks included in the branch chain.
And S470, determining a main chain from the branched chains according to the weight of each branched chain, and rolling back the branched chains outside the main chain.
In the embodiment of the present invention, since the weight of the block is set, and the weight of the block is equivalent to the recognition degree of the block chain network to the block, the branch chain with the largest weight can be determined as the main chain of the block chain from all branch chains according to the weight of each branch chain. In order to ensure the uniqueness of the block chain data in the network, all branch chains except the branch chain selected as the main chain are regarded as invalid, and the transaction data in the branch chains are restored to the main chain regarded as correct at last time.
According to the technical scheme of the embodiment, when the block chain generates the branch chain, or when the block generation node finishes processing and recording the transaction requests within a period of time or in a certain number, the target weight setting rule associated with the target attack type is determined through identifying the target attack type to which the branch chain belongs, so that different weights are set for each block in the branch chain according to the target weight setting rule. Or setting the block weight for the branch chain corresponding to the attack mode which is identified as maliciously discarding the block based on the longest chain by using a common weight setting rule. And obtaining the weight of each branch chain, determining the branch chain with the largest weight as the main chain, and rolling back the object data in the branch chains outside the main chain. The embodiment of the invention reduces or even eliminates the recognition degree of illegal blocks by determining the attack type of the branch chain and the weight setting rule and setting the weight corresponding to each block in the branch chain, thereby invalidating the branch chain specially prolonged by a malicious end, protecting the correct block in the block chain, determining the main chain from the branch chain based on the weight of the branch chain, avoiding the problem that the tail block of the previous block generation node is maliciously discarded by the next block generation node in the block generation node switching process to a certain extent, increasing the maliciousness cost of the next block generation node and reducing the success rate of malicious attack.
Example four
Fig. 5 is a schematic structural diagram of a block generation apparatus according to a fourth embodiment of the present invention, which is applicable to a case where at least two nodes alternately flow out a consensus mechanism of blocks according to a set rule. The device specifically includes:
a transaction request processing module 510, configured to process a transaction request through at least one transaction class thread to generate transaction data when detecting an initial processing time of reaching a local node;
and the transaction data packing module 520 is configured to pack the transaction data to be packed through the packing thread to generate a new block if it is detected that the packing point is reached.
The starting block-out time determining module 530 is configured to, before detecting a starting processing time of reaching a local node, obtain a starting block-out time of the local node in a current block generation period, as the starting processing time, where the starting block-out time is determined according to a block generation period of a previous block generation node and an inter-node transition time.
Optionally, the inter-node transition time is greater than the intra-node block output time, and the intra-node block output time is a block output interval in a block generation period of a single node.
Optionally, the starting block-out time determining module 530 is further specifically configured to:
and taking the sum of the ending block-out time of the block generation period of the previous block generation node and the transition time between the nodes as the starting block-out time of the local node in the current block generation period.
Further, the apparatus further comprises:
the start processing time determining module 540 is configured to, before detecting the start processing time of reaching the local node, if it is detected that the local node successfully receives the tail block of the previous block generation node, take the current time as the start processing time.
Optionally, the transaction data packing module 520 is specifically configured to:
and detecting whether the packaging point is reached according to the time length between the current time and the last block generation time generated by the local node and/or the size of the transaction data to be packaged.
Optionally, the transaction data packing module 520 is specifically configured to:
and if the time length between the current time and the last block generation time generated by the local node is equal to or larger than the first packing time interval threshold value, the arrival of the packing point is detected.
Optionally, the transaction data packing module 520 is specifically configured to:
and if the size of the object data to be packaged is larger than or equal to the first transaction packaging size threshold, detecting that the packaging point is reached.
Optionally, the transaction data packing module 520 is specifically configured to:
and if the time length between the current time and the last block generation time generated by the local node is equal to or greater than the second packing time interval threshold value and the size of the transaction data to be packed is greater than the second transaction packing size threshold value, detecting that the packing point is reached.
Further, the apparatus further comprises:
a block weight determining module 550, configured to determine a weight of each block in each branch chain if it is detected that at least two branch chains exist in the block chain;
a branch chain weight determining module 560, configured to determine a weight of each branch chain according to a weight of a block included in each branch chain;
the main chain determining module 570 is configured to determine a main chain from the branch chains according to the weight of each branch chain, and roll back branch chains other than the main chain.
Optionally, the block weight determining module 550 includes:
an attack type determining unit 5501, configured to determine a target attack type according to block information included in each branch chain;
a weight rule determining unit 5502, configured to determine, according to an association relationship between a preset attack type and a weight setting rule, a target weight setting rule associated with the target attack type;
a block weight determining unit 5503, configured to determine the weight of each block in the branch chain according to the target weight setting rule.
Optionally, the block weight determining module 550 is further configured to:
if the block generating node of any current block in the branch chain is different from the block generating node of the last block of the current block, setting the weight of the current block as a first numerical value;
if the block generation node of the current block is the same as the block generation node of the previous block of the current block, and the previous block is a forked block, setting the weight of the current block to be the first numerical value;
if the block generation node of the current block is the same as the block generation node of the previous block of the current block and the previous block is not a forked block, setting the weight of the current block to be a second numerical value;
wherein the first value is greater than the second value.
Optionally, the branch chain weight determining module 560 is specifically configured to:
and summing the weights of all blocks contained in the branch chain to obtain the weight of the branch chain.
Optionally, the main chain determining module 570 is specifically configured to:
and determining the branch chain with the largest weight as a main chain.
According to the technical scheme of the embodiment, through the mutual cooperation of the functional modules, the functions of determining the initial block output time, detecting block receiving, determining the initial processing time, processing a transaction request, caching transaction data, detecting a packing point, packing the transaction data, generating a block, detecting a branch chain, setting block weight, setting branch chain weight, determining a main chain and the like are realized. The embodiment of the invention provides a trigger condition for the packaging thread to package the transaction data through detecting the packaging point, so that effective transaction data are recorded in most blocks of the uplink, hollow blocks or invalid blocks in a block chain are reduced, the rationality of processing and transmission resource utilization is improved, and the storage space is saved. Meanwhile, different weights are set for each block in the branch chain according to the specific situation of the branch chain, and the actual proportion of each block in the block chain is reasonably distributed in advance, so that the main chain is determined from the branch chain based on the weights of the branch chain, and the reasonability of the main chain determination is improved. And the problem that the tail block of the previous block generation node is maliciously discarded by the next block generation node in the switching process of the block generation nodes is avoided to a certain extent, the maliciousness cost of the next block generation node is increased, and the success rate of maliciousness attack is reduced.
EXAMPLE five
Fig. 6 is a schematic structural diagram of an apparatus according to a fifth embodiment of the present invention, and fig. 6 shows a block diagram of an exemplary apparatus suitable for implementing the embodiment of the present invention. The device shown in fig. 6 is only an example and should not bring any limitation to the function and the scope of use of the embodiments of the present invention.
The device 12 shown in fig. 6 is only an example and should not bring any limitations to the functionality and scope of use of the embodiments of the present invention.
As shown in FIG. 6, device 12 is in the form of a general purpose computing device. The components of device 12 may include, but are not limited to: one or more processors 16, a system memory 28, and a bus 18 that connects the various system components (including the system memory 28 and the processors 16).
Bus 18 represents one or more of any of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, and a processor or local bus using any of a variety of bus architectures. By way of example, such architectures include, but are not limited to, Industry Standard Architecture (ISA) bus, micro-channel architecture (MAC) bus, enhanced ISA bus, Video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
Device 12 typically includes a variety of computer system readable media. Such media may be any available media that is accessible by device 12 and includes both volatile and nonvolatile media, removable and non-removable media.
The system memory 28 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM)30 and/or cache memory 32. Device 12 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage system 34 may be used to read from and write to non-removable, nonvolatile magnetic media (not shown in FIG. 6, and commonly referred to as a "hard drive"). Although not shown in FIG. 6, a magnetic disk drive for reading from and writing to a removable, nonvolatile magnetic disk (e.g., a "floppy disk") and an optical disk drive for reading from or writing to a removable, nonvolatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 by one or more data media interfaces. System memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to carry out the functions of embodiments of the invention.
A program/utility 40 having a set (at least one) of program modules 42 may be stored, for example, in system memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which examples or some combination thereof may comprise an implementation of a network environment. Program modules 42 generally carry out the functions and/or methodologies of embodiments described herein.
Device 12 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), with one or more devices that enable a user to interact with device 12, and/or with any devices (e.g., network card, modem, etc.) that enable device 12 to communicate with one or more other computing devices. Such communication may be through an input/output (I/O) interface 22. Also, the device 12 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network, such as the Internet) via the network adapter 20. As shown, the network adapter 20 communicates with the other modules of the device 12 via the bus 18. It should be understood that although not shown in the figures, other hardware and/or software modules may be used in conjunction with device 12, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, among others.
The processor 16 executes various functional applications and data processing by executing at least one program of the programs stored in the system memory 28, for example, to implement the block generation method provided by the embodiment of the present invention.
EXAMPLE six
An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program (or referred to as computer-executable instructions) is stored, where the computer program is used to execute a block generation method when executed by a processor, and the method includes:
when the initial processing time reaching the local node is detected, processing the transaction request through at least one transaction processing type thread to generate transaction data;
and if the detection result reaches the packing point, packing the transaction data to be packed through a packing thread to generate a new block.
Computer storage media for embodiments of the invention may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for embodiments of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or device. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the embodiments of the present invention have been described in more detail through the above embodiments, the embodiments of the present invention are not limited to the above embodiments, and many other equivalent embodiments may be included without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (30)

1. A block generation method performed by a block generation node, the method comprising:
when detecting the initial processing time reaching the local node, processing the transaction request through at least one transaction processing type thread to generate transaction data, wherein the initial processing time is the initial time point when the local node starts to start the transaction processing type thread to process the transaction request;
and if the packaging point is detected to be reached, packaging the transaction data to be packaged through a packaging thread to generate a new block, wherein the packaging point is an initial time point when the packaging thread starts to perform packaging to generate the new block.
2. The method of claim 1, prior to detecting an initial processing time to reach a native node, further comprising:
and acquiring the initial block output time of the local node in the current block generation period as the initial processing time, wherein the initial block output time is determined according to the block generation period of the previous block generation node and the transition time between the nodes.
3. The method of claim 2, wherein the inter-node transition time is greater than an intra-node out-block time, the intra-node out-block time being an out-block interval within a block generation period of a single node.
4. The method of claim 2, wherein the local node determines the start block-out time of the current block generation cycle by:
and taking the sum of the ending block-out time of the block generation period of the previous block generation node and the transition time between the nodes as the starting block-out time of the local node in the current block generation period.
5. The method of claim 1, prior to detecting an initial processing time to reach a native node, further comprising:
and if the local node is detected to successfully receive the tail block of the previous block generation node, taking the current time as the initial processing time.
6. The method of claim 1, wherein detecting whether a packing point is reached comprises:
and detecting whether the packaging point is reached according to the time length between the current time and the last block generation time generated by the local node and/or the size of the transaction data to be packaged.
7. The method of claim 6, wherein detecting whether a packing point is reached according to a time length between a current time and a last block generation time generated by a local node comprises:
and if the time length between the current time and the last block generation time generated by the local node is equal to or larger than the first packing time interval threshold value, the arrival of the packing point is detected.
8. The method of claim 6, wherein detecting whether a packing point is reached based on a size of the transaction data to be packed comprises:
and if the size of the object data to be packaged is larger than or equal to the first transaction packaging size threshold, detecting that the packaging point is reached.
9. The method of claim 6, wherein detecting whether the packing point is reached according to a time length between a current time and a last block generation time generated by the local node and a size of the transaction data to be packed comprises:
and if the time length between the current time and the last block generation time generated by the local node is equal to or greater than the second packing time interval threshold value and the size of the transaction data to be packed is greater than the second transaction packing size threshold value, detecting that the packing point is reached.
10. The method of claim 1, further comprising:
if the block chain is detected to have at least two branch chains, determining the weight of each block in each branch chain;
determining the weight of each branch chain according to the weight of the block contained in each branch chain;
and determining a main chain from the branched chains according to the weight of each branched chain, and rolling back the branched chains outside the main chain.
11. The method of claim 10, wherein determining the weight for each block in each branch chain comprises:
determining a target attack type according to block information contained in each branch chain;
determining a target weight setting rule associated with the target attack type according to an association relation between a preset attack type and the weight setting rule;
and determining the weight of each block in the branch chain according to the target weight setting rule.
12. The method of claim 10, wherein determining the weight for each block in each branch chain comprises:
if the block generating node of any current block in the branch chain is different from the block generating node of the last block of the current block, setting the weight of the current block as a first numerical value;
if the block generation node of the current block is the same as the block generation node of the previous block of the current block, and the previous block is a forked block, setting the weight of the current block to be the first numerical value;
if the block generation node of the current block is the same as the block generation node of the previous block of the current block and the previous block is not a forked block, setting the weight of the current block to be a second numerical value;
wherein the first value is greater than the second value.
13. The method of claim 10, wherein determining the weight of each branch chain according to the weight of the block included in each branch chain comprises:
and summing the weights of all blocks contained in the branch chain to obtain the weight of the branch chain.
14. The method of claim 10, wherein determining the main chain from the bifurcating chains based on the weight of each bifurcating chain comprises:
and determining the branch chain with the largest weight as a main chain.
15. A block generation apparatus arranged in a block generation node, comprising:
the transaction request processing module is used for processing a transaction request through at least one transaction processing type thread to generate transaction data when detecting initial processing time of reaching a local node, wherein the initial processing time is an initial time point when the local node starts the transaction processing type thread to perform transaction request processing;
and the transaction data packing module is used for packing the transaction data to be packed through the packing thread to generate a new block if the packing point is detected to be reached, wherein the packing point is the starting time point of the packing thread starting to execute packing to generate the new block.
16. The apparatus of claim 15, further comprising:
and the initial block-out time determining module is used for acquiring the initial block-out time of the local node in the current block generation period before detecting the initial processing time of reaching the local node, and the initial block-out time is used as the initial processing time, wherein the initial block-out time is determined according to the block generation period of the previous block generation node and the transition time between the nodes.
17. The apparatus of claim 16, wherein the inter-node transition time is greater than an intra-node out-block time, and wherein the intra-node out-block time is an out-block interval within a block generation period of a single node.
18. The apparatus of claim 16, wherein the start out-of-block time determination module is further specifically configured to:
and taking the sum of the ending block-out time of the block generation period of the previous block generation node and the transition time between the nodes as the starting block-out time of the local node in the current block generation period.
19. The apparatus of claim 15, further comprising:
and the initial processing time determining module is used for taking the current time as the initial processing time if the local node is detected to successfully receive the tail block of the previous block generating node before the initial processing time of the local node is detected.
20. The apparatus of claim 15, wherein the transaction data packaging module is specifically configured to:
and detecting whether the packaging point is reached according to the time length between the current time and the last block generation time generated by the local node and/or the size of the transaction data to be packaged.
21. The apparatus of claim 20, wherein the transaction data packaging module is specifically configured to:
and if the time length between the current time and the last block generation time generated by the local node is equal to or larger than the first packing time interval threshold value, the arrival of the packing point is detected.
22. The apparatus of claim 20, wherein the transaction data packaging module is specifically configured to:
and if the size of the object data to be packaged is larger than or equal to the first transaction packaging size threshold, detecting that the packaging point is reached.
23. The apparatus of claim 20, wherein the transaction data packaging module is specifically configured to:
and if the time length between the current time and the last block generation time generated by the local node is equal to or greater than the second packing time interval threshold value and the size of the transaction data to be packed is greater than the second transaction packing size threshold value, detecting that the packing point is reached.
24. The apparatus of claim 15, further comprising:
the block weight determining module is used for determining the weight of each block in each branch chain if at least two branch chains exist in the block chain;
the branch chain weight determining module is used for determining the weight of each branch chain according to the weight of the block contained in each branch chain;
and the main chain determining module is used for determining a main chain from the branched chains according to the weight of each branched chain and rolling back the branched chains except the main chain.
25. The apparatus of claim 24, wherein the block weight determining module comprises:
the attack type determining unit is used for determining a target attack type according to the block information contained in each branch chain;
the weight rule determining unit is used for determining a target weight setting rule associated with the target attack type according to the association relationship between the preset attack type and the weight setting rule;
and the block weight determining unit is used for determining the weight of each block in the branch chain according to the target weight setting rule.
26. The apparatus of claim 24, wherein the block weight determination module is further configured to:
if the block generating node of any current block in the branch chain is different from the block generating node of the last block of the current block, setting the weight of the current block as a first numerical value;
if the block generation node of the current block is the same as the block generation node of the previous block of the current block, and the previous block is a forked block, setting the weight of the current block to be the first numerical value;
if the block generation node of the current block is the same as the block generation node of the previous block of the current block and the previous block is not a forked block, setting the weight of the current block to be a second numerical value;
wherein the first value is greater than the second value.
27. The apparatus of claim 24, wherein the split-chain weight determination module is specifically configured to:
and summing the weights of all blocks contained in the branch chain to obtain the weight of the branch chain.
28. The apparatus of claim 24, wherein the backbone determination module is specifically configured to:
and determining the branch chain with the largest weight as a main chain.
29. An apparatus, comprising:
one or more processors;
a memory for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement the tile generation method of any of claims 1-14.
30. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the block generation method according to any one of claims 1 to 14.
CN201811087256.5A 2018-09-18 2018-09-18 Block generation method, device, equipment and storage medium Active CN109255057B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811087256.5A CN109255057B (en) 2018-09-18 2018-09-18 Block generation method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811087256.5A CN109255057B (en) 2018-09-18 2018-09-18 Block generation method, device, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN109255057A CN109255057A (en) 2019-01-22
CN109255057B true CN109255057B (en) 2021-05-07

Family

ID=65046941

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811087256.5A Active CN109255057B (en) 2018-09-18 2018-09-18 Block generation method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN109255057B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110493148B (en) * 2019-08-12 2022-04-01 深圳前海微众银行股份有限公司 Block processing, block consensus and block synchronization method and device
CN110753028B (en) * 2019-09-11 2021-06-22 复旦大学 Method for controlling distributed accounting network resource use
CN110619582B (en) * 2019-09-18 2023-07-14 深圳前海微众银行股份有限公司 Block chain transaction method, device, equipment and computer storage medium
CN111371558B (en) * 2020-02-26 2024-01-16 百度在线网络技术(北京)有限公司 Block chain data processing method and device, electronic equipment and medium
CN111813852B (en) * 2020-05-29 2023-12-01 上海申铁信息工程有限公司 Bifurcation control method and bifurcation control device for blockchain network
CN113596107A (en) * 2021-07-07 2021-11-02 支付宝(杭州)信息技术有限公司 Data synchronization method and device based on block chain
CN114385647B (en) * 2021-12-15 2023-04-07 达闼科技(北京)有限公司 Alliance link-out block method, alliance link-out block device, electronic equipment and medium

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106055597A (en) * 2016-05-24 2016-10-26 布比(北京)网络技术有限公司 Digital transaction system, and account information query method therefor
CN106656974A (en) * 2016-10-17 2017-05-10 江苏通付盾科技有限公司 Block chain grouping consensus method and system
CN107239953A (en) * 2017-06-20 2017-10-10 无锡井通网络科技有限公司 Fast data store method and system based on block chain
CN107291374A (en) * 2016-03-31 2017-10-24 慧荣科技股份有限公司 Method and device for recording use time of data block
CN107301546A (en) * 2017-05-03 2017-10-27 北京众享比特科技有限公司 Generating random number and methods for using them and device
CN108320160A (en) * 2018-02-02 2018-07-24 张超 Block catenary system, block common recognition method and apparatus
CN108427601A (en) * 2017-02-13 2018-08-21 北京航空航天大学 A kind of cluster transaction processing method of privately owned chain node

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150170114A1 (en) * 2013-12-18 2015-06-18 Apriva, Llc System and method for acquiring and integrating multi-source information for advanced analystics and visualization
CN106453636A (en) * 2016-11-22 2017-02-22 深圳银链科技有限公司 Credible block generation method and system
CN106815722B (en) * 2016-12-22 2021-05-07 中钞信用卡产业发展有限公司杭州区块链技术研究院 Information processing method and device based on block chain
CN107480987A (en) * 2017-07-25 2017-12-15 浙江大学 Green electric power supply certificate core hair based on block chain technology subscribes method and system
CN107657401A (en) * 2017-08-02 2018-02-02 北京瑞卓喜投科技发展有限公司 Express box monitoring method, device and system based on block chain technology

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107291374A (en) * 2016-03-31 2017-10-24 慧荣科技股份有限公司 Method and device for recording use time of data block
CN106055597A (en) * 2016-05-24 2016-10-26 布比(北京)网络技术有限公司 Digital transaction system, and account information query method therefor
CN106656974A (en) * 2016-10-17 2017-05-10 江苏通付盾科技有限公司 Block chain grouping consensus method and system
CN108427601A (en) * 2017-02-13 2018-08-21 北京航空航天大学 A kind of cluster transaction processing method of privately owned chain node
CN107301546A (en) * 2017-05-03 2017-10-27 北京众享比特科技有限公司 Generating random number and methods for using them and device
CN107239953A (en) * 2017-06-20 2017-10-10 无锡井通网络科技有限公司 Fast data store method and system based on block chain
CN108320160A (en) * 2018-02-02 2018-07-24 张超 Block catenary system, block common recognition method and apparatus

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
"Power distribution network modeling using block-based approach";Li Wern Chew et al.;《Electronics Packaging Technology Conference》;20140220;第230-234页 *
"基于区块链的投票系统的设计与实现";贾民政;《北京工业职业技术学院学报》;20180430;第17卷(第2期);第25-29页 *

Also Published As

Publication number Publication date
CN109255057A (en) 2019-01-22

Similar Documents

Publication Publication Date Title
CN109255057B (en) Block generation method, device, equipment and storage medium
CN108647963B (en) Method and device for determining main chain of block chain, server and storage medium
US7953915B2 (en) Interrupt dispatching method in multi-core environment and multi-core processor
US7957392B2 (en) Method and apparatus for high-performance bonding resequencing
CN111382327B (en) Character string matching device and method
CN109101662B (en) Block generation method, device, equipment and storage medium
WO2017167062A1 (en) Application program interface deadlock monitoring method and device
CN101460983A (en) Malicious attack detection system and an associated method of use
US9900090B1 (en) Inter-packet interval prediction learning algorithm
CN102299843B (en) Network data processing method based on graphic processing unit (GPU) and buffer area, and system thereof
CN112508573B (en) Transaction data processing method and device and computer equipment
CN109213828B (en) Block generation method, device, equipment and storage medium
WO2020157594A1 (en) Handling an input/output store instruction
KR101679573B1 (en) Method and apparatus for service traffic security using dimm channel distribution multicore processing system
CN108134775A (en) A kind of data processing method and equipment
CN110633168A (en) Data backup method and system for distributed storage system
CN110336677B (en) Block packing and broadcasting method and system, equipment and storage medium
CN111309700B (en) Control method and system for multi-sharing directory tree
US20140136683A1 (en) Inter-packet interval prediction operating algorithm
CN113703715A (en) Regular expression matching method and device, FPGA (field programmable Gate array) and medium
EP3872642A1 (en) Caching device, cache, system, method and apparatus for processing data, and medium
CN110535842B (en) Mimic security system and method based on sampling detection
CN109344630B (en) Block generation method, device, equipment and storage medium
CN109241362B (en) Block generation method, device, equipment and storage medium
WO2012028433A1 (en) Method and system for implementing cache offloading

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant