Block generation method and device
The block generation method and device enhance blockchain efficiency by pre-synchronizing node data and using hash sets to reduce coupling, thereby accelerating block generation and ensuring timely upload of critical data.
Patent Information
- Application Number
- CN202411329871.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2025-01-03
AI Technical Summary
The existing block generation method in blockchain technology is hindered by strong coupling between node consensus and block data content, leading to slow block generation speeds and inability to upload critical transaction data within a certain time frame.
A block generation method and device that employs data pre-synchronization between nodes, utilizing hash codes to form hash sets, deduplicate data, and synchronize only index sets during consensus, reducing coupling and increasing speed through a pipeline approach.
Significantly improves block generation speed by reducing network traffic and ensuring key transaction data is uploaded promptly by separating consensus from block data processing and using priority options or quality of service settings.
Smart Images

Figure CN119254782A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain technology, and more specifically to a block generation method and device. Background Art
[0002] At present, the block generation method is that the sending node broadcasts new data records (usually transaction information and smart contracts) to the entire network; the receiving node verifies the received data record information, such as whether the record information is legal. After passing the verification, the data record will be included in a block; all receiving nodes in the entire network execute the consensus algorithm on the block; the block is formally included in the blockchain for storage after passing the consensus algorithm process.
[0003] The disadvantages of this method are:
[0004] (1) Node consensus is strongly coupled with block data content, which seriously affects the speed of block generation, because consensus has been reached when determining the block data content, which needs to be determined through P2P broadcast data content, long chain competition or various other time-consuming transmission protocols;
[0005] (2) Critical transaction data cannot be uploaded to the chain within a certain time frame because node consensus cannot guarantee that the transaction data is included.
[0006] Therefore, how to overcome the above-mentioned defects is a problem that those skilled in the art need to solve urgently. Summary of the invention
[0007] In view of this, in order to at least partially solve the above technical problems, the present invention provides a block generation method and device; the purpose is to increase the block generation speed and reduce the coupling degree between the node consensus protocol and the block data content.
[0008] In order to achieve the above object, the present invention adopts the following technical solution:
[0009] In a first aspect, the present application provides a block generation method, including: generating a block through consensus after data pre-synchronization between nodes; wherein the data pre-synchronization step includes:
[0010] Sort the Hash codes corresponding to the data in each node in the order of the codes to obtain their respective hash sets;
[0011] After the local node collects the data, it updates its own hash set according to the hash code corresponding to the data, and broadcasts its own hash set to other nodes to obtain a difference set;
[0012] The data in the local node and each node are synchronized according to the difference set.
[0013] Furthermore, the synchronization process is as follows: the local node sends the sequential coding sequence in the difference set to each node to obtain the difference data in other nodes.
[0014] Furthermore, the synchronized data in the local node is deduplicated to obtain synchronized data.
[0015] Furthermore, the synchronized data has a corresponding content index set; during consensus, only the index in the content index set, the consensus message, and the execution result HASH are transmitted.
[0016] Furthermore, the consensus process includes:
[0017] Based on the synchronized data, block data is filtered, and consensus interaction is performed on the block data; wherein the principles for filtering block data include:
[0018] The transactions in the block data only include one account transfer out or one account transfer in;
[0019] The business type is the same; or
[0020] Filter based on the size of the block data set.
[0021] Furthermore, priority options are added to the key data in the synchronized data or the service quality level of the transaction content is set to ensure that the key data becomes block data and is uploaded to the chain at a certain time.
[0022] Furthermore, after the consensus is passed, a block is generated based on the consensus result, block data, and the corresponding content index.
[0023] In a second aspect, the present invention provides a block generation device, including a block generation device configured in each node, wherein the block generation device includes a data pre-synchronization module, a consensus module, and a block generation module;
[0024] The data pre-synchronization module is used to sort the Hash codes corresponding to the data in the node in the order of the codes to obtain the Hash set of the node; when the local node collects data, the Hash set of the local node is updated according to the Hash code corresponding to the data, and the Hash set of the local node is broadcast to other nodes to obtain a difference set; and synchronize the data in the local node with each node according to the difference set;
[0025] The consensus module is used to enable the local node to interact with other nodes for consensus based on the synchronized data and return the consensus result;
[0026] The block generation module is used to generate blocks according to the consensus results.
[0027] Furthermore, a candidate block module is provided between the data pre-synchronization module and the consensus module, for filtering block data based on the synchronized data; wherein the principles for filtering block data include:
[0028] The transactions in the block data only include one account transfer out or one account transfer in;
[0029] The business type is the same; or
[0030] Filter based on the size of the block data set.
[0031] Furthermore, the consensus module is connected to a smart contract acceleration module.
[0032] It can be seen from the above technical solution that compared with the prior art, the present invention discloses a block generation method and device, which is used to complete the processing interaction of basic transaction data and contract data at the bottom layer, and generate candidate block content through a simple consistency protocol, so that the consensus protocol can operate on the basis of the above candidate synchronization content, thereby completing the consensus interaction of data content, reducing coupling, and significantly improving the block generation speed.
[0033] In addition, by adding priority options or setting the QoS (quality of service) of the transaction content based on the consistency protocol or timing synchronization protocol, it is possible to ensure that key transaction data is uploaded to the chain at a certain time. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0035] Figure 1 This is a flow chart of the block generation method of the present invention;
[0036] Figure 2 It is a schematic diagram of the structure of the block generation device of the present invention. DETAILED DESCRIPTION
[0037] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0038] In order to improve the block generation speed, it is necessary to reduce the coupling degree between the node consensus protocol and the block data content, and realize the pipeline generation of block data. The embodiment of the present invention discloses a block generation method and device. By transforming the blockchain node into a pipeline, the basic transaction data and contract data are processed and interacted at the bottom layer, and the candidate block content is generated through a simple consistency protocol or a simple timing synchronization protocol, so that the consensus protocol operates on the basis of the above-mentioned candidate synchronization content (for example, deleting abnormal items, merging similar items, etc.), and finally completing the consensus interaction of the data content, and finally achieving the effect of reducing coupling and significantly improving the block generation speed.
[0039] Specifically, in this embodiment, the block generation method includes: generating blocks through consensus after data pre-synchronization between nodes; the core of which is the data pre-synchronization process, which includes the following steps:
[0040] Sort the Hash codes corresponding to the data in each node in the order of the codes to obtain their respective hash sets;
[0041] After the local node collects the data, it updates its own hash set according to the hash code corresponding to the data, and broadcasts its own hash set to other nodes to obtain a difference set;
[0042] The data in the local node and each node are synchronized according to the difference set.
[0043] In a preferred embodiment, a node is determined to be responsible for collecting transaction data and smart contract data within the current time range and retaining transaction data left over from the previous round; this node is referred to as a local node herein;
[0044] After the local node collects data, it updates its own hash set according to the hash code corresponding to the data; and broadcasts its own hash set to other nodes to obtain a difference set;
[0045] In a specific implementation, the pipeline operation is formed as follows Figure 1 As shown, firstly, the collected data set is sorted according to the Hash coding order to form a local candidate transaction data set, which is recorded as set A; then the HASH code corresponding to each data in set A is obtained, and after sequential numbering, an updated hash set is obtained, which is recorded as set B;
[0046] Furthermore, within a specified time, the B set is broadcast to other nodes according to certain rules to obtain a difference set.
[0047] In this embodiment, after the local node broadcasts the local B set, it will enter the difference collection stage. In this stage, it will receive the B set (HASH code + corresponding sequence code) of other nodes; through the fast comparison method, it will obtain the transaction difference set C between other nodes.ij , where i is the local node number and j is the number of other nodes.
[0048] The present invention compares the difference between two data sets based on the HASH coding principle, that is, if the HASH values of data within a limited range are the same, then the original data is the same. Therefore, only the HASH values need to be compared. When the sets are arranged in order, the difference value of the two sets can be determined by quick comparison.
[0049] Preferably, when the difference data is contained in multiple other nodes, the local node can reduce the network data interaction volume and the single node interaction volume through deduplication operation and network load balancing method.
[0050] When the local node completes the difference point comparison and forms a transaction difference set, it will enter the data synchronization stage. The process of synchronizing the data in the local node and each node according to the difference set in the present invention is: the local node sends the sequential coding sequence in the difference set to each node to synchronize the difference data in other nodes. Specifically, the local node i sends the difference set C to the blockchain peer node j. ij , to obtain the block data corresponding to node j.
[0051] In the present invention, since the length of the sequence number occupied by the sequential code is relatively small (for example, 2 bytes can represent a maximum of 2 16 =65536 numbers), so the content sent to node j can only contain the sequentially encoded serial number; each node can achieve data consistency as quickly as possible by sending a difference set and then obtaining transaction data.
[0052] As an exemplary implementation, after the local node data synchronization is completed, all received transaction data are deduplicated and uniformly sorted according to the HASH value to obtain the synchronized data, which is defined as a C set in this embodiment; since each node of the C set has the same content, it can be sorted in a simple order to form a content index set C. index , so that when nodes reach data consensus, network transmission traffic can be reduced by only transmitting indexes in the content index set, consensus messages, and execution result HASH.
[0053] Furthermore, the node consensus process includes:
[0054] Based on the synchronized data, block data is screened and security verification is performed. After the verification is passed, consensus interaction is performed on the block data.
[0055] In this embodiment, according to a certain rule, a data set for generating a block, that is, block data, is selected and recorded as a D set; wherein, in order to speed up the processing speed, the optional screening rules include:
[0056] The business in the block data only includes one account transfer out, or one account transfer in, and the rest of the data is retained for processing in the next block;
[0057] The business types are the same, for example, all businesses are transfer businesses, or smart contracts, or evidence storage businesses; or
[0058] Filter based on the size of the block data set, such as a maximum of 64K transactions.
[0059] As a preferred embodiment, the present application adds priority options to the key data in the synchronized data or sets the service quality level of the transaction content to ensure that the key data becomes block data and is uploaded to the chain at a certain time.
[0060] After the D set is screened, consensus is reached with the blockchain peer nodes through the consensus channel based on the D set, and only C is transmitted during the consensus interaction process. index The data, consensus message and execution result Hash in it.
[0061] When the consensus is passed, the block is generated based on the consensus result, block data and corresponding content index, and finally the current round of blocks is formed.
[0062] The present invention separates transaction information from smart contracts, and uses a HASH sorting method when processing record data. During interaction, only index transmission is used to significantly reduce network transmission traffic. At the same time, based on the three stages of data broadcasting, difference collection, and data synchronization, rapid data acquisition is achieved, reducing the overall data interaction volume. The block generation method provided by the present invention fully adopts a pipeline method, which significantly improves the block generation speed and execution speed.
[0063] In another embodiment, the present application further discloses a block generation device, which is configured in each node, and the block generation device includes a data pre-synchronization module, a consensus module, and a block generation module; Figure 2 As shown; among them,
[0064] The data pre-synchronization module is used to sort the Hash codes corresponding to the data in the nodes in the corresponding order to obtain the Hash set of the nodes; when one of the nodes collects data, the Hash set of the current node is updated according to the Hash code corresponding to the data, and the Hash set of the current node is broadcast to other nodes to obtain a difference set; and the data in the current node and each node are synchronized according to the difference set;
[0065] Preferably, the data pre-synchronization module may be configured to include:
[0066] The data broadcast unit is used to update its own hash set after collecting data and broadcast the hash set to other nodes;
[0067] A difference collection unit, used to receive feedback information from other nodes and collect differences; and
[0068] The data synchronization unit is used to synchronize the data in the current node with the data in other nodes according to the difference set.
[0069] The consensus module in this application is used to enable the current node to interact with other nodes for consensus based on the synchronized data and return the consensus result;
[0070] As a preference, before data consensus interaction, block data is screened and obtained based on synchronized data through the candidate block module; the principles include:
[0071] The transactions in the block data only include one account transfer out or one account transfer in;
[0072] The business type is the same; or
[0073] Filter based on the size of the block data set.
[0074] Finally, the block generation module generates blocks based on the consensus results.
[0075] As an exemplary implementation, the consensus module is connected to a smart contract acceleration module;
[0076] Compared with the existing blockchain data solutions, the present invention has higher execution efficiency. The core of the processing method or device of the present invention is to add a block data pre-synchronization module to each blockchain node. The data pre-synchronization module can perform simple interaction according to the index HASH method to form fast synchronization, so that the consensus module and the block content are completely separated in data processing.
[0077] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0078] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A block generation method, characterized in that: After data is pre-synchronized between nodes, blocks are generated through consensus; The steps of data pre-synchronization include: Sort the Hash codes corresponding to the data in each node in the order of the codes to obtain their respective hash sets; After the local node collects the data, it updates its own hash set according to the hash code corresponding to the data, and broadcasts its own hash set to other nodes to obtain a difference set; The data in the local node and each node are synchronized according to the difference set.
2. The block generation method according to claim 1, characterized in that: The synchronization process is as follows: the local node sends the sequential coding sequence in the difference set to each node to obtain the difference data in other nodes.
3. The block generation method according to claim 1, characterized in that: The synchronized data in the local node is deduplicated to obtain synchronized data.
4. The block generation method according to claim 1, characterized in that: The synchronized data has a corresponding content index set; during consensus, only the index in the content index set, consensus message, and execution result HASH are transmitted.
5. The block generation method according to claim 1, characterized in that: The consensus process includes: Based on the synchronized data, block data is filtered, and consensus interaction is performed on the block data; wherein the principles for filtering block data include: The transactions in the block data only include one account transfer out or one account transfer in; The business type is the same; or Filter based on the size of the block data set.
6. The block generation method according to claim 5, characterized in that: Add priority options for key data in the synchronized data or set the service quality level of the transaction content to ensure that the key data becomes block data and is uploaded to the chain at a certain time.
7. The block generation method according to claim 1, characterized in that: After the consensus is passed, a block is generated based on the consensus result, block data and corresponding content index.
8. A block generation device, characterized in that: Configured in each node, the block generation device includes a data pre-synchronization module, a consensus module, and a block generation module; The data pre-synchronization module is used to sort the Hash codes corresponding to the data in the node in the coding order to obtain the hash set of the node; After the local node collects data, it updates the hash set of the local node according to the hash code corresponding to the data, and broadcasts the hash set of the local node to other nodes to obtain a difference set; and synchronizing the data in the local node and each node according to the difference set; The consensus module is used to enable the local node to interact with other nodes for consensus based on the synchronized data and return the consensus result; The block generation module is used to generate blocks according to the consensus results.
9. The block generation device according to claim 8, characterized in that: A candidate block module is provided between the data pre-synchronization module and the consensus module, which is used to filter block data based on the synchronized data; wherein the principles for filtering block data include: The transactions in the block data only include one account transfer out or one account transfer in; The business type is the same; or Filter based on the size of the block data set.
10. The block generation device according to claim 8, characterized in that: The consensus module is connected to a smart contract acceleration module.